summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2008-10-21 10:54:40 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2008-10-21 10:54:40 +0800
commita8350e585f90e2d4d37bbae1893cb6133e8719b5 (patch)
treefafe76ef5d77b46538cca42eaba29f917a4b5c2d
Initial commit of popcap framework.1.3
-rw-r--r--osframework/Framework 1.21 Changes.txt40
-rw-r--r--osframework/Framework 1.22 Changes.txt28
-rw-r--r--osframework/Framework 1.30 Changes.txt189
-rw-r--r--osframework/INSTALLATION NOTES.txt34
-rw-r--r--osframework/Other Licenses.txt51
-rw-r--r--osframework/PopCap Framework License.txt46
-rw-r--r--osframework/docs/Font Building.docbin0 -> 70656 bytes
-rw-r--r--osframework/docs/Framework Open Source Wstring.docbin0 -> 36352 bytes
-rw-r--r--osframework/docs/Framework Version 1.2 Usage Notes.docbin0 -> 51200 bytes
-rw-r--r--osframework/docs/Pak Resource File Support.docbin0 -> 36352 bytes
-rw-r--r--osframework/docs/SexyAppFramework.docbin0 -> 68096 bytes
-rw-r--r--osframework/docs/Using PopCap Resource Manifests.docbin0 -> 50688 bytes
-rw-r--r--osframework/docs/Vista Support.docbin0 -> 29184 bytes
-rw-r--r--osframework/j2k-codec Notes.txt12
-rw-r--r--osframework/source/ImageLib/ImageLib VS2005.vcproj672
-rw-r--r--osframework/source/ImageLib/ImageLib.cpp1660
-rw-r--r--osframework/source/ImageLib/ImageLib.dsp481
-rw-r--r--osframework/source/ImageLib/ImageLib.h42
-rw-r--r--osframework/source/ImageLib/ImageLib.vcproj570
-rw-r--r--osframework/source/ImageLib/j2k-codec/J2K_Codec.bas68
-rw-r--r--osframework/source/ImageLib/j2k-codec/J2K_Codec.cs176
-rw-r--r--osframework/source/ImageLib/j2k-codec/J2K_Codec.vb91
-rw-r--r--osframework/source/ImageLib/j2k-codec/J2K_Control.idl62
-rw-r--r--osframework/source/ImageLib/j2k-codec/License.txt77
-rw-r--r--osframework/source/ImageLib/j2k-codec/ReadMe.txt103
-rw-r--r--osframework/source/ImageLib/j2k-codec/bmp.h83
-rw-r--r--osframework/source/ImageLib/j2k-codec/file_id.diz21
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-codec.dllbin0 -> 94208 bytes
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-codec.expbin0 -> 3334 bytes
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-codec.h533
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-codec.libbin0 -> 6626 bytes
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-codec.url2
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k-control.dllbin0 -> 93696 bytes
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k.icobin0 -> 318 bytes
-rw-r--r--osframework/source/ImageLib/j2k-codec/j2k_codec.pas271
-rw-r--r--osframework/source/ImageLib/j2k-codec/purchase.url2
-rw-r--r--osframework/source/ImageLib/jpeg/ansi2knr.136
-rw-r--r--osframework/source/ImageLib/jpeg/ansi2knr.c693
-rw-r--r--osframework/source/ImageLib/jpeg/cderror.h132
-rw-r--r--osframework/source/ImageLib/jpeg/cdjpeg.c181
-rw-r--r--osframework/source/ImageLib/jpeg/cdjpeg.h184
-rw-r--r--osframework/source/ImageLib/jpeg/change.log217
-rw-r--r--osframework/source/ImageLib/jpeg/cjpeg.1292
-rw-r--r--osframework/source/ImageLib/jpeg/cjpeg.c606
-rw-r--r--osframework/source/ImageLib/jpeg/ckconfig.c402
-rw-r--r--osframework/source/ImageLib/jpeg/coderules.doc118
-rw-r--r--osframework/source/ImageLib/jpeg/config.guess883
-rw-r--r--osframework/source/ImageLib/jpeg/config.sub954
-rw-r--r--osframework/source/ImageLib/jpeg/configure2011
-rw-r--r--osframework/source/ImageLib/jpeg/djpeg.1253
-rw-r--r--osframework/source/ImageLib/jpeg/djpeg.c616
-rw-r--r--osframework/source/ImageLib/jpeg/example.c433
-rw-r--r--osframework/source/ImageLib/jpeg/install-sh250
-rw-r--r--osframework/source/ImageLib/jpeg/jcapimin.c280
-rw-r--r--osframework/source/ImageLib/jpeg/jcapistd.c161
-rw-r--r--osframework/source/ImageLib/jpeg/jccoefct.c449
-rw-r--r--osframework/source/ImageLib/jpeg/jccolor.c459
-rw-r--r--osframework/source/ImageLib/jpeg/jcdctmgr.c387
-rw-r--r--osframework/source/ImageLib/jpeg/jchuff.c909
-rw-r--r--osframework/source/ImageLib/jpeg/jchuff.h47
-rw-r--r--osframework/source/ImageLib/jpeg/jcinit.c72
-rw-r--r--osframework/source/ImageLib/jpeg/jcmainct.c293
-rw-r--r--osframework/source/ImageLib/jpeg/jcmarker.c664
-rw-r--r--osframework/source/ImageLib/jpeg/jcmaster.c590
-rw-r--r--osframework/source/ImageLib/jpeg/jcomapi.c106
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.bcc48
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.cfg44
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.dj38
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.h43
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.mac43
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.manx43
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.mc652
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.sas43
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.st42
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.vc45
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.vms37
-rw-r--r--osframework/source/ImageLib/jpeg/jconfig.wat38
-rw-r--r--osframework/source/ImageLib/jpeg/jcparam.c610
-rw-r--r--osframework/source/ImageLib/jpeg/jcphuff.c833
-rw-r--r--osframework/source/ImageLib/jpeg/jcprepct.c354
-rw-r--r--osframework/source/ImageLib/jpeg/jcsample.c519
-rw-r--r--osframework/source/ImageLib/jpeg/jctrans.c388
-rw-r--r--osframework/source/ImageLib/jpeg/jdapimin.c395
-rw-r--r--osframework/source/ImageLib/jpeg/jdapistd.c275
-rw-r--r--osframework/source/ImageLib/jpeg/jdatadst.c151
-rw-r--r--osframework/source/ImageLib/jpeg/jdatasrc.c212
-rw-r--r--osframework/source/ImageLib/jpeg/jdcoefct.c736
-rw-r--r--osframework/source/ImageLib/jpeg/jdcolor.c396
-rw-r--r--osframework/source/ImageLib/jpeg/jdct.h176
-rw-r--r--osframework/source/ImageLib/jpeg/jddctmgr.c269
-rw-r--r--osframework/source/ImageLib/jpeg/jdhuff.c651
-rw-r--r--osframework/source/ImageLib/jpeg/jdhuff.h201
-rw-r--r--osframework/source/ImageLib/jpeg/jdinput.c381
-rw-r--r--osframework/source/ImageLib/jpeg/jdmainct.c512
-rw-r--r--osframework/source/ImageLib/jpeg/jdmarker.c1360
-rw-r--r--osframework/source/ImageLib/jpeg/jdmaster.c557
-rw-r--r--osframework/source/ImageLib/jpeg/jdmerge.c400
-rw-r--r--osframework/source/ImageLib/jpeg/jdphuff.c668
-rw-r--r--osframework/source/ImageLib/jpeg/jdpostct.c290
-rw-r--r--osframework/source/ImageLib/jpeg/jdsample.c478
-rw-r--r--osframework/source/ImageLib/jpeg/jdtrans.c143
-rw-r--r--osframework/source/ImageLib/jpeg/jerror.c252
-rw-r--r--osframework/source/ImageLib/jpeg/jerror.h291
-rw-r--r--osframework/source/ImageLib/jpeg/jfdctflt.c168
-rw-r--r--osframework/source/ImageLib/jpeg/jfdctfst.c224
-rw-r--r--osframework/source/ImageLib/jpeg/jfdctint.c283
-rw-r--r--osframework/source/ImageLib/jpeg/jidctflt.c242
-rw-r--r--osframework/source/ImageLib/jpeg/jidctfst.c368
-rw-r--r--osframework/source/ImageLib/jpeg/jidctint.c389
-rw-r--r--osframework/source/ImageLib/jpeg/jidctred.c398
-rw-r--r--osframework/source/ImageLib/jpeg/jinclude.h91
-rw-r--r--osframework/source/ImageLib/jpeg/jmemansi.c167
-rw-r--r--osframework/source/ImageLib/jpeg/jmemdos.c638
-rw-r--r--osframework/source/ImageLib/jpeg/jmemdosa.asm379
-rw-r--r--osframework/source/ImageLib/jpeg/jmemmac.c289
-rw-r--r--osframework/source/ImageLib/jpeg/jmemmgr.c1118
-rw-r--r--osframework/source/ImageLib/jpeg/jmemname.c276
-rw-r--r--osframework/source/ImageLib/jpeg/jmemnobs.c109
-rw-r--r--osframework/source/ImageLib/jpeg/jmemsys.h198
-rw-r--r--osframework/source/ImageLib/jpeg/jmorecfg.h394
-rw-r--r--osframework/source/ImageLib/jpeg/jpegint.h392
-rw-r--r--osframework/source/ImageLib/jpeg/jpeglib.h1096
-rw-r--r--osframework/source/ImageLib/jpeg/jpegtran.1238
-rw-r--r--osframework/source/ImageLib/jpeg/jpegtran.c504
-rw-r--r--osframework/source/ImageLib/jpeg/jquant1.c856
-rw-r--r--osframework/source/ImageLib/jpeg/jquant2.c1310
-rw-r--r--osframework/source/ImageLib/jpeg/jutils.c179
-rw-r--r--osframework/source/ImageLib/jpeg/jversion.h14
-rw-r--r--osframework/source/ImageLib/jpeg/ltconfig1512
-rw-r--r--osframework/source/ImageLib/jpeg/ltmain.sh2453
-rw-r--r--osframework/source/ImageLib/jpeg/makcjpeg.st38
-rw-r--r--osframework/source/ImageLib/jpeg/makdjpeg.st38
-rw-r--r--osframework/source/ImageLib/jpeg/makeapps.ds828
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.ansi214
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.bcc285
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.cfg319
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.dj220
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.manx214
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.mc6249
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.mms218
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.sas252
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.unix228
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.vc211
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.vms142
-rw-r--r--osframework/source/ImageLib/jpeg/makefile.wat233
-rw-r--r--osframework/source/ImageLib/jpeg/makelib.ds1046
-rw-r--r--osframework/source/ImageLib/jpeg/makeproj.mac213
-rw-r--r--osframework/source/ImageLib/jpeg/makljpeg.st70
-rw-r--r--osframework/source/ImageLib/jpeg/maktjpeg.st32
-rw-r--r--osframework/source/ImageLib/jpeg/makvms.opt4
-rw-r--r--osframework/source/ImageLib/jpeg/rdbmp.c439
-rw-r--r--osframework/source/ImageLib/jpeg/rdcolmap.c253
-rw-r--r--osframework/source/ImageLib/jpeg/rdgif.c38
-rw-r--r--osframework/source/ImageLib/jpeg/rdjpgcom.154
-rw-r--r--osframework/source/ImageLib/jpeg/rdjpgcom.c496
-rw-r--r--osframework/source/ImageLib/jpeg/rdppm.c458
-rw-r--r--osframework/source/ImageLib/jpeg/rdrle.c387
-rw-r--r--osframework/source/ImageLib/jpeg/rdswitch.c332
-rw-r--r--osframework/source/ImageLib/jpeg/rdtarga.c500
-rw-r--r--osframework/source/ImageLib/jpeg/readme385
-rw-r--r--osframework/source/ImageLib/jpeg/transupp.c928
-rw-r--r--osframework/source/ImageLib/jpeg/transupp.h135
-rw-r--r--osframework/source/ImageLib/jpeg/wrbmp.c442
-rw-r--r--osframework/source/ImageLib/jpeg/wrgif.c399
-rw-r--r--osframework/source/ImageLib/jpeg/wrjpgcom.1103
-rw-r--r--osframework/source/ImageLib/jpeg/wrjpgcom.c583
-rw-r--r--osframework/source/ImageLib/jpeg/wrppm.c268
-rw-r--r--osframework/source/ImageLib/jpeg/wrrle.c305
-rw-r--r--osframework/source/ImageLib/jpeg/wrtarga.c253
-rw-r--r--osframework/source/ImageLib/jpeg2000/COPYRIGHT2
-rw-r--r--osframework/source/ImageLib/jpeg2000/INSTALL3
-rw-r--r--osframework/source/ImageLib/jpeg2000/LICENSE104
-rw-r--r--osframework/source/ImageLib/jpeg2000/NEWS67
-rw-r--r--osframework/source/ImageLib/jpeg2000/README21
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_cm.c1294
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_cm.h315
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_config.h241
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_config2.h147
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_debug.c186
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_debug.h163
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_fix.h407
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_getopt.c217
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_getopt.h180
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_icc.c1770
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_icc.h456
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_iccdata.c566
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_image.c1493
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_image.h613
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_init.c211
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_init.h132
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_malloc.c167
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_malloc.h173
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_math.h166
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_seq.c477
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_seq.h348
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_stream.c1197
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_stream.h511
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_string.c145
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_string.h144
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_tvp.c286
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_tvp.h200
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_types.h259
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_version.c116
-rw-r--r--osframework/source/ImageLib/jpeg2000/jas_version.h169
-rw-r--r--osframework/source/ImageLib/jpeg2000/jasper.h141
-rw-r--r--osframework/source/ImageLib/jpeg2000/jp2_cod.c949
-rw-r--r--osframework/source/ImageLib/jpeg2000/jp2_cod.h348
-rw-r--r--osframework/source/ImageLib/jpeg2000/jp2_dec.c652
-rw-r--r--osframework/source/ImageLib/jpeg2000/jp2_dec.h134
-rw-r--r--osframework/source/ImageLib/jpeg2000/jp2_enc.c485
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_bs.c486
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_bs.h280
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_cod.h127
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_cs.c1694
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_cs.h812
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_dec.c2361
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_dec.h745
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_enc.c2672
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_enc.h695
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_fix.h193
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_flt.h129
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_math.c170
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_math.h148
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mct.c340
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mct.h160
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqcod.c228
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqcod.h173
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqdec.c355
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqdec.h320
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqenc.c441
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_mqenc.h285
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_qmfb.c1171
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_qmfb.h235
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1cod.c546
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1cod.h344
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1dec.c971
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1dec.h137
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1enc.c1008
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t1enc.h142
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2cod.c733
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2cod.h348
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2dec.c630
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2dec.h144
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2enc.c704
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_t2enc.h155
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_tagtree.c442
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_tagtree.h216
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_tsfb.c663
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_tsfb.h222
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_util.c243
-rw-r--r--osframework/source/ImageLib/jpeg2000/jpc_util.h126
-rw-r--r--osframework/source/ImageLib/png/announce72
-rw-r--r--osframework/source/ImageLib/png/changes476
-rw-r--r--osframework/source/ImageLib/png/example.c706
-rw-r--r--osframework/source/ImageLib/png/install104
-rw-r--r--osframework/source/ImageLib/png/knownbug58
-rw-r--r--osframework/source/ImageLib/png/libpng.32886
-rw-r--r--osframework/source/ImageLib/png/libpng.txt2112
-rw-r--r--osframework/source/ImageLib/png/libpngpf.3505
-rw-r--r--osframework/source/ImageLib/png/license70
-rw-r--r--osframework/source/ImageLib/png/png.558
-rw-r--r--osframework/source/ImageLib/png/png.c370
-rw-r--r--osframework/source/ImageLib/png/png.h2317
-rw-r--r--osframework/source/ImageLib/png/pngasmrd.h32
-rw-r--r--osframework/source/ImageLib/png/pngconf.h723
-rw-r--r--osframework/source/ImageLib/png/pngerror.c172
-rw-r--r--osframework/source/ImageLib/png/pngget.c650
-rw-r--r--osframework/source/ImageLib/png/pngmem.c500
-rw-r--r--osframework/source/ImageLib/png/pngnow.pngbin0 -> 2069 bytes
-rw-r--r--osframework/source/ImageLib/png/pngpread.c1141
-rw-r--r--osframework/source/ImageLib/png/pngread.c896
-rw-r--r--osframework/source/ImageLib/png/pngrio.c151
-rw-r--r--osframework/source/ImageLib/png/pngrtran.c3986
-rw-r--r--osframework/source/ImageLib/png/pngrutil.c2335
-rw-r--r--osframework/source/ImageLib/png/pngset.c391
-rw-r--r--osframework/source/ImageLib/png/pngtest.c1178
-rw-r--r--osframework/source/ImageLib/png/pngtest.pngbin0 -> 8574 bytes
-rw-r--r--osframework/source/ImageLib/png/pngtrans.c595
-rw-r--r--osframework/source/ImageLib/png/pngvcrd.c3838
-rw-r--r--osframework/source/ImageLib/png/pngwio.c213
-rw-r--r--osframework/source/ImageLib/png/pngwrite.c1005
-rw-r--r--osframework/source/ImageLib/png/pngwtran.c497
-rw-r--r--osframework/source/ImageLib/png/pngwutil.c2078
-rw-r--r--osframework/source/ImageLib/png/readme213
-rw-r--r--osframework/source/ImageLib/png/todo24
-rw-r--r--osframework/source/ImageLib/png/y2kinfo55
-rw-r--r--osframework/source/ImageLib/zlib/ChangeLog471
-rw-r--r--osframework/source/ImageLib/zlib/Make_vms.com115
-rw-r--r--osframework/source/ImageLib/zlib/Makefile174
-rw-r--r--osframework/source/ImageLib/zlib/Makefile.in174
-rw-r--r--osframework/source/ImageLib/zlib/Makefile.riscos151
-rw-r--r--osframework/source/ImageLib/zlib/adler32.c48
-rw-r--r--osframework/source/ImageLib/zlib/algorithm.txt213
-rw-r--r--osframework/source/ImageLib/zlib/compress.c68
-rw-r--r--osframework/source/ImageLib/zlib/configure212
-rw-r--r--osframework/source/ImageLib/zlib/crc32.c162
-rw-r--r--osframework/source/ImageLib/zlib/deflate.c1350
-rw-r--r--osframework/source/ImageLib/zlib/deflate.h318
-rw-r--r--osframework/source/ImageLib/zlib/descrip.mms48
-rw-r--r--osframework/source/ImageLib/zlib/example.c556
-rw-r--r--osframework/source/ImageLib/zlib/faq72
-rw-r--r--osframework/source/ImageLib/zlib/gzio.c875
-rw-r--r--osframework/source/ImageLib/zlib/index86
-rw-r--r--osframework/source/ImageLib/zlib/infblock.c398
-rw-r--r--osframework/source/ImageLib/zlib/infblock.h39
-rw-r--r--osframework/source/ImageLib/zlib/infcodes.c257
-rw-r--r--osframework/source/ImageLib/zlib/infcodes.h27
-rw-r--r--osframework/source/ImageLib/zlib/inffast.c170
-rw-r--r--osframework/source/ImageLib/zlib/inffast.h17
-rw-r--r--osframework/source/ImageLib/zlib/inffixed.h151
-rw-r--r--osframework/source/ImageLib/zlib/inflate.c366
-rw-r--r--osframework/source/ImageLib/zlib/inftrees.c455
-rw-r--r--osframework/source/ImageLib/zlib/inftrees.h58
-rw-r--r--osframework/source/ImageLib/zlib/infutil.c87
-rw-r--r--osframework/source/ImageLib/zlib/infutil.h98
-rw-r--r--osframework/source/ImageLib/zlib/maketree.c85
-rw-r--r--osframework/source/ImageLib/zlib/minigzip.c320
-rw-r--r--osframework/source/ImageLib/zlib/readme148
-rw-r--r--osframework/source/ImageLib/zlib/trees.c1214
-rw-r--r--osframework/source/ImageLib/zlib/trees.h128
-rw-r--r--osframework/source/ImageLib/zlib/uncompr.c58
-rw-r--r--osframework/source/ImageLib/zlib/zconf.h285
-rw-r--r--osframework/source/ImageLib/zlib/zlib.3107
-rw-r--r--osframework/source/ImageLib/zlib/zlib.h893
-rw-r--r--osframework/source/ImageLib/zlib/zutil.c225
-rw-r--r--osframework/source/ImageLib/zlib/zutil.h220
-rw-r--r--osframework/source/PakLib/PakInterface.cpp434
-rw-r--r--osframework/source/PakLib/PakInterface.h237
-rw-r--r--osframework/source/SexyAppFramework/AutoCrit.h34
-rw-r--r--osframework/source/SexyAppFramework/BassLoader.cpp197
-rw-r--r--osframework/source/SexyAppFramework/BassLoader.h104
-rw-r--r--osframework/source/SexyAppFramework/BassMusicInterface.cpp425
-rw-r--r--osframework/source/SexyAppFramework/BassMusicInterface.h68
-rw-r--r--osframework/source/SexyAppFramework/BltRotatedHelper.inc259
-rw-r--r--osframework/source/SexyAppFramework/Buffer.cpp584
-rw-r--r--osframework/source/SexyAppFramework/Buffer.h66
-rw-r--r--osframework/source/SexyAppFramework/ButtonListener.h21
-rw-r--r--osframework/source/SexyAppFramework/ButtonWidget.cpp288
-rw-r--r--osframework/source/SexyAppFramework/ButtonWidget.h78
-rw-r--r--osframework/source/SexyAppFramework/Checkbox.cpp81
-rw-r--r--osframework/source/SexyAppFramework/Checkbox.h46
-rw-r--r--osframework/source/SexyAppFramework/CheckboxListener.h15
-rw-r--r--osframework/source/SexyAppFramework/Color.cpp162
-rw-r--r--osframework/source/SexyAppFramework/Color.h50
-rw-r--r--osframework/source/SexyAppFramework/Common.cpp1324
-rw-r--r--osframework/source/SexyAppFramework/Common.h230
-rw-r--r--osframework/source/SexyAppFramework/CritSect.cpp20
-rw-r--r--osframework/source/SexyAppFramework/CritSect.h24
-rw-r--r--osframework/source/SexyAppFramework/CursorWidget.cpp30
-rw-r--r--osframework/source/SexyAppFramework/CursorWidget.h28
-rw-r--r--osframework/source/SexyAppFramework/D3D8Helper.cpp276
-rw-r--r--osframework/source/SexyAppFramework/D3D8Helper.h11
-rw-r--r--osframework/source/SexyAppFramework/D3DInterface.cpp2208
-rw-r--r--osframework/source/SexyAppFramework/D3DInterface.h154
-rw-r--r--osframework/source/SexyAppFramework/D3DTester.cpp1193
-rw-r--r--osframework/source/SexyAppFramework/D3DTester.h129
-rw-r--r--osframework/source/SexyAppFramework/DDI_Additive.inc265
-rw-r--r--osframework/source/SexyAppFramework/DDI_AlphaBlt.inc616
-rw-r--r--osframework/source/SexyAppFramework/DDI_BltRotated.inc217
-rw-r--r--osframework/source/SexyAppFramework/DDI_BltRotated_Additive.inc138
-rw-r--r--osframework/source/SexyAppFramework/DDI_FastBlt_NoAlpha.inc92
-rw-r--r--osframework/source/SexyAppFramework/DDI_FastStretch.inc206
-rw-r--r--osframework/source/SexyAppFramework/DDI_FastStretch_Additive.inc219
-rw-r--r--osframework/source/SexyAppFramework/DDI_NormalBlt_Volatile.inc194
-rw-r--r--osframework/source/SexyAppFramework/DDImage.cpp3277
-rw-r--r--osframework/source/SexyAppFramework/DDImage.h99
-rw-r--r--osframework/source/SexyAppFramework/DDInterface.cpp1432
-rw-r--r--osframework/source/SexyAppFramework/DDInterface.h136
-rw-r--r--osframework/source/SexyAppFramework/DSoundInstance.cpp177
-rw-r--r--osframework/source/SexyAppFramework/DSoundInstance.h58
-rw-r--r--osframework/source/SexyAppFramework/DSoundManager.cpp1098
-rw-r--r--osframework/source/SexyAppFramework/DSoundManager.h74
-rw-r--r--osframework/source/SexyAppFramework/Debug.cpp246
-rw-r--r--osframework/source/SexyAppFramework/Debug.h31
-rw-r--r--osframework/source/SexyAppFramework/DescParser.cpp552
-rw-r--r--osframework/source/SexyAppFramework/DescParser.h101
-rw-r--r--osframework/source/SexyAppFramework/Dialog.cpp407
-rw-r--r--osframework/source/SexyAppFramework/Dialog.h123
-rw-r--r--osframework/source/SexyAppFramework/DialogButton.cpp92
-rw-r--r--osframework/source/SexyAppFramework/DialogButton.h24
-rw-r--r--osframework/source/SexyAppFramework/DialogListener.h16
-rw-r--r--osframework/source/SexyAppFramework/DirectXErrorString.cpp220
-rw-r--r--osframework/source/SexyAppFramework/DirectXErrorString.h11
-rw-r--r--osframework/source/SexyAppFramework/EditListener.h22
-rw-r--r--osframework/source/SexyAppFramework/EditWidget.cpp694
-rw-r--r--osframework/source/SexyAppFramework/EditWidget.h102
-rw-r--r--osframework/source/SexyAppFramework/FModLoader.cpp287
-rw-r--r--osframework/source/SexyAppFramework/FModLoader.h239
-rw-r--r--osframework/source/SexyAppFramework/FModMusicInterface.cpp466
-rw-r--r--osframework/source/SexyAppFramework/FModMusicInterface.h64
-rw-r--r--osframework/source/SexyAppFramework/FModSoundInstance.cpp50
-rw-r--r--osframework/source/SexyAppFramework/FModSoundInstance.h32
-rw-r--r--osframework/source/SexyAppFramework/FModSoundManager.cpp114
-rw-r--r--osframework/source/SexyAppFramework/FModSoundManager.h41
-rw-r--r--osframework/source/SexyAppFramework/Flags.cpp2
-rw-r--r--osframework/source/SexyAppFramework/Flags.h76
-rw-r--r--osframework/source/SexyAppFramework/FlashWidget.cpp1384
-rw-r--r--osframework/source/SexyAppFramework/FlashWidget.h123
-rw-r--r--osframework/source/SexyAppFramework/Font.cpp74
-rw-r--r--osframework/source/SexyAppFramework/Font.h43
-rw-r--r--osframework/source/SexyAppFramework/GENERIC_DrawLineAA.inc92
-rw-r--r--osframework/source/SexyAppFramework/Graphics.cpp1356
-rw-r--r--osframework/source/SexyAppFramework/Graphics.h200
-rw-r--r--osframework/source/SexyAppFramework/GraphicsBuild.cpp18
-rw-r--r--osframework/source/SexyAppFramework/HTTPTransfer.cpp574
-rw-r--r--osframework/source/SexyAppFramework/HTTPTransfer.h84
-rw-r--r--osframework/source/SexyAppFramework/HyperlinkWidget.cpp51
-rw-r--r--osframework/source/SexyAppFramework/HyperlinkWidget.h27
-rw-r--r--osframework/source/SexyAppFramework/Image.cpp290
-rw-r--r--osframework/source/SexyAppFramework/Image.h104
-rw-r--r--osframework/source/SexyAppFramework/ImageFont.cpp1736
-rw-r--r--osframework/source/SexyAppFramework/ImageFont.h171
-rw-r--r--osframework/source/SexyAppFramework/Insets.cpp29
-rw-r--r--osframework/source/SexyAppFramework/Insets.h23
-rw-r--r--osframework/source/SexyAppFramework/KeyCodes.cpp151
-rw-r--r--osframework/source/SexyAppFramework/KeyCodes.h109
-rw-r--r--osframework/source/SexyAppFramework/ListListener.h17
-rw-r--r--osframework/source/SexyAppFramework/ListWidget.cpp510
-rw-r--r--osframework/source/SexyAppFramework/ListWidget.h96
-rw-r--r--osframework/source/SexyAppFramework/MI_AdditiveBlt.inc110
-rw-r--r--osframework/source/SexyAppFramework/MI_BltRotated.inc101
-rw-r--r--osframework/source/SexyAppFramework/MI_BltRotated_Additive.inc71
-rw-r--r--osframework/source/SexyAppFramework/MI_GetNativeAlphaData.inc44
-rw-r--r--osframework/source/SexyAppFramework/MI_GetRLAlphaData.inc52
-rw-r--r--osframework/source/SexyAppFramework/MI_NormalBlt.inc222
-rw-r--r--osframework/source/SexyAppFramework/MI_SlowStretchBlt.inc276
-rw-r--r--osframework/source/SexyAppFramework/MTRand.cpp197
-rw-r--r--osframework/source/SexyAppFramework/MTRand.h43
-rw-r--r--osframework/source/SexyAppFramework/MemoryImage.cpp1918
-rw-r--r--osframework/source/SexyAppFramework/MemoryImage.h113
-rw-r--r--osframework/source/SexyAppFramework/MemoryOuputModule.cpp81
-rw-r--r--osframework/source/SexyAppFramework/MiscBuild.cpp19
-rw-r--r--osframework/source/SexyAppFramework/MiscBuildBase.cpp18
-rw-r--r--osframework/source/SexyAppFramework/ModVal.cpp669
-rw-r--r--osframework/source/SexyAppFramework/ModVal.h72
-rw-r--r--osframework/source/SexyAppFramework/MusicInterface.cpp90
-rw-r--r--osframework/source/SexyAppFramework/MusicInterface.h43
-rw-r--r--osframework/source/SexyAppFramework/NativeDisplay.cpp28
-rw-r--r--osframework/source/SexyAppFramework/NativeDisplay.h32
-rw-r--r--osframework/source/SexyAppFramework/PerfTimer.cpp321
-rw-r--r--osframework/source/SexyAppFramework/PerfTimer.h122
-rw-r--r--osframework/source/SexyAppFramework/Point.h61
-rw-r--r--osframework/source/SexyAppFramework/PropertiesParser.cpp265
-rw-r--r--osframework/source/SexyAppFramework/PropertiesParser.h41
-rw-r--r--osframework/source/SexyAppFramework/Quantize.cpp78
-rw-r--r--osframework/source/SexyAppFramework/Quantize.h13
-rw-r--r--osframework/source/SexyAppFramework/Ratio.cpp36
-rw-r--r--osframework/source/SexyAppFramework/Ratio.h58
-rw-r--r--osframework/source/SexyAppFramework/Rect.h118
-rw-r--r--osframework/source/SexyAppFramework/Release - Final/BuildLog.htmbin0 -> 180762 bytes
-rw-r--r--osframework/source/SexyAppFramework/ResourceManager.cpp1274
-rw-r--r--osframework/source/SexyAppFramework/ResourceManager.h219
-rw-r--r--osframework/source/SexyAppFramework/SEHCatcher.cpp1292
-rw-r--r--osframework/source/SexyAppFramework/SEHCatcher.h97
-rw-r--r--osframework/source/SexyAppFramework/SWTri.cpp658
-rw-r--r--osframework/source/SexyAppFramework/SWTri.h184
-rw-r--r--osframework/source/SexyAppFramework/SWTri_DrawTriangle.cpp278
-rw-r--r--osframework/source/SexyAppFramework/SWTri_DrawTriangleInc1.cpp762
-rw-r--r--osframework/source/SexyAppFramework/SWTri_DrawTriangleInc2.cpp142
-rw-r--r--osframework/source/SexyAppFramework/SWTri_GetTexel.cpp44
-rw-r--r--osframework/source/SexyAppFramework/SWTri_Loop.cpp57
-rw-r--r--osframework/source/SexyAppFramework/SWTri_Pixel555.cpp69
-rw-r--r--osframework/source/SexyAppFramework/SWTri_Pixel565.cpp68
-rw-r--r--osframework/source/SexyAppFramework/SWTri_Pixel888.cpp64
-rw-r--r--osframework/source/SexyAppFramework/SWTri_Pixel8888.cpp87
-rw-r--r--osframework/source/SexyAppFramework/SWTri_TexelARGB.cpp39
-rw-r--r--osframework/source/SexyAppFramework/ScrollListener.h15
-rw-r--r--osframework/source/SexyAppFramework/ScrollbarWidget.cpp362
-rw-r--r--osframework/source/SexyAppFramework/ScrollbarWidget.h90
-rw-r--r--osframework/source/SexyAppFramework/ScrollbuttonWidget.cpp70
-rw-r--r--osframework/source/SexyAppFramework/ScrollbuttonWidget.h29
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase VS2005 WideString.vcproj8261
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase VS2005.vcproj8261
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase WideString.vcproj6153
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase.cpp7087
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase.dsp1304
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase.h577
-rw-r--r--osframework/source/SexyAppFramework/SexyAppBase.vcproj6151
-rw-r--r--osframework/source/SexyAppFramework/SexyMatrix.cpp295
-rw-r--r--osframework/source/SexyAppFramework/SexyMatrix.h91
-rw-r--r--osframework/source/SexyAppFramework/SexyVector.h77
-rw-r--r--osframework/source/SexyAppFramework/SharedImage.cpp106
-rw-r--r--osframework/source/SexyAppFramework/SharedImage.h50
-rw-r--r--osframework/source/SexyAppFramework/Slider.cpp174
-rw-r--r--osframework/source/SexyAppFramework/Slider.h43
-rw-r--r--osframework/source/SexyAppFramework/SliderListener.h15
-rw-r--r--osframework/source/SexyAppFramework/SmartPtr.h146
-rw-r--r--osframework/source/SexyAppFramework/SoundBuild.cpp9
-rw-r--r--osframework/source/SexyAppFramework/SoundInstance.h34
-rw-r--r--osframework/source/SexyAppFramework/SoundManager.h50
-rw-r--r--osframework/source/SexyAppFramework/SysFont.cpp318
-rw-r--r--osframework/source/SexyAppFramework/SysFont.h38
-rw-r--r--osframework/source/SexyAppFramework/TextWidget.cpp429
-rw-r--r--osframework/source/SexyAppFramework/TextWidget.h62
-rw-r--r--osframework/source/SexyAppFramework/TriVertex.h25
-rw-r--r--osframework/source/SexyAppFramework/Widget.cpp489
-rw-r--r--osframework/source/SexyAppFramework/Widget.h146
-rw-r--r--osframework/source/SexyAppFramework/WidgetBuildBase.cpp16
-rw-r--r--osframework/source/SexyAppFramework/WidgetContainer.cpp627
-rw-r--r--osframework/source/SexyAppFramework/WidgetContainer.h87
-rw-r--r--osframework/source/SexyAppFramework/WidgetManager.cpp806
-rw-r--r--osframework/source/SexyAppFramework/WidgetManager.h134
-rw-r--r--osframework/source/SexyAppFramework/XMLParser.cpp721
-rw-r--r--osframework/source/SexyAppFramework/XMLParser.h106
-rw-r--r--osframework/source/SexyAppFramework/bass.dllbin0 -> 92216 bytes
-rw-r--r--osframework/source/SexyAppFramework/bass.h808
-rw-r--r--osframework/source/SexyAppFramework/dsoundversion.h7
-rw-r--r--osframework/source/SexyAppFramework/fmod.h1063
-rw-r--r--osframework/source/SexyAppFramework/memmgr.h96
-rw-r--r--osframework/source/SexyAppFramework/ogg/COPYING28
-rw-r--r--osframework/source/SexyAppFramework/ogg/asm_arm.h243
-rw-r--r--osframework/source/SexyAppFramework/ogg/backends.h136
-rw-r--r--osframework/source/SexyAppFramework/ogg/bitwise.c266
-rw-r--r--osframework/source/SexyAppFramework/ogg/block.c453
-rw-r--r--osframework/source/SexyAppFramework/ogg/codebook.c350
-rw-r--r--osframework/source/SexyAppFramework/ogg/codebook.h102
-rw-r--r--osframework/source/SexyAppFramework/ogg/codec_internal.h92
-rw-r--r--osframework/source/SexyAppFramework/ogg/config_types.h25
-rw-r--r--osframework/source/SexyAppFramework/ogg/floor0.c437
-rw-r--r--osframework/source/SexyAppFramework/ogg/floor1.c440
-rw-r--r--osframework/source/SexyAppFramework/ogg/framing.c1126
-rw-r--r--osframework/source/SexyAppFramework/ogg/info.c354
-rw-r--r--osframework/source/SexyAppFramework/ogg/ivorbiscodec.h202
-rw-r--r--osframework/source/SexyAppFramework/ogg/ivorbisfile.h130
-rw-r--r--osframework/source/SexyAppFramework/ogg/lsp_lookup.h136
-rw-r--r--osframework/source/SexyAppFramework/ogg/mapping0.c322
-rw-r--r--osframework/source/SexyAppFramework/ogg/mdct.c510
-rw-r--r--osframework/source/SexyAppFramework/ogg/mdct.h52
-rw-r--r--osframework/source/SexyAppFramework/ogg/mdct_lookup.h540
-rw-r--r--osframework/source/SexyAppFramework/ogg/misc.h242
-rw-r--r--osframework/source/SexyAppFramework/ogg/ogg.h206
-rw-r--r--osframework/source/SexyAppFramework/ogg/os.h64
-rw-r--r--osframework/source/SexyAppFramework/ogg/os_types.h88
-rw-r--r--osframework/source/SexyAppFramework/ogg/registry.c50
-rw-r--r--osframework/source/SexyAppFramework/ogg/registry.h40
-rw-r--r--osframework/source/SexyAppFramework/ogg/res012.c336
-rw-r--r--osframework/source/SexyAppFramework/ogg/sharedbook.c443
-rw-r--r--osframework/source/SexyAppFramework/ogg/synthesis.c116
-rw-r--r--osframework/source/SexyAppFramework/ogg/vorbisfile.c1592
-rw-r--r--osframework/source/SexyAppFramework/ogg/window.c84
-rw-r--r--osframework/source/SexyAppFramework/ogg/window.h27
-rw-r--r--osframework/source/SexyAppFramework/ogg/window_lookup.h2084
-rw-r--r--osframework/source/SexyAppFramework/old_Quantize.cpp857
-rw-r--r--osframework/source/SexyAppFramework/scrnsave.c412
-rw-r--r--osframework/source/demos/Demo1/Board.cpp166
-rw-r--r--osframework/source/demos/Demo1/Board.h106
-rw-r--r--osframework/source/demos/Demo1/Demo1 VS2005 WideString.vcproj237
-rw-r--r--osframework/source/demos/Demo1/Demo1 VS2005.vcproj237
-rw-r--r--osframework/source/demos/Demo1/Demo1 WideString.vcproj149
-rw-r--r--osframework/source/demos/Demo1/Demo1.dsp126
-rw-r--r--osframework/source/demos/Demo1/Demo1.vcproj149
-rw-r--r--osframework/source/demos/Demo1/GameApp.cpp114
-rw-r--r--osframework/source/demos/Demo1/GameApp.h88
-rw-r--r--osframework/source/demos/Demo1/main.cpp46
-rw-r--r--osframework/source/demos/Demo2/Board.cpp305
-rw-r--r--osframework/source/demos/Demo2/Board.h108
-rw-r--r--osframework/source/demos/Demo2/Demo2 VS2005 WideString.vcproj237
-rw-r--r--osframework/source/demos/Demo2/Demo2 VS2005.vcproj237
-rw-r--r--osframework/source/demos/Demo2/Demo2 WideString.vcproj149
-rw-r--r--osframework/source/demos/Demo2/Demo2.dsp125
-rw-r--r--osframework/source/demos/Demo2/Demo2.vcproj149
-rw-r--r--osframework/source/demos/Demo2/GameApp.cpp306
-rw-r--r--osframework/source/demos/Demo2/GameApp.h105
-rw-r--r--osframework/source/demos/Demo2/main.cpp46
-rw-r--r--osframework/source/demos/Demo3/Board.cpp389
-rw-r--r--osframework/source/demos/Demo3/Board.h267
-rw-r--r--osframework/source/demos/Demo3/Demo3 VS2005 WideString.vcproj237
-rw-r--r--osframework/source/demos/Demo3/Demo3 VS2005.vcproj237
-rw-r--r--osframework/source/demos/Demo3/Demo3 WideString.vcproj149
-rw-r--r--osframework/source/demos/Demo3/Demo3.dsp125
-rw-r--r--osframework/source/demos/Demo3/Demo3.vcproj149
-rw-r--r--osframework/source/demos/Demo3/GameApp.cpp301
-rw-r--r--osframework/source/demos/Demo3/GameApp.h108
-rw-r--r--osframework/source/demos/Demo3/main.cpp45
-rw-r--r--osframework/source/demos/Demo4/Board.cpp488
-rw-r--r--osframework/source/demos/Demo4/Board.h331
-rw-r--r--osframework/source/demos/Demo4/Demo4 VS2005 WideString.vcproj251
-rw-r--r--osframework/source/demos/Demo4/Demo4 VS2005.vcproj251
-rw-r--r--osframework/source/demos/Demo4/Demo4 WideString.vcproj158
-rw-r--r--osframework/source/demos/Demo4/Demo4.dsp136
-rw-r--r--osframework/source/demos/Demo4/Demo4.vcproj158
-rw-r--r--osframework/source/demos/Demo4/GameApp.cpp395
-rw-r--r--osframework/source/demos/Demo4/GameApp.h122
-rw-r--r--osframework/source/demos/Demo4/TitleScreen.cpp210
-rw-r--r--osframework/source/demos/Demo4/TitleScreen.h127
-rw-r--r--osframework/source/demos/Demo4/main.cpp47
-rw-r--r--osframework/source/demos/Demo5/Board.cpp306
-rw-r--r--osframework/source/demos/Demo5/Board.h205
-rw-r--r--osframework/source/demos/Demo5/Demo5 VS2005 WideString.vcproj258
-rw-r--r--osframework/source/demos/Demo5/Demo5 VS2005.vcproj258
-rw-r--r--osframework/source/demos/Demo5/Demo5 WideString.vcproj162
-rw-r--r--osframework/source/demos/Demo5/Demo5.dsp150
-rw-r--r--osframework/source/demos/Demo5/Demo5.vcproj162
-rw-r--r--osframework/source/demos/Demo5/DemoDialog.cpp414
-rw-r--r--osframework/source/demos/Demo5/DemoDialog.h209
-rw-r--r--osframework/source/demos/Demo5/GameApp.cpp427
-rw-r--r--osframework/source/demos/Demo5/GameApp.h173
-rw-r--r--osframework/source/demos/Demo5/TitleScreen.cpp205
-rw-r--r--osframework/source/demos/Demo5/TitleScreen.h125
-rw-r--r--osframework/source/demos/Demo5/main.cpp50
-rw-r--r--osframework/source/demos/Hun-garr/Board.cpp2189
-rw-r--r--osframework/source/demos/Hun-garr/Board.h739
-rw-r--r--osframework/source/demos/Hun-garr/GameApp.cpp279
-rw-r--r--osframework/source/demos/Hun-garr/GameApp.h171
-rw-r--r--osframework/source/demos/Hun-garr/GameOverEffect.cpp452
-rw-r--r--osframework/source/demos/Hun-garr/GameOverEffect.h204
-rw-r--r--osframework/source/demos/Hun-garr/Hun-garr VS2005 WideString.vcproj276
-rw-r--r--osframework/source/demos/Hun-garr/Hun-garr VS2005.vcproj276
-rw-r--r--osframework/source/demos/Hun-garr/Hun-garr WideString.vcproj176
-rw-r--r--osframework/source/demos/Hun-garr/Hun-garr.vcproj176
-rw-r--r--osframework/source/demos/Hun-garr/Hungarr.dsp166
-rw-r--r--osframework/source/demos/Hun-garr/LevelupEffect.cpp438
-rw-r--r--osframework/source/demos/Hun-garr/LevelupEffect.h191
-rw-r--r--osframework/source/demos/Hun-garr/OptionsDialog.cpp273
-rw-r--r--osframework/source/demos/Hun-garr/OptionsDialog.h110
-rw-r--r--osframework/source/demos/Hun-garr/TitleScreen.cpp150
-rw-r--r--osframework/source/demos/Hun-garr/TitleScreen.h121
-rw-r--r--osframework/source/demos/Hun-garr/main.cpp41
-rw-r--r--osframework/source/demos/Res.cpp378
-rw-r--r--osframework/source/demos/Res.h147
-rw-r--r--osframework/source/demos/V12Demo/.#Board.cpp.1.7442
-rw-r--r--osframework/source/demos/V12Demo/.#Board.cpp.1.8442
-rw-r--r--osframework/source/demos/V12Demo/Board.cpp439
-rw-r--r--osframework/source/demos/V12Demo/Board.h87
-rw-r--r--osframework/source/demos/V12Demo/DemoWidget.cpp101
-rw-r--r--osframework/source/demos/V12Demo/DemoWidget.h38
-rw-r--r--osframework/source/demos/V12Demo/V12Demo VS2005 WideString.vcproj234
-rw-r--r--osframework/source/demos/V12Demo/V12Demo VS2005.vcproj234
-rw-r--r--osframework/source/demos/V12Demo/V12Demo WideString.vcproj143
-rw-r--r--osframework/source/demos/V12Demo/V12Demo.dsp141
-rw-r--r--osframework/source/demos/V12Demo/V12Demo.vcproj143
-rw-r--r--osframework/source/demos/V12Demo/V12DemoApp.cpp116
-rw-r--r--osframework/source/demos/V12Demo/V12DemoApp.h79
-rw-r--r--osframework/source/demos/V12Demo/main.cpp65
-rw-r--r--osframework/source/demos/XMLDemo/Board.cpp50
-rw-r--r--osframework/source/demos/XMLDemo/Board.h29
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemo VS2005 WideString.vcproj228
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemo VS2005.vcproj228
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemo WideString.vcproj139
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemo.dsp133
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemo.vcproj139
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemoApp.cpp217
-rw-r--r--osframework/source/demos/XMLDemo/XMLDemoApp.h83
-rw-r--r--osframework/source/demos/XMLDemo/main.cpp34
-rw-r--r--osframework/source/demos/bass.dllbin0 -> 92216 bytes
-rw-r--r--osframework/source/demos/demos.txt199
-rw-r--r--osframework/source/demos/fonts/ArmorPiercing22.txt67
-rw-r--r--osframework/source/demos/fonts/ContinuumBold12.txt100
-rw-r--r--osframework/source/demos/fonts/Kiloton9.txt56
-rw-r--r--osframework/source/demos/fonts/_ArmorPiercing22.pngbin0 -> 8303 bytes
-rw-r--r--osframework/source/demos/fonts/_ContinuumBold12.gifbin0 -> 8027 bytes
-rw-r--r--osframework/source/demos/fonts/_Kiloton9.pngbin0 -> 1033 bytes
-rw-r--r--osframework/source/demos/fonts/_supernova20.pngbin0 -> 2413 bytes
-rw-r--r--osframework/source/demos/fonts/supernova20.txt28
-rw-r--r--osframework/source/demos/images/atomicexplosion.jpgbin0 -> 20265 bytes
-rw-r--r--osframework/source/demos/images/atomicexplosion_.jpgbin0 -> 16883 bytes
-rw-r--r--osframework/source/demos/images/beam_opaque.jpgbin0 -> 573 bytes
-rw-r--r--osframework/source/demos/images/beam_opaque_.gifbin0 -> 1382 bytes
-rw-r--r--osframework/source/demos/images/bomb_radial_death.jpgbin0 -> 25696 bytes
-rw-r--r--osframework/source/demos/images/bomb_radial_death_.jpgbin0 -> 18025 bytes
-rw-r--r--osframework/source/demos/images/btn_down.gifbin0 -> 881 bytes
-rw-r--r--osframework/source/demos/images/btn_down_.gifbin0 -> 284 bytes
-rw-r--r--osframework/source/demos/images/btn_over.gifbin0 -> 881 bytes
-rw-r--r--osframework/source/demos/images/btn_over_.gifbin0 -> 284 bytes
-rw-r--r--osframework/source/demos/images/btn_up.gifbin0 -> 881 bytes
-rw-r--r--osframework/source/demos/images/btn_up_.gifbin0 -> 268 bytes
-rw-r--r--osframework/source/demos/images/checkbox.gifbin0 -> 933 bytes
-rw-r--r--osframework/source/demos/images/checkbox_.gifbin0 -> 217 bytes
-rw-r--r--osframework/source/demos/images/custom_dragging.gifbin0 -> 1134 bytes
-rw-r--r--osframework/source/demos/images/custom_dragging_.gifbin0 -> 485 bytes
-rw-r--r--osframework/source/demos/images/custom_hand.gifbin0 -> 501 bytes
-rw-r--r--osframework/source/demos/images/custom_hand_.gifbin0 -> 533 bytes
-rw-r--r--osframework/source/demos/images/custom_pointer.gifbin0 -> 1131 bytes
-rw-r--r--osframework/source/demos/images/custom_pointer_.gifbin0 -> 1566 bytes
-rw-r--r--osframework/source/demos/images/custom_text.gifbin0 -> 956 bytes
-rw-r--r--osframework/source/demos/images/dialog.gifbin0 -> 8246 bytes
-rw-r--r--osframework/source/demos/images/dialog_.gifbin0 -> 2394 bytes
-rw-r--r--osframework/source/demos/images/dialog_btn.gifbin0 -> 1667 bytes
-rw-r--r--osframework/source/demos/images/dialog_btn_.gifbin0 -> 849 bytes
-rw-r--r--osframework/source/demos/images/hungarr_logo.jpgbin0 -> 8008 bytes
-rw-r--r--osframework/source/demos/images/hungarr_logo_.gifbin0 -> 2347 bytes
-rw-r--r--osframework/source/demos/images/layer0.jpgbin0 -> 18797 bytes
-rw-r--r--osframework/source/demos/images/layer1.pngbin0 -> 34715 bytes
-rw-r--r--osframework/source/demos/images/layer2.pngbin0 -> 157474 bytes
-rw-r--r--osframework/source/demos/images/lightning.gifbin0 -> 77377 bytes
-rw-r--r--osframework/source/demos/images/lightning_.gifbin0 -> 32157 bytes
-rw-r--r--osframework/source/demos/images/loader_bar.jpgbin0 -> 4569 bytes
-rw-r--r--osframework/source/demos/images/loader_loading.gifbin0 -> 1596 bytes
-rw-r--r--osframework/source/demos/images/loader_loading_.gifbin0 -> 2547 bytes
-rw-r--r--osframework/source/demos/images/moon.gifbin0 -> 3895 bytes
-rw-r--r--osframework/source/demos/images/moon_.gifbin0 -> 621 bytes
-rw-r--r--osframework/source/demos/images/particle_lightning.jpgbin0 -> 5691 bytes
-rw-r--r--osframework/source/demos/images/planets_small.jpgbin0 -> 6302 bytes
-rw-r--r--osframework/source/demos/images/planets_small_.gifbin0 -> 3567 bytes
-rw-r--r--osframework/source/demos/images/robotrobot.gifbin0 -> 1131 bytes
-rw-r--r--osframework/source/demos/images/slider.gifbin0 -> 236 bytes
-rw-r--r--osframework/source/demos/images/slider_thumb.gifbin0 -> 242 bytes
-rw-r--r--osframework/source/demos/images/spark.jpgbin0 -> 927 bytes
-rw-r--r--osframework/source/demos/images/turbot_worry.gifbin0 -> 8085 bytes
-rw-r--r--osframework/source/demos/images/turbot_worry_.gifbin0 -> 2901 bytes
-rw-r--r--osframework/source/demos/images/unicron_baby.JPGbin0 -> 9522 bytes
-rw-r--r--osframework/source/demos/images/unicron_baby_.GIFbin0 -> 1197 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_down.jpgbin0 -> 17908 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_down_.gifbin0 -> 2133 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_left.jpgbin0 -> 16527 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_left_.gifbin0 -> 1562 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_right.jpgbin0 -> 4450 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_right_.gifbin0 -> 1564 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_up.jpgbin0 -> 5214 bytes
-rw-r--r--osframework/source/demos/images/unicron_beam_up_.gifbin0 -> 1867 bytes
-rw-r--r--osframework/source/demos/images/unicron_horiz.jpgbin0 -> 9352 bytes
-rw-r--r--osframework/source/demos/images/unicron_horiz_.gifbin0 -> 1874 bytes
-rw-r--r--osframework/source/demos/images/unicron_vert.jpgbin0 -> 9336 bytes
-rw-r--r--osframework/source/demos/images/unicron_vert_.gifbin0 -> 1905 bytes
-rw-r--r--osframework/source/demos/music/hungarr.oggbin0 -> 2467571 bytes
-rw-r--r--osframework/source/demos/music/music.mo3bin0 -> 343576 bytes
-rw-r--r--osframework/source/demos/osfd VS2005.sln91
-rw-r--r--osframework/source/demos/osfd WideString VS2005.sln91
-rw-r--r--osframework/source/demos/osfd WideString.sln80
-rw-r--r--osframework/source/demos/osfd.dsw149
-rw-r--r--osframework/source/demos/osfd.sln80
-rw-r--r--osframework/source/demos/properties/demo.xml38
-rw-r--r--osframework/source/demos/properties/resources.xml145
-rw-r--r--osframework/source/demos/sounds/bad2.oggbin0 -> 7999 bytes
-rw-r--r--osframework/source/demos/sounds/click2.oggbin0 -> 13500 bytes
-rw-r--r--osframework/source/demos/sounds/electro_start.oggbin0 -> 38895 bytes
-rw-r--r--osframework/source/demos/sounds/explosion.oggbin0 -> 19920 bytes
-rw-r--r--osframework/source/demos/sounds/killall_explode.oggbin0 -> 26950 bytes
-rw-r--r--osframework/source/demos/sounds/lament.oggbin0 -> 124400 bytes
-rw-r--r--osframework/source/demos/sounds/laserpowerup.oggbin0 -> 9587 bytes
-rw-r--r--osframework/source/demos/sounds/level_up.oggbin0 -> 29787 bytes
-rw-r--r--osframework/source/demos/sounds/level_up2.oggbin0 -> 16021 bytes
-rw-r--r--osframework/source/demos/sounds/magzap1.oggbin0 -> 7845 bytes
-rw-r--r--osframework/source/demos/sounds/metal_loop.wavbin0 -> 39290 bytes
-rw-r--r--osframework/source/demos/sounds/mouseover.oggbin0 -> 9903 bytes
-rw-r--r--osframework/source/demos/sounds/mutator.oggbin0 -> 13623 bytes
-rw-r--r--osframework/source/demos/sounds/planet.oggbin0 -> 11778 bytes
-rw-r--r--osframework/source/demos/sounds/robotlaser.oggbin0 -> 7547 bytes
-rw-r--r--osframework/source/demos/sounds/shorting.oggbin0 -> 17175 bytes
-rw-r--r--osframework/source/demos/sounds/slowdown1.oggbin0 -> 25757 bytes
-rw-r--r--osframework/source/demos/sounds/timer.oggbin0 -> 4171 bytes
-rw-r--r--osframework/source/demos/sounds/whirlpool1.oggbin0 -> 102612 bytes
-rw-r--r--osframework/tools/FontBuilder.exebin0 -> 4382720 bytes
-rw-r--r--osframework/tools/FontTester.exebin0 -> 1056768 bytes
-rw-r--r--osframework/tools/GFXMonger.exebin0 -> 528384 bytes
-rw-r--r--osframework/tools/MapLookup.exebin0 -> 348160 bytes
-rw-r--r--osframework/tools/PopPak.exebin0 -> 15360 bytes
-rw-r--r--osframework/tools/ResourceGen.exebin0 -> 172032 bytes
-rw-r--r--osframework/tools/fmod.dllbin0 -> 130560 bytes
749 files changed, 255096 insertions, 0 deletions
diff --git a/osframework/Framework 1.21 Changes.txt b/osframework/Framework 1.21 Changes.txt
new file mode 100644
index 0000000..44d2791
--- /dev/null
+++ b/osframework/Framework 1.21 Changes.txt
@@ -0,0 +1,40 @@
+Framework 1.21 changes:
+
+Widgets are no longer removed from their container in WidgeContainer::RemovedFromManager.
+It's your responsibility to remove all widgets from a container before deleting the container.
+Widgets will assert if they have a parent or if they have haven children in their destructor.
+To assist you, there's a helper method WidgetContainer::RemoveAllWidgets().
+
+Added LinearBlending for DrawImageMatrix/DrawImageTransform.
+Call Graphics::SetLinearBlend to enable/disable linear blending.
+
+Added good default faststretch and linear blend settings to WidgetManager drawing:
+ aClipG.SetFastStretch(!is3D);
+ aClipG.SetLinearBlend(is3D);
+
+Changed 3d test to not require "nvidia", "ati", or "radeon" in the name of the driver
+for recommending the video card if the video card driver's year is >= 2002.
+
+Changed Dialog::mYesButton and Dialog::mNoButton to Dialog::ID_YES and Dialog::ID_NO
+(1000 and 1001) to avoid conflict with user defined buttons.
+
+Various bug fixes
+
+------------------------------------------------------------------------------------
+Debug key (ctrl-alt-d) changes:
+F2 - Start/Stop Perf Timing
+
+F3 - toggle framerate display
+Shift F3 - toggle framerate/mouse coord display
+
+F8 - Show current Video Stats (mostly used to see if 3d is currently on)
+Shift F8 - Toggle 3d mode
+
+F10 - Single Step Program (show one frame at a time)
+Shift F10 - Stop single steping
+Ctrl F10 - Toggle Slow Motion
+
+F11 - Take Screenshot (goes into the _screenshots) directory
+Shift F11 - Dump all program images in memory to the _dump directory
+------------------------------------------------------------------------------------
+
diff --git a/osframework/Framework 1.22 Changes.txt b/osframework/Framework 1.22 Changes.txt
new file mode 100644
index 0000000..7149c9c
--- /dev/null
+++ b/osframework/Framework 1.22 Changes.txt
@@ -0,0 +1,28 @@
+Framework 1.22 changes:
+
+* Support for Visual Studio 2005
+
+* Fixed some C++ language conformance issues
+
+* Fixed some bugs with the flash widget and rendering issues
+
+* Got tired of casting warnings, properly casting stuff now
+
+* Fixed some demo bugs and bad programming practices
+
+* IMPORTANT NEW CHANGE: in order to cut filesize bloat, caused
+ by the addition of the software triangle rasterizer
+ code in 1.21, you now need to do the following IF you
+ use DrawImageMatrix or DrawImageTransform (with a
+ complex transformation) or if you get errors compiling
+ or at run time you get the assert "You need to call
+ SWTri_AddDrawTriFunc or SWTri_AddAllDrawTriFuncs"
+
+ 1. Include "SexyAppFramework/SWTri.h"
+ 2. Call the function SWTri_AddAllDrawTriFuncs()
+ 3. Alternatively to #2, if you know which triangle draw
+ functions you need, you can add them specifically via
+ SWTri_AddDrawTriFunc(...) and specifying which draw
+ function you need (check SWTri.h for a list).
+
+* Removed the ImageLib project files as they aren't needed, to avoid confusion \ No newline at end of file
diff --git a/osframework/Framework 1.30 Changes.txt b/osframework/Framework 1.30 Changes.txt
new file mode 100644
index 0000000..64258cb
--- /dev/null
+++ b/osframework/Framework 1.30 Changes.txt
@@ -0,0 +1,189 @@
+Changelog for Framework version 1.3:
+
+General
+=======
+* Removed support for Visual Studio / Visual C++ 6. If you use these versions, you will need to update your project files manually.
+ * Note: you can download Visual Studio 2005 Express edition for free from Microsoft (http://msdn.microsoft.com/vstudio/express/)
+* PAKfile support - See docs/Pak Resource File Support.doc
+* Added support for wide displays and for windowed emulation of wide displays.
+* some wide string/localization related changes to strings/chars: Use the WideString.vcproj projects for widestring support
+* Added support to draw anti-aliased lines/polygons
+* Cached WAV files are "encrypted" (weakly) to prevent the easy copying of sound resources.
+* All demos were made to be widestring compatible and we added corresponding widestring projects. std::string has been replaced with SexyString, char with SexyChar, and a few std::string to SexyString conversion functions are now scattered about the demos, where needed.
+* Irrelevant build configurations were removed from the projects
+* Fixed problem with project files where the framework wouldn't be built unless you manually built it. This caused the error with not finding sexyappframework.lib and preventing the demos from linking if you just did a rebuild all.
+* Made all projects default to not use edit/continue in debug mode
+
+Vista Support
+=============
+* Added GetAppDataFolder() to get the top-level directory where you can save files to. On Vista, this returns the appropriate storage location. On non-Vista, this returns the empty string.
+ * mFullCompanyName member of SexyAppBase is used to create this directory in the SexyAppBase::Init function.
+ * This directory looks like this: <Windows return location to ProgramData [defaults to c:\ProgramData]>\mFullCompanyName\mProdName\
+* Added CheckForVista() function that returns true if running on Vista.
+* Added CheckFor98Mill() function that returns true if running on Win95, Win98, or WinME
+* Changed registry functions to use HKEY_CURRENT_USER on all systems
+* Cached sound files save to GetAppDataFolder() location now (this is the same location on Pre-Vista machines; see above)
+* Added AllowAllAccess() function to Common to allow developers to set the permissions to directories/files to Everyone -> Full Control.
+
+ImageLib
+=============
+* JPEG2000 support added using j2k-codec (see http://www.j2k-codec.com for licensing information)
+* Fix to GetImage function not casting std::string::size_type to an int before passing it to min/max
+* Added gAutoLoadAlpha global variable. When true, GetImage will look for alpha masks (same filename with _ at the end or beginning of file). When false, alpha masks will not be automatically loaded.
+* Added gIgnoreJPEG2000Alpha global variable. When true, the alpha channel in a jp2 file will be set to entirely opaque. When false, the alpha channel will be preserved.
+
+
+SWTri_Pixel888.cpp
+===================
+* fix for alpha values that might end up getting messed up when writing to memory images.
+
+DDI_FastStretch_Additive.inc
+============================
+* fix for drawing stretched images in software being off a pixel
+
+HTTPTransfer
+====================
+* Added member variable /mContentLength/ to hold the "Content-Length: " parameter
+
+MI_NormalBlt/BltRotatedHelper.inc
+=================
+* 16-bit rotation optimizations
+
+BASS related:
+=============
+* Upgraded BASS files to work with 2.3 (2.2.0.1 is still shipped by default w/ framework though)
+* Exposed a lot more bass.dll methods
+* added variable, BassMusicInterface::mMusicLoadFlags, so that you can override the BASS music loading flags with whatever flags you want.
+
+
+MTRand
+======
+* Added methods for retrieving random integers and floats within a specified range.
+
+SoundManager/DSoundManager
+==========================
+* Added GetFreeSoundId to SoundManager to return the first available sound id
+* Has resource manager call soundmanager->releasesound when a sound is unloaded
+* sound ids are based on GetFreeSoundID instead of mCurSoundId, and mCurSoundId no longer exists.
+
+Slider
+=======
+* Added the ability to have vertical sliders instead of only horizontal: Just specify mHorizontal = false. Defaults to true for backwards compatibility.
+* fixed bug in SetValue():
+Setting a value less than 0 or greater than 1 could cause problems/crashes. Now clamps value to 0->1 range.
+* Added functionality so that if you click on the scroll bar (but not on the thumb) then the thumb and value get set to the position you clicked on. Previously, the widget didn't respond if you clicked anywhere outside of the thumb.
+
+Font/ImageFont
+===============
+* Fixed small inefficiency in CharWidth.
+* Allow colors specified in the decriptor to be simple integers such as 0xffffff instead of (1,1,1,1).
+* Fix crash with legacy font loading.
+* Make SysFonts return the correct Descent so that WriteWordWrapped works correctly.
+* Support drawing on MemoryImage objects with SysFont objects.
+
+SexyAppBase
+===========
+* Added mPhysMinimized and defer alt-enter processing to ProcessDeferredMessages.
+* Added mEnableMaximizeButton option to enable/disable the maximize button.
+* Added KillDialog method which lets you specify whether you want to remove and delete the dialog or not (useful for scrolling the dialog off the screen after it's ended).
+* Added tablet support.
+* Broke up the GameAlreadyRunning/NotifyGame message logic into virtual functions that can be overridden. This is so apps can do other things if the game is already running.
+* Add mFullCompanyName -- used for setting AppDataFolder
+* mChangeDirTo for -changedir command line parameter.
+* Add WM_QUERYOPEN hook which calls SexyAppBase::AppCanRestore. If this method returns true, Windows will be allowed to restore the window. Otherwise, it will not.
+* Add mIsDisabled to track disabled state of main window.
+* Change RegistryRead to use helper function RegistryReadKey while passing in HKEY_CURRENT_USER as the key to read.
+
+FlashWidget
+===========
+* SysColorChanged notification for Widgets. Now FlashWidget can detect when it needs to MarkDirty entirely.
+* fixed a crash caused by referencing invalid memory
+* Windows SDK v6.0 does not include comsuppw.lib by default with comdef.h. Manually added it.
+
+SexyMatrix
+==========
+* Allow DrawImageTransform to have scalex = -1 for mirroring an image.
+
+ModVal
+======
+* Made it so you can have multiple M()'s on a line instead of having to have unique M1(), M2(), etc
+
+D3DInterface
+============
+* Added mPhysMinimized and defer alt-enter processing to ProcessDeferredMessages.
+* Fixed multithreaded issue with mImageSet.
+* Fixed problem in BltTransformed when center parameter was true.
+* Copy right and bottom pixels to fill the borders of textures which don't go to the border. This emulates the texture having clamping turned on and going right up to the edge.
+* Recover bits shouldn't recover old bits (make sure bitschangedcount is up to date).
+
+Graphics and related .inc files
+================================
+* Added the ability to return a wordwrapped string to writing its original color by using the ^oldclr^ tag
+* Added SetScale:
+ Scales all calls that route through DrawImage(Image* theImage, int theX, int theY, const Rect& theSrcRect) by a value. This is part of the graphics state, so you can use Push/PopState with it.
+* Added Is3D to see if this graphics is drawing using the 3d card.
+* New draw string wordwrapped
+* Added DrawStringColor.
+* support for antialiased line/polygon drawing/filling
+* made WriteWordWrapped be able to continue from an indented point
+* Changed DrawStringColor to take an old color.
+* Fixed problem with DrawLineClipHelper needing to tell calling function that line is completely clipped.
+* Commented back in theOldColor in WriteWordWrappedHelper.
+* Fixed for loop scoped variable problem.
+* Optimizations to common drawing paths. Huge increases in FPS in some situations. If things look weird, #undef OPTIMIZE_SOFTWARE_DRAWING in MemoryImage.h
+* fixes bug with drawing stretched images to another image and having the resulting image appear partially transparent
+* Divide by zero fix when DestRect width/height = 1 and also stretching out (Bilinear blend version of stretching)
+* Just return from DrawImageBox if srcWidth or srcHeight <= 0.
+* Fixed write string problem where ^^ wouldn't work if it was near the end of the string.
+* Added theMaxChars parameter to WriteWordWrapped so you can gradually reveal all of the characters in a bunch of lines of text (just using substr doesn't work because the word wrapping changes as characters appear).
+* Made DrawImageRotatedF use the exact subpixel center of the image as the pivot point (as opposed to the integer center).
+
+
+WidgetContainer
+===============
+* Added WidgetContainer::WidgetRemovedHelper for calling RemovedFromManager on all child widgets and for calling DisableWidget on all child widgets.
+* fixed: If you have a widget that is at the end of mWidgets, and then that widget adds another widget and calls UpdateApp (like the blocking dialog box wait function), if you do not remove the added widget (i.e. set autokill for a blocking dialog wait function), and if the addING widget is not at the END of the mWidgets list, then the app will crash with an invalid iterator, as there is only 1 mUpdateIterator and it is being overwritten while UpdateApp is called. Also, if mUpdateThisRemoved is ever set while calling UpdateApp, its value will overwrite any previous value before the call to UpdateApp.
+* Added WidgetContainer::mZOrder which is used to keep a widget at a certain relative position in the widget list
+* Fixes a re-entrency bug that can cause the app to crash if mUpdateIterator is already at the end of the widget list inside of UpdateAll and mUpdateThisRemoved is false: previously the iterator got incremented again, causing it to be invalid.
+* Fix to GetWidgetAtHelper related to Base Modal dialogs.
+* Made all functions virtual
+
+
+Widget related
+===============
+* Fixed default values for fast stretch and linear blend in FlushDeferredOverlayWidgets.
+* added ability to have draw overlay pass in the priority at which it's calling the function
+* made Widget::ShowFinger check if mWidgetManager == NULL: previously it did this:
+
+if (on)
+ mWidgetManager->mApp->SetCursor(CURSOR_HAND);
+else
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+
+which will crash if the widget manager is NULL.
+
+ResourceManager
+===============
+* Added LoadFont and DeleteFont.
+* Added support to use sys fonts in resources.xml, via path="!sys:font_face" size="point_size" Bold, underline, italics, and shadow can all be specified as attributes in the tag itself.
+
+Checkbox
+========
+* added default draw method to checkbox for if no checked/unchecked image is specified
+
+XMLParser
+=========
+* fixed a potential bug with reusing the same XMLParser object on multiple files.
+* Added more supported encoding types: UTF-8, UTF-16, UTF-16LE, UTF-16BE.
+* Encoding types can be automatically detected by byte-order-markers, or they can be explicitly set with SetEncodingType method.
+
+D3DTester
+=========
+* Always retest 3d if it fails... This way, the user isn't permanently locked out of 3d for any reason.
+
+Common.h/.cpp
+=============
+* Fixed MkDir so it can handle backwards and forward slashes.
+* added functions: CheckForVista, GetAppDataFolder, SetAppDataFolder, AllowAllAccess. See "Vista" section for more Vista details.
+* Many helper functions introduced to support wide string, and the new framework string type: SexyString.
+* Added macro _S() which can be used to encapsulate string or character constants. This will ensure that strings are wide string if _USE_WIDE_STRING is defined, or narrow strings if it is undefined.
diff --git a/osframework/INSTALLATION NOTES.txt b/osframework/INSTALLATION NOTES.txt
new file mode 100644
index 0000000..046114f
--- /dev/null
+++ b/osframework/INSTALLATION NOTES.txt
@@ -0,0 +1,34 @@
+The most common reason why the demos and source fail to build are due to the lack
+of required software to build them. Ensure that you have the following before building:
+
+* The microsoft DirectX SDK (not just the runtime).
+ http://www.microsoft.com/directx
+
+* The Windows Platform SDK (VS2005 Express does NOT include this by default but Pro does).
+ http://www.microsoft.com/downloads/details.aspx?FamilyId=484269E2-3B89-47E3-8EB7-1F2BE6D7123A&displaylang=en
+ Do not be alarmed by the title "Windows Server 2003 SP1 Platform SDK Web Install".
+ This allows you to develop for not just Windows Server 2003 but Windows XP/x64/etc.
+
+ You will then need to manually add the paths for the Platform SDK to your search paths in
+ Visual Studio:
+
+ Go to Tools->Options->Projects And Solutions->VC++ Directories
+ Add the paths to the appropriate subsection:
+
+ Executable files - C:\Program Files\Microsoft SDK\Bin
+ Include files - C:\Program Files\Microsoft SDK\include
+ Library files - C:\Program Files\Microsoft SDK\lib
+
+
+* If you are using Visual Studio 2005 Express, make sure you add these additional libraries to your
+ Linker's include settings: gdi32.lib advapi32.lib shell32.lib
+
+* If you are making your own projects and are getting errors that look something like this:
+Linking...
+LIBCMTD.lib(tolower.obj) : error LNK2005: __tolower already defined in LIBCD.lib(tolower.obj)
+LIBCMTD.lib(tolower.obj) : error LNK2005: _tolower already defined in LIBCD.lib(tolower.obj)
+LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
+Debug/Temp.exe : fatal error LNK1169: one or more multiply defined symbols found
+Error executing link.exe.
+
+then you need to add LIBCD to the ignored default libraries for debug mode and LIBC for release. \ No newline at end of file
diff --git a/osframework/Other Licenses.txt b/osframework/Other Licenses.txt
new file mode 100644
index 0000000..4ff6ff1
--- /dev/null
+++ b/osframework/Other Licenses.txt
@@ -0,0 +1,51 @@
+The PopCap Games Framework provides interfaces to some third-party
+libraries, but licenses to those libraries are not automatically
+granted to you through use of the Framework. Listed below is
+information for libraries which require explicit licensing if you
+release a product which uses them.
+
+BASS Audio Library
+The BASS Audio Library is the default library used by the Framework
+to decompress sounds and to play music. Licenses to the BASS Audio
+Library can be purchased at http://www.un4seen.com/bass.html#license.
+You can avoid using the BASS Audio Library by setting
+SexyAppBase::mWantFMod before application initialization to use the
+FMOD Music Library or by setting SexyAppBase::mNoSoundNeeded if you
+do not need to load compressed audio or play tracked music.
+
+FMOD Audio Library
+The FMOD library is a popular alternative to the BASS Audio Library.
+Licenses to FMOD can be purchased at http://www.fmod.org/. Although
+the BASS Audio Library is the default sound library in the Framework,
+you can use FMOD instead by setting SexyAppBase::mWantFMod before
+application initialization.
+
+MP3 Compressed Audio
+The Framework supports both MP3 and OGG decompression through either
+BASS or FMOD. The OGG format can be used for free, but if you must
+use MP3 in your product, you will have to contact Thompson Multimedia
+and arrange to pay for an MP3 license. Game developers can get a
+'game license' to use MP3 for $2500. See
+http://www.mp3licensing.com/royalty/games.html.
+
+Macromedia Flash
+The Framework supports Flash through FlashWidget, but you must sign
+up for a license to redistribute the Flash ActiveX control if you
+use FlashWidget in your application. You can get a Flash license
+from Macromedia at
+http://www.macromedia.com/support/shockwave/info/licensing/main_2.html.
+Make sure you actually read the license, particularly the
+"Consideration" section.
+
+J2K-Codec Library
+The framework supports loading j2k images through the j2k-codec library.
+This library is NOT free and you must purchase your own copy if you want
+to use it in registered (non-demo) mode. You may obtain a copy from
+Alex Saveliev at http://j2k-codec.com. We do not distribute our key,
+so the library will run in demo mode with the following restrictions,
+as taken from the readme.txt file:
+ * beeps at the end of each decoding
+ * open the ordering page once in about 30 decoded images
+ * on the rare occasions do several other little nags
+
+The price of the j2k codec is between $49 and $399, depending on use. \ No newline at end of file
diff --git a/osframework/PopCap Framework License.txt b/osframework/PopCap Framework License.txt
new file mode 100644
index 0000000..e524c18
--- /dev/null
+++ b/osframework/PopCap Framework License.txt
@@ -0,0 +1,46 @@
+PopCap Games Framework License
+
+Version 1.0
+
+Copyright (c) 2005 PopCap Games. All rights reserved.
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the following
+conditions are met:
+
+1. Redistributions of source code or derived libraries, whether
+source code or binary, must include a copy of this PopCap Games
+Framework License in its entirety.
+
+2. The end-user documentation included with a work which
+contains any portion of the PopCap Games Framework must include
+the following acknowledgment:
+
+"This product includes portions of the PopCap Games Framework
+(http://developer.popcap.com/)."
+
+Alternatively, this acknowledgment may appear in the software
+itself, wherever such third-party acknowledgments normally
+appear.
+
+3. The names "PopCap" and "PopCap Games" must not be used to
+endorse or promote products derived from this software without
+prior written permission. For written permission, please
+contact bizdev@popcap.com.
+
+4. Products derived from this software may not be called
+"PopCap", nor may "PopCap" appear in their name, without prior
+written permission of PopCap Games.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, NON-INFRINGMENT AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL POPCAP
+GAMES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/osframework/docs/Font Building.doc b/osframework/docs/Font Building.doc
new file mode 100644
index 0000000..19a09b3
--- /dev/null
+++ b/osframework/docs/Font Building.doc
Binary files differ
diff --git a/osframework/docs/Framework Open Source Wstring.doc b/osframework/docs/Framework Open Source Wstring.doc
new file mode 100644
index 0000000..3d0d860
--- /dev/null
+++ b/osframework/docs/Framework Open Source Wstring.doc
Binary files differ
diff --git a/osframework/docs/Framework Version 1.2 Usage Notes.doc b/osframework/docs/Framework Version 1.2 Usage Notes.doc
new file mode 100644
index 0000000..48077ec
--- /dev/null
+++ b/osframework/docs/Framework Version 1.2 Usage Notes.doc
Binary files differ
diff --git a/osframework/docs/Pak Resource File Support.doc b/osframework/docs/Pak Resource File Support.doc
new file mode 100644
index 0000000..1128952
--- /dev/null
+++ b/osframework/docs/Pak Resource File Support.doc
Binary files differ
diff --git a/osframework/docs/SexyAppFramework.doc b/osframework/docs/SexyAppFramework.doc
new file mode 100644
index 0000000..1ca0f26
--- /dev/null
+++ b/osframework/docs/SexyAppFramework.doc
Binary files differ
diff --git a/osframework/docs/Using PopCap Resource Manifests.doc b/osframework/docs/Using PopCap Resource Manifests.doc
new file mode 100644
index 0000000..e2eed97
--- /dev/null
+++ b/osframework/docs/Using PopCap Resource Manifests.doc
Binary files differ
diff --git a/osframework/docs/Vista Support.doc b/osframework/docs/Vista Support.doc
new file mode 100644
index 0000000..99b496b
--- /dev/null
+++ b/osframework/docs/Vista Support.doc
Binary files differ
diff --git a/osframework/j2k-codec Notes.txt b/osframework/j2k-codec Notes.txt
new file mode 100644
index 0000000..603ec48
--- /dev/null
+++ b/osframework/j2k-codec Notes.txt
@@ -0,0 +1,12 @@
+The framework ships with a demo version of the j2k-codec. The demo has the following restrictions:
+ * beeps at the end of each decoding
+ * open the ordering page once in about 30 decoded images
+ * on the rare occasions do several other little nags
+
+If you want to use the j2k codec in your application, you will need to purchase a key from
+http://j2k-codec.com. The price is between $49 and $399. Once you have purchased a key,
+you can use it in the framework by calling:
+
+ImageLib::SetJ2KCodecKey(<your key>)
+
+When you load a JPEG2000 image, your key will be automatically passed to the j2k-codec library. \ No newline at end of file
diff --git a/osframework/source/ImageLib/ImageLib VS2005.vcproj b/osframework/source/ImageLib/ImageLib VS2005.vcproj
new file mode 100644
index 0000000..9ee9c0c
--- /dev/null
+++ b/osframework/source/ImageLib/ImageLib VS2005.vcproj
@@ -0,0 +1,672 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="ImageLib"
+ ProjectGUID="{BC8BFFB8-7E39-411A-B856-A75B1DF2D2F6}"
+ RootNamespace="Copy of ImageLib"
+ SccProjectName="&quot;$/WinAlch&quot;, YKBAAAAA"
+ SccLocalPath="..\winalch"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/ImageLib.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Release\ImageLib.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ PrecompiledHeaderFile=".\Debug/ImageLib.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Debug\ImageLib.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath=".\ImageLib.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <File
+ RelativePath=".\ImageLib.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="PNG"
+ >
+ <File
+ RelativePath=".\png\png.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\png.h"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngasmrd.h"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngconf.h"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngerror.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngget.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngmem.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngpread.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngread.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngrio.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngrtran.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngrutil.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngset.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngtrans.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngvcrd.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngwio.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngwrite.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngwtran.c"
+ >
+ </File>
+ <File
+ RelativePath=".\png\pngwutil.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG"
+ >
+ <File
+ RelativePath=".\jpeg\cderror.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\cdjpeg.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\cdjpeg.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcapimin.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcapistd.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jccoefct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jccolor.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcdctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jchuff.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jchuff.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcinit.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmainct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmarker.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmaster.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcomapi.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jconfig.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcparam.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcphuff.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcprepct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jcsample.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jctrans.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdapimin.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdapistd.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdatadst.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdatasrc.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdcoefct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdcolor.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdct.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jddctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdhuff.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdhuff.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdinput.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmainct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmarker.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmaster.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmerge.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdphuff.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdpostct.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdsample.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jdtrans.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jerror.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jerror.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctflt.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctfst.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctint.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctflt.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctfst.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctint.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctred.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jinclude.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemmgr.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemnobs.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemsys.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jmorecfg.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jpegint.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jpeglib.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jquant1.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jquant2.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jutils.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\jversion.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdbmp.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdcolmap.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdgif.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdppm.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdrle.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdswitch.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\rdtarga.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\transupp.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\transupp.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\wrbmp.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\wrgif.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\wrppm.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\wrrle.c"
+ >
+ </File>
+ <File
+ RelativePath=".\jpeg\wrtarga.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB"
+ >
+ <File
+ RelativePath="zlib\adler32.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\compress.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\crc32.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\deflate.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\deflate.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\gzio.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infblock.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infblock.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infcodes.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infcodes.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inffast.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inffast.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inffixed.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inflate.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inftrees.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\inftrees.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infutil.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\infutil.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\trees.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\trees.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\uncompr.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\zconf.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\zlib.h"
+ >
+ </File>
+ <File
+ RelativePath="zlib\zutil.c"
+ >
+ </File>
+ <File
+ RelativePath="zlib\zutil.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/ImageLib/ImageLib.cpp b/osframework/source/ImageLib/ImageLib.cpp
new file mode 100644
index 0000000..b8179c6
--- /dev/null
+++ b/osframework/source/ImageLib/ImageLib.cpp
@@ -0,0 +1,1660 @@
+#define XMD_H
+
+#include <windows.h>
+#include "ImageLib.h"
+#include "png\png.h"
+#include <math.h>
+#include <tchar.h>
+#include "..\PakLib\PakInterface.h"
+
+extern "C"
+{
+#include "jpeg\jpeglib.h"
+#include "jpeg\jerror.h"
+}
+
+//#include "jpeg2000/jasper.h"
+
+using namespace ImageLib;
+
+Image::Image()
+{
+ mWidth = 0;
+ mHeight = 0;
+ mBits = NULL;
+}
+
+Image::~Image()
+{
+ delete mBits;
+}
+
+int Image::GetWidth()
+{
+ return mWidth;
+}
+
+int Image::GetHeight()
+{
+ return mHeight;
+}
+
+unsigned long* Image::GetBits()
+{
+ return mBits;
+}
+
+//////////////////////////////////////////////////////////////////////////
+// PNG Pak Support
+
+static void png_pak_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)p_fread(data, (png_size_t)1, length,
+ (PFILE*)png_ptr->io_ptr);
+
+ if (check != length)
+ {
+ png_error(png_ptr, "Read Error");
+ }
+}
+
+Image* GetPNGImage(const std::string& theFileName)
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ unsigned int sig_read = 0;
+ png_uint_32 width, height;
+ int bit_depth, color_type, interlace_type;
+ PFILE *fp;
+
+ if ((fp = p_fopen(theFileName.c_str(), "rb")) == NULL)
+ return NULL;
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ NULL, NULL, NULL);
+ png_set_read_fn(png_ptr, (png_voidp)fp, png_pak_read_data);
+
+ if (png_ptr == NULL)
+ {
+ p_fclose(fp);
+ return NULL;
+ }
+
+ /* Allocate/initialize the memory for image information. REQUIRED. */
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ {
+ p_fclose(fp);
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+ return NULL;
+ }
+
+ /* Set error handling if you are using the setjmp/longjmp method (this is
+ * the normal method of doing things with libpng). REQUIRED unless you
+ * set up your own error handlers in the png_create_read_struct() earlier.
+ */
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ /* Free all of the memory associated with the png_ptr and info_ptr */
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+ p_fclose(fp);
+ /* If we get here, we had a problem reading the file */
+ return NULL;
+ }
+
+ //png_init_io(png_ptr, fp);
+
+ //png_ptr->io_ptr = (png_voidp)fp;
+
+ png_read_info(png_ptr, info_ptr);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ &interlace_type, NULL, NULL);
+
+ /* Add filler (or alpha) byte (before/after each RGB triplet) */
+ png_set_expand(png_ptr);
+ png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
+ //png_set_gray_1_2_4_to_8(png_ptr);
+ png_set_palette_to_rgb(png_ptr);
+ png_set_gray_to_rgb(png_ptr);
+ png_set_bgr(png_ptr);
+
+// int aNumBytes = png_get_rowbytes(png_ptr, info_ptr) * height / 4;
+ unsigned long* aBits = new unsigned long[width*height];
+ unsigned long* anAddr = aBits;
+ for (int i = 0; i < height; i++)
+ {
+ png_read_rows(png_ptr, (png_bytepp) &anAddr, NULL, 1);
+ anAddr += width;
+ }
+
+ /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
+ png_read_end(png_ptr, info_ptr);
+
+ /* clean up after the read, and free any memory allocated - REQUIRED */
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+
+ /* close the file */
+ p_fclose(fp);
+
+ Image* anImage = new Image();
+ anImage->mWidth = width;
+ anImage->mHeight = height;
+ anImage->mBits = aBits;
+
+ return anImage;
+}
+
+Image* GetTGAImage(const std::string& theFileName)
+{
+ PFILE* aTGAFile = p_fopen(theFileName.c_str(), "rb");
+ if (aTGAFile == NULL)
+ return NULL;
+
+ BYTE aHeaderIDLen;
+ p_fread(&aHeaderIDLen, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE aColorMapType;
+ p_fread(&aColorMapType, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE anImageType;
+ p_fread(&anImageType, sizeof(BYTE), 1, aTGAFile);
+
+ WORD aFirstEntryIdx;
+ p_fread(&aFirstEntryIdx, sizeof(WORD), 1, aTGAFile);
+
+ WORD aColorMapLen;
+ p_fread(&aColorMapLen, sizeof(WORD), 1, aTGAFile);
+
+ BYTE aColorMapEntrySize;
+ p_fread(&aColorMapEntrySize, sizeof(BYTE), 1, aTGAFile);
+
+ WORD anXOrigin;
+ p_fread(&anXOrigin, sizeof(WORD), 1, aTGAFile);
+
+ WORD aYOrigin;
+ p_fread(&aYOrigin, sizeof(WORD), 1, aTGAFile);
+
+ WORD anImageWidth;
+ p_fread(&anImageWidth, sizeof(WORD), 1, aTGAFile);
+
+ WORD anImageHeight;
+ p_fread(&anImageHeight, sizeof(WORD), 1, aTGAFile);
+
+ BYTE aBitCount = 32;
+ p_fread(&aBitCount, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE anImageDescriptor = 8 | (1<<5);
+ p_fread(&anImageDescriptor, sizeof(BYTE), 1, aTGAFile);
+
+ if ((aBitCount != 32) ||
+ (anImageDescriptor != (8 | (1<<5))))
+ {
+ p_fclose(aTGAFile);
+ return NULL;
+ }
+
+ Image* anImage = new Image();
+
+ anImage->mWidth = anImageWidth;
+ anImage->mHeight = anImageHeight;
+ anImage->mBits = new unsigned long[anImageWidth*anImageHeight];
+
+ p_fread(anImage->mBits, 4, anImage->mWidth*anImage->mHeight, aTGAFile);
+
+ p_fclose(aTGAFile);
+
+ return anImage;
+}
+
+int ReadBlobBlock(PFILE* fp, char* data)
+{
+ unsigned char aCount = 0;
+ p_fread(&aCount, sizeof(char), 1, fp);
+ p_fread(data, sizeof(char), aCount, fp);
+ return aCount;
+}
+
+Image* GetGIFImage(const std::string& theFileName)
+{
+ #define BitSet(byte,bit) (((byte) & (bit)) == (bit))
+ #define LSBFirstOrder(x,y) (((y) << 8) | (x))
+
+ int
+ opacity,
+ status;
+
+ register int i;
+
+ register unsigned char *p;
+
+ unsigned char
+ background,
+ c,
+ flag,
+ *global_colormap,
+ header[1664],
+ magick[12];
+
+ unsigned int
+ delay,
+ dispose,
+ global_colors,
+ image_count,
+ iterations;
+
+ /*
+ Open image file.
+ */
+
+ PFILE *fp;
+
+ if ((fp = p_fopen(theFileName.c_str(), "rb")) == NULL)
+ return NULL;
+ /*
+ Determine if this is a GIF file.
+ */
+ status=p_fread(magick, sizeof(char), 6, fp);
+
+ if (((strncmp((char *) magick,"GIF87",5) != 0) &&
+ (strncmp((char *) magick,"GIF89",5) != 0)))
+ return NULL;
+
+ global_colors=0;
+ global_colormap=(unsigned char *) NULL;
+
+ short pw;
+ short ph;
+
+ p_fread(&pw, sizeof(short), 1, fp);
+ p_fread(&ph, sizeof(short), 1, fp);
+ p_fread(&flag, sizeof(char), 1, fp);
+ p_fread(&background, sizeof(char), 1, fp);
+ p_fread(&c, sizeof(char), 1, fp);
+
+ if (BitSet(flag,0x80))
+ {
+ /*
+ opacity global colormap.
+ */
+ global_colors=1 << ((flag & 0x07)+1);
+ global_colormap=new unsigned char[3*global_colors];
+ if (global_colormap == (unsigned char *) NULL)
+ return NULL;
+
+ p_fread(global_colormap, sizeof(char), 3*global_colors, fp);
+ }
+
+ delay=0;
+ dispose=0;
+ iterations=1;
+ opacity=(-1);
+ image_count=0;
+
+ for ( ; ; )
+ {
+ if (p_fread(&c, sizeof(char), 1, fp) == 0)
+ break;
+
+ if (c == ';')
+ break; /* terminator */
+ if (c == '!')
+ {
+ /*
+ GIF Extension block.
+ */
+ p_fread(&c, sizeof(char), 1, fp);
+
+ switch (c)
+ {
+ case 0xf9:
+ {
+ /*
+ Read Graphics Control extension.
+ */
+ while (ReadBlobBlock(fp,(char *) header) > 0);
+
+ dispose=header[0] >> 2;
+ delay=(header[2] << 8) | header[1];
+ if ((header[0] & 0x01) == 1)
+ opacity=header[3];
+ break;
+ }
+ case 0xfe:
+ {
+ char *comments;
+ int length;
+
+ /*
+ Read Comment extension.
+ */
+ comments=(char *) NULL;
+ for ( ; ; )
+ {
+ length=ReadBlobBlock(fp,(char *) header);
+ if (length <= 0)
+ break;
+ if (comments == NULL)
+ {
+ comments= new char[length+1];
+ if (comments != (char *) NULL)
+ *comments='\0';
+ }
+
+ header[length]='\0';
+ strcat(comments,(char *) header);
+ }
+ if (comments == (char *) NULL)
+ break;
+
+ delete comments;
+ break;
+ }
+ case 0xff:
+ {
+ int
+ loop;
+
+ /*
+ Read Netscape Loop extension.
+ */
+ loop=false;
+ if (ReadBlobBlock(fp,(char *) header) > 0)
+ loop=!strncmp((char *) header,"NETSCAPE2.0",11);
+ while (ReadBlobBlock(fp,(char *) header) > 0)
+ if (loop)
+ iterations=(header[2] << 8) | header[1];
+ break;
+ }
+ default:
+ {
+ while (ReadBlobBlock(fp,(char *) header) > 0);
+ break;
+ }
+ }
+ }
+
+ if (c != ',')
+ continue;
+
+ if (image_count != 0)
+ {
+ /*
+ Allocate next image structure.
+ */
+
+ /*AllocateNextImage(image_info,image);
+ if (image->next == (Image *) NULL)
+ {
+ DestroyImages(image);
+ return((Image *) NULL);
+ }
+ image=image->next;
+ MagickMonitor(LoadImagesText,TellBlob(image),image->filesize);*/
+ }
+ image_count++;
+
+ short pagex;
+ short pagey;
+ short width;
+ short height;
+ int colors;
+ bool interlaced;
+
+ p_fread(&pagex, sizeof(short), 1, fp);
+ p_fread(&pagey, sizeof(short), 1, fp);
+ p_fread(&width, sizeof(short), 1, fp);
+ p_fread(&height, sizeof(short), 1, fp);
+ p_fread(&flag, sizeof(char), 1, fp);
+
+ colors=!BitSet(flag,0x80) ? global_colors : 1 << ((flag & 0x07)+1);
+ unsigned long* colortable = new unsigned long[colors];
+
+ interlaced = BitSet(flag,0x40);
+
+ delay=0;
+ dispose=0;
+ iterations=1;
+ /*if (image_info->ping)
+ {
+ f (opacity >= 0)
+ /image->matte=true;
+
+ CloseBlob(image);
+ return(image);
+ }*/
+ if ((width == 0) || (height == 0))
+ return NULL;
+ /*
+ Inititialize colormap.
+ */
+ /*if (!AllocateImageColormap(image,image->colors))
+ ThrowReaderException(ResourceLimitWarning,"Memory allocation failed",
+ image);*/
+ if (!BitSet(flag,0x80))
+ {
+ /*
+ Use global colormap.
+ */
+ p=global_colormap;
+ for (i=0; i < (int) colors; i++)
+ {
+ int r = *p++;
+ int g = *p++;
+ int b = *p++;
+
+ colortable[i] = 0xFF000000 | (r << 16) | (g << 8) | (b);
+ }
+
+ //image->background_color=
+ //image->colormap[Min(background,image->colors-1)];
+ }
+ else
+ {
+ unsigned char
+ *colormap;
+
+ /*
+ Read local colormap.
+ */
+ colormap=new unsigned char[3*colors];
+
+ int pos = p_ftell(fp);
+ p_fread(colormap, sizeof(char), 3*colors, fp);
+
+ p=colormap;
+ for (i=0; i < (int) colors; i++)
+ {
+ int r = *p++;
+ int g = *p++;
+ int b = *p++;
+
+ colortable[i] = 0xFF000000 | (r << 16) | (g << 8) | (b);
+ }
+ delete colormap;
+ }
+
+ /*if (opacity >= (int) colors)
+ {
+ for (i=colors; i < (opacity+1); i++)
+ {
+ image->colormap[i].red=0;
+ image->colormap[i].green=0;
+ image->colormap[i].blue=0;
+ }
+ image->colors=opacity+1;
+ }*/
+ /*
+ Decode image.
+ */
+ //status=DecodeImage(image,opacity,exception);
+
+ //if (global_colormap != (unsigned char *) NULL)
+ // LiberateMemory((void **) &global_colormap);
+ if (global_colormap != NULL)
+ {
+ delete [] global_colormap;
+ global_colormap = NULL;
+ }
+
+ //while (image->previous != (Image *) NULL)
+ // image=image->previous;
+
+ #define MaxStackSize 4096
+ #define NullCode (-1)
+
+ int
+ available,
+ bits,
+ code,
+ clear,
+ code_mask,
+ code_size,
+ count,
+ end_of_information,
+ in_code,
+ offset,
+ old_code,
+ pass,
+ y;
+
+ register int
+ x;
+
+ register unsigned int
+ datum;
+
+ short
+ *prefix;
+
+ unsigned char
+ data_size,
+ first,
+ *packet,
+ *pixel_stack,
+ *suffix,
+ *top_stack;
+
+ /*
+ Allocate decoder tables.
+ */
+
+ packet=new unsigned char[256];
+ prefix=new short[MaxStackSize];
+ suffix=new unsigned char [MaxStackSize];
+ pixel_stack= new unsigned char[MaxStackSize+1];
+
+ /*
+ Initialize GIF data stream decoder.
+ */
+ p_fread(&data_size, sizeof(char), 1, fp);
+ clear=1 << data_size;
+ end_of_information=clear+1;
+ available=clear+2;
+ old_code=NullCode;
+ code_size=data_size+1;
+ code_mask=(1 << code_size)-1;
+ for (code=0; code < clear; code++)
+ {
+ prefix[code]=0;
+ suffix[code]=(unsigned char) code;
+ }
+ /*
+ Decode GIF pixel stream.
+ */
+ datum=0;
+ bits=0;
+ c=0;
+ count=0;
+ first=0;
+ offset=0;
+ pass=0;
+ top_stack=pixel_stack;
+
+ unsigned long* aBits = new unsigned long[width*height];
+
+ register unsigned char *c = NULL;
+
+ for (y=0; y < (int) height; y++)
+ {
+ //q=SetImagePixels(image,0,offset,width,1);
+ //if (q == (PixelPacket *) NULL)
+ //break;
+ //indexes=GetIndexes(image);
+
+ unsigned long* q = aBits + offset*width;
+
+
+
+ for (x=0; x < (int) width; )
+ {
+ if (top_stack == pixel_stack)
+ {
+ if (bits < code_size)
+ {
+ /*
+ Load bytes until there is enough bits for a code.
+ */
+ if (count == 0)
+ {
+ /*
+ Read a new data block.
+ */
+ int pos = p_ftell(fp);
+
+ count=ReadBlobBlock(fp,(char *) packet);
+ if (count <= 0)
+ break;
+ c=packet;
+ }
+ datum+=(*c) << bits;
+ bits+=8;
+ c++;
+ count--;
+ continue;
+ }
+ /*
+ Get the next code.
+ */
+ code=datum & code_mask;
+ datum>>=code_size;
+ bits-=code_size;
+ /*
+ Interpret the code
+ */
+ if ((code > available) || (code == end_of_information))
+ break;
+ if (code == clear)
+ {
+ /*
+ Reset decoder.
+ */
+ code_size=data_size+1;
+ code_mask=(1 << code_size)-1;
+ available=clear+2;
+ old_code=NullCode;
+ continue;
+ }
+ if (old_code == NullCode)
+ {
+ *top_stack++=suffix[code];
+ old_code=code;
+ first=(unsigned char) code;
+ continue;
+ }
+ in_code=code;
+ if (code >= available)
+ {
+ *top_stack++=first;
+ code=old_code;
+ }
+ while (code >= clear)
+ {
+ *top_stack++=suffix[code];
+ code=prefix[code];
+ }
+ first=suffix[code];
+ /*
+ Add a new string to the string table,
+ */
+ if (available >= MaxStackSize)
+ break;
+ *top_stack++=first;
+ prefix[available]=old_code;
+ suffix[available]=first;
+ available++;
+ if (((available & code_mask) == 0) && (available < MaxStackSize))
+ {
+ code_size++;
+ code_mask+=available;
+ }
+ old_code=in_code;
+ }
+ /*
+ Pop a pixel off the pixel stack.
+ */
+ top_stack--;
+
+ int index=(*top_stack);
+
+ *q=colortable[index];
+
+ if (index == opacity)
+ *q = 0;
+
+ x++;
+ q++;
+ }
+
+ if (!interlaced)
+ offset++;
+ else
+ {
+ switch (pass)
+ {
+ case 0:
+ default:
+ {
+ offset+=8;
+ if (offset >= height)
+ {
+ pass++;
+ offset=4;
+ }
+ break;
+ }
+ case 1:
+ {
+ offset+=8;
+ if (offset >= height)
+ {
+ pass++;
+ offset=2;
+ }
+ break;
+ }
+ case 2:
+ {
+ offset+=4;
+ if (offset >= height)
+ {
+ pass++;
+ offset=1;
+ }
+ break;
+ }
+ case 3:
+ {
+ offset+=2;
+ break;
+ }
+ }
+ }
+
+ if (x < width)
+ break;
+
+ /*if (image->previous == (Image *) NULL)
+ if (QuantumTick(y,image->rows))
+ MagickMonitor(LoadImageText,y,image->rows);*/
+ }
+ delete pixel_stack;
+ delete suffix;
+ delete prefix;
+ delete packet;
+
+ delete colortable;
+
+ //if (y < image->rows)
+ //failed = true;
+
+ Image* anImage = new Image();
+
+ anImage->mWidth = width;
+ anImage->mHeight = height;
+ anImage->mBits = aBits;
+
+ //TODO: Change for animation crap
+ p_fclose(fp);
+ return anImage;
+ }
+
+ p_fclose(fp);
+
+ return NULL;
+}
+
+typedef struct my_error_mgr * my_error_ptr;
+
+struct my_error_mgr
+{
+ struct jpeg_error_mgr pub; /* "public" fields */
+
+ jmp_buf setjmp_buffer; /* for return to caller */
+};
+
+METHODDEF(void)
+my_error_exit (j_common_ptr cinfo)
+{
+ /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
+ my_error_ptr myerr = (my_error_ptr) cinfo->err;
+
+ /* Always display the message. */
+ /* We could postpone this until after returning, if we chose. */
+ (*cinfo->err->output_message) (cinfo);
+
+ /* Return control to the setjmp point */
+ longjmp(myerr->setjmp_buffer, 1);
+
+}
+
+bool ImageLib::WriteJPEGImage(const std::string& theFileName, Image* theImage)
+{
+ FILE *fp;
+
+ if ((fp = fopen(theFileName.c_str(), "wb")) == NULL)
+ return false;
+
+ struct jpeg_compress_struct cinfo;
+ struct my_error_mgr jerr;
+
+ cinfo.err = jpeg_std_error(&jerr.pub);
+ jerr.pub.error_exit = my_error_exit;
+
+ if (setjmp(jerr.setjmp_buffer))
+ {
+ /* If we get here, the JPEG code has signaled an error.
+ * We need to clean up the JPEG object, close the input file, and return.
+ */
+ jpeg_destroy_compress(&cinfo);
+ fclose(fp);
+ return false;
+ }
+
+ jpeg_create_compress(&cinfo);
+
+ cinfo.image_width = theImage->mWidth;
+ cinfo.image_height = theImage->mHeight;
+ cinfo.input_components = 3;
+ cinfo.in_color_space = JCS_RGB;
+ cinfo.optimize_coding = 1;
+ jpeg_set_defaults(&cinfo);
+ jpeg_set_quality(&cinfo, 80, TRUE);
+
+ jpeg_stdio_dest(&cinfo, fp);
+
+ jpeg_start_compress(&cinfo, true);
+
+ int row_stride = theImage->GetWidth() * 3;
+
+ unsigned char* aTempBuffer = new unsigned char[row_stride];
+
+ unsigned long* aSrcPtr = theImage->mBits;
+
+ for (int aRow = 0; aRow < theImage->mHeight; aRow++)
+ {
+ unsigned char* aDest = aTempBuffer;
+
+ for (int aCol = 0; aCol < theImage->mWidth; aCol++)
+ {
+ unsigned long src = *(aSrcPtr++);
+
+ *aDest++ = (src >> 16) & 0xFF;
+ *aDest++ = (src >> 8) & 0xFF;
+ *aDest++ = (src ) & 0xFF;
+ }
+
+ jpeg_write_scanlines(&cinfo, &aTempBuffer, 1);
+ }
+
+ delete [] aTempBuffer;
+
+ jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
+
+ fclose(fp);
+
+ return true;
+}
+
+bool ImageLib::WritePNGImage(const std::string& theFileName, Image* theImage)
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+
+ FILE *fp;
+
+ if ((fp = fopen(theFileName.c_str(), "wb")) == NULL)
+ return false;
+
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
+ NULL, NULL, NULL);
+
+ if (png_ptr == NULL)
+ {
+ fclose(fp);
+ return false;
+ }
+
+ // Allocate/initialize the memory for image information. REQUIRED.
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ {
+ fclose(fp);
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ return false;
+ }
+
+ // Set error handling if you are using the setjmp/longjmp method (this is
+ // the normal method of doing things with libpng). REQUIRED unless you
+ // set up your own error handlers in the png_create_write_struct() earlier.
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ // Free all of the memory associated with the png_ptr and info_ptr
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ fclose(fp);
+ // If we get here, we had a problem writeing the file
+ return NULL;
+ }
+
+ png_init_io(png_ptr, fp);
+
+ png_color_8 sig_bit;
+ sig_bit.red = 8;
+ sig_bit.green = 8;
+ sig_bit.blue = 8;
+ /* if the image has an alpha channel then */
+ sig_bit.alpha = 8;
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+ png_set_bgr(png_ptr);
+
+ png_set_IHDR(png_ptr, info_ptr, theImage->mWidth, theImage->mHeight, 8, PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+ // Add filler (or alpha) byte (before/after each RGB triplet)
+ //png_set_expand(png_ptr);
+ //png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
+ //png_set_gray_1_2_4_to_8(png_ptr);
+ //png_set_palette_to_rgb(png_ptr);
+ //png_set_gray_to_rgb(png_ptr);
+
+ png_write_info(png_ptr, info_ptr);
+
+ for (int i = 0; i < theImage->mHeight; i++)
+ {
+ png_bytep aRowPtr = (png_bytep) (theImage->mBits + i*theImage->mWidth);
+ png_write_rows(png_ptr, &aRowPtr, 1);
+ }
+
+ // write rest of file, and get additional chunks in info_ptr - REQUIRED
+ png_write_end(png_ptr, info_ptr);
+
+ // clean up after the write, and free any memory allocated - REQUIRED
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ // close the file
+ fclose(fp);
+
+ return true;
+}
+
+bool ImageLib::WriteTGAImage(const std::string& theFileName, Image* theImage)
+{
+ FILE* aTGAFile = fopen(theFileName.c_str(), "wb");
+ if (aTGAFile == NULL)
+ return false;
+
+ BYTE aHeaderIDLen = 0;
+ fwrite(&aHeaderIDLen, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE aColorMapType = 0;
+ fwrite(&aColorMapType, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE anImageType = 2;
+ fwrite(&anImageType, sizeof(BYTE), 1, aTGAFile);
+
+ WORD aFirstEntryIdx = 0;
+ fwrite(&aFirstEntryIdx, sizeof(WORD), 1, aTGAFile);
+
+ WORD aColorMapLen = 0;
+ fwrite(&aColorMapLen, sizeof(WORD), 1, aTGAFile);
+
+ BYTE aColorMapEntrySize = 0;
+ fwrite(&aColorMapEntrySize, sizeof(BYTE), 1, aTGAFile);
+
+ WORD anXOrigin = 0;
+ fwrite(&anXOrigin, sizeof(WORD), 1, aTGAFile);
+
+ WORD aYOrigin = 0;
+ fwrite(&aYOrigin, sizeof(WORD), 1, aTGAFile);
+
+ WORD anImageWidth = theImage->mWidth;
+ fwrite(&anImageWidth, sizeof(WORD), 1, aTGAFile);
+
+ WORD anImageHeight = theImage->mHeight;
+ fwrite(&anImageHeight, sizeof(WORD), 1, aTGAFile);
+
+ BYTE aBitCount = 32;
+ fwrite(&aBitCount, sizeof(BYTE), 1, aTGAFile);
+
+ BYTE anImageDescriptor = 8 | (1<<5);
+ fwrite(&anImageDescriptor, sizeof(BYTE), 1, aTGAFile);
+
+ fwrite(theImage->mBits, 4, theImage->mWidth*theImage->mHeight, aTGAFile);
+
+ fclose(aTGAFile);
+
+ return true;
+}
+
+bool ImageLib::WriteBMPImage(const std::string& theFileName, Image* theImage)
+{
+ FILE* aFile = fopen(theFileName.c_str(), "wb");
+ if (aFile == NULL)
+ return false;
+
+ BITMAPFILEHEADER aFileHeader;
+ BITMAPINFOHEADER aHeader;
+
+ memset(&aFileHeader,0,sizeof(aFileHeader));
+ memset(&aHeader,0,sizeof(aHeader));
+
+ int aNumBytes = theImage->mWidth*theImage->mHeight*4;
+
+ aFileHeader.bfType = ('M'<<8) | 'B';
+ aFileHeader.bfSize = sizeof(aFileHeader) + sizeof(aHeader) + aNumBytes;
+ aFileHeader.bfOffBits = sizeof(aHeader);
+
+ aHeader.biSize = sizeof(aHeader);
+ aHeader.biWidth = theImage->mWidth;
+ aHeader.biHeight = theImage->mHeight;
+ aHeader.biPlanes = 1;
+ aHeader.biBitCount = 32;
+ aHeader.biCompression = BI_RGB;
+
+ fwrite(&aFileHeader,sizeof(aFileHeader),1,aFile);
+ fwrite(&aHeader,sizeof(aHeader),1,aFile);
+ DWORD *aRow = theImage->mBits + (theImage->mHeight-1)*theImage->mWidth;
+ int aRowSize = theImage->mWidth*4;
+ for (int i=0; i<theImage->mHeight; i++, aRow-=theImage->mWidth)
+ fwrite(aRow,4,theImage->mWidth,aFile);
+
+ fclose(aFile);
+ return true;
+}
+
+//////////////////////////////////////////////////////////////////////////
+// JPEG Pak Reader
+
+typedef struct {
+ struct jpeg_source_mgr pub; /* public fields */
+
+ PFILE * infile; /* source stream */
+ JOCTET * buffer; /* start of buffer */
+ boolean start_of_file; /* have we gotten any data yet? */
+} pak_source_mgr;
+
+typedef pak_source_mgr * pak_src_ptr;
+
+#define INPUT_BUF_SIZE 4096
+
+METHODDEF(void) init_source (j_decompress_ptr cinfo)
+{
+ pak_src_ptr src = (pak_src_ptr) cinfo->src;
+ src->start_of_file = TRUE;
+}
+
+METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo)
+{
+ pak_src_ptr src = (pak_src_ptr) cinfo->src;
+ size_t nbytes;
+
+ nbytes = p_fread(src->buffer, 1, INPUT_BUF_SIZE, src->infile);
+ //((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
+
+ if (nbytes <= 0) {
+ if (src->start_of_file) /* Treat empty input file as fatal error */
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
+ WARNMS(cinfo, JWRN_JPEG_EOF);
+ /* Insert a fake EOI marker */
+ src->buffer[0] = (JOCTET) 0xFF;
+ src->buffer[1] = (JOCTET) JPEG_EOI;
+ nbytes = 2;
+ }
+
+ src->pub.next_input_byte = src->buffer;
+ src->pub.bytes_in_buffer = nbytes;
+ src->start_of_file = FALSE;
+
+ return TRUE;
+}
+
+METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes)
+{
+ pak_src_ptr src = (pak_src_ptr) cinfo->src;
+
+ if (num_bytes > 0) {
+ while (num_bytes > (long) src->pub.bytes_in_buffer) {
+ num_bytes -= (long) src->pub.bytes_in_buffer;
+ (void) fill_input_buffer(cinfo);
+ }
+ src->pub.next_input_byte += (size_t) num_bytes;
+ src->pub.bytes_in_buffer -= (size_t) num_bytes;
+ }
+}
+
+METHODDEF(void) term_source (j_decompress_ptr cinfo)
+{
+ /* no work necessary here */
+}
+
+void jpeg_pak_src (j_decompress_ptr cinfo, PFILE* infile)
+{
+ pak_src_ptr src;
+
+ /* The source object and input buffer are made permanent so that a series
+ * of JPEG images can be read from the same file by calling jpeg_stdio_src
+ * only before the first one. (If we discarded the buffer at the end of
+ * one image, we'd likely lose the start of the next one.)
+ * This makes it unsafe to use this manager and a different source
+ * manager serially with the same JPEG object. Caveat programmer.
+ */
+ if (cinfo->src == NULL) { /* first time for this JPEG object? */
+ cinfo->src = (struct jpeg_source_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ sizeof(pak_source_mgr));
+ src = (pak_src_ptr) cinfo->src;
+ src->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ INPUT_BUF_SIZE * sizeof(JOCTET));
+ }
+
+ src = (pak_src_ptr) cinfo->src;
+ 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; /* use default method */
+ src->pub.term_source = term_source;
+ src->infile = infile;
+ src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+ src->pub.next_input_byte = NULL; /* until buffer loaded */
+}
+
+
+Image* GetJPEGImage(const std::string& theFileName)
+{
+ PFILE *fp;
+
+ if ((fp = p_fopen(theFileName.c_str(), "rb")) == NULL)
+ return NULL;
+
+ struct jpeg_decompress_struct cinfo;
+ struct my_error_mgr jerr;
+
+ cinfo.err = jpeg_std_error(&jerr.pub);
+ jerr.pub.error_exit = my_error_exit;
+
+ if (setjmp(jerr.setjmp_buffer))
+ {
+ /* If we get here, the JPEG code has signaled an error.
+ * We need to clean up the JPEG object, close the input file, and return.
+ */
+ jpeg_destroy_decompress(&cinfo);
+ p_fclose(fp);
+ return 0;
+ }
+
+ jpeg_create_decompress(&cinfo);
+ jpeg_pak_src(&cinfo, fp);
+ jpeg_read_header(&cinfo, TRUE);
+ jpeg_start_decompress(&cinfo);
+ int row_stride = cinfo.output_width * cinfo.output_components;
+
+ unsigned char** buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
+
+ unsigned long* aBits = new unsigned long[cinfo.output_width*cinfo.output_height];
+ unsigned long* q = aBits;
+
+ if (cinfo.output_components==1)
+ {
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+
+ unsigned char* p = *buffer;
+ for (int i = 0; i < cinfo.output_width; i++)
+ {
+ int r = *p++;
+ *q++ = 0xFF000000 | (r << 16) | (r << 8) | (r);
+ }
+ }
+ }
+ else
+ {
+ while (cinfo.output_scanline < cinfo.output_height)
+ {
+ jpeg_read_scanlines(&cinfo, buffer, 1);
+
+ unsigned char* p = *buffer;
+ for (int i = 0; i < cinfo.output_width; i++)
+ {
+ int r = *p++;
+ int g = *p++;
+ int b = *p++;
+
+ *q++ = 0xFF000000 | (r << 16) | (g << 8) | (b);
+ }
+ }
+ }
+
+ Image* anImage = new Image();
+ anImage->mWidth = cinfo.output_width;
+ anImage->mHeight = cinfo.output_height;
+ anImage->mBits = aBits;
+
+ jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+
+ p_fclose(fp);
+
+ return anImage;
+}
+
+#if 0
+Image* GetJPEG2000Image(const std::string& theFileName)
+{
+ DWORD aTick = GetTickCount();
+
+ static bool inited = false;
+ if (!inited)
+ {
+ inited = true;
+ jas_init();
+ }
+
+ jas_stream_t* aStream = jas_stream_fopen(theFileName.c_str(),"rb");
+ if (!aStream)
+ return NULL;
+
+ // Read Image Header
+ int aFormat = jas_image_getfmt(aStream);
+ if (aFormat < 0)
+ {
+ jas_stream_close(aStream);
+ return NULL;
+ }
+
+ jas_image_t* aJasImage = jas_image_decode(aStream,aFormat,NULL);
+ if (!aJasImage)
+ {
+ jas_stream_close(aStream);
+ return NULL;
+ }
+
+ DWORD aDecodeTime = GetTickCount() - aTick;
+
+ int aNumComponents = jas_image_numcmpts(aJasImage);
+ if (aNumComponents<1 || aNumComponents>4)
+ {
+ jas_stream_close(aStream);
+ jas_image_destroy(aJasImage);
+ return NULL;
+ }
+
+ int i;
+ int aMaxWidth = 0;
+ int aMaxHeight = 0;
+ for (i=0; i<aNumComponents; i++)
+ {
+ int hstep = jas_image_cmpthstep(aJasImage,i);
+ int numHSteps = jas_image_cmptwidth(aJasImage,i);
+
+ int vstep = jas_image_cmptvstep(aJasImage,i);
+ int numVSteps = jas_image_cmptheight(aJasImage,i);
+
+ int aWidth = jas_image_cmpttlx(aJasImage,i) + hstep*numHSteps;
+ int aHeight = jas_image_cmpttly(aJasImage,i) + vstep*numVSteps;
+
+ if (aWidth > aMaxWidth)
+ aMaxWidth = aWidth;
+
+ if (aHeight > aMaxHeight)
+ aMaxHeight = aHeight;
+ }
+
+ // Read Image Data
+ Image *anImage = new Image;
+ anImage->mWidth = aMaxWidth;
+ anImage->mHeight = aMaxHeight;
+ anImage->mBits = new unsigned long[aMaxWidth * aMaxHeight];
+ memset(anImage->mBits,0,aMaxWidth * aMaxHeight*4);
+
+ int aColorModel = jas_image_clrspc(aJasImage);
+
+ for (i=0; i<aNumComponents; i++)
+ {
+ int hstep = jas_image_cmpthstep(aJasImage,i);
+ int vstep = jas_image_cmptvstep(aJasImage,i);
+ int numHSteps = jas_image_cmptwidth(aJasImage,i);
+ int numVSteps = jas_image_cmptheight(aJasImage,i);
+ int xorig = jas_image_cmpttlx(aJasImage,i);
+ int yorig = jas_image_cmpttly(aJasImage,i);
+ bool sign = jas_image_cmptsgnd(aJasImage,i)?true:false;
+
+ jas_matrix_t* aMatrix = jas_matrix_create(1,numHSteps);
+ if (!aMatrix)
+ {
+ delete anImage;
+ jas_image_destroy(aJasImage);
+ jas_stream_close(aStream);
+
+ return NULL;
+ }
+
+ int aShift = 8 - jas_image_cmptprec(aJasImage,i);
+ if (aShift<0)
+ {
+ delete anImage;
+ jas_matrix_destroy(aMatrix);
+ jas_image_destroy(aJasImage);
+ jas_stream_close(aStream);
+
+ return NULL;
+ }
+
+ unsigned long* destRow = anImage->mBits + yorig*numVSteps*anImage->GetWidth() + xorig*numHSteps;
+
+ // color model
+ int aComponentType = jas_image_cmpttype(aJasImage,i);
+ int aColorType = JAS_IMAGE_CT_COLOR(aComponentType);
+
+ switch (aColorType)
+ {
+ case JAS_IMAGE_CT_RGB_R: aShift += 16; break;
+ case JAS_IMAGE_CT_RGB_G: aShift += 8; break;
+ case JAS_IMAGE_CT_RGB_B: break;
+ default: aShift += 24; break;
+ }
+
+ for (int y=0; y<numVSteps; y++)
+ {
+ if (jas_image_readcmpt(aJasImage,i,0,y,numHSteps,1,aMatrix) )
+ {
+ delete anImage;
+ jas_matrix_destroy(aMatrix);
+ jas_image_destroy(aJasImage);
+ jas_stream_close(aStream);
+
+ return NULL;
+ }
+
+ unsigned long* dest = destRow;
+ for (int x=0; x<numHSteps; x++)
+ {
+ int aVal = jas_matrix_getv(aMatrix,x);
+ if (sign)
+ aVal = (unsigned char)(aVal + 128);
+
+ aVal <<= aShift;
+
+ unsigned long *destRowWriter = dest;
+ for (int j=0; j<vstep; j++)
+ {
+ unsigned long *destWriter = destRowWriter;
+ for (int k=0; k<hstep; k++)
+ *destWriter++ |= aVal;
+
+ destRowWriter += anImage->GetWidth();
+ }
+
+ dest += hstep;
+ }
+ destRow += vstep*anImage->GetWidth();
+ }
+
+ // release decoding matrix
+ jas_matrix_destroy(aMatrix);
+ }
+
+ DWORD aReadTime = GetTickCount() - aTick;
+ char aBuf[512];
+ sprintf(aBuf,"%d %d\n",aDecodeTime,aReadTime);
+ OutputDebugString(aBuf);
+
+
+ if (aNumComponents < 4) // add 255 alpha
+ {
+ int aSize = anImage->GetWidth()*anImage->GetHeight();
+ unsigned long *dest = anImage->mBits;
+ for (i=0; i<aSize; i++)
+ *dest++ |= 0xff000000;
+ }
+
+ jas_image_destroy(aJasImage);
+ jas_stream_close(aStream);
+
+ return anImage;
+}
+#else
+
+#include "j2k-codec\j2k-codec.h"
+
+HMODULE gJ2KCodec = NULL;
+std::string gJ2KCodecKey = "Your registration here";
+
+void ImageLib::InitJPEG2000()
+{
+ gJ2KCodec = ::LoadLibrary(_T("j2k-codec.dll"));
+}
+
+void ImageLib::CloseJPEG2000()
+{
+ if (gJ2KCodec != NULL)
+ {
+ ::FreeLibrary(gJ2KCodec);
+ gJ2KCodec = NULL;
+ }
+}
+
+void ImageLib::SetJ2KCodecKey(const std::string& theKey)
+{
+ gJ2KCodecKey = theKey;
+}
+
+int __stdcall Pak_seek(void *data_source, int offset)
+{
+ return p_fseek((PFILE*) data_source, offset, SEEK_SET);
+}
+
+int __stdcall Pak_read(void *ptr, int size, void *data_source)
+{
+ return p_fread(ptr, 1, size, (PFILE*) data_source);
+}
+
+void __stdcall Pak_close(void *data_source)
+{
+}
+
+Image* GetJPEG2000Image(const std::string& theFileName)
+{
+ if (gJ2KCodec != NULL)
+ {
+ PFILE* aFP = p_fopen(theFileName.c_str(), "rb");
+ if (aFP == NULL)
+ return NULL;
+
+ static int (__stdcall *fJ2K_getVersion)() = NULL;
+ static void (__stdcall *fJ2K_Unlock)(const char*) = NULL;
+ static void* (__stdcall *fJ2K_OpenCustom)(void*, J2K_Callbacks*) = NULL;
+ static void* (__stdcall *fJ2K_OpenFile)(const char*) = NULL;
+ static void (__stdcall *fJ2K_Close)(void*) = NULL;
+ static int (__stdcall *fJ2K_GetInfo)(void*, int*, int*, int*) = NULL;
+ static int (__stdcall *fJ2K_GetResolutionDimensions)(void*, int, int*, int*) = NULL;
+ static int (__stdcall *fJ2K_Decode)(void*, unsigned char**, int*, char*, int*) = NULL;
+ static int (__stdcall *fJ2K_getLastError)() = NULL;
+ static const char* (__stdcall *fJ2K_getErrorStr)(int) = NULL;
+ static bool loadFuncs = true;
+
+ if (loadFuncs)
+ {
+ loadFuncs = false;
+ *((void**)&fJ2K_getVersion) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_getVersion@0");
+ *((void**)&fJ2K_Unlock) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_Unlock@4");
+ *((void**)&fJ2K_OpenCustom) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_OpenCustom@8");
+ *((void**)&fJ2K_OpenFile) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_OpenFile@4");
+ *((void**)&fJ2K_Close) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_Close@4");
+ *((void**)&fJ2K_GetInfo) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_GetInfo@16");
+ *((void**)&fJ2K_GetResolutionDimensions) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_GetResolutionDimensions@16");
+ *((void**)&fJ2K_Decode) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_Decode@20");
+ *((void**)&fJ2K_getLastError) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_getLastError@0");
+ *((void**)&fJ2K_getErrorStr) = (void*)::GetProcAddress(gJ2KCodec, "_J2K_getErrorStr@4");
+
+ // j2k guys didn't use declare the export names. yay! now we have to update these mangled names any time the DLL changes.
+
+ if (!(fJ2K_getVersion != NULL &&
+ fJ2K_Unlock != NULL &&
+ fJ2K_OpenCustom != NULL &&
+ fJ2K_OpenFile != NULL &&
+ fJ2K_Close != NULL &&
+ fJ2K_GetInfo != NULL &&
+ fJ2K_GetResolutionDimensions != NULL &&
+ fJ2K_Decode != NULL &&
+ fJ2K_getLastError != NULL &&
+ fJ2K_getErrorStr != NULL))
+ {
+ CloseJPEG2000();
+ return NULL;
+ }
+
+ int aJ2kVer = (*fJ2K_getVersion)();
+ if (aJ2kVer < 0x120000)
+ {
+ CloseJPEG2000();
+ return NULL;
+ }
+
+ (*fJ2K_Unlock)(gJ2KCodecKey.c_str());
+ }
+
+ J2K_Callbacks aCallbacks;
+ aCallbacks.read = Pak_read;
+ aCallbacks.seek = Pak_seek;
+ aCallbacks.close = Pak_close;
+
+ //theFileName.c_str()
+ void* aJ2KImage = (*fJ2K_OpenCustom)(aFP, &aCallbacks);
+ if (aJ2KImage == NULL)
+ {
+ int anErrNum = (*fJ2K_getLastError)();
+ std::string anErrorMessage = (*fJ2K_getErrorStr)(anErrNum);
+ return NULL;
+ }
+
+ int aWidth, aHeight, aComponents;
+ if ((*fJ2K_GetInfo)(aJ2KImage, &aWidth, &aHeight, &aComponents) != J2KERR_SUCCESS)
+ {
+ (*fJ2K_Close)(aJ2KImage);
+ return NULL;
+ }
+
+ (*fJ2K_GetResolutionDimensions)(aJ2KImage, 0, &aWidth, &aHeight);
+
+ unsigned long* aBuffer = new unsigned long[aWidth*aHeight];
+ if (aBuffer == NULL)
+ {
+ (*fJ2K_Close)(aJ2KImage);
+ return NULL;
+ }
+
+ char anOptsBuffer[32];
+ strcpy(anOptsBuffer, "bpp=4,rl=0");
+
+ int aSize = aWidth*aHeight*4;
+ int aPitch = aWidth*4;
+ if ((*fJ2K_Decode)(aJ2KImage, (unsigned char**)&aBuffer, &aSize, anOptsBuffer, &aPitch) != J2KERR_SUCCESS)
+ {
+ (*fJ2K_Close)(aJ2KImage);
+ delete[] aBuffer;
+ return NULL;
+ }
+ (*fJ2K_Close)(aJ2KImage);
+
+ ImageLib::Image* anImage = new ImageLib::Image;
+ anImage->mBits = aBuffer;
+ anImage->mWidth = aWidth;
+ anImage->mHeight = aHeight;
+ if (gIgnoreJPEG2000Alpha)
+ {
+ DWORD *aPtr = anImage->mBits;
+ DWORD *anEnd = aPtr+anImage->mWidth*anImage->mHeight;
+ for (; aPtr!=anEnd; ++aPtr)
+ *aPtr |= 0xFF000000;
+ }
+
+ p_fclose(aFP);
+
+ return anImage;
+ }
+ return NULL;
+}
+
+#endif
+
+
+int ImageLib::gAlphaComposeColor = 0xFFFFFF;
+bool ImageLib::gAutoLoadAlpha = true;
+bool ImageLib::gIgnoreJPEG2000Alpha = true;
+
+Image* ImageLib::GetImage(const std::string& theFilename, bool lookForAlphaImage)
+{
+ if (!gAutoLoadAlpha)
+ lookForAlphaImage = false;
+
+ int aLastDotPos = theFilename.rfind('.');
+ int aLastSlashPos = max((int)theFilename.rfind('\\'), (int)theFilename.rfind('/'));
+
+ std::string anExt;
+ std::string aFilename;
+
+ if (aLastDotPos > aLastSlashPos)
+ {
+ anExt = theFilename.substr(aLastDotPos, theFilename.length() - aLastDotPos);
+ aFilename = theFilename.substr(0, aLastDotPos);
+ }
+ else
+ aFilename = theFilename;
+
+ Image* anImage = NULL;
+
+ if ((anImage == NULL) && ((stricmp(anExt.c_str(), ".tga") == 0) || (anExt.length() == 0)))
+ anImage = GetTGAImage(aFilename + ".tga");
+
+ if ((anImage == NULL) && ((stricmp(anExt.c_str(), ".jpg") == 0) || (anExt.length() == 0)))
+ anImage = GetJPEGImage(aFilename + ".jpg");
+
+ if ((anImage == NULL) && ((stricmp(anExt.c_str(), ".png") == 0) || (anExt.length() == 0)))
+ anImage = GetPNGImage(aFilename + ".png");
+
+ if ((anImage == NULL) && ((stricmp(anExt.c_str(), ".gif") == 0) || (anExt.length() == 0)))
+ anImage = GetGIFImage(aFilename + ".gif");
+
+ if (anImage == NULL && (stricmp(anExt.c_str(), ".j2k") == 0 || anExt.length() == 0))
+ anImage = GetJPEG2000Image(aFilename + ".j2k");
+ if (anImage == NULL && (stricmp(anExt.c_str(), ".jp2") == 0 || anExt.length() == 0))
+ anImage = GetJPEG2000Image(aFilename + ".jp2");
+
+
+ // Check for alpha images
+ Image* anAlphaImage = NULL;
+ if(lookForAlphaImage)
+ {
+ // Check _ImageName
+ anAlphaImage = GetImage(theFilename.substr(0, aLastSlashPos+1) + "_" +
+ theFilename.substr(aLastSlashPos+1, theFilename.length() - aLastSlashPos - 1), false);
+
+ // Check ImageName_
+ if(anAlphaImage==NULL)
+ anAlphaImage = GetImage(theFilename + "_", false);
+ }
+
+
+
+ // Compose alpha channel with image
+ if (anAlphaImage != NULL)
+ {
+ if (anImage != NULL)
+ {
+ if ((anImage->mWidth == anAlphaImage->mWidth) &&
+ (anImage->mHeight == anAlphaImage->mHeight))
+ {
+ unsigned long* aBits1 = anImage->mBits;
+ unsigned long* aBits2 = anAlphaImage->mBits;
+ int aSize = anImage->mWidth*anImage->mHeight;
+
+ for (int i = 0; i < aSize; i++)
+ {
+ *aBits1 = (*aBits1 & 0x00FFFFFF) | ((*aBits2 & 0xFF) << 24);
+ ++aBits1;
+ ++aBits2;
+ }
+ }
+
+ delete anAlphaImage;
+ }
+ else if (gAlphaComposeColor==0xFFFFFF)
+ {
+ anImage = anAlphaImage;
+
+ unsigned long* aBits1 = anImage->mBits;
+
+ int aSize = anImage->mWidth*anImage->mHeight;
+ for (int i = 0; i < aSize; i++)
+ {
+ *aBits1 = (0x00FFFFFF) | ((*aBits1 & 0xFF) << 24);
+ ++aBits1;
+ }
+ }
+ else
+ {
+ const int aColor = gAlphaComposeColor;
+ anImage = anAlphaImage;
+
+ unsigned long* aBits1 = anImage->mBits;
+
+ int aSize = anImage->mWidth*anImage->mHeight;
+ for (int i = 0; i < aSize; i++)
+ {
+ *aBits1 = aColor | ((*aBits1 & 0xFF) << 24);
+ ++aBits1;
+ }
+ }
+ }
+
+ return anImage;
+}
diff --git a/osframework/source/ImageLib/ImageLib.dsp b/osframework/source/ImageLib/ImageLib.dsp
new file mode 100644
index 0000000..21b5732
--- /dev/null
+++ b/osframework/source/ImageLib/ImageLib.dsp
@@ -0,0 +1,481 @@
+# Microsoft Developer Studio Project File - Name="ImageLib" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=ImageLib - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "ImageLib.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "ImageLib.mak" CFG="ImageLib - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "ImageLib - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "ImageLib - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""$/WinAlch", YKBAAAAA"
+# PROP Scc_LocalPath "..\winalch"
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "ImageLib - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "_LIB" /D "WIN32" /D "_WINDOWS" /D "_VISUALC_" /D "_IMAGE_MAGICK_JPEG_" /D "_JPEGLIB_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /fo"WinDM.res" /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "ImageLib - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "NDEBUG" /D "_LIB" /D "WIN32" /D "_WINDOWS" /D "_VISUALC_" /D "_IMAGE_MAGICK_JPEG_" /D "_JPEGLIB_" /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /fo"WinDM.res" /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "ImageLib - Win32 Release"
+# Name "ImageLib - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\ImageLib.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\ImageLib.h
+# End Source File
+# End Group
+# Begin Group "PNG"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\png\png.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\png.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngasmrd.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngconf.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngget.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngmem.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngpread.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngread.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngrio.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngrtran.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngrutil.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngset.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngtrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngvcrd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngwio.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngwrite.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngwtran.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png\pngwutil.c
+# End Source File
+# End Group
+# Begin Group "JPEG"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\jpeg\cderror.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\cdjpeg.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\cdjpeg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcapimin.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcapistd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jccoefct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jccolor.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcdctmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jchuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jchuff.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcinit.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcmainct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcmarker.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcmaster.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcomapi.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jconfig.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcparam.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcphuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcprepct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jcsample.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jctrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdapimin.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdapistd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdatadst.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdatasrc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdcoefct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdcolor.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdct.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jddctmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdhuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdhuff.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdinput.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdmainct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdmarker.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdmaster.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdmerge.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdphuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdpostct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdsample.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jdtrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jerror.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jfdctflt.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jfdctfst.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jfdctint.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jidctflt.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jidctfst.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jidctint.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jidctred.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jinclude.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jmemmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jmemnobs.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jmemsys.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jmorecfg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jpegint.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jpeglib.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jquant1.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jquant2.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jutils.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\jversion.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdbmp.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdcolmap.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdgif.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdppm.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdrle.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdswitch.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\rdtarga.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\transupp.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\transupp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\wrbmp.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\wrgif.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\wrppm.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\wrrle.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\jpeg\wrtarga.c
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/ImageLib/ImageLib.h b/osframework/source/ImageLib/ImageLib.h
new file mode 100644
index 0000000..081beae
--- /dev/null
+++ b/osframework/source/ImageLib/ImageLib.h
@@ -0,0 +1,42 @@
+#ifndef __IMAGELIB_H__
+#define __IMAGELIB_H__
+
+#include <string>
+
+namespace ImageLib
+{
+
+class Image
+{
+public:
+ int mWidth;
+ int mHeight;
+ unsigned long* mBits;
+
+public:
+ Image();
+ virtual ~Image();
+
+ int GetWidth();
+ int GetHeight();
+ unsigned long* GetBits();
+};
+
+bool WriteJPEGImage(const std::string& theFileName, Image* theImage);
+bool WritePNGImage(const std::string& theFileName, Image* theImage);
+bool WriteTGAImage(const std::string& theFileName, Image* theImage);
+bool WriteBMPImage(const std::string& theFileName, Image* theImage);
+extern int gAlphaComposeColor;
+extern bool gAutoLoadAlpha;
+extern bool gIgnoreJPEG2000Alpha; // I've noticed alpha in jpeg2000's that shouldn't have alpha so this defaults to true
+
+
+Image* GetImage(const std::string& theFileName, bool lookForAlphaImage = true);
+
+void InitJPEG2000();
+void CloseJPEG2000();
+void SetJ2KCodecKey(const std::string& theKey);
+
+}
+
+#endif //__IMAGELIB_H__ \ No newline at end of file
diff --git a/osframework/source/ImageLib/ImageLib.vcproj b/osframework/source/ImageLib/ImageLib.vcproj
new file mode 100644
index 0000000..85a3a67
--- /dev/null
+++ b/osframework/source/ImageLib/ImageLib.vcproj
@@ -0,0 +1,570 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="ImageLib"
+ ProjectGUID="{BC8BFFB8-7E39-411A-B856-A75B1DF2D2F6}"
+ SccProjectName="&quot;$/WinAlch&quot;, YKBAAAAA"
+ SccLocalPath="..\winalch">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/ImageLib.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Release\ImageLib.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ PrecompiledHeaderFile=".\Debug/ImageLib.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Debug\ImageLib.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug - Zylom|Win32"
+ OutputDirectory="Debug - Zylom"
+ IntermediateDirectory="Debug - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ PrecompiledHeaderFile=".\Debug/ImageLib.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Debug\ImageLib.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release - Zylom|Win32"
+ OutputDirectory="Release - Zylom"
+ IntermediateDirectory="Release - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="NDEBUG,_LIB,WIN32,_WINDOWS,_VISUALC_,_IMAGE_MAGICK_JPEG_,_JPEGLIB_"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/ImageLib.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile=".\Release - Zylom\ImageLib.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ ResourceOutputFileName="WinDM.res"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath=".\ImageLib.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath=".\ImageLib.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="PNG"
+ Filter="">
+ <File
+ RelativePath=".\png\png.c">
+ </File>
+ <File
+ RelativePath=".\png\png.h">
+ </File>
+ <File
+ RelativePath=".\png\pngasmrd.h">
+ </File>
+ <File
+ RelativePath=".\png\pngconf.h">
+ </File>
+ <File
+ RelativePath=".\png\pngerror.c">
+ </File>
+ <File
+ RelativePath=".\png\pngget.c">
+ </File>
+ <File
+ RelativePath=".\png\pngmem.c">
+ </File>
+ <File
+ RelativePath=".\png\pngpread.c">
+ </File>
+ <File
+ RelativePath=".\png\pngread.c">
+ </File>
+ <File
+ RelativePath=".\png\pngrio.c">
+ </File>
+ <File
+ RelativePath=".\png\pngrtran.c">
+ </File>
+ <File
+ RelativePath=".\png\pngrutil.c">
+ </File>
+ <File
+ RelativePath=".\png\pngset.c">
+ </File>
+ <File
+ RelativePath=".\png\pngtrans.c">
+ </File>
+ <File
+ RelativePath=".\png\pngvcrd.c">
+ </File>
+ <File
+ RelativePath=".\png\pngwio.c">
+ </File>
+ <File
+ RelativePath=".\png\pngwrite.c">
+ </File>
+ <File
+ RelativePath=".\png\pngwtran.c">
+ </File>
+ <File
+ RelativePath=".\png\pngwutil.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG"
+ Filter="">
+ <File
+ RelativePath=".\jpeg\cderror.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\cdjpeg.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\cdjpeg.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcapimin.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcapistd.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jccoefct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jccolor.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcdctmgr.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jchuff.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jchuff.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcinit.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmainct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmarker.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcmaster.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcomapi.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jconfig.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcparam.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcphuff.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcprepct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jcsample.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jctrans.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdapimin.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdapistd.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdatadst.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdatasrc.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdcoefct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdcolor.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdct.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jddctmgr.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdhuff.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdhuff.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdinput.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmainct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmarker.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmaster.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdmerge.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdphuff.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdpostct.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdsample.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jdtrans.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jerror.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jerror.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctflt.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctfst.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jfdctint.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctflt.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctfst.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctint.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jidctred.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jinclude.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemmgr.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemnobs.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jmemsys.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jmorecfg.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jpegint.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jpeglib.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\jquant1.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jquant2.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jutils.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\jversion.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdbmp.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdcolmap.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdgif.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdppm.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdrle.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdswitch.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\rdtarga.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\transupp.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\transupp.h">
+ </File>
+ <File
+ RelativePath=".\jpeg\wrbmp.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\wrgif.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\wrppm.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\wrrle.c">
+ </File>
+ <File
+ RelativePath=".\jpeg\wrtarga.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB"
+ Filter="">
+ <File
+ RelativePath="zlib\adler32.c">
+ </File>
+ <File
+ RelativePath="zlib\compress.c">
+ </File>
+ <File
+ RelativePath="zlib\crc32.c">
+ </File>
+ <File
+ RelativePath="zlib\deflate.c">
+ </File>
+ <File
+ RelativePath="zlib\deflate.h">
+ </File>
+ <File
+ RelativePath="zlib\gzio.c">
+ </File>
+ <File
+ RelativePath="zlib\infblock.c">
+ </File>
+ <File
+ RelativePath="zlib\infblock.h">
+ </File>
+ <File
+ RelativePath="zlib\infcodes.c">
+ </File>
+ <File
+ RelativePath="zlib\infcodes.h">
+ </File>
+ <File
+ RelativePath="zlib\inffast.c">
+ </File>
+ <File
+ RelativePath="zlib\inffast.h">
+ </File>
+ <File
+ RelativePath="zlib\inffixed.h">
+ </File>
+ <File
+ RelativePath="zlib\inflate.c">
+ </File>
+ <File
+ RelativePath="zlib\inftrees.c">
+ </File>
+ <File
+ RelativePath="zlib\inftrees.h">
+ </File>
+ <File
+ RelativePath="zlib\infutil.c">
+ </File>
+ <File
+ RelativePath="zlib\infutil.h">
+ </File>
+ <File
+ RelativePath="zlib\trees.c">
+ </File>
+ <File
+ RelativePath="zlib\trees.h">
+ </File>
+ <File
+ RelativePath="zlib\uncompr.c">
+ </File>
+ <File
+ RelativePath="zlib\zconf.h">
+ </File>
+ <File
+ RelativePath="zlib\zlib.h">
+ </File>
+ <File
+ RelativePath="zlib\zutil.c">
+ </File>
+ <File
+ RelativePath="zlib\zutil.h">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/ImageLib/j2k-codec/J2K_Codec.bas b/osframework/source/ImageLib/j2k-codec/J2K_Codec.bas
new file mode 100644
index 0000000..b31c974
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/J2K_Codec.bas
@@ -0,0 +1,68 @@
+Attribute VB_Name = "J2K_Codec"
+Public Enum J2K_ERRORS
+ J2KERR_SUCCESS = 0
+ J2KERR_NEED_MMX
+ J2KERR_NOT_ENOUGH_MEMORY
+ J2KERR_CORRUPTED_DATA
+ J2KERR_PIPE_FAILURE
+ J2KERR_INVALID_ARGUMENT
+ J2KERR_CANCELED
+ J2KERR_CANT_OPEN_FILE
+ J2KERR_OPTION_UNRECOGNIZED
+ J2KERR_NO_SUCH_TILE
+ J2KERR_NO_SUCH_RESOLUTION
+ J2KERR_BPP_TOO_SMALL
+ J2KERR_BUFFER_TOO_SMALL
+ J2KERR_NOT_PART1_FORMAT
+ J2KERR_IMAGE_IS_TOO_LARGE
+ J2KERR_TOO_MANY_RES_LEVEL
+ J2KERR_TOO_LARGE_CODEBLOCKS
+ J2KERR_NO_LAZINESS
+ J2KERR_NO_VCAUSAL
+ J2KERR_TOO_MANY_COMPONENTS
+ J2KERR_ONLY_8_BIT_COMPONENTS
+ J2KERR_ONLY_UNSIG_COMPONENTS
+ J2KERR_DOWNSAMPLED_COMPONENTS
+ J2KERR_ROI_NOT_SUPPORTED
+ J2KERR_PROGR_CHANGE_NOT_SUP
+ J2KERR_PACKET_HDRS_NOT_SUP
+ J2KERR_64BIT_BOXES_NOT_SUP
+ J2KERR_INTERNAL_ERROR
+End Enum
+
+Type J2K_Info
+ Version As Long
+ Width As Long
+ Height As Long
+ Components As Long
+ FileType As Long
+ hTiles As Long
+ vTiles As Long
+End Type
+
+Declare Function J2K_getVersion Lib "j2k-codec" Alias "_J2K_getVersion@0" () As Long
+Declare Function J2K_getLastError Lib "j2k-codec" Alias "_J2K_getLastError@0" () As Long
+
+Declare Sub J2K_getErrorStr Lib "j2k-codec" Alias "_J2K_getErrorStrVB@8" (ByVal ErrCode As Long, ByVal errStr As String)
+
+Declare Sub J2K_Unlock Lib "j2k-codec" Alias "_J2K_Unlock@4" (ByVal Key As String)
+
+Declare Function J2K_StartLogging Lib "j2k-codec" Alias "_J2K_StartLogging@8" (ByVal Level As Long, ByVal Append As Boolean) As Long
+Declare Sub J2K_StopLogging Lib "j2k-codec" Alias "_J2K_StopLogging@0" ()
+
+Declare Function J2K_OpenFile Lib "j2k-codec" Alias "_J2K_OpenFile@4" (ByVal FileName As String) As Long
+Declare Function J2K_OpenMemory Lib "j2k-codec" Alias "_J2K_OpenMemory@8" (ByRef Buffer As Byte, ByVal Size as Long) As Long
+
+Declare Function J2K_GetInfo Lib "j2k-codec" Alias "_J2K_GetInfo@16" (ByVal Image As Long, ByRef Width As Long, ByRef Height As Long, ByRef Components As Long) As Long
+Declare Function J2K_GetInfoEx Lib "j2k-codec" Alias "_J2K_GetInfoEx@8" (ByVal Image As Long, info As J2K_Info) As Long
+
+Declare Function J2K_SelectTiles Lib "j2k-codec" Alias "_J2K_SelectTiles@16" (ByVal Image As Long, ByVal StartTile As Long, ByVal EndTile As Long, ByVal Action As Long) As Long
+
+Declare Function J2K_GetResolutions Lib "j2k-codec" Alias "_J2K_GetResolutions@8" (ByVal Image As Long, ByRef Resolutions As Long) As Long
+Declare Function J2K_GetResolutionDimensions Lib "j2k-codec" Alias "_J2K_GetResolutionDimensions@16" (ByVal Image As Long, ByVal ResLevel As Long, ByRef Width As Long, ByRef Height As Long) As Long
+
+Declare Function J2K_Decode Lib "j2k-codec" Alias "_J2K_Decode@20" (ByVal Image As Long, ByRef Buffer As Long, ByRef Size As Long, Optional ByVal Options As String = "", Optional ByRef Pitch As Long = 0) As Long
+
+Declare Sub J2K_Cancel Lib "j2k-codec" Alias "_J2K_Cancel@4" (ByVal Image As Long)
+
+Declare Sub J2K_Close Lib "j2k-codec" Alias "_J2K_Close@4" (ByVal Image As Long)
diff --git a/osframework/source/ImageLib/j2k-codec/J2K_Codec.cs b/osframework/source/ImageLib/j2k-codec/J2K_Codec.cs
new file mode 100644
index 0000000..1671c2d
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/J2K_Codec.cs
@@ -0,0 +1,176 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+// Application namespace - change this to match your application if needed
+namespace J2K_CodecPrj
+{
+ public abstract class J2KCodec
+ {
+ // Returns codec version and build number in the 0x105678 form, where
+ // 10 is a version (1.0) and 5678 is a build number.
+ [DllImport("j2k-codec", EntryPoint="_J2K_getVersion@0")]
+ public static extern uint GetVersion();
+
+ // Returns the code of last error. Use GetErrorString() to get
+ // textual description of the error.
+ [DllImport("j2k-codec", EntryPoint="_J2K_getLastError@0")]
+ public static extern J2KError GetLastError();
+
+ [DllImport("j2k-codec", EntryPoint="_J2K_getErrorStrVB@8")]
+ private static extern void _GetErrorString(J2KError errCode, StringBuilder errStr);
+
+ // Returns the textual description of an error by the error code
+ // obtained from getLastError().
+ public static string GetErrorString(J2KError errCode)
+ {
+ StringBuilder sb = new StringBuilder(2048);
+ _GetErrorString(errCode, sb);
+ return sb.ToString();
+ }
+
+ // Returns the textual description of the last error.
+ public static string GetLastErrorString()
+ {
+ return GetErrorString(GetLastError());
+ }
+
+ // This function unlocks the full functionality of J2K-Codec. After you
+ // have purchased your personal registration key, you need to pass it
+ // to this function.
+ [DllImport("j2k-codec", EntryPoint="_J2K_Unlock@4")]
+ public static extern void Unlock(string key);
+
+
+ // This function creates a log-file and starts logging debug messages of J2K-Codec.
+ // 'level' can be Normal or Detailed.
+ // Passing append as true will append the log session to existing log-file.
+ // Returns 0 if there was no error.
+ // NOTES:
+ // 1. Log-file name is 'j2k-codec.log'
+ // 2. The performance will degrade significantly if the logging is on.
+ [DllImport("j2k-codec", EntryPoint="_J2K_StartLogging@8")]
+ public static extern J2KError StartLogging(J2KLogLevel level, bool append);
+
+ // Use this function to stop logging, initiated by StartLogging().
+ [DllImport("j2k-codec", EntryPoint="_J2K_StopLogging@0")]
+ public static extern void StopLogging(int level, bool append);
+
+ // Open an image from a file with given name.
+ [DllImport("j2k-codec", EntryPoint="_J2K_OpenFile@4")]
+ public static extern IntPtr OpenFile(string fileName);
+
+ // Open the image from a buffer with 'size' length
+ [DllImport("j2k-codec", EntryPoint="_J2K_OpenFile@4")]
+ public static extern IntPtr OpenMemory(byte[] buffer, uint size);
+
+ // Get size information from the image
+ [DllImport("j2k-codec", EntryPoint="_J2K_GetInfo@16")]
+ public static extern J2KError GetInfo(IntPtr image, out int width, out int height, out int components);
+
+ // Get more detailed information from the image
+ [DllImport("j2k-codec", EntryPoint="_J2K_GetInfoEx@8")]
+ public static extern J2KError GetInfoEx(IntPtr image, out J2KInfo info);
+
+
+ // Get meta data, embedded into the JP2 image. See help file for parameter explanation
+ [DllImport("j2k-codec", EntryPoint="_J2K_GetInfoEx@8")]
+ public static extern J2KError GetMetaData(IntPtr image, ref int no, ref J2KMetadata type, ref IntPtr data, ref int size);
+
+ // Decodes the image, previously created with Open(). If 'buffer' is
+ // null, then the required amount of memory is allocated and its size
+ // returned through the 'size' argument. pitch - distance, in bytes, to
+ // the start of next line. For options see help file.
+ [DllImport("j2k-codec", EntryPoint="_J2K_Decode@20")]
+ public static extern J2KError Decode(IntPtr image, ref IntPtr buffer, ref int size, string options, ref int pitch);
+
+ // Selects or unselects a tile or a tile range, depending on 'select'.
+ // If select is true then the tiles are selected for decoding,
+ // otherwise they are unselected. The range is defined by start and end
+ // tile numbers (inclusive) in the raster order. If end_tile==-1 then
+ // the max tile number will be used instead.
+ [DllImport("j2k-codec", EntryPoint="_J2K_SelectTiles@16")]
+ public static extern J2KError SelectTiles(IntPtr image, int startTile, int endTile, bool select);
+
+ // Gets the number of available resolution levels.
+ [DllImport("j2k-codec", EntryPoint="_J2K_GetResolutions@8")]
+ public static extern J2KError GetResolutions(IntPtr image, ref int resolutions);
+
+ // Gets the dimensions of a resolution level.
+ [DllImport("j2k-codec", EntryPoint="_J2K_GetResolutionDimensions@16")]
+ public static extern J2KError GetResolutionDimensions(IntPtr image, int resLevel, out int width, out int height);
+
+
+ // Cancels Decode() operations.
+ [DllImport("j2k-codec", EntryPoint="_J2K_Cancel@4")]
+ public static extern J2KError Cancel(IntPtr image);
+
+ // Destroys the image, previously created by Open(). All images must
+ // be closed using this function to avoid memory leaks.
+ [DllImport("j2k-codec", EntryPoint="_J2K_Close@4")]
+ public static extern J2KError Close(IntPtr image);
+ }
+
+ public enum J2KError
+ {
+ Success = 0,
+ NeedMMX,
+ NotEnoughMemory,
+ CorruptedData,
+ PipeFailure,
+ InvalidArgument,
+ Canceled,
+ CantOpenFile,
+ OptionUnrecognized,
+ NoSuchTile,
+ NoSuchResolution,
+ BppTooSmall,
+ BufferTooSmall,
+ NotPart1Format,
+ ImageIsTooLarge,
+ TooManyResLevel,
+ TooLargeCodeblocks,
+ NoLaziness,
+ NoVcausal,
+ TooManyComponents,
+ Only8BitComponents,
+ OnlyUnsigComponents,
+ DownsampledComponents,
+ RoiNotSupported,
+ ProgrChangeNotSup,
+ PacketHeadersNotSup,
+ No64BitSupport,
+ InternalError
+ }
+
+ public enum J2KLogLevel
+ {
+ Normal = 0,
+ Detailed = 1,
+ All = 1
+ }
+
+ public enum J2KMetadata
+ {
+ CommentStr,
+ CommentBin,
+ Geotiff,
+ Xml,
+ Url,
+ Pal,
+ Icc,
+ Unknown
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct J2KInfo
+ {
+ public int Version;
+ public int Width;
+ public int Height;
+ public int Components;
+ public int FileType;
+ public int HorizontalTiles;
+ public int VerticalTiles;
+ }
+}
diff --git a/osframework/source/ImageLib/j2k-codec/J2K_Codec.vb b/osframework/source/ImageLib/j2k-codec/J2K_Codec.vb
new file mode 100644
index 0000000..05f7cf3
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/J2K_Codec.vb
@@ -0,0 +1,91 @@
+Imports System.Text, System.Runtime.InteropServices
+Module J2K_Codec
+ Public Enum J2K_ERRORS
+ J2KERR_SUCCESS = 0
+ J2KERR_NEED_MMX
+ J2KERR_NOT_ENOUGH_MEMORY
+ J2KERR_CORRUPTED_DATA
+ J2KERR_PIPE_FAILURE
+ J2KERR_INVALID_ARGUMENT
+ J2KERR_CANCELED
+ J2KERR_CANT_OPEN_FILE
+ J2KERR_OPTION_UNRECOGNIZED
+ J2KERR_NO_SUCH_TILE
+ J2KERR_NO_SUCH_RESOLUTION
+ J2KERR_BPP_TOO_SMALL
+ J2KERR_BUFFER_TOO_SMALL
+ J2KERR_NOT_PART1_FORMAT
+ J2KERR_IMAGE_IS_TOO_LARGE
+ J2KERR_TOO_MANY_RES_LEVEL
+ J2KERR_TOO_LARGE_CODEBLOCKS
+ J2KERR_NO_LAZINESS
+ J2KERR_NO_VCAUSAL
+ J2KERR_TOO_MANY_COMPONENTS
+ J2KERR_ONLY_8_BIT_COMPONENTS
+ J2KERR_ONLY_UNSIG_COMPONENTS
+ J2KERR_DOWNSAMPLED_COMPONENTS
+ J2KERR_ROI_NOT_SUPPORTED
+ J2KERR_PROGR_CHANGE_NOT_SUP
+ J2KERR_PACKET_HDRS_NOT_SUP
+ J2KERR_64BIT_BOXES_NOT_SUP
+ J2KERR_INTERNAL_ERROR
+ End Enum
+
+ Public Enum J2K_Metadata
+ JP2_METADATA_COMMENT_STR = 0
+ JP2_METADATA_COMMENT_BIN
+ JP2_METADATA_GEOTIFF
+ JP2_METADATA_XML
+ JP2_METADATA_URL
+ JP2_METADATA_PAL
+ JP2_METADATA_ICC
+ JP2_METADATA_UNKNOWN
+ End Enum
+
+ Public CodingSchemes() As String = {"Lossy J2K", "Lossy JP2", "Lossless J2K", "Lossless JP2"}
+
+ 'Note that all "Long"s from the VB6 version have been changed to "Integer"
+ Public Structure J2K_Info
+ Dim Version As Integer
+ Dim Width As Integer
+ Dim Height As Integer
+ Dim Components As Integer
+ Dim FileType As Integer
+ Dim hTiles As Integer
+ Dim vTiles As Integer
+ End Structure
+
+ Declare Function J2K_getVersion Lib "j2k-codec" Alias "_J2K_getVersion@0" () As Integer
+
+ Declare Function J2K_getLastError Lib "j2k-codec" Alias "_J2K_getLastError@0" () As Integer
+
+ Declare Sub J2K_getErrorStr Lib "j2k-codec" Alias "_J2K_getErrorStrVB@8" (ByVal ErrCode As Integer, ByVal errStr As String)
+
+ Declare Sub J2K_Unlock Lib "j2k-codec" Alias "_J2K_Unlock@4" (ByVal Key As String)
+
+ Declare Function J2K_StartLogging Lib "j2k-codec" Alias "_J2K_StartLogging@8" (ByVal Level As Integer, ByVal Append As Boolean) As Integer
+
+ Declare Sub J2K_StopLogging Lib "j2k-codec" Alias "_J2K_StopLogging@0" ()
+
+ Declare Function J2K_OpenFile Lib "j2k-codec" Alias "_J2K_OpenFile@4" (ByVal FileName As String) As Integer
+
+ Declare Function J2K_OpenMemory Lib "j2k-codec" Alias "_J2K_OpenMemory@8" (ByRef Buffer As Byte, ByVal Size As Integer) As Integer
+
+ Declare Function J2K_GetInfo Lib "j2k-codec" Alias "_J2K_GetInfo@16" (ByVal Image As Integer, ByRef Width As Integer, ByRef Height As Integer, ByRef Components As Integer) As Integer
+ 'In Vb6 Info was declared as ByVal - it *has* to be ByRef for DotNet to work properly!
+ Declare Function J2K_GetInfoEx Lib "j2k-codec" Alias "_J2K_GetInfoEx@8" (ByVal Image As Integer, ByRef info As J2K_Info) As Integer
+
+ Declare Function J2K_SelectTiles Lib "j2k-codec" Alias "_J2K_SelectTiles@16" (ByVal Image As Integer, ByVal StartTile As Integer, ByVal EndTile As Integer, ByVal Action As Integer) As Integer
+
+ Declare Function J2K_GetResolutions Lib "j2k-codec" Alias "_J2K_GetResolutions@8" (ByVal Image As Integer, ByRef Resolutions As Integer) As Integer
+
+ Declare Function J2K_GetResolutionDimensions Lib "j2k-codec" Alias "_J2K_GetResolutionDimensions@16" (ByVal Image As Integer, ByVal ResLevel As Integer, ByRef Width As Integer, ByRef Height As Integer) As Integer
+
+ Declare Function J2K_Decode Lib "j2k-codec" Alias "_J2K_Decode@20" (ByVal Image As Integer, ByRef Buffer As IntPtr, ByRef Size As Integer, Optional ByVal Options As String = "", Optional ByRef Pitch As Integer = 0) As Integer
+
+ Declare Function J2K_GetMetaData Lib "j2k-codec" Alias "_J2K_GetMetaData@20" (ByVal Image As Integer, ByRef No As Integer, ByRef Type As Integer, ByRef Buffer As IntPtr, ByRef Size As Integer) As Integer
+
+ Declare Sub J2K_Cancel Lib "j2k-codec" Alias "_J2K_Cancel@4" (ByVal Image As Integer)
+
+ Declare Sub J2K_Close Lib "j2k-codec" Alias "_J2K_Close@4" (ByVal Image As Integer)
+End Module
diff --git a/osframework/source/ImageLib/j2k-codec/J2K_Control.idl b/osframework/source/ImageLib/j2k-codec/J2K_Control.idl
new file mode 100644
index 0000000..c9ca9fa
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/J2K_Control.idl
@@ -0,0 +1,62 @@
+// J2K_Control.idl : IDL source for J2K-Control.dll
+//
+
+// This file will be processed by the MIDL tool to
+// produce the type library (J2K_Control.tlb) and marshalling code.
+
+import "oaidl.idl";
+import "ocidl.idl";
+#include "olectl.h"
+
+
+ [
+ object,
+ uuid(BE29213A-CFA5-453D-B243-5F8ABE6A8BB3),
+ dual,
+ helpstring("IJ2K_Codec Interface"),
+ pointer_default(unique)
+ ]
+ interface IJ2K_Codec : IDispatch
+ {
+ [id(1), helpstring("open JPEG2000 file")] HRESULT OpenFile(BSTR filename, [optional] BSTR options);
+ [id(2), helpstring("open JPEG2000 file from memory buffer")] HRESULT OpenMemory(unsigned char *src_buffer, int src_size, [optional] BSTR options);
+ [id(3), helpstring("Create log-file and start logging")] HRESULT StartLogging(int level, int append);
+ [id(4), helpstring("Stop logging")] HRESULT StopLogging();
+ [propget, id(5), helpstring("Width of JPEG2000 image")] HRESULT ImageWidth([out, retval] long *pVal);
+ [propget, id(6), helpstring("Height of JPEG2000 image")] HRESULT ImageHeight([out, retval] long *pVal);
+ [propput, id(7), helpstring("Personal Registration Key")] HRESULT Key([in] BSTR newVal);
+ [propget, id(8), helpstring("The number of components in the JPEG2000 image")] HRESULT ImageComponents([out, retval] long *pVal);
+ [propget, id(9), helpstring("Resize image if true")] HRESULT DoScale([out, retval] BOOL *pVal);
+ [propput, id(9), helpstring("Resize image if true")] HRESULT DoScale([in] BOOL newVal);
+ };
+
+[
+ uuid(2A471E92-469E-469E-BC45-A3485F3911AB),
+ version(1.0),
+ helpstring("J2K_Control 1.0 Type Library")
+]
+library J2K_CONTROLLib
+{
+ importlib("stdole32.tlb");
+ importlib("stdole2.tlb");
+
+ [
+ uuid(DEE0B9C2-D2E6-44FC-A6F6-4C5A3DC2F56D),
+ helpstring("_IJ2K_CodecEvents Interface")
+ ]
+ dispinterface _IJ2K_CodecEvents
+ {
+ properties:
+ methods:
+ };
+
+ [
+ uuid(48AFF452-8543-4538-90FE-E541ECF19BA5),
+ helpstring("J2K_Codec Class")
+ ]
+ coclass J2K_Codec
+ {
+ [default] interface IJ2K_Codec;
+ [default, source] dispinterface _IJ2K_CodecEvents;
+ };
+};
diff --git a/osframework/source/ImageLib/j2k-codec/License.txt b/osframework/source/ImageLib/j2k-codec/License.txt
new file mode 100644
index 0000000..52fcf14
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/License.txt
@@ -0,0 +1,77 @@
+
+ J2K-Codec version 1.8
+
+
+ End User License Agreement
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+ IMPORTANT NOTICE
+
+ This License Agreement is a legal agreement between you (either an
+ individual or a single entity) and Alex Saveliev for the software
+ product identified above, which includes computer software in the
+ form of binary components, optional static linking libraries, samples
+ with source code, any associated media, and on-line or electronic
+ documentation (hereafter noted as "J2K-Codec").
+
+ Read this License Agreement carefully before using J2K-Codec.
+
+----------------------------------------------------------------------
+
+ BY USING J2K-CODEC IN ANY WAY YOU ACKNOWLEDGE THAT YOU HAVE
+ READ, UNDERSTAND AND AGREE TO THE TERMS OF THIS AGREEMENT.
+ IF YOU DO NOT AGREE TO THESE TERMS, DO NOT USE THIS SOFTWARE
+ IN ANY WAY, AND PROMPTLY RETURN IT OR DELETE ANY COPIES OF
+ THIS SOFTWARE IN YOUR POSSESSION.
+
+ J2K-Codec may not be used in any publicly distributed (either free
+ or commercial) product, or product that directly or indirectly
+ receives income with the aid of J2K-Codec, without a commercial
+ license from the developer. Releasing a product without a commercial
+ license in this instance is a breach of the J2K-Codec EULA and parties
+ who violate this license will be prosecuted under the full extent
+ of the law.
+
+ A commercial license may be obtained by registering (purchasing)
+ J2K-Codec from the developer. The user will receive a personal
+ registration key (special code), which signifies that the user has
+ now a valid commercial license. This key is used to remove all demo
+ version restrictions of J2K-Codec.
+
+ Once registered, the user is granted a non-exclusive, worldwide,
+ royalty-free license to use J2K-Codec binary component and source
+ code of J2K-Codec Samples in any number of user's own (either free
+ or commercial) software projects.
+
+ The user MAY NOT:
+
+ 1. pass the personal registration key to other users;
+
+ 2. redistribute the static linking package (a purchasable add-on);
+
+ 3. cause or permit reverse engineering, disassembly, decompilation
+ or alteration of J2K-Codec binary components or static linking
+ libraries by any means or purposes;
+
+ 4. sublicense J2K-Codec to another user as a standalone component, only
+ as a part of software that is developed by the user;
+
+ 5. remove any product identification, copyright notices, this license
+ agreement or other notices or proprietary restrictions from this
+ distribution package.
+
+
+ All copyrights to J2K-Codec are exclusively owned by the developer
+ - Alex Saveliev. "J2K-Codec" is a trademark of Alex Saveliev.
+
+ THIS SOFTWARE IS DISTRIBUTED ON THE "AS IS" BASIS. NO WARRANTY
+ OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE THE SOFTWARE AT
+ YOUR OWN RISK. THE DEVELOPER WILL NOT BE LIABLE FOR DATA LOSS,
+ DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING
+ OR MISUSING THIS SOFTWARE.
+
+----------------------------------------------------------------------
+
+ 2004-2006 (C) Alex Saveliev,
+ http://j2k-codec.com
diff --git a/osframework/source/ImageLib/j2k-codec/ReadMe.txt b/osframework/source/ImageLib/j2k-codec/ReadMe.txt
new file mode 100644
index 0000000..96a2217
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/ReadMe.txt
@@ -0,0 +1,103 @@
+
+-------------------------------------------------------------------
+ Readme for J2K-Codec 1.8 (release)
+ Copyright (c) 2004-2006 Alex Saveliev.
+-------------------------------------------------------------------
+
+
+ OVERVIEW
+ --------
+
+ J2K-Codec is a software component, which allows easy integration of
+ the new image compression standard - JPEG 2000 - into your applications.
+
+ This package includes:
+
+ 1. j2k-codec.dll. This DLL must be placed into your application folder.
+
+ Do not place it in any other folder. There are good reasons for that.
+ As Jeff Cogswell summed it up in his "Designing Highly Useable Software":
+
+ "Thus, as I just mentioned, if you're letting the system loader load
+ your libraries for you, the only viable place to put them is in the
+ same directory as the application."
+
+ 2. j2k-control.dll. This is an ActiveX control. Useful in VisualBasic and
+ other languages.
+
+ 3. Documentation in CHM format ('Docs' folder).
+
+ 4. All files required to call J2K-Codec functions from your programs.
+
+ 5. Examples of J2K-Codec usage ('Samples' folder).
+ In C, C++, C#, VisualBasic, VB.NET and Delphi.
+
+ 6. A collection of JPEG2000 test images ('TestImages' folder).
+
+
+ PURCHASE
+ --------
+
+ NOTE: J2K-Codec will function in the demo mode, until you buy a special
+ key to remove all restriction. See the list of demo restrictions below.
+
+ So you are welcome to try this demo version as long as you want.
+ But if you want to use J2K-Codec in any publicly distributed software,
+ you must purchase it and get your personal registration key.
+ After that, you can use J2K-Codec in any number of your own projects.
+
+ The price of J2K-Codec: $49-$149 USD.
+
+ Static Linking is available as a purchasable add-on.
+
+ Visit http://j2k-codec.com/order.html to order the program.
+
+ You will receive your registration key instantly, after your payment
+ is complete.
+
+
+ DEMO RESTRICTIONS
+ -----------------
+
+ Demo version of J2K-Codec will:
+ * beep at the end of each decoding
+ * open the ordering page once in about 30 decoded images
+ * on the rare occasions do several other little nags
+
+
+ WHAT'S NEW
+ ----------
+
+ See History.txt file.
+
+
+ THE LATEST VERSION
+ ------------------
+
+ You may download the latest version of J2K-Codec at:
+ http://j2k-codec.com/download.html
+
+
+ CONTACTING THE DEVELOPER
+ ------------------------
+
+ If you have any problems, questions, suggestions, etc. please
+ use the online form at
+ http://j2k-codec.com/support.html
+
+ Or email directly to: support@j2k-codec.com
+
+
+ To know more about JPEG 2000 you may visit our Info and Links pages:
+ http://j2k-codec.com/info.html
+ http://j2k-codec.com/links.html
+
+
+ DISCLAIMER
+ ----------
+
+ J2K-CODEC IS DISTRIBUTED ON THE "AS IS" BASIS. NO WARRANTY OF
+ ANY KIND IS EXPRESSED OR IMPLIED. YOU USE THE SOFTWARE AT YOUR
+ OWN RISK. THE DEVELOPER WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES,
+ LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING
+ THIS SOFTWARE.
diff --git a/osframework/source/ImageLib/j2k-codec/bmp.h b/osframework/source/ImageLib/j2k-codec/bmp.h
new file mode 100644
index 0000000..f2ee8c2
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/bmp.h
@@ -0,0 +1,83 @@
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// BMP Saving
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#include <windows.h>
+#include <stdio.h>
+
+int SaveAsBMP(char *filename, unsigned char *buffer, int width, int height, int bpp)
+{
+ int w, w2, h, tmp, color_map_size; unsigned char *row; FILE *f;
+
+ BITMAPFILEHEADER bmpHeader; BITMAPINFOHEADER bmpInfoHeader;
+
+ color_map_size=(bpp==1 ? 256*4 : 0);
+
+ bmpHeader.bfType='MB';
+ bmpHeader.bfSize=14+40;//sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
+ bmpHeader.bfSize+=color_map_size;
+ bmpHeader.bfOffBits=bmpHeader.bfSize;
+ bmpHeader.bfSize+=width*height*bpp;
+ bmpHeader.bfReserved1=bmpHeader.bfReserved2=0;
+
+ bmpInfoHeader.biSize=40;//sizeof(BITMAPINFOHEADER);
+ bmpInfoHeader.biWidth=width;
+ bmpInfoHeader.biHeight=height;
+ bmpInfoHeader.biPlanes=1;
+ bmpInfoHeader.biBitCount=(bpp==1) ? 8 : ((bpp==3) ? 24 : 32);
+ bmpInfoHeader.biCompression=BI_RGB;
+ bmpInfoHeader.biSizeImage=0;
+ bmpInfoHeader.biXPelsPerMeter=0;
+ bmpInfoHeader.biYPelsPerMeter=0;
+ bmpInfoHeader.biClrUsed=(bpp==1 ? 256 : 0);
+ bmpInfoHeader.biClrImportant=0;
+
+ f=fopen(filename, "wb"); if(!f) return 0;
+
+// fwrite(&bmpHeader, 14, 1, f);
+ fwrite(&bmpHeader.bfType, 2, 1, f);
+ fwrite(&bmpHeader.bfSize, 4, 1, f);
+ fwrite(&bmpHeader.bfReserved1, 2, 1, f);
+ fwrite(&bmpHeader.bfReserved2, 2, 1, f);
+ fwrite(&bmpHeader.bfOffBits, 4, 1, f);
+
+// fwrite(&bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, f);
+
+ fwrite(&bmpInfoHeader.biSize, 4, 1, f);
+ fwrite(&bmpInfoHeader.biWidth, 4, 1, f);
+ fwrite(&bmpInfoHeader.biHeight, 4, 1, f);
+ fwrite(&bmpInfoHeader.biPlanes, 2, 1, f);
+ fwrite(&bmpInfoHeader.biBitCount, 2, 1, f);
+ fwrite(&bmpInfoHeader.biCompression, 4, 1, f);
+ fwrite(&bmpInfoHeader.biSizeImage, 4, 1, f);
+ fwrite(&bmpInfoHeader.biXPelsPerMeter, 4, 1, f);
+ fwrite(&bmpInfoHeader.biYPelsPerMeter, 4, 1, f);
+ fwrite(&bmpInfoHeader.biClrUsed, 4, 1, f);
+ fwrite(&bmpInfoHeader.biClrImportant, 4, 1, f);
+
+ if(bpp==1)
+ {
+ for(w=0; w<256; w++){ tmp=(w<<16)|(w<<8)|w; fwrite(&tmp, 4, 1, f); }
+
+ for(h=0; h<height; h++)
+ {
+ row=buffer+width*(height-h-1);
+ for(w=0; w<width; w++) fputc(row[w], f);
+ if(width&3) for(w=0; w<4-(width&3); w++) fputc(0, f);
+ }
+ }
+ else
+ {
+ for(h=0; h<height; h++)
+ {
+ row=buffer+width*(height-h-1)*bpp;
+ for(w=0; w<width; w++, row+=bpp) fwrite(row, bpp, 1, f);
+ w2=width*bpp; if(w2&3) for(w=0; w<4-(w2&3); w++) fputc(0, f);
+ }
+ }
+
+ fclose(f);
+ return 1;
+}
diff --git a/osframework/source/ImageLib/j2k-codec/file_id.diz b/osframework/source/ImageLib/j2k-codec/file_id.diz
new file mode 100644
index 0000000..bc352bb
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/file_id.diz
@@ -0,0 +1,21 @@
+
+ J2K-Codec ver 1.8
+
+=====================================================
+
+ Make your graphics look better with an easy-to-use
+ JPEG 2000 decoding component. J2K-Codec can help
+ game developers, screensaver creators and many
+ others to improve their products--to achieve better
+ image quality and reduce installation package size.
+ The new image compression standard based on wavelet
+ technology has many interesting features not
+ available in the old JPEG, such as alpha-channel
+ and varied resolution levels.
+
+ Don't be outdated.
+
+=====================================================
+
+ Web: http://www.j2k-codec.com
+ E-mail: support@j2k-codec.com \ No newline at end of file
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-codec.dll b/osframework/source/ImageLib/j2k-codec/j2k-codec.dll
new file mode 100644
index 0000000..d07d18d
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-codec.dll
Binary files differ
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-codec.exp b/osframework/source/ImageLib/j2k-codec/j2k-codec.exp
new file mode 100644
index 0000000..4b582a1
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-codec.exp
Binary files differ
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-codec.h b/osframework/source/ImageLib/j2k-codec/j2k-codec.h
new file mode 100644
index 0000000..4545b6a
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-codec.h
@@ -0,0 +1,533 @@
+
+#ifndef __J2K_LIBRARY__
+#define __J2K_LIBRARY__
+
+
+#ifdef J2K_CODEC_EXPORTS
+
+ #ifdef J2K_CODEC_STATIC
+ #define J2K_CODEC_API(ret) extern "C" ret __stdcall
+ #else
+ #define J2K_CODEC_API(ret) extern "C" __declspec(dllexport) ret __stdcall
+ #endif
+
+#else
+
+ #ifdef __cplusplus
+
+ #include <windows.h> // Required for resources support in C++ Wrapper
+
+ #ifdef J2K_CODEC_STATIC
+ #define J2K_CODEC_API(ret) extern "C" ret __stdcall
+ #else
+ #define J2K_CODEC_API(ret) extern "C" __declspec(dllimport) ret __stdcall
+ #endif
+
+ #else // plain C
+
+ #ifdef J2K_CODEC_STATIC
+ #define J2K_CODEC_API(ret) extern ret __stdcall
+ #else
+ #define J2K_CODEC_API(ret) __declspec(dllimport) ret __stdcall
+ #endif
+
+ #endif
+
+ enum J2K_ErrorList
+ {
+ J2KERR_SUCCESS,
+ J2KERR_NEED_MMX,
+ J2KERR_NOT_ENOUGH_MEMORY,
+ J2KERR_CORRUPTED_DATA,
+ J2KERR_PIPE_FAILURE,
+ J2KERR_INVALID_ARGUMENT,
+ J2KERR_CANCELED,
+ J2KERR_CANT_OPEN_FILE,
+ J2KERR_OPTION_UNRECOGNIZED,
+ J2KERR_NO_SUCH_TILE,
+ J2KERR_NO_SUCH_RESOLUTION,
+ J2KERR_BPP_TOO_SMALL,
+ J2KERR_BUFFER_TOO_SMALL,
+ J2KERR_NOT_PART1_FORMAT,
+ J2KERR_IMAGE_IS_TOO_LARGE,
+ J2KERR_TOO_MANY_RES_LEVEL,
+ J2KERR_TOO_LARGE_CODEBLOCKS,
+ J2KERR_NO_LAZINESS,
+ J2KERR_NO_VCAUSAL,
+ J2KERR_TOO_MANY_COMPONENTS,
+ J2KERR_ONLY_8_BIT_COMPONENTS,
+ J2KERR_ONLY_UNSIG_COMPONENTS,
+ J2KERR_DOWNSAMPLED_COMPONENTS,
+ J2KERR_ROI_NOT_SUPPORTED,
+ J2KERR_PROGR_CHANGE_NOT_SUP,
+ J2KERR_PACKET_HDRS_NOT_SUP,
+ J2KERR_64BIT_BOXES_NOT_SUP,
+ J2KERR_INTERNAL_ERROR
+ };
+
+#endif
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getVersion()
+//
+// Returns codec version and build number in the 0x105678 form, where 10 is a version (1.0)
+// and 5678 is a build number.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_getVersion();
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getLastError()
+//
+// Returns the code of last error. Use J2K_getErrorStr() to get textual description of
+// the error.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_getLastError();
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getErrorStr()
+//
+// Returns the textual description of an error by the error code obtained from getLastError().
+// If the errCode is < 0 or > Max number of errors, the "<unknown>" string is returned.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(const char*) J2K_getErrorStr(int errCode);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getLastErrorStr()
+//
+// Returns the textual description of the last error.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(const char*) J2K_getLastErrorStr();
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Unlock()
+//
+// This function unlocks the full functionality of J2K-Codec. After you have purchased your
+// personal registration key, you need to pass it to this function.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(void) J2K_Unlock(const char *key);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_StartLogging()
+//
+// This function creates a log-file and starts logging debug messages of J2K-Codec.
+// 'level' can be 0 (Normal logging) or 1 (Detailed logging).
+// Passing 'append' = 1 allows to append the log session to existing log-file.
+// Returns 0 if there was no error.
+// NOTES:
+// 1. Log-file name is 'j2k-codec.log'
+// 2. The performance will degrade significantly if the logging is on.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+#define J2K_LOG_NORMAL 0
+#define J2K_LOG_DETAILED 1
+#define J2K_LOG_ALL J2K_LOG_DETAILED
+
+#define J2K_LOG_APPEND 1
+
+J2K_CODEC_API(int) J2K_StartLogging(int level, int append);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_StopLogging()
+//
+// Use this function to stop logging, initiated by J2K_StartLogging().
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(void) J2K_StopLogging();
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Open()
+//
+// Returns pointer to an internal class, representing the J2K image, or 0 if
+// there was an error. Use J2K_getLastError() to obtain the error code.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+typedef struct
+{
+ int (__stdcall *seek) (void *data_source, int offset);
+ int (__stdcall *read) (void *ptr, int size, void *data_source);
+ void (__stdcall *close) (void *data_source);
+}
+J2K_Callbacks;
+
+J2K_CODEC_API(void*) J2K_OpenFile(const char *filename);
+J2K_CODEC_API(void*) J2K_OpenMemory(unsigned char *src_buffer, int src_size);
+J2K_CODEC_API(void*) J2K_OpenCustom(void *data_source, J2K_Callbacks *cbs);
+
+#ifdef __cplusplus
+ __inline void* J2K_Open(const char *filename){ return J2K_OpenFile(filename); }
+ __inline void* J2K_Open(unsigned char *src_buffer, int src_size){ return J2K_OpenMemory(src_buffer, src_size); }
+ __inline void* J2K_Open(void *data_source, J2K_Callbacks *cbs){ return J2K_OpenCustom(data_source, cbs); }
+#endif
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetInfo()
+//
+// Gets various information about the image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_GetInfo(void *image, int *width, int *height, int *components);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetInfoEx()
+//
+// Gets extended information about the image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+typedef struct
+{
+ int Version; // J2K-Codec version as returned by J2K_getVersion()
+ int Width, Height; // Width and height of the image in pixels
+ int Components; // The number of components in the image
+ int FileType; // The image file type (0 = Lossy J2K, 1 = Lossy JP2, 2 = Lossless J2K, 3 = Lossless JP2)
+ int hTiles, vTiles; // The number of tiles in horizontal and vertical directions
+}
+J2K_Info;
+
+J2K_CODEC_API(int) J2K_GetInfoEx(void *image, J2K_Info *info);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetMetaData()
+//
+// Gets meta data, embedded into the JP2 image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+enum JP2_META_DATA_TYPES
+{
+ JP2_METADATA_COMMENT_STR,
+ JP2_METADATA_COMMENT_BIN,
+ JP2_METADATA_GEOTIFF,
+ JP2_METADATA_XML,
+ JP2_METADATA_URL,
+ JP2_METADATA_PAL,
+ JP2_METADATA_ICC,
+ JP2_METADATA_UNKNOWN
+};
+
+J2K_CODEC_API(int) J2K_GetMetaData(void *image, int *no, int *type, unsigned char **data, int *size);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_SelectTiles()
+//
+// Selects or unselects a tile or a tile range, depending on 'action'.
+// If action!=0 then the tiles are selected for decoding, otherwise - unselected.
+// The range is defined by start and end tile numbers (inclusive) in the raster order.
+// If end_tile==-1 then the max tile number will be used instead.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_SelectTiles(void *image, int start_tile, int end_tile, int action);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetResolutions()
+//
+// Gets the number of available resolution levels.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_GetResolutions(void *image, int *resolutions);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetResolutionDimensions()
+//
+// Gets the dimensions of a resolution level.
+// Returns J2KERR_SUCCESS or error code if function failed.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(int) J2K_GetResolutionDimensions(void *image, int res_level, int *width, int *height);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Decode()
+//
+// Decodes the image, previously created with J2K_Open().
+// If 'buffer' is null, then the required amount of memory is allocated and its size returned
+// through the 'size' argument.
+// 'buff_pitch' is a buffer pitch - distance, in bytes, to the start of next line.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+#ifdef __cplusplus
+ J2K_CODEC_API(int) J2K_Decode(void *image, unsigned char **buffer, int *size, char *options=0, int *pitch=0);
+#else
+ J2K_CODEC_API(int) J2K_Decode(void *image, unsigned char **buffer, int *size, char *options, int *pitch);
+#endif
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_EasyDecode()
+//
+// Decodes JPEG2000 file into memory buffer.
+// Buffer, image width, height and the number of components are passed back via specified pointers.
+// If succeeded - returns pointer to an internal structure, which represents the image, otherwise - NULL.
+// NOTE:
+// 1. You must not free the buffer yourself - use J2K_Close(j2k_image) instead!
+// 2. Unlike C++ Wrapper's easyDecode(), which allows to use the user buffer, C EasyDecode() doesn't.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(void*) J2K_EasyDecode(char *filename, unsigned char **buffer, int *width, int *height, int *components, char *options);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Cancel()
+//
+// Cancels J2K_Decode() operations.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(void) J2K_Cancel(void *image);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Close()
+//
+// Destroys the image, previously created by J2K_Open(). All images must be closed using
+// this function to avoid memory leaks.
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+J2K_CODEC_API(void) J2K_Close(void *image);
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+//
+// C++ Wrapper
+//
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+
+#ifndef J2K_CODEC_EXPORTS
+
+#ifdef __cplusplus
+
+// UNDOCUMENTED! You must never use this function directly!
+J2K_CODEC_API(int) J2K_GetResolutionDimensionsByStr(void *image, char *options, int *width, int *height);
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Image
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+class J2K_Image
+{
+ protected:
+
+ void *image;
+
+ int error(int code){ errStr=J2K_getErrorStr(code); return code; }
+ void reset(){ image=0; width=height=components=0; hTiles=vTiles=0; fileType=0; errStr=""; buffer=0; size=0; pitch=0; }
+ int _open()
+ {
+ if(!image) return error(J2K_getLastError());
+
+ J2K_Info info; int j2k_err=J2K_GetInfoEx(image, &info); if(j2k_err!=J2KERR_SUCCESS){ close(); return error(j2k_err); }
+
+ width = info.Width; height = info.Height; components = info.Components;
+ hTiles = info.hTiles; vTiles = info.vTiles; fileType = info.FileType;
+
+ return J2KERR_SUCCESS;
+ }
+
+ public:
+
+ int width, height, components, hTiles, vTiles, fileType; const char *errStr;
+
+ unsigned char *buffer; int size, pitch;
+
+ J2K_Image(){ reset(); }
+
+ int open(char *filename){ if(image) close(); image=J2K_Open(filename); return _open(); }
+ int open(unsigned char *src_buffer, int src_size){ if(image) close(); image=J2K_Open(src_buffer, src_size); return _open(); }
+ int open(int resource_no)
+ {
+ if(image) close();
+
+ HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(resource_no), RT_RCDATA); if(!hRes) return error(J2KERR_CANT_OPEN_FILE);
+ HGLOBAL res = LoadResource(NULL, hRes); if(!res) return error(J2KERR_CANT_OPEN_FILE);
+ int res_size= SizeofResource(NULL, hRes); if(!res_size) return error(J2KERR_CANT_OPEN_FILE);
+
+ unsigned char *res_data = (unsigned char*)LockResource(res);
+
+ image=J2K_Open(res_data, res_size); return _open();
+ }
+
+ int open(void *data_source, J2K_Callbacks *cbs){ if(image) close(); image=J2K_Open(data_source, cbs); return _open(); }
+
+ int getMetaData(int *no, int *type, unsigned char **data, int *size)
+ {
+ int j2k_err = J2K_GetMetaData(image, no, type, data, size);
+
+ if(j2k_err!=J2KERR_SUCCESS) return error(j2k_err); else return J2KERR_SUCCESS;
+ }
+
+ int selectTiles(int start_tile, int end_tile, int action)
+ {
+ int j2k_err = J2K_SelectTiles(image, start_tile, end_tile, action);
+
+ if(j2k_err!=J2KERR_SUCCESS) return error(j2k_err); else return J2KERR_SUCCESS;
+ }
+
+ int decode(char *options=0)
+ {
+ if(!image) return error(J2KERR_SUCCESS); // Do nothing if there's nothing to do
+
+ int j2k_err=J2K_GetResolutionDimensionsByStr(image, options, &width, &height);
+ if(j2k_err==J2KERR_SUCCESS || j2k_err==J2KERR_NO_SUCH_RESOLUTION)
+ {
+ j2k_err=J2K_Decode(image, &buffer, &size, options, &pitch); if(j2k_err==J2KERR_SUCCESS) return J2KERR_SUCCESS;
+ }
+
+ close(); return error(j2k_err);
+ }
+
+ int easyDecode(char *filename, char *options=0)
+ {
+ int j2k_err=open(filename); if(j2k_err==J2KERR_SUCCESS) return decode(options); else return error(j2k_err);
+ }
+
+ int easyDecode(unsigned char *src_buffer, int src_size, char *options=0)
+ {
+ int j2k_err=open(src_buffer, src_size); if(j2k_err==J2KERR_SUCCESS) return decode(options); else return error(j2k_err);
+ }
+
+ int easyDecode(int resource_no, char *options=0)
+ {
+ int j2k_err=open(resource_no); if(j2k_err==J2KERR_SUCCESS) return decode(options); else return error(j2k_err);
+ }
+
+ void close(){ if(image) J2K_Close(image); reset(); }
+
+ ~J2K_Image(){ close(); }
+};
+
+
+/*/////////////////////////////////////////////////////////////////////////////////////////
+// J2K Frames
+/////////////////////////////////////////////////////////////////////////////////////////*/
+
+#include <string.h>
+
+class J2K_Frames
+{
+ protected:
+
+ int **frame, currFrame, TotalFrames; bool isAlpha;
+
+ int error(int code){ errStr=J2K_getErrorStr(code); return code; }
+ void reset(){ frame=0; currFrame=0; TotalFrames=0; isAlpha=false; errStr=""; }
+ int _open(void *image, char *options)
+ {
+ close(); if(!image) return error(J2K_getLastError());
+
+ J2K_Info info; char new_options[128]; // char *new_options = (char*)alloca(strlen(options)+10);
+
+ int j2k_err = J2K_GetInfoEx(image, &info); if(j2k_err!=J2KERR_SUCCESS){ close(); return error(j2k_err); }
+
+ isAlpha = (info.Components==4);
+
+ TotalFrames = info.hTiles * info.vTiles;
+ frame = new int * [TotalFrames]; if(!frame) return error(J2KERR_NOT_ENOUGH_MEMORY);
+
+ for(int i=0; i<TotalFrames; i++)
+ {
+ frame[i] = NULL;
+
+ J2K_SelectTiles(image, 0,-1, 0); J2K_SelectTiles(image, i,i, 1); // Unselect all tiles and select current tile
+
+ int tileWidth, tileHeight;
+
+ if(J2K_GetResolutionDimensionsByStr(image, options, &tileWidth, &tileHeight) == J2KERR_SUCCESS)
+ {
+ frame[i] = new int[tileWidth*tileHeight + 3];
+ if(frame[i])
+ {
+ frame[i][0] = tileWidth; frame[i][1] = tileHeight; frame[i][2] = isAlpha ? 1 : 0;
+
+ unsigned char *buffer = (unsigned char*)(frame[i]+3);
+ int size = tileWidth*tileHeight*4;
+
+ strcpy(new_options, options); strcat(new_options, ",bpp=4"); // Override user's bpp, because frames have always bpp = 4
+
+ j2k_err = J2K_Decode(image, &buffer, &size, new_options); if(j2k_err!=J2KERR_SUCCESS){ delete frame[i]; frame[i]=NULL; }
+ }
+ }
+ }
+
+ J2K_Close(image); return J2KERR_SUCCESS;
+ }
+
+ void inc(){ currFrame++; if(currFrame>=TotalFrames) currFrame=0; }
+ void dec(){ currFrame--; if(currFrame<0) currFrame=TotalFrames-1; }
+
+ public:
+
+ const char *errStr;
+
+ J2K_Frames(){ reset(); }
+
+ int open(char *filename, char *options){ return _open(J2K_Open(filename), options); }
+ int open(unsigned char *src_buffer, int src_size, char *options){ return _open(J2K_Open(src_buffer, src_size), options); }
+ int open(void *data_source, J2K_Callbacks *cbs, char *options){ return _open(J2K_Open(data_source, cbs), options); }
+ int open(int resource_no, char *options)
+ {
+ HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(resource_no), RT_RCDATA); if(!hRes) return error(J2KERR_CANT_OPEN_FILE);
+ HGLOBAL res = LoadResource(NULL, hRes); if(!res) return error(J2KERR_CANT_OPEN_FILE);
+ int res_size= SizeofResource(NULL, hRes); if(!res_size) return error(J2KERR_CANT_OPEN_FILE);
+
+ unsigned char *res_data = (unsigned char*)LockResource(res); return _open(J2K_Open(res_data, res_size), options);
+ }
+
+ __inline int getFrames(){ return TotalFrames; }
+
+ __inline unsigned char* getFrame(int no)
+ {
+ if(no<0) no=0; if(no>=TotalFrames) no=TotalFrames-1;
+
+ if(frame) return (unsigned char*)frame[no]; else return NULL;
+ }
+
+ __inline unsigned char* operator()(int no){ return getFrame(no); }
+ __inline unsigned char* operator()(){ return getFrame(currFrame); }
+
+ __inline void operator=(int no)
+ {
+ if(no<0) no=0; if(no>=TotalFrames) no=TotalFrames-1;
+
+ currFrame=no;
+ }
+
+ __inline void operator++( ){ inc(); }
+ __inline void operator++(int){ inc(); }
+
+ __inline void operator--( ){ dec(); }
+ __inline void operator--(int){ dec(); }
+
+ void close(){ if(frame){ for(int i=0; i<TotalFrames; i++) if(frame[i]) delete frame[i]; delete frame; } reset(); }
+
+ ~J2K_Frames(){ close(); }
+};
+
+#endif
+
+#endif
+
+/* ///////////////////////////////////////////////////////////////////////////////////// */
+
+#endif
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-codec.lib b/osframework/source/ImageLib/j2k-codec/j2k-codec.lib
new file mode 100644
index 0000000..6bdf2bc
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-codec.lib
Binary files differ
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-codec.url b/osframework/source/ImageLib/j2k-codec/j2k-codec.url
new file mode 100644
index 0000000..345f835
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-codec.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=http://j2k-codec.com/
diff --git a/osframework/source/ImageLib/j2k-codec/j2k-control.dll b/osframework/source/ImageLib/j2k-codec/j2k-control.dll
new file mode 100644
index 0000000..1f74469
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k-control.dll
Binary files differ
diff --git a/osframework/source/ImageLib/j2k-codec/j2k.ico b/osframework/source/ImageLib/j2k-codec/j2k.ico
new file mode 100644
index 0000000..d87da75
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k.ico
Binary files differ
diff --git a/osframework/source/ImageLib/j2k-codec/j2k_codec.pas b/osframework/source/ImageLib/j2k-codec/j2k_codec.pas
new file mode 100644
index 0000000..d73e7be
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/j2k_codec.pas
@@ -0,0 +1,271 @@
+unit j2k_codec;
+
+interface
+
+const
+
+ J2KERR_SUCCESS = 0;
+ J2KERR_NEED_MMX = 1;
+ J2KERR_NOT_ENOUGH_MEMORY = 2;
+ J2KERR_CORRUPTED_DATA = 3;
+ J2KERR_PIPE_FAILURE = 4;
+ J2KERR_INVALID_ARGUMENT = 5;
+ J2KERR_CANCELED = 6;
+ J2KERR_CANT_OPEN_FILE = 7;
+ J2KERR_OPTION_UNRECOGNIZED = 8;
+ J2KERR_NO_SUCH_TILE = 9;
+ J2KERR_NO_SUCH_RESOLUTION = 10;
+ J2KERR_BPP_TOO_SMALL = 11;
+ J2KERR_BUFFER_TOO_SMALL = 12;
+ J2KERR_NOT_PART1_FORMAT = 13;
+ J2KERR_IMAGE_IS_TOO_LARGE = 14;
+ J2KERR_TOO_MANY_RES_LEVEL = 15;
+ J2KERR_TOO_LARGE_CODEBLOCKS = 16;
+ J2KERR_NO_LAZINESS = 17;
+ J2KERR_NO_VCAUSAL = 18;
+ J2KERR_TOO_MANY_COMPONENTS = 19;
+ J2KERR_ONLY_8_BIT_COMPONENTS = 20;
+ J2KERR_ONLY_UNSIG_COMPONENTS = 21;
+ J2KERR_DOWNSAMPLED_COMPONENTS = 22;
+ J2KERR_ROI_NOT_SUPPORTED = 23;
+ J2KERR_PROGR_CHANGE_NOT_SUP = 24;
+ J2KERR_PACKET_HDRS_NOT_SUP = 25;
+ J2KERR_64BIT_BOXES_NOT_SUP = 26;
+ J2KERR_INTERNAL_ERROR = 27;
+
+ j2kdll = 'j2k-codec.dll';
+
+type PJ2KImage = Pointer;
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getVersion()
+//
+// Returns codec version and build number in the 0x105678 form, where 10 is a version (1.0)
+// and 5678 is a build number.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_getVersion():integer; stdcall; external j2kdll name '_J2K_getVersion@0';
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getLastError()
+//
+// Returns the code of last error. Use J2K_getErrorStr() to get textual description of
+// the error.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_getLastError():integer; stdcall; external j2kdll name '_J2K_getLastError@0';
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getErrorStr()
+//
+// Returns the textual description of an error by the error code obtained from getLastError().
+// If the errCode is < 0 or > Max number of errors, the "<unknown>" string is returned.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_getErrorStr(errCode:integer):PChar; stdcall; external j2kdll name '_J2K_getErrorStr@4';
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_getLstErrorStr()
+//
+// Returns the textual description of the last error.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_getLastErrorStr():PChar; stdcall; external j2kdll name '_J2K_getLastErrorStr@0';
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Unlock()
+//
+// This function unlocks the full functionality of J2K-Codec. After you have purchased your
+// personal registration key, you need to pass it to this function.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+procedure J2K_Unlock(key:PChar); stdcall; external j2kdll name '_J2K_Unlock@4';
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// J2K_StartLogging()
+//
+// This function creates a log-file and starts logging debug messages of J2K-Codec.
+// 'level' can be 0 (Normal logging) or 1 (Detailed logging).
+// Passing 'append' = 1 allows to append the log session to existing log-file.
+// Returns 0 if there was no error.
+// NOTES:
+// 1. Log-file name is 'j2k-codec.log'
+// 2. The performance will degrade significantly if the logging is on.
+//////////////////////////////////////////////////////////////////////////////////////////
+
+const
+
+ J2K_LOG_NORMAL = 0;
+ J2K_LOG_DETAILED = 1;
+ J2K_LOG_ALL = J2K_LOG_DETAILED;
+
+ J2K_LOG_APPEND = 1;
+
+function J2K_StartLogging(level,append:integer):integer; stdcall; external j2kdll name '_J2K_StartLogging@8';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_StopLogging()
+//
+// Use this function to stop logging, initiated by J2K_StartLogging().
+///////////////////////////////////////////////////////////////////////////////////////////
+
+procedure J2K_StopLogging(); stdcall; external j2kdll name '_J2K_StopLogging@0';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Open()
+//
+// Returns pointer to an internal class, representing the J2K image, or 0 if
+// there was an error. Use J2K_getLastError() to obtain the error code.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+type
+
+ TJ2KCallbacks=record
+ seek: function(data_source:Pointer; offset:integer):integer; stdcall;
+ read: function(ptr:Pointer; size:integer; data_source:Pointer):integer; stdcall;
+ close: procedure(data_source:Pointer); stdcall;
+ end;
+
+function J2K_OpenFile(filename:PChar):PJ2KImage; stdcall; external j2kdll name '_J2K_OpenFile@4';
+function J2K_OpenMemory(src_buffer:Pointer; src_size:integer):PJ2KImage; stdcall; external j2kdll name '_J2K_OpenMemory@8';
+function J2K_OpenCustom(data_source:Pointer; const cbs:TJ2KCallbacks):PJ2KImage; stdcall; external j2kdll name '_J2K_OpenCustom@8';
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetInfo()
+//
+// Gets various information about the image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_GetInfo(image:PJ2KImage; out width, height, components:integer):integer; stdcall; external j2kdll name '_J2K_GetInfo@16';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetInfoEx()
+//
+// Gets extended information about the image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+type
+
+ TJ2KInfo = record
+ Version:integer; // J2K-Codec version as returned by J2K_getVersion()
+ Width, Height:integer; // Width and height of the image in pixels
+ Components:integer; // The number of components in the image
+ FileType:integer; // 0 - J2K, 1 - JP2
+ hTiles, vTiles:integer; // The number of tiles in horizontal and vertical directions
+ end;
+
+function J2K_GetInfoEx(image:PJ2KImage; out info:TJ2KInfo):integer; stdcall; external j2kdll name '_J2K_GetInfoEx@8';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetMetaData()
+//
+// Gets meta data, embedded into the JP2 image.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+const
+ JP2_METADATA_COMMENT_STR = 0;
+ JP2_METADATA_COMMENT_BIN = 1;
+ JP2_METADATA_GEOTIFF = 2;
+ JP2_METADATA_XML = 3;
+ JP2_METADATA_URL = 4;
+ JP2_METADATA_PAL = 5;
+ JP2_METADATA_ICC = 6;
+ JP2_METADATA_UNKNOWN = 7;
+
+
+function J2K_GetMetaData(image:PJ2KImage; out no, data_type:integer; var data:Pointer; out size:integer):integer; stdcall; external j2kdll name '_J2K_GetMetaData@20';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_SelectTiles()
+//
+// Selects or unselects a tile or a tile range, depending on 'action'.
+// If action!=0 then the tiles are selected for decoding, otherwise - unselected.
+// The range is defined by start and end tile numbers (inclusive) in the raster order.
+// If end_tile==-1 then the max tile number will be used instead.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_SelectTiles(image:PJ2KImage; start_tile, end_tile, action:integer):integer; stdcall; external j2kdll name '_J2K_SelectTiles@16';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetResolutions()
+//
+// Gets the number of available resolution levels.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_GetResolutions(image:PJ2KImage; out resolutions:integer):integer; stdcall; external j2kdll name '_J2K_GetResolutions@8';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_GetResolutionDimensions()
+//
+// Gets the dimensions of a resolution level.
+// Returns J2KERR_SUCCESS or error code if function failed.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_GetResolutionDimensions(image:PJ2KImage; res_level:integer; out width, height:integer):integer; stdcall; external j2kdll name '_J2K_GetResolutionDimensions@16';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Decode()
+//
+// Decodes the image, previously created with J2K_Open().
+// If 'buffer' is null, then the required amount of memory is allocated and its size returned
+// through the 'size' argument.
+// 'buff_pitch' is a buffer pitch - distance, in bytes, to the start of next line.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_Decode(image:PJ2KImage; out buffer:Pointer; out size:integer; options:PChar; out pitch:integer):integer; stdcall; external j2kdll name '_J2K_Decode@20';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Cancel()
+//
+// Cancels J2K_Decode() operations.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+procedure J2K_Cancel(image:PJ2KImage); stdcall; external j2kdll name '_J2K_Cancel@4';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_Close()
+//
+// Destroys the image, previously created by J2K_Open(). All images must be closed using
+// this function to avoid memory leaks.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+procedure J2K_Close(image:PJ2KImage); stdcall; external j2kdll name '_J2K_Close@4';
+
+
+///////////////////////////////////////////////////////////////////////////////////////////
+// J2K_EasyDecode()
+//
+// Decodes JPEG2000 file into memory buffer.
+// Buffer, image width, height and the number of components are passed back via specified pointers.
+// If succeeded - returns pointer to an internal structure, which represents the image, otherwise - NULL.
+// NOTE:
+// 1. You must not free the buffer yourself - use J2K_Close(j2k_image) instead!
+// 2. Unlike C++ Wrapper's easyDecode(), which allows to use the user buffer, C EasyDecode() doesn't.
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function J2K_EasyDecode(filename:string; out buffer:Pointer; out width, height, components:integer; options:PChar):PJ2KImage; stdcall; external j2kdll name '_J2K_EasyDecode@24';
+
+implementation
+
+end.
+
diff --git a/osframework/source/ImageLib/j2k-codec/purchase.url b/osframework/source/ImageLib/j2k-codec/purchase.url
new file mode 100644
index 0000000..6709646
--- /dev/null
+++ b/osframework/source/ImageLib/j2k-codec/purchase.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=http://j2k-codec.com/order.html
diff --git a/osframework/source/ImageLib/jpeg/ansi2knr.1 b/osframework/source/ImageLib/jpeg/ansi2knr.1
new file mode 100644
index 0000000..60b33cf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/ansi2knr.1
@@ -0,0 +1,36 @@
+.TH ANSI2KNR 1 "19 Jan 1996"
+.SH NAME
+ansi2knr \- convert ANSI C to Kernighan & Ritchie C
+.SH SYNOPSIS
+.I ansi2knr
+[--varargs] input_file [output_file]
+.SH DESCRIPTION
+If no output_file is supplied, output goes to stdout.
+.br
+There are no error messages.
+.sp
+.I ansi2knr
+recognizes function definitions by seeing a non-keyword identifier at the left
+margin, followed by a left parenthesis, with a right parenthesis as the last
+character on the line, and with a left brace as the first token on the
+following line (ignoring possible intervening comments). It will recognize a
+multi-line header provided that no intervening line ends with a left or right
+brace or a semicolon. These algorithms ignore whitespace and comments, except
+that the function name must be the first thing on the line.
+.sp
+The following constructs will confuse it:
+.br
+ - Any other construct that starts at the left margin and follows the
+above syntax (such as a macro or function call).
+.br
+ - Some macros that tinker with the syntax of the function header.
+.sp
+The --varargs switch is obsolete, and is recognized only for
+backwards compatibility. The present version of
+.I ansi2knr
+will always attempt to convert a ... argument to va_alist and va_dcl.
+.SH AUTHOR
+L. Peter Deutsch <ghost@aladdin.com> wrote the original ansi2knr and
+continues to maintain the current version; most of the code in the current
+version is his work. ansi2knr also includes contributions by Francois
+Pinard <pinard@iro.umontreal.ca> and Jim Avera <jima@netcom.com>.
diff --git a/osframework/source/ImageLib/jpeg/ansi2knr.c b/osframework/source/ImageLib/jpeg/ansi2knr.c
new file mode 100644
index 0000000..0e3ab13
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/ansi2knr.c
@@ -0,0 +1,693 @@
+/* ansi2knr.c */
+/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
+
+/*
+ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY. No author or distributor accepts responsibility to anyone for the
+consequences of using it or for whether it serves any particular purpose or
+works at all, unless he says so in writing. Refer to the GNU General Public
+License (the "GPL") for full details.
+
+Everyone is granted permission to copy, modify and redistribute ansi2knr,
+but only under the conditions described in the GPL. A copy of this license
+is supposed to have been given to you along with ansi2knr so you can know
+your rights and responsibilities. It should be in a file named COPYLEFT.
+[In the IJG distribution, the GPL appears below, not in a separate file.]
+Among other things, the copyright notice and this notice must be preserved
+on all copies.
+
+We explicitly state here what we believe is already implied by the GPL: if
+the ansi2knr program is distributed as a separate set of sources and a
+separate executable file which are aggregated on a storage medium together
+with another program, this in itself does not bring the other program under
+the GPL, nor does the mere fact that such a program or the procedures for
+constructing it invoke the ansi2knr executable bring any other part of the
+program under the GPL.
+*/
+
+/*
+---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
+----- These terms do NOT apply to the JPEG software itself; see README ------
+
+ GHOSTSCRIPT GENERAL PUBLIC LICENSE
+ (Clarified 11 Feb 1988)
+
+ Copyright (C) 1988 Richard M. Stallman
+ Everyone is permitted to copy and distribute verbatim copies of this
+ license, but changing it is not allowed. You can also use this wording
+ to make the terms for other programs.
+
+ The license agreements of most software companies keep you at the
+mercy of those companies. By contrast, our general public license is
+intended to give everyone the right to share Ghostscript. To make sure
+that you get the rights we want you to have, we need to make
+restrictions that forbid anyone to deny you these rights or to ask you
+to surrender the rights. Hence this license agreement.
+
+ Specifically, we want to make sure that you have the right to give
+away copies of Ghostscript, that you receive source code or else can get
+it if you want it, that you can change Ghostscript or use pieces of it
+in new free programs, and that you know you can do these things.
+
+ To make sure that everyone has such rights, we have to forbid you to
+deprive anyone else of these rights. For example, if you distribute
+copies of Ghostscript, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must tell them their rights.
+
+ Also, for our own protection, we must make certain that everyone finds
+out that there is no warranty for Ghostscript. If Ghostscript is
+modified by someone else and passed on, we want its recipients to know
+that what they have is not what we distributed, so that any problems
+introduced by others will not reflect on our reputation.
+
+ Therefore we (Richard M. Stallman and the Free Software Foundation,
+Inc.) make the following terms which say what you must do to be allowed
+to distribute or change Ghostscript.
+
+
+ COPYING POLICIES
+
+ 1. You may copy and distribute verbatim copies of Ghostscript source
+code as you receive it, in any medium, provided that you conspicuously
+and appropriately publish on each copy a valid copyright and license
+notice "Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
+Distributed by Free Software Foundation, Inc." (or with whatever year is
+appropriate); keep intact the notices on all files that refer to this
+License Agreement and to the absence of any warranty; and give any other
+recipients of the Ghostscript program a copy of this License Agreement
+along with the program. You may charge a distribution fee for the
+physical act of transferring a copy.
+
+ 2. You may modify your copy or copies of Ghostscript or any portion of
+it, and copy and distribute such modifications under the terms of
+Paragraph 1 above, provided that you also do the following:
+
+ a) cause the modified files to carry prominent notices stating
+ that you changed the files and the date of any change; and
+
+ b) cause the whole of any work that you distribute or publish,
+ that in whole or in part contains or is a derivative of Ghostscript
+ or any part thereof, to be licensed at no charge to all third
+ parties on terms identical to those contained in this License
+ Agreement (except that you may choose to grant more extensive
+ warranty protection to some or all third parties, at your option).
+
+ c) You may charge a distribution fee for the physical act of
+ transferring a copy, and you may at your option offer warranty
+ protection in exchange for a fee.
+
+Mere aggregation of another unrelated program with this program (or its
+derivative) on a volume of a storage or distribution medium does not bring
+the other program under the scope of these terms.
+
+ 3. You may copy and distribute Ghostscript (or a portion or derivative
+of it, under Paragraph 2) in object code or executable form under the
+terms of Paragraphs 1 and 2 above provided that you also do one of the
+following:
+
+ a) accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of
+ Paragraphs 1 and 2 above; or,
+
+ b) accompany it with a written offer, valid for at least three
+ years, to give any third party free (except for a nominal
+ shipping charge) a complete machine-readable copy of the
+ corresponding source code, to be distributed under the terms of
+ Paragraphs 1 and 2 above; or,
+
+ c) accompany it with the information you received as to where the
+ corresponding source code may be obtained. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form alone.)
+
+For an executable file, complete source code means all the source code for
+all modules it contains; but, as a special exception, it need not include
+source code for modules which are standard libraries that accompany the
+operating system on which the executable file runs.
+
+ 4. You may not copy, sublicense, distribute or transfer Ghostscript
+except as expressly provided under this License Agreement. Any attempt
+otherwise to copy, sublicense, distribute or transfer Ghostscript is
+void and your rights to use the program under this License agreement
+shall be automatically terminated. However, parties who have received
+computer software programs from you with this License Agreement will not
+have their licenses terminated so long as such parties remain in full
+compliance.
+
+ 5. If you wish to incorporate parts of Ghostscript into other free
+programs whose distribution conditions are different, write to the Free
+Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not
+yet worked out a simple rule that can be stated here, but we will often
+permit this. We will be guided by the two goals of preserving the free
+status of all derivatives of our free software and of promoting the
+sharing and reuse of software.
+
+Your comments and suggestions about our licensing policies and our
+software are welcome! Please contact the Free Software Foundation,
+Inc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
+
+ NO WARRANTY
+
+ BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
+NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
+WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
+M. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
+PROVIDE GHOSTSCRIPT "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
+ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF GHOSTSCRIPT IS WITH
+YOU. SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
+STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
+ENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
+GHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
+ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
+(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
+INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
+PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
+HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
+BY ANY OTHER PARTY.
+
+-------------------- End of file COPYLEFT ------------------------------
+*/
+
+/*
+ * Usage:
+ ansi2knr input_file [output_file]
+ * If no output_file is supplied, output goes to stdout.
+ * There are no error messages.
+ *
+ * ansi2knr recognizes function definitions by seeing a non-keyword
+ * identifier at the left margin, followed by a left parenthesis,
+ * with a right parenthesis as the last character on the line,
+ * and with a left brace as the first token on the following line
+ * (ignoring possible intervening comments).
+ * It will recognize a multi-line header provided that no intervening
+ * line ends with a left or right brace or a semicolon.
+ * These algorithms ignore whitespace and comments, except that
+ * the function name must be the first thing on the line.
+ * The following constructs will confuse it:
+ * - Any other construct that starts at the left margin and
+ * follows the above syntax (such as a macro or function call).
+ * - Some macros that tinker with the syntax of the function header.
+ */
+
+/*
+ * The original and principal author of ansi2knr is L. Peter Deutsch
+ * <ghost@aladdin.com>. Other authors are noted in the change history
+ * that follows (in reverse chronological order):
+ lpd 96-01-21 added code to cope with not HAVE_CONFIG_H and with
+ compilers that don't understand void, as suggested by
+ Tom Lane
+ lpd 96-01-15 changed to require that the first non-comment token
+ on the line following a function header be a left brace,
+ to reduce sensitivity to macros, as suggested by Tom Lane
+ <tgl@sss.pgh.pa.us>
+ lpd 95-06-22 removed #ifndefs whose sole purpose was to define
+ undefined preprocessor symbols as 0; changed all #ifdefs
+ for configuration symbols to #ifs
+ lpd 95-04-05 changed copyright notice to make it clear that
+ including ansi2knr in a program does not bring the entire
+ program under the GPL
+ lpd 94-12-18 added conditionals for systems where ctype macros
+ don't handle 8-bit characters properly, suggested by
+ Francois Pinard <pinard@iro.umontreal.ca>;
+ removed --varargs switch (this is now the default)
+ lpd 94-10-10 removed CONFIG_BROKETS conditional
+ lpd 94-07-16 added some conditionals to help GNU `configure',
+ suggested by Francois Pinard <pinard@iro.umontreal.ca>;
+ properly erase prototype args in function parameters,
+ contributed by Jim Avera <jima@netcom.com>;
+ correct error in writeblanks (it shouldn't erase EOLs)
+ lpd 89-xx-xx original version
+ */
+
+/* Most of the conditionals here are to make ansi2knr work with */
+/* or without the GNU configure machinery. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+
+#if HAVE_CONFIG_H
+
+/*
+ For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
+ This will define HAVE_CONFIG_H and so, activate the following lines.
+ */
+
+# if STDC_HEADERS || HAVE_STRING_H
+# include <string.h>
+# else
+# include <strings.h>
+# endif
+
+#else /* not HAVE_CONFIG_H */
+
+/* Otherwise do it the hard way */
+
+# ifdef BSD
+# include <strings.h>
+# else
+# ifdef VMS
+ extern int strlen(), strncmp();
+# else
+# include <string.h>
+# endif
+# endif
+
+#endif /* not HAVE_CONFIG_H */
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#else
+/*
+ malloc and free should be declared in stdlib.h,
+ but if you've got a K&R compiler, they probably aren't.
+ */
+# ifdef MSDOS
+# include <malloc.h>
+# else
+# ifdef VMS
+ extern char *malloc();
+ extern void free();
+# else
+ extern char *malloc();
+ extern int free();
+# endif
+# endif
+
+#endif
+
+/*
+ * The ctype macros don't always handle 8-bit characters correctly.
+ * Compensate for this here.
+ */
+#ifdef isascii
+# undef HAVE_ISASCII /* just in case */
+# define HAVE_ISASCII 1
+#else
+#endif
+#if STDC_HEADERS || !HAVE_ISASCII
+# define is_ascii(c) 1
+#else
+# define is_ascii(c) isascii(c)
+#endif
+
+#define is_space(c) (is_ascii(c) && isspace(c))
+#define is_alpha(c) (is_ascii(c) && isalpha(c))
+#define is_alnum(c) (is_ascii(c) && isalnum(c))
+
+/* Scanning macros */
+#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
+#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
+
+/* Forward references */
+char *skipspace();
+int writeblanks();
+int test1();
+int convert1();
+
+/* The main program */
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{ FILE *in, *out;
+#define bufsize 5000 /* arbitrary size */
+ char *buf;
+ char *line;
+ char *more;
+ /*
+ * In previous versions, ansi2knr recognized a --varargs switch.
+ * If this switch was supplied, ansi2knr would attempt to convert
+ * a ... argument to va_alist and va_dcl; if this switch was not
+ * supplied, ansi2knr would simply drop any such arguments.
+ * Now, ansi2knr always does this conversion, and we only
+ * check for this switch for backward compatibility.
+ */
+ int convert_varargs = 1;
+
+ if ( argc > 1 && argv[1][0] == '-' )
+ { if ( !strcmp(argv[1], "--varargs") )
+ { convert_varargs = 1;
+ argc--;
+ argv++;
+ }
+ else
+ { fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
+ exit(1);
+ }
+ }
+ switch ( argc )
+ {
+ default:
+ printf("Usage: ansi2knr input_file [output_file]\n");
+ exit(0);
+ case 2:
+ out = stdout;
+ break;
+ case 3:
+ out = fopen(argv[2], "w");
+ if ( out == NULL )
+ { fprintf(stderr, "Cannot open output file %s\n", argv[2]);
+ exit(1);
+ }
+ }
+ in = fopen(argv[1], "r");
+ if ( in == NULL )
+ { fprintf(stderr, "Cannot open input file %s\n", argv[1]);
+ exit(1);
+ }
+ fprintf(out, "#line 1 \"%s\"\n", argv[1]);
+ buf = malloc(bufsize);
+ line = buf;
+ while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
+ {
+test: line += strlen(line);
+ switch ( test1(buf) )
+ {
+ case 2: /* a function header */
+ convert1(buf, out, 1, convert_varargs);
+ break;
+ case 1: /* a function */
+ /* Check for a { at the start of the next line. */
+ more = ++line;
+f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
+ goto wl;
+ if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
+ goto wl;
+ switch ( *skipspace(more, 1) )
+ {
+ case '{':
+ /* Definitely a function header. */
+ convert1(buf, out, 0, convert_varargs);
+ fputs(more, out);
+ break;
+ case 0:
+ /* The next line was blank or a comment: */
+ /* keep scanning for a non-comment. */
+ line += strlen(line);
+ goto f;
+ default:
+ /* buf isn't a function header, but */
+ /* more might be. */
+ fputs(buf, out);
+ strcpy(buf, more);
+ line = buf;
+ goto test;
+ }
+ break;
+ case -1: /* maybe the start of a function */
+ if ( line != buf + (bufsize - 1) ) /* overflow check */
+ continue;
+ /* falls through */
+ default: /* not a function */
+wl: fputs(buf, out);
+ break;
+ }
+ line = buf;
+ }
+ if ( line != buf )
+ fputs(buf, out);
+ free(buf);
+ fclose(out);
+ fclose(in);
+ return 0;
+}
+
+/* Skip over space and comments, in either direction. */
+char *
+skipspace(p, dir)
+ register char *p;
+ register int dir; /* 1 for forward, -1 for backward */
+{ for ( ; ; )
+ { while ( is_space(*p) )
+ p += dir;
+ if ( !(*p == '/' && p[dir] == '*') )
+ break;
+ p += dir; p += dir;
+ while ( !(*p == '*' && p[dir] == '/') )
+ { if ( *p == 0 )
+ return p; /* multi-line comment?? */
+ p += dir;
+ }
+ p += dir; p += dir;
+ }
+ return p;
+}
+
+/*
+ * Write blanks over part of a string.
+ * Don't overwrite end-of-line characters.
+ */
+int
+writeblanks(start, end)
+ char *start;
+ char *end;
+{ char *p;
+ for ( p = start; p < end; p++ )
+ if ( *p != '\r' && *p != '\n' )
+ *p = ' ';
+ return 0;
+}
+
+/*
+ * Test whether the string in buf is a function definition.
+ * The string may contain and/or end with a newline.
+ * Return as follows:
+ * 0 - definitely not a function definition;
+ * 1 - definitely a function definition;
+ * 2 - definitely a function prototype (NOT USED);
+ * -1 - may be the beginning of a function definition,
+ * append another line and look again.
+ * The reason we don't attempt to convert function prototypes is that
+ * Ghostscript's declaration-generating macros look too much like
+ * prototypes, and confuse the algorithms.
+ */
+int
+test1(buf)
+ char *buf;
+{ register char *p = buf;
+ char *bend;
+ char *endfn;
+ int contin;
+
+ if ( !isidfirstchar(*p) )
+ return 0; /* no name at left margin */
+ bend = skipspace(buf + strlen(buf) - 1, -1);
+ switch ( *bend )
+ {
+ case ';': contin = 0 /*2*/; break;
+ case ')': contin = 1; break;
+ case '{': return 0; /* not a function */
+ case '}': return 0; /* not a function */
+ default: contin = -1;
+ }
+ while ( isidchar(*p) )
+ p++;
+ endfn = p;
+ p = skipspace(p, 1);
+ if ( *p++ != '(' )
+ return 0; /* not a function */
+ p = skipspace(p, 1);
+ if ( *p == ')' )
+ return 0; /* no parameters */
+ /* Check that the apparent function name isn't a keyword. */
+ /* We only need to check for keywords that could be followed */
+ /* by a left parenthesis (which, unfortunately, is most of them). */
+ { static char *words[] =
+ { "asm", "auto", "case", "char", "const", "double",
+ "extern", "float", "for", "if", "int", "long",
+ "register", "return", "short", "signed", "sizeof",
+ "static", "switch", "typedef", "unsigned",
+ "void", "volatile", "while", 0
+ };
+ char **key = words;
+ char *kp;
+ int len = endfn - buf;
+
+ while ( (kp = *key) != 0 )
+ { if ( strlen(kp) == len && !strncmp(kp, buf, len) )
+ return 0; /* name is a keyword */
+ key++;
+ }
+ }
+ return contin;
+}
+
+/* Convert a recognized function definition or header to K&R syntax. */
+int
+convert1(buf, out, header, convert_varargs)
+ char *buf;
+ FILE *out;
+ int header; /* Boolean */
+ int convert_varargs; /* Boolean */
+{ char *endfn;
+ register char *p;
+ char **breaks;
+ unsigned num_breaks = 2; /* for testing */
+ char **btop;
+ char **bp;
+ char **ap;
+ char *vararg = 0;
+
+ /* Pre-ANSI implementations don't agree on whether strchr */
+ /* is called strchr or index, so we open-code it here. */
+ for ( endfn = buf; *(endfn++) != '('; )
+ ;
+top: p = endfn;
+ breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
+ if ( breaks == 0 )
+ { /* Couldn't allocate break table, give up */
+ fprintf(stderr, "Unable to allocate break table!\n");
+ fputs(buf, out);
+ return -1;
+ }
+ btop = breaks + num_breaks * 2 - 2;
+ bp = breaks;
+ /* Parse the argument list */
+ do
+ { int level = 0;
+ char *lp = NULL;
+ char *rp;
+ char *end = NULL;
+
+ if ( bp >= btop )
+ { /* Filled up break table. */
+ /* Allocate a bigger one and start over. */
+ free((char *)breaks);
+ num_breaks <<= 1;
+ goto top;
+ }
+ *bp++ = p;
+ /* Find the end of the argument */
+ for ( ; end == NULL; p++ )
+ { switch(*p)
+ {
+ case ',':
+ if ( !level ) end = p;
+ break;
+ case '(':
+ if ( !level ) lp = p;
+ level++;
+ break;
+ case ')':
+ if ( --level < 0 ) end = p;
+ else rp = p;
+ break;
+ case '/':
+ p = skipspace(p, 1) - 1;
+ break;
+ default:
+ ;
+ }
+ }
+ /* Erase any embedded prototype parameters. */
+ if ( lp )
+ writeblanks(lp + 1, rp);
+ p--; /* back up over terminator */
+ /* Find the name being declared. */
+ /* This is complicated because of procedure and */
+ /* array modifiers. */
+ for ( ; ; )
+ { p = skipspace(p - 1, -1);
+ switch ( *p )
+ {
+ case ']': /* skip array dimension(s) */
+ case ')': /* skip procedure args OR name */
+ { int level = 1;
+ while ( level )
+ switch ( *--p )
+ {
+ case ']': case ')': level++; break;
+ case '[': case '(': level--; break;
+ case '/': p = skipspace(p, -1) + 1; break;
+ default: ;
+ }
+ }
+ if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
+ { /* We found the name being declared */
+ while ( !isidfirstchar(*p) )
+ p = skipspace(p, 1) + 1;
+ goto found;
+ }
+ break;
+ default:
+ goto found;
+ }
+ }
+found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
+ { if ( convert_varargs )
+ { *bp++ = "va_alist";
+ vararg = p-2;
+ }
+ else
+ { p++;
+ if ( bp == breaks + 1 ) /* sole argument */
+ writeblanks(breaks[0], p);
+ else
+ writeblanks(bp[-1] - 1, p);
+ bp--;
+ }
+ }
+ else
+ { while ( isidchar(*p) ) p--;
+ *bp++ = p+1;
+ }
+ p = end;
+ }
+ while ( *p++ == ',' );
+ *bp = p;
+ /* Make a special check for 'void' arglist */
+ if ( bp == breaks+2 )
+ { p = skipspace(breaks[0], 1);
+ if ( !strncmp(p, "void", 4) )
+ { p = skipspace(p+4, 1);
+ if ( p == breaks[2] - 1 )
+ { bp = breaks; /* yup, pretend arglist is empty */
+ writeblanks(breaks[0], p + 1);
+ }
+ }
+ }
+ /* Put out the function name and left parenthesis. */
+ p = buf;
+ while ( p != endfn ) putc(*p, out), p++;
+ /* Put out the declaration. */
+ if ( header )
+ { fputs(");", out);
+ for ( p = breaks[0]; *p; p++ )
+ if ( *p == '\r' || *p == '\n' )
+ putc(*p, out);
+ }
+ else
+ { for ( ap = breaks+1; ap < bp; ap += 2 )
+ { p = *ap;
+ while ( isidchar(*p) )
+ putc(*p, out), p++;
+ if ( ap < bp - 1 )
+ fputs(", ", out);
+ }
+ fputs(") ", out);
+ /* Put out the argument declarations */
+ for ( ap = breaks+2; ap <= bp; ap += 2 )
+ (*ap)[-1] = ';';
+ if ( vararg != 0 )
+ { *vararg = 0;
+ fputs(breaks[0], out); /* any prior args */
+ fputs("va_dcl", out); /* the final arg */
+ fputs(bp[0], out);
+ }
+ else
+ fputs(breaks[0], out);
+ }
+ free((char *)breaks);
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg/cderror.h b/osframework/source/ImageLib/jpeg/cderror.h
new file mode 100644
index 0000000..c19d38f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/cderror.h
@@ -0,0 +1,132 @@
+/*
+ * cderror.h
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file defines the error and message codes for the cjpeg/djpeg
+ * applications. These strings are not needed as part of the JPEG library
+ * proper.
+ * Edit this file to add new codes, or to translate the message strings to
+ * some other language.
+ */
+
+/*
+ * To define the enum list of message codes, include this file without
+ * defining macro JMESSAGE. To create a message string table, include it
+ * again with a suitable JMESSAGE definition (see jerror.c for an example).
+ */
+#ifndef JMESSAGE
+#ifndef CDERROR_H
+#define CDERROR_H
+/* First time through, define the enum list */
+#define JMAKE_ENUM_LIST
+#else
+/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
+#define JMESSAGE(code,string)
+#endif /* CDERROR_H */
+#endif /* JMESSAGE */
+
+#ifdef JMAKE_ENUM_LIST
+
+typedef enum {
+
+#define JMESSAGE(code,string) code ,
+
+#endif /* JMAKE_ENUM_LIST */
+
+JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
+
+#ifdef BMP_SUPPORTED
+JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
+JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
+JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
+JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
+JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
+JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
+JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
+JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
+JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
+JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
+JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
+#endif /* BMP_SUPPORTED */
+
+#ifdef GIF_SUPPORTED
+JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
+JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
+JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
+JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
+JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
+JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
+JMESSAGE(JTRC_GIF_BADVERSION,
+ "Warning: unexpected GIF version number '%c%c%c'")
+JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
+JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
+JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
+JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
+JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
+JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
+#endif /* GIF_SUPPORTED */
+
+#ifdef PPM_SUPPORTED
+JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
+JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
+JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
+JMESSAGE(JTRC_PGM, "%ux%u PGM image")
+JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
+JMESSAGE(JTRC_PPM, "%ux%u PPM image")
+JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
+#endif /* PPM_SUPPORTED */
+
+#ifdef RLE_SUPPORTED
+JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
+JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
+JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
+JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
+JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
+JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
+JMESSAGE(JERR_RLE_NOT, "Not an RLE file")
+JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
+JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
+JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
+JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
+JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
+JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
+JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
+#endif /* RLE_SUPPORTED */
+
+#ifdef TARGA_SUPPORTED
+JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
+JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
+JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
+JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
+JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
+JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
+#else
+JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
+#endif /* TARGA_SUPPORTED */
+
+JMESSAGE(JERR_BAD_CMAP_FILE,
+ "Color map file is invalid or of unsupported format")
+JMESSAGE(JERR_TOO_MANY_COLORS,
+ "Output file format cannot handle %d colormap entries")
+JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
+#ifdef TARGA_SUPPORTED
+JMESSAGE(JERR_UNKNOWN_FORMAT,
+ "Unrecognized input file format --- perhaps you need -targa")
+#else
+JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
+#endif
+JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")
+
+#ifdef JMAKE_ENUM_LIST
+
+ JMSG_LASTADDONCODE
+} ADDON_MESSAGE_CODE;
+
+#undef JMAKE_ENUM_LIST
+#endif /* JMAKE_ENUM_LIST */
+
+/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
+#undef JMESSAGE
diff --git a/osframework/source/ImageLib/jpeg/cdjpeg.c b/osframework/source/ImageLib/jpeg/cdjpeg.c
new file mode 100644
index 0000000..89fe633
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/cdjpeg.c
@@ -0,0 +1,181 @@
+/*
+ * cdjpeg.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains common support routines used by the IJG application
+ * programs (cjpeg, djpeg, jpegtran).
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef NEED_SIGNAL_CATCHER
+#include <signal.h> /* to declare signal() */
+#endif
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+
+/*
+ * Signal catcher to ensure that temporary files are removed before aborting.
+ * NB: for Amiga Manx C this is actually a global routine named _abort();
+ * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
+ */
+
+#ifdef NEED_SIGNAL_CATCHER
+
+static j_common_ptr sig_cinfo;
+
+void /* must be global for Manx C */
+signal_catcher (int signum)
+{
+ if (sig_cinfo != NULL) {
+ if (sig_cinfo->err != NULL) /* turn off trace output */
+ sig_cinfo->err->trace_level = 0;
+ jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
+ }
+ exit(EXIT_FAILURE);
+}
+
+
+GLOBAL(void)
+enable_signal_catcher (j_common_ptr cinfo)
+{
+ sig_cinfo = cinfo;
+#ifdef SIGINT /* not all systems have SIGINT */
+ signal(SIGINT, signal_catcher);
+#endif
+#ifdef SIGTERM /* not all systems have SIGTERM */
+ signal(SIGTERM, signal_catcher);
+#endif
+}
+
+#endif
+
+
+/*
+ * Optional progress monitor: display a percent-done figure on stderr.
+ */
+
+#ifdef PROGRESS_REPORT
+
+METHODDEF(void)
+progress_monitor (j_common_ptr cinfo)
+{
+ cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
+ int total_passes = prog->pub.total_passes + prog->total_extra_passes;
+ int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
+
+ if (percent_done != prog->percent_done) {
+ prog->percent_done = percent_done;
+ if (total_passes > 1) {
+ fprintf(stderr, "\rPass %d/%d: %3d%% ",
+ prog->pub.completed_passes + prog->completed_extra_passes + 1,
+ total_passes, percent_done);
+ } else {
+ fprintf(stderr, "\r %3d%% ", percent_done);
+ }
+ fflush(stderr);
+ }
+}
+
+
+GLOBAL(void)
+start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
+{
+ /* Enable progress display, unless trace output is on */
+ if (cinfo->err->trace_level == 0) {
+ progress->pub.progress_monitor = progress_monitor;
+ progress->completed_extra_passes = 0;
+ progress->total_extra_passes = 0;
+ progress->percent_done = -1;
+ cinfo->progress = &progress->pub;
+ }
+}
+
+
+GLOBAL(void)
+end_progress_monitor (j_common_ptr cinfo)
+{
+ /* Clear away progress display */
+ if (cinfo->err->trace_level == 0) {
+ fprintf(stderr, "\r \r");
+ fflush(stderr);
+ }
+}
+
+#endif
+
+
+/*
+ * Case-insensitive matching of possibly-abbreviated keyword switches.
+ * keyword is the constant keyword (must be lower case already),
+ * minchars is length of minimum legal abbreviation.
+ */
+
+GLOBAL(boolean)
+keymatch (char * arg, const char * keyword, int minchars)
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return FALSE; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return FALSE; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return FALSE;
+ return TRUE; /* A-OK */
+}
+
+
+/*
+ * Routines to establish binary I/O mode for stdin and stdout.
+ * Non-Unix systems often require some hacking to get out of text mode.
+ */
+
+GLOBAL(FILE *)
+read_stdin (void)
+{
+ FILE * input_file = stdin;
+
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "Cannot reopen stdin\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
+ return input_file;
+}
+
+
+GLOBAL(FILE *)
+write_stdout (void)
+{
+ FILE * output_file = stdout;
+
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdout), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "Cannot reopen stdout\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
+ return output_file;
+}
diff --git a/osframework/source/ImageLib/jpeg/cdjpeg.h b/osframework/source/ImageLib/jpeg/cdjpeg.h
new file mode 100644
index 0000000..1574e0b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/cdjpeg.h
@@ -0,0 +1,184 @@
+/*
+ * cdjpeg.h
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains common declarations for the sample applications
+ * cjpeg and djpeg. It is NOT used by the core JPEG library.
+ */
+
+#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
+#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jerror.h" /* get library error codes too */
+#include "cderror.h" /* get application-specific error codes */
+
+
+/*
+ * Object interface for cjpeg's source file decoding modules
+ */
+
+typedef struct cjpeg_source_struct * cjpeg_source_ptr;
+
+struct cjpeg_source_struct {
+ JMETHOD(void, start_input, (j_compress_ptr cinfo,
+ cjpeg_source_ptr sinfo));
+ JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
+ cjpeg_source_ptr sinfo));
+ JMETHOD(void, finish_input, (j_compress_ptr cinfo,
+ cjpeg_source_ptr sinfo));
+
+ FILE *input_file;
+
+ JSAMPARRAY buffer;
+ JDIMENSION buffer_height;
+};
+
+
+/*
+ * Object interface for djpeg's output file encoding modules
+ */
+
+typedef struct djpeg_dest_struct * djpeg_dest_ptr;
+
+struct djpeg_dest_struct {
+ /* start_output is called after jpeg_start_decompress finishes.
+ * The color map will be ready at this time, if one is needed.
+ */
+ JMETHOD(void, start_output, (j_decompress_ptr cinfo,
+ djpeg_dest_ptr dinfo));
+ /* Emit the specified number of pixel rows from the buffer. */
+ JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
+ djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied));
+ /* Finish up at the end of the image. */
+ JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
+ djpeg_dest_ptr dinfo));
+
+ /* Target file spec; filled in by djpeg.c after object is created. */
+ FILE * output_file;
+
+ /* Output pixel-row buffer. Created by module init or start_output.
+ * Width is cinfo->output_width * cinfo->output_components;
+ * height is buffer_height.
+ */
+ JSAMPARRAY buffer;
+ JDIMENSION buffer_height;
+};
+
+
+/*
+ * cjpeg/djpeg may need to perform extra passes to convert to or from
+ * the source/destination file format. The JPEG library does not know
+ * about these passes, but we'd like them to be counted by the progress
+ * monitor. We use an expanded progress monitor object to hold the
+ * additional pass count.
+ */
+
+struct cdjpeg_progress_mgr {
+ struct jpeg_progress_mgr pub; /* fields known to JPEG library */
+ int completed_extra_passes; /* extra passes completed */
+ int total_extra_passes; /* total extra */
+ /* last printed percentage stored here to avoid multiple printouts */
+ int percent_done;
+};
+
+typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
+
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jinit_read_bmp jIRdBMP
+#define jinit_write_bmp jIWrBMP
+#define jinit_read_gif jIRdGIF
+#define jinit_write_gif jIWrGIF
+#define jinit_read_ppm jIRdPPM
+#define jinit_write_ppm jIWrPPM
+#define jinit_read_rle jIRdRLE
+#define jinit_write_rle jIWrRLE
+#define jinit_read_targa jIRdTarga
+#define jinit_write_targa jIWrTarga
+#define read_quant_tables RdQTables
+#define read_scan_script RdScnScript
+#define set_quant_slots SetQSlots
+#define set_sample_factors SetSFacts
+#define read_color_map RdCMap
+#define enable_signal_catcher EnSigCatcher
+#define start_progress_monitor StProgMon
+#define end_progress_monitor EnProgMon
+#define read_stdin RdStdin
+#define write_stdout WrStdout
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+/* Module selection routines for I/O modules. */
+
+EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
+EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
+ boolean is_os2));
+EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
+EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
+EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
+EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
+EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
+EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
+EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
+EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
+
+/* cjpeg support routines (in rdswitch.c) */
+
+EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
+ int scale_factor, boolean force_baseline));
+EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
+EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
+EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
+
+/* djpeg support routines (in rdcolmap.c) */
+
+EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
+
+/* common support routines (in cdjpeg.c) */
+
+EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
+EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
+ cd_progress_ptr progress));
+EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
+EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
+EXTERN(FILE *) read_stdin JPP((void));
+EXTERN(FILE *) write_stdout JPP((void));
+
+/* miscellaneous useful macros */
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#define WRITE_BINARY "w"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#define WRITE_BINARY "wb", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#define WRITE_BINARY "wb"
+#endif
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+#ifdef VMS
+#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
+#else
+#define EXIT_SUCCESS 0
+#endif
+#endif
+#ifndef EXIT_WARNING
+#ifdef VMS
+#define EXIT_WARNING 1 /* VMS is very nonstandard */
+#else
+#define EXIT_WARNING 2
+#endif
+#endif
diff --git a/osframework/source/ImageLib/jpeg/change.log b/osframework/source/ImageLib/jpeg/change.log
new file mode 100644
index 0000000..953680c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/change.log
@@ -0,0 +1,217 @@
+CHANGE LOG for Independent JPEG Group's JPEG software
+
+
+Version 6b 27-Mar-1998
+-----------------------
+
+jpegtran has new features for lossless image transformations (rotation
+and flipping) as well as "lossless" reduction to grayscale.
+
+jpegtran now copies comments by default; it has a -copy switch to enable
+copying all APPn blocks as well, or to suppress comments. (Formerly it
+always suppressed comments and APPn blocks.) jpegtran now also preserves
+JFIF version and resolution information.
+
+New decompressor library feature: COM and APPn markers found in the input
+file can be saved in memory for later use by the application. (Before,
+you had to code this up yourself with a custom marker processor.)
+
+There is an unused field "void * client_data" now in compress and decompress
+parameter structs; this may be useful in some applications.
+
+JFIF version number information is now saved by the decoder and accepted by
+the encoder. jpegtran uses this to copy the source file's version number,
+to ensure "jpegtran -copy all" won't create bogus files that contain JFXX
+extensions but claim to be version 1.01. Applications that generate their
+own JFXX extension markers also (finally) have a supported way to cause the
+encoder to emit JFIF version number 1.02.
+
+djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather
+than as unknown APP0 markers.
+
+In -verbose mode, djpeg and rdjpgcom will try to print the contents of
+APP12 markers as text. Some digital cameras store useful text information
+in APP12 markers.
+
+Handling of truncated data streams is more robust: blocks beyond the one in
+which the error occurs will be output as uniform gray, or left unchanged
+if decoding a progressive JPEG. The appearance no longer depends on the
+Huffman tables being used.
+
+Huffman tables are checked for validity much more carefully than before.
+
+To avoid the Unisys LZW patent, djpeg's GIF output capability has been
+changed to produce "uncompressed GIFs", and cjpeg's GIF input capability
+has been removed altogether. We're not happy about it either, but there
+seems to be no good alternative.
+
+The configure script now supports building libjpeg as a shared library
+on many flavors of Unix (all the ones that GNU libtool knows how to
+build shared libraries for). Use "./configure --enable-shared" to
+try this out.
+
+New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio.
+Also, a jconfig file and a build script for Metrowerks CodeWarrior
+on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there
+are miscellaneous other minor improvements in the makefiles.
+
+jmemmac.c now knows how to create temporary files following Mac System 7
+conventions.
+
+djpeg's -map switch is now able to read raw-format PPM files reliably.
+
+cjpeg -progressive -restart no longer generates any unnecessary DRI markers.
+
+Multiple calls to jpeg_simple_progression for a single JPEG object
+no longer leak memory.
+
+
+Version 6a 7-Feb-96
+--------------------
+
+Library initialization sequence modified to detect version mismatches
+and struct field packing mismatches between library and calling application.
+This change requires applications to be recompiled, but does not require
+any application source code change.
+
+All routine declarations changed to the style "GLOBAL(type) name ...",
+that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the
+routine's return type as an argument. This makes it possible to add
+Microsoft-style linkage keywords to all the routines by changing just
+these macros. Note that any application code that was using these macros
+will have to be changed.
+
+DCT coefficient quantization tables are now stored in normal array order
+rather than zigzag order. Application code that calls jpeg_add_quant_table,
+or otherwise manipulates quantization tables directly, will need to be
+changed. If you need to make such code work with either older or newer
+versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is
+recommended.
+
+djpeg's trace capability now dumps DQT tables in natural order, not zigzag
+order. This allows the trace output to be made into a "-qtables" file
+more easily.
+
+New system-dependent memory manager module for use on Apple Macintosh.
+
+Fix bug in cjpeg's -smooth option: last one or two scanlines would be
+duplicates of the prior line unless the image height mod 16 was 1 or 2.
+
+Repair minor problems in VMS, BCC, MC6 makefiles.
+
+New configure script based on latest GNU Autoconf.
+
+Correct the list of include files needed by MetroWerks C for ccommand().
+
+Numerous small documentation updates.
+
+
+Version 6 2-Aug-95
+-------------------
+
+Progressive JPEG support: library can read and write full progressive JPEG
+files. A "buffered image" mode supports incremental decoding for on-the-fly
+display of progressive images. Simply recompiling an existing IJG-v5-based
+decoder with v6 should allow it to read progressive files, though of course
+without any special progressive display.
+
+New "jpegtran" application performs lossless transcoding between different
+JPEG formats; primarily, it can be used to convert baseline to progressive
+JPEG and vice versa. In support of jpegtran, the library now allows lossless
+reading and writing of JPEG files as DCT coefficient arrays. This ability
+may be of use in other applications.
+
+Notes for programmers:
+* We changed jpeg_start_decompress() to be able to suspend; this makes all
+decoding modes available to suspending-input applications. However,
+existing applications that use suspending input will need to be changed
+to check the return value from jpeg_start_decompress(). You don't need to
+do anything if you don't use a suspending data source.
+* We changed the interface to the virtual array routines: access_virt_array
+routines now take a count of the number of rows to access this time. The
+last parameter to request_virt_array routines is now interpreted as the
+maximum number of rows that may be accessed at once, but not necessarily
+the height of every access.
+
+
+Version 5b 15-Mar-95
+---------------------
+
+Correct bugs with grayscale images having v_samp_factor > 1.
+
+jpeg_write_raw_data() now supports output suspension.
+
+Correct bugs in "configure" script for case of compiling in
+a directory other than the one containing the source files.
+
+Repair bug in jquant1.c: sometimes didn't use as many colors as it could.
+
+Borland C makefile and jconfig file work under either MS-DOS or OS/2.
+
+Miscellaneous improvements to documentation.
+
+
+Version 5a 7-Dec-94
+--------------------
+
+Changed color conversion roundoff behavior so that grayscale values are
+represented exactly. (This causes test image files to change.)
+
+Make ordered dither use 16x16 instead of 4x4 pattern for a small quality
+improvement.
+
+New configure script based on latest GNU Autoconf.
+Fix configure script to handle CFLAGS correctly.
+Rename *.auto files to *.cfg, so that configure script still works if
+file names have been truncated for DOS.
+
+Fix bug in rdbmp.c: didn't allow for extra data between header and image.
+
+Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data.
+
+Fix several bugs in rdrle.c.
+
+NEED_SHORT_EXTERNAL_NAMES option was broken.
+
+Revise jerror.h/jerror.c for more flexibility in message table.
+
+Repair oversight in jmemname.c NO_MKTEMP case: file could be there
+but unreadable.
+
+
+Version 5 24-Sep-94
+--------------------
+
+Version 5 represents a nearly complete redesign and rewrite of the IJG
+software. Major user-visible changes include:
+ * Automatic configuration simplifies installation for most Unix systems.
+ * A range of speed vs. image quality tradeoffs are supported.
+ This includes resizing of an image during decompression: scaling down
+ by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.
+ * New programs rdjpgcom and wrjpgcom allow insertion and extraction
+ of text comments in a JPEG file.
+
+The application programmer's interface to the library has changed completely.
+Notable improvements include:
+ * We have eliminated the use of callback routines for handling the
+ uncompressed image data. The application now sees the library as a
+ set of routines that it calls to read or write image data on a
+ scanline-by-scanline basis.
+ * The application image data is represented in a conventional interleaved-
+ pixel format, rather than as a separate array for each color channel.
+ This can save a copying step in many programs.
+ * The handling of compressed data has been cleaned up: the application can
+ supply routines to source or sink the compressed data. It is possible to
+ suspend processing on source/sink buffer overrun, although this is not
+ supported in all operating modes.
+ * All static state has been eliminated from the library, so that multiple
+ instances of compression or decompression can be active concurrently.
+ * JPEG abbreviated datastream formats are supported, ie, quantization and
+ Huffman tables can be stored separately from the image data.
+ * And not only that, but the documentation of the library has improved
+ considerably!
+
+
+The last widely used release before the version 5 rewrite was version 4A of
+18-Feb-93. Change logs before that point have been discarded, since they
+are not of much interest after the rewrite.
diff --git a/osframework/source/ImageLib/jpeg/cjpeg.1 b/osframework/source/ImageLib/jpeg/cjpeg.1
new file mode 100644
index 0000000..cf6a5b2
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/cjpeg.1
@@ -0,0 +1,292 @@
+.TH CJPEG 1 "20 March 1998"
+.SH NAME
+cjpeg \- compress an image file to a JPEG file
+.SH SYNOPSIS
+.B cjpeg
+[
+.I options
+]
+[
+.I filename
+]
+.LP
+.SH DESCRIPTION
+.LP
+.B cjpeg
+compresses the named image file, or the standard input if no file is
+named, and produces a JPEG/JFIF file on the standard output.
+The currently supported input file formats are: PPM (PBMPLUS color
+format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster
+Toolkit format). (RLE is supported only if the URT library is available.)
+.SH OPTIONS
+All switch names may be abbreviated; for example,
+.B \-grayscale
+may be written
+.B \-gray
+or
+.BR \-gr .
+Most of the "basic" switches can be abbreviated to as little as one letter.
+Upper and lower case are equivalent (thus
+.B \-BMP
+is the same as
+.BR \-bmp ).
+British spellings are also accepted (e.g.,
+.BR \-greyscale ),
+though for brevity these are not mentioned below.
+.PP
+The basic switches are:
+.TP
+.BI \-quality " N"
+Scale quantization tables to adjust image quality. Quality is 0 (worst) to
+100 (best); default is 75. (See below for more info.)
+.TP
+.B \-grayscale
+Create monochrome JPEG file from color input. Be sure to use this switch when
+compressing a grayscale BMP file, because
+.B cjpeg
+isn't bright enough to notice whether a BMP file uses only shades of gray.
+By saying
+.BR \-grayscale ,
+you'll get a smaller JPEG file that takes less time to process.
+.TP
+.B \-optimize
+Perform optimization of entropy encoding parameters. Without this, default
+encoding parameters are used.
+.B \-optimize
+usually makes the JPEG file a little smaller, but
+.B cjpeg
+runs somewhat slower and needs much more memory. Image quality and speed of
+decompression are unaffected by
+.BR \-optimize .
+.TP
+.B \-progressive
+Create progressive JPEG file (see below).
+.TP
+.B \-targa
+Input file is Targa format. Targa files that contain an "identification"
+field will not be automatically recognized by
+.BR cjpeg ;
+for such files you must specify
+.B \-targa
+to make
+.B cjpeg
+treat the input as Targa format.
+For most Targa files, you won't need this switch.
+.PP
+The
+.B \-quality
+switch lets you trade off compressed file size against quality of the
+reconstructed image: the higher the quality setting, the larger the JPEG file,
+and the closer the output image will be to the original input. Normally you
+want to use the lowest quality setting (smallest file) that decompresses into
+something visually indistinguishable from the original image. For this
+purpose the quality setting should be between 50 and 95; the default of 75 is
+often about right. If you see defects at
+.B \-quality
+75, then go up 5 or 10 counts at a time until you are happy with the output
+image. (The optimal setting will vary from one image to another.)
+.PP
+.B \-quality
+100 will generate a quantization table of all 1's, minimizing loss in the
+quantization step (but there is still information loss in subsampling, as well
+as roundoff error). This setting is mainly of interest for experimental
+purposes. Quality values above about 95 are
+.B not
+recommended for normal use; the compressed file size goes up dramatically for
+hardly any gain in output image quality.
+.PP
+In the other direction, quality values below 50 will produce very small files
+of low image quality. Settings around 5 to 10 might be useful in preparing an
+index of a large image library, for example. Try
+.B \-quality
+2 (or so) for some amusing Cubist effects. (Note: quality
+values below about 25 generate 2-byte quantization tables, which are
+considered optional in the JPEG standard.
+.B cjpeg
+emits a warning message when you give such a quality value, because some
+other JPEG programs may be unable to decode the resulting file. Use
+.B \-baseline
+if you need to ensure compatibility at low quality values.)
+.PP
+The
+.B \-progressive
+switch creates a "progressive JPEG" file. In this type of JPEG file, the data
+is stored in multiple scans of increasing quality. If the file is being
+transmitted over a slow communications link, the decoder can use the first
+scan to display a low-quality image very quickly, and can then improve the
+display with each subsequent scan. The final image is exactly equivalent to a
+standard JPEG file of the same quality setting, and the total file size is
+about the same --- often a little smaller.
+.B Caution:
+progressive JPEG is not yet widely implemented, so many decoders will be
+unable to view a progressive JPEG file at all.
+.PP
+Switches for advanced users:
+.TP
+.B \-dct int
+Use integer DCT method (default).
+.TP
+.B \-dct fast
+Use fast integer DCT (less accurate).
+.TP
+.B \-dct float
+Use floating-point DCT method.
+The float method is very slightly more accurate than the int method, but is
+much slower unless your machine has very fast floating-point hardware. Also
+note that results of the floating-point method may vary slightly across
+machines, while the integer methods should give the same results everywhere.
+The fast integer method is much less accurate than the other two.
+.TP
+.BI \-restart " N"
+Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
+attached to the number.
+.B \-restart 0
+(the default) means no restart markers.
+.TP
+.BI \-smooth " N"
+Smooth the input image to eliminate dithering noise. N, ranging from 1 to
+100, indicates the strength of smoothing. 0 (the default) means no smoothing.
+.TP
+.BI \-maxmemory " N"
+Set limit for amount of memory to use in processing large images. Value is
+in thousands of bytes, or millions of bytes if "M" is attached to the
+number. For example,
+.B \-max 4m
+selects 4000000 bytes. If more space is needed, temporary files will be used.
+.TP
+.BI \-outfile " name"
+Send output image to the named file, not to standard output.
+.TP
+.B \-verbose
+Enable debug printout. More
+.BR \-v 's
+give more output. Also, version information is printed at startup.
+.TP
+.B \-debug
+Same as
+.BR \-verbose .
+.PP
+The
+.B \-restart
+option inserts extra markers that allow a JPEG decoder to resynchronize after
+a transmission error. Without restart markers, any damage to a compressed
+file will usually ruin the image from the point of the error to the end of the
+image; with restart markers, the damage is usually confined to the portion of
+the image up to the next restart marker. Of course, the restart markers
+occupy extra space. We recommend
+.B \-restart 1
+for images that will be transmitted across unreliable networks such as Usenet.
+.PP
+The
+.B \-smooth
+option filters the input to eliminate fine-scale noise. This is often useful
+when converting dithered images to JPEG: a moderate smoothing factor of 10 to
+50 gets rid of dithering patterns in the input file, resulting in a smaller
+JPEG file and a better-looking image. Too large a smoothing factor will
+visibly blur the image, however.
+.PP
+Switches for wizards:
+.TP
+.B \-baseline
+Force baseline-compatible quantization tables to be generated. This clamps
+quantization values to 8 bits even at low quality settings. (This switch is
+poorly named, since it does not ensure that the output is actually baseline
+JPEG. For example, you can use
+.B \-baseline
+and
+.B \-progressive
+together.)
+.TP
+.BI \-qtables " file"
+Use the quantization tables given in the specified text file.
+.TP
+.BI \-qslots " N[,...]"
+Select which quantization table to use for each color component.
+.TP
+.BI \-sample " HxV[,...]"
+Set JPEG sampling factors for each color component.
+.TP
+.BI \-scans " file"
+Use the scan script given in the specified text file.
+.PP
+The "wizard" switches are intended for experimentation with JPEG. If you
+don't know what you are doing, \fBdon't use them\fR. These switches are
+documented further in the file wizard.doc.
+.SH EXAMPLES
+.LP
+This example compresses the PPM file foo.ppm with a quality factor of
+60 and saves the output as foo.jpg:
+.IP
+.B cjpeg \-quality
+.I 60 foo.ppm
+.B >
+.I foo.jpg
+.SH HINTS
+Color GIF files are not the ideal input for JPEG; JPEG is really intended for
+compressing full-color (24-bit) images. In particular, don't try to convert
+cartoons, line drawings, and other images that have only a few distinct
+colors. GIF works great on these, JPEG does not. If you want to convert a
+GIF to JPEG, you should experiment with
+.BR cjpeg 's
+.B \-quality
+and
+.B \-smooth
+options to get a satisfactory conversion.
+.B \-smooth 10
+or so is often helpful.
+.PP
+Avoid running an image through a series of JPEG compression/decompression
+cycles. Image quality loss will accumulate; after ten or so cycles the image
+may be noticeably worse than it was after one cycle. It's best to use a
+lossless format while manipulating an image, then convert to JPEG format when
+you are ready to file the image away.
+.PP
+The
+.B \-optimize
+option to
+.B cjpeg
+is worth using when you are making a "final" version for posting or archiving.
+It's also a win when you are using low quality settings to make very small
+JPEG files; the percentage improvement is often a lot more than it is on
+larger files. (At present,
+.B \-optimize
+mode is always selected when generating progressive JPEG files.)
+.SH ENVIRONMENT
+.TP
+.B JPEGMEM
+If this environment variable is set, its value is the default memory limit.
+The value is specified as described for the
+.B \-maxmemory
+switch.
+.B JPEGMEM
+overrides the default value specified when the program was compiled, and
+itself is overridden by an explicit
+.BR \-maxmemory .
+.SH SEE ALSO
+.BR djpeg (1),
+.BR jpegtran (1),
+.BR rdjpgcom (1),
+.BR wrjpgcom (1)
+.br
+.BR ppm (5),
+.BR pgm (5)
+.br
+Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
+Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
+.SH AUTHOR
+Independent JPEG Group
+.SH BUGS
+Arithmetic coding is not supported for legal reasons.
+.PP
+GIF input files are no longer supported, to avoid the Unisys LZW patent.
+Use a Unisys-licensed program if you need to read a GIF file. (Conversion
+of GIF files to JPEG is usually a bad idea anyway.)
+.PP
+Not all variants of BMP and Targa file formats are supported.
+.PP
+The
+.B \-targa
+switch is not a bug, it's a feature. (It would be a bug if the Targa format
+designers had not been clueless.)
+.PP
+Still not as fast as we'd like.
diff --git a/osframework/source/ImageLib/jpeg/cjpeg.c b/osframework/source/ImageLib/jpeg/cjpeg.c
new file mode 100644
index 0000000..b9102ee
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/cjpeg.c
@@ -0,0 +1,606 @@
+/*
+ * cjpeg.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for the JPEG compressor.
+ * It should work on any system with Unix- or MS-DOS-style command lines.
+ *
+ * Two different command line styles are permitted, depending on the
+ * compile-time switch TWO_FILE_COMMANDLINE:
+ * cjpeg [options] inputfile outputfile
+ * cjpeg [options] [inputfile]
+ * In the second style, output is always to standard output, which you'd
+ * normally redirect to a file or pipe to some other program. Input is
+ * either from a named file or from standard input (typically redirected).
+ * The second style is convenient on Unix but is unhelpful on systems that
+ * don't support pipes. Also, you MUST use the first style if your system
+ * doesn't do binary I/O to stdin/stdout.
+ * To simplify script writing, the "-outfile" switch is provided. The syntax
+ * cjpeg [options] -outfile outputfile inputfile
+ * works regardless of which command line style is used.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "jversion.h" /* for version message */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/* Create the add-on message string table. */
+
+#define JMESSAGE(code,string) string ,
+
+static const char * const cdjpeg_message_table[] = {
+#include "cderror.h"
+ NULL
+};
+
+
+/*
+ * This routine determines what format the input file is,
+ * and selects the appropriate input-reading module.
+ *
+ * To determine which family of input formats the file belongs to,
+ * we may look only at the first byte of the file, since C does not
+ * guarantee that more than one character can be pushed back with ungetc.
+ * Looking at additional bytes would require one of these approaches:
+ * 1) assume we can fseek() the input file (fails for piped input);
+ * 2) assume we can push back more than one character (works in
+ * some C implementations, but unportable);
+ * 3) provide our own buffering (breaks input readers that want to use
+ * stdio directly, such as the RLE library);
+ * or 4) don't put back the data, and modify the input_init methods to assume
+ * they start reading after the start of file (also breaks RLE library).
+ * #1 is attractive for MS-DOS but is untenable on Unix.
+ *
+ * The most portable solution for file types that can't be identified by their
+ * first byte is to make the user tell us what they are. This is also the
+ * only approach for "raw" file types that contain only arbitrary values.
+ * We presently apply this method for Targa files. Most of the time Targa
+ * files start with 0x00, so we recognize that case. Potentially, however,
+ * a Targa file could start with any byte value (byte 0 is the length of the
+ * seldom-used ID field), so we provide a switch to force Targa input mode.
+ */
+
+static boolean is_targa; /* records user -targa switch */
+
+
+LOCAL(cjpeg_source_ptr)
+select_file_type (j_compress_ptr cinfo, FILE * infile)
+{
+ int c;
+
+ if (is_targa) {
+#ifdef TARGA_SUPPORTED
+ return jinit_read_targa(cinfo);
+#else
+ ERREXIT(cinfo, JERR_TGA_NOTCOMP);
+#endif
+ }
+
+ if ((c = getc(infile)) == EOF)
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
+ if (ungetc(c, infile) == EOF)
+ ERREXIT(cinfo, JERR_UNGETC_FAILED);
+
+ switch (c) {
+#ifdef BMP_SUPPORTED
+ case 'B':
+ return jinit_read_bmp(cinfo);
+#endif
+#ifdef GIF_SUPPORTED
+ case 'G':
+ return jinit_read_gif(cinfo);
+#endif
+#ifdef PPM_SUPPORTED
+ case 'P':
+ return jinit_read_ppm(cinfo);
+#endif
+#ifdef RLE_SUPPORTED
+ case 'R':
+ return jinit_read_rle(cinfo);
+#endif
+#ifdef TARGA_SUPPORTED
+ case 0x00:
+ return jinit_read_targa(cinfo);
+#endif
+ default:
+ ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
+ break;
+ }
+
+ return NULL; /* suppress compiler warnings */
+}
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n");
+ fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
+#ifdef ENTROPY_OPT_SUPPORTED
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
+#endif
+#ifdef C_PROGRESSIVE_SUPPORTED
+ fprintf(stderr, " -progressive Create progressive JPEG file\n");
+#endif
+#ifdef TARGA_SUPPORTED
+ fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
+#endif
+ fprintf(stderr, "Switches for advanced users:\n");
+#ifdef DCT_ISLOW_SUPPORTED
+ fprintf(stderr, " -dct int Use integer DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
+#endif
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
+#ifdef INPUT_SMOOTHING_SUPPORTED
+ fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
+#endif
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ fprintf(stderr, "Switches for wizards:\n");
+#ifdef C_ARITH_CODING_SUPPORTED
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
+#endif
+ fprintf(stderr, " -baseline Force baseline quantization tables\n");
+ fprintf(stderr, " -qtables file Use quantization tables given in file\n");
+ fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
+ fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
+#endif
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(int)
+parse_switches (j_compress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+ int quality; /* -quality parameter */
+ int q_scale_factor; /* scaling percentage for -qtables */
+ boolean force_baseline;
+ boolean simple_progressive;
+ char * qtablefile = NULL; /* saves -qtables filename if any */
+ char * qslotsarg = NULL; /* saves -qslots parm if any */
+ char * samplearg = NULL; /* saves -sample parm if any */
+ char * scansarg = NULL; /* saves -scans parm if any */
+
+ /* Set up default JPEG parameters. */
+ /* Note that default -quality level need not, and does not,
+ * match the default scaling for an explicit -qtables argument.
+ */
+ quality = 75; /* default -quality value */
+ q_scale_factor = 100; /* default to no scaling for -qtables */
+ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
+ simple_progressive = FALSE;
+ is_targa = FALSE;
+ outfilename = NULL;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "arithmetic", 1)) {
+ /* Use arithmetic coding. */
+#ifdef C_ARITH_CODING_SUPPORTED
+ cinfo->arith_code = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "baseline", 1)) {
+ /* Force baseline-compatible output (8-bit quantizer values). */
+ force_baseline = TRUE;
+
+ } else if (keymatch(arg, "dct", 2)) {
+ /* Select DCT algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "int", 1)) {
+ cinfo->dct_method = JDCT_ISLOW;
+ } else if (keymatch(argv[argn], "fast", 2)) {
+ cinfo->dct_method = JDCT_IFAST;
+ } else if (keymatch(argv[argn], "float", 2)) {
+ cinfo->dct_method = JDCT_FLOAT;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
+ /* Force a monochrome JPEG file to be generated. */
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
+ /* Enable entropy parm optimization. */
+#ifdef ENTROPY_OPT_SUPPORTED
+ cinfo->optimize_coding = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "progressive", 1)) {
+ /* Select simple progressive mode. */
+#ifdef C_PROGRESSIVE_SUPPORTED
+ simple_progressive = TRUE;
+ /* We must postpone execution until num_components is known. */
+#else
+ fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "quality", 1)) {
+ /* Quality factor (quantization table scaling factor). */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &quality) != 1)
+ usage();
+ /* Change scale factor in case -qtables is present. */
+ q_scale_factor = jpeg_quality_scaling(quality);
+
+ } else if (keymatch(arg, "qslots", 2)) {
+ /* Quantization table slot numbers. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ qslotsarg = argv[argn];
+ /* Must delay setting qslots until after we have processed any
+ * colorspace-determining switches, since jpeg_set_colorspace sets
+ * default quant table numbers.
+ */
+
+ } else if (keymatch(arg, "qtables", 2)) {
+ /* Quantization tables fetched from file. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ qtablefile = argv[argn];
+ /* We postpone actually reading the file in case -quality comes later. */
+
+ } else if (keymatch(arg, "restart", 1)) {
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (lval < 0 || lval > 65535L)
+ usage();
+ if (ch == 'b' || ch == 'B') {
+ cinfo->restart_interval = (unsigned int) lval;
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
+ } else {
+ cinfo->restart_in_rows = (int) lval;
+ /* restart_interval will be computed during startup */
+ }
+
+ } else if (keymatch(arg, "sample", 2)) {
+ /* Set sampling factors. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ samplearg = argv[argn];
+ /* Must delay setting sample factors until after we have processed any
+ * colorspace-determining switches, since jpeg_set_colorspace sets
+ * default sampling factors.
+ */
+
+ } else if (keymatch(arg, "scans", 2)) {
+ /* Set scan script. */
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ scansarg = argv[argn];
+ /* We must postpone reading the file in case -progressive appears. */
+#else
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "smooth", 2)) {
+ /* Set input smoothing factor. */
+ int val;
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &val) != 1)
+ usage();
+ if (val < 0 || val > 100)
+ usage();
+ cinfo->smoothing_factor = val;
+
+ } else if (keymatch(arg, "targa", 1)) {
+ /* Input file is Targa format. */
+ is_targa = TRUE;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ /* Post-switch-scanning cleanup */
+
+ if (for_real) {
+
+ /* Set quantization tables for selected quality. */
+ /* Some or all may be overridden if -qtables is present. */
+ jpeg_set_quality(cinfo, quality, force_baseline);
+
+ if (qtablefile != NULL) /* process -qtables if it was present */
+ if (! read_quant_tables(cinfo, qtablefile,
+ q_scale_factor, force_baseline))
+ usage();
+
+ if (qslotsarg != NULL) /* process -qslots if it was present */
+ if (! set_quant_slots(cinfo, qslotsarg))
+ usage();
+
+ if (samplearg != NULL) /* process -sample if it was present */
+ if (! set_sample_factors(cinfo, samplearg))
+ usage();
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+ if (simple_progressive) /* process -progressive; -scans can override */
+ jpeg_simple_progression(cinfo);
+#endif
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (scansarg != NULL) /* process -scans if it was present */
+ if (! read_scan_script(cinfo, scansarg))
+ usage();
+#endif
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ int file_index;
+ cjpeg_source_ptr src_mgr;
+ FILE * input_file;
+ FILE * output_file;
+ JDIMENSION num_scanlines;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "cjpeg"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG compression object with default error handling. */
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_compress(&cinfo);
+ /* Add some application-specific error messages (from cderror.h) */
+ jerr.addon_message_table = cdjpeg_message_table;
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
+
+ /* Now safe to enable signal catcher. */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &cinfo);
+#endif
+
+ /* Initialize JPEG parameters.
+ * Much of this may be overridden later.
+ * In particular, we don't yet know the input file's color space,
+ * but we need to provide some value for jpeg_set_defaults() to work.
+ */
+
+ cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
+ jpeg_set_defaults(&cinfo);
+
+ /* Scan command line to find file names.
+ * It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are ignored; we will rescan the switches after opening
+ * the input file.
+ */
+
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &cinfo, &progress);
+#endif
+
+ /* Figure out the input file format, and set up to read it. */
+ src_mgr = select_file_type(&cinfo, input_file);
+ src_mgr->input_file = input_file;
+
+ /* Read the input file header to obtain file size & colorspace. */
+ (*src_mgr->start_input) (&cinfo, src_mgr);
+
+ /* Now that we know input colorspace, fix colorspace-dependent defaults */
+ jpeg_default_colorspace(&cinfo);
+
+ /* Adjust default compression parameters by re-parsing the options */
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
+
+ /* Specify data destination for compression */
+ jpeg_stdio_dest(&cinfo, output_file);
+
+ /* Start compressor */
+ jpeg_start_compress(&cinfo, TRUE);
+
+ /* Process data */
+ while (cinfo.next_scanline < cinfo.image_height) {
+ num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
+ (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
+ }
+
+ /* Finish compression and release memory */
+ (*src_mgr->finish_input) (&cinfo, src_mgr);
+ jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &cinfo);
+#endif
+
+ /* All done. */
+ exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/osframework/source/ImageLib/jpeg/ckconfig.c b/osframework/source/ImageLib/jpeg/ckconfig.c
new file mode 100644
index 0000000..58e9c17
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/ckconfig.c
@@ -0,0 +1,402 @@
+/*
+ * ckconfig.c
+ *
+ * Copyright (C) 1991-1994, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ */
+
+/*
+ * This program is intended to help you determine how to configure the JPEG
+ * software for installation on a particular system. The idea is to try to
+ * compile and execute this program. If your compiler fails to compile the
+ * program, make changes as indicated in the comments below. Once you can
+ * compile the program, run it, and it will produce a "jconfig.h" file for
+ * your system.
+ *
+ * As a general rule, each time you try to compile this program,
+ * pay attention only to the *first* error message you get from the compiler.
+ * Many C compilers will issue lots of spurious error messages once they
+ * have gotten confused. Go to the line indicated in the first error message,
+ * and read the comments preceding that line to see what to change.
+ *
+ * Almost all of the edits you may need to make to this program consist of
+ * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
+ * or vice versa. This is called defining or undefining that symbol.
+ */
+
+
+/* First we must see if your system has the include files we need.
+ * We start out with the assumption that your system has all the ANSI-standard
+ * include files. If you get any error trying to include one of these files,
+ * undefine the corresponding HAVE_xxx symbol.
+ */
+
+#define HAVE_STDDEF_H /* replace 'define' by 'undef' if error here */
+#ifdef HAVE_STDDEF_H /* next line will be skipped if you undef... */
+#include <stddef.h>
+#endif
+
+#define HAVE_STDLIB_H /* same thing for stdlib.h */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <stdio.h> /* If you ain't got this, you ain't got C. */
+
+/* We have to see if your string functions are defined by
+ * strings.h (old BSD convention) or string.h (everybody else).
+ * We try the non-BSD convention first; define NEED_BSD_STRINGS
+ * if the compiler says it can't find string.h.
+ */
+
+#undef NEED_BSD_STRINGS
+
+#ifdef NEED_BSD_STRINGS
+#include <strings.h>
+#else
+#include <string.h>
+#endif
+
+/* On some systems (especially older Unix machines), type size_t is
+ * defined only in the include file <sys/types.h>. If you get a failure
+ * on the size_t test below, try defining NEED_SYS_TYPES_H.
+ */
+
+#undef NEED_SYS_TYPES_H /* start by assuming we don't need it */
+#ifdef NEED_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+
+/* Usually type size_t is defined in one of the include files we've included
+ * above. If not, you'll get an error on the "typedef size_t my_size_t;" line.
+ * In that case, first try defining NEED_SYS_TYPES_H just above.
+ * If that doesn't work, you'll have to search through your system library
+ * to figure out which include file defines "size_t". Look for a line that
+ * says "typedef something-or-other size_t;". Then, change the line below
+ * that says "#include <someincludefile.h>" to instead include the file
+ * you found size_t in, and define NEED_SPECIAL_INCLUDE. If you can't find
+ * type size_t anywhere, try replacing "#include <someincludefile.h>" with
+ * "typedef unsigned int size_t;".
+ */
+
+#undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */
+
+#ifdef NEED_SPECIAL_INCLUDE
+#include <someincludefile.h>
+#endif
+
+typedef size_t my_size_t; /* The payoff: do we have size_t now? */
+
+
+/* The next question is whether your compiler supports ANSI-style function
+ * prototypes. You need to know this in order to choose between using
+ * makefile.ansi and using makefile.unix.
+ * The #define line below is set to assume you have ANSI function prototypes.
+ * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
+ */
+
+#define HAVE_PROTOTYPES
+
+#ifdef HAVE_PROTOTYPES
+int testfunction (int arg1, int * arg2); /* check prototypes */
+
+struct methods_struct { /* check method-pointer declarations */
+ int (*error_exit) (char *msgtext);
+ int (*trace_message) (char *msgtext);
+ int (*another_method) (void);
+};
+
+int testfunction (int arg1, int * arg2) /* check definitions */
+{
+ return arg2[arg1];
+}
+
+int test2function (void) /* check void arg list */
+{
+ return 0;
+}
+#endif
+
+
+/* Now we want to find out if your compiler knows what "unsigned char" means.
+ * If you get an error on the "unsigned char un_char;" line,
+ * then undefine HAVE_UNSIGNED_CHAR.
+ */
+
+#define HAVE_UNSIGNED_CHAR
+
+#ifdef HAVE_UNSIGNED_CHAR
+unsigned char un_char;
+#endif
+
+
+/* Now we want to find out if your compiler knows what "unsigned short" means.
+ * If you get an error on the "unsigned short un_short;" line,
+ * then undefine HAVE_UNSIGNED_SHORT.
+ */
+
+#define HAVE_UNSIGNED_SHORT
+
+#ifdef HAVE_UNSIGNED_SHORT
+unsigned short un_short;
+#endif
+
+
+/* Now we want to find out if your compiler understands type "void".
+ * If you get an error anywhere in here, undefine HAVE_VOID.
+ */
+
+#define HAVE_VOID
+
+#ifdef HAVE_VOID
+/* Caution: a C++ compiler will insist on complete prototypes */
+typedef void * void_ptr; /* check void * */
+#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
+typedef void (*void_func) (int a, int b);
+#else
+typedef void (*void_func) ();
+#endif
+
+#ifdef HAVE_PROTOTYPES /* check void function result */
+void test3function (void_ptr arg1, void_func arg2)
+#else
+void test3function (arg1, arg2)
+ void_ptr arg1;
+ void_func arg2;
+#endif
+{
+ char * locptr = (char *) arg1; /* check casting to and from void * */
+ arg1 = (void *) locptr;
+ (*arg2) (1, 2); /* check call of fcn returning void */
+}
+#endif
+
+
+/* Now we want to find out if your compiler knows what "const" means.
+ * If you get an error here, undefine HAVE_CONST.
+ */
+
+#define HAVE_CONST
+
+#ifdef HAVE_CONST
+static const int carray[3] = {1, 2, 3};
+
+#ifdef HAVE_PROTOTYPES
+int test4function (const int arg1)
+#else
+int test4function (arg1)
+ const int arg1;
+#endif
+{
+ return carray[arg1];
+}
+#endif
+
+
+/* If you get an error or warning about this structure definition,
+ * define INCOMPLETE_TYPES_BROKEN.
+ */
+
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifndef INCOMPLETE_TYPES_BROKEN
+typedef struct undefined_structure * undef_struct_ptr;
+#endif
+
+
+/* If you get an error about duplicate names,
+ * define NEED_SHORT_EXTERNAL_NAMES.
+ */
+
+#undef NEED_SHORT_EXTERNAL_NAMES
+
+#ifndef NEED_SHORT_EXTERNAL_NAMES
+
+int possibly_duplicate_function ()
+{
+ return 0;
+}
+
+int possibly_dupli_function ()
+{
+ return 1;
+}
+
+#endif
+
+
+
+/************************************************************************
+ * OK, that's it. You should not have to change anything beyond this
+ * point in order to compile and execute this program. (You might get
+ * some warnings, but you can ignore them.)
+ * When you run the program, it will make a couple more tests that it
+ * can do automatically, and then it will create jconfig.h and print out
+ * any additional suggestions it has.
+ ************************************************************************
+ */
+
+
+#ifdef HAVE_PROTOTYPES
+int is_char_signed (int arg)
+#else
+int is_char_signed (arg)
+ int arg;
+#endif
+{
+ if (arg == 189) { /* expected result for unsigned char */
+ return 0; /* type char is unsigned */
+ }
+ else if (arg != -67) { /* expected result for signed char */
+ printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
+ printf("I fear the JPEG software will not work at all.\n\n");
+ }
+ return 1; /* assume char is signed otherwise */
+}
+
+
+#ifdef HAVE_PROTOTYPES
+int is_shifting_signed (long arg)
+#else
+int is_shifting_signed (arg)
+ long arg;
+#endif
+/* See whether right-shift on a long is signed or not. */
+{
+ long res = arg >> 4;
+
+ if (res == -0x7F7E80CL) { /* expected result for signed shift */
+ return 1; /* right shift is signed */
+ }
+ /* see if unsigned-shift hack will fix it. */
+ /* we can't just test exact value since it depends on width of long... */
+ res |= (~0L) << (32-4);
+ if (res == -0x7F7E80CL) { /* expected result now? */
+ return 0; /* right shift is unsigned */
+ }
+ printf("Right shift isn't acting as I expect it to.\n");
+ printf("I fear the JPEG software will not work at all.\n\n");
+ return 0; /* try it with unsigned anyway */
+}
+
+
+#ifdef HAVE_PROTOTYPES
+int main (int argc, char ** argv)
+#else
+int main (argc, argv)
+ int argc;
+ char ** argv;
+#endif
+{
+ char signed_char_check = (char) (-67);
+ FILE *outfile;
+
+ /* Attempt to write jconfig.h */
+ if ((outfile = fopen("jconfig.h", "w")) == NULL) {
+ printf("Failed to write jconfig.h\n");
+ return 1;
+ }
+
+ /* Write out all the info */
+ fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
+ fprintf(outfile, "/* see jconfig.doc for explanations */\n\n");
+#ifdef HAVE_PROTOTYPES
+ fprintf(outfile, "#define HAVE_PROTOTYPES\n");
+#else
+ fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
+#endif
+#ifdef HAVE_UNSIGNED_CHAR
+ fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
+#else
+ fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
+#endif
+#ifdef HAVE_UNSIGNED_SHORT
+ fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
+#else
+ fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
+#endif
+#ifdef HAVE_VOID
+ fprintf(outfile, "/* #define void char */\n");
+#else
+ fprintf(outfile, "#define void char\n");
+#endif
+#ifdef HAVE_CONST
+ fprintf(outfile, "/* #define const */\n");
+#else
+ fprintf(outfile, "#define const\n");
+#endif
+ if (is_char_signed((int) signed_char_check))
+ fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
+ else
+ fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
+#ifdef HAVE_STDDEF_H
+ fprintf(outfile, "#define HAVE_STDDEF_H\n");
+#else
+ fprintf(outfile, "#undef HAVE_STDDEF_H\n");
+#endif
+#ifdef HAVE_STDLIB_H
+ fprintf(outfile, "#define HAVE_STDLIB_H\n");
+#else
+ fprintf(outfile, "#undef HAVE_STDLIB_H\n");
+#endif
+#ifdef NEED_BSD_STRINGS
+ fprintf(outfile, "#define NEED_BSD_STRINGS\n");
+#else
+ fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
+#endif
+#ifdef NEED_SYS_TYPES_H
+ fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
+#else
+ fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
+#endif
+ fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+ fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
+#else
+ fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
+#endif
+#ifdef INCOMPLETE_TYPES_BROKEN
+ fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
+#else
+ fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
+#endif
+ fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
+ if (is_shifting_signed(-0x7F7E80B1L))
+ fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
+ else
+ fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
+ fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
+ fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
+ fprintf(outfile, "#define BMP_SUPPORTED /* BMP image file format */\n");
+ fprintf(outfile, "#define GIF_SUPPORTED /* GIF image file format */\n");
+ fprintf(outfile, "#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */\n");
+ fprintf(outfile, "#undef RLE_SUPPORTED /* Utah RLE image file format */\n");
+ fprintf(outfile, "#define TARGA_SUPPORTED /* Targa image file format */\n\n");
+ fprintf(outfile, "#undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */\n");
+ fprintf(outfile, "#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */\n");
+ fprintf(outfile, "#undef DONT_USE_B_MODE\n");
+ fprintf(outfile, "/* #define PROGRESS_REPORT */ /* optional */\n");
+ fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
+
+ /* Close the jconfig.h file */
+ fclose(outfile);
+
+ /* User report */
+ printf("Configuration check for Independent JPEG Group's software done.\n");
+ printf("\nI have written the jconfig.h file for you.\n\n");
+#ifdef HAVE_PROTOTYPES
+ printf("You should use makefile.ansi as the starting point for your Makefile.\n");
+#else
+ printf("You should use makefile.unix as the starting point for your Makefile.\n");
+#endif
+
+#ifdef NEED_SPECIAL_INCLUDE
+ printf("\nYou'll need to change jconfig.h to include the system include file\n");
+ printf("that you found type size_t in, or add a direct definition of type\n");
+ printf("size_t if that's what you used. Just add it to the end.\n");
+#endif
+
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg/coderules.doc b/osframework/source/ImageLib/jpeg/coderules.doc
new file mode 100644
index 0000000..2c56534
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/coderules.doc
@@ -0,0 +1,118 @@
+IJG JPEG LIBRARY: CODING RULES
+
+Copyright (C) 1991-1996, Thomas G. Lane.
+This file is part of the Independent JPEG Group's software.
+For conditions of distribution and use, see the accompanying README file.
+
+
+Since numerous people will be contributing code and bug fixes, it's important
+to establish a common coding style. The goal of using similar coding styles
+is much more important than the details of just what that style is.
+
+In general we follow the recommendations of "Recommended C Style and Coding
+Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
+Brader). This document is available in the IJG FTP archive (see
+jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
+
+Block comments should be laid out thusly:
+
+/*
+ * Block comments in this style.
+ */
+
+We indent statements in K&R style, e.g.,
+ if (test) {
+ then-part;
+ } else {
+ else-part;
+ }
+with two spaces per indentation level. (This indentation convention is
+handled automatically by GNU Emacs and many other text editors.)
+
+Multi-word names should be written in lower case with underscores, e.g.,
+multi_word_name (not multiWordName). Preprocessor symbols and enum constants
+are similar but upper case (MULTI_WORD_NAME). Names should be unique within
+the first fifteen characters. (On some older systems, global names must be
+unique within six characters. We accommodate this without cluttering the
+source code by using macros to substitute shorter names.)
+
+We use function prototypes everywhere; we rely on automatic source code
+transformation to feed prototype-less C compilers. Transformation is done
+by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).
+ansi2knr is not very bright, so it imposes a format requirement on function
+declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
+should be written in the following style:
+
+LOCAL(int *)
+function_name (int a, char *b)
+{
+ code...
+}
+
+Note that each function definition must begin with GLOBAL(type), LOCAL(type),
+or METHODDEF(type). These macros expand to "static type" or just "type" as
+appropriate. They provide a readable indication of the routine's usage and
+can readily be changed for special needs. (For instance, special linkage
+keywords can be inserted for use in Windows DLLs.)
+
+ansi2knr does not transform method declarations (function pointers in
+structs). We handle these with a macro JMETHOD, defined as
+ #ifdef HAVE_PROTOTYPES
+ #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
+ #else
+ #define JMETHOD(type,methodname,arglist) type (*methodname) ()
+ #endif
+which is used like this:
+ struct function_pointers {
+ JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
+ JMETHOD(void, term_entropy_encoder, (void));
+ };
+Note the set of parentheses surrounding the parameter list.
+
+A similar solution is used for forward and external function declarations
+(see the EXTERN and JPP macros).
+
+If the code is to work on non-ANSI compilers, we cannot rely on a prototype
+declaration to coerce actual parameters into the right types. Therefore, use
+explicit casts on actual parameters whenever the actual parameter type is not
+identical to the formal parameter. Beware of implicit conversions to "int".
+
+It seems there are some non-ANSI compilers in which the sizeof() operator
+is defined to return int, yet size_t is defined as long. Needless to say,
+this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(),
+so that the result is guaranteed to be of type size_t.
+
+
+The JPEG library is intended to be used within larger programs. Furthermore,
+we want it to be reentrant so that it can be used by applications that process
+multiple images concurrently. The following rules support these requirements:
+
+1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
+pass these through the common routines provided.
+
+2. Minimize global namespace pollution. Functions should be declared static
+wherever possible. (Note that our method-based calling conventions help this
+a lot: in many modules only the initialization function will ever need to be
+called directly, so only that function need be externally visible.) All
+global function names should begin with "jpeg_", and should have an
+abbreviated name (unique in the first six characters) substituted by macro
+when NEED_SHORT_EXTERNAL_NAMES is set.
+
+3. Don't use global variables; anything that must be used in another module
+should be in the common data structures.
+
+4. Don't use static variables except for read-only constant tables. Variables
+that should be private to a module can be placed into private structures (see
+the system architecture document, structure.doc).
+
+5. Source file names should begin with "j" for files that are part of the
+library proper; source files that are not part of the library, such as cjpeg.c
+and djpeg.c, do not begin with "j". Keep source file names to eight
+characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep
+compression and decompression code in separate source files --- some
+applications may want only one half of the library.
+
+Note: these rules (particularly #4) are not followed religiously in the
+modules that are used in cjpeg/djpeg but are not part of the JPEG library
+proper. Those modules are not really intended to be used in other
+applications.
diff --git a/osframework/source/ImageLib/jpeg/config.guess b/osframework/source/ImageLib/jpeg/config.guess
new file mode 100644
index 0000000..f60829f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/config.guess
@@ -0,0 +1,883 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+# Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Written by Per Bothner <bothner@cygnus.com>.
+# The master version of this file is at the FSF in /home/gd/gnu/lib.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub. If it succeeds, it prints the system name on stdout, and
+# exits with 0. Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit system type (host/target name).
+#
+# Only a few systems have been added to this list; please add others
+# (but try to keep the structure clean).
+#
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 8/24/94.)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+ PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+ alpha:OSF1:*:*)
+ if test $UNAME_RELEASE = "V4.0"; then
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+ fi
+ # A Vn.n version is a released version.
+ # A Tn.n version is a released field test version.
+ # A Xn.n version is an unreleased experimental baselevel.
+ # 1.2 uses "1.2" for uname -r.
+ cat <<EOF >dummy.s
+ .globl main
+ .ent main
+main:
+ .frame \$30,0,\$26,0
+ .prologue 0
+ .long 0x47e03d80 # implver $0
+ lda \$2,259
+ .long 0x47e20c21 # amask $2,$1
+ srl \$1,8,\$2
+ sll \$2,2,\$2
+ sll \$0,3,\$0
+ addl \$1,\$0,\$0
+ addl \$2,\$0,\$0
+ ret \$31,(\$26),1
+ .end main
+EOF
+ ${CC-cc} dummy.s -o dummy 2>/dev/null
+ if test "$?" = 0 ; then
+ ./dummy
+ case "$?" in
+ 7)
+ UNAME_MACHINE="alpha"
+ ;;
+ 15)
+ UNAME_MACHINE="alphaev5"
+ ;;
+ 14)
+ UNAME_MACHINE="alphaev56"
+ ;;
+ 10)
+ UNAME_MACHINE="alphapca56"
+ ;;
+ 16)
+ UNAME_MACHINE="alphaev6"
+ ;;
+ esac
+ fi
+ rm -f dummy.s dummy
+ echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr [[A-Z]] [[a-z]]`
+ exit 0 ;;
+ 21064:Windows_NT:50:3)
+ echo alpha-dec-winnt3.5
+ exit 0 ;;
+ Amiga*:UNIX_System_V:4.0:*)
+ echo m68k-cbm-sysv4
+ exit 0;;
+ amiga:NetBSD:*:*)
+ echo m68k-cbm-netbsd${UNAME_RELEASE}
+ exit 0 ;;
+ amiga:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ arc64:OpenBSD:*:*)
+ echo mips64el-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ arc:OpenBSD:*:*)
+ echo mipsel-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ hkmips:OpenBSD:*:*)
+ echo mips-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ pmax:OpenBSD:*:*)
+ echo mipsel-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ sgi:OpenBSD:*:*)
+ echo mips-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ wgrisc:OpenBSD:*:*)
+ echo mipsel-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+ echo arm-acorn-riscix${UNAME_RELEASE}
+ exit 0;;
+ arm32:NetBSD:*:*)
+ echo arm-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ exit 0 ;;
+ SR2?01:HI-UX/MPP:*:*)
+ echo hppa1.1-hitachi-hiuxmpp
+ exit 0;;
+ Pyramid*:OSx*:*:*|MIS*:OSx*:*:*)
+ # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+ if test "`(/bin/universe) 2>/dev/null`" = att ; then
+ echo pyramid-pyramid-sysv3
+ else
+ echo pyramid-pyramid-bsd
+ fi
+ exit 0 ;;
+ NILE:*:*:dcosx)
+ echo pyramid-pyramid-svr4
+ exit 0 ;;
+ sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+ echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit 0 ;;
+ i86pc:SunOS:5.*:*)
+ echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit 0 ;;
+ sun4*:SunOS:6*:*)
+ # According to config.sub, this is the proper way to canonicalize
+ # SunOS6. Hard to guess exactly what SunOS6 will be like, but
+ # it's likely to be more like Solaris than SunOS4.
+ echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit 0 ;;
+ sun4*:SunOS:*:*)
+ case "`/usr/bin/arch -k`" in
+ Series*|S4*)
+ UNAME_RELEASE=`uname -v`
+ ;;
+ esac
+ # Japanese Language versions have a version number like `4.1.3-JL'.
+ echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+ exit 0 ;;
+ sun3*:SunOS:*:*)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ exit 0 ;;
+ sun*:*:4.2BSD:*)
+ UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+ test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+ case "`/bin/arch`" in
+ sun3)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ ;;
+ sun4)
+ echo sparc-sun-sunos${UNAME_RELEASE}
+ ;;
+ esac
+ exit 0 ;;
+ aushp:SunOS:*:*)
+ echo sparc-auspex-sunos${UNAME_RELEASE}
+ exit 0 ;;
+ atari*:NetBSD:*:*)
+ echo m68k-atari-netbsd${UNAME_RELEASE}
+ exit 0 ;;
+ atari*:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ sun3*:NetBSD:*:*)
+ echo m68k-sun-netbsd${UNAME_RELEASE}
+ exit 0 ;;
+ sun3*:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ mac68k:NetBSD:*:*)
+ echo m68k-apple-netbsd${UNAME_RELEASE}
+ exit 0 ;;
+ mac68k:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ mvme68k:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ mvme88k:OpenBSD:*:*)
+ echo m88k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ powerpc:machten:*:*)
+ echo powerpc-apple-machten${UNAME_RELEASE}
+ exit 0 ;;
+ RISC*:Mach:*:*)
+ echo mips-dec-mach_bsd4.3
+ exit 0 ;;
+ RISC*:ULTRIX:*:*)
+ echo mips-dec-ultrix${UNAME_RELEASE}
+ exit 0 ;;
+ VAX*:ULTRIX*:*:*)
+ echo vax-dec-ultrix${UNAME_RELEASE}
+ exit 0 ;;
+ 2020:CLIX:*:*)
+ echo clipper-intergraph-clix${UNAME_RELEASE}
+ exit 0 ;;
+ mips:*:*:UMIPS | mips:*:*:RISCos)
+ sed 's/^ //' << EOF >dummy.c
+ int main (argc, argv) int argc; char **argv; {
+ #if defined (host_mips) && defined (MIPSEB)
+ #if defined (SYSTYPE_SYSV)
+ printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_SVR4)
+ printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+ printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+ #endif
+ #endif
+ exit (-1);
+ }
+EOF
+ ${CC-cc} dummy.c -o dummy \
+ && ./dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
+ && rm dummy.c dummy && exit 0
+ rm -f dummy.c dummy
+ echo mips-mips-riscos${UNAME_RELEASE}
+ exit 0 ;;
+ Night_Hawk:Power_UNIX:*:*)
+ echo powerpc-harris-powerunix
+ exit 0 ;;
+ m88k:CX/UX:7*:*)
+ echo m88k-harris-cxux7
+ exit 0 ;;
+ m88k:*:4*:R4*)
+ echo m88k-motorola-sysv4
+ exit 0 ;;
+ m88k:*:3*:R3*)
+ echo m88k-motorola-sysv3
+ exit 0 ;;
+ AViiON:dgux:*:*)
+ # DG/UX returns AViiON for all architectures
+ UNAME_PROCESSOR=`/usr/bin/uname -p`
+ if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then
+ if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
+ -o ${TARGET_BINARY_INTERFACE}x = x ] ; then
+ echo m88k-dg-dgux${UNAME_RELEASE}
+ else
+ echo m88k-dg-dguxbcs${UNAME_RELEASE}
+ fi
+ else echo i586-dg-dgux${UNAME_RELEASE}
+ fi
+ exit 0 ;;
+ M88*:DolphinOS:*:*) # DolphinOS (SVR3)
+ echo m88k-dolphin-sysv3
+ exit 0 ;;
+ M88*:*:R3*:*)
+ # Delta 88k system running SVR3
+ echo m88k-motorola-sysv3
+ exit 0 ;;
+ XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+ echo m88k-tektronix-sysv3
+ exit 0 ;;
+ Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+ echo m68k-tektronix-bsd
+ exit 0 ;;
+ *:IRIX*:*:*)
+ echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+ exit 0 ;;
+ ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+ echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
+ exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
+ i?86:AIX:*:*)
+ echo i386-ibm-aix
+ exit 0 ;;
+ *:AIX:2:3)
+ if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+ sed 's/^ //' << EOF >dummy.c
+ #include <sys/systemcfg.h>
+
+ main()
+ {
+ if (!__power_pc())
+ exit(1);
+ puts("powerpc-ibm-aix3.2.5");
+ exit(0);
+ }
+EOF
+ ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
+ rm -f dummy.c dummy
+ echo rs6000-ibm-aix3.2.5
+ elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+ echo rs6000-ibm-aix3.2.4
+ else
+ echo rs6000-ibm-aix3.2
+ fi
+ exit 0 ;;
+ *:AIX:*:4)
+ if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then
+ IBM_ARCH=rs6000
+ else
+ IBM_ARCH=powerpc
+ fi
+ if [ -x /usr/bin/oslevel ] ; then
+ IBM_REV=`/usr/bin/oslevel`
+ else
+ IBM_REV=4.${UNAME_RELEASE}
+ fi
+ echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+ exit 0 ;;
+ *:AIX:*:*)
+ echo rs6000-ibm-aix
+ exit 0 ;;
+ ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+ echo romp-ibm-bsd4.4
+ exit 0 ;;
+ ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
+ echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
+ exit 0 ;; # report: romp-ibm BSD 4.3
+ *:BOSX:*:*)
+ echo rs6000-bull-bosx
+ exit 0 ;;
+ DPX/2?00:B.O.S.:*:*)
+ echo m68k-bull-sysv3
+ exit 0 ;;
+ 9000/[34]??:4.3bsd:1.*:*)
+ echo m68k-hp-bsd
+ exit 0 ;;
+ hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+ echo m68k-hp-bsd4.4
+ exit 0 ;;
+ 9000/[3478]??:HP-UX:*:*)
+ case "${UNAME_MACHINE}" in
+ 9000/31? ) HP_ARCH=m68000 ;;
+ 9000/[34]?? ) HP_ARCH=m68k ;;
+ 9000/7?? | 9000/8?[1679] ) HP_ARCH=hppa1.1 ;;
+ 9000/8?? ) HP_ARCH=hppa1.0 ;;
+ esac
+ HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+ echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+ exit 0 ;;
+ 3050*:HI-UX:*:*)
+ sed 's/^ //' << EOF >dummy.c
+ #include <unistd.h>
+ int
+ main ()
+ {
+ long cpu = sysconf (_SC_CPU_VERSION);
+ /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+ true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
+ results, however. */
+ if (CPU_IS_PA_RISC (cpu))
+ {
+ switch (cpu)
+ {
+ case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+ default: puts ("hppa-hitachi-hiuxwe2"); break;
+ }
+ }
+ else if (CPU_IS_HP_MC68K (cpu))
+ puts ("m68k-hitachi-hiuxwe2");
+ else puts ("unknown-hitachi-hiuxwe2");
+ exit (0);
+ }
+EOF
+ ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
+ rm -f dummy.c dummy
+ echo unknown-hitachi-hiuxwe2
+ exit 0 ;;
+ 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+ echo hppa1.1-hp-bsd
+ exit 0 ;;
+ 9000/8??:4.3bsd:*:*)
+ echo hppa1.0-hp-bsd
+ exit 0 ;;
+ hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+ echo hppa1.1-hp-osf
+ exit 0 ;;
+ hp8??:OSF1:*:*)
+ echo hppa1.0-hp-osf
+ exit 0 ;;
+ i?86:OSF1:*:*)
+ if [ -x /usr/sbin/sysversion ] ; then
+ echo ${UNAME_MACHINE}-unknown-osf1mk
+ else
+ echo ${UNAME_MACHINE}-unknown-osf1
+ fi
+ exit 0 ;;
+ parisc*:Lites*:*:*)
+ echo hppa1.1-hp-lites
+ exit 0 ;;
+ C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+ echo c1-convex-bsd
+ exit 0 ;;
+ C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+ if getsysinfo -f scalar_acc
+ then echo c32-convex-bsd
+ else echo c2-convex-bsd
+ fi
+ exit 0 ;;
+ C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+ echo c34-convex-bsd
+ exit 0 ;;
+ C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+ echo c38-convex-bsd
+ exit 0 ;;
+ C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+ echo c4-convex-bsd
+ exit 0 ;;
+ CRAY*X-MP:*:*:*)
+ echo xmp-cray-unicos
+ exit 0 ;;
+ CRAY*Y-MP:*:*:*)
+ echo ymp-cray-unicos${UNAME_RELEASE}
+ exit 0 ;;
+ CRAY*[A-Z]90:*:*:*)
+ echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
+ exit 0 ;;
+ CRAY*TS:*:*:*)
+ echo t90-cray-unicos${UNAME_RELEASE}
+ exit 0 ;;
+ CRAY-2:*:*:*)
+ echo cray2-cray-unicos
+ exit 0 ;;
+ F300:UNIX_System_V:*:*)
+ FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+ echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit 0 ;;
+ F301:UNIX_System_V:*:*)
+ echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'`
+ exit 0 ;;
+ hp3[0-9][05]:NetBSD:*:*)
+ echo m68k-hp-netbsd${UNAME_RELEASE}
+ exit 0 ;;
+ hp300:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit 0 ;;
+ i?86:BSD/386:*:* | *:BSD/OS:*:*)
+ echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+ exit 0 ;;
+ *:FreeBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+ exit 0 ;;
+ *:NetBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ exit 0 ;;
+ *:OpenBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ exit 0 ;;
+ i*:CYGWIN*:*)
+ echo i386-pc-cygwin32
+ exit 0 ;;
+ i*:MINGW*:*)
+ echo i386-pc-mingw32
+ exit 0 ;;
+ p*:CYGWIN*:*)
+ echo powerpcle-unknown-cygwin32
+ exit 0 ;;
+ prep*:SunOS:5.*:*)
+ echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit 0 ;;
+ *:GNU:*:*)
+ echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+ exit 0 ;;
+ *:Linux:*:*)
+ # The BFD linker knows what the default object file format is, so
+ # first see if it will tell us.
+ ld_help_string=`ld --help 2>&1`
+ ld_supported_emulations=`echo $ld_help_string \
+ | sed -ne '/supported emulations:/!d
+ s/[ ][ ]*/ /g
+ s/.*supported emulations: *//
+ s/ .*//
+ p'`
+ case "$ld_supported_emulations" in
+ i?86linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ;;
+ i?86coff) echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ;;
+ sparclinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
+ m68klinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
+ elf32ppc) echo "powerpc-unknown-linux-gnu" ; exit 0 ;;
+ esac
+
+ if test "${UNAME_MACHINE}" = "alpha" ; then
+ sed 's/^ //' <<EOF >dummy.s
+ .globl main
+ .ent main
+ main:
+ .frame \$30,0,\$26,0
+ .prologue 0
+ .long 0x47e03d80 # implver $0
+ lda \$2,259
+ .long 0x47e20c21 # amask $2,$1
+ srl \$1,8,\$2
+ sll \$2,2,\$2
+ sll \$0,3,\$0
+ addl \$1,\$0,\$0
+ addl \$2,\$0,\$0
+ ret \$31,(\$26),1
+ .end main
+EOF
+ LIBC=""
+ ${CC-cc} dummy.s -o dummy 2>/dev/null
+ if test "$?" = 0 ; then
+ ./dummy
+ case "$?" in
+ 7)
+ UNAME_MACHINE="alpha"
+ ;;
+ 15)
+ UNAME_MACHINE="alphaev5"
+ ;;
+ 14)
+ UNAME_MACHINE="alphaev56"
+ ;;
+ 10)
+ UNAME_MACHINE="alphapca56"
+ ;;
+ 16)
+ UNAME_MACHINE="alphaev6"
+ ;;
+ esac
+
+ objdump --private-headers dummy | \
+ grep ld.so.1 > /dev/null
+ if test "$?" = 0 ; then
+ LIBC="libc1"
+ fi
+ fi
+ rm -f dummy.s dummy
+ echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0
+ elif test "${UNAME_MACHINE}" = "mips" ; then
+ cat >dummy.c <<EOF
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+#ifdef __MIPSEB__
+ printf ("%s-unknown-linux-gnu\n", argv[1]);
+#endif
+#ifdef __MIPSEL__
+ printf ("%sel-unknown-linux-gnu\n", argv[1]);
+#endif
+ return 0;
+}
+EOF
+ ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
+ rm -f dummy.c dummy
+ else
+ # Either a pre-BFD a.out linker (linux-gnuoldld)
+ # or one that does not give us useful --help.
+ # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout.
+ # If ld does not provide *any* "supported emulations:"
+ # that means it is gnuoldld.
+ echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations:"
+ test $? != 0 && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0
+
+ case "${UNAME_MACHINE}" in
+ i?86)
+ VENDOR=pc;
+ ;;
+ *)
+ VENDOR=unknown;
+ ;;
+ esac
+ # Determine whether the default compiler is a.out or elf
+ cat >dummy.c <<EOF
+#include <features.h>
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+#ifdef __ELF__
+# ifdef __GLIBC__
+# if __GLIBC__ >= 2
+ printf ("%s-${VENDOR}-linux-gnu\n", argv[1]);
+# else
+ printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+# endif
+# else
+ printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+# endif
+#else
+ printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]);
+#endif
+ return 0;
+}
+EOF
+ ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
+ rm -f dummy.c dummy
+ fi ;;
+# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
+# are messed up and put the nodename in both sysname and nodename.
+ i?86:DYNIX/ptx:4*:*)
+ echo i386-sequent-sysv4
+ exit 0 ;;
+ i?86:UNIX_SV:4.2MP:2.*)
+ # Unixware is an offshoot of SVR4, but it has its own version
+ # number series starting with 2...
+ # I am not positive that other SVR4 systems won't match this,
+ # I just have to hope. -- rms.
+ # Use sysv4.2uw... so that sysv4* matches it.
+ echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+ exit 0 ;;
+ i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*)
+ if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+ echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
+ else
+ echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE}
+ fi
+ exit 0 ;;
+ i?86:*:3.2:*)
+ if test -f /usr/options/cb.name; then
+ UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+ echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+ elif /bin/uname -X 2>/dev/null >/dev/null ; then
+ UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
+ (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
+ (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
+ && UNAME_MACHINE=i586
+ echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+ else
+ echo ${UNAME_MACHINE}-pc-sysv32
+ fi
+ exit 0 ;;
+ pc:*:*:*)
+ # uname -m prints for DJGPP always 'pc', but it prints nothing about
+ # the processor, so we play safe by assuming i386.
+ echo i386-pc-msdosdjgpp
+ exit 0 ;;
+ Intel:Mach:3*:*)
+ echo i386-pc-mach3
+ exit 0 ;;
+ paragon:*:*:*)
+ echo i860-intel-osf1
+ exit 0 ;;
+ i860:*:4.*:*) # i860-SVR4
+ if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+ echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+ else # Add other i860-SVR4 vendors below as they are discovered.
+ echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
+ fi
+ exit 0 ;;
+ mini*:CTIX:SYS*5:*)
+ # "miniframe"
+ echo m68010-convergent-sysv
+ exit 0 ;;
+ M68*:*:R3V[567]*:*)
+ test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+ 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
+ OS_REL=''
+ test -r /etc/.relid \
+ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+ && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+ 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && echo i486-ncr-sysv4 && exit 0 ;;
+ m68*:LynxOS:2.*:*)
+ echo m68k-unknown-lynxos${UNAME_RELEASE}
+ exit 0 ;;
+ mc68030:UNIX_System_V:4.*:*)
+ echo m68k-atari-sysv4
+ exit 0 ;;
+ i?86:LynxOS:2.*:*)
+ echo i386-unknown-lynxos${UNAME_RELEASE}
+ exit 0 ;;
+ TSUNAMI:LynxOS:2.*:*)
+ echo sparc-unknown-lynxos${UNAME_RELEASE}
+ exit 0 ;;
+ rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*)
+ echo rs6000-unknown-lynxos${UNAME_RELEASE}
+ exit 0 ;;
+ SM[BE]S:UNIX_SV:*:*)
+ echo mips-dde-sysv${UNAME_RELEASE}
+ exit 0 ;;
+ RM*:SINIX-*:*:*)
+ echo mips-sni-sysv4
+ exit 0 ;;
+ *:SINIX-*:*:*)
+ if uname -p 2>/dev/null >/dev/null ; then
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
+ echo ${UNAME_MACHINE}-sni-sysv4
+ else
+ echo ns32k-sni-sysv
+ fi
+ exit 0 ;;
+ PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+ # says <Richard.M.Bartel@ccMail.Census.GOV>
+ echo i586-unisys-sysv4
+ exit 0 ;;
+ *:UNIX_System_V:4*:FTX*)
+ # From Gerald Hewes <hewes@openmarket.com>.
+ # How about differentiating between stratus architectures? -djm
+ echo hppa1.1-stratus-sysv4
+ exit 0 ;;
+ *:*:*:FTX*)
+ # From seanf@swdc.stratus.com.
+ echo i860-stratus-sysv4
+ exit 0 ;;
+ mc68*:A/UX:*:*)
+ echo m68k-apple-aux${UNAME_RELEASE}
+ exit 0 ;;
+ news*:NEWS-OS:*:6*)
+ echo mips-sony-newsos6
+ exit 0 ;;
+ R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:*)
+ if [ -d /usr/nec ]; then
+ echo mips-nec-sysv${UNAME_RELEASE}
+ else
+ echo mips-unknown-sysv${UNAME_RELEASE}
+ fi
+ exit 0 ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+cat >dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+ /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
+ I don't know.... */
+ printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+ printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+ "4"
+#else
+ ""
+#endif
+ ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+ printf ("arm-acorn-riscix"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+ printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+ int version;
+ version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+ printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+ exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+ printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+ printf ("ns32k-encore-mach\n"); exit (0);
+#else
+ printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+ printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+ printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+ printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+ struct utsname un;
+
+ uname(&un);
+
+ if (strncmp(un.version, "V2", 2) == 0) {
+ printf ("i386-sequent-ptx2\n"); exit (0);
+ }
+ if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+ printf ("i386-sequent-ptx1\n"); exit (0);
+ }
+ printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+#if !defined (ultrix)
+ printf ("vax-dec-bsd\n"); exit (0);
+#else
+ printf ("vax-dec-ultrix\n"); exit (0);
+#endif
+#endif
+
+#if defined (alliant) && defined (i860)
+ printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+ exit (1);
+}
+EOF
+
+${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
+rm -f dummy.c dummy
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+ case `getsysinfo -f cpu_type` in
+ c1*)
+ echo c1-convex-bsd
+ exit 0 ;;
+ c2*)
+ if getsysinfo -f scalar_acc
+ then echo c32-convex-bsd
+ else echo c2-convex-bsd
+ fi
+ exit 0 ;;
+ c34*)
+ echo c34-convex-bsd
+ exit 0 ;;
+ c38*)
+ echo c38-convex-bsd
+ exit 0 ;;
+ c4*)
+ echo c4-convex-bsd
+ exit 0 ;;
+ esac
+fi
+
+#echo '(Unable to guess system type)' 1>&2
+
+exit 1
diff --git a/osframework/source/ImageLib/jpeg/config.sub b/osframework/source/ImageLib/jpeg/config.sub
new file mode 100644
index 0000000..fe5c364
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/config.sub
@@ -0,0 +1,954 @@
+#! /bin/sh
+# Configuration validation subroutine script, version 1.1.
+# Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine. It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support. The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+if [ x$1 = x ]
+then
+ echo Configuration name missing. 1>&2
+ echo "Usage: $0 CPU-MFR-OPSYS" 1>&2
+ echo "or $0 ALIAS" 1>&2
+ echo where ALIAS is a recognized configuration type. 1>&2
+ exit 1
+fi
+
+# First pass through any local machine types.
+case $1 in
+ *local*)
+ echo $1
+ exit 0
+ ;;
+ *)
+ ;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+ linux-gnu*)
+ os=-$maybe_os
+ basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+ ;;
+ *)
+ basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+ if [ $basic_machine != $1 ]
+ then os=`echo $1 | sed 's/.*-/-/'`
+ else os=; fi
+ ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work. We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+ -sun*os*)
+ # Prevent following clause from handling this invalid input.
+ ;;
+ -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+ -apple)
+ os=
+ basic_machine=$1
+ ;;
+ -hiux*)
+ os=-hiuxwe2
+ ;;
+ -sco5)
+ os=sco3.2v5
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco4)
+ os=-sco3.2v4
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2.[4-9]*)
+ os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2v[4-9]*)
+ # Don't forget version if it is 3.2v4 or newer.
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco*)
+ os=-sco3.2v2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -isc)
+ os=-isc2.2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -clix*)
+ basic_machine=clipper-intergraph
+ ;;
+ -isc*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -lynx*)
+ os=-lynxos
+ ;;
+ -ptx*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+ ;;
+ -windowsnt*)
+ os=`echo $os | sed -e 's/windowsnt/winnt/'`
+ ;;
+ -psos*)
+ os=-psos
+ ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+ # Recognize the basic CPU types without company name.
+ # Some are omitted here because they have special meanings below.
+ tahoe | i860 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \
+ | arme[lb] | pyramid | mn10200 | mn10300 \
+ | tron | a29k | 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 \
+ | alpha | alphaev5 | alphaev56 | we32k | ns16k | clipper \
+ | i370 | sh | powerpc | powerpcle | 1750a | dsp16xx | pdp11 \
+ | mips64 | mipsel | mips64el | mips64orion | mips64orionel \
+ | mipstx39 | mipstx39el \
+ | sparc | sparclet | sparclite | sparc64 | v850)
+ basic_machine=$basic_machine-unknown
+ ;;
+ # We use `pc' rather than `unknown'
+ # because (1) that's what they normally are, and
+ # (2) the word "unknown" tends to confuse beginning users.
+ i[3456]86)
+ basic_machine=$basic_machine-pc
+ ;;
+ # Object if more than one company name word.
+ *-*-*)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+ # Recognize the basic CPU types with company name.
+ vax-* | tahoe-* | i[3456]86-* | i860-* | m32r-* | m68k-* | m68000-* \
+ | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \
+ | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \
+ | power-* | none-* | 580-* | cray2-* | h8300-* | i960-* \
+ | xmp-* | ymp-* | hppa-* | hppa1.0-* | hppa1.1-* \
+ | alpha-* | alphaev5-* | alphaev56-* | we32k-* | cydra-* \
+ | ns16k-* | pn-* | np1-* | xps100-* | clipper-* | orion-* \
+ | sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \
+ | sparc64-* | mips64-* | mipsel-* \
+ | mips64el-* | mips64orion-* | mips64orionel-* \
+ | mipstx39-* | mipstx39el-* \
+ | f301-*)
+ ;;
+ # Recognize the various machine names and aliases which stand
+ # for a CPU type and a company and sometimes even an OS.
+ 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+ basic_machine=m68000-att
+ ;;
+ 3b*)
+ basic_machine=we32k-att
+ ;;
+ alliant | fx80)
+ basic_machine=fx80-alliant
+ ;;
+ altos | altos3068)
+ basic_machine=m68k-altos
+ ;;
+ am29k)
+ basic_machine=a29k-none
+ os=-bsd
+ ;;
+ amdahl)
+ basic_machine=580-amdahl
+ os=-sysv
+ ;;
+ amiga | amiga-*)
+ basic_machine=m68k-cbm
+ ;;
+ amigaos | amigados)
+ basic_machine=m68k-cbm
+ os=-amigaos
+ ;;
+ amigaunix | amix)
+ basic_machine=m68k-cbm
+ os=-sysv4
+ ;;
+ apollo68)
+ basic_machine=m68k-apollo
+ os=-sysv
+ ;;
+ aux)
+ basic_machine=m68k-apple
+ os=-aux
+ ;;
+ balance)
+ basic_machine=ns32k-sequent
+ os=-dynix
+ ;;
+ convex-c1)
+ basic_machine=c1-convex
+ os=-bsd
+ ;;
+ convex-c2)
+ basic_machine=c2-convex
+ os=-bsd
+ ;;
+ convex-c32)
+ basic_machine=c32-convex
+ os=-bsd
+ ;;
+ convex-c34)
+ basic_machine=c34-convex
+ os=-bsd
+ ;;
+ convex-c38)
+ basic_machine=c38-convex
+ os=-bsd
+ ;;
+ cray | ymp)
+ basic_machine=ymp-cray
+ os=-unicos
+ ;;
+ cray2)
+ basic_machine=cray2-cray
+ os=-unicos
+ ;;
+ [ctj]90-cray)
+ basic_machine=c90-cray
+ os=-unicos
+ ;;
+ crds | unos)
+ basic_machine=m68k-crds
+ ;;
+ da30 | da30-*)
+ basic_machine=m68k-da30
+ ;;
+ decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+ basic_machine=mips-dec
+ ;;
+ delta | 3300 | motorola-3300 | motorola-delta \
+ | 3300-motorola | delta-motorola)
+ basic_machine=m68k-motorola
+ ;;
+ delta88)
+ basic_machine=m88k-motorola
+ os=-sysv3
+ ;;
+ dpx20 | dpx20-*)
+ basic_machine=rs6000-bull
+ os=-bosx
+ ;;
+ dpx2* | dpx2*-bull)
+ basic_machine=m68k-bull
+ os=-sysv3
+ ;;
+ ebmon29k)
+ basic_machine=a29k-amd
+ os=-ebmon
+ ;;
+ elxsi)
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+ fx2800)
+ basic_machine=i860-alliant
+ ;;
+ genix)
+ basic_machine=ns32k-ns
+ ;;
+ gmicro)
+ basic_machine=tron-gmicro
+ os=-sysv
+ ;;
+ h3050r* | hiux*)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ h8300hms)
+ basic_machine=h8300-hitachi
+ os=-hms
+ ;;
+ harris)
+ basic_machine=m88k-harris
+ os=-sysv3
+ ;;
+ hp300-*)
+ basic_machine=m68k-hp
+ ;;
+ hp300bsd)
+ basic_machine=m68k-hp
+ os=-bsd
+ ;;
+ hp300hpux)
+ basic_machine=m68k-hp
+ os=-hpux
+ ;;
+ hp9k2[0-9][0-9] | hp9k31[0-9])
+ basic_machine=m68000-hp
+ ;;
+ hp9k3[2-9][0-9])
+ basic_machine=m68k-hp
+ ;;
+ hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7)
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[0-9][0-9] | hp8[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hppa-next)
+ os=-nextstep3
+ ;;
+ i370-ibm* | ibm*)
+ basic_machine=i370-ibm
+ os=-mvs
+ ;;
+# I'm not sure what "Sysv32" means. Should this be sysv3.2?
+ i[3456]86v32)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv32
+ ;;
+ i[3456]86v4*)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv4
+ ;;
+ i[3456]86v)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv
+ ;;
+ i[3456]86sol2)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-solaris2
+ ;;
+ iris | iris4d)
+ basic_machine=mips-sgi
+ case $os in
+ -irix*)
+ ;;
+ *)
+ os=-irix4
+ ;;
+ esac
+ ;;
+ isi68 | isi)
+ basic_machine=m68k-isi
+ os=-sysv
+ ;;
+ m88k-omron*)
+ basic_machine=m88k-omron
+ ;;
+ magnum | m3230)
+ basic_machine=mips-mips
+ os=-sysv
+ ;;
+ merlin)
+ basic_machine=ns32k-utek
+ os=-sysv
+ ;;
+ miniframe)
+ basic_machine=m68000-convergent
+ ;;
+ mipsel*-linux*)
+ basic_machine=mipsel-unknown
+ os=-linux-gnu
+ ;;
+ mips*-linux*)
+ basic_machine=mips-unknown
+ os=-linux-gnu
+ ;;
+ mips3*-*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+ ;;
+ mips3*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+ ;;
+ ncr3000)
+ basic_machine=i486-ncr
+ os=-sysv4
+ ;;
+ news | news700 | news800 | news900)
+ basic_machine=m68k-sony
+ os=-newsos
+ ;;
+ news1000)
+ basic_machine=m68030-sony
+ os=-newsos
+ ;;
+ news-3600 | risc-news)
+ basic_machine=mips-sony
+ os=-newsos
+ ;;
+ next | m*-next )
+ basic_machine=m68k-next
+ case $os in
+ -nextstep* )
+ ;;
+ -ns2*)
+ os=-nextstep2
+ ;;
+ *)
+ os=-nextstep3
+ ;;
+ esac
+ ;;
+ nh3000)
+ basic_machine=m68k-harris
+ os=-cxux
+ ;;
+ nh[45]000)
+ basic_machine=m88k-harris
+ os=-cxux
+ ;;
+ nindy960)
+ basic_machine=i960-intel
+ os=-nindy
+ ;;
+ np1)
+ basic_machine=np1-gould
+ ;;
+ pa-hitachi)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ paragon)
+ basic_machine=i860-intel
+ os=-osf
+ ;;
+ pbd)
+ basic_machine=sparc-tti
+ ;;
+ pbb)
+ basic_machine=m68k-tti
+ ;;
+ pc532 | pc532-*)
+ basic_machine=ns32k-pc532
+ ;;
+ pentium | p5)
+ basic_machine=i586-intel
+ ;;
+ pentiumpro | p6)
+ basic_machine=i686-intel
+ ;;
+ pentium-* | p5-*)
+ basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentiumpro-* | p6-*)
+ basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ k5)
+ # We don't have specific support for AMD's K5 yet, so just call it a Pentium
+ basic_machine=i586-amd
+ ;;
+ nexen)
+ # We don't have specific support for Nexgen yet, so just call it a Pentium
+ basic_machine=i586-nexgen
+ ;;
+ pn)
+ basic_machine=pn-gould
+ ;;
+ power) basic_machine=rs6000-ibm
+ ;;
+ ppc) basic_machine=powerpc-unknown
+ ;;
+ ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppcle | powerpclittle | ppc-le | powerpc-little)
+ basic_machine=powerpcle-unknown
+ ;;
+ ppcle-* | powerpclittle-*)
+ basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ps2)
+ basic_machine=i386-ibm
+ ;;
+ rm[46]00)
+ basic_machine=mips-siemens
+ ;;
+ rtpc | rtpc-*)
+ basic_machine=romp-ibm
+ ;;
+ sequent)
+ basic_machine=i386-sequent
+ ;;
+ sh)
+ basic_machine=sh-hitachi
+ os=-hms
+ ;;
+ sps7)
+ basic_machine=m68k-bull
+ os=-sysv2
+ ;;
+ spur)
+ basic_machine=spur-unknown
+ ;;
+ sun2)
+ basic_machine=m68000-sun
+ ;;
+ sun2os3)
+ basic_machine=m68000-sun
+ os=-sunos3
+ ;;
+ sun2os4)
+ basic_machine=m68000-sun
+ os=-sunos4
+ ;;
+ sun3os3)
+ basic_machine=m68k-sun
+ os=-sunos3
+ ;;
+ sun3os4)
+ basic_machine=m68k-sun
+ os=-sunos4
+ ;;
+ sun4os3)
+ basic_machine=sparc-sun
+ os=-sunos3
+ ;;
+ sun4os4)
+ basic_machine=sparc-sun
+ os=-sunos4
+ ;;
+ sun4sol2)
+ basic_machine=sparc-sun
+ os=-solaris2
+ ;;
+ sun3 | sun3-*)
+ basic_machine=m68k-sun
+ ;;
+ sun4)
+ basic_machine=sparc-sun
+ ;;
+ sun386 | sun386i | roadrunner)
+ basic_machine=i386-sun
+ ;;
+ symmetry)
+ basic_machine=i386-sequent
+ os=-dynix
+ ;;
+ tx39)
+ basic_machine=mipstx39-unknown
+ ;;
+ tx39el)
+ basic_machine=mipstx39el-unknown
+ ;;
+ tower | tower-32)
+ basic_machine=m68k-ncr
+ ;;
+ udi29k)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ ultra3)
+ basic_machine=a29k-nyu
+ os=-sym1
+ ;;
+ vaxv)
+ basic_machine=vax-dec
+ os=-sysv
+ ;;
+ vms)
+ basic_machine=vax-dec
+ os=-vms
+ ;;
+ vpp*|vx|vx-*)
+ basic_machine=f301-fujitsu
+ ;;
+ vxworks960)
+ basic_machine=i960-wrs
+ os=-vxworks
+ ;;
+ vxworks68)
+ basic_machine=m68k-wrs
+ os=-vxworks
+ ;;
+ vxworks29k)
+ basic_machine=a29k-wrs
+ os=-vxworks
+ ;;
+ xmp)
+ basic_machine=xmp-cray
+ os=-unicos
+ ;;
+ xps | xps100)
+ basic_machine=xps100-honeywell
+ ;;
+ none)
+ basic_machine=none-none
+ os=-none
+ ;;
+
+# Here we handle the default manufacturer of certain CPU types. It is in
+# some cases the only manufacturer, in others, it is the most popular.
+ mips)
+ if [ x$os = x-linux-gnu ]; then
+ basic_machine=mips-unknown
+ else
+ basic_machine=mips-mips
+ fi
+ ;;
+ romp)
+ basic_machine=romp-ibm
+ ;;
+ rs6000)
+ basic_machine=rs6000-ibm
+ ;;
+ vax)
+ basic_machine=vax-dec
+ ;;
+ pdp11)
+ basic_machine=pdp11-dec
+ ;;
+ we32k)
+ basic_machine=we32k-att
+ ;;
+ sparc)
+ basic_machine=sparc-sun
+ ;;
+ cydra)
+ basic_machine=cydra-cydrome
+ ;;
+ orion)
+ basic_machine=orion-highlevel
+ ;;
+ orion105)
+ basic_machine=clipper-highlevel
+ ;;
+ *)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+ *-digital*)
+ basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+ ;;
+ *-commodore*)
+ basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+ ;;
+ *)
+ ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+ # First match some system type aliases
+ # that might get confused with valid system types.
+ # -solaris* is a basic system type, with this one exception.
+ -solaris1 | -solaris1.*)
+ os=`echo $os | sed -e 's|solaris1|sunos4|'`
+ ;;
+ -solaris)
+ os=-solaris2
+ ;;
+ -svr4*)
+ os=-sysv4
+ ;;
+ -unixware*)
+ os=-sysv4.2uw
+ ;;
+ -gnu/linux*)
+ os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+ ;;
+ # First accept the basic system types.
+ # The portable systems comes first.
+ # Each alternative MUST END IN A *, to match a version number.
+ # -sysv* is not here because it comes later, after sysvr4.
+ -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+ | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+ | -aos* \
+ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+ | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
+ | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \
+ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ | -cygwin32* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+ | -mingw32* | -linux-gnu* | -uxpv*)
+ # Remember, each alternative MUST END IN *, to match a version number.
+ ;;
+ -linux*)
+ os=`echo $os | sed -e 's|linux|linux-gnu|'`
+ ;;
+ -sunos5*)
+ os=`echo $os | sed -e 's|sunos5|solaris2|'`
+ ;;
+ -sunos6*)
+ os=`echo $os | sed -e 's|sunos6|solaris3|'`
+ ;;
+ -osfrose*)
+ os=-osfrose
+ ;;
+ -osf*)
+ os=-osf
+ ;;
+ -utek*)
+ os=-bsd
+ ;;
+ -dynix*)
+ os=-bsd
+ ;;
+ -acis*)
+ os=-aos
+ ;;
+ -ctix* | -uts*)
+ os=-sysv
+ ;;
+ -ns2 )
+ os=-nextstep2
+ ;;
+ # Preserve the version number of sinix5.
+ -sinix5.*)
+ os=`echo $os | sed -e 's|sinix|sysv|'`
+ ;;
+ -sinix*)
+ os=-sysv4
+ ;;
+ -triton*)
+ os=-sysv3
+ ;;
+ -oss*)
+ os=-sysv3
+ ;;
+ -svr4)
+ os=-sysv4
+ ;;
+ -svr3)
+ os=-sysv3
+ ;;
+ -sysvr4)
+ os=-sysv4
+ ;;
+ # This must come after -sysvr4.
+ -sysv*)
+ ;;
+ -xenix)
+ os=-xenix
+ ;;
+ -none)
+ ;;
+ *)
+ # Get rid of the `-' at the beginning of $os.
+ os=`echo $os | sed 's/[^-]*-//'`
+ echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system. Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+ *-acorn)
+ os=-riscix1.2
+ ;;
+ arm*-semi)
+ os=-aout
+ ;;
+ pdp11-*)
+ os=-none
+ ;;
+ *-dec | vax-*)
+ os=-ultrix4.2
+ ;;
+ m68*-apollo)
+ os=-domain
+ ;;
+ i386-sun)
+ os=-sunos4.0.2
+ ;;
+ m68000-sun)
+ os=-sunos3
+ # This also exists in the configure program, but was not the
+ # default.
+ # os=-sunos4
+ ;;
+ *-tti) # must be before sparc entry or we get the wrong os.
+ os=-sysv3
+ ;;
+ sparc-* | *-sun)
+ os=-sunos4.1.1
+ ;;
+ *-ibm)
+ os=-aix
+ ;;
+ *-hp)
+ os=-hpux
+ ;;
+ *-hitachi)
+ os=-hiux
+ ;;
+ i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+ os=-sysv
+ ;;
+ *-cbm)
+ os=-amigaos
+ ;;
+ *-dg)
+ os=-dgux
+ ;;
+ *-dolphin)
+ os=-sysv3
+ ;;
+ m68k-ccur)
+ os=-rtu
+ ;;
+ m88k-omron*)
+ os=-luna
+ ;;
+ *-next )
+ os=-nextstep
+ ;;
+ *-sequent)
+ os=-ptx
+ ;;
+ *-crds)
+ os=-unos
+ ;;
+ *-ns)
+ os=-genix
+ ;;
+ i370-*)
+ os=-mvs
+ ;;
+ *-next)
+ os=-nextstep3
+ ;;
+ *-gould)
+ os=-sysv
+ ;;
+ *-highlevel)
+ os=-bsd
+ ;;
+ *-encore)
+ os=-bsd
+ ;;
+ *-sgi)
+ os=-irix
+ ;;
+ *-siemens)
+ os=-sysv4
+ ;;
+ *-masscomp)
+ os=-rtu
+ ;;
+ f301-fujitsu)
+ os=-uxpv
+ ;;
+ *)
+ os=-none
+ ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer. We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+ *-unknown)
+ case $os in
+ -riscix*)
+ vendor=acorn
+ ;;
+ -sunos*)
+ vendor=sun
+ ;;
+ -aix*)
+ vendor=ibm
+ ;;
+ -hpux*)
+ vendor=hp
+ ;;
+ -hiux*)
+ vendor=hitachi
+ ;;
+ -unos*)
+ vendor=crds
+ ;;
+ -dgux*)
+ vendor=dg
+ ;;
+ -luna*)
+ vendor=omron
+ ;;
+ -genix*)
+ vendor=ns
+ ;;
+ -mvs*)
+ vendor=ibm
+ ;;
+ -ptx*)
+ vendor=sequent
+ ;;
+ -vxsim* | -vxworks*)
+ vendor=wrs
+ ;;
+ -aux*)
+ vendor=apple
+ ;;
+ esac
+ basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+ ;;
+esac
+
+echo $basic_machine$os
diff --git a/osframework/source/ImageLib/jpeg/configure b/osframework/source/ImageLib/jpeg/configure
new file mode 100644
index 0000000..d3239e7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/configure
@@ -0,0 +1,2011 @@
+#! /bin/sh
+
+# Guess values for system-dependent variables and create Makefiles.
+# Generated automatically using autoconf version 2.12
+# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+
+# Defaults:
+ac_help=
+ac_default_prefix=/usr/local
+# Any additions from configure.in:
+ac_help="$ac_help
+ --enable-shared build shared library using GNU libtool"
+ac_help="$ac_help
+ --enable-static build static library using GNU libtool"
+ac_help="$ac_help
+ --enable-maxmem[=N] enable use of temp files, set max mem usage to N MB"
+ac_help="$ac_help
+"
+
+# Initialize some variables set by options.
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+build=NONE
+cache_file=./config.cache
+exec_prefix=NONE
+host=NONE
+no_create=
+nonopt=NONE
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+target=NONE
+verbose=
+x_includes=NONE
+x_libraries=NONE
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+# Initialize some other variables.
+subdirs=
+MFLAGS= MAKEFLAGS=
+# Maximum number of lines to put in a shell here document.
+ac_max_here_lines=12
+
+ac_prev=
+for ac_option
+do
+
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
+
+ case "$ac_option" in
+ -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) ac_optarg= ;;
+ esac
+
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case "$ac_option" in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir="$ac_optarg" ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build="$ac_optarg" ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file="$ac_optarg" ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir="$ac_optarg" ;;
+
+ -disable-* | --disable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ eval "enable_${ac_feature}=no" ;;
+
+ -enable-* | --enable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "enable_${ac_feature}='$ac_optarg'" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix="$ac_optarg" ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he)
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat << EOF
+Usage: configure [options] [host]
+Options: [defaults in brackets after descriptions]
+Configuration:
+ --cache-file=FILE cache test results in FILE
+ --help print this message
+ --no-create do not create output files
+ --quiet, --silent do not print \`checking...' messages
+ --version print the version of autoconf that created configure
+Directory and file names:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [same as prefix]
+ --bindir=DIR user executables in DIR [EPREFIX/bin]
+ --sbindir=DIR system admin executables in DIR [EPREFIX/sbin]
+ --libexecdir=DIR program executables in DIR [EPREFIX/libexec]
+ --datadir=DIR read-only architecture-independent data in DIR
+ [PREFIX/share]
+ --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data in DIR
+ [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var]
+ --libdir=DIR object code libraries in DIR [EPREFIX/lib]
+ --includedir=DIR C header files in DIR [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
+ --infodir=DIR info documentation in DIR [PREFIX/info]
+ --mandir=DIR man documentation in DIR [PREFIX/man]
+ --srcdir=DIR find the sources in DIR [configure dir or ..]
+ --program-prefix=PREFIX prepend PREFIX to installed program names
+ --program-suffix=SUFFIX append SUFFIX to installed program names
+ --program-transform-name=PROGRAM
+ run sed PROGRAM on installed program names
+EOF
+ cat << EOF
+Host type:
+ --build=BUILD configure for building on BUILD [BUILD=HOST]
+ --host=HOST configure for HOST [guessed]
+ --target=TARGET configure for TARGET [TARGET=HOST]
+Features and packages:
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --x-includes=DIR X include files are in DIR
+ --x-libraries=DIR X library files are in DIR
+EOF
+ if test -n "$ac_help"; then
+ echo "--enable and --with options recognized:$ac_help"
+ fi
+ exit 0 ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host="$ac_optarg" ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir="$ac_optarg" ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir="$ac_optarg" ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir="$ac_optarg" ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir="$ac_optarg" ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir="$ac_optarg" ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir="$ac_optarg" ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir="$ac_optarg" ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix="$ac_optarg" ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix="$ac_optarg" ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix="$ac_optarg" ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name="$ac_optarg" ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir="$ac_optarg" ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir="$ac_optarg" ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site="$ac_optarg" ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir="$ac_optarg" ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir="$ac_optarg" ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target="$ac_optarg" ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers)
+ echo "configure generated by autoconf version 2.12"
+ exit 0 ;;
+
+ -with-* | --with-*)
+ ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "with_${ac_package}='$ac_optarg'" ;;
+
+ -without-* | --without-*)
+ ac_package=`echo $ac_option|sed -e 's/-*without-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ eval "with_${ac_package}=no" ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes="$ac_optarg" ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries="$ac_optarg" ;;
+
+ -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
+ ;;
+
+ *=*)
+ varname=`echo "$ac_option"|sed -e 's/=.*//'`
+ # Reject names that aren't valid shell variable names.
+ if test -n "`echo $varname| sed 's/[a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $varname: invalid shell variable name" 1>&2; exit 1; }
+ fi
+ val="`echo "$ac_option"|sed 's/[^=]*=//'`"
+ test -n "$verbose" && echo " setting shell variable $varname to $val"
+ eval "$varname='$val'"
+ eval "export $varname" ;;
+
+ *)
+ if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
+ echo "configure: warning: $ac_option: invalid host type" 1>&2
+ fi
+ if test "x$nonopt" != xNONE; then
+ { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
+ fi
+ nonopt="$ac_option"
+ ;;
+
+ esac
+done
+
+if test -n "$ac_prev"; then
+ { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
+fi
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+# File descriptor usage:
+# 0 standard input
+# 1 file creation
+# 2 errors and warnings
+# 3 some systems may open it to /dev/tty
+# 4 used on the Kubota Titan
+# 6 checking for... messages and results
+# 5 compiler messages saved in config.log
+if test "$silent" = yes; then
+ exec 6>/dev/null
+else
+ exec 6>&1
+fi
+exec 5>./config.log
+
+echo "\
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+" 1>&5
+
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Also quote any args containing shell metacharacters.
+ac_configure_args=
+for ac_arg
+do
+ case "$ac_arg" in
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c) ;;
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
+ ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+ *) ac_configure_args="$ac_configure_args $ac_arg" ;;
+ esac
+done
+
+# NLS nuisances.
+# Only set these to C if already set. These must not be set unconditionally
+# because not all systems understand e.g. LANG=C (notably SCO).
+# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
+# Non-C LC_CTYPE values break the ctype check.
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo > confdefs.h
+
+# A filename unique to this package, relative to the directory that
+# configure is in, which we can look for to find out if srcdir is correct.
+ac_unique_file=jcmaster.c
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then its parent.
+ ac_prog=$0
+ ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
+ test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
+ srcdir=$ac_confdir
+ if test ! -r $srcdir/$ac_unique_file; then
+ srcdir=..
+ fi
+else
+ ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+ if test "$ac_srcdir_defaulted" = yes; then
+ { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
+ else
+ { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
+ fi
+fi
+srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
+
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+ if test "x$prefix" != xNONE; then
+ CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+ else
+ CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+ fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+ if test -r "$ac_site_file"; then
+ echo "loading site script $ac_site_file"
+ . "$ac_site_file"
+ fi
+done
+
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+ # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
+ if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+ ac_n= ac_c='
+' ac_t=' '
+ else
+ ac_n=-n ac_c= ac_t=
+ fi
+else
+ ac_n= ac_c='\c' ac_t=
+fi
+
+
+
+# Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:538: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_CC="gcc"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+if test -z "$CC"; then
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:567: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ ac_prog_rejected=no
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# -gt 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ set dummy "$ac_dir/$ac_word" "$@"
+ shift
+ ac_cv_prog_CC="$@"
+ fi
+fi
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+ test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
+echo "configure:615: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+cat > conftest.$ac_ext <<EOF
+#line 625 "configure"
+#include "confdefs.h"
+main(){return(0);}
+EOF
+if { (eval echo configure:629: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ ac_cv_prog_cc_works=yes
+ # If we can't run a trivial program, we are probably using a cross compiler.
+ if (./conftest; exit) 2>/dev/null; then
+ ac_cv_prog_cc_cross=no
+ else
+ ac_cv_prog_cc_cross=yes
+ fi
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ ac_cv_prog_cc_works=no
+fi
+rm -fr conftest*
+
+echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
+if test $ac_cv_prog_cc_works = no; then
+ { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
+fi
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
+echo "configure:649: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
+echo "configure:654: checking whether we are using GNU C" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.c <<EOF
+#ifdef __GNUC__
+ yes;
+#endif
+EOF
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:663: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+ ac_cv_prog_gcc=yes
+else
+ ac_cv_prog_gcc=no
+fi
+fi
+
+echo "$ac_t""$ac_cv_prog_gcc" 1>&6
+
+if test $ac_cv_prog_gcc = yes; then
+ GCC=yes
+ test "${CFLAGS+set}" = set || CFLAGS="-O2"
+else
+ GCC=
+ test "${CFLAGS+set}" = set || CFLAGS="-O"
+fi
+
+echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
+echo "configure:681: checking how to run the C preprocessor" >&5
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+ CPP=
+fi
+if test -z "$CPP"; then
+if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ # This must be in double quotes, not single quotes, because CPP may get
+ # substituted into the Makefile and "${CC-cc}" will confuse make.
+ CPP="${CC-cc} -E"
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp.
+ cat > conftest.$ac_ext <<EOF
+#line 696 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:702: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ :
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ CPP="${CC-cc} -E -traditional-cpp"
+ cat > conftest.$ac_ext <<EOF
+#line 713 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:719: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ :
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ CPP=/lib/cpp
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+ ac_cv_prog_CPP="$CPP"
+fi
+ CPP="$ac_cv_prog_CPP"
+else
+ ac_cv_prog_CPP="$CPP"
+fi
+echo "$ac_t""$CPP" 1>&6
+
+echo $ac_n "checking for function prototypes""... $ac_c" 1>&6
+echo "configure:742: checking for function prototypes" >&5
+if eval "test \"`echo '$''{'ijg_cv_have_prototypes'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 747 "configure"
+#include "confdefs.h"
+
+int testfunction (int arg1, int * arg2); /* check prototypes */
+struct methods_struct { /* check method-pointer declarations */
+ int (*error_exit) (char *msgtext);
+ int (*trace_message) (char *msgtext);
+ int (*another_method) (void);
+};
+int testfunction (int arg1, int * arg2) /* check definitions */
+{ return arg2[arg1]; }
+int test2function (void) /* check void arg list */
+{ return 0; }
+
+int main() {
+
+; return 0; }
+EOF
+if { (eval echo configure:765: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ijg_cv_have_prototypes=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ijg_cv_have_prototypes=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$ijg_cv_have_prototypes" 1>&6
+if test $ijg_cv_have_prototypes = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_PROTOTYPES
+EOF
+
+else
+ echo Your compiler does not seem to know about function prototypes.
+ echo Perhaps it needs a special switch to enable ANSI C mode.
+ echo If so, we recommend running configure like this:
+ echo " ./configure CC='cc -switch'"
+ echo where -switch is the proper switch.
+fi
+ac_safe=`echo "stddef.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for stddef.h""... $ac_c" 1>&6
+echo "configure:792: checking for stddef.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 797 "configure"
+#include "confdefs.h"
+#include <stddef.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:802: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define HAVE_STDDEF_H
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+ac_safe=`echo "stdlib.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for stdlib.h""... $ac_c" 1>&6
+echo "configure:828: checking for stdlib.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 833 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:838: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define HAVE_STDLIB_H
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+ac_safe=`echo "string.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for string.h""... $ac_c" 1>&6
+echo "configure:864: checking for string.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 869 "configure"
+#include "confdefs.h"
+#include <string.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:874: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ :
+else
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define NEED_BSD_STRINGS
+EOF
+
+fi
+
+echo $ac_n "checking for size_t""... $ac_c" 1>&6
+echo "configure:900: checking for size_t" >&5
+cat > conftest.$ac_ext <<EOF
+#line 902 "configure"
+#include "confdefs.h"
+
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <stdio.h>
+#ifdef NEED_BSD_STRINGS
+#include <strings.h>
+#else
+#include <string.h>
+#endif
+typedef size_t my_size_t;
+
+int main() {
+ my_size_t foovar;
+; return 0; }
+EOF
+if { (eval echo configure:923: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ijg_size_t_ok=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ijg_size_t_ok="not ANSI, perhaps it is in sys/types.h"
+fi
+rm -f conftest*
+echo "$ac_t""$ijg_size_t_ok" 1>&6
+if test "$ijg_size_t_ok" != yes; then
+ac_safe=`echo "sys/types.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for sys/types.h""... $ac_c" 1>&6
+echo "configure:937: checking for sys/types.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 942 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:947: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define NEED_SYS_TYPES_H
+EOF
+
+cat > conftest.$ac_ext <<EOF
+#line 968 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "size_t" >/dev/null 2>&1; then
+ rm -rf conftest*
+ ijg_size_t_ok="size_t is in sys/types.h"
+else
+ rm -rf conftest*
+ ijg_size_t_ok=no
+fi
+rm -f conftest*
+
+else
+ echo "$ac_t""no" 1>&6
+ijg_size_t_ok=no
+fi
+
+echo "$ac_t""$ijg_size_t_ok" 1>&6
+if test "$ijg_size_t_ok" = no; then
+ echo Type size_t is not defined in any of the usual places.
+ echo Try putting '"typedef unsigned int size_t;"' in jconfig.h.
+fi
+fi
+echo $ac_n "checking for type unsigned char""... $ac_c" 1>&6
+echo "configure:994: checking for type unsigned char" >&5
+cat > conftest.$ac_ext <<EOF
+#line 996 "configure"
+#include "confdefs.h"
+
+int main() {
+ unsigned char un_char;
+; return 0; }
+EOF
+if { (eval echo configure:1003: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6
+cat >> confdefs.h <<\EOF
+#define HAVE_UNSIGNED_CHAR
+EOF
+
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
+fi
+rm -f conftest*
+echo $ac_n "checking for type unsigned short""... $ac_c" 1>&6
+echo "configure:1018: checking for type unsigned short" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1020 "configure"
+#include "confdefs.h"
+
+int main() {
+ unsigned short un_short;
+; return 0; }
+EOF
+if { (eval echo configure:1027: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6
+cat >> confdefs.h <<\EOF
+#define HAVE_UNSIGNED_SHORT
+EOF
+
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
+fi
+rm -f conftest*
+echo $ac_n "checking for type void""... $ac_c" 1>&6
+echo "configure:1042: checking for type void" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1044 "configure"
+#include "confdefs.h"
+
+/* Caution: a C++ compiler will insist on valid prototypes */
+typedef void * void_ptr; /* check void * */
+#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
+typedef void (*void_func) (int a, int b);
+#else
+typedef void (*void_func) ();
+#endif
+
+#ifdef HAVE_PROTOTYPES /* check void function result */
+void test3function (void_ptr arg1, void_func arg2)
+#else
+void test3function (arg1, arg2)
+ void_ptr arg1;
+ void_func arg2;
+#endif
+{
+ char * locptr = (char *) arg1; /* check casting to and from void * */
+ arg1 = (void *) locptr;
+ (*arg2) (1, 2); /* check call of fcn returning void */
+}
+
+int main() {
+
+; return 0; }
+EOF
+if { (eval echo configure:1072: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define void char
+EOF
+
+fi
+rm -f conftest*
+
+echo $ac_n "checking for working const""... $ac_c" 1>&6
+echo "configure:1088: checking for working const" >&5
+if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1093 "configure"
+#include "confdefs.h"
+
+int main() {
+
+/* Ultrix mips cc rejects this. */
+typedef int charset[2]; const charset x;
+/* SunOS 4.1.1 cc rejects this. */
+char const *const *ccp;
+char **p;
+/* NEC SVR4.0.2 mips cc rejects this. */
+struct point {int x, y;};
+static struct point const zero = {0,0};
+/* AIX XL C 1.02.0.0 rejects this.
+ It does not let you subtract one const X* pointer from another in an arm
+ of an if-expression whose if-part is not a constant expression */
+const char *g = "string";
+ccp = &g + (g ? g-g : 0);
+/* HPUX 7.0 cc rejects these. */
+++ccp;
+p = (char**) ccp;
+ccp = (char const *const *) p;
+{ /* SCO 3.2v4 cc rejects this. */
+ char *t;
+ char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+ *t++ = 0;
+}
+{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
+ int x[] = {25, 17};
+ const int *foo = &x[0];
+ ++foo;
+}
+{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+ typedef const int *iptr;
+ iptr p = 0;
+ ++p;
+}
+{ /* AIX XL C 1.02.0.0 rejects this saying
+ "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+ struct s { int j; const int *ap[3]; };
+ struct s *b; b->j = 5;
+}
+{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+ const int foo = 10;
+}
+
+; return 0; }
+EOF
+if { (eval echo configure:1142: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ac_cv_c_const=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ac_cv_c_const=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$ac_cv_c_const" 1>&6
+if test $ac_cv_c_const = no; then
+ cat >> confdefs.h <<\EOF
+#define const
+EOF
+
+fi
+
+echo $ac_n "checking for inline""... $ac_c" 1>&6
+echo "configure:1163: checking for inline" >&5
+ijg_cv_inline=""
+cat > conftest.$ac_ext <<EOF
+#line 1166 "configure"
+#include "confdefs.h"
+
+int main() {
+} __inline__ int foo() { return 0; }
+int bar() { return foo();
+; return 0; }
+EOF
+if { (eval echo configure:1174: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ijg_cv_inline="__inline__"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ cat > conftest.$ac_ext <<EOF
+#line 1182 "configure"
+#include "confdefs.h"
+
+int main() {
+} __inline int foo() { return 0; }
+int bar() { return foo();
+; return 0; }
+EOF
+if { (eval echo configure:1190: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ijg_cv_inline="__inline"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ cat > conftest.$ac_ext <<EOF
+#line 1198 "configure"
+#include "confdefs.h"
+
+int main() {
+} inline int foo() { return 0; }
+int bar() { return foo();
+; return 0; }
+EOF
+if { (eval echo configure:1206: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ijg_cv_inline="inline"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+echo "$ac_t""$ijg_cv_inline" 1>&6
+cat >> confdefs.h <<EOF
+#define INLINE $ijg_cv_inline
+EOF
+
+echo $ac_n "checking for broken incomplete types""... $ac_c" 1>&6
+echo "configure:1224: checking for broken incomplete types" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1226 "configure"
+#include "confdefs.h"
+ typedef struct undefined_structure * undef_struct_ptr;
+int main() {
+
+; return 0; }
+EOF
+if { (eval echo configure:1233: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ echo "$ac_t""ok" 1>&6
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""broken" 1>&6
+cat >> confdefs.h <<\EOF
+#define INCOMPLETE_TYPES_BROKEN
+EOF
+
+fi
+rm -f conftest*
+echo $ac_n "checking for short external names""... $ac_c" 1>&6
+echo "configure:1248: checking for short external names" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1250 "configure"
+#include "confdefs.h"
+
+int possibly_duplicate_function () { return 0; }
+int possibly_dupli_function () { return 1; }
+
+int main() {
+
+; return 0; }
+EOF
+if { (eval echo configure:1260: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ echo "$ac_t""ok" 1>&6
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""short" 1>&6
+cat >> confdefs.h <<\EOF
+#define NEED_SHORT_EXTERNAL_NAMES
+EOF
+
+fi
+rm -f conftest*
+echo $ac_n "checking to see if char is signed""... $ac_c" 1>&6
+echo "configure:1275: checking to see if char is signed" >&5
+if test "$cross_compiling" = yes; then
+ echo Assuming that char is signed on target machine.
+echo If it is unsigned, this will be a little bit inefficient.
+
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1282 "configure"
+#include "confdefs.h"
+
+#ifdef HAVE_PROTOTYPES
+int is_char_signed (int arg)
+#else
+int is_char_signed (arg)
+ int arg;
+#endif
+{
+ if (arg == 189) { /* expected result for unsigned char */
+ return 0; /* type char is unsigned */
+ }
+ else if (arg != -67) { /* expected result for signed char */
+ printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
+ printf("I fear the JPEG software will not work at all.\n\n");
+ }
+ return 1; /* assume char is signed otherwise */
+}
+char signed_char_check = (char) (-67);
+main() {
+ exit(is_char_signed((int) signed_char_check));
+}
+EOF
+if { (eval echo configure:1306: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define CHAR_IS_UNSIGNED
+EOF
+
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ echo "$ac_t""yes" 1>&6
+fi
+rm -fr conftest*
+fi
+
+echo $ac_n "checking to see if right shift is signed""... $ac_c" 1>&6
+echo "configure:1323: checking to see if right shift is signed" >&5
+if test "$cross_compiling" = yes; then
+ echo "$ac_t""Assuming that right shift is signed on target machine." 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1328 "configure"
+#include "confdefs.h"
+
+#ifdef HAVE_PROTOTYPES
+int is_shifting_signed (long arg)
+#else
+int is_shifting_signed (arg)
+ long arg;
+#endif
+/* See whether right-shift on a long is signed or not. */
+{
+ long res = arg >> 4;
+
+ if (res == -0x7F7E80CL) { /* expected result for signed shift */
+ return 1; /* right shift is signed */
+ }
+ /* see if unsigned-shift hack will fix it. */
+ /* we can't just test exact value since it depends on width of long... */
+ res |= (~0L) << (32-4);
+ if (res == -0x7F7E80CL) { /* expected result now? */
+ return 0; /* right shift is unsigned */
+ }
+ printf("Right shift isn't acting as I expect it to.\n");
+ printf("I fear the JPEG software will not work at all.\n\n");
+ return 0; /* try it with unsigned anyway */
+}
+main() {
+ exit(is_shifting_signed(-0x7F7E80B1L));
+}
+EOF
+if { (eval echo configure:1358: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define RIGHT_SHIFT_IS_UNSIGNED
+EOF
+
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ echo "$ac_t""yes" 1>&6
+fi
+rm -fr conftest*
+fi
+
+echo $ac_n "checking to see if fopen accepts b spec""... $ac_c" 1>&6
+echo "configure:1375: checking to see if fopen accepts b spec" >&5
+if test "$cross_compiling" = yes; then
+ echo "$ac_t""Assuming that it does." 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1380 "configure"
+#include "confdefs.h"
+
+#include <stdio.h>
+main() {
+ if (fopen("conftestdata", "wb") != NULL)
+ exit(0);
+ exit(1);
+}
+EOF
+if { (eval echo configure:1390: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ echo "$ac_t""yes" 1>&6
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define DONT_USE_B_MODE
+EOF
+
+fi
+rm -fr conftest*
+fi
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+ if test -f $ac_dir/install-sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f $ac_dir/install.sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
+fi
+ac_config_guess=$ac_aux_dir/config.guess
+ac_config_sub=$ac_aux_dir/config.sub
+ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
+
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# ./install, which can be erroneously created by make from ./install.sh.
+echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
+echo "configure:1436: checking for a BSD compatible install" >&5
+if test -z "$INSTALL"; then
+if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ # Account for people who put trailing slashes in PATH elements.
+ case "$ac_dir/" in
+ /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ for ac_prog in ginstall installbsd scoinst install; do
+ if test -f $ac_dir/$ac_prog; then
+ if test $ac_prog = install &&
+ grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ # OSF/1 installbsd also uses dspmsg, but is usable.
+ :
+ else
+ ac_cv_path_install="$ac_dir/$ac_prog -c"
+ break 2
+ fi
+ fi
+ done
+ ;;
+ esac
+ done
+ IFS="$ac_save_IFS"
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL="$ac_cv_path_install"
+ else
+ # As a last resort, use the slow shell script. We don't cache a
+ # path for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the path is relative.
+ INSTALL="$ac_install_sh"
+ fi
+fi
+echo "$ac_t""$INSTALL" 1>&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+# Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:1488: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$RANLIB"; then
+ ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_RANLIB="ranlib"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+ test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB=":"
+fi
+fi
+RANLIB="$ac_cv_prog_RANLIB"
+if test -n "$RANLIB"; then
+ echo "$ac_t""$RANLIB" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+
+# Decide whether to use libtool,
+# and if so whether to build shared, static, or both flavors of library.
+LTSHARED="no"
+# Check whether --enable-shared or --disable-shared was given.
+if test "${enable_shared+set}" = set; then
+ enableval="$enable_shared"
+ LTSHARED="$enableval"
+fi
+
+LTSTATIC="no"
+# Check whether --enable-static or --disable-static was given.
+if test "${enable_static+set}" = set; then
+ enableval="$enable_static"
+ LTSTATIC="$enableval"
+fi
+
+if test "x$LTSHARED" != xno -o "x$LTSTATIC" != xno; then
+ USELIBTOOL="yes"
+ LIBTOOL="./libtool"
+ O="lo"
+ A="la"
+ LN='$(LIBTOOL) --mode=link $(CC)'
+ INSTALL_LIB='$(LIBTOOL) --mode=install ${INSTALL}'
+ INSTALL_PROGRAM="\$(LIBTOOL) --mode=install $INSTALL_PROGRAM"
+else
+ USELIBTOOL="no"
+ LIBTOOL=""
+ O="o"
+ A="a"
+ LN='$(CC)'
+ INSTALL_LIB="$INSTALL_DATA"
+fi
+
+
+
+
+
+
+# Configure libtool if needed.
+if test $USELIBTOOL = yes; then
+ disable_shared=
+ disable_static=
+ if test "x$LTSHARED" = xno; then
+ disable_shared="--disable-shared"
+ fi
+ if test "x$LTSTATIC" = xno; then
+ disable_static="--disable-static"
+ fi
+ $srcdir/ltconfig $disable_shared $disable_static $srcdir/ltmain.sh
+fi
+
+# Select memory manager depending on user input.
+# If no "-enable-maxmem", use jmemnobs
+MEMORYMGR='jmemnobs.$(O)'
+MAXMEM="no"
+# Check whether --enable-maxmem or --disable-maxmem was given.
+if test "${enable_maxmem+set}" = set; then
+ enableval="$enable_maxmem"
+ MAXMEM="$enableval"
+fi
+
+# support --with-maxmem for backwards compatibility with IJG V5.
+# Check whether --with-maxmem or --without-maxmem was given.
+if test "${with_maxmem+set}" = set; then
+ withval="$with_maxmem"
+ MAXMEM="$withval"
+fi
+
+if test "x$MAXMEM" = xyes; then
+ MAXMEM=1
+fi
+if test "x$MAXMEM" != xno; then
+ if test -n "`echo $MAXMEM | sed 's/[0-9]//g'`"; then
+ { echo "configure: error: non-numeric argument to --enable-maxmem" 1>&2; exit 1; }
+ fi
+ DEFAULTMAXMEM=`expr $MAXMEM \* 1048576`
+cat >> confdefs.h <<EOF
+#define DEFAULT_MAX_MEM ${DEFAULTMAXMEM}
+EOF
+
+echo $ac_n "checking for 'tmpfile()'""... $ac_c" 1>&6
+echo "configure:1596: checking for 'tmpfile()'" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1598 "configure"
+#include "confdefs.h"
+#include <stdio.h>
+int main() {
+ FILE * tfile = tmpfile();
+; return 0; }
+EOF
+if { (eval echo configure:1605: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6
+MEMORYMGR='jmemansi.$(O)'
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
+MEMORYMGR='jmemname.$(O)'
+cat >> confdefs.h <<\EOF
+#define NEED_SIGNAL_CATCHER
+EOF
+
+echo $ac_n "checking for 'mktemp()'""... $ac_c" 1>&6
+echo "configure:1620: checking for 'mktemp()'" >&5
+cat > conftest.$ac_ext <<EOF
+#line 1622 "configure"
+#include "confdefs.h"
+
+int main() {
+ char fname[80]; mktemp(fname);
+; return 0; }
+EOF
+if { (eval echo configure:1629: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
+cat >> confdefs.h <<\EOF
+#define NO_MKTEMP
+EOF
+
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+fi
+
+
+# Extract the library version ID from jpeglib.h.
+echo $ac_n "checking libjpeg version number""... $ac_c" 1>&6
+echo "configure:1650: checking libjpeg version number" >&5
+JPEG_LIB_VERSION=`sed -e '/^#define JPEG_LIB_VERSION/!d' -e 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' $srcdir/jpeglib.h`
+echo "$ac_t""$JPEG_LIB_VERSION" 1>&6
+
+
+# Prepare to massage makefile.cfg correctly.
+if test $ijg_cv_have_prototypes = yes; then
+ A2K_DEPS=""
+ COM_A2K="# "
+else
+ A2K_DEPS="ansi2knr"
+ COM_A2K=""
+fi
+
+
+# ansi2knr needs -DBSD if string.h is missing
+if test $ac_cv_header_string_h = no; then
+ ANSI2KNRFLAGS="-DBSD"
+else
+ ANSI2KNRFLAGS=""
+fi
+
+# Substitutions to enable or disable libtool-related stuff
+if test $USELIBTOOL = yes -a $ijg_cv_have_prototypes = yes; then
+ COM_LT=""
+else
+ COM_LT="# "
+fi
+
+if test "x$LTSHARED" != xno; then
+ FORCE_INSTALL_LIB="install-lib"
+else
+ FORCE_INSTALL_LIB=""
+fi
+
+# Set up -I directives
+if test "x$srcdir" = x.; then
+ INCLUDEFLAGS='-I$(srcdir)'
+else
+ INCLUDEFLAGS='-I. -I$(srcdir)'
+fi
+
+trap '' 1 2 15
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Any assignment to VPATH causes Sun make to only execute
+# the first set of double-colon rules, so remove it if not needed.
+# If there is a colon in the path, we need to keep it.
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d'
+fi
+
+trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
+
+DEFS=-DHAVE_CONFIG_H
+
+# Without the "./", some shells look in PATH for config.status.
+: ${CONFIG_STATUS=./config.status}
+
+echo creating $CONFIG_STATUS
+rm -f $CONFIG_STATUS
+cat > $CONFIG_STATUS <<EOF
+#! /bin/sh
+# Generated automatically by configure.
+# Run this file to recreate the current configuration.
+# This directory was configured as follows,
+# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+#
+# $0 $ac_configure_args
+#
+# Compiler output produced by configure, useful for debugging
+# configure, is in ./config.log if it exists.
+
+ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
+for ac_option
+do
+ case "\$ac_option" in
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
+ exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
+ -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
+ echo "$CONFIG_STATUS generated by autoconf version 2.12"
+ exit 0 ;;
+ -help | --help | --hel | --he | --h)
+ echo "\$ac_cs_usage"; exit 0 ;;
+ *) echo "\$ac_cs_usage"; exit 1 ;;
+ esac
+done
+
+ac_given_srcdir=$srcdir
+ac_given_INSTALL="$INSTALL"
+
+trap 'rm -fr `echo "Makefile:makefile.cfg jconfig.h:jconfig.cfg" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+# Protect against being on the right side of a sed subst in config.status.
+sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
+ s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
+$ac_vpsub
+$extrasub
+s%@CFLAGS@%$CFLAGS%g
+s%@CPPFLAGS@%$CPPFLAGS%g
+s%@CXXFLAGS@%$CXXFLAGS%g
+s%@DEFS@%$DEFS%g
+s%@LDFLAGS@%$LDFLAGS%g
+s%@LIBS@%$LIBS%g
+s%@exec_prefix@%$exec_prefix%g
+s%@prefix@%$prefix%g
+s%@program_transform_name@%$program_transform_name%g
+s%@bindir@%$bindir%g
+s%@sbindir@%$sbindir%g
+s%@libexecdir@%$libexecdir%g
+s%@datadir@%$datadir%g
+s%@sysconfdir@%$sysconfdir%g
+s%@sharedstatedir@%$sharedstatedir%g
+s%@localstatedir@%$localstatedir%g
+s%@libdir@%$libdir%g
+s%@includedir@%$includedir%g
+s%@oldincludedir@%$oldincludedir%g
+s%@infodir@%$infodir%g
+s%@mandir@%$mandir%g
+s%@CC@%$CC%g
+s%@CPP@%$CPP%g
+s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
+s%@INSTALL_DATA@%$INSTALL_DATA%g
+s%@RANLIB@%$RANLIB%g
+s%@LIBTOOL@%$LIBTOOL%g
+s%@O@%$O%g
+s%@A@%$A%g
+s%@LN@%$LN%g
+s%@INSTALL_LIB@%$INSTALL_LIB%g
+s%@MEMORYMGR@%$MEMORYMGR%g
+s%@JPEG_LIB_VERSION@%$JPEG_LIB_VERSION%g
+s%@A2K_DEPS@%$A2K_DEPS%g
+s%@COM_A2K@%$COM_A2K%g
+s%@ANSI2KNRFLAGS@%$ANSI2KNRFLAGS%g
+s%@COM_LT@%$COM_LT%g
+s%@FORCE_INSTALL_LIB@%$FORCE_INSTALL_LIB%g
+s%@INCLUDEFLAGS@%$INCLUDEFLAGS%g
+
+CEOF
+EOF
+
+cat >> $CONFIG_STATUS <<\EOF
+
+# Split the substitutions into bite-sized pieces for seds with
+# small command number limits, like on Digital OSF/1 and HP-UX.
+ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
+ac_file=1 # Number of current file.
+ac_beg=1 # First line for current file.
+ac_end=$ac_max_sed_cmds # Line after last line for current file.
+ac_more_lines=:
+ac_sed_cmds=""
+while $ac_more_lines; do
+ if test $ac_beg -gt 1; then
+ sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
+ else
+ sed "${ac_end}q" conftest.subs > conftest.s$ac_file
+ fi
+ if test ! -s conftest.s$ac_file; then
+ ac_more_lines=false
+ rm -f conftest.s$ac_file
+ else
+ if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds="sed -f conftest.s$ac_file"
+ else
+ ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
+ fi
+ ac_file=`expr $ac_file + 1`
+ ac_beg=$ac_end
+ ac_end=`expr $ac_end + $ac_max_sed_cmds`
+ fi
+done
+if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds=cat
+fi
+EOF
+
+cat >> $CONFIG_STATUS <<EOF
+
+CONFIG_FILES=\${CONFIG_FILES-"Makefile:makefile.cfg"}
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case "$ac_file" in
+ *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+ ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ *) ac_file_in="${ac_file}.in" ;;
+ esac
+
+ # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
+
+ # Remove last slash and all that follows it. Not all systems have dirname.
+ ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+ if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+ # The file is in a subdirectory.
+ test ! -d "$ac_dir" && mkdir "$ac_dir"
+ ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
+ else
+ ac_dir_suffix= ac_dots=
+ fi
+
+ case "$ac_given_srcdir" in
+ .) srcdir=.
+ if test -z "$ac_dots"; then top_srcdir=.
+ else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
+ /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
+ *) # Relative path.
+ srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
+ top_srcdir="$ac_dots$ac_given_srcdir" ;;
+ esac
+
+ case "$ac_given_INSTALL" in
+ [/$]*) INSTALL="$ac_given_INSTALL" ;;
+ *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
+ esac
+
+ echo creating "$ac_file"
+ rm -f "$ac_file"
+ configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
+ case "$ac_file" in
+ *Makefile*) ac_comsub="1i\\
+# $configure_input" ;;
+ *) ac_comsub= ;;
+ esac
+
+ ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+ sed -e "$ac_comsub
+s%@configure_input@%$configure_input%g
+s%@srcdir@%$srcdir%g
+s%@top_srcdir@%$top_srcdir%g
+s%@INSTALL@%$INSTALL%g
+" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
+fi; done
+rm -f conftest.s*
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)'
+ac_dB='\([ ][ ]*\)[^ ]*%\1#\2'
+ac_dC='\3'
+ac_dD='%g'
+# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
+ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
+ac_uB='\([ ]\)%\1#\2define\3'
+ac_uC=' '
+ac_uD='\4%g'
+# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
+ac_eB='$%\1#\2define\3'
+ac_eC=' '
+ac_eD='%g'
+
+if test "${CONFIG_HEADERS+set}" != set; then
+EOF
+cat >> $CONFIG_STATUS <<EOF
+ CONFIG_HEADERS="jconfig.h:jconfig.cfg"
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+fi
+for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case "$ac_file" in
+ *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+ ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ *) ac_file_in="${ac_file}.in" ;;
+ esac
+
+ echo creating $ac_file
+
+ rm -f conftest.frag conftest.in conftest.out
+ ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+ cat $ac_file_inputs > conftest.in
+
+EOF
+
+# Transform confdefs.h into a sed script conftest.vals that substitutes
+# the proper values into config.h.in to produce config.h. And first:
+# Protect against being on the right side of a sed subst in config.status.
+# Protect against being in an unquoted here document in config.status.
+rm -f conftest.vals
+cat > conftest.hdr <<\EOF
+s/[\\&%]/\\&/g
+s%[\\$`]%\\&%g
+s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+s%ac_d%ac_u%gp
+s%ac_u%ac_e%gp
+EOF
+sed -n -f conftest.hdr confdefs.h > conftest.vals
+rm -f conftest.hdr
+
+# This sed command replaces #undef with comments. This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >> conftest.vals <<\EOF
+EOF
+
+# Break up conftest.vals because some shells have a limit on
+# the size of here documents, and old seds have small limits too.
+
+rm -f conftest.tail
+while :
+do
+ ac_lines=`grep -c . conftest.vals`
+ # grep -c gives empty output for an empty file on some AIX systems.
+ if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
+ # Write a limited-size here document to conftest.frag.
+ echo ' cat > conftest.frag <<CEOF' >> $CONFIG_STATUS
+ sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS
+ echo 'CEOF
+ sed -f conftest.frag conftest.in > conftest.out
+ rm -f conftest.in
+ mv conftest.out conftest.in
+' >> $CONFIG_STATUS
+ sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail
+ rm -f conftest.vals
+ mv conftest.tail conftest.vals
+done
+rm -f conftest.vals
+
+cat >> $CONFIG_STATUS <<\EOF
+ rm -f conftest.frag conftest.h
+ echo "/* $ac_file. Generated automatically by configure. */" > conftest.h
+ cat conftest.in >> conftest.h
+ rm -f conftest.in
+ if cmp -s $ac_file conftest.h 2>/dev/null; then
+ echo "$ac_file is unchanged"
+ rm -f conftest.h
+ else
+ # Remove last slash and all that follows it. Not all systems have dirname.
+ ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+ if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+ # The file is in a subdirectory.
+ test ! -d "$ac_dir" && mkdir "$ac_dir"
+ fi
+ rm -f $ac_file
+ mv conftest.h $ac_file
+ fi
+fi; done
+
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+
+exit 0
+EOF
+chmod +x $CONFIG_STATUS
+rm -fr confdefs* $ac_clean_files
+test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
+
diff --git a/osframework/source/ImageLib/jpeg/djpeg.1 b/osframework/source/ImageLib/jpeg/djpeg.1
new file mode 100644
index 0000000..a1a335a
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/djpeg.1
@@ -0,0 +1,253 @@
+.TH DJPEG 1 "22 August 1997"
+.SH NAME
+djpeg \- decompress a JPEG file to an image file
+.SH SYNOPSIS
+.B djpeg
+[
+.I options
+]
+[
+.I filename
+]
+.LP
+.SH DESCRIPTION
+.LP
+.B djpeg
+decompresses the named JPEG file, or the standard input if no file is named,
+and produces an image file on the standard output. PBMPLUS (PPM/PGM), BMP,
+GIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected.
+(RLE is supported only if the URT library is available.)
+.SH OPTIONS
+All switch names may be abbreviated; for example,
+.B \-grayscale
+may be written
+.B \-gray
+or
+.BR \-gr .
+Most of the "basic" switches can be abbreviated to as little as one letter.
+Upper and lower case are equivalent (thus
+.B \-BMP
+is the same as
+.BR \-bmp ).
+British spellings are also accepted (e.g.,
+.BR \-greyscale ),
+though for brevity these are not mentioned below.
+.PP
+The basic switches are:
+.TP
+.BI \-colors " N"
+Reduce image to at most N colors. This reduces the number of colors used in
+the output image, so that it can be displayed on a colormapped display or
+stored in a colormapped file format. For example, if you have an 8-bit
+display, you'd need to reduce to 256 or fewer colors.
+.TP
+.BI \-quantize " N"
+Same as
+.BR \-colors .
+.B \-colors
+is the recommended name,
+.B \-quantize
+is provided only for backwards compatibility.
+.TP
+.B \-fast
+Select recommended processing options for fast, low quality output. (The
+default options are chosen for highest quality output.) Currently, this is
+equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR.
+.TP
+.B \-grayscale
+Force gray-scale output even if JPEG file is color. Useful for viewing on
+monochrome displays; also,
+.B djpeg
+runs noticeably faster in this mode.
+.TP
+.BI \-scale " M/N"
+Scale the output image by a factor M/N. Currently the scale factor must be
+1/1, 1/2, 1/4, or 1/8. Scaling is handy if the image is larger than your
+screen; also,
+.B djpeg
+runs much faster when scaling down the output.
+.TP
+.B \-bmp
+Select BMP output format (Windows flavor). 8-bit colormapped format is
+emitted if
+.B \-colors
+or
+.B \-grayscale
+is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color
+format is emitted.
+.TP
+.B \-gif
+Select GIF output format. Since GIF does not support more than 256 colors,
+.B \-colors 256
+is assumed (unless you specify a smaller number of colors).
+.TP
+.B \-os2
+Select BMP output format (OS/2 1.x flavor). 8-bit colormapped format is
+emitted if
+.B \-colors
+or
+.B \-grayscale
+is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color
+format is emitted.
+.TP
+.B \-pnm
+Select PBMPLUS (PPM/PGM) output format (this is the default format).
+PGM is emitted if the JPEG file is gray-scale or if
+.B \-grayscale
+is specified; otherwise PPM is emitted.
+.TP
+.B \-rle
+Select RLE output format. (Requires URT library.)
+.TP
+.B \-targa
+Select Targa output format. Gray-scale format is emitted if the JPEG file is
+gray-scale or if
+.B \-grayscale
+is specified; otherwise, colormapped format is emitted if
+.B \-colors
+is specified; otherwise, 24-bit full-color format is emitted.
+.PP
+Switches for advanced users:
+.TP
+.B \-dct int
+Use integer DCT method (default).
+.TP
+.B \-dct fast
+Use fast integer DCT (less accurate).
+.TP
+.B \-dct float
+Use floating-point DCT method.
+The float method is very slightly more accurate than the int method, but is
+much slower unless your machine has very fast floating-point hardware. Also
+note that results of the floating-point method may vary slightly across
+machines, while the integer methods should give the same results everywhere.
+The fast integer method is much less accurate than the other two.
+.TP
+.B \-dither fs
+Use Floyd-Steinberg dithering in color quantization.
+.TP
+.B \-dither ordered
+Use ordered dithering in color quantization.
+.TP
+.B \-dither none
+Do not use dithering in color quantization.
+By default, Floyd-Steinberg dithering is applied when quantizing colors; this
+is slow but usually produces the best results. Ordered dither is a compromise
+between speed and quality; no dithering is fast but usually looks awful. Note
+that these switches have no effect unless color quantization is being done.
+Ordered dither is only available in
+.B \-onepass
+mode.
+.TP
+.BI \-map " file"
+Quantize to the colors used in the specified image file. This is useful for
+producing multiple files with identical color maps, or for forcing a
+predefined set of colors to be used. The
+.I file
+must be a GIF or PPM file. This option overrides
+.B \-colors
+and
+.BR \-onepass .
+.TP
+.B \-nosmooth
+Use a faster, lower-quality upsampling routine.
+.TP
+.B \-onepass
+Use one-pass instead of two-pass color quantization. The one-pass method is
+faster and needs less memory, but it produces a lower-quality image.
+.B \-onepass
+is ignored unless you also say
+.B \-colors
+.IR N .
+Also, the one-pass method is always used for gray-scale output (the two-pass
+method is no improvement then).
+.TP
+.BI \-maxmemory " N"
+Set limit for amount of memory to use in processing large images. Value is
+in thousands of bytes, or millions of bytes if "M" is attached to the
+number. For example,
+.B \-max 4m
+selects 4000000 bytes. If more space is needed, temporary files will be used.
+.TP
+.BI \-outfile " name"
+Send output image to the named file, not to standard output.
+.TP
+.B \-verbose
+Enable debug printout. More
+.BR \-v 's
+give more output. Also, version information is printed at startup.
+.TP
+.B \-debug
+Same as
+.BR \-verbose .
+.SH EXAMPLES
+.LP
+This example decompresses the JPEG file foo.jpg, quantizes it to
+256 colors, and saves the output in 8-bit BMP format in foo.bmp:
+.IP
+.B djpeg \-colors 256 \-bmp
+.I foo.jpg
+.B >
+.I foo.bmp
+.SH HINTS
+To get a quick preview of an image, use the
+.B \-grayscale
+and/or
+.B \-scale
+switches.
+.B \-grayscale \-scale 1/8
+is the fastest case.
+.PP
+Several options are available that trade off image quality to gain speed.
+.B \-fast
+turns on the recommended settings.
+.PP
+.B \-dct fast
+and/or
+.B \-nosmooth
+gain speed at a small sacrifice in quality.
+When producing a color-quantized image,
+.B \-onepass \-dither ordered
+is fast but much lower quality than the default behavior.
+.B \-dither none
+may give acceptable results in two-pass mode, but is seldom tolerable in
+one-pass mode.
+.PP
+If you are fortunate enough to have very fast floating point hardware,
+\fB\-dct float\fR may be even faster than \fB\-dct fast\fR. But on most
+machines \fB\-dct float\fR is slower than \fB\-dct int\fR; in this case it is
+not worth using, because its theoretical accuracy advantage is too small to be
+significant in practice.
+.SH ENVIRONMENT
+.TP
+.B JPEGMEM
+If this environment variable is set, its value is the default memory limit.
+The value is specified as described for the
+.B \-maxmemory
+switch.
+.B JPEGMEM
+overrides the default value specified when the program was compiled, and
+itself is overridden by an explicit
+.BR \-maxmemory .
+.SH SEE ALSO
+.BR cjpeg (1),
+.BR jpegtran (1),
+.BR rdjpgcom (1),
+.BR wrjpgcom (1)
+.br
+.BR ppm (5),
+.BR pgm (5)
+.br
+Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
+Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
+.SH AUTHOR
+Independent JPEG Group
+.SH BUGS
+Arithmetic coding is not supported for legal reasons.
+.PP
+To avoid the Unisys LZW patent,
+.B djpeg
+produces uncompressed GIF files. These are larger than they should be, but
+are readable by standard GIF decoders.
+.PP
+Still not as fast as we'd like.
diff --git a/osframework/source/ImageLib/jpeg/djpeg.c b/osframework/source/ImageLib/jpeg/djpeg.c
new file mode 100644
index 0000000..a63523c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/djpeg.c
@@ -0,0 +1,616 @@
+/*
+ * djpeg.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for the JPEG decompressor.
+ * It should work on any system with Unix- or MS-DOS-style command lines.
+ *
+ * Two different command line styles are permitted, depending on the
+ * compile-time switch TWO_FILE_COMMANDLINE:
+ * djpeg [options] inputfile outputfile
+ * djpeg [options] [inputfile]
+ * In the second style, output is always to standard output, which you'd
+ * normally redirect to a file or pipe to some other program. Input is
+ * either from a named file or from standard input (typically redirected).
+ * The second style is convenient on Unix but is unhelpful on systems that
+ * don't support pipes. Also, you MUST use the first style if your system
+ * doesn't do binary I/O to stdin/stdout.
+ * To simplify script writing, the "-outfile" switch is provided. The syntax
+ * djpeg [options] -outfile outputfile inputfile
+ * works regardless of which command line style is used.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "jversion.h" /* for version message */
+
+#include <ctype.h> /* to declare isprint() */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/* Create the add-on message string table. */
+
+#define JMESSAGE(code,string) string ,
+
+static const char * const cdjpeg_message_table[] = {
+#include "cderror.h"
+ NULL
+};
+
+
+/*
+ * This list defines the known output image formats
+ * (not all of which need be supported by a given version).
+ * You can change the default output format by defining DEFAULT_FMT;
+ * indeed, you had better do so if you undefine PPM_SUPPORTED.
+ */
+
+typedef enum {
+ FMT_BMP, /* BMP format (Windows flavor) */
+ FMT_GIF, /* GIF format */
+ FMT_OS2, /* BMP format (OS/2 flavor) */
+ FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
+ FMT_RLE, /* RLE format */
+ FMT_TARGA, /* Targa format */
+ FMT_TIFF /* TIFF format */
+} IMAGE_FORMATS;
+
+#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
+#define DEFAULT_FMT FMT_PPM
+#endif
+
+static IMAGE_FORMATS requested_fmt;
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
+ fprintf(stderr, " -fast Fast, low-quality processing\n");
+ fprintf(stderr, " -grayscale Force grayscale output\n");
+#ifdef IDCT_SCALING_SUPPORTED
+ fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
+#endif
+#ifdef BMP_SUPPORTED
+ fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
+ (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
+#endif
+#ifdef GIF_SUPPORTED
+ fprintf(stderr, " -gif Select GIF output format%s\n",
+ (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
+#endif
+#ifdef BMP_SUPPORTED
+ fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
+ (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
+#endif
+#ifdef PPM_SUPPORTED
+ fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
+ (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
+#endif
+#ifdef RLE_SUPPORTED
+ fprintf(stderr, " -rle Select Utah RLE output format%s\n",
+ (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
+#endif
+#ifdef TARGA_SUPPORTED
+ fprintf(stderr, " -targa Select Targa output format%s\n",
+ (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
+#endif
+ fprintf(stderr, "Switches for advanced users:\n");
+#ifdef DCT_ISLOW_SUPPORTED
+ fprintf(stderr, " -dct int Use integer DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
+#endif
+ fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
+ fprintf(stderr, " -dither none Don't use dithering in quantization\n");
+ fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
+#ifdef QUANT_2PASS_SUPPORTED
+ fprintf(stderr, " -map FILE Map to colors used in named image file\n");
+#endif
+ fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
+#ifdef QUANT_1PASS_SUPPORTED
+ fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");
+#endif
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(int)
+parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+
+ /* Set up default JPEG parameters. */
+ requested_fmt = DEFAULT_FMT; /* set default output file format */
+ outfilename = NULL;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "bmp", 1)) {
+ /* BMP output format. */
+ requested_fmt = FMT_BMP;
+
+ } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
+ keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
+ /* Do color quantization. */
+ int val;
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d", &val) != 1)
+ usage();
+ cinfo->desired_number_of_colors = val;
+ cinfo->quantize_colors = TRUE;
+
+ } else if (keymatch(arg, "dct", 2)) {
+ /* Select IDCT algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "int", 1)) {
+ cinfo->dct_method = JDCT_ISLOW;
+ } else if (keymatch(argv[argn], "fast", 2)) {
+ cinfo->dct_method = JDCT_IFAST;
+ } else if (keymatch(argv[argn], "float", 2)) {
+ cinfo->dct_method = JDCT_FLOAT;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "dither", 2)) {
+ /* Select dithering algorithm. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "fs", 2)) {
+ cinfo->dither_mode = JDITHER_FS;
+ } else if (keymatch(argv[argn], "none", 2)) {
+ cinfo->dither_mode = JDITHER_NONE;
+ } else if (keymatch(argv[argn], "ordered", 2)) {
+ cinfo->dither_mode = JDITHER_ORDERED;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "fast", 1)) {
+ /* Select recommended processing options for quick-and-dirty output. */
+ cinfo->two_pass_quantize = FALSE;
+ cinfo->dither_mode = JDITHER_ORDERED;
+ if (! cinfo->quantize_colors) /* don't override an earlier -colors */
+ cinfo->desired_number_of_colors = 216;
+ cinfo->dct_method = JDCT_FASTEST;
+ cinfo->do_fancy_upsampling = FALSE;
+
+ } else if (keymatch(arg, "gif", 1)) {
+ /* GIF output format. */
+ requested_fmt = FMT_GIF;
+
+ } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
+ /* Force monochrome output. */
+ cinfo->out_color_space = JCS_GRAYSCALE;
+
+ } else if (keymatch(arg, "map", 3)) {
+ /* Quantize to a color map taken from an input file. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (for_real) { /* too expensive to do twice! */
+#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
+ FILE * mapfile;
+
+ if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ read_color_map(cinfo, mapfile);
+ fclose(mapfile);
+ cinfo->quantize_colors = TRUE;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ }
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "nosmooth", 3)) {
+ /* Suppress fancy upsampling */
+ cinfo->do_fancy_upsampling = FALSE;
+
+ } else if (keymatch(arg, "onepass", 3)) {
+ /* Use fast one-pass quantization. */
+ cinfo->two_pass_quantize = FALSE;
+
+ } else if (keymatch(arg, "os2", 3)) {
+ /* BMP output format (OS/2 flavor). */
+ requested_fmt = FMT_OS2;
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
+ /* PPM/PGM output format. */
+ requested_fmt = FMT_PPM;
+
+ } else if (keymatch(arg, "rle", 1)) {
+ /* RLE output format. */
+ requested_fmt = FMT_RLE;
+
+ } else if (keymatch(arg, "scale", 1)) {
+ /* Scale the output image by a fraction M/N. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d/%d",
+ &cinfo->scale_num, &cinfo->scale_denom) != 2)
+ usage();
+
+ } else if (keymatch(arg, "targa", 1)) {
+ /* Targa output format. */
+ requested_fmt = FMT_TARGA;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * Marker processor for COM and interesting APPn markers.
+ * This replaces the library's built-in processor, which just skips the marker.
+ * We want to print out the marker as text, to the extent possible.
+ * Note this code relies on a non-suspending data source.
+ */
+
+LOCAL(unsigned int)
+jpeg_getc (j_decompress_ptr cinfo)
+/* Read next byte */
+{
+ struct jpeg_source_mgr * datasrc = cinfo->src;
+
+ if (datasrc->bytes_in_buffer == 0) {
+ if (! (*datasrc->fill_input_buffer) (cinfo))
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
+ }
+ datasrc->bytes_in_buffer--;
+ return GETJOCTET(*datasrc->next_input_byte++);
+}
+
+
+METHODDEF(boolean)
+print_text_marker (j_decompress_ptr cinfo)
+{
+ boolean traceit = (cinfo->err->trace_level >= 1);
+ INT32 length;
+ unsigned int ch;
+ unsigned int lastch = 0;
+
+ length = jpeg_getc(cinfo) << 8;
+ length += jpeg_getc(cinfo);
+ length -= 2; /* discount the length word itself */
+
+ if (traceit) {
+ if (cinfo->unread_marker == JPEG_COM)
+ fprintf(stderr, "Comment, length %ld:\n", (long) length);
+ else /* assume it is an APPn otherwise */
+ fprintf(stderr, "APP%d, length %ld:\n",
+ cinfo->unread_marker - JPEG_APP0, (long) length);
+ }
+
+ while (--length >= 0) {
+ ch = jpeg_getc(cinfo);
+ if (traceit) {
+ /* Emit the character in a readable form.
+ * Nonprintables are converted to \nnn form,
+ * while \ is converted to \\.
+ * Newlines in CR, CR/LF, or LF form will be printed as one newline.
+ */
+ if (ch == '\r') {
+ fprintf(stderr, "\n");
+ } else if (ch == '\n') {
+ if (lastch != '\r')
+ fprintf(stderr, "\n");
+ } else if (ch == '\\') {
+ fprintf(stderr, "\\\\");
+ } else if (isprint(ch)) {
+ putc(ch, stderr);
+ } else {
+ fprintf(stderr, "\\%03o", ch);
+ }
+ lastch = ch;
+ }
+ }
+
+ if (traceit)
+ fprintf(stderr, "\n");
+
+ return TRUE;
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ int file_index;
+ djpeg_dest_ptr dest_mgr = NULL;
+ FILE * input_file;
+ FILE * output_file;
+ JDIMENSION num_scanlines;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "djpeg"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG decompression object with default error handling. */
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_decompress(&cinfo);
+ /* Add some application-specific error messages (from cderror.h) */
+ jerr.addon_message_table = cdjpeg_message_table;
+ jerr.first_addon_message = JMSG_FIRSTADDONCODE;
+ jerr.last_addon_message = JMSG_LASTADDONCODE;
+
+ /* Insert custom marker processor for COM and APP12.
+ * APP12 is used by some digital camera makers for textual info,
+ * so we provide the ability to display it as text.
+ * If you like, additional APPn marker types can be selected for display,
+ * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
+ */
+ jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
+ jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
+
+ /* Now safe to enable signal catcher. */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &cinfo);
+#endif
+
+ /* Scan command line to find file names. */
+ /* It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are ignored; we will rescan the switches after opening
+ * the input file.
+ * (Exception: tracing level set here controls verbosity for COM markers
+ * found during jpeg_read_header...)
+ */
+
+ file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &cinfo, &progress);
+#endif
+
+ /* Specify data source for decompression */
+ jpeg_stdio_src(&cinfo, input_file);
+
+ /* Read file header, set default decompression parameters */
+ (void) jpeg_read_header(&cinfo, TRUE);
+
+ /* Adjust default decompression parameters by re-parsing the options */
+ file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
+
+ /* Initialize the output module now to let it override any crucial
+ * option settings (for instance, GIF wants to force color quantization).
+ */
+ switch (requested_fmt) {
+#ifdef BMP_SUPPORTED
+ case FMT_BMP:
+ dest_mgr = jinit_write_bmp(&cinfo, FALSE);
+ break;
+ case FMT_OS2:
+ dest_mgr = jinit_write_bmp(&cinfo, TRUE);
+ break;
+#endif
+#ifdef GIF_SUPPORTED
+ case FMT_GIF:
+ dest_mgr = jinit_write_gif(&cinfo);
+ break;
+#endif
+#ifdef PPM_SUPPORTED
+ case FMT_PPM:
+ dest_mgr = jinit_write_ppm(&cinfo);
+ break;
+#endif
+#ifdef RLE_SUPPORTED
+ case FMT_RLE:
+ dest_mgr = jinit_write_rle(&cinfo);
+ break;
+#endif
+#ifdef TARGA_SUPPORTED
+ case FMT_TARGA:
+ dest_mgr = jinit_write_targa(&cinfo);
+ break;
+#endif
+ default:
+ ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
+ break;
+ }
+ dest_mgr->output_file = output_file;
+
+ /* Start decompressor */
+ (void) jpeg_start_decompress(&cinfo);
+
+ /* Write output file header */
+ (*dest_mgr->start_output) (&cinfo, dest_mgr);
+
+ /* Process data */
+ while (cinfo.output_scanline < cinfo.output_height) {
+ num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
+ dest_mgr->buffer_height);
+ (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
+ }
+
+#ifdef PROGRESS_REPORT
+ /* Hack: count final pass as done in case finish_output does an extra pass.
+ * The library won't have updated completed_passes.
+ */
+ progress.pub.completed_passes = progress.pub.total_passes;
+#endif
+
+ /* Finish decompression and release memory.
+ * I must do it in this order because output module has allocated memory
+ * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
+ */
+ (*dest_mgr->finish_output) (&cinfo, dest_mgr);
+ (void) jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &cinfo);
+#endif
+
+ /* All done. */
+ exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/osframework/source/ImageLib/jpeg/example.c b/osframework/source/ImageLib/jpeg/example.c
new file mode 100644
index 0000000..9dcbd7d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/example.c
@@ -0,0 +1,433 @@
+/*
+ * example.c
+ *
+ * This file illustrates how to use the IJG code as a subroutine library
+ * to read or write JPEG image files. You should look at this code in
+ * conjunction with the documentation file libjpeg.doc.
+ *
+ * This code will not do anything useful as-is, but it may be helpful as a
+ * skeleton for constructing routines that call the JPEG library.
+ *
+ * We present these routines in the same coding style used in the JPEG code
+ * (ANSI function definitions, etc); but you are of course free to code your
+ * routines in a different style if you prefer.
+ */
+
+#include <stdio.h>
+
+/*
+ * Include file for users of JPEG library.
+ * You will need to have included system headers that define at least
+ * the typedefs FILE and size_t before you can include jpeglib.h.
+ * (stdio.h is sufficient on ANSI-conforming systems.)
+ * You may also wish to include "jerror.h".
+ */
+
+#include "jpeglib.h"
+
+/*
+ * <setjmp.h> is used for the optional error recovery mechanism shown in
+ * the second part of the example.
+ */
+
+#include <setjmp.h>
+
+
+
+/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
+
+/* This half of the example shows how to feed data into the JPEG compressor.
+ * We present a minimal version that does not worry about refinements such
+ * as error recovery (the JPEG code will just exit() if it gets an error).
+ */
+
+
+/*
+ * IMAGE DATA FORMATS:
+ *
+ * The standard input image format is a rectangular array of pixels, with
+ * each pixel having the same number of "component" values (color channels).
+ * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
+ * If you are working with color data, then the color values for each pixel
+ * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
+ * RGB color.
+ *
+ * For this example, we'll assume that this data structure matches the way
+ * our application has stored the image in memory, so we can just pass a
+ * pointer to our image buffer. In particular, let's say that the image is
+ * RGB color and is described by:
+ */
+
+extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
+extern int image_height; /* Number of rows in image */
+extern int image_width; /* Number of columns in image */
+
+
+/*
+ * Sample routine for JPEG compression. We assume that the target file name
+ * and a compression quality factor are passed in.
+ */
+
+GLOBAL(void)
+write_JPEG_file (char * filename, int quality)
+{
+ /* This struct contains the JPEG compression parameters and pointers to
+ * working space (which is allocated as needed by the JPEG library).
+ * It is possible to have several such structures, representing multiple
+ * compression/decompression processes, in existence at once. We refer
+ * to any one struct (and its associated working data) as a "JPEG object".
+ */
+ struct jpeg_compress_struct cinfo;
+ /* This struct represents a JPEG error handler. It is declared separately
+ * because applications often want to supply a specialized error handler
+ * (see the second half of this file for an example). But here we just
+ * take the easy way out and use the standard error handler, which will
+ * print a message on stderr and call exit() if compression fails.
+ * Note that this struct must live as long as the main JPEG parameter
+ * struct, to avoid dangling-pointer problems.
+ */
+ struct jpeg_error_mgr jerr;
+ /* More stuff */
+ FILE * outfile; /* target file */
+ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
+ int row_stride; /* physical row width in image buffer */
+
+ /* Step 1: allocate and initialize JPEG compression object */
+
+ /* We have to set up the error handler first, in case the initialization
+ * step fails. (Unlikely, but it could happen if you are out of memory.)
+ * This routine fills in the contents of struct jerr, and returns jerr's
+ * address which we place into the link field in cinfo.
+ */
+ cinfo.err = jpeg_std_error(&jerr);
+ /* Now we can initialize the JPEG compression object. */
+ jpeg_create_compress(&cinfo);
+
+ /* Step 2: specify data destination (eg, a file) */
+ /* Note: steps 2 and 3 can be done in either order. */
+
+ /* Here we use the library-supplied code to send compressed data to a
+ * stdio stream. You can also write your own code to do something else.
+ * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
+ * requires it in order to write binary files.
+ */
+ if ((outfile = fopen(filename, "wb")) == NULL) {
+ fprintf(stderr, "can't open %s\n", filename);
+ exit(1);
+ }
+ jpeg_stdio_dest(&cinfo, outfile);
+
+ /* Step 3: set parameters for compression */
+
+ /* First we supply a description of the input image.
+ * Four fields of the cinfo struct must be filled in:
+ */
+ cinfo.image_width = image_width; /* image width and height, in pixels */
+ cinfo.image_height = image_height;
+ cinfo.input_components = 3; /* # of color components per pixel */
+ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
+ /* Now use the library's routine to set default compression parameters.
+ * (You must set at least cinfo.in_color_space before calling this,
+ * since the defaults depend on the source color space.)
+ */
+ jpeg_set_defaults(&cinfo);
+ /* Now you can set any non-default parameters you wish to.
+ * Here we just illustrate the use of quality (quantization table) scaling:
+ */
+ jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
+
+ /* Step 4: Start compressor */
+
+ /* TRUE ensures that we will write a complete interchange-JPEG file.
+ * Pass TRUE unless you are very sure of what you're doing.
+ */
+ jpeg_start_compress(&cinfo, TRUE);
+
+ /* Step 5: while (scan lines remain to be written) */
+ /* jpeg_write_scanlines(...); */
+
+ /* Here we use the library's state variable cinfo.next_scanline as the
+ * loop counter, so that we don't have to keep track ourselves.
+ * To keep things simple, we pass one scanline per call; you can pass
+ * more if you wish, though.
+ */
+ row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
+
+ while (cinfo.next_scanline < cinfo.image_height) {
+ /* jpeg_write_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could pass
+ * more than one scanline at a time if that's more convenient.
+ */
+ row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
+ (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
+ }
+
+ /* Step 6: Finish compression */
+
+ jpeg_finish_compress(&cinfo);
+ /* After finish_compress, we can close the output file. */
+ fclose(outfile);
+
+ /* Step 7: release JPEG compression object */
+
+ /* This is an important step since it will release a good deal of memory. */
+ jpeg_destroy_compress(&cinfo);
+
+ /* And we're done! */
+}
+
+
+/*
+ * SOME FINE POINTS:
+ *
+ * In the above loop, we ignored the return value of jpeg_write_scanlines,
+ * which is the number of scanlines actually written. We could get away
+ * with this because we were only relying on the value of cinfo.next_scanline,
+ * which will be incremented correctly. If you maintain additional loop
+ * variables then you should be careful to increment them properly.
+ * Actually, for output to a stdio stream you needn't worry, because
+ * then jpeg_write_scanlines will write all the lines passed (or else exit
+ * with a fatal error). Partial writes can only occur if you use a data
+ * destination module that can demand suspension of the compressor.
+ * (If you don't know what that's for, you don't need it.)
+ *
+ * If the compressor requires full-image buffers (for entropy-coding
+ * optimization or a multi-scan JPEG file), it will create temporary
+ * files for anything that doesn't fit within the maximum-memory setting.
+ * (Note that temp files are NOT needed if you use the default parameters.)
+ * On some systems you may need to set up a signal handler to ensure that
+ * temporary files are deleted if the program is interrupted. See libjpeg.doc.
+ *
+ * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
+ * files to be compatible with everyone else's. If you cannot readily read
+ * your data in that order, you'll need an intermediate array to hold the
+ * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
+ * source data using the JPEG code's internal virtual-array mechanisms.
+ */
+
+
+
+/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
+
+/* This half of the example shows how to read data from the JPEG decompressor.
+ * It's a bit more refined than the above, in that we show:
+ * (a) how to modify the JPEG library's standard error-reporting behavior;
+ * (b) how to allocate workspace using the library's memory manager.
+ *
+ * Just to make this example a little different from the first one, we'll
+ * assume that we do not intend to put the whole image into an in-memory
+ * buffer, but to send it line-by-line someplace else. We need a one-
+ * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
+ * memory manager allocate it for us. This approach is actually quite useful
+ * because we don't need to remember to deallocate the buffer separately: it
+ * will go away automatically when the JPEG object is cleaned up.
+ */
+
+
+/*
+ * ERROR HANDLING:
+ *
+ * The JPEG library's standard error handler (jerror.c) is divided into
+ * several "methods" which you can override individually. This lets you
+ * adjust the behavior without duplicating a lot of code, which you might
+ * have to update with each future release.
+ *
+ * Our example here shows how to override the "error_exit" method so that
+ * control is returned to the library's caller when a fatal error occurs,
+ * rather than calling exit() as the standard error_exit method does.
+ *
+ * We use C's setjmp/longjmp facility to return control. This means that the
+ * routine which calls the JPEG library must first execute a setjmp() call to
+ * establish the return point. We want the replacement error_exit to do a
+ * longjmp(). But we need to make the setjmp buffer accessible to the
+ * error_exit routine. To do this, we make a private extension of the
+ * standard JPEG error handler object. (If we were using C++, we'd say we
+ * were making a subclass of the regular error handler.)
+ *
+ * Here's the extended error handler struct:
+ */
+
+struct my_error_mgr {
+ struct jpeg_error_mgr pub; /* "public" fields */
+
+ jmp_buf setjmp_buffer; /* for return to caller */
+};
+
+typedef struct my_error_mgr * my_error_ptr;
+
+/*
+ * Here's the routine that will replace the standard error_exit method:
+ */
+
+METHODDEF(void)
+my_error_exit (j_common_ptr cinfo)
+{
+ /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
+ my_error_ptr myerr = (my_error_ptr) cinfo->err;
+
+ /* Always display the message. */
+ /* We could postpone this until after returning, if we chose. */
+ (*cinfo->err->output_message) (cinfo);
+
+ /* Return control to the setjmp point */
+ longjmp(myerr->setjmp_buffer, 1);
+}
+
+
+/*
+ * Sample routine for JPEG decompression. We assume that the source file name
+ * is passed in. We want to return 1 on success, 0 on error.
+ */
+
+
+GLOBAL(int)
+read_JPEG_file (char * filename)
+{
+ /* This struct contains the JPEG decompression parameters and pointers to
+ * working space (which is allocated as needed by the JPEG library).
+ */
+ struct jpeg_decompress_struct cinfo;
+ /* We use our private extension JPEG error handler.
+ * Note that this struct must live as long as the main JPEG parameter
+ * struct, to avoid dangling-pointer problems.
+ */
+ struct my_error_mgr jerr;
+ /* More stuff */
+ FILE * infile; /* source file */
+ JSAMPARRAY buffer; /* Output row buffer */
+ int row_stride; /* physical row width in output buffer */
+
+ /* In this example we want to open the input file before doing anything else,
+ * so that the setjmp() error recovery below can assume the file is open.
+ * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
+ * requires it in order to read binary files.
+ */
+
+ if ((infile = fopen(filename, "rb")) == NULL) {
+ fprintf(stderr, "can't open %s\n", filename);
+ return 0;
+ }
+
+ /* Step 1: allocate and initialize JPEG decompression object */
+
+ /* We set up the normal JPEG error routines, then override error_exit. */
+ cinfo.err = jpeg_std_error(&jerr.pub);
+ jerr.pub.error_exit = my_error_exit;
+ /* Establish the setjmp return context for my_error_exit to use. */
+ if (setjmp(jerr.setjmp_buffer)) {
+ /* If we get here, the JPEG code has signaled an error.
+ * We need to clean up the JPEG object, close the input file, and return.
+ */
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return 0;
+ }
+ /* Now we can initialize the JPEG decompression object. */
+ jpeg_create_decompress(&cinfo);
+
+ /* Step 2: specify data source (eg, a file) */
+
+ jpeg_stdio_src(&cinfo, infile);
+
+ /* Step 3: read file parameters with jpeg_read_header() */
+
+ (void) jpeg_read_header(&cinfo, TRUE);
+ /* We can ignore the return value from jpeg_read_header since
+ * (a) suspension is not possible with the stdio data source, and
+ * (b) we passed TRUE to reject a tables-only JPEG file as an error.
+ * See libjpeg.doc for more info.
+ */
+
+ /* Step 4: set parameters for decompression */
+
+ /* In this example, we don't need to change any of the defaults set by
+ * jpeg_read_header(), so we do nothing here.
+ */
+
+ /* Step 5: Start decompressor */
+
+ (void) jpeg_start_decompress(&cinfo);
+ /* We can ignore the return value since suspension is not possible
+ * with the stdio data source.
+ */
+
+ /* We may need to do some setup of our own at this point before reading
+ * the data. After jpeg_start_decompress() we have the correct scaled
+ * output image dimensions available, as well as the output colormap
+ * if we asked for color quantization.
+ * In this example, we need to make an output work buffer of the right size.
+ */
+ /* JSAMPLEs per row in output buffer */
+ row_stride = cinfo.output_width * cinfo.output_components;
+ /* Make a one-row-high sample array that will go away when done with image */
+ buffer = (*cinfo.mem->alloc_sarray)
+ ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
+
+ /* Step 6: while (scan lines remain to be read) */
+ /* jpeg_read_scanlines(...); */
+
+ /* Here we use the library's state variable cinfo.output_scanline as the
+ * loop counter, so that we don't have to keep track ourselves.
+ */
+ while (cinfo.output_scanline < cinfo.output_height) {
+ /* jpeg_read_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could ask for
+ * more than one scanline at a time if that's more convenient.
+ */
+ (void) jpeg_read_scanlines(&cinfo, buffer, 1);
+ /* Assume put_scanline_someplace wants a pointer and sample count. */
+ put_scanline_someplace(buffer[0], row_stride);
+ }
+
+ /* Step 7: Finish decompression */
+
+ (void) jpeg_finish_decompress(&cinfo);
+ /* We can ignore the return value since suspension is not possible
+ * with the stdio data source.
+ */
+
+ /* Step 8: Release JPEG decompression object */
+
+ /* This is an important step since it will release a good deal of memory. */
+ jpeg_destroy_decompress(&cinfo);
+
+ /* After finish_decompress, we can close the input file.
+ * Here we postpone it until after no more JPEG errors are possible,
+ * so as to simplify the setjmp error logic above. (Actually, I don't
+ * think that jpeg_destroy can do an error exit, but why assume anything...)
+ */
+ fclose(infile);
+
+ /* At this point you may want to check to see whether any corrupt-data
+ * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
+ */
+
+ /* And we're done! */
+ return 1;
+}
+
+
+/*
+ * SOME FINE POINTS:
+ *
+ * In the above code, we ignored the return value of jpeg_read_scanlines,
+ * which is the number of scanlines actually read. We could get away with
+ * this because we asked for only one line at a time and we weren't using
+ * a suspending data source. See libjpeg.doc for more info.
+ *
+ * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
+ * we should have done it beforehand to ensure that the space would be
+ * counted against the JPEG max_memory setting. In some systems the above
+ * code would risk an out-of-memory error. However, in general we don't
+ * know the output image dimensions before jpeg_start_decompress(), unless we
+ * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this.
+ *
+ * Scanlines are returned in the same order as they appear in the JPEG file,
+ * which is standardly top-to-bottom. If you must emit data bottom-to-top,
+ * you can use one of the virtual arrays provided by the JPEG memory manager
+ * to invert the data. See wrbmp.c for an example.
+ *
+ * As with compression, some operating modes may require temporary files.
+ * On some systems you may need to set up a signal handler to ensure that
+ * temporary files are deleted if the program is interrupted. See libjpeg.doc.
+ */
diff --git a/osframework/source/ImageLib/jpeg/install-sh b/osframework/source/ImageLib/jpeg/install-sh
new file mode 100644
index 0000000..082fd7c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/install-sh
@@ -0,0 +1,250 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. M.I.T. makes no representations about the
+# suitability of this software for any purpose. It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch. It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd="$stripprog"
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "install: no input file specified"
+ exit 1
+else
+ true
+fi
+
+if [ x"$dir_arg" != x ]; then
+ dst=$src
+ src=""
+
+ if [ -d $dst ]; then
+ instcmd=:
+ else
+ instcmd=mkdir
+ fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+ if [ -f $src -o -d $src ]
+ then
+ true
+ else
+ echo "install: $src does not exist"
+ exit 1
+ fi
+
+ if [ x"$dst" = x ]
+ then
+ echo "install: no destination specified"
+ exit 1
+ else
+ true
+ fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+ if [ -d $dst ]
+ then
+ dst="$dst"/`basename $src`
+ else
+ true
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+ pathcomp="${pathcomp}${1}"
+ shift
+
+ if [ ! -d "${pathcomp}" ] ;
+ then
+ $mkdirprog "${pathcomp}"
+ else
+ true
+ fi
+
+ pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+ $doit $instcmd $dst &&
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+ if [ x"$transformarg" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ dstfile=`basename $dst $transformbasename |
+ sed $transformarg`$transformbasename
+ fi
+
+# don't allow the sed command to completely eliminate the filename
+
+ if [ x"$dstfile" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ true
+ fi
+
+# Make a temp file name in the proper directory.
+
+ dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+ $doit $instcmd $src $dsttmp &&
+
+ trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing. If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+ $doit $rmcmd -f $dstdir/$dstfile &&
+ $doit $mvcmd $dsttmp $dstdir/$dstfile
+
+fi &&
+
+
+exit 0
diff --git a/osframework/source/ImageLib/jpeg/jcapimin.c b/osframework/source/ImageLib/jpeg/jcapimin.c
new file mode 100644
index 0000000..493af5c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcapimin.c
@@ -0,0 +1,280 @@
+/*
+ * jcapimin.c
+ *
+ * Copyright (C) 1994-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains application interface code for the compression half
+ * of the JPEG library. These are the "minimum" API routines that may be
+ * needed in either the normal full-compression case or the transcoding-only
+ * case.
+ *
+ * Most of the routines intended to be called directly by an application
+ * are in this file or in jcapistd.c. But also see jcparam.c for
+ * parameter-setup helper routines, jcomapi.c for routines shared by
+ * compression and decompression, and jctrans.c for the transcoding case.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Initialization of a JPEG compression object.
+ * The error manager must already be set up (in case memory manager fails).
+ */
+
+GLOBAL(void)
+jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
+{
+ int i;
+
+ /* Guard against version mismatches between library and caller. */
+ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
+ if (version != JPEG_LIB_VERSION)
+ ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
+ if (structsize != SIZEOF(struct jpeg_compress_struct))
+ ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
+ (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
+
+ /* For debugging purposes, we zero the whole master structure.
+ * But the application has already set the err pointer, and may have set
+ * client_data, so we have to save and restore those fields.
+ * Note: if application hasn't set client_data, tools like Purify may
+ * complain here.
+ */
+ {
+ struct jpeg_error_mgr * err = cinfo->err;
+ void * client_data = cinfo->client_data; /* ignore Purify complaint here */
+ MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
+ cinfo->err = err;
+ cinfo->client_data = client_data;
+ }
+ cinfo->is_decompressor = FALSE;
+
+ /* Initialize a memory manager instance for this object */
+ jinit_memory_mgr((j_common_ptr) cinfo);
+
+ /* Zero out pointers to permanent structures. */
+ cinfo->progress = NULL;
+ cinfo->dest = NULL;
+
+ cinfo->comp_info = NULL;
+
+ for (i = 0; i < NUM_QUANT_TBLS; i++)
+ cinfo->quant_tbl_ptrs[i] = NULL;
+
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ cinfo->dc_huff_tbl_ptrs[i] = NULL;
+ cinfo->ac_huff_tbl_ptrs[i] = NULL;
+ }
+
+ cinfo->script_space = NULL;
+
+ cinfo->input_gamma = 1.0; /* in case application forgets */
+
+ /* OK, I'm ready */
+ cinfo->global_state = CSTATE_START;
+}
+
+
+/*
+ * Destruction of a JPEG compression object
+ */
+
+GLOBAL(void)
+jpeg_destroy_compress (j_compress_ptr cinfo)
+{
+ jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
+}
+
+
+/*
+ * Abort processing of a JPEG compression operation,
+ * but don't destroy the object itself.
+ */
+
+GLOBAL(void)
+jpeg_abort_compress (j_compress_ptr cinfo)
+{
+ jpeg_abort((j_common_ptr) cinfo); /* use common routine */
+}
+
+
+/*
+ * Forcibly suppress or un-suppress all quantization and Huffman tables.
+ * Marks all currently defined tables as already written (if suppress)
+ * or not written (if !suppress). This will control whether they get emitted
+ * by a subsequent jpeg_start_compress call.
+ *
+ * This routine is exported for use by applications that want to produce
+ * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
+ * since it is called by jpeg_start_compress, we put it here --- otherwise
+ * jcparam.o would be linked whether the application used it or not.
+ */
+
+GLOBAL(void)
+jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
+{
+ int i;
+ JQUANT_TBL * qtbl;
+ JHUFF_TBL * htbl;
+
+ for (i = 0; i < NUM_QUANT_TBLS; i++) {
+ if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
+ qtbl->sent_table = suppress;
+ }
+
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
+ htbl->sent_table = suppress;
+ if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
+ htbl->sent_table = suppress;
+ }
+}
+
+
+/*
+ * Finish JPEG compression.
+ *
+ * If a multipass operating mode was selected, this may do a great deal of
+ * work including most of the actual output.
+ */
+
+GLOBAL(void)
+jpeg_finish_compress (j_compress_ptr cinfo)
+{
+ JDIMENSION iMCU_row;
+
+ if (cinfo->global_state == CSTATE_SCANNING ||
+ cinfo->global_state == CSTATE_RAW_OK) {
+ /* Terminate first pass */
+ if (cinfo->next_scanline < cinfo->image_height)
+ ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
+ (*cinfo->master->finish_pass) (cinfo);
+ } else if (cinfo->global_state != CSTATE_WRCOEFS)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ /* Perform any remaining passes */
+ while (! cinfo->master->is_last_pass) {
+ (*cinfo->master->prepare_for_pass) (cinfo);
+ for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) iMCU_row;
+ cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+ /* We bypass the main controller and invoke coef controller directly;
+ * all work is being done from the coefficient buffer.
+ */
+ if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
+ }
+ (*cinfo->master->finish_pass) (cinfo);
+ }
+ /* Write EOI, do final cleanup */
+ (*cinfo->marker->write_file_trailer) (cinfo);
+ (*cinfo->dest->term_destination) (cinfo);
+ /* We can use jpeg_abort to release memory and reset global_state */
+ jpeg_abort((j_common_ptr) cinfo);
+}
+
+
+/*
+ * Write a special marker.
+ * This is only recommended for writing COM or APPn markers.
+ * Must be called after jpeg_start_compress() and before
+ * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
+ */
+
+GLOBAL(void)
+jpeg_write_marker (j_compress_ptr cinfo, int marker,
+ const JOCTET *dataptr, unsigned int datalen)
+{
+ JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
+
+ if (cinfo->next_scanline != 0 ||
+ (cinfo->global_state != CSTATE_SCANNING &&
+ cinfo->global_state != CSTATE_RAW_OK &&
+ cinfo->global_state != CSTATE_WRCOEFS))
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
+ write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
+ while (datalen--) {
+ (*write_marker_byte) (cinfo, *dataptr);
+ dataptr++;
+ }
+}
+
+/* Same, but piecemeal. */
+
+GLOBAL(void)
+jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
+{
+ if (cinfo->next_scanline != 0 ||
+ (cinfo->global_state != CSTATE_SCANNING &&
+ cinfo->global_state != CSTATE_RAW_OK &&
+ cinfo->global_state != CSTATE_WRCOEFS))
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
+}
+
+GLOBAL(void)
+jpeg_write_m_byte (j_compress_ptr cinfo, int val)
+{
+ (*cinfo->marker->write_marker_byte) (cinfo, val);
+}
+
+
+/*
+ * Alternate compression function: just write an abbreviated table file.
+ * Before calling this, all parameters and a data destination must be set up.
+ *
+ * To produce a pair of files containing abbreviated tables and abbreviated
+ * image data, one would proceed as follows:
+ *
+ * initialize JPEG object
+ * set JPEG parameters
+ * set destination to table file
+ * jpeg_write_tables(cinfo);
+ * set destination to image file
+ * jpeg_start_compress(cinfo, FALSE);
+ * write data...
+ * jpeg_finish_compress(cinfo);
+ *
+ * jpeg_write_tables has the side effect of marking all tables written
+ * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
+ * will not re-emit the tables unless it is passed write_all_tables=TRUE.
+ */
+
+GLOBAL(void)
+jpeg_write_tables (j_compress_ptr cinfo)
+{
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* (Re)initialize error mgr and destination modules */
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
+ (*cinfo->dest->init_destination) (cinfo);
+ /* Initialize the marker writer ... bit of a crock to do it here. */
+ jinit_marker_writer(cinfo);
+ /* Write them tables! */
+ (*cinfo->marker->write_tables_only) (cinfo);
+ /* And clean up. */
+ (*cinfo->dest->term_destination) (cinfo);
+ /*
+ * In library releases up through v6a, we called jpeg_abort() here to free
+ * any working memory allocated by the destination manager and marker
+ * writer. Some applications had a problem with that: they allocated space
+ * of their own from the library memory manager, and didn't want it to go
+ * away during write_tables. So now we do nothing. This will cause a
+ * memory leak if an app calls write_tables repeatedly without doing a full
+ * compression cycle or otherwise resetting the JPEG object. However, that
+ * seems less bad than unexpectedly freeing memory in the normal case.
+ * An app that prefers the old behavior can call jpeg_abort for itself after
+ * each call to jpeg_write_tables().
+ */
+}
diff --git a/osframework/source/ImageLib/jpeg/jcapistd.c b/osframework/source/ImageLib/jpeg/jcapistd.c
new file mode 100644
index 0000000..fed66ca
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcapistd.c
@@ -0,0 +1,161 @@
+/*
+ * jcapistd.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains application interface code for the compression half
+ * of the JPEG library. These are the "standard" API routines that are
+ * used in the normal full-compression case. They are not used by a
+ * transcoding-only application. Note that if an application links in
+ * jpeg_start_compress, it will end up linking in the entire compressor.
+ * We thus must separate this file from jcapimin.c to avoid linking the
+ * whole compression library into a transcoder.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Compression initialization.
+ * Before calling this, all parameters and a data destination must be set up.
+ *
+ * We require a write_all_tables parameter as a failsafe check when writing
+ * multiple datastreams from the same compression object. Since prior runs
+ * will have left all the tables marked sent_table=TRUE, a subsequent run
+ * would emit an abbreviated stream (no tables) by default. This may be what
+ * is wanted, but for safety's sake it should not be the default behavior:
+ * programmers should have to make a deliberate choice to emit abbreviated
+ * images. Therefore the documentation and examples should encourage people
+ * to pass write_all_tables=TRUE; then it will take active thought to do the
+ * wrong thing.
+ */
+
+GLOBAL(void)
+jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
+{
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ if (write_all_tables)
+ jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
+
+ /* (Re)initialize error mgr and destination modules */
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
+ (*cinfo->dest->init_destination) (cinfo);
+ /* Perform master selection of active modules */
+ jinit_compress_master(cinfo);
+ /* Set up for the first pass */
+ (*cinfo->master->prepare_for_pass) (cinfo);
+ /* Ready for application to drive first pass through jpeg_write_scanlines
+ * or jpeg_write_raw_data.
+ */
+ cinfo->next_scanline = 0;
+ cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
+}
+
+
+/*
+ * Write some scanlines of data to the JPEG compressor.
+ *
+ * The return value will be the number of lines actually written.
+ * This should be less than the supplied num_lines only in case that
+ * the data destination module has requested suspension of the compressor,
+ * or if more than image_height scanlines are passed in.
+ *
+ * Note: we warn about excess calls to jpeg_write_scanlines() since
+ * this likely signals an application programmer error. However,
+ * excess scanlines passed in the last valid call are *silently* ignored,
+ * so that the application need not adjust num_lines for end-of-image
+ * when using a multiple-scanline buffer.
+ */
+
+GLOBAL(JDIMENSION)
+jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
+ JDIMENSION num_lines)
+{
+ JDIMENSION row_ctr, rows_left;
+
+ if (cinfo->global_state != CSTATE_SCANNING)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ if (cinfo->next_scanline >= cinfo->image_height)
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) cinfo->next_scanline;
+ cinfo->progress->pass_limit = (long) cinfo->image_height;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+
+ /* Give master control module another chance if this is first call to
+ * jpeg_write_scanlines. This lets output of the frame/scan headers be
+ * delayed so that application can write COM, etc, markers between
+ * jpeg_start_compress and jpeg_write_scanlines.
+ */
+ if (cinfo->master->call_pass_startup)
+ (*cinfo->master->pass_startup) (cinfo);
+
+ /* Ignore any extra scanlines at bottom of image. */
+ rows_left = cinfo->image_height - cinfo->next_scanline;
+ if (num_lines > rows_left)
+ num_lines = rows_left;
+
+ row_ctr = 0;
+ (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
+ cinfo->next_scanline += row_ctr;
+ return row_ctr;
+}
+
+
+/*
+ * Alternate entry point to write raw data.
+ * Processes exactly one iMCU row per call, unless suspended.
+ */
+
+GLOBAL(JDIMENSION)
+jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
+ JDIMENSION num_lines)
+{
+ JDIMENSION lines_per_iMCU_row;
+
+ if (cinfo->global_state != CSTATE_RAW_OK)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ if (cinfo->next_scanline >= cinfo->image_height) {
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+ return 0;
+ }
+
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) cinfo->next_scanline;
+ cinfo->progress->pass_limit = (long) cinfo->image_height;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+
+ /* Give master control module another chance if this is first call to
+ * jpeg_write_raw_data. This lets output of the frame/scan headers be
+ * delayed so that application can write COM, etc, markers between
+ * jpeg_start_compress and jpeg_write_raw_data.
+ */
+ if (cinfo->master->call_pass_startup)
+ (*cinfo->master->pass_startup) (cinfo);
+
+ /* Verify that at least one iMCU row has been passed. */
+ lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
+ if (num_lines < lines_per_iMCU_row)
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
+
+ /* Directly compress the row. */
+ if (! (*cinfo->coef->compress_data) (cinfo, data)) {
+ /* If compressor did not consume the whole row, suspend processing. */
+ return 0;
+ }
+
+ /* OK, we processed one iMCU row. */
+ cinfo->next_scanline += lines_per_iMCU_row;
+ return lines_per_iMCU_row;
+}
diff --git a/osframework/source/ImageLib/jpeg/jccoefct.c b/osframework/source/ImageLib/jpeg/jccoefct.c
new file mode 100644
index 0000000..c713b85
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jccoefct.c
@@ -0,0 +1,449 @@
+/*
+ * jccoefct.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the coefficient buffer controller for compression.
+ * This controller is the top level of the JPEG compressor proper.
+ * The coefficient buffer lies between forward-DCT and entropy encoding steps.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* We use a full-image coefficient buffer when doing Huffman optimization,
+ * and also for writing multiple-scan JPEG files. In all cases, the DCT
+ * step is run during the first pass, and subsequent passes need only read
+ * the buffered coefficients.
+ */
+#ifdef ENTROPY_OPT_SUPPORTED
+#define FULL_COEF_BUFFER_SUPPORTED
+#else
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+#define FULL_COEF_BUFFER_SUPPORTED
+#endif
+#endif
+
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_c_coef_controller pub; /* public fields */
+
+ JDIMENSION iMCU_row_num; /* iMCU row # within image */
+ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
+ int MCU_vert_offset; /* counts MCU rows within iMCU row */
+ int MCU_rows_per_iMCU_row; /* number of such rows needed */
+
+ /* For single-pass compression, it's sufficient to buffer just one MCU
+ * (although this may prove a bit slow in practice). We allocate a
+ * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
+ * MCU constructed and sent. (On 80x86, the workspace is FAR even though
+ * it's not really very big; this is to keep the module interfaces unchanged
+ * when a large coefficient buffer is necessary.)
+ * In multi-pass modes, this array points to the current MCU's blocks
+ * within the virtual arrays.
+ */
+ JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
+
+ /* In multi-pass modes, we need a virtual block array for each component. */
+ jvirt_barray_ptr whole_image[MAX_COMPONENTS];
+} my_coef_controller;
+
+typedef my_coef_controller * my_coef_ptr;
+
+
+/* Forward declarations */
+METHODDEF(boolean) compress_data
+ JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
+#ifdef FULL_COEF_BUFFER_SUPPORTED
+METHODDEF(boolean) compress_first_pass
+ JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
+METHODDEF(boolean) compress_output
+ JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
+#endif
+
+
+LOCAL(void)
+start_iMCU_row (j_compress_ptr cinfo)
+/* Reset within-iMCU-row counters for a new row */
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ /* In an interleaved scan, an MCU row is the same as an iMCU row.
+ * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
+ * But at the bottom of the image, process only what's left.
+ */
+ if (cinfo->comps_in_scan > 1) {
+ coef->MCU_rows_per_iMCU_row = 1;
+ } else {
+ if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
+ else
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
+ }
+
+ coef->mcu_ctr = 0;
+ coef->MCU_vert_offset = 0;
+}
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ coef->iMCU_row_num = 0;
+ start_iMCU_row(cinfo);
+
+ switch (pass_mode) {
+ case JBUF_PASS_THRU:
+ if (coef->whole_image[0] != NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ coef->pub.compress_data = compress_data;
+ break;
+#ifdef FULL_COEF_BUFFER_SUPPORTED
+ case JBUF_SAVE_AND_PASS:
+ if (coef->whole_image[0] == NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ coef->pub.compress_data = compress_first_pass;
+ break;
+ case JBUF_CRANK_DEST:
+ if (coef->whole_image[0] == NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ coef->pub.compress_data = compress_output;
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ break;
+ }
+}
+
+
+/*
+ * Process some data in the single-pass case.
+ * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
+ * per call, ie, v_samp_factor block rows for each component in the image.
+ * Returns TRUE if the iMCU row is completed, FALSE if suspended.
+ *
+ * NB: input_buf contains a plane for each component in image,
+ * which we index according to the component's SOF position.
+ */
+
+METHODDEF(boolean)
+compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+ JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ int blkn, bi, ci, yindex, yoffset, blockcnt;
+ JDIMENSION ypos, xpos;
+ jpeg_component_info *compptr;
+
+ /* Loop to write as much as one whole iMCU row */
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+ yoffset++) {
+ for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
+ MCU_col_num++) {
+ /* Determine where data comes from in input_buf and do the DCT thing.
+ * Each call on forward_DCT processes a horizontal row of DCT blocks
+ * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
+ * sequentially. Dummy blocks at the right or bottom edge are filled in
+ * specially. The data in them does not matter for image reconstruction,
+ * so we fill them with values that will encode to the smallest amount of
+ * data, viz: all zeroes in the AC entries, DC entries equal to previous
+ * block's DC value. (Thanks to Thomas Kinsman for this idea.)
+ */
+ blkn = 0;
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
+ : compptr->last_col_width;
+ xpos = MCU_col_num * compptr->MCU_sample_width;
+ ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+ if (coef->iMCU_row_num < last_iMCU_row ||
+ yoffset+yindex < compptr->last_row_height) {
+ (*cinfo->fdct->forward_DCT) (cinfo, compptr,
+ input_buf[compptr->component_index],
+ coef->MCU_buffer[blkn],
+ ypos, xpos, (JDIMENSION) blockcnt);
+ if (blockcnt < compptr->MCU_width) {
+ /* Create some dummy blocks at the right edge of the image. */
+ jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
+ (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
+ for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
+ coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
+ }
+ }
+ } else {
+ /* Create a row of dummy blocks at the bottom of the image. */
+ jzero_far((void FAR *) coef->MCU_buffer[blkn],
+ compptr->MCU_width * SIZEOF(JBLOCK));
+ for (bi = 0; bi < compptr->MCU_width; bi++) {
+ coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
+ }
+ }
+ blkn += compptr->MCU_width;
+ ypos += DCTSIZE;
+ }
+ }
+ /* Try to write the MCU. In event of a suspension failure, we will
+ * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
+ */
+ if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
+ /* Suspension forced; update state counters and exit */
+ coef->MCU_vert_offset = yoffset;
+ coef->mcu_ctr = MCU_col_num;
+ return FALSE;
+ }
+ }
+ /* Completed an MCU row, but perhaps not an iMCU row */
+ coef->mcu_ctr = 0;
+ }
+ /* Completed the iMCU row, advance counters for next one */
+ coef->iMCU_row_num++;
+ start_iMCU_row(cinfo);
+ return TRUE;
+}
+
+
+#ifdef FULL_COEF_BUFFER_SUPPORTED
+
+/*
+ * Process some data in the first pass of a multi-pass case.
+ * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
+ * per call, ie, v_samp_factor block rows for each component in the image.
+ * This amount of data is read from the source buffer, DCT'd and quantized,
+ * and saved into the virtual arrays. We also generate suitable dummy blocks
+ * as needed at the right and lower edges. (The dummy blocks are constructed
+ * in the virtual arrays, which have been padded appropriately.) This makes
+ * it possible for subsequent passes not to worry about real vs. dummy blocks.
+ *
+ * We must also emit the data to the entropy encoder. This is conveniently
+ * done by calling compress_output() after we've loaded the current strip
+ * of the virtual arrays.
+ *
+ * NB: input_buf contains a plane for each component in image. All
+ * components are DCT'd and loaded into the virtual arrays in this pass.
+ * However, it may be that only a subset of the components are emitted to
+ * the entropy encoder during this first pass; be careful about looking
+ * at the scan-dependent variables (MCU dimensions, etc).
+ */
+
+METHODDEF(boolean)
+compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ JDIMENSION blocks_across, MCUs_across, MCUindex;
+ int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
+ JCOEF lastDC;
+ jpeg_component_info *compptr;
+ JBLOCKARRAY buffer;
+ JBLOCKROW thisblockrow, lastblockrow;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Align the virtual buffer for this component. */
+ buffer = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+ coef->iMCU_row_num * compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ /* Count non-dummy DCT block rows in this iMCU row. */
+ if (coef->iMCU_row_num < last_iMCU_row)
+ block_rows = compptr->v_samp_factor;
+ else {
+ /* NB: can't use last_row_height here, since may not be set! */
+ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+ if (block_rows == 0) block_rows = compptr->v_samp_factor;
+ }
+ blocks_across = compptr->width_in_blocks;
+ h_samp_factor = compptr->h_samp_factor;
+ /* Count number of dummy blocks to be added at the right margin. */
+ ndummy = (int) (blocks_across % h_samp_factor);
+ if (ndummy > 0)
+ ndummy = h_samp_factor - ndummy;
+ /* Perform DCT for all non-dummy blocks in this iMCU row. Each call
+ * on forward_DCT processes a complete horizontal row of DCT blocks.
+ */
+ for (block_row = 0; block_row < block_rows; block_row++) {
+ thisblockrow = buffer[block_row];
+ (*cinfo->fdct->forward_DCT) (cinfo, compptr,
+ input_buf[ci], thisblockrow,
+ (JDIMENSION) (block_row * DCTSIZE),
+ (JDIMENSION) 0, blocks_across);
+ if (ndummy > 0) {
+ /* Create dummy blocks at the right edge of the image. */
+ thisblockrow += blocks_across; /* => first dummy block */
+ jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
+ lastDC = thisblockrow[-1][0];
+ for (bi = 0; bi < ndummy; bi++) {
+ thisblockrow[bi][0] = lastDC;
+ }
+ }
+ }
+ /* If at end of image, create dummy block rows as needed.
+ * The tricky part here is that within each MCU, we want the DC values
+ * of the dummy blocks to match the last real block's DC value.
+ * This squeezes a few more bytes out of the resulting file...
+ */
+ if (coef->iMCU_row_num == last_iMCU_row) {
+ blocks_across += ndummy; /* include lower right corner */
+ MCUs_across = blocks_across / h_samp_factor;
+ for (block_row = block_rows; block_row < compptr->v_samp_factor;
+ block_row++) {
+ thisblockrow = buffer[block_row];
+ lastblockrow = buffer[block_row-1];
+ jzero_far((void FAR *) thisblockrow,
+ (size_t) (blocks_across * SIZEOF(JBLOCK)));
+ for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
+ lastDC = lastblockrow[h_samp_factor-1][0];
+ for (bi = 0; bi < h_samp_factor; bi++) {
+ thisblockrow[bi][0] = lastDC;
+ }
+ thisblockrow += h_samp_factor; /* advance to next MCU in row */
+ lastblockrow += h_samp_factor;
+ }
+ }
+ }
+ }
+ /* NB: compress_output will increment iMCU_row_num if successful.
+ * A suspension return will result in redoing all the work above next time.
+ */
+
+ /* Emit data to the entropy encoder, sharing code with subsequent passes */
+ return compress_output(cinfo, input_buf);
+}
+
+
+/*
+ * Process some data in subsequent passes of a multi-pass case.
+ * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
+ * per call, ie, v_samp_factor block rows for each component in the scan.
+ * The data is obtained from the virtual arrays and fed to the entropy coder.
+ * Returns TRUE if the iMCU row is completed, FALSE if suspended.
+ *
+ * NB: input_buf is ignored; it is likely to be a NULL pointer.
+ */
+
+METHODDEF(boolean)
+compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+ int blkn, ci, xindex, yindex, yoffset;
+ JDIMENSION start_col;
+ JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
+ JBLOCKROW buffer_ptr;
+ jpeg_component_info *compptr;
+
+ /* Align the virtual buffers for the components used in this scan.
+ * NB: during first pass, this is safe only because the buffers will
+ * already be aligned properly, so jmemmgr.c won't need to do any I/O.
+ */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ buffer[ci] = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
+ coef->iMCU_row_num * compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ }
+
+ /* Loop to process one whole iMCU row */
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+ yoffset++) {
+ for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
+ MCU_col_num++) {
+ /* Construct list of pointers to DCT blocks belonging to this MCU */
+ blkn = 0; /* index of current DCT block within MCU */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ start_col = MCU_col_num * compptr->MCU_width;
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+ buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
+ for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
+ coef->MCU_buffer[blkn++] = buffer_ptr++;
+ }
+ }
+ }
+ /* Try to write the MCU. */
+ if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
+ /* Suspension forced; update state counters and exit */
+ coef->MCU_vert_offset = yoffset;
+ coef->mcu_ctr = MCU_col_num;
+ return FALSE;
+ }
+ }
+ /* Completed an MCU row, but perhaps not an iMCU row */
+ coef->mcu_ctr = 0;
+ }
+ /* Completed the iMCU row, advance counters for next one */
+ coef->iMCU_row_num++;
+ start_iMCU_row(cinfo);
+ return TRUE;
+}
+
+#endif /* FULL_COEF_BUFFER_SUPPORTED */
+
+
+/*
+ * Initialize coefficient buffer controller.
+ */
+
+GLOBAL(void)
+jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
+{
+ my_coef_ptr coef;
+
+ coef = (my_coef_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_coef_controller));
+ cinfo->coef = (struct jpeg_c_coef_controller *) coef;
+ coef->pub.start_pass = start_pass_coef;
+
+ /* Create the coefficient buffer. */
+ if (need_full_buffer) {
+#ifdef FULL_COEF_BUFFER_SUPPORTED
+ /* Allocate a full-image virtual array for each component, */
+ /* padded to a multiple of samp_factor DCT blocks in each direction. */
+ int ci;
+ jpeg_component_info *compptr;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) compptr->v_samp_factor);
+ }
+#else
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+#endif
+ } else {
+ /* We only need a single-MCU buffer. */
+ JBLOCKROW buffer;
+ int i;
+
+ buffer = (JBLOCKROW)
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
+ for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
+ coef->MCU_buffer[i] = buffer + i;
+ }
+ coef->whole_image[0] = NULL; /* flag for no virtual arrays */
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jccolor.c b/osframework/source/ImageLib/jpeg/jccolor.c
new file mode 100644
index 0000000..2663724
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jccolor.c
@@ -0,0 +1,459 @@
+/*
+ * jccolor.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains input colorspace conversion routines.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_color_converter pub; /* public fields */
+
+ /* Private state for RGB->YCC conversion */
+ INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
+} my_color_converter;
+
+typedef my_color_converter * my_cconvert_ptr;
+
+
+/**************** RGB -> YCbCr conversion: most common case **************/
+
+/*
+ * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
+ * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
+ * The conversion equations to be implemented are therefore
+ * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
+ * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
+ * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
+ * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
+ * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
+ * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
+ * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
+ * were not represented exactly. Now we sacrifice exact representation of
+ * maximum red and maximum blue in order to get exact grayscales.
+ *
+ * To avoid floating-point arithmetic, we represent the fractional constants
+ * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
+ * the products by 2^16, with appropriate rounding, to get the correct answer.
+ *
+ * For even more speed, we avoid doing any multiplications in the inner loop
+ * by precalculating the constants times R,G,B for all possible values.
+ * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
+ * for 12-bit samples it is still acceptable. It's not very reasonable for
+ * 16-bit samples, but if you want lossless storage you shouldn't be changing
+ * colorspace anyway.
+ * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
+ * in the tables to save adding them separately in the inner loop.
+ */
+
+#define SCALEBITS 16 /* speediest right-shift on some machines */
+#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
+#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
+#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
+
+/* We allocate one big table and divide it up into eight parts, instead of
+ * doing eight alloc_small requests. This lets us use a single table base
+ * address, which can be held in a register in the inner loops on many
+ * machines (more than can hold all eight addresses, anyway).
+ */
+
+#define R_Y_OFF 0 /* offset to R => Y section */
+#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
+#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
+#define R_CB_OFF (3*(MAXJSAMPLE+1))
+#define G_CB_OFF (4*(MAXJSAMPLE+1))
+#define B_CB_OFF (5*(MAXJSAMPLE+1))
+#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
+#define G_CR_OFF (6*(MAXJSAMPLE+1))
+#define B_CR_OFF (7*(MAXJSAMPLE+1))
+#define TABLE_SIZE (8*(MAXJSAMPLE+1))
+
+
+/*
+ * Initialize for RGB->YCC colorspace conversion.
+ */
+
+METHODDEF(void)
+rgb_ycc_start (j_compress_ptr cinfo)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ INT32 * rgb_ycc_tab;
+ INT32 i;
+
+ /* Allocate and fill in the conversion tables. */
+ cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (TABLE_SIZE * SIZEOF(INT32)));
+
+ for (i = 0; i <= MAXJSAMPLE; i++) {
+ rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
+ rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
+ rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
+ rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
+ rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
+ /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
+ * This ensures that the maximum output will round to MAXJSAMPLE
+ * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
+ */
+ rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
+/* B=>Cb and R=>Cr tables are the same
+ rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
+*/
+ rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
+ rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
+ }
+}
+
+
+/*
+ * Convert some rows of samples to the JPEG colorspace.
+ *
+ * Note that we change from the application's interleaved-pixel format
+ * to our internal noninterleaved, one-plane-per-component format.
+ * The input buffer is therefore three times as wide as the output buffer.
+ *
+ * A starting row offset is provided only for the output buffer. The caller
+ * can easily adjust the passed input_buf value to accommodate any row
+ * offset required on that side.
+ */
+
+METHODDEF(void)
+rgb_ycc_convert (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ register int r, g, b;
+ register INT32 * ctab = cconvert->rgb_ycc_tab;
+ register JSAMPROW inptr;
+ register JSAMPROW outptr0, outptr1, outptr2;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->image_width;
+
+ while (--num_rows >= 0) {
+ inptr = *input_buf++;
+ outptr0 = output_buf[0][output_row];
+ outptr1 = output_buf[1][output_row];
+ outptr2 = output_buf[2][output_row];
+ output_row++;
+ for (col = 0; col < num_cols; col++) {
+ r = GETJSAMPLE(inptr[RGB_RED]);
+ g = GETJSAMPLE(inptr[RGB_GREEN]);
+ b = GETJSAMPLE(inptr[RGB_BLUE]);
+ inptr += RGB_PIXELSIZE;
+ /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
+ * must be too; we do not need an explicit range-limiting operation.
+ * Hence the value being shifted is never negative, and we don't
+ * need the general RIGHT_SHIFT macro.
+ */
+ /* Y */
+ outptr0[col] = (JSAMPLE)
+ ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
+ >> SCALEBITS);
+ /* Cb */
+ outptr1[col] = (JSAMPLE)
+ ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
+ >> SCALEBITS);
+ /* Cr */
+ outptr2[col] = (JSAMPLE)
+ ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
+ >> SCALEBITS);
+ }
+ }
+}
+
+
+/**************** Cases other than RGB -> YCbCr **************/
+
+
+/*
+ * Convert some rows of samples to the JPEG colorspace.
+ * This version handles RGB->grayscale conversion, which is the same
+ * as the RGB->Y portion of RGB->YCbCr.
+ * We assume rgb_ycc_start has been called (we only use the Y tables).
+ */
+
+METHODDEF(void)
+rgb_gray_convert (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ register int r, g, b;
+ register INT32 * ctab = cconvert->rgb_ycc_tab;
+ register JSAMPROW inptr;
+ register JSAMPROW outptr;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->image_width;
+
+ while (--num_rows >= 0) {
+ inptr = *input_buf++;
+ outptr = output_buf[0][output_row];
+ output_row++;
+ for (col = 0; col < num_cols; col++) {
+ r = GETJSAMPLE(inptr[RGB_RED]);
+ g = GETJSAMPLE(inptr[RGB_GREEN]);
+ b = GETJSAMPLE(inptr[RGB_BLUE]);
+ inptr += RGB_PIXELSIZE;
+ /* Y */
+ outptr[col] = (JSAMPLE)
+ ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
+ >> SCALEBITS);
+ }
+ }
+}
+
+
+/*
+ * Convert some rows of samples to the JPEG colorspace.
+ * This version handles Adobe-style CMYK->YCCK conversion,
+ * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
+ * conversion as above, while passing K (black) unchanged.
+ * We assume rgb_ycc_start has been called.
+ */
+
+METHODDEF(void)
+cmyk_ycck_convert (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ register int r, g, b;
+ register INT32 * ctab = cconvert->rgb_ycc_tab;
+ register JSAMPROW inptr;
+ register JSAMPROW outptr0, outptr1, outptr2, outptr3;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->image_width;
+
+ while (--num_rows >= 0) {
+ inptr = *input_buf++;
+ outptr0 = output_buf[0][output_row];
+ outptr1 = output_buf[1][output_row];
+ outptr2 = output_buf[2][output_row];
+ outptr3 = output_buf[3][output_row];
+ output_row++;
+ for (col = 0; col < num_cols; col++) {
+ r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
+ g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
+ b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
+ /* K passes through as-is */
+ outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
+ inptr += 4;
+ /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
+ * must be too; we do not need an explicit range-limiting operation.
+ * Hence the value being shifted is never negative, and we don't
+ * need the general RIGHT_SHIFT macro.
+ */
+ /* Y */
+ outptr0[col] = (JSAMPLE)
+ ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
+ >> SCALEBITS);
+ /* Cb */
+ outptr1[col] = (JSAMPLE)
+ ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
+ >> SCALEBITS);
+ /* Cr */
+ outptr2[col] = (JSAMPLE)
+ ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
+ >> SCALEBITS);
+ }
+ }
+}
+
+
+/*
+ * Convert some rows of samples to the JPEG colorspace.
+ * This version handles grayscale output with no conversion.
+ * The source can be either plain grayscale or YCbCr (since Y == gray).
+ */
+
+METHODDEF(void)
+grayscale_convert (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows)
+{
+ register JSAMPROW inptr;
+ register JSAMPROW outptr;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->image_width;
+ int instride = cinfo->input_components;
+
+ while (--num_rows >= 0) {
+ inptr = *input_buf++;
+ outptr = output_buf[0][output_row];
+ output_row++;
+ for (col = 0; col < num_cols; col++) {
+ outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
+ inptr += instride;
+ }
+ }
+}
+
+
+/*
+ * Convert some rows of samples to the JPEG colorspace.
+ * This version handles multi-component colorspaces without conversion.
+ * We assume input_components == num_components.
+ */
+
+METHODDEF(void)
+null_convert (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows)
+{
+ register JSAMPROW inptr;
+ register JSAMPROW outptr;
+ register JDIMENSION col;
+ register int ci;
+ int nc = cinfo->num_components;
+ JDIMENSION num_cols = cinfo->image_width;
+
+ while (--num_rows >= 0) {
+ /* It seems fastest to make a separate pass for each component. */
+ for (ci = 0; ci < nc; ci++) {
+ inptr = *input_buf;
+ outptr = output_buf[ci][output_row];
+ for (col = 0; col < num_cols; col++) {
+ outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
+ inptr += nc;
+ }
+ }
+ input_buf++;
+ output_row++;
+ }
+}
+
+
+/*
+ * Empty method for start_pass.
+ */
+
+METHODDEF(void)
+null_method (j_compress_ptr cinfo)
+{
+ /* no work needed */
+}
+
+
+/*
+ * Module initialization routine for input colorspace conversion.
+ */
+
+GLOBAL(void)
+jinit_color_converter (j_compress_ptr cinfo)
+{
+ my_cconvert_ptr cconvert;
+
+ cconvert = (my_cconvert_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_color_converter));
+ cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
+ /* set start_pass to null method until we find out differently */
+ cconvert->pub.start_pass = null_method;
+
+ /* Make sure input_components agrees with in_color_space */
+ switch (cinfo->in_color_space) {
+ case JCS_GRAYSCALE:
+ if (cinfo->input_components != 1)
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ break;
+
+ case JCS_RGB:
+#if RGB_PIXELSIZE != 3
+ if (cinfo->input_components != RGB_PIXELSIZE)
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ break;
+#endif /* else share code with YCbCr */
+
+ case JCS_YCbCr:
+ if (cinfo->input_components != 3)
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ break;
+
+ case JCS_CMYK:
+ case JCS_YCCK:
+ if (cinfo->input_components != 4)
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ break;
+
+ default: /* JCS_UNKNOWN can be anything */
+ if (cinfo->input_components < 1)
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ break;
+ }
+
+ /* Check num_components, set conversion method based on requested space */
+ switch (cinfo->jpeg_color_space) {
+ case JCS_GRAYSCALE:
+ if (cinfo->num_components != 1)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ if (cinfo->in_color_space == JCS_GRAYSCALE)
+ cconvert->pub.color_convert = grayscale_convert;
+ else if (cinfo->in_color_space == JCS_RGB) {
+ cconvert->pub.start_pass = rgb_ycc_start;
+ cconvert->pub.color_convert = rgb_gray_convert;
+ } else if (cinfo->in_color_space == JCS_YCbCr)
+ cconvert->pub.color_convert = grayscale_convert;
+ else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_RGB:
+ if (cinfo->num_components != 3)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
+ cconvert->pub.color_convert = null_convert;
+ else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_YCbCr:
+ if (cinfo->num_components != 3)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ if (cinfo->in_color_space == JCS_RGB) {
+ cconvert->pub.start_pass = rgb_ycc_start;
+ cconvert->pub.color_convert = rgb_ycc_convert;
+ } else if (cinfo->in_color_space == JCS_YCbCr)
+ cconvert->pub.color_convert = null_convert;
+ else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_CMYK:
+ if (cinfo->num_components != 4)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ if (cinfo->in_color_space == JCS_CMYK)
+ cconvert->pub.color_convert = null_convert;
+ else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_YCCK:
+ if (cinfo->num_components != 4)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ if (cinfo->in_color_space == JCS_CMYK) {
+ cconvert->pub.start_pass = rgb_ycc_start;
+ cconvert->pub.color_convert = cmyk_ycck_convert;
+ } else if (cinfo->in_color_space == JCS_YCCK)
+ cconvert->pub.color_convert = null_convert;
+ else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ default: /* allow null conversion of JCS_UNKNOWN */
+ if (cinfo->jpeg_color_space != cinfo->in_color_space ||
+ cinfo->num_components != cinfo->input_components)
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ cconvert->pub.color_convert = null_convert;
+ break;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jcdctmgr.c b/osframework/source/ImageLib/jpeg/jcdctmgr.c
new file mode 100644
index 0000000..e3f90dc
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcdctmgr.c
@@ -0,0 +1,387 @@
+/*
+ * jcdctmgr.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the forward-DCT management logic.
+ * This code selects a particular DCT implementation to be used,
+ * and it performs related housekeeping chores including coefficient
+ * quantization.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+
+/* Private subobject for this module */
+
+typedef struct {
+ struct jpeg_forward_dct pub; /* public fields */
+
+ /* Pointer to the DCT routine actually in use */
+ forward_DCT_method_ptr do_dct;
+
+ /* The actual post-DCT divisors --- not identical to the quant table
+ * entries, because of scaling (especially for an unnormalized DCT).
+ * Each table is given in normal array order.
+ */
+ DCTELEM * divisors[NUM_QUANT_TBLS];
+
+#ifdef DCT_FLOAT_SUPPORTED
+ /* Same as above for the floating-point case. */
+ float_DCT_method_ptr do_float_dct;
+ FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
+#endif
+} my_fdct_controller;
+
+typedef my_fdct_controller * my_fdct_ptr;
+
+
+/*
+ * Initialize for a processing pass.
+ * Verify that all referenced Q-tables are present, and set up
+ * the divisor table for each one.
+ * In the current implementation, DCT of all components is done during
+ * the first pass, even if only some components will be output in the
+ * first scan. Hence all components should be examined here.
+ */
+
+METHODDEF(void)
+start_pass_fdctmgr (j_compress_ptr cinfo)
+{
+ my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
+ int ci, qtblno, i;
+ jpeg_component_info *compptr;
+ JQUANT_TBL * qtbl;
+ DCTELEM * dtbl;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ qtblno = compptr->quant_tbl_no;
+ /* Make sure specified quantization table is present */
+ if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
+ cinfo->quant_tbl_ptrs[qtblno] == NULL)
+ ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
+ qtbl = cinfo->quant_tbl_ptrs[qtblno];
+ /* Compute divisors for this quant table */
+ /* We may do this more than once for same table, but it's not a big deal */
+ switch (cinfo->dct_method) {
+#ifdef DCT_ISLOW_SUPPORTED
+ case JDCT_ISLOW:
+ /* For LL&M IDCT method, divisors are equal to raw quantization
+ * coefficients multiplied by 8 (to counteract scaling).
+ */
+ if (fdct->divisors[qtblno] == NULL) {
+ fdct->divisors[qtblno] = (DCTELEM *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ DCTSIZE2 * SIZEOF(DCTELEM));
+ }
+ dtbl = fdct->divisors[qtblno];
+ for (i = 0; i < DCTSIZE2; i++) {
+ dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
+ }
+ break;
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ case JDCT_IFAST:
+ {
+ /* For AA&N IDCT method, divisors are equal to quantization
+ * coefficients scaled by scalefactor[row]*scalefactor[col], where
+ * scalefactor[0] = 1
+ * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
+ * We apply a further scale factor of 8.
+ */
+#define CONST_BITS 14
+ static const INT16 aanscales[DCTSIZE2] = {
+ /* precomputed values scaled up by 14 bits */
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+ 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+ 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+ 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+ 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
+ };
+ SHIFT_TEMPS
+
+ if (fdct->divisors[qtblno] == NULL) {
+ fdct->divisors[qtblno] = (DCTELEM *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ DCTSIZE2 * SIZEOF(DCTELEM));
+ }
+ dtbl = fdct->divisors[qtblno];
+ for (i = 0; i < DCTSIZE2; i++) {
+ dtbl[i] = (DCTELEM)
+ DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
+ (INT32) aanscales[i]),
+ CONST_BITS-3);
+ }
+ }
+ break;
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ case JDCT_FLOAT:
+ {
+ /* For float AA&N IDCT method, divisors are equal to quantization
+ * coefficients scaled by scalefactor[row]*scalefactor[col], where
+ * scalefactor[0] = 1
+ * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
+ * We apply a further scale factor of 8.
+ * What's actually stored is 1/divisor so that the inner loop can
+ * use a multiplication rather than a division.
+ */
+ FAST_FLOAT * fdtbl;
+ int row, col;
+ static const double aanscalefactor[DCTSIZE] = {
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ };
+
+ if (fdct->float_divisors[qtblno] == NULL) {
+ fdct->float_divisors[qtblno] = (FAST_FLOAT *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ DCTSIZE2 * SIZEOF(FAST_FLOAT));
+ }
+ fdtbl = fdct->float_divisors[qtblno];
+ i = 0;
+ for (row = 0; row < DCTSIZE; row++) {
+ for (col = 0; col < DCTSIZE; col++) {
+ fdtbl[i] = (FAST_FLOAT)
+ (1.0 / (((double) qtbl->quantval[i] *
+ aanscalefactor[row] * aanscalefactor[col] * 8.0)));
+ i++;
+ }
+ }
+ }
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ break;
+ }
+ }
+}
+
+
+/*
+ * Perform forward DCT on one or more blocks of a component.
+ *
+ * The input samples are taken from the sample_data[] array starting at
+ * position start_row/start_col, and moving to the right for any additional
+ * blocks. The quantized coefficients are returned in coef_blocks[].
+ */
+
+METHODDEF(void)
+forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
+ JDIMENSION start_row, JDIMENSION start_col,
+ JDIMENSION num_blocks)
+/* This version is used for integer DCT implementations. */
+{
+ /* This routine is heavily used, so it's worth coding it tightly. */
+ my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
+ forward_DCT_method_ptr do_dct = fdct->do_dct;
+ DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
+ DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
+ JDIMENSION bi;
+
+ sample_data += start_row; /* fold in the vertical offset once */
+
+ for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
+ /* Load data into workspace, applying unsigned->signed conversion */
+ { register DCTELEM *workspaceptr;
+ register JSAMPROW elemptr;
+ register int elemr;
+
+ workspaceptr = workspace;
+ for (elemr = 0; elemr < DCTSIZE; elemr++) {
+ elemptr = sample_data[elemr] + start_col;
+#if DCTSIZE == 8 /* unroll the inner loop */
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+#else
+ { register int elemc;
+ for (elemc = DCTSIZE; elemc > 0; elemc--) {
+ *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
+ }
+ }
+#endif
+ }
+ }
+
+ /* Perform the DCT */
+ (*do_dct) (workspace);
+
+ /* Quantize/descale the coefficients, and store into coef_blocks[] */
+ { register DCTELEM temp, qval;
+ register int i;
+ register JCOEFPTR output_ptr = coef_blocks[bi];
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ qval = divisors[i];
+ temp = workspace[i];
+ /* Divide the coefficient value by qval, ensuring proper rounding.
+ * Since C does not specify the direction of rounding for negative
+ * quotients, we have to force the dividend positive for portability.
+ *
+ * In most files, at least half of the output values will be zero
+ * (at default quantization settings, more like three-quarters...)
+ * so we should ensure that this case is fast. On many machines,
+ * a comparison is enough cheaper than a divide to make a special test
+ * a win. Since both inputs will be nonnegative, we need only test
+ * for a < b to discover whether a/b is 0.
+ * If your machine's division is fast enough, define FAST_DIVIDE.
+ */
+#ifdef FAST_DIVIDE
+#define DIVIDE_BY(a,b) a /= b
+#else
+#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
+#endif
+ if (temp < 0) {
+ temp = -temp;
+ temp += qval>>1; /* for rounding */
+ DIVIDE_BY(temp, qval);
+ temp = -temp;
+ } else {
+ temp += qval>>1; /* for rounding */
+ DIVIDE_BY(temp, qval);
+ }
+ output_ptr[i] = (JCOEF) temp;
+ }
+ }
+ }
+}
+
+
+#ifdef DCT_FLOAT_SUPPORTED
+
+METHODDEF(void)
+forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
+ JDIMENSION start_row, JDIMENSION start_col,
+ JDIMENSION num_blocks)
+/* This version is used for floating-point DCT implementations. */
+{
+ /* This routine is heavily used, so it's worth coding it tightly. */
+ my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
+ float_DCT_method_ptr do_dct = fdct->do_float_dct;
+ FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
+ FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
+ JDIMENSION bi;
+
+ sample_data += start_row; /* fold in the vertical offset once */
+
+ for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
+ /* Load data into workspace, applying unsigned->signed conversion */
+ { register FAST_FLOAT *workspaceptr;
+ register JSAMPROW elemptr;
+ register int elemr;
+
+ workspaceptr = workspace;
+ for (elemr = 0; elemr < DCTSIZE; elemr++) {
+ elemptr = sample_data[elemr] + start_col;
+#if DCTSIZE == 8 /* unroll the inner loop */
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+#else
+ { register int elemc;
+ for (elemc = DCTSIZE; elemc > 0; elemc--) {
+ *workspaceptr++ = (FAST_FLOAT)
+ (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
+ }
+ }
+#endif
+ }
+ }
+
+ /* Perform the DCT */
+ (*do_dct) (workspace);
+
+ /* Quantize/descale the coefficients, and store into coef_blocks[] */
+ { register FAST_FLOAT temp;
+ register int i;
+ register JCOEFPTR output_ptr = coef_blocks[bi];
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ /* Apply the quantization and scaling factor */
+ temp = workspace[i] * divisors[i];
+ /* Round to nearest integer.
+ * Since C does not specify the direction of rounding for negative
+ * quotients, we have to force the dividend positive for portability.
+ * The maximum coefficient size is +-16K (for 12-bit data), so this
+ * code should work for either 16-bit or 32-bit ints.
+ */
+ output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
+ }
+ }
+ }
+}
+
+#endif /* DCT_FLOAT_SUPPORTED */
+
+
+/*
+ * Initialize FDCT manager.
+ */
+
+GLOBAL(void)
+jinit_forward_dct (j_compress_ptr cinfo)
+{
+ my_fdct_ptr fdct;
+ int i;
+
+ fdct = (my_fdct_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_fdct_controller));
+ cinfo->fdct = (struct jpeg_forward_dct *) fdct;
+ fdct->pub.start_pass = start_pass_fdctmgr;
+
+ switch (cinfo->dct_method) {
+#ifdef DCT_ISLOW_SUPPORTED
+ case JDCT_ISLOW:
+ fdct->pub.forward_DCT = forward_DCT;
+ fdct->do_dct = jpeg_fdct_islow;
+ break;
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ case JDCT_IFAST:
+ fdct->pub.forward_DCT = forward_DCT;
+ fdct->do_dct = jpeg_fdct_ifast;
+ break;
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ case JDCT_FLOAT:
+ fdct->pub.forward_DCT = forward_DCT_float;
+ fdct->do_float_dct = jpeg_fdct_float;
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ break;
+ }
+
+ /* Mark divisor tables unallocated */
+ for (i = 0; i < NUM_QUANT_TBLS; i++) {
+ fdct->divisors[i] = NULL;
+#ifdef DCT_FLOAT_SUPPORTED
+ fdct->float_divisors[i] = NULL;
+#endif
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jchuff.c b/osframework/source/ImageLib/jpeg/jchuff.c
new file mode 100644
index 0000000..16d9366
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jchuff.c
@@ -0,0 +1,909 @@
+/*
+ * jchuff.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains Huffman entropy encoding routines.
+ *
+ * Much of the complexity here has to do with supporting output suspension.
+ * If the data destination module demands suspension, we want to be able to
+ * back up to the start of the current MCU. To do this, we copy state
+ * variables into local working storage, and update them back to the
+ * permanent JPEG objects only upon successful completion of an MCU.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jchuff.h" /* Declarations shared with jcphuff.c */
+
+
+/* Expanded entropy encoder object for Huffman encoding.
+ *
+ * The savable_state subrecord contains fields that change within an MCU,
+ * but must not be updated permanently until we complete the MCU.
+ */
+
+typedef struct {
+ INT32 put_buffer; /* current bit-accumulation buffer */
+ int put_bits; /* # of bits now in it */
+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
+} savable_state;
+
+/* This macro is to work around compilers with missing or broken
+ * structure assignment. You'll need to fix this code if you have
+ * such a compiler and you change MAX_COMPS_IN_SCAN.
+ */
+
+#ifndef NO_STRUCT_ASSIGN
+#define ASSIGN_STATE(dest,src) ((dest) = (src))
+#else
+#if MAX_COMPS_IN_SCAN == 4
+#define ASSIGN_STATE(dest,src) \
+ ((dest).put_buffer = (src).put_buffer, \
+ (dest).put_bits = (src).put_bits, \
+ (dest).last_dc_val[0] = (src).last_dc_val[0], \
+ (dest).last_dc_val[1] = (src).last_dc_val[1], \
+ (dest).last_dc_val[2] = (src).last_dc_val[2], \
+ (dest).last_dc_val[3] = (src).last_dc_val[3])
+#endif
+#endif
+
+
+typedef struct {
+ struct jpeg_entropy_encoder pub; /* public fields */
+
+ savable_state saved; /* Bit buffer & DC state at start of MCU */
+
+ /* These fields are NOT loaded into local working state. */
+ unsigned int restarts_to_go; /* MCUs left in this restart interval */
+ int next_restart_num; /* next restart number to write (0-7) */
+
+ /* Pointers to derived tables (these workspaces have image lifespan) */
+ c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
+ c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
+
+#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
+ long * dc_count_ptrs[NUM_HUFF_TBLS];
+ long * ac_count_ptrs[NUM_HUFF_TBLS];
+#endif
+} huff_entropy_encoder;
+
+typedef huff_entropy_encoder * huff_entropy_ptr;
+
+/* Working state while writing an MCU.
+ * This struct contains all the fields that are needed by subroutines.
+ */
+
+typedef struct {
+ JOCTET * next_output_byte; /* => next byte to write in buffer */
+ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
+ savable_state cur; /* Current bit buffer & DC state */
+ j_compress_ptr cinfo; /* dump_buffer needs access to this */
+} working_state;
+
+
+/* Forward declarations */
+METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
+#ifdef ENTROPY_OPT_SUPPORTED
+METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
+#endif
+
+
+/*
+ * Initialize for a Huffman-compressed scan.
+ * If gather_statistics is TRUE, we do not output anything during the scan,
+ * just count the Huffman symbols used and generate Huffman code tables.
+ */
+
+METHODDEF(void)
+start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int ci, dctbl, actbl;
+ jpeg_component_info * compptr;
+
+ if (gather_statistics) {
+#ifdef ENTROPY_OPT_SUPPORTED
+ entropy->pub.encode_mcu = encode_mcu_gather;
+ entropy->pub.finish_pass = finish_pass_gather;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ entropy->pub.encode_mcu = encode_mcu_huff;
+ entropy->pub.finish_pass = finish_pass_huff;
+ }
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ dctbl = compptr->dc_tbl_no;
+ actbl = compptr->ac_tbl_no;
+ if (gather_statistics) {
+#ifdef ENTROPY_OPT_SUPPORTED
+ /* Check for invalid table indexes */
+ /* (make_c_derived_tbl does this in the other path) */
+ if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
+ if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
+ /* Allocate and zero the statistics tables */
+ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
+ if (entropy->dc_count_ptrs[dctbl] == NULL)
+ entropy->dc_count_ptrs[dctbl] = (long *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ 257 * SIZEOF(long));
+ MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
+ if (entropy->ac_count_ptrs[actbl] == NULL)
+ entropy->ac_count_ptrs[actbl] = (long *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ 257 * SIZEOF(long));
+ MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
+#endif
+ } else {
+ /* Compute derived values for Huffman tables */
+ /* We may do this more than once for a table, but it's not expensive */
+ jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
+ & entropy->dc_derived_tbls[dctbl]);
+ jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
+ & entropy->ac_derived_tbls[actbl]);
+ }
+ /* Initialize DC predictions to 0 */
+ entropy->saved.last_dc_val[ci] = 0;
+ }
+
+ /* Initialize bit buffer to empty */
+ entropy->saved.put_buffer = 0;
+ entropy->saved.put_bits = 0;
+
+ /* Initialize restart stuff */
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num = 0;
+}
+
+
+/*
+ * Compute the derived values for a Huffman table.
+ * This routine also performs some validation checks on the table.
+ *
+ * Note this is also used by jcphuff.c.
+ */
+
+GLOBAL(void)
+jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
+ c_derived_tbl ** pdtbl)
+{
+ JHUFF_TBL *htbl;
+ c_derived_tbl *dtbl;
+ int p, i, l, lastp, si, maxsymbol;
+ char huffsize[257];
+ unsigned int huffcode[257];
+ unsigned int code;
+
+ /* Note that huffsize[] and huffcode[] are filled in code-length order,
+ * paralleling the order of the symbols themselves in htbl->huffval[].
+ */
+
+ /* Find the input Huffman table */
+ if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
+ htbl =
+ isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
+ if (htbl == NULL)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
+
+ /* Allocate a workspace if we haven't already done so. */
+ if (*pdtbl == NULL)
+ *pdtbl = (c_derived_tbl *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(c_derived_tbl));
+ dtbl = *pdtbl;
+
+ /* Figure C.1: make table of Huffman code length for each symbol */
+
+ p = 0;
+ for (l = 1; l <= 16; l++) {
+ i = (int) htbl->bits[l];
+ if (i < 0 || p + i > 256) /* protect against table overrun */
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ while (i--)
+ huffsize[p++] = (char) l;
+ }
+ huffsize[p] = 0;
+ lastp = p;
+
+ /* Figure C.2: generate the codes themselves */
+ /* We also validate that the counts represent a legal Huffman code tree. */
+
+ code = 0;
+ si = huffsize[0];
+ p = 0;
+ while (huffsize[p]) {
+ while (((int) huffsize[p]) == si) {
+ huffcode[p++] = code;
+ code++;
+ }
+ /* code is now 1 more than the last code used for codelength si; but
+ * it must still fit in si bits, since no code is allowed to be all ones.
+ */
+ if (((INT32) code) >= (((INT32) 1) << si))
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ code <<= 1;
+ si++;
+ }
+
+ /* Figure C.3: generate encoding tables */
+ /* These are code and size indexed by symbol value */
+
+ /* Set all codeless symbols to have code length 0;
+ * this lets us detect duplicate VAL entries here, and later
+ * allows emit_bits to detect any attempt to emit such symbols.
+ */
+ MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
+
+ /* This is also a convenient place to check for out-of-range
+ * and duplicated VAL entries. We allow 0..255 for AC symbols
+ * but only 0..15 for DC. (We could constrain them further
+ * based on data depth and mode, but this seems enough.)
+ */
+ maxsymbol = isDC ? 15 : 255;
+
+ for (p = 0; p < lastp; p++) {
+ i = htbl->huffval[p];
+ if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ dtbl->ehufco[i] = huffcode[p];
+ dtbl->ehufsi[i] = huffsize[p];
+ }
+}
+
+
+/* Outputting bytes to the file */
+
+/* Emit a byte, taking 'action' if must suspend. */
+#define emit_byte(state,val,action) \
+ { *(state)->next_output_byte++ = (JOCTET) (val); \
+ if (--(state)->free_in_buffer == 0) \
+ if (! dump_buffer(state)) \
+ { action; } }
+
+
+LOCAL(boolean)
+dump_buffer (working_state * state)
+/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
+{
+ struct jpeg_destination_mgr * dest = state->cinfo->dest;
+
+ if (! (*dest->empty_output_buffer) (state->cinfo))
+ return FALSE;
+ /* After a successful buffer dump, must reset buffer pointers */
+ state->next_output_byte = dest->next_output_byte;
+ state->free_in_buffer = dest->free_in_buffer;
+ return TRUE;
+}
+
+
+/* Outputting bits to the file */
+
+/* Only the right 24 bits of put_buffer are used; the valid bits are
+ * left-justified in this part. At most 16 bits can be passed to emit_bits
+ * in one call, and we never retain more than 7 bits in put_buffer
+ * between calls, so 24 bits are sufficient.
+ */
+
+INLINE
+LOCAL(boolean)
+emit_bits (working_state * state, unsigned int code, int size)
+/* Emit some bits; return TRUE if successful, FALSE if must suspend */
+{
+ /* This routine is heavily used, so it's worth coding tightly. */
+ register INT32 put_buffer = (INT32) code;
+ register int put_bits = state->cur.put_bits;
+
+ /* if size is 0, caller used an invalid Huffman table entry */
+ if (size == 0)
+ ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
+
+ put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
+
+ put_bits += size; /* new number of bits in buffer */
+
+ put_buffer <<= 24 - put_bits; /* align incoming bits */
+
+ put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
+
+ while (put_bits >= 8) {
+ int c = (int) ((put_buffer >> 16) & 0xFF);
+
+ emit_byte(state, c, return FALSE);
+ if (c == 0xFF) { /* need to stuff a zero byte? */
+ emit_byte(state, 0, return FALSE);
+ }
+ put_buffer <<= 8;
+ put_bits -= 8;
+ }
+
+ state->cur.put_buffer = put_buffer; /* update state variables */
+ state->cur.put_bits = put_bits;
+
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+flush_bits (working_state * state)
+{
+ if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
+ return FALSE;
+ state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
+ state->cur.put_bits = 0;
+ return TRUE;
+}
+
+
+/* Encode a single block's worth of coefficients */
+
+LOCAL(boolean)
+encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
+ c_derived_tbl *dctbl, c_derived_tbl *actbl)
+{
+ register int temp, temp2;
+ register int nbits;
+ register int k, r, i;
+
+ /* Encode the DC coefficient difference per section F.1.2.1 */
+
+ temp = temp2 = block[0] - last_dc_val;
+
+ if (temp < 0) {
+ temp = -temp; /* temp is abs value of input */
+ /* For a negative input, want temp2 = bitwise complement of abs(input) */
+ /* This code assumes we are on a two's complement machine */
+ temp2--;
+ }
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 0;
+ while (temp) {
+ nbits++;
+ temp >>= 1;
+ }
+ /* Check for out-of-range coefficient values.
+ * Since we're encoding a difference, the range limit is twice as much.
+ */
+ if (nbits > MAX_COEF_BITS+1)
+ ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
+
+ /* Emit the Huffman-coded symbol for the number of bits */
+ if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
+ return FALSE;
+
+ /* Emit that number of bits of the value, if positive, */
+ /* or the complement of its magnitude, if negative. */
+ if (nbits) /* emit_bits rejects calls with size 0 */
+ if (! emit_bits(state, (unsigned int) temp2, nbits))
+ return FALSE;
+
+ /* Encode the AC coefficients per section F.1.2.2 */
+
+ r = 0; /* r = run length of zeros */
+
+ for (k = 1; k < DCTSIZE2; k++) {
+ if ((temp = block[jpeg_natural_order[k]]) == 0) {
+ r++;
+ } else {
+ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
+ while (r > 15) {
+ if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
+ return FALSE;
+ r -= 16;
+ }
+
+ temp2 = temp;
+ if (temp < 0) {
+ temp = -temp; /* temp is abs value of input */
+ /* This code assumes we are on a two's complement machine */
+ temp2--;
+ }
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 1; /* there must be at least one 1 bit */
+ while ((temp >>= 1))
+ nbits++;
+ /* Check for out-of-range coefficient values */
+ if (nbits > MAX_COEF_BITS)
+ ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
+
+ /* Emit Huffman symbol for run length / number of bits */
+ i = (r << 4) + nbits;
+ if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
+ return FALSE;
+
+ /* Emit that number of bits of the value, if positive, */
+ /* or the complement of its magnitude, if negative. */
+ if (! emit_bits(state, (unsigned int) temp2, nbits))
+ return FALSE;
+
+ r = 0;
+ }
+ }
+
+ /* If the last coef(s) were zero, emit an end-of-block code */
+ if (r > 0)
+ if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
+ return FALSE;
+
+ return TRUE;
+}
+
+
+/*
+ * Emit a restart marker & resynchronize predictions.
+ */
+
+LOCAL(boolean)
+emit_restart (working_state * state, int restart_num)
+{
+ int ci;
+
+ if (! flush_bits(state))
+ return FALSE;
+
+ emit_byte(state, 0xFF, return FALSE);
+ emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
+
+ /* Re-initialize DC predictions to 0 */
+ for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
+ state->cur.last_dc_val[ci] = 0;
+
+ /* The restart counter is not updated until we successfully write the MCU. */
+
+ return TRUE;
+}
+
+
+/*
+ * Encode and output one MCU's worth of Huffman-compressed coefficients.
+ */
+
+METHODDEF(boolean)
+encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ working_state state;
+ int blkn, ci;
+ jpeg_component_info * compptr;
+
+ /* Load up working state */
+ state.next_output_byte = cinfo->dest->next_output_byte;
+ state.free_in_buffer = cinfo->dest->free_in_buffer;
+ ASSIGN_STATE(state.cur, entropy->saved);
+ state.cinfo = cinfo;
+
+ /* Emit restart marker if needed */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! emit_restart(&state, entropy->next_restart_num))
+ return FALSE;
+ }
+
+ /* Encode the MCU data blocks */
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ ci = cinfo->MCU_membership[blkn];
+ compptr = cinfo->cur_comp_info[ci];
+ if (! encode_one_block(&state,
+ MCU_data[blkn][0], state.cur.last_dc_val[ci],
+ entropy->dc_derived_tbls[compptr->dc_tbl_no],
+ entropy->ac_derived_tbls[compptr->ac_tbl_no]))
+ return FALSE;
+ /* Update last_dc_val */
+ state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
+ }
+
+ /* Completed MCU, so update state */
+ cinfo->dest->next_output_byte = state.next_output_byte;
+ cinfo->dest->free_in_buffer = state.free_in_buffer;
+ ASSIGN_STATE(entropy->saved, state.cur);
+
+ /* Update restart-interval state too */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num++;
+ entropy->next_restart_num &= 7;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Finish up at the end of a Huffman-compressed scan.
+ */
+
+METHODDEF(void)
+finish_pass_huff (j_compress_ptr cinfo)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ working_state state;
+
+ /* Load up working state ... flush_bits needs it */
+ state.next_output_byte = cinfo->dest->next_output_byte;
+ state.free_in_buffer = cinfo->dest->free_in_buffer;
+ ASSIGN_STATE(state.cur, entropy->saved);
+ state.cinfo = cinfo;
+
+ /* Flush out the last data */
+ if (! flush_bits(&state))
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
+
+ /* Update state */
+ cinfo->dest->next_output_byte = state.next_output_byte;
+ cinfo->dest->free_in_buffer = state.free_in_buffer;
+ ASSIGN_STATE(entropy->saved, state.cur);
+}
+
+
+/*
+ * Huffman coding optimization.
+ *
+ * We first scan the supplied data and count the number of uses of each symbol
+ * that is to be Huffman-coded. (This process MUST agree with the code above.)
+ * Then we build a Huffman coding tree for the observed counts.
+ * Symbols which are not needed at all for the particular image are not
+ * assigned any code, which saves space in the DHT marker as well as in
+ * the compressed data.
+ */
+
+#ifdef ENTROPY_OPT_SUPPORTED
+
+
+/* Process a single block's worth of coefficients */
+
+LOCAL(void)
+htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
+ long dc_counts[], long ac_counts[])
+{
+ register int temp;
+ register int nbits;
+ register int k, r;
+
+ /* Encode the DC coefficient difference per section F.1.2.1 */
+
+ temp = block[0] - last_dc_val;
+ if (temp < 0)
+ temp = -temp;
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 0;
+ while (temp) {
+ nbits++;
+ temp >>= 1;
+ }
+ /* Check for out-of-range coefficient values.
+ * Since we're encoding a difference, the range limit is twice as much.
+ */
+ if (nbits > MAX_COEF_BITS+1)
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
+
+ /* Count the Huffman symbol for the number of bits */
+ dc_counts[nbits]++;
+
+ /* Encode the AC coefficients per section F.1.2.2 */
+
+ r = 0; /* r = run length of zeros */
+
+ for (k = 1; k < DCTSIZE2; k++) {
+ if ((temp = block[jpeg_natural_order[k]]) == 0) {
+ r++;
+ } else {
+ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
+ while (r > 15) {
+ ac_counts[0xF0]++;
+ r -= 16;
+ }
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ if (temp < 0)
+ temp = -temp;
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 1; /* there must be at least one 1 bit */
+ while ((temp >>= 1))
+ nbits++;
+ /* Check for out-of-range coefficient values */
+ if (nbits > MAX_COEF_BITS)
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
+
+ /* Count Huffman symbol for run length / number of bits */
+ ac_counts[(r << 4) + nbits]++;
+
+ r = 0;
+ }
+ }
+
+ /* If the last coef(s) were zero, emit an end-of-block code */
+ if (r > 0)
+ ac_counts[0]++;
+}
+
+
+/*
+ * Trial-encode one MCU's worth of Huffman-compressed coefficients.
+ * No data is actually output, so no suspension return is possible.
+ */
+
+METHODDEF(boolean)
+encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int blkn, ci;
+ jpeg_component_info * compptr;
+
+ /* Take care of restart intervals if needed */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ /* Re-initialize DC predictions to 0 */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++)
+ entropy->saved.last_dc_val[ci] = 0;
+ /* Update restart state */
+ entropy->restarts_to_go = cinfo->restart_interval;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ ci = cinfo->MCU_membership[blkn];
+ compptr = cinfo->cur_comp_info[ci];
+ htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
+ entropy->dc_count_ptrs[compptr->dc_tbl_no],
+ entropy->ac_count_ptrs[compptr->ac_tbl_no]);
+ entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Generate the best Huffman code table for the given counts, fill htbl.
+ * Note this is also used by jcphuff.c.
+ *
+ * The JPEG standard requires that no symbol be assigned a codeword of all
+ * one bits (so that padding bits added at the end of a compressed segment
+ * can't look like a valid code). Because of the canonical ordering of
+ * codewords, this just means that there must be an unused slot in the
+ * longest codeword length category. Section K.2 of the JPEG spec suggests
+ * reserving such a slot by pretending that symbol 256 is a valid symbol
+ * with count 1. In theory that's not optimal; giving it count zero but
+ * including it in the symbol set anyway should give a better Huffman code.
+ * But the theoretically better code actually seems to come out worse in
+ * practice, because it produces more all-ones bytes (which incur stuffed
+ * zero bytes in the final file). In any case the difference is tiny.
+ *
+ * The JPEG standard requires Huffman codes to be no more than 16 bits long.
+ * If some symbols have a very small but nonzero probability, the Huffman tree
+ * must be adjusted to meet the code length restriction. We currently use
+ * the adjustment method suggested in JPEG section K.2. This method is *not*
+ * optimal; it may not choose the best possible limited-length code. But
+ * typically only very-low-frequency symbols will be given less-than-optimal
+ * lengths, so the code is almost optimal. Experimental comparisons against
+ * an optimal limited-length-code algorithm indicate that the difference is
+ * microscopic --- usually less than a hundredth of a percent of total size.
+ * So the extra complexity of an optimal algorithm doesn't seem worthwhile.
+ */
+
+GLOBAL(void)
+jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
+{
+#define MAX_CLEN 32 /* assumed maximum initial code length */
+ UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
+ int codesize[257]; /* codesize[k] = code length of symbol k */
+ int others[257]; /* next symbol in current branch of tree */
+ int c1, c2;
+ int p, i, j;
+ long v;
+
+ /* This algorithm is explained in section K.2 of the JPEG standard */
+
+ MEMZERO(bits, SIZEOF(bits));
+ MEMZERO(codesize, SIZEOF(codesize));
+ for (i = 0; i < 257; i++)
+ others[i] = -1; /* init links to empty */
+
+ freq[256] = 1; /* make sure 256 has a nonzero count */
+ /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
+ * that no real symbol is given code-value of all ones, because 256
+ * will be placed last in the largest codeword category.
+ */
+
+ /* Huffman's basic algorithm to assign optimal code lengths to symbols */
+
+ for (;;) {
+ /* Find the smallest nonzero frequency, set c1 = its symbol */
+ /* In case of ties, take the larger symbol number */
+ c1 = -1;
+ v = 1000000000L;
+ for (i = 0; i <= 256; i++) {
+ if (freq[i] && freq[i] <= v) {
+ v = freq[i];
+ c1 = i;
+ }
+ }
+
+ /* Find the next smallest nonzero frequency, set c2 = its symbol */
+ /* In case of ties, take the larger symbol number */
+ c2 = -1;
+ v = 1000000000L;
+ for (i = 0; i <= 256; i++) {
+ if (freq[i] && freq[i] <= v && i != c1) {
+ v = freq[i];
+ c2 = i;
+ }
+ }
+
+ /* Done if we've merged everything into one frequency */
+ if (c2 < 0)
+ break;
+
+ /* Else merge the two counts/trees */
+ freq[c1] += freq[c2];
+ freq[c2] = 0;
+
+ /* Increment the codesize of everything in c1's tree branch */
+ codesize[c1]++;
+ while (others[c1] >= 0) {
+ c1 = others[c1];
+ codesize[c1]++;
+ }
+
+ others[c1] = c2; /* chain c2 onto c1's tree branch */
+
+ /* Increment the codesize of everything in c2's tree branch */
+ codesize[c2]++;
+ while (others[c2] >= 0) {
+ c2 = others[c2];
+ codesize[c2]++;
+ }
+ }
+
+ /* Now count the number of symbols of each code length */
+ for (i = 0; i <= 256; i++) {
+ if (codesize[i]) {
+ /* The JPEG standard seems to think that this can't happen, */
+ /* but I'm paranoid... */
+ if (codesize[i] > MAX_CLEN)
+ ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
+
+ bits[codesize[i]]++;
+ }
+ }
+
+ /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
+ * Huffman procedure assigned any such lengths, we must adjust the coding.
+ * Here is what the JPEG spec says about how this next bit works:
+ * Since symbols are paired for the longest Huffman code, the symbols are
+ * removed from this length category two at a time. The prefix for the pair
+ * (which is one bit shorter) is allocated to one of the pair; then,
+ * skipping the BITS entry for that prefix length, a code word from the next
+ * shortest nonzero BITS entry is converted into a prefix for two code words
+ * one bit longer.
+ */
+
+ for (i = MAX_CLEN; i > 16; i--) {
+ while (bits[i] > 0) {
+ j = i - 2; /* find length of new prefix to be used */
+ while (bits[j] == 0)
+ j--;
+
+ bits[i] -= 2; /* remove two symbols */
+ bits[i-1]++; /* one goes in this length */
+ bits[j+1] += 2; /* two new symbols in this length */
+ bits[j]--; /* symbol of this length is now a prefix */
+ }
+ }
+
+ /* Remove the count for the pseudo-symbol 256 from the largest codelength */
+ while (bits[i] == 0) /* find largest codelength still in use */
+ i--;
+ bits[i]--;
+
+ /* Return final symbol counts (only for lengths 0..16) */
+ MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
+
+ /* Return a list of the symbols sorted by code length */
+ /* It's not real clear to me why we don't need to consider the codelength
+ * changes made above, but the JPEG spec seems to think this works.
+ */
+ p = 0;
+ for (i = 1; i <= MAX_CLEN; i++) {
+ for (j = 0; j <= 255; j++) {
+ if (codesize[j] == i) {
+ htbl->huffval[p] = (UINT8) j;
+ p++;
+ }
+ }
+ }
+
+ /* Set sent_table FALSE so updated table will be written to JPEG file. */
+ htbl->sent_table = FALSE;
+}
+
+
+/*
+ * Finish up a statistics-gathering pass and create the new Huffman tables.
+ */
+
+METHODDEF(void)
+finish_pass_gather (j_compress_ptr cinfo)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int ci, dctbl, actbl;
+ jpeg_component_info * compptr;
+ JHUFF_TBL **htblptr;
+ boolean did_dc[NUM_HUFF_TBLS];
+ boolean did_ac[NUM_HUFF_TBLS];
+
+ /* It's important not to apply jpeg_gen_optimal_table more than once
+ * per table, because it clobbers the input frequency counts!
+ */
+ MEMZERO(did_dc, SIZEOF(did_dc));
+ MEMZERO(did_ac, SIZEOF(did_ac));
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ dctbl = compptr->dc_tbl_no;
+ actbl = compptr->ac_tbl_no;
+ if (! did_dc[dctbl]) {
+ htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
+ if (*htblptr == NULL)
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
+ jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
+ did_dc[dctbl] = TRUE;
+ }
+ if (! did_ac[actbl]) {
+ htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
+ if (*htblptr == NULL)
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
+ jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
+ did_ac[actbl] = TRUE;
+ }
+ }
+}
+
+
+#endif /* ENTROPY_OPT_SUPPORTED */
+
+
+/*
+ * Module initialization routine for Huffman entropy encoding.
+ */
+
+GLOBAL(void)
+jinit_huff_encoder (j_compress_ptr cinfo)
+{
+ huff_entropy_ptr entropy;
+ int i;
+
+ entropy = (huff_entropy_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(huff_entropy_encoder));
+ cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
+ entropy->pub.start_pass = start_pass_huff;
+
+ /* Mark tables unallocated */
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
+#ifdef ENTROPY_OPT_SUPPORTED
+ entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
+#endif
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jchuff.h b/osframework/source/ImageLib/jpeg/jchuff.h
new file mode 100644
index 0000000..8c02c09
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jchuff.h
@@ -0,0 +1,47 @@
+/*
+ * jchuff.h
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains declarations for Huffman entropy encoding routines
+ * that are shared between the sequential encoder (jchuff.c) and the
+ * progressive encoder (jcphuff.c). No other modules need to see these.
+ */
+
+/* The legal range of a DCT coefficient is
+ * -1024 .. +1023 for 8-bit data;
+ * -16384 .. +16383 for 12-bit data.
+ * Hence the magnitude should always fit in 10 or 14 bits respectively.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define MAX_COEF_BITS 10
+#else
+#define MAX_COEF_BITS 14
+#endif
+
+/* Derived data constructed for each Huffman table */
+
+typedef struct {
+ unsigned int ehufco[256]; /* code for each symbol */
+ char ehufsi[256]; /* length of code for each symbol */
+ /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
+} c_derived_tbl;
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_make_c_derived_tbl jMkCDerived
+#define jpeg_gen_optimal_table jGenOptTbl
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+/* Expand a Huffman table definition into the derived format */
+EXTERN(void) jpeg_make_c_derived_tbl
+ JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
+ c_derived_tbl ** pdtbl));
+
+/* Generate an optimal table definition given the specified counts */
+EXTERN(void) jpeg_gen_optimal_table
+ JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
diff --git a/osframework/source/ImageLib/jpeg/jcinit.c b/osframework/source/ImageLib/jpeg/jcinit.c
new file mode 100644
index 0000000..19de8d0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcinit.c
@@ -0,0 +1,72 @@
+/*
+ * jcinit.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains initialization logic for the JPEG compressor.
+ * This routine is in charge of selecting the modules to be executed and
+ * making an initialization call to each one.
+ *
+ * Logically, this code belongs in jcmaster.c. It's split out because
+ * linking this routine implies linking the entire compression library.
+ * For a transcoding-only application, we want to be able to use jcmaster.c
+ * without linking in the whole library.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Master selection of compression modules.
+ * This is done once at the start of processing an image. We determine
+ * which modules will be used and give them appropriate initialization calls.
+ */
+
+GLOBAL(void)
+jinit_compress_master (j_compress_ptr cinfo)
+{
+ /* Initialize master control (includes parameter checking/processing) */
+ jinit_c_master_control(cinfo, FALSE /* full compression */);
+
+ /* Preprocessing */
+ if (! cinfo->raw_data_in) {
+ jinit_color_converter(cinfo);
+ jinit_downsampler(cinfo);
+ jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
+ }
+ /* Forward DCT */
+ jinit_forward_dct(cinfo);
+ /* Entropy encoding: either Huffman or arithmetic coding. */
+ if (cinfo->arith_code) {
+ ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
+ } else {
+ if (cinfo->progressive_mode) {
+#ifdef C_PROGRESSIVE_SUPPORTED
+ jinit_phuff_encoder(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else
+ jinit_huff_encoder(cinfo);
+ }
+
+ /* Need a full-image coefficient buffer in any multi-pass mode. */
+ jinit_c_coef_controller(cinfo,
+ (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
+ jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
+
+ jinit_marker_writer(cinfo);
+
+ /* We can now tell the memory manager to allocate virtual arrays. */
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
+
+ /* Write the datastream header (SOI) immediately.
+ * Frame and scan headers are postponed till later.
+ * This lets application insert special markers after the SOI.
+ */
+ (*cinfo->marker->write_file_header) (cinfo);
+}
diff --git a/osframework/source/ImageLib/jpeg/jcmainct.c b/osframework/source/ImageLib/jpeg/jcmainct.c
new file mode 100644
index 0000000..14aa4c7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcmainct.c
@@ -0,0 +1,293 @@
+/*
+ * jcmainct.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the main buffer controller for compression.
+ * The main buffer lies between the pre-processor and the JPEG
+ * compressor proper; it holds downsampled data in the JPEG colorspace.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Note: currently, there is no operating mode in which a full-image buffer
+ * is needed at this step. If there were, that mode could not be used with
+ * "raw data" input, since this module is bypassed in that case. However,
+ * we've left the code here for possible use in special applications.
+ */
+#undef FULL_MAIN_BUFFER_SUPPORTED
+
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_c_main_controller pub; /* public fields */
+
+ JDIMENSION cur_iMCU_row; /* number of current iMCU row */
+ JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
+ boolean suspended; /* remember if we suspended output */
+ J_BUF_MODE pass_mode; /* current operating mode */
+
+ /* If using just a strip buffer, this points to the entire set of buffers
+ * (we allocate one for each component). In the full-image case, this
+ * points to the currently accessible strips of the virtual arrays.
+ */
+ JSAMPARRAY buffer[MAX_COMPONENTS];
+
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+ /* If using full-image storage, this array holds pointers to virtual-array
+ * control blocks for each component. Unused if not full-image storage.
+ */
+ jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
+#endif
+} my_main_controller;
+
+typedef my_main_controller * my_main_ptr;
+
+
+/* Forward declarations */
+METHODDEF(void) process_data_simple_main
+ JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
+ JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+METHODDEF(void) process_data_buffer_main
+ JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
+ JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
+#endif
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+
+ /* Do nothing in raw-data mode. */
+ if (cinfo->raw_data_in)
+ return;
+
+ main->cur_iMCU_row = 0; /* initialize counters */
+ main->rowgroup_ctr = 0;
+ main->suspended = FALSE;
+ main->pass_mode = pass_mode; /* save mode for use by process_data */
+
+ switch (pass_mode) {
+ case JBUF_PASS_THRU:
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+ if (main->whole_image[0] != NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+#endif
+ main->pub.process_data = process_data_simple_main;
+ break;
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+ case JBUF_SAVE_SOURCE:
+ case JBUF_CRANK_DEST:
+ case JBUF_SAVE_AND_PASS:
+ if (main->whole_image[0] == NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ main->pub.process_data = process_data_buffer_main;
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ break;
+ }
+}
+
+
+/*
+ * Process some data.
+ * This routine handles the simple pass-through mode,
+ * where we have only a strip buffer.
+ */
+
+METHODDEF(void)
+process_data_simple_main (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+
+ while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
+ /* Read input data if we haven't filled the main buffer yet */
+ if (main->rowgroup_ctr < DCTSIZE)
+ (*cinfo->prep->pre_process_data) (cinfo,
+ input_buf, in_row_ctr, in_rows_avail,
+ main->buffer, &main->rowgroup_ctr,
+ (JDIMENSION) DCTSIZE);
+
+ /* If we don't have a full iMCU row buffered, return to application for
+ * more data. Note that preprocessor will always pad to fill the iMCU row
+ * at the bottom of the image.
+ */
+ if (main->rowgroup_ctr != DCTSIZE)
+ return;
+
+ /* Send the completed row to the compressor */
+ if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
+ /* If compressor did not consume the whole row, then we must need to
+ * suspend processing and return to the application. In this situation
+ * we pretend we didn't yet consume the last input row; otherwise, if
+ * it happened to be the last row of the image, the application would
+ * think we were done.
+ */
+ if (! main->suspended) {
+ (*in_row_ctr)--;
+ main->suspended = TRUE;
+ }
+ return;
+ }
+ /* We did finish the row. Undo our little suspension hack if a previous
+ * call suspended; then mark the main buffer empty.
+ */
+ if (main->suspended) {
+ (*in_row_ctr)++;
+ main->suspended = FALSE;
+ }
+ main->rowgroup_ctr = 0;
+ main->cur_iMCU_row++;
+ }
+}
+
+
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+
+/*
+ * Process some data.
+ * This routine handles all of the modes that use a full-size buffer.
+ */
+
+METHODDEF(void)
+process_data_buffer_main (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ int ci;
+ jpeg_component_info *compptr;
+ boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
+
+ while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
+ /* Realign the virtual buffers if at the start of an iMCU row. */
+ if (main->rowgroup_ctr == 0) {
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, main->whole_image[ci],
+ main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
+ (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
+ }
+ /* In a read pass, pretend we just read some source data. */
+ if (! writing) {
+ *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
+ main->rowgroup_ctr = DCTSIZE;
+ }
+ }
+
+ /* If a write pass, read input data until the current iMCU row is full. */
+ /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
+ if (writing) {
+ (*cinfo->prep->pre_process_data) (cinfo,
+ input_buf, in_row_ctr, in_rows_avail,
+ main->buffer, &main->rowgroup_ctr,
+ (JDIMENSION) DCTSIZE);
+ /* Return to application if we need more data to fill the iMCU row. */
+ if (main->rowgroup_ctr < DCTSIZE)
+ return;
+ }
+
+ /* Emit data, unless this is a sink-only pass. */
+ if (main->pass_mode != JBUF_SAVE_SOURCE) {
+ if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
+ /* If compressor did not consume the whole row, then we must need to
+ * suspend processing and return to the application. In this situation
+ * we pretend we didn't yet consume the last input row; otherwise, if
+ * it happened to be the last row of the image, the application would
+ * think we were done.
+ */
+ if (! main->suspended) {
+ (*in_row_ctr)--;
+ main->suspended = TRUE;
+ }
+ return;
+ }
+ /* We did finish the row. Undo our little suspension hack if a previous
+ * call suspended; then mark the main buffer empty.
+ */
+ if (main->suspended) {
+ (*in_row_ctr)++;
+ main->suspended = FALSE;
+ }
+ }
+
+ /* If get here, we are done with this iMCU row. Mark buffer empty. */
+ main->rowgroup_ctr = 0;
+ main->cur_iMCU_row++;
+ }
+}
+
+#endif /* FULL_MAIN_BUFFER_SUPPORTED */
+
+
+/*
+ * Initialize main buffer controller.
+ */
+
+GLOBAL(void)
+jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
+{
+ my_main_ptr main;
+ int ci;
+ jpeg_component_info *compptr;
+
+ main = (my_main_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_main_controller));
+ cinfo->main = (struct jpeg_c_main_controller *) main;
+ main->pub.start_pass = start_pass_main;
+
+ /* We don't need to create a buffer in raw-data mode. */
+ if (cinfo->raw_data_in)
+ return;
+
+ /* Create the buffer. It holds downsampled data, so each component
+ * may be of a different size.
+ */
+ if (need_full_buffer) {
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+ /* Allocate a full-image virtual array for each component */
+ /* Note we pad the bottom to a multiple of the iMCU height */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ compptr->width_in_blocks * DCTSIZE,
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor) * DCTSIZE,
+ (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
+ }
+#else
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+#endif
+ } else {
+#ifdef FULL_MAIN_BUFFER_SUPPORTED
+ main->whole_image[0] = NULL; /* flag for no virtual arrays */
+#endif
+ /* Allocate a strip buffer for each component */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ main->buffer[ci] = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ compptr->width_in_blocks * DCTSIZE,
+ (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
+ }
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jcmarker.c b/osframework/source/ImageLib/jpeg/jcmarker.c
new file mode 100644
index 0000000..0d3ca5e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcmarker.c
@@ -0,0 +1,664 @@
+/*
+ * jcmarker.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write JPEG datastream markers.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+typedef enum { /* JPEG marker codes */
+ M_SOF0 = 0xc0,
+ M_SOF1 = 0xc1,
+ M_SOF2 = 0xc2,
+ M_SOF3 = 0xc3,
+
+ M_SOF5 = 0xc5,
+ M_SOF6 = 0xc6,
+ M_SOF7 = 0xc7,
+
+ M_JPG = 0xc8,
+ M_SOF9 = 0xc9,
+ M_SOF10 = 0xca,
+ M_SOF11 = 0xcb,
+
+ M_SOF13 = 0xcd,
+ M_SOF14 = 0xce,
+ M_SOF15 = 0xcf,
+
+ M_DHT = 0xc4,
+
+ M_DAC = 0xcc,
+
+ M_RST0 = 0xd0,
+ M_RST1 = 0xd1,
+ M_RST2 = 0xd2,
+ M_RST3 = 0xd3,
+ M_RST4 = 0xd4,
+ M_RST5 = 0xd5,
+ M_RST6 = 0xd6,
+ M_RST7 = 0xd7,
+
+ M_SOI = 0xd8,
+ M_EOI = 0xd9,
+ M_SOS = 0xda,
+ M_DQT = 0xdb,
+ M_DNL = 0xdc,
+ M_DRI = 0xdd,
+ M_DHP = 0xde,
+ M_EXP = 0xdf,
+
+ M_APP0 = 0xe0,
+ M_APP1 = 0xe1,
+ M_APP2 = 0xe2,
+ M_APP3 = 0xe3,
+ M_APP4 = 0xe4,
+ M_APP5 = 0xe5,
+ M_APP6 = 0xe6,
+ M_APP7 = 0xe7,
+ M_APP8 = 0xe8,
+ M_APP9 = 0xe9,
+ M_APP10 = 0xea,
+ M_APP11 = 0xeb,
+ M_APP12 = 0xec,
+ M_APP13 = 0xed,
+ M_APP14 = 0xee,
+ M_APP15 = 0xef,
+
+ M_JPG0 = 0xf0,
+ M_JPG13 = 0xfd,
+ M_COM = 0xfe,
+
+ M_TEM = 0x01,
+
+ M_ERROR = 0x100
+} JPEG_MARKER;
+
+
+/* Private state */
+
+typedef struct {
+ struct jpeg_marker_writer pub; /* public fields */
+
+ unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
+} my_marker_writer;
+
+typedef my_marker_writer * my_marker_ptr;
+
+
+/*
+ * Basic output routines.
+ *
+ * Note that we do not support suspension while writing a marker.
+ * Therefore, an application using suspension must ensure that there is
+ * enough buffer space for the initial markers (typ. 600-700 bytes) before
+ * calling jpeg_start_compress, and enough space to write the trailing EOI
+ * (a few bytes) before calling jpeg_finish_compress. Multipass compression
+ * modes are not supported at all with suspension, so those two are the only
+ * points where markers will be written.
+ */
+
+LOCAL(void)
+emit_byte (j_compress_ptr cinfo, int val)
+/* Emit a byte */
+{
+ struct jpeg_destination_mgr * dest = cinfo->dest;
+
+ *(dest->next_output_byte)++ = (JOCTET) val;
+ if (--dest->free_in_buffer == 0) {
+ if (! (*dest->empty_output_buffer) (cinfo))
+ ERREXIT(cinfo, JERR_CANT_SUSPEND);
+ }
+}
+
+
+LOCAL(void)
+emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
+/* Emit a marker code */
+{
+ emit_byte(cinfo, 0xFF);
+ emit_byte(cinfo, (int) mark);
+}
+
+
+LOCAL(void)
+emit_2bytes (j_compress_ptr cinfo, int value)
+/* Emit a 2-byte integer; these are always MSB first in JPEG files */
+{
+ emit_byte(cinfo, (value >> 8) & 0xFF);
+ emit_byte(cinfo, value & 0xFF);
+}
+
+
+/*
+ * Routines to write specific marker types.
+ */
+
+LOCAL(int)
+emit_dqt (j_compress_ptr cinfo, int index)
+/* Emit a DQT marker */
+/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
+{
+ JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
+ int prec;
+ int i;
+
+ if (qtbl == NULL)
+ ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
+
+ prec = 0;
+ for (i = 0; i < DCTSIZE2; i++) {
+ if (qtbl->quantval[i] > 255)
+ prec = 1;
+ }
+
+ if (! qtbl->sent_table) {
+ emit_marker(cinfo, M_DQT);
+
+ emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
+
+ emit_byte(cinfo, index + (prec<<4));
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ /* The table entries must be emitted in zigzag order. */
+ unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
+ if (prec)
+ emit_byte(cinfo, (int) (qval >> 8));
+ emit_byte(cinfo, (int) (qval & 0xFF));
+ }
+
+ qtbl->sent_table = TRUE;
+ }
+
+ return prec;
+}
+
+
+LOCAL(void)
+emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
+/* Emit a DHT marker */
+{
+ JHUFF_TBL * htbl;
+ int length, i;
+
+ if (is_ac) {
+ htbl = cinfo->ac_huff_tbl_ptrs[index];
+ index += 0x10; /* output index has AC bit set */
+ } else {
+ htbl = cinfo->dc_huff_tbl_ptrs[index];
+ }
+
+ if (htbl == NULL)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
+
+ if (! htbl->sent_table) {
+ emit_marker(cinfo, M_DHT);
+
+ length = 0;
+ for (i = 1; i <= 16; i++)
+ length += htbl->bits[i];
+
+ emit_2bytes(cinfo, length + 2 + 1 + 16);
+ emit_byte(cinfo, index);
+
+ for (i = 1; i <= 16; i++)
+ emit_byte(cinfo, htbl->bits[i]);
+
+ for (i = 0; i < length; i++)
+ emit_byte(cinfo, htbl->huffval[i]);
+
+ htbl->sent_table = TRUE;
+ }
+}
+
+
+LOCAL(void)
+emit_dac (j_compress_ptr cinfo)
+/* Emit a DAC marker */
+/* Since the useful info is so small, we want to emit all the tables in */
+/* one DAC marker. Therefore this routine does its own scan of the table. */
+{
+#ifdef C_ARITH_CODING_SUPPORTED
+ char dc_in_use[NUM_ARITH_TBLS];
+ char ac_in_use[NUM_ARITH_TBLS];
+ int length, i;
+ jpeg_component_info *compptr;
+
+ for (i = 0; i < NUM_ARITH_TBLS; i++)
+ dc_in_use[i] = ac_in_use[i] = 0;
+
+ for (i = 0; i < cinfo->comps_in_scan; i++) {
+ compptr = cinfo->cur_comp_info[i];
+ dc_in_use[compptr->dc_tbl_no] = 1;
+ ac_in_use[compptr->ac_tbl_no] = 1;
+ }
+
+ length = 0;
+ for (i = 0; i < NUM_ARITH_TBLS; i++)
+ length += dc_in_use[i] + ac_in_use[i];
+
+ emit_marker(cinfo, M_DAC);
+
+ emit_2bytes(cinfo, length*2 + 2);
+
+ for (i = 0; i < NUM_ARITH_TBLS; i++) {
+ if (dc_in_use[i]) {
+ emit_byte(cinfo, i);
+ emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
+ }
+ if (ac_in_use[i]) {
+ emit_byte(cinfo, i + 0x10);
+ emit_byte(cinfo, cinfo->arith_ac_K[i]);
+ }
+ }
+#endif /* C_ARITH_CODING_SUPPORTED */
+}
+
+
+LOCAL(void)
+emit_dri (j_compress_ptr cinfo)
+/* Emit a DRI marker */
+{
+ emit_marker(cinfo, M_DRI);
+
+ emit_2bytes(cinfo, 4); /* fixed length */
+
+ emit_2bytes(cinfo, (int) cinfo->restart_interval);
+}
+
+
+LOCAL(void)
+emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
+/* Emit a SOF marker */
+{
+ int ci;
+ jpeg_component_info *compptr;
+
+ emit_marker(cinfo, code);
+
+ emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
+
+ /* Make sure image isn't bigger than SOF field can handle */
+ if ((long) cinfo->image_height > 65535L ||
+ (long) cinfo->image_width > 65535L)
+ ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
+
+ emit_byte(cinfo, cinfo->data_precision);
+ emit_2bytes(cinfo, (int) cinfo->image_height);
+ emit_2bytes(cinfo, (int) cinfo->image_width);
+
+ emit_byte(cinfo, cinfo->num_components);
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ emit_byte(cinfo, compptr->component_id);
+ emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
+ emit_byte(cinfo, compptr->quant_tbl_no);
+ }
+}
+
+
+LOCAL(void)
+emit_sos (j_compress_ptr cinfo)
+/* Emit a SOS marker */
+{
+ int i, td, ta;
+ jpeg_component_info *compptr;
+
+ emit_marker(cinfo, M_SOS);
+
+ emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
+
+ emit_byte(cinfo, cinfo->comps_in_scan);
+
+ for (i = 0; i < cinfo->comps_in_scan; i++) {
+ compptr = cinfo->cur_comp_info[i];
+ emit_byte(cinfo, compptr->component_id);
+ td = compptr->dc_tbl_no;
+ ta = compptr->ac_tbl_no;
+ if (cinfo->progressive_mode) {
+ /* Progressive mode: only DC or only AC tables are used in one scan;
+ * furthermore, Huffman coding of DC refinement uses no table at all.
+ * We emit 0 for unused field(s); this is recommended by the P&M text
+ * but does not seem to be specified in the standard.
+ */
+ if (cinfo->Ss == 0) {
+ ta = 0; /* DC scan */
+ if (cinfo->Ah != 0 && !cinfo->arith_code)
+ td = 0; /* no DC table either */
+ } else {
+ td = 0; /* AC scan */
+ }
+ }
+ emit_byte(cinfo, (td << 4) + ta);
+ }
+
+ emit_byte(cinfo, cinfo->Ss);
+ emit_byte(cinfo, cinfo->Se);
+ emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
+}
+
+
+LOCAL(void)
+emit_jfif_app0 (j_compress_ptr cinfo)
+/* Emit a JFIF-compliant APP0 marker */
+{
+ /*
+ * Length of APP0 block (2 bytes)
+ * Block ID (4 bytes - ASCII "JFIF")
+ * Zero byte (1 byte to terminate the ID string)
+ * Version Major, Minor (2 bytes - major first)
+ * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
+ * Xdpu (2 bytes - dots per unit horizontal)
+ * Ydpu (2 bytes - dots per unit vertical)
+ * Thumbnail X size (1 byte)
+ * Thumbnail Y size (1 byte)
+ */
+
+ emit_marker(cinfo, M_APP0);
+
+ emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
+
+ emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
+ emit_byte(cinfo, 0x46);
+ emit_byte(cinfo, 0x49);
+ emit_byte(cinfo, 0x46);
+ emit_byte(cinfo, 0);
+ emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
+ emit_byte(cinfo, cinfo->JFIF_minor_version);
+ emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
+ emit_2bytes(cinfo, (int) cinfo->X_density);
+ emit_2bytes(cinfo, (int) cinfo->Y_density);
+ emit_byte(cinfo, 0); /* No thumbnail image */
+ emit_byte(cinfo, 0);
+}
+
+
+LOCAL(void)
+emit_adobe_app14 (j_compress_ptr cinfo)
+/* Emit an Adobe APP14 marker */
+{
+ /*
+ * Length of APP14 block (2 bytes)
+ * Block ID (5 bytes - ASCII "Adobe")
+ * Version Number (2 bytes - currently 100)
+ * Flags0 (2 bytes - currently 0)
+ * Flags1 (2 bytes - currently 0)
+ * Color transform (1 byte)
+ *
+ * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
+ * now in circulation seem to use Version = 100, so that's what we write.
+ *
+ * We write the color transform byte as 1 if the JPEG color space is
+ * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
+ * whether the encoder performed a transformation, which is pretty useless.
+ */
+
+ emit_marker(cinfo, M_APP14);
+
+ emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
+
+ emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
+ emit_byte(cinfo, 0x64);
+ emit_byte(cinfo, 0x6F);
+ emit_byte(cinfo, 0x62);
+ emit_byte(cinfo, 0x65);
+ emit_2bytes(cinfo, 100); /* Version */
+ emit_2bytes(cinfo, 0); /* Flags0 */
+ emit_2bytes(cinfo, 0); /* Flags1 */
+ switch (cinfo->jpeg_color_space) {
+ case JCS_YCbCr:
+ emit_byte(cinfo, 1); /* Color transform = 1 */
+ break;
+ case JCS_YCCK:
+ emit_byte(cinfo, 2); /* Color transform = 2 */
+ break;
+ default:
+ emit_byte(cinfo, 0); /* Color transform = 0 */
+ break;
+ }
+}
+
+
+/*
+ * These routines allow writing an arbitrary marker with parameters.
+ * The only intended use is to emit COM or APPn markers after calling
+ * write_file_header and before calling write_frame_header.
+ * Other uses are not guaranteed to produce desirable results.
+ * Counting the parameter bytes properly is the caller's responsibility.
+ */
+
+METHODDEF(void)
+write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
+/* Emit an arbitrary marker header */
+{
+ if (datalen > (unsigned int) 65533) /* safety check */
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ emit_marker(cinfo, (JPEG_MARKER) marker);
+
+ emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
+}
+
+METHODDEF(void)
+write_marker_byte (j_compress_ptr cinfo, int val)
+/* Emit one byte of marker parameters following write_marker_header */
+{
+ emit_byte(cinfo, val);
+}
+
+
+/*
+ * Write datastream header.
+ * This consists of an SOI and optional APPn markers.
+ * We recommend use of the JFIF marker, but not the Adobe marker,
+ * when using YCbCr or grayscale data. The JFIF marker should NOT
+ * be used for any other JPEG colorspace. The Adobe marker is helpful
+ * to distinguish RGB, CMYK, and YCCK colorspaces.
+ * Note that an application can write additional header markers after
+ * jpeg_start_compress returns.
+ */
+
+METHODDEF(void)
+write_file_header (j_compress_ptr cinfo)
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+
+ emit_marker(cinfo, M_SOI); /* first the SOI */
+
+ /* SOI is defined to reset restart interval to 0 */
+ marker->last_restart_interval = 0;
+
+ if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
+ emit_jfif_app0(cinfo);
+ if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
+ emit_adobe_app14(cinfo);
+}
+
+
+/*
+ * Write frame header.
+ * This consists of DQT and SOFn markers.
+ * Note that we do not emit the SOF until we have emitted the DQT(s).
+ * This avoids compatibility problems with incorrect implementations that
+ * try to error-check the quant table numbers as soon as they see the SOF.
+ */
+
+METHODDEF(void)
+write_frame_header (j_compress_ptr cinfo)
+{
+ int ci, prec;
+ boolean is_baseline;
+ jpeg_component_info *compptr;
+
+ /* Emit DQT for each quantization table.
+ * Note that emit_dqt() suppresses any duplicate tables.
+ */
+ prec = 0;
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ prec += emit_dqt(cinfo, compptr->quant_tbl_no);
+ }
+ /* now prec is nonzero iff there are any 16-bit quant tables. */
+
+ /* Check for a non-baseline specification.
+ * Note we assume that Huffman table numbers won't be changed later.
+ */
+ if (cinfo->arith_code || cinfo->progressive_mode ||
+ cinfo->data_precision != 8) {
+ is_baseline = FALSE;
+ } else {
+ is_baseline = TRUE;
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
+ is_baseline = FALSE;
+ }
+ if (prec && is_baseline) {
+ is_baseline = FALSE;
+ /* If it's baseline except for quantizer size, warn the user */
+ TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
+ }
+ }
+
+ /* Emit the proper SOF marker */
+ if (cinfo->arith_code) {
+ emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
+ } else {
+ if (cinfo->progressive_mode)
+ emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
+ else if (is_baseline)
+ emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
+ else
+ emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
+ }
+}
+
+
+/*
+ * Write scan header.
+ * This consists of DHT or DAC markers, optional DRI, and SOS.
+ * Compressed data will be written following the SOS.
+ */
+
+METHODDEF(void)
+write_scan_header (j_compress_ptr cinfo)
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+ int i;
+ jpeg_component_info *compptr;
+
+ if (cinfo->arith_code) {
+ /* Emit arith conditioning info. We may have some duplication
+ * if the file has multiple scans, but it's so small it's hardly
+ * worth worrying about.
+ */
+ emit_dac(cinfo);
+ } else {
+ /* Emit Huffman tables.
+ * Note that emit_dht() suppresses any duplicate tables.
+ */
+ for (i = 0; i < cinfo->comps_in_scan; i++) {
+ compptr = cinfo->cur_comp_info[i];
+ if (cinfo->progressive_mode) {
+ /* Progressive mode: only DC or only AC tables are used in one scan */
+ if (cinfo->Ss == 0) {
+ if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
+ emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
+ } else {
+ emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
+ }
+ } else {
+ /* Sequential mode: need both DC and AC tables */
+ emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
+ emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
+ }
+ }
+ }
+
+ /* Emit DRI if required --- note that DRI value could change for each scan.
+ * We avoid wasting space with unnecessary DRIs, however.
+ */
+ if (cinfo->restart_interval != marker->last_restart_interval) {
+ emit_dri(cinfo);
+ marker->last_restart_interval = cinfo->restart_interval;
+ }
+
+ emit_sos(cinfo);
+}
+
+
+/*
+ * Write datastream trailer.
+ */
+
+METHODDEF(void)
+write_file_trailer (j_compress_ptr cinfo)
+{
+ emit_marker(cinfo, M_EOI);
+}
+
+
+/*
+ * Write an abbreviated table-specification datastream.
+ * This consists of SOI, DQT and DHT tables, and EOI.
+ * Any table that is defined and not marked sent_table = TRUE will be
+ * emitted. Note that all tables will be marked sent_table = TRUE at exit.
+ */
+
+METHODDEF(void)
+write_tables_only (j_compress_ptr cinfo)
+{
+ int i;
+
+ emit_marker(cinfo, M_SOI);
+
+ for (i = 0; i < NUM_QUANT_TBLS; i++) {
+ if (cinfo->quant_tbl_ptrs[i] != NULL)
+ (void) emit_dqt(cinfo, i);
+ }
+
+ if (! cinfo->arith_code) {
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
+ emit_dht(cinfo, i, FALSE);
+ if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
+ emit_dht(cinfo, i, TRUE);
+ }
+ }
+
+ emit_marker(cinfo, M_EOI);
+}
+
+
+/*
+ * Initialize the marker writer module.
+ */
+
+GLOBAL(void)
+jinit_marker_writer (j_compress_ptr cinfo)
+{
+ my_marker_ptr marker;
+
+ /* Create the subobject */
+ marker = (my_marker_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_marker_writer));
+ cinfo->marker = (struct jpeg_marker_writer *) marker;
+ /* Initialize method pointers */
+ marker->pub.write_file_header = write_file_header;
+ marker->pub.write_frame_header = write_frame_header;
+ marker->pub.write_scan_header = write_scan_header;
+ marker->pub.write_file_trailer = write_file_trailer;
+ marker->pub.write_tables_only = write_tables_only;
+ marker->pub.write_marker_header = write_marker_header;
+ marker->pub.write_marker_byte = write_marker_byte;
+ /* Initialize private state */
+ marker->last_restart_interval = 0;
+}
diff --git a/osframework/source/ImageLib/jpeg/jcmaster.c b/osframework/source/ImageLib/jpeg/jcmaster.c
new file mode 100644
index 0000000..e61138b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcmaster.c
@@ -0,0 +1,590 @@
+/*
+ * jcmaster.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains master control logic for the JPEG compressor.
+ * These routines are concerned with parameter validation, initial setup,
+ * and inter-pass control (determining the number of passes and the work
+ * to be done in each pass).
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private state */
+
+typedef enum {
+ main_pass, /* input data, also do first output step */
+ huff_opt_pass, /* Huffman code optimization pass */
+ output_pass /* data output pass */
+} c_pass_type;
+
+typedef struct {
+ struct jpeg_comp_master pub; /* public fields */
+
+ c_pass_type pass_type; /* the type of the current pass */
+
+ int pass_number; /* # of passes completed */
+ int total_passes; /* total # of passes needed */
+
+ int scan_number; /* current index in scan_info[] */
+} my_comp_master;
+
+typedef my_comp_master * my_master_ptr;
+
+
+/*
+ * Support routines that do various essential calculations.
+ */
+
+LOCAL(void)
+initial_setup (j_compress_ptr cinfo)
+/* Do computations that are needed before master selection phase */
+{
+ int ci;
+ jpeg_component_info *compptr;
+ long samplesperrow;
+ JDIMENSION jd_samplesperrow;
+
+ /* Sanity check on image dimensions */
+ if (cinfo->image_height <= 0 || cinfo->image_width <= 0
+ || cinfo->num_components <= 0 || cinfo->input_components <= 0)
+ ERREXIT(cinfo, JERR_EMPTY_IMAGE);
+
+ /* Make sure image isn't bigger than I can handle */
+ if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
+ (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
+ ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
+
+ /* Width of an input scanline must be representable as JDIMENSION. */
+ samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
+ jd_samplesperrow = (JDIMENSION) samplesperrow;
+ if ((long) jd_samplesperrow != samplesperrow)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+
+ /* For now, precision must match compiled-in value... */
+ if (cinfo->data_precision != BITS_IN_JSAMPLE)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
+
+ /* Check that number of components won't exceed internal array sizes */
+ if (cinfo->num_components > MAX_COMPONENTS)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
+ MAX_COMPONENTS);
+
+ /* Compute maximum sampling factors; check factor validity */
+ cinfo->max_h_samp_factor = 1;
+ cinfo->max_v_samp_factor = 1;
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
+ compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
+ ERREXIT(cinfo, JERR_BAD_SAMPLING);
+ cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
+ compptr->h_samp_factor);
+ cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
+ compptr->v_samp_factor);
+ }
+
+ /* Compute dimensions of components */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Fill in the correct component_index value; don't rely on application */
+ compptr->component_index = ci;
+ /* For compression, we never do DCT scaling. */
+ compptr->DCT_scaled_size = DCTSIZE;
+ /* Size in DCT blocks */
+ compptr->width_in_blocks = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
+ (long) (cinfo->max_h_samp_factor * DCTSIZE));
+ compptr->height_in_blocks = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
+ (long) (cinfo->max_v_samp_factor * DCTSIZE));
+ /* Size in samples */
+ compptr->downsampled_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
+ (long) cinfo->max_h_samp_factor);
+ compptr->downsampled_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
+ (long) cinfo->max_v_samp_factor);
+ /* Mark component needed (this flag isn't actually used for compression) */
+ compptr->component_needed = TRUE;
+ }
+
+ /* Compute number of fully interleaved MCU rows (number of times that
+ * main controller will call coefficient controller).
+ */
+ cinfo->total_iMCU_rows = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height,
+ (long) (cinfo->max_v_samp_factor*DCTSIZE));
+}
+
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+
+LOCAL(void)
+validate_script (j_compress_ptr cinfo)
+/* Verify that the scan script in cinfo->scan_info[] is valid; also
+ * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
+ */
+{
+ const jpeg_scan_info * scanptr;
+ int scanno, ncomps, ci, coefi, thisi;
+ int Ss, Se, Ah, Al;
+ boolean component_sent[MAX_COMPONENTS];
+#ifdef C_PROGRESSIVE_SUPPORTED
+ int * last_bitpos_ptr;
+ int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
+ /* -1 until that coefficient has been seen; then last Al for it */
+#endif
+
+ if (cinfo->num_scans <= 0)
+ ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
+
+ /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
+ * for progressive JPEG, no scan can have this.
+ */
+ scanptr = cinfo->scan_info;
+ if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
+#ifdef C_PROGRESSIVE_SUPPORTED
+ cinfo->progressive_mode = TRUE;
+ last_bitpos_ptr = & last_bitpos[0][0];
+ for (ci = 0; ci < cinfo->num_components; ci++)
+ for (coefi = 0; coefi < DCTSIZE2; coefi++)
+ *last_bitpos_ptr++ = -1;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ cinfo->progressive_mode = FALSE;
+ for (ci = 0; ci < cinfo->num_components; ci++)
+ component_sent[ci] = FALSE;
+ }
+
+ for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
+ /* Validate component indexes */
+ ncomps = scanptr->comps_in_scan;
+ if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
+ for (ci = 0; ci < ncomps; ci++) {
+ thisi = scanptr->component_index[ci];
+ if (thisi < 0 || thisi >= cinfo->num_components)
+ ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
+ /* Components must appear in SOF order within each scan */
+ if (ci > 0 && thisi <= scanptr->component_index[ci-1])
+ ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
+ }
+ /* Validate progression parameters */
+ Ss = scanptr->Ss;
+ Se = scanptr->Se;
+ Ah = scanptr->Ah;
+ Al = scanptr->Al;
+ if (cinfo->progressive_mode) {
+#ifdef C_PROGRESSIVE_SUPPORTED
+ /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
+ * seems wrong: the upper bound ought to depend on data precision.
+ * Perhaps they really meant 0..N+1 for N-bit precision.
+ * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
+ * out-of-range reconstructed DC values during the first DC scan,
+ * which might cause problems for some decoders.
+ */
+#if BITS_IN_JSAMPLE == 8
+#define MAX_AH_AL 10
+#else
+#define MAX_AH_AL 13
+#endif
+ if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
+ Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ if (Ss == 0) {
+ if (Se != 0) /* DC and AC together not OK */
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ } else {
+ if (ncomps != 1) /* AC scans must be for only one component */
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ }
+ for (ci = 0; ci < ncomps; ci++) {
+ last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
+ if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ for (coefi = Ss; coefi <= Se; coefi++) {
+ if (last_bitpos_ptr[coefi] < 0) {
+ /* first scan of this coefficient */
+ if (Ah != 0)
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ } else {
+ /* not first scan */
+ if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ }
+ last_bitpos_ptr[coefi] = Al;
+ }
+ }
+#endif
+ } else {
+ /* For sequential JPEG, all progression parameters must be these: */
+ if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
+ ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
+ /* Make sure components are not sent twice */
+ for (ci = 0; ci < ncomps; ci++) {
+ thisi = scanptr->component_index[ci];
+ if (component_sent[thisi])
+ ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
+ component_sent[thisi] = TRUE;
+ }
+ }
+ }
+
+ /* Now verify that everything got sent. */
+ if (cinfo->progressive_mode) {
+#ifdef C_PROGRESSIVE_SUPPORTED
+ /* For progressive mode, we only check that at least some DC data
+ * got sent for each component; the spec does not require that all bits
+ * of all coefficients be transmitted. Would it be wiser to enforce
+ * transmission of all coefficient bits??
+ */
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ if (last_bitpos[ci][0] < 0)
+ ERREXIT(cinfo, JERR_MISSING_DATA);
+ }
+#endif
+ } else {
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ if (! component_sent[ci])
+ ERREXIT(cinfo, JERR_MISSING_DATA);
+ }
+ }
+}
+
+#endif /* C_MULTISCAN_FILES_SUPPORTED */
+
+
+LOCAL(void)
+select_scan_parameters (j_compress_ptr cinfo)
+/* Set up the scan parameters for the current scan */
+{
+ int ci;
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (cinfo->scan_info != NULL) {
+ /* Prepare for current scan --- the script is already validated */
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+ const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
+
+ cinfo->comps_in_scan = scanptr->comps_in_scan;
+ for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
+ cinfo->cur_comp_info[ci] =
+ &cinfo->comp_info[scanptr->component_index[ci]];
+ }
+ cinfo->Ss = scanptr->Ss;
+ cinfo->Se = scanptr->Se;
+ cinfo->Ah = scanptr->Ah;
+ cinfo->Al = scanptr->Al;
+ }
+ else
+#endif
+ {
+ /* Prepare for single sequential-JPEG scan containing all components */
+ if (cinfo->num_components > MAX_COMPS_IN_SCAN)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
+ MAX_COMPS_IN_SCAN);
+ cinfo->comps_in_scan = cinfo->num_components;
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
+ }
+ cinfo->Ss = 0;
+ cinfo->Se = DCTSIZE2-1;
+ cinfo->Ah = 0;
+ cinfo->Al = 0;
+ }
+}
+
+
+LOCAL(void)
+per_scan_setup (j_compress_ptr cinfo)
+/* Do computations that are needed before processing a JPEG scan */
+/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
+{
+ int ci, mcublks, tmp;
+ jpeg_component_info *compptr;
+
+ if (cinfo->comps_in_scan == 1) {
+
+ /* Noninterleaved (single-component) scan */
+ compptr = cinfo->cur_comp_info[0];
+
+ /* Overall image size in MCUs */
+ cinfo->MCUs_per_row = compptr->width_in_blocks;
+ cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
+
+ /* For noninterleaved scan, always one block per MCU */
+ compptr->MCU_width = 1;
+ compptr->MCU_height = 1;
+ compptr->MCU_blocks = 1;
+ compptr->MCU_sample_width = DCTSIZE;
+ compptr->last_col_width = 1;
+ /* For noninterleaved scans, it is convenient to define last_row_height
+ * as the number of block rows present in the last iMCU row.
+ */
+ tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+ if (tmp == 0) tmp = compptr->v_samp_factor;
+ compptr->last_row_height = tmp;
+
+ /* Prepare array describing MCU composition */
+ cinfo->blocks_in_MCU = 1;
+ cinfo->MCU_membership[0] = 0;
+
+ } else {
+
+ /* Interleaved (multi-component) scan */
+ if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
+ MAX_COMPS_IN_SCAN);
+
+ /* Overall image size in MCUs */
+ cinfo->MCUs_per_row = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width,
+ (long) (cinfo->max_h_samp_factor*DCTSIZE));
+ cinfo->MCU_rows_in_scan = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height,
+ (long) (cinfo->max_v_samp_factor*DCTSIZE));
+
+ cinfo->blocks_in_MCU = 0;
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* Sampling factors give # of blocks of component in each MCU */
+ compptr->MCU_width = compptr->h_samp_factor;
+ compptr->MCU_height = compptr->v_samp_factor;
+ compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
+ compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
+ /* Figure number of non-dummy blocks in last MCU column & row */
+ tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
+ if (tmp == 0) tmp = compptr->MCU_width;
+ compptr->last_col_width = tmp;
+ tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
+ if (tmp == 0) tmp = compptr->MCU_height;
+ compptr->last_row_height = tmp;
+ /* Prepare array describing MCU composition */
+ mcublks = compptr->MCU_blocks;
+ if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
+ ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
+ while (mcublks-- > 0) {
+ cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
+ }
+ }
+
+ }
+
+ /* Convert restart specified in rows to actual MCU count. */
+ /* Note that count must fit in 16 bits, so we provide limiting. */
+ if (cinfo->restart_in_rows > 0) {
+ long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
+ cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
+ }
+}
+
+
+/*
+ * Per-pass setup.
+ * This is called at the beginning of each pass. We determine which modules
+ * will be active during this pass and give them appropriate start_pass calls.
+ * We also set is_last_pass to indicate whether any more passes will be
+ * required.
+ */
+
+METHODDEF(void)
+prepare_for_pass (j_compress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+
+ switch (master->pass_type) {
+ case main_pass:
+ /* Initial pass: will collect input data, and do either Huffman
+ * optimization or data output for the first scan.
+ */
+ select_scan_parameters(cinfo);
+ per_scan_setup(cinfo);
+ if (! cinfo->raw_data_in) {
+ (*cinfo->cconvert->start_pass) (cinfo);
+ (*cinfo->downsample->start_pass) (cinfo);
+ (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
+ }
+ (*cinfo->fdct->start_pass) (cinfo);
+ (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
+ (*cinfo->coef->start_pass) (cinfo,
+ (master->total_passes > 1 ?
+ JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
+ (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
+ if (cinfo->optimize_coding) {
+ /* No immediate data output; postpone writing frame/scan headers */
+ master->pub.call_pass_startup = FALSE;
+ } else {
+ /* Will write frame/scan headers at first jpeg_write_scanlines call */
+ master->pub.call_pass_startup = TRUE;
+ }
+ break;
+#ifdef ENTROPY_OPT_SUPPORTED
+ case huff_opt_pass:
+ /* Do Huffman optimization for a scan after the first one. */
+ select_scan_parameters(cinfo);
+ per_scan_setup(cinfo);
+ if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
+ (*cinfo->entropy->start_pass) (cinfo, TRUE);
+ (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
+ master->pub.call_pass_startup = FALSE;
+ break;
+ }
+ /* Special case: Huffman DC refinement scans need no Huffman table
+ * and therefore we can skip the optimization pass for them.
+ */
+ master->pass_type = output_pass;
+ master->pass_number++;
+ /*FALLTHROUGH*/
+#endif
+ case output_pass:
+ /* Do a data-output pass. */
+ /* We need not repeat per-scan setup if prior optimization pass did it. */
+ if (! cinfo->optimize_coding) {
+ select_scan_parameters(cinfo);
+ per_scan_setup(cinfo);
+ }
+ (*cinfo->entropy->start_pass) (cinfo, FALSE);
+ (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
+ /* We emit frame/scan headers now */
+ if (master->scan_number == 0)
+ (*cinfo->marker->write_frame_header) (cinfo);
+ (*cinfo->marker->write_scan_header) (cinfo);
+ master->pub.call_pass_startup = FALSE;
+ break;
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ }
+
+ master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
+
+ /* Set up progress monitor's pass info if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->completed_passes = master->pass_number;
+ cinfo->progress->total_passes = master->total_passes;
+ }
+}
+
+
+/*
+ * Special start-of-pass hook.
+ * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
+ * In single-pass processing, we need this hook because we don't want to
+ * write frame/scan headers during jpeg_start_compress; we want to let the
+ * application write COM markers etc. between jpeg_start_compress and the
+ * jpeg_write_scanlines loop.
+ * In multi-pass processing, this routine is not used.
+ */
+
+METHODDEF(void)
+pass_startup (j_compress_ptr cinfo)
+{
+ cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
+
+ (*cinfo->marker->write_frame_header) (cinfo);
+ (*cinfo->marker->write_scan_header) (cinfo);
+}
+
+
+/*
+ * Finish up at end of pass.
+ */
+
+METHODDEF(void)
+finish_pass_master (j_compress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+
+ /* The entropy coder always needs an end-of-pass call,
+ * either to analyze statistics or to flush its output buffer.
+ */
+ (*cinfo->entropy->finish_pass) (cinfo);
+
+ /* Update state for next pass */
+ switch (master->pass_type) {
+ case main_pass:
+ /* next pass is either output of scan 0 (after optimization)
+ * or output of scan 1 (if no optimization).
+ */
+ master->pass_type = output_pass;
+ if (! cinfo->optimize_coding)
+ master->scan_number++;
+ break;
+ case huff_opt_pass:
+ /* next pass is always output of current scan */
+ master->pass_type = output_pass;
+ break;
+ case output_pass:
+ /* next pass is either optimization or output of next scan */
+ if (cinfo->optimize_coding)
+ master->pass_type = huff_opt_pass;
+ master->scan_number++;
+ break;
+ }
+
+ master->pass_number++;
+}
+
+
+/*
+ * Initialize master compression control.
+ */
+
+GLOBAL(void)
+jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
+{
+ my_master_ptr master;
+
+ master = (my_master_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_comp_master));
+ cinfo->master = (struct jpeg_comp_master *) master;
+ master->pub.prepare_for_pass = prepare_for_pass;
+ master->pub.pass_startup = pass_startup;
+ master->pub.finish_pass = finish_pass_master;
+ master->pub.is_last_pass = FALSE;
+
+ /* Validate parameters, determine derived values */
+ initial_setup(cinfo);
+
+ if (cinfo->scan_info != NULL) {
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ validate_script(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ cinfo->progressive_mode = FALSE;
+ cinfo->num_scans = 1;
+ }
+
+ if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
+ cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
+
+ /* Initialize my private state */
+ if (transcode_only) {
+ /* no main pass in transcoding */
+ if (cinfo->optimize_coding)
+ master->pass_type = huff_opt_pass;
+ else
+ master->pass_type = output_pass;
+ } else {
+ /* for normal compression, first pass is always this type: */
+ master->pass_type = main_pass;
+ }
+ master->scan_number = 0;
+ master->pass_number = 0;
+ if (cinfo->optimize_coding)
+ master->total_passes = cinfo->num_scans * 2;
+ else
+ master->total_passes = cinfo->num_scans;
+}
diff --git a/osframework/source/ImageLib/jpeg/jcomapi.c b/osframework/source/ImageLib/jpeg/jcomapi.c
new file mode 100644
index 0000000..1b1a340
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcomapi.c
@@ -0,0 +1,106 @@
+/*
+ * jcomapi.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains application interface routines that are used for both
+ * compression and decompression.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Abort processing of a JPEG compression or decompression operation,
+ * but don't destroy the object itself.
+ *
+ * For this, we merely clean up all the nonpermanent memory pools.
+ * Note that temp files (virtual arrays) are not allowed to belong to
+ * the permanent pool, so we will be able to close all temp files here.
+ * Closing a data source or destination, if necessary, is the application's
+ * responsibility.
+ */
+
+GLOBAL(void)
+jpeg_abort (j_common_ptr cinfo)
+{
+ int pool;
+
+ /* Do nothing if called on a not-initialized or destroyed JPEG object. */
+ if (cinfo->mem == NULL)
+ return;
+
+ /* Releasing pools in reverse order might help avoid fragmentation
+ * with some (brain-damaged) malloc libraries.
+ */
+ for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
+ (*cinfo->mem->free_pool) (cinfo, pool);
+ }
+
+ /* Reset overall state for possible reuse of object */
+ if (cinfo->is_decompressor) {
+ cinfo->global_state = DSTATE_START;
+ /* Try to keep application from accessing now-deleted marker list.
+ * A bit kludgy to do it here, but this is the most central place.
+ */
+ ((j_decompress_ptr) cinfo)->marker_list = NULL;
+ } else {
+ cinfo->global_state = CSTATE_START;
+ }
+}
+
+
+/*
+ * Destruction of a JPEG object.
+ *
+ * Everything gets deallocated except the master jpeg_compress_struct itself
+ * and the error manager struct. Both of these are supplied by the application
+ * and must be freed, if necessary, by the application. (Often they are on
+ * the stack and so don't need to be freed anyway.)
+ * Closing a data source or destination, if necessary, is the application's
+ * responsibility.
+ */
+
+GLOBAL(void)
+jpeg_destroy (j_common_ptr cinfo)
+{
+ /* We need only tell the memory manager to release everything. */
+ /* NB: mem pointer is NULL if memory mgr failed to initialize. */
+ if (cinfo->mem != NULL)
+ (*cinfo->mem->self_destruct) (cinfo);
+ cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
+ cinfo->global_state = 0; /* mark it destroyed */
+}
+
+
+/*
+ * Convenience routines for allocating quantization and Huffman tables.
+ * (Would jutils.c be a more reasonable place to put these?)
+ */
+
+GLOBAL(JQUANT_TBL *)
+jpeg_alloc_quant_table (j_common_ptr cinfo)
+{
+ JQUANT_TBL *tbl;
+
+ tbl = (JQUANT_TBL *)
+ (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
+ tbl->sent_table = FALSE; /* make sure this is false in any new table */
+ return tbl;
+}
+
+
+GLOBAL(JHUFF_TBL *)
+jpeg_alloc_huff_table (j_common_ptr cinfo)
+{
+ JHUFF_TBL *tbl;
+
+ tbl = (JHUFF_TBL *)
+ (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
+ tbl->sent_table = FALSE; /* make sure this is false in any new table */
+ return tbl;
+}
diff --git a/osframework/source/ImageLib/jpeg/jconfig.bcc b/osframework/source/ImageLib/jpeg/jconfig.bcc
new file mode 100644
index 0000000..6538a0f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.bcc
@@ -0,0 +1,48 @@
+/* jconfig.bcc --- jconfig.h for Borland C (Turbo C) on MS-DOS or OS/2. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#ifdef __MSDOS__
+#define NEED_FAR_POINTERS /* for small or medium memory model */
+#endif
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN /* this assumes you have -w-stu in CFLAGS */
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#ifdef __MSDOS__
+#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
+#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
+#define USE_FMEM /* Borland has _fmemcpy() and _fmemset() */
+#endif
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE
+#define USE_SETMODE /* Borland has setmode() */
+#ifdef __MSDOS__
+#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */
+#endif
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.cfg b/osframework/source/ImageLib/jpeg/jconfig.cfg
new file mode 100644
index 0000000..5bc0113
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.cfg
@@ -0,0 +1,44 @@
+/* jconfig.cfg --- source file edited by configure script */
+/* see jconfig.doc for explanations */
+
+#undef HAVE_PROTOTYPES
+#undef HAVE_UNSIGNED_CHAR
+#undef HAVE_UNSIGNED_SHORT
+#undef void
+#undef const
+#undef CHAR_IS_UNSIGNED
+#undef HAVE_STDDEF_H
+#undef HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+/* Define this if you get warnings about undefined structures. */
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+#undef INLINE
+/* These are for configuring the JPEG memory manager. */
+#undef DEFAULT_MAX_MEM
+#undef NO_MKTEMP
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+
+/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
+#undef PROGRESS_REPORT
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.dj b/osframework/source/ImageLib/jpeg/jconfig.dj
new file mode 100644
index 0000000..7cd1ed5
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.dj
@@ -0,0 +1,38 @@
+/* jconfig.dj --- jconfig.h for DJGPP (Delorie's GNU C port) on MS-DOS. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS /* DJGPP uses flat 32-bit addressing */
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE /* optional */
+#define USE_SETMODE /* Needed to make one-file style work in DJGPP */
+#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.h b/osframework/source/ImageLib/jpeg/jconfig.h
new file mode 100644
index 0000000..9da2736
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.h
@@ -0,0 +1,43 @@
+/* jconfig.h. Generated automatically by configure. */
+/* jconfig.cfg --- source file edited by configure script */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+/* Define this if you get warnings about undefined structures. */
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+#define INLINE
+/* These are for configuring the JPEG memory manager. */
+#undef DEFAULT_MAX_MEM
+#undef NO_MKTEMP
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+
+/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
+#undef PROGRESS_REPORT
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.mac b/osframework/source/ImageLib/jpeg/jconfig.mac
new file mode 100644
index 0000000..1db67f5
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.mac
@@ -0,0 +1,43 @@
+/* jconfig.mac --- jconfig.h for CodeWarrior on Apple Macintosh */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#define USE_MAC_MEMMGR /* Define this if you use jmemmac.c */
+
+#define ALIGN_TYPE long /* Needed for 680x0 Macs */
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define USE_CCOMMAND /* Command line reader for Macintosh */
+#define TWO_FILE_COMMANDLINE /* Binary I/O thru stdin/stdout doesn't work */
+
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.manx b/osframework/source/ImageLib/jpeg/jconfig.manx
new file mode 100644
index 0000000..0dbd0b8
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.manx
@@ -0,0 +1,43 @@
+/* jconfig.manx --- jconfig.h for Amiga systems using Manx Aztec C ver 5.x. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
+
+#define SHORTxSHORT_32 /* produces better DCT code with Aztec C */
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE
+#define NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#define signal_catcher _abort /* hack for Aztec C naming requirements */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.mc6 b/osframework/source/ImageLib/jpeg/jconfig.mc6
new file mode 100644
index 0000000..5492365
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.mc6
@@ -0,0 +1,52 @@
+/* jconfig.mc6 --- jconfig.h for Microsoft C on MS-DOS, version 6.00A & up. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#define NEED_FAR_POINTERS /* for small or medium memory model */
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
+
+#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
+
+#define USE_FMEM /* Microsoft has _fmemcpy() and _fmemset() */
+
+#define NEED_FHEAPMIN /* far heap management routines are broken */
+
+#define SHORTxLCONST_32 /* enable compiler-specific DCT optimization */
+/* Note: the above define is known to improve the code with Microsoft C 6.00A.
+ * I do not know whether it is good for later compiler versions.
+ * Please report any info on this point to jpeg-info@uunet.uu.net.
+ */
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE
+#define USE_SETMODE /* Microsoft has setmode() */
+#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.sas b/osframework/source/ImageLib/jpeg/jconfig.sas
new file mode 100644
index 0000000..a802dd3
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.sas
@@ -0,0 +1,43 @@
+/* jconfig.sas --- jconfig.h for Amiga systems using SAS C 6.0 and up. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
+
+#define NO_MKTEMP /* SAS C doesn't have mktemp() */
+
+#define SHORTxSHORT_32 /* produces better DCT code with SAS C */
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE
+#define NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.st b/osframework/source/ImageLib/jpeg/jconfig.st
new file mode 100644
index 0000000..796b3c9
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.st
@@ -0,0 +1,42 @@
+/* jconfig.st --- jconfig.h for Atari ST/STE/TT using Pure C or Turbo C. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+#define INCOMPLETE_TYPES_BROKEN /* suppress undefined-structure warnings */
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#define ALIGN_TYPE long /* apparently double is a weird size? */
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE /* optional -- undef if you like Unix style */
+/* Note: if you undef TWO_FILE_COMMANDLINE, you may need to define
+ * USE_SETMODE. Some Atari compilers require it, some do not.
+ */
+#define NEED_SIGNAL_CATCHER /* needed if you use jmemname.c */
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.vc b/osframework/source/ImageLib/jpeg/jconfig.vc
new file mode 100644
index 0000000..2f4da14
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.vc
@@ -0,0 +1,45 @@
+/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 95 or NT. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+/* Define "boolean" as unsigned char, not int, per Windows custom */
+#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
+typedef unsigned char boolean;
+#endif
+#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
+
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE /* optional */
+#define USE_SETMODE /* Microsoft has setmode() */
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.vms b/osframework/source/ImageLib/jpeg/jconfig.vms
new file mode 100644
index 0000000..eb582dc
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.vms
@@ -0,0 +1,37 @@
+/* jconfig.vms --- jconfig.h for use on Digital VMS. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#define TWO_FILE_COMMANDLINE /* Needed on VMS */
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jconfig.wat b/osframework/source/ImageLib/jpeg/jconfig.wat
new file mode 100644
index 0000000..d57ceb9
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jconfig.wat
@@ -0,0 +1,38 @@
+/* jconfig.wat --- jconfig.h for Watcom C/C++ on MS-DOS or OS/2. */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_UNSIGNED_SHORT
+/* #define void char */
+/* #define const */
+#define CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H
+#define HAVE_STDLIB_H
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS /* Watcom uses flat 32-bit addressing */
+#undef NEED_SHORT_EXTERNAL_NAMES
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED /* BMP image file format */
+#define GIF_SUPPORTED /* GIF image file format */
+#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED /* Utah RLE image file format */
+#define TARGA_SUPPORTED /* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE /* optional */
+#define USE_SETMODE /* Needed to make one-file style work in Watcom */
+#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT /* optional */
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/osframework/source/ImageLib/jpeg/jcparam.c b/osframework/source/ImageLib/jpeg/jcparam.c
new file mode 100644
index 0000000..bbd175c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcparam.c
@@ -0,0 +1,610 @@
+/*
+ * jcparam.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains optional default-setting code for the JPEG compressor.
+ * Applications do not have to use this file, but those that don't use it
+ * must know a lot more about the innards of the JPEG code.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Quantization table setup routines
+ */
+
+GLOBAL(void)
+jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
+ const unsigned int *basic_table,
+ int scale_factor, boolean force_baseline)
+/* Define a quantization table equal to the basic_table times
+ * a scale factor (given as a percentage).
+ * If force_baseline is TRUE, the computed quantization table entries
+ * are limited to 1..255 for JPEG baseline compatibility.
+ */
+{
+ JQUANT_TBL ** qtblptr;
+ int i;
+ long temp;
+
+ /* Safety check to ensure start_compress not called yet. */
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
+ ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
+
+ qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
+
+ if (*qtblptr == NULL)
+ *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
+ /* limit the values to the valid range */
+ if (temp <= 0L) temp = 1L;
+ if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
+ if (force_baseline && temp > 255L)
+ temp = 255L; /* limit to baseline range if requested */
+ (*qtblptr)->quantval[i] = (UINT16) temp;
+ }
+
+ /* Initialize sent_table FALSE so table will be written to JPEG file. */
+ (*qtblptr)->sent_table = FALSE;
+}
+
+
+GLOBAL(void)
+jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
+ boolean force_baseline)
+/* Set or change the 'quality' (quantization) setting, using default tables
+ * and a straight percentage-scaling quality scale. In most cases it's better
+ * to use jpeg_set_quality (below); this entry point is provided for
+ * applications that insist on a linear percentage scaling.
+ */
+{
+ /* These are the sample quantization tables given in JPEG spec section K.1.
+ * The spec says that the values given produce "good" quality, and
+ * when divided by 2, "very good" quality.
+ */
+ static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68, 109, 103, 77,
+ 24, 35, 55, 64, 81, 104, 113, 92,
+ 49, 64, 78, 87, 103, 121, 120, 101,
+ 72, 92, 95, 98, 112, 100, 103, 99
+ };
+ static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ };
+
+ /* Set up two quantization tables using the specified scaling */
+ jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
+ scale_factor, force_baseline);
+ jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
+ scale_factor, force_baseline);
+}
+
+
+GLOBAL(int)
+jpeg_quality_scaling (int quality)
+/* Convert a user-specified quality rating to a percentage scaling factor
+ * for an underlying quantization table, using our recommended scaling curve.
+ * The input 'quality' factor should be 0 (terrible) to 100 (very good).
+ */
+{
+ /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
+ if (quality <= 0) quality = 1;
+ if (quality > 100) quality = 100;
+
+ /* The basic table is used as-is (scaling 100) for a quality of 50.
+ * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
+ * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
+ * to make all the table entries 1 (hence, minimum quantization loss).
+ * Qualities 1..50 are converted to scaling percentage 5000/Q.
+ */
+ if (quality < 50)
+ quality = 5000 / quality;
+ else
+ quality = 200 - quality*2;
+
+ return quality;
+}
+
+
+GLOBAL(void)
+jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
+/* Set or change the 'quality' (quantization) setting, using default tables.
+ * This is the standard quality-adjusting entry point for typical user
+ * interfaces; only those who want detailed control over quantization tables
+ * would use the preceding three routines directly.
+ */
+{
+ /* Convert user 0-100 rating to percentage scaling */
+ quality = jpeg_quality_scaling(quality);
+
+ /* Set up standard quality tables */
+ jpeg_set_linear_quality(cinfo, quality, force_baseline);
+}
+
+
+/*
+ * Huffman table setup routines
+ */
+
+LOCAL(void)
+add_huff_table (j_compress_ptr cinfo,
+ JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
+/* Define a Huffman table */
+{
+ int nsymbols, len;
+
+ if (*htblptr == NULL)
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
+
+ /* Copy the number-of-symbols-of-each-code-length counts */
+ MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
+
+ /* Validate the counts. We do this here mainly so we can copy the right
+ * number of symbols from the val[] array, without risking marching off
+ * the end of memory. jchuff.c will do a more thorough test later.
+ */
+ nsymbols = 0;
+ for (len = 1; len <= 16; len++)
+ nsymbols += bits[len];
+ if (nsymbols < 1 || nsymbols > 256)
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+
+ MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
+
+ /* Initialize sent_table FALSE so table will be written to JPEG file. */
+ (*htblptr)->sent_table = FALSE;
+}
+
+
+LOCAL(void)
+std_huff_tables (j_compress_ptr cinfo)
+/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
+/* IMPORTANT: these are only valid for 8-bit data precision! */
+{
+ static const UINT8 bits_dc_luminance[17] =
+ { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
+ static const UINT8 val_dc_luminance[] =
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+
+ static const UINT8 bits_dc_chrominance[17] =
+ { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
+ static const UINT8 val_dc_chrominance[] =
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+
+ static const UINT8 bits_ac_luminance[17] =
+ { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
+ static const UINT8 val_ac_luminance[] =
+ { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
+ 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
+ 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
+ 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
+ 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
+ 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+ 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+ 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+ 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
+ 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
+ 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
+ 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa };
+
+ static const UINT8 bits_ac_chrominance[17] =
+ { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
+ static const UINT8 val_ac_chrominance[] =
+ { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
+ 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+ 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+ 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
+ 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
+ 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
+ 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+ 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
+ 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
+ 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
+ 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
+ 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+ 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa };
+
+ add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
+ bits_dc_luminance, val_dc_luminance);
+ add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
+ bits_ac_luminance, val_ac_luminance);
+ add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
+ bits_dc_chrominance, val_dc_chrominance);
+ add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
+ bits_ac_chrominance, val_ac_chrominance);
+}
+
+
+/*
+ * Default parameter setup for compression.
+ *
+ * Applications that don't choose to use this routine must do their
+ * own setup of all these parameters. Alternately, you can call this
+ * to establish defaults and then alter parameters selectively. This
+ * is the recommended approach since, if we add any new parameters,
+ * your code will still work (they'll be set to reasonable defaults).
+ */
+
+GLOBAL(void)
+jpeg_set_defaults (j_compress_ptr cinfo)
+{
+ int i;
+
+ /* Safety check to ensure start_compress not called yet. */
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* Allocate comp_info array large enough for maximum component count.
+ * Array is made permanent in case application wants to compress
+ * multiple images at same param settings.
+ */
+ if (cinfo->comp_info == NULL)
+ cinfo->comp_info = (jpeg_component_info *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ MAX_COMPONENTS * SIZEOF(jpeg_component_info));
+
+ /* Initialize everything not dependent on the color space */
+
+ cinfo->data_precision = BITS_IN_JSAMPLE;
+ /* Set up two quantization tables using default quality of 75 */
+ jpeg_set_quality(cinfo, 75, TRUE);
+ /* Set up two Huffman tables */
+ std_huff_tables(cinfo);
+
+ /* Initialize default arithmetic coding conditioning */
+ for (i = 0; i < NUM_ARITH_TBLS; i++) {
+ cinfo->arith_dc_L[i] = 0;
+ cinfo->arith_dc_U[i] = 1;
+ cinfo->arith_ac_K[i] = 5;
+ }
+
+ /* Default is no multiple-scan output */
+ cinfo->scan_info = NULL;
+ cinfo->num_scans = 0;
+
+ /* Expect normal source image, not raw downsampled data */
+ cinfo->raw_data_in = FALSE;
+
+ /* Use Huffman coding, not arithmetic coding, by default */
+ cinfo->arith_code = FALSE;
+
+ /* By default, don't do extra passes to optimize entropy coding */
+ cinfo->optimize_coding = FALSE;
+ /* The standard Huffman tables are only valid for 8-bit data precision.
+ * If the precision is higher, force optimization on so that usable
+ * tables will be computed. This test can be removed if default tables
+ * are supplied that are valid for the desired precision.
+ */
+ if (cinfo->data_precision > 8)
+ cinfo->optimize_coding = TRUE;
+
+ /* By default, use the simpler non-cosited sampling alignment */
+ cinfo->CCIR601_sampling = FALSE;
+
+ /* No input smoothing */
+ cinfo->smoothing_factor = 0;
+
+ /* DCT algorithm preference */
+ cinfo->dct_method = JDCT_DEFAULT;
+
+ /* No restart markers */
+ cinfo->restart_interval = 0;
+ cinfo->restart_in_rows = 0;
+
+ /* Fill in default JFIF marker parameters. Note that whether the marker
+ * will actually be written is determined by jpeg_set_colorspace.
+ *
+ * By default, the library emits JFIF version code 1.01.
+ * An application that wants to emit JFIF 1.02 extension markers should set
+ * JFIF_minor_version to 2. We could probably get away with just defaulting
+ * to 1.02, but there may still be some decoders in use that will complain
+ * about that; saying 1.01 should minimize compatibility problems.
+ */
+ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
+ cinfo->JFIF_minor_version = 1;
+ cinfo->density_unit = 0; /* Pixel size is unknown by default */
+ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
+ cinfo->Y_density = 1;
+
+ /* Choose JPEG colorspace based on input space, set defaults accordingly */
+
+ jpeg_default_colorspace(cinfo);
+}
+
+
+/*
+ * Select an appropriate JPEG colorspace for in_color_space.
+ */
+
+GLOBAL(void)
+jpeg_default_colorspace (j_compress_ptr cinfo)
+{
+ switch (cinfo->in_color_space) {
+ case JCS_GRAYSCALE:
+ jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
+ break;
+ case JCS_RGB:
+ jpeg_set_colorspace(cinfo, JCS_YCbCr);
+ break;
+ case JCS_YCbCr:
+ jpeg_set_colorspace(cinfo, JCS_YCbCr);
+ break;
+ case JCS_CMYK:
+ jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
+ break;
+ case JCS_YCCK:
+ jpeg_set_colorspace(cinfo, JCS_YCCK);
+ break;
+ case JCS_UNKNOWN:
+ jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
+ }
+}
+
+
+/*
+ * Set the JPEG colorspace, and choose colorspace-dependent default values.
+ */
+
+GLOBAL(void)
+jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
+{
+ jpeg_component_info * compptr;
+ int ci;
+
+#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
+ (compptr = &cinfo->comp_info[index], \
+ compptr->component_id = (id), \
+ compptr->h_samp_factor = (hsamp), \
+ compptr->v_samp_factor = (vsamp), \
+ compptr->quant_tbl_no = (quant), \
+ compptr->dc_tbl_no = (dctbl), \
+ compptr->ac_tbl_no = (actbl) )
+
+ /* Safety check to ensure start_compress not called yet. */
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
+ * tables 1 for chrominance components.
+ */
+
+ cinfo->jpeg_color_space = colorspace;
+
+ cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
+ cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
+
+ switch (colorspace) {
+ case JCS_GRAYSCALE:
+ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
+ cinfo->num_components = 1;
+ /* JFIF specifies component ID 1 */
+ SET_COMP(0, 1, 1,1, 0, 0,0);
+ break;
+ case JCS_RGB:
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
+ cinfo->num_components = 3;
+ SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
+ SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
+ SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
+ break;
+ case JCS_YCbCr:
+ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
+ cinfo->num_components = 3;
+ /* JFIF specifies component IDs 1,2,3 */
+ /* We default to 2x2 subsamples of chrominance */
+ SET_COMP(0, 1, 2,2, 0, 0,0);
+ SET_COMP(1, 2, 1,1, 1, 1,1);
+ SET_COMP(2, 3, 1,1, 1, 1,1);
+ break;
+ case JCS_CMYK:
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
+ cinfo->num_components = 4;
+ SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
+ SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
+ SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
+ SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
+ break;
+ case JCS_YCCK:
+ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
+ cinfo->num_components = 4;
+ SET_COMP(0, 1, 2,2, 0, 0,0);
+ SET_COMP(1, 2, 1,1, 1, 1,1);
+ SET_COMP(2, 3, 1,1, 1, 1,1);
+ SET_COMP(3, 4, 2,2, 0, 0,0);
+ break;
+ case JCS_UNKNOWN:
+ cinfo->num_components = cinfo->input_components;
+ if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
+ MAX_COMPONENTS);
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ SET_COMP(ci, ci, 1,1, 0, 0,0);
+ }
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ }
+}
+
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+
+LOCAL(jpeg_scan_info *)
+fill_a_scan (jpeg_scan_info * scanptr, int ci,
+ int Ss, int Se, int Ah, int Al)
+/* Support routine: generate one scan for specified component */
+{
+ scanptr->comps_in_scan = 1;
+ scanptr->component_index[0] = ci;
+ scanptr->Ss = Ss;
+ scanptr->Se = Se;
+ scanptr->Ah = Ah;
+ scanptr->Al = Al;
+ scanptr++;
+ return scanptr;
+}
+
+LOCAL(jpeg_scan_info *)
+fill_scans (jpeg_scan_info * scanptr, int ncomps,
+ int Ss, int Se, int Ah, int Al)
+/* Support routine: generate one scan for each component */
+{
+ int ci;
+
+ for (ci = 0; ci < ncomps; ci++) {
+ scanptr->comps_in_scan = 1;
+ scanptr->component_index[0] = ci;
+ scanptr->Ss = Ss;
+ scanptr->Se = Se;
+ scanptr->Ah = Ah;
+ scanptr->Al = Al;
+ scanptr++;
+ }
+ return scanptr;
+}
+
+LOCAL(jpeg_scan_info *)
+fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
+/* Support routine: generate interleaved DC scan if possible, else N scans */
+{
+ int ci;
+
+ if (ncomps <= MAX_COMPS_IN_SCAN) {
+ /* Single interleaved DC scan */
+ scanptr->comps_in_scan = ncomps;
+ for (ci = 0; ci < ncomps; ci++)
+ scanptr->component_index[ci] = ci;
+ scanptr->Ss = scanptr->Se = 0;
+ scanptr->Ah = Ah;
+ scanptr->Al = Al;
+ scanptr++;
+ } else {
+ /* Noninterleaved DC scan for each component */
+ scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
+ }
+ return scanptr;
+}
+
+
+/*
+ * Create a recommended progressive-JPEG script.
+ * cinfo->num_components and cinfo->jpeg_color_space must be correct.
+ */
+
+GLOBAL(void)
+jpeg_simple_progression (j_compress_ptr cinfo)
+{
+ int ncomps = cinfo->num_components;
+ int nscans;
+ jpeg_scan_info * scanptr;
+
+ /* Safety check to ensure start_compress not called yet. */
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* Figure space needed for script. Calculation must match code below! */
+ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
+ /* Custom script for YCbCr color images. */
+ nscans = 10;
+ } else {
+ /* All-purpose script for other color spaces. */
+ if (ncomps > MAX_COMPS_IN_SCAN)
+ nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
+ else
+ nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
+ }
+
+ /* Allocate space for script.
+ * We need to put it in the permanent pool in case the application performs
+ * multiple compressions without changing the settings. To avoid a memory
+ * leak if jpeg_simple_progression is called repeatedly for the same JPEG
+ * object, we try to re-use previously allocated space, and we allocate
+ * enough space to handle YCbCr even if initially asked for grayscale.
+ */
+ if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
+ cinfo->script_space_size = MAX(nscans, 10);
+ cinfo->script_space = (jpeg_scan_info *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ cinfo->script_space_size * SIZEOF(jpeg_scan_info));
+ }
+ scanptr = cinfo->script_space;
+ cinfo->scan_info = scanptr;
+ cinfo->num_scans = nscans;
+
+ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
+ /* Custom script for YCbCr color images. */
+ /* Initial DC scan */
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
+ /* Initial AC scan: get some luma data out in a hurry */
+ scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
+ /* Chroma data is too small to be worth expending many scans on */
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
+ /* Complete spectral selection for luma AC */
+ scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
+ /* Refine next bit of luma AC */
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
+ /* Finish DC successive approximation */
+ scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
+ /* Finish AC successive approximation */
+ scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
+ scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
+ /* Luma bottom bit comes last since it's usually largest scan */
+ scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
+ } else {
+ /* All-purpose script for other color spaces. */
+ /* Successive approximation first pass */
+ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
+ scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
+ scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
+ /* Successive approximation second pass */
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
+ /* Successive approximation final pass */
+ scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
+ scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
+ }
+}
+
+#endif /* C_PROGRESSIVE_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jcphuff.c b/osframework/source/ImageLib/jpeg/jcphuff.c
new file mode 100644
index 0000000..a4ee850
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcphuff.c
@@ -0,0 +1,833 @@
+/*
+ * jcphuff.c
+ *
+ * Copyright (C) 1995-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains Huffman entropy encoding routines for progressive JPEG.
+ *
+ * We do not support output suspension in this module, since the library
+ * currently does not allow multiple-scan files to be written with output
+ * suspension.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jchuff.h" /* Declarations shared with jchuff.c */
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+
+/* Expanded entropy encoder object for progressive Huffman encoding. */
+
+typedef struct {
+ struct jpeg_entropy_encoder pub; /* public fields */
+
+ /* Mode flag: TRUE for optimization, FALSE for actual data output */
+ boolean gather_statistics;
+
+ /* Bit-level coding status.
+ * next_output_byte/free_in_buffer are local copies of cinfo->dest fields.
+ */
+ JOCTET * next_output_byte; /* => next byte to write in buffer */
+ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
+ INT32 put_buffer; /* current bit-accumulation buffer */
+ int put_bits; /* # of bits now in it */
+ j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
+
+ /* Coding status for DC components */
+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
+
+ /* Coding status for AC components */
+ int ac_tbl_no; /* the table number of the single component */
+ unsigned int EOBRUN; /* run length of EOBs */
+ unsigned int BE; /* # of buffered correction bits before MCU */
+ char * bit_buffer; /* buffer for correction bits (1 per char) */
+ /* packing correction bits tightly would save some space but cost time... */
+
+ unsigned int restarts_to_go; /* MCUs left in this restart interval */
+ int next_restart_num; /* next restart number to write (0-7) */
+
+ /* Pointers to derived tables (these workspaces have image lifespan).
+ * Since any one scan codes only DC or only AC, we only need one set
+ * of tables, not one for DC and one for AC.
+ */
+ c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
+
+ /* Statistics tables for optimization; again, one set is enough */
+ long * count_ptrs[NUM_HUFF_TBLS];
+} phuff_entropy_encoder;
+
+typedef phuff_entropy_encoder * phuff_entropy_ptr;
+
+/* MAX_CORR_BITS is the number of bits the AC refinement correction-bit
+ * buffer can hold. Larger sizes may slightly improve compression, but
+ * 1000 is already well into the realm of overkill.
+ * The minimum safe size is 64 bits.
+ */
+
+#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
+
+/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
+ * We assume that int right shift is unsigned if INT32 right shift is,
+ * which should be safe.
+ */
+
+#ifdef RIGHT_SHIFT_IS_UNSIGNED
+#define ISHIFT_TEMPS int ishift_temp;
+#define IRIGHT_SHIFT(x,shft) \
+ ((ishift_temp = (x)) < 0 ? \
+ (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
+ (ishift_temp >> (shft)))
+#else
+#define ISHIFT_TEMPS
+#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
+#endif
+
+/* Forward declarations */
+METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
+METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
+
+
+/*
+ * Initialize for a Huffman-compressed scan using progressive JPEG.
+ */
+
+METHODDEF(void)
+start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ boolean is_DC_band;
+ int ci, tbl;
+ jpeg_component_info * compptr;
+
+ entropy->cinfo = cinfo;
+ entropy->gather_statistics = gather_statistics;
+
+ is_DC_band = (cinfo->Ss == 0);
+
+ /* We assume jcmaster.c already validated the scan parameters. */
+
+ /* Select execution routines */
+ if (cinfo->Ah == 0) {
+ if (is_DC_band)
+ entropy->pub.encode_mcu = encode_mcu_DC_first;
+ else
+ entropy->pub.encode_mcu = encode_mcu_AC_first;
+ } else {
+ if (is_DC_band)
+ entropy->pub.encode_mcu = encode_mcu_DC_refine;
+ else {
+ entropy->pub.encode_mcu = encode_mcu_AC_refine;
+ /* AC refinement needs a correction bit buffer */
+ if (entropy->bit_buffer == NULL)
+ entropy->bit_buffer = (char *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ MAX_CORR_BITS * SIZEOF(char));
+ }
+ }
+ if (gather_statistics)
+ entropy->pub.finish_pass = finish_pass_gather_phuff;
+ else
+ entropy->pub.finish_pass = finish_pass_phuff;
+
+ /* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1
+ * for AC coefficients.
+ */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* Initialize DC predictions to 0 */
+ entropy->last_dc_val[ci] = 0;
+ /* Get table index */
+ if (is_DC_band) {
+ if (cinfo->Ah != 0) /* DC refinement needs no table */
+ continue;
+ tbl = compptr->dc_tbl_no;
+ } else {
+ entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
+ }
+ if (gather_statistics) {
+ /* Check for invalid table index */
+ /* (make_c_derived_tbl does this in the other path) */
+ if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
+ /* Allocate and zero the statistics tables */
+ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
+ if (entropy->count_ptrs[tbl] == NULL)
+ entropy->count_ptrs[tbl] = (long *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ 257 * SIZEOF(long));
+ MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
+ } else {
+ /* Compute derived values for Huffman table */
+ /* We may do this more than once for a table, but it's not expensive */
+ jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
+ & entropy->derived_tbls[tbl]);
+ }
+ }
+
+ /* Initialize AC stuff */
+ entropy->EOBRUN = 0;
+ entropy->BE = 0;
+
+ /* Initialize bit buffer to empty */
+ entropy->put_buffer = 0;
+ entropy->put_bits = 0;
+
+ /* Initialize restart stuff */
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num = 0;
+}
+
+
+/* Outputting bytes to the file.
+ * NB: these must be called only when actually outputting,
+ * that is, entropy->gather_statistics == FALSE.
+ */
+
+/* Emit a byte */
+#define emit_byte(entropy,val) \
+ { *(entropy)->next_output_byte++ = (JOCTET) (val); \
+ if (--(entropy)->free_in_buffer == 0) \
+ dump_buffer(entropy); }
+
+
+LOCAL(void)
+dump_buffer (phuff_entropy_ptr entropy)
+/* Empty the output buffer; we do not support suspension in this module. */
+{
+ struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
+
+ if (! (*dest->empty_output_buffer) (entropy->cinfo))
+ ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
+ /* After a successful buffer dump, must reset buffer pointers */
+ entropy->next_output_byte = dest->next_output_byte;
+ entropy->free_in_buffer = dest->free_in_buffer;
+}
+
+
+/* Outputting bits to the file */
+
+/* Only the right 24 bits of put_buffer are used; the valid bits are
+ * left-justified in this part. At most 16 bits can be passed to emit_bits
+ * in one call, and we never retain more than 7 bits in put_buffer
+ * between calls, so 24 bits are sufficient.
+ */
+
+INLINE
+LOCAL(void)
+emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
+/* Emit some bits, unless we are in gather mode */
+{
+ /* This routine is heavily used, so it's worth coding tightly. */
+ register INT32 put_buffer = (INT32) code;
+ register int put_bits = entropy->put_bits;
+
+ /* if size is 0, caller used an invalid Huffman table entry */
+ if (size == 0)
+ ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
+
+ if (entropy->gather_statistics)
+ return; /* do nothing if we're only getting stats */
+
+ put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
+
+ put_bits += size; /* new number of bits in buffer */
+
+ put_buffer <<= 24 - put_bits; /* align incoming bits */
+
+ put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
+
+ while (put_bits >= 8) {
+ int c = (int) ((put_buffer >> 16) & 0xFF);
+
+ emit_byte(entropy, c);
+ if (c == 0xFF) { /* need to stuff a zero byte? */
+ emit_byte(entropy, 0);
+ }
+ put_buffer <<= 8;
+ put_bits -= 8;
+ }
+
+ entropy->put_buffer = put_buffer; /* update variables */
+ entropy->put_bits = put_bits;
+}
+
+
+LOCAL(void)
+flush_bits (phuff_entropy_ptr entropy)
+{
+ emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
+ entropy->put_buffer = 0; /* and reset bit-buffer to empty */
+ entropy->put_bits = 0;
+}
+
+
+/*
+ * Emit (or just count) a Huffman symbol.
+ */
+
+INLINE
+LOCAL(void)
+emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
+{
+ if (entropy->gather_statistics)
+ entropy->count_ptrs[tbl_no][symbol]++;
+ else {
+ c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
+ emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
+ }
+}
+
+
+/*
+ * Emit bits from a correction bit buffer.
+ */
+
+LOCAL(void)
+emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
+ unsigned int nbits)
+{
+ if (entropy->gather_statistics)
+ return; /* no real work */
+
+ while (nbits > 0) {
+ emit_bits(entropy, (unsigned int) (*bufstart), 1);
+ bufstart++;
+ nbits--;
+ }
+}
+
+
+/*
+ * Emit any pending EOBRUN symbol.
+ */
+
+LOCAL(void)
+emit_eobrun (phuff_entropy_ptr entropy)
+{
+ register int temp, nbits;
+
+ if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
+ temp = entropy->EOBRUN;
+ nbits = 0;
+ while ((temp >>= 1))
+ nbits++;
+ /* safety check: shouldn't happen given limited correction-bit buffer */
+ if (nbits > 14)
+ ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
+
+ emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
+ if (nbits)
+ emit_bits(entropy, entropy->EOBRUN, nbits);
+
+ entropy->EOBRUN = 0;
+
+ /* Emit any buffered correction bits */
+ emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
+ entropy->BE = 0;
+ }
+}
+
+
+/*
+ * Emit a restart marker & resynchronize predictions.
+ */
+
+LOCAL(void)
+emit_restart (phuff_entropy_ptr entropy, int restart_num)
+{
+ int ci;
+
+ emit_eobrun(entropy);
+
+ if (! entropy->gather_statistics) {
+ flush_bits(entropy);
+ emit_byte(entropy, 0xFF);
+ emit_byte(entropy, JPEG_RST0 + restart_num);
+ }
+
+ if (entropy->cinfo->Ss == 0) {
+ /* Re-initialize DC predictions to 0 */
+ for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
+ entropy->last_dc_val[ci] = 0;
+ } else {
+ /* Re-initialize all AC-related fields to 0 */
+ entropy->EOBRUN = 0;
+ entropy->BE = 0;
+ }
+}
+
+
+/*
+ * MCU encoding for DC initial scan (either spectral selection,
+ * or first pass of successive approximation).
+ */
+
+METHODDEF(boolean)
+encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ register int temp, temp2;
+ register int nbits;
+ int blkn, ci;
+ int Al = cinfo->Al;
+ JBLOCKROW block;
+ jpeg_component_info * compptr;
+ ISHIFT_TEMPS
+
+ entropy->next_output_byte = cinfo->dest->next_output_byte;
+ entropy->free_in_buffer = cinfo->dest->free_in_buffer;
+
+ /* Emit restart marker if needed */
+ if (cinfo->restart_interval)
+ if (entropy->restarts_to_go == 0)
+ emit_restart(entropy, entropy->next_restart_num);
+
+ /* Encode the MCU data blocks */
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ block = MCU_data[blkn];
+ ci = cinfo->MCU_membership[blkn];
+ compptr = cinfo->cur_comp_info[ci];
+
+ /* Compute the DC value after the required point transform by Al.
+ * This is simply an arithmetic right shift.
+ */
+ temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
+
+ /* DC differences are figured on the point-transformed values. */
+ temp = temp2 - entropy->last_dc_val[ci];
+ entropy->last_dc_val[ci] = temp2;
+
+ /* Encode the DC coefficient difference per section G.1.2.1 */
+ temp2 = temp;
+ if (temp < 0) {
+ temp = -temp; /* temp is abs value of input */
+ /* For a negative input, want temp2 = bitwise complement of abs(input) */
+ /* This code assumes we are on a two's complement machine */
+ temp2--;
+ }
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 0;
+ while (temp) {
+ nbits++;
+ temp >>= 1;
+ }
+ /* Check for out-of-range coefficient values.
+ * Since we're encoding a difference, the range limit is twice as much.
+ */
+ if (nbits > MAX_COEF_BITS+1)
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
+
+ /* Count/emit the Huffman-coded symbol for the number of bits */
+ emit_symbol(entropy, compptr->dc_tbl_no, nbits);
+
+ /* Emit that number of bits of the value, if positive, */
+ /* or the complement of its magnitude, if negative. */
+ if (nbits) /* emit_bits rejects calls with size 0 */
+ emit_bits(entropy, (unsigned int) temp2, nbits);
+ }
+
+ cinfo->dest->next_output_byte = entropy->next_output_byte;
+ cinfo->dest->free_in_buffer = entropy->free_in_buffer;
+
+ /* Update restart-interval state too */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num++;
+ entropy->next_restart_num &= 7;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * MCU encoding for AC initial scan (either spectral selection,
+ * or first pass of successive approximation).
+ */
+
+METHODDEF(boolean)
+encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ register int temp, temp2;
+ register int nbits;
+ register int r, k;
+ int Se = cinfo->Se;
+ int Al = cinfo->Al;
+ JBLOCKROW block;
+
+ entropy->next_output_byte = cinfo->dest->next_output_byte;
+ entropy->free_in_buffer = cinfo->dest->free_in_buffer;
+
+ /* Emit restart marker if needed */
+ if (cinfo->restart_interval)
+ if (entropy->restarts_to_go == 0)
+ emit_restart(entropy, entropy->next_restart_num);
+
+ /* Encode the MCU data block */
+ block = MCU_data[0];
+
+ /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */
+
+ r = 0; /* r = run length of zeros */
+
+ for (k = cinfo->Ss; k <= Se; k++) {
+ if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
+ r++;
+ continue;
+ }
+ /* We must apply the point transform by Al. For AC coefficients this
+ * is an integer division with rounding towards 0. To do this portably
+ * in C, we shift after obtaining the absolute value; so the code is
+ * interwoven with finding the abs value (temp) and output bits (temp2).
+ */
+ if (temp < 0) {
+ temp = -temp; /* temp is abs value of input */
+ temp >>= Al; /* apply the point transform */
+ /* For a negative coef, want temp2 = bitwise complement of abs(coef) */
+ temp2 = ~temp;
+ } else {
+ temp >>= Al; /* apply the point transform */
+ temp2 = temp;
+ }
+ /* Watch out for case that nonzero coef is zero after point transform */
+ if (temp == 0) {
+ r++;
+ continue;
+ }
+
+ /* Emit any pending EOBRUN */
+ if (entropy->EOBRUN > 0)
+ emit_eobrun(entropy);
+ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
+ while (r > 15) {
+ emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
+ r -= 16;
+ }
+
+ /* Find the number of bits needed for the magnitude of the coefficient */
+ nbits = 1; /* there must be at least one 1 bit */
+ while ((temp >>= 1))
+ nbits++;
+ /* Check for out-of-range coefficient values */
+ if (nbits > MAX_COEF_BITS)
+ ERREXIT(cinfo, JERR_BAD_DCT_COEF);
+
+ /* Count/emit Huffman symbol for run length / number of bits */
+ emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
+
+ /* Emit that number of bits of the value, if positive, */
+ /* or the complement of its magnitude, if negative. */
+ emit_bits(entropy, (unsigned int) temp2, nbits);
+
+ r = 0; /* reset zero run length */
+ }
+
+ if (r > 0) { /* If there are trailing zeroes, */
+ entropy->EOBRUN++; /* count an EOB */
+ if (entropy->EOBRUN == 0x7FFF)
+ emit_eobrun(entropy); /* force it out to avoid overflow */
+ }
+
+ cinfo->dest->next_output_byte = entropy->next_output_byte;
+ cinfo->dest->free_in_buffer = entropy->free_in_buffer;
+
+ /* Update restart-interval state too */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num++;
+ entropy->next_restart_num &= 7;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * MCU encoding for DC successive approximation refinement scan.
+ * Note: we assume such scans can be multi-component, although the spec
+ * is not very clear on the point.
+ */
+
+METHODDEF(boolean)
+encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ register int temp;
+ int blkn;
+ int Al = cinfo->Al;
+ JBLOCKROW block;
+
+ entropy->next_output_byte = cinfo->dest->next_output_byte;
+ entropy->free_in_buffer = cinfo->dest->free_in_buffer;
+
+ /* Emit restart marker if needed */
+ if (cinfo->restart_interval)
+ if (entropy->restarts_to_go == 0)
+ emit_restart(entropy, entropy->next_restart_num);
+
+ /* Encode the MCU data blocks */
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ block = MCU_data[blkn];
+
+ /* We simply emit the Al'th bit of the DC coefficient value. */
+ temp = (*block)[0];
+ emit_bits(entropy, (unsigned int) (temp >> Al), 1);
+ }
+
+ cinfo->dest->next_output_byte = entropy->next_output_byte;
+ cinfo->dest->free_in_buffer = entropy->free_in_buffer;
+
+ /* Update restart-interval state too */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num++;
+ entropy->next_restart_num &= 7;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * MCU encoding for AC successive approximation refinement scan.
+ */
+
+METHODDEF(boolean)
+encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ register int temp;
+ register int r, k;
+ int EOB;
+ char *BR_buffer;
+ unsigned int BR;
+ int Se = cinfo->Se;
+ int Al = cinfo->Al;
+ JBLOCKROW block;
+ int absvalues[DCTSIZE2];
+
+ entropy->next_output_byte = cinfo->dest->next_output_byte;
+ entropy->free_in_buffer = cinfo->dest->free_in_buffer;
+
+ /* Emit restart marker if needed */
+ if (cinfo->restart_interval)
+ if (entropy->restarts_to_go == 0)
+ emit_restart(entropy, entropy->next_restart_num);
+
+ /* Encode the MCU data block */
+ block = MCU_data[0];
+
+ /* It is convenient to make a pre-pass to determine the transformed
+ * coefficients' absolute values and the EOB position.
+ */
+ EOB = 0;
+ for (k = cinfo->Ss; k <= Se; k++) {
+ temp = (*block)[jpeg_natural_order[k]];
+ /* We must apply the point transform by Al. For AC coefficients this
+ * is an integer division with rounding towards 0. To do this portably
+ * in C, we shift after obtaining the absolute value.
+ */
+ if (temp < 0)
+ temp = -temp; /* temp is abs value of input */
+ temp >>= Al; /* apply the point transform */
+ absvalues[k] = temp; /* save abs value for main pass */
+ if (temp == 1)
+ EOB = k; /* EOB = index of last newly-nonzero coef */
+ }
+
+ /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */
+
+ r = 0; /* r = run length of zeros */
+ BR = 0; /* BR = count of buffered bits added now */
+ BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
+
+ for (k = cinfo->Ss; k <= Se; k++) {
+ if ((temp = absvalues[k]) == 0) {
+ r++;
+ continue;
+ }
+
+ /* Emit any required ZRLs, but not if they can be folded into EOB */
+ while (r > 15 && k <= EOB) {
+ /* emit any pending EOBRUN and the BE correction bits */
+ emit_eobrun(entropy);
+ /* Emit ZRL */
+ emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
+ r -= 16;
+ /* Emit buffered correction bits that must be associated with ZRL */
+ emit_buffered_bits(entropy, BR_buffer, BR);
+ BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
+ BR = 0;
+ }
+
+ /* If the coef was previously nonzero, it only needs a correction bit.
+ * NOTE: a straight translation of the spec's figure G.7 would suggest
+ * that we also need to test r > 15. But if r > 15, we can only get here
+ * if k > EOB, which implies that this coefficient is not 1.
+ */
+ if (temp > 1) {
+ /* The correction bit is the next bit of the absolute value. */
+ BR_buffer[BR++] = (char) (temp & 1);
+ continue;
+ }
+
+ /* Emit any pending EOBRUN and the BE correction bits */
+ emit_eobrun(entropy);
+
+ /* Count/emit Huffman symbol for run length / number of bits */
+ emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
+
+ /* Emit output bit for newly-nonzero coef */
+ temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
+ emit_bits(entropy, (unsigned int) temp, 1);
+
+ /* Emit buffered correction bits that must be associated with this code */
+ emit_buffered_bits(entropy, BR_buffer, BR);
+ BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
+ BR = 0;
+ r = 0; /* reset zero run length */
+ }
+
+ if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
+ entropy->EOBRUN++; /* count an EOB */
+ entropy->BE += BR; /* concat my correction bits to older ones */
+ /* We force out the EOB if we risk either:
+ * 1. overflow of the EOB counter;
+ * 2. overflow of the correction bit buffer during the next MCU.
+ */
+ if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
+ emit_eobrun(entropy);
+ }
+
+ cinfo->dest->next_output_byte = entropy->next_output_byte;
+ cinfo->dest->free_in_buffer = entropy->free_in_buffer;
+
+ /* Update restart-interval state too */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0) {
+ entropy->restarts_to_go = cinfo->restart_interval;
+ entropy->next_restart_num++;
+ entropy->next_restart_num &= 7;
+ }
+ entropy->restarts_to_go--;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Finish up at the end of a Huffman-compressed progressive scan.
+ */
+
+METHODDEF(void)
+finish_pass_phuff (j_compress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+
+ entropy->next_output_byte = cinfo->dest->next_output_byte;
+ entropy->free_in_buffer = cinfo->dest->free_in_buffer;
+
+ /* Flush out any buffered data */
+ emit_eobrun(entropy);
+ flush_bits(entropy);
+
+ cinfo->dest->next_output_byte = entropy->next_output_byte;
+ cinfo->dest->free_in_buffer = entropy->free_in_buffer;
+}
+
+
+/*
+ * Finish up a statistics-gathering pass and create the new Huffman tables.
+ */
+
+METHODDEF(void)
+finish_pass_gather_phuff (j_compress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ boolean is_DC_band;
+ int ci, tbl;
+ jpeg_component_info * compptr;
+ JHUFF_TBL **htblptr;
+ boolean did[NUM_HUFF_TBLS];
+
+ /* Flush out buffered data (all we care about is counting the EOB symbol) */
+ emit_eobrun(entropy);
+
+ is_DC_band = (cinfo->Ss == 0);
+
+ /* It's important not to apply jpeg_gen_optimal_table more than once
+ * per table, because it clobbers the input frequency counts!
+ */
+ MEMZERO(did, SIZEOF(did));
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ if (is_DC_band) {
+ if (cinfo->Ah != 0) /* DC refinement needs no table */
+ continue;
+ tbl = compptr->dc_tbl_no;
+ } else {
+ tbl = compptr->ac_tbl_no;
+ }
+ if (! did[tbl]) {
+ if (is_DC_band)
+ htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
+ else
+ htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
+ if (*htblptr == NULL)
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
+ jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
+ did[tbl] = TRUE;
+ }
+ }
+}
+
+
+/*
+ * Module initialization routine for progressive Huffman entropy encoding.
+ */
+
+GLOBAL(void)
+jinit_phuff_encoder (j_compress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy;
+ int i;
+
+ entropy = (phuff_entropy_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(phuff_entropy_encoder));
+ cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
+ entropy->pub.start_pass = start_pass_phuff;
+
+ /* Mark tables unallocated */
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ entropy->derived_tbls[i] = NULL;
+ entropy->count_ptrs[i] = NULL;
+ }
+ entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
+}
+
+#endif /* C_PROGRESSIVE_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jcprepct.c b/osframework/source/ImageLib/jpeg/jcprepct.c
new file mode 100644
index 0000000..fdc4bc2
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcprepct.c
@@ -0,0 +1,354 @@
+/*
+ * jcprepct.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the compression preprocessing controller.
+ * This controller manages the color conversion, downsampling,
+ * and edge expansion steps.
+ *
+ * Most of the complexity here is associated with buffering input rows
+ * as required by the downsampler. See the comments at the head of
+ * jcsample.c for the downsampler's needs.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* At present, jcsample.c can request context rows only for smoothing.
+ * In the future, we might also need context rows for CCIR601 sampling
+ * or other more-complex downsampling procedures. The code to support
+ * context rows should be compiled only if needed.
+ */
+#ifdef INPUT_SMOOTHING_SUPPORTED
+#define CONTEXT_ROWS_SUPPORTED
+#endif
+
+
+/*
+ * For the simple (no-context-row) case, we just need to buffer one
+ * row group's worth of pixels for the downsampling step. At the bottom of
+ * the image, we pad to a full row group by replicating the last pixel row.
+ * The downsampler's last output row is then replicated if needed to pad
+ * out to a full iMCU row.
+ *
+ * When providing context rows, we must buffer three row groups' worth of
+ * pixels. Three row groups are physically allocated, but the row pointer
+ * arrays are made five row groups high, with the extra pointers above and
+ * below "wrapping around" to point to the last and first real row groups.
+ * This allows the downsampler to access the proper context rows.
+ * At the top and bottom of the image, we create dummy context rows by
+ * copying the first or last real pixel row. This copying could be avoided
+ * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
+ * trouble on the compression side.
+ */
+
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_c_prep_controller pub; /* public fields */
+
+ /* Downsampling input buffer. This buffer holds color-converted data
+ * until we have enough to do a downsample step.
+ */
+ JSAMPARRAY color_buf[MAX_COMPONENTS];
+
+ JDIMENSION rows_to_go; /* counts rows remaining in source image */
+ int next_buf_row; /* index of next row to store in color_buf */
+
+#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
+ int this_row_group; /* starting row index of group to process */
+ int next_buf_stop; /* downsample when we reach this index */
+#endif
+} my_prep_controller;
+
+typedef my_prep_controller * my_prep_ptr;
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
+
+ if (pass_mode != JBUF_PASS_THRU)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+
+ /* Initialize total-height counter for detecting bottom of image */
+ prep->rows_to_go = cinfo->image_height;
+ /* Mark the conversion buffer empty */
+ prep->next_buf_row = 0;
+#ifdef CONTEXT_ROWS_SUPPORTED
+ /* Preset additional state variables for context mode.
+ * These aren't used in non-context mode, so we needn't test which mode.
+ */
+ prep->this_row_group = 0;
+ /* Set next_buf_stop to stop after two row groups have been read in. */
+ prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
+#endif
+}
+
+
+/*
+ * Expand an image vertically from height input_rows to height output_rows,
+ * by duplicating the bottom row.
+ */
+
+LOCAL(void)
+expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
+ int input_rows, int output_rows)
+{
+ register int row;
+
+ for (row = input_rows; row < output_rows; row++) {
+ jcopy_sample_rows(image_data, input_rows-1, image_data, row,
+ 1, num_cols);
+ }
+}
+
+
+/*
+ * Process some data in the simple no-context case.
+ *
+ * Preprocessor output data is counted in "row groups". A row group
+ * is defined to be v_samp_factor sample rows of each component.
+ * Downsampling will produce this much data from each max_v_samp_factor
+ * input rows.
+ */
+
+METHODDEF(void)
+pre_process_data (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail,
+ JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
+ JDIMENSION out_row_groups_avail)
+{
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
+ int numrows, ci;
+ JDIMENSION inrows;
+ jpeg_component_info * compptr;
+
+ while (*in_row_ctr < in_rows_avail &&
+ *out_row_group_ctr < out_row_groups_avail) {
+ /* Do color conversion to fill the conversion buffer. */
+ inrows = in_rows_avail - *in_row_ctr;
+ numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
+ numrows = (int) MIN((JDIMENSION) numrows, inrows);
+ (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
+ prep->color_buf,
+ (JDIMENSION) prep->next_buf_row,
+ numrows);
+ *in_row_ctr += numrows;
+ prep->next_buf_row += numrows;
+ prep->rows_to_go -= numrows;
+ /* If at bottom of image, pad to fill the conversion buffer. */
+ if (prep->rows_to_go == 0 &&
+ prep->next_buf_row < cinfo->max_v_samp_factor) {
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
+ prep->next_buf_row, cinfo->max_v_samp_factor);
+ }
+ prep->next_buf_row = cinfo->max_v_samp_factor;
+ }
+ /* If we've filled the conversion buffer, empty it. */
+ if (prep->next_buf_row == cinfo->max_v_samp_factor) {
+ (*cinfo->downsample->downsample) (cinfo,
+ prep->color_buf, (JDIMENSION) 0,
+ output_buf, *out_row_group_ctr);
+ prep->next_buf_row = 0;
+ (*out_row_group_ctr)++;
+ }
+ /* If at bottom of image, pad the output to a full iMCU height.
+ * Note we assume the caller is providing a one-iMCU-height output buffer!
+ */
+ if (prep->rows_to_go == 0 &&
+ *out_row_group_ctr < out_row_groups_avail) {
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ expand_bottom_edge(output_buf[ci],
+ compptr->width_in_blocks * DCTSIZE,
+ (int) (*out_row_group_ctr * compptr->v_samp_factor),
+ (int) (out_row_groups_avail * compptr->v_samp_factor));
+ }
+ *out_row_group_ctr = out_row_groups_avail;
+ break; /* can exit outer loop without test */
+ }
+ }
+}
+
+
+#ifdef CONTEXT_ROWS_SUPPORTED
+
+/*
+ * Process some data in the context case.
+ */
+
+METHODDEF(void)
+pre_process_context (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail,
+ JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
+ JDIMENSION out_row_groups_avail)
+{
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
+ int numrows, ci;
+ int buf_height = cinfo->max_v_samp_factor * 3;
+ JDIMENSION inrows;
+
+ while (*out_row_group_ctr < out_row_groups_avail) {
+ if (*in_row_ctr < in_rows_avail) {
+ /* Do color conversion to fill the conversion buffer. */
+ inrows = in_rows_avail - *in_row_ctr;
+ numrows = prep->next_buf_stop - prep->next_buf_row;
+ numrows = (int) MIN((JDIMENSION) numrows, inrows);
+ (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
+ prep->color_buf,
+ (JDIMENSION) prep->next_buf_row,
+ numrows);
+ /* Pad at top of image, if first time through */
+ if (prep->rows_to_go == cinfo->image_height) {
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ int row;
+ for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
+ jcopy_sample_rows(prep->color_buf[ci], 0,
+ prep->color_buf[ci], -row,
+ 1, cinfo->image_width);
+ }
+ }
+ }
+ *in_row_ctr += numrows;
+ prep->next_buf_row += numrows;
+ prep->rows_to_go -= numrows;
+ } else {
+ /* Return for more data, unless we are at the bottom of the image. */
+ if (prep->rows_to_go != 0)
+ break;
+ /* When at bottom of image, pad to fill the conversion buffer. */
+ if (prep->next_buf_row < prep->next_buf_stop) {
+ for (ci = 0; ci < cinfo->num_components; ci++) {
+ expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
+ prep->next_buf_row, prep->next_buf_stop);
+ }
+ prep->next_buf_row = prep->next_buf_stop;
+ }
+ }
+ /* If we've gotten enough data, downsample a row group. */
+ if (prep->next_buf_row == prep->next_buf_stop) {
+ (*cinfo->downsample->downsample) (cinfo,
+ prep->color_buf,
+ (JDIMENSION) prep->this_row_group,
+ output_buf, *out_row_group_ctr);
+ (*out_row_group_ctr)++;
+ /* Advance pointers with wraparound as necessary. */
+ prep->this_row_group += cinfo->max_v_samp_factor;
+ if (prep->this_row_group >= buf_height)
+ prep->this_row_group = 0;
+ if (prep->next_buf_row >= buf_height)
+ prep->next_buf_row = 0;
+ prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
+ }
+ }
+}
+
+
+/*
+ * Create the wrapped-around downsampling input buffer needed for context mode.
+ */
+
+LOCAL(void)
+create_context_buffer (j_compress_ptr cinfo)
+{
+ my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
+ int rgroup_height = cinfo->max_v_samp_factor;
+ int ci, i;
+ jpeg_component_info * compptr;
+ JSAMPARRAY true_buffer, fake_buffer;
+
+ /* Grab enough space for fake row pointers for all the components;
+ * we need five row groups' worth of pointers for each component.
+ */
+ fake_buffer = (JSAMPARRAY)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (cinfo->num_components * 5 * rgroup_height) *
+ SIZEOF(JSAMPROW));
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Allocate the actual buffer space (3 row groups) for this component.
+ * We make the buffer wide enough to allow the downsampler to edge-expand
+ * horizontally within the buffer, if it so chooses.
+ */
+ true_buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
+ (JDIMENSION) (3 * rgroup_height));
+ /* Copy true buffer row pointers into the middle of the fake row array */
+ MEMCOPY(fake_buffer + rgroup_height, true_buffer,
+ 3 * rgroup_height * SIZEOF(JSAMPROW));
+ /* Fill in the above and below wraparound pointers */
+ for (i = 0; i < rgroup_height; i++) {
+ fake_buffer[i] = true_buffer[2 * rgroup_height + i];
+ fake_buffer[4 * rgroup_height + i] = true_buffer[i];
+ }
+ prep->color_buf[ci] = fake_buffer + rgroup_height;
+ fake_buffer += 5 * rgroup_height; /* point to space for next component */
+ }
+}
+
+#endif /* CONTEXT_ROWS_SUPPORTED */
+
+
+/*
+ * Initialize preprocessing controller.
+ */
+
+GLOBAL(void)
+jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
+{
+ my_prep_ptr prep;
+ int ci;
+ jpeg_component_info * compptr;
+
+ if (need_full_buffer) /* safety check */
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+
+ prep = (my_prep_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_prep_controller));
+ cinfo->prep = (struct jpeg_c_prep_controller *) prep;
+ prep->pub.start_pass = start_pass_prep;
+
+ /* Allocate the color conversion buffer.
+ * We make the buffer wide enough to allow the downsampler to edge-expand
+ * horizontally within the buffer, if it so chooses.
+ */
+ if (cinfo->downsample->need_context_rows) {
+ /* Set up to provide context rows */
+#ifdef CONTEXT_ROWS_SUPPORTED
+ prep->pub.pre_process_data = pre_process_context;
+ create_context_buffer(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ /* No context, just make it tall enough for one row group */
+ prep->pub.pre_process_data = pre_process_data;
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
+ cinfo->max_h_samp_factor) / compptr->h_samp_factor),
+ (JDIMENSION) cinfo->max_v_samp_factor);
+ }
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jcsample.c b/osframework/source/ImageLib/jpeg/jcsample.c
new file mode 100644
index 0000000..fe29fca
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jcsample.c
@@ -0,0 +1,519 @@
+/*
+ * jcsample.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains downsampling routines.
+ *
+ * Downsampling input data is counted in "row groups". A row group
+ * is defined to be max_v_samp_factor pixel rows of each component,
+ * from which the downsampler produces v_samp_factor sample rows.
+ * A single row group is processed in each call to the downsampler module.
+ *
+ * The downsampler is responsible for edge-expansion of its output data
+ * to fill an integral number of DCT blocks horizontally. The source buffer
+ * may be modified if it is helpful for this purpose (the source buffer is
+ * allocated wide enough to correspond to the desired output width).
+ * The caller (the prep controller) is responsible for vertical padding.
+ *
+ * The downsampler may request "context rows" by setting need_context_rows
+ * during startup. In this case, the input arrays will contain at least
+ * one row group's worth of pixels above and below the passed-in data;
+ * the caller will create dummy rows at image top and bottom by replicating
+ * the first or last real pixel row.
+ *
+ * An excellent reference for image resampling is
+ * Digital Image Warping, George Wolberg, 1990.
+ * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
+ *
+ * The downsampling algorithm used here is a simple average of the source
+ * pixels covered by the output pixel. The hi-falutin sampling literature
+ * refers to this as a "box filter". In general the characteristics of a box
+ * filter are not very good, but for the specific cases we normally use (1:1
+ * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
+ * nearly so bad. If you intend to use other sampling ratios, you'd be well
+ * advised to improve this code.
+ *
+ * A simple input-smoothing capability is provided. This is mainly intended
+ * for cleaning up color-dithered GIF input files (if you find it inadequate,
+ * we suggest using an external filtering program such as pnmconvol). When
+ * enabled, each input pixel P is replaced by a weighted sum of itself and its
+ * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF,
+ * where SF = (smoothing_factor / 1024).
+ * Currently, smoothing is only supported for 2h2v sampling factors.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Pointer to routine to downsample a single component */
+typedef JMETHOD(void, downsample1_ptr,
+ (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data));
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_downsampler pub; /* public fields */
+
+ /* Downsampling method pointers, one per component */
+ downsample1_ptr methods[MAX_COMPONENTS];
+} my_downsampler;
+
+typedef my_downsampler * my_downsample_ptr;
+
+
+/*
+ * Initialize for a downsampling pass.
+ */
+
+METHODDEF(void)
+start_pass_downsample (j_compress_ptr cinfo)
+{
+ /* no work for now */
+}
+
+
+/*
+ * Expand a component horizontally from width input_cols to width output_cols,
+ * by duplicating the rightmost samples.
+ */
+
+LOCAL(void)
+expand_right_edge (JSAMPARRAY image_data, int num_rows,
+ JDIMENSION input_cols, JDIMENSION output_cols)
+{
+ register JSAMPROW ptr;
+ register JSAMPLE pixval;
+ register int count;
+ int row;
+ int numcols = (int) (output_cols - input_cols);
+
+ if (numcols > 0) {
+ for (row = 0; row < num_rows; row++) {
+ ptr = image_data[row] + input_cols;
+ pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
+ for (count = numcols; count > 0; count--)
+ *ptr++ = pixval;
+ }
+ }
+}
+
+
+/*
+ * Do downsampling for a whole row group (all components).
+ *
+ * In this version we simply downsample each component independently.
+ */
+
+METHODDEF(void)
+sep_downsample (j_compress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION in_row_index,
+ JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
+{
+ my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
+ int ci;
+ jpeg_component_info * compptr;
+ JSAMPARRAY in_ptr, out_ptr;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ in_ptr = input_buf[ci] + in_row_index;
+ out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
+ (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
+ }
+}
+
+
+/*
+ * Downsample pixel values of a single component.
+ * One row group is processed per call.
+ * This version handles arbitrary integral sampling ratios, without smoothing.
+ * Note that this version is not actually used for customary sampling ratios.
+ */
+
+METHODDEF(void)
+int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
+ JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
+ JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
+ JSAMPROW inptr, outptr;
+ INT32 outvalue;
+
+ h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
+ v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
+ numpix = h_expand * v_expand;
+ numpix2 = numpix/2;
+
+ /* Expand input data enough to let all the output samples be generated
+ * by the standard loop. Special-casing padded output would be more
+ * efficient.
+ */
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
+ cinfo->image_width, output_cols * h_expand);
+
+ inrow = 0;
+ for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
+ outptr = output_data[outrow];
+ for (outcol = 0, outcol_h = 0; outcol < output_cols;
+ outcol++, outcol_h += h_expand) {
+ outvalue = 0;
+ for (v = 0; v < v_expand; v++) {
+ inptr = input_data[inrow+v] + outcol_h;
+ for (h = 0; h < h_expand; h++) {
+ outvalue += (INT32) GETJSAMPLE(*inptr++);
+ }
+ }
+ *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
+ }
+ inrow += v_expand;
+ }
+}
+
+
+/*
+ * Downsample pixel values of a single component.
+ * This version handles the special case of a full-size component,
+ * without smoothing.
+ */
+
+METHODDEF(void)
+fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ /* Copy the data */
+ jcopy_sample_rows(input_data, 0, output_data, 0,
+ cinfo->max_v_samp_factor, cinfo->image_width);
+ /* Edge-expand */
+ expand_right_edge(output_data, cinfo->max_v_samp_factor,
+ cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
+}
+
+
+/*
+ * Downsample pixel values of a single component.
+ * This version handles the common case of 2:1 horizontal and 1:1 vertical,
+ * without smoothing.
+ *
+ * A note about the "bias" calculations: when rounding fractional values to
+ * integer, we do not want to always round 0.5 up to the next integer.
+ * If we did that, we'd introduce a noticeable bias towards larger values.
+ * Instead, this code is arranged so that 0.5 will be rounded up or down at
+ * alternate pixel locations (a simple ordered dither pattern).
+ */
+
+METHODDEF(void)
+h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ int outrow;
+ JDIMENSION outcol;
+ JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
+ register JSAMPROW inptr, outptr;
+ register int bias;
+
+ /* Expand input data enough to let all the output samples be generated
+ * by the standard loop. Special-casing padded output would be more
+ * efficient.
+ */
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
+ cinfo->image_width, output_cols * 2);
+
+ for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
+ outptr = output_data[outrow];
+ inptr = input_data[outrow];
+ bias = 0; /* bias = 0,1,0,1,... for successive samples */
+ for (outcol = 0; outcol < output_cols; outcol++) {
+ *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
+ + bias) >> 1);
+ bias ^= 1; /* 0=>1, 1=>0 */
+ inptr += 2;
+ }
+ }
+}
+
+
+/*
+ * Downsample pixel values of a single component.
+ * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
+ * without smoothing.
+ */
+
+METHODDEF(void)
+h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ int inrow, outrow;
+ JDIMENSION outcol;
+ JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
+ register JSAMPROW inptr0, inptr1, outptr;
+ register int bias;
+
+ /* Expand input data enough to let all the output samples be generated
+ * by the standard loop. Special-casing padded output would be more
+ * efficient.
+ */
+ expand_right_edge(input_data, cinfo->max_v_samp_factor,
+ cinfo->image_width, output_cols * 2);
+
+ inrow = 0;
+ for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
+ outptr = output_data[outrow];
+ inptr0 = input_data[inrow];
+ inptr1 = input_data[inrow+1];
+ bias = 1; /* bias = 1,2,1,2,... for successive samples */
+ for (outcol = 0; outcol < output_cols; outcol++) {
+ *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
+ + bias) >> 2);
+ bias ^= 3; /* 1=>2, 2=>1 */
+ inptr0 += 2; inptr1 += 2;
+ }
+ inrow += 2;
+ }
+}
+
+
+#ifdef INPUT_SMOOTHING_SUPPORTED
+
+/*
+ * Downsample pixel values of a single component.
+ * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
+ * with smoothing. One row of context is required.
+ */
+
+METHODDEF(void)
+h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ int inrow, outrow;
+ JDIMENSION colctr;
+ JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
+ register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
+ INT32 membersum, neighsum, memberscale, neighscale;
+
+ /* Expand input data enough to let all the output samples be generated
+ * by the standard loop. Special-casing padded output would be more
+ * efficient.
+ */
+ expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
+ cinfo->image_width, output_cols * 2);
+
+ /* We don't bother to form the individual "smoothed" input pixel values;
+ * we can directly compute the output which is the average of the four
+ * smoothed values. Each of the four member pixels contributes a fraction
+ * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
+ * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
+ * output. The four corner-adjacent neighbor pixels contribute a fraction
+ * SF to just one smoothed pixel, or SF/4 to the final output; while the
+ * eight edge-adjacent neighbors contribute SF to each of two smoothed
+ * pixels, or SF/2 overall. In order to use integer arithmetic, these
+ * factors are scaled by 2^16 = 65536.
+ * Also recall that SF = smoothing_factor / 1024.
+ */
+
+ memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
+ neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
+
+ inrow = 0;
+ for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
+ outptr = output_data[outrow];
+ inptr0 = input_data[inrow];
+ inptr1 = input_data[inrow+1];
+ above_ptr = input_data[inrow-1];
+ below_ptr = input_data[inrow+2];
+
+ /* Special case for first column: pretend column -1 is same as column 0 */
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+ GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
+ neighsum += neighsum;
+ neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
+ membersum = membersum * memberscale + neighsum * neighscale;
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
+ inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
+
+ for (colctr = output_cols - 2; colctr > 0; colctr--) {
+ /* sum of pixels directly mapped to this output element */
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+ /* sum of edge-neighbor pixels */
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+ GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
+ GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
+ /* The edge-neighbors count twice as much as corner-neighbors */
+ neighsum += neighsum;
+ /* Add in the corner-neighbors */
+ neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
+ GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
+ /* form final output scaled up by 2^16 */
+ membersum = membersum * memberscale + neighsum * neighscale;
+ /* round, descale and output it */
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
+ inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
+ }
+
+ /* Special case for last column */
+ membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
+ GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+ neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
+ GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+ GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
+ GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
+ neighsum += neighsum;
+ neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
+ GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
+ membersum = membersum * memberscale + neighsum * neighscale;
+ *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
+
+ inrow += 2;
+ }
+}
+
+
+/*
+ * Downsample pixel values of a single component.
+ * This version handles the special case of a full-size component,
+ * with smoothing. One row of context is required.
+ */
+
+METHODDEF(void)
+fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
+ JSAMPARRAY input_data, JSAMPARRAY output_data)
+{
+ int outrow;
+ JDIMENSION colctr;
+ JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
+ register JSAMPROW inptr, above_ptr, below_ptr, outptr;
+ INT32 membersum, neighsum, memberscale, neighscale;
+ int colsum, lastcolsum, nextcolsum;
+
+ /* Expand input data enough to let all the output samples be generated
+ * by the standard loop. Special-casing padded output would be more
+ * efficient.
+ */
+ expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
+ cinfo->image_width, output_cols);
+
+ /* Each of the eight neighbor pixels contributes a fraction SF to the
+ * smoothed pixel, while the main pixel contributes (1-8*SF). In order
+ * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
+ * Also recall that SF = smoothing_factor / 1024.
+ */
+
+ memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
+ neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
+
+ for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
+ outptr = output_data[outrow];
+ inptr = input_data[outrow];
+ above_ptr = input_data[outrow-1];
+ below_ptr = input_data[outrow+1];
+
+ /* Special case for first column */
+ colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
+ GETJSAMPLE(*inptr);
+ membersum = GETJSAMPLE(*inptr++);
+ nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
+ GETJSAMPLE(*inptr);
+ neighsum = colsum + (colsum - membersum) + nextcolsum;
+ membersum = membersum * memberscale + neighsum * neighscale;
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
+ lastcolsum = colsum; colsum = nextcolsum;
+
+ for (colctr = output_cols - 2; colctr > 0; colctr--) {
+ membersum = GETJSAMPLE(*inptr++);
+ above_ptr++; below_ptr++;
+ nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
+ GETJSAMPLE(*inptr);
+ neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
+ membersum = membersum * memberscale + neighsum * neighscale;
+ *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
+ lastcolsum = colsum; colsum = nextcolsum;
+ }
+
+ /* Special case for last column */
+ membersum = GETJSAMPLE(*inptr);
+ neighsum = lastcolsum + (colsum - membersum) + colsum;
+ membersum = membersum * memberscale + neighsum * neighscale;
+ *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
+
+ }
+}
+
+#endif /* INPUT_SMOOTHING_SUPPORTED */
+
+
+/*
+ * Module initialization routine for downsampling.
+ * Note that we must select a routine for each component.
+ */
+
+GLOBAL(void)
+jinit_downsampler (j_compress_ptr cinfo)
+{
+ my_downsample_ptr downsample;
+ int ci;
+ jpeg_component_info * compptr;
+ boolean smoothok = TRUE;
+
+ downsample = (my_downsample_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_downsampler));
+ cinfo->downsample = (struct jpeg_downsampler *) downsample;
+ downsample->pub.start_pass = start_pass_downsample;
+ downsample->pub.downsample = sep_downsample;
+ downsample->pub.need_context_rows = FALSE;
+
+ if (cinfo->CCIR601_sampling)
+ ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
+
+ /* Verify we can handle the sampling factors, and set up method pointers */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
+ compptr->v_samp_factor == cinfo->max_v_samp_factor) {
+#ifdef INPUT_SMOOTHING_SUPPORTED
+ if (cinfo->smoothing_factor) {
+ downsample->methods[ci] = fullsize_smooth_downsample;
+ downsample->pub.need_context_rows = TRUE;
+ } else
+#endif
+ downsample->methods[ci] = fullsize_downsample;
+ } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
+ compptr->v_samp_factor == cinfo->max_v_samp_factor) {
+ smoothok = FALSE;
+ downsample->methods[ci] = h2v1_downsample;
+ } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
+ compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
+#ifdef INPUT_SMOOTHING_SUPPORTED
+ if (cinfo->smoothing_factor) {
+ downsample->methods[ci] = h2v2_smooth_downsample;
+ downsample->pub.need_context_rows = TRUE;
+ } else
+#endif
+ downsample->methods[ci] = h2v2_downsample;
+ } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
+ (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
+ smoothok = FALSE;
+ downsample->methods[ci] = int_downsample;
+ } else
+ ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
+ }
+
+#ifdef INPUT_SMOOTHING_SUPPORTED
+ if (cinfo->smoothing_factor && !smoothok)
+ TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
+#endif
+}
diff --git a/osframework/source/ImageLib/jpeg/jctrans.c b/osframework/source/ImageLib/jpeg/jctrans.c
new file mode 100644
index 0000000..8b36e36
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jctrans.c
@@ -0,0 +1,388 @@
+/*
+ * jctrans.c
+ *
+ * Copyright (C) 1995-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains library routines for transcoding compression,
+ * that is, writing raw DCT coefficient arrays to an output JPEG file.
+ * The routines in jcapimin.c will also be needed by a transcoder.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Forward declarations */
+LOCAL(void) transencode_master_selection
+ JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
+LOCAL(void) transencode_coef_controller
+ JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
+
+
+/*
+ * Compression initialization for writing raw-coefficient data.
+ * Before calling this, all parameters and a data destination must be set up.
+ * Call jpeg_finish_compress() to actually write the data.
+ *
+ * The number of passed virtual arrays must match cinfo->num_components.
+ * Note that the virtual arrays need not be filled or even realized at
+ * the time write_coefficients is called; indeed, if the virtual arrays
+ * were requested from this compression object's memory manager, they
+ * typically will be realized during this routine and filled afterwards.
+ */
+
+GLOBAL(void)
+jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
+{
+ if (cinfo->global_state != CSTATE_START)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ /* Mark all tables to be written */
+ jpeg_suppress_tables(cinfo, FALSE);
+ /* (Re)initialize error mgr and destination modules */
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
+ (*cinfo->dest->init_destination) (cinfo);
+ /* Perform master selection of active modules */
+ transencode_master_selection(cinfo, coef_arrays);
+ /* Wait for jpeg_finish_compress() call */
+ cinfo->next_scanline = 0; /* so jpeg_write_marker works */
+ cinfo->global_state = CSTATE_WRCOEFS;
+}
+
+
+/*
+ * Initialize the compression object with default parameters,
+ * then copy from the source object all parameters needed for lossless
+ * transcoding. Parameters that can be varied without loss (such as
+ * scan script and Huffman optimization) are left in their default states.
+ */
+
+GLOBAL(void)
+jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
+ j_compress_ptr dstinfo)
+{
+ JQUANT_TBL ** qtblptr;
+ jpeg_component_info *incomp, *outcomp;
+ JQUANT_TBL *c_quant, *slot_quant;
+ int tblno, ci, coefi;
+
+ /* Safety check to ensure start_compress not called yet. */
+ if (dstinfo->global_state != CSTATE_START)
+ ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
+ /* Copy fundamental image dimensions */
+ dstinfo->image_width = srcinfo->image_width;
+ dstinfo->image_height = srcinfo->image_height;
+ dstinfo->input_components = srcinfo->num_components;
+ dstinfo->in_color_space = srcinfo->jpeg_color_space;
+ /* Initialize all parameters to default values */
+ jpeg_set_defaults(dstinfo);
+ /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
+ * Fix it to get the right header markers for the image colorspace.
+ */
+ jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
+ dstinfo->data_precision = srcinfo->data_precision;
+ dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
+ /* Copy the source's quantization tables. */
+ for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
+ if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
+ qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
+ if (*qtblptr == NULL)
+ *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
+ MEMCOPY((*qtblptr)->quantval,
+ srcinfo->quant_tbl_ptrs[tblno]->quantval,
+ SIZEOF((*qtblptr)->quantval));
+ (*qtblptr)->sent_table = FALSE;
+ }
+ }
+ /* Copy the source's per-component info.
+ * Note we assume jpeg_set_defaults has allocated the dest comp_info array.
+ */
+ dstinfo->num_components = srcinfo->num_components;
+ if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
+ ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
+ MAX_COMPONENTS);
+ for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
+ ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
+ outcomp->component_id = incomp->component_id;
+ outcomp->h_samp_factor = incomp->h_samp_factor;
+ outcomp->v_samp_factor = incomp->v_samp_factor;
+ outcomp->quant_tbl_no = incomp->quant_tbl_no;
+ /* Make sure saved quantization table for component matches the qtable
+ * slot. If not, the input file re-used this qtable slot.
+ * IJG encoder currently cannot duplicate this.
+ */
+ tblno = outcomp->quant_tbl_no;
+ if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
+ srcinfo->quant_tbl_ptrs[tblno] == NULL)
+ ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
+ slot_quant = srcinfo->quant_tbl_ptrs[tblno];
+ c_quant = incomp->quant_table;
+ if (c_quant != NULL) {
+ for (coefi = 0; coefi < DCTSIZE2; coefi++) {
+ if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
+ ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
+ }
+ }
+ /* Note: we do not copy the source's Huffman table assignments;
+ * instead we rely on jpeg_set_colorspace to have made a suitable choice.
+ */
+ }
+ /* Also copy JFIF version and resolution information, if available.
+ * Strictly speaking this isn't "critical" info, but it's nearly
+ * always appropriate to copy it if available. In particular,
+ * if the application chooses to copy JFIF 1.02 extension markers from
+ * the source file, we need to copy the version to make sure we don't
+ * emit a file that has 1.02 extensions but a claimed version of 1.01.
+ * We will *not*, however, copy version info from mislabeled "2.01" files.
+ */
+ if (srcinfo->saw_JFIF_marker) {
+ if (srcinfo->JFIF_major_version == 1) {
+ dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
+ dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
+ }
+ dstinfo->density_unit = srcinfo->density_unit;
+ dstinfo->X_density = srcinfo->X_density;
+ dstinfo->Y_density = srcinfo->Y_density;
+ }
+}
+
+
+/*
+ * Master selection of compression modules for transcoding.
+ * This substitutes for jcinit.c's initialization of the full compressor.
+ */
+
+LOCAL(void)
+transencode_master_selection (j_compress_ptr cinfo,
+ jvirt_barray_ptr * coef_arrays)
+{
+ /* Although we don't actually use input_components for transcoding,
+ * jcmaster.c's initial_setup will complain if input_components is 0.
+ */
+ cinfo->input_components = 1;
+ /* Initialize master control (includes parameter checking/processing) */
+ jinit_c_master_control(cinfo, TRUE /* transcode only */);
+
+ /* Entropy encoding: either Huffman or arithmetic coding. */
+ if (cinfo->arith_code) {
+ ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
+ } else {
+ if (cinfo->progressive_mode) {
+#ifdef C_PROGRESSIVE_SUPPORTED
+ jinit_phuff_encoder(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else
+ jinit_huff_encoder(cinfo);
+ }
+
+ /* We need a special coefficient buffer controller. */
+ transencode_coef_controller(cinfo, coef_arrays);
+
+ jinit_marker_writer(cinfo);
+
+ /* We can now tell the memory manager to allocate virtual arrays. */
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
+
+ /* Write the datastream header (SOI, JFIF) immediately.
+ * Frame and scan headers are postponed till later.
+ * This lets application insert special markers after the SOI.
+ */
+ (*cinfo->marker->write_file_header) (cinfo);
+}
+
+
+/*
+ * The rest of this file is a special implementation of the coefficient
+ * buffer controller. This is similar to jccoefct.c, but it handles only
+ * output from presupplied virtual arrays. Furthermore, we generate any
+ * dummy padding blocks on-the-fly rather than expecting them to be present
+ * in the arrays.
+ */
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_c_coef_controller pub; /* public fields */
+
+ JDIMENSION iMCU_row_num; /* iMCU row # within image */
+ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
+ int MCU_vert_offset; /* counts MCU rows within iMCU row */
+ int MCU_rows_per_iMCU_row; /* number of such rows needed */
+
+ /* Virtual block array for each component. */
+ jvirt_barray_ptr * whole_image;
+
+ /* Workspace for constructing dummy blocks at right/bottom edges. */
+ JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
+} my_coef_controller;
+
+typedef my_coef_controller * my_coef_ptr;
+
+
+LOCAL(void)
+start_iMCU_row (j_compress_ptr cinfo)
+/* Reset within-iMCU-row counters for a new row */
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ /* In an interleaved scan, an MCU row is the same as an iMCU row.
+ * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
+ * But at the bottom of the image, process only what's left.
+ */
+ if (cinfo->comps_in_scan > 1) {
+ coef->MCU_rows_per_iMCU_row = 1;
+ } else {
+ if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
+ else
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
+ }
+
+ coef->mcu_ctr = 0;
+ coef->MCU_vert_offset = 0;
+}
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ if (pass_mode != JBUF_CRANK_DEST)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+
+ coef->iMCU_row_num = 0;
+ start_iMCU_row(cinfo);
+}
+
+
+/*
+ * Process some data.
+ * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
+ * per call, ie, v_samp_factor block rows for each component in the scan.
+ * The data is obtained from the virtual arrays and fed to the entropy coder.
+ * Returns TRUE if the iMCU row is completed, FALSE if suspended.
+ *
+ * NB: input_buf is ignored; it is likely to be a NULL pointer.
+ */
+
+METHODDEF(boolean)
+compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+ JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ int blkn, ci, xindex, yindex, yoffset, blockcnt;
+ JDIMENSION start_col;
+ JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
+ JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
+ JBLOCKROW buffer_ptr;
+ jpeg_component_info *compptr;
+
+ /* Align the virtual buffers for the components used in this scan. */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ buffer[ci] = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
+ coef->iMCU_row_num * compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ }
+
+ /* Loop to process one whole iMCU row */
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+ yoffset++) {
+ for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
+ MCU_col_num++) {
+ /* Construct list of pointers to DCT blocks belonging to this MCU */
+ blkn = 0; /* index of current DCT block within MCU */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ start_col = MCU_col_num * compptr->MCU_width;
+ blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
+ : compptr->last_col_width;
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+ if (coef->iMCU_row_num < last_iMCU_row ||
+ yindex+yoffset < compptr->last_row_height) {
+ /* Fill in pointers to real blocks in this row */
+ buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
+ for (xindex = 0; xindex < blockcnt; xindex++)
+ MCU_buffer[blkn++] = buffer_ptr++;
+ } else {
+ /* At bottom of image, need a whole row of dummy blocks */
+ xindex = 0;
+ }
+ /* Fill in any dummy blocks needed in this row.
+ * Dummy blocks are filled in the same way as in jccoefct.c:
+ * all zeroes in the AC entries, DC entries equal to previous
+ * block's DC value. The init routine has already zeroed the
+ * AC entries, so we need only set the DC entries correctly.
+ */
+ for (; xindex < compptr->MCU_width; xindex++) {
+ MCU_buffer[blkn] = coef->dummy_buffer[blkn];
+ MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
+ blkn++;
+ }
+ }
+ }
+ /* Try to write the MCU. */
+ if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
+ /* Suspension forced; update state counters and exit */
+ coef->MCU_vert_offset = yoffset;
+ coef->mcu_ctr = MCU_col_num;
+ return FALSE;
+ }
+ }
+ /* Completed an MCU row, but perhaps not an iMCU row */
+ coef->mcu_ctr = 0;
+ }
+ /* Completed the iMCU row, advance counters for next one */
+ coef->iMCU_row_num++;
+ start_iMCU_row(cinfo);
+ return TRUE;
+}
+
+
+/*
+ * Initialize coefficient buffer controller.
+ *
+ * Each passed coefficient array must be the right size for that
+ * coefficient: width_in_blocks wide and height_in_blocks high,
+ * with unitheight at least v_samp_factor.
+ */
+
+LOCAL(void)
+transencode_coef_controller (j_compress_ptr cinfo,
+ jvirt_barray_ptr * coef_arrays)
+{
+ my_coef_ptr coef;
+ JBLOCKROW buffer;
+ int i;
+
+ coef = (my_coef_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_coef_controller));
+ cinfo->coef = (struct jpeg_c_coef_controller *) coef;
+ coef->pub.start_pass = start_pass_coef;
+ coef->pub.compress_data = compress_output;
+
+ /* Save pointer to virtual arrays */
+ coef->whole_image = coef_arrays;
+
+ /* Allocate and pre-zero space for dummy DCT blocks. */
+ buffer = (JBLOCKROW)
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
+ jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
+ for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
+ coef->dummy_buffer[i] = buffer + i;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdapimin.c b/osframework/source/ImageLib/jpeg/jdapimin.c
new file mode 100644
index 0000000..bd1df92
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdapimin.c
@@ -0,0 +1,395 @@
+/*
+ * jdapimin.c
+ *
+ * Copyright (C) 1994-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains application interface code for the decompression half
+ * of the JPEG library. These are the "minimum" API routines that may be
+ * needed in either the normal full-decompression case or the
+ * transcoding-only case.
+ *
+ * Most of the routines intended to be called directly by an application
+ * are in this file or in jdapistd.c. But also see jcomapi.c for routines
+ * shared by compression and decompression, and jdtrans.c for the transcoding
+ * case.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * Initialization of a JPEG decompression object.
+ * The error manager must already be set up (in case memory manager fails).
+ */
+
+GLOBAL(void)
+jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
+{
+ int i;
+
+ /* Guard against version mismatches between library and caller. */
+ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
+ if (version != JPEG_LIB_VERSION)
+ ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
+ if (structsize != SIZEOF(struct jpeg_decompress_struct))
+ ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
+ (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
+
+ /* For debugging purposes, we zero the whole master structure.
+ * But the application has already set the err pointer, and may have set
+ * client_data, so we have to save and restore those fields.
+ * Note: if application hasn't set client_data, tools like Purify may
+ * complain here.
+ */
+ {
+ struct jpeg_error_mgr * err = cinfo->err;
+ void * client_data = cinfo->client_data; /* ignore Purify complaint here */
+ MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
+ cinfo->err = err;
+ cinfo->client_data = client_data;
+ }
+ cinfo->is_decompressor = TRUE;
+
+ /* Initialize a memory manager instance for this object */
+ jinit_memory_mgr((j_common_ptr) cinfo);
+
+ /* Zero out pointers to permanent structures. */
+ cinfo->progress = NULL;
+ cinfo->src = NULL;
+
+ for (i = 0; i < NUM_QUANT_TBLS; i++)
+ cinfo->quant_tbl_ptrs[i] = NULL;
+
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ cinfo->dc_huff_tbl_ptrs[i] = NULL;
+ cinfo->ac_huff_tbl_ptrs[i] = NULL;
+ }
+
+ /* Initialize marker processor so application can override methods
+ * for COM, APPn markers before calling jpeg_read_header.
+ */
+ cinfo->marker_list = NULL;
+ jinit_marker_reader(cinfo);
+
+ /* And initialize the overall input controller. */
+ jinit_input_controller(cinfo);
+
+ /* OK, I'm ready */
+ cinfo->global_state = DSTATE_START;
+}
+
+
+/*
+ * Destruction of a JPEG decompression object
+ */
+
+GLOBAL(void)
+jpeg_destroy_decompress (j_decompress_ptr cinfo)
+{
+ jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
+}
+
+
+/*
+ * Abort processing of a JPEG decompression operation,
+ * but don't destroy the object itself.
+ */
+
+GLOBAL(void)
+jpeg_abort_decompress (j_decompress_ptr cinfo)
+{
+ jpeg_abort((j_common_ptr) cinfo); /* use common routine */
+}
+
+
+/*
+ * Set default decompression parameters.
+ */
+
+LOCAL(void)
+default_decompress_parms (j_decompress_ptr cinfo)
+{
+ /* Guess the input colorspace, and set output colorspace accordingly. */
+ /* (Wish JPEG committee had provided a real way to specify this...) */
+ /* Note application may override our guesses. */
+ switch (cinfo->num_components) {
+ case 1:
+ cinfo->jpeg_color_space = JCS_GRAYSCALE;
+ cinfo->out_color_space = JCS_GRAYSCALE;
+ break;
+
+ case 3:
+ if (cinfo->saw_JFIF_marker) {
+ cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
+ } else if (cinfo->saw_Adobe_marker) {
+ switch (cinfo->Adobe_transform) {
+ case 0:
+ cinfo->jpeg_color_space = JCS_RGB;
+ break;
+ case 1:
+ cinfo->jpeg_color_space = JCS_YCbCr;
+ break;
+ default:
+ WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
+ break;
+ }
+ } else {
+ /* Saw no special markers, try to guess from the component IDs */
+ int cid0 = cinfo->comp_info[0].component_id;
+ int cid1 = cinfo->comp_info[1].component_id;
+ int cid2 = cinfo->comp_info[2].component_id;
+
+ if (cid0 == 1 && cid1 == 2 && cid2 == 3)
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
+ else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
+ cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
+ else {
+ TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
+ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
+ }
+ }
+ /* Always guess RGB is proper output colorspace. */
+ cinfo->out_color_space = JCS_RGB;
+ break;
+
+ case 4:
+ if (cinfo->saw_Adobe_marker) {
+ switch (cinfo->Adobe_transform) {
+ case 0:
+ cinfo->jpeg_color_space = JCS_CMYK;
+ break;
+ case 2:
+ cinfo->jpeg_color_space = JCS_YCCK;
+ break;
+ default:
+ WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
+ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
+ break;
+ }
+ } else {
+ /* No special markers, assume straight CMYK. */
+ cinfo->jpeg_color_space = JCS_CMYK;
+ }
+ cinfo->out_color_space = JCS_CMYK;
+ break;
+
+ default:
+ cinfo->jpeg_color_space = JCS_UNKNOWN;
+ cinfo->out_color_space = JCS_UNKNOWN;
+ break;
+ }
+
+ /* Set defaults for other decompression parameters. */
+ cinfo->scale_num = 1; /* 1:1 scaling */
+ cinfo->scale_denom = 1;
+ cinfo->output_gamma = 1.0;
+ cinfo->buffered_image = FALSE;
+ cinfo->raw_data_out = FALSE;
+ cinfo->dct_method = JDCT_DEFAULT;
+ cinfo->do_fancy_upsampling = TRUE;
+ cinfo->do_block_smoothing = TRUE;
+ cinfo->quantize_colors = FALSE;
+ /* We set these in case application only sets quantize_colors. */
+ cinfo->dither_mode = JDITHER_FS;
+#ifdef QUANT_2PASS_SUPPORTED
+ cinfo->two_pass_quantize = TRUE;
+#else
+ cinfo->two_pass_quantize = FALSE;
+#endif
+ cinfo->desired_number_of_colors = 256;
+ cinfo->colormap = NULL;
+ /* Initialize for no mode change in buffered-image mode. */
+ cinfo->enable_1pass_quant = FALSE;
+ cinfo->enable_external_quant = FALSE;
+ cinfo->enable_2pass_quant = FALSE;
+}
+
+
+/*
+ * Decompression startup: read start of JPEG datastream to see what's there.
+ * Need only initialize JPEG object and supply a data source before calling.
+ *
+ * This routine will read as far as the first SOS marker (ie, actual start of
+ * compressed data), and will save all tables and parameters in the JPEG
+ * object. It will also initialize the decompression parameters to default
+ * values, and finally return JPEG_HEADER_OK. On return, the application may
+ * adjust the decompression parameters and then call jpeg_start_decompress.
+ * (Or, if the application only wanted to determine the image parameters,
+ * the data need not be decompressed. In that case, call jpeg_abort or
+ * jpeg_destroy to release any temporary space.)
+ * If an abbreviated (tables only) datastream is presented, the routine will
+ * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
+ * re-use the JPEG object to read the abbreviated image datastream(s).
+ * It is unnecessary (but OK) to call jpeg_abort in this case.
+ * The JPEG_SUSPENDED return code only occurs if the data source module
+ * requests suspension of the decompressor. In this case the application
+ * should load more source data and then re-call jpeg_read_header to resume
+ * processing.
+ * If a non-suspending data source is used and require_image is TRUE, then the
+ * return code need not be inspected since only JPEG_HEADER_OK is possible.
+ *
+ * This routine is now just a front end to jpeg_consume_input, with some
+ * extra error checking.
+ */
+
+GLOBAL(int)
+jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
+{
+ int retcode;
+
+ if (cinfo->global_state != DSTATE_START &&
+ cinfo->global_state != DSTATE_INHEADER)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ retcode = jpeg_consume_input(cinfo);
+
+ switch (retcode) {
+ case JPEG_REACHED_SOS:
+ retcode = JPEG_HEADER_OK;
+ break;
+ case JPEG_REACHED_EOI:
+ if (require_image) /* Complain if application wanted an image */
+ ERREXIT(cinfo, JERR_NO_IMAGE);
+ /* Reset to start state; it would be safer to require the application to
+ * call jpeg_abort, but we can't change it now for compatibility reasons.
+ * A side effect is to free any temporary memory (there shouldn't be any).
+ */
+ jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
+ retcode = JPEG_HEADER_TABLES_ONLY;
+ break;
+ case JPEG_SUSPENDED:
+ /* no work */
+ break;
+ }
+
+ return retcode;
+}
+
+
+/*
+ * Consume data in advance of what the decompressor requires.
+ * This can be called at any time once the decompressor object has
+ * been created and a data source has been set up.
+ *
+ * This routine is essentially a state machine that handles a couple
+ * of critical state-transition actions, namely initial setup and
+ * transition from header scanning to ready-for-start_decompress.
+ * All the actual input is done via the input controller's consume_input
+ * method.
+ */
+
+GLOBAL(int)
+jpeg_consume_input (j_decompress_ptr cinfo)
+{
+ int retcode = JPEG_SUSPENDED;
+
+ /* NB: every possible DSTATE value should be listed in this switch */
+ switch (cinfo->global_state) {
+ case DSTATE_START:
+ /* Start-of-datastream actions: reset appropriate modules */
+ (*cinfo->inputctl->reset_input_controller) (cinfo);
+ /* Initialize application's data source module */
+ (*cinfo->src->init_source) (cinfo);
+ cinfo->global_state = DSTATE_INHEADER;
+ /*FALLTHROUGH*/
+ case DSTATE_INHEADER:
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
+ if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
+ /* Set up default parameters based on header data */
+ default_decompress_parms(cinfo);
+ /* Set global state: ready for start_decompress */
+ cinfo->global_state = DSTATE_READY;
+ }
+ break;
+ case DSTATE_READY:
+ /* Can't advance past first SOS until start_decompress is called */
+ retcode = JPEG_REACHED_SOS;
+ break;
+ case DSTATE_PRELOAD:
+ case DSTATE_PRESCAN:
+ case DSTATE_SCANNING:
+ case DSTATE_RAW_OK:
+ case DSTATE_BUFIMAGE:
+ case DSTATE_BUFPOST:
+ case DSTATE_STOPPING:
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
+ break;
+ default:
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ }
+ return retcode;
+}
+
+
+/*
+ * Have we finished reading the input file?
+ */
+
+GLOBAL(boolean)
+jpeg_input_complete (j_decompress_ptr cinfo)
+{
+ /* Check for valid jpeg object */
+ if (cinfo->global_state < DSTATE_START ||
+ cinfo->global_state > DSTATE_STOPPING)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ return cinfo->inputctl->eoi_reached;
+}
+
+
+/*
+ * Is there more than one scan?
+ */
+
+GLOBAL(boolean)
+jpeg_has_multiple_scans (j_decompress_ptr cinfo)
+{
+ /* Only valid after jpeg_read_header completes */
+ if (cinfo->global_state < DSTATE_READY ||
+ cinfo->global_state > DSTATE_STOPPING)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ return cinfo->inputctl->has_multiple_scans;
+}
+
+
+/*
+ * Finish JPEG decompression.
+ *
+ * This will normally just verify the file trailer and release temp storage.
+ *
+ * Returns FALSE if suspended. The return value need be inspected only if
+ * a suspending data source is used.
+ */
+
+GLOBAL(boolean)
+jpeg_finish_decompress (j_decompress_ptr cinfo)
+{
+ if ((cinfo->global_state == DSTATE_SCANNING ||
+ cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
+ /* Terminate final pass of non-buffered mode */
+ if (cinfo->output_scanline < cinfo->output_height)
+ ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
+ (*cinfo->master->finish_output_pass) (cinfo);
+ cinfo->global_state = DSTATE_STOPPING;
+ } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
+ /* Finishing after a buffered-image operation */
+ cinfo->global_state = DSTATE_STOPPING;
+ } else if (cinfo->global_state != DSTATE_STOPPING) {
+ /* STOPPING = repeat call after a suspension, anything else is error */
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ }
+ /* Read until EOI */
+ while (! cinfo->inputctl->eoi_reached) {
+ if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
+ return FALSE; /* Suspend, come back later */
+ }
+ /* Do final cleanup */
+ (*cinfo->src->term_source) (cinfo);
+ /* We can use jpeg_abort to release memory and reset global_state */
+ jpeg_abort((j_common_ptr) cinfo);
+ return TRUE;
+}
diff --git a/osframework/source/ImageLib/jpeg/jdapistd.c b/osframework/source/ImageLib/jpeg/jdapistd.c
new file mode 100644
index 0000000..f6c7fff
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdapistd.c
@@ -0,0 +1,275 @@
+/*
+ * jdapistd.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains application interface code for the decompression half
+ * of the JPEG library. These are the "standard" API routines that are
+ * used in the normal full-decompression case. They are not used by a
+ * transcoding-only application. Note that if an application links in
+ * jpeg_start_decompress, it will end up linking in the entire decompressor.
+ * We thus must separate this file from jdapimin.c to avoid linking the
+ * whole decompression library into a transcoder.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Forward declarations */
+LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
+
+
+/*
+ * Decompression initialization.
+ * jpeg_read_header must be completed before calling this.
+ *
+ * If a multipass operating mode was selected, this will do all but the
+ * last pass, and thus may take a great deal of time.
+ *
+ * Returns FALSE if suspended. The return value need be inspected only if
+ * a suspending data source is used.
+ */
+
+GLOBAL(boolean)
+jpeg_start_decompress (j_decompress_ptr cinfo)
+{
+ if (cinfo->global_state == DSTATE_READY) {
+ /* First call: initialize master control, select active modules */
+ jinit_master_decompress(cinfo);
+ if (cinfo->buffered_image) {
+ /* No more work here; expecting jpeg_start_output next */
+ cinfo->global_state = DSTATE_BUFIMAGE;
+ return TRUE;
+ }
+ cinfo->global_state = DSTATE_PRELOAD;
+ }
+ if (cinfo->global_state == DSTATE_PRELOAD) {
+ /* If file has multiple scans, absorb them all into the coef buffer */
+ if (cinfo->inputctl->has_multiple_scans) {
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+ for (;;) {
+ int retcode;
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL)
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ /* Absorb some more input */
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
+ if (retcode == JPEG_SUSPENDED)
+ return FALSE;
+ if (retcode == JPEG_REACHED_EOI)
+ break;
+ /* Advance progress counter if appropriate */
+ if (cinfo->progress != NULL &&
+ (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
+ if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
+ /* jdmaster underestimated number of scans; ratchet up one scan */
+ cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
+ }
+ }
+ }
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+ }
+ cinfo->output_scan_number = cinfo->input_scan_number;
+ } else if (cinfo->global_state != DSTATE_PRESCAN)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ /* Perform any dummy output passes, and set up for the final pass */
+ return output_pass_setup(cinfo);
+}
+
+
+/*
+ * Set up for an output pass, and perform any dummy pass(es) needed.
+ * Common subroutine for jpeg_start_decompress and jpeg_start_output.
+ * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
+ * Exit: If done, returns TRUE and sets global_state for proper output mode.
+ * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
+ */
+
+LOCAL(boolean)
+output_pass_setup (j_decompress_ptr cinfo)
+{
+ if (cinfo->global_state != DSTATE_PRESCAN) {
+ /* First call: do pass setup */
+ (*cinfo->master->prepare_for_output_pass) (cinfo);
+ cinfo->output_scanline = 0;
+ cinfo->global_state = DSTATE_PRESCAN;
+ }
+ /* Loop over any required dummy passes */
+ while (cinfo->master->is_dummy_pass) {
+#ifdef QUANT_2PASS_SUPPORTED
+ /* Crank through the dummy pass */
+ while (cinfo->output_scanline < cinfo->output_height) {
+ JDIMENSION last_scanline;
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+ /* Process some data */
+ last_scanline = cinfo->output_scanline;
+ (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
+ &cinfo->output_scanline, (JDIMENSION) 0);
+ if (cinfo->output_scanline == last_scanline)
+ return FALSE; /* No progress made, must suspend */
+ }
+ /* Finish up dummy pass, and set up for another one */
+ (*cinfo->master->finish_output_pass) (cinfo);
+ (*cinfo->master->prepare_for_output_pass) (cinfo);
+ cinfo->output_scanline = 0;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif /* QUANT_2PASS_SUPPORTED */
+ }
+ /* Ready for application to drive output pass through
+ * jpeg_read_scanlines or jpeg_read_raw_data.
+ */
+ cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
+ return TRUE;
+}
+
+
+/*
+ * Read some scanlines of data from the JPEG decompressor.
+ *
+ * The return value will be the number of lines actually read.
+ * This may be less than the number requested in several cases,
+ * including bottom of image, data source suspension, and operating
+ * modes that emit multiple scanlines at a time.
+ *
+ * Note: we warn about excess calls to jpeg_read_scanlines() since
+ * this likely signals an application programmer error. However,
+ * an oversize buffer (max_lines > scanlines remaining) is not an error.
+ */
+
+GLOBAL(JDIMENSION)
+jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
+ JDIMENSION max_lines)
+{
+ JDIMENSION row_ctr;
+
+ if (cinfo->global_state != DSTATE_SCANNING)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ if (cinfo->output_scanline >= cinfo->output_height) {
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+ return 0;
+ }
+
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+
+ /* Process some data */
+ row_ctr = 0;
+ (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
+ cinfo->output_scanline += row_ctr;
+ return row_ctr;
+}
+
+
+/*
+ * Alternate entry point to read raw data.
+ * Processes exactly one iMCU row per call, unless suspended.
+ */
+
+GLOBAL(JDIMENSION)
+jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
+ JDIMENSION max_lines)
+{
+ JDIMENSION lines_per_iMCU_row;
+
+ if (cinfo->global_state != DSTATE_RAW_OK)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ if (cinfo->output_scanline >= cinfo->output_height) {
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+ return 0;
+ }
+
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ }
+
+ /* Verify that at least one iMCU row can be returned. */
+ lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
+ if (max_lines < lines_per_iMCU_row)
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
+
+ /* Decompress directly into user's buffer. */
+ if (! (*cinfo->coef->decompress_data) (cinfo, data))
+ return 0; /* suspension forced, can do nothing more */
+
+ /* OK, we processed one iMCU row. */
+ cinfo->output_scanline += lines_per_iMCU_row;
+ return lines_per_iMCU_row;
+}
+
+
+/* Additional entry points for buffered-image mode. */
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+/*
+ * Initialize for an output pass in buffered-image mode.
+ */
+
+GLOBAL(boolean)
+jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
+{
+ if (cinfo->global_state != DSTATE_BUFIMAGE &&
+ cinfo->global_state != DSTATE_PRESCAN)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ /* Limit scan number to valid range */
+ if (scan_number <= 0)
+ scan_number = 1;
+ if (cinfo->inputctl->eoi_reached &&
+ scan_number > cinfo->input_scan_number)
+ scan_number = cinfo->input_scan_number;
+ cinfo->output_scan_number = scan_number;
+ /* Perform any dummy output passes, and set up for the real pass */
+ return output_pass_setup(cinfo);
+}
+
+
+/*
+ * Finish up after an output pass in buffered-image mode.
+ *
+ * Returns FALSE if suspended. The return value need be inspected only if
+ * a suspending data source is used.
+ */
+
+GLOBAL(boolean)
+jpeg_finish_output (j_decompress_ptr cinfo)
+{
+ if ((cinfo->global_state == DSTATE_SCANNING ||
+ cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
+ /* Terminate this pass. */
+ /* We do not require the whole pass to have been completed. */
+ (*cinfo->master->finish_output_pass) (cinfo);
+ cinfo->global_state = DSTATE_BUFPOST;
+ } else if (cinfo->global_state != DSTATE_BUFPOST) {
+ /* BUFPOST = repeat call after a suspension, anything else is error */
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ }
+ /* Read markers looking for SOS or EOI */
+ while (cinfo->input_scan_number <= cinfo->output_scan_number &&
+ ! cinfo->inputctl->eoi_reached) {
+ if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
+ return FALSE; /* Suspend, come back later */
+ }
+ cinfo->global_state = DSTATE_BUFIMAGE;
+ return TRUE;
+}
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jdatadst.c b/osframework/source/ImageLib/jpeg/jdatadst.c
new file mode 100644
index 0000000..2ece4e9
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdatadst.c
@@ -0,0 +1,151 @@
+/*
+ * jdatadst.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains compression data destination routines for the case of
+ * emitting JPEG data to a file (or any stdio stream). While these routines
+ * are sufficient for most applications, some will want to use a different
+ * destination manager.
+ * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
+ * JOCTETs into 8-bit-wide elements on external storage. If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jerror.h"
+
+
+/* Expanded data destination object for stdio output */
+
+typedef struct {
+ struct jpeg_destination_mgr pub; /* public fields */
+
+ FILE * outfile; /* target stream */
+ JOCTET * buffer; /* start of buffer */
+} my_destination_mgr;
+
+typedef my_destination_mgr * my_dest_ptr;
+
+#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
+
+
+/*
+ * Initialize destination --- called by jpeg_start_compress
+ * before any data is actually written.
+ */
+
+METHODDEF(void)
+init_destination (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+ /* Allocate the output buffer --- it will be released when done with image */
+ dest->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
+
+ dest->pub.next_output_byte = dest->buffer;
+ dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+}
+
+
+/*
+ * Empty the output buffer --- called whenever buffer fills up.
+ *
+ * In typical applications, this should write the entire output buffer
+ * (ignoring the current state of next_output_byte & free_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been dumped.
+ *
+ * In applications that need to be able to suspend compression due to output
+ * overrun, a FALSE return indicates that the buffer cannot be emptied now.
+ * In this situation, the compressor will return to its caller (possibly with
+ * an indication that it has not accepted all the supplied scanlines). The
+ * application should resume compression after it has made more room in the
+ * output buffer. Note that there are substantial restrictions on the use of
+ * suspension --- see the documentation.
+ *
+ * When suspending, the compressor will back up to a convenient restart point
+ * (typically the start of the current MCU). next_output_byte & free_in_buffer
+ * indicate where the restart point will be if the current call returns FALSE.
+ * Data beyond this point will be regenerated after resumption, so do not
+ * write it out when emptying the buffer externally.
+ */
+
+METHODDEF(boolean)
+empty_output_buffer (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+ if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
+ (size_t) OUTPUT_BUF_SIZE)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+
+ dest->pub.next_output_byte = dest->buffer;
+ dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+
+ return TRUE;
+}
+
+
+/*
+ * Terminate destination --- called by jpeg_finish_compress
+ * after all data has been written. Usually needs to flush buffer.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_destination (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+ size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
+
+ /* Write any data remaining in the buffer */
+ if (datacount > 0) {
+ if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ }
+ fflush(dest->outfile);
+ /* Make sure we wrote the output file OK */
+ if (ferror(dest->outfile))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * Prepare for output to a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing compression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
+{
+ my_dest_ptr dest;
+
+ /* The destination object is made permanent so that multiple JPEG images
+ * can be written to the same file without re-executing jpeg_stdio_dest.
+ * This makes it dangerous to use this manager and a different destination
+ * manager serially with the same JPEG object, because their private object
+ * sizes may be different. Caveat programmer.
+ */
+ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
+ cinfo->dest = (struct jpeg_destination_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_destination_mgr));
+ }
+
+ dest = (my_dest_ptr) cinfo->dest;
+ dest->pub.init_destination = init_destination;
+ dest->pub.empty_output_buffer = empty_output_buffer;
+ dest->pub.term_destination = term_destination;
+ dest->outfile = outfile;
+}
diff --git a/osframework/source/ImageLib/jpeg/jdatasrc.c b/osframework/source/ImageLib/jpeg/jdatasrc.c
new file mode 100644
index 0000000..29b6983
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdatasrc.c
@@ -0,0 +1,212 @@
+/*
+ * jdatasrc.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains decompression data source routines for the case of
+ * reading JPEG data from a file (or any stdio stream). While these routines
+ * are sufficient for most applications, some will want to use a different
+ * source manager.
+ * IMPORTANT: we assume that fread() will correctly transcribe an array of
+ * JOCTETs from 8-bit-wide elements on external storage. If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jerror.h"
+
+
+/* Expanded data source object for stdio input */
+
+typedef struct {
+ struct jpeg_source_mgr pub; /* public fields */
+
+ FILE * infile; /* source stream */
+ JOCTET * buffer; /* start of buffer */
+ boolean start_of_file; /* have we gotten any data yet? */
+} my_source_mgr;
+
+typedef my_source_mgr * my_src_ptr;
+
+#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
+
+
+/*
+ * Initialize source --- called by jpeg_read_header
+ * before any data is actually read.
+ */
+
+METHODDEF(void)
+init_source (j_decompress_ptr cinfo)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+
+ /* We reset the empty-input-file flag for each image,
+ * but we don't clear the input buffer.
+ * This is correct behavior for reading a series of images from one source.
+ */
+ src->start_of_file = TRUE;
+}
+
+
+/*
+ * Fill the input buffer --- called whenever buffer is emptied.
+ *
+ * In typical applications, this should read fresh data into the buffer
+ * (ignoring the current state of next_input_byte & bytes_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been reloaded. It is not necessary to
+ * fill the buffer entirely, only to obtain at least one more byte.
+ *
+ * There is no such thing as an EOF return. If the end of the file has been
+ * reached, the routine has a choice of ERREXIT() or inserting fake data into
+ * the buffer. In most cases, generating a warning message and inserting a
+ * fake EOI marker is the best course of action --- this will allow the
+ * decompressor to output however much of the image is there. However,
+ * the resulting error message is misleading if the real problem is an empty
+ * input file, so we handle that case specially.
+ *
+ * In applications that need to be able to suspend compression due to input
+ * not being available yet, a FALSE return indicates that no more data can be
+ * obtained right now, but more may be forthcoming later. In this situation,
+ * the decompressor will return to its caller (with an indication of the
+ * number of scanlines it has read, if any). The application should resume
+ * decompression after it has loaded more data into the input buffer. Note
+ * that there are substantial restrictions on the use of suspension --- see
+ * the documentation.
+ *
+ * When suspending, the decompressor will back up to a convenient restart point
+ * (typically the start of the current MCU). 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 move it to
+ * the front of the buffer rather than discarding it.
+ */
+
+METHODDEF(boolean)
+fill_input_buffer (j_decompress_ptr cinfo)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+ size_t nbytes;
+
+ nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
+
+ if (nbytes <= 0) {
+ if (src->start_of_file) /* Treat empty input file as fatal error */
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
+ WARNMS(cinfo, JWRN_JPEG_EOF);
+ /* Insert a fake EOI marker */
+ src->buffer[0] = (JOCTET) 0xFF;
+ src->buffer[1] = (JOCTET) JPEG_EOI;
+ nbytes = 2;
+ }
+
+ src->pub.next_input_byte = src->buffer;
+ src->pub.bytes_in_buffer = nbytes;
+ src->start_of_file = FALSE;
+
+ return TRUE;
+}
+
+
+/*
+ * Skip data --- used to skip over a potentially large amount of
+ * uninteresting data (such as an APPn marker).
+ *
+ * Writers of suspendable-input applications must note that skip_input_data
+ * is not granted the right to give a suspension return. If the skip extends
+ * beyond the data currently in the buffer, the buffer can be marked empty so
+ * that the next read will cause a fill_input_buffer call that can suspend.
+ * Arranging for additional bytes to be discarded before reloading the input
+ * buffer is the application writer's problem.
+ */
+
+METHODDEF(void)
+skip_input_data (j_decompress_ptr cinfo, long num_bytes)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+
+ /* Just a dumb implementation for now. Could use fseek() except
+ * it doesn't work on pipes. Not clear that being smart is worth
+ * any trouble anyway --- large skips are infrequent.
+ */
+ if (num_bytes > 0) {
+ while (num_bytes > (long) src->pub.bytes_in_buffer) {
+ num_bytes -= (long) src->pub.bytes_in_buffer;
+ (void) fill_input_buffer(cinfo);
+ /* note we assume that fill_input_buffer will never return FALSE,
+ * so suspension need not be handled.
+ */
+ }
+ src->pub.next_input_byte += (size_t) num_bytes;
+ src->pub.bytes_in_buffer -= (size_t) num_bytes;
+ }
+}
+
+
+/*
+ * An additional method that can be provided by data source modules is the
+ * resync_to_restart method for error recovery in the presence of RST markers.
+ * For the moment, this source module just uses the default resync method
+ * provided by the JPEG library. That method assumes that no backtracking
+ * is possible.
+ */
+
+
+/*
+ * Terminate source --- called by jpeg_finish_decompress
+ * after all data has been read. Often a no-op.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_source (j_decompress_ptr cinfo)
+{
+ /* no work necessary here */
+}
+
+
+/*
+ * Prepare for input from a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing decompression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
+{
+ my_src_ptr src;
+
+ /* The source object and input buffer are made permanent so that a series
+ * of JPEG images can be read from the same file by calling jpeg_stdio_src
+ * only before the first one. (If we discarded the buffer at the end of
+ * one image, we'd likely lose the start of the next one.)
+ * This makes it unsafe to use this manager and a different source
+ * manager serially with the same JPEG object. Caveat programmer.
+ */
+ if (cinfo->src == NULL) { /* first time for this JPEG object? */
+ cinfo->src = (struct jpeg_source_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_source_mgr));
+ src = (my_src_ptr) cinfo->src;
+ src->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ INPUT_BUF_SIZE * SIZEOF(JOCTET));
+ }
+
+ src = (my_src_ptr) cinfo->src;
+ 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; /* use default method */
+ src->pub.term_source = term_source;
+ src->infile = infile;
+ src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+ src->pub.next_input_byte = NULL; /* until buffer loaded */
+}
diff --git a/osframework/source/ImageLib/jpeg/jdcoefct.c b/osframework/source/ImageLib/jpeg/jdcoefct.c
new file mode 100644
index 0000000..992bd10
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdcoefct.c
@@ -0,0 +1,736 @@
+/*
+ * jdcoefct.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the coefficient buffer controller for decompression.
+ * This controller is the top level of the JPEG decompressor proper.
+ * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
+ *
+ * In buffered-image mode, this controller is the interface between
+ * input-oriented processing and output-oriented processing.
+ * Also, the input side (only) is used when reading a file for transcoding.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+/* Block smoothing is only applicable for progressive JPEG, so: */
+#ifndef D_PROGRESSIVE_SUPPORTED
+#undef BLOCK_SMOOTHING_SUPPORTED
+#endif
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_d_coef_controller pub; /* public fields */
+
+ /* These variables keep track of the current location of the input side. */
+ /* cinfo->input_iMCU_row is also used for this. */
+ JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
+ int MCU_vert_offset; /* counts MCU rows within iMCU row */
+ int MCU_rows_per_iMCU_row; /* number of such rows needed */
+
+ /* The output side's location is represented by cinfo->output_iMCU_row. */
+
+ /* In single-pass modes, it's sufficient to buffer just one MCU.
+ * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
+ * and let the entropy decoder write into that workspace each time.
+ * (On 80x86, the workspace is FAR even though it's not really very big;
+ * this is to keep the module interfaces unchanged when a large coefficient
+ * buffer is necessary.)
+ * In multi-pass modes, this array points to the current MCU's blocks
+ * within the virtual arrays; it is used only by the input side.
+ */
+ JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+ /* In multi-pass modes, we need a virtual block array for each component. */
+ jvirt_barray_ptr whole_image[MAX_COMPONENTS];
+#endif
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+ /* When doing block smoothing, we latch coefficient Al values here */
+ int * coef_bits_latch;
+#define SAVED_COEFS 6 /* we save coef_bits[0..5] */
+#endif
+} my_coef_controller;
+
+typedef my_coef_controller * my_coef_ptr;
+
+/* Forward declarations */
+METHODDEF(int) decompress_onepass
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+METHODDEF(int) decompress_data
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+#endif
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
+METHODDEF(int) decompress_smooth_data
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+#endif
+
+
+LOCAL(void)
+start_iMCU_row (j_decompress_ptr cinfo)
+/* Reset within-iMCU-row counters for a new row (input side) */
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ /* In an interleaved scan, an MCU row is the same as an iMCU row.
+ * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
+ * But at the bottom of the image, process only what's left.
+ */
+ if (cinfo->comps_in_scan > 1) {
+ coef->MCU_rows_per_iMCU_row = 1;
+ } else {
+ if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
+ else
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
+ }
+
+ coef->MCU_ctr = 0;
+ coef->MCU_vert_offset = 0;
+}
+
+
+/*
+ * Initialize for an input processing pass.
+ */
+
+METHODDEF(void)
+start_input_pass (j_decompress_ptr cinfo)
+{
+ cinfo->input_iMCU_row = 0;
+ start_iMCU_row(cinfo);
+}
+
+
+/*
+ * Initialize for an output processing pass.
+ */
+
+METHODDEF(void)
+start_output_pass (j_decompress_ptr cinfo)
+{
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ /* If multipass, check to see whether to use block smoothing on this pass */
+ if (coef->pub.coef_arrays != NULL) {
+ if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
+ coef->pub.decompress_data = decompress_smooth_data;
+ else
+ coef->pub.decompress_data = decompress_data;
+ }
+#endif
+ cinfo->output_iMCU_row = 0;
+}
+
+
+/*
+ * Decompress and return some data in the single-pass case.
+ * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
+ * Input and output must run in lockstep since we have only a one-MCU buffer.
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+ *
+ * NB: output_buf contains a plane for each component in image,
+ * which we index according to the component's SOF position.
+ */
+
+METHODDEF(int)
+decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+ JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ int blkn, ci, xindex, yindex, yoffset, useful_width;
+ JSAMPARRAY output_ptr;
+ JDIMENSION start_col, output_col;
+ jpeg_component_info *compptr;
+ inverse_DCT_method_ptr inverse_DCT;
+
+ /* Loop to process as much as one whole iMCU row */
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+ yoffset++) {
+ for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
+ MCU_col_num++) {
+ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
+ jzero_far((void FAR *) coef->MCU_buffer[0],
+ (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
+ if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
+ /* Suspension forced; update state counters and exit */
+ coef->MCU_vert_offset = yoffset;
+ coef->MCU_ctr = MCU_col_num;
+ return JPEG_SUSPENDED;
+ }
+ /* Determine where data should go in output_buf and do the IDCT thing.
+ * We skip dummy blocks at the right and bottom edges (but blkn gets
+ * incremented past them!). Note the inner loop relies on having
+ * allocated the MCU_buffer[] blocks sequentially.
+ */
+ blkn = 0; /* index of current DCT block within MCU */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* Don't bother to IDCT an uninteresting component. */
+ if (! compptr->component_needed) {
+ blkn += compptr->MCU_blocks;
+ continue;
+ }
+ inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
+ useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
+ : compptr->last_col_width;
+ output_ptr = output_buf[compptr->component_index] +
+ yoffset * compptr->DCT_scaled_size;
+ start_col = MCU_col_num * compptr->MCU_sample_width;
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+ if (cinfo->input_iMCU_row < last_iMCU_row ||
+ yoffset+yindex < compptr->last_row_height) {
+ output_col = start_col;
+ for (xindex = 0; xindex < useful_width; xindex++) {
+ (*inverse_DCT) (cinfo, compptr,
+ (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
+ output_ptr, output_col);
+ output_col += compptr->DCT_scaled_size;
+ }
+ }
+ blkn += compptr->MCU_width;
+ output_ptr += compptr->DCT_scaled_size;
+ }
+ }
+ }
+ /* Completed an MCU row, but perhaps not an iMCU row */
+ coef->MCU_ctr = 0;
+ }
+ /* Completed the iMCU row, advance counters for next one */
+ cinfo->output_iMCU_row++;
+ if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
+ start_iMCU_row(cinfo);
+ return JPEG_ROW_COMPLETED;
+ }
+ /* Completed the scan */
+ (*cinfo->inputctl->finish_input_pass) (cinfo);
+ return JPEG_SCAN_COMPLETED;
+}
+
+
+/*
+ * Dummy consume-input routine for single-pass operation.
+ */
+
+METHODDEF(int)
+dummy_consume_data (j_decompress_ptr cinfo)
+{
+ return JPEG_SUSPENDED; /* Always indicate nothing was done */
+}
+
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+/*
+ * Consume input data and store it in the full-image coefficient buffer.
+ * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
+ * ie, v_samp_factor block rows for each component in the scan.
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+ */
+
+METHODDEF(int)
+consume_data (j_decompress_ptr cinfo)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+ int blkn, ci, xindex, yindex, yoffset;
+ JDIMENSION start_col;
+ JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
+ JBLOCKROW buffer_ptr;
+ jpeg_component_info *compptr;
+
+ /* Align the virtual buffers for the components used in this scan. */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ buffer[ci] = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
+ cinfo->input_iMCU_row * compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ /* Note: entropy decoder expects buffer to be zeroed,
+ * but this is handled automatically by the memory manager
+ * because we requested a pre-zeroed array.
+ */
+ }
+
+ /* Loop to process one whole iMCU row */
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+ yoffset++) {
+ for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
+ MCU_col_num++) {
+ /* Construct list of pointers to DCT blocks belonging to this MCU */
+ blkn = 0; /* index of current DCT block within MCU */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ start_col = MCU_col_num * compptr->MCU_width;
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+ buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
+ for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
+ coef->MCU_buffer[blkn++] = buffer_ptr++;
+ }
+ }
+ }
+ /* Try to fetch the MCU. */
+ if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
+ /* Suspension forced; update state counters and exit */
+ coef->MCU_vert_offset = yoffset;
+ coef->MCU_ctr = MCU_col_num;
+ return JPEG_SUSPENDED;
+ }
+ }
+ /* Completed an MCU row, but perhaps not an iMCU row */
+ coef->MCU_ctr = 0;
+ }
+ /* Completed the iMCU row, advance counters for next one */
+ if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
+ start_iMCU_row(cinfo);
+ return JPEG_ROW_COMPLETED;
+ }
+ /* Completed the scan */
+ (*cinfo->inputctl->finish_input_pass) (cinfo);
+ return JPEG_SCAN_COMPLETED;
+}
+
+
+/*
+ * Decompress and return some data in the multi-pass case.
+ * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+ *
+ * NB: output_buf contains a plane for each component in image.
+ */
+
+METHODDEF(int)
+decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ JDIMENSION block_num;
+ int ci, block_row, block_rows;
+ JBLOCKARRAY buffer;
+ JBLOCKROW buffer_ptr;
+ JSAMPARRAY output_ptr;
+ JDIMENSION output_col;
+ jpeg_component_info *compptr;
+ inverse_DCT_method_ptr inverse_DCT;
+
+ /* Force some input to be done if we are getting ahead of the input. */
+ while (cinfo->input_scan_number < cinfo->output_scan_number ||
+ (cinfo->input_scan_number == cinfo->output_scan_number &&
+ cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
+ if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
+ return JPEG_SUSPENDED;
+ }
+
+ /* OK, output from the virtual arrays. */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Don't bother to IDCT an uninteresting component. */
+ if (! compptr->component_needed)
+ continue;
+ /* Align the virtual buffer for this component. */
+ buffer = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+ cinfo->output_iMCU_row * compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ /* Count non-dummy DCT block rows in this iMCU row. */
+ if (cinfo->output_iMCU_row < last_iMCU_row)
+ block_rows = compptr->v_samp_factor;
+ else {
+ /* NB: can't use last_row_height here; it is input-side-dependent! */
+ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+ if (block_rows == 0) block_rows = compptr->v_samp_factor;
+ }
+ inverse_DCT = cinfo->idct->inverse_DCT[ci];
+ output_ptr = output_buf[ci];
+ /* Loop over all DCT blocks to be processed. */
+ for (block_row = 0; block_row < block_rows; block_row++) {
+ buffer_ptr = buffer[block_row];
+ output_col = 0;
+ for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
+ (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
+ output_ptr, output_col);
+ buffer_ptr++;
+ output_col += compptr->DCT_scaled_size;
+ }
+ output_ptr += compptr->DCT_scaled_size;
+ }
+ }
+
+ if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
+ return JPEG_ROW_COMPLETED;
+ return JPEG_SCAN_COMPLETED;
+}
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+/*
+ * This code applies interblock smoothing as described by section K.8
+ * of the JPEG standard: the first 5 AC coefficients are estimated from
+ * the DC values of a DCT block and its 8 neighboring blocks.
+ * We apply smoothing only for progressive JPEG decoding, and only if
+ * the coefficients it can estimate are not yet known to full precision.
+ */
+
+/* Natural-order array positions of the first 5 zigzag-order coefficients */
+#define Q01_POS 1
+#define Q10_POS 8
+#define Q20_POS 16
+#define Q11_POS 9
+#define Q02_POS 2
+
+/*
+ * Determine whether block smoothing is applicable and safe.
+ * We also latch the current states of the coef_bits[] entries for the
+ * AC coefficients; otherwise, if the input side of the decompressor
+ * advances into a new scan, we might think the coefficients are known
+ * more accurately than they really are.
+ */
+
+LOCAL(boolean)
+smoothing_ok (j_decompress_ptr cinfo)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ boolean smoothing_useful = FALSE;
+ int ci, coefi;
+ jpeg_component_info *compptr;
+ JQUANT_TBL * qtable;
+ int * coef_bits;
+ int * coef_bits_latch;
+
+ if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
+ return FALSE;
+
+ /* Allocate latch area if not already done */
+ if (coef->coef_bits_latch == NULL)
+ coef->coef_bits_latch = (int *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->num_components *
+ (SAVED_COEFS * SIZEOF(int)));
+ coef_bits_latch = coef->coef_bits_latch;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* All components' quantization values must already be latched. */
+ if ((qtable = compptr->quant_table) == NULL)
+ return FALSE;
+ /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
+ if (qtable->quantval[0] == 0 ||
+ qtable->quantval[Q01_POS] == 0 ||
+ qtable->quantval[Q10_POS] == 0 ||
+ qtable->quantval[Q20_POS] == 0 ||
+ qtable->quantval[Q11_POS] == 0 ||
+ qtable->quantval[Q02_POS] == 0)
+ return FALSE;
+ /* DC values must be at least partly known for all components. */
+ coef_bits = cinfo->coef_bits[ci];
+ if (coef_bits[0] < 0)
+ return FALSE;
+ /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
+ for (coefi = 1; coefi <= 5; coefi++) {
+ coef_bits_latch[coefi] = coef_bits[coefi];
+ if (coef_bits[coefi] != 0)
+ smoothing_useful = TRUE;
+ }
+ coef_bits_latch += SAVED_COEFS;
+ }
+
+ return smoothing_useful;
+}
+
+
+/*
+ * Variant of decompress_data for use when doing block smoothing.
+ */
+
+METHODDEF(int)
+decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+{
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+ JDIMENSION block_num, last_block_column;
+ int ci, block_row, block_rows, access_rows;
+ JBLOCKARRAY buffer;
+ JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
+ JSAMPARRAY output_ptr;
+ JDIMENSION output_col;
+ jpeg_component_info *compptr;
+ inverse_DCT_method_ptr inverse_DCT;
+ boolean first_row, last_row;
+ JBLOCK workspace;
+ int *coef_bits;
+ JQUANT_TBL *quanttbl;
+ INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
+ int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
+ int Al, pred;
+
+ /* Force some input to be done if we are getting ahead of the input. */
+ while (cinfo->input_scan_number <= cinfo->output_scan_number &&
+ ! cinfo->inputctl->eoi_reached) {
+ if (cinfo->input_scan_number == cinfo->output_scan_number) {
+ /* If input is working on current scan, we ordinarily want it to
+ * have completed the current row. But if input scan is DC,
+ * we want it to keep one row ahead so that next block row's DC
+ * values are up to date.
+ */
+ JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
+ if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
+ break;
+ }
+ if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
+ return JPEG_SUSPENDED;
+ }
+
+ /* OK, output from the virtual arrays. */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Don't bother to IDCT an uninteresting component. */
+ if (! compptr->component_needed)
+ continue;
+ /* Count non-dummy DCT block rows in this iMCU row. */
+ if (cinfo->output_iMCU_row < last_iMCU_row) {
+ block_rows = compptr->v_samp_factor;
+ access_rows = block_rows * 2; /* this and next iMCU row */
+ last_row = FALSE;
+ } else {
+ /* NB: can't use last_row_height here; it is input-side-dependent! */
+ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+ if (block_rows == 0) block_rows = compptr->v_samp_factor;
+ access_rows = block_rows; /* this iMCU row only */
+ last_row = TRUE;
+ }
+ /* Align the virtual buffer for this component. */
+ if (cinfo->output_iMCU_row > 0) {
+ access_rows += compptr->v_samp_factor; /* prior iMCU row too */
+ buffer = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+ (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
+ (JDIMENSION) access_rows, FALSE);
+ buffer += compptr->v_samp_factor; /* point to current iMCU row */
+ first_row = FALSE;
+ } else {
+ buffer = (*cinfo->mem->access_virt_barray)
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+ (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
+ first_row = TRUE;
+ }
+ /* Fetch component-dependent info */
+ coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
+ quanttbl = compptr->quant_table;
+ Q00 = quanttbl->quantval[0];
+ Q01 = quanttbl->quantval[Q01_POS];
+ Q10 = quanttbl->quantval[Q10_POS];
+ Q20 = quanttbl->quantval[Q20_POS];
+ Q11 = quanttbl->quantval[Q11_POS];
+ Q02 = quanttbl->quantval[Q02_POS];
+ inverse_DCT = cinfo->idct->inverse_DCT[ci];
+ output_ptr = output_buf[ci];
+ /* Loop over all DCT blocks to be processed. */
+ for (block_row = 0; block_row < block_rows; block_row++) {
+ buffer_ptr = buffer[block_row];
+ if (first_row && block_row == 0)
+ prev_block_row = buffer_ptr;
+ else
+ prev_block_row = buffer[block_row-1];
+ if (last_row && block_row == block_rows-1)
+ next_block_row = buffer_ptr;
+ else
+ next_block_row = buffer[block_row+1];
+ /* We fetch the surrounding DC values using a sliding-register approach.
+ * Initialize all nine here so as to do the right thing on narrow pics.
+ */
+ DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
+ DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
+ DC7 = DC8 = DC9 = (int) next_block_row[0][0];
+ output_col = 0;
+ last_block_column = compptr->width_in_blocks - 1;
+ for (block_num = 0; block_num <= last_block_column; block_num++) {
+ /* Fetch current DCT block into workspace so we can modify it. */
+ jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
+ /* Update DC values */
+ if (block_num < last_block_column) {
+ DC3 = (int) prev_block_row[1][0];
+ DC6 = (int) buffer_ptr[1][0];
+ DC9 = (int) next_block_row[1][0];
+ }
+ /* Compute coefficient estimates per K.8.
+ * An estimate is applied only if coefficient is still zero,
+ * and is not known to be fully accurate.
+ */
+ /* AC01 */
+ if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
+ num = 36 * Q00 * (DC4 - DC6);
+ if (num >= 0) {
+ pred = (int) (((Q01<<7) + num) / (Q01<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ } else {
+ pred = (int) (((Q01<<7) - num) / (Q01<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ pred = -pred;
+ }
+ workspace[1] = (JCOEF) pred;
+ }
+ /* AC10 */
+ if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
+ num = 36 * Q00 * (DC2 - DC8);
+ if (num >= 0) {
+ pred = (int) (((Q10<<7) + num) / (Q10<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ } else {
+ pred = (int) (((Q10<<7) - num) / (Q10<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ pred = -pred;
+ }
+ workspace[8] = (JCOEF) pred;
+ }
+ /* AC20 */
+ if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
+ num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
+ if (num >= 0) {
+ pred = (int) (((Q20<<7) + num) / (Q20<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ } else {
+ pred = (int) (((Q20<<7) - num) / (Q20<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ pred = -pred;
+ }
+ workspace[16] = (JCOEF) pred;
+ }
+ /* AC11 */
+ if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
+ num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
+ if (num >= 0) {
+ pred = (int) (((Q11<<7) + num) / (Q11<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ } else {
+ pred = (int) (((Q11<<7) - num) / (Q11<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ pred = -pred;
+ }
+ workspace[9] = (JCOEF) pred;
+ }
+ /* AC02 */
+ if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
+ num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
+ if (num >= 0) {
+ pred = (int) (((Q02<<7) + num) / (Q02<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ } else {
+ pred = (int) (((Q02<<7) - num) / (Q02<<8));
+ if (Al > 0 && pred >= (1<<Al))
+ pred = (1<<Al)-1;
+ pred = -pred;
+ }
+ workspace[2] = (JCOEF) pred;
+ }
+ /* OK, do the IDCT */
+ (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
+ output_ptr, output_col);
+ /* Advance for next column */
+ DC1 = DC2; DC2 = DC3;
+ DC4 = DC5; DC5 = DC6;
+ DC7 = DC8; DC8 = DC9;
+ buffer_ptr++, prev_block_row++, next_block_row++;
+ output_col += compptr->DCT_scaled_size;
+ }
+ output_ptr += compptr->DCT_scaled_size;
+ }
+ }
+
+ if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
+ return JPEG_ROW_COMPLETED;
+ return JPEG_SCAN_COMPLETED;
+}
+
+#endif /* BLOCK_SMOOTHING_SUPPORTED */
+
+
+/*
+ * Initialize coefficient buffer controller.
+ */
+
+GLOBAL(void)
+jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
+{
+ my_coef_ptr coef;
+
+ coef = (my_coef_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_coef_controller));
+ cinfo->coef = (struct jpeg_d_coef_controller *) coef;
+ coef->pub.start_input_pass = start_input_pass;
+ coef->pub.start_output_pass = start_output_pass;
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+ coef->coef_bits_latch = NULL;
+#endif
+
+ /* Create the coefficient buffer. */
+ if (need_full_buffer) {
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+ /* Allocate a full-image virtual array for each component, */
+ /* padded to a multiple of samp_factor DCT blocks in each direction. */
+ /* Note we ask for a pre-zeroed array. */
+ int ci, access_rows;
+ jpeg_component_info *compptr;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ access_rows = compptr->v_samp_factor;
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+ /* If block smoothing could be used, need a bigger window */
+ if (cinfo->progressive_mode)
+ access_rows *= 3;
+#endif
+ coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) access_rows);
+ }
+ coef->pub.consume_data = consume_data;
+ coef->pub.decompress_data = decompress_data;
+ coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ /* We only need a single-MCU buffer. */
+ JBLOCKROW buffer;
+ int i;
+
+ buffer = (JBLOCKROW)
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
+ for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
+ coef->MCU_buffer[i] = buffer + i;
+ }
+ coef->pub.consume_data = dummy_consume_data;
+ coef->pub.decompress_data = decompress_onepass;
+ coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdcolor.c b/osframework/source/ImageLib/jpeg/jdcolor.c
new file mode 100644
index 0000000..fd7b138
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdcolor.c
@@ -0,0 +1,396 @@
+/*
+ * jdcolor.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains output colorspace conversion routines.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_color_deconverter pub; /* public fields */
+
+ /* Private state for YCC->RGB conversion */
+ int * Cr_r_tab; /* => table for Cr to R conversion */
+ int * Cb_b_tab; /* => table for Cb to B conversion */
+ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
+ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
+} my_color_deconverter;
+
+typedef my_color_deconverter * my_cconvert_ptr;
+
+
+/**************** YCbCr -> RGB conversion: most common case **************/
+
+/*
+ * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
+ * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
+ * The conversion equations to be implemented are therefore
+ * R = Y + 1.40200 * Cr
+ * G = Y - 0.34414 * Cb - 0.71414 * Cr
+ * B = Y + 1.77200 * Cb
+ * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
+ * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
+ *
+ * To avoid floating-point arithmetic, we represent the fractional constants
+ * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
+ * the products by 2^16, with appropriate rounding, to get the correct answer.
+ * Notice that Y, being an integral input, does not contribute any fraction
+ * so it need not participate in the rounding.
+ *
+ * For even more speed, we avoid doing any multiplications in the inner loop
+ * by precalculating the constants times Cb and Cr for all possible values.
+ * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
+ * for 12-bit samples it is still acceptable. It's not very reasonable for
+ * 16-bit samples, but if you want lossless storage you shouldn't be changing
+ * colorspace anyway.
+ * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
+ * values for the G calculation are left scaled up, since we must add them
+ * together before rounding.
+ */
+
+#define SCALEBITS 16 /* speediest right-shift on some machines */
+#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
+#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
+
+
+/*
+ * Initialize tables for YCC->RGB colorspace conversion.
+ */
+
+LOCAL(void)
+build_ycc_rgb_table (j_decompress_ptr cinfo)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ int i;
+ INT32 x;
+ SHIFT_TEMPS
+
+ cconvert->Cr_r_tab = (int *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(int));
+ cconvert->Cb_b_tab = (int *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(int));
+ cconvert->Cr_g_tab = (INT32 *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
+ cconvert->Cb_g_tab = (INT32 *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
+
+ for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
+ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
+ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
+ /* Cr=>R value is nearest int to 1.40200 * x */
+ cconvert->Cr_r_tab[i] = (int)
+ RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
+ /* Cb=>B value is nearest int to 1.77200 * x */
+ cconvert->Cb_b_tab[i] = (int)
+ RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
+ /* Cr=>G value is scaled-up -0.71414 * x */
+ cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
+ /* Cb=>G value is scaled-up -0.34414 * x */
+ /* We also add in ONE_HALF so that need not do it in inner loop */
+ cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
+ }
+}
+
+
+/*
+ * Convert some rows of samples to the output colorspace.
+ *
+ * Note that we change from noninterleaved, one-plane-per-component format
+ * to interleaved-pixel format. The output buffer is therefore three times
+ * as wide as the input buffer.
+ * A starting row offset is provided only for the input buffer. The caller
+ * can easily adjust the passed output_buf value to accommodate any row
+ * offset required on that side.
+ */
+
+METHODDEF(void)
+ycc_rgb_convert (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ register int y, cb, cr;
+ register JSAMPROW outptr;
+ register JSAMPROW inptr0, inptr1, inptr2;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->output_width;
+ /* copy these pointers into registers if possible */
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
+ register int * Crrtab = cconvert->Cr_r_tab;
+ register int * Cbbtab = cconvert->Cb_b_tab;
+ register INT32 * Crgtab = cconvert->Cr_g_tab;
+ register INT32 * Cbgtab = cconvert->Cb_g_tab;
+ SHIFT_TEMPS
+
+ while (--num_rows >= 0) {
+ inptr0 = input_buf[0][input_row];
+ inptr1 = input_buf[1][input_row];
+ inptr2 = input_buf[2][input_row];
+ input_row++;
+ outptr = *output_buf++;
+ for (col = 0; col < num_cols; col++) {
+ y = GETJSAMPLE(inptr0[col]);
+ cb = GETJSAMPLE(inptr1[col]);
+ cr = GETJSAMPLE(inptr2[col]);
+ /* Range-limiting is essential due to noise introduced by DCT losses. */
+ outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
+ outptr[RGB_GREEN] = range_limit[y +
+ ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
+ SCALEBITS))];
+ outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
+ outptr += RGB_PIXELSIZE;
+ }
+ }
+}
+
+
+/**************** Cases other than YCbCr -> RGB **************/
+
+
+/*
+ * Color conversion for no colorspace change: just copy the data,
+ * converting from separate-planes to interleaved representation.
+ */
+
+METHODDEF(void)
+null_convert (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION count;
+ register int num_components = cinfo->num_components;
+ JDIMENSION num_cols = cinfo->output_width;
+ int ci;
+
+ while (--num_rows >= 0) {
+ for (ci = 0; ci < num_components; ci++) {
+ inptr = input_buf[ci][input_row];
+ outptr = output_buf[0] + ci;
+ for (count = num_cols; count > 0; count--) {
+ *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
+ outptr += num_components;
+ }
+ }
+ input_row++;
+ output_buf++;
+ }
+}
+
+
+/*
+ * Color conversion for grayscale: just copy the data.
+ * This also works for YCbCr -> grayscale conversion, in which
+ * we just copy the Y (luminance) component and ignore chrominance.
+ */
+
+METHODDEF(void)
+grayscale_convert (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
+ num_rows, cinfo->output_width);
+}
+
+
+/*
+ * Convert grayscale to RGB: just duplicate the graylevel three times.
+ * This is provided to support applications that don't want to cope
+ * with grayscale as a separate case.
+ */
+
+METHODDEF(void)
+gray_rgb_convert (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->output_width;
+
+ while (--num_rows >= 0) {
+ inptr = input_buf[0][input_row++];
+ outptr = *output_buf++;
+ for (col = 0; col < num_cols; col++) {
+ /* We can dispense with GETJSAMPLE() here */
+ outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
+ outptr += RGB_PIXELSIZE;
+ }
+ }
+}
+
+
+/*
+ * Adobe-style YCCK->CMYK conversion.
+ * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
+ * conversion as above, while passing K (black) unchanged.
+ * We assume build_ycc_rgb_table has been called.
+ */
+
+METHODDEF(void)
+ycck_cmyk_convert (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+ register int y, cb, cr;
+ register JSAMPROW outptr;
+ register JSAMPROW inptr0, inptr1, inptr2, inptr3;
+ register JDIMENSION col;
+ JDIMENSION num_cols = cinfo->output_width;
+ /* copy these pointers into registers if possible */
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
+ register int * Crrtab = cconvert->Cr_r_tab;
+ register int * Cbbtab = cconvert->Cb_b_tab;
+ register INT32 * Crgtab = cconvert->Cr_g_tab;
+ register INT32 * Cbgtab = cconvert->Cb_g_tab;
+ SHIFT_TEMPS
+
+ while (--num_rows >= 0) {
+ inptr0 = input_buf[0][input_row];
+ inptr1 = input_buf[1][input_row];
+ inptr2 = input_buf[2][input_row];
+ inptr3 = input_buf[3][input_row];
+ input_row++;
+ outptr = *output_buf++;
+ for (col = 0; col < num_cols; col++) {
+ y = GETJSAMPLE(inptr0[col]);
+ cb = GETJSAMPLE(inptr1[col]);
+ cr = GETJSAMPLE(inptr2[col]);
+ /* Range-limiting is essential due to noise introduced by DCT losses. */
+ outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
+ outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
+ ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
+ SCALEBITS)))];
+ outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
+ /* K passes through unchanged */
+ outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
+ outptr += 4;
+ }
+ }
+}
+
+
+/*
+ * Empty method for start_pass.
+ */
+
+METHODDEF(void)
+start_pass_dcolor (j_decompress_ptr cinfo)
+{
+ /* no work needed */
+}
+
+
+/*
+ * Module initialization routine for output colorspace conversion.
+ */
+
+GLOBAL(void)
+jinit_color_deconverter (j_decompress_ptr cinfo)
+{
+ my_cconvert_ptr cconvert;
+ int ci;
+
+ cconvert = (my_cconvert_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_color_deconverter));
+ cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
+ cconvert->pub.start_pass = start_pass_dcolor;
+
+ /* Make sure num_components agrees with jpeg_color_space */
+ switch (cinfo->jpeg_color_space) {
+ case JCS_GRAYSCALE:
+ if (cinfo->num_components != 1)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ break;
+
+ case JCS_RGB:
+ case JCS_YCbCr:
+ if (cinfo->num_components != 3)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ break;
+
+ case JCS_CMYK:
+ case JCS_YCCK:
+ if (cinfo->num_components != 4)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ break;
+
+ default: /* JCS_UNKNOWN can be anything */
+ if (cinfo->num_components < 1)
+ ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
+ break;
+ }
+
+ /* Set out_color_components and conversion method based on requested space.
+ * Also clear the component_needed flags for any unused components,
+ * so that earlier pipeline stages can avoid useless computation.
+ */
+
+ switch (cinfo->out_color_space) {
+ case JCS_GRAYSCALE:
+ cinfo->out_color_components = 1;
+ if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
+ cinfo->jpeg_color_space == JCS_YCbCr) {
+ cconvert->pub.color_convert = grayscale_convert;
+ /* For color->grayscale conversion, only the Y (0) component is needed */
+ for (ci = 1; ci < cinfo->num_components; ci++)
+ cinfo->comp_info[ci].component_needed = FALSE;
+ } else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_RGB:
+ cinfo->out_color_components = RGB_PIXELSIZE;
+ if (cinfo->jpeg_color_space == JCS_YCbCr) {
+ cconvert->pub.color_convert = ycc_rgb_convert;
+ build_ycc_rgb_table(cinfo);
+ } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
+ cconvert->pub.color_convert = gray_rgb_convert;
+ } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
+ cconvert->pub.color_convert = null_convert;
+ } else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ case JCS_CMYK:
+ cinfo->out_color_components = 4;
+ if (cinfo->jpeg_color_space == JCS_YCCK) {
+ cconvert->pub.color_convert = ycck_cmyk_convert;
+ build_ycc_rgb_table(cinfo);
+ } else if (cinfo->jpeg_color_space == JCS_CMYK) {
+ cconvert->pub.color_convert = null_convert;
+ } else
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+
+ default:
+ /* Permit null conversion to same output space */
+ if (cinfo->out_color_space == cinfo->jpeg_color_space) {
+ cinfo->out_color_components = cinfo->num_components;
+ cconvert->pub.color_convert = null_convert;
+ } else /* unsupported non-null conversion */
+ ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+ break;
+ }
+
+ if (cinfo->quantize_colors)
+ cinfo->output_components = 1; /* single colormapped output component */
+ else
+ cinfo->output_components = cinfo->out_color_components;
+}
diff --git a/osframework/source/ImageLib/jpeg/jdct.h b/osframework/source/ImageLib/jpeg/jdct.h
new file mode 100644
index 0000000..b664cab
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdct.h
@@ -0,0 +1,176 @@
+/*
+ * jdct.h
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This include file contains common declarations for the forward and
+ * inverse DCT modules. These declarations are private to the DCT managers
+ * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
+ * The individual DCT algorithms are kept in separate files to ease
+ * machine-dependent tuning (e.g., assembly coding).
+ */
+
+
+/*
+ * A forward DCT routine is given a pointer to a work area of type DCTELEM[];
+ * the DCT is to be performed in-place in that buffer. Type DCTELEM is int
+ * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
+ * implementations use an array of type FAST_FLOAT, instead.)
+ * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
+ * The DCT outputs are returned scaled up by a factor of 8; they therefore
+ * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
+ * convention improves accuracy in integer implementations and saves some
+ * work in floating-point ones.
+ * Quantization of the output coefficients is done by jcdctmgr.c.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+typedef int DCTELEM; /* 16 or 32 bits is fine */
+#else
+typedef INT32 DCTELEM; /* must have 32 bits */
+#endif
+
+typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
+typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
+
+
+/*
+ * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
+ * to an output sample array. The routine must dequantize the input data as
+ * well as perform the IDCT; for dequantization, it uses the multiplier table
+ * pointed to by compptr->dct_table. The output data is to be placed into the
+ * sample array starting at a specified column. (Any row offset needed will
+ * be applied to the array pointer before it is passed to the IDCT code.)
+ * Note that the number of samples emitted by the IDCT routine is
+ * DCT_scaled_size * DCT_scaled_size.
+ */
+
+/* typedef inverse_DCT_method_ptr is declared in jpegint.h */
+
+/*
+ * Each IDCT routine has its own ideas about the best dct_table element type.
+ */
+
+typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
+#if BITS_IN_JSAMPLE == 8
+typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
+#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
+#else
+typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
+#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
+#endif
+typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
+
+
+/*
+ * Each IDCT routine is responsible for range-limiting its results and
+ * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
+ * be quite far out of range if the input data is corrupt, so a bulletproof
+ * range-limiting step is required. We use a mask-and-table-lookup method
+ * to do the combined operations quickly. See the comments with
+ * prepare_range_limit_table (in jdmaster.c) for more info.
+ */
+
+#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
+
+#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
+
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_fdct_islow jFDislow
+#define jpeg_fdct_ifast jFDifast
+#define jpeg_fdct_float jFDfloat
+#define jpeg_idct_islow jRDislow
+#define jpeg_idct_ifast jRDifast
+#define jpeg_idct_float jRDfloat
+#define jpeg_idct_4x4 jRD4x4
+#define jpeg_idct_2x2 jRD2x2
+#define jpeg_idct_1x1 jRD1x1
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+/* Extern declarations for the forward and inverse DCT routines. */
+
+EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
+EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
+EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
+
+EXTERN(void) jpeg_idct_islow
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+EXTERN(void) jpeg_idct_ifast
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+EXTERN(void) jpeg_idct_float
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+EXTERN(void) jpeg_idct_4x4
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+EXTERN(void) jpeg_idct_2x2
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+EXTERN(void) jpeg_idct_1x1
+ JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
+
+
+/*
+ * Macros for handling fixed-point arithmetic; these are used by many
+ * but not all of the DCT/IDCT modules.
+ *
+ * All values are expected to be of type INT32.
+ * Fractional constants are scaled left by CONST_BITS bits.
+ * CONST_BITS is defined within each module using these macros,
+ * and may differ from one module to the next.
+ */
+
+#define ONE ((INT32) 1)
+#define CONST_SCALE (ONE << CONST_BITS)
+
+/* Convert a positive real constant to an integer scaled by CONST_SCALE.
+ * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
+ * thus causing a lot of useless floating-point operations at run time.
+ */
+
+#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
+
+/* Descale and correctly round an INT32 value that's scaled by N bits.
+ * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
+ * the fudge factor is correct for either sign of X.
+ */
+
+#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
+
+/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
+ * This macro is used only when the two inputs will actually be no more than
+ * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
+ * full 32x32 multiply. This provides a useful speedup on many machines.
+ * Unfortunately there is no way to specify a 16x16->32 multiply portably
+ * in C, but some C compilers will do the right thing if you provide the
+ * correct combination of casts.
+ */
+
+#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
+#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
+#endif
+#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
+#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
+#endif
+
+#ifndef MULTIPLY16C16 /* default definition */
+#define MULTIPLY16C16(var,const) ((var) * (const))
+#endif
+
+/* Same except both inputs are variables. */
+
+#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
+#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
+#endif
+
+#ifndef MULTIPLY16V16 /* default definition */
+#define MULTIPLY16V16(var1,var2) ((var1) * (var2))
+#endif
diff --git a/osframework/source/ImageLib/jpeg/jddctmgr.c b/osframework/source/ImageLib/jpeg/jddctmgr.c
new file mode 100644
index 0000000..0e44eb1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jddctmgr.c
@@ -0,0 +1,269 @@
+/*
+ * jddctmgr.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the inverse-DCT management logic.
+ * This code selects a particular IDCT implementation to be used,
+ * and it performs related housekeeping chores. No code in this file
+ * is executed per IDCT step, only during output pass setup.
+ *
+ * Note that the IDCT routines are responsible for performing coefficient
+ * dequantization as well as the IDCT proper. This module sets up the
+ * dequantization multiplier table needed by the IDCT routine.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+
+/*
+ * The decompressor input side (jdinput.c) saves away the appropriate
+ * quantization table for each component at the start of the first scan
+ * involving that component. (This is necessary in order to correctly
+ * decode files that reuse Q-table slots.)
+ * When we are ready to make an output pass, the saved Q-table is converted
+ * to a multiplier table that will actually be used by the IDCT routine.
+ * The multiplier table contents are IDCT-method-dependent. To support
+ * application changes in IDCT method between scans, we can remake the
+ * multiplier tables if necessary.
+ * In buffered-image mode, the first output pass may occur before any data
+ * has been seen for some components, and thus before their Q-tables have
+ * been saved away. To handle this case, multiplier tables are preset
+ * to zeroes; the result of the IDCT will be a neutral gray level.
+ */
+
+
+/* Private subobject for this module */
+
+typedef struct {
+ struct jpeg_inverse_dct pub; /* public fields */
+
+ /* This array contains the IDCT method code that each multiplier table
+ * is currently set up for, or -1 if it's not yet set up.
+ * The actual multiplier tables are pointed to by dct_table in the
+ * per-component comp_info structures.
+ */
+ int cur_method[MAX_COMPONENTS];
+} my_idct_controller;
+
+typedef my_idct_controller * my_idct_ptr;
+
+
+/* Allocated multiplier tables: big enough for any supported variant */
+
+typedef union {
+ ISLOW_MULT_TYPE islow_array[DCTSIZE2];
+#ifdef DCT_IFAST_SUPPORTED
+ IFAST_MULT_TYPE ifast_array[DCTSIZE2];
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ FLOAT_MULT_TYPE float_array[DCTSIZE2];
+#endif
+} multiplier_table;
+
+
+/* The current scaled-IDCT routines require ISLOW-style multiplier tables,
+ * so be sure to compile that code if either ISLOW or SCALING is requested.
+ */
+#ifdef DCT_ISLOW_SUPPORTED
+#define PROVIDE_ISLOW_TABLES
+#else
+#ifdef IDCT_SCALING_SUPPORTED
+#define PROVIDE_ISLOW_TABLES
+#endif
+#endif
+
+
+/*
+ * Prepare for an output pass.
+ * Here we select the proper IDCT routine for each component and build
+ * a matching multiplier table.
+ */
+
+METHODDEF(void)
+start_pass (j_decompress_ptr cinfo)
+{
+ my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
+ int ci, i;
+ jpeg_component_info *compptr;
+ int method = 0;
+ inverse_DCT_method_ptr method_ptr = NULL;
+ JQUANT_TBL * qtbl;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Select the proper IDCT routine for this component's scaling */
+ switch (compptr->DCT_scaled_size) {
+#ifdef IDCT_SCALING_SUPPORTED
+ case 1:
+ method_ptr = jpeg_idct_1x1;
+ method = JDCT_ISLOW; /* jidctred uses islow-style table */
+ break;
+ case 2:
+ method_ptr = jpeg_idct_2x2;
+ method = JDCT_ISLOW; /* jidctred uses islow-style table */
+ break;
+ case 4:
+ method_ptr = jpeg_idct_4x4;
+ method = JDCT_ISLOW; /* jidctred uses islow-style table */
+ break;
+#endif
+ case DCTSIZE:
+ switch (cinfo->dct_method) {
+#ifdef DCT_ISLOW_SUPPORTED
+ case JDCT_ISLOW:
+ method_ptr = jpeg_idct_islow;
+ method = JDCT_ISLOW;
+ break;
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ case JDCT_IFAST:
+ method_ptr = jpeg_idct_ifast;
+ method = JDCT_IFAST;
+ break;
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ case JDCT_FLOAT:
+ method_ptr = jpeg_idct_float;
+ method = JDCT_FLOAT;
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ break;
+ }
+ break;
+ default:
+ ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
+ break;
+ }
+ idct->pub.inverse_DCT[ci] = method_ptr;
+ /* Create multiplier table from quant table.
+ * However, we can skip this if the component is uninteresting
+ * or if we already built the table. Also, if no quant table
+ * has yet been saved for the component, we leave the
+ * multiplier table all-zero; we'll be reading zeroes from the
+ * coefficient controller's buffer anyway.
+ */
+ if (! compptr->component_needed || idct->cur_method[ci] == method)
+ continue;
+ qtbl = compptr->quant_table;
+ if (qtbl == NULL) /* happens if no data yet for component */
+ continue;
+ idct->cur_method[ci] = method;
+ switch (method) {
+#ifdef PROVIDE_ISLOW_TABLES
+ case JDCT_ISLOW:
+ {
+ /* For LL&M IDCT method, multipliers are equal to raw quantization
+ * coefficients, but are stored as ints to ensure access efficiency.
+ */
+ ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
+ for (i = 0; i < DCTSIZE2; i++) {
+ ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
+ }
+ }
+ break;
+#endif
+#ifdef DCT_IFAST_SUPPORTED
+ case JDCT_IFAST:
+ {
+ /* For AA&N IDCT method, multipliers are equal to quantization
+ * coefficients scaled by scalefactor[row]*scalefactor[col], where
+ * scalefactor[0] = 1
+ * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
+ * For integer operation, the multiplier table is to be scaled by
+ * IFAST_SCALE_BITS.
+ */
+ IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
+#define CONST_BITS 14
+ static const INT16 aanscales[DCTSIZE2] = {
+ /* precomputed values scaled up by 14 bits */
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+ 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+ 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+ 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+ 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
+ };
+ SHIFT_TEMPS
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ ifmtbl[i] = (IFAST_MULT_TYPE)
+ DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
+ (INT32) aanscales[i]),
+ CONST_BITS-IFAST_SCALE_BITS);
+ }
+ }
+ break;
+#endif
+#ifdef DCT_FLOAT_SUPPORTED
+ case JDCT_FLOAT:
+ {
+ /* For float AA&N IDCT method, multipliers are equal to quantization
+ * coefficients scaled by scalefactor[row]*scalefactor[col], where
+ * scalefactor[0] = 1
+ * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
+ */
+ FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
+ int row, col;
+ static const double aanscalefactor[DCTSIZE] = {
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ };
+
+ i = 0;
+ for (row = 0; row < DCTSIZE; row++) {
+ for (col = 0; col < DCTSIZE; col++) {
+ fmtbl[i] = (FLOAT_MULT_TYPE)
+ ((double) qtbl->quantval[i] *
+ aanscalefactor[row] * aanscalefactor[col]);
+ i++;
+ }
+ }
+ }
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ break;
+ }
+ }
+}
+
+
+/*
+ * Initialize IDCT manager.
+ */
+
+GLOBAL(void)
+jinit_inverse_dct (j_decompress_ptr cinfo)
+{
+ my_idct_ptr idct;
+ int ci;
+ jpeg_component_info *compptr;
+
+ idct = (my_idct_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_idct_controller));
+ cinfo->idct = (struct jpeg_inverse_dct *) idct;
+ idct->pub.start_pass = start_pass;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Allocate and pre-zero a multiplier table for each component */
+ compptr->dct_table =
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(multiplier_table));
+ MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
+ /* Mark multiplier table not yet set up for any method */
+ idct->cur_method[ci] = -1;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdhuff.c b/osframework/source/ImageLib/jpeg/jdhuff.c
new file mode 100644
index 0000000..b2ad66d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdhuff.c
@@ -0,0 +1,651 @@
+/*
+ * jdhuff.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains Huffman entropy decoding routines.
+ *
+ * Much of the complexity here has to do with supporting input suspension.
+ * If the data source module demands suspension, we want to be able to back
+ * up to the start of the current MCU. To do this, we copy state variables
+ * into local working storage, and update them back to the permanent
+ * storage only upon successful completion of an MCU.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdhuff.h" /* Declarations shared with jdphuff.c */
+
+
+/*
+ * Expanded entropy decoder object for Huffman decoding.
+ *
+ * The savable_state subrecord contains fields that change within an MCU,
+ * but must not be updated permanently until we complete the MCU.
+ */
+
+typedef struct {
+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
+} savable_state;
+
+/* This macro is to work around compilers with missing or broken
+ * structure assignment. You'll need to fix this code if you have
+ * such a compiler and you change MAX_COMPS_IN_SCAN.
+ */
+
+#ifndef NO_STRUCT_ASSIGN
+#define ASSIGN_STATE(dest,src) ((dest) = (src))
+#else
+#if MAX_COMPS_IN_SCAN == 4
+#define ASSIGN_STATE(dest,src) \
+ ((dest).last_dc_val[0] = (src).last_dc_val[0], \
+ (dest).last_dc_val[1] = (src).last_dc_val[1], \
+ (dest).last_dc_val[2] = (src).last_dc_val[2], \
+ (dest).last_dc_val[3] = (src).last_dc_val[3])
+#endif
+#endif
+
+
+typedef struct {
+ struct jpeg_entropy_decoder pub; /* public fields */
+
+ /* These fields are loaded into local variables at start of each MCU.
+ * In case of suspension, we exit WITHOUT updating them.
+ */
+ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
+ savable_state saved; /* Other state at start of MCU */
+
+ /* These fields are NOT loaded into local working state. */
+ unsigned int restarts_to_go; /* MCUs left in this restart interval */
+
+ /* Pointers to derived tables (these workspaces have image lifespan) */
+ d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
+ d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
+
+ /* Precalculated info set up by start_pass for use in decode_mcu: */
+
+ /* Pointers to derived tables to be used for each block within an MCU */
+ d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
+ d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
+ /* Whether we care about the DC and AC coefficient values for each block */
+ boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
+ boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
+} huff_entropy_decoder;
+
+typedef huff_entropy_decoder * huff_entropy_ptr;
+
+
+/*
+ * Initialize for a Huffman-compressed scan.
+ */
+
+METHODDEF(void)
+start_pass_huff_decoder (j_decompress_ptr cinfo)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int ci, blkn, dctbl, actbl;
+ jpeg_component_info * compptr;
+
+ /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
+ * This ought to be an error condition, but we make it a warning because
+ * there are some baseline files out there with all zeroes in these bytes.
+ */
+ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
+ cinfo->Ah != 0 || cinfo->Al != 0)
+ WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ dctbl = compptr->dc_tbl_no;
+ actbl = compptr->ac_tbl_no;
+ /* Compute derived values for Huffman tables */
+ /* We may do this more than once for a table, but it's not expensive */
+ jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
+ & entropy->dc_derived_tbls[dctbl]);
+ jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
+ & entropy->ac_derived_tbls[actbl]);
+ /* Initialize DC predictions to 0 */
+ entropy->saved.last_dc_val[ci] = 0;
+ }
+
+ /* Precalculate decoding info for each block in an MCU of this scan */
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ ci = cinfo->MCU_membership[blkn];
+ compptr = cinfo->cur_comp_info[ci];
+ /* Precalculate which table to use for each block */
+ entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
+ entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
+ /* Decide whether we really care about the coefficient values */
+ if (compptr->component_needed) {
+ entropy->dc_needed[blkn] = TRUE;
+ /* we don't need the ACs if producing a 1/8th-size image */
+ entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
+ } else {
+ entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
+ }
+ }
+
+ /* Initialize bitread state variables */
+ entropy->bitstate.bits_left = 0;
+ entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
+ entropy->pub.insufficient_data = FALSE;
+
+ /* Initialize restart counter */
+ entropy->restarts_to_go = cinfo->restart_interval;
+}
+
+
+/*
+ * Compute the derived values for a Huffman table.
+ * This routine also performs some validation checks on the table.
+ *
+ * Note this is also used by jdphuff.c.
+ */
+
+GLOBAL(void)
+jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
+ d_derived_tbl ** pdtbl)
+{
+ JHUFF_TBL *htbl;
+ d_derived_tbl *dtbl;
+ int p, i, l, si, numsymbols;
+ int lookbits, ctr;
+ char huffsize[257];
+ unsigned int huffcode[257];
+ unsigned int code;
+
+ /* Note that huffsize[] and huffcode[] are filled in code-length order,
+ * paralleling the order of the symbols themselves in htbl->huffval[].
+ */
+
+ /* Find the input Huffman table */
+ if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
+ htbl =
+ isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
+ if (htbl == NULL)
+ ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
+
+ /* Allocate a workspace if we haven't already done so. */
+ if (*pdtbl == NULL)
+ *pdtbl = (d_derived_tbl *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(d_derived_tbl));
+ dtbl = *pdtbl;
+ dtbl->pub = htbl; /* fill in back link */
+
+ /* Figure C.1: make table of Huffman code length for each symbol */
+
+ p = 0;
+ for (l = 1; l <= 16; l++) {
+ i = (int) htbl->bits[l];
+ if (i < 0 || p + i > 256) /* protect against table overrun */
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ while (i--)
+ huffsize[p++] = (char) l;
+ }
+ huffsize[p] = 0;
+ numsymbols = p;
+
+ /* Figure C.2: generate the codes themselves */
+ /* We also validate that the counts represent a legal Huffman code tree. */
+
+ code = 0;
+ si = huffsize[0];
+ p = 0;
+ while (huffsize[p]) {
+ while (((int) huffsize[p]) == si) {
+ huffcode[p++] = code;
+ code++;
+ }
+ /* code is now 1 more than the last code used for codelength si; but
+ * it must still fit in si bits, since no code is allowed to be all ones.
+ */
+ if (((INT32) code) >= (((INT32) 1) << si))
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ code <<= 1;
+ si++;
+ }
+
+ /* Figure F.15: generate decoding tables for bit-sequential decoding */
+
+ p = 0;
+ for (l = 1; l <= 16; l++) {
+ if (htbl->bits[l]) {
+ /* valoffset[l] = huffval[] index of 1st symbol of code length l,
+ * minus the minimum code of length l
+ */
+ dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
+ p += htbl->bits[l];
+ dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
+ } else {
+ dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
+ }
+ }
+ dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
+
+ /* Compute lookahead tables to speed up decoding.
+ * First we set all the table entries to 0, indicating "too long";
+ * then we iterate through the Huffman codes that are short enough and
+ * fill in all the entries that correspond to bit sequences starting
+ * with that code.
+ */
+
+ MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
+
+ p = 0;
+ for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
+ for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
+ /* l = current code's length, p = its index in huffcode[] & huffval[]. */
+ /* Generate left-justified code followed by all possible bit sequences */
+ lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
+ for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
+ dtbl->look_nbits[lookbits] = l;
+ dtbl->look_sym[lookbits] = htbl->huffval[p];
+ lookbits++;
+ }
+ }
+ }
+
+ /* Validate symbols as being reasonable.
+ * For AC tables, we make no check, but accept all byte values 0..255.
+ * For DC tables, we require the symbols to be in range 0..15.
+ * (Tighter bounds could be applied depending on the data depth and mode,
+ * but this is sufficient to ensure safe decoding.)
+ */
+ if (isDC) {
+ for (i = 0; i < numsymbols; i++) {
+ int sym = htbl->huffval[i];
+ if (sym < 0 || sym > 15)
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+ }
+ }
+}
+
+
+/*
+ * Out-of-line code for bit fetching (shared with jdphuff.c).
+ * See jdhuff.h for info about usage.
+ * Note: current values of get_buffer and bits_left are passed as parameters,
+ * but are returned in the corresponding fields of the state struct.
+ *
+ * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width
+ * of get_buffer to be used. (On machines with wider words, an even larger
+ * buffer could be used.) However, on some machines 32-bit shifts are
+ * quite slow and take time proportional to the number of places shifted.
+ * (This is true with most PC compilers, for instance.) In this case it may
+ * be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the
+ * average shift distance at the cost of more calls to jpeg_fill_bit_buffer.
+ */
+
+#ifdef SLOW_SHIFT_32
+#define MIN_GET_BITS 15 /* minimum allowable value */
+#else
+#define MIN_GET_BITS (BIT_BUF_SIZE-7)
+#endif
+
+
+GLOBAL(boolean)
+jpeg_fill_bit_buffer (bitread_working_state * state,
+ register bit_buf_type get_buffer, register int bits_left,
+ int nbits)
+/* Load up the bit buffer to a depth of at least nbits */
+{
+ /* Copy heavily used state fields into locals (hopefully registers) */
+ register const JOCTET * next_input_byte = state->next_input_byte;
+ register size_t bytes_in_buffer = state->bytes_in_buffer;
+ j_decompress_ptr cinfo = state->cinfo;
+
+ /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
+ /* (It is assumed that no request will be for more than that many bits.) */
+ /* We fail to do so only if we hit a marker or are forced to suspend. */
+
+ if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
+ while (bits_left < MIN_GET_BITS) {
+ register int c;
+
+ /* Attempt to read a byte */
+ if (bytes_in_buffer == 0) {
+ if (! (*cinfo->src->fill_input_buffer) (cinfo))
+ return FALSE;
+ next_input_byte = cinfo->src->next_input_byte;
+ bytes_in_buffer = cinfo->src->bytes_in_buffer;
+ }
+ bytes_in_buffer--;
+ c = GETJOCTET(*next_input_byte++);
+
+ /* If it's 0xFF, check and discard stuffed zero byte */
+ if (c == 0xFF) {
+ /* Loop here to discard any padding FF's on terminating marker,
+ * so that we can save a valid unread_marker value. NOTE: we will
+ * accept multiple FF's followed by a 0 as meaning a single FF data
+ * byte. This data pattern is not valid according to the standard.
+ */
+ do {
+ if (bytes_in_buffer == 0) {
+ if (! (*cinfo->src->fill_input_buffer) (cinfo))
+ return FALSE;
+ next_input_byte = cinfo->src->next_input_byte;
+ bytes_in_buffer = cinfo->src->bytes_in_buffer;
+ }
+ bytes_in_buffer--;
+ c = GETJOCTET(*next_input_byte++);
+ } while (c == 0xFF);
+
+ if (c == 0) {
+ /* Found FF/00, which represents an FF data byte */
+ c = 0xFF;
+ } else {
+ /* Oops, it's actually a marker indicating end of compressed data.
+ * Save the marker code for later use.
+ * Fine point: it might appear that we should save the marker into
+ * bitread working state, not straight into permanent state. But
+ * once we have hit a marker, we cannot need to suspend within the
+ * current MCU, because we will read no more bytes from the data
+ * source. So it is OK to update permanent state right away.
+ */
+ cinfo->unread_marker = c;
+ /* See if we need to insert some fake zero bits. */
+ goto no_more_bytes;
+ }
+ }
+
+ /* OK, load c into get_buffer */
+ get_buffer = (get_buffer << 8) | c;
+ bits_left += 8;
+ } /* end while */
+ } else {
+ no_more_bytes:
+ /* We get here if we've read the marker that terminates the compressed
+ * data segment. There should be enough bits in the buffer register
+ * to satisfy the request; if so, no problem.
+ */
+ if (nbits > bits_left) {
+ /* Uh-oh. Report corrupted data to user and stuff zeroes into
+ * the data stream, so that we can produce some kind of image.
+ * We use a nonvolatile flag to ensure that only one warning message
+ * appears per data segment.
+ */
+ if (! cinfo->entropy->insufficient_data) {
+ WARNMS(cinfo, JWRN_HIT_MARKER);
+ cinfo->entropy->insufficient_data = TRUE;
+ }
+ /* Fill the buffer with zero bits */
+ get_buffer <<= MIN_GET_BITS - bits_left;
+ bits_left = MIN_GET_BITS;
+ }
+ }
+
+ /* Unload the local registers */
+ state->next_input_byte = next_input_byte;
+ state->bytes_in_buffer = bytes_in_buffer;
+ state->get_buffer = get_buffer;
+ state->bits_left = bits_left;
+
+ return TRUE;
+}
+
+
+/*
+ * Out-of-line code for Huffman code decoding.
+ * See jdhuff.h for info about usage.
+ */
+
+GLOBAL(int)
+jpeg_huff_decode (bitread_working_state * state,
+ register bit_buf_type get_buffer, register int bits_left,
+ d_derived_tbl * htbl, int min_bits)
+{
+ register int l = min_bits;
+ register INT32 code;
+
+ /* HUFF_DECODE has determined that the code is at least min_bits */
+ /* bits long, so fetch that many bits in one swoop. */
+
+ CHECK_BIT_BUFFER(*state, l, return -1);
+ code = GET_BITS(l);
+
+ /* Collect the rest of the Huffman code one bit at a time. */
+ /* This is per Figure F.16 in the JPEG spec. */
+
+ while (code > htbl->maxcode[l]) {
+ code <<= 1;
+ CHECK_BIT_BUFFER(*state, 1, return -1);
+ code |= GET_BITS(1);
+ l++;
+ }
+
+ /* Unload the local registers */
+ state->get_buffer = get_buffer;
+ state->bits_left = bits_left;
+
+ /* With garbage input we may reach the sentinel value l = 17. */
+
+ if (l > 16) {
+ WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
+ return 0; /* fake a zero as the safest result */
+ }
+
+ return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
+}
+
+
+/*
+ * Figure F.12: extend sign bit.
+ * On some machines, a shift and add will be faster than a table lookup.
+ */
+
+#ifdef AVOID_TABLES
+
+#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
+
+#else
+
+#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
+
+static const int extend_test[16] = /* entry n is 2**(n-1) */
+ { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
+ 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
+
+static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
+ { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
+ ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
+ ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
+ ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
+
+#endif /* AVOID_TABLES */
+
+
+/*
+ * Check for a restart marker & resynchronize decoder.
+ * Returns FALSE if must suspend.
+ */
+
+LOCAL(boolean)
+process_restart (j_decompress_ptr cinfo)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int ci;
+
+ /* Throw away any unused bits remaining in bit buffer; */
+ /* include any full bytes in next_marker's count of discarded bytes */
+ cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
+ entropy->bitstate.bits_left = 0;
+
+ /* Advance past the RSTn marker */
+ if (! (*cinfo->marker->read_restart_marker) (cinfo))
+ return FALSE;
+
+ /* Re-initialize DC predictions to 0 */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++)
+ entropy->saved.last_dc_val[ci] = 0;
+
+ /* Reset restart counter */
+ entropy->restarts_to_go = cinfo->restart_interval;
+
+ /* Reset out-of-data flag, unless read_restart_marker left us smack up
+ * against a marker. In that case we will end up treating the next data
+ * segment as empty, and we can avoid producing bogus output pixels by
+ * leaving the flag set.
+ */
+ if (cinfo->unread_marker == 0)
+ entropy->pub.insufficient_data = FALSE;
+
+ return TRUE;
+}
+
+
+/*
+ * Decode and return one MCU's worth of Huffman-compressed coefficients.
+ * The coefficients are reordered from zigzag order into natural array order,
+ * but are not dequantized.
+ *
+ * The i'th block of the MCU is stored into the block pointed to by
+ * MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER.
+ * (Wholesale zeroing is usually a little faster than retail...)
+ *
+ * Returns FALSE if data source requested suspension. In that case no
+ * changes have been made to permanent state. (Exception: some output
+ * coefficients may already have been assigned. This is harmless for
+ * this module, since we'll just re-assign them on the next call.)
+ */
+
+METHODDEF(boolean)
+decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
+ int blkn;
+ BITREAD_STATE_VARS;
+ savable_state state;
+
+ /* Process restart marker if needed; may have to suspend */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! process_restart(cinfo))
+ return FALSE;
+ }
+
+ /* If we've run out of data, just leave the MCU set to zeroes.
+ * This way, we return uniform gray for the remainder of the segment.
+ */
+ if (! entropy->pub.insufficient_data) {
+
+ /* Load up working state */
+ BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
+ ASSIGN_STATE(state, entropy->saved);
+
+ /* Outer loop handles each block in the MCU */
+
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ JBLOCKROW block = MCU_data[blkn];
+ d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
+ d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
+ register int s, k, r;
+
+ /* Decode a single block's worth of coefficients */
+
+ /* Section F.2.2.1: decode the DC coefficient difference */
+ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
+ if (s) {
+ CHECK_BIT_BUFFER(br_state, s, return FALSE);
+ r = GET_BITS(s);
+ s = HUFF_EXTEND(r, s);
+ }
+
+ if (entropy->dc_needed[blkn]) {
+ /* Convert DC difference to actual value, update last_dc_val */
+ int ci = cinfo->MCU_membership[blkn];
+ s += state.last_dc_val[ci];
+ state.last_dc_val[ci] = s;
+ /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
+ (*block)[0] = (JCOEF) s;
+ }
+
+ if (entropy->ac_needed[blkn]) {
+
+ /* Section F.2.2.2: decode the AC coefficients */
+ /* Since zeroes are skipped, output area must be cleared beforehand */
+ for (k = 1; k < DCTSIZE2; k++) {
+ HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
+
+ r = s >> 4;
+ s &= 15;
+
+ if (s) {
+ k += r;
+ CHECK_BIT_BUFFER(br_state, s, return FALSE);
+ r = GET_BITS(s);
+ s = HUFF_EXTEND(r, s);
+ /* Output coefficient in natural (dezigzagged) order.
+ * Note: the extra entries in jpeg_natural_order[] will save us
+ * if k >= DCTSIZE2, which could happen if the data is corrupted.
+ */
+ (*block)[jpeg_natural_order[k]] = (JCOEF) s;
+ } else {
+ if (r != 15)
+ break;
+ k += 15;
+ }
+ }
+
+ } else {
+
+ /* Section F.2.2.2: decode the AC coefficients */
+ /* In this path we just discard the values */
+ for (k = 1; k < DCTSIZE2; k++) {
+ HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
+
+ r = s >> 4;
+ s &= 15;
+
+ if (s) {
+ k += r;
+ CHECK_BIT_BUFFER(br_state, s, return FALSE);
+ DROP_BITS(s);
+ } else {
+ if (r != 15)
+ break;
+ k += 15;
+ }
+ }
+
+ }
+ }
+
+ /* Completed MCU, so update state */
+ BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
+ ASSIGN_STATE(entropy->saved, state);
+ }
+
+ /* Account for restart interval (no-op if not using restarts) */
+ entropy->restarts_to_go--;
+
+ return TRUE;
+}
+
+
+/*
+ * Module initialization routine for Huffman entropy decoding.
+ */
+
+GLOBAL(void)
+jinit_huff_decoder (j_decompress_ptr cinfo)
+{
+ huff_entropy_ptr entropy;
+ int i;
+
+ entropy = (huff_entropy_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(huff_entropy_decoder));
+ cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
+ entropy->pub.start_pass = start_pass_huff_decoder;
+ entropy->pub.decode_mcu = decode_mcu;
+
+ /* Mark tables unallocated */
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdhuff.h b/osframework/source/ImageLib/jpeg/jdhuff.h
new file mode 100644
index 0000000..12c0747
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdhuff.h
@@ -0,0 +1,201 @@
+/*
+ * jdhuff.h
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains declarations for Huffman entropy decoding routines
+ * that are shared between the sequential decoder (jdhuff.c) and the
+ * progressive decoder (jdphuff.c). No other modules need to see these.
+ */
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_make_d_derived_tbl jMkDDerived
+#define jpeg_fill_bit_buffer jFilBitBuf
+#define jpeg_huff_decode jHufDecode
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+
+/* Derived data constructed for each Huffman table */
+
+#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
+
+typedef struct {
+ /* Basic tables: (element [0] of each array is unused) */
+ INT32 maxcode[18]; /* largest code of length k (-1 if none) */
+ /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
+ INT32 valoffset[17]; /* huffval[] offset for codes of length k */
+ /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
+ * the smallest code of length k; so given a code of length k, the
+ * corresponding symbol is huffval[code + valoffset[k]]
+ */
+
+ /* Link to public Huffman table (needed only in jpeg_huff_decode) */
+ JHUFF_TBL *pub;
+
+ /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
+ * the input data stream. If the next Huffman code is no more
+ * than HUFF_LOOKAHEAD bits long, we can obtain its length and
+ * the corresponding symbol directly from these tables.
+ */
+ int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
+ UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
+} d_derived_tbl;
+
+/* Expand a Huffman table definition into the derived format */
+EXTERN(void) jpeg_make_d_derived_tbl
+ JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
+ d_derived_tbl ** pdtbl));
+
+
+/*
+ * Fetching the next N bits from the input stream is a time-critical operation
+ * for the Huffman decoders. We implement it with a combination of inline
+ * macros and out-of-line subroutines. Note that N (the number of bits
+ * demanded at one time) never exceeds 15 for JPEG use.
+ *
+ * We read source bytes into get_buffer and dole out bits as needed.
+ * If get_buffer already contains enough bits, they are fetched in-line
+ * by the macros CHECK_BIT_BUFFER and GET_BITS. When there aren't enough
+ * bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer
+ * as full as possible (not just to the number of bits needed; this
+ * prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer).
+ * Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension.
+ * On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains
+ * at least the requested number of bits --- dummy zeroes are inserted if
+ * necessary.
+ */
+
+typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
+#define BIT_BUF_SIZE 32 /* size of buffer in bits */
+
+/* If long is > 32 bits on your machine, and shifting/masking longs is
+ * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE
+ * appropriately should be a win. Unfortunately we can't define the size
+ * with something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)
+ * because not all machines measure sizeof in 8-bit bytes.
+ */
+
+typedef struct { /* Bitreading state saved across MCUs */
+ bit_buf_type get_buffer; /* current bit-extraction buffer */
+ int bits_left; /* # of unused bits in it */
+} bitread_perm_state;
+
+typedef struct { /* Bitreading working state within an MCU */
+ /* Current data source location */
+ /* We need a copy, rather than munging the original, in case of suspension */
+ const JOCTET * next_input_byte; /* => next byte to read from source */
+ size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
+ /* Bit input buffer --- note these values are kept in register variables,
+ * not in this struct, inside the inner loops.
+ */
+ bit_buf_type get_buffer; /* current bit-extraction buffer */
+ int bits_left; /* # of unused bits in it */
+ /* Pointer needed by jpeg_fill_bit_buffer. */
+ j_decompress_ptr cinfo; /* back link to decompress master record */
+} bitread_working_state;
+
+/* Macros to declare and load/save bitread local variables. */
+#define BITREAD_STATE_VARS \
+ register bit_buf_type get_buffer; \
+ register int bits_left; \
+ bitread_working_state br_state
+
+#define BITREAD_LOAD_STATE(cinfop,permstate) \
+ br_state.cinfo = cinfop; \
+ br_state.next_input_byte = cinfop->src->next_input_byte; \
+ br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
+ get_buffer = permstate.get_buffer; \
+ bits_left = permstate.bits_left;
+
+#define BITREAD_SAVE_STATE(cinfop,permstate) \
+ cinfop->src->next_input_byte = br_state.next_input_byte; \
+ cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
+ permstate.get_buffer = get_buffer; \
+ permstate.bits_left = bits_left
+
+/*
+ * These macros provide the in-line portion of bit fetching.
+ * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer
+ * before using GET_BITS, PEEK_BITS, or DROP_BITS.
+ * The variables get_buffer and bits_left are assumed to be locals,
+ * but the state struct might not be (jpeg_huff_decode needs this).
+ * CHECK_BIT_BUFFER(state,n,action);
+ * Ensure there are N bits in get_buffer; if suspend, take action.
+ * val = GET_BITS(n);
+ * Fetch next N bits.
+ * val = PEEK_BITS(n);
+ * Fetch next N bits without removing them from the buffer.
+ * DROP_BITS(n);
+ * Discard next N bits.
+ * The value N should be a simple variable, not an expression, because it
+ * is evaluated multiple times.
+ */
+
+#define CHECK_BIT_BUFFER(state,nbits,action) \
+ { if (bits_left < (nbits)) { \
+ if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
+ { action; } \
+ get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
+
+#define GET_BITS(nbits) \
+ (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
+
+#define PEEK_BITS(nbits) \
+ (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
+
+#define DROP_BITS(nbits) \
+ (bits_left -= (nbits))
+
+/* Load up the bit buffer to a depth of at least nbits */
+EXTERN(boolean) jpeg_fill_bit_buffer
+ JPP((bitread_working_state * state, register bit_buf_type get_buffer,
+ register int bits_left, int nbits));
+
+
+/*
+ * Code for extracting next Huffman-coded symbol from input bit stream.
+ * Again, this is time-critical and we make the main paths be macros.
+ *
+ * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits
+ * without looping. Usually, more than 95% of the Huffman codes will be 8
+ * or fewer bits long. The few overlength codes are handled with a loop,
+ * which need not be inline code.
+ *
+ * Notes about the HUFF_DECODE macro:
+ * 1. Near the end of the data segment, we may fail to get enough bits
+ * for a lookahead. In that case, we do it the hard way.
+ * 2. If the lookahead table contains no entry, the next code must be
+ * more than HUFF_LOOKAHEAD bits long.
+ * 3. jpeg_huff_decode returns -1 if forced to suspend.
+ */
+
+#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
+{ register int nb, look; \
+ if (bits_left < HUFF_LOOKAHEAD) { \
+ if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
+ get_buffer = state.get_buffer; bits_left = state.bits_left; \
+ if (bits_left < HUFF_LOOKAHEAD) { \
+ nb = 1; goto slowlabel; \
+ } \
+ } \
+ look = PEEK_BITS(HUFF_LOOKAHEAD); \
+ if ((nb = htbl->look_nbits[look]) != 0) { \
+ DROP_BITS(nb); \
+ result = htbl->look_sym[look]; \
+ } else { \
+ nb = HUFF_LOOKAHEAD+1; \
+slowlabel: \
+ if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
+ { failaction; } \
+ get_buffer = state.get_buffer; bits_left = state.bits_left; \
+ } \
+}
+
+/* Out-of-line case for Huffman code fetching */
+EXTERN(int) jpeg_huff_decode
+ JPP((bitread_working_state * state, register bit_buf_type get_buffer,
+ register int bits_left, d_derived_tbl * htbl, int min_bits));
diff --git a/osframework/source/ImageLib/jpeg/jdinput.c b/osframework/source/ImageLib/jpeg/jdinput.c
new file mode 100644
index 0000000..2d5c747
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdinput.c
@@ -0,0 +1,381 @@
+/*
+ * jdinput.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains input control logic for the JPEG decompressor.
+ * These routines are concerned with controlling the decompressor's input
+ * processing (marker reading and coefficient decoding). The actual input
+ * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private state */
+
+typedef struct {
+ struct jpeg_input_controller pub; /* public fields */
+
+ boolean inheaders; /* TRUE until first SOS is reached */
+} my_input_controller;
+
+typedef my_input_controller * my_inputctl_ptr;
+
+
+/* Forward declarations */
+METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
+
+
+/*
+ * Routines to calculate various quantities related to the size of the image.
+ */
+
+LOCAL(void)
+initial_setup (j_decompress_ptr cinfo)
+/* Called once, when first SOS marker is reached */
+{
+ int ci;
+ jpeg_component_info *compptr;
+
+ /* Make sure image isn't bigger than I can handle */
+ if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
+ (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
+ ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
+
+ /* For now, precision must match compiled-in value... */
+ if (cinfo->data_precision != BITS_IN_JSAMPLE)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
+
+ /* Check that number of components won't exceed internal array sizes */
+ if (cinfo->num_components > MAX_COMPONENTS)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
+ MAX_COMPONENTS);
+
+ /* Compute maximum sampling factors; check factor validity */
+ cinfo->max_h_samp_factor = 1;
+ cinfo->max_v_samp_factor = 1;
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
+ compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
+ ERREXIT(cinfo, JERR_BAD_SAMPLING);
+ cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
+ compptr->h_samp_factor);
+ cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
+ compptr->v_samp_factor);
+ }
+
+ /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
+ * In the full decompressor, this will be overridden by jdmaster.c;
+ * but in the transcoder, jdmaster.c is not used, so we must do it here.
+ */
+ cinfo->min_DCT_scaled_size = DCTSIZE;
+
+ /* Compute dimensions of components */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ compptr->DCT_scaled_size = DCTSIZE;
+ /* Size in DCT blocks */
+ compptr->width_in_blocks = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
+ (long) (cinfo->max_h_samp_factor * DCTSIZE));
+ compptr->height_in_blocks = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
+ (long) (cinfo->max_v_samp_factor * DCTSIZE));
+ /* downsampled_width and downsampled_height will also be overridden by
+ * jdmaster.c if we are doing full decompression. The transcoder library
+ * doesn't use these values, but the calling application might.
+ */
+ /* Size in samples */
+ compptr->downsampled_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
+ (long) cinfo->max_h_samp_factor);
+ compptr->downsampled_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
+ (long) cinfo->max_v_samp_factor);
+ /* Mark component needed, until color conversion says otherwise */
+ compptr->component_needed = TRUE;
+ /* Mark no quantization table yet saved for component */
+ compptr->quant_table = NULL;
+ }
+
+ /* Compute number of fully interleaved MCU rows. */
+ cinfo->total_iMCU_rows = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height,
+ (long) (cinfo->max_v_samp_factor*DCTSIZE));
+
+ /* Decide whether file contains multiple scans */
+ if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
+ cinfo->inputctl->has_multiple_scans = TRUE;
+ else
+ cinfo->inputctl->has_multiple_scans = FALSE;
+}
+
+
+LOCAL(void)
+per_scan_setup (j_decompress_ptr cinfo)
+/* Do computations that are needed before processing a JPEG scan */
+/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
+{
+ int ci, mcublks, tmp;
+ jpeg_component_info *compptr;
+
+ if (cinfo->comps_in_scan == 1) {
+
+ /* Noninterleaved (single-component) scan */
+ compptr = cinfo->cur_comp_info[0];
+
+ /* Overall image size in MCUs */
+ cinfo->MCUs_per_row = compptr->width_in_blocks;
+ cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
+
+ /* For noninterleaved scan, always one block per MCU */
+ compptr->MCU_width = 1;
+ compptr->MCU_height = 1;
+ compptr->MCU_blocks = 1;
+ compptr->MCU_sample_width = compptr->DCT_scaled_size;
+ compptr->last_col_width = 1;
+ /* For noninterleaved scans, it is convenient to define last_row_height
+ * as the number of block rows present in the last iMCU row.
+ */
+ tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+ if (tmp == 0) tmp = compptr->v_samp_factor;
+ compptr->last_row_height = tmp;
+
+ /* Prepare array describing MCU composition */
+ cinfo->blocks_in_MCU = 1;
+ cinfo->MCU_membership[0] = 0;
+
+ } else {
+
+ /* Interleaved (multi-component) scan */
+ if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
+ ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
+ MAX_COMPS_IN_SCAN);
+
+ /* Overall image size in MCUs */
+ cinfo->MCUs_per_row = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width,
+ (long) (cinfo->max_h_samp_factor*DCTSIZE));
+ cinfo->MCU_rows_in_scan = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height,
+ (long) (cinfo->max_v_samp_factor*DCTSIZE));
+
+ cinfo->blocks_in_MCU = 0;
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* Sampling factors give # of blocks of component in each MCU */
+ compptr->MCU_width = compptr->h_samp_factor;
+ compptr->MCU_height = compptr->v_samp_factor;
+ compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
+ compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
+ /* Figure number of non-dummy blocks in last MCU column & row */
+ tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
+ if (tmp == 0) tmp = compptr->MCU_width;
+ compptr->last_col_width = tmp;
+ tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
+ if (tmp == 0) tmp = compptr->MCU_height;
+ compptr->last_row_height = tmp;
+ /* Prepare array describing MCU composition */
+ mcublks = compptr->MCU_blocks;
+ if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
+ ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
+ while (mcublks-- > 0) {
+ cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
+ }
+ }
+
+ }
+}
+
+
+/*
+ * Save away a copy of the Q-table referenced by each component present
+ * in the current scan, unless already saved during a prior scan.
+ *
+ * In a multiple-scan JPEG file, the encoder could assign different components
+ * the same Q-table slot number, but change table definitions between scans
+ * so that each component uses a different Q-table. (The IJG encoder is not
+ * currently capable of doing this, but other encoders might.) Since we want
+ * to be able to dequantize all the components at the end of the file, this
+ * means that we have to save away the table actually used for each component.
+ * We do this by copying the table at the start of the first scan containing
+ * the component.
+ * The JPEG spec prohibits the encoder from changing the contents of a Q-table
+ * slot between scans of a component using that slot. If the encoder does so
+ * anyway, this decoder will simply use the Q-table values that were current
+ * at the start of the first scan for the component.
+ *
+ * The decompressor output side looks only at the saved quant tables,
+ * not at the current Q-table slots.
+ */
+
+LOCAL(void)
+latch_quant_tables (j_decompress_ptr cinfo)
+{
+ int ci, qtblno;
+ jpeg_component_info *compptr;
+ JQUANT_TBL * qtbl;
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* No work if we already saved Q-table for this component */
+ if (compptr->quant_table != NULL)
+ continue;
+ /* Make sure specified quantization table is present */
+ qtblno = compptr->quant_tbl_no;
+ if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
+ cinfo->quant_tbl_ptrs[qtblno] == NULL)
+ ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
+ /* OK, save away the quantization table */
+ qtbl = (JQUANT_TBL *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(JQUANT_TBL));
+ MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
+ compptr->quant_table = qtbl;
+ }
+}
+
+
+/*
+ * Initialize the input modules to read a scan of compressed data.
+ * The first call to this is done by jdmaster.c after initializing
+ * the entire decompressor (during jpeg_start_decompress).
+ * Subsequent calls come from consume_markers, below.
+ */
+
+METHODDEF(void)
+start_input_pass (j_decompress_ptr cinfo)
+{
+ per_scan_setup(cinfo);
+ latch_quant_tables(cinfo);
+ (*cinfo->entropy->start_pass) (cinfo);
+ (*cinfo->coef->start_input_pass) (cinfo);
+ cinfo->inputctl->consume_input = cinfo->coef->consume_data;
+}
+
+
+/*
+ * Finish up after inputting a compressed-data scan.
+ * This is called by the coefficient controller after it's read all
+ * the expected data of the scan.
+ */
+
+METHODDEF(void)
+finish_input_pass (j_decompress_ptr cinfo)
+{
+ cinfo->inputctl->consume_input = consume_markers;
+}
+
+
+/*
+ * Read JPEG markers before, between, or after compressed-data scans.
+ * Change state as necessary when a new scan is reached.
+ * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
+ *
+ * The consume_input method pointer points either here or to the
+ * coefficient controller's consume_data routine, depending on whether
+ * we are reading a compressed data segment or inter-segment markers.
+ */
+
+METHODDEF(int)
+consume_markers (j_decompress_ptr cinfo)
+{
+ my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
+ int val;
+
+ if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
+ return JPEG_REACHED_EOI;
+
+ val = (*cinfo->marker->read_markers) (cinfo);
+
+ switch (val) {
+ case JPEG_REACHED_SOS: /* Found SOS */
+ if (inputctl->inheaders) { /* 1st SOS */
+ initial_setup(cinfo);
+ inputctl->inheaders = FALSE;
+ /* Note: start_input_pass must be called by jdmaster.c
+ * before any more input can be consumed. jdapimin.c is
+ * responsible for enforcing this sequencing.
+ */
+ } else { /* 2nd or later SOS marker */
+ if (! inputctl->pub.has_multiple_scans)
+ ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
+ start_input_pass(cinfo);
+ }
+ break;
+ case JPEG_REACHED_EOI: /* Found EOI */
+ inputctl->pub.eoi_reached = TRUE;
+ if (inputctl->inheaders) { /* Tables-only datastream, apparently */
+ if (cinfo->marker->saw_SOF)
+ ERREXIT(cinfo, JERR_SOF_NO_SOS);
+ } else {
+ /* Prevent infinite loop in coef ctlr's decompress_data routine
+ * if user set output_scan_number larger than number of scans.
+ */
+ if (cinfo->output_scan_number > cinfo->input_scan_number)
+ cinfo->output_scan_number = cinfo->input_scan_number;
+ }
+ break;
+ case JPEG_SUSPENDED:
+ break;
+ }
+
+ return val;
+}
+
+
+/*
+ * Reset state to begin a fresh datastream.
+ */
+
+METHODDEF(void)
+reset_input_controller (j_decompress_ptr cinfo)
+{
+ my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
+
+ inputctl->pub.consume_input = consume_markers;
+ inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
+ inputctl->pub.eoi_reached = FALSE;
+ inputctl->inheaders = TRUE;
+ /* Reset other modules */
+ (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
+ (*cinfo->marker->reset_marker_reader) (cinfo);
+ /* Reset progression state -- would be cleaner if entropy decoder did this */
+ cinfo->coef_bits = NULL;
+}
+
+
+/*
+ * Initialize the input controller module.
+ * This is called only once, when the decompression object is created.
+ */
+
+GLOBAL(void)
+jinit_input_controller (j_decompress_ptr cinfo)
+{
+ my_inputctl_ptr inputctl;
+
+ /* Create subobject in permanent pool */
+ inputctl = (my_inputctl_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_input_controller));
+ cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
+ /* Initialize method pointers */
+ inputctl->pub.consume_input = consume_markers;
+ inputctl->pub.reset_input_controller = reset_input_controller;
+ inputctl->pub.start_input_pass = start_input_pass;
+ inputctl->pub.finish_input_pass = finish_input_pass;
+ /* Initialize state: can't use reset_input_controller since we don't
+ * want to try to reset other modules yet.
+ */
+ inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
+ inputctl->pub.eoi_reached = FALSE;
+ inputctl->inheaders = TRUE;
+}
diff --git a/osframework/source/ImageLib/jpeg/jdmainct.c b/osframework/source/ImageLib/jpeg/jdmainct.c
new file mode 100644
index 0000000..6b0f06f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdmainct.c
@@ -0,0 +1,512 @@
+/*
+ * jdmainct.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the main buffer controller for decompression.
+ * The main buffer lies between the JPEG decompressor proper and the
+ * post-processor; it holds downsampled data in the JPEG colorspace.
+ *
+ * Note that this code is bypassed in raw-data mode, since the application
+ * supplies the equivalent of the main buffer in that case.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * In the current system design, the main buffer need never be a full-image
+ * buffer; any full-height buffers will be found inside the coefficient or
+ * postprocessing controllers. Nonetheless, the main controller is not
+ * trivial. Its responsibility is to provide context rows for upsampling/
+ * rescaling, and doing this in an efficient fashion is a bit tricky.
+ *
+ * Postprocessor input data is counted in "row groups". A row group
+ * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
+ * sample rows of each component. (We require DCT_scaled_size values to be
+ * chosen such that these numbers are integers. In practice DCT_scaled_size
+ * values will likely be powers of two, so we actually have the stronger
+ * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
+ * Upsampling will typically produce max_v_samp_factor pixel rows from each
+ * row group (times any additional scale factor that the upsampler is
+ * applying).
+ *
+ * The coefficient controller will deliver data to us one iMCU row at a time;
+ * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
+ * exactly min_DCT_scaled_size row groups. (This amount of data corresponds
+ * to one row of MCUs when the image is fully interleaved.) Note that the
+ * number of sample rows varies across components, but the number of row
+ * groups does not. Some garbage sample rows may be included in the last iMCU
+ * row at the bottom of the image.
+ *
+ * Depending on the vertical scaling algorithm used, the upsampler may need
+ * access to the sample row(s) above and below its current input row group.
+ * The upsampler is required to set need_context_rows TRUE at global selection
+ * time if so. When need_context_rows is FALSE, this controller can simply
+ * obtain one iMCU row at a time from the coefficient controller and dole it
+ * out as row groups to the postprocessor.
+ *
+ * When need_context_rows is TRUE, this controller guarantees that the buffer
+ * passed to postprocessing contains at least one row group's worth of samples
+ * above and below the row group(s) being processed. Note that the context
+ * rows "above" the first passed row group appear at negative row offsets in
+ * the passed buffer. At the top and bottom of the image, the required
+ * context rows are manufactured by duplicating the first or last real sample
+ * row; this avoids having special cases in the upsampling inner loops.
+ *
+ * The amount of context is fixed at one row group just because that's a
+ * convenient number for this controller to work with. The existing
+ * upsamplers really only need one sample row of context. An upsampler
+ * supporting arbitrary output rescaling might wish for more than one row
+ * group of context when shrinking the image; tough, we don't handle that.
+ * (This is justified by the assumption that downsizing will be handled mostly
+ * by adjusting the DCT_scaled_size values, so that the actual scale factor at
+ * the upsample step needn't be much less than one.)
+ *
+ * To provide the desired context, we have to retain the last two row groups
+ * of one iMCU row while reading in the next iMCU row. (The last row group
+ * can't be processed until we have another row group for its below-context,
+ * and so we have to save the next-to-last group too for its above-context.)
+ * We could do this most simply by copying data around in our buffer, but
+ * that'd be very slow. We can avoid copying any data by creating a rather
+ * strange pointer structure. Here's how it works. We allocate a workspace
+ * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
+ * of row groups per iMCU row). We create two sets of redundant pointers to
+ * the workspace. Labeling the physical row groups 0 to M+1, the synthesized
+ * pointer lists look like this:
+ * M+1 M-1
+ * master pointer --> 0 master pointer --> 0
+ * 1 1
+ * ... ...
+ * M-3 M-3
+ * M-2 M
+ * M-1 M+1
+ * M M-2
+ * M+1 M-1
+ * 0 0
+ * We read alternate iMCU rows using each master pointer; thus the last two
+ * row groups of the previous iMCU row remain un-overwritten in the workspace.
+ * The pointer lists are set up so that the required context rows appear to
+ * be adjacent to the proper places when we pass the pointer lists to the
+ * upsampler.
+ *
+ * The above pictures describe the normal state of the pointer lists.
+ * At top and bottom of the image, we diddle the pointer lists to duplicate
+ * the first or last sample row as necessary (this is cheaper than copying
+ * sample rows around).
+ *
+ * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that
+ * situation each iMCU row provides only one row group so the buffering logic
+ * must be different (eg, we must read two iMCU rows before we can emit the
+ * first row group). For now, we simply do not support providing context
+ * rows when min_DCT_scaled_size is 1. That combination seems unlikely to
+ * be worth providing --- if someone wants a 1/8th-size preview, they probably
+ * want it quick and dirty, so a context-free upsampler is sufficient.
+ */
+
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_d_main_controller pub; /* public fields */
+
+ /* Pointer to allocated workspace (M or M+2 row groups). */
+ JSAMPARRAY buffer[MAX_COMPONENTS];
+
+ boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
+ JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
+
+ /* Remaining fields are only used in the context case. */
+
+ /* These are the master pointers to the funny-order pointer lists. */
+ JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
+
+ int whichptr; /* indicates which pointer set is now in use */
+ int context_state; /* process_data state machine status */
+ JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
+ JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
+} my_main_controller;
+
+typedef my_main_controller * my_main_ptr;
+
+/* context_state values: */
+#define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
+#define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
+#define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
+
+
+/* Forward declarations */
+METHODDEF(void) process_data_simple_main
+ JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
+METHODDEF(void) process_data_context_main
+ JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
+#ifdef QUANT_2PASS_SUPPORTED
+METHODDEF(void) process_data_crank_post
+ JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
+#endif
+
+
+LOCAL(void)
+alloc_funny_pointers (j_decompress_ptr cinfo)
+/* Allocate space for the funny pointer lists.
+ * This is done only once, not once per pass.
+ */
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ int ci, rgroup;
+ int M = cinfo->min_DCT_scaled_size;
+ jpeg_component_info *compptr;
+ JSAMPARRAY xbuf;
+
+ /* Get top-level space for component array pointers.
+ * We alloc both arrays with one call to save a few cycles.
+ */
+ main->xbuffer[0] = (JSAMPIMAGE)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
+ main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size; /* height of a row group of component */
+ /* Get space for pointer lists --- M+4 row groups in each list.
+ * We alloc both pointer lists with one call to save a few cycles.
+ */
+ xbuf = (JSAMPARRAY)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
+ xbuf += rgroup; /* want one row group at negative offsets */
+ main->xbuffer[0][ci] = xbuf;
+ xbuf += rgroup * (M + 4);
+ main->xbuffer[1][ci] = xbuf;
+ }
+}
+
+
+LOCAL(void)
+make_funny_pointers (j_decompress_ptr cinfo)
+/* Create the funny pointer lists discussed in the comments above.
+ * The actual workspace is already allocated (in main->buffer),
+ * and the space for the pointer lists is allocated too.
+ * This routine just fills in the curiously ordered lists.
+ * This will be repeated at the beginning of each pass.
+ */
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ int ci, i, rgroup;
+ int M = cinfo->min_DCT_scaled_size;
+ jpeg_component_info *compptr;
+ JSAMPARRAY buf, xbuf0, xbuf1;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size; /* height of a row group of component */
+ xbuf0 = main->xbuffer[0][ci];
+ xbuf1 = main->xbuffer[1][ci];
+ /* First copy the workspace pointers as-is */
+ buf = main->buffer[ci];
+ for (i = 0; i < rgroup * (M + 2); i++) {
+ xbuf0[i] = xbuf1[i] = buf[i];
+ }
+ /* In the second list, put the last four row groups in swapped order */
+ for (i = 0; i < rgroup * 2; i++) {
+ xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
+ xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
+ }
+ /* The wraparound pointers at top and bottom will be filled later
+ * (see set_wraparound_pointers, below). Initially we want the "above"
+ * pointers to duplicate the first actual data line. This only needs
+ * to happen in xbuffer[0].
+ */
+ for (i = 0; i < rgroup; i++) {
+ xbuf0[i - rgroup] = xbuf0[0];
+ }
+ }
+}
+
+
+LOCAL(void)
+set_wraparound_pointers (j_decompress_ptr cinfo)
+/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
+ * This changes the pointer list state from top-of-image to the normal state.
+ */
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ int ci, i, rgroup;
+ int M = cinfo->min_DCT_scaled_size;
+ jpeg_component_info *compptr;
+ JSAMPARRAY xbuf0, xbuf1;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size; /* height of a row group of component */
+ xbuf0 = main->xbuffer[0][ci];
+ xbuf1 = main->xbuffer[1][ci];
+ for (i = 0; i < rgroup; i++) {
+ xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
+ xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
+ xbuf0[rgroup*(M+2) + i] = xbuf0[i];
+ xbuf1[rgroup*(M+2) + i] = xbuf1[i];
+ }
+ }
+}
+
+
+LOCAL(void)
+set_bottom_pointers (j_decompress_ptr cinfo)
+/* Change the pointer lists to duplicate the last sample row at the bottom
+ * of the image. whichptr indicates which xbuffer holds the final iMCU row.
+ * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
+ */
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ int ci, i, rgroup, iMCUheight, rows_left;
+ jpeg_component_info *compptr;
+ JSAMPARRAY xbuf;
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Count sample rows in one iMCU row and in one row group */
+ iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
+ rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
+ /* Count nondummy sample rows remaining for this component */
+ rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
+ if (rows_left == 0) rows_left = iMCUheight;
+ /* Count nondummy row groups. Should get same answer for each component,
+ * so we need only do it once.
+ */
+ if (ci == 0) {
+ main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
+ }
+ /* Duplicate the last real sample row rgroup*2 times; this pads out the
+ * last partial rowgroup and ensures at least one full rowgroup of context.
+ */
+ xbuf = main->xbuffer[main->whichptr][ci];
+ for (i = 0; i < rgroup * 2; i++) {
+ xbuf[rows_left + i] = xbuf[rows_left-1];
+ }
+ }
+}
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+
+ switch (pass_mode) {
+ case JBUF_PASS_THRU:
+ if (cinfo->upsample->need_context_rows) {
+ main->pub.process_data = process_data_context_main;
+ make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
+ main->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
+ main->context_state = CTX_PREPARE_FOR_IMCU;
+ main->iMCU_row_ctr = 0;
+ } else {
+ /* Simple case with no context needed */
+ main->pub.process_data = process_data_simple_main;
+ }
+ main->buffer_full = FALSE; /* Mark buffer empty */
+ main->rowgroup_ctr = 0;
+ break;
+#ifdef QUANT_2PASS_SUPPORTED
+ case JBUF_CRANK_DEST:
+ /* For last pass of 2-pass quantization, just crank the postprocessor */
+ main->pub.process_data = process_data_crank_post;
+ break;
+#endif
+ default:
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ break;
+ }
+}
+
+
+/*
+ * Process some data.
+ * This handles the simple case where no context is required.
+ */
+
+METHODDEF(void)
+process_data_simple_main (j_decompress_ptr cinfo,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+ JDIMENSION rowgroups_avail;
+
+ /* Read input data if we haven't filled the main buffer yet */
+ if (! main->buffer_full) {
+ if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer))
+ return; /* suspension forced, can do nothing more */
+ main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
+ }
+
+ /* There are always min_DCT_scaled_size row groups in an iMCU row. */
+ rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
+ /* Note: at the bottom of the image, we may pass extra garbage row groups
+ * to the postprocessor. The postprocessor has to check for bottom
+ * of image anyway (at row resolution), so no point in us doing it too.
+ */
+
+ /* Feed the postprocessor */
+ (*cinfo->post->post_process_data) (cinfo, main->buffer,
+ &main->rowgroup_ctr, rowgroups_avail,
+ output_buf, out_row_ctr, out_rows_avail);
+
+ /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
+ if (main->rowgroup_ctr >= rowgroups_avail) {
+ main->buffer_full = FALSE;
+ main->rowgroup_ctr = 0;
+ }
+}
+
+
+/*
+ * Process some data.
+ * This handles the case where context rows must be provided.
+ */
+
+METHODDEF(void)
+process_data_context_main (j_decompress_ptr cinfo,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_main_ptr main = (my_main_ptr) cinfo->main;
+
+ /* Read input data if we haven't filled the main buffer yet */
+ if (! main->buffer_full) {
+ if (! (*cinfo->coef->decompress_data) (cinfo,
+ main->xbuffer[main->whichptr]))
+ return; /* suspension forced, can do nothing more */
+ main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
+ main->iMCU_row_ctr++; /* count rows received */
+ }
+
+ /* Postprocessor typically will not swallow all the input data it is handed
+ * in one call (due to filling the output buffer first). Must be prepared
+ * to exit and restart. This switch lets us keep track of how far we got.
+ * Note that each case falls through to the next on successful completion.
+ */
+ switch (main->context_state) {
+ case CTX_POSTPONED_ROW:
+ /* Call postprocessor using previously set pointers for postponed row */
+ (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
+ &main->rowgroup_ctr, main->rowgroups_avail,
+ output_buf, out_row_ctr, out_rows_avail);
+ if (main->rowgroup_ctr < main->rowgroups_avail)
+ return; /* Need to suspend */
+ main->context_state = CTX_PREPARE_FOR_IMCU;
+ if (*out_row_ctr >= out_rows_avail)
+ return; /* Postprocessor exactly filled output buf */
+ /*FALLTHROUGH*/
+ case CTX_PREPARE_FOR_IMCU:
+ /* Prepare to process first M-1 row groups of this iMCU row */
+ main->rowgroup_ctr = 0;
+ main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
+ /* Check for bottom of image: if so, tweak pointers to "duplicate"
+ * the last sample row, and adjust rowgroups_avail to ignore padding rows.
+ */
+ if (main->iMCU_row_ctr == cinfo->total_iMCU_rows)
+ set_bottom_pointers(cinfo);
+ main->context_state = CTX_PROCESS_IMCU;
+ /*FALLTHROUGH*/
+ case CTX_PROCESS_IMCU:
+ /* Call postprocessor using previously set pointers */
+ (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
+ &main->rowgroup_ctr, main->rowgroups_avail,
+ output_buf, out_row_ctr, out_rows_avail);
+ if (main->rowgroup_ctr < main->rowgroups_avail)
+ return; /* Need to suspend */
+ /* After the first iMCU, change wraparound pointers to normal state */
+ if (main->iMCU_row_ctr == 1)
+ set_wraparound_pointers(cinfo);
+ /* Prepare to load new iMCU row using other xbuffer list */
+ main->whichptr ^= 1; /* 0=>1 or 1=>0 */
+ main->buffer_full = FALSE;
+ /* Still need to process last row group of this iMCU row, */
+ /* which is saved at index M+1 of the other xbuffer */
+ main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
+ main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
+ main->context_state = CTX_POSTPONED_ROW;
+ }
+}
+
+
+/*
+ * Process some data.
+ * Final pass of two-pass quantization: just call the postprocessor.
+ * Source data will be the postprocessor controller's internal buffer.
+ */
+
+#ifdef QUANT_2PASS_SUPPORTED
+
+METHODDEF(void)
+process_data_crank_post (j_decompress_ptr cinfo,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
+ (JDIMENSION *) NULL, (JDIMENSION) 0,
+ output_buf, out_row_ctr, out_rows_avail);
+}
+
+#endif /* QUANT_2PASS_SUPPORTED */
+
+
+/*
+ * Initialize main buffer controller.
+ */
+
+GLOBAL(void)
+jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
+{
+ my_main_ptr main;
+ int ci, rgroup, ngroups;
+ jpeg_component_info *compptr;
+
+ main = (my_main_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_main_controller));
+ cinfo->main = (struct jpeg_d_main_controller *) main;
+ main->pub.start_pass = start_pass_main;
+
+ if (need_full_buffer) /* shouldn't happen */
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+
+ /* Allocate the workspace.
+ * ngroups is the number of row groups we need.
+ */
+ if (cinfo->upsample->need_context_rows) {
+ if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
+ ERREXIT(cinfo, JERR_NOTIMPL);
+ alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
+ ngroups = cinfo->min_DCT_scaled_size + 2;
+ } else {
+ ngroups = cinfo->min_DCT_scaled_size;
+ }
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size; /* height of a row group of component */
+ main->buffer[ci] = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ compptr->width_in_blocks * compptr->DCT_scaled_size,
+ (JDIMENSION) (rgroup * ngroups));
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdmarker.c b/osframework/source/ImageLib/jpeg/jdmarker.c
new file mode 100644
index 0000000..9811761
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdmarker.c
@@ -0,0 +1,1360 @@
+/*
+ * jdmarker.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to decode JPEG datastream markers.
+ * Most of the complexity arises from our desire to support input
+ * suspension: if not all of the data for a marker is available,
+ * we must exit back to the application. On resumption, we reprocess
+ * the marker.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+typedef enum { /* JPEG marker codes */
+ M_SOF0 = 0xc0,
+ M_SOF1 = 0xc1,
+ M_SOF2 = 0xc2,
+ M_SOF3 = 0xc3,
+
+ M_SOF5 = 0xc5,
+ M_SOF6 = 0xc6,
+ M_SOF7 = 0xc7,
+
+ M_JPG = 0xc8,
+ M_SOF9 = 0xc9,
+ M_SOF10 = 0xca,
+ M_SOF11 = 0xcb,
+
+ M_SOF13 = 0xcd,
+ M_SOF14 = 0xce,
+ M_SOF15 = 0xcf,
+
+ M_DHT = 0xc4,
+
+ M_DAC = 0xcc,
+
+ M_RST0 = 0xd0,
+ M_RST1 = 0xd1,
+ M_RST2 = 0xd2,
+ M_RST3 = 0xd3,
+ M_RST4 = 0xd4,
+ M_RST5 = 0xd5,
+ M_RST6 = 0xd6,
+ M_RST7 = 0xd7,
+
+ M_SOI = 0xd8,
+ M_EOI = 0xd9,
+ M_SOS = 0xda,
+ M_DQT = 0xdb,
+ M_DNL = 0xdc,
+ M_DRI = 0xdd,
+ M_DHP = 0xde,
+ M_EXP = 0xdf,
+
+ M_APP0 = 0xe0,
+ M_APP1 = 0xe1,
+ M_APP2 = 0xe2,
+ M_APP3 = 0xe3,
+ M_APP4 = 0xe4,
+ M_APP5 = 0xe5,
+ M_APP6 = 0xe6,
+ M_APP7 = 0xe7,
+ M_APP8 = 0xe8,
+ M_APP9 = 0xe9,
+ M_APP10 = 0xea,
+ M_APP11 = 0xeb,
+ M_APP12 = 0xec,
+ M_APP13 = 0xed,
+ M_APP14 = 0xee,
+ M_APP15 = 0xef,
+
+ M_JPG0 = 0xf0,
+ M_JPG13 = 0xfd,
+ M_COM = 0xfe,
+
+ M_TEM = 0x01,
+
+ M_ERROR = 0x100
+} JPEG_MARKER;
+
+
+/* Private state */
+
+typedef struct {
+ struct jpeg_marker_reader pub; /* public fields */
+
+ /* Application-overridable marker processing methods */
+ jpeg_marker_parser_method process_COM;
+ jpeg_marker_parser_method process_APPn[16];
+
+ /* Limit on marker data length to save for each marker type */
+ unsigned int length_limit_COM;
+ unsigned int length_limit_APPn[16];
+
+ /* Status of COM/APPn marker saving */
+ jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
+ unsigned int bytes_read; /* data bytes read so far in marker */
+ /* Note: cur_marker is not linked into marker_list until it's all read. */
+} my_marker_reader;
+
+typedef my_marker_reader * my_marker_ptr;
+
+
+/*
+ * 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 --- used only 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); \
+ }
+
+/* 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); \
+ bytes_in_buffer--; \
+ 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); \
+ bytes_in_buffer--; \
+ V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
+ MAKE_BYTE_AVAIL(cinfo,action); \
+ bytes_in_buffer--; \
+ V += GETJOCTET(*next_input_byte++); )
+
+
+/*
+ * Routines to process JPEG markers.
+ *
+ * Entry condition: JPEG marker itself has been read and its code saved
+ * in cinfo->unread_marker; input restart point is just after the marker.
+ *
+ * Exit: if return TRUE, have read and processed any parameters, and have
+ * updated the restart point to point after the parameters.
+ * If return FALSE, was forced to suspend before reaching end of
+ * marker parameters; restart point has not been moved. Same routine
+ * will be called again after application supplies more input data.
+ *
+ * This approach to suspension assumes that all of a marker's parameters
+ * can fit into a single input bufferload. This should hold for "normal"
+ * markers. Some COM/APPn markers might have large parameter segments
+ * that might not fit. If we are simply dropping such a marker, we use
+ * skip_input_data to get past it, and thereby put the problem on the
+ * source manager's shoulders. If we are saving the marker's contents
+ * into memory, we use a slightly different convention: when forced to
+ * suspend, the marker processor updates the restart point to the end of
+ * what it's consumed (ie, the end of the buffer) before returning FALSE.
+ * On resumption, cinfo->unread_marker still contains the marker code,
+ * but the data source will point to the next chunk of marker data.
+ * The marker processor must retain internal state to deal with this.
+ *
+ * Note that we don't bother to avoid duplicate trace messages if a
+ * suspension occurs within marker parameters. Other side effects
+ * require more care.
+ */
+
+
+LOCAL(boolean)
+get_soi (j_decompress_ptr cinfo)
+/* Process an SOI marker */
+{
+ int i;
+
+ TRACEMS(cinfo, 1, JTRC_SOI);
+
+ if (cinfo->marker->saw_SOI)
+ ERREXIT(cinfo, JERR_SOI_DUPLICATE);
+
+ /* Reset all parameters that are defined to be reset by SOI */
+
+ for (i = 0; i < NUM_ARITH_TBLS; i++) {
+ cinfo->arith_dc_L[i] = 0;
+ cinfo->arith_dc_U[i] = 1;
+ cinfo->arith_ac_K[i] = 5;
+ }
+ cinfo->restart_interval = 0;
+
+ /* Set initial assumptions for colorspace etc */
+
+ cinfo->jpeg_color_space = JCS_UNKNOWN;
+ cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
+
+ cinfo->saw_JFIF_marker = FALSE;
+ cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
+ cinfo->JFIF_minor_version = 1;
+ cinfo->density_unit = 0;
+ cinfo->X_density = 1;
+ cinfo->Y_density = 1;
+ cinfo->saw_Adobe_marker = FALSE;
+ cinfo->Adobe_transform = 0;
+
+ cinfo->marker->saw_SOI = TRUE;
+
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
+/* Process a SOFn marker */
+{
+ INT32 length;
+ int c, ci;
+ jpeg_component_info * compptr;
+ INPUT_VARS(cinfo);
+
+ cinfo->progressive_mode = is_prog;
+ cinfo->arith_code = is_arith;
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+
+ INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
+ INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
+ INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
+ INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
+
+ length -= 8;
+
+ TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
+ (int) cinfo->image_width, (int) cinfo->image_height,
+ cinfo->num_components);
+
+ if (cinfo->marker->saw_SOF)
+ ERREXIT(cinfo, JERR_SOF_DUPLICATE);
+
+ /* We don't support files in which the image height is initially specified */
+ /* as 0 and is later redefined by DNL. As long as we have to check that, */
+ /* might as well have a general sanity check. */
+ if (cinfo->image_height <= 0 || cinfo->image_width <= 0
+ || cinfo->num_components <= 0)
+ ERREXIT(cinfo, JERR_EMPTY_IMAGE);
+
+ if (length != (cinfo->num_components * 3))
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ if (cinfo->comp_info == NULL) /* do only once, even if suspend */
+ cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->num_components * SIZEOF(jpeg_component_info));
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ compptr->component_index = ci;
+ INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
+ INPUT_BYTE(cinfo, c, return FALSE);
+ compptr->h_samp_factor = (c >> 4) & 15;
+ compptr->v_samp_factor = (c ) & 15;
+ INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
+
+ TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
+ compptr->component_id, compptr->h_samp_factor,
+ compptr->v_samp_factor, compptr->quant_tbl_no);
+ }
+
+ cinfo->marker->saw_SOF = TRUE;
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+get_sos (j_decompress_ptr cinfo)
+/* Process a SOS marker */
+{
+ INT32 length;
+ int i, ci, n, c, cc;
+ jpeg_component_info * compptr;
+ INPUT_VARS(cinfo);
+
+ if (! cinfo->marker->saw_SOF)
+ ERREXIT(cinfo, JERR_SOS_NO_SOF);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+
+ INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
+
+ TRACEMS1(cinfo, 1, JTRC_SOS, n);
+
+ if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ cinfo->comps_in_scan = n;
+
+ /* Collect the component-spec parameters */
+
+ for (i = 0; i < n; i++) {
+ INPUT_BYTE(cinfo, cc, return FALSE);
+ INPUT_BYTE(cinfo, c, return FALSE);
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ if (cc == compptr->component_id)
+ goto id_found;
+ }
+
+ ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
+
+ id_found:
+
+ cinfo->cur_comp_info[i] = compptr;
+ compptr->dc_tbl_no = (c >> 4) & 15;
+ compptr->ac_tbl_no = (c ) & 15;
+
+ TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
+ compptr->dc_tbl_no, compptr->ac_tbl_no);
+ }
+
+ /* Collect the additional scan parameters Ss, Se, Ah/Al. */
+ INPUT_BYTE(cinfo, c, return FALSE);
+ cinfo->Ss = c;
+ INPUT_BYTE(cinfo, c, return FALSE);
+ cinfo->Se = c;
+ INPUT_BYTE(cinfo, c, return FALSE);
+ cinfo->Ah = (c >> 4) & 15;
+ cinfo->Al = (c ) & 15;
+
+ TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
+ cinfo->Ah, cinfo->Al);
+
+ /* Prepare to scan data & restart markers */
+ cinfo->marker->next_restart_num = 0;
+
+ /* Count another SOS marker */
+ cinfo->input_scan_number++;
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+#ifdef D_ARITH_CODING_SUPPORTED
+
+LOCAL(boolean)
+get_dac (j_decompress_ptr cinfo)
+/* Process a DAC marker */
+{
+ INT32 length;
+ int index, val;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+
+ while (length > 0) {
+ INPUT_BYTE(cinfo, index, return FALSE);
+ INPUT_BYTE(cinfo, val, return FALSE);
+
+ length -= 2;
+
+ TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
+
+ if (index < 0 || index >= (2*NUM_ARITH_TBLS))
+ ERREXIT1(cinfo, JERR_DAC_INDEX, index);
+
+ if (index >= NUM_ARITH_TBLS) { /* define AC table */
+ cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
+ } else { /* define DC table */
+ cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
+ cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
+ if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
+ ERREXIT1(cinfo, JERR_DAC_VALUE, val);
+ }
+ }
+
+ if (length != 0)
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+#else /* ! D_ARITH_CODING_SUPPORTED */
+
+#define get_dac(cinfo) skip_variable(cinfo)
+
+#endif /* D_ARITH_CODING_SUPPORTED */
+
+
+LOCAL(boolean)
+get_dht (j_decompress_ptr cinfo)
+/* Process a DHT marker */
+{
+ INT32 length;
+ UINT8 bits[17];
+ UINT8 huffval[256];
+ int i, index, count;
+ JHUFF_TBL **htblptr;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+
+ while (length > 16) {
+ INPUT_BYTE(cinfo, index, return FALSE);
+
+ TRACEMS1(cinfo, 1, JTRC_DHT, index);
+
+ bits[0] = 0;
+ count = 0;
+ for (i = 1; i <= 16; i++) {
+ INPUT_BYTE(cinfo, bits[i], return FALSE);
+ count += bits[i];
+ }
+
+ length -= 1 + 16;
+
+ TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
+ bits[1], bits[2], bits[3], bits[4],
+ bits[5], bits[6], bits[7], bits[8]);
+ TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
+ bits[9], bits[10], bits[11], bits[12],
+ bits[13], bits[14], bits[15], bits[16]);
+
+ /* Here we just do minimal validation of the counts to avoid walking
+ * off the end of our table space. jdhuff.c will check more carefully.
+ */
+ if (count > 256 || ((INT32) count) > length)
+ ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
+
+ for (i = 0; i < count; i++)
+ INPUT_BYTE(cinfo, huffval[i], return FALSE);
+
+ length -= count;
+
+ if (index & 0x10) { /* AC table definition */
+ index -= 0x10;
+ htblptr = &cinfo->ac_huff_tbl_ptrs[index];
+ } else { /* DC table definition */
+ htblptr = &cinfo->dc_huff_tbl_ptrs[index];
+ }
+
+ if (index < 0 || index >= NUM_HUFF_TBLS)
+ ERREXIT1(cinfo, JERR_DHT_INDEX, index);
+
+ if (*htblptr == NULL)
+ *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
+
+ MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
+ MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
+ }
+
+ if (length != 0)
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+get_dqt (j_decompress_ptr cinfo)
+/* Process a DQT marker */
+{
+ INT32 length;
+ int n, i, prec;
+ unsigned int tmp;
+ JQUANT_TBL *quant_ptr;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+
+ while (length > 0) {
+ INPUT_BYTE(cinfo, n, return FALSE);
+ prec = n >> 4;
+ n &= 0x0F;
+
+ TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
+
+ if (n >= NUM_QUANT_TBLS)
+ ERREXIT1(cinfo, JERR_DQT_INDEX, n);
+
+ if (cinfo->quant_tbl_ptrs[n] == NULL)
+ cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
+ quant_ptr = cinfo->quant_tbl_ptrs[n];
+
+ for (i = 0; i < DCTSIZE2; i++) {
+ if (prec)
+ INPUT_2BYTES(cinfo, tmp, return FALSE);
+ else
+ INPUT_BYTE(cinfo, tmp, return FALSE);
+ /* We convert the zigzag-order table to natural array order. */
+ quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
+ }
+
+ if (cinfo->err->trace_level >= 2) {
+ for (i = 0; i < DCTSIZE2; i += 8) {
+ TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
+ quant_ptr->quantval[i], quant_ptr->quantval[i+1],
+ quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
+ quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
+ quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
+ }
+ }
+
+ length -= DCTSIZE2+1;
+ if (prec) length -= DCTSIZE2;
+ }
+
+ if (length != 0)
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+get_dri (j_decompress_ptr cinfo)
+/* Process a DRI marker */
+{
+ INT32 length;
+ unsigned int tmp;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+
+ if (length != 4)
+ ERREXIT(cinfo, JERR_BAD_LENGTH);
+
+ INPUT_2BYTES(cinfo, tmp, return FALSE);
+
+ TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
+
+ cinfo->restart_interval = tmp;
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+/*
+ * Routines for processing APPn and COM markers.
+ * These are either saved in memory or discarded, per application request.
+ * APP0 and APP14 are specially checked to see if they are
+ * JFIF and Adobe markers, respectively.
+ */
+
+#define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
+#define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
+#define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
+
+
+LOCAL(void)
+examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
+ unsigned int datalen, INT32 remaining)
+/* Examine first few bytes from an APP0.
+ * Take appropriate action if it is a JFIF marker.
+ * datalen is # of bytes at data[], remaining is length of rest of marker data.
+ */
+{
+ INT32 totallen = (INT32) datalen + remaining;
+
+ if (datalen >= APP0_DATA_LEN &&
+ GETJOCTET(data[0]) == 0x4A &&
+ GETJOCTET(data[1]) == 0x46 &&
+ GETJOCTET(data[2]) == 0x49 &&
+ GETJOCTET(data[3]) == 0x46 &&
+ GETJOCTET(data[4]) == 0) {
+ /* Found JFIF APP0 marker: save info */
+ cinfo->saw_JFIF_marker = TRUE;
+ cinfo->JFIF_major_version = GETJOCTET(data[5]);
+ cinfo->JFIF_minor_version = GETJOCTET(data[6]);
+ cinfo->density_unit = GETJOCTET(data[7]);
+ cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
+ cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
+ /* Check version.
+ * Major version must be 1, anything else signals an incompatible change.
+ * (We used to treat this as an error, but now it's a nonfatal warning,
+ * because some bozo at Hijaak couldn't read the spec.)
+ * Minor version should be 0..2, but process anyway if newer.
+ */
+ if (cinfo->JFIF_major_version != 1)
+ WARNMS2(cinfo, JWRN_JFIF_MAJOR,
+ cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
+ /* Generate trace messages */
+ TRACEMS5(cinfo, 1, JTRC_JFIF,
+ cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
+ cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
+ /* Validate thumbnail dimensions and issue appropriate messages */
+ if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
+ TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
+ GETJOCTET(data[12]), GETJOCTET(data[13]));
+ totallen -= APP0_DATA_LEN;
+ if (totallen !=
+ ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
+ TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
+ } else if (datalen >= 6 &&
+ GETJOCTET(data[0]) == 0x4A &&
+ GETJOCTET(data[1]) == 0x46 &&
+ GETJOCTET(data[2]) == 0x58 &&
+ GETJOCTET(data[3]) == 0x58 &&
+ GETJOCTET(data[4]) == 0) {
+ /* Found JFIF "JFXX" extension APP0 marker */
+ /* The library doesn't actually do anything with these,
+ * but we try to produce a helpful trace message.
+ */
+ switch (GETJOCTET(data[5])) {
+ case 0x10:
+ TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
+ break;
+ case 0x11:
+ TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
+ break;
+ case 0x13:
+ TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
+ break;
+ default:
+ TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
+ GETJOCTET(data[5]), (int) totallen);
+ break;
+ }
+ } else {
+ /* Start of APP0 does not match "JFIF" or "JFXX", or too short */
+ TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
+ }
+}
+
+
+LOCAL(void)
+examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
+ unsigned int datalen, INT32 remaining)
+/* Examine first few bytes from an APP14.
+ * Take appropriate action if it is an Adobe marker.
+ * datalen is # of bytes at data[], remaining is length of rest of marker data.
+ */
+{
+ unsigned int version, flags0, flags1, transform;
+
+ if (datalen >= APP14_DATA_LEN &&
+ GETJOCTET(data[0]) == 0x41 &&
+ GETJOCTET(data[1]) == 0x64 &&
+ GETJOCTET(data[2]) == 0x6F &&
+ GETJOCTET(data[3]) == 0x62 &&
+ GETJOCTET(data[4]) == 0x65) {
+ /* Found Adobe APP14 marker */
+ version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
+ flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
+ flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
+ transform = GETJOCTET(data[11]);
+ TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
+ cinfo->saw_Adobe_marker = TRUE;
+ cinfo->Adobe_transform = (UINT8) transform;
+ } else {
+ /* Start of APP14 does not match "Adobe", or too short */
+ TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
+ }
+}
+
+
+METHODDEF(boolean)
+get_interesting_appn (j_decompress_ptr cinfo)
+/* Process an APP0 or APP14 marker without saving it */
+{
+ INT32 length;
+ JOCTET b[APPN_DATA_LEN];
+ unsigned int i, numtoread;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+
+ /* get the interesting part of the marker data */
+ if (length >= APPN_DATA_LEN)
+ numtoread = APPN_DATA_LEN;
+ else if (length > 0)
+ numtoread = (unsigned int) length;
+ else
+ numtoread = 0;
+ for (i = 0; i < numtoread; i++)
+ INPUT_BYTE(cinfo, b[i], return FALSE);
+ length -= numtoread;
+
+ /* process it */
+ switch (cinfo->unread_marker) {
+ case M_APP0:
+ examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
+ break;
+ case M_APP14:
+ examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
+ break;
+ default:
+ /* can't get here unless jpeg_save_markers chooses wrong processor */
+ ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
+ break;
+ }
+
+ /* skip any remaining data -- could be lots */
+ INPUT_SYNC(cinfo);
+ if (length > 0)
+ (*cinfo->src->skip_input_data) (cinfo, (long) length);
+
+ return TRUE;
+}
+
+
+#ifdef SAVE_MARKERS_SUPPORTED
+
+METHODDEF(boolean)
+save_marker (j_decompress_ptr cinfo)
+/* Save an APPn or COM marker into the marker list */
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+ jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
+ unsigned int bytes_read, data_length;
+ JOCTET FAR * data;
+ INT32 length = 0;
+ INPUT_VARS(cinfo);
+
+ if (cur_marker == NULL) {
+ /* begin reading a marker */
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+ if (length >= 0) { /* watch out for bogus length word */
+ /* figure out how much we want to save */
+ unsigned int limit;
+ if (cinfo->unread_marker == (int) M_COM)
+ limit = marker->length_limit_COM;
+ else
+ limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
+ if ((unsigned int) length < limit)
+ limit = (unsigned int) length;
+ /* allocate and initialize the marker item */
+ cur_marker = (jpeg_saved_marker_ptr)
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(struct jpeg_marker_struct) + limit);
+ cur_marker->next = NULL;
+ cur_marker->marker = (UINT8) cinfo->unread_marker;
+ cur_marker->original_length = (unsigned int) length;
+ cur_marker->data_length = limit;
+ /* data area is just beyond the jpeg_marker_struct */
+ data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
+ marker->cur_marker = cur_marker;
+ marker->bytes_read = 0;
+ bytes_read = 0;
+ data_length = limit;
+ } else {
+ /* deal with bogus length word */
+ bytes_read = data_length = 0;
+ data = NULL;
+ }
+ } else {
+ /* resume reading a marker */
+ bytes_read = marker->bytes_read;
+ data_length = cur_marker->data_length;
+ data = cur_marker->data + bytes_read;
+ }
+
+ while (bytes_read < data_length) {
+ INPUT_SYNC(cinfo); /* move the restart point to here */
+ marker->bytes_read = bytes_read;
+ /* If there's not at least one byte in buffer, suspend */
+ MAKE_BYTE_AVAIL(cinfo, return FALSE);
+ /* Copy bytes with reasonable rapidity */
+ while (bytes_read < data_length && bytes_in_buffer > 0) {
+ *data++ = *next_input_byte++;
+ bytes_in_buffer--;
+ bytes_read++;
+ }
+ }
+
+ /* Done reading what we want to read */
+ if (cur_marker != NULL) { /* will be NULL if bogus length word */
+ /* Add new marker to end of list */
+ if (cinfo->marker_list == NULL) {
+ cinfo->marker_list = cur_marker;
+ } else {
+ jpeg_saved_marker_ptr prev = cinfo->marker_list;
+ while (prev->next != NULL)
+ prev = prev->next;
+ prev->next = cur_marker;
+ }
+ /* Reset pointer & calc remaining data length */
+ data = cur_marker->data;
+ length = cur_marker->original_length - data_length;
+ }
+ /* Reset to initial state for next marker */
+ marker->cur_marker = NULL;
+
+ /* Process the marker if interesting; else just make a generic trace msg */
+ switch (cinfo->unread_marker) {
+ case M_APP0:
+ examine_app0(cinfo, data, data_length, length);
+ break;
+ case M_APP14:
+ examine_app14(cinfo, data, data_length, length);
+ break;
+ default:
+ TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
+ (int) (data_length + length));
+ break;
+ }
+
+ /* skip any remaining data -- could be lots */
+ INPUT_SYNC(cinfo); /* do before skip_input_data */
+ if (length > 0)
+ (*cinfo->src->skip_input_data) (cinfo, (long) length);
+
+ return TRUE;
+}
+
+#endif /* SAVE_MARKERS_SUPPORTED */
+
+
+METHODDEF(boolean)
+skip_variable (j_decompress_ptr cinfo)
+/* Skip over an unknown or uninteresting variable-length marker */
+{
+ INT32 length;
+ INPUT_VARS(cinfo);
+
+ INPUT_2BYTES(cinfo, length, return FALSE);
+ length -= 2;
+
+ TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
+
+ INPUT_SYNC(cinfo); /* do before skip_input_data */
+ if (length > 0)
+ (*cinfo->src->skip_input_data) (cinfo, (long) length);
+
+ return TRUE;
+}
+
+
+/*
+ * Find the next JPEG marker, save it in cinfo->unread_marker.
+ * Returns FALSE if had to suspend before reaching a marker;
+ * in that case cinfo->unread_marker is unchanged.
+ *
+ * Note that the result might not be a valid marker code,
+ * but it will never be 0 or FF.
+ */
+
+LOCAL(boolean)
+next_marker (j_decompress_ptr cinfo)
+{
+ int c;
+ INPUT_VARS(cinfo);
+
+ for (;;) {
+ INPUT_BYTE(cinfo, c, return FALSE);
+ /* Skip any non-FF bytes.
+ * This may look a bit inefficient, but it will not occur in a valid file.
+ * We sync after each discarded byte so that a suspending data source
+ * can discard the byte from its buffer.
+ */
+ while (c != 0xFF) {
+ cinfo->marker->discarded_bytes++;
+ INPUT_SYNC(cinfo);
+ INPUT_BYTE(cinfo, c, return FALSE);
+ }
+ /* This loop swallows any duplicate FF bytes. Extra FFs are legal as
+ * pad bytes, so don't count them in discarded_bytes. We assume there
+ * will not be so many consecutive FF bytes as to overflow a suspending
+ * data source's input buffer.
+ */
+ do {
+ INPUT_BYTE(cinfo, c, return FALSE);
+ } while (c == 0xFF);
+ if (c != 0)
+ break; /* found a valid marker, exit loop */
+ /* Reach here if we found a stuffed-zero data sequence (FF/00).
+ * Discard it and loop back to try again.
+ */
+ cinfo->marker->discarded_bytes += 2;
+ INPUT_SYNC(cinfo);
+ }
+
+ if (cinfo->marker->discarded_bytes != 0) {
+ WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
+ cinfo->marker->discarded_bytes = 0;
+ }
+
+ cinfo->unread_marker = c;
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+LOCAL(boolean)
+first_marker (j_decompress_ptr cinfo)
+/* Like next_marker, but used to obtain the initial SOI marker. */
+/* For this marker, we do not allow preceding garbage or fill; otherwise,
+ * we might well scan an entire input file before realizing it ain't JPEG.
+ * If an application wants to process non-JFIF files, it must seek to the
+ * SOI before calling the JPEG library.
+ */
+{
+ int c, c2;
+ INPUT_VARS(cinfo);
+
+ INPUT_BYTE(cinfo, c, return FALSE);
+ INPUT_BYTE(cinfo, c2, return FALSE);
+ if (c != 0xFF || c2 != (int) M_SOI)
+ ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
+
+ cinfo->unread_marker = c2;
+
+ INPUT_SYNC(cinfo);
+ return TRUE;
+}
+
+
+/*
+ * Read markers until SOS or EOI.
+ *
+ * Returns same codes as are defined for jpeg_consume_input:
+ * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
+ */
+
+METHODDEF(int)
+read_markers (j_decompress_ptr cinfo)
+{
+ /* Outer loop repeats once for each marker. */
+ for (;;) {
+ /* Collect the marker proper, unless we already did. */
+ /* NB: first_marker() enforces the requirement that SOI appear first. */
+ if (cinfo->unread_marker == 0) {
+ if (! cinfo->marker->saw_SOI) {
+ if (! first_marker(cinfo))
+ return JPEG_SUSPENDED;
+ } else {
+ if (! next_marker(cinfo))
+ return JPEG_SUSPENDED;
+ }
+ }
+ /* At this point cinfo->unread_marker contains the marker code and the
+ * input point is just past the marker proper, but before any parameters.
+ * A suspension will cause us to return with this state still true.
+ */
+ switch (cinfo->unread_marker) {
+ case M_SOI:
+ if (! get_soi(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_SOF0: /* Baseline */
+ case M_SOF1: /* Extended sequential, Huffman */
+ if (! get_sof(cinfo, FALSE, FALSE))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_SOF2: /* Progressive, Huffman */
+ if (! get_sof(cinfo, TRUE, FALSE))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_SOF9: /* Extended sequential, arithmetic */
+ if (! get_sof(cinfo, FALSE, TRUE))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_SOF10: /* Progressive, arithmetic */
+ if (! get_sof(cinfo, TRUE, TRUE))
+ return JPEG_SUSPENDED;
+ break;
+
+ /* Currently unsupported SOFn types */
+ case M_SOF3: /* Lossless, Huffman */
+ case M_SOF5: /* Differential sequential, Huffman */
+ case M_SOF6: /* Differential progressive, Huffman */
+ case M_SOF7: /* Differential lossless, Huffman */
+ case M_JPG: /* Reserved for JPEG extensions */
+ case M_SOF11: /* Lossless, arithmetic */
+ case M_SOF13: /* Differential sequential, arithmetic */
+ case M_SOF14: /* Differential progressive, arithmetic */
+ case M_SOF15: /* Differential lossless, arithmetic */
+ ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
+ break;
+
+ case M_SOS:
+ if (! get_sos(cinfo))
+ return JPEG_SUSPENDED;
+ cinfo->unread_marker = 0; /* processed the marker */
+ return JPEG_REACHED_SOS;
+
+ case M_EOI:
+ TRACEMS(cinfo, 1, JTRC_EOI);
+ cinfo->unread_marker = 0; /* processed the marker */
+ return JPEG_REACHED_EOI;
+
+ case M_DAC:
+ if (! get_dac(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_DHT:
+ if (! get_dht(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_DQT:
+ if (! get_dqt(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_DRI:
+ if (! get_dri(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_APP0:
+ case M_APP1:
+ case M_APP2:
+ case M_APP3:
+ case M_APP4:
+ case M_APP5:
+ case M_APP6:
+ case M_APP7:
+ case M_APP8:
+ case M_APP9:
+ case M_APP10:
+ case M_APP11:
+ case M_APP12:
+ case M_APP13:
+ case M_APP14:
+ case M_APP15:
+ if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[
+ cinfo->unread_marker - (int) M_APP0]) (cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_COM:
+ if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ case M_RST0: /* these are all parameterless */
+ case M_RST1:
+ case M_RST2:
+ case M_RST3:
+ case M_RST4:
+ case M_RST5:
+ case M_RST6:
+ case M_RST7:
+ case M_TEM:
+ TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
+ break;
+
+ case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
+ if (! skip_variable(cinfo))
+ return JPEG_SUSPENDED;
+ break;
+
+ default: /* must be DHP, EXP, JPGn, or RESn */
+ /* For now, we treat the reserved markers as fatal errors since they are
+ * likely to be used to signal incompatible JPEG Part 3 extensions.
+ * Once the JPEG 3 version-number marker is well defined, this code
+ * ought to change!
+ */
+ ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
+ break;
+ }
+ /* Successfully processed marker, so reset state variable */
+ cinfo->unread_marker = 0;
+ } /* end loop */
+}
+
+
+/*
+ * Read a restart marker, which is expected to appear next in the datastream;
+ * if the marker is not there, take appropriate recovery action.
+ * Returns FALSE if suspension is required.
+ *
+ * This is called by the entropy decoder after it has read an appropriate
+ * number of MCUs. cinfo->unread_marker may be nonzero if the entropy decoder
+ * has already read a marker from the data source. Under normal conditions
+ * cinfo->unread_marker will be reset to 0 before returning; if not reset,
+ * it holds a marker which the decoder will be unable to read past.
+ */
+
+METHODDEF(boolean)
+read_restart_marker (j_decompress_ptr cinfo)
+{
+ /* Obtain a marker unless we already did. */
+ /* Note that next_marker will complain if it skips any data. */
+ if (cinfo->unread_marker == 0) {
+ if (! next_marker(cinfo))
+ return FALSE;
+ }
+
+ if (cinfo->unread_marker ==
+ ((int) M_RST0 + cinfo->marker->next_restart_num)) {
+ /* Normal case --- swallow the marker and let entropy decoder continue */
+ TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
+ cinfo->unread_marker = 0;
+ } else {
+ /* Uh-oh, the restart markers have been messed up. */
+ /* Let the data source manager determine how to resync. */
+ if (! (*cinfo->src->resync_to_restart) (cinfo,
+ cinfo->marker->next_restart_num))
+ return FALSE;
+ }
+
+ /* Update next-restart state */
+ cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
+
+ return TRUE;
+}
+
+
+/*
+ * This is the default resync_to_restart method for data source managers
+ * to use if they don't have any better approach. Some data source managers
+ * may be able to back up, or may have additional knowledge about the data
+ * which permits a more intelligent recovery strategy; such managers would
+ * presumably supply their own resync method.
+ *
+ * read_restart_marker calls resync_to_restart if it finds a marker other than
+ * the restart marker it was expecting. (This code is *not* used unless
+ * a nonzero restart interval has been declared.) cinfo->unread_marker is
+ * the marker code actually found (might be anything, except 0 or FF).
+ * The desired restart marker number (0..7) is passed as a parameter.
+ * This routine is supposed to apply whatever error recovery strategy seems
+ * appropriate in order to position the input stream to the next data segment.
+ * Note that cinfo->unread_marker is treated as a marker appearing before
+ * the current data-source input point; usually it should be reset to zero
+ * before returning.
+ * Returns FALSE if suspension is required.
+ *
+ * This implementation is substantially constrained by wanting to treat the
+ * input as a data stream; this means we can't back up. Therefore, we have
+ * only the following actions to work with:
+ * 1. Simply discard the marker and let the entropy decoder resume at next
+ * byte of file.
+ * 2. Read forward until we find another marker, discarding intervening
+ * data. (In theory we could look ahead within the current bufferload,
+ * without having to discard data if we don't find the desired marker.
+ * This idea is not implemented here, in part because it makes behavior
+ * dependent on buffer size and chance buffer-boundary positions.)
+ * 3. Leave the marker unread (by failing to zero cinfo->unread_marker).
+ * This will cause the entropy decoder to process an empty data segment,
+ * inserting dummy zeroes, and then we will reprocess the marker.
+ *
+ * #2 is appropriate if we think the desired marker lies ahead, while #3 is
+ * appropriate if the found marker is a future restart marker (indicating
+ * that we have missed the desired restart marker, probably because it got
+ * corrupted).
+ * We apply #2 or #3 if the found marker is a restart marker no more than
+ * two counts behind or ahead of the expected one. We also apply #2 if the
+ * found marker is not a legal JPEG marker code (it's certainly bogus data).
+ * If the found marker is a restart marker more than 2 counts away, we do #1
+ * (too much risk that the marker is erroneous; with luck we will be able to
+ * resync at some future point).
+ * For any valid non-restart JPEG marker, we apply #3. This keeps us from
+ * overrunning the end of a scan. An implementation limited to single-scan
+ * files might find it better to apply #2 for markers other than EOI, since
+ * any other marker would have to be bogus data in that case.
+ */
+
+GLOBAL(boolean)
+jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
+{
+ int marker = cinfo->unread_marker;
+ int action = 1;
+
+ /* Always put up a warning. */
+ WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
+
+ /* Outer loop handles repeated decision after scanning forward. */
+ for (;;) {
+ if (marker < (int) M_SOF0)
+ action = 2; /* invalid marker */
+ else if (marker < (int) M_RST0 || marker > (int) M_RST7)
+ action = 3; /* valid non-restart marker */
+ else {
+ if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
+ marker == ((int) M_RST0 + ((desired+2) & 7)))
+ action = 3; /* one of the next two expected restarts */
+ else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
+ marker == ((int) M_RST0 + ((desired-2) & 7)))
+ action = 2; /* a prior restart, so advance */
+ else
+ action = 1; /* desired restart or too far away */
+ }
+ TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
+ switch (action) {
+ case 1:
+ /* Discard marker and let entropy decoder resume processing. */
+ cinfo->unread_marker = 0;
+ return TRUE;
+ case 2:
+ /* Scan to the next marker, and repeat the decision loop. */
+ if (! next_marker(cinfo))
+ return FALSE;
+ marker = cinfo->unread_marker;
+ break;
+ case 3:
+ /* Return without advancing past this marker. */
+ /* Entropy decoder will be forced to process an empty segment. */
+ return TRUE;
+ }
+ } /* end loop */
+}
+
+
+/*
+ * Reset marker processing state to begin a fresh datastream.
+ */
+
+METHODDEF(void)
+reset_marker_reader (j_decompress_ptr cinfo)
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+
+ cinfo->comp_info = NULL; /* until allocated by get_sof */
+ cinfo->input_scan_number = 0; /* no SOS seen yet */
+ cinfo->unread_marker = 0; /* no pending marker */
+ marker->pub.saw_SOI = FALSE; /* set internal state too */
+ marker->pub.saw_SOF = FALSE;
+ marker->pub.discarded_bytes = 0;
+ marker->cur_marker = NULL;
+}
+
+
+/*
+ * Initialize the marker reader module.
+ * This is called only once, when the decompression object is created.
+ */
+
+GLOBAL(void)
+jinit_marker_reader (j_decompress_ptr cinfo)
+{
+ my_marker_ptr marker;
+ int i;
+
+ /* Create subobject in permanent pool */
+ marker = (my_marker_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_marker_reader));
+ cinfo->marker = (struct jpeg_marker_reader *) marker;
+ /* Initialize public method pointers */
+ marker->pub.reset_marker_reader = reset_marker_reader;
+ marker->pub.read_markers = read_markers;
+ marker->pub.read_restart_marker = read_restart_marker;
+ /* Initialize COM/APPn processing.
+ * By default, we examine and then discard APP0 and APP14,
+ * but simply discard COM and all other APPn.
+ */
+ marker->process_COM = skip_variable;
+ marker->length_limit_COM = 0;
+ for (i = 0; i < 16; i++) {
+ marker->process_APPn[i] = skip_variable;
+ marker->length_limit_APPn[i] = 0;
+ }
+ marker->process_APPn[0] = get_interesting_appn;
+ marker->process_APPn[14] = get_interesting_appn;
+ /* Reset marker processing state */
+ reset_marker_reader(cinfo);
+}
+
+
+/*
+ * Control saving of COM and APPn markers into marker_list.
+ */
+
+#ifdef SAVE_MARKERS_SUPPORTED
+
+GLOBAL(void)
+jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
+ unsigned int length_limit)
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+ long maxlength;
+ jpeg_marker_parser_method processor;
+
+ /* Length limit mustn't be larger than what we can allocate
+ * (should only be a concern in a 16-bit environment).
+ */
+ maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
+ if (((long) length_limit) > maxlength)
+ length_limit = (unsigned int) maxlength;
+
+ /* Choose processor routine to use.
+ * APP0/APP14 have special requirements.
+ */
+ if (length_limit) {
+ processor = save_marker;
+ /* If saving APP0/APP14, save at least enough for our internal use. */
+ if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
+ length_limit = APP0_DATA_LEN;
+ else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
+ length_limit = APP14_DATA_LEN;
+ } else {
+ processor = skip_variable;
+ /* If discarding APP0/APP14, use our regular on-the-fly processor. */
+ if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
+ processor = get_interesting_appn;
+ }
+
+ if (marker_code == (int) M_COM) {
+ marker->process_COM = processor;
+ marker->length_limit_COM = length_limit;
+ } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
+ marker->process_APPn[marker_code - (int) M_APP0] = processor;
+ marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
+ } else
+ ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
+}
+
+#endif /* SAVE_MARKERS_SUPPORTED */
+
+
+/*
+ * Install a special processing method for COM or APPn markers.
+ */
+
+GLOBAL(void)
+jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
+ jpeg_marker_parser_method routine)
+{
+ my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
+
+ if (marker_code == (int) M_COM)
+ marker->process_COM = routine;
+ else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
+ marker->process_APPn[marker_code - (int) M_APP0] = routine;
+ else
+ ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
+}
diff --git a/osframework/source/ImageLib/jpeg/jdmaster.c b/osframework/source/ImageLib/jpeg/jdmaster.c
new file mode 100644
index 0000000..eda4b3f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdmaster.c
@@ -0,0 +1,557 @@
+/*
+ * jdmaster.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains master control logic for the JPEG decompressor.
+ * These routines are concerned with selecting the modules to be executed
+ * and with determining the number of passes and the work to be done in each
+ * pass.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private state */
+
+typedef struct {
+ struct jpeg_decomp_master pub; /* public fields */
+
+ int pass_number; /* # of passes completed */
+
+ boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
+
+ /* Saved references to initialized quantizer modules,
+ * in case we need to switch modes.
+ */
+ struct jpeg_color_quantizer * quantizer_1pass;
+ struct jpeg_color_quantizer * quantizer_2pass;
+} my_decomp_master;
+
+typedef my_decomp_master * my_master_ptr;
+
+
+/*
+ * Determine whether merged upsample/color conversion should be used.
+ * CRUCIAL: this must match the actual capabilities of jdmerge.c!
+ */
+
+LOCAL(boolean)
+use_merged_upsample (j_decompress_ptr cinfo)
+{
+#ifdef UPSAMPLE_MERGING_SUPPORTED
+ /* Merging is the equivalent of plain box-filter upsampling */
+ if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
+ return FALSE;
+ /* jdmerge.c only supports YCC=>RGB color conversion */
+ if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
+ cinfo->out_color_space != JCS_RGB ||
+ cinfo->out_color_components != RGB_PIXELSIZE)
+ return FALSE;
+ /* and it only handles 2h1v or 2h2v sampling ratios */
+ if (cinfo->comp_info[0].h_samp_factor != 2 ||
+ cinfo->comp_info[1].h_samp_factor != 1 ||
+ cinfo->comp_info[2].h_samp_factor != 1 ||
+ cinfo->comp_info[0].v_samp_factor > 2 ||
+ cinfo->comp_info[1].v_samp_factor != 1 ||
+ cinfo->comp_info[2].v_samp_factor != 1)
+ return FALSE;
+ /* furthermore, it doesn't work if we've scaled the IDCTs differently */
+ if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
+ cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
+ cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
+ return FALSE;
+ /* ??? also need to test for upsample-time rescaling, when & if supported */
+ return TRUE; /* by golly, it'll work... */
+#else
+ return FALSE;
+#endif
+}
+
+
+/*
+ * Compute output image dimensions and related values.
+ * NOTE: this is exported for possible use by application.
+ * Hence it mustn't do anything that can't be done twice.
+ * Also note that it may be called before the master module is initialized!
+ */
+
+GLOBAL(void)
+jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
+/* Do computations that are needed before master selection phase */
+{
+#ifdef IDCT_SCALING_SUPPORTED
+ int ci;
+ jpeg_component_info *compptr;
+#endif
+
+ /* Prevent application from calling me at wrong times */
+ if (cinfo->global_state != DSTATE_READY)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+#ifdef IDCT_SCALING_SUPPORTED
+
+ /* Compute actual output image dimensions and DCT scaling choices. */
+ if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
+ /* Provide 1/8 scaling */
+ cinfo->output_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width, 8L);
+ cinfo->output_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height, 8L);
+ cinfo->min_DCT_scaled_size = 1;
+ } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
+ /* Provide 1/4 scaling */
+ cinfo->output_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width, 4L);
+ cinfo->output_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height, 4L);
+ cinfo->min_DCT_scaled_size = 2;
+ } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
+ /* Provide 1/2 scaling */
+ cinfo->output_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width, 2L);
+ cinfo->output_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height, 2L);
+ cinfo->min_DCT_scaled_size = 4;
+ } else {
+ /* Provide 1/1 scaling */
+ cinfo->output_width = cinfo->image_width;
+ cinfo->output_height = cinfo->image_height;
+ cinfo->min_DCT_scaled_size = DCTSIZE;
+ }
+ /* In selecting the actual DCT scaling for each component, we try to
+ * scale up the chroma components via IDCT scaling rather than upsampling.
+ * This saves time if the upsampler gets to use 1:1 scaling.
+ * Note this code assumes that the supported DCT scalings are powers of 2.
+ */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ int ssize = cinfo->min_DCT_scaled_size;
+ while (ssize < DCTSIZE &&
+ (compptr->h_samp_factor * ssize * 2 <=
+ cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
+ (compptr->v_samp_factor * ssize * 2 <=
+ cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
+ ssize = ssize * 2;
+ }
+ compptr->DCT_scaled_size = ssize;
+ }
+
+ /* Recompute downsampled dimensions of components;
+ * application needs to know these if using raw downsampled data.
+ */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Size in samples, after IDCT scaling */
+ compptr->downsampled_width = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_width *
+ (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
+ (long) (cinfo->max_h_samp_factor * DCTSIZE));
+ compptr->downsampled_height = (JDIMENSION)
+ jdiv_round_up((long) cinfo->image_height *
+ (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
+ (long) (cinfo->max_v_samp_factor * DCTSIZE));
+ }
+
+#else /* !IDCT_SCALING_SUPPORTED */
+
+ /* Hardwire it to "no scaling" */
+ cinfo->output_width = cinfo->image_width;
+ cinfo->output_height = cinfo->image_height;
+ /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
+ * and has computed unscaled downsampled_width and downsampled_height.
+ */
+
+#endif /* IDCT_SCALING_SUPPORTED */
+
+ /* Report number of components in selected colorspace. */
+ /* Probably this should be in the color conversion module... */
+ switch (cinfo->out_color_space) {
+ case JCS_GRAYSCALE:
+ cinfo->out_color_components = 1;
+ break;
+ case JCS_RGB:
+#if RGB_PIXELSIZE != 3
+ cinfo->out_color_components = RGB_PIXELSIZE;
+ break;
+#endif /* else share code with YCbCr */
+ case JCS_YCbCr:
+ cinfo->out_color_components = 3;
+ break;
+ case JCS_CMYK:
+ case JCS_YCCK:
+ cinfo->out_color_components = 4;
+ break;
+ default: /* else must be same colorspace as in file */
+ cinfo->out_color_components = cinfo->num_components;
+ break;
+ }
+ cinfo->output_components = (cinfo->quantize_colors ? 1 :
+ cinfo->out_color_components);
+
+ /* See if upsampler will want to emit more than one row at a time */
+ if (use_merged_upsample(cinfo))
+ cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
+ else
+ cinfo->rec_outbuf_height = 1;
+}
+
+
+/*
+ * Several decompression processes need to range-limit values to the range
+ * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
+ * due to noise introduced by quantization, roundoff error, etc. These
+ * processes are inner loops and need to be as fast as possible. On most
+ * machines, particularly CPUs with pipelines or instruction prefetch,
+ * a (subscript-check-less) C table lookup
+ * x = sample_range_limit[x];
+ * is faster than explicit tests
+ * if (x < 0) x = 0;
+ * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
+ * These processes all use a common table prepared by the routine below.
+ *
+ * For most steps we can mathematically guarantee that the initial value
+ * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
+ * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
+ * limiting step (just after the IDCT), a wildly out-of-range value is
+ * possible if the input data is corrupt. To avoid any chance of indexing
+ * off the end of memory and getting a bad-pointer trap, we perform the
+ * post-IDCT limiting thus:
+ * x = range_limit[x & MASK];
+ * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
+ * samples. Under normal circumstances this is more than enough range and
+ * a correct output will be generated; with bogus input data the mask will
+ * cause wraparound, and we will safely generate a bogus-but-in-range output.
+ * For the post-IDCT step, we want to convert the data from signed to unsigned
+ * representation by adding CENTERJSAMPLE at the same time that we limit it.
+ * So the post-IDCT limiting table ends up looking like this:
+ * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
+ * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
+ * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
+ * 0,1,...,CENTERJSAMPLE-1
+ * Negative inputs select values from the upper half of the table after
+ * masking.
+ *
+ * We can save some space by overlapping the start of the post-IDCT table
+ * with the simpler range limiting table. The post-IDCT table begins at
+ * sample_range_limit + CENTERJSAMPLE.
+ *
+ * Note that the table is allocated in near data space on PCs; it's small
+ * enough and used often enough to justify this.
+ */
+
+LOCAL(void)
+prepare_range_limit_table (j_decompress_ptr cinfo)
+/* Allocate and fill in the sample_range_limit table */
+{
+ JSAMPLE * table;
+ int i;
+
+ table = (JSAMPLE *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
+ table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
+ cinfo->sample_range_limit = table;
+ /* First segment of "simple" table: limit[x] = 0 for x < 0 */
+ MEMZERO(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 */
+ MEMZERO(table + (2 * (MAXJSAMPLE+1)),
+ (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
+ MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
+ cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
+}
+
+
+/*
+ * Master selection of decompression modules.
+ * This is done once at jpeg_start_decompress time. We determine
+ * which modules will be used and give them appropriate initialization calls.
+ * We also initialize the decompressor input side to begin consuming data.
+ *
+ * Since jpeg_read_header has finished, we know what is in the SOF
+ * and (first) SOS markers. We also have all the application parameter
+ * settings.
+ */
+
+LOCAL(void)
+master_selection (j_decompress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+ boolean use_c_buffer;
+ long samplesperrow;
+ JDIMENSION jd_samplesperrow;
+
+ /* Initialize dimensions and other stuff */
+ jpeg_calc_output_dimensions(cinfo);
+ prepare_range_limit_table(cinfo);
+
+ /* Width of an output scanline must be representable as JDIMENSION. */
+ samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
+ jd_samplesperrow = (JDIMENSION) samplesperrow;
+ if ((long) jd_samplesperrow != samplesperrow)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+
+ /* Initialize my private state */
+ master->pass_number = 0;
+ master->using_merged_upsample = use_merged_upsample(cinfo);
+
+ /* Color quantizer selection */
+ master->quantizer_1pass = NULL;
+ master->quantizer_2pass = NULL;
+ /* No mode changes if not using buffered-image mode. */
+ if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
+ cinfo->enable_1pass_quant = FALSE;
+ cinfo->enable_external_quant = FALSE;
+ cinfo->enable_2pass_quant = FALSE;
+ }
+ if (cinfo->quantize_colors) {
+ if (cinfo->raw_data_out)
+ ERREXIT(cinfo, JERR_NOTIMPL);
+ /* 2-pass quantizer only works in 3-component color space. */
+ if (cinfo->out_color_components != 3) {
+ cinfo->enable_1pass_quant = TRUE;
+ cinfo->enable_external_quant = FALSE;
+ cinfo->enable_2pass_quant = FALSE;
+ cinfo->colormap = NULL;
+ } else if (cinfo->colormap != NULL) {
+ cinfo->enable_external_quant = TRUE;
+ } else if (cinfo->two_pass_quantize) {
+ cinfo->enable_2pass_quant = TRUE;
+ } else {
+ cinfo->enable_1pass_quant = TRUE;
+ }
+
+ if (cinfo->enable_1pass_quant) {
+#ifdef QUANT_1PASS_SUPPORTED
+ jinit_1pass_quantizer(cinfo);
+ master->quantizer_1pass = cinfo->cquantize;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ }
+
+ /* We use the 2-pass code to map to external colormaps. */
+ if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
+#ifdef QUANT_2PASS_SUPPORTED
+ jinit_2pass_quantizer(cinfo);
+ master->quantizer_2pass = cinfo->cquantize;
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ }
+ /* If both quantizers are initialized, the 2-pass one is left active;
+ * this is necessary for starting with quantization to an external map.
+ */
+ }
+
+ /* Post-processing: in particular, color conversion first */
+ if (! cinfo->raw_data_out) {
+ if (master->using_merged_upsample) {
+#ifdef UPSAMPLE_MERGING_SUPPORTED
+ jinit_merged_upsampler(cinfo); /* does color conversion too */
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else {
+ jinit_color_deconverter(cinfo);
+ jinit_upsampler(cinfo);
+ }
+ jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
+ }
+ /* Inverse DCT */
+ jinit_inverse_dct(cinfo);
+ /* Entropy decoding: either Huffman or arithmetic coding. */
+ if (cinfo->arith_code) {
+ ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
+ } else {
+ if (cinfo->progressive_mode) {
+#ifdef D_PROGRESSIVE_SUPPORTED
+ jinit_phuff_decoder(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else
+ jinit_huff_decoder(cinfo);
+ }
+
+ /* Initialize principal buffer controllers. */
+ use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
+ jinit_d_coef_controller(cinfo, use_c_buffer);
+
+ if (! cinfo->raw_data_out)
+ jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
+
+ /* We can now tell the memory manager to allocate virtual arrays. */
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
+
+ /* Initialize input side of decompressor to consume first scan. */
+ (*cinfo->inputctl->start_input_pass) (cinfo);
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+ /* If jpeg_start_decompress will read the whole file, initialize
+ * progress monitoring appropriately. The input step is counted
+ * as one pass.
+ */
+ if (cinfo->progress != NULL && ! cinfo->buffered_image &&
+ cinfo->inputctl->has_multiple_scans) {
+ int nscans;
+ /* Estimate number of scans to set pass_limit. */
+ if (cinfo->progressive_mode) {
+ /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
+ nscans = 2 + 3 * cinfo->num_components;
+ } else {
+ /* For a nonprogressive multiscan file, estimate 1 scan per component. */
+ nscans = cinfo->num_components;
+ }
+ cinfo->progress->pass_counter = 0L;
+ cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
+ cinfo->progress->completed_passes = 0;
+ cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
+ /* Count the input pass as done */
+ master->pass_number++;
+ }
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+}
+
+
+/*
+ * Per-pass setup.
+ * This is called at the beginning of each output pass. We determine which
+ * modules will be active during this pass and give them appropriate
+ * start_pass calls. We also set is_dummy_pass to indicate whether this
+ * is a "real" output pass or a dummy pass for color quantization.
+ * (In the latter case, jdapistd.c will crank the pass to completion.)
+ */
+
+METHODDEF(void)
+prepare_for_output_pass (j_decompress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+
+ if (master->pub.is_dummy_pass) {
+#ifdef QUANT_2PASS_SUPPORTED
+ /* Final pass of 2-pass quantization */
+ master->pub.is_dummy_pass = FALSE;
+ (*cinfo->cquantize->start_pass) (cinfo, FALSE);
+ (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
+ (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif /* QUANT_2PASS_SUPPORTED */
+ } else {
+ if (cinfo->quantize_colors && cinfo->colormap == NULL) {
+ /* Select new quantization method */
+ if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
+ cinfo->cquantize = master->quantizer_2pass;
+ master->pub.is_dummy_pass = TRUE;
+ } else if (cinfo->enable_1pass_quant) {
+ cinfo->cquantize = master->quantizer_1pass;
+ } else {
+ ERREXIT(cinfo, JERR_MODE_CHANGE);
+ }
+ }
+ (*cinfo->idct->start_pass) (cinfo);
+ (*cinfo->coef->start_output_pass) (cinfo);
+ if (! cinfo->raw_data_out) {
+ if (! master->using_merged_upsample)
+ (*cinfo->cconvert->start_pass) (cinfo);
+ (*cinfo->upsample->start_pass) (cinfo);
+ if (cinfo->quantize_colors)
+ (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
+ (*cinfo->post->start_pass) (cinfo,
+ (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
+ (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
+ }
+ }
+
+ /* Set up progress monitor's pass info if present */
+ if (cinfo->progress != NULL) {
+ cinfo->progress->completed_passes = master->pass_number;
+ cinfo->progress->total_passes = master->pass_number +
+ (master->pub.is_dummy_pass ? 2 : 1);
+ /* In buffered-image mode, we assume one more output pass if EOI not
+ * yet reached, but no more passes if EOI has been reached.
+ */
+ if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
+ cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
+ }
+ }
+}
+
+
+/*
+ * Finish up at end of an output pass.
+ */
+
+METHODDEF(void)
+finish_output_pass (j_decompress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+
+ if (cinfo->quantize_colors)
+ (*cinfo->cquantize->finish_pass) (cinfo);
+ master->pass_number++;
+}
+
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+/*
+ * Switch to a new external colormap between output passes.
+ */
+
+GLOBAL(void)
+jpeg_new_colormap (j_decompress_ptr cinfo)
+{
+ my_master_ptr master = (my_master_ptr) cinfo->master;
+
+ /* Prevent application from calling me at wrong times */
+ if (cinfo->global_state != DSTATE_BUFIMAGE)
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ if (cinfo->quantize_colors && cinfo->enable_external_quant &&
+ cinfo->colormap != NULL) {
+ /* Select 2-pass quantizer for external colormap use */
+ cinfo->cquantize = master->quantizer_2pass;
+ /* Notify quantizer of colormap change */
+ (*cinfo->cquantize->new_color_map) (cinfo);
+ master->pub.is_dummy_pass = FALSE; /* just in case */
+ } else
+ ERREXIT(cinfo, JERR_MODE_CHANGE);
+}
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+
+
+/*
+ * Initialize master decompression control and select active modules.
+ * This is performed at the start of jpeg_start_decompress.
+ */
+
+GLOBAL(void)
+jinit_master_decompress (j_decompress_ptr cinfo)
+{
+ my_master_ptr master;
+
+ master = (my_master_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_decomp_master));
+ cinfo->master = (struct jpeg_decomp_master *) master;
+ master->pub.prepare_for_output_pass = prepare_for_output_pass;
+ master->pub.finish_output_pass = finish_output_pass;
+
+ master->pub.is_dummy_pass = FALSE;
+
+ master_selection(cinfo);
+}
diff --git a/osframework/source/ImageLib/jpeg/jdmerge.c b/osframework/source/ImageLib/jpeg/jdmerge.c
new file mode 100644
index 0000000..9e3a595
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdmerge.c
@@ -0,0 +1,400 @@
+/*
+ * jdmerge.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains code for merged upsampling/color conversion.
+ *
+ * This file combines functions from jdsample.c and jdcolor.c;
+ * read those files first to understand what's going on.
+ *
+ * When the chroma components are to be upsampled by simple replication
+ * (ie, box filtering), we can save some work in color conversion by
+ * calculating all the output pixels corresponding to a pair of chroma
+ * samples at one time. In the conversion equations
+ * R = Y + K1 * Cr
+ * G = Y + K2 * Cb + K3 * Cr
+ * B = Y + K4 * Cb
+ * only the Y term varies among the group of pixels corresponding to a pair
+ * of chroma samples, so the rest of the terms can be calculated just once.
+ * At typical sampling ratios, this eliminates half or three-quarters of the
+ * multiplications needed for color conversion.
+ *
+ * This file currently provides implementations for the following cases:
+ * YCbCr => RGB color conversion only.
+ * Sampling ratios of 2h1v or 2h2v.
+ * No scaling needed at upsample time.
+ * Corner-aligned (non-CCIR601) sampling alignment.
+ * Other special cases could be added, but in most applications these are
+ * the only common cases. (For uncommon cases we fall back on the more
+ * general code in jdsample.c and jdcolor.c.)
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+#ifdef UPSAMPLE_MERGING_SUPPORTED
+
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_upsampler pub; /* public fields */
+
+ /* Pointer to routine to do actual upsampling/conversion of one row group */
+ JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
+ JSAMPARRAY output_buf));
+
+ /* Private state for YCC->RGB conversion */
+ int * Cr_r_tab; /* => table for Cr to R conversion */
+ int * Cb_b_tab; /* => table for Cb to B conversion */
+ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
+ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
+
+ /* For 2:1 vertical sampling, we produce two output rows at a time.
+ * We need a "spare" row buffer to hold the second output row if the
+ * application provides just a one-row buffer; we also use the spare
+ * to discard the dummy last row if the image height is odd.
+ */
+ JSAMPROW spare_row;
+ boolean spare_full; /* T if spare buffer is occupied */
+
+ JDIMENSION out_row_width; /* samples per output row */
+ JDIMENSION rows_to_go; /* counts rows remaining in image */
+} my_upsampler;
+
+typedef my_upsampler * my_upsample_ptr;
+
+#define SCALEBITS 16 /* speediest right-shift on some machines */
+#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
+#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
+
+
+/*
+ * Initialize tables for YCC->RGB colorspace conversion.
+ * This is taken directly from jdcolor.c; see that file for more info.
+ */
+
+LOCAL(void)
+build_ycc_rgb_table (j_decompress_ptr cinfo)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ int i;
+ INT32 x;
+ SHIFT_TEMPS
+
+ upsample->Cr_r_tab = (int *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(int));
+ upsample->Cb_b_tab = (int *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(int));
+ upsample->Cr_g_tab = (INT32 *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
+ upsample->Cb_g_tab = (INT32 *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (MAXJSAMPLE+1) * SIZEOF(INT32));
+
+ for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
+ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
+ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
+ /* Cr=>R value is nearest int to 1.40200 * x */
+ upsample->Cr_r_tab[i] = (int)
+ RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
+ /* Cb=>B value is nearest int to 1.77200 * x */
+ upsample->Cb_b_tab[i] = (int)
+ RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
+ /* Cr=>G value is scaled-up -0.71414 * x */
+ upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
+ /* Cb=>G value is scaled-up -0.34414 * x */
+ /* We also add in ONE_HALF so that need not do it in inner loop */
+ upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
+ }
+}
+
+
+/*
+ * Initialize for an upsampling pass.
+ */
+
+METHODDEF(void)
+start_pass_merged_upsample (j_decompress_ptr cinfo)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+
+ /* Mark the spare buffer empty */
+ upsample->spare_full = FALSE;
+ /* Initialize total-height counter for detecting bottom of image */
+ upsample->rows_to_go = cinfo->output_height;
+}
+
+
+/*
+ * Control routine to do upsampling (and color conversion).
+ *
+ * The control routine just handles the row buffering considerations.
+ */
+
+METHODDEF(void)
+merged_2v_upsample (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+/* 2:1 vertical sampling case: may need a spare row. */
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ JSAMPROW work_ptrs[2];
+ JDIMENSION num_rows; /* number of rows returned to caller */
+
+ if (upsample->spare_full) {
+ /* If we have a spare row saved from a previous cycle, just return it. */
+ jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
+ 1, upsample->out_row_width);
+ num_rows = 1;
+ upsample->spare_full = FALSE;
+ } else {
+ /* Figure number of rows to return to caller. */
+ num_rows = 2;
+ /* Not more than the distance to the end of the image. */
+ if (num_rows > upsample->rows_to_go)
+ num_rows = upsample->rows_to_go;
+ /* And not more than what the client can accept: */
+ out_rows_avail -= *out_row_ctr;
+ if (num_rows > out_rows_avail)
+ num_rows = out_rows_avail;
+ /* Create output pointer array for upsampler. */
+ work_ptrs[0] = output_buf[*out_row_ctr];
+ if (num_rows > 1) {
+ work_ptrs[1] = output_buf[*out_row_ctr + 1];
+ } else {
+ work_ptrs[1] = upsample->spare_row;
+ upsample->spare_full = TRUE;
+ }
+ /* Now do the upsampling. */
+ (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
+ }
+
+ /* Adjust counts */
+ *out_row_ctr += num_rows;
+ upsample->rows_to_go -= num_rows;
+ /* When the buffer is emptied, declare this input row group consumed */
+ if (! upsample->spare_full)
+ (*in_row_group_ctr)++;
+}
+
+
+METHODDEF(void)
+merged_1v_upsample (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+/* 1:1 vertical sampling case: much easier, never need a spare row. */
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+
+ /* Just do the upsampling. */
+ (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
+ output_buf + *out_row_ctr);
+ /* Adjust counts */
+ (*out_row_ctr)++;
+ (*in_row_group_ctr)++;
+}
+
+
+/*
+ * These are the routines invoked by the control routines to do
+ * the actual upsampling/conversion. One row group is processed per call.
+ *
+ * Note: since we may be writing directly into application-supplied buffers,
+ * we have to be honest about the output width; we can't assume the buffer
+ * has been rounded up to an even width.
+ */
+
+
+/*
+ * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
+ */
+
+METHODDEF(void)
+h2v1_merged_upsample (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
+ JSAMPARRAY output_buf)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ register int y, cred, cgreen, cblue;
+ int cb, cr;
+ register JSAMPROW outptr;
+ JSAMPROW inptr0, inptr1, inptr2;
+ JDIMENSION col;
+ /* copy these pointers into registers if possible */
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
+ int * Crrtab = upsample->Cr_r_tab;
+ int * Cbbtab = upsample->Cb_b_tab;
+ INT32 * Crgtab = upsample->Cr_g_tab;
+ INT32 * Cbgtab = upsample->Cb_g_tab;
+ SHIFT_TEMPS
+
+ inptr0 = input_buf[0][in_row_group_ctr];
+ inptr1 = input_buf[1][in_row_group_ctr];
+ inptr2 = input_buf[2][in_row_group_ctr];
+ outptr = output_buf[0];
+ /* Loop for each pair of output pixels */
+ for (col = cinfo->output_width >> 1; col > 0; col--) {
+ /* Do the chroma part of the calculation */
+ cb = GETJSAMPLE(*inptr1++);
+ cr = GETJSAMPLE(*inptr2++);
+ cred = Crrtab[cr];
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
+ cblue = Cbbtab[cb];
+ /* Fetch 2 Y values and emit 2 pixels */
+ y = GETJSAMPLE(*inptr0++);
+ outptr[RGB_RED] = range_limit[y + cred];
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
+ outptr[RGB_BLUE] = range_limit[y + cblue];
+ outptr += RGB_PIXELSIZE;
+ y = GETJSAMPLE(*inptr0++);
+ outptr[RGB_RED] = range_limit[y + cred];
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
+ outptr[RGB_BLUE] = range_limit[y + cblue];
+ outptr += RGB_PIXELSIZE;
+ }
+ /* If image width is odd, do the last output column separately */
+ if (cinfo->output_width & 1) {
+ cb = GETJSAMPLE(*inptr1);
+ cr = GETJSAMPLE(*inptr2);
+ cred = Crrtab[cr];
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
+ cblue = Cbbtab[cb];
+ y = GETJSAMPLE(*inptr0);
+ outptr[RGB_RED] = range_limit[y + cred];
+ outptr[RGB_GREEN] = range_limit[y + cgreen];
+ outptr[RGB_BLUE] = range_limit[y + cblue];
+ }
+}
+
+
+/*
+ * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
+ */
+
+METHODDEF(void)
+h2v2_merged_upsample (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
+ JSAMPARRAY output_buf)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ register int y, cred, cgreen, cblue;
+ int cb, cr;
+ register JSAMPROW outptr0, outptr1;
+ JSAMPROW inptr00, inptr01, inptr1, inptr2;
+ JDIMENSION col;
+ /* copy these pointers into registers if possible */
+ register JSAMPLE * range_limit = cinfo->sample_range_limit;
+ int * Crrtab = upsample->Cr_r_tab;
+ int * Cbbtab = upsample->Cb_b_tab;
+ INT32 * Crgtab = upsample->Cr_g_tab;
+ INT32 * Cbgtab = upsample->Cb_g_tab;
+ SHIFT_TEMPS
+
+ inptr00 = input_buf[0][in_row_group_ctr*2];
+ inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
+ inptr1 = input_buf[1][in_row_group_ctr];
+ inptr2 = input_buf[2][in_row_group_ctr];
+ outptr0 = output_buf[0];
+ outptr1 = output_buf[1];
+ /* Loop for each group of output pixels */
+ for (col = cinfo->output_width >> 1; col > 0; col--) {
+ /* Do the chroma part of the calculation */
+ cb = GETJSAMPLE(*inptr1++);
+ cr = GETJSAMPLE(*inptr2++);
+ cred = Crrtab[cr];
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
+ cblue = Cbbtab[cb];
+ /* Fetch 4 Y values and emit 4 pixels */
+ y = GETJSAMPLE(*inptr00++);
+ outptr0[RGB_RED] = range_limit[y + cred];
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
+ outptr0 += RGB_PIXELSIZE;
+ y = GETJSAMPLE(*inptr00++);
+ outptr0[RGB_RED] = range_limit[y + cred];
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
+ outptr0 += RGB_PIXELSIZE;
+ y = GETJSAMPLE(*inptr01++);
+ outptr1[RGB_RED] = range_limit[y + cred];
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
+ outptr1 += RGB_PIXELSIZE;
+ y = GETJSAMPLE(*inptr01++);
+ outptr1[RGB_RED] = range_limit[y + cred];
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
+ outptr1 += RGB_PIXELSIZE;
+ }
+ /* If image width is odd, do the last output column separately */
+ if (cinfo->output_width & 1) {
+ cb = GETJSAMPLE(*inptr1);
+ cr = GETJSAMPLE(*inptr2);
+ cred = Crrtab[cr];
+ cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
+ cblue = Cbbtab[cb];
+ y = GETJSAMPLE(*inptr00);
+ outptr0[RGB_RED] = range_limit[y + cred];
+ outptr0[RGB_GREEN] = range_limit[y + cgreen];
+ outptr0[RGB_BLUE] = range_limit[y + cblue];
+ y = GETJSAMPLE(*inptr01);
+ outptr1[RGB_RED] = range_limit[y + cred];
+ outptr1[RGB_GREEN] = range_limit[y + cgreen];
+ outptr1[RGB_BLUE] = range_limit[y + cblue];
+ }
+}
+
+
+/*
+ * Module initialization routine for merged upsampling/color conversion.
+ *
+ * NB: this is called under the conditions determined by use_merged_upsample()
+ * in jdmaster.c. That routine MUST correspond to the actual capabilities
+ * of this module; no safety checks are made here.
+ */
+
+GLOBAL(void)
+jinit_merged_upsampler (j_decompress_ptr cinfo)
+{
+ my_upsample_ptr upsample;
+
+ upsample = (my_upsample_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_upsampler));
+ cinfo->upsample = (struct jpeg_upsampler *) upsample;
+ upsample->pub.start_pass = start_pass_merged_upsample;
+ upsample->pub.need_context_rows = FALSE;
+
+ upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
+
+ if (cinfo->max_v_samp_factor == 2) {
+ upsample->pub.upsample = merged_2v_upsample;
+ upsample->upmethod = h2v2_merged_upsample;
+ /* Allocate a spare row buffer */
+ upsample->spare_row = (JSAMPROW)
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
+ } else {
+ upsample->pub.upsample = merged_1v_upsample;
+ upsample->upmethod = h2v1_merged_upsample;
+ /* No spare row needed */
+ upsample->spare_row = NULL;
+ }
+
+ build_ycc_rgb_table(cinfo);
+}
+
+#endif /* UPSAMPLE_MERGING_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jdphuff.c b/osframework/source/ImageLib/jpeg/jdphuff.c
new file mode 100644
index 0000000..2404743
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdphuff.c
@@ -0,0 +1,668 @@
+/*
+ * jdphuff.c
+ *
+ * Copyright (C) 1995-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains Huffman entropy decoding routines for progressive JPEG.
+ *
+ * Much of the complexity here has to do with supporting input suspension.
+ * If the data source module demands suspension, we want to be able to back
+ * up to the start of the current MCU. To do this, we copy state variables
+ * into local working storage, and update them back to the permanent
+ * storage only upon successful completion of an MCU.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdhuff.h" /* Declarations shared with jdhuff.c */
+
+
+#ifdef D_PROGRESSIVE_SUPPORTED
+
+/*
+ * Expanded entropy decoder object for progressive Huffman decoding.
+ *
+ * The savable_state subrecord contains fields that change within an MCU,
+ * but must not be updated permanently until we complete the MCU.
+ */
+
+typedef struct {
+ unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
+} savable_state;
+
+/* This macro is to work around compilers with missing or broken
+ * structure assignment. You'll need to fix this code if you have
+ * such a compiler and you change MAX_COMPS_IN_SCAN.
+ */
+
+#ifndef NO_STRUCT_ASSIGN
+#define ASSIGN_STATE(dest,src) ((dest) = (src))
+#else
+#if MAX_COMPS_IN_SCAN == 4
+#define ASSIGN_STATE(dest,src) \
+ ((dest).EOBRUN = (src).EOBRUN, \
+ (dest).last_dc_val[0] = (src).last_dc_val[0], \
+ (dest).last_dc_val[1] = (src).last_dc_val[1], \
+ (dest).last_dc_val[2] = (src).last_dc_val[2], \
+ (dest).last_dc_val[3] = (src).last_dc_val[3])
+#endif
+#endif
+
+
+typedef struct {
+ struct jpeg_entropy_decoder pub; /* public fields */
+
+ /* These fields are loaded into local variables at start of each MCU.
+ * In case of suspension, we exit WITHOUT updating them.
+ */
+ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
+ savable_state saved; /* Other state at start of MCU */
+
+ /* These fields are NOT loaded into local working state. */
+ unsigned int restarts_to_go; /* MCUs left in this restart interval */
+
+ /* Pointers to derived tables (these workspaces have image lifespan) */
+ d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
+
+ d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
+} phuff_entropy_decoder;
+
+typedef phuff_entropy_decoder * phuff_entropy_ptr;
+
+/* Forward declarations */
+METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+
+
+/*
+ * Initialize for a Huffman-compressed scan.
+ */
+
+METHODDEF(void)
+start_pass_phuff_decoder (j_decompress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ boolean is_DC_band, bad;
+ int ci, coefi, tbl;
+ int *coef_bit_ptr;
+ jpeg_component_info * compptr;
+
+ is_DC_band = (cinfo->Ss == 0);
+
+ /* Validate scan parameters */
+ bad = FALSE;
+ if (is_DC_band) {
+ if (cinfo->Se != 0)
+ bad = TRUE;
+ } else {
+ /* need not check Ss/Se < 0 since they came from unsigned bytes */
+ if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
+ bad = TRUE;
+ /* AC scans may have only one component */
+ if (cinfo->comps_in_scan != 1)
+ bad = TRUE;
+ }
+ if (cinfo->Ah != 0) {
+ /* Successive approximation refinement scan: must have Al = Ah-1. */
+ if (cinfo->Al != cinfo->Ah-1)
+ bad = TRUE;
+ }
+ if (cinfo->Al > 13) /* need not check for < 0 */
+ bad = TRUE;
+ /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
+ * but the spec doesn't say so, and we try to be liberal about what we
+ * accept. Note: large Al values could result in out-of-range DC
+ * coefficients during early scans, leading to bizarre displays due to
+ * overflows in the IDCT math. But we won't crash.
+ */
+ if (bad)
+ ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
+ cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
+ /* Update progression status, and verify that scan order is legal.
+ * Note that inter-scan inconsistencies are treated as warnings
+ * not fatal errors ... not clear if this is right way to behave.
+ */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ int cindex = cinfo->cur_comp_info[ci]->component_index;
+ coef_bit_ptr = & cinfo->coef_bits[cindex][0];
+ if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
+ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
+ for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
+ int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
+ if (cinfo->Ah != expected)
+ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
+ coef_bit_ptr[coefi] = cinfo->Al;
+ }
+ }
+
+ /* Select MCU decoding routine */
+ if (cinfo->Ah == 0) {
+ if (is_DC_band)
+ entropy->pub.decode_mcu = decode_mcu_DC_first;
+ else
+ entropy->pub.decode_mcu = decode_mcu_AC_first;
+ } else {
+ if (is_DC_band)
+ entropy->pub.decode_mcu = decode_mcu_DC_refine;
+ else
+ entropy->pub.decode_mcu = decode_mcu_AC_refine;
+ }
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+ compptr = cinfo->cur_comp_info[ci];
+ /* Make sure requested tables are present, and compute derived tables.
+ * We may build same derived table more than once, but it's not expensive.
+ */
+ if (is_DC_band) {
+ if (cinfo->Ah == 0) { /* DC refinement needs no table */
+ tbl = compptr->dc_tbl_no;
+ jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
+ & entropy->derived_tbls[tbl]);
+ }
+ } else {
+ tbl = compptr->ac_tbl_no;
+ jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
+ & entropy->derived_tbls[tbl]);
+ /* remember the single active table */
+ entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
+ }
+ /* Initialize DC predictions to 0 */
+ entropy->saved.last_dc_val[ci] = 0;
+ }
+
+ /* Initialize bitread state variables */
+ entropy->bitstate.bits_left = 0;
+ entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
+ entropy->pub.insufficient_data = FALSE;
+
+ /* Initialize private state variables */
+ entropy->saved.EOBRUN = 0;
+
+ /* Initialize restart counter */
+ entropy->restarts_to_go = cinfo->restart_interval;
+}
+
+
+/*
+ * Figure F.12: extend sign bit.
+ * On some machines, a shift and add will be faster than a table lookup.
+ */
+
+#ifdef AVOID_TABLES
+
+#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
+
+#else
+
+#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
+
+static const int extend_test[16] = /* entry n is 2**(n-1) */
+ { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
+ 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
+
+static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
+ { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
+ ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
+ ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
+ ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
+
+#endif /* AVOID_TABLES */
+
+
+/*
+ * Check for a restart marker & resynchronize decoder.
+ * Returns FALSE if must suspend.
+ */
+
+LOCAL(boolean)
+process_restart (j_decompress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ int ci;
+
+ /* Throw away any unused bits remaining in bit buffer; */
+ /* include any full bytes in next_marker's count of discarded bytes */
+ cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
+ entropy->bitstate.bits_left = 0;
+
+ /* Advance past the RSTn marker */
+ if (! (*cinfo->marker->read_restart_marker) (cinfo))
+ return FALSE;
+
+ /* Re-initialize DC predictions to 0 */
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++)
+ entropy->saved.last_dc_val[ci] = 0;
+ /* Re-init EOB run count, too */
+ entropy->saved.EOBRUN = 0;
+
+ /* Reset restart counter */
+ entropy->restarts_to_go = cinfo->restart_interval;
+
+ /* Reset out-of-data flag, unless read_restart_marker left us smack up
+ * against a marker. In that case we will end up treating the next data
+ * segment as empty, and we can avoid producing bogus output pixels by
+ * leaving the flag set.
+ */
+ if (cinfo->unread_marker == 0)
+ entropy->pub.insufficient_data = FALSE;
+
+ return TRUE;
+}
+
+
+/*
+ * Huffman MCU decoding.
+ * Each of these routines decodes and returns one MCU's worth of
+ * Huffman-compressed coefficients.
+ * The coefficients are reordered from zigzag order into natural array order,
+ * but are not dequantized.
+ *
+ * The i'th block of the MCU is stored into the block pointed to by
+ * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
+ *
+ * We return FALSE if data source requested suspension. In that case no
+ * changes have been made to permanent state. (Exception: some output
+ * coefficients may already have been assigned. This is harmless for
+ * spectral selection, since we'll just re-assign them on the next call.
+ * Successive approximation AC refinement has to be more careful, however.)
+ */
+
+/*
+ * MCU decoding for DC initial scan (either spectral selection,
+ * or first pass of successive approximation).
+ */
+
+METHODDEF(boolean)
+decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ int Al = cinfo->Al;
+ register int s, r;
+ int blkn, ci;
+ JBLOCKROW block;
+ BITREAD_STATE_VARS;
+ savable_state state;
+ d_derived_tbl * tbl;
+ jpeg_component_info * compptr;
+
+ /* Process restart marker if needed; may have to suspend */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! process_restart(cinfo))
+ return FALSE;
+ }
+
+ /* If we've run out of data, just leave the MCU set to zeroes.
+ * This way, we return uniform gray for the remainder of the segment.
+ */
+ if (! entropy->pub.insufficient_data) {
+
+ /* Load up working state */
+ BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
+ ASSIGN_STATE(state, entropy->saved);
+
+ /* Outer loop handles each block in the MCU */
+
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ block = MCU_data[blkn];
+ ci = cinfo->MCU_membership[blkn];
+ compptr = cinfo->cur_comp_info[ci];
+ tbl = entropy->derived_tbls[compptr->dc_tbl_no];
+
+ /* Decode a single block's worth of coefficients */
+
+ /* Section F.2.2.1: decode the DC coefficient difference */
+ HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
+ if (s) {
+ CHECK_BIT_BUFFER(br_state, s, return FALSE);
+ r = GET_BITS(s);
+ s = HUFF_EXTEND(r, s);
+ }
+
+ /* Convert DC difference to actual value, update last_dc_val */
+ s += state.last_dc_val[ci];
+ state.last_dc_val[ci] = s;
+ /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
+ (*block)[0] = (JCOEF) (s << Al);
+ }
+
+ /* Completed MCU, so update state */
+ BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
+ ASSIGN_STATE(entropy->saved, state);
+ }
+
+ /* Account for restart interval (no-op if not using restarts) */
+ entropy->restarts_to_go--;
+
+ return TRUE;
+}
+
+
+/*
+ * MCU decoding for AC initial scan (either spectral selection,
+ * or first pass of successive approximation).
+ */
+
+METHODDEF(boolean)
+decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ int Se = cinfo->Se;
+ int Al = cinfo->Al;
+ register int s, k, r;
+ unsigned int EOBRUN;
+ JBLOCKROW block;
+ BITREAD_STATE_VARS;
+ d_derived_tbl * tbl;
+
+ /* Process restart marker if needed; may have to suspend */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! process_restart(cinfo))
+ return FALSE;
+ }
+
+ /* If we've run out of data, just leave the MCU set to zeroes.
+ * This way, we return uniform gray for the remainder of the segment.
+ */
+ if (! entropy->pub.insufficient_data) {
+
+ /* Load up working state.
+ * We can avoid loading/saving bitread state if in an EOB run.
+ */
+ EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
+
+ /* There is always only one block per MCU */
+
+ if (EOBRUN > 0) /* if it's a band of zeroes... */
+ EOBRUN--; /* ...process it now (we do nothing) */
+ else {
+ BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
+ block = MCU_data[0];
+ tbl = entropy->ac_derived_tbl;
+
+ for (k = cinfo->Ss; k <= Se; k++) {
+ HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
+ r = s >> 4;
+ s &= 15;
+ if (s) {
+ k += r;
+ CHECK_BIT_BUFFER(br_state, s, return FALSE);
+ r = GET_BITS(s);
+ s = HUFF_EXTEND(r, s);
+ /* Scale and output coefficient in natural (dezigzagged) order */
+ (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
+ } else {
+ if (r == 15) { /* ZRL */
+ k += 15; /* skip 15 zeroes in band */
+ } else { /* EOBr, run length is 2^r + appended bits */
+ EOBRUN = 1 << r;
+ if (r) { /* EOBr, r > 0 */
+ CHECK_BIT_BUFFER(br_state, r, return FALSE);
+ r = GET_BITS(r);
+ EOBRUN += r;
+ }
+ EOBRUN--; /* this band is processed at this moment */
+ break; /* force end-of-band */
+ }
+ }
+ }
+
+ BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
+ }
+
+ /* Completed MCU, so update state */
+ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
+ }
+
+ /* Account for restart interval (no-op if not using restarts) */
+ entropy->restarts_to_go--;
+
+ return TRUE;
+}
+
+
+/*
+ * MCU decoding for DC successive approximation refinement scan.
+ * Note: we assume such scans can be multi-component, although the spec
+ * is not very clear on the point.
+ */
+
+METHODDEF(boolean)
+decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
+ int blkn;
+ JBLOCKROW block;
+ BITREAD_STATE_VARS;
+
+ /* Process restart marker if needed; may have to suspend */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! process_restart(cinfo))
+ return FALSE;
+ }
+
+ /* Not worth the cycles to check insufficient_data here,
+ * since we will not change the data anyway if we read zeroes.
+ */
+
+ /* Load up working state */
+ BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
+
+ /* Outer loop handles each block in the MCU */
+
+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
+ block = MCU_data[blkn];
+
+ /* Encoded data is simply the next bit of the two's-complement DC value */
+ CHECK_BIT_BUFFER(br_state, 1, return FALSE);
+ if (GET_BITS(1))
+ (*block)[0] |= p1;
+ /* Note: since we use |=, repeating the assignment later is safe */
+ }
+
+ /* Completed MCU, so update state */
+ BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
+
+ /* Account for restart interval (no-op if not using restarts) */
+ entropy->restarts_to_go--;
+
+ return TRUE;
+}
+
+
+/*
+ * MCU decoding for AC successive approximation refinement scan.
+ */
+
+METHODDEF(boolean)
+decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
+{
+ phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
+ int Se = cinfo->Se;
+ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
+ int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
+ register int s, k, r;
+ unsigned int EOBRUN;
+ JBLOCKROW block;
+ JCOEFPTR thiscoef;
+ BITREAD_STATE_VARS;
+ d_derived_tbl * tbl;
+ int num_newnz;
+ int newnz_pos[DCTSIZE2];
+
+ /* Process restart marker if needed; may have to suspend */
+ if (cinfo->restart_interval) {
+ if (entropy->restarts_to_go == 0)
+ if (! process_restart(cinfo))
+ return FALSE;
+ }
+
+ /* If we've run out of data, don't modify the MCU.
+ */
+ if (! entropy->pub.insufficient_data) {
+
+ /* Load up working state */
+ BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
+ EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
+
+ /* There is always only one block per MCU */
+ block = MCU_data[0];
+ tbl = entropy->ac_derived_tbl;
+
+ /* If we are forced to suspend, we must undo the assignments to any newly
+ * nonzero coefficients in the block, because otherwise we'd get confused
+ * next time about which coefficients were already nonzero.
+ * But we need not undo addition of bits to already-nonzero coefficients;
+ * instead, we can test the current bit to see if we already did it.
+ */
+ num_newnz = 0;
+
+ /* initialize coefficient loop counter to start of band */
+ k = cinfo->Ss;
+
+ if (EOBRUN == 0) {
+ for (; k <= Se; k++) {
+ HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
+ r = s >> 4;
+ s &= 15;
+ if (s) {
+ if (s != 1) /* size of new coef should always be 1 */
+ WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
+ CHECK_BIT_BUFFER(br_state, 1, goto undoit);
+ if (GET_BITS(1))
+ s = p1; /* newly nonzero coef is positive */
+ else
+ s = m1; /* newly nonzero coef is negative */
+ } else {
+ if (r != 15) {
+ EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
+ if (r) {
+ CHECK_BIT_BUFFER(br_state, r, goto undoit);
+ r = GET_BITS(r);
+ EOBRUN += r;
+ }
+ break; /* rest of block is handled by EOB logic */
+ }
+ /* note s = 0 for processing ZRL */
+ }
+ /* Advance over already-nonzero coefs and r still-zero coefs,
+ * appending correction bits to the nonzeroes. A correction bit is 1
+ * if the absolute value of the coefficient must be increased.
+ */
+ do {
+ thiscoef = *block + jpeg_natural_order[k];
+ if (*thiscoef != 0) {
+ CHECK_BIT_BUFFER(br_state, 1, goto undoit);
+ if (GET_BITS(1)) {
+ if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
+ if (*thiscoef >= 0)
+ *thiscoef += p1;
+ else
+ *thiscoef += m1;
+ }
+ }
+ } else {
+ if (--r < 0)
+ break; /* reached target zero coefficient */
+ }
+ k++;
+ } while (k <= Se);
+ if (s) {
+ int pos = jpeg_natural_order[k];
+ /* Output newly nonzero coefficient */
+ (*block)[pos] = (JCOEF) s;
+ /* Remember its position in case we have to suspend */
+ newnz_pos[num_newnz++] = pos;
+ }
+ }
+ }
+
+ if (EOBRUN > 0) {
+ /* Scan any remaining coefficient positions after the end-of-band
+ * (the last newly nonzero coefficient, if any). Append a correction
+ * bit to each already-nonzero coefficient. A correction bit is 1
+ * if the absolute value of the coefficient must be increased.
+ */
+ for (; k <= Se; k++) {
+ thiscoef = *block + jpeg_natural_order[k];
+ if (*thiscoef != 0) {
+ CHECK_BIT_BUFFER(br_state, 1, goto undoit);
+ if (GET_BITS(1)) {
+ if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
+ if (*thiscoef >= 0)
+ *thiscoef += p1;
+ else
+ *thiscoef += m1;
+ }
+ }
+ }
+ }
+ /* Count one block completed in EOB run */
+ EOBRUN--;
+ }
+
+ /* Completed MCU, so update state */
+ BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
+ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
+ }
+
+ /* Account for restart interval (no-op if not using restarts) */
+ entropy->restarts_to_go--;
+
+ return TRUE;
+
+undoit:
+ /* Re-zero any output coefficients that we made newly nonzero */
+ while (num_newnz > 0)
+ (*block)[newnz_pos[--num_newnz]] = 0;
+
+ return FALSE;
+}
+
+
+/*
+ * Module initialization routine for progressive Huffman entropy decoding.
+ */
+
+GLOBAL(void)
+jinit_phuff_decoder (j_decompress_ptr cinfo)
+{
+ phuff_entropy_ptr entropy;
+ int *coef_bit_ptr;
+ int ci, i;
+
+ entropy = (phuff_entropy_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(phuff_entropy_decoder));
+ cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
+ entropy->pub.start_pass = start_pass_phuff_decoder;
+
+ /* Mark derived tables unallocated */
+ for (i = 0; i < NUM_HUFF_TBLS; i++) {
+ entropy->derived_tbls[i] = NULL;
+ }
+
+ /* Create progression status table */
+ cinfo->coef_bits = (int (*)[DCTSIZE2])
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->num_components*DCTSIZE2*SIZEOF(int));
+ coef_bit_ptr = & cinfo->coef_bits[0][0];
+ for (ci = 0; ci < cinfo->num_components; ci++)
+ for (i = 0; i < DCTSIZE2; i++)
+ *coef_bit_ptr++ = -1;
+}
+
+#endif /* D_PROGRESSIVE_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jdpostct.c b/osframework/source/ImageLib/jpeg/jdpostct.c
new file mode 100644
index 0000000..7ba9eed
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdpostct.c
@@ -0,0 +1,290 @@
+/*
+ * jdpostct.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the decompression postprocessing controller.
+ * This controller manages the upsampling, color conversion, and color
+ * quantization/reduction steps; specifically, it controls the buffering
+ * between upsample/color conversion and color quantization/reduction.
+ *
+ * If no color quantization/reduction is required, then this module has no
+ * work to do, and it just hands off to the upsample/color conversion code.
+ * An integrated upsample/convert/quantize process would replace this module
+ * entirely.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Private buffer controller object */
+
+typedef struct {
+ struct jpeg_d_post_controller pub; /* public fields */
+
+ /* Color quantization source buffer: this holds output data from
+ * the upsample/color conversion step to be passed to the quantizer.
+ * For two-pass color quantization, we need a full-image buffer;
+ * for one-pass operation, a strip buffer is sufficient.
+ */
+ jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
+ JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
+ JDIMENSION strip_height; /* buffer size in rows */
+ /* for two-pass mode only: */
+ JDIMENSION starting_row; /* row # of first row in current strip */
+ JDIMENSION next_row; /* index of next row to fill/empty in strip */
+} my_post_controller;
+
+typedef my_post_controller * my_post_ptr;
+
+
+/* Forward declarations */
+METHODDEF(void) post_process_1pass
+ JPP((j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+#ifdef QUANT_2PASS_SUPPORTED
+METHODDEF(void) post_process_prepass
+ JPP((j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+METHODDEF(void) post_process_2pass
+ JPP((j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+#endif
+
+
+/*
+ * Initialize for a processing pass.
+ */
+
+METHODDEF(void)
+start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
+{
+ my_post_ptr post = (my_post_ptr) cinfo->post;
+
+ switch (pass_mode) {
+ case JBUF_PASS_THRU:
+ if (cinfo->quantize_colors) {
+ /* Single-pass processing with color quantization. */
+ post->pub.post_process_data = post_process_1pass;
+ /* We could be doing buffered-image output before starting a 2-pass
+ * color quantization; in that case, jinit_d_post_controller did not
+ * allocate a strip buffer. Use the virtual-array buffer as workspace.
+ */
+ if (post->buffer == NULL) {
+ post->buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, post->whole_image,
+ (JDIMENSION) 0, post->strip_height, TRUE);
+ }
+ } else {
+ /* For single-pass processing without color quantization,
+ * I have no work to do; just call the upsampler directly.
+ */
+ post->pub.post_process_data = cinfo->upsample->upsample;
+ }
+ break;
+#ifdef QUANT_2PASS_SUPPORTED
+ case JBUF_SAVE_AND_PASS:
+ /* First pass of 2-pass quantization */
+ if (post->whole_image == NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ post->pub.post_process_data = post_process_prepass;
+ break;
+ case JBUF_CRANK_DEST:
+ /* Second pass of 2-pass quantization */
+ if (post->whole_image == NULL)
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ post->pub.post_process_data = post_process_2pass;
+ break;
+#endif /* QUANT_2PASS_SUPPORTED */
+ default:
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+ break;
+ }
+ post->starting_row = post->next_row = 0;
+}
+
+
+/*
+ * Process some data in the one-pass (strip buffer) case.
+ * This is used for color precision reduction as well as one-pass quantization.
+ */
+
+METHODDEF(void)
+post_process_1pass (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_post_ptr post = (my_post_ptr) cinfo->post;
+ JDIMENSION num_rows, max_rows;
+
+ /* Fill the buffer, but not more than what we can dump out in one go. */
+ /* Note we rely on the upsampler to detect bottom of image. */
+ max_rows = out_rows_avail - *out_row_ctr;
+ if (max_rows > post->strip_height)
+ max_rows = post->strip_height;
+ num_rows = 0;
+ (*cinfo->upsample->upsample) (cinfo,
+ input_buf, in_row_group_ctr, in_row_groups_avail,
+ post->buffer, &num_rows, max_rows);
+ /* Quantize and emit data. */
+ (*cinfo->cquantize->color_quantize) (cinfo,
+ post->buffer, output_buf + *out_row_ctr, (int) num_rows);
+ *out_row_ctr += num_rows;
+}
+
+
+#ifdef QUANT_2PASS_SUPPORTED
+
+/*
+ * Process some data in the first pass of 2-pass quantization.
+ */
+
+METHODDEF(void)
+post_process_prepass (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_post_ptr post = (my_post_ptr) cinfo->post;
+ JDIMENSION old_next_row, num_rows;
+
+ /* Reposition virtual buffer if at start of strip. */
+ if (post->next_row == 0) {
+ post->buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, post->whole_image,
+ post->starting_row, post->strip_height, TRUE);
+ }
+
+ /* Upsample some data (up to a strip height's worth). */
+ old_next_row = post->next_row;
+ (*cinfo->upsample->upsample) (cinfo,
+ input_buf, in_row_group_ctr, in_row_groups_avail,
+ post->buffer, &post->next_row, post->strip_height);
+
+ /* Allow quantizer to scan new data. No data is emitted, */
+ /* but we advance out_row_ctr so outer loop can tell when we're done. */
+ if (post->next_row > old_next_row) {
+ num_rows = post->next_row - old_next_row;
+ (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
+ (JSAMPARRAY) NULL, (int) num_rows);
+ *out_row_ctr += num_rows;
+ }
+
+ /* Advance if we filled the strip. */
+ if (post->next_row >= post->strip_height) {
+ post->starting_row += post->strip_height;
+ post->next_row = 0;
+ }
+}
+
+
+/*
+ * Process some data in the second pass of 2-pass quantization.
+ */
+
+METHODDEF(void)
+post_process_2pass (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_post_ptr post = (my_post_ptr) cinfo->post;
+ JDIMENSION num_rows, max_rows;
+
+ /* Reposition virtual buffer if at start of strip. */
+ if (post->next_row == 0) {
+ post->buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, post->whole_image,
+ post->starting_row, post->strip_height, FALSE);
+ }
+
+ /* Determine number of rows to emit. */
+ num_rows = post->strip_height - post->next_row; /* available in strip */
+ max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
+ if (num_rows > max_rows)
+ num_rows = max_rows;
+ /* We have to check bottom of image here, can't depend on upsampler. */
+ max_rows = cinfo->output_height - post->starting_row;
+ if (num_rows > max_rows)
+ num_rows = max_rows;
+
+ /* Quantize and emit data. */
+ (*cinfo->cquantize->color_quantize) (cinfo,
+ post->buffer + post->next_row, output_buf + *out_row_ctr,
+ (int) num_rows);
+ *out_row_ctr += num_rows;
+
+ /* Advance if we filled the strip. */
+ post->next_row += num_rows;
+ if (post->next_row >= post->strip_height) {
+ post->starting_row += post->strip_height;
+ post->next_row = 0;
+ }
+}
+
+#endif /* QUANT_2PASS_SUPPORTED */
+
+
+/*
+ * Initialize postprocessing controller.
+ */
+
+GLOBAL(void)
+jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
+{
+ my_post_ptr post;
+
+ post = (my_post_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_post_controller));
+ cinfo->post = (struct jpeg_d_post_controller *) post;
+ post->pub.start_pass = start_pass_dpost;
+ post->whole_image = NULL; /* flag for no virtual arrays */
+ post->buffer = NULL; /* flag for no strip buffer */
+
+ /* Create the quantization buffer, if needed */
+ if (cinfo->quantize_colors) {
+ /* The buffer strip height is max_v_samp_factor, which is typically
+ * an efficient number of rows for upsampling to return.
+ * (In the presence of output rescaling, we might want to be smarter?)
+ */
+ post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
+ if (need_full_buffer) {
+ /* Two-pass color quantization: need full-image storage. */
+ /* We round up the number of rows to a multiple of the strip height. */
+#ifdef QUANT_2PASS_SUPPORTED
+ post->whole_image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ cinfo->output_width * cinfo->out_color_components,
+ (JDIMENSION) jround_up((long) cinfo->output_height,
+ (long) post->strip_height),
+ post->strip_height);
+#else
+ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
+#endif /* QUANT_2PASS_SUPPORTED */
+ } else {
+ /* One-pass color quantization: just make a strip buffer. */
+ post->buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->output_width * cinfo->out_color_components,
+ post->strip_height);
+ }
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdsample.c b/osframework/source/ImageLib/jpeg/jdsample.c
new file mode 100644
index 0000000..e0d9040
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdsample.c
@@ -0,0 +1,478 @@
+/*
+ * jdsample.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains upsampling routines.
+ *
+ * Upsampling input data is counted in "row groups". A row group
+ * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
+ * sample rows of each component. Upsampling will normally produce
+ * max_v_samp_factor pixel rows from each row group (but this could vary
+ * if the upsampler is applying a scale factor of its own).
+ *
+ * An excellent reference for image resampling is
+ * Digital Image Warping, George Wolberg, 1990.
+ * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Pointer to routine to upsample a single component */
+typedef JMETHOD(void, upsample1_ptr,
+ (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_upsampler pub; /* public fields */
+
+ /* Color conversion buffer. When using separate upsampling and color
+ * conversion steps, this buffer holds one upsampled row group until it
+ * has been color converted and output.
+ * Note: we do not allocate any storage for component(s) which are full-size,
+ * ie do not need rescaling. The corresponding entry of color_buf[] is
+ * simply set to point to the input data array, thereby avoiding copying.
+ */
+ JSAMPARRAY color_buf[MAX_COMPONENTS];
+
+ /* Per-component upsampling method pointers */
+ upsample1_ptr methods[MAX_COMPONENTS];
+
+ int next_row_out; /* counts rows emitted from color_buf */
+ JDIMENSION rows_to_go; /* counts rows remaining in image */
+
+ /* Height of an input row group for each component. */
+ int rowgroup_height[MAX_COMPONENTS];
+
+ /* These arrays save pixel expansion factors so that int_expand need not
+ * recompute them each time. They are unused for other upsampling methods.
+ */
+ UINT8 h_expand[MAX_COMPONENTS];
+ UINT8 v_expand[MAX_COMPONENTS];
+} my_upsampler;
+
+typedef my_upsampler * my_upsample_ptr;
+
+
+/*
+ * Initialize for an upsampling pass.
+ */
+
+METHODDEF(void)
+start_pass_upsample (j_decompress_ptr cinfo)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+
+ /* Mark the conversion buffer empty */
+ upsample->next_row_out = cinfo->max_v_samp_factor;
+ /* Initialize total-height counter for detecting bottom of image */
+ upsample->rows_to_go = cinfo->output_height;
+}
+
+
+/*
+ * Control routine to do upsampling (and color conversion).
+ *
+ * In this version we upsample each component independently.
+ * We upsample one row group into the conversion buffer, then apply
+ * color conversion a row at a time.
+ */
+
+METHODDEF(void)
+sep_upsample (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ int ci;
+ jpeg_component_info * compptr;
+ JDIMENSION num_rows;
+
+ /* Fill the conversion buffer, if it's empty */
+ if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Invoke per-component upsample method. Notice we pass a POINTER
+ * to color_buf[ci], so that fullsize_upsample can change it.
+ */
+ (*upsample->methods[ci]) (cinfo, compptr,
+ input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
+ upsample->color_buf + ci);
+ }
+ upsample->next_row_out = 0;
+ }
+
+ /* Color-convert and emit rows */
+
+ /* How many we have in the buffer: */
+ num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
+ /* Not more than the distance to the end of the image. Need this test
+ * in case the image height is not a multiple of max_v_samp_factor:
+ */
+ if (num_rows > upsample->rows_to_go)
+ num_rows = upsample->rows_to_go;
+ /* And not more than what the client can accept: */
+ out_rows_avail -= *out_row_ctr;
+ if (num_rows > out_rows_avail)
+ num_rows = out_rows_avail;
+
+ (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
+ (JDIMENSION) upsample->next_row_out,
+ output_buf + *out_row_ctr,
+ (int) num_rows);
+
+ /* Adjust counts */
+ *out_row_ctr += num_rows;
+ upsample->rows_to_go -= num_rows;
+ upsample->next_row_out += num_rows;
+ /* When the buffer is emptied, declare this input row group consumed */
+ if (upsample->next_row_out >= cinfo->max_v_samp_factor)
+ (*in_row_group_ctr)++;
+}
+
+
+/*
+ * These are the routines invoked by sep_upsample to upsample pixel values
+ * of a single component. One row group is processed per call.
+ */
+
+
+/*
+ * For full-size components, we just make color_buf[ci] point at the
+ * input buffer, and thus avoid copying any data. Note that this is
+ * safe only because sep_upsample doesn't declare the input row group
+ * "consumed" until we are done color converting and emitting it.
+ */
+
+METHODDEF(void)
+fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ *output_data_ptr = input_data;
+}
+
+
+/*
+ * This is a no-op version used for "uninteresting" components.
+ * These components will not be referenced by color conversion.
+ */
+
+METHODDEF(void)
+noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ *output_data_ptr = NULL; /* safety check */
+}
+
+
+/*
+ * This version handles any integral sampling ratios.
+ * This is not used for typical JPEG files, so it need not be fast.
+ * Nor, for that matter, is it particularly accurate: the algorithm is
+ * simple replication of the input pixel onto the corresponding output
+ * pixels. The hi-falutin sampling literature refers to this as a
+ * "box filter". A box filter tends to introduce visible artifacts,
+ * so if you are actually going to use 3:1 or 4:1 sampling ratios
+ * you would be well advised to improve this code.
+ */
+
+METHODDEF(void)
+int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
+ JSAMPARRAY output_data = *output_data_ptr;
+ register JSAMPROW inptr, outptr;
+ register JSAMPLE invalue;
+ register int h;
+ JSAMPROW outend;
+ int h_expand, v_expand;
+ int inrow, outrow;
+
+ h_expand = upsample->h_expand[compptr->component_index];
+ v_expand = upsample->v_expand[compptr->component_index];
+
+ inrow = outrow = 0;
+ while (outrow < cinfo->max_v_samp_factor) {
+ /* Generate one output row with proper horizontal expansion */
+ inptr = input_data[inrow];
+ outptr = output_data[outrow];
+ outend = outptr + cinfo->output_width;
+ while (outptr < outend) {
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
+ for (h = h_expand; h > 0; h--) {
+ *outptr++ = invalue;
+ }
+ }
+ /* Generate any additional output rows by duplicating the first one */
+ if (v_expand > 1) {
+ jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
+ v_expand-1, cinfo->output_width);
+ }
+ inrow++;
+ outrow += v_expand;
+ }
+}
+
+
+/*
+ * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
+ * It's still a box filter.
+ */
+
+METHODDEF(void)
+h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ JSAMPARRAY output_data = *output_data_ptr;
+ register JSAMPROW inptr, outptr;
+ register JSAMPLE invalue;
+ JSAMPROW outend;
+ int inrow;
+
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
+ inptr = input_data[inrow];
+ outptr = output_data[inrow];
+ outend = outptr + cinfo->output_width;
+ while (outptr < outend) {
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
+ *outptr++ = invalue;
+ *outptr++ = invalue;
+ }
+ }
+}
+
+
+/*
+ * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
+ * It's still a box filter.
+ */
+
+METHODDEF(void)
+h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ JSAMPARRAY output_data = *output_data_ptr;
+ register JSAMPROW inptr, outptr;
+ register JSAMPLE invalue;
+ JSAMPROW outend;
+ int inrow, outrow;
+
+ inrow = outrow = 0;
+ while (outrow < cinfo->max_v_samp_factor) {
+ inptr = input_data[inrow];
+ outptr = output_data[outrow];
+ outend = outptr + cinfo->output_width;
+ while (outptr < outend) {
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
+ *outptr++ = invalue;
+ *outptr++ = invalue;
+ }
+ jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
+ 1, cinfo->output_width);
+ inrow++;
+ outrow += 2;
+ }
+}
+
+
+/*
+ * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
+ *
+ * The upsampling algorithm is linear interpolation between pixel centers,
+ * also known as a "triangle filter". This is a good compromise between
+ * speed and visual quality. The centers of the output pixels are 1/4 and 3/4
+ * of the way between input pixel centers.
+ *
+ * A note about the "bias" calculations: when rounding fractional values to
+ * integer, we do not want to always round 0.5 up to the next integer.
+ * If we did that, we'd introduce a noticeable bias towards larger values.
+ * Instead, this code is arranged so that 0.5 will be rounded up or down at
+ * alternate pixel locations (a simple ordered dither pattern).
+ */
+
+METHODDEF(void)
+h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ JSAMPARRAY output_data = *output_data_ptr;
+ register JSAMPROW inptr, outptr;
+ register int invalue;
+ register JDIMENSION colctr;
+ int inrow;
+
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
+ inptr = input_data[inrow];
+ outptr = output_data[inrow];
+ /* Special case for first column */
+ invalue = GETJSAMPLE(*inptr++);
+ *outptr++ = (JSAMPLE) invalue;
+ *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
+
+ for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
+ /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
+ invalue = GETJSAMPLE(*inptr++) * 3;
+ *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
+ *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
+ }
+
+ /* Special case for last column */
+ invalue = GETJSAMPLE(*inptr);
+ *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
+ *outptr++ = (JSAMPLE) invalue;
+ }
+}
+
+
+/*
+ * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
+ * Again a triangle filter; see comments for h2v1 case, above.
+ *
+ * It is OK for us to reference the adjacent input rows because we demanded
+ * context from the main buffer controller (see initialization code).
+ */
+
+METHODDEF(void)
+h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
+{
+ JSAMPARRAY output_data = *output_data_ptr;
+ register JSAMPROW inptr0, inptr1, outptr;
+#if BITS_IN_JSAMPLE == 8
+ register int thiscolsum, lastcolsum, nextcolsum;
+#else
+ register INT32 thiscolsum, lastcolsum, nextcolsum;
+#endif
+ register JDIMENSION colctr;
+ int inrow, outrow, v;
+
+ inrow = outrow = 0;
+ while (outrow < cinfo->max_v_samp_factor) {
+ for (v = 0; v < 2; v++) {
+ /* inptr0 points to nearest input row, inptr1 points to next nearest */
+ inptr0 = input_data[inrow];
+ if (v == 0) /* next nearest is row above */
+ inptr1 = input_data[inrow-1];
+ else /* next nearest is row below */
+ inptr1 = input_data[inrow+1];
+ outptr = output_data[outrow++];
+
+ /* Special case for first column */
+ thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
+ nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
+ *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
+ *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
+ lastcolsum = thiscolsum; thiscolsum = nextcolsum;
+
+ for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
+ /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
+ /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
+ nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
+ *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
+ *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
+ lastcolsum = thiscolsum; thiscolsum = nextcolsum;
+ }
+
+ /* Special case for last column */
+ *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
+ *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
+ }
+ inrow++;
+ }
+}
+
+
+/*
+ * Module initialization routine for upsampling.
+ */
+
+GLOBAL(void)
+jinit_upsampler (j_decompress_ptr cinfo)
+{
+ my_upsample_ptr upsample;
+ int ci;
+ jpeg_component_info * compptr;
+ boolean need_buffer, do_fancy;
+ int h_in_group, v_in_group, h_out_group, v_out_group;
+
+ upsample = (my_upsample_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_upsampler));
+ cinfo->upsample = (struct jpeg_upsampler *) upsample;
+ upsample->pub.start_pass = start_pass_upsample;
+ upsample->pub.upsample = sep_upsample;
+ upsample->pub.need_context_rows = FALSE; /* until we find out differently */
+
+ if (cinfo->CCIR601_sampling) /* this isn't supported */
+ ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
+
+ /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
+ * so don't ask for it.
+ */
+ do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
+
+ /* Verify we can handle the sampling factors, select per-component methods,
+ * and create storage as needed.
+ */
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+ ci++, compptr++) {
+ /* Compute size of an "input group" after IDCT scaling. This many samples
+ * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
+ */
+ h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size;
+ v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
+ cinfo->min_DCT_scaled_size;
+ h_out_group = cinfo->max_h_samp_factor;
+ v_out_group = cinfo->max_v_samp_factor;
+ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
+ need_buffer = TRUE;
+ if (! compptr->component_needed) {
+ /* Don't bother to upsample an uninteresting component. */
+ upsample->methods[ci] = noop_upsample;
+ need_buffer = FALSE;
+ } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
+ /* Fullsize components can be processed without any work. */
+ upsample->methods[ci] = fullsize_upsample;
+ need_buffer = FALSE;
+ } else if (h_in_group * 2 == h_out_group &&
+ v_in_group == v_out_group) {
+ /* Special cases for 2h1v upsampling */
+ if (do_fancy && compptr->downsampled_width > 2)
+ upsample->methods[ci] = h2v1_fancy_upsample;
+ else
+ upsample->methods[ci] = h2v1_upsample;
+ } else if (h_in_group * 2 == h_out_group &&
+ v_in_group * 2 == v_out_group) {
+ /* Special cases for 2h2v upsampling */
+ if (do_fancy && compptr->downsampled_width > 2) {
+ upsample->methods[ci] = h2v2_fancy_upsample;
+ upsample->pub.need_context_rows = TRUE;
+ } else
+ upsample->methods[ci] = h2v2_upsample;
+ } else if ((h_out_group % h_in_group) == 0 &&
+ (v_out_group % v_in_group) == 0) {
+ /* Generic integral-factors upsampling method */
+ upsample->methods[ci] = int_upsample;
+ upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
+ upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
+ } else
+ ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
+ if (need_buffer) {
+ upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) jround_up((long) cinfo->output_width,
+ (long) cinfo->max_h_samp_factor),
+ (JDIMENSION) cinfo->max_v_samp_factor);
+ }
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jdtrans.c b/osframework/source/ImageLib/jpeg/jdtrans.c
new file mode 100644
index 0000000..12c193c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jdtrans.c
@@ -0,0 +1,143 @@
+/*
+ * jdtrans.c
+ *
+ * Copyright (C) 1995-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains library routines for transcoding decompression,
+ * that is, reading raw DCT coefficient arrays from an input JPEG file.
+ * The routines in jdapimin.c will also be needed by a transcoder.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/* Forward declarations */
+LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
+
+
+/*
+ * Read the coefficient arrays from a JPEG file.
+ * jpeg_read_header must be completed before calling this.
+ *
+ * The entire image is read into a set of virtual coefficient-block arrays,
+ * one per component. The return value is a pointer to the array of
+ * virtual-array descriptors. These can be manipulated directly via the
+ * JPEG memory manager, or handed off to jpeg_write_coefficients().
+ * To release the memory occupied by the virtual arrays, call
+ * jpeg_finish_decompress() when done with the data.
+ *
+ * An alternative usage is to simply obtain access to the coefficient arrays
+ * during a buffered-image-mode decompression operation. This is allowed
+ * after any jpeg_finish_output() call. The arrays can be accessed until
+ * jpeg_finish_decompress() is called. (Note that any call to the library
+ * may reposition the arrays, so don't rely on access_virt_barray() results
+ * to stay valid across library calls.)
+ *
+ * Returns NULL if suspended. This case need be checked only if
+ * a suspending data source is used.
+ */
+
+GLOBAL(jvirt_barray_ptr *)
+jpeg_read_coefficients (j_decompress_ptr cinfo)
+{
+ if (cinfo->global_state == DSTATE_READY) {
+ /* First call: initialize active modules */
+ transdecode_master_selection(cinfo);
+ cinfo->global_state = DSTATE_RDCOEFS;
+ }
+ if (cinfo->global_state == DSTATE_RDCOEFS) {
+ /* Absorb whole file into the coef buffer */
+ for (;;) {
+ int retcode;
+ /* Call progress monitor hook if present */
+ if (cinfo->progress != NULL)
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+ /* Absorb some more input */
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
+ if (retcode == JPEG_SUSPENDED)
+ return NULL;
+ if (retcode == JPEG_REACHED_EOI)
+ break;
+ /* Advance progress counter if appropriate */
+ if (cinfo->progress != NULL &&
+ (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
+ if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
+ /* startup underestimated number of scans; ratchet up one scan */
+ cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
+ }
+ }
+ }
+ /* Set state so that jpeg_finish_decompress does the right thing */
+ cinfo->global_state = DSTATE_STOPPING;
+ }
+ /* At this point we should be in state DSTATE_STOPPING if being used
+ * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
+ * to the coefficients during a full buffered-image-mode decompression.
+ */
+ if ((cinfo->global_state == DSTATE_STOPPING ||
+ cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
+ return cinfo->coef->coef_arrays;
+ }
+ /* Oops, improper usage */
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+ return NULL; /* keep compiler happy */
+}
+
+
+/*
+ * Master selection of decompression modules for transcoding.
+ * This substitutes for jdmaster.c's initialization of the full decompressor.
+ */
+
+LOCAL(void)
+transdecode_master_selection (j_decompress_ptr cinfo)
+{
+ /* This is effectively a buffered-image operation. */
+ cinfo->buffered_image = TRUE;
+
+ /* Entropy decoding: either Huffman or arithmetic coding. */
+ if (cinfo->arith_code) {
+ ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
+ } else {
+ if (cinfo->progressive_mode) {
+#ifdef D_PROGRESSIVE_SUPPORTED
+ jinit_phuff_decoder(cinfo);
+#else
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+#endif
+ } else
+ jinit_huff_decoder(cinfo);
+ }
+
+ /* Always get a full-image coefficient buffer. */
+ jinit_d_coef_controller(cinfo, TRUE);
+
+ /* We can now tell the memory manager to allocate virtual arrays. */
+ (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
+
+ /* Initialize input side of decompressor to consume first scan. */
+ (*cinfo->inputctl->start_input_pass) (cinfo);
+
+ /* Initialize progress monitoring. */
+ if (cinfo->progress != NULL) {
+ int nscans;
+ /* Estimate number of scans to set pass_limit. */
+ if (cinfo->progressive_mode) {
+ /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
+ nscans = 2 + 3 * cinfo->num_components;
+ } else if (cinfo->inputctl->has_multiple_scans) {
+ /* For a nonprogressive multiscan file, estimate 1 scan per component. */
+ nscans = cinfo->num_components;
+ } else {
+ nscans = 1;
+ }
+ cinfo->progress->pass_counter = 0L;
+ cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
+ cinfo->progress->completed_passes = 0;
+ cinfo->progress->total_passes = 1;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/jerror.c b/osframework/source/ImageLib/jpeg/jerror.c
new file mode 100644
index 0000000..c98aed7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jerror.c
@@ -0,0 +1,252 @@
+/*
+ * jerror.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains simple error-reporting and trace-message routines.
+ * These are suitable for Unix-like systems and others where writing to
+ * stderr is the right thing to do. Many applications will want to replace
+ * some or all of these routines.
+ *
+ * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
+ * you get a Windows-specific hack to display error messages in a dialog box.
+ * It ain't much, but it beats dropping error messages into the bit bucket,
+ * which is what happens to output to stderr under most Windows C compilers.
+ *
+ * These routines are used by both the compression and decompression code.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jversion.h"
+#include "jerror.h"
+
+#ifdef USE_WINDOWS_MESSAGEBOX
+#include <windows.h>
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+
+
+/*
+ * Create the message string table.
+ * We do this from the master message list in jerror.h by re-reading
+ * jerror.h with a suitable definition for macro JMESSAGE.
+ * The message table is made an external symbol just in case any applications
+ * want to refer to it directly.
+ */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_std_message_table jMsgTable
+#endif
+
+#define JMESSAGE(code,string) string ,
+
+const char * const jpeg_std_message_table[] = {
+#include "jerror.h"
+ NULL
+};
+
+
+/*
+ * Error exit handler: must not return to caller.
+ *
+ * Applications may override this if they want to get control back after
+ * an error. Typically one would longjmp somewhere instead of exiting.
+ * The setjmp buffer can be made a private field within an expanded error
+ * handler object. Note that the info needed to generate an error message
+ * is stored in the error object, so you can generate the message now or
+ * later, at your convenience.
+ * You should make sure that the JPEG object is cleaned up (with jpeg_abort
+ * or jpeg_destroy) at some point.
+ */
+
+METHODDEF(void)
+error_exit (j_common_ptr cinfo)
+{
+ /* Always display the message */
+ (*cinfo->err->output_message) (cinfo);
+
+ /* Let the memory manager delete any temp files before we die */
+ jpeg_destroy(cinfo);
+
+ exit(EXIT_FAILURE);
+}
+
+
+/*
+ * Actual output of an error or trace message.
+ * Applications may override this method to send JPEG messages somewhere
+ * other than stderr.
+ *
+ * On Windows, printing to stderr is generally completely useless,
+ * so we provide optional code to produce an error-dialog popup.
+ * Most Windows applications will still prefer to override this routine,
+ * but if they don't, it'll do something at least marginally useful.
+ *
+ * NOTE: to use the library in an environment that doesn't support the
+ * C stdio library, you may have to delete the call to fprintf() entirely,
+ * not just not use this routine.
+ */
+
+METHODDEF(void)
+output_message (j_common_ptr cinfo)
+{
+ char buffer[JMSG_LENGTH_MAX];
+
+ /* Create the message */
+ (*cinfo->err->format_message) (cinfo, buffer);
+
+#ifdef USE_WINDOWS_MESSAGEBOX
+ /* Display it in a message dialog box */
+ MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
+ MB_OK | MB_ICONERROR);
+#else
+ /* Send it to stderr, adding a newline */
+ fprintf(stderr, "%s\n", buffer);
+#endif
+}
+
+
+/*
+ * Decide whether to emit a trace or warning message.
+ * msg_level is one of:
+ * -1: recoverable corrupt-data warning, may want to abort.
+ * 0: important advisory messages (always display to user).
+ * 1: first level of tracing detail.
+ * 2,3,...: successively more detailed tracing messages.
+ * An application might override this method if it wanted to abort on warnings
+ * or change the policy about which messages to display.
+ */
+
+METHODDEF(void)
+emit_message (j_common_ptr cinfo, int msg_level)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+
+ if (msg_level < 0) {
+ /* It's a warning message. Since corrupt files may generate many warnings,
+ * the policy implemented here is to show only the first warning,
+ * unless trace_level >= 3.
+ */
+ if (err->num_warnings == 0 || err->trace_level >= 3)
+ (*err->output_message) (cinfo);
+ /* Always count warnings in num_warnings. */
+ err->num_warnings++;
+ } else {
+ /* It's a trace message. Show it if trace_level >= msg_level. */
+ if (err->trace_level >= msg_level)
+ (*err->output_message) (cinfo);
+ }
+}
+
+
+/*
+ * Format a message string for the most recent JPEG error or message.
+ * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
+ * characters. Note that no '\n' character is added to the string.
+ * Few applications should need to override this method.
+ */
+
+METHODDEF(void)
+format_message (j_common_ptr cinfo, char * buffer)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+ int msg_code = err->msg_code;
+ const char * msgtext = NULL;
+ const char * msgptr;
+ char ch;
+ boolean isstring;
+
+ /* Look up message string in proper table */
+ if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
+ msgtext = err->jpeg_message_table[msg_code];
+ } else if (err->addon_message_table != NULL &&
+ msg_code >= err->first_addon_message &&
+ msg_code <= err->last_addon_message) {
+ msgtext = err->addon_message_table[msg_code - err->first_addon_message];
+ }
+
+ /* Defend against bogus message number */
+ if (msgtext == NULL) {
+ err->msg_parm.i[0] = msg_code;
+ msgtext = err->jpeg_message_table[0];
+ }
+
+ /* Check for string parameter, as indicated by %s in the message text */
+ isstring = FALSE;
+ msgptr = msgtext;
+ while ((ch = *msgptr++) != '\0') {
+ if (ch == '%') {
+ if (*msgptr == 's') isstring = TRUE;
+ break;
+ }
+ }
+
+ /* Format the message into the passed buffer */
+ if (isstring)
+ sprintf(buffer, msgtext, err->msg_parm.s);
+ else
+ sprintf(buffer, msgtext,
+ err->msg_parm.i[0], err->msg_parm.i[1],
+ err->msg_parm.i[2], err->msg_parm.i[3],
+ err->msg_parm.i[4], err->msg_parm.i[5],
+ err->msg_parm.i[6], err->msg_parm.i[7]);
+}
+
+
+/*
+ * Reset error state variables at start of a new image.
+ * This is called during compression startup to reset trace/error
+ * processing to default state, without losing any application-specific
+ * method pointers. An application might possibly want to override
+ * this method if it has additional error processing state.
+ */
+
+METHODDEF(void)
+reset_error_mgr (j_common_ptr cinfo)
+{
+ cinfo->err->num_warnings = 0;
+ /* trace_level is not reset since it is an application-supplied parameter */
+ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
+}
+
+
+/*
+ * Fill in the standard error-handling methods in a jpeg_error_mgr object.
+ * Typical call is:
+ * struct jpeg_compress_struct cinfo;
+ * struct jpeg_error_mgr err;
+ *
+ * cinfo.err = jpeg_std_error(&err);
+ * after which the application may override some of the methods.
+ */
+
+GLOBAL(struct jpeg_error_mgr *)
+jpeg_std_error (struct jpeg_error_mgr * err)
+{
+ err->error_exit = error_exit;
+ err->emit_message = emit_message;
+ err->output_message = output_message;
+ err->format_message = format_message;
+ err->reset_error_mgr = reset_error_mgr;
+
+ err->trace_level = 0; /* default = no tracing */
+ err->num_warnings = 0; /* no warnings emitted yet */
+ err->msg_code = 0; /* may be useful as a flag for "no error" */
+
+ /* Initialize message table pointers */
+ err->jpeg_message_table = jpeg_std_message_table;
+ err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
+
+ err->addon_message_table = NULL;
+ err->first_addon_message = 0; /* for safety */
+ err->last_addon_message = 0;
+
+ return err;
+}
diff --git a/osframework/source/ImageLib/jpeg/jerror.h b/osframework/source/ImageLib/jpeg/jerror.h
new file mode 100644
index 0000000..79084f2
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jerror.h
@@ -0,0 +1,291 @@
+/*
+ * jerror.h
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file defines the error and message codes for the JPEG library.
+ * Edit this file to add new codes, or to translate the message strings to
+ * some other language.
+ * A set of error-reporting macros are defined too. Some applications using
+ * the JPEG library may wish to include this file to get the error codes
+ * and/or the macros.
+ */
+
+/*
+ * To define the enum list of message codes, include this file without
+ * defining macro JMESSAGE. To create a message string table, include it
+ * again with a suitable JMESSAGE definition (see jerror.c for an example).
+ */
+#ifndef JMESSAGE
+#ifndef JERROR_H
+/* First time through, define the enum list */
+#define JMAKE_ENUM_LIST
+#else
+/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
+#define JMESSAGE(code,string)
+#endif /* JERROR_H */
+#endif /* JMESSAGE */
+
+#ifdef JMAKE_ENUM_LIST
+
+typedef enum {
+
+#define JMESSAGE(code,string) code ,
+
+#endif /* JMAKE_ENUM_LIST */
+
+JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
+
+/* For maintenance convenience, list is alphabetical by message code name */
+JMESSAGE(JERR_ARITH_NOTIMPL,
+ "Sorry, there are legal restrictions on arithmetic coding")
+JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
+JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
+JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
+JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
+JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
+JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
+JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
+JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
+JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
+JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
+JMESSAGE(JERR_BAD_LIB_VERSION,
+ "Wrong JPEG library version: library is %d, caller expects %d")
+JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
+JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
+JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
+JMESSAGE(JERR_BAD_PROGRESSION,
+ "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
+JMESSAGE(JERR_BAD_PROG_SCRIPT,
+ "Invalid progressive parameters at scan script entry %d")
+JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
+JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
+JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
+JMESSAGE(JERR_BAD_STRUCT_SIZE,
+ "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
+JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
+JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
+JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
+JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
+JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
+JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
+JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
+JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
+JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
+JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
+JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
+JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
+JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
+JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
+JMESSAGE(JERR_FILE_READ, "Input file read error")
+JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
+JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
+JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
+JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
+JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
+JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
+JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
+JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
+ "Cannot transcode due to multiple use of quantization table %d")
+JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
+JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
+JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
+JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
+JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
+JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
+JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
+JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
+JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
+JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
+JMESSAGE(JERR_QUANT_COMPONENTS,
+ "Cannot quantize more than %d color components")
+JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
+JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
+JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
+JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
+JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
+JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
+JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
+JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
+JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
+JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
+JMESSAGE(JERR_TFILE_WRITE,
+ "Write failed on temporary file --- out of disk space?")
+JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
+JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
+JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
+JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
+JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
+JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
+JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
+JMESSAGE(JMSG_VERSION, JVERSION)
+JMESSAGE(JTRC_16BIT_TABLES,
+ "Caution: quantization tables are too coarse for baseline JPEG")
+JMESSAGE(JTRC_ADOBE,
+ "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
+JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
+JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
+JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
+JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
+JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
+JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
+JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
+JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
+JMESSAGE(JTRC_EOI, "End Of Image")
+JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
+JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
+JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
+ "Warning: thumbnail image size does not match data length %u")
+JMESSAGE(JTRC_JFIF_EXTENSION,
+ "JFIF extension marker: type 0x%02x, length %u")
+JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
+JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
+JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
+JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
+JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
+JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
+JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
+JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
+JMESSAGE(JTRC_RST, "RST%d")
+JMESSAGE(JTRC_SMOOTH_NOTIMPL,
+ "Smoothing not supported with nonstandard sampling ratios")
+JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
+JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
+JMESSAGE(JTRC_SOI, "Start of Image")
+JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
+JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
+JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
+JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
+JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
+JMESSAGE(JTRC_THUMB_JPEG,
+ "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
+JMESSAGE(JTRC_THUMB_PALETTE,
+ "JFIF extension marker: palette thumbnail image, length %u")
+JMESSAGE(JTRC_THUMB_RGB,
+ "JFIF extension marker: RGB thumbnail image, length %u")
+JMESSAGE(JTRC_UNKNOWN_IDS,
+ "Unrecognized component IDs %d %d %d, assuming YCbCr")
+JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
+JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
+JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
+JMESSAGE(JWRN_BOGUS_PROGRESSION,
+ "Inconsistent progression sequence for component %d coefficient %d")
+JMESSAGE(JWRN_EXTRANEOUS_DATA,
+ "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
+JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
+JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
+JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
+JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
+JMESSAGE(JWRN_MUST_RESYNC,
+ "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
+JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
+JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
+
+#ifdef JMAKE_ENUM_LIST
+
+ JMSG_LASTMSGCODE
+} J_MESSAGE_CODE;
+
+#undef JMAKE_ENUM_LIST
+#endif /* JMAKE_ENUM_LIST */
+
+/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
+#undef JMESSAGE
+
+
+#ifndef JERROR_H
+#define JERROR_H
+
+/* Macros to simplify using the error and trace message stuff */
+/* The first parameter is either type of cinfo pointer */
+
+/* Fatal errors (print message and exit) */
+#define ERREXIT(cinfo,code) \
+ ((cinfo)->err->msg_code = (code), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT1(cinfo,code,p1) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT2(cinfo,code,p1,p2) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (cinfo)->err->msg_parm.i[1] = (p2), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT3(cinfo,code,p1,p2,p3) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (cinfo)->err->msg_parm.i[1] = (p2), \
+ (cinfo)->err->msg_parm.i[2] = (p3), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (cinfo)->err->msg_parm.i[1] = (p2), \
+ (cinfo)->err->msg_parm.i[2] = (p3), \
+ (cinfo)->err->msg_parm.i[3] = (p4), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXITS(cinfo,code,str) \
+ ((cinfo)->err->msg_code = (code), \
+ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+ (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+
+#define MAKESTMT(stuff) do { stuff } while (0)
+
+/* Nonfatal errors (we can keep going, but the data is probably corrupt) */
+#define WARNMS(cinfo,code) \
+ ((cinfo)->err->msg_code = (code), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+#define WARNMS1(cinfo,code,p1) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+#define WARNMS2(cinfo,code,p1,p2) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (cinfo)->err->msg_parm.i[1] = (p2), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+
+/* Informational/debugging messages */
+#define TRACEMS(cinfo,lvl,code) \
+ ((cinfo)->err->msg_code = (code), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS1(cinfo,lvl,code,p1) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS2(cinfo,lvl,code,p1,p2) \
+ ((cinfo)->err->msg_code = (code), \
+ (cinfo)->err->msg_parm.i[0] = (p1), \
+ (cinfo)->err->msg_parm.i[1] = (p2), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
+ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
+ (cinfo)->err->msg_code = (code); \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
+ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+ (cinfo)->err->msg_code = (code); \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
+ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+ _mp[4] = (p5); \
+ (cinfo)->err->msg_code = (code); \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
+ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+ _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
+ (cinfo)->err->msg_code = (code); \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMSS(cinfo,lvl,code,str) \
+ ((cinfo)->err->msg_code = (code), \
+ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+ (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+
+#endif /* JERROR_H */
diff --git a/osframework/source/ImageLib/jpeg/jfdctflt.c b/osframework/source/ImageLib/jpeg/jfdctflt.c
new file mode 100644
index 0000000..7ccfb38
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jfdctflt.c
@@ -0,0 +1,168 @@
+/*
+ * jfdctflt.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a floating-point implementation of the
+ * forward DCT (Discrete Cosine Transform).
+ *
+ * This implementation should be more accurate than either of the integer
+ * DCT implementations. However, it may not give the same results on all
+ * machines because of differences in roundoff behavior. Speed will depend
+ * on the hardware's floating point capacity.
+ *
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+ * on each column. Direct algorithms are also available, but they are
+ * much more complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
+ * JPEG textbook (see REFERENCES section in file README). The following code
+ * is based directly on figure 4-8 in P&M.
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
+ * possible to arrange the computation so that many of the multiplies are
+ * simple scalings of the final outputs. These multiplies can then be
+ * folded into the multiplications or divisions by the JPEG quantization
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
+ * to be done in the DCT itself.
+ * The primary disadvantage of this method is that with a fixed-point
+ * implementation, accuracy is lost due to imprecise representation of the
+ * scaled quantization values. However, that problem does not arise if
+ * we use floating point arithmetic.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_FLOAT_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/*
+ * Perform the forward DCT on one block of samples.
+ */
+
+GLOBAL(void)
+jpeg_fdct_float (FAST_FLOAT * data)
+{
+ FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
+ FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
+ FAST_FLOAT *dataptr;
+ int ctr;
+
+ /* Pass 1: process rows. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[0] + dataptr[7];
+ tmp7 = dataptr[0] - dataptr[7];
+ tmp1 = dataptr[1] + dataptr[6];
+ tmp6 = dataptr[1] - dataptr[6];
+ tmp2 = dataptr[2] + dataptr[5];
+ tmp5 = dataptr[2] - dataptr[5];
+ tmp3 = dataptr[3] + dataptr[4];
+ tmp4 = dataptr[3] - dataptr[4];
+
+ /* Even part */
+
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[0] = tmp10 + tmp11; /* phase 3 */
+ dataptr[4] = tmp10 - tmp11;
+
+ z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
+ dataptr[2] = tmp13 + z1; /* phase 5 */
+ dataptr[6] = tmp13 - z1;
+
+ /* Odd part */
+
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
+ z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
+ z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
+ z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ dataptr[5] = z13 + z2; /* phase 6 */
+ dataptr[3] = z13 - z2;
+ dataptr[1] = z11 + z4;
+ dataptr[7] = z11 - z4;
+
+ dataptr += DCTSIZE; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ /* Even part */
+
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
+ dataptr[DCTSIZE*4] = tmp10 - tmp11;
+
+ z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
+ dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
+ dataptr[DCTSIZE*6] = tmp13 - z1;
+
+ /* Odd part */
+
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
+ z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
+ z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
+ z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
+ dataptr[DCTSIZE*3] = z13 - z2;
+ dataptr[DCTSIZE*1] = z11 + z4;
+ dataptr[DCTSIZE*7] = z11 - z4;
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
+
+#endif /* DCT_FLOAT_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jfdctfst.c b/osframework/source/ImageLib/jpeg/jfdctfst.c
new file mode 100644
index 0000000..005a74f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jfdctfst.c
@@ -0,0 +1,224 @@
+/*
+ * jfdctfst.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a fast, not so accurate integer implementation of the
+ * forward DCT (Discrete Cosine Transform).
+ *
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+ * on each column. Direct algorithms are also available, but they are
+ * much more complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
+ * JPEG textbook (see REFERENCES section in file README). The following code
+ * is based directly on figure 4-8 in P&M.
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
+ * possible to arrange the computation so that many of the multiplies are
+ * simple scalings of the final outputs. These multiplies can then be
+ * folded into the multiplications or divisions by the JPEG quantization
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
+ * to be done in the DCT itself.
+ * The primary disadvantage of this method is that with fixed-point math,
+ * accuracy is lost due to imprecise representation of the scaled
+ * quantization values. The smaller the quantization table entry, the less
+ * precise the scaled value, so this implementation does worse with high-
+ * quality-setting files than with low-quality ones.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_IFAST_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/* Scaling decisions are generally the same as in the LL&M algorithm;
+ * see jfdctint.c for more details. However, we choose to descale
+ * (right shift) multiplication products as soon as they are formed,
+ * rather than carrying additional fractional bits into subsequent additions.
+ * This compromises accuracy slightly, but it lets us save a few shifts.
+ * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
+ * everywhere except in the multiplications proper; this saves a good deal
+ * of work on 16-bit-int machines.
+ *
+ * Again to save a few shifts, the intermediate results between pass 1 and
+ * pass 2 are not upscaled, but are represented only to integral precision.
+ *
+ * A final compromise is to represent the multiplicative constants to only
+ * 8 fractional bits, rather than 13. This saves some shifting work on some
+ * machines, and may also reduce the cost of multiplication (since there
+ * are fewer one-bits in the constants).
+ */
+
+#define CONST_BITS 8
+
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 8
+#define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
+#define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
+#define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
+#define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
+#else
+#define FIX_0_382683433 FIX(0.382683433)
+#define FIX_0_541196100 FIX(0.541196100)
+#define FIX_0_707106781 FIX(0.707106781)
+#define FIX_1_306562965 FIX(1.306562965)
+#endif
+
+
+/* We can gain a little more speed, with a further compromise in accuracy,
+ * by omitting the addition in a descaling shift. This yields an incorrectly
+ * rounded result half the time...
+ */
+
+#ifndef USE_ACCURATE_ROUNDING
+#undef DESCALE
+#define DESCALE(x,n) RIGHT_SHIFT(x, n)
+#endif
+
+
+/* Multiply a DCTELEM variable by an INT32 constant, and immediately
+ * descale to yield a DCTELEM result.
+ */
+
+#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
+
+
+/*
+ * Perform the forward DCT on one block of samples.
+ */
+
+GLOBAL(void)
+jpeg_fdct_ifast (DCTELEM * data)
+{
+ DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ DCTELEM tmp10, tmp11, tmp12, tmp13;
+ DCTELEM z1, z2, z3, z4, z5, z11, z13;
+ DCTELEM *dataptr;
+ int ctr;
+ SHIFT_TEMPS
+
+ /* Pass 1: process rows. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[0] + dataptr[7];
+ tmp7 = dataptr[0] - dataptr[7];
+ tmp1 = dataptr[1] + dataptr[6];
+ tmp6 = dataptr[1] - dataptr[6];
+ tmp2 = dataptr[2] + dataptr[5];
+ tmp5 = dataptr[2] - dataptr[5];
+ tmp3 = dataptr[3] + dataptr[4];
+ tmp4 = dataptr[3] - dataptr[4];
+
+ /* Even part */
+
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[0] = tmp10 + tmp11; /* phase 3 */
+ dataptr[4] = tmp10 - tmp11;
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
+ dataptr[2] = tmp13 + z1; /* phase 5 */
+ dataptr[6] = tmp13 - z1;
+
+ /* Odd part */
+
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
+ z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
+ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
+ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ dataptr[5] = z13 + z2; /* phase 6 */
+ dataptr[3] = z13 - z2;
+ dataptr[1] = z11 + z4;
+ dataptr[7] = z11 - z4;
+
+ dataptr += DCTSIZE; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ /* Even part */
+
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
+ dataptr[DCTSIZE*4] = tmp10 - tmp11;
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
+ dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
+ dataptr[DCTSIZE*6] = tmp13 - z1;
+
+ /* Odd part */
+
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
+ z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
+ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
+ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
+ dataptr[DCTSIZE*3] = z13 - z2;
+ dataptr[DCTSIZE*1] = z11 + z4;
+ dataptr[DCTSIZE*7] = z11 - z4;
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
+
+#endif /* DCT_IFAST_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jfdctint.c b/osframework/source/ImageLib/jpeg/jfdctint.c
new file mode 100644
index 0000000..d626927
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jfdctint.c
@@ -0,0 +1,283 @@
+/*
+ * jfdctint.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a slow-but-accurate integer implementation of the
+ * forward DCT (Discrete Cosine Transform).
+ *
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+ * on each column. Direct algorithms are also available, but they are
+ * much more complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on an algorithm described in
+ * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
+ * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
+ * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
+ * The primary algorithm described there uses 11 multiplies and 29 adds.
+ * We use their alternate method with 12 multiplies and 32 adds.
+ * The advantage of this method is that no data path contains more than one
+ * multiplication; this allows a very simple and accurate implementation in
+ * scaled fixed-point arithmetic, with a minimal number of shifts.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_ISLOW_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/*
+ * The poop on this scaling stuff is as follows:
+ *
+ * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
+ * larger than the true DCT outputs. The final outputs are therefore
+ * a factor of N larger than desired; since N=8 this can be cured by
+ * a simple right shift at the end of the algorithm. The advantage of
+ * this arrangement is that we save two multiplications per 1-D DCT,
+ * because the y0 and y4 outputs need not be divided by sqrt(N).
+ * In the IJG code, this factor of 8 is removed by the quantization step
+ * (in jcdctmgr.c), NOT in this module.
+ *
+ * We have to do addition and subtraction of the integer inputs, which
+ * is no problem, and multiplication by fractional constants, which is
+ * a problem to do in integer arithmetic. We multiply all the constants
+ * by CONST_SCALE and convert them to integer constants (thus retaining
+ * CONST_BITS bits of precision in the constants). After doing a
+ * multiplication we have to divide the product by CONST_SCALE, with proper
+ * rounding, to produce the correct output. This division can be done
+ * cheaply as a right shift of CONST_BITS bits. We postpone shifting
+ * as long as possible so that partial sums can be added together with
+ * full fractional precision.
+ *
+ * The outputs of the first pass are scaled up by PASS1_BITS bits so that
+ * they are represented to better-than-integral precision. These outputs
+ * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
+ * with the recommended scaling. (For 12-bit sample data, the intermediate
+ * array is INT32 anyway.)
+ *
+ * To avoid overflow of the 32-bit intermediate results in pass 2, we must
+ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
+ * shows that the values given below are the most effective.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 13
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 13
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 13
+#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
+#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
+#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
+#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
+#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
+#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
+#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
+#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
+#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
+#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
+#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
+#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
+#else
+#define FIX_0_298631336 FIX(0.298631336)
+#define FIX_0_390180644 FIX(0.390180644)
+#define FIX_0_541196100 FIX(0.541196100)
+#define FIX_0_765366865 FIX(0.765366865)
+#define FIX_0_899976223 FIX(0.899976223)
+#define FIX_1_175875602 FIX(1.175875602)
+#define FIX_1_501321110 FIX(1.501321110)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_1_961570560 FIX(1.961570560)
+#define FIX_2_053119869 FIX(2.053119869)
+#define FIX_2_562915447 FIX(2.562915447)
+#define FIX_3_072711026 FIX(3.072711026)
+#endif
+
+
+/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
+ * For 8-bit samples with the recommended scaling, all the variable
+ * and constant values involved are no more than 16 bits wide, so a
+ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
+ * For 12-bit samples, a full 32-bit multiplication will be needed.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
+#else
+#define MULTIPLY(var,const) ((var) * (const))
+#endif
+
+
+/*
+ * Perform the forward DCT on one block of samples.
+ */
+
+GLOBAL(void)
+jpeg_fdct_islow (DCTELEM * data)
+{
+ INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ INT32 tmp10, tmp11, tmp12, tmp13;
+ INT32 z1, z2, z3, z4, z5;
+ DCTELEM *dataptr;
+ int ctr;
+ SHIFT_TEMPS
+
+ /* Pass 1: process rows. */
+ /* Note results are scaled up by sqrt(8) compared to a true DCT; */
+ /* furthermore, we scale the results by 2**PASS1_BITS. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[0] + dataptr[7];
+ tmp7 = dataptr[0] - dataptr[7];
+ tmp1 = dataptr[1] + dataptr[6];
+ tmp6 = dataptr[1] - dataptr[6];
+ tmp2 = dataptr[2] + dataptr[5];
+ tmp5 = dataptr[2] - dataptr[5];
+ tmp3 = dataptr[3] + dataptr[4];
+ tmp4 = dataptr[3] - dataptr[4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
+ dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS-PASS1_BITS);
+ dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS-PASS1_BITS);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
+ dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
+
+ dataptr += DCTSIZE; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns.
+ * We remove the PASS1_BITS scaling, but leave the results scaled up
+ * by an overall factor of 8.
+ */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
+ dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS+PASS1_BITS);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
+ CONST_BITS+PASS1_BITS);
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
+
+#endif /* DCT_ISLOW_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jidctflt.c b/osframework/source/ImageLib/jpeg/jidctflt.c
new file mode 100644
index 0000000..5fea54c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jidctflt.c
@@ -0,0 +1,242 @@
+/*
+ * jidctflt.c
+ *
+ * Copyright (C) 1994-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a floating-point implementation of the
+ * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
+ * must also perform dequantization of the input coefficients.
+ *
+ * This implementation should be more accurate than either of the integer
+ * IDCT implementations. However, it may not give the same results on all
+ * machines because of differences in roundoff behavior. Speed will depend
+ * on the hardware's floating point capacity.
+ *
+ * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
+ * on each row (or vice versa, but it's more convenient to emit a row at
+ * a time). Direct algorithms are also available, but they are much more
+ * complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
+ * JPEG textbook (see REFERENCES section in file README). The following code
+ * is based directly on figure 4-8 in P&M.
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
+ * possible to arrange the computation so that many of the multiplies are
+ * simple scalings of the final outputs. These multiplies can then be
+ * folded into the multiplications or divisions by the JPEG quantization
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
+ * to be done in the DCT itself.
+ * The primary disadvantage of this method is that with a fixed-point
+ * implementation, accuracy is lost due to imprecise representation of the
+ * scaled quantization values. However, that problem does not arise if
+ * we use floating point arithmetic.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_FLOAT_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/* Dequantize a coefficient by multiplying it by the multiplier-table
+ * entry; produce a float result.
+ */
+
+#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients.
+ */
+
+GLOBAL(void)
+jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
+ FAST_FLOAT z5, z10, z11, z12, z13;
+ JCOEFPTR inptr;
+ FLOAT_MULT_TYPE * quantptr;
+ FAST_FLOAT * wsptr;
+ JSAMPROW outptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ int ctr;
+ FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
+ SHIFT_TEMPS
+
+ /* Pass 1: process columns from input, store into work array. */
+
+ inptr = coef_block;
+ quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
+ wsptr = workspace;
+ for (ctr = DCTSIZE; ctr > 0; ctr--) {
+ /* Due to quantization, we will usually find that many of the input
+ * coefficients are zero, especially the AC terms. We can exploit this
+ * by short-circuiting the IDCT calculation for any column in which all
+ * the AC terms are zero. In that case each output is equal to the
+ * DC coefficient (with scale factor as needed).
+ * With typical images and quantization tables, half or more of the
+ * column DCT calculations can be simplified this way.
+ */
+
+ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
+ inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
+ inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
+ inptr[DCTSIZE*7] == 0) {
+ /* AC terms all zero */
+ FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+
+ wsptr[DCTSIZE*0] = dcval;
+ wsptr[DCTSIZE*1] = dcval;
+ wsptr[DCTSIZE*2] = dcval;
+ wsptr[DCTSIZE*3] = dcval;
+ wsptr[DCTSIZE*4] = dcval;
+ wsptr[DCTSIZE*5] = dcval;
+ wsptr[DCTSIZE*6] = dcval;
+ wsptr[DCTSIZE*7] = dcval;
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ continue;
+ }
+
+ /* Even part */
+
+ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+ tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
+ tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
+ tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
+
+ tmp10 = tmp0 + tmp2; /* phase 3 */
+ tmp11 = tmp0 - tmp2;
+
+ tmp13 = tmp1 + tmp3; /* phases 5-3 */
+ tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
+
+ tmp0 = tmp10 + tmp13; /* phase 2 */
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ /* Odd part */
+
+ tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
+ tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
+ tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
+ tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
+
+ z13 = tmp6 + tmp5; /* phase 6 */
+ z10 = tmp6 - tmp5;
+ z11 = tmp4 + tmp7;
+ z12 = tmp4 - tmp7;
+
+ tmp7 = z11 + z13; /* phase 5 */
+ tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
+
+ z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
+ tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
+ tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
+
+ tmp6 = tmp12 - tmp7; /* phase 2 */
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ wsptr[DCTSIZE*0] = tmp0 + tmp7;
+ wsptr[DCTSIZE*7] = tmp0 - tmp7;
+ wsptr[DCTSIZE*1] = tmp1 + tmp6;
+ wsptr[DCTSIZE*6] = tmp1 - tmp6;
+ wsptr[DCTSIZE*2] = tmp2 + tmp5;
+ wsptr[DCTSIZE*5] = tmp2 - tmp5;
+ wsptr[DCTSIZE*4] = tmp3 + tmp4;
+ wsptr[DCTSIZE*3] = tmp3 - tmp4;
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ }
+
+ /* Pass 2: process rows from work array, store into output array. */
+ /* Note that we must descale the results by a factor of 8 == 2**3. */
+
+ wsptr = workspace;
+ for (ctr = 0; ctr < DCTSIZE; ctr++) {
+ outptr = output_buf[ctr] + output_col;
+ /* Rows of zeroes can be exploited in the same way as we did with columns.
+ * However, the column calculation has created many nonzero AC terms, so
+ * the simplification applies less often (typically 5% to 10% of the time).
+ * And testing floats for zero is relatively expensive, so we don't bother.
+ */
+
+ /* Even part */
+
+ tmp10 = wsptr[0] + wsptr[4];
+ tmp11 = wsptr[0] - wsptr[4];
+
+ tmp13 = wsptr[2] + wsptr[6];
+ tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
+
+ tmp0 = tmp10 + tmp13;
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ /* Odd part */
+
+ z13 = wsptr[5] + wsptr[3];
+ z10 = wsptr[5] - wsptr[3];
+ z11 = wsptr[1] + wsptr[7];
+ z12 = wsptr[1] - wsptr[7];
+
+ tmp7 = z11 + z13;
+ tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
+
+ z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
+ tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
+ tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
+
+ tmp6 = tmp12 - tmp7;
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ /* Final output stage: scale down by a factor of 8 and range-limit */
+
+ outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
+ & RANGE_MASK];
+ outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
+ & RANGE_MASK];
+ outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
+ & RANGE_MASK];
+ outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
+ & RANGE_MASK];
+ outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
+ & RANGE_MASK];
+ outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
+ & RANGE_MASK];
+ outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
+ & RANGE_MASK];
+ outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
+ & RANGE_MASK];
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+#endif /* DCT_FLOAT_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jidctfst.c b/osframework/source/ImageLib/jpeg/jidctfst.c
new file mode 100644
index 0000000..078b8c4
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jidctfst.c
@@ -0,0 +1,368 @@
+/*
+ * jidctfst.c
+ *
+ * Copyright (C) 1994-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a fast, not so accurate integer implementation of the
+ * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
+ * must also perform dequantization of the input coefficients.
+ *
+ * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
+ * on each row (or vice versa, but it's more convenient to emit a row at
+ * a time). Direct algorithms are also available, but they are much more
+ * complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
+ * JPEG textbook (see REFERENCES section in file README). The following code
+ * is based directly on figure 4-8 in P&M.
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
+ * possible to arrange the computation so that many of the multiplies are
+ * simple scalings of the final outputs. These multiplies can then be
+ * folded into the multiplications or divisions by the JPEG quantization
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
+ * to be done in the DCT itself.
+ * The primary disadvantage of this method is that with fixed-point math,
+ * accuracy is lost due to imprecise representation of the scaled
+ * quantization values. The smaller the quantization table entry, the less
+ * precise the scaled value, so this implementation does worse with high-
+ * quality-setting files than with low-quality ones.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_IFAST_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/* Scaling decisions are generally the same as in the LL&M algorithm;
+ * see jidctint.c for more details. However, we choose to descale
+ * (right shift) multiplication products as soon as they are formed,
+ * rather than carrying additional fractional bits into subsequent additions.
+ * This compromises accuracy slightly, but it lets us save a few shifts.
+ * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
+ * everywhere except in the multiplications proper; this saves a good deal
+ * of work on 16-bit-int machines.
+ *
+ * The dequantized coefficients are not integers because the AA&N scaling
+ * factors have been incorporated. We represent them scaled up by PASS1_BITS,
+ * so that the first and second IDCT rounds have the same input scaling.
+ * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
+ * avoid a descaling shift; this compromises accuracy rather drastically
+ * for small quantization table entries, but it saves a lot of shifts.
+ * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
+ * so we use a much larger scaling factor to preserve accuracy.
+ *
+ * A final compromise is to represent the multiplicative constants to only
+ * 8 fractional bits, rather than 13. This saves some shifting work on some
+ * machines, and may also reduce the cost of multiplication (since there
+ * are fewer one-bits in the constants).
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 8
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 8
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 8
+#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
+#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
+#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
+#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
+#else
+#define FIX_1_082392200 FIX(1.082392200)
+#define FIX_1_414213562 FIX(1.414213562)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_2_613125930 FIX(2.613125930)
+#endif
+
+
+/* We can gain a little more speed, with a further compromise in accuracy,
+ * by omitting the addition in a descaling shift. This yields an incorrectly
+ * rounded result half the time...
+ */
+
+#ifndef USE_ACCURATE_ROUNDING
+#undef DESCALE
+#define DESCALE(x,n) RIGHT_SHIFT(x, n)
+#endif
+
+
+/* Multiply a DCTELEM variable by an INT32 constant, and immediately
+ * descale to yield a DCTELEM result.
+ */
+
+#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
+
+
+/* Dequantize a coefficient by multiplying it by the multiplier-table
+ * entry; produce a DCTELEM result. For 8-bit data a 16x16->16
+ * multiplication will do. For 12-bit data, the multiplier table is
+ * declared INT32, so a 32-bit multiply will be used.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
+#else
+#define DEQUANTIZE(coef,quantval) \
+ DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
+#endif
+
+
+/* Like DESCALE, but applies to a DCTELEM and produces an int.
+ * We assume that int right shift is unsigned if INT32 right shift is.
+ */
+
+#ifdef RIGHT_SHIFT_IS_UNSIGNED
+#define ISHIFT_TEMPS DCTELEM ishift_temp;
+#if BITS_IN_JSAMPLE == 8
+#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
+#else
+#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
+#endif
+#define IRIGHT_SHIFT(x,shft) \
+ ((ishift_temp = (x)) < 0 ? \
+ (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
+ (ishift_temp >> (shft)))
+#else
+#define ISHIFT_TEMPS
+#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
+#endif
+
+#ifdef USE_ACCURATE_ROUNDING
+#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
+#else
+#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
+#endif
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients.
+ */
+
+GLOBAL(void)
+jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ DCTELEM tmp10, tmp11, tmp12, tmp13;
+ DCTELEM z5, z10, z11, z12, z13;
+ JCOEFPTR inptr;
+ IFAST_MULT_TYPE * quantptr;
+ int * wsptr;
+ JSAMPROW outptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ int ctr;
+ int workspace[DCTSIZE2]; /* buffers data between passes */
+ SHIFT_TEMPS /* for DESCALE */
+ ISHIFT_TEMPS /* for IDESCALE */
+
+ /* Pass 1: process columns from input, store into work array. */
+
+ inptr = coef_block;
+ quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
+ wsptr = workspace;
+ for (ctr = DCTSIZE; ctr > 0; ctr--) {
+ /* Due to quantization, we will usually find that many of the input
+ * coefficients are zero, especially the AC terms. We can exploit this
+ * by short-circuiting the IDCT calculation for any column in which all
+ * the AC terms are zero. In that case each output is equal to the
+ * DC coefficient (with scale factor as needed).
+ * With typical images and quantization tables, half or more of the
+ * column DCT calculations can be simplified this way.
+ */
+
+ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
+ inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
+ inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
+ inptr[DCTSIZE*7] == 0) {
+ /* AC terms all zero */
+ int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+
+ wsptr[DCTSIZE*0] = dcval;
+ wsptr[DCTSIZE*1] = dcval;
+ wsptr[DCTSIZE*2] = dcval;
+ wsptr[DCTSIZE*3] = dcval;
+ wsptr[DCTSIZE*4] = dcval;
+ wsptr[DCTSIZE*5] = dcval;
+ wsptr[DCTSIZE*6] = dcval;
+ wsptr[DCTSIZE*7] = dcval;
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ continue;
+ }
+
+ /* Even part */
+
+ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+ tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
+ tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
+ tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
+
+ tmp10 = tmp0 + tmp2; /* phase 3 */
+ tmp11 = tmp0 - tmp2;
+
+ tmp13 = tmp1 + tmp3; /* phases 5-3 */
+ tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
+
+ tmp0 = tmp10 + tmp13; /* phase 2 */
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ /* Odd part */
+
+ tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
+ tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
+ tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
+ tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
+
+ z13 = tmp6 + tmp5; /* phase 6 */
+ z10 = tmp6 - tmp5;
+ z11 = tmp4 + tmp7;
+ z12 = tmp4 - tmp7;
+
+ tmp7 = z11 + z13; /* phase 5 */
+ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
+
+ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
+ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
+ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
+
+ tmp6 = tmp12 - tmp7; /* phase 2 */
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
+ wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
+ wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
+ wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
+ wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
+ wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
+ wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
+ wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ }
+
+ /* Pass 2: process rows from work array, store into output array. */
+ /* Note that we must descale the results by a factor of 8 == 2**3, */
+ /* and also undo the PASS1_BITS scaling. */
+
+ wsptr = workspace;
+ for (ctr = 0; ctr < DCTSIZE; ctr++) {
+ outptr = output_buf[ctr] + output_col;
+ /* Rows of zeroes can be exploited in the same way as we did with columns.
+ * However, the column calculation has created many nonzero AC terms, so
+ * the simplification applies less often (typically 5% to 10% of the time).
+ * On machines with very fast multiplication, it's possible that the
+ * test takes more time than it's worth. In that case this section
+ * may be commented out.
+ */
+
+#ifndef NO_ZERO_ROW_TEST
+ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
+ wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
+ /* AC terms all zero */
+ JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
+ & RANGE_MASK];
+
+ outptr[0] = dcval;
+ outptr[1] = dcval;
+ outptr[2] = dcval;
+ outptr[3] = dcval;
+ outptr[4] = dcval;
+ outptr[5] = dcval;
+ outptr[6] = dcval;
+ outptr[7] = dcval;
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ continue;
+ }
+#endif
+
+ /* Even part */
+
+ tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
+ tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
+
+ tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
+ tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
+ - tmp13;
+
+ tmp0 = tmp10 + tmp13;
+ tmp3 = tmp10 - tmp13;
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ /* Odd part */
+
+ z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
+ z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
+ z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
+ z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
+
+ tmp7 = z11 + z13; /* phase 5 */
+ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
+
+ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
+ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
+ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
+
+ tmp6 = tmp12 - tmp7; /* phase 2 */
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ /* Final output stage: scale down by a factor of 8 and range-limit */
+
+ outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
+ & RANGE_MASK];
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+#endif /* DCT_IFAST_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jidctint.c b/osframework/source/ImageLib/jpeg/jidctint.c
new file mode 100644
index 0000000..4f47fe8
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jidctint.c
@@ -0,0 +1,389 @@
+/*
+ * jidctint.c
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a slow-but-accurate integer implementation of the
+ * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
+ * must also perform dequantization of the input coefficients.
+ *
+ * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
+ * on each row (or vice versa, but it's more convenient to emit a row at
+ * a time). Direct algorithms are also available, but they are much more
+ * complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on an algorithm described in
+ * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
+ * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
+ * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
+ * The primary algorithm described there uses 11 multiplies and 29 adds.
+ * We use their alternate method with 12 multiplies and 32 adds.
+ * The advantage of this method is that no data path contains more than one
+ * multiplication; this allows a very simple and accurate implementation in
+ * scaled fixed-point arithmetic, with a minimal number of shifts.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef DCT_ISLOW_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/*
+ * The poop on this scaling stuff is as follows:
+ *
+ * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
+ * larger than the true IDCT outputs. The final outputs are therefore
+ * a factor of N larger than desired; since N=8 this can be cured by
+ * a simple right shift at the end of the algorithm. The advantage of
+ * this arrangement is that we save two multiplications per 1-D IDCT,
+ * because the y0 and y4 inputs need not be divided by sqrt(N).
+ *
+ * We have to do addition and subtraction of the integer inputs, which
+ * is no problem, and multiplication by fractional constants, which is
+ * a problem to do in integer arithmetic. We multiply all the constants
+ * by CONST_SCALE and convert them to integer constants (thus retaining
+ * CONST_BITS bits of precision in the constants). After doing a
+ * multiplication we have to divide the product by CONST_SCALE, with proper
+ * rounding, to produce the correct output. This division can be done
+ * cheaply as a right shift of CONST_BITS bits. We postpone shifting
+ * as long as possible so that partial sums can be added together with
+ * full fractional precision.
+ *
+ * The outputs of the first pass are scaled up by PASS1_BITS bits so that
+ * they are represented to better-than-integral precision. These outputs
+ * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
+ * with the recommended scaling. (To scale up 12-bit sample data further, an
+ * intermediate INT32 array would be needed.)
+ *
+ * To avoid overflow of the 32-bit intermediate results in pass 2, we must
+ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
+ * shows that the values given below are the most effective.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 13
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 13
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 13
+#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
+#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
+#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
+#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
+#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
+#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
+#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
+#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
+#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
+#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
+#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
+#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
+#else
+#define FIX_0_298631336 FIX(0.298631336)
+#define FIX_0_390180644 FIX(0.390180644)
+#define FIX_0_541196100 FIX(0.541196100)
+#define FIX_0_765366865 FIX(0.765366865)
+#define FIX_0_899976223 FIX(0.899976223)
+#define FIX_1_175875602 FIX(1.175875602)
+#define FIX_1_501321110 FIX(1.501321110)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_1_961570560 FIX(1.961570560)
+#define FIX_2_053119869 FIX(2.053119869)
+#define FIX_2_562915447 FIX(2.562915447)
+#define FIX_3_072711026 FIX(3.072711026)
+#endif
+
+
+/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
+ * For 8-bit samples with the recommended scaling, all the variable
+ * and constant values involved are no more than 16 bits wide, so a
+ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
+ * For 12-bit samples, a full 32-bit multiplication will be needed.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
+#else
+#define MULTIPLY(var,const) ((var) * (const))
+#endif
+
+
+/* Dequantize a coefficient by multiplying it by the multiplier-table
+ * entry; produce an int result. In this module, both inputs and result
+ * are 16 bits or less, so either int or short multiply will work.
+ */
+
+#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients.
+ */
+
+GLOBAL(void)
+jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ INT32 tmp0, tmp1, tmp2, tmp3;
+ INT32 tmp10, tmp11, tmp12, tmp13;
+ INT32 z1, z2, z3, z4, z5;
+ JCOEFPTR inptr;
+ ISLOW_MULT_TYPE * quantptr;
+ int * wsptr;
+ JSAMPROW outptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ int ctr;
+ int workspace[DCTSIZE2]; /* buffers data between passes */
+ SHIFT_TEMPS
+
+ /* Pass 1: process columns from input, store into work array. */
+ /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
+ /* furthermore, we scale the results by 2**PASS1_BITS. */
+
+ inptr = coef_block;
+ quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
+ wsptr = workspace;
+ for (ctr = DCTSIZE; ctr > 0; ctr--) {
+ /* Due to quantization, we will usually find that many of the input
+ * coefficients are zero, especially the AC terms. We can exploit this
+ * by short-circuiting the IDCT calculation for any column in which all
+ * the AC terms are zero. In that case each output is equal to the
+ * DC coefficient (with scale factor as needed).
+ * With typical images and quantization tables, half or more of the
+ * column DCT calculations can be simplified this way.
+ */
+
+ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
+ inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
+ inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
+ inptr[DCTSIZE*7] == 0) {
+ /* AC terms all zero */
+ int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
+
+ wsptr[DCTSIZE*0] = dcval;
+ wsptr[DCTSIZE*1] = dcval;
+ wsptr[DCTSIZE*2] = dcval;
+ wsptr[DCTSIZE*3] = dcval;
+ wsptr[DCTSIZE*4] = dcval;
+ wsptr[DCTSIZE*5] = dcval;
+ wsptr[DCTSIZE*6] = dcval;
+ wsptr[DCTSIZE*7] = dcval;
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ continue;
+ }
+
+ /* Even part: reverse the even part of the forward DCT. */
+ /* The rotator is sqrt(2)*c(-6). */
+
+ z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
+ z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
+
+ z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
+ tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
+ tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
+
+ z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+ z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
+
+ tmp0 = (z2 + z3) << CONST_BITS;
+ tmp1 = (z2 - z3) << CONST_BITS;
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ /* Odd part per figure 8; the matrix is unitary and hence its
+ * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
+ */
+
+ tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
+ tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
+ tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
+ tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
+
+ z1 = tmp0 + tmp3;
+ z2 = tmp1 + tmp2;
+ z3 = tmp0 + tmp2;
+ z4 = tmp1 + tmp3;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ tmp0 += z1 + z3;
+ tmp1 += z2 + z4;
+ tmp2 += z2 + z3;
+ tmp3 += z1 + z4;
+
+ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
+
+ wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
+ wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
+
+ inptr++; /* advance pointers to next column */
+ quantptr++;
+ wsptr++;
+ }
+
+ /* Pass 2: process rows from work array, store into output array. */
+ /* Note that we must descale the results by a factor of 8 == 2**3, */
+ /* and also undo the PASS1_BITS scaling. */
+
+ wsptr = workspace;
+ for (ctr = 0; ctr < DCTSIZE; ctr++) {
+ outptr = output_buf[ctr] + output_col;
+ /* Rows of zeroes can be exploited in the same way as we did with columns.
+ * However, the column calculation has created many nonzero AC terms, so
+ * the simplification applies less often (typically 5% to 10% of the time).
+ * On machines with very fast multiplication, it's possible that the
+ * test takes more time than it's worth. In that case this section
+ * may be commented out.
+ */
+
+#ifndef NO_ZERO_ROW_TEST
+ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
+ wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
+ /* AC terms all zero */
+ JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
+ & RANGE_MASK];
+
+ outptr[0] = dcval;
+ outptr[1] = dcval;
+ outptr[2] = dcval;
+ outptr[3] = dcval;
+ outptr[4] = dcval;
+ outptr[5] = dcval;
+ outptr[6] = dcval;
+ outptr[7] = dcval;
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ continue;
+ }
+#endif
+
+ /* Even part: reverse the even part of the forward DCT. */
+ /* The rotator is sqrt(2)*c(-6). */
+
+ z2 = (INT32) wsptr[2];
+ z3 = (INT32) wsptr[6];
+
+ z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
+ tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
+ tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
+
+ tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
+ tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ /* Odd part per figure 8; the matrix is unitary and hence its
+ * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
+ */
+
+ tmp0 = (INT32) wsptr[7];
+ tmp1 = (INT32) wsptr[5];
+ tmp2 = (INT32) wsptr[3];
+ tmp3 = (INT32) wsptr[1];
+
+ z1 = tmp0 + tmp3;
+ z2 = tmp1 + tmp2;
+ z3 = tmp0 + tmp2;
+ z4 = tmp1 + tmp3;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ tmp0 += z1 + z3;
+ tmp1 += z2 + z4;
+ tmp2 += z2 + z3;
+ tmp3 += z1 + z4;
+
+ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
+
+ outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+ outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
+ CONST_BITS+PASS1_BITS+3)
+ & RANGE_MASK];
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+#endif /* DCT_ISLOW_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jidctred.c b/osframework/source/ImageLib/jpeg/jidctred.c
new file mode 100644
index 0000000..911899b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jidctred.c
@@ -0,0 +1,398 @@
+/*
+ * jidctred.c
+ *
+ * Copyright (C) 1994-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains inverse-DCT routines that produce reduced-size output:
+ * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
+ *
+ * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
+ * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
+ * with an 8-to-4 step that produces the four averages of two adjacent outputs
+ * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
+ * These steps were derived by computing the corresponding values at the end
+ * of the normal LL&M code, then simplifying as much as possible.
+ *
+ * 1x1 is trivial: just take the DC coefficient divided by 8.
+ *
+ * See jidctint.c for additional comments.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jdct.h" /* Private declarations for DCT subsystem */
+
+#ifdef IDCT_SCALING_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+ Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
+#endif
+
+
+/* Scaling is the same as in jidctint.c. */
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 13
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 13
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 13
+#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
+#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
+#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
+#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
+#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
+#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
+#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
+#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
+#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
+#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
+#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
+#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
+#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
+#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
+#else
+#define FIX_0_211164243 FIX(0.211164243)
+#define FIX_0_509795579 FIX(0.509795579)
+#define FIX_0_601344887 FIX(0.601344887)
+#define FIX_0_720959822 FIX(0.720959822)
+#define FIX_0_765366865 FIX(0.765366865)
+#define FIX_0_850430095 FIX(0.850430095)
+#define FIX_0_899976223 FIX(0.899976223)
+#define FIX_1_061594337 FIX(1.061594337)
+#define FIX_1_272758580 FIX(1.272758580)
+#define FIX_1_451774981 FIX(1.451774981)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_2_172734803 FIX(2.172734803)
+#define FIX_2_562915447 FIX(2.562915447)
+#define FIX_3_624509785 FIX(3.624509785)
+#endif
+
+
+/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
+ * For 8-bit samples with the recommended scaling, all the variable
+ * and constant values involved are no more than 16 bits wide, so a
+ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
+ * For 12-bit samples, a full 32-bit multiplication will be needed.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
+#else
+#define MULTIPLY(var,const) ((var) * (const))
+#endif
+
+
+/* Dequantize a coefficient by multiplying it by the multiplier-table
+ * entry; produce an int result. In this module, both inputs and result
+ * are 16 bits or less, so either int or short multiply will work.
+ */
+
+#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients,
+ * producing a reduced-size 4x4 output block.
+ */
+
+GLOBAL(void)
+jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ INT32 tmp0, tmp2, tmp10, tmp12;
+ INT32 z1, z2, z3, z4;
+ JCOEFPTR inptr;
+ ISLOW_MULT_TYPE * quantptr;
+ int * wsptr;
+ JSAMPROW outptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ int ctr;
+ int workspace[DCTSIZE*4]; /* buffers data between passes */
+ SHIFT_TEMPS
+
+ /* Pass 1: process columns from input, store into work array. */
+
+ inptr = coef_block;
+ quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
+ wsptr = workspace;
+ for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
+ /* Don't bother to process column 4, because second pass won't use it */
+ if (ctr == DCTSIZE-4)
+ continue;
+ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
+ inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
+ inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
+ /* AC terms all zero; we need not examine term 4 for 4x4 output */
+ int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
+
+ wsptr[DCTSIZE*0] = dcval;
+ wsptr[DCTSIZE*1] = dcval;
+ wsptr[DCTSIZE*2] = dcval;
+ wsptr[DCTSIZE*3] = dcval;
+
+ continue;
+ }
+
+ /* Even part */
+
+ tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+ tmp0 <<= (CONST_BITS+1);
+
+ z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
+ z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
+
+ tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
+
+ tmp10 = tmp0 + tmp2;
+ tmp12 = tmp0 - tmp2;
+
+ /* Odd part */
+
+ z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
+ z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
+ z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
+ z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
+
+ tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
+ + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
+ + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
+ + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
+
+ tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
+ + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
+ + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
+ + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
+
+ /* Final output stage */
+
+ wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
+ wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
+ wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
+ wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
+ }
+
+ /* Pass 2: process 4 rows from work array, store into output array. */
+
+ wsptr = workspace;
+ for (ctr = 0; ctr < 4; ctr++) {
+ outptr = output_buf[ctr] + output_col;
+ /* It's not clear whether a zero row test is worthwhile here ... */
+
+#ifndef NO_ZERO_ROW_TEST
+ if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
+ wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
+ /* AC terms all zero */
+ JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
+ & RANGE_MASK];
+
+ outptr[0] = dcval;
+ outptr[1] = dcval;
+ outptr[2] = dcval;
+ outptr[3] = dcval;
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ continue;
+ }
+#endif
+
+ /* Even part */
+
+ tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
+
+ tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
+ + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
+
+ tmp10 = tmp0 + tmp2;
+ tmp12 = tmp0 - tmp2;
+
+ /* Odd part */
+
+ z1 = (INT32) wsptr[7];
+ z2 = (INT32) wsptr[5];
+ z3 = (INT32) wsptr[3];
+ z4 = (INT32) wsptr[1];
+
+ tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
+ + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
+ + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
+ + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
+
+ tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
+ + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
+ + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
+ + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
+
+ /* Final output stage */
+
+ outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
+ CONST_BITS+PASS1_BITS+3+1)
+ & RANGE_MASK];
+ outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
+ CONST_BITS+PASS1_BITS+3+1)
+ & RANGE_MASK];
+ outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
+ CONST_BITS+PASS1_BITS+3+1)
+ & RANGE_MASK];
+ outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
+ CONST_BITS+PASS1_BITS+3+1)
+ & RANGE_MASK];
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients,
+ * producing a reduced-size 2x2 output block.
+ */
+
+GLOBAL(void)
+jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ INT32 tmp0, tmp10, z1;
+ JCOEFPTR inptr;
+ ISLOW_MULT_TYPE * quantptr;
+ int * wsptr;
+ JSAMPROW outptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ int ctr;
+ int workspace[DCTSIZE*2]; /* buffers data between passes */
+ SHIFT_TEMPS
+
+ /* Pass 1: process columns from input, store into work array. */
+
+ inptr = coef_block;
+ quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
+ wsptr = workspace;
+ for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
+ /* Don't bother to process columns 2,4,6 */
+ if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
+ continue;
+ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
+ inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
+ /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
+ int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
+
+ wsptr[DCTSIZE*0] = dcval;
+ wsptr[DCTSIZE*1] = dcval;
+
+ continue;
+ }
+
+ /* Even part */
+
+ z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
+ tmp10 = z1 << (CONST_BITS+2);
+
+ /* Odd part */
+
+ z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
+ tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
+ z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
+ tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
+ z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
+ tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
+ z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
+ tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
+
+ /* Final output stage */
+
+ wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
+ wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
+ }
+
+ /* Pass 2: process 2 rows from work array, store into output array. */
+
+ wsptr = workspace;
+ for (ctr = 0; ctr < 2; ctr++) {
+ outptr = output_buf[ctr] + output_col;
+ /* It's not clear whether a zero row test is worthwhile here ... */
+
+#ifndef NO_ZERO_ROW_TEST
+ if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
+ /* AC terms all zero */
+ JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
+ & RANGE_MASK];
+
+ outptr[0] = dcval;
+ outptr[1] = dcval;
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ continue;
+ }
+#endif
+
+ /* Even part */
+
+ tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
+
+ /* Odd part */
+
+ tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
+ + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
+ + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
+ + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
+
+ /* Final output stage */
+
+ outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
+ CONST_BITS+PASS1_BITS+3+2)
+ & RANGE_MASK];
+ outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
+ CONST_BITS+PASS1_BITS+3+2)
+ & RANGE_MASK];
+
+ wsptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients,
+ * producing a reduced-size 1x1 output block.
+ */
+
+GLOBAL(void)
+jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col)
+{
+ int dcval;
+ ISLOW_MULT_TYPE * quantptr;
+ JSAMPLE *range_limit = IDCT_range_limit(cinfo);
+ SHIFT_TEMPS
+
+ /* We hardly need an inverse DCT routine for this: just take the
+ * average pixel value, which is one-eighth of the DC coefficient.
+ */
+ quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
+ dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
+ dcval = (int) DESCALE((INT32) dcval, 3);
+
+ output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
+}
+
+#endif /* IDCT_SCALING_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jinclude.h b/osframework/source/ImageLib/jpeg/jinclude.h
new file mode 100644
index 0000000..5ff60fe
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jinclude.h
@@ -0,0 +1,91 @@
+/*
+ * jinclude.h
+ *
+ * Copyright (C) 1991-1994, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file exists to provide a single place to fix any problems with
+ * including the wrong system include files. (Common problems are taken
+ * care of by the standard jconfig symbols, but on really weird systems
+ * you may have to edit this file.)
+ *
+ * NOTE: this file is NOT intended to be included by applications using the
+ * JPEG library. Most applications need only include jpeglib.h.
+ */
+
+
+/* Include auto-config file to find out which system include files we need. */
+
+#include "jconfig.h" /* auto configuration options */
+#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
+
+/*
+ * We need the NULL macro and size_t typedef.
+ * On an ANSI-conforming system it is sufficient to include <stddef.h>.
+ * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
+ * pull in <sys/types.h> as well.
+ * Note that the core JPEG library does not require <stdio.h>;
+ * only the default error handler and data source/destination modules do.
+ * But we must pull it in because of the references to FILE in jpeglib.h.
+ * You can remove those references if you want to compile without <stdio.h>.
+ */
+
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef NEED_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#include <stdio.h>
+
+/*
+ * We need memory copying and zeroing functions, plus strncpy().
+ * ANSI and System V implementations declare these in <string.h>.
+ * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
+ * Some systems may declare memset and memcpy in <memory.h>.
+ *
+ * NOTE: we assume the size parameters to these functions are of type size_t.
+ * Change the casts in these macros if not!
+ */
+
+#ifdef NEED_BSD_STRINGS
+
+#include <strings.h>
+#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
+#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
+
+#else /* not BSD, assume ANSI/SysV string lib */
+
+#include <string.h>
+#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
+#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
+
+#endif
+
+/*
+ * In ANSI C, and indeed any rational implementation, size_t is also the
+ * type returned by sizeof(). However, it seems there are some irrational
+ * implementations out there, in which sizeof() returns an int even though
+ * size_t is defined as long or unsigned long. To ensure consistent results
+ * we always use this SIZEOF() macro in place of using sizeof() directly.
+ */
+
+#define SIZEOF(object) ((size_t) sizeof(object))
+
+/*
+ * The modules that use fread() and fwrite() always invoke them through
+ * these macros. On some systems you may need to twiddle the argument casts.
+ * CAUTION: argument order is different from underlying functions!
+ */
+
+#define JFREAD(file,buf,sizeofbuf) \
+ ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
+#define JFWRITE(file,buf,sizeofbuf) \
+ ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
diff --git a/osframework/source/ImageLib/jpeg/jmemansi.c b/osframework/source/ImageLib/jpeg/jmemansi.c
new file mode 100644
index 0000000..b5da474
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemansi.c
@@ -0,0 +1,167 @@
+/*
+ * jmemansi.c
+ *
+ * Copyright (C) 1992-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file provides a simple generic implementation of the system-
+ * dependent portion of the JPEG memory manager. This implementation
+ * assumes that you have the ANSI-standard library routine tmpfile().
+ * Also, the problem of determining the amount of memory available
+ * is shoved onto the user.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
+extern void * malloc JPP((size_t size));
+extern void free JPP((void *ptr));
+#endif
+
+#ifndef SEEK_SET /* pre-ANSI systems may not define this; */
+#define SEEK_SET 0 /* if not, assume 0 is correct */
+#endif
+
+
+/*
+ * Memory allocation and freeing are controlled by the regular library
+ * routines malloc() and free().
+ */
+
+GLOBAL(void *)
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * "Large" objects are treated the same as "small" ones.
+ * NB: although we include FAR keywords in the routine declarations,
+ * this file won't actually work in 80x86 small/medium model; at least,
+ * you probably won't be able to process useful-size images in only 64KB.
+ */
+
+GLOBAL(void FAR *)
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void FAR *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * This routine computes the total memory space available for allocation.
+ * It's impossible to do this in a portable way; our current solution is
+ * to make the user tell us (with a default value set at compile time).
+ * If you can actually get the available space, it's a good idea to subtract
+ * a slop factor of 5% or so.
+ */
+
+#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
+#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
+#endif
+
+GLOBAL(long)
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
+ long max_bytes_needed, long already_allocated)
+{
+ return cinfo->mem->max_memory_to_use - already_allocated;
+}
+
+
+/*
+ * Backing store (temporary file) management.
+ * Backing store objects are only used when the value returned by
+ * jpeg_mem_available is less than the total space needed. You can dispense
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
+ */
+
+
+METHODDEF(void)
+read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ if (JFREAD(info->temp_file, buffer_address, byte_count)
+ != (size_t) byte_count)
+ ERREXIT(cinfo, JERR_TFILE_READ);
+}
+
+
+METHODDEF(void)
+write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ if (JFWRITE(info->temp_file, buffer_address, byte_count)
+ != (size_t) byte_count)
+ ERREXIT(cinfo, JERR_TFILE_WRITE);
+}
+
+
+METHODDEF(void)
+close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ fclose(info->temp_file);
+ /* Since this implementation uses tmpfile() to create the file,
+ * no explicit file deletion is needed.
+ */
+}
+
+
+/*
+ * Initial opening of a backing-store object.
+ *
+ * This version uses tmpfile(), which constructs a suitable file name
+ * behind the scenes. We don't have to use info->temp_name[] at all;
+ * indeed, we can't even find out the actual name of the temp file.
+ */
+
+GLOBAL(void)
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ if ((info->temp_file = tmpfile()) == NULL)
+ ERREXITS(cinfo, JERR_TFILE_CREATE, "");
+ info->read_backing_store = read_backing_store;
+ info->write_backing_store = write_backing_store;
+ info->close_backing_store = close_backing_store;
+}
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required.
+ */
+
+GLOBAL(long)
+jpeg_mem_init (j_common_ptr cinfo)
+{
+ return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
+}
+
+GLOBAL(void)
+jpeg_mem_term (j_common_ptr cinfo)
+{
+ /* no work */
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemdos.c b/osframework/source/ImageLib/jpeg/jmemdos.c
new file mode 100644
index 0000000..0955047
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemdos.c
@@ -0,0 +1,638 @@
+/*
+ * jmemdos.c
+ *
+ * Copyright (C) 1992-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file provides an MS-DOS-compatible implementation of the system-
+ * dependent portion of the JPEG memory manager. Temporary data can be
+ * stored in extended or expanded memory as well as in regular DOS files.
+ *
+ * If you use this file, you must be sure that NEED_FAR_POINTERS is defined
+ * if you compile in a small-data memory model; it should NOT be defined if
+ * you use a large-data memory model. This file is not recommended if you
+ * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
+ * Also, this code will NOT work if struct fields are aligned on greater than
+ * 2-byte boundaries.
+ *
+ * Based on code contributed by Ge' Weijers.
+ */
+
+/*
+ * If you have both extended and expanded memory, you may want to change the
+ * order in which they are tried in jopen_backing_store. On a 286 machine
+ * expanded memory is usually faster, since extended memory access involves
+ * an expensive protected-mode-and-back switch. On 386 and better, extended
+ * memory is usually faster. As distributed, the code tries extended memory
+ * first (what? not everyone has a 386? :-).
+ *
+ * You can disable use of extended/expanded memory entirely by altering these
+ * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).
+ */
+
+#ifndef XMS_SUPPORTED
+#define XMS_SUPPORTED 1
+#endif
+#ifndef EMS_SUPPORTED
+#define EMS_SUPPORTED 1
+#endif
+
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare these */
+extern void * malloc JPP((size_t size));
+extern void free JPP((void *ptr));
+extern char * getenv JPP((const char * name));
+#endif
+
+#ifdef NEED_FAR_POINTERS
+
+#ifdef __TURBOC__
+/* These definitions work for Borland C (Turbo C) */
+#include <alloc.h> /* need farmalloc(), farfree() */
+#define far_malloc(x) farmalloc(x)
+#define far_free(x) farfree(x)
+#else
+/* These definitions work for Microsoft C and compatible compilers */
+#include <malloc.h> /* need _fmalloc(), _ffree() */
+#define far_malloc(x) _fmalloc(x)
+#define far_free(x) _ffree(x)
+#endif
+
+#else /* not NEED_FAR_POINTERS */
+
+#define far_malloc(x) malloc(x)
+#define far_free(x) free(x)
+
+#endif /* NEED_FAR_POINTERS */
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#else
+#define READ_BINARY "rb"
+#endif
+
+#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */
+ You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */
+#endif
+
+#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */
+ MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
+#endif
+
+
+/*
+ * Declarations for assembly-language support routines (see jmemdosa.asm).
+ *
+ * The functions are declared "far" as are all their pointer arguments;
+ * this ensures the assembly source code will work regardless of the
+ * compiler memory model. We assume "short" is 16 bits, "long" is 32.
+ */
+
+typedef void far * XMSDRIVER; /* actually a pointer to code */
+typedef struct { /* registers for calling XMS driver */
+ unsigned short ax, dx, bx;
+ void far * ds_si;
+ } XMScontext;
+typedef struct { /* registers for calling EMS driver */
+ unsigned short ax, dx, bx;
+ void far * ds_si;
+ } EMScontext;
+
+extern short far jdos_open JPP((short far * handle, char far * filename));
+extern short far jdos_close JPP((short handle));
+extern short far jdos_seek JPP((short handle, long offset));
+extern short far jdos_read JPP((short handle, void far * buffer,
+ unsigned short count));
+extern short far jdos_write JPP((short handle, void far * buffer,
+ unsigned short count));
+extern void far jxms_getdriver JPP((XMSDRIVER far *));
+extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
+extern short far jems_available JPP((void));
+extern void far jems_calldriver JPP((EMScontext far *));
+
+
+/*
+ * Selection of a file name for a temporary file.
+ * This is highly system-dependent, and you may want to customize it.
+ */
+
+static int next_file_num; /* to distinguish among several temp files */
+
+LOCAL(void)
+select_file_name (char * fname)
+{
+ const char * env;
+ char * ptr;
+ FILE * tfile;
+
+ /* Keep generating file names till we find one that's not in use */
+ for (;;) {
+ /* Get temp directory name from environment TMP or TEMP variable;
+ * if none, use "."
+ */
+ if ((env = (const char *) getenv("TMP")) == NULL)
+ if ((env = (const char *) getenv("TEMP")) == NULL)
+ env = ".";
+ if (*env == '\0') /* null string means "." */
+ env = ".";
+ ptr = fname; /* copy name to fname */
+ while (*env != '\0')
+ *ptr++ = *env++;
+ if (ptr[-1] != '\\' && ptr[-1] != '/')
+ *ptr++ = '\\'; /* append backslash if not in env variable */
+ /* Append a suitable file name */
+ next_file_num++; /* advance counter */
+ sprintf(ptr, "JPG%03d.TMP", next_file_num);
+ /* Probe to see if file name is already in use */
+ if ((tfile = fopen(fname, READ_BINARY)) == NULL)
+ break;
+ fclose(tfile); /* oops, it's there; close tfile & try again */
+ }
+}
+
+
+/*
+ * Near-memory allocation and freeing are controlled by the regular library
+ * routines malloc() and free().
+ */
+
+GLOBAL(void *)
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * "Large" objects are allocated in far memory, if possible
+ */
+
+GLOBAL(void FAR *)
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void FAR *) far_malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
+{
+ far_free(object);
+}
+
+
+/*
+ * This routine computes the total memory space available for allocation.
+ * It's impossible to do this in a portable way; our current solution is
+ * to make the user tell us (with a default value set at compile time).
+ * If you can actually get the available space, it's a good idea to subtract
+ * a slop factor of 5% or so.
+ */
+
+#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
+#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */
+#endif
+
+GLOBAL(long)
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
+ long max_bytes_needed, long already_allocated)
+{
+ return cinfo->mem->max_memory_to_use - already_allocated;
+}
+
+
+/*
+ * Backing store (temporary file) management.
+ * Backing store objects are only used when the value returned by
+ * jpeg_mem_available is less than the total space needed. You can dispense
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
+ */
+
+/*
+ * For MS-DOS we support three types of backing storage:
+ * 1. Conventional DOS files. We access these by direct DOS calls rather
+ * than via the stdio package. This provides a bit better performance,
+ * but the real reason is that the buffers to be read or written are FAR.
+ * The stdio library for small-data memory models can't cope with that.
+ * 2. Extended memory, accessed per the XMS V2.0 specification.
+ * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
+ * You'll need copies of those specs to make sense of the related code.
+ * The specs are available by Internet FTP from the SIMTEL archives
+ * (oak.oakland.edu and its various mirror sites). See files
+ * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.
+ */
+
+
+/*
+ * Access methods for a DOS file.
+ */
+
+
+METHODDEF(void)
+read_file_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (jdos_seek(info->handle.file_handle, file_offset))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
+ if (byte_count > 65535L) /* safety check */
+ ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
+ if (jdos_read(info->handle.file_handle, buffer_address,
+ (unsigned short) byte_count))
+ ERREXIT(cinfo, JERR_TFILE_READ);
+}
+
+
+METHODDEF(void)
+write_file_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (jdos_seek(info->handle.file_handle, file_offset))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
+ if (byte_count > 65535L) /* safety check */
+ ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
+ if (jdos_write(info->handle.file_handle, buffer_address,
+ (unsigned short) byte_count))
+ ERREXIT(cinfo, JERR_TFILE_WRITE);
+}
+
+
+METHODDEF(void)
+close_file_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ jdos_close(info->handle.file_handle); /* close the file */
+ remove(info->temp_name); /* delete the file */
+/* If your system doesn't have remove(), try unlink() instead.
+ * remove() is the ANSI-standard name for this function, but
+ * unlink() was more common in pre-ANSI systems.
+ */
+ TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
+}
+
+
+LOCAL(boolean)
+open_file_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ short handle;
+
+ select_file_name(info->temp_name);
+ if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
+ /* might as well exit since jpeg_open_backing_store will fail anyway */
+ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
+ return FALSE;
+ }
+ info->handle.file_handle = handle;
+ info->read_backing_store = read_file_store;
+ info->write_backing_store = write_file_store;
+ info->close_backing_store = close_file_store;
+ TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
+ return TRUE; /* succeeded */
+}
+
+
+/*
+ * Access methods for extended memory.
+ */
+
+#if XMS_SUPPORTED
+
+static XMSDRIVER xms_driver; /* saved address of XMS driver */
+
+typedef union { /* either long offset or real-mode pointer */
+ long offset;
+ void far * ptr;
+ } XMSPTR;
+
+typedef struct { /* XMS move specification structure */
+ long length;
+ XMSH src_handle;
+ XMSPTR src;
+ XMSH dst_handle;
+ XMSPTR dst;
+ } XMSspec;
+
+#define ODD(X) (((X) & 1L) != 0)
+
+
+METHODDEF(void)
+read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ XMScontext ctx;
+ XMSspec spec;
+ char endbuffer[2];
+
+ /* The XMS driver can't cope with an odd length, so handle the last byte
+ * specially if byte_count is odd. We don't expect this to be common.
+ */
+
+ spec.length = byte_count & (~ 1L);
+ spec.src_handle = info->handle.xms_handle;
+ spec.src.offset = file_offset;
+ spec.dst_handle = 0;
+ spec.dst.ptr = buffer_address;
+
+ ctx.ds_si = (void far *) & spec;
+ ctx.ax = 0x0b00; /* EMB move */
+ jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
+ if (ctx.ax != 1)
+ ERREXIT(cinfo, JERR_XMS_READ);
+
+ if (ODD(byte_count)) {
+ read_xms_store(cinfo, info, (void FAR *) endbuffer,
+ file_offset + byte_count - 1L, 2L);
+ ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
+ }
+}
+
+
+METHODDEF(void)
+write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ XMScontext ctx;
+ XMSspec spec;
+ char endbuffer[2];
+
+ /* The XMS driver can't cope with an odd length, so handle the last byte
+ * specially if byte_count is odd. We don't expect this to be common.
+ */
+
+ spec.length = byte_count & (~ 1L);
+ spec.src_handle = 0;
+ spec.src.ptr = buffer_address;
+ spec.dst_handle = info->handle.xms_handle;
+ spec.dst.offset = file_offset;
+
+ ctx.ds_si = (void far *) & spec;
+ ctx.ax = 0x0b00; /* EMB move */
+ jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
+ if (ctx.ax != 1)
+ ERREXIT(cinfo, JERR_XMS_WRITE);
+
+ if (ODD(byte_count)) {
+ read_xms_store(cinfo, info, (void FAR *) endbuffer,
+ file_offset + byte_count - 1L, 2L);
+ endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
+ write_xms_store(cinfo, info, (void FAR *) endbuffer,
+ file_offset + byte_count - 1L, 2L);
+ }
+}
+
+
+METHODDEF(void)
+close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ XMScontext ctx;
+
+ ctx.dx = info->handle.xms_handle;
+ ctx.ax = 0x0a00;
+ jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
+ TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
+ /* we ignore any error return from the driver */
+}
+
+
+LOCAL(boolean)
+open_xms_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ XMScontext ctx;
+
+ /* Get address of XMS driver */
+ jxms_getdriver((XMSDRIVER far *) & xms_driver);
+ if (xms_driver == NULL)
+ return FALSE; /* no driver to be had */
+
+ /* Get version number, must be >= 2.00 */
+ ctx.ax = 0x0000;
+ jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
+ if (ctx.ax < (unsigned short) 0x0200)
+ return FALSE;
+
+ /* Try to get space (expressed in kilobytes) */
+ ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
+ ctx.ax = 0x0900;
+ jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
+ if (ctx.ax != 1)
+ return FALSE;
+
+ /* Succeeded, save the handle and away we go */
+ info->handle.xms_handle = ctx.dx;
+ info->read_backing_store = read_xms_store;
+ info->write_backing_store = write_xms_store;
+ info->close_backing_store = close_xms_store;
+ TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
+ return TRUE; /* succeeded */
+}
+
+#endif /* XMS_SUPPORTED */
+
+
+/*
+ * Access methods for expanded memory.
+ */
+
+#if EMS_SUPPORTED
+
+/* The EMS move specification structure requires word and long fields aligned
+ * at odd byte boundaries. Some compilers will align struct fields at even
+ * byte boundaries. While it's usually possible to force byte alignment,
+ * that causes an overall performance penalty and may pose problems in merging
+ * JPEG into a larger application. Instead we accept some rather dirty code
+ * here. Note this code would fail if the hardware did not allow odd-byte
+ * word & long accesses, but all 80x86 CPUs do.
+ */
+
+typedef void far * EMSPTR;
+
+typedef union { /* EMS move specification structure */
+ long length; /* It's easy to access first 4 bytes */
+ char bytes[18]; /* Misaligned fields in here! */
+ } EMSspec;
+
+/* Macros for accessing misaligned fields */
+#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset])))
+#define SRC_TYPE(spec) FIELD_AT(spec,4,char)
+#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH)
+#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short)
+#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short)
+#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR)
+#define DST_TYPE(spec) FIELD_AT(spec,11,char)
+#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH)
+#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short)
+#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short)
+#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR)
+
+#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */
+
+#define HIBYTE(W) (((W) >> 8) & 0xFF)
+#define LOBYTE(W) ((W) & 0xFF)
+
+
+METHODDEF(void)
+read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ EMScontext ctx;
+ EMSspec spec;
+
+ spec.length = byte_count;
+ SRC_TYPE(spec) = 1;
+ SRC_HANDLE(spec) = info->handle.ems_handle;
+ SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
+ SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
+ DST_TYPE(spec) = 0;
+ DST_HANDLE(spec) = 0;
+ DST_PTR(spec) = buffer_address;
+
+ ctx.ds_si = (void far *) & spec;
+ ctx.ax = 0x5700; /* move memory region */
+ jems_calldriver((EMScontext far *) & ctx);
+ if (HIBYTE(ctx.ax) != 0)
+ ERREXIT(cinfo, JERR_EMS_READ);
+}
+
+
+METHODDEF(void)
+write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ EMScontext ctx;
+ EMSspec spec;
+
+ spec.length = byte_count;
+ SRC_TYPE(spec) = 0;
+ SRC_HANDLE(spec) = 0;
+ SRC_PTR(spec) = buffer_address;
+ DST_TYPE(spec) = 1;
+ DST_HANDLE(spec) = info->handle.ems_handle;
+ DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
+ DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
+
+ ctx.ds_si = (void far *) & spec;
+ ctx.ax = 0x5700; /* move memory region */
+ jems_calldriver((EMScontext far *) & ctx);
+ if (HIBYTE(ctx.ax) != 0)
+ ERREXIT(cinfo, JERR_EMS_WRITE);
+}
+
+
+METHODDEF(void)
+close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ EMScontext ctx;
+
+ ctx.ax = 0x4500;
+ ctx.dx = info->handle.ems_handle;
+ jems_calldriver((EMScontext far *) & ctx);
+ TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
+ /* we ignore any error return from the driver */
+}
+
+
+LOCAL(boolean)
+open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ EMScontext ctx;
+
+ /* Is EMS driver there? */
+ if (! jems_available())
+ return FALSE;
+
+ /* Get status, make sure EMS is OK */
+ ctx.ax = 0x4000;
+ jems_calldriver((EMScontext far *) & ctx);
+ if (HIBYTE(ctx.ax) != 0)
+ return FALSE;
+
+ /* Get version, must be >= 4.0 */
+ ctx.ax = 0x4600;
+ jems_calldriver((EMScontext far *) & ctx);
+ if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
+ return FALSE;
+
+ /* Try to allocate requested space */
+ ctx.ax = 0x4300;
+ ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
+ jems_calldriver((EMScontext far *) & ctx);
+ if (HIBYTE(ctx.ax) != 0)
+ return FALSE;
+
+ /* Succeeded, save the handle and away we go */
+ info->handle.ems_handle = ctx.dx;
+ info->read_backing_store = read_ems_store;
+ info->write_backing_store = write_ems_store;
+ info->close_backing_store = close_ems_store;
+ TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
+ return TRUE; /* succeeded */
+}
+
+#endif /* EMS_SUPPORTED */
+
+
+/*
+ * Initial opening of a backing-store object.
+ */
+
+GLOBAL(void)
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ /* Try extended memory, then expanded memory, then regular file. */
+#if XMS_SUPPORTED
+ if (open_xms_store(cinfo, info, total_bytes_needed))
+ return;
+#endif
+#if EMS_SUPPORTED
+ if (open_ems_store(cinfo, info, total_bytes_needed))
+ return;
+#endif
+ if (open_file_store(cinfo, info, total_bytes_needed))
+ return;
+ ERREXITS(cinfo, JERR_TFILE_CREATE, "");
+}
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required.
+ */
+
+GLOBAL(long)
+jpeg_mem_init (j_common_ptr cinfo)
+{
+ next_file_num = 0; /* initialize temp file name generator */
+ return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
+}
+
+GLOBAL(void)
+jpeg_mem_term (j_common_ptr cinfo)
+{
+ /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
+ * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
+ */
+#ifdef NEED_FHEAPMIN
+ _fheapmin();
+#endif
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemdosa.asm b/osframework/source/ImageLib/jpeg/jmemdosa.asm
new file mode 100644
index 0000000..c6ec48b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemdosa.asm
@@ -0,0 +1,379 @@
+;
+; jmemdosa.asm
+;
+; Copyright (C) 1992, Thomas G. Lane.
+; This file is part of the Independent JPEG Group's software.
+; For conditions of distribution and use, see the accompanying README file.
+;
+; This file contains low-level interface routines to support the MS-DOS
+; backing store manager (jmemdos.c). Routines are provided to access disk
+; files through direct DOS calls, and to access XMS and EMS drivers.
+;
+; This file should assemble with Microsoft's MASM or any compatible
+; assembler (including Borland's Turbo Assembler). If you haven't got
+; a compatible assembler, better fall back to jmemansi.c or jmemname.c.
+;
+; To minimize dependence on the C compiler's register usage conventions,
+; we save and restore all 8086 registers, even though most compilers only
+; require SI,DI,DS to be preserved. Also, we use only 16-bit-wide return
+; values, which everybody returns in AX.
+;
+; Based on code contributed by Ge' Weijers.
+;
+
+JMEMDOSA_TXT segment byte public 'CODE'
+
+ assume cs:JMEMDOSA_TXT
+
+ public _jdos_open
+ public _jdos_close
+ public _jdos_seek
+ public _jdos_read
+ public _jdos_write
+ public _jxms_getdriver
+ public _jxms_calldriver
+ public _jems_available
+ public _jems_calldriver
+
+;
+; short far jdos_open (short far * handle, char far * filename)
+;
+; Create and open a temporary file
+;
+_jdos_open proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov cx,0 ; normal file attributes
+ lds dx,dword ptr [bp+10] ; get filename pointer
+ mov ah,3ch ; create file
+ int 21h
+ jc open_err ; if failed, return error code
+ lds bx,dword ptr [bp+6] ; get handle pointer
+ mov word ptr [bx],ax ; save the handle
+ xor ax,ax ; return zero for OK
+open_err: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jdos_open endp
+
+
+;
+; short far jdos_close (short handle)
+;
+; Close the file handle
+;
+_jdos_close proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov bx,word ptr [bp+6] ; file handle
+ mov ah,3eh ; close file
+ int 21h
+ jc close_err ; if failed, return error code
+ xor ax,ax ; return zero for OK
+close_err: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jdos_close endp
+
+
+;
+; short far jdos_seek (short handle, long offset)
+;
+; Set file position
+;
+_jdos_seek proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov bx,word ptr [bp+6] ; file handle
+ mov dx,word ptr [bp+8] ; LS offset
+ mov cx,word ptr [bp+10] ; MS offset
+ mov ax,4200h ; absolute seek
+ int 21h
+ jc seek_err ; if failed, return error code
+ xor ax,ax ; return zero for OK
+seek_err: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jdos_seek endp
+
+
+;
+; short far jdos_read (short handle, void far * buffer, unsigned short count)
+;
+; Read from file
+;
+_jdos_read proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov bx,word ptr [bp+6] ; file handle
+ lds dx,dword ptr [bp+8] ; buffer address
+ mov cx,word ptr [bp+12] ; number of bytes
+ mov ah,3fh ; read file
+ int 21h
+ jc read_err ; if failed, return error code
+ cmp ax,word ptr [bp+12] ; make sure all bytes were read
+ je read_ok
+ mov ax,1 ; else return 1 for not OK
+ jmp short read_err
+read_ok: xor ax,ax ; return zero for OK
+read_err: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jdos_read endp
+
+
+;
+; short far jdos_write (short handle, void far * buffer, unsigned short count)
+;
+; Write to file
+;
+_jdos_write proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov bx,word ptr [bp+6] ; file handle
+ lds dx,dword ptr [bp+8] ; buffer address
+ mov cx,word ptr [bp+12] ; number of bytes
+ mov ah,40h ; write file
+ int 21h
+ jc write_err ; if failed, return error code
+ cmp ax,word ptr [bp+12] ; make sure all bytes written
+ je write_ok
+ mov ax,1 ; else return 1 for not OK
+ jmp short write_err
+write_ok: xor ax,ax ; return zero for OK
+write_err: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jdos_write endp
+
+
+;
+; void far jxms_getdriver (XMSDRIVER far *)
+;
+; Get the address of the XMS driver, or NULL if not available
+;
+_jxms_getdriver proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov ax,4300h ; call multiplex interrupt with
+ int 2fh ; a magic cookie, hex 4300
+ cmp al,80h ; AL should contain hex 80
+ je xmsavail
+ xor dx,dx ; no XMS driver available
+ xor ax,ax ; return a nil pointer
+ jmp short xmsavail_done
+xmsavail: mov ax,4310h ; fetch driver address with
+ int 2fh ; another magic cookie
+ mov dx,es ; copy address to dx:ax
+ mov ax,bx
+xmsavail_done: les bx,dword ptr [bp+6] ; get pointer to return value
+ mov word ptr es:[bx],ax
+ mov word ptr es:[bx+2],dx
+ pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jxms_getdriver endp
+
+
+;
+; void far jxms_calldriver (XMSDRIVER, XMScontext far *)
+;
+; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.
+; These are loaded, the XMS call is performed, and the new values of the
+; AX,DX,BX registers are written back to the context structure.
+;
+_jxms_calldriver proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ les bx,dword ptr [bp+10] ; get XMScontext pointer
+ mov ax,word ptr es:[bx] ; load registers
+ mov dx,word ptr es:[bx+2]
+ mov si,word ptr es:[bx+6]
+ mov ds,word ptr es:[bx+8]
+ mov bx,word ptr es:[bx+4]
+ call dword ptr [bp+6] ; call the driver
+ mov cx,bx ; save returned BX for a sec
+ les bx,dword ptr [bp+10] ; get XMScontext pointer
+ mov word ptr es:[bx],ax ; put back ax,dx,bx
+ mov word ptr es:[bx+2],dx
+ mov word ptr es:[bx+4],cx
+ pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jxms_calldriver endp
+
+
+;
+; short far jems_available (void)
+;
+; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)
+;
+_jems_available proc far
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ mov ax,3567h ; get interrupt vector 67h
+ int 21h
+ push cs
+ pop ds
+ mov di,000ah ; check offs 10 in returned seg
+ lea si,ASCII_device_name ; against literal string
+ mov cx,8
+ cld
+ repe cmpsb
+ jne no_ems
+ mov ax,1 ; match, it's there
+ jmp short avail_done
+no_ems: xor ax,ax ; it's not there
+avail_done: pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ ret
+
+ASCII_device_name db "EMMXXXX0"
+
+_jems_available endp
+
+
+;
+; void far jems_calldriver (EMScontext far *)
+;
+; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers.
+; These are loaded, the EMS trap is performed, and the new values of the
+; AX,DX,BX registers are written back to the context structure.
+;
+_jems_calldriver proc far
+ push bp ; linkage
+ mov bp,sp
+ push si ; save all registers for safety
+ push di
+ push bx
+ push cx
+ push dx
+ push es
+ push ds
+ les bx,dword ptr [bp+6] ; get EMScontext pointer
+ mov ax,word ptr es:[bx] ; load registers
+ mov dx,word ptr es:[bx+2]
+ mov si,word ptr es:[bx+6]
+ mov ds,word ptr es:[bx+8]
+ mov bx,word ptr es:[bx+4]
+ int 67h ; call the EMS driver
+ mov cx,bx ; save returned BX for a sec
+ les bx,dword ptr [bp+6] ; get EMScontext pointer
+ mov word ptr es:[bx],ax ; put back ax,dx,bx
+ mov word ptr es:[bx+2],dx
+ mov word ptr es:[bx+4],cx
+ pop ds ; restore registers and exit
+ pop es
+ pop dx
+ pop cx
+ pop bx
+ pop di
+ pop si
+ pop bp
+ ret
+_jems_calldriver endp
+
+JMEMDOSA_TXT ends
+
+ end
diff --git a/osframework/source/ImageLib/jpeg/jmemmac.c b/osframework/source/ImageLib/jpeg/jmemmac.c
new file mode 100644
index 0000000..a6f043e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemmac.c
@@ -0,0 +1,289 @@
+/*
+ * jmemmac.c
+ *
+ * Copyright (C) 1992-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * jmemmac.c provides an Apple Macintosh implementation of the system-
+ * dependent portion of the JPEG memory manager.
+ *
+ * If you use jmemmac.c, then you must define USE_MAC_MEMMGR in the
+ * JPEG_INTERNALS part of jconfig.h.
+ *
+ * jmemmac.c uses the Macintosh toolbox routines NewPtr and DisposePtr
+ * instead of malloc and free. It accurately determines the amount of
+ * memory available by using CompactMem. Notice that if left to its
+ * own devices, this code can chew up all available space in the
+ * application's zone, with the exception of the rather small "slop"
+ * factor computed in jpeg_mem_available(). The application can ensure
+ * that more space is left over by reducing max_memory_to_use.
+ *
+ * Large images are swapped to disk using temporary files and System 7.0+'s
+ * temporary folder functionality.
+ *
+ * Note that jmemmac.c depends on two features of MacOS that were first
+ * introduced in System 7: FindFolder and the FSSpec-based calls.
+ * If your application uses jmemmac.c and is run under System 6 or earlier,
+ * and the jpeg library decides it needs a temporary file, it will abort,
+ * printing error messages about requiring System 7. (If no temporary files
+ * are created, it will run fine.)
+ *
+ * If you want to use jmemmac.c in an application that might be used with
+ * System 6 or earlier, then you should remove dependencies on FindFolder
+ * and the FSSpec calls. You will need to replace FindFolder with some
+ * other mechanism for finding a place to put temporary files, and you
+ * should replace the FSSpec calls with their HFS equivalents:
+ *
+ * FSpDelete -> HDelete
+ * FSpGetFInfo -> HGetFInfo
+ * FSpCreate -> HCreate
+ * FSpOpenDF -> HOpen *** Note: not HOpenDF ***
+ * FSMakeFSSpec -> (fill in spec by hand.)
+ *
+ * (Use HOpen instead of HOpenDF. HOpen is just a glue-interface to PBHOpen,
+ * which is on all HFS macs. HOpenDF is a System 7 addition which avoids the
+ * ages-old problem of names starting with a period.)
+ *
+ * Contributed by Sam Bushell (jsam@iagu.on.net) and
+ * Dan Gildor (gyld@in-touch.com).
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef USE_MAC_MEMMGR /* make sure user got configuration right */
+ You forgot to define USE_MAC_MEMMGR in jconfig.h. /* deliberate syntax error */
+#endif
+
+#include <Memory.h> /* we use the MacOS memory manager */
+#include <Files.h> /* we use the MacOS File stuff */
+#include <Folders.h> /* we use the MacOS HFS stuff */
+#include <Script.h> /* for smSystemScript */
+#include <Gestalt.h> /* we use Gestalt to test for specific functionality */
+
+#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
+#define TEMP_FILE_NAME "JPG%03d.TMP"
+#endif
+
+static int next_file_num; /* to distinguish among several temp files */
+
+
+/*
+ * Memory allocation and freeing are controlled by the MacOS library
+ * routines NewPtr() and DisposePtr(), which allocate fixed-address
+ * storage. Unfortunately, the IJG library isn't smart enough to cope
+ * with relocatable storage.
+ */
+
+GLOBAL(void *)
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void *) NewPtr(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
+{
+ DisposePtr((Ptr) object);
+}
+
+
+/*
+ * "Large" objects are treated the same as "small" ones.
+ * NB: we include FAR keywords in the routine declarations simply for
+ * consistency with the rest of the IJG code; FAR should expand to empty
+ * on rational architectures like the Mac.
+ */
+
+GLOBAL(void FAR *)
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void FAR *) NewPtr(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
+{
+ DisposePtr((Ptr) object);
+}
+
+
+/*
+ * This routine computes the total memory space available for allocation.
+ */
+
+GLOBAL(long)
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
+ long max_bytes_needed, long already_allocated)
+{
+ long limit = cinfo->mem->max_memory_to_use - already_allocated;
+ long slop, mem;
+
+ /* Don't ask for more than what application has told us we may use */
+ if (max_bytes_needed > limit && limit > 0)
+ max_bytes_needed = limit;
+ /* Find whether there's a big enough free block in the heap.
+ * CompactMem tries to create a contiguous block of the requested size,
+ * and then returns the size of the largest free block (which could be
+ * much more or much less than we asked for).
+ * We add some slop to ensure we don't use up all available memory.
+ */
+ slop = max_bytes_needed / 16 + 32768L;
+ mem = CompactMem(max_bytes_needed + slop) - slop;
+ if (mem < 0)
+ mem = 0; /* sigh, couldn't even get the slop */
+ /* Don't take more than the application says we can have */
+ if (mem > limit && limit > 0)
+ mem = limit;
+ return mem;
+}
+
+
+/*
+ * Backing store (temporary file) management.
+ * Backing store objects are only used when the value returned by
+ * jpeg_mem_available is less than the total space needed. You can dispense
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
+ */
+
+
+METHODDEF(void)
+read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ long bytes = byte_count;
+ long retVal;
+
+ if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+
+ retVal = FSRead ( info->temp_file, &bytes,
+ (unsigned char *) buffer_address );
+ if ( retVal != noErr || bytes != byte_count )
+ ERREXIT(cinfo, JERR_TFILE_READ);
+}
+
+
+METHODDEF(void)
+write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ long bytes = byte_count;
+ long retVal;
+
+ if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+
+ retVal = FSWrite ( info->temp_file, &bytes,
+ (unsigned char *) buffer_address );
+ if ( retVal != noErr || bytes != byte_count )
+ ERREXIT(cinfo, JERR_TFILE_WRITE);
+}
+
+
+METHODDEF(void)
+close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ FSClose ( info->temp_file );
+ FSpDelete ( &(info->tempSpec) );
+}
+
+
+/*
+ * Initial opening of a backing-store object.
+ *
+ * This version uses FindFolder to find the Temporary Items folder,
+ * and puts the temporary file in there.
+ */
+
+GLOBAL(void)
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ short tmpRef, vRefNum;
+ long dirID;
+ FInfo finderInfo;
+ FSSpec theSpec;
+ Str255 fName;
+ OSErr osErr;
+ long gestaltResponse = 0;
+
+ /* Check that FSSpec calls are available. */
+ osErr = Gestalt( gestaltFSAttr, &gestaltResponse );
+ if ( ( osErr != noErr )
+ || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) )
+ ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required");
+ /* TO DO: add a proper error message to jerror.h. */
+
+ /* Check that FindFolder is available. */
+ osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse );
+ if ( ( osErr != noErr )
+ || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) )
+ ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required.");
+ /* TO DO: add a proper error message to jerror.h. */
+
+ osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
+ &vRefNum, &dirID );
+ if ( osErr != noErr )
+ ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable");
+ /* TO DO: Try putting the temp files somewhere else. */
+
+ /* Keep generating file names till we find one that's not in use */
+ for (;;) {
+ next_file_num++; /* advance counter */
+
+ sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num);
+ strcpy ( (Ptr)fName+1, info->temp_name );
+ *fName = strlen (info->temp_name);
+ osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec );
+
+ if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr )
+ break;
+ }
+
+ osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript );
+ if ( osErr != noErr )
+ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
+
+ osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) );
+ if ( osErr != noErr )
+ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
+
+ info->tempSpec = theSpec;
+
+ info->read_backing_store = read_backing_store;
+ info->write_backing_store = write_backing_store;
+ info->close_backing_store = close_backing_store;
+ TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
+}
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required.
+ */
+
+GLOBAL(long)
+jpeg_mem_init (j_common_ptr cinfo)
+{
+ next_file_num = 0;
+
+ /* max_memory_to_use will be initialized to FreeMem()'s result;
+ * the calling application might later reduce it, for example
+ * to leave room to invoke multiple JPEG objects.
+ * Note that FreeMem returns the total number of free bytes;
+ * it may not be possible to allocate a single block of this size.
+ */
+ return FreeMem();
+}
+
+GLOBAL(void)
+jpeg_mem_term (j_common_ptr cinfo)
+{
+ /* no work */
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemmgr.c b/osframework/source/ImageLib/jpeg/jmemmgr.c
new file mode 100644
index 0000000..b636f1b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemmgr.c
@@ -0,0 +1,1118 @@
+/*
+ * jmemmgr.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains the JPEG system-independent memory management
+ * routines. This code is usable across a wide variety of machines; most
+ * of the system dependencies have been isolated in a separate file.
+ * The major functions provided here are:
+ * * pool-based allocation and freeing of memory;
+ * * policy decisions about how to divide available memory among the
+ * virtual arrays;
+ * * control logic for swapping virtual arrays between main memory and
+ * backing storage.
+ * The separate system-dependent file provides the actual backing-storage
+ * access code, and it contains the policy decision about how much total
+ * main memory to use.
+ * This file is system-dependent in the sense that some of its functions
+ * are unnecessary in some systems. For example, if there is enough virtual
+ * memory so that backing storage will never be used, much of the virtual
+ * array control logic could be removed. (Of course, if you have that much
+ * memory then you shouldn't care about a little bit of unused code...)
+ */
+
+#define JPEG_INTERNALS
+#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef NO_GETENV
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
+extern char * getenv JPP((const char * name));
+#endif
+#endif
+
+
+/*
+ * Some important notes:
+ * The allocation routines provided here must never return NULL.
+ * They should exit to error_exit if unsuccessful.
+ *
+ * It's not a good idea to try to merge the sarray and barray routines,
+ * even though they are textually almost the same, because samples are
+ * usually stored as bytes while coefficients are shorts or ints. Thus,
+ * in machines where byte pointers have a different representation from
+ * word pointers, the resulting machine code could not be the same.
+ */
+
+
+/*
+ * Many machines require storage alignment: longs must start on 4-byte
+ * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc()
+ * always returns pointers that are multiples of the worst-case alignment
+ * requirement, and we had better do so too.
+ * There isn't any really portable way to determine the worst-case alignment
+ * requirement. This module assumes that the alignment requirement is
+ * multiples of sizeof(ALIGN_TYPE).
+ * By default, we define ALIGN_TYPE as double. This is necessary on some
+ * workstations (where doubles really do need 8-byte alignment) and will work
+ * fine on nearly everything. If your machine has lesser alignment needs,
+ * you can save a few bytes by making ALIGN_TYPE smaller.
+ * The only place I know of where this will NOT work is certain Macintosh
+ * 680x0 compilers that define double as a 10-byte IEEE extended float.
+ * Doing 10-byte alignment is counterproductive because longwords won't be
+ * aligned well. Put "#define ALIGN_TYPE long" in jconfig.h if you have
+ * such a compiler.
+ */
+
+#ifndef ALIGN_TYPE /* so can override from jconfig.h */
+#define ALIGN_TYPE double
+#endif
+
+
+/*
+ * We allocate objects from "pools", where each pool is gotten with a single
+ * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
+ * overhead within a pool, except for alignment padding. Each pool has a
+ * header with a link to the next pool of the same class.
+ * Small and large pool headers are identical except that the latter's
+ * link pointer must be FAR on 80x86 machines.
+ * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
+ * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
+ * of the alignment requirement of ALIGN_TYPE.
+ */
+
+typedef union small_pool_struct * small_pool_ptr;
+
+typedef union small_pool_struct {
+ struct {
+ small_pool_ptr next; /* next in list of pools */
+ size_t bytes_used; /* how many bytes already used within pool */
+ size_t bytes_left; /* bytes still available in this pool */
+ } hdr;
+ ALIGN_TYPE dummy; /* included in union to ensure alignment */
+} small_pool_hdr;
+
+typedef union large_pool_struct FAR * large_pool_ptr;
+
+typedef union large_pool_struct {
+ struct {
+ large_pool_ptr next; /* next in list of pools */
+ size_t bytes_used; /* how many bytes already used within pool */
+ size_t bytes_left; /* bytes still available in this pool */
+ } hdr;
+ ALIGN_TYPE dummy; /* included in union to ensure alignment */
+} large_pool_hdr;
+
+
+/*
+ * Here is the full definition of a memory manager object.
+ */
+
+typedef struct {
+ struct jpeg_memory_mgr pub; /* public fields */
+
+ /* Each pool identifier (lifetime class) names a linked list of pools. */
+ small_pool_ptr small_list[JPOOL_NUMPOOLS];
+ large_pool_ptr large_list[JPOOL_NUMPOOLS];
+
+ /* Since we only have one lifetime class of virtual arrays, only one
+ * linked list is necessary (for each datatype). Note that the virtual
+ * array control blocks being linked together are actually stored somewhere
+ * in the small-pool list.
+ */
+ jvirt_sarray_ptr virt_sarray_list;
+ jvirt_barray_ptr virt_barray_list;
+
+ /* This counts total space obtained from jpeg_get_small/large */
+ long total_space_allocated;
+
+ /* alloc_sarray and alloc_barray set this value for use by virtual
+ * array routines.
+ */
+ JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
+} my_memory_mgr;
+
+typedef my_memory_mgr * my_mem_ptr;
+
+
+/*
+ * The control blocks for virtual arrays.
+ * Note that these blocks are allocated in the "small" pool area.
+ * System-dependent info for the associated backing store (if any) is hidden
+ * inside the backing_store_info struct.
+ */
+
+struct jvirt_sarray_control {
+ JSAMPARRAY mem_buffer; /* => the in-memory buffer */
+ JDIMENSION rows_in_array; /* total virtual array height */
+ JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
+ JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
+ JDIMENSION rows_in_mem; /* height of memory buffer */
+ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
+ JDIMENSION cur_start_row; /* first logical row # in the buffer */
+ JDIMENSION first_undef_row; /* row # of first uninitialized row */
+ boolean pre_zero; /* pre-zero mode requested? */
+ boolean dirty; /* do current buffer contents need written? */
+ boolean b_s_open; /* is backing-store data valid? */
+ jvirt_sarray_ptr next; /* link to next virtual sarray control block */
+ backing_store_info b_s_info; /* System-dependent control info */
+};
+
+struct jvirt_barray_control {
+ JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
+ JDIMENSION rows_in_array; /* total virtual array height */
+ JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
+ JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
+ JDIMENSION rows_in_mem; /* height of memory buffer */
+ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
+ JDIMENSION cur_start_row; /* first logical row # in the buffer */
+ JDIMENSION first_undef_row; /* row # of first uninitialized row */
+ boolean pre_zero; /* pre-zero mode requested? */
+ boolean dirty; /* do current buffer contents need written? */
+ boolean b_s_open; /* is backing-store data valid? */
+ jvirt_barray_ptr next; /* link to next virtual barray control block */
+ backing_store_info b_s_info; /* System-dependent control info */
+};
+
+
+#ifdef MEM_STATS /* optional extra stuff for statistics */
+
+LOCAL(void)
+print_mem_stats (j_common_ptr cinfo, int pool_id)
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr shdr_ptr;
+ large_pool_ptr lhdr_ptr;
+
+ /* Since this is only a debugging stub, we can cheat a little by using
+ * fprintf directly rather than going through the trace message code.
+ * This is helpful because message parm array can't handle longs.
+ */
+ fprintf(stderr, "Freeing pool %d, total space = %ld\n",
+ pool_id, mem->total_space_allocated);
+
+ for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
+ lhdr_ptr = lhdr_ptr->hdr.next) {
+ fprintf(stderr, " Large chunk used %ld\n",
+ (long) lhdr_ptr->hdr.bytes_used);
+ }
+
+ for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
+ shdr_ptr = shdr_ptr->hdr.next) {
+ fprintf(stderr, " Small chunk used %ld free %ld\n",
+ (long) shdr_ptr->hdr.bytes_used,
+ (long) shdr_ptr->hdr.bytes_left);
+ }
+}
+
+#endif /* MEM_STATS */
+
+
+LOCAL(void)
+out_of_memory (j_common_ptr cinfo, int which)
+/* Report an out-of-memory error and stop execution */
+/* If we compiled MEM_STATS support, report alloc requests before dying */
+{
+#ifdef MEM_STATS
+ cinfo->err->trace_level = 2; /* force self_destruct to report stats */
+#endif
+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
+}
+
+
+/*
+ * Allocation of "small" objects.
+ *
+ * For these, we use pooled storage. When a new pool must be created,
+ * we try to get enough space for the current request plus a "slop" factor,
+ * where the slop will be the amount of leftover space in the new pool.
+ * The speed vs. space tradeoff is largely determined by the slop values.
+ * A different slop value is provided for each pool class (lifetime),
+ * and we also distinguish the first pool of a class from later ones.
+ * NOTE: the values given work fairly well on both 16- and 32-bit-int
+ * machines, but may be too small if longs are 64 bits or more.
+ */
+
+static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
+{
+ 1600, /* first PERMANENT pool */
+ 16000 /* first IMAGE pool */
+};
+
+static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
+{
+ 0, /* additional PERMANENT pools */
+ 5000 /* additional IMAGE pools */
+};
+
+#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
+
+
+METHODDEF(void *)
+alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
+/* Allocate a "small" object */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr hdr_ptr, prev_hdr_ptr;
+ char * data_ptr;
+ size_t odd_bytes, min_request, slop;
+
+ /* Check for unsatisfiable request (do now to ensure no overflow below) */
+ if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
+ out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
+
+ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
+ odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
+ if (odd_bytes > 0)
+ sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
+
+ /* See if space is available in any existing pool */
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+ prev_hdr_ptr = NULL;
+ hdr_ptr = mem->small_list[pool_id];
+ while (hdr_ptr != NULL) {
+ if (hdr_ptr->hdr.bytes_left >= sizeofobject)
+ break; /* found pool with enough space */
+ prev_hdr_ptr = hdr_ptr;
+ hdr_ptr = hdr_ptr->hdr.next;
+ }
+
+ /* Time to make a new pool? */
+ if (hdr_ptr == NULL) {
+ /* min_request is what we need now, slop is what will be leftover */
+ min_request = sizeofobject + SIZEOF(small_pool_hdr);
+ if (prev_hdr_ptr == NULL) /* first pool in class? */
+ slop = first_pool_slop[pool_id];
+ else
+ slop = extra_pool_slop[pool_id];
+ /* Don't ask for more than MAX_ALLOC_CHUNK */
+ if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
+ slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
+ /* Try to get space, if fail reduce slop and try again */
+ for (;;) {
+ hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
+ if (hdr_ptr != NULL)
+ break;
+ slop /= 2;
+ if (slop < MIN_SLOP) /* give up when it gets real small */
+ out_of_memory(cinfo, 2); /* jpeg_get_small failed */
+ }
+ mem->total_space_allocated += min_request + slop;
+ /* Success, initialize the new pool header and add to end of list */
+ hdr_ptr->hdr.next = NULL;
+ hdr_ptr->hdr.bytes_used = 0;
+ hdr_ptr->hdr.bytes_left = sizeofobject + slop;
+ if (prev_hdr_ptr == NULL) /* first pool in class? */
+ mem->small_list[pool_id] = hdr_ptr;
+ else
+ prev_hdr_ptr->hdr.next = hdr_ptr;
+ }
+
+ /* OK, allocate the object from the current pool */
+ data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
+ data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
+ hdr_ptr->hdr.bytes_used += sizeofobject;
+ hdr_ptr->hdr.bytes_left -= sizeofobject;
+
+ return (void *) data_ptr;
+}
+
+
+/*
+ * Allocation of "large" objects.
+ *
+ * The external semantics of these are the same as "small" objects,
+ * except that FAR pointers are used on 80x86. However the pool
+ * management heuristics are quite different. We assume that each
+ * request is large enough that it may as well be passed directly to
+ * jpeg_get_large; the pool management just links everything together
+ * so that we can free it all on demand.
+ * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
+ * structures. The routines that create these structures (see below)
+ * deliberately bunch rows together to ensure a large request size.
+ */
+
+METHODDEF(void FAR *)
+alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
+/* Allocate a "large" object */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ large_pool_ptr hdr_ptr;
+ size_t odd_bytes;
+
+ /* Check for unsatisfiable request (do now to ensure no overflow below) */
+ if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
+ out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
+
+ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
+ odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
+ if (odd_bytes > 0)
+ sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
+
+ /* Always make a new pool */
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
+ SIZEOF(large_pool_hdr));
+ if (hdr_ptr == NULL)
+ out_of_memory(cinfo, 4); /* jpeg_get_large failed */
+ mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
+
+ /* Success, initialize the new pool header and add to list */
+ hdr_ptr->hdr.next = mem->large_list[pool_id];
+ /* We maintain space counts in each pool header for statistical purposes,
+ * even though they are not needed for allocation.
+ */
+ hdr_ptr->hdr.bytes_used = sizeofobject;
+ hdr_ptr->hdr.bytes_left = 0;
+ mem->large_list[pool_id] = hdr_ptr;
+
+ return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
+}
+
+
+/*
+ * Creation of 2-D sample arrays.
+ * The pointers are in near heap, the samples themselves in FAR heap.
+ *
+ * To minimize allocation overhead and to allow I/O of large contiguous
+ * blocks, we allocate the sample rows in groups of as many rows as possible
+ * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
+ * NB: the virtual array control routines, later in this file, know about
+ * this chunking of rows. The rowsperchunk value is left in the mem manager
+ * object so that it can be saved away if this sarray is the workspace for
+ * a virtual array.
+ */
+
+METHODDEF(JSAMPARRAY)
+alloc_sarray (j_common_ptr cinfo, int pool_id,
+ JDIMENSION samplesperrow, JDIMENSION numrows)
+/* Allocate a 2-D sample array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ JSAMPARRAY result;
+ JSAMPROW workspace;
+ JDIMENSION rowsperchunk, currow, i;
+ long ltemp;
+
+ /* Calculate max # of rows allowed in one allocation chunk */
+ ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
+ ((long) samplesperrow * SIZEOF(JSAMPLE));
+ if (ltemp <= 0)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+ if (ltemp < (long) numrows)
+ rowsperchunk = (JDIMENSION) ltemp;
+ else
+ rowsperchunk = numrows;
+ mem->last_rowsperchunk = rowsperchunk;
+
+ /* Get space for row pointers (small object) */
+ result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
+ (size_t) (numrows * SIZEOF(JSAMPROW)));
+
+ /* Get the rows themselves (large objects) */
+ currow = 0;
+ while (currow < numrows) {
+ rowsperchunk = MIN(rowsperchunk, numrows - currow);
+ workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
+ (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
+ * SIZEOF(JSAMPLE)));
+ for (i = rowsperchunk; i > 0; i--) {
+ result[currow++] = workspace;
+ workspace += samplesperrow;
+ }
+ }
+
+ return result;
+}
+
+
+/*
+ * Creation of 2-D coefficient-block arrays.
+ * This is essentially the same as the code for sample arrays, above.
+ */
+
+METHODDEF(JBLOCKARRAY)
+alloc_barray (j_common_ptr cinfo, int pool_id,
+ JDIMENSION blocksperrow, JDIMENSION numrows)
+/* Allocate a 2-D coefficient-block array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ JBLOCKARRAY result;
+ JBLOCKROW workspace;
+ JDIMENSION rowsperchunk, currow, i;
+ long ltemp;
+
+ /* Calculate max # of rows allowed in one allocation chunk */
+ ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
+ ((long) blocksperrow * SIZEOF(JBLOCK));
+ if (ltemp <= 0)
+ ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
+ if (ltemp < (long) numrows)
+ rowsperchunk = (JDIMENSION) ltemp;
+ else
+ rowsperchunk = numrows;
+ mem->last_rowsperchunk = rowsperchunk;
+
+ /* Get space for row pointers (small object) */
+ result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
+ (size_t) (numrows * SIZEOF(JBLOCKROW)));
+
+ /* Get the rows themselves (large objects) */
+ currow = 0;
+ while (currow < numrows) {
+ rowsperchunk = MIN(rowsperchunk, numrows - currow);
+ workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
+ (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
+ * SIZEOF(JBLOCK)));
+ for (i = rowsperchunk; i > 0; i--) {
+ result[currow++] = workspace;
+ workspace += blocksperrow;
+ }
+ }
+
+ return result;
+}
+
+
+/*
+ * About virtual array management:
+ *
+ * The above "normal" array routines are only used to allocate strip buffers
+ * (as wide as the image, but just a few rows high). Full-image-sized buffers
+ * are handled as "virtual" arrays. The array is still accessed a strip at a
+ * time, but the memory manager must save the whole array for repeated
+ * accesses. The intended implementation is that there is a strip buffer in
+ * memory (as high as is possible given the desired memory limit), plus a
+ * backing file that holds the rest of the array.
+ *
+ * The request_virt_array routines are told the total size of the image and
+ * the maximum number of rows that will be accessed at once. The in-memory
+ * buffer must be at least as large as the maxaccess value.
+ *
+ * The request routines create control blocks but not the in-memory buffers.
+ * That is postponed until realize_virt_arrays is called. At that time the
+ * total amount of space needed is known (approximately, anyway), so free
+ * memory can be divided up fairly.
+ *
+ * The access_virt_array routines are responsible for making a specific strip
+ * area accessible (after reading or writing the backing file, if necessary).
+ * Note that the access routines are told whether the caller intends to modify
+ * the accessed strip; during a read-only pass this saves having to rewrite
+ * data to disk. The access routines are also responsible for pre-zeroing
+ * any newly accessed rows, if pre-zeroing was requested.
+ *
+ * In current usage, the access requests are usually for nonoverlapping
+ * strips; that is, successive access start_row numbers differ by exactly
+ * num_rows = maxaccess. This means we can get good performance with simple
+ * buffer dump/reload logic, by making the in-memory buffer be a multiple
+ * of the access height; then there will never be accesses across bufferload
+ * boundaries. The code will still work with overlapping access requests,
+ * but it doesn't handle bufferload overlaps very efficiently.
+ */
+
+
+METHODDEF(jvirt_sarray_ptr)
+request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
+ JDIMENSION samplesperrow, JDIMENSION numrows,
+ JDIMENSION maxaccess)
+/* Request a virtual 2-D sample array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ jvirt_sarray_ptr result;
+
+ /* Only IMAGE-lifetime virtual arrays are currently supported */
+ if (pool_id != JPOOL_IMAGE)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ /* get control block */
+ result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
+ SIZEOF(struct jvirt_sarray_control));
+
+ result->mem_buffer = NULL; /* marks array not yet realized */
+ result->rows_in_array = numrows;
+ result->samplesperrow = samplesperrow;
+ result->maxaccess = maxaccess;
+ result->pre_zero = pre_zero;
+ result->b_s_open = FALSE; /* no associated backing-store object */
+ result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
+ mem->virt_sarray_list = result;
+
+ return result;
+}
+
+
+METHODDEF(jvirt_barray_ptr)
+request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
+ JDIMENSION blocksperrow, JDIMENSION numrows,
+ JDIMENSION maxaccess)
+/* Request a virtual 2-D coefficient-block array */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ jvirt_barray_ptr result;
+
+ /* Only IMAGE-lifetime virtual arrays are currently supported */
+ if (pool_id != JPOOL_IMAGE)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+ /* get control block */
+ result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
+ SIZEOF(struct jvirt_barray_control));
+
+ result->mem_buffer = NULL; /* marks array not yet realized */
+ result->rows_in_array = numrows;
+ result->blocksperrow = blocksperrow;
+ result->maxaccess = maxaccess;
+ result->pre_zero = pre_zero;
+ result->b_s_open = FALSE; /* no associated backing-store object */
+ result->next = mem->virt_barray_list; /* add to list of virtual arrays */
+ mem->virt_barray_list = result;
+
+ return result;
+}
+
+
+METHODDEF(void)
+realize_virt_arrays (j_common_ptr cinfo)
+/* Allocate the in-memory buffers for any unrealized virtual arrays */
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ long space_per_minheight, maximum_space, avail_mem;
+ long minheights, max_minheights;
+ jvirt_sarray_ptr sptr;
+ jvirt_barray_ptr bptr;
+
+ /* Compute the minimum space needed (maxaccess rows in each buffer)
+ * and the maximum space needed (full image height in each buffer).
+ * These may be of use to the system-dependent jpeg_mem_available routine.
+ */
+ space_per_minheight = 0;
+ maximum_space = 0;
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->mem_buffer == NULL) { /* if not realized yet */
+ space_per_minheight += (long) sptr->maxaccess *
+ (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
+ maximum_space += (long) sptr->rows_in_array *
+ (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
+ }
+ }
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->mem_buffer == NULL) { /* if not realized yet */
+ space_per_minheight += (long) bptr->maxaccess *
+ (long) bptr->blocksperrow * SIZEOF(JBLOCK);
+ maximum_space += (long) bptr->rows_in_array *
+ (long) bptr->blocksperrow * SIZEOF(JBLOCK);
+ }
+ }
+
+ if (space_per_minheight <= 0)
+ return; /* no unrealized arrays, no work */
+
+ /* Determine amount of memory to actually use; this is system-dependent. */
+ avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
+ mem->total_space_allocated);
+
+ /* If the maximum space needed is available, make all the buffers full
+ * height; otherwise parcel it out with the same number of minheights
+ * in each buffer.
+ */
+ if (avail_mem >= maximum_space)
+ max_minheights = 1000000000L;
+ else {
+ max_minheights = avail_mem / space_per_minheight;
+ /* If there doesn't seem to be enough space, try to get the minimum
+ * anyway. This allows a "stub" implementation of jpeg_mem_available().
+ */
+ if (max_minheights <= 0)
+ max_minheights = 1;
+ }
+
+ /* Allocate the in-memory buffers and initialize backing store as needed. */
+
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->mem_buffer == NULL) { /* if not realized yet */
+ minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
+ if (minheights <= max_minheights) {
+ /* This buffer fits in memory */
+ sptr->rows_in_mem = sptr->rows_in_array;
+ } else {
+ /* It doesn't fit in memory, create backing store. */
+ sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
+ jpeg_open_backing_store(cinfo, & sptr->b_s_info,
+ (long) sptr->rows_in_array *
+ (long) sptr->samplesperrow *
+ (long) SIZEOF(JSAMPLE));
+ sptr->b_s_open = TRUE;
+ }
+ sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
+ sptr->samplesperrow, sptr->rows_in_mem);
+ sptr->rowsperchunk = mem->last_rowsperchunk;
+ sptr->cur_start_row = 0;
+ sptr->first_undef_row = 0;
+ sptr->dirty = FALSE;
+ }
+ }
+
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->mem_buffer == NULL) { /* if not realized yet */
+ minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
+ if (minheights <= max_minheights) {
+ /* This buffer fits in memory */
+ bptr->rows_in_mem = bptr->rows_in_array;
+ } else {
+ /* It doesn't fit in memory, create backing store. */
+ bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
+ jpeg_open_backing_store(cinfo, & bptr->b_s_info,
+ (long) bptr->rows_in_array *
+ (long) bptr->blocksperrow *
+ (long) SIZEOF(JBLOCK));
+ bptr->b_s_open = TRUE;
+ }
+ bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
+ bptr->blocksperrow, bptr->rows_in_mem);
+ bptr->rowsperchunk = mem->last_rowsperchunk;
+ bptr->cur_start_row = 0;
+ bptr->first_undef_row = 0;
+ bptr->dirty = FALSE;
+ }
+ }
+}
+
+
+LOCAL(void)
+do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
+/* Do backing store read or write of a virtual sample array */
+{
+ long bytesperrow, file_offset, byte_count, rows, thisrow, i;
+
+ bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
+ file_offset = ptr->cur_start_row * bytesperrow;
+ /* Loop to read or write each allocation chunk in mem_buffer */
+ for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
+ /* One chunk, but check for short chunk at end of buffer */
+ rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
+ /* Transfer no more than is currently defined */
+ thisrow = (long) ptr->cur_start_row + i;
+ rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
+ /* Transfer no more than fits in file */
+ rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
+ if (rows <= 0) /* this chunk might be past end of file! */
+ break;
+ byte_count = rows * bytesperrow;
+ if (writing)
+ (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ else
+ (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ file_offset += byte_count;
+ }
+}
+
+
+LOCAL(void)
+do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
+/* Do backing store read or write of a virtual coefficient-block array */
+{
+ long bytesperrow, file_offset, byte_count, rows, thisrow, i;
+
+ bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
+ file_offset = ptr->cur_start_row * bytesperrow;
+ /* Loop to read or write each allocation chunk in mem_buffer */
+ for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
+ /* One chunk, but check for short chunk at end of buffer */
+ rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
+ /* Transfer no more than is currently defined */
+ thisrow = (long) ptr->cur_start_row + i;
+ rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
+ /* Transfer no more than fits in file */
+ rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
+ if (rows <= 0) /* this chunk might be past end of file! */
+ break;
+ byte_count = rows * bytesperrow;
+ if (writing)
+ (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ else
+ (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
+ (void FAR *) ptr->mem_buffer[i],
+ file_offset, byte_count);
+ file_offset += byte_count;
+ }
+}
+
+
+METHODDEF(JSAMPARRAY)
+access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
+ JDIMENSION start_row, JDIMENSION num_rows,
+ boolean writable)
+/* Access the part of a virtual sample array starting at start_row */
+/* and extending for num_rows rows. writable is true if */
+/* caller intends to modify the accessed area. */
+{
+ JDIMENSION end_row = start_row + num_rows;
+ JDIMENSION undef_row;
+
+ /* debugging check */
+ if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
+ ptr->mem_buffer == NULL)
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+
+ /* Make the desired part of the virtual array accessible */
+ if (start_row < ptr->cur_start_row ||
+ end_row > ptr->cur_start_row+ptr->rows_in_mem) {
+ if (! ptr->b_s_open)
+ ERREXIT(cinfo, JERR_VIRTUAL_BUG);
+ /* Flush old buffer contents if necessary */
+ if (ptr->dirty) {
+ do_sarray_io(cinfo, ptr, TRUE);
+ ptr->dirty = FALSE;
+ }
+ /* Decide what part of virtual array to access.
+ * Algorithm: if target address > current window, assume forward scan,
+ * load starting at target address. If target address < current window,
+ * assume backward scan, load so that target area is top of window.
+ * Note that when switching from forward write to forward read, will have
+ * start_row = 0, so the limiting case applies and we load from 0 anyway.
+ */
+ if (start_row > ptr->cur_start_row) {
+ ptr->cur_start_row = start_row;
+ } else {
+ /* use long arithmetic here to avoid overflow & unsigned problems */
+ long ltemp;
+
+ ltemp = (long) end_row - (long) ptr->rows_in_mem;
+ if (ltemp < 0)
+ ltemp = 0; /* don't fall off front end of file */
+ ptr->cur_start_row = (JDIMENSION) ltemp;
+ }
+ /* Read in the selected part of the array.
+ * During the initial write pass, we will do no actual read
+ * because the selected part is all undefined.
+ */
+ do_sarray_io(cinfo, ptr, FALSE);
+ }
+ /* Ensure the accessed part of the array is defined; prezero if needed.
+ * To improve locality of access, we only prezero the part of the array
+ * that the caller is about to access, not the entire in-memory array.
+ */
+ if (ptr->first_undef_row < end_row) {
+ if (ptr->first_undef_row < start_row) {
+ if (writable) /* writer skipped over a section of array */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ undef_row = start_row; /* but reader is allowed to read ahead */
+ } else {
+ undef_row = ptr->first_undef_row;
+ }
+ if (writable)
+ ptr->first_undef_row = end_row;
+ if (ptr->pre_zero) {
+ size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
+ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
+ end_row -= ptr->cur_start_row;
+ while (undef_row < end_row) {
+ jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
+ undef_row++;
+ }
+ } else {
+ if (! writable) /* reader looking at undefined data */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ }
+ }
+ /* Flag the buffer dirty if caller will write in it */
+ if (writable)
+ ptr->dirty = TRUE;
+ /* Return address of proper part of the buffer */
+ return ptr->mem_buffer + (start_row - ptr->cur_start_row);
+}
+
+
+METHODDEF(JBLOCKARRAY)
+access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
+ JDIMENSION start_row, JDIMENSION num_rows,
+ boolean writable)
+/* Access the part of a virtual block array starting at start_row */
+/* and extending for num_rows rows. writable is true if */
+/* caller intends to modify the accessed area. */
+{
+ JDIMENSION end_row = start_row + num_rows;
+ JDIMENSION undef_row;
+
+ /* debugging check */
+ if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
+ ptr->mem_buffer == NULL)
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+
+ /* Make the desired part of the virtual array accessible */
+ if (start_row < ptr->cur_start_row ||
+ end_row > ptr->cur_start_row+ptr->rows_in_mem) {
+ if (! ptr->b_s_open)
+ ERREXIT(cinfo, JERR_VIRTUAL_BUG);
+ /* Flush old buffer contents if necessary */
+ if (ptr->dirty) {
+ do_barray_io(cinfo, ptr, TRUE);
+ ptr->dirty = FALSE;
+ }
+ /* Decide what part of virtual array to access.
+ * Algorithm: if target address > current window, assume forward scan,
+ * load starting at target address. If target address < current window,
+ * assume backward scan, load so that target area is top of window.
+ * Note that when switching from forward write to forward read, will have
+ * start_row = 0, so the limiting case applies and we load from 0 anyway.
+ */
+ if (start_row > ptr->cur_start_row) {
+ ptr->cur_start_row = start_row;
+ } else {
+ /* use long arithmetic here to avoid overflow & unsigned problems */
+ long ltemp;
+
+ ltemp = (long) end_row - (long) ptr->rows_in_mem;
+ if (ltemp < 0)
+ ltemp = 0; /* don't fall off front end of file */
+ ptr->cur_start_row = (JDIMENSION) ltemp;
+ }
+ /* Read in the selected part of the array.
+ * During the initial write pass, we will do no actual read
+ * because the selected part is all undefined.
+ */
+ do_barray_io(cinfo, ptr, FALSE);
+ }
+ /* Ensure the accessed part of the array is defined; prezero if needed.
+ * To improve locality of access, we only prezero the part of the array
+ * that the caller is about to access, not the entire in-memory array.
+ */
+ if (ptr->first_undef_row < end_row) {
+ if (ptr->first_undef_row < start_row) {
+ if (writable) /* writer skipped over a section of array */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ undef_row = start_row; /* but reader is allowed to read ahead */
+ } else {
+ undef_row = ptr->first_undef_row;
+ }
+ if (writable)
+ ptr->first_undef_row = end_row;
+ if (ptr->pre_zero) {
+ size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
+ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
+ end_row -= ptr->cur_start_row;
+ while (undef_row < end_row) {
+ jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
+ undef_row++;
+ }
+ } else {
+ if (! writable) /* reader looking at undefined data */
+ ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
+ }
+ }
+ /* Flag the buffer dirty if caller will write in it */
+ if (writable)
+ ptr->dirty = TRUE;
+ /* Return address of proper part of the buffer */
+ return ptr->mem_buffer + (start_row - ptr->cur_start_row);
+}
+
+
+/*
+ * Release all objects belonging to a specified pool.
+ */
+
+METHODDEF(void)
+free_pool (j_common_ptr cinfo, int pool_id)
+{
+ my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
+ small_pool_ptr shdr_ptr;
+ large_pool_ptr lhdr_ptr;
+ size_t space_freed;
+
+ if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
+ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
+
+#ifdef MEM_STATS
+ if (cinfo->err->trace_level > 1)
+ print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
+#endif
+
+ /* If freeing IMAGE pool, close any virtual arrays first */
+ if (pool_id == JPOOL_IMAGE) {
+ jvirt_sarray_ptr sptr;
+ jvirt_barray_ptr bptr;
+
+ for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
+ if (sptr->b_s_open) { /* there may be no backing store */
+ sptr->b_s_open = FALSE; /* prevent recursive close if error */
+ (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
+ }
+ }
+ mem->virt_sarray_list = NULL;
+ for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
+ if (bptr->b_s_open) { /* there may be no backing store */
+ bptr->b_s_open = FALSE; /* prevent recursive close if error */
+ (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
+ }
+ }
+ mem->virt_barray_list = NULL;
+ }
+
+ /* Release large objects */
+ lhdr_ptr = mem->large_list[pool_id];
+ mem->large_list[pool_id] = NULL;
+
+ while (lhdr_ptr != NULL) {
+ large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
+ space_freed = lhdr_ptr->hdr.bytes_used +
+ lhdr_ptr->hdr.bytes_left +
+ SIZEOF(large_pool_hdr);
+ jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
+ mem->total_space_allocated -= space_freed;
+ lhdr_ptr = next_lhdr_ptr;
+ }
+
+ /* Release small objects */
+ shdr_ptr = mem->small_list[pool_id];
+ mem->small_list[pool_id] = NULL;
+
+ while (shdr_ptr != NULL) {
+ small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
+ space_freed = shdr_ptr->hdr.bytes_used +
+ shdr_ptr->hdr.bytes_left +
+ SIZEOF(small_pool_hdr);
+ jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
+ mem->total_space_allocated -= space_freed;
+ shdr_ptr = next_shdr_ptr;
+ }
+}
+
+
+/*
+ * Close up shop entirely.
+ * Note that this cannot be called unless cinfo->mem is non-NULL.
+ */
+
+METHODDEF(void)
+self_destruct (j_common_ptr cinfo)
+{
+ int pool;
+
+ /* Close all backing store, release all memory.
+ * Releasing pools in reverse order might help avoid fragmentation
+ * with some (brain-damaged) malloc libraries.
+ */
+ for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
+ free_pool(cinfo, pool);
+ }
+
+ /* Release the memory manager control block too. */
+ jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
+ cinfo->mem = NULL; /* ensures I will be called only once */
+
+ jpeg_mem_term(cinfo); /* system-dependent cleanup */
+}
+
+
+/*
+ * Memory manager initialization.
+ * When this is called, only the error manager pointer is valid in cinfo!
+ */
+
+GLOBAL(void)
+jinit_memory_mgr (j_common_ptr cinfo)
+{
+ my_mem_ptr mem;
+ long max_to_use;
+ int pool;
+ size_t test_mac;
+
+ cinfo->mem = NULL; /* for safety if init fails */
+
+ /* Check for configuration errors.
+ * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
+ * doesn't reflect any real hardware alignment requirement.
+ * The test is a little tricky: for X>0, X and X-1 have no one-bits
+ * in common if and only if X is a power of 2, ie has only one one-bit.
+ * Some compilers may give an "unreachable code" warning here; ignore it.
+ */
+ if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
+ ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
+ /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
+ * a multiple of SIZEOF(ALIGN_TYPE).
+ * Again, an "unreachable code" warning may be ignored here.
+ * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
+ */
+ test_mac = (size_t) MAX_ALLOC_CHUNK;
+ if ((long) test_mac != MAX_ALLOC_CHUNK ||
+ (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
+ ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
+
+ max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
+
+ /* Attempt to allocate memory manager's control block */
+ mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
+
+ if (mem == NULL) {
+ jpeg_mem_term(cinfo); /* system-dependent cleanup */
+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
+ }
+
+ /* OK, fill in the method pointers */
+ mem->pub.alloc_small = alloc_small;
+ mem->pub.alloc_large = alloc_large;
+ mem->pub.alloc_sarray = alloc_sarray;
+ mem->pub.alloc_barray = alloc_barray;
+ mem->pub.request_virt_sarray = request_virt_sarray;
+ mem->pub.request_virt_barray = request_virt_barray;
+ mem->pub.realize_virt_arrays = realize_virt_arrays;
+ mem->pub.access_virt_sarray = access_virt_sarray;
+ mem->pub.access_virt_barray = access_virt_barray;
+ mem->pub.free_pool = free_pool;
+ mem->pub.self_destruct = self_destruct;
+
+ /* Make MAX_ALLOC_CHUNK accessible to other modules */
+ mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
+
+ /* Initialize working state */
+ mem->pub.max_memory_to_use = max_to_use;
+
+ for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
+ mem->small_list[pool] = NULL;
+ mem->large_list[pool] = NULL;
+ }
+ mem->virt_sarray_list = NULL;
+ mem->virt_barray_list = NULL;
+
+ mem->total_space_allocated = SIZEOF(my_memory_mgr);
+
+ /* Declare ourselves open for business */
+ cinfo->mem = & mem->pub;
+
+ /* Check for an environment variable JPEGMEM; if found, override the
+ * default max_memory setting from jpeg_mem_init. Note that the
+ * surrounding application may again override this value.
+ * If your system doesn't support getenv(), define NO_GETENV to disable
+ * this feature.
+ */
+#ifndef NO_GETENV
+ { char * memenv;
+
+ if ((memenv = getenv("JPEGMEM")) != NULL) {
+ char ch = 'x';
+
+ if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
+ if (ch == 'm' || ch == 'M')
+ max_to_use *= 1000L;
+ mem->pub.max_memory_to_use = max_to_use * 1000L;
+ }
+ }
+ }
+#endif
+
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemname.c b/osframework/source/ImageLib/jpeg/jmemname.c
new file mode 100644
index 0000000..e28b212
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemname.c
@@ -0,0 +1,276 @@
+/*
+ * jmemname.c
+ *
+ * Copyright (C) 1992-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file provides a generic implementation of the system-dependent
+ * portion of the JPEG memory manager. This implementation assumes that
+ * you must explicitly construct a name for each temp file.
+ * Also, the problem of determining the amount of memory available
+ * is shoved onto the user.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
+extern void * malloc JPP((size_t size));
+extern void free JPP((void *ptr));
+#endif
+
+#ifndef SEEK_SET /* pre-ANSI systems may not define this; */
+#define SEEK_SET 0 /* if not, assume 0 is correct */
+#endif
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#define RW_BINARY "w+"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#define RW_BINARY "w+b", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#define RW_BINARY "w+b"
+#endif
+#endif
+
+
+/*
+ * Selection of a file name for a temporary file.
+ * This is system-dependent!
+ *
+ * The code as given is suitable for most Unix systems, and it is easily
+ * modified for most non-Unix systems. Some notes:
+ * 1. The temp file is created in the directory named by TEMP_DIRECTORY.
+ * The default value is /usr/tmp, which is the conventional place for
+ * creating large temp files on Unix. On other systems you'll probably
+ * want to change the file location. You can do this by editing the
+ * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h.
+ *
+ * 2. If you need to change the file name as well as its location,
+ * you can override the TEMP_FILE_NAME macro. (Note that this is
+ * actually a printf format string; it must contain %s and %d.)
+ * Few people should need to do this.
+ *
+ * 3. mktemp() is used to ensure that multiple processes running
+ * simultaneously won't select the same file names. If your system
+ * doesn't have mktemp(), define NO_MKTEMP to do it the hard way.
+ * (If you don't have <errno.h>, also define NO_ERRNO_H.)
+ *
+ * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c
+ * will cause the temp files to be removed if you stop the program early.
+ */
+
+#ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */
+#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */
+#endif
+
+static int next_file_num; /* to distinguish among several temp files */
+
+#ifdef NO_MKTEMP
+
+#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
+#define TEMP_FILE_NAME "%sJPG%03d.TMP"
+#endif
+
+#ifndef NO_ERRNO_H
+#include <errno.h> /* to define ENOENT */
+#endif
+
+/* ANSI C specifies that errno is a macro, but on older systems it's more
+ * likely to be a plain int variable. And not all versions of errno.h
+ * bother to declare it, so we have to in order to be most portable. Thus:
+ */
+#ifndef errno
+extern int errno;
+#endif
+
+
+LOCAL(void)
+select_file_name (char * fname)
+{
+ FILE * tfile;
+
+ /* Keep generating file names till we find one that's not in use */
+ for (;;) {
+ next_file_num++; /* advance counter */
+ sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
+ if ((tfile = fopen(fname, READ_BINARY)) == NULL) {
+ /* fopen could have failed for a reason other than the file not
+ * being there; for example, file there but unreadable.
+ * If <errno.h> isn't available, then we cannot test the cause.
+ */
+#ifdef ENOENT
+ if (errno != ENOENT)
+ continue;
+#endif
+ break;
+ }
+ fclose(tfile); /* oops, it's there; close tfile & try again */
+ }
+}
+
+#else /* ! NO_MKTEMP */
+
+/* Note that mktemp() requires the initial filename to end in six X's */
+#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
+#define TEMP_FILE_NAME "%sJPG%dXXXXXX"
+#endif
+
+LOCAL(void)
+select_file_name (char * fname)
+{
+ next_file_num++; /* advance counter */
+ sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
+ mktemp(fname); /* make sure file name is unique */
+ /* mktemp replaces the trailing XXXXXX with a unique string of characters */
+}
+
+#endif /* NO_MKTEMP */
+
+
+/*
+ * Memory allocation and freeing are controlled by the regular library
+ * routines malloc() and free().
+ */
+
+GLOBAL(void *)
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * "Large" objects are treated the same as "small" ones.
+ * NB: although we include FAR keywords in the routine declarations,
+ * this file won't actually work in 80x86 small/medium model; at least,
+ * you probably won't be able to process useful-size images in only 64KB.
+ */
+
+GLOBAL(void FAR *)
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void FAR *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * This routine computes the total memory space available for allocation.
+ * It's impossible to do this in a portable way; our current solution is
+ * to make the user tell us (with a default value set at compile time).
+ * If you can actually get the available space, it's a good idea to subtract
+ * a slop factor of 5% or so.
+ */
+
+#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
+#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
+#endif
+
+GLOBAL(long)
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
+ long max_bytes_needed, long already_allocated)
+{
+ return cinfo->mem->max_memory_to_use - already_allocated;
+}
+
+
+/*
+ * Backing store (temporary file) management.
+ * Backing store objects are only used when the value returned by
+ * jpeg_mem_available is less than the total space needed. You can dispense
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
+ */
+
+
+METHODDEF(void)
+read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ if (JFREAD(info->temp_file, buffer_address, byte_count)
+ != (size_t) byte_count)
+ ERREXIT(cinfo, JERR_TFILE_READ);
+}
+
+
+METHODDEF(void)
+write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count)
+{
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
+ if (JFWRITE(info->temp_file, buffer_address, byte_count)
+ != (size_t) byte_count)
+ ERREXIT(cinfo, JERR_TFILE_WRITE);
+}
+
+
+METHODDEF(void)
+close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
+{
+ fclose(info->temp_file); /* close the file */
+ unlink(info->temp_name); /* delete the file */
+/* If your system doesn't have unlink(), use remove() instead.
+ * remove() is the ANSI-standard name for this function, but if
+ * your system was ANSI you'd be using jmemansi.c, right?
+ */
+ TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
+}
+
+
+/*
+ * Initial opening of a backing-store object.
+ */
+
+GLOBAL(void)
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ select_file_name(info->temp_name);
+ if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)
+ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
+ info->read_backing_store = read_backing_store;
+ info->write_backing_store = write_backing_store;
+ info->close_backing_store = close_backing_store;
+ TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
+}
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required.
+ */
+
+GLOBAL(long)
+jpeg_mem_init (j_common_ptr cinfo)
+{
+ next_file_num = 0; /* initialize temp file name generator */
+ return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
+}
+
+GLOBAL(void)
+jpeg_mem_term (j_common_ptr cinfo)
+{
+ /* no work */
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemnobs.c b/osframework/source/ImageLib/jpeg/jmemnobs.c
new file mode 100644
index 0000000..6aa1e92
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemnobs.c
@@ -0,0 +1,109 @@
+/*
+ * jmemnobs.c
+ *
+ * Copyright (C) 1992-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file provides a really simple implementation of the system-
+ * dependent portion of the JPEG memory manager. This implementation
+ * assumes that no backing-store files are needed: all required space
+ * can be obtained from malloc().
+ * This is very portable in the sense that it'll compile on almost anything,
+ * but you'd better have lots of main memory (or virtual memory) if you want
+ * to process big images.
+ * Note that the max_memory_to_use option is ignored by this implementation.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "jmemsys.h" /* import the system-dependent declarations */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
+extern void * malloc JPP((size_t size));
+extern void free JPP((void *ptr));
+#endif
+
+
+/*
+ * Memory allocation and freeing are controlled by the regular library
+ * routines malloc() and free().
+ */
+
+GLOBAL(void *)
+jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * "Large" objects are treated the same as "small" ones.
+ * NB: although we include FAR keywords in the routine declarations,
+ * this file won't actually work in 80x86 small/medium model; at least,
+ * you probably won't be able to process useful-size images in only 64KB.
+ */
+
+GLOBAL(void FAR *)
+jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
+{
+ return (void FAR *) malloc(sizeofobject);
+}
+
+GLOBAL(void)
+jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
+{
+ free(object);
+}
+
+
+/*
+ * This routine computes the total memory space available for allocation.
+ * Here we always say, "we got all you want bud!"
+ */
+
+GLOBAL(long)
+jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
+ long max_bytes_needed, long already_allocated)
+{
+ return max_bytes_needed;
+}
+
+
+/*
+ * Backing store (temporary file) management.
+ * Since jpeg_mem_available always promised the moon,
+ * this should never be called and we can just error out.
+ */
+
+GLOBAL(void)
+jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
+ long total_bytes_needed)
+{
+ ERREXIT(cinfo, JERR_NO_BACKING_STORE);
+}
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required. Here, there isn't any.
+ */
+
+GLOBAL(long)
+jpeg_mem_init (j_common_ptr cinfo)
+{
+ return 0; /* just set max_memory_to_use to 0 */
+}
+
+GLOBAL(void)
+jpeg_mem_term (j_common_ptr cinfo)
+{
+ /* no work */
+}
diff --git a/osframework/source/ImageLib/jpeg/jmemsys.h b/osframework/source/ImageLib/jpeg/jmemsys.h
new file mode 100644
index 0000000..2a87961
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmemsys.h
@@ -0,0 +1,198 @@
+/*
+ * jmemsys.h
+ *
+ * Copyright (C) 1992-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This include file defines the interface between the system-independent
+ * and system-dependent portions of the JPEG memory manager. No other
+ * modules need include it. (The system-independent portion is jmemmgr.c;
+ * there are several different versions of the system-dependent portion.)
+ *
+ * This file works as-is for the system-dependent memory managers supplied
+ * in the IJG distribution. You may need to modify it if you write a
+ * custom memory manager. If system-dependent changes are needed in
+ * this file, the best method is to #ifdef them based on a configuration
+ * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR
+ * and USE_MAC_MEMMGR.
+ */
+
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_get_small jGetSmall
+#define jpeg_free_small jFreeSmall
+#define jpeg_get_large jGetLarge
+#define jpeg_free_large jFreeLarge
+#define jpeg_mem_available jMemAvail
+#define jpeg_open_backing_store jOpenBackStore
+#define jpeg_mem_init jMemInit
+#define jpeg_mem_term jMemTerm
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+
+/*
+ * These two functions are used to allocate and release small chunks of
+ * memory. (Typically the total amount requested through jpeg_get_small is
+ * no more than 20K or so; this will be requested in chunks of a few K each.)
+ * Behavior should be the same as for the standard library functions malloc
+ * and free; in particular, jpeg_get_small must return NULL on failure.
+ * On most systems, these ARE malloc and free. jpeg_free_small is passed the
+ * size of the object being freed, just in case it's needed.
+ * On an 80x86 machine using small-data memory model, these manage near heap.
+ */
+
+EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
+EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
+ size_t sizeofobject));
+
+/*
+ * These two functions are used to allocate and release large chunks of
+ * memory (up to the total free space designated by jpeg_mem_available).
+ * The interface is the same as above, except that on an 80x86 machine,
+ * far pointers are used. On most other machines these are identical to
+ * the jpeg_get/free_small routines; but we keep them separate anyway,
+ * in case a different allocation strategy is desirable for large chunks.
+ */
+
+EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
+ size_t sizeofobject));
+EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
+ size_t sizeofobject));
+
+/*
+ * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
+ * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
+ * matter, but that case should never come into play). This macro is needed
+ * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
+ * On those machines, we expect that jconfig.h will provide a proper value.
+ * On machines with 32-bit flat address spaces, any large constant may be used.
+ *
+ * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
+ * size_t and will be a multiple of sizeof(align_type).
+ */
+
+#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
+#define MAX_ALLOC_CHUNK 1000000000L
+#endif
+
+/*
+ * This routine computes the total space still available for allocation by
+ * jpeg_get_large. If more space than this is needed, backing store will be
+ * used. NOTE: any memory already allocated must not be counted.
+ *
+ * There is a minimum space requirement, corresponding to the minimum
+ * feasible buffer sizes; jmemmgr.c will request that much space even if
+ * jpeg_mem_available returns zero. The maximum space needed, enough to hold
+ * all working storage in memory, is also passed in case it is useful.
+ * Finally, the total space already allocated is passed. If no better
+ * method is available, cinfo->mem->max_memory_to_use - already_allocated
+ * is often a suitable calculation.
+ *
+ * It is OK for jpeg_mem_available to underestimate the space available
+ * (that'll just lead to more backing-store access than is really necessary).
+ * However, an overestimate will lead to failure. Hence it's wise to subtract
+ * a slop factor from the true available space. 5% should be enough.
+ *
+ * On machines with lots of virtual memory, any large constant may be returned.
+ * Conversely, zero may be returned to always use the minimum amount of memory.
+ */
+
+EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
+ long min_bytes_needed,
+ long max_bytes_needed,
+ long already_allocated));
+
+
+/*
+ * This structure holds whatever state is needed to access a single
+ * backing-store object. The read/write/close method pointers are called
+ * by jmemmgr.c to manipulate the backing-store object; all other fields
+ * are private to the system-dependent backing store routines.
+ */
+
+#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
+
+
+#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
+
+typedef unsigned short XMSH; /* type of extended-memory handles */
+typedef unsigned short EMSH; /* type of expanded-memory handles */
+
+typedef union {
+ short file_handle; /* DOS file handle if it's a temp file */
+ XMSH xms_handle; /* handle if it's a chunk of XMS */
+ EMSH ems_handle; /* handle if it's a chunk of EMS */
+} handle_union;
+
+#endif /* USE_MSDOS_MEMMGR */
+
+#ifdef USE_MAC_MEMMGR /* Mac-specific junk */
+#include <Files.h>
+#endif /* USE_MAC_MEMMGR */
+
+
+typedef struct backing_store_struct * backing_store_ptr;
+
+typedef struct backing_store_struct {
+ /* Methods for reading/writing/closing this backing-store object */
+ JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
+ backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count));
+ JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
+ backing_store_ptr info,
+ void FAR * buffer_address,
+ long file_offset, long byte_count));
+ JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
+ backing_store_ptr info));
+
+ /* Private fields for system-dependent backing-store management */
+#ifdef USE_MSDOS_MEMMGR
+ /* For the MS-DOS manager (jmemdos.c), we need: */
+ handle_union handle; /* reference to backing-store storage object */
+ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
+#else
+#ifdef USE_MAC_MEMMGR
+ /* For the Mac manager (jmemmac.c), we need: */
+ short temp_file; /* file reference number to temp file */
+ FSSpec tempSpec; /* the FSSpec for the temp file */
+ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
+#else
+ /* For a typical implementation with temp files, we need: */
+ FILE * temp_file; /* stdio reference to temp file */
+ char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
+#endif
+#endif
+} backing_store_info;
+
+
+/*
+ * Initial opening of a backing-store object. This must fill in the
+ * read/write/close pointers in the object. The read/write routines
+ * may take an error exit if the specified maximum file size is exceeded.
+ * (If jpeg_mem_available always returns a large value, this routine can
+ * just take an error exit.)
+ */
+
+EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
+ backing_store_ptr info,
+ long total_bytes_needed));
+
+
+/*
+ * These routines take care of any system-dependent initialization and
+ * cleanup required. jpeg_mem_init will be called before anything is
+ * allocated (and, therefore, nothing in cinfo is of use except the error
+ * manager pointer). It should return a suitable default value for
+ * max_memory_to_use; this may subsequently be overridden by the surrounding
+ * application. (Note that max_memory_to_use is only important if
+ * jpeg_mem_available chooses to consult it ... no one else will.)
+ * jpeg_mem_term may assume that all requested memory has been freed and that
+ * all opened backing-store objects have been closed.
+ */
+
+EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
+EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
diff --git a/osframework/source/ImageLib/jpeg/jmorecfg.h b/osframework/source/ImageLib/jpeg/jmorecfg.h
new file mode 100644
index 0000000..a8cbaa8
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jmorecfg.h
@@ -0,0 +1,394 @@
+/*
+ * jmorecfg.h
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains additional configuration options that customize the
+ * JPEG software for special applications or support machine-dependent
+ * optimizations. Most users will not need to touch this file.
+ */
+
+/*
+ * Define BITS_IN_JSAMPLE as either
+ * 8 for 8-bit sample values (the usual setting)
+ * 12 for 12-bit sample values
+ * Only 8 and 12 are legal data precisions for lossy JPEG according to the
+ * JPEG standard, and the IJG code does not support anything else!
+ * We do not support run-time selection of data precision, sorry.
+ */
+
+#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
+
+
+/*
+ * Maximum number of components (color channels) allowed in JPEG image.
+ * To meet the letter of the JPEG spec, set this to 255. However, darn
+ * few applications need more than 4 channels (maybe 5 for CMYK + alpha
+ * mask). We recommend 10 as a reasonable compromise; use 4 if you are
+ * really short on memory. (Each allowed component costs a hundred or so
+ * bytes of storage, whether actually used in an image or not.)
+ */
+
+#define MAX_COMPONENTS 10 /* maximum number of image components */
+
+
+/*
+ * Basic data types.
+ * You may need to change these if you have a machine with unusual data
+ * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
+ * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
+ * but it had better be at least 16.
+ */
+
+/* Representation of a single sample (pixel element value).
+ * We frequently allocate large arrays of these, so it's important to keep
+ * them small. But if you have memory to burn and access to char or short
+ * arrays is very slow on your hardware, you might want to change these.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+/* JSAMPLE should be the smallest type that will hold the values 0..255.
+ * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
+ */
+
+#ifdef HAVE_UNSIGNED_CHAR
+
+typedef unsigned char JSAMPLE;
+#define GETJSAMPLE(value) ((int) (value))
+
+#else /* not HAVE_UNSIGNED_CHAR */
+
+typedef char JSAMPLE;
+#ifdef CHAR_IS_UNSIGNED
+#define GETJSAMPLE(value) ((int) (value))
+#else
+#define GETJSAMPLE(value) ((int) (value) & 0xFF)
+#endif /* CHAR_IS_UNSIGNED */
+
+#endif /* HAVE_UNSIGNED_CHAR */
+
+#define MAXJSAMPLE 255
+#define CENTERJSAMPLE 128
+
+#endif /* BITS_IN_JSAMPLE == 8 */
+
+
+#if BITS_IN_JSAMPLE == 12
+/* JSAMPLE should be the smallest type that will hold the values 0..4095.
+ * On nearly all machines "short" will do nicely.
+ */
+
+typedef short JSAMPLE;
+#define GETJSAMPLE(value) ((int) (value))
+
+#define MAXJSAMPLE 4095
+#define CENTERJSAMPLE 2048
+
+#endif /* BITS_IN_JSAMPLE == 12 */
+
+
+/* Representation of a DCT frequency coefficient.
+ * This should be a signed value of at least 16 bits; "short" is usually OK.
+ * Again, we allocate large arrays of these, but you can change to int
+ * if you have memory to burn and "short" is really slow.
+ */
+
+typedef short JCOEF;
+
+
+/* Compressed datastreams are represented as arrays of JOCTET.
+ * These must be EXACTLY 8 bits wide, at least once they are written to
+ * external storage. Note that when using the stdio data source/destination
+ * managers, this is also the data type passed to fread/fwrite.
+ */
+
+#ifdef HAVE_UNSIGNED_CHAR
+
+typedef unsigned char JOCTET;
+#define GETJOCTET(value) (value)
+
+#else /* not HAVE_UNSIGNED_CHAR */
+
+typedef char JOCTET;
+#ifdef CHAR_IS_UNSIGNED
+#define GETJOCTET(value) (value)
+#else
+#define GETJOCTET(value) ((value) & 0xFF)
+#endif /* CHAR_IS_UNSIGNED */
+
+#endif /* HAVE_UNSIGNED_CHAR */
+
+
+/* These typedefs are used for various table entries and so forth.
+ * They must be at least as wide as specified; but making them too big
+ * won't cost a huge amount of memory, so we don't provide special
+ * extraction code like we did for JSAMPLE. (In other words, these
+ * typedefs live at a different point on the speed/space tradeoff curve.)
+ */
+
+/* UINT8 must hold at least the values 0..255. */
+
+#ifdef HAVE_UNSIGNED_CHAR
+typedef unsigned char UINT8;
+#else /* not HAVE_UNSIGNED_CHAR */
+#ifdef CHAR_IS_UNSIGNED
+typedef char UINT8;
+#else /* not CHAR_IS_UNSIGNED */
+typedef short UINT8;
+#endif /* CHAR_IS_UNSIGNED */
+#endif /* HAVE_UNSIGNED_CHAR */
+
+/* UINT16 must hold at least the values 0..65535. */
+
+#ifdef HAVE_UNSIGNED_SHORT
+typedef unsigned short UINT16;
+#else /* not HAVE_UNSIGNED_SHORT */
+typedef unsigned int UINT16;
+#endif /* HAVE_UNSIGNED_SHORT */
+
+/* INT16 must hold at least the values -32768..32767. */
+
+#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
+typedef short INT16;
+#endif
+
+/* INT32 must hold at least signed 32-bit values. */
+
+#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
+typedef long INT32;
+#endif
+
+/* Datatype used for image dimensions. The JPEG standard only supports
+ * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
+ * "unsigned int" is sufficient on all machines. However, if you need to
+ * handle larger images and you don't mind deviating from the spec, you
+ * can change this datatype.
+ */
+
+typedef unsigned int JDIMENSION;
+
+#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
+
+
+/* These macros are used in all function definitions and extern declarations.
+ * You could modify them if you need to change function linkage conventions;
+ * in particular, you'll need to do that to make the library a Windows DLL.
+ * Another application is to make all functions global for use with debuggers
+ * or code profilers that require it.
+ */
+
+/* a function called through method pointers: */
+#define METHODDEF(type) static type
+/* a function used only in its module: */
+#define LOCAL(type) static type
+
+#if !defined(_VISUALC_)
+# error Something is very very wrong. This header must only be used under Visual C++.
+#endif
+/**
+ * Under VISUALC we have single threaded static libraries, or
+ * mutli-threaded DLLs using the multithreaded runtime DLLs.
+ **/
+# if defined(_MT) && defined(_DLL) && !defined(_JPEGDLL_) && !defined(_LIB)
+# define _JPEGDLL_
+# endif
+# if defined(_JPEGDLL_)
+# pragma warning( disable: 4273 ) /* Disable the stupid dll linkage warnings */
+# if !defined(_JPEGLIB_)
+/* a function referenced thru EXTERNs: */
+# define GLOBAL(type) __declspec(dllimport) type
+/* a reference to a GLOBAL function: */
+# define EXTERN(type) extern __declspec(dllimport) type
+# else
+/* a function referenced thru EXTERNs: */
+# define GLOBAL(type) __declspec(dllexport) type
+/* a reference to a GLOBAL function: */
+# define EXTERN(type) extern __declspec(dllexport) type
+# endif
+# else
+/* a function referenced thru EXTERNs: */
+# define GLOBAL(type) type
+/* a reference to a GLOBAL function: */
+# define EXTERN(type) extern type
+# endif
+
+#pragma warning(disable : 4018)
+#pragma warning(disable : 4244)
+#pragma warning(disable : 4142)
+
+
+/* This macro is used to declare a "method", that is, a function pointer.
+ * We want to supply prototype parameters if the compiler can cope.
+ * Note that the arglist parameter must be parenthesized!
+ * Again, you can customize this if you need special linkage keywords.
+ */
+
+#ifdef HAVE_PROTOTYPES
+#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
+#else
+#define JMETHOD(type,methodname,arglist) type (*methodname) ()
+#endif
+
+
+/* Here is the pseudo-keyword for declaring pointers that must be "far"
+ * on 80x86 machines. Most of the specialized coding for 80x86 is handled
+ * by just saying "FAR *" where such a pointer is needed. In a few places
+ * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
+ */
+
+#ifdef NEED_FAR_POINTERS
+#define FAR far
+#else
+#ifndef FAR
+#define FAR
+#endif
+#endif
+
+
+/*
+ * On a few systems, type boolean and/or its values FALSE, TRUE may appear
+ * in standard header files. Or you may have conflicts with application-
+ * specific header files that you want to include together with these files.
+ * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
+ *
+ */
+#ifndef HAVE_BOOLEAN
+typedef unsigned char boolean;
+#endif
+#ifndef FALSE /* in case these macros already exist */
+#define FALSE 0 /* values of boolean */
+#endif
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+
+/*
+ * The remaining options affect code selection within the JPEG library,
+ * but they don't need to be visible to most applications using the library.
+ * To minimize application namespace pollution, the symbols won't be
+ * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.
+ */
+
+#ifdef JPEG_INTERNALS
+#define JPEG_INTERNAL_OPTIONS
+#endif
+
+#ifdef JPEG_INTERNAL_OPTIONS
+
+
+/*
+ * These defines indicate whether to include various optional functions.
+ * Undefining some of these symbols will produce a smaller but less capable
+ * library. Note that you can leave certain source files out of the
+ * compilation/linking process if you've #undef'd the corresponding symbols.
+ * (You may HAVE to do that if your compiler doesn't like null source files.)
+ */
+
+/* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */
+
+/* Capability options common to encoder and decoder: */
+
+#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
+#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
+#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
+
+/* Encoder capability options: */
+
+#undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
+#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
+#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
+#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
+/* Note: if you selected 12-bit data precision, it is dangerous to turn off
+ * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
+ * precision, so jchuff.c normally uses entropy optimization to compute
+ * usable tables for higher precision. If you don't want to do optimization,
+ * you'll have to supply different default Huffman tables.
+ * The exact same statements apply for progressive JPEG: the default tables
+ * don't work for progressive mode. (This may get fixed, however.)
+ */
+#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
+
+/* Decoder capability options: */
+
+#undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
+#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
+#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
+#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
+#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
+#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
+#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
+#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
+#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
+#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
+
+/* more capability options later, no doubt */
+
+
+/*
+ * Ordering of RGB data in scanlines passed to or from the application.
+ * If your application wants to deal with data in the order B,G,R, just
+ * change these macros. You can also deal with formats such as R,G,B,X
+ * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing
+ * the offsets will also change the order in which colormap data is organized.
+ * RESTRICTIONS:
+ * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
+ * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
+ * useful if you are using JPEG color spaces other than YCbCr or grayscale.
+ * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
+ * is not 3 (they don't understand about dummy color components!). So you
+ * can't use color quantization if you change that value.
+ */
+
+#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
+#define RGB_GREEN 1 /* Offset of Green */
+#define RGB_BLUE 2 /* Offset of Blue */
+#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
+
+
+/* Definitions for speed-related optimizations. */
+
+
+/* If your compiler supports inline functions, define INLINE
+ * as the inline keyword; otherwise define it as empty.
+ */
+
+#ifndef INLINE
+#ifdef __GNUC__ /* for instance, GNU C knows about inline */
+#define INLINE __inline__
+#endif
+#ifndef INLINE
+#define INLINE inline
+#endif
+#endif
+
+
+/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
+ * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
+ * as short on such a machine. MULTIPLIER must be at least 16 bits wide.
+ */
+
+#ifndef MULTIPLIER
+#define MULTIPLIER int /* type for fastest integer multiply */
+#endif
+
+
+/* FAST_FLOAT should be either float or double, whichever is done faster
+ * by your compiler. (Note that this type is only used in the floating point
+ * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
+ * Typically, float is faster in ANSI C compilers, while double is faster in
+ * pre-ANSI compilers (because they insist on converting to double anyway).
+ * The code below therefore chooses float if we have ANSI-style prototypes.
+ */
+
+#ifndef FAST_FLOAT
+#ifdef HAVE_PROTOTYPES
+#define FAST_FLOAT float
+#else
+#define FAST_FLOAT double
+#endif
+#endif
+
+#endif /* JPEG_INTERNAL_OPTIONS */ \ No newline at end of file
diff --git a/osframework/source/ImageLib/jpeg/jpegint.h b/osframework/source/ImageLib/jpeg/jpegint.h
new file mode 100644
index 0000000..685a361
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jpegint.h
@@ -0,0 +1,392 @@
+/*
+ * jpegint.h
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file provides common declarations for the various JPEG modules.
+ * These declarations are considered internal to the JPEG library; most
+ * applications using the library shouldn't need to include this file.
+ */
+
+
+/* Declarations for both compression & decompression */
+
+typedef enum { /* Operating modes for buffer controllers */
+ JBUF_PASS_THRU, /* Plain stripwise operation */
+ /* Remaining modes require a full-image buffer to have been created */
+ JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
+ JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
+ JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
+} J_BUF_MODE;
+
+/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
+#define CSTATE_START 100 /* after create_compress */
+#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
+#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
+#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
+#define DSTATE_START 200 /* after create_decompress */
+#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
+#define DSTATE_READY 202 /* found SOS, ready for start_decompress */
+#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
+#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
+#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
+#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
+#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
+#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
+#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
+#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
+
+
+/* Declarations for compression modules */
+
+/* Master control module */
+struct jpeg_comp_master {
+ JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
+ JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
+ JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
+
+ /* State variables made visible to other modules */
+ boolean call_pass_startup; /* True if pass_startup must be called */
+ boolean is_last_pass; /* True during last pass */
+};
+
+/* Main buffer control (downsampled-data buffer) */
+struct jpeg_c_main_controller {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
+ JMETHOD(void, process_data, (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail));
+};
+
+/* Compression preprocessing (downsampling input buffer control) */
+struct jpeg_c_prep_controller {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
+ JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf,
+ JDIMENSION *in_row_ctr,
+ JDIMENSION in_rows_avail,
+ JSAMPIMAGE output_buf,
+ JDIMENSION *out_row_group_ctr,
+ JDIMENSION out_row_groups_avail));
+};
+
+/* Coefficient buffer control */
+struct jpeg_c_coef_controller {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
+ JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
+ JSAMPIMAGE input_buf));
+};
+
+/* Colorspace conversion */
+struct jpeg_color_converter {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo));
+ JMETHOD(void, color_convert, (j_compress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
+ JDIMENSION output_row, int num_rows));
+};
+
+/* Downsampling */
+struct jpeg_downsampler {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo));
+ JMETHOD(void, downsample, (j_compress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION in_row_index,
+ JSAMPIMAGE output_buf,
+ JDIMENSION out_row_group_index));
+
+ boolean need_context_rows; /* TRUE if need rows above & below */
+};
+
+/* Forward DCT (also controls coefficient quantization) */
+struct jpeg_forward_dct {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo));
+ /* perhaps this should be an array??? */
+ JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
+ jpeg_component_info * compptr,
+ JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
+ JDIMENSION start_row, JDIMENSION start_col,
+ JDIMENSION num_blocks));
+};
+
+/* Entropy encoding */
+struct jpeg_entropy_encoder {
+ JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
+ JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
+ JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
+};
+
+/* Marker writing */
+struct jpeg_marker_writer {
+ JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
+ JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
+ JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
+ JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
+ JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
+ /* These routines are exported to allow insertion of extra markers */
+ /* Probably only COM and APPn markers should be written this way */
+ JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
+ unsigned int datalen));
+ JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
+};
+
+
+/* Declarations for decompression modules */
+
+/* Master control module */
+struct jpeg_decomp_master {
+ JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
+ JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
+
+ /* State variables made visible to other modules */
+ boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
+};
+
+/* Input control module */
+struct jpeg_input_controller {
+ JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
+ JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
+ JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
+ JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
+
+ /* State variables made visible to other modules */
+ boolean has_multiple_scans; /* True if file has multiple scans */
+ boolean eoi_reached; /* True when EOI has been consumed */
+};
+
+/* Main buffer control (downsampled-data buffer) */
+struct jpeg_d_main_controller {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
+ JMETHOD(void, process_data, (j_decompress_ptr cinfo,
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+};
+
+/* Coefficient buffer control */
+struct jpeg_d_coef_controller {
+ JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
+ JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
+ JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
+ JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
+ JSAMPIMAGE output_buf));
+ /* Pointer to array of coefficient virtual arrays, or NULL if none */
+ jvirt_barray_ptr *coef_arrays;
+};
+
+/* Decompression postprocessing (color quantization buffer control) */
+struct jpeg_d_post_controller {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
+ JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf,
+ JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+};
+
+/* Marker reading & parsing */
+struct jpeg_marker_reader {
+ JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
+ /* Read markers until SOS or EOI.
+ * Returns same codes as are defined for jpeg_consume_input:
+ * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
+ */
+ JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
+ /* Read a restart marker --- exported for use by entropy decoder only */
+ jpeg_marker_parser_method read_restart_marker;
+
+ /* State of marker reader --- nominally internal, but applications
+ * supplying COM or APPn handlers might like to know the state.
+ */
+ boolean saw_SOI; /* found SOI? */
+ boolean saw_SOF; /* found SOF? */
+ int next_restart_num; /* next restart number expected (0-7) */
+ unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
+};
+
+/* Entropy decoding */
+struct jpeg_entropy_decoder {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
+ JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
+ JBLOCKROW *MCU_data));
+
+ /* This is here to share code between baseline and progressive decoders; */
+ /* other modules probably should not use it */
+ boolean insufficient_data; /* set TRUE after emitting warning */
+};
+
+/* Inverse DCT (also performs dequantization) */
+typedef JMETHOD(void, inverse_DCT_method_ptr,
+ (j_decompress_ptr cinfo, jpeg_component_info * compptr,
+ JCOEFPTR coef_block,
+ JSAMPARRAY output_buf, JDIMENSION output_col));
+
+struct jpeg_inverse_dct {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
+ /* It is useful to allow each component to have a separate IDCT method. */
+ inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
+};
+
+/* Upsampling (note that upsampler must also call color converter) */
+struct jpeg_upsampler {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
+ JMETHOD(void, upsample, (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf,
+ JDIMENSION *in_row_group_ctr,
+ JDIMENSION in_row_groups_avail,
+ JSAMPARRAY output_buf,
+ JDIMENSION *out_row_ctr,
+ JDIMENSION out_rows_avail));
+
+ boolean need_context_rows; /* TRUE if need rows above & below */
+};
+
+/* Colorspace conversion */
+struct jpeg_color_deconverter {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
+ JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
+ JSAMPIMAGE input_buf, JDIMENSION input_row,
+ JSAMPARRAY output_buf, int num_rows));
+};
+
+/* Color quantization or color precision reduction */
+struct jpeg_color_quantizer {
+ JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
+ JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPARRAY output_buf,
+ int num_rows));
+ JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
+ JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
+};
+
+
+/* Miscellaneous useful macros */
+
+#undef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#undef MIN
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+
+/* We assume that right shift corresponds to signed division by 2 with
+ * rounding towards minus infinity. This is correct for typical "arithmetic
+ * shift" instructions that shift in copies of the sign bit. But some
+ * C compilers implement >> with an unsigned shift. For these machines you
+ * must define RIGHT_SHIFT_IS_UNSIGNED.
+ * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
+ * It is only applied with constant shift counts. SHIFT_TEMPS must be
+ * included in the variables of any routine using RIGHT_SHIFT.
+ */
+
+#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
+
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jinit_compress_master jICompress
+#define jinit_c_master_control jICMaster
+#define jinit_c_main_controller jICMainC
+#define jinit_c_prep_controller jICPrepC
+#define jinit_c_coef_controller jICCoefC
+#define jinit_color_converter jICColor
+#define jinit_downsampler jIDownsampler
+#define jinit_forward_dct jIFDCT
+#define jinit_huff_encoder jIHEncoder
+#define jinit_phuff_encoder jIPHEncoder
+#define jinit_marker_writer jIMWriter
+#define jinit_master_decompress jIDMaster
+#define jinit_d_main_controller jIDMainC
+#define jinit_d_coef_controller jIDCoefC
+#define jinit_d_post_controller jIDPostC
+#define jinit_input_controller jIInCtlr
+#define jinit_marker_reader jIMReader
+#define jinit_huff_decoder jIHDecoder
+#define jinit_phuff_decoder jIPHDecoder
+#define jinit_inverse_dct jIIDCT
+#define jinit_upsampler jIUpsampler
+#define jinit_color_deconverter jIDColor
+#define jinit_1pass_quantizer jI1Quant
+#define jinit_2pass_quantizer jI2Quant
+#define jinit_merged_upsampler jIMUpsampler
+#define jinit_memory_mgr jIMemMgr
+#define jdiv_round_up jDivRound
+#define jround_up jRound
+#define jcopy_sample_rows jCopySamples
+#define jcopy_block_row jCopyBlocks
+#define jzero_far jZeroFar
+#define jpeg_zigzag_order jZIGTable
+#define jpeg_natural_order jZAGTable
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+
+/* Compression module initialization routines */
+EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
+ boolean transcode_only));
+EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
+EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
+/* Decompression module initialization routines */
+EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
+ boolean need_full_buffer));
+EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
+EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
+/* Memory manager initialization */
+EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
+
+/* Utility routines in jutils.c */
+EXTERN(long) jdiv_round_up JPP((long a, long b));
+EXTERN(long) jround_up JPP((long a, long b));
+EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
+ JSAMPARRAY output_array, int dest_row,
+ int num_rows, JDIMENSION num_cols));
+EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
+ JDIMENSION num_blocks));
+EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
+/* Constant tables in jutils.c */
+#if 0 /* This table is not actually needed in v6a */
+extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
+#endif
+extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
+
+/* Suppress undefined-structure complaints if necessary. */
+
+#ifdef INCOMPLETE_TYPES_BROKEN
+#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
+struct jvirt_sarray_control { long dummy; };
+struct jvirt_barray_control { long dummy; };
+#endif
+#endif /* INCOMPLETE_TYPES_BROKEN */
diff --git a/osframework/source/ImageLib/jpeg/jpeglib.h b/osframework/source/ImageLib/jpeg/jpeglib.h
new file mode 100644
index 0000000..b9356f3
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jpeglib.h
@@ -0,0 +1,1096 @@
+/*
+ * jpeglib.h
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file defines the application interface for the JPEG library.
+ * Most applications using the library need only include this file,
+ * and perhaps jerror.h if they want to know the exact error codes.
+ */
+
+#ifndef JPEGLIB_H
+#define JPEGLIB_H
+
+/*
+ * First we include the configuration files that record how this
+ * installation of the JPEG library is set up. jconfig.h can be
+ * generated automatically for many systems. jmorecfg.h contains
+ * manual configuration options that most people need not worry about.
+ */
+
+#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
+#include "jconfig.h" /* widely used configuration options */
+#endif
+#include "jmorecfg.h" /* seldom changed options */
+
+
+/* Version ID for the JPEG library.
+ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
+ */
+
+#define JPEG_LIB_VERSION 62 /* Version 6b */
+
+
+/* Various constants determining the sizes of things.
+ * All of these are specified by the JPEG standard, so don't change them
+ * if you want to be compatible.
+ */
+
+#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
+#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
+#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
+#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
+#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
+#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
+#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
+/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
+ * the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
+ * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
+ * to handle it. We even let you do this from the jconfig.h file. However,
+ * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
+ * sometimes emits noncompliant files doesn't mean you should too.
+ */
+#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
+#ifndef D_MAX_BLOCKS_IN_MCU
+#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
+#endif
+
+
+/* Data structures for images (arrays of samples and of DCT coefficients).
+ * On 80x86 machines, the image arrays are too big for near pointers,
+ * but the pointer arrays can fit in near memory.
+ */
+
+typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
+typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
+typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
+
+typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
+typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
+typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
+typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
+
+typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
+
+
+/* Types for JPEG compression parameters and working tables. */
+
+
+/* DCT coefficient quantization tables. */
+
+typedef struct {
+ /* This array gives the coefficient quantizers in natural array order
+ * (not the zigzag order in which they are stored in a JPEG DQT marker).
+ * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
+ */
+ UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
+ /* This field is used only during compression. It's initialized FALSE when
+ * the table is created, and set TRUE when it's been output to the file.
+ * You could suppress output of a table by setting this to TRUE.
+ * (See jpeg_suppress_tables for an example.)
+ */
+ boolean sent_table; /* TRUE when table has been output */
+} JQUANT_TBL;
+
+
+/* Huffman coding tables. */
+
+typedef struct {
+ /* These two fields directly represent the contents of a JPEG DHT marker */
+ UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
+ /* length k bits; bits[0] is unused */
+ UINT8 huffval[256]; /* The symbols, in order of incr code length */
+ /* This field is used only during compression. It's initialized FALSE when
+ * the table is created, and set TRUE when it's been output to the file.
+ * You could suppress output of a table by setting this to TRUE.
+ * (See jpeg_suppress_tables for an example.)
+ */
+ boolean sent_table; /* TRUE when table has been output */
+} JHUFF_TBL;
+
+
+/* Basic info about one component (color channel). */
+
+typedef struct {
+ /* These values are fixed over the whole image. */
+ /* For compression, they must be supplied by parameter setup; */
+ /* for decompression, they are read from the SOF marker. */
+ int component_id; /* identifier for this component (0..255) */
+ int component_index; /* its index in SOF or cinfo->comp_info[] */
+ int h_samp_factor; /* horizontal sampling factor (1..4) */
+ int v_samp_factor; /* vertical sampling factor (1..4) */
+ int quant_tbl_no; /* quantization table selector (0..3) */
+ /* These values may vary between scans. */
+ /* For compression, they must be supplied by parameter setup; */
+ /* for decompression, they are read from the SOS marker. */
+ /* The decompressor output side may not use these variables. */
+ int dc_tbl_no; /* DC entropy table selector (0..3) */
+ int ac_tbl_no; /* AC entropy table selector (0..3) */
+
+ /* Remaining fields should be treated as private by applications. */
+
+ /* These values are computed during compression or decompression startup: */
+ /* Component's size in DCT blocks.
+ * Any dummy blocks added to complete an MCU are not counted; therefore
+ * these values do not depend on whether a scan is interleaved or not.
+ */
+ JDIMENSION width_in_blocks;
+ JDIMENSION height_in_blocks;
+ /* Size of a DCT block in samples. Always DCTSIZE for compression.
+ * For decompression this is the size of the output from one DCT block,
+ * reflecting any scaling we choose to apply during the IDCT step.
+ * Values of 1,2,4,8 are likely to be supported. Note that different
+ * components may receive different IDCT scalings.
+ */
+ int DCT_scaled_size;
+ /* The downsampled dimensions are the component's actual, unpadded number
+ * of samples at the main buffer (preprocessing/compression interface), thus
+ * downsampled_width = ceil(image_width * Hi/Hmax)
+ * and similarly for height. For decompression, IDCT scaling is included, so
+ * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
+ */
+ JDIMENSION downsampled_width; /* actual width in samples */
+ JDIMENSION downsampled_height; /* actual height in samples */
+ /* This flag is used only for decompression. In cases where some of the
+ * components will be ignored (eg grayscale output from YCbCr image),
+ * we can skip most computations for the unused components.
+ */
+ boolean component_needed; /* do we need the value of this component? */
+
+ /* These values are computed before starting a scan of the component. */
+ /* The decompressor output side may not use these variables. */
+ int MCU_width; /* number of blocks per MCU, horizontally */
+ int MCU_height; /* number of blocks per MCU, vertically */
+ int MCU_blocks; /* MCU_width * MCU_height */
+ int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
+ int last_col_width; /* # of non-dummy blocks across in last MCU */
+ int last_row_height; /* # of non-dummy blocks down in last MCU */
+
+ /* Saved quantization table for component; NULL if none yet saved.
+ * See jdinput.c comments about the need for this information.
+ * This field is currently used only for decompression.
+ */
+ JQUANT_TBL * quant_table;
+
+ /* Private per-component storage for DCT or IDCT subsystem. */
+ void * dct_table;
+} jpeg_component_info;
+
+
+/* The script for encoding a multiple-scan file is an array of these: */
+
+typedef struct {
+ int comps_in_scan; /* number of components encoded in this scan */
+ int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
+ int Ss, Se; /* progressive JPEG spectral selection parms */
+ int Ah, Al; /* progressive JPEG successive approx. parms */
+} jpeg_scan_info;
+
+/* The decompressor can save APPn and COM markers in a list of these: */
+
+typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
+
+struct jpeg_marker_struct {
+ jpeg_saved_marker_ptr next; /* next in list, or NULL */
+ UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
+ unsigned int original_length; /* # bytes of data in the file */
+ unsigned int data_length; /* # bytes of data saved at data[] */
+ JOCTET FAR * data; /* the data contained in the marker */
+ /* the marker length word is not counted in data_length or original_length */
+};
+
+/* Known color spaces. */
+
+typedef enum {
+ JCS_UNKNOWN, /* error/unspecified */
+ JCS_GRAYSCALE, /* monochrome */
+ JCS_RGB, /* red/green/blue */
+ JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
+ JCS_CMYK, /* C/M/Y/K */
+ JCS_YCCK /* Y/Cb/Cr/K */
+} J_COLOR_SPACE;
+
+/* DCT/IDCT algorithm options. */
+
+typedef enum {
+ JDCT_ISLOW, /* slow but accurate integer algorithm */
+ JDCT_IFAST, /* faster, less accurate integer method */
+ JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
+} J_DCT_METHOD;
+
+#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
+#define JDCT_DEFAULT JDCT_ISLOW
+#endif
+#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
+#define JDCT_FASTEST JDCT_IFAST
+#endif
+
+/* Dithering options for decompression. */
+
+typedef enum {
+ JDITHER_NONE, /* no dithering */
+ JDITHER_ORDERED, /* simple ordered dither */
+ JDITHER_FS /* Floyd-Steinberg error diffusion dither */
+} J_DITHER_MODE;
+
+
+/* Common fields between JPEG compression and decompression master structs. */
+
+#define jpeg_common_fields \
+ struct jpeg_error_mgr * err; /* Error handler module */\
+ struct jpeg_memory_mgr * mem; /* Memory manager module */\
+ struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
+ void * client_data; /* Available for use by application */\
+ boolean is_decompressor; /* So common code can tell which is which */\
+ int global_state /* For checking call sequence validity */
+
+/* Routines that are to be used by both halves of the library are declared
+ * to receive a pointer to this structure. There are no actual instances of
+ * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
+ */
+struct jpeg_common_struct {
+ jpeg_common_fields; /* Fields common to both master struct types */
+ /* Additional fields follow in an actual jpeg_compress_struct or
+ * jpeg_decompress_struct. All three structs must agree on these
+ * initial fields! (This would be a lot cleaner in C++.)
+ */
+};
+
+typedef struct jpeg_common_struct * j_common_ptr;
+typedef struct jpeg_compress_struct * j_compress_ptr;
+typedef struct jpeg_decompress_struct * j_decompress_ptr;
+
+
+/* Master record for a compression instance */
+
+struct jpeg_compress_struct {
+ jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
+
+ /* Destination for compressed data */
+ struct jpeg_destination_mgr * dest;
+
+ /* Description of source image --- these fields must be filled in by
+ * outer application before starting compression. in_color_space must
+ * be correct before you can even call jpeg_set_defaults().
+ */
+
+ JDIMENSION image_width; /* input image width */
+ JDIMENSION image_height; /* input image height */
+ int input_components; /* # of color components in input image */
+ J_COLOR_SPACE in_color_space; /* colorspace of input image */
+
+ double input_gamma; /* image gamma of input image */
+
+ /* Compression parameters --- these fields must be set before calling
+ * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to
+ * initialize everything to reasonable defaults, then changing anything
+ * the application specifically wants to change. That way you won't get
+ * burnt when new parameters are added. Also note that there are several
+ * helper routines to simplify changing parameters.
+ */
+
+ int data_precision; /* bits of precision in image data */
+
+ int num_components; /* # of color components in JPEG image */
+ J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
+
+ jpeg_component_info * comp_info;
+ /* comp_info[i] describes component that appears i'th in SOF */
+
+ JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
+ /* ptrs to coefficient quantization tables, or NULL if not defined */
+
+ JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
+ JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
+ /* ptrs to Huffman coding tables, or NULL if not defined */
+
+ UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
+ UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
+ UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
+
+ int num_scans; /* # of entries in scan_info array */
+ const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
+ /* The default value of scan_info is NULL, which causes a single-scan
+ * sequential JPEG file to be emitted. To create a multi-scan file,
+ * set num_scans and scan_info to point to an array of scan definitions.
+ */
+
+ boolean raw_data_in; /* TRUE=caller supplies downsampled data */
+ boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
+ boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
+ boolean CCIR601_sampling; /* TRUE=first samples are cosited */
+ int smoothing_factor; /* 1..100, or 0 for no input smoothing */
+ J_DCT_METHOD dct_method; /* DCT algorithm selector */
+
+ /* The restart interval can be specified in absolute MCUs by setting
+ * restart_interval, or in MCU rows by setting restart_in_rows
+ * (in which case the correct restart_interval will be figured
+ * for each scan).
+ */
+ unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
+ int restart_in_rows; /* if > 0, MCU rows per restart interval */
+
+ /* Parameters controlling emission of special markers. */
+
+ boolean write_JFIF_header; /* should a JFIF marker be written? */
+ UINT8 JFIF_major_version; /* What to write for the JFIF version number */
+ UINT8 JFIF_minor_version;
+ /* These three values are not used by the JPEG code, merely copied */
+ /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */
+ /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */
+ /* ratio is defined by X_density/Y_density even when density_unit=0. */
+ UINT8 density_unit; /* JFIF code for pixel size units */
+ UINT16 X_density; /* Horizontal pixel density */
+ UINT16 Y_density; /* Vertical pixel density */
+ boolean write_Adobe_marker; /* should an Adobe marker be written? */
+
+ /* State variable: index of next scanline to be written to
+ * jpeg_write_scanlines(). Application may use this to control its
+ * processing loop, e.g., "while (next_scanline < image_height)".
+ */
+
+ JDIMENSION next_scanline; /* 0 .. image_height-1 */
+
+ /* Remaining fields are known throughout compressor, but generally
+ * should not be touched by a surrounding application.
+ */
+
+ /*
+ * These fields are computed during compression startup
+ */
+ boolean progressive_mode; /* TRUE if scan script uses progressive mode */
+ int max_h_samp_factor; /* largest h_samp_factor */
+ int max_v_samp_factor; /* largest v_samp_factor */
+
+ JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
+ /* The coefficient controller receives data in units of MCU rows as defined
+ * for fully interleaved scans (whether the JPEG file is interleaved or not).
+ * There are v_samp_factor * DCTSIZE sample rows of each component in an
+ * "iMCU" (interleaved MCU) row.
+ */
+
+ /*
+ * These fields are valid during any one scan.
+ * They describe the components and MCUs actually appearing in the scan.
+ */
+ int comps_in_scan; /* # of JPEG components in this scan */
+ jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
+ /* *cur_comp_info[i] describes component that appears i'th in SOS */
+
+ JDIMENSION MCUs_per_row; /* # of MCUs across the image */
+ JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
+
+ int blocks_in_MCU; /* # of DCT blocks per MCU */
+ int MCU_membership[C_MAX_BLOCKS_IN_MCU];
+ /* MCU_membership[i] is index in cur_comp_info of component owning */
+ /* i'th block in an MCU */
+
+ int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
+
+ /*
+ * Links to compression subobjects (methods and private variables of modules)
+ */
+ struct jpeg_comp_master * master;
+ struct jpeg_c_main_controller * main;
+ struct jpeg_c_prep_controller * prep;
+ struct jpeg_c_coef_controller * coef;
+ struct jpeg_marker_writer * marker;
+ struct jpeg_color_converter * cconvert;
+ struct jpeg_downsampler * downsample;
+ struct jpeg_forward_dct * fdct;
+ struct jpeg_entropy_encoder * entropy;
+ jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
+ int script_space_size;
+};
+
+
+/* Master record for a decompression instance */
+
+struct jpeg_decompress_struct {
+ jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
+
+ /* Source of compressed data */
+ struct jpeg_source_mgr * src;
+
+ /* Basic description of image --- filled in by jpeg_read_header(). */
+ /* Application may inspect these values to decide how to process image. */
+
+ JDIMENSION image_width; /* nominal image width (from SOF marker) */
+ JDIMENSION image_height; /* nominal image height */
+ int num_components; /* # of color components in JPEG image */
+ J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
+
+ /* Decompression processing parameters --- these fields must be set before
+ * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes
+ * them to default values.
+ */
+
+ J_COLOR_SPACE out_color_space; /* colorspace for output */
+
+ unsigned int scale_num, scale_denom; /* fraction by which to scale image */
+
+ double output_gamma; /* image gamma wanted in output */
+
+ boolean buffered_image; /* TRUE=multiple output passes */
+ boolean raw_data_out; /* TRUE=downsampled data wanted */
+
+ J_DCT_METHOD dct_method; /* IDCT algorithm selector */
+ boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
+ boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
+
+ boolean quantize_colors; /* TRUE=colormapped output wanted */
+ /* the following are ignored if not quantize_colors: */
+ J_DITHER_MODE dither_mode; /* type of color dithering to use */
+ boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
+ int desired_number_of_colors; /* max # colors to use in created colormap */
+ /* these are significant only in buffered-image mode: */
+ boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
+ boolean enable_external_quant;/* enable future use of external colormap */
+ boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
+
+ /* Description of actual output image that will be returned to application.
+ * These fields are computed by jpeg_start_decompress().
+ * You can also use jpeg_calc_output_dimensions() to determine these values
+ * in advance of calling jpeg_start_decompress().
+ */
+
+ JDIMENSION output_width; /* scaled image width */
+ JDIMENSION output_height; /* scaled image height */
+ int out_color_components; /* # of color components in out_color_space */
+ int output_components; /* # of color components returned */
+ /* output_components is 1 (a colormap index) when quantizing colors;
+ * otherwise it equals out_color_components.
+ */
+ int rec_outbuf_height; /* min recommended height of scanline buffer */
+ /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
+ * high, space and time will be wasted due to unnecessary data copying.
+ * Usually rec_outbuf_height will be 1 or 2, at most 4.
+ */
+
+ /* When quantizing colors, the output colormap is described by these fields.
+ * The application can supply a colormap by setting colormap non-NULL before
+ * calling jpeg_start_decompress; otherwise a colormap is created during
+ * jpeg_start_decompress or jpeg_start_output.
+ * The map has out_color_components rows and actual_number_of_colors columns.
+ */
+ int actual_number_of_colors; /* number of entries in use */
+ JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
+
+ /* State variables: these variables indicate the progress of decompression.
+ * The application may examine these but must not modify them.
+ */
+
+ /* Row index of next scanline to be read from jpeg_read_scanlines().
+ * Application may use this to control its processing loop, e.g.,
+ * "while (output_scanline < output_height)".
+ */
+ JDIMENSION output_scanline; /* 0 .. output_height-1 */
+
+ /* Current input scan number and number of iMCU rows completed in scan.
+ * These indicate the progress of the decompressor input side.
+ */
+ int input_scan_number; /* Number of SOS markers seen so far */
+ JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
+
+ /* The "output scan number" is the notional scan being displayed by the
+ * output side. The decompressor will not allow output scan/row number
+ * to get ahead of input scan/row, but it can fall arbitrarily far behind.
+ */
+ int output_scan_number; /* Nominal scan number being displayed */
+ JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
+
+ /* Current progression status. coef_bits[c][i] indicates the precision
+ * with which component c's DCT coefficient i (in zigzag order) is known.
+ * It is -1 when no data has yet been received, otherwise it is the point
+ * transform (shift) value for the most recent scan of the coefficient
+ * (thus, 0 at completion of the progression).
+ * This pointer is NULL when reading a non-progressive file.
+ */
+ int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
+
+ /* Internal JPEG parameters --- the application usually need not look at
+ * these fields. Note that the decompressor output side may not use
+ * any parameters that can change between scans.
+ */
+
+ /* Quantization and Huffman tables are carried forward across input
+ * datastreams when processing abbreviated JPEG datastreams.
+ */
+
+ JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
+ /* ptrs to coefficient quantization tables, or NULL if not defined */
+
+ JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
+ JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
+ /* ptrs to Huffman coding tables, or NULL if not defined */
+
+ /* These parameters are never carried across datastreams, since they
+ * are given in SOF/SOS markers or defined to be reset by SOI.
+ */
+
+ int data_precision; /* bits of precision in image data */
+
+ jpeg_component_info * comp_info;
+ /* comp_info[i] describes component that appears i'th in SOF */
+
+ boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
+ boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
+
+ UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
+ UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
+ UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
+
+ unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
+
+ /* These fields record data obtained from optional markers recognized by
+ * the JPEG library.
+ */
+ boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
+ /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
+ UINT8 JFIF_major_version; /* JFIF version number */
+ UINT8 JFIF_minor_version;
+ UINT8 density_unit; /* JFIF code for pixel size units */
+ UINT16 X_density; /* Horizontal pixel density */
+ UINT16 Y_density; /* Vertical pixel density */
+ boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
+ UINT8 Adobe_transform; /* Color transform code from Adobe marker */
+
+ boolean CCIR601_sampling; /* TRUE=first samples are cosited */
+
+ /* Aside from the specific data retained from APPn markers known to the
+ * library, the uninterpreted contents of any or all APPn and COM markers
+ * can be saved in a list for examination by the application.
+ */
+ jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
+
+ /* Remaining fields are known throughout decompressor, but generally
+ * should not be touched by a surrounding application.
+ */
+
+ /*
+ * These fields are computed during decompression startup
+ */
+ int max_h_samp_factor; /* largest h_samp_factor */
+ int max_v_samp_factor; /* largest v_samp_factor */
+
+ int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
+
+ JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
+ /* The coefficient controller's input and output progress is measured in
+ * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows
+ * in fully interleaved JPEG scans, but are used whether the scan is
+ * interleaved or not. We define an iMCU row as v_samp_factor DCT block
+ * rows of each component. Therefore, the IDCT output contains
+ * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
+ */
+
+ JSAMPLE * sample_range_limit; /* table for fast range-limiting */
+
+ /*
+ * These fields are valid during any one scan.
+ * They describe the components and MCUs actually appearing in the scan.
+ * Note that the decompressor output side must not use these fields.
+ */
+ int comps_in_scan; /* # of JPEG components in this scan */
+ jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
+ /* *cur_comp_info[i] describes component that appears i'th in SOS */
+
+ JDIMENSION MCUs_per_row; /* # of MCUs across the image */
+ JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
+
+ int blocks_in_MCU; /* # of DCT blocks per MCU */
+ int MCU_membership[D_MAX_BLOCKS_IN_MCU];
+ /* MCU_membership[i] is index in cur_comp_info of component owning */
+ /* i'th block in an MCU */
+
+ int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
+
+ /* This field is shared between entropy decoder and marker parser.
+ * It is either zero or the code of a JPEG marker that has been
+ * read from the data source, but has not yet been processed.
+ */
+ int unread_marker;
+
+ /*
+ * Links to decompression subobjects (methods, private variables of modules)
+ */
+ struct jpeg_decomp_master * master;
+ struct jpeg_d_main_controller * main;
+ struct jpeg_d_coef_controller * coef;
+ struct jpeg_d_post_controller * post;
+ struct jpeg_input_controller * inputctl;
+ struct jpeg_marker_reader * marker;
+ struct jpeg_entropy_decoder * entropy;
+ struct jpeg_inverse_dct * idct;
+ struct jpeg_upsampler * upsample;
+ struct jpeg_color_deconverter * cconvert;
+ struct jpeg_color_quantizer * cquantize;
+};
+
+
+/* "Object" declarations for JPEG modules that may be supplied or called
+ * directly by the surrounding application.
+ * As with all objects in the JPEG library, these structs only define the
+ * publicly visible methods and state variables of a module. Additional
+ * private fields may exist after the public ones.
+ */
+
+
+/* Error handler object */
+
+struct jpeg_error_mgr {
+ /* Error exit handler: does not return to caller */
+ JMETHOD(void, error_exit, (j_common_ptr cinfo));
+ /* Conditionally emit a trace or warning message */
+ JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
+ /* Routine that actually outputs a trace or error message */
+ JMETHOD(void, output_message, (j_common_ptr cinfo));
+ /* Format a message string for the most recent JPEG error or message */
+ JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
+#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
+ /* Reset error state variables at start of a new image */
+ JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
+
+ /* The message ID code and any parameters are saved here.
+ * A message can have one string parameter or up to 8 int parameters.
+ */
+ int msg_code;
+#define JMSG_STR_PARM_MAX 80
+ union {
+ int i[8];
+ char s[JMSG_STR_PARM_MAX];
+ } msg_parm;
+
+ /* Standard state variables for error facility */
+
+ int trace_level; /* max msg_level that will be displayed */
+
+ /* For recoverable corrupt-data errors, we emit a warning message,
+ * but keep going unless emit_message chooses to abort. emit_message
+ * should count warnings in num_warnings. The surrounding application
+ * can check for bad data by seeing if num_warnings is nonzero at the
+ * end of processing.
+ */
+ long num_warnings; /* number of corrupt-data warnings */
+
+ /* These fields point to the table(s) of error message strings.
+ * An application can change the table pointer to switch to a different
+ * message list (typically, to change the language in which errors are
+ * reported). Some applications may wish to add additional error codes
+ * that will be handled by the JPEG library error mechanism; the second
+ * table pointer is used for this purpose.
+ *
+ * First table includes all errors generated by JPEG library itself.
+ * Error code 0 is reserved for a "no such error string" message.
+ */
+ const char * const * jpeg_message_table; /* Library errors */
+ int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
+ /* Second table can be added by application (see cjpeg/djpeg for example).
+ * It contains strings numbered first_addon_message..last_addon_message.
+ */
+ const char * const * addon_message_table; /* Non-library errors */
+ int first_addon_message; /* code for first string in addon table */
+ int last_addon_message; /* code for last string in addon table */
+};
+
+
+/* Progress monitor object */
+
+struct jpeg_progress_mgr {
+ JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
+
+ long pass_counter; /* work units completed in this pass */
+ long pass_limit; /* total number of work units in this pass */
+ int completed_passes; /* passes completed so far */
+ int total_passes; /* total number of passes expected */
+};
+
+
+/* Data destination object for compression */
+
+struct jpeg_destination_mgr {
+ JOCTET * next_output_byte; /* => next byte to write in buffer */
+ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
+
+ JMETHOD(void, init_destination, (j_compress_ptr cinfo));
+ JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
+ JMETHOD(void, term_destination, (j_compress_ptr cinfo));
+};
+
+
+/* Data source object for decompression */
+
+struct jpeg_source_mgr {
+ const JOCTET * next_input_byte; /* => next byte to read from buffer */
+ size_t bytes_in_buffer; /* # of bytes remaining in buffer */
+
+ JMETHOD(void, init_source, (j_decompress_ptr cinfo));
+ JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
+ JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
+ JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
+ JMETHOD(void, term_source, (j_decompress_ptr cinfo));
+};
+
+
+/* Memory manager object.
+ * Allocates "small" objects (a few K total), "large" objects (tens of K),
+ * and "really big" objects (virtual arrays with backing store if needed).
+ * The memory manager does not allow individual objects to be freed; rather,
+ * each created object is assigned to a pool, and whole pools can be freed
+ * at once. This is faster and more convenient than remembering exactly what
+ * to free, especially where malloc()/free() are not too speedy.
+ * NB: alloc routines never return NULL. They exit to error_exit if not
+ * successful.
+ */
+
+#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
+#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
+#define JPOOL_NUMPOOLS 2
+
+typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
+typedef struct jvirt_barray_control * jvirt_barray_ptr;
+
+
+struct jpeg_memory_mgr {
+ /* Method pointers */
+ JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
+ size_t sizeofobject));
+ JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
+ size_t sizeofobject));
+ JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
+ JDIMENSION samplesperrow,
+ JDIMENSION numrows));
+ JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
+ JDIMENSION blocksperrow,
+ JDIMENSION numrows));
+ JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
+ int pool_id,
+ boolean pre_zero,
+ JDIMENSION samplesperrow,
+ JDIMENSION numrows,
+ JDIMENSION maxaccess));
+ JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
+ int pool_id,
+ boolean pre_zero,
+ JDIMENSION blocksperrow,
+ JDIMENSION numrows,
+ JDIMENSION maxaccess));
+ JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
+ JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
+ jvirt_sarray_ptr ptr,
+ JDIMENSION start_row,
+ JDIMENSION num_rows,
+ boolean writable));
+ JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
+ jvirt_barray_ptr ptr,
+ JDIMENSION start_row,
+ JDIMENSION num_rows,
+ boolean writable));
+ JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
+ JMETHOD(void, self_destruct, (j_common_ptr cinfo));
+
+ /* Limit on memory allocation for this JPEG object. (Note that this is
+ * merely advisory, not a guaranteed maximum; it only affects the space
+ * used for virtual-array buffers.) May be changed by outer application
+ * after creating the JPEG object.
+ */
+ long max_memory_to_use;
+
+ /* Maximum allocation request accepted by alloc_large. */
+ long max_alloc_chunk;
+};
+
+
+/* Routine signature for application-supplied marker processing methods.
+ * Need not pass marker code since it is stored in cinfo->unread_marker.
+ */
+typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
+
+
+/* Declarations for routines called by application.
+ * The JPP macro hides prototype parameters from compilers that can't cope.
+ * Note JPP requires double parentheses.
+ */
+
+#ifdef HAVE_PROTOTYPES
+#define JPP(arglist) arglist
+#else
+#define JPP(arglist) ()
+#endif
+
+
+/* Short forms of external names for systems with brain-damaged linkers.
+ * We shorten external names to be unique in the first six letters, which
+ * is good enough for all known systems.
+ * (If your compiler itself needs names to be unique in less than 15
+ * characters, you are out of luck. Get a better compiler.)
+ */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_std_error jStdError
+#define jpeg_CreateCompress jCreaCompress
+#define jpeg_CreateDecompress jCreaDecompress
+#define jpeg_destroy_compress jDestCompress
+#define jpeg_destroy_decompress jDestDecompress
+#define jpeg_stdio_dest jStdDest
+#define jpeg_stdio_src jStdSrc
+#define jpeg_set_defaults jSetDefaults
+#define jpeg_set_colorspace jSetColorspace
+#define jpeg_default_colorspace jDefColorspace
+#define jpeg_set_quality jSetQuality
+#define jpeg_set_linear_quality jSetLQuality
+#define jpeg_add_quant_table jAddQuantTable
+#define jpeg_quality_scaling jQualityScaling
+#define jpeg_simple_progression jSimProgress
+#define jpeg_suppress_tables jSuppressTables
+#define jpeg_alloc_quant_table jAlcQTable
+#define jpeg_alloc_huff_table jAlcHTable
+#define jpeg_start_compress jStrtCompress
+#define jpeg_write_scanlines jWrtScanlines
+#define jpeg_finish_compress jFinCompress
+#define jpeg_write_raw_data jWrtRawData
+#define jpeg_write_marker jWrtMarker
+#define jpeg_write_m_header jWrtMHeader
+#define jpeg_write_m_byte jWrtMByte
+#define jpeg_write_tables jWrtTables
+#define jpeg_read_header jReadHeader
+#define jpeg_start_decompress jStrtDecompress
+#define jpeg_read_scanlines jReadScanlines
+#define jpeg_finish_decompress jFinDecompress
+#define jpeg_read_raw_data jReadRawData
+#define jpeg_has_multiple_scans jHasMultScn
+#define jpeg_start_output jStrtOutput
+#define jpeg_finish_output jFinOutput
+#define jpeg_input_complete jInComplete
+#define jpeg_new_colormap jNewCMap
+#define jpeg_consume_input jConsumeInput
+#define jpeg_calc_output_dimensions jCalcDimensions
+#define jpeg_save_markers jSaveMarkers
+#define jpeg_set_marker_processor jSetMarker
+#define jpeg_read_coefficients jReadCoefs
+#define jpeg_write_coefficients jWrtCoefs
+#define jpeg_copy_critical_parameters jCopyCrit
+#define jpeg_abort_compress jAbrtCompress
+#define jpeg_abort_decompress jAbrtDecompress
+#define jpeg_abort jAbort
+#define jpeg_destroy jDestroy
+#define jpeg_resync_to_restart jResyncRestart
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+
+/* Default error-management setup */
+EXTERN(struct jpeg_error_mgr *) jpeg_std_error
+ JPP((struct jpeg_error_mgr * err));
+
+/* Initialization of JPEG compression objects.
+ * jpeg_create_compress() and jpeg_create_decompress() are the exported
+ * names that applications should call. These expand to calls on
+ * jpeg_CreateCompress and jpeg_CreateDecompress with additional information
+ * passed for version mismatch checking.
+ * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
+ */
+#define jpeg_create_compress(cinfo) \
+ jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
+ (size_t) sizeof(struct jpeg_compress_struct))
+#define jpeg_create_decompress(cinfo) \
+ jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
+ (size_t) sizeof(struct jpeg_decompress_struct))
+EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
+ int version, size_t structsize));
+EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
+ int version, size_t structsize));
+/* Destruction of JPEG compression objects */
+EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
+EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
+
+/* Standard data source and destination managers: stdio streams. */
+/* Caller is responsible for opening the file before and closing after. */
+EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
+EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
+
+/* Default parameter setup for compression */
+EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
+/* Compression parameter setup aids */
+EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
+ J_COLOR_SPACE colorspace));
+EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
+EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
+ boolean force_baseline));
+EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
+ int scale_factor,
+ boolean force_baseline));
+EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
+ const unsigned int *basic_table,
+ int scale_factor,
+ boolean force_baseline));
+EXTERN(int) jpeg_quality_scaling JPP((int quality));
+EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
+EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
+ boolean suppress));
+EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
+EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
+
+/* Main entry points for compression */
+EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
+ boolean write_all_tables));
+EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
+ JSAMPARRAY scanlines,
+ JDIMENSION num_lines));
+EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
+
+/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
+EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
+ JSAMPIMAGE data,
+ JDIMENSION num_lines));
+
+/* Write a special marker. See libjpeg.doc concerning safe usage. */
+EXTERN(void) jpeg_write_marker
+ JPP((j_compress_ptr cinfo, int marker,
+ const JOCTET * dataptr, unsigned int datalen));
+/* Same, but piecemeal. */
+EXTERN(void) jpeg_write_m_header
+ JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
+EXTERN(void) jpeg_write_m_byte
+ JPP((j_compress_ptr cinfo, int val));
+
+/* Alternate compression function: just write an abbreviated table file */
+EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
+
+/* Decompression startup: read start of JPEG datastream to see what's there */
+EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
+ boolean require_image));
+/* Return value is one of: */
+#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
+#define JPEG_HEADER_OK 1 /* Found valid image datastream */
+#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
+/* If you pass require_image = TRUE (normal case), you need not check for
+ * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
+ * JPEG_SUSPENDED is only possible if you use a data source module that can
+ * give a suspension return (the stdio source module doesn't).
+ */
+
+/* Main entry points for decompression */
+EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
+EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
+ JSAMPARRAY scanlines,
+ JDIMENSION max_lines));
+EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
+
+/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
+EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
+ JSAMPIMAGE data,
+ JDIMENSION max_lines));
+
+/* Additional entry points for buffered-image mode. */
+EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
+EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
+ int scan_number));
+EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
+EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
+EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
+EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
+/* Return value is one of: */
+/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */
+#define JPEG_REACHED_SOS 1 /* Reached start of new scan */
+#define JPEG_REACHED_EOI 2 /* Reached end of image */
+#define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
+#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
+
+/* Precalculate output dimensions for current decompression parameters. */
+EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
+
+/* Control saving of COM and APPn markers into marker_list. */
+EXTERN(void) jpeg_save_markers
+ JPP((j_decompress_ptr cinfo, int marker_code,
+ unsigned int length_limit));
+
+/* Install a special processing method for COM or APPn markers. */
+EXTERN(void) jpeg_set_marker_processor
+ JPP((j_decompress_ptr cinfo, int marker_code,
+ jpeg_marker_parser_method routine));
+
+/* Read or write raw DCT coefficients --- useful for lossless transcoding. */
+EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
+EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
+ jvirt_barray_ptr * coef_arrays));
+EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
+ j_compress_ptr dstinfo));
+
+/* If you choose to abort compression or decompression before completing
+ * jpeg_finish_(de)compress, then you need to clean up to release memory,
+ * temporary files, etc. You can just call jpeg_destroy_(de)compress
+ * if you're done with the JPEG object, but if you want to clean it up and
+ * reuse it, call this:
+ */
+EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
+EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
+
+/* Generic versions of jpeg_abort and jpeg_destroy that work on either
+ * flavor of JPEG object. These may be more convenient in some places.
+ */
+EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
+EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
+
+/* Default restart-marker-resync procedure for use by data source modules */
+EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
+ int desired));
+
+
+/* These marker codes are exported since applications and data source modules
+ * are likely to want to use them.
+ */
+
+#define JPEG_RST0 0xD0 /* RST0 marker code */
+#define JPEG_EOI 0xD9 /* EOI marker code */
+#define JPEG_APP0 0xE0 /* APP0 marker code */
+#define JPEG_COM 0xFE /* COM marker code */
+
+
+/* If we have a brain-damaged compiler that emits warnings (or worse, errors)
+ * for structure definitions that are never filled in, keep it quiet by
+ * supplying dummy definitions for the various substructures.
+ */
+
+#ifdef INCOMPLETE_TYPES_BROKEN
+#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
+struct jvirt_sarray_control { long dummy; };
+struct jvirt_barray_control { long dummy; };
+struct jpeg_comp_master { long dummy; };
+struct jpeg_c_main_controller { long dummy; };
+struct jpeg_c_prep_controller { long dummy; };
+struct jpeg_c_coef_controller { long dummy; };
+struct jpeg_marker_writer { long dummy; };
+struct jpeg_color_converter { long dummy; };
+struct jpeg_downsampler { long dummy; };
+struct jpeg_forward_dct { long dummy; };
+struct jpeg_entropy_encoder { long dummy; };
+struct jpeg_decomp_master { long dummy; };
+struct jpeg_d_main_controller { long dummy; };
+struct jpeg_d_coef_controller { long dummy; };
+struct jpeg_d_post_controller { long dummy; };
+struct jpeg_input_controller { long dummy; };
+struct jpeg_marker_reader { long dummy; };
+struct jpeg_entropy_decoder { long dummy; };
+struct jpeg_inverse_dct { long dummy; };
+struct jpeg_upsampler { long dummy; };
+struct jpeg_color_deconverter { long dummy; };
+struct jpeg_color_quantizer { long dummy; };
+#endif /* JPEG_INTERNALS */
+#endif /* INCOMPLETE_TYPES_BROKEN */
+
+
+/*
+ * The JPEG library modules define JPEG_INTERNALS before including this file.
+ * The internal structure declarations are read only when that is true.
+ * Applications using the library should not include jpegint.h, but may wish
+ * to include jerror.h.
+ */
+
+#ifdef JPEG_INTERNALS
+#include "jpegint.h" /* fetch private declarations */
+#include "jerror.h" /* fetch error codes too */
+#endif
+
+#endif /* JPEGLIB_H */
diff --git a/osframework/source/ImageLib/jpeg/jpegtran.1 b/osframework/source/ImageLib/jpeg/jpegtran.1
new file mode 100644
index 0000000..ba3c2b3
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jpegtran.1
@@ -0,0 +1,238 @@
+.TH JPEGTRAN 1 "3 August 1997"
+.SH NAME
+jpegtran \- lossless transformation of JPEG files
+.SH SYNOPSIS
+.B jpegtran
+[
+.I options
+]
+[
+.I filename
+]
+.LP
+.SH DESCRIPTION
+.LP
+.B jpegtran
+performs various useful transformations of JPEG files.
+It can translate the coded representation from one variant of JPEG to another,
+for example from baseline JPEG to progressive JPEG or vice versa. It can also
+perform some rearrangements of the image data, for example turning an image
+from landscape to portrait format by rotation.
+.PP
+.B jpegtran
+works by rearranging the compressed data (DCT coefficients), without
+ever fully decoding the image. Therefore, its transformations are lossless:
+there is no image degradation at all, which would not be true if you used
+.B djpeg
+followed by
+.B cjpeg
+to accomplish the same conversion. But by the same token,
+.B jpegtran
+cannot perform lossy operations such as changing the image quality.
+.PP
+.B jpegtran
+reads the named JPEG/JFIF file, or the standard input if no file is
+named, and produces a JPEG/JFIF file on the standard output.
+.SH OPTIONS
+All switch names may be abbreviated; for example,
+.B \-optimize
+may be written
+.B \-opt
+or
+.BR \-o .
+Upper and lower case are equivalent.
+British spellings are also accepted (e.g.,
+.BR \-optimise ),
+though for brevity these are not mentioned below.
+.PP
+To specify the coded JPEG representation used in the output file,
+.B jpegtran
+accepts a subset of the switches recognized by
+.BR cjpeg :
+.TP
+.B \-optimize
+Perform optimization of entropy encoding parameters.
+.TP
+.B \-progressive
+Create progressive JPEG file.
+.TP
+.BI \-restart " N"
+Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
+attached to the number.
+.TP
+.BI \-scans " file"
+Use the scan script given in the specified text file.
+.PP
+See
+.BR cjpeg (1)
+for more details about these switches.
+If you specify none of these switches, you get a plain baseline-JPEG output
+file. The quality setting and so forth are determined by the input file.
+.PP
+The image can be losslessly transformed by giving one of these switches:
+.TP
+.B \-flip horizontal
+Mirror image horizontally (left-right).
+.TP
+.B \-flip vertical
+Mirror image vertically (top-bottom).
+.TP
+.B \-rotate 90
+Rotate image 90 degrees clockwise.
+.TP
+.B \-rotate 180
+Rotate image 180 degrees.
+.TP
+.B \-rotate 270
+Rotate image 270 degrees clockwise (or 90 ccw).
+.TP
+.B \-transpose
+Transpose image (across UL-to-LR axis).
+.TP
+.B \-transverse
+Transverse transpose (across UR-to-LL axis).
+.PP
+The transpose transformation has no restrictions regarding image dimensions.
+The other transformations operate rather oddly if the image dimensions are not
+a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
+transform complete blocks of DCT coefficient data in the desired way.
+.PP
+.BR jpegtran 's
+default behavior when transforming an odd-size image is designed
+to preserve exact reversibility and mathematical consistency of the
+transformation set. As stated, transpose is able to flip the entire image
+area. Horizontal mirroring leaves any partial iMCU column at the right edge
+untouched, but is able to flip all rows of the image. Similarly, vertical
+mirroring leaves any partial iMCU row at the bottom edge untouched, but is
+able to flip all columns. The other transforms can be built up as sequences
+of transpose and flip operations; for consistency, their actions on edge
+pixels are defined to be the same as the end result of the corresponding
+transpose-and-flip sequence.
+.PP
+For practical use, you may prefer to discard any untransformable edge pixels
+rather than having a strange-looking strip along the right and/or bottom edges
+of a transformed image. To do this, add the
+.B \-trim
+switch:
+.TP
+.B \-trim
+Drop non-transformable edge blocks.
+.PP
+Obviously, a transformation with
+.B \-trim
+is not reversible, so strictly speaking
+.B jpegtran
+with this switch is not lossless. Also, the expected mathematical
+equivalences between the transformations no longer hold. For example,
+.B \-rot 270 -trim
+trims only the bottom edge, but
+.B \-rot 90 -trim
+followed by
+.B \-rot 180 -trim
+trims both edges.
+.PP
+Another not-strictly-lossless transformation switch is:
+.TP
+.B \-grayscale
+Force grayscale output.
+.PP
+This option discards the chrominance channels if the input image is YCbCr
+(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
+luminance channel is preserved exactly, so this is a better method of reducing
+to grayscale than decompression, conversion, and recompression. This switch
+is particularly handy for fixing a monochrome picture that was mistakenly
+encoded as a color JPEG. (In such a case, the space savings from getting rid
+of the near-empty chroma channels won't be large; but the decoding time for
+a grayscale JPEG is substantially less than that for a color JPEG.)
+.PP
+.B jpegtran
+also recognizes these switches that control what to do with "extra" markers,
+such as comment blocks:
+.TP
+.B \-copy none
+Copy no extra markers from source file. This setting suppresses all
+comments and other excess baggage present in the source file.
+.TP
+.B \-copy comments
+Copy only comment markers. This setting copies comments from the source file,
+but discards any other inessential data.
+.TP
+.B \-copy all
+Copy all extra markers. This setting preserves miscellaneous markers
+found in the source file, such as JFIF thumbnails and Photoshop settings.
+In some files these extra markers can be sizable.
+.PP
+The default behavior is
+.BR "\-copy comments" .
+(Note: in IJG releases v6 and v6a,
+.B jpegtran
+always did the equivalent of
+.BR "\-copy none" .)
+.PP
+Additional switches recognized by jpegtran are:
+.TP
+.BI \-maxmemory " N"
+Set limit for amount of memory to use in processing large images. Value is
+in thousands of bytes, or millions of bytes if "M" is attached to the
+number. For example,
+.B \-max 4m
+selects 4000000 bytes. If more space is needed, temporary files will be used.
+.TP
+.BI \-outfile " name"
+Send output image to the named file, not to standard output.
+.TP
+.B \-verbose
+Enable debug printout. More
+.BR \-v 's
+give more output. Also, version information is printed at startup.
+.TP
+.B \-debug
+Same as
+.BR \-verbose .
+.SH EXAMPLES
+.LP
+This example converts a baseline JPEG file to progressive form:
+.IP
+.B jpegtran \-progressive
+.I foo.jpg
+.B >
+.I fooprog.jpg
+.PP
+This example rotates an image 90 degrees clockwise, discarding any
+unrotatable edge pixels:
+.IP
+.B jpegtran \-rot 90 -trim
+.I foo.jpg
+.B >
+.I foo90.jpg
+.SH ENVIRONMENT
+.TP
+.B JPEGMEM
+If this environment variable is set, its value is the default memory limit.
+The value is specified as described for the
+.B \-maxmemory
+switch.
+.B JPEGMEM
+overrides the default value specified when the program was compiled, and
+itself is overridden by an explicit
+.BR \-maxmemory .
+.SH SEE ALSO
+.BR cjpeg (1),
+.BR djpeg (1),
+.BR rdjpgcom (1),
+.BR wrjpgcom (1)
+.br
+Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
+Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
+.SH AUTHOR
+Independent JPEG Group
+.SH BUGS
+Arithmetic coding is not supported for legal reasons.
+.PP
+The transform options can't transform odd-size images perfectly. Use
+.B \-trim
+if you don't like the results without it.
+.PP
+The entire image is read into memory and then written out again, even in
+cases where this isn't really necessary. Expect swapping on large images,
+especially when using the more complex transform options.
diff --git a/osframework/source/ImageLib/jpeg/jpegtran.c b/osframework/source/ImageLib/jpeg/jpegtran.c
new file mode 100644
index 0000000..719aaa7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jpegtran.c
@@ -0,0 +1,504 @@
+/*
+ * jpegtran.c
+ *
+ * Copyright (C) 1995-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a command-line user interface for JPEG transcoding.
+ * It is very similar to cjpeg.c, but provides lossless transcoding between
+ * different JPEG file formats. It also provides some lossless and sort-of-
+ * lossless transformations of JPEG data.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "transupp.h" /* Support routines for jpegtran */
+#include "jversion.h" /* for version message */
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+
+/*
+ * Argument-parsing code.
+ * The switch parser is designed to be useful with DOS-style command line
+ * syntax, ie, intermixed switches and file names, where only the switches
+ * to the left of a given file name affect processing of that file.
+ * The main program in this file doesn't actually use this capability...
+ */
+
+
+static const char * progname; /* program name for error messages */
+static char * outfilename; /* for -outfile switch */
+static JCOPY_OPTION copyoption; /* -copy switch */
+static jpeg_transform_info transformoption; /* image transformation options */
+
+
+LOCAL(void)
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -copy none Copy no extra markers from source file\n");
+ fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
+ fprintf(stderr, " -copy all Copy all extra markers\n");
+#ifdef ENTROPY_OPT_SUPPORTED
+ fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
+#endif
+#ifdef C_PROGRESSIVE_SUPPORTED
+ fprintf(stderr, " -progressive Create progressive JPEG file\n");
+#endif
+#if TRANSFORMS_SUPPORTED
+ fprintf(stderr, "Switches for modifying the image:\n");
+ fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
+ fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
+ fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
+ fprintf(stderr, " -transpose Transpose image\n");
+ fprintf(stderr, " -transverse Transverse transpose image\n");
+ fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
+#endif /* TRANSFORMS_SUPPORTED */
+ fprintf(stderr, "Switches for advanced users:\n");
+ fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
+ fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
+ fprintf(stderr, " -outfile name Specify name for output file\n");
+ fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ fprintf(stderr, "Switches for wizards:\n");
+#ifdef C_ARITH_CODING_SUPPORTED
+ fprintf(stderr, " -arithmetic Use arithmetic coding\n");
+#endif
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
+#endif
+ exit(EXIT_FAILURE);
+}
+
+
+LOCAL(void)
+select_transform (JXFORM_CODE transform)
+/* Silly little routine to detect multiple transform options,
+ * which we can't handle.
+ */
+{
+#if TRANSFORMS_SUPPORTED
+ if (transformoption.transform == JXFORM_NONE ||
+ transformoption.transform == transform) {
+ transformoption.transform = transform;
+ } else {
+ fprintf(stderr, "%s: can only do one image transformation at a time\n",
+ progname);
+ usage();
+ }
+#else
+ fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+}
+
+
+LOCAL(int)
+parse_switches (j_compress_ptr cinfo, int argc, char **argv,
+ int last_file_arg_seen, boolean for_real)
+/* Parse optional switches.
+ * Returns argv[] index of first file-name argument (== argc if none).
+ * Any file names with indexes <= last_file_arg_seen are ignored;
+ * they have presumably been processed in a previous iteration.
+ * (Pass 0 for last_file_arg_seen on the first or only iteration.)
+ * for_real is FALSE on the first (dummy) pass; we may skip any expensive
+ * processing.
+ */
+{
+ int argn;
+ char * arg;
+ boolean simple_progressive;
+ char * scansarg = NULL; /* saves -scans parm if any */
+
+ /* Set up default JPEG parameters. */
+ simple_progressive = FALSE;
+ outfilename = NULL;
+ copyoption = JCOPYOPT_DEFAULT;
+ transformoption.transform = JXFORM_NONE;
+ transformoption.trim = FALSE;
+ transformoption.force_grayscale = FALSE;
+ cinfo->err->trace_level = 0;
+
+ /* Scan command line options, adjust parameters */
+
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (*arg != '-') {
+ /* Not a switch, must be a file name argument */
+ if (argn <= last_file_arg_seen) {
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
+ }
+ break; /* else done parsing switches */
+ }
+ arg++; /* advance past switch marker character */
+
+ if (keymatch(arg, "arithmetic", 1)) {
+ /* Use arithmetic coding. */
+#ifdef C_ARITH_CODING_SUPPORTED
+ cinfo->arith_code = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "copy", 1)) {
+ /* Select which extra markers to copy. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "none", 1)) {
+ copyoption = JCOPYOPT_NONE;
+ } else if (keymatch(argv[argn], "comments", 1)) {
+ copyoption = JCOPYOPT_COMMENTS;
+ } else if (keymatch(argv[argn], "all", 1)) {
+ copyoption = JCOPYOPT_ALL;
+ } else
+ usage();
+
+ } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
+ /* Enable debug printouts. */
+ /* On first -d, print version identification */
+ static boolean printed_version = FALSE;
+
+ if (! printed_version) {
+ fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n",
+ JVERSION, JCOPYRIGHT);
+ printed_version = TRUE;
+ }
+ cinfo->err->trace_level++;
+
+ } else if (keymatch(arg, "flip", 1)) {
+ /* Mirror left-right or top-bottom. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "horizontal", 1))
+ select_transform(JXFORM_FLIP_H);
+ else if (keymatch(argv[argn], "vertical", 1))
+ select_transform(JXFORM_FLIP_V);
+ else
+ usage();
+
+ } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
+ /* Force to grayscale. */
+#if TRANSFORMS_SUPPORTED
+ transformoption.force_grayscale = TRUE;
+#else
+ select_transform(JXFORM_NONE); /* force an error */
+#endif
+
+ } else if (keymatch(arg, "maxmemory", 3)) {
+ /* Maximum memory in Kb (or Mb with 'm'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (ch == 'm' || ch == 'M')
+ lval *= 1000L;
+ cinfo->mem->max_memory_to_use = lval * 1000L;
+
+ } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
+ /* Enable entropy parm optimization. */
+#ifdef ENTROPY_OPT_SUPPORTED
+ cinfo->optimize_coding = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "outfile", 4)) {
+ /* Set output file name. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
+
+ } else if (keymatch(arg, "progressive", 1)) {
+ /* Select simple progressive mode. */
+#ifdef C_PROGRESSIVE_SUPPORTED
+ simple_progressive = TRUE;
+ /* We must postpone execution until num_components is known. */
+#else
+ fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "restart", 1)) {
+ /* Restart interval in MCU rows (or in MCUs with 'b'). */
+ long lval;
+ char ch = 'x';
+
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
+ usage();
+ if (lval < 0 || lval > 65535L)
+ usage();
+ if (ch == 'b' || ch == 'B') {
+ cinfo->restart_interval = (unsigned int) lval;
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
+ } else {
+ cinfo->restart_in_rows = (int) lval;
+ /* restart_interval will be computed during startup */
+ }
+
+ } else if (keymatch(arg, "rotate", 2)) {
+ /* Rotate 90, 180, or 270 degrees (measured clockwise). */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (keymatch(argv[argn], "90", 2))
+ select_transform(JXFORM_ROT_90);
+ else if (keymatch(argv[argn], "180", 3))
+ select_transform(JXFORM_ROT_180);
+ else if (keymatch(argv[argn], "270", 3))
+ select_transform(JXFORM_ROT_270);
+ else
+ usage();
+
+ } else if (keymatch(arg, "scans", 1)) {
+ /* Set scan script. */
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ scansarg = argv[argn];
+ /* We must postpone reading the file in case -progressive appears. */
+#else
+ fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
+ } else if (keymatch(arg, "transpose", 1)) {
+ /* Transpose (across UL-to-LR axis). */
+ select_transform(JXFORM_TRANSPOSE);
+
+ } else if (keymatch(arg, "transverse", 6)) {
+ /* Transverse transpose (across UR-to-LL axis). */
+ select_transform(JXFORM_TRANSVERSE);
+
+ } else if (keymatch(arg, "trim", 3)) {
+ /* Trim off any partial edge MCUs that the transform can't handle. */
+ transformoption.trim = TRUE;
+
+ } else {
+ usage(); /* bogus switch */
+ }
+ }
+
+ /* Post-switch-scanning cleanup */
+
+ if (for_real) {
+
+#ifdef C_PROGRESSIVE_SUPPORTED
+ if (simple_progressive) /* process -progressive; -scans can override */
+ jpeg_simple_progression(cinfo);
+#endif
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+ if (scansarg != NULL) /* process -scans if it was present */
+ if (! read_scan_script(cinfo, scansarg))
+ usage();
+#endif
+ }
+
+ return argn; /* return index of next arg (file name) */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ struct jpeg_decompress_struct srcinfo;
+ struct jpeg_compress_struct dstinfo;
+ struct jpeg_error_mgr jsrcerr, jdsterr;
+#ifdef PROGRESS_REPORT
+ struct cdjpeg_progress_mgr progress;
+#endif
+ jvirt_barray_ptr * src_coef_arrays;
+ jvirt_barray_ptr * dst_coef_arrays;
+ int file_index;
+ FILE * input_file;
+ FILE * output_file;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "jpegtran"; /* in case C library doesn't provide it */
+
+ /* Initialize the JPEG decompression object with default error handling. */
+ srcinfo.err = jpeg_std_error(&jsrcerr);
+ jpeg_create_decompress(&srcinfo);
+ /* Initialize the JPEG compression object with default error handling. */
+ dstinfo.err = jpeg_std_error(&jdsterr);
+ jpeg_create_compress(&dstinfo);
+
+ /* Now safe to enable signal catcher.
+ * Note: we assume only the decompression object will have virtual arrays.
+ */
+#ifdef NEED_SIGNAL_CATCHER
+ enable_signal_catcher((j_common_ptr) &srcinfo);
+#endif
+
+ /* Scan command line to find file names.
+ * It is convenient to use just one switch-parsing routine, but the switch
+ * values read here are mostly ignored; we will rescan the switches after
+ * opening the input file. Also note that most of the switches affect the
+ * destination JPEG object, so we parse into that and then copy over what
+ * needs to affects the source too.
+ */
+
+ file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
+ jsrcerr.trace_level = jdsterr.trace_level;
+ srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
+
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have either -outfile switch or explicit output file name */
+ if (outfilename == NULL) {
+ if (file_index != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ outfilename = argv[file_index+1];
+ } else {
+ if (file_index != argc-1) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (file_index < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Open the input file. */
+ if (file_index < argc) {
+ if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+ input_file = read_stdin();
+ }
+
+ /* Open the output file. */
+ if (outfilename != NULL) {
+ if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default output file is stdout */
+ output_file = write_stdout();
+ }
+
+#ifdef PROGRESS_REPORT
+ start_progress_monitor((j_common_ptr) &dstinfo, &progress);
+#endif
+
+ /* Specify data source for decompression */
+ jpeg_stdio_src(&srcinfo, input_file);
+
+ /* Enable saving of extra markers that we want to copy */
+ jcopy_markers_setup(&srcinfo, copyoption);
+
+ /* Read file header */
+ (void) jpeg_read_header(&srcinfo, TRUE);
+
+ /* Any space needed by a transform option must be requested before
+ * jpeg_read_coefficients so that memory allocation will be done right.
+ */
+#if TRANSFORMS_SUPPORTED
+ jtransform_request_workspace(&srcinfo, &transformoption);
+#endif
+
+ /* Read source file as DCT coefficients */
+ src_coef_arrays = jpeg_read_coefficients(&srcinfo);
+
+ /* Initialize destination compression parameters from source values */
+ jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
+
+ /* Adjust destination parameters if required by transform options;
+ * also find out which set of coefficient arrays will hold the output.
+ */
+#if TRANSFORMS_SUPPORTED
+ dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
+ src_coef_arrays,
+ &transformoption);
+#else
+ dst_coef_arrays = src_coef_arrays;
+#endif
+
+ /* Adjust default compression parameters by re-parsing the options */
+ file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);
+
+ /* Specify data destination for compression */
+ jpeg_stdio_dest(&dstinfo, output_file);
+
+ /* Start compressor (note no image data is actually written here) */
+ jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
+
+ /* Copy to the output file any extra markers that we want to preserve */
+ jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
+
+ /* Execute image transformation, if any */
+#if TRANSFORMS_SUPPORTED
+ jtransform_execute_transformation(&srcinfo, &dstinfo,
+ src_coef_arrays,
+ &transformoption);
+#endif
+
+ /* Finish compression and release memory */
+ jpeg_finish_compress(&dstinfo);
+ jpeg_destroy_compress(&dstinfo);
+ (void) jpeg_finish_decompress(&srcinfo);
+ jpeg_destroy_decompress(&srcinfo);
+
+ /* Close files, if we opened them */
+ if (input_file != stdin)
+ fclose(input_file);
+ if (output_file != stdout)
+ fclose(output_file);
+
+#ifdef PROGRESS_REPORT
+ end_progress_monitor((j_common_ptr) &dstinfo);
+#endif
+
+ /* All done. */
+ exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/osframework/source/ImageLib/jpeg/jquant1.c b/osframework/source/ImageLib/jpeg/jquant1.c
new file mode 100644
index 0000000..aaa34a1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jquant1.c
@@ -0,0 +1,856 @@
+/*
+ * jquant1.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains 1-pass color quantization (color mapping) routines.
+ * These routines provide mapping to a fixed color map using equally spaced
+ * color values. Optional Floyd-Steinberg or ordered dithering is available.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+#ifdef QUANT_1PASS_SUPPORTED
+
+
+/*
+ * The main purpose of 1-pass quantization is to provide a fast, if not very
+ * high quality, colormapped output capability. A 2-pass quantizer usually
+ * gives better visual quality; however, for quantized grayscale output this
+ * quantizer is perfectly adequate. Dithering is highly recommended with this
+ * quantizer, though you can turn it off if you really want to.
+ *
+ * In 1-pass quantization the colormap must be chosen in advance of seeing the
+ * image. We use a map consisting of all combinations of Ncolors[i] color
+ * values for the i'th component. The Ncolors[] values are chosen so that
+ * their product, the total number of colors, is no more than that requested.
+ * (In most cases, the product will be somewhat less.)
+ *
+ * Since the colormap is orthogonal, the representative value for each color
+ * component can be determined without considering the other components;
+ * then these indexes can be combined into a colormap index by a standard
+ * N-dimensional-array-subscript calculation. Most of the arithmetic involved
+ * can be precalculated and stored in the lookup table colorindex[].
+ * colorindex[i][j] maps pixel value j in component i to the nearest
+ * representative value (grid plane) for that component; this index is
+ * multiplied by the array stride for component i, so that the
+ * index of the colormap entry closest to a given pixel value is just
+ * sum( colorindex[component-number][pixel-component-value] )
+ * Aside from being fast, this scheme allows for variable spacing between
+ * representative values with no additional lookup cost.
+ *
+ * If gamma correction has been applied in color conversion, it might be wise
+ * to adjust the color grid spacing so that the representative colors are
+ * equidistant in linear space. At this writing, gamma correction is not
+ * implemented by jdcolor, so nothing is done here.
+ */
+
+
+/* Declarations for ordered dithering.
+ *
+ * We use a standard 16x16 ordered dither array. The basic concept of ordered
+ * dithering is described in many references, for instance Dale Schumacher's
+ * chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991).
+ * In place of Schumacher's comparisons against a "threshold" value, we add a
+ * "dither" value to the input pixel and then round the result to the nearest
+ * output value. The dither value is equivalent to (0.5 - threshold) times
+ * the distance between output values. For ordered dithering, we assume that
+ * the output colors are equally spaced; if not, results will probably be
+ * worse, since the dither may be too much or too little at a given point.
+ *
+ * The normal calculation would be to form pixel value + dither, range-limit
+ * this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.
+ * We can skip the separate range-limiting step by extending the colorindex
+ * table in both directions.
+ */
+
+#define ODITHER_SIZE 16 /* dimension of dither matrix */
+/* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */
+#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
+#define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
+
+typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
+typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
+
+static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
+ /* Bayer's order-4 dither array. Generated by the code given in
+ * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I.
+ * The values in this array must range from 0 to ODITHER_CELLS-1.
+ */
+ { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
+ { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
+ { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
+ { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
+ { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
+ { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
+ { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
+ { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
+ { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
+ { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
+ { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
+ { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
+ { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
+ { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
+ { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
+ { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
+};
+
+
+/* Declarations for Floyd-Steinberg dithering.
+ *
+ * Errors are accumulated into the array fserrors[], at a resolution of
+ * 1/16th of a pixel count. The error at a given pixel is propagated
+ * to its not-yet-processed neighbors using the standard F-S fractions,
+ * ... (here) 7/16
+ * 3/16 5/16 1/16
+ * We work left-to-right on even rows, right-to-left on odd rows.
+ *
+ * We can get away with a single array (holding one row's worth of errors)
+ * by using it to store the current row's errors at pixel columns not yet
+ * processed, but the next row's errors at columns already processed. We
+ * need only a few extra variables to hold the errors immediately around the
+ * current column. (If we are lucky, those variables are in registers, but
+ * even if not, they're probably cheaper to access than array elements are.)
+ *
+ * The fserrors[] array is indexed [component#][position].
+ * We provide (#columns + 2) entries per component; the extra entry at each
+ * end saves us from special-casing the first and last pixels.
+ *
+ * Note: on a wide image, we might not have enough room in a PC's near data
+ * segment to hold the error array; so it is allocated with alloc_large.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+typedef INT16 FSERROR; /* 16 bits should be enough */
+typedef int LOCFSERROR; /* use 'int' for calculation temps */
+#else
+typedef INT32 FSERROR; /* may need more than 16 bits */
+typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
+#endif
+
+typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
+
+
+/* Private subobject */
+
+#define MAX_Q_COMPS 4 /* max components I can handle */
+
+typedef struct {
+ struct jpeg_color_quantizer pub; /* public fields */
+
+ /* Initially allocated colormap is saved here */
+ JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
+ int sv_actual; /* number of entries in use */
+
+ JSAMPARRAY colorindex; /* Precomputed mapping for speed */
+ /* colorindex[i][j] = index of color closest to pixel value j in component i,
+ * premultiplied as described above. Since colormap indexes must fit into
+ * JSAMPLEs, the entries of this array will too.
+ */
+ boolean is_padded; /* is the colorindex padded for odither? */
+
+ int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
+
+ /* Variables for ordered dithering */
+ int row_index; /* cur row's vertical index in dither matrix */
+ ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
+
+ /* Variables for Floyd-Steinberg dithering */
+ FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
+ boolean on_odd_row; /* flag to remember which row we are on */
+} my_cquantizer;
+
+typedef my_cquantizer * my_cquantize_ptr;
+
+
+/*
+ * Policy-making subroutines for create_colormap and create_colorindex.
+ * These routines determine the colormap to be used. The rest of the module
+ * only assumes that the colormap is orthogonal.
+ *
+ * * select_ncolors decides how to divvy up the available colors
+ * among the components.
+ * * output_value defines the set of representative values for a component.
+ * * largest_input_value defines the mapping from input values to
+ * representative values for a component.
+ * Note that the latter two routines may impose different policies for
+ * different components, though this is not currently done.
+ */
+
+
+LOCAL(int)
+select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
+/* 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). */
+{
+ int nc = cinfo->out_color_components; /* number of color components */
+ int max_colors = cinfo->desired_number_of_colors;
+ int total_colors, iroot, i, j;
+ boolean changed;
+ long temp;
+ static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
+
+ /* 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)
+ ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
+
+ /* 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.
+ * Sometimes, the first component can be incremented more than once!
+ * (Example: for 16 colors, we start at 2*2*2, go to 3*2*2, then 4*2*2.)
+ * In RGB colorspace, try to increment G first, then R, then B.
+ */
+ do {
+ changed = FALSE;
+ for (i = 0; i < nc; i++) {
+ j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : 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 with this pass */
+ Ncolors[j]++; /* OK, apply the increment */
+ total_colors = (int) temp;
+ changed = TRUE;
+ }
+ } while (changed);
+
+ return total_colors;
+}
+
+
+LOCAL(int)
+output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
+/* Return j'th output value, where j will range from 0 to maxj */
+/* The output values must fall in 0..MAXJSAMPLE in increasing order */
+{
+ /* We always provide values 0 and MAXJSAMPLE for each component;
+ * any additional values are equally spaced between these limits.
+ * (Forcing the upper and lower values to the limits ensures that
+ * dithering can't produce a color outside the selected gamut.)
+ */
+ return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
+}
+
+
+LOCAL(int)
+largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
+/* Return largest input value that should map to j'th output value */
+/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
+{
+ /* Breakpoints are halfway between values returned by output_value */
+ return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
+}
+
+
+/*
+ * Create the colormap.
+ */
+
+LOCAL(void)
+create_colormap (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ JSAMPARRAY colormap; /* Created colormap */
+ int total_colors; /* Number of distinct output colors */
+ int i,j,k, nci, blksize, blkdist, ptr, val;
+
+ /* Select number of colors for each component */
+ total_colors = select_ncolors(cinfo, cquantize->Ncolors);
+
+ /* Report selected color counts */
+ if (cinfo->out_color_components == 3)
+ TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
+ total_colors, cquantize->Ncolors[0],
+ cquantize->Ncolors[1], cquantize->Ncolors[2]);
+ else
+ TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
+
+ /* Allocate and fill in the colormap. */
+ /* The colors are ordered in the map in standard row-major order, */
+ /* i.e. rightmost (highest-indexed) color changes most rapidly. */
+
+ colormap = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
+
+ /* blksize is number of adjacent repeated entries for a component */
+ /* blkdist is distance between groups of identical entries for a component */
+ blkdist = total_colors;
+
+ for (i = 0; i < cinfo->out_color_components; i++) {
+ /* fill in colormap entries for i'th color component */
+ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
+ blksize = blkdist / nci;
+ for (j = 0; j < nci; j++) {
+ /* Compute j'th output value (out of nci) for component */
+ val = output_value(cinfo, i, j, nci-1);
+ /* Fill in all colormap entries that have this value of this component */
+ for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
+ /* fill in blksize entries beginning at ptr */
+ for (k = 0; k < blksize; k++)
+ colormap[i][ptr+k] = (JSAMPLE) val;
+ }
+ }
+ blkdist = blksize; /* blksize of this color is blkdist of next */
+ }
+
+ /* Save the colormap in private storage,
+ * where it will survive color quantization mode changes.
+ */
+ cquantize->sv_colormap = colormap;
+ cquantize->sv_actual = total_colors;
+}
+
+
+/*
+ * Create the color index table.
+ */
+
+LOCAL(void)
+create_colorindex (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ JSAMPROW indexptr;
+ int i,j,k, nci, blksize, val, pad;
+
+ /* For ordered dither, we pad the color index tables by MAXJSAMPLE in
+ * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
+ * This is not necessary in the other dithering modes. However, we
+ * flag whether it was done in case user changes dithering mode.
+ */
+ if (cinfo->dither_mode == JDITHER_ORDERED) {
+ pad = MAXJSAMPLE*2;
+ cquantize->is_padded = TRUE;
+ } else {
+ pad = 0;
+ cquantize->is_padded = FALSE;
+ }
+
+ cquantize->colorindex = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) (MAXJSAMPLE+1 + pad),
+ (JDIMENSION) cinfo->out_color_components);
+
+ /* blksize is number of adjacent repeated entries for a component */
+ blksize = cquantize->sv_actual;
+
+ for (i = 0; i < cinfo->out_color_components; i++) {
+ /* fill in colorindex entries for i'th color component */
+ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
+ blksize = blksize / nci;
+
+ /* adjust colorindex pointers to provide padding at negative indexes. */
+ if (pad)
+ cquantize->colorindex[i] += MAXJSAMPLE;
+
+ /* in loop, val = index of current output value, */
+ /* and k = largest j that maps to current val */
+ indexptr = cquantize->colorindex[i];
+ val = 0;
+ k = largest_input_value(cinfo, i, 0, nci-1);
+ for (j = 0; j <= MAXJSAMPLE; j++) {
+ while (j > k) /* advance val if past boundary */
+ k = largest_input_value(cinfo, i, ++val, nci-1);
+ /* premultiply so that no multiplication needed in main processing */
+ indexptr[j] = (JSAMPLE) (val * blksize);
+ }
+ /* Pad at both ends if necessary */
+ if (pad)
+ for (j = 1; j <= MAXJSAMPLE; j++) {
+ indexptr[-j] = indexptr[0];
+ indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
+ }
+ }
+}
+
+
+/*
+ * Create an ordered-dither array for a component having ncolors
+ * distinct output values.
+ */
+
+LOCAL(ODITHER_MATRIX_PTR)
+make_odither_array (j_decompress_ptr cinfo, int ncolors)
+{
+ ODITHER_MATRIX_PTR odither;
+ int j,k;
+ INT32 num,den;
+
+ odither = (ODITHER_MATRIX_PTR)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(ODITHER_MATRIX));
+ /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
+ * Hence the dither value for the matrix cell with fill order f
+ * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
+ * On 16-bit-int machine, be careful to avoid overflow.
+ */
+ den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
+ for (j = 0; j < ODITHER_SIZE; j++) {
+ for (k = 0; k < ODITHER_SIZE; k++) {
+ num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
+ * MAXJSAMPLE;
+ /* Ensure round towards zero despite C's lack of consistency
+ * about rounding negative values in integer division...
+ */
+ odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
+ }
+ }
+ return odither;
+}
+
+
+/*
+ * Create the ordered-dither tables.
+ * Components having the same number of representative colors may
+ * share a dither table.
+ */
+
+LOCAL(void)
+create_odither_tables (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ ODITHER_MATRIX_PTR odither;
+ int i, j, nci;
+
+ for (i = 0; i < cinfo->out_color_components; i++) {
+ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
+ odither = NULL; /* search for matching prior component */
+ for (j = 0; j < i; j++) {
+ if (nci == cquantize->Ncolors[j]) {
+ odither = cquantize->odither[j];
+ break;
+ }
+ }
+ if (odither == NULL) /* need a new table? */
+ odither = make_odither_array(cinfo, nci);
+ cquantize->odither[i] = odither;
+ }
+}
+
+
+/*
+ * Map some rows of pixels to the output colormapped representation.
+ */
+
+METHODDEF(void)
+color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+/* General case, no dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ JSAMPARRAY colorindex = cquantize->colorindex;
+ register int pixcode, ci;
+ register JSAMPROW ptrin, ptrout;
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+ register int nc = cinfo->out_color_components;
+
+ for (row = 0; row < num_rows; row++) {
+ ptrin = input_buf[row];
+ ptrout = output_buf[row];
+ for (col = width; col > 0; col--) {
+ pixcode = 0;
+ for (ci = 0; ci < nc; ci++) {
+ pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
+ }
+ *ptrout++ = (JSAMPLE) pixcode;
+ }
+ }
+}
+
+
+METHODDEF(void)
+color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+/* Fast path for out_color_components==3, no dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ register int pixcode;
+ register JSAMPROW ptrin, ptrout;
+ JSAMPROW colorindex0 = cquantize->colorindex[0];
+ JSAMPROW colorindex1 = cquantize->colorindex[1];
+ JSAMPROW colorindex2 = cquantize->colorindex[2];
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+
+ for (row = 0; row < num_rows; row++) {
+ ptrin = input_buf[row];
+ ptrout = output_buf[row];
+ for (col = width; col > 0; col--) {
+ pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
+ pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
+ pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
+ *ptrout++ = (JSAMPLE) pixcode;
+ }
+ }
+}
+
+
+METHODDEF(void)
+quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+/* General case, with ordered dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ register JSAMPROW input_ptr;
+ register JSAMPROW output_ptr;
+ JSAMPROW colorindex_ci;
+ int * dither; /* points to active row of dither matrix */
+ int row_index, col_index; /* current indexes into dither matrix */
+ int nc = cinfo->out_color_components;
+ int ci;
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+
+ for (row = 0; row < num_rows; row++) {
+ /* Initialize output values to 0 so can process components separately */
+ jzero_far((void FAR *) output_buf[row],
+ (size_t) (width * SIZEOF(JSAMPLE)));
+ row_index = cquantize->row_index;
+ for (ci = 0; ci < nc; ci++) {
+ input_ptr = input_buf[row] + ci;
+ output_ptr = output_buf[row];
+ colorindex_ci = cquantize->colorindex[ci];
+ dither = cquantize->odither[ci][row_index];
+ col_index = 0;
+
+ for (col = width; col > 0; col--) {
+ /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
+ * select output value, accumulate into output code for this pixel.
+ * Range-limiting need not be done explicitly, as we have extended
+ * the colorindex table to produce the right answers for out-of-range
+ * inputs. The maximum dither is +- MAXJSAMPLE; this sets the
+ * required amount of padding.
+ */
+ *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
+ input_ptr += nc;
+ output_ptr++;
+ col_index = (col_index + 1) & ODITHER_MASK;
+ }
+ }
+ /* Advance row index for next row */
+ row_index = (row_index + 1) & ODITHER_MASK;
+ cquantize->row_index = row_index;
+ }
+}
+
+
+METHODDEF(void)
+quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+/* Fast path for out_color_components==3, with ordered dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ register int pixcode;
+ register JSAMPROW input_ptr;
+ register JSAMPROW output_ptr;
+ JSAMPROW colorindex0 = cquantize->colorindex[0];
+ JSAMPROW colorindex1 = cquantize->colorindex[1];
+ JSAMPROW colorindex2 = cquantize->colorindex[2];
+ int * dither0; /* points to active row of dither matrix */
+ int * dither1;
+ int * dither2;
+ int row_index, col_index; /* current indexes into dither matrix */
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+
+ for (row = 0; row < num_rows; row++) {
+ row_index = cquantize->row_index;
+ input_ptr = input_buf[row];
+ output_ptr = output_buf[row];
+ dither0 = cquantize->odither[0][row_index];
+ dither1 = cquantize->odither[1][row_index];
+ dither2 = cquantize->odither[2][row_index];
+ col_index = 0;
+
+ for (col = width; col > 0; col--) {
+ pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
+ dither0[col_index]]);
+ pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
+ dither1[col_index]]);
+ pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
+ dither2[col_index]]);
+ *output_ptr++ = (JSAMPLE) pixcode;
+ col_index = (col_index + 1) & ODITHER_MASK;
+ }
+ row_index = (row_index + 1) & ODITHER_MASK;
+ cquantize->row_index = row_index;
+ }
+}
+
+
+METHODDEF(void)
+quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+/* General case, with Floyd-Steinberg dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ register LOCFSERROR cur; /* current error or pixel value */
+ LOCFSERROR belowerr; /* error for pixel below cur */
+ LOCFSERROR bpreverr; /* error for below/prev col */
+ LOCFSERROR bnexterr; /* error for below/next col */
+ LOCFSERROR delta;
+ register FSERRPTR errorptr; /* => fserrors[] at column before current */
+ register JSAMPROW input_ptr;
+ register JSAMPROW output_ptr;
+ JSAMPROW colorindex_ci;
+ JSAMPROW colormap_ci;
+ int pixcode;
+ int nc = cinfo->out_color_components;
+ int dir; /* 1 for left-to-right, -1 for right-to-left */
+ int dirnc; /* dir * nc */
+ int ci;
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+ JSAMPLE *range_limit = cinfo->sample_range_limit;
+ SHIFT_TEMPS
+
+ for (row = 0; row < num_rows; row++) {
+ /* Initialize output values to 0 so can process components separately */
+ jzero_far((void FAR *) output_buf[row],
+ (size_t) (width * SIZEOF(JSAMPLE)));
+ for (ci = 0; ci < nc; ci++) {
+ input_ptr = input_buf[row] + ci;
+ output_ptr = output_buf[row];
+ if (cquantize->on_odd_row) {
+ /* work right to left in this row */
+ input_ptr += (width-1) * nc; /* so point to rightmost pixel */
+ output_ptr += width-1;
+ dir = -1;
+ dirnc = -nc;
+ errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
+ } else {
+ /* work left to right in this row */
+ dir = 1;
+ dirnc = nc;
+ errorptr = cquantize->fserrors[ci]; /* => entry before first column */
+ }
+ colorindex_ci = cquantize->colorindex[ci];
+ colormap_ci = cquantize->sv_colormap[ci];
+ /* Preset error values: no error propagated to first pixel from left */
+ cur = 0;
+ /* and no error propagated to row below yet */
+ belowerr = 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.
+ */
+ cur = RIGHT_SHIFT(cur + 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.
+ */
+ cur += GETJSAMPLE(*input_ptr);
+ cur = GETJSAMPLE(range_limit[cur]);
+ /* Select output value, accumulate into output code for this pixel */
+ pixcode = GETJSAMPLE(colorindex_ci[cur]);
+ *output_ptr += (JSAMPLE) pixcode;
+ /* Compute actual representation error at this pixel */
+ /* Note: we can do this even though we don't have the final */
+ /* pixel code, because the colormap is orthogonal. */
+ cur -= GETJSAMPLE(colormap_ci[pixcode]);
+ /* 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.
+ */
+ bnexterr = cur;
+ delta = cur * 2;
+ cur += delta; /* form error * 3 */
+ errorptr[0] = (FSERROR) (bpreverr + cur);
+ cur += delta; /* form error * 5 */
+ bpreverr = belowerr + cur;
+ belowerr = bnexterr;
+ 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.
+ */
+ input_ptr += dirnc; /* advance input ptr to next column */
+ output_ptr += dir; /* advance output ptr to next column */
+ 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.
+ */
+ errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
+ }
+ cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
+ }
+}
+
+
+/*
+ * Allocate workspace for Floyd-Steinberg errors.
+ */
+
+LOCAL(void)
+alloc_fs_workspace (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ size_t arraysize;
+ int i;
+
+ arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
+ for (i = 0; i < cinfo->out_color_components; i++) {
+ cquantize->fserrors[i] = (FSERRPTR)
+ (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
+ }
+}
+
+
+/*
+ * Initialize for one-pass color quantization.
+ */
+
+METHODDEF(void)
+start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ size_t arraysize;
+ int i;
+
+ /* Install my colormap. */
+ cinfo->colormap = cquantize->sv_colormap;
+ cinfo->actual_number_of_colors = cquantize->sv_actual;
+
+ /* Initialize for desired dithering mode. */
+ switch (cinfo->dither_mode) {
+ case JDITHER_NONE:
+ if (cinfo->out_color_components == 3)
+ cquantize->pub.color_quantize = color_quantize3;
+ else
+ cquantize->pub.color_quantize = color_quantize;
+ break;
+ case JDITHER_ORDERED:
+ if (cinfo->out_color_components == 3)
+ cquantize->pub.color_quantize = quantize3_ord_dither;
+ else
+ cquantize->pub.color_quantize = quantize_ord_dither;
+ cquantize->row_index = 0; /* initialize state for ordered dither */
+ /* If user changed to ordered dither from another mode,
+ * we must recreate the color index table with padding.
+ * This will cost extra space, but probably isn't very likely.
+ */
+ if (! cquantize->is_padded)
+ create_colorindex(cinfo);
+ /* Create ordered-dither tables if we didn't already. */
+ if (cquantize->odither[0] == NULL)
+ create_odither_tables(cinfo);
+ break;
+ case JDITHER_FS:
+ cquantize->pub.color_quantize = quantize_fs_dither;
+ cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
+ /* Allocate Floyd-Steinberg workspace if didn't already. */
+ if (cquantize->fserrors[0] == NULL)
+ alloc_fs_workspace(cinfo);
+ /* Initialize the propagated errors to zero. */
+ arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
+ for (i = 0; i < cinfo->out_color_components; i++)
+ jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+ break;
+ }
+}
+
+
+/*
+ * Finish up at the end of the pass.
+ */
+
+METHODDEF(void)
+finish_pass_1_quant (j_decompress_ptr cinfo)
+{
+ /* no work in 1-pass case */
+}
+
+
+/*
+ * Switch to a new external colormap between output passes.
+ * Shouldn't get to this module!
+ */
+
+METHODDEF(void)
+new_color_map_1_quant (j_decompress_ptr cinfo)
+{
+ ERREXIT(cinfo, JERR_MODE_CHANGE);
+}
+
+
+/*
+ * Module initialization routine for 1-pass color quantization.
+ */
+
+GLOBAL(void)
+jinit_1pass_quantizer (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize;
+
+ cquantize = (my_cquantize_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_cquantizer));
+ cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
+ cquantize->pub.start_pass = start_pass_1_quant;
+ cquantize->pub.finish_pass = finish_pass_1_quant;
+ cquantize->pub.new_color_map = new_color_map_1_quant;
+ cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
+ cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
+
+ /* Make sure my internal arrays won't overflow */
+ if (cinfo->out_color_components > MAX_Q_COMPS)
+ ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
+ /* Make sure colormap indexes can be represented by JSAMPLEs */
+ if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
+ ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
+
+ /* Create the colormap and color index table. */
+ create_colormap(cinfo);
+ create_colorindex(cinfo);
+
+ /* Allocate Floyd-Steinberg workspace now if requested.
+ * We do this now since it is FAR storage and may affect the memory
+ * manager's space calculations. If the user changes to FS dither
+ * mode in a later pass, we will allocate the space then, and will
+ * possibly overrun the max_memory_to_use setting.
+ */
+ if (cinfo->dither_mode == JDITHER_FS)
+ alloc_fs_workspace(cinfo);
+}
+
+#endif /* QUANT_1PASS_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jquant2.c b/osframework/source/ImageLib/jpeg/jquant2.c
new file mode 100644
index 0000000..87a3920
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jquant2.c
@@ -0,0 +1,1310 @@
+/*
+ * jquant2.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains 2-pass color quantization (color mapping) routines.
+ * These routines provide selection of a custom color map for an image,
+ * followed by mapping of the image to that color map, with optional
+ * Floyd-Steinberg dithering.
+ * It is also possible to use just the second pass to map to an arbitrary
+ * externally-given color map.
+ *
+ * Note: ordered dithering is not supported, since there isn't any fast
+ * way to compute intercolor distances; it's unclear that ordered dither's
+ * fundamental assumptions even hold with an irregularly spaced color map.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+#ifdef QUANT_2PASS_SUPPORTED
+
+
+/*
+ * This module implements the well-known Heckbert paradigm for color
+ * quantization. Most of the ideas used here can be traced back to
+ * Heckbert's seminal paper
+ * Heckbert, Paul. "Color Image Quantization for Frame Buffer Display",
+ * Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304.
+ *
+ * In the first pass over the image, we accumulate a histogram showing the
+ * usage count of each possible color. To keep the histogram to a reasonable
+ * size, we reduce the precision of the input; typical practice is to retain
+ * 5 or 6 bits per color, so that 8 or 4 different input values are counted
+ * in the same histogram cell.
+ *
+ * Next, the color-selection step begins with a box representing the whole
+ * color space, and repeatedly splits the "largest" remaining box until we
+ * have as many boxes as desired colors. Then the mean color in each
+ * remaining box becomes one of the possible output colors.
+ *
+ * The second pass over the image maps each input pixel to the closest output
+ * color (optionally after applying a Floyd-Steinberg dithering correction).
+ * This mapping is logically trivial, but making it go fast enough requires
+ * considerable care.
+ *
+ * Heckbert-style quantizers vary a good deal in their policies for choosing
+ * the "largest" box and deciding where to cut it. The particular policies
+ * used here have proved out well in experimental comparisons, but better ones
+ * may yet be found.
+ *
+ * In earlier versions of the IJG code, this module quantized in YCbCr color
+ * space, processing the raw upsampled data without a color conversion step.
+ * This allowed the color conversion math to be done only once per colormap
+ * entry, not once per pixel. However, that optimization precluded other
+ * useful optimizations (such as merging color conversion with upsampling)
+ * and it also interfered with desired capabilities such as quantizing to an
+ * externally-supplied colormap. We have therefore abandoned that approach.
+ * The present code works in the post-conversion color space, typically RGB.
+ *
+ * To improve the visual quality of the results, we actually work in scaled
+ * RGB space, giving G distances more weight than R, and R in turn more than
+ * B. To do everything in integer math, we must use integer scale factors.
+ * The 2/3/1 scale factors used here correspond loosely to the relative
+ * weights of the colors in the NTSC grayscale equation.
+ * If you want to use this code to quantize a non-RGB color space, you'll
+ * probably need to change these scale factors.
+ */
+
+#define R_SCALE 2 /* scale R distances by this much */
+#define G_SCALE 3 /* scale G distances by this much */
+#define B_SCALE 1 /* and B by this much */
+
+/* Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined
+ * in jmorecfg.h. As the code stands, it will do the right thing for R,G,B
+ * and B,G,R orders. If you define some other weird order in jmorecfg.h,
+ * you'll get compile errors until you extend this logic. In that case
+ * you'll probably want to tweak the histogram sizes too.
+ */
+
+#if RGB_RED == 0
+#define C0_SCALE R_SCALE
+#endif
+#if RGB_BLUE == 0
+#define C0_SCALE B_SCALE
+#endif
+#if RGB_GREEN == 1
+#define C1_SCALE G_SCALE
+#endif
+#if RGB_RED == 2
+#define C2_SCALE R_SCALE
+#endif
+#if RGB_BLUE == 2
+#define C2_SCALE B_SCALE
+#endif
+
+
+/*
+ * First we have the histogram data structure and routines for creating it.
+ *
+ * The number of bits of precision can be adjusted by changing these symbols.
+ * We recommend keeping 6 bits for G and 5 each for R and B.
+ * If you have plenty of memory and cycles, 6 bits all around gives marginally
+ * better results; if you are short of memory, 5 bits all around will save
+ * some space but degrade the results.
+ * To maintain a fully accurate histogram, we'd need to allocate a "long"
+ * (preferably unsigned long) for each cell. In practice this is overkill;
+ * we can get by with 16 bits per cell. Few of the cell counts will overflow,
+ * and clamping those that do overflow to the maximum value will give close-
+ * enough results. This reduces the recommended histogram size from 256Kb
+ * to 128Kb, which is a useful savings on PC-class machines.
+ * (In the second pass the histogram space is re-used for pixel mapping data;
+ * in that capacity, each cell must be able to store zero to the number of
+ * desired colors. 16 bits/cell is plenty for that too.)
+ * Since the JPEG code is intended to run in small memory model on 80x86
+ * machines, we can't just allocate the histogram in one chunk. Instead
+ * of a true 3-D array, we use a row of pointers to 2-D arrays. Each
+ * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and
+ * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that
+ * on 80x86 machines, the pointer row is in near memory but the actual
+ * arrays are in far memory (same arrangement as we use for image arrays).
+ */
+
+#define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
+
+/* These will do the right thing for either R,G,B or B,G,R color order,
+ * but you may not like the results for other color orders.
+ */
+#define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
+#define HIST_C1_BITS 6 /* bits of precision in G histogram */
+#define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
+
+/* Number of elements along histogram axes. */
+#define HIST_C0_ELEMS (1<<HIST_C0_BITS)
+#define HIST_C1_ELEMS (1<<HIST_C1_BITS)
+#define HIST_C2_ELEMS (1<<HIST_C2_BITS)
+
+/* These are the amounts to shift an input value to get a histogram index. */
+#define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
+#define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
+#define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
+
+
+typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
+
+typedef histcell FAR * histptr; /* for pointers to histogram cells */
+
+typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
+typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
+typedef hist2d * hist3d; /* type for top-level pointer */
+
+
+/* Declarations for Floyd-Steinberg dithering.
+ *
+ * Errors are accumulated into the array fserrors[], at a resolution of
+ * 1/16th of a pixel count. The error at a given pixel is propagated
+ * to its not-yet-processed neighbors using the standard F-S fractions,
+ * ... (here) 7/16
+ * 3/16 5/16 1/16
+ * We work left-to-right on even rows, right-to-left on odd rows.
+ *
+ * We can get away with a single array (holding one row's worth of errors)
+ * by using it to store the current row's errors at pixel columns not yet
+ * processed, but the next row's errors at columns already processed. We
+ * need only a few extra variables to hold the errors immediately around the
+ * current column. (If we are lucky, those variables are in registers, but
+ * even if not, they're probably cheaper to access than array elements are.)
+ *
+ * The fserrors[] array has (#columns + 2) entries; the extra entry at
+ * each end saves us from special-casing the first and last pixels.
+ * Each entry is three values long, one value for each color component.
+ *
+ * Note: on a wide image, we might not have enough room in a PC's near data
+ * segment to hold the error array; so it is allocated with alloc_large.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+typedef INT16 FSERROR; /* 16 bits should be enough */
+typedef int LOCFSERROR; /* use 'int' for calculation temps */
+#else
+typedef INT32 FSERROR; /* may need more than 16 bits */
+typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
+#endif
+
+typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
+
+
+/* Private subobject */
+
+typedef struct {
+ struct jpeg_color_quantizer pub; /* public fields */
+
+ /* Space for the eventually created colormap is stashed here */
+ JSAMPARRAY sv_colormap; /* colormap allocated at init time */
+ int desired; /* desired # of colors = size of colormap */
+
+ /* Variables for accumulating image statistics */
+ hist3d histogram; /* pointer to the histogram */
+
+ boolean needs_zeroed; /* TRUE if next pass must zero histogram */
+
+ /* Variables for Floyd-Steinberg dithering */
+ FSERRPTR fserrors; /* accumulated errors */
+ boolean on_odd_row; /* flag to remember which row we are on */
+ int * error_limiter; /* table for clamping the applied error */
+} my_cquantizer;
+
+typedef my_cquantizer * my_cquantize_ptr;
+
+
+/*
+ * Prescan some rows of pixels.
+ * In this module the prescan simply updates the histogram, which has been
+ * initialized to zeroes by start_pass.
+ * An output_buf parameter is required by the method signature, but no data
+ * is actually output (in fact the buffer controller is probably passing a
+ * NULL pointer).
+ */
+
+METHODDEF(void)
+prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
+ JSAMPARRAY output_buf, int num_rows)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ register JSAMPROW ptr;
+ register histptr histp;
+ register hist3d histogram = cquantize->histogram;
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr = input_buf[row];
+ for (col = width; col > 0; col--) {
+ /* get pixel value and index into the histogram */
+ histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
+ [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
+ [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
+ /* increment, check for overflow and undo increment if so. */
+ if (++(*histp) <= 0)
+ (*histp)--;
+ ptr += 3;
+ }
+ }
+}
+
+
+/*
+ * Next we have the really interesting routines: selection of a colormap
+ * given the completed histogram.
+ * These routines work with a list of "boxes", each representing a rectangular
+ * subset of the input color space (to histogram precision).
+ */
+
+typedef struct {
+ /* The bounds of the box (inclusive); expressed as histogram indexes */
+ int c0min, c0max;
+ int c1min, c1max;
+ int c2min, c2max;
+ /* The volume (actually 2-norm) of the box */
+ INT32 volume;
+ /* The number of nonzero histogram cells within this box */
+ long colorcount;
+} box;
+
+typedef box * boxptr;
+
+
+LOCAL(boxptr)
+find_biggest_color_pop (boxptr boxlist, int numboxes)
+/* Find the splittable box with the largest color population */
+/* Returns NULL if no splittable boxes remain */
+{
+ register boxptr boxp;
+ register int i;
+ register long maxc = 0;
+ boxptr which = NULL;
+
+ for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
+ if (boxp->colorcount > maxc && boxp->volume > 0) {
+ which = boxp;
+ maxc = boxp->colorcount;
+ }
+ }
+ return which;
+}
+
+
+LOCAL(boxptr)
+find_biggest_volume (boxptr boxlist, int numboxes)
+/* Find the splittable box with the largest (scaled) volume */
+/* Returns NULL if no splittable boxes remain */
+{
+ register boxptr boxp;
+ register int i;
+ register INT32 maxv = 0;
+ boxptr which = NULL;
+
+ for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
+ if (boxp->volume > maxv) {
+ which = boxp;
+ maxv = boxp->volume;
+ }
+ }
+ return which;
+}
+
+
+LOCAL(void)
+update_box (j_decompress_ptr cinfo, boxptr boxp)
+/* Shrink the min/max bounds of a box to enclose only nonzero elements, */
+/* and recompute its volume and population */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ histptr histp;
+ int c0,c1,c2;
+ int c0min,c0max,c1min,c1max,c2min,c2max;
+ INT32 dist0,dist1,dist2;
+ long ccount;
+
+ c0min = boxp->c0min; c0max = boxp->c0max;
+ c1min = boxp->c1min; c1max = boxp->c1max;
+ c2min = boxp->c2min; c2max = boxp->c2max;
+
+ if (c0max > c0min)
+ for (c0 = c0min; c0 <= c0max; c0++)
+ for (c1 = c1min; c1 <= c1max; c1++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++)
+ if (*histp++ != 0) {
+ boxp->c0min = c0min = c0;
+ goto have_c0min;
+ }
+ }
+ have_c0min:
+ if (c0max > c0min)
+ for (c0 = c0max; c0 >= c0min; c0--)
+ for (c1 = c1min; c1 <= c1max; c1++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++)
+ if (*histp++ != 0) {
+ boxp->c0max = c0max = c0;
+ goto have_c0max;
+ }
+ }
+ have_c0max:
+ if (c1max > c1min)
+ for (c1 = c1min; c1 <= c1max; c1++)
+ for (c0 = c0min; c0 <= c0max; c0++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++)
+ if (*histp++ != 0) {
+ boxp->c1min = c1min = c1;
+ goto have_c1min;
+ }
+ }
+ have_c1min:
+ if (c1max > c1min)
+ for (c1 = c1max; c1 >= c1min; c1--)
+ for (c0 = c0min; c0 <= c0max; c0++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++)
+ if (*histp++ != 0) {
+ boxp->c1max = c1max = c1;
+ goto have_c1max;
+ }
+ }
+ have_c1max:
+ if (c2max > c2min)
+ for (c2 = c2min; c2 <= c2max; c2++)
+ for (c0 = c0min; c0 <= c0max; c0++) {
+ histp = & histogram[c0][c1min][c2];
+ for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
+ if (*histp != 0) {
+ boxp->c2min = c2min = c2;
+ goto have_c2min;
+ }
+ }
+ have_c2min:
+ if (c2max > c2min)
+ for (c2 = c2max; c2 >= c2min; c2--)
+ for (c0 = c0min; c0 <= c0max; c0++) {
+ histp = & histogram[c0][c1min][c2];
+ for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
+ if (*histp != 0) {
+ boxp->c2max = c2max = c2;
+ goto have_c2max;
+ }
+ }
+ have_c2max:
+
+ /* Update box volume.
+ * We use 2-norm rather than real volume here; this biases the method
+ * against making long narrow boxes, and it has the side benefit that
+ * a box is splittable iff norm > 0.
+ * Since the differences are expressed in histogram-cell units,
+ * we have to shift back to JSAMPLE units to get consistent distances;
+ * after which, we scale according to the selected distance scale factors.
+ */
+ dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
+ dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
+ dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
+ boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
+
+ /* Now scan remaining volume of box and compute population */
+ ccount = 0;
+ for (c0 = c0min; c0 <= c0max; c0++)
+ for (c1 = c1min; c1 <= c1max; c1++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++, histp++)
+ if (*histp != 0) {
+ ccount++;
+ }
+ }
+ boxp->colorcount = ccount;
+}
+
+
+LOCAL(int)
+median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
+ int desired_colors)
+/* Repeatedly select and split the largest box until we have enough boxes */
+{
+ int n,lb;
+ int c0,c1,c2,cmax;
+ register boxptr b1,b2;
+
+ while (numboxes < desired_colors) {
+ /* Select box to split.
+ * Current algorithm: by population for first half, then by volume.
+ */
+ if (numboxes*2 <= desired_colors) {
+ b1 = find_biggest_color_pop(boxlist, numboxes);
+ } else {
+ b1 = find_biggest_volume(boxlist, numboxes);
+ }
+ if (b1 == NULL) /* no splittable boxes left! */
+ break;
+ b2 = &boxlist[numboxes]; /* where new box will go */
+ /* Copy the color bounds to the new box. */
+ b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
+ b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
+ /* Choose which axis to split the box on.
+ * Current algorithm: longest scaled axis.
+ * See notes in update_box about scaling distances.
+ */
+ c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
+ c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
+ c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
+ /* We want to break any ties in favor of green, then red, blue last.
+ * This code does the right thing for R,G,B or B,G,R color orders only.
+ */
+#if RGB_RED == 0
+ cmax = c1; n = 1;
+ if (c0 > cmax) { cmax = c0; n = 0; }
+ if (c2 > cmax) { n = 2; }
+#else
+ cmax = c1; n = 1;
+ if (c2 > cmax) { cmax = c2; n = 2; }
+ if (c0 > cmax) { n = 0; }
+#endif
+ /* Choose split point along selected axis, and update box bounds.
+ * Current algorithm: split at halfway point.
+ * (Since the box has been shrunk to minimum volume,
+ * any split will produce two nonempty subboxes.)
+ * Note that lb value is max for lower box, so must be < old max.
+ */
+ switch (n) {
+ case 0:
+ lb = (b1->c0max + b1->c0min) / 2;
+ b1->c0max = lb;
+ b2->c0min = lb+1;
+ break;
+ case 1:
+ lb = (b1->c1max + b1->c1min) / 2;
+ b1->c1max = lb;
+ b2->c1min = lb+1;
+ break;
+ case 2:
+ lb = (b1->c2max + b1->c2min) / 2;
+ b1->c2max = lb;
+ b2->c2min = lb+1;
+ break;
+ }
+ /* Update stats for boxes */
+ update_box(cinfo, b1);
+ update_box(cinfo, b2);
+ numboxes++;
+ }
+ return numboxes;
+}
+
+
+LOCAL(void)
+compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
+/* Compute representative color for a box, put it in colormap[icolor] */
+{
+ /* Current algorithm: mean weighted by pixels (not colors) */
+ /* Note it is important to get the rounding correct! */
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ histptr histp;
+ int c0,c1,c2;
+ int c0min,c0max,c1min,c1max,c2min,c2max;
+ long count;
+ long total = 0;
+ long c0total = 0;
+ long c1total = 0;
+ long c2total = 0;
+
+ c0min = boxp->c0min; c0max = boxp->c0max;
+ c1min = boxp->c1min; c1max = boxp->c1max;
+ c2min = boxp->c2min; c2max = boxp->c2max;
+
+ for (c0 = c0min; c0 <= c0max; c0++)
+ for (c1 = c1min; c1 <= c1max; c1++) {
+ histp = & histogram[c0][c1][c2min];
+ for (c2 = c2min; c2 <= c2max; c2++) {
+ if ((count = *histp++) != 0) {
+ total += count;
+ c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
+ c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
+ c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
+ }
+ }
+ }
+
+ cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
+ cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
+ cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
+}
+
+
+LOCAL(void)
+select_colors (j_decompress_ptr cinfo, int desired_colors)
+/* Master routine for color selection */
+{
+ boxptr boxlist;
+ int numboxes;
+ int i;
+
+ /* Allocate workspace for box list */
+ boxlist = (boxptr) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
+ /* Initialize one box containing whole space */
+ numboxes = 1;
+ boxlist[0].c0min = 0;
+ boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
+ boxlist[0].c1min = 0;
+ boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
+ boxlist[0].c2min = 0;
+ boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
+ /* Shrink it to actually-used volume and set its statistics */
+ update_box(cinfo, & boxlist[0]);
+ /* Perform median-cut to produce final box list */
+ numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
+ /* Compute the representative color for each box, fill colormap */
+ for (i = 0; i < numboxes; i++)
+ compute_color(cinfo, & boxlist[i], i);
+ cinfo->actual_number_of_colors = numboxes;
+ TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
+}
+
+
+/*
+ * These routines are concerned with the time-critical task of mapping input
+ * colors to the nearest color in the selected colormap.
+ *
+ * We re-use the histogram space as an "inverse color map", essentially a
+ * cache for the results of nearest-color searches. All colors within a
+ * histogram cell will be mapped to the same colormap entry, namely the one
+ * closest to the cell's center. This may not be quite the closest entry to
+ * the actual input color, but it's almost as good. A zero in the cache
+ * indicates we haven't found the nearest color for that cell yet; the array
+ * is cleared to zeroes before starting the mapping pass. When we find the
+ * nearest color for a cell, its colormap index plus one is recorded in the
+ * cache for future use. The pass2 scanning routines call fill_inverse_cmap
+ * when they need to use an unfilled entry in the cache.
+ *
+ * Our method of efficiently finding nearest colors is based on the "locally
+ * sorted search" idea described by Heckbert and on the incremental distance
+ * calculation described by Spencer W. Thomas in chapter III.1 of Graphics
+ * Gems II (James Arvo, ed. Academic Press, 1991). Thomas points out that
+ * the distances from a given colormap entry to each cell of the histogram can
+ * be computed quickly using an incremental method: the differences between
+ * distances to adjacent cells themselves differ by a constant. This allows a
+ * fairly fast implementation of the "brute force" approach of computing the
+ * distance from every colormap entry to every histogram cell. Unfortunately,
+ * it needs a work array to hold the best-distance-so-far for each histogram
+ * cell (because the inner loop has to be over cells, not colormap entries).
+ * The work array elements have to be INT32s, so the work array would need
+ * 256Kb at our recommended precision. This is not feasible in DOS machines.
+ *
+ * To get around these problems, we apply Thomas' method to compute the
+ * nearest colors for only the cells within a small subbox of the histogram.
+ * The work array need be only as big as the subbox, so the memory usage
+ * problem is solved. Furthermore, we need not fill subboxes that are never
+ * referenced in pass2; many images use only part of the color gamut, so a
+ * fair amount of work is saved. An additional advantage of this
+ * approach is that we can apply Heckbert's locality criterion to quickly
+ * eliminate colormap entries that are far away from the subbox; typically
+ * three-fourths of the colormap entries are rejected by Heckbert's criterion,
+ * and we need not compute their distances to individual cells in the subbox.
+ * The speed of this approach is heavily influenced by the subbox size: too
+ * small means too much overhead, too big loses because Heckbert's criterion
+ * can't eliminate as many colormap entries. Empirically the best subbox
+ * size seems to be about 1/512th of the histogram (1/8th in each direction).
+ *
+ * Thomas' article also describes a refined method which is asymptotically
+ * faster than the brute-force method, but it is also far more complex and
+ * cannot efficiently be applied to small subboxes. It is therefore not
+ * useful for programs intended to be portable to DOS machines. On machines
+ * with plenty of memory, filling the whole histogram in one shot with Thomas'
+ * refined method might be faster than the present code --- but then again,
+ * it might not be any faster, and it's certainly more complicated.
+ */
+
+
+/* log2(histogram cells in update box) for each axis; this can be adjusted */
+#define BOX_C0_LOG (HIST_C0_BITS-3)
+#define BOX_C1_LOG (HIST_C1_BITS-3)
+#define BOX_C2_LOG (HIST_C2_BITS-3)
+
+#define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
+#define BOX_C1_ELEMS (1<<BOX_C1_LOG)
+#define BOX_C2_ELEMS (1<<BOX_C2_LOG)
+
+#define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
+#define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
+#define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
+
+
+/*
+ * The next three routines implement inverse colormap filling. They could
+ * all be folded into one big routine, but splitting them up this way saves
+ * some stack space (the mindist[] and bestdist[] arrays need not coexist)
+ * and may allow some compilers to produce better code by registerizing more
+ * inner-loop variables.
+ */
+
+LOCAL(int)
+find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
+ JSAMPLE colorlist[])
+/* Locate the colormap entries close enough to an update box to be candidates
+ * for the nearest entry to some cell(s) in the update box. The update box
+ * is specified by the center coordinates of its first cell. The number of
+ * candidate colormap entries is returned, and their colormap indexes are
+ * placed in colorlist[].
+ * This routine uses Heckbert's "locally sorted search" criterion to select
+ * the colors that need further consideration.
+ */
+{
+ int numcolors = cinfo->actual_number_of_colors;
+ int maxc0, maxc1, maxc2;
+ int centerc0, centerc1, centerc2;
+ int i, x, ncolors;
+ INT32 minmaxdist, min_dist, max_dist, tdist;
+ INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
+
+ /* Compute true coordinates of update box's upper corner and center.
+ * Actually we compute the coordinates of the center of the upper-corner
+ * histogram cell, which are the upper bounds of the volume we care about.
+ * Note that since ">>" rounds down, the "center" values may be closer to
+ * min than to max; hence comparisons to them must be "<=", not "<".
+ */
+ maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
+ centerc0 = (minc0 + maxc0) >> 1;
+ maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
+ centerc1 = (minc1 + maxc1) >> 1;
+ maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
+ centerc2 = (minc2 + maxc2) >> 1;
+
+ /* For each color in colormap, find:
+ * 1. its minimum squared-distance to any point in the update box
+ * (zero if color is within update box);
+ * 2. its maximum squared-distance to any point in the update box.
+ * Both of these can be found by considering only the corners of the box.
+ * We save the minimum distance for each color in mindist[];
+ * only the smallest maximum distance is of interest.
+ */
+ minmaxdist = 0x7FFFFFFFL;
+
+ for (i = 0; i < numcolors; i++) {
+ /* We compute the squared-c0-distance term, then add in the other two. */
+ x = GETJSAMPLE(cinfo->colormap[0][i]);
+ if (x < minc0) {
+ tdist = (x - minc0) * C0_SCALE;
+ min_dist = tdist*tdist;
+ tdist = (x - maxc0) * C0_SCALE;
+ max_dist = tdist*tdist;
+ } else if (x > maxc0) {
+ tdist = (x - maxc0) * C0_SCALE;
+ min_dist = tdist*tdist;
+ tdist = (x - minc0) * C0_SCALE;
+ max_dist = tdist*tdist;
+ } else {
+ /* within cell range so no contribution to min_dist */
+ min_dist = 0;
+ if (x <= centerc0) {
+ tdist = (x - maxc0) * C0_SCALE;
+ max_dist = tdist*tdist;
+ } else {
+ tdist = (x - minc0) * C0_SCALE;
+ max_dist = tdist*tdist;
+ }
+ }
+
+ x = GETJSAMPLE(cinfo->colormap[1][i]);
+ if (x < minc1) {
+ tdist = (x - minc1) * C1_SCALE;
+ min_dist += tdist*tdist;
+ tdist = (x - maxc1) * C1_SCALE;
+ max_dist += tdist*tdist;
+ } else if (x > maxc1) {
+ tdist = (x - maxc1) * C1_SCALE;
+ min_dist += tdist*tdist;
+ tdist = (x - minc1) * C1_SCALE;
+ max_dist += tdist*tdist;
+ } else {
+ /* within cell range so no contribution to min_dist */
+ if (x <= centerc1) {
+ tdist = (x - maxc1) * C1_SCALE;
+ max_dist += tdist*tdist;
+ } else {
+ tdist = (x - minc1) * C1_SCALE;
+ max_dist += tdist*tdist;
+ }
+ }
+
+ x = GETJSAMPLE(cinfo->colormap[2][i]);
+ if (x < minc2) {
+ tdist = (x - minc2) * C2_SCALE;
+ min_dist += tdist*tdist;
+ tdist = (x - maxc2) * C2_SCALE;
+ max_dist += tdist*tdist;
+ } else if (x > maxc2) {
+ tdist = (x - maxc2) * C2_SCALE;
+ min_dist += tdist*tdist;
+ tdist = (x - minc2) * C2_SCALE;
+ max_dist += tdist*tdist;
+ } else {
+ /* within cell range so no contribution to min_dist */
+ if (x <= centerc2) {
+ tdist = (x - maxc2) * C2_SCALE;
+ max_dist += tdist*tdist;
+ } else {
+ tdist = (x - minc2) * C2_SCALE;
+ max_dist += tdist*tdist;
+ }
+ }
+
+ mindist[i] = min_dist; /* save away the results */
+ if (max_dist < minmaxdist)
+ minmaxdist = max_dist;
+ }
+
+ /* Now we know that no cell in the update box is more than minmaxdist
+ * away from some colormap entry. Therefore, only colors that are
+ * within minmaxdist of some part of the box need be considered.
+ */
+ ncolors = 0;
+ for (i = 0; i < numcolors; i++) {
+ if (mindist[i] <= minmaxdist)
+ colorlist[ncolors++] = (JSAMPLE) i;
+ }
+ return ncolors;
+}
+
+
+LOCAL(void)
+find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
+ int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
+/* Find the closest colormap entry for each cell in the update box,
+ * given the list of candidate colors prepared by find_nearby_colors.
+ * Return the indexes of the closest entries in the bestcolor[] array.
+ * This routine uses Thomas' incremental distance calculation method to
+ * find the distance from a colormap entry to successive cells in the box.
+ */
+{
+ int ic0, ic1, ic2;
+ int i, icolor;
+ register INT32 * bptr; /* pointer into bestdist[] array */
+ JSAMPLE * cptr; /* pointer into bestcolor[] array */
+ INT32 dist0, dist1; /* initial distance values */
+ register INT32 dist2; /* current distance in inner loop */
+ INT32 xx0, xx1; /* distance increments */
+ register INT32 xx2;
+ INT32 inc0, inc1, inc2; /* initial values for increments */
+ /* This array holds the distance to the nearest-so-far color for each cell */
+ INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
+
+ /* Initialize best-distance for each cell of the update box */
+ bptr = bestdist;
+ for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
+ *bptr++ = 0x7FFFFFFFL;
+
+ /* For each color selected by find_nearby_colors,
+ * compute its distance to the center of each cell in the box.
+ * If that's less than best-so-far, update best distance and color number.
+ */
+
+ /* Nominal steps between cell centers ("x" in Thomas article) */
+#define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
+#define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
+#define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
+
+ for (i = 0; i < numcolors; i++) {
+ icolor = GETJSAMPLE(colorlist[i]);
+ /* Compute (square of) distance from minc0/c1/c2 to this color */
+ inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
+ dist0 = inc0*inc0;
+ inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
+ dist0 += inc1*inc1;
+ inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
+ dist0 += inc2*inc2;
+ /* Form the initial difference increments */
+ inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
+ inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
+ inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
+ /* Now loop over all cells in box, updating distance per Thomas method */
+ bptr = bestdist;
+ cptr = bestcolor;
+ xx0 = inc0;
+ for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
+ dist1 = dist0;
+ xx1 = inc1;
+ for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
+ dist2 = dist1;
+ xx2 = inc2;
+ for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
+ if (dist2 < *bptr) {
+ *bptr = dist2;
+ *cptr = (JSAMPLE) icolor;
+ }
+ dist2 += xx2;
+ xx2 += 2 * STEP_C2 * STEP_C2;
+ bptr++;
+ cptr++;
+ }
+ dist1 += xx1;
+ xx1 += 2 * STEP_C1 * STEP_C1;
+ }
+ dist0 += xx0;
+ xx0 += 2 * STEP_C0 * STEP_C0;
+ }
+ }
+}
+
+
+LOCAL(void)
+fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
+/* Fill the inverse-colormap entries in the update box that contains */
+/* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */
+/* we can fill as many others as we wish.) */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ int minc0, minc1, minc2; /* lower left corner of update box */
+ int ic0, ic1, ic2;
+ register JSAMPLE * cptr; /* pointer into bestcolor[] array */
+ register histptr cachep; /* pointer into main cache array */
+ /* This array lists the candidate colormap indexes. */
+ JSAMPLE colorlist[MAXNUMCOLORS];
+ int numcolors; /* number of candidate colors */
+ /* This array holds the actually closest colormap index for each cell. */
+ JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
+
+ /* Convert cell coordinates to update box ID */
+ c0 >>= BOX_C0_LOG;
+ c1 >>= BOX_C1_LOG;
+ c2 >>= BOX_C2_LOG;
+
+ /* Compute true coordinates of update box's origin corner.
+ * Actually we compute the coordinates of the center of the corner
+ * histogram cell, which are the lower bounds of the volume we care about.
+ */
+ minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
+ minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
+ minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
+
+ /* Determine which colormap entries are close enough to be candidates
+ * for the nearest entry to some cell in the update box.
+ */
+ numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
+
+ /* Determine the actually nearest colors. */
+ find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
+ bestcolor);
+
+ /* Save the best color numbers (plus 1) in the main cache array */
+ c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
+ c1 <<= BOX_C1_LOG;
+ c2 <<= BOX_C2_LOG;
+ cptr = bestcolor;
+ for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
+ for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
+ cachep = & histogram[c0+ic0][c1+ic1][c2];
+ for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
+ *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
+ }
+ }
+ }
+}
+
+
+/*
+ * Map some rows of pixels to the output colormapped representation.
+ */
+
+METHODDEF(void)
+pass2_no_dither (j_decompress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
+/* This version performs no dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ register JSAMPROW inptr, outptr;
+ register histptr cachep;
+ register int c0, c1, c2;
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+
+ for (row = 0; row < num_rows; row++) {
+ inptr = input_buf[row];
+ outptr = output_buf[row];
+ for (col = width; col > 0; col--) {
+ /* get pixel value and index into the cache */
+ c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
+ c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
+ c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
+ cachep = & histogram[c0][c1][c2];
+ /* If we have not seen this color before, find nearest colormap entry */
+ /* and update the cache */
+ if (*cachep == 0)
+ fill_inverse_cmap(cinfo, c0,c1,c2);
+ /* Now emit the colormap index for this cell */
+ *outptr++ = (JSAMPLE) (*cachep - 1);
+ }
+ }
+}
+
+
+METHODDEF(void)
+pass2_fs_dither (j_decompress_ptr cinfo,
+ JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
+/* This version performs Floyd-Steinberg dithering */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
+ LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
+ LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
+ register FSERRPTR errorptr; /* => fserrors[] at column before current */
+ JSAMPROW inptr; /* => current input pixel */
+ JSAMPROW outptr; /* => current output pixel */
+ histptr cachep;
+ int dir; /* +1 or -1 depending on direction */
+ int dir3; /* 3*dir, for advancing inptr & errorptr */
+ int row;
+ JDIMENSION col;
+ JDIMENSION width = cinfo->output_width;
+ JSAMPLE *range_limit = cinfo->sample_range_limit;
+ int *error_limit = cquantize->error_limiter;
+ JSAMPROW colormap0 = cinfo->colormap[0];
+ JSAMPROW colormap1 = cinfo->colormap[1];
+ JSAMPROW colormap2 = cinfo->colormap[2];
+ SHIFT_TEMPS
+
+ for (row = 0; row < num_rows; row++) {
+ inptr = input_buf[row];
+ outptr = output_buf[row];
+ if (cquantize->on_odd_row) {
+ /* work right to left in this row */
+ inptr += (width-1) * 3; /* so point to rightmost pixel */
+ outptr += width-1;
+ dir = -1;
+ dir3 = -3;
+ errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
+ cquantize->on_odd_row = FALSE; /* flip for next time */
+ } else {
+ /* work left to right in this row */
+ dir = 1;
+ dir3 = 3;
+ errorptr = cquantize->fserrors; /* => entry before first real column */
+ cquantize->on_odd_row = TRUE; /* flip for next time */
+ }
+ /* Preset error values: no error propagated to first pixel from left */
+ cur0 = cur1 = cur2 = 0;
+ /* and no error propagated to row below yet */
+ belowerr0 = belowerr1 = belowerr2 = 0;
+ bpreverr0 = bpreverr1 = bpreverr2 = 0;
+
+ for (col = width; col > 0; col--) {
+ /* curN 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.
+ */
+ cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
+ cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
+ cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
+ /* Limit the error using transfer function set by init_error_limit.
+ * See comments with init_error_limit for rationale.
+ */
+ cur0 = error_limit[cur0];
+ cur1 = error_limit[cur1];
+ cur2 = error_limit[cur2];
+ /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
+ * The maximum error is +- MAXJSAMPLE (or less with error limiting);
+ * this sets the required size of the range_limit array.
+ */
+ cur0 += GETJSAMPLE(inptr[0]);
+ cur1 += GETJSAMPLE(inptr[1]);
+ cur2 += GETJSAMPLE(inptr[2]);
+ cur0 = GETJSAMPLE(range_limit[cur0]);
+ cur1 = GETJSAMPLE(range_limit[cur1]);
+ cur2 = GETJSAMPLE(range_limit[cur2]);
+ /* Index into the cache with adjusted pixel value */
+ cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
+ /* If we have not seen this color before, find nearest colormap */
+ /* entry and update the cache */
+ if (*cachep == 0)
+ fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
+ /* Now emit the colormap index for this cell */
+ { register int pixcode = *cachep - 1;
+ *outptr = (JSAMPLE) pixcode;
+ /* Compute representation error for this pixel */
+ cur0 -= GETJSAMPLE(colormap0[pixcode]);
+ cur1 -= GETJSAMPLE(colormap1[pixcode]);
+ cur2 -= GETJSAMPLE(colormap2[pixcode]);
+ }
+ /* 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.
+ */
+ { register LOCFSERROR bnexterr, delta;
+
+ bnexterr = cur0; /* Process component 0 */
+ delta = cur0 * 2;
+ cur0 += delta; /* form error * 3 */
+ errorptr[0] = (FSERROR) (bpreverr0 + cur0);
+ cur0 += delta; /* form error * 5 */
+ bpreverr0 = belowerr0 + cur0;
+ belowerr0 = bnexterr;
+ cur0 += delta; /* form error * 7 */
+ bnexterr = cur1; /* Process component 1 */
+ delta = cur1 * 2;
+ cur1 += delta; /* form error * 3 */
+ errorptr[1] = (FSERROR) (bpreverr1 + cur1);
+ cur1 += delta; /* form error * 5 */
+ bpreverr1 = belowerr1 + cur1;
+ belowerr1 = bnexterr;
+ cur1 += delta; /* form error * 7 */
+ bnexterr = cur2; /* Process component 2 */
+ delta = cur2 * 2;
+ cur2 += delta; /* form error * 3 */
+ errorptr[2] = (FSERROR) (bpreverr2 + cur2);
+ cur2 += delta; /* form error * 5 */
+ bpreverr2 = belowerr2 + cur2;
+ belowerr2 = bnexterr;
+ cur2 += delta; /* form error * 7 */
+ }
+ /* At this point curN 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.
+ */
+ inptr += dir3; /* Advance pixel pointers to next column */
+ outptr += dir;
+ errorptr += dir3; /* advance errorptr to current column */
+ }
+ /* Post-loop cleanup: we must unload the final error values into the
+ * final fserrors[] entry. Note we need not unload belowerrN because
+ * it is for the dummy column before or after the actual array.
+ */
+ errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
+ errorptr[1] = (FSERROR) bpreverr1;
+ errorptr[2] = (FSERROR) bpreverr2;
+ }
+}
+
+
+/*
+ * Initialize the error-limiting transfer function (lookup table).
+ * The raw F-S error computation can potentially compute error values of up to
+ * +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
+ * much less, otherwise obviously wrong pixels will be created. (Typical
+ * effects include weird fringes at color-area boundaries, isolated bright
+ * pixels in a dark area, etc.) The standard advice for avoiding this problem
+ * is to ensure that the "corners" of the color cube are allocated as output
+ * colors; then repeated errors in the same direction cannot cause cascading
+ * error buildup. However, that only prevents the error from getting
+ * completely out of hand; Aaron Giles reports that error limiting improves
+ * the results even with corner colors allocated.
+ * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
+ * well, but the smoother transfer function used below is even better. Thanks
+ * to Aaron Giles for this idea.
+ */
+
+LOCAL(void)
+init_error_limit (j_decompress_ptr cinfo)
+/* Allocate and fill in the error_limiter table */
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ int * table;
+ int in, out;
+
+ table = (int *) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
+ table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
+ cquantize->error_limiter = table;
+
+#define STEPSIZE ((MAXJSAMPLE+1)/16)
+ /* Map errors 1:1 up to +- MAXJSAMPLE/16 */
+ out = 0;
+ for (in = 0; in < STEPSIZE; in++, out++) {
+ table[in] = out; table[-in] = -out;
+ }
+ /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
+ for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
+ table[in] = out; table[-in] = -out;
+ }
+ /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
+ for (; in <= MAXJSAMPLE; in++) {
+ table[in] = out; table[-in] = -out;
+ }
+#undef STEPSIZE
+}
+
+
+/*
+ * Finish up at the end of each pass.
+ */
+
+METHODDEF(void)
+finish_pass1 (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+
+ /* Select the representative colors and fill in cinfo->colormap */
+ cinfo->colormap = cquantize->sv_colormap;
+ select_colors(cinfo, cquantize->desired);
+ /* Force next pass to zero the color index table */
+ cquantize->needs_zeroed = TRUE;
+}
+
+
+METHODDEF(void)
+finish_pass2 (j_decompress_ptr cinfo)
+{
+ /* no work */
+}
+
+
+/*
+ * Initialize for each processing pass.
+ */
+
+METHODDEF(void)
+start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+ hist3d histogram = cquantize->histogram;
+ int i;
+
+ /* Only F-S dithering or no dithering is supported. */
+ /* If user asks for ordered dither, give him F-S. */
+ if (cinfo->dither_mode != JDITHER_NONE)
+ cinfo->dither_mode = JDITHER_FS;
+
+ if (is_pre_scan) {
+ /* Set up method pointers */
+ cquantize->pub.color_quantize = prescan_quantize;
+ cquantize->pub.finish_pass = finish_pass1;
+ cquantize->needs_zeroed = TRUE; /* Always zero histogram */
+ } else {
+ /* Set up method pointers */
+ if (cinfo->dither_mode == JDITHER_FS)
+ cquantize->pub.color_quantize = pass2_fs_dither;
+ else
+ cquantize->pub.color_quantize = pass2_no_dither;
+ cquantize->pub.finish_pass = finish_pass2;
+
+ /* Make sure color count is acceptable */
+ i = cinfo->actual_number_of_colors;
+ if (i < 1)
+ ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
+ if (i > MAXNUMCOLORS)
+ ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
+
+ if (cinfo->dither_mode == JDITHER_FS) {
+ size_t arraysize = (size_t) ((cinfo->output_width + 2) *
+ (3 * SIZEOF(FSERROR)));
+ /* Allocate Floyd-Steinberg workspace if we didn't already. */
+ if (cquantize->fserrors == NULL)
+ cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
+ /* Initialize the propagated errors to zero. */
+ jzero_far((void FAR *) cquantize->fserrors, arraysize);
+ /* Make the error-limit table if we didn't already. */
+ if (cquantize->error_limiter == NULL)
+ init_error_limit(cinfo);
+ cquantize->on_odd_row = FALSE;
+ }
+
+ }
+ /* Zero the histogram or inverse color map, if necessary */
+ if (cquantize->needs_zeroed) {
+ for (i = 0; i < HIST_C0_ELEMS; i++) {
+ jzero_far((void FAR *) histogram[i],
+ HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
+ }
+ cquantize->needs_zeroed = FALSE;
+ }
+}
+
+
+/*
+ * Switch to a new external colormap between output passes.
+ */
+
+METHODDEF(void)
+new_color_map_2_quant (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
+
+ /* Reset the inverse color map */
+ cquantize->needs_zeroed = TRUE;
+}
+
+
+/*
+ * Module initialization routine for 2-pass color quantization.
+ */
+
+GLOBAL(void)
+jinit_2pass_quantizer (j_decompress_ptr cinfo)
+{
+ my_cquantize_ptr cquantize;
+ int i;
+
+ cquantize = (my_cquantize_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(my_cquantizer));
+ cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
+ cquantize->pub.start_pass = start_pass_2_quant;
+ cquantize->pub.new_color_map = new_color_map_2_quant;
+ cquantize->fserrors = NULL; /* flag optional arrays not allocated */
+ cquantize->error_limiter = NULL;
+
+ /* Make sure jdmaster didn't give me a case I can't handle */
+ if (cinfo->out_color_components != 3)
+ ERREXIT(cinfo, JERR_NOTIMPL);
+
+ /* Allocate the histogram/inverse colormap storage */
+ cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
+ for (i = 0; i < HIST_C0_ELEMS; i++) {
+ cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
+ }
+ cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
+
+ /* Allocate storage for the completed colormap, if required.
+ * We do this now since it is FAR storage and may affect
+ * the memory manager's space calculations.
+ */
+ if (cinfo->enable_2pass_quant) {
+ /* Make sure color count is acceptable */
+ int desired = cinfo->desired_number_of_colors;
+ /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
+ if (desired < 8)
+ ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
+ /* Make sure colormap indexes can be represented by JSAMPLEs */
+ if (desired > MAXNUMCOLORS)
+ ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
+ cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
+ cquantize->desired = desired;
+ } else
+ cquantize->sv_colormap = NULL;
+
+ /* Only F-S dithering or no dithering is supported. */
+ /* If user asks for ordered dither, give him F-S. */
+ if (cinfo->dither_mode != JDITHER_NONE)
+ cinfo->dither_mode = JDITHER_FS;
+
+ /* Allocate Floyd-Steinberg workspace if necessary.
+ * This isn't really needed until pass 2, but again it is FAR storage.
+ * Although we will cope with a later change in dither_mode,
+ * we do not promise to honor max_memory_to_use if dither_mode changes.
+ */
+ if (cinfo->dither_mode == JDITHER_FS) {
+ cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
+ /* Might as well create the error-limiting table too. */
+ init_error_limit(cinfo);
+ }
+}
+
+#endif /* QUANT_2PASS_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/jutils.c b/osframework/source/ImageLib/jpeg/jutils.c
new file mode 100644
index 0000000..286cda2
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jutils.c
@@ -0,0 +1,179 @@
+/*
+ * jutils.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains tables and miscellaneous utility routines needed
+ * for both compression and decompression.
+ * Note we prefix all global names with "j" to minimize conflicts with
+ * a surrounding application.
+ */
+
+#define JPEG_INTERNALS
+#include "jinclude.h"
+#include "jpeglib.h"
+
+
+/*
+ * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
+ * of a DCT block read in natural order (left to right, top to bottom).
+ */
+
+#if 0 /* This table is not actually needed in v6a */
+
+const int jpeg_zigzag_order[DCTSIZE2] = {
+ 0, 1, 5, 6, 14, 15, 27, 28,
+ 2, 4, 7, 13, 16, 26, 29, 42,
+ 3, 8, 12, 17, 25, 30, 41, 43,
+ 9, 11, 18, 24, 31, 40, 44, 53,
+ 10, 19, 23, 32, 39, 45, 52, 54,
+ 20, 22, 33, 38, 46, 51, 55, 60,
+ 21, 34, 37, 47, 50, 56, 59, 61,
+ 35, 36, 48, 49, 57, 58, 62, 63
+};
+
+#endif
+
+/*
+ * jpeg_natural_order[i] is the natural-order position of the i'th element
+ * of zigzag order.
+ *
+ * When reading corrupted data, the Huffman decoders could attempt
+ * to reference an entry beyond the end of this array (if the decoded
+ * zero run length reaches past the end of the block). To prevent
+ * wild stores without adding an inner-loop test, we put some extra
+ * "63"s after the real entries. This will cause the extra coefficient
+ * to be stored in location 63 of the block, not somewhere random.
+ * The worst case would be a run-length of 15, which means we need 16
+ * fake entries.
+ */
+
+const int jpeg_natural_order[DCTSIZE2+16] = {
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
+ 63, 63, 63, 63, 63, 63, 63, 63
+};
+
+
+/*
+ * Arithmetic utilities
+ */
+
+GLOBAL(long)
+jdiv_round_up (long a, long b)
+/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
+/* Assumes a >= 0, b > 0 */
+{
+ return (a + b - 1L) / b;
+}
+
+
+GLOBAL(long)
+jround_up (long a, long b)
+/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
+/* Assumes a >= 0, b > 0 */
+{
+ a += b - 1L;
+ return a - (a % b);
+}
+
+
+/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
+ * and coefficient-block arrays. This won't work on 80x86 because the arrays
+ * are FAR and we're assuming a small-pointer memory model. However, some
+ * DOS compilers provide far-pointer versions of memcpy() and memset() even
+ * in the small-model libraries. These will be used if USE_FMEM is defined.
+ * Otherwise, the routines below do it the hard way. (The performance cost
+ * is not all that great, because these routines aren't very heavily used.)
+ */
+
+#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
+#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
+#define FMEMZERO(target,size) MEMZERO(target,size)
+#else /* 80x86 case, define if we can */
+#ifdef USE_FMEM
+#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
+#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
+#endif
+#endif
+
+
+GLOBAL(void)
+jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
+ JSAMPARRAY output_array, int dest_row,
+ int num_rows, JDIMENSION num_cols)
+/* Copy some rows of samples from one place to another.
+ * num_rows rows are copied from input_array[source_row++]
+ * to output_array[dest_row++]; these areas may overlap for duplication.
+ * The source and destination arrays must be at least as wide as num_cols.
+ */
+{
+ register JSAMPROW inptr, outptr;
+#ifdef FMEMCOPY
+ register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
+#else
+ register JDIMENSION count;
+#endif
+ register int row;
+
+ input_array += source_row;
+ output_array += dest_row;
+
+ for (row = num_rows; row > 0; row--) {
+ inptr = *input_array++;
+ outptr = *output_array++;
+#ifdef FMEMCOPY
+ FMEMCOPY(outptr, inptr, count);
+#else
+ for (count = num_cols; count > 0; count--)
+ *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
+#endif
+ }
+}
+
+
+GLOBAL(void)
+jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
+ JDIMENSION num_blocks)
+/* Copy a row of coefficient blocks from one place to another. */
+{
+#ifdef FMEMCOPY
+ FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
+#else
+ register JCOEFPTR inptr, outptr;
+ register long count;
+
+ inptr = (JCOEFPTR) input_row;
+ outptr = (JCOEFPTR) output_row;
+ for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
+ *outptr++ = *inptr++;
+ }
+#endif
+}
+
+
+GLOBAL(void)
+jzero_far (void FAR * target, size_t bytestozero)
+/* Zero out a chunk of FAR memory. */
+/* This might be sample-array data, block-array data, or alloc_large data. */
+{
+#ifdef FMEMZERO
+ FMEMZERO(target, bytestozero);
+#else
+ register char FAR * ptr = (char FAR *) target;
+ register size_t count;
+
+ for (count = bytestozero; count > 0; count--) {
+ *ptr++ = 0;
+ }
+#endif
+}
diff --git a/osframework/source/ImageLib/jpeg/jversion.h b/osframework/source/ImageLib/jpeg/jversion.h
new file mode 100644
index 0000000..dadd453
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/jversion.h
@@ -0,0 +1,14 @@
+/*
+ * jversion.h
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains software version identification.
+ */
+
+
+#define JVERSION "6b 27-Mar-1998"
+
+#define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane"
diff --git a/osframework/source/ImageLib/jpeg/ltconfig b/osframework/source/ImageLib/jpeg/ltconfig
new file mode 100644
index 0000000..679dd73
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/ltconfig
@@ -0,0 +1,1512 @@
+#! /bin/sh
+
+# ltconfig - Create a system-specific libtool.
+# Copyright (C) 1996-1998 Free Software Foundation, Inc.
+# Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# A lot of this script is taken from autoconf-2.10.
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+if test "${CDPATH+set}" = set; then CDPATH=; export CDPATH; fi
+
+echo=echo
+if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then :
+else
+ # The Solaris and AIX default echo program unquotes backslashes.
+ # This makes it impossible to quote backslashes using
+ # echo "$something" | sed 's/\\/\\\\/g'
+ # So, we emulate echo with printf '%s\n'
+ echo="printf %s\\n"
+ if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then :
+ else
+ # Oops. We have no working printf. Try to find a not-so-buggy echo.
+ echo=echo
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
+ for dir in $PATH /usr/ucb; do
+ if test -f $dir/echo && test "X`$dir/echo '\t'`" = 'X\t'; then
+ echo="$dir/echo"
+ break
+ fi
+ done
+ IFS="$save_ifs"
+ fi
+fi
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='sed -e s/^X//'
+sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g'
+
+# The name of this program.
+progname=`$echo "X$0" | $Xsed -e 's%^.*/%%'`
+
+# Constants:
+PROGRAM=ltconfig
+PACKAGE=libtool
+VERSION=1.2
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.c 1>&5'
+ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.c $LIBS 1>&5'
+rm="rm -f"
+
+help="Try \`$progname --help' for more information."
+
+# Global variables:
+can_build_shared=yes
+enable_shared=yes
+# All known linkers require a `.a' archive for static linking.
+enable_static=yes
+ltmain=
+silent=
+srcdir=
+ac_config_guess=
+ac_config_sub=
+host=
+nonopt=
+verify_host=yes
+with_gcc=no
+with_gnu_ld=no
+
+old_AR="$AR"
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+old_CPPFLAGS="$CPPFLAGS"
+old_LD="$LD"
+old_LN_S="$LN_S"
+old_NM="$NM"
+old_RANLIB="$RANLIB"
+
+# Parse the command line options.
+args=
+prev=
+for option
+do
+ case "$option" in
+ -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) optarg= ;;
+ esac
+
+ # If the previous option needs an argument, assign it.
+ if test -n "$prev"; then
+ eval "$prev=\$option"
+ prev=
+ continue
+ fi
+
+ case "$option" in
+ --help) cat <<EOM
+Usage: $progname [OPTION]... LTMAIN [HOST]
+
+Generate a system-specific libtool script.
+
+ --disable-shared do not build shared libraries
+ --disable-static do not build static libraries
+ --help display this help and exit
+ --no-verify do not verify that HOST is a valid host type
+ --quiet same as \`--silent'
+ --silent do not print informational messages
+ --srcdir=DIR find \`config.guess' in DIR
+ --version output version information and exit
+ --with-gcc assume that the GNU C compiler will be used
+ --with-gnu-ld assume that the C compiler uses the GNU linker
+
+LTMAIN is the \`ltmain.sh' shell script fragment that provides basic libtool
+functionality.
+
+HOST is the canonical host system name [default=guessed].
+EOM
+ exit 0
+ ;;
+
+ --disable-shared) enable_shared=no ;;
+
+ --disable-static) enable_static=no ;;
+
+ --quiet | --silent) silent=yes ;;
+
+ --srcdir) prev=srcdir ;;
+ --srcdir=*) srcdir="$optarg" ;;
+
+ --no-verify) verify_host=no ;;
+
+ --version) echo "$PROGRAM (GNU $PACKAGE) $VERSION"; exit 0 ;;
+
+ --with-gcc) with_gcc=yes ;;
+ --with-gnu-ld) with_gnu_ld=yes ;;
+
+ -*)
+ echo "$progname: unrecognized option \`$option'" 1>&2
+ echo "$help" 1>&2
+ exit 1
+ ;;
+
+ *)
+ if test -z "$ltmain"; then
+ ltmain="$option"
+ elif test -z "$host"; then
+# This generates an unnecessary warning for sparc-sun-solaris4.1.3_U1
+# if test -n "`echo $option| sed 's/[-a-z0-9.]//g'`"; then
+# echo "$progname: warning \`$option' is not a valid host type" 1>&2
+# fi
+ host="$option"
+ else
+ echo "$progname: too many arguments" 1>&2
+ echo "$help" 1>&2
+ exit 1
+ fi ;;
+ esac
+done
+
+if test -z "$ltmain"; then
+ echo "$progname: you must specify a LTMAIN file" 1>&2
+ echo "$help" 1>&2
+ exit 1
+fi
+
+if test -f "$ltmain"; then :
+else
+ echo "$progname: \`$ltmain' does not exist" 1>&2
+ echo "$help" 1>&2
+ exit 1
+fi
+
+# Quote any args containing shell metacharacters.
+ltconfig_args=
+for arg
+do
+ case "$arg" in
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
+ ltconfig_args="$ltconfig_args '$arg'" ;;
+ *) ltconfig_args="$ltconfig_args $arg" ;;
+ esac
+done
+
+# A relevant subset of AC_INIT.
+
+# File descriptor usage:
+# 0 standard input
+# 1 file creation
+# 2 errors and warnings
+# 3 some systems may open it to /dev/tty
+# 4 used on the Kubota Titan
+# 5 compiler messages saved in config.log
+# 6 checking for... messages and results
+if test "$silent" = yes; then
+ exec 6>/dev/null
+else
+ exec 6>&1
+fi
+exec 5>>./config.log
+
+# NLS nuisances.
+# Only set LANG and LC_ALL to C if already set.
+# These must not be set unconditionally because not all systems understand
+# e.g. LANG=C (notably SCO).
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+
+if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+ # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
+ if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+ ac_n= ac_c='
+' ac_t=' '
+ else
+ ac_n=-n ac_c= ac_t=
+ fi
+else
+ ac_n= ac_c='\c' ac_t=
+fi
+
+if test -z "$srcdir"; then
+ # Assume the source directory is the same one as the path to ltmain.sh.
+ srcdir=`$echo "$ltmain" | $Xsed -e 's%/[^/]*$%%'`
+ test "$srcdir" = "$ltmain" && srcdir=.
+fi
+
+trap "$rm conftest*; exit 1" 1 2 15
+if test "$verify_host" = yes; then
+ # Check for config.guess and config.sub.
+ ac_aux_dir=
+ for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+ if test -f $ac_dir/config.guess; then
+ ac_aux_dir=$ac_dir
+ break
+ fi
+ done
+ if test -z "$ac_aux_dir"; then
+ echo "$progname: cannot find config.guess in $srcdir $srcdir/.. $srcdir/../.." 1>&2
+ echo "$help" 1>&2
+ exit 1
+ fi
+ ac_config_guess=$ac_aux_dir/config.guess
+ ac_config_sub=$ac_aux_dir/config.sub
+
+ # Make sure we can run config.sub.
+ if $ac_config_sub sun4 >/dev/null 2>&1; then :
+ else
+ echo "$progname: cannot run $ac_config_sub" 1>&2
+ echo "$help" 1>&2
+ exit 1
+ fi
+
+ echo $ac_n "checking host system type""... $ac_c" 1>&6
+
+ host_alias=$host
+ case "$host_alias" in
+ "")
+ if host_alias=`$ac_config_guess`; then :
+ else
+ echo "$progname: cannot guess host type; you must specify one" 1>&2
+ echo "$help" 1>&2
+ exit 1
+ fi ;;
+ esac
+ host=`$ac_config_sub $host_alias`
+ echo "$ac_t$host" 1>&6
+
+ # Make sure the host verified.
+ test -z "$host" && exit 1
+
+elif test -z "$host"; then
+ echo "$progname: you must specify a host type if you use \`--no-verify'" 1>&2
+ echo "$help" 1>&2
+ exit 1
+else
+ host_alias=$host
+fi
+
+# Transform linux* to *-*-linux-gnu*, to support old configure scripts.
+case "$host_os" in
+linux-gnu*) ;;
+linux*) host=`echo $host | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
+esac
+
+host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+case "$host_os" in
+aix3*)
+ # AIX sometimes has problems with the GCC collect2 program. For some
+ # reason, if we set the COLLECT_NAMES environment variable, the problems
+ # vanish in a puff of smoke.
+ if test "${COLLECT_NAMES+set}" != set; then
+ COLLECT_NAMES=
+ export COLLECT_NAMES
+ fi
+ ;;
+esac
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR cru $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+# Set a sane default for `AR'.
+test -z "$AR" && AR=ar
+
+# If RANLIB is not set, then run the test.
+if test "${RANLIB+set}" != "set"; then
+ result=no
+
+ echo $ac_n "checking for ranlib... $ac_c" 1>&6
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
+ for dir in $PATH; do
+ test -z "$dir" && dir=.
+ if test -f $dir/ranlib; then
+ RANLIB="ranlib"
+ result="ranlib"
+ break
+ fi
+ done
+ IFS="$save_ifs"
+
+ echo "$ac_t$result" 1>&6
+fi
+
+if test -n "$RANLIB"; then
+ old_archive_cmds="$old_archive_cmds;\$RANLIB \$oldlib"
+ old_postinstall_cmds="\$RANLIB \$oldlib;$old_postinstall_cmds"
+fi
+
+# Check to see if we are using GCC.
+if test "$with_gcc" != yes || test -z "$CC"; then
+ # If CC is not set, then try to find GCC or a usable CC.
+ if test -z "$CC"; then
+ echo $ac_n "checking for gcc... $ac_c" 1>&6
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
+ for dir in $PATH; do
+ IFS="$save_ifs"
+ test -z "$dir" && dir=.
+ if test -f $dir/gcc; then
+ CC="gcc"
+ break
+ fi
+ done
+ IFS="$save_ifs"
+
+ if test -n "$CC"; then
+ echo "$ac_t$CC" 1>&6
+ else
+ echo "$ac_t"no 1>&6
+ fi
+ fi
+
+ # Not "gcc", so try "cc", rejecting "/usr/ucb/cc".
+ if test -z "$CC"; then
+ echo $ac_n "checking for cc... $ac_c" 1>&6
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
+ cc_rejected=no
+ for dir in $PATH; do
+ test -z "$dir" && dir=.
+ if test -f $dir/cc; then
+ if test "$dir/cc" = "/usr/ucb/cc"; then
+ cc_rejected=yes
+ continue
+ fi
+ CC="cc"
+ break
+ fi
+ done
+ IFS="$save_ifs"
+ if test $cc_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $CC
+ shift
+ if test $# -gt 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same name, so the bogon will be chosen
+ # first if we set CC to just the name; use the full file name.
+ shift
+ set dummy "$dir/cc" "$@"
+ shift
+ CC="$@"
+ fi
+ fi
+
+ if test -n "$CC"; then
+ echo "$ac_t$CC" 1>&6
+ else
+ echo "$ac_t"no 1>&6
+ fi
+
+ if test -z "$CC"; then
+ echo "$progname: error: no acceptable cc found in \$PATH" 1>&2
+ exit 1
+ fi
+ fi
+
+ # Now see if the compiler is really GCC.
+ with_gcc=no
+ echo $ac_n "checking whether we are using GNU C... $ac_c" 1>&6
+ echo "$progname:424: checking whether we are using GNU C" >&5
+
+ $rm conftest.c
+ cat > conftest.c <<EOF
+#ifdef __GNUC__
+ yes;
+#endif
+EOF
+ if { ac_try='${CC-cc} -E conftest.c'; { (eval echo $progname:432: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+ with_gcc=yes
+ fi
+ $rm conftest.c
+ echo "$ac_t$with_gcc" 1>&6
+fi
+
+# Allow CC to be a program name with arguments.
+set dummy $CC
+compiler="$2"
+
+echo $ac_n "checking for $compiler option to produce PIC... $ac_c" 1>&6
+pic_flag=
+special_shlib_compile_flags=
+wl=
+link_static_flag=
+no_builtin_flag=
+
+if test "$with_gcc" = yes; then
+ wl='-Wl,'
+ link_static_flag='-static'
+ no_builtin_flag=' -fno-builtin'
+
+ case "$host_os" in
+ aix3* | aix4* | irix5* | irix6* | osf3* | osf4*)
+ # PIC is the default for these OSes.
+ ;;
+ os2*)
+ # We can build DLLs from non-PIC.
+ ;;
+ amigaos*)
+ # FIXME: we need at least 68020 code to build shared libraries, but
+ # adding the `-m68020' flag to GCC prevents building anything better,
+ # like `-m68040'.
+ pic_flag='-m68020 -resident32 -malways-restore-a4'
+ ;;
+ *)
+ pic_flag='-fPIC'
+ ;;
+ esac
+else
+ # PORTME Check for PIC flags for the system compiler.
+ case "$host_os" in
+ aix3* | aix4*)
+ # All AIX code is PIC.
+ link_static_flag='-bnso -bI:/lib/syscalls.exp'
+ ;;
+
+ hpux9* | hpux10*)
+ # Is there a better link_static_flag that works with the bundled CC?
+ wl='-Wl,'
+ link_static_flag="${wl}-a ${wl}archive"
+ pic_flag='+Z'
+ ;;
+
+ irix5* | irix6*)
+ wl='-Wl,'
+ link_static_flag='-non_shared'
+ # PIC (with -KPIC) is the default.
+ ;;
+
+ os2*)
+ # We can build DLLs from non-PIC.
+ ;;
+
+ osf3* | osf4*)
+ # All OSF/1 code is PIC.
+ wl='-Wl,'
+ link_static_flag='-non_shared'
+ ;;
+
+ sco3.2v5*)
+ pic_flag='-Kpic'
+ link_static_flag='-dn'
+ special_shlib_compile_flags='-belf'
+ ;;
+
+ solaris2*)
+ pic_flag='-KPIC'
+ link_static_flag='-Bstatic'
+ wl='-Wl,'
+ ;;
+
+ sunos4*)
+ pic_flag='-PIC'
+ link_static_flag='-Bstatic'
+ wl='-Qoption ld '
+ ;;
+
+ sysv4.2uw2*)
+ pic_flag='-KPIC'
+ link_static_flag='-Bstatic'
+ wl='-Wl,'
+ ;;
+
+ uts4*)
+ pic_flag='-pic'
+ link_static_flag='-Bstatic'
+ ;;
+
+ *)
+ can_build_shared=no
+ ;;
+ esac
+fi
+
+if test -n "$pic_flag"; then
+ echo "$ac_t$pic_flag" 1>&6
+
+ # Check to make sure the pic_flag actually works.
+ echo $ac_n "checking if $compiler PIC flag $pic_flag works... $ac_c" 1>&6
+ $rm conftest*
+ echo > conftest.c
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $pic_flag -DPIC"
+ echo "$progname:547: checking if $compiler PIC flag $pic_flag works" >&5
+ if { (eval echo $progname:548: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; } && test -s conftest.o; then
+ # Append any warnings to the config.log.
+ cat conftest.err 1>&5
+
+ # On HP-UX, both CC and GCC only warn that PIC is supported... then they
+ # create non-PIC objects. So, if there were any warnings, we assume that
+ # PIC is not supported.
+ if test -s conftest.err; then
+ echo "$ac_t"no 1>&6
+ can_build_shared=no
+ pic_flag=
+ else
+ echo "$ac_t"yes 1>&6
+ pic_flag=" $pic_flag"
+ fi
+ else
+ # Append any errors to the config.log.
+ cat conftest.err 1>&5
+ can_build_shared=no
+ pic_flag=
+ echo "$ac_t"no 1>&6
+ fi
+ CFLAGS="$save_CFLAGS"
+ $rm conftest*
+else
+ echo "$ac_t"none 1>&6
+fi
+
+# Check for any special shared library compilation flags.
+if test -n "$special_shlib_compile_flags"; then
+ echo "$progname: warning: \`$CC' requires \`$special_shlib_compile_flags' to build shared libraries" 1>&2
+ if echo "$old_CC $old_CFLAGS " | egrep -e "[ ]$special_shlib_compile_flags[ ]" >/dev/null; then :
+ else
+ echo "$progname: add \`$special_shlib_compile_flags' to the CC or CFLAGS env variable and reconfigure" 1>&2
+ can_build_shared=no
+ fi
+fi
+
+echo $ac_n "checking if $compiler static flag $link_static_flag works... $ac_c" 1>&6
+$rm conftest*
+echo 'main(){return(0);}' > conftest.c
+save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS $link_static_flag"
+echo "$progname:591: checking if $compiler static flag $link_static_flag works" >&5
+if { (eval echo $progname:592: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ echo "$ac_t$link_static_flag" 1>&6
+else
+ echo "$ac_t"none 1>&6
+ link_static_flag=
+fi
+LDFLAGS="$save_LDFLAGS"
+$rm conftest*
+
+if test -z "$LN_S"; then
+ # Check to see if we can use ln -s, or we need hard links.
+ echo $ac_n "checking whether ln -s works... $ac_c" 1>&6
+ $rm conftestdata
+ if ln -s X conftestdata 2>/dev/null; then
+ $rm conftestdata
+ LN_S="ln -s"
+ else
+ LN_S=ln
+ fi
+ if test "$LN_S" = "ln -s"; then
+ echo "$ac_t"yes 1>&6
+ else
+ echo "$ac_t"no 1>&6
+ fi
+fi
+
+# Make sure LD is an absolute path.
+if test -z "$LD"; then
+ ac_prog=ld
+ if test "$with_gcc" = yes; then
+ # Check if gcc -print-prog-name=ld gives a path.
+ echo $ac_n "checking for ld used by GCC... $ac_c" 1>&6
+ echo "$progname:624: checking for ld used by GCC" >&5
+ ac_prog=`($CC -print-prog-name=ld) 2>&5`
+ case "$ac_prog" in
+ # Accept absolute paths.
+ /* | [A-Za-z]:\\*)
+ test -z "$LD" && LD="$ac_prog"
+ ;;
+ "")
+ # If it fails, then pretend we are not using GCC.
+ ac_prog=ld
+ ;;
+ *)
+ # If it is relative, then search for the first ld in PATH.
+ with_gnu_ld=unknown
+ ;;
+ esac
+ elif test "$with_gnu_ld" = yes; then
+ echo $ac_n "checking for GNU ld... $ac_c" 1>&6
+ echo "$progname:642: checking for GNU ld" >&5
+ else
+ echo $ac_n "checking for non-GNU ld""... $ac_c" 1>&6
+ echo "$progname:645: checking for non-GNU ld" >&5
+ fi
+
+ if test -z "$LD"; then
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f "$ac_dir/$ac_prog"; then
+ LD="$ac_dir/$ac_prog"
+ # Check to see if the program is GNU ld. I'd rather use --version,
+ # but apparently some GNU ld's only accept -v.
+ # Break only if it was the GNU/non-GNU ld that we prefer.
+ if "$LD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then
+ test "$with_gnu_ld" != no && break
+ else
+ test "$with_gnu_ld" != yes && break
+ fi
+ fi
+ done
+ IFS="$ac_save_ifs"
+ fi
+
+ if test -n "$LD"; then
+ echo "$ac_t$LD" 1>&6
+ else
+ echo "$ac_t"no 1>&6
+ fi
+
+ if test -z "$LD"; then
+ echo "$progname: error: no acceptable ld found in \$PATH" 1>&2
+ exit 1
+ fi
+fi
+
+# Check to see if it really is or is not GNU ld.
+echo $ac_n "checking if the linker ($LD) is GNU ld... $ac_c" 1>&6
+# I'd rather use --version here, but apparently some GNU ld's only accept -v.
+if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
+ with_gnu_ld=yes
+else
+ with_gnu_ld=no
+fi
+echo "$ac_t$with_gnu_ld" 1>&6
+
+# See if the linker supports building shared libraries.
+echo $ac_n "checking whether the linker ($LD) supports shared libraries... $ac_c" 1>&6
+
+allow_undefined_flag=
+no_undefined_flag=
+archive_cmds=
+old_archive_from_new_cmds=
+export_dynamic_flag_spec=
+hardcode_libdir_flag_spec=
+hardcode_libdir_separator=
+hardcode_direct=no
+hardcode_minus_L=no
+hardcode_shlibpath_var=unsupported
+runpath_var=
+
+case "$host_os" in
+amigaos* | sunos4*)
+ # On these operating systems, we should treat GNU ld like the system ld.
+ gnu_ld_acts_native=yes
+ ;;
+*)
+ gnu_ld_acts_native=no
+ ;;
+esac
+
+ld_shlibs=yes
+if test "$with_gnu_ld" = yes && test "$gnu_ld_acts_native" != yes; then
+
+ # See if GNU ld supports shared libraries.
+ if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
+ archive_cmds='$CC -shared ${wl}-soname $wl$soname -o $lib$libobjs'
+ runpath_var=LD_RUN_PATH
+ ld_shlibs=yes
+ else
+ ld_shlibs=no
+ fi
+
+ if test "$ld_shlibs" = yes; then
+ hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'
+ export_dynamic_flag_spec='${wl}--export-dynamic'
+ fi
+else
+ # PORTME fill in a description of your system's linker (not GNU ld)
+ case "$host_os" in
+ aix3*)
+ allow_undefined_flag=unsupported
+ archive_cmds='$NM$libobjs | $global_symbol_pipe | sed '\''s/.* //'\'' > $lib.exp;$LD -o $objdir/$soname$libobjs -bE:$lib.exp -T512 -H512 -bM:SRE;$AR cru $lib $objdir/$soname'
+ # Note: this linker hardcodes the directories in LIBPATH if there
+ # are no directories specified by -L.
+ hardcode_minus_L=yes
+ if test "$with_gcc" = yes && test -z "$link_static_flag"; then
+ # Neither direct hardcoding nor static linking is supported with a
+ # broken collect2.
+ hardcode_direct=unsupported
+ fi
+ ;;
+
+ aix4*)
+ allow_undefined_flag=unsupported
+ archive_cmds='$NM$libobjs | $global_symbol_pipe | sed '\''s/.* //'\'' > $lib.exp;$CC -o $objdir/$soname$libobjs ${wl}-bE:$lib.exp ${wl}-bM:SRE ${wl}-bnoentry;$AR cru $lib $objdir/$soname'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ ;;
+
+ amigaos*)
+ archive_cmds='$rm $objdir/a2ixlibrary.data;$echo "#define NAME $libname" > $objdir/a2ixlibrary.data;$echo "#define LIBRARY_ID 1" >> $objdir/a2ixlibrary.data;$echo "#define VERSION $major" >> $objdir/a2ixlibrary.data;$echo "#define REVISION $revision" >> $objdir/a2ixlibrary.data;$AR cru $lib$libobjs;$RANLIB $lib;(cd $objdir && a2ixlibrary -32)'
+ hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_minus_L=yes
+ ;;
+
+ # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+ # support. Future versions do this automatically, but an explicit c++rt0.o
+ # does not break anything, and helps significantly (at the cost of a little
+ # extra space).
+ freebsd2.2*)
+ archive_cmds='$LD -Bshareable -o $lib$libobjs /usr/lib/c++rt0.o'
+ hardcode_libdir_flag_spec='-R$libdir'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+ freebsd2*)
+ archive_cmds='$LD -Bshareable -o $lib$libobjs'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ # FreeBSD 3, at last, uses gcc -shared to do shared libraries.
+ freebsd3*)
+ archive_cmds='$CC -shared -o $lib$libobjs'
+ hardcode_libdir_flag_spec='-R$libdir'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ hpux9*)
+ archive_cmds='$rm $objdir/$soname;$LD -b +s +b $install_libdir -o $objdir/$soname$libobjs;mv $objdir/$soname $lib'
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ export_dynamic_flag_spec='${wl}-E'
+ ;;
+
+ hpux10*)
+ archive_cmds='$LD -b +h $soname +s +b $install_libdir -o $lib$libobjs'
+ hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ export_dynamic_flag_spec='${wl}-E'
+ ;;
+
+ irix5* | irix6*)
+ archive_cmds='$LD -shared -o $lib -soname $soname -set_version $verstring$libobjs'
+ hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+ ;;
+
+ netbsd*)
+ # Tested with NetBSD 1.2 ld
+ archive_cmds='$LD -Bshareable -o $lib$libobjs'
+ hardcode_libdir_flag_spec='-R$libdir'
+ hardcode_direct=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ openbsd*)
+ archive_cmds='$LD -Bshareable -o $lib$libobjs'
+ hardcode_libdir_flag_spec='-R$libdir'
+ hardcode_direct=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ os2*)
+ hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_minus_L=yes
+ allow_undefined_flag=unsupported
+ archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $objdir/$libname.def;$echo "DESCRIPTION \"$libname\"" >> $objdir/$libname.def;$echo DATA >> $objdir/$libname.def;$echo " SINGLE NONSHARED" >> $objdir/$libname.def;$echo EXPORTS >> $objdir/$libname.def;emxexp$libobjs >> $objdir/$libname.def;$CC -Zdll -Zcrtdll -o $lib$libobjs $objdir/$libname.def'
+ old_archive_from_new_cmds='emximp -o $objdir/$libname.a $objdir/$libname.def'
+ ;;
+
+ osf3* | osf4*)
+ allow_undefined_flag=' -expect_unresolved \*'
+ archive_cmds='$LD -shared${allow_undefined_flag} -o $lib -soname $soname -set_version $verstring$libobjs$deplibs'
+ hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+ hardcode_libdir_separator=:
+ ;;
+
+ sco3.2v5*)
+ archive_cmds='$LD -G -o $lib$libobjs'
+ hardcode_direct=yes
+ ;;
+
+ solaris2*)
+ no_undefined_flag=' -z text'
+ archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib$libobjs'
+ hardcode_libdir_flag_spec='-R$libdir'
+ hardcode_shlibpath_var=no
+
+ # Solaris 2 before 2.5 hardcodes -L paths.
+ case "$host_os" in
+ solaris2.[0-4]*)
+ hardcode_minus_L=yes
+ ;;
+ esac
+ ;;
+
+ sunos4*)
+ if test "$with_gcc" = yes; then
+ archive_cmds='$CC -shared -o $lib$libobjs'
+ else
+ archive_cmds='$LD -assert pure-text -Bstatic -o $lib$libobjs'
+ fi
+
+ if test "$with_gnu_ld" = yes; then
+ export_dynamic_flag_spec='${wl}-export-dynamic'
+ fi
+ hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_direct=yes
+ hardcode_minus_L=yes
+ hardcode_shlibpath_var=no
+ ;;
+
+ uts4*)
+ archive_cmds='$LD -G -h $soname -o $lib$libobjs'
+ hardcode_libdir_flag_spec='-L$libdir'
+ hardcode_direct=no
+ hardcode_minus_L=no
+ hardcode_shlibpath_var=no
+ ;;
+
+ *)
+ ld_shlibs=no
+ can_build_shared=no
+ ;;
+ esac
+fi
+echo "$ac_t$ld_shlibs" 1>&6
+
+if test -z "$NM"; then
+ echo $ac_n "checking for BSD-compatible nm... $ac_c" 1>&6
+ case "$NM" in
+ /* | [A-Za-z]:\\*) ;; # Let the user override the test with a path.
+ *)
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in /usr/ucb /usr/ccs/bin $PATH /bin; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/nm; then
+ # Check to see if the nm accepts a BSD-compat flag.
+ # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+ # nm: unknown option "B" ignored
+ if ($ac_dir/nm -B /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
+ NM="$ac_dir/nm -B"
+ elif ($ac_dir/nm -p /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
+ NM="$ac_dir/nm -p"
+ else
+ NM="$ac_dir/nm"
+ fi
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+ test -z "$NM" && NM=nm
+ ;;
+ esac
+ echo "$ac_t$NM" 1>&6
+fi
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+echo $ac_n "checking command to parse $NM output... $ac_c" 1>&6
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix. What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRSTU]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Transform the above into a raw symbol and a C symbol.
+symxfrm='\1 \1'
+
+# Define system-specific variables.
+case "$host_os" in
+aix*)
+ symcode='[BCDTU]'
+ ;;
+irix*)
+ # Cannot use undefined symbols on IRIX because inlined functions mess us up.
+ symcode='[BCDEGRST]'
+ ;;
+solaris2*)
+ symcode='[BDTU]'
+ ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+if $NM -V 2>&1 | egrep '(GNU|with BFD)' > /dev/null; then
+ symcode='[ABCDGISTUW]'
+fi
+
+# Write the raw and C identifiers.
+global_symbol_pipe="sed -n -e 's/^.* $symcode $sympat$/$symxfrm/p'"
+
+# Check to see that the pipe works correctly.
+pipe_works=no
+$rm conftest*
+cat > conftest.c <<EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(){}
+#ifdef __cplusplus
+}
+#endif
+main(){nm_test_var='a';nm_test_func();return(0);}
+EOF
+
+echo "$progname:971: checking if global_symbol_pipe works" >&5
+if { (eval echo $progname:972: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then
+ # Now try to grab the symbols.
+ nlist=conftest.nm
+ if { echo "$progname:975: eval \"$NM conftest.o | $global_symbol_pipe > $nlist\"" >&5; eval "$NM conftest.o | $global_symbol_pipe > $nlist 2>&5"; } && test -s "$nlist"; then
+
+ # Try sorting and uniquifying the output.
+ if sort "$nlist" | uniq > "$nlist"T; then
+ mv -f "$nlist"T "$nlist"
+ wcout=`wc "$nlist" 2>/dev/null`
+ count=`$echo "X$wcout" | $Xsed -e 's/^[ ]*\([0-9][0-9]*\).*$/\1/'`
+ (test "$count" -ge 0) 2>/dev/null || count=-1
+ else
+ rm -f "$nlist"T
+ count=-1
+ fi
+
+ # Make sure that we snagged all the symbols we need.
+ if egrep ' nm_test_var$' "$nlist" >/dev/null; then
+ if egrep ' nm_test_func$' "$nlist" >/dev/null; then
+ cat <<EOF > conftest.c
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EOF
+ # Now generate the symbol file.
+ sed 's/^.* \(.*\)$/extern char \1;/' < "$nlist" >> conftest.c
+
+ cat <<EOF >> conftest.c
+#if defined (__STDC__) && __STDC__
+# define __ptr_t void *
+#else
+# define __ptr_t char *
+#endif
+
+/* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */
+int dld_preloaded_symbol_count = $count;
+
+/* The mapping between symbol names and symbols. */
+struct {
+ char *name;
+ __ptr_t address;
+}
+dld_preloaded_symbols[] =
+{
+EOF
+ sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$nlist" >> conftest.c
+ cat <<\EOF >> conftest.c
+ {0, (__ptr_t) 0}
+};
+
+#ifdef __cplusplus
+}
+#endif
+EOF
+ # Now try linking the two files.
+ mv conftest.o conftestm.o
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS='conftestm.o'
+ CFLAGS="$CFLAGS$no_builtin_flag"
+ if { (eval echo $progname:1033: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ pipe_works=yes
+ else
+ echo "$progname: failed program was:" >&5
+ cat conftest.c >&5
+ fi
+ LIBS="$save_LIBS"
+ else
+ echo "cannot find nm_test_func in $nlist" >&5
+ fi
+ else
+ echo "cannot find nm_test_var in $nlist" >&5
+ fi
+ else
+ echo "cannot run $global_symbol_pipe" >&5
+ fi
+else
+ echo "$progname: failed program was:" >&5
+ cat conftest.c >&5
+fi
+$rm conftest*
+
+# Do not use the global_symbol_pipe unless it works.
+echo "$ac_t$pipe_works" 1>&6
+test "$pipe_works" = yes || global_symbol_pipe=
+
+# Check hardcoding attributes.
+echo $ac_n "checking how to hardcode library paths into programs... $ac_c" 1>&6
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" || \
+ test -n "$runpath_var"; then
+
+ # We can hardcode non-existant directories.
+ if test "$hardcode_direct" != no && \
+ test "$hardcode_minus_L" != no && \
+ test "$hardcode_shlibpath_var" != no; then
+
+ # Linking always hardcodes the temporary library directory.
+ hardcode_action=relink
+ else
+ # We can link without hardcoding, and we can hardcode nonexisting dirs.
+ hardcode_action=immediate
+ fi
+elif test "$hardcode_direct" != yes && \
+ test "$hardcode_minus_L" != yes && \
+ test "$hardcode_shlibpath_var" != yes; then
+ # We cannot hardcode anything.
+ hardcode_action=unsupported
+else
+ # We can only hardcode existing directories.
+ hardcode_action=relink
+fi
+echo "$ac_t$hardcode_action" 1>&6
+test "$hardcode_action" = unsupported && can_build_shared=no
+
+
+reload_flag=
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+echo $ac_n "checking for $LD option to reload object files... $ac_c" 1>&6
+# PORTME Some linker may need a different reload flag.
+reload_flag='-r'
+echo "$ac_t$reload_flag"
+test -n "$reload_flag" && reload_flag=" $reload_flag"
+
+# PORTME Fill in your ld.so characteristics
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+version_type=none
+dynamic_linker="$host_os ld.so"
+
+echo $ac_n "checking dynamic linker characteristics... $ac_c" 1>&6
+case "$host_os" in
+aix3* | aix4*)
+ version_type=linux
+ library_names_spec='${libname}${release}.so.$versuffix $libname.a'
+ shlibpath_var=LIBPATH
+
+ # AIX has no versioning support, so we append a major version to the name.
+ soname_spec='${libname}${release}.so.$major'
+ ;;
+
+amigaos*)
+ library_names_spec='$libname.ixlibrary $libname.a'
+ # Create ${libname}_ixlibrary.a entries in /sys/libs.
+ finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
+ ;;
+
+freebsd2* | freebsd3*)
+ version_type=sunos
+ library_names_spec='${libname}${release}.so.$versuffix $libname.so'
+ finish_cmds='PATH="$PATH:/sbin" ldconfig -m $libdir'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+gnu*)
+ version_type=sunos
+ library_names_spec='${libname}${release}.so.$versuffix'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+hpux9* | hpux10*)
+ # Give a soname corresponding to the major version so that dld.sl refuses to
+ # link against other versions.
+ dynamic_linker="$host_os dld.sl"
+ version_type=sunos
+ shlibpath_var=SHLIB_PATH
+ library_names_spec='${libname}${release}.sl.$versuffix ${libname}${release}.sl.$major $libname.sl'
+ soname_spec='${libname}${release}.sl.$major'
+ # HP-UX runs *really* slowly unless shared libraries are mode 555.
+ postinstall_cmds='chmod 555 $lib'
+ ;;
+
+irix5* | irix6*)
+ version_type=osf
+ soname_spec='${libname}${release}.so'
+ library_names_spec='${libname}${release}.so.$versuffix $libname.so'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux-gnuoldld* | linux-gnuaout* | linux-gnucoff*)
+ dynamic_linker=no
+ ;;
+
+# This must be Linux ELF.
+linux-gnu*)
+ version_type=linux
+ library_names_spec='${libname}${release}.so.$versuffix ${libname}${release}.so.$major $libname.so'
+ soname_spec='${libname}${release}.so.$major'
+ finish_cmds='PATH="$PATH:/sbin" ldconfig -n $libdir'
+ shlibpath_var=LD_LIBRARY_PATH
+
+ if test -f /lib/ld.so.1; then
+ dynamic_linker='GNU ld.so'
+ else
+ # Only the GNU ld.so supports shared libraries on MkLinux.
+ case "$host_cpu" in
+ powerpc*) dynamic_linker=no ;;
+ *) dynamic_linker='Linux ld.so' ;;
+ esac
+ fi
+ ;;
+
+netbsd* | openbsd*)
+ version_type=sunos
+ library_names_spec='${libname}${release}.so.$versuffix'
+ finish_cmds='PATH="$PATH:/sbin" ldconfig -m $libdir'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+os2*)
+ libname_spec='$name'
+ library_names_spec='$libname.dll $libname.a'
+ dynamic_linker='OS/2 ld.exe'
+ shlibpath_var=LIBPATH
+ ;;
+
+osf3* | osf4*)
+ version_type=osf
+ soname_spec='${libname}${release}.so'
+ library_names_spec='${libname}${release}.so.$versuffix $libname.so'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+sco3.2v5*)
+ version_type=osf
+ soname_spec='${libname}${release}.so.$major'
+ library_names_spec='${libname}${release}.so.$versuffix ${libname}${release}.so.$major $libname.so'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+solaris2*)
+ version_type=linux
+ library_names_spec='${libname}${release}.so.$versuffix ${libname}${release}.so.$major $libname.so'
+ soname_spec='${libname}${release}.so.$major'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+sunos4*)
+ version_type=sunos
+ library_names_spec='${libname}${release}.so.$versuffix'
+ finish_cmds='PATH="$PATH:/usr/etc" ldconfig $libdir'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+sysv4.2uw2*)
+ version_type=linux
+ library_names_spec='${libname}${release}.so.$versuffix ${libname}${release}.so.$major $libname.so'
+ soname_spec='${libname}${release}.so.$major'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+uts4*)
+ version_type=linux
+ library_names_spec='${libname}${release}.so.$versuffix ${libname}${release}.so.$major $libname.so'
+ soname_spec='${libname}${release}.so.$major'
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
+*)
+ dynamic_linker=no
+ ;;
+esac
+echo "$ac_t$dynamic_linker"
+test "$dynamic_linker" = no && can_build_shared=no
+
+# Report the final consequences.
+echo "checking if libtool supports shared libraries... $can_build_shared" 1>&6
+
+echo $ac_n "checking whether to build shared libraries... $ac_c" 1>&6
+test "$can_build_shared" = "no" && enable_shared=no
+
+# On AIX, shared libraries and static libraries use the same namespace, and
+# are all built from PIC.
+case "$host_os" in
+aix*)
+ test "$enable_shared" = yes && enable_static=no
+ if test -n "$RANLIB"; then
+ archive_cmds="$archive_cmds;\$RANLIB \$lib"
+ postinstall_cmds='$RANLIB $lib'
+ fi
+ ;;
+esac
+
+echo "$ac_t$enable_shared" 1>&6
+
+# Make sure either enable_shared or enable_static is yes.
+test "$enable_shared" = yes || enable_static=yes
+
+echo "checking whether to build static libraries... $enable_static" 1>&6
+
+echo $ac_n "checking for objdir... $ac_c" 1>&6
+rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+ objdir=.libs
+else
+ # MS-DOS does not allow filenames that begin with a dot.
+ objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+echo "$ac_t$objdir" 1>&6
+
+# Copy echo and quote the copy, instead of the original, because it is
+# used later.
+ltecho="$echo"
+
+# Now quote all the things that may contain metacharacters.
+for var in ltecho old_CC old_CFLAGS old_CPPFLAGS old_LD old_NM old_RANLIB \
+ old_LN_S AR CC LD LN_S NM reload_flag reload_cmds wl pic_flag \
+ link_static_flag no_builtin_flag export_dynamic_flag_spec \
+ libname_spec library_names_spec soname_spec RANLIB \
+ old_archive_cmds old_archive_from_new_cmds old_postinstall_cmds \
+ old_postuninstall_cmds archive_cmds postinstall_cmds postuninstall_cmds \
+ allow_undefined_flag no_undefined_flag \
+ finish_cmds finish_eval global_symbol_pipe \
+ hardcode_libdir_flag_spec hardcode_libdir_separator; do
+
+ case "$var" in
+ reload_cmds | old_archive_cmds | old_archive_from_new_cmds | \
+ old_postinstall_cmds | old_postuninstall_cmds | archive_cmds | \
+ postinstall_cmds | postuninstall_cmds | finish_cmds)
+ # Double-quote double-evaled strings.
+ eval "$var=\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\"\`"
+ ;;
+ *)
+ eval "$var=\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`"
+ ;;
+ esac
+done
+
+ofile=libtool
+trap "$rm $ofile; exit 1" 1 2 15
+echo creating $ofile
+$rm $ofile
+cat <<EOF > $ofile
+#! /bin/sh
+
+# libtool - Provide generalized library-building support services.
+# Generated automatically by $PROGRAM - GNU $PACKAGE $VERSION
+# NOTE: Changes made to this file will be lost: look at ltconfig or ltmain.sh.
+#
+# Copyright (C) 1996-1998 Free Software Foundation, Inc.
+# Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This program was configured as follows,
+# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+#
+# CC="$old_CC" CFLAGS="$old_CFLAGS" CPPFLAGS="$old_CPPFLAGS" \\
+# LD="$old_LD" NM="$old_NM" RANLIB="$old_RANLIB" LN_S="$old_LN_S" \\
+# $0$ltconfig_args
+#
+# Compiler and other test output produced by $progname, useful for
+# debugging $progname, is in ./config.log if it exists.
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="sed -e s/^X//"
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+if test "\${CDPATH+set}" = set; then CDPATH=; export CDPATH; fi
+
+# An echo program that does not interpret backslashes.
+echo="$ltecho"
+
+# The version of $progname that generated this script.
+LTCONFIG_VERSION="$VERSION"
+
+# Shell to use when invoking shell scripts.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Whether or not to build libtool libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build old-style libraries.
+build_old_libs=$enable_static
+
+# The host system.
+host_alias="$host_alias"
+host="$host"
+
+# The archiver.
+AR="$AR"
+
+# The default C compiler.
+CC="$CC"
+
+# The linker used to build libraries.
+LD="$LD"
+
+# Whether we need hard or soft links.
+LN_S="$LN_S"
+
+# A BSD-compatible nm program.
+NM="$NM"
+
+# The name of the directory that contains temporary libtool files.
+objdir="$objdir"
+
+# How to create reloadable object files.
+reload_flag="$reload_flag"
+reload_cmds="$reload_cmds"
+
+# How to pass a linker flag through the compiler.
+wl="$wl"
+
+# Additional compiler flags for building library objects.
+pic_flag="$pic_flag"
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag="$link_static_flag"
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag="$no_builtin_flag"
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec="$export_dynamic_flag_spec"
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec="$libname_spec"
+
+# List of archive names. First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec="$library_names_spec"
+
+# The coded name of the library, if different from the real name.
+soname_spec="$soname_spec"
+
+# Commands used to build and install an old-style archive.
+RANLIB="$RANLIB"
+old_archive_cmds="$old_archive_cmds"
+old_postinstall_cmds="$old_postinstall_cmds"
+old_postuninstall_cmds="$old_postuninstall_cmds"
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds="$old_archive_from_new_cmds"
+
+# Commands used to build and install a shared archive.
+archive_cmds="$archive_cmds"
+postinstall_cmds="$postinstall_cmds"
+postuninstall_cmds="$postuninstall_cmds"
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag="$allow_undefined_flag"
+
+# Flag that forces no undefined symbols.
+no_undefined_flag="$no_undefined_flag"
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds="$finish_cmds"
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval="$finish_eval"
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe="$global_symbol_pipe"
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec="$hardcode_libdir_flag_spec"
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator="$hardcode_libdir_separator"
+
+# Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var
+
+EOF
+
+case "$host_os" in
+aix3*)
+ cat <<\EOF >> $ofile
+# AIX sometimes has problems with the GCC collect2 program. For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "${COLLECT_NAMES+set}" != set; then
+ COLLECT_NAMES=
+ export COLLECT_NAMES
+fi
+
+EOF
+ ;;
+esac
+
+# Append the ltmain.sh script.
+cat "$ltmain" >> $ofile || (rm -f $ofile; exit 1)
+
+chmod +x $ofile
+exit 0
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
diff --git a/osframework/source/ImageLib/jpeg/ltmain.sh b/osframework/source/ImageLib/jpeg/ltmain.sh
new file mode 100644
index 0000000..fe2d850
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/ltmain.sh
@@ -0,0 +1,2453 @@
+# ltmain.sh - Provide generalized library-building support services.
+# NOTE: Changing this file will not affect anything until you rerun ltconfig.
+#
+# Copyright (C) 1996-1998 Free Software Foundation, Inc.
+# Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# The name of this program.
+progname=`$echo "$0" | sed 's%^.*/%%'`
+modename="$progname"
+
+# Constants.
+PROGRAM=ltmain.sh
+PACKAGE=libtool
+VERSION=1.2
+
+default_mode=
+help="Try \`$progname --help' for more information."
+magic="%%%MAGIC variable%%%"
+mkdir="mkdir"
+mv="mv -f"
+rm="rm -f"
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='sed -e s/^X//'
+sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
+
+# NLS nuisances.
+# Only set LANG and LC_ALL to C if already set.
+# These must not be set unconditionally because not all systems understand
+# e.g. LANG=C (notably SCO).
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+
+if test "$LTCONFIG_VERSION" != "$VERSION"; then
+ echo "$modename: ltconfig version \`$LTCONFIG_VERSION' does not match $PROGRAM version \`$VERSION'" 1>&2
+ echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2
+ exit 1
+fi
+
+if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+ echo "$modename: not configured to build any kind of library" 1>&2
+ echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2
+ exit 1
+fi
+
+# Global variables.
+mode=$default_mode
+nonopt=
+prev=
+prevopt=
+run=
+show="$echo"
+show_help=
+execute_dlfiles=
+
+# Parse our command line options once, thoroughly.
+while test $# -gt 0
+do
+ arg="$1"
+ shift
+
+ case "$arg" in
+ -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) optarg= ;;
+ esac
+
+ # If the previous option needs an argument, assign it.
+ if test -n "$prev"; then
+ case "$prev" in
+ execute_dlfiles)
+ eval "$prev=\"\$$prev \$arg\""
+ ;;
+ *)
+ eval "$prev=\$arg"
+ ;;
+ esac
+
+ prev=
+ prevopt=
+ continue
+ fi
+
+ # Have we seen a non-optional argument yet?
+ case "$arg" in
+ --help)
+ show_help=yes
+ ;;
+
+ --version)
+ echo "$PROGRAM (GNU $PACKAGE) $VERSION"
+ exit 0
+ ;;
+
+ --dry-run | -n)
+ run=:
+ ;;
+
+ --features)
+ echo "host: $host"
+ if test "$build_libtool_libs" = yes; then
+ echo "enable shared libraries"
+ else
+ echo "disable shared libraries"
+ fi
+ if test "$build_old_libs" = yes; then
+ echo "enable static libraries"
+ else
+ echo "disable static libraries"
+ fi
+ exit 0
+ ;;
+
+ --finish) mode="finish" ;;
+
+ --mode) prevopt="--mode" prev=mode ;;
+ --mode=*) mode="$optarg" ;;
+
+ --quiet | --silent)
+ show=:
+ ;;
+
+ -dlopen)
+ prevopt="-dlopen"
+ prev=execute_dlfiles
+ ;;
+
+ -*)
+ $echo "$modename: unrecognized option \`$arg'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+
+ *)
+ nonopt="$arg"
+ break
+ ;;
+ esac
+done
+
+if test -n "$prevopt"; then
+ $echo "$modename: option \`$prevopt' requires an argument" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+fi
+
+if test -z "$show_help"; then
+
+ # Infer the operation mode.
+ if test -z "$mode"; then
+ case "$nonopt" in
+ *cc | *++ | gcc* | *-gcc*)
+ mode=link
+ for arg
+ do
+ case "$arg" in
+ -c)
+ mode=compile
+ break
+ ;;
+ esac
+ done
+ ;;
+ *db | *dbx)
+ mode=execute
+ ;;
+ *install*|cp|mv)
+ mode=install
+ ;;
+ *rm)
+ mode=uninstall
+ ;;
+ *)
+ # If we have no mode, but dlfiles were specified, then do execute mode.
+ test -n "$execute_dlfiles" && mode=execute
+
+ # Just use the default operation mode.
+ if test -z "$mode"; then
+ if test -n "$nonopt"; then
+ $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2
+ else
+ $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2
+ fi
+ fi
+ ;;
+ esac
+ fi
+
+ # Only execute mode is allowed to have -dlopen flags.
+ if test -n "$execute_dlfiles" && test "$mode" != execute; then
+ $echo "$modename: unrecognized option \`-dlopen'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ # Change the help message to a mode-specific one.
+ generic_help="$help"
+ help="Try \`$modename --help --mode=$mode' for more information."
+
+ # These modes are in order of execution frequency so that they run quickly.
+ case "$mode" in
+ # libtool compile mode
+ compile)
+ modename="$modename: compile"
+ # Get the compilation command and the source file.
+ base_compile=
+ lastarg=
+ srcfile="$nonopt"
+ suppress_output=
+
+ for arg
+ do
+ # Accept any command-line options.
+ case "$arg" in
+ -o)
+ $echo "$modename: you cannot specify the output filename with \`-o'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+
+ -static)
+ build_libtool_libs=no
+ build_old_libs=yes
+ continue
+ ;;
+ esac
+
+ # Accept the current argument as the source file.
+ lastarg="$srcfile"
+ srcfile="$arg"
+
+ # Aesthetically quote the previous argument.
+
+ # Backslashify any backslashes, double quotes, and dollar signs.
+ # These are the only characters that are still specially
+ # interpreted inside of double-quoted scrings.
+ lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"`
+
+ # Double-quote args containing other shell metacharacters.
+ # Many Bourne shells cannot handle close brackets correctly in scan
+ # sets, so we specify it separately.
+ case "$lastarg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ lastarg="\"$lastarg\""
+ ;;
+ esac
+
+ # Add the previous argument to base_compile.
+ if test -z "$base_compile"; then
+ base_compile="$lastarg"
+ else
+ base_compile="$base_compile $lastarg"
+ fi
+ done
+
+ # Get the name of the library object.
+ libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'`
+
+ # Recognize several different file suffixes.
+ xform='[cCFSfms]'
+ case "$libobj" in
+ *.ada) xform=ada ;;
+ *.adb) xform=adb ;;
+ *.ads) xform=ads ;;
+ *.asm) xform=asm ;;
+ *.c++) xform=c++ ;;
+ *.cc) xform=cc ;;
+ *.cpp) xform=cpp ;;
+ *.cxx) xform=cxx ;;
+ *.f90) xform=f90 ;;
+ *.for) xform=for ;;
+ esac
+
+ libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
+
+ case "$libobj" in
+ *.lo) obj=`$echo "X$libobj" | $Xsed -e 's/\.lo$/.o/'` ;;
+ *)
+ $echo "$modename: cannot determine name of library object from \`$srcfile'" 1>&2
+ exit 1
+ ;;
+ esac
+
+ if test -z "$base_compile"; then
+ $echo "$modename: you must specify a compilation command" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ # Delete any leftover library objects.
+ if test "$build_old_libs" = yes; then
+ $run $rm $obj $libobj
+ trap "$run $rm $obj $libobj; exit 1" 1 2 15
+ else
+ $run $rm $libobj
+ trap "$run $rm $libobj; exit 1" 1 2 15
+ fi
+
+ # Only build a PIC object if we are building libtool libraries.
+ if test "$build_libtool_libs" = yes; then
+ # Without this assignment, base_compile gets emptied.
+ fbsd_hideous_sh_bug=$base_compile
+
+ # All platforms use -DPIC, to notify preprocessed assembler code.
+ $show "$base_compile$pic_flag -DPIC $srcfile"
+ if $run eval "$base_compile\$pic_flag -DPIC \$srcfile"; then :
+ else
+ test -n "$obj" && $run $rm $obj
+ exit 1
+ fi
+
+ # If we have no pic_flag, then copy the object into place and finish.
+ if test -z "$pic_flag"; then
+ $show "$LN_S $obj $libobj"
+ $run $LN_S $obj $libobj
+ exit $?
+ fi
+
+ # Just move the object, then go on to compile the next one
+ $show "$mv $obj $libobj"
+ $run $mv $obj $libobj || exit 1
+
+ # Allow error messages only from the first compilation.
+ suppress_output=' >/dev/null 2>&1'
+ fi
+
+ # Only build a position-dependent object if we build old libraries.
+ if test "$build_old_libs" = yes; then
+ # Suppress compiler output if we already did a PIC compilation.
+ $show "$base_compile $srcfile$suppress_output"
+ if $run eval "$base_compile \$srcfile$suppress_output"; then :
+ else
+ $run $rm $obj $libobj
+ exit 1
+ fi
+ fi
+
+ # Create an invalid libtool object if no PIC, so that we do not
+ # accidentally link it into a program.
+ if test "$build_libtool_libs" != yes; then
+ $show "echo timestamp > $libobj"
+ $run eval "echo timestamp > \$libobj" || exit $?
+ fi
+
+ exit 0
+ ;;
+
+ # libtool link mode
+ link)
+ modename="$modename: link"
+ CC="$nonopt"
+ allow_undefined=yes
+ compile_command="$CC"
+ finalize_command="$CC"
+
+ compile_shlibpath=
+ finalize_shlibpath=
+ deplibs=
+ dlfiles=
+ dlprefiles=
+ export_dynamic=no
+ hardcode_libdirs=
+ libobjs=
+ link_against_libtool_libs=
+ ltlibs=
+ objs=
+ prev=
+ prevarg=
+ release=
+ rpath=
+ perm_rpath=
+ temp_rpath=
+ vinfo=
+
+ # We need to know -static, to get the right output filenames.
+ for arg
+ do
+ case "$arg" in
+ -all-static | -static)
+ if test "X$arg" = "X-all-static" && test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
+ $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2
+ fi
+ build_libtool_libs=no
+ build_old_libs=yes
+ break
+ ;;
+ esac
+ done
+
+ # See if our shared archives depend on static archives.
+ test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+ # Go through the arguments, transforming them on the way.
+ for arg
+ do
+ # If the previous option needs an argument, assign it.
+ if test -n "$prev"; then
+ case "$prev" in
+ output)
+ compile_command="$compile_command @OUTPUT@"
+ finalize_command="$finalize_command @OUTPUT@"
+ ;;
+ esac
+
+ case "$prev" in
+ dlfiles|dlprefiles)
+ case "$arg" in
+ *.la | *.lo) ;; # We handle these cases below.
+ *)
+ dlprefiles="$dlprefiles $arg"
+ test "$prev" = dlfiles && dlfiles="$dlfiles $arg"
+ prev=
+ ;;
+ esac
+ ;;
+ release)
+ release="-$arg"
+ prev=
+ continue
+ ;;
+ rpath)
+ rpath="$rpath $arg"
+ prev=
+ continue
+ ;;
+ *)
+ eval "$prev=\"\$arg\""
+ prev=
+ continue
+ ;;
+ esac
+ fi
+
+ prevarg="$arg"
+
+ case "$arg" in
+ -all-static)
+ if test -n "$link_static_flag"; then
+ compile_command="$compile_command $link_static_flag"
+ finalize_command="$finalize_command $link_static_flag"
+ fi
+ continue
+ ;;
+
+ -allow-undefined)
+ # FIXME: remove this flag sometime in the future.
+ $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2
+ continue
+ ;;
+
+ -dlopen)
+ prev=dlfiles
+ continue
+ ;;
+
+ -dlpreopen)
+ prev=dlprefiles
+ continue
+ ;;
+
+ -export-dynamic)
+ if test "$export_dynamic" != yes; then
+ export_dynamic=yes
+ if test -n "$export_dynamic_flag_spec"; then
+ eval arg=\"$export_dynamic_flag_spec\"
+ else
+ arg=
+ fi
+
+ # Add the symbol object into the linking commands.
+ compile_command="$compile_command @SYMFILE@"
+ finalize_command="$finalize_command @SYMFILE@"
+ fi
+ ;;
+
+ -L*)
+ dir=`$echo "X$arg" | $Xsed -e 's%^-L\(.*\)$%\1%'`
+ case "$dir" in
+ /* | [A-Za-z]:\\*)
+ # Add the corresponding hardcode_libdir_flag, if it is not identical.
+ ;;
+ *)
+ $echo "$modename: \`-L$dir' cannot specify a relative directory" 1>&2
+ exit 1
+ ;;
+ esac
+ deplibs="$deplibs $arg"
+ ;;
+
+ -l*) deplibs="$deplibs $arg" ;;
+
+ -no-undefined)
+ allow_undefined=no
+ continue
+ ;;
+
+ -o) prev=output ;;
+
+ -release)
+ prev=release
+ continue
+ ;;
+
+ -rpath)
+ prev=rpath
+ continue
+ ;;
+
+ -static)
+ # If we have no pic_flag, then this is the same as -all-static.
+ if test -z "$pic_flag" && test -n "$link_static_flag"; then
+ compile_command="$compile_command $link_static_flag"
+ finalize_command="$finalize_command $link_static_flag"
+ fi
+ continue
+ ;;
+
+ -version-info)
+ prev=vinfo
+ continue
+ ;;
+
+ # Some other compiler flag.
+ -* | +*)
+ # Unknown arguments in both finalize_command and compile_command need
+ # to be aesthetically quoted because they are evaled later.
+ arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
+ case "$arg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ arg="\"$arg\""
+ ;;
+ esac
+ ;;
+
+ *.o | *.a)
+ # A standard object.
+ objs="$objs $arg"
+ ;;
+
+ *.lo)
+ # A library object.
+ if test "$prev" = dlfiles; then
+ dlfiles="$dlfiles $arg"
+ if test "$build_libtool_libs" = yes; then
+ prev=
+ continue
+ else
+ # If libtool objects are unsupported, then we need to preload.
+ prev=dlprefiles
+ fi
+ fi
+
+ if test "$prev" = dlprefiles; then
+ # Preload the old-style object.
+ dlprefiles="$dlprefiles "`$echo "X$arg" | $Xsed -e 's/\.lo$/\.o/'`
+ prev=
+ fi
+ libobjs="$libobjs $arg"
+ ;;
+
+ *.la)
+ # A libtool-controlled library.
+
+ dlname=
+ libdir=
+ library_names=
+ old_library=
+
+ # Check to see that this really is a libtool archive.
+ if (sed -e '2q' $arg | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then :
+ else
+ $echo "$modename: \`$arg' is not a valid libtool archive" 1>&2
+ exit 1
+ fi
+
+ # If there is no directory component, then add one.
+ case "$arg" in
+ */* | *\\*) . $arg ;;
+ *) . ./$arg ;;
+ esac
+
+ if test -z "$libdir"; then
+ $echo "$modename: \`$arg' contains no -rpath information" 1>&2
+ exit 1
+ fi
+
+ # Get the name of the library we link against.
+ linklib=
+ for l in $old_library $library_names; do
+ linklib="$l"
+ done
+
+ if test -z "$linklib"; then
+ $echo "$modename: cannot find name of link library for \`$arg'" 1>&2
+ exit 1
+ fi
+
+ # Find the relevant object directory and library name.
+ name=`$echo "X$arg" | $Xsed -e 's%^.*/%%' -e 's/\.la$//' -e 's/^lib//'`
+ dir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
+ if test "X$dir" = "X$arg"; then
+ dir="$objdir"
+ else
+ dir="$dir/$objdir"
+ fi
+
+ # This library was specified with -dlopen.
+ if test "$prev" = dlfiles; then
+ dlfiles="$dlfiles $arg"
+ if test -z "$dlname"; then
+ # If there is no dlname, we need to preload.
+ prev=dlprefiles
+ else
+ # We should not create a dependency on this library, but we
+ # may need any libraries it requires.
+ compile_command="$compile_command$dependency_libs"
+ finalize_command="$finalize_command$dependency_libs"
+ prev=
+ continue
+ fi
+ fi
+
+ # The library was specified with -dlpreopen.
+ if test "$prev" = dlprefiles; then
+ # Prefer using a static library (so that no silly _DYNAMIC symbols
+ # are required to link).
+ if test -n "$old_library"; then
+ dlprefiles="$dlprefiles $dir/$old_library"
+ else
+ dlprefiles="$dlprefiles $dir/$linklib"
+ fi
+ prev=
+ fi
+
+ if test "$build_libtool_libs" = yes && test -n "$library_names"; then
+ link_against_libtool_libs="$link_against_libtool_libs $arg"
+ if test -n "$shlibpath_var"; then
+ # Make sure the rpath contains only unique directories.
+ case "$temp_rpath " in
+ *" $dir "*) ;;
+ *) temp_rpath="$temp_rpath $dir" ;;
+ esac
+ fi
+
+ # This is the magic to use -rpath.
+ if test -n "$hardcode_libdir_flag_spec"; then
+ if test -n "$hardcode_libdir_separator"; then
+ if test -z "$hardcode_libdirs"; then
+ # Put the magic libdir with the hardcode flag.
+ hardcode_libdirs="$libdir"
+ libdir="@HARDCODE_LIBDIRS@"
+ else
+ # Just accumulate the unique libdirs.
+ case "$hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator" in
+ *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+ ;;
+ *)
+ hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+ ;;
+ esac
+ libdir=
+ fi
+ fi
+
+ if test -n "$libdir"; then
+ eval flag=\"$hardcode_libdir_flag_spec\"
+
+ compile_command="$compile_command $flag"
+ finalize_command="$finalize_command $flag"
+ fi
+ elif test -n "$runpath_var"; then
+ # Do the same for the permanent run path.
+ case "$perm_rpath " in
+ *" $libdir "*) ;;
+ *) perm_rpath="$perm_rpath $libdir" ;;
+ esac
+ fi
+
+
+ case "$hardcode_action" in
+ immediate)
+ if test "$hardcode_direct" = no; then
+ compile_command="$compile_command $dir/$linklib"
+ elif test "$hardcode_minus_L" = no; then
+ compile_command="$compile_command -L$dir -l$name"
+ elif test "$hardcode_shlibpath_var" = no; then
+ compile_shlibpath="$compile_shlibpath$dir:"
+ compile_command="$compile_command -l$name"
+ fi
+ ;;
+
+ relink)
+ # We need an absolute path.
+ case "$dir" in
+ /* | [A-Za-z]:\\*) ;;
+ *)
+ absdir=`cd "$dir" && pwd`
+ if test -z "$absdir"; then
+ $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
+ exit 1
+ fi
+ dir="$absdir"
+ ;;
+ esac
+
+ if test "$hardcode_direct" = yes; then
+ compile_command="$compile_command $dir/$linklib"
+ elif test "$hardcode_minus_L" = yes; then
+ compile_command="$compile_command -L$dir -l$name"
+ elif test "$hardcode_shlibpath_var" = yes; then
+ compile_shlibpath="$compile_shlibpath$dir:"
+ compile_command="$compile_command -l$name"
+ fi
+ ;;
+
+ *)
+ $echo "$modename: \`$hardcode_action' is an unknown hardcode action" 1>&2
+ exit 1
+ ;;
+ esac
+
+ # Finalize command for both is simple: just hardcode it.
+ if test "$hardcode_direct" = yes; then
+ finalize_command="$finalize_command $libdir/$linklib"
+ elif test "$hardcode_minus_L" = yes; then
+ finalize_command="$finalize_command -L$libdir -l$name"
+ elif test "$hardcode_shlibpath_var" = yes; then
+ finalize_shlibpath="$finalize_shlibpath$libdir:"
+ finalize_command="$finalize_command -l$name"
+ else
+ # We cannot seem to hardcode it, guess we'll fake it.
+ finalize_command="$finalize_command -L$libdir -l$name"
+ fi
+ else
+ # Transform directly to old archives if we don't build new libraries.
+ if test -n "$pic_flag" && test -z "$old_library"; then
+ $echo "$modename: cannot find static library for \`$arg'" 1>&2
+ exit 1
+ fi
+
+ # Here we assume that one of hardcode_direct or hardcode_minus_L
+ # is not unsupported. This is valid on all known static and
+ # shared platforms.
+ if test "$hardcode_direct" != unsupported; then
+ test -n "$old_library" && linklib="$old_library"
+ compile_command="$compile_command $dir/$linklib"
+ finalize_command="$finalize_command $dir/$linklib"
+ else
+ compile_command="$compile_command -L$dir -l$name"
+ finalize_command="$finalize_command -L$dir -l$name"
+ fi
+ fi
+
+ # Add in any libraries that this one depends upon.
+ compile_command="$compile_command$dependency_libs"
+ finalize_command="$finalize_command$dependency_libs"
+ continue
+ ;;
+
+ # Some other compiler argument.
+ *)
+ # Unknown arguments in both finalize_command and compile_command need
+ # to be aesthetically quoted because they are evaled later.
+ arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
+ case "$arg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ arg="\"$arg\""
+ ;;
+ esac
+ ;;
+ esac
+
+ # Now actually substitute the argument into the commands.
+ if test -n "$arg"; then
+ compile_command="$compile_command $arg"
+ finalize_command="$finalize_command $arg"
+ fi
+ done
+
+ if test -n "$prev"; then
+ $echo "$modename: the \`$prevarg' option requires an argument" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ if test -n "$vinfo" && test -n "$release"; then
+ $echo "$modename: you cannot specify both \`-version-info' and \`-release'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ oldlib=
+ oldobjs=
+ case "$output" in
+ "")
+ $echo "$modename: you must specify an output file" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+
+ */* | *\\*)
+ $echo "$modename: output file \`$output' must have no directory components" 1>&2
+ exit 1
+ ;;
+
+ *.a)
+ # Now set the variables for building old libraries.
+ build_libtool_libs=no
+ build_old_libs=yes
+ oldlib="$output"
+ $show "$rm $oldlib"
+ $run $rm $oldlib
+ ;;
+
+ *.la)
+ # Make sure we only generate libraries of the form `libNAME.la'.
+ case "$output" in
+ lib*) ;;
+ *)
+ $echo "$modename: libtool library \`$arg' must begin with \`lib'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+ esac
+
+ name=`$echo "X$output" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
+ eval libname=\"$libname_spec\"
+
+ # All the library-specific variables (install_libdir is set above).
+ library_names=
+ old_library=
+ dlname=
+ current=0
+ revision=0
+ age=0
+
+ if test -n "$objs"; then
+ $echo "$modename: cannot build libtool library \`$output' from non-libtool objects:$objs" 2>&1
+ exit 1
+ fi
+
+ # How the heck are we supposed to write a wrapper for a shared library?
+ if test -n "$link_against_libtool_libs"; then
+ $echo "$modename: libtool library \`$output' may not depend on uninstalled libraries:$link_against_libtool_libs" 1>&2
+ exit 1
+ fi
+
+ if test -n "$dlfiles$dlprefiles"; then
+ $echo "$modename: warning: \`-dlopen' is ignored while creating libtool libraries" 1>&2
+ # Nullify the symbol file.
+ compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+ fi
+
+ if test -z "$rpath"; then
+ $echo "$modename: you must specify an installation directory with \`-rpath'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ set dummy $rpath
+ if test $# -gt 2; then
+ $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2
+ fi
+ install_libdir="$2"
+
+ # Parse the version information argument.
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=':'
+ set dummy $vinfo
+ IFS="$save_ifs"
+
+ if test -n "$5"; then
+ $echo "$modename: too many parameters to \`-version-info'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ test -n "$2" && current="$2"
+ test -n "$3" && revision="$3"
+ test -n "$4" && age="$4"
+
+ # Check that each of the things are valid numbers.
+ case "$current" in
+ 0 | [1-9] | [1-9][0-9]*) ;;
+ *)
+ $echo "$modename: CURRENT \`$current' is not a nonnegative integer" 1>&2
+ $echo "$modename: \`$vinfo' is not valid version information" 1>&2
+ exit 1
+ ;;
+ esac
+
+ case "$revision" in
+ 0 | [1-9] | [1-9][0-9]*) ;;
+ *)
+ $echo "$modename: REVISION \`$revision' is not a nonnegative integer" 1>&2
+ $echo "$modename: \`$vinfo' is not valid version information" 1>&2
+ exit 1
+ ;;
+ esac
+
+ case "$age" in
+ 0 | [1-9] | [1-9][0-9]*) ;;
+ *)
+ $echo "$modename: AGE \`$age' is not a nonnegative integer" 1>&2
+ $echo "$modename: \`$vinfo' is not valid version information" 1>&2
+ exit 1
+ ;;
+ esac
+
+ if test $age -gt $current; then
+ $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2
+ $echo "$modename: \`$vinfo' is not valid version information" 1>&2
+ exit 1
+ fi
+
+ # Calculate the version variables.
+ version_vars="version_type current age revision"
+ case "$version_type" in
+ none) ;;
+
+ linux)
+ version_vars="$version_vars major versuffix"
+ major=`expr $current - $age`
+ versuffix="$major.$age.$revision"
+ ;;
+
+ osf)
+ version_vars="$version_vars versuffix verstring"
+ major=`expr $current - $age`
+ versuffix="$current.$age.$revision"
+ verstring="$versuffix"
+
+ # Add in all the interfaces that we are compatible with.
+ loop=$age
+ while test $loop != 0; do
+ iface=`expr $current - $loop`
+ loop=`expr $loop - 1`
+ verstring="$verstring:${iface}.0"
+ done
+
+ # Make executables depend on our current version.
+ verstring="$verstring:${current}.0"
+ ;;
+
+ sunos)
+ version_vars="$version_vars major versuffix"
+ major="$current"
+ versuffix="$current.$revision"
+ ;;
+
+ *)
+ $echo "$modename: unknown library version type \`$version_type'" 1>&2
+ echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2
+ exit 1
+ ;;
+ esac
+
+ # Create the output directory, or remove our outputs if we need to.
+ if test -d $objdir; then
+ $show "$rm $objdir/$output $objdir/$libname.* $objdir/${libname}${release}.*"
+ $run $rm $objdir/$output $objdir/$libname.* $objdir/${libname}${release}.*
+ else
+ $show "$mkdir $objdir"
+ $run $mkdir $objdir
+ status=$?
+ if test $status -eq 0 || test -d $objdir; then :
+ else
+ exit $status
+ fi
+ fi
+
+ # Check to see if the archive will have undefined symbols.
+ if test "$allow_undefined" = yes; then
+ if test "$allow_undefined_flag" = unsupported; then
+ $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2
+ build_libtool_libs=no
+ build_old_libs=yes
+ fi
+ else
+ # Don't allow undefined symbols.
+ allow_undefined_flag="$no_undefined_flag"
+ fi
+
+ # Add libc to deplibs on all systems.
+ dependency_libs="$deplibs"
+ deplibs="$deplibs -lc"
+
+ if test "$build_libtool_libs" = yes; then
+ # Get the real and link names of the library.
+ eval library_names=\"$library_names_spec\"
+ set dummy $library_names
+ realname="$2"
+ shift; shift
+
+ if test -n "$soname_spec"; then
+ eval soname=\"$soname_spec\"
+ else
+ soname="$realname"
+ fi
+
+ lib="$objdir/$realname"
+ for link
+ do
+ linknames="$linknames $link"
+ done
+
+ # Use standard objects if they are PIC.
+ test -z "$pic_flag" && libobjs=`$echo "X$libobjs " | $Xsed -e 's/\.lo /.o /g' -e 's/ $//g'`
+
+ # Do each of the archive commands.
+ eval cmds=\"$archive_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+
+ # Create links to the real library.
+ for linkname in $linknames; do
+ $show "(cd $objdir && $LN_S $realname $linkname)"
+ $run eval '(cd $objdir && $LN_S $realname $linkname)' || exit $?
+ done
+
+ # If -export-dynamic was specified, set the dlname.
+ if test "$export_dynamic" = yes; then
+ # On all known operating systems, these are identical.
+ dlname="$soname"
+ fi
+ fi
+
+ # Now set the variables for building old libraries.
+ oldlib="$objdir/$libname.a"
+ ;;
+
+ *.lo | *.o)
+ if test -n "$link_against_libtool_libs"; then
+ $echo "$modename: error: cannot link libtool libraries into reloadable objects" 1>&2
+ exit 1
+ fi
+
+ if test -n "$deplibs"; then
+ $echo "$modename: warning: \`-l' and \`-L' are ignored while creating objects" 1>&2
+ fi
+
+ if test -n "$dlfiles$dlprefiles"; then
+ $echo "$modename: warning: \`-dlopen' is ignored while creating objects" 1>&2
+ # Nullify the symbol file.
+ compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+ fi
+
+ if test -n "$rpath"; then
+ $echo "$modename: warning: \`-rpath' is ignored while creating objects" 1>&2
+ fi
+
+ if test -n "$vinfo"; then
+ $echo "$modename: warning: \`-version-info' is ignored while creating objects" 1>&2
+ fi
+
+ if test -n "$release"; then
+ $echo "$modename: warning: \`-release' is ignored while creating objects" 1>&2
+ fi
+
+ case "$output" in
+ *.lo)
+ if test -n "$objs"; then
+ $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2
+ exit 1
+ fi
+ libobj="$output"
+ obj=`$echo "X$output" | $Xsed -e 's/\.lo$/.o/'`
+ ;;
+ *)
+ libobj=
+ obj="$output"
+ ;;
+ esac
+
+ # Delete the old objects.
+ $run $rm $obj $libobj
+
+ # Create the old-style object.
+ reload_objs="$objs"`$echo "X$libobjs " | $Xsed -e 's/[^ ]*\.a //g' -e 's/\.lo /.o /g' -e 's/ $//g'`
+
+ output="$obj"
+ eval cmds=\"$reload_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+
+ # Exit if we aren't doing a library object file.
+ test -z "$libobj" && exit 0
+
+ if test "$build_libtool_libs" != yes; then
+ # Create an invalid libtool object if no PIC, so that we don't
+ # accidentally link it into a program.
+ $show "echo timestamp > $libobj"
+ $run eval "echo timestamp > $libobj" || exit $?
+ exit 0
+ fi
+
+ if test -n "$pic_flag"; then
+ # Only do commands if we really have different PIC objects.
+ reload_objs="$libobjs"
+ output="$libobj"
+ eval cmds=\"$reload_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+ else
+ # Just create a symlink.
+ $show "$LN_S $obj $libobj"
+ $run $LN_S $obj $libobj || exit 1
+ fi
+
+ exit 0
+ ;;
+
+ *)
+ if test -n "$vinfo"; then
+ $echo "$modename: warning: \`-version-info' is ignored while linking programs" 1>&2
+ fi
+
+ if test -n "$release"; then
+ $echo "$modename: warning: \`-release' is ignored while creating objects" 1>&2
+ fi
+
+ if test -n "$rpath"; then
+ # If the user specified any rpath flags, then add them.
+ for libdir in $rpath; do
+ if test -n "$hardcode_libdir_flag_spec"; then
+ if test -n "$hardcode_libdir_separator"; then
+ if test -z "$hardcode_libdirs"; then
+ # Put the magic libdir with the hardcode flag.
+ hardcode_libdirs="$libdir"
+ libdir="@HARDCODE_LIBDIRS@"
+ else
+ # Just accumulate the unique libdirs.
+ case "$hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator" in
+ *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+ ;;
+ *)
+ hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+ ;;
+ esac
+ libdir=
+ fi
+ fi
+
+ if test -n "$libdir"; then
+ eval flag=\"$hardcode_libdir_flag_spec\"
+
+ compile_command="$compile_command $flag"
+ finalize_command="$finalize_command $flag"
+ fi
+ elif test -n "$runpath_var"; then
+ case "$perm_rpath " in
+ *" $libdir "*) ;;
+ *) perm_rpath="$perm_rpath $libdir" ;;
+ esac
+ fi
+ done
+ fi
+
+ # Substitute the hardcoded libdirs into the compile commands.
+ if test -n "$hardcode_libdir_separator"; then
+ compile_command=`$echo "X$compile_command" | $Xsed -e "s%@HARDCODE_LIBDIRS@%$hardcode_libdirs%g"`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@HARDCODE_LIBDIRS@%$hardcode_libdirs%g"`
+ fi
+
+ if test -n "$libobjs" && test "$build_old_libs" = yes; then
+ # Transform all the library objects into standard objects.
+ compile_command=`$echo "X$compile_command " | $Xsed -e 's/\.lo /.o /g' -e 's/ $//'`
+ finalize_command=`$echo "X$finalize_command " | $Xsed -e 's/\.lo /.o /g' -e 's/ $//'`
+ fi
+
+ if test "$export_dynamic" = yes && test -n "$NM" && test -n "$global_symbol_pipe"; then
+ dlsyms="${output}S.c"
+ else
+ dlsyms=
+ fi
+
+ if test -n "$dlsyms"; then
+ # Add our own program objects to the preloaded list.
+ dlprefiles=`$echo "X$objs$dlprefiles " | $Xsed -e 's/\.lo /.o /g' -e 's/ $//'`
+
+ # Discover the nlist of each of the dlfiles.
+ nlist="$objdir/${output}.nm"
+
+ if test -d $objdir; then
+ $show "$rm $nlist ${nlist}T"
+ $run $rm "$nlist" "${nlist}T"
+ else
+ $show "$mkdir $objdir"
+ $run $mkdir $objdir
+ status=$?
+ if test $status -eq 0 || test -d $objdir; then :
+ else
+ exit $status
+ fi
+ fi
+
+ for arg in $dlprefiles; do
+ $show "extracting global C symbols from \`$arg'"
+ $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'"
+ done
+
+ # Parse the name list into a source file.
+ $show "creating $objdir/$dlsyms"
+ if test -z "$run"; then
+ # Make sure we at least have an empty file.
+ test -f "$nlist" || : > "$nlist"
+
+ # Try sorting and uniquifying the output.
+ if sort "$nlist" | uniq > "$nlist"T; then
+ mv -f "$nlist"T "$nlist"
+ wcout=`wc "$nlist" 2>/dev/null`
+ count=`echo "X$wcout" | $Xsed -e 's/^[ ]*\([0-9][0-9]*\).*$/\1/'`
+ (test "$count" -ge 0) 2>/dev/null || count=-1
+ else
+ $rm "$nlist"T
+ count=-1
+ fi
+
+ case "$dlsyms" in
+ "") ;;
+ *.c)
+ $echo > "$objdir/$dlsyms" "\
+/* $dlsyms - symbol resolution table for \`$output' dlsym emulation. */
+/* Generated by $PROGRAM - GNU $PACKAGE $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+/* Prevent the only kind of declaration conflicts we can make. */
+#define dld_preloaded_symbol_count some_other_symbol
+#define dld_preloaded_symbols some_other_symbol
+
+/* External symbol declarations for the compiler. */\
+"
+
+ if test -f "$nlist"; then
+ sed -e 's/^.* \(.*\)$/extern char \1;/' < "$nlist" >> "$objdir/$dlsyms"
+ else
+ echo '/* NONE */' >> "$objdir/$dlsyms"
+ fi
+
+ $echo >> "$objdir/$dlsyms" "\
+
+#undef dld_preloaded_symbol_count
+#undef dld_preloaded_symbols
+
+#if defined (__STDC__) && __STDC__
+# define __ptr_t void *
+#else
+# define __ptr_t char *
+#endif
+
+/* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */
+int dld_preloaded_symbol_count = $count;
+
+/* The mapping between symbol names and symbols. */
+struct {
+ char *name;
+ __ptr_t address;
+}
+dld_preloaded_symbols[] =
+{\
+"
+
+ if test -f "$nlist"; then
+ sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$nlist" >> "$objdir/$dlsyms"
+ fi
+
+ $echo >> "$objdir/$dlsyms" "\
+ {0, (__ptr_t) 0}
+};
+
+#ifdef __cplusplus
+}
+#endif\
+"
+ ;;
+
+ *)
+ $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2
+ exit 1
+ ;;
+ esac
+ fi
+
+ # Now compile the dynamic symbol file.
+ $show "(cd $objdir && $CC -c$no_builtin_flag \"$dlsyms\")"
+ $run eval '(cd $objdir && $CC -c$no_builtin_flag "$dlsyms")' || exit $?
+
+ # Transform the symbol file into the correct name.
+ compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$objdir/${output}S.o%"`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$objdir/${output}S.o%"`
+ elif test "$export_dynamic" != yes; then
+ test -n "$dlfiles$dlprefiles" && $echo "$modename: warning: \`-dlopen' and \`-dlpreopen' are ignored without \`-export-dynamic'" 1>&2
+ else
+ # We keep going just in case the user didn't refer to
+ # dld_preloaded_symbols. The linker will fail if global_symbol_pipe
+ # really was required.
+ $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2
+
+ # Nullify the symbol file.
+ compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+ fi
+
+ if test -z "$link_against_libtool_libs" || test "$build_libtool_libs" != yes; then
+ # Replace the output file specification.
+ compile_command=`$echo "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+
+ # We have no uninstalled library dependencies, so finalize right now.
+ $show "$compile_command"
+ $run eval "$compile_command"
+ exit $?
+ fi
+
+ # Replace the output file specification.
+ compile_command=`$echo "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$objdir/$output"'%g'`
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e 's%@OUTPUT@%'"$objdir/$output"'T%g'`
+
+ # Create the binary in the object directory, then wrap it.
+ if test -d $objdir; then :
+ else
+ $show "$mkdir $objdir"
+ $run $mkdir $objdir
+ status=$?
+ if test $status -eq 0 || test -d $objdir; then :
+ else
+ exit $status
+ fi
+ fi
+
+ if test -n "$shlibpath_var"; then
+ # We should set the shlibpath_var
+ rpath=
+ for dir in $temp_rpath; do
+ case "$dir" in
+ /* | [A-Za-z]:\\*)
+ # Absolute path.
+ rpath="$rpath$dir:"
+ ;;
+ *)
+ # Relative path: add a thisdir entry.
+ rpath="$rpath\$thisdir/$dir:"
+ ;;
+ esac
+ done
+ temp_rpath="$rpath"
+ fi
+
+ # Delete the old output file.
+ $run $rm $output
+
+ if test -n "$compile_shlibpath"; then
+ compile_command="$shlibpath_var=\"$compile_shlibpath\$$shlibpath_var\" $compile_command"
+ fi
+ if test -n "$finalize_shlibpath"; then
+ finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+ fi
+
+ if test -n "$runpath_var" && test -n "$perm_rpath"; then
+ # We should set the runpath_var.
+ rpath=
+ for dir in $perm_rpath; do
+ rpath="$rpath$dir:"
+ done
+ compile_command="$runpath_var=\"$rpath\$$runpath_var\" $compile_command"
+ finalize_command="$runpath_var=\"$rpath\$$runpath_var\" $finalize_command"
+ fi
+
+ case "$hardcode_action" in
+ relink)
+ # AGH! Flame the AIX and HP-UX people for me, will ya?
+ $echo "$modename: warning: using a buggy system linker" 1>&2
+ $echo "$modename: relinking will be required before \`$output' can be installed" 1>&2
+ ;;
+ esac
+
+ $show "$compile_command"
+ $run eval "$compile_command" || exit $?
+
+ # Now create the wrapper script.
+ $show "creating $output"
+
+ # Quote the finalize command for shipping.
+ finalize_command=`$echo "X$finalize_command" | $Xsed -e "$sed_quote_subst"`
+
+ # Quote $echo for shipping.
+ qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"`
+
+ # Only actually do things if our run command is non-null.
+ if test -z "$run"; then
+ $rm $output
+ trap "$rm $output; exit 1" 1 2 15
+
+ $echo > $output "\
+#! /bin/sh
+
+# $output - temporary wrapper script for $objdir/$output
+# Generated by ltmain.sh - GNU $PACKAGE $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of \``pwd`'.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='sed -e s/^X//'
+sed_quote_subst='$sed_quote_subst'
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+if test \"\${CDPATH+set}\" = set; then CDPATH=; export CDPATH; fi
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+ # install mode needs the following variables:
+ link_against_libtool_libs='$link_against_libtool_libs'
+ finalize_command=\"$finalize_command\"
+else
+ # When we are sourced in execute mode, \$file and \$echo are already set.
+ if test \"\$libtool_execute_magic\" = \"$magic\"; then :
+ else
+ echo=\"$qecho\"
+ file=\"\$0\"
+ fi\
+"
+ $echo >> $output "\
+
+ # Find the directory that this script lives in.
+ thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
+ test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=\`ls -ld \"\$file\" | sed -n 's/.*-> //p'\`
+ while test -n \"\$file\"; do
+ destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
+
+ # If there was a directory component, then change thisdir.
+ if test \"x\$destdir\" != \"x\$file\"; then
+ case \"\$destdir\" in
+ /* | [A-Za-z]:\\*) thisdir=\"\$destdir\" ;;
+ *) thisdir=\"\$thisdir/\$destdir\" ;;
+ esac
+ fi
+
+ file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
+ file=\`ls -ld \"\$thisdir/\$file\" | sed -n 's/.*-> //p'\`
+ done
+
+ # Try to get the absolute directory name.
+ absdir=\`cd \"\$thisdir\" && pwd\`
+ test -n \"\$absdir\" && thisdir=\"\$absdir\"
+
+ progdir=\"\$thisdir/$objdir\"
+ program='$output'
+
+ if test -f \"\$progdir/\$program\"; then"
+
+ # Export our shlibpath_var if we have one.
+ if test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+ $echo >> $output "\
+ # Add our own library path to $shlibpath_var
+ $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+ # Some systems cannot cope with colon-terminated $shlibpath_var
+ $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/:*\$//'\`
+
+ export $shlibpath_var
+"
+ fi
+
+ $echo >> $output "\
+ if test \"\$libtool_execute_magic\" != \"$magic\"; then
+ # Run the actual program with our arguments.
+
+ # Export the path to the program.
+ PATH=\"\$progdir:\$PATH\"
+ export PATH
+
+ exec \$program \${1+\"\$@\"}
+
+ \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\"
+ exit 1
+ fi
+ else
+ # The program doesn't exist.
+ \$echo \"\$0: error: \$progdir/\$program does not exist\" 1>&2
+ \$echo \"This script is just a wrapper for \$program.\" 1>&2
+ echo \"See the $PACKAGE documentation for more information.\" 1>&2
+ exit 1
+ fi
+fi\
+"
+ chmod +x $output
+ fi
+ exit 0
+ ;;
+ esac
+
+ # See if we need to build an old-fashioned archive.
+ if test "$build_old_libs" = "yes"; then
+ # Transform .lo files to .o files.
+ oldobjs="$objs"`$echo "X$libobjs " | $Xsed -e 's/[^ ]*\.a //g' -e 's/\.lo /.o /g' -e 's/ $//g'`
+
+ # Do each command in the archive commands.
+ if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
+ eval cmds=\"$old_archive_from_new_cmds\"
+ else
+ eval cmds=\"$old_archive_cmds\"
+ fi
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+ fi
+
+ # Now create the libtool archive.
+ case "$output" in
+ *.la)
+ old_library=
+ test "$build_old_libs" = yes && old_library="$libname.a"
+
+ $show "creating $output"
+
+ # Only create the output if not a dry run.
+ if test -z "$run"; then
+ $echo > $output "\
+# $output - a libtool library file
+# Generated by ltmain.sh - GNU $PACKAGE $VERSION
+
+# The name that we can dlopen(3).
+dlname='$dlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'\
+"
+ fi
+
+ # Do a symbolic link so that the libtool archive can be found in
+ # LD_LIBRARY_PATH before the program is installed.
+ $show "(cd $objdir && $LN_S ../$output $output)"
+ $run eval "(cd $objdir && $LN_S ../$output $output)" || exit 1
+ ;;
+ esac
+ exit 0
+ ;;
+
+ # libtool install mode
+ install)
+ modename="$modename: install"
+
+ # There may be an optional /bin/sh argument at the beginning of
+ # install_prog (especially on Windows NT).
+ if test "$nonopt" = "$SHELL"; then
+ # Aesthetically quote it.
+ arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"`
+ case "$arg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ arg="\"$arg\""
+ ;;
+ esac
+ install_prog="$arg "
+ arg="$1"
+ shift
+ else
+ install_prog=
+ arg="$nonopt"
+ fi
+
+ # The real first argument should be the name of the installation program.
+ # Aesthetically quote it.
+ arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
+ case "$arg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ arg="\"$arg\""
+ ;;
+ esac
+ install_prog="$install_prog$arg"
+
+ # We need to accept at least all the BSD install flags.
+ dest=
+ files=
+ opts=
+ prev=
+ install_type=
+ isdir=
+ stripme=
+ for arg
+ do
+ if test -n "$dest"; then
+ files="$files $dest"
+ dest="$arg"
+ continue
+ fi
+
+ case "$arg" in
+ -d) isdir=yes ;;
+ -f) prev="-f" ;;
+ -g) prev="-g" ;;
+ -m) prev="-m" ;;
+ -o) prev="-o" ;;
+ -s)
+ stripme=" -s"
+ continue
+ ;;
+ -*) ;;
+
+ *)
+ # If the previous option needed an argument, then skip it.
+ if test -n "$prev"; then
+ prev=
+ else
+ dest="$arg"
+ continue
+ fi
+ ;;
+ esac
+
+ # Aesthetically quote the argument.
+ arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
+ case "$arg" in
+ *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*)
+ arg="\"$arg\""
+ ;;
+ esac
+ install_prog="$install_prog $arg"
+ done
+
+ if test -z "$install_prog"; then
+ $echo "$modename: you must specify an install program" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ if test -n "$prev"; then
+ $echo "$modename: the \`$prev' option requires an argument" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ if test -z "$files"; then
+ if test -z "$dest"; then
+ $echo "$modename: no file or destination specified" 1>&2
+ else
+ $echo "$modename: you must specify a destination" 1>&2
+ fi
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ # Strip any trailing slash from the destination.
+ dest=`$echo "X$dest" | $Xsed -e 's%/$%%'`
+
+ # Check to see that the destination is a directory.
+ test -d "$dest" && isdir=yes
+ if test -n "$isdir"; then
+ destdir="$dest"
+ destname=
+ else
+ destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'`
+ test "X$destdir" = "X$dest" && destdir=.
+ destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'`
+
+ # Not a directory, so check to see that there is only one file specified.
+ set dummy $files
+ if test $# -gt 2; then
+ $echo "$modename: \`$dest' is not a directory" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+ fi
+ case "$destdir" in
+ /* | [A-Za-z]:\\*) ;;
+ *)
+ for file in $files; do
+ case "$file" in
+ *.lo) ;;
+ *)
+ $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+ ;;
+ esac
+
+ # This variable tells wrapper scripts just to set variables rather
+ # than running their programs.
+ libtool_install_magic="$magic"
+
+ staticlibs=
+ future_libdirs=
+ current_libdirs=
+ for file in $files; do
+
+ # Do each installation.
+ case "$file" in
+ *.a)
+ # Do the static libraries later.
+ staticlibs="$staticlibs $file"
+ ;;
+
+ *.la)
+ # Check to see that this really is a libtool archive.
+ if (sed -e '2q' $file | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then :
+ else
+ $echo "$modename: \`$file' is not a valid libtool archive" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ library_names=
+ old_library=
+ # If there is no directory component, then add one.
+ case "$file" in
+ */* | *\\*) . $file ;;
+ *) . ./$file ;;
+ esac
+
+ # Add the libdir to current_libdirs if it is the destination.
+ if test "X$destdir" = "X$libdir"; then
+ case "$current_libdirs " in
+ *" $libdir "*) ;;
+ *) current_libdirs="$current_libdirs $libdir" ;;
+ esac
+ else
+ # Note the libdir as a future libdir.
+ case "$future_libdirs " in
+ *" $libdir "*) ;;
+ *) future_libdirs="$future_libdirs $libdir" ;;
+ esac
+ fi
+
+ dir="`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/"
+ test "X$dir" = "X$file/" && dir=
+ dir="$dir$objdir"
+
+ # See the names of the shared library.
+ set dummy $library_names
+ if test -n "$2"; then
+ realname="$2"
+ shift
+ shift
+
+ # Install the shared library and build the symlinks.
+ $show "$install_prog $dir/$realname $destdir/$realname"
+ $run eval "$install_prog $dir/$realname $destdir/$realname" || exit $?
+ test "X$dlname" = "X$realname" && dlname=
+
+ if test $# -gt 0; then
+ # Delete the old symlinks.
+ rmcmd="$rm"
+ for linkname
+ do
+ rmcmd="$rmcmd $destdir/$linkname"
+ done
+ $show "$rmcmd"
+ $run $rmcmd
+
+ # ... and create new ones.
+ for linkname
+ do
+ test "X$dlname" = "X$linkname" && dlname=
+ $show "(cd $destdir && $LN_S $realname $linkname)"
+ $run eval "(cd $destdir && $LN_S $realname $linkname)"
+ done
+ fi
+
+ if test -n "$dlname"; then
+ # Install the dynamically-loadable library.
+ $show "$install_prog $dir/$dlname $destdir/$dlname"
+ $run eval "$install_prog $dir/$dlname $destdir/$dlname" || exit $?
+ fi
+
+ # Do each command in the postinstall commands.
+ lib="$destdir/$realname"
+ eval cmds=\"$postinstall_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+ fi
+
+ # Install the pseudo-library for information purposes.
+ name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
+ $show "$install_prog $file $destdir/$name"
+ $run eval "$install_prog $file $destdir/$name" || exit $?
+
+ # Maybe install the static library, too.
+ test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
+ ;;
+
+ *.lo)
+ # Install (i.e. copy) a libtool object.
+
+ # Figure out destination file name, if it wasn't already specified.
+ if test -n "$destname"; then
+ destfile="$destdir/$destname"
+ else
+ destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
+ destfile="$destdir/$destfile"
+ fi
+
+ # Deduce the name of the destination old-style object file.
+ case "$destfile" in
+ *.lo)
+ staticdest=`$echo "X$destfile" | $Xsed -e 's/\.lo$/\.o/'`
+ ;;
+ *.o)
+ staticdest="$destfile"
+ destfile=
+ ;;
+ *)
+ $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+ esac
+
+ # Install the libtool object if requested.
+ if test -n "$destfile"; then
+ $show "$install_prog $file $destfile"
+ $run eval "$install_prog $file $destfile" || exit $?
+ fi
+
+ # Install the old object if enabled.
+ if test "$build_old_libs" = yes; then
+ # Deduce the name of the old-style object file.
+ staticobj=`$echo "X$file" | $Xsed -e 's/\.lo$/\.o/'`
+
+ $show "$install_prog $staticobj $staticdest"
+ $run eval "$install_prog \$staticobj \$staticdest" || exit $?
+ fi
+ exit 0
+ ;;
+
+ *)
+ # Do a test to see if this is really a libtool program.
+ if (sed -e '4q' $file | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then
+ link_against_libtool_libs=
+ finalize_command=
+
+ # If there is no directory component, then add one.
+ case "$file" in
+ */* | *\\*) . $file ;;
+ *) . ./$file ;;
+ esac
+
+ # Check the variables that should have been set.
+ if test -z "$link_against_libtool_libs" || test -z "$finalize_command"; then
+ $echo "$modename: invalid libtool wrapper script \`$file'" 1>&2
+ exit 1
+ fi
+
+ finalize=yes
+ for lib in $link_against_libtool_libs; do
+ # Check to see that each library is installed.
+ libdir=
+ if test -f "$lib"; then
+ # If there is no directory component, then add one.
+ case "$lib" in
+ */* | *\\*) . $lib ;;
+ *) . ./$lib ;;
+ esac
+ fi
+ libfile="$libdir/`$echo "X$lib" | $Xsed -e 's%^.*/%%g'`"
+ if test -z "$libdir"; then
+ $echo "$modename: warning: \`$lib' contains no -rpath information" 1>&2
+ elif test -f "$libfile"; then :
+ else
+ $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2
+ finalize=no
+ fi
+ done
+
+ if test "$hardcode_action" = relink; then
+ if test "$finalize" = yes; then
+ $echo "$modename: warning: relinking \`$file' on behalf of your buggy system linker" 1>&2
+ $show "$finalize_command"
+ if $run eval "$finalize_command"; then :
+ else
+ $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2
+ continue
+ fi
+ file="$objdir/$file"T
+ else
+ $echo "$modename: warning: cannot relink \`$file' on behalf of your buggy system linker" 1>&2
+ fi
+ else
+ # Install the binary that we compiled earlier.
+ file=`$echo "X$file" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+ fi
+ fi
+
+ $show "$install_prog$stripme $file $dest"
+ $run eval "$install_prog\$stripme \$file \$dest" || exit $?
+ ;;
+ esac
+ done
+
+ for file in $staticlibs; do
+ name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
+
+ # Set up the ranlib parameters.
+ oldlib="$destdir/$name"
+
+ $show "$install_prog $file $oldlib"
+ $run eval "$install_prog \$file \$oldlib" || exit $?
+
+ # Do each command in the postinstall commands.
+ eval cmds=\"$old_postinstall_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd" || exit $?
+ done
+ IFS="$save_ifs"
+ done
+
+ if test -n "$future_libdirs"; then
+ $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2
+ fi
+
+ if test -n "$current_libdirs"; then
+ # Maybe just do a dry run.
+ test -n "$run" && current_libdirs=" -n$current_libdirs"
+ exec $SHELL $0 --finish$current_libdirs
+ exit 1
+ fi
+
+ exit 0
+ ;;
+
+ # libtool finish mode
+ finish)
+ modename="$modename: finish"
+ libdirs="$nonopt"
+
+ if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+ for dir
+ do
+ libdirs="$libdirs $dir"
+ done
+
+ for libdir in $libdirs; do
+ if test -n "$finish_cmds"; then
+ # Do each command in the finish commands.
+ eval cmds=\"$finish_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd"
+ done
+ IFS="$save_ifs"
+ fi
+ if test -n "$finish_eval"; then
+ # Do the single finish_eval.
+ eval cmds=\"$finish_eval\"
+ $run eval "$cmds"
+ fi
+ done
+ fi
+
+ echo "------------------------------------------------------------------------------"
+ echo "Libraries have been installed in:"
+ for libdir in $libdirs; do
+ echo " $libdir"
+ done
+ echo
+ echo "To link against installed libraries in a given directory, LIBDIR,"
+ echo "you must use the \`-LLIBDIR' flag during linking."
+ echo
+ echo " You will also need to do one of the following:"
+ if test -n "$shlibpath_var"; then
+ echo " - add LIBDIR to the \`$shlibpath_var' environment variable"
+ echo " during execution"
+ fi
+ if test -n "$runpath_var"; then
+ echo " - add LIBDIR to the \`$runpath_var' environment variable"
+ echo " during linking"
+ fi
+ if test -n "$hardcode_libdir_flag_spec"; then
+ libdir=LIBDIR
+ eval flag=\"$hardcode_libdir_flag_spec\"
+
+ echo " - use the \`$flag' linker flag"
+ fi
+ if test -f /etc/ld.so.conf; then
+ echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+ fi
+ echo
+ echo "See any operating system documentation about shared libraries for"
+ echo "more information, such as the ld(1) and ld.so(8) manual pages."
+ echo "------------------------------------------------------------------------------"
+ exit 0
+ ;;
+
+ # libtool execute mode
+ execute)
+ modename="$modename: execute"
+
+ # The first argument is the command name.
+ cmd="$nonopt"
+ if test -z "$cmd"; then
+ $echo "$modename: you must specify a COMMAND" 1>&2
+ $echo "$help"
+ exit 1
+ fi
+
+ # Handle -dlopen flags immediately.
+ for file in $execute_dlfiles; do
+ if test -f "$file"; then :
+ else
+ $echo "$modename: \`$file' is not a file" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ dir=
+ case "$file" in
+ *.la)
+ # Check to see that this really is a libtool archive.
+ if (sed -e '2q' $file | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then :
+ else
+ $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ # Read the libtool library.
+ dlname=
+ library_names=
+
+ # If there is no directory component, then add one.
+ case "$file" in
+ */* | *\\*) . $file ;;
+ *) . ./$file ;;
+ esac
+
+ # Skip this library if it cannot be dlopened.
+ if test -z "$dlname"; then
+ # Warn if it was a shared library.
+ test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'"
+ continue
+ fi
+
+ dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
+ test "X$dir" = "X$file" && dir=.
+
+ if test -f "$dir/$objdir/$dlname"; then
+ dir="$dir/$objdir"
+ else
+ $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2
+ exit 1
+ fi
+ ;;
+
+ *.lo)
+ # Just add the directory containing the .lo file.
+ dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
+ test "X$dir" = "X$file" && dir=.
+ ;;
+
+ *)
+ $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2
+ continue
+ ;;
+ esac
+
+ # Get the absolute pathname.
+ absdir=`cd "$dir" && pwd`
+ test -n "$absdir" && dir="$absdir"
+
+ # Now add the directory to shlibpath_var.
+ if eval "test -z \"\$$shlibpath_var\""; then
+ eval "$shlibpath_var=\"\$dir\""
+ else
+ eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+ fi
+ done
+
+ # This variable tells wrapper scripts just to set shlibpath_var
+ # rather than running their programs.
+ libtool_execute_magic="$magic"
+
+ # Check if any of the arguments is a wrapper script.
+ args=
+ for file
+ do
+ case "$file" in
+ -*) ;;
+ *)
+ # Do a test to see if this is really a libtool program.
+ if (sed -e '4q' $file | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then
+ # If there is no directory component, then add one.
+ case "$file" in
+ */* | *\\*) . $file ;;
+ *) . ./$file ;;
+ esac
+
+ # Transform arg to wrapped name.
+ file="$progdir/$program"
+ fi
+ ;;
+ esac
+ # Quote arguments (to preserve shell metacharacters).
+ file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"`
+ args="$args \"$file\""
+ done
+
+ if test -z "$run"; then
+ # Export the shlibpath_var.
+ eval "export $shlibpath_var"
+
+ # Now actually exec the command.
+ eval "exec \$cmd$args"
+
+ $echo "$modename: cannot exec \$cmd$args"
+ exit 1
+ else
+ # Display what would be done.
+ eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\""
+ $echo "export $shlibpath_var"
+ $echo "$cmd$args"
+ exit 0
+ fi
+ ;;
+
+ # libtool uninstall mode
+ uninstall)
+ modename="$modename: uninstall"
+ rm="$nonopt"
+ files=
+
+ for arg
+ do
+ case "$arg" in
+ -*) rm="$rm $arg" ;;
+ *) files="$files $arg" ;;
+ esac
+ done
+
+ if test -z "$rm"; then
+ $echo "$modename: you must specify an RM program" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ fi
+
+ for file in $files; do
+ dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
+ test "X$dir" = "X$file" && dir=.
+ name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
+
+ rmfiles="$file"
+
+ case "$name" in
+ *.la)
+ # Possibly a libtool archive, so verify it.
+ if (sed -e '2q' $file | egrep '^# Generated by ltmain\.sh') >/dev/null 2>&1; then
+ . $dir/$name
+
+ # Delete the libtool libraries and symlinks.
+ for n in $library_names; do
+ rmfiles="$rmfiles $dir/$n"
+ test "X$n" = "X$dlname" && dlname=
+ done
+ test -n "$dlname" && rmfiles="$rmfiles $dir/$dlname"
+ test -n "$old_library" && rmfiles="$rmfiles $dir/$old_library"
+
+ $show "$rm $rmfiles"
+ $run $rm $rmfiles
+
+ if test -n "$library_names"; then
+ # Do each command in the postuninstall commands.
+ eval cmds=\"$postuninstall_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd"
+ done
+ IFS="$save_ifs"
+ fi
+
+ if test -n "$old_library"; then
+ # Do each command in the old_postuninstall commands.
+ eval cmds=\"$old_postuninstall_cmds\"
+ IFS="${IFS= }"; save_ifs="$IFS"; IFS=';'
+ for cmd in $cmds; do
+ IFS="$save_ifs"
+ $show "$cmd"
+ $run eval "$cmd"
+ done
+ IFS="$save_ifs"
+ fi
+
+ # FIXME: should reinstall the best remaining shared library.
+ fi
+ ;;
+
+ *.lo)
+ if test "$build_old_libs" = yes; then
+ oldobj=`$echo "X$name" | $Xsed -e 's/\.lo$/\.o/'`
+ rmfiles="$rmfiles $dir/$oldobj"
+ fi
+ $show "$rm $rmfiles"
+ $run $rm $rmfiles
+ ;;
+
+ *)
+ $show "$rm $rmfiles"
+ $run $rm $rmfiles
+ ;;
+ esac
+ done
+ exit 0
+ ;;
+
+ "")
+ $echo "$modename: you must specify a MODE" 1>&2
+ $echo "$generic_help" 1>&2
+ exit 1
+ ;;
+ esac
+
+ $echo "$modename: invalid operation mode \`$mode'" 1>&2
+ $echo "$generic_help" 1>&2
+ exit 1
+fi # test -z "$show_help"
+
+# We need to display help for each of the modes.
+case "$mode" in
+"") $echo \
+"Usage: $modename [OPTION]... [MODE-ARG]...
+
+Provide generalized library-building support services.
+
+-n, --dry-run display commands without modifying any files
+ --features display configuration information and exit
+ --finish same as \`--mode=finish'
+ --help display this help message and exit
+ --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS]
+ --quiet same as \`--silent'
+ --silent don't print informational messages
+ --version print version information
+
+MODE must be one of the following:
+
+ compile compile a source file into a libtool object
+ execute automatically set library path, then run a program
+ finish complete the installation of libtool libraries
+ install install libraries or executables
+ link create a library or an executable
+ uninstall remove libraries from an installed directory
+
+MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for
+a more detailed description of MODE."
+ exit 0
+ ;;
+
+compile)
+ $echo \
+"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+COMPILE-COMMAND is a command to be used in creating a \`standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix \`.c' with the
+library object suffix, \`.lo'."
+ ;;
+
+execute)
+ $echo \
+"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+ -dlopen FILE add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to \`-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+ ;;
+
+finish)
+ $echo \
+"Usage: $modename [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges. Use
+the \`--dry-run' option if you just want to see what would be executed."
+ ;;
+
+install)
+ $echo \
+"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command. The first component should be
+either the \`install' or \`cp' program.
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+ ;;
+
+link)
+ $echo \
+"Usage: $modename [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+ -all-static do not do any dynamic linking at all
+ -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime
+ -dlpreopen FILE link in FILE and add its symbols to dld_preloaded_symbols
+ -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+ -LLIBDIR search LIBDIR for required installed libraries
+ -lNAME OUTPUT-FILE requires the installed library libNAME
+ -no-undefined declare that a library does not refer to external symbols
+ -o OUTPUT-FILE create OUTPUT-FILE from the specified objects
+ -release RELEASE specify package release information
+ -rpath LIBDIR the created library will eventually be installed in LIBDIR
+ -static do not do any dynamic linking of libtool libraries
+ -version-info CURRENT[:REVISION[:AGE]]
+ specify library version info [each variable defaults to 0]
+
+All other options (arguments beginning with \`-') are ignored.
+
+Every other argument is treated as a filename. Files ending in \`.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in \`.la', then a libtool library is created, only
+library objects (\`.lo' files) may be specified, and \`-rpath' is required.
+
+If OUTPUT-FILE ends in \`.a', then a standard library is created using \`ar'
+and \`ranlib'.
+
+If OUTPUT-FILE ends in \`.lo' or \`.o', then a reloadable object file is
+created, otherwise an executable program is created."
+ ;;
+
+uninstall)
+ $echo
+"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+ ;;
+
+*)
+ $echo "$modename: invalid operation mode \`$mode'" 1>&2
+ $echo "$help" 1>&2
+ exit 1
+ ;;
+esac
+
+echo
+$echo "Try \`$modename --help' for more information about other modes."
+
+exit 0
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
diff --git a/osframework/source/ImageLib/jpeg/makcjpeg.st b/osframework/source/ImageLib/jpeg/makcjpeg.st
new file mode 100644
index 0000000..06bdf56
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makcjpeg.st
@@ -0,0 +1,38 @@
+; Project file for Independent JPEG Group's software
+;
+; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
+; Thanks to Frank Moehle (Frank.Moehle@arbi.informatik.uni-oldenburg.de),
+; Dr. B. Setzepfandt (bernd@gina.uni-muenster.de),
+; and Guido Vollbeding (guivol@esc.de).
+;
+; To use this file, rename it to cjpeg.prj.
+; If you are using Turbo C, change filenames beginning with "pc..." to "tc..."
+; Read installation instructions before trying to make the program!
+;
+;
+; * * * Output file * * *
+cjpeg.ttp
+;
+; * * * COMPILER OPTIONS * * *
+.C[-P] ; absolute calls
+.C[-M] ; and no string merging, folks
+.C[-w-cln] ; no "constant is long" warnings
+.C[-w-par] ; no "parameter xxxx unused"
+.C[-w-rch] ; no "unreachable code"
+.C[-wsig] ; warn if significant digits may be lost
+=
+; * * * * List of modules * * * *
+pcstart.o
+cjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
+cdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdswitch.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+libjpeg.lib ; built by libjpeg.prj
+pcfltlib.lib ; floating point library
+; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
+pcstdlib.lib ; standard library
+pcextlib.lib ; extended library
diff --git a/osframework/source/ImageLib/jpeg/makdjpeg.st b/osframework/source/ImageLib/jpeg/makdjpeg.st
new file mode 100644
index 0000000..873fd0f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makdjpeg.st
@@ -0,0 +1,38 @@
+; Project file for Independent JPEG Group's software
+;
+; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
+; Thanks to Frank Moehle (Frank.Moehle@arbi.informatik.uni-oldenburg.de),
+; Dr. B. Setzepfandt (bernd@gina.uni-muenster.de),
+; and Guido Vollbeding (guivol@esc.de).
+;
+; To use this file, rename it to djpeg.prj.
+; If you are using Turbo C, change filenames beginning with "pc..." to "tc..."
+; Read installation instructions before trying to make the program!
+;
+;
+; * * * Output file * * *
+djpeg.ttp
+;
+; * * * COMPILER OPTIONS * * *
+.C[-P] ; absolute calls
+.C[-M] ; and no string merging, folks
+.C[-w-cln] ; no "constant is long" warnings
+.C[-w-par] ; no "parameter xxxx unused"
+.C[-w-rch] ; no "unreachable code"
+.C[-wsig] ; warn if significant digits may be lost
+=
+; * * * * List of modules * * * *
+pcstart.o
+djpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
+cdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdcolmap.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+wrppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+wrgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+wrtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+wrbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+wrrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+libjpeg.lib ; built by libjpeg.prj
+pcfltlib.lib ; floating point library
+; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
+pcstdlib.lib ; standard library
+pcextlib.lib ; extended library
diff --git a/osframework/source/ImageLib/jpeg/makeapps.ds b/osframework/source/ImageLib/jpeg/makeapps.ds
new file mode 100644
index 0000000..8535d4d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makeapps.ds
@@ -0,0 +1,828 @@
+# Microsoft Developer Studio Generated NMAKE File, Format Version 4.20
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+!IF "$(CFG)" == ""
+CFG=cjpeg - Win32
+!MESSAGE No configuration specified. Defaulting to cjpeg - Win32.
+!ENDIF
+
+!IF "$(CFG)" != "cjpeg - Win32" && "$(CFG)" != "djpeg - Win32" &&\
+ "$(CFG)" != "jpegtran - Win32" && "$(CFG)" != "rdjpgcom - Win32" &&\
+ "$(CFG)" != "wrjpgcom - Win32"
+!MESSAGE Invalid configuration "$(CFG)" specified.
+!MESSAGE You can specify a configuration when running NMAKE on this makefile
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "apps.mak" CFG="cjpeg - Win32"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "cjpeg - Win32" (based on "Win32 (x86) Console Application")
+!MESSAGE "djpeg - Win32" (based on "Win32 (x86) Console Application")
+!MESSAGE "jpegtran - Win32" (based on "Win32 (x86) Console Application")
+!MESSAGE "rdjpgcom - Win32" (based on "Win32 (x86) Console Application")
+!MESSAGE "wrjpgcom - Win32" (based on "Win32 (x86) Console Application")
+!MESSAGE
+!ERROR An invalid configuration is specified.
+!ENDIF
+
+!IF "$(OS)" == "Windows_NT"
+NULL=
+!ELSE
+NULL=nul
+!ENDIF
+################################################################################
+# Begin Project
+# PROP Target_Last_Scanned "cjpeg - Win32"
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "cjpeg - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "cjpeg\Release"
+# PROP BASE Intermediate_Dir "cjpeg\Release"
+# PROP BASE Target_Dir "cjpeg"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "cjpeg\Release"
+# PROP Intermediate_Dir "cjpeg\Release"
+# PROP Target_Dir "cjpeg"
+OUTDIR=.\cjpeg\Release
+INTDIR=.\cjpeg\Release
+
+ALL : "$(OUTDIR)\cjpeg.exe"
+
+CLEAN :
+ -@erase "$(INTDIR)\cjpeg.obj"
+ -@erase "$(INTDIR)\rdppm.obj"
+ -@erase "$(INTDIR)\rdgif.obj"
+ -@erase "$(INTDIR)\rdtarga.obj"
+ -@erase "$(INTDIR)\rdrle.obj"
+ -@erase "$(INTDIR)\rdbmp.obj"
+ -@erase "$(INTDIR)\rdswitch.obj"
+ -@erase "$(INTDIR)\cdjpeg.obj"
+ -@erase "$(OUTDIR)\cjpeg.exe"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE"\
+ /Fp"$(INTDIR)/cjpeg.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\cjpeg\Release/
+CPP_SBRS=.\.
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/cjpeg.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+LINK32_FLAGS=Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib\
+ comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
+ odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
+ /pdb:"$(OUTDIR)/cjpeg.pdb" /machine:I386 /out:"$(OUTDIR)/cjpeg.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\cjpeg.obj" \
+ "$(INTDIR)\rdppm.obj" \
+ "$(INTDIR)\rdgif.obj" \
+ "$(INTDIR)\rdtarga.obj" \
+ "$(INTDIR)\rdrle.obj" \
+ "$(INTDIR)\rdbmp.obj" \
+ "$(INTDIR)\rdswitch.obj" \
+ "$(INTDIR)\cdjpeg.obj" \
+
+
+"$(OUTDIR)\cjpeg.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "djpeg - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "djpeg\Release"
+# PROP BASE Intermediate_Dir "djpeg\Release"
+# PROP BASE Target_Dir "djpeg"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "djpeg\Release"
+# PROP Intermediate_Dir "djpeg\Release"
+# PROP Target_Dir "djpeg"
+OUTDIR=.\djpeg\Release
+INTDIR=.\djpeg\Release
+
+ALL : "$(OUTDIR)\djpeg.exe"
+
+CLEAN :
+ -@erase "$(INTDIR)\djpeg.obj"
+ -@erase "$(INTDIR)\wrppm.obj"
+ -@erase "$(INTDIR)\wrgif.obj"
+ -@erase "$(INTDIR)\wrtarga.obj"
+ -@erase "$(INTDIR)\wrrle.obj"
+ -@erase "$(INTDIR)\wrbmp.obj"
+ -@erase "$(INTDIR)\rdcolmap.obj"
+ -@erase "$(INTDIR)\cdjpeg.obj"
+ -@erase "$(OUTDIR)\djpeg.exe"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE"\
+ /Fp"$(INTDIR)/djpeg.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\djpeg\Release/
+CPP_SBRS=.\.
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/djpeg.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+LINK32_FLAGS=Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib\
+ comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
+ odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
+ /pdb:"$(OUTDIR)/djpeg.pdb" /machine:I386 /out:"$(OUTDIR)/djpeg.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\djpeg.obj" \
+ "$(INTDIR)\wrppm.obj" \
+ "$(INTDIR)\wrgif.obj" \
+ "$(INTDIR)\wrtarga.obj" \
+ "$(INTDIR)\wrrle.obj" \
+ "$(INTDIR)\wrbmp.obj" \
+ "$(INTDIR)\rdcolmap.obj" \
+ "$(INTDIR)\cdjpeg.obj" \
+
+
+"$(OUTDIR)\djpeg.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "jpegtran - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "jpegtran\Release"
+# PROP BASE Intermediate_Dir "jpegtran\Release"
+# PROP BASE Target_Dir "jpegtran"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "jpegtran\Release"
+# PROP Intermediate_Dir "jpegtran\Release"
+# PROP Target_Dir "jpegtran"
+OUTDIR=.\jpegtran\Release
+INTDIR=.\jpegtran\Release
+
+ALL : "$(OUTDIR)\jpegtran.exe"
+
+CLEAN :
+ -@erase "$(INTDIR)\jpegtran.obj"
+ -@erase "$(INTDIR)\rdswitch.obj"
+ -@erase "$(INTDIR)\cdjpeg.obj"
+ -@erase "$(INTDIR)\transupp.obj"
+ -@erase "$(OUTDIR)\jpegtran.exe"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE"\
+ /Fp"$(INTDIR)/jpegtran.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\jpegtran\Release/
+CPP_SBRS=.\.
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/jpegtran.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+LINK32_FLAGS=Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib\
+ comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
+ odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
+ /pdb:"$(OUTDIR)/jpegtran.pdb" /machine:I386 /out:"$(OUTDIR)/jpegtran.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\jpegtran.obj" \
+ "$(INTDIR)\rdswitch.obj" \
+ "$(INTDIR)\cdjpeg.obj" \
+ "$(INTDIR)\transupp.obj" \
+
+
+"$(OUTDIR)\jpegtran.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "rdjpgcom - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "rdjpgcom\Release"
+# PROP BASE Intermediate_Dir "rdjpgcom\Release"
+# PROP BASE Target_Dir "rdjpgcom"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "rdjpgcom\Release"
+# PROP Intermediate_Dir "rdjpgcom\Release"
+# PROP Target_Dir "rdjpgcom"
+OUTDIR=.\rdjpgcom\Release
+INTDIR=.\rdjpgcom\Release
+
+ALL : "$(OUTDIR)\rdjpgcom.exe"
+
+CLEAN :
+ -@erase "$(INTDIR)\rdjpgcom.obj"
+ -@erase "$(OUTDIR)\rdjpgcom.exe"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE"\
+ /Fp"$(INTDIR)/rdjpgcom.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\rdjpgcom\Release/
+CPP_SBRS=.\.
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/rdjpgcom.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+LINK32_FLAGS=Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib\
+ comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
+ odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
+ /pdb:"$(OUTDIR)/rdjpgcom.pdb" /machine:I386 /out:"$(OUTDIR)/rdjpgcom.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\rdjpgcom.obj"
+
+"$(OUTDIR)\rdjpgcom.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "wrjpgcom - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "wrjpgcom\Release"
+# PROP BASE Intermediate_Dir "wrjpgcom\Release"
+# PROP BASE Target_Dir "wrjpgcom"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "wrjpgcom\Release"
+# PROP Intermediate_Dir "wrjpgcom\Release"
+# PROP Target_Dir "wrjpgcom"
+OUTDIR=.\wrjpgcom\Release
+INTDIR=.\wrjpgcom\Release
+
+ALL : "$(OUTDIR)\wrjpgcom.exe"
+
+CLEAN :
+ -@erase "$(INTDIR)\wrjpgcom.obj"
+ -@erase "$(OUTDIR)\wrjpgcom.exe"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE"\
+ /Fp"$(INTDIR)/wrjpgcom.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\wrjpgcom\Release/
+CPP_SBRS=.\.
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/wrjpgcom.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+LINK32_FLAGS=Release\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib\
+ comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
+ odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
+ /pdb:"$(OUTDIR)/wrjpgcom.pdb" /machine:I386 /out:"$(OUTDIR)/wrjpgcom.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\wrjpgcom.obj"
+
+"$(OUTDIR)\wrjpgcom.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ENDIF
+
+.c{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.cpp{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.cxx{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.c{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+.cpp{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+.cxx{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+################################################################################
+# Begin Target
+
+# Name "cjpeg - Win32"
+
+!IF "$(CFG)" == "cjpeg - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="cjpeg.c"
+DEP_CPP_CJPEG=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+ "jversion.h"\
+
+
+"$(INTDIR)\cjpeg.obj" : $(SOURCE) $(DEP_CPP_CJPEG) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="cdjpeg.c"
+DEP_CPP_CDJPE=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\cdjpeg.obj" : $(SOURCE) $(DEP_CPP_CDJPE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdswitch.c"
+DEP_CPP_RDSWI=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdswitch.obj" : $(SOURCE) $(DEP_CPP_RDSWI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdppm.c"
+DEP_CPP_RDPPM=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdppm.obj" : $(SOURCE) $(DEP_CPP_RDPPM) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdgif.c"
+DEP_CPP_RDGIF=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdgif.obj" : $(SOURCE) $(DEP_CPP_RDGIF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdtarga.c"
+DEP_CPP_RDTAR=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdtarga.obj" : $(SOURCE) $(DEP_CPP_RDTAR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdbmp.c"
+DEP_CPP_RDBMP=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdbmp.obj" : $(SOURCE) $(DEP_CPP_RDBMP) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdrle.c"
+DEP_CPP_RDRLE=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdrle.obj" : $(SOURCE) $(DEP_CPP_RDRLE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+################################################################################
+# Begin Target
+
+# Name "djpeg - Win32"
+
+!IF "$(CFG)" == "djpeg - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="djpeg.c"
+DEP_CPP_DJPEG=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+ "jversion.h"\
+
+
+"$(INTDIR)\djpeg.obj" : $(SOURCE) $(DEP_CPP_DJPEG) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="cdjpeg.c"
+DEP_CPP_CDJPE=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\cdjpeg.obj" : $(SOURCE) $(DEP_CPP_CDJPE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdcolmap.c"
+DEP_CPP_RDCOL=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdcolmap.obj" : $(SOURCE) $(DEP_CPP_RDCOL) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="wrppm.c"
+DEP_CPP_WRPPM=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\wrppm.obj" : $(SOURCE) $(DEP_CPP_WRPPM) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="wrgif.c"
+DEP_CPP_WRGIF=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\wrgif.obj" : $(SOURCE) $(DEP_CPP_WRGIF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="wrtarga.c"
+DEP_CPP_WRTAR=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\wrtarga.obj" : $(SOURCE) $(DEP_CPP_WRTAR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="wrbmp.c"
+DEP_CPP_WRBMP=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\wrbmp.obj" : $(SOURCE) $(DEP_CPP_WRBMP) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="wrrle.c"
+DEP_CPP_WRRLE=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\wrrle.obj" : $(SOURCE) $(DEP_CPP_WRRLE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+################################################################################
+# Begin Target
+
+# Name "jpegtran - Win32"
+
+!IF "$(CFG)" == "jpegtran - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="jpegtran.c"
+DEP_CPP_JPEGT=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+ "transupp.h"\
+ "jversion.h"\
+
+
+"$(INTDIR)\jpegtran.obj" : $(SOURCE) $(DEP_CPP_JPEGT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="cdjpeg.c"
+DEP_CPP_CDJPE=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\cdjpeg.obj" : $(SOURCE) $(DEP_CPP_CDJPE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="rdswitch.c"
+DEP_CPP_RDSWI=\
+ "cdjpeg.h"\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+ "cderror.h"\
+
+
+"$(INTDIR)\rdswitch.obj" : $(SOURCE) $(DEP_CPP_RDSWI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="transupp.c"
+DEP_CPP_TRANS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "transupp.h"\
+
+
+"$(INTDIR)\transupp.obj" : $(SOURCE) $(DEP_CPP_TRANS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+################################################################################
+# Begin Target
+
+# Name "rdjpgcom - Win32"
+
+!IF "$(CFG)" == "rdjpgcom - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="rdjpgcom.c"
+DEP_CPP_RDJPG=\
+ "jinclude.h"\
+ "jconfig.h"\
+
+
+"$(INTDIR)\rdjpgcom.obj" : $(SOURCE) $(DEP_CPP_RDJPG) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+################################################################################
+# Begin Target
+
+# Name "wrjpgcom - Win32"
+
+!IF "$(CFG)" == "wrjpgcom - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="wrjpgcom.c"
+DEP_CPP_WRJPG=\
+ "jinclude.h"\
+ "jconfig.h"\
+
+
+"$(INTDIR)\wrjpgcom.obj" : $(SOURCE) $(DEP_CPP_WRJPG) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+# End Project
+################################################################################
+
diff --git a/osframework/source/ImageLib/jpeg/makefile.ansi b/osframework/source/ImageLib/jpeg/makefile.ansi
new file mode 100644
index 0000000..39e8462
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.ansi
@@ -0,0 +1,214 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is suitable for Unix-like systems with ANSI-capable compilers.
+# If you have a non-ANSI compiler, makefile.unix is a better starting point.
+
+# Read installation instructions before saying "make" !!
+
+# The name of your C compiler:
+CC= cc
+
+# You may need to adjust these cc options:
+CFLAGS= -O
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Link-time cc options:
+LDFLAGS=
+
+# To link any special libraries, add the necessary -l commands here.
+LDLIBS=
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Unix this is usually jmemnobs.o, but you may want
+# to use jmemansi.o or jmemname.o if you have limited swap space.
+SYSDEPMEM= jmemnobs.o
+
+# miscellaneous OS-dependent stuff
+# linker
+LN= $(CC)
+# file deletion command
+RM= rm -f
+# library (.a) file creation command
+AR= ar rc
+# second step in .a creation (use "touch" if not needed)
+AR2= ranlib
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
+# decompression library object files
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
+# These objectfiles are included in libjpeg.a
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
+
+
+all: libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+
+libjpeg.a: $(LIBOBJECTS)
+ $(RM) libjpeg.a
+ $(AR) libjpeg.a $(LIBOBJECTS)
+ $(AR2) libjpeg.a
+
+cjpeg: $(COBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
+
+djpeg: $(DOBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
+
+jpegtran: $(TROBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)
+
+rdjpgcom: rdjpgcom.o
+ $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
+
+wrjpgcom: wrjpgcom.o
+ $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ $(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom
+ $(RM) core testout*
+
+test: cjpeg djpeg jpegtran
+ $(RM) testout*
+ ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ ./cjpeg -dct int -outfile testout.jpg testimg.ppm
+ ./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ ./jpegtran -outfile testoutt.jpg testprog.jpg
+ cmp testimg.ppm testout.ppm
+ cmp testimg.bmp testout.bmp
+ cmp testimg.jpg testout.jpg
+ cmp testimg.ppm testoutp.ppm
+ cmp testimgp.jpg testoutp.jpg
+ cmp testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.bcc b/osframework/source/ImageLib/jpeg/makefile.bcc
new file mode 100644
index 0000000..92e3218
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.bcc
@@ -0,0 +1,285 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is suitable for Borland C on MS-DOS or OS/2.
+# It works with Borland C++ for DOS, revision 3.0 or later,
+# and has been tested with Borland C++ for OS/2.
+# Watch out for optimization bugs in the OS/2 compilers --- see notes below!
+# Thanks to Tom Wright and Ge' Weijers (original DOS) and
+# Ken Porter (OS/2) for this file.
+
+# Read installation instructions before saying "make" !!
+
+# Are we under DOS or OS/2?
+!if !$d(DOS) && !$d(OS2)
+!if $d(__OS2__)
+OS2=1
+!else
+DOS=1
+!endif
+!endif
+
+# The name of your C compiler:
+CC= bcc
+
+# You may need to adjust these cc options:
+!if $d(DOS)
+CFLAGS= -O2 -mm -w-par -w-stu -w-ccc -w-rch
+!else
+CFLAGS= -O1 -w-par -w-stu -w-ccc -w-rch
+!endif
+# -O2 enables full code optimization (for pre-3.0 Borland C++, use -O -G -Z).
+# -O2 is buggy in Borland OS/2 C++ revision 2.0, so use -O1 there for now.
+# If you have Borland OS/2 C++ revision 1.0, use -O or no optimization at all.
+# -mm selects medium memory model (near data, far code pointers; DOS only!)
+# -w-par suppresses warnings about unused function parameters
+# -w-stu suppresses warnings about incomplete structures
+# -w-ccc suppresses warnings about compile-time-constant conditions
+# -w-rch suppresses warnings about unreachable code
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Link-time cc options:
+!if $d(DOS)
+LDFLAGS= -mm
+# memory model option here must match CFLAGS!
+!else
+LDFLAGS=
+# -lai full-screen app
+# -lc case-significant link
+!endif
+
+# Put here the object file name for the correct system-dependent memory
+# manager file.
+# For DOS, we recommend jmemdos.c and jmemdosa.asm.
+# For OS/2, we recommend jmemnobs.c (flat memory!)
+# SYSDEPMEMLIB must list the same files with "+" signs for the librarian.
+!if $d(DOS)
+SYSDEPMEM= jmemdos.obj jmemdosa.obj
+SYSDEPMEMLIB= +jmemdos.obj +jmemdosa.obj
+!else
+SYSDEPMEM= jmemnobs.obj
+SYSDEPMEMLIB= +jmemnobs.obj
+!endif
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.obj jcapistd.obj jctrans.obj jcparam.obj jdatadst.obj \
+ jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj jcprepct.obj \
+ jccoefct.obj jccolor.obj jcsample.obj jchuff.obj jcphuff.obj \
+ jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj
+# decompression library object files
+DLIBOBJECTS= jdapimin.obj jdapistd.obj jdtrans.obj jdatasrc.obj \
+ jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdphuff.obj \
+ jdmainct.obj jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj \
+ jidctflt.obj jidctint.obj jidctred.obj jdsample.obj jdcolor.obj \
+ jquant1.obj jquant2.obj jdmerge.obj
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \
+ rdswitch.obj cdjpeg.obj
+DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
+ rdcolmap.obj cdjpeg.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+
+
+all: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+
+libjpeg.lib: $(LIBOBJECTS)
+ - del libjpeg.lib
+ tlib libjpeg.lib /E /C @&&|
++jcapimin.obj +jcapistd.obj +jctrans.obj +jcparam.obj +jdatadst.obj &
++jcinit.obj +jcmaster.obj +jcmarker.obj +jcmainct.obj +jcprepct.obj &
++jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj +jcphuff.obj &
++jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj +jfdctint.obj +jdapimin.obj &
++jdapistd.obj +jdtrans.obj +jdatasrc.obj +jdmaster.obj +jdinput.obj &
++jdmarker.obj +jdhuff.obj +jdphuff.obj +jdmainct.obj +jdcoefct.obj &
++jdpostct.obj +jddctmgr.obj +jidctfst.obj +jidctflt.obj +jidctint.obj &
++jidctred.obj +jdsample.obj +jdcolor.obj +jquant1.obj +jquant2.obj &
++jdmerge.obj +jcomapi.obj +jutils.obj +jerror.obj +jmemmgr.obj &
+$(SYSDEPMEMLIB)
+|
+
+cjpeg.exe: $(COBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) -ecjpeg.exe $(COBJECTS) libjpeg.lib
+
+djpeg.exe: $(DOBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) -edjpeg.exe $(DOBJECTS) libjpeg.lib
+
+jpegtran.exe: $(TROBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) -ejpegtran.exe $(TROBJECTS) libjpeg.lib
+
+rdjpgcom.exe: rdjpgcom.c
+!if $d(DOS)
+ $(CC) -ms -O rdjpgcom.c
+!else
+ $(CC) $(CFLAGS) rdjpgcom.c
+!endif
+
+# On DOS, wrjpgcom needs large model so it can malloc a 64K chunk
+wrjpgcom.exe: wrjpgcom.c
+!if $d(DOS)
+ $(CC) -ml -O wrjpgcom.c
+!else
+ $(CC) $(CFLAGS) wrjpgcom.c
+!endif
+
+# This "{}" syntax allows Borland Make to "batch" source files.
+# In this way, each run of the compiler can build many modules.
+.c.obj:
+ $(CC) $(CFLAGS) -c{ $<}
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ - del *.obj
+ - del libjpeg.lib
+ - del cjpeg.exe
+ - del djpeg.exe
+ - del jpegtran.exe
+ - del rdjpgcom.exe
+ - del wrjpgcom.exe
+ - del testout*.*
+
+test: cjpeg.exe djpeg.exe jpegtran.exe
+ - del testout*.*
+ djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ cjpeg -dct int -outfile testout.jpg testimg.ppm
+ djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ jpegtran -outfile testoutt.jpg testprog.jpg
+!if $d(DOS)
+ fc /b testimg.ppm testout.ppm
+ fc /b testimg.bmp testout.bmp
+ fc /b testimg.jpg testout.jpg
+ fc /b testimg.ppm testoutp.ppm
+ fc /b testimgp.jpg testoutp.jpg
+ fc /b testorig.jpg testoutt.jpg
+!else
+ echo n > n.tmp
+ comp testimg.ppm testout.ppm < n.tmp
+ comp testimg.bmp testout.bmp < n.tmp
+ comp testimg.jpg testout.jpg < n.tmp
+ comp testimg.ppm testoutp.ppm < n.tmp
+ comp testimgp.jpg testoutp.jpg < n.tmp
+ comp testorig.jpg testoutt.jpg < n.tmp
+ del n.tmp
+!endif
+
+
+jcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.obj: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.obj: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.obj: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+jmemdosa.obj: jmemdosa.asm
+ tasm /mx jmemdosa.asm
diff --git a/osframework/source/ImageLib/jpeg/makefile.cfg b/osframework/source/ImageLib/jpeg/makefile.cfg
new file mode 100644
index 0000000..4e54bb0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.cfg
@@ -0,0 +1,319 @@
+# Makefile for Independent JPEG Group's software
+
+# makefile.cfg is edited by configure to produce a custom Makefile.
+
+# Read installation instructions before saying "make" !!
+
+# For compiling with source and object files in different directories.
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# Where to install the programs and man pages.
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = $(exec_prefix)/bin
+libdir = $(exec_prefix)/lib
+includedir = $(prefix)/include
+binprefix =
+manprefix =
+manext = 1
+mandir = $(prefix)/man/man$(manext)
+
+# The name of your C compiler:
+CC= @CC@
+
+# You may need to adjust these cc options:
+CFLAGS= @CFLAGS@ @CPPFLAGS@ @INCLUDEFLAGS@
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+# However, any special defines for ansi2knr.c may be included here:
+ANSI2KNRFLAGS= @ANSI2KNRFLAGS@
+
+# Link-time cc options:
+LDFLAGS= @LDFLAGS@
+
+# To link any special libraries, add the necessary -l commands here.
+LDLIBS= @LIBS@
+
+# If using GNU libtool, LIBTOOL references it; if not, LIBTOOL is empty.
+LIBTOOL = @LIBTOOL@
+# $(O) expands to "lo" if using libtool, plain "o" if not.
+# Similarly, $(A) expands to "la" or "a".
+O = @O@
+A = @A@
+
+# Library version ID; libtool uses this for the shared library version number.
+# Note: we suggest this match the macro of the same name in jpeglib.h.
+JPEG_LIB_VERSION = @JPEG_LIB_VERSION@
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Unix this is usually jmemnobs.o, but you may want
+# to use jmemansi.o or jmemname.o if you have limited swap space.
+SYSDEPMEM= @MEMORYMGR@
+
+# miscellaneous OS-dependent stuff
+SHELL= /bin/sh
+# linker
+LN= @LN@
+# file deletion command
+RM= rm -f
+# directory creation command
+MKDIR= mkdir
+# library (.a) file creation command
+AR= ar rc
+# second step in .a creation (use "touch" if not needed)
+AR2= @RANLIB@
+# installation program
+INSTALL= @INSTALL@
+INSTALL_PROGRAM= @INSTALL_PROGRAM@
+INSTALL_LIB= @INSTALL_LIB@
+INSTALL_DATA= @INSTALL_DATA@
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.$(O) jutils.$(O) jerror.$(O) jmemmgr.$(O) $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.$(O) jcapistd.$(O) jctrans.$(O) jcparam.$(O) \
+ jdatadst.$(O) jcinit.$(O) jcmaster.$(O) jcmarker.$(O) jcmainct.$(O) \
+ jcprepct.$(O) jccoefct.$(O) jccolor.$(O) jcsample.$(O) jchuff.$(O) \
+ jcphuff.$(O) jcdctmgr.$(O) jfdctfst.$(O) jfdctflt.$(O) \
+ jfdctint.$(O)
+# decompression library object files
+DLIBOBJECTS= jdapimin.$(O) jdapistd.$(O) jdtrans.$(O) jdatasrc.$(O) \
+ jdmaster.$(O) jdinput.$(O) jdmarker.$(O) jdhuff.$(O) jdphuff.$(O) \
+ jdmainct.$(O) jdcoefct.$(O) jdpostct.$(O) jddctmgr.$(O) \
+ jidctfst.$(O) jidctflt.$(O) jidctint.$(O) jidctred.$(O) \
+ jdsample.$(O) jdcolor.$(O) jquant1.$(O) jquant2.$(O) jdmerge.$(O)
+# These objectfiles are included in libjpeg.a
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.$(O) rdppm.$(O) rdgif.$(O) rdtarga.$(O) rdrle.$(O) \
+ rdbmp.$(O) rdswitch.$(O) cdjpeg.$(O)
+DOBJECTS= djpeg.$(O) wrppm.$(O) wrgif.$(O) wrtarga.$(O) wrrle.$(O) \
+ wrbmp.$(O) rdcolmap.$(O) cdjpeg.$(O)
+TROBJECTS= jpegtran.$(O) rdswitch.$(O) cdjpeg.$(O) transupp.$(O)
+
+
+all: @A2K_DEPS@ libjpeg.$(A) cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+
+# Special compilation rules to support ansi2knr and libtool.
+.SUFFIXES: .lo .la
+
+# How to compile with libtool.
+@COM_LT@.c.lo:
+@COM_LT@ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c
+
+# How to use ansi2knr, when not using libtool.
+@COM_A2K@.c.o:
+@COM_A2K@ ./ansi2knr $(srcdir)/$*.c knr/$*.c
+@COM_A2K@ $(CC) $(CFLAGS) -c knr/$*.c
+@COM_A2K@ $(RM) knr/$*.c
+
+# How to use ansi2knr AND libtool.
+@COM_A2K@.c.lo:
+@COM_A2K@ ./ansi2knr $(srcdir)/$*.c knr/$*.c
+@COM_A2K@ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c knr/$*.c
+@COM_A2K@ $(RM) knr/$*.c
+
+ansi2knr: ansi2knr.c
+ $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr $(srcdir)/ansi2knr.c
+ $(MKDIR) knr
+
+# the library:
+
+# without libtool:
+libjpeg.a: @A2K_DEPS@ $(LIBOBJECTS)
+ $(RM) libjpeg.a
+ $(AR) libjpeg.a $(LIBOBJECTS)
+ $(AR2) libjpeg.a
+
+# with libtool:
+libjpeg.la: @A2K_DEPS@ $(LIBOBJECTS)
+ $(LIBTOOL) --mode=link $(CC) -o libjpeg.la $(LIBOBJECTS) \
+ -rpath $(libdir) -version-info $(JPEG_LIB_VERSION)
+
+# sample programs:
+
+cjpeg: $(COBJECTS) libjpeg.$(A)
+ $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.$(A) $(LDLIBS)
+
+djpeg: $(DOBJECTS) libjpeg.$(A)
+ $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.$(A) $(LDLIBS)
+
+jpegtran: $(TROBJECTS) libjpeg.$(A)
+ $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.$(A) $(LDLIBS)
+
+rdjpgcom: rdjpgcom.$(O)
+ $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.$(O) $(LDLIBS)
+
+wrjpgcom: wrjpgcom.$(O)
+ $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.$(O) $(LDLIBS)
+
+# Installation rules:
+
+install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom @FORCE_INSTALL_LIB@
+ $(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg
+ $(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg
+ $(INSTALL_PROGRAM) jpegtran $(bindir)/$(binprefix)jpegtran
+ $(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom
+ $(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcom
+ $(INSTALL_DATA) $(srcdir)/cjpeg.1 $(mandir)/$(manprefix)cjpeg.$(manext)
+ $(INSTALL_DATA) $(srcdir)/djpeg.1 $(mandir)/$(manprefix)djpeg.$(manext)
+ $(INSTALL_DATA) $(srcdir)/jpegtran.1 $(mandir)/$(manprefix)jpegtran.$(manext)
+ $(INSTALL_DATA) $(srcdir)/rdjpgcom.1 $(mandir)/$(manprefix)rdjpgcom.$(manext)
+ $(INSTALL_DATA) $(srcdir)/wrjpgcom.1 $(mandir)/$(manprefix)wrjpgcom.$(manext)
+
+install-lib: libjpeg.$(A) install-headers
+ $(INSTALL_LIB) libjpeg.$(A) $(libdir)/$(binprefix)libjpeg.$(A)
+
+install-headers: jconfig.h
+ $(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h
+ $(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h
+ $(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h
+ $(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.h
+
+clean:
+ $(RM) *.o *.lo libjpeg.a libjpeg.la
+ $(RM) cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+ $(RM) ansi2knr core testout* config.log config.status
+ $(RM) -r knr .libs _libs
+
+distclean: clean
+ $(RM) Makefile jconfig.h libtool config.cache
+
+test: cjpeg djpeg jpegtran
+ $(RM) testout*
+ ./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg
+ ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg
+ ./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm
+ ./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg
+ ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm
+ ./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg
+ cmp $(srcdir)/testimg.ppm testout.ppm
+ cmp $(srcdir)/testimg.bmp testout.bmp
+ cmp $(srcdir)/testimg.jpg testout.jpg
+ cmp $(srcdir)/testimg.ppm testoutp.ppm
+ cmp $(srcdir)/testimgp.jpg testoutp.jpg
+ cmp $(srcdir)/testorig.jpg testoutt.jpg
+
+check: test
+
+# Mistake catcher:
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+# GNU Make likes to know which target names are not really files to be made:
+.PHONY: all install install-lib install-headers clean distclean test check
+
+
+jcapimin.$(O): jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.$(O): jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.$(O): jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.$(O): jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.$(O): jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.$(O): jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.$(O): jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.$(O): jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.$(O): jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.$(O): jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.$(O): jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.$(O): jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.$(O): jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.$(O): jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.$(O): jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.$(O): jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.$(O): jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.$(O): jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.$(O): jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.$(O): jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.$(O): jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.$(O): jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.$(O): jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.$(O): jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.$(O): jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.$(O): jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.$(O): jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.$(O): jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.$(O): jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.$(O): jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.$(O): jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.$(O): jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.$(O): jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.$(O): jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.$(O): jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.$(O): jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.$(O): jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.$(O): jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.$(O): jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.$(O): jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.$(O): jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.$(O): jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.$(O): jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.$(O): jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.$(O): jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.$(O): jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.$(O): jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.$(O): jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.$(O): jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.$(O): jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.$(O): cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.$(O): djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.$(O): jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.$(O): rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.$(O): wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.$(O): cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.$(O): rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.$(O): rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.$(O): transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.$(O): rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.$(O): wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.$(O): rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.$(O): wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.$(O): rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.$(O): wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.$(O): rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.$(O): wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.$(O): rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.$(O): wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.dj b/osframework/source/ImageLib/jpeg/makefile.dj
new file mode 100644
index 0000000..4355ce2
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.dj
@@ -0,0 +1,220 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for DJGPP (Delorie's GNU C port on MS-DOS), v2.0 or later.
+# Thanks to Frank J. Donahoe for this version.
+
+# Read installation instructions before saying "make" !!
+
+# The name of your C compiler:
+CC= gcc
+
+# You may need to adjust these cc options:
+CFLAGS= -O2 -Wall -I.
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Link-time cc options:
+LDFLAGS= -s
+
+# To link any special libraries, add the necessary -l commands here.
+LDLIBS=
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For DJGPP this is usually jmemnobs.o, but you could
+# use jmemname.o if you want to use named temp files instead of swap space.
+SYSDEPMEM= jmemnobs.o
+
+# miscellaneous OS-dependent stuff
+# linker
+LN= $(CC)
+# file deletion command
+RM= del
+# library (.a) file creation command
+AR= ar rc
+# second step in .a creation (use "touch" if not needed)
+AR2= ranlib
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
+# decompression library object files
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
+# These objectfiles are included in libjpeg.a
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
+
+
+all: libjpeg.a cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+
+libjpeg.a: $(LIBOBJECTS)
+ $(RM) libjpeg.a
+ $(AR) libjpeg.a $(LIBOBJECTS)
+ $(AR2) libjpeg.a
+
+cjpeg.exe: $(COBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o cjpeg.exe $(COBJECTS) libjpeg.a $(LDLIBS)
+
+djpeg.exe: $(DOBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o djpeg.exe $(DOBJECTS) libjpeg.a $(LDLIBS)
+
+jpegtran.exe: $(TROBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o jpegtran.exe $(TROBJECTS) libjpeg.a $(LDLIBS)
+
+rdjpgcom.exe: rdjpgcom.o
+ $(LN) $(LDFLAGS) -o rdjpgcom.exe rdjpgcom.o $(LDLIBS)
+
+wrjpgcom.exe: wrjpgcom.o
+ $(LN) $(LDFLAGS) -o wrjpgcom.exe wrjpgcom.o $(LDLIBS)
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ $(RM) *.o
+ $(RM) cjpeg.exe
+ $(RM) djpeg.exe
+ $(RM) jpegtran.exe
+ $(RM) rdjpgcom.exe
+ $(RM) wrjpgcom.exe
+ $(RM) libjpeg.a
+ $(RM) testout*.*
+
+test: cjpeg.exe djpeg.exe jpegtran.exe
+ $(RM) testout*.*
+ ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ ./cjpeg -dct int -outfile testout.jpg testimg.ppm
+ ./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ ./jpegtran -outfile testoutt.jpg testprog.jpg
+ fc /b testimg.ppm testout.ppm
+ fc /b testimg.bmp testout.bmp
+ fc /b testimg.jpg testout.jpg
+ fc /b testimg.ppm testoutp.ppm
+ fc /b testimgp.jpg testoutp.jpg
+ fc /b testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.manx b/osframework/source/ImageLib/jpeg/makefile.manx
new file mode 100644
index 0000000..7cbc752
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.manx
@@ -0,0 +1,214 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for Amiga systems using Manx Aztec C ver 5.x.
+# Thanks to D.J. James (djjames@cup.portal.com) for this version.
+
+# Read installation instructions before saying "make" !!
+
+# The name of your C compiler:
+CC= cc
+
+# You may need to adjust these cc options:
+# Uncomment for generic 68000 code (will work on any Amiga)
+ARCHFLAGS= -sn
+
+# Uncomment for 68020/68030 code (faster, but won't run on 68000 CPU)
+#ARCHFLAGS= -c2
+
+CFLAGS= -MC -MD $(ARCHFLAGS) -spfam -r4
+
+# Link-time cc options:
+LDFLAGS= -g
+
+# To link any special libraries, add the necessary -l commands here.
+LDLIBS= -lml -lcl
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Amiga we recommend jmemname.o.
+SYSDEPMEM= jmemname.o
+
+# miscellaneous OS-dependent stuff
+# linker
+LN= ln
+# file deletion command
+RM= delete quiet
+# library (.lib) file creation command
+AR= lb
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
+# decompression library object files
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
+
+
+all: libjpeg.lib cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+
+libjpeg.lib: $(LIBOBJECTS)
+ -$(RM) libjpeg.lib
+ $(AR) libjpeg.lib $(LIBOBJECTS)
+
+cjpeg: $(COBJECTS) libjpeg.lib
+ $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.lib $(LDLIBS)
+
+djpeg: $(DOBJECTS) libjpeg.lib
+ $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.lib $(LDLIBS)
+
+jpegtran: $(TROBJECTS) libjpeg.lib
+ $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.lib $(LDLIBS)
+
+rdjpgcom: rdjpgcom.o
+ $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
+
+wrjpgcom: wrjpgcom.o
+ $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ -$(RM) *.o cjpeg djpeg jpegtran libjpeg.lib rdjpgcom wrjpgcom
+ -$(RM) core testout*.*
+
+test: cjpeg djpeg jpegtran
+ -$(RM) testout*.*
+ djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ cjpeg -dct int -outfile testout.jpg testimg.ppm
+ djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ jpegtran -outfile testoutt.jpg testprog.jpg
+ cmp testimg.ppm testout.ppm
+ cmp testimg.bmp testout.bmp
+ cmp testimg.jpg testout.jpg
+ cmp testimg.ppm testoutp.ppm
+ cmp testimgp.jpg testoutp.jpg
+ cmp testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.mc6 b/osframework/source/ImageLib/jpeg/makefile.mc6
new file mode 100644
index 0000000..1185fb4
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.mc6
@@ -0,0 +1,249 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for Microsoft C for MS-DOS, version 6.00A and up.
+# Use NMAKE, not Microsoft's brain-damaged MAKE.
+# Thanks to Alan Wright and Chris Turner of Olivetti Research Ltd.
+
+# Read installation instructions before saying "nmake" !!
+
+# You may need to adjust these compiler options:
+CFLAGS = -AM -Oecigt -Gs -W3
+# -AM medium memory model (or use -AS for small model, if you remove features)
+# -Oecigt -Gs maximum safe optimisation (-Ol has bugs in MSC 6.00A)
+# -W3 warning level 3
+# You might also want to add -G2 if you have an 80286, etc.
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Jan-Herman Buining suggests the following switches for MS C 8.0 and a 486:
+# CFLAGS = /AM /f- /FPi87 /G3 /Gs /Gy /Ob1 /Oc /Oe /Og /Oi /Ol /On /Oo /Ot \
+# /OV4 /W3
+# except for jquant1.c, which must be compiled with /Oo- to avoid a compiler
+# crash.
+
+# Ingar Steinsland suggests the following switches when building
+# a 16-bit Windows DLL:
+# CFLAGS = -ALw -Gsw -Zpe -W3 -O2 -Zi -Zd
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For DOS, we recommend jmemdos.c and jmemdosa.asm.
+# (But not for Windows; see install.doc if you use this makefile for Windows.)
+SYSDEPMEM= jmemdos.obj jmemdosa.obj
+# SYSDEPMEMLIB must list the same files with "+" signs for the librarian.
+SYSDEPMEMLIB= +jmemdos.obj +jmemdosa.obj
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.obj jcapistd.obj jctrans.obj jcparam.obj jdatadst.obj \
+ jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj jcprepct.obj \
+ jccoefct.obj jccolor.obj jcsample.obj jchuff.obj jcphuff.obj \
+ jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj
+# decompression library object files
+DLIBOBJECTS= jdapimin.obj jdapistd.obj jdtrans.obj jdatasrc.obj \
+ jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdphuff.obj \
+ jdmainct.obj jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj \
+ jidctflt.obj jidctint.obj jidctred.obj jdsample.obj jdcolor.obj \
+ jquant1.obj jquant2.obj jdmerge.obj
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \
+ rdswitch.obj cdjpeg.obj
+DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
+ rdcolmap.obj cdjpeg.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+
+# need linker response file because file list > 128 chars
+RFILE = libjpeg.ans
+
+
+all: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+
+libjpeg.lib: $(LIBOBJECTS) $(RFILE)
+ del libjpeg.lib
+ lib @$(RFILE)
+
+# linker response file for building libjpeg.lib
+$(RFILE) : makefile
+ del $(RFILE)
+ echo libjpeg.lib >$(RFILE)
+# silly want-to-create-it prompt:
+ echo y >>$(RFILE)
+ echo +jcapimin.obj +jcapistd.obj +jctrans.obj +jcparam.obj & >>$(RFILE)
+ echo +jdatadst.obj +jcinit.obj +jcmaster.obj +jcmarker.obj & >>$(RFILE)
+ echo +jcmainct.obj +jcprepct.obj +jccoefct.obj & >>$(RFILE)
+ echo +jccolor.obj +jcsample.obj +jchuff.obj +jcphuff.obj & >>$(RFILE)
+ echo +jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj & >>$(RFILE)
+ echo +jfdctint.obj +jdapimin.obj +jdapistd.obj & >>$(RFILE)
+ echo +jdtrans.obj +jdatasrc.obj +jdmaster.obj +jdinput.obj & >>$(RFILE)
+ echo +jdmarker.obj +jdhuff.obj +jdphuff.obj +jdmainct.obj & >>$(RFILE)
+ echo +jdcoefct.obj +jdpostct.obj +jddctmgr.obj & >>$(RFILE)
+ echo +jidctfst.obj +jidctflt.obj +jidctint.obj & >>$(RFILE)
+ echo +jidctred.obj +jdsample.obj +jdcolor.obj +jquant1.obj & >>$(RFILE)
+ echo +jquant2.obj +jdmerge.obj +jcomapi.obj +jutils.obj & >>$(RFILE)
+ echo +jerror.obj +jmemmgr.obj & >>$(RFILE)
+ echo $(SYSDEPMEMLIB) ; >>$(RFILE)
+
+cjpeg.exe: $(COBJECTS) libjpeg.lib
+ echo $(COBJECTS) >cjpeg.lst
+ link /STACK:4096 /EXEPACK @cjpeg.lst, cjpeg.exe, , libjpeg.lib, ;
+ del cjpeg.lst
+
+djpeg.exe: $(DOBJECTS) libjpeg.lib
+ echo $(DOBJECTS) >djpeg.lst
+ link /STACK:4096 /EXEPACK @djpeg.lst, djpeg.exe, , libjpeg.lib, ;
+ del djpeg.lst
+
+jpegtran.exe: $(TROBJECTS) libjpeg.lib
+ link /STACK:4096 /EXEPACK $(TROBJECTS), jpegtran.exe, , libjpeg.lib, ;
+
+rdjpgcom.exe: rdjpgcom.c
+ $(CC) -AS -O -W3 rdjpgcom.c
+
+# wrjpgcom needs large model so it can malloc a 64K chunk
+wrjpgcom.exe: wrjpgcom.c
+ $(CC) -AL -O -W3 wrjpgcom.c
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ del *.obj
+ del libjpeg.lib
+ del cjpeg.exe
+ del djpeg.exe
+ del jpegtran.exe
+ del rdjpgcom.exe
+ del wrjpgcom.exe
+ del testout*.*
+
+test: cjpeg.exe djpeg.exe jpegtran.exe
+ del testout*.*
+ djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ cjpeg -dct int -outfile testout.jpg testimg.ppm
+ djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ jpegtran -outfile testoutt.jpg testprog.jpg
+ fc /b testimg.ppm testout.ppm
+ fc /b testimg.bmp testout.bmp
+ fc /b testimg.jpg testout.jpg
+ fc /b testimg.ppm testoutp.ppm
+ fc /b testimgp.jpg testoutp.jpg
+ fc /b testorig.jpg testoutt.jpg
+
+
+jcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.obj: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.obj: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.obj: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+jmemdosa.obj : jmemdosa.asm
+ masm /mx $*;
diff --git a/osframework/source/ImageLib/jpeg/makefile.mms b/osframework/source/ImageLib/jpeg/makefile.mms
new file mode 100644
index 0000000..4ce8b89
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.mms
@@ -0,0 +1,218 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for use with MMS on Digital VMS systems.
+# Thanks to Rick Dyson (dyson@iowasp.physics.uiowa.edu)
+# and Tim Bell (tbell@netcom.com) for their help.
+
+# Read installation instructions before saying "MMS" !!
+
+# You may need to adjust these cc options:
+CFLAGS= $(CFLAGS) /NoDebug /Optimize
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via /Define switches here.
+.ifdef ALPHA
+OPT=
+.else
+OPT= ,Sys$Disk:[]MAKVMS.OPT/Option
+.endif
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Unix this is usually jmemnobs.o, but you may want
+# to use jmemansi.o or jmemname.o if you have limited swap space.
+SYSDEPMEM= jmemnobs.obj
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.obj jcapistd.obj jctrans.obj jcparam.obj jdatadst.obj \
+ jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj jcprepct.obj \
+ jccoefct.obj jccolor.obj jcsample.obj jchuff.obj jcphuff.obj \
+ jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj
+# decompression library object files
+DLIBOBJECTS= jdapimin.obj jdapistd.obj jdtrans.obj jdatasrc.obj \
+ jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdphuff.obj \
+ jdmainct.obj jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj \
+ jidctflt.obj jidctint.obj jidctred.obj jdsample.obj jdcolor.obj \
+ jquant1.obj jquant2.obj jdmerge.obj
+# These objectfiles are included in libjpeg.olb
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \
+ rdswitch.obj cdjpeg.obj
+DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
+ rdcolmap.obj cdjpeg.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+# objectfile lists with commas --- what a crock
+COBJLIST= cjpeg.obj,rdppm.obj,rdgif.obj,rdtarga.obj,rdrle.obj,rdbmp.obj,\
+ rdswitch.obj,cdjpeg.obj
+DOBJLIST= djpeg.obj,wrppm.obj,wrgif.obj,wrtarga.obj,wrrle.obj,wrbmp.obj,\
+ rdcolmap.obj,cdjpeg.obj
+TROBJLIST= jpegtran.obj,rdswitch.obj,cdjpeg.obj,transupp.obj
+LIBOBJLIST= jcapimin.obj,jcapistd.obj,jctrans.obj,jcparam.obj,jdatadst.obj,\
+ jcinit.obj,jcmaster.obj,jcmarker.obj,jcmainct.obj,jcprepct.obj,\
+ jccoefct.obj,jccolor.obj,jcsample.obj,jchuff.obj,jcphuff.obj,\
+ jcdctmgr.obj,jfdctfst.obj,jfdctflt.obj,jfdctint.obj,jdapimin.obj,\
+ jdapistd.obj,jdtrans.obj,jdatasrc.obj,jdmaster.obj,jdinput.obj,\
+ jdmarker.obj,jdhuff.obj,jdphuff.obj,jdmainct.obj,jdcoefct.obj,\
+ jdpostct.obj,jddctmgr.obj,jidctfst.obj,jidctflt.obj,jidctint.obj,\
+ jidctred.obj,jdsample.obj,jdcolor.obj,jquant1.obj,jquant2.obj,\
+ jdmerge.obj,jcomapi.obj,jutils.obj,jerror.obj,jmemmgr.obj,$(SYSDEPMEM)
+
+
+.first
+ @- Define /NoLog Sys Sys$Library
+
+ALL : libjpeg.olb cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+ @ Continue
+
+libjpeg.olb : $(LIBOBJECTS)
+ Library /Create libjpeg.olb $(LIBOBJLIST)
+
+cjpeg.exe : $(COBJECTS) libjpeg.olb
+ $(LINK) $(LFLAGS) /Executable = cjpeg.exe $(COBJLIST),libjpeg.olb/Library$(OPT)
+
+djpeg.exe : $(DOBJECTS) libjpeg.olb
+ $(LINK) $(LFLAGS) /Executable = djpeg.exe $(DOBJLIST),libjpeg.olb/Library$(OPT)
+
+jpegtran.exe : $(TROBJECTS) libjpeg.olb
+ $(LINK) $(LFLAGS) /Executable = jpegtran.exe $(TROBJLIST),libjpeg.olb/Library$(OPT)
+
+rdjpgcom.exe : rdjpgcom.obj
+ $(LINK) $(LFLAGS) /Executable = rdjpgcom.exe rdjpgcom.obj$(OPT)
+
+wrjpgcom.exe : wrjpgcom.obj
+ $(LINK) $(LFLAGS) /Executable = wrjpgcom.exe wrjpgcom.obj$(OPT)
+
+jconfig.h : jconfig.vms
+ @- Copy jconfig.vms jconfig.h
+
+clean :
+ @- Set Protection = Owner:RWED *.*;-1
+ @- Set Protection = Owner:RWED *.OBJ
+ - Purge /NoLog /NoConfirm *.*
+ - Delete /NoLog /NoConfirm *.OBJ;
+
+test : cjpeg.exe djpeg.exe jpegtran.exe
+ mcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ mcr sys$disk:[]djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ mcr sys$disk:[]cjpeg -dct int -outfile testout.jpg testimg.ppm
+ mcr sys$disk:[]djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ mcr sys$disk:[]cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ mcr sys$disk:[]jpegtran -outfile testoutt.jpg testprog.jpg
+ - Backup /Compare/Log testimg.ppm testout.ppm
+ - Backup /Compare/Log testimg.bmp testout.bmp
+ - Backup /Compare/Log testimg.jpg testout.jpg
+ - Backup /Compare/Log testimg.ppm testoutp.ppm
+ - Backup /Compare/Log testimgp.jpg testoutp.jpg
+ - Backup /Compare/Log testorig.jpg testoutt.jpg
+
+
+jcapimin.obj : jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.obj : jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.obj : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.obj : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.obj : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.obj : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.obj : jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.obj : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.obj : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.obj : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.obj : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.obj : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.obj : jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.obj : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.obj : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.obj : jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.obj : jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.obj : jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.obj : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.obj : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.obj : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.obj : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.obj : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.obj : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.obj : jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.obj : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.obj : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.obj : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.obj : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.obj : jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.obj : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.obj : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.obj : jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.obj : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.obj : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.obj : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.obj : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.obj : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.obj : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.obj : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.obj : jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.obj : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.obj : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.obj : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.obj : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.obj : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.obj : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.obj : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.obj : jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.obj : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.obj : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.obj : jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.obj : rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.obj : wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.obj : cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.obj : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.obj : rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.obj : transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.obj : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.obj : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.obj : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.obj : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.obj : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.obj : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.obj : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.obj : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.obj : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.obj : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.sas b/osframework/source/ImageLib/jpeg/makefile.sas
new file mode 100644
index 0000000..d26793d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.sas
@@ -0,0 +1,252 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for Amiga systems using SAS C 6.0 and up.
+# Thanks to Ed Hanway, Mark Rinfret, and Jim Zepeda.
+
+# Read installation instructions before saying "make" !!
+
+# The name of your C compiler:
+CC= sc
+
+# You may need to adjust these cc options:
+# Uncomment the following lines for generic 680x0 version
+ARCHFLAGS= cpu=any
+SUFFIX=
+
+# Uncomment the following lines for 68030-only version
+#ARCHFLAGS= cpu=68030
+#SUFFIX=.030
+
+CFLAGS= nostackcheck data=near parms=register optimize $(ARCHFLAGS) \
+ ignore=104 ignore=304 ignore=306
+# ignore=104 disables warnings for mismatched const qualifiers
+# ignore=304 disables warnings for variables being optimized out
+# ignore=306 disables warnings for the inlining of functions
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via define switches here.
+
+# Link-time cc options:
+LDFLAGS= SC SD ND BATCH
+
+# To link any special libraries, add the necessary commands here.
+LDLIBS= LIB:scm.lib LIB:sc.lib
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Amiga we recommend jmemname.o.
+SYSDEPMEM= jmemname.o
+
+# miscellaneous OS-dependent stuff
+# linker
+LN= slink
+# file deletion command
+RM= delete quiet
+# library (.lib) file creation command
+AR= oml
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
+# decompression library object files
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
+
+
+all: libjpeg.lib cjpeg$(SUFFIX) djpeg$(SUFFIX) jpegtran$(SUFFIX) rdjpgcom$(SUFFIX) wrjpgcom$(SUFFIX)
+
+# note: do several AR steps to avoid command line length limitations
+
+libjpeg.lib: $(LIBOBJECTS)
+ -$(RM) libjpeg.lib
+ $(AR) libjpeg.lib r $(CLIBOBJECTS)
+ $(AR) libjpeg.lib r $(DLIBOBJECTS)
+ $(AR) libjpeg.lib r $(COMOBJECTS)
+
+cjpeg$(SUFFIX): $(COBJECTS) libjpeg.lib
+ $(LN) <WITH <
+$(LDFLAGS)
+TO cjpeg$(SUFFIX)
+FROM LIB:c.o $(COBJECTS)
+LIB libjpeg.lib $(LDLIBS)
+<
+
+djpeg$(SUFFIX): $(DOBJECTS) libjpeg.lib
+ $(LN) <WITH <
+$(LDFLAGS)
+TO djpeg$(SUFFIX)
+FROM LIB:c.o $(DOBJECTS)
+LIB libjpeg.lib $(LDLIBS)
+<
+
+jpegtran$(SUFFIX): $(TROBJECTS) libjpeg.lib
+ $(LN) <WITH <
+$(LDFLAGS)
+TO jpegtran$(SUFFIX)
+FROM LIB:c.o $(TROBJECTS)
+LIB libjpeg.lib $(LDLIBS)
+<
+
+rdjpgcom$(SUFFIX): rdjpgcom.o
+ $(LN) <WITH <
+$(LDFLAGS)
+TO rdjpgcom$(SUFFIX)
+FROM LIB:c.o rdjpgcom.o
+LIB $(LDLIBS)
+<
+
+wrjpgcom$(SUFFIX): wrjpgcom.o
+ $(LN) <WITH <
+$(LDFLAGS)
+TO wrjpgcom$(SUFFIX)
+FROM LIB:c.o wrjpgcom.o
+LIB $(LDLIBS)
+<
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ -$(RM) *.o cjpeg djpeg jpegtran cjpeg.030 djpeg.030 jpegtran.030
+ -$(RM) rdjpgcom wrjpgcom rdjpgcom.030 wrjpgcom.030
+ -$(RM) libjpeg.lib core testout*.*
+
+test: cjpeg djpeg jpegtran
+ -$(RM) testout*.*
+ djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ cjpeg -dct int -outfile testout.jpg testimg.ppm
+ djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ jpegtran -outfile testoutt.jpg testprog.jpg
+ cmp testimg.ppm testout.ppm
+ cmp testimg.bmp testout.bmp
+ cmp testimg.jpg testout.jpg
+ cmp testimg.ppm testoutp.ppm
+ cmp testimgp.jpg testoutp.jpg
+ cmp testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.unix b/osframework/source/ImageLib/jpeg/makefile.unix
new file mode 100644
index 0000000..069ca71
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.unix
@@ -0,0 +1,228 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is suitable for Unix-like systems with non-ANSI compilers.
+# If you have an ANSI compiler, makefile.ansi is a better starting point.
+
+# Read installation instructions before saying "make" !!
+
+# The name of your C compiler:
+CC= cc
+
+# You may need to adjust these cc options:
+CFLAGS= -O
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+# However, any special defines for ansi2knr.c may be included here:
+ANSI2KNRFLAGS=
+
+# Link-time cc options:
+LDFLAGS=
+
+# To link any special libraries, add the necessary -l commands here.
+LDLIBS=
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For Unix this is usually jmemnobs.o, but you may want
+# to use jmemansi.o or jmemname.o if you have limited swap space.
+SYSDEPMEM= jmemnobs.o
+
+# miscellaneous OS-dependent stuff
+# linker
+LN= $(CC)
+# file deletion command
+RM= rm -f
+# file rename command
+MV= mv
+# library (.a) file creation command
+AR= ar rc
+# second step in .a creation (use "touch" if not needed)
+AR2= ranlib
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.o jcapistd.o jctrans.o jcparam.o jdatadst.o jcinit.o \
+ jcmaster.o jcmarker.o jcmainct.o jcprepct.o jccoefct.o jccolor.o \
+ jcsample.o jchuff.o jcphuff.o jcdctmgr.o jfdctfst.o jfdctflt.o \
+ jfdctint.o
+# decompression library object files
+DLIBOBJECTS= jdapimin.o jdapistd.o jdtrans.o jdatasrc.o jdmaster.o \
+ jdinput.o jdmarker.o jdhuff.o jdphuff.o jdmainct.o jdcoefct.o \
+ jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
+ jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
+# These objectfiles are included in libjpeg.a
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \
+ cdjpeg.o
+DOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \
+ cdjpeg.o
+TROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o
+
+
+all: ansi2knr libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom
+
+# This rule causes ansi2knr to be invoked.
+.c.o:
+ ./ansi2knr $*.c T$*.c
+ $(CC) $(CFLAGS) -c T$*.c
+ $(RM) T$*.c $*.o
+ $(MV) T$*.o $*.o
+
+ansi2knr: ansi2knr.c
+ $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
+
+libjpeg.a: ansi2knr $(LIBOBJECTS)
+ $(RM) libjpeg.a
+ $(AR) libjpeg.a $(LIBOBJECTS)
+ $(AR2) libjpeg.a
+
+cjpeg: ansi2knr $(COBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
+
+djpeg: ansi2knr $(DOBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
+
+jpegtran: ansi2knr $(TROBJECTS) libjpeg.a
+ $(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)
+
+rdjpgcom: rdjpgcom.o
+ $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
+
+wrjpgcom: wrjpgcom.o
+ $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean:
+ $(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom
+ $(RM) ansi2knr core testout*
+
+test: cjpeg djpeg jpegtran
+ $(RM) testout*
+ ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ ./cjpeg -dct int -outfile testout.jpg testimg.ppm
+ ./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ ./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ ./jpegtran -outfile testoutt.jpg testprog.jpg
+ cmp testimg.ppm testout.ppm
+ cmp testimg.bmp testout.bmp
+ cmp testimg.jpg testout.jpg
+ cmp testimg.ppm testoutp.ppm
+ cmp testimgp.jpg testoutp.jpg
+ cmp testorig.jpg testoutt.jpg
+
+
+jcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.o: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.o: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.o: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.vc b/osframework/source/ImageLib/jpeg/makefile.vc
new file mode 100644
index 0000000..da851be
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.vc
@@ -0,0 +1,211 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is for Microsoft Visual C++ on Windows NT (and 95?).
+# It builds the IJG library as a statically linkable library (.LIB),
+# and builds the sample applications as console-mode apps.
+# Thanks to Xingong Chang, Raymond Everly and others.
+
+# Read installation instructions before saying "nmake" !!
+# To build an optimized library without debug info, say "nmake nodebug=1".
+
+# Pull in standard variable definitions
+!include <win32.mak>
+
+# You may want to adjust these compiler options:
+CFLAGS= $(cflags) $(cdebug) $(cvars) -I.
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Link-time options:
+LDFLAGS= $(ldebug) $(conlflags)
+
+# To link any special libraries, add the necessary commands here.
+LDLIBS= $(conlibs)
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. For NT we suggest jmemnobs.obj, which expects the OS to
+# provide adequate virtual memory.
+SYSDEPMEM= jmemnobs.obj
+
+# miscellaneous OS-dependent stuff
+# file deletion command
+RM= del
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc \
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc \
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds \
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.obj jcapistd.obj jctrans.obj jcparam.obj jdatadst.obj \
+ jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj jcprepct.obj \
+ jccoefct.obj jccolor.obj jcsample.obj jchuff.obj jcphuff.obj \
+ jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj
+# decompression library object files
+DLIBOBJECTS= jdapimin.obj jdapistd.obj jdtrans.obj jdatasrc.obj \
+ jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdphuff.obj \
+ jdmainct.obj jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj \
+ jidctflt.obj jidctint.obj jidctred.obj jdsample.obj jdcolor.obj \
+ jquant1.obj jquant2.obj jdmerge.obj
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \
+ rdswitch.obj cdjpeg.obj
+DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
+ rdcolmap.obj cdjpeg.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+
+# Template command for compiling .c to .obj
+.c.obj:
+ $(cc) $(CFLAGS) $*.c
+
+
+all: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+
+libjpeg.lib: $(LIBOBJECTS)
+ $(RM) libjpeg.lib
+ lib -out:libjpeg.lib $(LIBOBJECTS)
+
+cjpeg.exe: $(COBJECTS) libjpeg.lib
+ $(link) $(LDFLAGS) -out:cjpeg.exe $(COBJECTS) libjpeg.lib $(LDLIBS)
+
+djpeg.exe: $(DOBJECTS) libjpeg.lib
+ $(link) $(LDFLAGS) -out:djpeg.exe $(DOBJECTS) libjpeg.lib $(LDLIBS)
+
+jpegtran.exe: $(TROBJECTS) libjpeg.lib
+ $(link) $(LDFLAGS) -out:jpegtran.exe $(TROBJECTS) libjpeg.lib $(LDLIBS)
+
+rdjpgcom.exe: rdjpgcom.obj
+ $(link) $(LDFLAGS) -out:rdjpgcom.exe rdjpgcom.obj $(LDLIBS)
+
+wrjpgcom.exe: wrjpgcom.obj
+ $(link) $(LDFLAGS) -out:wrjpgcom.exe wrjpgcom.obj $(LDLIBS)
+
+
+clean:
+ $(RM) *.obj *.exe libjpeg.lib
+ $(RM) testout*
+
+test: cjpeg.exe djpeg.exe jpegtran.exe
+ $(RM) testout*
+ .\djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ .\djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ .\cjpeg -dct int -outfile testout.jpg testimg.ppm
+ .\djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ .\cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ .\jpegtran -outfile testoutt.jpg testprog.jpg
+ fc /b testimg.ppm testout.ppm
+ fc /b testimg.bmp testout.bmp
+ fc /b testimg.jpg testout.jpg
+ fc /b testimg.ppm testoutp.ppm
+ fc /b testimgp.jpg testoutp.jpg
+ fc /b testorig.jpg testoutt.jpg
+
+
+jcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.obj: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.obj: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.obj: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makefile.vms b/osframework/source/ImageLib/jpeg/makefile.vms
new file mode 100644
index 0000000..711f852
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.vms
@@ -0,0 +1,142 @@
+$! Makefile for Independent JPEG Group's software
+$!
+$! This is a command procedure for Digital VMS systems that do not have MMS.
+$! It builds the JPEG software by brute force, recompiling everything whether
+$! or not it is necessary. It then runs the basic self-test.
+$! Thanks to Rick Dyson (dyson@iowasp.physics.uiowa.edu)
+$! and Tim Bell (tbell@netcom.com) for their help.
+$!
+$! Read installation instructions before running this!!
+$!
+$ If F$Mode () .eqs. "INTERACTIVE"
+$ Then
+$ VERIFY = F$Verify (0)
+$ Else
+$ VERIFY = F$Verify (1)
+$ EndIf
+$ On Control_Y Then GoTo End
+$ On Error Then GoTo End
+$
+$ If F$GetSyi ("HW_MODEL") .gt. 1023
+$ Then
+$ OPT = ""
+$ Else
+$ OPT = ",Sys$Disk:[]makvms.opt/Option"
+$ EndIf
+$
+$ DoCompile := CC /NoDebug /Optimize /NoList
+$!
+$ DoCompile jcapimin.c
+$ DoCompile jcapistd.c
+$ DoCompile jctrans.c
+$ DoCompile jcparam.c
+$ DoCompile jdatadst.c
+$ DoCompile jcinit.c
+$ DoCompile jcmaster.c
+$ DoCompile jcmarker.c
+$ DoCompile jcmainct.c
+$ DoCompile jcprepct.c
+$ DoCompile jccoefct.c
+$ DoCompile jccolor.c
+$ DoCompile jcsample.c
+$ DoCompile jchuff.c
+$ DoCompile jcphuff.c
+$ DoCompile jcdctmgr.c
+$ DoCompile jfdctfst.c
+$ DoCompile jfdctflt.c
+$ DoCompile jfdctint.c
+$ DoCompile jdapimin.c
+$ DoCompile jdapistd.c
+$ DoCompile jdtrans.c
+$ DoCompile jdatasrc.c
+$ DoCompile jdmaster.c
+$ DoCompile jdinput.c
+$ DoCompile jdmarker.c
+$ DoCompile jdhuff.c
+$ DoCompile jdphuff.c
+$ DoCompile jdmainct.c
+$ DoCompile jdcoefct.c
+$ DoCompile jdpostct.c
+$ DoCompile jddctmgr.c
+$ DoCompile jidctfst.c
+$ DoCompile jidctflt.c
+$ DoCompile jidctint.c
+$ DoCompile jidctred.c
+$ DoCompile jdsample.c
+$ DoCompile jdcolor.c
+$ DoCompile jquant1.c
+$ DoCompile jquant2.c
+$ DoCompile jdmerge.c
+$ DoCompile jcomapi.c
+$ DoCompile jutils.c
+$ DoCompile jerror.c
+$ DoCompile jmemmgr.c
+$ DoCompile jmemnobs.c
+$!
+$ Library /Create libjpeg.olb jcapimin.obj,jcapistd.obj,jctrans.obj, -
+ jcparam.obj,jdatadst.obj,jcinit.obj,jcmaster.obj,jcmarker.obj, -
+ jcmainct.obj,jcprepct.obj,jccoefct.obj,jccolor.obj,jcsample.obj, -
+ jchuff.obj,jcphuff.obj,jcdctmgr.obj,jfdctfst.obj,jfdctflt.obj, -
+ jfdctint.obj,jdapimin.obj,jdapistd.obj,jdtrans.obj,jdatasrc.obj, -
+ jdmaster.obj,jdinput.obj,jdmarker.obj,jdhuff.obj,jdphuff.obj, -
+ jdmainct.obj,jdcoefct.obj,jdpostct.obj,jddctmgr.obj,jidctfst.obj, -
+ jidctflt.obj,jidctint.obj,jidctred.obj,jdsample.obj,jdcolor.obj, -
+ jquant1.obj,jquant2.obj,jdmerge.obj,jcomapi.obj,jutils.obj, -
+ jerror.obj,jmemmgr.obj,jmemnobs.obj
+$!
+$ DoCompile cjpeg.c
+$ DoCompile rdppm.c
+$ DoCompile rdgif.c
+$ DoCompile rdtarga.c
+$ DoCompile rdrle.c
+$ DoCompile rdbmp.c
+$ DoCompile rdswitch.c
+$ DoCompile cdjpeg.c
+$!
+$ Link /NoMap /Executable = cjpeg.exe cjpeg.obj,rdppm.obj,rdgif.obj, -
+ rdtarga.obj,rdrle.obj,rdbmp.obj,rdswitch.obj,cdjpeg.obj,libjpeg.olb/Library'OPT'
+$!
+$ DoCompile djpeg.c
+$ DoCompile wrppm.c
+$ DoCompile wrgif.c
+$ DoCompile wrtarga.c
+$ DoCompile wrrle.c
+$ DoCompile wrbmp.c
+$ DoCompile rdcolmap.c
+$ DoCompile cdjpeg.c
+$!
+$ Link /NoMap /Executable = djpeg.exe djpeg.obj,wrppm.obj,wrgif.obj, -
+ wrtarga.obj,wrrle.obj,wrbmp.obj,rdcolmap.obj,cdjpeg.obj,libjpeg.olb/Library'OPT'
+$!
+$ DoCompile jpegtran.c
+$ DoCompile rdswitch.c
+$ DoCompile cdjpeg.c
+$ DoCompile transupp.c
+$!
+$ Link /NoMap /Executable = jpegtran.exe jpegtran.obj,rdswitch.obj, -
+ cdjpeg.obj,transupp.obj,libjpeg.olb/Library'OPT'
+$!
+$ DoCompile rdjpgcom.c
+$ Link /NoMap /Executable = rdjpgcom.exe rdjpgcom.obj'OPT'
+$!
+$ DoCompile wrjpgcom.c
+$ Link /NoMap /Executable = wrjpgcom.exe wrjpgcom.obj'OPT'
+$!
+$! Run the self-test
+$!
+$ mcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+$ mcr sys$disk:[]djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+$ mcr sys$disk:[]cjpeg -dct int -outfile testout.jpg testimg.ppm
+$ mcr sys$disk:[]djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+$ mcr sys$disk:[]cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+$ mcr sys$disk:[]jpegtran -outfile testoutt.jpg testprog.jpg
+$ Backup /Compare/Log testimg.ppm testout.ppm
+$ Backup /Compare/Log testimg.bmp testout.bmp
+$ Backup /Compare/Log testimg.jpg testout.jpg
+$ Backup /Compare/Log testimg.ppm testoutp.ppm
+$ Backup /Compare/Log testimgp.jpg testoutp.jpg
+$ Backup /Compare/Log testorig.jpg testoutt.jpg
+$!
+$End:
+$ If Verify Then Set Verify
+$ Exit
diff --git a/osframework/source/ImageLib/jpeg/makefile.wat b/osframework/source/ImageLib/jpeg/makefile.wat
new file mode 100644
index 0000000..c0570dc
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makefile.wat
@@ -0,0 +1,233 @@
+# Makefile for Independent JPEG Group's software
+
+# This makefile is suitable for Watcom C/C++ 10.0 on MS-DOS (using
+# dos4g extender), OS/2, and Windows NT console mode.
+# Thanks to Janos Haide, jhaide@btrvtech.com.
+
+# Read installation instructions before saying "wmake" !!
+
+# Uncomment line for desired system
+SYSTEM=DOS
+#SYSTEM=OS2
+#SYSTEM=NT
+
+# The name of your C compiler:
+CC= wcl386
+
+# You may need to adjust these cc options:
+CFLAGS= -4r -ort -wx -zq -bt=$(SYSTEM)
+# Caution: avoid -ol or -ox; these generate bad code with 10.0 or 10.0a.
+# Generally, we recommend defining any configuration symbols in jconfig.h,
+# NOT via -D switches here.
+
+# Link-time cc options:
+!ifeq SYSTEM DOS
+LDFLAGS= -zq -l=dos4g
+!else ifeq SYSTEM OS2
+LDFLAGS= -zq -l=os2v2
+!else ifeq SYSTEM NT
+LDFLAGS= -zq -l=nt
+!endif
+
+# Put here the object file name for the correct system-dependent memory
+# manager file. jmemnobs should work fine for dos4g or OS/2 environment.
+SYSDEPMEM= jmemnobs.obj
+
+# End of configurable options.
+
+
+# source files: JPEG library proper
+LIBSOURCES= jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c &
+ jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c &
+ jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c &
+ jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c &
+ jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c &
+ jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c &
+ jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c &
+ jquant2.c jutils.c jmemmgr.c
+# memmgr back ends: compile only one of these into a working library
+SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
+# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
+APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c &
+ rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c &
+ rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
+SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
+# files included by source files
+INCLUDES= jchuff.h jdhuff.h jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h &
+ jpegint.h jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h
+# documentation, test, and support files
+DOCS= README install.doc usage.doc cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 &
+ wrjpgcom.1 wizard.doc example.c libjpeg.doc structure.doc &
+ coderules.doc filelist.doc change.log
+MKFILES= configure makefile.cfg makefile.ansi makefile.unix makefile.bcc &
+ makefile.mc6 makefile.dj makefile.wat makefile.vc makelib.ds &
+ makeapps.ds makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st &
+ maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms &
+ makvms.opt
+CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat &
+ jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas &
+ jconfig.vms
+CONFIGUREFILES= config.guess config.sub install-sh ltconfig ltmain.sh
+OTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
+TESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg &
+ testimgp.jpg
+DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) &
+ $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
+# library object files common to compression and decompression
+COMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+# compression library object files
+CLIBOBJECTS= jcapimin.obj jcapistd.obj jctrans.obj jcparam.obj jdatadst.obj &
+ jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj jcprepct.obj &
+ jccoefct.obj jccolor.obj jcsample.obj jchuff.obj jcphuff.obj &
+ jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj
+# decompression library object files
+DLIBOBJECTS= jdapimin.obj jdapistd.obj jdtrans.obj jdatasrc.obj &
+ jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdphuff.obj &
+ jdmainct.obj jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj &
+ jidctflt.obj jidctint.obj jidctred.obj jdsample.obj jdcolor.obj &
+ jquant1.obj jquant2.obj jdmerge.obj
+# These objectfiles are included in libjpeg.lib
+LIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
+# object files for sample applications (excluding library files)
+COBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj &
+ rdswitch.obj cdjpeg.obj
+DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj &
+ rdcolmap.obj cdjpeg.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+
+
+all: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
+
+libjpeg.lib: $(LIBOBJECTS)
+ - del libjpeg.lib
+ * wlib -n libjpeg.lib $(LIBOBJECTS)
+
+cjpeg.exe: $(COBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) $(COBJECTS) libjpeg.lib
+
+djpeg.exe: $(DOBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) $(DOBJECTS) libjpeg.lib
+
+jpegtran.exe: $(TROBJECTS) libjpeg.lib
+ $(CC) $(LDFLAGS) $(TROBJECTS) libjpeg.lib
+
+rdjpgcom.exe: rdjpgcom.c
+ $(CC) $(CFLAGS) $(LDFLAGS) rdjpgcom.c
+
+wrjpgcom.exe: wrjpgcom.c
+ $(CC) $(CFLAGS) $(LDFLAGS) wrjpgcom.c
+
+.c.obj:
+ $(CC) $(CFLAGS) -c $<
+
+jconfig.h: jconfig.doc
+ echo You must prepare a system-dependent jconfig.h file.
+ echo Please read the installation directions in install.doc.
+ exit 1
+
+clean: .SYMBOLIC
+ - del *.obj
+ - del libjpeg.lib
+ - del cjpeg.exe
+ - del djpeg.exe
+ - del jpegtran.exe
+ - del rdjpgcom.exe
+ - del wrjpgcom.exe
+ - del testout*.*
+
+test: cjpeg.exe djpeg.exe jpegtran.exe .SYMBOLIC
+ - del testout*.*
+ djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
+ djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg
+ cjpeg -dct int -outfile testout.jpg testimg.ppm
+ djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg
+ cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm
+ jpegtran -outfile testoutt.jpg testprog.jpg
+!ifeq SYSTEM DOS
+ fc /b testimg.ppm testout.ppm
+ fc /b testimg.bmp testout.bmp
+ fc /b testimg.jpg testout.jpg
+ fc /b testimg.ppm testoutp.ppm
+ fc /b testimgp.jpg testoutp.jpg
+ fc /b testorig.jpg testoutt.jpg
+!else
+ echo n > n.tmp
+ comp testimg.ppm testout.ppm < n.tmp
+ comp testimg.bmp testout.bmp < n.tmp
+ comp testimg.jpg testout.jpg < n.tmp
+ comp testimg.ppm testoutp.ppm < n.tmp
+ comp testimgp.jpg testoutp.jpg < n.tmp
+ comp testorig.jpg testoutt.jpg < n.tmp
+ del n.tmp
+!endif
+
+
+jcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcphuff.obj: jcphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jchuff.h
+jcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
+jdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdphuff.obj: jdphuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdhuff.h
+jdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
+jfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jidctred.obj: jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
+jquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
+jmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+jmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
+cjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+djpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
+jpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h
+rdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h
+wrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h
+cdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+transupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h
+rdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+rdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
+wrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
diff --git a/osframework/source/ImageLib/jpeg/makelib.ds b/osframework/source/ImageLib/jpeg/makelib.ds
new file mode 100644
index 0000000..78d0ddf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makelib.ds
@@ -0,0 +1,1046 @@
+# Microsoft Developer Studio Generated NMAKE File, Format Version 4.20
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+!IF "$(CFG)" == ""
+CFG=jpeg - Win32
+!MESSAGE No configuration specified. Defaulting to jpeg - Win32.
+!ENDIF
+
+!IF "$(CFG)" != "jpeg - Win32"
+!MESSAGE Invalid configuration "$(CFG)" specified.
+!MESSAGE You can specify a configuration when running NMAKE on this makefile
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "jpeg.mak" CFG="jpeg - Win32"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "jpeg - Win32" (based on "Win32 (x86) Static Library")
+!MESSAGE
+!ERROR An invalid configuration is specified.
+!ENDIF
+
+!IF "$(OS)" == "Windows_NT"
+NULL=
+!ELSE
+NULL=nul
+!ENDIF
+################################################################################
+# Begin Project
+# PROP Target_Last_Scanned "jpeg - Win32"
+CPP=cl.exe
+
+!IF "$(CFG)" == "jpeg - Win32"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+OUTDIR=.\Release
+INTDIR=.\Release
+
+ALL : "$(OUTDIR)\jpeg.lib"
+
+CLEAN :
+ -@erase "$(INTDIR)\jcapimin.obj"
+ -@erase "$(INTDIR)\jcapistd.obj"
+ -@erase "$(INTDIR)\jctrans.obj"
+ -@erase "$(INTDIR)\jcparam.obj"
+ -@erase "$(INTDIR)\jdatadst.obj"
+ -@erase "$(INTDIR)\jcinit.obj"
+ -@erase "$(INTDIR)\jcmaster.obj"
+ -@erase "$(INTDIR)\jcmarker.obj"
+ -@erase "$(INTDIR)\jcmainct.obj"
+ -@erase "$(INTDIR)\jcprepct.obj"
+ -@erase "$(INTDIR)\jccoefct.obj"
+ -@erase "$(INTDIR)\jccolor.obj"
+ -@erase "$(INTDIR)\jcsample.obj"
+ -@erase "$(INTDIR)\jchuff.obj"
+ -@erase "$(INTDIR)\jcphuff.obj"
+ -@erase "$(INTDIR)\jcdctmgr.obj"
+ -@erase "$(INTDIR)\jfdctfst.obj"
+ -@erase "$(INTDIR)\jfdctflt.obj"
+ -@erase "$(INTDIR)\jfdctint.obj"
+ -@erase "$(INTDIR)\jdapimin.obj"
+ -@erase "$(INTDIR)\jdapistd.obj"
+ -@erase "$(INTDIR)\jdtrans.obj"
+ -@erase "$(INTDIR)\jdatasrc.obj"
+ -@erase "$(INTDIR)\jdmaster.obj"
+ -@erase "$(INTDIR)\jdinput.obj"
+ -@erase "$(INTDIR)\jdmarker.obj"
+ -@erase "$(INTDIR)\jdhuff.obj"
+ -@erase "$(INTDIR)\jdphuff.obj"
+ -@erase "$(INTDIR)\jdmainct.obj"
+ -@erase "$(INTDIR)\jdcoefct.obj"
+ -@erase "$(INTDIR)\jdpostct.obj"
+ -@erase "$(INTDIR)\jddctmgr.obj"
+ -@erase "$(INTDIR)\jidctfst.obj"
+ -@erase "$(INTDIR)\jidctflt.obj"
+ -@erase "$(INTDIR)\jidctint.obj"
+ -@erase "$(INTDIR)\jidctred.obj"
+ -@erase "$(INTDIR)\jdsample.obj"
+ -@erase "$(INTDIR)\jdcolor.obj"
+ -@erase "$(INTDIR)\jquant1.obj"
+ -@erase "$(INTDIR)\jquant2.obj"
+ -@erase "$(INTDIR)\jdmerge.obj"
+ -@erase "$(INTDIR)\jcomapi.obj"
+ -@erase "$(INTDIR)\jutils.obj"
+ -@erase "$(INTDIR)\jerror.obj"
+ -@erase "$(INTDIR)\jmemmgr.obj"
+ -@erase "$(INTDIR)\jmemnobs.obj"
+ -@erase "$(OUTDIR)\jpeg.lib"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
+CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
+ /Fp"$(INTDIR)/jpeg.pch" /YX /Fo"$(INTDIR)/" /c
+CPP_OBJS=.\Release/
+CPP_SBRS=.\.
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o"$(OUTDIR)/jpeg.bsc"
+BSC32_SBRS= \
+
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+LIB32_FLAGS=/nologo /out:"$(OUTDIR)/jpeg.lib"
+LIB32_OBJS= \
+ "$(INTDIR)\jcapimin.obj" \
+ "$(INTDIR)\jcapistd.obj" \
+ "$(INTDIR)\jctrans.obj" \
+ "$(INTDIR)\jcparam.obj" \
+ "$(INTDIR)\jdatadst.obj" \
+ "$(INTDIR)\jcinit.obj" \
+ "$(INTDIR)\jcmaster.obj" \
+ "$(INTDIR)\jcmarker.obj" \
+ "$(INTDIR)\jcmainct.obj" \
+ "$(INTDIR)\jcprepct.obj" \
+ "$(INTDIR)\jccoefct.obj" \
+ "$(INTDIR)\jccolor.obj" \
+ "$(INTDIR)\jcsample.obj" \
+ "$(INTDIR)\jchuff.obj" \
+ "$(INTDIR)\jcphuff.obj" \
+ "$(INTDIR)\jcdctmgr.obj" \
+ "$(INTDIR)\jfdctfst.obj" \
+ "$(INTDIR)\jfdctflt.obj" \
+ "$(INTDIR)\jfdctint.obj" \
+ "$(INTDIR)\jdapimin.obj" \
+ "$(INTDIR)\jdapistd.obj" \
+ "$(INTDIR)\jdtrans.obj" \
+ "$(INTDIR)\jdatasrc.obj" \
+ "$(INTDIR)\jdmaster.obj" \
+ "$(INTDIR)\jdinput.obj" \
+ "$(INTDIR)\jdmarker.obj" \
+ "$(INTDIR)\jdhuff.obj" \
+ "$(INTDIR)\jdphuff.obj" \
+ "$(INTDIR)\jdmainct.obj" \
+ "$(INTDIR)\jdcoefct.obj" \
+ "$(INTDIR)\jdpostct.obj" \
+ "$(INTDIR)\jddctmgr.obj" \
+ "$(INTDIR)\jidctfst.obj" \
+ "$(INTDIR)\jidctflt.obj" \
+ "$(INTDIR)\jidctint.obj" \
+ "$(INTDIR)\jidctred.obj" \
+ "$(INTDIR)\jdsample.obj" \
+ "$(INTDIR)\jdcolor.obj" \
+ "$(INTDIR)\jquant1.obj" \
+ "$(INTDIR)\jquant2.obj" \
+ "$(INTDIR)\jdmerge.obj" \
+ "$(INTDIR)\jcomapi.obj" \
+ "$(INTDIR)\jutils.obj" \
+ "$(INTDIR)\jerror.obj" \
+ "$(INTDIR)\jmemmgr.obj" \
+ "$(INTDIR)\jmemnobs.obj"
+
+"$(OUTDIR)\jpeg.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
+ $(LIB32) @<<
+ $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
+<<
+
+!ENDIF
+
+.c{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.cpp{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.cxx{$(CPP_OBJS)}.obj:
+ $(CPP) $(CPP_PROJ) $<
+
+.c{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+.cpp{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+.cxx{$(CPP_SBRS)}.sbr:
+ $(CPP) $(CPP_PROJ) $<
+
+################################################################################
+# Begin Target
+
+# Name "jpeg - Win32"
+
+!IF "$(CFG)" == "jpeg - Win32"
+
+!ENDIF
+
+################################################################################
+# Begin Source File
+
+SOURCE="jcapimin.c"
+DEP_CPP_JCAPI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcapimin.obj" : $(SOURCE) $(DEP_CPP_JCAPI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcapistd.c"
+DEP_CPP_JCAPIS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcapistd.obj" : $(SOURCE) $(DEP_CPP_JCAPIS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jccoefct.c"
+DEP_CPP_JCCOE=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jccoefct.obj" : $(SOURCE) $(DEP_CPP_JCCOE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jccolor.c"
+DEP_CPP_JCCOL=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jccolor.obj" : $(SOURCE) $(DEP_CPP_JCCOL) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcdctmgr.c"
+DEP_CPP_JCDCT=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jcdctmgr.obj" : $(SOURCE) $(DEP_CPP_JCDCT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jchuff.c"
+DEP_CPP_JCHUF=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jchuff.h"\
+
+
+"$(INTDIR)\jchuff.obj" : $(SOURCE) $(DEP_CPP_JCHUF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcinit.c"
+DEP_CPP_JCINI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcinit.obj" : $(SOURCE) $(DEP_CPP_JCINI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcmainct.c"
+DEP_CPP_JCMAI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcmainct.obj" : $(SOURCE) $(DEP_CPP_JCMAI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcmarker.c"
+DEP_CPP_JCMAR=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcmarker.obj" : $(SOURCE) $(DEP_CPP_JCMAR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcmaster.c"
+DEP_CPP_JCMAS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcmaster.obj" : $(SOURCE) $(DEP_CPP_JCMAS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcomapi.c"
+DEP_CPP_JCOMA=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcomapi.obj" : $(SOURCE) $(DEP_CPP_JCOMA) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcparam.c"
+DEP_CPP_JCPAR=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcparam.obj" : $(SOURCE) $(DEP_CPP_JCPAR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcphuff.c"
+DEP_CPP_JCPHU=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jchuff.h"\
+
+
+"$(INTDIR)\jcphuff.obj" : $(SOURCE) $(DEP_CPP_JCPHU) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcprepct.c"
+DEP_CPP_JCPRE=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcprepct.obj" : $(SOURCE) $(DEP_CPP_JCPRE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jcsample.c"
+DEP_CPP_JCSAM=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jcsample.obj" : $(SOURCE) $(DEP_CPP_JCSAM) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jctrans.c"
+DEP_CPP_JCTRA=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jctrans.obj" : $(SOURCE) $(DEP_CPP_JCTRA) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdapimin.c"
+DEP_CPP_JDAPI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdapimin.obj" : $(SOURCE) $(DEP_CPP_JDAPI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdapistd.c"
+DEP_CPP_JDAPIS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdapistd.obj" : $(SOURCE) $(DEP_CPP_JDAPIS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdatadst.c"
+DEP_CPP_JDATA=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdatadst.obj" : $(SOURCE) $(DEP_CPP_JDATA) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdatasrc.c"
+DEP_CPP_JDATAS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdatasrc.obj" : $(SOURCE) $(DEP_CPP_JDATAS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdcoefct.c"
+DEP_CPP_JDCOE=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdcoefct.obj" : $(SOURCE) $(DEP_CPP_JDCOE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdcolor.c"
+DEP_CPP_JDCOL=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdcolor.obj" : $(SOURCE) $(DEP_CPP_JDCOL) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jddctmgr.c"
+DEP_CPP_JDDCT=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jddctmgr.obj" : $(SOURCE) $(DEP_CPP_JDDCT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdhuff.c"
+DEP_CPP_JDHUF=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdhuff.h"\
+
+
+"$(INTDIR)\jdhuff.obj" : $(SOURCE) $(DEP_CPP_JDHUF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdinput.c"
+DEP_CPP_JDINP=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdinput.obj" : $(SOURCE) $(DEP_CPP_JDINP) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdmainct.c"
+DEP_CPP_JDMAI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdmainct.obj" : $(SOURCE) $(DEP_CPP_JDMAI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdmarker.c"
+DEP_CPP_JDMAR=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdmarker.obj" : $(SOURCE) $(DEP_CPP_JDMAR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdmaster.c"
+DEP_CPP_JDMAS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdmaster.obj" : $(SOURCE) $(DEP_CPP_JDMAS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdmerge.c"
+DEP_CPP_JDMER=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdmerge.obj" : $(SOURCE) $(DEP_CPP_JDMER) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdphuff.c"
+DEP_CPP_JDPHU=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdhuff.h"\
+
+
+"$(INTDIR)\jdphuff.obj" : $(SOURCE) $(DEP_CPP_JDPHU) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdpostct.c"
+DEP_CPP_JDPOS=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdpostct.obj" : $(SOURCE) $(DEP_CPP_JDPOS) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdsample.c"
+DEP_CPP_JDSAM=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdsample.obj" : $(SOURCE) $(DEP_CPP_JDSAM) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jdtrans.c"
+DEP_CPP_JDTRA=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jdtrans.obj" : $(SOURCE) $(DEP_CPP_JDTRA) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jerror.c"
+DEP_CPP_JERRO=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jversion.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jerror.obj" : $(SOURCE) $(DEP_CPP_JERRO) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jfdctflt.c"
+DEP_CPP_JFDCT=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jfdctflt.obj" : $(SOURCE) $(DEP_CPP_JFDCT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jfdctfst.c"
+DEP_CPP_JFDCTF=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jfdctfst.obj" : $(SOURCE) $(DEP_CPP_JFDCTF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jfdctint.c"
+DEP_CPP_JFDCTI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jfdctint.obj" : $(SOURCE) $(DEP_CPP_JFDCTI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jidctflt.c"
+DEP_CPP_JIDCT=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jidctflt.obj" : $(SOURCE) $(DEP_CPP_JIDCT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jidctfst.c"
+DEP_CPP_JIDCTF=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jidctfst.obj" : $(SOURCE) $(DEP_CPP_JIDCTF) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jidctint.c"
+DEP_CPP_JIDCTI=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jidctint.obj" : $(SOURCE) $(DEP_CPP_JIDCTI) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jidctred.c"
+DEP_CPP_JIDCTR=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jdct.h"\
+
+
+"$(INTDIR)\jidctred.obj" : $(SOURCE) $(DEP_CPP_JIDCTR) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jquant1.c"
+DEP_CPP_JQUAN=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jquant1.obj" : $(SOURCE) $(DEP_CPP_JQUAN) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jquant2.c"
+DEP_CPP_JQUANT=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jquant2.obj" : $(SOURCE) $(DEP_CPP_JQUANT) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jutils.c"
+DEP_CPP_JUTIL=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+
+
+"$(INTDIR)\jutils.obj" : $(SOURCE) $(DEP_CPP_JUTIL) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jmemmgr.c"
+DEP_CPP_JMEMM=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jmemsys.h"\
+
+
+"$(INTDIR)\jmemmgr.obj" : $(SOURCE) $(DEP_CPP_JMEMM) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE="jmemnobs.c"
+DEP_CPP_JMEMN=\
+ "jinclude.h"\
+ "jconfig.h"\
+ "jpeglib.h"\
+ "jmorecfg.h"\
+ "jpegint.h"\
+ "jerror.h"\
+ "jmemsys.h"\
+
+
+"$(INTDIR)\jmemnobs.obj" : $(SOURCE) $(DEP_CPP_JMEMN) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+# End Source File
+# End Target
+# End Project
+################################################################################
+
diff --git a/osframework/source/ImageLib/jpeg/makeproj.mac b/osframework/source/ImageLib/jpeg/makeproj.mac
new file mode 100644
index 0000000..cd466da
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makeproj.mac
@@ -0,0 +1,213 @@
+--
+-- makeproj.mac
+--
+-- This AppleScript builds Code Warrior PRO Release 2 project files for the
+-- libjpeg library as well as the test programs 'cjpeg', 'djpeg', 'jpegtran'.
+-- (We'd distribute real project files, except they're not text
+-- and would create maintenance headaches.)
+--
+-- The script then compiles and links the library and the test programs.
+-- NOTE: if you haven't already created a 'jconfig.h' file, the script
+-- automatically copies 'jconfig.mac' to 'jconfig.h'.
+--
+-- To use this script, you must have AppleScript 1.1 or later installed
+-- and a suitable AppleScript editor like Script Editor or Script Debugger
+-- (http://www.latenightsw.com). Open this file with your AppleScript
+-- editor and execute the "run" command to build the projects.
+--
+-- Thanks to Dan Sears and Don Agro for this script.
+-- Questions about this script can be addressed to dogpark@interlog.com
+--
+
+on run
+
+ choose folder with prompt ">>> Select IJG source folder <<<"
+ set ijg_folder to result
+
+ choose folder with prompt ">>> Select MetroWerks folder <<<"
+ set cw_folder to result
+
+ -- if jconfig.h doesn't already exist, copy jconfig.mac
+
+ tell application "Finder"
+ if not (exists file "jconfig.h" of ijg_folder) then
+ duplicate {file "jconfig.mac" of folder ijg_folder}
+ select file "jconfig.mac copy" of folder ijg_folder
+ set name of selection to "jconfig.h"
+ end if
+ end tell
+
+ tell application "CodeWarrior IDE 2.1"
+ with timeout of 10000 seconds
+
+ -- create libjpeg project
+
+ activate
+ Create Project (ijg_folder as string) & "libjpeg.proj"
+ Set Preferences of panel "Target Settings" to {Target Name:"libjpeg"}
+ Set Preferences of panel "PPC Project" to {File Name:"libjpeg"}
+ Set Preferences of panel "Target Settings" to {Linker:"MacOS PPC Linker"}
+ Set Preferences of panel "PPC Project" to {Project Type:library}
+ Set Preferences of panel "C/C++ Compiler" to {ANSI Strict:true}
+ Set Preferences of panel "C/C++ Compiler" to {Enums Always Ints:true}
+ Set Preferences of panel "PPC Codegen" to {Struct Alignment:PowerPC}
+ Set Preferences of panel "PPC Linker" to {Generate SYM File:false}
+
+ Add Files (ijg_folder as string) & "jcapimin.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcapistd.c" To Segment 1
+ Add Files (ijg_folder as string) & "jctrans.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcparam.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdatadst.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcinit.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcmaster.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcmarker.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcmainct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcprepct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jccoefct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jccolor.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcsample.c" To Segment 1
+ Add Files (ijg_folder as string) & "jchuff.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcphuff.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcdctmgr.c" To Segment 1
+ Add Files (ijg_folder as string) & "jfdctfst.c" To Segment 1
+ Add Files (ijg_folder as string) & "jfdctflt.c" To Segment 1
+ Add Files (ijg_folder as string) & "jfdctint.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdapimin.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdapistd.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdtrans.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdatasrc.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdmaster.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdinput.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdmarker.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdhuff.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdphuff.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdmainct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdcoefct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdpostct.c" To Segment 1
+ Add Files (ijg_folder as string) & "jddctmgr.c" To Segment 1
+ Add Files (ijg_folder as string) & "jidctfst.c" To Segment 1
+ Add Files (ijg_folder as string) & "jidctflt.c" To Segment 1
+ Add Files (ijg_folder as string) & "jidctint.c" To Segment 1
+ Add Files (ijg_folder as string) & "jidctred.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdsample.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdcolor.c" To Segment 1
+ Add Files (ijg_folder as string) & "jquant1.c" To Segment 1
+ Add Files (ijg_folder as string) & "jquant2.c" To Segment 1
+ Add Files (ijg_folder as string) & "jdmerge.c" To Segment 1
+ Add Files (ijg_folder as string) & "jcomapi.c" To Segment 1
+ Add Files (ijg_folder as string) & "jutils.c" To Segment 1
+ Add Files (ijg_folder as string) & "jerror.c" To Segment 1
+ Add Files (ijg_folder as string) & "jmemmgr.c" To Segment 1
+ Add Files (ijg_folder as string) & "jmemmac.c" To Segment 1
+
+ -- compile and link the library
+
+ Make Project
+ Close Project
+
+ -- create cjpeg project
+
+ activate
+ Create Project (ijg_folder as string) & "cjpeg.proj"
+ Set Preferences of panel "Target Settings" to {Target Name:"cjpeg"}
+ Set Preferences of panel "PPC Project" to {File Name:"cjpeg"}
+ Set Preferences of panel "Target Settings" to {Linker:"MacOS PPC Linker"}
+ Set Preferences of panel "C/C++ Compiler" to {ANSI Strict:true}
+ Set Preferences of panel "C/C++ Compiler" to {Enums Always Ints:true}
+ Set Preferences of panel "PPC Codegen" to {Struct Alignment:PowerPC}
+ Set Preferences of panel "PPC Linker" to {Generate SYM File:false}
+
+ Add Files (ijg_folder as string) & "cjpeg.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdppm.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdgif.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdtarga.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdrle.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdbmp.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdswitch.c" To Segment 1
+ Add Files (ijg_folder as string) & "cdjpeg.c" To Segment 1
+
+ Add Files (ijg_folder as string) & "libjpeg" To Segment 2
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib" To Segment 3
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib" To Segment 4
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib" To Segment 4
+
+ -- compile and link cjpeg
+
+ Make Project
+ Close Project
+
+ -- create djpeg project
+
+ activate
+ Create Project (ijg_folder as string) & "djpeg.proj"
+ Set Preferences of panel "Target Settings" to {Target Name:"djpeg"}
+ Set Preferences of panel "PPC Project" to {File Name:"djpeg"}
+ Set Preferences of panel "Target Settings" to {Linker:"MacOS PPC Linker"}
+ Set Preferences of panel "C/C++ Compiler" to {ANSI Strict:true}
+ Set Preferences of panel "C/C++ Compiler" to {Enums Always Ints:true}
+ Set Preferences of panel "PPC Codegen" to {Struct Alignment:PowerPC}
+ Set Preferences of panel "PPC Linker" to {Generate SYM File:false}
+
+ Add Files (ijg_folder as string) & "djpeg.c" To Segment 1
+ Add Files (ijg_folder as string) & "wrppm.c" To Segment 1
+ Add Files (ijg_folder as string) & "wrgif.c" To Segment 1
+ Add Files (ijg_folder as string) & "wrtarga.c" To Segment 1
+ Add Files (ijg_folder as string) & "wrrle.c" To Segment 1
+ Add Files (ijg_folder as string) & "wrbmp.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdcolmap.c" To Segment 1
+ Add Files (ijg_folder as string) & "cdjpeg.c" To Segment 1
+
+ Add Files (ijg_folder as string) & "libjpeg" To Segment 2
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib" To Segment 3
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib" To Segment 4
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib" To Segment 4
+
+ -- compile and link djpeg
+
+ Make Project
+ Close Project
+
+ -- create jpegtran project
+
+ activate
+ Create Project (ijg_folder as string) & "jpegtran.proj"
+ Set Preferences of panel "Target Settings" to {Target Name:"jpegtran"}
+ Set Preferences of panel "PPC Project" to {File Name:"jpegtran"}
+ Set Preferences of panel "Target Settings" to {Linker:"MacOS PPC Linker"}
+ Set Preferences of panel "C/C++ Compiler" to {ANSI Strict:true}
+ Set Preferences of panel "C/C++ Compiler" to {Enums Always Ints:true}
+ Set Preferences of panel "PPC Codegen" to {Struct Alignment:PowerPC}
+ Set Preferences of panel "PPC Linker" to {Generate SYM File:false}
+
+ Add Files (ijg_folder as string) & "jpegtran.c" To Segment 1
+ Add Files (ijg_folder as string) & "rdswitch.c" To Segment 1
+ Add Files (ijg_folder as string) & "cdjpeg.c" To Segment 1
+ Add Files (ijg_folder as string) & "transupp.c" To Segment 1
+
+ Add Files (ijg_folder as string) & "libjpeg" To Segment 2
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib" To Segment 3
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib" To Segment 3
+
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib" To Segment 4
+ Add Files (cw_folder as string) & "Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib" To Segment 4
+
+ -- compile and link jpegtran
+
+ Make Project
+ Close Project
+
+ quit
+
+ end timeout
+ end tell
+end run
diff --git a/osframework/source/ImageLib/jpeg/makljpeg.st b/osframework/source/ImageLib/jpeg/makljpeg.st
new file mode 100644
index 0000000..96bfb65
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makljpeg.st
@@ -0,0 +1,70 @@
+; Project file for Independent JPEG Group's software
+;
+; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
+; Thanks to Frank Moehle (Frank.Moehle@arbi.informatik.uni-oldenburg.de),
+; Dr. B. Setzepfandt (bernd@gina.uni-muenster.de),
+; and Guido Vollbeding (guivol@esc.de).
+;
+; To use this file, rename it to libjpeg.prj.
+; Read installation instructions before trying to make the program!
+;
+;
+; * * * Output file * * *
+libjpeg.lib
+;
+; * * * COMPILER OPTIONS * * *
+.C[-P] ; absolute calls
+.C[-M] ; and no string merging, folks
+.C[-w-cln] ; no "constant is long" warnings
+.C[-w-par] ; no "parameter xxxx unused"
+.C[-w-rch] ; no "unreachable code"
+.C[-wsig] ; warn if significant digits may be lost
+.L[-J] ; link new Obj-format (so we get a library)
+=
+; * * * * List of modules * * * *
+jcapimin.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcapistd.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jccoefct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jccolor.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcdctmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jchuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jchuff.h)
+jcinit.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcmainct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcmarker.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcmaster.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcomapi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcparam.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcphuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jchuff.h)
+jcprepct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jcsample.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jctrans.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdapimin.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdapistd.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdatadst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)
+jdatasrc.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)
+jdcoefct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdcolor.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jddctmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jdhuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdhuff.h)
+jdinput.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdmainct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdmarker.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdmaster.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdmerge.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdphuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdhuff.h)
+jdpostct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdsample.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jdtrans.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jerror.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jversion.h,jerror.h)
+jfdctflt.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jfdctfst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jfdctint.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jidctflt.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jidctfst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jidctint.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jidctred.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
+jquant1.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jquant2.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jutils.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
+jmemmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)
+jmemansi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)
diff --git a/osframework/source/ImageLib/jpeg/maktjpeg.st b/osframework/source/ImageLib/jpeg/maktjpeg.st
new file mode 100644
index 0000000..ced1951
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/maktjpeg.st
@@ -0,0 +1,32 @@
+; Project file for Independent JPEG Group's software
+;
+; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
+; Thanks to Frank Moehle (Frank.Moehle@arbi.informatik.uni-oldenburg.de),
+; Dr. B. Setzepfandt (bernd@gina.uni-muenster.de),
+; and Guido Vollbeding (guivol@esc.de).
+;
+; To use this file, rename it to jpegtran.prj.
+; If you are using Turbo C, change filenames beginning with "pc..." to "tc..."
+; Read installation instructions before trying to make the program!
+;
+;
+; * * * Output file * * *
+jpegtran.ttp
+;
+; * * * COMPILER OPTIONS * * *
+.C[-P] ; absolute calls
+.C[-M] ; and no string merging, folks
+.C[-w-cln] ; no "constant is long" warnings
+.C[-w-par] ; no "parameter xxxx unused"
+.C[-w-rch] ; no "unreachable code"
+.C[-wsig] ; warn if significant digits may be lost
+=
+; * * * * List of modules * * * *
+pcstart.o
+jpegtran.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,transupp.h,jversion.h)
+cdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+rdswitch.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
+transupp.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,transupp.h)
+libjpeg.lib ; built by libjpeg.prj
+pcstdlib.lib ; standard library
+pcextlib.lib ; extended library
diff --git a/osframework/source/ImageLib/jpeg/makvms.opt b/osframework/source/ImageLib/jpeg/makvms.opt
new file mode 100644
index 0000000..26db714
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/makvms.opt
@@ -0,0 +1,4 @@
+! A pointer to the VAX/VMS C Run-Time Shareable Library.
+! This file is needed by makefile.mms and makefile.vms,
+! but only for the older VAX C compiler. DEC C does not need it.
+Sys$Library:VAXCRTL.EXE /Share
diff --git a/osframework/source/ImageLib/jpeg/rdbmp.c b/osframework/source/ImageLib/jpeg/rdbmp.c
new file mode 100644
index 0000000..4f61bcf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdbmp.c
@@ -0,0 +1,439 @@
+/*
+ * rdbmp.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in Microsoft "BMP"
+ * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
+ * Currently, only 8-bit and 24-bit images are supported, not 1-bit or
+ * 4-bit (feeding such low-depth images into JPEG would be silly anyway).
+ * Also, we don't support RLE-compressed files.
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume input from
+ * an ordinary stdio stream. They further assume that reading begins
+ * at the start of the file; start_input may need work if the
+ * user interface has already read some data (e.g., to determine that
+ * the file is indeed BMP format).
+ *
+ * This code contributed by James Arthur Boucher.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef BMP_SUPPORTED
+
+
+/* Macros to deal with unsigned chars as efficiently as compiler allows */
+
+#ifdef HAVE_UNSIGNED_CHAR
+typedef unsigned char U_CHAR;
+#define UCH(x) ((int) (x))
+#else /* !HAVE_UNSIGNED_CHAR */
+#ifdef CHAR_IS_UNSIGNED
+typedef char U_CHAR;
+#define UCH(x) ((int) (x))
+#else
+typedef char U_CHAR;
+#define UCH(x) ((int) (x) & 0xFF)
+#endif
+#endif /* HAVE_UNSIGNED_CHAR */
+
+
+#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
+
+
+/* Private version of data source object */
+
+typedef struct _bmp_source_struct * bmp_source_ptr;
+
+typedef struct _bmp_source_struct {
+ struct cjpeg_source_struct pub; /* public fields */
+
+ j_compress_ptr cinfo; /* back link saves passing separate parm */
+
+ JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
+
+ jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
+ JDIMENSION source_row; /* Current source row number */
+ JDIMENSION row_width; /* Physical width of scanlines in file */
+
+ int bits_per_pixel; /* remembers 8- or 24-bit format */
+} bmp_source_struct;
+
+
+LOCAL(int)
+read_byte (bmp_source_ptr sinfo)
+/* Read next byte from BMP file */
+{
+ register FILE *infile = sinfo->pub.input_file;
+ register int c;
+
+ if ((c = getc(infile)) == EOF)
+ ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
+ return c;
+}
+
+
+LOCAL(void)
+read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize)
+/* Read the colormap from a BMP file */
+{
+ int i;
+
+ switch (mapentrysize) {
+ case 3:
+ /* BGR format (occurs in OS/2 files) */
+ for (i = 0; i < cmaplen; i++) {
+ sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
+ }
+ break;
+ case 4:
+ /* BGR0 format (occurs in MS Windows files) */
+ for (i = 0; i < cmaplen; i++) {
+ sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
+ (void) read_byte(sinfo);
+ }
+ break;
+ default:
+ ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);
+ break;
+ }
+}
+
+
+/*
+ * Read one row of pixels.
+ * The image has been read into the whole_image array, but is otherwise
+ * unprocessed. We must read it out in top-to-bottom row order, and if
+ * it is an 8-bit image, we must expand colormapped pixels to 24bit format.
+ */
+
+METHODDEF(JDIMENSION)
+get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 8-bit colormap indexes */
+{
+ bmp_source_ptr source = (bmp_source_ptr) sinfo;
+ register JSAMPARRAY colormap = source->colormap;
+ JSAMPARRAY image_ptr;
+ register int t;
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION col;
+
+ /* Fetch next row from virtual array */
+ source->source_row--;
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->whole_image,
+ source->source_row, (JDIMENSION) 1, FALSE);
+
+ /* Expand the colormap indexes to real data */
+ inptr = image_ptr[0];
+ outptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ t = GETJSAMPLE(*inptr++);
+ *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
+ *outptr++ = colormap[1][t];
+ *outptr++ = colormap[2][t];
+ }
+
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 24-bit pixels */
+{
+ bmp_source_ptr source = (bmp_source_ptr) sinfo;
+ JSAMPARRAY image_ptr;
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION col;
+
+ /* Fetch next row from virtual array */
+ source->source_row--;
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->whole_image,
+ source->source_row, (JDIMENSION) 1, FALSE);
+
+ /* Transfer data. Note source values are in BGR order
+ * (even though Microsoft's own documents say the opposite).
+ */
+ inptr = image_ptr[0];
+ outptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
+ outptr[1] = *inptr++;
+ outptr[0] = *inptr++;
+ outptr += 3;
+ }
+
+ return 1;
+}
+
+
+/*
+ * This method loads the image into whole_image during the first call on
+ * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
+ * get_8bit_row or get_24bit_row on subsequent calls.
+ */
+
+METHODDEF(JDIMENSION)
+preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ bmp_source_ptr source = (bmp_source_ptr) sinfo;
+ register FILE *infile = source->pub.input_file;
+ register int c;
+ register JSAMPROW out_ptr;
+ JSAMPARRAY image_ptr;
+ JDIMENSION row, col;
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+
+ /* Read the data into a virtual array in input-file row order. */
+ for (row = 0; row < cinfo->image_height; row++) {
+ if (progress != NULL) {
+ progress->pub.pass_counter = (long) row;
+ progress->pub.pass_limit = (long) cinfo->image_height;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->whole_image,
+ row, (JDIMENSION) 1, TRUE);
+ out_ptr = image_ptr[0];
+ for (col = source->row_width; col > 0; col--) {
+ /* inline copy of read_byte() for speed */
+ if ((c = getc(infile)) == EOF)
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ *out_ptr++ = (JSAMPLE) c;
+ }
+ }
+ if (progress != NULL)
+ progress->completed_extra_passes++;
+
+ /* Set up to read from the virtual array in top-to-bottom order */
+ switch (source->bits_per_pixel) {
+ case 8:
+ source->pub.get_pixel_rows = get_8bit_row;
+ break;
+ case 24:
+ source->pub.get_pixel_rows = get_24bit_row;
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BMP_BADDEPTH);
+ }
+ source->source_row = cinfo->image_height;
+
+ /* And read the first row */
+ return (*source->pub.get_pixel_rows) (cinfo, sinfo);
+}
+
+
+/*
+ * Read the file header; return image size and component count.
+ */
+
+METHODDEF(void)
+start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ bmp_source_ptr source = (bmp_source_ptr) sinfo;
+ U_CHAR bmpfileheader[14];
+ U_CHAR bmpinfoheader[64];
+#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \
+ (((unsigned int) UCH(array[offset+1])) << 8))
+#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \
+ (((INT32) UCH(array[offset+1])) << 8) + \
+ (((INT32) UCH(array[offset+2])) << 16) + \
+ (((INT32) UCH(array[offset+3])) << 24))
+ INT32 bfOffBits;
+ INT32 headerSize;
+ INT32 biWidth = 0; /* initialize to avoid compiler warning */
+ INT32 biHeight = 0;
+ unsigned int biPlanes;
+ INT32 biCompression;
+ INT32 biXPelsPerMeter,biYPelsPerMeter;
+ INT32 biClrUsed = 0;
+ int mapentrysize = 0; /* 0 indicates no colormap */
+ INT32 bPad;
+ JDIMENSION row_width;
+
+ /* Read and verify the bitmap file header */
+ if (! ReadOK(source->pub.input_file, bmpfileheader, 14))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */
+ ERREXIT(cinfo, JERR_BMP_NOT);
+ bfOffBits = (INT32) GET_4B(bmpfileheader,10);
+ /* We ignore the remaining fileheader fields */
+
+ /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
+ * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which.
+ */
+ if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ headerSize = (INT32) GET_4B(bmpinfoheader,0);
+ if (headerSize < 12 || headerSize > 64)
+ ERREXIT(cinfo, JERR_BMP_BADHEADER);
+ if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+
+ switch ((int) headerSize) {
+ case 12:
+ /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */
+ biWidth = (INT32) GET_2B(bmpinfoheader,4);
+ biHeight = (INT32) GET_2B(bmpinfoheader,6);
+ biPlanes = GET_2B(bmpinfoheader,8);
+ source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
+
+ switch (source->bits_per_pixel) {
+ case 8: /* colormapped image */
+ mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
+ TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
+ break;
+ case 24: /* RGB image */
+ TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BMP_BADDEPTH);
+ break;
+ }
+ if (biPlanes != 1)
+ ERREXIT(cinfo, JERR_BMP_BADPLANES);
+ break;
+ case 40:
+ case 64:
+ /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */
+ /* or OS/2 2.x header, which has additional fields that we ignore */
+ biWidth = GET_4B(bmpinfoheader,4);
+ biHeight = GET_4B(bmpinfoheader,8);
+ biPlanes = GET_2B(bmpinfoheader,12);
+ source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14);
+ biCompression = GET_4B(bmpinfoheader,16);
+ biXPelsPerMeter = GET_4B(bmpinfoheader,24);
+ biYPelsPerMeter = GET_4B(bmpinfoheader,28);
+ biClrUsed = GET_4B(bmpinfoheader,32);
+ /* biSizeImage, biClrImportant fields are ignored */
+
+ switch (source->bits_per_pixel) {
+ case 8: /* colormapped image */
+ mapentrysize = 4; /* Windows uses RGBQUAD colormap */
+ TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
+ break;
+ case 24: /* RGB image */
+ TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BMP_BADDEPTH);
+ break;
+ }
+ if (biPlanes != 1)
+ ERREXIT(cinfo, JERR_BMP_BADPLANES);
+ if (biCompression != 0)
+ ERREXIT(cinfo, JERR_BMP_COMPRESSED);
+
+ if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
+ /* Set JFIF density parameters from the BMP data */
+ cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
+ cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
+ cinfo->density_unit = 2; /* dots/cm */
+ }
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BMP_BADHEADER);
+ break;
+ }
+
+ /* Compute distance to bitmap data --- will adjust for colormap below */
+ bPad = bfOffBits - (headerSize + 14);
+
+ /* Read the colormap, if any */
+ if (mapentrysize > 0) {
+ if (biClrUsed <= 0)
+ biClrUsed = 256; /* assume it's 256 */
+ else if (biClrUsed > 256)
+ ERREXIT(cinfo, JERR_BMP_BADCMAP);
+ /* Allocate space to store the colormap */
+ source->colormap = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) biClrUsed, (JDIMENSION) 3);
+ /* and read it from the file */
+ read_colormap(source, (int) biClrUsed, mapentrysize);
+ /* account for size of colormap */
+ bPad -= biClrUsed * mapentrysize;
+ }
+
+ /* Skip any remaining pad bytes */
+ if (bPad < 0) /* incorrect bfOffBits value? */
+ ERREXIT(cinfo, JERR_BMP_BADHEADER);
+ while (--bPad >= 0) {
+ (void) read_byte(source);
+ }
+
+ /* Compute row width in file, including padding to 4-byte boundary */
+ if (source->bits_per_pixel == 24)
+ row_width = (JDIMENSION) (biWidth * 3);
+ else
+ row_width = (JDIMENSION) biWidth;
+ while ((row_width & 3) != 0) row_width++;
+ source->row_width = row_width;
+
+ /* Allocate space for inversion array, prepare for preload pass */
+ source->whole_image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ row_width, (JDIMENSION) biHeight, (JDIMENSION) 1);
+ source->pub.get_pixel_rows = preload_image;
+ if (cinfo->progress != NULL) {
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+ progress->total_extra_passes++; /* count file input as separate pass */
+ }
+
+ /* Allocate one-row buffer for returned data */
+ source->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) (biWidth * 3), (JDIMENSION) 1);
+ source->pub.buffer_height = 1;
+
+ cinfo->in_color_space = JCS_RGB;
+ cinfo->input_components = 3;
+ cinfo->data_precision = 8;
+ cinfo->image_width = (JDIMENSION) biWidth;
+ cinfo->image_height = (JDIMENSION) biHeight;
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ /* no work */
+}
+
+
+/*
+ * The module selection routine for BMP format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_bmp (j_compress_ptr cinfo)
+{
+ bmp_source_ptr source;
+
+ /* Create module interface object */
+ source = (bmp_source_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(bmp_source_struct));
+ source->cinfo = cinfo; /* make back link for subroutines */
+ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
+ source->pub.start_input = start_input_bmp;
+ source->pub.finish_input = finish_input_bmp;
+
+ return (cjpeg_source_ptr) source;
+}
+
+#endif /* BMP_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/rdcolmap.c b/osframework/source/ImageLib/jpeg/rdcolmap.c
new file mode 100644
index 0000000..eebf834
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdcolmap.c
@@ -0,0 +1,253 @@
+/*
+ * rdcolmap.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file implements djpeg's "-map file" switch. It reads a source image
+ * and constructs a colormap to be supplied to the JPEG decompressor.
+ *
+ * Currently, these file formats are supported for the map file:
+ * GIF: the contents of the GIF's global colormap are used.
+ * PPM (either text or raw flavor): the entire file is read and
+ * each unique pixel value is entered in the map.
+ * Note that reading a large PPM file will be horrendously slow.
+ * Typically, a PPM-format map file should contain just one pixel
+ * of each desired color. Such a file can be extracted from an
+ * ordinary image PPM file with ppmtomap(1).
+ *
+ * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not
+ * currently implemented.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
+
+/* Portions of this code are based on the PBMPLUS library, which is:
+**
+** Copyright (C) 1988 by Jef Poskanzer.
+**
+** Permission to use, copy, modify, and distribute this software and its
+** documentation for any purpose and without fee is hereby granted, provided
+** that the above copyright notice appear in all copies and that both that
+** copyright notice and this permission notice appear in supporting
+** documentation. This software is provided "as is" without express or
+** implied warranty.
+*/
+
+
+/*
+ * Add a (potentially) new color to the color map.
+ */
+
+LOCAL(void)
+add_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
+{
+ JSAMPROW colormap0 = cinfo->colormap[0];
+ JSAMPROW colormap1 = cinfo->colormap[1];
+ JSAMPROW colormap2 = cinfo->colormap[2];
+ int ncolors = cinfo->actual_number_of_colors;
+ int index;
+
+ /* Check for duplicate color. */
+ for (index = 0; index < ncolors; index++) {
+ if (GETJSAMPLE(colormap0[index]) == R &&
+ GETJSAMPLE(colormap1[index]) == G &&
+ GETJSAMPLE(colormap2[index]) == B)
+ return; /* color is already in map */
+ }
+
+ /* Check for map overflow. */
+ if (ncolors >= (MAXJSAMPLE+1))
+ ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));
+
+ /* OK, add color to map. */
+ colormap0[ncolors] = (JSAMPLE) R;
+ colormap1[ncolors] = (JSAMPLE) G;
+ colormap2[ncolors] = (JSAMPLE) B;
+ cinfo->actual_number_of_colors++;
+}
+
+
+/*
+ * Extract color map from a GIF file.
+ */
+
+LOCAL(void)
+read_gif_map (j_decompress_ptr cinfo, FILE * infile)
+{
+ int header[13];
+ int i, colormaplen;
+ int R, G, B;
+
+ /* Initial 'G' has already been read by read_color_map */
+ /* Read the rest of the GIF header and logical screen descriptor */
+ for (i = 1; i < 13; i++) {
+ if ((header[i] = getc(infile)) == EOF)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ }
+
+ /* Verify GIF Header */
+ if (header[1] != 'I' || header[2] != 'F')
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+
+ /* There must be a global color map. */
+ if ((header[10] & 0x80) == 0)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+
+ /* OK, fetch it. */
+ colormaplen = 2 << (header[10] & 0x07);
+
+ for (i = 0; i < colormaplen; i++) {
+ R = getc(infile);
+ G = getc(infile);
+ B = getc(infile);
+ if (R == EOF || G == EOF || B == EOF)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ add_map_entry(cinfo,
+ R << (BITS_IN_JSAMPLE-8),
+ G << (BITS_IN_JSAMPLE-8),
+ B << (BITS_IN_JSAMPLE-8));
+ }
+}
+
+
+/* Support routines for reading PPM */
+
+
+LOCAL(int)
+pbm_getc (FILE * infile)
+/* Read next char, skipping over any comments */
+/* A comment/newline sequence is returned as a newline */
+{
+ register int ch;
+
+ ch = getc(infile);
+ if (ch == '#') {
+ do {
+ ch = getc(infile);
+ } while (ch != '\n' && ch != EOF);
+ }
+ return ch;
+}
+
+
+LOCAL(unsigned int)
+read_pbm_integer (j_decompress_ptr cinfo, FILE * infile)
+/* Read an unsigned decimal integer from the PPM file */
+/* Swallows one trailing character after the integer */
+/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
+/* This should not be a problem in practice. */
+{
+ register int ch;
+ register unsigned int val;
+
+ /* Skip any leading whitespace */
+ do {
+ ch = pbm_getc(infile);
+ if (ch == EOF)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
+
+ if (ch < '0' || ch > '9')
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+
+ val = ch - '0';
+ while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
+ val *= 10;
+ val += ch - '0';
+ }
+ return val;
+}
+
+
+/*
+ * Extract color map from a PPM file.
+ */
+
+LOCAL(void)
+read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
+{
+ int c;
+ unsigned int w, h, maxval, row, col;
+ int R, G, B;
+
+ /* Initial 'P' has already been read by read_color_map */
+ c = getc(infile); /* save format discriminator for a sec */
+
+ /* while we fetch the remaining header info */
+ w = read_pbm_integer(cinfo, infile);
+ h = read_pbm_integer(cinfo, infile);
+ maxval = read_pbm_integer(cinfo, infile);
+
+ if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+
+ /* For now, we don't support rescaling from an unusual maxval. */
+ if (maxval != (unsigned int) MAXJSAMPLE)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+
+ switch (c) {
+ case '3': /* it's a text-format PPM file */
+ for (row = 0; row < h; row++) {
+ for (col = 0; col < w; col++) {
+ R = read_pbm_integer(cinfo, infile);
+ G = read_pbm_integer(cinfo, infile);
+ B = read_pbm_integer(cinfo, infile);
+ add_map_entry(cinfo, R, G, B);
+ }
+ }
+ break;
+
+ case '6': /* it's a raw-format PPM file */
+ for (row = 0; row < h; row++) {
+ for (col = 0; col < w; col++) {
+ R = getc(infile);
+ G = getc(infile);
+ B = getc(infile);
+ if (R == EOF || G == EOF || B == EOF)
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ add_map_entry(cinfo, R, G, B);
+ }
+ }
+ break;
+
+ default:
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ break;
+ }
+}
+
+
+/*
+ * Main entry point from djpeg.c.
+ * Input: opened input file (from file name argument on command line).
+ * Output: colormap and actual_number_of_colors fields are set in cinfo.
+ */
+
+GLOBAL(void)
+read_color_map (j_decompress_ptr cinfo, FILE * infile)
+{
+ /* Allocate space for a color map of maximum supported size. */
+ cinfo->colormap = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);
+ cinfo->actual_number_of_colors = 0; /* initialize map to empty */
+
+ /* Read first byte to determine file format */
+ switch (getc(infile)) {
+ case 'G':
+ read_gif_map(cinfo, infile);
+ break;
+ case 'P':
+ read_ppm_map(cinfo, infile);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
+ break;
+ }
+}
+
+#endif /* QUANT_2PASS_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/rdgif.c b/osframework/source/ImageLib/jpeg/rdgif.c
new file mode 100644
index 0000000..b0757e7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdgif.c
@@ -0,0 +1,38 @@
+/*
+ * rdgif.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in GIF format.
+ *
+ *****************************************************************************
+ * NOTE: to avoid entanglements with Unisys' patent on LZW compression, *
+ * the ability to read GIF files has been removed from the IJG distribution. *
+ * Sorry about that. *
+ *****************************************************************************
+ *
+ * We are required to state that
+ * "The Graphics Interchange Format(c) is the Copyright property of
+ * CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ * CompuServe Incorporated."
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef GIF_SUPPORTED
+
+/*
+ * The module selection routine for GIF format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_gif (j_compress_ptr cinfo)
+{
+ fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n");
+ exit(EXIT_FAILURE);
+ return NULL; /* keep compiler happy */
+}
+
+#endif /* GIF_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/rdjpgcom.1 b/osframework/source/ImageLib/jpeg/rdjpgcom.1
new file mode 100644
index 0000000..dd837a8
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdjpgcom.1
@@ -0,0 +1,54 @@
+.TH RDJPGCOM 1 "11 October 1997"
+.SH NAME
+rdjpgcom \- display text comments from a JPEG file
+.SH SYNOPSIS
+.B rdjpgcom
+[
+.B \-verbose
+]
+[
+.I filename
+]
+.LP
+.SH DESCRIPTION
+.LP
+.B rdjpgcom
+reads the named JPEG/JFIF file, or the standard input if no file is named,
+and prints any text comments found in the file on the standard output.
+.PP
+The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
+Although the standard doesn't actually define what COM blocks are for, they
+are widely used to hold user-supplied text strings. This lets you add
+annotations, titles, index terms, etc to your JPEG files, and later retrieve
+them as text. COM blocks do not interfere with the image stored in the JPEG
+file. The maximum size of a COM block is 64K, but you can have as many of
+them as you like in one JPEG file.
+.SH OPTIONS
+.TP
+.B \-verbose
+Causes
+.B rdjpgcom
+to also display the JPEG image dimensions.
+.PP
+Switch names may be abbreviated, and are not case sensitive.
+.SH HINTS
+.B rdjpgcom
+does not depend on the IJG JPEG library. Its source code is intended as an
+illustration of the minimum amount of code required to parse a JPEG file
+header correctly.
+.PP
+In
+.B \-verbose
+mode,
+.B rdjpgcom
+will also attempt to print the contents of any "APP12" markers as text.
+Some digital cameras produce APP12 markers containing useful textual
+information. If you like, you can modify the source code to print
+other APPn marker types as well.
+.SH SEE ALSO
+.BR cjpeg (1),
+.BR djpeg (1),
+.BR jpegtran (1),
+.BR wrjpgcom (1)
+.SH AUTHOR
+Independent JPEG Group
diff --git a/osframework/source/ImageLib/jpeg/rdjpgcom.c b/osframework/source/ImageLib/jpeg/rdjpgcom.c
new file mode 100644
index 0000000..c8b94bb
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdjpgcom.c
@@ -0,0 +1,496 @@
+/*
+ * rdjpgcom.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a very simple stand-alone application that displays
+ * the text in COM (comment) markers in a JFIF file.
+ * This may be useful as an example of the minimum logic needed to parse
+ * JPEG markers.
+ */
+
+#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
+#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
+
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#endif
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+#ifdef VMS
+#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
+#else
+#define EXIT_SUCCESS 0
+#endif
+#endif
+
+
+/*
+ * These macros are used to read the input file.
+ * To reuse this code in another application, you might need to change these.
+ */
+
+static FILE * infile; /* input JPEG file */
+
+/* Return next input byte, or EOF if no more */
+#define NEXTBYTE() getc(infile)
+
+
+/* Error exit handler */
+#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
+
+
+/* Read one byte, testing for EOF */
+static int
+read_1_byte (void)
+{
+ int c;
+
+ c = NEXTBYTE();
+ if (c == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return c;
+}
+
+/* Read 2 bytes, convert to unsigned int */
+/* All 2-byte quantities in JPEG markers are MSB first */
+static unsigned int
+read_2_bytes (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ if (c1 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ c2 = NEXTBYTE();
+ if (c2 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return (((unsigned int) c1) << 8) + ((unsigned int) c2);
+}
+
+
+/*
+ * JPEG markers consist of one or more 0xFF bytes, followed by a marker
+ * code byte (which is not an FF). Here are the marker codes of interest
+ * in this program. (See jdmarker.c for a more complete list.)
+ */
+
+#define M_SOF0 0xC0 /* Start Of Frame N */
+#define M_SOF1 0xC1 /* N indicates which compression process */
+#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
+#define M_SOF3 0xC3
+#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
+#define M_SOF6 0xC6
+#define M_SOF7 0xC7
+#define M_SOF9 0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
+#define M_EOI 0xD9 /* End Of Image (end of datastream) */
+#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
+#define M_APP0 0xE0 /* Application-specific marker, type N */
+#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
+#define M_COM 0xFE /* COMment */
+
+
+/*
+ * Find the next JPEG marker and return its marker code.
+ * We expect at least one FF byte, possibly more if the compressor used FFs
+ * to pad the file.
+ * There could also be non-FF garbage between markers. The treatment of such
+ * garbage is unspecified; we choose to skip over it but emit a warning msg.
+ * NB: this routine must not be used after seeing SOS marker, since it will
+ * not deal correctly with FF/00 sequences in the compressed image data...
+ */
+
+static int
+next_marker (void)
+{
+ int c;
+ int discarded_bytes = 0;
+
+ /* Find 0xFF byte; count and skip any non-FFs. */
+ c = read_1_byte();
+ while (c != 0xFF) {
+ discarded_bytes++;
+ c = read_1_byte();
+ }
+ /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
+ * are legal as pad bytes, so don't count them in discarded_bytes.
+ */
+ do {
+ c = read_1_byte();
+ } while (c == 0xFF);
+
+ if (discarded_bytes != 0) {
+ fprintf(stderr, "Warning: garbage data found in JPEG file\n");
+ }
+
+ return c;
+}
+
+
+/*
+ * Read the initial marker, which should be SOI.
+ * For a JFIF file, the first two bytes of the file should be literally
+ * 0xFF M_SOI. To be more general, we could use next_marker, but if the
+ * input file weren't actually JPEG at all, next_marker might read the whole
+ * file and then return a misleading error message...
+ */
+
+static int
+first_marker (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ c2 = NEXTBYTE();
+ if (c1 != 0xFF || c2 != M_SOI)
+ ERREXIT("Not a JPEG file");
+ return c2;
+}
+
+
+/*
+ * Most types of marker are followed by a variable-length parameter segment.
+ * This routine skips over the parameters for any marker we don't otherwise
+ * want to process.
+ * Note that we MUST skip the parameter segment explicitly in order not to
+ * be fooled by 0xFF bytes that might appear within the parameter segment;
+ * such bytes do NOT introduce new markers.
+ */
+
+static void
+skip_variable (void)
+/* Skip over an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ (void) read_1_byte();
+ length--;
+ }
+}
+
+
+/*
+ * Process a COM marker.
+ * We want to print out the marker contents as legible text;
+ * we must guard against non-text junk and varying newline representations.
+ */
+
+static void
+process_COM (void)
+{
+ unsigned int length;
+ int ch;
+ int lastch = 0;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+
+ while (length > 0) {
+ ch = read_1_byte();
+ /* Emit the character in a readable form.
+ * Nonprintables are converted to \nnn form,
+ * while \ is converted to \\.
+ * Newlines in CR, CR/LF, or LF form will be printed as one newline.
+ */
+ if (ch == '\r') {
+ printf("\n");
+ } else if (ch == '\n') {
+ if (lastch != '\r')
+ printf("\n");
+ } else if (ch == '\\') {
+ printf("\\\\");
+ } else if (isprint(ch)) {
+ putc(ch, stdout);
+ } else {
+ printf("\\%03o", ch);
+ }
+ lastch = ch;
+ length--;
+ }
+ printf("\n");
+}
+
+
+/*
+ * Process a SOFn marker.
+ * This code is only needed if you want to know the image dimensions...
+ */
+
+static void
+process_SOFn (int marker)
+{
+ unsigned int length;
+ unsigned int image_height, image_width;
+ int data_precision, num_components;
+ const char * process;
+ int ci;
+
+ length = read_2_bytes(); /* usual parameter length count */
+
+ data_precision = read_1_byte();
+ image_height = read_2_bytes();
+ image_width = read_2_bytes();
+ num_components = read_1_byte();
+
+ switch (marker) {
+ case M_SOF0: process = "Baseline"; break;
+ case M_SOF1: process = "Extended sequential"; break;
+ case M_SOF2: process = "Progressive"; break;
+ case M_SOF3: process = "Lossless"; break;
+ case M_SOF5: process = "Differential sequential"; break;
+ case M_SOF6: process = "Differential progressive"; break;
+ case M_SOF7: process = "Differential lossless"; break;
+ case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
+ case M_SOF10: process = "Progressive, arithmetic coding"; break;
+ case M_SOF11: process = "Lossless, arithmetic coding"; break;
+ case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
+ case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
+ case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
+ default: process = "Unknown"; break;
+ }
+
+ printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
+ image_width, image_height, num_components, data_precision);
+ printf("JPEG process: %s\n", process);
+
+ if (length != (unsigned int) (8 + num_components * 3))
+ ERREXIT("Bogus SOF marker length");
+
+ for (ci = 0; ci < num_components; ci++) {
+ (void) read_1_byte(); /* Component ID code */
+ (void) read_1_byte(); /* H, V sampling factors */
+ (void) read_1_byte(); /* Quantization table number */
+ }
+}
+
+
+/*
+ * Parse the marker stream until SOS or EOI is seen;
+ * display any COM markers.
+ * While the companion program wrjpgcom will always insert COM markers before
+ * SOFn, other implementations might not, so we scan to SOS before stopping.
+ * If we were only interested in the image dimensions, we would stop at SOFn.
+ * (Conversely, if we only cared about COM markers, there would be no need
+ * for special code to handle SOFn; we could treat it like other markers.)
+ */
+
+static int
+scan_JPEG_header (int verbose)
+{
+ int marker;
+
+ /* Expect SOI at start of file */
+ if (first_marker() != M_SOI)
+ ERREXIT("Expected SOI marker first");
+
+ /* Scan miscellaneous markers until we reach SOS. */
+ for (;;) {
+ marker = next_marker();
+ switch (marker) {
+ /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
+ * treated as SOFn. C4 in particular is actually DHT.
+ */
+ case M_SOF0: /* Baseline */
+ case M_SOF1: /* Extended sequential, Huffman */
+ case M_SOF2: /* Progressive, Huffman */
+ case M_SOF3: /* Lossless, Huffman */
+ case M_SOF5: /* Differential sequential, Huffman */
+ case M_SOF6: /* Differential progressive, Huffman */
+ case M_SOF7: /* Differential lossless, Huffman */
+ case M_SOF9: /* Extended sequential, arithmetic */
+ case M_SOF10: /* Progressive, arithmetic */
+ case M_SOF11: /* Lossless, arithmetic */
+ case M_SOF13: /* Differential sequential, arithmetic */
+ case M_SOF14: /* Differential progressive, arithmetic */
+ case M_SOF15: /* Differential lossless, arithmetic */
+ if (verbose)
+ process_SOFn(marker);
+ else
+ skip_variable();
+ break;
+
+ case M_SOS: /* stop before hitting compressed data */
+ return marker;
+
+ case M_EOI: /* in case it's a tables-only JPEG stream */
+ return marker;
+
+ case M_COM:
+ process_COM();
+ break;
+
+ case M_APP12:
+ /* Some digital camera makers put useful textual information into
+ * APP12 markers, so we print those out too when in -verbose mode.
+ */
+ if (verbose) {
+ printf("APP12 contains:\n");
+ process_COM();
+ } else
+ skip_variable();
+ break;
+
+ default: /* Anything else just gets skipped */
+ skip_variable(); /* we assume it has a parameter count... */
+ break;
+ }
+ } /* end loop */
+}
+
+
+/* Command line parsing code */
+
+static const char * progname; /* program name for error messages */
+
+
+static void
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
+
+ fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -verbose Also display dimensions of JPEG image\n");
+
+ exit(EXIT_FAILURE);
+}
+
+
+static int
+keymatch (char * arg, const char * keyword, int minchars)
+/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
+/* keyword is the constant keyword (must be lower case already), */
+/* minchars is length of minimum legal abbreviation. */
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return 0; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return 0; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return 0;
+ return 1; /* A-OK */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ int argn;
+ char * arg;
+ int verbose = 0;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "rdjpgcom"; /* in case C library doesn't provide it */
+
+ /* Parse switches, if any */
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (arg[0] != '-')
+ break; /* not switch, must be file name */
+ arg++; /* advance over '-' */
+ if (keymatch(arg, "verbose", 1)) {
+ verbose++;
+ } else
+ usage();
+ }
+
+ /* Open the input file. */
+ /* Unix style: expect zero or one file name */
+ if (argn < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+ if (argn < argc) {
+ if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdin\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ infile = stdin;
+#endif
+ }
+
+ /* Scan the JPEG headers. */
+ (void) scan_JPEG_header(verbose);
+
+ /* All done. */
+ exit(EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/osframework/source/ImageLib/jpeg/rdppm.c b/osframework/source/ImageLib/jpeg/rdppm.c
new file mode 100644
index 0000000..bec0bc0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdppm.c
@@ -0,0 +1,458 @@
+/*
+ * rdppm.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in PPM/PGM format.
+ * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
+ * The PBMPLUS library is NOT required to compile this software
+ * (but it is highly useful as a set of PPM image manipulation programs).
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume input from
+ * an ordinary stdio stream. They further assume that reading begins
+ * at the start of the file; start_input may need work if the
+ * user interface has already read some data (e.g., to determine that
+ * the file is indeed PPM format).
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef PPM_SUPPORTED
+
+
+/* Portions of this code are based on the PBMPLUS library, which is:
+**
+** Copyright (C) 1988 by Jef Poskanzer.
+**
+** Permission to use, copy, modify, and distribute this software and its
+** documentation for any purpose and without fee is hereby granted, provided
+** that the above copyright notice appear in all copies and that both that
+** copyright notice and this permission notice appear in supporting
+** documentation. This software is provided "as is" without express or
+** implied warranty.
+*/
+
+
+/* Macros to deal with unsigned chars as efficiently as compiler allows */
+
+#ifdef HAVE_UNSIGNED_CHAR
+typedef unsigned char U_CHAR;
+#define UCH(x) ((int) (x))
+#else /* !HAVE_UNSIGNED_CHAR */
+#ifdef CHAR_IS_UNSIGNED
+typedef char U_CHAR;
+#define UCH(x) ((int) (x))
+#else
+typedef char U_CHAR;
+#define UCH(x) ((int) (x) & 0xFF)
+#endif
+#endif /* HAVE_UNSIGNED_CHAR */
+
+
+#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
+
+
+/*
+ * On most systems, reading individual bytes with getc() is drastically less
+ * efficient than buffering a row at a time with fread(). On PCs, we must
+ * allocate the buffer in near data space, because we are assuming small-data
+ * memory model, wherein fread() can't reach far memory. If you need to
+ * process very wide images on a PC, you might have to compile in large-memory
+ * model, or else replace fread() with a getc() loop --- which will be much
+ * slower.
+ */
+
+
+/* Private version of data source object */
+
+typedef struct {
+ struct cjpeg_source_struct pub; /* public fields */
+
+ U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */
+ JSAMPROW pixrow; /* FAR pointer to same */
+ size_t buffer_width; /* width of I/O buffer */
+ JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
+} ppm_source_struct;
+
+typedef ppm_source_struct * ppm_source_ptr;
+
+
+LOCAL(int)
+pbm_getc (FILE * infile)
+/* Read next char, skipping over any comments */
+/* A comment/newline sequence is returned as a newline */
+{
+ register int ch;
+
+ ch = getc(infile);
+ if (ch == '#') {
+ do {
+ ch = getc(infile);
+ } while (ch != '\n' && ch != EOF);
+ }
+ return ch;
+}
+
+
+LOCAL(unsigned int)
+read_pbm_integer (j_compress_ptr cinfo, FILE * infile)
+/* Read an unsigned decimal integer from the PPM file */
+/* Swallows one trailing character after the integer */
+/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
+/* This should not be a problem in practice. */
+{
+ register int ch;
+ register unsigned int val;
+
+ /* Skip any leading whitespace */
+ do {
+ ch = pbm_getc(infile);
+ if (ch == EOF)
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
+
+ if (ch < '0' || ch > '9')
+ ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
+
+ val = ch - '0';
+ while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
+ val *= 10;
+ val += ch - '0';
+ }
+ return val;
+}
+
+
+/*
+ * Read one row of pixels.
+ *
+ * We provide several different versions depending on input file format.
+ * In all cases, input is scaled to the size of JSAMPLE.
+ *
+ * A really fast path is provided for reading byte/sample raw files with
+ * maxval = MAXJSAMPLE, which is the normal case for 8-bit data.
+ */
+
+
+METHODDEF(JDIMENSION)
+get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading text-format PGM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ FILE * infile = source->pub.input_file;
+ register JSAMPROW ptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
+ }
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading text-format PPM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ FILE * infile = source->pub.input_file;
+ register JSAMPROW ptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
+ *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
+ *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
+ }
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading raw-byte-format PGM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register U_CHAR * bufferptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ ptr = source->pub.buffer[0];
+ bufferptr = source->iobuffer;
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr++ = rescale[UCH(*bufferptr++)];
+ }
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading raw-byte-format PPM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register U_CHAR * bufferptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ ptr = source->pub.buffer[0];
+ bufferptr = source->iobuffer;
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr++ = rescale[UCH(*bufferptr++)];
+ *ptr++ = rescale[UCH(*bufferptr++)];
+ *ptr++ = rescale[UCH(*bufferptr++)];
+ }
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE.
+ * In this case we just read right into the JSAMPLE buffer!
+ * Note that same code works for PPM and PGM files.
+ */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+
+ if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading raw-word-format PGM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register U_CHAR * bufferptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ ptr = source->pub.buffer[0];
+ bufferptr = source->iobuffer;
+ for (col = cinfo->image_width; col > 0; col--) {
+ register int temp;
+ temp = UCH(*bufferptr++);
+ temp |= UCH(*bufferptr++) << 8;
+ *ptr++ = rescale[temp];
+ }
+ return 1;
+}
+
+
+METHODDEF(JDIMENSION)
+get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading raw-word-format PPM files with any maxval */
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register U_CHAR * bufferptr;
+ register JSAMPLE *rescale = source->rescale;
+ JDIMENSION col;
+
+ if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ ptr = source->pub.buffer[0];
+ bufferptr = source->iobuffer;
+ for (col = cinfo->image_width; col > 0; col--) {
+ register int temp;
+ temp = UCH(*bufferptr++);
+ temp |= UCH(*bufferptr++) << 8;
+ *ptr++ = rescale[temp];
+ temp = UCH(*bufferptr++);
+ temp |= UCH(*bufferptr++) << 8;
+ *ptr++ = rescale[temp];
+ temp = UCH(*bufferptr++);
+ temp |= UCH(*bufferptr++) << 8;
+ *ptr++ = rescale[temp];
+ }
+ return 1;
+}
+
+
+/*
+ * Read the file header; return image size and component count.
+ */
+
+METHODDEF(void)
+start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ ppm_source_ptr source = (ppm_source_ptr) sinfo;
+ int c;
+ unsigned int w, h, maxval;
+ boolean need_iobuffer, use_raw_buffer, need_rescale;
+
+ if (getc(source->pub.input_file) != 'P')
+ ERREXIT(cinfo, JERR_PPM_NOT);
+
+ c = getc(source->pub.input_file); /* subformat discriminator character */
+
+ /* detect unsupported variants (ie, PBM) before trying to read header */
+ switch (c) {
+ case '2': /* it's a text-format PGM file */
+ case '3': /* it's a text-format PPM file */
+ case '5': /* it's a raw-format PGM file */
+ case '6': /* it's a raw-format PPM file */
+ break;
+ default:
+ ERREXIT(cinfo, JERR_PPM_NOT);
+ break;
+ }
+
+ /* fetch the remaining header info */
+ w = read_pbm_integer(cinfo, source->pub.input_file);
+ h = read_pbm_integer(cinfo, source->pub.input_file);
+ maxval = read_pbm_integer(cinfo, source->pub.input_file);
+
+ if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
+ ERREXIT(cinfo, JERR_PPM_NOT);
+
+ cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
+ cinfo->image_width = (JDIMENSION) w;
+ cinfo->image_height = (JDIMENSION) h;
+
+ /* initialize flags to most common settings */
+ need_iobuffer = TRUE; /* do we need an I/O buffer? */
+ use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */
+ need_rescale = TRUE; /* do we need a rescale array? */
+
+ switch (c) {
+ case '2': /* it's a text-format PGM file */
+ cinfo->input_components = 1;
+ cinfo->in_color_space = JCS_GRAYSCALE;
+ TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
+ source->pub.get_pixel_rows = get_text_gray_row;
+ need_iobuffer = FALSE;
+ break;
+
+ case '3': /* it's a text-format PPM file */
+ cinfo->input_components = 3;
+ cinfo->in_color_space = JCS_RGB;
+ TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
+ source->pub.get_pixel_rows = get_text_rgb_row;
+ need_iobuffer = FALSE;
+ break;
+
+ case '5': /* it's a raw-format PGM file */
+ cinfo->input_components = 1;
+ cinfo->in_color_space = JCS_GRAYSCALE;
+ TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
+ if (maxval > 255) {
+ source->pub.get_pixel_rows = get_word_gray_row;
+ } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {
+ source->pub.get_pixel_rows = get_raw_row;
+ use_raw_buffer = TRUE;
+ need_rescale = FALSE;
+ } else {
+ source->pub.get_pixel_rows = get_scaled_gray_row;
+ }
+ break;
+
+ case '6': /* it's a raw-format PPM file */
+ cinfo->input_components = 3;
+ cinfo->in_color_space = JCS_RGB;
+ TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
+ if (maxval > 255) {
+ source->pub.get_pixel_rows = get_word_rgb_row;
+ } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {
+ source->pub.get_pixel_rows = get_raw_row;
+ use_raw_buffer = TRUE;
+ need_rescale = FALSE;
+ } else {
+ source->pub.get_pixel_rows = get_scaled_rgb_row;
+ }
+ break;
+ }
+
+ /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
+ if (need_iobuffer) {
+ source->buffer_width = (size_t) w * cinfo->input_components *
+ ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR)));
+ source->iobuffer = (U_CHAR *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ source->buffer_width);
+ }
+
+ /* Create compressor input buffer. */
+ if (use_raw_buffer) {
+ /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
+ /* Synthesize a JSAMPARRAY pointer structure */
+ /* Cast here implies near->far pointer conversion on PCs */
+ source->pixrow = (JSAMPROW) source->iobuffer;
+ source->pub.buffer = & source->pixrow;
+ source->pub.buffer_height = 1;
+ } else {
+ /* Need to translate anyway, so make a separate sample buffer. */
+ source->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1);
+ source->pub.buffer_height = 1;
+ }
+
+ /* Compute the rescaling array if required. */
+ if (need_rescale) {
+ INT32 val, half_maxval;
+
+ /* On 16-bit-int machines we have to be careful of maxval = 65535 */
+ source->rescale = (JSAMPLE *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
+ half_maxval = maxval / 2;
+ for (val = 0; val <= (INT32) maxval; val++) {
+ /* The multiplication here must be done in 32 bits to avoid overflow */
+ source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval);
+ }
+ }
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ /* no work */
+}
+
+
+/*
+ * The module selection routine for PPM format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_ppm (j_compress_ptr cinfo)
+{
+ ppm_source_ptr source;
+
+ /* Create module interface object */
+ source = (ppm_source_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(ppm_source_struct));
+ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
+ source->pub.start_input = start_input_ppm;
+ source->pub.finish_input = finish_input_ppm;
+
+ return (cjpeg_source_ptr) source;
+}
+
+#endif /* PPM_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/rdrle.c b/osframework/source/ImageLib/jpeg/rdrle.c
new file mode 100644
index 0000000..df871e0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdrle.c
@@ -0,0 +1,387 @@
+/*
+ * rdrle.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in Utah RLE format.
+ * The Utah Raster Toolkit library is required (version 3.1 or later).
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume input from
+ * an ordinary stdio stream. They further assume that reading begins
+ * at the start of the file; start_input may need work if the
+ * user interface has already read some data (e.g., to determine that
+ * the file is indeed RLE format).
+ *
+ * Based on code contributed by Mike Lijewski,
+ * with updates from Robert Hutchinson.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef RLE_SUPPORTED
+
+/* rle.h is provided by the Utah Raster Toolkit. */
+
+#include <rle.h>
+
+/*
+ * We assume that JSAMPLE has the same representation as rle_pixel,
+ * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
+ */
+
+#if BITS_IN_JSAMPLE != 8
+ Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
+#endif
+
+/*
+ * We support the following types of RLE files:
+ *
+ * GRAYSCALE - 8 bits, no colormap
+ * MAPPEDGRAY - 8 bits, 1 channel colomap
+ * PSEUDOCOLOR - 8 bits, 3 channel colormap
+ * TRUECOLOR - 24 bits, 3 channel colormap
+ * DIRECTCOLOR - 24 bits, no colormap
+ *
+ * For now, we ignore any alpha channel in the image.
+ */
+
+typedef enum
+ { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
+
+
+/*
+ * Since RLE stores scanlines bottom-to-top, we have to invert the image
+ * to conform to JPEG's top-to-bottom order. To do this, we read the
+ * incoming image into a virtual array on the first get_pixel_rows call,
+ * then fetch the required row from the virtual array on subsequent calls.
+ */
+
+typedef struct _rle_source_struct * rle_source_ptr;
+
+typedef struct _rle_source_struct {
+ struct cjpeg_source_struct pub; /* public fields */
+
+ rle_kind visual; /* actual type of input file */
+ jvirt_sarray_ptr image; /* virtual array to hold the image */
+ JDIMENSION row; /* current row # in the virtual array */
+ rle_hdr header; /* Input file information */
+ rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
+
+} rle_source_struct;
+
+
+/*
+ * Read the file header; return image size and component count.
+ */
+
+METHODDEF(void)
+start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ rle_source_ptr source = (rle_source_ptr) sinfo;
+ JDIMENSION width, height;
+#ifdef PROGRESS_REPORT
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+#endif
+
+ /* Use RLE library routine to get the header info */
+ source->header = *rle_hdr_init(NULL);
+ source->header.rle_file = source->pub.input_file;
+ switch (rle_get_setup(&(source->header))) {
+ case RLE_SUCCESS:
+ /* A-OK */
+ break;
+ case RLE_NOT_RLE:
+ ERREXIT(cinfo, JERR_RLE_NOT);
+ break;
+ case RLE_NO_SPACE:
+ ERREXIT(cinfo, JERR_RLE_MEM);
+ break;
+ case RLE_EMPTY:
+ ERREXIT(cinfo, JERR_RLE_EMPTY);
+ break;
+ case RLE_EOF:
+ ERREXIT(cinfo, JERR_RLE_EOF);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_RLE_BADERROR);
+ break;
+ }
+
+ /* Figure out what we have, set private vars and return values accordingly */
+
+ width = source->header.xmax - source->header.xmin + 1;
+ height = source->header.ymax - source->header.ymin + 1;
+ source->header.xmin = 0; /* realign horizontally */
+ source->header.xmax = width-1;
+
+ cinfo->image_width = width;
+ cinfo->image_height = height;
+ cinfo->data_precision = 8; /* we can only handle 8 bit data */
+
+ if (source->header.ncolors == 1 && source->header.ncmap == 0) {
+ source->visual = GRAYSCALE;
+ TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
+ } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
+ source->visual = MAPPEDGRAY;
+ TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
+ 1 << source->header.cmaplen);
+ } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
+ source->visual = PSEUDOCOLOR;
+ TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
+ 1 << source->header.cmaplen);
+ } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
+ source->visual = TRUECOLOR;
+ TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
+ 1 << source->header.cmaplen);
+ } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
+ source->visual = DIRECTCOLOR;
+ TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
+ } else
+ ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
+
+ if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
+ cinfo->in_color_space = JCS_GRAYSCALE;
+ cinfo->input_components = 1;
+ } else {
+ cinfo->in_color_space = JCS_RGB;
+ cinfo->input_components = 3;
+ }
+
+ /*
+ * A place to hold each scanline while it's converted.
+ * (GRAYSCALE scanlines don't need converting)
+ */
+ if (source->visual != GRAYSCALE) {
+ source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) width, (JDIMENSION) cinfo->input_components);
+ }
+
+ /* request a virtual array to hold the image */
+ source->image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) (width * source->header.ncolors),
+ (JDIMENSION) height, (JDIMENSION) 1);
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ /* count file input as separate pass */
+ progress->total_extra_passes++;
+ }
+#endif
+
+ source->pub.buffer_height = 1;
+}
+
+
+/*
+ * Read one row of pixels.
+ * Called only after load_image has read the image into the virtual array.
+ * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.
+ */
+
+METHODDEF(JDIMENSION)
+get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ rle_source_ptr source = (rle_source_ptr) sinfo;
+
+ source->row--;
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
+
+ return 1;
+}
+
+/*
+ * Read one row of pixels.
+ * Called only after load_image has read the image into the virtual array.
+ * Used for PSEUDOCOLOR images.
+ */
+
+METHODDEF(JDIMENSION)
+get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ rle_source_ptr source = (rle_source_ptr) sinfo;
+ JSAMPROW src_row, dest_row;
+ JDIMENSION col;
+ rle_map *colormap;
+ int val;
+
+ colormap = source->header.cmap;
+ dest_row = source->pub.buffer[0];
+ source->row--;
+ src_row = * (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
+
+ for (col = cinfo->image_width; col > 0; col--) {
+ val = GETJSAMPLE(*src_row++);
+ *dest_row++ = (JSAMPLE) (colormap[val ] >> 8);
+ *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8);
+ *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8);
+ }
+
+ return 1;
+}
+
+
+/*
+ * Load the image into a virtual array. We have to do this because RLE
+ * files start at the lower left while the JPEG standard has them starting
+ * in the upper left. This is called the first time we want to get a row
+ * of input. What we do is load the RLE data into the array and then call
+ * the appropriate routine to read one row from the array. Before returning,
+ * we set source->pub.get_pixel_rows so that subsequent calls go straight to
+ * the appropriate row-reading routine.
+ */
+
+METHODDEF(JDIMENSION)
+load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ rle_source_ptr source = (rle_source_ptr) sinfo;
+ JDIMENSION row, col;
+ JSAMPROW scanline, red_ptr, green_ptr, blue_ptr;
+ rle_pixel **rle_row;
+ rle_map *colormap;
+ char channel;
+#ifdef PROGRESS_REPORT
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+#endif
+
+ colormap = source->header.cmap;
+ rle_row = source->rle_row;
+
+ /* Read the RLE data into our virtual array.
+ * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
+ * and (b) we are not on a machine where FAR pointers differ from regular.
+ */
+ RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_limit = cinfo->image_height;
+ progress->pub.pass_counter = 0;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+
+ switch (source->visual) {
+
+ case GRAYSCALE:
+ case PSEUDOCOLOR:
+ for (row = 0; row < cinfo->image_height; row++) {
+ rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
+ rle_getrow(&source->header, rle_row);
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_counter++;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+ }
+ break;
+
+ case MAPPEDGRAY:
+ case TRUECOLOR:
+ for (row = 0; row < cinfo->image_height; row++) {
+ scanline = * (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
+ rle_row = source->rle_row;
+ rle_getrow(&source->header, rle_row);
+
+ for (col = 0; col < cinfo->image_width; col++) {
+ for (channel = 0; channel < source->header.ncolors; channel++) {
+ *scanline++ = (JSAMPLE)
+ (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);
+ }
+ }
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_counter++;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+ }
+ break;
+
+ case DIRECTCOLOR:
+ for (row = 0; row < cinfo->image_height; row++) {
+ scanline = * (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
+ rle_getrow(&source->header, rle_row);
+
+ red_ptr = rle_row[0];
+ green_ptr = rle_row[1];
+ blue_ptr = rle_row[2];
+
+ for (col = cinfo->image_width; col > 0; col--) {
+ *scanline++ = *red_ptr++;
+ *scanline++ = *green_ptr++;
+ *scanline++ = *blue_ptr++;
+ }
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_counter++;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+ }
+ }
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL)
+ progress->completed_extra_passes++;
+#endif
+
+ /* Set up to call proper row-extraction routine in future */
+ if (source->visual == PSEUDOCOLOR) {
+ source->pub.buffer = source->rle_row;
+ source->pub.get_pixel_rows = get_pseudocolor_row;
+ } else {
+ source->pub.get_pixel_rows = get_rle_row;
+ }
+ source->row = cinfo->image_height;
+
+ /* And fetch the topmost (bottommost) row */
+ return (*source->pub.get_pixel_rows) (cinfo, sinfo);
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ /* no work */
+}
+
+
+/*
+ * The module selection routine for RLE format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_rle (j_compress_ptr cinfo)
+{
+ rle_source_ptr source;
+
+ /* Create module interface object */
+ source = (rle_source_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(rle_source_struct));
+ /* Fill in method ptrs */
+ source->pub.start_input = start_input_rle;
+ source->pub.finish_input = finish_input_rle;
+ source->pub.get_pixel_rows = load_image;
+
+ return (cjpeg_source_ptr) source;
+}
+
+#endif /* RLE_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/rdswitch.c b/osframework/source/ImageLib/jpeg/rdswitch.c
new file mode 100644
index 0000000..b915ad9
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdswitch.c
@@ -0,0 +1,332 @@
+/*
+ * rdswitch.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to process some of cjpeg's more complicated
+ * command-line switches. Switches processed here are:
+ * -qtables file Read quantization tables from text file
+ * -scans file Read scan script from text file
+ * -qslots N[,N,...] Set component quantization table selectors
+ * -sample HxV[,HxV,...] Set component sampling factors
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include <ctype.h> /* to declare isdigit(), isspace() */
+
+
+LOCAL(int)
+text_getc (FILE * file)
+/* Read next char, skipping over any comments (# to end of line) */
+/* A comment/newline sequence is returned as a newline */
+{
+ register int ch;
+
+ ch = getc(file);
+ if (ch == '#') {
+ do {
+ ch = getc(file);
+ } while (ch != '\n' && ch != EOF);
+ }
+ return ch;
+}
+
+
+LOCAL(boolean)
+read_text_integer (FILE * file, long * result, int * termchar)
+/* Read an unsigned decimal integer from a file, store it in result */
+/* Reads one trailing character after the integer; returns it in termchar */
+{
+ register int ch;
+ register long val;
+
+ /* Skip any leading whitespace, detect EOF */
+ do {
+ ch = text_getc(file);
+ if (ch == EOF) {
+ *termchar = ch;
+ return FALSE;
+ }
+ } while (isspace(ch));
+
+ if (! isdigit(ch)) {
+ *termchar = ch;
+ return FALSE;
+ }
+
+ val = ch - '0';
+ while ((ch = text_getc(file)) != EOF) {
+ if (! isdigit(ch))
+ break;
+ val *= 10;
+ val += ch - '0';
+ }
+ *result = val;
+ *termchar = ch;
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+read_quant_tables (j_compress_ptr cinfo, char * filename,
+ int scale_factor, boolean force_baseline)
+/* Read a set of quantization tables from the specified file.
+ * The file is plain ASCII text: decimal numbers with whitespace between.
+ * Comments preceded by '#' may be included in the file.
+ * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
+ * The tables are implicitly numbered 0,1,etc.
+ * NOTE: does not affect the qslots mapping, which will default to selecting
+ * table 0 for luminance (or primary) components, 1 for chrominance components.
+ * You must use -qslots if you want a different component->table mapping.
+ */
+{
+ FILE * fp;
+ int tblno, i, termchar;
+ long val;
+ unsigned int table[DCTSIZE2];
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't open table file %s\n", filename);
+ return FALSE;
+ }
+ tblno = 0;
+
+ while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
+ if (tblno >= NUM_QUANT_TBLS) {
+ fprintf(stderr, "Too many tables in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ table[0] = (unsigned int) val;
+ for (i = 1; i < DCTSIZE2; i++) {
+ if (! read_text_integer(fp, &val, &termchar)) {
+ fprintf(stderr, "Invalid table data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ table[i] = (unsigned int) val;
+ }
+ jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
+ tblno++;
+ }
+
+ if (termchar != EOF) {
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+
+ fclose(fp);
+ return TRUE;
+}
+
+
+#ifdef C_MULTISCAN_FILES_SUPPORTED
+
+LOCAL(boolean)
+read_scan_integer (FILE * file, long * result, int * termchar)
+/* Variant of read_text_integer that always looks for a non-space termchar;
+ * this simplifies parsing of punctuation in scan scripts.
+ */
+{
+ register int ch;
+
+ if (! read_text_integer(file, result, termchar))
+ return FALSE;
+ ch = *termchar;
+ while (ch != EOF && isspace(ch))
+ ch = text_getc(file);
+ if (isdigit(ch)) { /* oops, put it back */
+ if (ungetc(ch, file) == EOF)
+ return FALSE;
+ ch = ' ';
+ } else {
+ /* Any separators other than ';' and ':' are ignored;
+ * this allows user to insert commas, etc, if desired.
+ */
+ if (ch != EOF && ch != ';' && ch != ':')
+ ch = ' ';
+ }
+ *termchar = ch;
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+read_scan_script (j_compress_ptr cinfo, char * filename)
+/* Read a scan script from the specified text file.
+ * Each entry in the file defines one scan to be emitted.
+ * Entries are separated by semicolons ';'.
+ * An entry contains one to four component indexes,
+ * optionally followed by a colon ':' and four progressive-JPEG parameters.
+ * The component indexes denote which component(s) are to be transmitted
+ * in the current scan. The first component has index 0.
+ * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
+ * The file is free format text: any whitespace may appear between numbers
+ * and the ':' and ';' punctuation marks. Also, other punctuation (such
+ * as commas or dashes) can be placed between numbers if desired.
+ * Comments preceded by '#' may be included in the file.
+ * Note: we do very little validity checking here;
+ * jcmaster.c will validate the script parameters.
+ */
+{
+ FILE * fp;
+ int scanno, ncomps, termchar;
+ long val;
+ jpeg_scan_info * scanptr;
+#define MAX_SCANS 100 /* quite arbitrary limit */
+ jpeg_scan_info scans[MAX_SCANS];
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't open scan definition file %s\n", filename);
+ return FALSE;
+ }
+ scanptr = scans;
+ scanno = 0;
+
+ while (read_scan_integer(fp, &val, &termchar)) {
+ if (scanno >= MAX_SCANS) {
+ fprintf(stderr, "Too many scans defined in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ scanptr->component_index[0] = (int) val;
+ ncomps = 1;
+ while (termchar == ' ') {
+ if (ncomps >= MAX_COMPS_IN_SCAN) {
+ fprintf(stderr, "Too many components in one scan in file %s\n",
+ filename);
+ fclose(fp);
+ return FALSE;
+ }
+ if (! read_scan_integer(fp, &val, &termchar))
+ goto bogus;
+ scanptr->component_index[ncomps] = (int) val;
+ ncomps++;
+ }
+ scanptr->comps_in_scan = ncomps;
+ if (termchar == ':') {
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Ss = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Se = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
+ goto bogus;
+ scanptr->Ah = (int) val;
+ if (! read_scan_integer(fp, &val, &termchar))
+ goto bogus;
+ scanptr->Al = (int) val;
+ } else {
+ /* set non-progressive parameters */
+ scanptr->Ss = 0;
+ scanptr->Se = DCTSIZE2-1;
+ scanptr->Ah = 0;
+ scanptr->Al = 0;
+ }
+ if (termchar != ';' && termchar != EOF) {
+bogus:
+ fprintf(stderr, "Invalid scan entry format in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+ scanptr++, scanno++;
+ }
+
+ if (termchar != EOF) {
+ fprintf(stderr, "Non-numeric data in file %s\n", filename);
+ fclose(fp);
+ return FALSE;
+ }
+
+ if (scanno > 0) {
+ /* Stash completed scan list in cinfo structure.
+ * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
+ * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
+ */
+ scanptr = (jpeg_scan_info *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ scanno * SIZEOF(jpeg_scan_info));
+ MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
+ cinfo->scan_info = scanptr;
+ cinfo->num_scans = scanno;
+ }
+
+ fclose(fp);
+ return TRUE;
+}
+
+#endif /* C_MULTISCAN_FILES_SUPPORTED */
+
+
+GLOBAL(boolean)
+set_quant_slots (j_compress_ptr cinfo, char *arg)
+/* Process a quantization-table-selectors parameter string, of the form
+ * N[,N,...]
+ * If there are more components than parameters, the last value is replicated.
+ */
+{
+ int val = 0; /* default table # */
+ int ci;
+ char ch;
+
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
+ if (*arg) {
+ ch = ','; /* if not set by sscanf, will be ',' */
+ if (sscanf(arg, "%d%c", &val, &ch) < 1)
+ return FALSE;
+ if (ch != ',') /* syntax check */
+ return FALSE;
+ if (val < 0 || val >= NUM_QUANT_TBLS) {
+ fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
+ NUM_QUANT_TBLS-1);
+ return FALSE;
+ }
+ cinfo->comp_info[ci].quant_tbl_no = val;
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
+ ;
+ } else {
+ /* reached end of parameter, set remaining components to last table */
+ cinfo->comp_info[ci].quant_tbl_no = val;
+ }
+ }
+ return TRUE;
+}
+
+
+GLOBAL(boolean)
+set_sample_factors (j_compress_ptr cinfo, char *arg)
+/* Process a sample-factors parameter string, of the form
+ * HxV[,HxV,...]
+ * If there are more components than parameters, "1x1" is assumed for the rest.
+ */
+{
+ int ci, val1, val2;
+ char ch1, ch2;
+
+ for (ci = 0; ci < MAX_COMPONENTS; ci++) {
+ if (*arg) {
+ ch2 = ','; /* if not set by sscanf, will be ',' */
+ if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
+ return FALSE;
+ if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
+ return FALSE;
+ if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
+ fprintf(stderr, "JPEG sampling factors must be 1..4\n");
+ return FALSE;
+ }
+ cinfo->comp_info[ci].h_samp_factor = val1;
+ cinfo->comp_info[ci].v_samp_factor = val2;
+ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
+ ;
+ } else {
+ /* reached end of parameter, set remaining components to 1x1 sampling */
+ cinfo->comp_info[ci].h_samp_factor = 1;
+ cinfo->comp_info[ci].v_samp_factor = 1;
+ }
+ }
+ return TRUE;
+}
diff --git a/osframework/source/ImageLib/jpeg/rdtarga.c b/osframework/source/ImageLib/jpeg/rdtarga.c
new file mode 100644
index 0000000..d7ffc33
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/rdtarga.c
@@ -0,0 +1,500 @@
+/*
+ * rdtarga.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to read input images in Targa format.
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume input from
+ * an ordinary stdio stream. They further assume that reading begins
+ * at the start of the file; start_input may need work if the
+ * user interface has already read some data (e.g., to determine that
+ * the file is indeed Targa format).
+ *
+ * Based on code contributed by Lee Daniel Crocker.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef TARGA_SUPPORTED
+
+
+/* Macros to deal with unsigned chars as efficiently as compiler allows */
+
+#ifdef HAVE_UNSIGNED_CHAR
+typedef unsigned char U_CHAR;
+#define UCH(x) ((int) (x))
+#else /* !HAVE_UNSIGNED_CHAR */
+#ifdef CHAR_IS_UNSIGNED
+typedef char U_CHAR;
+#define UCH(x) ((int) (x))
+#else
+typedef char U_CHAR;
+#define UCH(x) ((int) (x) & 0xFF)
+#endif
+#endif /* HAVE_UNSIGNED_CHAR */
+
+
+#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
+
+
+/* Private version of data source object */
+
+typedef struct _tga_source_struct * tga_source_ptr;
+
+typedef struct _tga_source_struct {
+ struct cjpeg_source_struct pub; /* public fields */
+
+ j_compress_ptr cinfo; /* back link saves passing separate parm */
+
+ JSAMPARRAY colormap; /* Targa colormap (converted to my format) */
+
+ jvirt_sarray_ptr whole_image; /* Needed if funny input row order */
+ JDIMENSION current_row; /* Current logical row number to read */
+
+ /* Pointer to routine to extract next Targa pixel from input file */
+ JMETHOD(void, read_pixel, (tga_source_ptr sinfo));
+
+ /* Result of read_pixel is delivered here: */
+ U_CHAR tga_pixel[4];
+
+ int pixel_size; /* Bytes per Targa pixel (1 to 4) */
+
+ /* State info for reading RLE-coded pixels; both counts must be init to 0 */
+ int block_count; /* # of pixels remaining in RLE block */
+ int dup_pixel_count; /* # of times to duplicate previous pixel */
+
+ /* This saves the correct pixel-row-expansion method for preload_image */
+ JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
+ cjpeg_source_ptr sinfo));
+} tga_source_struct;
+
+
+/* For expanding 5-bit pixel values to 8-bit with best rounding */
+
+static const UINT8 c5to8bits[32] = {
+ 0, 8, 16, 25, 33, 41, 49, 58,
+ 66, 74, 82, 90, 99, 107, 115, 123,
+ 132, 140, 148, 156, 165, 173, 181, 189,
+ 197, 206, 214, 222, 230, 239, 247, 255
+};
+
+
+
+LOCAL(int)
+read_byte (tga_source_ptr sinfo)
+/* Read next byte from Targa file */
+{
+ register FILE *infile = sinfo->pub.input_file;
+ register int c;
+
+ if ((c = getc(infile)) == EOF)
+ ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
+ return c;
+}
+
+
+LOCAL(void)
+read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize)
+/* Read the colormap from a Targa file */
+{
+ int i;
+
+ /* Presently only handles 24-bit BGR format */
+ if (mapentrysize != 24)
+ ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP);
+
+ for (i = 0; i < cmaplen; i++) {
+ sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
+ sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
+ }
+}
+
+
+/*
+ * read_pixel methods: get a single pixel from Targa file into tga_pixel[]
+ */
+
+METHODDEF(void)
+read_non_rle_pixel (tga_source_ptr sinfo)
+/* Read one Targa pixel from the input file; no RLE expansion */
+{
+ register FILE *infile = sinfo->pub.input_file;
+ register int i;
+
+ for (i = 0; i < sinfo->pixel_size; i++) {
+ sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
+ }
+}
+
+
+METHODDEF(void)
+read_rle_pixel (tga_source_ptr sinfo)
+/* Read one Targa pixel from the input file, expanding RLE data as needed */
+{
+ register FILE *infile = sinfo->pub.input_file;
+ register int i;
+
+ /* Duplicate previously read pixel? */
+ if (sinfo->dup_pixel_count > 0) {
+ sinfo->dup_pixel_count--;
+ return;
+ }
+
+ /* Time to read RLE block header? */
+ if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
+ i = read_byte(sinfo);
+ if (i & 0x80) { /* Start of duplicate-pixel block? */
+ sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
+ sinfo->block_count = 0; /* then read new block header */
+ } else {
+ sinfo->block_count = i & 0x7F; /* number of pixels after this one */
+ }
+ }
+
+ /* Read next pixel */
+ for (i = 0; i < sinfo->pixel_size; i++) {
+ sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
+ }
+}
+
+
+/*
+ * Read one row of pixels.
+ *
+ * We provide several different versions depending on input file format.
+ */
+
+
+METHODDEF(JDIMENSION)
+get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 8-bit grayscale pixels */
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
+ }
+ return 1;
+}
+
+METHODDEF(JDIMENSION)
+get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 8-bit colormap indexes */
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ register int t;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+ register JSAMPARRAY colormap = source->colormap;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
+ t = UCH(source->tga_pixel[0]);
+ *ptr++ = colormap[0][t];
+ *ptr++ = colormap[1][t];
+ *ptr++ = colormap[2][t];
+ }
+ return 1;
+}
+
+METHODDEF(JDIMENSION)
+get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 16-bit pixels */
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ register int t;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
+ t = UCH(source->tga_pixel[0]);
+ t += UCH(source->tga_pixel[1]) << 8;
+ /* We expand 5 bit data to 8 bit sample width.
+ * The format of the 16-bit (LSB first) input word is
+ * xRRRRRGGGGGBBBBB
+ */
+ ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F];
+ t >>= 5;
+ ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F];
+ t >>= 5;
+ ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F];
+ ptr += 3;
+ }
+ return 1;
+}
+
+METHODDEF(JDIMENSION)
+get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+/* This version is for reading 24-bit pixels */
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+
+ ptr = source->pub.buffer[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]);
+ *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
+ }
+ return 1;
+}
+
+/*
+ * Targa also defines a 32-bit pixel format with order B,G,R,A.
+ * We presently ignore the attribute byte, so the code for reading
+ * these pixels is identical to the 24-bit routine above.
+ * This works because the actual pixel length is only known to read_pixel.
+ */
+
+#define get_32bit_row get_24bit_row
+
+
+/*
+ * This method is for re-reading the input data in standard top-down
+ * row order. The entire image has already been read into whole_image
+ * with proper conversion of pixel format, but it's in a funny row order.
+ */
+
+METHODDEF(JDIMENSION)
+get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ JDIMENSION source_row;
+
+ /* Compute row of source that maps to current_row of normal order */
+ /* For now, assume image is bottom-up and not interlaced. */
+ /* NEEDS WORK to support interlaced images! */
+ source_row = cinfo->image_height - source->current_row - 1;
+
+ /* Fetch that row from virtual array */
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->whole_image,
+ source_row, (JDIMENSION) 1, FALSE);
+
+ source->current_row++;
+ return 1;
+}
+
+
+/*
+ * This method loads the image into whole_image during the first call on
+ * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
+ * get_memory_row on subsequent calls.
+ */
+
+METHODDEF(JDIMENSION)
+preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ JDIMENSION row;
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+
+ /* Read the data into a virtual array in input-file row order. */
+ for (row = 0; row < cinfo->image_height; row++) {
+ if (progress != NULL) {
+ progress->pub.pass_counter = (long) row;
+ progress->pub.pass_limit = (long) cinfo->image_height;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+ source->pub.buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE);
+ (*source->get_pixel_rows) (cinfo, sinfo);
+ }
+ if (progress != NULL)
+ progress->completed_extra_passes++;
+
+ /* Set up to read from the virtual array in unscrambled order */
+ source->pub.get_pixel_rows = get_memory_row;
+ source->current_row = 0;
+ /* And read the first row */
+ return get_memory_row(cinfo, sinfo);
+}
+
+
+/*
+ * Read the file header; return image size and component count.
+ */
+
+METHODDEF(void)
+start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ tga_source_ptr source = (tga_source_ptr) sinfo;
+ U_CHAR targaheader[18];
+ int idlen, cmaptype, subtype, flags, interlace_type, components;
+ unsigned int width, height, maplen;
+ boolean is_bottom_up;
+
+#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
+ (((unsigned int) UCH(targaheader[offset+1])) << 8))
+
+ if (! ReadOK(source->pub.input_file, targaheader, 18))
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+
+ /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */
+ if (targaheader[16] == 15)
+ targaheader[16] = 16;
+
+ idlen = UCH(targaheader[0]);
+ cmaptype = UCH(targaheader[1]);
+ subtype = UCH(targaheader[2]);
+ maplen = GET_2B(5);
+ width = GET_2B(12);
+ height = GET_2B(14);
+ source->pixel_size = UCH(targaheader[16]) >> 3;
+ flags = UCH(targaheader[17]); /* Image Descriptor byte */
+
+ is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */
+ interlace_type = flags >> 6; /* bits 6/7 are interlace code */
+
+ if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
+ source->pixel_size < 1 || source->pixel_size > 4 ||
+ (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
+ interlace_type != 0) /* currently don't allow interlaced image */
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+
+ if (subtype > 8) {
+ /* It's an RLE-coded file */
+ source->read_pixel = read_rle_pixel;
+ source->block_count = source->dup_pixel_count = 0;
+ subtype -= 8;
+ } else {
+ /* Non-RLE file */
+ source->read_pixel = read_non_rle_pixel;
+ }
+
+ /* Now should have subtype 1, 2, or 3 */
+ components = 3; /* until proven different */
+ cinfo->in_color_space = JCS_RGB;
+
+ switch (subtype) {
+ case 1: /* Colormapped image */
+ if (source->pixel_size == 1 && cmaptype == 1)
+ source->get_pixel_rows = get_8bit_row;
+ else
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+ TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
+ break;
+ case 2: /* RGB image */
+ switch (source->pixel_size) {
+ case 2:
+ source->get_pixel_rows = get_16bit_row;
+ break;
+ case 3:
+ source->get_pixel_rows = get_24bit_row;
+ break;
+ case 4:
+ source->get_pixel_rows = get_32bit_row;
+ break;
+ default:
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+ break;
+ }
+ TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
+ break;
+ case 3: /* Grayscale image */
+ components = 1;
+ cinfo->in_color_space = JCS_GRAYSCALE;
+ if (source->pixel_size == 1)
+ source->get_pixel_rows = get_8bit_gray_row;
+ else
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+ TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+ break;
+ }
+
+ if (is_bottom_up) {
+ /* Create a virtual array to buffer the upside-down image. */
+ source->whole_image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);
+ if (cinfo->progress != NULL) {
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+ progress->total_extra_passes++; /* count file input as separate pass */
+ }
+ /* source->pub.buffer will point to the virtual array. */
+ source->pub.buffer_height = 1; /* in case anyone looks at it */
+ source->pub.get_pixel_rows = preload_image;
+ } else {
+ /* Don't need a virtual array, but do need a one-row input buffer. */
+ source->whole_image = NULL;
+ source->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (JDIMENSION) width * components, (JDIMENSION) 1);
+ source->pub.buffer_height = 1;
+ source->pub.get_pixel_rows = source->get_pixel_rows;
+ }
+
+ while (idlen--) /* Throw away ID field */
+ (void) read_byte(source);
+
+ if (maplen > 0) {
+ if (maplen > 256 || GET_2B(3) != 0)
+ ERREXIT(cinfo, JERR_TGA_BADCMAP);
+ /* Allocate space to store the colormap */
+ source->colormap = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);
+ /* and read it from the file */
+ read_colormap(source, (int) maplen, UCH(targaheader[7]));
+ } else {
+ if (cmaptype) /* but you promised a cmap! */
+ ERREXIT(cinfo, JERR_TGA_BADPARMS);
+ source->colormap = NULL;
+ }
+
+ cinfo->input_components = components;
+ cinfo->data_precision = 8;
+ cinfo->image_width = width;
+ cinfo->image_height = height;
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
+{
+ /* no work */
+}
+
+
+/*
+ * The module selection routine for Targa format input.
+ */
+
+GLOBAL(cjpeg_source_ptr)
+jinit_read_targa (j_compress_ptr cinfo)
+{
+ tga_source_ptr source;
+
+ /* Create module interface object */
+ source = (tga_source_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(tga_source_struct));
+ source->cinfo = cinfo; /* make back link for subroutines */
+ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
+ source->pub.start_input = start_input_tga;
+ source->pub.finish_input = finish_input_tga;
+
+ return (cjpeg_source_ptr) source;
+}
+
+#endif /* TARGA_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/readme b/osframework/source/ImageLib/jpeg/readme
new file mode 100644
index 0000000..911d0e8
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/readme
@@ -0,0 +1,385 @@
+The Independent JPEG Group's JPEG software
+==========================================
+
+README for release 6b of 27-Mar-1998
+====================================
+
+This distribution contains the sixth public release of the Independent JPEG
+Group's free JPEG software. You are welcome to redistribute this software and
+to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
+
+Serious users of this software (particularly those incorporating it into
+larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
+our electronic mailing list. Mailing list members are notified of updates
+and have a chance to participate in technical discussions, etc.
+
+This software is the work of Tom Lane, Philip Gladstone, Jim Boucher,
+Lee Crocker, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi,
+Guido Vollbeding, Ge' Weijers, and other members of the Independent JPEG
+Group.
+
+IJG is not affiliated with the official ISO JPEG standards committee.
+
+
+DOCUMENTATION ROADMAP
+=====================
+
+This file contains the following sections:
+
+OVERVIEW General description of JPEG and the IJG software.
+LEGAL ISSUES Copyright, lack of warranty, terms of distribution.
+REFERENCES Where to learn more about JPEG.
+ARCHIVE LOCATIONS Where to find newer versions of this software.
+RELATED SOFTWARE Other stuff you should get.
+FILE FORMAT WARS Software *not* to get.
+TO DO Plans for future IJG releases.
+
+Other documentation files in the distribution are:
+
+User documentation:
+ install.doc How to configure and install the IJG software.
+ usage.doc Usage instructions for cjpeg, djpeg, jpegtran,
+ rdjpgcom, and wrjpgcom.
+ *.1 Unix-style man pages for programs (same info as usage.doc).
+ wizard.doc Advanced usage instructions for JPEG wizards only.
+ change.log Version-to-version change highlights.
+Programmer and internal documentation:
+ libjpeg.doc How to use the JPEG library in your own programs.
+ example.c Sample code for calling the JPEG library.
+ structure.doc Overview of the JPEG library's internal structure.
+ filelist.doc Road map of IJG files.
+ coderules.doc Coding style rules --- please read if you contribute code.
+
+Please read at least the files install.doc and usage.doc. Useful information
+can also be found in the JPEG FAQ (Frequently Asked Questions) article. See
+ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
+
+If you want to understand how the JPEG code works, we suggest reading one or
+more of the REFERENCES, then looking at the documentation files (in roughly
+the order listed) before diving into the code.
+
+
+OVERVIEW
+========
+
+This package contains C software to implement JPEG image compression and
+decompression. JPEG (pronounced "jay-peg") is a standardized compression
+method for full-color and gray-scale images. JPEG is intended for compressing
+"real-world" scenes; line drawings, cartoons and other non-realistic images
+are not its strong suit. JPEG is lossy, meaning that the output image is not
+exactly identical to the input image. Hence you must not use JPEG if you
+have to have identical output bits. However, on typical photographic images,
+very good compression levels can be obtained with no visible change, and
+remarkably high compression levels are possible if you can tolerate a
+low-quality image. For more details, see the references, or just experiment
+with various compression settings.
+
+This software implements JPEG baseline, extended-sequential, and progressive
+compression processes. Provision is made for supporting all variants of these
+processes, although some uncommon parameter settings aren't implemented yet.
+For legal reasons, we are not distributing code for the arithmetic-coding
+variants of JPEG; see LEGAL ISSUES. We have made no provision for supporting
+the hierarchical or lossless processes defined in the standard.
+
+We provide a set of library routines for reading and writing JPEG image files,
+plus two sample applications "cjpeg" and "djpeg", which use the library to
+perform conversion between JPEG and some other popular image file formats.
+The library is intended to be reused in other applications.
+
+In order to support file conversion and viewing software, we have included
+considerable functionality beyond the bare JPEG coding/decoding capability;
+for example, the color quantization modules are not strictly part of JPEG
+decoding, but they are essential for output to colormapped file formats or
+colormapped displays. These extra functions can be compiled out of the
+library if not required for a particular application. We have also included
+"jpegtran", a utility for lossless transcoding between different JPEG
+processes, and "rdjpgcom" and "wrjpgcom", two simple applications for
+inserting and extracting textual comments in JFIF files.
+
+The emphasis in designing this software has been on achieving portability and
+flexibility, while also making it fast enough to be useful. In particular,
+the software is not intended to be read as a tutorial on JPEG. (See the
+REFERENCES section for introductory material.) Rather, it is intended to
+be reliable, portable, industrial-strength code. We do not claim to have
+achieved that goal in every aspect of the software, but we strive for it.
+
+We welcome the use of this software as a component of commercial products.
+No royalty is required, but we do ask for an acknowledgement in product
+documentation, as described under LEGAL ISSUES.
+
+
+LEGAL ISSUES
+============
+
+In plain English:
+
+1. We don't promise that this software works. (But if you find any bugs,
+ please let us know!)
+2. You can use this software for whatever you want. You don't have to pay us.
+3. You may not pretend that you wrote this software. If you use it in a
+ program, you must acknowledge somewhere in your documentation that
+ you've used the IJG code.
+
+In legalese:
+
+The authors make NO WARRANTY or representation, either express or implied,
+with respect to this software, its quality, accuracy, merchantability, or
+fitness for a particular purpose. This software is provided "AS IS", and you,
+its user, assume the entire risk as to its quality and accuracy.
+
+This software is copyright (C) 1991-1998, Thomas G. Lane.
+All Rights Reserved except as specified below.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+software (or portions thereof) for any purpose, without fee, subject to these
+conditions:
+(1) If any part of the source code for this software is distributed, then this
+README file must be included, with this copyright and no-warranty notice
+unaltered; and any additions, deletions, or changes to the original files
+must be clearly indicated in accompanying documentation.
+(2) If only executable code is distributed, then the accompanying
+documentation must state that "this software is based in part on the work of
+the Independent JPEG Group".
+(3) Permission for use of this software is granted only if the user accepts
+full responsibility for any undesirable consequences; the authors accept
+NO LIABILITY for damages of any kind.
+
+These conditions apply to any software derived from or based on the IJG code,
+not just to the unmodified library. If you use our work, you ought to
+acknowledge us.
+
+Permission is NOT granted for the use of any IJG author's name or company name
+in advertising or publicity relating to this software or products derived from
+it. This software may be referred to only as "the Independent JPEG Group's
+software".
+
+We specifically permit and encourage the use of this software as the basis of
+commercial products, provided that all warranty or liability claims are
+assumed by the product vendor.
+
+
+ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
+sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
+ansi2knr.c is NOT covered by the above copyright and conditions, but instead
+by the usual distribution terms of the Free Software Foundation; principally,
+that you must include source code if you redistribute it. (See the file
+ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part
+of any program generated from the IJG code, this does not limit you more than
+the foregoing paragraphs do.
+
+The Unix configuration script "configure" was produced with GNU Autoconf.
+It is copyright by the Free Software Foundation but is freely distributable.
+The same holds for its supporting scripts (config.guess, config.sub,
+ltconfig, ltmain.sh). Another support script, install-sh, is copyright
+by M.I.T. but is also freely distributable.
+
+It appears that the arithmetic coding option of the JPEG spec is covered by
+patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot
+legally be used without obtaining one or more licenses. For this reason,
+support for arithmetic coding has been removed from the free JPEG software.
+(Since arithmetic coding provides only a marginal gain over the unpatented
+Huffman mode, it is unlikely that very many implementations will support it.)
+So far as we are aware, there are no patent restrictions on the remaining
+code.
+
+The IJG distribution formerly included code to read and write GIF files.
+To avoid entanglement with the Unisys LZW patent, GIF reading support has
+been removed altogether, and the GIF writer has been simplified to produce
+"uncompressed GIFs". This technique does not use the LZW algorithm; the
+resulting GIF files are larger than usual, but are readable by all standard
+GIF decoders.
+
+We are required to state that
+ "The Graphics Interchange Format(c) is the Copyright property of
+ CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ CompuServe Incorporated."
+
+
+REFERENCES
+==========
+
+We highly recommend reading one or more of these references before trying to
+understand the innards of the JPEG software.
+
+The best short technical introduction to the JPEG compression algorithm is
+ Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
+ Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
+(Adjacent articles in that issue discuss MPEG motion picture compression,
+applications of JPEG, and related topics.) If you don't have the CACM issue
+handy, a PostScript file containing a revised version of Wallace's article is
+available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz. The file (actually
+a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
+omits the sample images that appeared in CACM, but it includes corrections
+and some added material. Note: the Wallace article is copyright ACM and IEEE,
+and it may not be used for commercial purposes.
+
+A somewhat less technical, more leisurely introduction to JPEG can be found in
+"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
+M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1. This book provides
+good explanations and example C code for a multitude of compression methods
+including JPEG. It is an excellent source if you are comfortable reading C
+code but don't know much about data compression in general. The book's JPEG
+sample code is far from industrial-strength, but when you are ready to look
+at a full implementation, you've got one here...
+
+The best full description of JPEG is the textbook "JPEG Still Image Data
+Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published
+by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. Price US$59.95, 638 pp.
+The book includes the complete text of the ISO JPEG standards (DIS 10918-1
+and draft DIS 10918-2). This is by far the most complete exposition of JPEG
+in existence, and we highly recommend it.
+
+The JPEG standard itself is not available electronically; you must order a
+paper copy through ISO or ITU. (Unless you feel a need to own a certified
+official copy, we recommend buying the Pennebaker and Mitchell book instead;
+it's much cheaper and includes a great deal of useful explanatory material.)
+In the USA, copies of the standard may be ordered from ANSI Sales at (212)
+642-4900, or from Global Engineering Documents at (800) 854-7179. (ANSI
+doesn't take credit card orders, but Global does.) It's not cheap: as of
+1992, ANSI was charging $95 for Part 1 and $47 for Part 2, plus 7%
+shipping/handling. The standard is divided into two parts, Part 1 being the
+actual specification, while Part 2 covers compliance testing methods. Part 1
+is titled "Digital Compression and Coding of Continuous-tone Still Images,
+Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
+10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of
+Continuous-tone Still Images, Part 2: Compliance testing" and has document
+numbers ISO/IEC IS 10918-2, ITU-T T.83.
+
+Some extensions to the original JPEG standard are defined in JPEG Part 3,
+a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84. IJG
+currently does not support any Part 3 extensions.
+
+The JPEG standard does not specify all details of an interchangeable file
+format. For the omitted details we follow the "JFIF" conventions, revision
+1.02. A copy of the JFIF spec is available from:
+ Literature Department
+ C-Cube Microsystems, Inc.
+ 1778 McCarthy Blvd.
+ Milpitas, CA 95035
+ phone (408) 944-6300, fax (408) 944-6314
+A PostScript version of this document is available by FTP at
+ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz. There is also a plain text
+version at ftp://ftp.uu.net/graphics/jpeg/jfif.txt.gz, but it is missing
+the figures.
+
+The TIFF 6.0 file format specification can be obtained by FTP from
+ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
+found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
+IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
+Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
+(Compression tag 7). Copies of this Note can be obtained from ftp.sgi.com or
+from ftp://ftp.uu.net/graphics/jpeg/. It is expected that the next revision
+of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
+Although IJG's own code does not support TIFF/JPEG, the free libtiff library
+uses our library to implement TIFF/JPEG per the Note. libtiff is available
+from ftp://ftp.sgi.com/graphics/tiff/.
+
+
+ARCHIVE LOCATIONS
+=================
+
+The "official" archive site for this software is ftp.uu.net (Internet
+address 192.48.96.9). The most recent released version can always be found
+there in directory graphics/jpeg. This particular version will be archived
+as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz. If you don't have
+direct Internet access, UUNET's archives are also available via UUCP; contact
+help@uunet.uu.net for information on retrieving files that way.
+
+Numerous Internet sites maintain copies of the UUNET files. However, only
+ftp.uu.net is guaranteed to have the latest official version.
+
+You can also obtain this software in DOS-compatible "zip" archive format from
+the SimTel archives (ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/), or
+on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP), library 12
+"JPEG Tools". Again, these versions may sometimes lag behind the ftp.uu.net
+release.
+
+The JPEG FAQ (Frequently Asked Questions) article is a useful source of
+general information about JPEG. It is updated constantly and therefore is
+not included in this distribution. The FAQ is posted every two weeks to
+Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
+It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
+and other news.answers archive sites, including the official news.answers
+archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
+If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
+with body
+ send usenet/news.answers/jpeg-faq/part1
+ send usenet/news.answers/jpeg-faq/part2
+
+
+RELATED SOFTWARE
+================
+
+Numerous viewing and image manipulation programs now support JPEG. (Quite a
+few of them use this library to do so.) The JPEG FAQ described above lists
+some of the more popular free and shareware viewers, and tells where to
+obtain them on Internet.
+
+If you are on a Unix machine, we highly recommend Jef Poskanzer's free
+PBMPLUS software, which provides many useful operations on PPM-format image
+files. In particular, it can convert PPM images to and from a wide range of
+other formats, thus making cjpeg/djpeg considerably more useful. The latest
+version is distributed by the NetPBM group, and is available from numerous
+sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/.
+Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is;
+you are likely to have difficulty making it work on any non-Unix machine.
+
+A different free JPEG implementation, written by the PVRG group at Stanford,
+is available from ftp://havefun.stanford.edu/pub/jpeg/. This program
+is designed for research and experimentation rather than production use;
+it is slower, harder to use, and less portable than the IJG code, but it
+is easier to read and modify. Also, the PVRG code supports lossless JPEG,
+which we do not. (On the other hand, it doesn't do progressive JPEG.)
+
+
+FILE FORMAT WARS
+================
+
+Some JPEG programs produce files that are not compatible with our library.
+The root of the problem is that the ISO JPEG committee failed to specify a
+concrete file format. Some vendors "filled in the blanks" on their own,
+creating proprietary formats that no one else could read. (For example, none
+of the early commercial JPEG implementations for the Macintosh were able to
+exchange compressed files.)
+
+The file format we have adopted is called JFIF (see REFERENCES). This format
+has been agreed to by a number of major commercial JPEG vendors, and it has
+become the de facto standard. JFIF is a minimal or "low end" representation.
+We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF
+Technical Note #2) for "high end" applications that need to record a lot of
+additional data about an image. TIFF/JPEG is fairly new and not yet widely
+supported, unfortunately.
+
+The upcoming JPEG Part 3 standard defines a file format called SPIFF.
+SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should
+be able to read the most common variant of SPIFF. SPIFF has some technical
+advantages over JFIF, but its major claim to fame is simply that it is an
+official standard rather than an informal one. At this point it is unclear
+whether SPIFF will supersede JFIF or whether JFIF will remain the de-facto
+standard. IJG intends to support SPIFF once the standard is frozen, but we
+have not decided whether it should become our default output format or not.
+(In any case, our decoder will remain capable of reading JFIF indefinitely.)
+
+Various proprietary file formats incorporating JPEG compression also exist.
+We have little or no sympathy for the existence of these formats. Indeed,
+one of the original reasons for developing this free software was to help
+force convergence on common, open format standards for JPEG files. Don't
+use a proprietary file format!
+
+
+TO DO
+=====
+
+The major thrust for v7 will probably be improvement of visual quality.
+The current method for scaling the quantization tables is known not to be
+very good at low Q values. We also intend to investigate block boundary
+smoothing, "poor man's variable quantization", and other means of improving
+quality-vs-file-size performance without sacrificing compatibility.
+
+In future versions, we are considering supporting some of the upcoming JPEG
+Part 3 extensions --- principally, variable quantization and the SPIFF file
+format.
+
+As always, speeding things up is of great interest.
+
+Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
diff --git a/osframework/source/ImageLib/jpeg/transupp.c b/osframework/source/ImageLib/jpeg/transupp.c
new file mode 100644
index 0000000..53a9940
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/transupp.c
@@ -0,0 +1,928 @@
+/*
+ * transupp.c
+ *
+ * Copyright (C) 1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains image transformation routines and other utility code
+ * used by the jpegtran sample application. These are NOT part of the core
+ * JPEG library. But we keep these routines separate from jpegtran.c to
+ * ease the task of maintaining jpegtran-like programs that have other user
+ * interfaces.
+ */
+
+/* Although this file really shouldn't have access to the library internals,
+ * it's helpful to let it call jround_up() and jcopy_block_row().
+ */
+#define JPEG_INTERNALS
+
+#include "jinclude.h"
+#include "jpeglib.h"
+#include "transupp.h" /* My own external interface */
+
+
+#if TRANSFORMS_SUPPORTED
+
+/*
+ * Lossless image transformation routines. These routines work on DCT
+ * coefficient arrays and thus do not require any lossy decompression
+ * or recompression of the image.
+ * Thanks to Guido Vollbeding for the initial design and code of this feature.
+ *
+ * Horizontal flipping is done in-place, using a single top-to-bottom
+ * pass through the virtual source array. It will thus be much the
+ * fastest option for images larger than main memory.
+ *
+ * The other routines require a set of destination virtual arrays, so they
+ * need twice as much memory as jpegtran normally does. The destination
+ * arrays are always written in normal scan order (top to bottom) because
+ * the virtual array manager expects this. The source arrays will be scanned
+ * in the corresponding order, which means multiple passes through the source
+ * arrays for most of the transforms. That could result in much thrashing
+ * if the image is larger than main memory.
+ *
+ * Some notes about the operating environment of the individual transform
+ * routines:
+ * 1. Both the source and destination virtual arrays are allocated from the
+ * source JPEG object, and therefore should be manipulated by calling the
+ * source's memory manager.
+ * 2. The destination's component count should be used. It may be smaller
+ * than the source's when forcing to grayscale.
+ * 3. Likewise the destination's sampling factors should be used. When
+ * forcing to grayscale the destination's sampling factors will be all 1,
+ * and we may as well take that as the effective iMCU size.
+ * 4. When "trim" is in effect, the destination's dimensions will be the
+ * trimmed values but the source's will be untrimmed.
+ * 5. All the routines assume that the source and destination buffers are
+ * padded out to a full iMCU boundary. This is true, although for the
+ * source buffer it is an undocumented property of jdcoefct.c.
+ * Notes 2,3,4 boil down to this: generally we should use the destination's
+ * dimensions and ignore the source's.
+ */
+
+
+LOCAL(void)
+do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays)
+/* Horizontal flip; done in-place, so no separate dest array is required */
+{
+ JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
+ int ci, k, offset_y;
+ JBLOCKARRAY buffer;
+ JCOEFPTR ptr1, ptr2;
+ JCOEF temp1, temp2;
+ jpeg_component_info *compptr;
+
+ /* Horizontal mirroring of DCT blocks is accomplished by swapping
+ * pairs of blocks in-place. Within a DCT block, we perform horizontal
+ * mirroring by changing the signs of odd-numbered columns.
+ * Partial iMCUs at the right edge are left untouched.
+ */
+ MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_width = MCU_cols * compptr->h_samp_factor;
+ for (blk_y = 0; blk_y < compptr->height_in_blocks;
+ blk_y += compptr->v_samp_factor) {
+ buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
+ ptr1 = buffer[offset_y][blk_x];
+ ptr2 = buffer[offset_y][comp_width - blk_x - 1];
+ /* this unrolled loop doesn't need to know which row it's on... */
+ for (k = 0; k < DCTSIZE2; k += 2) {
+ temp1 = *ptr1; /* swap even column */
+ temp2 = *ptr2;
+ *ptr1++ = temp2;
+ *ptr2++ = temp1;
+ temp1 = *ptr1; /* swap odd column with sign change */
+ temp2 = *ptr2;
+ *ptr1++ = -temp2;
+ *ptr2++ = -temp1;
+ }
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* Vertical flip */
+{
+ JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JBLOCKROW src_row_ptr, dst_row_ptr;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ /* We output into a separate array because we can't touch different
+ * rows of the source virtual array simultaneously. Otherwise, this
+ * is a pretty straightforward analog of horizontal flip.
+ * Within a DCT block, vertical mirroring is done by changing the signs
+ * of odd-numbered rows.
+ * Partial iMCUs at the bottom edge are copied verbatim.
+ */
+ MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_height = MCU_rows * compptr->v_samp_factor;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ if (dst_blk_y < comp_height) {
+ /* Row is within the mirrorable area. */
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci],
+ comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ } else {
+ /* Bottom-edge blocks will be copied verbatim. */
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ }
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ if (dst_blk_y < comp_height) {
+ /* Row is within the mirrorable area. */
+ dst_row_ptr = dst_buffer[offset_y];
+ src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
+ for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
+ dst_blk_x++) {
+ dst_ptr = dst_row_ptr[dst_blk_x];
+ src_ptr = src_row_ptr[dst_blk_x];
+ for (i = 0; i < DCTSIZE; i += 2) {
+ /* copy even row */
+ for (j = 0; j < DCTSIZE; j++)
+ *dst_ptr++ = *src_ptr++;
+ /* copy odd row with sign change */
+ for (j = 0; j < DCTSIZE; j++)
+ *dst_ptr++ = - *src_ptr++;
+ }
+ }
+ } else {
+ /* Just copy row verbatim. */
+ jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
+ compptr->width_in_blocks);
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* Transpose source into destination */
+{
+ JDIMENSION dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_x, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ /* Transposing pixels within a block just requires transposing the
+ * DCT coefficients.
+ * Partial iMCUs at the edges require no special treatment; we simply
+ * process all the available DCT blocks for every component.
+ */
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
+ dst_blk_x += compptr->h_samp_factor) {
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
+ (JDIMENSION) compptr->h_samp_factor, FALSE);
+ for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
+ src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
+ dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
+ for (i = 0; i < DCTSIZE; i++)
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ }
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* 90 degree rotation is equivalent to
+ * 1. Transposing the image;
+ * 2. Horizontal mirroring.
+ * These two steps are merged into a single processing routine.
+ */
+{
+ JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_x, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ /* Because of the horizontal mirror step, we can't process partial iMCUs
+ * at the (output) right edge properly. They just get transposed and
+ * not mirrored.
+ */
+ MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_width = MCU_cols * compptr->h_samp_factor;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
+ dst_blk_x += compptr->h_samp_factor) {
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
+ (JDIMENSION) compptr->h_samp_factor, FALSE);
+ for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
+ src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
+ if (dst_blk_x < comp_width) {
+ /* Block is within the mirrorable area. */
+ dst_ptr = dst_buffer[offset_y]
+ [comp_width - dst_blk_x - offset_x - 1];
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ i++;
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ }
+ } else {
+ /* Edge blocks are transposed but not mirrored. */
+ dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
+ for (i = 0; i < DCTSIZE; i++)
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* 270 degree rotation is equivalent to
+ * 1. Horizontal mirroring;
+ * 2. Transposing the image.
+ * These two steps are merged into a single processing routine.
+ */
+{
+ JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_x, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ /* Because of the horizontal mirror step, we can't process partial iMCUs
+ * at the (output) bottom edge properly. They just get transposed and
+ * not mirrored.
+ */
+ MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_height = MCU_rows * compptr->v_samp_factor;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
+ dst_blk_x += compptr->h_samp_factor) {
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
+ (JDIMENSION) compptr->h_samp_factor, FALSE);
+ for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
+ dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
+ if (dst_blk_y < comp_height) {
+ /* Block is within the mirrorable area. */
+ src_ptr = src_buffer[offset_x]
+ [comp_height - dst_blk_y - offset_y - 1];
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < DCTSIZE; j++) {
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ j++;
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ }
+ }
+ } else {
+ /* Edge blocks are transposed but not mirrored. */
+ src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
+ for (i = 0; i < DCTSIZE; i++)
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* 180 degree rotation is equivalent to
+ * 1. Vertical mirroring;
+ * 2. Horizontal mirroring.
+ * These two steps are merged into a single processing routine.
+ */
+{
+ JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JBLOCKROW src_row_ptr, dst_row_ptr;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+ MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_width = MCU_cols * compptr->h_samp_factor;
+ comp_height = MCU_rows * compptr->v_samp_factor;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ if (dst_blk_y < comp_height) {
+ /* Row is within the vertically mirrorable area. */
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci],
+ comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ } else {
+ /* Bottom-edge rows are only mirrored horizontally. */
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+ }
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ if (dst_blk_y < comp_height) {
+ /* Row is within the mirrorable area. */
+ dst_row_ptr = dst_buffer[offset_y];
+ src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
+ /* Process the blocks that can be mirrored both ways. */
+ for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
+ dst_ptr = dst_row_ptr[dst_blk_x];
+ src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
+ for (i = 0; i < DCTSIZE; i += 2) {
+ /* For even row, negate every odd column. */
+ for (j = 0; j < DCTSIZE; j += 2) {
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = - *src_ptr++;
+ }
+ /* For odd row, negate every even column. */
+ for (j = 0; j < DCTSIZE; j += 2) {
+ *dst_ptr++ = - *src_ptr++;
+ *dst_ptr++ = *src_ptr++;
+ }
+ }
+ }
+ /* Any remaining right-edge blocks are only mirrored vertically. */
+ for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
+ dst_ptr = dst_row_ptr[dst_blk_x];
+ src_ptr = src_row_ptr[dst_blk_x];
+ for (i = 0; i < DCTSIZE; i += 2) {
+ for (j = 0; j < DCTSIZE; j++)
+ *dst_ptr++ = *src_ptr++;
+ for (j = 0; j < DCTSIZE; j++)
+ *dst_ptr++ = - *src_ptr++;
+ }
+ }
+ } else {
+ /* Remaining rows are just mirrored horizontally. */
+ dst_row_ptr = dst_buffer[offset_y];
+ src_row_ptr = src_buffer[offset_y];
+ /* Process the blocks that can be mirrored. */
+ for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
+ dst_ptr = dst_row_ptr[dst_blk_x];
+ src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
+ for (i = 0; i < DCTSIZE2; i += 2) {
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = - *src_ptr++;
+ }
+ }
+ /* Any remaining right-edge blocks are only copied. */
+ for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
+ dst_ptr = dst_row_ptr[dst_blk_x];
+ src_ptr = src_row_ptr[dst_blk_x];
+ for (i = 0; i < DCTSIZE2; i++)
+ *dst_ptr++ = *src_ptr++;
+ }
+ }
+ }
+ }
+ }
+}
+
+
+LOCAL(void)
+do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jvirt_barray_ptr *dst_coef_arrays)
+/* Transverse transpose is equivalent to
+ * 1. 180 degree rotation;
+ * 2. Transposition;
+ * or
+ * 1. Horizontal mirroring;
+ * 2. Transposition;
+ * 3. Horizontal mirroring.
+ * These steps are merged into a single processing routine.
+ */
+{
+ JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
+ int ci, i, j, offset_x, offset_y;
+ JBLOCKARRAY src_buffer, dst_buffer;
+ JCOEFPTR src_ptr, dst_ptr;
+ jpeg_component_info *compptr;
+
+ MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
+ MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
+
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ comp_width = MCU_cols * compptr->h_samp_factor;
+ comp_height = MCU_rows * compptr->v_samp_factor;
+ for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
+ dst_blk_y += compptr->v_samp_factor) {
+ dst_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+ for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
+ for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
+ dst_blk_x += compptr->h_samp_factor) {
+ src_buffer = (*srcinfo->mem->access_virt_barray)
+ ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
+ (JDIMENSION) compptr->h_samp_factor, FALSE);
+ for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
+ if (dst_blk_y < comp_height) {
+ src_ptr = src_buffer[offset_x]
+ [comp_height - dst_blk_y - offset_y - 1];
+ if (dst_blk_x < comp_width) {
+ /* Block is within the mirrorable area. */
+ dst_ptr = dst_buffer[offset_y]
+ [comp_width - dst_blk_x - offset_x - 1];
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < DCTSIZE; j++) {
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ j++;
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ }
+ i++;
+ for (j = 0; j < DCTSIZE; j++) {
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ j++;
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ }
+ }
+ } else {
+ /* Right-edge blocks are mirrored in y only */
+ dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < DCTSIZE; j++) {
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ j++;
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ }
+ }
+ }
+ } else {
+ src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
+ if (dst_blk_x < comp_width) {
+ /* Bottom-edge blocks are mirrored in x only */
+ dst_ptr = dst_buffer[offset_y]
+ [comp_width - dst_blk_x - offset_x - 1];
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ i++;
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
+ }
+ } else {
+ /* At lower right corner, just transpose, no mirroring */
+ dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
+ for (i = 0; i < DCTSIZE; i++)
+ for (j = 0; j < DCTSIZE; j++)
+ dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+/* Request any required workspace.
+ *
+ * We allocate the workspace virtual arrays from the source decompression
+ * object, so that all the arrays (both the original data and the workspace)
+ * will be taken into account while making memory management decisions.
+ * Hence, this routine must be called after jpeg_read_header (which reads
+ * the image dimensions) and before jpeg_read_coefficients (which realizes
+ * the source's virtual arrays).
+ */
+
+GLOBAL(void)
+jtransform_request_workspace (j_decompress_ptr srcinfo,
+ jpeg_transform_info *info)
+{
+ jvirt_barray_ptr *coef_arrays = NULL;
+ jpeg_component_info *compptr;
+ int ci;
+
+ if (info->force_grayscale &&
+ srcinfo->jpeg_color_space == JCS_YCbCr &&
+ srcinfo->num_components == 3) {
+ /* We'll only process the first component */
+ info->num_components = 1;
+ } else {
+ /* Process all the components */
+ info->num_components = srcinfo->num_components;
+ }
+
+ switch (info->transform) {
+ case JXFORM_NONE:
+ case JXFORM_FLIP_H:
+ /* Don't need a workspace array */
+ break;
+ case JXFORM_FLIP_V:
+ case JXFORM_ROT_180:
+ /* Need workspace arrays having same dimensions as source image.
+ * Note that we allocate arrays padded out to the next iMCU boundary,
+ * so that transform routines need not worry about missing edge blocks.
+ */
+ coef_arrays = (jvirt_barray_ptr *)
+ (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
+ SIZEOF(jvirt_barray_ptr) * info->num_components);
+ for (ci = 0; ci < info->num_components; ci++) {
+ compptr = srcinfo->comp_info + ci;
+ coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
+ ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) compptr->v_samp_factor);
+ }
+ break;
+ case JXFORM_TRANSPOSE:
+ case JXFORM_TRANSVERSE:
+ case JXFORM_ROT_90:
+ case JXFORM_ROT_270:
+ /* Need workspace arrays having transposed dimensions.
+ * Note that we allocate arrays padded out to the next iMCU boundary,
+ * so that transform routines need not worry about missing edge blocks.
+ */
+ coef_arrays = (jvirt_barray_ptr *)
+ (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
+ SIZEOF(jvirt_barray_ptr) * info->num_components);
+ for (ci = 0; ci < info->num_components; ci++) {
+ compptr = srcinfo->comp_info + ci;
+ coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
+ ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (long) compptr->v_samp_factor),
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+ (long) compptr->h_samp_factor),
+ (JDIMENSION) compptr->h_samp_factor);
+ }
+ break;
+ }
+ info->workspace_coef_arrays = coef_arrays;
+}
+
+
+/* Transpose destination image parameters */
+
+LOCAL(void)
+transpose_critical_parameters (j_compress_ptr dstinfo)
+{
+ int tblno, i, j, ci, itemp;
+ jpeg_component_info *compptr;
+ JQUANT_TBL *qtblptr;
+ JDIMENSION dtemp;
+ UINT16 qtemp;
+
+ /* Transpose basic image dimensions */
+ dtemp = dstinfo->image_width;
+ dstinfo->image_width = dstinfo->image_height;
+ dstinfo->image_height = dtemp;
+
+ /* Transpose sampling factors */
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ compptr = dstinfo->comp_info + ci;
+ itemp = compptr->h_samp_factor;
+ compptr->h_samp_factor = compptr->v_samp_factor;
+ compptr->v_samp_factor = itemp;
+ }
+
+ /* Transpose quantization tables */
+ for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
+ qtblptr = dstinfo->quant_tbl_ptrs[tblno];
+ if (qtblptr != NULL) {
+ for (i = 0; i < DCTSIZE; i++) {
+ for (j = 0; j < i; j++) {
+ qtemp = qtblptr->quantval[i*DCTSIZE+j];
+ qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
+ qtblptr->quantval[j*DCTSIZE+i] = qtemp;
+ }
+ }
+ }
+ }
+}
+
+
+/* Trim off any partial iMCUs on the indicated destination edge */
+
+LOCAL(void)
+trim_right_edge (j_compress_ptr dstinfo)
+{
+ int ci, max_h_samp_factor;
+ JDIMENSION MCU_cols;
+
+ /* We have to compute max_h_samp_factor ourselves,
+ * because it hasn't been set yet in the destination
+ * (and we don't want to use the source's value).
+ */
+ max_h_samp_factor = 1;
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
+ max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
+ }
+ MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
+ if (MCU_cols > 0) /* can't trim to 0 pixels */
+ dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
+}
+
+LOCAL(void)
+trim_bottom_edge (j_compress_ptr dstinfo)
+{
+ int ci, max_v_samp_factor;
+ JDIMENSION MCU_rows;
+
+ /* We have to compute max_v_samp_factor ourselves,
+ * because it hasn't been set yet in the destination
+ * (and we don't want to use the source's value).
+ */
+ max_v_samp_factor = 1;
+ for (ci = 0; ci < dstinfo->num_components; ci++) {
+ int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
+ max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
+ }
+ MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
+ if (MCU_rows > 0) /* can't trim to 0 pixels */
+ dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
+}
+
+
+/* Adjust output image parameters as needed.
+ *
+ * This must be called after jpeg_copy_critical_parameters()
+ * and before jpeg_write_coefficients().
+ *
+ * The return value is the set of virtual coefficient arrays to be written
+ * (either the ones allocated by jtransform_request_workspace, or the
+ * original source data arrays). The caller will need to pass this value
+ * to jpeg_write_coefficients().
+ */
+
+GLOBAL(jvirt_barray_ptr *)
+jtransform_adjust_parameters (j_decompress_ptr srcinfo,
+ j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jpeg_transform_info *info)
+{
+ /* If force-to-grayscale is requested, adjust destination parameters */
+ if (info->force_grayscale) {
+ /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed
+ * properly. Among other things, the target h_samp_factor & v_samp_factor
+ * will get set to 1, which typically won't match the source.
+ * In fact we do this even if the source is already grayscale; that
+ * provides an easy way of coercing a grayscale JPEG with funny sampling
+ * factors to the customary 1,1. (Some decoders fail on other factors.)
+ */
+ if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
+ dstinfo->num_components == 3) ||
+ (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
+ dstinfo->num_components == 1)) {
+ /* We have to preserve the source's quantization table number. */
+ int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
+ jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
+ dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
+ } else {
+ /* Sorry, can't do it */
+ ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
+ }
+ }
+
+ /* Correct the destination's image dimensions etc if necessary */
+ switch (info->transform) {
+ case JXFORM_NONE:
+ /* Nothing to do */
+ break;
+ case JXFORM_FLIP_H:
+ if (info->trim)
+ trim_right_edge(dstinfo);
+ break;
+ case JXFORM_FLIP_V:
+ if (info->trim)
+ trim_bottom_edge(dstinfo);
+ break;
+ case JXFORM_TRANSPOSE:
+ transpose_critical_parameters(dstinfo);
+ /* transpose does NOT have to trim anything */
+ break;
+ case JXFORM_TRANSVERSE:
+ transpose_critical_parameters(dstinfo);
+ if (info->trim) {
+ trim_right_edge(dstinfo);
+ trim_bottom_edge(dstinfo);
+ }
+ break;
+ case JXFORM_ROT_90:
+ transpose_critical_parameters(dstinfo);
+ if (info->trim)
+ trim_right_edge(dstinfo);
+ break;
+ case JXFORM_ROT_180:
+ if (info->trim) {
+ trim_right_edge(dstinfo);
+ trim_bottom_edge(dstinfo);
+ }
+ break;
+ case JXFORM_ROT_270:
+ transpose_critical_parameters(dstinfo);
+ if (info->trim)
+ trim_bottom_edge(dstinfo);
+ break;
+ }
+
+ /* Return the appropriate output data set */
+ if (info->workspace_coef_arrays != NULL)
+ return info->workspace_coef_arrays;
+ return src_coef_arrays;
+}
+
+
+/* Execute the actual transformation, if any.
+ *
+ * This must be called *after* jpeg_write_coefficients, because it depends
+ * on jpeg_write_coefficients to have computed subsidiary values such as
+ * the per-component width and height fields in the destination object.
+ *
+ * Note that some transformations will modify the source data arrays!
+ */
+
+GLOBAL(void)
+jtransform_execute_transformation (j_decompress_ptr srcinfo,
+ j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jpeg_transform_info *info)
+{
+ jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
+
+ switch (info->transform) {
+ case JXFORM_NONE:
+ break;
+ case JXFORM_FLIP_H:
+ do_flip_h(srcinfo, dstinfo, src_coef_arrays);
+ break;
+ case JXFORM_FLIP_V:
+ do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ case JXFORM_TRANSPOSE:
+ do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ case JXFORM_TRANSVERSE:
+ do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ case JXFORM_ROT_90:
+ do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ case JXFORM_ROT_180:
+ do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ case JXFORM_ROT_270:
+ do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
+ break;
+ }
+}
+
+#endif /* TRANSFORMS_SUPPORTED */
+
+
+/* Setup decompression object to save desired markers in memory.
+ * This must be called before jpeg_read_header() to have the desired effect.
+ */
+
+GLOBAL(void)
+jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
+{
+#ifdef SAVE_MARKERS_SUPPORTED
+ int m;
+
+ /* Save comments except under NONE option */
+ if (option != JCOPYOPT_NONE) {
+ jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
+ }
+ /* Save all types of APPn markers iff ALL option */
+ if (option == JCOPYOPT_ALL) {
+ for (m = 0; m < 16; m++)
+ jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
+ }
+#endif /* SAVE_MARKERS_SUPPORTED */
+}
+
+/* Copy markers saved in the given source object to the destination object.
+ * This should be called just after jpeg_start_compress() or
+ * jpeg_write_coefficients().
+ * Note that those routines will have written the SOI, and also the
+ * JFIF APP0 or Adobe APP14 markers if selected.
+ */
+
+GLOBAL(void)
+jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ JCOPY_OPTION option)
+{
+ jpeg_saved_marker_ptr marker;
+
+ /* In the current implementation, we don't actually need to examine the
+ * option flag here; we just copy everything that got saved.
+ * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
+ * if the encoder library already wrote one.
+ */
+ for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
+ if (dstinfo->write_JFIF_header &&
+ marker->marker == JPEG_APP0 &&
+ marker->data_length >= 5 &&
+ GETJOCTET(marker->data[0]) == 0x4A &&
+ GETJOCTET(marker->data[1]) == 0x46 &&
+ GETJOCTET(marker->data[2]) == 0x49 &&
+ GETJOCTET(marker->data[3]) == 0x46 &&
+ GETJOCTET(marker->data[4]) == 0)
+ continue; /* reject duplicate JFIF */
+ if (dstinfo->write_Adobe_marker &&
+ marker->marker == JPEG_APP0+14 &&
+ marker->data_length >= 5 &&
+ GETJOCTET(marker->data[0]) == 0x41 &&
+ GETJOCTET(marker->data[1]) == 0x64 &&
+ GETJOCTET(marker->data[2]) == 0x6F &&
+ GETJOCTET(marker->data[3]) == 0x62 &&
+ GETJOCTET(marker->data[4]) == 0x65)
+ continue; /* reject duplicate Adobe */
+#ifdef NEED_FAR_POINTERS
+ /* We could use jpeg_write_marker if the data weren't FAR... */
+ {
+ unsigned int i;
+ jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
+ for (i = 0; i < marker->data_length; i++)
+ jpeg_write_m_byte(dstinfo, marker->data[i]);
+ }
+#else
+ jpeg_write_marker(dstinfo, marker->marker,
+ marker->data, marker->data_length);
+#endif
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg/transupp.h b/osframework/source/ImageLib/jpeg/transupp.h
new file mode 100644
index 0000000..eb0b055
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/transupp.h
@@ -0,0 +1,135 @@
+/*
+ * transupp.h
+ *
+ * Copyright (C) 1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains declarations for image transformation routines and
+ * other utility code used by the jpegtran sample application. These are
+ * NOT part of the core JPEG library. But we keep these routines separate
+ * from jpegtran.c to ease the task of maintaining jpegtran-like programs
+ * that have other user interfaces.
+ *
+ * NOTE: all the routines declared here have very specific requirements
+ * about when they are to be executed during the reading and writing of the
+ * source and destination files. See the comments in transupp.c, or see
+ * jpegtran.c for an example of correct usage.
+ */
+
+/* If you happen not to want the image transform support, disable it here */
+#ifndef TRANSFORMS_SUPPORTED
+#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
+#endif
+
+/* Short forms of external names for systems with brain-damaged linkers. */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jtransform_request_workspace jTrRequest
+#define jtransform_adjust_parameters jTrAdjust
+#define jtransform_execute_transformation jTrExec
+#define jcopy_markers_setup jCMrkSetup
+#define jcopy_markers_execute jCMrkExec
+#endif /* NEED_SHORT_EXTERNAL_NAMES */
+
+
+/*
+ * Codes for supported types of image transformations.
+ */
+
+typedef enum {
+ JXFORM_NONE, /* no transformation */
+ JXFORM_FLIP_H, /* horizontal flip */
+ JXFORM_FLIP_V, /* vertical flip */
+ JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
+ JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
+ JXFORM_ROT_90, /* 90-degree clockwise rotation */
+ JXFORM_ROT_180, /* 180-degree rotation */
+ JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
+} JXFORM_CODE;
+
+/*
+ * Although rotating and flipping data expressed as DCT coefficients is not
+ * hard, there is an asymmetry in the JPEG format specification for images
+ * whose dimensions aren't multiples of the iMCU size. The right and bottom
+ * image edges are padded out to the next iMCU boundary with junk data; but
+ * no padding is possible at the top and left edges. If we were to flip
+ * the whole image including the pad data, then pad garbage would become
+ * visible at the top and/or left, and real pixels would disappear into the
+ * pad margins --- perhaps permanently, since encoders & decoders may not
+ * bother to preserve DCT blocks that appear to be completely outside the
+ * nominal image area. So, we have to exclude any partial iMCUs from the
+ * basic transformation.
+ *
+ * Transpose is the only transformation that can handle partial iMCUs at the
+ * right and bottom edges completely cleanly. flip_h can flip partial iMCUs
+ * at the bottom, but leaves any partial iMCUs at the right edge untouched.
+ * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
+ * The other transforms are defined as combinations of these basic transforms
+ * and process edge blocks in a way that preserves the equivalence.
+ *
+ * The "trim" option causes untransformable partial iMCUs to be dropped;
+ * this is not strictly lossless, but it usually gives the best-looking
+ * result for odd-size images. Note that when this option is active,
+ * the expected mathematical equivalences between the transforms may not hold.
+ * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
+ * followed by -rot 180 -trim trims both edges.)
+ *
+ * We also offer a "force to grayscale" option, which simply discards the
+ * chrominance channels of a YCbCr image. This is lossless in the sense that
+ * the luminance channel is preserved exactly. It's not the same kind of
+ * thing as the rotate/flip transformations, but it's convenient to handle it
+ * as part of this package, mainly because the transformation routines have to
+ * be aware of the option to know how many components to work on.
+ */
+
+typedef struct {
+ /* Options: set by caller */
+ JXFORM_CODE transform; /* image transform operator */
+ boolean trim; /* if TRUE, trim partial MCUs as needed */
+ boolean force_grayscale; /* if TRUE, convert color image to grayscale */
+
+ /* Internal workspace: caller should not touch these */
+ int num_components; /* # of components in workspace */
+ jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
+} jpeg_transform_info;
+
+
+#if TRANSFORMS_SUPPORTED
+
+/* Request any required workspace */
+EXTERN(void) jtransform_request_workspace
+ JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
+/* Adjust output image parameters */
+EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
+ JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jpeg_transform_info *info));
+/* Execute the actual transformation, if any */
+EXTERN(void) jtransform_execute_transformation
+ JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ jvirt_barray_ptr *src_coef_arrays,
+ jpeg_transform_info *info));
+
+#endif /* TRANSFORMS_SUPPORTED */
+
+
+/*
+ * Support for copying optional markers from source to destination file.
+ */
+
+typedef enum {
+ JCOPYOPT_NONE, /* copy no optional markers */
+ JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
+ JCOPYOPT_ALL /* copy all optional markers */
+} JCOPY_OPTION;
+
+#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
+
+/* Setup decompression object to save desired markers in memory */
+EXTERN(void) jcopy_markers_setup
+ JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
+/* Copy markers saved in the given source object to the destination object */
+EXTERN(void) jcopy_markers_execute
+ JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
+ JCOPY_OPTION option));
diff --git a/osframework/source/ImageLib/jpeg/wrbmp.c b/osframework/source/ImageLib/jpeg/wrbmp.c
new file mode 100644
index 0000000..2b8146e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrbmp.c
@@ -0,0 +1,442 @@
+/*
+ * wrbmp.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write output images in Microsoft "BMP"
+ * format (MS Windows 3.x and OS/2 1.x flavors).
+ * Either 8-bit colormapped or 24-bit full-color format can be written.
+ * No compression is supported.
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume output to
+ * an ordinary stdio stream.
+ *
+ * This code contributed by James Arthur Boucher.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef BMP_SUPPORTED
+
+
+/*
+ * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
+ * This is not yet implemented.
+ */
+
+#if BITS_IN_JSAMPLE != 8
+ Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
+#endif
+
+/*
+ * Since BMP stores scanlines bottom-to-top, we have to invert the image
+ * from JPEG's top-to-bottom order. To do this, we save the outgoing data
+ * in a virtual array during put_pixel_row calls, then actually emit the
+ * BMP file during finish_output. The virtual array contains one JSAMPLE per
+ * pixel if the output is grayscale or colormapped, three if it is full color.
+ */
+
+/* Private version of data destination object */
+
+typedef struct {
+ struct djpeg_dest_struct pub; /* public fields */
+
+ boolean is_os2; /* saves the OS2 format request flag */
+
+ jvirt_sarray_ptr whole_image; /* needed to reverse row order */
+ JDIMENSION data_width; /* JSAMPLEs per row */
+ JDIMENSION row_width; /* physical width of one row in the BMP file */
+ int pad_bytes; /* number of padding bytes needed per row */
+ JDIMENSION cur_output_row; /* next row# to write to virtual array */
+} bmp_dest_struct;
+
+typedef bmp_dest_struct * bmp_dest_ptr;
+
+
+/* Forward declarations */
+LOCAL(void) write_colormap
+ JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest,
+ int map_colors, int map_entry_size));
+
+
+/*
+ * Write some pixel data.
+ * In this module rows_supplied will always be 1.
+ */
+
+METHODDEF(void)
+put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+/* This version is for writing 24-bit pixels */
+{
+ bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
+ JSAMPARRAY image_ptr;
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION col;
+ int pad;
+
+ /* Access next row in virtual array */
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->whole_image,
+ dest->cur_output_row, (JDIMENSION) 1, TRUE);
+ dest->cur_output_row++;
+
+ /* Transfer data. Note destination values must be in BGR order
+ * (even though Microsoft's own documents say the opposite).
+ */
+ inptr = dest->pub.buffer[0];
+ outptr = image_ptr[0];
+ for (col = cinfo->output_width; col > 0; col--) {
+ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
+ outptr[1] = *inptr++;
+ outptr[0] = *inptr++;
+ outptr += 3;
+ }
+
+ /* Zero out the pad bytes. */
+ pad = dest->pad_bytes;
+ while (--pad >= 0)
+ *outptr++ = 0;
+}
+
+METHODDEF(void)
+put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+/* This version is for grayscale OR quantized color output */
+{
+ bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
+ JSAMPARRAY image_ptr;
+ register JSAMPROW inptr, outptr;
+ register JDIMENSION col;
+ int pad;
+
+ /* Access next row in virtual array */
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->whole_image,
+ dest->cur_output_row, (JDIMENSION) 1, TRUE);
+ dest->cur_output_row++;
+
+ /* Transfer data. */
+ inptr = dest->pub.buffer[0];
+ outptr = image_ptr[0];
+ for (col = cinfo->output_width; col > 0; col--) {
+ *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */
+ }
+
+ /* Zero out the pad bytes. */
+ pad = dest->pad_bytes;
+ while (--pad >= 0)
+ *outptr++ = 0;
+}
+
+
+/*
+ * Startup: normally writes the file header.
+ * In this module we may as well postpone everything until finish_output.
+ */
+
+METHODDEF(void)
+start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ /* no work here */
+}
+
+
+/*
+ * Finish up at the end of the file.
+ *
+ * Here is where we really output the BMP file.
+ *
+ * First, routines to write the Windows and OS/2 variants of the file header.
+ */
+
+LOCAL(void)
+write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
+/* Write a Windows-style BMP file header, including colormap if needed */
+{
+ char bmpfileheader[14];
+ char bmpinfoheader[40];
+#define PUT_2B(array,offset,value) \
+ (array[offset] = (char) ((value) & 0xFF), \
+ array[offset+1] = (char) (((value) >> 8) & 0xFF))
+#define PUT_4B(array,offset,value) \
+ (array[offset] = (char) ((value) & 0xFF), \
+ array[offset+1] = (char) (((value) >> 8) & 0xFF), \
+ array[offset+2] = (char) (((value) >> 16) & 0xFF), \
+ array[offset+3] = (char) (((value) >> 24) & 0xFF))
+ INT32 headersize, bfSize;
+ int bits_per_pixel, cmap_entries;
+
+ /* Compute colormap size and total file size */
+ if (cinfo->out_color_space == JCS_RGB) {
+ if (cinfo->quantize_colors) {
+ /* Colormapped RGB */
+ bits_per_pixel = 8;
+ cmap_entries = 256;
+ } else {
+ /* Unquantized, full color RGB */
+ bits_per_pixel = 24;
+ cmap_entries = 0;
+ }
+ } else {
+ /* Grayscale output. We need to fake a 256-entry colormap. */
+ bits_per_pixel = 8;
+ cmap_entries = 256;
+ }
+ /* File size */
+ headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */
+ bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
+
+ /* Set unused fields of header to 0 */
+ MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
+ MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader));
+
+ /* Fill the file header */
+ bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
+ bmpfileheader[1] = 0x4D;
+ PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
+ /* we leave bfReserved1 & bfReserved2 = 0 */
+ PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
+
+ /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */
+ PUT_2B(bmpinfoheader, 0, 40); /* biSize */
+ PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */
+ PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */
+ PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */
+ PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */
+ /* we leave biCompression = 0, for none */
+ /* we leave biSizeImage = 0; this is correct for uncompressed data */
+ if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */
+ PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */
+ PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */
+ }
+ PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
+ /* we leave biClrImportant = 0 */
+
+ if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+
+ if (cmap_entries > 0)
+ write_colormap(cinfo, dest, cmap_entries, 4);
+}
+
+
+LOCAL(void)
+write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
+/* Write an OS2-style BMP file header, including colormap if needed */
+{
+ char bmpfileheader[14];
+ char bmpcoreheader[12];
+ INT32 headersize, bfSize;
+ int bits_per_pixel, cmap_entries;
+
+ /* Compute colormap size and total file size */
+ if (cinfo->out_color_space == JCS_RGB) {
+ if (cinfo->quantize_colors) {
+ /* Colormapped RGB */
+ bits_per_pixel = 8;
+ cmap_entries = 256;
+ } else {
+ /* Unquantized, full color RGB */
+ bits_per_pixel = 24;
+ cmap_entries = 0;
+ }
+ } else {
+ /* Grayscale output. We need to fake a 256-entry colormap. */
+ bits_per_pixel = 8;
+ cmap_entries = 256;
+ }
+ /* File size */
+ headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
+ bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
+
+ /* Set unused fields of header to 0 */
+ MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
+ MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader));
+
+ /* Fill the file header */
+ bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
+ bmpfileheader[1] = 0x4D;
+ PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
+ /* we leave bfReserved1 & bfReserved2 = 0 */
+ PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
+
+ /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
+ PUT_2B(bmpcoreheader, 0, 12); /* bcSize */
+ PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
+ PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
+ PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
+ PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
+
+ if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+
+ if (cmap_entries > 0)
+ write_colormap(cinfo, dest, cmap_entries, 3);
+}
+
+
+/*
+ * Write the colormap.
+ * Windows uses BGR0 map entries; OS/2 uses BGR entries.
+ */
+
+LOCAL(void)
+write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,
+ int map_colors, int map_entry_size)
+{
+ JSAMPARRAY colormap = cinfo->colormap;
+ int num_colors = cinfo->actual_number_of_colors;
+ FILE * outfile = dest->pub.output_file;
+ int i;
+
+ if (colormap != NULL) {
+ if (cinfo->out_color_components == 3) {
+ /* Normal case with RGB colormap */
+ for (i = 0; i < num_colors; i++) {
+ putc(GETJSAMPLE(colormap[2][i]), outfile);
+ putc(GETJSAMPLE(colormap[1][i]), outfile);
+ putc(GETJSAMPLE(colormap[0][i]), outfile);
+ if (map_entry_size == 4)
+ putc(0, outfile);
+ }
+ } else {
+ /* Grayscale colormap (only happens with grayscale quantization) */
+ for (i = 0; i < num_colors; i++) {
+ putc(GETJSAMPLE(colormap[0][i]), outfile);
+ putc(GETJSAMPLE(colormap[0][i]), outfile);
+ putc(GETJSAMPLE(colormap[0][i]), outfile);
+ if (map_entry_size == 4)
+ putc(0, outfile);
+ }
+ }
+ } else {
+ /* If no colormap, must be grayscale data. Generate a linear "map". */
+ for (i = 0; i < 256; i++) {
+ putc(i, outfile);
+ putc(i, outfile);
+ putc(i, outfile);
+ if (map_entry_size == 4)
+ putc(0, outfile);
+ }
+ }
+ /* Pad colormap with zeros to ensure specified number of colormap entries */
+ if (i > map_colors)
+ ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
+ for (; i < map_colors; i++) {
+ putc(0, outfile);
+ putc(0, outfile);
+ putc(0, outfile);
+ if (map_entry_size == 4)
+ putc(0, outfile);
+ }
+}
+
+
+METHODDEF(void)
+finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
+ register FILE * outfile = dest->pub.output_file;
+ JSAMPARRAY image_ptr;
+ register JSAMPROW data_ptr;
+ JDIMENSION row;
+ register JDIMENSION col;
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+
+ /* Write the header and colormap */
+ if (dest->is_os2)
+ write_os2_header(cinfo, dest);
+ else
+ write_bmp_header(cinfo, dest);
+
+ /* Write the file body from our virtual array */
+ for (row = cinfo->output_height; row > 0; row--) {
+ if (progress != NULL) {
+ progress->pub.pass_counter = (long) (cinfo->output_height - row);
+ progress->pub.pass_limit = (long) cinfo->output_height;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+ image_ptr = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE);
+ data_ptr = image_ptr[0];
+ for (col = dest->row_width; col > 0; col--) {
+ putc(GETJSAMPLE(*data_ptr), outfile);
+ data_ptr++;
+ }
+ }
+ if (progress != NULL)
+ progress->completed_extra_passes++;
+
+ /* Make sure we wrote the output file OK */
+ fflush(outfile);
+ if (ferror(outfile))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * The module selection routine for BMP format output.
+ */
+
+GLOBAL(djpeg_dest_ptr)
+jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)
+{
+ bmp_dest_ptr dest;
+ JDIMENSION row_width;
+
+ /* Create module interface object, fill in method pointers */
+ dest = (bmp_dest_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(bmp_dest_struct));
+ dest->pub.start_output = start_output_bmp;
+ dest->pub.finish_output = finish_output_bmp;
+ dest->is_os2 = is_os2;
+
+ if (cinfo->out_color_space == JCS_GRAYSCALE) {
+ dest->pub.put_pixel_rows = put_gray_rows;
+ } else if (cinfo->out_color_space == JCS_RGB) {
+ if (cinfo->quantize_colors)
+ dest->pub.put_pixel_rows = put_gray_rows;
+ else
+ dest->pub.put_pixel_rows = put_pixel_rows;
+ } else {
+ ERREXIT(cinfo, JERR_BMP_COLORSPACE);
+ }
+
+ /* Calculate output image dimensions so we can allocate space */
+ jpeg_calc_output_dimensions(cinfo);
+
+ /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
+ row_width = cinfo->output_width * cinfo->output_components;
+ dest->data_width = row_width;
+ while ((row_width & 3) != 0) row_width++;
+ dest->row_width = row_width;
+ dest->pad_bytes = (int) (row_width - dest->data_width);
+
+ /* Allocate space for inversion array, prepare for write pass */
+ dest->whole_image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ row_width, cinfo->output_height, (JDIMENSION) 1);
+ dest->cur_output_row = 0;
+ if (cinfo->progress != NULL) {
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+ progress->total_extra_passes++; /* count file input as separate pass */
+ }
+
+ /* Create decompressor output buffer. */
+ dest->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1);
+ dest->pub.buffer_height = 1;
+
+ return (djpeg_dest_ptr) dest;
+}
+
+#endif /* BMP_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/wrgif.c b/osframework/source/ImageLib/jpeg/wrgif.c
new file mode 100644
index 0000000..13f953b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrgif.c
@@ -0,0 +1,399 @@
+/*
+ * wrgif.c
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write output images in GIF format.
+ *
+ **************************************************************************
+ * NOTE: to avoid entanglements with Unisys' patent on LZW compression, *
+ * this code has been modified to output "uncompressed GIF" files. *
+ * There is no trace of the LZW algorithm in this file. *
+ **************************************************************************
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume output to
+ * an ordinary stdio stream.
+ */
+
+/*
+ * This code is loosely based on ppmtogif from the PBMPLUS distribution
+ * of Feb. 1991. That file contains the following copyright notice:
+ * Based on GIFENCODE by David Rowley <mgardi@watdscu.waterloo.edu>.
+ * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al.
+ * Copyright (C) 1989 by Jef Poskanzer.
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation. This software is provided "as is" without express or
+ * implied warranty.
+ *
+ * We are also required to state that
+ * "The Graphics Interchange Format(c) is the Copyright property of
+ * CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ * CompuServe Incorporated."
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef GIF_SUPPORTED
+
+
+/* Private version of data destination object */
+
+typedef struct {
+ struct djpeg_dest_struct pub; /* public fields */
+
+ j_decompress_ptr cinfo; /* back link saves passing separate parm */
+
+ /* State for packing variable-width codes into a bitstream */
+ int n_bits; /* current number of bits/code */
+ int maxcode; /* maximum code, given n_bits */
+ INT32 cur_accum; /* holds bits not yet output */
+ int cur_bits; /* # of bits in cur_accum */
+
+ /* State for GIF code assignment */
+ int ClearCode; /* clear code (doesn't change) */
+ int EOFCode; /* EOF code (ditto) */
+ int code_counter; /* counts output symbols */
+
+ /* GIF data packet construction buffer */
+ int bytesinpkt; /* # of bytes in current packet */
+ char packetbuf[256]; /* workspace for accumulating packet */
+
+} gif_dest_struct;
+
+typedef gif_dest_struct * gif_dest_ptr;
+
+/* Largest value that will fit in N bits */
+#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
+
+
+/*
+ * Routines to package finished data bytes into GIF data blocks.
+ * A data block consists of a count byte (1..255) and that many data bytes.
+ */
+
+LOCAL(void)
+flush_packet (gif_dest_ptr dinfo)
+/* flush any accumulated data */
+{
+ if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */
+ dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;
+ if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)
+ != (size_t) dinfo->bytesinpkt)
+ ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
+ dinfo->bytesinpkt = 0;
+ }
+}
+
+
+/* Add a character to current packet; flush to disk if necessary */
+#define CHAR_OUT(dinfo,c) \
+ { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \
+ if ((dinfo)->bytesinpkt >= 255) \
+ flush_packet(dinfo); \
+ }
+
+
+/* Routine to convert variable-width codes into a byte stream */
+
+LOCAL(void)
+output (gif_dest_ptr dinfo, int code)
+/* Emit a code of n_bits bits */
+/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */
+{
+ dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits;
+ dinfo->cur_bits += dinfo->n_bits;
+
+ while (dinfo->cur_bits >= 8) {
+ CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
+ dinfo->cur_accum >>= 8;
+ dinfo->cur_bits -= 8;
+ }
+}
+
+
+/* The pseudo-compression algorithm.
+ *
+ * In this module we simply output each pixel value as a separate symbol;
+ * thus, no compression occurs. In fact, there is expansion of one bit per
+ * pixel, because we use a symbol width one bit wider than the pixel width.
+ *
+ * GIF ordinarily uses variable-width symbols, and the decoder will expect
+ * to ratchet up the symbol width after a fixed number of symbols.
+ * To simplify the logic and keep the expansion penalty down, we emit a
+ * GIF Clear code to reset the decoder just before the width would ratchet up.
+ * Thus, all the symbols in the output file will have the same bit width.
+ * Note that emitting the Clear codes at the right times is a mere matter of
+ * counting output symbols and is in no way dependent on the LZW patent.
+ *
+ * With a small basic pixel width (low color count), Clear codes will be
+ * needed very frequently, causing the file to expand even more. So this
+ * simplistic approach wouldn't work too well on bilevel images, for example.
+ * But for output of JPEG conversions the pixel width will usually be 8 bits
+ * (129 to 256 colors), so the overhead added by Clear symbols is only about
+ * one symbol in every 256.
+ */
+
+LOCAL(void)
+compress_init (gif_dest_ptr dinfo, int i_bits)
+/* Initialize pseudo-compressor */
+{
+ /* init all the state variables */
+ dinfo->n_bits = i_bits;
+ dinfo->maxcode = MAXCODE(dinfo->n_bits);
+ dinfo->ClearCode = (1 << (i_bits - 1));
+ dinfo->EOFCode = dinfo->ClearCode + 1;
+ dinfo->code_counter = dinfo->ClearCode + 2;
+ /* init output buffering vars */
+ dinfo->bytesinpkt = 0;
+ dinfo->cur_accum = 0;
+ dinfo->cur_bits = 0;
+ /* GIF specifies an initial Clear code */
+ output(dinfo, dinfo->ClearCode);
+}
+
+
+LOCAL(void)
+compress_pixel (gif_dest_ptr dinfo, int c)
+/* Accept and "compress" one pixel value.
+ * The given value must be less than n_bits wide.
+ */
+{
+ /* Output the given pixel value as a symbol. */
+ output(dinfo, c);
+ /* Issue Clear codes often enough to keep the reader from ratcheting up
+ * its symbol size.
+ */
+ if (dinfo->code_counter < dinfo->maxcode) {
+ dinfo->code_counter++;
+ } else {
+ output(dinfo, dinfo->ClearCode);
+ dinfo->code_counter = dinfo->ClearCode + 2; /* reset the counter */
+ }
+}
+
+
+LOCAL(void)
+compress_term (gif_dest_ptr dinfo)
+/* Clean up at end */
+{
+ /* Send an EOF code */
+ output(dinfo, dinfo->EOFCode);
+ /* Flush the bit-packing buffer */
+ if (dinfo->cur_bits > 0) {
+ CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
+ }
+ /* Flush the packet buffer */
+ flush_packet(dinfo);
+}
+
+
+/* GIF header construction */
+
+
+LOCAL(void)
+put_word (gif_dest_ptr dinfo, unsigned int w)
+/* Emit a 16-bit word, LSB first */
+{
+ putc(w & 0xFF, dinfo->pub.output_file);
+ putc((w >> 8) & 0xFF, dinfo->pub.output_file);
+}
+
+
+LOCAL(void)
+put_3bytes (gif_dest_ptr dinfo, int val)
+/* Emit 3 copies of same byte value --- handy subr for colormap construction */
+{
+ putc(val, dinfo->pub.output_file);
+ putc(val, dinfo->pub.output_file);
+ putc(val, dinfo->pub.output_file);
+}
+
+
+LOCAL(void)
+emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
+/* Output the GIF file header, including color map */
+/* If colormap==NULL, synthesize a gray-scale colormap */
+{
+ int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
+ int cshift = dinfo->cinfo->data_precision - 8;
+ int i;
+
+ if (num_colors > 256)
+ ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
+ /* Compute bits/pixel and related values */
+ BitsPerPixel = 1;
+ while (num_colors > (1 << BitsPerPixel))
+ BitsPerPixel++;
+ ColorMapSize = 1 << BitsPerPixel;
+ if (BitsPerPixel <= 1)
+ InitCodeSize = 2;
+ else
+ InitCodeSize = BitsPerPixel;
+ /*
+ * Write the GIF header.
+ * Note that we generate a plain GIF87 header for maximum compatibility.
+ */
+ putc('G', dinfo->pub.output_file);
+ putc('I', dinfo->pub.output_file);
+ putc('F', dinfo->pub.output_file);
+ putc('8', dinfo->pub.output_file);
+ putc('7', dinfo->pub.output_file);
+ putc('a', dinfo->pub.output_file);
+ /* Write the Logical Screen Descriptor */
+ put_word(dinfo, (unsigned int) dinfo->cinfo->output_width);
+ put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
+ FlagByte = 0x80; /* Yes, there is a global color table */
+ FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */
+ FlagByte |= (BitsPerPixel-1); /* size of global color table */
+ putc(FlagByte, dinfo->pub.output_file);
+ putc(0, dinfo->pub.output_file); /* Background color index */
+ putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */
+ /* Write the Global Color Map */
+ /* If the color map is more than 8 bits precision, */
+ /* we reduce it to 8 bits by shifting */
+ for (i=0; i < ColorMapSize; i++) {
+ if (i < num_colors) {
+ if (colormap != NULL) {
+ if (dinfo->cinfo->out_color_space == JCS_RGB) {
+ /* Normal case: RGB color map */
+ putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file);
+ putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file);
+ putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file);
+ } else {
+ /* Grayscale "color map": possible if quantizing grayscale image */
+ put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift);
+ }
+ } else {
+ /* Create a gray-scale map of num_colors values, range 0..255 */
+ put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1));
+ }
+ } else {
+ /* fill out the map to a power of 2 */
+ put_3bytes(dinfo, 0);
+ }
+ }
+ /* Write image separator and Image Descriptor */
+ putc(',', dinfo->pub.output_file); /* separator */
+ put_word(dinfo, 0); /* left/top offset */
+ put_word(dinfo, 0);
+ put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */
+ put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
+ /* flag byte: not interlaced, no local color map */
+ putc(0x00, dinfo->pub.output_file);
+ /* Write Initial Code Size byte */
+ putc(InitCodeSize, dinfo->pub.output_file);
+
+ /* Initialize for "compression" of image data */
+ compress_init(dinfo, InitCodeSize+1);
+}
+
+
+/*
+ * Startup: write the file header.
+ */
+
+METHODDEF(void)
+start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ gif_dest_ptr dest = (gif_dest_ptr) dinfo;
+
+ if (cinfo->quantize_colors)
+ emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);
+ else
+ emit_header(dest, 256, (JSAMPARRAY) NULL);
+}
+
+
+/*
+ * Write some pixel data.
+ * In this module rows_supplied will always be 1.
+ */
+
+METHODDEF(void)
+put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ gif_dest_ptr dest = (gif_dest_ptr) dinfo;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+
+ ptr = dest->pub.buffer[0];
+ for (col = cinfo->output_width; col > 0; col--) {
+ compress_pixel(dest, GETJSAMPLE(*ptr++));
+ }
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ gif_dest_ptr dest = (gif_dest_ptr) dinfo;
+
+ /* Flush "compression" mechanism */
+ compress_term(dest);
+ /* Write a zero-length data block to end the series */
+ putc(0, dest->pub.output_file);
+ /* Write the GIF terminator mark */
+ putc(';', dest->pub.output_file);
+ /* Make sure we wrote the output file OK */
+ fflush(dest->pub.output_file);
+ if (ferror(dest->pub.output_file))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * The module selection routine for GIF format output.
+ */
+
+GLOBAL(djpeg_dest_ptr)
+jinit_write_gif (j_decompress_ptr cinfo)
+{
+ gif_dest_ptr dest;
+
+ /* Create module interface object, fill in method pointers */
+ dest = (gif_dest_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(gif_dest_struct));
+ dest->cinfo = cinfo; /* make back link for subroutines */
+ dest->pub.start_output = start_output_gif;
+ dest->pub.put_pixel_rows = put_pixel_rows;
+ dest->pub.finish_output = finish_output_gif;
+
+ if (cinfo->out_color_space != JCS_GRAYSCALE &&
+ cinfo->out_color_space != JCS_RGB)
+ ERREXIT(cinfo, JERR_GIF_COLORSPACE);
+
+ /* Force quantization if color or if > 8 bits input */
+ if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) {
+ /* Force quantization to at most 256 colors */
+ cinfo->quantize_colors = TRUE;
+ if (cinfo->desired_number_of_colors > 256)
+ cinfo->desired_number_of_colors = 256;
+ }
+
+ /* Calculate output image dimensions so we can allocate space */
+ jpeg_calc_output_dimensions(cinfo);
+
+ if (cinfo->output_components != 1) /* safety check: just one component? */
+ ERREXIT(cinfo, JERR_GIF_BUG);
+
+ /* Create decompressor output buffer. */
+ dest->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1);
+ dest->pub.buffer_height = 1;
+
+ return (djpeg_dest_ptr) dest;
+}
+
+#endif /* GIF_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/wrjpgcom.1 b/osframework/source/ImageLib/jpeg/wrjpgcom.1
new file mode 100644
index 0000000..44dad35
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrjpgcom.1
@@ -0,0 +1,103 @@
+.TH WRJPGCOM 1 "15 June 1995"
+.SH NAME
+wrjpgcom \- insert text comments into a JPEG file
+.SH SYNOPSIS
+.B wrjpgcom
+[
+.B \-replace
+]
+[
+.BI \-comment " text"
+]
+[
+.BI \-cfile " name"
+]
+[
+.I filename
+]
+.LP
+.SH DESCRIPTION
+.LP
+.B wrjpgcom
+reads the named JPEG/JFIF file, or the standard input if no file is named,
+and generates a new JPEG/JFIF file on standard output. A comment block is
+added to the file.
+.PP
+The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
+Although the standard doesn't actually define what COM blocks are for, they
+are widely used to hold user-supplied text strings. This lets you add
+annotations, titles, index terms, etc to your JPEG files, and later retrieve
+them as text. COM blocks do not interfere with the image stored in the JPEG
+file. The maximum size of a COM block is 64K, but you can have as many of
+them as you like in one JPEG file.
+.PP
+.B wrjpgcom
+adds a COM block, containing text you provide, to a JPEG file.
+Ordinarily, the COM block is added after any existing COM blocks; but you
+can delete the old COM blocks if you wish.
+.SH OPTIONS
+Switch names may be abbreviated, and are not case sensitive.
+.TP
+.B \-replace
+Delete any existing COM blocks from the file.
+.TP
+.BI \-comment " text"
+Supply text for new COM block on command line.
+.TP
+.BI \-cfile " name"
+Read text for new COM block from named file.
+.PP
+If you have only one line of comment text to add, you can provide it on the
+command line with
+.BR \-comment .
+The comment text must be surrounded with quotes so that it is treated as a
+single argument. Longer comments can be read from a text file.
+.PP
+If you give neither
+.B \-comment
+nor
+.BR \-cfile ,
+then
+.B wrjpgcom
+will read the comment text from standard input. (In this case an input image
+file name MUST be supplied, so that the source JPEG file comes from somewhere
+else.) You can enter multiple lines, up to 64KB worth. Type an end-of-file
+indicator (usually control-D) to terminate the comment text entry.
+.PP
+.B wrjpgcom
+will not add a COM block if the provided comment string is empty. Therefore
+\fB\-replace \-comment ""\fR can be used to delete all COM blocks from a file.
+.SH EXAMPLES
+.LP
+Add a short comment to in.jpg, producing out.jpg:
+.IP
+.B wrjpgcom \-c
+\fI"View of my back yard" in.jpg
+.B >
+.I out.jpg
+.PP
+Attach a long comment previously stored in comment.txt:
+.IP
+.B wrjpgcom
+.I in.jpg
+.B <
+.I comment.txt
+.B >
+.I out.jpg
+.PP
+or equivalently
+.IP
+.B wrjpgcom
+.B -cfile
+.I comment.txt
+.B <
+.I in.jpg
+.B >
+.I out.jpg
+.SH SEE ALSO
+.BR cjpeg (1),
+.BR djpeg (1),
+.BR jpegtran (1),
+.BR rdjpgcom (1)
+.SH AUTHOR
+Independent JPEG Group
diff --git a/osframework/source/ImageLib/jpeg/wrjpgcom.c b/osframework/source/ImageLib/jpeg/wrjpgcom.c
new file mode 100644
index 0000000..7d10ee6
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrjpgcom.c
@@ -0,0 +1,583 @@
+/*
+ * wrjpgcom.c
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a very simple stand-alone application that inserts
+ * user-supplied text as a COM (comment) marker in a JFIF file.
+ * This may be useful as an example of the minimum logic needed to parse
+ * JPEG markers.
+ */
+
+#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
+#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
+
+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
+extern void * malloc ();
+#endif
+#include <ctype.h> /* to declare isupper(), tolower() */
+#ifdef USE_SETMODE
+#include <fcntl.h> /* to declare setmode()'s parameter macros */
+/* If you have setmode() but not <io.h>, just delete this line: */
+#include <io.h> /* to declare setmode() */
+#endif
+
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef __MWERKS__
+#include <SIOUX.h> /* Metrowerks needs this */
+#include <console.h> /* ... and this */
+#endif
+#ifdef THINK_C
+#include <console.h> /* Think declares it here */
+#endif
+#endif
+
+#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
+#define READ_BINARY "r"
+#define WRITE_BINARY "w"
+#else
+#ifdef VMS /* VMS is very nonstandard */
+#define READ_BINARY "rb", "ctx=stm"
+#define WRITE_BINARY "wb", "ctx=stm"
+#else /* standard ANSI-compliant case */
+#define READ_BINARY "rb"
+#define WRITE_BINARY "wb"
+#endif
+#endif
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+#ifdef VMS
+#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
+#else
+#define EXIT_SUCCESS 0
+#endif
+#endif
+
+/* Reduce this value if your malloc() can't allocate blocks up to 64K.
+ * On DOS, compiling in large model is usually a better solution.
+ */
+
+#ifndef MAX_COM_LENGTH
+#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */
+#endif
+
+
+/*
+ * These macros are used to read the input file and write the output file.
+ * To reuse this code in another application, you might need to change these.
+ */
+
+static FILE * infile; /* input JPEG file */
+
+/* Return next input byte, or EOF if no more */
+#define NEXTBYTE() getc(infile)
+
+static FILE * outfile; /* output JPEG file */
+
+/* Emit an output byte */
+#define PUTBYTE(x) putc((x), outfile)
+
+
+/* Error exit handler */
+#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
+
+
+/* Read one byte, testing for EOF */
+static int
+read_1_byte (void)
+{
+ int c;
+
+ c = NEXTBYTE();
+ if (c == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return c;
+}
+
+/* Read 2 bytes, convert to unsigned int */
+/* All 2-byte quantities in JPEG markers are MSB first */
+static unsigned int
+read_2_bytes (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ if (c1 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ c2 = NEXTBYTE();
+ if (c2 == EOF)
+ ERREXIT("Premature EOF in JPEG file");
+ return (((unsigned int) c1) << 8) + ((unsigned int) c2);
+}
+
+
+/* Routines to write data to output file */
+
+static void
+write_1_byte (int c)
+{
+ PUTBYTE(c);
+}
+
+static void
+write_2_bytes (unsigned int val)
+{
+ PUTBYTE((val >> 8) & 0xFF);
+ PUTBYTE(val & 0xFF);
+}
+
+static void
+write_marker (int marker)
+{
+ PUTBYTE(0xFF);
+ PUTBYTE(marker);
+}
+
+static void
+copy_rest_of_file (void)
+{
+ int c;
+
+ while ((c = NEXTBYTE()) != EOF)
+ PUTBYTE(c);
+}
+
+
+/*
+ * JPEG markers consist of one or more 0xFF bytes, followed by a marker
+ * code byte (which is not an FF). Here are the marker codes of interest
+ * in this program. (See jdmarker.c for a more complete list.)
+ */
+
+#define M_SOF0 0xC0 /* Start Of Frame N */
+#define M_SOF1 0xC1 /* N indicates which compression process */
+#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
+#define M_SOF3 0xC3
+#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
+#define M_SOF6 0xC6
+#define M_SOF7 0xC7
+#define M_SOF9 0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
+#define M_EOI 0xD9 /* End Of Image (end of datastream) */
+#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
+#define M_COM 0xFE /* COMment */
+
+
+/*
+ * Find the next JPEG marker and return its marker code.
+ * We expect at least one FF byte, possibly more if the compressor used FFs
+ * to pad the file. (Padding FFs will NOT be replicated in the output file.)
+ * There could also be non-FF garbage between markers. The treatment of such
+ * garbage is unspecified; we choose to skip over it but emit a warning msg.
+ * NB: this routine must not be used after seeing SOS marker, since it will
+ * not deal correctly with FF/00 sequences in the compressed image data...
+ */
+
+static int
+next_marker (void)
+{
+ int c;
+ int discarded_bytes = 0;
+
+ /* Find 0xFF byte; count and skip any non-FFs. */
+ c = read_1_byte();
+ while (c != 0xFF) {
+ discarded_bytes++;
+ c = read_1_byte();
+ }
+ /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
+ * are legal as pad bytes, so don't count them in discarded_bytes.
+ */
+ do {
+ c = read_1_byte();
+ } while (c == 0xFF);
+
+ if (discarded_bytes != 0) {
+ fprintf(stderr, "Warning: garbage data found in JPEG file\n");
+ }
+
+ return c;
+}
+
+
+/*
+ * Read the initial marker, which should be SOI.
+ * For a JFIF file, the first two bytes of the file should be literally
+ * 0xFF M_SOI. To be more general, we could use next_marker, but if the
+ * input file weren't actually JPEG at all, next_marker might read the whole
+ * file and then return a misleading error message...
+ */
+
+static int
+first_marker (void)
+{
+ int c1, c2;
+
+ c1 = NEXTBYTE();
+ c2 = NEXTBYTE();
+ if (c1 != 0xFF || c2 != M_SOI)
+ ERREXIT("Not a JPEG file");
+ return c2;
+}
+
+
+/*
+ * Most types of marker are followed by a variable-length parameter segment.
+ * This routine skips over the parameters for any marker we don't otherwise
+ * want to process.
+ * Note that we MUST skip the parameter segment explicitly in order not to
+ * be fooled by 0xFF bytes that might appear within the parameter segment;
+ * such bytes do NOT introduce new markers.
+ */
+
+static void
+copy_variable (void)
+/* Copy an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ write_2_bytes(length);
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ write_1_byte(read_1_byte());
+ length--;
+ }
+}
+
+static void
+skip_variable (void)
+/* Skip over an unknown or uninteresting variable-length marker */
+{
+ unsigned int length;
+
+ /* Get the marker parameter length count */
+ length = read_2_bytes();
+ /* Length includes itself, so must be at least 2 */
+ if (length < 2)
+ ERREXIT("Erroneous JPEG marker length");
+ length -= 2;
+ /* Skip over the remaining bytes */
+ while (length > 0) {
+ (void) read_1_byte();
+ length--;
+ }
+}
+
+
+/*
+ * Parse the marker stream until SOFn or EOI is seen;
+ * copy data to output, but discard COM markers unless keep_COM is true.
+ */
+
+static int
+scan_JPEG_header (int keep_COM)
+{
+ int marker;
+
+ /* Expect SOI at start of file */
+ if (first_marker() != M_SOI)
+ ERREXIT("Expected SOI marker first");
+ write_marker(M_SOI);
+
+ /* Scan miscellaneous markers until we reach SOFn. */
+ for (;;) {
+ marker = next_marker();
+ switch (marker) {
+ /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
+ * treated as SOFn. C4 in particular is actually DHT.
+ */
+ case M_SOF0: /* Baseline */
+ case M_SOF1: /* Extended sequential, Huffman */
+ case M_SOF2: /* Progressive, Huffman */
+ case M_SOF3: /* Lossless, Huffman */
+ case M_SOF5: /* Differential sequential, Huffman */
+ case M_SOF6: /* Differential progressive, Huffman */
+ case M_SOF7: /* Differential lossless, Huffman */
+ case M_SOF9: /* Extended sequential, arithmetic */
+ case M_SOF10: /* Progressive, arithmetic */
+ case M_SOF11: /* Lossless, arithmetic */
+ case M_SOF13: /* Differential sequential, arithmetic */
+ case M_SOF14: /* Differential progressive, arithmetic */
+ case M_SOF15: /* Differential lossless, arithmetic */
+ return marker;
+
+ case M_SOS: /* should not see compressed data before SOF */
+ ERREXIT("SOS without prior SOFn");
+ break;
+
+ case M_EOI: /* in case it's a tables-only JPEG stream */
+ return marker;
+
+ case M_COM: /* Existing COM: conditionally discard */
+ if (keep_COM) {
+ write_marker(marker);
+ copy_variable();
+ } else {
+ skip_variable();
+ }
+ break;
+
+ default: /* Anything else just gets copied */
+ write_marker(marker);
+ copy_variable(); /* we assume it has a parameter count... */
+ break;
+ }
+ } /* end loop */
+}
+
+
+/* Command line parsing code */
+
+static const char * progname; /* program name for error messages */
+
+
+static void
+usage (void)
+/* complain about bad command line */
+{
+ fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n");
+ fprintf(stderr, "You can add to or replace any existing comment(s).\n");
+
+ fprintf(stderr, "Usage: %s [switches] ", progname);
+#ifdef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "inputfile outputfile\n");
+#else
+ fprintf(stderr, "[inputfile]\n");
+#endif
+
+ fprintf(stderr, "Switches (names may be abbreviated):\n");
+ fprintf(stderr, " -replace Delete any existing comments\n");
+ fprintf(stderr, " -comment \"text\" Insert comment with given text\n");
+ fprintf(stderr, " -cfile name Read comment from named file\n");
+ fprintf(stderr, "Notice that you must put quotes around the comment text\n");
+ fprintf(stderr, "when you use -comment.\n");
+ fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n");
+ fprintf(stderr, "then the comment text is read from standard input.\n");
+ fprintf(stderr, "It can be multiple lines, up to %u characters total.\n",
+ (unsigned int) MAX_COM_LENGTH);
+#ifndef TWO_FILE_COMMANDLINE
+ fprintf(stderr, "You must specify an input JPEG file name when supplying\n");
+ fprintf(stderr, "comment text from standard input.\n");
+#endif
+
+ exit(EXIT_FAILURE);
+}
+
+
+static int
+keymatch (char * arg, const char * keyword, int minchars)
+/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
+/* keyword is the constant keyword (must be lower case already), */
+/* minchars is length of minimum legal abbreviation. */
+{
+ register int ca, ck;
+ register int nmatched = 0;
+
+ while ((ca = *arg++) != '\0') {
+ if ((ck = *keyword++) == '\0')
+ return 0; /* arg longer than keyword, no good */
+ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
+ ca = tolower(ca);
+ if (ca != ck)
+ return 0; /* no good */
+ nmatched++; /* count matched characters */
+ }
+ /* reached end of argument; fail if it's too short for unique abbrev */
+ if (nmatched < minchars)
+ return 0;
+ return 1; /* A-OK */
+}
+
+
+/*
+ * The main program.
+ */
+
+int
+main (int argc, char **argv)
+{
+ int argn;
+ char * arg;
+ int keep_COM = 1;
+ char * comment_arg = NULL;
+ FILE * comment_file = NULL;
+ unsigned int comment_length = 0;
+ int marker;
+
+ /* On Mac, fetch a command line. */
+#ifdef USE_CCOMMAND
+ argc = ccommand(&argv);
+#endif
+
+ progname = argv[0];
+ if (progname == NULL || progname[0] == 0)
+ progname = "wrjpgcom"; /* in case C library doesn't provide it */
+
+ /* Parse switches, if any */
+ for (argn = 1; argn < argc; argn++) {
+ arg = argv[argn];
+ if (arg[0] != '-')
+ break; /* not switch, must be file name */
+ arg++; /* advance over '-' */
+ if (keymatch(arg, "replace", 1)) {
+ keep_COM = 0;
+ } else if (keymatch(arg, "cfile", 2)) {
+ if (++argn >= argc) usage();
+ if ((comment_file = fopen(argv[argn], "r")) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else if (keymatch(arg, "comment", 1)) {
+ if (++argn >= argc) usage();
+ comment_arg = argv[argn];
+ /* If the comment text starts with '"', then we are probably running
+ * under MS-DOG and must parse out the quoted string ourselves. Sigh.
+ */
+ if (comment_arg[0] == '"') {
+ comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
+ if (comment_arg == NULL)
+ ERREXIT("Insufficient memory");
+ strcpy(comment_arg, argv[argn]+1);
+ for (;;) {
+ comment_length = (unsigned int) strlen(comment_arg);
+ if (comment_length > 0 && comment_arg[comment_length-1] == '"') {
+ comment_arg[comment_length-1] = '\0'; /* zap terminating quote */
+ break;
+ }
+ if (++argn >= argc)
+ ERREXIT("Missing ending quote mark");
+ strcat(comment_arg, " ");
+ strcat(comment_arg, argv[argn]);
+ }
+ }
+ comment_length = (unsigned int) strlen(comment_arg);
+ } else
+ usage();
+ }
+
+ /* Cannot use both -comment and -cfile. */
+ if (comment_arg != NULL && comment_file != NULL)
+ usage();
+ /* If there is neither -comment nor -cfile, we will read the comment text
+ * from stdin; in this case there MUST be an input JPEG file name.
+ */
+ if (comment_arg == NULL && comment_file == NULL && argn >= argc)
+ usage();
+
+ /* Open the input file. */
+ if (argn < argc) {
+ if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ /* default input file is stdin */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdin), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdin\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ infile = stdin;
+#endif
+ }
+
+ /* Open the output file. */
+#ifdef TWO_FILE_COMMANDLINE
+ /* Must have explicit output file name */
+ if (argn != argc-2) {
+ fprintf(stderr, "%s: must name one input and one output file\n",
+ progname);
+ usage();
+ }
+ if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]);
+ exit(EXIT_FAILURE);
+ }
+#else
+ /* Unix style: expect zero or one file name */
+ if (argn < argc-1) {
+ fprintf(stderr, "%s: only one input file\n", progname);
+ usage();
+ }
+ /* default output file is stdout */
+#ifdef USE_SETMODE /* need to hack file mode? */
+ setmode(fileno(stdout), O_BINARY);
+#endif
+#ifdef USE_FDOPEN /* need to re-open in binary mode? */
+ if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
+ fprintf(stderr, "%s: can't open stdout\n", progname);
+ exit(EXIT_FAILURE);
+ }
+#else
+ outfile = stdout;
+#endif
+#endif /* TWO_FILE_COMMANDLINE */
+
+ /* Collect comment text from comment_file or stdin, if necessary */
+ if (comment_arg == NULL) {
+ FILE * src_file;
+ int c;
+
+ comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
+ if (comment_arg == NULL)
+ ERREXIT("Insufficient memory");
+ comment_length = 0;
+ src_file = (comment_file != NULL ? comment_file : stdin);
+ while ((c = getc(src_file)) != EOF) {
+ if (comment_length >= (unsigned int) MAX_COM_LENGTH) {
+ fprintf(stderr, "Comment text may not exceed %u bytes\n",
+ (unsigned int) MAX_COM_LENGTH);
+ exit(EXIT_FAILURE);
+ }
+ comment_arg[comment_length++] = (char) c;
+ }
+ if (comment_file != NULL)
+ fclose(comment_file);
+ }
+
+ /* Copy JPEG headers until SOFn marker;
+ * we will insert the new comment marker just before SOFn.
+ * This (a) causes the new comment to appear after, rather than before,
+ * existing comments; and (b) ensures that comments come after any JFIF
+ * or JFXX markers, as required by the JFIF specification.
+ */
+ marker = scan_JPEG_header(keep_COM);
+ /* Insert the new COM marker, but only if nonempty text has been supplied */
+ if (comment_length > 0) {
+ write_marker(M_COM);
+ write_2_bytes(comment_length + 2);
+ while (comment_length > 0) {
+ write_1_byte(*comment_arg++);
+ comment_length--;
+ }
+ }
+ /* Duplicate the remainder of the source file.
+ * Note that any COM markers occuring after SOF will not be touched.
+ */
+ write_marker(marker);
+ copy_rest_of_file();
+
+ /* All done. */
+ exit(EXIT_SUCCESS);
+ return 0; /* suppress no-return-value warnings */
+}
diff --git a/osframework/source/ImageLib/jpeg/wrppm.c b/osframework/source/ImageLib/jpeg/wrppm.c
new file mode 100644
index 0000000..cfd4160
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrppm.c
@@ -0,0 +1,268 @@
+/*
+ * wrppm.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write output images in PPM/PGM format.
+ * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
+ * The PBMPLUS library is NOT required to compile this software
+ * (but it is highly useful as a set of PPM image manipulation programs).
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume output to
+ * an ordinary stdio stream.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef PPM_SUPPORTED
+
+
+/*
+ * For 12-bit JPEG data, we either downscale the values to 8 bits
+ * (to write standard byte-per-sample PPM/PGM files), or output
+ * nonstandard word-per-sample PPM/PGM files. Downscaling is done
+ * if PPM_NORAWWORD is defined (this can be done in the Makefile
+ * or in jconfig.h).
+ * (When the core library supports data precision reduction, a cleaner
+ * implementation will be to ask for that instead.)
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v)
+#define BYTESPERSAMPLE 1
+#define PPM_MAXVAL 255
+#else
+#ifdef PPM_NORAWWORD
+#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8))
+#define BYTESPERSAMPLE 1
+#define PPM_MAXVAL 255
+#else
+/* The word-per-sample format always puts the LSB first. */
+#define PUTPPMSAMPLE(ptr,v) \
+ { register int val_ = v; \
+ *ptr++ = (char) (val_ & 0xFF); \
+ *ptr++ = (char) ((val_ >> 8) & 0xFF); \
+ }
+#define BYTESPERSAMPLE 2
+#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1)
+#endif
+#endif
+
+
+/*
+ * When JSAMPLE is the same size as char, we can just fwrite() the
+ * decompressed data to the PPM or PGM file. On PCs, in order to make this
+ * work the output buffer must be allocated in near data space, because we are
+ * assuming small-data memory model wherein fwrite() can't reach far memory.
+ * If you need to process very wide images on a PC, you might have to compile
+ * in large-memory model, or else replace fwrite() with a putc() loop ---
+ * which will be much slower.
+ */
+
+
+/* Private version of data destination object */
+
+typedef struct {
+ struct djpeg_dest_struct pub; /* public fields */
+
+ /* Usually these two pointers point to the same place: */
+ char *iobuffer; /* fwrite's I/O buffer */
+ JSAMPROW pixrow; /* decompressor output buffer */
+ size_t buffer_width; /* width of I/O buffer */
+ JDIMENSION samples_per_row; /* JSAMPLEs per output row */
+} ppm_dest_struct;
+
+typedef ppm_dest_struct * ppm_dest_ptr;
+
+
+/*
+ * Write some pixel data.
+ * In this module rows_supplied will always be 1.
+ *
+ * put_pixel_rows handles the "normal" 8-bit case where the decompressor
+ * output buffer is physically the same as the fwrite buffer.
+ */
+
+METHODDEF(void)
+put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
+
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+/*
+ * This code is used when we have to copy the data and apply a pixel
+ * format translation. Typically this only happens in 12-bit mode.
+ */
+
+METHODDEF(void)
+copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
+ register char * bufferptr;
+ register JSAMPROW ptr;
+ register JDIMENSION col;
+
+ ptr = dest->pub.buffer[0];
+ bufferptr = dest->iobuffer;
+ for (col = dest->samples_per_row; col > 0; col--) {
+ PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++));
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+/*
+ * Write some pixel data when color quantization is in effect.
+ * We have to demap the color index values to straight data.
+ */
+
+METHODDEF(void)
+put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
+ register char * bufferptr;
+ register int pixval;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register JSAMPROW color_map1 = cinfo->colormap[1];
+ register JSAMPROW color_map2 = cinfo->colormap[2];
+ register JDIMENSION col;
+
+ ptr = dest->pub.buffer[0];
+ bufferptr = dest->iobuffer;
+ for (col = cinfo->output_width; col > 0; col--) {
+ pixval = GETJSAMPLE(*ptr++);
+ PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval]));
+ PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval]));
+ PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval]));
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+METHODDEF(void)
+put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
+ register char * bufferptr;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map = cinfo->colormap[0];
+ register JDIMENSION col;
+
+ ptr = dest->pub.buffer[0];
+ bufferptr = dest->iobuffer;
+ for (col = cinfo->output_width; col > 0; col--) {
+ PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)]));
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+/*
+ * Startup: write the file header.
+ */
+
+METHODDEF(void)
+start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
+
+ /* Emit file header */
+ switch (cinfo->out_color_space) {
+ case JCS_GRAYSCALE:
+ /* emit header for raw PGM format */
+ fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n",
+ (long) cinfo->output_width, (long) cinfo->output_height,
+ PPM_MAXVAL);
+ break;
+ case JCS_RGB:
+ /* emit header for raw PPM format */
+ fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n",
+ (long) cinfo->output_width, (long) cinfo->output_height,
+ PPM_MAXVAL);
+ break;
+ default:
+ ERREXIT(cinfo, JERR_PPM_COLORSPACE);
+ }
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ /* Make sure we wrote the output file OK */
+ fflush(dinfo->output_file);
+ if (ferror(dinfo->output_file))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * The module selection routine for PPM format output.
+ */
+
+GLOBAL(djpeg_dest_ptr)
+jinit_write_ppm (j_decompress_ptr cinfo)
+{
+ ppm_dest_ptr dest;
+
+ /* Create module interface object, fill in method pointers */
+ dest = (ppm_dest_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(ppm_dest_struct));
+ dest->pub.start_output = start_output_ppm;
+ dest->pub.finish_output = finish_output_ppm;
+
+ /* Calculate output image dimensions so we can allocate space */
+ jpeg_calc_output_dimensions(cinfo);
+
+ /* Create physical I/O buffer. Note we make this near on a PC. */
+ dest->samples_per_row = cinfo->output_width * cinfo->out_color_components;
+ dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char));
+ dest->iobuffer = (char *) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);
+
+ if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 ||
+ SIZEOF(JSAMPLE) != SIZEOF(char)) {
+ /* When quantizing, we need an output buffer for colormap indexes
+ * that's separate from the physical I/O buffer. We also need a
+ * separate buffer if pixel format translation must take place.
+ */
+ dest->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->output_width * cinfo->output_components, (JDIMENSION) 1);
+ dest->pub.buffer_height = 1;
+ if (! cinfo->quantize_colors)
+ dest->pub.put_pixel_rows = copy_pixel_rows;
+ else if (cinfo->out_color_space == JCS_GRAYSCALE)
+ dest->pub.put_pixel_rows = put_demapped_gray;
+ else
+ dest->pub.put_pixel_rows = put_demapped_rgb;
+ } else {
+ /* We will fwrite() directly from decompressor output buffer. */
+ /* Synthesize a JSAMPARRAY pointer structure */
+ /* Cast here implies near->far pointer conversion on PCs */
+ dest->pixrow = (JSAMPROW) dest->iobuffer;
+ dest->pub.buffer = & dest->pixrow;
+ dest->pub.buffer_height = 1;
+ dest->pub.put_pixel_rows = put_pixel_rows;
+ }
+
+ return (djpeg_dest_ptr) dest;
+}
+
+#endif /* PPM_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/wrrle.c b/osframework/source/ImageLib/jpeg/wrrle.c
new file mode 100644
index 0000000..7a00c0d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrrle.c
@@ -0,0 +1,305 @@
+/*
+ * wrrle.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write output images in RLE format.
+ * The Utah Raster Toolkit library is required (version 3.1 or later).
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume output to
+ * an ordinary stdio stream.
+ *
+ * Based on code contributed by Mike Lijewski,
+ * with updates from Robert Hutchinson.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef RLE_SUPPORTED
+
+/* rle.h is provided by the Utah Raster Toolkit. */
+
+#include <rle.h>
+
+/*
+ * We assume that JSAMPLE has the same representation as rle_pixel,
+ * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
+ */
+
+#if BITS_IN_JSAMPLE != 8
+ Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
+#endif
+
+
+/*
+ * Since RLE stores scanlines bottom-to-top, we have to invert the image
+ * from JPEG's top-to-bottom order. To do this, we save the outgoing data
+ * in a virtual array during put_pixel_row calls, then actually emit the
+ * RLE file during finish_output.
+ */
+
+
+/*
+ * For now, if we emit an RLE color map then it is always 256 entries long,
+ * though not all of the entries need be used.
+ */
+
+#define CMAPBITS 8
+#define CMAPLENGTH (1<<(CMAPBITS))
+
+typedef struct {
+ struct djpeg_dest_struct pub; /* public fields */
+
+ jvirt_sarray_ptr image; /* virtual array to store the output image */
+ rle_map *colormap; /* RLE-style color map, or NULL if none */
+ rle_pixel **rle_row; /* To pass rows to rle_putrow() */
+
+} rle_dest_struct;
+
+typedef rle_dest_struct * rle_dest_ptr;
+
+/* Forward declarations */
+METHODDEF(void) rle_put_pixel_rows
+ JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied));
+
+
+/*
+ * Write the file header.
+ *
+ * In this module it's easier to wait till finish_output to write anything.
+ */
+
+METHODDEF(void)
+start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ rle_dest_ptr dest = (rle_dest_ptr) dinfo;
+ size_t cmapsize;
+ int i, ci;
+#ifdef PROGRESS_REPORT
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+#endif
+
+ /*
+ * Make sure the image can be stored in RLE format.
+ *
+ * - RLE stores image dimensions as *signed* 16 bit integers. JPEG
+ * uses unsigned, so we have to check the width.
+ *
+ * - Colorspace is expected to be grayscale or RGB.
+ *
+ * - The number of channels (components) is expected to be 1 (grayscale/
+ * pseudocolor) or 3 (truecolor/directcolor).
+ * (could be 2 or 4 if using an alpha channel, but we aren't)
+ */
+
+ if (cinfo->output_width > 32767 || cinfo->output_height > 32767)
+ ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width,
+ cinfo->output_height);
+
+ if (cinfo->out_color_space != JCS_GRAYSCALE &&
+ cinfo->out_color_space != JCS_RGB)
+ ERREXIT(cinfo, JERR_RLE_COLORSPACE);
+
+ if (cinfo->output_components != 1 && cinfo->output_components != 3)
+ ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components);
+
+ /* Convert colormap, if any, to RLE format. */
+
+ dest->colormap = NULL;
+
+ if (cinfo->quantize_colors) {
+ /* Allocate storage for RLE-style cmap, zero any extra entries */
+ cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map);
+ dest->colormap = (rle_map *) (*cinfo->mem->alloc_small)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize);
+ MEMZERO(dest->colormap, cmapsize);
+
+ /* Save away data in RLE format --- note 8-bit left shift! */
+ /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */
+ for (ci = 0; ci < cinfo->out_color_components; ci++) {
+ for (i = 0; i < cinfo->actual_number_of_colors; i++) {
+ dest->colormap[ci * CMAPLENGTH + i] =
+ GETJSAMPLE(cinfo->colormap[ci][i]) << 8;
+ }
+ }
+ }
+
+ /* Set the output buffer to the first row */
+ dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE);
+ dest->pub.buffer_height = 1;
+
+ dest->pub.put_pixel_rows = rle_put_pixel_rows;
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->total_extra_passes++; /* count file writing as separate pass */
+ }
+#endif
+}
+
+
+/*
+ * Write some pixel data.
+ *
+ * This routine just saves the data away in a virtual array.
+ */
+
+METHODDEF(void)
+rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ rle_dest_ptr dest = (rle_dest_ptr) dinfo;
+
+ if (cinfo->output_scanline < cinfo->output_height) {
+ dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->image,
+ cinfo->output_scanline, (JDIMENSION) 1, TRUE);
+ }
+}
+
+/*
+ * Finish up at the end of the file.
+ *
+ * Here is where we really output the RLE file.
+ */
+
+METHODDEF(void)
+finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ rle_dest_ptr dest = (rle_dest_ptr) dinfo;
+ rle_hdr header; /* Output file information */
+ rle_pixel **rle_row, *red, *green, *blue;
+ JSAMPROW output_row;
+ char cmapcomment[80];
+ int row, col;
+ int ci;
+#ifdef PROGRESS_REPORT
+ cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
+#endif
+
+ /* Initialize the header info */
+ header = *rle_hdr_init(NULL);
+ header.rle_file = dest->pub.output_file;
+ header.xmin = 0;
+ header.xmax = cinfo->output_width - 1;
+ header.ymin = 0;
+ header.ymax = cinfo->output_height - 1;
+ header.alpha = 0;
+ header.ncolors = cinfo->output_components;
+ for (ci = 0; ci < cinfo->output_components; ci++) {
+ RLE_SET_BIT(header, ci);
+ }
+ if (cinfo->quantize_colors) {
+ header.ncmap = cinfo->out_color_components;
+ header.cmaplen = CMAPBITS;
+ header.cmap = dest->colormap;
+ /* Add a comment to the output image with the true colormap length. */
+ sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors);
+ rle_putcom(cmapcomment, &header);
+ }
+
+ /* Emit the RLE header and color map (if any) */
+ rle_put_setup(&header);
+
+ /* Now output the RLE data from our virtual array.
+ * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
+ * and (b) we are not on a machine where FAR pointers differ from regular.
+ */
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_limit = cinfo->output_height;
+ progress->pub.pass_counter = 0;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+
+ if (cinfo->output_components == 1) {
+ for (row = cinfo->output_height-1; row >= 0; row--) {
+ rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->image,
+ (JDIMENSION) row, (JDIMENSION) 1, FALSE);
+ rle_putrow(rle_row, (int) cinfo->output_width, &header);
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_counter++;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+ }
+ } else {
+ for (row = cinfo->output_height-1; row >= 0; row--) {
+ rle_row = (rle_pixel **) dest->rle_row;
+ output_row = * (*cinfo->mem->access_virt_sarray)
+ ((j_common_ptr) cinfo, dest->image,
+ (JDIMENSION) row, (JDIMENSION) 1, FALSE);
+ red = rle_row[0];
+ green = rle_row[1];
+ blue = rle_row[2];
+ for (col = cinfo->output_width; col > 0; col--) {
+ *red++ = GETJSAMPLE(*output_row++);
+ *green++ = GETJSAMPLE(*output_row++);
+ *blue++ = GETJSAMPLE(*output_row++);
+ }
+ rle_putrow(rle_row, (int) cinfo->output_width, &header);
+#ifdef PROGRESS_REPORT
+ if (progress != NULL) {
+ progress->pub.pass_counter++;
+ (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
+ }
+#endif
+ }
+ }
+
+#ifdef PROGRESS_REPORT
+ if (progress != NULL)
+ progress->completed_extra_passes++;
+#endif
+
+ /* Emit file trailer */
+ rle_puteof(&header);
+ fflush(dest->pub.output_file);
+ if (ferror(dest->pub.output_file))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * The module selection routine for RLE format output.
+ */
+
+GLOBAL(djpeg_dest_ptr)
+jinit_write_rle (j_decompress_ptr cinfo)
+{
+ rle_dest_ptr dest;
+
+ /* Create module interface object, fill in method pointers */
+ dest = (rle_dest_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(rle_dest_struct));
+ dest->pub.start_output = start_output_rle;
+ dest->pub.finish_output = finish_output_rle;
+
+ /* Calculate output image dimensions so we can allocate space */
+ jpeg_calc_output_dimensions(cinfo);
+
+ /* Allocate a work array for output to the RLE library. */
+ dest->rle_row = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ cinfo->output_width, (JDIMENSION) cinfo->output_components);
+
+ /* Allocate a virtual array to hold the image. */
+ dest->image = (*cinfo->mem->request_virt_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
+ (JDIMENSION) (cinfo->output_width * cinfo->output_components),
+ cinfo->output_height, (JDIMENSION) 1);
+
+ return (djpeg_dest_ptr) dest;
+}
+
+#endif /* RLE_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg/wrtarga.c b/osframework/source/ImageLib/jpeg/wrtarga.c
new file mode 100644
index 0000000..6566273
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg/wrtarga.c
@@ -0,0 +1,253 @@
+/*
+ * wrtarga.c
+ *
+ * Copyright (C) 1991-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains routines to write output images in Targa format.
+ *
+ * These routines may need modification for non-Unix environments or
+ * specialized applications. As they stand, they assume output to
+ * an ordinary stdio stream.
+ *
+ * Based on code contributed by Lee Daniel Crocker.
+ */
+
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+
+#ifdef TARGA_SUPPORTED
+
+
+/*
+ * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
+ * This is not yet implemented.
+ */
+
+#if BITS_IN_JSAMPLE != 8
+ Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
+#endif
+
+/*
+ * The output buffer needs to be writable by fwrite(). On PCs, we must
+ * allocate the buffer in near data space, because we are assuming small-data
+ * memory model, wherein fwrite() can't reach far memory. If you need to
+ * process very wide images on a PC, you might have to compile in large-memory
+ * model, or else replace fwrite() with a putc() loop --- which will be much
+ * slower.
+ */
+
+
+/* Private version of data destination object */
+
+typedef struct {
+ struct djpeg_dest_struct pub; /* public fields */
+
+ char *iobuffer; /* physical I/O buffer */
+ JDIMENSION buffer_width; /* width of one row */
+} tga_dest_struct;
+
+typedef tga_dest_struct * tga_dest_ptr;
+
+
+LOCAL(void)
+write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors)
+/* Create and write a Targa header */
+{
+ char targaheader[18];
+
+ /* Set unused fields of header to 0 */
+ MEMZERO(targaheader, SIZEOF(targaheader));
+
+ if (num_colors > 0) {
+ targaheader[1] = 1; /* color map type 1 */
+ targaheader[5] = (char) (num_colors & 0xFF);
+ targaheader[6] = (char) (num_colors >> 8);
+ targaheader[7] = 24; /* 24 bits per cmap entry */
+ }
+
+ targaheader[12] = (char) (cinfo->output_width & 0xFF);
+ targaheader[13] = (char) (cinfo->output_width >> 8);
+ targaheader[14] = (char) (cinfo->output_height & 0xFF);
+ targaheader[15] = (char) (cinfo->output_height >> 8);
+ targaheader[17] = 0x20; /* Top-down, non-interlaced */
+
+ if (cinfo->out_color_space == JCS_GRAYSCALE) {
+ targaheader[2] = 3; /* image type = uncompressed gray-scale */
+ targaheader[16] = 8; /* bits per pixel */
+ } else { /* must be RGB */
+ if (num_colors > 0) {
+ targaheader[2] = 1; /* image type = colormapped RGB */
+ targaheader[16] = 8;
+ } else {
+ targaheader[2] = 2; /* image type = uncompressed RGB */
+ targaheader[16] = 24;
+ }
+ }
+
+ if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * Write some pixel data.
+ * In this module rows_supplied will always be 1.
+ */
+
+METHODDEF(void)
+put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+/* used for unquantized full-color output */
+{
+ tga_dest_ptr dest = (tga_dest_ptr) dinfo;
+ register JSAMPROW inptr;
+ register char * outptr;
+ register JDIMENSION col;
+
+ inptr = dest->pub.buffer[0];
+ outptr = dest->iobuffer;
+ for (col = cinfo->output_width; col > 0; col--) {
+ outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */
+ outptr[1] = (char) GETJSAMPLE(inptr[1]);
+ outptr[2] = (char) GETJSAMPLE(inptr[0]);
+ inptr += 3, outptr += 3;
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+METHODDEF(void)
+put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+/* used for grayscale OR quantized color output */
+{
+ tga_dest_ptr dest = (tga_dest_ptr) dinfo;
+ register JSAMPROW inptr;
+ register char * outptr;
+ register JDIMENSION col;
+
+ inptr = dest->pub.buffer[0];
+ outptr = dest->iobuffer;
+ for (col = cinfo->output_width; col > 0; col--) {
+ *outptr++ = (char) GETJSAMPLE(*inptr++);
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+/*
+ * Write some demapped pixel data when color quantization is in effect.
+ * For Targa, this is only applied to grayscale data.
+ */
+
+METHODDEF(void)
+put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
+ JDIMENSION rows_supplied)
+{
+ tga_dest_ptr dest = (tga_dest_ptr) dinfo;
+ register JSAMPROW inptr;
+ register char * outptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register JDIMENSION col;
+
+ inptr = dest->pub.buffer[0];
+ outptr = dest->iobuffer;
+ for (col = cinfo->output_width; col > 0; col--) {
+ *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]);
+ }
+ (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+}
+
+
+/*
+ * Startup: write the file header.
+ */
+
+METHODDEF(void)
+start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ tga_dest_ptr dest = (tga_dest_ptr) dinfo;
+ int num_colors, i;
+ FILE *outfile;
+
+ if (cinfo->out_color_space == JCS_GRAYSCALE) {
+ /* Targa doesn't have a mapped grayscale format, so we will */
+ /* demap quantized gray output. Never emit a colormap. */
+ write_header(cinfo, dinfo, 0);
+ if (cinfo->quantize_colors)
+ dest->pub.put_pixel_rows = put_demapped_gray;
+ else
+ dest->pub.put_pixel_rows = put_gray_rows;
+ } else if (cinfo->out_color_space == JCS_RGB) {
+ if (cinfo->quantize_colors) {
+ /* We only support 8-bit colormap indexes, so only 256 colors */
+ num_colors = cinfo->actual_number_of_colors;
+ if (num_colors > 256)
+ ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors);
+ write_header(cinfo, dinfo, num_colors);
+ /* Write the colormap. Note Targa uses BGR byte order */
+ outfile = dest->pub.output_file;
+ for (i = 0; i < num_colors; i++) {
+ putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile);
+ putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile);
+ putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile);
+ }
+ dest->pub.put_pixel_rows = put_gray_rows;
+ } else {
+ write_header(cinfo, dinfo, 0);
+ dest->pub.put_pixel_rows = put_pixel_rows;
+ }
+ } else {
+ ERREXIT(cinfo, JERR_TGA_COLORSPACE);
+ }
+}
+
+
+/*
+ * Finish up at the end of the file.
+ */
+
+METHODDEF(void)
+finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
+{
+ /* Make sure we wrote the output file OK */
+ fflush(dinfo->output_file);
+ if (ferror(dinfo->output_file))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+}
+
+
+/*
+ * The module selection routine for Targa format output.
+ */
+
+GLOBAL(djpeg_dest_ptr)
+jinit_write_targa (j_decompress_ptr cinfo)
+{
+ tga_dest_ptr dest;
+
+ /* Create module interface object, fill in method pointers */
+ dest = (tga_dest_ptr)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ SIZEOF(tga_dest_struct));
+ dest->pub.start_output = start_output_tga;
+ dest->pub.finish_output = finish_output_tga;
+
+ /* Calculate output image dimensions so we can allocate space */
+ jpeg_calc_output_dimensions(cinfo);
+
+ /* Create I/O buffer. Note we make this near on a PC. */
+ dest->buffer_width = cinfo->output_width * cinfo->output_components;
+ dest->iobuffer = (char *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ (size_t) (dest->buffer_width * SIZEOF(char)));
+
+ /* Create decompressor output buffer. */
+ dest->pub.buffer = (*cinfo->mem->alloc_sarray)
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1);
+ dest->pub.buffer_height = 1;
+
+ return (djpeg_dest_ptr) dest;
+}
+
+#endif /* TARGA_SUPPORTED */
diff --git a/osframework/source/ImageLib/jpeg2000/COPYRIGHT b/osframework/source/ImageLib/jpeg2000/COPYRIGHT
new file mode 100644
index 0000000..ab71156
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/COPYRIGHT
@@ -0,0 +1,2 @@
+The copyright information for the JasPer software accompanies the software
+license, and can be found in the file named "LICENSE".
diff --git a/osframework/source/ImageLib/jpeg2000/INSTALL b/osframework/source/ImageLib/jpeg2000/INSTALL
new file mode 100644
index 0000000..5f332bc
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/INSTALL
@@ -0,0 +1,3 @@
+Detailed instructions on how to build and install the JasPer software
+can be found in the JasPer Software Reference Manual which is located
+in the doc directory. (See the section titled "Building the Software".)
diff --git a/osframework/source/ImageLib/jpeg2000/LICENSE b/osframework/source/ImageLib/jpeg2000/LICENSE
new file mode 100644
index 0000000..41c49cf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/LICENSE
@@ -0,0 +1,104 @@
+JasPer Software License
+
+Copyright (c) 1999-2000, Image Power, Inc. and the University of British
+Columbia, Canada.
+Copyright (c) 2001-2003 Michael David Adams.
+All rights reserved.
+
+IMAGE POWER JPEG-2000 PUBLIC LICENSE
+************************************
+
+GRANT:
+
+Permission is hereby granted, free of charge, to any person (the "User")
+obtaining a copy of this software and associated documentation, to deal
+in the JasPer Software without restriction, including without limitation
+the right to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the JasPer Software (in source and binary forms),
+and to permit persons to whom the JasPer Software is furnished to do so,
+provided further that the License Conditions below are met.
+
+License Conditions
+******************
+
+A. Redistributions of source code must retain the above copyright notice,
+and this list of conditions, and the following disclaimer.
+
+B. Redistributions in binary form must reproduce the above copyright
+notice, and this list of conditions, and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+C. Neither the name of Image Power, Inc. nor any other contributor
+(including, but not limited to, the University of British Columbia and
+Michael David Adams) may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+D. User agrees that it shall not commence any action against Image Power,
+Inc., the University of British Columbia, Michael David Adams, or any
+other contributors (collectively "Licensors") for infringement of any
+intellectual property rights ("IPR") held by the User in respect of any
+technology that User owns or has a right to license or sublicense and
+which is an element required in order to claim compliance with ISO/IEC
+15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+rights worldwide arising under statutory or common law, and whether
+or not perfected, including, without limitation, all (i) patents and
+patent applications owned or licensable by User; (ii) rights associated
+with works of authorship including copyrights, copyright applications,
+copyright registrations, mask work rights, mask work applications,
+mask work registrations; (iii) rights relating to the protection of
+trade secrets and confidential information; (iv) any right analogous
+to those set forth in subsections (i), (ii), or (iii) and any other
+proprietary rights relating to intangible property (other than trademark,
+trade dress, or service mark rights); and (v) divisions, continuations,
+renewals, reissues and extensions of the foregoing (as and to the extent
+applicable) now existing, hereafter filed, issued or acquired.
+
+E. If User commences an infringement action against any Licensor(s) then
+such Licensor(s) shall have the right to terminate User's license and
+all sublicenses that have been granted hereunder by User to other parties.
+
+F. This software is for use only in hardware or software products that
+are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+or right to this Software is granted for products that do not comply
+with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+from the ISO.
+
+THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+NOTICE SPECIFIED IN THIS SECTION.
diff --git a/osframework/source/ImageLib/jpeg2000/NEWS b/osframework/source/ImageLib/jpeg2000/NEWS
new file mode 100644
index 0000000..2abadee
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/NEWS
@@ -0,0 +1,67 @@
+Hi, Folks.
+
+I am pleased to announce the availability of JasPer version 1.700.x.
+Numerous changes have been made to the software since the 1.600.0 release.
+A few of the highlights are listed below. This list is in no particular
+order, and is not intended to be exhaustive.
+
+1) A preliminary attempt at a color management subsystem has been added
+to JasPer. This will allow for more accurate color reproduction when
+transcoding or rendering image data. Some of the underlying color
+management functionality makes use of the ICC color profile file
+format. Consequently, support for handling this file format is now
+present in JasPer. This support intelligently handles shared tags via
+reference counting. (Thanks to Scott Houchin <scott.houchin@kodak.com>
+for providing some ICC profiles for use in JasPer, and for answering a
+number of questions about the ICC color profile file format.) Some sample
+ICC profiles have been included with the JasPer distribution.
+
+2) Previously, the configure process did not generate a configuration
+header file. Instead, all of the configure-related preprocessor defines
+were hardwired into the makefiles. Unfortunately, this approach has
+the strong potential to cause problems when non-JasPer application
+programs are built against the JasPer library (since such application
+programs will often fail to specify the correct configure-related
+preprocessor defines for JasPer). In order to resolve this problem, the
+configure-related preprocessor defines are now saved in a configuration
+header file (which is always included by application programs).
+
+3) Temporary files created with the jas_stream_tmpfile function
+were not correctly removed upon file close under Microsoft Windows.
+Apparently, the Microsoft Windows operating system will not allow a file
+to be unlinked when it is open. The problem has been solved by deferring
+the unlink operation until the time of file close. (Thank you to Rick
+Bryan <rlbryan@pobox.com> for pointing out this bug and providing a
+suggested fix.)
+
+4) An option has been added to the JPEG encoder to allow a quality factor
+to be specified. (Thanks to Jason Fritts <jefritts@cse.wustl.edu>
+for providing a suggested patch which I adopted with a few minor
+modifications.)
+
+5) A new make target has been added for RPM building. This functionality
+is experimental, and not officially supported. Your mileage may vary.
+Void where prohibited by law. Batteries not included. :) (Thanks
+to Alexander Karaivanov <adk@medical-insight.com> for providing the
+necessary changes.)
+
+6) The code now compiles with many fewer warnings on most platforms.
+Previously, some unresolved type issues and missing type casts caused
+numerous warnings to be generated by most compilers. Also, some
+prototypes were missing or broken. The majority of these problems have
+been fixed (either by using consistent types or adding type casts).
+The source files jpc_enc.c and jpc_t1enc.c still need to be fixed,
+however. Hopefully, this will happen in the next release.
+
+The new JasPer release is available from the JasPer Project Home Page
+(i.e., http://www.ece.uvic.ca/~mdadams/jasper) and the JPEG web site
+(i.e., http://www.jpeg.org/software).
+
+Regards,
+Michael
+
+---
+Michael Adams, Assistant Professor
+Dept. of Elec. and Comp. Engineering, University of Victoria
+P.O. Box 3055 STN CSC, Victoria, BC, V8W 3P6, CANADA
+E-mail: mdadams@ece.uvic.ca, Web: www.ece.uvic.ca/~mdadams
diff --git a/osframework/source/ImageLib/jpeg2000/README b/osframework/source/ImageLib/jpeg2000/README
new file mode 100644
index 0000000..400eec1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/README
@@ -0,0 +1,21 @@
+JasPer Readme
+*************
+
+This is the source code distribution for JasPer. JasPer is a collection
+of software (i.e., a library and application programs) for the coding
+and manipulation of images. This software can handle image data in a
+variety of formats. One such format supported by JasPer is the JPEG-2000
+format defined in ISO/IEC 15444-1.
+
+The complete licensing terms for the JasPer software can be found in
+the file named "LICENSE" in the top level directory of this software
+distribution. Any use of this software contrary to the terms of the
+license is strictly prohibited. The changes made to the software
+since the last release are described in the file "NEWS". Detailed
+documentation on the JasPer software can be found in the JasPer Software
+Reference Manual. This manual is located in the "doc" directory, and
+includes useful information such as: 1) how to build, install, and use
+the software, 2) how to submit report bugs, and 3) where to find
+additional information about the software.
+
+Enjoy! :)
diff --git a/osframework/source/ImageLib/jpeg2000/jas_cm.c b/osframework/source/ImageLib/jpeg2000/jas_cm.c
new file mode 100644
index 0000000..ccab2c6
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_cm.c
@@ -0,0 +1,1294 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Color Management
+ *
+ * $Id: jas_cm.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#include "jas_config.h"
+#include <math.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "jas_cm.h"
+#include "jas_icc.h"
+#include "jas_init.h"
+#include "jas_stream.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+static jas_cmprof_t *jas_cmprof_create(void);
+static void jas_cmshapmatlut_cleanup(jas_cmshapmatlut_t *);
+static jas_cmreal_t jas_cmshapmatlut_lookup(jas_cmshapmatlut_t *lut, jas_cmreal_t x);
+
+static void jas_cmpxform_destroy(jas_cmpxform_t *pxform);
+static jas_cmpxform_t *jas_cmpxform_copy(jas_cmpxform_t *pxform);
+
+static void jas_cmshapmat_destroy(jas_cmpxform_t *pxform);
+static int jas_cmshapmat_apply(jas_cmpxform_t *pxform, jas_cmreal_t *in,
+ jas_cmreal_t *out, int cnt);
+
+static int jas_cmputint(long **bufptr, int sgnd, int prec, long val);
+static int jas_cmgetint(long **bufptr, int sgnd, int prec, long *val);
+static int jas_cmpxformseq_append(jas_cmpxformseq_t *pxformseq,
+ jas_cmpxformseq_t *othpxformseq);
+static int jas_cmpxformseq_appendcnvt(jas_cmpxformseq_t *pxformseq,
+ int, int);
+static int jas_cmpxformseq_resize(jas_cmpxformseq_t *pxformseq, int n);
+
+static int mono(jas_iccprof_t *prof, int op, jas_cmpxformseq_t **pxformseq);
+static int triclr(jas_iccprof_t *prof, int op, jas_cmpxformseq_t **retpxformseq);
+
+static void jas_cmpxformseq_destroy(jas_cmpxformseq_t *pxformseq);
+static int jas_cmpxformseq_delete(jas_cmpxformseq_t *pxformseq, int i);
+static jas_cmpxformseq_t *jas_cmpxformseq_create(void);
+static jas_cmpxformseq_t *jas_cmpxformseq_copy(jas_cmpxformseq_t *pxformseq);
+static int jas_cmshapmat_invmat(jas_cmreal_t out[3][4], jas_cmreal_t in[3][4]);
+static int jas_cmpxformseq_insertpxform(jas_cmpxformseq_t *pxformseq,
+ int i, jas_cmpxform_t *pxform);
+
+#define SEQFWD(intent) (intent)
+#define SEQREV(intent) (4 + (intent))
+#define SEQSIM(intent) (8 + (intent))
+#define SEQGAM 12
+
+#define fwdpxformseq(prof, intent) \
+ (((prof)->pxformseqs[SEQFWD(intent)]) ? \
+ ((prof)->pxformseqs[SEQFWD(intent)]) : \
+ ((prof)->pxformseqs[SEQFWD(0)]))
+
+#define revpxformseq(prof, intent) \
+ (((prof)->pxformseqs[SEQREV(intent)]) ? \
+ ((prof)->pxformseqs[SEQREV(intent)]) : \
+ ((prof)->pxformseqs[SEQREV(0)]))
+
+#define simpxformseq(prof, intent) \
+ (((prof)->pxformseqs[SEQSIM(intent)]) ? \
+ ((prof)->pxformseqs[SEQSIM(intent)]) : \
+ ((prof)->pxformseqs[SEQSIM(0)]))
+
+#define gampxformseq(prof) ((prof)->pxformseqs[SEQGAM])
+
+static int icctoclrspc(int iccclrspc, int refflag);
+static jas_cmpxform_t *jas_cmpxform_create0(void);
+static jas_cmpxform_t *jas_cmpxform_createshapmat(void);
+static void jas_cmshapmatlut_init(jas_cmshapmatlut_t *lut);
+static int jas_cmshapmatlut_set(jas_cmshapmatlut_t *lut, jas_icccurv_t *curv);
+
+static jas_cmpxformops_t shapmat_ops = {jas_cmshapmat_destroy, jas_cmshapmat_apply, 0};
+static jas_cmprof_t *jas_cmprof_createsycc(void);
+
+/******************************************************************************\
+* Color profile class.
+\******************************************************************************/
+
+jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc)
+{
+ jas_iccprof_t *iccprof;
+ jas_cmprof_t *prof;
+
+ iccprof = 0;
+ prof = 0;
+ switch (clrspc) {
+ case JAS_CLRSPC_SYCBCR:
+ if (!(prof = jas_cmprof_createsycc()))
+ goto error;
+ break;
+ default:
+ if (!(iccprof = jas_iccprof_createfromclrspc(clrspc)))
+ goto error;
+ if (!(prof = jas_cmprof_createfromiccprof(iccprof)))
+ goto error;
+ jas_iccprof_destroy(iccprof);
+ if (!jas_clrspc_isgeneric(clrspc))
+ prof->clrspc = clrspc;
+ break;
+ }
+ return prof;
+error:
+ if (iccprof)
+ jas_iccprof_destroy(iccprof);
+ return 0;
+}
+
+static jas_cmprof_t *jas_cmprof_createsycc()
+{
+ jas_cmprof_t *prof;
+ jas_cmpxform_t *fwdpxform;
+ jas_cmpxform_t *revpxform;
+ jas_cmshapmat_t *fwdshapmat;
+ jas_cmshapmat_t *revshapmat;
+ int i;
+ int j;
+
+ if (!(prof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB)))
+ goto error;
+ prof->clrspc = JAS_CLRSPC_SYCBCR;
+ assert(prof->numchans == 3 && prof->numrefchans == 3);
+ assert(prof->refclrspc == JAS_CLRSPC_CIEXYZ);
+ if (!(fwdpxform = jas_cmpxform_createshapmat()))
+ goto error;
+ fwdpxform->numinchans = 3;
+ fwdpxform->numoutchans = 3;
+ fwdshapmat = &fwdpxform->data.shapmat;
+ fwdshapmat->mono = 0;
+ fwdshapmat->order = 0;
+ fwdshapmat->useluts = 0;
+ fwdshapmat->usemat = 1;
+ fwdshapmat->mat[0][0] = 1.0;
+ fwdshapmat->mat[0][1] = 0.0;
+ fwdshapmat->mat[0][2] = 1.402;
+ fwdshapmat->mat[1][0] = 1.0;
+ fwdshapmat->mat[1][1] = -0.34413;
+ fwdshapmat->mat[1][2] = -0.71414;
+ fwdshapmat->mat[2][0] = 1.0;
+ fwdshapmat->mat[2][1] = 1.772;
+ fwdshapmat->mat[2][2] = 0.0;
+ fwdshapmat->mat[0][3] = -0.5 * (1.402);
+ fwdshapmat->mat[1][3] = -0.5 * (-0.34413 - 0.71414);
+ fwdshapmat->mat[2][3] = -0.5 * (1.772);
+ if (!(revpxform = jas_cmpxform_createshapmat()))
+ goto error;
+ revpxform->numinchans = 3;
+ revpxform->numoutchans = 3;
+ revshapmat = &revpxform->data.shapmat;
+ revshapmat->mono = 0;
+ revshapmat->order = 1;
+ revshapmat->useluts = 0;
+ revshapmat->usemat = 1;
+ jas_cmshapmat_invmat(revshapmat->mat, fwdshapmat->mat);
+
+ for (i = 0; i < JAS_CMXFORM_NUMINTENTS; ++i) {
+ j = SEQFWD(i);
+ if (prof->pxformseqs[j]) {
+ if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j], 0,
+ fwdpxform))
+ goto error;
+ }
+ j = SEQREV(i);
+ if (prof->pxformseqs[j]) {
+ if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j],
+ -1, revpxform))
+ goto error;
+ }
+ }
+
+ jas_cmpxform_destroy(fwdpxform);
+ jas_cmpxform_destroy(revpxform);
+ return prof;
+error:
+ return 0;
+}
+
+jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof)
+{
+ jas_cmprof_t *prof;
+ jas_icchdr_t icchdr;
+ jas_cmpxformseq_t *fwdpxformseq;
+ jas_cmpxformseq_t *revpxformseq;
+
+ if (!(prof = jas_cmprof_create()))
+ goto error;
+ jas_iccprof_gethdr(iccprof, &icchdr);
+ if (!(prof->iccprof = jas_iccprof_copy(iccprof)))
+ goto error;
+ prof->clrspc = icctoclrspc(icchdr.colorspc, 0);
+ prof->refclrspc = icctoclrspc(icchdr.refcolorspc, 1);
+ prof->numchans = jas_clrspc_numchans(prof->clrspc);
+ prof->numrefchans = jas_clrspc_numchans(prof->refclrspc);
+
+ if (prof->numchans == 1) {
+ if (mono(prof->iccprof, 0, &fwdpxformseq))
+ goto error;
+ if (mono(prof->iccprof, 1, &revpxformseq))
+ goto error;
+ } else if (prof->numchans == 3) {
+ if (triclr(prof->iccprof, 0, &fwdpxformseq))
+ goto error;
+ if (triclr(prof->iccprof, 1, &revpxformseq))
+ goto error;
+ }
+ prof->pxformseqs[SEQFWD(0)] = fwdpxformseq;
+ prof->pxformseqs[SEQREV(0)] = revpxformseq;
+
+#if 0
+ if (prof->numchans > 1) {
+ lut(prof->iccprof, 0, PER, &pxformseq);
+ pxformseqs_set(prof, SEQFWD(PER), pxformseq);
+ lut(prof->iccprof, 1, PER, &pxformseq);
+ pxformseqs_set(prof, SEQREV(PER), pxformseq);
+ lut(prof->iccprof, 0, CLR, &pxformseq);
+ pxformseqs_set(prof, SEQREV(CLR), pxformseq);
+ lut(prof->iccprof, 1, CLR, &pxformseq);
+ pxformseqs_set(prof, SEQREV(CLR), pxformseq);
+ lut(prof->iccprof, 0, SAT, &pxformseq);
+ pxformseqs_set(prof, SEQREV(SAT), pxformseq);
+ lut(prof->iccprof, 1, SAT, &pxformseq);
+ pxformseqs_set(prof, SEQREV(SAT), pxformseq);
+ }
+#endif
+
+ return prof;
+error:
+ return 0;
+}
+
+static jas_cmprof_t *jas_cmprof_create()
+{
+ int i;
+ jas_cmprof_t *prof;
+ if (!(prof = jas_malloc(sizeof(jas_cmprof_t))))
+ return 0;
+ memset(prof, 0, sizeof(jas_cmprof_t));
+ prof->iccprof = 0;
+ for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i)
+ prof->pxformseqs[i] = 0;
+ return prof;
+}
+
+void jas_cmprof_destroy(jas_cmprof_t *prof)
+{
+ int i;
+ for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i) {
+ if (prof->pxformseqs[i]) {
+ jas_cmpxformseq_destroy(prof->pxformseqs[i]);
+ prof->pxformseqs[i] = 0;
+ }
+ }
+ if (prof->iccprof)
+ jas_iccprof_destroy(prof->iccprof);
+ jas_free(prof);
+}
+
+jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof)
+{
+ jas_cmprof_t *newprof;
+ int i;
+
+ if (!(newprof = jas_cmprof_create()))
+ goto error;
+ newprof->clrspc = prof->clrspc;
+ newprof->numchans = prof->numchans;
+ newprof->refclrspc = prof->refclrspc;
+ newprof->numrefchans = prof->numrefchans;
+ newprof->iccprof = jas_iccprof_copy(prof->iccprof);
+ for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i) {
+ if (prof->pxformseqs[i]) {
+ if (!(newprof->pxformseqs[i] = jas_cmpxformseq_copy(prof->pxformseqs[i])))
+ goto error;
+ }
+ }
+ return newprof;
+error:
+ return 0;
+}
+
+/******************************************************************************\
+* Transform class.
+\******************************************************************************/
+
+jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,
+ jas_cmprof_t *prfprof, int op, int intent, int optimize)
+{
+ jas_cmxform_t *xform;
+ jas_cmpxformseq_t *inpxformseq;
+ jas_cmpxformseq_t *outpxformseq;
+ jas_cmpxformseq_t *altoutpxformseq;
+ jas_cmpxformseq_t *prfpxformseq;
+ int prfintent;
+
+ /* Avoid compiler warnings about unused parameters. */
+ optimize = 0;
+
+ prfintent = intent;
+
+ if (!(xform = jas_malloc(sizeof(jas_cmxform_t))))
+ goto error;
+ if (!(xform->pxformseq = jas_cmpxformseq_create()))
+ goto error;
+
+ switch (op) {
+ case JAS_CMXFORM_OP_FWD:
+ inpxformseq = fwdpxformseq(inprof, intent);
+ outpxformseq = revpxformseq(outprof, intent);
+ if (!inpxformseq || !outpxformseq)
+ goto error;
+ if (jas_cmpxformseq_append(xform->pxformseq, inpxformseq) ||
+ jas_cmpxformseq_appendcnvt(xform->pxformseq,
+ inprof->refclrspc, outprof->refclrspc) ||
+ jas_cmpxformseq_append(xform->pxformseq, outpxformseq))
+ goto error;
+ xform->numinchans = jas_clrspc_numchans(inprof->clrspc);
+ xform->numoutchans = jas_clrspc_numchans(outprof->clrspc);
+ break;
+ case JAS_CMXFORM_OP_REV:
+ outpxformseq = fwdpxformseq(outprof, intent);
+ inpxformseq = revpxformseq(inprof, intent);
+ if (!outpxformseq || !inpxformseq)
+ goto error;
+ if (jas_cmpxformseq_append(xform->pxformseq, outpxformseq) ||
+ jas_cmpxformseq_appendcnvt(xform->pxformseq,
+ outprof->refclrspc, inprof->refclrspc) ||
+ jas_cmpxformseq_append(xform->pxformseq, inpxformseq))
+ goto error;
+ xform->numinchans = jas_clrspc_numchans(outprof->clrspc);
+ xform->numoutchans = jas_clrspc_numchans(inprof->clrspc);
+ break;
+ case JAS_CMXFORM_OP_PROOF:
+ assert(prfprof);
+ inpxformseq = fwdpxformseq(inprof, intent);
+ prfpxformseq = fwdpxformseq(prfprof, prfintent);
+ if (!inpxformseq || !prfpxformseq)
+ goto error;
+ outpxformseq = simpxformseq(outprof, intent);
+ altoutpxformseq = 0;
+ if (!outpxformseq) {
+ outpxformseq = revpxformseq(outprof, intent);
+ altoutpxformseq = fwdpxformseq(outprof, intent);
+ if (!outpxformseq || !altoutpxformseq)
+ goto error;
+ }
+ if (jas_cmpxformseq_append(xform->pxformseq, inpxformseq) ||
+ jas_cmpxformseq_appendcnvt(xform->pxformseq,
+ inprof->refclrspc, outprof->refclrspc))
+ goto error;
+ if (altoutpxformseq) {
+ if (jas_cmpxformseq_append(xform->pxformseq, outpxformseq) ||
+ jas_cmpxformseq_append(xform->pxformseq, altoutpxformseq))
+ goto error;
+ } else {
+ if (jas_cmpxformseq_append(xform->pxformseq, outpxformseq))
+ goto error;
+ }
+ if (jas_cmpxformseq_appendcnvt(xform->pxformseq,
+ outprof->refclrspc, inprof->refclrspc) ||
+ jas_cmpxformseq_append(xform->pxformseq, prfpxformseq))
+ goto error;
+ xform->numinchans = jas_clrspc_numchans(inprof->clrspc);
+ xform->numoutchans = jas_clrspc_numchans(prfprof->clrspc);
+ break;
+ case JAS_CMXFORM_OP_GAMUT:
+ inpxformseq = fwdpxformseq(inprof, intent);
+ outpxformseq = gampxformseq(outprof);
+ if (!inpxformseq || !outpxformseq)
+ goto error;
+ if (jas_cmpxformseq_append(xform->pxformseq, inpxformseq) ||
+ jas_cmpxformseq_appendcnvt(xform->pxformseq,
+ inprof->refclrspc, outprof->refclrspc) ||
+ jas_cmpxformseq_append(xform->pxformseq, outpxformseq))
+ goto error;
+ xform->numinchans = jas_clrspc_numchans(inprof->clrspc);
+ xform->numoutchans = 1;
+ break;
+ }
+ return xform;
+error:
+ return 0;
+}
+
+#define APPLYBUFSIZ 2048
+int jas_cmxform_apply(jas_cmxform_t *xform, jas_cmpixmap_t *in, jas_cmpixmap_t *out)
+{
+ jas_cmcmptfmt_t *fmt;
+ jas_cmreal_t buf[2][APPLYBUFSIZ];
+ jas_cmpxformseq_t *pxformseq;
+ int i;
+ int j;
+ int width;
+ int height;
+ int total;
+ int n;
+ jas_cmreal_t *inbuf;
+ jas_cmreal_t *outbuf;
+ jas_cmpxform_t *pxform;
+ long *dataptr;
+ int maxchans;
+ int bufmax;
+ int m;
+ int bias;
+ jas_cmreal_t scale;
+ long v;
+ jas_cmreal_t *bufptr;
+
+ if (xform->numinchans > in->numcmpts || xform->numoutchans > out->numcmpts)
+ goto error;
+
+ fmt = &in->cmptfmts[0];
+ width = fmt->width;
+ height = fmt->height;
+ for (i = 1; i < xform->numinchans; ++i) {
+ fmt = &in->cmptfmts[i];
+ if (fmt->width != width || fmt->height != height) {
+ goto error;
+ }
+ }
+ for (i = 0; i < xform->numoutchans; ++i) {
+ fmt = &out->cmptfmts[i];
+ if (fmt->width != width || fmt->height != height) {
+ goto error;
+ }
+ }
+
+ maxchans = 0;
+ pxformseq = xform->pxformseq;
+ for (i = 0; i < pxformseq->numpxforms; ++i) {
+ pxform = pxformseq->pxforms[i];
+ if (pxform->numinchans > maxchans) {
+ maxchans = pxform->numinchans;
+ }
+ if (pxform->numoutchans > maxchans) {
+ maxchans = pxform->numoutchans;
+ }
+ }
+ bufmax = APPLYBUFSIZ / maxchans;
+ assert(bufmax > 0);
+
+ total = width * height;
+ n = 0;
+ while (n < total) {
+
+ inbuf = &buf[0][0];
+ m = JAS_MIN(total - n, bufmax);
+
+ for (i = 0; i < xform->numinchans; ++i) {
+ fmt = &in->cmptfmts[i];
+ scale = (double)((1 << fmt->prec) - 1);
+ bias = fmt->sgnd ? (1 << (fmt->prec - 1)) : 0;
+ dataptr = &fmt->buf[n];
+ bufptr = &inbuf[i];
+ for (j = 0; j < m; ++j) {
+ if (jas_cmgetint(&dataptr, fmt->sgnd, fmt->prec, &v))
+ goto error;
+ *bufptr = (v - bias) / scale;
+ bufptr += xform->numinchans;
+ }
+ }
+
+ inbuf = &buf[0][0];
+ outbuf = inbuf;
+ for (i = 0; i < pxformseq->numpxforms; ++i) {
+ pxform = pxformseq->pxforms[i];
+ if (pxform->numoutchans > pxform->numinchans) {
+ outbuf = (inbuf == &buf[0][0]) ? &buf[1][0] : &buf[0][0];
+ } else {
+ outbuf = inbuf;
+ }
+ if ((*pxform->ops->apply)(pxform, inbuf, outbuf, m))
+ goto error;
+ inbuf = outbuf;
+ }
+
+ for (i = 0; i < xform->numoutchans; ++i) {
+ fmt = &out->cmptfmts[i];
+ scale = (double)((1 << fmt->prec) - 1);
+ bias = fmt->sgnd ? (1 << (fmt->prec - 1)) : 0;
+ bufptr = &outbuf[i];
+ dataptr = &fmt->buf[n];
+ for (j = 0; j < m; ++j) {
+ v = (*bufptr) * scale + bias;
+ bufptr += xform->numoutchans;
+ if (jas_cmputint(&dataptr, fmt->sgnd, fmt->prec, v))
+ goto error;
+ }
+ }
+
+ n += m;
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+void jas_cmxform_destroy(jas_cmxform_t *xform)
+{
+ if (xform->pxformseq)
+ jas_cmpxformseq_destroy(xform->pxformseq);
+ jas_free(xform);
+}
+
+/******************************************************************************\
+* Primitive transform sequence class.
+\******************************************************************************/
+
+static jas_cmpxformseq_t *jas_cmpxformseq_create()
+{
+ jas_cmpxformseq_t *pxformseq;
+ pxformseq = 0;
+ if (!(pxformseq = jas_malloc(sizeof(jas_cmpxformseq_t))))
+ goto error;
+ pxformseq->pxforms = 0;
+ pxformseq->numpxforms = 0;
+ pxformseq->maxpxforms = 0;
+ if (jas_cmpxformseq_resize(pxformseq, 16))
+ goto error;
+ return pxformseq;
+error:
+ if (pxformseq)
+ jas_cmpxformseq_destroy(pxformseq);
+ return 0;
+}
+
+static jas_cmpxformseq_t *jas_cmpxformseq_copy(jas_cmpxformseq_t *pxformseq)
+{
+ jas_cmpxformseq_t *newpxformseq;
+
+ if (!(newpxformseq = jas_cmpxformseq_create()))
+ goto error;
+ if (jas_cmpxformseq_append(newpxformseq, pxformseq))
+ goto error;
+ return newpxformseq;
+error:
+ return 0;
+}
+
+static void jas_cmpxformseq_destroy(jas_cmpxformseq_t *pxformseq)
+{
+ while (pxformseq->numpxforms > 0)
+ jas_cmpxformseq_delete(pxformseq, pxformseq->numpxforms - 1);
+ if (pxformseq->pxforms)
+ jas_free(pxformseq->pxforms);
+ jas_free(pxformseq);
+}
+
+static int jas_cmpxformseq_delete(jas_cmpxformseq_t *pxformseq, int i)
+{
+ assert(i >= 0 && i < pxformseq->numpxforms);
+ if (i != pxformseq->numpxforms - 1)
+ abort();
+ jas_cmpxform_destroy(pxformseq->pxforms[i]);
+ pxformseq->pxforms[i] = 0;
+ --pxformseq->numpxforms;
+ return 0;
+}
+
+static int jas_cmpxformseq_appendcnvt(jas_cmpxformseq_t *pxformseq,
+ int dstclrspc, int srcclrspc)
+{
+ if (dstclrspc == srcclrspc)
+ return 0;
+ abort();
+ /* Avoid compiler warnings about unused parameters. */
+ pxformseq = 0;
+ return -1;
+}
+
+static int jas_cmpxformseq_insertpxform(jas_cmpxformseq_t *pxformseq,
+ int i, jas_cmpxform_t *pxform)
+{
+ jas_cmpxform_t *tmppxform;
+ int n;
+ if (i < 0)
+ i = pxformseq->numpxforms;
+ assert(i >= 0 && i <= pxformseq->numpxforms);
+ if (pxformseq->numpxforms >= pxformseq->maxpxforms) {
+ if (jas_cmpxformseq_resize(pxformseq, pxformseq->numpxforms +
+ 16))
+ goto error;
+ }
+ assert(pxformseq->numpxforms < pxformseq->maxpxforms);
+ if (!(tmppxform = jas_cmpxform_copy(pxform)))
+ goto error;
+ n = pxformseq->numpxforms - i;
+ if (n > 0) {
+ memmove(&pxformseq->pxforms[i + 1], &pxformseq->pxforms[i],
+ n * sizeof(jas_cmpxform_t *));
+ }
+ pxformseq->pxforms[i] = tmppxform;
+ ++pxformseq->numpxforms;
+ return 0;
+error:
+ return -1;
+}
+
+static int jas_cmpxformseq_append(jas_cmpxformseq_t *pxformseq,
+ jas_cmpxformseq_t *othpxformseq)
+{
+ int n;
+ int i;
+ jas_cmpxform_t *pxform;
+ jas_cmpxform_t *othpxform;
+ n = pxformseq->numpxforms + othpxformseq->numpxforms;
+ if (n > pxformseq->maxpxforms) {
+ if (jas_cmpxformseq_resize(pxformseq, n))
+ goto error;
+ }
+ for (i = 0; i < othpxformseq->numpxforms; ++i) {
+ othpxform = othpxformseq->pxforms[i];
+ if (!(pxform = jas_cmpxform_copy(othpxform)))
+ goto error;
+ pxformseq->pxforms[pxformseq->numpxforms] = pxform;
+ ++pxformseq->numpxforms;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static int jas_cmpxformseq_resize(jas_cmpxformseq_t *pxformseq, int n)
+{
+ jas_cmpxform_t **p;
+ assert(n >= pxformseq->numpxforms);
+ p = (!pxformseq->pxforms) ? jas_malloc(n * sizeof(jas_cmpxform_t *)) :
+ jas_realloc(pxformseq->pxforms, n * sizeof(jas_cmpxform_t *));
+ if (!p) {
+ return -1;
+ }
+ pxformseq->pxforms = p;
+ pxformseq->maxpxforms = n;
+ return 0;
+}
+
+/******************************************************************************\
+* Primitive transform class.
+\******************************************************************************/
+
+static jas_cmpxform_t *jas_cmpxform_create0()
+{
+ jas_cmpxform_t *pxform;
+ if (!(pxform = jas_malloc(sizeof(jas_cmpxform_t))))
+ return 0;
+ memset(pxform, 0, sizeof(jas_cmpxform_t));
+ pxform->refcnt = 0;
+ pxform->ops = 0;
+ return pxform;
+}
+
+static void jas_cmpxform_destroy(jas_cmpxform_t *pxform)
+{
+ if (--pxform->refcnt <= 0) {
+ (*pxform->ops->destroy)(pxform);
+ jas_free(pxform);
+ }
+}
+
+static jas_cmpxform_t *jas_cmpxform_copy(jas_cmpxform_t *pxform)
+{
+ ++pxform->refcnt;
+ return pxform;
+}
+
+/******************************************************************************\
+* Shaper matrix class.
+\******************************************************************************/
+
+static jas_cmpxform_t *jas_cmpxform_createshapmat()
+{
+ int i;
+ int j;
+ jas_cmpxform_t *pxform;
+ jas_cmshapmat_t *shapmat;
+ if (!(pxform = jas_cmpxform_create0()))
+ return 0;
+ pxform->ops = &shapmat_ops;
+ shapmat = &pxform->data.shapmat;
+ shapmat->mono = 0;
+ shapmat->order = 0;
+ shapmat->useluts = 0;
+ shapmat->usemat = 0;
+ for (i = 0; i < 3; ++i)
+ jas_cmshapmatlut_init(&shapmat->luts[i]);
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 4; ++j)
+ shapmat->mat[i][j] = 0.0;
+ }
+ ++pxform->refcnt;
+ return pxform;
+}
+
+static void jas_cmshapmat_destroy(jas_cmpxform_t *pxform)
+{
+ jas_cmshapmat_t *shapmat = &pxform->data.shapmat;
+ int i;
+ for (i = 0; i < 3; ++i)
+ jas_cmshapmatlut_cleanup(&shapmat->luts[i]);
+}
+
+static int jas_cmshapmat_apply(jas_cmpxform_t *pxform, jas_cmreal_t *in,
+ jas_cmreal_t *out, int cnt)
+{
+ jas_cmshapmat_t *shapmat = &pxform->data.shapmat;
+ jas_cmreal_t *src;
+ jas_cmreal_t *dst;
+ jas_cmreal_t a0;
+ jas_cmreal_t a1;
+ jas_cmreal_t a2;
+ jas_cmreal_t b0;
+ jas_cmreal_t b1;
+ jas_cmreal_t b2;
+ src = in;
+ dst = out;
+ if (!shapmat->mono) {
+ while (--cnt >= 0) {
+ a0 = *src++;
+ a1 = *src++;
+ a2 = *src++;
+ if (!shapmat->order && shapmat->useluts) {
+ a0 = jas_cmshapmatlut_lookup(&shapmat->luts[0], a0);
+ a1 = jas_cmshapmatlut_lookup(&shapmat->luts[1], a1);
+ a2 = jas_cmshapmatlut_lookup(&shapmat->luts[2], a2);
+ }
+ if (shapmat->usemat) {
+ b0 = shapmat->mat[0][0] * a0
+ + shapmat->mat[0][1] * a1
+ + shapmat->mat[0][2] * a2
+ + shapmat->mat[0][3];
+ b1 = shapmat->mat[1][0] * a0
+ + shapmat->mat[1][1] * a1
+ + shapmat->mat[1][2] * a2
+ + shapmat->mat[1][3];
+ b2 = shapmat->mat[2][0] * a0
+ + shapmat->mat[2][1] * a1
+ + shapmat->mat[2][2] * a2
+ + shapmat->mat[2][3];
+ a0 = b0;
+ a1 = b1;
+ a2 = b2;
+ }
+ if (shapmat->order && shapmat->useluts) {
+ a0 = jas_cmshapmatlut_lookup(&shapmat->luts[0], a0);
+ a1 = jas_cmshapmatlut_lookup(&shapmat->luts[1], a1);
+ a2 = jas_cmshapmatlut_lookup(&shapmat->luts[2], a2);
+ }
+ *dst++ = a0;
+ *dst++ = a1;
+ *dst++ = a2;
+ }
+ } else {
+ if (!shapmat->order) {
+ while (--cnt >= 0) {
+ a0 = *src++;
+ if (shapmat->useluts)
+ a0 = jas_cmshapmatlut_lookup(&shapmat->luts[0], a0);
+ a2 = a0 * shapmat->mat[2][0];
+ a1 = a0 * shapmat->mat[1][0];
+ a0 = a0 * shapmat->mat[0][0];
+ *dst++ = a0;
+ *dst++ = a1;
+ *dst++ = a2;
+ }
+ } else {
+assert(0);
+ while (--cnt >= 0) {
+ a0 = *src++;
+ src++;
+ src++;
+ a0 = a0 * shapmat->mat[0][0];
+ if (shapmat->useluts)
+ a0 = jas_cmshapmatlut_lookup(&shapmat->luts[0], a0);
+ *dst++ = a0;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static void jas_cmshapmatlut_init(jas_cmshapmatlut_t *lut)
+{
+ lut->data = 0;
+ lut->size = 0;
+}
+
+static void jas_cmshapmatlut_cleanup(jas_cmshapmatlut_t *lut)
+{
+ if (lut->data) {
+ jas_free(lut->data);
+ lut->data = 0;
+ }
+ lut->size = 0;
+}
+
+static double gammafn(double x, double gamma)
+{
+ if (x == 0.0)
+ return 0.0;
+ return pow(x, gamma);
+}
+
+static int jas_cmshapmatlut_set(jas_cmshapmatlut_t *lut, jas_icccurv_t *curv)
+{
+ jas_cmreal_t gamma;
+ int i;
+ gamma = 0;
+ jas_cmshapmatlut_cleanup(lut);
+ if (curv->numents == 0) {
+ lut->size = 2;
+ if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
+ goto error;
+ lut->data[0] = 0.0;
+ lut->data[1] = 1.0;
+ } else if (curv->numents == 1) {
+ lut->size = 256;
+ if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
+ goto error;
+ gamma = curv->ents[0] / 256.0;
+ for (i = 0; i < lut->size; ++i) {
+ lut->data[i] = gammafn(i / (double) (lut->size - 1), gamma);
+ }
+ } else {
+ lut->size = curv->numents;
+ if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
+ goto error;
+ for (i = 0; i < lut->size; ++i) {
+ lut->data[i] = curv->ents[i] / 65535.0;
+ }
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static jas_cmreal_t jas_cmshapmatlut_lookup(jas_cmshapmatlut_t *lut, jas_cmreal_t x)
+{
+ jas_cmreal_t t;
+ int lo;
+ int hi;
+ t = x * (lut->size - 1);
+ lo = floor(t);
+ if (lo < 0)
+ return lut->data[0];
+ hi = ceil(t);
+ if (hi >= lut->size)
+ return lut->data[lut->size - 1];
+ return lut->data[lo] + (t - lo) * (lut->data[hi] - lut->data[lo]);
+}
+
+static int jas_cmshapmatlut_invert(jas_cmshapmatlut_t *invlut,
+ jas_cmshapmatlut_t *lut, int n)
+{
+ int i;
+ int j;
+ int k;
+ jas_cmreal_t ax;
+ jas_cmreal_t ay;
+ jas_cmreal_t bx;
+ jas_cmreal_t by;
+ jas_cmreal_t sx;
+ jas_cmreal_t sy;
+ assert(n >= 2);
+ if (invlut->data) {
+ jas_free(invlut->data);
+ invlut->data = 0;
+ }
+ /* The sample values should be nondecreasing. */
+ for (i = 1; i < lut->size; ++i) {
+ if (lut->data[i - 1] > lut->data[i]) {
+ assert(0);
+ return -1;
+ }
+ }
+ if (!(invlut->data = jas_malloc(n * sizeof(jas_cmreal_t))))
+ return -1;
+ invlut->size = n;
+ for (i = 0; i < invlut->size; ++i) {
+ sy = ((double) i) / (invlut->size - 1);
+ sx = 1.0;
+ for (j = 0; j < lut->size; ++j) {
+ ay = lut->data[j];
+ if (sy == ay) {
+ for (k = j + 1; k < lut->size; ++k) {
+ by = lut->data[k];
+ if (by != sy)
+ break;
+#if 0
+assert(0);
+#endif
+ }
+ if (k < lut->size) {
+ --k;
+ ax = ((double) j) / (lut->size - 1);
+ bx = ((double) k) / (lut->size - 1);
+ sx = (ax + bx) / 2.0;
+ }
+ break;
+ }
+ if (j < lut->size - 1) {
+ by = lut->data[j + 1];
+ if (sy > ay && sy < by) {
+ ax = ((double) j) / (lut->size - 1);
+ bx = ((double) j + 1) / (lut->size - 1);
+ sx = ax +
+ (sy - ay) / (by - ay) * (bx - ax);
+ break;
+ }
+ }
+ }
+ invlut->data[i] = sx;
+ }
+#if 0
+for (i=0;i<lut->size;++i)
+ fprintf(stderr, "lut[%d]=%f ", i, lut->data[i]);
+for (i=0;i<invlut->size;++i)
+ fprintf(stderr, "invlut[%d]=%f ", i, invlut->data[i]);
+#endif
+ return 0;
+}
+
+static int jas_cmshapmat_invmat(jas_cmreal_t out[3][4], jas_cmreal_t in[3][4])
+{
+ jas_cmreal_t d;
+ d = in[0][0] * (in[1][1] * in[2][2] - in[1][2] * in[2][1])
+ - in[0][1] * (in[1][0] * in[2][2] - in[1][2] * in[2][0])
+ + in[0][2] * (in[1][0] * in[2][1] - in[1][1] * in[2][0]);
+#if 0
+fprintf(stderr, "delta=%f\n", d);
+#endif
+ if (JAS_ABS(d) < 1e-6)
+ return -1;
+ out[0][0] = (in[1][1] * in[2][2] - in[1][2] * in[2][1]) / d;
+ out[1][0] = -(in[1][0] * in[2][2] - in[1][2] * in[2][0]) / d;
+ out[2][0] = (in[1][0] * in[2][1] - in[1][1] * in[2][0]) / d;
+ out[0][1] = -(in[0][1] * in[2][2] - in[0][2] * in[2][1]) / d;
+ out[1][1] = (in[0][0] * in[2][2] - in[0][2] * in[2][0]) / d;
+ out[2][1] = -(in[0][0] * in[2][1] - in[0][1] * in[2][0]) / d;
+ out[0][2] = (in[0][1] * in[1][2] - in[0][2] * in[1][1]) / d;
+ out[1][2] = -(in[0][0] * in[1][2] - in[1][0] * in[0][2]) / d;
+ out[2][2] = (in[0][0] * in[1][1] - in[0][1] * in[1][0]) / d;
+ out[0][3] = -in[0][3];
+ out[1][3] = -in[1][3];
+ out[2][3] = -in[2][3];
+#if 0
+fprintf(stderr, "[ %f %f %f %f ]\n[ %f %f %f %f ]\n[ %f %f %f %f ]\n",
+in[0][0], in[0][1], in[0][2], in[0][3],
+in[1][0], in[1][1], in[1][2], in[1][3],
+in[2][0], in[2][1], in[2][2], in[2][3]);
+fprintf(stderr, "[ %f %f %f %f ]\n[ %f %f %f %f ]\n[ %f %f %f %f ]\n",
+out[0][0], out[0][1], out[0][2], out[0][3],
+out[1][0], out[1][1], out[1][2], out[1][3],
+out[2][0], out[2][1], out[2][2], out[2][3]);
+#endif
+ return 0;
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static int icctoclrspc(int iccclrspc, int refflag)
+{
+ if (refflag) {
+ switch (iccclrspc) {
+ case JAS_ICC_COLORSPC_XYZ:
+ return JAS_CLRSPC_CIEXYZ;
+ case JAS_ICC_COLORSPC_LAB:
+ return JAS_CLRSPC_CIELAB;
+ default:
+ abort();
+ break;
+ }
+ } else {
+ switch (iccclrspc) {
+ case JAS_ICC_COLORSPC_YCBCR:
+ return JAS_CLRSPC_GENYCBCR;
+ case JAS_ICC_COLORSPC_RGB:
+ return JAS_CLRSPC_GENRGB;
+ case JAS_ICC_COLORSPC_GRAY:
+ return JAS_CLRSPC_GENGRAY;
+ default:
+ abort();
+ break;
+ }
+ }
+}
+
+static int mono(jas_iccprof_t *iccprof, int op, jas_cmpxformseq_t **retpxformseq)
+{
+ jas_iccattrval_t *graytrc;
+ jas_cmshapmat_t *shapmat;
+ jas_cmpxform_t *pxform;
+ jas_cmpxformseq_t *pxformseq;
+ jas_cmshapmatlut_t lut;
+
+ jas_cmshapmatlut_init(&lut);
+ if (!(graytrc = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRYTRC)) ||
+ graytrc->type != JAS_ICC_TYPE_CURV)
+ goto error;
+ if (!(pxform = jas_cmpxform_createshapmat()))
+ goto error;
+ shapmat = &pxform->data.shapmat;
+ if (!(pxformseq = jas_cmpxformseq_create()))
+ goto error;
+ if (jas_cmpxformseq_insertpxform(pxformseq, -1, pxform))
+ goto error;
+
+ pxform->numinchans = 1;
+ pxform->numoutchans = 3;
+
+ shapmat->mono = 1;
+ shapmat->useluts = 1;
+ shapmat->usemat = 1;
+ if (!op) {
+ shapmat->order = 0;
+ shapmat->mat[0][0] = 0.9642;
+ shapmat->mat[1][0] = 1.0;
+ shapmat->mat[2][0] = 0.8249;
+ if (jas_cmshapmatlut_set(&shapmat->luts[0], &graytrc->data.curv))
+ goto error;
+ } else {
+ shapmat->order = 1;
+ shapmat->mat[0][0] = 1.0 / 0.9642;
+ shapmat->mat[1][0] = 1.0;
+ shapmat->mat[2][0] = 1.0 / 0.8249;
+ jas_cmshapmatlut_init(&lut);
+ if (jas_cmshapmatlut_set(&lut, &graytrc->data.curv))
+ goto error;
+ if (jas_cmshapmatlut_invert(&shapmat->luts[0], &lut, lut.size))
+ goto error;
+ jas_cmshapmatlut_cleanup(&lut);
+ }
+ jas_iccattrval_destroy(graytrc);
+ jas_cmpxform_destroy(pxform);
+ *retpxformseq = pxformseq;
+ return 0;
+error:
+ return -1;
+}
+
+static int triclr(jas_iccprof_t *iccprof, int op, jas_cmpxformseq_t **retpxformseq)
+{
+ int i;
+ jas_iccattrval_t *trcs[3];
+ jas_iccattrval_t *cols[3];
+ jas_cmshapmat_t *shapmat;
+ jas_cmpxform_t *pxform;
+ jas_cmpxformseq_t *pxformseq;
+ jas_cmreal_t mat[3][4];
+ jas_cmshapmatlut_t lut;
+ jas_cmshapmatlut_init(&lut);
+ for (i = 0; i < 3; ++i) {
+ trcs[i] = 0;
+ cols[i] = 0;
+ }
+ if (!(trcs[0] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_REDTRC)) ||
+ !(trcs[1] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRNTRC)) ||
+ !(trcs[2] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_BLUTRC)) ||
+ !(cols[0] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_REDMATCOL)) ||
+ !(cols[1] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRNMATCOL)) ||
+ !(cols[2] = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_BLUMATCOL)))
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ if (trcs[i]->type != JAS_ICC_TYPE_CURV ||
+ cols[i]->type != JAS_ICC_TYPE_XYZ)
+ goto error;
+ }
+ if (!(pxform = jas_cmpxform_createshapmat()))
+ goto error;
+ pxform->numinchans = 3;
+ pxform->numoutchans = 3;
+ shapmat = &pxform->data.shapmat;
+ if (!(pxformseq = jas_cmpxformseq_create()))
+ goto error;
+ if (jas_cmpxformseq_insertpxform(pxformseq, -1, pxform))
+ goto error;
+ shapmat->mono = 0;
+ shapmat->useluts = 1;
+ shapmat->usemat = 1;
+ if (!op) {
+ shapmat->order = 0;
+ for (i = 0; i < 3; ++i) {
+ shapmat->mat[0][i] = cols[i]->data.xyz.x / 65536.0;
+ shapmat->mat[1][i] = cols[i]->data.xyz.y / 65536.0;
+ shapmat->mat[2][i] = cols[i]->data.xyz.z / 65536.0;
+ }
+ for (i = 0; i < 3; ++i)
+ shapmat->mat[i][3] = 0.0;
+ for (i = 0; i < 3; ++i) {
+ if (jas_cmshapmatlut_set(&shapmat->luts[i], &trcs[i]->data.curv))
+ goto error;
+ }
+ } else {
+ shapmat->order = 1;
+ for (i = 0; i < 3; ++i) {
+ mat[0][i] = cols[i]->data.xyz.x / 65536.0;
+ mat[1][i] = cols[i]->data.xyz.y / 65536.0;
+ mat[2][i] = cols[i]->data.xyz.z / 65536.0;
+ }
+ for (i = 0; i < 3; ++i)
+ mat[i][3] = 0.0;
+ if (jas_cmshapmat_invmat(shapmat->mat, mat))
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ jas_cmshapmatlut_init(&lut);
+ if (jas_cmshapmatlut_set(&lut, &trcs[i]->data.curv))
+ goto error;
+ if (jas_cmshapmatlut_invert(&shapmat->luts[i], &lut, lut.size))
+ goto error;
+ jas_cmshapmatlut_cleanup(&lut);
+ }
+ }
+ for (i = 0; i < 3; ++i) {
+ jas_iccattrval_destroy(trcs[i]);
+ jas_iccattrval_destroy(cols[i]);
+ }
+ jas_cmpxform_destroy(pxform);
+ *retpxformseq = pxformseq;
+ return 0;
+error:
+ return -1;
+}
+
+static int jas_cmgetint(long **bufptr, int sgnd, int prec, long *val)
+{
+ long v;
+ int m;
+ v = **bufptr;
+ if (sgnd) {
+ m = (1 << (prec - 1));
+ if (v < -m || v >= m)
+ return -1;
+ } else {
+ if (v < 0 || v >= (1 << prec))
+ return -1;
+ }
+ ++(*bufptr);
+ *val = v;
+ return 0;
+}
+
+static int jas_cmputint(long **bufptr, int sgnd, int prec, long val)
+{
+ int m;
+ if (sgnd) {
+ m = (1 << (prec - 1));
+ if (val < -m || val >= m)
+ return -1;
+ } else {
+ if (val < 0 || val >= (1 << prec))
+ return -1;
+ }
+ **bufptr = val;
+ ++(*bufptr);
+ return 0;
+}
+
+int jas_clrspc_numchans(int clrspc)
+{
+ switch (jas_clrspc_fam(clrspc)) {
+ case JAS_CLRSPC_FAM_XYZ:
+ case JAS_CLRSPC_FAM_LAB:
+ case JAS_CLRSPC_FAM_RGB:
+ case JAS_CLRSPC_FAM_YCBCR:
+ return 3;
+ break;
+ case JAS_CLRSPC_FAM_GRAY:
+ return 1;
+ break;
+ default:
+ abort();
+ break;
+ }
+}
+
+jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof)
+{
+ return jas_iccprof_copy(prof->iccprof);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_cm.h b/osframework/source/ImageLib/jpeg2000/jas_cm.h
new file mode 100644
index 0000000..73e8f6a
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_cm.h
@@ -0,0 +1,315 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Color Management
+ *
+ * $Id: jas_cm.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_CM_H
+#define JAS_CM_H
+
+#include "jas_config.h"
+#include "jas_icc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef int jas_clrspc_t;
+
+/* transform operations */
+#define JAS_CMXFORM_OP_FWD 0
+#define JAS_CMXFORM_OP_REV 1
+#define JAS_CMXFORM_OP_PROOF 2
+#define JAS_CMXFORM_OP_GAMUT 3
+
+/* rendering intents */
+#define JAS_CMXFORM_INTENT_PER 0
+#define JAS_CMXFORM_INTENT_RELCLR 1
+#define JAS_CMXFORM_INTENT_ABSCLR 2
+#define JAS_CMXFORM_INTENT_SAT 3
+#define JAS_CMXFORM_NUMINTENTS 4
+
+#define JAS_CMXFORM_OPTM_SPEED 0
+#define JAS_CMXFORM_OPTM_SIZE 1
+#define JAS_CMXFORM_OPTM_ACC 2
+
+
+#define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
+#define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
+#define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
+#define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
+#define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
+
+#define JAS_CLRSPC_UNKNOWNMASK 0x4000
+
+/* color space families */
+#define JAS_CLRSPC_FAM_UNKNOWN 0
+#define JAS_CLRSPC_FAM_XYZ 1
+#define JAS_CLRSPC_FAM_LAB 2
+#define JAS_CLRSPC_FAM_GRAY 3
+#define JAS_CLRSPC_FAM_RGB 4
+#define JAS_CLRSPC_FAM_YCBCR 5
+
+/* specific color spaces */
+#define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
+#define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
+#define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
+#define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
+#define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
+#define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
+
+/* generic color spaces */
+#define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
+#define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
+#define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
+
+#define JAS_CLRSPC_CHANIND_YCBCR_Y 0
+#define JAS_CLRSPC_CHANIND_YCBCR_CB 1
+#define JAS_CLRSPC_CHANIND_YCBCR_CR 2
+
+#define JAS_CLRSPC_CHANIND_RGB_R 0
+#define JAS_CLRSPC_CHANIND_RGB_G 1
+#define JAS_CLRSPC_CHANIND_RGB_B 2
+
+#define JAS_CLRSPC_CHANIND_GRAY_Y 0
+
+typedef double jas_cmreal_t;
+
+struct jas_cmpxform_s;
+
+typedef struct {
+ long *buf;
+ int prec;
+ int sgnd;
+ int width;
+ int height;
+} jas_cmcmptfmt_t;
+
+typedef struct {
+ int numcmpts;
+ jas_cmcmptfmt_t *cmptfmts;
+} jas_cmpixmap_t;
+
+typedef struct {
+ void (*destroy)(struct jas_cmpxform_s *pxform);
+ int (*apply)(struct jas_cmpxform_s *pxform, jas_cmreal_t *in, jas_cmreal_t *out, int cnt);
+ void (*dump)(struct jas_cmpxform_s *pxform);
+} jas_cmpxformops_t;
+
+typedef struct {
+ jas_cmreal_t *data;
+ int size;
+} jas_cmshapmatlut_t;
+
+typedef struct {
+ int mono;
+ int order;
+ int useluts;
+ int usemat;
+ jas_cmshapmatlut_t luts[3];
+ jas_cmreal_t mat[3][4];
+} jas_cmshapmat_t;
+
+typedef struct {
+ int order;
+} jas_cmshaplut_t;
+
+typedef struct {
+ int inclrspc;
+ int outclrspc;
+} jas_cmclrspcconv_t;
+
+#define jas_align_t double
+
+typedef struct jas_cmpxform_s {
+ int refcnt;
+ jas_cmpxformops_t *ops;
+ int numinchans;
+ int numoutchans;
+ union {
+ jas_align_t dummy;
+ jas_cmshapmat_t shapmat;
+ jas_cmshaplut_t shaplut;
+ jas_cmclrspcconv_t clrspcconv;
+ } data;
+} jas_cmpxform_t;
+
+typedef struct {
+ int numpxforms;
+ int maxpxforms;
+ jas_cmpxform_t **pxforms;
+} jas_cmpxformseq_t;
+
+typedef struct {
+ int numinchans;
+ int numoutchans;
+ jas_cmpxformseq_t *pxformseq;
+} jas_cmxform_t;
+
+#define JAS_CMPROF_TYPE_DEV 1
+#define JAS_CMPROF_TYPE_CLRSPC 2
+
+#define JAS_CMPROF_NUMPXFORMSEQS 13
+
+typedef struct {
+ int clrspc;
+ int numchans;
+ int refclrspc;
+ int numrefchans;
+ jas_iccprof_t *iccprof;
+ jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
+} jas_cmprof_t;
+
+/* Create a profile. */
+
+/* Destroy a profile. */
+void jas_cmprof_destroy(jas_cmprof_t *prof);
+
+#if 0
+typedef int_fast32_t jas_cmattrname_t;
+typedef int_fast32_t jas_cmattrval_t;
+typedef int_fast32_t jas_cmattrtype_t;
+/* Load a profile. */
+int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, int fmt);
+/* Save a profile. */
+int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, int fmt);
+/* Set an attribute of a profile. */
+int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
+/* Get an attribute of a profile. */
+void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
+#endif
+
+jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,
+ jas_cmprof_t *proofprof, int op, int intent, int optimize);
+
+void jas_cmxform_destroy(jas_cmxform_t *xform);
+
+/* Apply a transform to data. */
+int jas_cmxform_apply(jas_cmxform_t *xform, jas_cmpixmap_t *in,
+ jas_cmpixmap_t *out);
+
+int jas_cxform_optimize(jas_cmxform_t *xform, int optimize);
+
+int jas_clrspc_numchans(int clrspc);
+jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof);
+jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc);
+jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof);
+
+#define jas_cmprof_clrspc(prof) ((prof)->clrspc)
+jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_config.h b/osframework/source/ImageLib/jpeg2000/jas_config.h
new file mode 100644
index 0000000..fe298d4
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_config.h
@@ -0,0 +1,241 @@
+/* src/libjasper/include/jasper/jas_config.h. Generated automatically by configure. */
+/* src/libjasper/include/jasper/jas_config.h.in. Generated automatically from configure.in by autoheader. */
+
+/*
+ * Copyright (c) 2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JAS_CONFIG_H
+#define JAS_CONFIG_H
+
+/* This identifies the version of JasPer. */
+#define JAS_VERSION "1.700.2"
+
+/* The preprocessor symbol JAS_WIN_MSVC_BUILD should not be defined
+ unless the JasPer software is being built under Microsoft Windows
+ using Microsoft Visual C. */
+#define JAS_WIN_MSVC_BUILD
+#define EXCLUDE_JPG_SUPPORT
+#define EXCLUDE_MIF_SUPPORT
+#define EXCLUDE_PNM_SUPPORT
+#define EXCLUDE_RAS_SUPPORT
+#define EXCLUDE_BMP_SUPPORT
+#define EXCLUDE_PGX_SUPPORT
+//#define EXCLUDE_JPC_SUPPORT
+//#define EXCLUDE_JP2_SUPPORT
+
+#ifndef JAS_WIN_MSVC_BUILD
+
+/* Define to empty if the keyword does not work. */
+/* #undef const */
+
+/* Define if you don't have vprintf but do have _doprnt. */
+/* #undef HAVE_DOPRNT */
+
+/* Define if you have the vprintf function. */
+#define HAVE_VPRINTF 1
+
+/* Define as __inline if that's what the C compiler calls it. */
+/* #undef inline */
+
+/* Define to `unsigned' if <sys/types.h> doesn't define. */
+/* #undef size_t */
+
+/* Define if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define if your processor stores words with the most significant
+ byte first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define if the X Window System is missing or not being used. */
+/* #undef X_DISPLAY_MISSING */
+
+#define JAS_CONFIGURE 1
+#define JAS_VERSION "1.700.2"
+/* #undef DEBUG_MEMALLOC */
+/* #undef DEBUG_OVERFLOW */
+/* #undef ushort */
+/* #undef uint */
+#define uchar unsigned char
+#define longlong long long
+#define ulonglong unsigned long long
+/* #undef ssize_t */
+
+/* The number of bytes in a int. */
+#define SIZEOF_INT 4
+
+/* The number of bytes in a long. */
+#define SIZEOF_LONG 4
+
+/* The number of bytes in a long long. */
+#define SIZEOF_LONG_LONG 8
+
+/* The number of bytes in a short. */
+#define SIZEOF_SHORT 2
+
+/* The number of bytes in a unsigned int. */
+#define SIZEOF_UNSIGNED_INT 4
+
+/* The number of bytes in a unsigned long. */
+#define SIZEOF_UNSIGNED_LONG 4
+
+/* The number of bytes in a unsigned long long. */
+#define SIZEOF_UNSIGNED_LONG_LONG 8
+
+/* The number of bytes in a unsigned short. */
+#define SIZEOF_UNSIGNED_SHORT 2
+
+/* Define if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define if you have the <io.h> header file. */
+/* #undef HAVE_IO_H */
+
+/* Define if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define if you have the <stdbool.h> header file. */
+#define HAVE_STDBOOL_H 1
+
+/* Define if you have the <stddef.h> header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define if you have the <windows.h> header file. */
+/* #undef HAVE_WINDOWS_H */
+
+/* Define if you have the m library (-lm). */
+#define HAVE_LIBM 1
+
+/* Name of package */
+#define PACKAGE "jasper"
+
+/* Version number of package */
+#define VERSION "1.700.2"
+
+#else
+#include "jas_config2.h"
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_config2.h b/osframework/source/ImageLib/jpeg2000/jas_config2.h
new file mode 100644
index 0000000..0b77b63
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_config2.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JAS_CONFIG2_H
+#define JAS_CONFIG2_H
+
+/*
+ * Configuration for Microsoft Windows and Microsoft Visual C.
+ *
+ * We are not using a configure-based build.
+ * Try to compensate for this here, by specifying the preprocessor symbols
+ * normally defined by configure.
+ */
+
+#define uchar unsigned char
+#define ushort unsigned short
+#define uint unsigned int
+#define ulong unsigned long
+#define longlong long long
+#define ulonglong unsigned long long
+/*#define ssize_t int*/
+
+#define HAVE_FCNTL_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_IO_H 1
+#define HAVE_WINDOWS_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#ifndef HAVE_STDLIB_H
+#define HAVE_STDLIB_H 1
+#endif
+
+#ifndef HAVE_STDDEF_H
+#define HAVE_STDDEF_H 1
+#endif
+
+#pragma warning(disable:4244)
+#pragma warning(disable:4018)
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_debug.c b/osframework/source/ImageLib/jpeg2000/jas_debug.c
new file mode 100644
index 0000000..863eae1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_debug.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "jas_types.h"
+#include "jas_debug.h"
+
+/******************************************************************************\
+* Local data.
+\******************************************************************************/
+
+static int jas_dbglevel = 0;
+/* The debug level. */
+
+/******************************************************************************\
+* Code for getting/setting the debug level.
+\******************************************************************************/
+
+/* Set the library debug level. */
+int jas_setdbglevel(int dbglevel)
+{
+ int olddbglevel;
+
+ /* Save the old debug level. */
+ olddbglevel = jas_dbglevel;
+
+ /* Change the debug level. */
+ jas_dbglevel = dbglevel;
+
+ /* Return the old debug level. */
+ return olddbglevel;
+}
+
+/* Get the library debug level. */
+int jas_getdbglevel()
+{
+ return jas_dbglevel;
+}
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+/* Perform formatted output to standard error. */
+int jas_eprintf(const char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
+/* Dump memory to a stream. */
+int jas_memdump(FILE *out, void *data, size_t len)
+{
+ size_t i;
+ size_t j;
+ uchar *dp;
+ dp = data;
+ for (i = 0; i < len; i += 16) {
+ fprintf(out, "%04x:", i);
+ for (j = 0; j < 16; ++j) {
+ if (i + j < len) {
+ fprintf(out, " %02x", dp[i + j]);
+ }
+ }
+ fprintf(out, "\n");
+ }
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_debug.h b/osframework/source/ImageLib/jpeg2000/jas_debug.h
new file mode 100644
index 0000000..9353d2f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_debug.h
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Debugging-Related Code
+ *
+ * $Id: jas_debug.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_DEBUG_H
+#define JAS_DEBUG_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+
+#include "jas_config.h"
+#include "jas_types.h"
+#include "jas_debug.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Macros and functions.
+\******************************************************************************/
+
+/* Output debugging information to standard error provided that the debug
+ level is set sufficiently high. */
+#if defined(DEBUG)
+#define JAS_DBGLOG(n, x) \
+ ((jas_getdbglevel() >= (n)) ? (jas_eprintf x) : 0)
+#else
+#define JAS_DBGLOG(n, x)
+#endif
+
+/* Get the library debug level. */
+int jas_getdbglevel(void);
+
+/* Set the library debug level. */
+int jas_setdbglevel(int dbglevel);
+
+/* Perform formatted output to standard error. */
+int jas_eprintf(const char *fmt, ...);
+
+/* Dump memory to a stream. */
+int jas_memdump(FILE *out, void *data, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_fix.h b/osframework/source/ImageLib/jpeg2000/jas_fix.h
new file mode 100644
index 0000000..0882fc0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_fix.h
@@ -0,0 +1,407 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Fixed-Point Number Class
+ *
+ * $Id: jas_fix.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_FIX_H
+#define JAS_FIX_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "jas_config.h"
+#include "jas_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* The representation of the value zero. */
+#define JAS_FIX_ZERO(fix_t, fracbits) \
+ JAS_CAST(fix_t, 0)
+
+/* The representation of the value one. */
+#define JAS_FIX_ONE(fix_t, fracbits) \
+ (JAS_CAST(fix_t, 1) << (fracbits))
+
+/* The representation of the value one half. */
+#define JAS_FIX_HALF(fix_t, fracbits) \
+ (JAS_CAST(fix_t, 1) << ((fracbits) - 1))
+
+/******************************************************************************\
+* Conversion operations.
+\******************************************************************************/
+
+/* Convert an int to a fixed-point number. */
+#define JAS_INTTOFIX(fix_t, fracbits, x) \
+ JAS_CAST(fix_t, (x) << (fracbits))
+
+/* Convert a fixed-point number to an int. */
+#define JAS_FIXTOINT(fix_t, fracbits, x) \
+ JAS_CAST(int, (x) >> (fracbits))
+
+/* Convert a fixed-point number to a double. */
+#define JAS_FIXTODBL(fix_t, fracbits, x) \
+ (JAS_CAST(double, x) / (JAS_CAST(fix_t, 1) << (fracbits)))
+
+/* Convert a double to a fixed-point number. */
+#define JAS_DBLTOFIX(fix_t, fracbits, x) \
+ JAS_CAST(fix_t, ((x) * JAS_CAST(double, JAS_CAST(fix_t, 1) << (fracbits))))
+
+/******************************************************************************\
+* Basic arithmetic operations.
+* All other arithmetic operations are synthesized from these basic operations.
+* There are three macros for each type of arithmetic operation.
+* One macro always performs overflow/underflow checking, one never performs
+* overflow/underflow checking, and one is generic with its behavior
+* depending on compile-time flags.
+* Only the generic macros should be invoked directly by application code.
+\******************************************************************************/
+
+/* Calculate the sum of two fixed-point numbers. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_ADD JAS_FIX_ADD_FAST
+#else
+#define JAS_FIX_ADD JAS_FIX_ADD_OFLOW
+#endif
+
+/* Calculate the sum of two fixed-point numbers without overflow checking. */
+#define JAS_FIX_ADD_FAST(fix_t, fracbits, x, y) ((x) + (y))
+
+/* Calculate the sum of two fixed-point numbers with overflow checking. */
+#define JAS_FIX_ADD_OFLOW(fix_t, fracbits, x, y) \
+ ((x) >= 0) ? \
+ (((y) >= 0) ? ((x) + (y) >= 0 || JAS_FIX_OFLOW(), (x) + (y)) : \
+ ((x) + (y))) : \
+ (((y) >= 0) ? ((x) + (y)) : ((x) + (y) < 0 || JAS_FIX_OFLOW(), \
+ (x) + (y)))
+
+/* Calculate the product of two fixed-point numbers. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_MUL JAS_FIX_MUL_FAST
+#else
+#define JAS_FIX_MUL JAS_FIX_MUL_OFLOW
+#endif
+
+/* Calculate the product of two fixed-point numbers without overflow
+ checking. */
+#define JAS_FIX_MUL_FAST(fix_t, fracbits, bigfix_t, x, y) \
+ JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y)) >> \
+ (fracbits))
+
+/* Calculate the product of two fixed-point numbers with overflow
+ checking. */
+#define JAS_FIX_MUL_OFLOW(fix_t, fracbits, bigfix_t, x, y) \
+ ((JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> (fracbits)) == \
+ JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
+ (fracbits))) ? \
+ JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
+ (fracbits))) : JAS_FIX_OFLOW())
+
+/* Calculate the product of a fixed-point number and an int. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_FAST
+#else
+#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_OFLOW
+#endif
+
+/* Calculate the product of a fixed-point number and an int without overflow
+ checking. */
+#define JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y) \
+ JAS_CAST(fix_t, ((x) * (y)))
+
+/* Calculate the product of a fixed-point number and an int with overflow
+ checking. */
+#define JAS_FIX_MULBYINT_OFLOW(fix_t, fracbits, x, y) \
+ JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y)
+
+/* Calculate the quotient of two fixed-point numbers. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_DIV JAS_FIX_DIV_FAST
+#else
+#define JAS_FIX_DIV JAS_FIX_DIV_UFLOW
+#endif
+
+/* Calculate the quotient of two fixed-point numbers without underflow
+ checking. */
+#define JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y) \
+ JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) << (fracbits)) / (y))
+
+/* Calculate the quotient of two fixed-point numbers with underflow
+ checking. */
+#define JAS_FIX_DIV_UFLOW(fix_t, fracbits, bigfix_t, x, y) \
+ JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y)
+
+/* Negate a fixed-point number. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_NEG JAS_FIX_NEG_FAST
+#else
+#define JAS_FIX_NEG JAS_FIX_NEG_OFLOW
+#endif
+
+/* Negate a fixed-point number without overflow checking. */
+#define JAS_FIX_NEG_FAST(fix_t, fracbits, x) \
+ (-(x))
+
+/* Negate a fixed-point number with overflow checking. */
+/* Yes, overflow is actually possible for two's complement representations,
+ although highly unlikely to occur. */
+#define JAS_FIX_NEG_OFLOW(fix_t, fracbits, x) \
+ (((x) < 0) ? (-(x) > 0 || JAS_FIX_OFLOW(), -(x)) : (-(x)))
+
+/* Perform an arithmetic shift left of a fixed-point number. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_ASL JAS_FIX_ASL_FAST
+#else
+#define JAS_FIX_ASL JAS_FIX_ASL_OFLOW
+#endif
+
+/* Perform an arithmetic shift left of a fixed-point number without overflow
+ checking. */
+#define JAS_FIX_ASL_FAST(fix_t, fracbits, x, n) \
+ ((x) << (n))
+
+/* Perform an arithmetic shift left of a fixed-point number with overflow
+ checking. */
+#define JAS_FIX_ASL_OFLOW(fix_t, fracbits, x, n) \
+ ((((x) << (n)) >> (n)) == (x) || JAS_FIX_OFLOW(), (x) << (n))
+
+/* Perform an arithmetic shift right of a fixed-point number. */
+#if !defined(DEBUG_OVERFLOW)
+#define JAS_FIX_ASR JAS_FIX_ASR_FAST
+#else
+#define JAS_FIX_ASR JAS_FIX_ASR_UFLOW
+#endif
+
+/* Perform an arithmetic shift right of a fixed-point number without underflow
+ checking. */
+#define JAS_FIX_ASR_FAST(fix_t, fracbits, x, n) \
+ ((x) >> (n))
+
+/* Perform an arithmetic shift right of a fixed-point number with underflow
+ checking. */
+#define JAS_FIX_ASR_UFLOW(fix_t, fracbits, x, n) \
+ JAS_FIX_ASR_FAST(fix_t, fracbits, x, n)
+
+/******************************************************************************\
+* Other basic arithmetic operations.
+\******************************************************************************/
+
+/* Calculate the difference between two fixed-point numbers. */
+#define JAS_FIX_SUB(fix_t, fracbits, x, y) \
+ JAS_FIX_ADD(fix_t, fracbits, x, JAS_FIX_NEG(fix_t, fracbits, y))
+
+/* Add one fixed-point number to another. */
+#define JAS_FIX_PLUSEQ(fix_t, fracbits, x, y) \
+ ((x) = JAS_FIX_ADD(fix_t, fracbits, x, y))
+
+/* Subtract one fixed-point number from another. */
+#define JAS_FIX_MINUSEQ(fix_t, fracbits, x, y) \
+ ((x) = JAS_FIX_SUB(fix_t, fracbits, x, y))
+
+/* Multiply one fixed-point number by another. */
+#define JAS_FIX_MULEQ(fix_t, fracbits, bigfix_t, x, y) \
+ ((x) = JAS_FIX_MUL(fix_t, fracbits, bigfix_t, x, y))
+
+/******************************************************************************\
+* Miscellaneous operations.
+\******************************************************************************/
+
+/* Calculate the absolute value of a fixed-point number. */
+#define JAS_FIX_ABS(fix_t, fracbits, x) \
+ (((x) >= 0) ? (x) : (JAS_FIX_NEG(fix_t, fracbits, x)))
+
+/* Is a fixed-point number an integer? */
+#define JAS_FIX_ISINT(fix_t, fracbits, x) \
+ (JAS_FIX_FLOOR(fix_t, fracbits, x) == (x))
+
+/* Get the sign of a fixed-point number. */
+#define JAS_FIX_SGN(fix_t, fracbits, x) \
+ ((x) >= 0 ? 1 : (-1))
+
+/******************************************************************************\
+* Relational operations.
+\******************************************************************************/
+
+/* Compare two fixed-point numbers. */
+#define JAS_FIX_CMP(fix_t, fracbits, x, y) \
+ ((x) > (y) ? 1 : (((x) == (y)) ? 0 : (-1)))
+
+/* Less than. */
+#define JAS_FIX_LT(fix_t, fracbits, x, y) \
+ ((x) < (y))
+
+/* Less than or equal. */
+#define JAS_FIX_LTE(fix_t, fracbits, x, y) \
+ ((x) <= (y))
+
+/* Greater than. */
+#define JAS_FIX_GT(fix_t, fracbits, x, y) \
+ ((x) > (y))
+
+/* Greater than or equal. */
+#define JAS_FIX_GTE(fix_t, fracbits, x, y) \
+ ((x) >= (y))
+
+/******************************************************************************\
+* Rounding functions.
+\******************************************************************************/
+
+/* Round a fixed-point number to the nearest integer. */
+#define JAS_FIX_ROUND(fix_t, fracbits, x) \
+ (((x) < 0) ? JAS_FIX_FLOOR(fix_t, fracbits, JAS_FIX_ADD(fix_t, fracbits, \
+ (x), JAS_FIX_HALF(fix_t, fracbits))) : \
+ JAS_FIX_NEG(fix_t, fracbits, JAS_FIX_FLOOR(fix_t, fracbits, \
+ JAS_FIX_ADD(fix_t, fracbits, (-(x)), JAS_FIX_HALF(fix_t, fracbits)))))
+
+/* Round a fixed-point number to the nearest integer in the direction of
+ negative infinity (i.e., the floor function). */
+#define JAS_FIX_FLOOR(fix_t, fracbits, x) \
+ ((x) & (~((JAS_CAST(fix_t, 1) << (fracbits)) - 1)))
+
+/* Round a fixed-point number to the nearest integer in the direction
+ of zero. */
+#define JAS_FIX_TRUNC(fix_t, fracbits, x) \
+ (((x) >= 0) ? JAS_FIX_FLOOR(fix_t, fracbits, x) : \
+ JAS_FIX_CEIL(fix_t, fracbits, x))
+
+/******************************************************************************\
+* The below macros are for internal library use only. Do not invoke them
+* directly in application code.
+\******************************************************************************/
+
+/* Handle overflow. */
+#define JAS_FIX_OFLOW() \
+ fprintf(stderr, "overflow error: file %s, line %d\n", __FILE__, __LINE__)
+
+/* Handle underflow. */
+#define JAS_FIX_UFLOW() \
+ fprintf(stderr, "underflow error: file %s, line %d\n", __FILE__, __LINE__)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_getopt.c b/osframework/source/ImageLib/jpeg2000/jas_getopt.c
new file mode 100644
index 0000000..2af30a0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_getopt.c
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 1999-2000, Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Command Line Option Parsing Library
+ *
+ * $Id: jas_getopt.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+
+#include "jas_getopt.h"
+#include "jas_math.h"
+
+/******************************************************************************\
+* Global data.
+\******************************************************************************/
+
+int jas_optind = 0;
+int jas_opterr = 1;
+char *jas_optarg = 0;
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+static jas_opt_t *jas_optlookup(jas_opt_t *opts, char *name)
+{
+ jas_opt_t *opt;
+
+ for (opt = opts; opt->id >= 0 && opt->name; ++opt) {
+ if (!strcmp(opt->name, name)) {
+ return opt;
+ }
+ }
+ return 0;
+}
+
+int jas_getopt(int argc, char **argv, jas_opt_t *opts)
+{
+ char *cp;
+ int id;
+ int hasarg;
+ jas_opt_t *opt;
+ char *s;
+
+ if (!jas_optind) {
+ jas_optind = JAS_MIN(1, argc);
+ }
+ while (jas_optind < argc) {
+ s = cp = argv[jas_optind];
+ if (*cp == '-') {
+ /* We are processing an option. */
+ ++jas_optind;
+ if (*++cp == '-') {
+ /* We are processing a long option. */
+ ++cp;
+ if (*cp == '\0') {
+ /* This is the end of the options. */
+ return JAS_GETOPT_EOF;
+ }
+ if (!(opt = jas_optlookup(opts, cp))) {
+ if (jas_opterr) {
+ fprintf(stderr, "unknown long option %s\n", s);
+ }
+ return JAS_GETOPT_ERR;
+ }
+ hasarg = (opt->flags & JAS_OPT_HASARG) != 0;
+ id = opt->id;
+ } else {
+ /* We are processing a short option. */
+ if (strlen(cp) != 1 ||
+ !(opt = jas_optlookup(opts, cp))) {
+ if (jas_opterr) {
+ fprintf(stderr, "unknown short option %s\n", s);
+ }
+ return JAS_GETOPT_ERR;
+ }
+ hasarg = (opt->flags & JAS_OPT_HASARG) != 0;
+ id = opt->id;
+ }
+ if (hasarg) {
+ /* The option has an argument. */
+ if (jas_optind >= argc) {
+ if (jas_opterr) {
+ fprintf(stderr, "missing argument for option %s\n", s);
+ }
+ return JAS_GETOPT_ERR;
+ }
+ jas_optarg = argv[jas_optind];
+ ++jas_optind;
+ } else {
+ /* The option does not have an argument. */
+ jas_optarg = 0;
+ }
+ return id;
+ } else {
+ /* We are not processing an option. */
+ return JAS_GETOPT_EOF;
+ }
+ }
+ return JAS_GETOPT_EOF;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_getopt.h b/osframework/source/ImageLib/jpeg2000/jas_getopt.h
new file mode 100644
index 0000000..baaf3d6
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_getopt.h
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Command Line Option Parsing Code
+ *
+ * $Id: jas_getopt.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_GETOPT_H
+#define JAS_GETOPT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "jas_config.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+#define JAS_GETOPT_EOF (-1)
+#define JAS_GETOPT_ERR '?'
+
+/* option flags. */
+#define JAS_OPT_HASARG 0x01 /* option has argument */
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Command line option type. */
+typedef struct {
+
+ int id;
+ /* The unique identifier for this option. */
+
+ char *name;
+ /* The name of this option. */
+
+ int flags;
+ /* option flags. */
+
+} jas_opt_t;
+
+/******************************************************************************\
+* External data.
+\******************************************************************************/
+
+/* The current option index. */
+extern int jas_optind;
+
+/* The current option argument. */
+extern char *jas_optarg;
+
+/* The debug level. */
+extern int jas_opterr;
+
+/******************************************************************************\
+* Prototypes.
+\******************************************************************************/
+
+/* Get the next option. */
+int jas_getopt(int argc, char **argv, jas_opt_t *opts);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_icc.c b/osframework/source/ImageLib/jpeg2000/jas_icc.c
new file mode 100644
index 0000000..efafe34
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_icc.c
@@ -0,0 +1,1770 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#include <assert.h>
+#include "jas_config.h"
+#include "jas_types.h"
+#include "jas_malloc.h"
+#include "jas_debug.h"
+#include "jas_icc.h"
+#include "jas_cm.h"
+#include "jas_stream.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+
+#define jas_iccputuint8(out, val) jas_iccputuint(out, 1, val)
+#define jas_iccputuint16(out, val) jas_iccputuint(out, 2, val)
+#define jas_iccputsint32(out, val) jas_iccputsint(out, 4, val)
+#define jas_iccputuint32(out, val) jas_iccputuint(out, 4, val)
+#define jas_iccputuint64(out, val) jas_iccputuint(out, 8, val)
+
+static jas_iccattrval_t *jas_iccattrval_create0(void);
+
+static int jas_iccgetuint(jas_stream_t *in, int n, ulonglong *val);
+static int jas_iccgetuint8(jas_stream_t *in, jas_iccuint8_t *val);
+static int jas_iccgetuint16(jas_stream_t *in, jas_iccuint16_t *val);
+static int jas_iccgetsint32(jas_stream_t *in, jas_iccsint32_t *val);
+static int jas_iccgetuint32(jas_stream_t *in, jas_iccuint32_t *val);
+static int jas_iccgetuint64(jas_stream_t *in, jas_iccuint64_t *val);
+static int jas_iccputuint(jas_stream_t *out, int n, ulonglong val);
+static int jas_iccputsint(jas_stream_t *out, int n, longlong val);
+static jas_iccprof_t *jas_iccprof_create(void);
+static int jas_iccprof_readhdr(jas_stream_t *in, jas_icchdr_t *hdr);
+static int jas_iccprof_writehdr(jas_stream_t *out, jas_icchdr_t *hdr);
+static int jas_iccprof_gettagtab(jas_stream_t *in, jas_icctagtab_t *tagtab);
+static void jas_iccprof_sorttagtab(jas_icctagtab_t *tagtab);
+static int jas_iccattrtab_lookup(jas_iccattrtab_t *attrtab, jas_iccuint32_t name);
+static jas_iccattrtab_t *jas_iccattrtab_copy(jas_iccattrtab_t *attrtab);
+static jas_iccattrvalinfo_t *jas_iccattrvalinfo_lookup(jas_iccsig_t name);
+static int jas_iccgettime(jas_stream_t *in, jas_icctime_t *time);
+static int jas_iccgetxyz(jas_stream_t *in, jas_iccxyz_t *xyz);
+static int jas_icctagtabent_cmp(const void *src, const void *dst);
+
+static void jas_icccurv_destroy(jas_iccattrval_t *attrval);
+static int jas_icccurv_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval);
+static int jas_icccurv_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_icccurv_getsize(jas_iccattrval_t *attrval);
+static int jas_icccurv_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_icccurv_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static void jas_icctxtdesc_destroy(jas_iccattrval_t *attrval);
+static int jas_icctxtdesc_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval);
+static int jas_icctxtdesc_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_icctxtdesc_getsize(jas_iccattrval_t *attrval);
+static int jas_icctxtdesc_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_icctxtdesc_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static void jas_icctxt_destroy(jas_iccattrval_t *attrval);
+static int jas_icctxt_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval);
+static int jas_icctxt_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_icctxt_getsize(jas_iccattrval_t *attrval);
+static int jas_icctxt_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_icctxt_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static int jas_iccxyz_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_iccxyz_getsize(jas_iccattrval_t *attrval);
+static int jas_iccxyz_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_iccxyz_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static jas_iccattrtab_t *jas_iccattrtab_create(void);
+static void jas_iccattrtab_destroy(jas_iccattrtab_t *tab);
+static int jas_iccattrtab_resize(jas_iccattrtab_t *tab, int maxents);
+static int jas_iccattrtab_add(jas_iccattrtab_t *attrtab, int i,
+ jas_iccuint32_t name, jas_iccattrval_t *val);
+static int jas_iccattrtab_replace(jas_iccattrtab_t *attrtab, int i,
+ jas_iccuint32_t name, jas_iccattrval_t *val);
+static void jas_iccattrtab_delete(jas_iccattrtab_t *attrtab, int i);
+static long jas_iccpadtomult(long x, long y);
+static int jas_iccattrtab_get(jas_iccattrtab_t *attrtab, int i,
+ jas_iccattrname_t *name, jas_iccattrval_t **val);
+static int jas_iccprof_puttagtab(jas_stream_t *out, jas_icctagtab_t *tagtab);
+
+static void jas_icclut16_destroy(jas_iccattrval_t *attrval);
+static int jas_icclut16_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval);
+static int jas_icclut16_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_icclut16_getsize(jas_iccattrval_t *attrval);
+static int jas_icclut16_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_icclut16_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static void jas_icclut8_destroy(jas_iccattrval_t *attrval);
+static int jas_icclut8_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval);
+static int jas_icclut8_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt);
+static int jas_icclut8_getsize(jas_iccattrval_t *attrval);
+static int jas_icclut8_output(jas_iccattrval_t *attrval, jas_stream_t *out);
+static void jas_icclut8_dump(jas_iccattrval_t *attrval, FILE *out);
+
+static int jas_iccputtime(jas_stream_t *out, jas_icctime_t *ctime);
+static int jas_iccputxyz(jas_stream_t *out, jas_iccxyz_t *xyz);
+
+static long jas_iccpowi(int x, int n);
+
+static char *jas_iccsigtostr(int sig, char *buf);
+
+
+jas_iccattrvalinfo_t jas_iccattrvalinfos[] = {
+ {JAS_ICC_TYPE_CURV, {jas_icccurv_destroy, jas_icccurv_copy,
+ jas_icccurv_input, jas_icccurv_output, jas_icccurv_getsize,
+ jas_icccurv_dump}},
+ {JAS_ICC_TYPE_XYZ, {0, 0, jas_iccxyz_input, jas_iccxyz_output,
+ jas_iccxyz_getsize, jas_iccxyz_dump}},
+ {JAS_ICC_TYPE_TXTDESC, {jas_icctxtdesc_destroy,
+ jas_icctxtdesc_copy, jas_icctxtdesc_input, jas_icctxtdesc_output,
+ jas_icctxtdesc_getsize, jas_icctxtdesc_dump}},
+ {JAS_ICC_TYPE_TXT, {jas_icctxt_destroy, jas_icctxt_copy,
+ jas_icctxt_input, jas_icctxt_output, jas_icctxt_getsize,
+ jas_icctxt_dump}},
+ {JAS_ICC_TYPE_LUT8, {jas_icclut8_destroy, jas_icclut8_copy,
+ jas_icclut8_input, jas_icclut8_output, jas_icclut8_getsize,
+ jas_icclut8_dump}},
+ {JAS_ICC_TYPE_LUT16, {jas_icclut16_destroy, jas_icclut16_copy,
+ jas_icclut16_input, jas_icclut16_output, jas_icclut16_getsize,
+ jas_icclut16_dump}},
+ {0, {0, 0, 0, 0, 0, 0}}
+};
+
+typedef struct {
+ jas_iccuint32_t tag;
+ char *name;
+} jas_icctaginfo_t;
+
+/******************************************************************************\
+* profile class
+\******************************************************************************/
+
+static jas_iccprof_t *jas_iccprof_create()
+{
+ jas_iccprof_t *prof;
+ prof = 0;
+ if (!(prof = jas_malloc(sizeof(jas_iccprof_t)))) {
+ goto error;
+ }
+ if (!(prof->attrtab = jas_iccattrtab_create()))
+ goto error;
+ memset(&prof->hdr, 0, sizeof(jas_icchdr_t));
+ prof->tagtab.numents = 0;
+ prof->tagtab.ents = 0;
+ return prof;
+error:
+ if (prof)
+ jas_iccprof_destroy(prof);
+ return 0;
+}
+
+jas_iccprof_t *jas_iccprof_copy(jas_iccprof_t *prof)
+{
+ jas_iccprof_t *newprof;
+ newprof = 0;
+ if (!(newprof = jas_iccprof_create()))
+ goto error;
+ newprof->hdr = prof->hdr;
+ newprof->tagtab.numents = 0;
+ newprof->tagtab.ents = 0;
+ assert(newprof->attrtab);
+ jas_iccattrtab_destroy(newprof->attrtab);
+ if (!(newprof->attrtab = jas_iccattrtab_copy(prof->attrtab)))
+ goto error;
+ return newprof;
+error:
+ if (newprof)
+ jas_iccprof_destroy(newprof);
+ return 0;
+}
+
+void jas_iccprof_destroy(jas_iccprof_t *prof)
+{
+ if (prof->attrtab)
+ jas_iccattrtab_destroy(prof->attrtab);
+ if (prof->tagtab.ents)
+ jas_free(prof->tagtab.ents);
+ jas_free(prof);
+}
+
+void jas_iccprof_dump(jas_iccprof_t *prof, FILE *out)
+{
+ jas_iccattrtab_dump(prof->attrtab, out);
+}
+
+jas_iccprof_t *jas_iccprof_load(jas_stream_t *in)
+{
+ jas_iccprof_t *prof;
+ int numtags;
+ long curoff;
+ long reloff;
+ long prevoff;
+ jas_iccsig_t type;
+ jas_iccattrval_t *attrval;
+ jas_iccattrval_t *prevattrval;
+ jas_icctagtabent_t *tagtabent;
+ jas_iccattrvalinfo_t *attrvalinfo;
+ int i;
+ int len;
+
+ prof = 0;
+ attrval = 0;
+
+ if (!(prof = jas_iccprof_create())) {
+ goto error;
+ }
+
+ if (jas_iccprof_readhdr(in, &prof->hdr)) {
+ jas_eprintf("cannot get header\n");
+ goto error;
+ }
+ if (jas_iccprof_gettagtab(in, &prof->tagtab)) {
+ jas_eprintf("cannot get tab table\n");
+ goto error;
+ }
+ jas_iccprof_sorttagtab(&prof->tagtab);
+
+ numtags = prof->tagtab.numents;
+ curoff = JAS_ICC_HDRLEN + 4 + 12 * numtags;
+ prevoff = 0;
+ prevattrval = 0;
+ for (i = 0; i < numtags; ++i) {
+ tagtabent = &prof->tagtab.ents[i];
+ if (tagtabent->off == JAS_CAST(jas_iccuint32_t, prevoff)) {
+ if (prevattrval) {
+ if (!(attrval = jas_iccattrval_clone(prevattrval)))
+ goto error;
+ if (jas_iccprof_setattr(prof, tagtabent->tag, attrval))
+ goto error;
+ jas_iccattrval_destroy(attrval);
+ } else {
+#if 0
+ jas_eprintf("warning: skipping unknown tag type\n");
+#endif
+ }
+ continue;
+ }
+ reloff = tagtabent->off - curoff;
+ if (reloff > 0) {
+ if (jas_stream_gobble(in, reloff) != reloff)
+ goto error;
+ curoff += reloff;
+ } else if (reloff < 0) {
+ /* This should never happen since we read the tagged
+ element data in a single pass. */
+ abort();
+ }
+ prevoff = curoff;
+ if (jas_iccgetuint32(in, &type)) {
+ goto error;
+ }
+ if (jas_stream_gobble(in, 4) != 4) {
+ goto error;
+ }
+ curoff += 8;
+ if (!(attrvalinfo = jas_iccattrvalinfo_lookup(type))) {
+#if 0
+ jas_eprintf("warning: skipping unknown tag type\n");
+#endif
+ prevattrval = 0;
+ continue;
+ }
+ if (!(attrval = jas_iccattrval_create(type))) {
+ goto error;
+ }
+ len = tagtabent->len - 8;
+ if ((*attrval->ops->input)(attrval, in, len)) {
+ goto error;
+ }
+ curoff += len;
+ if (jas_iccprof_setattr(prof, tagtabent->tag, attrval)) {
+ goto error;
+ }
+ prevattrval = attrval; /* This is correct, but slimey. */
+ jas_iccattrval_destroy(attrval);
+ attrval = 0;
+ }
+
+ return prof;
+
+error:
+ if (prof)
+ jas_iccprof_destroy(prof);
+ if (attrval)
+ jas_iccattrval_destroy(attrval);
+ return 0;
+}
+
+int jas_iccprof_save(jas_iccprof_t *prof, jas_stream_t *out)
+{
+ long curoff;
+ long reloff;
+ long newoff;
+ int i;
+ int j;
+ jas_icctagtabent_t *tagtabent;
+ jas_icctagtabent_t *sharedtagtabent;
+ jas_icctagtabent_t *tmptagtabent;
+ jas_iccuint32_t attrname;
+ jas_iccattrval_t *attrval;
+ jas_icctagtab_t *tagtab;
+
+ tagtab = &prof->tagtab;
+ if (!(tagtab->ents = jas_malloc(prof->attrtab->numattrs *
+ sizeof(jas_icctagtabent_t))))
+ goto error;
+ tagtab->numents = prof->attrtab->numattrs;
+ curoff = JAS_ICC_HDRLEN + 4 + 12 * tagtab->numents;
+ for (i = 0; i < JAS_CAST(int, tagtab->numents); ++i) {
+ tagtabent = &tagtab->ents[i];
+ if (jas_iccattrtab_get(prof->attrtab, i, &attrname, &attrval))
+ goto error;
+ assert(attrval->ops->output);
+ tagtabent->tag = attrname;
+ tagtabent->data = &attrval->data;
+ sharedtagtabent = 0;
+ for (j = 0; j < i; ++j) {
+ tmptagtabent = &tagtab->ents[j];
+ if (tagtabent->data == tmptagtabent->data) {
+ sharedtagtabent = tmptagtabent;
+ break;
+ }
+ }
+ if (sharedtagtabent) {
+ tagtabent->off = sharedtagtabent->off;
+ tagtabent->len = sharedtagtabent->len;
+ tagtabent->first = sharedtagtabent;
+ } else {
+ tagtabent->off = curoff;
+ tagtabent->len = (*attrval->ops->getsize)(attrval) + 8;
+ tagtabent->first = 0;
+ if (i < JAS_CAST(int, tagtab->numents - 1)) {
+ curoff = jas_iccpadtomult(curoff + tagtabent->len, 4);
+ } else {
+ curoff += tagtabent->len;
+ }
+ }
+ jas_iccattrval_destroy(attrval);
+ }
+ prof->hdr.size = curoff;
+ if (jas_iccprof_writehdr(out, &prof->hdr))
+ goto error;
+ if (jas_iccprof_puttagtab(out, &prof->tagtab))
+ goto error;
+ curoff = JAS_ICC_HDRLEN + 4 + 12 * tagtab->numents;
+ for (i = 0; i < JAS_CAST(int, tagtab->numents);) {
+ tagtabent = &tagtab->ents[i];
+ assert(curoff == JAS_CAST(long, tagtabent->off));
+ if (jas_iccattrtab_get(prof->attrtab, i, &attrname, &attrval))
+ goto error;
+ if (jas_iccputuint32(out, attrval->type) || jas_stream_pad(out,
+ 4, 0) != 4)
+ goto error;
+ if ((*attrval->ops->output)(attrval, out))
+ goto error;
+ jas_iccattrval_destroy(attrval);
+ curoff += tagtabent->len;
+ ++i;
+ while (i < JAS_CAST(int, tagtab->numents) &&
+ tagtab->ents[i].first)
+ ++i;
+ newoff = (i < JAS_CAST(int, tagtab->numents)) ?
+ tagtab->ents[i].off : prof->hdr.size;
+ reloff = newoff - curoff;
+ assert(reloff >= 0);
+ if (reloff > 0) {
+ if (jas_stream_pad(out, reloff, 0) != reloff)
+ goto error;
+ curoff += reloff;
+ }
+ }
+ return 0;
+error:
+ /* XXX - need to free some resources here */
+ return -1;
+}
+
+static int jas_iccprof_writehdr(jas_stream_t *out, jas_icchdr_t *hdr)
+{
+ if (jas_iccputuint32(out, hdr->size) ||
+ jas_iccputuint32(out, hdr->cmmtype) ||
+ jas_iccputuint32(out, hdr->version) ||
+ jas_iccputuint32(out, hdr->clas) ||
+ jas_iccputuint32(out, hdr->colorspc) ||
+ jas_iccputuint32(out, hdr->refcolorspc) ||
+ jas_iccputtime(out, &hdr->ctime) ||
+ jas_iccputuint32(out, hdr->magic) ||
+ jas_iccputuint32(out, hdr->platform) ||
+ jas_iccputuint32(out, hdr->flags) ||
+ jas_iccputuint32(out, hdr->maker) ||
+ jas_iccputuint32(out, hdr->model) ||
+ jas_iccputuint64(out, hdr->attr) ||
+ jas_iccputuint32(out, hdr->intent) ||
+ jas_iccputxyz(out, &hdr->illum) ||
+ jas_iccputuint32(out, hdr->creator) ||
+ jas_stream_pad(out, 44, 0) != 44)
+ return -1;
+ return 0;
+}
+
+static int jas_iccprof_puttagtab(jas_stream_t *out, jas_icctagtab_t *tagtab)
+{
+ int i;
+ jas_icctagtabent_t *tagtabent;
+ if (jas_iccputuint32(out, tagtab->numents))
+ goto error;
+ for (i = 0; i < JAS_CAST(int, tagtab->numents); ++i) {
+ tagtabent = &tagtab->ents[i];
+ if (jas_iccputuint32(out, tagtabent->tag) ||
+ jas_iccputuint32(out, tagtabent->off) ||
+ jas_iccputuint32(out, tagtabent->len))
+ goto error;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static int jas_iccprof_readhdr(jas_stream_t *in, jas_icchdr_t *hdr)
+{
+ if (jas_iccgetuint32(in, &hdr->size) ||
+ jas_iccgetuint32(in, &hdr->cmmtype) ||
+ jas_iccgetuint32(in, &hdr->version) ||
+ jas_iccgetuint32(in, &hdr->clas) ||
+ jas_iccgetuint32(in, &hdr->colorspc) ||
+ jas_iccgetuint32(in, &hdr->refcolorspc) ||
+ jas_iccgettime(in, &hdr->ctime) ||
+ jas_iccgetuint32(in, &hdr->magic) ||
+ jas_iccgetuint32(in, &hdr->platform) ||
+ jas_iccgetuint32(in, &hdr->flags) ||
+ jas_iccgetuint32(in, &hdr->maker) ||
+ jas_iccgetuint32(in, &hdr->model) ||
+ jas_iccgetuint64(in, &hdr->attr) ||
+ jas_iccgetuint32(in, &hdr->intent) ||
+ jas_iccgetxyz(in, &hdr->illum) ||
+ jas_iccgetuint32(in, &hdr->creator) ||
+ jas_stream_gobble(in, 44) != 44)
+ return -1;
+ return 0;
+}
+
+static int jas_iccprof_gettagtab(jas_stream_t *in, jas_icctagtab_t *tagtab)
+{
+ int i;
+ jas_icctagtabent_t *tagtabent;
+
+ if (tagtab->ents) {
+ jas_free(tagtab->ents);
+ tagtab->ents = 0;
+ }
+ if (jas_iccgetuint32(in, &tagtab->numents))
+ goto error;
+ if (!(tagtab->ents = jas_malloc(tagtab->numents *
+ sizeof(jas_icctagtabent_t))))
+ goto error;
+ tagtabent = tagtab->ents;
+ for (i = 0; i < JAS_CAST(long, tagtab->numents); ++i) {
+ if (jas_iccgetuint32(in, &tagtabent->tag) ||
+ jas_iccgetuint32(in, &tagtabent->off) ||
+ jas_iccgetuint32(in, &tagtabent->len))
+ goto error;
+ ++tagtabent;
+ }
+ return 0;
+error:
+ if (tagtab->ents) {
+ jas_free(tagtab->ents);
+ tagtab->ents = 0;
+ }
+ return -1;
+}
+
+jas_iccattrval_t *jas_iccprof_getattr(jas_iccprof_t *prof,
+ jas_iccattrname_t name)
+{
+ int i;
+ jas_iccattrval_t *attrval;
+ if ((i = jas_iccattrtab_lookup(prof->attrtab, name)) < 0)
+ goto error;
+ if (!(attrval = jas_iccattrval_clone(prof->attrtab->attrs[i].val)))
+ goto error;
+ return attrval;
+error:
+ return 0;
+}
+
+int jas_iccprof_setattr(jas_iccprof_t *prof, jas_iccattrname_t name,
+ jas_iccattrval_t *val)
+{
+ int i;
+ if ((i = jas_iccattrtab_lookup(prof->attrtab, name)) >= 0) {
+ if (val) {
+ if (jas_iccattrtab_replace(prof->attrtab, i, name, val))
+ goto error;
+ } else {
+ jas_iccattrtab_delete(prof->attrtab, i);
+ }
+ } else {
+ if (val) {
+ if (jas_iccattrtab_add(prof->attrtab, -1, name, val))
+ goto error;
+ } else {
+ /* NOP */
+ }
+ }
+ return 0;
+error:
+ return -1;
+}
+
+int jas_iccprof_gethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr)
+{
+ *hdr = prof->hdr;
+ return 0;
+}
+
+int jas_iccprof_sethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr)
+{
+ prof->hdr = *hdr;
+ return 0;
+}
+
+static void jas_iccprof_sorttagtab(jas_icctagtab_t *tagtab)
+{
+ qsort(tagtab->ents, tagtab->numents, sizeof(jas_icctagtabent_t),
+ jas_icctagtabent_cmp);
+}
+
+static int jas_icctagtabent_cmp(const void *src, const void *dst)
+{
+ jas_icctagtabent_t *srctagtabent = JAS_CAST(jas_icctagtabent_t *, src);
+ jas_icctagtabent_t *dsttagtabent = JAS_CAST(jas_icctagtabent_t *, dst);
+ if (srctagtabent->off > dsttagtabent->off) {
+ return 1;
+ } else if (srctagtabent->off < dsttagtabent->off) {
+ return -1;
+ }
+ return 0;
+}
+
+static jas_iccattrvalinfo_t *jas_iccattrvalinfo_lookup(jas_iccsig_t type)
+{
+ jas_iccattrvalinfo_t *info;
+ info = jas_iccattrvalinfos;
+ for (info = jas_iccattrvalinfos; info->type; ++info) {
+ if (info->type == type) {
+ return info;
+ }
+ }
+ return 0;
+}
+
+static int jas_iccgettime(jas_stream_t *in, jas_icctime_t *time)
+{
+ if (jas_iccgetuint16(in, &time->year) ||
+ jas_iccgetuint16(in, &time->month) ||
+ jas_iccgetuint16(in, &time->day) ||
+ jas_iccgetuint16(in, &time->hour) ||
+ jas_iccgetuint16(in, &time->min) ||
+ jas_iccgetuint16(in, &time->sec)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jas_iccgetxyz(jas_stream_t *in, jas_iccxyz_t *xyz)
+{
+ if (jas_iccgetsint32(in, &xyz->x) ||
+ jas_iccgetsint32(in, &xyz->y) ||
+ jas_iccgetsint32(in, &xyz->z)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jas_iccputtime(jas_stream_t *out, jas_icctime_t *time)
+{
+ jas_iccputuint16(out, time->year);
+ jas_iccputuint16(out, time->month);
+ jas_iccputuint16(out, time->day);
+ jas_iccputuint16(out, time->hour);
+ jas_iccputuint16(out, time->min);
+ jas_iccputuint16(out, time->sec);
+ return 0;
+}
+
+static int jas_iccputxyz(jas_stream_t *out, jas_iccxyz_t *xyz)
+{
+ jas_iccputuint32(out, xyz->x);
+ jas_iccputuint32(out, xyz->y);
+ jas_iccputuint32(out, xyz->z);
+ return 0;
+}
+
+/******************************************************************************\
+* attribute table class
+\******************************************************************************/
+
+static jas_iccattrtab_t *jas_iccattrtab_create()
+{
+ jas_iccattrtab_t *tab;
+ tab = 0;
+ if (!(tab = jas_malloc(sizeof(jas_iccattrtab_t))))
+ goto error;
+ tab->maxattrs = 0;
+ tab->numattrs = 0;
+ tab->attrs = 0;
+ if (jas_iccattrtab_resize(tab, 32))
+ goto error;
+ return tab;
+error:
+ if (tab)
+ jas_iccattrtab_destroy(tab);
+ return 0;
+}
+
+static jas_iccattrtab_t *jas_iccattrtab_copy(jas_iccattrtab_t *attrtab)
+{
+ jas_iccattrtab_t *newattrtab;
+ int i;
+ if (!(newattrtab = jas_iccattrtab_create()))
+ goto error;
+ for (i = 0; i < attrtab->numattrs; ++i) {
+ if (jas_iccattrtab_add(newattrtab, i, attrtab->attrs[i].name,
+ attrtab->attrs[i].val))
+ goto error;
+ }
+ return newattrtab;
+error:
+ return 0;
+}
+
+static void jas_iccattrtab_destroy(jas_iccattrtab_t *tab)
+{
+ if (tab->attrs) {
+ while (tab->numattrs > 0) {
+ jas_iccattrtab_delete(tab, 0);
+ }
+ jas_free(tab->attrs);
+ }
+ jas_free(tab);
+}
+
+void jas_iccattrtab_dump(jas_iccattrtab_t *attrtab, FILE *out)
+{
+ int i;
+ jas_iccattr_t *attr;
+ jas_iccattrval_t *attrval;
+ jas_iccattrvalinfo_t *info;
+ char buf[16];
+ fprintf(out, "numattrs=%d\n", attrtab->numattrs);
+ fprintf(out, "---\n");
+ for (i = 0; i < attrtab->numattrs; ++i) {
+ attr = &attrtab->attrs[i];
+ attrval = attr->val;
+ info = jas_iccattrvalinfo_lookup(attrval->type);
+ if (!info) abort();
+ fprintf(out, "attrno=%d; attrname=\"%s\"(0x%08x); attrtype=\"%s\"(0x%08x)\n",
+ i,
+ jas_iccsigtostr(attr->name, &buf[0]),
+ attr->name,
+ jas_iccsigtostr(attrval->type, &buf[8]),
+ attrval->type
+ );
+ jas_iccattrval_dump(attrval, out);
+ fprintf(out, "---\n");
+ }
+}
+
+static int jas_iccattrtab_resize(jas_iccattrtab_t *tab, int maxents)
+{
+ jas_iccattr_t *newattrs;
+ assert(maxents >= tab->numattrs);
+ newattrs = tab->attrs ? jas_realloc(tab->attrs, maxents *
+ sizeof(jas_iccattr_t)) : jas_malloc(maxents * sizeof(jas_iccattr_t));
+ if (!newattrs)
+ return -1;
+ tab->attrs = newattrs;
+ tab->maxattrs = maxents;
+ return 0;
+}
+
+static int jas_iccattrtab_add(jas_iccattrtab_t *attrtab, int i,
+ jas_iccuint32_t name, jas_iccattrval_t *val)
+{
+ int n;
+ jas_iccattr_t *attr;
+ jas_iccattrval_t *tmpattrval;
+ tmpattrval = 0;
+ if (i < 0) {
+ i = attrtab->numattrs;
+ }
+ assert(i >= 0 && i <= attrtab->numattrs);
+ if (attrtab->numattrs >= attrtab->maxattrs) {
+ if (jas_iccattrtab_resize(attrtab, attrtab->numattrs + 32)) {
+ goto error;
+ }
+ }
+ if (!(tmpattrval = jas_iccattrval_clone(val)))
+ goto error;
+ n = attrtab->numattrs - i;
+ if (n > 0)
+ memmove(&attrtab->attrs[i + 1], &attrtab->attrs[i],
+ n * sizeof(jas_iccattr_t));
+ attr = &attrtab->attrs[i];
+ attr->name = name;
+ attr->val = tmpattrval;
+ ++attrtab->numattrs;
+ return 0;
+error:
+ if (tmpattrval)
+ jas_iccattrval_destroy(tmpattrval);
+ return -1;
+}
+
+static int jas_iccattrtab_replace(jas_iccattrtab_t *attrtab, int i,
+ jas_iccuint32_t name, jas_iccattrval_t *val)
+{
+ jas_iccattrval_t *newval;
+ jas_iccattr_t *attr;
+ if (!(newval = jas_iccattrval_clone(val)))
+ goto error;
+ attr = &attrtab->attrs[i];
+ jas_iccattrval_destroy(attr->val);
+ attr->name = name;
+ attr->val = newval;
+ return 0;
+error:
+ return -1;
+}
+
+static void jas_iccattrtab_delete(jas_iccattrtab_t *attrtab, int i)
+{
+ int n;
+ jas_iccattrval_destroy(attrtab->attrs[i].val);
+ if ((n = attrtab->numattrs - i - 1) > 0)
+ memmove(&attrtab->attrs[i], &attrtab->attrs[i + 1],
+ n * sizeof(jas_iccattr_t));
+ --attrtab->numattrs;
+}
+
+static int jas_iccattrtab_get(jas_iccattrtab_t *attrtab, int i,
+ jas_iccattrname_t *name, jas_iccattrval_t **val)
+{
+ jas_iccattr_t *attr;
+ if (i < 0 || i >= attrtab->numattrs)
+ goto error;
+ attr = &attrtab->attrs[i];
+ *name = attr->name;
+ if (!(*val = jas_iccattrval_clone(attr->val)))
+ goto error;
+ return 0;
+error:
+ return -1;
+}
+
+static int jas_iccattrtab_lookup(jas_iccattrtab_t *attrtab,
+ jas_iccuint32_t name)
+{
+ int i;
+ jas_iccattr_t *attr;
+ for (i = 0; i < attrtab->numattrs; ++i) {
+ attr = &attrtab->attrs[i];
+ if (attr->name == name)
+ return i;
+ }
+ return -1;
+}
+
+/******************************************************************************\
+* attribute value class
+\******************************************************************************/
+
+jas_iccattrval_t *jas_iccattrval_create(jas_iccuint32_t type)
+{
+ jas_iccattrval_t *attrval;
+ jas_iccattrvalinfo_t *info;
+
+ if (!(info = jas_iccattrvalinfo_lookup(type)))
+ goto error;
+ if (!(attrval = jas_iccattrval_create0()))
+ goto error;
+ attrval->ops = &info->ops;
+ attrval->type = type;
+ ++attrval->refcnt;
+ memset(&attrval->data, 0, sizeof(attrval->data));
+ return attrval;
+error:
+ return 0;
+}
+
+jas_iccattrval_t *jas_iccattrval_clone(jas_iccattrval_t *attrval)
+{
+ ++attrval->refcnt;
+ return attrval;
+}
+
+void jas_iccattrval_destroy(jas_iccattrval_t *attrval)
+{
+#if 0
+fprintf(stderr, "refcnt=%d\n", attrval->refcnt);
+#endif
+ if (--attrval->refcnt <= 0) {
+ if (attrval->ops->destroy)
+ (*attrval->ops->destroy)(attrval);
+ jas_free(attrval);
+ }
+}
+
+void jas_iccattrval_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ char buf[8];
+ jas_iccsigtostr(attrval->type, buf);
+ fprintf(out, "refcnt = %d; type = 0x%08x %s\n", attrval->refcnt,
+ attrval->type, jas_iccsigtostr(attrval->type, &buf[0]));
+ if (attrval->ops->dump) {
+ (*attrval->ops->dump)(attrval, out);
+ }
+}
+
+int jas_iccattrval_allowmodify(jas_iccattrval_t **attrvalx)
+{
+ jas_iccattrval_t *newattrval;
+ jas_iccattrval_t *attrval = *attrvalx;
+ newattrval = 0;
+ if (attrval->refcnt > 1) {
+ if (!(newattrval = jas_iccattrval_create0()))
+ goto error;
+ newattrval->ops = attrval->ops;
+ newattrval->type = attrval->type;
+ ++newattrval->refcnt;
+ if (newattrval->ops->copy) {
+ if ((*newattrval->ops->copy)(newattrval, attrval))
+ goto error;
+ } else {
+ memcpy(&newattrval->data, &attrval->data,
+ sizeof(newattrval->data));
+ }
+ *attrvalx = newattrval;
+ }
+ return 0;
+error:
+ if (newattrval) {
+ jas_free(newattrval);
+ }
+ return -1;
+}
+
+static jas_iccattrval_t *jas_iccattrval_create0()
+{
+ jas_iccattrval_t *attrval;
+ if (!(attrval = jas_malloc(sizeof(jas_iccattrval_t))))
+ return 0;
+ memset(attrval, 0, sizeof(jas_iccattrval_t));
+ attrval->refcnt = 0;
+ attrval->ops = 0;
+ attrval->type = 0;
+ return attrval;
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static int jas_iccxyz_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int len)
+{
+ if (len != 4 * 3) abort();
+ return jas_iccgetxyz(in, &attrval->data.xyz);
+}
+
+static int jas_iccxyz_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_iccxyz_t *xyz = &attrval->data.xyz;
+ if (jas_iccputuint32(out, xyz->x) ||
+ jas_iccputuint32(out, xyz->y) ||
+ jas_iccputuint32(out, xyz->z))
+ return -1;
+ return 0;
+}
+
+static int jas_iccxyz_getsize(jas_iccattrval_t *attrval)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ attrval = 0;
+
+ return 12;
+}
+
+static void jas_iccxyz_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ jas_iccxyz_t *xyz = &attrval->data.xyz;
+ fprintf(out, "(%f, %f, %f)\n", xyz->x / 65536.0, xyz->y / 65536.0, xyz->z / 65536.0);
+}
+
+/******************************************************************************\
+* attribute table class
+\******************************************************************************/
+
+static void jas_icccurv_destroy(jas_iccattrval_t *attrval)
+{
+ jas_icccurv_t *curv = &attrval->data.curv;
+ if (curv->ents)
+ jas_free(curv->ents);
+}
+
+static int jas_icccurv_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ attrval = 0;
+ othattrval = 0;
+
+ /* Not yet implemented. */
+ abort();
+ return -1;
+}
+
+static int jas_icccurv_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt)
+{
+ jas_icccurv_t *curv = &attrval->data.curv;
+ unsigned int i;
+
+ curv->numents = 0;
+ curv->ents = 0;
+
+ if (jas_iccgetuint32(in, &curv->numents))
+ goto error;
+ if (!(curv->ents = jas_malloc(curv->numents * sizeof(jas_iccuint16_t))))
+ goto error;
+ for (i = 0; i < curv->numents; ++i) {
+ if (jas_iccgetuint16(in, &curv->ents[i]))
+ goto error;
+ }
+
+ if (JAS_CAST(int, 4 + 2 * curv->numents) != cnt)
+ goto error;
+ return 0;
+
+error:
+ jas_icccurv_destroy(attrval);
+ return -1;
+}
+
+static int jas_icccurv_getsize(jas_iccattrval_t *attrval)
+{
+ jas_icccurv_t *curv = &attrval->data.curv;
+ return 4 + 2 * curv->numents;
+}
+
+static int jas_icccurv_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_icccurv_t *curv = &attrval->data.curv;
+ unsigned int i;
+
+ if (jas_iccputuint32(out, curv->numents))
+ goto error;
+ for (i = 0; i < curv->numents; ++i) {
+ if (jas_iccputuint16(out, curv->ents[i]))
+ goto error;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static void jas_icccurv_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ int i;
+ jas_icccurv_t *curv = &attrval->data.curv;
+ fprintf(out, "number of entires = %d\n", curv->numents);
+ if (curv->numents == 1) {
+ fprintf(out, "gamma = %f\n", curv->ents[0] / 256.0);
+ } else {
+ for (i = 0; i < JAS_CAST(int, curv->numents); ++i) {
+ if (i < 3 || i >= JAS_CAST(int, curv->numents) - 3) {
+ fprintf(out, "entry[%d] = %f\n", i, curv->ents[i] / 65535.0);
+ }
+ }
+ }
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static void jas_icctxtdesc_destroy(jas_iccattrval_t *attrval)
+{
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+ if (txtdesc->ascdata)
+ jas_free(txtdesc->ascdata);
+ if (txtdesc->ucdata)
+ jas_free(txtdesc->ucdata);
+}
+
+static int jas_icctxtdesc_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval)
+{
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+
+ /* Avoid compiler warnings about unused parameters. */
+ attrval = 0;
+ othattrval = 0;
+ txtdesc = 0;
+
+ /* Not yet implemented. */
+ abort();
+ return -1;
+}
+
+static int jas_icctxtdesc_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt)
+{
+ int n;
+ int c;
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+ txtdesc->ascdata = 0;
+ txtdesc->ucdata = 0;
+ if (jas_iccgetuint32(in, &txtdesc->asclen))
+ goto error;
+ if (!(txtdesc->ascdata = jas_malloc(txtdesc->asclen)))
+ goto error;
+ if (jas_stream_read(in, txtdesc->ascdata, txtdesc->asclen) !=
+ JAS_CAST(int, txtdesc->asclen))
+ goto error;
+ txtdesc->ascdata[txtdesc->asclen - 1] = '\0';
+ if (jas_iccgetuint32(in, &txtdesc->uclangcode) ||
+ jas_iccgetuint32(in, &txtdesc->uclen))
+ goto error;
+ if (!(txtdesc->ucdata = jas_malloc(txtdesc->uclen * 2)))
+ goto error;
+ if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) !=
+ JAS_CAST(int, txtdesc->uclen * 2))
+ goto error;
+ if (jas_iccgetuint16(in, &txtdesc->sccode))
+ goto error;
+ if ((c = jas_stream_getc(in)) == EOF)
+ goto error;
+ txtdesc->maclen = c;
+ if (jas_stream_read(in, txtdesc->macdata, 67) != 67)
+ goto error;
+ txtdesc->asclen = strlen(txtdesc->ascdata) + 1;
+#define WORKAROUND_BAD_PROFILES
+#ifdef WORKAROUND_BAD_PROFILES
+ n = txtdesc->asclen + txtdesc->uclen * 2 + 15 + 67;
+ if (n > cnt) {
+ return -1;
+ }
+ if (n < cnt) {
+ if (jas_stream_gobble(in, cnt - n) != cnt - n)
+ goto error;
+ }
+#else
+ if (txtdesc->asclen + txtdesc->uclen * 2 + 15 + 67 != cnt)
+ return -1;
+#endif
+ return 0;
+error:
+ jas_icctxtdesc_destroy(attrval);
+ return -1;
+}
+
+static int jas_icctxtdesc_getsize(jas_iccattrval_t *attrval)
+{
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+ return strlen(txtdesc->ascdata) + 1 + txtdesc->uclen * 2 + 15 + 67;
+}
+
+static int jas_icctxtdesc_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+ if (jas_iccputuint32(out, txtdesc->asclen) ||
+ jas_stream_puts(out, txtdesc->ascdata) ||
+ jas_stream_putc(out, 0) == EOF ||
+ jas_iccputuint32(out, txtdesc->uclangcode) ||
+ jas_iccputuint32(out, txtdesc->uclen) ||
+ jas_stream_write(out, txtdesc->ucdata, txtdesc->uclen * 2) != JAS_CAST(int, txtdesc->uclen * 2) ||
+ jas_iccputuint16(out, txtdesc->sccode) ||
+ jas_stream_putc(out, txtdesc->maclen) == EOF)
+ goto error;
+ if (txtdesc->maclen > 0) {
+ if (jas_stream_write(out, txtdesc->macdata, 67) != 67)
+ goto error;
+ } else {
+ if (jas_stream_pad(out, 67, 0) != 67)
+ goto error;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static void jas_icctxtdesc_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ jas_icctxtdesc_t *txtdesc = &attrval->data.txtdesc;
+ fprintf(out, "ascii = \"%s\"\n", txtdesc->ascdata);
+ fprintf(out, "uclangcode = %d; uclen = %d\n", txtdesc->uclangcode,
+ txtdesc->uclen);
+ fprintf(out, "sccode = %d\n", txtdesc->sccode);
+ fprintf(out, "maclen = %d\n", txtdesc->maclen);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static void jas_icctxt_destroy(jas_iccattrval_t *attrval)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ if (txt->string)
+ jas_free(txt->string);
+}
+
+static int jas_icctxt_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ jas_icctxt_t *othtxt = &othattrval->data.txt;
+ if (!(txt->string = strdup(othtxt->string)))
+ return -1;
+ return 0;
+}
+
+static int jas_icctxt_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ txt->string = 0;
+ if (!(txt->string = jas_malloc(cnt)))
+ goto error;
+ if (jas_stream_read(in, txt->string, cnt) != cnt)
+ goto error;
+ txt->string[cnt - 1] = '\0';
+ if (JAS_CAST(int, strlen(txt->string)) + 1 != cnt)
+ goto error;
+ return 0;
+error:
+ if (txt->string)
+ jas_free(txt->string);
+ return -1;
+}
+
+static int jas_icctxt_getsize(jas_iccattrval_t *attrval)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ return strlen(txt->string) + 1;
+}
+
+static int jas_icctxt_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ if (jas_stream_puts(out, txt->string) ||
+ jas_stream_putc(out, 0) == EOF)
+ return -1;
+ return 0;
+}
+
+static void jas_icctxt_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ jas_icctxt_t *txt = &attrval->data.txt;
+ fprintf(out, "string = \"%s\"\n", txt->string);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static void jas_icclut8_destroy(jas_iccattrval_t *attrval)
+{
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ if (lut8->clut)
+ jas_free(lut8->clut);
+ if (lut8->intabs)
+ jas_free(lut8->intabs);
+ if (lut8->intabsbuf)
+ jas_free(lut8->intabsbuf);
+ if (lut8->outtabs)
+ jas_free(lut8->outtabs);
+ if (lut8->outtabsbuf)
+ jas_free(lut8->outtabsbuf);
+}
+
+static int jas_icclut8_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval)
+{
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ /* Avoid compiler warnings about unused parameters. */
+ attrval = 0;
+ othattrval = 0;
+ lut8 = 0;
+ abort();
+ return -1;
+}
+
+static int jas_icclut8_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt)
+{
+ int i;
+ int j;
+ int clutsize;
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ lut8->clut = 0;
+ lut8->intabs = 0;
+ lut8->intabsbuf = 0;
+ lut8->outtabs = 0;
+ lut8->outtabsbuf = 0;
+ if (jas_iccgetuint8(in, &lut8->numinchans) ||
+ jas_iccgetuint8(in, &lut8->numoutchans) ||
+ jas_iccgetuint8(in, &lut8->clutlen) ||
+ jas_stream_getc(in) == EOF)
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ if (jas_iccgetsint32(in, &lut8->e[i][j]))
+ goto error;
+ }
+ }
+ if (jas_iccgetuint16(in, &lut8->numintabents) ||
+ jas_iccgetuint16(in, &lut8->numouttabents))
+ goto error;
+ clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
+ if (!(lut8->clut = jas_malloc(clutsize * sizeof(jas_iccuint8_t))) ||
+ !(lut8->intabsbuf = jas_malloc(lut8->numinchans *
+ lut8->numintabents * sizeof(jas_iccuint8_t))) ||
+ !(lut8->intabs = jas_malloc(lut8->numinchans *
+ sizeof(jas_iccuint8_t *))))
+ goto error;
+ for (i = 0; i < lut8->numinchans; ++i)
+ lut8->intabs[i] = &lut8->intabsbuf[i * lut8->numintabents];
+ if (!(lut8->outtabsbuf = jas_malloc(lut8->numoutchans *
+ lut8->numouttabents * sizeof(jas_iccuint8_t))) ||
+ !(lut8->outtabs = jas_malloc(lut8->numoutchans *
+ sizeof(jas_iccuint8_t *))))
+ goto error;
+ for (i = 0; i < lut8->numoutchans; ++i)
+ lut8->outtabs[i] = &lut8->outtabsbuf[i * lut8->numouttabents];
+ for (i = 0; i < lut8->numinchans; ++i) {
+ for (j = 0; j < JAS_CAST(int, lut8->numintabents); ++j) {
+ if (jas_iccgetuint8(in, &lut8->intabs[i][j]))
+ goto error;
+ }
+ }
+ for (i = 0; i < lut8->numoutchans; ++i) {
+ for (j = 0; j < JAS_CAST(int, lut8->numouttabents); ++j) {
+ if (jas_iccgetuint8(in, &lut8->outtabs[i][j]))
+ goto error;
+ }
+ }
+ for (i = 0; i < clutsize; ++i) {
+ if (jas_iccgetuint8(in, &lut8->clut[i]))
+ goto error;
+ }
+ if (JAS_CAST(int, 44 + lut8->numinchans * lut8->numintabents +
+ lut8->numoutchans * lut8->numouttabents +
+ jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans) !=
+ cnt)
+ goto error;
+ return 0;
+error:
+ jas_icclut8_destroy(attrval);
+ return -1;
+}
+
+static int jas_icclut8_getsize(jas_iccattrval_t *attrval)
+{
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ return 44 + lut8->numinchans * lut8->numintabents +
+ lut8->numoutchans * lut8->numouttabents +
+ jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
+}
+
+static int jas_icclut8_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ int i;
+ int j;
+ int n;
+ lut8->clut = 0;
+ lut8->intabs = 0;
+ lut8->intabsbuf = 0;
+ lut8->outtabs = 0;
+ lut8->outtabsbuf = 0;
+ if (jas_stream_putc(out, lut8->numinchans) == EOF ||
+ jas_stream_putc(out, lut8->numoutchans) == EOF ||
+ jas_stream_putc(out, lut8->clutlen) == EOF ||
+ jas_stream_putc(out, 0) == EOF)
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ if (jas_iccputsint32(out, lut8->e[i][j]))
+ goto error;
+ }
+ }
+ if (jas_iccputuint16(out, lut8->numintabents) ||
+ jas_iccputuint16(out, lut8->numouttabents))
+ goto error;
+ n = lut8->numinchans * lut8->numintabents;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint8(out, lut8->intabsbuf[i]))
+ goto error;
+ }
+ n = lut8->numoutchans * lut8->numouttabents;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint8(out, lut8->outtabsbuf[i]))
+ goto error;
+ }
+ n = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint8(out, lut8->clut[i]))
+ goto error;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static void jas_icclut8_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ jas_icclut8_t *lut8 = &attrval->data.lut8;
+ int i;
+ int j;
+ fprintf(out, "numinchans=%d, numoutchans=%d, clutlen=%d\n",
+ lut8->numinchans, lut8->numoutchans, lut8->clutlen);
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ fprintf(out, "e[%d][%d]=%f ", i, j, lut8->e[i][j] / 65536.0);
+ }
+ fprintf(out, "\n");
+ }
+ fprintf(out, "numintabents=%d, numouttabents=%d\n",
+ lut8->numintabents, lut8->numouttabents);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static void jas_icclut16_destroy(jas_iccattrval_t *attrval)
+{
+ jas_icclut16_t *lut16 = &attrval->data.lut16;
+ if (lut16->clut)
+ jas_free(lut16->clut);
+ if (lut16->intabs)
+ jas_free(lut16->intabs);
+ if (lut16->intabsbuf)
+ jas_free(lut16->intabsbuf);
+ if (lut16->outtabs)
+ jas_free(lut16->outtabs);
+ if (lut16->outtabsbuf)
+ jas_free(lut16->outtabsbuf);
+}
+
+static int jas_icclut16_copy(jas_iccattrval_t *attrval,
+ jas_iccattrval_t *othattrval)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ attrval = 0;
+ othattrval = 0;
+ /* Not yet implemented. */
+ abort();
+ return -1;
+}
+
+static int jas_icclut16_input(jas_iccattrval_t *attrval, jas_stream_t *in,
+ int cnt)
+{
+ int i;
+ int j;
+ int clutsize;
+ jas_icclut16_t *lut16 = &attrval->data.lut16;
+ lut16->clut = 0;
+ lut16->intabs = 0;
+ lut16->intabsbuf = 0;
+ lut16->outtabs = 0;
+ lut16->outtabsbuf = 0;
+ if (jas_iccgetuint8(in, &lut16->numinchans) ||
+ jas_iccgetuint8(in, &lut16->numoutchans) ||
+ jas_iccgetuint8(in, &lut16->clutlen) ||
+ jas_stream_getc(in) == EOF)
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ if (jas_iccgetsint32(in, &lut16->e[i][j]))
+ goto error;
+ }
+ }
+ if (jas_iccgetuint16(in, &lut16->numintabents) ||
+ jas_iccgetuint16(in, &lut16->numouttabents))
+ goto error;
+ clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans;
+ if (!(lut16->clut = jas_malloc(clutsize * sizeof(jas_iccuint16_t))) ||
+ !(lut16->intabsbuf = jas_malloc(lut16->numinchans *
+ lut16->numintabents * sizeof(jas_iccuint16_t))) ||
+ !(lut16->intabs = jas_malloc(lut16->numinchans *
+ sizeof(jas_iccuint16_t *))))
+ goto error;
+ for (i = 0; i < lut16->numinchans; ++i)
+ lut16->intabs[i] = &lut16->intabsbuf[i * lut16->numintabents];
+ if (!(lut16->outtabsbuf = jas_malloc(lut16->numoutchans *
+ lut16->numouttabents * sizeof(jas_iccuint16_t))) ||
+ !(lut16->outtabs = jas_malloc(lut16->numoutchans *
+ sizeof(jas_iccuint16_t *))))
+ goto error;
+ for (i = 0; i < lut16->numoutchans; ++i)
+ lut16->outtabs[i] = &lut16->outtabsbuf[i * lut16->numouttabents];
+ for (i = 0; i < lut16->numinchans; ++i) {
+ for (j = 0; j < JAS_CAST(int, lut16->numintabents); ++j) {
+ if (jas_iccgetuint16(in, &lut16->intabs[i][j]))
+ goto error;
+ }
+ }
+ for (i = 0; i < lut16->numoutchans; ++i) {
+ for (j = 0; j < JAS_CAST(int, lut16->numouttabents); ++j) {
+ if (jas_iccgetuint16(in, &lut16->outtabs[i][j]))
+ goto error;
+ }
+ }
+ for (i = 0; i < clutsize; ++i) {
+ if (jas_iccgetuint16(in, &lut16->clut[i]))
+ goto error;
+ }
+ if (JAS_CAST(int, 44 + 2 * (lut16->numinchans * lut16->numintabents +
+ lut16->numoutchans * lut16->numouttabents +
+ jas_iccpowi(lut16->clutlen, lut16->numinchans) *
+ lut16->numoutchans)) != cnt)
+ goto error;
+ return 0;
+error:
+ jas_icclut16_destroy(attrval);
+ return -1;
+}
+
+static int jas_icclut16_getsize(jas_iccattrval_t *attrval)
+{
+ jas_icclut16_t *lut16 = &attrval->data.lut16;
+ return 44 + 2 * (lut16->numinchans * lut16->numintabents +
+ lut16->numoutchans * lut16->numouttabents +
+ jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans);
+}
+
+static int jas_icclut16_output(jas_iccattrval_t *attrval, jas_stream_t *out)
+{
+ jas_icclut16_t *lut16 = &attrval->data.lut16;
+ int i;
+ int j;
+ int n;
+ if (jas_stream_putc(out, lut16->numinchans) == EOF ||
+ jas_stream_putc(out, lut16->numoutchans) == EOF ||
+ jas_stream_putc(out, lut16->clutlen) == EOF ||
+ jas_stream_putc(out, 0) == EOF)
+ goto error;
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ if (jas_iccputsint32(out, lut16->e[i][j]))
+ goto error;
+ }
+ }
+ if (jas_iccputuint16(out, lut16->numintabents) ||
+ jas_iccputuint16(out, lut16->numouttabents))
+ goto error;
+ n = lut16->numinchans * lut16->numintabents;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint16(out, lut16->intabsbuf[i]))
+ goto error;
+ }
+ n = lut16->numoutchans * lut16->numouttabents;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint16(out, lut16->outtabsbuf[i]))
+ goto error;
+ }
+ n = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans;
+ for (i = 0; i < n; ++i) {
+ if (jas_iccputuint16(out, lut16->clut[i]))
+ goto error;
+ }
+ return 0;
+error:
+ return -1;
+}
+
+static void jas_icclut16_dump(jas_iccattrval_t *attrval, FILE *out)
+{
+ jas_icclut16_t *lut16 = &attrval->data.lut16;
+ int i;
+ int j;
+ fprintf(out, "numinchans=%d, numoutchans=%d, clutlen=%d\n",
+ lut16->numinchans, lut16->numoutchans, lut16->clutlen);
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j) {
+ fprintf(out, "e[%d][%d]=%f ", i, j, lut16->e[i][j] / 65536.0);
+ }
+ fprintf(out, "\n");
+ }
+ fprintf(out, "numintabents=%d, numouttabents=%d\n",
+ lut16->numintabents, lut16->numouttabents);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static int jas_iccgetuint(jas_stream_t *in, int n, ulonglong *val)
+{
+ int i;
+ int c;
+ ulonglong v;
+ v = 0;
+ for (i = n; i > 0; --i) {
+ if ((c = jas_stream_getc(in)) == EOF)
+ return -1;
+ v = (v << 8) | c;
+ }
+ *val = v;
+ return 0;
+}
+
+static int jas_iccgetuint8(jas_stream_t *in, jas_iccuint8_t *val)
+{
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF)
+ return -1;
+ *val = c;
+ return 0;
+}
+
+static int jas_iccgetuint16(jas_stream_t *in, jas_iccuint16_t *val)
+{
+ ulonglong tmp;
+ if (jas_iccgetuint(in, 2, &tmp))
+ return -1;
+ *val = tmp;
+ return 0;
+}
+
+static int jas_iccgetsint32(jas_stream_t *in, jas_iccsint32_t *val)
+{
+ ulonglong tmp;
+ if (jas_iccgetuint(in, 4, &tmp))
+ return -1;
+ *val = (tmp & 0x80000000) ? (-JAS_CAST(longlong, (((~tmp) &
+ 0x7fffffff) + 1))) : JAS_CAST(longlong, tmp);
+ return 0;
+}
+
+static int jas_iccgetuint32(jas_stream_t *in, jas_iccuint32_t *val)
+{
+ ulonglong tmp;
+ if (jas_iccgetuint(in, 4, &tmp))
+ return -1;
+ *val = tmp;
+ return 0;
+}
+
+static int jas_iccgetuint64(jas_stream_t *in, jas_iccuint64_t *val)
+{
+ ulonglong tmp;
+ if (jas_iccgetuint(in, 8, &tmp))
+ return -1;
+ *val = tmp;
+ return 0;
+}
+
+static int jas_iccputuint(jas_stream_t *out, int n, ulonglong val)
+{
+ int i;
+ int c;
+ for (i = n; i > 0; --i) {
+ c = (val >> (8 * (i - 1))) & 0xff;
+ if (jas_stream_putc(out, c) == EOF)
+ return -1;
+ }
+ return 0;
+}
+
+static int jas_iccputsint(jas_stream_t *out, int n, longlong val)
+{
+ ulonglong tmp;
+ tmp = (val < 0) ? (abort(), 0) : val;
+ return jas_iccputuint(out, n, tmp);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static char *jas_iccsigtostr(int sig, char *buf)
+{
+ int n;
+ int c;
+ char *bufptr;
+ bufptr = buf;
+ for (n = 4; n > 0; --n) {
+ c = (sig >> 24) & 0xff;
+ if (isalpha(c) || isdigit(c)) {
+ *bufptr++ = c;
+ }
+ sig <<= 8;
+ }
+ *bufptr = '\0';
+ return buf;
+}
+
+static long jas_iccpadtomult(long x, long y)
+{
+ return ((x + y - 1) / y) * y;
+}
+
+static long jas_iccpowi(int x, int n)
+{
+ long y;
+ y = 1;
+ while (--n >= 0)
+ y *= x;
+ return y;
+}
+
+
+jas_iccprof_t *jas_iccprof_createfrombuf(uchar *buf, int len)
+{
+ jas_stream_t *in;
+ jas_iccprof_t *prof;
+ if (!(in = jas_stream_memopen(JAS_CAST(char *, buf), len)))
+ goto error;
+ if (!(prof = jas_iccprof_load(in)))
+ goto error;
+ jas_stream_close(in);
+ return prof;
+error:
+ return 0;
+}
+
+jas_iccprof_t *jas_iccprof_createfromclrspc(int clrspc)
+{
+ jas_iccprof_t *prof;
+ switch (clrspc) {
+ case JAS_CLRSPC_SRGB:
+ prof = jas_iccprof_createfrombuf(jas_iccprofdata_srgb,
+ jas_iccprofdata_srgblen);
+ break;
+ case JAS_CLRSPC_SGRAY:
+ prof = jas_iccprof_createfrombuf(jas_iccprofdata_sgray,
+ jas_iccprofdata_sgraylen);
+ break;
+ default:
+ prof = 0;
+ break;
+ }
+ return prof;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_icc.h b/osframework/source/ImageLib/jpeg2000/jas_icc.h
new file mode 100644
index 0000000..0afc325
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_icc.h
@@ -0,0 +1,456 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JAS_ICC_H
+#define JAS_ICC_H
+
+#include "jas_config.h"
+#include "jas_types.h"
+#include "jas_stream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Profile file signature. */
+#define JAS_ICC_MAGIC 0x61637370
+
+#define JAS_ICC_HDRLEN 128
+
+/* Profile/device class signatures. */
+#define JAS_ICC_CLAS_IN 0x73636e72 /* input device */
+#define JAS_ICC_CLAS_DPY 0x6d6e7472 /* display device */
+#define JAS_ICC_CLAS_OUT 0x70727472 /* output device */
+#define JAS_ICC_CLAS_LNK 0x6c696e6b /* device link */
+#define JAS_ICC_CLAS_CNV 0x73706163 /* color space conversion */
+#define JAS_ICC_CLAS_ABS 0x61627374 /* abstract */
+#define JAS_ICC_CLAS_NAM 0x6e6d636c /* named color */
+
+/* Color space signatures. */
+#define JAS_ICC_COLORSPC_XYZ 0x58595a20 /* XYZ */
+#define JAS_ICC_COLORSPC_LAB 0x4c616220 /* LAB */
+#define JAS_ICC_COLORSPC_LUV 0x4c757620 /* LUV */
+#define JAS_ICC_COLORSPC_YCBCR 0x59436272 /* YCbCr */
+#define JAS_ICC_COLORSPC_YXY 0x59787920 /* Yxy */
+#define JAS_ICC_COLORSPC_RGB 0x52474220 /* RGB */
+#define JAS_ICC_COLORSPC_GRAY 0x47524159 /* Gray */
+#define JAS_ICC_COLORSPC_HSV 0x48535620 /* HSV */
+#define JAS_ICC_COLORSPC_HLS 0x484c5320 /* HLS */
+#define JAS_ICC_COLORSPC_CMYK 0x434d594b /* CMYK */
+#define JAS_ICC_COLORSPC_CMY 0x434d5920 /* CMY */
+#define JAS_ICC_COLORSPC_2 0x32434c52 /* 2 channel color */
+#define JAS_ICC_COLORSPC_3 0x33434c52 /* 3 channel color */
+#define JAS_ICC_COLORSPC_4 0x34434c52 /* 4 channel color */
+#define JAS_ICC_COLORSPC_5 0x35434c52 /* 5 channel color */
+#define JAS_ICC_COLORSPC_6 0x36434c52 /* 6 channel color */
+#define JAS_ICC_COLORSPC_7 0x37434c52 /* 7 channel color */
+#define JAS_ICC_COLORSPC_8 0x38434c52 /* 8 channel color */
+#define JAS_ICC_COLORSPC_9 0x39434c52 /* 9 channel color */
+#define JAS_ICC_COLORSPC_10 0x41434c52 /* 10 channel color */
+#define JAS_ICC_COLORSPC_11 0x42434c52 /* 11 channel color */
+#define JAS_ICC_COLORSPC_12 0x43434c52 /* 12 channel color */
+#define JAS_ICC_COLORSPC_13 0x44434c52 /* 13 channel color */
+#define JAS_ICC_COLORSPC_14 0x45434c52 /* 14 channel color */
+#define JAS_ICC_COLORSPC_15 0x46434c52 /* 15 channel color */
+
+/* Profile connection color space (PCS) signatures. */
+#define JAS_ICC_REFCOLORSPC_XYZ 0x58595a20 /* CIE XYZ */
+#define JAS_ICC_REFCOLORSPC_LAB 0x4c616220 /* CIE Lab */
+
+/* Primary platform signatures. */
+#define JAS_ICC_PLATFORM_APPL 0x4150504c /* Apple Computer */
+#define JAS_ICC_PLATFORM_MSFT 0x4d534654 /* Microsoft */
+#define JAS_ICC_PLATFORM_SGI 0x53474920 /* Silicon Graphics */
+#define JAS_ICC_PLATFORM_SUNW 0x53554e57 /* Sun Microsystems */
+#define JAS_ICC_PLATFORM_TGNT 0x54474e54 /* Taligent */
+
+/* Profile flags. */
+#define JAS_ICC_FLAGS_EMBED 0x01 /* embedded */
+#define JAS_ICC_FLAGS_NOSEP 0x02 /* no separate use */
+
+/* Attributes. */
+#define JAS_ICC_ATTR_TRANS 0x01 /* transparent */
+#define JAS_ICC_ATTR_MATTE 0x02 /* matte */
+
+/* Rendering intents. */
+#define JAS_ICC_INTENT_PER 0 /* perceptual */
+#define JAS_ICC_INTENT_REL 1 /* relative colorimetric */
+#define JAS_ICC_INTENT_SAT 2 /* saturation */
+#define JAS_ICC_INTENT_ABS 3 /* absolute colorimetric */
+
+/* Tag signatures. */
+#define JAS_ICC_TAG_ATOB0 0x41324230 /* */
+#define JAS_ICC_TAG_ATOB1 0x41324231 /* */
+#define JAS_ICC_TAG_ATOB2 0x41324232 /* */
+#define JAS_ICC_TAG_BLUMATCOL 0x6258595a /* */
+#define JAS_ICC_TAG_BLUTRC 0x62545243 /* */
+#define JAS_ICC_TAG_BTOA0 0x42324130 /* */
+#define JAS_ICC_TAG_BTOA1 0x42324131 /* */
+#define JAS_ICC_TAG_BTOA2 0x42324132 /* */
+#define JAS_ICC_TAG_CALTIME 0x63616c74 /* */
+#define JAS_ICC_TAG_CHARTARGET 0x74617267 /* */
+#define JAS_ICC_TAG_CPYRT 0x63707274 /* */
+#define JAS_ICC_TAG_CRDINFO 0x63726469 /* */
+#define JAS_ICC_TAG_DEVMAKERDESC 0x646d6e64 /* */
+#define JAS_ICC_TAG_DEVMODELDESC 0x646d6464 /* */
+#define JAS_ICC_TAG_DEVSET 0x64657673 /* */
+#define JAS_ICC_TAG_GAMUT 0x67616d74 /* */
+#define JAS_ICC_TAG_GRYTRC 0x6b545243 /* */
+#define JAS_ICC_TAG_GRNMATCOL 0x6758595a /* */
+#define JAS_ICC_TAG_GRNTRC 0x67545243 /* */
+#define JAS_ICC_TAG_LUM 0x6c756d69 /* */
+#define JAS_ICC_TAG_MEASURE 0x6d656173 /* */
+#define JAS_ICC_TAG_MEDIABLKPT 0x626b7074 /* */
+#define JAS_ICC_TAG_MEDIAWHIPT 0x77747074 /* */
+#define JAS_ICC_TAG_NAMCOLR 0x6e636f6c /* */
+#define JAS_ICC_TAG_NAMCOLR2 0x6e636c32 /* */
+#define JAS_ICC_TAG_OUTRESP 0x72657370 /* */
+#define JAS_ICC_TAG_PREVIEW0 0x70726530 /* */
+#define JAS_ICC_TAG_PREVIEW1 0x70726531 /* */
+#define JAS_ICC_TAG_PREVIEW2 0x70726532 /* */
+#define JAS_ICC_TAG_PROFDESC 0x64657363 /* */
+#define JAS_ICC_TAG_PROFSEQDESC 0x70736571 /* */
+#define JAS_ICC_TAG_PSDCRD0 0x70736430 /* */
+#define JAS_ICC_TAG_PSCRDD1 0x70736431 /* */
+#define JAS_ICC_TAG_PSCRDD2 0x70736432 /* */
+#define JAS_ICC_TAG_PSCRDD3 0x70736433 /* */
+#define JAS_ICC_TAG_PS2CSA 0x70733273 /* */
+#define JAS_ICC_TAG_PS2RENINTENT 0x70733269 /* */
+#define JAS_ICC_TAG_REDMATCOL 0x7258595a /* */
+#define JAS_ICC_TAG_REDTRC 0x72545243 /* */
+#define JAS_ICC_TAG_SCRNGDES 0x73637264 /* */
+#define JAS_ICC_TAG_SCRNG 0x7363726e /* */
+#define JAS_ICC_TAG_TECH 0x74656368 /* */
+#define JAS_ICC_TAG_UCRBG 0x62666420 /* */
+#define JAS_ICC_TAG_VIEWCONDDESC 0x76756564 /* */
+#define JAS_ICC_TAG_VIEWCOND 0x76696577 /* */
+
+/* Type signatures. */
+#define JAS_ICC_TYPE_CRDINFO 0x63726469 /* CRD information */
+#define JAS_ICC_TYPE_CURV 0x63757276 /* curve */
+#define JAS_ICC_TYPE_DATA 0x64617461 /* data */
+#define JAS_ICC_TYPE_TIME 0x6474696d /* date/time */
+#define JAS_ICC_TYPE_DEVSET 0x64657673 /* device settings */
+#define JAS_ICC_TYPE_LUT16 0x6d667432 /* */
+#define JAS_ICC_TYPE_LUT8 0x6d667431 /* */
+#define JAS_ICC_TYPE_MEASURE 0x6d656173 /* */
+#define JAS_ICC_TYPE_NAMCOLR 0x6e636f6c /* */
+#define JAS_ICC_TYPE_NAMCOLR2 0x6e636c32 /* */
+#define JAS_ICC_TYPE_PROFSEQDESC 0x70736571 /* profile sequence description */
+#define JAS_ICC_TYPE_RESPCURVSET16 0x72637332 /* response curve set 16 */
+#define JAS_ICC_TYPE_SF32 0x73663332 /* signed 32-bit fixed-point */
+#define JAS_ICC_TYPE_SCRNG 0x7363726e /* screening */
+#define JAS_ICC_TYPE_SIG 0x73696720 /* signature */
+#define JAS_ICC_TYPE_TXTDESC 0x64657363 /* text description */
+#define JAS_ICC_TYPE_TXT 0x74657874 /* text */
+#define JAS_ICC_TYPE_UF32 0x75663332 /* unsigned 32-bit fixed-point */
+#define JAS_ICC_TYPE_UCRBG 0x62666420 /* */
+#define JAS_ICC_TYPE_UI16 0x75693136 /* */
+#define JAS_ICC_TYPE_UI32 0x75693332 /* */
+#define JAS_ICC_TYPE_UI8 0x75693038 /* */
+#define JAS_ICC_TYPE_UI64 0x75693634 /* */
+#define JAS_ICC_TYPE_VIEWCOND 0x76696577 /* */
+#define JAS_ICC_TYPE_XYZ 0x58595a20 /* XYZ */
+
+typedef uint_fast8_t jas_iccuint8_t;
+typedef uint_fast16_t jas_iccuint16_t;
+typedef uint_fast32_t jas_iccuint32_t;
+typedef int_fast32_t jas_iccsint32_t;
+typedef int_fast32_t jas_iccs15fixed16_t;
+typedef uint_fast32_t jas_iccu16fixed16_t;
+typedef uint_fast64_t jas_iccuint64_t;
+typedef uint_fast32_t jas_iccsig_t;
+
+typedef jas_iccsig_t jas_icctagsig_t;
+typedef jas_iccsig_t jas_icctagtype_t;
+typedef jas_iccsig_t jas_iccattrname_t;
+
+/* Date/time type. */
+typedef struct {
+ jas_iccuint16_t year;
+ jas_iccuint16_t month;
+ jas_iccuint16_t day;
+ jas_iccuint16_t hour;
+ jas_iccuint16_t min;
+ jas_iccuint16_t sec;
+} jas_icctime_t;
+
+/* XYZ type. */
+typedef struct {
+ jas_iccs15fixed16_t x;
+ jas_iccs15fixed16_t y;
+ jas_iccs15fixed16_t z;
+} jas_iccxyz_t;
+
+/* Curve type. */
+typedef struct {
+ jas_iccuint32_t numents;
+ jas_iccuint16_t *ents;
+} jas_icccurv_t;
+
+/* Text description type. */
+typedef struct {
+ jas_iccuint32_t asclen;
+ char *ascdata; /* ASCII invariant description */
+ jas_iccuint32_t uclangcode; /* Unicode language code */
+ jas_iccuint32_t uclen; /* Unicode localizable description count */
+ uchar *ucdata; /* Unicode localizable description */
+ jas_iccuint16_t sccode; /* ScriptCode code */
+ jas_iccuint8_t maclen; /* Localizable Macintosh description count */
+ uchar macdata[69]; /* Localizable Macintosh description */
+} jas_icctxtdesc_t;
+
+/* Text type. */
+typedef struct {
+ char *string; /* ASCII character string */
+} jas_icctxt_t;
+
+typedef struct {
+ jas_iccuint8_t numinchans;
+ jas_iccuint8_t numoutchans;
+ jas_iccsint32_t e[3][3];
+ jas_iccuint8_t clutlen;
+ jas_iccuint8_t *clut;
+ jas_iccuint16_t numintabents;
+ jas_iccuint8_t **intabs;
+ jas_iccuint8_t *intabsbuf;
+ jas_iccuint16_t numouttabents;
+ jas_iccuint8_t **outtabs;
+ jas_iccuint8_t *outtabsbuf;
+} jas_icclut8_t;
+
+typedef struct {
+ jas_iccuint8_t numinchans;
+ jas_iccuint8_t numoutchans;
+ jas_iccsint32_t e[3][3];
+ jas_iccuint8_t clutlen;
+ jas_iccuint16_t *clut;
+ jas_iccuint16_t numintabents;
+ jas_iccuint16_t **intabs;
+ jas_iccuint16_t *intabsbuf;
+ jas_iccuint16_t numouttabents;
+ jas_iccuint16_t **outtabs;
+ jas_iccuint16_t *outtabsbuf;
+} jas_icclut16_t;
+
+struct jas_iccattrval_s;
+
+typedef struct {
+ void (*destroy)(struct jas_iccattrval_s *);
+ int (*copy)(struct jas_iccattrval_s *, struct jas_iccattrval_s *);
+ int (*input)(struct jas_iccattrval_s *, jas_stream_t *, int);
+ int (*output)(struct jas_iccattrval_s *, jas_stream_t *);
+ int (*getsize)(struct jas_iccattrval_s *);
+ void (*dump)(struct jas_iccattrval_s *, FILE *);
+} jas_iccattrvalops_t;
+
+/* Attribute value type (type and value information). */
+typedef struct jas_iccattrval_s {
+ int refcnt; /* reference count */
+ jas_iccsig_t type; /* type */
+ jas_iccattrvalops_t *ops; /* type-dependent operations */
+ union {
+ jas_iccxyz_t xyz;
+ jas_icccurv_t curv;
+ jas_icctxtdesc_t txtdesc;
+ jas_icctxt_t txt;
+ jas_icclut8_t lut8;
+ jas_icclut16_t lut16;
+ } data; /* value */
+} jas_iccattrval_t;
+
+/* Header type. */
+typedef struct {
+ jas_iccuint32_t size; /* profile size */
+ jas_iccsig_t cmmtype; /* CMM type signature */
+ jas_iccuint32_t version; /* profile version */
+ jas_iccsig_t clas; /* profile/device class signature */
+ jas_iccsig_t colorspc; /* color space of data */
+ jas_iccsig_t refcolorspc; /* profile connection space */
+ jas_icctime_t ctime; /* creation time */
+ jas_iccsig_t magic; /* profile file signature */
+ jas_iccsig_t platform; /* primary platform */
+ jas_iccuint32_t flags; /* profile flags */
+ jas_iccsig_t maker; /* device manufacturer signature */
+ jas_iccsig_t model; /* device model signature */
+ jas_iccuint64_t attr; /* device setup attributes */
+ jas_iccsig_t intent; /* rendering intent */
+ jas_iccxyz_t illum; /* illuminant */
+ jas_iccsig_t creator; /* profile creator signature */
+} jas_icchdr_t;
+
+typedef struct {
+ jas_iccsig_t name;
+ jas_iccattrval_t *val;
+} jas_iccattr_t;
+
+typedef struct {
+ int numattrs;
+ int maxattrs;
+ jas_iccattr_t *attrs;
+} jas_iccattrtab_t;
+
+typedef struct jas_icctagtabent_s {
+ jas_iccuint32_t tag;
+ jas_iccuint32_t off;
+ jas_iccuint32_t len;
+ void *data;
+ struct jas_icctagtabent_s *first;
+} jas_icctagtabent_t;
+
+typedef struct {
+ jas_iccuint32_t numents;
+ jas_icctagtabent_t *ents;
+} jas_icctagtab_t;
+
+/* ICC profile type. */
+typedef struct {
+ jas_icchdr_t hdr;
+ jas_icctagtab_t tagtab;
+ jas_iccattrtab_t *attrtab;
+} jas_iccprof_t;
+
+typedef struct {
+ jas_iccuint32_t type;
+ jas_iccattrvalops_t ops;
+} jas_iccattrvalinfo_t;
+
+jas_iccprof_t *jas_iccprof_load(jas_stream_t *in);
+int jas_iccprof_save(jas_iccprof_t *prof, jas_stream_t *out);
+void jas_iccprof_destroy(jas_iccprof_t *prof);
+jas_iccattrval_t *jas_iccprof_getattr(jas_iccprof_t *prof,
+ jas_iccattrname_t name);
+int jas_iccprof_setattr(jas_iccprof_t *prof, jas_iccattrname_t name,
+ jas_iccattrval_t *val);
+void jas_iccprof_dump(jas_iccprof_t *prof, FILE *out);
+jas_iccprof_t *jas_iccprof_copy(jas_iccprof_t *prof);
+int jas_iccprof_gethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
+int jas_iccprof_sethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
+
+void jas_iccattrval_destroy(jas_iccattrval_t *attrval);
+void jas_iccattrval_dump(jas_iccattrval_t *attrval, FILE *out);
+int jas_iccattrval_allowmodify(jas_iccattrval_t **attrval);
+jas_iccattrval_t *jas_iccattrval_clone(jas_iccattrval_t *attrval);
+jas_iccattrval_t *jas_iccattrval_create(jas_iccuint32_t type);
+
+void jas_iccattrtab_dump(jas_iccattrtab_t *attrtab, FILE *out);
+
+extern uchar jas_iccprofdata_srgb[];
+extern int jas_iccprofdata_srgblen;
+extern uchar jas_iccprofdata_sgray[];
+extern int jas_iccprofdata_sgraylen;
+jas_iccprof_t *jas_iccprof_createfrombuf(uchar *buf, int len);
+jas_iccprof_t *jas_iccprof_createfromclrspc(int clrspc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_iccdata.c b/osframework/source/ImageLib/jpeg2000/jas_iccdata.c
new file mode 100644
index 0000000..3f32b47
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_iccdata.c
@@ -0,0 +1,566 @@
+/*
+ * Copyright (c) 2002-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#include "jas_config.h"
+#include "jas_types.h"
+
+uchar jas_iccprofdata_srgb[] =
+{
+ 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f,
+ 0x02, 0x10, 0x00, 0x00, 0x6d, 0x6e, 0x74, 0x72,
+ 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20,
+ 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06,
+ 0x00, 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70,
+ 0x4d, 0x53, 0x46, 0x54, 0x00, 0x00, 0x00, 0x00,
+ 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47, 0x42,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d,
+ 0x48, 0x50, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x11, 0x63, 0x70, 0x72, 0x74,
+ 0x00, 0x00, 0x01, 0x50, 0x00, 0x00, 0x00, 0x33,
+ 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x01, 0x84,
+ 0x00, 0x00, 0x00, 0x6c, 0x77, 0x74, 0x70, 0x74,
+ 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x14,
+ 0x62, 0x6b, 0x70, 0x74, 0x00, 0x00, 0x02, 0x04,
+ 0x00, 0x00, 0x00, 0x14, 0x72, 0x58, 0x59, 0x5a,
+ 0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x14,
+ 0x67, 0x58, 0x59, 0x5a, 0x00, 0x00, 0x02, 0x2c,
+ 0x00, 0x00, 0x00, 0x14, 0x62, 0x58, 0x59, 0x5a,
+ 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x14,
+ 0x64, 0x6d, 0x6e, 0x64, 0x00, 0x00, 0x02, 0x54,
+ 0x00, 0x00, 0x00, 0x70, 0x64, 0x6d, 0x64, 0x64,
+ 0x00, 0x00, 0x02, 0xc4, 0x00, 0x00, 0x00, 0x88,
+ 0x76, 0x75, 0x65, 0x64, 0x00, 0x00, 0x03, 0x4c,
+ 0x00, 0x00, 0x00, 0x86, 0x76, 0x69, 0x65, 0x77,
+ 0x00, 0x00, 0x03, 0xd4, 0x00, 0x00, 0x00, 0x24,
+ 0x6c, 0x75, 0x6d, 0x69, 0x00, 0x00, 0x03, 0xf8,
+ 0x00, 0x00, 0x00, 0x14, 0x6d, 0x65, 0x61, 0x73,
+ 0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00, 0x24,
+ 0x74, 0x65, 0x63, 0x68, 0x00, 0x00, 0x04, 0x30,
+ 0x00, 0x00, 0x00, 0x0c, 0x72, 0x54, 0x52, 0x43,
+ 0x00, 0x00, 0x04, 0x3c, 0x00, 0x00, 0x08, 0x0c,
+ 0x67, 0x54, 0x52, 0x43, 0x00, 0x00, 0x04, 0x3c,
+ 0x00, 0x00, 0x08, 0x0c, 0x62, 0x54, 0x52, 0x43,
+ 0x00, 0x00, 0x04, 0x3c, 0x00, 0x00, 0x08, 0x0c,
+ 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00,
+ 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
+ 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
+ 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65,
+ 0x74, 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61,
+ 0x72, 0x64, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x61,
+ 0x6e, 0x79, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
+ 0x73, 0x52, 0x47, 0x42, 0x20, 0x49, 0x45, 0x43,
+ 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e,
+ 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x12, 0x73, 0x52, 0x47,
+ 0x42, 0x20, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39,
+ 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xf3, 0x51, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x01, 0x16, 0xcc, 0x58, 0x59, 0x5a, 0x20,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x6f, 0xa2, 0x00, 0x00, 0x38, 0xf5,
+ 0x00, 0x00, 0x03, 0x90, 0x58, 0x59, 0x5a, 0x20,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x99,
+ 0x00, 0x00, 0xb7, 0x85, 0x00, 0x00, 0x18, 0xda,
+ 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x24, 0xa0, 0x00, 0x00, 0x0f, 0x84,
+ 0x00, 0x00, 0xb6, 0xcf, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
+ 0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74, 0x70,
+ 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69,
+ 0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x16, 0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74,
+ 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e,
+ 0x69, 0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e,
+ 0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39, 0x36,
+ 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44, 0x65,
+ 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52, 0x47,
+ 0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72,
+ 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x2d,
+ 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x2e, 0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39,
+ 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44,
+ 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52,
+ 0x47, 0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75,
+ 0x72, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20,
+ 0x2d, 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
+ 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
+ 0x65, 0x20, 0x56, 0x69, 0x65, 0x77, 0x69, 0x6e,
+ 0x67, 0x20, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74,
+ 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x49,
+ 0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d,
+ 0x32, 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x52,
+ 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
+ 0x20, 0x56, 0x69, 0x65, 0x77, 0x69, 0x6e, 0x67,
+ 0x20, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69,
+ 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x49, 0x45,
+ 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32,
+ 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x65, 0x77,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xa4, 0xfe,
+ 0x00, 0x14, 0x5f, 0x2e, 0x00, 0x10, 0xcf, 0x14,
+ 0x00, 0x03, 0xed, 0xcc, 0x00, 0x04, 0x13, 0x0b,
+ 0x00, 0x03, 0x5c, 0x9e, 0x00, 0x00, 0x00, 0x01,
+ 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x4c, 0x09, 0x56, 0x00, 0x50, 0x00, 0x00,
+ 0x00, 0x57, 0x1f, 0xe7, 0x6d, 0x65, 0x61, 0x73,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x02, 0x8f, 0x00, 0x00, 0x00, 0x02,
+ 0x73, 0x69, 0x67, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x43, 0x52, 0x54, 0x20, 0x63, 0x75, 0x72, 0x76,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x0f,
+ 0x00, 0x14, 0x00, 0x19, 0x00, 0x1e, 0x00, 0x23,
+ 0x00, 0x28, 0x00, 0x2d, 0x00, 0x32, 0x00, 0x37,
+ 0x00, 0x3b, 0x00, 0x40, 0x00, 0x45, 0x00, 0x4a,
+ 0x00, 0x4f, 0x00, 0x54, 0x00, 0x59, 0x00, 0x5e,
+ 0x00, 0x63, 0x00, 0x68, 0x00, 0x6d, 0x00, 0x72,
+ 0x00, 0x77, 0x00, 0x7c, 0x00, 0x81, 0x00, 0x86,
+ 0x00, 0x8b, 0x00, 0x90, 0x00, 0x95, 0x00, 0x9a,
+ 0x00, 0x9f, 0x00, 0xa4, 0x00, 0xa9, 0x00, 0xae,
+ 0x00, 0xb2, 0x00, 0xb7, 0x00, 0xbc, 0x00, 0xc1,
+ 0x00, 0xc6, 0x00, 0xcb, 0x00, 0xd0, 0x00, 0xd5,
+ 0x00, 0xdb, 0x00, 0xe0, 0x00, 0xe5, 0x00, 0xeb,
+ 0x00, 0xf0, 0x00, 0xf6, 0x00, 0xfb, 0x01, 0x01,
+ 0x01, 0x07, 0x01, 0x0d, 0x01, 0x13, 0x01, 0x19,
+ 0x01, 0x1f, 0x01, 0x25, 0x01, 0x2b, 0x01, 0x32,
+ 0x01, 0x38, 0x01, 0x3e, 0x01, 0x45, 0x01, 0x4c,
+ 0x01, 0x52, 0x01, 0x59, 0x01, 0x60, 0x01, 0x67,
+ 0x01, 0x6e, 0x01, 0x75, 0x01, 0x7c, 0x01, 0x83,
+ 0x01, 0x8b, 0x01, 0x92, 0x01, 0x9a, 0x01, 0xa1,
+ 0x01, 0xa9, 0x01, 0xb1, 0x01, 0xb9, 0x01, 0xc1,
+ 0x01, 0xc9, 0x01, 0xd1, 0x01, 0xd9, 0x01, 0xe1,
+ 0x01, 0xe9, 0x01, 0xf2, 0x01, 0xfa, 0x02, 0x03,
+ 0x02, 0x0c, 0x02, 0x14, 0x02, 0x1d, 0x02, 0x26,
+ 0x02, 0x2f, 0x02, 0x38, 0x02, 0x41, 0x02, 0x4b,
+ 0x02, 0x54, 0x02, 0x5d, 0x02, 0x67, 0x02, 0x71,
+ 0x02, 0x7a, 0x02, 0x84, 0x02, 0x8e, 0x02, 0x98,
+ 0x02, 0xa2, 0x02, 0xac, 0x02, 0xb6, 0x02, 0xc1,
+ 0x02, 0xcb, 0x02, 0xd5, 0x02, 0xe0, 0x02, 0xeb,
+ 0x02, 0xf5, 0x03, 0x00, 0x03, 0x0b, 0x03, 0x16,
+ 0x03, 0x21, 0x03, 0x2d, 0x03, 0x38, 0x03, 0x43,
+ 0x03, 0x4f, 0x03, 0x5a, 0x03, 0x66, 0x03, 0x72,
+ 0x03, 0x7e, 0x03, 0x8a, 0x03, 0x96, 0x03, 0xa2,
+ 0x03, 0xae, 0x03, 0xba, 0x03, 0xc7, 0x03, 0xd3,
+ 0x03, 0xe0, 0x03, 0xec, 0x03, 0xf9, 0x04, 0x06,
+ 0x04, 0x13, 0x04, 0x20, 0x04, 0x2d, 0x04, 0x3b,
+ 0x04, 0x48, 0x04, 0x55, 0x04, 0x63, 0x04, 0x71,
+ 0x04, 0x7e, 0x04, 0x8c, 0x04, 0x9a, 0x04, 0xa8,
+ 0x04, 0xb6, 0x04, 0xc4, 0x04, 0xd3, 0x04, 0xe1,
+ 0x04, 0xf0, 0x04, 0xfe, 0x05, 0x0d, 0x05, 0x1c,
+ 0x05, 0x2b, 0x05, 0x3a, 0x05, 0x49, 0x05, 0x58,
+ 0x05, 0x67, 0x05, 0x77, 0x05, 0x86, 0x05, 0x96,
+ 0x05, 0xa6, 0x05, 0xb5, 0x05, 0xc5, 0x05, 0xd5,
+ 0x05, 0xe5, 0x05, 0xf6, 0x06, 0x06, 0x06, 0x16,
+ 0x06, 0x27, 0x06, 0x37, 0x06, 0x48, 0x06, 0x59,
+ 0x06, 0x6a, 0x06, 0x7b, 0x06, 0x8c, 0x06, 0x9d,
+ 0x06, 0xaf, 0x06, 0xc0, 0x06, 0xd1, 0x06, 0xe3,
+ 0x06, 0xf5, 0x07, 0x07, 0x07, 0x19, 0x07, 0x2b,
+ 0x07, 0x3d, 0x07, 0x4f, 0x07, 0x61, 0x07, 0x74,
+ 0x07, 0x86, 0x07, 0x99, 0x07, 0xac, 0x07, 0xbf,
+ 0x07, 0xd2, 0x07, 0xe5, 0x07, 0xf8, 0x08, 0x0b,
+ 0x08, 0x1f, 0x08, 0x32, 0x08, 0x46, 0x08, 0x5a,
+ 0x08, 0x6e, 0x08, 0x82, 0x08, 0x96, 0x08, 0xaa,
+ 0x08, 0xbe, 0x08, 0xd2, 0x08, 0xe7, 0x08, 0xfb,
+ 0x09, 0x10, 0x09, 0x25, 0x09, 0x3a, 0x09, 0x4f,
+ 0x09, 0x64, 0x09, 0x79, 0x09, 0x8f, 0x09, 0xa4,
+ 0x09, 0xba, 0x09, 0xcf, 0x09, 0xe5, 0x09, 0xfb,
+ 0x0a, 0x11, 0x0a, 0x27, 0x0a, 0x3d, 0x0a, 0x54,
+ 0x0a, 0x6a, 0x0a, 0x81, 0x0a, 0x98, 0x0a, 0xae,
+ 0x0a, 0xc5, 0x0a, 0xdc, 0x0a, 0xf3, 0x0b, 0x0b,
+ 0x0b, 0x22, 0x0b, 0x39, 0x0b, 0x51, 0x0b, 0x69,
+ 0x0b, 0x80, 0x0b, 0x98, 0x0b, 0xb0, 0x0b, 0xc8,
+ 0x0b, 0xe1, 0x0b, 0xf9, 0x0c, 0x12, 0x0c, 0x2a,
+ 0x0c, 0x43, 0x0c, 0x5c, 0x0c, 0x75, 0x0c, 0x8e,
+ 0x0c, 0xa7, 0x0c, 0xc0, 0x0c, 0xd9, 0x0c, 0xf3,
+ 0x0d, 0x0d, 0x0d, 0x26, 0x0d, 0x40, 0x0d, 0x5a,
+ 0x0d, 0x74, 0x0d, 0x8e, 0x0d, 0xa9, 0x0d, 0xc3,
+ 0x0d, 0xde, 0x0d, 0xf8, 0x0e, 0x13, 0x0e, 0x2e,
+ 0x0e, 0x49, 0x0e, 0x64, 0x0e, 0x7f, 0x0e, 0x9b,
+ 0x0e, 0xb6, 0x0e, 0xd2, 0x0e, 0xee, 0x0f, 0x09,
+ 0x0f, 0x25, 0x0f, 0x41, 0x0f, 0x5e, 0x0f, 0x7a,
+ 0x0f, 0x96, 0x0f, 0xb3, 0x0f, 0xcf, 0x0f, 0xec,
+ 0x10, 0x09, 0x10, 0x26, 0x10, 0x43, 0x10, 0x61,
+ 0x10, 0x7e, 0x10, 0x9b, 0x10, 0xb9, 0x10, 0xd7,
+ 0x10, 0xf5, 0x11, 0x13, 0x11, 0x31, 0x11, 0x4f,
+ 0x11, 0x6d, 0x11, 0x8c, 0x11, 0xaa, 0x11, 0xc9,
+ 0x11, 0xe8, 0x12, 0x07, 0x12, 0x26, 0x12, 0x45,
+ 0x12, 0x64, 0x12, 0x84, 0x12, 0xa3, 0x12, 0xc3,
+ 0x12, 0xe3, 0x13, 0x03, 0x13, 0x23, 0x13, 0x43,
+ 0x13, 0x63, 0x13, 0x83, 0x13, 0xa4, 0x13, 0xc5,
+ 0x13, 0xe5, 0x14, 0x06, 0x14, 0x27, 0x14, 0x49,
+ 0x14, 0x6a, 0x14, 0x8b, 0x14, 0xad, 0x14, 0xce,
+ 0x14, 0xf0, 0x15, 0x12, 0x15, 0x34, 0x15, 0x56,
+ 0x15, 0x78, 0x15, 0x9b, 0x15, 0xbd, 0x15, 0xe0,
+ 0x16, 0x03, 0x16, 0x26, 0x16, 0x49, 0x16, 0x6c,
+ 0x16, 0x8f, 0x16, 0xb2, 0x16, 0xd6, 0x16, 0xfa,
+ 0x17, 0x1d, 0x17, 0x41, 0x17, 0x65, 0x17, 0x89,
+ 0x17, 0xae, 0x17, 0xd2, 0x17, 0xf7, 0x18, 0x1b,
+ 0x18, 0x40, 0x18, 0x65, 0x18, 0x8a, 0x18, 0xaf,
+ 0x18, 0xd5, 0x18, 0xfa, 0x19, 0x20, 0x19, 0x45,
+ 0x19, 0x6b, 0x19, 0x91, 0x19, 0xb7, 0x19, 0xdd,
+ 0x1a, 0x04, 0x1a, 0x2a, 0x1a, 0x51, 0x1a, 0x77,
+ 0x1a, 0x9e, 0x1a, 0xc5, 0x1a, 0xec, 0x1b, 0x14,
+ 0x1b, 0x3b, 0x1b, 0x63, 0x1b, 0x8a, 0x1b, 0xb2,
+ 0x1b, 0xda, 0x1c, 0x02, 0x1c, 0x2a, 0x1c, 0x52,
+ 0x1c, 0x7b, 0x1c, 0xa3, 0x1c, 0xcc, 0x1c, 0xf5,
+ 0x1d, 0x1e, 0x1d, 0x47, 0x1d, 0x70, 0x1d, 0x99,
+ 0x1d, 0xc3, 0x1d, 0xec, 0x1e, 0x16, 0x1e, 0x40,
+ 0x1e, 0x6a, 0x1e, 0x94, 0x1e, 0xbe, 0x1e, 0xe9,
+ 0x1f, 0x13, 0x1f, 0x3e, 0x1f, 0x69, 0x1f, 0x94,
+ 0x1f, 0xbf, 0x1f, 0xea, 0x20, 0x15, 0x20, 0x41,
+ 0x20, 0x6c, 0x20, 0x98, 0x20, 0xc4, 0x20, 0xf0,
+ 0x21, 0x1c, 0x21, 0x48, 0x21, 0x75, 0x21, 0xa1,
+ 0x21, 0xce, 0x21, 0xfb, 0x22, 0x27, 0x22, 0x55,
+ 0x22, 0x82, 0x22, 0xaf, 0x22, 0xdd, 0x23, 0x0a,
+ 0x23, 0x38, 0x23, 0x66, 0x23, 0x94, 0x23, 0xc2,
+ 0x23, 0xf0, 0x24, 0x1f, 0x24, 0x4d, 0x24, 0x7c,
+ 0x24, 0xab, 0x24, 0xda, 0x25, 0x09, 0x25, 0x38,
+ 0x25, 0x68, 0x25, 0x97, 0x25, 0xc7, 0x25, 0xf7,
+ 0x26, 0x27, 0x26, 0x57, 0x26, 0x87, 0x26, 0xb7,
+ 0x26, 0xe8, 0x27, 0x18, 0x27, 0x49, 0x27, 0x7a,
+ 0x27, 0xab, 0x27, 0xdc, 0x28, 0x0d, 0x28, 0x3f,
+ 0x28, 0x71, 0x28, 0xa2, 0x28, 0xd4, 0x29, 0x06,
+ 0x29, 0x38, 0x29, 0x6b, 0x29, 0x9d, 0x29, 0xd0,
+ 0x2a, 0x02, 0x2a, 0x35, 0x2a, 0x68, 0x2a, 0x9b,
+ 0x2a, 0xcf, 0x2b, 0x02, 0x2b, 0x36, 0x2b, 0x69,
+ 0x2b, 0x9d, 0x2b, 0xd1, 0x2c, 0x05, 0x2c, 0x39,
+ 0x2c, 0x6e, 0x2c, 0xa2, 0x2c, 0xd7, 0x2d, 0x0c,
+ 0x2d, 0x41, 0x2d, 0x76, 0x2d, 0xab, 0x2d, 0xe1,
+ 0x2e, 0x16, 0x2e, 0x4c, 0x2e, 0x82, 0x2e, 0xb7,
+ 0x2e, 0xee, 0x2f, 0x24, 0x2f, 0x5a, 0x2f, 0x91,
+ 0x2f, 0xc7, 0x2f, 0xfe, 0x30, 0x35, 0x30, 0x6c,
+ 0x30, 0xa4, 0x30, 0xdb, 0x31, 0x12, 0x31, 0x4a,
+ 0x31, 0x82, 0x31, 0xba, 0x31, 0xf2, 0x32, 0x2a,
+ 0x32, 0x63, 0x32, 0x9b, 0x32, 0xd4, 0x33, 0x0d,
+ 0x33, 0x46, 0x33, 0x7f, 0x33, 0xb8, 0x33, 0xf1,
+ 0x34, 0x2b, 0x34, 0x65, 0x34, 0x9e, 0x34, 0xd8,
+ 0x35, 0x13, 0x35, 0x4d, 0x35, 0x87, 0x35, 0xc2,
+ 0x35, 0xfd, 0x36, 0x37, 0x36, 0x72, 0x36, 0xae,
+ 0x36, 0xe9, 0x37, 0x24, 0x37, 0x60, 0x37, 0x9c,
+ 0x37, 0xd7, 0x38, 0x14, 0x38, 0x50, 0x38, 0x8c,
+ 0x38, 0xc8, 0x39, 0x05, 0x39, 0x42, 0x39, 0x7f,
+ 0x39, 0xbc, 0x39, 0xf9, 0x3a, 0x36, 0x3a, 0x74,
+ 0x3a, 0xb2, 0x3a, 0xef, 0x3b, 0x2d, 0x3b, 0x6b,
+ 0x3b, 0xaa, 0x3b, 0xe8, 0x3c, 0x27, 0x3c, 0x65,
+ 0x3c, 0xa4, 0x3c, 0xe3, 0x3d, 0x22, 0x3d, 0x61,
+ 0x3d, 0xa1, 0x3d, 0xe0, 0x3e, 0x20, 0x3e, 0x60,
+ 0x3e, 0xa0, 0x3e, 0xe0, 0x3f, 0x21, 0x3f, 0x61,
+ 0x3f, 0xa2, 0x3f, 0xe2, 0x40, 0x23, 0x40, 0x64,
+ 0x40, 0xa6, 0x40, 0xe7, 0x41, 0x29, 0x41, 0x6a,
+ 0x41, 0xac, 0x41, 0xee, 0x42, 0x30, 0x42, 0x72,
+ 0x42, 0xb5, 0x42, 0xf7, 0x43, 0x3a, 0x43, 0x7d,
+ 0x43, 0xc0, 0x44, 0x03, 0x44, 0x47, 0x44, 0x8a,
+ 0x44, 0xce, 0x45, 0x12, 0x45, 0x55, 0x45, 0x9a,
+ 0x45, 0xde, 0x46, 0x22, 0x46, 0x67, 0x46, 0xab,
+ 0x46, 0xf0, 0x47, 0x35, 0x47, 0x7b, 0x47, 0xc0,
+ 0x48, 0x05, 0x48, 0x4b, 0x48, 0x91, 0x48, 0xd7,
+ 0x49, 0x1d, 0x49, 0x63, 0x49, 0xa9, 0x49, 0xf0,
+ 0x4a, 0x37, 0x4a, 0x7d, 0x4a, 0xc4, 0x4b, 0x0c,
+ 0x4b, 0x53, 0x4b, 0x9a, 0x4b, 0xe2, 0x4c, 0x2a,
+ 0x4c, 0x72, 0x4c, 0xba, 0x4d, 0x02, 0x4d, 0x4a,
+ 0x4d, 0x93, 0x4d, 0xdc, 0x4e, 0x25, 0x4e, 0x6e,
+ 0x4e, 0xb7, 0x4f, 0x00, 0x4f, 0x49, 0x4f, 0x93,
+ 0x4f, 0xdd, 0x50, 0x27, 0x50, 0x71, 0x50, 0xbb,
+ 0x51, 0x06, 0x51, 0x50, 0x51, 0x9b, 0x51, 0xe6,
+ 0x52, 0x31, 0x52, 0x7c, 0x52, 0xc7, 0x53, 0x13,
+ 0x53, 0x5f, 0x53, 0xaa, 0x53, 0xf6, 0x54, 0x42,
+ 0x54, 0x8f, 0x54, 0xdb, 0x55, 0x28, 0x55, 0x75,
+ 0x55, 0xc2, 0x56, 0x0f, 0x56, 0x5c, 0x56, 0xa9,
+ 0x56, 0xf7, 0x57, 0x44, 0x57, 0x92, 0x57, 0xe0,
+ 0x58, 0x2f, 0x58, 0x7d, 0x58, 0xcb, 0x59, 0x1a,
+ 0x59, 0x69, 0x59, 0xb8, 0x5a, 0x07, 0x5a, 0x56,
+ 0x5a, 0xa6, 0x5a, 0xf5, 0x5b, 0x45, 0x5b, 0x95,
+ 0x5b, 0xe5, 0x5c, 0x35, 0x5c, 0x86, 0x5c, 0xd6,
+ 0x5d, 0x27, 0x5d, 0x78, 0x5d, 0xc9, 0x5e, 0x1a,
+ 0x5e, 0x6c, 0x5e, 0xbd, 0x5f, 0x0f, 0x5f, 0x61,
+ 0x5f, 0xb3, 0x60, 0x05, 0x60, 0x57, 0x60, 0xaa,
+ 0x60, 0xfc, 0x61, 0x4f, 0x61, 0xa2, 0x61, 0xf5,
+ 0x62, 0x49, 0x62, 0x9c, 0x62, 0xf0, 0x63, 0x43,
+ 0x63, 0x97, 0x63, 0xeb, 0x64, 0x40, 0x64, 0x94,
+ 0x64, 0xe9, 0x65, 0x3d, 0x65, 0x92, 0x65, 0xe7,
+ 0x66, 0x3d, 0x66, 0x92, 0x66, 0xe8, 0x67, 0x3d,
+ 0x67, 0x93, 0x67, 0xe9, 0x68, 0x3f, 0x68, 0x96,
+ 0x68, 0xec, 0x69, 0x43, 0x69, 0x9a, 0x69, 0xf1,
+ 0x6a, 0x48, 0x6a, 0x9f, 0x6a, 0xf7, 0x6b, 0x4f,
+ 0x6b, 0xa7, 0x6b, 0xff, 0x6c, 0x57, 0x6c, 0xaf,
+ 0x6d, 0x08, 0x6d, 0x60, 0x6d, 0xb9, 0x6e, 0x12,
+ 0x6e, 0x6b, 0x6e, 0xc4, 0x6f, 0x1e, 0x6f, 0x78,
+ 0x6f, 0xd1, 0x70, 0x2b, 0x70, 0x86, 0x70, 0xe0,
+ 0x71, 0x3a, 0x71, 0x95, 0x71, 0xf0, 0x72, 0x4b,
+ 0x72, 0xa6, 0x73, 0x01, 0x73, 0x5d, 0x73, 0xb8,
+ 0x74, 0x14, 0x74, 0x70, 0x74, 0xcc, 0x75, 0x28,
+ 0x75, 0x85, 0x75, 0xe1, 0x76, 0x3e, 0x76, 0x9b,
+ 0x76, 0xf8, 0x77, 0x56, 0x77, 0xb3, 0x78, 0x11,
+ 0x78, 0x6e, 0x78, 0xcc, 0x79, 0x2a, 0x79, 0x89,
+ 0x79, 0xe7, 0x7a, 0x46, 0x7a, 0xa5, 0x7b, 0x04,
+ 0x7b, 0x63, 0x7b, 0xc2, 0x7c, 0x21, 0x7c, 0x81,
+ 0x7c, 0xe1, 0x7d, 0x41, 0x7d, 0xa1, 0x7e, 0x01,
+ 0x7e, 0x62, 0x7e, 0xc2, 0x7f, 0x23, 0x7f, 0x84,
+ 0x7f, 0xe5, 0x80, 0x47, 0x80, 0xa8, 0x81, 0x0a,
+ 0x81, 0x6b, 0x81, 0xcd, 0x82, 0x30, 0x82, 0x92,
+ 0x82, 0xf4, 0x83, 0x57, 0x83, 0xba, 0x84, 0x1d,
+ 0x84, 0x80, 0x84, 0xe3, 0x85, 0x47, 0x85, 0xab,
+ 0x86, 0x0e, 0x86, 0x72, 0x86, 0xd7, 0x87, 0x3b,
+ 0x87, 0x9f, 0x88, 0x04, 0x88, 0x69, 0x88, 0xce,
+ 0x89, 0x33, 0x89, 0x99, 0x89, 0xfe, 0x8a, 0x64,
+ 0x8a, 0xca, 0x8b, 0x30, 0x8b, 0x96, 0x8b, 0xfc,
+ 0x8c, 0x63, 0x8c, 0xca, 0x8d, 0x31, 0x8d, 0x98,
+ 0x8d, 0xff, 0x8e, 0x66, 0x8e, 0xce, 0x8f, 0x36,
+ 0x8f, 0x9e, 0x90, 0x06, 0x90, 0x6e, 0x90, 0xd6,
+ 0x91, 0x3f, 0x91, 0xa8, 0x92, 0x11, 0x92, 0x7a,
+ 0x92, 0xe3, 0x93, 0x4d, 0x93, 0xb6, 0x94, 0x20,
+ 0x94, 0x8a, 0x94, 0xf4, 0x95, 0x5f, 0x95, 0xc9,
+ 0x96, 0x34, 0x96, 0x9f, 0x97, 0x0a, 0x97, 0x75,
+ 0x97, 0xe0, 0x98, 0x4c, 0x98, 0xb8, 0x99, 0x24,
+ 0x99, 0x90, 0x99, 0xfc, 0x9a, 0x68, 0x9a, 0xd5,
+ 0x9b, 0x42, 0x9b, 0xaf, 0x9c, 0x1c, 0x9c, 0x89,
+ 0x9c, 0xf7, 0x9d, 0x64, 0x9d, 0xd2, 0x9e, 0x40,
+ 0x9e, 0xae, 0x9f, 0x1d, 0x9f, 0x8b, 0x9f, 0xfa,
+ 0xa0, 0x69, 0xa0, 0xd8, 0xa1, 0x47, 0xa1, 0xb6,
+ 0xa2, 0x26, 0xa2, 0x96, 0xa3, 0x06, 0xa3, 0x76,
+ 0xa3, 0xe6, 0xa4, 0x56, 0xa4, 0xc7, 0xa5, 0x38,
+ 0xa5, 0xa9, 0xa6, 0x1a, 0xa6, 0x8b, 0xa6, 0xfd,
+ 0xa7, 0x6e, 0xa7, 0xe0, 0xa8, 0x52, 0xa8, 0xc4,
+ 0xa9, 0x37, 0xa9, 0xa9, 0xaa, 0x1c, 0xaa, 0x8f,
+ 0xab, 0x02, 0xab, 0x75, 0xab, 0xe9, 0xac, 0x5c,
+ 0xac, 0xd0, 0xad, 0x44, 0xad, 0xb8, 0xae, 0x2d,
+ 0xae, 0xa1, 0xaf, 0x16, 0xaf, 0x8b, 0xb0, 0x00,
+ 0xb0, 0x75, 0xb0, 0xea, 0xb1, 0x60, 0xb1, 0xd6,
+ 0xb2, 0x4b, 0xb2, 0xc2, 0xb3, 0x38, 0xb3, 0xae,
+ 0xb4, 0x25, 0xb4, 0x9c, 0xb5, 0x13, 0xb5, 0x8a,
+ 0xb6, 0x01, 0xb6, 0x79, 0xb6, 0xf0, 0xb7, 0x68,
+ 0xb7, 0xe0, 0xb8, 0x59, 0xb8, 0xd1, 0xb9, 0x4a,
+ 0xb9, 0xc2, 0xba, 0x3b, 0xba, 0xb5, 0xbb, 0x2e,
+ 0xbb, 0xa7, 0xbc, 0x21, 0xbc, 0x9b, 0xbd, 0x15,
+ 0xbd, 0x8f, 0xbe, 0x0a, 0xbe, 0x84, 0xbe, 0xff,
+ 0xbf, 0x7a, 0xbf, 0xf5, 0xc0, 0x70, 0xc0, 0xec,
+ 0xc1, 0x67, 0xc1, 0xe3, 0xc2, 0x5f, 0xc2, 0xdb,
+ 0xc3, 0x58, 0xc3, 0xd4, 0xc4, 0x51, 0xc4, 0xce,
+ 0xc5, 0x4b, 0xc5, 0xc8, 0xc6, 0x46, 0xc6, 0xc3,
+ 0xc7, 0x41, 0xc7, 0xbf, 0xc8, 0x3d, 0xc8, 0xbc,
+ 0xc9, 0x3a, 0xc9, 0xb9, 0xca, 0x38, 0xca, 0xb7,
+ 0xcb, 0x36, 0xcb, 0xb6, 0xcc, 0x35, 0xcc, 0xb5,
+ 0xcd, 0x35, 0xcd, 0xb5, 0xce, 0x36, 0xce, 0xb6,
+ 0xcf, 0x37, 0xcf, 0xb8, 0xd0, 0x39, 0xd0, 0xba,
+ 0xd1, 0x3c, 0xd1, 0xbe, 0xd2, 0x3f, 0xd2, 0xc1,
+ 0xd3, 0x44, 0xd3, 0xc6, 0xd4, 0x49, 0xd4, 0xcb,
+ 0xd5, 0x4e, 0xd5, 0xd1, 0xd6, 0x55, 0xd6, 0xd8,
+ 0xd7, 0x5c, 0xd7, 0xe0, 0xd8, 0x64, 0xd8, 0xe8,
+ 0xd9, 0x6c, 0xd9, 0xf1, 0xda, 0x76, 0xda, 0xfb,
+ 0xdb, 0x80, 0xdc, 0x05, 0xdc, 0x8a, 0xdd, 0x10,
+ 0xdd, 0x96, 0xde, 0x1c, 0xde, 0xa2, 0xdf, 0x29,
+ 0xdf, 0xaf, 0xe0, 0x36, 0xe0, 0xbd, 0xe1, 0x44,
+ 0xe1, 0xcc, 0xe2, 0x53, 0xe2, 0xdb, 0xe3, 0x63,
+ 0xe3, 0xeb, 0xe4, 0x73, 0xe4, 0xfc, 0xe5, 0x84,
+ 0xe6, 0x0d, 0xe6, 0x96, 0xe7, 0x1f, 0xe7, 0xa9,
+ 0xe8, 0x32, 0xe8, 0xbc, 0xe9, 0x46, 0xe9, 0xd0,
+ 0xea, 0x5b, 0xea, 0xe5, 0xeb, 0x70, 0xeb, 0xfb,
+ 0xec, 0x86, 0xed, 0x11, 0xed, 0x9c, 0xee, 0x28,
+ 0xee, 0xb4, 0xef, 0x40, 0xef, 0xcc, 0xf0, 0x58,
+ 0xf0, 0xe5, 0xf1, 0x72, 0xf1, 0xff, 0xf2, 0x8c,
+ 0xf3, 0x19, 0xf3, 0xa7, 0xf4, 0x34, 0xf4, 0xc2,
+ 0xf5, 0x50, 0xf5, 0xde, 0xf6, 0x6d, 0xf6, 0xfb,
+ 0xf7, 0x8a, 0xf8, 0x19, 0xf8, 0xa8, 0xf9, 0x38,
+ 0xf9, 0xc7, 0xfa, 0x57, 0xfa, 0xe7, 0xfb, 0x77,
+ 0xfc, 0x07, 0xfc, 0x98, 0xfd, 0x29, 0xfd, 0xba,
+ 0xfe, 0x4b, 0xfe, 0xdc, 0xff, 0x6d, 0xff, 0xff
+};
+
+int jas_iccprofdata_srgblen = sizeof(jas_iccprofdata_srgb);
+
+uchar jas_iccprofdata_sgray[] = {
+ 0x00, 0x00, 0x01, 0x8a, 0x00, 0x00, 0x00, 0x00,
+ 0x02, 0x20, 0x00, 0x00, 0x73, 0x63, 0x6e, 0x72,
+ 0x47, 0x52, 0x41, 0x59, 0x58, 0x59, 0x5a, 0x20,
+ 0x07, 0xd3, 0x00, 0x01, 0x00, 0x1f, 0x00, 0x0d,
+ 0x00, 0x35, 0x00, 0x21, 0x61, 0x63, 0x73, 0x70,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x4b, 0x4f, 0x44, 0x41, 0x73, 0x47, 0x72, 0x79,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d,
+ 0x4a, 0x50, 0x45, 0x47, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x04, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x86,
+ 0x63, 0x70, 0x72, 0x74, 0x00, 0x00, 0x01, 0x3c,
+ 0x00, 0x00, 0x00, 0x2b, 0x77, 0x74, 0x70, 0x74,
+ 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x00, 0x14,
+ 0x6b, 0x54, 0x52, 0x43, 0x00, 0x00, 0x01, 0x7c,
+ 0x00, 0x00, 0x00, 0x0e, 0x64, 0x65, 0x73, 0x63,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
+ 0x52, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74,
+ 0x65, 0x64, 0x20, 0x49, 0x43, 0x43, 0x20, 0x70,
+ 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x64,
+ 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x69, 0x6e,
+ 0x67, 0x20, 0x73, 0x52, 0x47, 0x42, 0x2d, 0x67,
+ 0x72, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74,
+ 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70, 0x79,
+ 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x32, 0x30,
+ 0x30, 0x33, 0x20, 0x73, 0x52, 0x47, 0x42, 0x2d,
+ 0x67, 0x72, 0x65, 0x79, 0x20, 0x52, 0x65, 0x66,
+ 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x00, 0x00,
+ 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xf3, 0x54, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x01, 0x16, 0xcf, 0x63, 0x75, 0x72, 0x76,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x01, 0xcd
+};
+
+int jas_iccprofdata_sgraylen = sizeof(jas_iccprofdata_sgray);
diff --git a/osframework/source/ImageLib/jpeg2000/jas_image.c b/osframework/source/ImageLib/jpeg2000/jas_image.c
new file mode 100644
index 0000000..f0dadd0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_image.c
@@ -0,0 +1,1493 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Image Library
+ *
+ * $Id: jas_image.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <ctype.h>
+
+#include "jas_math.h"
+#include "jas_image.h"
+#include "jas_malloc.h"
+#include "jas_string.h"
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+#define FLOORDIV(x, y) ((x) / (y))
+
+/******************************************************************************\
+* Local prototypes.
+\******************************************************************************/
+
+static jas_image_cmpt_t *jas_image_cmpt_create0(void);
+static void jas_image_cmpt_destroy(jas_image_cmpt_t *cmpt);
+static jas_image_cmpt_t *jas_image_cmpt_create(uint_fast32_t tlx, uint_fast32_t tly,
+ uint_fast32_t hstep, uint_fast32_t vstep, uint_fast32_t width, uint_fast32_t
+ height, uint_fast16_t depth, bool sgnd, uint_fast32_t inmem);
+static void jas_image_setbbox(jas_image_t *image);
+static jas_image_cmpt_t *jas_image_cmpt_copy(jas_image_cmpt_t *cmpt);
+static int jas_image_growcmpts(jas_image_t *image, int maxcmpts);
+static uint_fast32_t inttobits(jas_seqent_t v, int prec, bool sgnd);
+static jas_seqent_t bitstoint(uint_fast32_t v, int prec, bool sgnd);
+static int putint(jas_stream_t *out, int sgnd, int prec, long val);
+static int getint(jas_stream_t *in, int sgnd, int prec, long *val);
+static void jas_image_calcbbox2(jas_image_t *image, jas_image_coord_t *tlx,
+ jas_image_coord_t *tly, jas_image_coord_t *brx, jas_image_coord_t *bry);
+static long uptomult(long x, long y);
+static long downtomult(long x, long y);
+static long convert(long val, int oldsgnd, int oldprec, int newsgnd,
+ int newprec);
+static void jas_image_calcbbox2(jas_image_t *image, jas_image_coord_t *tlx,
+ jas_image_coord_t *tly, jas_image_coord_t *brx, jas_image_coord_t *bry);
+
+/******************************************************************************\
+* Global data.
+\******************************************************************************/
+
+static int jas_image_numfmts = 0;
+static jas_image_fmtinfo_t jas_image_fmtinfos[JAS_IMAGE_MAXFMTS];
+
+/******************************************************************************\
+* Create and destroy operations.
+\******************************************************************************/
+
+jas_image_t *jas_image_create(int numcmpts, jas_image_cmptparm_t *cmptparms,
+ int clrspc)
+{
+ jas_image_t *image;
+ uint_fast32_t rawsize;
+ uint_fast32_t inmem;
+ int cmptno;
+ jas_image_cmptparm_t *cmptparm;
+
+ if (!(image = jas_image_create0())) {
+ return 0;
+ }
+
+ image->clrspc_ = clrspc;
+ image->maxcmpts_ = numcmpts;
+ image->inmem_ = true;
+
+ /* Allocate memory for the per-component information. */
+ if (!(image->cmpts_ = jas_malloc(image->maxcmpts_ *
+ sizeof(jas_image_cmpt_t *)))) {
+ jas_image_destroy(image);
+ return 0;
+ }
+ /* Initialize in case of failure. */
+ for (cmptno = 0; cmptno < image->maxcmpts_; ++cmptno) {
+ image->cmpts_[cmptno] = 0;
+ }
+
+ /* Compute the approximate raw size of the image. */
+ rawsize = 0;
+ for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno,
+ ++cmptparm) {
+ rawsize += cmptparm->width * cmptparm->height *
+ (cmptparm->prec + 7) / 8;
+ }
+ /* Decide whether to buffer the image data in memory, based on the
+ raw size of the image. */
+ inmem = (rawsize < JAS_IMAGE_INMEMTHRESH);
+
+ /* Create the individual image components. */
+ for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno,
+ ++cmptparm) {
+ if (!(image->cmpts_[cmptno] = jas_image_cmpt_create(cmptparm->tlx,
+ cmptparm->tly, cmptparm->hstep, cmptparm->vstep,
+ cmptparm->width, cmptparm->height, cmptparm->prec,
+ cmptparm->sgnd, inmem))) {
+ jas_image_destroy(image);
+ return 0;
+ }
+ ++image->numcmpts_;
+ }
+
+ /* Determine the bounding box for all of the components on the
+ reference grid (i.e., the image area) */
+ jas_image_setbbox(image);
+
+ return image;
+}
+
+jas_image_t *jas_image_create0()
+{
+ jas_image_t *image;
+
+ if (!(image = jas_malloc(sizeof(jas_image_t)))) {
+ return 0;
+ }
+
+ image->tlx_ = 0;
+ image->tly_ = 0;
+ image->brx_ = 0;
+ image->bry_ = 0;
+ image->clrspc_ = JAS_CLRSPC_UNKNOWN;
+ image->numcmpts_ = 0;
+ image->maxcmpts_ = 0;
+ image->cmpts_ = 0;
+ image->inmem_ = true;
+ image->cmprof_ = 0;
+
+ return image;
+}
+
+jas_image_t *jas_image_copy(jas_image_t *image)
+{
+ jas_image_t *newimage;
+ int cmptno;
+
+ newimage = jas_image_create0();
+ if (jas_image_growcmpts(newimage, image->numcmpts_)) {
+ goto error;
+ }
+ for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) {
+ if (!(newimage->cmpts_[cmptno] = jas_image_cmpt_copy(image->cmpts_[cmptno]))) {
+ goto error;
+ }
+ ++newimage->numcmpts_;
+ }
+
+ jas_image_setbbox(newimage);
+
+ if (image->cmprof_) {
+ if (!(newimage->cmprof_ = jas_cmprof_copy(image->cmprof_)))
+ goto error;
+ }
+
+ return newimage;
+error:
+ if (newimage) {
+ jas_image_destroy(newimage);
+ }
+ return 0;
+}
+
+static jas_image_cmpt_t *jas_image_cmpt_create0()
+{
+ jas_image_cmpt_t *cmpt;
+ if (!(cmpt = jas_malloc(sizeof(jas_image_cmpt_t)))) {
+ return 0;
+ }
+ memset(cmpt, 0, sizeof(jas_image_cmpt_t));
+ cmpt->type_ = JAS_IMAGE_CT_UNKNOWN;
+ return cmpt;
+}
+
+static jas_image_cmpt_t *jas_image_cmpt_copy(jas_image_cmpt_t *cmpt)
+{
+ jas_image_cmpt_t *newcmpt;
+
+ if (!(newcmpt = jas_image_cmpt_create0())) {
+ return 0;
+ }
+ newcmpt->tlx_ = cmpt->tlx_;
+ newcmpt->tly_ = cmpt->tly_;
+ newcmpt->hstep_ = cmpt->hstep_;
+ newcmpt->vstep_ = cmpt->vstep_;
+ newcmpt->width_ = cmpt->width_;
+ newcmpt->height_ = cmpt->height_;
+ newcmpt->prec_ = cmpt->prec_;
+ newcmpt->sgnd_ = cmpt->sgnd_;
+ newcmpt->cps_ = cmpt->cps_;
+ newcmpt->type_ = cmpt->type_;
+ if (!(newcmpt->stream_ = jas_stream_memopen(0, 0))) {
+ return 0;
+ }
+ if (jas_stream_seek(cmpt->stream_, 0, SEEK_SET)) {
+ return 0;
+ }
+ if (jas_stream_copy(newcmpt->stream_, cmpt->stream_, -1)) {
+ return 0;
+ }
+ if (jas_stream_seek(newcmpt->stream_, 0, SEEK_SET)) {
+ return 0;
+ }
+ return newcmpt;
+}
+
+void jas_image_destroy(jas_image_t *image)
+{
+ int i;
+
+ if (image->cmpts_) {
+ for (i = 0; i < image->numcmpts_; ++i) {
+ jas_image_cmpt_destroy(image->cmpts_[i]);
+ image->cmpts_[i] = 0;
+ }
+ jas_free(image->cmpts_);
+ }
+ if (image->cmprof_)
+ jas_cmprof_destroy(image->cmprof_);
+ jas_free(image);
+}
+
+static jas_image_cmpt_t *jas_image_cmpt_create(uint_fast32_t tlx, uint_fast32_t tly,
+ uint_fast32_t hstep, uint_fast32_t vstep, uint_fast32_t width, uint_fast32_t
+ height, uint_fast16_t depth, bool sgnd, uint_fast32_t inmem)
+{
+ jas_image_cmpt_t *cmpt;
+ long size;
+
+ if (!(cmpt = jas_malloc(sizeof(jas_image_cmpt_t)))) {
+ return 0;
+ }
+
+ cmpt->tlx_ = tlx;
+ cmpt->tly_ = tly;
+ cmpt->hstep_ = hstep;
+ cmpt->vstep_ = vstep;
+ cmpt->width_ = width;
+ cmpt->height_ = height;
+ cmpt->prec_ = depth;
+ cmpt->sgnd_ = sgnd;
+ cmpt->stream_ = 0;
+ cmpt->cps_ = (depth + 7) / 8;
+
+ size = cmpt->width_ * cmpt->height_ * cmpt->cps_;
+ cmpt->stream_ = (inmem) ? jas_stream_memopen(0, size) : jas_stream_tmpfile();
+ if (!cmpt->stream_) {
+ jas_image_cmpt_destroy(cmpt);
+ return 0;
+ }
+
+ /* Zero the component data. This isn't necessary, but it is
+ convenient for debugging purposes. */
+ if (jas_stream_seek(cmpt->stream_, size - 1, SEEK_SET) < 0 ||
+ jas_stream_putc(cmpt->stream_, 0) == EOF ||
+ jas_stream_seek(cmpt->stream_, 0, SEEK_SET) < 0) {
+ jas_image_cmpt_destroy(cmpt);
+ return 0;
+ }
+
+ return cmpt;
+}
+
+static void jas_image_cmpt_destroy(jas_image_cmpt_t *cmpt)
+{
+ if (cmpt->stream_) {
+ jas_stream_close(cmpt->stream_);
+ }
+ jas_free(cmpt);
+}
+
+/******************************************************************************\
+* Load and save operations.
+\******************************************************************************/
+
+jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ jas_image_t *image;
+
+ image = 0;
+
+ /* If possible, try to determine the format of the input data. */
+ if (fmt < 0) {
+ if ((fmt = jas_image_getfmt(in)) < 0)
+ goto error;
+ }
+
+ /* Is it possible to decode an image represented in this format? */
+ if (!(fmtinfo = jas_image_lookupfmtbyid(fmt)))
+ goto error;
+ if (!fmtinfo->ops.decode)
+ goto error;
+
+ /* Decode the image. */
+ if (!(image = (*fmtinfo->ops.decode)(in, optstr)))
+ goto error;
+
+ /* Create a color profile if needed. */
+ if (!jas_clrspc_isunknown(image->clrspc_) &&
+ !jas_clrspc_isgeneric(image->clrspc_) && !image->cmprof_) {
+ if (!(image->cmprof_ =
+ jas_cmprof_createfromclrspc(jas_image_clrspc(image))))
+ goto error;
+ }
+
+ return image;
+error:
+ if (image)
+ jas_image_destroy(image);
+ return 0;
+}
+
+int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, char *optstr)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) {
+ return -1;
+ }
+ return (fmtinfo->ops.encode) ? (*fmtinfo->ops.encode)(image, out,
+ optstr) : (-1);
+}
+
+/******************************************************************************\
+* Component read and write operations.
+\******************************************************************************/
+
+int jas_image_readcmpt(jas_image_t *image, int cmptno, jas_image_coord_t x,
+ jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ jas_matrix_t *data)
+{
+ jas_image_cmpt_t *cmpt;
+ jas_image_coord_t i;
+ jas_image_coord_t j;
+ int k;
+ jas_seqent_t v;
+ int c;
+ jas_seqent_t *dr;
+ jas_seqent_t *d;
+ int drs;
+
+ if (cmptno < 0 || cmptno >= image->numcmpts_) {
+ return -1;
+ }
+
+ cmpt = image->cmpts_[cmptno];
+ if (x >= cmpt->width_ || y >= cmpt->height_ ||
+ x + width > cmpt->width_ ||
+ y + height > cmpt->height_) {
+ return -1;
+ }
+
+ if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) {
+ if (jas_matrix_resize(data, height, width)) {
+ return -1;
+ }
+ }
+
+ dr = jas_matrix_getref(data, 0, 0);
+ drs = jas_matrix_rowstep(data);
+ for (i = 0; i < height; ++i, dr += drs) {
+ d = dr;
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x)
+ * cmpt->cps_, SEEK_SET) < 0) {
+ return -1;
+ }
+ for (j = width; j > 0; --j, ++d) {
+ v = 0;
+ for (k = cmpt->cps_; k > 0; --k) {
+ if ((c = jas_stream_getc(cmpt->stream_)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | (c & 0xff);
+ }
+ *d = bitstoint(v, cmpt->prec_, cmpt->sgnd_);
+ }
+ }
+
+ return 0;
+}
+
+int jas_image_writecmpt(jas_image_t *image, int cmptno, jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width,
+ jas_image_coord_t height, jas_matrix_t *data)
+{
+ jas_image_cmpt_t *cmpt;
+ jas_image_coord_t i;
+ jas_image_coord_t j;
+ jas_seqent_t *d;
+ jas_seqent_t *dr;
+ int drs;
+ jas_seqent_t v;
+ int k;
+ int c;
+
+ if (cmptno < 0 || cmptno >= image->numcmpts_) {
+ return -1;
+ }
+
+ cmpt = image->cmpts_[cmptno];
+ if (x >= cmpt->width_ || y >= cmpt->height_ ||
+ x + width > cmpt->width_ ||
+ y + height > cmpt->height_) {
+ return -1;
+ }
+
+ if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) {
+ return -1;
+ }
+
+ dr = jas_matrix_getref(data, 0, 0);
+ drs = jas_matrix_rowstep(data);
+ for (i = 0; i < height; ++i, dr += drs) {
+ d = dr;
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x)
+ * cmpt->cps_, SEEK_SET) < 0) {
+ return -1;
+ }
+ for (j = width; j > 0; --j, ++d) {
+ v = inttobits(*d, cmpt->prec_, cmpt->sgnd_);
+ for (k = cmpt->cps_; k > 0; --k) {
+ c = (v >> (8 * (cmpt->cps_ - 1))) & 0xff;
+ if (jas_stream_putc(cmpt->stream_,
+ (unsigned char) c) == EOF) {
+ return -1;
+ }
+ v <<= 8;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* File format operations.
+\******************************************************************************/
+
+void jas_image_clearfmts()
+{
+ int i;
+ jas_image_fmtinfo_t *fmtinfo;
+ for (i = 0; i < jas_image_numfmts; ++i) {
+ fmtinfo = &jas_image_fmtinfos[i];
+ if (fmtinfo->name) {
+ jas_free(fmtinfo->name);
+ fmtinfo->name = 0;
+ }
+ if (fmtinfo->ext) {
+ jas_free(fmtinfo->ext);
+ fmtinfo->ext = 0;
+ }
+ if (fmtinfo->desc) {
+ jas_free(fmtinfo->desc);
+ fmtinfo->desc = 0;
+ }
+ }
+ jas_image_numfmts = 0;
+}
+
+int jas_image_addfmt(int id, char *name, char *ext, char *desc,
+ jas_image_fmtops_t *ops)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ assert(id >= 0 && name && ext && ops);
+ if (jas_image_numfmts >= JAS_IMAGE_MAXFMTS) {
+ return -1;
+ }
+ fmtinfo = &jas_image_fmtinfos[jas_image_numfmts];
+ fmtinfo->id = id;
+ if (!(fmtinfo->name = jas_strdup(name))) {
+ return -1;
+ }
+ if (!(fmtinfo->ext = jas_strdup(ext))) {
+ jas_free(fmtinfo->name);
+ return -1;
+ }
+ if (!(fmtinfo->desc = jas_strdup(desc))) {
+ jas_free(fmtinfo->name);
+ jas_free(fmtinfo->ext);
+ return -1;
+ }
+ fmtinfo->ops = *ops;
+ ++jas_image_numfmts;
+ return 0;
+}
+
+int jas_image_strtofmt(char *name)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ if (!(fmtinfo = jas_image_lookupfmtbyname(name))) {
+ return -1;
+ }
+ return fmtinfo->id;
+}
+
+char *jas_image_fmttostr(int fmt)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) {
+ return 0;
+ }
+ return fmtinfo->name;
+}
+
+int jas_image_getfmt(jas_stream_t *in)
+{
+ jas_image_fmtinfo_t *fmtinfo;
+ int found;
+ int i;
+
+ /* Check for data in each of the supported formats. */
+ found = 0;
+ for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i,
+ ++fmtinfo) {
+ if (fmtinfo->ops.validate) {
+ /* Is the input data valid for this format? */
+ if (!(*fmtinfo->ops.validate)(in)) {
+ found = 1;
+ break;
+ }
+ }
+ }
+ return found ? fmtinfo->id : (-1);
+}
+
+int jas_image_fmtfromname(char *name)
+{
+ int i;
+ char *ext;
+ jas_image_fmtinfo_t *fmtinfo;
+ /* Get the file name extension. */
+ if (!(ext = strrchr(name, '.'))) {
+ return -1;
+ }
+ ++ext;
+ /* Try to find a format that uses this extension. */
+ for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i,
+ ++fmtinfo) {
+ /* Do we have a match? */
+ if (!strcmp(ext, fmtinfo->ext)) {
+ return fmtinfo->id;
+ }
+ }
+ return -1;
+}
+
+/******************************************************************************\
+* Miscellaneous operations.
+\******************************************************************************/
+
+uint_fast32_t jas_image_rawsize(jas_image_t *image)
+{
+ uint_fast32_t rawsize;
+ int cmptno;
+ jas_image_cmpt_t *cmpt;
+
+ rawsize = 0;
+ for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) {
+ cmpt = image->cmpts_[cmptno];
+ rawsize += (cmpt->width_ * cmpt->height_ * cmpt->prec_ +
+ 7) / 8;
+ }
+ return rawsize;
+}
+
+void jas_image_delcmpt(jas_image_t *image, int cmptno)
+{
+ if (cmptno >= image->numcmpts_) {
+ return;
+ }
+ jas_image_cmpt_destroy(image->cmpts_[cmptno]);
+ if (cmptno < image->numcmpts_) {
+ memmove(&image->cmpts_[cmptno], &image->cmpts_[cmptno + 1],
+ (image->numcmpts_ - 1 - cmptno) * sizeof(jas_image_cmpt_t *));
+ }
+ --image->numcmpts_;
+
+ jas_image_setbbox(image);
+}
+
+int jas_image_addcmpt(jas_image_t *image, int cmptno,
+ jas_image_cmptparm_t *cmptparm)
+{
+ jas_image_cmpt_t *newcmpt;
+ if (cmptno < 0)
+ cmptno = image->numcmpts_;
+ assert(cmptno >= 0 && cmptno <= image->numcmpts_);
+ if (image->numcmpts_ >= image->maxcmpts_) {
+ if (jas_image_growcmpts(image, image->maxcmpts_ + 128)) {
+ return -1;
+ }
+ }
+ if (!(newcmpt = jas_image_cmpt_create(cmptparm->tlx,
+ cmptparm->tly, cmptparm->hstep, cmptparm->vstep,
+ cmptparm->width, cmptparm->height, cmptparm->prec,
+ cmptparm->sgnd, 1))) {
+ return -1;
+ }
+ if (cmptno < image->numcmpts_) {
+ memmove(&image->cmpts_[cmptno + 1], &image->cmpts_[cmptno],
+ (image->numcmpts_ - cmptno) * sizeof(jas_image_cmpt_t *));
+ }
+ image->cmpts_[cmptno] = newcmpt;
+ ++image->numcmpts_;
+
+ jas_image_setbbox(image);
+
+ return 0;
+}
+
+jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id)
+{
+ int i;
+ jas_image_fmtinfo_t *fmtinfo;
+
+ for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, ++fmtinfo) {
+ if (fmtinfo->id == id) {
+ return fmtinfo;
+ }
+ }
+ return 0;
+}
+
+jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name)
+{
+ int i;
+ jas_image_fmtinfo_t *fmtinfo;
+
+ for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, ++fmtinfo) {
+ if (!strcmp(fmtinfo->name, name)) {
+ return fmtinfo;
+ }
+ }
+ return 0;
+}
+
+
+
+
+
+static uint_fast32_t inttobits(jas_seqent_t v, int prec, bool sgnd)
+{
+ uint_fast32_t ret;
+ ret = ((sgnd && v < 0) ? ((1 << prec) + v) : v) & JAS_ONES(prec);
+ return ret;
+}
+
+static jas_seqent_t bitstoint(uint_fast32_t v, int prec, bool sgnd)
+{
+ jas_seqent_t ret;
+ v &= JAS_ONES(prec);
+ ret = (sgnd && (v & (1 << (prec - 1)))) ? (v - (1 << prec)) : v;
+ return ret;
+}
+
+static void jas_image_setbbox(jas_image_t *image)
+{
+ jas_image_cmpt_t *cmpt;
+ int cmptno;
+ int_fast32_t x;
+ int_fast32_t y;
+
+ if (image->numcmpts_ > 0) {
+ /* Determine the bounding box for all of the components on the
+ reference grid (i.e., the image area) */
+ cmpt = image->cmpts_[0];
+ image->tlx_ = cmpt->tlx_;
+ image->tly_ = cmpt->tly_;
+ image->brx_ = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1) + 1;
+ image->bry_ = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1) + 1;
+ for (cmptno = 1; cmptno < image->numcmpts_; ++cmptno) {
+ cmpt = image->cmpts_[cmptno];
+ if (image->tlx_ > cmpt->tlx_) {
+ image->tlx_ = cmpt->tlx_;
+ }
+ if (image->tly_ > cmpt->tly_) {
+ image->tly_ = cmpt->tly_;
+ }
+ x = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1) + 1;
+ if (image->brx_ < x) {
+ image->brx_ = x;
+ }
+ y = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1) + 1;
+ if (image->bry_ < y) {
+ image->bry_ = y;
+ }
+ }
+ } else {
+ image->tlx_ = 0;
+ image->tly_ = 0;
+ image->brx_ = 0;
+ image->bry_ = 0;
+ }
+}
+
+static int jas_image_growcmpts(jas_image_t *image, int maxcmpts)
+{
+ jas_image_cmpt_t **newcmpts;
+ int cmptno;
+
+ newcmpts = (!image->cmpts_) ? jas_malloc(maxcmpts * sizeof(jas_image_cmpt_t *)) :
+ jas_realloc(image->cmpts_, maxcmpts * sizeof(jas_image_cmpt_t *));
+ if (!newcmpts) {
+ return -1;
+ }
+ image->cmpts_ = newcmpts;
+ image->maxcmpts_ = maxcmpts;
+ for (cmptno = image->numcmpts_; cmptno < image->maxcmpts_; ++cmptno) {
+ image->cmpts_[cmptno] = 0;
+ }
+ return 0;
+}
+
+int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno, jas_image_t *srcimage,
+ int srccmptno)
+{
+ jas_image_cmpt_t *newcmpt;
+ if (dstimage->numcmpts_ >= dstimage->maxcmpts_) {
+ if (jas_image_growcmpts(dstimage, dstimage->maxcmpts_ + 128)) {
+ return -1;
+ }
+ }
+ if (!(newcmpt = jas_image_cmpt_copy(srcimage->cmpts_[srccmptno]))) {
+ return -1;
+ }
+ if (dstcmptno < dstimage->numcmpts_) {
+ memmove(&dstimage->cmpts_[dstcmptno + 1], &dstimage->cmpts_[dstcmptno],
+ (dstimage->numcmpts_ - dstcmptno) * sizeof(jas_image_cmpt_t *));
+ }
+ dstimage->cmpts_[dstcmptno] = newcmpt;
+ ++dstimage->numcmpts_;
+
+ jas_image_setbbox(dstimage);
+ return 0;
+}
+
+void jas_image_dump(jas_image_t *image, FILE *out)
+{
+ long buf[1024];
+ int cmptno;
+ int n;
+ int i;
+ int width;
+ int height;
+ jas_image_cmpt_t *cmpt;
+ for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) {
+ cmpt = image->cmpts_[cmptno];
+ fprintf(out, "prec=%d, sgnd=%d, cmpttype=%d\n", cmpt->prec_,
+ cmpt->sgnd_, cmpt->type_);
+ width = jas_image_cmptwidth(image, cmptno);
+ height = jas_image_cmptheight(image, cmptno);
+ n = JAS_MIN(16, width);
+ if (jas_image_readcmpt2(image, cmptno, 0, 0, n, 1, buf)) {
+ abort();
+ }
+ for (i = 0; i < n; ++i) {
+ fprintf(out, " f(%d,%d)=%ld", i, 0, buf[i]);
+ }
+ fprintf(out, "\n");
+ if (jas_image_readcmpt2(image, cmptno, width - n, height - 1, n, 1, buf)) {
+ abort();
+ }
+ for (i = 0; i < n; ++i) {
+ fprintf(out, " f(%d,%d)=%ld", width - n + i, height - 1, buf[i]);
+ }
+ fprintf(out, "\n");
+ }
+}
+
+int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,
+ int_fast32_t *lutents, int dtype, int newcmptno)
+{
+ jas_image_cmptparm_t cmptparms;
+ int_fast32_t v;
+ int i;
+ int j;
+ jas_image_cmpt_t *cmpt;
+
+ cmpt = image->cmpts_[cmptno];
+ cmptparms.tlx = cmpt->tlx_;
+ cmptparms.tly = cmpt->tly_;
+ cmptparms.hstep = cmpt->hstep_;
+ cmptparms.vstep = cmpt->vstep_;
+ cmptparms.width = cmpt->width_;
+ cmptparms.height = cmpt->height_;
+ cmptparms.prec = JAS_IMAGE_CDT_GETPREC(dtype);
+ cmptparms.sgnd = JAS_IMAGE_CDT_GETSGND(dtype);
+
+ if (jas_image_addcmpt(image, newcmptno, &cmptparms)) {
+ return -1;
+ }
+ if (newcmptno <= cmptno) {
+ ++cmptno;
+ cmpt = image->cmpts_[cmptno];
+ }
+
+ for (j = 0; j < cmpt->height_; ++j) {
+ for (i = 0; i < cmpt->width_; ++i) {
+ v = jas_image_readcmptsample(image, cmptno, i, j);
+ if (v < 0) {
+ v = 0;
+ } else if (v >= numlutents) {
+ v = numlutents - 1;
+ }
+ jas_image_writecmptsample(image, newcmptno, i, j,
+ lutents[v]);
+ }
+ }
+ return 0;
+}
+
+int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y)
+{
+ jas_image_cmpt_t *cmpt;
+ uint_fast32_t v;
+ int k;
+ int c;
+
+ cmpt = image->cmpts_[cmptno];
+
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_,
+ SEEK_SET) < 0) {
+ return -1;
+ }
+ v = 0;
+ for (k = cmpt->cps_; k > 0; --k) {
+ if ((c = jas_stream_getc(cmpt->stream_)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | (c & 0xff);
+ }
+ return bitstoint(v, cmpt->prec_, cmpt->sgnd_);
+}
+
+void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y,
+ int_fast32_t v)
+{
+ jas_image_cmpt_t *cmpt;
+ uint_fast32_t t;
+ int k;
+ int c;
+
+ cmpt = image->cmpts_[cmptno];
+
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_,
+ SEEK_SET) < 0) {
+ return;
+ }
+ t = inttobits(v, cmpt->prec_, cmpt->sgnd_);
+ for (k = cmpt->cps_; k > 0; --k) {
+ c = (t >> (8 * (cmpt->cps_ - 1))) & 0xff;
+ if (jas_stream_putc(cmpt->stream_, (unsigned char) c) == EOF) {
+ return;
+ }
+ t <<= 8;
+ }
+}
+
+int jas_image_getcmptbytype(jas_image_t *image, int ctype)
+{
+ int cmptno;
+
+ for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) {
+ if (image->cmpts_[cmptno]->type_ == ctype) {
+ return cmptno;
+ }
+ }
+ return -1;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/***********************************************/
+/***********************************************/
+/***********************************************/
+/***********************************************/
+
+int jas_image_readcmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
+ jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ long *buf)
+{
+ jas_image_cmpt_t *cmpt;
+ jas_image_coord_t i;
+ jas_image_coord_t j;
+ long v;
+ long *bufptr;
+
+ if (cmptno < 0 || cmptno >= image->numcmpts_)
+ goto error;
+ cmpt = image->cmpts_[cmptno];
+ if (x < 0 || x >= cmpt->width_ || y < 0 || y >= cmpt->height_ ||
+ width < 0 || height < 0 || x + width > cmpt->width_ ||
+ y + height > cmpt->height_)
+ goto error;
+
+ bufptr = buf;
+ for (i = 0; i < height; ++i) {
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x)
+ * cmpt->cps_, SEEK_SET) < 0)
+ goto error;
+ for (j = 0; j < width; ++j) {
+ if (getint(cmpt->stream_, cmpt->sgnd_, cmpt->prec_, &v))
+ goto error;
+ *bufptr++ = v;
+ }
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+int jas_image_writecmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
+ jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ long *buf)
+{
+ jas_image_cmpt_t *cmpt;
+ jas_image_coord_t i;
+ jas_image_coord_t j;
+ long v;
+ long *bufptr;
+
+ if (cmptno < 0 || cmptno >= image->numcmpts_)
+ goto error;
+ cmpt = image->cmpts_[cmptno];
+ if (x < 0 || x >= cmpt->width_ || y < 0 || y >= cmpt->height_ ||
+ width < 0 || height < 0 || x + width > cmpt->width_ ||
+ y + height > cmpt->height_)
+ goto error;
+
+ bufptr = buf;
+ for (i = 0; i < height; ++i) {
+ if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x)
+ * cmpt->cps_, SEEK_SET) < 0)
+ goto error;
+ for (j = 0; j < width; ++j) {
+ v = *bufptr++;
+ if (putint(cmpt->stream_, cmpt->sgnd_, cmpt->prec_, v))
+ goto error;
+ }
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+int jas_image_sampcmpt(jas_image_t *image, int cmptno, int newcmptno,
+ jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs,
+ jas_image_coord_t vs, int sgnd, int prec)
+{
+ jas_image_cmpt_t *oldcmpt;
+ jas_image_cmpt_t *newcmpt;
+ int width;
+ int height;
+ jas_image_coord_t tlx;
+ jas_image_coord_t tly;
+ jas_image_coord_t brx;
+ jas_image_coord_t bry;
+ int i;
+ int j;
+ jas_image_cmptparm_t cmptparm;
+ jas_image_coord_t ax;
+ jas_image_coord_t ay;
+ jas_image_coord_t bx;
+ jas_image_coord_t by;
+ jas_image_coord_t d0;
+ jas_image_coord_t d1;
+ jas_image_coord_t d2;
+ jas_image_coord_t d3;
+ jas_image_coord_t oldx;
+ jas_image_coord_t oldy;
+ jas_image_coord_t x;
+ jas_image_coord_t y;
+ long v;
+ jas_image_coord_t cmptbrx;
+ jas_image_coord_t cmptbry;
+
+ assert(cmptno >= 0 && cmptno < image->numcmpts_);
+ oldcmpt = image->cmpts_[cmptno];
+ assert(oldcmpt->tlx_ == 0 && oldcmpt->tly_ == 0);
+ jas_image_calcbbox2(image, &tlx, &tly, &brx, &bry);
+ width = FLOORDIV(brx - ho + hs, hs);
+ height = FLOORDIV(bry - vo + vs, vs);
+ cmptparm.tlx = ho;
+ cmptparm.tly = vo;
+ cmptparm.hstep = hs;
+ cmptparm.vstep = vs;
+ cmptparm.width = width;
+ cmptparm.height = height;
+ cmptparm.prec = prec;
+ cmptparm.sgnd = sgnd;
+ if (jas_image_addcmpt(image, newcmptno, &cmptparm))
+ goto error;
+cmptbrx = oldcmpt->tlx_ + (oldcmpt->width_ - 1) * oldcmpt->hstep_;
+cmptbry = oldcmpt->tly_ + (oldcmpt->height_ - 1) * oldcmpt->vstep_;
+ newcmpt = image->cmpts_[newcmptno];
+ jas_stream_rewind(newcmpt->stream_);
+ for (i = 0; i < height; ++i) {
+ y = newcmpt->tly_ + newcmpt->vstep_ * i;
+ for (j = 0; j < width; ++j) {
+ x = newcmpt->tlx_ + newcmpt->hstep_ * j;
+ ax = downtomult(x - oldcmpt->tlx_, oldcmpt->hstep_) + oldcmpt->tlx_;
+ ay = downtomult(y - oldcmpt->tly_, oldcmpt->vstep_) + oldcmpt->tly_;
+ bx = uptomult(x - oldcmpt->tlx_, oldcmpt->hstep_) + oldcmpt->tlx_;
+ if (bx > cmptbrx)
+ bx = cmptbrx;
+ by = uptomult(y - oldcmpt->tly_, oldcmpt->vstep_) + oldcmpt->tly_;
+ if (by > cmptbry)
+ by = cmptbry;
+ d0 = (ax - x) * (ax - x) + (ay - y) * (ay - y);
+ d1 = (bx - x) * (bx - x) + (ay - y) * (ay - y);
+ d2 = (bx - x) * (bx - x) + (by - y) * (by - y);
+ d3 = (ax - x) * (ax - x) + (by - y) * (by - y);
+ if (d0 <= d1 && d0 <= d2 && d0 <= d3) {
+ oldx = (ax - oldcmpt->tlx_) / oldcmpt->hstep_;
+ oldy = (ay - oldcmpt->tly_) / oldcmpt->vstep_;
+ } else if (d1 <= d0 && d1 <= d2 && d1 <= d3) {
+ oldx = (bx - oldcmpt->tlx_) / oldcmpt->hstep_;
+ oldy = (ay - oldcmpt->tly_) / oldcmpt->vstep_;
+ } else if (d2 <= d0 && d2 <= d1 && d1 <= d3) {
+ oldx = (bx - oldcmpt->tlx_) / oldcmpt->hstep_;
+ oldy = (by - oldcmpt->tly_) / oldcmpt->vstep_;
+ } else {
+ oldx = (ax - oldcmpt->tlx_) / oldcmpt->hstep_;
+ oldy = (by - oldcmpt->tly_) / oldcmpt->vstep_;
+ }
+ assert(oldx >= 0 && oldx < oldcmpt->width_ &&
+ oldy >= 0 && oldy < oldcmpt->height_);
+ if (jas_stream_seek(oldcmpt->stream_, oldcmpt->cps_ *
+ (oldy * oldcmpt->width_ + oldx), SEEK_SET) < 0)
+ goto error;
+ if (getint(oldcmpt->stream_, oldcmpt->sgnd_,
+ oldcmpt->prec_, &v))
+ goto error;
+ if (newcmpt->prec_ != oldcmpt->prec_ ||
+ newcmpt->sgnd_ != oldcmpt->sgnd_) {
+ v = convert(v, oldcmpt->sgnd_, oldcmpt->prec_,
+ newcmpt->sgnd_, newcmpt->prec_);
+ }
+ if (putint(newcmpt->stream_, newcmpt->sgnd_,
+ newcmpt->prec_, v))
+ goto error;
+ }
+ }
+ return 0;
+error:
+ return -1;
+}
+
+int jas_image_ishomosamp(jas_image_t *image)
+{
+ jas_image_coord_t hstep;
+ jas_image_coord_t vstep;
+ int result;
+ int i;
+ hstep = jas_image_cmpthstep(image, 0);
+ vstep = jas_image_cmptvstep(image, 0);
+ result = 1;
+ for (i = 0; i < image->numcmpts_; ++i) {
+ if (jas_image_cmpthstep(image, i) != hstep ||
+ jas_image_cmptvstep(image, i) != vstep) {
+ result = 0;
+ break;
+ }
+ }
+ return result;
+}
+
+/* Note: This function defines a bounding box differently. */
+static void jas_image_calcbbox2(jas_image_t *image, jas_image_coord_t *tlx,
+ jas_image_coord_t *tly, jas_image_coord_t *brx, jas_image_coord_t *bry)
+{
+ jas_image_cmpt_t *cmpt;
+ jas_image_coord_t tmptlx;
+ jas_image_coord_t tmptly;
+ jas_image_coord_t tmpbrx;
+ jas_image_coord_t tmpbry;
+ jas_image_coord_t t;
+ int i;
+ if (image->numcmpts_ > 0) {
+ cmpt = image->cmpts_[0];
+ tmptlx = cmpt->tlx_;
+ tmptly = cmpt->tly_;
+ tmpbrx = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1);
+ tmpbry = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1);
+ for (i = 0; i < image->numcmpts_; ++i) {
+ cmpt = image->cmpts_[i];
+ if (cmpt->tlx_ < tmptlx)
+ tmptlx = cmpt->tlx_;
+ if (cmpt->tly_ < tmptly)
+ tmptly = cmpt->tly_;
+ t = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1);
+ if (t > tmpbrx)
+ tmpbrx = t;
+ t = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1);
+ if (t > tmpbry)
+ tmpbry = t;
+ }
+ } else {
+ tmptlx = 0;
+ tmptly = 0;
+ tmpbrx = -1;
+ tmpbry = -1;
+ }
+ *tlx = tmptlx;
+ *tly = tmptly;
+ *brx = tmpbrx;
+ *bry = tmpbry;
+}
+
+
+
+static int getint(jas_stream_t *in, int sgnd, int prec, long *val)
+{
+ long v;
+ int n;
+ int c;
+ n = (prec + 7) / 8;
+ v = 0;
+ while (--n >= 0) {
+ if ((c = jas_stream_getc(in)) == EOF)
+ return -1;
+ v = (v << 8) | c;
+ }
+ v &= ((1 << prec) - 1);
+ if (sgnd) {
+ /* XXX - Do something here. */
+ abort();
+ } else {
+ *val = v;
+ }
+ return 0;
+}
+
+static int putint(jas_stream_t *out, int sgnd, int prec, long val)
+{
+ int n;
+ int c;
+ if (sgnd) {
+ /* XXX - Do something here. */
+ abort();
+ }
+ val &= (1 << prec) - 1;
+ n = (prec + 7) / 8;
+ while (--n >= 0) {
+ c = (val >> (n * 8)) & 0xff;
+ if (jas_stream_putc(out, c) != c)
+ return -1;
+ }
+ return 0;
+}
+
+static long convert(long val, int oldsgnd, int oldprec, int newsgnd,
+ int newprec)
+{
+ if (newsgnd != oldsgnd) {
+ }
+ if (newprec != oldprec) {
+ if (newprec > oldprec) {
+ val <<= newprec - oldprec;
+ } else if (oldprec > newprec) {
+ val >>= oldprec - newprec;
+ }
+ }
+ return val;
+}
+
+static long downtomult(long x, long y)
+{
+ assert(x >= 0);
+ return (x / y) * y;
+}
+
+static long uptomult(long x, long y)
+{
+ assert(x >= 0);
+ return ((x + y - 1) / y) * y;
+}
+
+jas_image_t *jas_image_chclrspc(jas_image_t *image, jas_cmprof_t *outprof,
+ int intent)
+{
+ jas_image_t *inimage;
+ int minhstep;
+ int minvstep;
+ int i;
+ int j;
+ int k;
+ int n;
+ int hstep;
+ int vstep;
+ int numinauxchans;
+ int numoutauxchans;
+ int numinclrchans;
+ int numoutclrchans;
+ int prec;
+ jas_image_t *outimage;
+ int cmpttype;
+ int numoutchans;
+ jas_cmprof_t *inprof;
+ jas_cmprof_t *tmpprof;
+ jas_image_cmptparm_t cmptparm;
+ int width;
+ int height;
+ jas_cmxform_t *xform;
+ jas_cmpixmap_t inpixmap;
+ jas_cmpixmap_t outpixmap;
+ jas_cmcmptfmt_t *incmptfmts;
+ jas_cmcmptfmt_t *outcmptfmts;
+
+#if 0
+fprintf(stderr, "IMAGE\n");
+jas_image_dump(image, stderr);
+#endif
+
+ if (!(inimage = jas_image_copy(image)))
+ goto error;
+ image = 0;
+
+ if (!jas_image_ishomosamp(inimage)) {
+ minhstep = jas_image_cmpthstep(inimage, 0);
+ minvstep = jas_image_cmptvstep(inimage, 0);
+ for (i = 1; i < jas_image_numcmpts(inimage); ++i) {
+ hstep = jas_image_cmpthstep(inimage, i);
+ vstep = jas_image_cmptvstep(inimage, i);
+ if (hstep < minhstep)
+ minhstep = hstep;
+ if (vstep < minvstep)
+ minvstep = vstep;
+ }
+ n = jas_image_numcmpts(inimage);
+ for (i = 0; i < n; ++i) {
+ cmpttype = jas_image_cmpttype(inimage, i);
+ if (jas_image_sampcmpt(inimage, i, i + 1, 0, 0, minhstep, minvstep, jas_image_cmptsgnd(inimage, i), jas_image_cmptprec(inimage, i)))
+ goto error;
+ jas_image_setcmpttype(inimage, i + 1, cmpttype);
+ jas_image_delcmpt(inimage, i);
+ }
+ }
+
+ width = jas_image_cmptwidth(inimage, 0);
+ height = jas_image_cmptheight(inimage, 0);
+ hstep = jas_image_cmpthstep(inimage, 0);
+ vstep = jas_image_cmptvstep(inimage, 0);
+
+ inprof = jas_image_cmprof(inimage);
+ assert(inprof);
+ numinclrchans = jas_clrspc_numchans(jas_cmprof_clrspc(inprof));
+ numinauxchans = jas_image_numcmpts(inimage) - numinclrchans;
+ numoutclrchans = jas_clrspc_numchans(jas_cmprof_clrspc(outprof));
+ numoutauxchans = 0;
+ numoutchans = numoutclrchans + numoutauxchans;
+ prec = 8;
+
+ if (!(outimage = jas_image_create0()))
+ goto error;
+
+ /* Create a component for each of the colorants. */
+ for (i = 0; i < numoutclrchans; ++i) {
+ cmptparm.tlx = 0;
+ cmptparm.tly = 0;
+ cmptparm.hstep = hstep;
+ cmptparm.vstep = vstep;
+ cmptparm.width = width;
+ cmptparm.height = height;
+ cmptparm.prec = prec;
+ cmptparm.sgnd = 0;
+ if (jas_image_addcmpt(outimage, -1, &cmptparm))
+ goto error;
+ jas_image_setcmpttype(outimage, i, JAS_IMAGE_CT_COLOR(i));
+ }
+#if 0
+ /* Copy the auxiliary components without modification. */
+ for (i = 0; i < jas_image_numcmpts(inimage); ++i) {
+ if (!ISCOLOR(jas_image_cmpttype(inimage, i))) {
+ jas_image_copycmpt(outimage, -1, inimage, i);
+/* XXX - need to specify laydown of component on ref. grid */
+ }
+ }
+#endif
+
+ if (!(tmpprof = jas_cmprof_copy(outprof)))
+ goto error;
+ assert(!jas_image_cmprof(outimage));
+ jas_image_setcmprof(outimage, tmpprof);
+ tmpprof = 0;
+ jas_image_setclrspc(outimage, jas_cmprof_clrspc(outprof));
+
+ if (!(xform = jas_cmxform_create(inprof, outprof, 0, JAS_CMXFORM_OP_FWD, intent, 0)))
+ goto error;
+
+ inpixmap.numcmpts = numinclrchans;
+ incmptfmts = malloc(numinclrchans * sizeof(jas_cmcmptfmt_t));
+ assert(incmptfmts);
+ inpixmap.cmptfmts = incmptfmts;
+ for (i = 0; i < numinclrchans; ++i) {
+ j = jas_image_getcmptbytype(inimage, JAS_IMAGE_CT_COLOR(i));
+ assert(j >= 0);
+ if (!(incmptfmts[i].buf = malloc(width * sizeof(long))))
+ goto error;
+ incmptfmts[i].prec = jas_image_cmptprec(inimage, j);
+ incmptfmts[i].sgnd = jas_image_cmptsgnd(inimage, j);
+ incmptfmts[i].width = width;
+ incmptfmts[i].height = 1;
+ }
+
+ outpixmap.numcmpts = numoutclrchans;
+ outcmptfmts = malloc(numoutclrchans * sizeof(jas_cmcmptfmt_t));
+ assert(outcmptfmts);
+ outpixmap.cmptfmts = outcmptfmts;
+
+ for (i = 0; i < numoutclrchans; ++i) {
+ j = jas_image_getcmptbytype(outimage, JAS_IMAGE_CT_COLOR(i));
+ assert(j >= 0);
+ if (!(outcmptfmts[i].buf = malloc(width * sizeof(long))))
+ goto error;
+ outcmptfmts[i].prec = jas_image_cmptprec(outimage, j);
+ outcmptfmts[i].sgnd = jas_image_cmptsgnd(outimage, j);
+ outcmptfmts[i].width = width;
+ outcmptfmts[i].height = 1;
+ }
+
+ for (i = 0; i < height; ++i) {
+ for (j = 0; j < numinclrchans; ++j) {
+ k = jas_image_getcmptbytype(inimage, JAS_IMAGE_CT_COLOR(j));
+ if (jas_image_readcmpt2(inimage, k, 0, i, width, 1, incmptfmts[j].buf))
+ goto error;
+ }
+ jas_cmxform_apply(xform, &inpixmap, &outpixmap);
+ for (j = 0; j < numoutclrchans; ++j) {
+ k = jas_image_getcmptbytype(outimage, JAS_IMAGE_CT_COLOR(j));
+ if (jas_image_writecmpt2(outimage, k, 0, i, width, 1, outcmptfmts[j].buf))
+ goto error;
+ }
+ }
+
+ for (i = 0; i < numoutclrchans; ++i)
+ jas_free(outcmptfmts[i].buf);
+ jas_free(outcmptfmts);
+ for (i = 0; i < numinclrchans; ++i)
+ jas_free(incmptfmts[i].buf);
+ jas_free(incmptfmts);
+ jas_cmxform_destroy(xform);
+ jas_image_destroy(inimage);
+
+#if 0
+fprintf(stderr, "INIMAGE\n");
+jas_image_dump(inimage, stderr);
+fprintf(stderr, "OUTIMAGE\n");
+jas_image_dump(outimage, stderr);
+#endif
+ return outimage;
+error:
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_image.h b/osframework/source/ImageLib/jpeg2000/jas_image.h
new file mode 100644
index 0000000..a268672
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_image.h
@@ -0,0 +1,613 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Image Class
+ *
+ * $Id: jas_image.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_IMAGE_H
+#define JAS_IMAGE_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+#include "jas_stream.h"
+#include "jas_seq.h"
+#include "jas_cm.h"
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/*
+ * Miscellaneous constants.
+ */
+
+/* The threshold at which image data is no longer stored in memory. */
+#define JAS_IMAGE_INMEMTHRESH (16 * 1024 * 1024)
+
+/*
+ * Component types
+ */
+
+#define JAS_IMAGE_CT_UNKNOWN 0x10000
+#define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff)
+#define JAS_IMAGE_CT_OPACITY 0x08000
+
+#define JAS_IMAGE_CT_RGB_R 0
+#define JAS_IMAGE_CT_RGB_G 1
+#define JAS_IMAGE_CT_RGB_B 2
+
+#define JAS_IMAGE_CT_YCBCR_Y 0
+#define JAS_IMAGE_CT_YCBCR_CB 1
+#define JAS_IMAGE_CT_YCBCR_CR 2
+
+#define JAS_IMAGE_CT_GRAY_Y 0
+
+/******************************************************************************\
+* Simple types.
+\******************************************************************************/
+
+/* Image coordinate. */
+typedef int_fast32_t jas_image_coord_t;
+
+/* Color space (e.g., RGB, YCbCr). */
+typedef int_fast16_t jas_image_colorspc_t;
+
+/* Component type (e.g., color, opacity). */
+typedef int_fast32_t jas_image_cmpttype_t;
+
+/* Component sample data format (e.g., real/integer, signedness, precision). */
+typedef int_fast16_t jas_image_smpltype_t;
+
+/******************************************************************************\
+* Image class and supporting classes.
+\******************************************************************************/
+
+/* Image component class. */
+
+typedef struct {
+
+ jas_image_coord_t tlx_;
+ /* The x-coordinate of the top-left corner of the component. */
+
+ jas_image_coord_t tly_;
+ /* The y-coordinate of the top-left corner of the component. */
+
+ jas_image_coord_t hstep_;
+ /* The horizontal sampling period in units of the reference grid. */
+
+ jas_image_coord_t vstep_;
+ /* The vertical sampling period in units of the reference grid. */
+
+ jas_image_coord_t width_;
+ /* The component width in samples. */
+
+ jas_image_coord_t height_;
+ /* The component height in samples. */
+
+#ifdef FIX_ME
+ int smpltype_;
+#else
+ int prec_;
+ /* The precision of the sample data (i.e., the number of bits per
+ sample). If the samples are signed values, this quantity
+ includes the sign bit. */
+
+ int sgnd_;
+ /* The signedness of the sample data. */
+#endif
+
+ jas_stream_t *stream_;
+ /* The stream containing the component data. */
+
+ int cps_;
+ /* The number of characters per sample in the stream. */
+
+ jas_image_cmpttype_t type_;
+ /* The type of component (e.g., opacity, red, green, blue, luma). */
+
+} jas_image_cmpt_t;
+
+/* Image class. */
+
+typedef struct {
+
+ jas_image_coord_t tlx_;
+ /* The x-coordinate of the top-left corner of the image bounding box. */
+
+ jas_image_coord_t tly_;
+ /* The y-coordinate of the top-left corner of the image bounding box. */
+
+ jas_image_coord_t brx_;
+ /* The x-coordinate of the bottom-right corner of the image bounding
+ box (plus one). */
+
+ jas_image_coord_t bry_;
+ /* The y-coordinate of the bottom-right corner of the image bounding
+ box (plus one). */
+
+ int numcmpts_;
+ /* The number of components. */
+
+ int maxcmpts_;
+ /* The maximum number of components that this image can have (i.e., the
+ allocated size of the components array). */
+
+ jas_image_cmpt_t **cmpts_;
+ /* Per-component information. */
+
+ jas_clrspc_t clrspc_;
+
+ jas_cmprof_t *cmprof_;
+
+ bool inmem_;
+
+} jas_image_t;
+
+/* Component parameters class. */
+/* This data type exists solely/mainly for the purposes of the
+ jas_image_create function. */
+
+typedef struct {
+
+ jas_image_coord_t tlx;
+ /* The x-coordinate of the top-left corner of the component. */
+
+ jas_image_coord_t tly;
+ /* The y-coordinate of the top-left corner of the component. */
+
+ jas_image_coord_t hstep;
+ /* The horizontal sampling period in units of the reference grid. */
+
+ jas_image_coord_t vstep;
+ /* The vertical sampling period in units of the reference grid. */
+
+ jas_image_coord_t width;
+ /* The width of the component in samples. */
+
+ jas_image_coord_t height;
+ /* The height of the component in samples. */
+
+#ifdef FIX_ME
+ int smpltype;
+#else
+ int prec;
+ /* The precision of the component sample data. */
+
+ int sgnd;
+ /* The signedness of the component sample data. */
+#endif
+
+} jas_image_cmptparm_t;
+
+/******************************************************************************\
+* File format related classes.
+\******************************************************************************/
+
+#define JAS_IMAGE_MAXFMTS 32
+/* The maximum number of image data formats supported. */
+
+/* Image format-dependent operations. */
+
+typedef struct {
+
+ jas_image_t *(*decode)(jas_stream_t *in, char *opts);
+ /* Decode image data from a stream. */
+
+ int (*encode)(jas_image_t *image, jas_stream_t *out, char *opts);
+ /* Encode image data to a stream. */
+
+ int (*validate)(jas_stream_t *in);
+ /* Determine if stream data is in a particular format. */
+
+} jas_image_fmtops_t;
+
+/* Image format information. */
+
+typedef struct {
+
+ int id;
+ /* The ID for this format. */
+
+ char *name;
+ /* The name by which this format is identified. */
+
+ char *ext;
+ /* The file name extension associated with this format. */
+
+ char *desc;
+ /* A brief description of the format. */
+
+ jas_image_fmtops_t ops;
+ /* The operations for this format. */
+
+} jas_image_fmtinfo_t;
+
+/******************************************************************************\
+* Image operations.
+\******************************************************************************/
+
+/* Create an image. */
+jas_image_t *jas_image_create(int numcmpts,
+ jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc);
+
+/* Create an "empty" image. */
+jas_image_t *jas_image_create0(void);
+
+/* Clone an image. */
+jas_image_t *jas_image_copy(jas_image_t *image);
+
+/* Deallocate any resources associated with an image. */
+void jas_image_destroy(jas_image_t *image);
+
+/* Get the width of the image in units of the image reference grid. */
+#define jas_image_width(image) \
+ ((image)->brx_ - (image)->tlx_)
+
+/* Get the height of the image in units of the image reference grid. */
+#define jas_image_height(image) \
+ ((image)->bry_ - (image)->tly_)
+
+/* Get the x-coordinate of the top-left corner of the image bounding box
+ on the reference grid. */
+#define jas_image_tlx(image) \
+ ((image)->tlx_)
+
+/* Get the y-coordinate of the top-left corner of the image bounding box
+ on the reference grid. */
+#define jas_image_tly(image) \
+ ((image)->tly_)
+
+/* Get the x-coordinate of the bottom-right corner of the image bounding box
+ on the reference grid (plus one). */
+#define jas_image_brx(image) \
+ ((image)->brx_)
+
+/* Get the y-coordinate of the bottom-right corner of the image bounding box
+ on the reference grid (plus one). */
+#define jas_image_bry(image) \
+ ((image)->bry_)
+
+/* Get the number of image components. */
+#define jas_image_numcmpts(image) \
+ ((image)->numcmpts_)
+
+/* Get the color model used by the image. */
+#define jas_image_clrspc(image) \
+ ((image)->clrspc_)
+
+/* Set the color model for an image. */
+#define jas_image_setclrspc(image, clrspc) \
+ ((image)->clrspc_ = (clrspc))
+
+#define jas_image_cmpttype(image, cmptno) \
+ ((image)->cmpts_[(cmptno)]->type_)
+#define jas_image_setcmpttype(image, cmptno, type) \
+ ((image)->cmpts_[(cmptno)]->type_ = (type))
+
+/* Get the width of a component. */
+#define jas_image_cmptwidth(image, cmptno) \
+ ((image)->cmpts_[cmptno]->width_)
+
+/* Get the height of a component. */
+#define jas_image_cmptheight(image, cmptno) \
+ ((image)->cmpts_[cmptno]->height_)
+
+/* Get the signedness of the sample data for a component. */
+#define jas_image_cmptsgnd(image, cmptno) \
+ ((image)->cmpts_[cmptno]->sgnd_)
+
+/* Get the precision of the sample data for a component. */
+#define jas_image_cmptprec(image, cmptno) \
+ ((image)->cmpts_[cmptno]->prec_)
+
+/* Get the horizontal subsampling factor for a component. */
+#define jas_image_cmpthstep(image, cmptno) \
+ ((image)->cmpts_[cmptno]->hstep_)
+
+/* Get the vertical subsampling factor for a component. */
+#define jas_image_cmptvstep(image, cmptno) \
+ ((image)->cmpts_[cmptno]->vstep_)
+
+/* Get the x-coordinate of the top-left corner of a component. */
+#define jas_image_cmpttlx(image, cmptno) \
+ ((image)->cmpts_[cmptno]->tlx_)
+
+/* Get the y-coordinate of the top-left corner of a component. */
+#define jas_image_cmpttly(image, cmptno) \
+ ((image)->cmpts_[cmptno]->tly_)
+
+/* Get the x-coordinate of the bottom-right corner of a component
+ (plus "one"). */
+#define jas_image_cmptbrx(image, cmptno) \
+ ((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \
+ (image)->cmpts_[cmptno]->hstep_)
+
+/* Get the y-coordinate of the bottom-right corner of a component
+ (plus "one"). */
+#define jas_image_cmptbry(image, cmptno) \
+ ((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \
+ (image)->cmpts_[cmptno]->vstep_)
+
+/* Get the raw size of an image (i.e., the nominal size of the image without
+ any compression. */
+uint_fast32_t jas_image_rawsize(jas_image_t *image);
+
+/* Create an image from a stream in some specified format. */
+jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr);
+
+/* Write an image to a stream in a specified format. */
+int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt,
+ char *optstr);
+
+/* Read a rectangular region of an image component. */
+/* The position and size of the rectangular region to be read is specified
+relative to the component's coordinate system. */
+int jas_image_readcmpt(jas_image_t *image, int cmptno,
+ jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ jas_matrix_t *data);
+
+/* Write a rectangular region of an image component. */
+int jas_image_writecmpt(jas_image_t *image, int cmptno,
+ jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ jas_matrix_t *data);
+
+/* Delete a component from an image. */
+void jas_image_delcmpt(jas_image_t *image, int cmptno);
+
+/* Add a component to an image. */
+int jas_image_addcmpt(jas_image_t *image, int cmptno,
+ jas_image_cmptparm_t *cmptparm);
+
+/* Copy a component from one image to another. */
+int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno,
+ jas_image_t *srcimage, int srccmptno);
+
+#define JAS_IMAGE_CDT_GETSGND(dtype) (((dtype) >> 7) & 1)
+#define JAS_IMAGE_CDT_SETSGND(dtype) (((dtype) & 1) << 7)
+#define JAS_IMAGE_CDT_GETPREC(dtype) ((dtype) & 0x7f)
+#define JAS_IMAGE_CDT_SETPREC(dtype) ((dtype) & 0x7f)
+
+#define jas_image_cmptdtype(image, cmptno) \
+ (JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_))
+
+int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,
+ int_fast32_t *lutents, int dtype, int newcmptno);
+
+int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y);
+void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y,
+ int_fast32_t v);
+
+int jas_image_getcmptbytype(jas_image_t *image, int ctype);
+
+/******************************************************************************\
+* Image format-related operations.
+\******************************************************************************/
+
+/* Clear the table of image formats. */
+void jas_image_clearfmts(void);
+
+/* Add entry to table of image formats. */
+int jas_image_addfmt(int id, char *name, char *ext, char *desc,
+ jas_image_fmtops_t *ops);
+
+/* Get the ID for the image format with the specified name. */
+int jas_image_strtofmt(char *s);
+
+/* Get the name of the image format with the specified ID. */
+char *jas_image_fmttostr(int fmt);
+
+/* Lookup image format information by the format ID. */
+jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id);
+
+/* Lookup image format information by the format name. */
+jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name);
+
+/* Guess the format of an image file based on its name. */
+int jas_image_fmtfromname(char *filename);
+
+/* Get the format of image data in a stream. */
+int jas_image_getfmt(jas_stream_t *in);
+
+
+#define jas_image_cmprof(image) ((image)->cmprof_)
+int jas_image_ishomosamp(jas_image_t *image);
+int jas_image_sampcmpt(jas_image_t *image, int cmptno, int newcmptno,
+ jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs,
+ jas_image_coord_t vs, int sgnd, int prec);
+int jas_image_writecmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
+ jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ long *buf);
+int jas_image_readcmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
+ jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
+ long *buf);
+
+#define jas_image_setcmprof(image, cmprof) ((image)->cmprof_ = cmprof)
+jas_image_t *jas_image_chclrspc(jas_image_t *image, jas_cmprof_t *outprof,
+ int intent);
+void jas_image_dump(jas_image_t *image, FILE *out);
+
+/******************************************************************************\
+* Image format-dependent operations.
+\******************************************************************************/
+
+#if !defined(EXCLUDE_JPG_SUPPORT)
+/* Format-dependent operations for JPG support. */
+jas_image_t *jpg_decode(jas_stream_t *in, char *optstr);
+int jpg_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int jpg_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_MIF_SUPPORT)
+/* Format-dependent operations for MIF support. */
+jas_image_t *mif_decode(jas_stream_t *in, char *optstr);
+int mif_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int mif_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_PNM_SUPPORT)
+/* Format-dependent operations for PNM support. */
+jas_image_t *pnm_decode(jas_stream_t *in, char *optstr);
+int pnm_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int pnm_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_RAS_SUPPORT)
+/* Format-dependent operations for Sun Rasterfile support. */
+jas_image_t *ras_decode(jas_stream_t *in, char *optstr);
+int ras_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int ras_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_BMP_SUPPORT)
+/* Format-dependent operations for BMP support. */
+jas_image_t *bmp_decode(jas_stream_t *in, char *optstr);
+int bmp_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int bmp_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_JP2_SUPPORT)
+/* Format-dependent operations for JP2 support. */
+jas_image_t *jp2_decode(jas_stream_t *in, char *optstr);
+int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int jp2_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_JPC_SUPPORT)
+/* Format-dependent operations for JPEG-2000 code stream support. */
+jas_image_t *jpc_decode(jas_stream_t *in, char *optstr);
+int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int jpc_validate(jas_stream_t *in);
+#endif
+
+#if !defined(EXCLUDE_PGX_SUPPORT)
+/* Format-dependent operations for PGX support. */
+jas_image_t *pgx_decode(jas_stream_t *in, char *optstr);
+int pgx_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
+int pgx_validate(jas_stream_t *in);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_init.c b/osframework/source/ImageLib/jpeg2000/jas_init.c
new file mode 100644
index 0000000..ac9624e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_init.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+#include "jas_image.h"
+#include "jas_init.h"
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+/* Initialize the image format table. */
+int jas_init()
+{
+ jas_image_fmtops_t fmtops;
+ int fmtid;
+
+ fmtid = 0;
+
+#if !defined(EXCLUDE_MIF_SUPPORT)
+ fmtops.decode = mif_decode;
+ fmtops.encode = mif_encode;
+ fmtops.validate = mif_validate;
+ jas_image_addfmt(fmtid, "mif", "mif", "My Image Format (MIF)", &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_PNM_SUPPORT)
+ fmtops.decode = pnm_decode;
+ fmtops.encode = pnm_encode;
+ fmtops.validate = pnm_validate;
+ jas_image_addfmt(fmtid, "pnm", "pnm", "Portable Graymap/Pixmap (PNM)",
+ &fmtops);
+ jas_image_addfmt(fmtid, "pnm", "pgm", "Portable Graymap/Pixmap (PNM)",
+ &fmtops);
+ jas_image_addfmt(fmtid, "pnm", "ppm", "Portable Graymap/Pixmap (PNM)",
+ &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_BMP_SUPPORT)
+ fmtops.decode = bmp_decode;
+ fmtops.encode = bmp_encode;
+ fmtops.validate = bmp_validate;
+ jas_image_addfmt(fmtid, "bmp", "bmp", "Microsoft Bitmap (BMP)", &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_RAS_SUPPORT)
+ fmtops.decode = ras_decode;
+ fmtops.encode = ras_encode;
+ fmtops.validate = ras_validate;
+ jas_image_addfmt(fmtid, "ras", "ras", "Sun Rasterfile (RAS)", &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_JP2_SUPPORT)
+ fmtops.decode = jp2_decode;
+ fmtops.encode = jp2_encode;
+ fmtops.validate = jp2_validate;
+ jas_image_addfmt(fmtid, "jp2", "jp2",
+ "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops);
+ ++fmtid;
+ fmtops.decode = jpc_decode;
+ fmtops.encode = jpc_encode;
+ fmtops.validate = jpc_validate;
+ jas_image_addfmt(fmtid, "jpc", "jpc",
+ "JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)", &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_JPG_SUPPORT)
+ fmtops.decode = jpg_decode;
+ fmtops.encode = jpg_encode;
+ fmtops.validate = jpg_validate;
+ jas_image_addfmt(fmtid, "jpg", "jpg", "JPEG (ISO/IEC 10918-1)", &fmtops);
+ ++fmtid;
+#endif
+
+#if !defined(EXCLUDE_PGX_SUPPORT)
+ fmtops.decode = pgx_decode;
+ fmtops.encode = pgx_encode;
+ fmtops.validate = pgx_validate;
+ jas_image_addfmt(fmtid, "pgx", "pgx", "JPEG-2000 VM Format (PGX)", &fmtops);
+ ++fmtid;
+#endif
+
+ /* We must not register the JasPer library exit handler until after
+ at least one memory allocation is performed. This is desirable
+ as it ensures that the JasPer exit handler is called before the
+ debug memory allocator exit handler. */
+ atexit(jas_cleanup);
+
+ return 0;
+}
+
+void jas_cleanup()
+{
+ jas_image_clearfmts();
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_init.h b/osframework/source/ImageLib/jpeg2000/jas_init.h
new file mode 100644
index 0000000..bbe5334
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_init.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JAS_INIT_H
+#define JAS_INIT_H
+
+#include "jas_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+int jas_init(void);
+
+void jas_cleanup(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_malloc.c b/osframework/source/ImageLib/jpeg2000/jas_malloc.c
new file mode 100644
index 0000000..42b7669
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_malloc.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Memory Allocator
+ *
+ * $Id: jas_malloc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+
+/* We need the prototype for memset. */
+#include <string.h>
+
+#include "jas_malloc.h"
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+#if defined(DEBUG_MEMALLOC)
+#include "../../../local/src/memalloc.c"
+#endif
+
+#if !defined(DEBUG_MEMALLOC)
+
+void *jas_malloc(size_t size)
+{
+ return malloc(size);
+}
+
+void jas_free(void *ptr)
+{
+ free(ptr);
+}
+
+void *jas_realloc(void *ptr, size_t size)
+{
+ return realloc(ptr, size);
+}
+
+void *jas_calloc(size_t nmemb, size_t size)
+{
+ void *ptr;
+ size_t n;
+ n = nmemb * size;
+ if (!(ptr = jas_malloc(n * sizeof(char)))) {
+ return 0;
+ }
+ memset(ptr, 0, n);
+ return ptr;
+}
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_malloc.h b/osframework/source/ImageLib/jpeg2000/jas_malloc.h
new file mode 100644
index 0000000..fb45a0c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_malloc.h
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Memory Allocator
+ *
+ * $Id: jas_malloc.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_MALLOC_H
+#define JAS_MALLOC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Hack follows...
+\******************************************************************************/
+
+#if defined(DEBUG_MEMALLOC)
+/* This is somewhat of a hack, but it's a useful hack. :-) */
+/* Use my own custom memory allocator for debugging. */
+#include "../../../../local/src/memalloc.h"
+#define jas_malloc MEMALLOC
+#define jas_free MEMFREE
+#define jas_realloc MEMREALLOC
+#define jas_calloc MEMCALLOC
+#endif
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+#if !defined(DEBUG_MEMALLOC)
+
+/* Allocate memory. */
+void *jas_malloc(size_t size);
+
+/* Free memory. */
+void jas_free(void *ptr);
+
+/* Resize a block of allocated memory. */
+void *jas_realloc(void *ptr, size_t size);
+
+/* Allocate a block of memory and initialize the contents to zero. */
+void *jas_calloc(size_t nmemb, size_t size);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_math.h b/osframework/source/ImageLib/jpeg2000/jas_math.h
new file mode 100644
index 0000000..2bfba80
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_math.h
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Math-Related Code
+ *
+ * $Id: jas_math.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_MATH_H
+#define JAS_MATH_H
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include "jas_config.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Macros
+\******************************************************************************/
+
+/* Compute the absolute value. */
+#define JAS_ABS(x) \
+ (((x) >= 0) ? (x) : (-(x)))
+
+/* Compute the minimum of two values. */
+#define JAS_MIN(x, y) \
+ (((x) < (y)) ? (x) : (y))
+
+/* Compute the maximum of two values. */
+#define JAS_MAX(x, y) \
+ (((x) > (y)) ? (x) : (y))
+
+/* Compute the remainder from division (where division is defined such
+ that the remainder is always nonnegative). */
+#define JAS_MOD(x, y) \
+ (((x) < 0) ? (((-x) % (y)) ? ((y) - ((-(x)) % (y))) : (0)) : ((x) % (y)))
+
+/* Compute the integer with the specified number of least significant bits
+ set to one. */
+#define JAS_ONES(n) \
+ ((1 << (n)) - 1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_seq.c b/osframework/source/ImageLib/jpeg2000/jas_seq.c
new file mode 100644
index 0000000..771dc92
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_seq.c
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Sequence/Matrix Library
+ *
+ * $Id: jas_seq.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdlib.h>
+#include <assert.h>
+#include <math.h>
+
+#include "jas_seq.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+/******************************************************************************\
+* Constructors and destructors.
+\******************************************************************************/
+
+jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend)
+{
+ jas_matrix_t *matrix;
+ assert(xstart <= xend && ystart <= yend);
+ if (!(matrix = jas_matrix_create(yend - ystart, xend - xstart))) {
+ return 0;
+ }
+ matrix->xstart_ = xstart;
+ matrix->ystart_ = ystart;
+ matrix->xend_ = xend;
+ matrix->yend_ = yend;
+ return matrix;
+}
+
+jas_matrix_t *jas_matrix_create(int numrows, int numcols)
+{
+ jas_matrix_t *matrix;
+ int i;
+
+ if (!(matrix = jas_malloc(sizeof(jas_matrix_t)))) {
+ return 0;
+ }
+ matrix->flags_ = 0;
+ matrix->numrows_ = numrows;
+ matrix->numcols_ = numcols;
+ matrix->rows_ = 0;
+ matrix->maxrows_ = numrows;
+ matrix->data_ = 0;
+ matrix->datasize_ = numrows * numcols;
+
+ if (matrix->maxrows_ > 0) {
+ if (!(matrix->rows_ = jas_malloc(matrix->maxrows_ *
+ sizeof(jas_seqent_t *)))) {
+ jas_matrix_destroy(matrix);
+ return 0;
+ }
+ }
+
+ if (matrix->datasize_ > 0) {
+ if (!(matrix->data_ = jas_malloc(matrix->datasize_ *
+ sizeof(jas_seqent_t)))) {
+ jas_matrix_destroy(matrix);
+ return 0;
+ }
+ }
+
+ for (i = 0; i < numrows; ++i) {
+ matrix->rows_[i] = &matrix->data_[i * matrix->numcols_];
+ }
+
+ for (i = 0; i < matrix->datasize_; ++i) {
+ matrix->data_[i] = 0;
+ }
+
+ matrix->xstart_ = 0;
+ matrix->ystart_ = 0;
+ matrix->xend_ = matrix->numcols_;
+ matrix->yend_ = matrix->numrows_;
+
+ return matrix;
+}
+
+void jas_matrix_destroy(jas_matrix_t *matrix)
+{
+ if (matrix->data_) {
+ assert(!(matrix->flags_ & JAS_MATRIX_REF));
+ jas_free(matrix->data_);
+ matrix->data_ = 0;
+ }
+ if (matrix->rows_) {
+ jas_free(matrix->rows_);
+ matrix->rows_ = 0;
+ }
+ jas_free(matrix);
+}
+
+jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x)
+{
+ jas_matrix_t *y;
+ int i;
+ int j;
+ y = jas_seq2d_create(jas_seq2d_xstart(x), jas_seq2d_ystart(x), jas_seq2d_xend(x),
+ jas_seq2d_yend(x));
+ assert(y);
+ for (i = 0; i < x->numrows_; ++i) {
+ for (j = 0; j < x->numcols_; ++j) {
+ *jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j);
+ }
+ }
+ return y;
+}
+
+jas_matrix_t *jas_matrix_copy(jas_matrix_t *x)
+{
+ jas_matrix_t *y;
+ int i;
+ int j;
+ y = jas_matrix_create(x->numrows_, x->numcols_);
+ for (i = 0; i < x->numrows_; ++i) {
+ for (j = 0; j < x->numcols_; ++j) {
+ *jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j);
+ }
+ }
+ return y;
+}
+
+/******************************************************************************\
+* Bind operations.
+\******************************************************************************/
+
+void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart, int ystart,
+ int xend, int yend)
+{
+ jas_matrix_bindsub(s, s1, ystart - s1->ystart_, xstart - s1->xstart_,
+ yend - s1->ystart_ - 1, xend - s1->xstart_ - 1);
+}
+
+void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0,
+ int r1, int c1)
+{
+ int i;
+
+ if (mat0->data_) {
+ if (!(mat0->flags_ & JAS_MATRIX_REF)) {
+ jas_free(mat0->data_);
+ }
+ mat0->data_ = 0;
+ mat0->datasize_ = 0;
+ }
+ if (mat0->rows_) {
+ jas_free(mat0->rows_);
+ mat0->rows_ = 0;
+ }
+ mat0->flags_ |= JAS_MATRIX_REF;
+ mat0->numrows_ = r1 - r0 + 1;
+ mat0->numcols_ = c1 - c0 + 1;
+ mat0->maxrows_ = mat0->numrows_;
+ mat0->rows_ = jas_malloc(mat0->maxrows_ * sizeof(jas_seqent_t *));
+ for (i = 0; i < mat0->numrows_; ++i) {
+ mat0->rows_[i] = mat1->rows_[r0 + i] + c0;
+ }
+
+ mat0->xstart_ = mat1->xstart_ + c0;
+ mat0->ystart_ = mat1->ystart_ + r0;
+ mat0->xend_ = mat0->xstart_ + mat0->numcols_;
+ mat0->yend_ = mat0->ystart_ + mat0->numrows_;
+}
+
+/******************************************************************************\
+* Arithmetic operations.
+\******************************************************************************/
+
+int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1)
+{
+ int i;
+ int j;
+
+ if (mat0->numrows_ != mat1->numrows_ || mat0->numcols_ !=
+ mat1->numcols_) {
+ return 1;
+ }
+ for (i = 0; i < mat0->numrows_; i++) {
+ for (j = 0; j < mat0->numcols_; j++) {
+ if (jas_matrix_get(mat0, i, j) != jas_matrix_get(mat1, i, j)) {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+void jas_matrix_divpow2(jas_matrix_t *matrix, int n)
+{
+ int i;
+ int j;
+ jas_seqent_t *rowstart;
+ int rowstep;
+ jas_seqent_t *data;
+
+ rowstep = jas_matrix_rowstep(matrix);
+ for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
+ rowstart += rowstep) {
+ for (j = matrix->numcols_, data = rowstart; j > 0; --j,
+ ++data) {
+ *data = (*data >= 0) ? ((*data) >> n) :
+ (-((-(*data)) >> n));
+ }
+ }
+}
+
+void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval, jas_seqent_t maxval)
+{
+ int i;
+ int j;
+ jas_seqent_t v;
+ jas_seqent_t *rowstart;
+ jas_seqent_t *data;
+ int rowstep;
+
+ rowstep = jas_matrix_rowstep(matrix);
+ for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
+ rowstart += rowstep) {
+ data = rowstart;
+ for (j = matrix->numcols_, data = rowstart; j > 0; --j,
+ ++data) {
+ v = *data;
+ if (v < minval) {
+ *data = minval;
+ } else if (v > maxval) {
+ *data = maxval;
+ }
+ }
+ }
+}
+
+void jas_matrix_asr(jas_matrix_t *matrix, int n)
+{
+ int i;
+ int j;
+ jas_seqent_t *rowstart;
+ int rowstep;
+ jas_seqent_t *data;
+
+ assert(n >= 0);
+ rowstep = jas_matrix_rowstep(matrix);
+ for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
+ rowstart += rowstep) {
+ for (j = matrix->numcols_, data = rowstart; j > 0; --j,
+ ++data) {
+ *data >>= n;
+ }
+ }
+}
+
+void jas_matrix_asl(jas_matrix_t *matrix, int n)
+{
+ int i;
+ int j;
+ jas_seqent_t *rowstart;
+ int rowstep;
+ jas_seqent_t *data;
+
+ rowstep = jas_matrix_rowstep(matrix);
+ for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
+ rowstart += rowstep) {
+ for (j = matrix->numcols_, data = rowstart; j > 0; --j,
+ ++data) {
+ *data <<= n;
+ }
+ }
+}
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols)
+{
+ int size;
+ int i;
+
+ size = numrows * numcols;
+ if (size > matrix->datasize_ || numrows > matrix->maxrows_) {
+ return -1;
+ }
+
+ matrix->numrows_ = numrows;
+ matrix->numcols_ = numcols;
+
+ for (i = 0; i < numrows; ++i) {
+ matrix->rows_[i] = &matrix->data_[numcols * i];
+ }
+
+ return 0;
+}
+
+int jas_matrix_output(jas_matrix_t *matrix, FILE *out)
+{
+ int i;
+ int j;
+ jas_seqent_t x;
+
+ fprintf(out, "%d %d\n", jas_matrix_numrows(matrix), jas_matrix_numcols(matrix));
+ for (i = 0; i < jas_matrix_numrows(matrix); ++i) {
+ for (j = 0; j < jas_matrix_numcols(matrix); ++j) {
+ x = jas_matrix_get(matrix, i, j);
+ fprintf(out, "%ld", JAS_CAST(long, x));
+ if (j < jas_matrix_numcols(matrix) - 1) {
+ fprintf(out, " ");
+ }
+ }
+ fprintf(out, "\n");
+ }
+ return 0;
+}
+
+void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val)
+{
+ int i;
+ int j;
+ jas_seqent_t *rowstart;
+ int rowstep;
+ jas_seqent_t *data;
+
+ rowstep = jas_matrix_rowstep(matrix);
+ for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
+ rowstart += rowstep) {
+ for (j = matrix->numcols_, data = rowstart; j > 0; --j,
+ ++data) {
+ *data = val;
+ }
+ }
+}
+
+#if 0
+jas_matrix_t *jas_matrix_input(FILE *in)
+{
+ jas_matrix_t *matrix;
+ int i;
+ int j;
+ long x;
+ int numrows;
+ int numcols;
+
+ if (fscanf(in, "%d %d", &numrows, &numcols) != 2)
+ return 0;
+ if (!(matrix = jas_matrix_create(numrows, numcols)))
+ return 0;
+
+ /* Get matrix data. */
+ for (i = 0; i < jas_matrix_numrows(matrix); i++) {
+ for (j = 0; j < jas_matrix_numcols(matrix); j++) {
+ if (fscanf(in, "%ld", &x) != 1) {
+ jas_matrix_destroy(matrix);
+ return 0;
+ }
+ jas_matrix_set(matrix, i, j, JAS_CAST(jas_seqent_t, x));
+ }
+ }
+
+ return matrix;
+}
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_seq.h b/osframework/source/ImageLib/jpeg2000/jas_seq.h
new file mode 100644
index 0000000..036cca1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_seq.h
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Sequence/Matrix Library
+ *
+ * $Id: jas_seq.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_SEQ_H
+#define JAS_SEQ_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+
+#include "jas_stream.h"
+#include "jas_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* This matrix is a reference to another matrix. */
+#define JAS_MATRIX_REF 0x0001
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* An element in a sequence. */
+typedef int_fast32_t jas_seqent_t;
+
+/* An element in a matrix. */
+typedef int_fast32_t jas_matent_t;
+
+/* Matrix. */
+
+typedef struct {
+
+ /* Additional state information. */
+ int flags_;
+
+ /* The starting horizontal index. */
+ int_fast32_t xstart_;
+
+ /* The starting vertical index. */
+ int_fast32_t ystart_;
+
+ /* The ending horizontal index. */
+ int_fast32_t xend_;
+
+ /* The ending vertical index. */
+ int_fast32_t yend_;
+
+ /* The number of rows in the matrix. */
+ int_fast32_t numrows_;
+
+ /* The number of columns in the matrix. */
+ int_fast32_t numcols_;
+
+ /* Pointers to the start of each row. */
+ jas_seqent_t **rows_;
+
+ /* The allocated size of the rows array. */
+ int_fast32_t maxrows_;
+
+ /* The matrix data buffer. */
+ jas_seqent_t *data_;
+
+ /* The allocated size of the data array. */
+ int_fast32_t datasize_;
+
+} jas_matrix_t;
+
+typedef jas_matrix_t jas_seq2d_t;
+typedef jas_matrix_t jas_seq_t;
+
+/******************************************************************************\
+* Functions/macros for matrix class.
+\******************************************************************************/
+
+/* Get the number of rows. */
+#define jas_matrix_numrows(matrix) \
+ ((matrix)->numrows_)
+
+/* Get the number of columns. */
+#define jas_matrix_numcols(matrix) \
+ ((matrix)->numcols_)
+
+/* Get a matrix element. */
+#define jas_matrix_get(matrix, i, j) \
+ ((matrix)->rows_[i][j])
+
+/* Set a matrix element. */
+#define jas_matrix_set(matrix, i, j, v) \
+ ((matrix)->rows_[i][j] = (v))
+
+/* Get an element from a matrix that is known to be a row or column vector. */
+#define jas_matrix_getv(matrix, i) \
+ (((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i]) : \
+ ((matrix)->rows_[i][0]))
+
+/* Set an element in a matrix that is known to be a row or column vector. */
+#define jas_matrix_setv(matrix, i, v) \
+ (((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i] = (v)) : \
+ ((matrix)->rows_[i][0] = (v)))
+
+/* Get the address of an element in a matrix. */
+#define jas_matrix_getref(matrix, i, j) \
+ (&(matrix)->rows_[i][j])
+
+#define jas_matrix_getvref(matrix, i) \
+ (((matrix)->numrows_ > 1) ? jas_matrix_getref(matrix, i, 0) : jas_matrix_getref(matrix, 0, i))
+
+#define jas_matrix_length(matrix) \
+ (max((matrix)->numrows_, (matrix)->numcols_))
+
+/* Create a matrix with the specified dimensions. */
+jas_matrix_t *jas_matrix_create(int numrows, int numcols);
+
+/* Destroy a matrix. */
+void jas_matrix_destroy(jas_matrix_t *matrix);
+
+/* Resize a matrix. The previous contents of the matrix are lost. */
+int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols);
+
+int jas_matrix_output(jas_matrix_t *matrix, FILE *out);
+
+/* Create a matrix that references part of another matrix. */
+void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0,
+ int r1, int c1);
+
+/* Create a matrix that is a reference to a row of another matrix. */
+#define jas_matrix_bindrow(mat0, mat1, r) \
+ (jas_matrix_bindsub((mat0), (mat1), (r), 0, (r), (mat1)->numcols_ - 1))
+
+/* Create a matrix that is a reference to a column of another matrix. */
+#define jas_matrix_bindcol(mat0, mat1, c) \
+ (jas_matrix_bindsub((mat0), (mat1), 0, (c), (mat1)->numrows_ - 1, (c)))
+
+/* Clip the values of matrix elements to the specified range. */
+void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval,
+ jas_seqent_t maxval);
+
+/* Arithmetic shift left of all elements in a matrix. */
+void jas_matrix_asl(jas_matrix_t *matrix, int n);
+
+/* Arithmetic shift right of all elements in a matrix. */
+void jas_matrix_asr(jas_matrix_t *matrix, int n);
+
+/* Almost-but-not-quite arithmetic shift right of all elements in a matrix. */
+void jas_matrix_divpow2(jas_matrix_t *matrix, int n);
+
+/* Set all elements of a matrix to the specified value. */
+void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val);
+
+/* The spacing between rows of a matrix. */
+#define jas_matrix_rowstep(matrix) \
+ (((matrix)->numrows_ > 1) ? ((matrix)->rows_[1] - (matrix)->rows_[0]) : (0))
+
+/* The spacing between columns of a matrix. */
+#define jas_matrix_step(matrix) \
+ (((matrix)->numrows_ > 1) ? (jas_matrix_rowstep(matrix)) : (1))
+
+/* Compare two matrices for equality. */
+int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1);
+
+jas_matrix_t *jas_matrix_copy(jas_matrix_t *x);
+
+/******************************************************************************\
+* Functions/macros for 2-D sequence class.
+\******************************************************************************/
+
+jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x);
+
+jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend);
+
+#define jas_seq2d_destroy(s) \
+ jas_matrix_destroy(s)
+
+#define jas_seq2d_xstart(s) \
+ ((s)->xstart_)
+#define jas_seq2d_ystart(s) \
+ ((s)->ystart_)
+#define jas_seq2d_xend(s) \
+ ((s)->xend_)
+#define jas_seq2d_yend(s) \
+ ((s)->yend_)
+#define jas_seq2d_getref(s, x, y) \
+ (jas_matrix_getref(s, (y) - (s)->ystart_, (x) - (s)->xstart_))
+#define jas_seq2d_get(s, x, y) \
+ (jas_matrix_get(s, (y) - (s)->ystart_, (x) - (s)->xstart_))
+#define jas_seq2d_rowstep(s) \
+ jas_matrix_rowstep(s)
+#define jas_seq2d_width(s) \
+ ((s)->xend_ - (s)->xstart_)
+#define jas_seq2d_height(s) \
+ ((s)->yend_ - (s)->ystart_)
+#define jas_seq2d_setshift(s, x, y) \
+ ((s)->xstart_ = (x), (s)->ystart_ = (y), \
+ (s)->xend_ = (s)->xstart_ + (s)->numcols_, \
+ (s)->yend_ = (s)->ystart_ + (s)->numrows_)
+
+void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart,
+ int ystart, int xend, int yend);
+
+/******************************************************************************\
+* Functions/macros for 1-D sequence class.
+\******************************************************************************/
+
+#define jas_seq_create(start, end) \
+ (jas_seq2d_create(start, 0, end, 1))
+
+#define jas_seq_destroy(seq) \
+ (jas_seq2d_destroy(seq))
+
+#define jas_seq_set(seq, i, v) \
+ ((seq)->rows_[0][(i) - (seq)->xstart_] = (v))
+#define jas_seq_getref(seq, i) \
+ (&(seq)->rows_[0][(i) - (seq)->xstart_])
+#define jas_seq_get(seq, i) \
+ ((seq)->rows_[0][(i) - (seq)->xstart_])
+#define jas_seq_start(seq) \
+ ((seq)->xstart_)
+#define jas_seq_end(seq) \
+ ((seq)->xend_)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_stream.c b/osframework/source/ImageLib/jpeg2000/jas_stream.c
new file mode 100644
index 0000000..607e3ae
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_stream.c
@@ -0,0 +1,1197 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * I/O Stream Library
+ *
+ * $Id: jas_stream.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <ctype.h>
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#if defined(WIN32) || defined(HAVE_IO_H)
+#include <io.h>
+#endif
+
+#include "jas_types.h"
+#include "jas_stream.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+/******************************************************************************\
+* Local function prototypes.
+\******************************************************************************/
+
+static int jas_strtoopenmode(const char *s);
+static void jas_stream_destroy(jas_stream_t *stream);
+static jas_stream_t *jas_stream_create(void);
+static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,
+ int bufsize);
+
+static int mem_read(jas_stream_obj_t *obj, char *buf, int cnt);
+static int mem_write(jas_stream_obj_t *obj, char *buf, int cnt);
+static long mem_seek(jas_stream_obj_t *obj, long offset, int origin);
+static int mem_close(jas_stream_obj_t *obj);
+
+static int sfile_read(jas_stream_obj_t *obj, char *buf, int cnt);
+static int sfile_write(jas_stream_obj_t *obj, char *buf, int cnt);
+static long sfile_seek(jas_stream_obj_t *obj, long offset, int origin);
+static int sfile_close(jas_stream_obj_t *obj);
+
+static int file_read(jas_stream_obj_t *obj, char *buf, int cnt);
+static int file_write(jas_stream_obj_t *obj, char *buf, int cnt);
+static long file_seek(jas_stream_obj_t *obj, long offset, int origin);
+static int file_close(jas_stream_obj_t *obj);
+
+/******************************************************************************\
+* Local data.
+\******************************************************************************/
+
+static jas_stream_ops_t jas_stream_fileops = {
+ file_read,
+ file_write,
+ file_seek,
+ file_close
+};
+
+static jas_stream_ops_t jas_stream_sfileops = {
+ sfile_read,
+ sfile_write,
+ sfile_seek,
+ sfile_close
+};
+
+static jas_stream_ops_t jas_stream_memops = {
+ mem_read,
+ mem_write,
+ mem_seek,
+ mem_close
+};
+
+/******************************************************************************\
+* Code for opening and closing streams.
+\******************************************************************************/
+
+static jas_stream_t *jas_stream_create()
+{
+ jas_stream_t *stream;
+
+ if (!(stream = jas_malloc(sizeof(jas_stream_t)))) {
+ return 0;
+ }
+ stream->openmode_ = 0;
+ stream->bufmode_ = 0;
+ stream->flags_ = 0;
+ stream->bufbase_ = 0;
+ stream->bufstart_ = 0;
+ stream->bufsize_ = 0;
+ stream->ptr_ = 0;
+ stream->cnt_ = 0;
+ stream->ops_ = 0;
+ stream->obj_ = 0;
+ stream->rwcnt_ = 0;
+ stream->rwlimit_ = -1;
+
+ return stream;
+}
+
+jas_stream_t *jas_stream_memopen(char *buf, int bufsize)
+{
+ jas_stream_t *stream;
+ jas_stream_memobj_t *obj;
+
+ if (!(stream = jas_stream_create())) {
+ return 0;
+ }
+
+ /* A stream associated with a memory buffer is always opened
+ for both reading and writing in binary mode. */
+ stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY;
+
+ /* Since the stream data is already resident in memory, buffering
+ is not necessary. */
+ /* But... It still may be faster to use buffering anyways. */
+ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);
+
+ /* Select the operations for a memory stream. */
+ stream->ops_ = &jas_stream_memops;
+
+ /* Allocate memory for the underlying memory stream object. */
+ if (!(obj = jas_malloc(sizeof(jas_stream_memobj_t)))) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+ stream->obj_ = (void *) obj;
+
+ /* Initialize a few important members of the memory stream object. */
+ obj->myalloc_ = 0;
+ obj->buf_ = 0;
+
+ /* If the buffer size specified is nonpositive, then the buffer
+ is allocated internally and automatically grown as needed. */
+ if (bufsize <= 0) {
+ obj->bufsize_ = 1024;
+ obj->growable_ = 1;
+ } else {
+ obj->bufsize_ = bufsize;
+ obj->growable_ = 0;
+ }
+ if (buf) {
+ obj->buf_ = (unsigned char *) buf;
+ } else {
+ obj->buf_ = jas_malloc(obj->bufsize_ * sizeof(char));
+ obj->myalloc_ = 1;
+ }
+ if (!obj->buf_) {
+ jas_stream_close(stream);
+ return 0;
+ }
+
+ if (bufsize > 0 && buf) {
+ /* If a buffer was supplied by the caller and its length is positive,
+ make the associated buffer data appear in the stream initially. */
+ obj->len_ = bufsize;
+ } else {
+ /* The stream is initially empty. */
+ obj->len_ = 0;
+ }
+ obj->pos_ = 0;
+
+ return stream;
+}
+
+jas_stream_t *jas_stream_fopen(const char *filename, const char *mode)
+{
+ jas_stream_t *stream;
+ jas_stream_fileobj_t *obj;
+ int openflags;
+
+ /* Allocate a stream object. */
+ if (!(stream = jas_stream_create())) {
+ return 0;
+ }
+
+ /* Parse the mode string. */
+ stream->openmode_ = jas_strtoopenmode(mode);
+
+ /* Determine the correct flags to use for opening the file. */
+ if ((stream->openmode_ & JAS_STREAM_READ) &&
+ (stream->openmode_ & JAS_STREAM_WRITE)) {
+ openflags = O_RDWR;
+ } else if (stream->openmode_ & JAS_STREAM_READ) {
+ openflags = O_RDONLY;
+ } else if (stream->openmode_ & JAS_STREAM_WRITE) {
+ openflags = O_WRONLY;
+ } else {
+ openflags = 0;
+ }
+ if (stream->openmode_ & JAS_STREAM_APPEND) {
+ openflags |= O_APPEND;
+ }
+ if (stream->openmode_ & JAS_STREAM_BINARY) {
+ openflags |= O_BINARY;
+ }
+ if (stream->openmode_ & JAS_STREAM_CREATE) {
+ openflags |= O_CREAT | O_TRUNC;
+ }
+
+ /* Allocate space for the underlying file stream object. */
+ if (!(obj = jas_malloc(sizeof(jas_stream_fileobj_t)))) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+ obj->fd = -1;
+ obj->flags = 0;
+ obj->pathname[0] = '\0';
+ stream->obj_ = (void *) obj;
+
+ /* Select the operations for a file stream object. */
+ stream->ops_ = &jas_stream_fileops;
+
+ /* Open the underlying file. */
+ if ((obj->fd = open(filename, openflags, JAS_STREAM_PERMS)) < 0) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+
+ /* By default, use full buffering for this type of stream. */
+ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);
+
+ return stream;
+}
+
+jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp)
+{
+ jas_stream_t *stream;
+ int openflags;
+
+ /* Eliminate compiler warning about unused variable. */
+ path = 0;
+
+ /* Allocate a stream object. */
+ if (!(stream = jas_stream_create())) {
+ return 0;
+ }
+
+ /* Parse the mode string. */
+ stream->openmode_ = jas_strtoopenmode(mode);
+
+ /* Determine the correct flags to use for opening the file. */
+ if ((stream->openmode_ & JAS_STREAM_READ) &&
+ (stream->openmode_ & JAS_STREAM_WRITE)) {
+ openflags = O_RDWR;
+ } else if (stream->openmode_ & JAS_STREAM_READ) {
+ openflags = O_RDONLY;
+ } else if (stream->openmode_ & JAS_STREAM_WRITE) {
+ openflags = O_WRONLY;
+ } else {
+ openflags = 0;
+ }
+ if (stream->openmode_ & JAS_STREAM_APPEND) {
+ openflags |= O_APPEND;
+ }
+ if (stream->openmode_ & JAS_STREAM_BINARY) {
+ openflags |= O_BINARY;
+ }
+ if (stream->openmode_ & JAS_STREAM_CREATE) {
+ openflags |= O_CREAT | O_TRUNC;
+ }
+
+ stream->obj_ = JAS_CAST(void *, fp);
+
+ /* Select the operations for a file stream object. */
+ stream->ops_ = &jas_stream_sfileops;
+
+ /* By default, use full buffering for this type of stream. */
+ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);
+
+ return stream;
+}
+
+jas_stream_t *jas_stream_tmpfile()
+{
+ jas_stream_t *stream;
+ jas_stream_fileobj_t *obj;
+
+ if (!(stream = jas_stream_create())) {
+ return 0;
+ }
+
+ /* A temporary file stream is always opened for both reading and
+ writing in binary mode. */
+ stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY;
+
+ /* Allocate memory for the underlying temporary file object. */
+ if (!(obj = jas_malloc(sizeof(jas_stream_fileobj_t)))) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+ obj->fd = -1;
+ obj->flags = 0;
+ obj->pathname[0] = '\0';
+ stream->obj_ = obj;
+
+ /* Choose a file name. */
+ tmpnam(obj->pathname);
+
+ /* Open the underlying file. */
+ if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY,
+ JAS_STREAM_PERMS)) < 0) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+
+ /* Unlink the file so that it will disappear if the program
+ terminates abnormally. */
+ /* Under UNIX, one can unlink an open file and continue to do I/O
+ on it. Not all operating systems support this functionality, however.
+ For example, under Microsoft Windows the unlink operation will fail,
+ since the file is open. */
+ if (unlink(obj->pathname)) {
+ /* We will try unlinking the file again after it is closed. */
+ obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE;
+ }
+
+ /* Use full buffering. */
+ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);
+
+ stream->ops_ = &jas_stream_fileops;
+
+ return stream;
+}
+
+jas_stream_t *jas_stream_fdopen(int fd, const char *mode)
+{
+ jas_stream_t *stream;
+ jas_stream_fileobj_t *obj;
+
+ /* Allocate a stream object. */
+ if (!(stream = jas_stream_create())) {
+ return 0;
+ }
+
+ /* Parse the mode string. */
+ stream->openmode_ = jas_strtoopenmode(mode);
+
+#if defined(WIN32)
+ /* Argh!!! Someone ought to banish text mode (i.e., O_TEXT) to the
+ greatest depths of purgatory! */
+ /* Ensure that the file descriptor is in binary mode, if the caller
+ has specified the binary mode flag. Arguably, the caller ought to
+ take care of this, but text mode is a ugly wart anyways, so we save
+ the caller some grief by handling this within the stream library. */
+ /* This ugliness is mainly for the benefit of those who run the
+ JasPer software under Windows from shells that insist on opening
+ files in text mode. For example, in the Cygwin environment,
+ shells often open files in text mode when I/O redirection is
+ used. Grr... */
+ if (stream->openmode_ & JAS_STREAM_BINARY) {
+ setmode(fd, O_BINARY);
+ }
+#endif
+
+ /* Allocate space for the underlying file stream object. */
+ if (!(obj = jas_malloc(sizeof(jas_stream_fileobj_t)))) {
+ jas_stream_destroy(stream);
+ return 0;
+ }
+ obj->fd = fd;
+ obj->flags = 0;
+ obj->pathname[0] = '\0';
+ stream->obj_ = (void *) obj;
+
+ /* Do not close the underlying file descriptor when the stream is
+ closed. */
+ obj->flags |= JAS_STREAM_FILEOBJ_NOCLOSE;
+
+ /* By default, use full buffering for this type of stream. */
+ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);
+
+ /* Select the operations for a file stream object. */
+ stream->ops_ = &jas_stream_fileops;
+
+ return stream;
+}
+
+static void jas_stream_destroy(jas_stream_t *stream)
+{
+ /* If the memory for the buffer was allocated with malloc, free
+ this memory. */
+ if ((stream->bufmode_ & JAS_STREAM_FREEBUF) && stream->bufbase_) {
+ jas_free(stream->bufbase_);
+ stream->bufbase_ = 0;
+ }
+ jas_free(stream);
+}
+
+int jas_stream_close(jas_stream_t *stream)
+{
+ /* Flush buffer if necessary. */
+ jas_stream_flush(stream);
+
+ /* Close the underlying stream object. */
+ (*stream->ops_->close_)(stream->obj_);
+
+ jas_stream_destroy(stream);
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for reading and writing streams.
+\******************************************************************************/
+
+int jas_stream_getc_func(jas_stream_t *stream)
+{
+ assert(stream->ptr_ - stream->bufbase_ <= stream->bufsize_ +
+ JAS_STREAM_MAXPUTBACK);
+ return jas_stream_getc_macro(stream);
+}
+
+int jas_stream_putc_func(jas_stream_t *stream, int c)
+{
+ assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_);
+ return jas_stream_putc_macro(stream, c);
+}
+
+int jas_stream_ungetc(jas_stream_t *stream, int c)
+{
+ if (!stream->ptr_ || stream->ptr_ == stream->bufbase_) {
+ return -1;
+ }
+
+ /* Reset the EOF indicator (since we now have at least one character
+ to read). */
+ stream->flags_ &= ~JAS_STREAM_EOF;
+
+ --stream->rwcnt_;
+ --stream->ptr_;
+ ++stream->cnt_;
+ *stream->ptr_ = c;
+ return 0;
+}
+
+int jas_stream_read(jas_stream_t *stream, void *buf, int cnt)
+{
+ int n;
+ int c;
+ char *bufptr;
+
+ bufptr = buf;
+
+ n = 0;
+ while (n < cnt) {
+ if ((c = jas_stream_getc(stream)) == EOF) {
+ return n;
+ }
+ *bufptr++ = c;
+ ++n;
+ }
+
+ return n;
+}
+
+int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt)
+{
+ int n;
+ const char *bufptr;
+
+ bufptr = buf;
+
+ n = 0;
+ while (n < cnt) {
+ if (jas_stream_putc(stream, *bufptr) == EOF) {
+ return n;
+ }
+ ++bufptr;
+ ++n;
+ }
+
+ return n;
+}
+
+/* Note: This function uses a fixed size buffer. Therefore, it cannot
+ handle invocations that will produce more output than can be held
+ by the buffer. */
+int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[4096];
+ int ret;
+
+ va_start(ap, fmt);
+ ret = vsprintf(buf, fmt, ap);
+ jas_stream_puts(stream, buf);
+ va_end(ap);
+ return ret;
+}
+
+int jas_stream_puts(jas_stream_t *stream, const char *s)
+{
+ while (*s != '\0') {
+ if (jas_stream_putc_macro(stream, *s) == EOF) {
+ return -1;
+ }
+ ++s;
+ }
+ return 0;
+}
+
+char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize)
+{
+ int c;
+ char *bufptr;
+ assert(bufsize > 0);
+
+ bufptr = buf;
+ while (bufsize > 1) {
+ if ((c = jas_stream_getc(stream)) == EOF) {
+ break;
+ }
+ *bufptr++ = c;
+ --bufsize;
+ if (c == '\n') {
+ break;
+ }
+ }
+ *bufptr = '\0';
+ return buf;
+}
+
+int jas_stream_gobble(jas_stream_t *stream, int n)
+{
+ int m;
+ m = n;
+ for (m = n; m > 0; --m) {
+ if (jas_stream_getc(stream) == EOF) {
+ return n - m;
+ }
+ }
+ return n;
+}
+
+int jas_stream_pad(jas_stream_t *stream, int n, int c)
+{
+ int m;
+ m = n;
+ for (m = n; m > 0; --m) {
+ if (jas_stream_putc(stream, c) == EOF)
+ return n - m;
+ }
+ return n;
+}
+
+/******************************************************************************\
+* Code for getting and setting the stream position.
+\******************************************************************************/
+
+int jas_stream_isseekable(jas_stream_t *stream)
+{
+ if (stream->ops_ == &jas_stream_memops) {
+ return 1;
+ } else if (stream->ops_ == &jas_stream_fileops) {
+ if ((*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR) < 0) {
+ return 0;
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+int jas_stream_rewind(jas_stream_t *stream)
+{
+ return jas_stream_seek(stream, 0, SEEK_SET);
+}
+
+long jas_stream_seek(jas_stream_t *stream, long offset, int origin)
+{
+ long newpos;
+
+ /* The buffer cannot be in use for both reading and writing. */
+ assert(!((stream->bufmode_ & JAS_STREAM_RDBUF) && (stream->bufmode_ &
+ JAS_STREAM_WRBUF)));
+
+ /* Reset the EOF indicator (since we may not be at the EOF anymore). */
+ stream->flags_ &= ~JAS_STREAM_EOF;
+
+ if (stream->bufmode_ & JAS_STREAM_RDBUF) {
+ if (origin == SEEK_CUR) {
+ offset -= stream->cnt_;
+ }
+ } else if (stream->bufmode_ & JAS_STREAM_WRBUF) {
+ if (jas_stream_flush(stream)) {
+ return -1;
+ }
+ }
+ stream->cnt_ = 0;
+ stream->ptr_ = stream->bufstart_;
+ stream->bufmode_ &= ~(JAS_STREAM_RDBUF | JAS_STREAM_WRBUF);
+
+ if ((newpos = (*stream->ops_->seek_)(stream->obj_, offset, origin))
+ < 0) {
+ return -1;
+ }
+
+ return newpos;
+}
+
+long jas_stream_tell(jas_stream_t *stream)
+{
+ int adjust;
+ int offset;
+
+ if (stream->bufmode_ & JAS_STREAM_RDBUF) {
+ adjust = -stream->cnt_;
+ } else if (stream->bufmode_ & JAS_STREAM_WRBUF) {
+ adjust = stream->ptr_ - stream->bufstart_;
+ } else {
+ adjust = 0;
+ }
+
+ if ((offset = (*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR)) < 0) {
+ return -1;
+ }
+
+ return offset + adjust;
+}
+
+/******************************************************************************\
+* Buffer initialization code.
+\******************************************************************************/
+
+static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,
+ int bufsize)
+{
+ /* If this function is being called, the buffer should not have been
+ initialized yet. */
+ assert(!stream->bufbase_);
+
+ if (bufmode != JAS_STREAM_UNBUF) {
+ /* The full- or line-buffered mode is being employed. */
+ if (!buf) {
+ /* The caller has not specified a buffer to employ, so allocate
+ one. */
+ if ((stream->bufbase_ = jas_malloc(JAS_STREAM_BUFSIZE +
+ JAS_STREAM_MAXPUTBACK))) {
+ stream->bufmode_ |= JAS_STREAM_FREEBUF;
+ stream->bufsize_ = JAS_STREAM_BUFSIZE;
+ } else {
+ /* The buffer allocation has failed. Resort to unbuffered
+ operation. */
+ stream->bufbase_ = stream->tinybuf_;
+ stream->bufsize_ = 1;
+ }
+ } else {
+ /* The caller has specified a buffer to employ. */
+ /* The buffer must be large enough to accommodate maximum
+ putback. */
+ assert(bufsize > JAS_STREAM_MAXPUTBACK);
+ stream->bufbase_ = JAS_CAST(uchar *, buf);
+ stream->bufsize_ = bufsize - JAS_STREAM_MAXPUTBACK;
+ }
+ } else {
+ /* The unbuffered mode is being employed. */
+ /* A buffer should not have been supplied by the caller. */
+ assert(!buf);
+ /* Use a trivial one-character buffer. */
+ stream->bufbase_ = stream->tinybuf_;
+ stream->bufsize_ = 1;
+ }
+ stream->bufstart_ = &stream->bufbase_[JAS_STREAM_MAXPUTBACK];
+ stream->ptr_ = stream->bufstart_;
+ stream->cnt_ = 0;
+ stream->bufmode_ |= bufmode & JAS_STREAM_BUFMODEMASK;
+}
+
+/******************************************************************************\
+* Buffer filling and flushing code.
+\******************************************************************************/
+
+int jas_stream_flush(jas_stream_t *stream)
+{
+ if (stream->bufmode_ & JAS_STREAM_RDBUF) {
+ return 0;
+ }
+ return jas_stream_flushbuf(stream, EOF);
+}
+
+int jas_stream_fillbuf(jas_stream_t *stream, int getflag)
+{
+ int c;
+
+ /* The stream must not be in an error or EOF state. */
+ if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) {
+ return EOF;
+ }
+
+ /* The stream must be open for reading. */
+ if ((stream->openmode_ & JAS_STREAM_READ) == 0) {
+ return EOF;
+ }
+
+ /* Make a half-hearted attempt to confirm that the buffer is not
+ currently being used for writing. This check is not intended
+ to be foolproof! */
+ assert((stream->bufmode_ & JAS_STREAM_WRBUF) == 0);
+
+ assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_);
+
+ /* Mark the buffer as being used for reading. */
+ stream->bufmode_ |= JAS_STREAM_RDBUF;
+
+ /* Read new data into the buffer. */
+ stream->ptr_ = stream->bufstart_;
+ if ((stream->cnt_ = (*stream->ops_->read_)(stream->obj_,
+ (char *) stream->bufstart_, stream->bufsize_)) <= 0) {
+ if (stream->cnt_ < 0) {
+ stream->flags_ |= JAS_STREAM_ERR;
+ } else {
+ stream->flags_ |= JAS_STREAM_EOF;
+ }
+ stream->cnt_ = 0;
+ return EOF;
+ }
+
+ assert(stream->cnt_ > 0);
+ /* Get or peek at the first character in the buffer. */
+ c = (getflag) ? jas_stream_getc2(stream) : (*stream->ptr_);
+
+ return c;
+}
+
+int jas_stream_flushbuf(jas_stream_t *stream, int c)
+{
+ int len;
+ int n;
+
+ /* The stream should not be in an error or EOF state. */
+ if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) {
+ return EOF;
+ }
+
+ /* The stream must be open for writing. */
+ if ((stream->openmode_ & (JAS_STREAM_WRITE | JAS_STREAM_APPEND)) == 0) {
+ return EOF;
+ }
+
+ /* The buffer should not currently be in use for reading. */
+ assert(!(stream->bufmode_ & JAS_STREAM_RDBUF));
+
+ /* Note: Do not use the quantity stream->cnt to determine the number
+ of characters in the buffer! Depending on how this function was
+ called, the stream->cnt value may be "off-by-one". */
+ len = stream->ptr_ - stream->bufstart_;
+ if (len > 0) {
+ n = (*stream->ops_->write_)(stream->obj_, (char *)
+ stream->bufstart_, len);
+ if (n != len) {
+ stream->flags_ |= JAS_STREAM_ERR;
+ return EOF;
+ }
+ }
+ stream->cnt_ = stream->bufsize_;
+ stream->ptr_ = stream->bufstart_;
+
+ stream->bufmode_ |= JAS_STREAM_WRBUF;
+
+ if (c != EOF) {
+ assert(stream->cnt_ > 0);
+ return jas_stream_putc2(stream, c);
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* Miscellaneous code.
+\******************************************************************************/
+
+static int jas_strtoopenmode(const char *s)
+{
+ int openmode = 0;
+ while (*s != '\0') {
+ switch (*s) {
+ case 'r':
+ openmode |= JAS_STREAM_READ;
+ break;
+ case 'w':
+ openmode |= JAS_STREAM_WRITE | JAS_STREAM_CREATE;
+ break;
+ case 'b':
+ openmode |= JAS_STREAM_BINARY;
+ break;
+ case 'a':
+ openmode |= JAS_STREAM_APPEND;
+ break;
+ case '+':
+ openmode |= JAS_STREAM_READ | JAS_STREAM_WRITE;
+ break;
+ default:
+ break;
+ }
+ ++s;
+ }
+ return openmode;
+}
+
+int jas_stream_copy(jas_stream_t *out, jas_stream_t *in, int n)
+{
+ int all;
+ int c;
+ int m;
+
+ all = (n < 0) ? 1 : 0;
+
+ m = n;
+ while (all || m > 0) {
+ if ((c = jas_stream_getc_macro(in)) == EOF) {
+ /* The next character of input could not be read. */
+ /* Return with an error if an I/O error occured
+ (not including EOF) or if an explicit copy count
+ was specified. */
+ return (!all || jas_stream_error(in)) ? (-1) : 0;
+ }
+ if (jas_stream_putc_macro(out, c) == EOF) {
+ return -1;
+ }
+ --m;
+ }
+ return 0;
+}
+
+long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt)
+{
+ int old;
+
+ old = stream->rwcnt_;
+ stream->rwcnt_ = rwcnt;
+ return old;
+}
+
+int jas_stream_display(jas_stream_t *stream, FILE *fp, int n)
+{
+ unsigned char buf[16];
+ int i;
+ int j;
+ int m;
+ int c;
+ int display;
+ int cnt;
+
+ cnt = n - (n % 16);
+ display = 1;
+
+ for (i = 0; i < n; i += 16) {
+ if (n > 16 && i > 0) {
+ display = (i >= cnt) ? 1 : 0;
+ }
+ if (display) {
+ fprintf(fp, "%08x:", i);
+ }
+ m = JAS_MIN(n - i, 16);
+ for (j = 0; j < m; ++j) {
+ if ((c = jas_stream_getc(stream)) == EOF) {
+ abort();
+ return -1;
+ }
+ buf[j] = c;
+ }
+ if (display) {
+ for (j = 0; j < m; ++j) {
+ fprintf(fp, " %02x", buf[j]);
+ }
+ fputc(' ', fp);
+ for (; j < 16; ++j) {
+ fprintf(fp, " ");
+ }
+ for (j = 0; j < m; ++j) {
+ if (isprint(buf[j])) {
+ fputc(buf[j], fp);
+ } else {
+ fputc(' ', fp);
+ }
+ }
+ fprintf(fp, "\n");
+ }
+
+
+ }
+ return 0;
+}
+
+long jas_stream_length(jas_stream_t *stream)
+{
+ long oldpos;
+ long pos;
+ if ((oldpos = jas_stream_tell(stream)) < 0) {
+ return -1;
+ }
+ if (jas_stream_seek(stream, 0, SEEK_END) < 0) {
+ return -1;
+ }
+ if ((pos = jas_stream_tell(stream)) < 0) {
+ return -1;
+ }
+ if (jas_stream_seek(stream, oldpos, SEEK_SET) < 0) {
+ return -1;
+ }
+ return pos;
+}
+
+/******************************************************************************\
+* Memory stream object.
+\******************************************************************************/
+
+static int mem_read(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ int n;
+ jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj;
+ n = m->len_ - m->pos_;
+ cnt = JAS_MIN(n, cnt);
+ memcpy(buf, &m->buf_[m->pos_], cnt);
+ m->pos_ += cnt;
+ return cnt;
+}
+
+static int mem_resize(jas_stream_memobj_t *m, int bufsize)
+{
+ unsigned char *buf;
+
+ assert(m->buf_);
+ if (!(buf = jas_realloc(m->buf_, bufsize * sizeof(unsigned char)))) {
+ return -1;
+ }
+ m->buf_ = buf;
+ m->bufsize_ = bufsize;
+ return 0;
+}
+
+static int mem_write(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ int n;
+ int ret;
+ jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj;
+ long newbufsize;
+ long newpos;
+
+ newpos = m->pos_ + cnt;
+ if (newpos > m->bufsize_ && m->growable_) {
+ newbufsize = m->bufsize_;
+ while (newbufsize < newpos) {
+ newbufsize <<= 1;
+ assert(newbufsize >= 0);
+ }
+ if (mem_resize(m, newbufsize)) {
+ return -1;
+ }
+ }
+ if (m->pos_ > m->len_) {
+ /* The current position is beyond the end of the file, so
+ pad the file to the current position with zeros. */
+ n = JAS_MIN(m->pos_, m->bufsize_) - m->len_;
+ if (n > 0) {
+ memset(&m->buf_[m->len_], 0, n);
+ m->len_ += n;
+ }
+ if (m->pos_ != m->len_) {
+ /* The buffer is not big enough. */
+ return 0;
+ }
+ }
+ n = m->bufsize_ - m->pos_;
+ ret = JAS_MIN(n, cnt);
+ if (ret > 0) {
+ memcpy(&m->buf_[m->pos_], buf, ret);
+ m->pos_ += ret;
+ }
+ if (m->pos_ > m->len_) {
+ m->len_ = m->pos_;
+ }
+assert(ret == cnt);
+ return ret;
+}
+
+static long mem_seek(jas_stream_obj_t *obj, long offset, int origin)
+{
+ jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj;
+ long newpos;
+
+ switch (origin) {
+ case SEEK_SET:
+ newpos = offset;
+ break;
+ case SEEK_END:
+ newpos = m->len_ - offset;
+ break;
+ case SEEK_CUR:
+ newpos = m->pos_ + offset;
+ break;
+ default:
+ abort();
+ break;
+ }
+ if (newpos < 0) {
+ return -1;
+ }
+ m->pos_ = newpos;
+
+ return m->pos_;
+}
+
+static int mem_close(jas_stream_obj_t *obj)
+{
+ jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj;
+ if (m->myalloc_ && m->buf_) {
+ jas_free(m->buf_);
+ m->buf_ = 0;
+ }
+ jas_free(obj);
+ return 0;
+}
+
+/******************************************************************************\
+* File stream object.
+\******************************************************************************/
+
+static int file_read(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ jas_stream_fileobj_t *fileobj = JAS_CAST(jas_stream_fileobj_t *, obj);
+ return read(fileobj->fd, buf, cnt);
+}
+
+static int file_write(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ jas_stream_fileobj_t *fileobj = JAS_CAST(jas_stream_fileobj_t *, obj);
+ return write(fileobj->fd, buf, cnt);
+}
+
+static long file_seek(jas_stream_obj_t *obj, long offset, int origin)
+{
+ jas_stream_fileobj_t *fileobj = JAS_CAST(jas_stream_fileobj_t *, obj);
+ return lseek(fileobj->fd, offset, origin);
+}
+
+static int file_close(jas_stream_obj_t *obj)
+{
+ jas_stream_fileobj_t *fileobj = JAS_CAST(jas_stream_fileobj_t *, obj);
+ int ret;
+ ret = close(fileobj->fd);
+ if (fileobj->flags & JAS_STREAM_FILEOBJ_DELONCLOSE) {
+ unlink(fileobj->pathname);
+ }
+ jas_free(fileobj);
+ return ret;
+}
+
+/******************************************************************************\
+* Stdio file stream object.
+\******************************************************************************/
+
+static int sfile_read(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ FILE *fp;
+ fp = JAS_CAST(FILE *, obj);
+ return fread(buf, 1, cnt, fp);
+}
+
+static int sfile_write(jas_stream_obj_t *obj, char *buf, int cnt)
+{
+ FILE *fp;
+ fp = JAS_CAST(FILE *, obj);
+ return fwrite(buf, 1, cnt, fp);
+}
+
+static long sfile_seek(jas_stream_obj_t *obj, long offset, int origin)
+{
+ FILE *fp;
+ fp = JAS_CAST(FILE *, obj);
+ return fseek(fp, offset, origin);
+}
+
+static int sfile_close(jas_stream_obj_t *obj)
+{
+ FILE *fp;
+ fp = JAS_CAST(FILE *, obj);
+ return fclose(fp);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_stream.h b/osframework/source/ImageLib/jpeg2000/jas_stream.h
new file mode 100644
index 0000000..d4faa91
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_stream.h
@@ -0,0 +1,511 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * I/O Stream Class
+ *
+ * $Id: jas_stream.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_STREAM_H
+#define JAS_STREAM_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include "jas_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* On most UNIX systems, we probably need to define O_BINARY ourselves. */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+/*
+ * Stream open flags.
+ */
+
+/* The stream was opened for reading. */
+#define JAS_STREAM_READ 0x0001
+/* The stream was opened for writing. */
+#define JAS_STREAM_WRITE 0x0002
+/* The stream was opened for appending. */
+#define JAS_STREAM_APPEND 0x0004
+/* The stream was opened in binary mode. */
+#define JAS_STREAM_BINARY 0x0008
+/* The stream should be created/truncated. */
+#define JAS_STREAM_CREATE 0x0010
+
+
+/*
+ * Stream buffering flags.
+ */
+
+/* The stream is unbuffered. */
+#define JAS_STREAM_UNBUF 0x0000
+/* The stream is line buffered. */
+#define JAS_STREAM_LINEBUF 0x0001
+/* The stream is fully buffered. */
+#define JAS_STREAM_FULLBUF 0x0002
+/* The buffering mode mask. */
+#define JAS_STREAM_BUFMODEMASK 0x000f
+
+/* The memory associated with the buffer needs to be deallocated when the
+ stream is destroyed. */
+#define JAS_STREAM_FREEBUF 0x0008
+/* The buffer is currently being used for reading. */
+#define JAS_STREAM_RDBUF 0x0010
+/* The buffer is currently being used for writing. */
+#define JAS_STREAM_WRBUF 0x0020
+
+/*
+ * Stream error flags.
+ */
+
+/* The end-of-file has been encountered (on reading). */
+#define JAS_STREAM_EOF 0x0001
+/* An I/O error has been encountered on the stream. */
+#define JAS_STREAM_ERR 0x0002
+/* The read/write limit has been exceeded. */
+#define JAS_STREAM_RWLIMIT 0x0004
+/* The error mask. */
+#define JAS_STREAM_ERRMASK \
+ (JAS_STREAM_EOF | JAS_STREAM_ERR | JAS_STREAM_RWLIMIT)
+
+/*
+ * Other miscellaneous constants.
+ */
+
+/* The default buffer size (for fully-buffered operation). */
+#define JAS_STREAM_BUFSIZE 8192
+/* The default permission mask for file creation. */
+#define JAS_STREAM_PERMS 0666
+
+/* The maximum number of characters that can always be put back on a stream. */
+#define JAS_STREAM_MAXPUTBACK 16
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/*
+ * Generic file object.
+ */
+
+typedef void jas_stream_obj_t;
+
+/*
+ * Generic file object operations.
+ */
+
+typedef struct {
+
+ /* Read characters from a file object. */
+ int (*read_)(jas_stream_obj_t *obj, char *buf, int cnt);
+
+ /* Write characters to a file object. */
+ int (*write_)(jas_stream_obj_t *obj, char *buf, int cnt);
+
+ /* Set the position for a file object. */
+ long (*seek_)(jas_stream_obj_t *obj, long offset, int origin);
+
+ /* Close a file object. */
+ int (*close_)(jas_stream_obj_t *obj);
+
+} jas_stream_ops_t;
+
+/*
+ * Stream object.
+ */
+
+typedef struct {
+
+ /* The mode in which the stream was opened. */
+ int openmode_;
+
+ /* The buffering mode. */
+ int bufmode_;
+
+ /* The stream status. */
+ int flags_;
+
+ /* The start of the buffer area to use for reading/writing. */
+ uchar *bufbase_;
+
+ /* The start of the buffer area excluding the extra initial space for
+ character putback. */
+ uchar *bufstart_;
+
+ /* The buffer size. */
+ int bufsize_;
+
+ /* The current position in the buffer. */
+ uchar *ptr_;
+
+ /* The number of characters that must be read/written before
+ the buffer needs to be filled/flushed. */
+ int cnt_;
+
+ /* A trivial buffer to be used for unbuffered operation. */
+ uchar tinybuf_[JAS_STREAM_MAXPUTBACK + 1];
+
+ /* The operations for the underlying stream file object. */
+ jas_stream_ops_t *ops_;
+
+ /* The underlying stream file object. */
+ jas_stream_obj_t *obj_;
+
+ /* The number of characters read/written. */
+ long rwcnt_;
+
+ /* The maximum number of characters that may be read/written. */
+ long rwlimit_;
+
+} jas_stream_t;
+
+/*
+ * Regular file object.
+ */
+
+/*
+ * File descriptor file object.
+ */
+typedef struct {
+ int fd;
+ int flags;
+ char pathname[L_tmpnam + 1];
+} jas_stream_fileobj_t;
+
+#define JAS_STREAM_FILEOBJ_DELONCLOSE 0x01
+#define JAS_STREAM_FILEOBJ_NOCLOSE 0x02
+
+/*
+ * Memory file object.
+ */
+
+typedef struct {
+
+ /* The data associated with this file. */
+ uchar *buf_;
+
+ /* The allocated size of the buffer for holding file data. */
+ int bufsize_;
+
+ /* The length of the file. */
+ int_fast32_t len_;
+
+ /* The seek position. */
+ int_fast32_t pos_;
+
+ /* Is the buffer growable? */
+ int growable_;
+
+ /* Was the buffer allocated internally? */
+ int myalloc_;
+
+} jas_stream_memobj_t;
+
+/******************************************************************************\
+* Macros/functions for opening and closing streams.
+\******************************************************************************/
+
+/* Open a file as a stream. */
+jas_stream_t *jas_stream_fopen(const char *filename, const char *mode);
+
+/* Open a memory buffer as a stream. */
+jas_stream_t *jas_stream_memopen(char *buf, int bufsize);
+
+/* Open a file descriptor as a stream. */
+jas_stream_t *jas_stream_fdopen(int fd, const char *mode);
+
+/* Open a stdio stream as a stream. */
+jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp);
+
+/* Open a temporary file as a stream. */
+jas_stream_t *jas_stream_tmpfile(void);
+
+/* Close a stream. */
+int jas_stream_close(jas_stream_t *stream);
+
+/******************************************************************************\
+* Macros/functions for getting/setting the stream state.
+\******************************************************************************/
+
+/* Get the EOF indicator for a stream. */
+#define jas_stream_eof(stream) \
+ (((stream)->flags_ & JAS_STREAM_EOF) != 0)
+
+/* Get the error indicator for a stream. */
+#define jas_stream_error(stream) \
+ (((stream)->flags_ & JAS_STREAM_ERR) != 0)
+
+/* Clear the error indicator for a stream. */
+#define jas_stream_clearerr(stream) \
+ ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))
+
+/* Get the read/write limit for a stream. */
+#define jas_stream_getrwlimit(stream) \
+ (((const jas_stream_t *)(stream))->rwlimit_)
+
+/* Set the read/write limit for a stream. */
+int jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit);
+
+/* Get the read/write count for a stream. */
+#define jas_stream_getrwcount(stream) \
+ (((const jas_stream_t *)(stream))->rwcnt_)
+
+/* Set the read/write count for a stream. */
+long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt);
+
+/******************************************************************************\
+* Macros/functions for I/O.
+\******************************************************************************/
+
+/* Read a character from a stream. */
+#if defined(DEBUG)
+#define jas_stream_getc(stream) jas_stream_getc_func(stream)
+#else
+#define jas_stream_getc(stream) jas_stream_getc_macro(stream)
+#endif
+
+/* Write a character to a stream. */
+#if defined(DEBUG)
+#define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
+#else
+#define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
+#endif
+
+/* Read characters from a stream into a buffer. */
+int jas_stream_read(jas_stream_t *stream, void *buf, int cnt);
+
+/* Write characters from a buffer to a stream. */
+int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt);
+
+/* Write formatted output to a stream. */
+int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...);
+
+/* Write a string to a stream. */
+int jas_stream_puts(jas_stream_t *stream, const char *s);
+
+/* Read a line of input from a stream. */
+char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize);
+
+/* Look at the next character to be read from a stream without actually
+ removing it from the stream. */
+#define jas_stream_peekc(stream) \
+ (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
+ ((int)(*(stream)->ptr_)))
+
+/* Put a character back on a stream. */
+int jas_stream_ungetc(jas_stream_t *stream, int c);
+
+/******************************************************************************\
+* Macros/functions for getting/setting the stream position.
+\******************************************************************************/
+
+/* Is it possible to seek on this stream? */
+int jas_stream_isseekable(jas_stream_t *stream);
+
+/* Set the current position within the stream. */
+long jas_stream_seek(jas_stream_t *stream, long offset, int origin);
+
+/* Get the current position within the stream. */
+long jas_stream_tell(jas_stream_t *stream);
+
+/* Seek to the beginning of a stream. */
+int jas_stream_rewind(jas_stream_t *stream);
+
+/******************************************************************************\
+* Macros/functions for flushing.
+\******************************************************************************/
+
+/* Flush any pending output to a stream. */
+int jas_stream_flush(jas_stream_t *stream);
+
+/******************************************************************************\
+* Miscellaneous macros/functions.
+\******************************************************************************/
+
+/* Copy data from one stream to another. */
+int jas_stream_copy(jas_stream_t *dst, jas_stream_t *src, int n);
+
+/* Display stream contents (for debugging purposes). */
+int jas_stream_display(jas_stream_t *stream, FILE *fp, int n);
+
+/* Consume (i.e., discard) characters from stream. */
+int jas_stream_gobble(jas_stream_t *stream, int n);
+
+/* Write a character multiple times to a stream. */
+int jas_stream_pad(jas_stream_t *stream, int n, int c);
+
+/* Get the size of the file associated with the specified stream.
+ The specified stream must be seekable. */
+long jas_stream_length(jas_stream_t *stream);
+
+/******************************************************************************\
+* Internal functions.
+\******************************************************************************/
+
+/* The following functions are for internal use only! If you call them
+directly, you will die a horrible, miserable, and painful death! */
+
+/* Read a character from a stream. */
+#define jas_stream_getc_macro(stream) \
+ ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \
+ JAS_STREAM_RWLIMIT))) ? \
+ (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \
+ (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \
+ jas_stream_getc2(stream)) : EOF)
+#define jas_stream_getc2(stream) \
+ ((--(stream)->cnt_ < 0) ? jas_stream_fillbuf(stream, 1) : \
+ (++(stream)->rwcnt_, (int)(*(stream)->ptr_++)))
+
+/* Write a character to a stream. */
+#define jas_stream_putc_macro(stream, c) \
+ ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \
+ JAS_STREAM_RWLIMIT))) ? \
+ (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \
+ (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \
+ jas_stream_putc2(stream, c)) : EOF)
+#define jas_stream_putc2(stream, c) \
+ (((stream)->bufmode_ |= JAS_STREAM_WRBUF, --(stream)->cnt_ < 0) ? \
+ jas_stream_flushbuf((stream), (uchar)(c)) : \
+ (++(stream)->rwcnt_, (int)(*(stream)->ptr_++ = (c))))
+
+/* These prototypes need to be here for the sake of the stream_getc and
+stream_putc macros. */
+int jas_stream_fillbuf(jas_stream_t *stream, int getflag);
+int jas_stream_flushbuf(jas_stream_t *stream, int c);
+int jas_stream_getc_func(jas_stream_t *stream);
+int jas_stream_putc_func(jas_stream_t *stream, int c);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_string.c b/osframework/source/ImageLib/jpeg2000/jas_string.c
new file mode 100644
index 0000000..1ab5637
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_string.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * String Library
+ *
+ * $Id: jas_string.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include <string.h>
+
+#include "jas_malloc.h"
+#include "jas_string.h"
+
+/******************************************************************************\
+* Miscellaneous Functions
+\******************************************************************************/
+
+/* This function is equivalent to the popular but non-standard (and
+ not-always-available) strdup function. */
+
+char *jas_strdup(const char *s)
+{
+ int n;
+ char *p;
+ n = strlen(s) + 1;
+ if (!(p = jas_malloc(n * sizeof(char)))) {
+ return 0;
+ }
+ strcpy(p, s);
+ return p;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_string.h b/osframework/source/ImageLib/jpeg2000/jas_string.h
new file mode 100644
index 0000000..568ea36
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_string.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * String Library
+ *
+ * $Id: jas_string.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_STRING_H
+#define JAS_STRING_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Copy a string (a la strdup). */
+char *jas_strdup(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_tvp.c b/osframework/source/ImageLib/jpeg2000/jas_tvp.c
new file mode 100644
index 0000000..2c4011e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_tvp.c
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tag-Value Parser Library
+ *
+ * $Id: jas_tvp.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#include "jas_malloc.h"
+#include "jas_string.h"
+#include "jas_tvp.h"
+
+/******************************************************************************\
+* Macros.
+\******************************************************************************/
+
+/* Is the specified character valid for a tag name? */
+#define JAS_TVP_ISTAG(x) \
+ (isalpha(x) || (x) == '_' || isdigit(x))
+
+/******************************************************************************\
+* Code for creating and destroying a tag-value parser.
+\******************************************************************************/
+
+jas_tvparser_t *jas_tvparser_create(const char *s)
+{
+ jas_tvparser_t *tvp;
+ if (!(tvp = jas_malloc(sizeof(jas_tvparser_t)))) {
+ return 0;
+ }
+ if (!(tvp->buf = jas_strdup(s))) {
+ jas_tvparser_destroy(tvp);
+ return 0;
+ }
+ tvp->pos = tvp->buf;
+ tvp->tag = 0;
+ tvp->val = 0;
+ return tvp;
+}
+
+void jas_tvparser_destroy(jas_tvparser_t *tvp)
+{
+ if (tvp->buf) {
+ jas_free(tvp->buf);
+ }
+ jas_free(tvp);
+}
+
+/******************************************************************************\
+* Main parsing code.
+\******************************************************************************/
+
+/* Get the next tag-value pair. */
+int jas_tvparser_next(jas_tvparser_t *tvp)
+{
+ char *p;
+ char *tag;
+ char *val;
+
+ /* Skip any leading whitespace. */
+ p = tvp->pos;
+ while (*p != '\0' && isspace(*p)) {
+ ++p;
+ }
+
+ /* Has the end of the input data been reached? */
+ if (*p == '\0') {
+ /* No more tags are present. */
+ tvp->pos = p;
+ return 1;
+ }
+
+ /* Does the tag name begin with a valid character? */
+ if (!JAS_TVP_ISTAG(*p)) {
+ return -1;
+ }
+
+ /* Remember where the tag name begins. */
+ tag = p;
+
+ /* Find the end of the tag name. */
+ while (*p != '\0' && JAS_TVP_ISTAG(*p)) {
+ ++p;
+ }
+
+ /* Has the end of the input data been reached? */
+ if (*p == '\0') {
+ /* The value field is empty. */
+ tvp->tag = tag;
+ tvp->val = "";
+ tvp->pos = p;
+ return 0;
+ }
+
+ /* Is a value field not present? */
+ if (*p != '=') {
+ if (*p != '\0' && !isspace(*p)) {
+ return -1;
+ }
+ *p++ = '\0';
+ tvp->tag = tag;
+ tvp->val = "";
+ tvp->pos = p;
+ return 0;
+ }
+
+ *p++ = '\0';
+
+ val = p;
+ while (*p != '\0' && !isspace(*p)) {
+ ++p;
+ }
+
+ if (*p != '\0') {
+ *p++ = '\0';
+ }
+
+ tvp->pos = p;
+ tvp->tag = tag;
+ tvp->val = val;
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for querying the current tag/value.
+\******************************************************************************/
+
+/* Get the current tag. */
+char *jas_tvparser_gettag(jas_tvparser_t *tvp)
+{
+ return tvp->tag;
+}
+
+/* Get the current value. */
+char *jas_tvparser_getval(jas_tvparser_t *tvp)
+{
+ return tvp->val;
+}
+
+/******************************************************************************\
+* Miscellaneous code.
+\******************************************************************************/
+
+/* Lookup a tag by name. */
+jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name)
+{
+ jas_taginfo_t *taginfo;
+ taginfo = taginfos;
+ while (taginfo->id >= 0) {
+ if (!strcmp(taginfo->name, name)) {
+ return taginfo;
+ }
+ ++taginfo;
+ }
+ return 0;
+}
+
+/* This function is simply for convenience. */
+/* One can avoid testing for the special case of a null pointer, by
+ using this function. This function never returns a null pointer. */
+jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo)
+{
+ static jas_taginfo_t invalidtaginfo = {
+ -1, 0
+ };
+
+ return taginfo ? taginfo : &invalidtaginfo;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_tvp.h b/osframework/source/ImageLib/jpeg2000/jas_tvp.h
new file mode 100644
index 0000000..31373ae
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_tvp.h
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tag/Value Parser
+ *
+ * $Id: jas_tvp.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_TVP_H
+#define JAS_TVP_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Tag information type. */
+
+typedef struct {
+
+ int id;
+ /* The ID for the tag. */
+
+ char *name;
+ /* The name of the tag. */
+
+} jas_taginfo_t;
+
+/* Tag-value parser type. */
+
+typedef struct {
+
+ char *buf;
+ /* The parsing buffer. */
+
+ char *tag;
+ /* The current tag name. */
+
+ char *val;
+ /* The current value. */
+
+ char *pos;
+ /* The current position in the parsing buffer. */
+
+} jas_tvparser_t;
+
+/******************************************************************************\
+* Tag information functions.
+\******************************************************************************/
+
+/* Lookup a tag by name. */
+jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name);
+
+/* This function returns a pointer to the specified taginfo object if it
+ exists (i.e., the pointer is nonnull); otherwise, a pointer to a dummy
+ object is returned. This is useful in some situations to avoid checking
+ for a null pointer. */
+jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo);
+
+/******************************************************************************\
+* Tag-value parser functions.
+\******************************************************************************/
+
+/* Create a tag-value parser for the specified string. */
+jas_tvparser_t *jas_tvparser_create(const char *s);
+
+/* Destroy a tag-value parser. */
+void jas_tvparser_destroy(jas_tvparser_t *tvparser);
+
+/* Get the next tag-value pair. */
+int jas_tvparser_next(jas_tvparser_t *tvparser);
+
+/* Get the tag name for the current tag-value pair. */
+char *jas_tvparser_gettag(jas_tvparser_t *tvparser);
+
+/* Get the value for the current tag-value pair. */
+char *jas_tvparser_getval(jas_tvparser_t *tvparser);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_types.h b/osframework/source/ImageLib/jpeg2000/jas_types.h
new file mode 100644
index 0000000..bb7ed2f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_types.h
@@ -0,0 +1,259 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Primitive Types
+ *
+ * $Id: jas_types.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_TYPES_H
+#define JAS_TYPES_H
+
+#include "jas_config.h"
+
+#if !defined(JAS_CONFIGURE)
+
+#if defined(WIN32) || defined(HAVE_WINDOWS_H)
+/*
+ We are dealing with Microsoft Windows and most likely Microsoft
+ Visual C (MSVC). (Heaven help us.) Sadly, MSVC does not correctly
+ define some of the standard types specified in ISO/IEC 9899:1999.
+ In particular, it does not define the "long long" and "unsigned long
+ long" types. So, we work around this problem by using the "INT64"
+ and "UINT64" types that are defined in the header file "windows.h".
+ */
+#include <windows.h>
+#undef longlong
+#define longlong INT64
+#undef ulonglong
+#define ulonglong UINT64
+#endif
+
+#endif
+
+#if defined(HAVE_STDLIB_H)
+#include <stdlib.h>
+#endif
+#if defined(HAVE_STDDEF_H)
+#include <stddef.h>
+#endif
+#if defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+
+#if defined(HAVE_STDBOOL_H)
+/*
+ * The C language implementation does correctly provide the standard header
+ * file "stdbool.h".
+ */
+#include <stdbool.h>
+#else
+
+#ifndef __cplusplus
+/*
+ * The C language implementation does not provide the standard header file
+ * "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
+ * braindamage below.
+ */
+#if !defined(bool)
+#define bool int
+#endif
+#if !defined(true)
+#define true 1
+#endif
+#if !defined(false)
+#define false 0
+#endif
+#endif
+
+#endif
+
+#if defined(HAVE_STDINT_H)
+/*
+ * The C language implementation does correctly provide the standard header
+ * file "stdint.h".
+ */
+#include <stdint.h>
+#else
+/*
+ * The C language implementation does not provide the standard header file
+ * "stdint.h" as required by ISO/IEC 9899:1999. Try to compensate for this
+ * braindamage below.
+ */
+#include <limits.h>
+/**********/
+#if !defined(INT_FAST8_MIN)
+typedef signed char int_fast8_t;
+#define INT_FAST8_MIN (-127)
+#define INT_FAST8_MAX 128
+#endif
+/**********/
+#if !defined(UINT_FAST8_MIN)
+typedef unsigned char uint_fast8_t;
+#define UINT_FAST8_MIN 0
+#define UINT_FAST8_MAX 255
+#endif
+/**********/
+#if !defined(INT_FAST16_MIN)
+typedef short int_fast16_t;
+#define INT_FAST16_MIN SHRT_MIN
+#define INT_FAST16_MAX SHRT_MAX
+#endif
+/**********/
+#if !defined(UINT_FAST16_MIN)
+typedef unsigned short uint_fast16_t;
+#define UINT_FAST16_MIN USHRT_MIN
+#define UINT_FAST16_MAX USHRT_MAX
+#endif
+/**********/
+#if !defined(INT_FAST32_MIN)
+typedef int int_fast32_t;
+#define INT_FAST32_MIN INT_MIN
+#define INT_FAST32_MAX INT_MAX
+#endif
+/**********/
+#if !defined(UINT_FAST32_MIN)
+typedef unsigned int uint_fast32_t;
+#define UINT_FAST32_MIN UINT_MIN
+#define UINT_FAST32_MAX UINT_MAX
+#endif
+/**********/
+#if !defined(INT_FAST64_MIN)
+typedef longlong int_fast64_t;
+#define INT_FAST64_MIN LLONG_MIN
+#define INT_FAST64_MAX LLONG_MAX
+#endif
+/**********/
+#if !defined(UINT_FAST64_MIN)
+typedef ulonglong uint_fast64_t;
+#define UINT_FAST64_MIN ULLONG_MIN
+#define UINT_FAST64_MAX ULLONG_MAX
+#endif
+/**********/
+#endif
+
+/* The below macro is intended to be used for type casts. By using this
+ macro, type casts can be easily located in the source code with
+ tools like "grep". */
+#define JAS_CAST(t, e) \
+ ((t) (e))
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jas_version.c b/osframework/source/ImageLib/jpeg2000/jas_version.c
new file mode 100644
index 0000000..6846b19
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_version.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#include "jas_version.h"
+
+const char *jas_getversion()
+{
+ return JAS_VERSION;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jas_version.h b/osframework/source/ImageLib/jpeg2000/jas_version.h
new file mode 100644
index 0000000..697ace4
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jas_version.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jas_version.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JAS_VERSION_H
+#define JAS_VERSION_H
+
+#include "jas_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************\
+* Constants and types.
+\******************************************************************************/
+
+#if !defined(JAS_VERSION)
+/* The version information below should match that specified in
+ the "configure.in" file! */
+#define JAS_VERSION "unknown"
+#endif
+
+#define JAS_COPYRIGHT \
+ "Copyright (c) 1999-2000 Image Power, Inc. and the University of\n" \
+ " British Columbia.\n" \
+ "Copyright (c) 2001-2003 Michael David Adams.\n" \
+ "All rights reserved.\n"
+
+#define JAS_NOTES \
+ "For more information about this software, please visit the following\n" \
+ "web sites/pages:\n" \
+ " http://www.ece.uvic.ca/~mdadams/jasper\n" \
+ " http://www.jpeg.org/software\n" \
+ "To be added to the (moderated) JasPer software announcements\n" \
+ "mailing list, send an email to:\n" \
+ " jasper-announce-subscribe@yahoogroups.com\n" \
+ "To be added to the (unmoderated) JasPer software discussion\n" \
+ "mailing list, send an email to:\n" \
+ " jasper-discussion-subscribe@yahoogroups.com\n" \
+ "Please send any bug reports to:\n" \
+ " mdadams@ieee.org\n"
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+const char *jas_getversion(void);
+/* Get the version information for the JasPer library. */
+/* Note: Since libjasper can be built as a shared library, the version
+ returned by this function may not necessarily correspond to JAS_VERSION. */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jasper.h b/osframework/source/ImageLib/jpeg2000/jasper.h
new file mode 100644
index 0000000..e8d87dc
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jasper.h
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JAS_JASPER_H
+#define JAS_JASPER_H
+
+#include "jas_config.h"
+#include "jas_types.h"
+#include "jas_version.h"
+
+#include "jas_init.h"
+#include "jas_cm.h"
+#include "jas_icc.h"
+#include "jas_fix.h"
+#include "jas_debug.h"
+#include "jas_getopt.h"
+#include "jas_image.h"
+#include "jas_icc.h"
+#include "jas_math.h"
+#include "jas_malloc.h"
+#include "jas_seq.h"
+#include "jas_stream.h"
+#include "jas_string.h"
+#include "jas_tvp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jp2_cod.c b/osframework/source/ImageLib/jpeg2000/jp2_cod.c
new file mode 100644
index 0000000..278b70d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jp2_cod.c
@@ -0,0 +1,949 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JP2 Library
+ *
+ * $Id: jp2_cod.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "jas_stream.h"
+#include "jas_malloc.h"
+#include "jas_debug.h"
+
+#include "jp2_cod.h"
+
+/******************************************************************************\
+* Function prototypes.
+\******************************************************************************/
+
+#define ONES(n) ((1 << (n)) - 1)
+
+jp2_boxinfo_t *jp2_boxinfolookup(int type);
+
+static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val);
+static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val);
+static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val);
+static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val);
+static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val);
+static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val);
+static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val);
+static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val);
+
+static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val);
+
+jp2_box_t *jp2_box_get(jas_stream_t *in);
+void jp2_box_dump(jp2_box_t *box, FILE *out);
+
+static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out);
+static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out);
+static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out);
+static void jp2_bpcc_destroy(jp2_box_t *box);
+static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out);
+static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out);
+static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out);
+static void jp2_colr_destroy(jp2_box_t *box);
+static void jp2_cdef_destroy(jp2_box_t *box);
+static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out);
+static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out);
+static void jp2_cmap_destroy(jp2_box_t *box);
+static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out);
+static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out);
+static void jp2_pclr_destroy(jp2_box_t *box);
+static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out);
+static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out);
+
+/******************************************************************************\
+* Local data.
+\******************************************************************************/
+
+jp2_boxinfo_t jp2_boxinfos[] = {
+ {JP2_BOX_JP, "JP", 0,
+ {0, 0, jp2_jp_getdata, jp2_jp_putdata, 0}},
+ {JP2_BOX_FTYP, "FTYP", 0,
+ {0, 0, jp2_ftyp_getdata, jp2_ftyp_putdata, 0}},
+ {JP2_BOX_JP2H, "JP2H", JP2_BOX_SUPER,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_IHDR, "IHDR", 0,
+ {0, 0, jp2_ihdr_getdata, jp2_ihdr_putdata, 0}},
+ {JP2_BOX_BPCC, "BPCC", 0,
+ {0, jp2_bpcc_destroy, jp2_bpcc_getdata, jp2_bpcc_putdata, 0}},
+ {JP2_BOX_COLR, "COLR", 0,
+ {0, jp2_colr_destroy, jp2_colr_getdata, jp2_colr_putdata, jp2_colr_dumpdata}},
+ {JP2_BOX_PCLR, "PCLR", 0,
+ {0, jp2_pclr_destroy, jp2_pclr_getdata, jp2_pclr_putdata, jp2_pclr_dumpdata}},
+ {JP2_BOX_CMAP, "CMAP", 0,
+ {0, jp2_cmap_destroy, jp2_cmap_getdata, jp2_cmap_putdata, jp2_cmap_dumpdata}},
+ {JP2_BOX_CDEF, "CDEF", 0,
+ {0, jp2_cdef_destroy, jp2_cdef_getdata, jp2_cdef_putdata, jp2_cdef_dumpdata}},
+ {JP2_BOX_RES, "RES", JP2_BOX_SUPER,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_RESC, "RESC", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_RESD, "RESD", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_JP2C, "JP2C", JP2_BOX_NODATA,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_JP2I, "JP2I", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_XML, "XML", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_UUID, "UUID", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_UINF, "UINF", JP2_BOX_SUPER,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_ULST, "ULST", 0,
+ {0, 0, 0, 0, 0}},
+ {JP2_BOX_URL, "URL", 0,
+ {0, 0, 0, 0, 0}},
+ {0, 0, 0, {0, 0, 0, 0, 0}},
+};
+
+jp2_boxinfo_t jp2_boxinfo_unk = {
+ 0, "Unknown", 0, {0, 0, 0, 0, 0}
+};
+
+/******************************************************************************\
+* Box constructor.
+\******************************************************************************/
+
+jp2_box_t *jp2_box_create(int type)
+{
+ jp2_box_t *box;
+ jp2_boxinfo_t *boxinfo;
+
+ if (!(box = jas_malloc(sizeof(jp2_box_t)))) {
+ return 0;
+ }
+ memset(box, 0, sizeof(jp2_box_t));
+ box->type = type;
+ box->len = 0;
+ if (!(boxinfo = jp2_boxinfolookup(type))) {
+ return 0;
+ }
+ box->info = boxinfo;
+ box->ops = &boxinfo->ops;
+ return box;
+}
+
+/******************************************************************************\
+* Box destructor.
+\******************************************************************************/
+
+void jp2_box_destroy(jp2_box_t *box)
+{
+ if (box->ops->destroy) {
+ (*box->ops->destroy)(box);
+ }
+ jas_free(box);
+}
+
+static void jp2_bpcc_destroy(jp2_box_t *box)
+{
+ jp2_bpcc_t *bpcc = &box->data.bpcc;
+ if (bpcc->bpcs) {
+ jas_free(bpcc->bpcs);
+ bpcc->bpcs = 0;
+ }
+}
+
+static void jp2_cdef_destroy(jp2_box_t *box)
+{
+ jp2_cdef_t *cdef = &box->data.cdef;
+ if (cdef->ents) {
+ jas_free(cdef->ents);
+ cdef->ents = 0;
+ }
+}
+
+/******************************************************************************\
+* Box input.
+\******************************************************************************/
+
+jp2_box_t *jp2_box_get(jas_stream_t *in)
+{
+ jp2_box_t *box;
+ jp2_boxinfo_t *boxinfo;
+ jas_stream_t *tmpstream;
+ uint_fast32_t len;
+ uint_fast64_t extlen;
+ bool dataflag;
+
+ box = 0;
+ tmpstream = 0;
+
+ if (!(box = jas_malloc(sizeof(jp2_box_t)))) {
+ goto error;
+ }
+ box->ops = &jp2_boxinfo_unk.ops;
+ if (jp2_getuint32(in, &len) || jp2_getuint32(in, &box->type)) {
+ goto error;
+ }
+ boxinfo = jp2_boxinfolookup(box->type);
+ box->info = boxinfo;
+ box->ops = &boxinfo->ops;
+ box->len = len;
+ if (box->len == 1) {
+ if (jp2_getuint64(in, &extlen)) {
+ goto error;
+ }
+ box->len = extlen;
+ }
+ if (box->len != 0 && box->len < 8) {
+ goto error;
+ }
+
+ dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA));
+
+ if (dataflag) {
+ if (!(tmpstream = jas_stream_memopen(0, 0))) {
+ goto error;
+ }
+ if (jas_stream_copy(tmpstream, in, box->len - JP2_BOX_HDRLEN)) {
+ goto error;
+ }
+ jas_stream_rewind(tmpstream);
+
+ if (box->ops->getdata) {
+ if ((*box->ops->getdata)(box, tmpstream)) {
+ goto error;
+ }
+ }
+ jas_stream_close(tmpstream);
+ }
+
+#if 0
+ jp2_box_dump(box, stderr);
+#endif
+
+ return box;
+ abort();
+
+error:
+ if (box) {
+ jp2_box_destroy(box);
+ }
+ if (tmpstream) {
+ jas_stream_close(tmpstream);
+ }
+ return 0;
+}
+
+void jp2_box_dump(jp2_box_t *box, FILE *out)
+{
+ jp2_boxinfo_t *boxinfo;
+ boxinfo = jp2_boxinfolookup(box->type);
+ assert(boxinfo);
+
+ fprintf(out, "JP2 box: ");
+ fprintf(out, "type=%c%s%c (0x%08x); length=%d\n", '"', boxinfo->name,
+ '"', box->type, box->len);
+ if (box->ops->dumpdata) {
+ (*box->ops->dumpdata)(box, out);
+ }
+}
+
+static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_jp_t *jp = &box->data.jp;
+ if (jp2_getuint32(in, &jp->magic)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_ftyp_t *ftyp = &box->data.ftyp;
+ unsigned int i;
+ if (jp2_getuint32(in, &ftyp->majver) || jp2_getuint32(in, &ftyp->minver)) {
+ return -1;
+ }
+ ftyp->numcompatcodes = ((box->len - JP2_BOX_HDRLEN) - 8) / 4;
+ if (ftyp->numcompatcodes > JP2_FTYP_MAXCOMPATCODES) {
+ return -1;
+ }
+ for (i = 0; i < ftyp->numcompatcodes; ++i) {
+ if (jp2_getuint32(in, &ftyp->compatcodes[i])) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_ihdr_t *ihdr = &box->data.ihdr;
+ if (jp2_getuint32(in, &ihdr->height) || jp2_getuint32(in, &ihdr->width) ||
+ jp2_getuint16(in, &ihdr->numcmpts) || jp2_getuint8(in, &ihdr->bpc) ||
+ jp2_getuint8(in, &ihdr->comptype) || jp2_getuint8(in, &ihdr->csunk) ||
+ jp2_getuint8(in, &ihdr->ipr)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_bpcc_t *bpcc = &box->data.bpcc;
+ unsigned int i;
+ bpcc->numcmpts = box->len - JP2_BOX_HDRLEN;
+ if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * sizeof(uint_fast8_t)))) {
+ return -1;
+ }
+ for (i = 0; i < bpcc->numcmpts; ++i) {
+ if (jp2_getuint8(in, &bpcc->bpcs[i])) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out)
+{
+ jp2_colr_t *colr = &box->data.colr;
+ fprintf(out, "method=%d; pri=%d; approx=%d\n", (int)colr->method, (int)colr->pri, (int)colr->approx);
+ switch (colr->method) {
+ case JP2_COLR_ENUM:
+ fprintf(out, "csid=%d\n", (int)colr->csid);
+ break;
+ case JP2_COLR_ICC:
+ jas_memdump(out, colr->iccp, colr->iccplen);
+ break;
+ }
+}
+
+static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_colr_t *colr = &box->data.colr;
+ colr->csid = 0;
+ colr->iccp = 0;
+ colr->iccplen = 0;
+
+ if (jp2_getuint8(in, &colr->method) || jp2_getuint8(in, &colr->pri) ||
+ jp2_getuint8(in, &colr->approx)) {
+ return -1;
+ }
+ switch (colr->method) {
+ case JP2_COLR_ENUM:
+ if (jp2_getuint32(in, &colr->csid)) {
+ return -1;
+ }
+ break;
+ case JP2_COLR_ICC:
+ colr->iccplen = box->len - JP2_BOX_HDRLEN - 3;
+ if (!(colr->iccp = jas_malloc(colr->iccplen * sizeof(uint_fast8_t)))) {
+ return -1;
+ }
+ if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) {
+ return -1;
+ }
+ break;
+ }
+ return 0;
+}
+
+static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out)
+{
+ jp2_cdef_t *cdef = &box->data.cdef;
+ unsigned int i;
+ for (i = 0; i < cdef->numchans; ++i) {
+ fprintf(out, "channo=%d; type=%d; assoc=%d\n",
+ cdef->ents[i].channo, cdef->ents[i].type, cdef->ents[i].assoc);
+ }
+}
+
+static void jp2_colr_destroy(jp2_box_t *box)
+{
+ jp2_colr_t *colr = &box->data.colr;
+ if (colr->iccp) {
+ jas_free(colr->iccp);
+ }
+}
+
+static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_cdef_t *cdef = &box->data.cdef;
+ jp2_cdefchan_t *chan;
+ unsigned int channo;
+ if (jp2_getuint16(in, &cdef->numchans)) {
+ return -1;
+ }
+ if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) {
+ return -1;
+ }
+ for (channo = 0; channo < cdef->numchans; ++channo) {
+ chan = &cdef->ents[channo];
+ if (jp2_getuint16(in, &chan->channo) || jp2_getuint16(in, &chan->type) ||
+ jp2_getuint16(in, &chan->assoc)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Box output.
+\******************************************************************************/
+
+int jp2_box_put(jp2_box_t *box, jas_stream_t *out)
+{
+ jas_stream_t *tmpstream;
+ bool extlen;
+ bool dataflag;
+
+ tmpstream = 0;
+
+ dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA));
+
+ if (dataflag) {
+ tmpstream = jas_stream_memopen(0, 0);
+ if (box->ops->putdata) {
+ if ((*box->ops->putdata)(box, tmpstream)) {
+ goto error;
+ }
+ }
+ box->len = jas_stream_tell(tmpstream) + JP2_BOX_HDRLEN;
+ jas_stream_rewind(tmpstream);
+ }
+ extlen = (box->len >= (((uint_fast64_t)1) << 32)) != 0;
+ if (jp2_putuint32(out, extlen ? 1 : box->len)) {
+ goto error;
+ }
+ if (jp2_putuint32(out, box->type)) {
+ goto error;
+ }
+ if (extlen) {
+ if (jp2_putuint64(out, box->len)) {
+ goto error;
+ }
+ }
+
+ if (dataflag) {
+ if (jas_stream_copy(out, tmpstream, box->len - JP2_BOX_HDRLEN)) {
+ goto error;
+ }
+ jas_stream_close(tmpstream);
+ }
+
+ return 0;
+ abort();
+
+error:
+
+ if (tmpstream) {
+ jas_stream_close(tmpstream);
+ }
+ return -1;
+}
+
+static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_jp_t *jp = &box->data.jp;
+ if (jp2_putuint32(out, jp->magic)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_ftyp_t *ftyp = &box->data.ftyp;
+ unsigned int i;
+ if (jp2_putuint32(out, ftyp->majver) || jp2_putuint32(out, ftyp->minver)) {
+ return -1;
+ }
+ for (i = 0; i < ftyp->numcompatcodes; ++i) {
+ if (jp2_putuint32(out, ftyp->compatcodes[i])) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_ihdr_t *ihdr = &box->data.ihdr;
+ if (jp2_putuint32(out, ihdr->height) || jp2_putuint32(out, ihdr->width) ||
+ jp2_putuint16(out, ihdr->numcmpts) || jp2_putuint8(out, ihdr->bpc) ||
+ jp2_putuint8(out, ihdr->comptype) || jp2_putuint8(out, ihdr->csunk) ||
+ jp2_putuint8(out, ihdr->ipr)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_bpcc_t *bpcc = &box->data.bpcc;
+ unsigned int i;
+ for (i = 0; i < bpcc->numcmpts; ++i) {
+ if (jp2_putuint8(out, bpcc->bpcs[i])) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_colr_t *colr = &box->data.colr;
+ if (jp2_putuint8(out, colr->method) || jp2_putuint8(out, colr->pri) ||
+ jp2_putuint8(out, colr->approx)) {
+ return -1;
+ }
+ switch (colr->method) {
+ case JP2_COLR_ENUM:
+ if (jp2_putuint32(out, colr->csid)) {
+ return -1;
+ }
+ break;
+ case JP2_COLR_ICC:
+ if (jas_stream_write(out, colr->iccp,
+ JAS_CAST(int, colr->iccplen)) != JAS_CAST(int, colr->iccplen))
+ return -1;
+ break;
+ }
+ return 0;
+}
+
+static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ jp2_cdef_t *cdef = &box->data.cdef;
+ unsigned int i;
+ jp2_cdefchan_t *ent;
+
+ if (jp2_putuint16(out, cdef->numchans)) {
+ return -1;
+ }
+
+ for (i = 0; i < cdef->numchans; ++i) {
+ ent = &cdef->ents[i];
+ if (jp2_putuint16(out, ent->channo) ||
+ jp2_putuint16(out, ent->type) ||
+ jp2_putuint16(out, ent->assoc)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Input operations for primitive types.
+\******************************************************************************/
+
+static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val)
+{
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ if (val) {
+ *val = c;
+ }
+ return 0;
+}
+
+static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val)
+{
+ uint_fast16_t v;
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if (val) {
+ *val = v;
+ }
+ return 0;
+}
+
+static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val)
+{
+ uint_fast32_t v;
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if (val) {
+ *val = v;
+ }
+ return 0;
+}
+
+static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val)
+{
+ in = 0;
+ val = 0;
+ abort();
+}
+
+/******************************************************************************\
+* Output operations for primitive types.
+\******************************************************************************/
+
+static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val)
+{
+ if (jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val)
+{
+ if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
+ jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val)
+{
+ if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF ||
+ jas_stream_putc(out, (val >> 16) & 0xff) == EOF ||
+ jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
+ jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val)
+{
+ if (jp2_putuint32(out, (val >> 32) & 0xffffffffUL) ||
+ jp2_putuint32(out, val & 0xffffffffUL)) {
+ return -1;
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Miscellaneous code.
+\******************************************************************************/
+
+jp2_boxinfo_t *jp2_boxinfolookup(int type)
+{
+ jp2_boxinfo_t *boxinfo;
+ for (boxinfo = jp2_boxinfos; boxinfo->name; ++boxinfo) {
+ if (boxinfo->type == type) {
+ return boxinfo;
+ }
+ }
+ return &jp2_boxinfo_unk;
+}
+
+
+
+
+
+static void jp2_cmap_destroy(jp2_box_t *box)
+{
+ jp2_cmap_t *cmap = &box->data.cmap;
+ if (cmap->ents) {
+ jas_free(cmap->ents);
+ }
+}
+
+static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_cmap_t *cmap = &box->data.cmap;
+ jp2_cmapent_t *ent;
+ unsigned int i;
+
+ cmap->numchans = (box->len - JP2_BOX_HDRLEN) / 4;
+ if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) {
+ return -1;
+ }
+ for (i = 0; i < cmap->numchans; ++i) {
+ ent = &cmap->ents[i];
+ if (jp2_getuint16(in, &ent->cmptno) ||
+ jp2_getuint8(in, &ent->map) ||
+ jp2_getuint8(in, &ent->pcol)) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+ /* Eliminate compiler warning about unused variables. */
+ box = 0;
+ out = 0;
+
+ return -1;
+}
+
+static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out)
+{
+ jp2_cmap_t *cmap = &box->data.cmap;
+ unsigned int i;
+ jp2_cmapent_t *ent;
+ fprintf(out, "numchans = %d\n", (int) cmap->numchans);
+ for (i = 0; i < cmap->numchans; ++i) {
+ ent = &cmap->ents[i];
+ fprintf(out, "cmptno=%d; map=%d; pcol=%d\n",
+ (int) ent->cmptno, (int) ent->map, (int) ent->pcol);
+ }
+}
+
+static void jp2_pclr_destroy(jp2_box_t *box)
+{
+ jp2_pclr_t *pclr = &box->data.pclr;
+ if (pclr->lutdata) {
+ jas_free(pclr->lutdata);
+ }
+ if (pclr->bpc)
+ jas_free(pclr->bpc);
+}
+
+static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+ jp2_pclr_t *pclr = &box->data.pclr;
+ int lutsize;
+ unsigned int i;
+ unsigned int j;
+ int_fast32_t x;
+
+ pclr->lutdata = 0;
+
+ if (jp2_getuint16(in, &pclr->numlutents) ||
+ jp2_getuint8(in, &pclr->numchans)) {
+ return -1;
+ }
+ lutsize = pclr->numlutents * pclr->numchans;
+ if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) {
+ return -1;
+ }
+ if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) {
+ return -1;
+ }
+ for (i = 0; i < pclr->numchans; ++i) {
+ if (jp2_getuint8(in, &pclr->bpc[i])) {
+ return -1;
+ }
+ }
+ for (i = 0; i < pclr->numlutents; ++i) {
+ for (j = 0; j < pclr->numchans; ++j) {
+ if (jp2_getint(in, (pclr->bpc[j] & 0x80) != 0,
+ (pclr->bpc[j] & 0x7f) + 1, &x)) {
+ return -1;
+ }
+ pclr->lutdata[i * pclr->numchans + j] = x;
+ }
+ }
+ return 0;
+}
+
+static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+#if 0
+ jp2_pclr_t *pclr = &box->data.pclr;
+#endif
+/* Eliminate warning about unused variable. */
+box = 0;
+out = 0;
+ return -1;
+}
+
+static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out)
+{
+ jp2_pclr_t *pclr = &box->data.pclr;
+ unsigned int i;
+ int j;
+ fprintf(out, "numents=%d; numchans=%d\n", (int) pclr->numlutents,
+ (int) pclr->numchans);
+ for (i = 0; i < pclr->numlutents; ++i) {
+ for (j = 0; j < pclr->numchans; ++j) {
+ fprintf(out, "LUT[%d][%d]=%d\n", i, j, pclr->lutdata[i * pclr->numchans + j]);
+ }
+ }
+}
+
+static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val)
+{
+ int c;
+ int i;
+ uint_fast32_t v;
+ int m;
+
+ m = (n + 7) / 8;
+
+ v = 0;
+ for (i = 0; i < m; ++i) {
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ }
+ v &= ONES(n);
+ if (s) {
+ int sb;
+ sb = v & (1 << (8 * m - 1));
+ *val = ((~v) + 1) & ONES(8 * m);
+ if (sb) {
+ *val = -*val;
+ }
+ } else {
+ *val = v;
+ }
+
+ return 0;
+}
+
+jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo)
+{
+ unsigned int i;
+ jp2_cdefchan_t *cdefent;
+ for (i = 0; i < cdef->numchans; ++i) {
+ cdefent = &cdef->ents[i];
+ if (cdefent->channo == JAS_CAST(unsigned int, channo)) {
+ return cdefent;
+ }
+ }
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jp2_cod.h b/osframework/source/ImageLib/jpeg2000/jp2_cod.h
new file mode 100644
index 0000000..3e806e1
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jp2_cod.h
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JP2 Library
+ *
+ * $Id: jp2_cod.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JP2_COD_H
+#define JP2_COD_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+
+/******************************************************************************\
+* Macros.
+\******************************************************************************/
+
+#define JP2_SPTOBPC(s, p) \
+ ((((p) - 1) & 0x7f) | (((s) & 1) << 7))
+
+/******************************************************************************\
+* Box class.
+\******************************************************************************/
+
+#define JP2_BOX_HDRLEN 8
+
+/* Box types. */
+#define JP2_BOX_JP 0x6a502020 /* Signature */
+#define JP2_BOX_FTYP 0x66747970 /* File Type */
+#define JP2_BOX_JP2H 0x6a703268 /* JP2 Header */
+#define JP2_BOX_IHDR 0x69686472 /* Image Header */
+#define JP2_BOX_BPCC 0x62706363 /* Bits Per Component */
+#define JP2_BOX_COLR 0x636f6c72 /* Color Specification */
+#define JP2_BOX_PCLR 0x70636c72 /* Palette */
+#define JP2_BOX_CMAP 0x636d6170 /* Component Mapping */
+#define JP2_BOX_CDEF 0x63646566 /* Channel Definition */
+#define JP2_BOX_RES 0x72657320 /* Resolution */
+#define JP2_BOX_RESC 0x72657363 /* Capture Resolution */
+#define JP2_BOX_RESD 0x72657364 /* Default Display Resolution */
+#define JP2_BOX_JP2C 0x6a703263 /* Contiguous Code Stream */
+#define JP2_BOX_JP2I 0x6a703269 /* Intellectual Property */
+#define JP2_BOX_XML 0x786d6c20 /* XML */
+#define JP2_BOX_UUID 0x75756964 /* UUID */
+#define JP2_BOX_UINF 0x75696e66 /* UUID Info */
+#define JP2_BOX_ULST 0x75637374 /* UUID List */
+#define JP2_BOX_URL 0x75726c20 /* URL */
+
+#define JP2_BOX_SUPER 0x01
+#define JP2_BOX_NODATA 0x02
+
+/* JP box data. */
+
+#define JP2_JP_MAGIC 0x0d0a870a
+#define JP2_JP_LEN 12
+
+typedef struct {
+ uint_fast32_t magic;
+} jp2_jp_t;
+
+/* FTYP box data. */
+
+#define JP2_FTYP_MAXCOMPATCODES 32
+#define JP2_FTYP_MAJVER 0x6a703220
+#define JP2_FTYP_MINVER 0
+#define JP2_FTYP_COMPATCODE JP2_FTYP_MAJVER
+
+typedef struct {
+ uint_fast32_t majver;
+ uint_fast32_t minver;
+ uint_fast32_t numcompatcodes;
+ uint_fast32_t compatcodes[JP2_FTYP_MAXCOMPATCODES];
+} jp2_ftyp_t;
+
+/* IHDR box data. */
+
+#define JP2_IHDR_COMPTYPE 7
+#define JP2_IHDR_BPCNULL 255
+
+typedef struct {
+ uint_fast32_t width;
+ uint_fast32_t height;
+ uint_fast16_t numcmpts;
+ uint_fast8_t bpc;
+ uint_fast8_t comptype;
+ uint_fast8_t csunk;
+ uint_fast8_t ipr;
+} jp2_ihdr_t;
+
+/* BPCC box data. */
+
+typedef struct {
+ uint_fast16_t numcmpts;
+ uint_fast8_t *bpcs;
+} jp2_bpcc_t;
+
+/* COLR box data. */
+
+#define JP2_COLR_ENUM 1
+#define JP2_COLR_ICC 2
+#define JP2_COLR_PRI 0
+
+#define JP2_COLR_SRGB 16
+#define JP2_COLR_SGRAY 17
+#define JP2_COLR_SYCC 18
+
+typedef struct {
+ uint_fast8_t method;
+ uint_fast8_t pri;
+ uint_fast8_t approx;
+ uint_fast32_t csid;
+ uint_fast8_t *iccp;
+ int iccplen;
+ /* XXX - Someday we ought to add ICC profile data here. */
+} jp2_colr_t;
+
+/* PCLR box data. */
+
+typedef struct {
+ uint_fast16_t numlutents;
+ uint_fast8_t numchans;
+ int_fast32_t *lutdata;
+ uint_fast8_t *bpc;
+} jp2_pclr_t;
+
+/* CDEF box per-channel data. */
+
+#define JP2_CDEF_RGB_R 1
+#define JP2_CDEF_RGB_G 2
+#define JP2_CDEF_RGB_B 3
+
+#define JP2_CDEF_YCBCR_Y 1
+#define JP2_CDEF_YCBCR_CB 2
+#define JP2_CDEF_YCBCR_CR 3
+
+#define JP2_CDEF_GRAY_Y 1
+
+#define JP2_CDEF_TYPE_COLOR 0
+#define JP2_CDEF_TYPE_OPACITY 1
+#define JP2_CDEF_TYPE_UNSPEC 65535
+#define JP2_CDEF_ASOC_ALL 0
+#define JP2_CDEF_ASOC_NONE 65535
+
+typedef struct {
+ uint_fast16_t channo;
+ uint_fast16_t type;
+ uint_fast16_t assoc;
+} jp2_cdefchan_t;
+
+/* CDEF box data. */
+
+typedef struct {
+ uint_fast16_t numchans;
+ jp2_cdefchan_t *ents;
+} jp2_cdef_t;
+
+typedef struct {
+ uint_fast16_t cmptno;
+ uint_fast8_t map;
+ uint_fast8_t pcol;
+} jp2_cmapent_t;
+
+typedef struct {
+ uint_fast16_t numchans;
+ jp2_cmapent_t *ents;
+} jp2_cmap_t;
+
+#define JP2_CMAP_DIRECT 0
+#define JP2_CMAP_PALETTE 1
+
+/* Generic box. */
+
+struct jp2_boxops_s;
+typedef struct {
+
+ struct jp2_boxops_s *ops;
+ struct jp2_boxinfo_s *info;
+
+ uint_fast32_t type;
+ uint_fast32_t len;
+
+ union {
+ jp2_jp_t jp;
+ jp2_ftyp_t ftyp;
+ jp2_ihdr_t ihdr;
+ jp2_bpcc_t bpcc;
+ jp2_colr_t colr;
+ jp2_pclr_t pclr;
+ jp2_cdef_t cdef;
+ jp2_cmap_t cmap;
+ } data;
+
+} jp2_box_t;
+
+typedef struct jp2_boxops_s {
+ void (*init)(jp2_box_t *box);
+ void (*destroy)(jp2_box_t *box);
+ int (*getdata)(jp2_box_t *box, jas_stream_t *in);
+ int (*putdata)(jp2_box_t *box, jas_stream_t *out);
+ void (*dumpdata)(jp2_box_t *box, FILE *out);
+} jp2_boxops_t;
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+typedef struct jp2_boxinfo_s {
+ int type;
+ char *name;
+ int flags;
+ jp2_boxops_t ops;
+} jp2_boxinfo_t;
+
+/******************************************************************************\
+* Box class.
+\******************************************************************************/
+
+jp2_box_t *jp2_box_create(int type);
+void jp2_box_destroy(jp2_box_t *box);
+jp2_box_t *jp2_box_get(jas_stream_t *in);
+int jp2_box_put(jp2_box_t *box, jas_stream_t *out);
+
+#define JP2_DTYPETOBPC(dtype) \
+ ((JAS_IMAGE_CDT_GETSGND(dtype) << 7) | (JAS_IMAGE_CDT_GETPREC(dtype) - 1))
+#define JP2_BPCTODTYPE(bpc) \
+ (JAS_IMAGE_CDT_SETSGND(bpc >> 7) | JAS_IMAGE_CDT_SETPREC((bpc & 0x7f) + 1))
+
+#define ICC_CS_RGB 0x52474220
+#define ICC_CS_YCBCR 0x59436272
+#define ICC_CS_GRAY 0x47524159
+
+jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo);
+
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jp2_dec.c b/osframework/source/ImageLib/jpeg2000/jp2_dec.c
new file mode 100644
index 0000000..0e3479f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jp2_dec.c
@@ -0,0 +1,652 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JP2 Library
+ *
+ * $Id: jp2_dec.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_image.h"
+#include "jas_stream.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+#include "jas_malloc.h"
+#include "jas_version.h"
+
+#include "jp2_cod.h"
+#include "jp2_dec.h"
+
+#define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK))
+
+static jp2_dec_t *jp2_dec_create(void);
+static void jp2_dec_destroy(jp2_dec_t *dec);
+static int jp2_getcs(jp2_colr_t *colr);
+static int fromiccpcs(int cs);
+static int jp2_getct(int colorspace, int type, int assoc);
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+jas_image_t *jp2_decode(jas_stream_t *in, char *optstr)
+{
+ jp2_box_t *box;
+ int found;
+ jas_image_t *image;
+ jp2_dec_t *dec;
+ bool samedtype;
+ int dtype;
+ unsigned int i;
+ jp2_cmap_t *cmapd;
+ jp2_pclr_t *pclrd;
+ jp2_cdef_t *cdefd;
+ unsigned int channo;
+ int newcmptno;
+ int_fast32_t *lutents;
+#if 0
+ jp2_cdefchan_t *cdefent;
+ int cmptno;
+#endif
+ jp2_cmapent_t *cmapent;
+ jas_icchdr_t icchdr;
+ jas_iccprof_t *iccprof;
+
+ dec = 0;
+ box = 0;
+ image = 0;
+
+ if (!(dec = jp2_dec_create())) {
+ goto error;
+ }
+
+ /* Get the first box. This should be a JP box. */
+ if (!(box = jp2_box_get(in))) {
+ jas_eprintf("error: cannot get box\n");
+ goto error;
+ }
+ if (box->type != JP2_BOX_JP) {
+ jas_eprintf("error: expecting signature box\n");
+ goto error;
+ }
+ if (box->data.jp.magic != JP2_JP_MAGIC) {
+ jas_eprintf("incorrect magic number\n");
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /* Get the second box. This should be a FTYP box. */
+ if (!(box = jp2_box_get(in))) {
+ goto error;
+ }
+ if (box->type != JP2_BOX_FTYP) {
+ jas_eprintf("expecting file type box\n");
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /* Get more boxes... */
+ found = 0;
+ while ((box = jp2_box_get(in))) {
+ if (jas_getdbglevel() >= 1) {
+ fprintf(stderr, "box type %s\n", box->info->name);
+ }
+ switch (box->type) {
+ case JP2_BOX_JP2C:
+ found = 1;
+ break;
+ case JP2_BOX_IHDR:
+ if (!dec->ihdr) {
+ dec->ihdr = box;
+ box = 0;
+ }
+ break;
+ case JP2_BOX_BPCC:
+ if (!dec->bpcc) {
+ dec->bpcc = box;
+ box = 0;
+ }
+ break;
+ case JP2_BOX_CDEF:
+ if (!dec->cdef) {
+ dec->cdef = box;
+ box = 0;
+ }
+ break;
+ case JP2_BOX_PCLR:
+ if (!dec->pclr) {
+ dec->pclr = box;
+ box = 0;
+ }
+ break;
+ case JP2_BOX_CMAP:
+ if (!dec->cmap) {
+ dec->cmap = box;
+ box = 0;
+ }
+ break;
+ case JP2_BOX_COLR:
+ if (!dec->colr) {
+ dec->colr = box;
+ box = 0;
+ }
+ break;
+ }
+ if (box) {
+ jp2_box_destroy(box);
+ box = 0;
+ }
+ if (found) {
+ break;
+ }
+ }
+
+ if (!found) {
+ jas_eprintf("error: no code stream found\n");
+ goto error;
+ }
+
+ if (!(dec->image = jpc_decode(in, optstr))) {
+ jas_eprintf("error: cannot decode code stream\n");
+ goto error;
+ }
+
+ /* An IHDR box must be present. */
+ if (!dec->ihdr) {
+ jas_eprintf("error: missing IHDR box\n");
+ goto error;
+ }
+
+ /* Does the number of components indicated in the IHDR box match
+ the value specified in the code stream? */
+ if (dec->ihdr->data.ihdr.numcmpts != JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
+ jas_eprintf("warning: number of components mismatch\n");
+ }
+
+ /* At least one component must be present. */
+ if (!jas_image_numcmpts(dec->image)) {
+ jas_eprintf("error: no components\n");
+ goto error;
+ }
+
+ /* Determine if all components have the same data type. */
+ samedtype = true;
+ dtype = jas_image_cmptdtype(dec->image, 0);
+ for (i = 1; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
+ if (jas_image_cmptdtype(dec->image, i) != dtype) {
+ samedtype = false;
+ break;
+ }
+ }
+
+ /* Is the component data type indicated in the IHDR box consistent
+ with the data in the code stream? */
+ if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) ||
+ (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) {
+ jas_eprintf("warning: component data type mismatch\n");
+ }
+
+ /* Is the compression type supported? */
+ if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) {
+ jas_eprintf("error: unsupported compression type\n");
+ goto error;
+ }
+
+ if (dec->bpcc) {
+ /* Is the number of components indicated in the BPCC box
+ consistent with the code stream data? */
+ if (dec->bpcc->data.bpcc.numcmpts != JAS_CAST(uint, jas_image_numcmpts(
+ dec->image))) {
+ jas_eprintf("warning: number of components mismatch\n");
+ }
+ /* Is the component data type information indicated in the BPCC
+ box consistent with the code stream data? */
+ if (!samedtype) {
+ for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
+ if (jas_image_cmptdtype(dec->image, i) != JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) {
+ jas_eprintf("warning: component data type mismatch\n");
+ }
+ }
+ } else {
+ jas_eprintf("warning: superfluous BPCC box\n");
+ }
+ }
+
+ /* A COLR box must be present. */
+ if (!dec->colr) {
+ jas_eprintf("error: no COLR box\n");
+ goto error;
+ }
+
+ switch (dec->colr->data.colr.method) {
+ case JP2_COLR_ENUM:
+ jas_image_setclrspc(dec->image, jp2_getcs(&dec->colr->data.colr));
+ break;
+ case JP2_COLR_ICC:
+ iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp,
+ dec->colr->data.colr.iccplen);
+ assert(iccprof);
+ jas_iccprof_gethdr(iccprof, &icchdr);
+ jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc);
+ jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc));
+ dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof);
+ assert(dec->image->cmprof_);
+ jas_iccprof_destroy(iccprof);
+ break;
+ }
+
+ /* If a CMAP box is present, a PCLR box must also be present. */
+ if (dec->cmap && !dec->pclr) {
+ jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n");
+ jp2_box_destroy(dec->cmap);
+ dec->cmap = 0;
+ }
+
+ /* If a CMAP box is not present, a PCLR box must not be present. */
+ if (!dec->cmap && dec->pclr) {
+ jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n");
+ jp2_box_destroy(dec->pclr);
+ dec->pclr = 0;
+ }
+
+ /* Determine the number of channels (which is essentially the number
+ of components after any palette mappings have been applied). */
+ dec->numchans = dec->cmap ? dec->cmap->data.cmap.numchans : JAS_CAST(uint, jas_image_numcmpts(dec->image));
+
+ /* Perform a basic sanity check on the CMAP box if present. */
+ if (dec->cmap) {
+ for (i = 0; i < dec->numchans; ++i) {
+ /* Is the component number reasonable? */
+ if (dec->cmap->data.cmap.ents[i].cmptno >= JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
+ jas_eprintf("error: invalid component number in CMAP box\n");
+ goto error;
+ }
+ /* Is the LUT index reasonable? */
+ if (dec->cmap->data.cmap.ents[i].pcol >= dec->pclr->data.pclr.numchans) {
+ jas_eprintf("error: invalid CMAP LUT index\n");
+ goto error;
+ }
+ }
+ }
+
+ /* Allocate space for the channel-number to component-number LUT. */
+ if (!(dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)))) {
+ jas_eprintf("error: no memory\n");
+ goto error;
+ }
+
+ if (!dec->cmap) {
+ for (i = 0; i < dec->numchans; ++i) {
+ dec->chantocmptlut[i] = i;
+ }
+ } else {
+ cmapd = &dec->cmap->data.cmap;
+ pclrd = &dec->pclr->data.pclr;
+ cdefd = &dec->cdef->data.cdef;
+ for (channo = 0; channo < cmapd->numchans; ++channo) {
+ cmapent = &cmapd->ents[channo];
+ if (cmapent->map == JP2_CMAP_DIRECT) {
+ dec->chantocmptlut[channo] = channo;
+ } else if (cmapent->map == JP2_CMAP_PALETTE) {
+ lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t));
+ for (i = 0; i < pclrd->numlutents; ++i) {
+ lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans];
+ }
+ newcmptno = jas_image_numcmpts(dec->image);
+ jas_image_depalettize(dec->image, cmapent->cmptno, pclrd->numlutents, lutents, JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno);
+ dec->chantocmptlut[channo] = newcmptno;
+ jas_free(lutents);
+#if 0
+ if (dec->cdef) {
+ cdefent = jp2_cdef_lookup(cdefd, channo);
+ if (!cdefent) {
+ abort();
+ }
+ jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), cdefent->type, cdefent->assoc));
+ } else {
+ jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), 0, channo + 1));
+ }
+#endif
+ }
+ }
+ }
+
+ /* Mark all components as being of unknown type. */
+
+ for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
+ jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN);
+ }
+
+ /* Determine the type of each component. */
+ if (dec->cdef) {
+ for (i = 0; i < dec->numchans; ++i) {
+ jas_image_setcmpttype(dec->image,
+ dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo],
+ jp2_getct(jas_image_clrspc(dec->image),
+ dec->cdef->data.cdef.ents[i].type, dec->cdef->data.cdef.ents[i].assoc));
+ }
+ } else {
+ for (i = 0; i < dec->numchans; ++i) {
+ jas_image_setcmpttype(dec->image, dec->chantocmptlut[i],
+ jp2_getct(jas_image_clrspc(dec->image), 0, i + 1));
+ }
+ }
+
+ /* Delete any components that are not of interest. */
+ for (i = jas_image_numcmpts(dec->image); i > 0; --i) {
+ if (jas_image_cmpttype(dec->image, i - 1) == JAS_IMAGE_CT_UNKNOWN) {
+ jas_image_delcmpt(dec->image, i - 1);
+ }
+ }
+
+ /* Ensure that some components survived. */
+ if (!jas_image_numcmpts(dec->image)) {
+ jas_eprintf("error: no components\n");
+ goto error;
+ }
+#if 0
+fprintf(stderr, "no of components is %d\n", jas_image_numcmpts(dec->image));
+#endif
+
+ /* Prevent the image from being destroyed later. */
+ image = dec->image;
+ dec->image = 0;
+
+ jp2_dec_destroy(dec);
+
+ return image;
+
+error:
+ if (box) {
+ jp2_box_destroy(box);
+ }
+ if (dec) {
+ jp2_dec_destroy(dec);
+ }
+ return 0;
+}
+
+int jp2_validate(jas_stream_t *in)
+{
+ char buf[JP2_VALIDATELEN];
+ int i;
+ int n;
+#if 0
+ jas_stream_t *tmpstream;
+ jp2_box_t *box;
+#endif
+
+ assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN);
+
+ /* Read the validation data (i.e., the data used for detecting
+ the format). */
+ if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) {
+ return -1;
+ }
+
+ /* Put the validation data back onto the stream, so that the
+ stream position will not be changed. */
+ for (i = n - 1; i >= 0; --i) {
+ if (jas_stream_ungetc(in, buf[i]) == EOF) {
+ return -1;
+ }
+ }
+
+ /* Did we read enough data? */
+ if (n < JP2_VALIDATELEN) {
+ return -1;
+ }
+
+ /* Is the box type correct? */
+ if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) !=
+ JP2_BOX_JP)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static jp2_dec_t *jp2_dec_create(void)
+{
+ jp2_dec_t *dec;
+
+ if (!(dec = jas_malloc(sizeof(jp2_dec_t)))) {
+ return 0;
+ }
+ dec->ihdr = 0;
+ dec->bpcc = 0;
+ dec->cdef = 0;
+ dec->pclr = 0;
+ dec->image = 0;
+ dec->chantocmptlut = 0;
+ dec->cmap = 0;
+ dec->colr = 0;
+ return dec;
+}
+
+static void jp2_dec_destroy(jp2_dec_t *dec)
+{
+ if (dec->ihdr) {
+ jp2_box_destroy(dec->ihdr);
+ }
+ if (dec->bpcc) {
+ jp2_box_destroy(dec->bpcc);
+ }
+ if (dec->cdef) {
+ jp2_box_destroy(dec->cdef);
+ }
+ if (dec->pclr) {
+ jp2_box_destroy(dec->pclr);
+ }
+ if (dec->image) {
+ jas_image_destroy(dec->image);
+ }
+ if (dec->cmap) {
+ jp2_box_destroy(dec->cmap);
+ }
+ if (dec->colr) {
+ jp2_box_destroy(dec->colr);
+ }
+ if (dec->chantocmptlut) {
+ jas_free(dec->chantocmptlut);
+ }
+ jas_free(dec);
+}
+
+static int jp2_getct(int colorspace, int type, int assoc)
+{
+ if (type == 1 && assoc == 0) {
+ return JAS_IMAGE_CT_OPACITY;
+ }
+ if (type == 0 && assoc >= 1 && assoc <= 65534) {
+ switch (colorspace) {
+ case JAS_CLRSPC_FAM_RGB:
+ switch (assoc) {
+ case JP2_CDEF_RGB_R:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R);
+ break;
+ case JP2_CDEF_RGB_G:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G);
+ break;
+ case JP2_CDEF_RGB_B:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B);
+ break;
+ }
+ break;
+ case JAS_CLRSPC_FAM_YCBCR:
+ switch (assoc) {
+ case JP2_CDEF_YCBCR_Y:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y);
+ break;
+ case JP2_CDEF_YCBCR_CB:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB);
+ break;
+ case JP2_CDEF_YCBCR_CR:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR);
+ break;
+ }
+ break;
+ case JAS_CLRSPC_FAM_GRAY:
+ switch (assoc) {
+ case JP2_CDEF_GRAY_Y:
+ return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
+ break;
+ }
+ break;
+ default:
+ return JAS_IMAGE_CT_COLOR(assoc - 1);
+ break;
+ }
+ }
+ return JAS_IMAGE_CT_UNKNOWN;
+}
+
+static int jp2_getcs(jp2_colr_t *colr)
+{
+ if (colr->method == JP2_COLR_ENUM) {
+ switch (colr->csid) {
+ case JP2_COLR_SRGB:
+ return JAS_CLRSPC_SRGB;
+ break;
+ case JP2_COLR_SYCC:
+ return JAS_CLRSPC_SYCBCR;
+ break;
+ case JP2_COLR_SGRAY:
+ return JAS_CLRSPC_SGRAY;
+ break;
+ }
+ }
+ return JAS_CLRSPC_UNKNOWN;
+}
+
+static int fromiccpcs(int cs)
+{
+ switch (cs) {
+ case ICC_CS_RGB:
+ return JAS_CLRSPC_GENRGB;
+ break;
+ case ICC_CS_YCBCR:
+ return JAS_CLRSPC_GENYCBCR;
+ break;
+ case ICC_CS_GRAY:
+ return JAS_CLRSPC_GENGRAY;
+ break;
+ }
+ return JAS_CLRSPC_UNKNOWN;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jp2_dec.h b/osframework/source/ImageLib/jpeg2000/jp2_dec.h
new file mode 100644
index 0000000..2e124d6
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jp2_dec.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JP2_DEC_H
+#define JP2_DEC_H
+
+#include "jas_image.h"
+#include "jas_stream.h"
+#include "jp2_cod.h"
+
+typedef struct {
+
+ jp2_box_t *pclr;
+ jp2_box_t *cdef;
+ jp2_box_t *ihdr;
+ jp2_box_t *bpcc;
+ jp2_box_t *cmap;
+ jp2_box_t *colr;
+ jas_image_t *image;
+ uint_fast16_t numchans;
+ uint_fast16_t *chantocmptlut;
+
+} jp2_dec_t;
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jp2_enc.c b/osframework/source/ImageLib/jpeg2000/jp2_enc.c
new file mode 100644
index 0000000..f905748
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jp2_enc.c
@@ -0,0 +1,485 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JP2 Library
+ *
+ * $Id: jp2_enc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include "jas_malloc.h"
+#include "jas_image.h"
+#include "jas_stream.h"
+#include "jas_cm.h"
+#include "jas_icc.h"
+#include "jp2_cod.h"
+
+static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype);
+static int clrspctojp2(jas_clrspc_t clrspc);
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
+{
+ jp2_box_t *box;
+ jp2_ftyp_t *ftyp;
+ jp2_ihdr_t *ihdr;
+ jas_stream_t *tmpstream;
+ int allcmptssame;
+ jp2_bpcc_t *bpcc;
+ long len;
+ uint_fast16_t cmptno;
+ jp2_colr_t *colr;
+ char buf[4096];
+ uint_fast32_t overhead;
+ jp2_cdefchan_t *cdefchanent;
+ jp2_cdef_t *cdef;
+ int i;
+ uint_fast32_t typeasoc;
+jas_iccprof_t *iccprof;
+jas_stream_t *iccstream;
+int pos;
+int needcdef;
+int prec;
+int sgnd;
+
+ box = 0;
+ tmpstream = 0;
+
+ allcmptssame = 1;
+ sgnd = jas_image_cmptsgnd(image, 0);
+ prec = jas_image_cmptprec(image, 0);
+ for (i = 1; i < jas_image_numcmpts(image); ++i) {
+ if (jas_image_cmptsgnd(image, i) != sgnd ||
+ jas_image_cmptprec(image, i) != prec) {
+ allcmptssame = 0;
+ break;
+ }
+ }
+
+ /* Output the signature box. */
+
+ if (!(box = jp2_box_create(JP2_BOX_JP))) {
+ goto error;
+ }
+ box->data.jp.magic = JP2_JP_MAGIC;
+ if (jp2_box_put(box, out)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /* Output the file type box. */
+
+ if (!(box = jp2_box_create(JP2_BOX_FTYP))) {
+ goto error;
+ }
+ ftyp = &box->data.ftyp;
+ ftyp->majver = JP2_FTYP_MAJVER;
+ ftyp->minver = JP2_FTYP_MINVER;
+ ftyp->numcompatcodes = 1;
+ ftyp->compatcodes[0] = JP2_FTYP_COMPATCODE;
+ if (jp2_box_put(box, out)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /*
+ * Generate the data portion of the JP2 header box.
+ * We cannot simply output the header for this box
+ * since we do not yet know the correct value for the length
+ * field.
+ */
+
+ if (!(tmpstream = jas_stream_memopen(0, 0))) {
+ goto error;
+ }
+
+ /* Generate image header box. */
+
+ if (!(box = jp2_box_create(JP2_BOX_IHDR))) {
+ goto error;
+ }
+ ihdr = &box->data.ihdr;
+ ihdr->width = jas_image_width(image);
+ ihdr->height = jas_image_height(image);
+ ihdr->numcmpts = jas_image_numcmpts(image);
+ ihdr->bpc = allcmptssame ? JP2_SPTOBPC(jas_image_cmptsgnd(image, 0),
+ jas_image_cmptprec(image, 0)) : JP2_IHDR_BPCNULL;
+ ihdr->comptype = JP2_IHDR_COMPTYPE;
+ ihdr->csunk = 0;
+ ihdr->ipr = 0;
+ if (jp2_box_put(box, tmpstream)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /* Generate bits per component box. */
+
+ if (!allcmptssame) {
+ if (!(box = jp2_box_create(JP2_BOX_BPCC))) {
+ goto error;
+ }
+ bpcc = &box->data.bpcc;
+ bpcc->numcmpts = jas_image_numcmpts(image);
+ if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts *
+ sizeof(uint_fast8_t)))) {
+ goto error;
+ }
+ for (cmptno = 0; cmptno < bpcc->numcmpts; ++cmptno) {
+ bpcc->bpcs[cmptno] = JP2_SPTOBPC(jas_image_cmptsgnd(image,
+ cmptno), jas_image_cmptprec(image, cmptno));
+ }
+ if (jp2_box_put(box, tmpstream)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+ }
+
+ /* Generate color specification box. */
+
+ if (!(box = jp2_box_create(JP2_BOX_COLR))) {
+ goto error;
+ }
+ colr = &box->data.colr;
+ switch (jas_image_clrspc(image)) {
+ case JAS_CLRSPC_SRGB:
+ case JAS_CLRSPC_SYCBCR:
+ case JAS_CLRSPC_SGRAY:
+ colr->method = JP2_COLR_ENUM;
+ colr->csid = clrspctojp2(jas_image_clrspc(image));
+ colr->pri = JP2_COLR_PRI;
+ colr->approx = 0;
+ break;
+ default:
+ colr->method = JP2_COLR_ICC;
+ colr->pri = JP2_COLR_PRI;
+ colr->approx = 0;
+ iccprof = jas_iccprof_createfromcmprof(jas_image_cmprof(image));
+ assert(iccprof);
+ iccstream = jas_stream_memopen(0, 0);
+ assert(iccstream);
+ if (jas_iccprof_save(iccprof, iccstream))
+ abort();
+ if ((pos = jas_stream_tell(iccstream)) < 0)
+ abort();
+ colr->iccplen = pos;
+ colr->iccp = jas_malloc(pos);
+ assert(colr->iccp);
+ jas_stream_rewind(iccstream);
+ if (jas_stream_read(iccstream, colr->iccp, colr->iccplen) != colr->iccplen)
+ abort();
+ jas_stream_close(iccstream);
+ jas_iccprof_destroy(iccprof);
+ break;
+ }
+ if (jp2_box_put(box, tmpstream)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ needcdef = 1;
+ switch (jas_clrspc_fam(jas_image_clrspc(image))) {
+ case JAS_CLRSPC_FAM_RGB:
+ if (jas_image_cmpttype(image, 0) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R) &&
+ jas_image_cmpttype(image, 1) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G) &&
+ jas_image_cmpttype(image, 2) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B))
+ needcdef = 0;
+ break;
+ case JAS_CLRSPC_FAM_YCBCR:
+ if (jas_image_cmpttype(image, 0) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y) &&
+ jas_image_cmpttype(image, 1) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB) &&
+ jas_image_cmpttype(image, 2) ==
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR))
+ needcdef = 0;
+ break;
+ case JAS_CLRSPC_FAM_GRAY:
+ if (jas_image_cmpttype(image, 0) ==
+ JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y))
+ needcdef = 0;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ if (needcdef) {
+ if (!(box = jp2_box_create(JP2_BOX_CDEF))) {
+ goto error;
+ }
+ cdef = &box->data.cdef;
+ cdef->numchans = jas_image_numcmpts(image);
+ cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t));
+ for (i = 0; i < jas_image_numcmpts(image); ++i) {
+ cdefchanent = &cdef->ents[i];
+ cdefchanent->channo = i;
+ typeasoc = jp2_gettypeasoc(jas_image_clrspc(image), jas_image_cmpttype(image, i));
+ cdefchanent->type = typeasoc >> 16;
+ cdefchanent->assoc = typeasoc & 0x7fff;
+ }
+ if (jp2_box_put(box, tmpstream)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+ }
+
+ /* Determine the total length of the JP2 header box. */
+
+ len = jas_stream_tell(tmpstream);
+ jas_stream_rewind(tmpstream);
+
+ /*
+ * Output the JP2 header box and all of the boxes which it contains.
+ */
+
+ if (!(box = jp2_box_create(JP2_BOX_JP2H))) {
+ goto error;
+ }
+ box->len = len + JP2_BOX_HDRLEN;
+ if (jp2_box_put(box, out)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ if (jas_stream_copy(out, tmpstream, len)) {
+ goto error;
+ }
+
+ jas_stream_close(tmpstream);
+ tmpstream = 0;
+
+ /*
+ * Output the contiguous code stream box.
+ */
+
+ if (!(box = jp2_box_create(JP2_BOX_JP2C))) {
+ goto error;
+ }
+ box->len = 0;
+ if (jp2_box_put(box, out)) {
+ goto error;
+ }
+ jp2_box_destroy(box);
+ box = 0;
+
+ /* Output the JPEG-2000 code stream. */
+
+ overhead = jas_stream_getrwcount(out);
+ sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""),
+ (unsigned long) overhead);
+
+ if (jpc_encode(image, out, buf)) {
+ goto error;
+ }
+
+ return 0;
+ abort();
+
+error:
+
+ if (box) {
+ jp2_box_destroy(box);
+ }
+ if (tmpstream) {
+ jas_stream_close(tmpstream);
+ }
+ return -1;
+}
+
+static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype)
+{
+ int type;
+ int asoc;
+
+ if (ctype & JAS_IMAGE_CT_OPACITY) {
+ type = JP2_CDEF_TYPE_OPACITY;
+ asoc = JP2_CDEF_ASOC_ALL;
+ goto done;
+ }
+
+ type = JP2_CDEF_TYPE_UNSPEC;
+ asoc = JP2_CDEF_ASOC_NONE;
+ switch (jas_clrspc_fam(colorspace)) {
+ case JAS_CLRSPC_FAM_RGB:
+ switch (JAS_IMAGE_CT_COLOR(ctype)) {
+ case JAS_IMAGE_CT_RGB_R:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_RGB_R;
+ break;
+ case JAS_IMAGE_CT_RGB_G:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_RGB_G;
+ break;
+ case JAS_IMAGE_CT_RGB_B:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_RGB_B;
+ break;
+ }
+ break;
+ case JAS_CLRSPC_FAM_YCBCR:
+ switch (JAS_IMAGE_CT_COLOR(ctype)) {
+ case JAS_IMAGE_CT_YCBCR_Y:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_YCBCR_Y;
+ break;
+ case JAS_IMAGE_CT_YCBCR_CB:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_YCBCR_CB;
+ break;
+ case JAS_IMAGE_CT_YCBCR_CR:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_YCBCR_CR;
+ break;
+ }
+ break;
+ case JAS_CLRSPC_FAM_GRAY:
+ type = JP2_CDEF_TYPE_COLOR;
+ asoc = JP2_CDEF_GRAY_Y;
+ break;
+ }
+
+done:
+ return (type << 16) | asoc;
+}
+
+static int clrspctojp2(jas_clrspc_t clrspc)
+{
+ switch (clrspc) {
+ case JAS_CLRSPC_SRGB:
+ return JP2_COLR_SRGB;
+ case JAS_CLRSPC_SYCBCR:
+ return JP2_COLR_SYCC;
+ case JAS_CLRSPC_SGRAY:
+ return JP2_COLR_SGRAY;
+ default:
+ abort();
+ break;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_bs.c b/osframework/source/ImageLib/jpeg2000/jpc_bs.c
new file mode 100644
index 0000000..fb1223c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_bs.c
@@ -0,0 +1,486 @@
+/*
+ * Copyright (c) 1999-2000, Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Bit Stream Class
+ *
+ * $Id: jpc_bs.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "jas_malloc.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+
+#include "jpc_bs.h"
+
+/******************************************************************************\
+* Local function prototypes.
+\******************************************************************************/
+
+static jpc_bitstream_t *jpc_bitstream_alloc(void);
+
+/******************************************************************************\
+* Code for opening and closing bit streams.
+\******************************************************************************/
+
+/* Open a bit stream from a stream. */
+jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, char *mode)
+{
+ jpc_bitstream_t *bitstream;
+
+ /* Ensure that the open mode is valid. */
+ assert(!strcmp(mode, "r") || !strcmp(mode, "w") || !strcmp(mode, "r+")
+ || !strcmp(mode, "w+"));
+
+ if (!(bitstream = jpc_bitstream_alloc())) {
+ return 0;
+ }
+
+ /* By default, do not close the underlying (character) stream, upon
+ the close of the bit stream. */
+ bitstream->flags_ = JPC_BITSTREAM_NOCLOSE;
+
+ bitstream->stream_ = stream;
+ bitstream->openmode_ = (mode[0] == 'w') ? JPC_BITSTREAM_WRITE :
+ JPC_BITSTREAM_READ;
+
+ /* Mark the data buffer as empty. */
+ bitstream->cnt_ = (bitstream->openmode_ == JPC_BITSTREAM_READ) ? 0 : 8;
+ bitstream->buf_ = 0;
+
+ return bitstream;
+}
+
+/* Close a bit stream. */
+int jpc_bitstream_close(jpc_bitstream_t *bitstream)
+{
+ int ret = 0;
+
+ /* Align to the next byte boundary while considering the effects of
+ bit stuffing. */
+ if (jpc_bitstream_align(bitstream)) {
+ ret = -1;
+ }
+
+ /* If necessary, close the underlying (character) stream. */
+ if (!(bitstream->flags_ & JPC_BITSTREAM_NOCLOSE) && bitstream->stream_) {
+ if (jas_stream_close(bitstream->stream_)) {
+ ret = -1;
+ }
+ bitstream->stream_ = 0;
+ }
+
+ jas_free(bitstream);
+ return ret;
+}
+
+/* Allocate a new bit stream. */
+static jpc_bitstream_t *jpc_bitstream_alloc()
+{
+ jpc_bitstream_t *bitstream;
+
+ /* Allocate memory for the new bit stream object. */
+ if (!(bitstream = jas_malloc(sizeof(jpc_bitstream_t)))) {
+ return 0;
+ }
+ /* Initialize all of the data members. */
+ bitstream->stream_ = 0;
+ bitstream->cnt_ = 0;
+ bitstream->flags_ = 0;
+ bitstream->openmode_ = 0;
+
+ return bitstream;
+}
+
+/******************************************************************************\
+* Code for reading/writing from/to bit streams.
+\******************************************************************************/
+
+/* Get a bit from a bit stream. */
+int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream)
+{
+ int ret;
+ JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func(%p)\n", bitstream));
+ ret = jpc_bitstream_getbit_macro(bitstream);
+ JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func -> %d\n", ret));
+ return ret;
+}
+
+/* Put a bit to a bit stream. */
+int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int b)
+{
+ int ret;
+ JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func(%p, %d)\n", bitstream, b));
+ ret = jpc_bitstream_putbit_macro(bitstream, b);
+ JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func() -> %d\n", ret));
+ return ret;
+}
+
+/* Get one or more bits from a bit stream. */
+long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n)
+{
+ long v;
+ int u;
+
+ /* We can reliably get at most 31 bits since ISO/IEC 9899 only
+ guarantees that a long can represent values up to 2^31-1. */
+ assert(n >= 0 && n < 32);
+
+ /* Get the number of bits requested from the specified bit stream. */
+ v = 0;
+ while (--n >= 0) {
+ if ((u = jpc_bitstream_getbit(bitstream)) < 0) {
+ return -1;
+ }
+ v = (v << 1) | u;
+ }
+ return v;
+}
+
+/* Put one or more bits to a bit stream. */
+int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v)
+{
+ int m;
+
+ /* We can reliably put at most 31 bits since ISO/IEC 9899 only
+ guarantees that a long can represent values up to 2^31-1. */
+ assert(n >= 0 && n < 32);
+ /* Ensure that only the bits to be output are nonzero. */
+ assert(!(v & (~JAS_ONES(n))));
+
+ /* Put the desired number of bits to the specified bit stream. */
+ m = n - 1;
+ while (--n >= 0) {
+ if (jpc_bitstream_putbit(bitstream, (v >> m) & 1) == EOF) {
+ return EOF;
+ }
+ v <<= 1;
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Code for buffer filling and flushing.
+\******************************************************************************/
+
+/* Fill the buffer for a bit stream. */
+int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream)
+{
+ int c;
+ /* Note: The count has already been decremented by the caller. */
+ assert(bitstream->openmode_ & JPC_BITSTREAM_READ);
+ assert(bitstream->cnt_ <= 0);
+
+ if (bitstream->flags_ & JPC_BITSTREAM_ERR) {
+ bitstream->cnt_ = 0;
+ return -1;
+ }
+
+ if (bitstream->flags_ & JPC_BITSTREAM_EOF) {
+ bitstream->buf_ = 0x7f;
+ bitstream->cnt_ = 7;
+ return 1;
+ }
+
+ bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;
+ if ((c = jas_stream_getc((bitstream)->stream_)) == EOF) {
+ bitstream->flags_ |= JPC_BITSTREAM_EOF;
+ return 1;
+ }
+ bitstream->cnt_ = (bitstream->buf_ == 0xff00) ? 6 : 7;
+ bitstream->buf_ |= c & ((1 << (bitstream->cnt_ + 1)) - 1);
+ return (bitstream->buf_ >> bitstream->cnt_) & 1;
+}
+
+
+/******************************************************************************\
+* Code related to flushing.
+\******************************************************************************/
+
+/* Does the bit stream need to be aligned to a byte boundary (considering
+ the effects of bit stuffing)? */
+int jpc_bitstream_needalign(jpc_bitstream_t *bitstream)
+{
+ if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
+ /* The bit stream is open for reading. */
+ /* If there are any bits buffered for reading, or the
+ previous byte forced a stuffed bit, alignment is
+ required. */
+ if ((bitstream->cnt_ < 8 && bitstream->cnt_ > 0) ||
+ ((bitstream->buf_ >> 8) & 0xff) == 0xff) {
+ return 1;
+ }
+ } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
+ /* The bit stream is open for writing. */
+ /* If there are any bits buffered for writing, or the
+ previous byte forced a stuffed bit, alignment is
+ required. */
+ if ((bitstream->cnt_ < 8 && bitstream->cnt_ >= 0) ||
+ ((bitstream->buf_ >> 8) & 0xff) == 0xff) {
+ return 1;
+ }
+ } else {
+ /* This should not happen. Famous last words, eh? :-) */
+ assert(0);
+ return -1;
+ }
+ return 0;
+}
+
+/* How many additional bytes would be output if we align the bit stream? */
+int jpc_bitstream_pending(jpc_bitstream_t *bitstream)
+{
+ if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
+ /* The bit stream is being used for writing. */
+#if 1
+ /* XXX - Is this really correct? Check someday... */
+ if (bitstream->cnt_ < 8) {
+ return 1;
+ }
+#else
+ if (bitstream->cnt_ < 8) {
+ if (((bitstream->buf_ >> 8) & 0xff) == 0xff) {
+ return 2;
+ }
+ return 1;
+ }
+#endif
+ return 0;
+ } else {
+ /* This operation should not be invoked on a bit stream that
+ is being used for reading. */
+ return -1;
+ }
+}
+
+/* Align the bit stream to a byte boundary. */
+int jpc_bitstream_align(jpc_bitstream_t *bitstream)
+{
+ int ret;
+ if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
+ ret = jpc_bitstream_inalign(bitstream, 0, 0);
+ } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
+ ret = jpc_bitstream_outalign(bitstream, 0);
+ } else {
+ abort();
+ }
+ return ret;
+}
+
+/* Align a bit stream in the input case. */
+int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask,
+ int filldata)
+{
+ int n;
+ int v;
+ int u;
+ int numfill;
+ int m;
+
+ numfill = 7;
+ m = 0;
+ v = 0;
+ if (bitstream->cnt_ > 0) {
+ n = bitstream->cnt_;
+ } else if (!bitstream->cnt_) {
+ n = ((bitstream->buf_ & 0xff) == 0xff) ? 7 : 0;
+ } else {
+ n = 0;
+ }
+ if (n > 0) {
+ if ((u = jpc_bitstream_getbits(bitstream, n)) < 0) {
+ return -1;
+ }
+ m += n;
+ v = (v << n) | u;
+ }
+ if ((bitstream->buf_ & 0xff) == 0xff) {
+ if ((u = jpc_bitstream_getbits(bitstream, 7)) < 0) {
+ return -1;
+ }
+ v = (v << 7) | u;
+ m += 7;
+ }
+ if (m > numfill) {
+ v >>= m - numfill;
+ } else {
+ filldata >>= numfill - m;
+ fillmask >>= numfill - m;
+ }
+ if (((~(v ^ filldata)) & fillmask) != fillmask) {
+ /* The actual fill pattern does not match the expected one. */
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Align a bit stream in the output case. */
+int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata)
+{
+ int n;
+ int v;
+
+ /* Ensure that this bit stream is open for writing. */
+ assert(bitstream->openmode_ & JPC_BITSTREAM_WRITE);
+
+ /* Ensure that the first bit of fill data is zero. */
+ /* Note: The first bit of fill data must be zero. If this were not
+ the case, the fill data itself could cause further bit stuffing to
+ be required (which would cause numerous complications). */
+ assert(!(filldata & (~0x3f)));
+
+ if (!bitstream->cnt_) {
+ if ((bitstream->buf_ & 0xff) == 0xff) {
+ n = 7;
+ v = filldata;
+ } else {
+ n = 0;
+ v = 0;
+ }
+ } else if (bitstream->cnt_ > 0 && bitstream->cnt_ < 8) {
+ n = bitstream->cnt_;
+ v = filldata >> (7 - n);
+ } else {
+ n = 0;
+ v = 0;
+ return 0;
+ }
+
+ /* Write the appropriate fill data to the bit stream. */
+ if (n > 0) {
+ if (jpc_bitstream_putbits(bitstream, n, v)) {
+ return -1;
+ }
+ }
+ if (bitstream->cnt_ < 8) {
+ assert(bitstream->cnt_ >= 0 && bitstream->cnt_ < 8);
+ assert((bitstream->buf_ & 0xff) != 0xff);
+ /* Force the pending byte of output to be written to the
+ underlying (character) stream. */
+ if (jas_stream_putc(bitstream->stream_, bitstream->buf_ & 0xff) == EOF) {
+ return -1;
+ }
+ bitstream->cnt_ = 8;
+ bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;
+ }
+
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_bs.h b/osframework/source/ImageLib/jpeg2000/jpc_bs.h
new file mode 100644
index 0000000..2c9b672
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_bs.h
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Bit Stream Class
+ *
+ * $Id: jpc_bs.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_BS_H
+#define JPC_BS_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+
+#include "jas_types.h"
+#include "jas_stream.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/*
+ * Bit stream open mode flags.
+ */
+
+/* Bit stream open for reading. */
+#define JPC_BITSTREAM_READ 0x01
+/* Bit stream open for writing. */
+#define JPC_BITSTREAM_WRITE 0x02
+
+/*
+ * Bit stream flags.
+ */
+
+/* Do not close underlying character stream. */
+#define JPC_BITSTREAM_NOCLOSE 0x01
+/* End of file has been reached while reading. */
+#define JPC_BITSTREAM_EOF 0x02
+/* An I/O error has occured. */
+#define JPC_BITSTREAM_ERR 0x04
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Bit stream class. */
+
+typedef struct {
+
+ /* Some miscellaneous flags. */
+ int flags_;
+
+ /* The input/output buffer. */
+ uint_fast16_t buf_;
+
+ /* The number of bits remaining in the byte being read/written. */
+ int cnt_;
+
+ /* The underlying stream associated with this bit stream. */
+ jas_stream_t *stream_;
+
+ /* The mode in which this bit stream was opened. */
+ int openmode_;
+
+} jpc_bitstream_t;
+
+/******************************************************************************\
+* Functions/macros for opening and closing bit streams..
+\******************************************************************************/
+
+/* Open a stream as a bit stream. */
+jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, char *mode);
+
+/* Close a bit stream. */
+int jpc_bitstream_close(jpc_bitstream_t *bitstream);
+
+/******************************************************************************\
+* Functions/macros for reading from and writing to bit streams..
+\******************************************************************************/
+
+/* Read a bit from a bit stream. */
+#if defined(DEBUG)
+#define jpc_bitstream_getbit(bitstream) \
+ jpc_bitstream_getbit_func(bitstream)
+#else
+#define jpc_bitstream_getbit(bitstream) \
+ jpc_bitstream_getbit_macro(bitstream)
+#endif
+
+/* Write a bit to a bit stream. */
+#if defined(DEBUG)
+#define jpc_bitstream_putbit(bitstream, v) \
+ jpc_bitstream_putbit_func(bitstream, v)
+#else
+#define jpc_bitstream_putbit(bitstream, v) \
+ jpc_bitstream_putbit_macro(bitstream, v)
+#endif
+
+/* Read one or more bits from a bit stream. */
+long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n);
+
+/* Write one or more bits to a bit stream. */
+int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v);
+
+/******************************************************************************\
+* Functions/macros for flushing and aligning bit streams.
+\******************************************************************************/
+
+/* Align the current position within the bit stream to the next byte
+ boundary. */
+int jpc_bitstream_align(jpc_bitstream_t *bitstream);
+
+/* Align the current position in the bit stream with the next byte boundary,
+ ensuring that certain bits consumed in the process match a particular
+ pattern. */
+int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask,
+ int filldata);
+
+/* Align the current position in the bit stream with the next byte boundary,
+ writing bits from the specified pattern (if necessary) in the process. */
+int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata);
+
+/* Check if a bit stream needs alignment. */
+int jpc_bitstream_needalign(jpc_bitstream_t *bitstream);
+
+/* How many additional bytes would be output if the bit stream was aligned? */
+int jpc_bitstream_pending(jpc_bitstream_t *bitstream);
+
+/******************************************************************************\
+* Functions/macros for querying state information for bit streams.
+\******************************************************************************/
+
+/* Has EOF been encountered on a bit stream? */
+#define jpc_bitstream_eof(bitstream) \
+ ((bitstream)->flags_ & JPC_BITSTREAM_EOF)
+
+/******************************************************************************\
+* Internals.
+\******************************************************************************/
+
+/* DO NOT DIRECTLY INVOKE ANY OF THE MACROS OR FUNCTIONS BELOW. THEY ARE
+ FOR INTERNAL USE ONLY. */
+
+int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream);
+
+int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int v);
+
+int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream);
+
+#define jpc_bitstream_getbit_macro(bitstream) \
+ (assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
+ (--(bitstream)->cnt_ >= 0) ? \
+ ((int)(((bitstream)->buf_ >> (bitstream)->cnt_) & 1)) : \
+ jpc_bitstream_fillbuf(bitstream))
+
+#define jpc_bitstream_putbit_macro(bitstream, bit) \
+ (assert((bitstream)->openmode_ & JPC_BITSTREAM_WRITE), \
+ (--(bitstream)->cnt_ < 0) ? \
+ ((bitstream)->buf_ = ((bitstream)->buf_ << 8) & 0xffff, \
+ (bitstream)->cnt_ = ((bitstream)->buf_ == 0xff00) ? 6 : 7, \
+ (bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
+ (jas_stream_putc((bitstream)->stream_, (bitstream)->buf_ >> 8) == EOF) \
+ ? (EOF) : ((bit) & 1)) : \
+ ((bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
+ (bit) & 1))
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_cod.h b/osframework/source/ImageLib/jpeg2000/jpc_cod.h
new file mode 100644
index 0000000..f5d6bc0
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_cod.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_cod.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_COD_H
+#define JPC_COD_H
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* The nominal word size used by this implementation. */
+#define JPC_PREC 32
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_cs.c b/osframework/source/ImageLib/jpeg2000/jpc_cs.c
new file mode 100644
index 0000000..dcfff2d
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_cs.c
@@ -0,0 +1,1694 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JPEG-2000 Code Stream Library
+ *
+ * $Id: jpc_cs.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdlib.h>
+#include <assert.h>
+#include <ctype.h>
+
+#include "jas_malloc.h"
+#include "jas_debug.h"
+
+#include "jpc_cs.h"
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Marker segment table entry. */
+typedef struct {
+ int id;
+ char *name;
+ jpc_msops_t ops;
+} jpc_mstabent_t;
+
+/******************************************************************************\
+* Local prototypes.
+\******************************************************************************/
+
+static jpc_mstabent_t *jpc_mstab_lookup(int id);
+
+static int jpc_poc_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_poc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_poc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static void jpc_poc_destroyparms(jpc_ms_t *ms);
+
+static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_sot_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_siz_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_cod_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_coc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_qcd_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_qcc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_rgn_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_sop_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_ppm_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_ppt_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+static int jpc_com_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+
+static int jpc_sot_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_siz_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_cod_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_coc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_qcd_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_qcc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_rgn_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_unk_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_sop_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_ppm_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_ppt_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_crg_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+static int jpc_com_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+
+static int jpc_sot_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_siz_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_cod_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_coc_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_qcd_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_qcc_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_rgn_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_unk_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_sop_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_ppm_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_ppt_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_crg_dumpparms(jpc_ms_t *ms, FILE *out);
+static int jpc_com_dumpparms(jpc_ms_t *ms, FILE *out);
+
+static void jpc_siz_destroyparms(jpc_ms_t *ms);
+static void jpc_qcd_destroyparms(jpc_ms_t *ms);
+static void jpc_qcc_destroyparms(jpc_ms_t *ms);
+static void jpc_cod_destroyparms(jpc_ms_t *ms);
+static void jpc_coc_destroyparms(jpc_ms_t *ms);
+static void jpc_unk_destroyparms(jpc_ms_t *ms);
+static void jpc_ppm_destroyparms(jpc_ms_t *ms);
+static void jpc_ppt_destroyparms(jpc_ms_t *ms);
+static void jpc_crg_destroyparms(jpc_ms_t *ms);
+static void jpc_com_destroyparms(jpc_ms_t *ms);
+
+static void jpc_qcx_destroycompparms(jpc_qcxcp_t *compparms);
+static int jpc_qcx_getcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate,
+ jas_stream_t *in, uint_fast16_t len);
+static int jpc_qcx_putcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate,
+ jas_stream_t *out);
+static void jpc_cox_destroycompparms(jpc_coxcp_t *compparms);
+static int jpc_cox_getcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate,
+ jas_stream_t *in, int prtflag, jpc_coxcp_t *compparms);
+static int jpc_cox_putcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate,
+ jas_stream_t *out, int prtflag, jpc_coxcp_t *compparms);
+
+/******************************************************************************\
+* Global data.
+\******************************************************************************/
+
+static jpc_mstabent_t jpc_mstab[] = {
+ {JPC_MS_SOC, "SOC", {0, 0, 0, 0}},
+ {JPC_MS_SOT, "SOT", {0, jpc_sot_getparms, jpc_sot_putparms,
+ jpc_sot_dumpparms}},
+ {JPC_MS_SOD, "SOD", {0, 0, 0, 0}},
+ {JPC_MS_EOC, "EOC", {0, 0, 0, 0}},
+ {JPC_MS_SIZ, "SIZ", {jpc_siz_destroyparms, jpc_siz_getparms,
+ jpc_siz_putparms, jpc_siz_dumpparms}},
+ {JPC_MS_COD, "COD", {jpc_cod_destroyparms, jpc_cod_getparms,
+ jpc_cod_putparms, jpc_cod_dumpparms}},
+ {JPC_MS_COC, "COC", {jpc_coc_destroyparms, jpc_coc_getparms,
+ jpc_coc_putparms, jpc_coc_dumpparms}},
+ {JPC_MS_RGN, "RGN", {0, jpc_rgn_getparms, jpc_rgn_putparms,
+ jpc_rgn_dumpparms}},
+ {JPC_MS_QCD, "QCD", {jpc_qcd_destroyparms, jpc_qcd_getparms,
+ jpc_qcd_putparms, jpc_qcd_dumpparms}},
+ {JPC_MS_QCC, "QCC", {jpc_qcc_destroyparms, jpc_qcc_getparms,
+ jpc_qcc_putparms, jpc_qcc_dumpparms}},
+ {JPC_MS_POC, "POC", {jpc_poc_destroyparms, jpc_poc_getparms,
+ jpc_poc_putparms, jpc_poc_dumpparms}},
+ {JPC_MS_TLM, "TLM", {0, jpc_unk_getparms, jpc_unk_putparms, 0}},
+ {JPC_MS_PLM, "PLM", {0, jpc_unk_getparms, jpc_unk_putparms, 0}},
+ {JPC_MS_PPM, "PPM", {jpc_ppm_destroyparms, jpc_ppm_getparms,
+ jpc_ppm_putparms, jpc_ppm_dumpparms}},
+ {JPC_MS_PPT, "PPT", {jpc_ppt_destroyparms, jpc_ppt_getparms,
+ jpc_ppt_putparms, jpc_ppt_dumpparms}},
+ {JPC_MS_SOP, "SOP", {0, jpc_sop_getparms, jpc_sop_putparms,
+ jpc_sop_dumpparms}},
+ {JPC_MS_EPH, "EPH", {0, 0, 0, 0}},
+ {JPC_MS_CRG, "CRG", {0, jpc_crg_getparms, jpc_crg_putparms,
+ jpc_crg_dumpparms}},
+ {JPC_MS_COM, "COM", {jpc_com_destroyparms, jpc_com_getparms,
+ jpc_com_putparms, jpc_com_dumpparms}},
+ {-1, "UNKNOWN", {jpc_unk_destroyparms, jpc_unk_getparms,
+ jpc_unk_putparms, jpc_unk_dumpparms}}
+};
+
+/******************************************************************************\
+* Code stream manipulation functions.
+\******************************************************************************/
+
+/* Create a code stream state object. */
+jpc_cstate_t *jpc_cstate_create()
+{
+ jpc_cstate_t *cstate;
+ if (!(cstate = jas_malloc(sizeof(jpc_cstate_t)))) {
+ return 0;
+ }
+ cstate->numcomps = 0;
+ return cstate;
+}
+
+/* Destroy a code stream state object. */
+void jpc_cstate_destroy(jpc_cstate_t *cstate)
+{
+ jas_free(cstate);
+}
+
+/* Read a marker segment from a stream. */
+jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate)
+{
+ jpc_ms_t *ms;
+ jpc_mstabent_t *mstabent;
+ jas_stream_t *tmpstream;
+
+ if (!(ms = jpc_ms_create(0))) {
+ return 0;
+ }
+
+ /* Get the marker type. */
+ if (jpc_getuint16(in, &ms->id) || ms->id < JPC_MS_MIN ||
+ ms->id > JPC_MS_MAX) {
+ jpc_ms_destroy(ms);
+ return 0;
+ }
+
+ mstabent = jpc_mstab_lookup(ms->id);
+ ms->ops = &mstabent->ops;
+
+ /* Get the marker segment length and parameters if present. */
+ /* Note: It is tacitly assumed that a marker segment cannot have
+ parameters unless it has a length field. That is, there cannot
+ be a parameters field without a length field and vice versa. */
+ if (JPC_MS_HASPARMS(ms->id)) {
+ /* Get the length of the marker segment. */
+ if (jpc_getuint16(in, &ms->len) || ms->len < 3) {
+ jpc_ms_destroy(ms);
+ return 0;
+ }
+ /* Calculate the length of the marker segment parameters. */
+ ms->len -= 2;
+ /* Create and prepare a temporary memory stream from which to
+ read the marker segment parameters. */
+ /* Note: This approach provides a simple way of ensuring that
+ we never read beyond the end of the marker segment (even if
+ the marker segment length is errantly set too small). */
+ if (!(tmpstream = jas_stream_memopen(0, 0))) {
+ jpc_ms_destroy(ms);
+ return 0;
+ }
+ if (jas_stream_copy(tmpstream, in, ms->len) ||
+ jas_stream_seek(tmpstream, 0, SEEK_SET) < 0) {
+ jas_stream_close(tmpstream);
+ jpc_ms_destroy(ms);
+ return 0;
+ }
+ /* Get the marker segment parameters. */
+ if ((*ms->ops->getparms)(ms, cstate, tmpstream)) {
+ ms->ops = 0;
+ jpc_ms_destroy(ms);
+ jas_stream_close(tmpstream);
+ return 0;
+ }
+
+ if (jas_getdbglevel() > 0) {
+ jpc_ms_dump(ms, stderr);
+ }
+
+ if (JAS_CAST(ulong, jas_stream_tell(tmpstream)) != ms->len) {
+ fprintf(stderr,
+ "warning: trailing garbage in marker segment (%ld bytes)\n",
+ ms->len - jas_stream_tell(tmpstream));
+ }
+
+ /* Close the temporary stream. */
+ jas_stream_close(tmpstream);
+
+ } else {
+ /* There are no marker segment parameters. */
+ ms->len = 0;
+
+ if (jas_getdbglevel() > 0) {
+ jpc_ms_dump(ms, stderr);
+ }
+ }
+
+ /* Update the code stream state information based on the type of
+ marker segment read. */
+ /* Note: This is a bit of a hack, but I'm not going to define another
+ type of virtual function for this one special case. */
+ if (ms->id == JPC_MS_SIZ) {
+ cstate->numcomps = ms->parms.siz.numcomps;
+ }
+
+ return ms;
+}
+
+/* Write a marker segment to a stream. */
+int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms)
+{
+ jas_stream_t *tmpstream;
+ int len;
+
+ /* Output the marker segment type. */
+ if (jpc_putuint16(out, ms->id)) {
+ return -1;
+ }
+
+ /* Output the marker segment length and parameters if necessary. */
+ if (ms->ops->putparms) {
+ /* Create a temporary stream in which to buffer the
+ parameter data. */
+ if (!(tmpstream = jas_stream_memopen(0, 0))) {
+ return -1;
+ }
+ if ((*ms->ops->putparms)(ms, cstate, tmpstream)) {
+ jas_stream_close(tmpstream);
+ return -1;
+ }
+ /* Get the number of bytes of parameter data written. */
+ if ((len = jas_stream_tell(tmpstream)) < 0) {
+ jas_stream_close(tmpstream);
+ return -1;
+ }
+ ms->len = len;
+ /* Write the marker segment length and parameter data to
+ the output stream. */
+ if (jas_stream_seek(tmpstream, 0, SEEK_SET) < 0 ||
+ jpc_putuint16(out, ms->len + 2) ||
+ jas_stream_copy(out, tmpstream, ms->len) < 0) {
+ jas_stream_close(tmpstream);
+ return -1;
+ }
+ /* Close the temporary stream. */
+ jas_stream_close(tmpstream);
+ }
+
+ /* This is a bit of a hack, but I'm not going to define another
+ type of virtual function for this one special case. */
+ if (ms->id == JPC_MS_SIZ) {
+ cstate->numcomps = ms->parms.siz.numcomps;
+ }
+
+ if (jas_getdbglevel() > 0) {
+ jpc_ms_dump(ms, stderr);
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* Marker segment operations.
+\******************************************************************************/
+
+/* Create a marker segment of the specified type. */
+jpc_ms_t *jpc_ms_create(int type)
+{
+ jpc_ms_t *ms;
+ jpc_mstabent_t *mstabent;
+
+ if (!(ms = jas_malloc(sizeof(jpc_ms_t)))) {
+ return 0;
+ }
+ ms->id = type;
+ ms->len = 0;
+ mstabent = jpc_mstab_lookup(ms->id);
+ ms->ops = &mstabent->ops;
+ memset(&ms->parms, 0, sizeof(jpc_msparms_t));
+ return ms;
+}
+
+/* Destroy a marker segment. */
+void jpc_ms_destroy(jpc_ms_t *ms)
+{
+ if (ms->ops && ms->ops->destroyparms) {
+ (*ms->ops->destroyparms)(ms);
+ }
+ jas_free(ms);
+}
+
+/* Dump a marker segment to a stream for debugging. */
+void jpc_ms_dump(jpc_ms_t *ms, FILE *out)
+{
+ jpc_mstabent_t *mstabent;
+ mstabent = jpc_mstab_lookup(ms->id);
+ fprintf(out, "type = 0x%04x (%s);", ms->id, mstabent->name);
+ if (JPC_MS_HASPARMS(ms->id)) {
+ fprintf(out, " len = %d;", ms->len + 2);
+ if (ms->ops->dumpparms) {
+ (*ms->ops->dumpparms)(ms, out);
+ } else {
+ fprintf(out, "\n");
+ }
+ } else {
+ fprintf(out, "\n");
+ }
+}
+
+/******************************************************************************\
+* SOT marker segment operations.
+\******************************************************************************/
+
+static int jpc_sot_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_sot_t *sot = &ms->parms.sot;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (jpc_getuint16(in, &sot->tileno) ||
+ jpc_getuint32(in, &sot->len) ||
+ jpc_getuint8(in, &sot->partno) ||
+ jpc_getuint8(in, &sot->numparts)) {
+ return -1;
+ }
+ if (jas_stream_eof(in)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_sot_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_sot_t *sot = &ms->parms.sot;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (jpc_putuint16(out, sot->tileno) ||
+ jpc_putuint32(out, sot->len) ||
+ jpc_putuint8(out, sot->partno) ||
+ jpc_putuint8(out, sot->numparts)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_sot_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_sot_t *sot = &ms->parms.sot;
+ fprintf(out, "tileno = %d; len = %d; partno = %d; numparts = %d\n",
+ sot->tileno, sot->len, sot->partno, sot->numparts);
+ return 0;
+}
+
+/******************************************************************************\
+* SIZ marker segment operations.
+\******************************************************************************/
+
+static void jpc_siz_destroyparms(jpc_ms_t *ms)
+{
+ jpc_siz_t *siz = &ms->parms.siz;
+ if (siz->comps) {
+ jas_free(siz->comps);
+ }
+}
+
+static int jpc_siz_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate,
+ jas_stream_t *in)
+{
+ jpc_siz_t *siz = &ms->parms.siz;
+ unsigned int i;
+ uint_fast8_t tmp;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (jpc_getuint16(in, &siz->caps) ||
+ jpc_getuint32(in, &siz->width) ||
+ jpc_getuint32(in, &siz->height) ||
+ jpc_getuint32(in, &siz->xoff) ||
+ jpc_getuint32(in, &siz->yoff) ||
+ jpc_getuint32(in, &siz->tilewidth) ||
+ jpc_getuint32(in, &siz->tileheight) ||
+ jpc_getuint32(in, &siz->tilexoff) ||
+ jpc_getuint32(in, &siz->tileyoff) ||
+ jpc_getuint16(in, &siz->numcomps)) {
+ return -1;
+ }
+ if (!siz->width || !siz->height || !siz->tilewidth ||
+ !siz->tileheight || !siz->numcomps) {
+ return -1;
+ }
+ if (!(siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)))) {
+ return -1;
+ }
+ for (i = 0; i < siz->numcomps; ++i) {
+ if (jpc_getuint8(in, &tmp) ||
+ jpc_getuint8(in, &siz->comps[i].hsamp) ||
+ jpc_getuint8(in, &siz->comps[i].vsamp)) {
+ jas_free(siz->comps);
+ return -1;
+ }
+ siz->comps[i].sgnd = (tmp >> 7) & 1;
+ siz->comps[i].prec = (tmp & 0x7f) + 1;
+ }
+ if (jas_stream_eof(in)) {
+ jas_free(siz->comps);
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_siz_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_siz_t *siz = &ms->parms.siz;
+ unsigned int i;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ assert(siz->width && siz->height && siz->tilewidth &&
+ siz->tileheight && siz->numcomps);
+ if (jpc_putuint16(out, siz->caps) ||
+ jpc_putuint32(out, siz->width) ||
+ jpc_putuint32(out, siz->height) ||
+ jpc_putuint32(out, siz->xoff) ||
+ jpc_putuint32(out, siz->yoff) ||
+ jpc_putuint32(out, siz->tilewidth) ||
+ jpc_putuint32(out, siz->tileheight) ||
+ jpc_putuint32(out, siz->tilexoff) ||
+ jpc_putuint32(out, siz->tileyoff) ||
+ jpc_putuint16(out, siz->numcomps)) {
+ return -1;
+ }
+ for (i = 0; i < siz->numcomps; ++i) {
+ if (jpc_putuint8(out, ((siz->comps[i].sgnd & 1) << 7) |
+ ((siz->comps[i].prec - 1) & 0x7f)) ||
+ jpc_putuint8(out, siz->comps[i].hsamp) ||
+ jpc_putuint8(out, siz->comps[i].vsamp)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jpc_siz_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_siz_t *siz = &ms->parms.siz;
+ unsigned int i;
+ fprintf(out, "caps = 0x%02x;\n", siz->caps);
+ fprintf(out, "width = %d; height = %d; xoff = %d; yoff = %d;\n",
+ siz->width, siz->height, siz->xoff, siz->yoff);
+ fprintf(out, "tilewidth = %d; tileheight = %d; tilexoff = %d; "
+ "tileyoff = %d;\n", siz->tilewidth, siz->tileheight, siz->tilexoff,
+ siz->tileyoff);
+ for (i = 0; i < siz->numcomps; ++i) {
+ fprintf(out, "prec[%d] = %d; sgnd[%d] = %d; hsamp[%d] = %d; "
+ "vsamp[%d] = %d\n", i, siz->comps[i].prec, i,
+ siz->comps[i].sgnd, i, siz->comps[i].hsamp, i,
+ siz->comps[i].vsamp);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* COD marker segment operations.
+\******************************************************************************/
+
+static void jpc_cod_destroyparms(jpc_ms_t *ms)
+{
+ jpc_cod_t *cod = &ms->parms.cod;
+ jpc_cox_destroycompparms(&cod->compparms);
+}
+
+static int jpc_cod_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_cod_t *cod = &ms->parms.cod;
+ if (jpc_getuint8(in, &cod->csty)) {
+ return -1;
+ }
+ if (jpc_getuint8(in, &cod->prg) ||
+ jpc_getuint16(in, &cod->numlyrs) ||
+ jpc_getuint8(in, &cod->mctrans)) {
+ return -1;
+ }
+ if (jpc_cox_getcompparms(ms, cstate, in,
+ (cod->csty & JPC_COX_PRT) != 0, &cod->compparms)) {
+ return -1;
+ }
+ if (jas_stream_eof(in)) {
+ jpc_cod_destroyparms(ms);
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_cod_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_cod_t *cod = &ms->parms.cod;
+ assert(cod->numlyrs > 0 && cod->compparms.numdlvls <= 32);
+ assert(cod->compparms.numdlvls == cod->compparms.numrlvls - 1);
+ if (jpc_putuint8(out, cod->compparms.csty) ||
+ jpc_putuint8(out, cod->prg) ||
+ jpc_putuint16(out, cod->numlyrs) ||
+ jpc_putuint8(out, cod->mctrans)) {
+ return -1;
+ }
+ if (jpc_cox_putcompparms(ms, cstate, out,
+ (cod->csty & JPC_COX_PRT) != 0, &cod->compparms)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_cod_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_cod_t *cod = &ms->parms.cod;
+ int i;
+ fprintf(out, "csty = 0x%02x;\n", cod->compparms.csty);
+ fprintf(out, "numdlvls = %d; qmfbid = %d; mctrans = %d\n",
+ cod->compparms.numdlvls, cod->compparms.qmfbid, cod->mctrans);
+ fprintf(out, "prg = %d; numlyrs = %d;\n",
+ cod->prg, cod->numlyrs);
+ fprintf(out, "cblkwidthval = %d; cblkheightval = %d; "
+ "cblksty = 0x%02x;\n", cod->compparms.cblkwidthval, cod->compparms.cblkheightval,
+ cod->compparms.cblksty);
+ if (cod->csty & JPC_COX_PRT) {
+ for (i = 0; i < cod->compparms.numrlvls; ++i) {
+ fprintf(stderr, "prcwidth[%d] = %d, prcheight[%d] = %d\n",
+ i, cod->compparms.rlvls[i].parwidthval,
+ i, cod->compparms.rlvls[i].parheightval);
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* COC marker segment operations.
+\******************************************************************************/
+
+static void jpc_coc_destroyparms(jpc_ms_t *ms)
+{
+ jpc_coc_t *coc = &ms->parms.coc;
+ jpc_cox_destroycompparms(&coc->compparms);
+}
+
+static int jpc_coc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_coc_t *coc = &ms->parms.coc;
+ uint_fast8_t tmp;
+ if (cstate->numcomps <= 256) {
+ if (jpc_getuint8(in, &tmp)) {
+ return -1;
+ }
+ coc->compno = tmp;
+ } else {
+ if (jpc_getuint16(in, &coc->compno)) {
+ return -1;
+ }
+ }
+ if (jpc_getuint8(in, &coc->compparms.csty)) {
+ return -1;
+ }
+ if (jpc_cox_getcompparms(ms, cstate, in,
+ (coc->compparms.csty & JPC_COX_PRT) != 0, &coc->compparms)) {
+ return -1;
+ }
+ if (jas_stream_eof(in)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_coc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_coc_t *coc = &ms->parms.coc;
+ assert(coc->compparms.numdlvls <= 32);
+ if (cstate->numcomps <= 256) {
+ if (jpc_putuint8(out, coc->compno)) {
+ return -1;
+ }
+ } else {
+ if (jpc_putuint16(out, coc->compno)) {
+ return -1;
+ }
+ }
+ if (jpc_putuint8(out, coc->compparms.csty)) {
+ return -1;
+ }
+ if (jpc_cox_putcompparms(ms, cstate, out,
+ (coc->compparms.csty & JPC_COX_PRT) != 0, &coc->compparms)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_coc_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_coc_t *coc = &ms->parms.coc;
+ fprintf(out, "compno = %d; csty = 0x%02x; numdlvls = %d;\n",
+ coc->compno, coc->compparms.csty, coc->compparms.numdlvls);
+ fprintf(out, "cblkwidthval = %d; cblkheightval = %d; "
+ "cblksty = 0x%02x; qmfbid = %d;\n", coc->compparms.cblkwidthval,
+ coc->compparms.cblkheightval, coc->compparms.cblksty, coc->compparms.qmfbid);
+ return 0;
+}
+/******************************************************************************\
+* COD/COC marker segment operation helper functions.
+\******************************************************************************/
+
+static void jpc_cox_destroycompparms(jpc_coxcp_t *compparms)
+{
+ /* Eliminate compiler warning about unused variables. */
+ compparms = 0;
+}
+
+static int jpc_cox_getcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate,
+ jas_stream_t *in, int prtflag, jpc_coxcp_t *compparms)
+{
+ uint_fast8_t tmp;
+ int i;
+
+ /* Eliminate compiler warning about unused variables. */
+ ms = 0;
+ cstate = 0;
+
+ if (jpc_getuint8(in, &compparms->numdlvls) ||
+ jpc_getuint8(in, &compparms->cblkwidthval) ||
+ jpc_getuint8(in, &compparms->cblkheightval) ||
+ jpc_getuint8(in, &compparms->cblksty) ||
+ jpc_getuint8(in, &compparms->qmfbid)) {
+ return -1;
+ }
+ compparms->numrlvls = compparms->numdlvls + 1;
+ if (prtflag) {
+ for (i = 0; i < compparms->numrlvls; ++i) {
+ if (jpc_getuint8(in, &tmp)) {
+ jpc_cox_destroycompparms(compparms);
+ return -1;
+ }
+ compparms->rlvls[i].parwidthval = tmp & 0xf;
+ compparms->rlvls[i].parheightval = (tmp >> 4) & 0xf;
+ }
+/* Sigh. This bit should be in the same field in both COC and COD mrk segs. */
+compparms->csty |= JPC_COX_PRT;
+ } else {
+ }
+ if (jas_stream_eof(in)) {
+ jpc_cox_destroycompparms(compparms);
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_cox_putcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate,
+ jas_stream_t *out, int prtflag, jpc_coxcp_t *compparms)
+{
+ int i;
+ assert(compparms->numdlvls <= 32);
+
+ /* Eliminate compiler warning about unused variables. */
+ ms = 0;
+ cstate = 0;
+
+ if (jpc_putuint8(out, compparms->numdlvls) ||
+ jpc_putuint8(out, compparms->cblkwidthval) ||
+ jpc_putuint8(out, compparms->cblkheightval) ||
+ jpc_putuint8(out, compparms->cblksty) ||
+ jpc_putuint8(out, compparms->qmfbid)) {
+ return -1;
+ }
+ if (prtflag) {
+ for (i = 0; i < compparms->numrlvls; ++i) {
+ if (jpc_putuint8(out,
+ ((compparms->rlvls[i].parheightval & 0xf) << 4) |
+ (compparms->rlvls[i].parwidthval & 0xf))) {
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* RGN marker segment operations.
+\******************************************************************************/
+
+static int jpc_rgn_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_rgn_t *rgn = &ms->parms.rgn;
+ uint_fast8_t tmp;
+ if (cstate->numcomps <= 256) {
+ if (jpc_getuint8(in, &tmp)) {
+ return -1;
+ }
+ rgn->compno = tmp;
+ } else {
+ if (jpc_getuint16(in, &rgn->compno)) {
+ return -1;
+ }
+ }
+ if (jpc_getuint8(in, &rgn->roisty) ||
+ jpc_getuint8(in, &rgn->roishift)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_rgn_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_rgn_t *rgn = &ms->parms.rgn;
+ if (cstate->numcomps <= 256) {
+ if (jpc_putuint8(out, rgn->compno)) {
+ return -1;
+ }
+ } else {
+ if (jpc_putuint16(out, rgn->compno)) {
+ return -1;
+ }
+ }
+ if (jpc_putuint8(out, rgn->roisty) ||
+ jpc_putuint8(out, rgn->roishift)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_rgn_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_rgn_t *rgn = &ms->parms.rgn;
+ fprintf(out, "compno = %d; roisty = %d; roishift = %d\n",
+ rgn->compno, rgn->roisty, rgn->roishift);
+ return 0;
+}
+
+/******************************************************************************\
+* QCD marker segment operations.
+\******************************************************************************/
+
+static void jpc_qcd_destroyparms(jpc_ms_t *ms)
+{
+ jpc_qcd_t *qcd = &ms->parms.qcd;
+ jpc_qcx_destroycompparms(&qcd->compparms);
+}
+
+static int jpc_qcd_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_qcxcp_t *compparms = &ms->parms.qcd.compparms;
+ return jpc_qcx_getcompparms(compparms, cstate, in, ms->len);
+}
+
+static int jpc_qcd_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_qcxcp_t *compparms = &ms->parms.qcd.compparms;
+ return jpc_qcx_putcompparms(compparms, cstate, out);
+}
+
+static int jpc_qcd_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_qcd_t *qcd = &ms->parms.qcd;
+ int i;
+ fprintf(out, "qntsty = %d; numguard = %d; numstepsizes = %d\n",
+ (int) qcd->compparms.qntsty, qcd->compparms.numguard, qcd->compparms.numstepsizes);
+ for (i = 0; i < qcd->compparms.numstepsizes; ++i) {
+ fprintf(out, "expn[%d] = 0x%04x; mant[%d] = 0x%04x;\n",
+ i, (unsigned) JPC_QCX_GETEXPN(qcd->compparms.stepsizes[i]),
+ i, (unsigned) JPC_QCX_GETMANT(qcd->compparms.stepsizes[i]));
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* QCC marker segment operations.
+\******************************************************************************/
+
+static void jpc_qcc_destroyparms(jpc_ms_t *ms)
+{
+ jpc_qcc_t *qcc = &ms->parms.qcc;
+ jpc_qcx_destroycompparms(&qcc->compparms);
+}
+
+static int jpc_qcc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_qcc_t *qcc = &ms->parms.qcc;
+ uint_fast8_t tmp;
+ int len;
+ len = ms->len;
+ if (cstate->numcomps <= 256) {
+ jpc_getuint8(in, &tmp);
+ qcc->compno = tmp;
+ --len;
+ } else {
+ jpc_getuint16(in, &qcc->compno);
+ len -= 2;
+ }
+ if (jpc_qcx_getcompparms(&qcc->compparms, cstate, in, len)) {
+ return -1;
+ }
+ if (jas_stream_eof(in)) {
+ jpc_qcc_destroyparms(ms);
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_qcc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_qcc_t *qcc = &ms->parms.qcc;
+ if (cstate->numcomps <= 256) {
+ jpc_putuint8(out, qcc->compno);
+ } else {
+ jpc_putuint16(out, qcc->compno);
+ }
+ if (jpc_qcx_putcompparms(&qcc->compparms, cstate, out)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_qcc_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_qcc_t *qcc = &ms->parms.qcc;
+ int i;
+ fprintf(out, "compno = %d; qntsty = %d; numguard = %d; "
+ "numstepsizes = %d\n", qcc->compno, qcc->compparms.qntsty, qcc->compparms.numguard,
+ qcc->compparms.numstepsizes);
+ for (i = 0; i < qcc->compparms.numstepsizes; ++i) {
+ fprintf(out, "expn[%d] = 0x%04x; mant[%d] = 0x%04x;\n",
+ i, (unsigned) JPC_QCX_GETEXPN(qcc->compparms.stepsizes[i]),
+ i, (unsigned) JPC_QCX_GETMANT(qcc->compparms.stepsizes[i]));
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* QCD/QCC marker segment helper functions.
+\******************************************************************************/
+
+static void jpc_qcx_destroycompparms(jpc_qcxcp_t *compparms)
+{
+ if (compparms->stepsizes) {
+ jas_free(compparms->stepsizes);
+ }
+}
+
+static int jpc_qcx_getcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate,
+ jas_stream_t *in, uint_fast16_t len)
+{
+ uint_fast8_t tmp;
+ int n;
+ int i;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ n = 0;
+ jpc_getuint8(in, &tmp);
+ ++n;
+ compparms->qntsty = tmp & 0x1f;
+ compparms->numguard = (tmp >> 5) & 7;
+ switch (compparms->qntsty) {
+ case JPC_QCX_SIQNT:
+ compparms->numstepsizes = 1;
+ break;
+ case JPC_QCX_NOQNT:
+ compparms->numstepsizes = (len - n);
+ break;
+ case JPC_QCX_SEQNT:
+ /* XXX - this is a hack */
+ compparms->numstepsizes = (len - n) / 2;
+ break;
+ }
+if (compparms->numstepsizes > 0) {
+ compparms->stepsizes = jas_malloc(compparms->numstepsizes *
+ sizeof(uint_fast32_t));
+ assert(compparms->stepsizes);
+ for (i = 0; i < compparms->numstepsizes; ++i) {
+ if (compparms->qntsty == JPC_QCX_NOQNT) {
+ jpc_getuint8(in, &tmp);
+ compparms->stepsizes[i] = JPC_QCX_EXPN(tmp >> 3);
+ } else {
+ jpc_getuint16(in, &compparms->stepsizes[i]);
+ }
+ }
+} else {
+ compparms->stepsizes = 0;
+}
+ if (jas_stream_error(in) || jas_stream_eof(in)) {
+ jpc_qcx_destroycompparms(compparms);
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_qcx_putcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate,
+ jas_stream_t *out)
+{
+ int i;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ jpc_putuint8(out, ((compparms->numguard & 7) << 5) | compparms->qntsty);
+ for (i = 0; i < compparms->numstepsizes; ++i) {
+ if (compparms->qntsty == JPC_QCX_NOQNT) {
+ jpc_putuint8(out, JPC_QCX_GETEXPN(
+ compparms->stepsizes[i]) << 3);
+ } else {
+ jpc_putuint16(out, compparms->stepsizes[i]);
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* SOP marker segment operations.
+\******************************************************************************/
+
+static int jpc_sop_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_sop_t *sop = &ms->parms.sop;
+
+ /* Eliminate compiler warning about unused variable. */
+ cstate = 0;
+
+ if (jpc_getuint16(in, &sop->seqno)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_sop_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_sop_t *sop = &ms->parms.sop;
+
+ /* Eliminate compiler warning about unused variable. */
+ cstate = 0;
+
+ if (jpc_putuint16(out, sop->seqno)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_sop_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_sop_t *sop = &ms->parms.sop;
+ fprintf(out, "seqno = %d;\n", sop->seqno);
+ return 0;
+}
+
+/******************************************************************************\
+* PPM marker segment operations.
+\******************************************************************************/
+
+static void jpc_ppm_destroyparms(jpc_ms_t *ms)
+{
+ jpc_ppm_t *ppm = &ms->parms.ppm;
+ if (ppm->data) {
+ jas_free(ppm->data);
+ }
+}
+
+static int jpc_ppm_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_ppm_t *ppm = &ms->parms.ppm;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ ppm->data = 0;
+
+ if (ms->len < 1) {
+ goto error;
+ }
+ if (jpc_getuint8(in, &ppm->ind)) {
+ goto error;
+ }
+
+ ppm->len = ms->len - 1;
+ if (ppm->len > 0) {
+ if (!(ppm->data = jas_malloc(ppm->len * sizeof(unsigned char)))) {
+ goto error;
+ }
+ if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) {
+ goto error;
+ }
+ } else {
+ ppm->data = 0;
+ }
+ return 0;
+
+error:
+ jpc_ppm_destroyparms(ms);
+ return -1;
+}
+
+static int jpc_ppm_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_ppm_t *ppm = &ms->parms.ppm;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (JAS_CAST(uint, jas_stream_write(out, (char *) ppm->data, ppm->len)) != ppm->len) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_ppm_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_ppm_t *ppm = &ms->parms.ppm;
+ fprintf(out, "ind=%d; len = %d;\n", ppm->ind, ppm->len);
+ if (ppm->len > 0) {
+ fprintf(out, "data =\n");
+ jas_memdump(out, ppm->data, ppm->len);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* PPT marker segment operations.
+\******************************************************************************/
+
+static void jpc_ppt_destroyparms(jpc_ms_t *ms)
+{
+ jpc_ppt_t *ppt = &ms->parms.ppt;
+ if (ppt->data) {
+ jas_free(ppt->data);
+ }
+}
+
+static int jpc_ppt_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_ppt_t *ppt = &ms->parms.ppt;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ ppt->data = 0;
+
+ if (ms->len < 1) {
+ goto error;
+ }
+ if (jpc_getuint8(in, &ppt->ind)) {
+ goto error;
+ }
+ ppt->len = ms->len - 1;
+ if (ppt->len > 0) {
+ if (!(ppt->data = jas_malloc(ppt->len * sizeof(unsigned char)))) {
+ goto error;
+ }
+ if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) {
+ goto error;
+ }
+ } else {
+ ppt->data = 0;
+ }
+ return 0;
+
+error:
+ jpc_ppt_destroyparms(ms);
+ return -1;
+}
+
+static int jpc_ppt_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_ppt_t *ppt = &ms->parms.ppt;
+
+ /* Eliminate compiler warning about unused variable. */
+ cstate = 0;
+
+ if (jpc_putuint8(out, ppt->ind)) {
+ return -1;
+ }
+ if (jas_stream_write(out, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_ppt_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_ppt_t *ppt = &ms->parms.ppt;
+ fprintf(out, "ind=%d; len = %d;\n", ppt->ind, ppt->len);
+ if (ppt->len > 0) {
+ fprintf(out, "data =\n");
+ jas_memdump(out, ppt->data, ppt->len);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* POC marker segment operations.
+\******************************************************************************/
+
+static void jpc_poc_destroyparms(jpc_ms_t *ms)
+{
+ jpc_poc_t *poc = &ms->parms.poc;
+ if (poc->pchgs) {
+ jas_free(poc->pchgs);
+ }
+}
+
+static int jpc_poc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_poc_t *poc = &ms->parms.poc;
+ jpc_pocpchg_t *pchg;
+ int pchgno;
+ uint_fast8_t tmp;
+ poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) :
+ (ms->len / 7);
+ if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) {
+ goto error;
+ }
+ for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno,
+ ++pchg) {
+ if (jpc_getuint8(in, &pchg->rlvlnostart)) {
+ goto error;
+ }
+ if (cstate->numcomps > 256) {
+ if (jpc_getuint16(in, &pchg->compnostart)) {
+ goto error;
+ }
+ } else {
+ if (jpc_getuint8(in, &tmp)) {
+ goto error;
+ };
+ pchg->compnostart = tmp;
+ }
+ if (jpc_getuint16(in, &pchg->lyrnoend) ||
+ jpc_getuint8(in, &pchg->rlvlnoend)) {
+ goto error;
+ }
+ if (cstate->numcomps > 256) {
+ if (jpc_getuint16(in, &pchg->compnoend)) {
+ goto error;
+ }
+ } else {
+ if (jpc_getuint8(in, &tmp)) {
+ goto error;
+ }
+ pchg->compnoend = tmp;
+ }
+ if (jpc_getuint8(in, &pchg->prgord)) {
+ goto error;
+ }
+ if (pchg->rlvlnostart > pchg->rlvlnoend ||
+ pchg->compnostart > pchg->compnoend) {
+ goto error;
+ }
+ }
+ return 0;
+
+error:
+ jpc_poc_destroyparms(ms);
+ return -1;
+}
+
+static int jpc_poc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_poc_t *poc = &ms->parms.poc;
+ jpc_pocpchg_t *pchg;
+ int pchgno;
+ for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno,
+ ++pchg) {
+ if (jpc_putuint8(out, pchg->rlvlnostart) ||
+ ((cstate->numcomps > 256) ?
+ jpc_putuint16(out, pchg->compnostart) :
+ jpc_putuint8(out, pchg->compnostart)) ||
+ jpc_putuint16(out, pchg->lyrnoend) ||
+ jpc_putuint8(out, pchg->rlvlnoend) ||
+ ((cstate->numcomps > 256) ?
+ jpc_putuint16(out, pchg->compnoend) :
+ jpc_putuint8(out, pchg->compnoend)) ||
+ jpc_putuint8(out, pchg->prgord)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jpc_poc_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_poc_t *poc = &ms->parms.poc;
+ jpc_pocpchg_t *pchg;
+ int pchgno;
+ for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs;
+ ++pchgno, ++pchg) {
+ fprintf(out, "po[%d] = %d; ", pchgno, pchg->prgord);
+ fprintf(out, "cs[%d] = %d; ce[%d] = %d; ",
+ pchgno, pchg->compnostart, pchgno, pchg->compnoend);
+ fprintf(out, "rs[%d] = %d; re[%d] = %d; ",
+ pchgno, pchg->rlvlnostart, pchgno, pchg->rlvlnoend);
+ fprintf(out, "le[%d] = %d\n", pchgno, pchg->lyrnoend);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* CRG marker segment operations.
+\******************************************************************************/
+
+static void jpc_crg_destroyparms(jpc_ms_t *ms)
+{
+ jpc_crg_t *crg = &ms->parms.crg;
+ if (crg->comps) {
+ jas_free(crg->comps);
+ }
+}
+
+static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_crg_t *crg = &ms->parms.crg;
+ jpc_crgcomp_t *comp;
+ uint_fast16_t compno;
+ crg->numcomps = cstate->numcomps;
+ if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) {
+ return -1;
+ }
+ for (compno = 0, comp = crg->comps; compno < cstate->numcomps;
+ ++compno, ++comp) {
+ if (jpc_getuint16(in, &comp->hoff) ||
+ jpc_getuint16(in, &comp->voff)) {
+ jpc_crg_destroyparms(ms);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jpc_crg_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_crg_t *crg = &ms->parms.crg;
+ int compno;
+ jpc_crgcomp_t *comp;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno,
+ ++comp) {
+ if (jpc_putuint16(out, comp->hoff) ||
+ jpc_putuint16(out, comp->voff)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jpc_crg_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_crg_t *crg = &ms->parms.crg;
+ int compno;
+ jpc_crgcomp_t *comp;
+ for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno,
+ ++comp) {
+ fprintf(out, "hoff[%d] = %d; voff[%d] = %d\n", compno,
+ comp->hoff, compno, comp->voff);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Operations for COM marker segment.
+\******************************************************************************/
+
+static void jpc_com_destroyparms(jpc_ms_t *ms)
+{
+ jpc_com_t *com = &ms->parms.com;
+ if (com->data) {
+ jas_free(com->data);
+ }
+}
+
+static int jpc_com_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_com_t *com = &ms->parms.com;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (jpc_getuint16(in, &com->regid)) {
+ return -1;
+ }
+ com->len = ms->len - 2;
+ if (com->len > 0) {
+ if (!(com->data = jas_malloc(com->len))) {
+ return -1;
+ }
+ if (jas_stream_read(in, com->data, com->len) != JAS_CAST(int, com->len)) {
+ return -1;
+ }
+ } else {
+ com->data = 0;
+ }
+ return 0;
+}
+
+static int jpc_com_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ jpc_com_t *com = &ms->parms.com;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (jpc_putuint16(out, com->regid)) {
+ return -1;
+ }
+ if (jas_stream_write(out, com->data, com->len) != JAS_CAST(int, com->len)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_com_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ jpc_com_t *com = &ms->parms.com;
+ unsigned int i;
+ int printable;
+ fprintf(out, "regid = %d;\n", com->regid);
+ printable = 1;
+ for (i = 0; i < com->len; ++i) {
+ if (!isprint(com->data[i])) {
+ printable = 0;
+ break;
+ }
+ }
+ if (printable) {
+ fprintf(out, "data = ");
+ fwrite(com->data, sizeof(char), com->len, out);
+ fprintf(out, "\n");
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Operations for unknown types of marker segments.
+\******************************************************************************/
+
+static void jpc_unk_destroyparms(jpc_ms_t *ms)
+{
+ jpc_unk_t *unk = &ms->parms.unk;
+ if (unk->data) {
+ jas_free(unk->data);
+ }
+}
+
+static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in)
+{
+ jpc_unk_t *unk = &ms->parms.unk;
+
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+
+ if (ms->len > 0) {
+ if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) {
+ return -1;
+ }
+ if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) {
+ jas_free(unk->data);
+ return -1;
+ }
+ unk->len = ms->len;
+ } else {
+ unk->data = 0;
+ unk->len = 0;
+ }
+ return 0;
+}
+
+static int jpc_unk_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out)
+{
+ /* Eliminate compiler warning about unused variables. */
+ cstate = 0;
+ ms = 0;
+ out = 0;
+
+ /* If this function is called, we are trying to write an unsupported
+ type of marker segment. Return with an error indication. */
+ return -1;
+}
+
+static int jpc_unk_dumpparms(jpc_ms_t *ms, FILE *out)
+{
+ unsigned int i;
+ jpc_unk_t *unk = &ms->parms.unk;
+ for (i = 0; i < unk->len; ++i) {
+ fprintf(out, "%02x ", unk->data[i]);
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Primitive I/O operations.
+\******************************************************************************/
+
+int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val)
+{
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ if (val) {
+ *val = c;
+ }
+ return 0;
+}
+
+int jpc_putuint8(jas_stream_t *out, uint_fast8_t val)
+{
+ if (jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val)
+{
+ uint_fast16_t v;
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if (val) {
+ *val = v;
+ }
+ return 0;
+}
+
+int jpc_putuint16(jas_stream_t *out, uint_fast16_t val)
+{
+ if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
+ jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val)
+{
+ uint_fast32_t v;
+ int c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if ((c = jas_stream_getc(in)) == EOF) {
+ return -1;
+ }
+ v = (v << 8) | c;
+ if (val) {
+ *val = v;
+ }
+ return 0;
+}
+
+int jpc_putuint32(jas_stream_t *out, uint_fast32_t val)
+{
+ if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF ||
+ jas_stream_putc(out, (val >> 16) & 0xff) == EOF ||
+ jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
+ jas_stream_putc(out, val & 0xff) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Miscellany
+\******************************************************************************/
+
+static jpc_mstabent_t *jpc_mstab_lookup(int id)
+{
+ jpc_mstabent_t *mstabent;
+ for (mstabent = jpc_mstab;; ++mstabent) {
+ if (mstabent->id == id || mstabent->id < 0) {
+ return mstabent;
+ }
+ }
+ assert(0);
+ return 0;
+}
+
+int jpc_validate(jas_stream_t *in)
+{
+ int n;
+ int i;
+ unsigned char buf[2];
+
+ assert(JAS_STREAM_MAXPUTBACK >= 2);
+
+ if ((n = jas_stream_read(in, (char *) buf, 2)) < 0) {
+ return -1;
+ }
+ for (i = n - 1; i >= 0; --i) {
+ if (jas_stream_ungetc(in, buf[i]) == EOF) {
+ return -1;
+ }
+ }
+ if (n < 2) {
+ return -1;
+ }
+ if (buf[0] == (JPC_MS_SOC >> 8) && buf[1] == (JPC_MS_SOC & 0xff)) {
+ return 0;
+ }
+ return -1;
+}
+
+int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long len)
+{
+ return jas_stream_copy(out, in, len);
+}
+
+int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long len)
+{
+ return jas_stream_copy(out, in, len);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_cs.h b/osframework/source/ImageLib/jpeg2000/jpc_cs.h
new file mode 100644
index 0000000..81bfcb7
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_cs.h
@@ -0,0 +1,812 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JPEG-2000 Code Stream Library
+ *
+ * $Id: jpc_cs.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_CS_H
+#define JPC_CS_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_image.h"
+#include "jas_stream.h"
+
+#include "jpc_cod.h"
+
+/******************************************************************************\
+* Constants and Types.
+\******************************************************************************/
+
+/* The maximum number of resolution levels. */
+#define JPC_MAXRLVLS 33
+
+/* The maximum number of bands. */
+#define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1)
+
+/* The maximum number of layers. */
+#define JPC_MAXLYRS 16384
+
+/**************************************\
+* Code stream.
+\**************************************/
+
+/*
+ * Code stream states.
+ */
+
+/* Initial. */
+#define JPC_CS_INIT 0
+/* Main header. */
+#define JPC_CS_MHDR 1
+/* Tile-part header. */
+#define JPC_CS_THDR 2
+/* Main trailer. */
+#define JPC_CS_MTLR 3
+/* Tile-part data. */
+#define JPC_CS_TDATA 4
+
+/*
+ * Unfortunately, the code stream syntax was not designed in such a way that
+ * any given marker segment can be correctly decoded without additional state
+ * derived from previously decoded marker segments.
+ * For example, a RGN/COC/QCC marker segment cannot be decoded unless the
+ * number of components is known.
+ */
+
+/*
+ * Code stream state information.
+ */
+
+typedef struct {
+
+ /* The number of components. */
+ uint_fast16_t numcomps;
+
+} jpc_cstate_t;
+
+/**************************************\
+* SOT marker segment parameters.
+\**************************************/
+
+typedef struct {
+
+ /* The tile number. */
+ uint_fast16_t tileno;
+
+ /* The combined length of the marker segment and its auxilary data
+ (i.e., packet data). */
+ uint_fast32_t len;
+
+ /* The tile-part instance. */
+ uint_fast8_t partno;
+
+ /* The number of tile-parts. */
+ uint_fast8_t numparts;
+
+} jpc_sot_t;
+
+/**************************************\
+* SIZ marker segment parameters.
+\**************************************/
+
+/* Per component information. */
+
+typedef struct {
+
+ /* The precision of the samples. */
+ uint_fast8_t prec;
+
+ /* The signedness of the samples. */
+ uint_fast8_t sgnd;
+
+ /* The horizontal separation of samples with respect to the reference
+ grid. */
+ uint_fast8_t hsamp;
+
+ /* The vertical separation of samples with respect to the reference
+ grid. */
+ uint_fast8_t vsamp;
+
+} jpc_sizcomp_t;
+
+/* SIZ marker segment parameters. */
+
+typedef struct {
+
+ /* The code stream capabilities. */
+ uint_fast16_t caps;
+
+ /* The width of the image in units of the reference grid. */
+ uint_fast32_t width;
+
+ /* The height of the image in units of the reference grid. */
+ uint_fast32_t height;
+
+ /* The horizontal offset from the origin of the reference grid to the
+ left side of the image area. */
+ uint_fast32_t xoff;
+
+ /* The vertical offset from the origin of the reference grid to the
+ top side of the image area. */
+ uint_fast32_t yoff;
+
+ /* The nominal width of a tile in units of the reference grid. */
+ uint_fast32_t tilewidth;
+
+ /* The nominal height of a tile in units of the reference grid. */
+ uint_fast32_t tileheight;
+
+ /* The horizontal offset from the origin of the reference grid to the
+ left side of the first tile. */
+ uint_fast32_t tilexoff;
+
+ /* The vertical offset from the origin of the reference grid to the
+ top side of the first tile. */
+ uint_fast32_t tileyoff;
+
+ /* The number of components. */
+ uint_fast16_t numcomps;
+
+ /* The per-component information. */
+ jpc_sizcomp_t *comps;
+
+} jpc_siz_t;
+
+/**************************************\
+* COD marker segment parameters.
+\**************************************/
+
+/*
+ * Coding style constants.
+ */
+
+/* Precincts may be used. */
+#define JPC_COX_PRT 0x01
+/* SOP marker segments may be used. */
+#define JPC_COD_SOP 0x02
+/* EPH marker segments may be used. */
+#define JPC_COD_EPH 0x04
+
+/*
+ * Progression order constants.
+ */
+
+/* Layer-resolution-component-precinct progressive
+ (i.e., progressive by fidelity). */
+#define JPC_COD_LRCPPRG 0
+/* Resolution-layer-component-precinct progressive
+ (i.e., progressive by resolution). */
+#define JPC_COD_RLCPPRG 1
+/* Resolution-precinct-component-layer progressive. */
+#define JPC_COD_RPCLPRG 2
+/* Precinct-component-resolution-layer progressive. */
+#define JPC_COD_PCRLPRG 3
+/* Component-position-resolution-layer progressive. */
+#define JPC_COD_CPRLPRG 4
+
+/*
+ * Code block style constants.
+ */
+
+#define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */
+#define JPC_COX_RESET 0x02 /* Reset context probabilities. */
+#define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */
+#define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */
+#define JPC_COX_PTERM 0x10 /* Predictable termination. */
+#define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */
+
+/* Transform constants. */
+#define JPC_COX_INS 0x00 /* Irreversible 9/7. */
+#define JPC_COX_RFT 0x01 /* Reversible 5/3. */
+
+/* Multicomponent transform constants. */
+#define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */
+#define JPC_COD_MCT 0x01 /* Multicomponent transform. */
+
+/* Get the code block size value from the code block size exponent. */
+#define JPC_COX_CBLKSIZEEXPN(x) ((x) - 2)
+/* Get the code block size exponent from the code block size value. */
+#define JPC_COX_GETCBLKSIZEEXPN(x) ((x) + 2)
+
+/* Per resolution-level information. */
+
+typedef struct {
+
+ /* The packet partition width. */
+ uint_fast8_t parwidthval;
+
+ /* The packet partition height. */
+ uint_fast8_t parheightval;
+
+} jpc_coxrlvl_t;
+
+/* Per component information. */
+
+typedef struct {
+
+ /* The coding style. */
+ uint_fast8_t csty;
+
+ /* The number of decomposition levels. */
+ uint_fast8_t numdlvls;
+
+ /* The nominal code block width specifier. */
+ uint_fast8_t cblkwidthval;
+
+ /* The nominal code block height specifier. */
+ uint_fast8_t cblkheightval;
+
+ /* The style of coding passes. */
+ uint_fast8_t cblksty;
+
+ /* The QMFB employed. */
+ uint_fast8_t qmfbid;
+
+ /* The number of resolution levels. */
+ int numrlvls;
+
+ /* The per-resolution-level information. */
+ jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
+
+} jpc_coxcp_t;
+
+/* COD marker segment parameters. */
+
+typedef struct {
+
+ /* The general coding style. */
+ uint_fast8_t csty;
+
+ /* The progression order. */
+ uint_fast8_t prg;
+
+ /* The number of layers. */
+ uint_fast16_t numlyrs;
+
+ /* The multicomponent transform. */
+ uint_fast8_t mctrans;
+
+ /* Component-related parameters. */
+ jpc_coxcp_t compparms;
+
+} jpc_cod_t;
+
+/* COC marker segment parameters. */
+
+typedef struct {
+
+ /* The component number. */
+ uint_fast16_t compno;
+
+ /* Component-related parameters. */
+ jpc_coxcp_t compparms;
+
+} jpc_coc_t;
+
+/**************************************\
+* RGN marker segment parameters.
+\**************************************/
+
+/* The maxshift ROI style. */
+#define JPC_RGN_MAXSHIFT 0x00
+
+typedef struct {
+
+ /* The component to which the marker applies. */
+ uint_fast16_t compno;
+
+ /* The ROI style. */
+ uint_fast8_t roisty;
+
+ /* The ROI shift value. */
+ uint_fast8_t roishift;
+
+} jpc_rgn_t;
+
+/**************************************\
+* QCD/QCC marker segment parameters.
+\**************************************/
+
+/*
+ * Quantization style constants.
+ */
+
+#define JPC_QCX_NOQNT 0 /* No quantization. */
+#define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */
+#define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */
+
+/*
+ * Stepsize manipulation macros.
+ */
+
+#define JPC_QCX_GETEXPN(x) ((x) >> 11)
+#define JPC_QCX_GETMANT(x) ((x) & 0x07ff)
+#define JPC_QCX_EXPN(x) (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11))
+#define JPC_QCX_MANT(x) (assert(!((x) & (~0x7ff))), ((x) & 0x7ff))
+
+/* Per component information. */
+
+typedef struct {
+
+ /* The quantization style. */
+ uint_fast8_t qntsty;
+
+ /* The number of step sizes. */
+ int numstepsizes;
+
+ /* The step sizes. */
+ uint_fast16_t *stepsizes;
+
+ /* The number of guard bits. */
+ uint_fast8_t numguard;
+
+} jpc_qcxcp_t;
+
+/* QCC marker segment parameters. */
+
+typedef struct {
+
+ /* The component associated with this marker segment. */
+ uint_fast16_t compno;
+
+ /* The parameters. */
+ jpc_qcxcp_t compparms;
+
+} jpc_qcc_t;
+
+/* QCD marker segment parameters. */
+
+typedef struct {
+
+ /* The parameters. */
+ jpc_qcxcp_t compparms;
+
+} jpc_qcd_t;
+
+/**************************************\
+* POD marker segment parameters.
+\**************************************/
+
+typedef struct {
+
+ /* The progression order. */
+ uint_fast8_t prgord;
+
+ /* The lower bound (inclusive) on the resolution level for the
+ progression order volume. */
+ uint_fast8_t rlvlnostart;
+
+ /* The upper bound (exclusive) on the resolution level for the
+ progression order volume. */
+ uint_fast8_t rlvlnoend;
+
+ /* The lower bound (inclusive) on the component for the progression
+ order volume. */
+ uint_fast16_t compnostart;
+
+ /* The upper bound (exclusive) on the component for the progression
+ order volume. */
+ uint_fast16_t compnoend;
+
+ /* The upper bound (exclusive) on the layer for the progression
+ order volume. */
+ uint_fast16_t lyrnoend;
+
+} jpc_pocpchg_t;
+
+/* An alias for the above type. */
+typedef jpc_pocpchg_t jpc_pchg_t;
+
+/* POC marker segment parameters. */
+
+typedef struct {
+
+ /* The number of progression order changes. */
+ int numpchgs;
+
+ /* The per-progression-order-change information. */
+ jpc_pocpchg_t *pchgs;
+
+} jpc_poc_t;
+
+/**************************************\
+* PPM/PPT marker segment parameters.
+\**************************************/
+
+/* PPM marker segment parameters. */
+
+typedef struct {
+
+ /* The index. */
+ uint_fast8_t ind;
+
+ /* The length. */
+ uint_fast16_t len;
+
+ /* The data. */
+ uchar *data;
+
+} jpc_ppm_t;
+
+/* PPT marker segment parameters. */
+
+typedef struct {
+
+ /* The index. */
+ uint_fast8_t ind;
+
+ /* The length. */
+ uint_fast32_t len;
+
+ /* The data. */
+ unsigned char *data;
+
+} jpc_ppt_t;
+
+/**************************************\
+* COM marker segment parameters.
+\**************************************/
+
+/*
+ * Registration IDs.
+ */
+
+#define JPC_COM_BIN 0x00
+#define JPC_COM_LATIN 0x01
+
+typedef struct {
+
+ /* The registration ID. */
+ uint_fast16_t regid;
+
+ /* The length of the data in bytes. */
+ uint_fast16_t len;
+
+ /* The data. */
+ uchar *data;
+
+} jpc_com_t;
+
+/**************************************\
+* SOP marker segment parameters.
+\**************************************/
+
+typedef struct {
+
+ /* The sequence number. */
+ uint_fast16_t seqno;
+
+} jpc_sop_t;
+
+/**************************************\
+* CRG marker segment parameters.
+\**************************************/
+
+/* Per component information. */
+
+typedef struct {
+
+ /* The horizontal offset. */
+ uint_fast16_t hoff;
+
+ /* The vertical offset. */
+ uint_fast16_t voff;
+
+} jpc_crgcomp_t;
+
+typedef struct {
+
+ /* The number of components. */
+ int numcomps;
+
+ /* Per component information. */
+ jpc_crgcomp_t *comps;
+
+} jpc_crg_t;
+
+/**************************************\
+* Marker segment parameters for unknown marker type.
+\**************************************/
+
+typedef struct {
+
+ /* The data. */
+ uchar *data;
+
+ /* The length. */
+ uint_fast16_t len;
+
+} jpc_unk_t;
+
+/**************************************\
+* Generic marker segment parameters.
+\**************************************/
+
+typedef union {
+ int soc; /* unused */
+ jpc_sot_t sot;
+ int sod; /* unused */
+ int eoc; /* unused */
+ jpc_siz_t siz;
+ jpc_cod_t cod;
+ jpc_coc_t coc;
+ jpc_rgn_t rgn;
+ jpc_qcd_t qcd;
+ jpc_qcc_t qcc;
+ jpc_poc_t poc;
+ /* jpc_plm_t plm; */
+ /* jpc_plt_t plt; */
+ jpc_ppm_t ppm;
+ jpc_ppt_t ppt;
+ jpc_sop_t sop;
+ int eph; /* unused */
+ jpc_com_t com;
+ jpc_crg_t crg;
+ jpc_unk_t unk;
+} jpc_msparms_t;
+
+/**************************************\
+* Marker segment.
+\**************************************/
+
+/* Marker segment IDs. */
+
+/* The smallest valid marker value. */
+#define JPC_MS_MIN 0xff00
+
+/* The largest valid marker value. */
+#define JPC_MS_MAX 0xffff
+
+/* The minimum marker value that cannot occur within packet data. */
+#define JPC_MS_INMIN 0xff80
+/* The maximum marker value that cannot occur within packet data. */
+#define JPC_MS_INMAX 0xffff
+
+/* Delimiting marker segments. */
+#define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */
+#define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */
+#define JPC_MS_SOD 0xff93 /* Start of data (SOD). */
+#define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */
+
+/* Fixed information marker segments. */
+#define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */
+
+/* Functional marker segments. */
+#define JPC_MS_COD 0xff52 /* Coding style default (COD). */
+#define JPC_MS_COC 0xff53 /* Coding style component (COC). */
+#define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */
+#define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */
+#define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */
+#define JPC_MS_POC 0xff5f /* Progression order default (POC). */
+
+/* Pointer marker segments. */
+#define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */
+#define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */
+#define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */
+#define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */
+#define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */
+
+/* In bit stream marker segments. */
+#define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */
+#define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */
+
+/* Informational marker segments. */
+#define JPC_MS_CRG 0xff63 /* Component registration (CRG). */
+#define JPC_MS_COM 0xff64 /* Comment (COM). */
+
+/* Forward declaration. */
+struct jpc_msops_s;
+
+/* Generic marker segment class. */
+
+typedef struct {
+
+ /* The type of marker segment. */
+ uint_fast16_t id;
+
+ /* The length of the marker segment. */
+ uint_fast16_t len;
+
+ /* The starting offset within the stream. */
+ uint_fast32_t off;
+
+ /* The parameters of the marker segment. */
+ jpc_msparms_t parms;
+
+ /* The marker segment operations. */
+ struct jpc_msops_s *ops;
+
+} jpc_ms_t;
+
+/* Marker segment operations (which depend on the marker segment type). */
+
+typedef struct jpc_msops_s {
+
+ /* Destroy the marker segment parameters. */
+ void (*destroyparms)(jpc_ms_t *ms);
+
+ /* Get the marker segment parameters from a stream. */
+ int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
+
+ /* Put the marker segment parameters to a stream. */
+ int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
+
+ /* Dump the marker segment parameters (for debugging). */
+ int (*dumpparms)(jpc_ms_t *ms, FILE *out);
+
+} jpc_msops_t;
+
+/******************************************************************************\
+* Macros/Functions.
+\******************************************************************************/
+
+/* Create a code-stream state object. */
+jpc_cstate_t *jpc_cstate_create(void);
+
+/* Destroy a code-stream state object. */
+void jpc_cstate_destroy(jpc_cstate_t *cstate);
+
+/* Create a marker segment. */
+jpc_ms_t *jpc_ms_create(int type);
+
+/* Destroy a marker segment. */
+void jpc_ms_destroy(jpc_ms_t *ms);
+
+/* Does a marker segment have parameters? */
+#define JPC_MS_HASPARMS(x) \
+ (!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \
+ (x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f)))
+
+/* Get the marker segment type. */
+#define jpc_ms_gettype(ms) \
+ ((ms)->id)
+
+/* Read a marker segment from a stream. */
+jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
+
+/* Write a marker segment to a stream. */
+int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
+
+/* Copy code stream data from one stream to another. */
+int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
+
+/* Copy code stream data from one stream to another. */
+int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
+
+/* Dump a marker segment (for debugging). */
+void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
+
+/* Read a 8-bit unsigned integer from a stream. */
+int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
+
+/* Read a 16-bit unsigned integer from a stream. */
+int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
+
+/* Read a 32-bit unsigned integer from a stream. */
+int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
+
+/* Write a 8-bit unsigned integer to a stream. */
+int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
+
+/* Write a 16-bit unsigned integer to a stream. */
+int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
+
+/* Write a 32-bit unsigned integer to a stream. */
+int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_dec.c b/osframework/source/ImageLib/jpeg2000/jpc_dec.c
new file mode 100644
index 0000000..ff8a468
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_dec.c
@@ -0,0 +1,2361 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_dec.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jas_types.h"
+#include "jas_math.h"
+#include "jas_tvp.h"
+#include "jas_malloc.h"
+#include "jas_debug.h"
+
+#include "jpc_fix.h"
+#include "jpc_dec.h"
+#include "jpc_cs.h"
+#include "jpc_mct.h"
+#include "jpc_t2dec.h"
+#include "jpc_t1dec.h"
+#include "jpc_math.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+#define JPC_MHSOC 0x0001
+ /* In the main header, expecting a SOC marker segment. */
+#define JPC_MHSIZ 0x0002
+ /* In the main header, expecting a SIZ marker segment. */
+#define JPC_MH 0x0004
+ /* In the main header, expecting "other" marker segments. */
+#define JPC_TPHSOT 0x0008
+ /* In a tile-part header, expecting a SOT marker segment. */
+#define JPC_TPH 0x0010
+ /* In a tile-part header, expecting "other" marker segments. */
+#define JPC_MT 0x0020
+ /* In the main trailer. */
+
+typedef struct {
+
+ uint_fast16_t id;
+ /* The marker segment type. */
+
+ int validstates;
+ /* The states in which this type of marker segment can be
+ validly encountered. */
+
+ int (*action)(jpc_dec_t *dec, jpc_ms_t *ms);
+ /* The action to take upon encountering this type of marker segment. */
+
+} jpc_dec_mstabent_t;
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+/* COD/COC parameters have been specified. */
+#define JPC_CSET 0x0001
+/* QCD/QCC parameters have been specified. */
+#define JPC_QSET 0x0002
+/* COD/COC parameters set from a COC marker segment. */
+#define JPC_COC 0x0004
+/* QCD/QCC parameters set from a QCC marker segment. */
+#define JPC_QCC 0x0008
+
+/******************************************************************************\
+* Local function prototypes.
+\******************************************************************************/
+
+static int jpc_dec_dump(jpc_dec_t *dec, FILE *out);
+
+jpc_ppxstab_t *jpc_ppxstab_create(void);
+void jpc_ppxstab_destroy(jpc_ppxstab_t *tab);
+int jpc_ppxstab_grow(jpc_ppxstab_t *tab, int maxents);
+int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent);
+jpc_streamlist_t *jpc_ppmstabtostreams(jpc_ppxstab_t *tab);
+int jpc_pptstabwrite(jas_stream_t *out, jpc_ppxstab_t *tab);
+jpc_ppxstabent_t *jpc_ppxstabent_create(void);
+void jpc_ppxstabent_destroy(jpc_ppxstabent_t *ent);
+
+int jpc_streamlist_numstreams(jpc_streamlist_t *streamlist);
+jpc_streamlist_t *jpc_streamlist_create(void);
+int jpc_streamlist_insert(jpc_streamlist_t *streamlist, int streamno,
+ jas_stream_t *stream);
+jas_stream_t *jpc_streamlist_remove(jpc_streamlist_t *streamlist, int streamno);
+void jpc_streamlist_destroy(jpc_streamlist_t *streamlist);
+jas_stream_t *jpc_streamlist_get(jpc_streamlist_t *streamlist, int streamno);
+
+static void jpc_dec_cp_resetflags(jpc_dec_cp_t *cp);
+static jpc_dec_cp_t *jpc_dec_cp_create(uint_fast16_t numcomps);
+static int jpc_dec_cp_isvalid(jpc_dec_cp_t *cp);
+static jpc_dec_cp_t *jpc_dec_cp_copy(jpc_dec_cp_t *cp);
+static int jpc_dec_cp_setfromcod(jpc_dec_cp_t *cp, jpc_cod_t *cod);
+static int jpc_dec_cp_setfromcoc(jpc_dec_cp_t *cp, jpc_coc_t *coc);
+static int jpc_dec_cp_setfromcox(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp,
+ jpc_coxcp_t *compparms, int flags);
+static int jpc_dec_cp_setfromqcd(jpc_dec_cp_t *cp, jpc_qcd_t *qcd);
+static int jpc_dec_cp_setfromqcc(jpc_dec_cp_t *cp, jpc_qcc_t *qcc);
+static int jpc_dec_cp_setfromqcx(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp,
+ jpc_qcxcp_t *compparms, int flags);
+static int jpc_dec_cp_setfromrgn(jpc_dec_cp_t *cp, jpc_rgn_t *rgn);
+static int jpc_dec_cp_prepare(jpc_dec_cp_t *cp);
+static void jpc_dec_cp_destroy(jpc_dec_cp_t *cp);
+static int jpc_dec_cp_setfrompoc(jpc_dec_cp_t *cp, jpc_poc_t *poc, int reset);
+static int jpc_pi_addpchgfrompoc(jpc_pi_t *pi, jpc_poc_t *poc);
+
+static int jpc_dec_decode(jpc_dec_t *dec);
+static jpc_dec_t *jpc_dec_create(jpc_dec_importopts_t *impopts, jas_stream_t *in);
+static void jpc_dec_destroy(jpc_dec_t *dec);
+static void jpc_dequantize(jas_matrix_t *x, jpc_fix_t absstepsize);
+static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps);
+static jpc_fix_t jpc_calcabsstepsize(int stepsize, int numbits);
+static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile);
+static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile);
+static int jpc_dec_tilefini(jpc_dec_t *dec, jpc_dec_tile_t *tile);
+static int jpc_dec_process_soc(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_sod(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_eoc(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_cod(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_coc(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_rgn(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_qcd(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_poc(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_ppm(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_ppt(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_com(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_unk(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms);
+static int jpc_dec_parseopts(char *optstr, jpc_dec_importopts_t *opts);
+
+static jpc_dec_mstabent_t *jpc_dec_mstab_lookup(uint_fast16_t id);
+
+/******************************************************************************\
+* Global data.
+\******************************************************************************/
+
+jpc_dec_mstabent_t jpc_dec_mstab[] = {
+ {JPC_MS_SOC, JPC_MHSOC, jpc_dec_process_soc},
+ {JPC_MS_SOT, JPC_MH | JPC_TPHSOT, jpc_dec_process_sot},
+ {JPC_MS_SOD, JPC_TPH, jpc_dec_process_sod},
+ {JPC_MS_EOC, JPC_TPHSOT, jpc_dec_process_eoc},
+ {JPC_MS_SIZ, JPC_MHSIZ, jpc_dec_process_siz},
+ {JPC_MS_COD, JPC_MH | JPC_TPH, jpc_dec_process_cod},
+ {JPC_MS_COC, JPC_MH | JPC_TPH, jpc_dec_process_coc},
+ {JPC_MS_RGN, JPC_MH | JPC_TPH, jpc_dec_process_rgn},
+ {JPC_MS_QCD, JPC_MH | JPC_TPH, jpc_dec_process_qcd},
+ {JPC_MS_QCC, JPC_MH | JPC_TPH, jpc_dec_process_qcc},
+ {JPC_MS_POC, JPC_MH | JPC_TPH, jpc_dec_process_poc},
+ {JPC_MS_TLM, JPC_MH, 0},
+ {JPC_MS_PLM, JPC_MH, 0},
+ {JPC_MS_PLT, JPC_TPH, 0},
+ {JPC_MS_PPM, JPC_MH, jpc_dec_process_ppm},
+ {JPC_MS_PPT, JPC_TPH, jpc_dec_process_ppt},
+ {JPC_MS_SOP, 0, 0},
+ {JPC_MS_CRG, JPC_MH, jpc_dec_process_crg},
+ {JPC_MS_COM, JPC_MH | JPC_TPH, jpc_dec_process_com},
+ {0, JPC_MH | JPC_TPH, jpc_dec_process_unk}
+};
+
+/******************************************************************************\
+* The main entry point for the JPEG-2000 decoder.
+\******************************************************************************/
+
+jas_image_t *jpc_decode(jas_stream_t *in, char *optstr)
+{
+ jpc_dec_importopts_t opts;
+ jpc_dec_t *dec;
+ jas_image_t *image;
+
+ dec = 0;
+
+ if (jpc_dec_parseopts(optstr, &opts)) {
+ goto error;
+ }
+
+ jpc_initluts();
+
+ if (!(dec = jpc_dec_create(&opts, in))) {
+ goto error;
+ }
+
+ /* Do most of the work. */
+ if (jpc_dec_decode(dec)) {
+ goto error;
+ }
+
+ if (jas_image_numcmpts(dec->image) >= 3) {
+ jas_image_setclrspc(dec->image, JAS_CLRSPC_SRGB);
+ jas_image_setcmpttype(dec->image, 0,
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R));
+ jas_image_setcmpttype(dec->image, 1,
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G));
+ jas_image_setcmpttype(dec->image, 2,
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B));
+ } else {
+ jas_image_setclrspc(dec->image, JAS_CLRSPC_SGRAY);
+ jas_image_setcmpttype(dec->image, 0,
+ JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y));
+ }
+
+ /* Save the return value. */
+ image = dec->image;
+
+ /* Stop the image from being discarded. */
+ dec->image = 0;
+
+ /* Destroy decoder. */
+ jpc_dec_destroy(dec);
+
+ return image;
+
+error:
+ if (dec) {
+ jpc_dec_destroy(dec);
+ }
+ return 0;
+}
+
+typedef enum {
+ OPT_MAXLYRS,
+ OPT_MAXPKTS,
+ OPT_DEBUG
+} optid_t;
+
+jas_taginfo_t decopts[] = {
+ {OPT_MAXLYRS, "maxlyrs"},
+ {OPT_MAXPKTS, "maxpkts"},
+ {OPT_DEBUG, "debug"},
+ {-1, 0}
+};
+
+static int jpc_dec_parseopts(char *optstr, jpc_dec_importopts_t *opts)
+{
+ jas_tvparser_t *tvp;
+
+ opts->debug = 0;
+ opts->maxlyrs = JPC_MAXLYRS;
+ opts->maxpkts = -1;
+
+ if (!(tvp = jas_tvparser_create(optstr ? optstr : ""))) {
+ return -1;
+ }
+
+ while (!jas_tvparser_next(tvp)) {
+ switch (jas_taginfo_nonull(jas_taginfos_lookup(decopts,
+ jas_tvparser_gettag(tvp)))->id) {
+ case OPT_MAXLYRS:
+ opts->maxlyrs = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_DEBUG:
+ opts->debug = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_MAXPKTS:
+ opts->maxpkts = atoi(jas_tvparser_getval(tvp));
+ break;
+ default:
+ fprintf(stderr, "warning: ignoring invalid option %s\n",
+ jas_tvparser_gettag(tvp));
+ break;
+ }
+ }
+
+ jas_tvparser_destroy(tvp);
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for table-driven code stream decoder.
+\******************************************************************************/
+
+static jpc_dec_mstabent_t *jpc_dec_mstab_lookup(uint_fast16_t id)
+{
+ jpc_dec_mstabent_t *mstabent;
+ for (mstabent = jpc_dec_mstab; mstabent->id != 0; ++mstabent) {
+ if (mstabent->id == id) {
+ break;
+ }
+ }
+ return mstabent;
+}
+
+static int jpc_dec_decode(jpc_dec_t *dec)
+{
+ jpc_ms_t *ms;
+ jpc_dec_mstabent_t *mstabent;
+ int ret;
+ jpc_cstate_t *cstate;
+
+ if (!(cstate = jpc_cstate_create())) {
+ return -1;
+ }
+ dec->cstate = cstate;
+
+ /* Initially, we should expect to encounter a SOC marker segment. */
+ dec->state = JPC_MHSOC;
+
+ for (;;) {
+
+ /* Get the next marker segment in the code stream. */
+ if (!(ms = jpc_getms(dec->in, cstate))) {
+ fprintf(stderr, "cannot get marker segment\n");
+ return -1;
+ }
+
+ mstabent = jpc_dec_mstab_lookup(ms->id);
+ assert(mstabent);
+
+ /* Ensure that this type of marker segment is permitted
+ at this point in the code stream. */
+ if (!(dec->state & mstabent->validstates)) {
+ fprintf(stderr, "unexpected marker segment type\n");
+ jpc_ms_destroy(ms);
+ return -1;
+ }
+
+ /* Process the marker segment. */
+ if (mstabent->action) {
+ ret = (*mstabent->action)(dec, ms);
+ } else {
+ /* No explicit action is required. */
+ ret = 0;
+ }
+
+ /* Destroy the marker segment. */
+ jpc_ms_destroy(ms);
+
+ if (ret < 0) {
+ return -1;
+ } else if (ret > 0) {
+ break;
+ }
+
+ }
+
+ return 0;
+}
+
+static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ int cmptno;
+ jpc_dec_cmpt_t *cmpt;
+ jpc_crg_t *crg;
+
+ crg = &ms->parms.crg;
+ for (cmptno = 0, cmpt = dec->cmpts; cmptno < dec->numcomps; ++cmptno,
+ ++cmpt) {
+ /* Ignore the information in the CRG marker segment for now.
+ This information serves no useful purpose for decoding anyhow.
+ Some other parts of the code need to be changed if these lines
+ are uncommented.
+ cmpt->hsubstep = crg->comps[cmptno].hoff;
+ cmpt->vsubstep = crg->comps[cmptno].voff;
+ */
+ }
+ return 0;
+}
+
+static int jpc_dec_process_soc(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ /* Eliminate warnings about unused variables. */
+ ms = 0;
+
+ /* We should expect to encounter a SIZ marker segment next. */
+ dec->state = JPC_MHSIZ;
+
+ return 0;
+}
+
+static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_dec_tile_t *tile;
+ jpc_sot_t *sot = &ms->parms.sot;
+ jas_image_cmptparm_t *compinfos;
+ jas_image_cmptparm_t *compinfo;
+ jpc_dec_cmpt_t *cmpt;
+ int cmptno;
+
+ if (dec->state == JPC_MH) {
+
+ compinfos = jas_malloc(dec->numcomps * sizeof(jas_image_cmptparm_t));
+ assert(compinfos);
+ for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos;
+ cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) {
+ compinfo->tlx = 0;
+ compinfo->tly = 0;
+ compinfo->prec = cmpt->prec;
+ compinfo->sgnd = cmpt->sgnd;
+ compinfo->width = cmpt->width;
+ compinfo->height = cmpt->height;
+ compinfo->hstep = cmpt->hstep;
+ compinfo->vstep = cmpt->vstep;
+ }
+
+ if (!(dec->image = jas_image_create(dec->numcomps, compinfos,
+ JAS_CLRSPC_UNKNOWN))) {
+ return -1;
+ }
+ jas_free(compinfos);
+
+ /* Is the packet header information stored in PPM marker segments in
+ the main header? */
+ if (dec->ppmstab) {
+ /* Convert the PPM marker segment data into a collection of streams
+ (one stream per tile-part). */
+ if (!(dec->pkthdrstreams = jpc_ppmstabtostreams(dec->ppmstab))) {
+ abort();
+ }
+ jpc_ppxstab_destroy(dec->ppmstab);
+ dec->ppmstab = 0;
+ }
+ }
+
+ if (sot->len > 0) {
+ dec->curtileendoff = jas_stream_getrwcount(dec->in) - ms->len -
+ 4 + sot->len;
+ } else {
+ dec->curtileendoff = 0;
+ }
+
+ if (JAS_CAST(int, sot->tileno) > dec->numtiles) {
+ fprintf(stderr, "invalid tile number in SOT marker segment\n");
+ return -1;
+ }
+ /* Set the current tile. */
+ dec->curtile = &dec->tiles[sot->tileno];
+ tile = dec->curtile;
+ /* Ensure that this is the expected part number. */
+ if (sot->partno != tile->partno) {
+ return -1;
+ }
+ if (tile->numparts > 0 && sot->partno >= tile->numparts) {
+ return -1;
+ }
+ if (!tile->numparts && sot->numparts > 0) {
+ tile->numparts = sot->numparts;
+ }
+
+ tile->pptstab = 0;
+
+ switch (tile->state) {
+ case JPC_TILE_INIT:
+ /* This is the first tile-part for this tile. */
+ tile->state = JPC_TILE_ACTIVE;
+ assert(!tile->cp);
+ if (!(tile->cp = jpc_dec_cp_copy(dec->cp))) {
+ return -1;
+ }
+ jpc_dec_cp_resetflags(dec->cp);
+ break;
+ default:
+ if (sot->numparts == sot->partno - 1) {
+ tile->state = JPC_TILE_ACTIVELAST;
+ }
+ break;
+ }
+
+ /* Note: We do not increment the expected tile-part number until
+ all processing for this tile-part is complete. */
+
+ /* We should expect to encounter other tile-part header marker
+ segments next. */
+ dec->state = JPC_TPH;
+
+ return 0;
+}
+
+static int jpc_dec_process_sod(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_dec_tile_t *tile;
+ int pos;
+
+ /* Eliminate compiler warnings about unused variables. */
+ ms = 0;
+
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+
+ if (!tile->partno) {
+ if (!jpc_dec_cp_isvalid(tile->cp)) {
+ return -1;
+ }
+ jpc_dec_cp_prepare(tile->cp);
+ if (jpc_dec_tileinit(dec, tile)) {
+ return -1;
+ }
+ }
+
+ /* Are packet headers stored in the main header or tile-part header? */
+ if (dec->pkthdrstreams) {
+ /* Get the stream containing the packet header data for this
+ tile-part. */
+ if (!(tile->pkthdrstream = jpc_streamlist_remove(dec->pkthdrstreams, 0))) {
+ return -1;
+ }
+ }
+
+ if (tile->pptstab) {
+ if (!tile->pkthdrstream) {
+ if (!(tile->pkthdrstream = jas_stream_memopen(0, 0))) {
+ return -1;
+ }
+ }
+ pos = jas_stream_tell(tile->pkthdrstream);
+ jas_stream_seek(tile->pkthdrstream, 0, SEEK_END);
+ if (jpc_pptstabwrite(tile->pkthdrstream, tile->pptstab)) {
+ return -1;
+ }
+ jas_stream_seek(tile->pkthdrstream, pos, SEEK_SET);
+ jpc_ppxstab_destroy(tile->pptstab);
+ tile->pptstab = 0;
+ }
+
+ if (jas_getdbglevel() >= 10) {
+ jpc_dec_dump(dec, stderr);
+ }
+
+ if (jpc_dec_decodepkts(dec, (tile->pkthdrstream) ? tile->pkthdrstream :
+ dec->in, dec->in)) {
+ fprintf(stderr, "jpc_dec_decodepkts failed\n");
+ return -1;
+ }
+
+ /* Gobble any unconsumed tile data. */
+ if (dec->curtileendoff > 0) {
+ long curoff;
+ uint_fast32_t n;
+ curoff = jas_stream_getrwcount(dec->in);
+ if (curoff < dec->curtileendoff) {
+ n = dec->curtileendoff - curoff;
+ fprintf(stderr,
+ "warning: ignoring trailing garbage (%lu bytes)\n",
+ (unsigned long) n);
+
+ while (n-- > 0) {
+ if (jas_stream_getc(dec->in) == EOF) {
+ fprintf(stderr, "read error\n");
+ return -1;
+ }
+ }
+ } else if (curoff > dec->curtileendoff) {
+ fprintf(stderr,
+ "warning: not enough tile data (%lu bytes)\n",
+ (unsigned long) curoff - dec->curtileendoff);
+ }
+
+ }
+
+ if (tile->numparts > 0 && tile->partno == tile->numparts - 1) {
+ if (jpc_dec_tiledecode(dec, tile)) {
+ return -1;
+ }
+ jpc_dec_tilefini(dec, tile);
+ }
+
+ dec->curtile = 0;
+
+ /* Increment the expected tile-part number. */
+ ++tile->partno;
+
+ /* We should expect to encounter a SOT marker segment next. */
+ dec->state = JPC_TPHSOT;
+
+ return 0;
+}
+
+static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile)
+{
+ jpc_dec_tcomp_t *tcomp;
+ int compno;
+ int rlvlno;
+ jpc_dec_rlvl_t *rlvl;
+ jpc_dec_band_t *band;
+ jpc_dec_prc_t *prc;
+ int bndno;
+ jpc_tsfb_band_t *bnd;
+ int bandno;
+ jpc_dec_ccp_t *ccp;
+ int prccnt;
+ jpc_dec_cblk_t *cblk;
+ int cblkcnt;
+ uint_fast32_t tlprcxstart;
+ uint_fast32_t tlprcystart;
+ uint_fast32_t brprcxend;
+ uint_fast32_t brprcyend;
+ uint_fast32_t tlcbgxstart;
+ uint_fast32_t tlcbgystart;
+ uint_fast32_t brcbgxend;
+ uint_fast32_t brcbgyend;
+ uint_fast32_t cbgxstart;
+ uint_fast32_t cbgystart;
+ uint_fast32_t cbgxend;
+ uint_fast32_t cbgyend;
+ uint_fast32_t tlcblkxstart;
+ uint_fast32_t tlcblkystart;
+ uint_fast32_t brcblkxend;
+ uint_fast32_t brcblkyend;
+ uint_fast32_t cblkxstart;
+ uint_fast32_t cblkystart;
+ uint_fast32_t cblkxend;
+ uint_fast32_t cblkyend;
+ uint_fast32_t tmpxstart;
+ uint_fast32_t tmpystart;
+ uint_fast32_t tmpxend;
+ uint_fast32_t tmpyend;
+ jpc_dec_cp_t *cp;
+ jpc_tsfb_band_t bnds[64];
+ jpc_pchg_t *pchg;
+ int pchgno;
+ jpc_dec_cmpt_t *cmpt;
+
+ cp = tile->cp;
+ tile->realmode = 0;
+ if (cp->mctid == JPC_MCT_ICT) {
+ tile->realmode = 1;
+ }
+
+ for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno <
+ dec->numcomps; ++compno, ++tcomp, ++cmpt) {
+ ccp = &tile->cp->ccps[compno];
+ if (ccp->qmfbid == JPC_COX_INS) {
+ tile->realmode = 1;
+ }
+ tcomp->numrlvls = ccp->numrlvls;
+ if (!(tcomp->rlvls = jas_malloc(tcomp->numrlvls *
+ sizeof(jpc_dec_rlvl_t)))) {
+ return -1;
+ }
+ if (!(tcomp->data = jas_seq2d_create(JPC_CEILDIV(tile->xstart,
+ cmpt->hstep), JPC_CEILDIV(tile->ystart, cmpt->vstep),
+ JPC_CEILDIV(tile->xend, cmpt->hstep), JPC_CEILDIV(tile->yend,
+ cmpt->vstep)))) {
+ return -1;
+ }
+ if (!(tcomp->tsfb = jpc_cod_gettsfb(ccp->qmfbid,
+ tcomp->numrlvls - 1))) {
+ return -1;
+ }
+{
+ jpc_tsfb_getbands(tcomp->tsfb, jas_seq2d_xstart(tcomp->data), jas_seq2d_ystart(tcomp->data), jas_seq2d_xend(tcomp->data), jas_seq2d_yend(tcomp->data), bnds);
+}
+ for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls;
+ ++rlvlno, ++rlvl) {
+rlvl->bands = 0;
+ rlvl->xstart = JPC_CEILDIVPOW2(tcomp->xstart,
+ tcomp->numrlvls - 1 - rlvlno);
+ rlvl->ystart = JPC_CEILDIVPOW2(tcomp->ystart,
+ tcomp->numrlvls - 1 - rlvlno);
+ rlvl->xend = JPC_CEILDIVPOW2(tcomp->xend,
+ tcomp->numrlvls - 1 - rlvlno);
+ rlvl->yend = JPC_CEILDIVPOW2(tcomp->yend,
+ tcomp->numrlvls - 1 - rlvlno);
+ rlvl->prcwidthexpn = ccp->prcwidthexpns[rlvlno];
+ rlvl->prcheightexpn = ccp->prcheightexpns[rlvlno];
+ tlprcxstart = JPC_FLOORDIVPOW2(rlvl->xstart,
+ rlvl->prcwidthexpn) << rlvl->prcwidthexpn;
+ tlprcystart = JPC_FLOORDIVPOW2(rlvl->ystart,
+ rlvl->prcheightexpn) << rlvl->prcheightexpn;
+ brprcxend = JPC_CEILDIVPOW2(rlvl->xend,
+ rlvl->prcwidthexpn) << rlvl->prcwidthexpn;
+ brprcyend = JPC_CEILDIVPOW2(rlvl->yend,
+ rlvl->prcheightexpn) << rlvl->prcheightexpn;
+ rlvl->numhprcs = (brprcxend - tlprcxstart) >>
+ rlvl->prcwidthexpn;
+ rlvl->numvprcs = (brprcyend - tlprcystart) >>
+ rlvl->prcheightexpn;
+ rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs;
+
+ if (rlvl->xstart >= rlvl->xend || rlvl->ystart >= rlvl->yend) {
+ rlvl->bands = 0;
+ rlvl->numprcs = 0;
+ rlvl->numhprcs = 0;
+ rlvl->numvprcs = 0;
+ continue;
+ }
+ if (!rlvlno) {
+ tlcbgxstart = tlprcxstart;
+ tlcbgystart = tlprcystart;
+ brcbgxend = brprcxend;
+ brcbgyend = brprcyend;
+ rlvl->cbgwidthexpn = rlvl->prcwidthexpn;
+ rlvl->cbgheightexpn = rlvl->prcheightexpn;
+ } else {
+ tlcbgxstart = JPC_CEILDIVPOW2(tlprcxstart, 1);
+ tlcbgystart = JPC_CEILDIVPOW2(tlprcystart, 1);
+ brcbgxend = JPC_CEILDIVPOW2(brprcxend, 1);
+ brcbgyend = JPC_CEILDIVPOW2(brprcyend, 1);
+ rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1;
+ rlvl->cbgheightexpn = rlvl->prcheightexpn - 1;
+ }
+ rlvl->cblkwidthexpn = JAS_MIN(ccp->cblkwidthexpn,
+ rlvl->cbgwidthexpn);
+ rlvl->cblkheightexpn = JAS_MIN(ccp->cblkheightexpn,
+ rlvl->cbgheightexpn);
+
+ rlvl->numbands = (!rlvlno) ? 1 : 3;
+ if (!(rlvl->bands = jas_malloc(rlvl->numbands *
+ sizeof(jpc_dec_band_t)))) {
+ return -1;
+ }
+ for (bandno = 0, band = rlvl->bands;
+ bandno < rlvl->numbands; ++bandno, ++band) {
+ bndno = (!rlvlno) ? 0 : (3 * (rlvlno - 1) +
+ bandno + 1);
+ bnd = &bnds[bndno];
+
+ band->orient = bnd->orient;
+ band->stepsize = ccp->stepsizes[bndno];
+ band->analgain = JPC_NOMINALGAIN(ccp->qmfbid,
+ tcomp->numrlvls - 1, rlvlno, band->orient);
+ band->absstepsize = jpc_calcabsstepsize(band->stepsize,
+ cmpt->prec + band->analgain);
+ band->numbps = ccp->numguardbits +
+ JPC_QCX_GETEXPN(band->stepsize) - 1;
+ band->roishift = (ccp->roishift + band->numbps >= JPC_PREC) ?
+ (JPC_PREC - 1 - band->numbps) : ccp->roishift;
+ band->data = 0;
+ band->prcs = 0;
+ if (bnd->xstart == bnd->xend || bnd->ystart == bnd->yend) {
+ continue;
+ }
+ if (!(band->data = jas_seq2d_create(0, 0, 0, 0))) {
+ return -1;
+ }
+ jas_seq2d_bindsub(band->data, tcomp->data, bnd->locxstart, bnd->locystart, bnd->locxend, bnd->locyend);
+ jas_seq2d_setshift(band->data, bnd->xstart, bnd->ystart);
+
+ assert(rlvl->numprcs);
+
+ if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_dec_prc_t)))) {
+ return -1;
+ }
+
+/************************************************/
+ cbgxstart = tlcbgxstart;
+ cbgystart = tlcbgystart;
+ for (prccnt = rlvl->numprcs, prc = band->prcs;
+ prccnt > 0; --prccnt, ++prc) {
+ cbgxend = cbgxstart + (1 << rlvl->cbgwidthexpn);
+ cbgyend = cbgystart + (1 << rlvl->cbgheightexpn);
+ prc->xstart = JAS_MAX(cbgxstart, JAS_CAST(uint_fast32_t, jas_seq2d_xstart(band->data)));
+ prc->ystart = JAS_MAX(cbgystart, JAS_CAST(uint_fast32_t, jas_seq2d_ystart(band->data)));
+ prc->xend = JAS_MIN(cbgxend, JAS_CAST(uint_fast32_t, jas_seq2d_xend(band->data)));
+ prc->yend = JAS_MIN(cbgyend, JAS_CAST(uint_fast32_t, jas_seq2d_yend(band->data)));
+ if (prc->xend > prc->xstart && prc->yend > prc->ystart) {
+ tlcblkxstart = JPC_FLOORDIVPOW2(prc->xstart,
+ rlvl->cblkwidthexpn) << rlvl->cblkwidthexpn;
+ tlcblkystart = JPC_FLOORDIVPOW2(prc->ystart,
+ rlvl->cblkheightexpn) << rlvl->cblkheightexpn;
+ brcblkxend = JPC_CEILDIVPOW2(prc->xend,
+ rlvl->cblkwidthexpn) << rlvl->cblkwidthexpn;
+ brcblkyend = JPC_CEILDIVPOW2(prc->yend,
+ rlvl->cblkheightexpn) << rlvl->cblkheightexpn;
+ prc->numhcblks = (brcblkxend - tlcblkxstart) >>
+ rlvl->cblkwidthexpn;
+ prc->numvcblks = (brcblkyend - tlcblkystart) >>
+ rlvl->cblkheightexpn;
+ prc->numcblks = prc->numhcblks * prc->numvcblks;
+ assert(prc->numcblks > 0);
+
+ if (!(prc->incltagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) {
+ return -1;
+ }
+ if (!(prc->numimsbstagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) {
+ return -1;
+ }
+ if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_dec_cblk_t)))) {
+ return -1;
+ }
+
+ cblkxstart = cbgxstart;
+ cblkystart = cbgystart;
+ for (cblkcnt = prc->numcblks, cblk = prc->cblks; cblkcnt > 0;) {
+ cblkxend = cblkxstart + (1 << rlvl->cblkwidthexpn);
+ cblkyend = cblkystart + (1 << rlvl->cblkheightexpn);
+ tmpxstart = JAS_MAX(cblkxstart, prc->xstart);
+ tmpystart = JAS_MAX(cblkystart, prc->ystart);
+ tmpxend = JAS_MIN(cblkxend, prc->xend);
+ tmpyend = JAS_MIN(cblkyend, prc->yend);
+ if (tmpxend > tmpxstart && tmpyend > tmpystart) {
+ cblk->firstpassno = -1;
+ cblk->mqdec = 0;
+ cblk->nulldec = 0;
+ cblk->flags = 0;
+ cblk->numpasses = 0;
+ cblk->segs.head = 0;
+ cblk->segs.tail = 0;
+ cblk->curseg = 0;
+ cblk->numimsbs = 0;
+ cblk->numlenbits = 3;
+ cblk->flags = 0;
+ if (!(cblk->data = jas_seq2d_create(0, 0, 0, 0))) {
+ return -1;
+ }
+ jas_seq2d_bindsub(cblk->data, band->data, tmpxstart, tmpystart, tmpxend, tmpyend);
+ ++cblk;
+ --cblkcnt;
+ }
+ cblkxstart += 1 << rlvl->cblkwidthexpn;
+ if (cblkxstart >= cbgxend) {
+ cblkxstart = cbgxstart;
+ cblkystart += 1 << rlvl->cblkheightexpn;
+ }
+ }
+
+ } else {
+ prc->cblks = 0;
+ prc->incltagtree = 0;
+ prc->numimsbstagtree = 0;
+ }
+ cbgxstart += 1 << rlvl->cbgwidthexpn;
+ if (cbgxstart >= brcbgxend) {
+ cbgxstart = tlcbgxstart;
+ cbgystart += 1 << rlvl->cbgheightexpn;
+ }
+
+ }
+/********************************************/
+ }
+ }
+ }
+
+if (!(tile->pi = jpc_dec_pi_create(dec, tile)))
+{
+ return -1;
+}
+
+ for (pchgno = 0; pchgno < jpc_pchglist_numpchgs(tile->cp->pchglist);
+ ++pchgno) {
+ pchg = jpc_pchg_copy(jpc_pchglist_get(tile->cp->pchglist, pchgno));
+ assert(pchg);
+ jpc_pi_addpchg(tile->pi, pchg);
+ }
+ jpc_pi_init(tile->pi);
+
+ return 0;
+}
+
+static int jpc_dec_tilefini(jpc_dec_t *dec, jpc_dec_tile_t *tile)
+{
+ jpc_dec_tcomp_t *tcomp;
+ int compno;
+ int bandno;
+ int rlvlno;
+ jpc_dec_band_t *band;
+ jpc_dec_rlvl_t *rlvl;
+ int prcno;
+ jpc_dec_prc_t *prc;
+ jpc_dec_seg_t *seg;
+ jpc_dec_cblk_t *cblk;
+ int cblkno;
+
+if (tile->tcomps) {
+
+ for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps;
+ ++compno, ++tcomp) {
+ for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls;
+ ++rlvlno, ++rlvl) {
+if (!rlvl->bands) {
+ continue;
+}
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; ++bandno, ++band) {
+if (band->prcs) {
+ for (prcno = 0, prc = band->prcs; prcno <
+ rlvl->numprcs; ++prcno, ++prc) {
+if (!prc->cblks) {
+ continue;
+}
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; ++cblkno, ++cblk) {
+
+ while (cblk->segs.head) {
+ seg = cblk->segs.head;
+ jpc_seglist_remove(&cblk->segs, seg);
+ jpc_seg_destroy(seg);
+ }
+ jas_matrix_destroy(cblk->data);
+ if (cblk->mqdec) {
+ jpc_mqdec_destroy(cblk->mqdec);
+ }
+ if (cblk->nulldec) {
+ jpc_bitstream_close(cblk->nulldec);
+ }
+ if (cblk->flags) {
+ jas_matrix_destroy(cblk->flags);
+ }
+ }
+ if (prc->incltagtree) {
+ jpc_tagtree_destroy(prc->incltagtree);
+ }
+ if (prc->numimsbstagtree) {
+ jpc_tagtree_destroy(prc->numimsbstagtree);
+ }
+ if (prc->cblks) {
+ jas_free(prc->cblks);
+ }
+ }
+}
+ if (band->data) {
+ jas_matrix_destroy(band->data);
+ }
+ if (band->prcs) {
+ jas_free(band->prcs);
+ }
+ }
+ if (rlvl->bands) {
+ jas_free(rlvl->bands);
+ }
+ }
+ if (tcomp->rlvls) {
+ jas_free(tcomp->rlvls);
+ }
+ if (tcomp->data) {
+ jas_matrix_destroy(tcomp->data);
+ }
+ if (tcomp->tsfb) {
+ jpc_tsfb_destroy(tcomp->tsfb);
+ }
+ }
+}
+ if (tile->cp) {
+ jpc_dec_cp_destroy(tile->cp);
+ tile->cp = 0;
+ }
+ if (tile->tcomps) {
+ jas_free(tile->tcomps);
+ tile->tcomps = 0;
+ }
+ if (tile->pi) {
+ jpc_pi_destroy(tile->pi);
+ tile->pi = 0;
+ }
+ if (tile->pkthdrstream) {
+ jas_stream_close(tile->pkthdrstream);
+ tile->pkthdrstream = 0;
+ }
+ if (tile->pptstab) {
+ jpc_ppxstab_destroy(tile->pptstab);
+ tile->pptstab = 0;
+ }
+
+ tile->state = JPC_TILE_DONE;
+
+ return 0;
+}
+
+static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile)
+{
+ int i;
+ int j;
+ jpc_dec_tcomp_t *tcomp;
+ jpc_dec_rlvl_t *rlvl;
+ jpc_dec_band_t *band;
+ int compno;
+ int rlvlno;
+ int bandno;
+ int adjust;
+ int v;
+ jpc_dec_ccp_t *ccp;
+ jpc_dec_cmpt_t *cmpt;
+
+ if (jpc_dec_decodecblks(dec, tile)) {
+ fprintf(stderr, "jpc_dec_decodecblks failed\n");
+ return -1;
+ }
+
+ /* Perform dequantization. */
+ for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps;
+ ++compno, ++tcomp) {
+ ccp = &tile->cp->ccps[compno];
+ for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls;
+ ++rlvlno, ++rlvl) {
+ if (!rlvl->bands) {
+ continue;
+ }
+ for (bandno = 0, band = rlvl->bands;
+ bandno < rlvl->numbands; ++bandno, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ jpc_undo_roi(band->data, band->roishift, ccp->roishift -
+ band->roishift, band->numbps);
+ if (tile->realmode) {
+ jas_matrix_asl(band->data, JPC_FIX_FRACBITS);
+ jpc_dequantize(band->data, band->absstepsize);
+ }
+
+ }
+ }
+ }
+
+ /* Apply an inverse wavelet transform if necessary. */
+ for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps;
+ ++compno, ++tcomp) {
+ ccp = &tile->cp->ccps[compno];
+ jpc_tsfb_synthesize(tcomp->tsfb, ((ccp->qmfbid ==
+ JPC_COX_RFT) ? JPC_TSFB_RITIMODE : 0), tcomp->data);
+ }
+
+
+ /* Apply an inverse intercomponent transform if necessary. */
+ switch (tile->cp->mctid) {
+ case JPC_MCT_RCT:
+ assert(dec->numcomps == 3);
+ jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data,
+ tile->tcomps[2].data);
+ break;
+ case JPC_MCT_ICT:
+ assert(dec->numcomps == 3);
+ jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data,
+ tile->tcomps[2].data);
+ break;
+ }
+
+ /* Perform rounding and convert to integer values. */
+ if (tile->realmode) {
+ for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps;
+ ++compno, ++tcomp) {
+ for (i = 0; i < jas_matrix_numrows(tcomp->data); ++i) {
+ for (j = 0; j < jas_matrix_numcols(tcomp->data); ++j) {
+ v = jas_matrix_get(tcomp->data, i, j);
+ v = jpc_fix_round(v);
+ jas_matrix_set(tcomp->data, i, j, jpc_fixtoint(v));
+ }
+ }
+ }
+ }
+
+ /* Perform level shift. */
+ for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno <
+ dec->numcomps; ++compno, ++tcomp, ++cmpt) {
+ adjust = cmpt->sgnd ? 0 : (1 << (cmpt->prec - 1));
+ for (i = 0; i < jas_matrix_numrows(tcomp->data); ++i) {
+ for (j = 0; j < jas_matrix_numcols(tcomp->data); ++j) {
+ *jas_matrix_getref(tcomp->data, i, j) += adjust;
+ }
+ }
+ }
+
+ /* Perform clipping. */
+ for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno <
+ dec->numcomps; ++compno, ++tcomp, ++cmpt) {
+ jpc_fix_t mn;
+ jpc_fix_t mx;
+ mn = cmpt->sgnd ? (-(1 << (cmpt->prec - 1))) : (0);
+ mx = cmpt->sgnd ? ((1 << (cmpt->prec - 1)) - 1) : ((1 <<
+ cmpt->prec) - 1);
+ jas_matrix_clip(tcomp->data, mn, mx);
+ }
+
+ /* XXX need to free tsfb struct */
+
+ /* Write the data for each component of the image. */
+ for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno <
+ dec->numcomps; ++compno, ++tcomp, ++cmpt) {
+ if (jas_image_writecmpt(dec->image, compno, tcomp->xstart -
+ JPC_CEILDIV(dec->xstart, cmpt->hstep), tcomp->ystart -
+ JPC_CEILDIV(dec->ystart, cmpt->vstep), jas_matrix_numcols(
+ tcomp->data), jas_matrix_numrows(tcomp->data), tcomp->data)) {
+ fprintf(stderr, "write component failed\n");
+ return -4;
+ }
+ }
+
+ return 0;
+}
+
+static int jpc_dec_process_eoc(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ int tileno;
+ jpc_dec_tile_t *tile;
+
+ /* Eliminate compiler warnings about unused variables. */
+ ms = 0;
+
+ for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles; ++tileno,
+ ++tile) {
+ if (tile->state == JPC_TILE_ACTIVE) {
+ if (jpc_dec_tiledecode(dec, tile)) {
+ return -1;
+ }
+ }
+ jpc_dec_tilefini(dec, tile);
+ }
+
+ /* We are done processing the code stream. */
+ dec->state = JPC_MT;
+
+ return 1;
+}
+
+static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_siz_t *siz = &ms->parms.siz;
+ int compno;
+ int tileno;
+ jpc_dec_tile_t *tile;
+ jpc_dec_tcomp_t *tcomp;
+ int htileno;
+ int vtileno;
+ jpc_dec_cmpt_t *cmpt;
+
+ dec->xstart = siz->xoff;
+ dec->ystart = siz->yoff;
+ dec->xend = siz->width;
+ dec->yend = siz->height;
+ dec->tilewidth = siz->tilewidth;
+ dec->tileheight = siz->tileheight;
+ dec->tilexoff = siz->tilexoff;
+ dec->tileyoff = siz->tileyoff;
+ dec->numcomps = siz->numcomps;
+ if (!(dec->cp = jpc_dec_cp_create(dec->numcomps))) {
+ return -1;
+ }
+
+ if (!(dec->cmpts = jas_malloc(dec->numcomps * sizeof(jpc_dec_cmpt_t)))) {
+ return -1;
+ }
+
+ for (compno = 0, cmpt = dec->cmpts; compno < dec->numcomps; ++compno,
+ ++cmpt) {
+ cmpt->prec = siz->comps[compno].prec;
+ cmpt->sgnd = siz->comps[compno].sgnd;
+ cmpt->hstep = siz->comps[compno].hsamp;
+ cmpt->vstep = siz->comps[compno].vsamp;
+ cmpt->width = JPC_CEILDIV(dec->xend, cmpt->hstep) -
+ JPC_CEILDIV(dec->xstart, cmpt->hstep);
+ cmpt->height = JPC_CEILDIV(dec->yend, cmpt->vstep) -
+ JPC_CEILDIV(dec->ystart, cmpt->vstep);
+ cmpt->hsubstep = 0;
+ cmpt->vsubstep = 0;
+ }
+
+ dec->image = 0;
+
+ dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth);
+ dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight);
+ dec->numtiles = dec->numhtiles * dec->numvtiles;
+ if (!(dec->tiles = jas_malloc(dec->numtiles * sizeof(jpc_dec_tile_t)))) {
+ return -1;
+ }
+
+ for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles; ++tileno,
+ ++tile) {
+ htileno = tileno % dec->numhtiles;
+ vtileno = tileno / dec->numhtiles;
+ tile->realmode = 0;
+ tile->state = JPC_TILE_INIT;
+ tile->xstart = JAS_MAX(dec->tilexoff + htileno * dec->tilewidth,
+ dec->xstart);
+ tile->ystart = JAS_MAX(dec->tileyoff + vtileno * dec->tileheight,
+ dec->ystart);
+ tile->xend = JAS_MIN(dec->tilexoff + (htileno + 1) *
+ dec->tilewidth, dec->xend);
+ tile->yend = JAS_MIN(dec->tileyoff + (vtileno + 1) *
+ dec->tileheight, dec->yend);
+ tile->numparts = 0;
+ tile->partno = 0;
+ tile->pkthdrstream = 0;
+ tile->pkthdrstreampos = 0;
+ tile->pptstab = 0;
+ tile->cp = 0;
+ if (!(tile->tcomps = jas_malloc(dec->numcomps *
+ sizeof(jpc_dec_tcomp_t)))) {
+ return -1;
+ }
+ for (compno = 0, cmpt = dec->cmpts, tcomp = tile->tcomps;
+ compno < dec->numcomps; ++compno, ++cmpt, ++tcomp) {
+ tcomp->rlvls = 0;
+ tcomp->data = 0;
+ tcomp->xstart = JPC_CEILDIV(tile->xstart, cmpt->hstep);
+ tcomp->ystart = JPC_CEILDIV(tile->ystart, cmpt->vstep);
+ tcomp->xend = JPC_CEILDIV(tile->xend, cmpt->hstep);
+ tcomp->yend = JPC_CEILDIV(tile->yend, cmpt->vstep);
+ tcomp->tsfb = 0;
+ }
+ }
+
+ dec->pkthdrstreams = 0;
+
+ /* We should expect to encounter other main header marker segments
+ or an SOT marker segment next. */
+ dec->state = JPC_MH;
+
+ return 0;
+}
+
+static int jpc_dec_process_cod(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_cod_t *cod = &ms->parms.cod;
+ jpc_dec_tile_t *tile;
+
+ switch (dec->state) {
+ case JPC_MH:
+ jpc_dec_cp_setfromcod(dec->cp, cod);
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (tile->partno != 0) {
+ return -1;
+ }
+ jpc_dec_cp_setfromcod(tile->cp, cod);
+ break;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_coc(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_coc_t *coc = &ms->parms.coc;
+ jpc_dec_tile_t *tile;
+
+ if (JAS_CAST(int, coc->compno) > dec->numcomps) {
+ fprintf(stderr,
+ "invalid component number in COC marker segment\n");
+ return -1;
+ }
+ switch (dec->state) {
+ case JPC_MH:
+ jpc_dec_cp_setfromcoc(dec->cp, coc);
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (tile->partno > 0) {
+ return -1;
+ }
+ jpc_dec_cp_setfromcoc(tile->cp, coc);
+ break;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_rgn(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_rgn_t *rgn = &ms->parms.rgn;
+ jpc_dec_tile_t *tile;
+
+ if (JAS_CAST(int, rgn->compno) > dec->numcomps) {
+ fprintf(stderr,
+ "invalid component number in RGN marker segment\n");
+ return -1;
+ }
+ switch (dec->state) {
+ case JPC_MH:
+ jpc_dec_cp_setfromrgn(dec->cp, rgn);
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (tile->partno > 0) {
+ return -1;
+ }
+ jpc_dec_cp_setfromrgn(tile->cp, rgn);
+ break;
+ }
+
+ return 0;
+}
+
+static int jpc_dec_process_qcd(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_qcd_t *qcd = &ms->parms.qcd;
+ jpc_dec_tile_t *tile;
+
+ switch (dec->state) {
+ case JPC_MH:
+ jpc_dec_cp_setfromqcd(dec->cp, qcd);
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (tile->partno > 0) {
+ return -1;
+ }
+ jpc_dec_cp_setfromqcd(tile->cp, qcd);
+ break;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_qcc_t *qcc = &ms->parms.qcc;
+ jpc_dec_tile_t *tile;
+
+ if (JAS_CAST(int, qcc->compno) > dec->numcomps) {
+ fprintf(stderr,
+ "invalid component number in QCC marker segment\n");
+ return -1;
+ }
+ switch (dec->state) {
+ case JPC_MH:
+ jpc_dec_cp_setfromqcc(dec->cp, qcc);
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (tile->partno > 0) {
+ return -1;
+ }
+ jpc_dec_cp_setfromqcc(tile->cp, qcc);
+ break;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_poc(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_poc_t *poc = &ms->parms.poc;
+ jpc_dec_tile_t *tile;
+ switch (dec->state) {
+ case JPC_MH:
+ if (jpc_dec_cp_setfrompoc(dec->cp, poc, 1)) {
+ return -1;
+ }
+ break;
+ case JPC_TPH:
+ if (!(tile = dec->curtile)) {
+ return -1;
+ }
+ if (!tile->partno) {
+ if (jpc_dec_cp_setfrompoc(tile->cp, poc, (!tile->partno))) {
+ return -1;
+ }
+ } else {
+ jpc_pi_addpchgfrompoc(tile->pi, poc);
+ }
+ break;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_ppm(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_ppm_t *ppm = &ms->parms.ppm;
+ jpc_ppxstabent_t *ppmstabent;
+
+ if (!dec->ppmstab) {
+ if (!(dec->ppmstab = jpc_ppxstab_create())) {
+ return -1;
+ }
+ }
+
+ if (!(ppmstabent = jpc_ppxstabent_create())) {
+ return -1;
+ }
+ ppmstabent->ind = ppm->ind;
+ ppmstabent->data = ppm->data;
+ ppm->data = 0;
+ ppmstabent->len = ppm->len;
+ if (jpc_ppxstab_insert(dec->ppmstab, ppmstabent)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_ppt(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ jpc_ppt_t *ppt = &ms->parms.ppt;
+ jpc_dec_tile_t *tile;
+ jpc_ppxstabent_t *pptstabent;
+
+ tile = dec->curtile;
+ if (!tile->pptstab) {
+ if (!(tile->pptstab = jpc_ppxstab_create())) {
+ return -1;
+ }
+ }
+ if (!(pptstabent = jpc_ppxstabent_create())) {
+ return -1;
+ }
+ pptstabent->ind = ppt->ind;
+ pptstabent->data = ppt->data;
+ ppt->data = 0;
+ pptstabent->len = ppt->len;
+ if (jpc_ppxstab_insert(tile->pptstab, pptstabent)) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_dec_process_com(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ /* Eliminate compiler warnings about unused variables. */
+ dec = 0;
+ ms = 0;
+
+ return 0;
+}
+
+static int jpc_dec_process_unk(jpc_dec_t *dec, jpc_ms_t *ms)
+{
+ /* Eliminate compiler warnings about unused variables. */
+ dec = 0;
+
+ fprintf(stderr, "warning: ignoring unknown marker segment\n");
+ jpc_ms_dump(ms, stderr);
+ return 0;
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static jpc_dec_cp_t *jpc_dec_cp_create(uint_fast16_t numcomps)
+{
+ jpc_dec_cp_t *cp;
+ jpc_dec_ccp_t *ccp;
+ int compno;
+
+ if (!(cp = jas_malloc(sizeof(jpc_dec_cp_t)))) {
+ return 0;
+ }
+ cp->flags = 0;
+ cp->numcomps = numcomps;
+ cp->prgord = 0;
+ cp->numlyrs = 0;
+ cp->mctid = 0;
+ cp->csty = 0;
+ if (!(cp->ccps = jas_malloc(cp->numcomps * sizeof(jpc_dec_ccp_t)))) {
+ return 0;
+ }
+ if (!(cp->pchglist = jpc_pchglist_create())) {
+ jas_free(cp->ccps);
+ return 0;
+ }
+ for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
+ ++compno, ++ccp) {
+ ccp->flags = 0;
+ ccp->numrlvls = 0;
+ ccp->cblkwidthexpn = 0;
+ ccp->cblkheightexpn = 0;
+ ccp->qmfbid = 0;
+ ccp->numstepsizes = 0;
+ ccp->numguardbits = 0;
+ ccp->roishift = 0;
+ ccp->cblkctx = 0;
+ }
+ return cp;
+}
+
+static jpc_dec_cp_t *jpc_dec_cp_copy(jpc_dec_cp_t *cp)
+{
+ jpc_dec_cp_t *newcp;
+ jpc_dec_ccp_t *newccp;
+ jpc_dec_ccp_t *ccp;
+ int compno;
+
+ if (!(newcp = jpc_dec_cp_create(cp->numcomps))) {
+ return 0;
+ }
+ newcp->flags = cp->flags;
+ newcp->prgord = cp->prgord;
+ newcp->numlyrs = cp->numlyrs;
+ newcp->mctid = cp->mctid;
+ newcp->csty = cp->csty;
+ jpc_pchglist_destroy(newcp->pchglist);
+ newcp->pchglist = 0;
+ if (!(newcp->pchglist = jpc_pchglist_copy(cp->pchglist))) {
+ jas_free(newcp);
+ return 0;
+ }
+ for (compno = 0, newccp = newcp->ccps, ccp = cp->ccps;
+ compno < cp->numcomps;
+ ++compno, ++newccp, ++ccp) {
+ *newccp = *ccp;
+ }
+ return newcp;
+}
+
+static void jpc_dec_cp_resetflags(jpc_dec_cp_t *cp)
+{
+ int compno;
+ jpc_dec_ccp_t *ccp;
+ cp->flags &= (JPC_CSET | JPC_QSET);
+ for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
+ ++compno, ++ccp) {
+ ccp->flags = 0;
+ }
+}
+
+static void jpc_dec_cp_destroy(jpc_dec_cp_t *cp)
+{
+ if (cp->ccps) {
+ jas_free(cp->ccps);
+ }
+ if (cp->pchglist) {
+ jpc_pchglist_destroy(cp->pchglist);
+ }
+ jas_free(cp);
+}
+
+static int jpc_dec_cp_isvalid(jpc_dec_cp_t *cp)
+{
+ uint_fast16_t compcnt;
+ jpc_dec_ccp_t *ccp;
+
+ if (!(cp->flags & JPC_CSET) || !(cp->flags & JPC_QSET)) {
+ return 0;
+ }
+ for (compcnt = cp->numcomps, ccp = cp->ccps; compcnt > 0; --compcnt,
+ ++ccp) {
+ /* Is there enough step sizes for the number of bands? */
+ if ((ccp->qsty != JPC_QCX_SIQNT && JAS_CAST(int, ccp->numstepsizes) < 3 *
+ ccp->numrlvls - 2) || (ccp->qsty == JPC_QCX_SIQNT &&
+ ccp->numstepsizes != 1)) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+static void calcstepsizes(uint_fast16_t refstepsize, int numrlvls,
+ uint_fast16_t *stepsizes)
+{
+ int bandno;
+ int numbands;
+ uint_fast16_t expn;
+ uint_fast16_t mant;
+ expn = JPC_QCX_GETEXPN(refstepsize);
+ mant = JPC_QCX_GETMANT(refstepsize);
+ numbands = 3 * numrlvls - 2;
+ for (bandno = 0; bandno < numbands; ++bandno) {
+ stepsizes[bandno] = JPC_QCX_MANT(mant) | JPC_QCX_EXPN(expn +
+ (numrlvls - 1) - (numrlvls - 1 - ((bandno > 0) ? ((bandno + 2) / 3) : (0))));
+ }
+}
+
+static int jpc_dec_cp_prepare(jpc_dec_cp_t *cp)
+{
+ jpc_dec_ccp_t *ccp;
+ int compno;
+ int i;
+ for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
+ ++compno, ++ccp) {
+ if (!(ccp->csty & JPC_COX_PRT)) {
+ for (i = 0; i < JPC_MAXRLVLS; ++i) {
+ ccp->prcwidthexpns[i] = 15;
+ ccp->prcheightexpns[i] = 15;
+ }
+ }
+ if (ccp->qsty == JPC_QCX_SIQNT) {
+ calcstepsizes(ccp->stepsizes[0], ccp->numrlvls, ccp->stepsizes);
+ }
+ }
+ return 0;
+}
+
+static int jpc_dec_cp_setfromcod(jpc_dec_cp_t *cp, jpc_cod_t *cod)
+{
+ jpc_dec_ccp_t *ccp;
+ int compno;
+ cp->flags |= JPC_CSET;
+ cp->prgord = cod->prg;
+ if (cod->mctrans) {
+ cp->mctid = (cod->compparms.qmfbid == JPC_COX_INS) ? (JPC_MCT_ICT) : (JPC_MCT_RCT);
+ } else {
+ cp->mctid = JPC_MCT_NONE;
+ }
+ cp->numlyrs = cod->numlyrs;
+ cp->csty = cod->csty & (JPC_COD_SOP | JPC_COD_EPH);
+ for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
+ ++compno, ++ccp) {
+ jpc_dec_cp_setfromcox(cp, ccp, &cod->compparms, 0);
+ }
+ cp->flags |= JPC_CSET;
+ return 0;
+}
+
+static int jpc_dec_cp_setfromcoc(jpc_dec_cp_t *cp, jpc_coc_t *coc)
+{
+ jpc_dec_cp_setfromcox(cp, &cp->ccps[coc->compno], &coc->compparms, JPC_COC);
+ return 0;
+}
+
+static int jpc_dec_cp_setfromcox(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp,
+ jpc_coxcp_t *compparms, int flags)
+{
+ int rlvlno;
+
+ /* Eliminate compiler warnings about unused variables. */
+ cp = 0;
+
+ if ((flags & JPC_COC) || !(ccp->flags & JPC_COC)) {
+ ccp->numrlvls = compparms->numdlvls + 1;
+ ccp->cblkwidthexpn = JPC_COX_GETCBLKSIZEEXPN(
+ compparms->cblkwidthval);
+ ccp->cblkheightexpn = JPC_COX_GETCBLKSIZEEXPN(
+ compparms->cblkheightval);
+ ccp->qmfbid = compparms->qmfbid;
+ ccp->cblkctx = compparms->cblksty;
+ ccp->csty = compparms->csty & JPC_COX_PRT;
+ for (rlvlno = 0; rlvlno < compparms->numrlvls; ++rlvlno) {
+ ccp->prcwidthexpns[rlvlno] =
+ compparms->rlvls[rlvlno].parwidthval;
+ ccp->prcheightexpns[rlvlno] =
+ compparms->rlvls[rlvlno].parheightval;
+ }
+ ccp->flags |= flags | JPC_CSET;
+ }
+ return 0;
+}
+
+static int jpc_dec_cp_setfromqcd(jpc_dec_cp_t *cp, jpc_qcd_t *qcd)
+{
+ int compno;
+ jpc_dec_ccp_t *ccp;
+ for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
+ ++compno, ++ccp) {
+ jpc_dec_cp_setfromqcx(cp, ccp, &qcd->compparms, 0);
+ }
+ cp->flags |= JPC_QSET;
+ return 0;
+}
+
+static int jpc_dec_cp_setfromqcc(jpc_dec_cp_t *cp, jpc_qcc_t *qcc)
+{
+ return jpc_dec_cp_setfromqcx(cp, &cp->ccps[qcc->compno], &qcc->compparms, JPC_QCC);
+}
+
+static int jpc_dec_cp_setfromqcx(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp,
+ jpc_qcxcp_t *compparms, int flags)
+{
+ int bandno;
+
+ /* Eliminate compiler warnings about unused variables. */
+ cp = 0;
+
+ if ((flags & JPC_QCC) || !(ccp->flags & JPC_QCC)) {
+ ccp->flags |= flags | JPC_QSET;
+ for (bandno = 0; bandno < compparms->numstepsizes; ++bandno) {
+ ccp->stepsizes[bandno] = compparms->stepsizes[bandno];
+ }
+ ccp->numstepsizes = compparms->numstepsizes;
+ ccp->numguardbits = compparms->numguard;
+ ccp->qsty = compparms->qntsty;
+ }
+ return 0;
+}
+
+static int jpc_dec_cp_setfromrgn(jpc_dec_cp_t *cp, jpc_rgn_t *rgn)
+{
+ jpc_dec_ccp_t *ccp;
+ ccp = &cp->ccps[rgn->compno];
+ ccp->roishift = rgn->roishift;
+ return 0;
+}
+
+static int jpc_pi_addpchgfrompoc(jpc_pi_t *pi, jpc_poc_t *poc)
+{
+ int pchgno;
+ jpc_pchg_t *pchg;
+ for (pchgno = 0; pchgno < poc->numpchgs; ++pchgno) {
+ if (!(pchg = jpc_pchg_copy(&poc->pchgs[pchgno]))) {
+ return -1;
+ }
+ if (jpc_pchglist_insert(pi->pchglist, -1, pchg)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int jpc_dec_cp_setfrompoc(jpc_dec_cp_t *cp, jpc_poc_t *poc, int reset)
+{
+ int pchgno;
+ jpc_pchg_t *pchg;
+ if (reset) {
+ while (jpc_pchglist_numpchgs(cp->pchglist) > 0) {
+ pchg = jpc_pchglist_remove(cp->pchglist, 0);
+ jpc_pchg_destroy(pchg);
+ }
+ }
+ for (pchgno = 0; pchgno < poc->numpchgs; ++pchgno) {
+ if (!(pchg = jpc_pchg_copy(&poc->pchgs[pchgno]))) {
+ return -1;
+ }
+ if (jpc_pchglist_insert(cp->pchglist, -1, pchg)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static jpc_fix_t jpc_calcabsstepsize(int stepsize, int numbits)
+{
+ jpc_fix_t absstepsize;
+ int n;
+
+ absstepsize = jpc_inttofix(1);
+ n = JPC_FIX_FRACBITS - 11;
+ absstepsize |= (n >= 0) ? (JPC_QCX_GETMANT(stepsize) << n) :
+ (JPC_QCX_GETMANT(stepsize) >> (-n));
+ n = numbits - JPC_QCX_GETEXPN(stepsize);
+ absstepsize = (n >= 0) ? (absstepsize << n) : (absstepsize >> (-n));
+ return absstepsize;
+}
+
+static void jpc_dequantize(jas_matrix_t *x, jpc_fix_t absstepsize)
+{
+ int i;
+ int j;
+ int t;
+
+ assert(absstepsize >= 0);
+ if (absstepsize == jpc_inttofix(1)) {
+ return;
+ }
+
+ for (i = 0; i < jas_matrix_numrows(x); ++i) {
+ for (j = 0; j < jas_matrix_numcols(x); ++j) {
+ t = jas_matrix_get(x, i, j);
+ if (t) {
+ t = jpc_fix_mul(t, absstepsize);
+ } else {
+ t = 0;
+ }
+ jas_matrix_set(x, i, j, t);
+ }
+ }
+
+}
+
+static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps)
+{
+ int i;
+ int j;
+ int thresh;
+ jpc_fix_t val;
+ jpc_fix_t mag;
+ bool warn;
+ uint_fast32_t mask;
+
+ if (roishift == 0 && bgshift == 0) {
+ return;
+ }
+ thresh = 1 << roishift;
+
+ warn = false;
+ for (i = 0; i < jas_matrix_numrows(x); ++i) {
+ for (j = 0; j < jas_matrix_numcols(x); ++j) {
+ val = jas_matrix_get(x, i, j);
+ mag = JAS_ABS(val);
+ if (mag >= thresh) {
+ /* We are dealing with ROI data. */
+ mag >>= roishift;
+ val = (val < 0) ? (-mag) : mag;
+ jas_matrix_set(x, i, j, val);
+ } else {
+ /* We are dealing with non-ROI (i.e., background) data. */
+ mag <<= bgshift;
+ mask = (1 << numbps) - 1;
+ /* Perform a basic sanity check on the sample value. */
+ /* Some implementations write garbage in the unused
+ most-significant bit planes introduced by ROI shifting.
+ Here we ensure that any such bits are masked off. */
+ if (mag & (~mask)) {
+ if (!warn) {
+ fprintf(stderr,
+ "warning: possibly corrupt code stream\n");
+ warn = true;
+ }
+ mag &= mask;
+ }
+ val = (val < 0) ? (-mag) : mag;
+ jas_matrix_set(x, i, j, val);
+ }
+ }
+ }
+}
+
+static jpc_dec_t *jpc_dec_create(jpc_dec_importopts_t *impopts, jas_stream_t *in)
+{
+ jpc_dec_t *dec;
+
+ if (!(dec = jas_malloc(sizeof(jpc_dec_t)))) {
+ return 0;
+ }
+
+ dec->image = 0;
+ dec->xstart = 0;
+ dec->ystart = 0;
+ dec->xend = 0;
+ dec->yend = 0;
+ dec->tilewidth = 0;
+ dec->tileheight = 0;
+ dec->tilexoff = 0;
+ dec->tileyoff = 0;
+ dec->numhtiles = 0;
+ dec->numvtiles = 0;
+ dec->numtiles = 0;
+ dec->tiles = 0;
+ dec->curtile = 0;
+ dec->numcomps = 0;
+ dec->in = in;
+ dec->cp = 0;
+ dec->maxlyrs = impopts->maxlyrs;
+ dec->maxpkts = impopts->maxpkts;
+dec->numpkts = 0;
+ dec->ppmseqno = 0;
+ dec->state = 0;
+ dec->cmpts = 0;
+ dec->pkthdrstreams = 0;
+ dec->ppmstab = 0;
+ dec->curtileendoff = 0;
+
+ return dec;
+}
+
+static void jpc_dec_destroy(jpc_dec_t *dec)
+{
+ if (dec->cstate) {
+ jpc_cstate_destroy(dec->cstate);
+ }
+ if (dec->pkthdrstreams) {
+ jpc_streamlist_destroy(dec->pkthdrstreams);
+ }
+ if (dec->image) {
+ jas_image_destroy(dec->image);
+ }
+
+ if (dec->cp) {
+ jpc_dec_cp_destroy(dec->cp);
+ }
+
+ if (dec->cmpts) {
+ jas_free(dec->cmpts);
+ }
+
+ if (dec->tiles) {
+ jas_free(dec->tiles);
+ }
+
+ jas_free(dec);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins, jpc_dec_seg_t *node)
+{
+ jpc_dec_seg_t *prev;
+ jpc_dec_seg_t *next;
+
+ prev = ins;
+ node->prev = prev;
+ next = prev ? (prev->next) : 0;
+ node->prev = prev;
+ node->next = next;
+ if (prev) {
+ prev->next = node;
+ } else {
+ list->head = node;
+ }
+ if (next) {
+ next->prev = node;
+ } else {
+ list->tail = node;
+ }
+}
+
+void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *seg)
+{
+ jpc_dec_seg_t *prev;
+ jpc_dec_seg_t *next;
+
+ prev = seg->prev;
+ next = seg->next;
+ if (prev) {
+ prev->next = next;
+ } else {
+ list->head = next;
+ }
+ if (next) {
+ next->prev = prev;
+ } else {
+ list->tail = prev;
+ }
+ seg->prev = 0;
+ seg->next = 0;
+}
+
+jpc_dec_seg_t *jpc_seg_alloc()
+{
+ jpc_dec_seg_t *seg;
+
+ if (!(seg = jas_malloc(sizeof(jpc_dec_seg_t)))) {
+ return 0;
+ }
+ seg->prev = 0;
+ seg->next = 0;
+ seg->passno = -1;
+ seg->numpasses = 0;
+ seg->maxpasses = 0;
+ seg->type = JPC_SEG_INVALID;
+ seg->stream = 0;
+ seg->cnt = 0;
+ seg->complete = 0;
+ seg->lyrno = -1;
+ return seg;
+}
+
+void jpc_seg_destroy(jpc_dec_seg_t *seg)
+{
+ if (seg->stream) {
+ jas_stream_close(seg->stream);
+ }
+ jas_free(seg);
+}
+
+static int jpc_dec_dump(jpc_dec_t *dec, FILE *out)
+{
+ jpc_dec_tile_t *tile;
+ int tileno;
+ jpc_dec_tcomp_t *tcomp;
+ int compno;
+ jpc_dec_rlvl_t *rlvl;
+ int rlvlno;
+ jpc_dec_band_t *band;
+ int bandno;
+ jpc_dec_prc_t *prc;
+ int prcno;
+ jpc_dec_cblk_t *cblk;
+ int cblkno;
+
+ for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles;
+ ++tileno, ++tile) {
+ for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps;
+ ++compno, ++tcomp) {
+ for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno <
+ tcomp->numrlvls; ++rlvlno, ++rlvl) {
+fprintf(out, "RESOLUTION LEVEL %d\n", rlvlno);
+fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, w = %d, h = %d\n",
+ rlvl->xstart, rlvl->ystart, rlvl->xend, rlvl->yend, rlvl->xend -
+ rlvl->xstart, rlvl->yend - rlvl->ystart);
+ for (bandno = 0, band = rlvl->bands;
+ bandno < rlvl->numbands; ++bandno, ++band) {
+fprintf(out, "BAND %d\n", bandno);
+fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, w = %d, h = %d\n",
+ jas_seq2d_xstart(band->data), jas_seq2d_ystart(band->data), jas_seq2d_xend(band->data),
+ jas_seq2d_yend(band->data), jas_seq2d_xend(band->data) - jas_seq2d_xstart(band->data),
+ jas_seq2d_yend(band->data) - jas_seq2d_ystart(band->data));
+ for (prcno = 0, prc = band->prcs;
+ prcno < rlvl->numprcs; ++prcno,
+ ++prc) {
+fprintf(out, "CODE BLOCK GROUP %d\n", prcno);
+fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, w = %d, h = %d\n",
+ prc->xstart, prc->ystart, prc->xend, prc->yend, prc->xend -
+ prc->xstart, prc->yend - prc->ystart);
+ for (cblkno = 0, cblk =
+ prc->cblks; cblkno <
+ prc->numcblks; ++cblkno,
+ ++cblk) {
+fprintf(out, "CODE BLOCK %d\n", cblkno);
+fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, w = %d, h = %d\n",
+ jas_seq2d_xstart(cblk->data), jas_seq2d_ystart(cblk->data), jas_seq2d_xend(cblk->data),
+ jas_seq2d_yend(cblk->data), jas_seq2d_xend(cblk->data) - jas_seq2d_xstart(cblk->data),
+ jas_seq2d_yend(cblk->data) - jas_seq2d_ystart(cblk->data));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+jpc_streamlist_t *jpc_streamlist_create()
+{
+ jpc_streamlist_t *streamlist;
+ int i;
+
+ if (!(streamlist = jas_malloc(sizeof(jpc_streamlist_t)))) {
+ return 0;
+ }
+ streamlist->numstreams = 0;
+ streamlist->maxstreams = 100;
+ if (!(streamlist->streams = jas_malloc(streamlist->maxstreams *
+ sizeof(jas_stream_t *)))) {
+ jas_free(streamlist);
+ return 0;
+ }
+ for (i = 0; i < streamlist->maxstreams; ++i) {
+ streamlist->streams[i] = 0;
+ }
+ return streamlist;
+}
+
+int jpc_streamlist_insert(jpc_streamlist_t *streamlist, int streamno,
+ jas_stream_t *stream)
+{
+ jas_stream_t **newstreams;
+ int newmaxstreams;
+ int i;
+ /* Grow the array of streams if necessary. */
+ if (streamlist->numstreams >= streamlist->maxstreams) {
+ newmaxstreams = streamlist->maxstreams + 1024;
+ if (!(newstreams = jas_realloc(streamlist->streams,
+ (newmaxstreams + 1024) * sizeof(jas_stream_t *)))) {
+ return -1;
+ }
+ for (i = streamlist->numstreams; i < streamlist->maxstreams; ++i) {
+ streamlist->streams[i] = 0;
+ }
+ streamlist->maxstreams = newmaxstreams;
+ streamlist->streams = newstreams;
+ }
+ if (streamno != streamlist->numstreams) {
+ /* Can only handle insertion at start of list. */
+ return -1;
+ }
+ streamlist->streams[streamno] = stream;
+ ++streamlist->numstreams;
+ return 0;
+}
+
+jas_stream_t *jpc_streamlist_remove(jpc_streamlist_t *streamlist, int streamno)
+{
+ jas_stream_t *stream;
+ int i;
+ if (streamno >= streamlist->numstreams) {
+ abort();
+ }
+ stream = streamlist->streams[streamno];
+ for (i = streamno + 1; i < streamlist->numstreams; ++i) {
+ streamlist->streams[i - 1] = streamlist->streams[i];
+ }
+ --streamlist->numstreams;
+ return stream;
+}
+
+void jpc_streamlist_destroy(jpc_streamlist_t *streamlist)
+{
+ int streamno;
+ if (streamlist->streams) {
+ for (streamno = 0; streamno < streamlist->numstreams;
+ ++streamno) {
+ jas_stream_close(streamlist->streams[streamno]);
+ }
+ jas_free(streamlist->streams);
+ }
+ jas_free(streamlist);
+}
+
+jas_stream_t *jpc_streamlist_get(jpc_streamlist_t *streamlist, int streamno)
+{
+ assert(streamno < streamlist->numstreams);
+ return streamlist->streams[streamno];
+}
+
+int jpc_streamlist_numstreams(jpc_streamlist_t *streamlist)
+{
+ return streamlist->numstreams;
+}
+
+jpc_ppxstab_t *jpc_ppxstab_create()
+{
+ jpc_ppxstab_t *tab;
+
+ if (!(tab = jas_malloc(sizeof(jpc_ppxstab_t)))) {
+ return 0;
+ }
+ tab->numents = 0;
+ tab->maxents = 0;
+ tab->ents = 0;
+ return tab;
+}
+
+void jpc_ppxstab_destroy(jpc_ppxstab_t *tab)
+{
+ int i;
+ for (i = 0; i < tab->numents; ++i) {
+ jpc_ppxstabent_destroy(tab->ents[i]);
+ }
+ if (tab->ents) {
+ jas_free(tab->ents);
+ }
+ jas_free(tab);
+}
+
+int jpc_ppxstab_grow(jpc_ppxstab_t *tab, int maxents)
+{
+ jpc_ppxstabent_t **newents;
+ if (tab->maxents < maxents) {
+ newents = (tab->ents) ? jas_realloc(tab->ents, maxents *
+ sizeof(jpc_ppxstabent_t *)) : jas_malloc(maxents * sizeof(jpc_ppxstabent_t *));
+ if (!newents) {
+ return -1;
+ }
+ tab->ents = newents;
+ tab->maxents = maxents;
+ }
+ return 0;
+}
+
+int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent)
+{
+ int inspt;
+ int i;
+
+ for (i = 0; i < tab->numents; ++i) {
+ if (tab->ents[i]->ind > ent->ind) {
+ break;
+ }
+ }
+ inspt = i;
+
+ if (tab->numents >= tab->maxents) {
+ if (jpc_ppxstab_grow(tab, tab->maxents + 128)) {
+ return -1;
+ }
+ }
+
+ for (i = tab->numents; i > inspt; --i) {
+ tab->ents[i] = tab->ents[i - 1];
+ }
+ tab->ents[i] = ent;
+ ++tab->numents;
+
+ return 0;
+}
+
+jpc_streamlist_t *jpc_ppmstabtostreams(jpc_ppxstab_t *tab)
+{
+ jpc_streamlist_t *streams;
+ uchar *dataptr;
+ uint_fast32_t datacnt;
+ uint_fast32_t tpcnt;
+ jpc_ppxstabent_t *ent;
+ int entno;
+ jas_stream_t *stream;
+ int n;
+
+ if (!(streams = jpc_streamlist_create())) {
+ goto error;
+ }
+
+ if (!tab->numents) {
+ return streams;
+ }
+
+ entno = 0;
+ ent = tab->ents[entno];
+ dataptr = ent->data;
+ datacnt = ent->len;
+ for (;;) {
+
+ /* Get the length of the packet header data for the current
+ tile-part. */
+ if (datacnt < 4) {
+ goto error;
+ }
+ if (!(stream = jas_stream_memopen(0, 0))) {
+ goto error;
+ }
+ if (jpc_streamlist_insert(streams, jpc_streamlist_numstreams(streams),
+ stream)) {
+ goto error;
+ }
+ tpcnt = (dataptr[0] << 24) | (dataptr[1] << 16) | (dataptr[2] << 8)
+ | dataptr[3];
+ datacnt -= 4;
+ dataptr += 4;
+
+ /* Get the packet header data for the current tile-part. */
+ while (tpcnt) {
+ if (!datacnt) {
+ if (++entno >= tab->numents) {
+ goto error;
+ }
+ ent = tab->ents[entno];
+ dataptr = ent->data;
+ datacnt = ent->len;
+ }
+ n = JAS_MIN(tpcnt, datacnt);
+ if (jas_stream_write(stream, dataptr, n) != n) {
+ goto error;
+ }
+ tpcnt -= n;
+ dataptr += n;
+ datacnt -= n;
+ }
+ jas_stream_rewind(stream);
+ if (!datacnt) {
+ if (++entno >= tab->numents) {
+ break;
+ }
+ ent = tab->ents[entno];
+ dataptr = ent->data;
+ datacnt = ent->len;
+ }
+ }
+
+ return streams;
+
+error:
+ jpc_streamlist_destroy(streams);
+ return 0;
+}
+
+int jpc_pptstabwrite(jas_stream_t *out, jpc_ppxstab_t *tab)
+{
+ int i;
+ jpc_ppxstabent_t *ent;
+ for (i = 0; i < tab->numents; ++i) {
+ ent = tab->ents[i];
+ if (jas_stream_write(out, ent->data, ent->len) != JAS_CAST(int, ent->len)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+jpc_ppxstabent_t *jpc_ppxstabent_create()
+{
+ jpc_ppxstabent_t *ent;
+ if (!(ent = jas_malloc(sizeof(jpc_ppxstabent_t)))) {
+ return 0;
+ }
+ ent->data = 0;
+ ent->len = 0;
+ ent->ind = 0;
+ return ent;
+}
+
+void jpc_ppxstabent_destroy(jpc_ppxstabent_t *ent)
+{
+ if (ent->data) {
+ jas_free(ent->data);
+ }
+ jas_free(ent);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_dec.h b/osframework/source/ImageLib/jpeg2000/jpc_dec.h
new file mode 100644
index 0000000..8ef26e5
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_dec.h
@@ -0,0 +1,745 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * JPEG-2000 Decoder
+ *
+ * $Id: jpc_dec.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_DEC_H
+#define JPC_DEC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_stream.h"
+
+#include "jpc_tsfb.h"
+#include "jpc_bs.h"
+#include "jpc_tagtree.h"
+#include "jpc_cs.h"
+#include "jpc_cod.h"
+#include "jpc_mqdec.h"
+#include "jpc_t2cod.h"
+
+/******************************************************************************\
+* Below are some ugly warts necessary to support packed packet headers.
+\******************************************************************************/
+
+/* PPM/PPT marker segment table entry. */
+
+typedef struct {
+
+ /* The index for this entry. */
+ uint_fast16_t ind;
+
+ /* The data length. */
+ uint_fast32_t len;
+
+ /* The data. */
+ uchar *data;
+
+} jpc_ppxstabent_t;
+
+/* PPM/PPT marker segment table. */
+
+typedef struct {
+
+ /* The number of entries. */
+ int numents;
+
+ /* The maximum number of entries (i.e., the allocated size of the array
+ below). */
+ int maxents;
+
+ /* The table entries. */
+ jpc_ppxstabent_t **ents;
+
+} jpc_ppxstab_t;
+
+/* Stream list class. */
+
+typedef struct {
+
+ /* The number of streams in this list. */
+ int numstreams;
+
+ /* The maximum number of streams that can be accomodated without
+ growing the streams array. */
+ int maxstreams;
+
+ /* The streams. */
+ jas_stream_t **streams;
+
+} jpc_streamlist_t;
+
+/******************************************************************************\
+* Coding parameters class.
+\******************************************************************************/
+
+/* Per-component coding parameters. */
+
+typedef struct {
+
+ /* How were various coding parameters set? */
+ int flags;
+
+ /* Per-component coding style parameters (e.g., explicit precinct sizes) */
+ uint_fast8_t csty;
+
+ /* The number of resolution levels. */
+ uint_fast8_t numrlvls;
+
+ /* The code block width exponent. */
+ uint_fast8_t cblkwidthexpn;
+
+ /* The code block height exponent. */
+ uint_fast8_t cblkheightexpn;
+
+ /* The QMFB ID. */
+ uint_fast8_t qmfbid;
+
+ /* The quantization style. */
+ uint_fast8_t qsty;
+
+ /* The number of quantizer step sizes. */
+ uint_fast16_t numstepsizes;
+
+ /* The step sizes. */
+ uint_fast16_t stepsizes[3 * JPC_MAXRLVLS + 1];
+
+ /* The number of guard bits. */
+ uint_fast8_t numguardbits;
+
+ /* The ROI shift value. */
+ uint_fast8_t roishift;
+
+ /* The code block parameters. */
+ uint_fast8_t cblkctx;
+
+ /* The precinct width exponents. */
+ uint_fast8_t prcwidthexpns[JPC_MAXRLVLS];
+
+ /* The precinct height exponents. */
+ uint_fast8_t prcheightexpns[JPC_MAXRLVLS];
+
+} jpc_dec_ccp_t;
+
+/* Coding paramters. */
+
+typedef struct {
+
+ /* How were these coding parameters set? */
+ int flags;
+
+ /* Progression change list. */
+ jpc_pchglist_t *pchglist;
+
+ /* Progression order. */
+ uint_fast8_t prgord;
+
+ /* The number of layers. */
+ uint_fast16_t numlyrs;
+
+ /* The MCT ID. */
+ uint_fast8_t mctid;
+
+ /* The coding style parameters (e.g., SOP, EPH). */
+ uint_fast8_t csty;
+
+ /* The number of components. */
+ int numcomps;
+
+ /* The per-component coding parameters. */
+ jpc_dec_ccp_t *ccps;
+
+} jpc_dec_cp_t;
+
+/******************************************************************************\
+* Decoder class.
+\******************************************************************************/
+
+/* Decoder per-segment state information. */
+
+typedef struct jpc_dec_seg_s {
+
+ /* The next segment in the list. */
+ struct jpc_dec_seg_s *next;
+
+ /* The previous segment in the list. */
+ struct jpc_dec_seg_s *prev;
+
+ /* The starting pass number for this segment. */
+ int passno;
+
+ /* The number of passes in this segment. */
+ int numpasses;
+
+ /* The maximum number of passes in this segment. */
+ int maxpasses;
+
+ /* The type of data in this segment (i.e., MQ or raw). */
+ int type;
+
+ /* A stream containing the data for this segment. */
+ jas_stream_t *stream;
+
+ /* The number of bytes destined for this segment from the packet
+ currently being decoded. */
+ int cnt;
+
+ /* A flag indicating if this segment has been terminated. */
+ int complete;
+
+ /* The layer number to which this segment belongs. */
+ /* If the segment spans multiple layers, then the largest layer number
+ spanned by the segment is used. */
+ int lyrno;
+
+} jpc_dec_seg_t;
+
+/* Decoder segment list. */
+
+typedef struct {
+
+ /* The first entry in the list. */
+ jpc_dec_seg_t *head;
+
+ /* The last entry in the list. */
+ jpc_dec_seg_t *tail;
+
+} jpc_dec_seglist_t;
+
+/* Decoder per-code-block state information. */
+
+typedef struct {
+
+ /* The number of passes. */
+ int numpasses;
+
+ /* A list of segments that still need to be decoded. */
+ jpc_dec_seglist_t segs;
+
+ /* The first incomplete/partial segment. */
+ jpc_dec_seg_t *curseg;
+
+ /* The number of leading insignificant bit planes for this code block. */
+ int numimsbs;
+
+ /* The number of bits used to encode pass data lengths. */
+ int numlenbits;
+
+ /* The first pass number containing data for this code block. */
+ int firstpassno;
+
+ /* The MQ decoder. */
+ jpc_mqdec_t *mqdec;
+
+ /* The raw bit stream decoder. */
+ jpc_bitstream_t *nulldec;
+
+ /* The per-sample state information for this code block. */
+ jas_matrix_t *flags;
+
+ /* The sample data associated with this code block. */
+ jas_matrix_t *data;
+
+} jpc_dec_cblk_t;
+
+/* Decoder per-code-block-group state information. */
+
+typedef struct {
+
+ /* The x-coordinate of the top-left corner of the precinct. */
+ uint_fast32_t xstart;
+
+ /* The y-coordinate of the top-left corner of the precinct. */
+ uint_fast32_t ystart;
+
+ /* The x-coordinate of the bottom-right corner of the precinct
+ (plus one). */
+ uint_fast32_t xend;
+
+ /* The y-coordinate of the bottom-right corner of the precinct
+ (plus one). */
+ uint_fast32_t yend;
+
+ /* The number of code blocks spanning this precinct in the horizontal
+ direction. */
+ int numhcblks;
+
+ /* The number of code blocks spanning this precinct in the vertical
+ direction. */
+ int numvcblks;
+
+ /* The total number of code blocks in this precinct. */
+ int numcblks;
+
+ /* The per code block information. */
+ jpc_dec_cblk_t *cblks;
+
+ /* The inclusion tag tree. */
+ jpc_tagtree_t *incltagtree;
+
+ /* The insignificant MSBs tag tree. */
+ jpc_tagtree_t *numimsbstagtree;
+
+} jpc_dec_prc_t;
+
+/* Decoder per-band state information. */
+
+typedef struct {
+
+ /* The per-code-block-group state information. */
+ jpc_dec_prc_t *prcs;
+
+ /* The sample data associated with this band. */
+ jas_matrix_t *data;
+
+ /* The orientation of this band (i.e., LL, LH, HL, or HH). */
+ int orient;
+
+ /* The encoded quantizer step size. */
+ int stepsize;
+
+ /* The absolute quantizer step size. */
+ jpc_fix_t absstepsize;
+
+ /* The number of bit planes for this band. */
+ int numbps;
+
+ /* The analysis gain associated with this band. */
+ int analgain;
+
+ /* The ROI shift value for this band. */
+ int roishift;
+
+} jpc_dec_band_t;
+
+/* Decoder per-resolution-level state information. */
+
+typedef struct {
+
+ /* The number of bands associated with this resolution level. */
+ int numbands;
+
+ /* The per-band information. */
+ jpc_dec_band_t *bands;
+
+ /* The x-coordinate of the top-left corner of the tile-component
+ at this resolution. */
+ uint_fast32_t xstart;
+
+ /* The y-coordinate of the top-left corner of the tile-component
+ at this resolution. */
+ uint_fast32_t ystart;
+
+ /* The x-coordinate of the bottom-right corner of the tile-component
+ at this resolution (plus one). */
+ uint_fast32_t xend;
+
+ /* The y-coordinate of the bottom-right corner of the tile-component
+ at this resolution (plus one). */
+ uint_fast32_t yend;
+
+ /* The exponent value for the nominal precinct width measured
+ relative to the associated LL band. */
+ int prcwidthexpn;
+
+ /* The exponent value for the nominal precinct height measured
+ relative to the associated LL band. */
+ int prcheightexpn;
+
+ /* The number of precincts in the horizontal direction. */
+ int numhprcs;
+
+ /* The number of precincts in the vertical direction. */
+ int numvprcs;
+
+ /* The total number of precincts. */
+ int numprcs;
+
+ /* The exponent value for the nominal code block group width.
+ This quantity is associated with the next lower resolution level
+ (assuming that there is one). */
+ int cbgwidthexpn;
+
+ /* The exponent value for the nominal code block group height
+ This quantity is associated with the next lower resolution level
+ (assuming that there is one). */
+ int cbgheightexpn;
+
+ /* The exponent value for the code block width. */
+ uint_fast16_t cblkwidthexpn;
+
+ /* The exponent value for the code block height. */
+ uint_fast16_t cblkheightexpn;
+
+} jpc_dec_rlvl_t;
+
+/* Decoder per-tile-component state information. */
+
+typedef struct {
+
+ /* The x-coordinate of the top-left corner of the tile-component
+ in the coordinate system of the tile-component. */
+ uint_fast32_t xstart;
+
+ /* The y-coordinate of the top-left corner of the tile-component
+ in the coordinate system of the tile-component. */
+ uint_fast32_t ystart;
+
+ /* The x-coordinate of the bottom-right corner of the tile-component
+ in the coordinate system of the tile-component (plus one). */
+ uint_fast32_t xend;
+
+ /* The y-coordinate of the bottom-right corner of the tile-component
+ in the coordinate system of the tile-component (plus one). */
+ uint_fast32_t yend;
+
+ /* The component data for the current tile. */
+ jas_matrix_t *data;
+
+ /* The number of resolution levels. */
+ int numrlvls;
+
+ /* The per resolution level information. */
+ jpc_dec_rlvl_t *rlvls;
+
+ /* The TSFB. */
+ jpc_tsfb_t *tsfb;
+
+} jpc_dec_tcomp_t;
+
+/*
+ * Tile states.
+ */
+
+#define JPC_TILE_INIT 0
+#define JPC_TILE_ACTIVE 1
+#define JPC_TILE_ACTIVELAST 2
+#define JPC_TILE_DONE 3
+
+/* Decoder per-tile state information. */
+
+typedef struct {
+
+ /* The processing state for this tile. */
+ int state;
+
+ /* The x-coordinate of the top-left corner of the tile on the reference
+ grid. */
+ uint_fast32_t xstart;
+
+ /* The y-coordinate of the top-left corner of the tile on the reference
+ grid. */
+ uint_fast32_t ystart;
+
+ /* The x-coordinate of the bottom-right corner of the tile on the
+ reference grid (plus one). */
+ uint_fast32_t xend;
+
+ /* The y-coordinate of the bottom-right corner of the tile on the
+ reference grid (plus one). */
+ uint_fast32_t yend;
+
+ /* The packed packet header data for this tile. */
+ jpc_ppxstab_t *pptstab;
+
+ /* A stream containing the packed packet header data for this tile. */
+ jas_stream_t *pkthdrstream;
+
+ /* The current position within the packed packet header stream. */
+ long pkthdrstreampos;
+
+ /* The coding parameters for this tile. */
+ jpc_dec_cp_t *cp;
+
+ /* The per tile-component information. */
+ jpc_dec_tcomp_t *tcomps;
+
+ /* The next expected tile-part number. */
+ int partno;
+
+ /* The number of tile-parts. */
+ int numparts;
+
+ /* The coding mode. */
+ int realmode;
+
+ /* The packet iterator for this tile. */
+ jpc_pi_t *pi;
+
+} jpc_dec_tile_t;
+
+/* Decoder per-component state information. */
+
+typedef struct {
+
+ /* The horizontal sampling period. */
+ uint_fast32_t hstep;
+
+ /* The vertical sampling period. */
+ uint_fast32_t vstep;
+
+ /* The number of samples in the horizontal direction. */
+ uint_fast32_t width;
+
+ /* The number of samples in the vertical direction. */
+ uint_fast32_t height;
+
+ /* The precision of the sample data. */
+ uint_fast16_t prec;
+
+ /* The signedness of the sample data. */
+ bool sgnd;
+
+ /* The sample alignment horizontal offset. */
+ uint_fast32_t hsubstep;
+
+ /* The sample alignment vertical offset. */
+ uint_fast32_t vsubstep;
+
+} jpc_dec_cmpt_t;
+
+/* Decoder state information. */
+
+typedef struct {
+
+ /* The decoded image. */
+ jas_image_t *image;
+
+ /* The x-coordinate of the top-left corner of the image area on
+ the reference grid. */
+ uint_fast32_t xstart;
+
+ /* The y-coordinate of the top-left corner of the image area on
+ the reference grid. */
+ uint_fast32_t ystart;
+
+ /* The x-coordinate of the bottom-right corner of the image area on
+ the reference grid (plus one). */
+ uint_fast32_t xend;
+
+ /* The y-coordinate of the bottom-right corner of the image area on
+ the reference grid (plus one). */
+ uint_fast32_t yend;
+
+ /* The nominal tile width in units of the image reference grid. */
+ uint_fast32_t tilewidth;
+
+ /* The nominal tile height in units of the image reference grid. */
+ uint_fast32_t tileheight;
+
+ /* The horizontal offset from the origin of the reference grid to the
+ left side of the first tile. */
+ uint_fast32_t tilexoff;
+
+ /* The vertical offset from the origin of the reference grid to the
+ top side of the first tile. */
+ uint_fast32_t tileyoff;
+
+ /* The number of tiles spanning the image area in the vertical
+ direction. */
+ int numhtiles;
+
+ /* The number of tiles spanning the image area in the horizontal
+ direction. */
+ int numvtiles;
+
+ /* The total number of tiles. */
+ int numtiles;
+
+ /* The per-tile information. */
+ jpc_dec_tile_t *tiles;
+
+ /* The tile currently being processed. */
+ jpc_dec_tile_t *curtile;
+
+ /* The number of components. */
+ int numcomps;
+
+ /* The stream containing the input JPEG-2000 code stream data. */
+ jas_stream_t *in;
+
+ /* The default coding parameters for all tiles. */
+ jpc_dec_cp_t *cp;
+
+ /* The maximum number of layers that may be decoded. */
+ int maxlyrs;
+
+ /* The maximum number of packets that may be decoded. */
+ int maxpkts;
+
+ /* The number of packets decoded so far in the processing of the entire
+ code stream. */
+ int numpkts;
+
+ /* The next expected PPM marker segment sequence number. */
+ int ppmseqno;
+
+ /* The current state for code stream processing. */
+ int state;
+
+ /* The per-component information. */
+ jpc_dec_cmpt_t *cmpts;
+
+ /* The information from PPM marker segments. */
+ jpc_ppxstab_t *ppmstab;
+
+ /* A list of streams containing packet header data from PPM marker
+ segments. */
+ jpc_streamlist_t *pkthdrstreams;
+
+ /* The expected ending offset for a tile-part. */
+ long curtileendoff;
+
+ /* This is required by the tier-2 decoder. */
+ jpc_cstate_t *cstate;
+
+} jpc_dec_t;
+
+/* Decoder options. */
+
+typedef struct {
+
+ /* The debug level for the decoder. */
+ int debug;
+
+ /* The maximum number of layers to decode. */
+ int maxlyrs;
+
+ /* The maximum number of packets to decode. */
+ int maxpkts;
+
+} jpc_dec_importopts_t;
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Create a decoder segment object. */
+jpc_dec_seg_t *jpc_seg_alloc(void);
+
+/* Destroy a decoder segment object. */
+void jpc_seg_destroy(jpc_dec_seg_t *seg);
+
+/* Remove a segment from a segment list. */
+void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *node);
+
+/* Insert a segment into a segment list. */
+void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins,
+ jpc_dec_seg_t *node);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_enc.c b/osframework/source/ImageLib/jpeg2000/jpc_enc.c
new file mode 100644
index 0000000..7358352
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_enc.c
@@ -0,0 +1,2672 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_enc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <math.h>
+#include <float.h>
+
+#include "jas_string.h"
+#include "jas_malloc.h"
+#include "jas_image.h"
+#include "jas_fix.h"
+#include "jas_tvp.h"
+#include "jas_version.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+
+#include "jpc_flt.h"
+#include "jpc_fix.h"
+#include "jpc_tagtree.h"
+#include "jpc_enc.h"
+#include "jpc_cs.h"
+#include "jpc_mct.h"
+#include "jpc_tsfb.h"
+#include "jpc_qmfb.h"
+#include "jpc_t1enc.h"
+#include "jpc_t2enc.h"
+#include "jpc_cod.h"
+#include "jpc_math.h"
+#include "jpc_util.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+#define JPC_POW2(n) \
+ (1 << (n))
+
+#define JPC_FLOORTOMULTPOW2(x, n) \
+ (((n) > 0) ? ((x) & (~((1 << n) - 1))) : (x))
+/* Round to the nearest multiple of the specified power of two in the
+ direction of negative infinity. */
+
+#define JPC_CEILTOMULTPOW2(x, n) \
+ (((n) > 0) ? JPC_FLOORTOMULTPOW2(((x) + (1 << (n)) - 1), n) : (x))
+/* Round to the nearest multiple of the specified power of two in the
+ direction of positive infinity. */
+
+#define JPC_POW2(n) \
+ (1 << (n))
+
+jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno);
+void jpc_enc_tile_destroy(jpc_enc_tile_t *tile);
+
+static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp,
+ jas_image_t *image, jpc_enc_tile_t *tile);
+static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt);
+static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp,
+ jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos);
+static void rlvl_destroy(jpc_enc_rlvl_t *rlvl);
+static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp,
+ jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos);
+static void band_destroy(jpc_enc_band_t *bands);
+static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp,
+ jpc_enc_band_t *band);
+static void prc_destroy(jpc_enc_prc_t *prcs);
+static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp,
+ jpc_enc_prc_t *prc);
+static void cblk_destroy(jpc_enc_cblk_t *cblks);
+int ratestrtosize(char *s, uint_fast32_t rawsize, uint_fast32_t *size);
+static void pass_destroy(jpc_enc_pass_t *pass);
+void jpc_enc_dump(jpc_enc_t *enc);
+
+/******************************************************************************\
+* Local prototypes.
+\******************************************************************************/
+
+int dump_passes(jpc_enc_pass_t *passes, int numpasses, jpc_enc_cblk_t *cblk);
+void calcrdslopes(jpc_enc_cblk_t *cblk);
+void dump_layeringinfo(jpc_enc_t *enc);
+static int jpc_calcssexp(jpc_fix_t stepsize);
+static int jpc_calcssmant(jpc_fix_t stepsize);
+void quantize(jas_matrix_t *data, jpc_fix_t stepsize);
+static int jpc_enc_encodemainhdr(jpc_enc_t *enc);
+static int jpc_enc_encodemainbody(jpc_enc_t *enc);
+int jpc_enc_encodetiledata(jpc_enc_t *enc);
+jpc_enc_t *jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image);
+void jpc_enc_destroy(jpc_enc_t *enc);
+static int jpc_enc_encodemainhdr(jpc_enc_t *enc);
+static int jpc_enc_encodemainbody(jpc_enc_t *enc);
+int jpc_enc_encodetiledata(jpc_enc_t *enc);
+int rateallocate(jpc_enc_t *enc, int numlyrs, uint_fast32_t *cumlens);
+int setins(int numvalues, jpc_flt_t *values, jpc_flt_t value);
+static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image);
+void jpc_enc_cp_destroy(jpc_enc_cp_t *cp);
+static uint_fast32_t jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn);
+
+static uint_fast32_t jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn)
+{
+ int p;
+ uint_fast32_t mant;
+ uint_fast32_t expn;
+ int n;
+
+ if (absdelta < 0) {
+ abort();
+ }
+
+ p = jpc_firstone(absdelta) - JPC_FIX_FRACBITS;
+ n = 11 - jpc_firstone(absdelta);
+ mant = ((n < 0) ? (absdelta >> (-n)) : (absdelta << n)) & 0x7ff;
+ expn = scaleexpn - p;
+ if (scaleexpn < p) {
+ abort();
+ }
+ return JPC_QCX_EXPN(expn) | JPC_QCX_MANT(mant);
+}
+
+typedef enum {
+ OPT_DEBUG,
+ OPT_IMGAREAOFFX,
+ OPT_IMGAREAOFFY,
+ OPT_TILEGRDOFFX,
+ OPT_TILEGRDOFFY,
+ OPT_TILEWIDTH,
+ OPT_TILEHEIGHT,
+ OPT_PRCWIDTH,
+ OPT_PRCHEIGHT,
+ OPT_CBLKWIDTH,
+ OPT_CBLKHEIGHT,
+ OPT_MODE,
+ OPT_PRG,
+ OPT_NOMCT,
+ OPT_MAXRLVLS,
+ OPT_SOP,
+ OPT_EPH,
+ OPT_LAZY,
+ OPT_TERMALL,
+ OPT_SEGSYM,
+ OPT_VCAUSAL,
+ OPT_RESET,
+ OPT_PTERM,
+ OPT_NUMGBITS,
+ OPT_RATE,
+ OPT_ILYRRATES,
+ OPT_JP2OVERHEAD
+} optid_t;
+
+jas_taginfo_t encopts[] = {
+ {OPT_DEBUG, "debug"},
+ {OPT_IMGAREAOFFX, "imgareatlx"},
+ {OPT_IMGAREAOFFY, "imgareatly"},
+ {OPT_TILEGRDOFFX, "tilegrdtlx"},
+ {OPT_TILEGRDOFFY, "tilegrdtly"},
+ {OPT_TILEWIDTH, "tilewidth"},
+ {OPT_TILEHEIGHT, "tileheight"},
+ {OPT_PRCWIDTH, "prcwidth"},
+ {OPT_PRCHEIGHT, "prcheight"},
+ {OPT_CBLKWIDTH, "cblkwidth"},
+ {OPT_CBLKHEIGHT, "cblkheight"},
+ {OPT_MODE, "mode"},
+ {OPT_PRG, "prg"},
+ {OPT_NOMCT, "nomct"},
+ {OPT_MAXRLVLS, "numrlvls"},
+ {OPT_SOP, "sop"},
+ {OPT_EPH, "eph"},
+ {OPT_LAZY, "lazy"},
+ {OPT_TERMALL, "termall"},
+ {OPT_SEGSYM, "segsym"},
+ {OPT_VCAUSAL, "vcausal"},
+ {OPT_PTERM, "pterm"},
+ {OPT_RESET, "resetprob"},
+ {OPT_NUMGBITS, "numgbits"},
+ {OPT_RATE, "rate"},
+ {OPT_ILYRRATES, "ilyrrates"},
+ {OPT_JP2OVERHEAD, "_jp2overhead"},
+ {-1, 0}
+};
+
+typedef enum {
+ PO_L = 0,
+ PO_R
+} poid_t;
+
+
+jas_taginfo_t prgordtab[] = {
+ {JPC_COD_LRCPPRG, "lrcp"},
+ {JPC_COD_RLCPPRG, "rlcp"},
+ {JPC_COD_RPCLPRG, "rpcl"},
+ {JPC_COD_PCRLPRG, "pcrl"},
+ {JPC_COD_CPRLPRG, "cprl"},
+ {-1, 0}
+};
+
+typedef enum {
+ MODE_INT,
+ MODE_REAL
+} modeid_t;
+
+jas_taginfo_t modetab[] = {
+ {MODE_INT, "int"},
+ {MODE_REAL, "real"},
+ {-1, 0}
+};
+
+/******************************************************************************\
+* The main encoder entry point.
+\******************************************************************************/
+
+int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
+{
+ jpc_enc_t *enc;
+ jpc_enc_cp_t *cp;
+
+ enc = 0;
+ cp = 0;
+
+ jpc_initluts();
+
+ if (!(cp = cp_create(optstr, image))) {
+ fprintf(stderr, "invalid JP encoder options\n");
+ goto error;
+ }
+
+ if (!(enc = jpc_enc_create(cp, out, image))) {
+ goto error;
+ }
+ cp = 0;
+
+ /* Encode the main header. */
+ if (jpc_enc_encodemainhdr(enc)) {
+ goto error;
+ }
+
+ /* Encode the main body. This constitutes most of the encoding work. */
+ if (jpc_enc_encodemainbody(enc)) {
+ goto error;
+ }
+
+ /* Write EOC marker segment. */
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_EOC))) {
+ goto error;
+ }
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write EOI marker\n");
+ goto error;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+ if (jas_stream_flush(enc->out)) {
+ goto error;
+ }
+
+ jpc_enc_destroy(enc);
+
+ return 0;
+
+error:
+ if (cp) {
+ jpc_enc_cp_destroy(cp);
+ }
+ if (enc) {
+ jpc_enc_destroy(enc);
+ }
+ return -1;
+}
+
+/******************************************************************************\
+* Option parsing code.
+\******************************************************************************/
+
+static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image)
+{
+ jpc_enc_cp_t *cp;
+ jas_tvparser_t *tvp;
+ int ret;
+ int numilyrrates;
+ double *ilyrrates;
+ int i;
+ int tagid;
+ jpc_enc_tcp_t *tcp;
+ jpc_enc_tccp_t *tccp;
+ jpc_enc_ccp_t *ccp;
+ int cmptno;
+ uint_fast16_t rlvlno;
+ uint_fast16_t prcwidthexpn;
+ uint_fast16_t prcheightexpn;
+ bool enablemct;
+ uint_fast32_t jp2overhead;
+ uint_fast16_t lyrno;
+ uint_fast32_t hsteplcm;
+ uint_fast32_t vsteplcm;
+ bool mctvalid;
+
+ tvp = 0;
+ cp = 0;
+ ilyrrates = 0;
+ numilyrrates = 0;
+
+ if (!(cp = jas_malloc(sizeof(jpc_enc_cp_t)))) {
+ goto error;
+ }
+
+ prcwidthexpn = 15;
+ prcheightexpn = 15;
+ enablemct = true;
+ jp2overhead = 0;
+
+ cp->ccps = 0;
+ cp->debug = 0;
+ cp->imgareatlx = UINT_FAST32_MAX;
+ cp->imgareatly = UINT_FAST32_MAX;
+ cp->refgrdwidth = 0;
+ cp->refgrdheight = 0;
+ cp->tilegrdoffx = UINT_FAST32_MAX;
+ cp->tilegrdoffy = UINT_FAST32_MAX;
+ cp->tilewidth = 0;
+ cp->tileheight = 0;
+ cp->numcmpts = jas_image_numcmpts(image);
+
+ hsteplcm = 1;
+ vsteplcm = 1;
+ for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) {
+ if (jas_image_cmptbrx(image, cmptno) + jas_image_cmpthstep(image, cmptno) <=
+ jas_image_brx(image) || jas_image_cmptbry(image, cmptno) +
+ jas_image_cmptvstep(image, cmptno) <= jas_image_bry(image)) {
+ fprintf(stderr, "unsupported image type\n");
+ goto error;
+ }
+ /* Note: We ought to be calculating the LCMs here. Fix some day. */
+ hsteplcm *= jas_image_cmpthstep(image, cmptno);
+ vsteplcm *= jas_image_cmptvstep(image, cmptno);
+ }
+
+ if (!(cp->ccps = jas_malloc(cp->numcmpts * sizeof(jpc_enc_ccp_t)))) {
+ goto error;
+ }
+ for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno,
+ ++ccp) {
+ ccp->sampgrdstepx = jas_image_cmpthstep(image, cmptno);
+ ccp->sampgrdstepy = jas_image_cmptvstep(image, cmptno);
+ /* XXX - this isn't quite correct for more general image */
+ ccp->sampgrdsubstepx = 0;
+ ccp->sampgrdsubstepx = 0;
+ ccp->prec = jas_image_cmptprec(image, cmptno);
+ ccp->sgnd = jas_image_cmptsgnd(image, cmptno);
+ ccp->numstepsizes = 0;
+ memset(ccp->stepsizes, 0, sizeof(ccp->stepsizes));
+ }
+
+ cp->rawsize = jas_image_rawsize(image);
+ cp->totalsize = UINT_FAST32_MAX;
+
+ tcp = &cp->tcp;
+ tcp->csty = 0;
+ tcp->intmode = true;
+ tcp->prg = JPC_COD_LRCPPRG;
+ tcp->numlyrs = 1;
+ tcp->ilyrrates = 0;
+
+ tccp = &cp->tccp;
+ tccp->csty = 0;
+ tccp->maxrlvls = 6;
+ tccp->cblkwidthexpn = 6;
+ tccp->cblkheightexpn = 6;
+ tccp->cblksty = 0;
+ tccp->numgbits = 2;
+
+ if (!(tvp = jas_tvparser_create(optstr ? optstr : ""))) {
+ goto error;
+ }
+
+ while (!(ret = jas_tvparser_next(tvp))) {
+ switch (jas_taginfo_nonull(jas_taginfos_lookup(encopts,
+ jas_tvparser_gettag(tvp)))->id) {
+ case OPT_DEBUG:
+ cp->debug = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_IMGAREAOFFX:
+ cp->imgareatlx = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_IMGAREAOFFY:
+ cp->imgareatly = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_TILEGRDOFFX:
+ cp->tilegrdoffx = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_TILEGRDOFFY:
+ cp->tilegrdoffy = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_TILEWIDTH:
+ cp->tilewidth = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_TILEHEIGHT:
+ cp->tileheight = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_PRCWIDTH:
+ prcwidthexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
+ break;
+ case OPT_PRCHEIGHT:
+ prcheightexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
+ break;
+ case OPT_CBLKWIDTH:
+ tccp->cblkwidthexpn =
+ jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
+ break;
+ case OPT_CBLKHEIGHT:
+ tccp->cblkheightexpn =
+ jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
+ break;
+ case OPT_MODE:
+ if ((tagid = jas_taginfo_nonull(jas_taginfos_lookup(modetab,
+ jas_tvparser_getval(tvp)))->id) < 0) {
+ fprintf(stderr,
+ "ignoring invalid mode %s\n",
+ jas_tvparser_getval(tvp));
+ } else {
+ tcp->intmode = (tagid == MODE_INT);
+ }
+ break;
+ case OPT_PRG:
+ if ((tagid = jas_taginfo_nonull(jas_taginfos_lookup(prgordtab,
+ jas_tvparser_getval(tvp)))->id) < 0) {
+ fprintf(stderr,
+ "ignoring invalid progression order %s\n",
+ jas_tvparser_getval(tvp));
+ } else {
+ tcp->prg = tagid;
+ }
+ break;
+ case OPT_NOMCT:
+ enablemct = false;
+ break;
+ case OPT_MAXRLVLS:
+ tccp->maxrlvls = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_SOP:
+ cp->tcp.csty |= JPC_COD_SOP;
+ break;
+ case OPT_EPH:
+ cp->tcp.csty |= JPC_COD_EPH;
+ break;
+ case OPT_LAZY:
+ tccp->cblksty |= JPC_COX_LAZY;
+ break;
+ case OPT_TERMALL:
+ tccp->cblksty |= JPC_COX_TERMALL;
+ break;
+ case OPT_SEGSYM:
+ tccp->cblksty |= JPC_COX_SEGSYM;
+ break;
+ case OPT_VCAUSAL:
+ tccp->cblksty |= JPC_COX_VSC;
+ break;
+ case OPT_RESET:
+ tccp->cblksty |= JPC_COX_RESET;
+ break;
+ case OPT_PTERM:
+ tccp->cblksty |= JPC_COX_PTERM;
+ break;
+ case OPT_NUMGBITS:
+ cp->tccp.numgbits = atoi(jas_tvparser_getval(tvp));
+ break;
+ case OPT_RATE:
+ if (ratestrtosize(jas_tvparser_getval(tvp), cp->rawsize,
+ &cp->totalsize)) {
+ fprintf(stderr,
+ "ignoring bad rate specifier %s\n",
+ jas_tvparser_getval(tvp));
+ }
+ break;
+ case OPT_ILYRRATES:
+ if (jpc_atoaf(jas_tvparser_getval(tvp), &numilyrrates,
+ &ilyrrates)) {
+ fprintf(stderr,
+ "warning: invalid intermediate layer rates specifier ignored (%s)\n",
+ jas_tvparser_getval(tvp));
+ }
+ break;
+
+ case OPT_JP2OVERHEAD:
+ jp2overhead = atoi(jas_tvparser_getval(tvp));
+ break;
+ default:
+ fprintf(stderr, "warning: ignoring invalid option %s\n",
+ jas_tvparser_gettag(tvp));
+ break;
+ }
+ }
+
+ jas_tvparser_destroy(tvp);
+ tvp = 0;
+
+ if (cp->totalsize != UINT_FAST32_MAX) {
+ cp->totalsize = (cp->totalsize > jp2overhead) ?
+ (cp->totalsize - jp2overhead) : 0;
+ }
+
+ if (cp->imgareatlx == UINT_FAST32_MAX) {
+ cp->imgareatlx = 0;
+ } else {
+ if (hsteplcm != 1) {
+ fprintf(stderr, "warning: overriding imgareatlx value\n");
+ }
+ cp->imgareatlx *= hsteplcm;
+ }
+ if (cp->imgareatly == UINT_FAST32_MAX) {
+ cp->imgareatly = 0;
+ } else {
+ if (vsteplcm != 1) {
+ fprintf(stderr, "warning: overriding imgareatly value\n");
+ }
+ cp->imgareatly *= vsteplcm;
+ }
+ cp->refgrdwidth = cp->imgareatlx + jas_image_width(image);
+ cp->refgrdheight = cp->imgareatly + jas_image_height(image);
+ if (cp->tilegrdoffx == UINT_FAST32_MAX) {
+ cp->tilegrdoffx = cp->imgareatlx;
+ }
+ if (cp->tilegrdoffy == UINT_FAST32_MAX) {
+ cp->tilegrdoffy = cp->imgareatly;
+ }
+ if (!cp->tilewidth) {
+ cp->tilewidth = cp->refgrdwidth - cp->tilegrdoffx;
+ }
+ if (!cp->tileheight) {
+ cp->tileheight = cp->refgrdheight - cp->tilegrdoffy;
+ }
+
+ if (cp->numcmpts == 3) {
+ mctvalid = true;
+ for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) {
+ if (jas_image_cmptprec(image, cmptno) != jas_image_cmptprec(image, 0) ||
+ jas_image_cmptsgnd(image, cmptno) != jas_image_cmptsgnd(image, 0) ||
+ jas_image_cmptwidth(image, cmptno) != jas_image_cmptwidth(image, 0) ||
+ jas_image_cmptheight(image, cmptno) != jas_image_cmptheight(image, 0)) {
+ mctvalid = false;
+ }
+ }
+ } else {
+ mctvalid = false;
+ }
+ if (mctvalid && enablemct && jas_clrspc_fam(jas_image_clrspc(image)) != JAS_CLRSPC_FAM_RGB) {
+ fprintf(stderr, "warning: color space apparently not RGB\n");
+ }
+ if (mctvalid && enablemct && jas_clrspc_fam(jas_image_clrspc(image)) == JAS_CLRSPC_FAM_RGB) {
+ tcp->mctid = (tcp->intmode) ? (JPC_MCT_RCT) : (JPC_MCT_ICT);
+ } else {
+ tcp->mctid = JPC_MCT_NONE;
+ }
+ tccp->qmfbid = (tcp->intmode) ? (JPC_COX_RFT) : (JPC_COX_INS);
+
+ for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) {
+ tccp->prcwidthexpns[rlvlno] = prcwidthexpn;
+ tccp->prcheightexpns[rlvlno] = prcheightexpn;
+ }
+ if (prcwidthexpn != 15 || prcheightexpn != 15) {
+ tccp->csty |= JPC_COX_PRT;
+ }
+
+ /* Ensure that the tile width and height is valid. */
+ if (!cp->tilewidth) {
+ fprintf(stderr, "invalid tile width %lu\n", (unsigned long)
+ cp->tilewidth);
+ goto error;
+ }
+ if (!cp->tileheight) {
+ fprintf(stderr, "invalid tile height %lu\n", (unsigned long)
+ cp->tileheight);
+ goto error;
+ }
+
+ /* Ensure that the tile grid offset is valid. */
+ if (cp->tilegrdoffx > cp->imgareatlx ||
+ cp->tilegrdoffy > cp->imgareatly ||
+ cp->tilegrdoffx + cp->tilewidth < cp->imgareatlx ||
+ cp->tilegrdoffy + cp->tileheight < cp->imgareatly) {
+ fprintf(stderr, "invalid tile grid offset (%lu, %lu)\n",
+ (unsigned long) cp->tilegrdoffx, (unsigned long)
+ cp->tilegrdoffy);
+ goto error;
+ }
+
+ cp->numhtiles = JPC_CEILDIV(cp->refgrdwidth - cp->tilegrdoffx,
+ cp->tilewidth);
+ cp->numvtiles = JPC_CEILDIV(cp->refgrdheight - cp->tilegrdoffy,
+ cp->tileheight);
+ cp->numtiles = cp->numhtiles * cp->numvtiles;
+
+ if (ilyrrates && numilyrrates > 0) {
+ tcp->numlyrs = numilyrrates + 1;
+ if (!(tcp->ilyrrates = jas_malloc((tcp->numlyrs - 1) *
+ sizeof(jpc_fix_t)))) {
+ goto error;
+ }
+ for (i = 0; i < JAS_CAST(int, tcp->numlyrs - 1); ++i) {
+ tcp->ilyrrates[i] = jpc_dbltofix(ilyrrates[i]);
+ }
+ }
+
+ /* Ensure that the integer mode is used in the case of lossless
+ coding. */
+ if (cp->totalsize == UINT_FAST32_MAX && (!cp->tcp.intmode)) {
+ fprintf(stderr, "cannot use real mode for lossless coding\n");
+ goto error;
+ }
+
+ /* Ensure that the precinct width is valid. */
+ if (prcwidthexpn > 15) {
+ fprintf(stderr, "invalid precinct width\n");
+ goto error;
+ }
+
+ /* Ensure that the precinct height is valid. */
+ if (prcheightexpn > 15) {
+ fprintf(stderr, "invalid precinct height\n");
+ goto error;
+ }
+
+ /* Ensure that the code block width is valid. */
+ if (cp->tccp.cblkwidthexpn < 2 || cp->tccp.cblkwidthexpn > 12) {
+ fprintf(stderr, "invalid code block width %d\n",
+ JPC_POW2(cp->tccp.cblkwidthexpn));
+ goto error;
+ }
+
+ /* Ensure that the code block height is valid. */
+ if (cp->tccp.cblkheightexpn < 2 || cp->tccp.cblkheightexpn > 12) {
+ fprintf(stderr, "invalid code block height %d\n",
+ JPC_POW2(cp->tccp.cblkheightexpn));
+ goto error;
+ }
+
+ /* Ensure that the code block size is not too large. */
+ if (cp->tccp.cblkwidthexpn + cp->tccp.cblkheightexpn > 12) {
+ fprintf(stderr, "code block size too large\n");
+ goto error;
+ }
+
+ /* Ensure that the number of layers is valid. */
+ if (cp->tcp.numlyrs > 16384) {
+ fprintf(stderr, "too many layers\n");
+ goto error;
+ }
+
+ /* There must be at least one resolution level. */
+ if (cp->tccp.maxrlvls < 1) {
+ fprintf(stderr, "must be at least one resolution level\n");
+ goto error;
+ }
+
+ /* Ensure that the number of guard bits is valid. */
+ if (cp->tccp.numgbits > 8) {
+ fprintf(stderr, "invalid number of guard bits\n");
+ goto error;
+ }
+
+ /* Ensure that the rate is within the legal range. */
+ if (cp->totalsize != UINT_FAST32_MAX && cp->totalsize > cp->rawsize) {
+ fprintf(stderr, "warning: specified rate is unreasonably large (%lu > %lu)\n", (unsigned long) cp->totalsize, (unsigned long) cp->rawsize);
+ }
+
+ /* Ensure that the intermediate layer rates are valid. */
+ if (tcp->numlyrs > 1) {
+ /* The intermediate layers rates must increase monotonically. */
+ for (lyrno = 0; lyrno + 2 < tcp->numlyrs; ++lyrno) {
+ if (tcp->ilyrrates[lyrno] >= tcp->ilyrrates[lyrno + 1]) {
+ fprintf(stderr, "intermediate layer rates must increase monotonically\n");
+ goto error;
+ }
+ }
+ /* The intermediate layer rates must be less than the overall rate. */
+ if (cp->totalsize != UINT_FAST32_MAX) {
+ for (lyrno = 0; lyrno < tcp->numlyrs - 1; ++lyrno) {
+ if (jpc_fixtodbl(tcp->ilyrrates[lyrno]) > ((double) cp->totalsize)
+ / cp->rawsize) {
+ fprintf(stderr, "warning: intermediate layer rates must be less than overall rate\n");
+ goto error;
+ }
+ }
+ }
+ }
+
+ if (ilyrrates) {
+ jas_free(ilyrrates);
+ }
+
+ return cp;
+
+error:
+
+ if (ilyrrates) {
+ jas_free(ilyrrates);
+ }
+ if (tvp) {
+ jas_tvparser_destroy(tvp);
+ }
+ if (cp) {
+ jpc_enc_cp_destroy(cp);
+ }
+ return 0;
+}
+
+void jpc_enc_cp_destroy(jpc_enc_cp_t *cp)
+{
+ if (cp->ccps) {
+ if (cp->tcp.ilyrrates) {
+ jas_free(cp->tcp.ilyrrates);
+ }
+ jas_free(cp->ccps);
+ }
+ jas_free(cp);
+}
+
+int ratestrtosize(char *s, uint_fast32_t rawsize, uint_fast32_t *size)
+{
+ char *cp;
+ jpc_flt_t f;
+
+ /* Note: This function must not modify output size on failure. */
+ if ((cp = strchr(s, 'B'))) {
+ *size = atoi(s);
+ } else {
+ f = atof(s);
+ if (f < 0) {
+ *size = 0;
+ } else if (f > 1.0) {
+ *size = rawsize + 1;
+ } else {
+ *size = f * rawsize;
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Encoder constructor and destructor.
+\******************************************************************************/
+
+jpc_enc_t *jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image)
+{
+ jpc_enc_t *enc;
+
+ enc = 0;
+
+ if (!(enc = jas_malloc(sizeof(jpc_enc_t)))) {
+ goto error;
+ }
+
+ enc->image = image;
+ enc->out = out;
+ enc->cp = cp;
+ enc->cstate = 0;
+ enc->tmpstream = 0;
+ enc->mrk = 0;
+ enc->curtile = 0;
+
+ if (!(enc->cstate = jpc_cstate_create())) {
+ goto error;
+ }
+ enc->len = 0;
+ enc->mainbodysize = 0;
+
+ return enc;
+
+error:
+
+ if (enc) {
+ jpc_enc_destroy(enc);
+ }
+ return 0;
+}
+
+void jpc_enc_destroy(jpc_enc_t *enc)
+{
+ /* The image object (i.e., enc->image) and output stream object
+ (i.e., enc->out) are created outside of the encoder.
+ Therefore, they must not be destroyed here. */
+
+ if (enc->curtile) {
+ jpc_enc_tile_destroy(enc->curtile);
+ }
+ if (enc->cp) {
+ jpc_enc_cp_destroy(enc->cp);
+ }
+ if (enc->cstate) {
+ jpc_cstate_destroy(enc->cstate);
+ }
+ if (enc->tmpstream) {
+ jas_stream_close(enc->tmpstream);
+ }
+
+ jas_free(enc);
+}
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+static int jpc_calcssmant(jpc_fix_t stepsize)
+{
+ int n;
+ int e;
+ int m;
+
+ n = jpc_firstone(stepsize);
+ e = n - JPC_FIX_FRACBITS;
+ if (n >= 11) {
+ m = (stepsize >> (n - 11)) & 0x7ff;
+ } else {
+ m = (stepsize & ((1 << n) - 1)) << (11 - n);
+ }
+ return m;
+}
+
+static int jpc_calcssexp(jpc_fix_t stepsize)
+{
+ return jpc_firstone(stepsize) - JPC_FIX_FRACBITS;
+}
+
+static int jpc_enc_encodemainhdr(jpc_enc_t *enc)
+{
+ jpc_siz_t *siz;
+ jpc_cod_t *cod;
+ jpc_qcd_t *qcd;
+ int i;
+long startoff;
+long mainhdrlen;
+ jpc_enc_cp_t *cp;
+ jpc_qcc_t *qcc;
+ jpc_enc_tccp_t *tccp;
+ uint_fast16_t cmptno;
+ jpc_tsfb_band_t bandinfos[JPC_MAXBANDS];
+ jpc_fix_t mctsynweight;
+ jpc_enc_tcp_t *tcp;
+ jpc_tsfb_t *tsfb;
+ jpc_tsfb_band_t *bandinfo;
+ uint_fast16_t numbands;
+ uint_fast16_t bandno;
+ uint_fast16_t rlvlno;
+ uint_fast16_t analgain;
+ jpc_fix_t absstepsize;
+ char buf[1024];
+ jpc_com_t *com;
+
+ cp = enc->cp;
+
+startoff = jas_stream_getrwcount(enc->out);
+
+ /* Write SOC marker segment. */
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_SOC))) {
+ return -1;
+ }
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write SOC marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+ /* Write SIZ marker segment. */
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_SIZ))) {
+ return -1;
+ }
+ siz = &enc->mrk->parms.siz;
+ siz->caps = 0;
+ siz->xoff = cp->imgareatlx;
+ siz->yoff = cp->imgareatly;
+ siz->width = cp->refgrdwidth;
+ siz->height = cp->refgrdheight;
+ siz->tilexoff = cp->tilegrdoffx;
+ siz->tileyoff = cp->tilegrdoffy;
+ siz->tilewidth = cp->tilewidth;
+ siz->tileheight = cp->tileheight;
+ siz->numcomps = cp->numcmpts;
+ siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t));
+ assert(siz->comps);
+ for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) {
+ siz->comps[i].prec = cp->ccps[i].prec;
+ siz->comps[i].sgnd = cp->ccps[i].sgnd;
+ siz->comps[i].hsamp = cp->ccps[i].sampgrdstepx;
+ siz->comps[i].vsamp = cp->ccps[i].sampgrdstepy;
+ }
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write SIZ marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_COM))) {
+ return -1;
+ }
+ sprintf(buf, "Creator: JasPer Version %s", jas_getversion());
+ com = &enc->mrk->parms.com;
+ com->len = strlen(buf);
+ com->regid = JPC_COM_LATIN;
+ if (!(com->data = JAS_CAST(uchar *, jas_strdup(buf)))) {
+ abort();
+ }
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write COM marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+#if 0
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_CRG))) {
+ return -1;
+ }
+ crg = &enc->mrk->parms.crg;
+ crg->comps = jas_malloc(crg->numcomps * sizeof(jpc_crgcomp_t));
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write CRG marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+#endif
+
+ tcp = &cp->tcp;
+ tccp = &cp->tccp;
+ for (cmptno = 0; cmptno < cp->numcmpts; ++cmptno) {
+ tsfb = jpc_cod_gettsfb(tccp->qmfbid, tccp->maxrlvls - 1);
+ jpc_tsfb_getbands(tsfb, 0, 0, 1 << tccp->maxrlvls, 1 << tccp->maxrlvls,
+ bandinfos);
+ jpc_tsfb_destroy(tsfb);
+ mctsynweight = jpc_mct_getsynweight(tcp->mctid, cmptno);
+ numbands = 3 * tccp->maxrlvls - 2;
+ for (bandno = 0, bandinfo = bandinfos; bandno < numbands;
+ ++bandno, ++bandinfo) {
+ rlvlno = (bandno) ? ((bandno - 1) / 3 + 1) : 0;
+ analgain = JPC_NOMINALGAIN(tccp->qmfbid, tccp->maxrlvls,
+ rlvlno, bandinfo->orient);
+ if (!tcp->intmode) {
+ absstepsize = jpc_fix_div(jpc_inttofix(1 <<
+ (analgain + 1)), bandinfo->synenergywt);
+ } else {
+ absstepsize = jpc_inttofix(1);
+ }
+ cp->ccps[cmptno].stepsizes[bandno] =
+ jpc_abstorelstepsize(absstepsize,
+ cp->ccps[cmptno].prec + analgain);
+ }
+ cp->ccps[cmptno].numstepsizes = numbands;
+ }
+
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_COD))) {
+ return -1;
+ }
+ cod = &enc->mrk->parms.cod;
+ cod->csty = cp->tccp.csty | cp->tcp.csty;
+ cod->compparms.csty = cp->tccp.csty | cp->tcp.csty;
+ cod->compparms.numdlvls = cp->tccp.maxrlvls - 1;
+ cod->compparms.numrlvls = cp->tccp.maxrlvls;
+ cod->prg = cp->tcp.prg;
+ cod->numlyrs = cp->tcp.numlyrs;
+ cod->compparms.cblkwidthval = JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkwidthexpn);
+ cod->compparms.cblkheightval = JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkheightexpn);
+ cod->compparms.cblksty = cp->tccp.cblksty;
+ cod->compparms.qmfbid = cp->tccp.qmfbid;
+ cod->mctrans = (cp->tcp.mctid != JPC_MCT_NONE);
+ if (tccp->csty & JPC_COX_PRT) {
+ for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) {
+ cod->compparms.rlvls[rlvlno].parwidthval = tccp->prcwidthexpns[rlvlno];
+ cod->compparms.rlvls[rlvlno].parheightval = tccp->prcheightexpns[rlvlno];
+ }
+ }
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write COD marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_QCD))) {
+ return -1;
+ }
+ qcd = &enc->mrk->parms.qcd;
+ qcd->compparms.qntsty = (tccp->qmfbid == JPC_COX_INS) ?
+ JPC_QCX_SEQNT : JPC_QCX_NOQNT;
+ qcd->compparms.numstepsizes = cp->ccps[0].numstepsizes;
+ qcd->compparms.numguard = cp->tccp.numgbits;
+ qcd->compparms.stepsizes = cp->ccps[0].stepsizes;
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ return -1;
+ }
+ /* We do not want the step size array to be freed! */
+ qcd->compparms.stepsizes = 0;
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+ tccp = &cp->tccp;
+ for (cmptno = 1; cmptno < cp->numcmpts; ++cmptno) {
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_QCC))) {
+ return -1;
+ }
+ qcc = &enc->mrk->parms.qcc;
+ qcc->compno = cmptno;
+ qcc->compparms.qntsty = (tccp->qmfbid == JPC_COX_INS) ?
+ JPC_QCX_SEQNT : JPC_QCX_NOQNT;
+ qcc->compparms.numstepsizes = cp->ccps[cmptno].numstepsizes;
+ qcc->compparms.numguard = cp->tccp.numgbits;
+ qcc->compparms.stepsizes = cp->ccps[cmptno].stepsizes;
+ if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
+ return -1;
+ }
+ /* We do not want the step size array to be freed! */
+ qcc->compparms.stepsizes = 0;
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+ }
+
+#define MAINTLRLEN 2
+ mainhdrlen = jas_stream_getrwcount(enc->out) - startoff;
+ enc->len += mainhdrlen;
+ if (enc->cp->totalsize != UINT_FAST32_MAX) {
+ uint_fast32_t overhead;
+ overhead = mainhdrlen + MAINTLRLEN;
+ enc->mainbodysize = (enc->cp->totalsize >= overhead) ?
+ (enc->cp->totalsize - overhead) : 0;
+ } else {
+ enc->mainbodysize = UINT_FAST32_MAX;
+ }
+
+ return 0;
+}
+
+static int jpc_enc_encodemainbody(jpc_enc_t *enc)
+{
+ int tileno;
+ int tilex;
+ int tiley;
+ int i;
+ jpc_sot_t *sot;
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_rlvl_t *lvl;
+ int rlvlno;
+ jpc_qcc_t *qcc;
+ jpc_cod_t *cod;
+ int adjust;
+ int j;
+ int absbandno;
+ long numbytes;
+ long tilehdrlen;
+ long tilelen;
+ jpc_enc_tile_t *tile;
+ jpc_enc_cp_t *cp;
+ double rho;
+ int lyrno;
+ int cmptno;
+ int samestepsizes;
+ jpc_enc_ccp_t *ccps;
+ jpc_enc_tccp_t *tccp;
+int bandno;
+uint_fast32_t x;
+uint_fast32_t y;
+int mingbits;
+int actualnumbps;
+jpc_fix_t mxmag;
+jpc_fix_t mag;
+int numgbits;
+
+ cp = enc->cp;
+
+ /* Avoid compile warnings. */
+ numbytes = 0;
+
+ for (tileno = 0; tileno < JAS_CAST(int, cp->numtiles); ++tileno) {
+ tilex = tileno % cp->numhtiles;
+ tiley = tileno / cp->numhtiles;
+
+ if (!(enc->curtile = jpc_enc_tile_create(enc->cp, enc->image, tileno))) {
+ abort();
+ }
+
+ tile = enc->curtile;
+
+ if (jas_getdbglevel() >= 10) {
+ jpc_enc_dump(enc);
+ }
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (cmptno = 0, comp = tile->tcmpts; cmptno < tile->numtcmpts; ++cmptno, ++comp) {
+ if (!cp->ccps[cmptno].sgnd) {
+ adjust = 1 << (cp->ccps[cmptno].prec - 1);
+ for (i = 0; i < jas_matrix_numrows(comp->data); ++i) {
+ for (j = 0; j < jas_matrix_numcols(comp->data); ++j) {
+ *jas_matrix_getref(comp->data, i, j) -= adjust;
+ }
+ }
+ }
+ }
+
+ if (!tile->intmode) {
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ jas_matrix_asl(comp->data, JPC_FIX_FRACBITS);
+ }
+ }
+
+ switch (tile->mctid) {
+ case JPC_MCT_RCT:
+assert(jas_image_numcmpts(enc->image) == 3);
+ jpc_rct(tile->tcmpts[0].data, tile->tcmpts[1].data,
+ tile->tcmpts[2].data);
+ break;
+ case JPC_MCT_ICT:
+assert(jas_image_numcmpts(enc->image) == 3);
+ jpc_ict(tile->tcmpts[0].data, tile->tcmpts[1].data,
+ tile->tcmpts[2].data);
+ break;
+ default:
+ break;
+ }
+
+ for (i = 0; i < jas_image_numcmpts(enc->image); ++i) {
+ comp = &tile->tcmpts[i];
+ jpc_tsfb_analyze(comp->tsfb, ((comp->qmfbid == JPC_COX_RFT) ? JPC_TSFB_RITIMODE : 0), comp->data);
+
+ }
+
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (cmptno = 0, comp = tile->tcmpts; comp != endcomps; ++cmptno, ++comp) {
+ mingbits = 0;
+ absbandno = 0;
+ /* All bands must have a corresponding quantizer step size,
+ even if they contain no samples and are never coded. */
+ /* Some bands may not be hit by the loop below, so we must
+ initialize all of the step sizes to a sane value. */
+ memset(comp->stepsizes, 0, sizeof(comp->stepsizes));
+ for (rlvlno = 0, lvl = comp->rlvls; rlvlno < comp->numrlvls; ++rlvlno, ++lvl) {
+ if (!lvl->bands) {
+ absbandno += rlvlno ? 3 : 1;
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ ++absbandno;
+ continue;
+ }
+ actualnumbps = 0;
+ mxmag = 0;
+ for (y = 0; y < JAS_CAST(uint_fast32_t, jas_matrix_numrows(band->data)); ++y) {
+ for (x = 0; x < JAS_CAST(uint_fast32_t, jas_matrix_numcols(band->data)); ++x) {
+ mag = abs(jas_matrix_get(band->data, y, x));
+ if (mag > mxmag) {
+ mxmag = mag;
+ }
+ }
+ }
+ if (tile->intmode) {
+ actualnumbps = jpc_firstone(mxmag) + 1;
+ } else {
+ actualnumbps = jpc_firstone(mxmag) + 1 - JPC_FIX_FRACBITS;
+ }
+ numgbits = actualnumbps - (cp->ccps[cmptno].prec - 1 +
+ band->analgain);
+#if 0
+fprintf(stderr, "%d %d mag=%d actual=%d numgbits=%d\n", cp->ccps[cmptno].prec, band->analgain, mxmag, actualnumbps, numgbits);
+#endif
+ if (numgbits > mingbits) {
+ mingbits = numgbits;
+ }
+ if (!tile->intmode) {
+ band->absstepsize = jpc_fix_div(jpc_inttofix(1
+ << (band->analgain + 1)),
+ band->synweight);
+ } else {
+ band->absstepsize = jpc_inttofix(1);
+ }
+ band->stepsize = jpc_abstorelstepsize(
+ band->absstepsize, cp->ccps[cmptno].prec +
+ band->analgain);
+ band->numbps = cp->tccp.numgbits +
+ JPC_QCX_GETEXPN(band->stepsize) - 1;
+
+ if ((!tile->intmode) && band->data) {
+ quantize(band->data, band->absstepsize);
+ }
+
+ comp->stepsizes[absbandno] = band->stepsize;
+ ++absbandno;
+ }
+ }
+
+ assert(JPC_FIX_FRACBITS >= JPC_NUMEXTRABITS);
+ if (!tile->intmode) {
+ jas_matrix_divpow2(comp->data, JPC_FIX_FRACBITS - JPC_NUMEXTRABITS);
+ } else {
+ jas_matrix_asl(comp->data, JPC_NUMEXTRABITS);
+ }
+
+#if 0
+fprintf(stderr, "mingbits %d\n", mingbits);
+#endif
+ if (mingbits > cp->tccp.numgbits) {
+ fprintf(stderr, "error: too few guard bits (need at least %d)\n",
+ mingbits);
+ return -1;
+ }
+ }
+
+ if (!(enc->tmpstream = jas_stream_memopen(0, 0))) {
+ fprintf(stderr, "cannot open tmp file\n");
+ return -1;
+ }
+
+ /* Write the tile header. */
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_SOT))) {
+ return -1;
+ }
+ sot = &enc->mrk->parms.sot;
+ sot->len = 0;
+ sot->tileno = tileno;
+ sot->partno = 0;
+ sot->numparts = 1;
+ if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write SOT marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+
+/************************************************************************/
+/************************************************************************/
+/************************************************************************/
+
+ tccp = &cp->tccp;
+ for (cmptno = 0; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno) {
+ comp = &tile->tcmpts[cmptno];
+ if (comp->numrlvls != tccp->maxrlvls) {
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_COD))) {
+ return -1;
+ }
+/* XXX = this is not really correct. we are using comp #0's precint sizes
+and other characteristics */
+ comp = &tile->tcmpts[0];
+ cod = &enc->mrk->parms.cod;
+ cod->compparms.csty = 0;
+ cod->compparms.numdlvls = comp->numrlvls - 1;
+ cod->prg = tile->prg;
+ cod->numlyrs = tile->numlyrs;
+ cod->compparms.cblkwidthval = JPC_COX_CBLKSIZEEXPN(comp->cblkwidthexpn);
+ cod->compparms.cblkheightval = JPC_COX_CBLKSIZEEXPN(comp->cblkheightexpn);
+ cod->compparms.cblksty = comp->cblksty;
+ cod->compparms.qmfbid = comp->qmfbid;
+ cod->mctrans = (tile->mctid != JPC_MCT_NONE);
+ for (i = 0; i < comp->numrlvls; ++i) {
+ cod->compparms.rlvls[i].parwidthval = comp->rlvls[i].prcwidthexpn;
+ cod->compparms.rlvls[i].parheightval = comp->rlvls[i].prcheightexpn;
+ }
+ if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) {
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+ }
+ }
+
+ for (cmptno = 0, comp = tile->tcmpts; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno, ++comp) {
+ ccps = &cp->ccps[cmptno];
+ if (JAS_CAST(int, ccps->numstepsizes) == comp->numstepsizes) {
+ samestepsizes = 1;
+ for (bandno = 0; bandno < JAS_CAST(int, ccps->numstepsizes); ++bandno) {
+ if (ccps->stepsizes[bandno] != comp->stepsizes[bandno]) {
+ samestepsizes = 0;
+ break;
+ }
+ }
+ } else {
+ samestepsizes = 0;
+ }
+ if (!samestepsizes) {
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_QCC))) {
+ return -1;
+ }
+ qcc = &enc->mrk->parms.qcc;
+ qcc->compno = cmptno;
+ qcc->compparms.numguard = cp->tccp.numgbits;
+ qcc->compparms.qntsty = (comp->qmfbid == JPC_COX_INS) ?
+ JPC_QCX_SEQNT : JPC_QCX_NOQNT;
+ qcc->compparms.numstepsizes = comp->numstepsizes;
+ qcc->compparms.stepsizes = comp->stepsizes;
+ if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) {
+ return -1;
+ }
+ qcc->compparms.stepsizes = 0;
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+ }
+ }
+
+ /* Write a SOD marker to indicate the end of the tile header. */
+ if (!(enc->mrk = jpc_ms_create(JPC_MS_SOD))) {
+ return -1;
+ }
+ if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) {
+ fprintf(stderr, "cannot write SOD marker\n");
+ return -1;
+ }
+ jpc_ms_destroy(enc->mrk);
+ enc->mrk = 0;
+tilehdrlen = jas_stream_getrwcount(enc->tmpstream);
+
+/************************************************************************/
+/************************************************************************/
+/************************************************************************/
+
+if (jpc_enc_enccblks(enc)) {
+ abort();
+ return -1;
+}
+
+ cp = enc->cp;
+ rho = (double) (tile->brx - tile->tlx) * (tile->bry - tile->tly) /
+ ((cp->refgrdwidth - cp->imgareatlx) * (cp->refgrdheight -
+ cp->imgareatly));
+ tile->rawsize = cp->rawsize * rho;
+
+ for (lyrno = 0; lyrno < tile->numlyrs - 1; ++lyrno) {
+ tile->lyrsizes[lyrno] = tile->rawsize * jpc_fixtodbl(
+ cp->tcp.ilyrrates[lyrno]);
+ }
+ tile->lyrsizes[tile->numlyrs - 1] = (cp->totalsize != UINT_FAST32_MAX) ?
+ (rho * enc->mainbodysize) : UINT_FAST32_MAX;
+ for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) {
+ if (tile->lyrsizes[lyrno] != UINT_FAST32_MAX) {
+ if (tilehdrlen <= JAS_CAST(long, tile->lyrsizes[lyrno])) {
+ tile->lyrsizes[lyrno] -= tilehdrlen;
+ } else {
+ tile->lyrsizes[lyrno] = 0;
+ }
+ }
+ }
+
+ if (rateallocate(enc, tile->numlyrs, tile->lyrsizes)) {
+ return -1;
+ }
+
+#if 0
+fprintf(stderr, "ENCODE TILE DATA\n");
+#endif
+ if (jpc_enc_encodetiledata(enc)) {
+ fprintf(stderr, "dotile failed\n");
+ return -1;
+ }
+
+/************************************************************************/
+/************************************************************************/
+/************************************************************************/
+
+/************************************************************************/
+/************************************************************************/
+/************************************************************************/
+
+ tilelen = jas_stream_tell(enc->tmpstream);
+
+ if (jas_stream_seek(enc->tmpstream, 6, SEEK_SET) < 0) {
+ return -1;
+ }
+ jpc_putuint32(enc->tmpstream, tilelen);
+
+ if (jas_stream_seek(enc->tmpstream, 0, SEEK_SET) < 0) {
+ return -1;
+ }
+ if (jpc_putdata(enc->out, enc->tmpstream, -1)) {
+ return -1;
+ }
+ enc->len += tilelen;
+
+ jas_stream_close(enc->tmpstream);
+ enc->tmpstream = 0;
+
+ jpc_enc_tile_destroy(enc->curtile);
+ enc->curtile = 0;
+
+ }
+
+ return 0;
+}
+
+int jpc_enc_encodetiledata(jpc_enc_t *enc)
+{
+assert(enc->tmpstream);
+ if (jpc_enc_encpkts(enc, enc->tmpstream)) {
+ return -1;
+ }
+ return 0;
+}
+
+int dump_passes(jpc_enc_pass_t *passes, int numpasses, jpc_enc_cblk_t *cblk)
+{
+ jpc_enc_pass_t *pass;
+ int i;
+ jas_stream_memobj_t *smo;
+
+ smo = cblk->stream->obj_;
+
+ pass = passes;
+ for (i = 0; i < numpasses; ++i) {
+ fprintf(stderr, "start=%d end=%d type=%d term=%d lyrno=%d firstchar=%02x size=%ld pos=%ld\n",
+ (int)pass->start, (int)pass->end, (int)pass->type, (int)pass->term, (int)pass->lyrno,
+ smo->buf_[pass->start], (long)smo->len_, (long)smo->pos_);
+#if 0
+ jas_memdump(stderr, &smo->buf_[pass->start], pass->end - pass->start);
+#endif
+ ++pass;
+ }
+ return 0;
+}
+
+void quantize(jas_matrix_t *data, jpc_fix_t stepsize)
+{
+ int i;
+ int j;
+ jpc_fix_t t;
+
+ if (stepsize == jpc_inttofix(1)) {
+ return;
+ }
+
+ for (i = 0; i < jas_matrix_numrows(data); ++i) {
+ for (j = 0; j < jas_matrix_numcols(data); ++j) {
+ t = jas_matrix_get(data, i, j);
+
+{
+ if (t < 0) {
+ t = jpc_fix_neg(jpc_fix_div(jpc_fix_neg(t), stepsize));
+ } else {
+ t = jpc_fix_div(t, stepsize);
+ }
+}
+
+ jas_matrix_set(data, i, j, t);
+ }
+ }
+}
+
+void calcrdslopes(jpc_enc_cblk_t *cblk)
+{
+ jpc_enc_pass_t *endpasses;
+ jpc_enc_pass_t *pass0;
+ jpc_enc_pass_t *pass1;
+ jpc_enc_pass_t *pass2;
+ jpc_flt_t slope0;
+ jpc_flt_t slope;
+ jpc_flt_t dd;
+ long dr;
+
+ endpasses = &cblk->passes[cblk->numpasses];
+ pass2 = cblk->passes;
+ slope0 = 0;
+ while (pass2 != endpasses) {
+ pass0 = 0;
+ for (pass1 = cblk->passes; pass1 != endpasses; ++pass1) {
+ dd = pass1->cumwmsedec;
+ dr = pass1->end;
+ if (pass0) {
+ dd -= pass0->cumwmsedec;
+ dr -= pass0->end;
+ }
+ if (dd <= 0) {
+ pass1->rdslope = JPC_BADRDSLOPE;
+ if (pass1 >= pass2) {
+ pass2 = &pass1[1];
+ }
+ continue;
+ }
+ if (pass1 < pass2 && pass1->rdslope <= 0) {
+ continue;
+ }
+ if (!dr) {
+ assert(pass0);
+ pass0->rdslope = 0;
+ break;
+ }
+ slope = dd / dr;
+ if (pass0 && slope >= slope0) {
+ pass0->rdslope = 0;
+ break;
+ }
+ pass1->rdslope = slope;
+ if (pass1 >= pass2) {
+ pass2 = &pass1[1];
+ }
+ pass0 = pass1;
+ slope0 = slope;
+ }
+ }
+
+#if 0
+ for (pass0 = cblk->passes; pass0 != endpasses; ++pass0) {
+if (pass0->rdslope > 0.0) {
+ fprintf(stderr, "pass %02d nmsedec=%lf dec=%lf end=%d %lf\n", pass0 - cblk->passes,
+ fixtodbl(pass0->nmsedec), pass0->wmsedec, pass0->end, pass0->rdslope);
+}
+ }
+#endif
+}
+
+void dump_layeringinfo(jpc_enc_t *enc)
+{
+
+ jpc_enc_tcmpt_t *tcmpt;
+ int tcmptno;
+ jpc_enc_rlvl_t *rlvl;
+ int rlvlno;
+ jpc_enc_band_t *band;
+ int bandno;
+ jpc_enc_prc_t *prc;
+ int prcno;
+ jpc_enc_cblk_t *cblk;
+ int cblkno;
+ jpc_enc_pass_t *pass;
+ int passno;
+ int lyrno;
+ jpc_enc_tile_t *tile;
+
+ tile = enc->curtile;
+
+ for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) {
+ fprintf(stderr, "lyrno = %02d\n", lyrno);
+ for (tcmptno = 0, tcmpt = tile->tcmpts; tcmptno < tile->numtcmpts;
+ ++tcmptno, ++tcmpt) {
+ for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
+ ++rlvlno, ++rlvl) {
+ if (!rlvl->bands) {
+ continue;
+ }
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs;
+ ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ for (cblkno = 0, cblk = prc->cblks; cblkno <
+ prc->numcblks; ++cblkno, ++cblk) {
+ for (passno = 0, pass = cblk->passes; passno <
+ cblk->numpasses && pass->lyrno == lyrno;
+ ++passno, ++pass) {
+ fprintf(stderr, "lyrno=%02d cmptno=%02d rlvlno=%02d bandno=%02d prcno=%02d cblkno=%03d passno=%03d\n", lyrno, tcmptno, rlvlno, bandno, prcno, cblkno, passno);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+int rateallocate(jpc_enc_t *enc, int numlyrs, uint_fast32_t *cumlens)
+{
+ jpc_flt_t lo;
+ jpc_flt_t hi;
+ jas_stream_t *out;
+ long cumlen;
+ int lyrno;
+ jpc_flt_t thresh;
+ jpc_flt_t goodthresh;
+ int success;
+ long pos;
+ long oldpos;
+ int numiters;
+
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_rlvl_t *endlvls;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ jpc_enc_pass_t *pass;
+ jpc_enc_pass_t *endpasses;
+ jpc_enc_pass_t *pass1;
+ jpc_flt_t mxrdslope;
+ jpc_flt_t mnrdslope;
+ jpc_enc_tile_t *tile;
+ jpc_enc_prc_t *prc;
+ int prcno;
+
+ tile = enc->curtile;
+
+ for (lyrno = 1; lyrno < numlyrs - 1; ++lyrno) {
+ if (cumlens[lyrno - 1] > cumlens[lyrno]) {
+ abort();
+ }
+ }
+
+ if (!(out = jas_stream_memopen(0, 0))) {
+ return -1;
+ }
+
+
+ /* Find minimum and maximum R-D slope values. */
+ mnrdslope = DBL_MAX;
+ mxrdslope = 0;
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ calcrdslopes(cblk);
+ endpasses = &cblk->passes[cblk->numpasses];
+ for (pass = cblk->passes; pass != endpasses; ++pass) {
+ if (pass->rdslope > 0) {
+ if (pass->rdslope < mnrdslope) {
+ mnrdslope = pass->rdslope;
+ }
+ if (pass->rdslope > mxrdslope) {
+ mxrdslope = pass->rdslope;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+if (jas_getdbglevel()) {
+ fprintf(stderr, "min rdslope = %f max rdslope = %f\n", mnrdslope, mxrdslope);
+}
+
+ jpc_init_t2state(enc, 1);
+
+ for (lyrno = 0; lyrno < numlyrs; ++lyrno) {
+
+ lo = mnrdslope;
+ hi = mxrdslope;
+
+ success = 0;
+ goodthresh = 0;
+ numiters = 0;
+
+ do {
+
+ cumlen = cumlens[lyrno];
+ if (cumlen == UINT_FAST32_MAX) {
+ /* Only the last layer can be free of a rate
+ constraint (e.g., for lossless coding). */
+ assert(lyrno == numlyrs - 1);
+ goodthresh = -1;
+ success = 1;
+ break;
+ }
+
+ thresh = (lo + hi) / 2;
+
+ /* Save the tier 2 coding state. */
+ jpc_save_t2state(enc);
+ oldpos = jas_stream_tell(out);
+ assert(oldpos >= 0);
+
+ /* Assign all passes with R-D slopes greater than or
+ equal to the current threshold to this layer. */
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ if (cblk->curpass) {
+ endpasses = &cblk->passes[cblk->numpasses];
+ pass1 = cblk->curpass;
+ for (pass = cblk->curpass; pass != endpasses; ++pass) {
+ if (pass->rdslope >= thresh) {
+ pass1 = &pass[1];
+ }
+ }
+ for (pass = cblk->curpass; pass != pass1; ++pass) {
+ pass->lyrno = lyrno;
+ }
+ for (; pass != endpasses; ++pass) {
+ pass->lyrno = -1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Perform tier 2 coding. */
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ for (prcno = 0; prcno < lvl->numprcs; ++prcno) {
+ if (jpc_enc_encpkt(enc, out, comp - tile->tcmpts, lvl - comp->rlvls, prcno, lyrno)) {
+ return -1;
+ }
+ }
+ }
+ }
+
+ pos = jas_stream_tell(out);
+
+ /* Check the rate constraint. */
+ assert(pos >= 0);
+ if (pos > cumlen) {
+ /* The rate is too high. */
+ lo = thresh;
+ } else if (pos <= cumlen) {
+ /* The rate is low enough, so try higher. */
+ hi = thresh;
+ if (!success || thresh < goodthresh) {
+ goodthresh = thresh;
+ success = 1;
+ }
+ }
+
+ /* Save the tier 2 coding state. */
+ jpc_restore_t2state(enc);
+ if (jas_stream_seek(out, oldpos, SEEK_SET) < 0) {
+ abort();
+ }
+
+if (jas_getdbglevel()) {
+fprintf(stderr, "maxlen=%08ld actuallen=%08ld thresh=%f\n", cumlen, pos, thresh);
+}
+
+ ++numiters;
+ } while (lo < hi - 1e-3 && numiters < 32);
+
+ if (!success) {
+ fprintf(stderr, "warning: empty layer generated\n");
+ }
+
+if (jas_getdbglevel()) {
+fprintf(stderr, "success %d goodthresh %f\n", success, goodthresh);
+}
+
+ /* Assign all passes with R-D slopes greater than or
+ equal to the selected threshold to this layer. */
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+if (!lvl->bands) {
+ continue;
+}
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ if (cblk->curpass) {
+ endpasses = &cblk->passes[cblk->numpasses];
+ pass1 = cblk->curpass;
+ if (success) {
+ for (pass = cblk->curpass; pass != endpasses; ++pass) {
+ if (pass->rdslope >= goodthresh) {
+ pass1 = &pass[1];
+ }
+ }
+ }
+ for (pass = cblk->curpass; pass != pass1; ++pass) {
+ pass->lyrno = lyrno;
+ }
+ for (; pass != endpasses; ++pass) {
+ pass->lyrno = -1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Perform tier 2 coding. */
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ for (prcno = 0; prcno < lvl->numprcs; ++prcno) {
+ if (jpc_enc_encpkt(enc, out, comp - tile->tcmpts, lvl - comp->rlvls, prcno, lyrno)) {
+ return -1;
+ }
+ }
+ }
+ }
+ }
+
+ if (jas_getdbglevel() >= 5) {
+ dump_layeringinfo(enc);
+ }
+
+ jas_stream_close(out);
+
+ JAS_DBGLOG(10, ("done doing rateallocation\n"));
+#if 0
+fprintf(stderr, "DONE RATE ALLOCATE\n");
+#endif
+
+ return 0;
+}
+
+/******************************************************************************\
+* Tile constructors and destructors.
+\******************************************************************************/
+
+jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno)
+{
+ jpc_enc_tile_t *tile;
+ uint_fast32_t htileno;
+ uint_fast32_t vtileno;
+ uint_fast16_t lyrno;
+ uint_fast16_t cmptno;
+ jpc_enc_tcmpt_t *tcmpt;
+
+ if (!(tile = jas_malloc(sizeof(jpc_enc_tile_t)))) {
+ goto error;
+ }
+
+ /* Initialize a few members used in error recovery. */
+ tile->tcmpts = 0;
+ tile->lyrsizes = 0;
+ tile->numtcmpts = cp->numcmpts;
+ tile->pi = 0;
+
+ tile->tileno = tileno;
+ htileno = tileno % cp->numhtiles;
+ vtileno = tileno / cp->numhtiles;
+
+ /* Calculate the coordinates of the top-left and bottom-right
+ corners of the tile. */
+ tile->tlx = JAS_MAX(cp->tilegrdoffx + htileno * cp->tilewidth,
+ cp->imgareatlx);
+ tile->tly = JAS_MAX(cp->tilegrdoffy + vtileno * cp->tileheight,
+ cp->imgareatly);
+ tile->brx = JAS_MIN(cp->tilegrdoffx + (htileno + 1) * cp->tilewidth,
+ cp->refgrdwidth);
+ tile->bry = JAS_MIN(cp->tilegrdoffy + (vtileno + 1) * cp->tileheight,
+ cp->refgrdheight);
+
+ /* Initialize some tile coding parameters. */
+ tile->intmode = cp->tcp.intmode;
+ tile->csty = cp->tcp.csty;
+ tile->prg = cp->tcp.prg;
+ tile->mctid = cp->tcp.mctid;
+
+ tile->numlyrs = cp->tcp.numlyrs;
+ if (!(tile->lyrsizes = jas_malloc(tile->numlyrs *
+ sizeof(uint_fast32_t)))) {
+ goto error;
+ }
+ for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) {
+ tile->lyrsizes[lyrno] = 0;
+ }
+
+ /* Allocate an array for the per-tile-component information. */
+ if (!(tile->tcmpts = jas_malloc(cp->numcmpts * sizeof(jpc_enc_tcmpt_t)))) {
+ goto error;
+ }
+ /* Initialize a few members critical for error recovery. */
+ for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts;
+ ++cmptno, ++tcmpt) {
+ tcmpt->rlvls = 0;
+ tcmpt->tsfb = 0;
+ tcmpt->data = 0;
+ }
+ /* Initialize the per-tile-component information. */
+ for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts;
+ ++cmptno, ++tcmpt) {
+ if (!tcmpt_create(tcmpt, cp, image, tile)) {
+ goto error;
+ }
+ }
+
+ /* Initialize the synthesis weights for the MCT. */
+ switch (tile->mctid) {
+ case JPC_MCT_RCT:
+ tile->tcmpts[0].synweight = jpc_dbltofix(sqrt(3.0));
+ tile->tcmpts[1].synweight = jpc_dbltofix(sqrt(0.6875));
+ tile->tcmpts[2].synweight = jpc_dbltofix(sqrt(0.6875));
+ break;
+ case JPC_MCT_ICT:
+ tile->tcmpts[0].synweight = jpc_dbltofix(sqrt(3.0000));
+ tile->tcmpts[1].synweight = jpc_dbltofix(sqrt(3.2584));
+ tile->tcmpts[2].synweight = jpc_dbltofix(sqrt(2.4755));
+ break;
+ default:
+ case JPC_MCT_NONE:
+ for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts;
+ ++cmptno, ++tcmpt) {
+ tcmpt->synweight = JPC_FIX_ONE;
+ }
+ break;
+ }
+
+ if (!(tile->pi = jpc_enc_pi_create(cp, tile))) {
+ goto error;
+ }
+
+ return tile;
+
+error:
+
+ if (tile) {
+ jpc_enc_tile_destroy(tile);
+ }
+ return 0;
+}
+
+void jpc_enc_tile_destroy(jpc_enc_tile_t *tile)
+{
+ jpc_enc_tcmpt_t *tcmpt;
+ uint_fast16_t cmptno;
+
+ if (tile->tcmpts) {
+ for (cmptno = 0, tcmpt = tile->tcmpts; cmptno <
+ tile->numtcmpts; ++cmptno, ++tcmpt) {
+ tcmpt_destroy(tcmpt);
+ }
+ jas_free(tile->tcmpts);
+ }
+ if (tile->lyrsizes) {
+ jas_free(tile->lyrsizes);
+ }
+ if (tile->pi) {
+ jpc_pi_destroy(tile->pi);
+ }
+ jas_free(tile);
+}
+
+static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp,
+ jas_image_t *image, jpc_enc_tile_t *tile)
+{
+ uint_fast16_t cmptno;
+ uint_fast16_t rlvlno;
+ jpc_enc_rlvl_t *rlvl;
+ uint_fast32_t tlx;
+ uint_fast32_t tly;
+ uint_fast32_t brx;
+ uint_fast32_t bry;
+ uint_fast32_t cmpttlx;
+ uint_fast32_t cmpttly;
+ jpc_enc_ccp_t *ccp;
+ jpc_tsfb_band_t bandinfos[JPC_MAXBANDS];
+
+ tcmpt->tile = tile;
+ tcmpt->tsfb = 0;
+ tcmpt->data = 0;
+ tcmpt->rlvls = 0;
+
+ /* Deduce the component number. */
+ cmptno = tcmpt - tile->tcmpts;
+
+ ccp = &cp->ccps[cmptno];
+
+ /* Compute the coordinates of the top-left and bottom-right
+ corners of this tile-component. */
+ tlx = JPC_CEILDIV(tile->tlx, ccp->sampgrdstepx);
+ tly = JPC_CEILDIV(tile->tly, ccp->sampgrdstepy);
+ brx = JPC_CEILDIV(tile->brx, ccp->sampgrdstepx);
+ bry = JPC_CEILDIV(tile->bry, ccp->sampgrdstepy);
+
+ /* Create a sequence to hold the tile-component sample data. */
+ if (!(tcmpt->data = jas_seq2d_create(tlx, tly, brx, bry))) {
+ goto error;
+ }
+
+ /* Get the image data associated with this tile-component. */
+ cmpttlx = JPC_CEILDIV(cp->imgareatlx, ccp->sampgrdstepx);
+ cmpttly = JPC_CEILDIV(cp->imgareatly, ccp->sampgrdstepy);
+ if (jas_image_readcmpt(image, cmptno, tlx - cmpttlx, tly - cmpttly,
+ brx - tlx, bry - tly, tcmpt->data)) {
+ goto error;
+ }
+
+ tcmpt->synweight = 0;
+ tcmpt->qmfbid = cp->tccp.qmfbid;
+ tcmpt->numrlvls = cp->tccp.maxrlvls;
+ tcmpt->numbands = 3 * tcmpt->numrlvls - 2;
+ if (!(tcmpt->tsfb = jpc_cod_gettsfb(tcmpt->qmfbid, tcmpt->numrlvls - 1))) {
+ goto error;
+ }
+
+ for (rlvlno = 0; rlvlno < tcmpt->numrlvls; ++rlvlno) {
+ tcmpt->prcwidthexpns[rlvlno] = cp->tccp.prcwidthexpns[rlvlno];
+ tcmpt->prcheightexpns[rlvlno] = cp->tccp.prcheightexpns[rlvlno];
+ }
+ tcmpt->cblkwidthexpn = cp->tccp.cblkwidthexpn;
+ tcmpt->cblkheightexpn = cp->tccp.cblkheightexpn;
+ tcmpt->cblksty = cp->tccp.cblksty;
+ tcmpt->csty = cp->tccp.csty;
+
+ tcmpt->numstepsizes = tcmpt->numbands;
+ assert(tcmpt->numstepsizes <= JPC_MAXBANDS);
+ memset(tcmpt->stepsizes, 0, sizeof(tcmpt->numstepsizes *
+ sizeof(uint_fast16_t)));
+
+ /* Retrieve information about the various bands. */
+ jpc_tsfb_getbands(tcmpt->tsfb, jas_seq2d_xstart(tcmpt->data),
+ jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data),
+ jas_seq2d_yend(tcmpt->data), bandinfos);
+
+ if (!(tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)))) {
+ goto error;
+ }
+ for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
+ ++rlvlno, ++rlvl) {
+ rlvl->bands = 0;
+ rlvl->tcmpt = tcmpt;
+ }
+ for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
+ ++rlvlno, ++rlvl) {
+ if (!rlvl_create(rlvl, cp, tcmpt, bandinfos)) {
+ goto error;
+ }
+ }
+
+ return tcmpt;
+
+error:
+
+ tcmpt_destroy(tcmpt);
+ return 0;
+
+}
+
+static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt)
+{
+ jpc_enc_rlvl_t *rlvl;
+ uint_fast16_t rlvlno;
+
+ if (tcmpt->rlvls) {
+ for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
+ ++rlvlno, ++rlvl) {
+ rlvl_destroy(rlvl);
+ }
+ jas_free(tcmpt->rlvls);
+ }
+
+ if (tcmpt->data) {
+ jas_seq2d_destroy(tcmpt->data);
+ }
+ if (tcmpt->tsfb) {
+ jpc_tsfb_destroy(tcmpt->tsfb);
+ }
+}
+
+static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp,
+ jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos)
+{
+ uint_fast16_t rlvlno;
+ uint_fast32_t tlprctlx;
+ uint_fast32_t tlprctly;
+ uint_fast32_t brprcbrx;
+ uint_fast32_t brprcbry;
+ uint_fast16_t bandno;
+ jpc_enc_band_t *band;
+
+ /* Deduce the resolution level. */
+ rlvlno = rlvl - tcmpt->rlvls;
+
+ /* Initialize members required for error recovery. */
+ rlvl->bands = 0;
+ rlvl->tcmpt = tcmpt;
+
+ /* Compute the coordinates of the top-left and bottom-right
+ corners of the tile-component at this resolution. */
+ rlvl->tlx = JPC_CEILDIVPOW2(jas_seq2d_xstart(tcmpt->data), tcmpt->numrlvls -
+ 1 - rlvlno);
+ rlvl->tly = JPC_CEILDIVPOW2(jas_seq2d_ystart(tcmpt->data), tcmpt->numrlvls -
+ 1 - rlvlno);
+ rlvl->brx = JPC_CEILDIVPOW2(jas_seq2d_xend(tcmpt->data), tcmpt->numrlvls -
+ 1 - rlvlno);
+ rlvl->bry = JPC_CEILDIVPOW2(jas_seq2d_yend(tcmpt->data), tcmpt->numrlvls -
+ 1 - rlvlno);
+
+ if (rlvl->tlx >= rlvl->brx || rlvl->tly >= rlvl->bry) {
+ rlvl->numhprcs = 0;
+ rlvl->numvprcs = 0;
+ rlvl->numprcs = 0;
+ return rlvl;
+ }
+
+ rlvl->numbands = (!rlvlno) ? 1 : 3;
+ rlvl->prcwidthexpn = cp->tccp.prcwidthexpns[rlvlno];
+ rlvl->prcheightexpn = cp->tccp.prcheightexpns[rlvlno];
+ if (!rlvlno) {
+ rlvl->cbgwidthexpn = rlvl->prcwidthexpn;
+ rlvl->cbgheightexpn = rlvl->prcheightexpn;
+ } else {
+ rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1;
+ rlvl->cbgheightexpn = rlvl->prcheightexpn - 1;
+ }
+ rlvl->cblkwidthexpn = JAS_MIN(cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn);
+ rlvl->cblkheightexpn = JAS_MIN(cp->tccp.cblkheightexpn, rlvl->cbgheightexpn);
+
+ /* Compute the number of precincts. */
+ tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn);
+ tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn);
+ brprcbrx = JPC_CEILTOMULTPOW2(rlvl->brx, rlvl->prcwidthexpn);
+ brprcbry = JPC_CEILTOMULTPOW2(rlvl->bry, rlvl->prcheightexpn);
+ rlvl->numhprcs = JPC_FLOORDIVPOW2(brprcbrx - tlprctlx, rlvl->prcwidthexpn);
+ rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn);
+ rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs;
+
+ if (!(rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)))) {
+ goto error;
+ }
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ band->prcs = 0;
+ band->data = 0;
+ band->rlvl = rlvl;
+ }
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ if (!band_create(band, cp, rlvl, bandinfos)) {
+ goto error;
+ }
+ }
+
+ return rlvl;
+error:
+
+ rlvl_destroy(rlvl);
+ return 0;
+}
+
+static void rlvl_destroy(jpc_enc_rlvl_t *rlvl)
+{
+ jpc_enc_band_t *band;
+ uint_fast16_t bandno;
+
+ if (rlvl->bands) {
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ band_destroy(band);
+ }
+ jas_free(rlvl->bands);
+ }
+}
+
+static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp,
+ jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos)
+{
+ uint_fast16_t bandno;
+ uint_fast16_t gblbandno;
+ uint_fast16_t rlvlno;
+ jpc_tsfb_band_t *bandinfo;
+ jpc_enc_tcmpt_t *tcmpt;
+ uint_fast32_t prcno;
+ jpc_enc_prc_t *prc;
+
+ tcmpt = rlvl->tcmpt;
+ band->data = 0;
+ band->prcs = 0;
+ band->rlvl = rlvl;
+
+ /* Deduce the resolution level and band number. */
+ rlvlno = rlvl - rlvl->tcmpt->rlvls;
+ bandno = band - rlvl->bands;
+ gblbandno = (!rlvlno) ? 0 : (3 * (rlvlno - 1) + bandno + 1);
+
+ bandinfo = &bandinfos[gblbandno];
+
+if (bandinfo->xstart != bandinfo->xend && bandinfo->ystart != bandinfo->yend) {
+ if (!(band->data = jas_seq2d_create(0, 0, 0, 0))) {
+ goto error;
+ }
+ jas_seq2d_bindsub(band->data, tcmpt->data, bandinfo->locxstart,
+ bandinfo->locystart, bandinfo->locxend, bandinfo->locyend);
+ jas_seq2d_setshift(band->data, bandinfo->xstart, bandinfo->ystart);
+}
+ band->orient = bandinfo->orient;
+ band->analgain = JPC_NOMINALGAIN(cp->tccp.qmfbid, tcmpt->numrlvls, rlvlno,
+ band->orient);
+ band->numbps = 0;
+ band->absstepsize = 0;
+ band->stepsize = 0;
+ band->synweight = bandinfo->synenergywt;
+
+if (band->data) {
+ if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)))) {
+ goto error;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno,
+ ++prc) {
+ prc->cblks = 0;
+ prc->incltree = 0;
+ prc->nlibtree = 0;
+ prc->savincltree = 0;
+ prc->savnlibtree = 0;
+ prc->band = band;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno,
+ ++prc) {
+ if (!prc_create(prc, cp, band)) {
+ goto error;
+ }
+ }
+}
+
+ return band;
+
+error:
+ band_destroy(band);
+ return 0;
+}
+
+static void band_destroy(jpc_enc_band_t *band)
+{
+ jpc_enc_prc_t *prc;
+ jpc_enc_rlvl_t *rlvl;
+ uint_fast32_t prcno;
+
+ if (band->prcs) {
+ rlvl = band->rlvl;
+ for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs;
+ ++prcno, ++prc) {
+ prc_destroy(prc);
+ }
+ jas_free(band->prcs);
+ }
+ if (band->data) {
+ jas_seq2d_destroy(band->data);
+ }
+}
+
+static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_band_t *band)
+{
+ uint_fast32_t prcno;
+ uint_fast32_t prcxind;
+ uint_fast32_t prcyind;
+ uint_fast32_t cbgtlx;
+ uint_fast32_t cbgtly;
+ uint_fast32_t tlprctlx;
+ uint_fast32_t tlprctly;
+ uint_fast32_t tlcbgtlx;
+ uint_fast32_t tlcbgtly;
+ uint_fast16_t rlvlno;
+ jpc_enc_rlvl_t *rlvl;
+ uint_fast32_t tlcblktlx;
+ uint_fast32_t tlcblktly;
+ uint_fast32_t brcblkbrx;
+ uint_fast32_t brcblkbry;
+ uint_fast32_t cblkno;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_tcmpt_t *tcmpt;
+
+ prc->cblks = 0;
+ prc->incltree = 0;
+ prc->savincltree = 0;
+ prc->nlibtree = 0;
+ prc->savnlibtree = 0;
+
+ rlvl = band->rlvl;
+ tcmpt = rlvl->tcmpt;
+rlvlno = rlvl - tcmpt->rlvls;
+ prcno = prc - band->prcs;
+ prcxind = prcno % rlvl->numhprcs;
+ prcyind = prcno / rlvl->numhprcs;
+ prc->band = band;
+
+tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn);
+tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn);
+if (!rlvlno) {
+ tlcbgtlx = tlprctlx;
+ tlcbgtly = tlprctly;
+} else {
+ tlcbgtlx = JPC_CEILDIVPOW2(tlprctlx, 1);
+ tlcbgtly = JPC_CEILDIVPOW2(tlprctly, 1);
+}
+
+ /* Compute the coordinates of the top-left and bottom-right
+ corners of the precinct. */
+ cbgtlx = tlcbgtlx + (prcxind << rlvl->cbgwidthexpn);
+ cbgtly = tlcbgtly + (prcyind << rlvl->cbgheightexpn);
+ prc->tlx = JAS_MAX(jas_seq2d_xstart(band->data), cbgtlx);
+ prc->tly = JAS_MAX(jas_seq2d_ystart(band->data), cbgtly);
+ prc->brx = JAS_MIN(jas_seq2d_xend(band->data), cbgtlx +
+ (1 << rlvl->cbgwidthexpn));
+ prc->bry = JAS_MIN(jas_seq2d_yend(band->data), cbgtly +
+ (1 << rlvl->cbgheightexpn));
+
+ if (prc->tlx < prc->brx && prc->tly < prc->bry) {
+ /* The precinct contains at least one code block. */
+
+ tlcblktlx = JPC_FLOORTOMULTPOW2(prc->tlx, rlvl->cblkwidthexpn);
+ tlcblktly = JPC_FLOORTOMULTPOW2(prc->tly, rlvl->cblkheightexpn);
+ brcblkbrx = JPC_CEILTOMULTPOW2(prc->brx, rlvl->cblkwidthexpn);
+ brcblkbry = JPC_CEILTOMULTPOW2(prc->bry, rlvl->cblkheightexpn);
+ prc->numhcblks = JPC_FLOORDIVPOW2(brcblkbrx - tlcblktlx,
+ rlvl->cblkwidthexpn);
+ prc->numvcblks = JPC_FLOORDIVPOW2(brcblkbry - tlcblktly,
+ rlvl->cblkheightexpn);
+ prc->numcblks = prc->numhcblks * prc->numvcblks;
+
+ if (!(prc->incltree = jpc_tagtree_create(prc->numhcblks,
+ prc->numvcblks))) {
+ goto error;
+ }
+ if (!(prc->nlibtree = jpc_tagtree_create(prc->numhcblks,
+ prc->numvcblks))) {
+ goto error;
+ }
+ if (!(prc->savincltree = jpc_tagtree_create(prc->numhcblks,
+ prc->numvcblks))) {
+ goto error;
+ }
+ if (!(prc->savnlibtree = jpc_tagtree_create(prc->numhcblks,
+ prc->numvcblks))) {
+ goto error;
+ }
+
+ if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)))) {
+ goto error;
+ }
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ cblk->passes = 0;
+ cblk->stream = 0;
+ cblk->mqenc = 0;
+ cblk->data = 0;
+ cblk->flags = 0;
+ cblk->prc = prc;
+ }
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ if (!cblk_create(cblk, cp, prc)) {
+ goto error;
+ }
+ }
+ } else {
+ /* The precinct does not contain any code blocks. */
+ prc->tlx = prc->brx;
+ prc->tly = prc->bry;
+ prc->numcblks = 0;
+ prc->numhcblks = 0;
+ prc->numvcblks = 0;
+ prc->cblks = 0;
+ prc->incltree = 0;
+ prc->nlibtree = 0;
+ prc->savincltree = 0;
+ prc->savnlibtree = 0;
+ }
+
+ return prc;
+
+error:
+ prc_destroy(prc);
+ return 0;
+}
+
+static void prc_destroy(jpc_enc_prc_t *prc)
+{
+ jpc_enc_cblk_t *cblk;
+ uint_fast32_t cblkno;
+
+ if (prc->cblks) {
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ cblk_destroy(cblk);
+ }
+ jas_free(prc->cblks);
+ }
+ if (prc->incltree) {
+ jpc_tagtree_destroy(prc->incltree);
+ }
+ if (prc->nlibtree) {
+ jpc_tagtree_destroy(prc->nlibtree);
+ }
+ if (prc->savincltree) {
+ jpc_tagtree_destroy(prc->savincltree);
+ }
+ if (prc->savnlibtree) {
+ jpc_tagtree_destroy(prc->savnlibtree);
+ }
+}
+
+static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_enc_prc_t *prc)
+{
+ jpc_enc_band_t *band;
+ uint_fast32_t cblktlx;
+ uint_fast32_t cblktly;
+ uint_fast32_t cblkbrx;
+ uint_fast32_t cblkbry;
+ jpc_enc_rlvl_t *rlvl;
+ uint_fast32_t cblkxind;
+ uint_fast32_t cblkyind;
+ uint_fast32_t cblkno;
+ uint_fast32_t tlcblktlx;
+ uint_fast32_t tlcblktly;
+
+ cblkno = cblk - prc->cblks;
+ cblkxind = cblkno % prc->numhcblks;
+ cblkyind = cblkno / prc->numhcblks;
+ rlvl = prc->band->rlvl;
+ cblk->prc = prc;
+
+ cblk->numpasses = 0;
+ cblk->passes = 0;
+ cblk->numencpasses = 0;
+ cblk->numimsbs = 0;
+ cblk->numlenbits = 0;
+ cblk->stream = 0;
+ cblk->mqenc = 0;
+ cblk->flags = 0;
+ cblk->numbps = 0;
+ cblk->curpass = 0;
+ cblk->data = 0;
+ cblk->savedcurpass = 0;
+ cblk->savednumlenbits = 0;
+ cblk->savednumencpasses = 0;
+
+ band = prc->band;
+ tlcblktlx = JPC_FLOORTOMULTPOW2(prc->tlx, rlvl->cblkwidthexpn);
+ tlcblktly = JPC_FLOORTOMULTPOW2(prc->tly, rlvl->cblkheightexpn);
+ cblktlx = JAS_MAX(tlcblktlx + (cblkxind << rlvl->cblkwidthexpn), prc->tlx);
+ cblktly = JAS_MAX(tlcblktly + (cblkyind << rlvl->cblkheightexpn), prc->tly);
+ cblkbrx = JAS_MIN(tlcblktlx + ((cblkxind + 1) << rlvl->cblkwidthexpn),
+ prc->brx);
+ cblkbry = JAS_MIN(tlcblktly + ((cblkyind + 1) << rlvl->cblkheightexpn),
+ prc->bry);
+
+ assert(cblktlx < cblkbrx && cblktly < cblkbry);
+ if (!(cblk->data = jas_seq2d_create(0, 0, 0, 0))) {
+ goto error;
+ }
+ jas_seq2d_bindsub(cblk->data, band->data, cblktlx, cblktly, cblkbrx, cblkbry);
+
+ return cblk;
+
+error:
+ cblk_destroy(cblk);
+ return 0;
+}
+
+static void cblk_destroy(jpc_enc_cblk_t *cblk)
+{
+ uint_fast16_t passno;
+ jpc_enc_pass_t *pass;
+ if (cblk->passes) {
+ for (passno = 0, pass = cblk->passes; passno < cblk->numpasses;
+ ++passno, ++pass) {
+ pass_destroy(pass);
+ }
+ jas_free(cblk->passes);
+ }
+ if (cblk->stream) {
+ jas_stream_close(cblk->stream);
+ }
+ if (cblk->mqenc) {
+ jpc_mqenc_destroy(cblk->mqenc);
+ }
+ if (cblk->data) {
+ jas_seq2d_destroy(cblk->data);
+ }
+ if (cblk->flags) {
+ jas_seq2d_destroy(cblk->flags);
+ }
+}
+
+static void pass_destroy(jpc_enc_pass_t *pass)
+{
+ /* XXX - need to free resources here */
+}
+
+void jpc_enc_dump(jpc_enc_t *enc)
+{
+ jpc_enc_tile_t *tile;
+ jpc_enc_tcmpt_t *tcmpt;
+ jpc_enc_rlvl_t *rlvl;
+ jpc_enc_band_t *band;
+ jpc_enc_prc_t *prc;
+ jpc_enc_cblk_t *cblk;
+ uint_fast16_t cmptno;
+ uint_fast16_t rlvlno;
+ uint_fast16_t bandno;
+ uint_fast32_t prcno;
+ uint_fast32_t cblkno;
+
+ tile = enc->curtile;
+
+ for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < tile->numtcmpts; ++cmptno,
+ ++tcmpt) {
+ fprintf(stderr, " tcmpt %5d %5d %5d %5d\n", jas_seq2d_xstart(tcmpt->data), jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), jas_seq2d_yend(tcmpt->data));
+ for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
+ ++rlvlno, ++rlvl) {
+ fprintf(stderr, " rlvl %5d %5d %5d %5d\n", rlvl->tlx, rlvl->tly, rlvl->brx, rlvl->bry);
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ fprintf(stderr, " band %5d %5d %5d %5d\n", jas_seq2d_xstart(band->data), jas_seq2d_ystart(band->data), jas_seq2d_xend(band->data), jas_seq2d_yend(band->data));
+ for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs;
+ ++prcno, ++prc) {
+ fprintf(stderr, " prc %5d %5d %5d %5d (%5d %5d)\n", prc->tlx, prc->tly, prc->brx, prc->bry, prc->brx - prc->tlx, prc->bry - prc->tly);
+ if (!prc->cblks) {
+ continue;
+ }
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ fprintf(stderr, " cblk %5d %5d %5d %5d\n", jas_seq2d_xstart(cblk->data), jas_seq2d_ystart(cblk->data), jas_seq2d_xend(cblk->data), jas_seq2d_yend(cblk->data));
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_enc.h b/osframework/source/ImageLib/jpeg2000/jpc_enc.h
new file mode 100644
index 0000000..0f9e191
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_enc.h
@@ -0,0 +1,695 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_enc.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_ENC_H
+#define JPC_ENC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_seq.h"
+
+#include "jpc_t2cod.h"
+#include "jpc_mqenc.h"
+#include "jpc_cod.h"
+#include "jpc_tagtree.h"
+#include "jpc_cs.h"
+#include "jpc_flt.h"
+#include "jpc_tsfb.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* The number of bits used in various lookup tables. */
+#define JPC_NUMEXTRABITS JPC_NMSEDEC_FRACBITS
+
+/* An invalid R-D slope value. */
+#define JPC_BADRDSLOPE (-1)
+
+/******************************************************************************\
+* Coding parameters types.
+\******************************************************************************/
+
+/* Per-component coding paramters. */
+
+typedef struct {
+
+ /* The horizontal sampling period. */
+ uint_fast8_t sampgrdstepx;
+
+ /* The vertical sampling period. */
+ uint_fast8_t sampgrdstepy;
+
+ /* The sample alignment horizontal offset. */
+ uint_fast8_t sampgrdsubstepx;
+
+ /* The sample alignment vertical offset. */
+ uint_fast8_t sampgrdsubstepy;
+
+ /* The precision of the samples. */
+ uint_fast8_t prec;
+
+ /* The signedness of the samples. */
+ bool sgnd;
+
+ /* The number of step sizes. */
+ uint_fast16_t numstepsizes;
+
+ /* The quantizer step sizes. */
+ uint_fast16_t stepsizes[JPC_MAXBANDS];
+
+} jpc_enc_ccp_t;
+
+/* Per-tile coding parameters. */
+
+typedef struct {
+
+ /* The coding mode. */
+ bool intmode;
+
+ /* The coding style (i.e., SOP, EPH). */
+ uint_fast8_t csty;
+
+ /* The progression order. */
+ uint_fast8_t prg;
+
+ /* The multicomponent transform. */
+ uint_fast8_t mctid;
+
+ /* The number of layers. */
+ uint_fast16_t numlyrs;
+
+ /* The normalized bit rates associated with the various
+ intermediate layers. */
+ jpc_fix_t *ilyrrates;
+
+} jpc_enc_tcp_t;
+
+/* Per tile-component coding parameters. */
+
+typedef struct {
+
+ /* The coding style (i.e., explicit precinct sizes). */
+ uint_fast8_t csty;
+
+ /* The maximum number of resolution levels allowed. */
+ uint_fast8_t maxrlvls;
+
+ /* The exponent for the nominal code block width. */
+ uint_fast16_t cblkwidthexpn;
+
+ /* The exponent for the nominal code block height. */
+ uint_fast16_t cblkheightexpn;
+
+ /* The code block style parameters (e.g., lazy, terminate all,
+ segmentation symbols, causal, reset probability models). */
+ uint_fast8_t cblksty;
+
+ /* The QMFB. */
+ uint_fast8_t qmfbid;
+
+ /* The precinct width values. */
+ uint_fast16_t prcwidthexpns[JPC_MAXRLVLS];
+
+ /* The precinct height values. */
+ uint_fast16_t prcheightexpns[JPC_MAXRLVLS];
+
+ /* The number of guard bits. */
+ uint_fast8_t numgbits;
+
+} jpc_enc_tccp_t;
+
+/* Coding parameters. */
+
+typedef struct {
+
+ /* The debug level. */
+ int debug;
+
+ /* The horizontal offset from the origin of the reference grid to the
+ left edge of the image area. */
+ uint_fast32_t imgareatlx;
+
+ /* The vertical offset from the origin of the reference grid to the
+ top edge of the image area. */
+ uint_fast32_t imgareatly;
+
+ /* The horizontal offset from the origin of the reference grid to the
+ right edge of the image area (plus one). */
+ uint_fast32_t refgrdwidth;
+
+ /* The vertical offset from the origin of the reference grid to the
+ bottom edge of the image area (plus one). */
+ uint_fast32_t refgrdheight;
+
+ /* The horizontal offset from the origin of the tile grid to the
+ origin of the reference grid. */
+ uint_fast32_t tilegrdoffx;
+
+ /* The vertical offset from the origin of the tile grid to the
+ origin of the reference grid. */
+ uint_fast32_t tilegrdoffy;
+
+ /* The nominal tile width in units of the image reference grid. */
+ uint_fast32_t tilewidth;
+
+ /* The nominal tile height in units of the image reference grid. */
+ uint_fast32_t tileheight;
+
+ /* The number of tiles spanning the image area in the horizontal
+ direction. */
+ uint_fast32_t numhtiles;
+
+ /* The number of tiles spanning the image area in the vertical
+ direction. */
+ uint_fast32_t numvtiles;
+
+ /* The number of tiles. */
+ uint_fast32_t numtiles;
+
+ /* The number of components. */
+ uint_fast16_t numcmpts;
+
+ /* The per-component coding parameters. */
+ jpc_enc_ccp_t *ccps;
+
+ /* The per-tile coding parameters. */
+ jpc_enc_tcp_t tcp;
+
+ /* The per-tile-component coding parameters. */
+ jpc_enc_tccp_t tccp;
+
+ /* The target code stream length in bytes. */
+ uint_fast32_t totalsize;
+
+ /* The raw (i.e., uncompressed) size of the image in bytes. */
+ uint_fast32_t rawsize;
+
+} jpc_enc_cp_t;
+
+/******************************************************************************\
+* Encoder class.
+\******************************************************************************/
+
+/* Encoder per-coding-pass state information. */
+
+typedef struct {
+
+ /* The starting offset for this pass. */
+ int start;
+
+ /* The ending offset for this pass. */
+ int end;
+
+ /* The type of data in this pass (i.e., MQ or raw). */
+ int type;
+
+ /* Flag indicating that this pass is terminated. */
+ int term;
+
+ /* The entropy coder state after coding this pass. */
+ jpc_mqencstate_t mqencstate;
+
+ /* The layer to which this pass has been assigned. */
+ int lyrno;
+
+ /* The R-D slope for this pass. */
+ jpc_flt_t rdslope;
+
+ /* The weighted MSE reduction associated with this pass. */
+ jpc_flt_t wmsedec;
+
+ /* The cumulative weighted MSE reduction. */
+ jpc_flt_t cumwmsedec;
+
+ /* The normalized MSE reduction. */
+ long nmsedec;
+
+} jpc_enc_pass_t;
+
+/* Encoder per-code-block state information. */
+
+typedef struct {
+
+ /* The number of passes. */
+ int numpasses;
+
+ /* The per-pass information. */
+ jpc_enc_pass_t *passes;
+
+ /* The number of passes encoded so far. */
+ int numencpasses;
+
+ /* The number of insignificant MSBs. */
+ int numimsbs;
+
+ /* The number of bits used to encode pass data lengths. */
+ int numlenbits;
+
+ /* The byte stream for this code block. */
+ jas_stream_t *stream;
+
+ /* The entropy encoder. */
+ jpc_mqenc_t *mqenc;
+
+ /* The data for this code block. */
+ jas_matrix_t *data;
+
+ /* The state for this code block. */
+ jas_matrix_t *flags;
+
+ /* The number of bit planes required for this code block. */
+ int numbps;
+
+ /* The next pass to be encoded. */
+ jpc_enc_pass_t *curpass;
+
+ /* The per-code-block-group state information. */
+ struct jpc_enc_prc_s *prc;
+
+ /* The saved current pass. */
+ /* This is used by the rate control code. */
+ jpc_enc_pass_t *savedcurpass;
+
+ /* The saved length indicator size. */
+ /* This is used by the rate control code. */
+ int savednumlenbits;
+
+ /* The saved number of encoded passes. */
+ /* This is used by the rate control code. */
+ int savednumencpasses;
+
+} jpc_enc_cblk_t;
+
+/* Encoder per-code-block-group state information. */
+
+typedef struct jpc_enc_prc_s {
+
+ /* The x-coordinate of the top-left corner of the precinct. */
+ uint_fast32_t tlx;
+
+ /* The y-coordinate of the top-left corner of the precinct. */
+ uint_fast32_t tly;
+
+ /* The x-coordinate of the bottom-right corner of the precinct
+ (plus one). */
+ uint_fast32_t brx;
+
+ /* The y-coordinate of the bottom-right corner of the precinct
+ (plus one). */
+ uint_fast32_t bry;
+
+ /* The number of code blocks spanning the precinct in the horizontal
+ direction. */
+ int numhcblks;
+
+ /* The number of code blocks spanning the precinct in the vertical
+ direction. */
+ int numvcblks;
+
+ /* The total number of code blocks. */
+ int numcblks;
+
+ /* The per-code-block information. */
+ jpc_enc_cblk_t *cblks;
+
+ /* The inclusion tag tree. */
+ jpc_tagtree_t *incltree;
+
+ /* The insignifcant MSBs tag tree. */
+ jpc_tagtree_t *nlibtree;
+
+ /* The per-band information. */
+ struct jpc_enc_band_s *band;
+
+ /* The saved inclusion tag tree. */
+ /* This is used by rate control. */
+ jpc_tagtree_t *savincltree;
+
+ /* The saved leading-insignificant-bit-planes tag tree. */
+ /* This is used by rate control. */
+ jpc_tagtree_t *savnlibtree;
+
+} jpc_enc_prc_t;
+
+/* Encoder per-band state information. */
+
+typedef struct jpc_enc_band_s {
+
+ /* The per precinct information. */
+ jpc_enc_prc_t *prcs;
+
+ /* The coefficient data for this band. */
+ jas_matrix_t *data;
+
+ /* The orientation of this band (i.e., LL, LH, HL, or HH). */
+ int orient;
+
+ /* The number of bit planes associated with this band. */
+ int numbps;
+
+ /* The quantizer step size. */
+ jpc_fix_t absstepsize;
+
+ /* The encoded quantizer step size. */
+ int stepsize;
+
+ /* The L2 norm of the synthesis basis functions associated with
+ this band. (The MCT is not considered in this value.) */
+ jpc_fix_t synweight;
+
+ /* The analysis gain for this band. */
+ int analgain;
+
+ /* The per-resolution-level information. */
+ struct jpc_enc_rlvl_s *rlvl;
+
+} jpc_enc_band_t;
+
+/* Encoder per-resolution-level state information. */
+
+typedef struct jpc_enc_rlvl_s {
+
+ /* The x-coordinate of the top-left corner of the tile-component
+ at this resolution. */
+ uint_fast32_t tlx;
+
+ /* The y-coordinate of the top-left corner of the tile-component
+ at this resolution. */
+ uint_fast32_t tly;
+
+ /* The x-coordinate of the bottom-right corner of the tile-component
+ at this resolution (plus one). */
+ uint_fast32_t brx;
+
+ /* The y-coordinate of the bottom-right corner of the tile-component
+ at this resolution (plus one). */
+ uint_fast32_t bry;
+
+ /* The exponent value for the nominal precinct width measured
+ relative to the associated LL band. */
+ int prcwidthexpn;
+
+ /* The exponent value for the nominal precinct height measured
+ relative to the associated LL band. */
+ int prcheightexpn;
+
+ /* The number of precincts spanning the resolution level in the
+ horizontal direction. */
+ int numhprcs;
+
+ /* The number of precincts spanning the resolution level in the
+ vertical direction. */
+ int numvprcs;
+
+ /* The total number of precincts. */
+ int numprcs;
+
+ /* The exponent value for the nominal code block group width.
+ This quantity is associated with the next lower resolution level
+ (assuming that there is one). */
+ int cbgwidthexpn;
+
+ /* The exponent value for the nominal code block group height.
+ This quantity is associated with the next lower resolution level
+ (assuming that there is one). */
+ int cbgheightexpn;
+
+ /* The exponent value for the code block width. */
+ uint_fast16_t cblkwidthexpn;
+
+ /* The exponent value for the code block height. */
+ uint_fast16_t cblkheightexpn;
+
+ /* The number of bands associated with this resolution level. */
+ int numbands;
+
+ /* The per-band information. */
+ jpc_enc_band_t *bands;
+
+ /* The parent tile-component. */
+ struct jpc_enc_tcmpt_s *tcmpt;
+
+} jpc_enc_rlvl_t;
+
+/* Encoder per-tile-component state information. */
+
+typedef struct jpc_enc_tcmpt_s {
+
+ /* The number of resolution levels. */
+ int numrlvls;
+
+ /* The per-resolution-level information. */
+ jpc_enc_rlvl_t *rlvls;
+
+ /* The tile-component data. */
+ jas_matrix_t *data;
+
+ /* The QMFB. */
+ int qmfbid;
+
+ /* The number of bands. */
+ int numbands;
+
+ /* The TSFB. */
+ jpc_tsfb_t *tsfb;
+
+ /* The synthesis energy weight (for the MCT). */
+ jpc_fix_t synweight;
+
+ /* The precinct width exponents. */
+ int prcwidthexpns[JPC_MAXRLVLS];
+
+ /* The precinct height exponents. */
+ int prcheightexpns[JPC_MAXRLVLS];
+
+ /* The code block width exponent. */
+ int cblkwidthexpn;
+
+ /* The code block height exponent. */
+ int cblkheightexpn;
+
+ /* Coding style (i.e., explicit precinct sizes). */
+ int csty;
+
+ /* Code block style. */
+ int cblksty;
+
+ /* The number of quantizer step sizes. */
+ int numstepsizes;
+
+ /* The encoded quantizer step sizes. */
+ uint_fast16_t stepsizes[JPC_MAXBANDS];
+
+ /* The parent tile. */
+ struct jpc_enc_tile_s *tile;
+
+} jpc_enc_tcmpt_t;
+
+/* Encoder per-tile state information. */
+
+typedef struct jpc_enc_tile_s {
+
+ /* The tile number. */
+ uint_fast32_t tileno;
+
+ /* The x-coordinate of the top-left corner of the tile measured with
+ respect to the reference grid. */
+ uint_fast32_t tlx;
+
+ /* The y-coordinate of the top-left corner of the tile measured with
+ respect to the reference grid. */
+ uint_fast32_t tly;
+
+ /* The x-coordinate of the bottom-right corner of the tile measured
+ with respect to the reference grid (plus one). */
+ uint_fast32_t brx;
+
+ /* The y-coordinate of the bottom-right corner of the tile measured
+ with respect to the reference grid (plus one). */
+ uint_fast32_t bry;
+
+ /* The coding style. */
+ uint_fast8_t csty;
+
+ /* The progression order. */
+ uint_fast8_t prg;
+
+ /* The number of layers. */
+ int numlyrs;
+
+ /* The MCT to employ (if any). */
+ uint_fast8_t mctid;
+
+ /* The packet iterator (used to determine the order of packet
+ generation). */
+ jpc_pi_t *pi;
+
+ /* The coding mode (i.e., integer or real). */
+ bool intmode;
+
+ /* The number of bytes to allocate to the various layers. */
+ uint_fast32_t *lyrsizes;
+
+ /* The number of tile-components. */
+ int numtcmpts;
+
+ /* The per tile-component information. */
+ jpc_enc_tcmpt_t *tcmpts;
+
+ /* The raw (i.e., uncompressed) size of this tile. */
+ uint_fast32_t rawsize;
+
+} jpc_enc_tile_t;
+
+/* Encoder class. */
+
+typedef struct jpc_enc_s {
+
+ /* The image being encoded. */
+ jas_image_t *image;
+
+ /* The output stream. */
+ jas_stream_t *out;
+
+ /* The coding parameters. */
+ jpc_enc_cp_t *cp;
+
+ /* The tile currently being processed. */
+ jpc_enc_tile_t *curtile;
+
+ /* The code stream state. */
+ jpc_cstate_t *cstate;
+
+ /* The number of bytes output so far. */
+ uint_fast32_t len;
+
+ /* The number of bytes available for the main body of the code stream. */
+ /* This is used for rate allocation purposes. */
+ uint_fast32_t mainbodysize;
+
+ /* The marker segment currently being processed. */
+ /* This member is a convenience for making cleanup easier. */
+ jpc_ms_t *mrk;
+
+ /* The stream used to temporarily hold tile-part data. */
+ jas_stream_t *tmpstream;
+
+} jpc_enc_t;
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_fix.h b/osframework/source/ImageLib/jpeg2000/jpc_fix.h
new file mode 100644
index 0000000..e06eda6
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_fix.h
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Fixed-Point Number Class
+ *
+ * $Id: jpc_fix.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_FIX_H
+#define JPC_FIX_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+#include "jas_fix.h"
+
+/******************************************************************************\
+* Basic parameters of the fixed-point type.
+\******************************************************************************/
+
+/* The integral type used to represent a fixed-point number. This
+ type must be capable of representing values from -(2^31) to 2^31-1
+ (inclusive). */
+typedef int_fast32_t jpc_fix_t;
+
+/* The integral type used to respresent higher-precision intermediate results.
+ This type should be capable of representing values from -(2^63) to 2^63-1
+ (inclusive). */
+typedef int_fast64_t jpc_fix_big_t;
+
+/* The number of bits used for the fractional part of a fixed-point number. */
+#define JPC_FIX_FRACBITS 13
+
+/******************************************************************************\
+* Instantiations of the generic fixed-point number macros for the
+* parameters given above. (Too bad C does not support templates, eh?)
+* The purpose of these macros is self-evident if one examines the
+* corresponding macros in the jasper/jas_fix.h header file.
+\******************************************************************************/
+
+#define JPC_FIX_ZERO JAS_FIX_ZERO(jpc_fix_t, JPC_FIX_FRACBITS)
+#define JPC_FIX_ONE JAS_FIX_ONE(jpc_fix_t, JPC_FIX_FRACBITS)
+#define JPC_FIX_HALF JAS_FIX_HALF(jpc_fix_t, JPC_FIX_FRACBITS)
+
+#define jpc_inttofix(x) JAS_INTTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fixtoint(x) JAS_FIXTOINT(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fixtodbl(x) JAS_FIXTODBL(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_dbltofix(x) JAS_DBLTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x)
+
+#define jpc_fix_add(x, y) JAS_FIX_ADD(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
+#define jpc_fix_sub(x, y) JAS_FIX_SUB(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
+#define jpc_fix_mul(x, y) \
+ JAS_FIX_MUL(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
+#define jpc_fix_mulbyint(x, y) \
+ JAS_FIX_MULBYINT(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
+#define jpc_fix_div(x, y) \
+ JAS_FIX_DIV(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
+#define jpc_fix_neg(x) JAS_FIX_NEG(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_asl(x, n) JAS_FIX_ASL(jpc_fix_t, JPC_FIX_FRACBITS, x, n)
+#define jpc_fix_asr(x, n) JAS_FIX_ASR(jpc_fix_t, JPC_FIX_FRACBITS, x, n)
+
+#define jpc_fix_pluseq(x, y) JAS_FIX_PLUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
+#define jpc_fix_minuseq(x, y) JAS_FIX_MINUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
+#define jpc_fix_muleq(x, y) \
+ JAS_FIX_MULEQ(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
+
+#define jpc_fix_abs(x) JAS_FIX_ABS(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_isint(x) JAS_FIX_ISINT(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_sgn(x) JAS_FIX_SGN(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_round(x) JAS_FIX_ROUND(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_floor(x) JAS_FIX_FLOOR(jpc_fix_t, JPC_FIX_FRACBITS, x)
+#define jpc_fix_trunc(x) JAS_FIX_TRUNC(jpc_fix_t, JPC_FIX_FRACBITS, x)
+
+/******************************************************************************\
+* Extra macros for convenience.
+\******************************************************************************/
+
+/* Compute the sum of three fixed-point numbers. */
+#define jpc_fix_add3(x, y, z) jpc_fix_add(jpc_fix_add(x, y), z)
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_flt.h b/osframework/source/ImageLib/jpeg2000/jpc_flt.h
new file mode 100644
index 0000000..62261ce
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_flt.h
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Floating-Point Class
+ *
+ * $Id: jpc_flt.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_FLT_H
+#define JPC_FLT_H
+
+#include <float.h>
+
+/* The code ought to be modified so this type is not used at all. */
+/* Very few places in the code rely on floating-point arithmetic, aside
+ from conversions in printf's. */
+typedef double jpc_flt_t;
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_math.c b/osframework/source/ImageLib/jpeg2000/jpc_math.c
new file mode 100644
index 0000000..b8d4823
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_math.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Math Library
+ *
+ * $Id: jpc_math.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "jpc_math.h"
+
+/******************************************************************************\
+* Miscellaneous Functions
+\******************************************************************************/
+
+/* Calculate the integer quantity floor(log2(x)), where x is a positive
+ integer. */
+int jpc_floorlog2(int x)
+{
+ int y;
+
+ /* The argument must be positive. */
+ assert(x > 0);
+
+ y = 0;
+ while (x > 1) {
+ x >>= 1;
+ ++y;
+ }
+ return y;
+}
+
+/* Calculate the bit position of the first leading one in a nonnegative
+ integer. */
+/* This function is the basically the same as ceillog2(x), except that the
+ allowable range for x is slightly different. */
+int jpc_firstone(int x)
+{
+ int n;
+
+ /* The argument must be nonnegative. */
+ assert(x >= 0);
+
+ n = -1;
+ while (x > 0) {
+ x >>= 1;
+ ++n;
+ }
+ return n;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_math.h b/osframework/source/ImageLib/jpeg2000/jpc_math.h
new file mode 100644
index 0000000..0373532
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_math.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JPC_MATH_H
+#define JPC_MATH_H
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include <assert.h>
+
+/******************************************************************************\
+* Macros
+\******************************************************************************/
+
+/* Compute the floor of the quotient of two integers. */
+#define JPC_FLOORDIV(x, y) ((x) / (y))
+
+/* Compute the ceiling of the quotient of two integers. */
+#define JPC_CEILDIV(x, y) (((x) + (y) - 1) / (y))
+
+/* Compute the floor of (x / 2^y). */
+#define JPC_FLOORDIVPOW2(x, y) ((x) >> (y))
+
+/* Compute the ceiling of (x / 2^y). */
+#define JPC_CEILDIVPOW2(x, y) (((x) + (1 << (y)) - 1) >> (y))
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Calculate the bit position of the first leading one in a nonnegative
+ integer. */
+int jpc_firstone(int x);
+
+/* Calculate the integer quantity floor(log2(x)), where x is a positive
+ integer. */
+int jpc_floorlog2(int x);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mct.c b/osframework/source/ImageLib/jpeg2000/jpc_mct.c
new file mode 100644
index 0000000..50432a3
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mct.c
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Multicomponent Transform Code
+ *
+ * $Id: jpc_mct.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+
+#include "jas_seq.h"
+
+#include "jpc_fix.h"
+#include "jpc_mct.h"
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+/* Compute the forward RCT. */
+
+void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
+{
+ int numrows;
+ int numcols;
+ int i;
+ int j;
+ jpc_fix_t *c0p;
+ jpc_fix_t *c1p;
+ jpc_fix_t *c2p;
+
+ numrows = jas_matrix_numrows(c0);
+ numcols = jas_matrix_numcols(c0);
+
+ /* All three matrices must have the same dimensions. */
+ assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
+ && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
+
+ for (i = 0; i < numrows; i++) {
+ c0p = jas_matrix_getref(c0, i, 0);
+ c1p = jas_matrix_getref(c1, i, 0);
+ c2p = jas_matrix_getref(c2, i, 0);
+ for (j = numcols; j > 0; --j) {
+ int r;
+ int g;
+ int b;
+ int y;
+ int u;
+ int v;
+ r = *c0p;
+ g = *c1p;
+ b = *c2p;
+ y = (r + (g << 1) + b) >> 2;
+ u = b - g;
+ v = r - g;
+ *c0p++ = y;
+ *c1p++ = u;
+ *c2p++ = v;
+ }
+ }
+}
+
+/* Compute the inverse RCT. */
+
+void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
+{
+ int numrows;
+ int numcols;
+ int i;
+ int j;
+ jpc_fix_t *c0p;
+ jpc_fix_t *c1p;
+ jpc_fix_t *c2p;
+
+ numrows = jas_matrix_numrows(c0);
+ numcols = jas_matrix_numcols(c0);
+
+ /* All three matrices must have the same dimensions. */
+ assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
+ && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
+
+ for (i = 0; i < numrows; i++) {
+ c0p = jas_matrix_getref(c0, i, 0);
+ c1p = jas_matrix_getref(c1, i, 0);
+ c2p = jas_matrix_getref(c2, i, 0);
+ for (j = numcols; j > 0; --j) {
+ int r;
+ int g;
+ int b;
+ int y;
+ int u;
+ int v;
+ y = *c0p;
+ u = *c1p;
+ v = *c2p;
+ g = y - ((u + v) >> 2);
+ r = v + g;
+ b = u + g;
+ *c0p++ = r;
+ *c1p++ = g;
+ *c2p++ = b;
+ }
+ }
+}
+
+void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
+{
+ int numrows;
+ int numcols;
+ int i;
+ int j;
+ jpc_fix_t r;
+ jpc_fix_t g;
+ jpc_fix_t b;
+ jpc_fix_t y;
+ jpc_fix_t u;
+ jpc_fix_t v;
+ jpc_fix_t *c0p;
+ jpc_fix_t *c1p;
+ jpc_fix_t *c2p;
+
+ numrows = jas_matrix_numrows(c0);
+ assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
+ numcols = jas_matrix_numcols(c0);
+ assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
+ for (i = 0; i < numrows; ++i) {
+ c0p = jas_matrix_getref(c0, i, 0);
+ c1p = jas_matrix_getref(c1, i, 0);
+ c2p = jas_matrix_getref(c2, i, 0);
+ for (j = numcols; j > 0; --j) {
+ r = *c0p;
+ g = *c1p;
+ b = *c2p;
+ y = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.299), r), jpc_fix_mul(jpc_dbltofix(0.587), g),
+ jpc_fix_mul(jpc_dbltofix(0.114), b));
+ u = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(-0.16875), r), jpc_fix_mul(jpc_dbltofix(-0.33126), g),
+ jpc_fix_mul(jpc_dbltofix(0.5), b));
+ v = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.5), r), jpc_fix_mul(jpc_dbltofix(-0.41869), g),
+ jpc_fix_mul(jpc_dbltofix(-0.08131), b));
+ *c0p++ = y;
+ *c1p++ = u;
+ *c2p++ = v;
+ }
+ }
+}
+
+void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
+{
+ int numrows;
+ int numcols;
+ int i;
+ int j;
+ jpc_fix_t r;
+ jpc_fix_t g;
+ jpc_fix_t b;
+ jpc_fix_t y;
+ jpc_fix_t u;
+ jpc_fix_t v;
+ jpc_fix_t *c0p;
+ jpc_fix_t *c1p;
+ jpc_fix_t *c2p;
+
+ numrows = jas_matrix_numrows(c0);
+ assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
+ numcols = jas_matrix_numcols(c0);
+ assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
+ for (i = 0; i < numrows; ++i) {
+ c0p = jas_matrix_getref(c0, i, 0);
+ c1p = jas_matrix_getref(c1, i, 0);
+ c2p = jas_matrix_getref(c2, i, 0);
+ for (j = numcols; j > 0; --j) {
+ y = *c0p;
+ u = *c1p;
+ v = *c2p;
+ r = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.402), v));
+ g = jpc_fix_add3(y, jpc_fix_mul(jpc_dbltofix(-0.34413), u),
+ jpc_fix_mul(jpc_dbltofix(-0.71414), v));
+ b = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.772), u));
+ *c0p++ = r;
+ *c1p++ = g;
+ *c2p++ = b;
+ }
+ }
+}
+
+jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno)
+{
+ jpc_fix_t synweight;
+
+ synweight = JPC_FIX_ONE;
+ switch (mctid) {
+ case JPC_MCT_RCT:
+ switch (cmptno) {
+ case 0:
+ synweight = jpc_dbltofix(sqrt(3.0));
+ break;
+ case 1:
+ synweight = jpc_dbltofix(sqrt(0.6875));
+ break;
+ case 2:
+ synweight = jpc_dbltofix(sqrt(0.6875));
+ break;
+ }
+ break;
+ case JPC_MCT_ICT:
+ switch (cmptno) {
+ case 0:
+ synweight = jpc_dbltofix(sqrt(3.0000));
+ break;
+ case 1:
+ synweight = jpc_dbltofix(sqrt(3.2584));
+ break;
+ case 2:
+ synweight = jpc_dbltofix(sqrt(2.4755));
+ break;
+ }
+ break;
+#if 0
+ default:
+ synweight = JPC_FIX_ONE;
+ break;
+#endif
+ }
+
+ return synweight;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mct.h b/osframework/source/ImageLib/jpeg2000/jpc_mct.h
new file mode 100644
index 0000000..b152a24
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mct.h
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Multicomponent Transform Code
+ *
+ * $Id: jpc_mct.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_MCT_H
+#define JPC_MCT_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_seq.h"
+#include "jas_fix.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/*
+ * Multicomponent transform IDs.
+ */
+
+#define JPC_MCT_NONE 0
+#define JPC_MCT_ICT 1
+#define JPC_MCT_RCT 2
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Calculate the forward RCT. */
+void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
+
+/* Calculate the inverse RCT. */
+void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
+
+/* Calculate the forward ICT. */
+void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
+
+/* Calculate the inverse ICT. */
+void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
+
+/* Get the synthesis weight associated with a particular component. */
+jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqcod.c b/osframework/source/ImageLib/jpeg2000/jpc_mqcod.c
new file mode 100644
index 0000000..7dda240
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqcod.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Coder
+ *
+ * $Id: jpc_mqcod.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_malloc.h"
+
+#include "jpc_mqcod.h"
+
+/******************************************************************************\
+* Data.
+\******************************************************************************/
+
+/* MQ coder per-state information. */
+
+jpc_mqstate_t jpc_mqstates[47 * 2] = {
+ {0x5601, 0, &jpc_mqstates[ 2], &jpc_mqstates[ 3]},
+ {0x5601, 1, &jpc_mqstates[ 3], &jpc_mqstates[ 2]},
+ {0x3401, 0, &jpc_mqstates[ 4], &jpc_mqstates[12]},
+ {0x3401, 1, &jpc_mqstates[ 5], &jpc_mqstates[13]},
+ {0x1801, 0, &jpc_mqstates[ 6], &jpc_mqstates[18]},
+ {0x1801, 1, &jpc_mqstates[ 7], &jpc_mqstates[19]},
+ {0x0ac1, 0, &jpc_mqstates[ 8], &jpc_mqstates[24]},
+ {0x0ac1, 1, &jpc_mqstates[ 9], &jpc_mqstates[25]},
+ {0x0521, 0, &jpc_mqstates[10], &jpc_mqstates[58]},
+ {0x0521, 1, &jpc_mqstates[11], &jpc_mqstates[59]},
+ {0x0221, 0, &jpc_mqstates[76], &jpc_mqstates[66]},
+ {0x0221, 1, &jpc_mqstates[77], &jpc_mqstates[67]},
+ {0x5601, 0, &jpc_mqstates[14], &jpc_mqstates[13]},
+ {0x5601, 1, &jpc_mqstates[15], &jpc_mqstates[12]},
+ {0x5401, 0, &jpc_mqstates[16], &jpc_mqstates[28]},
+ {0x5401, 1, &jpc_mqstates[17], &jpc_mqstates[29]},
+ {0x4801, 0, &jpc_mqstates[18], &jpc_mqstates[28]},
+ {0x4801, 1, &jpc_mqstates[19], &jpc_mqstates[29]},
+ {0x3801, 0, &jpc_mqstates[20], &jpc_mqstates[28]},
+ {0x3801, 1, &jpc_mqstates[21], &jpc_mqstates[29]},
+ {0x3001, 0, &jpc_mqstates[22], &jpc_mqstates[34]},
+ {0x3001, 1, &jpc_mqstates[23], &jpc_mqstates[35]},
+ {0x2401, 0, &jpc_mqstates[24], &jpc_mqstates[36]},
+ {0x2401, 1, &jpc_mqstates[25], &jpc_mqstates[37]},
+ {0x1c01, 0, &jpc_mqstates[26], &jpc_mqstates[40]},
+ {0x1c01, 1, &jpc_mqstates[27], &jpc_mqstates[41]},
+ {0x1601, 0, &jpc_mqstates[58], &jpc_mqstates[42]},
+ {0x1601, 1, &jpc_mqstates[59], &jpc_mqstates[43]},
+ {0x5601, 0, &jpc_mqstates[30], &jpc_mqstates[29]},
+ {0x5601, 1, &jpc_mqstates[31], &jpc_mqstates[28]},
+ {0x5401, 0, &jpc_mqstates[32], &jpc_mqstates[28]},
+ {0x5401, 1, &jpc_mqstates[33], &jpc_mqstates[29]},
+ {0x5101, 0, &jpc_mqstates[34], &jpc_mqstates[30]},
+ {0x5101, 1, &jpc_mqstates[35], &jpc_mqstates[31]},
+ {0x4801, 0, &jpc_mqstates[36], &jpc_mqstates[32]},
+ {0x4801, 1, &jpc_mqstates[37], &jpc_mqstates[33]},
+ {0x3801, 0, &jpc_mqstates[38], &jpc_mqstates[34]},
+ {0x3801, 1, &jpc_mqstates[39], &jpc_mqstates[35]},
+ {0x3401, 0, &jpc_mqstates[40], &jpc_mqstates[36]},
+ {0x3401, 1, &jpc_mqstates[41], &jpc_mqstates[37]},
+ {0x3001, 0, &jpc_mqstates[42], &jpc_mqstates[38]},
+ {0x3001, 1, &jpc_mqstates[43], &jpc_mqstates[39]},
+ {0x2801, 0, &jpc_mqstates[44], &jpc_mqstates[38]},
+ {0x2801, 1, &jpc_mqstates[45], &jpc_mqstates[39]},
+ {0x2401, 0, &jpc_mqstates[46], &jpc_mqstates[40]},
+ {0x2401, 1, &jpc_mqstates[47], &jpc_mqstates[41]},
+ {0x2201, 0, &jpc_mqstates[48], &jpc_mqstates[42]},
+ {0x2201, 1, &jpc_mqstates[49], &jpc_mqstates[43]},
+ {0x1c01, 0, &jpc_mqstates[50], &jpc_mqstates[44]},
+ {0x1c01, 1, &jpc_mqstates[51], &jpc_mqstates[45]},
+ {0x1801, 0, &jpc_mqstates[52], &jpc_mqstates[46]},
+ {0x1801, 1, &jpc_mqstates[53], &jpc_mqstates[47]},
+ {0x1601, 0, &jpc_mqstates[54], &jpc_mqstates[48]},
+ {0x1601, 1, &jpc_mqstates[55], &jpc_mqstates[49]},
+ {0x1401, 0, &jpc_mqstates[56], &jpc_mqstates[50]},
+ {0x1401, 1, &jpc_mqstates[57], &jpc_mqstates[51]},
+ {0x1201, 0, &jpc_mqstates[58], &jpc_mqstates[52]},
+ {0x1201, 1, &jpc_mqstates[59], &jpc_mqstates[53]},
+ {0x1101, 0, &jpc_mqstates[60], &jpc_mqstates[54]},
+ {0x1101, 1, &jpc_mqstates[61], &jpc_mqstates[55]},
+ {0x0ac1, 0, &jpc_mqstates[62], &jpc_mqstates[56]},
+ {0x0ac1, 1, &jpc_mqstates[63], &jpc_mqstates[57]},
+ {0x09c1, 0, &jpc_mqstates[64], &jpc_mqstates[58]},
+ {0x09c1, 1, &jpc_mqstates[65], &jpc_mqstates[59]},
+ {0x08a1, 0, &jpc_mqstates[66], &jpc_mqstates[60]},
+ {0x08a1, 1, &jpc_mqstates[67], &jpc_mqstates[61]},
+ {0x0521, 0, &jpc_mqstates[68], &jpc_mqstates[62]},
+ {0x0521, 1, &jpc_mqstates[69], &jpc_mqstates[63]},
+ {0x0441, 0, &jpc_mqstates[70], &jpc_mqstates[64]},
+ {0x0441, 1, &jpc_mqstates[71], &jpc_mqstates[65]},
+ {0x02a1, 0, &jpc_mqstates[72], &jpc_mqstates[66]},
+ {0x02a1, 1, &jpc_mqstates[73], &jpc_mqstates[67]},
+ {0x0221, 0, &jpc_mqstates[74], &jpc_mqstates[68]},
+ {0x0221, 1, &jpc_mqstates[75], &jpc_mqstates[69]},
+ {0x0141, 0, &jpc_mqstates[76], &jpc_mqstates[70]},
+ {0x0141, 1, &jpc_mqstates[77], &jpc_mqstates[71]},
+ {0x0111, 0, &jpc_mqstates[78], &jpc_mqstates[72]},
+ {0x0111, 1, &jpc_mqstates[79], &jpc_mqstates[73]},
+ {0x0085, 0, &jpc_mqstates[80], &jpc_mqstates[74]},
+ {0x0085, 1, &jpc_mqstates[81], &jpc_mqstates[75]},
+ {0x0049, 0, &jpc_mqstates[82], &jpc_mqstates[76]},
+ {0x0049, 1, &jpc_mqstates[83], &jpc_mqstates[77]},
+ {0x0025, 0, &jpc_mqstates[84], &jpc_mqstates[78]},
+ {0x0025, 1, &jpc_mqstates[85], &jpc_mqstates[79]},
+ {0x0015, 0, &jpc_mqstates[86], &jpc_mqstates[80]},
+ {0x0015, 1, &jpc_mqstates[87], &jpc_mqstates[81]},
+ {0x0009, 0, &jpc_mqstates[88], &jpc_mqstates[82]},
+ {0x0009, 1, &jpc_mqstates[89], &jpc_mqstates[83]},
+ {0x0005, 0, &jpc_mqstates[90], &jpc_mqstates[84]},
+ {0x0005, 1, &jpc_mqstates[91], &jpc_mqstates[85]},
+ {0x0001, 0, &jpc_mqstates[90], &jpc_mqstates[86]},
+ {0x0001, 1, &jpc_mqstates[91], &jpc_mqstates[87]},
+ {0x5601, 0, &jpc_mqstates[92], &jpc_mqstates[92]},
+ {0x5601, 1, &jpc_mqstates[93], &jpc_mqstates[93]},
+};
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqcod.h b/osframework/source/ImageLib/jpeg2000/jpc_mqcod.h
new file mode 100644
index 0000000..b115982
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqcod.h
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Coder
+ *
+ * $Id: jpc_mqcod.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_MQCOD_H
+#define JPC_MQCOD_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/*
+ * MQ coder context information.
+ */
+
+typedef struct {
+
+ /* The most probable symbol (MPS). */
+ int mps;
+
+ /* The state index. */
+ int_fast16_t ind;
+
+} jpc_mqctx_t;
+
+/*
+ * MQ coder state table entry.
+ */
+
+typedef struct jpc_mqstate_s {
+
+ /* The Qe value. */
+ uint_fast16_t qeval;
+
+ /* The MPS. */
+ int mps;
+
+ /* The NMPS state. */
+ struct jpc_mqstate_s *nmps;
+
+ /* The NLPS state. */
+ struct jpc_mqstate_s *nlps;
+
+} jpc_mqstate_t;
+
+/******************************************************************************\
+* Data.
+\******************************************************************************/
+
+/* The state table for the MQ coder. */
+extern jpc_mqstate_t jpc_mqstates[];
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqdec.c b/osframework/source/ImageLib/jpeg2000/jpc_mqdec.c
new file mode 100644
index 0000000..efebaeb
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqdec.c
@@ -0,0 +1,355 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Decoder
+ *
+ * $Id: jpc_mqdec.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "jas_types.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+
+#include "jpc_mqdec.h"
+
+/******************************************************************************\
+* Local macros.
+\******************************************************************************/
+
+#if defined(DEBUG)
+#define MQDEC_CALL(n, x) \
+ ((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0))
+#else
+#define MQDEC_CALL(n, x)
+#endif
+
+/******************************************************************************\
+* Local function prototypes.
+\******************************************************************************/
+
+static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec);
+
+/******************************************************************************\
+* Code for creation and destruction of a MQ decoder.
+\******************************************************************************/
+
+/* Create a MQ decoder. */
+jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in)
+{
+ jpc_mqdec_t *mqdec;
+
+ /* There must be at least one context. */
+ assert(maxctxs > 0);
+
+ /* Allocate memory for the MQ decoder. */
+ if (!(mqdec = jas_malloc(sizeof(jpc_mqdec_t)))) {
+ goto error;
+ }
+ mqdec->in = in;
+ mqdec->maxctxs = maxctxs;
+ /* Allocate memory for the per-context state information. */
+ if (!(mqdec->ctxs = jas_malloc(mqdec->maxctxs * sizeof(jpc_mqstate_t *)))) {
+ goto error;
+ }
+ /* Set the current context to the first context. */
+ mqdec->curctx = mqdec->ctxs;
+
+ /* If an input stream has been associated with the MQ decoder,
+ initialize the decoder state from the stream. */
+ if (mqdec->in) {
+ jpc_mqdec_init(mqdec);
+ }
+ /* Initialize the per-context state information. */
+ jpc_mqdec_setctxs(mqdec, 0, 0);
+
+ return mqdec;
+
+error:
+ /* Oops... Something has gone wrong. */
+ if (mqdec) {
+ jpc_mqdec_destroy(mqdec);
+ }
+ return 0;
+}
+
+/* Destroy a MQ decoder. */
+void jpc_mqdec_destroy(jpc_mqdec_t *mqdec)
+{
+ if (mqdec->ctxs) {
+ jas_free(mqdec->ctxs);
+ }
+ jas_free(mqdec);
+}
+
+/******************************************************************************\
+* Code for initialization of a MQ decoder.
+\******************************************************************************/
+
+/* Initialize the state of a MQ decoder. */
+
+void jpc_mqdec_init(jpc_mqdec_t *mqdec)
+{
+ int c;
+
+ mqdec->eof = 0;
+ mqdec->creg = 0;
+ /* Get the next byte from the input stream. */
+ if ((c = jas_stream_getc(mqdec->in)) == EOF) {
+ /* We have encountered an I/O error or EOF. */
+ c = 0xff;
+ mqdec->eof = 1;
+ }
+ mqdec->inbuffer = c;
+ mqdec->creg += mqdec->inbuffer << 16;
+ jpc_mqdec_bytein(mqdec);
+ mqdec->creg <<= 7;
+ mqdec->ctreg -= 7;
+ mqdec->areg = 0x8000;
+}
+
+/* Set the input stream for a MQ decoder. */
+
+void jpc_mqdec_setinput(jpc_mqdec_t *mqdec, jas_stream_t *in)
+{
+ mqdec->in = in;
+}
+
+/* Initialize one or more contexts. */
+
+void jpc_mqdec_setctxs(jpc_mqdec_t *mqdec, int numctxs, jpc_mqctx_t *ctxs)
+{
+ jpc_mqstate_t **ctx;
+ int n;
+
+ ctx = mqdec->ctxs;
+ n = JAS_MIN(mqdec->maxctxs, numctxs);
+ while (--n >= 0) {
+ *ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps];
+ ++ctx;
+ ++ctxs;
+ }
+ n = mqdec->maxctxs - numctxs;
+ while (--n >= 0) {
+ *ctx = &jpc_mqstates[0];
+ ++ctx;
+ }
+}
+
+/* Initialize a context. */
+
+void jpc_mqdec_setctx(jpc_mqdec_t *mqdec, int ctxno, jpc_mqctx_t *ctx)
+{
+ jpc_mqstate_t **ctxi;
+ ctxi = &mqdec->ctxs[ctxno];
+ *ctxi = &jpc_mqstates[2 * ctx->ind + ctx->mps];
+}
+
+/******************************************************************************\
+* Code for decoding a bit.
+\******************************************************************************/
+
+/* Decode a bit. */
+
+int jpc_mqdec_getbit_func(register jpc_mqdec_t *mqdec)
+{
+ int bit;
+ JAS_DBGLOG(100, ("jpc_mqdec_getbit_func(%p)\n", mqdec));
+ MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
+ bit = jpc_mqdec_getbit_macro(mqdec);
+ MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
+ JAS_DBGLOG(100, ("ctx = %d, decoded %d\n", mqdec->curctx -
+ mqdec->ctxs, bit));
+ return bit;
+}
+
+/* Apply MPS_EXCHANGE algorithm (with RENORMD). */
+int jpc_mqdec_mpsexchrenormd(register jpc_mqdec_t *mqdec)
+{
+ int ret;
+ register jpc_mqstate_t *state = *mqdec->curctx;
+ jpc_mqdec_mpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret);
+ jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in,
+ mqdec->eof, mqdec->inbuffer);
+ return ret;
+}
+
+/* Apply LPS_EXCHANGE algorithm (with RENORMD). */
+int jpc_mqdec_lpsexchrenormd(register jpc_mqdec_t *mqdec)
+{
+ int ret;
+ register jpc_mqstate_t *state = *mqdec->curctx;
+ jpc_mqdec_lpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret);
+ jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in,
+ mqdec->eof, mqdec->inbuffer);
+ return ret;
+}
+
+/******************************************************************************\
+* Support code.
+\******************************************************************************/
+
+/* Apply the BYTEIN algorithm. */
+static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec)
+{
+ int c;
+ unsigned char prevbuf;
+
+ if (!mqdec->eof) {
+ if ((c = jas_stream_getc(mqdec->in)) == EOF) {
+ mqdec->eof = 1;
+ c = 0xff;
+ }
+ prevbuf = mqdec->inbuffer;
+ mqdec->inbuffer = c;
+ if (prevbuf == 0xff) {
+ if (c > 0x8f) {
+ mqdec->creg += 0xff00;
+ mqdec->ctreg = 8;
+ } else {
+ mqdec->creg += c << 9;
+ mqdec->ctreg = 7;
+ }
+ } else {
+ mqdec->creg += c << 8;
+ mqdec->ctreg = 8;
+ }
+ } else {
+ mqdec->creg += 0xff00;
+ mqdec->ctreg = 8;
+ }
+}
+
+/******************************************************************************\
+* Code for debugging.
+\******************************************************************************/
+
+/* Dump a MQ decoder to a stream for debugging. */
+
+void jpc_mqdec_dump(jpc_mqdec_t *mqdec, FILE *out)
+{
+ fprintf(out, "MQDEC A = %08lx, C = %08lx, CT=%08lx, ",
+ (unsigned long) mqdec->areg, (unsigned long) mqdec->creg,
+ (unsigned long) mqdec->ctreg);
+ fprintf(out, "CTX = %d, ", mqdec->curctx - mqdec->ctxs);
+ fprintf(out, "IND %d, MPS %d, QEVAL %x\n", *mqdec->curctx -
+ jpc_mqstates, (*mqdec->curctx)->mps, (*mqdec->curctx)->qeval);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqdec.h b/osframework/source/ImageLib/jpeg2000/jpc_mqdec.h
new file mode 100644
index 0000000..6218a3b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqdec.h
@@ -0,0 +1,320 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Decoder
+ *
+ * $Id: jpc_mqdec.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_MQDEC_H
+#define JPC_MQDEC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+#include "jas_stream.h"
+
+#include "jpc_mqcod.h"
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* MQ arithmetic decoder. */
+
+typedef struct {
+
+ /* The C register. */
+ uint_fast32_t creg;
+
+ /* The A register. */
+ uint_fast32_t areg;
+
+ /* The CT register. */
+ uint_fast32_t ctreg;
+
+ /* The current context. */
+ jpc_mqstate_t **curctx;
+
+ /* The per-context information. */
+ jpc_mqstate_t **ctxs;
+
+ /* The maximum number of contexts. */
+ int maxctxs;
+
+ /* The stream from which to read data. */
+ jas_stream_t *in;
+
+ /* The last character read. */
+ uchar inbuffer;
+
+ /* The EOF indicator. */
+ int eof;
+
+} jpc_mqdec_t;
+
+/******************************************************************************\
+* Functions/macros for construction and destruction.
+\******************************************************************************/
+
+/* Create a MQ decoder. */
+jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in);
+
+/* Destroy a MQ decoder. */
+void jpc_mqdec_destroy(jpc_mqdec_t *dec);
+
+/******************************************************************************\
+* Functions/macros for initialization.
+\******************************************************************************/
+
+/* Set the input stream associated with a MQ decoder. */
+void jpc_mqdec_setinput(jpc_mqdec_t *dec, jas_stream_t *in);
+
+/* Initialize a MQ decoder. */
+void jpc_mqdec_init(jpc_mqdec_t *dec);
+
+/******************************************************************************\
+* Functions/macros for manipulating contexts.
+\******************************************************************************/
+
+/* Set the current context for a MQ decoder. */
+#define jpc_mqdec_setcurctx(dec, ctxno) \
+ ((mqdec)->curctx = &(mqdec)->ctxs[ctxno]);
+
+/* Set the state information for a particular context of a MQ decoder. */
+void jpc_mqdec_setctx(jpc_mqdec_t *dec, int ctxno, jpc_mqctx_t *ctx);
+
+/* Set the state information for all contexts of a MQ decoder. */
+void jpc_mqdec_setctxs(jpc_mqdec_t *dec, int numctxs, jpc_mqctx_t *ctxs);
+
+/******************************************************************************\
+* Functions/macros for decoding bits.
+\******************************************************************************/
+
+/* Decode a symbol. */
+#if !defined(DEBUG)
+#define jpc_mqdec_getbit(dec) \
+ jpc_mqdec_getbit_macro(dec)
+#else
+#define jpc_mqdec_getbit(dec) \
+ jpc_mqdec_getbit_func(dec)
+#endif
+
+/* Decode a symbol (assuming an unskewed probability distribution). */
+#if !defined(DEBUG)
+#define jpc_mqdec_getbitnoskew(dec) \
+ jpc_mqdec_getbit_macro(dec)
+#else
+#define jpc_mqdec_getbitnoskew(dec) \
+ jpc_mqdec_getbit_func(dec)
+#endif
+
+/******************************************************************************\
+* Functions/macros for debugging.
+\******************************************************************************/
+
+/* Dump the MQ decoder state for debugging. */
+void jpc_mqdec_dump(jpc_mqdec_t *dec, FILE *out);
+
+/******************************************************************************\
+* EVERYTHING BELOW THIS POINT IS IMPLEMENTATION SPECIFIC AND NOT PART OF THE
+* APPLICATION INTERFACE. DO NOT RELY ON ANY OF THE INTERNAL FUNCTIONS/MACROS
+* GIVEN BELOW.
+\******************************************************************************/
+
+#define jpc_mqdec_getbit_macro(dec) \
+ ((((dec)->areg -= (*(dec)->curctx)->qeval), \
+ (dec)->creg >> 16 >= (*(dec)->curctx)->qeval) ? \
+ ((((dec)->creg -= (*(dec)->curctx)->qeval << 16), \
+ (dec)->areg & 0x8000) ? (*(dec)->curctx)->mps : \
+ jpc_mqdec_mpsexchrenormd(dec)) : \
+ jpc_mqdec_lpsexchrenormd(dec))
+
+#define jpc_mqdec_mpsexchange(areg, delta, curctx, bit) \
+{ \
+ if ((areg) < (delta)) { \
+ register jpc_mqstate_t *state = *(curctx); \
+ /* LPS decoded. */ \
+ (bit) = state->mps ^ 1; \
+ *(curctx) = state->nlps; \
+ } else { \
+ register jpc_mqstate_t *state = *(curctx); \
+ /* MPS decoded. */ \
+ (bit) = state->mps; \
+ *(curctx) = state->nmps; \
+ } \
+}
+
+#define jpc_mqdec_lpsexchange(areg, delta, curctx, bit) \
+{ \
+ if ((areg) >= (delta)) { \
+ register jpc_mqstate_t *state = *(curctx); \
+ (areg) = (delta); \
+ (bit) = state->mps ^ 1; \
+ *(curctx) = state->nlps; \
+ } else { \
+ register jpc_mqstate_t *state = *(curctx); \
+ (areg) = (delta); \
+ (bit) = state->mps; \
+ *(curctx) = state->nmps; \
+ } \
+}
+
+#define jpc_mqdec_renormd(areg, creg, ctreg, in, eof, inbuf) \
+{ \
+ do { \
+ if (!(ctreg)) { \
+ jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf); \
+ } \
+ (areg) <<= 1; \
+ (creg) <<= 1; \
+ --(ctreg); \
+ } while (!((areg) & 0x8000)); \
+}
+
+#define jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf) \
+{ \
+ int c; \
+ unsigned char prevbuf; \
+ if (!(eof)) { \
+ if ((c = jas_stream_getc(in)) == EOF) { \
+ (eof) = 1; \
+ c = 0xff; \
+ } \
+ prevbuf = (inbuf); \
+ (inbuf) = c; \
+ if (prevbuf == 0xff) { \
+ if (c > 0x8f) { \
+ (creg) += 0xff00; \
+ (ctreg) = 8; \
+ } else { \
+ (creg) += c << 9; \
+ (ctreg) = 7; \
+ } \
+ } else { \
+ (creg) += c << 8; \
+ (ctreg) = 8; \
+ } \
+ } else { \
+ (creg) += 0xff00; \
+ (ctreg) = 8; \
+ } \
+}
+
+int jpc_mqdec_getbit_func(jpc_mqdec_t *dec);
+int jpc_mqdec_mpsexchrenormd(jpc_mqdec_t *dec);
+int jpc_mqdec_lpsexchrenormd(jpc_mqdec_t *dec);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqenc.c b/osframework/source/ImageLib/jpeg2000/jpc_mqenc.c
new file mode 100644
index 0000000..a4b017c
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqenc.c
@@ -0,0 +1,441 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Encoder
+ *
+ * $Id: jpc_mqenc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "jas_stream.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+
+#include "jpc_mqenc.h"
+
+/******************************************************************************\
+* Macros
+\******************************************************************************/
+
+#if defined(DEBUG)
+#define JPC_MQENC_CALL(n, x) \
+ ((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0))
+#else
+#define JPC_MQENC_CALL(n, x)
+#endif
+
+#define jpc_mqenc_codemps9(areg, creg, ctreg, curctx, enc) \
+{ \
+ jpc_mqstate_t *state = *(curctx); \
+ (areg) -= state->qeval; \
+ if (!((areg) & 0x8000)) { \
+ if ((areg) < state->qeval) { \
+ (areg) = state->qeval; \
+ } else { \
+ (creg) += state->qeval; \
+ } \
+ *(curctx) = state->nmps; \
+ jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \
+ } else { \
+ (creg) += state->qeval; \
+ } \
+}
+
+#define jpc_mqenc_codelps2(areg, creg, ctreg, curctx, enc) \
+{ \
+ jpc_mqstate_t *state = *(curctx); \
+ (areg) -= state->qeval; \
+ if ((areg) < state->qeval) { \
+ (creg) += state->qeval; \
+ } else { \
+ (areg) = state->qeval; \
+ } \
+ *(curctx) = state->nlps; \
+ jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \
+}
+
+#define jpc_mqenc_renorme(areg, creg, ctreg, enc) \
+{ \
+ do { \
+ (areg) <<= 1; \
+ (creg) <<= 1; \
+ if (!--(ctreg)) { \
+ jpc_mqenc_byteout((areg), (creg), (ctreg), (enc)); \
+ } \
+ } while (!((areg) & 0x8000)); \
+}
+
+#define jpc_mqenc_byteout(areg, creg, ctreg, enc) \
+{ \
+ if ((enc)->outbuf != 0xff) { \
+ if ((creg) & 0x8000000) { \
+ if (++((enc)->outbuf) == 0xff) { \
+ (creg) &= 0x7ffffff; \
+ jpc_mqenc_byteout2(enc); \
+ enc->outbuf = ((creg) >> 20) & 0xff; \
+ (creg) &= 0xfffff; \
+ (ctreg) = 7; \
+ } else { \
+ jpc_mqenc_byteout2(enc); \
+ enc->outbuf = ((creg) >> 19) & 0xff; \
+ (creg) &= 0x7ffff; \
+ (ctreg) = 8; \
+ } \
+ } else { \
+ jpc_mqenc_byteout2(enc); \
+ (enc)->outbuf = ((creg) >> 19) & 0xff; \
+ (creg) &= 0x7ffff; \
+ (ctreg) = 8; \
+ } \
+ } else { \
+ jpc_mqenc_byteout2(enc); \
+ (enc)->outbuf = ((creg) >> 20) & 0xff; \
+ (creg) &= 0xfffff; \
+ (ctreg) = 7; \
+ } \
+}
+
+#define jpc_mqenc_byteout2(enc) \
+{ \
+ if (enc->outbuf >= 0) { \
+ if (jas_stream_putc(enc->out, (unsigned char)enc->outbuf) == EOF) { \
+ enc->err |= 1; \
+ } \
+ } \
+ enc->lastbyte = enc->outbuf; \
+}
+
+/******************************************************************************\
+* Local function protoypes.
+\******************************************************************************/
+
+static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc);
+
+/******************************************************************************\
+* Code for creation and destruction of encoder.
+\******************************************************************************/
+
+/* Create a MQ encoder. */
+
+jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out)
+{
+ jpc_mqenc_t *mqenc;
+
+ /* Allocate memory for the MQ encoder. */
+ if (!(mqenc = jas_malloc(sizeof(jpc_mqenc_t)))) {
+ goto error;
+ }
+ mqenc->out = out;
+ mqenc->maxctxs = maxctxs;
+
+ /* Allocate memory for the per-context state information. */
+ if (!(mqenc->ctxs = jas_malloc(mqenc->maxctxs * sizeof(jpc_mqstate_t *)))) {
+ goto error;
+ }
+
+ /* Set the current context to the first one. */
+ mqenc->curctx = mqenc->ctxs;
+
+ jpc_mqenc_init(mqenc);
+
+ /* Initialize the per-context state information to something sane. */
+ jpc_mqenc_setctxs(mqenc, 0, 0);
+
+ return mqenc;
+
+error:
+ if (mqenc) {
+ jpc_mqenc_destroy(mqenc);
+ }
+ return 0;
+}
+
+/* Destroy a MQ encoder. */
+
+void jpc_mqenc_destroy(jpc_mqenc_t *mqenc)
+{
+ if (mqenc->ctxs) {
+ jas_free(mqenc->ctxs);
+ }
+ jas_free(mqenc);
+}
+
+/******************************************************************************\
+* State initialization code.
+\******************************************************************************/
+
+/* Initialize the coding state of a MQ encoder. */
+
+void jpc_mqenc_init(jpc_mqenc_t *mqenc)
+{
+ mqenc->areg = 0x8000;
+ mqenc->outbuf = -1;
+ mqenc->creg = 0;
+ mqenc->ctreg = 12;
+ mqenc->lastbyte = -1;
+ mqenc->err = 0;
+}
+
+/* Initialize one or more contexts. */
+
+void jpc_mqenc_setctxs(jpc_mqenc_t *mqenc, int numctxs, jpc_mqctx_t *ctxs)
+{
+ jpc_mqstate_t **ctx;
+ int n;
+
+ ctx = mqenc->ctxs;
+ n = JAS_MIN(mqenc->maxctxs, numctxs);
+ while (--n >= 0) {
+ *ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps];
+ ++ctx;
+ ++ctxs;
+ }
+ n = mqenc->maxctxs - numctxs;
+ while (--n >= 0) {
+ *ctx = &jpc_mqstates[0];
+ ++ctx;
+ }
+
+}
+
+/* Get the coding state for a MQ encoder. */
+
+void jpc_mqenc_getstate(jpc_mqenc_t *mqenc, jpc_mqencstate_t *state)
+{
+ state->areg = mqenc->areg;
+ state->creg = mqenc->creg;
+ state->ctreg = mqenc->ctreg;
+ state->lastbyte = mqenc->lastbyte;
+}
+
+/******************************************************************************\
+* Code for coding symbols.
+\******************************************************************************/
+
+/* Encode a bit. */
+
+int jpc_mqenc_putbit_func(jpc_mqenc_t *mqenc, int bit)
+{
+ const jpc_mqstate_t *state;
+ JAS_DBGLOG(100, ("jpc_mqenc_putbit(%p, %d)\n", mqenc, bit));
+ JPC_MQENC_CALL(100, jpc_mqenc_dump(mqenc, stderr));
+
+ state = *(mqenc->curctx);
+
+ if (state->mps == bit) {
+ /* Apply the CODEMPS algorithm as defined in the standard. */
+ mqenc->areg -= state->qeval;
+ if (!(mqenc->areg & 0x8000)) {
+ jpc_mqenc_codemps2(mqenc);
+ } else {
+ mqenc->creg += state->qeval;
+ }
+ } else {
+ /* Apply the CODELPS algorithm as defined in the standard. */
+ jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc);
+ }
+
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
+
+int jpc_mqenc_codemps2(jpc_mqenc_t *mqenc)
+{
+ /* Note: This function only performs part of the work associated with
+ the CODEMPS algorithm from the standard. Some of the work is also
+ performed by the caller. */
+
+ jpc_mqstate_t *state = *(mqenc->curctx);
+ if (mqenc->areg < state->qeval) {
+ mqenc->areg = state->qeval;
+ } else {
+ mqenc->creg += state->qeval;
+ }
+ *mqenc->curctx = state->nmps;
+ jpc_mqenc_renorme(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
+
+int jpc_mqenc_codelps(jpc_mqenc_t *mqenc)
+{
+ jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc);
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
+
+/******************************************************************************\
+* Miscellaneous code.
+\******************************************************************************/
+
+/* Terminate the code word. */
+
+int jpc_mqenc_flush(jpc_mqenc_t *mqenc, int termmode)
+{
+ int_fast16_t k;
+
+ switch (termmode) {
+ case JPC_MQENC_PTERM:
+ k = 11 - mqenc->ctreg + 1;
+ while (k > 0) {
+ mqenc->creg <<= mqenc->ctreg;
+ mqenc->ctreg = 0;
+ jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg,
+ mqenc);
+ k -= mqenc->ctreg;
+ }
+ if (mqenc->outbuf != 0xff) {
+ jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
+ }
+ break;
+ case JPC_MQENC_DEFTERM:
+ jpc_mqenc_setbits(mqenc);
+ mqenc->creg <<= mqenc->ctreg;
+ jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
+ mqenc->creg <<= mqenc->ctreg;
+ jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
+ if (mqenc->outbuf != 0xff) {
+ jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
+ }
+ break;
+ default:
+ abort();
+ break;
+ }
+ return 0;
+}
+
+static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc)
+{
+ uint_fast32_t tmp = mqenc->creg + mqenc->areg;
+ mqenc->creg |= 0xffff;
+ if (mqenc->creg >= tmp) {
+ mqenc->creg -= 0x8000;
+ }
+}
+
+/* Dump a MQ encoder to a stream for debugging. */
+
+int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out)
+{
+ fprintf(out, "AREG = %08x, CREG = %08x, CTREG = %d\n",
+ mqenc->areg, mqenc->creg, mqenc->ctreg);
+ fprintf(out, "IND = %02d, MPS = %d, QEVAL = %04x\n",
+ *mqenc->curctx - jpc_mqstates, (*mqenc->curctx)->mps,
+ (*mqenc->curctx)->qeval);
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_mqenc.h b/osframework/source/ImageLib/jpeg2000/jpc_mqenc.h
new file mode 100644
index 0000000..1ae218a
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_mqenc.h
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * MQ Arithmetic Encoder
+ *
+ * $Id: jpc_mqenc.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_MQENC_H
+#define JPC_MQENC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_types.h"
+#include "jas_stream.h"
+
+#include "jpc_mqcod.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/*
+ * Termination modes.
+ */
+
+#define JPC_MQENC_DEFTERM 0 /* default termination */
+#define JPC_MQENC_PTERM 1 /* predictable termination */
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* MQ arithmetic encoder class. */
+
+typedef struct {
+
+ /* The C register. */
+ uint_fast32_t creg;
+
+ /* The A register. */
+ uint_fast32_t areg;
+
+ /* The CT register. */
+ uint_fast32_t ctreg;
+
+ /* The maximum number of contexts. */
+ int maxctxs;
+
+ /* The per-context information. */
+ jpc_mqstate_t **ctxs;
+
+ /* The current context. */
+ jpc_mqstate_t **curctx;
+
+ /* The stream for encoder output. */
+ jas_stream_t *out;
+
+ /* The byte buffer (i.e., the B variable in the standard). */
+ int_fast16_t outbuf;
+
+ /* The last byte output. */
+ int_fast16_t lastbyte;
+
+ /* The error indicator. */
+ int err;
+
+} jpc_mqenc_t;
+
+/* MQ arithmetic encoder state information. */
+
+typedef struct {
+
+ /* The A register. */
+ unsigned areg;
+
+ /* The C register. */
+ unsigned creg;
+
+ /* The CT register. */
+ unsigned ctreg;
+
+ /* The last byte output by the encoder. */
+ int lastbyte;
+
+} jpc_mqencstate_t;
+
+/******************************************************************************\
+* Functions/macros for construction and destruction.
+\******************************************************************************/
+
+/* Create a MQ encoder. */
+jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out);
+
+/* Destroy a MQ encoder. */
+void jpc_mqenc_destroy(jpc_mqenc_t *enc);
+
+/******************************************************************************\
+* Functions/macros for initialization.
+\******************************************************************************/
+
+/* Initialize a MQ encoder. */
+void jpc_mqenc_init(jpc_mqenc_t *enc);
+
+/******************************************************************************\
+* Functions/macros for context manipulation.
+\******************************************************************************/
+
+/* Set the current context. */
+#define jpc_mqenc_setcurctx(enc, ctxno) \
+ ((enc)->curctx = &(enc)->ctxs[ctxno]);
+
+/* Set the state information for a particular context. */
+void jpc_mqenc_setctx(jpc_mqenc_t *enc, int ctxno, jpc_mqctx_t *ctx);
+
+/* Set the state information for multiple contexts. */
+void jpc_mqenc_setctxs(jpc_mqenc_t *enc, int numctxs, jpc_mqctx_t *ctxs);
+
+/******************************************************************************\
+* Miscellaneous functions/macros.
+\******************************************************************************/
+
+/* Get the error state of a MQ encoder. */
+#define jpc_mqenc_error(enc) \
+ ((enc)->err)
+
+/* Get the current encoder state. */
+void jpc_mqenc_getstate(jpc_mqenc_t *enc, jpc_mqencstate_t *state);
+
+/* Terminate the code. */
+int jpc_mqenc_flush(jpc_mqenc_t *enc, int termmode);
+
+/******************************************************************************\
+* Functions/macros for encoding bits.
+\******************************************************************************/
+
+/* Encode a bit. */
+#if !defined(DEBUG)
+#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_macro(enc, bit)
+#else
+#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_func(enc, bit)
+#endif
+
+/******************************************************************************\
+* Functions/macros for debugging.
+\******************************************************************************/
+
+int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out);
+
+/******************************************************************************\
+* Implementation-specific details.
+\******************************************************************************/
+
+/* Note: This macro is included only to satisfy the needs of
+ the mqenc_putbit macro. */
+#define jpc_mqenc_putbit_macro(enc, bit) \
+ (((*((enc)->curctx))->mps == (bit)) ? \
+ (((enc)->areg -= (*(enc)->curctx)->qeval), \
+ ((!((enc)->areg & 0x8000)) ? (jpc_mqenc_codemps2(enc)) : \
+ ((enc)->creg += (*(enc)->curctx)->qeval))) : \
+ jpc_mqenc_codelps(enc))
+
+/* Note: These function prototypes are included only to satisfy the
+ needs of the mqenc_putbit_macro macro. Do not call any of these
+ functions directly. */
+int jpc_mqenc_codemps2(jpc_mqenc_t *enc);
+int jpc_mqenc_codelps(jpc_mqenc_t *enc);
+
+/* Note: This function prototype is included only to satisfy the needs of
+ the mqenc_putbit macro. */
+int jpc_mqenc_putbit_func(jpc_mqenc_t *enc, int bit);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_qmfb.c b/osframework/source/ImageLib/jpeg2000/jpc_qmfb.c
new file mode 100644
index 0000000..0950f57
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_qmfb.c
@@ -0,0 +1,1171 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Quadrature Mirror-Image Filter Bank (QMFB) Library
+ *
+ * $Id: jpc_qmfb.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+
+#include "jas_fix.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+#include "jpc_qmfb.h"
+#include "jpc_tsfb.h"
+#include "jpc_math.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static jpc_qmfb1d_t *jpc_qmfb1d_create(void);
+
+static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb);
+static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb);
+static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+jpc_qmfb1dops_t jpc_ft_ops = {
+ jpc_ft_getnumchans,
+ jpc_ft_getanalfilters,
+ jpc_ft_getsynfilters,
+ jpc_ft_analyze,
+ jpc_ft_synthesize
+};
+
+jpc_qmfb1dops_t jpc_ns_ops = {
+ jpc_ns_getnumchans,
+ jpc_ns_getanalfilters,
+ jpc_ns_getsynfilters,
+ jpc_ns_analyze,
+ jpc_ns_synthesize
+};
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static void jpc_qmfb1d_setup(jpc_fix_t *startptr, int startind, int endind,
+ int intrastep, jpc_fix_t **lstartptr, int *lstartind, int *lendind,
+ jpc_fix_t **hstartptr, int *hstartind, int *hendind)
+{
+ *lstartind = JPC_CEILDIVPOW2(startind, 1);
+ *lendind = JPC_CEILDIVPOW2(endind, 1);
+ *hstartind = JPC_FLOORDIVPOW2(startind, 1);
+ *hendind = JPC_FLOORDIVPOW2(endind, 1);
+ *lstartptr = startptr;
+ *hstartptr = &startptr[(*lendind - *lstartind) * intrastep];
+}
+
+static void jpc_qmfb1d_split(jpc_fix_t *startptr, int startind, int endind,
+ register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
+ jpc_fix_t *hstartptr, int hstartind, int hendind)
+{
+ int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
+#if defined(WIN32)
+#define QMFB_SPLITBUFSIZE 4096
+ jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
+#else
+ jpc_fix_t splitbuf[bufsize];
+#endif
+ jpc_fix_t *buf = splitbuf;
+ int llen;
+ int hlen;
+ int twostep;
+ jpc_fix_t *tmpptr;
+ register jpc_fix_t *ptr;
+ register jpc_fix_t *hptr;
+ register jpc_fix_t *lptr;
+ register int n;
+ int state;
+
+ twostep = step << 1;
+ llen = lendind - lstartind;
+ hlen = hendind - hstartind;
+
+#if defined(WIN32)
+ /* Get a buffer. */
+ if (bufsize > QMFB_SPLITBUFSIZE) {
+ if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
+ /* We have no choice but to commit suicide in this case. */
+ abort();
+ }
+ }
+#endif
+
+ if (hstartind < lstartind) {
+ /* The first sample in the input signal is to appear
+ in the highpass subband signal. */
+ /* Copy the appropriate samples into the lowpass subband
+ signal, saving any samples destined for the highpass subband
+ signal as they are overwritten. */
+ tmpptr = buf;
+ ptr = &startptr[step];
+ lptr = lstartptr;
+ n = llen;
+ state = 1;
+ while (n-- > 0) {
+ if (state) {
+ *tmpptr = *lptr;
+ ++tmpptr;
+ }
+ *lptr = *ptr;
+ ptr += twostep;
+ lptr += step;
+ state ^= 1;
+ }
+ /* Copy the appropriate samples into the highpass subband
+ signal. */
+ /* Handle the nonoverwritten samples. */
+ hptr = &hstartptr[(hlen - 1) * step];
+ ptr = &startptr[(((llen + hlen - 1) >> 1) << 1) * step];
+ n = hlen - (tmpptr - buf);
+ while (n-- > 0) {
+ *hptr = *ptr;
+ hptr -= step;
+ ptr -= twostep;
+ }
+ /* Handle the overwritten samples. */
+ n = tmpptr - buf;
+ while (n-- > 0) {
+ --tmpptr;
+ *hptr = *tmpptr;
+ hptr -= step;
+ }
+ } else {
+ /* The first sample in the input signal is to appear
+ in the lowpass subband signal. */
+ /* Copy the appropriate samples into the lowpass subband
+ signal, saving any samples for the highpass subband
+ signal as they are overwritten. */
+ state = 0;
+ ptr = startptr;
+ lptr = lstartptr;
+ tmpptr = buf;
+ n = llen;
+ while (n-- > 0) {
+ if (state) {
+ *tmpptr = *lptr;
+ ++tmpptr;
+ }
+ *lptr = *ptr;
+ ptr += twostep;
+ lptr += step;
+ state ^= 1;
+ }
+ /* Copy the appropriate samples into the highpass subband
+ signal. */
+ /* Handle the nonoverwritten samples. */
+ ptr = &startptr[((((llen + hlen) >> 1) << 1) - 1) * step];
+ hptr = &hstartptr[(hlen - 1) * step];
+ n = hlen - (tmpptr - buf);
+ while (n-- > 0) {
+ *hptr = *ptr;
+ ptr -= twostep;
+ hptr -= step;
+ }
+ /* Handle the overwritten samples. */
+ n = tmpptr - buf;
+ while (n-- > 0) {
+ --tmpptr;
+ *hptr = *tmpptr;
+ hptr -= step;
+ }
+ }
+
+#if defined(WIN32)
+ /* If the split buffer was allocated on the heap, free this memory. */
+ if (buf != splitbuf) {
+ jas_free(buf);
+ }
+#endif
+}
+
+static void jpc_qmfb1d_join(jpc_fix_t *startptr, int startind, int endind,
+ register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
+ jpc_fix_t *hstartptr, int hstartind, int hendind)
+{
+ int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
+#if defined(WIN32)
+#define QMFB_JOINBUFSIZE 4096
+ jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
+#else
+ jpc_fix_t joinbuf[bufsize];
+#endif
+ jpc_fix_t *buf = joinbuf;
+ int llen;
+ int hlen;
+ int twostep;
+ jpc_fix_t *tmpptr;
+ register jpc_fix_t *ptr;
+ register jpc_fix_t *hptr;
+ register jpc_fix_t *lptr;
+ register int n;
+ int state;
+
+#if defined(WIN32)
+ /* Allocate memory for the join buffer from the heap. */
+ if (bufsize > QMFB_JOINBUFSIZE) {
+ if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
+ /* We have no choice but to commit suicide. */
+ abort();
+ }
+ }
+#endif
+
+ twostep = step << 1;
+ llen = lendind - lstartind;
+ hlen = hendind - hstartind;
+
+ if (hstartind < lstartind) {
+ /* The first sample in the highpass subband signal is to
+ appear first in the output signal. */
+ /* Copy the appropriate samples into the first phase of the
+ output signal. */
+ tmpptr = buf;
+ hptr = hstartptr;
+ ptr = startptr;
+ n = (llen + 1) >> 1;
+ while (n-- > 0) {
+ *tmpptr = *ptr;
+ *ptr = *hptr;
+ ++tmpptr;
+ ptr += twostep;
+ hptr += step;
+ }
+ n = hlen - ((llen + 1) >> 1);
+ while (n-- > 0) {
+ *ptr = *hptr;
+ ptr += twostep;
+ hptr += step;
+ }
+ /* Copy the appropriate samples into the second phase of
+ the output signal. */
+ ptr -= (lendind > hendind) ? (step) : (step + twostep);
+ state = !((llen - 1) & 1);
+ lptr = &lstartptr[(llen - 1) * step];
+ n = llen;
+ while (n-- > 0) {
+ if (state) {
+ --tmpptr;
+ *ptr = *tmpptr;
+ } else {
+ *ptr = *lptr;
+ }
+ lptr -= step;
+ ptr -= twostep;
+ state ^= 1;
+ }
+ } else {
+ /* The first sample in the lowpass subband signal is to
+ appear first in the output signal. */
+ /* Copy the appropriate samples into the first phase of the
+ output signal (corresponding to even indexed samples). */
+ lptr = &lstartptr[(llen - 1) * step];
+ ptr = &startptr[((llen - 1) << 1) * step];
+ n = llen >> 1;
+ tmpptr = buf;
+ while (n-- > 0) {
+ *tmpptr = *ptr;
+ *ptr = *lptr;
+ ++tmpptr;
+ ptr -= twostep;
+ lptr -= step;
+ }
+ n = llen - (llen >> 1);
+ while (n-- > 0) {
+ *ptr = *lptr;
+ ptr -= twostep;
+ lptr -= step;
+ }
+ /* Copy the appropriate samples into the second phase of
+ the output signal (corresponding to odd indexed
+ samples). */
+ ptr = &startptr[step];
+ hptr = hstartptr;
+ state = !(llen & 1);
+ n = hlen;
+ while (n-- > 0) {
+ if (state) {
+ --tmpptr;
+ *ptr = *tmpptr;
+ } else {
+ *ptr = *hptr;
+ }
+ hptr += step;
+ ptr += twostep;
+ state ^= 1;
+ }
+ }
+
+#if defined(WIN32)
+ /* If the join buffer was allocated on the heap, free this memory. */
+ if (buf != joinbuf) {
+ jas_free(buf);
+ }
+#endif
+}
+
+/******************************************************************************\
+* Code for 5/3 transform.
+\******************************************************************************/
+
+static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ return 2;
+}
+
+static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+ len = 0;
+ filters = 0;
+ abort();
+ return -1;
+}
+
+static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ jas_seq_t *lf;
+ jas_seq_t *hf;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ lf = 0;
+ hf = 0;
+
+ if (len > 1 || (!len)) {
+ if (!(lf = jas_seq_create(-1, 2))) {
+ goto error;
+ }
+ jas_seq_set(lf, -1, jpc_dbltofix(0.5));
+ jas_seq_set(lf, 0, jpc_dbltofix(1.0));
+ jas_seq_set(lf, 1, jpc_dbltofix(0.5));
+ if (!(hf = jas_seq_create(-1, 4))) {
+ goto error;
+ }
+ jas_seq_set(hf, -1, jpc_dbltofix(-0.125));
+ jas_seq_set(hf, 0, jpc_dbltofix(-0.25));
+ jas_seq_set(hf, 1, jpc_dbltofix(0.75));
+ jas_seq_set(hf, 2, jpc_dbltofix(-0.25));
+ jas_seq_set(hf, 3, jpc_dbltofix(-0.125));
+ } else if (len == 1) {
+ if (!(lf = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(lf, 0, jpc_dbltofix(1.0));
+ if (!(hf = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(hf, 0, jpc_dbltofix(2.0));
+ } else {
+ abort();
+ }
+
+ filters[0] = lf;
+ filters[1] = hf;
+
+ return 0;
+
+error:
+ if (lf) {
+ jas_seq_destroy(lf);
+ }
+ if (hf) {
+ jas_seq_destroy(hf);
+ }
+ return -1;
+}
+
+#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (hendind) - (hstartind); \
+ if ((hstartind) < (lstartind)) { \
+ pluseq(*hptr, *lptr); \
+ hptr += (step); \
+ --n; \
+ } \
+ if ((hendind) >= (lendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \
+ hptr += (step); \
+ lptr += (step); \
+ } \
+ if ((hendind) >= (lendind)) { \
+ pluseq(*hptr, *lptr); \
+ } \
+}
+
+#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (lendind) - (lstartind); \
+ if ((hstartind) >= (lstartind)) { \
+ pluseq(*lptr, *hptr); \
+ lptr += (step); \
+ --n; \
+ } \
+ if ((lendind) > (hendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \
+ lptr += (step); \
+ hptr += (step); \
+ } \
+ if ((lendind) > (hendind)) { \
+ pluseq(*lptr, *hptr); \
+ } \
+}
+
+#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (hendind) - (hstartind); \
+ if ((hstartind) < (lstartind)) { \
+ *hptr pmeqop *lptr; \
+ hptr += (step); \
+ --n; \
+ } \
+ if ((hendind) >= (lendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ *hptr pmeqop (*lptr + lptr[(step)]) >> 1; \
+ hptr += (step); \
+ lptr += (step); \
+ } \
+ if ((hendind) >= (lendind)) { \
+ *hptr pmeqop *lptr; \
+ } \
+}
+
+#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (lendind) - (lstartind); \
+ if ((hstartind) >= (lstartind)) { \
+ *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
+ lptr += (step); \
+ --n; \
+ } \
+ if ((lendind) > (hendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ *lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \
+ lptr += (step); \
+ hptr += (step); \
+ } \
+ if ((lendind) > (hendind)) { \
+ *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
+ } \
+}
+
+static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ jpc_fix_t *startptr;
+ int startind;
+ int endind;
+ jpc_fix_t * lstartptr;
+ int lstartind;
+ int lendind;
+ jpc_fix_t * hstartptr;
+ int hstartind;
+ int hendind;
+ int interstep;
+ int intrastep;
+ int numseq;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ if (flags & JPC_QMFB1D_VERT) {
+ interstep = 1;
+ intrastep = jas_seq2d_rowstep(x);
+ numseq = jas_seq2d_width(x);
+ startind = jas_seq2d_ystart(x);
+ endind = jas_seq2d_yend(x);
+ } else {
+ interstep = jas_seq2d_rowstep(x);
+ intrastep = 1;
+ numseq = jas_seq2d_height(x);
+ startind = jas_seq2d_xstart(x);
+ endind = jas_seq2d_xend(x);
+ }
+
+ assert(startind < endind);
+
+ startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
+ if (flags & JPC_QMFB1D_RITIMODE) {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ jpc_qmfb1d_split(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ RFT_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep, -=);
+ RFT_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep, +=);
+ } else {
+ if (lstartind == lendind) {
+ *startptr <<= 1;
+ }
+ }
+ startptr += interstep;
+ }
+ } else {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ jpc_qmfb1d_split(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ NFT_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_fix_minuseq);
+ NFT_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_fix_pluseq);
+ } else {
+ if (lstartind == lendind) {
+ *startptr = jpc_fix_asl(*startptr, 1);
+ }
+ }
+ startptr += interstep;
+ }
+ }
+}
+
+static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ jpc_fix_t *startptr;
+ int startind;
+ int endind;
+ jpc_fix_t *lstartptr;
+ int lstartind;
+ int lendind;
+ jpc_fix_t *hstartptr;
+ int hstartind;
+ int hendind;
+ int interstep;
+ int intrastep;
+ int numseq;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ if (flags & JPC_QMFB1D_VERT) {
+ interstep = 1;
+ intrastep = jas_seq2d_rowstep(x);
+ numseq = jas_seq2d_width(x);
+ startind = jas_seq2d_ystart(x);
+ endind = jas_seq2d_yend(x);
+ } else {
+ interstep = jas_seq2d_rowstep(x);
+ intrastep = 1;
+ numseq = jas_seq2d_height(x);
+ startind = jas_seq2d_xstart(x);
+ endind = jas_seq2d_xend(x);
+ }
+
+ assert(startind < endind);
+
+ startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
+ if (flags & JPC_QMFB1D_RITIMODE) {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ RFT_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep, -=);
+ RFT_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep, +=);
+ jpc_qmfb1d_join(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ } else {
+ if (lstartind == lendind) {
+ *startptr >>= 1;
+ }
+ }
+ startptr += interstep;
+ }
+ } else {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ NFT_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_fix_minuseq);
+ NFT_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_fix_pluseq);
+ jpc_qmfb1d_join(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ } else {
+ if (lstartind == lendind) {
+ *startptr = jpc_fix_asr(*startptr, 1);
+ }
+ }
+ startptr += interstep;
+ }
+ }
+}
+
+/******************************************************************************\
+* Code for 9/7 transform.
+\******************************************************************************/
+
+static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ return 2;
+}
+
+static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+ len = 0;
+ filters = 0;
+
+ abort();
+ return -1;
+}
+
+static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ jas_seq_t *lf;
+ jas_seq_t *hf;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ lf = 0;
+ hf = 0;
+
+ if (len > 1 || (!len)) {
+ if (!(lf = jas_seq_create(-3, 4))) {
+ goto error;
+ }
+ jas_seq_set(lf, -3, jpc_dbltofix(-0.09127176311424948));
+ jas_seq_set(lf, -2, jpc_dbltofix(-0.05754352622849957));
+ jas_seq_set(lf, -1, jpc_dbltofix(0.5912717631142470));
+ jas_seq_set(lf, 0, jpc_dbltofix(1.115087052456994));
+ jas_seq_set(lf, 1, jpc_dbltofix(0.5912717631142470));
+ jas_seq_set(lf, 2, jpc_dbltofix(-0.05754352622849957));
+ jas_seq_set(lf, 3, jpc_dbltofix(-0.09127176311424948));
+ if (!(hf = jas_seq_create(-3, 6))) {
+ goto error;
+ }
+ jas_seq_set(hf, -3, jpc_dbltofix(-0.02674875741080976 * 2.0));
+ jas_seq_set(hf, -2, jpc_dbltofix(-0.01686411844287495 * 2.0));
+ jas_seq_set(hf, -1, jpc_dbltofix(0.07822326652898785 * 2.0));
+ jas_seq_set(hf, 0, jpc_dbltofix(0.2668641184428723 * 2.0));
+ jas_seq_set(hf, 1, jpc_dbltofix(-0.6029490182363579 * 2.0));
+ jas_seq_set(hf, 2, jpc_dbltofix(0.2668641184428723 * 2.0));
+ jas_seq_set(hf, 3, jpc_dbltofix(0.07822326652898785 * 2.0));
+ jas_seq_set(hf, 4, jpc_dbltofix(-0.01686411844287495 * 2.0));
+ jas_seq_set(hf, 5, jpc_dbltofix(-0.02674875741080976 * 2.0));
+ } else if (len == 1) {
+ if (!(lf = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(lf, 0, jpc_dbltofix(1.0));
+ if (!(hf = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(hf, 0, jpc_dbltofix(2.0));
+ } else {
+ abort();
+ }
+
+ filters[0] = lf;
+ filters[1] = hf;
+
+ return 0;
+
+error:
+ if (lf) {
+ jas_seq_destroy(lf);
+ }
+ if (hf) {
+ jas_seq_destroy(hf);
+ }
+ return -1;
+}
+
+#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (hendind) - (hstartind); \
+ jpc_fix_t twoalpha = jpc_fix_mulbyint(alpha, 2); \
+ if ((hstartind) < (lstartind)) { \
+ jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
+ hptr += (step); \
+ --n; \
+ } \
+ if ((hendind) >= (lendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \
+ hptr += (step); \
+ lptr += (step); \
+ } \
+ if ((hendind) >= (lendind)) { \
+ jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
+ } \
+}
+
+#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
+{ \
+ register jpc_fix_t *lptr = (lstartptr); \
+ register jpc_fix_t *hptr = (hstartptr); \
+ register int n = (lendind) - (lstartind); \
+ int twoalpha = jpc_fix_mulbyint(alpha, 2); \
+ if ((hstartind) >= (lstartind)) { \
+ jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
+ lptr += (step); \
+ --n; \
+ } \
+ if ((lendind) > (hendind)) { \
+ --n; \
+ } \
+ while (n-- > 0) { \
+ jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \
+ lptr += (step); \
+ hptr += (step); \
+ } \
+ if ((lendind) > (hendind)) { \
+ jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
+ } \
+}
+
+#define NNS_SCALE(startptr, startind, endind, step, alpha) \
+{ \
+ register jpc_fix_t *ptr = (startptr); \
+ register int n = (endind) - (startind); \
+ while (n-- > 0) { \
+ jpc_fix_muleq(*ptr, alpha); \
+ ptr += (step); \
+ } \
+}
+
+static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ jpc_fix_t *startptr;
+ int startind;
+ int endind;
+ jpc_fix_t *lstartptr;
+ int lstartind;
+ int lendind;
+ jpc_fix_t *hstartptr;
+ int hstartind;
+ int hendind;
+ int interstep;
+ int intrastep;
+ int numseq;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ if (flags & JPC_QMFB1D_VERT) {
+ interstep = 1;
+ intrastep = jas_seq2d_rowstep(x);
+ numseq = jas_seq2d_width(x);
+ startind = jas_seq2d_ystart(x);
+ endind = jas_seq2d_yend(x);
+ } else {
+ interstep = jas_seq2d_rowstep(x);
+ intrastep = 1;
+ numseq = jas_seq2d_height(x);
+ startind = jas_seq2d_xstart(x);
+ endind = jas_seq2d_xend(x);
+ }
+
+ assert(startind < endind);
+
+ startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
+ if (!(flags & JPC_QMFB1D_RITIMODE)) {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ jpc_qmfb1d_split(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ NNS_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(-1.586134342));
+ NNS_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(-0.052980118));
+ NNS_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(0.882911075));
+ NNS_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(0.443506852));
+ NNS_SCALE(lstartptr, lstartind, lendind,
+ intrastep, jpc_dbltofix(1.0/1.23017410558578));
+ NNS_SCALE(hstartptr, hstartind, hendind,
+ intrastep, jpc_dbltofix(1.0/1.62578613134411));
+ } else {
+#if 0
+ if (lstartind == lendind) {
+ *startptr = jpc_fix_asl(*startptr, 1);
+ }
+#endif
+ }
+ startptr += interstep;
+ }
+ } else {
+ /* The reversible integer-to-integer mode is not supported
+ for this transform. */
+ abort();
+ }
+}
+
+static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ jpc_fix_t *startptr;
+ int startind;
+ int endind;
+ jpc_fix_t *lstartptr;
+ int lstartind;
+ int lendind;
+ jpc_fix_t *hstartptr;
+ int hstartind;
+ int hendind;
+ int interstep;
+ int intrastep;
+ int numseq;
+
+ /* Avoid compiler warnings about unused parameters. */
+ qmfb = 0;
+
+ if (flags & JPC_QMFB1D_VERT) {
+ interstep = 1;
+ intrastep = jas_seq2d_rowstep(x);
+ numseq = jas_seq2d_width(x);
+ startind = jas_seq2d_ystart(x);
+ endind = jas_seq2d_yend(x);
+ } else {
+ interstep = jas_seq2d_rowstep(x);
+ intrastep = 1;
+ numseq = jas_seq2d_height(x);
+ startind = jas_seq2d_xstart(x);
+ endind = jas_seq2d_xend(x);
+ }
+
+ assert(startind < endind);
+
+ startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
+ if (!(flags & JPC_QMFB1D_RITIMODE)) {
+ while (numseq-- > 0) {
+ jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
+ &lstartptr, &lstartind, &lendind, &hstartptr,
+ &hstartind, &hendind);
+ if (endind - startind > 1) {
+ NNS_SCALE(lstartptr, lstartind, lendind,
+ intrastep, jpc_dbltofix(1.23017410558578));
+ NNS_SCALE(hstartptr, hstartind, hendind,
+ intrastep, jpc_dbltofix(1.62578613134411));
+ NNS_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(-0.443506852));
+ NNS_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(-0.882911075));
+ NNS_LIFT1(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(0.052980118));
+ NNS_LIFT0(lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind, intrastep,
+ jpc_dbltofix(1.586134342));
+ jpc_qmfb1d_join(startptr, startind, endind,
+ intrastep, lstartptr, lstartind, lendind,
+ hstartptr, hstartind, hendind);
+ } else {
+#if 0
+ if (lstartind == lendind) {
+ *startptr = jpc_fix_asr(*startptr, 1);
+ }
+#endif
+ }
+ startptr += interstep;
+ }
+ } else {
+ /* The reversible integer-to-integer mode is not supported
+ for this transform. */
+ abort();
+ }
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid)
+{
+ jpc_qmfb1d_t *qmfb;
+ if (!(qmfb = jpc_qmfb1d_create())) {
+ return 0;
+ }
+ switch (qmfbid) {
+ case JPC_QMFB1D_FT:
+ qmfb->ops = &jpc_ft_ops;
+ break;
+ case JPC_QMFB1D_NS:
+ qmfb->ops = &jpc_ns_ops;
+ break;
+ default:
+ jpc_qmfb1d_destroy(qmfb);
+ return 0;
+ break;
+ }
+ return qmfb;
+}
+
+static jpc_qmfb1d_t *jpc_qmfb1d_create()
+{
+ jpc_qmfb1d_t *qmfb;
+ if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {
+ return 0;
+ }
+ qmfb->ops = 0;
+ return qmfb;
+}
+
+jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb)
+{
+ jpc_qmfb1d_t *newqmfb;
+
+ if (!(newqmfb = jpc_qmfb1d_create())) {
+ return 0;
+ }
+ newqmfb->ops = qmfb->ops;
+ return newqmfb;
+}
+
+void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb)
+{
+ jas_free(qmfb);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart,
+ uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands,
+ int *numbandsptr, jpc_qmfb1dband_t *bands)
+{
+ int start;
+ int end;
+
+ assert(maxbands >= 2);
+
+ if (flags & JPC_QMFB1D_VERT) {
+ start = ystart;
+ end = yend;
+ } else {
+ start = xstart;
+ end = xend;
+ }
+ assert(jpc_qmfb1d_getnumchans(qmfb) == 2);
+ assert(start <= end);
+ bands[0].start = JPC_CEILDIVPOW2(start, 1);
+ bands[0].end = JPC_CEILDIVPOW2(end, 1);
+ bands[0].locstart = start;
+ bands[0].locend = start + bands[0].end - bands[0].start;
+ bands[1].start = JPC_FLOORDIVPOW2(start, 1);
+ bands[1].end = JPC_FLOORDIVPOW2(end, 1);
+ bands[1].locstart = bands[0].locend;
+ bands[1].locend = bands[1].locstart + bands[1].end - bands[1].start;
+ assert(bands[1].locend == end);
+ *numbandsptr = 2;
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb)
+{
+ return (*qmfb->ops->getnumchans)(qmfb);
+}
+
+int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ return (*qmfb->ops->getanalfilters)(qmfb, len, filters);
+}
+
+int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
+{
+ return (*qmfb->ops->getsynfilters)(qmfb, len, filters);
+}
+
+void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ (*qmfb->ops->analyze)(qmfb, flags, x);
+}
+
+void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
+{
+ (*qmfb->ops->synthesize)(qmfb, flags, x);
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_qmfb.h b/osframework/source/ImageLib/jpeg2000/jpc_qmfb.h
new file mode 100644
index 0000000..e6edc9b
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_qmfb.h
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Quadrature Mirror-Image Filter Bank (QMFB) Routines
+ *
+ * $Id: jpc_qmfb.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_QMFB_H
+#define JPC_QMFB_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_seq.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* The maximum number of channels for a QMF bank. */
+#define JPC_QMFB1D_MAXCHANS 2
+
+/* Select reversible integer-to-integer mode. */
+#define JPC_QMFB1D_RITIMODE 1
+
+/* Vertical filtering. */
+#define JPC_QMFB1D_VERT 0x10000
+
+/* QMFB IDs. */
+#define JPC_QMFB1D_FT 1 /* 5/3 */
+#define JPC_QMFB1D_NS 2 /* 9/7 */
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Forward declaration. */
+struct jpc_qmfb1dops_s;
+
+/* Band information. */
+
+typedef struct {
+
+ /* The starting index for the band in the downsampled domain. */
+ int start;
+
+ /* The ending index for the band in the downsampled domain. */
+ int end;
+
+ /* The location of the start of the band. */
+ int locstart;
+
+ /* The location of the end of the band. */
+ int locend;
+
+} jpc_qmfb1dband_t;
+
+/* QMF bank */
+
+typedef struct {
+
+ /* The operations for this QMFB. */
+ struct jpc_qmfb1dops_s *ops;
+
+} jpc_qmfb1d_t;
+
+/* QMFB operations. */
+
+typedef struct jpc_qmfb1dops_s {
+
+ /* The number of channels in the QMFB. */
+ int (*getnumchans)(jpc_qmfb1d_t *qmfb);
+
+ /* Get the analysis filters for this QMFB. */
+ int (*getanalfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+
+ /* Get the synthesis filters for this QMFB. */
+ int (*getsynfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
+
+ /* Do analysis. */
+ void (*analyze)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+ /* Do synthesis. */
+ void (*synthesize)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+} jpc_qmfb1dops_t;
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Create a QMFB from a QMFB ID. */
+jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid);
+
+/* Create a copy of a QMFB. */
+jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb);
+
+/* Destroy a QMFB. */
+void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb);
+
+/* Get the number of channels for a QMFB. */
+int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb);
+
+/* Get the analysis filters for a QMFB. */
+int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len,
+ jas_seq2d_t **filters);
+
+/* Get the synthesis filters for a QMFB. */
+int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len,
+ jas_seq2d_t **filters);
+
+/* Get the bands for a QMFB. */
+void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart,
+ uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands,
+ int *numbandsptr, jpc_qmfb1dband_t *bands);
+
+/* Perform analysis. */
+void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+/* Perform synthesis. */
+void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1cod.c b/osframework/source/ImageLib/jpeg2000/jpc_t1cod.c
new file mode 100644
index 0000000..972a563
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1cod.c
@@ -0,0 +1,546 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_t1cod.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <math.h>
+
+#include "jas_types.h"
+#include "jas_math.h"
+
+#include "jpc_bs.h"
+#include "jpc_dec.h"
+#include "jpc_cs.h"
+#include "jpc_mqcod.h"
+#include "jpc_t1cod.h"
+#include "jpc_tsfb.h"
+
+double jpc_pow2i(int n);
+
+/******************************************************************************\
+* Global data.
+\******************************************************************************/
+
+int jpc_zcctxnolut[4 * 256];
+int jpc_spblut[256];
+int jpc_scctxnolut[256];
+int jpc_magctxnolut[4096];
+
+jpc_fix_t jpc_signmsedec[1 << JPC_NMSEDEC_BITS];
+jpc_fix_t jpc_refnmsedec[1 << JPC_NMSEDEC_BITS];
+jpc_fix_t jpc_signmsedec0[1 << JPC_NMSEDEC_BITS];
+jpc_fix_t jpc_refnmsedec0[1 << JPC_NMSEDEC_BITS];
+
+jpc_mqctx_t jpc_mqctxs[JPC_NUMCTXS];
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+void jpc_initmqctxs(void);
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+int JPC_PASSTYPE(int passno)
+{
+ int passtype;
+ switch (passno % 3) {
+ case 0:
+ passtype = JPC_CLNPASS;
+ break;
+ case 1:
+ passtype = JPC_SIGPASS;
+ break;
+ case 2:
+ passtype = JPC_REFPASS;
+ break;
+ default:
+ passtype = -1;
+ assert(0);
+ break;
+ }
+ return passtype;
+}
+
+int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient)
+{
+ /* Avoid compiler warnings about unused parameters. */
+ numlvls = 0;
+
+if (qmfbid == JPC_COX_INS) {
+ return 0;
+}
+ assert(qmfbid == JPC_COX_RFT);
+ if (lvlno == 0) {
+ assert(orient == JPC_TSFB_LL);
+ return 0;
+ } else {
+ switch (orient) {
+ case JPC_TSFB_LH:
+ case JPC_TSFB_HL:
+ return 1;
+ break;
+ case JPC_TSFB_HH:
+ return 2;
+ break;
+ }
+ }
+ abort();
+}
+
+/******************************************************************************\
+* Coding pass related functions.
+\******************************************************************************/
+
+int JPC_SEGTYPE(int passno, int firstpassno, int bypass)
+{
+ int passtype;
+ if (bypass) {
+ passtype = JPC_PASSTYPE(passno);
+ if (passtype == JPC_CLNPASS) {
+ return JPC_SEG_MQ;
+ }
+ return ((passno < firstpassno + 10) ? JPC_SEG_MQ : JPC_SEG_RAW);
+ } else {
+ return JPC_SEG_MQ;
+ }
+}
+
+int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass, int termall)
+{
+ int ret;
+ int passtype;
+
+ if (termall) {
+ ret = 1;
+ } else if (bypass) {
+ if (passno < firstpassno + 10) {
+ ret = 10 - (passno - firstpassno);
+ } else {
+ passtype = JPC_PASSTYPE(passno);
+ switch (passtype) {
+ case JPC_SIGPASS:
+ ret = 2;
+ break;
+ case JPC_REFPASS:
+ ret = 1;
+ break;
+ case JPC_CLNPASS:
+ ret = 1;
+ break;
+ default:
+ ret = -1;
+ assert(0);
+ break;
+ }
+ }
+ } else {
+ ret = JPC_PREC * 3 - 2;
+ }
+ ret = JAS_MIN(ret, numpasses - passno);
+ return ret;
+}
+
+int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,
+ int lazy)
+{
+ int ret;
+ int n;
+ if (passno - firstpassno == numpasses - 1) {
+ ret = 1;
+ } else {
+ n = JPC_SEGPASSCNT(passno, firstpassno, numpasses, lazy, termall);
+ ret = (n <= 1) ? 1 : 0;
+ }
+
+ return ret;
+}
+
+/******************************************************************************\
+* Lookup table code.
+\******************************************************************************/
+
+void jpc_initluts()
+{
+ int i;
+ int orient;
+ int refine;
+ float u;
+ float v;
+ float t;
+
+/* XXX - hack */
+jpc_initmqctxs();
+
+ for (orient = 0; orient < 4; ++orient) {
+ for (i = 0; i < 256; ++i) {
+ jpc_zcctxnolut[(orient << 8) | i] = jpc_getzcctxno(i, orient);
+ }
+ }
+
+ for (i = 0; i < 256; ++i) {
+ jpc_spblut[i] = jpc_getspb(i << 4);
+ }
+
+ for (i = 0; i < 256; ++i) {
+ jpc_scctxnolut[i] = jpc_getscctxno(i << 4);
+ }
+
+ for (refine = 0; refine < 2; ++refine) {
+ for (i = 0; i < 2048; ++i) {
+ jpc_magctxnolut[(refine << 11) + i] = jpc_getmagctxno((refine ? JPC_REFINE : 0) | i);
+ }
+ }
+
+ for (i = 0; i < (1 << JPC_NMSEDEC_BITS); ++i) {
+ t = i * jpc_pow2i(-JPC_NMSEDEC_FRACBITS);
+ u = t;
+ v = t - 1.5;
+ jpc_signmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
+/* XXX - this calc is not correct */
+ jpc_signmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
+ u = t - 1.0;
+ if (i & (1 << (JPC_NMSEDEC_BITS - 1))) {
+ v = t - 1.5;
+ } else {
+ v = t - 0.5;
+ }
+ jpc_refnmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
+/* XXX - this calc is not correct */
+ jpc_refnmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
+ }
+}
+
+jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos)
+{
+ jpc_fix_t y;
+ assert(!(x & (~JAS_ONES(bitpos + 1))));
+ y = jpc_getsignmsedec_macro(x, bitpos);
+ return y;
+}
+
+int jpc_getzcctxno(int f, int orient)
+{
+ int h;
+ int v;
+ int d;
+ int n;
+ int t;
+ int hv;
+
+ /* Avoid compiler warning. */
+ n = 0;
+
+ h = ((f & JPC_WSIG) != 0) + ((f & JPC_ESIG) != 0);
+ v = ((f & JPC_NSIG) != 0) + ((f & JPC_SSIG) != 0);
+ d = ((f & JPC_NWSIG) != 0) + ((f & JPC_NESIG) != 0) + ((f & JPC_SESIG) != 0) + ((f & JPC_SWSIG) != 0);
+ switch (orient) {
+ case JPC_TSFB_HL:
+ t = h;
+ h = v;
+ v = t;
+ case JPC_TSFB_LL:
+ case JPC_TSFB_LH:
+ if (!h) {
+ if (!v) {
+ if (!d) {
+ n = 0;
+ } else if (d == 1) {
+ n = 1;
+ } else {
+ n = 2;
+ }
+ } else if (v == 1) {
+ n = 3;
+ } else {
+ n = 4;
+ }
+ } else if (h == 1) {
+ if (!v) {
+ if (!d) {
+ n = 5;
+ } else {
+ n = 6;
+ }
+ } else {
+ n = 7;
+ }
+ } else {
+ n = 8;
+ }
+ break;
+ case JPC_TSFB_HH:
+ hv = h + v;
+ if (!d) {
+ if (!hv) {
+ n = 0;
+ } else if (hv == 1) {
+ n = 1;
+ } else {
+ n = 2;
+ }
+ } else if (d == 1) {
+ if (!hv) {
+ n = 3;
+ } else if (hv == 1) {
+ n = 4;
+ } else {
+ n = 5;
+ }
+ } else if (d == 2) {
+ if (!hv) {
+ n = 6;
+ } else {
+ n = 7;
+ }
+ } else {
+ n = 8;
+ }
+ break;
+ }
+ assert(n < JPC_NUMZCCTXS);
+ return JPC_ZCCTXNO + n;
+}
+
+int jpc_getspb(int f)
+{
+ int hc;
+ int vc;
+ int n;
+
+ hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG), 1) -
+ JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) + ((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1);
+ vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG), 1) -
+ JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) + ((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1);
+ if (!hc && !vc) {
+ n = 0;
+ } else {
+ n = (!(hc > 0 || (!hc && vc > 0)));
+ }
+ return n;
+}
+
+int jpc_getscctxno(int f)
+{
+ int hc;
+ int vc;
+ int n;
+
+ /* Avoid compiler warning. */
+ n = 0;
+
+ hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG),
+ 1) - JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) +
+ ((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1);
+ vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG),
+ 1) - JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) +
+ ((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1);
+ assert(hc >= -1 && hc <= 1 && vc >= -1 && vc <= 1);
+ if (hc < 0) {
+ hc = -hc;
+ vc = -vc;
+ }
+ if (!hc) {
+ if (vc == -1) {
+ n = 1;
+ } else if (!vc) {
+ n = 0;
+ } else {
+ n = 1;
+ }
+ } else if (hc == 1) {
+ if (vc == -1) {
+ n = 2;
+ } else if (!vc) {
+ n = 3;
+ } else {
+ n = 4;
+ }
+ }
+ assert(n < JPC_NUMSCCTXS);
+ return JPC_SCCTXNO + n;
+}
+
+int jpc_getmagctxno(int f)
+{
+ int n;
+
+ if (!(f & JPC_REFINE)) {
+ n = (f & (JPC_OTHSIGMSK)) ? 1 : 0;
+ } else {
+ n = 2;
+ }
+
+ assert(n < JPC_NUMMAGCTXS);
+ return JPC_MAGCTXNO + n;
+}
+
+void jpc_initctxs(jpc_mqctx_t *ctxs)
+{
+ jpc_mqctx_t *ctx;
+ int i;
+
+ ctx = ctxs;
+ for (i = 0; i < JPC_NUMCTXS; ++i) {
+ ctx->mps = 0;
+ switch (i) {
+ case JPC_UCTXNO:
+ ctx->ind = 46;
+ break;
+ case JPC_ZCCTXNO:
+ ctx->ind = 4;
+ break;
+ case JPC_AGGCTXNO:
+ ctx->ind = 3;
+ break;
+ default:
+ ctx->ind = 0;
+ break;
+ }
+ ++ctx;
+ }
+}
+
+void jpc_initmqctxs()
+{
+ jpc_initctxs(jpc_mqctxs);
+}
+
+/* Calculate the real quantity exp2(n), where x is an integer. */
+double jpc_pow2i(int n)
+{
+ double x;
+ double a;
+
+ x = 1.0;
+ if (n < 0) {
+ a = 0.5;
+ n = -n;
+ } else {
+ a = 2.0;
+ }
+ while (--n >= 0) {
+ x *= a;
+ }
+ return x;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1cod.h b/osframework/source/ImageLib/jpeg2000/jpc_t1cod.h
new file mode 100644
index 0000000..ad9b41f
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1cod.h
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_t1cod.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T1COD_H
+#define JPC_T1COD_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_fix.h"
+#include "jas_math.h"
+
+#include "jpc_mqcod.h"
+#include "jpc_tsfb.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+/* The number of bits used to index into various lookup tables. */
+#define JPC_NMSEDEC_BITS 7
+#define JPC_NMSEDEC_FRACBITS (JPC_NMSEDEC_BITS - 1)
+
+/*
+ * Segment types.
+ */
+
+/* Invalid. */
+#define JPC_SEG_INVALID 0
+/* MQ. */
+#define JPC_SEG_MQ 1
+/* Raw. */
+#define JPC_SEG_RAW 2
+
+/* The nominal word size. */
+#define JPC_PREC 32
+
+/* Tier-1 coding pass types. */
+#define JPC_SIGPASS 0 /* significance */
+#define JPC_REFPASS 1 /* refinement */
+#define JPC_CLNPASS 2 /* cleanup */
+
+/*
+ * Per-sample state information for tier-1 coding.
+ */
+
+/* The northeast neighbour has been found to be significant. */
+#define JPC_NESIG 0x0001
+/* The southeast neighbour has been found to be significant. */
+#define JPC_SESIG 0x0002
+/* The southwest neighbour has been found to be significant. */
+#define JPC_SWSIG 0x0004
+/* The northwest neighbour has been found to be significant. */
+#define JPC_NWSIG 0x0008
+/* The north neighbour has been found to be significant. */
+#define JPC_NSIG 0x0010
+/* The east neighbour has been found to be significant. */
+#define JPC_ESIG 0x0020
+/* The south neighbour has been found to be significant. */
+#define JPC_SSIG 0x0040
+/* The west neighbour has been found to be significant. */
+#define JPC_WSIG 0x0080
+/* The significance mask for 8-connected neighbours. */
+#define JPC_OTHSIGMSK \
+ (JPC_NSIG | JPC_NESIG | JPC_ESIG | JPC_SESIG | JPC_SSIG | JPC_SWSIG | JPC_WSIG | JPC_NWSIG)
+/* The significance mask for 4-connected neighbours. */
+#define JPC_PRIMSIGMSK (JPC_NSIG | JPC_ESIG | JPC_SSIG | JPC_WSIG)
+
+/* The north neighbour is negative in value. */
+#define JPC_NSGN 0x0100
+/* The east neighbour is negative in value. */
+#define JPC_ESGN 0x0200
+/* The south neighbour is negative in value. */
+#define JPC_SSGN 0x0400
+/* The west neighbour is negative in value. */
+#define JPC_WSGN 0x0800
+/* The sign mask for 4-connected neighbours. */
+#define JPC_SGNMSK (JPC_NSGN | JPC_ESGN | JPC_SSGN | JPC_WSGN)
+
+/* This sample has been found to be significant. */
+#define JPC_SIG 0x1000
+/* The sample has been refined. */
+#define JPC_REFINE 0x2000
+/* This sample has been processed during the significance pass. */
+#define JPC_VISIT 0x4000
+
+/* The number of aggregation contexts. */
+#define JPC_NUMAGGCTXS 1
+/* The number of zero coding contexts. */
+#define JPC_NUMZCCTXS 9
+/* The number of magnitude contexts. */
+#define JPC_NUMMAGCTXS 3
+/* The number of sign coding contexts. */
+#define JPC_NUMSCCTXS 5
+/* The number of uniform contexts. */
+#define JPC_NUMUCTXS 1
+
+/* The context ID for the first aggregation context. */
+#define JPC_AGGCTXNO 0
+/* The context ID for the first zero coding context. */
+#define JPC_ZCCTXNO (JPC_AGGCTXNO + JPC_NUMAGGCTXS)
+/* The context ID for the first magnitude context. */
+#define JPC_MAGCTXNO (JPC_ZCCTXNO + JPC_NUMZCCTXS)
+/* The context ID for the first sign coding context. */
+#define JPC_SCCTXNO (JPC_MAGCTXNO + JPC_NUMMAGCTXS)
+/* The context ID for the first uniform context. */
+#define JPC_UCTXNO (JPC_SCCTXNO + JPC_NUMSCCTXS)
+/* The total number of contexts. */
+#define JPC_NUMCTXS (JPC_UCTXNO + JPC_NUMUCTXS)
+
+/******************************************************************************\
+* External data.
+\******************************************************************************/
+
+/* These lookup tables are used by various macros/functions. */
+/* Do not access these lookup tables directly. */
+extern int jpc_zcctxnolut[];
+extern int jpc_spblut[];
+extern int jpc_scctxnolut[];
+extern int jpc_magctxnolut[];
+extern jpc_fix_t jpc_refnmsedec[];
+extern jpc_fix_t jpc_signmsedec[];
+extern jpc_fix_t jpc_refnmsedec0[];
+extern jpc_fix_t jpc_signmsedec0[];
+
+/* The initial settings for the MQ contexts. */
+extern jpc_mqctx_t jpc_mqctxs[];
+
+/******************************************************************************\
+* Functions and macros.
+\******************************************************************************/
+
+/* Initialize the MQ contexts. */
+void jpc_initctxs(jpc_mqctx_t *ctxs);
+
+/* Get the zero coding context. */
+int jpc_getzcctxno(int f, int orient);
+#define JPC_GETZCCTXNO(f, orient) \
+ (jpc_zcctxnolut[((orient) << 8) | ((f) & JPC_OTHSIGMSK)])
+
+/* Get the sign prediction bit. */
+int jpc_getspb(int f);
+#define JPC_GETSPB(f) \
+ (jpc_spblut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
+
+/* Get the sign coding context. */
+int jpc_getscctxno(int f);
+#define JPC_GETSCCTXNO(f) \
+ (jpc_scctxnolut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
+
+/* Get the magnitude context. */
+int jpc_getmagctxno(int f);
+#define JPC_GETMAGCTXNO(f) \
+ (jpc_magctxnolut[((f) & JPC_OTHSIGMSK) | ((((f) & JPC_REFINE) != 0) << 11)])
+
+/* Get the normalized MSE reduction for significance passes. */
+#define JPC_GETSIGNMSEDEC(x, bitpos) jpc_getsignmsedec_macro(x, bitpos)
+jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos);
+#define jpc_getsignmsedec_macro(x, bitpos) \
+ ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_signmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
+ (jpc_signmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
+
+/* Get the normalized MSE reduction for refinement passes. */
+#define JPC_GETREFNMSEDEC(x, bitpos) jpc_getrefnmsedec_macro(x, bitpos)
+jpc_fix_t jpc_refsignmsedec_func(jpc_fix_t x, int bitpos);
+#define jpc_getrefnmsedec_macro(x, bitpos) \
+ ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_refnmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
+ (jpc_refnmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
+
+/* Arithmetic shift right (with ability to shift left also). */
+#define JPC_ASR(x, n) \
+ (((n) >= 0) ? ((x) >> (n)) : ((x) << (-(n))))
+
+/* Update the per-sample state information. */
+#define JPC_UPDATEFLAGS4(fp, rowstep, s, vcausalflag) \
+{ \
+ register jpc_fix_t *np = (fp) - (rowstep); \
+ register jpc_fix_t *sp = (fp) + (rowstep); \
+ if ((vcausalflag)) { \
+ sp[-1] |= JPC_NESIG; \
+ sp[1] |= JPC_NWSIG; \
+ if (s) { \
+ *sp |= JPC_NSIG | JPC_NSGN; \
+ (fp)[-1] |= JPC_ESIG | JPC_ESGN; \
+ (fp)[1] |= JPC_WSIG | JPC_WSGN; \
+ } else { \
+ *sp |= JPC_NSIG; \
+ (fp)[-1] |= JPC_ESIG; \
+ (fp)[1] |= JPC_WSIG; \
+ } \
+ } else { \
+ np[-1] |= JPC_SESIG; \
+ np[1] |= JPC_SWSIG; \
+ sp[-1] |= JPC_NESIG; \
+ sp[1] |= JPC_NWSIG; \
+ if (s) { \
+ *np |= JPC_SSIG | JPC_SSGN; \
+ *sp |= JPC_NSIG | JPC_NSGN; \
+ (fp)[-1] |= JPC_ESIG | JPC_ESGN; \
+ (fp)[1] |= JPC_WSIG | JPC_WSGN; \
+ } else { \
+ *np |= JPC_SSIG; \
+ *sp |= JPC_NSIG; \
+ (fp)[-1] |= JPC_ESIG; \
+ (fp)[1] |= JPC_WSIG; \
+ } \
+ } \
+}
+
+/* Initialize the lookup tables used by the codec. */
+void jpc_initluts(void);
+
+/* Get the nominal gain associated with a particular band. */
+int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient);
+
+/* Get the coding pass type. */
+int JPC_PASSTYPE(int passno);
+
+/* Get the segment type. */
+int JPC_SEGTYPE(int passno, int firstpassno, int bypass);
+
+/* Get the number of coding passess in the segment. */
+int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass,
+ int termall);
+
+/* Is the coding pass terminated? */
+int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,
+ int lazy);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1dec.c b/osframework/source/ImageLib/jpeg2000/jpc_t1dec.c
new file mode 100644
index 0000000..993f7de
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1dec.c
@@ -0,0 +1,971 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 1 Decoder
+ *
+ * $Id: jpc_t1dec.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jas_fix.h"
+#include "jas_stream.h"
+#include "jas_math.h"
+
+#include "jpc_bs.h"
+#include "jpc_mqdec.h"
+#include "jpc_t1dec.h"
+#include "jpc_t1cod.h"
+#include "jpc_dec.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band,
+ jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs);
+static int dec_sigpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient,
+ int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
+static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos,
+ int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
+static int dec_refpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int vcausalflag,
+ jas_matrix_t *flags, jas_matrix_t *data);
+static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos,
+ int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
+static int dec_clnpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient,
+ int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data);
+
+#if defined(DEBUG)
+static long t1dec_cnt = 0;
+#endif
+
+#if !defined(DEBUG)
+#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \
+ ((v) = jpc_mqdec_getbit(mqdec))
+#else
+#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \
+{ \
+ (v) = jpc_mqdec_getbit(mqdec); \
+ if (jas_getdbglevel() >= 100) { \
+ fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \
+ ++t1dec_cnt; \
+ } \
+}
+#endif
+#define JPC_T1D_GETBITNOSKEW(mqdec, v, passtypename, symtypename) \
+ JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename)
+
+#if !defined(DEBUG)
+#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \
+ ((v) = jpc_bitstream_getbit(bitstream))
+#else
+#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \
+{ \
+ (v) = jpc_bitstream_getbit(bitstream); \
+ if (jas_getdbglevel() >= 100) { \
+ fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \
+ ++t1dec_cnt; \
+ } \
+}
+#endif
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile)
+{
+ jpc_dec_tcomp_t *tcomp;
+ int compcnt;
+ jpc_dec_rlvl_t *rlvl;
+ int rlvlcnt;
+ jpc_dec_band_t *band;
+ int bandcnt;
+ jpc_dec_prc_t *prc;
+ int prccnt;
+ jpc_dec_cblk_t *cblk;
+ int cblkcnt;
+
+ for (compcnt = dec->numcomps, tcomp = tile->tcomps; compcnt > 0;
+ --compcnt, ++tcomp) {
+ for (rlvlcnt = tcomp->numrlvls, rlvl = tcomp->rlvls;
+ rlvlcnt > 0; --rlvlcnt, ++rlvl) {
+ if (!rlvl->bands) {
+ continue;
+ }
+ for (bandcnt = rlvl->numbands, band = rlvl->bands;
+ bandcnt > 0; --bandcnt, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prccnt = rlvl->numprcs, prc = band->prcs;
+ prccnt > 0; --prccnt, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ for (cblkcnt = prc->numcblks,
+ cblk = prc->cblks; cblkcnt > 0;
+ --cblkcnt, ++cblk) {
+ if (jpc_dec_decodecblk(dec, tile, tcomp,
+ band, cblk, 1, JPC_MAXLYRS)) {
+ return -1;
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band,
+ jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs)
+{
+ jpc_dec_seg_t *seg;
+ int i;
+ int bpno;
+ int passtype;
+ int ret;
+ int compno;
+ int filldata;
+ int fillmask;
+ jpc_dec_ccp_t *ccp;
+
+ compno = tcomp - tile->tcomps;
+
+ if (!cblk->flags) {
+ /* Note: matrix is assumed to be zeroed */
+ if (!(cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) +
+ 2, jas_matrix_numcols(cblk->data) + 2))) {
+ return -1;
+ }
+ }
+
+ seg = cblk->segs.head;
+ while (seg && (seg != cblk->curseg || dopartial) && (maxlyrs < 0 ||
+ seg->lyrno < maxlyrs)) {
+ assert(seg->numpasses >= seg->maxpasses || dopartial);
+ assert(seg->stream);
+ jas_stream_rewind(seg->stream);
+ jas_stream_setrwcount(seg->stream, 0);
+ if (seg->type == JPC_SEG_MQ) {
+ if (!cblk->mqdec) {
+ if (!(cblk->mqdec = jpc_mqdec_create(JPC_NUMCTXS, 0))) {
+ return -1;
+ }
+ jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs);
+ }
+ jpc_mqdec_setinput(cblk->mqdec, seg->stream);
+ jpc_mqdec_init(cblk->mqdec);
+ } else {
+ assert(seg->type == JPC_SEG_RAW);
+ if (!cblk->nulldec) {
+ if (!(cblk->nulldec = jpc_bitstream_sopen(seg->stream, "r"))) {
+ assert(0);
+ }
+ }
+ }
+
+
+ for (i = 0; i < seg->numpasses; ++i) {
+ if (cblk->numimsbs > band->numbps) {
+ ccp = &tile->cp->ccps[compno];
+ if (ccp->roishift <= 0) {
+ fprintf(stderr, "warning: corrupt code stream\n");
+ } else {
+ if (cblk->numimsbs < ccp->roishift - band->numbps) {
+ fprintf(stderr, "warning: corrupt code stream\n");
+ }
+ }
+ }
+ bpno = band->roishift + band->numbps - 1 - (cblk->numimsbs +
+ (seg->passno + i - cblk->firstpassno + 2) / 3);
+if (bpno < 0) {
+ goto premature_exit;
+}
+#if 1
+ passtype = (seg->passno + i + 2) % 3;
+#else
+ passtype = JPC_PASSTYPE(seg->passno + i + 2);
+#endif
+ assert(bpno >= 0 && bpno < 31);
+ switch (passtype) {
+ case JPC_SIGPASS:
+ ret = (seg->type == JPC_SEG_MQ) ? dec_sigpass(dec,
+ cblk->mqdec, bpno, band->orient,
+ (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
+ cblk->flags, cblk->data) :
+ dec_rawsigpass(dec, cblk->nulldec, bpno,
+ (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
+ cblk->flags, cblk->data);
+ break;
+ case JPC_REFPASS:
+ ret = (seg->type == JPC_SEG_MQ) ?
+ dec_refpass(dec, cblk->mqdec, bpno,
+ (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
+ cblk->flags, cblk->data) :
+ dec_rawrefpass(dec, cblk->nulldec, bpno,
+ (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
+ cblk->flags, cblk->data);
+ break;
+ case JPC_CLNPASS:
+ assert(seg->type == JPC_SEG_MQ);
+ ret = dec_clnpass(dec, cblk->mqdec, bpno,
+ band->orient, (tile->cp->ccps[compno].cblkctx &
+ JPC_COX_VSC) != 0, (tile->cp->ccps[compno].cblkctx &
+ JPC_COX_SEGSYM) != 0, cblk->flags,
+ cblk->data);
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ /* Do we need to reset after each coding pass? */
+ if (tile->cp->ccps[compno].cblkctx & JPC_COX_RESET) {
+ jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs);
+ }
+
+ if (ret) {
+ fprintf(stderr, "coding pass failed passtype=%d segtype=%d\n", passtype, seg->type);
+ return -1;
+ }
+
+ }
+
+ if (seg->type == JPC_SEG_MQ) {
+/* Note: dont destroy mq decoder because context info will be lost */
+ } else {
+ assert(seg->type == JPC_SEG_RAW);
+ if (tile->cp->ccps[compno].cblkctx & JPC_COX_PTERM) {
+ fillmask = 0x7f;
+ filldata = 0x2a;
+ } else {
+ fillmask = 0;
+ filldata = 0;
+ }
+ if ((ret = jpc_bitstream_inalign(cblk->nulldec, fillmask,
+ filldata)) < 0) {
+ return -1;
+ } else if (ret > 0) {
+ fprintf(stderr, "warning: bad termination pattern detected\n");
+ }
+ jpc_bitstream_close(cblk->nulldec);
+ cblk->nulldec = 0;
+ }
+
+ cblk->curseg = seg->next;
+ jpc_seglist_remove(&cblk->segs, seg);
+ jpc_seg_destroy(seg);
+ seg = cblk->curseg;
+ }
+
+ assert(dopartial ? (!cblk->curseg) : 1);
+
+premature_exit:
+ return 0;
+}
+
+/******************************************************************************\
+* Code for significance pass.
+\******************************************************************************/
+
+#define jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, vcausalflag) \
+{ \
+ int f; \
+ int v; \
+ f = *(fp); \
+ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
+ jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO(f, (orient))); \
+ JPC_T1D_GETBIT((mqdec), v, "SIG", "ZC"); \
+ if (v) { \
+ jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \
+ JPC_T1D_GETBIT((mqdec), v, "SIG", "SC"); \
+ v ^= JPC_GETSPB(f); \
+ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
+ *(fp) |= JPC_SIG; \
+ *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \
+ } \
+ *(fp) |= JPC_VISIT; \
+ } \
+}
+
+static int dec_sigpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient,
+ int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data)
+{
+ int i;
+ int j;
+ int one;
+ int half;
+ int oneplushalf;
+ int vscanlen;
+ int width;
+ int height;
+ jpc_fix_t *fp;
+ int frowstep;
+ int fstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dp;
+ int drowstep;
+ int dstripestep;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *dvscanstart;
+ int k;
+
+ /* Avoid compiler warning about unused parameters. */
+ dec = 0;
+
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << bitpos;
+ half = one >> 1;
+ oneplushalf = one | half;
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ /* Process first sample in vertical scan. */
+ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
+ orient, mqdec, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process second sample in vertical scan. */
+ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
+ orient, mqdec, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process third sample in vertical scan. */
+ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
+ orient, mqdec, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process fourth sample in vertical scan. */
+ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
+ orient, mqdec, 0);
+ }
+ }
+ return 0;
+}
+
+#define jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, vcausalflag) \
+{ \
+ jpc_fix_t f = *(fp); \
+ jpc_fix_t v; \
+ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
+ JPC_T1D_RAWGETBIT(in, v, "SIG", "ZC"); \
+ if (v < 0) { \
+ return -1; \
+ } \
+ if (v) { \
+ JPC_T1D_RAWGETBIT(in, v, "SIG", "SC"); \
+ if (v < 0) { \
+ return -1; \
+ } \
+ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
+ *(fp) |= JPC_SIG; \
+ *(dp) = v ? (-oneplushalf) : (oneplushalf); \
+ } \
+ *(fp) |= JPC_VISIT; \
+ } \
+}
+
+static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag,
+ jas_matrix_t *flags, jas_matrix_t *data)
+{
+ int i;
+ int j;
+ int k;
+ int one;
+ int half;
+ int oneplushalf;
+ int vscanlen;
+ int width;
+ int height;
+ jpc_fix_t *fp;
+ int frowstep;
+ int fstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dp;
+ int drowstep;
+ int dstripestep;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *dvscanstart;
+
+ /* Avoid compiler warning about unused parameters. */
+ dec = 0;
+
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << bitpos;
+ half = one >> 1;
+ oneplushalf = one | half;
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ /* Process first sample in vertical scan. */
+ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
+ in, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process second sample in vertical scan. */
+ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
+ in, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process third sample in vertical scan. */
+ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
+ in, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process fourth sample in vertical scan. */
+ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
+ in, 0);
+
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Code for refinement pass.
+\******************************************************************************/
+
+#define jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, vcausalflag) \
+{ \
+ int v; \
+ int t; \
+ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
+ jpc_mqdec_setcurctx((mqdec), JPC_GETMAGCTXNO(*(fp))); \
+ JPC_T1D_GETBITNOSKEW((mqdec), v, "REF", "MR"); \
+ t = (v ? (poshalf) : (neghalf)); \
+ *(dp) += (*(dp) < 0) ? (-t) : t; \
+ *(fp) |= JPC_REFINE; \
+ } \
+}
+
+static int dec_refpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos,
+ int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data)
+{
+ int i;
+ int j;
+ int vscanlen;
+ int width;
+ int height;
+ int one;
+ int poshalf;
+ int neghalf;
+ jpc_fix_t *fp;
+ int frowstep;
+ int fstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dp;
+ int drowstep;
+ int dstripestep;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *dvscanstart;
+ int k;
+
+ /* Avoid compiler warning about unused parameters. */
+ dec = 0;
+ vcausalflag = 0;
+
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << bitpos;
+ poshalf = one >> 1;
+ neghalf = (bitpos > 0) ? (-poshalf) : (-1);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ /* Process first sample in vertical scan. */
+ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec,
+ vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process second sample in vertical scan. */
+ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process third sample in vertical scan. */
+ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process fourth sample in vertical scan. */
+ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
+ }
+ }
+
+ return 0;
+}
+
+#define jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, vcausalflag) \
+{ \
+ jpc_fix_t v; \
+ jpc_fix_t t; \
+ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
+ JPC_T1D_RAWGETBIT(in, v, "REF", "MAGREF"); \
+ if (v < 0) { \
+ return -1; \
+ } \
+ t = (v ? poshalf : neghalf); \
+ *(dp) += (*(dp) < 0) ? (-t) : t; \
+ *(fp) |= JPC_REFINE; \
+ } \
+}
+
+static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag,
+ jas_matrix_t *flags, jas_matrix_t *data)
+{
+ int i;
+ int j;
+ int k;
+ int vscanlen;
+ int width;
+ int height;
+ int one;
+ int poshalf;
+ int neghalf;
+ jpc_fix_t *fp;
+ int frowstep;
+ int fstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dp;
+ int drowstep;
+ int dstripestep;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *dvscanstart;
+
+ /* Avoid compiler warning about unused parameters. */
+ dec = 0;
+ vcausalflag = 0;
+
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << bitpos;
+ poshalf = one >> 1;
+ neghalf = (bitpos > 0) ? (-poshalf) : (-1);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ /* Process first sample in vertical scan. */
+ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in,
+ vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process second sample in vertical scan. */
+ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process third sample in vertical scan. */
+ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process fourth sample in vertical scan. */
+ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************\
+* Code for cleanup pass.
+\******************************************************************************/
+
+#define jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, mqdec, flabel, plabel, vcausalflag) \
+{ \
+ int v; \
+flabel \
+ if (!((f) & (JPC_SIG | JPC_VISIT))) { \
+ jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO((f), (orient))); \
+ JPC_T1D_GETBIT((mqdec), v, "CLN", "ZC"); \
+ if (v) { \
+plabel \
+ /* Coefficient is significant. */ \
+ jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \
+ JPC_T1D_GETBIT((mqdec), v, "CLN", "SC"); \
+ v ^= JPC_GETSPB(f); \
+ *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \
+ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
+ *(fp) |= JPC_SIG; \
+ } \
+ } \
+ /* XXX - Is this correct? Can aggregation cause some VISIT bits not to be reset? Check. */ \
+ *(fp) &= ~JPC_VISIT; \
+}
+
+static int dec_clnpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient,
+ int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data)
+{
+ int i;
+ int j;
+ int k;
+ int vscanlen;
+ int v;
+ int half;
+ int runlen;
+ int f;
+ int width;
+ int height;
+ int one;
+ int oneplushalf;
+
+ jpc_fix_t *fp;
+ int frowstep;
+ int fstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *fvscanstart;
+
+ jpc_fix_t *dp;
+ int drowstep;
+ int dstripestep;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *dvscanstart;
+
+ /* Avoid compiler warning about unused parameters. */
+ dec = 0;
+
+ one = 1 << bitpos;
+ half = one >> 1;
+ oneplushalf = one | half;
+
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = 0; i < height; i += 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(4, height - i);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ if (vscanlen >= 4 && (!((*fp) & (JPC_SIG | JPC_VISIT |
+ JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG |
+ JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) &
+ (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep,
+ !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) {
+
+ jpc_mqdec_setcurctx(mqdec, JPC_AGGCTXNO);
+ JPC_T1D_GETBIT(mqdec, v, "CLN", "AGG");
+ if (!v) {
+ continue;
+ }
+ jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO);
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL");
+ runlen = v;
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL");
+ runlen = (runlen << 1) | v;
+ f = *(fp = fvscanstart + frowstep * runlen);
+ dp = dvscanstart + drowstep * runlen;
+ k = vscanlen - runlen;
+ switch (runlen) {
+ case 0:
+ goto clnpass_partial0;
+ break;
+ case 1:
+ goto clnpass_partial1;
+ break;
+ case 2:
+ goto clnpass_partial2;
+ break;
+ case 3:
+ goto clnpass_partial3;
+ break;
+ }
+ } else {
+ f = *(fp = fvscanstart);
+ dp = dvscanstart;
+ k = vscanlen;
+ goto clnpass_full0;
+ }
+
+ /* Process first sample in vertical scan. */
+ jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
+ mqdec, clnpass_full0:, clnpass_partial0:,
+ vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process second sample in vertical scan. */
+ f = *fp;
+ jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
+ mqdec, ;, clnpass_partial1:, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process third sample in vertical scan. */
+ f = *fp;
+ jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
+ mqdec, ;, clnpass_partial2:, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ /* Process fourth sample in vertical scan. */
+ f = *fp;
+ jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
+ mqdec, ;, clnpass_partial3:, 0);
+ }
+ }
+
+ if (segsymflag) {
+ int segsymval;
+ segsymval = 0;
+ jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO);
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
+ segsymval = (segsymval << 1) | (v & 1);
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
+ segsymval = (segsymval << 1) | (v & 1);
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
+ segsymval = (segsymval << 1) | (v & 1);
+ JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
+ segsymval = (segsymval << 1) | (v & 1);
+ if (segsymval != 0xa) {
+ fprintf(stderr, "warning: bad segmentation symbol\n");
+ }
+ }
+
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1dec.h b/osframework/source/ImageLib/jpeg2000/jpc_t1dec.h
new file mode 100644
index 0000000..16eb932
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1dec.h
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 1 Decoder
+ *
+ * $Id: jpc_t1dec.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T1DEC_H
+#define JPC_T1DEC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jpc_dec.h"
+#include "jpc_mqdec.h"
+#include "jpc_t1cod.h"
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Decode all of the code blocks for a particular tile. */
+int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1enc.c b/osframework/source/ImageLib/jpeg2000/jpc_t1enc.c
new file mode 100644
index 0000000..2ad1f99
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1enc.c
@@ -0,0 +1,1008 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 1 Encoder
+ *
+ * $Id: jpc_t1enc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jas_fix.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+#include "jpc_t1enc.h"
+#include "jpc_t1cod.h"
+#include "jpc_enc.h"
+#include "jpc_cod.h"
+#include "jpc_math.h"
+
+static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int,
+ jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
+
+static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int, jas_matrix_t *flags,
+ jas_matrix_t *data, int term, long *nmsedec);
+
+static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int,
+ int, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
+
+static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int,
+ jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
+
+static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int,
+ jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
+
+/******************************************************************************\
+* Code for encoding code blocks.
+\******************************************************************************/
+
+/* Encode all of the code blocks associated with the current tile. */
+int jpc_enc_enccblks(jpc_enc_t *enc)
+{
+ jpc_enc_tcmpt_t *tcmpt;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_rlvl_t *endlvls;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ int i;
+ int j;
+ int mx;
+ int bmx;
+ int v;
+ jpc_enc_tile_t *tile;
+ uint_fast32_t prcno;
+ jpc_enc_prc_t *prc;
+
+ tile = enc->curtile;
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (tcmpt = tile->tcmpts; tcmpt != endcomps; ++tcmpt) {
+ endlvls = &tcmpt->rlvls[tcmpt->numrlvls];
+ for (lvl = tcmpt->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ bmx = 0;
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ mx = 0;
+ for (i = 0; i < jas_matrix_numrows(cblk->data); ++i) {
+ for (j = 0; j < jas_matrix_numcols(cblk->data); ++j) {
+ v = abs(jas_matrix_get(cblk->data, i, j));
+ if (v > mx) {
+ mx = v;
+ }
+ }
+ }
+ if (mx > bmx) {
+ bmx = mx;
+ }
+ cblk->numbps = JAS_MAX(jpc_firstone(mx) + 1 - JPC_NUMEXTRABITS, 0);
+ }
+
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ cblk->numimsbs = band->numbps - cblk->numbps;
+ assert(cblk->numimsbs >= 0);
+ }
+
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ if (jpc_enc_enccblk(enc, cblk->stream, tcmpt, band, cblk)) {
+ return -1;
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+int getthebyte(jas_stream_t *in, long off)
+{
+ int c;
+ long oldpos;
+ oldpos = jas_stream_tell(in);
+ assert(oldpos >= 0);
+ jas_stream_seek(in, off, SEEK_SET);
+ c = jas_stream_peekc(in);
+ jas_stream_seek(in, oldpos, SEEK_SET);
+ return c;
+}
+
+/* Encode a single code block. */
+int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, jpc_enc_band_t *band, jpc_enc_cblk_t *cblk)
+{
+ jpc_enc_pass_t *pass;
+ jpc_enc_pass_t *endpasses;
+ int bitpos;
+ int n;
+ int adjust;
+ int ret;
+ int passtype;
+ int t;
+ jpc_bitstream_t *bout;
+ jpc_enc_pass_t *termpass;
+ jpc_enc_rlvl_t *rlvl;
+ int vcausal;
+ int segsym;
+ int termmode;
+ int c;
+
+ bout = 0;
+ rlvl = band->rlvl;
+
+ cblk->stream = jas_stream_memopen(0, 0);
+ assert(cblk->stream);
+ cblk->mqenc = jpc_mqenc_create(JPC_NUMCTXS, cblk->stream);
+ assert(cblk->mqenc);
+ jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs);
+
+ cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0;
+ if (cblk->numpasses > 0) {
+ cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t));
+ assert(cblk->passes);
+ } else {
+ cblk->passes = 0;
+ }
+ endpasses = &cblk->passes[cblk->numpasses];
+ for (pass = cblk->passes; pass != endpasses; ++pass) {
+ pass->start = 0;
+ pass->end = 0;
+ pass->term = JPC_ISTERMINATED(pass - cblk->passes, 0, cblk->numpasses, (tcmpt->cblksty & JPC_COX_TERMALL) != 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0);
+ pass->type = JPC_SEGTYPE(pass - cblk->passes, 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0);
+ pass->lyrno = -1;
+if (pass == endpasses - 1) {
+assert(pass->term == 1);
+ pass->term = 1;
+}
+ }
+
+ cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2,
+ jas_matrix_numcols(cblk->data) + 2);
+ assert(cblk->flags);
+
+
+ bitpos = cblk->numbps - 1;
+ pass = cblk->passes;
+ n = cblk->numpasses;
+ while (--n >= 0) {
+
+ if (pass->type == JPC_SEG_MQ) {
+ /* NOP */
+ } else {
+ assert(pass->type == JPC_SEG_RAW);
+ if (!bout) {
+ bout = jpc_bitstream_sopen(cblk->stream, "w");
+ assert(bout);
+ }
+ }
+
+#if 1
+ passtype = (pass - cblk->passes + 2) % 3;
+#else
+ passtype = JPC_PASSTYPE(pass - cblk->passes + 2);
+#endif
+ pass->start = jas_stream_tell(cblk->stream);
+#if 0
+assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream));
+#endif
+ assert(bitpos >= 0);
+ vcausal = (tcmpt->cblksty & JPC_COX_VSC) != 0;
+ segsym = (tcmpt->cblksty & JPC_COX_SEGSYM) != 0;
+ if (pass->term) {
+ termmode = ((tcmpt->cblksty & JPC_COX_PTERM) ?
+ JPC_MQENC_PTERM : JPC_MQENC_DEFTERM) + 1;
+ } else {
+ termmode = 0;
+ }
+ switch (passtype) {
+ case JPC_SIGPASS:
+ ret = (pass->type == JPC_SEG_MQ) ? jpc_encsigpass(cblk->mqenc,
+ bitpos, band->orient, vcausal, cblk->flags,
+ cblk->data, termmode, &pass->nmsedec) :
+ jpc_encrawsigpass(bout, bitpos, vcausal, cblk->flags,
+ cblk->data, termmode, &pass->nmsedec);
+ break;
+ case JPC_REFPASS:
+ ret = (pass->type == JPC_SEG_MQ) ? jpc_encrefpass(cblk->mqenc,
+ bitpos, vcausal, cblk->flags, cblk->data, termmode,
+ &pass->nmsedec) : jpc_encrawrefpass(bout, bitpos,
+ vcausal, cblk->flags, cblk->data, termmode,
+ &pass->nmsedec);
+ break;
+ case JPC_CLNPASS:
+ assert(pass->type == JPC_SEG_MQ);
+ ret = jpc_encclnpass(cblk->mqenc, bitpos, band->orient,
+ vcausal, segsym, cblk->flags, cblk->data, termmode,
+ &pass->nmsedec);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ if (pass->type == JPC_SEG_MQ) {
+ if (pass->term) {
+ jpc_mqenc_init(cblk->mqenc);
+ }
+ jpc_mqenc_getstate(cblk->mqenc, &pass->mqencstate);
+ pass->end = jas_stream_tell(cblk->stream);
+ if (tcmpt->cblksty & JPC_COX_RESET) {
+ jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs);
+ }
+ } else {
+ if (pass->term) {
+ if (jpc_bitstream_pending(bout)) {
+ jpc_bitstream_outalign(bout, 0x2a);
+ }
+ jpc_bitstream_close(bout);
+ bout = 0;
+ pass->end = jas_stream_tell(cblk->stream);
+ } else {
+ pass->end = jas_stream_tell(cblk->stream) +
+ jpc_bitstream_pending(bout);
+/* NOTE - This will not work. need to adjust by # of pending output bytes */
+ }
+ }
+#if 0
+/* XXX - This assertion fails sometimes when various coding modes are used.
+This seems to be harmless, but why does it happen at all? */
+assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream));
+#endif
+
+ pass->wmsedec = jpc_fixtodbl(band->rlvl->tcmpt->synweight) *
+ jpc_fixtodbl(band->rlvl->tcmpt->synweight) *
+ jpc_fixtodbl(band->synweight) *
+ jpc_fixtodbl(band->synweight) *
+ jpc_fixtodbl(band->absstepsize) * jpc_fixtodbl(band->absstepsize) *
+ ((double) (1 << bitpos)) * ((double)(1 << bitpos)) *
+ jpc_fixtodbl(pass->nmsedec);
+ pass->cumwmsedec = pass->wmsedec;
+ if (pass != cblk->passes) {
+ pass->cumwmsedec += pass[-1].cumwmsedec;
+ }
+ if (passtype == JPC_CLNPASS) {
+ --bitpos;
+ }
+ ++pass;
+ }
+
+#if 0
+dump_passes(cblk->passes, cblk->numpasses, cblk);
+#endif
+
+ n = 0;
+ endpasses = &cblk->passes[cblk->numpasses];
+ for (pass = cblk->passes; pass != endpasses; ++pass) {
+ if (pass->start < n) {
+ pass->start = n;
+ }
+ if (pass->end < n) {
+ pass->end = n;
+ }
+ if (!pass->term) {
+ termpass = pass;
+ while (termpass - pass < cblk->numpasses &&
+ !termpass->term) {
+ ++termpass;
+ }
+ if (pass->type == JPC_SEG_MQ) {
+ t = (pass->mqencstate.lastbyte == 0xff) ? 1 : 0;
+ if (pass->mqencstate.ctreg >= 5) {
+ adjust = 4 + t;
+ } else {
+ adjust = 5 + t;
+ }
+ pass->end += adjust;
+ }
+ if (pass->end > termpass->end) {
+ pass->end = termpass->end;
+ }
+ if ((c = getthebyte(cblk->stream, pass->end - 1)) == EOF) {
+ abort();
+ }
+ if (c == 0xff) {
+ ++pass->end;
+ }
+ n = JAS_MAX(n, pass->end);
+ } else {
+ n = JAS_MAX(n, pass->end);
+ }
+ }
+
+#if 0
+dump_passes(cblk->passes, cblk->numpasses, cblk);
+#endif
+
+ if (bout) {
+ jpc_bitstream_close(bout);
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for significance pass.
+\******************************************************************************/
+
+#define sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag) \
+{ \
+ int f; \
+ int v; \
+ f = *(fp); \
+ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
+ v = (abs(*(dp)) & (one)) ? 1 : 0; \
+ jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \
+ jpc_mqenc_putbit(mqenc, v); \
+ if (v) { \
+ *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
+ v = ((*(dp) < 0) ? 1 : 0); \
+ jpc_mqenc_setcurctx(mqenc, JPC_GETSCCTXNO(f)); \
+ jpc_mqenc_putbit(mqenc, v ^ JPC_GETSPB(f)); \
+ JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \
+ *(fp) |= JPC_SIG; \
+ } \
+ *(fp) |= JPC_VISIT; \
+ } \
+}
+
+static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag,
+ jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec)
+{
+ int i;
+ int j;
+ int one;
+ int vscanlen;
+ int width;
+ int height;
+ int frowstep;
+ int drowstep;
+ int fstripestep;
+ int dstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *fp;
+ jpc_fix_t *dp;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dvscanstart;
+ int k;
+
+ *nmsedec = 0;
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << (bitpos + JPC_NUMEXTRABITS);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ sigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, orient, mqenc, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ sigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, orient, mqenc, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ sigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, orient, mqenc, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ sigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, orient, mqenc, 0);
+
+ }
+ }
+
+ if (term) {
+ jpc_mqenc_flush(mqenc, term - 1);
+ }
+
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
+
+#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \
+{ \
+ jpc_fix_t f = *(fp); \
+ jpc_fix_t v; \
+ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
+ v = (abs(*(dp)) & (one)) ? 1 : 0; \
+ if ((jpc_bitstream_putbit((out), v)) == EOF) { \
+ return -1; \
+ } \
+ if (v) { \
+ *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
+ v = ((*(dp) < 0) ? 1 : 0); \
+ if (jpc_bitstream_putbit(out, v) == EOF) { \
+ return -1; \
+ } \
+ JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \
+ *(fp) |= JPC_SIG; \
+ } \
+ *(fp) |= JPC_VISIT; \
+ } \
+}
+
+static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags,
+ jas_matrix_t *data, int term, long *nmsedec)
+{
+ int i;
+ int j;
+ int k;
+ int one;
+ int vscanlen;
+ int width;
+ int height;
+ int frowstep;
+ int drowstep;
+ int fstripestep;
+ int dstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *fp;
+ jpc_fix_t *dp;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dvscanstart;
+
+ *nmsedec = 0;
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << (bitpos + JPC_NUMEXTRABITS);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ rawsigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, out, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ rawsigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, out, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ rawsigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, out, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ rawsigpass_step(fp, frowstep, dp, bitpos, one,
+ nmsedec, out, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+
+ }
+ }
+
+ if (term) {
+ jpc_bitstream_outalign(out, 0x2a);
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for refinement pass.
+\******************************************************************************/
+
+#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \
+{ \
+ int v; \
+ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
+ (d) = *(dp); \
+ *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \
+ jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \
+ v = (abs(d) & (one)) ? 1 : 0; \
+ jpc_mqenc_putbit((mqenc), v); \
+ *(fp) |= JPC_REFINE; \
+ } \
+}
+
+static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data,
+ int term, long *nmsedec)
+{
+ int i;
+ int j;
+ int one;
+ int vscanlen;
+ int d;
+ int width;
+ int height;
+ int frowstep;
+ int drowstep;
+ int fstripestep;
+ int dstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dvscanstart;
+ jpc_fix_t *dp;
+ jpc_fix_t *fp;
+int k;
+
+ *nmsedec = 0;
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << (bitpos + JPC_NUMEXTRABITS);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ refpass_step(fp, dp, bitpos, one, nmsedec,
+ mqenc, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ refpass_step(fp, dp, bitpos, one, nmsedec,
+ mqenc, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ refpass_step(fp, dp, bitpos, one, nmsedec,
+ mqenc, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ refpass_step(fp, dp, bitpos, one, nmsedec,
+ mqenc, 0);
+
+ }
+ }
+
+ if (term) {
+ jpc_mqenc_flush(mqenc, term - 1);
+ }
+
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
+
+#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \
+{ \
+ jpc_fix_t d; \
+ jpc_fix_t v; \
+ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
+ d = *(dp); \
+ *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \
+ v = (abs(d) & (one)) ? 1 : 0; \
+ if (jpc_bitstream_putbit((out), v) == EOF) { \
+ return -1; \
+ } \
+ *(fp) |= JPC_REFINE; \
+ } \
+}
+
+static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags,
+ jas_matrix_t *data, int term, long *nmsedec)
+{
+ int i;
+ int j;
+ int k;
+ int one;
+ int vscanlen;
+ int width;
+ int height;
+ int frowstep;
+ int drowstep;
+ int fstripestep;
+ int dstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dvscanstart;
+ jpc_fix_t *dp;
+ jpc_fix_t *fp;
+
+ *nmsedec = 0;
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << (bitpos + JPC_NUMEXTRABITS);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+
+ rawrefpass_step(fp, dp, bitpos, one, nmsedec,
+ out, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ rawrefpass_step(fp, dp, bitpos, one, nmsedec,
+ out, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ rawrefpass_step(fp, dp, bitpos, one, nmsedec,
+ out, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ rawrefpass_step(fp, dp, bitpos, one, nmsedec,
+ out, vcausalflag);
+
+ }
+ }
+
+ if (term) {
+ jpc_bitstream_outalign(out, 0x2a);
+ }
+
+ return 0;
+}
+
+/******************************************************************************\
+* Code for cleanup pass.
+\******************************************************************************/
+
+#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \
+{ \
+ int f; \
+ int v; \
+label1 \
+ f = *(fp); \
+ if (!(f & (JPC_SIG | JPC_VISIT))) { \
+ jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \
+ v = (abs(*(dp)) & (one)) ? 1 : 0; \
+ jpc_mqenc_putbit((mqenc), v); \
+ if (v) { \
+label2 \
+ f = *(fp); \
+ /* Coefficient is significant. */ \
+ *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
+ jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \
+ v = ((*(dp) < 0) ? 1 : 0); \
+ jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \
+ JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \
+ *(fp) |= JPC_SIG; \
+ } \
+ } \
+ *(fp) &= ~JPC_VISIT; \
+}
+
+static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags,
+ jas_matrix_t *data, int term, long *nmsedec)
+{
+ int i;
+ int j;
+ int k;
+ int vscanlen;
+ int v;
+ int runlen;
+ jpc_fix_t *fp;
+ int width;
+ int height;
+ jpc_fix_t *dp;
+ int one;
+ int frowstep;
+ int drowstep;
+ int fstripestep;
+ int dstripestep;
+ jpc_fix_t *fstripestart;
+ jpc_fix_t *dstripestart;
+ jpc_fix_t *fvscanstart;
+ jpc_fix_t *dvscanstart;
+
+ *nmsedec = 0;
+ width = jas_matrix_numcols(data);
+ height = jas_matrix_numrows(data);
+ frowstep = jas_matrix_rowstep(flags);
+ drowstep = jas_matrix_rowstep(data);
+ fstripestep = frowstep << 2;
+ dstripestep = drowstep << 2;
+
+ one = 1 << (bitpos + JPC_NUMEXTRABITS);
+
+ fstripestart = jas_matrix_getref(flags, 1, 1);
+ dstripestart = jas_matrix_getref(data, 0, 0);
+ for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
+ dstripestart += dstripestep) {
+ fvscanstart = fstripestart;
+ dvscanstart = dstripestart;
+ vscanlen = JAS_MIN(i, 4);
+ for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
+
+ fp = fvscanstart;
+ if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT |
+ JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG |
+ JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) &
+ (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep,
+ !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) {
+ dp = dvscanstart;
+ for (k = 0; k < vscanlen; ++k) {
+ v = (abs(*dp) & one) ? 1 : 0;
+ if (v) {
+ break;
+ }
+ dp += drowstep;
+ }
+ runlen = k;
+ if (runlen >= 4) {
+ jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO);
+ jpc_mqenc_putbit(mqenc, 0);
+ continue;
+ }
+ jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO);
+ jpc_mqenc_putbit(mqenc, 1);
+ jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO);
+ jpc_mqenc_putbit(mqenc, runlen >> 1);
+ jpc_mqenc_putbit(mqenc, runlen & 1);
+ fp = fvscanstart + frowstep * runlen;
+ dp = dvscanstart + drowstep * runlen;
+ k = vscanlen - runlen;
+ switch (runlen) {
+ case 0:
+ goto clnpass_partial0;
+ break;
+ case 1:
+ goto clnpass_partial1;
+ break;
+ case 2:
+ goto clnpass_partial2;
+ break;
+ case 3:
+ goto clnpass_partial3;
+ break;
+ }
+ } else {
+ runlen = 0;
+ fp = fvscanstart;
+ dp = dvscanstart;
+ k = vscanlen;
+ goto clnpass_full0;
+ }
+ clnpass_step(fp, frowstep, dp, bitpos, one,
+ orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ clnpass_step(fp, frowstep, dp, bitpos, one,
+ orient, nmsedec, mqenc, ;, clnpass_partial1:, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ clnpass_step(fp, frowstep, dp, bitpos, one,
+ orient, nmsedec, mqenc, ;, clnpass_partial2:, 0);
+ if (--k <= 0) {
+ continue;
+ }
+ fp += frowstep;
+ dp += drowstep;
+ clnpass_step(fp, frowstep, dp, bitpos, one,
+ orient, nmsedec, mqenc, ;, clnpass_partial3:, 0);
+ }
+ }
+
+ if (segsymflag) {
+ jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO);
+ jpc_mqenc_putbit(mqenc, 1);
+ jpc_mqenc_putbit(mqenc, 0);
+ jpc_mqenc_putbit(mqenc, 1);
+ jpc_mqenc_putbit(mqenc, 0);
+ }
+
+ if (term) {
+ jpc_mqenc_flush(mqenc, term - 1);
+ }
+
+ return jpc_mqenc_error(mqenc) ? (-1) : 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t1enc.h b/osframework/source/ImageLib/jpeg2000/jpc_t1enc.h
new file mode 100644
index 0000000..13026f9
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t1enc.h
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 1 Encoder
+ *
+ * $Id: jpc_t1enc.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T1ENC_H
+#define JPC_T1ENC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_seq.h"
+
+#include "jpc_enc.h"
+#include "jpc_t1cod.h"
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Encode all of the code blocks. */
+int jpc_enc_enccblks(jpc_enc_t *enc);
+
+/* Encode a single code block. */
+int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *comp,
+ jpc_enc_band_t *band, jpc_enc_cblk_t *cblk);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2cod.c b/osframework/source/ImageLib/jpeg2000/jpc_t2cod.c
new file mode 100644
index 0000000..32f3fbf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2cod.c
@@ -0,0 +1,733 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier-2 Coding Library
+ *
+ * $Id: jpc_t2cod.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#include "jas_math.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+
+#include "jpc_cs.h"
+#include "jpc_t2cod.h"
+#include "jpc_math.h"
+
+static int jpc_pi_nextlrcp(jpc_pi_t *pi);
+static int jpc_pi_nextrlcp(jpc_pi_t *pi);
+static int jpc_pi_nextrpcl(jpc_pi_t *pi);
+static int jpc_pi_nextpcrl(jpc_pi_t *pi);
+static int jpc_pi_nextcprl(jpc_pi_t *pi);
+
+int jpc_pi_next(jpc_pi_t *pi)
+{
+ jpc_pchg_t *pchg;
+ int ret;
+
+
+ for (;;) {
+
+ pi->valid = false;
+
+ if (!pi->pchg) {
+ ++pi->pchgno;
+ pi->compno = 0;
+ pi->rlvlno = 0;
+ pi->prcno = 0;
+ pi->lyrno = 0;
+ pi->prgvolfirst = true;
+ if (pi->pchgno < jpc_pchglist_numpchgs(pi->pchglist)) {
+ pi->pchg = jpc_pchglist_get(pi->pchglist, pi->pchgno);
+ } else if (pi->pchgno == jpc_pchglist_numpchgs(pi->pchglist)) {
+ pi->pchg = &pi->defaultpchg;
+ } else {
+ return 1;
+ }
+ }
+
+ pchg = pi->pchg;
+ switch (pchg->prgord) {
+ case JPC_COD_LRCPPRG:
+ ret = jpc_pi_nextlrcp(pi);
+ break;
+ case JPC_COD_RLCPPRG:
+ ret = jpc_pi_nextrlcp(pi);
+ break;
+ case JPC_COD_RPCLPRG:
+ ret = jpc_pi_nextrpcl(pi);
+ break;
+ case JPC_COD_PCRLPRG:
+ ret = jpc_pi_nextpcrl(pi);
+ break;
+ case JPC_COD_CPRLPRG:
+ ret = jpc_pi_nextcprl(pi);
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ if (!ret) {
+ pi->valid = true;
+ ++pi->pktno;
+ return 0;
+ }
+ pi->pchg = 0;
+ }
+}
+
+static int jpc_pi_nextlrcp(register jpc_pi_t *pi)
+{
+ jpc_pchg_t *pchg;
+ int *prclyrno;
+
+ pchg = pi->pchg;
+ if (!pi->prgvolfirst) {
+ prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
+ goto skip;
+ } else {
+ pi->prgvolfirst = false;
+ }
+
+ for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno <
+ JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
+ for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls &&
+ pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) {
+ for (pi->compno = pchg->compnostart, pi->picomp =
+ &pi->picomps[pi->compno]; pi->compno < pi->numcomps
+ && pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
+ ++pi->picomp) {
+ if (pi->rlvlno >= pi->picomp->numrlvls) {
+ continue;
+ }
+ pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
+ for (pi->prcno = 0, prclyrno =
+ pi->pirlvl->prclyrnos; pi->prcno <
+ pi->pirlvl->numprcs; ++pi->prcno,
+ ++prclyrno) {
+ if (pi->lyrno >= *prclyrno) {
+ *prclyrno = pi->lyrno;
+ ++(*prclyrno);
+ return 0;
+ }
+skip:
+ ;
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static int jpc_pi_nextrlcp(register jpc_pi_t *pi)
+{
+ jpc_pchg_t *pchg;
+ int *prclyrno;
+
+ pchg = pi->pchg;
+ if (!pi->prgvolfirst) {
+ assert(pi->prcno < pi->pirlvl->numprcs);
+ prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
+ goto skip;
+ } else {
+ pi->prgvolfirst = 0;
+ }
+
+ for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls &&
+ pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) {
+ for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno <
+ JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
+ for (pi->compno = pchg->compnostart, pi->picomp =
+ &pi->picomps[pi->compno]; pi->compno < pi->numcomps &&
+ pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno, ++pi->picomp) {
+ if (pi->rlvlno >= pi->picomp->numrlvls) {
+ continue;
+ }
+ pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
+ for (pi->prcno = 0, prclyrno = pi->pirlvl->prclyrnos;
+ pi->prcno < pi->pirlvl->numprcs; ++pi->prcno, ++prclyrno) {
+ if (pi->lyrno >= *prclyrno) {
+ *prclyrno = pi->lyrno;
+ ++(*prclyrno);
+ return 0;
+ }
+skip:
+ ;
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static int jpc_pi_nextrpcl(register jpc_pi_t *pi)
+{
+ int rlvlno;
+ jpc_pirlvl_t *pirlvl;
+ jpc_pchg_t *pchg;
+ int prchind;
+ int prcvind;
+ int *prclyrno;
+ int compno;
+ jpc_picomp_t *picomp;
+ int xstep;
+ int ystep;
+ uint_fast32_t r;
+ uint_fast32_t rpx;
+ uint_fast32_t rpy;
+ uint_fast32_t trx0;
+ uint_fast32_t try0;
+
+ pchg = pi->pchg;
+ if (!pi->prgvolfirst) {
+ goto skip;
+ } else {
+ pi->xstep = 0;
+ pi->ystep = 0;
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
+ ++compno, ++picomp) {
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ xstep = picomp->hsamp * (1 << (pirlvl->prcwidthexpn +
+ picomp->numrlvls - rlvlno - 1));
+ ystep = picomp->vsamp * (1 << (pirlvl->prcheightexpn +
+ picomp->numrlvls - rlvlno - 1));
+ pi->xstep = (!pi->xstep) ? xstep : JAS_MIN(pi->xstep, xstep);
+ pi->ystep = (!pi->ystep) ? ystep : JAS_MIN(pi->ystep, ystep);
+ }
+ }
+ pi->prgvolfirst = 0;
+ }
+
+ for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pchg->rlvlnoend &&
+ pi->rlvlno < pi->maxrlvls; ++pi->rlvlno) {
+ for (pi->y = pi->ystart; pi->y < pi->yend; pi->y +=
+ pi->ystep - (pi->y % pi->ystep)) {
+ for (pi->x = pi->xstart; pi->x < pi->xend; pi->x +=
+ pi->xstep - (pi->x % pi->xstep)) {
+ for (pi->compno = pchg->compnostart,
+ pi->picomp = &pi->picomps[pi->compno];
+ pi->compno < JAS_CAST(int, pchg->compnoend) && pi->compno <
+ pi->numcomps; ++pi->compno, ++pi->picomp) {
+ if (pi->rlvlno >= pi->picomp->numrlvls) {
+ continue;
+ }
+ pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
+ if (pi->pirlvl->numprcs == 0) {
+ continue;
+ }
+ r = pi->picomp->numrlvls - 1 - pi->rlvlno;
+ rpx = r + pi->pirlvl->prcwidthexpn;
+ rpy = r + pi->pirlvl->prcheightexpn;
+ trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
+ try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
+ if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx)))
+ || !(pi->x % (1 << rpx))) &&
+ ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy)))
+ || !(pi->y % (1 << rpy)))) {
+ prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
+ << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
+ pi->pirlvl->prcwidthexpn);
+ prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
+ << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
+ pi->pirlvl->prcheightexpn);
+ pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind;
+
+ assert(pi->prcno < pi->pirlvl->numprcs);
+ for (pi->lyrno = 0; pi->lyrno <
+ pi->numlyrs && pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
+ prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
+ if (pi->lyrno >= *prclyrno) {
+ ++(*prclyrno);
+ return 0;
+ }
+skip:
+ ;
+ }
+ }
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static int jpc_pi_nextpcrl(register jpc_pi_t *pi)
+{
+ int rlvlno;
+ jpc_pirlvl_t *pirlvl;
+ jpc_pchg_t *pchg;
+ int prchind;
+ int prcvind;
+ int *prclyrno;
+ int compno;
+ jpc_picomp_t *picomp;
+ int xstep;
+ int ystep;
+ uint_fast32_t trx0;
+ uint_fast32_t try0;
+ uint_fast32_t r;
+ uint_fast32_t rpx;
+ uint_fast32_t rpy;
+
+ pchg = pi->pchg;
+ if (!pi->prgvolfirst) {
+ goto skip;
+ } else {
+ pi->xstep = 0;
+ pi->ystep = 0;
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
+ ++compno, ++picomp) {
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ xstep = picomp->hsamp * (1 <<
+ (pirlvl->prcwidthexpn + picomp->numrlvls -
+ rlvlno - 1));
+ ystep = picomp->vsamp * (1 <<
+ (pirlvl->prcheightexpn + picomp->numrlvls -
+ rlvlno - 1));
+ pi->xstep = (!pi->xstep) ? xstep :
+ JAS_MIN(pi->xstep, xstep);
+ pi->ystep = (!pi->ystep) ? ystep :
+ JAS_MIN(pi->ystep, ystep);
+ }
+ }
+ pi->prgvolfirst = 0;
+ }
+
+ for (pi->y = pi->ystart; pi->y < pi->yend; pi->y += pi->ystep -
+ (pi->y % pi->ystep)) {
+ for (pi->x = pi->xstart; pi->x < pi->xend; pi->x += pi->xstep -
+ (pi->x % pi->xstep)) {
+ for (pi->compno = pchg->compnostart, pi->picomp =
+ &pi->picomps[pi->compno]; pi->compno < pi->numcomps
+ && pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
+ ++pi->picomp) {
+ for (pi->rlvlno = pchg->rlvlnostart,
+ pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
+ pi->rlvlno < pi->picomp->numrlvls &&
+ pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno,
+ ++pi->pirlvl) {
+ if (pi->pirlvl->numprcs == 0) {
+ continue;
+ }
+ r = pi->picomp->numrlvls - 1 - pi->rlvlno;
+ trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
+ try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
+ rpx = r + pi->pirlvl->prcwidthexpn;
+ rpy = r + pi->pirlvl->prcheightexpn;
+ if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) ||
+ !(pi->x % (pi->picomp->hsamp << rpx))) &&
+ ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) ||
+ !(pi->y % (pi->picomp->vsamp << rpy)))) {
+ prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
+ << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
+ pi->pirlvl->prcwidthexpn);
+ prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
+ << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
+ pi->pirlvl->prcheightexpn);
+ pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind;
+ assert(pi->prcno < pi->pirlvl->numprcs);
+ for (pi->lyrno = 0; pi->lyrno < pi->numlyrs &&
+ pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
+ prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
+ if (pi->lyrno >= *prclyrno) {
+ ++(*prclyrno);
+ return 0;
+ }
+skip:
+ ;
+ }
+ }
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static int jpc_pi_nextcprl(register jpc_pi_t *pi)
+{
+ int rlvlno;
+ jpc_pirlvl_t *pirlvl;
+ jpc_pchg_t *pchg;
+ int prchind;
+ int prcvind;
+ int *prclyrno;
+ uint_fast32_t trx0;
+ uint_fast32_t try0;
+ uint_fast32_t r;
+ uint_fast32_t rpx;
+ uint_fast32_t rpy;
+
+ pchg = pi->pchg;
+ if (!pi->prgvolfirst) {
+ goto skip;
+ } else {
+ pi->prgvolfirst = 0;
+ }
+
+ for (pi->compno = pchg->compnostart, pi->picomp =
+ &pi->picomps[pi->compno]; pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
+ ++pi->picomp) {
+ pirlvl = pi->picomp->pirlvls;
+ pi->xstep = pi->picomp->hsamp * (1 << (pirlvl->prcwidthexpn +
+ pi->picomp->numrlvls - 1));
+ pi->ystep = pi->picomp->vsamp * (1 << (pirlvl->prcheightexpn +
+ pi->picomp->numrlvls - 1));
+ for (rlvlno = 1, pirlvl = &pi->picomp->pirlvls[1];
+ rlvlno < pi->picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ pi->xstep = JAS_MIN(pi->xstep, pi->picomp->hsamp * (1 <<
+ (pirlvl->prcwidthexpn + pi->picomp->numrlvls -
+ rlvlno - 1)));
+ pi->ystep = JAS_MIN(pi->ystep, pi->picomp->vsamp * (1 <<
+ (pirlvl->prcheightexpn + pi->picomp->numrlvls -
+ rlvlno - 1)));
+ }
+ for (pi->y = pi->ystart; pi->y < pi->yend;
+ pi->y += pi->ystep - (pi->y % pi->ystep)) {
+ for (pi->x = pi->xstart; pi->x < pi->xend;
+ pi->x += pi->xstep - (pi->x % pi->xstep)) {
+ for (pi->rlvlno = pchg->rlvlnostart,
+ pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
+ pi->rlvlno < pi->picomp->numrlvls && pi->rlvlno <
+ pchg->rlvlnoend; ++pi->rlvlno, ++pi->pirlvl) {
+ if (pi->pirlvl->numprcs == 0) {
+ continue;
+ }
+ r = pi->picomp->numrlvls - 1 - pi->rlvlno;
+ trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
+ try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
+ rpx = r + pi->pirlvl->prcwidthexpn;
+ rpy = r + pi->pirlvl->prcheightexpn;
+ if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) ||
+ !(pi->x % (pi->picomp->hsamp << rpx))) &&
+ ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) ||
+ !(pi->y % (pi->picomp->vsamp << rpy)))) {
+ prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
+ << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
+ pi->pirlvl->prcwidthexpn);
+ prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
+ << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
+ pi->pirlvl->prcheightexpn);
+ pi->prcno = prcvind *
+ pi->pirlvl->numhprcs +
+ prchind;
+ assert(pi->prcno <
+ pi->pirlvl->numprcs);
+ for (pi->lyrno = 0; pi->lyrno <
+ pi->numlyrs && pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
+ prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
+ if (pi->lyrno >= *prclyrno) {
+ ++(*prclyrno);
+ return 0;
+ }
+skip:
+ ;
+ }
+ }
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static void pirlvl_destroy(jpc_pirlvl_t *rlvl)
+{
+ if (rlvl->prclyrnos) {
+ jas_free(rlvl->prclyrnos);
+ }
+}
+
+static void jpc_picomp_destroy(jpc_picomp_t *picomp)
+{
+ int rlvlno;
+ jpc_pirlvl_t *pirlvl;
+ if (picomp->pirlvls) {
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ pirlvl_destroy(pirlvl);
+ }
+ jas_free(picomp->pirlvls);
+ }
+}
+
+void jpc_pi_destroy(jpc_pi_t *pi)
+{
+ jpc_picomp_t *picomp;
+ int compno;
+ if (pi->picomps) {
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
+ ++compno, ++picomp) {
+ jpc_picomp_destroy(picomp);
+ }
+ jas_free(pi->picomps);
+ }
+ if (pi->pchglist) {
+ jpc_pchglist_destroy(pi->pchglist);
+ }
+ jas_free(pi);
+}
+
+jpc_pi_t *jpc_pi_create0()
+{
+ jpc_pi_t *pi;
+ if (!(pi = jas_malloc(sizeof(jpc_pi_t)))) {
+ return 0;
+ }
+ pi->picomps = 0;
+ pi->pchgno = 0;
+ if (!(pi->pchglist = jpc_pchglist_create())) {
+ jas_free(pi);
+ return 0;
+ }
+ return pi;
+}
+
+int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg)
+{
+ return jpc_pchglist_insert(pi->pchglist, -1, pchg);
+}
+
+jpc_pchglist_t *jpc_pchglist_create()
+{
+ jpc_pchglist_t *pchglist;
+ if (!(pchglist = jas_malloc(sizeof(jpc_pchglist_t)))) {
+ return 0;
+ }
+ pchglist->numpchgs = 0;
+ pchglist->maxpchgs = 0;
+ pchglist->pchgs = 0;
+ return pchglist;
+}
+
+int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg)
+{
+ int i;
+ int newmaxpchgs;
+ jpc_pchg_t **newpchgs;
+ if (pchgno < 0) {
+ pchgno = pchglist->numpchgs;
+ }
+ if (pchglist->numpchgs >= pchglist->maxpchgs) {
+ newmaxpchgs = pchglist->maxpchgs + 128;
+ if (!(newpchgs = jas_realloc(pchglist->pchgs, newmaxpchgs * sizeof(jpc_pchg_t *)))) {
+ return -1;
+ }
+ pchglist->maxpchgs = newmaxpchgs;
+ pchglist->pchgs = newpchgs;
+ }
+ for (i = pchglist->numpchgs; i > pchgno; --i) {
+ pchglist->pchgs[i] = pchglist->pchgs[i - 1];
+ }
+ pchglist->pchgs[pchgno] = pchg;
+ ++pchglist->numpchgs;
+ return 0;
+}
+
+jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno)
+{
+ int i;
+ jpc_pchg_t *pchg;
+ assert(pchgno < pchglist->numpchgs);
+ pchg = pchglist->pchgs[pchgno];
+ for (i = pchgno + 1; i < pchglist->numpchgs; ++i) {
+ pchglist->pchgs[i - 1] = pchglist->pchgs[i];
+ }
+ --pchglist->numpchgs;
+ return pchg;
+}
+
+jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg)
+{
+ jpc_pchg_t *newpchg;
+ if (!(newpchg = jas_malloc(sizeof(jpc_pchg_t)))) {
+ return 0;
+ }
+ *newpchg = *pchg;
+ return newpchg;
+}
+
+jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist)
+{
+ jpc_pchglist_t *newpchglist;
+ jpc_pchg_t *newpchg;
+ int pchgno;
+ if (!(newpchglist = jpc_pchglist_create())) {
+ return 0;
+ }
+ for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) {
+ if (!(newpchg = jpc_pchg_copy(pchglist->pchgs[pchgno])) ||
+ jpc_pchglist_insert(newpchglist, -1, newpchg)) {
+ jpc_pchglist_destroy(newpchglist);
+ return 0;
+ }
+ }
+ return newpchglist;
+}
+
+void jpc_pchglist_destroy(jpc_pchglist_t *pchglist)
+{
+ int pchgno;
+ if (pchglist->pchgs) {
+ for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) {
+ jpc_pchg_destroy(pchglist->pchgs[pchgno]);
+ }
+ jas_free(pchglist->pchgs);
+ }
+ jas_free(pchglist);
+}
+
+void jpc_pchg_destroy(jpc_pchg_t *pchg)
+{
+ jas_free(pchg);
+}
+
+jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno)
+{
+ return pchglist->pchgs[pchgno];
+}
+
+int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist)
+{
+ return pchglist->numpchgs;
+}
+
+int jpc_pi_init(jpc_pi_t *pi)
+{
+ int compno;
+ int rlvlno;
+ int prcno;
+ jpc_picomp_t *picomp;
+ jpc_pirlvl_t *pirlvl;
+ int *prclyrno;
+
+ pi->prgvolfirst = 0;
+ pi->valid = 0;
+ pi->pktno = -1;
+ pi->pchgno = -1;
+ pi->pchg = 0;
+
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
+ ++compno, ++picomp) {
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ for (prcno = 0, prclyrno = pirlvl->prclyrnos;
+ prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
+ *prclyrno = 0;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2cod.h b/osframework/source/ImageLib/jpeg2000/jpc_t2cod.h
new file mode 100644
index 0000000..062f033
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2cod.h
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier-2 Coding Library
+ *
+ * $Id: jpc_t2cod.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T2COD_H
+#define JPC_T2COD_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jpc_cs.h"
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+/* Progression change list. */
+
+typedef struct {
+
+ /* The number of progression changes. */
+ int numpchgs;
+
+ /* The maximum number of progression changes that can be accomodated
+ without growing the progression change array. */
+ int maxpchgs;
+
+ /* The progression changes. */
+ jpc_pchg_t **pchgs;
+
+} jpc_pchglist_t;
+
+/* Packet iterator per-resolution-level information. */
+
+typedef struct {
+
+ /* The number of precincts. */
+ int numprcs;
+
+ /* The last layer processed for each precinct. */
+ int *prclyrnos;
+
+ /* The precinct width exponent. */
+ int prcwidthexpn;
+
+ /* The precinct height exponent. */
+ int prcheightexpn;
+
+ /* The number of precincts spanning the resolution level in the horizontal
+ direction. */
+ int numhprcs;
+
+} jpc_pirlvl_t;
+
+/* Packet iterator per-component information. */
+
+typedef struct {
+
+ /* The number of resolution levels. */
+ int numrlvls;
+
+ /* The per-resolution-level information. */
+ jpc_pirlvl_t *pirlvls;
+
+ /* The horizontal sampling period. */
+ int hsamp;
+
+ /* The vertical sampling period. */
+ int vsamp;
+
+} jpc_picomp_t;
+
+/* Packet iterator class. */
+
+typedef struct {
+
+ /* The number of layers. */
+ int numlyrs;
+
+ /* The number of resolution levels. */
+ int maxrlvls;
+
+ /* The number of components. */
+ int numcomps;
+
+ /* The per-component information. */
+ jpc_picomp_t *picomps;
+
+ /* The current component. */
+ jpc_picomp_t *picomp;
+
+ /* The current resolution level. */
+ jpc_pirlvl_t *pirlvl;
+
+ /* The number of the current component. */
+ int compno;
+
+ /* The number of the current resolution level. */
+ int rlvlno;
+
+ /* The number of the current precinct. */
+ int prcno;
+
+ /* The number of the current layer. */
+ int lyrno;
+
+ /* The x-coordinate of the current position. */
+ int x;
+
+ /* The y-coordinate of the current position. */
+ int y;
+
+ /* The horizontal step size. */
+ int xstep;
+
+ /* The vertical step size. */
+ int ystep;
+
+ /* The x-coordinate of the top-left corner of the tile on the reference
+ grid. */
+ int xstart;
+
+ /* The y-coordinate of the top-left corner of the tile on the reference
+ grid. */
+ int ystart;
+
+ /* The x-coordinate of the bottom-right corner of the tile on the
+ reference grid (plus one). */
+ int xend;
+
+ /* The y-coordinate of the bottom-right corner of the tile on the
+ reference grid (plus one). */
+ int yend;
+
+ /* The current progression change. */
+ jpc_pchg_t *pchg;
+
+ /* The progression change list. */
+ jpc_pchglist_t *pchglist;
+
+ /* The progression to use in the absense of explicit specification. */
+ jpc_pchg_t defaultpchg;
+
+ /* The current progression change number. */
+ int pchgno;
+
+ /* Is this the first time in the current progression volume? */
+ bool prgvolfirst;
+
+ /* Is the current iterator value valid? */
+ bool valid;
+
+ /* The current packet number. */
+ int pktno;
+
+} jpc_pi_t;
+
+/******************************************************************************\
+* Functions/macros for packet iterators.
+\******************************************************************************/
+
+/* Create a packet iterator. */
+jpc_pi_t *jpc_pi_create0(void);
+
+/* Destroy a packet iterator. */
+void jpc_pi_destroy(jpc_pi_t *pi);
+
+/* Add a progression change to a packet iterator. */
+int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg);
+
+/* Prepare a packet iterator for iteration. */
+int jpc_pi_init(jpc_pi_t *pi);
+
+/* Set the iterator to the first packet. */
+int jpc_pi_begin(jpc_pi_t *pi);
+
+/* Proceed to the next packet in sequence. */
+int jpc_pi_next(jpc_pi_t *pi);
+
+/* Get the index of the current packet. */
+#define jpc_pi_getind(pi) ((pi)->pktno)
+
+/* Get the component number of the current packet. */
+#define jpc_pi_cmptno(pi) (assert(pi->valid), (pi)->compno)
+
+/* Get the resolution level of the current packet. */
+#define jpc_pi_rlvlno(pi) (assert(pi->valid), (pi)->rlvlno)
+
+/* Get the layer number of the current packet. */
+#define jpc_pi_lyrno(pi) (assert(pi->valid), (pi)->lyrno)
+
+/* Get the precinct number of the current packet. */
+#define jpc_pi_prcno(pi) (assert(pi->valid), (pi)->prcno)
+
+/* Get the progression order for the current packet. */
+#define jpc_pi_prg(pi) (assert(pi->valid), (pi)->pchg->prgord)
+
+/******************************************************************************\
+* Functions/macros for progression change lists.
+\******************************************************************************/
+
+/* Create a progression change list. */
+jpc_pchglist_t *jpc_pchglist_create(void);
+
+/* Destroy a progression change list. */
+void jpc_pchglist_destroy(jpc_pchglist_t *pchglist);
+
+/* Insert a new element into a progression change list. */
+int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg);
+
+/* Remove an element from a progression change list. */
+jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno);
+
+/* Get an element from a progression change list. */
+jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno);
+
+/* Copy a progression change list. */
+jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist);
+
+/* Get the number of elements in a progression change list. */
+int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist);
+
+/******************************************************************************\
+* Functions/macros for progression changes.
+\******************************************************************************/
+
+/* Destroy a progression change. */
+void jpc_pchg_destroy(jpc_pchg_t *pchg);
+
+/* Copy a progression change. */
+jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2dec.c b/osframework/source/ImageLib/jpeg2000/jpc_t2dec.c
new file mode 100644
index 0000000..19be199
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2dec.c
@@ -0,0 +1,630 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 2 Decoder
+ *
+ * $Id: jpc_t2dec.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jas_types.h"
+#include "jas_fix.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+#include "jas_stream.h"
+#include "jas_debug.h"
+
+#include "jpc_bs.h"
+#include "jpc_dec.h"
+#include "jpc_cs.h"
+#include "jpc_mqdec.h"
+#include "jpc_t2dec.h"
+#include "jpc_t1cod.h"
+#include "jpc_math.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+long jpc_dec_lookahead(jas_stream_t *in);
+static int jpc_getcommacode(jpc_bitstream_t *in);
+static int jpc_getnumnewpasses(jpc_bitstream_t *in);
+static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int lvlno,
+ int prcno, int lyrno);
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+static int jpc_getcommacode(jpc_bitstream_t *in)
+{
+ int n;
+ int v;
+
+ n = 0;
+ for (;;) {
+ if ((v = jpc_bitstream_getbit(in)) < 0) {
+ return -1;
+ }
+ if (jpc_bitstream_eof(in)) {
+ return -1;
+ }
+ if (!v) {
+ break;
+ }
+ ++n;
+ }
+
+ return n;
+}
+
+static int jpc_getnumnewpasses(jpc_bitstream_t *in)
+{
+ int n;
+
+ if ((n = jpc_bitstream_getbit(in)) > 0) {
+ if ((n = jpc_bitstream_getbit(in)) > 0) {
+ if ((n = jpc_bitstream_getbits(in, 2)) == 3) {
+ if ((n = jpc_bitstream_getbits(in, 5)) == 31) {
+ if ((n = jpc_bitstream_getbits(in, 7)) >= 0) {
+ n += 36 + 1;
+ }
+ } else if (n >= 0) {
+ n += 5 + 1;
+ }
+ } else if (n >= 0) {
+ n += 2 + 1;
+ }
+ } else if (!n) {
+ n += 2;
+ }
+ } else if (!n) {
+ ++n;
+ }
+
+ return n;
+}
+
+static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int rlvlno,
+ int prcno, int lyrno)
+{
+ jpc_bitstream_t *inb;
+ jpc_dec_tcomp_t *tcomp;
+ jpc_dec_rlvl_t *rlvl;
+ jpc_dec_band_t *band;
+ jpc_dec_cblk_t *cblk;
+ int n;
+ int m;
+ int i;
+ jpc_tagtreenode_t *leaf;
+ int included;
+ int ret;
+ int numnewpasses;
+ jpc_dec_seg_t *seg;
+ int len;
+ int present;
+ int savenumnewpasses;
+ int mycounter;
+ jpc_ms_t *ms;
+ jpc_dec_tile_t *tile;
+ jpc_dec_ccp_t *ccp;
+ jpc_dec_cp_t *cp;
+ int bandno;
+ jpc_dec_prc_t *prc;
+ int usedcblkcnt;
+ int cblkno;
+ uint_fast32_t bodylen;
+ bool discard;
+ int passno;
+ int maxpasses;
+ int hdrlen;
+ int hdroffstart;
+ int hdroffend;
+
+ /* Avoid compiler warning about possible use of uninitialized
+ variable. */
+ bodylen = 0;
+
+ discard = (lyrno >= dec->maxlyrs);
+
+ tile = dec->curtile;
+ cp = tile->cp;
+ ccp = &cp->ccps[compno];
+
+ /*
+ * Decode the packet header.
+ */
+
+ /* Decode the SOP marker segment if present. */
+ if (cp->csty & JPC_COD_SOP) {
+ if (jpc_dec_lookahead(in) == JPC_MS_SOP) {
+ if (!(ms = jpc_getms(in, dec->cstate))) {
+ return -1;
+ }
+ if (jpc_ms_gettype(ms) != JPC_MS_SOP) {
+ jpc_ms_destroy(ms);
+ fprintf(stderr, "missing SOP marker segment\n");
+ return -1;
+ }
+ jpc_ms_destroy(ms);
+ }
+ }
+
+hdroffstart = jas_stream_getrwcount(pkthdrstream);
+
+ if (!(inb = jpc_bitstream_sopen(pkthdrstream, "r"))) {
+ return -1;
+ }
+
+ if ((present = jpc_bitstream_getbit(inb)) < 0) {
+ return 1;
+ }
+ JAS_DBGLOG(10, ("\n", present));
+ JAS_DBGLOG(10, ("present=%d ", present));
+
+ /* Is the packet non-empty? */
+ if (present) {
+ /* The packet is non-empty. */
+ tcomp = &tile->tcomps[compno];
+ rlvl = &tcomp->rlvls[rlvlno];
+ bodylen = 0;
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ prc = &band->prcs[prcno];
+ if (!prc->cblks) {
+ continue;
+ }
+ usedcblkcnt = 0;
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ ++usedcblkcnt;
+ if (!cblk->numpasses) {
+ leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1);
+ if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) {
+ return -1;
+ }
+ } else {
+ if ((included = jpc_bitstream_getbit(inb)) < 0) {
+ return -1;
+ }
+ }
+ JAS_DBGLOG(10, ("\n"));
+ JAS_DBGLOG(10, ("included=%d ", included));
+ if (!included) {
+ continue;
+ }
+ if (!cblk->numpasses) {
+ i = 1;
+ leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1);
+ for (;;) {
+ if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) {
+ return -1;
+ }
+ if (ret) {
+ break;
+ }
+ ++i;
+ }
+ cblk->numimsbs = i - 1;
+ cblk->firstpassno = cblk->numimsbs * 3;
+ }
+ if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) {
+ return -1;
+ }
+ JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
+ seg = cblk->curseg;
+ savenumnewpasses = numnewpasses;
+ mycounter = 0;
+ if (numnewpasses > 0) {
+ if ((m = jpc_getcommacode(inb)) < 0) {
+ return -1;
+ }
+ cblk->numlenbits += m;
+ JAS_DBGLOG(10, ("increment=%d ", m));
+ while (numnewpasses > 0) {
+ passno = cblk->firstpassno + cblk->numpasses + mycounter;
+ /* XXX - the maxpasses is not set precisely but this doesn't matter... */
+ maxpasses = JPC_SEGPASSCNT(passno, cblk->firstpassno, 10000, (ccp->cblkctx & JPC_COX_LAZY) != 0, (ccp->cblkctx & JPC_COX_TERMALL) != 0);
+ if (!discard && !seg) {
+ if (!(seg = jpc_seg_alloc())) {
+ return -1;
+ }
+ jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg);
+ if (!cblk->curseg) {
+ cblk->curseg = seg;
+ }
+ seg->passno = passno;
+ seg->type = JPC_SEGTYPE(seg->passno, cblk->firstpassno, (ccp->cblkctx & JPC_COX_LAZY) != 0);
+ seg->maxpasses = maxpasses;
+ }
+ n = JAS_MIN(numnewpasses, maxpasses);
+ mycounter += n;
+ numnewpasses -= n;
+ if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
+ return -1;
+ }
+ JAS_DBGLOG(10, ("len=%d ", len));
+ if (!discard) {
+ seg->lyrno = lyrno;
+ seg->numpasses += n;
+ seg->cnt = len;
+ seg = seg->next;
+ }
+ bodylen += len;
+ }
+ }
+ cblk->numpasses += savenumnewpasses;
+ }
+ }
+
+ jpc_bitstream_inalign(inb, 0, 0);
+
+ } else {
+ if (jpc_bitstream_inalign(inb, 0x7f, 0)) {
+ fprintf(stderr, "alignment failed\n");
+ return -1;
+ }
+ }
+ jpc_bitstream_close(inb);
+
+ hdroffend = jas_stream_getrwcount(pkthdrstream);
+ hdrlen = hdroffend - hdroffstart;
+ if (jas_getdbglevel() >= 5) {
+ fprintf(stderr, "hdrlen=%lu bodylen=%lu \n", (unsigned long) hdrlen,
+ (unsigned long) bodylen);
+ }
+
+ if (cp->csty & JPC_COD_EPH) {
+ if (jpc_dec_lookahead(pkthdrstream) == JPC_MS_EPH) {
+ if (!(ms = jpc_getms(pkthdrstream, dec->cstate))) {
+ fprintf(stderr, "cannot get (EPH) marker segment\n");
+ return -1;
+ }
+ if (jpc_ms_gettype(ms) != JPC_MS_EPH) {
+ jpc_ms_destroy(ms);
+ fprintf(stderr, "missing EPH marker segment\n");
+ return -1;
+ }
+ jpc_ms_destroy(ms);
+ }
+ }
+
+ /* decode the packet body. */
+
+ if (jas_getdbglevel() >= 1) {
+ fprintf(stderr, "packet body offset=%06ld\n", (long) jas_stream_getrwcount(in));
+ }
+
+ if (!discard) {
+ tcomp = &tile->tcomps[compno];
+ rlvl = &tcomp->rlvls[rlvlno];
+ for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
+ ++bandno, ++band) {
+ if (!band->data) {
+ continue;
+ }
+ prc = &band->prcs[prcno];
+ if (!prc->cblks) {
+ continue;
+ }
+ for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
+ ++cblkno, ++cblk) {
+ seg = cblk->curseg;
+ while (seg) {
+ if (!seg->stream) {
+ if (!(seg->stream = jas_stream_memopen(0, 0))) {
+ return -1;
+ }
+ }
+#if 0
+fprintf(stderr, "lyrno=%02d, compno=%02d, lvlno=%02d, prcno=%02d, bandno=%02d, cblkno=%02d, passno=%02d numpasses=%02d cnt=%d numbps=%d, numimsbs=%d\n", lyrno, compno, rlvlno, prcno, band - rlvl->bands, cblk - prc->cblks, seg->passno, seg->numpasses, seg->cnt, band->numbps, cblk->numimsbs);
+#endif
+ if (seg->cnt > 0) {
+ if (jpc_getdata(in, seg->stream, seg->cnt) < 0) {
+ return -1;
+ }
+ seg->cnt = 0;
+ }
+ if (seg->numpasses >= seg->maxpasses) {
+ cblk->curseg = seg->next;
+ }
+ seg = seg->next;
+ }
+ }
+ }
+ } else {
+ if (jas_stream_gobble(in, bodylen) != JAS_CAST(int, bodylen)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/********************************************************************************************/
+/********************************************************************************************/
+
+int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in)
+{
+ jpc_dec_tile_t *tile;
+ jpc_pi_t *pi;
+ int ret;
+
+ tile = dec->curtile;
+ pi = tile->pi;
+ for (;;) {
+if (!tile->pkthdrstream || jas_stream_peekc(tile->pkthdrstream) == EOF) {
+ switch (jpc_dec_lookahead(in)) {
+ case JPC_MS_EOC:
+ case JPC_MS_SOT:
+ return 0;
+ break;
+ case JPC_MS_SOP:
+ case JPC_MS_EPH:
+ case 0:
+ break;
+ default:
+ return -1;
+ break;
+ }
+}
+ if ((ret = jpc_pi_next(pi))) {
+ return ret;
+ }
+if (dec->maxpkts >= 0 && dec->numpkts >= dec->maxpkts) {
+ fprintf(stderr, "warning: stopping decode prematurely as requested\n");
+ return 0;
+}
+ if (jas_getdbglevel() >= 1) {
+ fprintf(stderr, "packet offset=%08ld prg=%d cmptno=%02d "
+ "rlvlno=%02d prcno=%03d lyrno=%02d\n", (long)
+ jas_stream_getrwcount(in), jpc_pi_prg(pi), jpc_pi_cmptno(pi),
+ jpc_pi_rlvlno(pi), jpc_pi_prcno(pi), jpc_pi_lyrno(pi));
+ }
+ if (jpc_dec_decodepkt(dec, pkthdrstream, in, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi),
+ jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) {
+ return -1;
+ }
+++dec->numpkts;
+ }
+
+ return 0;
+}
+
+jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile)
+{
+ jpc_pi_t *pi;
+ int compno;
+ jpc_picomp_t *picomp;
+ jpc_pirlvl_t *pirlvl;
+ jpc_dec_tcomp_t *tcomp;
+ int rlvlno;
+ jpc_dec_rlvl_t *rlvl;
+ int prcno;
+ int *prclyrno;
+ jpc_dec_cmpt_t *cmpt;
+
+ if (!(pi = jpc_pi_create0())) {
+ return 0;
+ }
+ pi->numcomps = dec->numcomps;
+ if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno,
+ ++picomp) {
+ picomp->pirlvls = 0;
+ }
+
+ for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps;
+ compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
+ picomp->numrlvls = tcomp->numrlvls;
+ if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls *
+ sizeof(jpc_pirlvl_t)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ pirlvl->prclyrnos = 0;
+ }
+ for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
+ rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
+/* XXX sizeof(long) should be sizeof different type */
+ pirlvl->numprcs = rlvl->numprcs;
+ if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs *
+ sizeof(long)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ }
+ }
+
+ pi->maxrlvls = 0;
+ for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps, cmpt =
+ dec->cmpts; compno < pi->numcomps; ++compno, ++tcomp, ++picomp,
+ ++cmpt) {
+ picomp->hsamp = cmpt->hstep;
+ picomp->vsamp = cmpt->vstep;
+ for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
+ rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
+ pirlvl->prcwidthexpn = rlvl->prcwidthexpn;
+ pirlvl->prcheightexpn = rlvl->prcheightexpn;
+ for (prcno = 0, prclyrno = pirlvl->prclyrnos;
+ prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
+ *prclyrno = 0;
+ }
+ pirlvl->numhprcs = rlvl->numhprcs;
+ }
+ if (pi->maxrlvls < tcomp->numrlvls) {
+ pi->maxrlvls = tcomp->numrlvls;
+ }
+ }
+
+ pi->numlyrs = tile->cp->numlyrs;
+ pi->xstart = tile->xstart;
+ pi->ystart = tile->ystart;
+ pi->xend = tile->xend;
+ pi->yend = tile->yend;
+
+ pi->picomp = 0;
+ pi->pirlvl = 0;
+ pi->x = 0;
+ pi->y = 0;
+ pi->compno = 0;
+ pi->rlvlno = 0;
+ pi->prcno = 0;
+ pi->lyrno = 0;
+ pi->xstep = 0;
+ pi->ystep = 0;
+
+ pi->pchgno = -1;
+
+ pi->defaultpchg.prgord = tile->cp->prgord;
+ pi->defaultpchg.compnostart = 0;
+ pi->defaultpchg.compnoend = pi->numcomps;
+ pi->defaultpchg.rlvlnostart = 0;
+ pi->defaultpchg.rlvlnoend = pi->maxrlvls;
+ pi->defaultpchg.lyrnoend = pi->numlyrs;
+ pi->pchg = 0;
+
+ pi->valid = 0;
+
+ return pi;
+}
+
+long jpc_dec_lookahead(jas_stream_t *in)
+{
+ uint_fast16_t x;
+ if (jpc_getuint16(in, &x)) {
+ return -1;
+ }
+ if (jas_stream_ungetc(in, x & 0xff) == EOF ||
+ jas_stream_ungetc(in, x >> 8) == EOF) {
+ return -1;
+ }
+ if (x >= JPC_MS_INMIN && x <= JPC_MS_INMAX) {
+ return x;
+ }
+ return 0;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2dec.h b/osframework/source/ImageLib/jpeg2000/jpc_t2dec.h
new file mode 100644
index 0000000..4f28d75
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2dec.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 2 Decoder
+ *
+ * $Id: jpc_t2dec.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T2DEC_H
+#define JPC_T2DEC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_fix.h"
+#include "jas_stream.h"
+
+#include "jpc_bs.h"
+#include "jpc_dec.h"
+#include "jpc_mqdec.h"
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Decode the packets for a tile-part. */
+int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream,
+ jas_stream_t *in);
+
+/* Create a packet iterator for the decoder. */
+jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2enc.c b/osframework/source/ImageLib/jpeg2000/jpc_t2enc.c
new file mode 100644
index 0000000..9bad895
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2enc.c
@@ -0,0 +1,704 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 2 Encoder
+ *
+ * $Id: jpc_t2enc.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jas_fix.h"
+#include "jas_malloc.h"
+#include "jas_math.h"
+#include "jas_debug.h"
+
+#include "jpc_flt.h"
+#include "jpc_t2enc.h"
+#include "jpc_t2cod.h"
+#include "jpc_tagtree.h"
+#include "jpc_enc.h"
+#include "jpc_math.h"
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+static int jpc_putcommacode(jpc_bitstream_t *out, int n)
+{
+ assert(n >= 0);
+
+ while (--n >= 0) {
+ if (jpc_bitstream_putbit(out, 1) == EOF) {
+ return -1;
+ }
+ }
+ if (jpc_bitstream_putbit(out, 0) == EOF) {
+ return -1;
+ }
+ return 0;
+}
+
+static int jpc_putnumnewpasses(jpc_bitstream_t *out, int n)
+{
+ int ret;
+
+ if (n <= 0) {
+ return -1;
+ } else if (n == 1) {
+ ret = jpc_bitstream_putbit(out, 0);
+ } else if (n == 2) {
+ ret = jpc_bitstream_putbits(out, 2, 2);
+ } else if (n <= 5) {
+ ret = jpc_bitstream_putbits(out, 4, 0xc | (n - 3));
+ } else if (n <= 36) {
+ ret = jpc_bitstream_putbits(out, 9, 0x1e0 | (n - 6));
+ } else if (n <= 164) {
+ ret = jpc_bitstream_putbits(out, 16, 0xff80 | (n - 37));
+ } else {
+ /* The standard has no provision for encoding a larger value.
+ In practice, however, it is highly unlikely that this
+ limitation will ever be encountered. */
+ return -1;
+ }
+
+ return (ret != EOF) ? 0 : (-1);
+}
+
+int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out)
+{
+ jpc_enc_tile_t *tile;
+ jpc_pi_t *pi;
+
+ tile = enc->curtile;
+
+ jpc_init_t2state(enc, 0);
+ pi = tile->pi;
+ jpc_pi_init(pi);
+
+ if (!jpc_pi_next(pi)) {
+ for (;;) {
+ if (jpc_enc_encpkt(enc, out, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi),
+ jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) {
+ return -1;
+ }
+ if (jpc_pi_next(pi)) {
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno, int prcno, int lyrno)
+{
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ jpc_bitstream_t *outb;
+ jpc_enc_pass_t *pass;
+ jpc_enc_pass_t *startpass;
+ jpc_enc_pass_t *lastpass;
+ jpc_enc_pass_t *endpass;
+ jpc_enc_pass_t *endpasses;
+ int i;
+ int included;
+ int ret;
+ jpc_tagtreenode_t *leaf;
+ int n;
+ int t1;
+ int t2;
+ int adjust;
+ int maxadjust;
+ int datalen;
+ int numnewpasses;
+ int passcount;
+ jpc_enc_tile_t *tile;
+ jpc_enc_prc_t *prc;
+ jpc_enc_cp_t *cp;
+ jpc_ms_t *ms;
+
+ tile = enc->curtile;
+ cp = enc->cp;
+
+ if (cp->tcp.csty & JPC_COD_SOP) {
+ if (!(ms = jpc_ms_create(JPC_MS_SOP))) {
+ return -1;
+ }
+ ms->parms.sop.seqno = jpc_pi_getind(tile->pi);
+ if (jpc_putms(out, enc->cstate, ms)) {
+ return -1;
+ }
+ jpc_ms_destroy(ms);
+ }
+
+ outb = jpc_bitstream_sopen(out, "w+");
+ assert(outb);
+
+ if (jpc_bitstream_putbit(outb, 1) == EOF) {
+ return -1;
+ }
+ JAS_DBGLOG(10, ("\n"));
+ JAS_DBGLOG(10, ("present. "));
+
+ comp = &tile->tcmpts[compno];
+ lvl = &comp->rlvls[lvlno];
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ prc = &band->prcs[prcno];
+ if (!prc->cblks) {
+ continue;
+ }
+
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ if (!lyrno) {
+ leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
+ jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs);
+ }
+ pass = cblk->curpass;
+ included = (pass && pass->lyrno == lyrno);
+ if (included && (!cblk->numencpasses)) {
+ assert(pass->lyrno == lyrno);
+ leaf = jpc_tagtree_getleaf(prc->incltree,
+ cblk - prc->cblks);
+ jpc_tagtree_setvalue(prc->incltree, leaf, pass->lyrno);
+ }
+ }
+
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ pass = cblk->curpass;
+ included = (pass && pass->lyrno == lyrno);
+ if (!cblk->numencpasses) {
+ leaf = jpc_tagtree_getleaf(prc->incltree,
+ cblk - prc->cblks);
+ if (jpc_tagtree_encode(prc->incltree, leaf, lyrno
+ + 1, outb) < 0) {
+ return -1;
+ }
+ } else {
+ if (jpc_bitstream_putbit(outb, included) == EOF) {
+ return -1;
+ }
+ }
+ JAS_DBGLOG(10, ("included=%d ", included));
+ if (!included) {
+ continue;
+ }
+ if (!cblk->numencpasses) {
+ i = 1;
+ leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
+ for (;;) {
+ if ((ret = jpc_tagtree_encode(prc->nlibtree, leaf, i, outb)) < 0) {
+ return -1;
+ }
+ if (ret) {
+ break;
+ }
+ ++i;
+ }
+ assert(leaf->known_ && i == leaf->value_ + 1);
+ }
+
+ endpasses = &cblk->passes[cblk->numpasses];
+ startpass = pass;
+ endpass = startpass;
+ while (endpass != endpasses && endpass->lyrno == lyrno){
+ ++endpass;
+ }
+ numnewpasses = endpass - startpass;
+ if (jpc_putnumnewpasses(outb, numnewpasses)) {
+ return -1;
+ }
+ JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
+
+ lastpass = endpass - 1;
+ n = startpass->start;
+ passcount = 1;
+ maxadjust = 0;
+ for (pass = startpass; pass != endpass; ++pass) {
+ if (pass->term || pass == lastpass) {
+ datalen = pass->end - n;
+ t1 = jpc_firstone(datalen) + 1;
+ t2 = cblk->numlenbits + jpc_floorlog2(passcount);
+ adjust = JAS_MAX(t1 - t2, 0);
+ maxadjust = JAS_MAX(adjust, maxadjust);
+ n += datalen;
+ passcount = 1;
+ } else {
+ ++passcount;
+ }
+ }
+ if (jpc_putcommacode(outb, maxadjust)) {
+ return -1;
+ }
+ cblk->numlenbits += maxadjust;
+
+ lastpass = endpass - 1;
+ n = startpass->start;
+ passcount = 1;
+ for (pass = startpass; pass != endpass; ++pass) {
+ if (pass->term || pass == lastpass) {
+ datalen = pass->end - n;
+assert(jpc_firstone(datalen) < cblk->numlenbits + jpc_floorlog2(passcount));
+ if (jpc_bitstream_putbits(outb, cblk->numlenbits + jpc_floorlog2(passcount), datalen) == EOF) {
+ return -1;
+ }
+ n += datalen;
+ passcount = 1;
+ } else {
+ ++passcount;
+ }
+ }
+ }
+ }
+
+ jpc_bitstream_outalign(outb, 0);
+ jpc_bitstream_close(outb);
+
+ if (cp->tcp.csty & JPC_COD_EPH) {
+ if (!(ms = jpc_ms_create(JPC_MS_EPH))) {
+ return -1;
+ }
+ jpc_putms(out, enc->cstate, ms);
+ jpc_ms_destroy(ms);
+ }
+
+ comp = &tile->tcmpts[compno];
+ lvl = &comp->rlvls[lvlno];
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ prc = &band->prcs[prcno];
+ if (!prc->cblks) {
+ continue;
+ }
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ pass = cblk->curpass;
+
+ if (!pass) {
+ continue;
+ }
+ if (pass->lyrno != lyrno) {
+ assert(pass->lyrno < 0 || pass->lyrno > lyrno);
+ continue;
+ }
+
+ endpasses = &cblk->passes[cblk->numpasses];
+ startpass = pass;
+ endpass = startpass;
+ while (endpass != endpasses && endpass->lyrno == lyrno){
+ ++endpass;
+ }
+ lastpass = endpass - 1;
+ numnewpasses = endpass - startpass;
+
+ jas_stream_seek(cblk->stream, startpass->start, SEEK_SET);
+ assert(jas_stream_tell(cblk->stream) == startpass->start);
+ if (jas_stream_copy(out, cblk->stream, lastpass->end - startpass->start)) {
+ return -1;
+ }
+ cblk->curpass = (endpass != endpasses) ? endpass : 0;
+ cblk->numencpasses += numnewpasses;
+
+ }
+ }
+
+ return 0;
+}
+
+void jpc_save_t2state(jpc_enc_t *enc)
+{
+/* stream pos in embedded T1 stream may be wrong since not saved/restored! */
+
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_rlvl_t *endlvls;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ jpc_enc_tile_t *tile;
+ int prcno;
+ jpc_enc_prc_t *prc;
+
+ tile = enc->curtile;
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ jpc_tagtree_copy(prc->savincltree, prc->incltree);
+ jpc_tagtree_copy(prc->savnlibtree, prc->nlibtree);
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ cblk->savedcurpass = cblk->curpass;
+ cblk->savednumencpasses = cblk->numencpasses;
+ cblk->savednumlenbits = cblk->numlenbits;
+ }
+ }
+ }
+ }
+ }
+
+}
+
+void jpc_restore_t2state(jpc_enc_t *enc)
+{
+
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_rlvl_t *endlvls;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ jpc_enc_tile_t *tile;
+ int prcno;
+ jpc_enc_prc_t *prc;
+
+ tile = enc->curtile;
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ jpc_tagtree_copy(prc->incltree, prc->savincltree);
+ jpc_tagtree_copy(prc->nlibtree, prc->savnlibtree);
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ cblk->curpass = cblk->savedcurpass;
+ cblk->numencpasses = cblk->savednumencpasses;
+ cblk->numlenbits = cblk->savednumlenbits;
+ }
+ }
+ }
+ }
+ }
+}
+
+void jpc_init_t2state(jpc_enc_t *enc, int raflag)
+{
+/* It is assumed that band->numbps and cblk->numbps precomputed */
+
+ jpc_enc_tcmpt_t *comp;
+ jpc_enc_tcmpt_t *endcomps;
+ jpc_enc_rlvl_t *lvl;
+ jpc_enc_rlvl_t *endlvls;
+ jpc_enc_band_t *band;
+ jpc_enc_band_t *endbands;
+ jpc_enc_cblk_t *cblk;
+ jpc_enc_cblk_t *endcblks;
+ jpc_enc_pass_t *pass;
+ jpc_enc_pass_t *endpasses;
+ jpc_tagtreenode_t *leaf;
+ jpc_enc_tile_t *tile;
+ int prcno;
+ jpc_enc_prc_t *prc;
+
+ tile = enc->curtile;
+
+ endcomps = &tile->tcmpts[tile->numtcmpts];
+ for (comp = tile->tcmpts; comp != endcomps; ++comp) {
+ endlvls = &comp->rlvls[comp->numrlvls];
+ for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
+ if (!lvl->bands) {
+ continue;
+ }
+ endbands = &lvl->bands[lvl->numbands];
+ for (band = lvl->bands; band != endbands; ++band) {
+ if (!band->data) {
+ continue;
+ }
+ for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
+ if (!prc->cblks) {
+ continue;
+ }
+ jpc_tagtree_reset(prc->incltree);
+ jpc_tagtree_reset(prc->nlibtree);
+ endcblks = &prc->cblks[prc->numcblks];
+ for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
+ if (jas_stream_rewind(cblk->stream)) {
+ assert(0);
+ }
+ cblk->curpass = (cblk->numpasses > 0) ? cblk->passes : 0;
+ cblk->numencpasses = 0;
+ cblk->numlenbits = 3;
+ cblk->numimsbs = band->numbps - cblk->numbps;
+ assert(cblk->numimsbs >= 0);
+ leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
+ jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs);
+
+ if (raflag) {
+ endpasses = &cblk->passes[cblk->numpasses];
+ for (pass = cblk->passes; pass != endpasses; ++pass) {
+ pass->lyrno = -1;
+ pass->lyrno = 0;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
+
+jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile)
+{
+ jpc_pi_t *pi;
+ int compno;
+ jpc_picomp_t *picomp;
+ jpc_pirlvl_t *pirlvl;
+ jpc_enc_tcmpt_t *tcomp;
+ int rlvlno;
+ jpc_enc_rlvl_t *rlvl;
+ int prcno;
+ int *prclyrno;
+
+ if (!(pi = jpc_pi_create0())) {
+ return 0;
+ }
+ pi->pktno = -1;
+ pi->numcomps = cp->numcmpts;
+ if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno,
+ ++picomp) {
+ picomp->pirlvls = 0;
+ }
+
+ for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps;
+ compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
+ picomp->numrlvls = tcomp->numrlvls;
+ if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls *
+ sizeof(jpc_pirlvl_t)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
+ picomp->numrlvls; ++rlvlno, ++pirlvl) {
+ pirlvl->prclyrnos = 0;
+ }
+ for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
+ rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
+/* XXX sizeof(long) should be sizeof different type */
+ pirlvl->numprcs = rlvl->numprcs;
+ if (rlvl->numprcs) {
+ if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs *
+ sizeof(long)))) {
+ jpc_pi_destroy(pi);
+ return 0;
+ }
+ } else {
+ pirlvl->prclyrnos = 0;
+ }
+ }
+ }
+
+ pi->maxrlvls = 0;
+ for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps;
+ compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
+ picomp->hsamp = cp->ccps[compno].sampgrdstepx;
+ picomp->vsamp = cp->ccps[compno].sampgrdstepy;
+ for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
+ rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
+ pirlvl->prcwidthexpn = rlvl->prcwidthexpn;
+ pirlvl->prcheightexpn = rlvl->prcheightexpn;
+ for (prcno = 0, prclyrno = pirlvl->prclyrnos;
+ prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
+ *prclyrno = 0;
+ }
+ pirlvl->numhprcs = rlvl->numhprcs;
+ }
+ if (pi->maxrlvls < tcomp->numrlvls) {
+ pi->maxrlvls = tcomp->numrlvls;
+ }
+ }
+
+ pi->numlyrs = tile->numlyrs;
+ pi->xstart = tile->tlx;
+ pi->ystart = tile->tly;
+ pi->xend = tile->brx;
+ pi->yend = tile->bry;
+
+ pi->picomp = 0;
+ pi->pirlvl = 0;
+ pi->x = 0;
+ pi->y = 0;
+ pi->compno = 0;
+ pi->rlvlno = 0;
+ pi->prcno = 0;
+ pi->lyrno = 0;
+ pi->xstep = 0;
+ pi->ystep = 0;
+
+ pi->pchgno = -1;
+
+ pi->defaultpchg.prgord = tile->prg;
+ pi->defaultpchg.compnostart = 0;
+ pi->defaultpchg.compnoend = pi->numcomps;
+ pi->defaultpchg.rlvlnostart = 0;
+ pi->defaultpchg.rlvlnoend = pi->maxrlvls;
+ pi->defaultpchg.lyrnoend = pi->numlyrs;
+ pi->pchg = 0;
+
+ pi->valid = 0;
+
+ return pi;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_t2enc.h b/osframework/source/ImageLib/jpeg2000/jpc_t2enc.h
new file mode 100644
index 0000000..f083139
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_t2enc.h
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tier 2 Encoder
+ *
+ * $Id: jpc_t2enc.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_T2ENC_H
+#define JPC_T2ENC_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "jpc_enc.h"
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Encode the packets for a tile. */
+int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out);
+
+/* Encode the specified packet. */
+int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno,
+ int prcno, int lyrno);
+
+/* Save the tier-2 coding state. */
+void jpc_save_t2state(jpc_enc_t *enc);
+
+/* Restore the tier-2 coding state. */
+void jpc_restore_t2state(jpc_enc_t *enc);
+
+/* Initialize the tier-2 coding state. */
+void jpc_init_t2state(jpc_enc_t *enc, int raflag);
+
+/* Create a packet iterator for the encoder. */
+jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_tagtree.c b/osframework/source/ImageLib/jpeg2000/jpc_tagtree.c
new file mode 100644
index 0000000..0336701
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_tagtree.c
@@ -0,0 +1,442 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tag Tree Library
+ *
+ * $Id: jpc_tagtree.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <limits.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+
+#include "jas_malloc.h"
+
+#include "jpc_tagtree.h"
+
+/******************************************************************************\
+* Prototypes.
+\******************************************************************************/
+
+static jpc_tagtree_t *jpc_tagtree_alloc(void);
+
+/******************************************************************************\
+* Code for creating and destroying tag trees.
+\******************************************************************************/
+
+/* Create a tag tree. */
+
+jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv)
+{
+ int nplh[JPC_TAGTREE_MAXDEPTH];
+ int nplv[JPC_TAGTREE_MAXDEPTH];
+ jpc_tagtreenode_t *node;
+ jpc_tagtreenode_t *parentnode;
+ jpc_tagtreenode_t *parentnode0;
+ jpc_tagtree_t *tree;
+ int i;
+ int j;
+ int k;
+ int numlvls;
+ int n;
+
+ assert(numleafsh > 0 && numleafsv > 0);
+
+ if (!(tree = jpc_tagtree_alloc())) {
+ return 0;
+ }
+ tree->numleafsh_ = numleafsh;
+ tree->numleafsv_ = numleafsv;
+
+ numlvls = 0;
+ nplh[0] = numleafsh;
+ nplv[0] = numleafsv;
+ do {
+ n = nplh[numlvls] * nplv[numlvls];
+ nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
+ nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
+ tree->numnodes_ += n;
+ ++numlvls;
+ } while (n > 1);
+
+ if (!(tree->nodes_ = jas_malloc(tree->numnodes_ * sizeof(jpc_tagtreenode_t)))) {
+ return 0;
+ }
+
+ /* Initialize the parent links for all nodes in the tree. */
+
+ node = tree->nodes_;
+ parentnode = &tree->nodes_[tree->numleafsh_ * tree->numleafsv_];
+ parentnode0 = parentnode;
+
+ for (i = 0; i < numlvls - 1; ++i) {
+ for (j = 0; j < nplv[i]; ++j) {
+ k = nplh[i];
+ while (--k >= 0) {
+ node->parent_ = parentnode;
+ ++node;
+ if (--k >= 0) {
+ node->parent_ = parentnode;
+ ++node;
+ }
+ ++parentnode;
+ }
+ if ((j & 1) || j == nplv[i] - 1) {
+ parentnode0 = parentnode;
+ } else {
+ parentnode = parentnode0;
+ parentnode0 += nplh[i];
+ }
+ }
+ }
+ node->parent_ = 0;
+
+ /* Initialize the data values to something sane. */
+
+ jpc_tagtree_reset(tree);
+
+ return tree;
+}
+
+/* Destroy a tag tree. */
+
+void jpc_tagtree_destroy(jpc_tagtree_t *tree)
+{
+ if (tree->nodes_) {
+ jas_free(tree->nodes_);
+ }
+ jas_free(tree);
+}
+
+static jpc_tagtree_t *jpc_tagtree_alloc()
+{
+ jpc_tagtree_t *tree;
+
+ if (!(tree = jas_malloc(sizeof(jpc_tagtree_t)))) {
+ return 0;
+ }
+ tree->numleafsh_ = 0;
+ tree->numleafsv_ = 0;
+ tree->numnodes_ = 0;
+ tree->nodes_ = 0;
+
+ return tree;
+}
+
+/******************************************************************************\
+* Code.
+\******************************************************************************/
+
+/* Copy state information from one tag tree to another. */
+
+void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree)
+{
+ int n;
+ jpc_tagtreenode_t *srcnode;
+ jpc_tagtreenode_t *dstnode;
+
+ /* The two tag trees must have similar sizes. */
+ assert(srctree->numleafsh_ == dsttree->numleafsh_ &&
+ srctree->numleafsv_ == dsttree->numleafsv_);
+
+ n = srctree->numnodes_;
+ srcnode = srctree->nodes_;
+ dstnode = dsttree->nodes_;
+ while (--n >= 0) {
+ dstnode->value_ = srcnode->value_;
+ dstnode->low_ = srcnode->low_;
+ dstnode->known_ = srcnode->known_;
+ ++dstnode;
+ ++srcnode;
+ }
+}
+
+/* Reset all of the state information associated with a tag tree. */
+
+void jpc_tagtree_reset(jpc_tagtree_t *tree)
+{
+ int n;
+ jpc_tagtreenode_t *node;
+
+ n = tree->numnodes_;
+ node = tree->nodes_;
+
+ while (--n >= 0) {
+ node->value_ = INT_MAX;
+ node->low_ = 0;
+ node->known_ = 0;
+ ++node;
+ }
+}
+
+/* Set the value associated with the specified leaf node, updating
+the other nodes as necessary. */
+
+void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int value)
+{
+ jpc_tagtreenode_t *node;
+
+ /* Avoid compiler warnings about unused parameters. */
+ tree = 0;
+
+ assert(value >= 0);
+
+ node = leaf;
+ while (node && node->value_ > value) {
+ node->value_ = value;
+ node = node->parent_;
+ }
+}
+
+/* Get a particular leaf node. */
+
+jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n)
+{
+ return &tree->nodes_[n];
+}
+
+/* Invoke the tag tree encoding procedure. */
+
+int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int threshold, jpc_bitstream_t *out)
+{
+ jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1];
+ jpc_tagtreenode_t **stkptr;
+ jpc_tagtreenode_t *node;
+ int low;
+
+ /* Avoid compiler warnings about unused parameters. */
+ tree = 0;
+
+ assert(leaf);
+ assert(threshold >= 0);
+
+ /* Traverse to the root of the tree, recording the path taken. */
+ stkptr = stk;
+ node = leaf;
+ while (node->parent_) {
+ *stkptr++ = node;
+ node = node->parent_;
+ }
+
+ low = 0;
+ for (;;) {
+ if (low > node->low_) {
+ /* Deferred propagation of the lower bound downward in
+ the tree. */
+ node->low_ = low;
+ } else {
+ low = node->low_;
+ }
+
+ while (low < threshold) {
+ if (low >= node->value_) {
+ if (!node->known_) {
+ if (jpc_bitstream_putbit(out, 1) == EOF) {
+ return -1;
+ }
+ node->known_ = 1;
+ }
+ break;
+ }
+ if (jpc_bitstream_putbit(out, 0) == EOF) {
+ return -1;
+ }
+ ++low;
+ }
+ node->low_ = low;
+ if (stkptr == stk) {
+ break;
+ }
+ node = *--stkptr;
+
+ }
+ return (leaf->low_ < threshold) ? 1 : 0;
+
+}
+
+/* Invoke the tag tree decoding procedure. */
+
+int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int threshold, jpc_bitstream_t *in)
+{
+ jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1];
+ jpc_tagtreenode_t **stkptr;
+ jpc_tagtreenode_t *node;
+ int low;
+ int ret;
+
+ /* Avoid compiler warnings about unused parameters. */
+ tree = 0;
+
+ assert(threshold >= 0);
+
+ /* Traverse to the root of the tree, recording the path taken. */
+ stkptr = stk;
+ node = leaf;
+ while (node->parent_) {
+ *stkptr++ = node;
+ node = node->parent_;
+ }
+
+ low = 0;
+ for (;;) {
+ if (low > node->low_) {
+ node->low_ = low;
+ } else {
+ low = node->low_;
+ }
+ while (low < threshold && low < node->value_) {
+ if ((ret = jpc_bitstream_getbit(in)) < 0) {
+ return -1;
+ }
+ if (ret) {
+ node->value_ = low;
+ } else {
+ ++low;
+ }
+ }
+ node->low_ = low;
+ if (stkptr == stk) {
+ break;
+ }
+ node = *--stkptr;
+ }
+
+ return (node->value_ < threshold) ? 1 : 0;
+}
+
+/******************************************************************************\
+* Code for debugging.
+\******************************************************************************/
+
+void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out)
+{
+ jpc_tagtreenode_t *node;
+ int n;
+
+ node = tree->nodes_;
+ n = tree->numnodes_;
+ while (--n >= 0) {
+ fprintf(out, "node %p, parent %p, value %d, lower %d, known %d\n",
+ (void *) node, (void *) node->parent_, node->value_, node->low_,
+ node->known_);
+ ++node;
+ }
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_tagtree.h b/osframework/source/ImageLib/jpeg2000/jpc_tagtree.h
new file mode 100644
index 0000000..c589d03
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_tagtree.h
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tag Tree Library
+ *
+ * $Id: jpc_tagtree.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_TAGTREE_H
+#define JPC_TAGTREE_H
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include <limits.h>
+#include <stdio.h>
+
+#include "jpc_bs.h"
+
+/******************************************************************************\
+* Constants
+\******************************************************************************/
+
+/* The maximum allowable depth for a tag tree. */
+#define JPC_TAGTREE_MAXDEPTH 32
+
+/******************************************************************************\
+* Types
+\******************************************************************************/
+
+/*
+ * Tag tree node.
+ */
+
+typedef struct jpc_tagtreenode_ {
+
+ /* The parent of this node. */
+ struct jpc_tagtreenode_ *parent_;
+
+ /* The value associated with this node. */
+ int value_;
+
+ /* The lower bound on the value associated with this node. */
+ int low_;
+
+ /* A flag indicating if the value is known exactly. */
+ int known_;
+
+} jpc_tagtreenode_t;
+
+/*
+ * Tag tree.
+ */
+
+typedef struct {
+
+ /* The number of leaves in the horizontal direction. */
+ int numleafsh_;
+
+ /* The number of leaves in the vertical direction. */
+ int numleafsv_;
+
+ /* The total number of nodes in the tree. */
+ int numnodes_;
+
+ /* The nodes. */
+ jpc_tagtreenode_t *nodes_;
+
+} jpc_tagtree_t;
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Create a tag tree. */
+jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv);
+
+/* Destroy a tag tree. */
+void jpc_tagtree_destroy(jpc_tagtree_t *tree);
+
+/* Copy data from one tag tree to another. */
+void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree);
+
+/* Reset the tag tree state. */
+void jpc_tagtree_reset(jpc_tagtree_t *tree);
+
+/* Set the value associated with a particular leaf node of a tag tree. */
+void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int value);
+
+/* Get a pointer to a particular leaf node. */
+jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n);
+
+/* Invoke the tag tree decoding procedure. */
+int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int threshold, jpc_bitstream_t *in);
+
+/* Invoke the tag tree encoding procedure. */
+int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
+ int threshold, jpc_bitstream_t *out);
+
+/* Dump a tag tree (for debugging purposes). */
+void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_tsfb.c b/osframework/source/ImageLib/jpeg2000/jpc_tsfb.c
new file mode 100644
index 0000000..3a1a987
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_tsfb.c
@@ -0,0 +1,663 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tree-Structured Filter Bank (TSFB) Library
+ *
+ * $Id: jpc_tsfb.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include <assert.h>
+
+#include "jas_malloc.h"
+#include "jas_seq.h"
+
+#include "jpc_tsfb.h"
+#include "jpc_cod.h"
+#include "jpc_cs.h"
+#include "jpc_util.h"
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+#define bandnotovind(tsfbnode, x) ((x) / (tsfbnode)->numhchans)
+#define bandnotohind(tsfbnode, x) ((x) % (tsfbnode)->numhchans)
+
+static jpc_tsfb_t *jpc_tsfb_create(void);
+static jpc_tsfbnode_t *jpc_tsfbnode_create(void);
+static void jpc_tsfbnode_destroy(jpc_tsfbnode_t *node);
+static void jpc_tsfbnode_synthesize(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x);
+static void jpc_tsfbnode_analyze(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x);
+static void qmfb2d_getbands(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb,
+ uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend,
+ uint_fast32_t yend, int maxbands, int *numbandsptr, jpc_tsfbnodeband_t *bands);
+static void jpc_tsfbnode_getbandstree(jpc_tsfbnode_t *node, uint_fast32_t posxstart,
+ uint_fast32_t posystart, uint_fast32_t xstart, uint_fast32_t ystart,
+ uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t **bands);
+static int jpc_tsfbnode_findchild(jpc_tsfbnode_t *parnode, jpc_tsfbnode_t *cldnode);
+static int jpc_tsfbnode_getequivfilters(jpc_tsfbnode_t *tsfbnode, int cldind,
+ int width, int height, jas_seq_t **vfilter, jas_seq_t **hfilter);
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+jpc_tsfb_t *jpc_tsfb_wavelet(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, int numdlvls)
+{
+ jpc_tsfb_t *tsfb;
+ int dlvlno;
+ jpc_tsfbnode_t *curnode;
+ jpc_tsfbnode_t *prevnode;
+ int childno;
+ if (!(tsfb = jpc_tsfb_create())) {
+ return 0;
+ }
+ prevnode = 0;
+ for (dlvlno = 0; dlvlno < numdlvls; ++dlvlno) {
+ if (!(curnode = jpc_tsfbnode_create())) {
+ jpc_tsfb_destroy(tsfb);
+ return 0;
+ }
+ if (prevnode) {
+ prevnode->children[0] = curnode;
+ ++prevnode->numchildren;
+ curnode->parent = prevnode;
+ } else {
+ tsfb->root = curnode;
+ curnode->parent = 0;
+ }
+ if (hqmfb) {
+ curnode->numhchans = jpc_qmfb1d_getnumchans(hqmfb);
+ if (!(curnode->hqmfb = jpc_qmfb1d_copy(hqmfb))) {
+ jpc_tsfb_destroy(tsfb);
+ return 0;
+ }
+ } else {
+ curnode->hqmfb = 0;
+ curnode->numhchans = 1;
+ }
+ if (vqmfb) {
+ curnode->numvchans = jpc_qmfb1d_getnumchans(vqmfb);
+ if (!(curnode->vqmfb = jpc_qmfb1d_copy(vqmfb))) {
+ jpc_tsfb_destroy(tsfb);
+ return 0;
+ }
+ } else {
+ curnode->vqmfb = 0;
+ curnode->numvchans = 1;
+ }
+ curnode->maxchildren = curnode->numhchans * curnode->numvchans;
+ for (childno = 0; childno < curnode->maxchildren;
+ ++childno) {
+ curnode->children[childno] = 0;
+ }
+ prevnode = curnode;
+ }
+ return tsfb;
+}
+
+static jpc_tsfb_t *jpc_tsfb_create()
+{
+ jpc_tsfb_t *tsfb;
+ if (!(tsfb = jas_malloc(sizeof(jpc_tsfb_t)))) {
+ return 0;
+ }
+ tsfb->root = 0;
+ return tsfb;
+}
+
+void jpc_tsfb_destroy(jpc_tsfb_t *tsfb)
+{
+ if (tsfb->root) {
+ jpc_tsfbnode_destroy(tsfb->root);
+ }
+ jas_free(tsfb);
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+void jpc_tsfb_analyze(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x)
+{
+ if (tsfb->root) {
+ jpc_tsfbnode_analyze(tsfb->root, flags, x);
+ }
+}
+
+static void jpc_tsfbnode_analyze(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x)
+{
+ jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE];
+ int numbands;
+ jas_seq2d_t *y;
+ int bandno;
+ jpc_tsfbnodeband_t *band;
+
+ if (node->vqmfb) {
+ jpc_qmfb1d_analyze(node->vqmfb, flags | JPC_QMFB1D_VERT, x);
+ }
+ if (node->hqmfb) {
+ jpc_qmfb1d_analyze(node->hqmfb, flags, x);
+ }
+ if (node->numchildren > 0) {
+ qmfb2d_getbands(node->hqmfb, node->vqmfb, jas_seq2d_xstart(x),
+ jas_seq2d_ystart(x), jas_seq2d_xend(x), jas_seq2d_yend(x),
+ JPC_TSFB_MAXBANDSPERNODE, &numbands, nodebands);
+ y = jas_seq2d_create(0, 0, 0, 0);
+ assert(y);
+ for (bandno = 0, band = nodebands; bandno < numbands; ++bandno, ++band) {
+ if (node->children[bandno]) {
+ if (band->xstart != band->xend && band->ystart != band->yend) {
+ jas_seq2d_bindsub(y, x, band->locxstart, band->locystart,
+ band->locxend, band->locyend);
+ jas_seq2d_setshift(y, band->xstart, band->ystart);
+ jpc_tsfbnode_analyze(node->children[bandno], flags, y);
+ }
+ }
+ }
+ jas_matrix_destroy(y);
+ }
+}
+
+void jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x)
+{
+ if (tsfb->root) {
+ jpc_tsfbnode_synthesize(tsfb->root, flags, x);
+ }
+}
+
+static void jpc_tsfbnode_synthesize(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x)
+{
+ jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE];
+ int numbands;
+ jas_seq2d_t *y;
+ int bandno;
+ jpc_tsfbnodeband_t *band;
+
+ if (node->numchildren > 0) {
+ qmfb2d_getbands(node->hqmfb, node->vqmfb, jas_seq2d_xstart(x),
+ jas_seq2d_ystart(x), jas_seq2d_xend(x), jas_seq2d_yend(x),
+ JPC_TSFB_MAXBANDSPERNODE, &numbands, nodebands);
+ y = jas_seq2d_create(0, 0, 0, 0);
+ for (bandno = 0, band = nodebands; bandno < numbands; ++bandno, ++band) {
+ if (node->children[bandno]) {
+ if (band->xstart != band->xend && band->ystart != band->yend) {
+ jas_seq2d_bindsub(y, x, band->locxstart, band->locystart,
+ band->locxend, band->locyend);
+ jas_seq2d_setshift(y, band->xstart, band->ystart);
+ jpc_tsfbnode_synthesize(node->children[bandno], flags, y);
+ }
+ }
+ }
+ jas_seq2d_destroy(y);
+ }
+ if (node->hqmfb) {
+ jpc_qmfb1d_synthesize(node->hqmfb, flags, x);
+ }
+ if (node->vqmfb) {
+ jpc_qmfb1d_synthesize(node->vqmfb, flags | JPC_QMFB1D_VERT, x);
+ }
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+
+int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart, uint_fast32_t ystart,
+ uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t *bands)
+{
+ jpc_tsfb_band_t *savbands;
+ savbands = bands;
+ if (!tsfb->root) {
+ bands[0].xstart = xstart;
+ bands[0].ystart = ystart;
+ bands[0].xend = xend;
+ bands[0].yend = yend;
+ bands[0].locxstart = xstart;
+ bands[0].locystart = ystart;
+ bands[0].locxend = xend;
+ bands[0].locyend = yend;
+ bands[0].orient = JPC_TSFB_LL;
+ bands[0].synenergywt = JPC_FIX_ONE;
+ ++bands;
+ } else {
+ jpc_tsfbnode_getbandstree(tsfb->root, xstart, ystart,
+ xstart, ystart, xend, yend, &bands);
+ }
+ return bands - savbands;
+}
+
+static void jpc_tsfbnode_getbandstree(jpc_tsfbnode_t *node, uint_fast32_t posxstart,
+ uint_fast32_t posystart, uint_fast32_t xstart, uint_fast32_t ystart,
+ uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t **bands)
+{
+ jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE];
+ jpc_tsfbnodeband_t *nodeband;
+ int nodebandno;
+ int numnodebands;
+ jpc_tsfb_band_t *band;
+ jas_seq_t *hfilter;
+ jas_seq_t *vfilter;
+
+ qmfb2d_getbands(node->hqmfb, node->vqmfb, xstart, ystart, xend, yend,
+ JPC_TSFB_MAXBANDSPERNODE, &numnodebands, nodebands);
+ if (node->numchildren > 0) {
+ for (nodebandno = 0, nodeband = nodebands;
+ nodebandno < numnodebands; ++nodebandno, ++nodeband) {
+ if (node->children[nodebandno]) {
+ jpc_tsfbnode_getbandstree(node->children[
+ nodebandno], posxstart +
+ nodeband->locxstart - xstart, posystart +
+ nodeband->locystart - ystart, nodeband->xstart,
+ nodeband->ystart, nodeband->xend,
+ nodeband->yend, bands);
+
+ }
+ }
+ }
+assert(numnodebands == 4 || numnodebands == 3);
+ for (nodebandno = 0, nodeband = nodebands; nodebandno < numnodebands;
+ ++nodebandno, ++nodeband) {
+ if (!node->children[nodebandno]) {
+ band = *bands;
+ band->xstart = nodeband->xstart;
+ band->ystart = nodeband->ystart;
+ band->xend = nodeband->xend;
+ band->yend = nodeband->yend;
+ band->locxstart = posxstart + nodeband->locxstart -
+ xstart;
+ band->locystart = posystart + nodeband->locystart -
+ ystart;
+ band->locxend = band->locxstart + band->xend -
+ band->xstart;
+ band->locyend = band->locystart + band->yend -
+ band->ystart;
+ if (numnodebands == 4) {
+ switch (nodebandno) {
+ case 0:
+ band->orient = JPC_TSFB_LL;
+ break;
+ case 1:
+ band->orient = JPC_TSFB_HL;
+ break;
+ case 2:
+ band->orient = JPC_TSFB_LH;
+ break;
+ case 3:
+ band->orient = JPC_TSFB_HH;
+ break;
+ default:
+ abort();
+ break;
+ }
+ } else {
+ switch (nodebandno) {
+ case 0:
+ band->orient = JPC_TSFB_HL;
+ break;
+ case 1:
+ band->orient = JPC_TSFB_LH;
+ break;
+ case 2:
+ band->orient = JPC_TSFB_HH;
+ break;
+ default:
+ abort();
+ break;
+ }
+ }
+ jpc_tsfbnode_getequivfilters(node, nodebandno, band->xend - band->xstart, band->yend - band->ystart, &hfilter, &vfilter);
+ band->synenergywt = jpc_fix_mul(jpc_seq_norm(hfilter),
+ jpc_seq_norm(vfilter));
+ jas_seq_destroy(hfilter);
+ jas_seq_destroy(vfilter);
+ ++(*bands);
+ }
+ }
+}
+
+/******************************************************************************\
+*
+\******************************************************************************/
+
+static jpc_tsfbnode_t *jpc_tsfbnode_create()
+{
+ jpc_tsfbnode_t *node;
+ if (!(node = jas_malloc(sizeof(jpc_tsfbnode_t)))) {
+ return 0;
+ }
+ node->numhchans = 0;
+ node->numvchans = 0;
+ node->numchildren = 0;
+ node->maxchildren = 0;
+ node->hqmfb = 0;
+ node->vqmfb = 0;
+ node->parent = 0;
+ return node;
+}
+
+static void jpc_tsfbnode_destroy(jpc_tsfbnode_t *node)
+{
+ jpc_tsfbnode_t **child;
+ int childno;
+ for (childno = 0, child = node->children; childno < node->maxchildren;
+ ++childno, ++child) {
+ if (*child) {
+ jpc_tsfbnode_destroy(*child);
+ }
+ }
+ if (node->hqmfb) {
+ jpc_qmfb1d_destroy(node->hqmfb);
+ }
+ if (node->vqmfb) {
+ jpc_qmfb1d_destroy(node->vqmfb);
+ }
+ jas_free(node);
+}
+
+
+
+
+
+
+
+
+static void qmfb2d_getbands(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb,
+ uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend,
+ uint_fast32_t yend, int maxbands, int *numbandsptr, jpc_tsfbnodeband_t *bands)
+{
+ jpc_qmfb1dband_t hbands[JPC_QMFB1D_MAXCHANS];
+ jpc_qmfb1dband_t vbands[JPC_QMFB1D_MAXCHANS];
+ int numhbands;
+ int numvbands;
+ int numbands;
+ int bandno;
+ int hbandno;
+ int vbandno;
+ jpc_tsfbnodeband_t *band;
+
+ if (hqmfb) {
+ jpc_qmfb1d_getbands(hqmfb, 0, xstart, ystart, xend, yend,
+ JPC_QMFB1D_MAXCHANS, &numhbands, hbands);
+ } else {
+ numhbands = 1;
+ hbands[0].start = xstart;
+ hbands[0].end = xend;
+ hbands[0].locstart = xstart;
+ hbands[0].locend = xend;
+ }
+ if (vqmfb) {
+ jpc_qmfb1d_getbands(vqmfb, JPC_QMFB1D_VERT, xstart, ystart, xend,
+ yend, JPC_QMFB1D_MAXCHANS, &numvbands, vbands);
+ } else {
+ numvbands = 1;
+ vbands[0].start = ystart;
+ vbands[0].end = yend;
+ vbands[0].locstart = ystart;
+ vbands[0].locend = yend;
+ }
+ numbands = numhbands * numvbands;
+ assert(numbands <= maxbands);
+ *numbandsptr = numbands;
+ for (bandno = 0, band = bands; bandno < numbands; ++bandno, ++band) {
+ hbandno = bandno % numhbands;
+ vbandno = bandno / numhbands;
+ band->xstart = hbands[hbandno].start;
+ band->ystart = vbands[vbandno].start;
+ band->xend = hbands[hbandno].end;
+ band->yend = vbands[vbandno].end;
+ band->locxstart = hbands[hbandno].locstart;
+ band->locystart = vbands[vbandno].locstart;
+ band->locxend = hbands[hbandno].locend;
+ band->locyend = vbands[vbandno].locend;
+ assert(band->xstart <= band->xend &&
+ band->ystart <= band->yend);
+ if (band->xstart == band->xend) {
+ band->yend = band->ystart;
+ band->locyend = band->locystart;
+ } else if (band->ystart == band->yend) {
+ band->xend = band->xstart;
+ band->locxend = band->locxstart;
+ }
+ }
+}
+
+static int jpc_tsfbnode_getequivfilters(jpc_tsfbnode_t *tsfbnode, int cldind,
+ int width, int height, jas_seq_t **hfilter, jas_seq_t **vfilter)
+{
+ jas_seq_t *hseq;
+ jas_seq_t *vseq;
+ jpc_tsfbnode_t *node;
+ jas_seq2d_t *hfilters[JPC_QMFB1D_MAXCHANS];
+ jas_seq2d_t *vfilters[JPC_QMFB1D_MAXCHANS];
+ int numhchans;
+ int numvchans;
+ jas_seq_t *tmpseq;
+
+ hseq = 0;
+ vseq = 0;
+
+ if (!(hseq = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(hseq, 0, jpc_inttofix(1));
+ if (!(vseq = jas_seq_create(0, 1))) {
+ goto error;
+ }
+ jas_seq_set(vseq, 0, jpc_inttofix(1));
+
+ node = tsfbnode;
+ while (node) {
+ if (node->hqmfb) {
+ numhchans = jpc_qmfb1d_getnumchans(node->hqmfb);
+ if (jpc_qmfb1d_getsynfilters(node->hqmfb, width, hfilters)) {
+ goto error;
+ }
+ if (!(tmpseq = jpc_seq_upsample(hseq, numhchans))) {
+ goto error;
+ }
+ jas_seq_destroy(hseq);
+ hseq = tmpseq;
+ if (!(tmpseq = jpc_seq_conv(hseq, hfilters[bandnotohind(node, cldind)]))) {
+ goto error;
+ }
+ jas_seq_destroy(hfilters[0]);
+ jas_seq_destroy(hfilters[1]);
+ jas_seq_destroy(hseq);
+ hseq = tmpseq;
+ }
+ if (node->vqmfb) {
+ numvchans = jpc_qmfb1d_getnumchans(node->vqmfb);
+ if (jpc_qmfb1d_getsynfilters(node->vqmfb, height, vfilters)) {
+ abort();
+ }
+ if (!(tmpseq = jpc_seq_upsample(vseq, numvchans))) {
+ goto error;
+ }
+ jas_seq_destroy(vseq);
+ vseq = tmpseq;
+ if (!(tmpseq = jpc_seq_conv(vseq, vfilters[bandnotovind(node, cldind)]))) {
+ goto error;
+ }
+ jas_seq_destroy(vfilters[0]);
+ jas_seq_destroy(vfilters[1]);
+ jas_seq_destroy(vseq);
+ vseq = tmpseq;
+ }
+ if (node->parent) {
+ cldind = jpc_tsfbnode_findchild(node->parent, node);
+ }
+ node = node->parent;
+ }
+
+ *hfilter = hseq;
+ *vfilter = vseq;
+
+ return 0;
+
+error:
+ if (hseq) {
+ jas_seq_destroy(hseq);
+ }
+ if (vseq) {
+ jas_seq_destroy(vseq);
+ }
+ return -1;
+
+}
+
+static int jpc_tsfbnode_findchild(jpc_tsfbnode_t *parnode, jpc_tsfbnode_t *cldnode)
+{
+ int i;
+
+ for (i = 0; i < parnode->maxchildren; i++) {
+ if (parnode->children[i] == cldnode)
+ return i;
+ }
+ assert(0);
+ return -1;
+}
+
+jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels)
+{
+ jpc_tsfb_t *tsfb;
+
+ switch (qmfbid) {
+ case JPC_COX_RFT:
+ qmfbid = JPC_QMFB1D_FT;
+ break;
+ case JPC_COX_INS:
+ qmfbid = JPC_QMFB1D_NS;
+ break;
+ default:
+ assert(0);
+ qmfbid = 10;
+ break;
+ }
+
+{
+ jpc_qmfb1d_t *hqmfb;
+ hqmfb = jpc_qmfb1d_make(qmfbid);
+ assert(hqmfb);
+ tsfb = jpc_tsfb_wavelet(hqmfb, hqmfb, numlevels);
+ assert(tsfb);
+ jpc_qmfb1d_destroy(hqmfb);
+}
+
+ return tsfb;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_tsfb.h b/osframework/source/ImageLib/jpeg2000/jpc_tsfb.h
new file mode 100644
index 0000000..ea3ef98
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_tsfb.h
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * Tree-Structured Filter Bank (TSFB) Library
+ *
+ * $Id: jpc_tsfb.h,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+#ifndef JPC_TSFB_H
+#define JPC_TSFB_H
+
+/******************************************************************************\
+* Includes.
+\******************************************************************************/
+
+#include "jas_seq.h"
+
+#include "jpc_fix.h"
+#include "jpc_qmfb.h"
+
+/******************************************************************************\
+* Constants.
+\******************************************************************************/
+
+#define JPC_TSFB_MAXBANDS (JPC_TSFB_MAXDEPTH * 3 + 1)
+#define JPC_TSFB_MAXDEPTH 32
+#define JPC_TSFB_RITIMODE JPC_QMFB1D_RITIMODE
+
+#define JPC_TSFB_MAXBANDSPERNODE (JPC_QMFB1D_MAXCHANS * JPC_QMFB1D_MAXCHANS)
+
+#define JPC_TSFB_PRUNEVERT 0x01
+#define JPC_TSFB_PRUNEHORZ 0x02
+
+#define JPC_TSFB_LL 0
+#define JPC_TSFB_LH 1
+#define JPC_TSFB_HL 2
+#define JPC_TSFB_HH 3
+
+/******************************************************************************\
+* Types.
+\******************************************************************************/
+
+typedef struct {
+
+ int xstart;
+ int ystart;
+ int xend;
+ int yend;
+ int locxstart;
+ int locystart;
+ int locxend;
+ int locyend;
+
+} jpc_tsfbnodeband_t;
+
+typedef struct jpc_tsfbnode_s {
+
+ int numhchans;
+ int numvchans;
+ jpc_qmfb1d_t *hqmfb;
+ jpc_qmfb1d_t *vqmfb;
+ int maxchildren;
+ int numchildren;
+ struct jpc_tsfbnode_s *children[JPC_TSFB_MAXBANDSPERNODE];
+ struct jpc_tsfbnode_s *parent;
+
+} jpc_tsfbnode_t;
+
+typedef struct {
+ jpc_tsfbnode_t *root;
+} jpc_tsfb_t;
+
+typedef struct {
+ int xstart;
+ int ystart;
+ int xend;
+ int yend;
+ int orient;
+ int locxstart;
+ int locystart;
+ int locxend;
+ int locyend;
+ jpc_fix_t synenergywt;
+} jpc_tsfb_band_t;
+
+/******************************************************************************\
+* Functions.
+\******************************************************************************/
+
+/* Create a TSFB. */
+jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels);
+
+/* Create a wavelet-type TSFB with the specified horizontal and vertical
+ QMFBs. */
+jpc_tsfb_t *jpc_tsfb_wavelet(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb,
+ int numdlvls);
+
+/* Destroy a TSFB. */
+void jpc_tsfb_destroy(jpc_tsfb_t *tsfb);
+
+/* Perform analysis. */
+void jpc_tsfb_analyze(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x);
+
+/* Perform synthesis. */
+void jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x);
+
+/* Get band information for a TSFB. */
+int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart,
+ uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend,
+ jpc_tsfb_band_t *bands);
+
+#endif
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_util.c b/osframework/source/ImageLib/jpeg2000/jpc_util.c
new file mode 100644
index 0000000..3e71ebf
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_util.c
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 1999-2000 Image Power, Inc. and the University of
+ * British Columbia.
+ * Copyright (c) 2001-2003 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+/*
+ * $Id: jpc_util.c,v 1.1 2003/05/15 01:30:32 ace Exp $
+ */
+
+/******************************************************************************\
+* Includes
+\******************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "jas_math.h"
+#include "jas_malloc.h"
+
+#include "jpc_fix.h"
+#include "jpc_cs.h"
+#include "jpc_flt.h"
+#include "jpc_util.h"
+
+/******************************************************************************\
+* Miscellaneous Functions
+\******************************************************************************/
+
+int jpc_atoaf(char *s, int *numvalues, double **values)
+{
+ static char delim[] = ", \t\n";
+ char buf[4096];
+ int n;
+ double *vs;
+ char *cp;
+
+ strncpy(buf, s, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ n = 0;
+ if ((cp = strtok(buf, delim))) {
+ ++n;
+ while ((cp = strtok(0, delim))) {
+ if (cp != '\0') {
+ ++n;
+ }
+ }
+ }
+
+ if (n) {
+ if (!(vs = jas_malloc(n * sizeof(double)))) {
+ return -1;
+ }
+
+ strncpy(buf, s, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ n = 0;
+ if ((cp = strtok(buf, delim))) {
+ vs[n] = atof(cp);
+ ++n;
+ while ((cp = strtok(0, delim))) {
+ if (cp != '\0') {
+ vs[n] = atof(cp);
+ ++n;
+ }
+ }
+ }
+ } else {
+ vs = 0;
+ }
+
+ *numvalues = n;
+ *values = vs;
+
+ return 0;
+}
+
+jas_seq_t *jpc_seq_upsample(jas_seq_t *x, int m)
+{
+ jas_seq_t *z;
+ int i;
+
+ if (!(z = jas_seq_create(jas_seq_start(x) * m, (jas_seq_end(x) - 1) * m + 1)))
+ return 0;
+ for (i = jas_seq_start(z); i < jas_seq_end(z); i++) {
+ *jas_seq_getref(z, i) = (!JAS_MOD(i, m)) ? jas_seq_get(x, i / m) :
+ jpc_inttofix(0);
+ }
+
+ return z;
+}
+
+jpc_fix_t jpc_seq_norm(jas_seq_t *x)
+{
+ jpc_fix_t s;
+ int i;
+
+ s = jpc_inttofix(0);
+ for (i = jas_seq_start(x); i < jas_seq_end(x); i++) {
+ s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(x, i), jas_seq_get(x, i)));
+ }
+
+ return jpc_dbltofix(sqrt(jpc_fixtodbl(s)));
+}
+
+jas_seq_t *jpc_seq_conv(jas_seq_t *x, jas_seq_t *y)
+{
+ int i;
+ int j;
+ int k;
+ jas_seq_t *z;
+ jpc_fix_t s;
+ jpc_fix_t v;
+
+ z = jas_seq_create(jas_seq_start(x) + jas_seq_start(y),
+ jas_seq_end(x) + jas_seq_end(y) - 1);
+ assert(z);
+ for (i = jas_seq_start(z); i < jas_seq_end(z); i++) {
+ s = jpc_inttofix(0);
+ for (j = jas_seq_start(y); j < jas_seq_end(y); j++) {
+ k = i - j;
+ if (k < jas_seq_start(x) || k >= jas_seq_end(x)) {
+ v = JPC_FIX_ZERO;
+ } else {
+ v = jas_seq_get(x, k);
+ }
+ s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(y, j), v));
+ }
+ *jas_seq_getref(z, i) = s;
+ }
+
+ return z;
+}
diff --git a/osframework/source/ImageLib/jpeg2000/jpc_util.h b/osframework/source/ImageLib/jpeg2000/jpc_util.h
new file mode 100644
index 0000000..78b0a2e
--- /dev/null
+++ b/osframework/source/ImageLib/jpeg2000/jpc_util.h
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2001-2002 Michael David Adams.
+ * All rights reserved.
+ */
+
+/* __START_OF_JASPER_LICENSE__
+ *
+ * JasPer Software License
+ *
+ * IMAGE POWER JPEG-2000 PUBLIC LICENSE
+ * ************************************
+ *
+ * GRANT:
+ *
+ * Permission is hereby granted, free of charge, to any person (the "User")
+ * obtaining a copy of this software and associated documentation, to deal
+ * in the JasPer Software without restriction, including without limitation
+ * the right to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the JasPer Software (in source and binary forms),
+ * and to permit persons to whom the JasPer Software is furnished to do so,
+ * provided further that the License Conditions below are met.
+ *
+ * License Conditions
+ * ******************
+ *
+ * A. Redistributions of source code must retain the above copyright notice,
+ * and this list of conditions, and the following disclaimer.
+ *
+ * B. Redistributions in binary form must reproduce the above copyright
+ * notice, and this list of conditions, and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ *
+ * C. Neither the name of Image Power, Inc. nor any other contributor
+ * (including, but not limited to, the University of British Columbia and
+ * Michael David Adams) may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * D. User agrees that it shall not commence any action against Image Power,
+ * Inc., the University of British Columbia, Michael David Adams, or any
+ * other contributors (collectively "Licensors") for infringement of any
+ * intellectual property rights ("IPR") held by the User in respect of any
+ * technology that User owns or has a right to license or sublicense and
+ * which is an element required in order to claim compliance with ISO/IEC
+ * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
+ * rights worldwide arising under statutory or common law, and whether
+ * or not perfected, including, without limitation, all (i) patents and
+ * patent applications owned or licensable by User; (ii) rights associated
+ * with works of authorship including copyrights, copyright applications,
+ * copyright registrations, mask work rights, mask work applications,
+ * mask work registrations; (iii) rights relating to the protection of
+ * trade secrets and confidential information; (iv) any right analogous
+ * to those set forth in subsections (i), (ii), or (iii) and any other
+ * proprietary rights relating to intangible property (other than trademark,
+ * trade dress, or service mark rights); and (v) divisions, continuations,
+ * renewals, reissues and extensions of the foregoing (as and to the extent
+ * applicable) now existing, hereafter filed, issued or acquired.
+ *
+ * E. If User commences an infringement action against any Licensor(s) then
+ * such Licensor(s) shall have the right to terminate User's license and
+ * all sublicenses that have been granted hereunder by User to other parties.
+ *
+ * F. This software is for use only in hardware or software products that
+ * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
+ * or right to this Software is granted for products that do not comply
+ * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
+ * from the ISO.
+ *
+ * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
+ * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+ * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
+ * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
+ * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
+ * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
+ * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
+ * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
+ * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
+ * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
+ * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
+ * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
+ * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
+ * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
+ * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
+ * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
+ * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
+ * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
+ * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
+ * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
+ * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
+ * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
+ * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
+ * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
+ * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
+ * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
+ * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
+ * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
+ * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
+ * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
+ * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
+ * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
+ * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
+ * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
+ * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
+ * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
+ * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
+ * NOTICE SPECIFIED IN THIS SECTION.
+ *
+ * __END_OF_JASPER_LICENSE__
+ */
+
+#ifndef JPC_UTIL_H
+#define JPC_UTIL_H
+
+/* Parse a comma separated list of real numbers into an array of doubles. */
+int jpc_atoaf(char *s, int *numvalues, double **values);
+
+/* Upsample a sequence. */
+jas_seq_t *jpc_seq_upsample(jas_seq_t *seq, int n);
+
+/* Convolve two sequences. */
+jas_seq_t *jpc_seq_conv(jas_seq_t *seq0, jas_seq_t *seq1);
+
+/* Compute the norm of a sequence. */
+jpc_fix_t jpc_seq_norm(jas_seq_t *x);
+
+#endif
diff --git a/osframework/source/ImageLib/png/announce b/osframework/source/ImageLib/png/announce
new file mode 100644
index 0000000..e122454
--- /dev/null
+++ b/osframework/source/ImageLib/png/announce
@@ -0,0 +1,72 @@
+
+Libpng 1.0.5 - October 15, 1999
+
+This is a public release of libpng, intended for use in production codes.
+
+Changes since the last public release (1.0.3):
+
+ Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
+ if an attempt is made to read an interlaced image when it's not supported.
+ Added check if png_ptr->trans is defined before free'ing it in pngread.c
+ Modified the Y2K statement to include versions back to version 0.71
+ Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c
+ Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments)
+ Replaced leading blanks with tab characters in makefile.hux
+ Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
+ Changed (float)red and (float)green to (double)red, (double)green
+ in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
+ Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
+ Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
+ Updated documentation to refer to the PNG-1.2 specification.
+ Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c
+ in makefile.knr, INSTALL, and README (L. Peter Deutsch)
+ Fixed bugs in calculation of the length of rowbytes when adding alpha
+ channels to 16-bit images, in pngrtran.c (Chris Nokleberg)
+ Added function png_set_user_transform_info() to store user_transform_ptr,
+ user_depth, and user_channels into the png_struct, and a function
+ png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)
+ Added function png_set_empty_plte_permitted() to make libpng useable
+ in MNG applications.
+ Corrected the typedef for png_free_ptr in png.h (Jesse Jones).
+ Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c and
+ pngset.c, to be consistent with PNG-1.2, and allow variance of 500
+ before complaining.
+ Added assembler code contributed by Intel in file pngvcrd.c and modified
+ makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant)
+ Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
+ Added makefile.beo for BEOS on X86, contributed by Sander Stok.
+ Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
+ Changed leading blanks to tabs in all makefiles.
+ Made alternate versions of png_set_expand() in pngrtran.c, namely
+ png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha
+ (Greg Roelofs, in "PNG: The Definitive Guide").
+ Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h
+ Revised calculation of num_blocks in pngmem.c to avoid a potentially
+ negative shift distance, whose results are undefined in the C language.
+ Added a check in pngset.c to prevent writing multiple tIME chunks.
+ Added a check in pngwrite.c to detect invalid small window_bits sizes.
+ Added a demo read_user_transform_fn that examines the row filters in pngtest.c
+ Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
+ Made several minor corrections to pngtest.c
+ Changed "hptr += 16L" to "hptr = hptr + 16L" in pngmem.c for Turbo 3.0
+ Renamed the makefiles with longer but more user friendly extensions.
+ Define PNG_USE_PNGVCRD in makefile.vcawin32, to get MMX assembler code.
+ Copied the PNG copyright and license to a separate LICENSE file.
+ Revised documentation, png.h, and example.c to remove reference to
+ "viewing_gamma" which no longer appears in the PNG specification.
+ Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
+ Increase max_pixel_depth in pngrutil.c if a user transform needs it.
+ Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
+ Added a "png_check_version" function in png.c and pngtest.c that will generate
+ a helpful compiler error if an old png.h is found in the search path.
+ Added a copy of pngnow.png to the distribution.
+ Surrounded example.c code with #if 0 .. #endif to prevent people from
+ inadvertently trying to compile it.
+ Added type casting mostly in pngrtran.c and pngwtran.c
+ Removed some pointless "ptr = NULL" in pngmem.c
+ Added a "contrib" directory containing the source code from Greg's book.
+
+Send comments/corrections/commendations to
+png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
+
+Glenn R-P
diff --git a/osframework/source/ImageLib/png/changes b/osframework/source/ImageLib/png/changes
new file mode 100644
index 0000000..f7dd382
--- /dev/null
+++ b/osframework/source/ImageLib/png/changes
@@ -0,0 +1,476 @@
+CHANGES - changes for libpng
+
+version 0.2
+ added reader into png.h
+ fixed small problems in stub file
+version 0.3
+ added pull reader
+ split up pngwrite.c to several files
+ added pnglib.txt
+ added example.c
+ cleaned up writer, adding a few new tranformations
+ fixed some bugs in writer
+ interfaced with zlib 0.5
+ added K&R support
+ added check for 64 KB blocks for 16 bit machines
+version 0.4
+ cleaned up code and commented code
+ simplified time handling into png_time
+ created png_color_16 and png_color_8 to handle color needs
+ cleaned up color type defines
+ fixed various bugs
+ made various names more consistant
+ interfaced with zlib 0.71
+ cleaned up zTXt reader and writer (using zlib's Reset functions)
+ split transformations into pngrtran.c and pngwtran.c
+version 0.5
+ interfaced with zlib 0.8
+ fixed many reading and writing bugs
+ saved using 3 spaces instead of tabs
+version 0.6
+ added png_large_malloc() and png_large_free()
+ added png_size_t
+ cleaned up some compiler warnings
+ added png_start_read_image()
+version 0.7
+ cleaned up lots of bugs
+ finished dithering and other stuff
+ added test program
+ changed name from pnglib to libpng
+version 0.71 [June, 1995]
+ changed pngtest.png for zlib 0.93
+ fixed error in libpng.txt and example.c
+version 0.8
+ cleaned up some bugs
+ added png_set_filler()
+ split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
+ added #define's to remove unwanted code
+ moved png_info_init() to png.c
+ added old_size into png_realloc()
+ added functions to manually set filtering and compression info
+ changed compression parameters based on image type
+ optimized filter selection code
+ added version info
+ changed external functions passing floats to doubles (k&r problems?)
+ put all the configurable stuff in pngconf.h
+ enabled png_set_shift to work with paletted images on read
+ added png_read_update_info() - updates info structure with
+ transformations
+version 0.81 [August, 1995]
+ incorporated Tim Wegner's medium model code (thanks, Tim)
+version 0.82 [September, 1995]
+ [unspecified changes]
+version 0.85 [December, 1995]
+ added more medium model code (almost everything's a far)
+ added i/o, error, and memory callback functions
+ fixed some bugs (16 bit, 4 bit interlaced, etc.)
+ added first run progressive reader (barely tested)
+version 0.86 [January, 1996]
+ fixed bugs
+ improved documentation
+version 0.87 [January, 1996]
+ fixed medium model bugs
+ fixed other bugs introduced in 0.85 and 0.86
+ added some minor documentation
+version 0.88 [January, 1996]
+ fixed progressive bugs
+ replaced tabs with spaces
+ cleaned up documentation
+ added callbacks for read/write and warning/error functions
+version 0.89 [July, 1996]
+ added new initialization API to make libpng work better with shared libs
+ we now have png_create_read_struct(), png_create_write_struct(),
+ png_create_info_struct(), png_destroy_read_struct(), and
+ png_destroy_write_struct() instead of the separate calls to
+ malloc and png_read_init(), png_info_init(), and png_write_init()
+ changed warning/error callback functions to fix bug - this means you
+ should use the new initialization API if you were using the old
+ png_set_message_fn() calls, and that the old API no longer exists
+ so that people are aware that they need to change their code
+ changed filter selection API to allow selection of multiple filters
+ since it didn't work in previous versions of libpng anyways
+ optimized filter selection code
+ fixed png_set_background() to allow using an arbitrary RGB color for
+ paletted images
+ fixed gamma and background correction for paletted images, so
+ png_correct_palette is not needed unless you are correcting an
+ external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
+ in pngconf.h) - if nobody uses this, it may disappear in the future.
+ fixed bug with Borland 64K memory allocation (Alexander Lehmann)
+ fixed bug in interlace handling (Smarasderagd, I think)
+ added more error checking for writing and image to reduce invalid files
+ separated read and write functions so that they won't both be linked
+ into a binary when only reading or writing functionality is used
+ new pngtest image also has interlacing and zTXt
+ updated documentation to reflect new API
+version 0.90 [January, 1997]
+ made CRC errors/warnings on critical and ancillary chunks configurable
+ libpng will use the zlib CRC routines by (compile-time) default
+ changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
+ added external C++ wrapper statements to png.h (Gilles Dauphin)
+ allow PNG file to be read when some or all of file signature has already
+ been read from the beginning of the stream. ****This affects the size
+ of info_struct and invalidates all programs that use a shared libpng****
+ fixed png_filler() declarations
+ fixed? background color conversions
+ fixed order of error function pointers to match documentation
+ current chunk name is now available in png_struct to reduce the number
+ of nearly identical error messages (will simplify multi-lingual
+ support when available)
+ try to get ready for unknown-chunk callback functions:
+ - previously read critical chunks are flagged, so the chunk handling
+ routines can determine if the chunk is in the right place
+ - all chunk handling routines have the same prototypes, so we will
+ be able to handle all chunks via a callback mechanism
+ try to fix Linux "setjmp" buffer size problems
+version 0.95 [March, 1997]
+ fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
+ fixed bug in PNG file signature compares when start != 0
+ changed parameter type of png_set_filler(...filler...) from png_byte
+ to png_uint_32
+ added test for MACOS to ensure that both math.h and fp.h are not #included
+ added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
+ added "packswap" transformation, which changes the endianness of
+ packed-pixel bytes (Kevin Bracey)
+ added "strip_alpha" transformation, which removes the alpha channel of
+ input images without using it (not neccesarily a good idea)
+ added "swap_alpha" transformation, which puts the alpha channel in front
+ of the color bytes instead of after
+ removed all implicit variable tests which assume NULL == 0 (I think)
+ changed several variables to "png_size_t" to show 16/32-bit limitations
+ added new pCAL chunk read/write support
+ added experimental filter selection weighting (Greg Roelofs)
+ removed old png_set_rgbx() and png_set_xrgb() functions that have been
+ obsolete for about 2 years now (use png_set_filler() instead)
+ added macros to read 16- and 32-bit ints directly from buffer, to be
+ used only on those systems that support it (namely PowerPC and 680x0)
+ With some testing, this may become the default for MACOS/PPC systems.
+ only calculate CRC on data if we are going to use it
+ added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
+ added macros for simple libpng debugging output selectable at compile time
+ removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
+ more description of info_struct in libpng.txt and png.h
+ more instructions in example.c
+ more chunk types tested in pngtest.c
+ renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
+ png_set_<chunk>. We now have corresponding png_get_<chunk>
+ functions in pngget.c to get infomation in info_ptr. This isolates
+ the application from the internal organization of png_info_struct
+ (good for shared library implementations).
+version 0.96 [May, 1997]
+ fixed serious bug with < 8bpp images introduced in 0.95
+ fixed 256-color transparency bug (Greg Roelofs)
+ fixed up documentation (Greg Roelofs, Laszlo Nyul)
+ fixed "error" in pngconf.h for Linux setjmp() behaviour
+ fixed DOS medium model support (Tim Wegner)
+ fixed png_check_keyword() for case with error in static string text
+ added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
+ added typecasts to quiet compiler errors
+ added more debugging info
+version 0.97 [January, 1998]
+ removed PNG_USE_OWN_CRC capability
+ relocated png_set_crc_action from pngrutil.c to pngrtran.c
+ fixed typecasts of "new_key", etc. (Andreas Dilger)
+ added RFC 1152 [sic] date support
+ fixed bug in gamma handling of 4-bit grayscale
+ added 2-bit grayscale gamma handling (Glenn R-P)
+ added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
+ minor corrections in libpng.txt
+ added simple sRGB support (Glenn R-P)
+ easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
+ all configurable options can be selected from command-line instead
+ of having to edit pngconf.h (Glenn R-P)
+ fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
+ added more conditions for png_do_background, to avoid changing
+ black pixels to background when a background is supplied and
+ no pixels are transparent
+ repaired PNG_NO_STDIO behaviour
+ tested NODIV support and made it default behaviour (Greg Roelofs)
+ added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
+ regularized version numbering scheme and bumped shared-library major
+ version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
+version 0.98 [January, 1998]
+ cleaned up some typos in libpng.txt and in code documentation
+ fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
+ cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
+ changed recommendation about file_gamma for PC images to .51 from .45,
+ in example.c and libpng.txt, added comments to distinguish between
+ screen_gamma, viewing_gamma, and display_gamma.
+ changed all references to RFC1152 to read RFC1123 and changed the
+ PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
+ added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
+ changed srgb_intent from png_byte to int to avoid compiler bugs
+version 0.99 [January 30, 1998]
+ free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
+ fixed a longstanding "packswap" bug in pngtrans.c
+ fixed some inconsistencies in pngconf.h that prevented compiling with
+ PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
+ fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
+ changed recommendation about file_gamma for PC images to .50 from .51 in
+ example.c and libpng.txt, and changed file_gamma for sRGB images to .45
+ added a number of functions to access information from the png structure
+ png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
+ added TARGET_MACOS similar to zlib-1.0.8
+ define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
+ added type casting to all png_malloc() function calls
+version 0.99a [January 31, 1998]
+ Added type casts and parentheses to all returns that return a value.(Tim W.)
+version 0.99b [February 4, 1998]
+ Added type cast png_uint_32 on malloc function calls where needed.
+ Changed type of num_hist from png_uint_32 to int (same as num_palette).
+ Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
+ Renamed makefile.elf to makefile.lnx.
+version 0.99c [February 7, 1998]
+ More type casting. Removed erroneous overflow test in pngmem.c.
+ Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
+ Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5.
+version 0.99d [February 11, 1998]
+ Renamed "far_to_near()" "png_far_to_near()"
+ Revised libpng.3
+ Version 99c "buffered" operations didn't work as intended. Replaced them
+ with png_memcpy_check() and png_memset_check().
+ Added many "if (png_ptr == NULL) return" to quell compiler warnings about
+ unused png_ptr, mostly in pngget.c and pngset.c.
+ Check for overlength tRNS chunk present when indexed-color PLTE is read.
+ Cleaned up spelling errors in libpng.3/libpng.txt
+ Corrected a problem with png_get_tRNS() which returned undefined trans array
+version 0.99e [February 28, 1998]
+ Corrected png_get_tRNS() again.
+ Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
+ Touched up example.c to make more of it compileable, although the entire
+ file still can't be compiled (Willem van Schaik)
+ Fixed a bug in png_do_shift() (Bryan Tsai)
+ Added a space in png.h prototype for png_write_chunk_start()
+ Replaced pngtest.png with one created with zlib 1.1.1
+ Changed pngtest to report PASS even when file size is different (Jean-loup G.)
+ Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
+version 0.99f [March 5, 1998]
+ Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
+ Moved makefiles into a "scripts" directory, and added INSTALL instruction file
+ Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
+ Added pointers to "note on libpng versions" in makefile.lnx and README
+ Added row callback feature when reading and writing nonprogressive rows
+ and added a test of this feature in pngtest.c
+ Added user transform callbacks, with test of the feature in pngtest.c
+version 0.99g [March 6, 1998, morning]
+ Minor changes to pngtest.c to suppress compiler warnings.
+ Removed "beta" language from documentation.
+version 0.99h [March 6, 1998, evening]
+ Minor changes to previous minor changes to pngtest.c
+ Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
+ and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
+version 1.00 [March 7, 1998]
+ Changed several typedefs in pngrutil.c
+ Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
+ replaced "while(1)" with "for(;;)"
+ added PNGARG() to prototypes in pngtest.c and removed some prototypes
+ updated some of the makefiles (Tom Lane)
+ changed some typedefs (s_start, etc.) in pngrutil.c
+ fixed dimensions of "short_months" array in pngwrite.c
+ Replaced ansi2knr.c with the one from jpeg-v6
+version 1.0.0 [March 8, 1998]
+ Changed name from 1.00 to 1.0.0 (Adam Costello)
+ Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)
+version 1.0.0a [March 9, 1998]
+ Fixed three bugs in pngrtran.c to make gamma+background handling consistent
+ (Greg Roelofs)
+ Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz
+ for major, minor, and bugfix releases. This is 10001. (Adam Costello,
+ Tom Lane)
+ Make months range from 1-12 in png_convert_to_rfc1123
+version 1.0.0b [March 13, 1998]
+ Quieted compiler complaints about two empty "for" loops in pngrutil.c
+ Minor changes to makefile.s2x
+ Removed #ifdef/#endif around a png_free() in pngread.c
+version 1.0.1 [March 14, 1998]
+ Changed makefile.s2x to reduce security risk of using a relative pathname
+ Fixed some typos in the documentation (Greg).
+ Fixed a problem with value of "channels" returned by png_read_update_info()
+version 1.0.1a [April 21, 1998]
+ Optimized Paeth calculations by replacing abs() function calls with intrinsics
+ plus other loop optimizations. Improves avg decoding speed by about 20%.
+ Commented out i386istic "align" compiler flags in makefile.lnx.
+ Reduced the default warning level in some makefiles, to make them consistent.
+ Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
+ Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
+ Added grayscale and 16-bit capability to png_do_read_filler().
+ Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
+ too large when writing an image with bit_depth < 8 (Bob Dellaca).
+ Corrected some bugs in the experimental weighted filtering heuristics.
+ Moved a misplaced pngrutil code block that truncates tRNS if it has more
+ than num_palette entries -- test was done before num_palette was defined.
+ Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
+ Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
+version 1.0.1b [May 2, 1998]
+ Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
+ Relocated the png_composite macros from pngrtran.c to png.h (Greg).
+ Added makefile.sco (contributed by Mike Hopkirk).
+ Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
+ Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
+ More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
+ More work on loop optimization which may help when compiled with C++ compilers.
+ Added warnings when people try to use transforms they've defined out.
+ Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
+ Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
+version 1.0.1c [May 11, 1998]
+ Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
+ filler bytes should have been 0xff instead of 0xf.
+ Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
+ Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
+ out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
+ Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
+ for consistency, in pngconf.h
+ Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier
+ to remove unwanted capabilities via the compile line
+ Made some corrections to grammar (which, it's) in documentation (Greg).
+ Corrected example.c, use of row_pointers in png_write_image().
+version 1.0.1d [May 24, 1998]
+ Corrected several statements that used side effects illegally in pngrutil.c
+ and pngtrans.c, that were introduced in version 1.0.1b
+ Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
+ More corrections to example.c, use of row_pointers in png_write_image()
+ and png_read_rows().
+ Added pngdll.mak and pngdef.pas to scripts directory, contributed by
+ Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
+ Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
+ Changed several loops from count-down to count-up, for consistency.
+version 1.0.1e [June 6, 1998]
+ Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
+ added warnings when people try to set png_read_fn and png_write_fn in
+ the same structure.
+ Added a test such that png_do_gamma will be done when num_trans==0
+ for truecolor images that have defined a background. This corrects an
+ error that was introduced in libpng-0.90 that can cause gamma processing
+ to be skipped.
+ Added tests in png.h to include "trans" and "trans_values" in structures
+ when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
+ Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
+ Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
+ Added capability for user-provided malloc_fn() and free_fn() functions,
+ and revised pngtest.c to demonstrate their use, replacing the
+ PNGTEST_DEBUG_MEM feature.
+ Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
+version 1.0.2 [June 14, 1998]
+ Fixed two bugs in makefile.bor .
+version 1.0.2a [December 30, 1998]
+ Replaced and extended code that was removed from png_set_filler() in 1.0.1a.
+ Fixed a bug in png_do_filler() that made it fail to write filler bytes in
+ the left-most pixel of each row (Kevin Bracey).
+ Changed "static pngcharp tIME_string" to "static char tIME_string[30]"
+ in pngtest.c (Duncan Simpson).
+ Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk
+ even when no tIME chunk was present in the source file.
+ Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit.
+ Fixed a problem in png_read_push_finish_row(), which would not skip some
+ passes that it should skip, for images that are less than 3 pixels high.
+ Interchanged the order of calls to png_do_swap() and png_do_shift()
+ in pngwtran.c (John Cromer).
+ Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h .
+ Changed "bad adaptive filter type" from error to warning in pngrutil.c .
+ Fixed a documentation error about default filtering with 8-bit indexed-color.
+ Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO
+ (L. Peter Deutsch).
+ Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions.
+ Added png_get_copyright() and png_get_header_version() functions.
+ Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c
+ Added information about debugging in libpng.txt and libpng.3 .
+ Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and makefile.sco.
+ Removed lines after Dynamic Dependencies" in makefile.aco .
+ Revised makefile.dec to make a shared library (Jeremie Petit).
+ Removed trailing blanks from all files.
+version 1.0.2a [January 6, 1999]
+ Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h
+ Added "if" tests to silence complaints about unused png_ptr in png.h and png.c
+ Changed "check_if_png" function in example.c to return true (nonzero) if PNG.
+ Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()
+ which is obsolete.
+version 1.0.3 [January 14, 1999]
+ Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)
+ Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO.
+version 1.0.3a [August 12, 1999]
+ Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
+ if an attempt is made to read an interlaced image when it's not supported.
+ Added check if png_ptr->trans is defined before free'ing it in pngread.c
+ Modified the Y2K statement to include versions back to version 0.71
+ Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c
+ Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments)
+ Replaced leading blanks with tab characters in makefile.hux
+ Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
+ Changed (float)red and (float)green to (double)red, (double)green
+ in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
+ Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
+ Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
+ Updated documentation to refer to the PNG-1.2 specification.
+ Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c
+ in makefile.knr, INSTALL, and README (L. Peter Deutsch)
+ Fixed bugs in calculation of the length of rowbytes when adding alpha
+ channels to 16-bit images, in pngrtran.c (Chris Nokleberg)
+ Added function png_set_user_transform_info() to store user_transform_ptr,
+ user_depth, and user_channels into the png_struct, and a function
+ png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)
+ Added function png_set_empty_plte_permitted() to make libpng useable
+ in MNG applications.
+ Corrected the typedef for png_free_ptr in png.h (Jesse Jones).
+ Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be
+ consistent with PNG-1.2, and allow variance of 500 before complaining.
+ Added assembler code contributed by Intel in file pngvcrd.c and modified
+ makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant)
+ Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
+ Added some aliases for png_set_expand() in pngrtran.c, namely
+ png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()
+ (Greg Roelofs, in "PNG: The Definitive Guide").
+ Added makefile.beo for BEOS on X86, contributed by Sander Stok.
+version 1.0.3b [August 26, 1999]
+ Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
+ Changed leading blanks to tabs in all makefiles.
+ Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.
+ Made alternate versions of png_set_expand() in pngrtran.c, namely
+ png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha
+ (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases.
+ Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h
+ Revised calculation of num_blocks in pngmem.c to avoid a potentially
+ negative shift distance, whose results are undefined in the C language.
+ Added a check in pngset.c to prevent writing multiple tIME chunks.
+ Added a check in pngwrite.c to detect invalid small window_bits sizes.
+version 1.0.3d [September 4, 1999]
+ Fixed type casting of igamma in pngrutil.c
+ Added new png_expand functions to scripts/pngdef.pas and pngos2.def
+ Added a demo read_user_transform_fn that examines the row filters in pngtest.c
+version 1.0.4 [September 24, 1999]
+ Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
+ Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
+ Made several minor corrections to pngtest.c
+ Renamed the makefiles with longer but more user friendly extensions.
+ Copied the PNG copyright and license to a separate LICENSE file.
+ Revised documentation, png.h, and example.c to remove reference to
+ "viewing_gamma" which no longer appears in the PNG specification.
+ Revised pngvcrd.c to use MMX code for interlacing only on the final pass.
+ Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a
+ Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX
+ assembler code) and makefile.vcwin32 (doesn't).
+ Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
+ Added a copy of pngnow.png to the distribution.
+version 1.0.4a [September 25, 1999]
+ Increase max_pixel_depth in pngrutil.c if a user transform needs it.
+ Changed several division operations to right-shifts in pngvcrd.c
+version 1.0.4b [September 30, 1999]
+ Added parentheses in line 3732 of pngvcrd.c
+ Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
+version 1.0.4c [October 1, 1999]
+ Added a "png_check_version" function in png.c and pngtest.c that will generate
+ a helpful compiler error if an old png.h is found in the search path.
+ Changed type of png_user_transform_depth|channels from int to png_byte.
+version 1.0.4d [October 6, 1999]
+ Changed 0.45 to 0.45455 in png_set_sRGB()
+ Removed unused PLTE entries from pngnow.png
+ Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
+version 1.0.4e [October 10, 1999]
+ Fixed sign error in pngvcrd.c (Greg Roelofs)
+ Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
+version 1.0.5 [October 15, 1999]
+ Surrounded example.c code with #if 0 .. #endif to prevent people from
+ inadvertently trying to compile it.
+ Changed png_get_header_version() from a function to a macro in png.h
+ Added type casting mostly in pngrtran.c and pngwtran.c
+ Removed some pointless "ptr = NULL" in pngmem.c
+ Added a "contrib" directory containing the source code from Greg's book.
diff --git a/osframework/source/ImageLib/png/example.c b/osframework/source/ImageLib/png/example.c
new file mode 100644
index 0000000..8baa202
--- /dev/null
+++ b/osframework/source/ImageLib/png/example.c
@@ -0,0 +1,706 @@
+
+#if 0 /* in case someone actually tries to compile this */
+
+/* example.c - an example of using libpng */
+
+/* This is an example of how to use libpng to read and write PNG files.
+ * The file libpng.txt is much more verbose then this. If you have not
+ * read it, do so first. This was designed to be a starting point of an
+ * implementation. This is not officially part of libpng, and therefore
+ * does not require a copyright notice.
+ *
+ * This file does not currently compile, because it is missing certain
+ * parts, like allocating memory to hold an image. You will have to
+ * supply these parts to get it to compile. For an example of a minimal
+ * working PNG reader/writer, see pngtest.c, included in this distribution.
+ */
+
+#include "png.h"
+
+/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
+ * returns zero if the image is a PNG and nonzero if it isn't a PNG.
+ *
+ * The function check_if_png() shown here, but not used, returns nonzero (true)
+ * if the file can be opened and is a PNG, 0 (false) otherwise.
+ *
+ * If this call is successful, and you are going to keep the file open,
+ * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
+ * you have created the png_ptr, so that libpng knows your application
+ * has read that many bytes from the start of the file. Make sure you
+ * don't call png_set_sig_bytes() with more than 8 bytes read or give it
+ * an incorrect number of bytes read, or you will either have read too
+ * many bytes (your fault), or you are telling libpng to read the wrong
+ * number of magic bytes (also your fault).
+ *
+ * Many applications already read the first 2 or 4 bytes from the start
+ * of the image to determine the file type, so it would be easiest just
+ * to pass the bytes to png_sig_cmp() or even skip that if you know
+ * you have a PNG file, and call png_set_sig_bytes().
+ */
+#define PNG_BYTES_TO_CHECK 4
+int check_if_png(char *file_name, FILE **fp)
+{
+ char buf[PNG_BYTES_TO_CHECK];
+
+ /* Open the prospective PNG file. */
+ if ((*fp = fopen(file_name, "rb")) != NULL);
+ return 0;
+
+ /* Read in some of the signature bytes */
+ if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
+ return 0;
+
+ /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
+ Return nonzero (true) if they match */
+
+ return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
+}
+
+/* Read a PNG file. You may want to return an error code if the read
+ * fails (depending upon the failure). There are two "prototypes" given
+ * here - one where we are given the filename, and we need to open the
+ * file, and the other where we are given an open file (possibly with
+ * some or all of the magic bytes read - see comments above).
+ */
+#ifdef open_file /* prototype 1 */
+void read_png(char *file_name) /* We need to open the file */
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ unsigned int sig_read = 0;
+ png_uint_32 width, height;
+ int bit_depth, color_type, interlace_type;
+ FILE *fp;
+
+ if ((fp = fopen(file_name, "rb")) == NULL)
+ return;
+#else no_open_file /* prototype 2 */
+void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_uint_32 width, height;
+ int bit_depth, color_type, interlace_type;
+#endif no_open_file /* only use one prototype! */
+
+ /* Create and initialize the png_struct with the desired error handler
+ * functions. If you want to use the default stderr and longjump method,
+ * you can supply NULL for the last three parameters. We also supply the
+ * the compiler header file version, so that we know if the application
+ * was compiled with a compatible version of the library. REQUIRED
+ */
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ png_voidp user_error_ptr, user_error_fn, user_warning_fn);
+
+ if (png_ptr == NULL)
+ {
+ fclose(fp);
+ return;
+ }
+
+ /* Allocate/initialize the memory for image information. REQUIRED. */
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ {
+ fclose(fp);
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+ return;
+ }
+
+ /* Set error handling if you are using the setjmp/longjmp method (this is
+ * the normal method of doing things with libpng). REQUIRED unless you
+ * set up your own error handlers in the png_create_read_struct() earlier.
+ */
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ /* Free all of the memory associated with the png_ptr and info_ptr */
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+ fclose(fp);
+ /* If we get here, we had a problem reading the file */
+ return;
+ }
+
+ /* One of the following I/O initialization methods is REQUIRED */
+#ifdef streams /* PNG file I/O method 1 */
+ /* Set up the input control if you are using standard C streams */
+ png_init_io(png_ptr, fp);
+
+#else no_streams /* PNG file I/O method 2 */
+ /* If you are using replacement read functions, instead of calling
+ * png_init_io() here you would call:
+ */
+ png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
+ /* where user_io_ptr is a structure you want available to the callbacks */
+#endif no_streams /* Use only one I/O method! */
+
+ /* If we have already read some of the signature */
+ png_set_sig_bytes(png_ptr, sig_read);
+
+ /* The call to png_read_info() gives us all of the information from the
+ * PNG file before the first IDAT (image data chunk). REQUIRED
+ */
+ png_read_info(png_ptr, info_ptr);
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ &interlace_type, NULL, NULL);
+
+/**** Set up the data transformations you want. Note that these are all
+ **** optional. Only call them if you want/need them. Many of the
+ **** transformations only work on specific types of images, and many
+ **** are mutually exclusive.
+ ****/
+
+ /* tell libpng to strip 16 bit/color files down to 8 bits/color */
+ png_set_strip_16(png_ptr);
+
+ /* Strip alpha bytes from the input data without combining with the
+ * background (not recommended).
+ */
+ png_set_strip_alpha(png_ptr);
+
+ /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
+ * byte into separate bytes (useful for paletted and grayscale images).
+ */
+ png_set_packing(png_ptr);
+
+ /* Change the order of packed pixels to least significant bit first
+ * (not useful if you are using png_set_packing). */
+ png_set_packswap(png_ptr);
+
+ /* Expand paletted colors into true RGB triplets */
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_expand(png_ptr);
+
+ /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
+ if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
+ png_set_expand(png_ptr);
+
+ /* Expand paletted or RGB images with transparency to full alpha channels
+ * so the data will be available as RGBA quartets.
+ */
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_expand(png_ptr);
+
+ /* Set the background color to draw transparent and alpha images over.
+ * It is possible to set the red, green, and blue components directly
+ * for paletted images instead of supplying a palette index. Note that
+ * even if the PNG file supplies a background, you are not required to
+ * use it - you should use the (solid) application background if it has one.
+ */
+
+ png_color_16 my_background, *image_background;
+
+ if (png_get_bKGD(png_ptr, info_ptr, &image_background))
+ png_set_background(png_ptr, image_background,
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ else
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+
+ /* Some suggestions as to how to get a screen gamma value */
+
+ /* Note that screen gamma is the display_exponent, which includes
+ * the CRT_exponent and any correction for viewing conditions */
+ if (/* We have a user-defined screen gamma value */)
+ {
+ screen_gamma = user-defined screen_gamma;
+ }
+ /* This is one way that applications share the same screen gamma value */
+ else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
+ {
+ screen_gamma = atof(gamma_str);
+ }
+ /* If we don't have another value */
+ else
+ {
+ screen_gamma = 2.2; /* A good guess for a PC monitors in a dimly
+ lit room */
+ screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
+ }
+
+ /* Tell libpng to handle the gamma conversion for you. The second call
+ * is a good guess for PC generated images, but it should be configurable
+ * by the user at run time by the user. It is strongly suggested that
+ * your application support gamma correction.
+ */
+
+ int intent;
+
+ if (png_get_sRGB(png_ptr, info_ptr, &intent))
+ png_set_sRGB(png_ptr, intent, 0);
+ else
+ {
+ double image_gamma;
+ if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
+ png_set_gamma(png_ptr, screen_gamma, image_gamma);
+ else
+ png_set_gamma(png_ptr, screen_gamma, 0.45455);
+ }
+
+ /* Dither RGB files down to 8 bit palette or reduce palettes
+ * to the number of colors available on your screen.
+ */
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ png_uint_32 num_palette;
+ png_colorp palette;
+
+ /* This reduces the image to the application supplied palette */
+ if (/* we have our own palette */)
+ {
+ /* An array of colors to which the image should be dithered */
+ png_color std_color_cube[MAX_SCREEN_COLORS];
+
+ png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
+ MAX_SCREEN_COLORS, NULL, 0);
+ }
+ /* This reduces the image to the palette supplied in the file */
+ else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
+ {
+ png_color16p histogram;
+
+ png_get_hIST(png_ptr, info_ptr, &histogram);
+
+ png_set_dither(png_ptr, palette, num_palette,
+ max_screen_colors, histogram, 0);
+ }
+ }
+
+ /* invert monocrome files to have 0 as white and 1 as black */
+ png_set_invert_mono(png_ptr);
+
+ /* If you want to shift the pixel values from the range [0,255] or
+ * [0,65535] to the original [0,7] or [0,31], or whatever range the
+ * colors were originally in:
+ */
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
+ {
+ png_color8p sig_bit;
+
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
+ png_set_shift(png_ptr, sig_bit);
+ }
+
+ /* flip the RGB pixels to BGR (or RGBA to BGRA) */
+ png_set_bgr(png_ptr);
+
+ /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
+ png_set_swap_alpha(png_ptr);
+
+ /* swap bytes of 16 bit files to least significant byte first */
+ png_set_swap(png_ptr);
+
+ /* Add filler (or alpha) byte (before/after each RGB triplet) */
+ png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
+
+ /* Turn on interlace handling. REQUIRED if you are not using
+ * png_read_image(). To see how to handle interlacing passes,
+ * see the png_read_row() method below:
+ */
+ number_passes = png_set_interlace_handling(png_ptr);
+
+ /* Optional call to gamma correct and add the background to the palette
+ * and update info structure. REQUIRED if you are expecting libpng to
+ * update the palette for you (ie you selected such a transform above).
+ */
+ png_read_update_info(png_ptr, info_ptr);
+
+ /* Allocate the memory to hold the image using the fields of info_ptr. */
+
+ /* The easiest way to read the image: */
+ png_bytep row_pointers[height];
+
+ for (row = 0; row < height; row++)
+ {
+ row_pointers[row] = malloc(png_get_rowbytes(png_ptr, info_ptr));
+ }
+
+ /* Now it's time to read the image. One of these methods is REQUIRED */
+#ifdef entire /* Read the entire image in one go */
+ png_read_image(png_ptr, row_pointers);
+
+#else no_entire /* Read the image one or more scanlines at a time */
+ /* The other way to read images - deal with interlacing: */
+
+ for (pass = 0; pass < number_passes; pass++)
+ {
+#ifdef single /* Read the image a single row at a time */
+ for (y = 0; y < height; y++)
+ {
+ png_read_rows(png_ptr, &row_pointers[y], NULL, 1);
+ }
+
+#else no_single /* Read the image several rows at a time */
+ for (y = 0; y < height; y += number_of_rows)
+ {
+#ifdef sparkle /* Read the image using the "sparkle" effect. */
+ png_read_rows(png_ptr, &row_pointers[y], NULL, number_of_rows);
+
+ png_read_rows(png_ptr, NULL, row_pointers[y], number_of_rows);
+#else no_sparkle /* Read the image using the "rectangle" effect */
+ png_read_rows(png_ptr, NULL, &row_pointers[y], number_of_rows);
+#endif no_sparkle /* use only one of these two methods */
+ }
+
+ /* if you want to display the image after every pass, do
+ so here */
+#endif no_single /* use only one of these two methods */
+ }
+#endif no_entire /* use only one of these two methods */
+
+ /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
+ png_read_end(png_ptr, info_ptr);
+
+ /* clean up after the read, and free any memory allocated - REQUIRED */
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+
+ /* close the file */
+ fclose(fp);
+
+ /* that's it */
+ return;
+}
+
+/* progressively read a file */
+
+int
+initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
+{
+ /* Create and initialize the png_struct with the desired error handler
+ * functions. If you want to use the default stderr and longjump method,
+ * you can supply NULL for the last three parameters. We also check that
+ * the library version is compatible in case we are using dynamically
+ * linked libraries.
+ */
+ *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ png_voidp user_error_ptr, user_error_fn, user_warning_fn);
+
+ if (*png_ptr == NULL)
+ {
+ *info_ptr = NULL;
+ return ERROR;
+ }
+
+ *info_ptr = png_create_info_struct(png_ptr);
+
+ if (*info_ptr == NULL)
+ {
+ png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
+ return ERROR;
+ }
+
+ if (setjmp((*png_ptr)->jmpbuf))
+ {
+ png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
+ return ERROR;
+ }
+
+ /* This one's new. You will need to provide all three
+ * function callbacks, even if you aren't using them all.
+ * If you aren't using all functions, you can specify NULL
+ * parameters. Even when all three functions are NULL,
+ * you need to call png_set_progressive_read_fn().
+ * These functions shouldn't be dependent on global or
+ * static variables if you are decoding several images
+ * simultaneously. You should store stream specific data
+ * in a separate struct, given as the second parameter,
+ * and retrieve the pointer from inside the callbacks using
+ * the function png_get_progressive_ptr(png_ptr).
+ */
+ png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
+ info_callback, row_callback, end_callback);
+
+ return OK;
+}
+
+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;
+}
+
+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.
+ */
+}
+
+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:
+ */
+
+ png_progressive_combine_row(png_ptr, old_row, new_row);
+
+/* where old_row is what was displayed for previous rows. Note
+ * that the first pass (pass == 0 really) will completely cover
+ * the old row, so the rows do not have to be initialized. After
+ * the first pass (and only for interlaced images), you will have
+ * to pass the current row, and the function will combine the
+ * old row and the new row.
+ */
+}
+
+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.
+ */
+}
+
+/* write a png file */
+void write_png(char *file_name /* , ... other image information ... */)
+{
+ FILE *fp;
+ png_structp png_ptr;
+ png_infop info_ptr;
+
+ /* open the file */
+ fp = fopen(file_name, "wb");
+ if (fp == NULL)
+ return;
+
+ /* Create and initialize the png_struct with the desired error handler
+ * functions. If you want to use the default stderr and longjump method,
+ * you can supply NULL for the last three parameters. We also check that
+ * the library version is compatible with the one used at compile time,
+ * in case we are using dynamically linked libraries. REQUIRED.
+ */
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
+ png_voidp user_error_ptr, user_error_fn, user_warning_fn);
+
+ if (png_ptr == NULL)
+ {
+ fclose(fp);
+ return;
+ }
+
+ /* Allocate/initialize the image information data. REQUIRED */
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ {
+ fclose(fp);
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ return;
+ }
+
+ /* Set error handling. REQUIRED if you aren't supplying your own
+ * error hadnling functions in the png_create_write_struct() call.
+ */
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ /* If we get here, we had a problem reading the file */
+ fclose(fp);
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ return;
+ }
+
+ /* One of the following I/O initialization functions is REQUIRED */
+#ifdef streams /* I/O initialization method 1 */
+ /* set up the output control if you are using standard C streams */
+ png_init_io(png_ptr, fp);
+#else no_streams /* I/O initialization method 2 */
+ /* If you are using replacement read functions, instead of calling
+ * png_init_io() here you would call */
+ png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
+ user_IO_flush_function);
+ /* where user_io_ptr is a structure you want available to the callbacks */
+#endif no_streams /* only use one initialization method */
+
+ /* Set the image information here. Width and height are up to 2^31,
+ * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
+ * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
+ * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
+ * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
+ * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
+ * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
+ */
+ png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
+ PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+ /* set the palette if there is one. REQUIRED for indexed-color images */
+ palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
+ /* ... set palette colors ... */
+ png_set_PLTE(png_ptr, info_ptr, palette, 256);
+
+ /* optional significant bit chunk */
+ /* if we are dealing with a grayscale image then */
+ sig_bit.gray = true_bit_depth;
+ /* otherwise, if we are dealing with a color image then */
+ sig_bit.red = true_red_bit_depth;
+ sig_bit.green = true_green_bit_depth;
+ sig_bit.blue = true_blue_bit_depth;
+ /* if the image has an alpha channel then */
+ sig_bit.alpha = true_alpha_bit_depth;
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
+
+
+ /* Optional gamma chunk is strongly suggested if you have any guess
+ * as to the correct gamma of the image.
+ */
+ png_set_gAMA(png_ptr, info_ptr, gamma);
+
+ /* Optionally write comments into the image */
+ text_ptr[0].key = "Title";
+ text_ptr[0].text = "Mona Lisa";
+ text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
+ text_ptr[1].key = "Author";
+ text_ptr[1].text = "Leonardo DaVinci";
+ text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
+ text_ptr[2].key = "Description";
+ text_ptr[2].text = "<long text>";
+ text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
+ png_set_text(png_ptr, info_ptr, text_ptr, 3);
+
+ /* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
+ /* note that if sRGB is present the cHRM chunk must be ignored
+ * on read and must be written in accordance with the sRGB profile */
+
+ /* Write the file header information. REQUIRED */
+ png_write_info(png_ptr, info_ptr);
+
+ /* Once we write out the header, the compression type on the text
+ * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
+ * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
+ * at the end.
+ */
+
+ /* set up the transformations you want. Note that these are
+ * all optional. Only call them if you want them.
+ */
+
+ /* invert monocrome pixels */
+ png_set_invert_mono(png_ptr);
+
+ /* Shift the pixels up to a legal bit depth and fill in
+ * as appropriate to correctly scale the image.
+ */
+ png_set_shift(png_ptr, &sig_bit);
+
+ /* pack pixels into bytes */
+ png_set_packing(png_ptr);
+
+ /* swap location of alpha bytes from ARGB to RGBA */
+ png_set_swap_alpha(png_ptr);
+
+ /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
+ * RGB (4 channels -> 3 channels). The second parameter is not used.
+ */
+ png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
+
+ /* flip BGR pixels to RGB */
+ png_set_bgr(png_ptr);
+
+ /* swap bytes of 16-bit files to most significant byte first */
+ png_set_swap(png_ptr);
+
+ /* swap bits of 1, 2, 4 bit packed pixel formats */
+ png_set_packswap(png_ptr);
+
+ /* turn on interlace handling if you are not using png_write_image() */
+ if (interlacing)
+ number_passes = png_set_interlace_handling(png_ptr);
+ else
+ number_passes = 1;
+
+ /* The easiest way to write the image (you may have a different memory
+ * layout, however, so choose what fits your needs best). You need to
+ * use the first method if you aren't handling interlacing yourself.
+ */
+ png_uint_32 k, height, width;
+ png_byte image[height][width];
+ png_bytep row_pointers[height];
+ for (k = 0; k < height; k++)
+ row_pointers[k] = image + k*width;
+
+ /* One of the following output methods is REQUIRED */
+#ifdef entire /* write out the entire image data in one call */
+ png_write_image(png_ptr, row_pointers);
+
+ /* the other way to write the image - deal with interlacing */
+
+#else no_entire /* write out the image data by one or more scanlines */
+ /* The number of passes is either 1 for non-interlaced images,
+ * or 7 for interlaced images.
+ */
+ for (pass = 0; pass < number_passes; pass++)
+ {
+ /* Write a few rows at a time. */
+ png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows);
+
+ /* If you are only writing one row at a time, this works */
+ for (y = 0; y < height; y++)
+ {
+ png_write_rows(png_ptr, &row_pointers[y], 1);
+ }
+ }
+#endif no_entire /* use only one output method */
+
+ /* You can write optional chunks like tEXt, zTXt, and tIME at the end
+ * as well.
+ */
+
+ /* It is REQUIRED to call this to finish writing the rest of the file */
+ png_write_end(png_ptr, info_ptr);
+
+ /* if you malloced the palette, free it here */
+ free(info_ptr->palette);
+
+ /* if you allocated any text comments, free them here */
+
+ /* clean up after the write, and free any memory allocated */
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+
+ /* close the file */
+ fclose(fp);
+
+ /* that's it */
+ return;
+}
+
+#endif /* if 0 */
diff --git a/osframework/source/ImageLib/png/install b/osframework/source/ImageLib/png/install
new file mode 100644
index 0000000..b17bb8b
--- /dev/null
+++ b/osframework/source/ImageLib/png/install
@@ -0,0 +1,104 @@
+
+Installing libpng version 1.0.5 - October 15, 1999
+
+Before installing libpng, you must first install zlib. zlib
+can usually be found wherever you got libpng. zlib can be
+placed in another directory, at the same level as libpng.
+Note that your system might already have a preinstalled
+zlib, but you will still need to have access to the
+zlib.h and zconf.h include files that correspond to the
+version of zlib that's installed.
+
+You can rename the directories that you downloaded (they
+might be called "libpng-1.0.5" or "lpng103" and "zlib-1.1.3"
+or "zlib113") so that you have directories called "zlib" and "libpng".
+
+Your directory structure should look like this:
+
+ .. (the parent directory)
+ libpng (this directory)
+ INSTALL (this file)
+ README
+ *.h
+ *.c
+ contrib
+ gregbook
+ scripts
+ makefile.*
+ pngtest.png
+ etc.
+ zlib
+ README
+ *.h
+ *.c
+ contrib
+ etc.
+
+First enter the zlib directory and follow the instructions
+in zlib/README. Then come back here and choose the
+appropriate makefile.sys in the scripts directory.
+The files that are presently available in the scripts directory
+include
+
+ descrip.mms => VMS makefile for MMS or MMK
+ makefile.std => Generic UNIX makefile
+ makefile.knr => Archaic UNIX Makefile that converts files with
+ ansi2knr (Requires ansi2knr.c from
+ ftp://ftp.cs.wisc.edu/ghost)
+ makefile.dec => DEC Alpha UNIX makefile
+ makefile.hpux => HPUX (10.20 and 11.00) makefile
+ makefile.sgi => Silicon Graphics IRIX makefile
+ makefile.sunos => Sun makefile
+ makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.5)
+ makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.5)
+ makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
+ makefile.mips => MIPS makefile
+ makefile.acorn => Acorn makefile
+ makefile.amiga => Amiga makefile
+ smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
+ (Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
+ makefile.atari => Atari makefile
+ makefile.beos => BEOS makefile for X86
+ makefile.borland => Borland makefile
+ build.bat => MS-DOS batch file for Borland compiler
+ makefile.dj2 => DJGPP 2 makefile
+ makefile.msc => Microsoft C makefile
+ makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and later (uses
+ assembler code)
+ makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later (does
+ not use assembler code)
+ makefile.turboc3 => Turbo C 3.0 makefile
+ makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
+ pngos2.def => OS/2 module definition file used by makefile.os2
+ makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
+ 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
+ SCOPTIONS.ppc => Used with smakefile.ppc
+
+Copy the file (or files) that you need from the
+scripts directory into this directory, for example
+
+ MSDOS example: copy scripts\makefile.msc makefile
+ UNIX example: cp scripts/makefile.std makefile
+
+Read the makefile to see if you need to change any source or
+target directories to match your preferences.
+
+Then read pngconf.h to see if you want to make any configuration
+changes.
+
+Then just run "make test" which will create the libpng library in
+this directory and run a quick test that reads the "pngtest.png"
+file and writes a "pngout.png" file that should be identical to it.
+Look for "9782 zero samples" in the output of the test. For more
+confidence, you can run another test by typing "pngtest pngnow.png"
+and looking for "289 zero samples" in the output.
+
+Most of the makefiles will allow you to run "make install" to
+put the library in its final resting place (if you want to
+do that, run "make install" in the zlib directory first if necessary).
+
+Further information can be found in the README and libpng.txt
+files, in the individual makefiles, and in png.h, and the manual
+pages libpng.3 and png.5.
diff --git a/osframework/source/ImageLib/png/knownbug b/osframework/source/ImageLib/png/knownbug
new file mode 100644
index 0000000..f94366a
--- /dev/null
+++ b/osframework/source/ImageLib/png/knownbug
@@ -0,0 +1,58 @@
+
+Known bugs and suggested enhancements in libpng-1.0.4
+
+
+1. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
+
+ Loops need to be optimized everywhere
+
+ Make them count down instead of up -- Kevin Bracey
+
+ Optimizing compilers don't need this, and making
+ the change would be error prone -- Tom Lane, Glenn R-P
+
+ Question whether i-- or --i is better.
+
+ STATUS: Under investigation, postponed until after
+ libpng-1.0.5. About 160 loops will be turned around
+ in libpng-1.0.Nn, for testing.
+
+2. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
+
+ libpng-1.0.5 and earlier transform colors to gamma=1.0 space for
+ merging with background, and then back to the image's gamma. The
+ bit_depth of the intermediate (gamma=1.0) representation is probably
+ not sufficient. In the typical gamma=1/2.2 situation, the linear
+ pixels need about 4 more bits than the gamma-encoded ones, to avoid
+ loss of precision. A similar situation exists with the rgb_to_gray
+ operation.
+
+ STATUS: under development.
+
+3. September 1999 -- ENHANCEMENT --
+
+ It should be possible to use libpng without floating-point aritmetic.
+
+ STATUS: Under investigation, implementation postponed until after
+ libpng-1.0.5. The application interface will change because replacements
+ for the png_set_gAMA(), png_set_cHRM(), and corresponding png_get_()
+ functions will be needed.
+
+4. September 1999 -- BUG [FIXED] --
+
+ Portions of the new MMX code in pngvcrd.c were ifdef'd out because they
+ didn't work properly, but the bug appears to have been found and fixed.
+ As a result, all parts of the code are once again enabled. If you think
+ there's still a problem, you can recompile with one of the following two
+ macros defined and see if the problem goes away:
+
+ DISABLE_PNGVCRD_COMBINE
+ DISABLE_PNGVCRD_INTERLACE
+
+ The second one is in the function where the bug was; as far as we are
+ aware, there was never any bug in the other function. Please notify us
+ if you find any problems in libpng, regardless of whether the two macros
+ make any difference: png-implement@ccrc.wustl.edu
+
+ Again, we believe the MMX code in pngvcrd.c is 100% correct, but it has
+ not yet been tested extensively.
diff --git a/osframework/source/ImageLib/png/libpng.3 b/osframework/source/ImageLib/png/libpng.3
new file mode 100644
index 0000000..49363a5
--- /dev/null
+++ b/osframework/source/ImageLib/png/libpng.3
@@ -0,0 +1,2886 @@
+.TH LIBPNG 3 "October 15, 1999"
+.SH NAME
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5 - October 15, 1999
+.SH SYNOPSIS
+\fI\fB
+
+\fB#include <png.h>\fP
+
+\fI\fB
+
+\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_structp png_create_read_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_structp png_create_write_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
+
+\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_memcpy_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_memset_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fIerror_action\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_destroy_info (png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
+
+\fI\fB
+
+.SH DESCRIPTION
+The
+.I libpng
+library supports encoding, decoding, and various manipulations of
+the Portable Network Graphics (PNG) format image files. It uses the
+.IR zlib(3)
+compression library.
+Following is a copy of the libpng.txt file that accompanies libpng.
+.SH LIBPNG.TXT
+libpng.txt - A description on how to use and modify libpng
+
+ libpng version 1.0.5 - October 15, 1999
+ Updated and distributed by Glenn Randers-Pehrson
+ <randeg@alum.rpi.edu>
+ Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ For conditions of distribution and use, see copyright
+ notice in png.h.
+
+ based on:
+
+ libpng 1.0 beta 6 version 0.96 May 28, 1997
+ Updated and distributed by Andreas Dilger
+ Copyright (c) 1996, 1997 Andreas Dilger
+
+ libpng 1.0 beta 2 - version 0.88 January 26, 1996
+ For conditions of distribution and use, see copyright
+ notice in png.h. Copyright (c) 1995, 1996 Guy Eric
+ Schalnat, Group 42, Inc.
+
+ Updated/rewritten per request in the libpng FAQ
+ Copyright (c) 1995 Frank J. T. Wojcik
+ December 18, 1995 && January 20, 1996
+
+ *
+.SH I. Introduction
+
+This file describes how to use and modify the PNG reference library
+(known as libpng) for your own use. There are five sections to this
+file: introduction, structures, reading, writing, and modification and
+configuration notes for various special platforms. In addition to this
+file, example.c is a good starting point for using the library, as
+it is heavily commented and should include everything most people
+will need. We assume that libpng is already installed; see the
+INSTALL file for instructions on how to install libpng.
+
+Libpng was written as a companion to the PNG specification, as a way
+of reducing the amount of time and effort it takes to support the PNG
+file format in application programs.
+
+The PNG-1.2 specification is available at <http://www.cdrom.com/png>.
+
+The PNG-1.0 specification is available
+as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
+W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
+additional chunks are described in the special-purpose public chunks
+documents at <ftp://ftp.uu.net/graphics/png/documents/>.
+
+Other information
+about PNG, and the latest version of libpng, can be found at the PNG home
+page, <http://www.cdrom.com/pub/png/>.
+
+Most users will not have to modify the library significantly; advanced
+users may want to modify it more. All attempts were made to make it as
+complete as possible, while keeping the code easy to understand.
+Currently, this library only supports C. Support for other languages
+is being considered.
+
+Libpng has been designed to handle multiple sessions at one time,
+to be easily modifiable, to be portable to the vast majority of
+machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
+to use. The ultimate goal of libpng is to promote the acceptance of
+the PNG file format in whatever way possible. While there is still
+work to be done (see the TODO file), libpng should cover the
+majority of the needs of its users.
+
+Libpng uses zlib for its compression and decompression of PNG files.
+Further information about zlib, and the latest version of zlib, can
+be found at the zlib home page, <http://www.cdrom.com/pub/infozip/zlib/>.
+The zlib compression utility is a general purpose utility that is
+useful for more than PNG files, and can be used without libpng.
+See the documentation delivered with zlib for more details.
+You can usually find the source files for the zlib utility wherever you
+find the libpng source files.
+
+Libpng is thread safe, provided the threads are using different
+instances of the structures. Each thread should have its own
+png_struct and png_info instances, and thus its own image.
+Libpng does not protect itself against two threads using the
+same instance of a structure.
+
+
+.SH II. Structures
+
+There are two main structures that are important to libpng, png_struct
+and png_info. The first, png_struct, is an internal structure that
+will not, for the most part, be used by a user except as the first
+variable passed to every libpng function call.
+
+The png_info structure is designed to provide information about the
+PNG file. At one time, the fields of png_info were intended to be
+directly accessible to the user. However, this tended to cause problems
+with applications using dynamically loaded libraries, and as a result
+a set of interface functions for png_info was developed. The fields
+of png_info are still available for older applications, but it is
+suggested that applications use the new interfaces if at all possible.
+
+The png.h header file is an invaluable reference for programming with libpng.
+And while I'm on the topic, make sure you include the libpng header file:
+
+#include <png.h>
+
+.SH III. Reading
+
+Reading PNG files:
+
+We'll now walk you through the possible functions to call when reading
+in a PNG file, briefly explaining the syntax and purpose of each one.
+See example.c and png.h for more detail. While Progressive reading
+is covered in the next section, you will still need some of the
+functions discussed in this section to read a PNG file.
+
+You will want to do the I/O initialization(*) before you get into libpng,
+so if it doesn't work, you don't have much to undo. Of course, you
+will also want to insure that you are, in fact, dealing with a PNG
+file. Libpng provides a simple check to see if a file is a PNG file.
+To use it, pass in the first 1 to 8 bytes of the file, and it will
+return true or false (1 or 0) depending on whether the bytes could be
+part of a PNG file. Of course, the more bytes you pass in, the
+greater the accuracy of the prediction.
+
+If you are intending to keep the file pointer open for use in libpng,
+you must ensure you don't read more than 8 bytes from the beginning
+of the file, and you also have to make a call to png_set_sig_bytes_read()
+with the number of bytes you read from the beginning. Libpng will
+then only check the bytes (if any) that your program didn't read.
+
+(*): If you are not using the standard I/O functions, you will need
+to replace them with custom functions. See the discussion under
+Customizing libpng.
+
+
+ FILE *fp = fopen(file_name, "rb");
+ if (!fp)
+ {
+ return;
+ }
+ fread(header, 1, number, fp);
+ is_png = !png_sig_cmp(header, 0, number);
+ if (!is_png)
+ {
+ return;
+ }
+
+
+Next, png_struct and png_info need to be allocated and initialized. In
+order to ensure that the size of these structures is correct even with a
+dynamically linked libpng, there are functions to initialize and
+allocate the structures. We also pass the library version, optional
+pointers to error handling functions, and a pointer to a data struct for
+use by the error functions, if necessary (the pointer and functions can
+be NULL if the default error handlers are to be used). See the section
+on Changes to Libpng below regarding the old initialization functions.
+
+ png_structp png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return;
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr,
+ (png_infopp)NULL, (png_infopp)NULL);
+ return;
+ }
+
+ png_infop end_info = png_create_info_struct(png_ptr);
+ if (!end_info)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return;
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_read_struct_2() instead of png_create_read_struct():
+
+ png_structp png_ptr = png_create_read_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+The error handling routines passed to png_create_read_struct()
+and the memory alloc/free routines passed to png_create_struct_2()
+are only necessary if you are not using the libpng supplied error
+handling and memory alloc/free functions.
+
+When libpng encounters an error, it expects to longjmp back
+to your routine. Therefore, you will need to call setjmp and pass
+your png_ptr->jmpbuf. If you read the file from different
+routines, you will need to update the jmpbuf field every time you enter
+a new routine that will call a png_ function.
+
+See your documentation of setjmp/longjmp for your compiler for more
+handling in the Customizing Libpng section below for more information on
+the libpng error handling. If an error occurs, and libpng longjmp's
+back to your setjmp, you will want to call png_destroy_read_struct() to
+free any memory.
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+ fclose(fp);
+ return;
+ }
+
+Now you need to set up the input code. The default for libpng is to
+use the C function fread(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. If you wish to handle reading data in another
+way, you need not call the png_init_io() function, but you must then
+implement the libpng I/O methods discussed in the Customizing Libpng
+section below.
+
+ png_init_io(png_ptr, fp);
+
+If you had previously opened the file and read any of the signature from
+the beginning in order to see if this was a PNG file, you need to let
+libpng know that there are some bytes missing from the start of the file.
+
+ png_set_sig_bytes(png_ptr, number);
+
+At this point, you can set up a callback function that will be
+called after each row has been read, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void read_row_callback(png_ptr, png_uint_32 row, int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "read_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_read_status_fn(png_ptr, read_row_callback);
+
+In PNG files, the alpha channel in an image is the level of opacity.
+If you need the alpha channel in an image to be the level of transparency
+instead of opacity, you can invert the alpha channel (or the tRNS chunk
+data) after it's read, so that 0 is fully opaque and 255 (in 8-bit or
+paletted images) or 65535 (in 16-bit images) is fully transparent, with
+
+ png_set_invert_alpha(png_ptr);
+
+This has to appear here rather than later with the other transformations
+because the tRNS chunk data must be modified in the case of paletted images.
+If your image is not a paletted image, the tRNS data (which in such cases
+represents a single color to be rendered as transparent) won't be changed.
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_read_user_transform_fn(png_ptr,
+ read_transform_fn);
+
+You must supply the function
+
+ void read_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+after all of the other transformations have been processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function, and you can inform libpng that your transform
+function will change the number of channels or bit depth with the
+function
+
+ png_set_user_transform_info(png_ptr, user_ptr,
+ user_depth, user_channels);
+
+
+You can retrieve the pointer via the function
+png_get_user_transform_ptr(). For example:
+
+ voidp read_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+You are now ready to read all the file information up to the actual
+image data. You do this with a call to png_read_info().
+
+ png_read_info(png_ptr, info_ptr);
+
+Functions are used to get the information from the info_ptr:
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height,
+ &bit_depth, &color_type, &interlace_type,
+ &compression_type, &filter_type);
+
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels. (valid values are
+ 1, 2, 4, 8, 16 and depend also on
+ the color_type. See also
+ significant bits (sBIT) below).
+ color_type - describes which color/alpha channels
+ are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ filter_type - (must be PNG_FILTER_TYPE_BASE
+ for PNG 1.0)
+ compression_type - (must be PNG_COMPRESSION_TYPE_BASE
+ for PNG 1.0)
+ interlace_type - (PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7)
+ Any or all of interlace_type, compression_type, of
+ filter_type can be
+ NULL if you are not interested in their values.
+
+ channels = png_get_channels(png_ptr, info_ptr);
+ channels - number of channels of info for the
+ color type (valid values are 1 (GRAY,
+ PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
+ 4 (RGB_ALPHA or RGB + filler byte))
+ rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ rowbytes - number of bytes needed to hold a row
+
+ signature = png_get_signature(png_ptr, info_ptr);
+ signature - holds the signature read from the
+ file (if any). The data is kept in
+ the same offset it would be if the
+ whole signature were read (i.e. if an
+ application had already read in 4
+ bytes of signature before starting
+ libpng, the remaining 4 bytes would
+ be in signature[4] through signature[7]
+ (see png_set_sig_bytes())).
+
+
+ width = png_get_image_width(png_ptr,
+ info_ptr);
+ height = png_get_image_height(png_ptr,
+ info_ptr);
+ bit_depth = png_get_bit_depth(png_ptr,
+ info_ptr);
+ color_type = png_get_color_type(png_ptr,
+ info_ptr);
+ filter_type = png_get_filter_type(png_ptr,
+ info_ptr);
+ compression_type = png_get_compression_type(png_ptr,
+ info_ptr);
+ interlace_type = png_get_interlace_type(png_ptr,
+ info_ptr);
+
+
+These are also important, but their validity depends on whether the chunk
+has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
+png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
+data has been read, or zero if it is missing. The parameters to the
+png_get_<chunk> are set directly if they are simple data types, or a pointer
+into the info_ptr is returned for any complex types.
+
+ png_get_PLTE(png_ptr, info_ptr, &palette,
+ &num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_get_gAMA(png_ptr, info_ptr, &gamma);
+ gamma - the gamma the file is written
+ at (PNG_INFO_gAMA)
+
+ png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
+ srgb_intent - the rendering intent (PNG_INFO_sRGB)
+ The presence of the sRGB chunk
+ means that the pixel data is in the
+ sRGB color space. This chunk also
+ implies specific values of gAMA and
+ cHRM.
+
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray,
+ red, green, and blue channels,
+ whichever are appropriate for the
+ given color type (png_color_16)
+
+ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
+ &trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - transparent pixel for non-paletted
+ images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_get_hIST(png_ptr, info_ptr, &hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_color_16)
+
+ png_get_tIME(png_ptr, info_ptr, &mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_get_bKGD(png_ptr, info_ptr, &background);
+ background - background color (PNG_VALID_bKGD)
+
+ num_text = png_get_text(png_ptr, info_ptr, &text_ptr);
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i]->key - keyword for comment.
+ text_ptr[i]->text - text comments for current
+ keyword.
+ text_ptr[i]->compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE
+ or PNG_TEXT_COMPRESSION_zTXt
+ num_text - number of comments
+
+ png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
+ &unit_type);
+ offset_x - positive offset from the left edge
+ of the screen
+ offset_y - positive offset from the top edge
+ of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
+ &unit_type);
+ res_x - pixels/unit physical resolution in
+ x direction
+ res_y - pixels/unit physical resolution in
+ x direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+The data from the pHYs chunk can be retrieved in several convenient
+forms:
+
+ res_x = png_get_x_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_y = png_get_y_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_x_and_y = png_get_pixels_per_meter(png_ptr,
+ info_ptr)
+ aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
+ info_ptr)
+
+ (Each of these returns 0 [signifying "unknown"] if
+ the data is not present or if res_x is 0;
+ res_x_and_y is 0 if res_x != res_y)
+
+For more information, see the png_info definition in png.h and the
+PNG specification for chunk contents. Be careful with trusting
+rowbytes, as some of the transformations could increase the space
+needed to hold a row (expand, filler, gray_to_rgb, etc.).
+See png_read_update_info(), below.
+
+A quick word about text_ptr and num_text. PNG stores comments in
+keyword/text pairs, one pair per chunk, with no limit on the number
+of text chunks, and a 2^31 byte limit on their size. While there are
+suggested keywords, there is no requirement to restrict the use to these
+strings. It is strongly suggested that keywords and text be sensible
+to humans (that's the point), so don't use abbreviations. Non-printing
+symbols are not allowed. See the PNG specification for more details.
+There is also no requirement to have text after the keyword.
+
+Keywords should be limited to 79 Latin-1 characters without leading or
+trailing spaces, but non-consecutive spaces are allowed within the
+keyword. It is possible to have the same keyword any number of times.
+The text_ptr is an array of png_text structures, each holding pointer
+to a keyword and a pointer to a text string. Only the text string may
+be null. The keyword/text pairs are put into the array in the order
+that they are received. However, some or all of the text chunks may be
+after the image, so, to make sure you have read all the text chunks,
+don't mess with these until after you read the stuff after the image.
+This will be mentioned again below in the discussion that goes with
+png_read_end().
+
+After you've read the header information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+The colors used for the background and transparency values should be
+supplied in the same format/depth as the current image data. They
+are stored in the same format/depth as the image data in a bKGD or tRNS
+chunk, so this is what libpng expects for this data. The colors are
+transformed to keep in sync with the image data when an application
+calls the png_read_update_info() routine (see below).
+
+Data will be decoded into the supplied row buffers packed into bytes
+unless the library has been told to transform it into another format.
+For example, 4 bit/pixel paletted or grayscale data will be returned
+2 pixels/byte with the leftmost pixel in the high-order bits of the
+byte, unless png_set_packing() is called. 8-bit RGB data will be stored
+in RGB RGB RGB format unless png_set_filler() is called to insert filler
+bytes, either before or after each RGB triplet. 16-bit RGB data will
+be returned RRGGBB RRGGBB, with the most significant byte of the color
+value first, unless png_set_strip_16() is called to transform it to
+regular RGB RGB triplets, or png_set_filler() is called to insert
+filler bytes, either before or after each RRGGBB triplet. Similarly,
+8-bit or 16-bit grayscale data can be modified with png_set_filler()
+or png_set_strip_16().
+
+The following code transforms grayscale images of less than 8 to 8 bits,
+changes paletted images to RGB, and adds a full alpha channel if there is
+transparency information in a tRNS chunk. This is most useful on
+grayscale images with bit depths of 2 or 4 or if there is a multiple-image
+viewing application that wishes to treat all images in the same way.
+
+ if (color_type == PNG_COLOR_TYPE_PALETTE &&
+ bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
+
+ if (color_type == PNG_COLOR_TYPE_GRAY &&
+ bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
+
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
+
+These three functions are actually aliases for png_set_expand(), added
+in libpng version 1.0.4, with the function names expanded to improve code
+readability. In some future version they may actually do different
+things.
+
+PNG can have files with 16 bits per channel. If you only can handle
+8 bits per channel, this will strip the pixels down to 8 bit.
+
+ if (bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+The png_set_background() function tells libpng to composite images
+with alpha or simple transparency against the supplied background
+color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
+you may use this color, or supply another color more suitable for
+the current display (e.g., the background color from a web page). You
+need to tell libpng whether the color is in the gamma space of the
+display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
+(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
+that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
+know why anyone would use this, but it's here).
+
+If, for some reason, you don't need the alpha channel on an image,
+and you want to remove it rather than combining it with the background
+(but the image author certainly had in mind that you *would* combine
+it with the background, so that's what you should probably do):
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ png_set_strip_alpha(png_ptr);
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit
+files. This code expands to 1 pixel per byte without changing the
+values of the pixels:
+
+ if (bit_depth < 8)
+ png_set_packing(png_ptr);
+
+PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
+stored in a PNG image have been "scaled" or "shifted" up to the next
+higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
+8 bits/sample in the range [0, 255]). However, it is also possible to
+convert the PNG pixel data back to the original bit depth of the image.
+This call reduces the pixels back down to the original bit depth:
+
+ png_color_16p sig_bit;
+
+ if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
+ png_set_shift(png_ptr, sig_bit);
+
+PNG files store 3-color pixels in red, green, blue order. This code
+changes the storage of the pixels to blue, green, red:
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_bgr(png_ptr);
+
+PNG files store RGB pixels packed into 3 bytes. This code expands them
+into 4 bytes for windowing systems that need them in this format:
+
+ if (bit_depth == 8 && color_type ==
+ PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
+ filler, PNG_FILLER_BEFORE);
+
+where "filler" is the 8 or 16-bit number to fill with, and the location is
+either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
+you want the filler before the RGB or after. This transformation
+does not affect images that already have full alpha channels.
+
+If you are reading an image with an alpha channel, and you need the
+data as ARGB instead of the normal PNG format RGBA:
+
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_swap_alpha(png_ptr);
+
+For some uses, you may want a grayscale image to be represented as
+RGB. This code will do that conversion:
+
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_gray_to_rgb(png_ptr);
+
+Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
+with alpha. This is intended for conversion of images that really are
+gray (red == green == blue), so the function simply strips out the red
+and blue channels, leaving the green channel in the gray position.
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_rgb_to_gray(png_ptr, error_action,
+ double red_weight, double green_weight);
+
+ error_action = 1: silently do the conversion
+ error_action = 2: issue a warning if the original
+ image has any pixel where
+ red != green or red != blue
+ error_action = 3: issue an error and abort the
+ conversion if the original
+ image has any pixel where
+ red != green or red != blue
+
+ red_weight: weight of red component
+ (NULL -> default 54/256)
+ green_weight: weight of green component
+ (NULL -> default 183/256)
+
+If you have set error_action = 1 or 2, you can
+later check whether the image really was gray, after processing
+the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
+It will return a png_byte that is zero if the image was gray or
+1 if there were any non-gray pixels. bKGD and sBIT data
+will be silently converted to grayscale, using the green channel
+data, regardless of the error_action setting.
+
+With 0.0<=red_weight+green_weight<=1.0,
+the normalized graylevel is computed:
+
+ int rw = red_weight * 256;
+ int gw = green_weight * 256;
+ int bw = 256 - (rw + gw);
+ gray = (rw*red + gw*green + bw*blue)/256;
+
+The default values approximate those recommended in the Charles
+Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
+Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
+
+ Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
+
+Libpng approximates this with
+
+ Y = 0.211 * R + 0.715 * G + 0.074 * B
+
+which can be expressed with integers as
+
+ Y = (54 * R + 183 * G + 19 * B)/256
+
+The calculation is done in a linear colorspace, if the image gamma
+is known.
+
+If you have a grayscale and you are using png_set_expand_depth() or
+png_set_expand() to change to
+a higher bit-depth, you must either supply the background color as a gray
+value at the original file bit-depth (need_expand = 1) or else supply the
+background color as an RGB triplet at the final, expanded bit depth
+(need_expand = 0). Similarly, if you are reading a paletted image, you
+must either supply the background color as a palette index (need_expand = 1)
+or as an RGB triplet that may or may not be in the palette (need_expand = 0).
+
+ png_color_16 my_background;
+ png_color_16p image_background;
+
+ if (png_get_bKGD(png_ptr, info_ptr, &image_background))
+ png_set_background(png_ptr, image_background,
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ else
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+
+To properly display PNG images on any kind of system, the application needs
+to know what the display gamma is. Ideally, the user will know this, and
+the application will allow them to set it. One method of allowing the user
+to set the display gamma separately for each system is to check for a
+SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
+correctly set.
+
+Note that display_gamma is the overall gamma correction required to produce
+pleasing results, which depends on the lighting conditions in the surrounding
+environment. In a dim or brightly lit room, no compensation other than
+the physical gamma exponent of the monitor is needed, while in a dark room
+a slightly smaller exponent is better.
+
+ double gamma, screen_gamma;
+
+ if (/* We have a user-defined screen
+ gamma value */)
+ {
+ screen_gamma = user_defined_screen_gamma;
+ }
+ /* One way that applications can share the same
+ screen gamma value */
+ else if ((gamma_str = getenv("SCREEN_GAMMA"))
+ != NULL)
+ {
+ screen_gamma = (double)atof(gamma_str);
+ }
+ /* If we don't have another value */
+ else
+ {
+ screen_gamma = 2.2; /* A good guess for a
+ PC monitor in a bright office or a dim room */
+ screen_gamma = 2.0; /* A good guess for a
+ PC monitor in a dark room */
+ screen_gamma = 1.7 or 1.0; /* A good
+ guess for Mac systems */
+ }
+
+The png_set_gamma() function handles gamma transformations of the data.
+Pass both the file gamma and the current screen_gamma. If the file does
+not have a gamma value, you can pass one anyway if you have an idea what
+it is (usually 0.45455 is a good guess for GIF images on PCs). Note
+that file gammas are inverted from screen gammas. See the discussions
+on gamma in the PNG specification for an excellent description of what
+gamma is, and why all applications should support it. It is strongly
+recommended that PNG viewers support gamma correction.
+
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma))
+ png_set_gamma(png_ptr, screen_gamma, gamma);
+ else
+ png_set_gamma(png_ptr, screen_gamma, 0.45455);
+
+If you need to reduce an RGB file to a paletted file, or if a paletted
+file has more entries then will fit on your screen, png_set_dither()
+will do that. Note that this is a simple match dither that merely
+finds the closest color available. This should work fairly well with
+optimized palettes, and fairly badly with linear color cubes. If you
+pass a palette that is larger then maximum_colors, the file will
+reduce the number of colors in the palette so it will fit into
+maximum_colors. If there is a histogram, it will use it to make
+more intelligent choices when reducing the palette. If there is no
+histogram, it may not do as good a job.
+
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_PLTE))
+ {
+ png_color_16p histogram;
+
+ png_get_hIST(png_ptr, info_ptr,
+ &histogram);
+ png_set_dither(png_ptr, palette, num_palette,
+ max_screen_colors, histogram, 1);
+ }
+ else
+ {
+ png_color std_color_cube[MAX_SCREEN_COLORS] =
+ { ... colors ... };
+
+ png_set_dither(png_ptr, std_color_cube,
+ MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
+ NULL,0);
+ }
+ }
+
+PNG files describe monochrome as black being zero and white being one.
+The following code will reverse this (make black be one and white be
+zero):
+
+ if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
+ png_set_invert_mono(png_ptr);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code changes the storage to the
+other way (little-endian, i.e. least significant bits first, the
+way PCs store them):
+
+ if (bit_depth == 16)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+The last thing to handle is interlacing; this is covered in detail below,
+but you must call the function here if you want libpng to handle expansion
+of the interlaced image.
+
+ number_of_passes = png_set_interlace_handling(png_ptr);
+
+After setting the transformations, libpng can update your png_info
+structure to reflect any transformations you've requested with this
+call. This is most useful to update the info structure's rowbytes
+field so you can use it to allocate your image memory. This function
+will also update your palette with the correct screen_gamma and
+background if these have been given with the calls above.
+
+ png_read_update_info(png_ptr, info_ptr);
+
+After you call png_read_update_info(), you can allocate any
+memory you need to hold the image. The row data is simply
+raw byte data for all forms of images. As the actual allocation
+varies among applications, no example will be given. If you
+are allocating one large chunk, you will need to build an
+array of pointers to each row, as it will be needed for some
+of the functions below.
+
+After you've allocated memory, you can read the image data.
+The simplest way to do this is in one function call. If you are
+allocating enough memory to hold the whole image, you can just
+call png_read_image() and libpng will read in all the image data
+and put it in the memory area supplied. You will need to pass in
+an array of pointers to each row.
+
+This function automatically handles interlacing, so you don't need
+to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_read_rows().
+
+ png_read_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_bytep row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to read in the whole image at once, you can
+use png_read_rows() instead. If there is no interlacing (check
+interlace_type == PNG_INTERLACE_NONE), this is simple:
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+where row_pointers is the same as in the png_read_image() call.
+
+If you are doing this just one row at a time, you can do this with
+row_pointers:
+
+ png_bytep row_pointers = row;
+ png_read_row(png_ptr, &row_pointers, NULL);
+
+If the file is interlaced (info_ptr->interlace_type != 0), things get
+somewhat harder. The only current (PNG Specification version 1.2)
+interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
+is a somewhat complicated 2D interlace scheme, known as Adam7, that
+breaks down an image into seven smaller images of varying size, based
+on an 8x8 grid.
+
+libpng can fill out those images or it can give them to you "as is".
+If you want them filled out, there are two ways to do that. The one
+mentioned in the PNG specification is to expand each pixel to cover
+those pixels that have not been read yet (the "rectangle" method).
+This results in a blocky image for the first pass, which gradually
+smooths out as more pixels are read. The other method is the "sparkle"
+method, where pixels are drawn only in their final locations, with the
+rest of the image remaining whatever colors they were initialized to
+before the start of the read. The first method usually looks better,
+but tends to be slower, as there are more pixels to put in the rows.
+
+If you don't want libpng to handle the interlacing details, just call
+png_read_rows() seven times to read in all seven images. Each of the
+images is a valid image by itself, or they can all be combined on an
+8x8 grid to form a single image (although if you intend to combine them
+you would be far better off using the libpng interlace handling).
+
+The first pass will return an image 1/8 as wide as the entire image
+(every 8th column starting in column 0) and 1/8 as high as the original
+(every 8th row starting in row 0), the second will be 1/8 as wide
+(starting in column 4) and 1/8 as high (also starting in row 0). The
+third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
+1/8 as high (every 8th row starting in row 4), and the fourth pass will
+be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
+and every 4th row starting in row 0). The fifth pass will return an
+image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
+while the sixth pass will be 1/2 as wide and 1/2 as high as the original
+(starting in column 1 and row 0). The seventh and final pass will be as
+wide as the original, and 1/2 as high, containing all of the odd
+numbered scanlines. Phew!
+
+If you want libpng to expand the images, call this before calling
+png_start_read_image() or png_read_update_info():
+
+ if (interlace_type == PNG_INTERLACE_ADAM7)
+ number_of_passes
+ = png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+This function can be called even if the file is not interlaced,
+where it will return one pass.
+
+If you are not going to display the image after each pass, but are
+going to wait until the entire image is read in, use the sparkle
+effect. This effect is faster and the end result of either method
+is exactly the same. If you are planning on displaying the image
+after each pass, the "rectangle" effect is generally considered the
+better looking one.
+
+If you only want the "sparkle" effect, just call png_read_rows() as
+normal, with the third parameter NULL. Make sure you make pass over
+the image number_of_passes times, and you don't change the data in the
+rows between calls. You can change the locations of the data, just
+not the data. Each pass only writes the pixels appropriate for that
+pass, and assumes the data from previous passes is still valid.
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+If you only want the first effect (the rectangles), do the same as
+before except pass the row buffer in the third parameter, and leave
+the second parameter NULL.
+
+ png_read_rows(png_ptr, NULL, row_pointers,
+ number_of_rows);
+
+After you are finished reading the image, you can finish reading
+the file. If you are interested in comments or time, which may be
+stored either before or after the image data, you should pass the
+separate png_info struct if you want to keep the comments from
+before and after the image separate. If you are not interested, you
+can pass NULL.
+
+ png_read_end(png_ptr, end_info);
+
+When you are done, you can free all memory allocated by libpng like this:
+
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+
+For a more compact example of reading a PNG image, see the file example.c.
+
+
+Reading PNG files progressively:
+
+The progressive reader is slightly different then the non-progressive
+reader. Instead of calling png_read_info(), png_read_rows(), and
+png_read_end(), you make one call to png_process_data(), which calls
+callbacks when it has the info, a row, or the end of the image. You
+set up these callbacks with png_set_progressive_read_fn(). You don't
+have to worry about the input/output functions of libpng, as you are
+giving the library the data directly in png_process_data(). I will
+assume that you have read the section on reading PNG files above,
+so I will only highlight the differences (although I will show
+all of the code).
+
+png_structp png_ptr;
+png_infop info_ptr;
+
+ /* An example code fragment of how you would
+ initialize the progressive reader in your
+ application. */
+ int
+ initialize_png_reader()
+ {
+ png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return -1;
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ /* This one's new. You can provide functions
+ to be called when the header info is valid,
+ when each row is completed, and when the image
+ is finished. If you aren't using all functions,
+ you can specify NULL parameters. Even when all
+ three functions are NULL, you need to call
+ png_set_progressive_read_fn(). You can use
+ any struct as the user_ptr (cast to a void pointer
+ for the function call), and retrieve the pointer
+ from inside the callbacks using the function
+
+ png_get_progressive_ptr(png_ptr);
+
+ which will return a void pointer, which you have
+ to cast appropriately.
+ */
+ png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
+ info_callback, row_callback, end_callback);
+
+ return 0;
+ }
+
+ /* A code fragment that you call as you receive blocks
+ of data */
+ int
+ process_data(png_bytep buffer, png_uint_32 length)
+ {
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ /* This one's new also. Simply give it a chunk
+ of data from the file stream (in order, of
+ course). On machines with segmented memory
+ models 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, I haven't tried less then 256 bytes
+ yet). When this function returns, you may
+ want to display any rows that were generated
+ in the row callback if you don't already do
+ so there.
+ */
+ png_process_data(png_ptr, info_ptr, buffer, length);
+ return 0;
+ }
+
+ /* This function is called (as set by
+ png_set_progressive_read_fn() above) when enough data
+ has been supplied so all of the header has been
+ read.
+ */
+ 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.
+ */
+ }
+
+ /* This function is called when each row of image
+ data is complete */
+ void
+ row_callback(png_structp png_ptr, png_bytep new_row,
+ png_uint_32 row_num, int pass)
+ {
+ /* If the image is interlaced, and you turned
+ on the interlace handler, this function will
+ be called for every row in every pass. Some
+ of these rows will not be changed from the
+ previous pass. When the row is not changed,
+ the new_row variable will be NULL. The rows
+ and passes are called in order, so you don't
+ really need the row_num and pass, but I'm
+ supplying them because it may make your life
+ easier.
+
+ For the non-NULL rows of interlaced images,
+ you must call png_progressive_combine_row()
+ passing in the row and the old row. You can
+ call this function for NULL rows (it will just
+ return) and for non-interlaced images (it just
+ does the memcpy for you) if it will make the
+ code easier. Thus, you can just do this for
+ all cases:
+ */
+
+ png_progressive_combine_row(png_ptr, old_row,
+ new_row);
+
+ /* where old_row is what was displayed for
+ previously for the row. 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 after 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.
+ */
+ }
+
+
+
+.SH IV. Writing
+
+Much of this is very similar to reading. However, everything of
+importance is repeated here, so you won't have to constantly look
+back up in the reading section to understand writing.
+
+You will want to do the I/O initialization before you get into libpng,
+so if it doesn't work, you don't have anything to undo. If you are not
+using the standard I/O functions, you will need to replace them with
+custom writing functions. See the discussion under Customizing libpng.
+
+ FILE *fp = fopen(file_name, "wb");
+ if (!fp)
+ {
+ return;
+ }
+
+Next, png_struct and png_info need to be allocated and initialized.
+As these can be both relatively large, you may not want to store these
+on the stack, unless you have stack space to spare. Of course, you
+will want to check if they return NULL. If you are also reading,
+you won't want to name your read structure and your write structure
+both "png_ptr"; you can call them anything you like, such as
+"read_ptr" and "write_ptr". Look at pngtest.c, for example.
+
+ png_structp png_ptr = png_create_write_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return;
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_write_struct(&png_ptr,
+ (png_infopp)NULL);
+ return;
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_write_struct_2() instead of png_create_read_struct():
+
+ png_structp png_ptr = png_create_write_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+After you have these structures, you will need to set up the
+error handling. When libpng encounters an error, it expects to
+longjmp() back to your routine. Therefore, you will need to call
+setjmp() and pass the png_ptr->jmpbuf. If you
+write the file from different routines, you will need to update
+the jmpbuf field every time you enter a new routine that will
+call a png_ function. See your documentation of setjmp/longjmp
+for your compiler for more information on setjmp/longjmp. See
+the discussion on libpng error handling in the Customizing Libpng
+section below for more information on the libpng error handling.
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ fclose(fp);
+ return;
+ }
+ ...
+ return;
+
+Now you need to set up the output code. The default for libpng is to
+use the C function fwrite(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. Again, if you wish to handle writing data in
+another way, see the discussion on libpng I/O handling in the Customizing
+Libpng section below.
+
+ png_init_io(png_ptr, fp);
+
+At this point, you can set up a callback function that will be
+called after each row has been written, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void write_row_callback(png_ptr, png_uint_32 row, int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "write_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_write_status_fn(png_ptr, write_row_callback);
+
+You now have the option of modifying how the compression library will
+run. The following functions are mainly for testing, but may be useful
+in some cases, like if you need to write PNG files extremely fast and
+are willing to give up some compression, or if you want to get the
+maximum possible compression at the expense of slower writing. If you
+have no special needs in this area, let the library do what it wants by
+not calling this function at all, as it has been tuned to deliver a good
+speed/compression ratio. The second parameter to png_set_filter() is
+the filter method, for which the only valid value is '0' (as of the
+July 1999 PNG specification, version 1.2). The third parameter is a
+flag that indicates which filter type(s) are to be tested for each
+scanline. See the Compression Library for details on the specific filter
+types.
+
+
+ /* turn on or off filtering, and/or choose
+ specific filters */
+ png_set_filter(png_ptr, 0,
+ PNG_FILTER_NONE | PNG_FILTER_SUB |
+ PNG_FILTER_PAETH);
+
+The png_set_compression_???() functions interface to the zlib compression
+library, and should mostly be ignored unless you really know what you are
+doing. The only generally useful call is png_set_compression_level()
+which changes how much time zlib spends on trying to compress the image
+data. See the Compression Library for details on the compression levels.
+
+ /* set the zlib compression level */
+ png_set_compression_level(png_ptr,
+ Z_BEST_COMPRESSION);
+
+ /* set other zlib parameters */
+ png_set_compression_mem_level(png_ptr, 8);
+ png_set_compression_strategy(png_ptr,
+ Z_DEFAULT_STRATEGY);
+ png_set_compression_window_bits(png_ptr, 15);
+ png_set_compression_method(png_ptr, 8);
+
+You now need to fill in the png_info structure with all the data you
+wish to write before the actual image. Note that the only thing you
+are allowed to write after the image is the text chunks and the time
+chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
+the latest PNG specification for more information on that. If you
+wish to write them before the image, fill them in now, and flag that
+data as being valid. If you want to wait until after the data, don't
+fill them until png_write_end(). For all the fields in png_info and
+their data types, see png.h. For explanations of what the fields
+contain, see the PNG specification.
+
+Some of the more important parts of the png_info are:
+
+ png_set_IHDR(png_ptr, info_ptr, width, height,
+ bit_depth, color_type, interlace_type,
+ compression_type, filter_type)
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels.
+ (valid values are 1, 2, 4, 8, 16
+ and depend also on the
+ color_type. See also significant
+ bits (sBIT) below).
+ color_type - describes which color/alpha
+ channels are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ interlace_type - PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7
+ compression_type - (must be
+ PNG_COMPRESSION_TYPE_DEFAULT)
+ filter_type - (must be PNG_FILTER_TYPE_DEFAULT)
+
+ png_set_PLTE(png_ptr, info_ptr, palette,
+ num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_set_gAMA(png_ptr, info_ptr, gamma);
+ gamma - the gamma the image was created
+ at (PNG_INFO_gAMA)
+
+ png_set_sRGB(png_ptr, info_ptr, srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of
+ the sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This chunk also implies specific
+ values of gAMA and cHRM. Rendering
+ intent is the CSS-1 property that
+ has been defined by the International
+ Color Consortium
+ (http://www.color.org).
+ It can be one of
+ PNG_SRGB_INTENT_SATURATION,
+ PNG_SRGB_INTENT_PERCEPTUAL,
+ PNG_SRGB_INTENT_ABSOLUTE, or
+ PNG_SRGB_INTENT_RELATIVE.
+
+
+ png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
+ srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of the
+ sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This function also causes gAMA and
+ cHRM chunks with the specific values
+ that are consistent with sRGB to be
+ written.
+
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray, red,
+ green, and blue channels, whichever are
+ appropriate for the given color type
+ (png_color_16)
+
+ png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
+ trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - transparent pixel for non-paletted
+ images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_set_hIST(png_ptr, info_ptr, hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_color_16)
+
+ png_set_tIME(png_ptr, info_ptr, mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_set_bKGD(png_ptr, info_ptr, background);
+ background - background color (PNG_VALID_bKGD)
+
+ png_set_text(png_ptr, info_ptr, text_ptr, num_text);
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i]->key - keyword for comment.
+ text_ptr[i]->text - text comments for current
+ keyword.
+ text_ptr[i]->compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE or
+ PNG_TEXT_COMPRESSION_zTXt
+ num_text - number of comments in text_ptr
+
+ png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
+ unit_type);
+ offset_x - positive offset from the left
+ edge of the screen
+ offset_y - positive offset from the top
+ edge of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
+ unit_type);
+ res_x - pixels/unit physical resolution
+ in x direction
+ res_y - pixels/unit physical resolution
+ in y direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+In PNG files, the alpha channel in an image is the level of opacity.
+If your data is supplied as a level of transparency, you can invert the
+alpha channel before you write it, so that 0 is fully transparent and 255
+(in 8-bit or paletted images) or 65535 (in 16-bit images) is fully opaque,
+with
+
+ png_set_invert_alpha(png_ptr);
+
+This must appear here instead of later with the other transformations
+because in the case of paletted images the tRNS chunk data has to
+be inverted before the tRNS chunk is written. If your image is not a
+paletted image, the tRNS data (which in such cases represents a single
+color to be rendered as transparent) won't be changed.
+
+A quick word about text and num_text. text is an array of png_text
+structures. num_text is the number of valid structures in the array.
+If you want, you can use max_text to hold the size of the array, but
+libpng ignores it for writing (it does use it for reading). Each
+png_text structure holds a keyword-text value, and a compression type.
+The compression types have the same valid numbers as the compression
+types of the image data. Currently, the only valid number is zero.
+However, you can store text either compressed or uncompressed, unlike
+images, which always have to be compressed. So if you don't want the
+text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
+Until text gets around 1000 bytes, it is not worth compressing it.
+After the text has been written out to the file, the compression type
+is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
+so that it isn't written out again at the end (in case you are calling
+png_write_end() with the same struct.
+
+The keywords that are given in the PNG Specification are:
+
+ Title Short (one line) title or
+ caption for image
+ Author Name of image's creator
+ Description Description of image (possibly long)
+ Copyright Copyright notice
+ Creation Time Time of original image creation
+ (usually RFC 1123 format, see below)
+ Software Software used to create the image
+ Disclaimer Legal disclaimer
+ Warning Warning of nature of content
+ Source Device used to create the image
+ Comment Miscellaneous comment; conversion
+ from other image format
+
+The keyword-text pairs work like this. Keywords should be short
+simple descriptions of what the comment is about. Some typical
+keywords are found in the PNG specification, as is some recommendations
+on keywords. You can repeat keywords in a file. You can even write
+some text before the image and some after. For example, you may want
+to put a description of the image before the image, but leave the
+disclaimer until after, so viewers working over modem connections
+don't have to wait for the disclaimer to go over the modem before
+they start seeing the image. Finally, keywords should be full
+words, not abbreviations. Keywords and text are in the ISO 8859-1
+(Latin-1) character set (a superset of regular ASCII) and can not
+contain NUL characters, and should not contain control or other
+unprintable characters. To make the comments widely readable, stick
+with basic ASCII, and avoid machine specific character set extensions
+like the IBM-PC character set. The keyword must be present, but
+you can leave off the text string on non-compressed pairs.
+Compressed pairs must have a text string, as only the text string
+is compressed anyway, so the compression would be meaningless.
+
+PNG supports modification time via the png_time structure. Two
+conversion routines are proved, png_convert_from_time_t() for
+time_t and png_convert_from_struct_tm() for struct tm. The
+time_t routine uses gmtime(). You don't have to use either of
+these, but if you wish to fill in the png_time structure directly,
+you should provide the time in universal time (GMT) if possible
+instead of your local time. Note that the year number is the full
+year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
+that months start with 1.
+
+If you want to store the time of the original image creation, you should
+use a plain tEXt chunk with the "Creation Time" keyword. This is
+necessary because the "creation time" of a PNG image is somewhat vague,
+depending on whether you mean the PNG file, the time the image was
+created in a non-PNG format, a still photo from which the image was
+scanned, or possibly the subject matter itself. In order to facilitate
+machine-readable dates, it is recommended that the "Creation Time"
+tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
+although this isn't a requirement. Unlike the tIME chunk, the
+"Creation Time" tEXt chunk is not expected to be automatically changed
+by the software. To facilitate the use of RFC 1123 dates, a function
+png_convert_to_rfc1123(png_timep) is provided to convert from PNG
+time to an RFC 1123 format string.
+
+You are now ready to write all the file information up to the actual
+image data. You do this with a call to png_write_info().
+
+ png_write_info(png_ptr, info_ptr);
+
+After you've written the file information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
+the library to expand the input data to 4 or 8 bytes per pixel
+(or expand 1 or 2-byte grayscale data to 2 or 4 bytes per pixel).
+
+ png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
+
+where the 0 is the value that will be put in the 4th byte, and the
+location is either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending
+upon whether the filler byte is stored XRGB or RGBX.
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit files.
+If the data is supplied at 1 pixel per byte, use this code, which will
+correctly pack the pixels into a single byte:
+
+ png_set_packing(png_ptr);
+
+PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
+data is of another bit depth, you can write an sBIT chunk into the
+file so that decoders can get the original data if desired.
+
+ /* Set the true bit depth of the image data */
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ sig_bit.red = true_bit_depth;
+ sig_bit.green = true_bit_depth;
+ sig_bit.blue = true_bit_depth;
+ }
+ else
+ {
+ sig_bit.gray = true_bit_depth;
+ }
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ sig_bit.alpha = true_bit_depth;
+ }
+
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+
+If the data is stored in the row buffer in a bit depth other than
+one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
+this will scale the values to appear to be the correct bit depth as
+is required by PNG.
+
+ png_set_shift(png_ptr, &sig_bit);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code would be used if they are
+supplied the other way (little-endian, i.e. least significant bits
+first, the way PCs store them):
+
+ if (bit_depth > 8)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+PNG files store 3 color pixels in red, green, blue order. This code
+would be used if they are supplied as blue, green, red:
+
+ png_set_bgr(png_ptr);
+
+PNG files describe monochrome as black being zero and white being
+one. This code would be used if the pixels are supplied with this reversed
+(black being one and white being zero):
+
+ png_set_invert_mono(png_ptr);
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_write_user_transform_fn(png_ptr,
+ write_transform_fn);
+
+You must supply the function
+
+ void write_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+before any of the other transformations are processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function.
+
+ png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
+
+The user_channels and user_depth parameters of this function are ignored
+when writing; you can set them to zero as shown.
+
+You can retrieve the pointer via the function
+png_get_user_transform_ptr(). For example:
+
+ voidp write_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+It is possible to have libpng flush any pending output, either manually,
+or automatically after a certain number of lines have been written. To
+flush the output stream a single time call:
+
+ png_write_flush(png_ptr);
+
+and to have libpng flush the output stream periodically after a certain
+number of scanlines have been written, call:
+
+ png_set_flush(png_ptr, nrows);
+
+Note that the distance between rows is from the last time png_write_flush()
+was called, or the first row of the image if it has never been called.
+So if you write 50 lines, and then png_set_flush 25, it will flush the
+output on the next scanline, and every 25 lines thereafter, unless
+png_write_flush() is called before 25 more lines have been written.
+If nrows is too small (less than about 10 lines for a 640 pixel wide
+RGB image) the image compression may decrease noticeably (although this
+may be acceptable for real-time applications). Infrequent flushing will
+only degrade the compression performance by a few percent over images
+that do not use flushing.
+
+That's it for the transformations. Now you can write the image data.
+The simplest way to do this is in one function call. If have the
+whole image in memory, you can just call png_write_image() and libpng
+will write the image. You will need to pass in an array of pointers to
+each row. This function automatically handles interlacing, so you don't
+need to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_write_rows().
+
+ png_write_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_byte *row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to write the whole image at once, you can
+use png_write_rows() instead. If the file is not interlaced,
+this is simple:
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+row_pointers is the same as in the png_write_image() call.
+
+If you are just writing one row at a time, you can do this with
+row_pointers:
+
+ png_bytep row_pointer = row;
+
+ png_write_row(png_ptr, &row_pointer);
+
+When the file is interlaced, things can get a good deal more
+complicated. The only currently (as of August 1999 -- PNG Specification
+version 1.2, dated July 1999) defined interlacing scheme for PNG files
+is the "Adam7" interlace scheme, that breaks down an
+image into seven smaller images of varying size. libpng will build
+these images for you, or you can do them yourself. If you want to
+build them yourself, see the PNG specification for details of which
+pixels to write when.
+
+If you don't want libpng to handle the interlacing details, just
+use png_set_interlace_handling() and call png_write_rows() the
+correct number of times to write all seven sub-images.
+
+If you want libpng to build the sub-images, call this before you start
+writing any rows:
+
+ number_of_passes =
+ png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+
+Then write the complete image number_of_passes times.
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+As some of these rows are not used, and thus return immediately,
+you may want to read about interlacing in the PNG specification,
+and only update the rows that are actually used.
+
+After you are finished writing the image, you should finish writing
+the file. If you are interested in writing comments or time, you should
+pass an appropriately filled png_info pointer. If you are not interested,
+you can pass NULL.
+
+ png_write_end(png_ptr, info_ptr);
+
+When you are done, you can free all memory used by libpng like this:
+
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+You must free any data you allocated for info_ptr, such as comments,
+palette, or histogram, before the call to png_destroy_write_struct();
+
+For a more compact example of writing a PNG image, see the file example.c.
+
+.SH V. Modifying/Customizing libpng:
+
+There are two issues here. The first is changing how libpng does
+standard things like memory allocation, input/output, and error handling.
+The second deals with more complicated things like adding new chunks,
+adding new transformations, and generally changing how libpng works.
+
+All of the memory allocation, input/output, and error handling in libpng
+goes through callbacks that are user settable. The default routines are
+in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
+these functions, call the appropriate png_set_???_fn() function.
+
+Memory allocation is done through the functions png_large_malloc(),
+png_malloc(), png_realloc(), png_large_free(), and png_free(). These
+currently just call the standard C functions. The large functions must
+handle exactly 64K, but they don't have to handle more than that. If
+your pointers can't access more then 64K at a time, you will want to set
+MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
+memory allocation on a platform will change between applications, these
+functions must be modified in the library at compile time.
+
+Input/Output in libpng is done through png_read() and png_write(),
+which currently just call fread() and fwrite(). The FILE * is stored in
+png_struct and is initialized via png_init_io(). If you wish to change
+the method of I/O, the library supplies callbacks that you can set
+through the function png_set_read_fn() and png_set_write_fn() at run
+time, instead of calling the png_init_io() function.
+These functions
+also provide a void pointer that can be retrieved via the function
+png_get_io_ptr(). For example:
+
+ png_set_read_fn(png_structp read_ptr,
+ voidp read_io_ptr, png_rw_ptr read_data_fn)
+
+ png_set_write_fn(png_structp write_ptr,
+ voidp write_io_ptr, png_rw_ptr write_data_fn,
+ png_flush_ptr output_flush_fn);
+
+ voidp read_io_ptr = png_get_io_ptr(read_ptr);
+ voidp write_io_ptr = png_get_io_ptr(write_ptr);
+
+The replacement I/O functions should have prototypes as follows:
+
+ void user_read_data(png_structp png_ptr,
+ png_bytep data, png_uint_32 length);
+ void user_write_data(png_structp png_ptr,
+ png_bytep data, png_uint_32 length);
+ void user_flush_data(png_structp png_ptr);
+
+Supplying NULL for the read, write, or flush functions sets them back
+to using the default C stream functions. It is an error to read from
+a write stream, and vice versa.
+
+Error handling in libpng is done through png_error() and png_warning().
+Errors handled through png_error() are fatal, meaning that png_error()
+should never return to its caller. Currently, this is handled via
+setjmp() and longjmp(), but you could change this to do things like
+exit() if you should wish. On non-fatal errors, png_warning() is called
+to print a warning message, and then control returns to the calling code.
+By default png_error() and png_warning() print a message on stderr via
+fprintf() unless the library is compiled with PNG_NO_STDIO defined. If
+you wish to change the behavior of the error functions, you will need to
+set up your own message callbacks. These functions are normally supplied
+at the time that the png_struct is created. It is also possible to change
+these functions after png_create_???_struct() has been called by calling:
+
+ png_set_error_fn(png_structp png_ptr,
+ png_voidp error_ptr, png_error_ptr error_fn,
+ png_error_ptr warning_fn);
+
+ png_voidp error_ptr = png_get_error_ptr(png_ptr);
+
+If NULL is supplied for either error_fn or warning_fn, then the libpng
+default function will be used, calling fprintf() and/or longjmp() if a
+problem is encountered. The replacement error functions should have
+parameters as follows:
+
+ void user_error_fn(png_structp png_ptr,
+ png_const_charp error_msg);
+ void user_warning_fn(png_structp png_ptr,
+ png_const_charp warning_msg);
+
+The motivation behind using setjmp() and longjmp() is the C++ throw and
+catch exception handling methods. This makes the code much easier to write,
+as there is no need to check every return code of every function call.
+However, there are some uncertainties about the status of local variables
+after a longjmp, so the user may want to be careful about doing anything after
+setjmp returns non-zero besides returning itself. Consult your compiler
+documentation for more details.
+
+If you need to read or write custom chunks, you will need to get deeper
+into the libpng code, as a mechanism has not yet been supplied for user
+callbacks with custom chunks. First, read the PNG specification, and have
+a first level of understanding of how it works. Pay particular attention
+to the sections that describe chunk names, and look at how other chunks
+were designed, so you can do things similarly. Second, check out the
+sections of libpng that read and write chunks. Try to find a chunk that
+is similar to yours and copy off of it. More details can be found in the
+comments inside the code. A way of handling unknown chunks in a generic
+method, potentially via callback functions, would be best.
+
+If you wish to write your own transformation for the data, look through
+the part of the code that does the transformations, and check out some of
+the simpler ones to get an idea of how they work. Try to find a similar
+transformation to the one you want to add and copy off of it. More details
+can be found in the comments inside the code itself.
+
+Configuring for 16 bit platforms:
+
+You may need to change the png_large_malloc() and png_large_free()
+routines in pngmem.c, as these are required to allocate 64K, although
+there is already support for many of the common DOS compilers. Also,
+you will want to look into zconf.h to tell zlib (and thus libpng) that
+it cannot allocate more then 64K at a time. Even if you can, the memory
+won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
+
+Configuring for DOS:
+
+For DOS users who only have access to the lower 640K, you will
+have to limit zlib's memory usage via a png_set_compression_mem_level()
+call. See zlib.h or zconf.h in the zlib library for more information.
+
+Configuring for Medium Model:
+
+Libpng's support for medium model has been tested on most of the popular
+compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
+defined, and FAR gets defined to far in pngconf.h, and you should be
+all set. Everything in the library (except for zlib's structure) is
+expecting far data. You must use the typedefs with the p or pp on
+the end for pointers (or at least look at them and be careful). Make
+note that the row's of data are defined as png_bytepp, which is an
+unsigned char far * far *.
+
+Configuring for gui/windowing platforms:
+
+You will need to write new error and warning functions that use the GUI
+interface, as described previously, and set them to be the error and
+warning functions at the time that png_create_???_struct() is called,
+in order to have them available during the structure initialization.
+They can be changed later via png_set_error_fn(). On some compilers,
+you may also have to change the memory allocators (png_malloc, etc.).
+
+Configuring for compiler xxx:
+
+All includes for libpng are in pngconf.h. If you need to add/change/delete
+an include, this is the place to do it. The includes that are not
+needed outside libpng are protected by the PNG_INTERNAL definition,
+which is only defined for those routines inside libpng itself. The
+files in libpng proper only include png.h, which includes pngconf.h.
+
+Configuring zlib:
+
+There are special functions to configure the compression. Perhaps the
+most useful one changes the compression level, which currently uses
+input compression values in the range 0 - 9. The library normally
+uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
+have shown that for a large majority of images, compression values in
+the range 3-6 compress nearly as well as higher levels, and do so much
+faster. For online applications it may be desirable to have maximum speed
+(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
+specify no compression (Z_NO_COMPRESSION = 0), but this would create
+files larger than just storing the raw bitmap. You can specify the
+compression level by calling:
+
+ png_set_compression_level(png_ptr, level);
+
+Another useful one is to reduce the memory level used by the library.
+The memory level defaults to 8, but it can be lowered if you are
+short on memory (running DOS, for example, where you only have 640K).
+
+ png_set_compression_mem_level(png_ptr, level);
+
+The other functions are for configuring zlib. They are not recommended
+for normal use and may result in writing an invalid PNG file. See
+zlib.h for more information on what these mean.
+
+ png_set_compression_strategy(png_ptr,
+ strategy);
+ png_set_compression_window_bits(png_ptr,
+ window_bits);
+ png_set_compression_method(png_ptr, method);
+
+Controlling row filtering:
+
+If you want to control whether libpng uses filtering or not, which
+filters are used, and how it goes about picking row filters, you
+can call one of these functions. The selection and configuration
+of row filters can have a significant impact on the size and
+encoding speed and a somewhat lesser impact on the decoding speed
+of an image. Filtering is enabled by default for RGB and grayscale
+images (with and without alpha), but not for paletted images nor
+for any images with bit depths less than 8 bits/pixel.
+
+The 'method' parameter sets the main filtering method, which is
+currently only '0' in the PNG 1.2 specification. The 'filters'
+parameter sets which filter(s), if any, should be used for each
+scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
+to turn filtering on and off, respectively.
+
+Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
+PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
+ORed together '|' to specify one or more filters to use. These
+filters are described in more detail in the PNG specification. If
+you intend to change the filter type during the course of writing
+the image, you should start with flags set for all of the filters
+you intend to use so that libpng can initialize its internal
+structures appropriately for all of the filter types.
+
+ filters = PNG_FILTER_NONE | PNG_FILTER_SUB
+ | PNG_FILTER_UP;
+ png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
+ filters);
+
+It is also possible to influence how libpng chooses from among the
+available filters. This is done in two ways - by telling it how
+important it is to keep the same filter for successive rows, and
+by telling it the relative computational costs of the filters.
+
+ double weights[3] = {1.5, 1.3, 1.1},
+ costs[PNG_FILTER_VALUE_LAST] =
+ {1.0, 1.3, 1.3, 1.5, 1.7};
+
+ png_set_filter_selection(png_ptr,
+ PNG_FILTER_SELECTION_WEIGHTED, 3,
+ weights, costs);
+
+The weights are multiplying factors that indicate to libpng that the
+row filter should be the same for successive rows unless another row filter
+is that many times better than the previous filter. In the above example,
+if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
+"sum of absolute differences" 1.5 x 1.3 times higher than other filters
+and still be chosen, while the NONE filter could have a sum 1.1 times
+higher than other filters and still be chosen. Unspecified weights are
+taken to be 1.0, and the specified weights should probably be declining
+like those above in order to emphasize recent filters over older filters.
+
+The filter costs specify for each filter type a relative decoding cost
+to be considered when selecting row filters. This means that filters
+with higher costs are less likely to be chosen over filters with lower
+costs, unless their "sum of absolute differences" is that much smaller.
+The costs do not necessarily reflect the exact computational speeds of
+the various filters, since this would unduly influence the final image
+size.
+
+Note that the numbers above were invented purely for this example and
+are given only to help explain the function usage. Little testing has
+been done to find optimum values for either the costs or the weights.
+
+Removing unwanted object code:
+
+There are a bunch of #define's in pngconf.h that control what parts of
+libpng are compiled. All the defines end in _SUPPORTED. If you are
+never going to use a capability, you can change the #define to #undef
+before recompiling libpng and save yourself code and data space, or
+you can turn off individual capabilities with defines that begin with
+PNG_NO_.
+
+You can also turn all of the transforms and ancillary chunk capabilities
+off en masse with compiler directives that define
+PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
+or all four,
+along with directives to turn on any of the capabilities that you do
+want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
+the extra transformations but still leave the library fully capable of reading
+and writing PNG files with all known public chunks [except for sPLT].
+Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
+produces a library that is incapable of reading or writing ancillary chunks.
+If you are not using the progressive reading capability, you can
+turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
+this with the INTERLACING capability, which you'll still have).
+
+All the reading and writing specific code are in separate files, so the
+linker should only grab the files it needs. However, if you want to
+make sure, or if you are building a stand alone library, all the
+reading files start with pngr and all the writing files start with
+pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
+are used for both reading and writing, and always need to be included.
+The progressive reader is in pngpread.c
+
+If you are creating or distributing a dynamically linked library (a .so
+or DLL file), you should not remove or disable any parts of the library,
+as this will cause applications linked with different versions of the
+library to fail if they call functions not available in your library.
+The size of the library itself should not be an issue, because only
+those sections that are actually used will be loaded into memory.
+
+Requesting debug printout:
+
+The macro definition PNG_DEBUG can be used to request debugging
+printout. Set it to an integer value in the range 0 to 3. Higher
+numbers result in increasing amounts of debugging information. The
+information is printed to the "stderr" file, unless another file
+name is specified in the PNG_DEBUG_FILE macro definition.
+
+When PNG_DEBUG > 0, the following functions (macros) become available:
+
+ png_debug(level, message)
+ png_debug1(level, message, p1)
+ png_debug2(level, message, p1, p2)
+
+in which "level" is compared to PNG_DEBUG to decide whether to print
+the message, "message" is the formatted string to be printed,
+and p1 and p2 are parameters that are to be embedded in the string
+according to printf-style formatting directives. For example,
+
+ png_debug1(2, "foo=%d\n", foo);
+
+is expanded to
+
+ if(PNG_DEBUG > 2)
+ fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
+
+When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
+can still use PNG_DEBUG to control your own debugging:
+
+ #ifdef PNG_DEBUG
+ fprintf(stderr, ...
+ #endif
+
+When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
+having level = 0 will be printed. There aren't any such statements in
+this version of libpng, but if you insert some they will be printed.
+
+.SH VI. Changes to Libpng from version 0.88
+
+It should be noted that versions of libpng later than 0.96 are not
+distributed by the original libpng author, Guy Schalnat, nor by
+Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
+distributed versions 0.89 through 0.96, but rather by another member
+of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
+still alive and well, but they have moved on to other things.
+
+The old libpng functions png_read_init(), png_write_init(),
+png_info_init(), png_read_destroy(), and png_write_destory() have been
+moved to PNG_INTERNAL in version 0.95 to discourage their use. The
+preferred method of creating and initializing the libpng structures is
+via the png_create_read_struct(), png_create_write_struct(), and
+png_create_info_struct() because they isolate the size of the structures
+from the application, allow version error checking, and also allow the
+use of custom error handling routines during the initialization, which
+the old functions do not. The functions png_read_destroy() and
+png_write_destroy() do not actually free the memory that libpng
+allocated for these structs, but just reset the data structures, so they
+can be used instead of png_destroy_read_struct() and
+png_destroy_write_struct() if you feel there is too much system overhead
+allocating and freeing the png_struct for each image read.
+
+Setting the error callbacks via png_set_message_fn() before
+png_read_init() as was suggested in libpng-0.88 is no longer supported
+because this caused applications that do not use custom error functions
+to fail if the png_ptr was not initialized to zero. It is still possible
+to set the error callbacks AFTER png_read_init(), or to change them with
+png_set_error_fn(), which is essentially the same function, but with a
+new name to force compilation errors with applications that try to use
+the old method.
+
+.SH VII. Y2K Compliance in libpng
+
+October 15, 1999
+
+Since the PNG Development group is an ad-hoc body, we can't make
+an official declaration.
+
+This is your unofficial assurance that libpng from version 0.71 and
+upward through 1.0.5 are Y2K compliant. It is my belief that earlier
+versions were also Y2K compliant.
+
+Libpng only has three year fields. One is a 2-byte unsigned integer that
+will hold years up to 65535. The other two hold the date in text
+format, and will hold years up to 9999.
+
+The integer is
+ "png_uint_16 year" in png_time_struct.
+
+The strings are
+ "png_charp time_buffer" in png_struct and
+ "near_time_buffer", which is a local character string in png.c.
+
+There are seven time-related functions:
+
+ png_convert_to_rfc_1123() in png.c
+ (formerly png_convert_to_rfc_1152() in error)
+ png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
+ png_convert_from_time_t() in pngwrite.c
+ png_get_tIME() in pngget.c
+ png_handle_tIME() in pngrutil.c, called in pngread.c
+ png_set_tIME() in pngset.c
+ png_write_tIME() in pngwutil.c, called in pngwrite.c
+
+All appear to handle dates properly in a Y2K environment. The
+png_convert_from_time_t() function calls gmtime() to convert from system
+clock time, which returns (year - 1900), which we properly convert to
+the full 4-digit year. There is a possibility that applications using
+libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
+function, or that they are incorrectly passing only a 2-digit year
+instead of "year - 1900" into the png_convert_from_struct_tm() function,
+but this is not under our control. The libpng documentation has always
+stated that it works with 4-digit years, and the APIs have been
+documented as such.
+
+The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
+integer to hold the year, and can hold years as large as 65535.
+
+zlib, upon which libpng depends, is also Y2K compliant. It contains
+no date-related code.
+
+
+ Glenn Randers-Pehrson
+ libpng maintainer
+ PNG Development Group
+
+.SH NOTE
+
+Note about libpng version numbers:
+
+Due to various miscommunications, unforeseen code incompatibilities
+and occasional factors outside the authors' control, version numbering
+on the library has not always been consistent and straightforward.
+The following table summarizes matters since version 0.89c, which was
+the first widely used release:
+
+ source png.h png.h shared-lib
+ version string int version
+ ------- ------ ------ ----------
+ 0.89c 0.89 89 1.0.89
+ 0.90 0.90 90 0.90 [should be 2.0.90]
+ 0.95 0.95 95 0.95 [should be 2.0.95]
+ 0.96 0.96 96 0.96 [should be 2.0.96]
+ 0.97b 1.00.97 97 1.0.1 [should be 2.0.97]
+ 0.97c 0.97 97 2.0.97
+ 0.98 0.98 98 2.0.98
+ 0.99 0.99 98 2.0.99
+ 0.99a-m 0.99 99 2.0.99
+ 1.00 1.00 100 2.1.0 [int should be 10000]
+ 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
+ 1.0.1 1.0.1 10001 2.1.0
+
+Henceforth the source version will match the shared-library
+minor and patch numbers; the shared-library major version number will be
+used for changes in backward compatibility, as it is intended.
+The PNG_PNGLIB_VER macro, which is not used within libpng but
+is available for applications, is an unsigned integer of the form
+xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
+
+.SH "SEE ALSO"
+libpngpf(3), png(5)
+.LP
+.IR libpng :
+.IP
+ftp://ftp.uu.net/graphics/png
+http://www.cdrom.com/pub/png
+
+.LP
+.IR zlib :
+.IP
+(generally) at the same location as
+.I libpng
+or at
+.br
+ftp://ftp.uu.net/pub/archiving/zip/zlib
+.br
+http://www.cdrom.com/pub/infozip/zlib
+
+.LP
+.IR PNG specification: RFC 2083
+.IP
+(generally) at the same location as
+.I libpng
+or at
+.br
+ftp://ds.internic.net/rfc/rfc2083.txt
+.br
+or (as a W3C Recommendation) at
+.br
+http://www.w3.org/TR/REC-png.html
+
+.LP
+In the case of any inconsistency between the PNG specification
+and this library, the specification takes precedence.
+
+.SH AUTHORS
+This man page: Glenn Randers-Pehrson
+<randeg@alum.rpi.edu>
+
+The contributing authors would like to thank all those who helped
+with testing, bug fixes, and patience. This wouldn't have been
+possible without all of you.
+
+Thanks to Frank J. T. Wojcik for helping with the documentation.
+
+Libpng version 1.0.5 - October 15, 1999:
+Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
+Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
+
+Supported by the PNG development group
+.br
+(png-implement@ccrc.wustl.edu).
+
+.SH COPYRIGHT NOTICE:
+
+Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+(libpng versions 0.5, May 1995, through 0.89c, May 1996)
+Copyright (c) 1996, 1997 Andreas Dilger
+(libpng versions 0.90, December 1996, through 0.96, May 1997)
+Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+(libpng versions 0.97, January 1998, through 1.0.5, October 15, 1999)
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+ John Bowler
+ Kevin Bracey
+ Sam Bushell
+ Andreas Dilger
+ Magnus Holmgren
+ Tom Lane
+ Dave Martindale
+ Glenn Randers-Pehrson
+ Greg Roelofs
+ Guy Eric Schalnat
+ Paul Schmidt
+ Tom Tanner
+ Willem van Schaik
+ Tim Wegner
+
+The PNG Reference Library (libpng) is supplied "AS IS". The Contributing
+Authors and Group 42, Inc. disclaim all warranties, expressed or implied,
+including, without limitation, the warranties of merchantability and of
+fitness for any purpose. The Contributing Authors and Group 42, Inc.
+assume no liability for direct, indirect, incidental, special, exemplary,
+or consequential damages, which may result from the use of the PNG
+Reference Library, even if advised of the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+ 1. The origin of this source code must not be
+ misrepresented.
+
+ 2. Altered versions must be plainly marked as such
+ and must not be misrepresented as being the
+ original source.
+
+ 3. This Copyright notice may not be removed or
+ altered from any source or altered source
+ distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit, without
+fee, and encourage the use of this source code as a component to
+supporting the PNG file format in commercial products. If you use this
+source code in a product, acknowledgment is not required but would be
+appreciated.
+
+A "png_get_copyright" function is available, for convenient use in "about"
+boxes and the like:
+
+ printf("%s",png_get_copyright(NULL));
+
+Also, the PNG logo (in PNG format, of course) is supplied in the
+file "pngnow.png".
+
+Libpng is OSI Certified Open Source Software. OSI Certified is a
+certification mark of the Open Source Initiative.
+
+.\" end of man page
+
diff --git a/osframework/source/ImageLib/png/libpng.txt b/osframework/source/ImageLib/png/libpng.txt
new file mode 100644
index 0000000..492a764
--- /dev/null
+++ b/osframework/source/ImageLib/png/libpng.txt
@@ -0,0 +1,2112 @@
+libpng.txt - A description on how to use and modify libpng
+
+ libpng version 1.0.5 - October 15, 1999
+ Updated and distributed by Glenn Randers-Pehrson
+ <randeg@alum.rpi.edu>
+ Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ For conditions of distribution and use, see copyright
+ notice in png.h.
+
+ based on:
+
+ libpng 1.0 beta 6 version 0.96 May 28, 1997
+ Updated and distributed by Andreas Dilger
+ Copyright (c) 1996, 1997 Andreas Dilger
+
+ libpng 1.0 beta 2 - version 0.88 January 26, 1996
+ For conditions of distribution and use, see copyright
+ notice in png.h. Copyright (c) 1995, 1996 Guy Eric
+ Schalnat, Group 42, Inc.
+
+ Updated/rewritten per request in the libpng FAQ
+ Copyright (c) 1995 Frank J. T. Wojcik
+ December 18, 1995 && January 20, 1996
+
+ *
+I. Introduction
+
+This file describes how to use and modify the PNG reference library
+(known as libpng) for your own use. There are five sections to this
+file: introduction, structures, reading, writing, and modification and
+configuration notes for various special platforms. In addition to this
+file, example.c is a good starting point for using the library, as
+it is heavily commented and should include everything most people
+will need. We assume that libpng is already installed; see the
+INSTALL file for instructions on how to install libpng.
+
+Libpng was written as a companion to the PNG specification, as a way
+of reducing the amount of time and effort it takes to support the PNG
+file format in application programs.
+
+The PNG-1.2 specification is available at <http://www.cdrom.com/png>.
+
+The PNG-1.0 specification is available
+as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
+W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
+additional chunks are described in the special-purpose public chunks
+documents at <ftp://ftp.uu.net/graphics/png/documents/>.
+
+Other information
+about PNG, and the latest version of libpng, can be found at the PNG home
+page, <http://www.cdrom.com/pub/png/>.
+
+Most users will not have to modify the library significantly; advanced
+users may want to modify it more. All attempts were made to make it as
+complete as possible, while keeping the code easy to understand.
+Currently, this library only supports C. Support for other languages
+is being considered.
+
+Libpng has been designed to handle multiple sessions at one time,
+to be easily modifiable, to be portable to the vast majority of
+machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
+to use. The ultimate goal of libpng is to promote the acceptance of
+the PNG file format in whatever way possible. While there is still
+work to be done (see the TODO file), libpng should cover the
+majority of the needs of its users.
+
+Libpng uses zlib for its compression and decompression of PNG files.
+Further information about zlib, and the latest version of zlib, can
+be found at the zlib home page, <http://www.cdrom.com/pub/infozip/zlib/>.
+The zlib compression utility is a general purpose utility that is
+useful for more than PNG files, and can be used without libpng.
+See the documentation delivered with zlib for more details.
+You can usually find the source files for the zlib utility wherever you
+find the libpng source files.
+
+Libpng is thread safe, provided the threads are using different
+instances of the structures. Each thread should have its own
+png_struct and png_info instances, and thus its own image.
+Libpng does not protect itself against two threads using the
+same instance of a structure.
+
+
+II. Structures
+
+There are two main structures that are important to libpng, png_struct
+and png_info. The first, png_struct, is an internal structure that
+will not, for the most part, be used by a user except as the first
+variable passed to every libpng function call.
+
+The png_info structure is designed to provide information about the
+PNG file. At one time, the fields of png_info were intended to be
+directly accessible to the user. However, this tended to cause problems
+with applications using dynamically loaded libraries, and as a result
+a set of interface functions for png_info was developed. The fields
+of png_info are still available for older applications, but it is
+suggested that applications use the new interfaces if at all possible.
+
+The png.h header file is an invaluable reference for programming with libpng.
+And while I'm on the topic, make sure you include the libpng header file:
+
+#include <png.h>
+
+III. Reading
+
+Reading PNG files:
+
+We'll now walk you through the possible functions to call when reading
+in a PNG file, briefly explaining the syntax and purpose of each one.
+See example.c and png.h for more detail. While Progressive reading
+is covered in the next section, you will still need some of the
+functions discussed in this section to read a PNG file.
+
+You will want to do the I/O initialization(*) before you get into libpng,
+so if it doesn't work, you don't have much to undo. Of course, you
+will also want to insure that you are, in fact, dealing with a PNG
+file. Libpng provides a simple check to see if a file is a PNG file.
+To use it, pass in the first 1 to 8 bytes of the file, and it will
+return true or false (1 or 0) depending on whether the bytes could be
+part of a PNG file. Of course, the more bytes you pass in, the
+greater the accuracy of the prediction.
+
+If you are intending to keep the file pointer open for use in libpng,
+you must ensure you don't read more than 8 bytes from the beginning
+of the file, and you also have to make a call to png_set_sig_bytes_read()
+with the number of bytes you read from the beginning. Libpng will
+then only check the bytes (if any) that your program didn't read.
+
+(*): If you are not using the standard I/O functions, you will need
+to replace them with custom functions. See the discussion under
+Customizing libpng.
+
+
+ FILE *fp = fopen(file_name, "rb");
+ if (!fp)
+ {
+ return;
+ }
+ fread(header, 1, number, fp);
+ is_png = !png_sig_cmp(header, 0, number);
+ if (!is_png)
+ {
+ return;
+ }
+
+
+Next, png_struct and png_info need to be allocated and initialized. In
+order to ensure that the size of these structures is correct even with a
+dynamically linked libpng, there are functions to initialize and
+allocate the structures. We also pass the library version, optional
+pointers to error handling functions, and a pointer to a data struct for
+use by the error functions, if necessary (the pointer and functions can
+be NULL if the default error handlers are to be used). See the section
+on Changes to Libpng below regarding the old initialization functions.
+
+ png_structp png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return;
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr,
+ (png_infopp)NULL, (png_infopp)NULL);
+ return;
+ }
+
+ png_infop end_info = png_create_info_struct(png_ptr);
+ if (!end_info)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return;
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_read_struct_2() instead of png_create_read_struct():
+
+ png_structp png_ptr = png_create_read_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+The error handling routines passed to png_create_read_struct()
+and the memory alloc/free routines passed to png_create_struct_2()
+are only necessary if you are not using the libpng supplied error
+handling and memory alloc/free functions.
+
+When libpng encounters an error, it expects to longjmp back
+to your routine. Therefore, you will need to call setjmp and pass
+your png_ptr->jmpbuf. If you read the file from different
+routines, you will need to update the jmpbuf field every time you enter
+a new routine that will call a png_ function.
+
+See your documentation of setjmp/longjmp for your compiler for more
+handling in the Customizing Libpng section below for more information on
+the libpng error handling. If an error occurs, and libpng longjmp's
+back to your setjmp, you will want to call png_destroy_read_struct() to
+free any memory.
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+ fclose(fp);
+ return;
+ }
+
+Now you need to set up the input code. The default for libpng is to
+use the C function fread(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. If you wish to handle reading data in another
+way, you need not call the png_init_io() function, but you must then
+implement the libpng I/O methods discussed in the Customizing Libpng
+section below.
+
+ png_init_io(png_ptr, fp);
+
+If you had previously opened the file and read any of the signature from
+the beginning in order to see if this was a PNG file, you need to let
+libpng know that there are some bytes missing from the start of the file.
+
+ png_set_sig_bytes(png_ptr, number);
+
+At this point, you can set up a callback function that will be
+called after each row has been read, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void read_row_callback(png_ptr, png_uint_32 row, int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "read_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_read_status_fn(png_ptr, read_row_callback);
+
+In PNG files, the alpha channel in an image is the level of opacity.
+If you need the alpha channel in an image to be the level of transparency
+instead of opacity, you can invert the alpha channel (or the tRNS chunk
+data) after it's read, so that 0 is fully opaque and 255 (in 8-bit or
+paletted images) or 65535 (in 16-bit images) is fully transparent, with
+
+ png_set_invert_alpha(png_ptr);
+
+This has to appear here rather than later with the other transformations
+because the tRNS chunk data must be modified in the case of paletted images.
+If your image is not a paletted image, the tRNS data (which in such cases
+represents a single color to be rendered as transparent) won't be changed.
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_read_user_transform_fn(png_ptr,
+ read_transform_fn);
+
+You must supply the function
+
+ void read_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+after all of the other transformations have been processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function, and you can inform libpng that your transform
+function will change the number of channels or bit depth with the
+function
+
+ png_set_user_transform_info(png_ptr, user_ptr,
+ user_depth, user_channels);
+
+
+You can retrieve the pointer via the function
+png_get_user_transform_ptr(). For example:
+
+ voidp read_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+You are now ready to read all the file information up to the actual
+image data. You do this with a call to png_read_info().
+
+ png_read_info(png_ptr, info_ptr);
+
+Functions are used to get the information from the info_ptr:
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height,
+ &bit_depth, &color_type, &interlace_type,
+ &compression_type, &filter_type);
+
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels. (valid values are
+ 1, 2, 4, 8, 16 and depend also on
+ the color_type. See also
+ significant bits (sBIT) below).
+ color_type - describes which color/alpha channels
+ are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ filter_type - (must be PNG_FILTER_TYPE_BASE
+ for PNG 1.0)
+ compression_type - (must be PNG_COMPRESSION_TYPE_BASE
+ for PNG 1.0)
+ interlace_type - (PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7)
+ Any or all of interlace_type, compression_type, of
+ filter_type can be
+ NULL if you are not interested in their values.
+
+ channels = png_get_channels(png_ptr, info_ptr);
+ channels - number of channels of info for the
+ color type (valid values are 1 (GRAY,
+ PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
+ 4 (RGB_ALPHA or RGB + filler byte))
+ rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ rowbytes - number of bytes needed to hold a row
+
+ signature = png_get_signature(png_ptr, info_ptr);
+ signature - holds the signature read from the
+ file (if any). The data is kept in
+ the same offset it would be if the
+ whole signature were read (i.e. if an
+ application had already read in 4
+ bytes of signature before starting
+ libpng, the remaining 4 bytes would
+ be in signature[4] through signature[7]
+ (see png_set_sig_bytes())).
+
+
+ width = png_get_image_width(png_ptr,
+ info_ptr);
+ height = png_get_image_height(png_ptr,
+ info_ptr);
+ bit_depth = png_get_bit_depth(png_ptr,
+ info_ptr);
+ color_type = png_get_color_type(png_ptr,
+ info_ptr);
+ filter_type = png_get_filter_type(png_ptr,
+ info_ptr);
+ compression_type = png_get_compression_type(png_ptr,
+ info_ptr);
+ interlace_type = png_get_interlace_type(png_ptr,
+ info_ptr);
+
+
+These are also important, but their validity depends on whether the chunk
+has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
+png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
+data has been read, or zero if it is missing. The parameters to the
+png_get_<chunk> are set directly if they are simple data types, or a pointer
+into the info_ptr is returned for any complex types.
+
+ png_get_PLTE(png_ptr, info_ptr, &palette,
+ &num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_get_gAMA(png_ptr, info_ptr, &gamma);
+ gamma - the gamma the file is written
+ at (PNG_INFO_gAMA)
+
+ png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
+ srgb_intent - the rendering intent (PNG_INFO_sRGB)
+ The presence of the sRGB chunk
+ means that the pixel data is in the
+ sRGB color space. This chunk also
+ implies specific values of gAMA and
+ cHRM.
+
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray,
+ red, green, and blue channels,
+ whichever are appropriate for the
+ given color type (png_color_16)
+
+ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
+ &trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - transparent pixel for non-paletted
+ images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_get_hIST(png_ptr, info_ptr, &hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_color_16)
+
+ png_get_tIME(png_ptr, info_ptr, &mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_get_bKGD(png_ptr, info_ptr, &background);
+ background - background color (PNG_VALID_bKGD)
+
+ num_text = png_get_text(png_ptr, info_ptr, &text_ptr);
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i]->key - keyword for comment.
+ text_ptr[i]->text - text comments for current
+ keyword.
+ text_ptr[i]->compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE
+ or PNG_TEXT_COMPRESSION_zTXt
+ num_text - number of comments
+
+ png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
+ &unit_type);
+ offset_x - positive offset from the left edge
+ of the screen
+ offset_y - positive offset from the top edge
+ of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
+ &unit_type);
+ res_x - pixels/unit physical resolution in
+ x direction
+ res_y - pixels/unit physical resolution in
+ x direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+The data from the pHYs chunk can be retrieved in several convenient
+forms:
+
+ res_x = png_get_x_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_y = png_get_y_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_x_and_y = png_get_pixels_per_meter(png_ptr,
+ info_ptr)
+ aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
+ info_ptr)
+
+ (Each of these returns 0 [signifying "unknown"] if
+ the data is not present or if res_x is 0;
+ res_x_and_y is 0 if res_x != res_y)
+
+For more information, see the png_info definition in png.h and the
+PNG specification for chunk contents. Be careful with trusting
+rowbytes, as some of the transformations could increase the space
+needed to hold a row (expand, filler, gray_to_rgb, etc.).
+See png_read_update_info(), below.
+
+A quick word about text_ptr and num_text. PNG stores comments in
+keyword/text pairs, one pair per chunk, with no limit on the number
+of text chunks, and a 2^31 byte limit on their size. While there are
+suggested keywords, there is no requirement to restrict the use to these
+strings. It is strongly suggested that keywords and text be sensible
+to humans (that's the point), so don't use abbreviations. Non-printing
+symbols are not allowed. See the PNG specification for more details.
+There is also no requirement to have text after the keyword.
+
+Keywords should be limited to 79 Latin-1 characters without leading or
+trailing spaces, but non-consecutive spaces are allowed within the
+keyword. It is possible to have the same keyword any number of times.
+The text_ptr is an array of png_text structures, each holding pointer
+to a keyword and a pointer to a text string. Only the text string may
+be null. The keyword/text pairs are put into the array in the order
+that they are received. However, some or all of the text chunks may be
+after the image, so, to make sure you have read all the text chunks,
+don't mess with these until after you read the stuff after the image.
+This will be mentioned again below in the discussion that goes with
+png_read_end().
+
+After you've read the header information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+The colors used for the background and transparency values should be
+supplied in the same format/depth as the current image data. They
+are stored in the same format/depth as the image data in a bKGD or tRNS
+chunk, so this is what libpng expects for this data. The colors are
+transformed to keep in sync with the image data when an application
+calls the png_read_update_info() routine (see below).
+
+Data will be decoded into the supplied row buffers packed into bytes
+unless the library has been told to transform it into another format.
+For example, 4 bit/pixel paletted or grayscale data will be returned
+2 pixels/byte with the leftmost pixel in the high-order bits of the
+byte, unless png_set_packing() is called. 8-bit RGB data will be stored
+in RGB RGB RGB format unless png_set_filler() is called to insert filler
+bytes, either before or after each RGB triplet. 16-bit RGB data will
+be returned RRGGBB RRGGBB, with the most significant byte of the color
+value first, unless png_set_strip_16() is called to transform it to
+regular RGB RGB triplets, or png_set_filler() is called to insert
+filler bytes, either before or after each RRGGBB triplet. Similarly,
+8-bit or 16-bit grayscale data can be modified with png_set_filler()
+or png_set_strip_16().
+
+The following code transforms grayscale images of less than 8 to 8 bits,
+changes paletted images to RGB, and adds a full alpha channel if there is
+transparency information in a tRNS chunk. This is most useful on
+grayscale images with bit depths of 2 or 4 or if there is a multiple-image
+viewing application that wishes to treat all images in the same way.
+
+ if (color_type == PNG_COLOR_TYPE_PALETTE &&
+ bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
+
+ if (color_type == PNG_COLOR_TYPE_GRAY &&
+ bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
+
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
+
+These three functions are actually aliases for png_set_expand(), added
+in libpng version 1.0.4, with the function names expanded to improve code
+readability. In some future version they may actually do different
+things.
+
+PNG can have files with 16 bits per channel. If you only can handle
+8 bits per channel, this will strip the pixels down to 8 bit.
+
+ if (bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+The png_set_background() function tells libpng to composite images
+with alpha or simple transparency against the supplied background
+color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
+you may use this color, or supply another color more suitable for
+the current display (e.g., the background color from a web page). You
+need to tell libpng whether the color is in the gamma space of the
+display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
+(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
+that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
+know why anyone would use this, but it's here).
+
+If, for some reason, you don't need the alpha channel on an image,
+and you want to remove it rather than combining it with the background
+(but the image author certainly had in mind that you *would* combine
+it with the background, so that's what you should probably do):
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ png_set_strip_alpha(png_ptr);
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit
+files. This code expands to 1 pixel per byte without changing the
+values of the pixels:
+
+ if (bit_depth < 8)
+ png_set_packing(png_ptr);
+
+PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
+stored in a PNG image have been "scaled" or "shifted" up to the next
+higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
+8 bits/sample in the range [0, 255]). However, it is also possible to
+convert the PNG pixel data back to the original bit depth of the image.
+This call reduces the pixels back down to the original bit depth:
+
+ png_color_16p sig_bit;
+
+ if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
+ png_set_shift(png_ptr, sig_bit);
+
+PNG files store 3-color pixels in red, green, blue order. This code
+changes the storage of the pixels to blue, green, red:
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_bgr(png_ptr);
+
+PNG files store RGB pixels packed into 3 bytes. This code expands them
+into 4 bytes for windowing systems that need them in this format:
+
+ if (bit_depth == 8 && color_type ==
+ PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
+ filler, PNG_FILLER_BEFORE);
+
+where "filler" is the 8 or 16-bit number to fill with, and the location is
+either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
+you want the filler before the RGB or after. This transformation
+does not affect images that already have full alpha channels.
+
+If you are reading an image with an alpha channel, and you need the
+data as ARGB instead of the normal PNG format RGBA:
+
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_swap_alpha(png_ptr);
+
+For some uses, you may want a grayscale image to be represented as
+RGB. This code will do that conversion:
+
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_gray_to_rgb(png_ptr);
+
+Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
+with alpha. This is intended for conversion of images that really are
+gray (red == green == blue), so the function simply strips out the red
+and blue channels, leaving the green channel in the gray position.
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_rgb_to_gray(png_ptr, error_action,
+ double red_weight, double green_weight);
+
+ error_action = 1: silently do the conversion
+ error_action = 2: issue a warning if the original
+ image has any pixel where
+ red != green or red != blue
+ error_action = 3: issue an error and abort the
+ conversion if the original
+ image has any pixel where
+ red != green or red != blue
+
+ red_weight: weight of red component
+ (NULL -> default 54/256)
+ green_weight: weight of green component
+ (NULL -> default 183/256)
+
+If you have set error_action = 1 or 2, you can
+later check whether the image really was gray, after processing
+the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
+It will return a png_byte that is zero if the image was gray or
+1 if there were any non-gray pixels. bKGD and sBIT data
+will be silently converted to grayscale, using the green channel
+data, regardless of the error_action setting.
+
+With 0.0<=red_weight+green_weight<=1.0,
+the normalized graylevel is computed:
+
+ int rw = red_weight * 256;
+ int gw = green_weight * 256;
+ int bw = 256 - (rw + gw);
+ gray = (rw*red + gw*green + bw*blue)/256;
+
+The default values approximate those recommended in the Charles
+Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
+Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
+
+ Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
+
+Libpng approximates this with
+
+ Y = 0.211 * R + 0.715 * G + 0.074 * B
+
+which can be expressed with integers as
+
+ Y = (54 * R + 183 * G + 19 * B)/256
+
+The calculation is done in a linear colorspace, if the image gamma
+is known.
+
+If you have a grayscale and you are using png_set_expand_depth() or
+png_set_expand() to change to
+a higher bit-depth, you must either supply the background color as a gray
+value at the original file bit-depth (need_expand = 1) or else supply the
+background color as an RGB triplet at the final, expanded bit depth
+(need_expand = 0). Similarly, if you are reading a paletted image, you
+must either supply the background color as a palette index (need_expand = 1)
+or as an RGB triplet that may or may not be in the palette (need_expand = 0).
+
+ png_color_16 my_background;
+ png_color_16p image_background;
+
+ if (png_get_bKGD(png_ptr, info_ptr, &image_background))
+ png_set_background(png_ptr, image_background,
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ else
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+
+To properly display PNG images on any kind of system, the application needs
+to know what the display gamma is. Ideally, the user will know this, and
+the application will allow them to set it. One method of allowing the user
+to set the display gamma separately for each system is to check for a
+SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
+correctly set.
+
+Note that display_gamma is the overall gamma correction required to produce
+pleasing results, which depends on the lighting conditions in the surrounding
+environment. In a dim or brightly lit room, no compensation other than
+the physical gamma exponent of the monitor is needed, while in a dark room
+a slightly smaller exponent is better.
+
+ double gamma, screen_gamma;
+
+ if (/* We have a user-defined screen
+ gamma value */)
+ {
+ screen_gamma = user_defined_screen_gamma;
+ }
+ /* One way that applications can share the same
+ screen gamma value */
+ else if ((gamma_str = getenv("SCREEN_GAMMA"))
+ != NULL)
+ {
+ screen_gamma = (double)atof(gamma_str);
+ }
+ /* If we don't have another value */
+ else
+ {
+ screen_gamma = 2.2; /* A good guess for a
+ PC monitor in a bright office or a dim room */
+ screen_gamma = 2.0; /* A good guess for a
+ PC monitor in a dark room */
+ screen_gamma = 1.7 or 1.0; /* A good
+ guess for Mac systems */
+ }
+
+The png_set_gamma() function handles gamma transformations of the data.
+Pass both the file gamma and the current screen_gamma. If the file does
+not have a gamma value, you can pass one anyway if you have an idea what
+it is (usually 0.45455 is a good guess for GIF images on PCs). Note
+that file gammas are inverted from screen gammas. See the discussions
+on gamma in the PNG specification for an excellent description of what
+gamma is, and why all applications should support it. It is strongly
+recommended that PNG viewers support gamma correction.
+
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma))
+ png_set_gamma(png_ptr, screen_gamma, gamma);
+ else
+ png_set_gamma(png_ptr, screen_gamma, 0.45455);
+
+If you need to reduce an RGB file to a paletted file, or if a paletted
+file has more entries then will fit on your screen, png_set_dither()
+will do that. Note that this is a simple match dither that merely
+finds the closest color available. This should work fairly well with
+optimized palettes, and fairly badly with linear color cubes. If you
+pass a palette that is larger then maximum_colors, the file will
+reduce the number of colors in the palette so it will fit into
+maximum_colors. If there is a histogram, it will use it to make
+more intelligent choices when reducing the palette. If there is no
+histogram, it may not do as good a job.
+
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_PLTE))
+ {
+ png_color_16p histogram;
+
+ png_get_hIST(png_ptr, info_ptr,
+ &histogram);
+ png_set_dither(png_ptr, palette, num_palette,
+ max_screen_colors, histogram, 1);
+ }
+ else
+ {
+ png_color std_color_cube[MAX_SCREEN_COLORS] =
+ { ... colors ... };
+
+ png_set_dither(png_ptr, std_color_cube,
+ MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
+ NULL,0);
+ }
+ }
+
+PNG files describe monochrome as black being zero and white being one.
+The following code will reverse this (make black be one and white be
+zero):
+
+ if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
+ png_set_invert_mono(png_ptr);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code changes the storage to the
+other way (little-endian, i.e. least significant bits first, the
+way PCs store them):
+
+ if (bit_depth == 16)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+The last thing to handle is interlacing; this is covered in detail below,
+but you must call the function here if you want libpng to handle expansion
+of the interlaced image.
+
+ number_of_passes = png_set_interlace_handling(png_ptr);
+
+After setting the transformations, libpng can update your png_info
+structure to reflect any transformations you've requested with this
+call. This is most useful to update the info structure's rowbytes
+field so you can use it to allocate your image memory. This function
+will also update your palette with the correct screen_gamma and
+background if these have been given with the calls above.
+
+ png_read_update_info(png_ptr, info_ptr);
+
+After you call png_read_update_info(), you can allocate any
+memory you need to hold the image. The row data is simply
+raw byte data for all forms of images. As the actual allocation
+varies among applications, no example will be given. If you
+are allocating one large chunk, you will need to build an
+array of pointers to each row, as it will be needed for some
+of the functions below.
+
+After you've allocated memory, you can read the image data.
+The simplest way to do this is in one function call. If you are
+allocating enough memory to hold the whole image, you can just
+call png_read_image() and libpng will read in all the image data
+and put it in the memory area supplied. You will need to pass in
+an array of pointers to each row.
+
+This function automatically handles interlacing, so you don't need
+to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_read_rows().
+
+ png_read_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_bytep row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to read in the whole image at once, you can
+use png_read_rows() instead. If there is no interlacing (check
+interlace_type == PNG_INTERLACE_NONE), this is simple:
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+where row_pointers is the same as in the png_read_image() call.
+
+If you are doing this just one row at a time, you can do this with
+row_pointers:
+
+ png_bytep row_pointers = row;
+ png_read_row(png_ptr, &row_pointers, NULL);
+
+If the file is interlaced (info_ptr->interlace_type != 0), things get
+somewhat harder. The only current (PNG Specification version 1.2)
+interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
+is a somewhat complicated 2D interlace scheme, known as Adam7, that
+breaks down an image into seven smaller images of varying size, based
+on an 8x8 grid.
+
+libpng can fill out those images or it can give them to you "as is".
+If you want them filled out, there are two ways to do that. The one
+mentioned in the PNG specification is to expand each pixel to cover
+those pixels that have not been read yet (the "rectangle" method).
+This results in a blocky image for the first pass, which gradually
+smooths out as more pixels are read. The other method is the "sparkle"
+method, where pixels are drawn only in their final locations, with the
+rest of the image remaining whatever colors they were initialized to
+before the start of the read. The first method usually looks better,
+but tends to be slower, as there are more pixels to put in the rows.
+
+If you don't want libpng to handle the interlacing details, just call
+png_read_rows() seven times to read in all seven images. Each of the
+images is a valid image by itself, or they can all be combined on an
+8x8 grid to form a single image (although if you intend to combine them
+you would be far better off using the libpng interlace handling).
+
+The first pass will return an image 1/8 as wide as the entire image
+(every 8th column starting in column 0) and 1/8 as high as the original
+(every 8th row starting in row 0), the second will be 1/8 as wide
+(starting in column 4) and 1/8 as high (also starting in row 0). The
+third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
+1/8 as high (every 8th row starting in row 4), and the fourth pass will
+be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
+and every 4th row starting in row 0). The fifth pass will return an
+image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
+while the sixth pass will be 1/2 as wide and 1/2 as high as the original
+(starting in column 1 and row 0). The seventh and final pass will be as
+wide as the original, and 1/2 as high, containing all of the odd
+numbered scanlines. Phew!
+
+If you want libpng to expand the images, call this before calling
+png_start_read_image() or png_read_update_info():
+
+ if (interlace_type == PNG_INTERLACE_ADAM7)
+ number_of_passes
+ = png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+This function can be called even if the file is not interlaced,
+where it will return one pass.
+
+If you are not going to display the image after each pass, but are
+going to wait until the entire image is read in, use the sparkle
+effect. This effect is faster and the end result of either method
+is exactly the same. If you are planning on displaying the image
+after each pass, the "rectangle" effect is generally considered the
+better looking one.
+
+If you only want the "sparkle" effect, just call png_read_rows() as
+normal, with the third parameter NULL. Make sure you make pass over
+the image number_of_passes times, and you don't change the data in the
+rows between calls. You can change the locations of the data, just
+not the data. Each pass only writes the pixels appropriate for that
+pass, and assumes the data from previous passes is still valid.
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+If you only want the first effect (the rectangles), do the same as
+before except pass the row buffer in the third parameter, and leave
+the second parameter NULL.
+
+ png_read_rows(png_ptr, NULL, row_pointers,
+ number_of_rows);
+
+After you are finished reading the image, you can finish reading
+the file. If you are interested in comments or time, which may be
+stored either before or after the image data, you should pass the
+separate png_info struct if you want to keep the comments from
+before and after the image separate. If you are not interested, you
+can pass NULL.
+
+ png_read_end(png_ptr, end_info);
+
+When you are done, you can free all memory allocated by libpng like this:
+
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+
+For a more compact example of reading a PNG image, see the file example.c.
+
+
+Reading PNG files progressively:
+
+The progressive reader is slightly different then the non-progressive
+reader. Instead of calling png_read_info(), png_read_rows(), and
+png_read_end(), you make one call to png_process_data(), which calls
+callbacks when it has the info, a row, or the end of the image. You
+set up these callbacks with png_set_progressive_read_fn(). You don't
+have to worry about the input/output functions of libpng, as you are
+giving the library the data directly in png_process_data(). I will
+assume that you have read the section on reading PNG files above,
+so I will only highlight the differences (although I will show
+all of the code).
+
+png_structp png_ptr;
+png_infop info_ptr;
+
+ /* An example code fragment of how you would
+ initialize the progressive reader in your
+ application. */
+ int
+ initialize_png_reader()
+ {
+ png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return -1;
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ /* This one's new. You can provide functions
+ to be called when the header info is valid,
+ when each row is completed, and when the image
+ is finished. If you aren't using all functions,
+ you can specify NULL parameters. Even when all
+ three functions are NULL, you need to call
+ png_set_progressive_read_fn(). You can use
+ any struct as the user_ptr (cast to a void pointer
+ for the function call), and retrieve the pointer
+ from inside the callbacks using the function
+
+ png_get_progressive_ptr(png_ptr);
+
+ which will return a void pointer, which you have
+ to cast appropriately.
+ */
+ png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
+ info_callback, row_callback, end_callback);
+
+ return 0;
+ }
+
+ /* A code fragment that you call as you receive blocks
+ of data */
+ int
+ process_data(png_bytep buffer, png_uint_32 length)
+ {
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+ /* This one's new also. Simply give it a chunk
+ of data from the file stream (in order, of
+ course). On machines with segmented memory
+ models 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, I haven't tried less then 256 bytes
+ yet). When this function returns, you may
+ want to display any rows that were generated
+ in the row callback if you don't already do
+ so there.
+ */
+ png_process_data(png_ptr, info_ptr, buffer, length);
+ return 0;
+ }
+
+ /* This function is called (as set by
+ png_set_progressive_read_fn() above) when enough data
+ has been supplied so all of the header has been
+ read.
+ */
+ 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.
+ */
+ }
+
+ /* This function is called when each row of image
+ data is complete */
+ void
+ row_callback(png_structp png_ptr, png_bytep new_row,
+ png_uint_32 row_num, int pass)
+ {
+ /* If the image is interlaced, and you turned
+ on the interlace handler, this function will
+ be called for every row in every pass. Some
+ of these rows will not be changed from the
+ previous pass. When the row is not changed,
+ the new_row variable will be NULL. The rows
+ and passes are called in order, so you don't
+ really need the row_num and pass, but I'm
+ supplying them because it may make your life
+ easier.
+
+ For the non-NULL rows of interlaced images,
+ you must call png_progressive_combine_row()
+ passing in the row and the old row. You can
+ call this function for NULL rows (it will just
+ return) and for non-interlaced images (it just
+ does the memcpy for you) if it will make the
+ code easier. Thus, you can just do this for
+ all cases:
+ */
+
+ png_progressive_combine_row(png_ptr, old_row,
+ new_row);
+
+ /* where old_row is what was displayed for
+ previously for the row. 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 after 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.
+ */
+ }
+
+
+
+IV. Writing
+
+Much of this is very similar to reading. However, everything of
+importance is repeated here, so you won't have to constantly look
+back up in the reading section to understand writing.
+
+You will want to do the I/O initialization before you get into libpng,
+so if it doesn't work, you don't have anything to undo. If you are not
+using the standard I/O functions, you will need to replace them with
+custom writing functions. See the discussion under Customizing libpng.
+
+ FILE *fp = fopen(file_name, "wb");
+ if (!fp)
+ {
+ return;
+ }
+
+Next, png_struct and png_info need to be allocated and initialized.
+As these can be both relatively large, you may not want to store these
+on the stack, unless you have stack space to spare. Of course, you
+will want to check if they return NULL. If you are also reading,
+you won't want to name your read structure and your write structure
+both "png_ptr"; you can call them anything you like, such as
+"read_ptr" and "write_ptr". Look at pngtest.c, for example.
+
+ png_structp png_ptr = png_create_write_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return;
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_write_struct(&png_ptr,
+ (png_infopp)NULL);
+ return;
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_write_struct_2() instead of png_create_read_struct():
+
+ png_structp png_ptr = png_create_write_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+After you have these structures, you will need to set up the
+error handling. When libpng encounters an error, it expects to
+longjmp() back to your routine. Therefore, you will need to call
+setjmp() and pass the png_ptr->jmpbuf. If you
+write the file from different routines, you will need to update
+the jmpbuf field every time you enter a new routine that will
+call a png_ function. See your documentation of setjmp/longjmp
+for your compiler for more information on setjmp/longjmp. See
+the discussion on libpng error handling in the Customizing Libpng
+section below for more information on the libpng error handling.
+
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ fclose(fp);
+ return;
+ }
+ ...
+ return;
+
+Now you need to set up the output code. The default for libpng is to
+use the C function fwrite(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. Again, if you wish to handle writing data in
+another way, see the discussion on libpng I/O handling in the Customizing
+Libpng section below.
+
+ png_init_io(png_ptr, fp);
+
+At this point, you can set up a callback function that will be
+called after each row has been written, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void write_row_callback(png_ptr, png_uint_32 row, int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "write_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_write_status_fn(png_ptr, write_row_callback);
+
+You now have the option of modifying how the compression library will
+run. The following functions are mainly for testing, but may be useful
+in some cases, like if you need to write PNG files extremely fast and
+are willing to give up some compression, or if you want to get the
+maximum possible compression at the expense of slower writing. If you
+have no special needs in this area, let the library do what it wants by
+not calling this function at all, as it has been tuned to deliver a good
+speed/compression ratio. The second parameter to png_set_filter() is
+the filter method, for which the only valid value is '0' (as of the
+July 1999 PNG specification, version 1.2). The third parameter is a
+flag that indicates which filter type(s) are to be tested for each
+scanline. See the Compression Library for details on the specific filter
+types.
+
+
+ /* turn on or off filtering, and/or choose
+ specific filters */
+ png_set_filter(png_ptr, 0,
+ PNG_FILTER_NONE | PNG_FILTER_SUB |
+ PNG_FILTER_PAETH);
+
+The png_set_compression_???() functions interface to the zlib compression
+library, and should mostly be ignored unless you really know what you are
+doing. The only generally useful call is png_set_compression_level()
+which changes how much time zlib spends on trying to compress the image
+data. See the Compression Library for details on the compression levels.
+
+ /* set the zlib compression level */
+ png_set_compression_level(png_ptr,
+ Z_BEST_COMPRESSION);
+
+ /* set other zlib parameters */
+ png_set_compression_mem_level(png_ptr, 8);
+ png_set_compression_strategy(png_ptr,
+ Z_DEFAULT_STRATEGY);
+ png_set_compression_window_bits(png_ptr, 15);
+ png_set_compression_method(png_ptr, 8);
+
+You now need to fill in the png_info structure with all the data you
+wish to write before the actual image. Note that the only thing you
+are allowed to write after the image is the text chunks and the time
+chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
+the latest PNG specification for more information on that. If you
+wish to write them before the image, fill them in now, and flag that
+data as being valid. If you want to wait until after the data, don't
+fill them until png_write_end(). For all the fields in png_info and
+their data types, see png.h. For explanations of what the fields
+contain, see the PNG specification.
+
+Some of the more important parts of the png_info are:
+
+ png_set_IHDR(png_ptr, info_ptr, width, height,
+ bit_depth, color_type, interlace_type,
+ compression_type, filter_type)
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels.
+ (valid values are 1, 2, 4, 8, 16
+ and depend also on the
+ color_type. See also significant
+ bits (sBIT) below).
+ color_type - describes which color/alpha
+ channels are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ interlace_type - PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7
+ compression_type - (must be
+ PNG_COMPRESSION_TYPE_DEFAULT)
+ filter_type - (must be PNG_FILTER_TYPE_DEFAULT)
+
+ png_set_PLTE(png_ptr, info_ptr, palette,
+ num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_set_gAMA(png_ptr, info_ptr, gamma);
+ gamma - the gamma the image was created
+ at (PNG_INFO_gAMA)
+
+ png_set_sRGB(png_ptr, info_ptr, srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of
+ the sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This chunk also implies specific
+ values of gAMA and cHRM. Rendering
+ intent is the CSS-1 property that
+ has been defined by the International
+ Color Consortium
+ (http://www.color.org).
+ It can be one of
+ PNG_SRGB_INTENT_SATURATION,
+ PNG_SRGB_INTENT_PERCEPTUAL,
+ PNG_SRGB_INTENT_ABSOLUTE, or
+ PNG_SRGB_INTENT_RELATIVE.
+
+
+ png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
+ srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of the
+ sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This function also causes gAMA and
+ cHRM chunks with the specific values
+ that are consistent with sRGB to be
+ written.
+
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray, red,
+ green, and blue channels, whichever are
+ appropriate for the given color type
+ (png_color_16)
+
+ png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
+ trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - transparent pixel for non-paletted
+ images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_set_hIST(png_ptr, info_ptr, hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_color_16)
+
+ png_set_tIME(png_ptr, info_ptr, mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_set_bKGD(png_ptr, info_ptr, background);
+ background - background color (PNG_VALID_bKGD)
+
+ png_set_text(png_ptr, info_ptr, text_ptr, num_text);
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i]->key - keyword for comment.
+ text_ptr[i]->text - text comments for current
+ keyword.
+ text_ptr[i]->compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE or
+ PNG_TEXT_COMPRESSION_zTXt
+ num_text - number of comments in text_ptr
+
+ png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
+ unit_type);
+ offset_x - positive offset from the left
+ edge of the screen
+ offset_y - positive offset from the top
+ edge of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
+ unit_type);
+ res_x - pixels/unit physical resolution
+ in x direction
+ res_y - pixels/unit physical resolution
+ in y direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+In PNG files, the alpha channel in an image is the level of opacity.
+If your data is supplied as a level of transparency, you can invert the
+alpha channel before you write it, so that 0 is fully transparent and 255
+(in 8-bit or paletted images) or 65535 (in 16-bit images) is fully opaque,
+with
+
+ png_set_invert_alpha(png_ptr);
+
+This must appear here instead of later with the other transformations
+because in the case of paletted images the tRNS chunk data has to
+be inverted before the tRNS chunk is written. If your image is not a
+paletted image, the tRNS data (which in such cases represents a single
+color to be rendered as transparent) won't be changed.
+
+A quick word about text and num_text. text is an array of png_text
+structures. num_text is the number of valid structures in the array.
+If you want, you can use max_text to hold the size of the array, but
+libpng ignores it for writing (it does use it for reading). Each
+png_text structure holds a keyword-text value, and a compression type.
+The compression types have the same valid numbers as the compression
+types of the image data. Currently, the only valid number is zero.
+However, you can store text either compressed or uncompressed, unlike
+images, which always have to be compressed. So if you don't want the
+text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
+Until text gets around 1000 bytes, it is not worth compressing it.
+After the text has been written out to the file, the compression type
+is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
+so that it isn't written out again at the end (in case you are calling
+png_write_end() with the same struct.
+
+The keywords that are given in the PNG Specification are:
+
+ Title Short (one line) title or
+ caption for image
+ Author Name of image's creator
+ Description Description of image (possibly long)
+ Copyright Copyright notice
+ Creation Time Time of original image creation
+ (usually RFC 1123 format, see below)
+ Software Software used to create the image
+ Disclaimer Legal disclaimer
+ Warning Warning of nature of content
+ Source Device used to create the image
+ Comment Miscellaneous comment; conversion
+ from other image format
+
+The keyword-text pairs work like this. Keywords should be short
+simple descriptions of what the comment is about. Some typical
+keywords are found in the PNG specification, as is some recommendations
+on keywords. You can repeat keywords in a file. You can even write
+some text before the image and some after. For example, you may want
+to put a description of the image before the image, but leave the
+disclaimer until after, so viewers working over modem connections
+don't have to wait for the disclaimer to go over the modem before
+they start seeing the image. Finally, keywords should be full
+words, not abbreviations. Keywords and text are in the ISO 8859-1
+(Latin-1) character set (a superset of regular ASCII) and can not
+contain NUL characters, and should not contain control or other
+unprintable characters. To make the comments widely readable, stick
+with basic ASCII, and avoid machine specific character set extensions
+like the IBM-PC character set. The keyword must be present, but
+you can leave off the text string on non-compressed pairs.
+Compressed pairs must have a text string, as only the text string
+is compressed anyway, so the compression would be meaningless.
+
+PNG supports modification time via the png_time structure. Two
+conversion routines are proved, png_convert_from_time_t() for
+time_t and png_convert_from_struct_tm() for struct tm. The
+time_t routine uses gmtime(). You don't have to use either of
+these, but if you wish to fill in the png_time structure directly,
+you should provide the time in universal time (GMT) if possible
+instead of your local time. Note that the year number is the full
+year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
+that months start with 1.
+
+If you want to store the time of the original image creation, you should
+use a plain tEXt chunk with the "Creation Time" keyword. This is
+necessary because the "creation time" of a PNG image is somewhat vague,
+depending on whether you mean the PNG file, the time the image was
+created in a non-PNG format, a still photo from which the image was
+scanned, or possibly the subject matter itself. In order to facilitate
+machine-readable dates, it is recommended that the "Creation Time"
+tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
+although this isn't a requirement. Unlike the tIME chunk, the
+"Creation Time" tEXt chunk is not expected to be automatically changed
+by the software. To facilitate the use of RFC 1123 dates, a function
+png_convert_to_rfc1123(png_timep) is provided to convert from PNG
+time to an RFC 1123 format string.
+
+You are now ready to write all the file information up to the actual
+image data. You do this with a call to png_write_info().
+
+ png_write_info(png_ptr, info_ptr);
+
+After you've written the file information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
+the library to expand the input data to 4 or 8 bytes per pixel
+(or expand 1 or 2-byte grayscale data to 2 or 4 bytes per pixel).
+
+ png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
+
+where the 0 is the value that will be put in the 4th byte, and the
+location is either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending
+upon whether the filler byte is stored XRGB or RGBX.
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit files.
+If the data is supplied at 1 pixel per byte, use this code, which will
+correctly pack the pixels into a single byte:
+
+ png_set_packing(png_ptr);
+
+PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
+data is of another bit depth, you can write an sBIT chunk into the
+file so that decoders can get the original data if desired.
+
+ /* Set the true bit depth of the image data */
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ sig_bit.red = true_bit_depth;
+ sig_bit.green = true_bit_depth;
+ sig_bit.blue = true_bit_depth;
+ }
+ else
+ {
+ sig_bit.gray = true_bit_depth;
+ }
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ sig_bit.alpha = true_bit_depth;
+ }
+
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+
+If the data is stored in the row buffer in a bit depth other than
+one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
+this will scale the values to appear to be the correct bit depth as
+is required by PNG.
+
+ png_set_shift(png_ptr, &sig_bit);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code would be used if they are
+supplied the other way (little-endian, i.e. least significant bits
+first, the way PCs store them):
+
+ if (bit_depth > 8)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+PNG files store 3 color pixels in red, green, blue order. This code
+would be used if they are supplied as blue, green, red:
+
+ png_set_bgr(png_ptr);
+
+PNG files describe monochrome as black being zero and white being
+one. This code would be used if the pixels are supplied with this reversed
+(black being one and white being zero):
+
+ png_set_invert_mono(png_ptr);
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_write_user_transform_fn(png_ptr,
+ write_transform_fn);
+
+You must supply the function
+
+ void write_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+before any of the other transformations are processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function.
+
+ png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
+
+The user_channels and user_depth parameters of this function are ignored
+when writing; you can set them to zero as shown.
+
+You can retrieve the pointer via the function
+png_get_user_transform_ptr(). For example:
+
+ voidp write_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+It is possible to have libpng flush any pending output, either manually,
+or automatically after a certain number of lines have been written. To
+flush the output stream a single time call:
+
+ png_write_flush(png_ptr);
+
+and to have libpng flush the output stream periodically after a certain
+number of scanlines have been written, call:
+
+ png_set_flush(png_ptr, nrows);
+
+Note that the distance between rows is from the last time png_write_flush()
+was called, or the first row of the image if it has never been called.
+So if you write 50 lines, and then png_set_flush 25, it will flush the
+output on the next scanline, and every 25 lines thereafter, unless
+png_write_flush() is called before 25 more lines have been written.
+If nrows is too small (less than about 10 lines for a 640 pixel wide
+RGB image) the image compression may decrease noticeably (although this
+may be acceptable for real-time applications). Infrequent flushing will
+only degrade the compression performance by a few percent over images
+that do not use flushing.
+
+That's it for the transformations. Now you can write the image data.
+The simplest way to do this is in one function call. If have the
+whole image in memory, you can just call png_write_image() and libpng
+will write the image. You will need to pass in an array of pointers to
+each row. This function automatically handles interlacing, so you don't
+need to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_write_rows().
+
+ png_write_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_byte *row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to write the whole image at once, you can
+use png_write_rows() instead. If the file is not interlaced,
+this is simple:
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+row_pointers is the same as in the png_write_image() call.
+
+If you are just writing one row at a time, you can do this with
+row_pointers:
+
+ png_bytep row_pointer = row;
+
+ png_write_row(png_ptr, &row_pointer);
+
+When the file is interlaced, things can get a good deal more
+complicated. The only currently (as of August 1999 -- PNG Specification
+version 1.2, dated July 1999) defined interlacing scheme for PNG files
+is the "Adam7" interlace scheme, that breaks down an
+image into seven smaller images of varying size. libpng will build
+these images for you, or you can do them yourself. If you want to
+build them yourself, see the PNG specification for details of which
+pixels to write when.
+
+If you don't want libpng to handle the interlacing details, just
+use png_set_interlace_handling() and call png_write_rows() the
+correct number of times to write all seven sub-images.
+
+If you want libpng to build the sub-images, call this before you start
+writing any rows:
+
+ number_of_passes =
+ png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+
+Then write the complete image number_of_passes times.
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+As some of these rows are not used, and thus return immediately,
+you may want to read about interlacing in the PNG specification,
+and only update the rows that are actually used.
+
+After you are finished writing the image, you should finish writing
+the file. If you are interested in writing comments or time, you should
+pass an appropriately filled png_info pointer. If you are not interested,
+you can pass NULL.
+
+ png_write_end(png_ptr, info_ptr);
+
+When you are done, you can free all memory used by libpng like this:
+
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+You must free any data you allocated for info_ptr, such as comments,
+palette, or histogram, before the call to png_destroy_write_struct();
+
+For a more compact example of writing a PNG image, see the file example.c.
+
+V. Modifying/Customizing libpng:
+
+There are two issues here. The first is changing how libpng does
+standard things like memory allocation, input/output, and error handling.
+The second deals with more complicated things like adding new chunks,
+adding new transformations, and generally changing how libpng works.
+
+All of the memory allocation, input/output, and error handling in libpng
+goes through callbacks that are user settable. The default routines are
+in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
+these functions, call the appropriate png_set_???_fn() function.
+
+Memory allocation is done through the functions png_large_malloc(),
+png_malloc(), png_realloc(), png_large_free(), and png_free(). These
+currently just call the standard C functions. The large functions must
+handle exactly 64K, but they don't have to handle more than that. If
+your pointers can't access more then 64K at a time, you will want to set
+MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
+memory allocation on a platform will change between applications, these
+functions must be modified in the library at compile time.
+
+Input/Output in libpng is done through png_read() and png_write(),
+which currently just call fread() and fwrite(). The FILE * is stored in
+png_struct and is initialized via png_init_io(). If you wish to change
+the method of I/O, the library supplies callbacks that you can set
+through the function png_set_read_fn() and png_set_write_fn() at run
+time, instead of calling the png_init_io() function.
+These functions
+also provide a void pointer that can be retrieved via the function
+png_get_io_ptr(). For example:
+
+ png_set_read_fn(png_structp read_ptr,
+ voidp read_io_ptr, png_rw_ptr read_data_fn)
+
+ png_set_write_fn(png_structp write_ptr,
+ voidp write_io_ptr, png_rw_ptr write_data_fn,
+ png_flush_ptr output_flush_fn);
+
+ voidp read_io_ptr = png_get_io_ptr(read_ptr);
+ voidp write_io_ptr = png_get_io_ptr(write_ptr);
+
+The replacement I/O functions should have prototypes as follows:
+
+ void user_read_data(png_structp png_ptr,
+ png_bytep data, png_uint_32 length);
+ void user_write_data(png_structp png_ptr,
+ png_bytep data, png_uint_32 length);
+ void user_flush_data(png_structp png_ptr);
+
+Supplying NULL for the read, write, or flush functions sets them back
+to using the default C stream functions. It is an error to read from
+a write stream, and vice versa.
+
+Error handling in libpng is done through png_error() and png_warning().
+Errors handled through png_error() are fatal, meaning that png_error()
+should never return to its caller. Currently, this is handled via
+setjmp() and longjmp(), but you could change this to do things like
+exit() if you should wish. On non-fatal errors, png_warning() is called
+to print a warning message, and then control returns to the calling code.
+By default png_error() and png_warning() print a message on stderr via
+fprintf() unless the library is compiled with PNG_NO_STDIO defined. If
+you wish to change the behavior of the error functions, you will need to
+set up your own message callbacks. These functions are normally supplied
+at the time that the png_struct is created. It is also possible to change
+these functions after png_create_???_struct() has been called by calling:
+
+ png_set_error_fn(png_structp png_ptr,
+ png_voidp error_ptr, png_error_ptr error_fn,
+ png_error_ptr warning_fn);
+
+ png_voidp error_ptr = png_get_error_ptr(png_ptr);
+
+If NULL is supplied for either error_fn or warning_fn, then the libpng
+default function will be used, calling fprintf() and/or longjmp() if a
+problem is encountered. The replacement error functions should have
+parameters as follows:
+
+ void user_error_fn(png_structp png_ptr,
+ png_const_charp error_msg);
+ void user_warning_fn(png_structp png_ptr,
+ png_const_charp warning_msg);
+
+The motivation behind using setjmp() and longjmp() is the C++ throw and
+catch exception handling methods. This makes the code much easier to write,
+as there is no need to check every return code of every function call.
+However, there are some uncertainties about the status of local variables
+after a longjmp, so the user may want to be careful about doing anything after
+setjmp returns non-zero besides returning itself. Consult your compiler
+documentation for more details.
+
+If you need to read or write custom chunks, you will need to get deeper
+into the libpng code, as a mechanism has not yet been supplied for user
+callbacks with custom chunks. First, read the PNG specification, and have
+a first level of understanding of how it works. Pay particular attention
+to the sections that describe chunk names, and look at how other chunks
+were designed, so you can do things similarly. Second, check out the
+sections of libpng that read and write chunks. Try to find a chunk that
+is similar to yours and copy off of it. More details can be found in the
+comments inside the code. A way of handling unknown chunks in a generic
+method, potentially via callback functions, would be best.
+
+If you wish to write your own transformation for the data, look through
+the part of the code that does the transformations, and check out some of
+the simpler ones to get an idea of how they work. Try to find a similar
+transformation to the one you want to add and copy off of it. More details
+can be found in the comments inside the code itself.
+
+Configuring for 16 bit platforms:
+
+You may need to change the png_large_malloc() and png_large_free()
+routines in pngmem.c, as these are required to allocate 64K, although
+there is already support for many of the common DOS compilers. Also,
+you will want to look into zconf.h to tell zlib (and thus libpng) that
+it cannot allocate more then 64K at a time. Even if you can, the memory
+won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
+
+Configuring for DOS:
+
+For DOS users who only have access to the lower 640K, you will
+have to limit zlib's memory usage via a png_set_compression_mem_level()
+call. See zlib.h or zconf.h in the zlib library for more information.
+
+Configuring for Medium Model:
+
+Libpng's support for medium model has been tested on most of the popular
+compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
+defined, and FAR gets defined to far in pngconf.h, and you should be
+all set. Everything in the library (except for zlib's structure) is
+expecting far data. You must use the typedefs with the p or pp on
+the end for pointers (or at least look at them and be careful). Make
+note that the row's of data are defined as png_bytepp, which is an
+unsigned char far * far *.
+
+Configuring for gui/windowing platforms:
+
+You will need to write new error and warning functions that use the GUI
+interface, as described previously, and set them to be the error and
+warning functions at the time that png_create_???_struct() is called,
+in order to have them available during the structure initialization.
+They can be changed later via png_set_error_fn(). On some compilers,
+you may also have to change the memory allocators (png_malloc, etc.).
+
+Configuring for compiler xxx:
+
+All includes for libpng are in pngconf.h. If you need to add/change/delete
+an include, this is the place to do it. The includes that are not
+needed outside libpng are protected by the PNG_INTERNAL definition,
+which is only defined for those routines inside libpng itself. The
+files in libpng proper only include png.h, which includes pngconf.h.
+
+Configuring zlib:
+
+There are special functions to configure the compression. Perhaps the
+most useful one changes the compression level, which currently uses
+input compression values in the range 0 - 9. The library normally
+uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
+have shown that for a large majority of images, compression values in
+the range 3-6 compress nearly as well as higher levels, and do so much
+faster. For online applications it may be desirable to have maximum speed
+(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
+specify no compression (Z_NO_COMPRESSION = 0), but this would create
+files larger than just storing the raw bitmap. You can specify the
+compression level by calling:
+
+ png_set_compression_level(png_ptr, level);
+
+Another useful one is to reduce the memory level used by the library.
+The memory level defaults to 8, but it can be lowered if you are
+short on memory (running DOS, for example, where you only have 640K).
+
+ png_set_compression_mem_level(png_ptr, level);
+
+The other functions are for configuring zlib. They are not recommended
+for normal use and may result in writing an invalid PNG file. See
+zlib.h for more information on what these mean.
+
+ png_set_compression_strategy(png_ptr,
+ strategy);
+ png_set_compression_window_bits(png_ptr,
+ window_bits);
+ png_set_compression_method(png_ptr, method);
+
+Controlling row filtering:
+
+If you want to control whether libpng uses filtering or not, which
+filters are used, and how it goes about picking row filters, you
+can call one of these functions. The selection and configuration
+of row filters can have a significant impact on the size and
+encoding speed and a somewhat lesser impact on the decoding speed
+of an image. Filtering is enabled by default for RGB and grayscale
+images (with and without alpha), but not for paletted images nor
+for any images with bit depths less than 8 bits/pixel.
+
+The 'method' parameter sets the main filtering method, which is
+currently only '0' in the PNG 1.2 specification. The 'filters'
+parameter sets which filter(s), if any, should be used for each
+scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
+to turn filtering on and off, respectively.
+
+Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
+PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
+ORed together '|' to specify one or more filters to use. These
+filters are described in more detail in the PNG specification. If
+you intend to change the filter type during the course of writing
+the image, you should start with flags set for all of the filters
+you intend to use so that libpng can initialize its internal
+structures appropriately for all of the filter types.
+
+ filters = PNG_FILTER_NONE | PNG_FILTER_SUB
+ | PNG_FILTER_UP;
+ png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
+ filters);
+
+It is also possible to influence how libpng chooses from among the
+available filters. This is done in two ways - by telling it how
+important it is to keep the same filter for successive rows, and
+by telling it the relative computational costs of the filters.
+
+ double weights[3] = {1.5, 1.3, 1.1},
+ costs[PNG_FILTER_VALUE_LAST] =
+ {1.0, 1.3, 1.3, 1.5, 1.7};
+
+ png_set_filter_selection(png_ptr,
+ PNG_FILTER_SELECTION_WEIGHTED, 3,
+ weights, costs);
+
+The weights are multiplying factors that indicate to libpng that the
+row filter should be the same for successive rows unless another row filter
+is that many times better than the previous filter. In the above example,
+if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
+"sum of absolute differences" 1.5 x 1.3 times higher than other filters
+and still be chosen, while the NONE filter could have a sum 1.1 times
+higher than other filters and still be chosen. Unspecified weights are
+taken to be 1.0, and the specified weights should probably be declining
+like those above in order to emphasize recent filters over older filters.
+
+The filter costs specify for each filter type a relative decoding cost
+to be considered when selecting row filters. This means that filters
+with higher costs are less likely to be chosen over filters with lower
+costs, unless their "sum of absolute differences" is that much smaller.
+The costs do not necessarily reflect the exact computational speeds of
+the various filters, since this would unduly influence the final image
+size.
+
+Note that the numbers above were invented purely for this example and
+are given only to help explain the function usage. Little testing has
+been done to find optimum values for either the costs or the weights.
+
+Removing unwanted object code:
+
+There are a bunch of #define's in pngconf.h that control what parts of
+libpng are compiled. All the defines end in _SUPPORTED. If you are
+never going to use a capability, you can change the #define to #undef
+before recompiling libpng and save yourself code and data space, or
+you can turn off individual capabilities with defines that begin with
+PNG_NO_.
+
+You can also turn all of the transforms and ancillary chunk capabilities
+off en masse with compiler directives that define
+PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
+or all four,
+along with directives to turn on any of the capabilities that you do
+want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
+the extra transformations but still leave the library fully capable of reading
+and writing PNG files with all known public chunks [except for sPLT].
+Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
+produces a library that is incapable of reading or writing ancillary chunks.
+If you are not using the progressive reading capability, you can
+turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
+this with the INTERLACING capability, which you'll still have).
+
+All the reading and writing specific code are in separate files, so the
+linker should only grab the files it needs. However, if you want to
+make sure, or if you are building a stand alone library, all the
+reading files start with pngr and all the writing files start with
+pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
+are used for both reading and writing, and always need to be included.
+The progressive reader is in pngpread.c
+
+If you are creating or distributing a dynamically linked library (a .so
+or DLL file), you should not remove or disable any parts of the library,
+as this will cause applications linked with different versions of the
+library to fail if they call functions not available in your library.
+The size of the library itself should not be an issue, because only
+those sections that are actually used will be loaded into memory.
+
+Requesting debug printout:
+
+The macro definition PNG_DEBUG can be used to request debugging
+printout. Set it to an integer value in the range 0 to 3. Higher
+numbers result in increasing amounts of debugging information. The
+information is printed to the "stderr" file, unless another file
+name is specified in the PNG_DEBUG_FILE macro definition.
+
+When PNG_DEBUG > 0, the following functions (macros) become available:
+
+ png_debug(level, message)
+ png_debug1(level, message, p1)
+ png_debug2(level, message, p1, p2)
+
+in which "level" is compared to PNG_DEBUG to decide whether to print
+the message, "message" is the formatted string to be printed,
+and p1 and p2 are parameters that are to be embedded in the string
+according to printf-style formatting directives. For example,
+
+ png_debug1(2, "foo=%d\n", foo);
+
+is expanded to
+
+ if(PNG_DEBUG > 2)
+ fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
+
+When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
+can still use PNG_DEBUG to control your own debugging:
+
+ #ifdef PNG_DEBUG
+ fprintf(stderr, ...
+ #endif
+
+When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
+having level = 0 will be printed. There aren't any such statements in
+this version of libpng, but if you insert some they will be printed.
+
+VI. Changes to Libpng from version 0.88
+
+It should be noted that versions of libpng later than 0.96 are not
+distributed by the original libpng author, Guy Schalnat, nor by
+Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
+distributed versions 0.89 through 0.96, but rather by another member
+of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
+still alive and well, but they have moved on to other things.
+
+The old libpng functions png_read_init(), png_write_init(),
+png_info_init(), png_read_destroy(), and png_write_destory() have been
+moved to PNG_INTERNAL in version 0.95 to discourage their use. The
+preferred method of creating and initializing the libpng structures is
+via the png_create_read_struct(), png_create_write_struct(), and
+png_create_info_struct() because they isolate the size of the structures
+from the application, allow version error checking, and also allow the
+use of custom error handling routines during the initialization, which
+the old functions do not. The functions png_read_destroy() and
+png_write_destroy() do not actually free the memory that libpng
+allocated for these structs, but just reset the data structures, so they
+can be used instead of png_destroy_read_struct() and
+png_destroy_write_struct() if you feel there is too much system overhead
+allocating and freeing the png_struct for each image read.
+
+Setting the error callbacks via png_set_message_fn() before
+png_read_init() as was suggested in libpng-0.88 is no longer supported
+because this caused applications that do not use custom error functions
+to fail if the png_ptr was not initialized to zero. It is still possible
+to set the error callbacks AFTER png_read_init(), or to change them with
+png_set_error_fn(), which is essentially the same function, but with a
+new name to force compilation errors with applications that try to use
+the old method.
+
+VII. Y2K Compliance in libpng
+
+October 15, 1999
+
+Since the PNG Development group is an ad-hoc body, we can't make
+an official declaration.
+
+This is your unofficial assurance that libpng from version 0.71 and
+upward through 1.0.5 are Y2K compliant. It is my belief that earlier
+versions were also Y2K compliant.
+
+Libpng only has three year fields. One is a 2-byte unsigned integer that
+will hold years up to 65535. The other two hold the date in text
+format, and will hold years up to 9999.
+
+The integer is
+ "png_uint_16 year" in png_time_struct.
+
+The strings are
+ "png_charp time_buffer" in png_struct and
+ "near_time_buffer", which is a local character string in png.c.
+
+There are seven time-related functions:
+
+ png_convert_to_rfc_1123() in png.c
+ (formerly png_convert_to_rfc_1152() in error)
+ png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
+ png_convert_from_time_t() in pngwrite.c
+ png_get_tIME() in pngget.c
+ png_handle_tIME() in pngrutil.c, called in pngread.c
+ png_set_tIME() in pngset.c
+ png_write_tIME() in pngwutil.c, called in pngwrite.c
+
+All appear to handle dates properly in a Y2K environment. The
+png_convert_from_time_t() function calls gmtime() to convert from system
+clock time, which returns (year - 1900), which we properly convert to
+the full 4-digit year. There is a possibility that applications using
+libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
+function, or that they are incorrectly passing only a 2-digit year
+instead of "year - 1900" into the png_convert_from_struct_tm() function,
+but this is not under our control. The libpng documentation has always
+stated that it works with 4-digit years, and the APIs have been
+documented as such.
+
+The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
+integer to hold the year, and can hold years as large as 65535.
+
+zlib, upon which libpng depends, is also Y2K compliant. It contains
+no date-related code.
+
+
+ Glenn Randers-Pehrson
+ libpng maintainer
+ PNG Development Group
diff --git a/osframework/source/ImageLib/png/libpngpf.3 b/osframework/source/ImageLib/png/libpngpf.3
new file mode 100644
index 0000000..1c64360
--- /dev/null
+++ b/osframework/source/ImageLib/png/libpngpf.3
@@ -0,0 +1,505 @@
+.TH LIBPNGPF 3 October 15, 1999
+.SH NAME
+libpng \- Portable Network Graphics (PNG) Reference Library 1.0.5 - October 15, 1999
+(private functions)
+.SH SYNOPSIS
+\fB#include <png.h>\fP
+
+\fI\fB
+
+\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_size_t png_check_keyword (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charpp \fInew_key\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_create_struct (int \fP\fItype\fP\fB, png_malloc_ptr \fImalloc_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_voidp png_create_struct_2 (int \fItype\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_destroy_struct (png_voidp \fIstruct_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_background (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fP\fItrans_values\fP\fB, png_color_16p \fP\fIbackground\fP\fB, png_color_16p \fP\fIbackground_1\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_bytep \fP\fIgamma_from_1\fP\fB, png_bytep \fP\fIgamma_to_1\fP\fB, png_uint_16pp \fP\fIgamma_16\fP\fB, png_uint_16pp \fP\fIgamma_16_from_1\fP\fB, png_uint_16pp \fP\fIgamma_16_to_1\fP\fB, int \fIgamma_shift\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_dither (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIpalette_lookup\fP\fB, png_bytep \fIdither_lookup\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_expand (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fItrans_value\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_expand_palette (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fInum_trans\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_gamma (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_uint_16pp \fP\fIgamma_16_table\fP\fB, int \fIgamma_shift\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_pack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIbit_depth\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_read_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_read_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fP\fIpass\fP\fB, png_uint_32 \fItransformations\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_shift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIbit_depth\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_strip_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_unshift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIsig_bits\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB
+
+\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_IEND (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_process_IDAT_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_fill_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_restore_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_filter_row (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIprev_row\fP\fB, int \fIfilter\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fIcolor_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_IDAT (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fP\fIfilter_type\fP\fB, int \fIinterlace_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_pixels_per_unit\fP\fB, png_uint_32 \fP\fIy_pixels_per_unit\fP\fB, int \fIunit_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_uint_32 \fInum_pal\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fP\fIsbit\fP\fB, int \fIcolor_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fItext_len\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fP\fInumber\fP\fB, int \fIcolor_type\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_write_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fP\fItext_len\fP\fB, int \fIcompression\fP\fB);\fP
+
+\fI\fB
+
+\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
+
+\fI\fB
+
+\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
+
+\fI\fB
+
+.SH DESCRIPTION
+The functions listed above are used privately by libpng
+and are not recommended for use by applications. They
+are listed alphabetically here as an aid to libpng maintainers.
+See png.h for more information on these functions.
+
+.SH SEE ALSO
+libpng(3), png(5)
+.SH AUTHOR
+Glenn Randers-Pehrson
diff --git a/osframework/source/ImageLib/png/license b/osframework/source/ImageLib/png/license
new file mode 100644
index 0000000..1a44124
--- /dev/null
+++ b/osframework/source/ImageLib/png/license
@@ -0,0 +1,70 @@
+COPYRIGHT NOTICE:
+
+Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+(libpng versions 0.5, May 1995, through 0.89c, May 1996)
+Copyright (c) 1996, 1997 Andreas Dilger
+(libpng versions 0.90, December 1996, through 0.96, May 1997)
+Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+(libpng versions 0.97, January 1998, through 1.0.5, October 15, 1999)
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+ John Bowler
+ Kevin Bracey
+ Sam Bushell
+ Andreas Dilger
+ Magnus Holmgren
+ Tom Lane
+ Dave Martindale
+ Glenn Randers-Pehrson
+ Greg Roelofs
+ Guy Eric Schalnat
+ Paul Schmidt
+ Tom Tanner
+ Willem van Schaik
+ Tim Wegner
+
+The PNG Reference Library is supplied "AS IS". The Contributing Authors
+and Group 42, Inc. disclaim all warranties, expressed or implied,
+including, without limitation, the warranties of merchantability and of
+fitness for any purpose. The Contributing Authors and Group 42, Inc.
+assume no liability for direct, indirect, incidental, special, exemplary,
+or consequential damages, which may result from the use of the PNG
+Reference Library, even if advised of the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+ 1. The origin of this source code must not be
+ misrepresented.
+
+ 2. Altered versions must be plainly marked as such
+ and must not be misrepresented as being the
+ original source.
+
+ 3. This Copyright notice may not be removed or
+ altered from any source or altered source
+ distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit, without
+fee, and encourage the use of this source code as a component to
+supporting the PNG file format in commercial products. If you use this
+source code in a product, acknowledgment is not required but would be
+appreciated.
+
+A "png_get_copyright" function is available, for convenient use in "about"
+boxes and the like:
+
+ printf("%s",png_get_copyright(NULL));
+
+Also, the PNG logo (in PNG format, of course) is supplied in the
+file "pngnow.png".
+
+Libpng is OSI Certified Open Source Software. OSI Certified is a
+certification mark of the Open Source Initiative.
+
+Glenn Randers-Pehrson
+randeg@alum.rpi.edu
+October 15, 1999
diff --git a/osframework/source/ImageLib/png/png.5 b/osframework/source/ImageLib/png/png.5
new file mode 100644
index 0000000..bea166d
--- /dev/null
+++ b/osframework/source/ImageLib/png/png.5
@@ -0,0 +1,58 @@
+.TH PNG 5 "October 15, 1999"
+.SH NAME
+png \- Portable Network Graphics (PNG) format
+.SH DESCRIPTION
+PNG (Portable Network Graphics) is an extensible file format for the
+lossless, portable, well-compressed storage of raster images. PNG provides
+a patent-free replacement for GIF and can also replace many
+common uses of TIFF. Indexed-color, grayscale, and truecolor images are
+supported, plus an optional alpha channel. Sample depths range from
+1 to 16 bits.
+.br
+
+PNG is designed to work well in online viewing applications, such as the
+World Wide Web, so it is fully streamable with a progressive display
+option. PNG is robust, providing both full file integrity checking and
+fast, simple detection of common transmission errors. Also, PNG can store
+gamma and chromaticity data for improved color matching on heterogeneous
+platforms.
+
+.SH "SEE ALSO"
+.IR libpng(3), zlib(3), deflate(5), and zlib(5)
+.LP
+PNG 1.1 specification, January 1999:
+.IP
+.br
+http://www.cdrom.com/pub/png
+.LP
+PNG 1.0 specification, October 1996:
+.IP
+.br
+RFC 2083
+.IP
+.br
+ftp://ds.internic.net/rfc/rfc2083.txt
+.br
+or (as a W3C Recommendation) at
+.br
+http://www.w3.org/TR/REC-png.html
+.SH AUTHORS
+This man page: Glenn Randers-Pehrson
+.LP
+Portable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):
+Glenn Randers-Pehrson and others (png-list@ccrc.wustl.edu).
+.LP
+Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
+Thomas Boutell and others (png-list@ccrc.wustl.edu).
+.LP
+
+
+.SH COPYRIGHT NOTICE
+The PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.
+See the specification for conditions of use and distribution.
+.LP
+The PNG-1.0 specification is copyright (c) 1996 Massachussets Institute of
+Technology. See the specification for conditions of use and distribution.
+.LP
+.\" end of man page
+
diff --git a/osframework/source/ImageLib/png/png.c b/osframework/source/ImageLib/png/png.c
new file mode 100644
index 0000000..03bcefb
--- /dev/null
+++ b/osframework/source/ImageLib/png/png.c
@@ -0,0 +1,370 @@
+
+/* png.c - location for general purpose libpng functions
+ *
+ * libpng version 1.0.5 - October 15, 1999
+ * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+ * Copyright (c) 1996, 1997 Andreas Dilger
+ * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ *
+ */
+
+#define PNG_INTERNAL
+#define PNG_NO_EXTERN
+#include "png.h"
+
+PNG_GET_HEADER
+
+/* Version information for C files. This had better match the version
+ * string defined in png.h.
+ */
+
+char png_libpng_ver[12] = "1.0.5";
+
+/* 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 = (png_byte)(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 might be removed in the
+ * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
+ */
+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 */
+
+png_charp
+png_get_copyright(png_structp png_ptr)
+{
+ if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
+ return ("\n libpng version 1.0.5 - October 15, 1999\n\
+ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
+ Copyright (c) 1996, 1997 Andreas Dilger\n\
+ Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n");
+ return ("");
+}
+
+/* Generate a compiler error if there is an old png.h in the search path. */
+void
+png_check_version
+ (version_1_0_5 png_h_is_not_version_1_0_5)
+{
+ if(png_h_is_not_version_1_0_5 == NULL)
+ return;
+}
diff --git a/osframework/source/ImageLib/png/png.h b/osframework/source/ImageLib/png/png.h
new file mode 100644
index 0000000..77e94e0
--- /dev/null
+++ b/osframework/source/ImageLib/png/png.h
@@ -0,0 +1,2317 @@
+
+/* png.h - header file for PNG reference library
+ *
+ * libpng version 1.0.5 - October 15, 1999
+ * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+ * Copyright (c) 1996, 1997 Andreas Dilger
+ * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ *
+ * Authors and maintainers:
+ * libpng versions 0.71, May 1995, through 0.89c, May 1996: Guy Schalnat
+ * libpng versions 0.90, December 1996, through 0.96, May 1997: Andreas Dilger
+ * libpng versions 0.97, January 1998, through 1.0.5 - October 15, 1999: Glenn
+ * See also "Contributing Authors", below.
+ *
+ * Y2K compliance in libpng:
+ * =========================
+ *
+ * October 15, 1999
+ *
+ * Since the PNG Development group is an ad-hoc body, we can't make
+ * an official declaration.
+ *
+ * This is your unofficial assurance that libpng from version 0.71 and
+ * upward through 1.0.5 are Y2K compliant. It is my belief that earlier
+ * versions were also Y2K compliant.
+ *
+ * Libpng only has three year fields. One is a 2-byte unsigned integer
+ * that will hold years up to 65535. The other two hold the date in text
+ * format, and will hold years up to 9999.
+ *
+ * The integer is
+ * "png_uint_16 year" in png_time_struct.
+ *
+ * The strings are
+ * "png_charp time_buffer" in png_struct and
+ * "near_time_buffer", which is a local character string in png.c.
+ *
+ * There are seven time-related functions:
+ * png.c: png_convert_to_rfc_1123() in png.c
+ * (formerly png_convert_to_rfc_1152() in error)
+ * png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
+ * png_convert_from_time_t() in pngwrite.c
+ * png_get_tIME() in pngget.c
+ * png_handle_tIME() in pngrutil.c, called in pngread.c
+ * png_set_tIME() in pngset.c
+ * png_write_tIME() in pngwutil.c, called in pngwrite.c
+ *
+ * All handle dates properly in a Y2K environment. The
+ * png_convert_from_time_t() function calls gmtime() to convert from system
+ * clock time, which returns (year - 1900), which we properly convert to
+ * the full 4-digit year. There is a possibility that applications using
+ * libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
+ * function, or that they are incorrectly passing only a 2-digit year
+ * instead of "year - 1900" into the png_convert_from_struct_tm() function,
+ * but this is not under our control. The libpng documentation has always
+ * stated that it works with 4-digit years, and the APIs have been
+ * documented as such.
+ *
+ * The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
+ * integer to hold the year, and can hold years as large as 65535.
+ *
+ * zlib, upon which libpng depends, is also Y2K compliant. It contains
+ * no date-related code.
+ *
+ * Glenn Randers-Pehrson
+ * libpng maintainer
+ * PNG Development Group
+ *
+ * Note about libpng version numbers:
+ *
+ * Due to various miscommunications, unforeseen code incompatibilities
+ * and occasional factors outside the authors' control, version numbering
+ * on the library has not always been consistent and straightforward.
+ * The following table summarizes matters since version 0.89c, which was
+ * the first widely used release:
+ *
+ * source png.h png.h shared-lib
+ * version string int version
+ * ------- ------ ----- ----------
+ * 0.89c ("1.0 beta 3") 0.89 89 1.0.89
+ * 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
+ * 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
+ * 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
+ * 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
+ * 0.97c 0.97 97 2.0.97
+ * 0.98 0.98 98 2.0.98
+ * 0.99 0.99 98 2.0.99
+ * 0.99a-m 0.99 99 2.0.99
+ * 1.00 1.00 100 2.1.0 [100 should be 10000]
+ * 1.0.0 1.0.0 100 2.1.0 [100 should be 10000]
+ * 1.0.1 1.0.1 10001 2.1.0
+ * 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
+ * 1.0.2 1.0.2 10002 2.1.0.2
+ * 1.0.2a-b 1.0.2a-b 10003 2.1.0.2a-b
+ * 1.0.3 1.0.3 10003 2.1.0.3
+ * 1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
+ * 1.0.4 1.0.4 10004 2.1.0.4
+ * 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
+ * 1.0.5 1.0.5 10005 2.1.0.5
+ *
+ * Henceforth the source version will match the shared-library minor
+ * and patch numbers; the shared-library major version number will be
+ * used for changes in backward compatibility, as it is intended. The
+ * PNG_PNGLIB_VER macro, which is not used within libpng but is available
+ * for applications, is an unsigned integer of the form xyyzz corresponding
+ * to the source version x.y.z (leading zeros in y and z). Internal
+ * png-group versions (x.y.z[a-z]) will be given the next higher number.
+ *
+ * See libpng.txt or libpng.3 for more information. The PNG specification
+ * is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
+ * and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
+ */
+
+/*
+ * COPYRIGHT NOTICE:
+ *
+ * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+ * (libpng versions 0.5, May 1995, through 0.89c, May 1996)
+ * Copyright (c) 1996, 1997 Andreas Dilger
+ * (libpng versions 0.90, December 1996, through 0.96, May 1997)
+ * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ * (libpng versions 0.97, January 1998, through 1.0.5, October 15, 1999)
+ *
+ * For the purposes of this copyright and license, "Contributing Authors"
+ * is defined as the following set of individuals:
+ *
+ * John Bowler
+ * Kevin Bracey
+ * Sam Bushell
+ * Andreas Dilger
+ * Magnus Holmgren
+ * Tom Lane
+ * Dave Martindale
+ * Glenn Randers-Pehrson
+ * Greg Roelofs
+ * Guy Eric Schalnat
+ * Paul Schmidt
+ * Tom Tanner
+ * Willem van Schaik
+ * Tim Wegner
+ *
+ * The PNG Reference Library is supplied "AS IS". The Contributing Authors
+ * and Group 42, Inc. disclaim all warranties, expressed or implied,
+ * including, without limitation, the warranties of merchantability and of
+ * fitness for any purpose. The Contributing Authors and Group 42, Inc.
+ * assume no liability for direct, indirect, incidental, special, exemplary,
+ * or consequential damages, which may result from the use of the PNG
+ * Reference Library, even if advised of the possibility of such damage.
+ *
+ * Permission is hereby granted to use, copy, modify, and distribute this
+ * source code, or portions hereof, for any purpose, without fee, subject
+ * to the following restrictions:
+ *
+ * 1. The origin of this source code must not be
+ * misrepresented.
+ *
+ * 2. Altered versions must be plainly marked as such
+ * and must not be misrepresented as being the
+ * original source.
+ *
+ * 3. This Copyright notice may not be removed or
+ * altered from any source or altered source
+ * distribution.
+ *
+ * The Contributing Authors and Group 42, Inc. specifically permit, without
+ * fee, and encourage the use of this source code as a component to
+ * supporting the PNG file format in commercial products. If you use this
+ * source code in a product, acknowledgment is not required but would be
+ * appreciated.
+ */
+
+/*
+ * A "png_get_copyright" function is available, for convenient use in "about"
+ * boxes and the like:
+ *
+ * printf("%s",png_get_copyright(NULL));
+ *
+ * Also, the PNG logo (in PNG format, of course) is supplied in the
+ * file "pngnow.png".
+ */
+
+/*
+ * Libpng is OSI Certified Open Source Software. OSI Certified is a
+ * certification mark of the Open Source Initiative.
+ */
+
+/*
+ * The contributing authors would like to thank all those who helped
+ * with testing, bug fixes, and patience. This wouldn't have been
+ * possible without all of you.
+ *
+ * Thanks to Frank J. T. Wojcik for helping with the documentation.
+ */
+
+#ifndef _PNG_H
+#define _PNG_H
+
+/* This is not the place to learn how to use libpng. The file libpng.txt
+ * describes how to use libpng, and the file example.c summarizes it
+ * with some code on which to build. This file is useful for looking
+ * at the actual function definitions and structure components.
+ */
+
+/* include the compression library's header */
+#include "../zlib/zlib.h"
+
+/* include all user configurable info */
+#include "pngconf.h"
+
+/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* This file is arranged in several sections. The first section contains
+ * structure and type definitions. The second section contains the external
+ * library functions, while the third has the internal library functions,
+ * which applications aren't expected to use directly.
+ */
+
+/* Version information for png.h - this should match the version in png.c */
+#define PNG_LIBPNG_VER_STRING "1.0.5"
+
+/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
+ * We must not include leading zeros.
+ * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
+ * version 1.0.0 was mis-numbered 100 instead of 10000). From
+ * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=bugfix */
+#define PNG_LIBPNG_VER 10005 /* 1.0.5 */
+
+/* Note to maintainer: update this number in scripts/pngdef.pas as well */
+
+/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
+#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
+/* Version information for C files, stored in png.c. This had better match
+ * the version above.
+ */
+extern char png_libpng_ver[12]; /* need room for 99.99.99aa */
+
+/* Structures to facilitate easy interlacing. See png.c for more details */
+extern int FARDATA png_pass_start[7];
+extern int FARDATA png_pass_inc[7];
+extern int FARDATA png_pass_ystart[7];
+extern int FARDATA png_pass_yinc[7];
+extern int FARDATA png_pass_mask[7];
+extern int FARDATA png_pass_dsp_mask[7];
+/* These aren't currently used. If you need them, see png.c for more details
+extern int FARDATA png_pass_width[7];
+extern int FARDATA png_pass_height[7];
+*/
+
+#endif /* PNG_NO_EXTERN */
+
+/* Three color definitions. The order of the red, green, and blue, (and the
+ * exact size) is not important, although the size of the fields need to
+ * be png_byte or png_uint_16 (as defined below).
+ */
+typedef struct png_color_struct
+{
+ png_byte red;
+ png_byte green;
+ png_byte blue;
+} png_color;
+typedef png_color FAR * png_colorp;
+typedef png_color FAR * FAR * png_colorpp;
+
+typedef struct png_color_16_struct
+{
+ png_byte index; /* used for palette files */
+ png_uint_16 red; /* for use in red green blue files */
+ png_uint_16 green;
+ png_uint_16 blue;
+ png_uint_16 gray; /* for use in grayscale files */
+} png_color_16;
+typedef png_color_16 FAR * png_color_16p;
+typedef png_color_16 FAR * FAR * png_color_16pp;
+
+typedef struct png_color_8_struct
+{
+ png_byte red; /* for use in red green blue files */
+ png_byte green;
+ png_byte blue;
+ png_byte gray; /* for use in grayscale files */
+ png_byte alpha; /* for alpha channel files */
+} png_color_8;
+typedef png_color_8 FAR * png_color_8p;
+typedef png_color_8 FAR * FAR * png_color_8pp;
+
+/* png_text holds the text in a PNG file, and whether they are compressed
+ in the PNG file or not. The "text" field points to a regular C string. */
+typedef struct png_text_struct
+{
+ int compression; /* compression value, see PNG_TEXT_COMPRESSION_ */
+ png_charp key; /* keyword, 1-79 character description of "text" */
+ png_charp text; /* comment, may be an empty string (ie "") */
+ png_size_t text_length; /* length of "text" field */
+} png_text;
+typedef png_text FAR * png_textp;
+typedef png_text FAR * FAR * png_textpp;
+
+/* Supported compression types for text in PNG files (tEXt, and zTXt).
+ * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */
+#define PNG_TEXT_COMPRESSION_NONE_WR -3
+#define PNG_TEXT_COMPRESSION_zTXt_WR -2
+#define PNG_TEXT_COMPRESSION_NONE -1
+#define PNG_TEXT_COMPRESSION_zTXt 0
+#define PNG_TEXT_COMPRESSION_LAST 1 /* Not a valid value */
+
+/* png_time is a way to hold the time in an machine independent way.
+ * Two conversions are provided, both from time_t and struct tm. There
+ * is no portable way to convert to either of these structures, as far
+ * as I know. If you know of a portable way, send it to me. As a side
+ * note - PNG is Year 2000 compliant!
+ */
+typedef struct png_time_struct
+{
+ png_uint_16 year; /* full year, as in, 1995 */
+ png_byte month; /* month of year, 1 - 12 */
+ png_byte day; /* day of month, 1 - 31 */
+ png_byte hour; /* hour of day, 0 - 23 */
+ png_byte minute; /* minute of hour, 0 - 59 */
+ png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
+} png_time;
+typedef png_time FAR * png_timep;
+typedef png_time FAR * FAR * png_timepp;
+
+/* png_info is a structure that holds the information in a PNG file so
+ * that the application can find out the characteristics of the image.
+ * If you are reading the file, this structure will tell you what is
+ * in the PNG file. If you are writing the file, fill in the information
+ * you want to put into the PNG file, then call png_write_info().
+ * The names chosen should be very close to the PNG specification, so
+ * consult that document for information about the meaning of each field.
+ *
+ * With libpng < 0.95, it was only possible to directly set and read the
+ * the values in the png_info_struct, which meant that the contents and
+ * order of the values had to remain fixed. With libpng 0.95 and later,
+ * however, there are now functions that abstract the contents of
+ * png_info_struct from the application, so this makes it easier to use
+ * libpng with dynamic libraries, and even makes it possible to use
+ * libraries that don't have all of the libpng ancillary chunk-handing
+ * functionality.
+ *
+ * In any case, the order of the parameters in png_info_struct should NOT
+ * be changed for as long as possible to keep compatibility with applications
+ * that use the old direct-access method with png_info_struct.
+ */
+typedef struct png_info_struct
+{
+ /* the following are necessary for every PNG file */
+ png_uint_32 width; /* width of image in pixels (from IHDR) */
+ png_uint_32 height; /* height of image in pixels (from IHDR) */
+ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
+ png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
+ png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
+ png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
+ png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
+ png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
+ png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
+ png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
+ png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
+ png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+
+ /* The following is informational only on read, and not used on writes. */
+ png_byte channels; /* number of data channels per pixel (1, 3, 4)*/
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte spare_byte; /* to align the data, and for future use */
+ png_byte signature[8]; /* magic bytes read by libpng from start of file */
+
+ /* The rest of the data is optional. If you are reading, check the
+ * valid field to see if the information in these are valid. If you
+ * are writing, set the valid field to those chunks you want written,
+ * and initialize the appropriate fields below.
+ */
+
+#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) || \
+ defined(PNG_READ_GAMMA_SUPPORTED)
+ /* The gAMA chunk describes the gamma characteristics of the system
+ * on which the image was created, normally in the range [1.0, 2.5].
+ * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
+ */
+ float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
+#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
+
+#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
+ /* GR-P, 0.96a */
+ /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
+ png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
+#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
+
+#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
+ defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+ /* The tEXt and zTXt chunks contain human-readable textual data in
+ * uncompressed and compressed forms, respectively. The data in "text"
+ * is an array of pointers to uncompressed, null-terminated C strings.
+ * Each chunk has a keyword that describes the textual data contained
+ * in that chunk. Keywords are not required to be unique, and the text
+ * string may be empty. Any number of text chunks may be in an image.
+ */
+ int num_text; /* number of comments read/to write */
+ int max_text; /* current size of text array */
+ png_textp text; /* array of comments read/to write */
+#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
+#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
+ /* The tIME chunk holds the last time the displayed image data was
+ * modified. See the png_time struct for the contents of this struct.
+ */
+ png_time mod_time;
+#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
+#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
+ /* The sBIT chunk specifies the number of significant high-order bits
+ * in the pixel data. Values are in the range [1, bit_depth], and are
+ * only specified for the channels in the pixel data. The contents of
+ * the low-order bits is not specified. Data is valid if
+ * (valid & PNG_INFO_sBIT) is non-zero.
+ */
+ png_color_8 sig_bit; /* significant bits in color channels */
+#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
+#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
+ defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ /* The tRNS chunk supplies transparency data for paletted images and
+ * other image types that don't need a full alpha channel. There are
+ * "num_trans" transparency values for a paletted image, stored in the
+ * same order as the palette colors, starting from index 0. Values
+ * for the data are in the range [0, 255], ranging from fully transparent
+ * to fully opaque, respectively. For non-paletted images, there is a
+ * single color specified that should be treated as fully transparent.
+ * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
+ */
+ png_bytep trans; /* transparent values for paletted image */
+ png_color_16 trans_values; /* transparent color for non-palette image */
+#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
+#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) || \
+ defined(PNG_READ_BACKGROUND_SUPPORTED)
+ /* The bKGD chunk gives the suggested image background color if the
+ * display program does not have its own background color and the image
+ * is needs to composited onto a background before display. The colors
+ * in "background" are normally in the same color space/depth as the
+ * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
+ */
+ png_color_16 background;
+#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
+#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
+ /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
+ * and downwards from the top-left corner of the display, page, or other
+ * application-specific co-ordinate space. See the PNG_OFFSET_ defines
+ * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
+ */
+ png_uint_32 x_offset; /* x offset on page */
+ png_uint_32 y_offset; /* y offset on page */
+ png_byte offset_unit_type; /* offset units type */
+#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
+#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
+ /* The pHYs chunk gives the physical pixel density of the image for
+ * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
+ * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
+ */
+ png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
+ png_uint_32 y_pixels_per_unit; /* vertical pixel density */
+ png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
+#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
+#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
+ /* The hIST chunk contains the relative frequency or importance of the
+ * various palette entries, so that a viewer can intelligently select a
+ * reduced-color palette, if required. Data is an array of "num_palette"
+ * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
+ * is non-zero.
+ */
+ png_uint_16p hist;
+#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
+#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
+ /* The cHRM chunk describes the CIE color characteristics of the monitor
+ * on which the PNG was created. This data allows the viewer to do gamut
+ * mapping of the input image to ensure that the viewer sees the same
+ * colors in the image as the creator. Values are in the range
+ * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
+ */
+ float x_white;
+ float y_white;
+ float x_red;
+ float y_red;
+ float x_green;
+ float y_green;
+ float x_blue;
+ float y_blue;
+#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
+#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
+ /* The pCAL chunk describes a transformation between the stored pixel
+ * values and original physcical data values used to create the image.
+ * The integer range [0, 2^bit_depth - 1] maps to the floating-point
+ * range given by [pcal_X0, pcal_X1], and are further transformed by a
+ * (possibly non-linear) transformation function given by "pcal_type"
+ * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
+ * defines below, and the PNG-Group's Scientific Visualization extension
+ * chunks document png-scivis-19970203 for a complete description of the
+ * transformations and how they should be implemented, as well as the
+ * png-extensions document for a description of the ASCII parameter
+ * strings. Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
+ */
+ png_charp pcal_purpose; /* pCAL chunk description string */
+ png_int_32 pcal_X0; /* minimum value */
+ png_int_32 pcal_X1; /* maximum value */
+ png_charp pcal_units; /* Latin-1 string giving physical units */
+ png_charpp pcal_params; /* ASCII strings containing parameter values */
+ png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
+ png_byte pcal_nparams; /* number of parameters given in pcal_params */
+#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
+} png_info;
+typedef png_info FAR * png_infop;
+typedef png_info FAR * FAR * png_infopp;
+
+/* Maximum positive integer used in PNG is (2^31)-1 */
+#define PNG_MAX_UINT ((png_uint_32)0x7fffffffL)
+
+/* These describe the color_type field in png_info. */
+/* color type masks */
+#define PNG_COLOR_MASK_PALETTE 1
+#define PNG_COLOR_MASK_COLOR 2
+#define PNG_COLOR_MASK_ALPHA 4
+
+/* color types. Note that not all combinations are legal */
+#define PNG_COLOR_TYPE_GRAY 0
+#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
+#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
+#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
+#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
+
+/* This is for compression type. PNG 1.0-1.2 only define the single type. */
+#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
+#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
+
+/* This is for filter type. PNG 1.0-1.2 only define the single type. */
+#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
+#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
+
+/* These are for the interlacing type. These values should NOT be changed. */
+#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
+#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
+#define PNG_INTERLACE_LAST 2 /* Not a valid value */
+
+/* These are for the oFFs chunk. These values should NOT be changed. */
+#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
+#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
+#define PNG_OFFSET_LAST 2 /* Not a valid value */
+
+/* These are for the pCAL chunk. These values should NOT be changed. */
+#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
+#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
+#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
+#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
+#define PNG_EQUATION_LAST 4 /* Not a valid value */
+
+/* These are for the pHYs chunk. These values should NOT be changed. */
+#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
+#define PNG_RESOLUTION_METER 1 /* pixels/meter */
+#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
+
+/* These are for the sRGB chunk. These values should NOT be changed. */
+#define PNG_sRGB_INTENT_SATURATION 0
+#define PNG_sRGB_INTENT_PERCEPTUAL 1
+#define PNG_sRGB_INTENT_ABSOLUTE 2
+#define PNG_sRGB_INTENT_RELATIVE 3
+#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
+
+
+
+/* These determine if an ancillary chunk's data has been successfully read
+ * from the PNG header, or if the application has filled in the corresponding
+ * data in the info_struct to be written into the output file. The values
+ * of the PNG_INFO_<chunk> defines should NOT be changed.
+ */
+#define PNG_INFO_gAMA 0x0001
+#define PNG_INFO_sBIT 0x0002
+#define PNG_INFO_cHRM 0x0004
+#define PNG_INFO_PLTE 0x0008
+#define PNG_INFO_tRNS 0x0010
+#define PNG_INFO_bKGD 0x0020
+#define PNG_INFO_hIST 0x0040
+#define PNG_INFO_pHYs 0x0080
+#define PNG_INFO_oFFs 0x0100
+#define PNG_INFO_tIME 0x0200
+#define PNG_INFO_pCAL 0x0400
+#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
+
+/* This is used for the transformation routines, as some of them
+ * change these values for the row. It also should enable using
+ * the routines for other purposes.
+ */
+typedef struct png_row_info_struct
+{
+ png_uint_32 width; /* width of row */
+ png_uint_32 rowbytes; /* number of bytes in row */
+ png_byte color_type; /* color type of row */
+ png_byte bit_depth; /* bit depth of row */
+ png_byte channels; /* number of channels (1, 2, 3, or 4) */
+ png_byte pixel_depth; /* bits per pixel (depth * channels) */
+} png_row_info;
+
+typedef png_row_info FAR * png_row_infop;
+typedef png_row_info FAR * FAR * png_row_infopp;
+
+/* These are the function types for the I/O functions and for the functions
+ * that allow the user to override the default I/O functions with his or her
+ * own. The png_error_ptr type should match that of user-supplied warning
+ * and error functions, while the png_rw_ptr type should match that of the
+ * user read/write data functions.
+ */
+typedef struct png_struct_def png_struct;
+typedef png_struct FAR * png_structp;
+
+typedef void (*png_error_ptr) PNGARG((png_structp, png_const_charp));
+typedef void (*png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
+typedef void (*png_flush_ptr) PNGARG((png_structp));
+typedef void (*png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
+typedef void (*png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+typedef void (*png_progressive_info_ptr) PNGARG((png_structp, png_infop));
+typedef void (*png_progressive_end_ptr) PNGARG((png_structp, png_infop));
+typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
+ png_uint_32, int));
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
+ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+typedef void (*png_user_transform_ptr) PNGARG((png_structp,
+ png_row_infop, png_bytep));
+#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
+
+typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
+typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
+
+/* The structure that holds the information to read and write PNG files.
+ * The only people who need to care about what is inside of this are the
+ * people who will be modifying the library for their own special needs.
+ * It should NOT be accessed directly by an application, except to store
+ * the jmp_buf.
+ */
+
+struct png_struct_def
+{
+ jmp_buf jmpbuf; /* used in png_error */
+
+ png_error_ptr error_fn; /* function for printing errors and aborting */
+ png_error_ptr warning_fn; /* function for printing warnings */
+ png_voidp error_ptr; /* user supplied struct for error functions */
+ png_rw_ptr write_data_fn; /* function for writing output data */
+ png_rw_ptr read_data_fn; /* function for reading input data */
+ png_voidp io_ptr; /* ptr to application struct for I/O functions*/
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ png_user_transform_ptr read_user_transform_fn; /* user read transform */
+#endif
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+ png_user_transform_ptr write_user_transform_fn; /* user write transform */
+#endif
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
+ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+ png_voidp user_transform_ptr; /* user supplied struct for user transform */
+ png_byte user_transform_depth; /* bit depth of user transformed pixels */
+ png_byte user_transform_channels; /* channels in user transformed pixels */
+#endif
+
+ png_uint_32 mode; /* tells us where we are in the PNG file */
+ png_uint_32 flags; /* flags indicating various things to libpng */
+ png_uint_32 transformations; /* which transformations to perform */
+
+ z_stream zstream; /* pointer to decompression structure (below) */
+ png_bytep zbuf; /* buffer for zlib */
+ png_size_t zbuf_size; /* size of zbuf */
+ int zlib_level; /* holds zlib compression level */
+ int zlib_method; /* holds zlib compression method */
+ int zlib_window_bits; /* holds zlib compression window bits */
+ int zlib_mem_level; /* holds zlib compression memory level */
+ int zlib_strategy; /* holds zlib compression strategy */
+
+ png_uint_32 width; /* width of image in pixels */
+ png_uint_32 height; /* height of image in pixels */
+ png_uint_32 num_rows; /* number of rows in current pass */
+ png_uint_32 usr_width; /* width of row at start of write */
+ png_uint_32 rowbytes; /* size of row in bytes */
+ png_uint_32 irowbytes; /* size of current interlaced row in bytes */
+ png_uint_32 iwidth; /* width of current interlaced row in pixels */
+ png_uint_32 row_number; /* current row in interlace pass */
+ png_bytep prev_row; /* buffer to save previous (unfiltered) row */
+ png_bytep row_buf; /* buffer to save current (unfiltered) row */
+ png_bytep sub_row; /* buffer to save "sub" row when filtering */
+ png_bytep up_row; /* buffer to save "up" row when filtering */
+ png_bytep avg_row; /* buffer to save "avg" row when filtering */
+ png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
+ png_row_info row_info; /* used for transformation routines */
+
+ png_uint_32 idat_size; /* current IDAT size for read */
+ png_uint_32 crc; /* current chunk CRC value */
+ png_colorp palette; /* palette from the input file */
+ png_uint_16 num_palette; /* number of color entries in palette */
+ png_uint_16 num_trans; /* number of transparency values */
+ png_byte chunk_name[5]; /* null-terminated name of current chunk */
+ png_byte compression; /* file compression type (always 0) */
+ png_byte filter; /* file filter type (always 0) */
+ png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+ png_byte pass; /* current interlace pass (0 - 6) */
+ png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
+ png_byte color_type; /* color type of file */
+ png_byte bit_depth; /* bit depth of file */
+ png_byte usr_bit_depth; /* bit depth of users row */
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte channels; /* number of channels in file */
+ png_byte usr_channels; /* channels at start of write */
+ png_byte sig_bytes; /* magic bytes read/written from start of file */
+
+#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
+ png_uint_16 filler; /* filler bytes for pixel expansion */
+#endif /* PNG_READ_FILLER_SUPPORTED */
+#if defined(PNG_READ_bKGD_SUPPORTED)
+ png_byte background_gamma_type;
+ float background_gamma;
+ png_color_16 background; /* background color in screen gamma space */
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ png_color_16 background_1; /* background normalized to gamma 1.0 */
+#endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
+#endif /* PNG_READ_bKGD_SUPPORTED */
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+ png_flush_ptr output_flush_fn;/* Function for flushing output */
+ png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
+ png_uint_32 flush_rows; /* number of rows written since last flush */
+#endif /* PNG_WRITE_FLUSH_SUPPORTED */
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
+ float gamma; /* file gamma value */
+ float screen_gamma; /* screen gamma value (display_exponent) */
+#endif /* PNG_READ_GAMMA_SUPPORTED */
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ png_bytep gamma_table; /* gamma table for 8-bit depth files */
+ png_bytep gamma_from_1; /* converts from 1.0 to screen */
+ png_bytep gamma_to_1; /* converts from file to 1.0 */
+ png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
+ png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
+ png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
+#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_WRITE_GAMMA_SUPPORTED */
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
+ png_color_8 sig_bit; /* significant bits in each available channel */
+#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_READ_sBIT_SUPPORTED */
+#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
+ png_color_8 shift; /* shift for significant bit tranformation */
+#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
+#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
+ || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ png_bytep trans; /* transparency values for paletted files */
+ png_color_16 trans_values; /* transparency values for non-paletted files */
+#endif /* PNG_READ|WRITE_tRNS_SUPPORTED||PNG_READ_EXPAND|BACKGROUND_SUPPORTED */
+ png_read_status_ptr read_row_fn; /* called after each row is decoded */
+ png_write_status_ptr write_row_fn; /* called after each row is encoded */
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+ png_progressive_info_ptr info_fn; /* called after header data fully read */
+ png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
+ png_progressive_end_ptr end_fn; /* called after image is complete */
+ png_bytep save_buffer_ptr; /* current location in save_buffer */
+ png_bytep save_buffer; /* buffer for previously read data */
+ png_bytep current_buffer_ptr; /* current location in current_buffer */
+ png_bytep current_buffer; /* buffer for recently used data */
+ png_uint_32 push_length; /* size of current input chunk */
+ png_uint_32 skip_length; /* bytes to skip in input data */
+ png_size_t save_buffer_size; /* amount of data now in save_buffer */
+ png_size_t save_buffer_max; /* total size of save_buffer */
+ png_size_t buffer_size; /* total amount of available input data */
+ png_size_t current_buffer_size; /* amount of data now in current_buffer */
+ int process_mode; /* what push library is currently doing */
+ int cur_palette; /* current push library palette index */
+#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
+ png_size_t current_text_size; /* current size of text input data */
+ png_size_t current_text_left; /* how much text left to read in input */
+ png_charp current_text; /* current text chunk buffer */
+ png_charp current_text_ptr; /* current location in current_text */
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
+/* for the Borland special 64K segment handler */
+ png_bytepp offset_table_ptr;
+ png_bytep offset_table;
+ png_uint_16 offset_table_number;
+ png_uint_16 offset_table_count;
+ png_uint_16 offset_table_count_free;
+#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
+#if defined(PNG_READ_DITHER_SUPPORTED)
+ png_bytep palette_lookup; /* lookup table for dithering */
+ png_bytep dither_index; /* index translation for palette files */
+#endif /* PNG_READ_DITHER_SUPPORTED */
+#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
+ png_uint_16p hist; /* histogram */
+#endif
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ png_byte heuristic_method; /* heuristic for row filter selection */
+ png_byte num_prev_filters; /* number of weights for previous rows */
+ png_bytep prev_filters; /* filter type(s) of previous row(s) */
+ png_uint_16p filter_weights; /* weight(s) for previous line(s) */
+ png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
+ png_uint_16p filter_costs; /* relative filter calculation cost */
+ png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
+#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+ png_charp time_buffer; /* String to hold RFC 1123 time text */
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+#ifdef PNG_USER_MEM_SUPPORTED
+ png_voidp mem_ptr; /* user supplied struct for mem functions */
+ png_malloc_ptr malloc_fn; /* function for allocating memory */
+ png_free_ptr free_fn; /* function for freeing memory */
+#endif /* PNG_USER_MEM_SUPPORTED */
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+ png_byte rgb_to_gray_status;
+ png_byte rgb_to_gray_red_coeff;
+ png_byte rgb_to_gray_green_coeff;
+ png_byte rgb_to_gray_blue_coeff;
+#endif
+#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
+ defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
+ png_byte empty_plte_permitted;
+#endif
+};
+
+/* This prevents a compiler error in png_get_copyright() in png.c if png.c
+and png.h are both at * version 1.0.5
+ */
+typedef png_structp version_1_0_5;
+
+typedef png_struct FAR * FAR * png_structpp;
+
+/* Here are the function definitions most commonly used. This is not
+ * the place to find out how to use libpng. See libpng.txt for the
+ * full explanation, see example.c for the summary. This just provides
+ * a simple one line of the use of each function.
+ */
+
+/* Tell lib we have already handled the first <num_bytes> magic bytes.
+ * Handling more than 8 bytes from the beginning of the file is an error.
+ */
+extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
+ int num_bytes));
+
+/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
+ * PNG file. Returns zero if the supplied bytes match the 8-byte PNG
+ * signature, and non-zero otherwise. Having num_to_check == 0 or
+ * start > 7 will always fail (ie return non-zero).
+ */
+extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
+ png_size_t num_to_check));
+
+/* Simple signature checking function. This is the same as calling
+ * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
+ */
+extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
+
+/* Allocate and initialize png_ptr struct for reading, and any other memory. */
+extern PNG_EXPORT(png_structp,png_create_read_struct)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn));
+
+/* Allocate and initialize png_ptr struct for writing, and any other memory */
+extern PNG_EXPORT(png_structp,png_create_write_struct)
+ PNGARG((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
+extern PNG_EXPORT(png_structp,png_create_read_struct_2)
+ PNGARG((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));
+extern PNG_EXPORT(png_structp,png_create_write_struct_2)
+ PNGARG((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
+
+/* Write a PNG chunk - size, type, (optional) data, CRC. */
+extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name, png_bytep data, png_size_t length));
+
+/* Write the start of a PNG chunk - length and chunk name. */
+extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name, png_uint_32 length));
+
+/* Write the data of a PNG chunk started with png_write_chunk_start(). */
+extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
+ png_bytep data, png_size_t length));
+
+/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
+extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
+
+/* Allocate and initialize the info structure */
+extern PNG_EXPORT(png_infop,png_create_info_struct)
+ PNGARG((png_structp png_ptr));
+
+/* Initialize the info structure (old interface - NOT DLL EXPORTED) */
+extern void png_info_init PNGARG((png_infop info_ptr));
+
+/* Writes all the PNG information before the image. */
+extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* read the information before the actual image data. */
+extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
+ PNGARG((png_structp png_ptr, png_timep ptime));
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+/* convert from a struct tm to png_time */
+extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
+ struct tm FAR * ttime));
+
+/* convert from time_t to png_time. Uses gmtime() */
+extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
+ time_t ttime));
+#endif /* PNG_WRITE_tIME_SUPPORTED */
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
+extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
+extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
+extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
+extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_EXPAND_SUPPORTED */
+
+#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
+/* Use blue, green, red order for pixels. */
+extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_BGR_SUPPORTED || PNG_WRITE_BGR_SUPPORTED */
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+/* Expand the grayscale to 24-bit RGB if necessary. */
+extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+/* Reduce RGB to grayscale. */
+extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
+ int error_action, double red, double green ));
+extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
+ png_ptr));
+#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
+
+extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
+ png_colorp palette));
+
+#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
+extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_STRIP_ALPHA_SUPPORTED */
+
+#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
+ defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
+extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
+
+#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
+ defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
+extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
+
+#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
+/* Add a filler byte to 24-bit RGB images. */
+extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
+ png_uint_32 filler, int flags));
+
+/* The values of the PNG_FILLER_ defines should NOT be changed */
+#define PNG_FILLER_BEFORE 0
+#define PNG_FILLER_AFTER 1
+#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
+
+#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
+/* Swap bytes in 16-bit depth files. */
+extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_SWAP_SUPPORTED || PNG_WRITE_SWAP_SUPPORTED */
+
+#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
+/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
+extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_PACK_SUPPORTED || PNG_WRITE_PACK_SUPPORTED */
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
+/* Swap packing order of pixels in bytes. */
+extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_PACKSWAP_SUPPORTED || PNG_WRITE_PACKSWAP_SUPPORTED */
+
+#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
+/* Converts files to legal bit depths. */
+extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
+ png_color_8p true_bits));
+#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
+
+#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
+ defined(PNG_WRITE_INTERLACING_SUPPORTED)
+/* Have the code handle the interlacing. Returns the number of passes. */
+extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_INTERLACING_SUPPORTED || PNG_WRITE_INTERLACING_SUPPORTED */
+
+#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
+/* Invert monocrome files */
+extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_INVERT_SUPPORTED || PNG_WRITE_INVERT_SUPPORTED */
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+/* Handle alpha and tRNS by replacing with a background color. */
+extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
+ png_color_16p background_color, int background_gamma_code,
+ int need_expand, double background_gamma));
+#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
+#define PNG_BACKGROUND_GAMMA_SCREEN 1
+#define PNG_BACKGROUND_GAMMA_FILE 2
+#define PNG_BACKGROUND_GAMMA_UNIQUE 3
+#endif /* PNG_READ_BACKGROUND_SUPPORTED */
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+/* strip the second byte of information from a 16-bit depth file. */
+extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
+#endif /* PNG_READ_16_TO_8_SUPPORTED */
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+/* Turn on dithering, and reduce the palette to the number of colors available. */
+extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
+ png_colorp palette, int num_palette, int maximum_colors,
+ png_uint_16p histogram, int full_dither));
+#endif /* PNG_READ_DITHER_SUPPORTED */
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+/* Handle gamma correction. Screen_gamma=(display_exponent) */
+extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
+ double screen_gamma, double default_file_gamma));
+#endif /* PNG_READ_GAMMA_SUPPORTED */
+
+#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
+ defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
+/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
+extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
+ int empty_plte_permitted));
+#endif /* PNG_READ_EMPTY_PLTE_SUPPORTED */
+
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+/* Set how many lines between output flushes - 0 for no flushing */
+extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
+
+/* Flush the current PNG output buffer */
+extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
+#endif /* PNG_WRITE_FLUSH_SUPPORTED */
+
+/* optional update palette with requested transformations */
+extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
+
+/* optional call to update the users info structure */
+extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* read a one or more rows of image data.*/
+extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
+ png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
+
+/* read a row of data.*/
+extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
+ png_bytep row,
+ png_bytep display_row));
+
+/* read the whole image into memory at once. */
+extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
+ png_bytepp image));
+
+/* write a row of image data */
+extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
+ png_bytep row));
+
+/* write a few rows of image data */
+extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
+ png_bytepp row, png_uint_32 num_rows));
+
+/* write the image data */
+extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
+ png_bytepp image));
+
+/* writes the end of the PNG file. */
+extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* read the end of the PNG file. */
+extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* free any memory associated with the png_info_struct */
+extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
+ png_infopp info_ptr_ptr));
+
+/* free any memory associated with the png_struct and the png_info_structs */
+extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
+ png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
+
+/* free all memory used by the read (old method - NOT DLL EXPORTED) */
+extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_infop end_info_ptr));
+
+/* free any memory associated with the png_struct and the png_info_structs */
+extern PNG_EXPORT(void,png_destroy_write_struct)
+ PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
+
+/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */
+extern void png_write_destroy_info PNGARG((png_infop info_ptr));
+
+/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
+extern void png_write_destroy PNGARG((png_structp png_ptr));
+
+/* set the libpng method of handling chunk CRC errors */
+extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
+ int crit_action, int ancil_action));
+
+/* Values for png_set_crc_action() to say how to handle CRC errors in
+ * ancillary and critical chunks, and whether to use the data contained
+ * therein. Note that it is impossible to "discard" data in a critical
+ * chunk. For versions prior to 0.90, the action was always error/quit,
+ * whereas in version 0.90 and later, the action for CRC errors in ancillary
+ * chunks is warn/discard. These values should NOT be changed.
+ *
+ * value action:critical action:ancillary
+ */
+#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
+#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
+#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
+#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
+#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
+#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
+
+/* These functions give the user control over the scan-line filtering in
+ * libpng and the compression methods used by zlib. These functions are
+ * mainly useful for testing, as the defaults should work with most users.
+ * Those users who are tight on memory or want faster performance at the
+ * expense of compression can modify them. See the compression library
+ * header file (zlib.h) for an explination of the compression functions.
+ */
+
+/* set the filtering method(s) used by libpng. Currently, the only valid
+ * value for "method" is 0.
+ */
+extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
+ int filters));
+
+/* Flags for png_set_filter() to say which filters to use. The flags
+ * are chosen so that they don't conflict with real filter types
+ * below, in case they are supplied instead of the #defined constants.
+ * These values should NOT be changed.
+ */
+#define PNG_NO_FILTERS 0x00
+#define PNG_FILTER_NONE 0x08
+#define PNG_FILTER_SUB 0x10
+#define PNG_FILTER_UP 0x20
+#define PNG_FILTER_AVG 0x40
+#define PNG_FILTER_PAETH 0x80
+#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
+ PNG_FILTER_AVG | PNG_FILTER_PAETH)
+
+/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
+ * These defines should NOT be changed.
+ */
+#define PNG_FILTER_VALUE_NONE 0
+#define PNG_FILTER_VALUE_SUB 1
+#define PNG_FILTER_VALUE_UP 2
+#define PNG_FILTER_VALUE_AVG 3
+#define PNG_FILTER_VALUE_PAETH 4
+#define PNG_FILTER_VALUE_LAST 5
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
+/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
+ * defines, either the default (minimum-sum-of-absolute-differences), or
+ * the experimental method (weighted-minimum-sum-of-absolute-differences).
+ *
+ * Weights are factors >= 1.0, indicating how important it is to keep the
+ * filter type consistent between rows. Larger numbers mean the current
+ * filter is that many times as likely to be the same as the "num_weights"
+ * previous filters. This is cumulative for each previous row with a weight.
+ * There needs to be "num_weights" values in "filter_weights", or it can be
+ * NULL if the weights aren't being specified. Weights have no influence on
+ * the selection of the first row filter. Well chosen weights can (in theory)
+ * improve the compression for a given image.
+ *
+ * Costs are factors >= 1.0 indicating the relative decoding costs of a
+ * filter type. Higher costs indicate more decoding expense, and are
+ * therefore less likely to be selected over a filter with lower computational
+ * costs. There needs to be a value in "filter_costs" for each valid filter
+ * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't
+ * setting the costs. Costs try to improve the speed of decompression without
+ * unduly increasing the compressed image size.
+ *
+ * A negative weight or cost indicates the default value is to be used, and
+ * values in the range [0.0, 1.0) indicate the value is to remain unchanged.
+ * The default values for both weights and costs are currently 1.0, but may
+ * change if good general weighting/cost heuristics can be found. If both
+ * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
+ * to the UNWEIGHTED method, but with added encoding time/computation.
+ */
+extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
+ int heuristic_method, int num_weights, png_doublep filter_weights,
+ png_doublep filter_costs));
+#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
+
+/* Heuristic used for row filter selection. These defines should NOT be
+ * changed.
+ */
+#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
+#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
+#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
+#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
+
+/* Set the library compression level. Currently, valid values range from
+ * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
+ * (0 - no compression, 9 - "maximal" compression). Note that tests have
+ * shown that zlib compression levels 3-6 usually perform as well as level 9
+ * for PNG images, and do considerably fewer caclulations. In the future,
+ * these values may not correspond directly to the zlib compression levels.
+ */
+extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
+ int level));
+
+extern PNG_EXPORT(void,png_set_compression_mem_level)
+ PNGARG((png_structp png_ptr, int mem_level));
+
+extern PNG_EXPORT(void,png_set_compression_strategy)
+ PNGARG((png_structp png_ptr, int strategy));
+
+extern PNG_EXPORT(void,png_set_compression_window_bits)
+ PNGARG((png_structp png_ptr, int window_bits));
+
+extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
+ int method));
+
+/* These next functions are called for input/output, memory, and error
+ * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,
+ * and call standard C I/O routines such as fread(), fwrite(), and
+ * fprintf(). These functions can be made to use other I/O routines
+ * at run time for those applications that need to handle I/O in a
+ * different manner by calling png_set_???_fn(). See libpng.txt for
+ * more information.
+ */
+
+#if !defined(PNG_NO_STDIO)
+/* Initialize the input/output for the PNG file to the default functions. */
+extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
+#endif
+
+/* Replace the (error and abort), and warning functions with user
+ * supplied functions. If no messages are to be printed you must still
+ * write and use replacement functions. The replacement error_fn should
+ * still do a longjmp to the last setjmp location if you are using this
+ * method of error handling. If error_fn or warning_fn is NULL, the
+ * default function will be used.
+ */
+
+extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
+ png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
+
+/* Return the user pointer associated with the error functions */
+extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
+
+/* Replace the default data output functions with a user supplied one(s).
+ * If buffered output is not used, then output_flush_fn can be set to NULL.
+ * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
+ * output_flush_fn will be ignored (and thus can be NULL).
+ */
+extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
+ png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
+
+/* Replace the default data input function with a user supplied one. */
+extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
+ png_voidp io_ptr, png_rw_ptr read_data_fn));
+
+/* Return the user pointer associated with the I/O functions */
+extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
+
+extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
+ png_read_status_ptr read_row_fn));
+
+extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
+ png_write_status_ptr write_row_fn));
+
+#ifdef PNG_USER_MEM_SUPPORTED
+/* Replace the default memory allocation functions with user supplied one(s). */
+extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
+ png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+
+/* Return the user pointer associated with the memory functions */
+extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
+#endif /* PNG_USER_MEM_SUPPORTED */
+
+#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
+extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
+ png_ptr, png_user_transform_ptr read_user_transform_fn));
+#endif
+
+#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
+extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
+ png_ptr, png_user_transform_ptr write_user_transform_fn));
+#endif
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
+ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
+ png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
+ int user_transform_channels));
+/* Return the user pointer associated with the user transform functions */
+extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
+ PNGARG((png_structp png_ptr));
+#endif
+
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+/* Sets the function callbacks for the push reader, and a pointer to a
+ * user-defined structure available to the callback functions.
+ */
+extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
+ png_voidp progressive_ptr,
+ png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
+ png_progressive_end_ptr end_fn));
+
+/* returns the user pointer associated with the push read functions */
+extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
+ PNGARG((png_structp png_ptr));
+
+/* function to be called when data becomes available */
+extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
+
+/* function that combines rows. Not very much different than the
+ * png_combine_row() call. Is this even used?????
+ */
+extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
+ png_bytep old_row, png_bytep new_row));
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+
+extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
+
+/* frees a pointer allocated by png_malloc() */
+extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
+
+#ifdef PNG_USER_MEM_SUPPORTED
+extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
+extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
+ png_voidp ptr));
+#endif /* PNG_USER_MEM_SUPPORTED */
+
+extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
+ png_voidp s1, png_voidp s2, png_uint_32 size));
+
+extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
+ png_voidp s1, int value, png_uint_32 size));
+
+#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
+extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
+ int check));
+#endif /* USE_FAR_KEYWORD */
+
+/* Fatal error in PNG image of libpng - can't continue */
+extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
+ png_const_charp error));
+
+/* The same, but the chunk name is prepended to the error string. */
+extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
+ png_const_charp error));
+
+/* Non-fatal error in libpng. Can continue, but may have a problem. */
+extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
+ png_const_charp message));
+
+/* Non-fatal error in libpng, chunk name is prepended to message. */
+extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
+ png_const_charp message));
+
+/* The png_set_<chunk> functions are for storing values in the png_info_struct.
+ * Similarly, the png_get_<chunk> calls are used to read values from the
+ * png_info_struct, either storing the parameters in the passed variables, or
+ * setting pointers into the png_info_struct where the data is stored. The
+ * png_get_<chunk> functions return a non-zero value if the data was available
+ * in info_ptr, or return zero and do not change any of the parameters if the
+ * data was not available.
+ *
+ * These functions should be used instead of directly accessing png_info
+ * to avoid problems with future changes in the size and internal layout of
+ * png_info_struct.
+ */
+/* Returns "flag" if chunk data is valid in info_ptr. */
+extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
+png_infop info_ptr, png_uint_32 flag));
+
+/* Returns number of bytes needed to hold a transformed row. */
+extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
+png_infop info_ptr));
+
+/* Returns number of color channels in image. */
+extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
+png_infop info_ptr));
+
+#ifdef PNG_EASY_ACCESS_SUPPORTED
+/* Returns image width in pixels. */
+extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image height in pixels. */
+extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image bit_depth. */
+extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image color_type. */
+extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image filter_type. */
+extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image interlace_type. */
+extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image compression_type. */
+extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image resolution in pixels per meter, from pHYs chunk data. */
+extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns pixel aspect ratio, computed from pHYs chunk data. */
+extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
+extern PNG_EXPORT(png_uint_32, png_get_x_offset_pixels) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+extern PNG_EXPORT(png_uint_32, png_get_y_offset_pixels) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+extern PNG_EXPORT(png_uint_32, png_get_x_offset_microns) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+extern PNG_EXPORT(png_uint_32, png_get_y_offset_microns) PNGARG((png_structp
+png_ptr, png_infop info_ptr));
+
+#endif /* PNG_EASY_ACCESS_SUPPORTED */
+
+/* Returns pointer to signature string read from PNG header */
+extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
+png_infop info_ptr));
+
+#if defined(PNG_READ_bKGD_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_color_16p *background));
+#endif /* PNG_READ_bKGD_SUPPORTED */
+
+#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
+extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_color_16p background));
+#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
+
+#if defined(PNG_READ_cHRM_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((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));
+#endif /* PNG_READ_cHRM_SUPPORTED */
+
+#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
+extern PNG_EXPORT(void,png_set_cHRM) PNGARG((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));
+#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
+
+#if defined(PNG_READ_gAMA_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, double *file_gamma));
+#endif /* PNG_READ_gAMA_SUPPORTED */
+
+#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
+extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, double file_gamma));
+#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
+
+#if defined(PNG_READ_hIST_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_16p *hist));
+#endif /* PNG_READ_hIST_SUPPORTED */
+
+#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
+extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_16p hist));
+#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
+
+extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((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));
+
+extern PNG_EXPORT(void,png_set_IHDR) PNGARG((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 defined(PNG_READ_oFFs_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y,
+ int *unit_type));
+#endif /* PNG_READ_oFFs_SUPPORTED */
+
+#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
+extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 offset_x, png_uint_32 offset_y,
+ int unit_type));
+#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
+
+#if defined(PNG_READ_pCAL_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((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));
+#endif /* PNG_READ_pCAL_SUPPORTED */
+
+#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
+extern PNG_EXPORT(void,png_set_pCAL) PNGARG((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));
+#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
+
+#if defined(PNG_READ_pHYs_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
+#endif /* PNG_READ_pHYs_SUPPORTED */
+
+#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
+extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
+#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
+
+extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_colorp *palette, int *num_palette));
+
+extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_colorp palette, int num_palette));
+
+#if defined(PNG_READ_sBIT_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_color_8p *sig_bit));
+#endif /* PNG_READ_sBIT_SUPPORTED */
+
+#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
+extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_color_8p sig_bit));
+#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
+
+#if defined(PNG_READ_sRGB_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, int *intent));
+#endif /* PNG_READ_sRGB_SUPPORTED */
+
+#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
+extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, int intent));
+extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, int intent));
+#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
+
+#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
+/* png_get_text also returns the number of text chunks in text_ptr */
+extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_textp *text_ptr, int *num_text));
+#endif /* PNG_READ_tEXt_SUPPORTED || PNG_READ_zTXt_SUPPORTED */
+
+#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
+ defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_textp text_ptr, int num_text));
+#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
+
+#if defined(PNG_READ_tIME_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_timep *mod_time));
+#endif /* PNG_READ_tIME_SUPPORTED */
+
+#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
+extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_timep mod_time));
+#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
+
+#if defined(PNG_READ_tRNS_SUPPORTED)
+extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_bytep *trans, int *num_trans,
+ png_color_16p *trans_values));
+#endif /* PNG_READ_tRNS_SUPPORTED */
+
+#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
+extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_bytep trans, int num_trans,
+ png_color_16p trans_values));
+#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
+
+/* Define PNG_DEBUG at compile time for debugging information. Higher
+ * numbers for PNG_DEBUG mean more debugging information. This has
+ * only been added since version 0.95 so it is not implemented throughout
+ * libpng yet, but more support will be added as needed.
+ */
+#ifdef PNG_DEBUG
+#if (PNG_DEBUG > 0)
+#ifndef PNG_DEBUG_FILE
+#define PNG_DEBUG_FILE stderr
+#endif /* PNG_DEBUG_FILE */
+
+#define png_debug(l,m) if (PNG_DEBUG > l) \
+ fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
+ (l==2 ? "\t\t":(l>2 ? "\t\t\t":""))))
+#define png_debug1(l,m,p1) if (PNG_DEBUG > l) \
+ fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
+ (l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1)
+#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) \
+ fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
+ (l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1,p2)
+#endif /* (PNG_DEBUG > 0) */
+#endif /* PNG_DEBUG */
+#ifndef png_debug
+#define png_debug(l, m)
+#endif
+#ifndef png_debug1
+#define png_debug1(l, m, p1)
+#endif
+#ifndef png_debug2
+#define png_debug2(l, m, p1, p2)
+#endif
+
+extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
+extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
+
+#ifdef PNG_NO_EXTERN
+/* this only gets included in png.c */
+
+#define PNG_GET_HEADER \
+png_charp \
+png_get_header_version(png_structp png_ptr) \
+{ \
+ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ \
+ return("\n libpng version 1.0.5 - October 15, 1999 (header)\n"); \
+ return("\n libpng version 1.0.5 - October 15, 1999 (header)\n"); \
+}
+#endif
+
+#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
+/* With these routines we avoid an integer divide, which will be slower on
+ * most machines. However, it does take more operations than the corresponding
+ * divide method, so it may be slower on a few RISC systems. There are two
+ * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
+ *
+ * Note that the rounding factors are NOT supposed to be the same! 128 and
+ * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
+ * standard method.
+ *
+ * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
+ */
+
+ /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
+
+# define png_composite(composite, fg, alpha, bg) \
+ { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
+ + (png_uint_16)(bg)*(png_uint_16)(255 - \
+ (png_uint_16)(alpha)) + (png_uint_16)128); \
+ (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
+
+# define png_composite_16(composite, fg, alpha, bg) \
+ { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
+ + (png_uint_32)(bg)*(png_uint_32)(65535L - \
+ (png_uint_32)(alpha)) + (png_uint_32)32768L); \
+ (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
+
+#else /* standard method using integer division */
+
+# define png_composite(composite, fg, alpha, bg) \
+ (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
+ (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
+ (png_uint_16)127) / 255)
+
+# define png_composite_16(composite, fg, alpha, bg) \
+ (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
+ (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
+ (png_uint_32)32767) / (png_uint_32)65535L)
+
+#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
+
+/* These next functions are used internally in the code. They generally
+ * shouldn't be used unless you are writing code to add or replace some
+ * functionality in libpng. More information about most functions can
+ * be found in the files where the functions are located.
+ */
+
+#if defined(PNG_INTERNAL)
+
+/* Various modes of operation. Note that after an init, mode is set to
+ * zero automatically when the structure is created.
+ */
+#define PNG_BEFORE_IHDR 0x00
+#define PNG_HAVE_IHDR 0x01
+#define PNG_HAVE_PLTE 0x02
+#define PNG_HAVE_IDAT 0x04
+#define PNG_AFTER_IDAT 0x08
+#define PNG_HAVE_IEND 0x10
+#define PNG_HAVE_gAMA 0x20
+#define PNG_HAVE_cHRM 0x40
+#define PNG_HAVE_sRGB 0x80
+
+/* push model modes */
+#define PNG_READ_SIG_MODE 0
+#define PNG_READ_CHUNK_MODE 1
+#define PNG_READ_IDAT_MODE 2
+#define PNG_SKIP_MODE 3
+#define PNG_READ_tEXt_MODE 4
+#define PNG_READ_zTXt_MODE 5
+#define PNG_READ_DONE_MODE 6
+#define PNG_ERROR_MODE 7
+
+/* flags for the transformations the PNG library does on the image data */
+#define PNG_BGR 0x0001
+#define PNG_INTERLACE 0x0002
+#define PNG_PACK 0x0004
+#define PNG_SHIFT 0x0008
+#define PNG_SWAP_BYTES 0x0010
+#define PNG_INVERT_MONO 0x0020
+#define PNG_DITHER 0x0040
+#define PNG_BACKGROUND 0x0080
+#define PNG_BACKGROUND_EXPAND 0x0100
+ /* 0x0200 unused */
+#define PNG_16_TO_8 0x0400
+#define PNG_RGBA 0x0800
+#define PNG_EXPAND 0x1000
+#define PNG_GAMMA 0x2000
+#define PNG_GRAY_TO_RGB 0x4000
+#define PNG_FILLER 0x8000
+#define PNG_PACKSWAP 0x10000L
+#define PNG_SWAP_ALPHA 0x20000L
+#define PNG_STRIP_ALPHA 0x40000L
+#define PNG_INVERT_ALPHA 0x80000L
+#define PNG_USER_TRANSFORM 0x100000L
+#define PNG_RGB_TO_GRAY_ERR 0x200000L
+#define PNG_RGB_TO_GRAY_WARN 0x400000L
+#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
+
+/* flags for png_create_struct */
+#define PNG_STRUCT_PNG 0x0001
+#define PNG_STRUCT_INFO 0x0002
+
+/* Scaling factor for filter heuristic weighting calculations */
+#define PNG_WEIGHT_SHIFT 8
+#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
+#define PNG_COST_SHIFT 3
+#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
+
+/* flags for the png_ptr->flags rather than declaring a byte for each one */
+#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
+#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
+#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
+#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
+#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
+#define PNG_FLAG_ZLIB_FINISHED 0x0020
+#define PNG_FLAG_ROW_INIT 0x0040
+#define PNG_FLAG_FILLER_AFTER 0x0080
+#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
+#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
+#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
+#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
+#define PNG_FLAG_FREE_PALETTE 0x1000
+#define PNG_FLAG_FREE_TRANS 0x2000
+#define PNG_FLAG_FREE_HIST 0x4000
+#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
+#define PNG_FLAG_WROTE_tIME 0x10000L
+#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
+
+#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
+ PNG_FLAG_CRC_ANCILLARY_NOWARN)
+
+#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
+ PNG_FLAG_CRC_CRITICAL_IGNORE)
+
+#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
+ PNG_FLAG_CRC_CRITICAL_MASK)
+
+/* save typing and make code easier to understand */
+#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
+ abs((int)((c1).green) - (int)((c2).green)) + \
+ abs((int)((c1).blue) - (int)((c2).blue)))
+
+/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
+#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
+/* place to hold the signature string for a PNG file. */
+extern png_byte FARDATA png_sig[8];
+
+/* Constant strings for known chunk types. If you need to add a chunk,
+ * add a string holding the name here. See png.c for more details. We
+ * can't selectively include these, since we still check for chunk in the
+ * wrong locations with these labels.
+ */
+extern png_byte FARDATA png_IHDR[5];
+extern png_byte FARDATA png_IDAT[5];
+extern png_byte FARDATA png_IEND[5];
+extern png_byte FARDATA png_PLTE[5];
+extern png_byte FARDATA png_bKGD[5];
+extern png_byte FARDATA png_cHRM[5];
+extern png_byte FARDATA png_gAMA[5];
+extern png_byte FARDATA png_hIST[5];
+extern png_byte FARDATA png_oFFs[5];
+extern png_byte FARDATA png_pCAL[5];
+extern png_byte FARDATA png_pHYs[5];
+extern png_byte FARDATA png_sBIT[5];
+extern png_byte FARDATA png_sRGB[5];
+extern png_byte FARDATA png_tEXt[5];
+extern png_byte FARDATA png_tIME[5];
+extern png_byte FARDATA png_tRNS[5];
+extern png_byte FARDATA png_zTXt[5];
+
+#endif /* PNG_NO_EXTERN */
+
+/* Inline macros to do direct reads of bytes from the input buffer. These
+ * require that you are using an architecture that uses PNG byte ordering
+ * (MSB first) and supports unaligned data storage. I think that PowerPC
+ * in big-endian mode and 680x0 are the only ones that will support this.
+ * The x86 line of processors definitely do not. The png_get_int_32()
+ * routine also assumes we are using two's complement format for negative
+ * values, which is almost certainly true.
+ */
+#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
+#if defined(PNG_READ_pCAL_SUPPORTED)
+#define png_get_int_32(buf) ( *((png_int_32p) (buf)))
+#endif /* PNG_READ_pCAL_SUPPORTED */
+#define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
+#define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
+#else
+#if defined(PNG_READ_pCAL_SUPPORTED)
+PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
+#endif /* PNG_READ_pCAL_SUPPORTED */
+PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
+PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
+#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
+
+/* Initialize png_ptr struct for reading, and allocate any other memory.
+ * (old interface - NOT DLL EXPORTED).
+ */
+extern void png_read_init PNGARG((png_structp png_ptr));
+
+/* Initialize png_ptr struct for writing, and allocate any other memory.
+ * (old interface - NOT DLL EXPORTED).
+ */
+extern void png_write_init PNGARG((png_structp png_ptr));
+
+/* allocate memory for an internal libpng struct */
+PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
+
+/* free memory from internal libpng struct */
+PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
+
+PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
+ malloc_fn));
+PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
+ png_free_ptr free_fn));
+
+/* free any memory that info_ptr points to and reset struct. */
+PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* Function to allocate memory for zlib. */
+PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
+
+/* function to free memory for zlib */
+PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
+
+/* reset the CRC variable */
+PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
+
+/* Write the "data" buffer to whatever output you are using. */
+PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
+
+/* Read data from whatever input you are using into the "data" buffer */
+PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
+
+/* read bytes into buf, and update png_ptr->crc */
+PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
+ png_size_t length));
+
+/* read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
+PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
+
+/* read the CRC from the file and compare it to the libpng calculated CRC */
+PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
+
+/* Calculate the CRC over a section of data. Note that we are only
+ * passing a maximum of 64K on systems that have this as a memory limit,
+ * since this is the maximum buffer size we can specify.
+ */
+PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
+ png_size_t length));
+
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
+#endif
+
+/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
+ * The only currently known PNG chunks that use signed numbers are
+ * the ancillary extension chunks, oFFs and pCAL.
+ */
+PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
+
+#if defined(PNG_WRITE_pCAL_SUPPORTED)
+PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
+#endif
+
+/* Place a 16-bit number into a buffer in PNG byte order.
+ * The parameter is declared unsigned int, not png_uint_16,
+ * just to avoid potential problems on pre-ANSI C compilers.
+ */
+PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
+
+/* simple function to write the signature */
+PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
+
+/* write various chunks */
+
+/* Write the IHDR chunk, and update the png_struct with the necessary
+ * information.
+ */
+PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
+ png_uint_32 height,
+ int bit_depth, int color_type, int compression_type, int filter_type,
+ int interlace_type));
+
+PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
+ png_uint_32 num_pal));
+
+PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
+
+PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
+
+#if defined(PNG_WRITE_gAMA_SUPPORTED)
+PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
+#endif
+
+#if defined(PNG_WRITE_sBIT_SUPPORTED)
+PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
+ int color_type));
+#endif
+
+#if defined(PNG_WRITE_cHRM_SUPPORTED)
+PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_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));
+#endif
+
+#if defined(PNG_WRITE_sRGB_SUPPORTED)
+PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
+ int intent));
+#endif
+
+#if defined(PNG_WRITE_tRNS_SUPPORTED)
+PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
+ png_color_16p values, int number, int color_type));
+#endif
+
+#if defined(PNG_WRITE_bKGD_SUPPORTED)
+PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
+ png_color_16p values, int color_type));
+#endif
+
+#if defined(PNG_WRITE_hIST_SUPPORTED)
+PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
+ int num_hist));
+#endif
+
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
+ defined(PNG_WRITE_pCAL_SUPPORTED)
+PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
+ png_charp key, png_charpp new_key));
+#endif
+
+#if defined(PNG_WRITE_tEXt_SUPPORTED)
+PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
+ png_charp text, png_size_t text_len));
+#endif
+
+#if defined(PNG_WRITE_zTXt_SUPPORTED)
+PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
+ png_charp text, png_size_t text_len, int compression));
+#endif
+
+#if defined(PNG_WRITE_oFFs_SUPPORTED)
+PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
+ png_uint_32 x_offset, png_uint_32 y_offset, int unit_type));
+#endif
+
+#if defined(PNG_WRITE_pCAL_SUPPORTED)
+PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
+ png_int_32 X0, png_int_32 X1, int type, int nparams,
+ png_charp units, png_charpp params));
+#endif
+
+#if defined(PNG_WRITE_pHYs_SUPPORTED)
+PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
+ png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
+ int unit_type));
+#endif
+
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
+ png_timep mod_time));
+#endif
+
+/* Called when finished processing a row of data */
+PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
+
+/* Internal use only. Called before first row of data */
+PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
+#endif
+
+/* combine a row of data, dealing with alpha, etc. if requested */
+PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
+ int mask));
+
+#if defined(PNG_READ_INTERLACING_SUPPORTED)
+/* expand an interlaced row */
+PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
+ png_bytep row, int pass, png_uint_32 transformations));
+#endif
+
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+/* grab pixels out of a row for an interlaced pass */
+PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
+ png_bytep row, int pass));
+#endif
+
+/* unfilter a row */
+PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
+ png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
+
+/* Choose the best filter to use and filter the row data */
+PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
+ png_row_infop row_info));
+
+/* Write out the filtered row. */
+PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
+ png_bytep filtered_row));
+/* finish a row while reading, dealing with interlacing passes, etc. */
+PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
+
+/* initialize the row buffers, etc. */
+PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
+/* optional call to update the users info structure */
+PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+/* these are the functions that do the transformations */
+#if defined(PNG_READ_FILLER_SUPPORTED)
+PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
+ png_bytep row, png_uint_32 filler, png_uint_32 flags));
+#endif
+
+#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
+#endif
+
+#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
+#endif
+
+#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
+#endif
+
+#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
+#endif
+
+#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
+ defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
+PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
+ png_bytep row, png_uint_32 flags));
+#endif
+
+#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
+PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
+PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
+ row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
+ png_bytep row));
+#endif
+
+#if defined(PNG_READ_PACK_SUPPORTED)
+PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_SHIFT_SUPPORTED)
+PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_8p sig_bits));
+#endif
+
+#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
+PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
+ png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
+
+# if defined(PNG_CORRECT_PALETTE_SUPPORTED)
+PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
+ png_colorp palette, int num_palette));
+# endif
+#endif
+
+#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
+PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
+#endif
+
+#if defined(PNG_WRITE_PACK_SUPPORTED)
+PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
+ png_bytep row, png_uint_32 bit_depth));
+#endif
+
+#if defined(PNG_WRITE_SHIFT_SUPPORTED)
+PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_8p bit_depth));
+#endif
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_16p trans_values, png_color_16p background,
+ png_color_16p background_1,
+ png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
+ png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
+ png_uint_16pp gamma_16_to_1, int gamma_shift));
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
+ png_bytep gamma_table, png_uint_16pp gamma_16_table,
+ int gamma_shift));
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
+ png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
+PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
+ png_bytep row, png_color_16p trans_value));
+#endif
+
+/* The following decodes the appropriate chunks, and does error correction,
+ * then calls the appropriate callback for the chunk if it is valid.
+ */
+
+/* decode the IHDR chunk */
+PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+
+#if defined(PNG_READ_gAMA_SUPPORTED)
+PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_sBIT_SUPPORTED)
+PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_cHRM_SUPPORTED)
+PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_sRGB_SUPPORTED)
+PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_tRNS_SUPPORTED)
+PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_bKGD_SUPPORTED)
+PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_hIST_SUPPORTED)
+PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_oFFs_SUPPORTED)
+PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_pCAL_SUPPORTED)
+PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_pHYs_SUPPORTED)
+PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_tIME_SUPPORTED)
+PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_tEXt_SUPPORTED)
+PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+#if defined(PNG_READ_zTXt_SUPPORTED)
+PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif
+
+PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 length));
+
+PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
+ png_bytep chunk_name));
+
+/* handle the transformations for reading and writing */
+PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
+
+PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
+
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
+ png_uint_32 length));
+PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
+ png_bytep buffer, png_size_t length));
+PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
+ png_bytep buffer, png_size_t buffer_length));
+PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
+ png_bytep buffer, png_size_t buffer_length));
+PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
+PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 length));
+PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
+PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
+#if defined(PNG_READ_tEXt_SUPPORTED)
+PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 length));
+PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+#endif
+#if defined(PNG_READ_zTXt_SUPPORTED)
+PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr, png_uint_32 length));
+PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+#endif
+
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+
+#endif /* PNG_INTERNAL */
+
+#ifdef __cplusplus
+}
+#endif
+
+/* do not put anything past this line */
+#endif /* _PNG_H */
diff --git a/osframework/source/ImageLib/png/pngasmrd.h b/osframework/source/ImageLib/png/pngasmrd.h
new file mode 100644
index 0000000..da14213
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngasmrd.h
@@ -0,0 +1,32 @@
+/* pngasmrd.h - assembler version of utilities to read a PNG file
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * For conditions of distribution and use, see copyright notice in png.h
+ * Copyright (c) 1999 Glenn Randers-Pehrson
+ *
+ */
+
+#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
+
+/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
+#ifdef PNG_USE_PNGVCRD
+/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
+ * MMX will be detected at run time and used if present.
+ */
+#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
+#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+#endif
+
+/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
+#ifdef PNG_USE_PNGGCCRD
+/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c
+ * (not available in libpng 1.0.5).
+ * MMX will be detected at run time and used if present.
+ */
+#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
+#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/png/pngconf.h b/osframework/source/ImageLib/png/pngconf.h
new file mode 100644
index 0000000..d8fda85
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngconf.h
@@ -0,0 +1,723 @@
+
+/* pngconf.h - machine configurable file for libpng
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ */
+
+/* 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 extremely 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 than the size of a row (compressed),
+ * it should not make much difference how big this is.
+ */
+
+#ifndef PNG_ZBUF_SIZE
+#define PNG_ZBUF_SIZE 8192
+#endif
+
+/* 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 that 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_CONSOLE_IO will
+ * prevent these from being compiled and used. #defining PNG_NO_STDIO
+ * will also prevent these, plus will prevent the entire set of stdio
+ * macros and functions (FILE *, printf, etc.) from being compiled and used,
+ * unless (PNG_DEBUG > 0) has been #defined.
+ *
+ * #define PNG_NO_CONSOLE_IO
+ * #define PNG_NO_STDIO
+ */
+
+# ifdef PNG_NO_STDIO
+# ifndef PNG_NO_CONSOLE_IO
+# define PNG_NO_CONSOLE_IO
+# endif
+# ifdef PNG_DEBUG
+# if (PNG_DEBUG > 0)
+# include <stdio.h>
+# endif
+# endif
+# else
+# 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. Note that testing for
+ * just __MWERKS__ is not good enough, because the Codewarrior is now used
+ * on non-Mac platforms.
+ */
+#ifndef MACOS
+#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
+ defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
+#define MACOS
+#endif
+#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.
+ */
+#ifdef __linux__
+#ifdef _BSD_SOURCE
+#define _PNG_SAVE_BSD_SOURCE
+#undef _BSD_SOURCE
+#endif
+#ifdef _SETJMP_H
+__png.h__ already includes setjmp.h
+__dont__ include it again
+#endif
+#endif /* __linux__ */
+
+/* include setjmp.h for error handling */
+#include <setjmp.h>
+
+#ifdef __linux__
+#ifdef _PNG_SAVE_BSD_SOURCE
+#define _BSD_SOURCE
+#undef _PNG_SAVE_BSD_SOURCE
+#endif
+#endif /* __linux__ */
+
+#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>
+
+/* 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
+
+/* Codewarrior on NT has linking problems without this. */
+#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
+#define PNG_ALWAYS_EXTERN
+#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.
+ */
+#ifndef PNG_DITHER_RED_BITS
+#define PNG_DITHER_RED_BITS 5
+#endif
+#ifndef PNG_DITHER_GREEN_BITS
+#define PNG_DITHER_GREEN_BITS 5
+#endif
+#ifndef PNG_DITHER_BLUE_BITS
+#define PNG_DITHER_BLUE_BITS 5
+#endif
+
+/* 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).
+ */
+
+#ifndef PNG_MAX_GAMMA_8
+#define PNG_MAX_GAMMA_8 11
+#endif
+
+/* This controls how much a difference in gamma we can tolerate before
+ * we actually start doing gamma conversion.
+ */
+#ifndef PNG_GAMMA_THRESHOLD
+#define PNG_GAMMA_THRESHOLD 0.05
+#endif
+
+#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 do not want to use const, define PNG_NO_CONST here.
+ */
+
+#ifndef PNG_NO_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 */
+
+/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
+ to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
+ on the compile line, then pick and choose which ones to define without
+ having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED
+ if you only want to have a png-compliant reader/writer but don't need
+ any of the extra transformations. This saves about 80 kbytes in a
+ typical installation of the library. (PNG_NO_* form added in version
+ 1.0.1c, for consistency)
+ */
+
+
+#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
+ !defined(PNG_NO_READ_TRANSFORMS)
+#define PNG_READ_TRANSFORMS_SUPPORTED
+#endif
+#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
+ !defined(PNG_NO_WRITE_TRANSFORMS)
+#define PNG_WRITE_TRANSFORMS_SUPPORTED
+#endif
+
+#ifdef PNG_READ_TRANSFORMS_SUPPORTED
+#ifndef PNG_NO_READ_EXPAND
+#define PNG_READ_EXPAND_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_SHIFT
+#define PNG_READ_SHIFT_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_PACK
+#define PNG_READ_PACK_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_BGR
+#define PNG_READ_BGR_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_SWAP
+#define PNG_READ_SWAP_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_PACKSWAP
+#define PNG_READ_PACKSWAP_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_INVERT
+#define PNG_READ_INVERT_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_DITHER
+#define PNG_READ_DITHER_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_BACKGROUND
+#define PNG_READ_BACKGROUND_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_16_TO_8
+#define PNG_READ_16_TO_8_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_FILLER
+#define PNG_READ_FILLER_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_GAMMA
+#define PNG_READ_GAMMA_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_GRAY_TO_RGB
+#define PNG_READ_GRAY_TO_RGB_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_SWAP_ALPHA
+#define PNG_READ_SWAP_ALPHA_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_INVERT_ALPHA
+#define PNG_READ_INVERT_ALPHA_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_STRIP_ALPHA
+#define PNG_READ_STRIP_ALPHA_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_USER_TRANSFORM
+#define PNG_READ_USER_TRANSFORM_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_RGB_TO_GRAY
+#define PNG_READ_RGB_TO_GRAY_SUPPORTED
+#endif
+#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
+
+#if !defined(PNG_NO_PROGRESSIVE_READ) && \
+ !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
+#define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
+#endif /* about interlacing capability! You'll */
+ /* still have interlacing unless you change the following line: */
+#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
+
+#ifndef PNG_NO_READ_COMPOSITED_NODIV
+#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
+#endif
+
+#ifndef PNG_NO_READ_EMPTY_PLTE
+#define PNG_READ_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
+#endif
+
+#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
+#ifndef PNG_NO_WRITE_SHIFT
+#define PNG_WRITE_SHIFT_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_PACK
+#define PNG_WRITE_PACK_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_BGR
+#define PNG_WRITE_BGR_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_SWAP
+#define PNG_WRITE_SWAP_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_PACKSWAP
+#define PNG_WRITE_PACKSWAP_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_INVERT
+#define PNG_WRITE_INVERT_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_FILLER
+#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
+#endif
+#ifndef PNG_NO_WRITE_SWAP_ALPHA
+#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_INVERT_ALPHA
+#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_USER_TRANSFORM
+#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
+#endif
+#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
+
+#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
+ encoders, but can cause trouble
+ if left undefined */
+
+#ifndef PNG_NO_WRITE_WEIGHTED_FILTER
+#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
+#endif
+
+#ifndef PNG_NO_WRITE_FLUSH
+#define PNG_WRITE_FLUSH_SUPPORTED
+#endif
+
+#ifndef PNG_NO_WRITE_EMPTY_PLTE
+#define PNG_WRITE_EMPTY_PLTE_SUPPORTED /* useful for MNG applications */
+#endif
+
+#ifndef PNG_NO_STDIO
+#define PNG_TIME_RFC1123_SUPPORTED
+#endif
+
+/* This adds extra functions in pngget.c for accessing data from the
+ * info pointer (added in version 0.99)
+ * png_get_image_width()
+ * png_get_image_height()
+ * png_get_bit_depth()
+ * png_get_color_type()
+ * png_get_compression_type()
+ * png_get_filter_type()
+ * png_get_interlace_type()
+ * png_get_pixel_aspect_ratio()
+ * png_get_pixels_per_meter()
+ * png_get_x_offset_pixels()
+ * png_get_y_offset_pixels()
+ * png_get_x_offset_microns()
+ * png_get_y_offset_microns()
+ */
+#ifndef PNG_NO_EASY_ACCESS
+#define PNG_EASY_ACCESS_SUPPORTED
+#endif
+
+#ifndef PNG_NO_ASSEMBLER_CODE
+#define PNG_ASSEMBLER_CODE_SUPPORTED
+#endif
+
+/* These are currently experimental features, define them if you want */
+
+/* very little testing */
+/*
+#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
+#define PNG_USER_MEM_SUPPORTED
+*/
+
+/* This is only for PowerPC big-endian and 680x0 systems */
+/* some testing */
+/*
+#define PNG_READ_BIG_ENDIAN_SUPPORTED
+*/
+
+/* These functions are turned off by default, as they will be phased out. */
+/*
+#define PNG_USELESS_TESTS_SUPPORTED
+#define 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.
+ */
+
+#if !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
+ !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
+#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
+#endif
+#if !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
+ !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
+#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
+#endif
+
+#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
+#ifndef PNG_NO_READ_bKGD
+#define PNG_READ_bKGD_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_cHRM
+#define PNG_READ_cHRM_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_gAMA
+#define PNG_READ_gAMA_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_hIST
+#define PNG_READ_hIST_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_oFFs
+#define PNG_READ_oFFs_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_pCAL
+#define PNG_READ_pCAL_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_pHYs
+#define PNG_READ_pHYs_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_sBIT
+#define PNG_READ_sBIT_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_sRGB
+#define PNG_READ_sRGB_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_tEXt
+#define PNG_READ_tEXt_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_tIME
+#define PNG_READ_tIME_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_tRNS
+#define PNG_READ_tRNS_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_zTXt
+#define PNG_READ_zTXt_SUPPORTED
+#endif
+#ifndef PNG_NO_READ_OPT_PLTE
+#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
+#endif /* PLTE chunk in RGB and RGBA images */
+#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
+
+#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
+#ifndef PNG_NO_WRITE_bKGD
+#define PNG_WRITE_bKGD_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_cHRM
+#define PNG_WRITE_cHRM_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_gAMA
+#define PNG_WRITE_gAMA_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_hIST
+#define PNG_WRITE_hIST_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_oFFs
+#define PNG_WRITE_oFFs_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_pCAL
+#define PNG_WRITE_pCAL_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_pHYs
+#define PNG_WRITE_pHYs_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_sBIT
+#define PNG_WRITE_sBIT_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_sRGB
+#define PNG_WRITE_sRGB_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_tEXt
+#define PNG_WRITE_tEXt_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_tIME
+#define PNG_WRITE_tIME_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_tRNS
+#define PNG_WRITE_tRNS_SUPPORTED
+#endif
+#ifndef PNG_NO_WRITE_zTXt
+#define PNG_WRITE_zTXt_SUPPORTED
+#endif
+#endif /* PNG_WRITE_ANCILLARY_CHUNKS_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
+
+/* 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;
+
+
+#ifndef PNG_EXPORT
+ /* allow for compilation as dll under MS Windows */
+# ifdef __WIN32DLL__
+# define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
+# endif
+
+ /* this variant is used in Mozilla; may correspond to MSVC++ 6.0 changes */
+# ifdef ALT_WIN32_DLL
+# define PNG_EXPORT(type,symbol) type __attribute__((dllexport)) symbol
+# endif
+
+ /* allow for compilation as dll with Borland C++ 5.0 */
+# if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
+# define PNG_EXPORT(type,symbol) type _export symbol
+# endif
+
+ /* allow for compilation as shared lib under BeOS */
+# ifdef __BEOSDLL__
+# define PNG_EXPORT(type,symbol) __declspec(export) type symbol
+# endif
+#endif
+
+#ifndef PNG_EXPORT
+# define PNG_EXPORT(type,symbol) type symbol
+#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) (png_far_to_near(png_ptr,ptr,CHECK))
+# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
+# define png_strcpy _fstrcpy
+# 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_strcpy strcpy
+# 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 */
+
diff --git a/osframework/source/ImageLib/png/pngerror.c b/osframework/source/ImageLib/png/pngerror.c
new file mode 100644
index 0000000..21d74a5
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngerror.c
@@ -0,0 +1,172 @@
+
+/* pngerror.c - stub functions for i/o and memory allocation
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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++] = (png_byte)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_CONSOLE_IO
+ 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)
+{
+#ifndef PNG_NO_CONSOLE_IO
+ fprintf(stderr, "libpng warning: %s\n", message);
+#endif
+ if (png_ptr == NULL)
+ return;
+}
+
+/* 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);
+}
+
+
+
diff --git a/osframework/source/ImageLib/png/pngget.c b/osframework/source/ImageLib/png/pngget.c
new file mode 100644
index 0000000..6c3d327
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngget.c
@@ -0,0 +1,650 @@
+
+/* pngget.c - retrieval of values from info struct
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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_MAX_UINT/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
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+png_byte
+png_get_rgb_to_gray_status (png_structp png_ptr)
+{
+ return png_ptr->rgb_to_gray_status;
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngmem.c b/osframework/source/ImageLib/png/pngmem.c
new file mode 100644
index 0000000..d83b6bb
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngmem.c
@@ -0,0 +1,500 @@
+
+/* pngmem.c - stub functions for memory allocation
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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);
+ return;
+ }
+#endif /* PNG_USER_MEM_SUPPORTED */
+ farfree (struct_ptr);
+ }
+}
+
+/* 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;
+ }
+
+ if(png_ptr->zlib_window_bits > 14)
+ num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
+ else
+ 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 = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
+ }
+ for (i = 0; i < num_blocks; i++)
+ {
+ png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
+ hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
+ }
+
+ 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);
+ 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);
+ }
+}
+
+#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);
+ return;
+ }
+#endif /* PNG_USER_MEM_SUPPORTED */
+#if defined(__TURBOC__) && !defined(__FLAT__)
+ farfree(struct_ptr);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ hfree(struct_ptr);
+# else
+ free(struct_ptr);
+# 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);
+ 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);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ hfree(ptr);
+# else
+ free(ptr);
+# 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 */
diff --git a/osframework/source/ImageLib/png/pngnow.png b/osframework/source/ImageLib/png/pngnow.png
new file mode 100644
index 0000000..6a1f497
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngnow.png
Binary files differ
diff --git a/osframework/source/ImageLib/png/pngpread.c b/osframework/source/ImageLib/png/pngpread.c
new file mode 100644
index 0000000..4f98134
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngpread.c
@@ -0,0 +1,1141 @@
+
+/* pngpread.c - read a png file in push mode
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ */
+
+#define PNG_INTERNAL
+#include "png.h"
+
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+
+void
+png_process_data(png_structp png_ptr, png_infop info_ptr,
+ png_bytep buffer, png_size_t buffer_size)
+{
+ png_push_restore_buffer(png_ptr, buffer, buffer_size);
+
+ while (png_ptr->buffer_size)
+ {
+ png_process_some_data(png_ptr, info_ptr);
+ }
+}
+
+/* What we do with the incoming data depends on what we were previously
+ * doing before we ran out of data...
+ */
+void
+png_process_some_data(png_structp png_ptr, png_infop info_ptr)
+{
+ switch (png_ptr->process_mode)
+ {
+ case PNG_READ_SIG_MODE:
+ {
+ png_push_read_sig(png_ptr, info_ptr);
+ break;
+ }
+ case PNG_READ_CHUNK_MODE:
+ {
+ png_push_read_chunk(png_ptr, info_ptr);
+ break;
+ }
+ case PNG_READ_IDAT_MODE:
+ {
+ png_push_read_IDAT(png_ptr);
+ break;
+ }
+#if defined(PNG_READ_tEXt_SUPPORTED)
+ case PNG_READ_tEXt_MODE:
+ {
+ png_push_read_tEXt(png_ptr, info_ptr);
+ break;
+ }
+#endif
+#if defined(PNG_READ_zTXt_SUPPORTED)
+ case PNG_READ_zTXt_MODE:
+ {
+ png_push_read_zTXt(png_ptr, info_ptr);
+ break;
+ }
+#endif
+ case PNG_SKIP_MODE:
+ {
+ png_push_crc_finish(png_ptr);
+ break;
+ }
+ default:
+ {
+ png_ptr->buffer_size = 0;
+ break;
+ }
+ }
+}
+
+/* Read any remaining signature bytes from the stream and compare them with
+ * the correct PNG signature. It is possible that this routine is called
+ * with bytes already read from the signature, either because they have been
+ * checked by the calling application, or because of multiple calls to this
+ * routine.
+ */
+void
+png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
+{
+ png_size_t num_checked = png_ptr->sig_bytes,
+ num_to_check = 8 - num_checked;
+
+ if (png_ptr->buffer_size < num_to_check)
+ {
+ num_to_check = png_ptr->buffer_size;
+ }
+
+ png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
+ num_to_check);
+ png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
+
+ 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");
+ }
+ else
+ {
+ if (png_ptr->sig_bytes >= 8)
+ {
+ png_ptr->process_mode = PNG_READ_CHUNK_MODE;
+ }
+ }
+}
+
+void
+png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
+{
+ /* First we make sure we have enough data for the 4 byte chunk name
+ * and the 4 byte chunk length before proceeding with decoding the
+ * chunk data. To fully decode each of these chunks, we also make
+ * sure we have enough data in the buffer for the 4 byte CRC at the
+ * end of every chunk (except IDAT, which is handled separately).
+ */
+ if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
+ {
+ png_byte chunk_length[4];
+
+ if (png_ptr->buffer_size < 8)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_push_fill_buffer(png_ptr, chunk_length, 4);
+ png_ptr->push_length = png_get_uint_32(chunk_length);
+ png_reset_crc(png_ptr);
+ png_crc_read(png_ptr, png_ptr->chunk_name, 4);
+ png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
+ }
+
+ if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
+ }
+ else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
+ }
+ else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
+ {
+ /* If we reach an IDAT chunk, this means we have read all of the
+ * header chunks, and we can start reading the image (or if this
+ * is called after the image has been read - we have an error).
+ */
+ if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ if (png_ptr->push_length == 0)
+ return;
+
+ if (png_ptr->mode & PNG_AFTER_IDAT)
+ png_error(png_ptr, "Too many IDAT's found");
+ }
+
+ png_ptr->idat_size = png_ptr->push_length;
+ png_ptr->mode |= PNG_HAVE_IDAT;
+ png_ptr->process_mode = PNG_READ_IDAT_MODE;
+ png_push_have_info(png_ptr, info_ptr);
+ png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
+ png_ptr->zstream.next_out = png_ptr->row_buf;
+ return;
+ }
+ else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
+ png_ptr->process_mode = PNG_READ_DONE_MODE;
+ png_push_have_end(png_ptr, info_ptr);
+ }
+#if defined(PNG_READ_gAMA_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_sBIT_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_cHRM_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_sRGB_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_tRNS_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_bKGD_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_hIST_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_pHYs_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_oFFs_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_pCAL_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_tIME_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
+ {
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_tEXt_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
+ {
+ png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+#if defined(PNG_READ_zTXt_SUPPORTED)
+ else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
+ {
+ png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
+ }
+#endif
+ else
+ {
+ png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
+ }
+
+ png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
+}
+
+void
+png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
+{
+ png_ptr->process_mode = PNG_SKIP_MODE;
+ png_ptr->skip_length = skip;
+}
+
+void
+png_push_crc_finish(png_structp png_ptr)
+{
+ if (png_ptr->skip_length && png_ptr->save_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
+ save_size = (png_size_t)png_ptr->skip_length;
+ else
+ save_size = png_ptr->save_buffer_size;
+
+ png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
+
+ png_ptr->skip_length -= save_size;
+ png_ptr->buffer_size -= save_size;
+ png_ptr->save_buffer_size -= save_size;
+ png_ptr->save_buffer_ptr += save_size;
+ }
+ if (png_ptr->skip_length && png_ptr->current_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
+ save_size = (png_size_t)png_ptr->skip_length;
+ else
+ save_size = png_ptr->current_buffer_size;
+
+ png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
+
+ png_ptr->skip_length -= save_size;
+ png_ptr->buffer_size -= save_size;
+ png_ptr->current_buffer_size -= save_size;
+ png_ptr->current_buffer_ptr += save_size;
+ }
+ if (!png_ptr->skip_length)
+ {
+ if (png_ptr->buffer_size < 4)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_crc_finish(png_ptr, 0);
+ png_ptr->process_mode = PNG_READ_CHUNK_MODE;
+ }
+}
+
+void
+png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
+{
+ png_bytep ptr;
+
+ ptr = buffer;
+ if (png_ptr->save_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (length < png_ptr->save_buffer_size)
+ save_size = length;
+ else
+ save_size = png_ptr->save_buffer_size;
+
+ png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
+ length -= save_size;
+ ptr += save_size;
+ png_ptr->buffer_size -= save_size;
+ png_ptr->save_buffer_size -= save_size;
+ png_ptr->save_buffer_ptr += save_size;
+ }
+ if (length && png_ptr->current_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (length < png_ptr->current_buffer_size)
+ save_size = length;
+ else
+ save_size = png_ptr->current_buffer_size;
+
+ png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
+ png_ptr->buffer_size -= save_size;
+ png_ptr->current_buffer_size -= save_size;
+ png_ptr->current_buffer_ptr += save_size;
+ }
+}
+
+void
+png_push_save_buffer(png_structp png_ptr)
+{
+ if (png_ptr->save_buffer_size)
+ {
+ if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
+ {
+ png_size_t i,istop;
+ png_bytep sp;
+ png_bytep dp;
+
+ istop = png_ptr->save_buffer_size;
+ for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
+ i < istop; i++, sp++, dp++)
+ {
+ *dp = *sp;
+ }
+ }
+ }
+ if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
+ png_ptr->save_buffer_max)
+ {
+ png_size_t new_max;
+ png_bytep old_buffer;
+
+ new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
+ old_buffer = png_ptr->save_buffer;
+ png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)new_max);
+ png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
+ png_free(png_ptr, old_buffer);
+ png_ptr->save_buffer_max = new_max;
+ }
+ if (png_ptr->current_buffer_size)
+ {
+ png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
+ png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
+ png_ptr->save_buffer_size += png_ptr->current_buffer_size;
+ png_ptr->current_buffer_size = 0;
+ }
+ png_ptr->save_buffer_ptr = png_ptr->save_buffer;
+ png_ptr->buffer_size = 0;
+}
+
+void
+png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
+ png_size_t buffer_length)
+{
+ png_ptr->current_buffer = buffer;
+ png_ptr->current_buffer_size = buffer_length;
+ png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
+ png_ptr->current_buffer_ptr = png_ptr->current_buffer;
+}
+
+void
+png_push_read_IDAT(png_structp png_ptr)
+{
+ if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
+ {
+ png_byte chunk_length[4];
+
+ if (png_ptr->buffer_size < 8)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_push_fill_buffer(png_ptr, chunk_length, 4);
+ png_ptr->push_length = png_get_uint_32(chunk_length);
+
+ png_reset_crc(png_ptr);
+ png_crc_read(png_ptr, png_ptr->chunk_name, 4);
+ png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
+
+ if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
+ {
+ png_ptr->process_mode = PNG_READ_CHUNK_MODE;
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
+ png_error(png_ptr, "Not enough compressed data");
+ return;
+ }
+
+ png_ptr->idat_size = png_ptr->push_length;
+ }
+ if (png_ptr->idat_size && png_ptr->save_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
+ {
+ save_size = (png_size_t)png_ptr->idat_size;
+ /* check for overflow */
+ if((png_uint_32)save_size != png_ptr->idat_size)
+ png_error(png_ptr, "save_size overflowed in pngpread");
+ }
+ else
+ save_size = png_ptr->save_buffer_size;
+
+ png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
+ png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
+
+ png_ptr->idat_size -= save_size;
+ png_ptr->buffer_size -= save_size;
+ png_ptr->save_buffer_size -= save_size;
+ png_ptr->save_buffer_ptr += save_size;
+ }
+ if (png_ptr->idat_size && png_ptr->current_buffer_size)
+ {
+ png_size_t save_size;
+
+ if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
+ {
+ save_size = (png_size_t)png_ptr->idat_size;
+ /* check for overflow */
+ if((png_uint_32)save_size != png_ptr->idat_size)
+ png_error(png_ptr, "save_size overflowed in pngpread");
+ }
+ else
+ save_size = png_ptr->current_buffer_size;
+
+ png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
+ png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
+
+ png_ptr->idat_size -= save_size;
+ png_ptr->buffer_size -= save_size;
+ png_ptr->current_buffer_size -= save_size;
+ png_ptr->current_buffer_ptr += save_size;
+ }
+ if (!png_ptr->idat_size)
+ {
+ if (png_ptr->buffer_size < 4)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_crc_finish(png_ptr, 0);
+ png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
+ }
+}
+
+void
+png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
+ png_size_t buffer_length)
+{
+ int ret;
+
+ if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
+ png_error(png_ptr, "Extra compression data");
+
+ png_ptr->zstream.next_in = buffer;
+ png_ptr->zstream.avail_in = (uInt)buffer_length;
+ for(;;)
+ {
+ ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
+ if (ret == Z_STREAM_END)
+ {
+ if (png_ptr->zstream.avail_in)
+ png_error(png_ptr, "Extra compressed data");
+ if (!(png_ptr->zstream.avail_out))
+ {
+ png_push_process_row(png_ptr);
+ }
+
+ png_ptr->mode |= PNG_AFTER_IDAT;
+ png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
+ break;
+ }
+ else if (ret == Z_BUF_ERROR)
+ break;
+ else if (ret != Z_OK)
+ png_error(png_ptr, "Decompression Error");
+ if (!(png_ptr->zstream.avail_out))
+ {
+ png_push_process_row(png_ptr);
+ png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
+ png_ptr->zstream.next_out = png_ptr->row_buf;
+ }
+ else
+ break;
+ }
+}
+
+void
+png_push_process_row(png_structp png_ptr)
+{
+ 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);
+
+ switch (png_ptr->pass)
+ {
+ case 0:
+ {
+ int i;
+ for (i = 0; i < 8 && png_ptr->pass == 0; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ break;
+ }
+ case 1:
+ {
+ int i;
+ for (i = 0; i < 8 && png_ptr->pass == 1; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ if (png_ptr->pass == 2)
+ {
+ for (i = 0; i < 4 && png_ptr->pass == 2; i++)
+ {
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ }
+ break;
+ }
+ case 2:
+ {
+ int i;
+ for (i = 0; i < 4 && png_ptr->pass == 2; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ for (i = 0; i < 4 && png_ptr->pass == 2; i++)
+ {
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ break;
+ }
+ case 3:
+ {
+ int i;
+ for (i = 0; i < 4 && png_ptr->pass == 3; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ if (png_ptr->pass == 4)
+ {
+ for (i = 0; i < 2 && png_ptr->pass == 4; i++)
+ {
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ }
+ break;
+ }
+ case 4:
+ {
+ int i;
+ for (i = 0; i < 2 && png_ptr->pass == 4; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ for (i = 0; i < 2 && png_ptr->pass == 4; i++)
+ {
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ break;
+ }
+ case 5:
+ {
+ int i;
+ for (i = 0; i < 2 && png_ptr->pass == 5; i++)
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+ if (png_ptr->pass == 6)
+ {
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ break;
+ }
+ case 6:
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ if (png_ptr->pass != 6)
+ break;
+ png_push_have_row(png_ptr, NULL);
+ png_read_push_finish_row(png_ptr);
+ }
+ }
+ }
+ else
+#endif
+ {
+ png_push_have_row(png_ptr, png_ptr->row_buf + 1);
+ png_read_push_finish_row(png_ptr);
+ }
+}
+
+void
+png_read_push_finish_row(png_structp png_ptr)
+{
+ png_ptr->row_number++;
+ if (png_ptr->row_number < png_ptr->num_rows)
+ return;
+
+ if (png_ptr->interlaced)
+ {
+ png_ptr->row_number = 0;
+ png_memset_check(png_ptr, png_ptr->prev_row, 0,
+ png_ptr->rowbytes + 1);
+ do
+ {
+ png_ptr->pass++;
+ if (png_ptr->pass >= 7)
+ break;
+
+ png_ptr->iwidth = (png_ptr->width +
+ png_pass_inc[png_ptr->pass] - 1 -
+ png_pass_start[png_ptr->pass]) /
+ png_pass_inc[png_ptr->pass];
+
+ png_ptr->irowbytes = ((png_ptr->iwidth *
+ png_ptr->pixel_depth + 7) >> 3) + 1;
+
+ if (png_ptr->transformations & PNG_INTERLACE)
+ break;
+
+ png_ptr->num_rows = (png_ptr->height +
+ png_pass_yinc[png_ptr->pass] - 1 -
+ png_pass_ystart[png_ptr->pass]) /
+ png_pass_yinc[png_ptr->pass];
+
+ } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
+ }
+}
+
+#if defined(PNG_READ_tEXt_SUPPORTED)
+void
+png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
+ {
+ png_error(png_ptr, "Out of place tEXt");
+ /* to quiet some compiler warnings */
+ if(info_ptr == NULL) return;
+ }
+
+#ifdef PNG_MAX_MALLOC_64K
+ png_ptr->skip_length = 0; /* This may not be necessary */
+
+ if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
+ {
+ png_warning(png_ptr, "tEXt chunk too large to fit in memory");
+ png_ptr->skip_length = length - (png_uint_32)65535L;
+ length = (png_uint_32)65535L;
+ }
+#endif
+
+ png_ptr->current_text = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)(length+1));
+ png_ptr->current_text[length] = '\0';
+ png_ptr->current_text_ptr = png_ptr->current_text;
+ png_ptr->current_text_size = (png_size_t)length;
+ png_ptr->current_text_left = (png_size_t)length;
+ png_ptr->process_mode = PNG_READ_tEXt_MODE;
+}
+
+void
+png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
+{
+ if (png_ptr->buffer_size && png_ptr->current_text_left)
+ {
+ png_size_t text_size;
+
+ if (png_ptr->buffer_size < png_ptr->current_text_left)
+ text_size = png_ptr->buffer_size;
+ else
+ text_size = png_ptr->current_text_left;
+ png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
+ png_ptr->current_text_left -= text_size;
+ png_ptr->current_text_ptr += text_size;
+ }
+ if (!(png_ptr->current_text_left))
+ {
+ png_textp text_ptr;
+ png_charp text;
+ png_charp key;
+
+ if (png_ptr->buffer_size < 4)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_push_crc_finish(png_ptr);
+
+#if defined(PNG_MAX_MALLOC_64K)
+ if (png_ptr->skip_length)
+ return;
+#endif
+
+ key = png_ptr->current_text;
+ png_ptr->current_text = 0;
+
+ for (text = key; *text; text++)
+ /* empty loop */ ;
+
+ if (text != key + png_ptr->current_text_size)
+ text++;
+
+ text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
+ text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
+ text_ptr->key = key;
+ text_ptr->text = text;
+
+ png_set_text(png_ptr, info_ptr, text_ptr, 1);
+
+ png_free(png_ptr, text_ptr);
+ }
+}
+#endif
+
+#if defined(PNG_READ_zTXt_SUPPORTED)
+void
+png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
+ {
+ png_error(png_ptr, "Out of place zTXt");
+ /* to quiet some compiler warnings */
+ if(info_ptr == NULL) return;
+ }
+
+#ifdef PNG_MAX_MALLOC_64K
+ /* We can't handle zTXt chunks > 64K, since we don't have enough space
+ * to be able to store the uncompressed data. Actually, the threshold
+ * is probably around 32K, but it isn't as definite as 64K is.
+ */
+ if (length > (png_uint_32)65535L)
+ {
+ png_warning(png_ptr, "zTXt chunk too large to fit in memory");
+ png_push_crc_skip(png_ptr, length);
+ return;
+ }
+#endif
+
+ png_ptr->current_text = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)(length+1));
+ png_ptr->current_text[length] = '\0';
+ png_ptr->current_text_ptr = png_ptr->current_text;
+ png_ptr->current_text_size = (png_size_t)length;
+ png_ptr->current_text_left = (png_size_t)length;
+ png_ptr->process_mode = PNG_READ_zTXt_MODE;
+}
+
+void
+png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
+{
+ if (png_ptr->buffer_size && png_ptr->current_text_left)
+ {
+ png_size_t text_size;
+
+ if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
+ text_size = png_ptr->buffer_size;
+ else
+ text_size = png_ptr->current_text_left;
+ png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
+ png_ptr->current_text_left -= text_size;
+ png_ptr->current_text_ptr += text_size;
+ }
+ if (!(png_ptr->current_text_left))
+ {
+ png_textp text_ptr;
+ png_charp text;
+ png_charp key;
+ int ret;
+ png_size_t text_size, key_size;
+
+ if (png_ptr->buffer_size < 4)
+ {
+ png_push_save_buffer(png_ptr);
+ return;
+ }
+
+ png_push_crc_finish(png_ptr);
+
+ key = png_ptr->current_text;
+ png_ptr->current_text = 0;
+
+ for (text = key; *text; text++)
+ /* empty loop */ ;
+
+ /* zTXt can't have zero text */
+ if (text == key + png_ptr->current_text_size)
+ {
+ png_free(png_ptr, key);
+ return;
+ }
+
+ text++;
+
+ if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
+ {
+ png_free(png_ptr, key);
+ return;
+ }
+
+ text++;
+
+ png_ptr->zstream.next_in = (png_bytep )text;
+ png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
+ (text - key));
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+
+ key_size = text - key;
+ text_size = 0;
+ text = NULL;
+ ret = Z_STREAM_END;
+
+ while (png_ptr->zstream.avail_in)
+ {
+ ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
+ if (ret != Z_OK && ret != Z_STREAM_END)
+ {
+ inflateReset(&png_ptr->zstream);
+ png_ptr->zstream.avail_in = 0;
+ png_free(png_ptr, key);
+ png_free(png_ptr, text);
+ return;
+ }
+ if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
+ {
+ if (text == NULL)
+ {
+ text = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out +
+ key_size + 1));
+ png_memcpy(text + key_size, png_ptr->zbuf,
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ png_memcpy(text, key, key_size);
+ text_size = key_size + png_ptr->zbuf_size -
+ png_ptr->zstream.avail_out;
+ *(text + text_size) = '\0';
+ }
+ else
+ {
+ png_charp tmp;
+
+ tmp = text;
+ text = (png_charp)png_malloc(png_ptr, text_size +
+ (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ + 1));
+ png_memcpy(text, tmp, text_size);
+ png_free(png_ptr, tmp);
+ png_memcpy(text + text_size, png_ptr->zbuf,
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
+ *(text + text_size) = '\0';
+ }
+ if (ret != Z_STREAM_END)
+ {
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ }
+ }
+ else
+ {
+ break;
+ }
+
+ if (ret == Z_STREAM_END)
+ break;
+ }
+
+ inflateReset(&png_ptr->zstream);
+ png_ptr->zstream.avail_in = 0;
+
+ if (ret != Z_STREAM_END)
+ {
+ png_free(png_ptr, key);
+ png_free(png_ptr, text);
+ return;
+ }
+
+ png_free(png_ptr, key);
+ key = text;
+ text += key_size;
+
+ text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
+ text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
+ text_ptr->key = key;
+ text_ptr->text = text;
+
+ png_set_text(png_ptr, info_ptr, text_ptr, 1);
+
+ png_free(png_ptr, text_ptr);
+ }
+}
+#endif
+
+/* This function is called when we haven't found a handler for this
+ * chunk. In the future we will have code here that can handle
+ * user-defined callback functions for unknown chunks before they are
+ * ignored or cause an error. If there isn't a problem with the
+ * chunk itself (ie a bad chunk name or a critical chunk), the chunk
+ * is (currently) silently ignored.
+ */
+void
+png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_check_chunk_name(png_ptr, png_ptr->chunk_name);
+
+ if (!(png_ptr->chunk_name[0] & 0x20))
+ {
+ png_chunk_error(png_ptr, "unknown critical chunk");
+ /* to quiet some compiler warnings */
+ if(info_ptr == NULL) return;
+ }
+
+ png_push_crc_skip(png_ptr, length);
+}
+
+void
+png_push_have_info(png_structp png_ptr, png_infop info_ptr)
+{
+ if (png_ptr->info_fn != NULL)
+ (*(png_ptr->info_fn))(png_ptr, info_ptr);
+}
+
+void
+png_push_have_end(png_structp png_ptr, png_infop info_ptr)
+{
+ if (png_ptr->end_fn != NULL)
+ (*(png_ptr->end_fn))(png_ptr, info_ptr);
+}
+
+void
+png_push_have_row(png_structp png_ptr, png_bytep row)
+{
+ if (png_ptr->row_fn != NULL)
+ (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
+ (int)png_ptr->pass);
+}
+
+void
+png_progressive_combine_row (png_structp png_ptr,
+ png_bytep old_row, png_bytep new_row)
+{
+ if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
+ png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
+}
+
+void
+png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
+ png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
+ png_progressive_end_ptr end_fn)
+{
+ png_ptr->info_fn = info_fn;
+ png_ptr->row_fn = row_fn;
+ png_ptr->end_fn = end_fn;
+
+ png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
+}
+
+png_voidp
+png_get_progressive_ptr(png_structp png_ptr)
+{
+ return png_ptr->io_ptr;
+}
+
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+
diff --git a/osframework/source/ImageLib/png/pngread.c b/osframework/source/ImageLib/png/pngread.c
new file mode 100644
index 0000000..b9e79a9
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngread.c
@@ -0,0 +1,896 @@
+
+/* pngread.c - read a PNG file
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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_debug2(0, "Reading %s chunk, length=%d.\n", png_ptr->chunk_name,
+ length);
+
+ /* 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.5.
+ */
+
+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.5.
+ */
+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 */
+
+#ifdef PNG_READ_INTERLACING_SUPPORTED
+ pass = png_set_interlace_handling(png_ptr);
+#else
+ if (png_ptr->interlaced)
+ png_error(png_ptr,
+ "Cannot read interlaced image -- interlace handler disabled.");
+ pass = 1;
+#endif
+
+
+ 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 defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
+ defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
+ png_free(png_ptr, png_ptr->trans);
+#endif
+#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]);
+ }
+ png_free(png_ptr, png_ptr->gamma_16_table);
+ }
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ 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;
+}
diff --git a/osframework/source/ImageLib/png/pngrio.c b/osframework/source/ImageLib/png/pngrio.c
new file mode 100644
index 0000000..80e0eec
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngrio.c
@@ -0,0 +1,151 @@
+
+/* pngrio.c - functions for data input
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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 */
+}
+
diff --git a/osframework/source/ImageLib/png/pngrtran.c b/osframework/source/ImageLib/png/pngrtran.c
new file mode 100644
index 0000000..e31aad5
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngrtran.c
@@ -0,0 +1,3986 @@
+
+/* pngrtran.c - transforms the data in a row for PNG readers
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ *
+ * This file contains functions optionally called by an application
+ * in order to tell libpng how to handle data when reading a PNG.
+ * Transformations that are used in both reading and writing are
+ * in pngtrans.c.
+ */
+
+#define PNG_INTERNAL
+#include "png.h"
+
+/* Set the action on getting a CRC error for an ancillary or critical chunk. */
+void
+png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
+{
+ png_debug(1, "in png_set_crc_action\n");
+ /* Tell libpng how we react to CRC errors in critical chunks */
+ switch (crit_action)
+ {
+ case PNG_CRC_NO_CHANGE: /* leave setting as is */
+ break;
+ case PNG_CRC_WARN_USE: /* warn/use data */
+ png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
+ png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
+ break;
+ case PNG_CRC_QUIET_USE: /* quiet/use data */
+ png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
+ png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
+ PNG_FLAG_CRC_CRITICAL_IGNORE;
+ break;
+ case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
+ png_warning(png_ptr, "Can't discard critical data on CRC error.");
+ case PNG_CRC_ERROR_QUIT: /* error/quit */
+ case PNG_CRC_DEFAULT:
+ default:
+ png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
+ break;
+ }
+
+ switch (ancil_action)
+ {
+ case PNG_CRC_NO_CHANGE: /* leave setting as is */
+ break;
+ case PNG_CRC_WARN_USE: /* warn/use data */
+ png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
+ png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
+ break;
+ case PNG_CRC_QUIET_USE: /* quiet/use data */
+ png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
+ png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
+ PNG_FLAG_CRC_ANCILLARY_NOWARN;
+ break;
+ case PNG_CRC_ERROR_QUIT: /* error/quit */
+ png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
+ png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
+ break;
+ case PNG_CRC_WARN_DISCARD: /* warn/discard data */
+ case PNG_CRC_DEFAULT:
+ default:
+ png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
+ break;
+ }
+}
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+/* handle alpha and tRNS via a background color */
+void
+png_set_background(png_structp png_ptr,
+ png_color_16p background_color, int background_gamma_code,
+ int need_expand, double background_gamma)
+{
+ png_debug(1, "in png_set_background\n");
+ if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
+ {
+ png_warning(png_ptr, "Application must supply a known background gamma");
+ return;
+ }
+
+ png_ptr->transformations |= PNG_BACKGROUND;
+ png_memcpy(&(png_ptr->background), background_color, sizeof(png_color_16));
+ png_ptr->background_gamma = (float)background_gamma;
+ png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
+ png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
+
+ /* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA
+ * (in which case need_expand is superfluous anyway), the background color
+ * might actually be gray yet not be flagged as such. This is not a problem
+ * for the current code, which uses PNG_FLAG_BACKGROUND_IS_GRAY only to
+ * decide when to do the png_do_gray_to_rgb() transformation.
+ */
+ if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) ||
+ (!need_expand && background_color->red == background_color->green &&
+ background_color->red == background_color->blue))
+ png_ptr->flags |= PNG_FLAG_BACKGROUND_IS_GRAY;
+}
+#endif
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+/* strip 16 bit depth files to 8 bit depth */
+void
+png_set_strip_16(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_strip_16\n");
+ png_ptr->transformations |= PNG_16_TO_8;
+}
+#endif
+
+#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
+void
+png_set_strip_alpha(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_strip_alpha\n");
+ png_ptr->transformations |= PNG_STRIP_ALPHA;
+}
+#endif
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+/* Dither file to 8 bit. Supply a palette, the current number
+ * of elements in the palette, the maximum number of elements
+ * allowed, and a histogram if possible. If the current number
+ * of colors is greater then the maximum number, the palette will be
+ * modified to fit in the maximum number. "full_dither" indicates
+ * whether we need a dithering cube set up for RGB images, or if we
+ * simply are reducing the number of colors in a paletted image.
+ */
+
+typedef struct png_dsort_struct
+{
+ struct png_dsort_struct FAR * next;
+ png_byte left;
+ png_byte right;
+} png_dsort;
+typedef png_dsort FAR * png_dsortp;
+typedef png_dsort FAR * FAR * png_dsortpp;
+
+void
+png_set_dither(png_structp png_ptr, png_colorp palette,
+ int num_palette, int maximum_colors, png_uint_16p histogram,
+ int full_dither)
+{
+ png_debug(1, "in png_set_dither\n");
+ png_ptr->transformations |= PNG_DITHER;
+
+ if (!full_dither)
+ {
+ int i;
+
+ png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)(num_palette * sizeof (png_byte)));
+ for (i = 0; i < num_palette; i++)
+ png_ptr->dither_index[i] = (png_byte)i;
+ }
+
+ if (num_palette > maximum_colors)
+ {
+ if (histogram != NULL)
+ {
+ /* This is easy enough, just throw out the least used colors.
+ Perhaps not the best solution, but good enough. */
+
+ int i;
+ png_bytep sort;
+
+ /* initialize an array to sort colors */
+ sort = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_palette
+ * sizeof (png_byte)));
+
+ /* initialize the sort array */
+ for (i = 0; i < num_palette; i++)
+ sort[i] = (png_byte)i;
+
+ /* Find the least used palette entries by starting a
+ bubble sort, and running it until we have sorted
+ out enough colors. Note that we don't care about
+ sorting all the colors, just finding which are
+ least used. */
+
+ for (i = num_palette - 1; i >= maximum_colors; i--)
+ {
+ int done; /* to stop early if the list is pre-sorted */
+ int j;
+
+ done = 1;
+ for (j = 0; j < i; j++)
+ {
+ if (histogram[sort[j]] < histogram[sort[j + 1]])
+ {
+ png_byte t;
+
+ t = sort[j];
+ sort[j] = sort[j + 1];
+ sort[j + 1] = t;
+ done = 0;
+ }
+ }
+ if (done)
+ break;
+ }
+
+ /* swap the palette around, and set up a table, if necessary */
+ if (full_dither)
+ {
+ int j = num_palette;
+
+ /* put all the useful colors within the max, but don't
+ move the others */
+ for (i = 0; i < maximum_colors; i++)
+ {
+ if ((int)sort[i] >= maximum_colors)
+ {
+ do
+ j--;
+ while ((int)sort[j] >= maximum_colors);
+ palette[i] = palette[j];
+ }
+ }
+ }
+ else
+ {
+ int j = num_palette;
+
+ /* move all the used colors inside the max limit, and
+ develop a translation table */
+ for (i = 0; i < maximum_colors; i++)
+ {
+ /* only move the colors we need to */
+ if ((int)sort[i] >= maximum_colors)
+ {
+ png_color tmp_color;
+
+ do
+ j--;
+ while ((int)sort[j] >= maximum_colors);
+
+ tmp_color = palette[j];
+ palette[j] = palette[i];
+ palette[i] = tmp_color;
+ /* indicate where the color went */
+ png_ptr->dither_index[j] = (png_byte)i;
+ png_ptr->dither_index[i] = (png_byte)j;
+ }
+ }
+
+ /* find closest color for those colors we are not using */
+ for (i = 0; i < num_palette; i++)
+ {
+ if ((int)png_ptr->dither_index[i] >= maximum_colors)
+ {
+ int min_d, k, min_k, d_index;
+
+ /* find the closest color to one we threw out */
+ d_index = png_ptr->dither_index[i];
+ min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
+ for (k = 1, min_k = 0; k < maximum_colors; k++)
+ {
+ int d;
+
+ d = PNG_COLOR_DIST(palette[d_index], palette[k]);
+
+ if (d < min_d)
+ {
+ min_d = d;
+ min_k = k;
+ }
+ }
+ /* point to closest color */
+ png_ptr->dither_index[i] = (png_byte)min_k;
+ }
+ }
+ }
+ png_free(png_ptr, sort);
+ }
+ else
+ {
+ /* This is much harder to do simply (and quickly). Perhaps
+ we need to go through a median cut routine, but those
+ don't always behave themselves with only a few colors
+ as input. So we will just find the closest two colors,
+ and throw out one of them (chosen somewhat randomly).
+ [We don't understand this at all, so if someone wants to
+ work on improving it, be our guest - AED, GRP]
+ */
+ int i;
+ int max_d;
+ int num_new_palette;
+ png_dsortpp hash;
+ png_bytep index_to_palette;
+ /* where the original index currently is in the palette */
+ png_bytep palette_to_index;
+ /* which original index points to this palette color */
+
+ /* initialize palette index arrays */
+ index_to_palette = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)(num_palette * sizeof (png_byte)));
+ palette_to_index = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)(num_palette * sizeof (png_byte)));
+
+ /* initialize the sort array */
+ for (i = 0; i < num_palette; i++)
+ {
+ index_to_palette[i] = (png_byte)i;
+ palette_to_index[i] = (png_byte)i;
+ }
+
+ hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
+ sizeof (png_dsortp)));
+ for (i = 0; i < 769; i++)
+ hash[i] = NULL;
+/* png_memset(hash, 0, 769 * sizeof (png_dsortp)); */
+
+ num_new_palette = num_palette;
+
+ /* initial wild guess at how far apart the farthest pixel
+ pair we will be eliminating will be. Larger
+ numbers mean more areas will be allocated, Smaller
+ numbers run the risk of not saving enough data, and
+ having to do this all over again.
+
+ I have not done extensive checking on this number.
+ */
+ max_d = 96;
+
+ while (num_new_palette > maximum_colors)
+ {
+ for (i = 0; i < num_new_palette - 1; i++)
+ {
+ int j;
+
+ for (j = i + 1; j < num_new_palette; j++)
+ {
+ int d;
+
+ d = PNG_COLOR_DIST(palette[i], palette[j]);
+
+ if (d <= max_d)
+ {
+ png_dsortp t;
+
+ t = (png_dsortp)png_malloc(png_ptr, (png_uint_32)(sizeof
+ (png_dsort)));
+ t->next = hash[d];
+ t->left = (png_byte)i;
+ t->right = (png_byte)j;
+ hash[d] = t;
+ }
+ }
+ }
+
+ for (i = 0; i <= max_d; i++)
+ {
+ if (hash[i] != NULL)
+ {
+ png_dsortp p;
+
+ for (p = hash[i]; p; p = p->next)
+ {
+ if ((int)index_to_palette[p->left] < num_new_palette &&
+ (int)index_to_palette[p->right] < num_new_palette)
+ {
+ int j, next_j;
+
+ if (num_new_palette & 1)
+ {
+ j = p->left;
+ next_j = p->right;
+ }
+ else
+ {
+ j = p->right;
+ next_j = p->left;
+ }
+
+ num_new_palette--;
+ palette[index_to_palette[j]] = palette[num_new_palette];
+ if (!full_dither)
+ {
+ int k;
+
+ for (k = 0; k < num_palette; k++)
+ {
+ if (png_ptr->dither_index[k] ==
+ index_to_palette[j])
+ png_ptr->dither_index[k] =
+ index_to_palette[next_j];
+ if ((int)png_ptr->dither_index[k] ==
+ num_new_palette)
+ png_ptr->dither_index[k] =
+ index_to_palette[j];
+ }
+ }
+
+ index_to_palette[palette_to_index[num_new_palette]] =
+ index_to_palette[j];
+ palette_to_index[index_to_palette[j]] =
+ palette_to_index[num_new_palette];
+
+ index_to_palette[j] = (png_byte)num_new_palette;
+ palette_to_index[num_new_palette] = (png_byte)j;
+ }
+ if (num_new_palette <= maximum_colors)
+ break;
+ }
+ if (num_new_palette <= maximum_colors)
+ break;
+ }
+ }
+
+ for (i = 0; i < 769; i++)
+ {
+ if (hash[i] != NULL)
+ {
+ png_dsortp p = hash[i];
+ while (p)
+ {
+ png_dsortp t;
+
+ t = p->next;
+ png_free(png_ptr, p);
+ p = t;
+ }
+ }
+ hash[i] = 0;
+ }
+ max_d += 96;
+ }
+ png_free(png_ptr, hash);
+ png_free(png_ptr, palette_to_index);
+ png_free(png_ptr, index_to_palette);
+ }
+ num_palette = maximum_colors;
+ }
+ if (png_ptr->palette == NULL)
+ {
+ png_ptr->palette = palette;
+ }
+ png_ptr->num_palette = (png_uint_16)num_palette;
+
+ if (full_dither)
+ {
+ int i;
+ png_bytep distance;
+ int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
+ PNG_DITHER_BLUE_BITS;
+ int num_red = (1 << PNG_DITHER_RED_BITS);
+ int num_green = (1 << PNG_DITHER_GREEN_BITS);
+ int num_blue = (1 << PNG_DITHER_BLUE_BITS);
+ png_size_t num_entries = ((png_size_t)1 << total_bits);
+
+ png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
+ (png_uint_32)(num_entries * sizeof (png_byte)));
+
+ png_memset(png_ptr->palette_lookup, 0, num_entries * sizeof (png_byte));
+
+ distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
+ sizeof(png_byte)));
+
+ png_memset(distance, 0xff, num_entries * sizeof(png_byte));
+
+ for (i = 0; i < num_palette; i++)
+ {
+ int ir, ig, ib;
+ int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
+ int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
+ int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
+
+ for (ir = 0; ir < num_red; ir++)
+ {
+ int dr = abs(ir - r);
+ int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
+
+ for (ig = 0; ig < num_green; ig++)
+ {
+ int dg = abs(ig - g);
+ int dt = dr + dg;
+ int dm = ((dr > dg) ? dr : dg);
+ int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
+
+ for (ib = 0; ib < num_blue; ib++)
+ {
+ int d_index = index_g | ib;
+ int db = abs(ib - b);
+ int dmax = ((dm > db) ? dm : db);
+ int d = dmax + dt + db;
+
+ if (d < (int)distance[d_index])
+ {
+ distance[d_index] = (png_byte)d;
+ png_ptr->palette_lookup[d_index] = (png_byte)i;
+ }
+ }
+ }
+ }
+ }
+
+ png_free(png_ptr, distance);
+ }
+}
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+/* Transform the image from the file_gamma to the screen_gamma. We
+ * only do transformations on images where the file_gamma and screen_gamma
+ * are not close reciprocals, otherwise it slows things down slightly, and
+ * also needlessly introduces small errors.
+ */
+void
+png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
+{
+ png_debug(1, "in png_set_gamma\n");
+ if (fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
+ png_ptr->transformations |= PNG_GAMMA;
+ png_ptr->gamma = (float)file_gamma;
+ png_ptr->screen_gamma = (float)scrn_gamma;
+}
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+/* Expand paletted images to RGB, expand grayscale images of
+ * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
+ * to alpha channels.
+ */
+void
+png_set_expand(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_expand\n");
+ png_ptr->transformations |= PNG_EXPAND;
+}
+
+/* GRR 19990627: the following three functions currently are identical
+ * to png_set_expand(). However, it is entirely reasonable that someone
+ * might wish to expand an indexed image to RGB but *not* expand a single,
+ * fully transparent palette entry to a full alpha channel--perhaps instead
+ * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
+ * the transparent color with a particular RGB value, or drop tRNS entirely.
+ * IOW, a future version of the library may make the transformations flag
+ * a bit more fine-grained, with separate bits for each of these three
+ * functions.
+ *
+ * More to the point, these functions make it obvious what libpng will be
+ * doing, whereas "expand" can (and does) mean any number of things.
+ */
+
+/* Expand paletted images to RGB. */
+void
+png_set_palette_to_rgb(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_expand\n");
+ png_ptr->transformations |= PNG_EXPAND;
+}
+
+/* Expand grayscale images of less than 8-bit depth to 8 bits. */
+void
+png_set_gray_1_2_4_to_8(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_expand\n");
+ png_ptr->transformations |= PNG_EXPAND;
+}
+
+/* Expand tRNS chunks to alpha channels. */
+void
+png_set_tRNS_to_alpha(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_expand\n");
+ png_ptr->transformations |= PNG_EXPAND;
+}
+#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+void
+png_set_gray_to_rgb(png_structp png_ptr)
+{
+ png_debug(1, "in png_set_gray_to_rgb\n");
+ png_ptr->transformations |= PNG_GRAY_TO_RGB;
+}
+#endif
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+/* Convert a RGB image to a grayscale of the same width. This allows us,
+ * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
+ */
+void
+png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
+ double green)
+{
+ png_debug(1, "in png_set_rgb_to_gray\n");
+ switch(error_action)
+ {
+ case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
+ break;
+ case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
+ break;
+ case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
+ }
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ png_ptr->transformations |= PNG_EXPAND;
+#else
+ {
+ png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
+ png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
+ }
+#endif
+ {
+ png_byte red_byte = (png_byte)((float)red*255.0 + 0.5);
+ png_byte green_byte = (png_byte)((float)green*255.0 + 0.5);
+ if(red < 0.0 || green < 0.0)
+ {
+ red_byte = 54;
+ green_byte = 183;
+ }
+ else if(red_byte + green_byte > 255)
+ {
+ png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
+ red_byte = 54;
+ green_byte = 183;
+ }
+ png_ptr->rgb_to_gray_red_coeff = red_byte;
+ png_ptr->rgb_to_gray_green_coeff = green_byte;
+ png_ptr->rgb_to_gray_blue_coeff = (png_byte)(255-red_byte-green_byte);
+ }
+}
+#endif
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+void
+png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
+ read_user_transform_fn)
+{
+ png_debug(1, "in png_set_read_user_transform_fn\n");
+ png_ptr->transformations |= PNG_USER_TRANSFORM;
+ png_ptr->read_user_transform_fn = read_user_transform_fn;
+}
+#endif
+
+/* Initialize everything needed for the read. This includes modifying
+ * the palette.
+ */
+void
+png_init_read_transformations(png_structp png_ptr)
+{
+ png_debug(1, "in png_init_read_transformations\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if(png_ptr != NULL)
+#endif
+ {
+#if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
+ || defined(PNG_READ_GAMMA_SUPPORTED)
+ int color_type = png_ptr->color_type;
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
+ {
+ if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
+ {
+ /* expand background chunk. */
+ switch (png_ptr->bit_depth)
+ {
+ case 1:
+ png_ptr->background.gray *= (png_uint_16)0xff;
+ png_ptr->background.red = png_ptr->background.green =
+ png_ptr->background.blue = png_ptr->background.gray;
+ break;
+ case 2:
+ png_ptr->background.gray *= (png_uint_16)0x55;
+ png_ptr->background.red = png_ptr->background.green =
+ png_ptr->background.blue = png_ptr->background.gray;
+ break;
+ case 4:
+ png_ptr->background.gray *= (png_uint_16)0x11;
+ png_ptr->background.red = png_ptr->background.green =
+ png_ptr->background.blue = png_ptr->background.gray;
+ break;
+ case 8:
+ case 16:
+ png_ptr->background.red = png_ptr->background.green =
+ png_ptr->background.blue = png_ptr->background.gray;
+ break;
+ }
+ }
+ else if (color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_ptr->background.red =
+ png_ptr->palette[png_ptr->background.index].red;
+ png_ptr->background.green =
+ png_ptr->palette[png_ptr->background.index].green;
+ png_ptr->background.blue =
+ png_ptr->palette[png_ptr->background.index].blue;
+
+#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
+ if (png_ptr->transformations & PNG_INVERT_ALPHA)
+ {
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ if (!(png_ptr->transformations & PNG_EXPAND))
+#endif
+ {
+ /* invert the alpha channel (in tRNS) unless the pixels are
+ going to be expanded, in which case leave it for later */
+ int i,istop;
+ istop=(int)png_ptr->num_trans;
+ for (i=0; i<istop; i++)
+ png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
+ }
+ }
+#endif
+
+ }
+ }
+#endif
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ png_ptr->background_1 = png_ptr->background;
+#endif
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY))
+ {
+ png_build_gamma_table(png_ptr);
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->transformations & PNG_BACKGROUND)
+ {
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_color back, back_1;
+ png_colorp palette = png_ptr->palette;
+ int num_palette = png_ptr->num_palette;
+ int i;
+
+ if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
+ {
+ back.red = png_ptr->gamma_table[png_ptr->background.red];
+ back.green = png_ptr->gamma_table[png_ptr->background.green];
+ back.blue = png_ptr->gamma_table[png_ptr->background.blue];
+
+ back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
+ back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
+ back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
+ }
+ else
+ {
+ double g, gs;
+
+ switch (png_ptr->background_gamma_type)
+ {
+ case PNG_BACKGROUND_GAMMA_SCREEN:
+ g = (png_ptr->screen_gamma);
+ gs = 1.0;
+ break;
+ case PNG_BACKGROUND_GAMMA_FILE:
+ g = 1.0 / (png_ptr->gamma);
+ gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
+ break;
+ case PNG_BACKGROUND_GAMMA_UNIQUE:
+ g = 1.0 / (png_ptr->background_gamma);
+ gs = 1.0 / (png_ptr->background_gamma *
+ png_ptr->screen_gamma);
+ break;
+ default:
+ g = 1.0; /* back_1 */
+ gs = 1.0; /* back */
+ }
+
+ if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
+ {
+ back.red = (png_byte)png_ptr->background.red;
+ back.green = (png_byte)png_ptr->background.green;
+ back.blue = (png_byte)png_ptr->background.blue;
+ }
+ else
+ {
+ back.red = (png_byte)(pow(
+ (double)png_ptr->background.red/255, gs) * 255.0 + .5);
+ back.green = (png_byte)(pow(
+ (double)png_ptr->background.green/255, gs) * 255.0 + .5);
+ back.blue = (png_byte)(pow(
+ (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
+ }
+
+ back_1.red = (png_byte)(pow(
+ (double)png_ptr->background.red/255, g) * 255.0 + .5);
+ back_1.green = (png_byte)(pow(
+ (double)png_ptr->background.green/255, g) * 255.0 + .5);
+ back_1.blue = (png_byte)(pow(
+ (double)png_ptr->background.blue/255, g) * 255.0 + .5);
+ }
+
+ for (i = 0; i < num_palette; i++)
+ {
+ if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
+ {
+ if (png_ptr->trans[i] == 0)
+ {
+ palette[i] = back;
+ }
+ else /* if (png_ptr->trans[i] != 0xff) */
+ {
+ png_byte v, w;
+
+ v = png_ptr->gamma_to_1[palette[i].red];
+ png_composite(w, v, png_ptr->trans[i], back_1.red);
+ palette[i].red = png_ptr->gamma_from_1[w];
+
+ v = png_ptr->gamma_to_1[palette[i].green];
+ png_composite(w, v, png_ptr->trans[i], back_1.green);
+ palette[i].green = png_ptr->gamma_from_1[w];
+
+ v = png_ptr->gamma_to_1[palette[i].blue];
+ png_composite(w, v, png_ptr->trans[i], back_1.blue);
+ palette[i].blue = png_ptr->gamma_from_1[w];
+ }
+ }
+ else
+ {
+ palette[i].red = png_ptr->gamma_table[palette[i].red];
+ palette[i].green = png_ptr->gamma_table[palette[i].green];
+ palette[i].blue = png_ptr->gamma_table[palette[i].blue];
+ }
+ }
+ }
+ /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN)*/
+ else
+ /* color_type != PNG_COLOR_TYPE_PALETTE */
+ {
+ double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
+ double g = 1.0;
+ double gs = 1.0;
+
+ switch (png_ptr->background_gamma_type)
+ {
+ case PNG_BACKGROUND_GAMMA_SCREEN:
+ g = (png_ptr->screen_gamma);
+ gs = 1.0;
+ break;
+ case PNG_BACKGROUND_GAMMA_FILE:
+ g = 1.0 / (png_ptr->gamma);
+ gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
+ break;
+ case PNG_BACKGROUND_GAMMA_UNIQUE:
+ g = 1.0 / (png_ptr->background_gamma);
+ gs = 1.0 / (png_ptr->background_gamma *
+ png_ptr->screen_gamma);
+ break;
+ }
+
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ /* RGB or RGBA */
+ png_ptr->background_1.red = (png_uint_16)(pow(
+ (double)png_ptr->background.red / m, g) * m + .5);
+ png_ptr->background_1.green = (png_uint_16)(pow(
+ (double)png_ptr->background.green / m, g) * m + .5);
+ png_ptr->background_1.blue = (png_uint_16)(pow(
+ (double)png_ptr->background.blue / m, g) * m + .5);
+ png_ptr->background.red = (png_uint_16)(pow(
+ (double)png_ptr->background.red / m, gs) * m + .5);
+ png_ptr->background.green = (png_uint_16)(pow(
+ (double)png_ptr->background.green / m, gs) * m + .5);
+ png_ptr->background.blue = (png_uint_16)(pow(
+ (double)png_ptr->background.blue / m, gs) * m + .5);
+ }
+ else
+ {
+ /* GRAY or GRAY ALPHA */
+ png_ptr->background_1.gray = (png_uint_16)(pow(
+ (double)png_ptr->background.gray / m, g) * m + .5);
+ png_ptr->background.gray = (png_uint_16)(pow(
+ (double)png_ptr->background.gray / m, gs) * m + .5);
+ }
+ }
+ }
+ else
+ /* transformation does not include PNG_BACKGROUND */
+#endif
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_colorp palette = png_ptr->palette;
+ int num_palette = png_ptr->num_palette;
+ int i;
+
+ for (i = 0; i < num_palette; i++)
+ {
+ palette[i].red = png_ptr->gamma_table[palette[i].red];
+ palette[i].green = png_ptr->gamma_table[palette[i].green];
+ palette[i].blue = png_ptr->gamma_table[palette[i].blue];
+ }
+ }
+ }
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ else
+#endif
+#endif
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ /* No GAMMA transformation */
+ if (png_ptr->transformations & PNG_BACKGROUND &&
+ color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ int i;
+ int istop = (int)png_ptr->num_trans;
+ png_color back;
+ png_colorp palette = png_ptr->palette;
+
+ back.red = (png_byte)png_ptr->background.red;
+ back.green = (png_byte)png_ptr->background.green;
+ back.blue = (png_byte)png_ptr->background.blue;
+
+ for (i = 0; i < istop; i++)
+ {
+ if (png_ptr->trans[i] == 0)
+ {
+ palette[i] = back;
+ }
+ else if (png_ptr->trans[i] != 0xff)
+ {
+ /* The png_composite() macro is defined in png.h */
+ png_composite(palette[i].red, palette[i].red,
+ png_ptr->trans[i], back.red);
+ png_composite(palette[i].green, palette[i].green,
+ png_ptr->trans[i], back.green);
+ png_composite(palette[i].blue, palette[i].blue,
+ png_ptr->trans[i], back.blue);
+ }
+ }
+ }
+#endif
+
+#if defined(PNG_READ_SHIFT_SUPPORTED)
+ if ((png_ptr->transformations & PNG_SHIFT) &&
+ color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_uint_16 i;
+ png_uint_16 istop = png_ptr->num_palette;
+ int sr = 8 - png_ptr->sig_bit.red;
+ int sg = 8 - png_ptr->sig_bit.green;
+ int sb = 8 - png_ptr->sig_bit.blue;
+
+ if (sr < 0 || sr > 8)
+ sr = 0;
+ if (sg < 0 || sg > 8)
+ sg = 0;
+ if (sb < 0 || sb > 8)
+ sb = 0;
+ for (i = 0; i < istop; i++)
+ {
+ png_ptr->palette[i].red >>= sr;
+ png_ptr->palette[i].green >>= sg;
+ png_ptr->palette[i].blue >>= sb;
+ }
+ }
+#endif
+ }
+}
+
+/* Modify the info structure to reflect the transformations. The
+ * info should be updated so a PNG file could be written with it,
+ * assuming the transformations result in valid PNG data.
+ */
+void
+png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
+{
+ png_debug(1, "in png_read_transform_info\n");
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ if (png_ptr->transformations & PNG_EXPAND)
+ {
+ if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (png_ptr->num_trans)
+ info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ else
+ info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+ info_ptr->bit_depth = 8;
+ info_ptr->num_trans = 0;
+ }
+ else
+ {
+ if (png_ptr->num_trans)
+ info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+ if (info_ptr->bit_depth < 8)
+ info_ptr->bit_depth = 8;
+ info_ptr->num_trans = 0;
+ }
+ }
+#endif
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->transformations & PNG_BACKGROUND)
+ {
+ info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
+ info_ptr->num_trans = 0;
+ info_ptr->background = png_ptr->background;
+ }
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (png_ptr->transformations & PNG_GAMMA)
+ info_ptr->gamma = png_ptr->gamma;
+#endif
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+ if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16)
+ info_ptr->bit_depth = 8;
+#endif
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+ if (png_ptr->transformations & PNG_DITHER)
+ {
+ if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
+ (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
+ png_ptr->palette_lookup && info_ptr->bit_depth == 8)
+ {
+ info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+ }
+ }
+#endif
+
+#if defined(PNG_READ_PACK_SUPPORTED)
+ if ((png_ptr->transformations & PNG_PACK) && info_ptr->bit_depth < 8)
+ info_ptr->bit_depth = 8;
+#endif
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB)
+ info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
+#endif
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+ if (png_ptr->transformations & PNG_RGB_TO_GRAY)
+ info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
+#endif
+
+ 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 defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
+ if (png_ptr->transformations & PNG_STRIP_ALPHA)
+ info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
+#endif
+
+ if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
+ info_ptr->channels++;
+
+#if defined(PNG_READ_FILLER_SUPPORTED)
+ /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
+ if (png_ptr->transformations & PNG_FILLER &&
+ (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
+ info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
+ info_ptr->channels++;
+#endif
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ if(png_ptr->transformations & PNG_USER_TRANSFORM)
+ {
+ if(info_ptr->bit_depth < png_ptr->user_transform_depth)
+ info_ptr->bit_depth = png_ptr->user_transform_depth;
+ if(info_ptr->channels < png_ptr->user_transform_channels)
+ info_ptr->channels = png_ptr->user_transform_channels;
+ }
+#endif
+
+ info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
+ info_ptr->bit_depth);
+ info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
+
+}
+
+/* Transform the row. The order of transformations is significant,
+ * and is very touchy. If you add a transformation, take care to
+ * decide how it fits in with the other transformations here.
+ */
+void
+png_do_read_transformations(png_structp png_ptr)
+{
+ png_debug(1, "in png_do_read_transformations\n");
+#if !defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (png_ptr->row_buf == NULL)
+ {
+#if !defined(PNG_NO_STDIO)
+ char msg[50];
+
+ sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
+ png_ptr->pass);
+ png_error(png_ptr, msg);
+#else
+ png_error(png_ptr, "NULL row buffer");
+#endif
+ }
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ if (png_ptr->transformations & PNG_EXPAND)
+ {
+ if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
+ }
+ else
+ {
+ if (png_ptr->num_trans)
+ png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ &(png_ptr->trans_values));
+ else
+ png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ NULL);
+ }
+ }
+#endif
+
+#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
+ if (png_ptr->transformations & PNG_STRIP_ALPHA)
+ png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ PNG_FLAG_FILLER_AFTER);
+#endif
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+ if (png_ptr->transformations & PNG_RGB_TO_GRAY)
+ {
+ int rgb_error =
+ png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
+ if(rgb_error)
+ {
+ png_ptr->rgb_to_gray_status=1;
+ if(png_ptr->transformations == PNG_RGB_TO_GRAY_WARN)
+ png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
+ if(png_ptr->transformations == PNG_RGB_TO_GRAY_ERR)
+ png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
+ }
+ }
+#endif
+
+/*
+From Andreas Dilger e-mail to png-implement, 26 March 1998:
+
+ In most cases, the "simple transparency" should be done prior to doing
+ gray-to-RGB, or you will have to test 3x as many bytes to check if a
+ pixel is transparent. You would also need to make sure that the
+ transparency information is upgraded to RGB.
+
+ To summarize, the current flow is:
+ - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
+ with background "in place" if transparent,
+ convert to RGB if necessary
+ - Gray + alpha -> composite with gray background and remove alpha bytes,
+ convert to RGB if necessary
+
+ To support RGB backgrounds for gray images we need:
+ - Gray + simple transparency -> convert to RGB + simple transparency, compare
+ 3 or 6 bytes and composite with background
+ "in place" if transparent (3x compare/pixel
+ compared to doing composite with gray bkgrnd)
+ - Gray + alpha -> convert to RGB + alpha, composite with background and
+ remove alpha bytes (3x float operations/pixel
+ compared with composite on gray background)
+
+ Greg's change will do this. The reason it wasn't done before is for
+ performance, as this increases the per-pixel operations. If we would check
+ in advance if the background was gray or RGB, and position the gray-to-RGB
+ transform appropriately, then it would save a lot of work/time.
+ */
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ /* if gray -> RGB, do so now only if background is non-gray; else do later
+ * for performance reasons */
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
+ !(png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY))
+ png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if ((png_ptr->transformations & PNG_BACKGROUND) &&
+ ((png_ptr->num_trans != 0 ) ||
+ (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
+ png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ &(png_ptr->trans_values), &(png_ptr->background),
+ &(png_ptr->background_1),
+ png_ptr->gamma_table, png_ptr->gamma_from_1,
+ png_ptr->gamma_to_1, png_ptr->gamma_16_table,
+ png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
+ png_ptr->gamma_shift);
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if ((png_ptr->transformations & PNG_GAMMA) &&
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ !((png_ptr->transformations & PNG_BACKGROUND) &&
+ ((png_ptr->num_trans != 0) ||
+ (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
+#endif
+ (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
+ png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ png_ptr->gamma_table, png_ptr->gamma_16_table,
+ png_ptr->gamma_shift);
+#endif
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+ if (png_ptr->transformations & PNG_16_TO_8)
+ png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+ if (png_ptr->transformations & PNG_DITHER)
+ {
+ png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
+ png_ptr->palette_lookup, png_ptr->dither_index);
+ if(png_ptr->row_info.rowbytes == (png_uint_32)0)
+ png_error(png_ptr, "png_do_dither returned rowbytes=0");
+ }
+#endif
+
+#if defined(PNG_READ_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_READ_SHIFT_SUPPORTED)
+ if (png_ptr->transformations & PNG_SHIFT)
+ png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ &(png_ptr->shift));
+#endif
+
+#if defined(PNG_READ_PACK_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACK)
+ png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_BGR_SUPPORTED)
+ if (png_ptr->transformations & PNG_BGR)
+ png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ /* if gray -> RGB, do so now only if we did not do so above */
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
+ png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY)
+ png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_FILLER_SUPPORTED)
+ if (png_ptr->transformations & PNG_FILLER)
+ png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
+ (png_uint_32)png_ptr->filler, png_ptr->flags);
+#endif
+
+#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
+ if (png_ptr->transformations & PNG_INVERT_ALPHA)
+ png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
+ if (png_ptr->transformations & PNG_SWAP_ALPHA)
+ png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
+#endif
+
+#if defined(PNG_READ_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_READ_USER_TRANSFORM_SUPPORTED)
+ if (png_ptr->transformations & PNG_USER_TRANSFORM)
+ {
+ if(png_ptr->read_user_transform_fn != NULL)
+ (*(png_ptr->read_user_transform_fn)) /* user read 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 */
+ if(png_ptr->user_transform_depth)
+ png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
+ if(png_ptr->user_transform_channels)
+ png_ptr->row_info.channels = png_ptr->user_transform_channels;
+ png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
+ png_ptr->row_info.channels);
+ png_ptr->row_info.rowbytes = (png_ptr->row_info.width *
+ png_ptr->row_info.pixel_depth+7)>>3;
+ }
+#endif
+
+}
+
+#if defined(PNG_READ_PACK_SUPPORTED)
+/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
+ * without changing the actual values. Thus, if you had a row with
+ * a bit depth of 1, you would end up with bytes that only contained
+ * the numbers 0 or 1. If you would rather they contain 0 and 255, use
+ * png_do_shift() after this.
+ */
+void
+png_do_unpack(png_row_infop row_info, png_bytep row)
+{
+ png_debug(1, "in png_do_unpack\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
+#else
+ if (row_info->bit_depth < 8)
+#endif
+ {
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+
+ switch (row_info->bit_depth)
+ {
+ case 1:
+ {
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
+ for (i = 0; i < row_width; i++)
+ {
+ *dp = (png_byte)((*sp >> shift) & 0x1);
+ if (shift == 7)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift++;
+
+ dp--;
+ }
+ break;
+ }
+ case 2:
+ {
+
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+ for (i = 0; i < row_width; i++)
+ {
+ *dp = (png_byte)((*sp >> shift) & 0x3);
+ if (shift == 6)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift += 2;
+
+ dp--;
+ }
+ break;
+ }
+ case 4:
+ {
+ png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
+ png_bytep dp = row + (png_size_t)row_width - 1;
+ png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
+ for (i = 0; i < row_width; i++)
+ {
+ *dp = (png_byte)((*sp >> shift) & 0xf);
+ if (shift == 4)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift = 4;
+
+ dp--;
+ }
+ break;
+ }
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = (png_byte)(8 * row_info->channels);
+ row_info->rowbytes = row_width * row_info->channels;
+ }
+}
+#endif
+
+#if defined(PNG_READ_SHIFT_SUPPORTED)
+/* Reverse the effects of png_do_shift. This routine merely shifts the
+ * pixels back to their significant bits values. Thus, if you have
+ * a row of bit depth 8, but only 5 are significant, this will shift
+ * the values back to 0 through 31.
+ */
+void
+png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
+{
+ png_debug(1, "in png_do_unshift\n");
+ if (
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL && sig_bits != NULL &&
+#endif
+ row_info->color_type != PNG_COLOR_TYPE_PALETTE)
+ {
+ int shift[4];
+ int channels = 0;
+ int c;
+ png_uint_16 value = 0;
+ png_uint_32 row_width = row_info->width;
+
+ if (row_info->color_type & PNG_COLOR_MASK_COLOR)
+ {
+ shift[channels++] = row_info->bit_depth - sig_bits->red;
+ shift[channels++] = row_info->bit_depth - sig_bits->green;
+ shift[channels++] = row_info->bit_depth - sig_bits->blue;
+ }
+ else
+ {
+ shift[channels++] = row_info->bit_depth - sig_bits->gray;
+ }
+ if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ shift[channels++] = row_info->bit_depth - sig_bits->alpha;
+ }
+
+ for (c = 0; c < channels; c++)
+ {
+ if (shift[c] <= 0)
+ shift[c] = 0;
+ else
+ value = 1;
+ }
+
+ if (!value)
+ return;
+
+ switch (row_info->bit_depth)
+ {
+ case 2:
+ {
+ png_bytep bp;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+
+ for (bp = row, i = 0; i < istop; i++)
+ {
+ *bp >>= 1;
+ *bp++ &= 0x55;
+ }
+ break;
+ }
+ case 4:
+ {
+ png_bytep bp = row;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
+ (png_byte)((int)0xf >> shift[0]));
+
+ for (i = 0; i < istop; i++)
+ {
+ *bp >>= shift[0];
+ *bp++ &= mask;
+ }
+ break;
+ }
+ case 8:
+ {
+ png_bytep bp = row;
+ png_uint_32 i;
+ png_uint_32 istop = row_width * channels;
+
+ for (i = 0; i < istop; i++)
+ {
+ *bp++ >>= shift[i%channels];
+ }
+ break;
+ }
+ case 16:
+ {
+ png_bytep bp = row;
+ png_uint_32 i;
+ png_uint_32 istop = channels * row_width;
+
+ for (i = 0; i < istop; i++)
+ {
+ value = (png_uint_16)((*bp << 8) + *(bp + 1));
+ value >>= shift[i%channels];
+ *bp++ = (png_byte)(value >> 8);
+ *bp++ = (png_byte)(value & 0xff);
+ }
+ break;
+ }
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_16_TO_8_SUPPORTED)
+/* chop rows of bit depth 16 down to 8 */
+void
+png_do_chop(png_row_infop row_info, png_bytep row)
+{
+ png_debug(1, "in png_do_chop\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
+#else
+ if (row_info->bit_depth == 16)
+#endif
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ png_uint_32 i;
+ png_uint_32 istop = row_info->width * row_info->channels;
+
+ for (i = 0; i<istop; i++, sp += 2, dp++)
+ {
+#if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
+ /* This does a more accurate scaling of the 16-bit color
+ * value, rather than a simple low-byte truncation.
+ *
+ * What the ideal calculation should be:
+ * *dp = (((((png_uint_32)(*sp) << 8) |
+ * (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
+ *
+ * GRR: no, I think this is what it really should be:
+ * *dp = (((((png_uint_32)(*sp) << 8) |
+ * (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
+ *
+ * GRR: here's the exact calculation with shifts:
+ * temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
+ * *dp = (temp - (temp >> 8)) >> 8;
+ *
+ * Approximate calculation with shift/add instead of multiply/divide:
+ * *dp = ((((png_uint_32)(*sp) << 8) |
+ * (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8;
+ *
+ * What we actually do to avoid extra shifting and conversion:
+ */
+
+ *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
+#else
+ /* Simply discard the low order byte */
+ *dp = *sp;
+#endif
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = (png_byte)(8 * row_info->channels);
+ row_info->rowbytes = row_info->width * row_info->channels;
+ }
+}
+#endif
+
+#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
+void
+png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
+{
+ png_debug(1, "in png_do_read_swap_alpha\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL)
+#endif
+ {
+ png_uint_32 row_width = row_info->width;
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ {
+ /* This converts from RGBA to ARGB */
+ if (row_info->bit_depth == 8)
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_byte save;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ save = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = save;
+ }
+ }
+ /* This converts from RRGGBBAA to AARRGGBB */
+ else
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_byte save[2];
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ 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 GA to AG */
+ if (row_info->bit_depth == 8)
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_byte save;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ save = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = save;
+ }
+ }
+ /* This converts from GGAA to AAGG */
+ else
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_byte save[2];
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ save[0] = *(--sp);
+ save[1] = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = save[0];
+ *(--dp) = save[1];
+ }
+ }
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
+void
+png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
+{
+ png_debug(1, "in png_do_read_invert_alpha\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL)
+#endif
+ {
+ png_uint_32 row_width = row_info->width;
+ 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 = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ }
+ }
+ /* This inverts the alpha channel in RRGGBBAA */
+ else
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--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 = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = *(--sp);
+ }
+ }
+ /* This inverts the alpha channel in GGAA */
+ else
+ {
+ png_bytep sp = row + row_info->rowbytes;
+ png_bytep dp = sp;
+ png_uint_32 i;
+
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = (png_byte)(255 - *(--sp));
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ }
+ }
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_FILLER_SUPPORTED)
+/* Add filler channel if we have RGB color */
+void
+png_do_read_filler(png_row_infop row_info, png_bytep row,
+ png_uint_32 filler, png_uint_32 flags)
+{
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+
+ png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
+ png_byte lo_filler = (png_byte)(filler & 0xff);
+
+ png_debug(1, "in png_do_read_filler\n");
+ if (
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ row_info->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ if(row_info->bit_depth == 8)
+ {
+ /* This changes the data from G to GX */
+ if (flags & PNG_FLAG_FILLER_AFTER)
+ {
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 1; i < row_width; i++)
+ {
+ *(--dp) = lo_filler;
+ *(--dp) = *(--sp);
+ }
+ *(--dp) = lo_filler;
+ row_info->channels = 2;
+ row_info->pixel_depth = 16;
+ row_info->rowbytes = row_width * 2;
+ }
+ /* This changes the data from G to XG */
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = *(--sp);
+ *(--dp) = lo_filler;
+ }
+ row_info->channels = 2;
+ row_info->pixel_depth = 16;
+ row_info->rowbytes = row_width * 2;
+ }
+ }
+ else if(row_info->bit_depth == 16)
+ {
+ /* This changes the data from GG to GGXX */
+ if (flags & PNG_FLAG_FILLER_AFTER)
+ {
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 1; i < row_width; i++)
+ {
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ }
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ row_info->channels = 2;
+ row_info->pixel_depth = 32;
+ row_info->rowbytes = row_width * 4;
+ }
+ /* This changes the data from GG to XXGG */
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ }
+ row_info->channels = 2;
+ row_info->pixel_depth = 32;
+ row_info->rowbytes = row_width * 4;
+ }
+ }
+ } /* COLOR_TYPE == GRAY */
+ else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ if(row_info->bit_depth == 8)
+ {
+ /* This changes the data from RGB to RGBX */
+ if (flags & PNG_FLAG_FILLER_AFTER)
+ {
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 1; i < row_width; i++)
+ {
+ *(--dp) = lo_filler;
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ }
+ *(--dp) = lo_filler;
+ row_info->channels = 4;
+ row_info->pixel_depth = 32;
+ row_info->rowbytes = row_width * 4;
+ }
+ /* This changes the data from RGB to XRGB */
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = lo_filler;
+ }
+ row_info->channels = 4;
+ row_info->pixel_depth = 32;
+ row_info->rowbytes = row_width * 4;
+ }
+ }
+ else if(row_info->bit_depth == 16)
+ {
+ /* This changes the data from RRGGBB to RRGGBBXX */
+ if (flags & PNG_FLAG_FILLER_AFTER)
+ {
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 1; i < row_width; i++)
+ {
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ }
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ row_info->channels = 4;
+ row_info->pixel_depth = 64;
+ row_info->rowbytes = row_width * 8;
+ }
+ /* This changes the data from RRGGBB to XXRRGGBB */
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width * 3;
+ png_bytep dp = sp + (png_size_t)row_width;
+ for (i = 0; i < row_width; i++)
+ {
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = *(--sp);
+ *(--dp) = hi_filler;
+ *(--dp) = lo_filler;
+ }
+ row_info->channels = 4;
+ row_info->pixel_depth = 64;
+ row_info->rowbytes = row_width * 8;
+ }
+ }
+ } /* COLOR_TYPE == RGB */
+}
+#endif
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+/* expand grayscale files to RGB, with or without alpha */
+void
+png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
+{
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+
+ png_debug(1, "in png_do_gray_to_rgb\n");
+ if (row_info->bit_depth >= 8 &&
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ !(row_info->color_type & PNG_COLOR_MASK_COLOR))
+ {
+ if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ if (row_info->bit_depth == 8)
+ {
+ png_bytep sp = row + (png_size_t)row_width - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 2;
+ for (i = 0; i < row_width; i++)
+ {
+ *(dp--) = *sp;
+ *(dp--) = *sp;
+ *(dp--) = *(sp--);
+ }
+ }
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width * 2 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 4;
+ for (i = 0; i < row_width; i++)
+ {
+ *(dp--) = *sp;
+ *(dp--) = *(sp - 1);
+ *(dp--) = *sp;
+ *(dp--) = *(sp - 1);
+ *(dp--) = *(sp--);
+ *(dp--) = *(sp--);
+ }
+ }
+ }
+ else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ {
+ if (row_info->bit_depth == 8)
+ {
+ png_bytep sp = row + (png_size_t)row_width * 2 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 2;
+ for (i = 0; i < row_width; i++)
+ {
+ *(dp--) = *(sp--);
+ *(dp--) = *sp;
+ *(dp--) = *sp;
+ *(dp--) = *(sp--);
+ }
+ }
+ else
+ {
+ png_bytep sp = row + (png_size_t)row_width * 4 - 1;
+ png_bytep dp = sp + (png_size_t)row_width * 4;
+ for (i = 0; i < row_width; i++)
+ {
+ *(dp--) = *(sp--);
+ *(dp--) = *(sp--);
+ *(dp--) = *sp;
+ *(dp--) = *(sp - 1);
+ *(dp--) = *sp;
+ *(dp--) = *(sp - 1);
+ *(dp--) = *(sp--);
+ *(dp--) = *(sp--);
+ }
+ }
+ }
+ row_info->channels += (png_byte)2;
+ row_info->color_type |= PNG_COLOR_MASK_COLOR;
+ row_info->pixel_depth = (png_byte)(row_info->channels *
+ row_info->bit_depth);
+ row_info->rowbytes = ((row_width *
+ row_info->pixel_depth + 7) >> 3);
+ }
+}
+#endif
+
+#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+/* reduce RGB files to grayscale, with or without alpha
+ * using the equation given in Poynton's ColorFAQ at
+ * <http://www.inforamp.net/~poynton/>
+ * Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
+ *
+ * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
+ *
+ * We approximate this with
+ *
+ * Y = 0.211 * R + 0.715 * G + 0.074 * B
+ *
+ * which can be expressed with integers as
+ *
+ * Y = (54 * R + 183 * G + 19 * B)/256
+ *
+ * The calculation is to be done in a linear colorspace.
+ *
+ * Other integer coefficents can be used via png_set_rgb_to_gray().
+ */
+int
+png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
+
+{
+ png_uint_32 i;
+
+ png_uint_32 row_width = row_info->width;
+ int rgb_error = 0;
+
+ png_debug(1, "in png_do_rgb_to_gray\n");
+ if (
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ (row_info->color_type & PNG_COLOR_MASK_COLOR))
+ {
+ png_byte rc = png_ptr->rgb_to_gray_red_coeff;
+ png_byte gc = png_ptr->rgb_to_gray_green_coeff;
+ png_byte bc = png_ptr->rgb_to_gray_blue_coeff;
+
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ if (row_info->bit_depth == 8)
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+
+ for (i = 0; i < row_width; i++)
+ {
+ png_byte red = png_ptr->gamma_to_1[*(sp++)];
+ png_byte green = png_ptr->gamma_to_1[*(sp++)];
+ png_byte blue = png_ptr->gamma_to_1[*(sp++)];
+ if(red != green || red != blue)
+ {
+ rgb_error |= 1;
+ *(dp++) = png_ptr->gamma_from_1[
+ (rc*red+gc*green+bc*blue)>>8];
+ }
+ else
+ *(dp++) = *(sp-1);
+ }
+ }
+ else
+#endif
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_byte red = *(sp++);
+ png_byte green = *(sp++);
+ png_byte blue = *(sp++);
+ if(red != green || red != blue)
+ {
+ rgb_error |= 1;
+ *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>8);
+ }
+ else
+ *(dp++) = *(sp-1);
+ }
+ }
+ }
+
+ else /* RGB bit_depth == 16 */
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->gamma_16_to_1 != NULL &&
+ png_ptr->gamma_16_from_1 != NULL)
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 red, green, blue, w;
+
+ red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+
+ if(red == green && red == blue)
+ w = red;
+ else
+ {
+ png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
+ png_ptr->gamma_shift][red>>8];
+ png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
+ png_ptr->gamma_shift][green>>8];
+ png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
+ png_ptr->gamma_shift][blue>>8];
+ png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
+ + bc*blue_1)>>8);
+ w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
+ png_ptr->gamma_shift][gray16 >> 8];
+ rgb_error |= 1;
+ }
+
+ *(dp++) = (png_byte)((w>>8) & 0xff);
+ *(dp++) = (png_byte)(w & 0xff);
+ }
+ }
+ else
+#endif
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 red, green, blue, gray16;
+
+ red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+
+ if(red != green || red != blue)
+ rgb_error |= 1;
+ gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8);
+ *(dp++) = (png_byte)((gray16>>8) & 0xff);
+ *(dp++) = (png_byte)(gray16 & 0xff);
+ }
+ }
+ }
+ }
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ {
+ if (row_info->bit_depth == 8)
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_byte red = png_ptr->gamma_to_1[*(sp++)];
+ png_byte green = png_ptr->gamma_to_1[*(sp++)];
+ png_byte blue = png_ptr->gamma_to_1[*(sp++)];
+ if(red != green || red != blue)
+ rgb_error |= 1;
+ *(dp++) = png_ptr->gamma_from_1
+ [(rc*red + gc*green + bc*blue)>>8];
+ *(dp++) = *(sp++); /* alpha */
+ }
+ }
+ else
+#endif
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_byte red = *(sp++);
+ png_byte green = *(sp++);
+ png_byte blue = *(sp++);
+ if(red != green || red != blue)
+ rgb_error |= 1;
+ *(dp++) = (png_byte)((gc*red + gc*green + bc*blue)>>8);
+ *(dp++) = *(sp++); /* alpha */
+ }
+ }
+ }
+ else /* RGBA bit_depth == 16 */
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->gamma_16_to_1 != NULL &&
+ png_ptr->gamma_16_from_1 != NULL)
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 red, green, blue, w;
+
+ red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+ blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
+
+ if(red == green && red == blue)
+ w = red;
+ else
+ {
+ png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
+ png_ptr->gamma_shift][red>>8];
+ png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
+ png_ptr->gamma_shift][green>>8];
+ png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
+ png_ptr->gamma_shift][blue>>8];
+ png_uint_16 gray16 = (png_uint_16)((rc * red_1
+ + gc * green_1 + bc * blue_1)>>8);
+ w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
+ png_ptr->gamma_shift][gray16 >> 8];
+ rgb_error |= 1;
+ }
+
+ *(dp++) = (png_byte)((w>>8) & 0xff);
+ *(dp++) = (png_byte)(w & 0xff);
+ *(dp++) = *(sp++); /* alpha */
+ *(dp++) = *(sp++);
+ }
+ }
+ else
+#endif
+ {
+ png_bytep sp = row;
+ png_bytep dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 red, green, blue, gray16;
+ red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
+ green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
+ blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
+ if(red != green || red != blue)
+ rgb_error |= 1;
+ gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8);
+ *(dp++) = (png_byte)((gray16>>8) & 0xff);
+ *(dp++) = (png_byte)(gray16 & 0xff);
+ *(dp++) = *(sp++); /* alpha */
+ *(dp++) = *(sp++);
+ }
+ }
+ }
+ }
+ row_info->channels -= (png_byte)2;
+ row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
+ row_info->pixel_depth = (png_byte)(row_info->channels *
+ row_info->bit_depth);
+ row_info->rowbytes = ((row_width *
+ row_info->pixel_depth + 7) >> 3);
+ }
+ return rgb_error;
+}
+#endif
+
+/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
+ * large of png_color. This lets grayscale images be treated as
+ * paletted. Most useful for gamma correction and simplification
+ * of code.
+ */
+void
+png_build_grayscale_palette(int bit_depth, png_colorp palette)
+{
+ int num_palette;
+ int color_inc;
+ int i;
+ int v;
+
+ png_debug(1, "in png_do_build_grayscale_palette\n");
+ if (palette == NULL)
+ return;
+
+ switch (bit_depth)
+ {
+ case 1:
+ num_palette = 2;
+ color_inc = 0xff;
+ break;
+ case 2:
+ num_palette = 4;
+ color_inc = 0x55;
+ break;
+ case 4:
+ num_palette = 16;
+ color_inc = 0x11;
+ break;
+ case 8:
+ num_palette = 256;
+ color_inc = 1;
+ break;
+ default:
+ num_palette = 0;
+ color_inc = 0;
+ break;
+ }
+
+ for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
+ {
+ palette[i].red = (png_byte)v;
+ palette[i].green = (png_byte)v;
+ palette[i].blue = (png_byte)v;
+ }
+}
+
+/* This function is currently unused. Do we really need it? */
+#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
+void
+png_correct_palette(png_structp png_ptr, png_colorp palette,
+ int num_palette)
+{
+ png_debug(1, "in png_correct_palette\n");
+#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
+ if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
+ {
+ png_color back, back_1;
+
+ if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
+ {
+ back.red = png_ptr->gamma_table[png_ptr->background.red];
+ back.green = png_ptr->gamma_table[png_ptr->background.green];
+ back.blue = png_ptr->gamma_table[png_ptr->background.blue];
+
+ back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
+ back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
+ back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
+ }
+ else
+ {
+ double g;
+
+ g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
+
+ if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
+ fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
+ {
+ back.red = png_ptr->background.red;
+ back.green = png_ptr->background.green;
+ back.blue = png_ptr->background.blue;
+ }
+ else
+ {
+ back.red =
+ (png_byte)(pow((double)png_ptr->background.red/255, g) *
+ 255.0 + 0.5);
+ back.green =
+ (png_byte)(pow((double)png_ptr->background.green/255, g) *
+ 255.0 + 0.5);
+ back.blue =
+ (png_byte)(pow((double)png_ptr->background.blue/255, g) *
+ 255.0 + 0.5);
+ }
+
+ g = 1.0 / png_ptr->background_gamma;
+
+ back_1.red =
+ (png_byte)(pow((double)png_ptr->background.red/255, g) *
+ 255.0 + 0.5);
+ back_1.green =
+ (png_byte)(pow((double)png_ptr->background.green/255, g) *
+ 255.0 + 0.5);
+ back_1.blue =
+ (png_byte)(pow((double)png_ptr->background.blue/255, g) *
+ 255.0 + 0.5);
+ }
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_uint_32 i;
+
+ for (i = 0; i < (png_uint_32)num_palette; i++)
+ {
+ if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
+ {
+ palette[i] = back;
+ }
+ else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
+ {
+ png_byte v, w;
+
+ v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
+ png_composite(w, v, png_ptr->trans[i], back_1.red);
+ palette[i].red = png_ptr->gamma_from_1[w];
+
+ v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
+ png_composite(w, v, png_ptr->trans[i], back_1.green);
+ palette[i].green = png_ptr->gamma_from_1[w];
+
+ v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
+ png_composite(w, v, png_ptr->trans[i], back_1.blue);
+ palette[i].blue = png_ptr->gamma_from_1[w];
+ }
+ else
+ {
+ palette[i].red = png_ptr->gamma_table[palette[i].red];
+ palette[i].green = png_ptr->gamma_table[palette[i].green];
+ palette[i].blue = png_ptr->gamma_table[palette[i].blue];
+ }
+ }
+ }
+ else
+ {
+ int i;
+
+ for (i = 0; i < num_palette; i++)
+ {
+ if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
+ {
+ palette[i] = back;
+ }
+ else
+ {
+ palette[i].red = png_ptr->gamma_table[palette[i].red];
+ palette[i].green = png_ptr->gamma_table[palette[i].green];
+ palette[i].blue = png_ptr->gamma_table[palette[i].blue];
+ }
+ }
+ }
+ }
+ else
+#endif
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (png_ptr->transformations & PNG_GAMMA)
+ {
+ int i;
+
+ for (i = 0; i < num_palette; i++)
+ {
+ palette[i].red = png_ptr->gamma_table[palette[i].red];
+ palette[i].green = png_ptr->gamma_table[palette[i].green];
+ palette[i].blue = png_ptr->gamma_table[palette[i].blue];
+ }
+ }
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ else
+#endif
+#endif
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+ if (png_ptr->transformations & PNG_BACKGROUND)
+ {
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_color back;
+
+ back.red = (png_byte)png_ptr->background.red;
+ back.green = (png_byte)png_ptr->background.green;
+ back.blue = (png_byte)png_ptr->background.blue;
+
+ for (i = 0; i < (int)png_ptr->num_trans; i++)
+ {
+ if (png_ptr->trans[i] == 0)
+ {
+ palette[i].red = back.red;
+ palette[i].green = back.green;
+ palette[i].blue = back.blue;
+ }
+ else if (png_ptr->trans[i] != 0xff)
+ {
+ png_composite(palette[i].red, png_ptr->palette[i].red,
+ png_ptr->trans[i], back.red);
+ png_composite(palette[i].green, png_ptr->palette[i].green,
+ png_ptr->trans[i], back.green);
+ png_composite(palette[i].blue, png_ptr->palette[i].blue,
+ png_ptr->trans[i], back.blue);
+ }
+ }
+ }
+ else /* assume grayscale palette (what else could it be?) */
+ {
+ int i;
+
+ for (i = 0; i < num_palette; i++)
+ {
+ if (i == (png_byte)png_ptr->trans_values.gray)
+ {
+ palette[i].red = (png_byte)png_ptr->background.red;
+ palette[i].green = (png_byte)png_ptr->background.green;
+ palette[i].blue = (png_byte)png_ptr->background.blue;
+ }
+ }
+ }
+ }
+#endif
+}
+#endif
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED)
+/* Replace any alpha or transparency with the supplied background color.
+ * "background" is already in the screen gamma, while "background_1" is
+ * at a gamma of 1.0. Paletted files have already been taken care of.
+ */
+void
+png_do_background(png_row_infop row_info, png_bytep row,
+ png_color_16p trans_values, png_color_16p background,
+ png_color_16p background_1,
+ png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
+ png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
+ png_uint_16pp gamma_16_to_1, int gamma_shift)
+{
+ png_bytep sp, dp;
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+ int shift;
+
+ png_debug(1, "in png_do_background\n");
+ if (background != NULL &&
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
+ (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
+ {
+ switch (row_info->color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ {
+ switch (row_info->bit_depth)
+ {
+ case 1:
+ {
+ sp = row;
+ shift = 7;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((png_uint_16)((*sp >> shift) & 0x1)
+ == trans_values->gray)
+ {
+ *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
+ *sp |= (png_byte)(background->gray << shift);
+ }
+ if (!shift)
+ {
+ shift = 7;
+ sp++;
+ }
+ else
+ shift--;
+ }
+ break;
+ }
+ case 2:
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_table != NULL)
+ {
+ sp = row;
+ shift = 6;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((png_uint_16)((*sp >> shift) & 0x3)
+ == trans_values->gray)
+ {
+ *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
+ *sp |= (png_byte)(background->gray << shift);
+ }
+ else
+ {
+ png_byte p = (png_byte)((*sp >> shift) & 0x3);
+ png_byte g = (png_byte)((gamma_table [p | (p << 2) |
+ (p << 4) | (p << 6)] >> 6) & 0x3);
+ *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
+ *sp |= (png_byte)(g << shift);
+ }
+ if (!shift)
+ {
+ shift = 6;
+ sp++;
+ }
+ else
+ shift -= 2;
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ shift = 6;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((png_uint_16)((*sp >> shift) & 0x3)
+ == trans_values->gray)
+ {
+ *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
+ *sp |= (png_byte)(background->gray << shift);
+ }
+ if (!shift)
+ {
+ shift = 6;
+ sp++;
+ }
+ else
+ shift -= 2;
+ }
+ }
+ break;
+ }
+ case 4:
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_table != NULL)
+ {
+ sp = row;
+ shift = 4;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((png_uint_16)((*sp >> shift) & 0xf)
+ == trans_values->gray)
+ {
+ *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
+ *sp |= (png_byte)(background->gray << shift);
+ }
+ else
+ {
+ png_byte p = (png_byte)((*sp >> shift) & 0xf);
+ png_byte g = (png_byte)((gamma_table[p |
+ (p << 4)] >> 4) & 0xf);
+ *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
+ *sp |= (png_byte)(g << shift);
+ }
+ if (!shift)
+ {
+ shift = 4;
+ sp++;
+ }
+ else
+ shift -= 4;
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ shift = 4;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((png_uint_16)((*sp >> shift) & 0xf)
+ == trans_values->gray)
+ {
+ *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
+ *sp |= (png_byte)(background->gray << shift);
+ }
+ if (!shift)
+ {
+ shift = 4;
+ sp++;
+ }
+ else
+ shift -= 4;
+ }
+ }
+ break;
+ }
+ case 8:
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_table != NULL)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp++)
+ {
+ if (*sp == trans_values->gray)
+ {
+ *sp = (png_byte)background->gray;
+ }
+ else
+ {
+ *sp = gamma_table[*sp];
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp++)
+ {
+ if (*sp == trans_values->gray)
+ {
+ *sp = (png_byte)background->gray;
+ }
+ }
+ }
+ break;
+ }
+ case 16:
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_16 != NULL)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 2)
+ {
+ png_uint_16 v;
+
+ v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ if (v == trans_values->gray)
+ {
+ /* background is already in screen gamma */
+ *sp = (png_byte)((background->gray >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(background->gray & 0xff);
+ }
+ else
+ {
+ v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 2)
+ {
+ png_uint_16 v;
+
+ v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ if (v == trans_values->gray)
+ {
+ *sp = (png_byte)((background->gray >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(background->gray & 0xff);
+ }
+ }
+ }
+ break;
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_RGB:
+ {
+ if (row_info->bit_depth == 8)
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_table != NULL)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 3)
+ {
+ if (*sp == trans_values->red &&
+ *(sp + 1) == trans_values->green &&
+ *(sp + 2) == trans_values->blue)
+ {
+ *sp = (png_byte)background->red;
+ *(sp + 1) = (png_byte)background->green;
+ *(sp + 2) = (png_byte)background->blue;
+ }
+ else
+ {
+ *sp = gamma_table[*sp];
+ *(sp + 1) = gamma_table[*(sp + 1)];
+ *(sp + 2) = gamma_table[*(sp + 2)];
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 3)
+ {
+ if (*sp == trans_values->red &&
+ *(sp + 1) == trans_values->green &&
+ *(sp + 2) == trans_values->blue)
+ {
+ *sp = (png_byte)background->red;
+ *(sp + 1) = (png_byte)background->green;
+ *(sp + 2) = (png_byte)background->blue;
+ }
+ }
+ }
+ }
+ else /* if (row_info->bit_depth == 16) */
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_16 != NULL)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 6)
+ {
+ png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
+ png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
+ if (r == trans_values->red && g == trans_values->green &&
+ b == trans_values->blue)
+ {
+ /* background is already in screen gamma */
+ *sp = (png_byte)((background->red >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(background->red & 0xff);
+ *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
+ *(sp + 3) = (png_byte)(background->green & 0xff);
+ *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
+ *(sp + 5) = (png_byte)(background->blue & 0xff);
+ }
+ else
+ {
+ png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
+ *(sp + 2) = (png_byte)((v >> 8) & 0xff);
+ *(sp + 3) = (png_byte)(v & 0xff);
+ v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
+ *(sp + 4) = (png_byte)((v >> 8) & 0xff);
+ *(sp + 5) = (png_byte)(v & 0xff);
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp += 6)
+ {
+ png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
+ png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
+ png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
+
+ if (r == trans_values->red && g == trans_values->green &&
+ b == trans_values->blue)
+ {
+ *sp = (png_byte)((background->red >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(background->red & 0xff);
+ *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
+ *(sp + 3) = (png_byte)(background->green & 0xff);
+ *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
+ *(sp + 5) = (png_byte)(background->blue & 0xff);
+ }
+ }
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ {
+ if (row_info->bit_depth == 8)
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
+ gamma_table != NULL)
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 2, dp++)
+ {
+ png_uint_16 a = *(sp + 1);
+
+ if (a == 0xff)
+ {
+ *dp = gamma_table[*sp];
+ }
+ else if (a == 0)
+ {
+ /* background is already in screen gamma */
+ *dp = (png_byte)background->gray;
+ }
+ else
+ {
+ png_byte v, w;
+
+ v = gamma_to_1[*sp];
+ png_composite(w, v, a, background_1->gray);
+ *dp = gamma_from_1[w];
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 2, dp++)
+ {
+ png_byte a = *(sp + 1);
+
+ if (a == 0xff)
+ {
+ *dp = *sp;
+ }
+ else if (a == 0)
+ {
+ *dp = (png_byte)background->gray;
+ }
+ else
+ {
+ png_composite(*dp, *sp, a, background_1->gray);
+ }
+ }
+ }
+ }
+ else /* if (png_ptr->bit_depth == 16) */
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
+ gamma_16_to_1 != NULL)
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 4, dp += 2)
+ {
+ png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
+
+ if (a == (png_uint_16)0xffff)
+ {
+ png_uint_16 v;
+
+ v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
+ *dp = (png_byte)((v >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(v & 0xff);
+ }
+ else if (a == 0)
+ {
+ /* background is already in screen gamma */
+ *dp = (png_byte)((background->gray >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(background->gray & 0xff);
+ }
+ else
+ {
+ png_uint_16 g, v, w;
+
+ g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
+ png_composite_16(v, g, a, background_1->gray);
+ w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
+ *dp = (png_byte)((w >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(w & 0xff);
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 4, dp += 2)
+ {
+ png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
+ if (a == (png_uint_16)0xffff)
+ {
+ png_memcpy(dp, sp, 2);
+ }
+ else if (a == 0)
+ {
+ *dp = (png_byte)((background->gray >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(background->gray & 0xff);
+ }
+ else
+ {
+ png_uint_16 g, v;
+
+ g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ png_composite_16(v, g, a, background_1->gray);
+ *dp = (png_byte)((v >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(v & 0xff);
+ }
+ }
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ {
+ if (row_info->bit_depth == 8)
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
+ gamma_table != NULL)
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 4, dp += 3)
+ {
+ png_byte a = *(sp + 3);
+
+ if (a == 0xff)
+ {
+ *dp = gamma_table[*sp];
+ *(dp + 1) = gamma_table[*(sp + 1)];
+ *(dp + 2) = gamma_table[*(sp + 2)];
+ }
+ else if (a == 0)
+ {
+ /* background is already in screen gamma */
+ *dp = (png_byte)background->red;
+ *(dp + 1) = (png_byte)background->green;
+ *(dp + 2) = (png_byte)background->blue;
+ }
+ else
+ {
+ png_byte v, w;
+
+ v = gamma_to_1[*sp];
+ png_composite(w, v, a, background_1->red);
+ *dp = gamma_from_1[w];
+ v = gamma_to_1[*(sp + 1)];
+ png_composite(w, v, a, background_1->green);
+ *(dp + 1) = gamma_from_1[w];
+ v = gamma_to_1[*(sp + 2)];
+ png_composite(w, v, a, background_1->blue);
+ *(dp + 2) = gamma_from_1[w];
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 4, dp += 3)
+ {
+ png_byte a = *(sp + 3);
+
+ if (a == 0xff)
+ {
+ *dp = *sp;
+ *(dp + 1) = *(sp + 1);
+ *(dp + 2) = *(sp + 2);
+ }
+ else if (a == 0)
+ {
+ *dp = (png_byte)background->red;
+ *(dp + 1) = (png_byte)background->green;
+ *(dp + 2) = (png_byte)background->blue;
+ }
+ else
+ {
+ png_composite(*dp, *sp, a, background->red);
+ png_composite(*(dp + 1), *(sp + 1), a,
+ background->green);
+ png_composite(*(dp + 2), *(sp + 2), a,
+ background->blue);
+ }
+ }
+ }
+ }
+ else /* if (row_info->bit_depth == 16) */
+ {
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+ if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
+ gamma_16_to_1 != NULL)
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 8, dp += 6)
+ {
+ png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
+ << 8) + (png_uint_16)(*(sp + 7)));
+ if (a == (png_uint_16)0xffff)
+ {
+ png_uint_16 v;
+
+ v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
+ *dp = (png_byte)((v >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(v & 0xff);
+ v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
+ *(dp + 2) = (png_byte)((v >> 8) & 0xff);
+ *(dp + 3) = (png_byte)(v & 0xff);
+ v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
+ *(dp + 4) = (png_byte)((v >> 8) & 0xff);
+ *(dp + 5) = (png_byte)(v & 0xff);
+ }
+ else if (a == 0)
+ {
+ /* background is already in screen gamma */
+ *dp = (png_byte)((background->red >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(background->red & 0xff);
+ *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
+ *(dp + 3) = (png_byte)(background->green & 0xff);
+ *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
+ *(dp + 5) = (png_byte)(background->blue & 0xff);
+ }
+ else
+ {
+ png_uint_16 v, w, x;
+
+ v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
+ png_composite_16(w, v, a, background->red);
+ x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
+ *dp = (png_byte)((x >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(x & 0xff);
+ v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
+ png_composite_16(w, v, a, background->green);
+ x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
+ *(dp + 2) = (png_byte)((x >> 8) & 0xff);
+ *(dp + 3) = (png_byte)(x & 0xff);
+ v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
+ png_composite_16(w, v, a, background->blue);
+ x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
+ *(dp + 4) = (png_byte)((x >> 8) & 0xff);
+ *(dp + 5) = (png_byte)(x & 0xff);
+ }
+ }
+ }
+ else
+#endif
+ {
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++, sp += 8, dp += 6)
+ {
+ png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
+ << 8) + (png_uint_16)(*(sp + 7)));
+ if (a == (png_uint_16)0xffff)
+ {
+ png_memcpy(dp, sp, 6);
+ }
+ else if (a == 0)
+ {
+ *dp = (png_byte)((background->red >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(background->red & 0xff);
+ *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
+ *(dp + 3) = (png_byte)(background->green & 0xff);
+ *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
+ *(dp + 5) = (png_byte)(background->blue & 0xff);
+ }
+ else
+ {
+ png_uint_16 v;
+
+ png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
+ png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
+ + *(sp + 3));
+ png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
+ + *(sp + 5));
+
+ png_composite_16(v, r, a, background->red);
+ *dp = (png_byte)((v >> 8) & 0xff);
+ *(dp + 1) = (png_byte)(v & 0xff);
+ png_composite_16(v, g, a, background->green);
+ *(dp + 2) = (png_byte)((v >> 8) & 0xff);
+ *(dp + 3) = (png_byte)(v & 0xff);
+ png_composite_16(v, b, a, background->blue);
+ *(dp + 4) = (png_byte)((v >> 8) & 0xff);
+ *(dp + 5) = (png_byte)(v & 0xff);
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
+ row_info->channels--;
+ row_info->pixel_depth = (png_byte)(row_info->channels *
+ row_info->bit_depth);
+ row_info->rowbytes = ((row_width *
+ row_info->pixel_depth + 7) >> 3);
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+/* Gamma correct the image, avoiding the alpha channel. Make sure
+ * you do this after you deal with the transparency issue on grayscale
+ * or RGB images. If your bit depth is 8, use gamma_table, if it
+ * is 16, use gamma_16_table and gamma_shift. Build these with
+ * build_gamma_table().
+ */
+void
+png_do_gamma(png_row_infop row_info, png_bytep row,
+ png_bytep gamma_table, png_uint_16pp gamma_16_table,
+ int gamma_shift)
+{
+ png_bytep sp;
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+
+ png_debug(1, "in png_do_gamma\n");
+ if (
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
+ (row_info->bit_depth == 16 && gamma_16_table != NULL)))
+ {
+ switch (row_info->color_type)
+ {
+ case PNG_COLOR_TYPE_RGB:
+ {
+ if (row_info->bit_depth == 8)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ *sp = gamma_table[*sp];
+ sp++;
+ *sp = gamma_table[*sp];
+ sp++;
+ *sp = gamma_table[*sp];
+ sp++;
+ }
+ }
+ else /* if (row_info->bit_depth == 16) */
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 v;
+
+ v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ {
+ if (row_info->bit_depth == 8)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ *sp = gamma_table[*sp];
+ sp++;
+ *sp = gamma_table[*sp];
+ sp++;
+ *sp = gamma_table[*sp];
+ sp++;
+ sp++;
+ }
+ }
+ else /* if (row_info->bit_depth == 16) */
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 4;
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ {
+ if (row_info->bit_depth == 8)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ *sp = gamma_table[*sp];
+ sp += 2;
+ }
+ }
+ else /* if (row_info->bit_depth == 16) */
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 4;
+ }
+ }
+ break;
+ }
+ case PNG_COLOR_TYPE_GRAY:
+ {
+ if (row_info->bit_depth == 2)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i += 4)
+ {
+ int a = *sp & 0xc0;
+ int b = *sp & 0x30;
+ int c = *sp & 0x0c;
+ int d = *sp & 0x03;
+
+ *sp = (png_byte)(
+ ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
+ ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
+ ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
+ ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
+ sp++;
+ }
+ }
+ if (row_info->bit_depth == 4)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i += 2)
+ {
+ int msb = *sp & 0xf0;
+ int lsb = *sp & 0x0f;
+
+ *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
+ | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
+ sp++;
+ }
+ }
+ else if (row_info->bit_depth == 8)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ *sp = gamma_table[*sp];
+ sp++;
+ }
+ }
+ else if (row_info->bit_depth == 16)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
+ *sp = (png_byte)((v >> 8) & 0xff);
+ *(sp + 1) = (png_byte)(v & 0xff);
+ sp += 2;
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+/* Expands a palette row to an RGB or RGBA row depending
+ * upon whether you supply trans and num_trans.
+ */
+void
+png_do_expand_palette(png_row_infop row_info, png_bytep row,
+ png_colorp palette, png_bytep trans, int num_trans)
+{
+ int shift, value;
+ png_bytep sp, dp;
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+
+ png_debug(1, "in png_do_expand_palette\n");
+ if (
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ row != NULL && row_info != NULL &&
+#endif
+ row_info->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (row_info->bit_depth < 8)
+ {
+ switch (row_info->bit_depth)
+ {
+ case 1:
+ {
+ sp = row + (png_size_t)((row_width - 1) >> 3);
+ dp = row + (png_size_t)row_width - 1;
+ shift = 7 - (int)((row_width + 7) & 7);
+ for (i = 0; i < row_width; i++)
+ {
+ if ((*sp >> shift) & 0x1)
+ *dp = 1;
+ else
+ *dp = 0;
+ if (shift == 7)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift++;
+
+ dp--;
+ }
+ break;
+ }
+ case 2:
+ {
+ sp = row + (png_size_t)((row_width - 1) >> 2);
+ dp = row + (png_size_t)row_width - 1;
+ shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+ for (i = 0; i < row_width; i++)
+ {
+ value = (*sp >> shift) & 0x3;
+ *dp = (png_byte)value;
+ if (shift == 6)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift += 2;
+
+ dp--;
+ }
+ break;
+ }
+ case 4:
+ {
+ sp = row + (png_size_t)((row_width - 1) >> 1);
+ dp = row + (png_size_t)row_width - 1;
+ shift = (int)((row_width & 1) << 2);
+ for (i = 0; i < row_width; i++)
+ {
+ value = (*sp >> shift) & 0xf;
+ *dp = (png_byte)value;
+ if (shift == 4)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift += 4;
+
+ dp--;
+ }
+ break;
+ }
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = 8;
+ row_info->rowbytes = row_width;
+ }
+ switch (row_info->bit_depth)
+ {
+ case 8:
+ {
+ if (trans != NULL)
+ {
+ sp = row + (png_size_t)row_width - 1;
+ dp = row + (png_size_t)(row_width << 2) - 1;
+
+ for (i = 0; i < row_width; i++)
+ {
+ if ((int)(*sp) >= num_trans)
+ *dp-- = 0xff;
+ else
+ *dp-- = trans[*sp];
+ *dp-- = palette[*sp].blue;
+ *dp-- = palette[*sp].green;
+ *dp-- = palette[*sp].red;
+ sp--;
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = 32;
+ row_info->rowbytes = row_width * 4;
+ row_info->color_type = 6;
+ row_info->channels = 4;
+ }
+ else
+ {
+ sp = row + (png_size_t)row_width - 1;
+ dp = row + (png_size_t)(row_width * 3) - 1;
+
+ for (i = 0; i < row_width; i++)
+ {
+ *dp-- = palette[*sp].blue;
+ *dp-- = palette[*sp].green;
+ *dp-- = palette[*sp].red;
+ sp--;
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = 24;
+ row_info->rowbytes = row_width * 3;
+ row_info->color_type = 2;
+ row_info->channels = 3;
+ }
+ break;
+ }
+ }
+ }
+}
+
+/* If the bit depth < 8, it is expanded to 8. Also, if the
+ * transparency value is supplied, an alpha channel is built.
+ */
+void
+png_do_expand(png_row_infop row_info, png_bytep row,
+ png_color_16p trans_value)
+{
+ int shift, value;
+ png_bytep sp, dp;
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+
+ png_debug(1, "in png_do_expand\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL)
+#endif
+ {
+ if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
+
+ if (row_info->bit_depth < 8)
+ {
+ switch (row_info->bit_depth)
+ {
+ case 1:
+ {
+ gray = (png_uint_16)(gray*0xff);
+ sp = row + (png_size_t)((row_width - 1) >> 3);
+ dp = row + (png_size_t)row_width - 1;
+ shift = 7 - (int)((row_width + 7) & 7);
+ for (i = 0; i < row_width; i++)
+ {
+ if ((*sp >> shift) & 0x1)
+ *dp = 0xff;
+ else
+ *dp = 0;
+ if (shift == 7)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift++;
+
+ dp--;
+ }
+ break;
+ }
+ case 2:
+ {
+ gray = (png_uint_16)(gray*0x55);
+ sp = row + (png_size_t)((row_width - 1) >> 2);
+ dp = row + (png_size_t)row_width - 1;
+ shift = (int)((3 - ((row_width + 3) & 3)) << 1);
+ for (i = 0; i < row_width; i++)
+ {
+ value = (*sp >> shift) & 0x3;
+ *dp = (png_byte)(value | (value << 2) | (value << 4) |
+ (value << 6));
+ if (shift == 6)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift += 2;
+
+ dp--;
+ }
+ break;
+ }
+ case 4:
+ {
+ gray = (png_uint_16)(gray*0x11);
+ sp = row + (png_size_t)((row_width - 1) >> 1);
+ dp = row + (png_size_t)row_width - 1;
+ shift = (int)((1 - ((row_width + 1) & 1)) << 2);
+ for (i = 0; i < row_width; i++)
+ {
+ value = (*sp >> shift) & 0xf;
+ *dp = (png_byte)(value | (value << 4));
+ if (shift == 4)
+ {
+ shift = 0;
+ sp--;
+ }
+ else
+ shift = 4;
+
+ dp--;
+ }
+ break;
+ }
+ }
+ row_info->bit_depth = 8;
+ row_info->pixel_depth = 8;
+ row_info->rowbytes = row_width;
+ }
+
+ if (trans_value != NULL)
+ {
+ if (row_info->bit_depth == 8)
+ {
+ sp = row + (png_size_t)row_width - 1;
+ dp = row + (png_size_t)(row_width << 1) - 1;
+ for (i = 0; i < row_width; i++)
+ {
+ if (*sp == gray)
+ *dp-- = 0;
+ else
+ *dp-- = 0xff;
+ *dp-- = *sp--;
+ }
+ }
+ else if (row_info->bit_depth == 16)
+ {
+ sp = row + row_info->rowbytes - 1;
+ dp = row + (row_info->rowbytes << 1) - 1;
+ for (i = 0; i < row_width; i++)
+ {
+ if (((png_uint_16)*(sp) |
+ ((png_uint_16)*(sp - 1) << 8)) == gray)
+ {
+ *dp-- = 0;
+ *dp-- = 0;
+ }
+ else
+ {
+ *dp-- = 0xff;
+ *dp-- = 0xff;
+ }
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ }
+ }
+ row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ row_info->channels = 2;
+ row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
+ row_info->rowbytes =
+ ((row_width * row_info->pixel_depth) >> 3);
+ }
+ }
+ else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
+ {
+ if (row_info->bit_depth == 8)
+ {
+ sp = row + (png_size_t)row_info->rowbytes - 1;
+ dp = row + (png_size_t)(row_width << 2) - 1;
+ for (i = 0; i < row_width; i++)
+ {
+ if (*(sp - 2) == trans_value->red &&
+ *(sp - 1) == trans_value->green &&
+ *(sp - 0) == trans_value->blue)
+ *dp-- = 0;
+ else
+ *dp-- = 0xff;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ }
+ }
+ else if (row_info->bit_depth == 16)
+ {
+ sp = row + row_info->rowbytes - 1;
+ dp = row + (png_size_t)(row_width << 3) - 1;
+ for (i = 0; i < row_width; i++)
+ {
+ if ((((png_uint_16)*(sp - 4) |
+ ((png_uint_16)*(sp - 5) << 8)) == trans_value->red) &&
+ (((png_uint_16)*(sp - 2) |
+ ((png_uint_16)*(sp - 3) << 8)) == trans_value->green) &&
+ (((png_uint_16)*(sp - 0) |
+ ((png_uint_16)*(sp - 1) << 8)) == trans_value->blue))
+ {
+ *dp-- = 0;
+ *dp-- = 0;
+ }
+ else
+ {
+ *dp-- = 0xff;
+ *dp-- = 0xff;
+ }
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ *dp-- = *sp--;
+ }
+ }
+ row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ row_info->channels = 4;
+ row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
+ row_info->rowbytes =
+ ((row_width * row_info->pixel_depth) >> 3);
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_DITHER_SUPPORTED)
+void
+png_do_dither(png_row_infop row_info, png_bytep row,
+ png_bytep palette_lookup, png_bytep dither_lookup)
+{
+ png_bytep sp, dp;
+ png_uint_32 i;
+ png_uint_32 row_width=row_info->width;
+
+ png_debug(1, "in png_do_dither\n");
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL)
+#endif
+ {
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
+ palette_lookup && row_info->bit_depth == 8)
+ {
+ int r, g, b, p;
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ r = *sp++;
+ g = *sp++;
+ b = *sp++;
+
+ /* this looks real messy, but the compiler will reduce
+ it down to a reasonable formula. For example, with
+ 5 bits per color, we get:
+ p = (((r >> 3) & 0x1f) << 10) |
+ (((g >> 3) & 0x1f) << 5) |
+ ((b >> 3) & 0x1f);
+ */
+ p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
+ ((1 << PNG_DITHER_RED_BITS) - 1)) <<
+ (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
+ (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
+ ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
+ (PNG_DITHER_BLUE_BITS)) |
+ ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
+ ((1 << PNG_DITHER_BLUE_BITS) - 1));
+
+ *dp++ = palette_lookup[p];
+ }
+ row_info->color_type = PNG_COLOR_TYPE_PALETTE;
+ row_info->channels = 1;
+ row_info->pixel_depth = row_info->bit_depth;
+ row_info->rowbytes =
+ ((row_width * row_info->pixel_depth + 7) >> 3);
+ }
+ else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
+ palette_lookup != NULL && row_info->bit_depth == 8)
+ {
+ int r, g, b, p;
+ sp = row;
+ dp = row;
+ for (i = 0; i < row_width; i++)
+ {
+ r = *sp++;
+ g = *sp++;
+ b = *sp++;
+ sp++;
+
+ p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
+ ((1 << PNG_DITHER_RED_BITS) - 1)) <<
+ (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
+ (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
+ ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
+ (PNG_DITHER_BLUE_BITS)) |
+ ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
+ ((1 << PNG_DITHER_BLUE_BITS) - 1));
+
+ *dp++ = palette_lookup[p];
+ }
+ row_info->color_type = PNG_COLOR_TYPE_PALETTE;
+ row_info->channels = 1;
+ row_info->pixel_depth = row_info->bit_depth;
+ row_info->rowbytes =
+ ((row_width * row_info->pixel_depth + 7) >> 3);
+ }
+ else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
+ dither_lookup && row_info->bit_depth == 8)
+ {
+ sp = row;
+ for (i = 0; i < row_width; i++, sp++)
+ {
+ *sp = dither_lookup[*sp];
+ }
+ }
+ }
+}
+#endif
+
+#if defined(PNG_READ_GAMMA_SUPPORTED)
+static int png_gamma_shift[] =
+ {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0};
+
+/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit
+ * tables, we don't make a full table if we are reducing to 8-bit in
+ * the future. Note also how the gamma_16 tables are segmented so that
+ * we don't need to allocate > 64K chunks for a full 16-bit table.
+ */
+void
+png_build_gamma_table(png_structp png_ptr)
+{
+ png_debug(1, "in png_build_gamma_table\n");
+ if(png_ptr->gamma != 0.0)
+ {
+ if (png_ptr->bit_depth <= 8)
+ {
+ int i;
+ double g;
+
+ if (png_ptr->screen_gamma > .000001)
+ g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
+ else
+ g = 1.0;
+
+ png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
+
+ for (i = 0; i < 256; i++)
+ {
+ png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
+ g) * 255.0 + .5);
+ }
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
+ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+ if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
+ {
+
+ g = 1.0 / (png_ptr->gamma);
+
+ png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
+
+ for (i = 0; i < 256; i++)
+ {
+ png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
+ g) * 255.0 + .5);
+ }
+
+
+ png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
+
+ if(png_ptr->screen_gamma > 0.000001)
+ g = 1.0 / png_ptr->screen_gamma;
+ else
+ g = png_ptr->gamma; /* probably doing rgb_to_gray */
+
+ for (i = 0; i < 256; i++)
+ {
+ png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
+ g) * 255.0 + .5);
+
+ }
+ }
+#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
+ }
+ else
+ {
+ double g;
+ int i, j, shift, num;
+ int sig_bit;
+ png_uint_32 ig;
+
+ if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
+ {
+ sig_bit = (int)png_ptr->sig_bit.red;
+ if ((int)png_ptr->sig_bit.green > sig_bit)
+ sig_bit = png_ptr->sig_bit.green;
+ if ((int)png_ptr->sig_bit.blue > sig_bit)
+ sig_bit = png_ptr->sig_bit.blue;
+ }
+ else
+ {
+ sig_bit = (int)png_ptr->sig_bit.gray;
+ }
+
+ if (sig_bit > 0)
+ shift = 16 - sig_bit;
+ else
+ shift = 0;
+
+ if (png_ptr->transformations & PNG_16_TO_8)
+ {
+ if (shift < (16 - PNG_MAX_GAMMA_8))
+ shift = (16 - PNG_MAX_GAMMA_8);
+ }
+
+ if (shift > 8)
+ shift = 8;
+ if (shift < 0)
+ shift = 0;
+
+ png_ptr->gamma_shift = (png_byte)shift;
+
+ num = (1 << (8 - shift));
+
+ if (png_ptr->screen_gamma > .000001)
+ g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
+ else
+ g = 1.0;
+
+ png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
+ (png_uint_32)(num * sizeof (png_uint_16p)));
+
+ if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
+ {
+ double fin, fout;
+ png_uint_32 last, max;
+
+ for (i = 0; i < num; i++)
+ {
+ png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(256 * sizeof (png_uint_16)));
+ }
+
+ g = 1.0 / g;
+ last = 0;
+ for (i = 0; i < 256; i++)
+ {
+ fout = ((double)i + 0.5) / 256.0;
+ fin = pow(fout, g);
+ max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
+ while (last <= max)
+ {
+ png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
+ [(int)(last >> (8 - shift))] = (png_uint_16)(
+ (png_uint_16)i | ((png_uint_16)i << 8));
+ last++;
+ }
+ }
+ while (last < ((png_uint_32)num << 8))
+ {
+ png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
+ [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
+ last++;
+ }
+ }
+ else
+ {
+ for (i = 0; i < num; i++)
+ {
+ png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(256 * sizeof (png_uint_16)));
+
+ ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
+ for (j = 0; j < 256; j++)
+ {
+ png_ptr->gamma_16_table[i][j] =
+ (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
+ 65535.0, g) * 65535.0 + .5);
+ }
+ }
+ }
+
+#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
+ defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
+ if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
+ {
+
+ g = 1.0 / (png_ptr->gamma);
+
+ png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
+ (png_uint_32)(num * sizeof (png_uint_16p )));
+
+ for (i = 0; i < num; i++)
+ {
+ png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(256 * sizeof (png_uint_16)));
+
+ ig = (((png_uint_32)i *
+ (png_uint_32)png_gamma_shift[shift]) >> 4);
+ for (j = 0; j < 256; j++)
+ {
+ png_ptr->gamma_16_to_1[i][j] =
+ (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
+ 65535.0, g) * 65535.0 + .5);
+ }
+ }
+
+ if(png_ptr->screen_gamma > 0.000001)
+ g = 1.0 / png_ptr->screen_gamma;
+ else
+ g = png_ptr->gamma; /* probably doing rgb_to_gray */
+
+ png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
+ (png_uint_32)(num * sizeof (png_uint_16p)));
+
+ for (i = 0; i < num; i++)
+ {
+ png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(256 * sizeof (png_uint_16)));
+
+ ig = (((png_uint_32)i *
+ (png_uint_32)png_gamma_shift[shift]) >> 4);
+ for (j = 0; j < 256; j++)
+ {
+ png_ptr->gamma_16_from_1[i][j] =
+ (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
+ 65535.0, g) * 65535.0 + .5);
+ }
+ }
+ }
+#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
+ }
+ }
+}
+#endif
+
diff --git a/osframework/source/ImageLib/png/pngrutil.c b/osframework/source/ImageLib/png/pngrutil.c
new file mode 100644
index 0000000..f5762b7
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngrutil.c
@@ -0,0 +1,2335 @@
+
+/* pngrutil.c - utilities to read a PNG file
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ *
+ * This file contains routines that are only called from within
+ * libpng itself during the course of reading an image.
+ */
+
+#define PNG_INTERNAL
+#include "png.h"
+
+#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
+#include "pngasmrd.h"
+#endif
+
+#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
+/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
+png_uint_32
+png_get_uint_32(png_bytep buf)
+{
+ png_uint_32 i = ((png_uint_32)(*buf) << 24) +
+ ((png_uint_32)(*(buf + 1)) << 16) +
+ ((png_uint_32)(*(buf + 2)) << 8) +
+ (png_uint_32)(*(buf + 3));
+
+ return (i);
+}
+
+#if defined(PNG_READ_pCAL_SUPPORTED)
+/* Grab a signed 32-bit integer from a buffer in big-endian format. The
+ * data is stored in the PNG file in two's complement format, and it is
+ * assumed that the machine format for signed integers is the same. */
+png_int_32
+png_get_int_32(png_bytep buf)
+{
+ png_int_32 i = ((png_int_32)(*buf) << 24) +
+ ((png_int_32)(*(buf + 1)) << 16) +
+ ((png_int_32)(*(buf + 2)) << 8) +
+ (png_int_32)(*(buf + 3));
+
+ return (i);
+}
+#endif /* PNG_READ_pCAL_SUPPORTED */
+
+/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
+png_uint_16
+png_get_uint_16(png_bytep buf)
+{
+ png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
+ (png_uint_16)(*(buf + 1)));
+
+ return (i);
+}
+#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
+
+/* Read data, and (optionally) run it through the CRC. */
+void
+png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
+{
+ png_read_data(png_ptr, buf, length);
+ png_calculate_crc(png_ptr, buf, length);
+}
+
+/* Optionally skip data and then check the CRC. Depending on whether we
+ are reading a ancillary or critical chunk, and how the program has set
+ things up, we may calculate the CRC on the data and print a message.
+ Returns '1' if there was a CRC error, '0' otherwise. */
+int
+png_crc_finish(png_structp png_ptr, png_uint_32 skip)
+{
+ png_size_t i;
+ png_size_t istop = png_ptr->zbuf_size;
+
+ for (i = (png_size_t)skip; i > istop; i -= istop)
+ {
+ png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
+ }
+ if (i)
+ {
+ png_crc_read(png_ptr, png_ptr->zbuf, i);
+ }
+
+ if (png_crc_error(png_ptr))
+ {
+ if ((png_ptr->chunk_name[0] & 0x20 && /* Ancillary */
+ !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
+ (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
+ png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
+ {
+ png_chunk_warning(png_ptr, "CRC error");
+ }
+ else
+ {
+ png_chunk_error(png_ptr, "CRC error");
+ }
+ return (1);
+ }
+
+ return (0);
+}
+
+/* Compare the CRC stored in the PNG file with that calculated by libpng from
+ the data it has read thus far. */
+int
+png_crc_error(png_structp png_ptr)
+{
+ png_byte crc_bytes[4];
+ png_uint_32 crc;
+ 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;
+ }
+
+ png_read_data(png_ptr, crc_bytes, 4);
+
+ if (need_crc)
+ {
+ crc = png_get_uint_32(crc_bytes);
+ return ((int)(crc != png_ptr->crc));
+ }
+ else
+ return (0);
+}
+
+
+/* read and check the IDHR chunk */
+void
+png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_byte buf[13];
+ png_uint_32 width, height;
+ int bit_depth, color_type, compression_type, filter_type;
+ int interlace_type;
+
+ png_debug(1, "in png_handle_IHDR\n");
+
+ if (png_ptr->mode != PNG_BEFORE_IHDR)
+ png_error(png_ptr, "Out of place IHDR");
+
+ /* check the length */
+ if (length != 13)
+ png_error(png_ptr, "Invalid IHDR chunk");
+
+ png_ptr->mode |= PNG_HAVE_IHDR;
+
+ png_crc_read(png_ptr, buf, 13);
+ png_crc_finish(png_ptr, 0);
+
+ width = png_get_uint_32(buf);
+ height = png_get_uint_32(buf + 4);
+ bit_depth = buf[8];
+ color_type = buf[9];
+ compression_type = buf[10];
+ filter_type = buf[11];
+ interlace_type = buf[12];
+
+ /* check for width and height valid values */
+ if (width == 0 || width > PNG_MAX_UINT || height == 0 ||
+ height > PNG_MAX_UINT)
+ png_error(png_ptr, "Invalid image size in IHDR");
+
+ /* check other values */
+ if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
+ bit_depth != 8 && bit_depth != 16)
+ png_error(png_ptr, "Invalid bit depth in IHDR");
+
+ if (color_type < 0 || color_type == 1 ||
+ color_type == 5 || color_type > 6)
+ png_error(png_ptr, "Invalid color type in IHDR");
+
+ if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
+ ((color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
+ png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
+
+ if (interlace_type >= PNG_INTERLACE_LAST)
+ png_error(png_ptr, "Unknown interlace method in IHDR");
+
+ if (compression_type != PNG_COMPRESSION_TYPE_BASE)
+ png_error(png_ptr, "Unknown compression method in IHDR");
+
+ if (filter_type != PNG_FILTER_TYPE_BASE)
+ png_error(png_ptr, "Unknown filter method in IHDR");
+
+ /* set internal variables */
+ png_ptr->width = width;
+ png_ptr->height = height;
+ png_ptr->bit_depth = (png_byte)bit_depth;
+ png_ptr->interlaced = (png_byte)interlace_type;
+ png_ptr->color_type = (png_byte)color_type;
+
+ /* find number of channels */
+ switch (png_ptr->color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ case PNG_COLOR_TYPE_PALETTE:
+ png_ptr->channels = 1;
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ png_ptr->channels = 3;
+ break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ png_ptr->channels = 2;
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ png_ptr->channels = 4;
+ break;
+ }
+
+ /* set up other useful info */
+ png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
+ png_ptr->channels);
+ png_ptr->rowbytes = ((png_ptr->width *
+ (png_uint_32)png_ptr->pixel_depth + 7) >> 3);
+ png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
+ png_debug1(3,"channels = %d\n", png_ptr->channels);
+ png_debug1(3,"rowbytes = %d\n", png_ptr->rowbytes);
+ png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
+ color_type, interlace_type, compression_type, filter_type);
+}
+
+/* read and check the palette */
+void
+png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_colorp palette;
+ int num, i;
+
+ png_debug(1, "in png_handle_PLTE\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before PLTE");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid PLTE after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->mode & PNG_HAVE_PLTE)
+ png_error(png_ptr, "Duplicate PLTE chunk");
+
+ png_ptr->mode |= PNG_HAVE_PLTE;
+
+#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
+ if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
+ {
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+#endif
+
+ if (length % 3)
+ {
+ if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
+ {
+ png_warning(png_ptr, "Invalid palette chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else
+ {
+ png_error(png_ptr, "Invalid palette chunk");
+ }
+ }
+
+ num = (int)length / 3;
+ palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
+ png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
+ for (i = 0; i < num; i++)
+ {
+ png_byte buf[3];
+
+ png_crc_read(png_ptr, buf, 3);
+ /* don't depend upon png_color being any order */
+ palette[i].red = buf[0];
+ palette[i].green = buf[1];
+ palette[i].blue = buf[2];
+ }
+
+ /* If we actually NEED the PLTE chunk (ie for a paletted image), we do
+ whatever the normal CRC configuration tells us. However, if we
+ have an RGB image, the PLTE can be considered ancillary, so
+ we will act as though it is. */
+#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+#endif
+ {
+ png_crc_finish(png_ptr, 0);
+ }
+#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
+ else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
+ {
+ /* If we don't want to use the data from an ancillary chunk,
+ we have two options: an error abort, or a warning and we
+ ignore the data in this chunk (which should be OK, since
+ it's considered ancillary for a RGB or RGBA image). */
+ if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
+ {
+ if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
+ {
+ png_chunk_error(png_ptr, "CRC error");
+ }
+ else
+ {
+ png_chunk_warning(png_ptr, "CRC error");
+ png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
+ png_zfree(png_ptr, palette);
+ return;
+ }
+ }
+ /* Otherwise, we (optionally) emit a warning and use the chunk. */
+ else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
+ {
+ png_chunk_warning(png_ptr, "CRC error");
+ }
+ }
+#endif
+ png_ptr->palette = palette;
+ png_ptr->num_palette = (png_uint_16)num;
+ png_set_PLTE(png_ptr, info_ptr, palette, num);
+
+#if defined (PNG_READ_tRNS_SUPPORTED)
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
+ {
+ if (png_ptr->num_trans > png_ptr->num_palette)
+ {
+ png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
+ png_ptr->num_trans = png_ptr->num_palette;
+ }
+ }
+ }
+#endif
+
+}
+
+void
+png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_debug(1, "in png_handle_IEND\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
+ {
+ png_error(png_ptr, "No image in file");
+
+ /* to quiet compiler warnings about unused info_ptr */
+ if (info_ptr == NULL)
+ return;
+ }
+
+ png_ptr->mode |= PNG_AFTER_IDAT | PNG_HAVE_IEND;
+
+ if (length != 0)
+ {
+ png_warning(png_ptr, "Incorrect IEND chunk length");
+ }
+ png_crc_finish(png_ptr, length);
+}
+
+#if defined(PNG_READ_gAMA_SUPPORTED)
+void
+png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_uint_32 igamma;
+ float file_gamma;
+ png_byte buf[4];
+
+ png_debug(1, "in png_handle_gAMA\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before gAMA");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid gAMA after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->mode & PNG_HAVE_PLTE)
+ /* Should be an error, but we can cope with it */
+ png_warning(png_ptr, "Out of place gAMA chunk");
+
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA
+#if defined(PNG_READ_sRGB_SUPPORTED)
+ && !(info_ptr->valid & PNG_INFO_sRGB)
+#endif
+ )
+ {
+ png_warning(png_ptr, "Duplicate gAMA chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != 4)
+ {
+ png_warning(png_ptr, "Incorrect gAMA chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 4);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ igamma = png_get_uint_32(buf);
+ /* check for zero gamma */
+ if (igamma == 0)
+ return;
+
+#if defined(PNG_READ_sRGB_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_sRGB)
+ if(fabs((float)igamma - 45455.)>500.)
+ {
+ png_warning(png_ptr,
+ "Ignoring incorrect gAMA value when sRGB is also present");
+#ifndef PNG_NO_CONSOLE_IO
+ fprintf(stderr, "igamma = %lu\n", igamma);
+#endif
+ return;
+ }
+#endif /* PNG_READ_sRGB_SUPPORTED */
+
+ file_gamma = (float)igamma / (float)100000.0;
+#ifdef PNG_READ_GAMMA_SUPPORTED
+ png_ptr->gamma = file_gamma;
+#endif
+ png_set_gAMA(png_ptr, info_ptr, file_gamma);
+}
+#endif
+
+#if defined(PNG_READ_sBIT_SUPPORTED)
+void
+png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_size_t truelen;
+ png_byte buf[4];
+
+ png_debug(1, "in png_handle_sBIT\n");
+
+ buf[0] = buf[1] = buf[2] = buf[3] = 0;
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before sBIT");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid sBIT after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->mode & PNG_HAVE_PLTE)
+ {
+ /* Should be an error, but we can cope with it */
+ png_warning(png_ptr, "Out of place sBIT chunk");
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT)
+ {
+ png_warning(png_ptr, "Duplicate sBIT chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ truelen = 3;
+ else
+ truelen = (png_size_t)png_ptr->channels;
+
+ if (length != truelen)
+ {
+ png_warning(png_ptr, "Incorrect sBIT chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, truelen);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
+ {
+ png_ptr->sig_bit.red = buf[0];
+ png_ptr->sig_bit.green = buf[1];
+ png_ptr->sig_bit.blue = buf[2];
+ png_ptr->sig_bit.alpha = buf[3];
+ }
+ else
+ {
+ png_ptr->sig_bit.gray = buf[0];
+ png_ptr->sig_bit.red = buf[0];
+ png_ptr->sig_bit.green = buf[0];
+ png_ptr->sig_bit.blue = buf[0];
+ png_ptr->sig_bit.alpha = buf[1];
+ }
+ png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
+}
+#endif
+
+#if defined(PNG_READ_cHRM_SUPPORTED)
+void
+png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_byte buf[4];
+ png_uint_32 val;
+ float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
+
+ png_debug(1, "in png_handle_cHRM\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before sBIT");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid cHRM after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->mode & PNG_HAVE_PLTE)
+ /* Should be an error, but we can cope with it */
+ png_warning(png_ptr, "Missing PLTE before cHRM");
+
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM
+#if defined(PNG_READ_sRGB_SUPPORTED)
+ && !(info_ptr->valid & PNG_INFO_sRGB)
+#endif
+ )
+ {
+ png_warning(png_ptr, "Duplicate cHRM chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != 32)
+ {
+ png_warning(png_ptr, "Incorrect cHRM chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ white_x = (float)0.312713; /* assume sRGB */
+ else
+ white_x = (float)val / (float)100000.0;
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ white_y = (float)0.329016; /* assume sRGB */
+ else
+ white_y = (float)val / (float)100000.0;
+
+ if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
+ white_x + white_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM white point");
+ png_crc_finish(png_ptr, 24);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ red_x = (float)0.64; /* assume sRGB */
+ else
+ red_x = (float)val / (float)100000.0;
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ red_y = (float)0.33; /* assume sRGB */
+ else
+ red_y = (float)val / (float)100000.0;
+
+ if (red_x < 0 || red_x > 0.8 || red_y < 0 || red_y > 0.8 ||
+ red_x + red_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM red point");
+ png_crc_finish(png_ptr, 16);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ green_x = (float)0.3; /* assume sRGB */
+ else
+ green_x = (float)val / (float)100000.0;
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ green_y = (float)0.6; /* assume sRGB */
+ else
+ green_y = (float)val / (float)100000.0;
+
+ if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 ||
+ green_x + green_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM green point");
+ png_crc_finish(png_ptr, 8);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ blue_x = (float)0.15; /* assume sRGB */
+ else
+ blue_x = (float)val / (float)100000.0;
+
+ png_crc_read(png_ptr, buf, 4);
+ val = png_get_uint_32(buf);
+ if (val == (png_uint_32)0xffffffffL)
+ blue_y = (float)0.06; /* assume sRGB */
+ else
+ blue_y = (float)val / (float)100000.0;
+
+ if (blue_x < (float)0 || blue_x > (float)0.8 || blue_y < (float)0 ||
+ blue_y > (float)0.8 || blue_x + blue_y > (float)1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM blue point");
+ png_crc_finish(png_ptr, 0);
+ return;
+ }
+
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+#if defined(PNG_READ_sRGB_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_sRGB)
+ {
+ if (fabs(white_x - (float).3127) > (float).001 ||
+ fabs(white_y - (float).3290) > (float).001 ||
+ fabs( red_x - (float).6400) > (float).001 ||
+ fabs( red_y - (float).3300) > (float).001 ||
+ fabs(green_x - (float).3000) > (float).001 ||
+ fabs(green_y - (float).6000) > (float).001 ||
+ fabs( blue_x - (float).1500) > (float).001 ||
+ fabs( blue_y - (float).0600) > (float).001)
+ {
+
+ png_warning(png_ptr,
+ "Ignoring incorrect cHRM value when sRGB is also present");
+#ifndef PNG_NO_CONSOLE_IO
+ fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
+ white_x, white_y, red_x, red_y);
+ fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
+ green_x, green_y, blue_x, blue_y);
+#endif
+ }
+ return;
+ }
+#endif /* PNG_READ_sRGB_SUPPORTED */
+
+ png_set_cHRM(png_ptr, info_ptr,
+ white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
+}
+#endif
+
+#if defined(PNG_READ_sRGB_SUPPORTED)
+void
+png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ int intent;
+ png_byte buf[1];
+
+ png_debug(1, "in png_handle_sRGB\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before sRGB");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid sRGB after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->mode & PNG_HAVE_PLTE)
+ /* Should be an error, but we can cope with it */
+ png_warning(png_ptr, "Out of place sRGB chunk");
+
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB)
+ {
+ png_warning(png_ptr, "Duplicate sRGB chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != 1)
+ {
+ png_warning(png_ptr, "Incorrect sRGB chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 1);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ intent = buf[0];
+ /* check for bad intent */
+ if (intent >= PNG_sRGB_INTENT_LAST)
+ {
+ png_warning(png_ptr, "Unknown sRGB intent");
+ return;
+ }
+
+#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
+ if ((info_ptr->valid & PNG_INFO_gAMA))
+ if(fabs((png_ptr->gamma*(float)100000.+.5)-45455.) > 500.)
+ {
+ png_warning(png_ptr,
+ "Ignoring incorrect gAMA value when sRGB is also present");
+#ifndef PNG_NO_CONSOLE_IO
+ fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
+#endif
+ }
+#endif /* PNG_READ_gAMA_SUPPORTED */
+
+#ifdef PNG_READ_cHRM_SUPPORTED
+ if (info_ptr->valid & PNG_INFO_cHRM)
+ if (fabs(info_ptr->x_white - (float).3127) > (float).001 ||
+ fabs(info_ptr->y_white - (float).3290) > (float).001 ||
+ fabs( info_ptr->x_red - (float).6400) > (float).001 ||
+ fabs( info_ptr->y_red - (float).3300) > (float).001 ||
+ fabs(info_ptr->x_green - (float).3000) > (float).001 ||
+ fabs(info_ptr->y_green - (float).6000) > (float).001 ||
+ fabs( info_ptr->x_blue - (float).1500) > (float).001 ||
+ fabs( info_ptr->y_blue - (float).0600) > (float).001)
+ {
+ png_warning(png_ptr,
+ "Ignoring incorrect cHRM value when sRGB is also present");
+ }
+#endif /* PNG_READ_cHRM_SUPPORTED */
+
+ png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
+}
+#endif /* PNG_READ_sRGB_SUPPORTED */
+
+#if defined(PNG_READ_tRNS_SUPPORTED)
+void
+png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_debug(1, "in png_handle_tRNS\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before tRNS");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid tRNS after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
+ {
+ png_warning(png_ptr, "Duplicate tRNS chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (!(png_ptr->mode & PNG_HAVE_PLTE))
+ {
+ /* Should be an error, but we can cope with it */
+ png_warning(png_ptr, "Missing PLTE before tRNS");
+ }
+ else if (length > png_ptr->num_palette)
+ {
+ png_warning(png_ptr, "Incorrect tRNS chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ if (length == 0)
+ {
+ png_warning(png_ptr, "Zero length tRNS chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
+ png_ptr->flags |= PNG_FLAG_FREE_TRANS;
+ png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length);
+ png_ptr->num_trans = (png_uint_16)length;
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ png_byte buf[6];
+
+ if (length != 6)
+ {
+ png_warning(png_ptr, "Incorrect tRNS chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, (png_size_t)length);
+ png_ptr->num_trans = 1;
+ png_ptr->trans_values.red = png_get_uint_16(buf);
+ png_ptr->trans_values.green = png_get_uint_16(buf + 2);
+ png_ptr->trans_values.blue = png_get_uint_16(buf + 4);
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ png_byte buf[6];
+
+ if (length != 2)
+ {
+ png_warning(png_ptr, "Incorrect tRNS chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 2);
+ png_ptr->num_trans = 1;
+ png_ptr->trans_values.gray = png_get_uint_16(buf);
+ }
+ else
+ {
+ png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ png_set_tRNS(png_ptr, info_ptr, png_ptr->trans, png_ptr->num_trans,
+ &(png_ptr->trans_values));
+}
+#endif
+
+#if defined(PNG_READ_bKGD_SUPPORTED)
+void
+png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_size_t truelen;
+ png_byte buf[6];
+
+ png_debug(1, "in png_handle_bKGD\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before bKGD");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid bKGD after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
+ !(png_ptr->mode & PNG_HAVE_PLTE))
+ {
+ png_warning(png_ptr, "Missing PLTE before bKGD");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD)
+ {
+ png_warning(png_ptr, "Duplicate bKGD chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ truelen = 1;
+ else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
+ truelen = 6;
+ else
+ truelen = 2;
+
+ if (length != truelen)
+ {
+ png_warning(png_ptr, "Incorrect bKGD chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, truelen);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ /* We convert the index value into RGB components so that we can allow
+ * arbitrary RGB values for background when we have transparency, and
+ * so it is easy to determine the RGB values of the background color
+ * from the info_ptr struct. */
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_ptr->background.index = buf[0];
+ if(info_ptr->num_palette)
+ {
+ if(buf[0] > info_ptr->num_palette)
+ {
+ png_warning(png_ptr, "Incorrect bKGD chunk index value");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ png_ptr->background.red =
+ (png_uint_16)png_ptr->palette[buf[0]].red;
+ png_ptr->background.green =
+ (png_uint_16)png_ptr->palette[buf[0]].green;
+ png_ptr->background.blue =
+ (png_uint_16)png_ptr->palette[buf[0]].blue;
+ }
+ }
+ else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
+ {
+ png_ptr->background.red =
+ png_ptr->background.green =
+ png_ptr->background.blue =
+ png_ptr->background.gray = png_get_uint_16(buf);
+ }
+ else
+ {
+ png_ptr->background.red = png_get_uint_16(buf);
+ png_ptr->background.green = png_get_uint_16(buf + 2);
+ png_ptr->background.blue = png_get_uint_16(buf + 4);
+ }
+
+ png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
+}
+#endif
+
+#if defined(PNG_READ_hIST_SUPPORTED)
+void
+png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ int num, i;
+
+ png_debug(1, "in png_handle_hIST\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before hIST");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid hIST after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (!(png_ptr->mode & PNG_HAVE_PLTE))
+ {
+ png_warning(png_ptr, "Missing PLTE before hIST");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST)
+ {
+ png_warning(png_ptr, "Duplicate hIST chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != (png_uint_32)(2 * png_ptr->num_palette))
+ {
+ png_warning(png_ptr, "Incorrect hIST chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ num = (int)length / 2 ;
+ png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(num * sizeof (png_uint_16)));
+ png_ptr->flags |= PNG_FLAG_FREE_HIST;
+ for (i = 0; i < num; i++)
+ {
+ png_byte buf[2];
+
+ png_crc_read(png_ptr, buf, 2);
+ png_ptr->hist[i] = png_get_uint_16(buf);
+ }
+
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ png_set_hIST(png_ptr, info_ptr, png_ptr->hist);
+}
+#endif
+
+#if defined(PNG_READ_pHYs_SUPPORTED)
+void
+png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_byte buf[9];
+ png_uint_32 res_x, res_y;
+ int unit_type;
+
+ png_debug(1, "in png_handle_pHYs\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before pHYS");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid pHYS after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
+ {
+ png_warning(png_ptr, "Duplicate pHYS chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != 9)
+ {
+ png_warning(png_ptr, "Incorrect pHYs chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 9);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ res_x = png_get_uint_32(buf);
+ res_y = png_get_uint_32(buf + 4);
+ unit_type = buf[8];
+ png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
+}
+#endif
+
+#if defined(PNG_READ_oFFs_SUPPORTED)
+void
+png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_byte buf[9];
+ png_uint_32 offset_x, offset_y;
+ int unit_type;
+
+ png_debug(1, "in png_handle_oFFs\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before oFFs");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid oFFs after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
+ {
+ png_warning(png_ptr, "Duplicate oFFs chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (length != 9)
+ {
+ png_warning(png_ptr, "Incorrect oFFs chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 9);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ offset_x = png_get_uint_32(buf);
+ offset_y = png_get_uint_32(buf + 4);
+ unit_type = buf[8];
+ png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
+}
+#endif
+
+#if defined(PNG_READ_pCAL_SUPPORTED)
+/* read the pCAL chunk (png-scivis-19970203) */
+void
+png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_charp purpose;
+ png_int_32 X0, X1;
+ png_byte type, nparams;
+ png_charp buf, units, endptr;
+ png_charpp params;
+ png_size_t slength;
+ int i;
+
+ png_debug(1, "in png_handle_pCAL\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before pCAL");
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
+ {
+ png_warning(png_ptr, "Invalid pCAL after IDAT");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL)
+ {
+ png_warning(png_ptr, "Duplicate pCAL chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_debug1(2, "Allocating and reading pCAL chunk data (%d bytes)\n",
+ length + 1);
+ purpose = (png_charp)png_malloc(png_ptr, length + 1);
+ slength = (png_size_t)length;
+ png_crc_read(png_ptr, (png_bytep)purpose, slength);
+
+ if (png_crc_finish(png_ptr, 0))
+ {
+ png_free(png_ptr, purpose);
+ return;
+ }
+
+ purpose[slength] = 0x00; /* null terminate the last string */
+
+ png_debug(3, "Finding end of pCAL purpose string\n");
+ for (buf = purpose; *buf; buf++)
+ /* empty loop */ ;
+
+ endptr = purpose + slength;
+
+ /* We need to have at least 12 bytes after the purpose string
+ in order to get the parameter information. */
+ if (endptr <= buf + 12)
+ {
+ png_warning(png_ptr, "Invalid pCAL data");
+ png_free(png_ptr, purpose);
+ return;
+ }
+
+ png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
+ X0 = png_get_int_32((png_bytep)buf+1);
+ X1 = png_get_int_32((png_bytep)buf+5);
+ type = buf[9];
+ nparams = buf[10];
+ units = buf + 11;
+
+ png_debug(3, "Checking pCAL equation type and number of parameters\n");
+ /* Check that we have the right number of parameters for known
+ equation types. */
+ if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
+ (type == PNG_EQUATION_BASE_E && nparams != 3) ||
+ (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
+ (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
+ {
+ png_warning(png_ptr, "Invalid pCAL parameters for equation type");
+ png_free(png_ptr, purpose);
+ return;
+ }
+ else if (type >= PNG_EQUATION_LAST)
+ {
+ png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
+ }
+
+ for (buf = units; *buf; buf++)
+ /* Empty loop to move past the units string. */ ;
+
+ png_debug(3, "Allocating pCAL parameters array\n");
+ params = (png_charpp)png_malloc(png_ptr, (png_uint_32)(nparams
+ *sizeof(png_charp))) ;
+
+ /* Get pointers to the start of each parameter string. */
+ for (i = 0; i < (int)nparams; i++)
+ {
+ buf++; /* Skip the null string terminator from previous parameter. */
+
+ png_debug1(3, "Reading pCAL parameter %d\n", i);
+ for (params[i] = buf; *buf != 0x00 && buf <= endptr; buf++)
+ /* Empty loop to move past each parameter string */ ;
+
+ /* Make sure we haven't run out of data yet */
+ if (buf > endptr)
+ {
+ png_warning(png_ptr, "Invalid pCAL data");
+ png_free(png_ptr, purpose);
+ png_free(png_ptr, params);
+ return;
+ }
+ }
+
+ png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
+ units, params);
+
+ png_free(png_ptr, purpose);
+ png_free(png_ptr, params);
+}
+#endif
+
+#if defined(PNG_READ_tIME_SUPPORTED)
+void
+png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_byte buf[7];
+ png_time mod_time;
+
+ png_debug(1, "in png_handle_tIME\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Out of place tIME chunk");
+ else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME)
+ {
+ png_warning(png_ptr, "Duplicate tIME chunk");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ if (png_ptr->mode & PNG_HAVE_IDAT)
+ png_ptr->mode |= PNG_AFTER_IDAT;
+
+ if (length != 7)
+ {
+ png_warning(png_ptr, "Incorrect tIME chunk length");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+
+ png_crc_read(png_ptr, buf, 7);
+ if (png_crc_finish(png_ptr, 0))
+ return;
+
+ mod_time.second = buf[6];
+ mod_time.minute = buf[5];
+ mod_time.hour = buf[4];
+ mod_time.day = buf[3];
+ mod_time.month = buf[2];
+ mod_time.year = png_get_uint_16(buf);
+
+ png_set_tIME(png_ptr, info_ptr, &mod_time);
+}
+#endif
+
+#if defined(PNG_READ_tEXt_SUPPORTED)
+/* Note: this does not properly handle chunks that are > 64K under DOS */
+void
+png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_textp text_ptr;
+ png_charp key;
+ png_charp text;
+ png_uint_32 skip = 0;
+ png_size_t slength;
+
+ png_debug(1, "in png_handle_tEXt\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before tEXt");
+
+ if (png_ptr->mode & PNG_HAVE_IDAT)
+ png_ptr->mode |= PNG_AFTER_IDAT;
+
+#ifdef PNG_MAX_MALLOC_64K
+ if (length > (png_uint_32)65535L)
+ {
+ png_warning(png_ptr, "tEXt chunk too large to fit in memory");
+ skip = length - (png_uint_32)65535L;
+ length = (png_uint_32)65535L;
+ }
+#endif
+
+ key = (png_charp)png_malloc(png_ptr, length + 1);
+ slength = (png_size_t)length;
+ png_crc_read(png_ptr, (png_bytep)key, slength);
+
+ if (png_crc_finish(png_ptr, skip))
+ {
+ png_free(png_ptr, key);
+ return;
+ }
+
+ key[slength] = 0x00;
+
+ for (text = key; *text; text++)
+ /* empty loop to find end of key */ ;
+
+ if (text != key + slength)
+ text++;
+
+ text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
+ text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
+ text_ptr->key = key;
+ text_ptr->text = text;
+
+ png_set_text(png_ptr, info_ptr, text_ptr, 1);
+
+ png_free(png_ptr, text_ptr);
+}
+#endif
+
+#if defined(PNG_READ_zTXt_SUPPORTED)
+/* note: this does not correctly handle chunks that are > 64K under DOS */
+void
+png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ static char msg[] = "Error decoding zTXt chunk";
+ png_textp text_ptr;
+ png_charp key;
+ png_charp text;
+ int comp_type = PNG_TEXT_COMPRESSION_NONE;
+ png_size_t slength;
+
+ png_debug(1, "in png_handle_zTXt\n");
+
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
+ png_error(png_ptr, "Missing IHDR before zTXt");
+
+ if (png_ptr->mode & PNG_HAVE_IDAT)
+ png_ptr->mode |= PNG_AFTER_IDAT;
+
+#ifdef PNG_MAX_MALLOC_64K
+ /* We will no doubt have problems with chunks even half this size, but
+ there is no hard and fast rule to tell us where to stop. */
+ if (length > (png_uint_32)65535L)
+ {
+ png_warning(png_ptr,"zTXt chunk too large to fit in memory");
+ png_crc_finish(png_ptr, length);
+ return;
+ }
+#endif
+
+ key = (png_charp)png_malloc(png_ptr, length + 1);
+ slength = (png_size_t)length;
+ png_crc_read(png_ptr, (png_bytep)key, slength);
+ if (png_crc_finish(png_ptr, 0))
+ {
+ png_free(png_ptr, key);
+ return;
+ }
+
+ key[slength] = 0x00;
+
+ for (text = key; *text; text++)
+ /* empty loop */ ;
+
+ /* zTXt must have some text after the keyword */
+ if (text == key + slength)
+ {
+ png_warning(png_ptr, "Zero length zTXt chunk");
+ }
+ else if ((comp_type = *(++text)) == PNG_TEXT_COMPRESSION_zTXt)
+ {
+ png_size_t text_size, key_size;
+ text++;
+
+ png_ptr->zstream.next_in = (png_bytep)text;
+ png_ptr->zstream.avail_in = (uInt)(length - (text - key));
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+
+ key_size = (png_size_t)(text - key);
+ text_size = 0;
+ text = NULL;
+
+ while (png_ptr->zstream.avail_in)
+ {
+ int ret;
+
+ ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
+ if (ret != Z_OK && ret != Z_STREAM_END)
+ {
+ if (png_ptr->zstream.msg != NULL)
+ png_warning(png_ptr, png_ptr->zstream.msg);
+ else
+ png_warning(png_ptr, msg);
+ inflateReset(&png_ptr->zstream);
+ png_ptr->zstream.avail_in = 0;
+
+ if (text == NULL)
+ {
+ text_size = key_size + sizeof(msg) + 1;
+ text = (png_charp)png_malloc(png_ptr, (png_uint_32)text_size);
+ png_memcpy(text, key, key_size);
+ }
+
+ text[text_size - 1] = 0x00;
+
+ /* Copy what we can of the error message into the text chunk */
+ text_size = (png_size_t)(slength - (text - key) - 1);
+ text_size = sizeof(msg) > text_size ? text_size : sizeof(msg);
+ png_memcpy(text + key_size, msg, text_size + 1);
+ break;
+ }
+ if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
+ {
+ if (text == NULL)
+ {
+ text = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ + key_size + 1));
+ png_memcpy(text + key_size, png_ptr->zbuf,
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ png_memcpy(text, key, key_size);
+ text_size = key_size + png_ptr->zbuf_size -
+ png_ptr->zstream.avail_out;
+ *(text + text_size) = 0x00;
+ }
+ else
+ {
+ png_charp tmp;
+
+ tmp = text;
+ text = (png_charp)png_malloc(png_ptr, (png_uint_32)(text_size +
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
+ png_memcpy(text, tmp, text_size);
+ png_free(png_ptr, tmp);
+ png_memcpy(text + text_size, png_ptr->zbuf,
+ (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
+ text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
+ *(text + text_size) = 0x00;
+ }
+ if (ret != Z_STREAM_END)
+ {
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ inflateReset(&png_ptr->zstream);
+ png_ptr->zstream.avail_in = 0;
+
+ png_free(png_ptr, key);
+ key = text;
+ text += key_size;
+ }
+ else /* if (comp_type >= PNG_TEXT_COMPRESSION_LAST) */
+ {
+ png_size_t text_size;
+#if !defined(PNG_NO_STDIO)
+ char umsg[50];
+
+ sprintf(umsg, "Unknown zTXt compression type %d", comp_type);
+ png_warning(png_ptr, umsg);
+#else
+ png_warning(png_ptr, "Unknown zTXt compression type");
+#endif
+
+ /* Copy what we can of the error message into the text chunk */
+ text_size = (png_size_t)(slength - (text - key) - 1);
+ text_size = sizeof(msg) > text_size ? text_size : sizeof(msg);
+ png_memcpy(text, msg, text_size + 1);
+ }
+
+ text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
+ text_ptr->compression = comp_type;
+ text_ptr->key = key;
+ text_ptr->text = text;
+
+ png_set_text(png_ptr, info_ptr, text_ptr, 1);
+
+ png_free(png_ptr, text_ptr);
+}
+#endif
+
+/* This function is called when we haven't found a handler for a
+ chunk. If there isn't a problem with the chunk itself (ie bad
+ chunk name, CRC, or a critical chunk), the chunk is silently ignored. */
+void
+png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
+{
+ png_debug(1, "in png_handle_unknown\n");
+
+ /* In the future we can have code here that calls user-supplied
+ * callback functions for unknown chunks before they are ignored or
+ * cause an error.
+ */
+ png_check_chunk_name(png_ptr, png_ptr->chunk_name);
+
+ if (!(png_ptr->chunk_name[0] & 0x20))
+ {
+ png_chunk_error(png_ptr, "unknown critical chunk");
+
+ /* to quiet compiler warnings about unused info_ptr */
+ if (info_ptr == NULL)
+ return;
+ }
+
+ if (png_ptr->mode & PNG_HAVE_IDAT)
+ png_ptr->mode |= PNG_AFTER_IDAT;
+
+ png_crc_finish(png_ptr, length);
+
+}
+
+/* This function is called to verify that a chunk name is valid.
+ This function can't have the "critical chunk check" incorporated
+ into it, since in the future we will need to be able to call user
+ functions to handle unknown critical chunks after we check that
+ the chunk name itself is valid. */
+
+#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
+
+void
+png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
+{
+ png_debug(1, "in png_check_chunk_name\n");
+ if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
+ isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
+ {
+ png_chunk_error(png_ptr, "invalid chunk type");
+ }
+}
+
+/* Combines the row recently read in with the existing pixels in the
+ row. This routine takes care of alpha and transparency if requested.
+ This routine also handles the two methods of progressive display
+ of interlaced images, depending on the mask value.
+ The mask value describes which pixels are to be combined with
+ the row. The pattern always repeats every 8 pixels, so just 8
+ bits are needed. A one indicates the pixel is to be combined,
+ a zero indicates the pixel is to be skipped. This is in addition
+ to any alpha or transparency value associated with the pixel. If
+ you want all pixels to be combined, pass 0xff (255) in mask. */
+void
+#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
+png_combine_row_c
+#else
+png_combine_row
+#endif /* PNG_HAVE_ASSEMBLER_COMBINE_ROW */
+ (png_structp png_ptr, png_bytep row, int mask)
+{
+ png_debug(1,"in png_combine_row\n");
+ if (mask == 0xff)
+ {
+ png_memcpy(row, png_ptr->row_buf + 1,
+ (png_size_t)((png_ptr->width *
+ png_ptr->row_info.pixel_depth + 7) >> 3));
+ }
+ else
+ {
+ switch (png_ptr->row_info.pixel_depth)
+ {
+ case 1:
+ {
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
+ int s_inc, s_start, s_end;
+ int m = 0x80;
+ int shift;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 7;
+ s_inc = 1;
+ }
+ else
+#endif
+ {
+ s_start = 7;
+ s_end = 0;
+ s_inc = -1;
+ }
+
+ shift = s_start;
+
+ for (i = 0; i < row_width; i++)
+ {
+ if (m & mask)
+ {
+ int value;
+
+ value = (*sp >> shift) & 0x1;
+ *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+ case 2:
+ {
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
+ int s_start, s_end, s_inc;
+ int m = 0x80;
+ int shift;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
+ int value;
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 6;
+ s_inc = 2;
+ }
+ else
+#endif
+ {
+ s_start = 6;
+ s_end = 0;
+ s_inc = -2;
+ }
+
+ shift = s_start;
+
+ for (i = 0; i < row_width; i++)
+ {
+ if (m & mask)
+ {
+ value = (*sp >> shift) & 0x3;
+ *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+ case 4:
+ {
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
+ int s_start, s_end, s_inc;
+ int m = 0x80;
+ int shift;
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
+ int value;
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 4;
+ s_inc = 4;
+ }
+ else
+#endif
+ {
+ s_start = 4;
+ s_end = 0;
+ s_inc = -4;
+ }
+ shift = s_start;
+
+ for (i = 0; i < row_width; i++)
+ {
+ if (m & mask)
+ {
+ value = (*sp >> shift) & 0xf;
+ *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+ default:
+ {
+ png_bytep sp = png_ptr->row_buf + 1;
+ png_bytep dp = row;
+ png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ png_uint_32 i;
+ png_uint_32 row_width = png_ptr->width;
+ png_byte m = 0x80;
+
+
+ for (i = 0; i < row_width; i++)
+ {
+ if (m & mask)
+ {
+ png_memcpy(dp, sp, pixel_bytes);
+ }
+
+ sp += pixel_bytes;
+ dp += pixel_bytes;
+
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+ }
+ }
+}
+
+#if defined(PNG_READ_INTERLACING_SUPPORTED)
+void
+#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
+png_do_read_interlace_c
+#else
+png_do_read_interlace
+#endif /* PNG_HAVE_ASSEMBLER_READ_INTERLACE */
+ (png_row_infop row_info, png_bytep row, int pass,
+ png_uint_32 transformations)
+{
+ png_debug(1,"in png_do_read_interlace\n");
+ if (row != NULL && row_info != NULL)
+ {
+ png_uint_32 final_width;
+
+ final_width = row_info->width * png_pass_inc[pass];
+
+ switch (row_info->pixel_depth)
+ {
+ case 1:
+ {
+ png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
+ png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ int jstop = png_pass_inc[pass];
+ png_byte v;
+ png_uint_32 i;
+ int j;
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (int)((row_info->width + 7) & 7);
+ dshift = (int)((final_width + 7) & 7);
+ s_start = 7;
+ s_end = 0;
+ s_inc = -1;
+ }
+ else
+#endif
+ {
+ sshift = 7 - (int)((row_info->width + 7) & 7);
+ dshift = 7 - (int)((final_width + 7) & 7);
+ s_start = 0;
+ s_end = 7;
+ s_inc = 1;
+ }
+
+ for (i = 0; i < row_info->width; i++)
+ {
+ v = (png_byte)((*sp >> sshift) & 0x1);
+ for (j = 0; j < jstop; j++)
+ {
+ *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+ case 2:
+ {
+ png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
+ png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ int jstop = png_pass_inc[pass];
+ png_uint_32 i;
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (int)(((row_info->width + 3) & 3) << 1);
+ dshift = (int)(((final_width + 3) & 3) << 1);
+ s_start = 6;
+ s_end = 0;
+ s_inc = -2;
+ }
+ else
+#endif
+ {
+ sshift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
+ dshift = (int)((3 - ((final_width + 3) & 3)) << 1);
+ s_start = 0;
+ s_end = 6;
+ s_inc = 2;
+ }
+
+ for (i = 0; i < row_info->width; i++)
+ {
+ png_byte v;
+ int j;
+
+ v = (png_byte)((*sp >> sshift) & 0x3);
+ for (j = 0; j < jstop; j++)
+ {
+ *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+ case 4:
+ {
+ png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
+ png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ png_uint_32 i;
+ int jstop = png_pass_inc[pass];
+
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (int)(((row_info->width + 1) & 1) << 2);
+ dshift = (int)(((final_width + 1) & 1) << 2);
+ s_start = 4;
+ s_end = 0;
+ s_inc = -4;
+ }
+ else
+#endif
+ {
+ sshift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
+ dshift = (int)((1 - ((final_width + 1) & 1)) << 2);
+ s_start = 0;
+ s_end = 4;
+ s_inc = 4;
+ }
+
+ for (i = 0; i < row_info->width; i++)
+ {
+ png_byte v = (png_byte)((*sp >> sshift) & 0xf);
+ int j;
+
+ for (j = 0; j < jstop; j++)
+ {
+ *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+ default:
+ {
+ png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
+ png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
+ png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
+
+ int jstop = png_pass_inc[pass];
+ png_uint_32 i;
+
+ for (i = 0; i < row_info->width; i++)
+ {
+ png_byte v[8];
+ int j;
+
+ png_memcpy(v, sp, pixel_bytes);
+ for (j = 0; j < jstop; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sp -= pixel_bytes;
+ }
+ break;
+ }
+ }
+ row_info->width = final_width;
+ row_info->rowbytes = ((final_width *
+ (png_uint_32)row_info->pixel_depth + 7) >> 3);
+ }
+}
+#endif
+
+void
+#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+png_read_filter_row_c
+#else
+png_read_filter_row
+#endif /* PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */
+ (png_structp png_ptr, png_row_infop row_info, png_bytep row,
+ png_bytep prev_row, int filter)
+{
+ png_debug(1, "in png_read_filter_row\n");
+ png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter);
+ switch (filter)
+ {
+ case PNG_FILTER_VALUE_NONE:
+ break;
+ case PNG_FILTER_VALUE_SUB:
+ {
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_bytep rp = row + bpp;
+ png_bytep lp = row;
+
+ for (i = bpp; i < istop; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
+ rp++;
+ }
+ break;
+ }
+ case PNG_FILTER_VALUE_UP:
+ {
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+
+ for (i = 0; i < istop; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
+ rp++;
+ }
+ break;
+ }
+ case PNG_FILTER_VALUE_AVG:
+ {
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_uint_32 istop = row_info->rowbytes - bpp;
+
+ for (i = 0; i < bpp; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) +
+ ((int)(*pp++) / 2 )) & 0xff);
+ rp++;
+ }
+
+ for (i = 0; i < istop; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) +
+ (int)(*pp++ + *lp++) / 2 ) & 0xff);
+ rp++;
+ }
+ break;
+ }
+ case PNG_FILTER_VALUE_PAETH:
+ {
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_bytep cp = prev_row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_uint_32 istop=row_info->rowbytes - bpp;
+
+ for (i = 0; i < bpp; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
+ rp++;
+ }
+
+ for (i = 0; i < istop; i++) /* use leftover rp,pp */
+ {
+ int a, b, c, pa, pb, pc, p;
+
+ a = *lp++;
+ b = *pp++;
+ c = *cp++;
+
+ p = b - c;
+ pc = a - c;
+
+#ifdef PNG_USE_ABS
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
+#else
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
+#endif
+
+ /*
+ if (pa <= pb && pa <= pc)
+ p = a;
+ else if (pb <= pc)
+ p = b;
+ else
+ p = c;
+ */
+
+ p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+
+ *rp = (png_byte)(((int)(*rp) + p) & 0xff);
+ rp++;
+ }
+ break;
+ }
+ default:
+ png_warning(png_ptr, "Ignoring bad adaptive filter type");
+ *row=0;
+ break;
+ }
+}
+
+void
+png_read_finish_row(png_structp png_ptr)
+{
+ png_debug(1, "in png_read_finish_row\n");
+ png_ptr->row_number++;
+ if (png_ptr->row_number < png_ptr->num_rows)
+ return;
+
+ if (png_ptr->interlaced)
+ {
+ png_ptr->row_number = 0;
+ png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
+ do
+ {
+ png_ptr->pass++;
+ if (png_ptr->pass >= 7)
+ break;
+ png_ptr->iwidth = (png_ptr->width +
+ png_pass_inc[png_ptr->pass] - 1 -
+ png_pass_start[png_ptr->pass]) /
+ png_pass_inc[png_ptr->pass];
+ png_ptr->irowbytes = ((png_ptr->iwidth *
+ (png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
+
+ if (!(png_ptr->transformations & PNG_INTERLACE))
+ {
+ png_ptr->num_rows = (png_ptr->height +
+ png_pass_yinc[png_ptr->pass] - 1 -
+ png_pass_ystart[png_ptr->pass]) /
+ png_pass_yinc[png_ptr->pass];
+ if (!(png_ptr->num_rows))
+ continue;
+ }
+ else /* if (png_ptr->transformations & PNG_INTERLACE) */
+ break;
+ } while (png_ptr->iwidth == 0);
+
+ if (png_ptr->pass < 7)
+ return;
+ }
+
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
+ {
+ char extra;
+ int ret;
+
+ png_ptr->zstream.next_out = (Byte *)&extra;
+ png_ptr->zstream.avail_out = (uInt)1;
+ for(;;)
+ {
+ 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_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");
+
+ if (!(png_ptr->zstream.avail_out))
+ png_error(png_ptr, "Extra compressed data");
+
+ }
+ png_ptr->zstream.avail_out = 0;
+ }
+
+ if (png_ptr->idat_size || png_ptr->zstream.avail_in)
+ png_error(png_ptr, "Extra compression data");
+
+ inflateReset(&png_ptr->zstream);
+
+ png_ptr->mode |= PNG_AFTER_IDAT;
+}
+
+void
+png_read_start_row(png_structp png_ptr)
+{
+ int max_pixel_depth;
+ png_uint_32 row_bytes;
+
+ png_debug(1, "in png_read_start_row\n");
+ png_ptr->zstream.avail_in = 0;
+ png_init_read_transformations(png_ptr);
+ if (png_ptr->interlaced)
+ {
+ if (!(png_ptr->transformations & PNG_INTERLACE))
+ png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
+ png_pass_ystart[0]) / png_pass_yinc[0];
+ else
+ png_ptr->num_rows = png_ptr->height;
+
+ png_ptr->iwidth = (png_ptr->width +
+ png_pass_inc[png_ptr->pass] - 1 -
+ png_pass_start[png_ptr->pass]) /
+ png_pass_inc[png_ptr->pass];
+
+ row_bytes = ((png_ptr->iwidth *
+ (png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
+ png_ptr->irowbytes = (png_size_t)row_bytes;
+ if((png_uint_32)png_ptr->irowbytes != row_bytes)
+ png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
+ }
+ else
+ {
+ png_ptr->num_rows = png_ptr->height;
+ png_ptr->iwidth = png_ptr->width;
+ png_ptr->irowbytes = png_ptr->rowbytes + 1;
+ }
+ max_pixel_depth = png_ptr->pixel_depth;
+
+#if defined(PNG_READ_PACK_SUPPORTED)
+ if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
+ max_pixel_depth = 8;
+#endif
+
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ if (png_ptr->transformations & PNG_EXPAND)
+ {
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (png_ptr->num_trans)
+ max_pixel_depth = 32;
+ else
+ max_pixel_depth = 24;
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ if (max_pixel_depth < 8)
+ max_pixel_depth = 8;
+ if (png_ptr->num_trans)
+ max_pixel_depth *= 2;
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ if (png_ptr->num_trans)
+ {
+ max_pixel_depth *= 4;
+ max_pixel_depth /= 3;
+ }
+ }
+ }
+#endif
+
+#if defined(PNG_READ_FILLER_SUPPORTED)
+ if (png_ptr->transformations & (PNG_FILLER))
+ {
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ max_pixel_depth = 32;
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ if (max_pixel_depth <= 8)
+ max_pixel_depth = 16;
+ else
+ max_pixel_depth = 32;
+ }
+ else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ if (max_pixel_depth <= 32)
+ max_pixel_depth = 32;
+ else
+ max_pixel_depth = 64;
+ }
+ }
+#endif
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ if (png_ptr->transformations & PNG_GRAY_TO_RGB)
+ {
+ if (
+#if defined(PNG_READ_EXPAND_SUPPORTED)
+ (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
+#endif
+#if defined(PNG_READ_FILLER_SUPPORTED)
+ (png_ptr->transformations & (PNG_FILLER)) ||
+#endif
+ png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ {
+ if (max_pixel_depth <= 16)
+ max_pixel_depth = 32;
+ else
+ max_pixel_depth = 64;
+ }
+ else
+ {
+ if (max_pixel_depth <= 8)
+ max_pixel_depth = 24;
+ else
+ max_pixel_depth = 48;
+ }
+ }
+#endif
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ if(png_ptr->transformations & PNG_USER_TRANSFORM)
+ {
+ int user_pixel_depth=png_ptr->user_transform_depth*
+ png_ptr->user_transform_channels;
+ if(user_pixel_depth > max_pixel_depth)
+ max_pixel_depth=user_pixel_depth;
+ }
+#endif
+
+ /* align the width on the next larger 8 pixels. Mainly used
+ for interlacing */
+ row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
+ /* calculate the maximum bytes needed, adding a byte and a pixel
+ for safety's sake */
+ row_bytes = ((row_bytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
+ 1 + ((max_pixel_depth + 7) >> 3);
+#ifdef PNG_MAX_MALLOC_64K
+ if (row_bytes > (png_uint_32)65536L)
+ png_error(png_ptr, "This image requires a row greater than 64KB");
+#endif
+ png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, row_bytes);
+
+#ifdef PNG_MAX_MALLOC_64K
+ if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
+ png_error(png_ptr, "This image requires a row greater than 64KB");
+#endif
+ png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
+ png_ptr->rowbytes + 1));
+
+ png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
+
+ png_debug1(3, "width = %d,\n", png_ptr->width);
+ png_debug1(3, "height = %d,\n", png_ptr->height);
+ png_debug1(3, "iwidth = %d,\n", png_ptr->iwidth);
+ png_debug1(3, "num_rows = %d\n", png_ptr->num_rows);
+ png_debug1(3, "rowbytes = %d,\n", png_ptr->rowbytes);
+ png_debug1(3, "irowbytes = %d,\n", png_ptr->irowbytes);
+
+ png_ptr->flags |= PNG_FLAG_ROW_INIT;
+}
diff --git a/osframework/source/ImageLib/png/pngset.c b/osframework/source/ImageLib/png/pngset.c
new file mode 100644
index 0000000..b2e5f6c
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngset.c
@@ -0,0 +1,391 @@
+
+/* pngset.c - storage of image information into info struct
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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_MAX_UINT/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).45455;
+ 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 ||
+ (png_ptr->flags & PNG_FLAG_WROTE_tIME))
+ 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
+
+#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED)
+void
+png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
+{
+ png_debug1(1, "in png_permit_empty_plte\n", "");
+ if (png_ptr == NULL)
+ return;
+ png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted;
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngtest.c b/osframework/source/ImageLib/png/pngtest.c
new file mode 100644
index 0000000..66ce0a1
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngtest.c
@@ -0,0 +1,1178 @@
+
+/* pngtest.c - a simple test program to test libpng
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ *
+ * This program reads in a PNG image, writes it out again, and then
+ * compares the two files. If the files are identical, this shows that
+ * the basic chunk handling, filtering, and (de)compression code is working
+ * properly. It does not currently test all of the transforms, although
+ * it probably should.
+ *
+ * The program will report "FAIL" in certain legitimate cases:
+ * 1) when the compression level or filter selection method is changed.
+ * 2) when the chunk size is not 8K.
+ * 3) unknown ancillary chunks exist in the input file.
+ * 4) others not listed here...
+ * In these cases, it is best to check with another tool such as "pngcheck"
+ * to see what the differences between the two images are.
+ *
+ * If a filename is given on the command-line, then this file is used
+ * for the input, rather than the default "pngtest.png". This allows
+ * testing a wide variety of files easily. You can also test a number
+ * of files at once by typing "pngtest -m file1.png file2.png ..."
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
+#ifndef PNG_DEBUG
+#define PNG_DEBUG 0
+#endif
+
+/* Turn on CPU timing
+#define PNGTEST_TIMING
+*/
+
+#ifdef PNGTEST_TIMING
+static float t_start, t_stop, t_decode, t_encode, t_misc;
+#include <time.h>
+#endif
+
+#include "png.h"
+
+#ifdef PNGTEST_TIMING
+static float t_start, t_stop, t_decode, t_encode, t_misc;
+#if !defined(PNG_READ_tIME_SUPPORTED) && !defined(PNG_WRITE_tIME_SUPPORTED)
+#include <time.h>
+#endif
+#endif
+
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+static int tIME_chunk_present=0;
+static char tIME_string[30] = "no tIME chunk present in file";
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+
+static int verbose = 0;
+
+int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
+
+#ifdef __TURBOC__
+#include <mem.h>
+#endif
+
+/* defined so I can write to a file on gui/windowing platforms */
+/* #define STDERR stderr */
+#define STDERR stdout /* for DOS */
+
+/* example of using row callbacks to make a simple progress meter */
+static int status_pass=1;
+static int status_dots_requested=0;
+static int status_dots=1;
+
+void
+read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
+{
+ if(png_ptr == NULL || row_number > PNG_MAX_UINT) return;
+ if(status_pass != pass)
+ {
+ fprintf(stdout,"\n Pass %d: ",pass);
+ status_pass = pass;
+ status_dots = 31;
+ }
+ status_dots--;
+ if(status_dots == 0)
+ {
+ fprintf(stdout, "\n ");
+ status_dots=30;
+ }
+ fprintf(stdout, "r");
+}
+
+void
+write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
+{
+ if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return;
+ fprintf(stdout, "w");
+}
+
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+/* Example of using user transform callback (we don't transform anything,
+ but merely examine the row filters. We set this to 256 rather than
+ 5 in case illegal filter values are present.) */
+static png_uint_32 filters_used[256];
+void
+count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
+{
+ if(png_ptr != NULL && row_info != NULL)
+ ++filters_used[*(data-1)];
+}
+#endif
+
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+/* example of using user transform callback (we don't transform anything,
+ but merely count the zero samples) */
+
+static png_uint_32 zero_samples;
+
+void
+count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
+{
+ png_bytep dp = data;
+ if(png_ptr == NULL)return;
+
+ /* contents of 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)
+ */
+
+
+ /* counts the number of zero samples (or zero pixels if color_type is 3 */
+
+ if(row_info->color_type == 0 || row_info->color_type == 3)
+ {
+ int pos=0;
+ png_uint_32 n, nstop;
+ for (n=0, nstop=row_info->width; n<nstop; n++)
+ {
+ if(row_info->bit_depth == 1)
+ {
+ if(((*dp << pos++ )& 0x80) == 0) zero_samples++;
+ if(pos == 8)
+ {
+ pos = 0;
+ dp++;
+ }
+ }
+ if(row_info->bit_depth == 2)
+ {
+ if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++;
+ if(pos == 8)
+ {
+ pos = 0;
+ dp++;
+ }
+ }
+ if(row_info->bit_depth == 4)
+ {
+ if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++;
+ if(pos == 8)
+ {
+ pos = 0;
+ dp++;
+ }
+ }
+ if(row_info->bit_depth == 8)
+ if(*dp++ == 0) zero_samples++;
+ if(row_info->bit_depth == 16)
+ {
+ if((*dp | *(dp+1)) == 0) zero_samples++;
+ dp+=2;
+ }
+ }
+ }
+ else /* other color types */
+ {
+ png_uint_32 n, nstop;
+ int channel;
+ int color_channels = row_info->channels;
+ if(row_info->color_type > 3)color_channels--;
+
+ for (n=0, nstop=row_info->width; n<nstop; n++)
+ {
+ for (channel = 0; channel < color_channels; channel++)
+ {
+ if(row_info->bit_depth == 8)
+ if(*dp++ == 0) zero_samples++;
+ if(row_info->bit_depth == 16)
+ {
+ if((*dp | *(dp+1)) == 0) zero_samples++;
+ dp+=2;
+ }
+ }
+ if(row_info->color_type > 3)
+ {
+ dp++;
+ if(row_info->bit_depth == 16)dp++;
+ }
+ }
+ }
+}
+#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
+
+static int wrote_question = 0;
+
+#if defined(PNG_NO_STDIO)
+/* START of code to validate stdio-free compilation */
+/* These copies of the default read/write functions come from pngrio.c and */
+/* pngwio.c. They allow "don't include stdio" testing of the library. */
+/* 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 (check != length)
+ {
+ png_error(png_ptr, "read Error");
+ }
+}
+#endif /* USE_FAR_KEYWORD */
+
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+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
+
+/* 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 /* USE_FAR_KEYWORD */
+
+/* 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 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)
+{
+ PNG_CONST char *name = "UNKNOWN (ERROR!)";
+ if (png_ptr != NULL && png_ptr->error_ptr != NULL)
+ name = png_ptr->error_ptr;
+ fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
+}
+
+/* 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)
+{
+ png_default_warning(png_ptr, message);
+ /* We can return because png_error calls the default handler, which is
+ * actually OK in this case. */
+}
+#endif /* PNG_NO_STDIO */
+/* END of code to validate stdio-free compilation */
+
+/* START of code to validate memory allocation and deallocation */
+#ifdef PNG_USER_MEM_SUPPORTED
+
+/* 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.
+
+ This piece of code can be compiled to validate max 64K allocations
+ by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
+typedef struct memory_information {
+ png_uint_32 size;
+ png_voidp pointer;
+ struct memory_information FAR *next;
+} memory_information;
+typedef memory_information FAR *memory_infop;
+
+static memory_infop pinformation = NULL;
+static int current_allocation = 0;
+static int maximum_allocation = 0;
+
+extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
+extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
+ png_voidp ptr));
+
+png_voidp
+png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
+
+ /* png_malloc has already tested for NULL; png_create_struct calls
+ png_debug_malloc directly, with png_ptr == NULL which is OK */
+
+ if (size == 0)
+ return (png_voidp)(NULL);
+
+ /* This calls the library allocator twice, once to get the requested
+ buffer and once to get a new free list entry. */
+ {
+ memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
+ pinfo->size = size;
+ current_allocation += size;
+ if (current_allocation > maximum_allocation)
+ maximum_allocation = current_allocation;
+ pinfo->pointer = png_malloc_default(png_ptr, size);
+ pinfo->next = pinformation;
+ pinformation = pinfo;
+ /* Make sure the caller isn't assuming zeroed memory. */
+ png_memset(pinfo->pointer, 0xdd, pinfo->size);
+ return (png_voidp)(pinfo->pointer);
+ }
+}
+
+/* Free a pointer. It is removed from the list at the same time. */
+void
+png_debug_free(png_structp png_ptr, png_voidp ptr)
+{
+ if (png_ptr == NULL)
+ fprintf(STDERR, "NULL pointer to png_debug_free.\n");
+ if (ptr == 0) {
+#if 0 /* This happens all the time. */
+ fprintf(STDERR, "WARNING: freeing NULL pointer\n");
+#endif
+ return;
+ }
+
+ /* Unlink the element from the list. */
+ {
+ memory_infop FAR *ppinfo = &pinformation;
+ for (;;) {
+ memory_infop pinfo = *ppinfo;
+ if (pinfo->pointer == ptr) {
+ *ppinfo = pinfo->next;
+ current_allocation -= pinfo->size;
+ if (current_allocation < 0)
+ fprintf(STDERR, "Duplicate free of memory\n");
+ /* We must free the list element too, but first kill
+ the memory that is to be freed. */
+ memset(ptr, 0x55, pinfo->size);
+ png_free_default(png_ptr, pinfo);
+ break;
+ }
+ if (pinfo->next == NULL) {
+ fprintf(STDERR, "Pointer %x not found\n", ptr);
+ break;
+ }
+ ppinfo = &pinfo->next;
+ }
+ }
+
+ /* Finally free the data. */
+ png_free_default(png_ptr, ptr);
+}
+#endif /* PNG_USER_MEM_SUPPORTED */
+/* END of code to test memory allocation/deallocation */
+
+/* Test one file */
+int
+test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
+{
+ static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
+ png_structp read_ptr, write_ptr;
+ png_infop read_info_ptr, write_info_ptr, end_info_ptr;
+ png_bytep row_buf;
+ png_uint_32 y;
+ png_uint_32 width, height;
+ int num_pass, pass;
+ int bit_depth, color_type;
+#ifdef USE_FAR_KEYWORD
+ jmp_buf jmpbuf;
+#endif
+
+ char inbuf[256], outbuf[256];
+
+ row_buf = (png_bytep)NULL;
+
+ if ((fpin = fopen(inname, "rb")) == NULL)
+ {
+ fprintf(STDERR, "Could not find input file %s\n", inname);
+ return (1);
+ }
+
+ if ((fpout = fopen(outname, "wb")) == NULL)
+ {
+ fprintf(STDERR, "Could not open output file %s\n", outname);
+ fclose(fpin);
+ return (1);
+ }
+
+ png_debug(0, "Allocating read and write structures\n");
+#ifdef PNG_USER_MEM_SUPPORTED
+ read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
+ (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
+ (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
+#else
+ read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
+ (png_error_ptr)NULL, (png_error_ptr)NULL);
+#endif
+#if defined(PNG_NO_STDIO)
+ png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
+ png_default_warning);
+#endif
+#ifdef PNG_USER_MEM_SUPPORTED
+ write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
+ (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
+ (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
+#else
+ write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
+ (png_error_ptr)NULL, (png_error_ptr)NULL);
+#endif
+#if defined(PNG_NO_STDIO)
+ png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
+ png_default_warning);
+#endif
+ png_debug(0, "Allocating read_info, write_info and end_info structures\n");
+ read_info_ptr = png_create_info_struct(read_ptr);
+ write_info_ptr = png_create_info_struct(write_ptr);
+ end_info_ptr = png_create_info_struct(read_ptr);
+#ifdef PNG_USER_MEM_SUPPORTED
+#endif
+
+ png_debug(0, "Setting jmpbuf for read struct\n");
+#ifdef USE_FAR_KEYWORD
+ if (setjmp(jmpbuf))
+#else
+ if (setjmp(read_ptr->jmpbuf))
+#endif
+ {
+ fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
+ png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
+ png_destroy_write_struct(&write_ptr, &write_info_ptr);
+ fclose(fpin);
+ fclose(fpout);
+ return (1);
+ }
+#ifdef USE_FAR_KEYWORD
+ png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
+#endif
+
+ png_debug(0, "Setting jmpbuf for write struct\n");
+#ifdef USE_FAR_KEYWORD
+ if (setjmp(jmpbuf))
+#else
+ if (setjmp(write_ptr->jmpbuf))
+#endif
+ {
+ fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
+ png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
+ png_destroy_write_struct(&write_ptr, &write_info_ptr);
+ fclose(fpin);
+ fclose(fpout);
+ return (1);
+ }
+#ifdef USE_FAR_KEYWORD
+ png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
+#endif
+
+ png_debug(0, "Initializing input and output streams\n");
+#if !defined(PNG_NO_STDIO)
+ png_init_io(read_ptr, fpin);
+ png_init_io(write_ptr, fpout);
+#else
+ png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
+ png_set_write_fn(write_ptr, (png_voidp)fpout, png_default_write_data,
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+ png_default_flush);
+#else
+ NULL);
+#endif
+#endif
+ if(status_dots_requested == 1)
+ {
+ png_set_write_status_fn(write_ptr, write_row_callback);
+ png_set_read_status_fn(read_ptr, read_row_callback);
+ }
+ else
+ {
+ png_set_write_status_fn(write_ptr, NULL);
+ png_set_read_status_fn(read_ptr, NULL);
+ }
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ {
+ int i;
+ for(i=0; i<256; i++)
+ filters_used[i]=0;
+ png_set_read_user_transform_fn(read_ptr, count_filters);
+ }
+#endif
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+ zero_samples=0;
+ png_set_write_user_transform_fn(write_ptr, count_zero_samples);
+#endif
+
+ png_debug(0, "Reading info struct\n");
+ png_read_info(read_ptr, read_info_ptr);
+
+ png_debug(0, "Transferring info struct\n");
+ {
+ int interlace_type, compression_type, filter_type;
+
+ if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
+ &color_type, &interlace_type, &compression_type, &filter_type))
+ {
+ png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ color_type, interlace_type, compression_type, filter_type);
+#else
+ color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
+#endif
+ }
+ }
+#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
+ {
+ png_color_16p background;
+
+ if (png_get_bKGD(read_ptr, read_info_ptr, &background))
+ {
+ png_set_bKGD(write_ptr, write_info_ptr, background);
+ }
+ }
+#endif
+#if defined(PNG_READ_cHRM_SUPPORTED) && defined(PNG_WRITE_cHRM_SUPPORTED)
+ {
+ double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
+
+ if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
+ &red_y, &green_x, &green_y, &blue_x, &blue_y))
+ {
+ png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
+ red_y, green_x, green_y, blue_x, blue_y);
+ }
+ }
+#endif
+#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_WRITE_gAMA_SUPPORTED)
+ {
+ double gamma;
+
+ if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
+ {
+ png_set_gAMA(write_ptr, write_info_ptr, gamma);
+ }
+ }
+#endif
+#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
+ {
+ int intent;
+
+ if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
+ {
+ png_set_sRGB(write_ptr, write_info_ptr, intent);
+ }
+ }
+#endif
+#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED)
+ {
+ png_uint_16p hist;
+
+ if (png_get_hIST(read_ptr, read_info_ptr, &hist))
+ {
+ png_set_hIST(write_ptr, write_info_ptr, hist);
+ }
+ }
+#endif
+#if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED)
+ {
+ png_uint_32 offset_x, offset_y;
+ int unit_type;
+
+ if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
+ {
+ png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
+ }
+ }
+#endif
+#if defined(PNG_READ_pCAL_SUPPORTED) && defined(PNG_WRITE_pCAL_SUPPORTED)
+ {
+ png_charp purpose, units;
+ png_charpp params;
+ png_int_32 X0, X1;
+ int type, nparams;
+
+ if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
+ &nparams, &units, &params))
+ {
+ png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
+ nparams, units, params);
+ }
+ }
+#endif
+#if defined(PNG_READ_pHYs_SUPPORTED) && defined(PNG_WRITE_pHYs_SUPPORTED)
+ {
+ png_uint_32 res_x, res_y;
+ int unit_type;
+
+ if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
+ {
+ png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
+ }
+ }
+#endif
+ {
+ png_colorp palette;
+ int num_palette;
+
+ if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
+ {
+ png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
+ }
+ }
+#if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED)
+ {
+ png_color_8p sig_bit;
+
+ if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
+ {
+ png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
+ }
+ }
+#endif
+#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
+ (defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
+ {
+ png_textp text_ptr;
+ int num_text;
+
+ if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
+ {
+ png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
+ png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
+ }
+ }
+#endif
+#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
+ {
+ png_timep mod_time;
+
+ if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
+ {
+ png_set_tIME(write_ptr, write_info_ptr, mod_time);
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+ /* we have to use png_strcpy instead of "=" because the string
+ pointed to by png_convert_to_rfc1123() gets free'ed before
+ we use it */
+ png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
+ tIME_chunk_present++;
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+ }
+ }
+#endif
+#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
+ {
+ png_bytep trans;
+ int num_trans;
+ png_color_16p trans_values;
+
+ if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
+ &trans_values))
+ {
+ png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
+ trans_values);
+ }
+ }
+#endif
+
+ png_debug(0, "\nWriting info struct\n");
+ png_write_info(write_ptr, write_info_ptr);
+
+ png_debug(0, "\nAllocating row buffer \n");
+ row_buf = (png_bytep)png_malloc(read_ptr,
+ png_get_rowbytes(read_ptr, read_info_ptr));
+ if (row_buf == NULL)
+ {
+ fprintf(STDERR, "No memory to allocate row buffer\n");
+ png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
+ png_destroy_write_struct(&write_ptr, &write_info_ptr);
+ fclose(fpin);
+ fclose(fpout);
+ return (1);
+ }
+ png_debug(0, "Writing row data\n");
+
+#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
+ defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ num_pass = png_set_interlace_handling(read_ptr);
+ png_set_interlace_handling(write_ptr);
+#else
+ num_pass=1;
+#endif
+
+#ifdef PNGTEST_TIMING
+ t_stop = (float)clock();
+ t_misc += (t_stop - t_start);
+ t_start = t_stop;
+#endif
+ for (pass = 0; pass < num_pass; pass++)
+ {
+ png_debug1(0, "Writing row data for pass %d\n",pass);
+ for (y = 0; y < height; y++)
+ {
+ png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
+#ifdef PNGTEST_TIMING
+ t_stop = (float)clock();
+ t_decode += (t_stop - t_start);
+ t_start = t_stop;
+#endif
+ png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
+#ifdef PNGTEST_TIMING
+ t_stop = (float)clock();
+ t_encode += (t_stop - t_start);
+ t_start = t_stop;
+#endif
+ }
+ }
+
+ png_debug(0, "Reading and writing end_info data\n");
+ png_read_end(read_ptr, end_info_ptr);
+ png_write_end(write_ptr, end_info_ptr);
+
+#ifdef PNG_EASY_ACCESS_SUPPORTED
+ if(verbose)
+ {
+ png_uint_32 iwidth, iheight;
+ iwidth = png_get_image_width(write_ptr, write_info_ptr);
+ iheight = png_get_image_height(write_ptr, write_info_ptr);
+ fprintf(STDERR, "Image width = %lu, height = %lu\n",
+ iwidth, iheight);
+ }
+#endif
+
+ png_debug(0, "Destroying data structs\n");
+ png_free(read_ptr, row_buf);
+ png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
+ png_destroy_write_struct(&write_ptr, &write_info_ptr);
+
+ fclose(fpin);
+ fclose(fpout);
+
+ png_debug(0, "Opening files for comparison\n");
+ if ((fpin = fopen(inname, "rb")) == NULL)
+ {
+ fprintf(STDERR, "Could not find file %s\n", inname);
+ return (1);
+ }
+
+ if ((fpout = fopen(outname, "rb")) == NULL)
+ {
+ fprintf(STDERR, "Could not find file %s\n", outname);
+ fclose(fpin);
+ return (1);
+ }
+
+ for(;;)
+ {
+ png_size_t num_in, num_out;
+
+ num_in = fread(inbuf, 1, 1, fpin);
+ num_out = fread(outbuf, 1, 1, fpout);
+
+ if (num_in != num_out)
+ {
+ fprintf(STDERR, "Files %s and %s are of a different size\n",
+ inname, outname);
+ if(wrote_question == 0)
+ {
+ fprintf(STDERR,
+ " Was %s written with the same chunk size (8k),",inname);
+ fprintf(STDERR,
+ " filtering\n heuristic (libpng default), compression");
+ fprintf(STDERR,
+ " level (zlib default)\n and zlib version (%s)?\n\n",
+ ZLIB_VERSION);
+ wrote_question=1;
+ }
+ fclose(fpin);
+ fclose(fpout);
+ return (0);
+ }
+
+ if (!num_in)
+ break;
+
+ if (png_memcmp(inbuf, outbuf, num_in))
+ {
+ fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
+ if(wrote_question == 0)
+ {
+ fprintf(STDERR,
+ " Was %s written with the same chunk size (8k),",inname);
+ fprintf(STDERR,
+ " filtering\n heuristic (libpng default), compression");
+ fprintf(STDERR,
+ " level (zlib default)\n and zlib version (%s)?\n\n",
+ ZLIB_VERSION);
+ wrote_question=1;
+ }
+ fclose(fpin);
+ fclose(fpout);
+ return (0);
+ }
+ }
+
+ fclose(fpin);
+ fclose(fpout);
+
+ return (0);
+}
+
+/* input and output filenames */
+#ifdef RISCOS
+static PNG_CONST char *inname = "pngtest/png";
+static PNG_CONST char *outname = "pngout/png";
+#else
+static PNG_CONST char *inname = "pngtest.png";
+static PNG_CONST char *outname = "pngout.png";
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ int multiple = 0;
+ int ierror = 0;
+
+ fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
+ fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
+ fprintf(STDERR,"%s",png_get_copyright(NULL));
+
+ /* Do some consistency checking on the memory allocation settings, I'm
+ not sure this matters, but it is nice to know, the first of these
+ tests should be impossible because of the way the macros are set
+ in pngconf.h */
+#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
+ fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
+#endif
+ /* I think the following can happen. */
+#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
+ fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
+#endif
+
+ if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
+ {
+ fprintf(STDERR,
+ "Warning: versions are different between png.h and png.c\n");
+ fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
+ fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
+ ++ierror;
+ }
+
+ if (argc > 1)
+ {
+ if (strcmp(argv[1], "-m") == 0)
+ {
+ multiple = 1;
+ status_dots_requested = 0;
+ }
+ else if (strcmp(argv[1], "-mv") == 0 ||
+ strcmp(argv[1], "-vm") == 0 )
+ {
+ multiple = 1;
+ verbose = 1;
+ status_dots_requested = 1;
+ }
+ else if (strcmp(argv[1], "-v") == 0)
+ {
+ verbose = 1;
+ status_dots_requested = 1;
+ inname = argv[2];
+ }
+ else
+ {
+ inname = argv[1];
+ status_dots_requested = 0;
+ }
+ }
+
+ if (!multiple && argc == 3+verbose)
+ outname = argv[2+verbose];
+
+ if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
+ {
+ fprintf(STDERR,
+ "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
+ argv[0], argv[0]);
+ fprintf(STDERR,
+ " reads/writes one PNG file (without -m) or multiple files (-m)\n");
+ fprintf(STDERR,
+ " with -m %s is used as a temporary file\n", outname);
+ exit(1);
+ }
+
+ if (multiple)
+ {
+ int i;
+#ifdef PNG_USER_MEM_SUPPORTED
+ int allocation_now = current_allocation;
+#endif
+ for (i=2; i<argc; ++i)
+ {
+ int k, kerror;
+ fprintf(STDERR, "Testing %s:",argv[i]);
+ kerror = test_one_file(argv[i], outname);
+ if (kerror == 0)
+ {
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+ fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
+#else
+ fprintf(STDERR, " PASS\n");
+#endif
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ for (k=0; k<256; k++)
+ if(filters_used[k])
+ fprintf(STDERR, " Filter %d was used %lu times\n",
+ k,filters_used[k]);
+#endif
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+ if(tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n",tIME_string);
+ tIME_chunk_present = 0;
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+ }
+ else
+ {
+ fprintf(STDERR, " FAIL\n");
+ ierror += kerror;
+ }
+#ifdef PNG_USER_MEM_SUPPORTED
+ if (allocation_now != current_allocation)
+ fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
+ current_allocation-allocation_now);
+ if (current_allocation != 0) {
+ memory_infop pinfo = pinformation;
+
+ fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
+ current_allocation);
+ while (pinfo != NULL) {
+ fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
+ pinfo = pinfo->next;
+ }
+ }
+#endif
+ }
+#ifdef PNG_USER_MEM_SUPPORTED
+ fprintf(STDERR, " Current memory allocation: %d bytes\n",
+ current_allocation);
+ fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
+ maximum_allocation);
+#endif
+ }
+ else
+ {
+ int i;
+ for (i=0; i<3; ++i) {
+ int kerror;
+#ifdef PNG_USER_MEM_SUPPORTED
+ int allocation_now = current_allocation;
+#endif
+ if (i == 1) status_dots_requested = 1;
+ else if(verbose == 0)status_dots_requested = 0;
+ if (i == 0 || verbose == 1 || ierror != 0)
+ fprintf(STDERR, "Testing %s:",inname);
+ kerror = test_one_file(inname, outname);
+ if(kerror == 0)
+ {
+ if(verbose == 1 || i == 2)
+ {
+ int k;
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+ fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
+#else
+ fprintf(STDERR, " PASS\n");
+#endif
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
+ for (k=0; k<256; k++)
+ if(filters_used[k])
+ fprintf(STDERR, " Filter %d was used %lu times\n",
+ k,filters_used[k]);
+#endif
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+ if(tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n",tIME_string);
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+ }
+ }
+ else
+ {
+ if(verbose == 0 && i != 2)
+ fprintf(STDERR, "Testing %s:",inname);
+ fprintf(STDERR, " FAIL\n");
+ ierror += kerror;
+ }
+#ifdef PNG_USER_MEM_SUPPORTED
+ if (allocation_now != current_allocation)
+ fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
+ current_allocation-allocation_now);
+ if (current_allocation != 0) {
+ memory_infop pinfo = pinformation;
+
+ fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
+ current_allocation);
+ while (pinfo != NULL) {
+ fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
+ pinfo = pinfo->next;
+ }
+ }
+#endif
+ }
+#ifdef PNG_USER_MEM_SUPPORTED
+ fprintf(STDERR, " Current memory allocation: %d bytes\n",
+ current_allocation);
+ fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
+ maximum_allocation);
+#endif
+ }
+
+#ifdef PNGTEST_TIMING
+ t_stop = (float)clock();
+ t_misc += (t_stop - t_start);
+ t_start = t_stop;
+ fprintf(STDERR," CPU time used = %.3f seconds",
+ (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
+ fprintf(STDERR," (decoding %.3f,\n",
+ t_decode/(float)CLOCKS_PER_SEC);
+ fprintf(STDERR," encoding %.3f ,",
+ t_encode/(float)CLOCKS_PER_SEC);
+ fprintf(STDERR," other %.3f seconds)\n\n",
+ t_misc/(float)CLOCKS_PER_SEC);
+#endif
+
+ if (ierror == 0)
+ fprintf(STDERR, "libpng passes test\n");
+ else
+ fprintf(STDERR, "libpng FAILS test\n");
+ return (int)(ierror != 0);
+}
+
+/* Generate a compiler error if there is an old png.h in the search path. */
+void
+png_check_pngtest_version
+ (version_1_0_5 png_h_is_not_version_1_0_5)
+{
+ if(png_h_is_not_version_1_0_5 == NULL) return;
+}
diff --git a/osframework/source/ImageLib/png/pngtest.png b/osframework/source/ImageLib/png/pngtest.png
new file mode 100644
index 0000000..f3a6df4
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngtest.png
Binary files differ
diff --git a/osframework/source/ImageLib/png/pngtrans.c b/osframework/source/ImageLib/png/pngtrans.c
new file mode 100644
index 0000000..6253aac
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngtrans.c
@@ -0,0 +1,595 @@
+
+/* pngtrans.c - transforms the data in a row (used by both readers and writers)
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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;
+
+ /* This should probably go in the "do_filler" routine.
+ * I attempted to do that in libpng-1.0.1a but that caused problems
+ * so I restored it in libpng-1.0.2a
+ */
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ {
+ png_ptr->usr_channels = 4;
+ }
+
+ /* Also I added this in libpng-1.0.2a (what happens when we expand
+ * a less-than-8-bit grayscale to GA? */
+
+ if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
+ {
+ png_ptr->usr_channels = 2;
+ }
+}
+#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 */
+
+#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
+ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+void
+png_set_user_transform_info(png_structp png_ptr, png_voidp
+ user_transform_ptr, int user_transform_depth, int user_transform_channels)
+{
+ png_debug(1, "in png_set_user_transform_info\n");
+ png_ptr->user_transform_ptr = user_transform_ptr;
+ png_ptr->user_transform_depth = (png_byte)user_transform_depth;
+ png_ptr->user_transform_channels = (png_byte)user_transform_channels;
+}
+
+/* This function returns a pointer to the user_transform_ptr associated with
+ * the user transform 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_user_transform_ptr(png_structp png_ptr)
+{
+ return ((png_voidp)png_ptr->user_transform_ptr);
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngvcrd.c b/osframework/source/ImageLib/png/pngvcrd.c
new file mode 100644
index 0000000..b7b7630
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngvcrd.c
@@ -0,0 +1,3838 @@
+/* pngvcrd.c - mixed C/assembler version of utilities to read a PNG file
+ *
+ * For Intel x86 CPU and Microsoft Visual C++ compiler
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * For conditions of distribution and use, see copyright notice in png.h
+ * Copyright (c) 1998, Intel Corporation
+ * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
+ *
+ * Contributed by Nirav Chhatrapati, Intel Corporation, 1998
+ * Interface to libpng contributed by Gilles Vollant, 1999
+ *
+ */
+
+#define PNG_INTERNAL
+#include "png.h"
+
+#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
+
+static int mmx_supported=2;
+
+void
+png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info,
+ png_bytep row, png_bytep prev_row, int filter);
+
+static int mmxsupport()
+{
+ int mmx_supported_local = 0;
+ _asm {
+ pushfd //Save Eflag to stack
+ pop eax //Get Eflag from stack into eax
+ mov ecx, eax //Make another copy of Eflag in ecx
+ xor eax, 0x200000 //Toggle ID bit in Eflag [i.e. bit(21)]
+ push eax //Save modified Eflag back to stack
+
+ popfd //Restored modified value back to Eflag reg
+ pushfd //Save Eflag to stack
+ pop eax //Get Eflag from stack
+ xor eax, ecx //Compare the new Eflag with the original Eflag
+ jz NOT_SUPPORTED //If the same, CPUID instruction is not supported,
+ //skip following instructions and jump to
+ //NOT_SUPPORTED label
+
+ xor eax, eax //Set eax to zero
+
+ _asm _emit 0x0f //CPUID instruction (two bytes opcode)
+ _asm _emit 0xa2
+
+ cmp eax, 1 //make sure eax return non-zero value
+ jl NOT_SUPPORTED //If eax is zero, mmx not supported
+
+ xor eax, eax //set eax to zero
+ inc eax //Now increment eax to 1. This instruction is
+ //faster than the instruction "mov eax, 1"
+
+ _asm _emit 0x0f //CPUID instruction
+ _asm _emit 0xa2
+
+ and edx, 0x00800000 //mask out all bits but mmx bit(24)
+ cmp edx, 0 // 0 = mmx not supported
+ jz NOT_SUPPORTED // non-zero = Yes, mmx IS supported
+
+ mov mmx_supported_local, 1 //set return value to 1
+
+NOT_SUPPORTED:
+ mov eax, mmx_supported_local //move return value to eax
+
+ }
+
+ //mmx_supported_local=0; // test code for force don't support MMX
+ //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local);
+
+ return mmx_supported_local;
+}
+
+/* Combines the row recently read in with the previous row.
+ This routine takes care of alpha and transparency if requested.
+ This routine also handles the two methods of progressive display
+ of interlaced images, depending on the mask value.
+ The mask value describes which pixels are to be combined with
+ the row. The pattern always repeats every 8 pixels, so just 8
+ bits are needed. A one indicates the pixel is to be combined; a
+ zero indicates the pixel is to be skipped. This is in addition
+ to any alpha or transparency value associated with the pixel. If
+ you want all pixels to be combined, pass 0xff (255) in mask. */
+
+/* Use this routine for x86 platform - uses faster MMX routine if machine
+ supports MMX */
+
+void
+png_combine_row(png_structp png_ptr, png_bytep row, int mask)
+{
+#ifdef DISABLE_PNGVCRD_COMBINE
+ int save_mmx_supported = mmx_supported;
+#endif
+
+ png_debug(1,"in png_combine_row_asm\n");
+
+#ifdef DISABLE_PNGVCRD_COMBINE
+ if ((png_ptr->transformations & PNG_INTERLACE) && png_ptr->pass != 6)
+ mmx_supported = 0;
+ else
+#endif
+ if (mmx_supported == 2)
+ mmx_supported = mmxsupport();
+
+ if (mask == 0xff)
+ {
+ png_memcpy(row, png_ptr->row_buf + 1,
+ (png_size_t)((png_ptr->width * png_ptr->row_info.pixel_depth + 7) >> 3));
+ }
+ /* GRR: add "else if (mask == 0)" case?
+ * or does png_combine_row() not even get called in that case? */
+ else
+ {
+ switch (png_ptr->row_info.pixel_depth)
+ {
+ case 1:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int s_inc, s_start, s_end;
+ int m;
+ int shift;
+ png_uint_32 i;
+
+ sp = png_ptr->row_buf + 1;
+ dp = row;
+ m = 0x80;
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 7;
+ s_inc = 1;
+ }
+ else
+#endif
+ {
+ s_start = 7;
+ s_end = 0;
+ s_inc = -1;
+ }
+
+ shift = s_start;
+
+ for (i = 0; i < png_ptr->width; i++)
+ {
+ if (m & mask)
+ {
+ int value;
+
+ value = (*sp >> shift) & 0x1;
+ *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+
+ case 2:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int s_start, s_end, s_inc;
+ int m;
+ int shift;
+ png_uint_32 i;
+ int value;
+
+ sp = png_ptr->row_buf + 1;
+ dp = row;
+ m = 0x80;
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 6;
+ s_inc = 2;
+ }
+ else
+#endif
+ {
+ s_start = 6;
+ s_end = 0;
+ s_inc = -2;
+ }
+
+ shift = s_start;
+
+ for (i = 0; i < png_ptr->width; i++)
+ {
+ if (m & mask)
+ {
+ value = (*sp >> shift) & 0x3;
+ *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+
+ case 4:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int s_start, s_end, s_inc;
+ int m;
+ int shift;
+ png_uint_32 i;
+ int value;
+
+ sp = png_ptr->row_buf + 1;
+ dp = row;
+ m = 0x80;
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (png_ptr->transformations & PNG_PACKSWAP)
+ {
+ s_start = 0;
+ s_end = 4;
+ s_inc = 4;
+ }
+ else
+#endif
+ {
+ s_start = 4;
+ s_end = 0;
+ s_inc = -4;
+ }
+ shift = s_start;
+
+ for (i = 0; i < png_ptr->width; i++)
+ {
+ if (m & mask)
+ {
+ value = (*sp >> shift) & 0xf;
+ *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
+ *dp |= (png_byte)(value << shift);
+ }
+
+ if (shift == s_end)
+ {
+ shift = s_start;
+ sp++;
+ dp++;
+ }
+ else
+ shift += s_inc;
+ if (m == 1)
+ m = 0x80;
+ else
+ m >>= 1;
+ }
+ break;
+ }
+
+ case 8:
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ png_uint_32 len;
+ int m;
+ int diff, unmask;
+
+ __int64 mask0=0x0102040810204080;
+
+ if (mmx_supported)
+ {
+ srcptr = png_ptr->row_buf + 1;
+ dstptr = row;
+ m = 0x80;
+ unmask = ~mask;
+ len = png_ptr->width &~7; //reduce to multiple of 8
+ diff = png_ptr->width & 7; //amount lost
+
+ _asm
+ {
+ movd mm7, unmask //load bit pattern
+ psubb mm6,mm6 //zero mm6
+ punpcklbw mm7,mm7
+ punpcklwd mm7,mm7
+ punpckldq mm7,mm7 //fill register with 8 masks
+
+ movq mm0,mask0
+
+ pand mm0,mm7 //nonzero if keep byte
+ pcmpeqb mm0,mm6 //zeros->1s, v versa
+
+ mov ecx,len //load length of line (pixels)
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+ cmp ecx,0 //lcr
+ je mainloop8end
+
+mainloop8:
+ movq mm4,[esi]
+ pand mm4,mm0
+ movq mm6,mm0
+ pandn mm6,[ebx]
+ por mm4,mm6
+ movq [ebx],mm4
+
+ add esi,8 //inc by 8 bytes processed
+ add ebx,8
+ sub ecx,8 //dec by 8 pixels processed
+
+ ja mainloop8
+mainloop8end:
+
+ mov ecx,diff
+ cmp ecx,0
+ jz end8
+
+ mov edx,mask
+ sal edx,24 //make low byte the high byte
+
+secondloop8:
+ sal edx,1 //move high bit to CF
+ jnc skip8 //if CF = 0
+ mov al,[esi]
+ mov [ebx],al
+skip8:
+ inc esi
+ inc ebx
+
+ dec ecx
+ jnz secondloop8
+end8:
+ emms
+ }
+ }
+ else /* mmx not supported - use modified C routine */
+ {
+ register unsigned int incr1, initial_val, final_val;
+ png_size_t pixel_bytes;
+ png_uint_32 i;
+ register int disp = png_pass_inc[png_ptr->pass];
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dstptr, srcptr, pixel_bytes);
+ srcptr += incr1;
+ dstptr += incr1;
+ }
+ } /* end of else */
+
+ break;
+ } // end 8 bpp
+
+ case 16:
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ png_uint_32 len;
+ int unmask, diff;
+ __int64 mask1=0x0101020204040808,
+ mask0=0x1010202040408080;
+
+ if (mmx_supported)
+ {
+ srcptr = png_ptr->row_buf + 1;
+ dstptr = row;
+
+ unmask = ~mask;
+ len = (png_ptr->width)&~7;
+ diff = (png_ptr->width)&7;
+ _asm
+ {
+ movd mm7, unmask //load bit pattern
+ psubb mm6,mm6 //zero mm6
+ punpcklbw mm7,mm7
+ punpcklwd mm7,mm7
+ punpckldq mm7,mm7 //fill register with 8 masks
+
+ movq mm0,mask0
+ movq mm1,mask1
+
+ pand mm0,mm7
+ pand mm1,mm7
+
+ pcmpeqb mm0,mm6
+ pcmpeqb mm1,mm6
+
+ mov ecx,len //load length of line
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+ cmp ecx,0 //lcr
+ jz mainloop16end
+
+mainloop16:
+ movq mm4,[esi]
+ pand mm4,mm0
+ movq mm6,mm0
+ movq mm7,[ebx]
+ pandn mm6,mm7
+ por mm4,mm6
+ movq [ebx],mm4
+
+ movq mm5,[esi+8]
+ pand mm5,mm1
+ movq mm7,mm1
+ movq mm6,[ebx+8]
+ pandn mm7,mm6
+ por mm5,mm7
+ movq [ebx+8],mm5
+
+ add esi,16 //inc by 16 bytes processed
+ add ebx,16
+ sub ecx,8 //dec by 8 pixels processed
+
+ ja mainloop16
+
+mainloop16end:
+ mov ecx,diff
+ cmp ecx,0
+ jz end16
+
+ mov edx,mask
+ sal edx,24 //make low byte the high byte
+secondloop16:
+ sal edx,1 //move high bit to CF
+ jnc skip16 //if CF = 0
+ mov ax,[esi]
+ mov [ebx],ax
+skip16:
+ add esi,2
+ add ebx,2
+
+ dec ecx
+ jnz secondloop16
+end16:
+ emms
+ }
+ }
+ else /* mmx not supported - use modified C routine */
+ {
+ register unsigned int incr1, initial_val, final_val;
+ png_size_t pixel_bytes;
+ png_uint_32 i;
+ register int disp = png_pass_inc[png_ptr->pass];
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dstptr, srcptr, pixel_bytes);
+ srcptr += incr1;
+ dstptr += incr1;
+ }
+ } /* end of else */
+
+ break;
+ } // end 16 bpp
+
+ case 24:
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ png_uint_32 len;
+ int unmask, diff;
+
+ __int64 mask2=0x0101010202020404, //24bpp
+ mask1=0x0408080810101020,
+ mask0=0x2020404040808080;
+
+ srcptr = png_ptr->row_buf + 1;
+ dstptr = row;
+
+ unmask = ~mask;
+ len = (png_ptr->width)&~7;
+ diff = (png_ptr->width)&7;
+
+ if (mmx_supported)
+ {
+ _asm
+ {
+ movd mm7, unmask //load bit pattern
+ psubb mm6,mm6 //zero mm6
+ punpcklbw mm7,mm7
+ punpcklwd mm7,mm7
+ punpckldq mm7,mm7 //fill register with 8 masks
+
+ movq mm0,mask0
+ movq mm1,mask1
+ movq mm2,mask2
+
+ pand mm0,mm7
+ pand mm1,mm7
+ pand mm2,mm7
+
+ pcmpeqb mm0,mm6
+ pcmpeqb mm1,mm6
+ pcmpeqb mm2,mm6
+
+ mov ecx,len //load length of line
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+ cmp ecx,0
+ jz mainloop24end
+
+mainloop24:
+ movq mm4,[esi]
+ pand mm4,mm0
+ movq mm6,mm0
+ movq mm7,[ebx]
+ pandn mm6,mm7
+ por mm4,mm6
+ movq [ebx],mm4
+
+
+ movq mm5,[esi+8]
+ pand mm5,mm1
+ movq mm7,mm1
+ movq mm6,[ebx+8]
+ pandn mm7,mm6
+ por mm5,mm7
+ movq [ebx+8],mm5
+
+ movq mm6,[esi+16]
+ pand mm6,mm2
+ movq mm4,mm2
+ movq mm7,[ebx+16]
+ pandn mm4,mm7
+ por mm6,mm4
+ movq [ebx+16],mm6
+
+ add esi,24 //inc by 24 bytes processed
+ add ebx,24
+ sub ecx,8 //dec by 8 pixels processed
+
+ ja mainloop24
+
+mainloop24end:
+ mov ecx,diff
+ cmp ecx,0
+ jz end24
+
+ mov edx,mask
+ sal edx,24 //make low byte the high byte
+secondloop24:
+ sal edx,1 //move high bit to CF
+ jnc skip24 //if CF = 0
+ mov ax,[esi]
+ mov [ebx],ax
+ xor eax,eax
+ mov al,[esi+2]
+ mov [ebx+2],al
+skip24:
+ add esi,3
+ add ebx,3
+
+ dec ecx
+ jnz secondloop24
+
+end24:
+ emms
+ }
+ }
+ else /* mmx not supported - use modified C routine */
+ {
+ register unsigned int incr1, initial_val, final_val;
+ png_size_t pixel_bytes;
+ png_uint_32 i;
+ register int disp = png_pass_inc[png_ptr->pass];
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dstptr, srcptr, pixel_bytes);
+ srcptr += incr1;
+ dstptr += incr1;
+ }
+ } /* end of else */
+
+ break;
+ } // end 24 bpp
+
+ case 32:
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ png_uint_32 len;
+ int unmask, diff;
+
+ __int64 mask3=0x0101010102020202, //32bpp
+ mask2=0x0404040408080808,
+ mask1=0x1010101020202020,
+ mask0=0x4040404080808080;
+
+ srcptr = png_ptr->row_buf + 1;
+ dstptr = row;
+
+ unmask = ~mask;
+ len = (png_ptr->width)&~7;
+ diff = (png_ptr->width)&7;
+
+ if (mmx_supported)
+ {
+ _asm
+ {
+ movd mm7, unmask //load bit pattern
+ psubb mm6,mm6 //zero mm6
+ punpcklbw mm7,mm7
+ punpcklwd mm7,mm7
+ punpckldq mm7,mm7 //fill register with 8 masks
+
+ movq mm0,mask0
+ movq mm1,mask1
+ movq mm2,mask2
+ movq mm3,mask3
+
+ pand mm0,mm7
+ pand mm1,mm7
+ pand mm2,mm7
+ pand mm3,mm7
+
+ pcmpeqb mm0,mm6
+ pcmpeqb mm1,mm6
+ pcmpeqb mm2,mm6
+ pcmpeqb mm3,mm6
+
+ mov ecx,len //load length of line
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+
+ cmp ecx,0 //lcr
+ jz mainloop32end
+
+mainloop32:
+ movq mm4,[esi]
+ pand mm4,mm0
+ movq mm6,mm0
+ movq mm7,[ebx]
+ pandn mm6,mm7
+ por mm4,mm6
+ movq [ebx],mm4
+
+ movq mm5,[esi+8]
+ pand mm5,mm1
+ movq mm7,mm1
+ movq mm6,[ebx+8]
+ pandn mm7,mm6
+ por mm5,mm7
+ movq [ebx+8],mm5
+
+ movq mm6,[esi+16]
+ pand mm6,mm2
+ movq mm4,mm2
+ movq mm7,[ebx+16]
+ pandn mm4,mm7
+ por mm6,mm4
+ movq [ebx+16],mm6
+
+ movq mm7,[esi+24]
+ pand mm7,mm3
+ movq mm5,mm3
+ movq mm4,[ebx+24]
+ pandn mm5,mm4
+ por mm7,mm5
+ movq [ebx+24],mm7
+
+ add esi,32 //inc by 32 bytes processed
+ add ebx,32
+ sub ecx,8 //dec by 8 pixels processed
+
+ ja mainloop32
+
+mainloop32end:
+ mov ecx,diff
+ cmp ecx,0
+ jz end32
+
+ mov edx,mask
+ sal edx,24 //make low byte the high byte
+secondloop32:
+ sal edx,1 //move high bit to CF
+ jnc skip32 //if CF = 0
+ mov eax,[esi]
+ mov [ebx],eax
+skip32:
+ add esi,4
+ add ebx,4
+
+ dec ecx
+ jnz secondloop32
+
+end32:
+ emms
+ }
+ }
+ else /* mmx _not supported - Use modified C routine */
+ {
+ register unsigned int incr1, initial_val, final_val;
+ png_size_t pixel_bytes;
+ png_uint_32 i;
+ register int disp = png_pass_inc[png_ptr->pass];
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dstptr, srcptr, pixel_bytes);
+ srcptr += incr1;
+ dstptr += incr1;
+ }
+ } /* end of else */
+
+ break;
+ } // end 32 bpp
+
+ case 48:
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ png_uint_32 len;
+ int unmask, diff;
+
+ __int64 mask5=0x0101010101010202,
+ mask4=0x0202020204040404,
+ mask3=0x0404080808080808,
+ mask2=0x1010101010102020,
+ mask1=0x2020202040404040,
+ mask0=0x4040808080808080;
+
+ if (mmx_supported)
+ {
+ srcptr = png_ptr->row_buf + 1;
+ dstptr = row;
+
+ unmask = ~mask;
+ len = (png_ptr->width)&~7;
+ diff = (png_ptr->width)&7;
+ _asm
+ {
+ movd mm7, unmask //load bit pattern
+ psubb mm6,mm6 //zero mm6
+ punpcklbw mm7,mm7
+ punpcklwd mm7,mm7
+ punpckldq mm7,mm7 //fill register with 8 masks
+
+ movq mm0,mask0
+ movq mm1,mask1
+ movq mm2,mask2
+ movq mm3,mask3
+ movq mm4,mask4
+ movq mm5,mask5
+
+ pand mm0,mm7
+ pand mm1,mm7
+ pand mm2,mm7
+ pand mm3,mm7
+ pand mm4,mm7
+ pand mm5,mm7
+
+ pcmpeqb mm0,mm6
+ pcmpeqb mm1,mm6
+ pcmpeqb mm2,mm6
+ pcmpeqb mm3,mm6
+ pcmpeqb mm4,mm6
+ pcmpeqb mm5,mm6
+
+ mov ecx,len //load length of line
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+
+ cmp ecx,0
+ jz mainloop48end
+
+mainloop48:
+ movq mm7,[esi]
+ pand mm7,mm0
+ movq mm6,mm0
+ pandn mm6,[ebx]
+ por mm7,mm6
+ movq [ebx],mm7
+
+ movq mm6,[esi+8]
+ pand mm6,mm1
+ movq mm7,mm1
+ pandn mm7,[ebx+8]
+ por mm6,mm7
+ movq [ebx+8],mm6
+
+ movq mm6,[esi+16]
+ pand mm6,mm2
+ movq mm7,mm2
+ pandn mm7,[ebx+16]
+ por mm6,mm7
+ movq [ebx+16],mm6
+
+ movq mm7,[esi+24]
+ pand mm7,mm3
+ movq mm6,mm3
+ pandn mm6,[ebx+24]
+ por mm7,mm6
+ movq [ebx+24],mm7
+
+ movq mm6,[esi+32]
+ pand mm6,mm4
+ movq mm7,mm4
+ pandn mm7,[ebx+32]
+ por mm6,mm7
+ movq [ebx+32],mm6
+
+ movq mm7,[esi+40]
+ pand mm7,mm5
+ movq mm6,mm5
+ pandn mm6,[ebx+40]
+ por mm7,mm6
+ movq [ebx+40],mm7
+
+ add esi,48 //inc by 32 bytes processed
+ add ebx,48
+ sub ecx,8 //dec by 8 pixels processed
+
+ ja mainloop48
+mainloop48end:
+
+ mov ecx,diff
+ cmp ecx,0
+ jz end48
+
+ mov edx,mask
+ sal edx,24 //make low byte the high byte
+
+secondloop48:
+ sal edx,1 //move high bit to CF
+ jnc skip48 //if CF = 0
+ mov eax,[esi]
+ mov [ebx],eax
+skip48:
+ add esi,4
+ add ebx,4
+
+ dec ecx
+ jnz secondloop48
+
+end48:
+ emms
+ }
+ }
+ else /* mmx _not supported - Use modified C routine */
+ {
+ register unsigned int incr1, initial_val, final_val;
+ png_size_t pixel_bytes;
+ png_uint_32 i;
+ register int disp = png_pass_inc[png_ptr->pass];
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dstptr, srcptr, pixel_bytes);
+ srcptr += incr1;
+ dstptr += incr1;
+ }
+ } /* end of else */
+
+ break;
+ } // end 48 bpp
+
+ default:
+ {
+ png_bytep sptr;
+ png_bytep dp;
+ png_size_t pixel_bytes;
+ int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
+ unsigned int i;
+ register int disp = png_pass_inc[png_ptr->pass]; // get the offset
+ register unsigned int incr1, initial_val, final_val;
+
+ pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
+ sptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
+ pixel_bytes;
+ dp = row + offset_table[png_ptr->pass]*pixel_bytes;
+ initial_val = offset_table[png_ptr->pass]*pixel_bytes;
+ final_val = png_ptr->width*pixel_bytes;
+ incr1 = (disp)*pixel_bytes;
+ for (i = initial_val; i < final_val; i += incr1)
+ {
+ png_memcpy(dp, sptr, pixel_bytes);
+ sptr += incr1;
+ dp += incr1;
+ }
+ break;
+ }
+ } /* end switch (png_ptr->row_info.pixel_depth) */
+ } /* end if (non-trivial mask) */
+
+#ifdef DISABLE_PNGVCRD_COMBINE
+ mmx_supported = save_mmx_supported;
+#endif
+
+} /* end png_combine_row() */
+
+
+#if defined(PNG_READ_INTERLACING_SUPPORTED)
+
+void
+png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
+ png_uint_32 transformations)
+{
+#ifdef DISABLE_PNGVCRD_INTERLACE
+ int save_mmx_supported = mmx_supported;
+#endif
+
+ png_debug(1,"in png_do_read_interlace\n");
+
+#ifdef DISABLE_PNGVCRD_INTERLACE
+ /* In libpng versions 1.0.3a through 1.0.4d,
+ * a sign error in the post-MMX cleanup code for each pixel_depth resulted
+ * in bad pixels at the beginning of some rows of some images, and also
+ * (due to out-of-range memory reads and writes) caused heap corruption
+ * when compiled with MSVC 6.0. The error was fixed in version 1.0.4e,
+ * and the code appears to work completely correctly, so it is enabled
+ * by default.
+ */
+ if (1) /* all passes caused a heap problem in the old code */
+ mmx_supported = 0;
+ else
+#endif
+ if (mmx_supported == 2)
+ mmx_supported = mmxsupport();
+
+ if (row != NULL && row_info != NULL)
+ {
+ png_uint_32 final_width;
+
+ final_width = row_info->width * png_pass_inc[pass];
+
+ switch (row_info->pixel_depth)
+ {
+ case 1:
+ {
+ png_bytep sp, dp;
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ png_byte v;
+ png_uint_32 i;
+ int j;
+
+ sp = row + (png_size_t)((row_info->width - 1) >> 3);
+ dp = row + (png_size_t)((final_width - 1) >> 3);
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (int)((row_info->width + 7) & 7);
+ dshift = (int)((final_width + 7) & 7);
+ s_start = 7;
+ s_end = 0;
+ s_inc = -1;
+ }
+ else
+#endif
+ {
+ sshift = 7 - (int)((row_info->width + 7) & 7);
+ dshift = 7 - (int)((final_width + 7) & 7);
+ s_start = 0;
+ s_end = 7;
+ s_inc = 1;
+ }
+
+ for (i = row_info->width; i; i--)
+ {
+ v = (png_byte)((*sp >> sshift) & 0x1);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+
+ case 2:
+ {
+ png_bytep sp, dp;
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ png_uint_32 i;
+
+ sp = row + (png_size_t)((row_info->width - 1) >> 2);
+ dp = row + (png_size_t)((final_width - 1) >> 2);
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
+ dshift = (png_size_t)(((final_width + 3) & 3) << 1);
+ s_start = 6;
+ s_end = 0;
+ s_inc = -2;
+ }
+ else
+#endif
+ {
+ sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
+ dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
+ s_start = 0;
+ s_end = 6;
+ s_inc = 2;
+ }
+
+ for (i = row_info->width; i; i--)
+ {
+ png_byte v;
+ int j;
+
+ v = (png_byte)((*sp >> sshift) & 0x3);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+
+ case 4:
+ {
+ png_bytep sp, dp;
+ int sshift, dshift;
+ int s_start, s_end, s_inc;
+ png_uint_32 i;
+
+ sp = row + (png_size_t)((row_info->width - 1) >> 1);
+ dp = row + (png_size_t)((final_width - 1) >> 1);
+#if defined(PNG_READ_PACKSWAP_SUPPORTED)
+ if (transformations & PNG_PACKSWAP)
+ {
+ sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
+ dshift = (png_size_t)(((final_width + 1) & 1) << 2);
+ s_start = 4;
+ s_end = 0;
+ s_inc = -4;
+ }
+ else
+#endif
+ {
+ sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
+ dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
+ s_start = 0;
+ s_end = 4;
+ s_inc = 4;
+ }
+
+ for (i = row_info->width; i; i--)
+ {
+ png_byte v;
+ int j;
+
+ v = (png_byte)((*sp >> sshift) & 0xf);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
+ *dp |= (png_byte)(v << dshift);
+ if (dshift == s_end)
+ {
+ dshift = s_start;
+ dp--;
+ }
+ else
+ dshift += s_inc;
+ }
+ if (sshift == s_end)
+ {
+ sshift = s_start;
+ sp--;
+ }
+ else
+ sshift += s_inc;
+ }
+ break;
+ }
+
+ default: // This is the place where the routine is modified
+ {
+ __int64 const4 = 0x0000000000FFFFFF;
+ // __int64 const5 = 0x000000FFFFFF0000; // unused...
+ __int64 const6 = 0x00000000000000FF;
+ png_bytep sptr, dp;
+ png_uint_32 i;
+ png_size_t pixel_bytes;
+ int width = row_info->width;
+
+ pixel_bytes = (row_info->pixel_depth >> 3);
+
+ sptr = row + (width - 1) * pixel_bytes;
+ dp = row + (final_width - 1) * pixel_bytes;
+ // New code by Nirav Chhatrapati - Intel Corporation
+ // sign fix by GRR
+ // NOTE: there is NO MMX code for 48-bit and 64-bit images
+
+ if (mmx_supported) // use MMX routine if machine supports it
+ {
+ if (pixel_bytes == 3)
+ {
+ if ((pass == 0) || (pass == 1))
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width
+ sub edi, 21 // (png_pass_inc[pass] - 1)*pixel_bytes
+loop_pass0:
+ movd mm0, [esi] ; X X X X X v2 v1 v0
+ pand mm0, const4 ; 0 0 0 0 0 v2 v1 v0
+ movq mm1, mm0 ; 0 0 0 0 0 v2 v1 v0
+ psllq mm0, 16 ; 0 0 0 v2 v1 v0 0 0
+ movq mm2, mm0 ; 0 0 0 v2 v1 v0 0 0
+ psllq mm0, 24 ; v2 v1 v0 0 0 0 0 0
+ psrlq mm1, 8 ; 0 0 0 0 0 0 v2 v1
+ por mm0, mm2 ; v2 v1 v0 v2 v1 v0 0 0
+ por mm0, mm1 ; v2 v1 v0 v2 v1 v0 v2 v1
+ movq mm3, mm0 ; v2 v1 v0 v2 v1 v0 v2 v1
+ psllq mm0, 16 ; v0 v2 v1 v0 v2 v1 0 0
+ movq mm4, mm3 ; v2 v1 v0 v2 v1 v0 v2 v1
+ punpckhdq mm3, mm0 ; v0 v2 v1 v0 v2 v1 v0 v2
+ movq [edi+16] , mm4
+ psrlq mm0, 32 ; 0 0 0 0 v0 v2 v1 v0
+ movq [edi+8] , mm3
+ punpckldq mm0, mm4 ; v1 v0 v2 v1 v0 v2 v1 v0
+ sub esi, 3
+ movq [edi], mm0
+ sub edi, 24
+ //sub esi, 3
+ dec ecx
+ jnz loop_pass0
+ EMMS
+ }
+ }
+ else if ((pass == 2) || (pass == 3))
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width
+ sub edi, 9 // (png_pass_inc[pass] - 1)*pixel_bytes
+loop_pass2:
+ movd mm0, [esi] ; X X X X X v2 v1 v0
+ pand mm0, const4 ; 0 0 0 0 0 v2 v1 v0
+ movq mm1, mm0 ; 0 0 0 0 0 v2 v1 v0
+ psllq mm0, 16 ; 0 0 0 v2 v1 v0 0 0
+ movq mm2, mm0 ; 0 0 0 v2 v1 v0 0 0
+ psllq mm0, 24 ; v2 v1 v0 0 0 0 0 0
+ psrlq mm1, 8 ; 0 0 0 0 0 0 v2 v1
+ por mm0, mm2 ; v2 v1 v0 v2 v1 v0 0 0
+ por mm0, mm1 ; v2 v1 v0 v2 v1 v0 v2 v1
+ movq [edi+4], mm0 ; move to memory
+ psrlq mm0, 16 ; 0 0 v2 v1 v0 v2 v1 v0
+ movd [edi], mm0 ; move to memory
+ sub esi, 3
+ sub edi, 12
+ dec ecx
+ jnz loop_pass2
+ EMMS
+ }
+ }
+ else /* if ((pass == 4) || (pass == 5)) */
+ {
+ int width_mmx = ((width >> 1) << 1) - 8;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 3
+ sub edi, 9
+loop_pass4:
+ movq mm0, [esi] ; X X v2 v1 v0 v5 v4 v3
+ movq mm7, mm0 ; X X v2 v1 v0 v5 v4 v3
+ movq mm6, mm0 ; X X v2 v1 v0 v5 v4 v3
+ psllq mm0, 24 ; v1 v0 v5 v4 v3 0 0 0
+ pand mm7, const4 ; 0 0 0 0 0 v5 v4 v3
+ psrlq mm6, 24 ; 0 0 0 X X v2 v1 v0
+ por mm0, mm7 ; v1 v0 v5 v4 v3 v5 v4 v3
+ movq mm5, mm6 ; 0 0 0 X X v2 v1 v0
+ psllq mm6, 8 ; 0 0 X X v2 v1 v0 0
+ movq [edi], mm0 ; move quad to memory
+ psrlq mm5, 16 ; 0 0 0 0 0 X X v2
+ pand mm5, const6 ; 0 0 0 0 0 0 0 v2
+ por mm6, mm5 ; 0 0 X X v2 v1 v0 v2
+ movd [edi+8], mm6 ; move double to memory
+ sub esi, 6
+ sub edi, 12
+ sub ecx, 2
+ jnz loop_pass4
+ EMMS
+ }
+ }
+
+ sptr -= width_mmx*3;
+ dp -= width_mmx*6;
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+ } /* end of pixel_bytes == 3 */
+
+ else if (pixel_bytes == 1)
+ {
+ if ((pass == 0) || (pass == 1))
+ {
+ int width_mmx = ((width >> 2) << 2);
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub edi, 31
+ sub esi, 3
+loop1_pass0:
+ movd mm0, [esi] ; X X X X v0 v1 v2 v3
+ movq mm1, mm0 ; X X X X v0 v1 v2 v3
+ punpcklbw mm0, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
+ movq mm2, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
+ punpcklwd mm0, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
+ movq mm3, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
+ punpckldq mm0, mm0 ; v3 v3 v3 v3 v3 v3 v3 v3
+ punpckhdq mm3, mm3 ; v2 v2 v2 v2 v2 v2 v2 v2
+ movq [edi], mm0 ; move to memory v3
+ punpckhwd mm2, mm2 ; v0 v0 v0 v0 v1 v1 v1 v1
+ movq [edi+8], mm3 ; move to memory v2
+ movq mm4, mm2 ; v0 v0 v0 v0 v1 v1 v1 v1
+ punpckldq mm2, mm2 ; v1 v1 v1 v1 v1 v1 v1 v1
+ punpckhdq mm4, mm4 ; v0 v0 v0 v0 v0 v0 v0 v0
+ movq [edi+16], mm2 ; move to memory v1
+ movq [edi+24], mm4 ; move to memory v0
+ sub esi, 4
+ sub edi, 32
+ sub ecx, 4
+ jnz loop1_pass0
+ EMMS
+ }
+ }
+
+ sptr -= width_mmx;
+ dp -= width_mmx*8;
+ for (i = width; i; i--)
+ {
+ int j;
+
+ /* I simplified this part in version 1.0.4e
+ * here and in several other instances where
+ * pixel_bytes == 1 -- GR-P
+ *
+ * Original code:
+ *
+ * png_byte v[8];
+ * png_memcpy(v, sptr, pixel_bytes);
+ * for (j = 0; j < png_pass_inc[pass]; j++)
+ * {
+ * png_memcpy(dp, v, pixel_bytes);
+ * dp -= pixel_bytes;
+ * }
+ * sptr -= pixel_bytes;
+ *
+ * Replacement code is in the next three lines:
+ */
+
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ *dp-- = *sptr;
+ sptr--;
+ }
+ }
+ else if ((pass == 2) || (pass == 3))
+ {
+ int width_mmx = ((width >> 2) << 2);
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub edi, 15
+ sub esi, 3
+loop1_pass2:
+ movd mm0, [esi] ; X X X X v0 v1 v2 v3
+ punpcklbw mm0, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
+ movq mm1, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
+ punpcklwd mm0, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
+ punpckhwd mm1, mm1 ; v0 v0 v0 v0 v1 v1 v1 v1
+ movq [edi], mm0 ; move to memory v2 and v3
+ sub esi, 4
+ movq [edi+8], mm1 ; move to memory v1 and v0
+ sub edi, 16
+ sub ecx, 4
+ jnz loop1_pass2
+ EMMS
+ }
+ }
+
+ sptr -= width_mmx;
+ dp -= width_mmx*4;
+ for (i = width; i; i--)
+ {
+ int j;
+
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ *dp-- = *sptr;
+ }
+ sptr --;
+ }
+ }
+ else //if ((pass == 4) || (pass == 5))
+ {
+ int width_mmx = ((width >> 3) << 3);
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub edi, 15
+ sub esi, 7
+loop1_pass4:
+ movq mm0, [esi] ; v0 v1 v2 v3 v4 v5 v6 v7
+ movq mm1, mm0 ; v0 v1 v2 v3 v4 v5 v6 v7
+ punpcklbw mm0, mm0 ; v4 v4 v5 v5 v6 v6 v7 v7
+ //movq mm1, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
+ punpckhbw mm1, mm1 ;v0 v0 v1 v1 v2 v2 v3 v3
+ movq [edi+8], mm1 ; move to memory v0 v1 v2 and v3
+ sub esi, 8
+ movq [edi], mm0 ; move to memory v4 v5 v6 and v7
+ //sub esi, 4
+ sub edi, 16
+ sub ecx, 8
+ jnz loop1_pass4
+ EMMS
+ }
+ }
+
+ sptr -= width_mmx;
+ dp -= width_mmx*2;
+ for (i = width; i; i--)
+ {
+ int j;
+
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ *dp-- = *sptr;
+ }
+ sptr --;
+ }
+ }
+ } /* end of pixel_bytes == 1 */
+
+ else if (pixel_bytes == 2)
+ {
+ if ((pass == 0) || (pass == 1))
+ {
+ int width_mmx = ((width >> 1) << 1);
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 2
+ sub edi, 30
+loop2_pass0:
+ movd mm0, [esi] ; X X X X v1 v0 v3 v2
+ punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
+ movq mm1, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
+ punpckldq mm0, mm0 ; v3 v2 v3 v2 v3 v2 v3 v2
+ punpckhdq mm1, mm1 ; v1 v0 v1 v0 v1 v0 v1 v0
+ movq [edi], mm0
+ movq [edi + 8], mm0
+ movq [edi + 16], mm1
+ movq [edi + 24], mm1
+ sub esi, 4
+ sub edi, 32
+ sub ecx, 2
+ jnz loop2_pass0
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*2 - 2); // sign fixed
+ dp -= (width_mmx*16 - 2); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+
+ else if ((pass == 2) || (pass == 3))
+ {
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 2
+ sub edi, 14
+loop2_pass2:
+ movd mm0, [esi] ; X X X X v1 v0 v3 v2
+ punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
+ movq mm1, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
+ punpckldq mm0, mm0 ; v3 v2 v3 v2 v3 v2 v3 v2
+ punpckhdq mm1, mm1 ; v1 v0 v1 v0 v1 v0 v1 v0
+ movq [edi], mm0
+ sub esi, 4
+ movq [edi + 8], mm1
+ //sub esi, 4
+ sub edi, 16
+ sub ecx, 2
+ jnz loop2_pass2
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*2 - 2); // sign fixed
+ dp -= (width_mmx*8 - 2); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+
+ else // pass == 4 or 5
+ {
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 2
+ sub edi, 6
+loop2_pass4:
+ movd mm0, [esi] ; X X X X v1 v0 v3 v2
+ punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
+ sub esi, 4
+ movq [edi], mm0
+ sub edi, 8
+ sub ecx, 2
+ jnz loop2_pass4
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*2 - 2); // sign fixed
+ dp -= (width_mmx*4 - 2); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+ } /* end of pixel_bytes == 2 */
+
+ else if (pixel_bytes == 4)
+ {
+ if ((pass == 0) || (pass == 1))
+ {
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 4
+ sub edi, 60
+loop4_pass0:
+ movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
+ movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
+ punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
+ punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
+ movq [edi], mm0
+ movq [edi + 8], mm0
+ movq [edi + 16], mm0
+ movq [edi + 24], mm0
+ movq [edi+32], mm1
+ movq [edi + 40], mm1
+ movq [edi+ 48], mm1
+ sub esi, 8
+ movq [edi + 56], mm1
+ sub edi, 64
+ sub ecx, 2
+ jnz loop4_pass0
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*4 - 4); // sign fixed
+ dp -= (width_mmx*32 - 4); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+
+ else if ((pass == 2) || (pass == 3))
+ {
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 4
+ sub edi, 28
+loop4_pass2:
+ movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
+ movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
+ punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
+ punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
+ movq [edi], mm0
+ movq [edi + 8], mm0
+ movq [edi+16], mm1
+ movq [edi + 24], mm1
+ sub esi, 8
+ sub edi, 32
+ sub ecx, 2
+ jnz loop4_pass2
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*4 - 4); // sign fixed
+ dp -= (width_mmx*16 - 4); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+
+ else // pass == 4 or 5
+ {
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx;
+ if (width_mmx)
+ {
+ _asm
+ {
+ mov esi, sptr
+ mov edi, dp
+ mov ecx, width_mmx
+ sub esi, 4
+ sub edi, 12
+loop4_pass4:
+ movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
+ movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
+ punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
+ punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
+ movq [edi], mm0
+ sub esi, 8
+ movq [edi + 8], mm1
+ sub edi, 16
+ sub ecx, 2
+ jnz loop4_pass4
+ EMMS
+ }
+ }
+
+ sptr -= (width_mmx*4 - 4); // sign fixed
+ dp -= (width_mmx*8 - 4); // sign fixed
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ sptr -= pixel_bytes;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ dp -= pixel_bytes;
+ png_memcpy(dp, v, pixel_bytes);
+ }
+ }
+ }
+
+ } /* end of pixel_bytes == 4 */
+
+ else if (pixel_bytes == 6)
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ } /* end of pixel_bytes == 6 */
+
+ else
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr-= pixel_bytes;
+ }
+ }
+ } /* end of mmx_supported */
+
+ else /* MMX not supported: use modified C code - takes advantage
+ * of inlining of memcpy for a constant */
+ {
+ if (pixel_bytes == 1)
+ {
+ for (i = width; i; i--)
+ {
+ int j;
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ *dp-- = *sptr;
+ sptr--;
+ }
+ }
+ else if (pixel_bytes == 3)
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+ else if (pixel_bytes == 2)
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+ else if (pixel_bytes == 4)
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+ else if (pixel_bytes == 6)
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+ else
+ {
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+ png_memcpy(v, sptr, pixel_bytes);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, pixel_bytes);
+ dp -= pixel_bytes;
+ }
+ sptr -= pixel_bytes;
+ }
+ }
+
+ } /* end of MMX not supported */
+ break;
+ }
+ } /* end switch (row_info->pixel_depth) */
+
+ row_info->width = final_width;
+ row_info->rowbytes = ((final_width *
+ (png_uint_32)row_info->pixel_depth + 7) >> 3);
+ }
+
+#ifdef DISABLE_PNGVCRD_INTERLACE
+ mmx_supported = save_mmx_supported;
+#endif
+}
+
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
+
+
+// These variables are utilized in the functions below. They are declared
+// globally here to ensure alignment on 8-byte boundaries.
+
+union uAll {
+ __int64 use;
+ double align;
+} LBCarryMask = {0x0101010101010101},
+ HBClearMask = {0x7f7f7f7f7f7f7f7f},
+ ActiveMask, ActiveMask2, ActiveMaskEnd, ShiftBpp, ShiftRem;
+
+
+// Optimized code for PNG Average filter decoder
+void
+png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row
+ , png_bytep prev_row)
+{
+ int bpp;
+ png_uint_32 FullLength;
+ png_uint_32 MMXLength;
+ //png_uint_32 len;
+ int diff;
+
+ bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
+ FullLength = row_info->rowbytes; // # of bytes to filter
+ _asm {
+ // Init address pointers and offset
+ mov edi, row // edi ==> Avg(x)
+ xor ebx, ebx // ebx ==> x
+ mov edx, edi
+ mov esi, prev_row // esi ==> Prior(x)
+ sub edx, bpp // edx ==> Raw(x-bpp)
+
+ xor eax, eax
+ // Compute the Raw value for the first bpp bytes
+ // Raw(x) = Avg(x) + (Prior(x)/2)
+davgrlp:
+ mov al, [esi + ebx] // Load al with Prior(x)
+ inc ebx
+ shr al, 1 // divide by 2
+ add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
+ cmp ebx, bpp
+ mov [edi+ebx-1], al // Write back Raw(x);
+ // mov does not affect flags; -1 to offset inc ebx
+ jb davgrlp
+ // get # of bytes to alignment
+ mov diff, edi // take start of row
+ add diff, ebx // add bpp
+ add diff, 0xf // add 7 + 8 to incr past alignment boundary
+ and diff, 0xfffffff8 // mask to alignment boundary
+ sub diff, edi // subtract from start ==> value ebx at alignment
+ jz davggo
+ // fix alignment
+ // Compute the Raw value for the bytes upto the alignment boundary
+ // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
+ xor ecx, ecx
+davglp1:
+ xor eax, eax
+ mov cl, [esi + ebx] // load cl with Prior(x)
+ mov al, [edx + ebx] // load al with Raw(x-bpp)
+ add ax, cx
+ inc ebx
+ shr ax, 1 // divide by 2
+ add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
+ cmp ebx, diff // Check if at alignment boundary
+ mov [edi+ebx-1], al // Write back Raw(x);
+ // mov does not affect flags; -1 to offset inc ebx
+ jb davglp1 // Repeat until at alignment boundary
+davggo:
+ mov eax, FullLength
+ mov ecx, eax
+ sub eax, ebx // subtract alignment fix
+ and eax, 0x00000007 // calc bytes over mult of 8
+ sub ecx, eax // drop over bytes from original length
+ mov MMXLength, ecx
+ } // end _asm block
+ // Now do the math for the rest of the row
+ switch ( bpp )
+ {
+ case 3:
+ {
+ ActiveMask.use = 0x0000000000ffffff;
+ ShiftBpp.use = 24; // == 3 * 8
+ ShiftRem.use = 40; // == 64 - 24
+ _asm {
+ // Re-init address pointers and offset
+ movq mm7, ActiveMask
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ movq mm5, LBCarryMask
+ mov edi, row // edi ==> Avg(x)
+ movq mm4, HBClearMask
+ mov esi, prev_row // esi ==> Prior(x)
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
+ // (we correct position in loop below)
+davg3lp:
+ movq mm0, [edi + ebx] // Load mm0 with Avg(x)
+ // Add (Prev_row/2) to Average
+ movq mm3, mm5
+ psrlq mm2, ShiftRem // Correct position Raw(x-bpp) data
+ movq mm1, [esi + ebx] // Load mm1 with Prior(x)
+ movq mm6, mm7
+ pand mm3, mm1 // get lsb for each prev_row byte
+ psrlq mm1, 1 // divide prev_row bytes by 2
+ pand mm1, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
+ // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 1 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
+ // byte
+ // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
+ psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 3-5
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
+ // byte
+
+ // Add 3rd active group (Raw(x-bpp)/2) to Average with LBCarry
+ psllq mm6, ShiftBpp // shift the mm6 mask to cover the last two
+ // bytes
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ // Data only needs to be shifted once here to
+ // get the correct x-bpp offset.
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ add ebx, 8
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
+ // byte
+
+ // Now ready to write back to memory
+ movq [edi + ebx - 8], mm0
+ // Move updated Raw(x) to use as Raw(x-bpp) for next loop
+ cmp ebx, MMXLength
+ movq mm2, mm0 // mov updated Raw(x) to mm2
+ jb davg3lp
+ } // end _asm block
+ }
+ break;
+
+ case 6:
+ case 4:
+ case 7:
+ case 5:
+ {
+ ActiveMask.use = 0xffffffffffffffff; // use shift below to clear
+ // appropriate inactive bytes
+ ShiftBpp.use = bpp << 3;
+ ShiftRem.use = 64 - ShiftBpp.use;
+ _asm {
+ movq mm4, HBClearMask
+ // Re-init address pointers and offset
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ // Load ActiveMask and clear all bytes except for 1st active group
+ movq mm7, ActiveMask
+ mov edi, row // edi ==> Avg(x)
+ psrlq mm7, ShiftRem
+ mov esi, prev_row // esi ==> Prior(x)
+ movq mm6, mm7
+ movq mm5, LBCarryMask
+ psllq mm6, ShiftBpp // Create mask for 2nd active group
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
+ // (we correct position in loop below)
+davg4lp:
+ movq mm0, [edi + ebx]
+ psrlq mm2, ShiftRem // shift data to position correctly
+ movq mm1, [esi + ebx]
+ // Add (Prev_row/2) to Average
+ movq mm3, mm5
+ pand mm3, mm1 // get lsb for each prev_row byte
+ psrlq mm1, 1 // divide prev_row bytes by 2
+ pand mm1, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
+ // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm7 // Leave only Active Group 1 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
+ // byte
+ // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ add ebx, 8
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
+ // byte
+ cmp ebx, MMXLength
+ // Now ready to write back to memory
+ movq [edi + ebx - 8], mm0
+ // Prep Raw(x-bpp) for next loop
+ movq mm2, mm0 // mov updated Raws to mm2
+ jb davg4lp
+ } // end _asm block
+ }
+ break;
+ case 2:
+ {
+ ActiveMask.use = 0x000000000000ffff;
+ ShiftBpp.use = 24; // == 3 * 8
+ ShiftRem.use = 40; // == 64 - 24
+ _asm {
+ // Load ActiveMask
+ movq mm7, ActiveMask
+ // Re-init address pointers and offset
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ movq mm5, LBCarryMask
+ mov edi, row // edi ==> Avg(x)
+ movq mm4, HBClearMask
+ mov esi, prev_row // esi ==> Prior(x)
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
+ // (we correct position in loop below)
+davg2lp:
+ movq mm0, [edi + ebx]
+ psllq mm2, ShiftRem // shift data to position correctly
+ movq mm1, [esi + ebx]
+ // Add (Prev_row/2) to Average
+ movq mm3, mm5
+ pand mm3, mm1 // get lsb for each prev_row byte
+ psrlq mm1, 1 // divide prev_row bytes by 2
+ pand mm1, mm4 // clear invalid bit 7 of each byte
+ movq mm6, mm7
+ paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
+ // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 1 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
+ // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
+ psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 2 & 3
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
+
+ // Add rdd active group (Raw(x-bpp)/2) to Average with LBCarry
+ psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 4 & 5
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ // Data only needs to be shifted once here to
+ // get the correct x-bpp offset.
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
+
+ // Add 4th active group (Raw(x-bpp)/2) to Average with LBCarry
+ psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 6 & 7
+ movq mm2, mm0 // mov updated Raws to mm2
+ psllq mm2, ShiftBpp // shift data to position correctly
+ // Data only needs to be shifted once here to
+ // get the correct x-bpp offset.
+ add ebx, 8
+ movq mm1, mm3 // now use mm1 for getting LBCarrys
+ pand mm1, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1 (Only valid for active group)
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
+ pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
+ paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
+
+ cmp ebx, MMXLength
+ // Now ready to write back to memory
+ movq [edi + ebx - 8], mm0
+ // Prep Raw(x-bpp) for next loop
+ movq mm2, mm0 // mov updated Raws to mm2
+ jb davg2lp
+ } // end _asm block
+ }
+ break;
+
+ case 1: // bpp == 1
+ {
+ _asm {
+ // Re-init address pointers and offset
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ mov edi, row // edi ==> Avg(x)
+ cmp ebx, FullLength // Test if offset at end of array
+ jnb davg1end
+ // Do Paeth decode for remaining bytes
+ mov esi, prev_row // esi ==> Prior(x)
+ mov edx, edi
+ xor ecx, ecx // zero ecx before using cl & cx in loop below
+ sub edx, bpp // edx ==> Raw(x-bpp)
+davg1lp:
+ // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
+ xor eax, eax
+ mov cl, [esi + ebx] // load cl with Prior(x)
+ mov al, [edx + ebx] // load al with Raw(x-bpp)
+ add ax, cx
+ inc ebx
+ shr ax, 1 // divide by 2
+ add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
+ cmp ebx, FullLength // Check if at end of array
+ mov [edi+ebx-1], al // Write back Raw(x);
+ // mov does not affect flags; -1 to offset inc ebx
+ jb davg1lp
+davg1end:
+ } // end _asm block
+ }
+ return;
+
+ case 8: // bpp == 8
+ {
+ _asm {
+ // Re-init address pointers and offset
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ movq mm5, LBCarryMask
+ mov edi, row // edi ==> Avg(x)
+ movq mm4, HBClearMask
+ mov esi, prev_row // esi ==> Prior(x)
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
+ // (NO NEED to correct position in loop below)
+davg8lp:
+ movq mm0, [edi + ebx]
+ movq mm3, mm5
+ movq mm1, [esi + ebx]
+ add ebx, 8
+ pand mm3, mm1 // get lsb for each prev_row byte
+ psrlq mm1, 1 // divide prev_row bytes by 2
+ pand mm3, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm1, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm3 // add LBCarrys to Avg for each byte
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
+ paddb mm0, mm2 // add (Raw/2) to Avg for each byte
+ cmp ebx, MMXLength
+ movq [edi + ebx - 8], mm0
+ movq mm2, mm0 // reuse as Raw(x-bpp)
+ jb davg8lp
+ } // end _asm block
+ }
+ break;
+ default: // bpp greater than 8
+ {
+ _asm {
+ movq mm5, LBCarryMask
+ // Re-init address pointers and offset
+ mov ebx, diff // ebx ==> x = offset to alignment boundary
+ mov edi, row // edi ==> Avg(x)
+ movq mm4, HBClearMask
+ mov edx, edi
+ mov esi, prev_row // esi ==> Prior(x)
+ sub edx, bpp // edx ==> Raw(x-bpp)
+davgAlp:
+ movq mm0, [edi + ebx]
+ movq mm3, mm5
+ movq mm1, [esi + ebx]
+ pand mm3, mm1 // get lsb for each prev_row byte
+ movq mm2, [edx + ebx]
+ psrlq mm1, 1 // divide prev_row bytes by 2
+ pand mm3, mm2 // get LBCarrys for each byte where both
+ // lsb's were == 1
+ psrlq mm2, 1 // divide raw bytes by 2
+ pand mm1, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm3 // add LBCarrys to Avg for each byte
+ pand mm2, mm4 // clear invalid bit 7 of each byte
+ paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
+ add ebx, 8
+ paddb mm0, mm2 // add (Raw/2) to Avg for each byte
+ cmp ebx, MMXLength
+ movq [edi + ebx - 8], mm0
+ jb davgAlp
+ } // end _asm block
+ }
+ break;
+ } // end switch ( bpp )
+
+ _asm {
+ // MMX acceleration complete now do clean-up
+ // Check if any remaining bytes left to decode
+ mov ebx, MMXLength // ebx ==> x = offset bytes remaining after MMX
+ mov edi, row // edi ==> Avg(x)
+ cmp ebx, FullLength // Test if offset at end of array
+ jnb davgend
+ // Do Paeth decode for remaining bytes
+ mov esi, prev_row // esi ==> Prior(x)
+ mov edx, edi
+ xor ecx, ecx // zero ecx before using cl & cx in loop below
+ sub edx, bpp // edx ==> Raw(x-bpp)
+davglp2:
+ // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
+ xor eax, eax
+ mov cl, [esi + ebx] // load cl with Prior(x)
+ mov al, [edx + ebx] // load al with Raw(x-bpp)
+ add ax, cx
+ inc ebx
+ shr ax, 1 // divide by 2
+ add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
+ cmp ebx, FullLength // Check if at end of array
+ mov [edi+ebx-1], al // Write back Raw(x);
+ // mov does not affect flags; -1 to offset inc ebx
+ jb davglp2
+davgend:
+ emms // End MMX instructions; prep for possible FP instrs.
+ } // end _asm block
+}
+
+// Optimized code for PNG Paeth filter decoder
+void
+png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
+ png_bytep prev_row)
+{
+ png_uint_32 FullLength;
+ png_uint_32 MMXLength;
+ //png_uint_32 len;
+ int bpp;
+ int diff;
+ //int ptemp;
+ int patemp, pbtemp, pctemp;
+
+ bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
+ FullLength = row_info->rowbytes; // # of bytes to filter
+ _asm
+ {
+ xor ebx, ebx // ebx ==> x offset
+ mov edi, row
+ xor edx, edx // edx ==> x-bpp offset
+ mov esi, prev_row
+ xor eax, eax
+
+ // Compute the Raw value for the first bpp bytes
+ // Note: the formula works out to be always
+ // Paeth(x) = Raw(x) + Prior(x) where x < bpp
+dpthrlp:
+ mov al, [edi + ebx]
+ add al, [esi + ebx]
+ inc ebx
+ cmp ebx, bpp
+ mov [edi + ebx - 1], al
+ jb dpthrlp
+ // get # of bytes to alignment
+ mov diff, edi // take start of row
+ add diff, ebx // add bpp
+ xor ecx, ecx
+ add diff, 0xf // add 7 + 8 to incr past alignment boundary
+ and diff, 0xfffffff8 // mask to alignment boundary
+ sub diff, edi // subtract from start ==> value ebx at alignment
+ jz dpthgo
+ // fix alignment
+dpthlp1:
+ xor eax, eax
+ // pav = p - a = (a + b - c) - a = b - c
+ mov al, [esi + ebx] // load Prior(x) into al
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov patemp, eax // Save pav for later use
+ xor eax, eax
+ // pbv = p - b = (a + b - c) - b = a - c
+ mov al, [edi + edx] // load Raw(x-bpp) into al
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov ecx, eax
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ add eax, patemp // pcv = pav + pbv
+ // pc = abs(pcv)
+ test eax, 0x80000000
+ jz dpthpca
+ neg eax // reverse sign of neg values
+dpthpca:
+ mov pctemp, eax // save pc for later use
+ // pb = abs(pbv)
+ test ecx, 0x80000000
+ jz dpthpba
+ neg ecx // reverse sign of neg values
+dpthpba:
+ mov pbtemp, ecx // save pb for later use
+ // pa = abs(pav)
+ mov eax, patemp
+ test eax, 0x80000000
+ jz dpthpaa
+ neg eax // reverse sign of neg values
+dpthpaa:
+ mov patemp, eax // save pa for later use
+ // test if pa <= pb
+ cmp eax, ecx
+ jna dpthabb
+ // pa > pb; now test if pb <= pc
+ cmp ecx, pctemp
+ jna dpthbbc
+ // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthpaeth
+dpthbbc:
+ // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
+ mov cl, [esi + ebx] // load Prior(x) into cl
+ jmp dpthpaeth
+dpthabb:
+ // pa <= pb; now test if pa <= pc
+ cmp eax, pctemp
+ jna dpthabc
+ // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthpaeth
+dpthabc:
+ // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
+ mov cl, [edi + edx] // load Raw(x-bpp) into cl
+dpthpaeth:
+ inc ebx
+ inc edx
+ // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
+ add [edi + ebx - 1], cl
+ cmp ebx, diff
+ jb dpthlp1
+dpthgo:
+ mov ecx, FullLength
+ mov eax, ecx
+ sub eax, ebx // subtract alignment fix
+ and eax, 0x00000007 // calc bytes over mult of 8
+ sub ecx, eax // drop over bytes from original length
+ mov MMXLength, ecx
+ } // end _asm block
+ // Now do the math for the rest of the row
+ switch ( bpp )
+ {
+ case 3:
+ {
+ ActiveMask.use = 0x0000000000ffffff;
+ ActiveMaskEnd.use = 0xffff000000000000;
+ ShiftBpp.use = 24; // == bpp(3) * 8
+ ShiftRem.use = 40; // == 64 - 24
+ _asm
+ {
+ mov ebx, diff
+ mov edi, row
+ mov esi, prev_row
+ pxor mm0, mm0
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8]
+dpth3lp:
+ psrlq mm1, ShiftRem // shift last 3 bytes to 1st 3 bytes
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ punpcklbw mm1, mm0 // Unpack High bytes of a
+ movq mm3, [esi+ebx-8] // Prep c=Prior(x-bpp) bytes
+ punpcklbw mm2, mm0 // Unpack High bytes of b
+ psrlq mm3, ShiftRem // shift last 3 bytes to 1st 3 bytes
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ punpcklbw mm3, mm0 // Unpack High bytes of c
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ paddw mm7, mm3
+ pxor mm0, mm0
+ packuswb mm7, mm1
+ movq mm3, [esi + ebx] // load c=Prior(x-bpp)
+ pand mm7, ActiveMask
+ movq mm2, mm3 // load b=Prior(x) step 1
+ paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
+ punpcklbw mm3, mm0 // Unpack High bytes of c
+ movq [edi + ebx], mm7 // write back updated value
+ movq mm1, mm7 // Now mm1 will be used as Raw(x-bpp)
+ // Now do Paeth for 2nd set of bytes (3-5)
+ psrlq mm2, ShiftBpp // load b=Prior(x) step 2
+ punpcklbw mm1, mm0 // Unpack High bytes of a
+ pxor mm7, mm7
+ punpcklbw mm2, mm0 // Unpack High bytes of b
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ psubw mm5, mm3
+ psubw mm4, mm3
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
+ // pav + pbv = pbv + pav
+ movq mm6, mm5
+ paddw mm6, mm4
+
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm5 // Create mask pbv bytes < 0
+ pcmpgtw mm7, mm4 // Create mask pav bytes < 0
+ pand mm0, mm5 // Only pbv bytes < 0 in mm0
+ pand mm7, mm4 // Only pav bytes < 0 in mm7
+ psubw mm5, mm0
+ psubw mm4, mm7
+ psubw mm5, mm0
+ psubw mm4, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ pand mm3, mm7
+ pandn mm7, mm0
+ pxor mm1, mm1
+ paddw mm7, mm3
+ pxor mm0, mm0
+ packuswb mm7, mm1
+ movq mm3, mm2 // load c=Prior(x-bpp) step 1
+ pand mm7, ActiveMask
+ punpckhbw mm2, mm0 // Unpack High bytes of b
+ psllq mm7, ShiftBpp // Shift bytes to 2nd group of 3 bytes
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
+ psllq mm3, ShiftBpp // load c=Prior(x-bpp) step 2
+ movq [edi + ebx], mm7 // write back updated value
+ movq mm1, mm7
+ punpckhbw mm3, mm0 // Unpack High bytes of c
+ psllq mm1, ShiftBpp // Shift bytes
+ // Now mm1 will be used as Raw(x-bpp)
+ // Now do Paeth for 3rd, and final, set of bytes (6-7)
+ pxor mm7, mm7
+ punpckhbw mm1, mm0 // Unpack High bytes of a
+ psubw mm4, mm3
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ pxor mm0, mm0
+ paddw mm6, mm5
+
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ pandn mm0, mm1
+ pandn mm7, mm4
+ paddw mm0, mm2
+ paddw mm7, mm5
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pand mm3, mm7
+ pandn mm7, mm0
+ paddw mm7, mm3
+ pxor mm1, mm1
+ packuswb mm1, mm7
+ // Step ebx to next set of 8 bytes and repeat loop til done
+ add ebx, 8
+ pand mm1, ActiveMaskEnd
+ paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
+
+ cmp ebx, MMXLength
+ pxor mm0, mm0 // pxor does not affect flags
+ movq [edi + ebx - 8], mm1 // write back updated value
+ // mm1 will be used as Raw(x-bpp) next loop
+ // mm3 ready to be used as Prior(x-bpp) next loop
+ jb dpth3lp
+ } // end _asm block
+ }
+ break;
+
+ case 6:
+ case 7:
+ case 5:
+ {
+ ActiveMask.use = 0x00000000ffffffff;
+ ActiveMask2.use = 0xffffffff00000000;
+ ShiftBpp.use = bpp << 3; // == bpp * 8
+ ShiftRem.use = 64 - ShiftBpp.use;
+ _asm
+ {
+ mov ebx, diff
+ mov edi, row
+ mov esi, prev_row
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8]
+ pxor mm0, mm0
+dpth6lp:
+ // Must shift to position Raw(x-bpp) data
+ psrlq mm1, ShiftRem
+ // Do first set of 4 bytes
+ movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
+ punpcklbw mm1, mm0 // Unpack Low bytes of a
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ punpcklbw mm2, mm0 // Unpack Low bytes of b
+ // Must shift to position Prior(x-bpp) data
+ psrlq mm3, ShiftRem
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ punpcklbw mm3, mm0 // Unpack Low bytes of c
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ paddw mm7, mm3
+ pxor mm0, mm0
+ packuswb mm7, mm1
+ movq mm3, [esi + ebx - 8] // load c=Prior(x-bpp)
+ pand mm7, ActiveMask
+ psrlq mm3, ShiftRem
+ movq mm2, [esi + ebx] // load b=Prior(x) step 1
+ paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
+ movq mm6, mm2
+ movq [edi + ebx], mm7 // write back updated value
+ movq mm1, [edi+ebx-8]
+ psllq mm6, ShiftBpp
+ movq mm5, mm7
+ psrlq mm1, ShiftRem
+ por mm3, mm6
+ psllq mm5, ShiftBpp
+ punpckhbw mm3, mm0 // Unpack High bytes of c
+ por mm1, mm5
+ // Do second set of 4 bytes
+ punpckhbw mm2, mm0 // Unpack High bytes of b
+ punpckhbw mm1, mm0 // Unpack High bytes of a
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ pxor mm1, mm1
+ paddw mm7, mm3
+ pxor mm0, mm0
+ // Step ex to next set of 8 bytes and repeat loop til done
+ add ebx, 8
+ packuswb mm1, mm7
+ paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
+ cmp ebx, MMXLength
+ movq [edi + ebx - 8], mm1 // write back updated value
+ // mm1 will be used as Raw(x-bpp) next loop
+ jb dpth6lp
+ } // end _asm block
+ }
+ break;
+
+ case 4:
+ {
+ ActiveMask.use = 0x00000000ffffffff;
+ _asm {
+ mov ebx, diff
+ mov edi, row
+ mov esi, prev_row
+ pxor mm0, mm0
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8] // Only time should need to read
+ // a=Raw(x-bpp) bytes
+dpth4lp:
+ // Do first set of 4 bytes
+ movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
+ punpckhbw mm1, mm0 // Unpack Low bytes of a
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ punpcklbw mm2, mm0 // Unpack High bytes of b
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ punpckhbw mm3, mm0 // Unpack High bytes of c
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ paddw mm7, mm3
+ pxor mm0, mm0
+ packuswb mm7, mm1
+ movq mm3, [esi + ebx] // load c=Prior(x-bpp)
+ pand mm7, ActiveMask
+ movq mm2, mm3 // load b=Prior(x) step 1
+ paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
+ punpcklbw mm3, mm0 // Unpack High bytes of c
+ movq [edi + ebx], mm7 // write back updated value
+ movq mm1, mm7 // Now mm1 will be used as Raw(x-bpp)
+ // Do second set of 4 bytes
+ punpckhbw mm2, mm0 // Unpack Low bytes of b
+ punpcklbw mm1, mm0 // Unpack Low bytes of a
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ pxor mm1, mm1
+ paddw mm7, mm3
+ pxor mm0, mm0
+ // Step ex to next set of 8 bytes and repeat loop til done
+ add ebx, 8
+ packuswb mm1, mm7
+ paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
+ cmp ebx, MMXLength
+ movq [edi + ebx - 8], mm1 // write back updated value
+ // mm1 will be used as Raw(x-bpp) next loop
+ jb dpth4lp
+ } // end _asm block
+ }
+ break;
+ case 8: // bpp == 8
+ {
+ ActiveMask.use = 0x00000000ffffffff;
+ _asm {
+ mov ebx, diff
+ mov edi, row
+ mov esi, prev_row
+ pxor mm0, mm0
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8] // Only time should need to read
+ // a=Raw(x-bpp) bytes
+dpth8lp:
+ // Do first set of 4 bytes
+ movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
+ punpcklbw mm1, mm0 // Unpack Low bytes of a
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ punpcklbw mm2, mm0 // Unpack Low bytes of b
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ punpcklbw mm3, mm0 // Unpack Low bytes of c
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ paddw mm7, mm3
+ pxor mm0, mm0
+ packuswb mm7, mm1
+ movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
+ pand mm7, ActiveMask
+ movq mm2, [esi + ebx] // load b=Prior(x)
+ paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
+ punpckhbw mm3, mm0 // Unpack High bytes of c
+ movq [edi + ebx], mm7 // write back updated value
+ movq mm1, [edi+ebx-8] // read a=Raw(x-bpp) bytes
+
+ // Do second set of 4 bytes
+ punpckhbw mm2, mm0 // Unpack High bytes of b
+ punpckhbw mm1, mm0 // Unpack High bytes of a
+ // pav = p - a = (a + b - c) - a = b - c
+ movq mm4, mm2
+ // pbv = p - b = (a + b - c) - b = a - c
+ movq mm5, mm1
+ psubw mm4, mm3
+ pxor mm7, mm7
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ movq mm6, mm4
+ psubw mm5, mm3
+ // pa = abs(p-a) = abs(pav)
+ // pb = abs(p-b) = abs(pbv)
+ // pc = abs(p-c) = abs(pcv)
+ pcmpgtw mm0, mm4 // Create mask pav bytes < 0
+ paddw mm6, mm5
+ pand mm0, mm4 // Only pav bytes < 0 in mm7
+ pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
+ psubw mm4, mm0
+ pand mm7, mm5 // Only pbv bytes < 0 in mm0
+ psubw mm4, mm0
+ psubw mm5, mm7
+ pxor mm0, mm0
+ pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
+ pand mm0, mm6 // Only pav bytes < 0 in mm7
+ psubw mm5, mm7
+ psubw mm6, mm0
+ // test pa <= pb
+ movq mm7, mm4
+ psubw mm6, mm0
+ pcmpgtw mm7, mm5 // pa > pb?
+ movq mm0, mm7
+ // use mm7 mask to merge pa & pb
+ pand mm5, mm7
+ // use mm0 mask copy to merge a & b
+ pand mm2, mm0
+ pandn mm7, mm4
+ pandn mm0, mm1
+ paddw mm7, mm5
+ paddw mm0, mm2
+ // test ((pa <= pb)? pa:pb) <= pc
+ pcmpgtw mm7, mm6 // pab > pc?
+ pxor mm1, mm1
+ pand mm3, mm7
+ pandn mm7, mm0
+ pxor mm1, mm1
+ paddw mm7, mm3
+ pxor mm0, mm0
+ // Step ex to next set of 8 bytes and repeat loop til done
+ add ebx, 8
+ packuswb mm1, mm7
+ paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
+ cmp ebx, MMXLength
+ movq [edi + ebx - 8], mm1 // write back updated value
+ // mm1 will be used as Raw(x-bpp) next loop
+ jb dpth8lp
+ } // end _asm block
+ }
+ break;
+
+ case 1: // bpp = 1
+ case 2: // bpp = 2
+ default: // bpp > 8
+ {
+ _asm {
+ mov ebx, diff
+ cmp ebx, FullLength
+ jnb dpthdend
+ mov edi, row
+ mov esi, prev_row
+ // Do Paeth decode for remaining bytes
+ mov edx, ebx
+ xor ecx, ecx // zero ecx before using cl & cx in loop below
+ sub edx, bpp // Set edx = ebx - bpp
+dpthdlp:
+ xor eax, eax
+ // pav = p - a = (a + b - c) - a = b - c
+ mov al, [esi + ebx] // load Prior(x) into al
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov patemp, eax // Save pav for later use
+ xor eax, eax
+ // pbv = p - b = (a + b - c) - b = a - c
+ mov al, [edi + edx] // load Raw(x-bpp) into al
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov ecx, eax
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ add eax, patemp // pcv = pav + pbv
+ // pc = abs(pcv)
+ test eax, 0x80000000
+ jz dpthdpca
+ neg eax // reverse sign of neg values
+dpthdpca:
+ mov pctemp, eax // save pc for later use
+ // pb = abs(pbv)
+ test ecx, 0x80000000
+ jz dpthdpba
+ neg ecx // reverse sign of neg values
+dpthdpba:
+ mov pbtemp, ecx // save pb for later use
+ // pa = abs(pav)
+ mov eax, patemp
+ test eax, 0x80000000
+ jz dpthdpaa
+ neg eax // reverse sign of neg values
+dpthdpaa:
+ mov patemp, eax // save pa for later use
+ // test if pa <= pb
+ cmp eax, ecx
+ jna dpthdabb
+ // pa > pb; now test if pb <= pc
+ cmp ecx, pctemp
+ jna dpthdbbc
+ // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthdpaeth
+dpthdbbc:
+ // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
+ mov cl, [esi + ebx] // load Prior(x) into cl
+ jmp dpthdpaeth
+dpthdabb:
+ // pa <= pb; now test if pa <= pc
+ cmp eax, pctemp
+ jna dpthdabc
+ // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthdpaeth
+dpthdabc:
+ // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
+ mov cl, [edi + edx] // load Raw(x-bpp) into cl
+dpthdpaeth:
+ inc ebx
+ inc edx
+ // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
+ add [edi + ebx - 1], cl
+ cmp ebx, FullLength
+ jb dpthdlp
+dpthdend:
+ } // end _asm block
+ }
+ return; // No need to go further with this one
+ } // end switch ( bpp )
+ _asm
+ {
+ // MMX acceleration complete now do clean-up
+ // Check if any remaining bytes left to decode
+ mov ebx, MMXLength
+ cmp ebx, FullLength
+ jnb dpthend
+ mov edi, row
+ mov esi, prev_row
+ // Do Paeth decode for remaining bytes
+ mov edx, ebx
+ xor ecx, ecx // zero ecx before using cl & cx in loop below
+ sub edx, bpp // Set edx = ebx - bpp
+dpthlp2:
+ xor eax, eax
+ // pav = p - a = (a + b - c) - a = b - c
+ mov al, [esi + ebx] // load Prior(x) into al
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov patemp, eax // Save pav for later use
+ xor eax, eax
+ // pbv = p - b = (a + b - c) - b = a - c
+ mov al, [edi + edx] // load Raw(x-bpp) into al
+ sub eax, ecx // subtract Prior(x-bpp)
+ mov ecx, eax
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ add eax, patemp // pcv = pav + pbv
+ // pc = abs(pcv)
+ test eax, 0x80000000
+ jz dpthpca2
+ neg eax // reverse sign of neg values
+dpthpca2:
+ mov pctemp, eax // save pc for later use
+ // pb = abs(pbv)
+ test ecx, 0x80000000
+ jz dpthpba2
+ neg ecx // reverse sign of neg values
+dpthpba2:
+ mov pbtemp, ecx // save pb for later use
+ // pa = abs(pav)
+ mov eax, patemp
+ test eax, 0x80000000
+ jz dpthpaa2
+ neg eax // reverse sign of neg values
+dpthpaa2:
+ mov patemp, eax // save pa for later use
+ // test if pa <= pb
+ cmp eax, ecx
+ jna dpthabb2
+ // pa > pb; now test if pb <= pc
+ cmp ecx, pctemp
+ jna dpthbbc2
+ // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthpaeth2
+dpthbbc2:
+ // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
+ mov cl, [esi + ebx] // load Prior(x) into cl
+ jmp dpthpaeth2
+dpthabb2:
+ // pa <= pb; now test if pa <= pc
+ cmp eax, pctemp
+ jna dpthabc2
+ // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ mov cl, [esi + edx] // load Prior(x-bpp) into cl
+ jmp dpthpaeth2
+dpthabc2:
+ // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
+ mov cl, [edi + edx] // load Raw(x-bpp) into cl
+dpthpaeth2:
+ inc ebx
+ inc edx
+ // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
+ add [edi + ebx - 1], cl
+ cmp ebx, FullLength
+ jb dpthlp2
+dpthend:
+ emms // End MMX instructions; prep for possible FP instrs.
+ } // end _asm block
+}
+
+// Optimized code for PNG Sub filter decoder
+void
+png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
+{
+ //int test;
+ int bpp;
+ png_uint_32 FullLength;
+ png_uint_32 MMXLength;
+ int diff;
+
+ bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
+ FullLength = row_info->rowbytes - bpp; // # of bytes to filter
+ _asm {
+ mov edi, row
+ mov esi, edi // lp = row
+ add edi, bpp // rp = row + bpp
+ xor eax, eax
+ // get # of bytes to alignment
+ mov diff, edi // take start of row
+ add diff, 0xf // add 7 + 8 to incr past
+ // alignment boundary
+ xor ebx, ebx
+ and diff, 0xfffffff8 // mask to alignment boundary
+ sub diff, edi // subtract from start ==> value
+ // ebx at alignment
+ jz dsubgo
+ // fix alignment
+dsublp1:
+ mov al, [esi+ebx]
+ add [edi+ebx], al
+ inc ebx
+ cmp ebx, diff
+ jb dsublp1
+dsubgo:
+ mov ecx, FullLength
+ mov edx, ecx
+ sub edx, ebx // subtract alignment fix
+ and edx, 0x00000007 // calc bytes over mult of 8
+ sub ecx, edx // drop over bytes from length
+ mov MMXLength, ecx
+ } // end _asm block
+
+ // Now do the math for the rest of the row
+ switch ( bpp )
+ {
+ case 3:
+ {
+ ActiveMask.use = 0x0000ffffff000000;
+ ShiftBpp.use = 24; // == 3 * 8
+ ShiftRem.use = 40; // == 64 - 24
+ _asm {
+ mov edi, row
+ movq mm7, ActiveMask // Load ActiveMask for 2nd active byte group
+ mov esi, edi // lp = row
+ add edi, bpp // rp = row + bpp
+ movq mm6, mm7
+ mov ebx, diff
+ psllq mm6, ShiftBpp // Move mask in mm6 to cover 3rd active
+ // byte group
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8]
+dsub3lp:
+ psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
+ // no need for mask; shift clears inactive bytes
+ // Add 1st active group
+ movq mm0, [edi+ebx]
+ paddb mm0, mm1
+ // Add 2nd active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ pand mm1, mm7 // mask to use only 2nd active group
+ paddb mm0, mm1
+ // Add 3rd active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ pand mm1, mm6 // mask to use only 3rd active group
+ add ebx, 8
+ paddb mm0, mm1
+ cmp ebx, MMXLength
+ movq [edi+ebx-8], mm0 // Write updated Raws back to array
+ // Prep for doing 1st add at top of loop
+ movq mm1, mm0
+ jb dsub3lp
+ } // end _asm block
+ }
+ break;
+
+ case 1:
+ {
+ // Placed here just in case this is a duplicate of the
+ // non-MMX code for the SUB filter in png_read_filter_row above
+ //
+ // png_bytep rp;
+ // png_bytep lp;
+ // png_uint_32 i;
+ // bpp = (row_info->pixel_depth + 7) >> 3;
+ // for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
+ // i < row_info->rowbytes; i++, rp++, lp++)
+ // {
+ // *rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
+ // }
+ _asm {
+ mov ebx, diff
+ mov edi, row
+ cmp ebx, FullLength
+ jnb dsub1end
+ mov esi, edi // lp = row
+ xor eax, eax
+ add edi, bpp // rp = row + bpp
+dsub1lp:
+ mov al, [esi+ebx]
+ add [edi+ebx], al
+ inc ebx
+ cmp ebx, FullLength
+ jb dsub1lp
+dsub1end:
+ } // end _asm block
+ }
+ return;
+
+ case 6:
+ case 7:
+ case 4:
+ case 5:
+ {
+ ShiftBpp.use = bpp << 3;
+ ShiftRem.use = 64 - ShiftBpp.use;
+ _asm {
+ mov edi, row
+ mov ebx, diff
+ mov esi, edi // lp = row
+ add edi, bpp // rp = row + bpp
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8]
+dsub4lp:
+ psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
+ // no need for mask; shift clears inactive bytes
+ movq mm0, [edi+ebx]
+ paddb mm0, mm1
+ // Add 2nd active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ // there is no need for any mask
+ // since shift clears inactive bits/bytes
+ add ebx, 8
+ paddb mm0, mm1
+ cmp ebx, MMXLength
+ movq [edi+ebx-8], mm0
+ movq mm1, mm0 // Prep for doing 1st add at top of loop
+ jb dsub4lp
+ } // end _asm block
+ }
+ break;
+
+ case 2:
+ {
+ ActiveMask.use = 0x00000000ffff0000;
+ ShiftBpp.use = 16; // == 2 * 8
+ ShiftRem.use = 48; // == 64 - 16
+ _asm {
+ movq mm7, ActiveMask // Load ActiveMask for 2nd active byte group
+ mov ebx, diff
+ movq mm6, mm7
+ mov edi, row
+ psllq mm6, ShiftBpp // Move mask in mm6 to cover 3rd active
+ // byte group
+ mov esi, edi // lp = row
+ movq mm5, mm6
+ add edi, bpp // rp = row + bpp
+ psllq mm5, ShiftBpp // Move mask in mm5 to cover 4th active
+ // byte group
+ // PRIME the pump (load the first Raw(x-bpp) data set
+ movq mm1, [edi+ebx-8]
+dsub2lp:
+ // Add 1st active group
+ psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
+ // no need for mask; shift clears inactive
+ // bytes
+ movq mm0, [edi+ebx]
+ paddb mm0, mm1
+ // Add 2nd active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ pand mm1, mm7 // mask to use only 2nd active group
+ paddb mm0, mm1
+ // Add 3rd active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ pand mm1, mm6 // mask to use only 3rd active group
+ paddb mm0, mm1
+ // Add 4th active group
+ movq mm1, mm0 // mov updated Raws to mm1
+ psllq mm1, ShiftBpp // shift data to position correctly
+ pand mm1, mm5 // mask to use only 4th active group
+ add ebx, 8
+ paddb mm0, mm1
+ cmp ebx, MMXLength
+ movq [edi+ebx-8], mm0 // Write updated Raws back to array
+ movq mm1, mm0 // Prep for doing 1st add at top of loop
+ jb dsub2lp
+ } // end _asm block
+ }
+ break;
+ case 8:
+ {
+ _asm {
+ mov edi, row
+ mov ebx, diff
+ mov esi, edi // lp = row
+ add edi, bpp // rp = row + bpp
+ mov ecx, MMXLength
+ movq mm7, [edi+ebx-8] // PRIME the pump (load the first
+ // Raw(x-bpp) data set
+ and ecx, 0x0000003f // calc bytes over mult of 64
+dsub8lp:
+ movq mm0, [edi+ebx] // Load Sub(x) for 1st 8 bytes
+ paddb mm0, mm7
+ movq mm1, [edi+ebx+8] // Load Sub(x) for 2nd 8 bytes
+ movq [edi+ebx], mm0 // Write Raw(x) for 1st 8 bytes
+ // Now mm0 will be used as Raw(x-bpp) for
+ // the 2nd group of 8 bytes. This will be
+ // repeated for each group of 8 bytes with
+ // the 8th group being used as the Raw(x-bpp)
+ // for the 1st group of the next loop.
+ paddb mm1, mm0
+ movq mm2, [edi+ebx+16] // Load Sub(x) for 3rd 8 bytes
+ movq [edi+ebx+8], mm1 // Write Raw(x) for 2nd 8 bytes
+ paddb mm2, mm1
+ movq mm3, [edi+ebx+24] // Load Sub(x) for 4th 8 bytes
+ movq [edi+ebx+16], mm2 // Write Raw(x) for 3rd 8 bytes
+ paddb mm3, mm2
+ movq mm4, [edi+ebx+32] // Load Sub(x) for 5th 8 bytes
+ movq [edi+ebx+24], mm3 // Write Raw(x) for 4th 8 bytes
+ paddb mm4, mm3
+ movq mm5, [edi+ebx+40] // Load Sub(x) for 6th 8 bytes
+ movq [edi+ebx+32], mm4 // Write Raw(x) for 5th 8 bytes
+ paddb mm5, mm4
+ movq mm6, [edi+ebx+48] // Load Sub(x) for 7th 8 bytes
+ movq [edi+ebx+40], mm5 // Write Raw(x) for 6th 8 bytes
+ paddb mm6, mm5
+ movq mm7, [edi+ebx+56] // Load Sub(x) for 8th 8 bytes
+ movq [edi+ebx+48], mm6 // Write Raw(x) for 7th 8 bytes
+ add ebx, 64
+ paddb mm7, mm6
+ cmp ebx, ecx
+ movq [edi+ebx-8], mm7 // Write Raw(x) for 8th 8 bytes
+ jb dsub8lp
+ cmp ebx, MMXLength
+ jnb dsub8lt8
+dsub8lpA:
+ movq mm0, [edi+ebx]
+ add ebx, 8
+ paddb mm0, mm7
+ cmp ebx, MMXLength
+ movq [edi+ebx-8], mm0 // use -8 to offset early add to ebx
+ movq mm7, mm0 // Move calculated Raw(x) data to mm1 to
+ // be the new Raw(x-bpp) for the next loop
+ jb dsub8lpA
+dsub8lt8:
+ } // end _asm block
+ }
+ break;
+
+ default: // bpp greater than 8 bytes
+ {
+ _asm {
+ mov ebx, diff
+ mov edi, row
+ mov esi, edi // lp = row
+ add edi, bpp // rp = row + bpp
+dsubAlp:
+ movq mm0, [edi+ebx]
+ movq mm1, [esi+ebx]
+ add ebx, 8
+ paddb mm0, mm1
+ cmp ebx, MMXLength
+ movq [edi+ebx-8], mm0 // mov does not affect flags; -8 to offset
+ // add ebx
+ jb dsubAlp
+ } // end _asm block
+ }
+ break;
+
+ } // end switch ( bpp )
+
+ _asm {
+ mov ebx, MMXLength
+ mov edi, row
+ cmp ebx, FullLength
+ jnb dsubend
+ mov esi, edi // lp = row
+ xor eax, eax
+ add edi, bpp // rp = row + bpp
+dsublp2:
+ mov al, [esi+ebx]
+ add [edi+ebx], al
+ inc ebx
+ cmp ebx, FullLength
+ jb dsublp2
+dsubend:
+ emms // End MMX instructions; prep for possible FP instrs.
+ } // end _asm block
+}
+
+// Optimized code for PNG Up filter decoder
+void
+png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
+ png_bytep prev_row)
+{
+ png_uint_32 len;
+ len = row_info->rowbytes; // # of bytes to filter
+ _asm {
+ mov edi, row
+ // get # of bytes to alignment
+ mov ecx, edi
+ xor ebx, ebx
+ add ecx, 0x7
+ xor eax, eax
+ and ecx, 0xfffffff8
+ mov esi, prev_row
+ sub ecx, edi
+ jz dupgo
+ // fix alignment
+duplp1:
+ mov al, [edi+ebx]
+ add al, [esi+ebx]
+ inc ebx
+ cmp ebx, ecx
+ mov [edi + ebx-1], al // mov does not affect flags; -1 to offset inc ebx
+ jb duplp1
+dupgo:
+ mov ecx, len
+ mov edx, ecx
+ sub edx, ebx // subtract alignment fix
+ and edx, 0x0000003f // calc bytes over mult of 64
+ sub ecx, edx // drop over bytes from length
+ // Unrolled loop - use all MMX registers and interleave to reduce
+ // number of branch instructions (loops) and reduce partial stalls
+duploop:
+ movq mm1, [esi+ebx]
+ movq mm0, [edi+ebx]
+ movq mm3, [esi+ebx+8]
+ paddb mm0, mm1
+ movq mm2, [edi+ebx+8]
+ movq [edi+ebx], mm0
+ paddb mm2, mm3
+ movq mm5, [esi+ebx+16]
+ movq [edi+ebx+8], mm2
+ movq mm4, [edi+ebx+16]
+ movq mm7, [esi+ebx+24]
+ paddb mm4, mm5
+ movq mm6, [edi+ebx+24]
+ movq [edi+ebx+16], mm4
+ paddb mm6, mm7
+ movq mm1, [esi+ebx+32]
+ movq [edi+ebx+24], mm6
+ movq mm0, [edi+ebx+32]
+ movq mm3, [esi+ebx+40]
+ paddb mm0, mm1
+ movq mm2, [edi+ebx+40]
+ movq [edi+ebx+32], mm0
+ paddb mm2, mm3
+ movq mm5, [esi+ebx+48]
+ movq [edi+ebx+40], mm2
+ movq mm4, [edi+ebx+48]
+ movq mm7, [esi+ebx+56]
+ paddb mm4, mm5
+ movq mm6, [edi+ebx+56]
+ movq [edi+ebx+48], mm4
+ add ebx, 64
+ paddb mm6, mm7
+ cmp ebx, ecx
+ movq [edi+ebx-8], mm6 // (+56)movq does not affect flags;
+ // -8 to offset add ebx
+ jb duploop
+
+ cmp edx, 0 // Test for bytes over mult of 64
+ jz dupend
+
+
+ // 2 lines added by lcreeve@netins.net
+ // (mail 11 Jul 98 in png-implement list)
+ cmp edx, 8 //test for less than 8 bytes
+ jb duplt8
+
+
+ add ecx, edx
+ and edx, 0x00000007 // calc bytes over mult of 8
+ sub ecx, edx // drop over bytes from length
+ jz duplt8
+ // Loop using MMX registers mm0 & mm1 to update 8 bytes simultaneously
+duplpA:
+ movq mm1, [esi+ebx]
+ movq mm0, [edi+ebx]
+ add ebx, 8
+ paddb mm0, mm1
+ cmp ebx, ecx
+ movq [edi+ebx-8], mm0 // movq does not affect flags; -8 to offset add ebx
+ jb duplpA
+ cmp edx, 0 // Test for bytes over mult of 8
+ jz dupend
+duplt8:
+ xor eax, eax
+ add ecx, edx // move over byte count into counter
+ // Loop using x86 registers to update remaining bytes
+duplp2:
+ mov al, [edi + ebx]
+ add al, [esi + ebx]
+ inc ebx
+ cmp ebx, ecx
+ mov [edi + ebx-1], al // mov does not affect flags; -1 to offset inc ebx
+ jb duplp2
+dupend:
+ // Conversion of filtered row completed
+ emms // End MMX instructions; prep for possible FP instrs.
+ } // end _asm block
+}
+
+
+// Optimized png_read_filter_row routines
+void
+png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
+ row, png_bytep prev_row, int filter)
+{
+#ifdef PNG_DEBUG
+ char filnm[6];
+#endif
+ #define UseMMX 1
+
+ if (mmx_supported == 2)
+ mmx_supported = mmxsupport();
+
+ if (!mmx_supported)
+ {
+ png_read_filter_row_c(png_ptr, row_info, row, prev_row, filter);
+ return ;
+ }
+
+#ifdef PNG_DEBUG
+ png_debug(1, "in png_read_filter_row\n");
+#if (UseMMX == 1)
+ png_debug1(0,"%s, ", "MMX");
+#else
+ png_debug1(0,"%s, ", "x86");
+#endif
+ switch (filter)
+ {
+ case 0: sprintf(filnm, "None ");
+ break;
+ case 1: sprintf(filnm, "Sub ");
+ break;
+ case 2: sprintf(filnm, "Up ");
+ break;
+ case 3: sprintf(filnm, "Avg ");
+ break;
+ case 4: sprintf(filnm, "Paeth");
+ break;
+ default: sprintf(filnm, "Unknw");
+ break;
+ }
+ png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm);
+ png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth,
+ (int)((row_info->pixel_depth + 7) >> 3));
+ png_debug1(0,"len=%8d, ", row_info->rowbytes);
+#endif
+
+ switch (filter)
+ {
+ case PNG_FILTER_VALUE_NONE:
+ break;
+ case PNG_FILTER_VALUE_SUB:
+ {
+#if (UseMMX == 1)
+ if ((row_info->pixel_depth > 8) &&
+ (row_info->rowbytes >= 128) )
+ {
+ png_read_filter_row_mmx_sub(row_info, row);
+ }
+ else
+#endif
+ {
+ png_uint_32 i;
+ png_uint_32 istop = row_info->rowbytes;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_bytep rp = row + bpp;
+ png_bytep lp = row;
+
+ for (i = bpp; i < istop; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
+ rp++;
+ }
+ } //end !UseMMX
+ break;
+ }
+ case PNG_FILTER_VALUE_UP:
+ {
+#if (UseMMX == 1)
+ if ((row_info->pixel_depth > 8) &&
+ (row_info->rowbytes >= 128) )
+ {
+ png_read_filter_row_mmx_up(row_info, row, prev_row);
+ } //end if UseMMX
+ else
+#endif
+ {
+ png_bytep rp;
+ png_bytep pp;
+ png_uint_32 i;
+ for (i = 0, rp = row, pp = prev_row;
+ i < row_info->rowbytes; i++, rp++, pp++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
+ }
+ } //end !UseMMX
+ break;
+ }
+ case PNG_FILTER_VALUE_AVG:
+ {
+#if (UseMMX == 1)
+ if ((row_info->pixel_depth > 8) &&
+ (row_info->rowbytes >= 128) )
+ {
+ png_read_filter_row_mmx_avg(row_info, row, prev_row);
+ } //end if UseMMX
+ else
+#endif
+ {
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_uint_32 istop = row_info->rowbytes - bpp;
+
+ for (i = 0; i < bpp; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) +
+ ((int)(*pp++) >> 1)) & 0xff);
+ rp++;
+ }
+
+ for (i = 0; i < istop; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) +
+ ((int)(*pp++ + *lp++) >> 1)) & 0xff);
+ rp++;
+ }
+ } //end !UseMMX
+ break;
+ }
+ case PNG_FILTER_VALUE_PAETH:
+ {
+#if (UseMMX == 1)
+ if ((row_info->pixel_depth > 8) &&
+ (row_info->rowbytes >= 128) )
+ {
+ png_read_filter_row_mmx_paeth(row_info, row, prev_row);
+ } //end if UseMMX
+ else
+#endif
+ {
+ png_uint_32 i;
+ png_bytep rp = row;
+ png_bytep pp = prev_row;
+ png_bytep lp = row;
+ png_bytep cp = prev_row;
+ png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
+ png_uint_32 istop=row_info->rowbytes - bpp;
+
+ for (i = 0; i < bpp; i++)
+ {
+ *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
+ rp++;
+ }
+
+ for (i = 0; i < istop; i++) // use leftover rp,pp
+ {
+ int a, b, c, pa, pb, pc, p;
+
+ a = *lp++;
+ b = *pp++;
+ c = *cp++;
+
+ p = b - c;
+ pc = a - c;
+
+#ifdef PNG_USE_ABS
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
+#else
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
+#endif
+
+ /*
+ if (pa <= pb && pa <= pc)
+ p = a;
+ else if (pb <= pc)
+ p = b;
+ else
+ p = c;
+ */
+
+ p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+
+ *rp = (png_byte)(((int)(*rp) + p) & 0xff);
+ rp++;
+ }
+ } //end !UseMMX
+ break;
+ }
+ default:
+ png_error(png_ptr, "Bad adaptive filter type");
+ break;
+ }
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngwio.c b/osframework/source/ImageLib/png/pngwio.c
new file mode 100644
index 0000000..c83cf05
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngwio.c
@@ -0,0 +1,213 @@
+
+/* pngwio.c - functions for data output
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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
diff --git a/osframework/source/ImageLib/png/pngwrite.c b/osframework/source/ImageLib/png/pngwrite.c
new file mode 100644
index 0000000..c204787
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngwrite.c
@@ -0,0 +1,1005 @@
+
+/* pngwrite.c - general routines to write a PNG file
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ */
+
+/* get internal access to png.h */
+#define PNG_INTERNAL
+#include "png.h"
+
+/* Writes all the PNG information. This is the suggested way to use the
+ * library. If you have a new chunk to add, make a function to write it,
+ * and put it in the correct location here. If you want the chunk written
+ * after the image data, put it in png_write_end(). I strongly encourage
+ * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
+ * the chunk, as that will keep the code from breaking if you want to just
+ * write a plain PNG file. If you have long comments, I suggest writing
+ * them in png_write_end(), and compressing them.
+ */
+void
+png_write_info(png_structp png_ptr, png_infop info_ptr)
+{
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+ int i;
+#endif
+
+ png_debug(1, "in png_write_info\n");
+ png_write_sig(png_ptr); /* write PNG signature */
+ /* write IHDR information. */
+ png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
+ info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
+ info_ptr->filter_type,
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ info_ptr->interlace_type);
+#else
+ 0);
+#endif
+ /* the rest of these check to see if the valid field has the appropriate
+ flag set, and if it does, writes the chunk. */
+#if defined(PNG_WRITE_gAMA_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_gAMA)
+ png_write_gAMA(png_ptr, info_ptr->gamma);
+#endif
+#if defined(PNG_WRITE_sRGB_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_sRGB)
+ png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
+#endif
+#if defined(PNG_WRITE_sBIT_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_sBIT)
+ png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
+#endif
+#if defined(PNG_WRITE_cHRM_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_cHRM)
+ png_write_cHRM(png_ptr,
+ info_ptr->x_white, info_ptr->y_white,
+ info_ptr->x_red, info_ptr->y_red,
+ info_ptr->x_green, info_ptr->y_green,
+ info_ptr->x_blue, info_ptr->y_blue);
+#endif
+ if (info_ptr->valid & PNG_INFO_PLTE)
+ png_write_PLTE(png_ptr, info_ptr->palette,
+ (png_uint_32)info_ptr->num_palette);
+ else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ png_error(png_ptr, "Valid palette required for paletted images\n");
+
+#if defined(PNG_WRITE_tRNS_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_tRNS)
+ {
+#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
+ /* invert the alpha channel (in tRNS) */
+ if (png_ptr->transformations & PNG_INVERT_ALPHA &&
+ info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ int j;
+ for (j=0; j<(int)info_ptr->num_trans; j++)
+ info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
+ }
+#endif
+ png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
+ info_ptr->num_trans, info_ptr->color_type);
+ }
+#endif
+#if defined(PNG_WRITE_bKGD_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_bKGD)
+ png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
+#endif
+#if defined(PNG_WRITE_hIST_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_hIST)
+ png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
+#endif
+#if defined(PNG_WRITE_oFFs_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_oFFs)
+ png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
+ info_ptr->offset_unit_type);
+#endif
+#if defined(PNG_WRITE_pCAL_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_pCAL)
+ png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
+ info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
+ info_ptr->pcal_units, info_ptr->pcal_params);
+#endif
+#if defined(PNG_WRITE_pHYs_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_pHYs)
+ png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
+ info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
+#endif
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+ if (info_ptr->valid & PNG_INFO_tIME)
+ {
+ png_write_tIME(png_ptr, &(info_ptr->mod_time));
+ png_ptr->flags |= PNG_FLAG_WROTE_tIME;
+ }
+#endif
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+ /* Check to see if we need to write text chunks */
+ for (i = 0; i < info_ptr->num_text; i++)
+ {
+ png_debug2(2, "Writing header text chunk %d, type %d\n", i,
+ info_ptr->text[i].compression);
+ /* If we want a compressed text chunk */
+ if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
+ {
+#if defined(PNG_WRITE_zTXt_SUPPORTED)
+ /* write compressed chunk */
+ png_write_zTXt(png_ptr, info_ptr->text[i].key,
+ info_ptr->text[i].text, info_ptr->text[i].text_length,
+ info_ptr->text[i].compression);
+#else
+ png_warning(png_ptr, "Unable to write compressed text\n");
+#endif
+ /* Mark this chunk as written */
+ info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
+ }
+ else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
+ {
+#if defined(PNG_WRITE_tEXt_SUPPORTED)
+ /* write uncompressed chunk */
+ png_write_tEXt(png_ptr, info_ptr->text[i].key,
+ info_ptr->text[i].text, info_ptr->text[i].text_length);
+#else
+ png_warning(png_ptr, "Unable to write uncompressed text\n");
+#endif
+ /* Mark this chunk as written */
+ info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
+ }
+ }
+#endif
+}
+
+/* Writes the end of the PNG file. If you don't want to write comments or
+ * time information, you can pass NULL for info. If you already wrote these
+ * in png_write_info(), do not write them again here. If you have long
+ * comments, I suggest writing them here, and compressing them.
+ */
+void
+png_write_end(png_structp png_ptr, png_infop info_ptr)
+{
+ png_debug(1, "in png_write_end\n");
+ if (!(png_ptr->mode & PNG_HAVE_IDAT))
+ png_error(png_ptr, "No IDATs written into file");
+
+ /* see if user wants us to write information chunks */
+ if (info_ptr != NULL)
+ {
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+ int i; /* local index variable */
+#endif
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+ /* check to see if user has supplied a time chunk */
+ if (info_ptr->valid & PNG_INFO_tIME &&
+ !(png_ptr->flags & PNG_FLAG_WROTE_tIME))
+ png_write_tIME(png_ptr, &(info_ptr->mod_time));
+#endif
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
+ /* loop through comment chunks */
+ for (i = 0; i < info_ptr->num_text; i++)
+ {
+ png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
+ info_ptr->text[i].compression);
+ if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
+ {
+#if defined(PNG_WRITE_zTXt_SUPPORTED)
+ /* write compressed chunk */
+ png_write_zTXt(png_ptr, info_ptr->text[i].key,
+ info_ptr->text[i].text, info_ptr->text[i].text_length,
+ info_ptr->text[i].compression);
+#else
+ png_warning(png_ptr, "Unable to write compressed text\n");
+#endif
+ /* Mark this chunk as written */
+ info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
+ }
+ else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
+ {
+#if defined(PNG_WRITE_tEXt_SUPPORTED)
+ /* write uncompressed chunk */
+ png_write_tEXt(png_ptr, info_ptr->text[i].key,
+ info_ptr->text[i].text, info_ptr->text[i].text_length);
+#else
+ png_warning(png_ptr, "Unable to write uncompressed text\n");
+#endif
+
+ /* Mark this chunk as written */
+ info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
+ }
+ }
+#endif
+ }
+
+ png_ptr->mode |= PNG_AFTER_IDAT;
+
+ /* write end of PNG file */
+ png_write_IEND(png_ptr);
+}
+
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+void
+png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
+{
+ png_debug(1, "in png_convert_from_struct_tm\n");
+ ptime->year = (png_uint_16)(1900 + ttime->tm_year);
+ ptime->month = (png_byte)(ttime->tm_mon + 1);
+ ptime->day = (png_byte)ttime->tm_mday;
+ ptime->hour = (png_byte)ttime->tm_hour;
+ ptime->minute = (png_byte)ttime->tm_min;
+ ptime->second = (png_byte)ttime->tm_sec;
+}
+
+void
+png_convert_from_time_t(png_timep ptime, time_t ttime)
+{
+ struct tm *tbuf;
+
+ png_debug(1, "in png_convert_from_time_t\n");
+ tbuf = gmtime(&ttime);
+ png_convert_from_struct_tm(ptime, tbuf);
+}
+#endif
+
+/* Initialize png_ptr structure, and allocate any memory needed */
+png_structp
+png_create_write_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_write_struct_2(user_png_ver, error_ptr, error_fn,
+ warn_fn, NULL, NULL, NULL));
+}
+
+/* Alternate initialize png_ptr structure, and allocate any memory needed */
+png_structp
+png_create_write_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_write_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 /* PNG_USER_MEM_SUPPORTED */
+ {
+ 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] ||
+ (png_libpng_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_set_write_fn(png_ptr, NULL, NULL, NULL);
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
+ 1, NULL, NULL);
+#endif
+
+ return ((png_structp)png_ptr);
+}
+
+/* Initialize png_ptr structure, and allocate any memory needed */
+void
+png_write_init(png_structp png_ptr)
+{
+ jmp_buf tmp_jmp; /* to save current jump buffer */
+
+ png_debug(1, "in png_write_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_set_write_fn(png_ptr, NULL, NULL, NULL);
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
+ 1, NULL, NULL);
+#endif
+}
+
+/* Write a few rows of image data. If the image is interlaced,
+ * either you will have to write the 7 sub images, or, if you
+ * have called png_set_interlace_handling(), you will have to
+ * "write" the image seven times.
+ */
+void
+png_write_rows(png_structp png_ptr, png_bytepp row,
+ png_uint_32 num_rows)
+{
+ png_uint_32 i; /* row counter */
+ png_bytepp rp; /* row pointer */
+
+ png_debug(1, "in png_write_rows\n");
+ /* loop through the rows */
+ for (i = 0, rp = row; i < num_rows; i++, rp++)
+ {
+ png_write_row(png_ptr, *rp);
+ }
+}
+
+/* Write the image. You only need to call this function once, even
+ * if you are writing an interlaced image.
+ */
+void
+png_write_image(png_structp png_ptr, png_bytepp image)
+{
+ png_uint_32 i; /* row index */
+ int pass, num_pass; /* pass variables */
+ png_bytepp rp; /* points to current row */
+
+ png_debug(1, "in png_write_image\n");
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ /* intialize interlace handling. If image is not interlaced,
+ this will set pass to 1 */
+ num_pass = png_set_interlace_handling(png_ptr);
+#else
+ num_pass = 1;
+#endif
+ /* loop through passes */
+ for (pass = 0; pass < num_pass; pass++)
+ {
+ /* loop through image */
+ for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
+ {
+ png_write_row(png_ptr, *rp);
+ }
+ }
+}
+
+/* called by user to write a row of image data */
+void
+png_write_row(png_structp png_ptr, png_bytep row)
+{
+ png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
+ png_ptr->row_number, png_ptr->pass);
+ /* initialize transformations and other stuff if first time */
+ 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_WRITE_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_WRITE_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_WRITE_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_WRITE_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_WRITE_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_WRITE_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_WRITE_SWAP_SUPPORTED is not defined.");
+#endif
+
+ png_write_start_row(png_ptr);
+ }
+
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ /* if interlaced and not interested in row, return */
+ if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
+ {
+ switch (png_ptr->pass)
+ {
+ case 0:
+ if (png_ptr->row_number & 7)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 1:
+ if ((png_ptr->row_number & 7) || png_ptr->width < 5)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 2:
+ if ((png_ptr->row_number & 7) != 4)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 3:
+ if ((png_ptr->row_number & 3) || png_ptr->width < 3)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 4:
+ if ((png_ptr->row_number & 3) != 2)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 5:
+ if ((png_ptr->row_number & 1) || png_ptr->width < 2)
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ case 6:
+ if (!(png_ptr->row_number & 1))
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ break;
+ }
+ }
+#endif
+
+ /* set up row info for transformations */
+ png_ptr->row_info.color_type = png_ptr->color_type;
+ png_ptr->row_info.width = png_ptr->usr_width;
+ png_ptr->row_info.channels = png_ptr->usr_channels;
+ png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
+ png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
+ png_ptr->row_info.channels);
+
+ png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
+ (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
+
+ png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
+ png_debug1(3, "row_info->width = %d\n", png_ptr->row_info.width);
+ png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
+ png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
+ png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
+ png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes);
+
+ /* Copy user's row into buffer, leaving room for filter byte. */
+ png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
+ png_ptr->row_info.rowbytes);
+
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+ /* handle interlacing */
+ if (png_ptr->interlaced && png_ptr->pass < 6 &&
+ (png_ptr->transformations & PNG_INTERLACE))
+ {
+ png_do_write_interlace(&(png_ptr->row_info),
+ png_ptr->row_buf + 1, png_ptr->pass);
+ /* this should always get caught above, but still ... */
+ if (!(png_ptr->row_info.width))
+ {
+ png_write_finish_row(png_ptr);
+ return;
+ }
+ }
+#endif
+
+ /* handle other transformations */
+ if (png_ptr->transformations)
+ png_do_write_transformations(png_ptr);
+
+ /* Find a filter if necessary, filter the row and write it out. */
+ png_write_find_filter(png_ptr, &(png_ptr->row_info));
+
+ if (png_ptr->write_row_fn != NULL)
+ (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
+}
+
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+/* Set the automatic flush interval or 0 to turn flushing off */
+void
+png_set_flush(png_structp png_ptr, int nrows)
+{
+ png_debug(1, "in png_set_flush\n");
+ png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
+}
+
+/* flush the current output buffers now */
+void
+png_write_flush(png_structp png_ptr)
+{
+ int wrote_IDAT;
+
+ png_debug(1, "in png_write_flush\n");
+ /* We have already written out all of the data */
+ if (png_ptr->row_number >= png_ptr->num_rows)
+ return;
+
+ do
+ {
+ int ret;
+
+ /* compress the data */
+ ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
+ wrote_IDAT = 0;
+
+ /* check for compression errors */
+ if (ret != Z_OK)
+ {
+ if (png_ptr->zstream.msg != NULL)
+ png_error(png_ptr, png_ptr->zstream.msg);
+ else
+ png_error(png_ptr, "zlib error");
+ }
+
+ if (!(png_ptr->zstream.avail_out))
+ {
+ /* write the IDAT and reset the zlib output buffer */
+ png_write_IDAT(png_ptr, png_ptr->zbuf,
+ png_ptr->zbuf_size);
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ wrote_IDAT = 1;
+ }
+ } while(wrote_IDAT == 1);
+
+ /* If there is any data left to be output, write it into a new IDAT */
+ if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
+ {
+ /* write the IDAT and reset the zlib output buffer */
+ png_write_IDAT(png_ptr, png_ptr->zbuf,
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ }
+ png_ptr->flush_rows = 0;
+ png_flush(png_ptr);
+}
+#endif /* PNG_WRITE_FLUSH_SUPPORTED */
+
+/* free all memory used by the write */
+void
+png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
+{
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+#ifdef PNG_USER_MEM_SUPPORTED
+ png_free_ptr free_fn = NULL;
+#endif
+
+ png_debug(1, "in png_destroy_write_struct\n");
+ if (png_ptr_ptr != NULL)
+ {
+ png_ptr = *png_ptr_ptr;
+#ifdef PNG_USER_MEM_SUPPORTED
+ free_fn = png_ptr->free_fn;
+#endif
+ }
+
+ if (info_ptr_ptr != NULL)
+ info_ptr = *info_ptr_ptr;
+
+ if (info_ptr != NULL)
+ {
+#ifdef PNG_WRITE_tEXt_SUPPORTED
+ 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
+#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 (png_ptr != NULL)
+ {
+ png_write_destroy(png_ptr);
+#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 any memory used in png_ptr struct (old method) */
+void
+png_write_destroy(png_structp png_ptr)
+{
+ jmp_buf tmp_jmp; /* save jump buffer */
+ 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_write_destroy\n");
+ /* free any memory zlib uses */
+ deflateEnd(&png_ptr->zstream);
+
+ /* free our memory. png_free checks NULL for us. */
+ png_free(png_ptr, png_ptr->zbuf);
+ png_free(png_ptr, png_ptr->row_buf);
+ png_free(png_ptr, png_ptr->prev_row);
+ png_free(png_ptr, png_ptr->sub_row);
+ png_free(png_ptr, png_ptr->up_row);
+ png_free(png_ptr, png_ptr->avg_row);
+ png_free(png_ptr, png_ptr->paeth_row);
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+ png_free(png_ptr, png_ptr->time_buffer);
+#endif /* PNG_TIME_RFC1123_SUPPORTED */
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ png_free(png_ptr, png_ptr->prev_filters);
+ png_free(png_ptr, png_ptr->filter_weights);
+ png_free(png_ptr, png_ptr->inv_filter_weights);
+ png_free(png_ptr, png_ptr->filter_costs);
+ png_free(png_ptr, png_ptr->inv_filter_costs);
+#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
+
+ /* reset structure */
+ 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));
+}
+
+/* Allow the application to select one or more row filters to use. */
+void
+png_set_filter(png_structp png_ptr, int method, int filters)
+{
+ png_debug(1, "in png_set_filter\n");
+ /* We allow 'method' only for future expansion of the base filter method. */
+ if (method == PNG_FILTER_TYPE_BASE)
+ {
+ switch (filters & (PNG_ALL_FILTERS | 0x07))
+ {
+ case 5:
+ case 6:
+ case 7: png_warning(png_ptr, "Unknown row filter for method 0");
+ case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break;
+ case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break;
+ case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break;
+ case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break;
+ case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break;
+ default: png_ptr->do_filter = (png_byte)filters; break;
+ }
+
+ /* If we have allocated the row_buf, this means we have already started
+ * with the image and we should have allocated all of the filter buffers
+ * that have been selected. If prev_row isn't already allocated, then
+ * it is too late to start using the filters that need it, since we
+ * will be missing the data in the previous row. If an application
+ * wants to start and stop using particular filters during compression,
+ * it should start out with all of the filters, and then add and
+ * remove them after the start of compression.
+ */
+ if (png_ptr->row_buf != NULL)
+ {
+ if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
+ {
+ png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
+ }
+
+ if (png_ptr->do_filter & PNG_FILTER_UP && png_ptr->up_row == NULL)
+ {
+ if (png_ptr->prev_row == NULL)
+ {
+ png_warning(png_ptr, "Can't add Up filter after starting");
+ png_ptr->do_filter &= ~PNG_FILTER_UP;
+ }
+ else
+ {
+ png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
+ }
+ }
+
+ if (png_ptr->do_filter & PNG_FILTER_AVG && png_ptr->avg_row == NULL)
+ {
+ if (png_ptr->prev_row == NULL)
+ {
+ png_warning(png_ptr, "Can't add Average filter after starting");
+ png_ptr->do_filter &= ~PNG_FILTER_AVG;
+ }
+ else
+ {
+ png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
+ }
+ }
+
+ if (png_ptr->do_filter & PNG_FILTER_PAETH &&
+ png_ptr->paeth_row == NULL)
+ {
+ if (png_ptr->prev_row == NULL)
+ {
+ png_warning(png_ptr, "Can't add Paeth filter after starting");
+ png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
+ }
+ else
+ {
+ png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
+ }
+ }
+
+ if (png_ptr->do_filter == PNG_NO_FILTERS)
+ png_ptr->do_filter = PNG_FILTER_NONE;
+ }
+ }
+ else
+ png_error(png_ptr, "Unknown custom filter method");
+}
+
+/* This allows us to influence the way in which libpng chooses the "best"
+ * filter for the current scanline. While the "minimum-sum-of-absolute-
+ * differences metric is relatively fast and effective, there is some
+ * question as to whether it can be improved upon by trying to keep the
+ * filtered data going to zlib more consistent, hopefully resulting in
+ * better compression.
+ */
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
+void
+png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
+ int num_weights, png_doublep filter_weights,
+ png_doublep filter_costs)
+{
+ int i;
+
+ png_debug(1, "in png_set_filter_heuristics\n");
+ if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
+ {
+ png_warning(png_ptr, "Unknown filter heuristic method");
+ return;
+ }
+
+ if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
+ {
+ heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
+ }
+
+ if (num_weights < 0 || filter_weights == NULL ||
+ heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
+ {
+ num_weights = 0;
+ }
+
+ png_ptr->num_prev_filters = (png_byte)num_weights;
+ png_ptr->heuristic_method = (png_byte)heuristic_method;
+
+ if (num_weights > 0)
+ {
+ if (png_ptr->prev_filters == NULL)
+ {
+ png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)(sizeof(png_byte) * num_weights));
+
+ /* To make sure that the weighting starts out fairly */
+ for (i = 0; i < num_weights; i++)
+ {
+ png_ptr->prev_filters[i] = 255;
+ }
+ }
+
+ if (png_ptr->filter_weights == NULL)
+ {
+ png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr,
+ (png_uint_32)(sizeof(png_uint_16) * num_weights));
+
+ png_ptr->inv_filter_weights = (png_uint_16p) png_malloc(png_ptr,
+ (png_uint_32)(sizeof(png_uint_16) * num_weights));
+
+ for (i = 0; i < num_weights; i++)
+ {
+ png_ptr->inv_filter_weights[i] =
+ png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
+ }
+ }
+
+ for (i = 0; i < num_weights; i++)
+ {
+ if (filter_weights[i] < 0.0)
+ {
+ png_ptr->inv_filter_weights[i] =
+ png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
+ }
+ else
+ {
+ png_ptr->inv_filter_weights[i] =
+ (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
+ png_ptr->filter_weights[i] =
+ (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
+ }
+ }
+ }
+
+ /* If, in the future, there are other filter methods, this would
+ * need to be based on png_ptr->filter.
+ */
+ if (png_ptr->filter_costs == NULL)
+ {
+ png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr,
+ (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
+
+ png_ptr->inv_filter_costs = (png_uint_16p) png_malloc(png_ptr,
+ (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
+
+ for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
+ {
+ png_ptr->inv_filter_costs[i] =
+ png_ptr->filter_costs[i] = PNG_COST_FACTOR;
+ }
+ }
+
+ /* Here is where we set the relative costs of the different filters. We
+ * should take the desired compression level into account when setting
+ * the costs, so that Paeth, for instance, has a high relative cost at low
+ * compression levels, while it has a lower relative cost at higher
+ * compression settings. The filter types are in order of increasing
+ * relative cost, so it would be possible to do this with an algorithm.
+ */
+ for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
+ {
+ if (filter_costs == NULL || filter_costs[i] < 0.0)
+ {
+ png_ptr->inv_filter_costs[i] =
+ png_ptr->filter_costs[i] = PNG_COST_FACTOR;
+ }
+ else if (filter_costs[i] >= 1.0)
+ {
+ png_ptr->inv_filter_costs[i] =
+ (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
+ png_ptr->filter_costs[i] =
+ (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
+ }
+ }
+}
+#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
+
+void
+png_set_compression_level(png_structp png_ptr, int level)
+{
+ png_debug(1, "in png_set_compression_level\n");
+ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
+ png_ptr->zlib_level = level;
+}
+
+void
+png_set_compression_mem_level(png_structp png_ptr, int mem_level)
+{
+ png_debug(1, "in png_set_compression_mem_level\n");
+ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
+ png_ptr->zlib_mem_level = mem_level;
+}
+
+void
+png_set_compression_strategy(png_structp png_ptr, int strategy)
+{
+ png_debug(1, "in png_set_compression_strategy\n");
+ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
+ png_ptr->zlib_strategy = strategy;
+}
+
+void
+png_set_compression_window_bits(png_structp png_ptr, int window_bits)
+{
+ if (window_bits > 15)
+ png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
+ else if (window_bits < 8)
+ png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
+ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
+ png_ptr->zlib_window_bits = window_bits;
+}
+
+void
+png_set_compression_method(png_structp png_ptr, int method)
+{
+ png_debug(1, "in png_set_compression_method\n");
+ if (method != 8)
+ png_warning(png_ptr, "Only compression method 8 is supported by PNG");
+ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
+ png_ptr->zlib_method = method;
+}
+
+void
+png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
+{
+ png_ptr->write_row_fn = write_row_fn;
+}
+
+#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
+void
+png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
+ write_user_transform_fn)
+{
+ png_debug(1, "in png_set_write_user_transform_fn\n");
+ png_ptr->transformations |= PNG_USER_TRANSFORM;
+ png_ptr->write_user_transform_fn = write_user_transform_fn;
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngwtran.c b/osframework/source/ImageLib/png/pngwtran.c
new file mode 100644
index 0000000..530a71d
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngwtran.c
@@ -0,0 +1,497 @@
+
+/* pngwtran.c - transforms the data in a row for PNG writers
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 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_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_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_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)(((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++) = (png_byte)(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++) = (png_byte)(255 - *(sp++));
+ *(dp++) = (png_byte)(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++) = (png_byte)(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++) = (png_byte)(255 - *(sp++));
+ *(dp++) = (png_byte)(255 - *(sp++));
+ }
+ }
+ }
+ }
+}
+#endif
diff --git a/osframework/source/ImageLib/png/pngwutil.c b/osframework/source/ImageLib/png/pngwutil.c
new file mode 100644
index 0000000..7094402
--- /dev/null
+++ b/osframework/source/ImageLib/png/pngwutil.c
@@ -0,0 +1,2078 @@
+
+/* pngwutil.c - utilities to write a PNG file
+ *
+ * libpng 1.0.5 - October 15, 1999
+ * 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, 1999 Glenn Randers-Pehrson
+ */
+
+#define PNG_INTERNAL
+#include "png.h"
+
+/* Place a 32-bit number into a buffer in PNG byte order. We work
+ * with unsigned numbers for convenience, although one supported
+ * ancillary chunk uses signed (two's complement) numbers.
+ */
+void
+png_save_uint_32(png_bytep buf, png_uint_32 i)
+{
+ buf[0] = (png_byte)((i >> 24) & 0xff);
+ buf[1] = (png_byte)((i >> 16) & 0xff);
+ buf[2] = (png_byte)((i >> 8) & 0xff);
+ buf[3] = (png_byte)(i & 0xff);
+}
+
+#if defined(PNG_WRITE_pCAL_SUPPORTED)
+/* The png_save_int_32 function assumes integers are stored in two's
+ * complement format. If this isn't the case, then this routine needs to
+ * be modified to write data in two's complement format.
+ */
+void
+png_save_int_32(png_bytep buf, png_int_32 i)
+{
+ buf[0] = (png_byte)((i >> 24) & 0xff);
+ buf[1] = (png_byte)((i >> 16) & 0xff);
+ buf[2] = (png_byte)((i >> 8) & 0xff);
+ buf[3] = (png_byte)(i & 0xff);
+}
+#endif
+
+/* Place a 16-bit number into a buffer in PNG byte order.
+ * The parameter is declared unsigned int, not png_uint_16,
+ * just to avoid potential problems on pre-ANSI C compilers.
+ */
+void
+png_save_uint_16(png_bytep buf, unsigned int i)
+{
+ buf[0] = (png_byte)((i >> 8) & 0xff);
+ buf[1] = (png_byte)(i & 0xff);
+}
+
+/* Write a PNG chunk all at once. The type is an array of ASCII characters
+ * representing the chunk name. The array must be at least 4 bytes in
+ * length, and does not need to be null terminated. To be safe, pass the
+ * pre-defined chunk names here, and if you need a new one, define it
+ * where the others are defined. The length is the length of the data.
+ * All the data must be present. If that is not possible, use the
+ * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()
+ * functions instead.
+ */
+void
+png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
+ png_bytep data, png_size_t length)
+{
+ png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
+ png_write_chunk_data(png_ptr, data, length);
+ png_write_chunk_end(png_ptr);
+}
+
+/* Write the start of a PNG chunk. The type is the chunk type.
+ * The total_length is the sum of the lengths of all the data you will be
+ * passing in png_write_chunk_data().
+ */
+void
+png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
+ png_uint_32 length)
+{
+ png_byte buf[4];
+ png_debug2(0, "Writing %s chunk (%d bytes)\n", chunk_name, length);
+
+ /* write the length */
+ png_save_uint_32(buf, length);
+ png_write_data(png_ptr, buf, (png_size_t)4);
+
+ /* write the chunk name */
+ png_write_data(png_ptr, chunk_name, (png_size_t)4);
+ /* reset the crc and run it over the chunk name */
+ png_reset_crc(png_ptr);
+ png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
+}
+
+/* Write the data of a PNG chunk started with png_write_chunk_start().
+ * Note that multiple calls to this function are allowed, and that the
+ * sum of the lengths from these calls *must* add up to the total_length
+ * given to png_write_chunk_start().
+ */
+void
+png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
+{
+ /* write the data, and run the CRC over it */
+ if (data != NULL && length > 0)
+ {
+ png_calculate_crc(png_ptr, data, length);
+ png_write_data(png_ptr, data, length);
+ }
+}
+
+/* Finish a chunk started with png_write_chunk_start(). */
+void
+png_write_chunk_end(png_structp png_ptr)
+{
+ png_byte buf[4];
+
+ /* write the crc */
+ png_save_uint_32(buf, png_ptr->crc);
+
+ png_write_data(png_ptr, buf, (png_size_t)4);
+}
+
+/* Simple function to write the signature. If we have already written
+ * the magic bytes of the signature, or more likely, the PNG stream is
+ * being embedded into another stream and doesn't need its own signature,
+ * we should call png_set_sig_bytes() to tell libpng how many of the
+ * bytes have already been written.
+ */
+void
+png_write_sig(png_structp png_ptr)
+{
+ /* write the rest of the 8 byte signature */
+ png_write_data(png_ptr, &png_sig[png_ptr->sig_bytes],
+ (png_size_t)8 - png_ptr->sig_bytes);
+}
+
+/* Write the IHDR chunk, and update the png_struct with the necessary
+ * information. Note that the rest of this code depends upon this
+ * information being correct.
+ */
+void
+png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
+ int bit_depth, int color_type, int compression_type, int filter_type,
+ int interlace_type)
+{
+ png_byte buf[13]; /* buffer to store the IHDR info */
+
+ png_debug(1, "in png_write_IHDR\n");
+ /* Check that we have valid input data from the application info */
+ switch (color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ switch (bit_depth)
+ {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16: png_ptr->channels = 1; break;
+ default: png_error(png_ptr,"Invalid bit depth for grayscale image");
+ }
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ if (bit_depth != 8 && bit_depth != 16)
+ png_error(png_ptr, "Invalid bit depth for RGB image");
+ png_ptr->channels = 3;
+ break;
+ case PNG_COLOR_TYPE_PALETTE:
+ switch (bit_depth)
+ {
+ case 1:
+ case 2:
+ case 4:
+ case 8: png_ptr->channels = 1; break;
+ default: png_error(png_ptr, "Invalid bit depth for paletted image");
+ }
+ break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ if (bit_depth != 8 && bit_depth != 16)
+ png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
+ png_ptr->channels = 2;
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ if (bit_depth != 8 && bit_depth != 16)
+ png_error(png_ptr, "Invalid bit depth for RGBA image");
+ png_ptr->channels = 4;
+ break;
+ default:
+ png_error(png_ptr, "Invalid image color type specified");
+ }
+
+ if (compression_type != PNG_COMPRESSION_TYPE_BASE)
+ {
+ png_warning(png_ptr, "Invalid compression type specified");
+ compression_type = PNG_COMPRESSION_TYPE_BASE;
+ }
+
+ if (filter_type != PNG_FILTER_TYPE_BASE)
+ {
+ png_warning(png_ptr, "Invalid filter type specified");
+ filter_type = PNG_FILTER_TYPE_BASE;
+ }
+
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
+ if (interlace_type != PNG_INTERLACE_NONE &&
+ interlace_type != PNG_INTERLACE_ADAM7)
+ {
+ png_warning(png_ptr, "Invalid interlace type specified");
+ interlace_type = PNG_INTERLACE_ADAM7;
+ }
+#else
+ interlace_type=PNG_INTERLACE_NONE;
+#endif
+
+ /* save off the relevent information */
+ png_ptr->bit_depth = (png_byte)bit_depth;
+ png_ptr->color_type = (png_byte)color_type;
+ png_ptr->interlaced = (png_byte)interlace_type;
+ png_ptr->width = width;
+ png_ptr->height = height;
+
+ png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
+ png_ptr->rowbytes = ((width * (png_size_t)png_ptr->pixel_depth + 7) >> 3);
+ /* set the usr info, so any transformations can modify it */
+ png_ptr->usr_width = png_ptr->width;
+ png_ptr->usr_bit_depth = png_ptr->bit_depth;
+ png_ptr->usr_channels = png_ptr->channels;
+
+ /* pack the header information into the buffer */
+ png_save_uint_32(buf, width);
+ png_save_uint_32(buf + 4, height);
+ buf[8] = (png_byte)bit_depth;
+ buf[9] = (png_byte)color_type;
+ buf[10] = (png_byte)compression_type;
+ buf[11] = (png_byte)filter_type;
+ buf[12] = (png_byte)interlace_type;
+
+ /* write the chunk */
+ png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
+
+ /* initialize zlib with PNG info */
+ png_ptr->zstream.zalloc = png_zalloc;
+ png_ptr->zstream.zfree = png_zfree;
+ png_ptr->zstream.opaque = (voidpf)png_ptr;
+ if (!(png_ptr->do_filter))
+ {
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
+ png_ptr->bit_depth < 8)
+ png_ptr->do_filter = PNG_FILTER_NONE;
+ else
+ png_ptr->do_filter = PNG_ALL_FILTERS;
+ }
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
+ {
+ if (png_ptr->do_filter != PNG_FILTER_NONE)
+ png_ptr->zlib_strategy = Z_FILTERED;
+ else
+ png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
+ }
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
+ png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
+ png_ptr->zlib_mem_level = 8;
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
+ png_ptr->zlib_window_bits = 15;
+ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
+ png_ptr->zlib_method = 8;
+ deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
+ png_ptr->zlib_method, png_ptr->zlib_window_bits,
+ png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+
+ png_ptr->mode = PNG_HAVE_IHDR;
+}
+
+/* write the palette. We are careful not to trust png_color to be in the
+ * correct order for PNG, so people can redefine it to any convenient
+ * structure.
+ */
+void
+png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
+{
+ png_uint_32 i;
+ png_colorp pal_ptr;
+ png_byte buf[3];
+
+ png_debug(1, "in png_write_PLTE\n");
+ if ((
+#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
+ !png_ptr->empty_plte_permitted &&
+#endif
+ num_pal == 0) || num_pal > 256)
+ {
+ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_error(png_ptr, "Invalid number of colors in palette");
+ }
+ else
+ {
+ png_warning(png_ptr, "Invalid number of colors in palette");
+ return;
+ }
+ }
+
+ png_ptr->num_palette = (png_uint_16)num_pal;
+ png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
+
+ png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
+ for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
+ {
+ buf[0] = pal_ptr->red;
+ buf[1] = pal_ptr->green;
+ buf[2] = pal_ptr->blue;
+ png_write_chunk_data(png_ptr, buf, (png_size_t)3);
+ }
+ png_write_chunk_end(png_ptr);
+ png_ptr->mode |= PNG_HAVE_PLTE;
+}
+
+/* write an IDAT chunk */
+void
+png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
+{
+ png_debug(1, "in png_write_IDAT\n");
+ png_write_chunk(png_ptr, png_IDAT, data, length);
+ png_ptr->mode |= PNG_HAVE_IDAT;
+}
+
+/* write an IEND chunk */
+void
+png_write_IEND(png_structp png_ptr)
+{
+ png_debug(1, "in png_write_IEND\n");
+ png_write_chunk(png_ptr, png_IEND, NULL, (png_size_t)0);
+ png_ptr->mode |= PNG_HAVE_IEND;
+}
+
+#if defined(PNG_WRITE_gAMA_SUPPORTED)
+/* write a gAMA chunk */
+void
+png_write_gAMA(png_structp png_ptr, double file_gamma)
+{
+ png_uint_32 igamma;
+ png_byte buf[4];
+
+ png_debug(1, "in png_write_gAMA\n");
+ /* file_gamma is saved in 1/1000000ths */
+ igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
+ png_save_uint_32(buf, igamma);
+ png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
+}
+#endif
+
+#if defined(PNG_WRITE_sRGB_SUPPORTED)
+/* write a sRGB chunk */
+void
+png_write_sRGB(png_structp png_ptr, int srgb_intent)
+{
+ png_byte buf[1];
+
+ png_debug(1, "in png_write_sRGB\n");
+ if(srgb_intent >= PNG_sRGB_INTENT_LAST)
+ png_warning(png_ptr,
+ "Invalid sRGB rendering intent specified");
+ buf[0]=(png_byte)srgb_intent;
+ png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
+}
+#endif
+
+#if defined(PNG_WRITE_sBIT_SUPPORTED)
+/* write the sBIT chunk */
+void
+png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
+{
+ png_byte buf[4];
+ png_size_t size;
+
+ png_debug(1, "in png_write_sBIT\n");
+ /* make sure we don't depend upon the order of PNG_COLOR_8 */
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ png_byte maxbits;
+
+ maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
+ png_ptr->usr_bit_depth);
+ if (sbit->red == 0 || sbit->red > maxbits ||
+ sbit->green == 0 || sbit->green > maxbits ||
+ sbit->blue == 0 || sbit->blue > maxbits)
+ {
+ png_warning(png_ptr, "Invalid sBIT depth specified");
+ return;
+ }
+ buf[0] = sbit->red;
+ buf[1] = sbit->green;
+ buf[2] = sbit->blue;
+ size = 3;
+ }
+ else
+ {
+ if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
+ {
+ png_warning(png_ptr, "Invalid sBIT depth specified");
+ return;
+ }
+ buf[0] = sbit->gray;
+ size = 1;
+ }
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
+ {
+ png_warning(png_ptr, "Invalid sBIT depth specified");
+ return;
+ }
+ buf[size++] = sbit->alpha;
+ }
+
+ png_write_chunk(png_ptr, png_sBIT, buf, size);
+}
+#endif
+
+#if defined(PNG_WRITE_cHRM_SUPPORTED)
+/* write the cHRM chunk */
+void
+png_write_cHRM(png_structp png_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_uint_32 itemp;
+ png_byte buf[32];
+
+ png_debug(1, "in png_write_cHRM\n");
+ /* each value is saved int 1/1000000ths */
+ if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
+ white_x + white_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM white point specified");
+ return;
+ }
+ itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
+ png_save_uint_32(buf, itemp);
+ itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
+ png_save_uint_32(buf + 4, itemp);
+
+ if (red_x < 0 || red_x > 0.8 || red_y < 0 || red_y > 0.8 ||
+ red_x + red_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM red point specified");
+ return;
+ }
+ itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
+ png_save_uint_32(buf + 8, itemp);
+ itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
+ png_save_uint_32(buf + 12, itemp);
+
+ if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 ||
+ green_x + green_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM green point specified");
+ return;
+ }
+ itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
+ png_save_uint_32(buf + 16, itemp);
+ itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
+ png_save_uint_32(buf + 20, itemp);
+
+ if (blue_x < 0 || blue_x > 0.8 || blue_y < 0 || blue_y > 0.8 ||
+ blue_x + blue_y > 1.0)
+ {
+ png_warning(png_ptr, "Invalid cHRM blue point specified");
+ return;
+ }
+ itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
+ png_save_uint_32(buf + 24, itemp);
+ itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
+ png_save_uint_32(buf + 28, itemp);
+
+ png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
+}
+#endif
+
+#if defined(PNG_WRITE_tRNS_SUPPORTED)
+/* write the tRNS chunk */
+void
+png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
+ int num_trans, int color_type)
+{
+ png_byte buf[6];
+
+ png_debug(1, "in png_write_tRNS\n");
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
+ {
+ png_warning(png_ptr,"Invalid number of transparent colors specified");
+ return;
+ }
+ /* write the chunk out as it is */
+ png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
+ }
+ else if (color_type == PNG_COLOR_TYPE_GRAY)
+ {
+ /* one 16 bit value */
+ png_save_uint_16(buf, tran->gray);
+ png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
+ }
+ else if (color_type == PNG_COLOR_TYPE_RGB)
+ {
+ /* three 16 bit values */
+ png_save_uint_16(buf, tran->red);
+ png_save_uint_16(buf + 2, tran->green);
+ png_save_uint_16(buf + 4, tran->blue);
+ png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
+ }
+ else
+ {
+ png_warning(png_ptr, "Can't write tRNS with an alpha channel");
+ }
+}
+#endif
+
+#if defined(PNG_WRITE_bKGD_SUPPORTED)
+/* write the background chunk */
+void
+png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
+{
+ png_byte buf[6];
+
+ png_debug(1, "in png_write_bKGD\n");
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ if (
+#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
+ (!png_ptr->empty_plte_permitted ||
+ (png_ptr->empty_plte_permitted && png_ptr->num_palette)) &&
+#endif
+ back->index > png_ptr->num_palette)
+ {
+ png_warning(png_ptr, "Invalid background palette index");
+ return;
+ }
+ buf[0] = back->index;
+ png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
+ }
+ else if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ png_save_uint_16(buf, back->red);
+ png_save_uint_16(buf + 2, back->green);
+ png_save_uint_16(buf + 4, back->blue);
+ png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
+ }
+ else
+ {
+ png_save_uint_16(buf, back->gray);
+ png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
+ }
+}
+#endif
+
+#if defined(PNG_WRITE_hIST_SUPPORTED)
+/* write the histogram */
+void
+png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
+{
+ int i;
+ png_byte buf[3];
+
+ png_debug(1, "in png_write_hIST\n");
+ if (num_hist > (int)png_ptr->num_palette)
+ {
+ png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
+ png_ptr->num_palette);
+ png_warning(png_ptr, "Invalid number of histogram entries specified");
+ return;
+ }
+
+ png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
+ for (i = 0; i < num_hist; i++)
+ {
+ png_save_uint_16(buf, hist[i]);
+ png_write_chunk_data(png_ptr, buf, (png_size_t)2);
+ }
+ png_write_chunk_end(png_ptr);
+}
+#endif
+
+#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
+ defined(PNG_WRITE_pCAL_SUPPORTED)
+/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
+ * and if invalid, correct the keyword rather than discarding the entire
+ * chunk. The PNG 1.0 specification requires keywords 1-79 characters in
+ * length, forbids leading or trailing whitespace, multiple internal spaces,
+ * and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
+ *
+ * The new_key is allocated to hold the corrected keyword and must be freed
+ * by the calling routine. This avoids problems with trying to write to
+ * static keywords without having to have duplicate copies of the strings.
+ */
+png_size_t
+png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
+{
+ png_size_t key_len;
+ png_charp kp, dp;
+ int kflag;
+
+ png_debug(1, "in png_check_keyword\n");
+ *new_key = NULL;
+
+ if (key == NULL || (key_len = png_strlen(key)) == 0)
+ {
+ png_chunk_warning(png_ptr, "zero length keyword");
+ return ((png_size_t)0);
+ }
+
+ png_debug1(2, "Keyword to be checked is '%s'\n", key);
+
+ *new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 1));
+
+ /* Replace non-printing characters with a blank and print a warning */
+ for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
+ {
+ if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1))
+ {
+#if !defined(PNG_NO_STDIO)
+ char msg[40];
+
+ sprintf(msg, "invalid keyword character 0x%02X", *kp);
+ png_chunk_warning(png_ptr, msg);
+#else
+ png_chunk_warning(png_ptr, "invalid character in keyword");
+#endif
+ *dp = ' ';
+ }
+ else
+ {
+ *dp = *kp;
+ }
+ }
+ *dp = '\0';
+
+ /* Remove any trailing white space. */
+ kp = *new_key + key_len - 1;
+ if (*kp == ' ')
+ {
+ png_chunk_warning(png_ptr, "trailing spaces removed from keyword");
+
+ while (*kp == ' ')
+ {
+ *(kp--) = '\0';
+ key_len--;
+ }
+ }
+
+ /* Remove any leading white space. */
+ kp = *new_key;
+ if (*kp == ' ')
+ {
+ png_chunk_warning(png_ptr, "leading spaces removed from keyword");
+
+ while (*kp == ' ')
+ {
+ kp++;
+ key_len--;
+ }
+ }
+
+ png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
+
+ /* Remove multiple internal spaces. */
+ for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
+ {
+ if (*kp == ' ' && kflag == 0)
+ {
+ *(dp++) = *kp;
+ kflag = 1;
+ }
+ else if (*kp == ' ')
+ {
+ key_len--;
+ }
+ else
+ {
+ *(dp++) = *kp;
+ kflag = 0;
+ }
+ }
+ *dp = '\0';
+
+ if (key_len == 0)
+ {
+ png_chunk_warning(png_ptr, "zero length keyword");
+ }
+
+ if (key_len > 79)
+ {
+ png_chunk_warning(png_ptr, "keyword length must be 1 - 79 characters");
+ new_key[79] = '\0';
+ key_len = 79;
+ }
+
+ return (key_len);
+}
+#endif
+
+#if defined(PNG_WRITE_tEXt_SUPPORTED)
+/* write a tEXt chunk */
+void
+png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
+ png_size_t text_len)
+{
+ png_size_t key_len;
+ png_charp new_key;
+
+ png_debug(1, "in png_write_tEXt\n");
+ if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
+ {
+ png_warning(png_ptr, "Empty keyword in tEXt chunk");
+ return;
+ }
+
+ if (text == NULL || *text == '\0')
+ text_len = 0;
+
+ /* make sure we include the 0 after the key */
+ png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
+ /*
+ * We leave it to the application to meet PNG-1.0 requirements on the
+ * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
+ * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
+ */
+ png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
+ if (text_len)
+ png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
+
+ png_write_chunk_end(png_ptr);
+ png_free(png_ptr, new_key);
+}
+#endif
+
+#if defined(PNG_WRITE_zTXt_SUPPORTED)
+/* write a compressed text chunk */
+void
+png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
+ png_size_t text_len, int compression)
+{
+ png_size_t key_len;
+ char buf[1];
+ png_charp new_key;
+ int i, ret;
+ png_charpp output_ptr = NULL; /* array of pointers to output */
+ int num_output_ptr = 0; /* number of output pointers used */
+ int max_output_ptr = 0; /* size of output_ptr */
+
+ png_debug(1, "in png_write_zTXt\n");
+
+ if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
+ {
+ png_warning(png_ptr, "Empty keyword in zTXt chunk");
+ return;
+ }
+
+ if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
+ {
+ png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
+ png_free(png_ptr, new_key);
+ return;
+ }
+
+ png_free(png_ptr, new_key);
+
+ if (compression >= PNG_TEXT_COMPRESSION_LAST)
+ {
+#if !defined(PNG_NO_STDIO)
+ char msg[50];
+ sprintf(msg, "Unknown zTXt compression type %d", compression);
+ png_warning(png_ptr, msg);
+#else
+ png_warning(png_ptr, "Unknown zTXt compression type");
+#endif
+ compression = PNG_TEXT_COMPRESSION_zTXt;
+ }
+
+ /* We can't write the chunk until we find out how much data we have,
+ * which means we need to run the compressor first and save the
+ * output. This shouldn't be a problem, as the vast majority of
+ * comments should be reasonable, but we will set up an array of
+ * malloc'd pointers to be sure.
+ *
+ * If we knew the application was well behaved, we could simplify this
+ * greatly by assuming we can always malloc an output buffer large
+ * enough to hold the compressed text ((1001 * text_len / 1000) + 12)
+ * and malloc this directly. The only time this would be a bad idea is
+ * if we can't malloc more than 64K and we have 64K of random input
+ * data, or if the input string is incredibly large (although this
+ * wouldn't cause a failure, just a slowdown due to swapping).
+ */
+
+ /* set up the compression buffers */
+ png_ptr->zstream.avail_in = (uInt)text_len;
+ png_ptr->zstream.next_in = (Bytef *)text;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
+
+ /* this is the same compression loop as in png_write_row() */
+ do
+ {
+ /* compress the data */
+ ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
+ if (ret != Z_OK)
+ {
+ /* error */
+ if (png_ptr->zstream.msg != NULL)
+ png_error(png_ptr, png_ptr->zstream.msg);
+ else
+ png_error(png_ptr, "zlib error");
+ }
+ /* check to see if we need more room */
+ if (!png_ptr->zstream.avail_out && png_ptr->zstream.avail_in)
+ {
+ /* make sure the output array has room */
+ if (num_output_ptr >= max_output_ptr)
+ {
+ int old_max;
+
+ old_max = max_output_ptr;
+ max_output_ptr = num_output_ptr + 4;
+ if (output_ptr != NULL)
+ {
+ png_charpp old_ptr;
+
+ old_ptr = output_ptr;
+ output_ptr = (png_charpp)png_malloc(png_ptr,
+ (png_uint_32)(max_output_ptr * sizeof (png_charpp)));
+ png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
+ png_free(png_ptr, old_ptr);
+ }
+ else
+ output_ptr = (png_charpp)png_malloc(png_ptr,
+ (png_uint_32)(max_output_ptr * sizeof (png_charp)));
+ }
+
+ /* save the data */
+ output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)png_ptr->zbuf_size);
+ png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
+ png_ptr->zbuf_size);
+ num_output_ptr++;
+
+ /* and reset the buffer */
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ }
+ /* continue until we don't have any more to compress */
+ } while (png_ptr->zstream.avail_in);
+
+ /* finish the compression */
+ do
+ {
+ /* tell zlib we are finished */
+ ret = deflate(&png_ptr->zstream, Z_FINISH);
+ if (ret != Z_OK && ret != Z_STREAM_END)
+ {
+ /* we got an error */
+ if (png_ptr->zstream.msg != NULL)
+ png_error(png_ptr, png_ptr->zstream.msg);
+ else
+ png_error(png_ptr, "zlib error");
+ }
+
+ /* check to see if we need more room */
+ if (!(png_ptr->zstream.avail_out) && ret == Z_OK)
+ {
+ /* check to make sure our output array has room */
+ if (num_output_ptr >= max_output_ptr)
+ {
+ int old_max;
+
+ old_max = max_output_ptr;
+ max_output_ptr = num_output_ptr + 4;
+ if (output_ptr != NULL)
+ {
+ png_charpp old_ptr;
+
+ old_ptr = output_ptr;
+ /* This could be optimized to realloc() */
+ output_ptr = (png_charpp)png_malloc(png_ptr,
+ (png_uint_32)(max_output_ptr * sizeof (png_charpp)));
+ png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
+ png_free(png_ptr, old_ptr);
+ }
+ else
+ output_ptr = (png_charpp)png_malloc(png_ptr,
+ (png_uint_32)(max_output_ptr * sizeof (png_charp)));
+ }
+
+ /* save off the data */
+ output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
+ (png_uint_32)png_ptr->zbuf_size);
+ png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
+ png_ptr->zbuf_size);
+ num_output_ptr++;
+
+ /* and reset the buffer pointers */
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ }
+ } while (ret != Z_STREAM_END);
+
+ /* text length is number of buffers plus last buffer */
+ text_len = png_ptr->zbuf_size * num_output_ptr;
+ if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
+ text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
+
+ /* write start of chunk */
+ png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)(key_len+text_len+2));
+ /* write key */
+ png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1);
+ buf[0] = (png_byte)compression;
+ /* write compression */
+ png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
+
+ /* write saved output buffers, if any */
+ for (i = 0; i < num_output_ptr; i++)
+ {
+ png_write_chunk_data(png_ptr,(png_bytep)output_ptr[i],png_ptr->zbuf_size);
+ png_free(png_ptr, output_ptr[i]);
+ }
+ if (max_output_ptr != 0)
+ png_free(png_ptr, output_ptr);
+ /* write anything left in zbuf */
+ if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
+ png_write_chunk_data(png_ptr, png_ptr->zbuf,
+ png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ /* close the chunk */
+ png_write_chunk_end(png_ptr);
+
+ /* reset zlib for another zTXt or the image data */
+ deflateReset(&png_ptr->zstream);
+}
+#endif
+
+
+#if defined(PNG_WRITE_oFFs_SUPPORTED)
+/* write the oFFs chunk */
+void
+png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
+ png_uint_32 y_offset,
+ int unit_type)
+{
+ png_byte buf[9];
+
+ png_debug(1, "in png_write_oFFs\n");
+ if (unit_type >= PNG_OFFSET_LAST)
+ png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
+
+ png_save_uint_32(buf, x_offset);
+ png_save_uint_32(buf + 4, y_offset);
+ buf[8] = (png_byte)unit_type;
+
+ png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
+}
+#endif
+
+#if defined(PNG_WRITE_pCAL_SUPPORTED)
+/* write the pCAL chunk (png-scivis-19970203) */
+void
+png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
+ png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
+{
+ png_size_t purpose_len, units_len, total_len;
+ png_uint_32p params_len;
+ png_byte buf[10];
+ png_charp new_purpose;
+ int i;
+
+ png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
+ if (type >= PNG_EQUATION_LAST)
+ png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
+
+ purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
+ png_debug1(3, "pCAL purpose length = %d\n", purpose_len);
+ units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
+ png_debug1(3, "pCAL units length = %d\n", units_len);
+ total_len = purpose_len + units_len + 10;
+
+ params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
+ *sizeof(png_uint_32)));
+
+ /* Find the length of each parameter, making sure we don't count the
+ null terminator for the last parameter. */
+ for (i = 0; i < nparams; i++)
+ {
+ params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
+ png_debug2(3, "pCAL parameter %d length = %d\n", i, params_len[i]);
+ total_len += (png_size_t)params_len[i];
+ }
+
+ png_debug1(3, "pCAL total length = %d\n", total_len);
+ png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
+ png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
+ png_save_int_32(buf, X0);
+ png_save_int_32(buf + 4, X1);
+ buf[8] = (png_byte)type;
+ buf[9] = (png_byte)nparams;
+ png_write_chunk_data(png_ptr, buf, (png_size_t)10);
+ png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
+
+ png_free(png_ptr, new_purpose);
+
+ for (i = 0; i < nparams; i++)
+ {
+ png_write_chunk_data(png_ptr, (png_bytep)params[i],
+ (png_size_t)params_len[i]);
+ }
+
+ png_free(png_ptr, params_len);
+ png_write_chunk_end(png_ptr);
+}
+#endif
+
+#if defined(PNG_WRITE_pHYs_SUPPORTED)
+/* write the pHYs chunk */
+void
+png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
+ png_uint_32 y_pixels_per_unit,
+ int unit_type)
+{
+ png_byte buf[9];
+
+ png_debug(1, "in png_write_pHYs\n");
+ if (unit_type >= PNG_RESOLUTION_LAST)
+ png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
+
+ png_save_uint_32(buf, x_pixels_per_unit);
+ png_save_uint_32(buf + 4, y_pixels_per_unit);
+ buf[8] = (png_byte)unit_type;
+
+ png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
+}
+#endif
+
+#if defined(PNG_WRITE_tIME_SUPPORTED)
+/* Write the tIME chunk. Use either png_convert_from_struct_tm()
+ * or png_convert_from_time_t(), or fill in the structure yourself.
+ */
+void
+png_write_tIME(png_structp png_ptr, png_timep mod_time)
+{
+ png_byte buf[7];
+
+ png_debug(1, "in png_write_tIME\n");
+ if (mod_time->month > 12 || mod_time->month < 1 ||
+ mod_time->day > 31 || mod_time->day < 1 ||
+ mod_time->hour > 23 || mod_time->second > 60)
+ {
+ png_warning(png_ptr, "Invalid time specified for tIME chunk");
+ return;
+ }
+
+ png_save_uint_16(buf, mod_time->year);
+ buf[2] = mod_time->month;
+ buf[3] = mod_time->day;
+ buf[4] = mod_time->hour;
+ buf[5] = mod_time->minute;
+ buf[6] = mod_time->second;
+
+ png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
+}
+#endif
+
+/* initializes the row writing capability of libpng */
+void
+png_write_start_row(png_structp png_ptr)
+{
+ png_size_t buf_size;
+
+ png_debug(1, "in png_write_start_row\n");
+ buf_size = (png_size_t)(((png_ptr->width * png_ptr->usr_channels *
+ png_ptr->usr_bit_depth + 7) >> 3) + 1);
+
+ /* set up row buffer */
+ png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
+ png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
+
+ /* set up filtering buffer, if using this filter */
+ if (png_ptr->do_filter & PNG_FILTER_SUB)
+ {
+ png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
+ }
+
+ /* We only need to keep the previous row if we are using one of these. */
+ if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
+ {
+ /* set up previous row buffer */
+ png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
+ png_memset(png_ptr->prev_row, 0, buf_size);
+
+ if (png_ptr->do_filter & PNG_FILTER_UP)
+ {
+ png_ptr->up_row = (png_bytep )png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
+ }
+
+ if (png_ptr->do_filter & PNG_FILTER_AVG)
+ {
+ png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
+ }
+
+ if (png_ptr->do_filter & PNG_FILTER_PAETH)
+ {
+ png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
+ (png_ptr->rowbytes + 1));
+ png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
+ }
+ }
+
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
+ /* if interlaced, we need to set up width and height of pass */
+ if (png_ptr->interlaced)
+ {
+ if (!(png_ptr->transformations & PNG_INTERLACE))
+ {
+ png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
+ png_pass_ystart[0]) / png_pass_yinc[0];
+ png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
+ png_pass_start[0]) / png_pass_inc[0];
+ }
+ else
+ {
+ png_ptr->num_rows = png_ptr->height;
+ png_ptr->usr_width = png_ptr->width;
+ }
+ }
+ else
+#endif
+ {
+ png_ptr->num_rows = png_ptr->height;
+ png_ptr->usr_width = png_ptr->width;
+ }
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+}
+
+/* Internal use only. Called when finished processing a row of data. */
+void
+png_write_finish_row(png_structp png_ptr)
+{
+ int ret;
+
+ png_debug(1, "in png_write_finish_row\n");
+ /* next row */
+ png_ptr->row_number++;
+
+ /* see if we are done */
+ if (png_ptr->row_number < png_ptr->num_rows)
+ return;
+
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
+ /* if interlaced, go to next pass */
+ if (png_ptr->interlaced)
+ {
+ png_ptr->row_number = 0;
+ if (png_ptr->transformations & PNG_INTERLACE)
+ {
+ png_ptr->pass++;
+ }
+ else
+ {
+ /* loop until we find a non-zero width or height pass */
+ do
+ {
+ png_ptr->pass++;
+ if (png_ptr->pass >= 7)
+ break;
+ png_ptr->usr_width = (png_ptr->width +
+ png_pass_inc[png_ptr->pass] - 1 -
+ png_pass_start[png_ptr->pass]) /
+ png_pass_inc[png_ptr->pass];
+ png_ptr->num_rows = (png_ptr->height +
+ png_pass_yinc[png_ptr->pass] - 1 -
+ png_pass_ystart[png_ptr->pass]) /
+ png_pass_yinc[png_ptr->pass];
+ if (png_ptr->transformations & PNG_INTERLACE)
+ break;
+ } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
+
+ }
+
+ /* reset the row above the image for the next pass */
+ if (png_ptr->pass < 7)
+ {
+ if (png_ptr->prev_row != NULL)
+ png_memset(png_ptr->prev_row, 0,
+ (png_size_t) (((png_uint_32)png_ptr->usr_channels *
+ (png_uint_32)png_ptr->usr_bit_depth *
+ png_ptr->width + 7) >> 3) + 1);
+ return;
+ }
+ }
+#endif
+
+ /* if we get here, we've just written the last row, so we need
+ to flush the compressor */
+ do
+ {
+ /* tell the compressor we are done */
+ ret = deflate(&png_ptr->zstream, Z_FINISH);
+ /* check for an error */
+ if (ret != Z_OK && ret != Z_STREAM_END)
+ {
+ if (png_ptr->zstream.msg != NULL)
+ png_error(png_ptr, png_ptr->zstream.msg);
+ else
+ png_error(png_ptr, "zlib error");
+ }
+ /* check to see if we need more room */
+ if (!(png_ptr->zstream.avail_out) && ret == Z_OK)
+ {
+ png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ }
+ } while (ret != Z_STREAM_END);
+
+ /* write any extra space */
+ if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
+ {
+ png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
+ png_ptr->zstream.avail_out);
+ }
+
+ deflateReset(&png_ptr->zstream);
+}
+
+#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
+/* Pick out the correct pixels for the interlace pass.
+ * The basic idea here is to go through the row with a source
+ * pointer and a destination pointer (sp and dp), and copy the
+ * correct pixels for the pass. As the row gets compacted,
+ * sp will always be >= dp, so we should never overwrite anything.
+ * See the default: case for the easiest code to understand.
+ */
+void
+png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
+{
+ png_debug(1, "in png_do_write_interlace\n");
+ /* we don't have to do anything on the last pass (6) */
+#if defined(PNG_USELESS_TESTS_SUPPORTED)
+ if (row != NULL && row_info != NULL && pass < 6)
+#else
+ if (pass < 6)
+#endif
+ {
+ /* each pixel depth is handled separately */
+ switch (row_info->pixel_depth)
+ {
+ case 1:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int shift;
+ int d;
+ int value;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+
+ dp = row;
+ d = 0;
+ shift = 7;
+ for (i = png_pass_start[pass]; i < row_width;
+ i += png_pass_inc[pass])
+ {
+ sp = row + (png_size_t)(i >> 3);
+ value = (int)(*sp >> (7 - (int)(i & 7))) & 0x1;
+ d |= (value << shift);
+
+ if (shift == 0)
+ {
+ shift = 7;
+ *dp++ = (png_byte)d;
+ d = 0;
+ }
+ else
+ shift--;
+
+ }
+ if (shift != 7)
+ *dp = (png_byte)d;
+ break;
+ }
+ case 2:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int shift;
+ int d;
+ int value;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+
+ dp = row;
+ shift = 6;
+ d = 0;
+ for (i = png_pass_start[pass]; i < row_width;
+ i += png_pass_inc[pass])
+ {
+ sp = row + (png_size_t)(i >> 2);
+ value = (*sp >> ((3 - (int)(i & 3)) << 1)) & 0x3;
+ d |= (value << shift);
+
+ if (shift == 0)
+ {
+ shift = 6;
+ *dp++ = (png_byte)d;
+ d = 0;
+ }
+ else
+ shift -= 2;
+ }
+ if (shift != 6)
+ *dp = (png_byte)d;
+ break;
+ }
+ case 4:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ int shift;
+ int d;
+ int value;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+
+ dp = row;
+ shift = 4;
+ d = 0;
+ for (i = png_pass_start[pass]; i < row_width;
+ i += png_pass_inc[pass])
+ {
+ sp = row + (png_size_t)(i >> 1);
+ value = (*sp >> ((1 - (int)(i & 1)) << 2)) & 0xf;
+ d |= (value << shift);
+
+ if (shift == 0)
+ {
+ shift = 4;
+ *dp++ = (png_byte)d;
+ d = 0;
+ }
+ else
+ shift -= 4;
+ }
+ if (shift != 4)
+ *dp = (png_byte)d;
+ break;
+ }
+ default:
+ {
+ png_bytep sp;
+ png_bytep dp;
+ png_uint_32 i;
+ png_uint_32 row_width = row_info->width;
+ png_size_t pixel_bytes;
+
+ /* start at the beginning */
+ dp = row;
+ /* find out how many bytes each pixel takes up */
+ pixel_bytes = (row_info->pixel_depth >> 3);
+ /* loop through the row, only looking at the pixels that
+ matter */
+ for (i = png_pass_start[pass]; i < row_width;
+ i += png_pass_inc[pass])
+ {
+ /* find out where the original pixel is */
+ sp = row + (png_size_t)i * pixel_bytes;
+ /* move the pixel */
+ if (dp != sp)
+ png_memcpy(dp, sp, pixel_bytes);
+ /* next pixel */
+ dp += pixel_bytes;
+ }
+ break;
+ }
+ }
+ /* set new row width */
+ row_info->width = (row_info->width +
+ png_pass_inc[pass] - 1 -
+ png_pass_start[pass]) /
+ png_pass_inc[pass];
+ row_info->rowbytes = ((row_info->width *
+ row_info->pixel_depth + 7) >> 3);
+ }
+}
+#endif
+
+/* This filters the row, chooses which filter to use, if it has not already
+ * been specified by the application, and then writes the row out with the
+ * chosen filter.
+ */
+#define PNG_MAXSUM (~((png_uint_32)0) >> 1)
+#define PNG_HISHIFT 10
+#define PNG_LOMASK ((png_uint_32)0xffffL)
+#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
+void
+png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
+{
+ png_bytep prev_row, best_row, row_buf;
+ png_uint_32 mins, bpp;
+ png_byte filter_to_do = png_ptr->do_filter;
+ png_uint_32 row_bytes = row_info->rowbytes;
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ int num_p_filters = (int)png_ptr->num_prev_filters;
+#endif
+
+ png_debug(1, "in png_write_find_filter\n");
+ /* find out how many bytes offset each pixel is */
+ bpp = (row_info->pixel_depth + 7) / 8;
+
+ prev_row = png_ptr->prev_row;
+ best_row = row_buf = png_ptr->row_buf;
+ mins = PNG_MAXSUM;
+
+ /* The prediction method we use is to find which method provides the
+ * smallest value when summing the absolute values of the distances
+ * from zero, using anything >= 128 as negative numbers. This is known
+ * as the "minimum sum of absolute differences" heuristic. Other
+ * heuristics are the "weighted minimum sum of absolute differences"
+ * (experimental and can in theory improve compression), and the "zlib
+ * predictive" method (not implemented yet), which does test compressions
+ * of lines using different filter methods, and then chooses the
+ * (series of) filter(s) that give minimum compressed data size (VERY
+ * computationally expensive).
+ *
+ * GRR 980525: consider also
+ * (1) minimum sum of absolute differences from running average (i.e.,
+ * keep running sum of non-absolute differences & count of bytes)
+ * [track dispersion, too? restart average if dispersion too large?]
+ * (1b) minimum sum of absolute differences from sliding average, probably
+ * with window size <= deflate window (usually 32K)
+ * (2) minimum sum of squared differences from zero or running average
+ * (i.e., ~ root-mean-square approach)
+ */
+
+
+ /* We don't need to test the 'no filter' case if this is the only filter
+ * that has been chosen, as it doesn't actually do anything to the data.
+ */
+ if (filter_to_do & PNG_FILTER_NONE &&
+ filter_to_do != PNG_FILTER_NONE)
+ {
+ png_bytep rp;
+ png_uint_32 sum = 0;
+ png_uint_32 i;
+ int v;
+
+ for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
+ {
+ v = *rp;
+ sum += (v < 128) ? v : 256 - v;
+ }
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ png_uint_32 sumhi, sumlo;
+ int j;
+ sumlo = sum & PNG_LOMASK;
+ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
+
+ /* Reduce the sum if we match any of the previous rows */
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
+ {
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ /* Factor in the cost of this filter (this is here for completeness,
+ * but it makes no sense to have a "cost" for the NONE filter, as
+ * it has the minimum possible computational cost - none).
+ */
+ sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
+ PNG_COST_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
+ PNG_COST_SHIFT;
+
+ if (sumhi > PNG_HIMASK)
+ sum = PNG_MAXSUM;
+ else
+ sum = (sumhi << PNG_HISHIFT) + sumlo;
+ }
+#endif
+ mins = sum;
+ }
+
+ /* sub filter */
+ if (filter_to_do == PNG_FILTER_SUB)
+ /* it's the only filter so no testing is needed */
+ {
+ png_bytep rp, lp, dp;
+ png_uint_32 i;
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
+ i++, rp++, dp++)
+ {
+ *dp = *rp;
+ }
+ for (lp = row_buf + 1; i < row_bytes;
+ i++, rp++, lp++, dp++)
+ {
+ *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
+ }
+ best_row = png_ptr->sub_row;
+ }
+
+ else if (filter_to_do & PNG_FILTER_SUB)
+ {
+ png_bytep rp, dp, lp;
+ png_uint_32 sum = 0, lmins = mins;
+ png_uint_32 i;
+ int v;
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ /* We temporarily increase the "minimum sum" by the factor we
+ * would reduce the sum of this filter, so that we can do the
+ * early exit comparison without scaling the sum each time.
+ */
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 lmhi, lmlo;
+ lmlo = lmins & PNG_LOMASK;
+ lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
+ {
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
+ PNG_COST_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
+ PNG_COST_SHIFT;
+
+ if (lmhi > PNG_HIMASK)
+ lmins = PNG_MAXSUM;
+ else
+ lmins = (lmhi << PNG_HISHIFT) + lmlo;
+ }
+#endif
+
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
+ i++, rp++, dp++)
+ {
+ v = *dp = *rp;
+
+ sum += (v < 128) ? v : 256 - v;
+ }
+ for (lp = row_buf + 1; i < row_info->rowbytes;
+ i++, rp++, lp++, dp++)
+ {
+ v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+
+ if (sum > lmins) /* We are already worse, don't continue. */
+ break;
+ }
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 sumhi, sumlo;
+ sumlo = sum & PNG_LOMASK;
+ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
+ {
+ sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
+ PNG_COST_SHIFT;
+ sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
+ PNG_COST_SHIFT;
+
+ if (sumhi > PNG_HIMASK)
+ sum = PNG_MAXSUM;
+ else
+ sum = (sumhi << PNG_HISHIFT) + sumlo;
+ }
+#endif
+
+ if (sum < mins)
+ {
+ mins = sum;
+ best_row = png_ptr->sub_row;
+ }
+ }
+
+ /* up filter */
+ if (filter_to_do == PNG_FILTER_UP)
+ {
+ png_bytep rp, dp, pp;
+ png_uint_32 i;
+
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
+ pp = prev_row + 1; i < row_bytes;
+ i++, rp++, pp++, dp++)
+ {
+ *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
+ }
+ best_row = png_ptr->up_row;
+ }
+
+ else if (filter_to_do & PNG_FILTER_UP)
+ {
+ png_bytep rp, dp, pp;
+ png_uint_32 sum = 0, lmins = mins;
+ png_uint_32 i;
+ int v;
+
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 lmhi, lmlo;
+ lmlo = lmins & PNG_LOMASK;
+ lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
+ {
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
+ PNG_COST_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
+ PNG_COST_SHIFT;
+
+ if (lmhi > PNG_HIMASK)
+ lmins = PNG_MAXSUM;
+ else
+ lmins = (lmhi << PNG_HISHIFT) + lmlo;
+ }
+#endif
+
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
+ pp = prev_row + 1; i < row_bytes; i++)
+ {
+ v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+
+ if (sum > lmins) /* We are already worse, don't continue. */
+ break;
+ }
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 sumhi, sumlo;
+ sumlo = sum & PNG_LOMASK;
+ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
+ {
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
+ PNG_COST_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
+ PNG_COST_SHIFT;
+
+ if (sumhi > PNG_HIMASK)
+ sum = PNG_MAXSUM;
+ else
+ sum = (sumhi << PNG_HISHIFT) + sumlo;
+ }
+#endif
+
+ if (sum < mins)
+ {
+ mins = sum;
+ best_row = png_ptr->up_row;
+ }
+ }
+
+ /* avg filter */
+ if (filter_to_do == PNG_FILTER_AVG)
+ {
+ png_bytep rp, dp, pp, lp;
+ png_uint_32 i;
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
+ pp = prev_row + 1; i < bpp; i++)
+ {
+ *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
+ }
+ for (lp = row_buf + 1; i < row_bytes; i++)
+ {
+ *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
+ & 0xff);
+ }
+ best_row = png_ptr->avg_row;
+ }
+
+ else if (filter_to_do & PNG_FILTER_AVG)
+ {
+ png_bytep rp, dp, pp, lp;
+ png_uint_32 sum = 0, lmins = mins;
+ png_uint_32 i;
+ int v;
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 lmhi, lmlo;
+ lmlo = lmins & PNG_LOMASK;
+ lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
+ {
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
+ PNG_COST_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
+ PNG_COST_SHIFT;
+
+ if (lmhi > PNG_HIMASK)
+ lmins = PNG_MAXSUM;
+ else
+ lmins = (lmhi << PNG_HISHIFT) + lmlo;
+ }
+#endif
+
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
+ pp = prev_row + 1; i < bpp; i++)
+ {
+ v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+ }
+ for (lp = row_buf + 1; i < row_bytes; i++)
+ {
+ v = *dp++ =
+ (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+
+ if (sum > lmins) /* We are already worse, don't continue. */
+ break;
+ }
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 sumhi, sumlo;
+ sumlo = sum & PNG_LOMASK;
+ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
+ {
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
+ PNG_COST_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
+ PNG_COST_SHIFT;
+
+ if (sumhi > PNG_HIMASK)
+ sum = PNG_MAXSUM;
+ else
+ sum = (sumhi << PNG_HISHIFT) + sumlo;
+ }
+#endif
+
+ if (sum < mins)
+ {
+ mins = sum;
+ best_row = png_ptr->avg_row;
+ }
+ }
+
+ /* Paeth filter */
+ if (filter_to_do == PNG_FILTER_PAETH)
+ {
+ png_bytep rp, dp, pp, cp, lp;
+ png_uint_32 i;
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
+ pp = prev_row + 1; i < bpp; i++)
+ {
+ *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
+ }
+
+ for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
+ {
+ int a, b, c, pa, pb, pc, p;
+
+ b = *pp++;
+ c = *cp++;
+ a = *lp++;
+
+ p = b - c;
+ pc = a - c;
+
+#ifdef PNG_USE_ABS
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
+#else
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
+#endif
+
+ p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+
+ *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
+ }
+ best_row = png_ptr->paeth_row;
+ }
+
+ else if (filter_to_do & PNG_FILTER_PAETH)
+ {
+ png_bytep rp, dp, pp, cp, lp;
+ png_uint_32 sum = 0, lmins = mins;
+ png_uint_32 i;
+ int v;
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 lmhi, lmlo;
+ lmlo = lmins & PNG_LOMASK;
+ lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
+ {
+ lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
+ PNG_COST_SHIFT;
+ lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
+ PNG_COST_SHIFT;
+
+ if (lmhi > PNG_HIMASK)
+ lmins = PNG_MAXSUM;
+ else
+ lmins = (lmhi << PNG_HISHIFT) + lmlo;
+ }
+#endif
+
+ for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
+ pp = prev_row + 1; i < bpp; i++)
+ {
+ v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+ }
+
+ for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
+ {
+ int a, b, c, pa, pb, pc, p;
+
+ b = *pp++;
+ c = *cp++;
+ a = *lp++;
+
+#ifndef PNG_SLOW_PAETH
+ p = b - c;
+ pc = a - c;
+#ifdef PNG_USE_ABS
+ pa = abs(p);
+ pb = abs(pc);
+ pc = abs(p + pc);
+#else
+ pa = p < 0 ? -p : p;
+ pb = pc < 0 ? -pc : pc;
+ pc = (p + pc) < 0 ? -(p + pc) : p + pc;
+#endif
+ p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+#else /* PNG_SLOW_PAETH */
+ p = a + b - c;
+ pa = abs(p - a);
+ pb = abs(p - b);
+ pc = abs(p - c);
+ if (pa <= pb && pa <= pc)
+ p = a;
+ else if (pb <= pc)
+ p = b;
+ else
+ p = c;
+#endif /* PNG_SLOW_PAETH */
+
+ v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
+
+ sum += (v < 128) ? v : 256 - v;
+
+ if (sum > lmins) /* We are already worse, don't continue. */
+ break;
+ }
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
+ {
+ int j;
+ png_uint_32 sumhi, sumlo;
+ sumlo = sum & PNG_LOMASK;
+ sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
+
+ for (j = 0; j < num_p_filters; j++)
+ {
+ if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
+ {
+ sumlo = (sumlo * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_weights[j]) >>
+ PNG_WEIGHT_SHIFT;
+ }
+ }
+
+ sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
+ PNG_COST_SHIFT;
+ sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
+ PNG_COST_SHIFT;
+
+ if (sumhi > PNG_HIMASK)
+ sum = PNG_MAXSUM;
+ else
+ sum = (sumhi << PNG_HISHIFT) + sumlo;
+ }
+#endif
+
+ if (sum < mins)
+ {
+ best_row = png_ptr->paeth_row;
+ }
+ }
+
+ /* Do the actual writing of the filtered row data from the chosen filter. */
+
+ png_write_filtered_row(png_ptr, best_row);
+
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
+ /* Save the type of filter we picked this time for future calculations */
+ if (png_ptr->num_prev_filters > 0)
+ {
+ int j;
+ for (j = 1; j < num_p_filters; j++)
+ {
+ png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
+ }
+ png_ptr->prev_filters[j] = best_row[0];
+ }
+#endif
+}
+
+
+/* Do the actual writing of a previously filtered row. */
+void
+png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
+{
+ png_debug(1, "in png_write_filtered_row\n");
+ png_debug1(2, "filter = %d\n", filtered_row[0]);
+ /* set up the zlib input buffer */
+ png_ptr->zstream.next_in = filtered_row;
+ png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
+ /* repeat until we have compressed all the data */
+ do
+ {
+ int ret; /* return of zlib */
+
+ /* compress the data */
+ ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
+ /* check for compression errors */
+ if (ret != Z_OK)
+ {
+ if (png_ptr->zstream.msg != NULL)
+ png_error(png_ptr, png_ptr->zstream.msg);
+ else
+ png_error(png_ptr, "zlib error");
+ }
+
+ /* see if it is time to write another IDAT */
+ if (!(png_ptr->zstream.avail_out))
+ {
+ /* write the IDAT and reset the zlib output buffer */
+ png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
+ png_ptr->zstream.next_out = png_ptr->zbuf;
+ png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
+ }
+ /* repeat until all data has been compressed */
+ } while (png_ptr->zstream.avail_in);
+
+ /* swap the current and previous rows */
+ if (png_ptr->prev_row != NULL)
+ {
+ png_bytep tptr;
+
+ tptr = png_ptr->prev_row;
+ png_ptr->prev_row = png_ptr->row_buf;
+ png_ptr->row_buf = tptr;
+ }
+
+ /* finish row - updates counters and flushes zlib if last row */
+ png_write_finish_row(png_ptr);
+
+#if defined(PNG_WRITE_FLUSH_SUPPORTED)
+ png_ptr->flush_rows++;
+
+ if (png_ptr->flush_dist > 0 &&
+ png_ptr->flush_rows >= png_ptr->flush_dist)
+ {
+ png_write_flush(png_ptr);
+ }
+#endif /* PNG_WRITE_FLUSH_SUPPORTED */
+}
diff --git a/osframework/source/ImageLib/png/readme b/osframework/source/ImageLib/png/readme
new file mode 100644
index 0000000..1589e74
--- /dev/null
+++ b/osframework/source/ImageLib/png/readme
@@ -0,0 +1,213 @@
+README for libpng 1.0.5 - October 15, 1999 (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.
+
+Version 0.89 was 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 since mid-1995. By late 1997 it had
+finally gotten to the stage where there hadn't been significant
+changes to the API in some time, and people have a bad feeling about
+libraries with versions < 1.0. Version 1.0.0 was released in
+March 1998.
+
+****
+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 pngtest.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@ccrc.wustl.edu>
+and not on material submitted privately to Guy, Andreas, or Glenn. They will
+forward any good suggestions to the list.
+
+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@alum.rpi.edu
+png-implement@ccrc.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@ccrc.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
+ 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
+ contrib => Contributions
+ gregbook => source code for PNG reading and writing, from
+ Greg Roelofs' "PNG: The Definitive Guide",
+ O'Reilly, 1999
+ 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 (Requires ansi2knr.c from
+ ftp://ftp.cs.wisc.edu/ghost)
+ makefile.dec => DEC Alpha UNIX makefile
+ makefile.hpux => HPUX (10.20 and 11.00) makefile
+ makefile.sgi => Silicon Graphics IRIX makefile
+ makefile.sunos => Sun makefile
+ makefile.solaris => Solaris 2.X makefile
+ (gcc, creates libpng.so.2.1.0.5)
+ makefile.linux => Linux/ELF makefile
+ (gcc, creates libpng.so.2.1.0.5)
+ makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
+ makefile.mips => MIPS makefile
+ makefile.acorn => Acorn makefile
+ makefile.amiga => Amiga makefile
+ smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC
+ compiler (Requires SCOPTIONS, copied from
+ scripts/SCOPTIONS.ppc)
+ makefile.atari => Atari makefile
+ makefile.beos => BEOS makefile for X86
+ makefile.borland => Borland makefile
+ build.bat => MS-DOS batch file for Borland compiler
+ makefile.dj2 => DJGPP 2 makefile
+ makefile.msc => Microsoft C makefile
+ makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and
+ later (uses assembler code)
+ makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
+ later (does not use assembler code)
+ makefile.turboc3 => Turbo C 3.0 makefile
+ makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
+ pngos2.def => OS/2 module definition file used by makefile.os2
+ makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
+ 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
+ SCOPTIONS.ppc => Used with smakefile.ppc
+
+Good luck, and happy coding.
+
+-Glenn Randers-Pehrson
+ Internet: randeg@alum.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
diff --git a/osframework/source/ImageLib/png/todo b/osframework/source/ImageLib/png/todo
new file mode 100644
index 0000000..183e079
--- /dev/null
+++ b/osframework/source/ImageLib/png/todo
@@ -0,0 +1,24 @@
+TODO - list of things to do for libpng:
+
+Final bug fixes.
+Fix problem with C++ and EXTERN "C".
+Better C++ wrapper/full C++ implementation?
+Keep up with public chunks.
+sPLT chunk handling.
+cHRM transformation.
+Support for application-defined chunk handlers.
+Improve setjmp/longjmp usage or remove it in favor of returning error codes.
+High-level API for reading images.
+Add "grayscale->palette" transformation and "palette->grayscale" detection.
+Improved dithering.
+Multi-lingual error and warning message support.
+Complete sRGB transformation (presently it simply uses gamma=0.45455).
+Man pages for function calls.
+Better documentation.
+Better filter selection
+ (counting huffman bits/precompression? filter inertia? filter costs?).
+Optional palette (sPLT) creation.
+Histogram creation.
+Text conversion between different code pages (Latin-1 -> Mac and DOS).
+Improve API by hiding the info_ptr.
+Make a no-floating-point version.
diff --git a/osframework/source/ImageLib/png/y2kinfo b/osframework/source/ImageLib/png/y2kinfo
new file mode 100644
index 0000000..36b7fc9
--- /dev/null
+++ b/osframework/source/ImageLib/png/y2kinfo
@@ -0,0 +1,55 @@
+ Y2K compliance in libpng:
+ =========================
+
+ October 15, 1999
+
+ Since the PNG Development group is an ad-hoc body, we can't make
+ an official declaration.
+
+ This is your unofficial assurance that libpng from version 0.71 and
+ upward through 1.0.5 are Y2K compliant. It is my belief that earlier
+ versions were also Y2K compliant.
+
+ Libpng only has three year fields. One is a 2-byte unsigned integer
+ that will hold years up to 65535. The other two hold the date in text
+ format, and will hold years up to 9999.
+
+ The integer is
+ "png_uint_16 year" in png_time_struct.
+
+ The strings are
+ "png_charp time_buffer" in png_struct and
+ "near_time_buffer", which is a local character string in png.c.
+
+ There are seven time-related functions:
+
+ png_convert_to_rfc_1123() in png.c
+ (formerly png_convert_to_rfc_1152() in error)
+ png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
+ png_convert_from_time_t() in pngwrite.c
+ png_get_tIME() in pngget.c
+ png_handle_tIME() in pngrutil.c, called in pngread.c
+ png_set_tIME() in pngset.c
+ png_write_tIME() in pngwutil.c, called in pngwrite.c
+
+ All appear to handle dates properly in a Y2K environment. The
+ png_convert_from_time_t() function calls gmtime() to convert from system
+ clock time, which returns (year - 1900), which we properly convert to
+ the full 4-digit year. There is a possibility that applications using
+ libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
+ function, or that they are incorrectly passing only a 2-digit year
+ instead of "year - 1900" into the png_convert_from_struct_tm() function,
+ but this is not under our control. The libpng documentation has always
+ stated that it works with 4-digit years, and the APIs have been
+ documented as such.
+
+ The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
+ integer to hold the year, and can hold years as large as 65535.
+
+ zlib, upon which libpng depends, is also Y2K compliant. It contains
+ no date-related code.
+
+
+ Glenn Randers-Pehrson
+ libpng maintainer
+ PNG Development Group
diff --git a/osframework/source/ImageLib/zlib/ChangeLog b/osframework/source/ImageLib/zlib/ChangeLog
new file mode 100644
index 0000000..392819c
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/ChangeLog
@@ -0,0 +1,471 @@
+
+ ChangeLog file for zlib
+
+Changes in 1.1.3 (9 July 1998)
+- fix "an inflate input buffer bug that shows up on rare but persistent
+ occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+ (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+ See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+- Support gzdopen on Mac with Metrowerks (Jason Linhart)
+- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
+- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
+- avoid some warnings with Borland C (Tom Tanner)
+- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
+- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
+- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
+- use libdir and includedir in Makefile.in (Tim Mooney)
+- support shared libraries on OSF1 V4 (Tim Mooney)
+- remove so_locations in "make clean" (Tim Mooney)
+- fix maketree.c compilation error (Glenn, Mark)
+- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
+- new Makefile.riscos (Rich Walker)
+- initialize static descriptors in trees.c for embedded targets (Nick Smith)
+- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
+- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
+- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
+- fix maketree.c to allow clean compilation of inffixed.h (Mark)
+- fix parameter check in deflateCopy (Gunther Nikl)
+- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
+- Many portability patches by Christian Spieler:
+ . zutil.c, zutil.h: added "const" for zmem*
+ . Make_vms.com: fixed some typos
+ . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
+ . msdos/Makefile.msc: remove "default rtl link library" info from obj files
+ . msdos/Makefile.*: use model-dependent name for the built zlib library
+ . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
+ new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
+- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
+- replace __far with _far for better portability (Christian Spieler, Tom Lane)
+- fix test for errno.h in configure (Tim Newsham)
+
+Changes in 1.1.2 (19 March 98)
+- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
+ See http://www.winimage.com/zLibDll/unzip.html
+- preinitialize the inflate tables for fixed codes, to make the code
+ completely thread safe (Mark)
+- some simplifications and slight speed-up to the inflate code (Mark)
+- fix gzeof on non-compressed files (Allan Schrum)
+- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
+- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
+- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
+- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
+- do not wrap extern "C" around system includes (Tom Lane)
+- mention zlib binding for TCL in README (Andreas Kupries)
+- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
+- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
+- allow "configure --prefix $HOME" (Tim Mooney)
+- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
+- move Makefile.sas to amiga/Makefile.sas
+
+Changes in 1.1.1 (27 Feb 98)
+- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
+- remove block truncation heuristic which had very marginal effect for zlib
+ (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
+ compression ratio on some files. This also allows inlining _tr_tally for
+ matches in deflate_slow.
+- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
+
+Changes in 1.1.0 (24 Feb 98)
+- do not return STREAM_END prematurely in inflate (John Bowler)
+- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
+- compile with -DFASTEST to get compression code optimized for speed only
+- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
+- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
+ on Sun but significant on HP)
+
+- add a pointer to experimental unzip library in README (Gilles Vollant)
+- initialize variable gcc in configure (Chris Herborth)
+
+Changes in 1.0.9 (17 Feb 1998)
+- added gzputs and gzgets functions
+- do not clear eof flag in gzseek (Mark Diekhans)
+- fix gzseek for files in transparent mode (Mark Diekhans)
+- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
+- replace EXPORT with ZEXPORT to avoid conflict with other programs
+- added compress2 in zconf.h, zlib.def, zlib.dnt
+- new asm code from Gilles Vollant in contrib/asm386
+- simplify the inflate code (Mark):
+ . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
+ . ZALLOC the length list in inflate_trees_fixed() instead of using stack
+ . ZALLOC the value area for huft_build() instead of using stack
+ . Simplify Z_FINISH check in inflate()
+
+- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
+- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
+- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
+ the declaration of FAR (Gilles VOllant)
+- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
+- read_buf buf parameter of type Bytef* instead of charf*
+- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
+- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
+- fix check for presence of directories in "make install" (Ian Willis)
+
+Changes in 1.0.8 (27 Jan 1998)
+- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
+- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
+- added compress2() to allow setting the compression level
+- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
+- use constant arrays for the static trees in trees.c instead of computing
+ them at run time (thanks to Ken Raeburn for this suggestion). To create
+ trees.h, compile with GEN_TREES_H and run "make test".
+- check return code of example in "make test" and display result
+- pass minigzip command line options to file_compress
+- simplifying code of inflateSync to avoid gcc 2.8 bug
+
+- support CC="gcc -Wall" in configure -s (QingLong)
+- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
+- fix test for shared library support to avoid compiler warnings
+- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
+- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
+- do not use fdopen for Metrowerks on Mac (Brad Pettit))
+- add checks for gzputc and gzputc in example.c
+- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
+- use const for the CRC table (Ken Raeburn)
+- fixed "make uninstall" for shared libraries
+- use Tracev instead of Trace in infblock.c
+- in example.c use correct compressed length for test_sync
+- suppress +vnocompatwarnings in configure for HPUX (not always supported)
+
+Changes in 1.0.7 (20 Jan 1998)
+- fix gzseek which was broken in write mode
+- return error for gzseek to negative absolute position
+- fix configure for Linux (Chun-Chung Chen)
+- increase stack space for MSC (Tim Wegner)
+- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
+- define EXPORTVA for gzprintf (Gilles Vollant)
+- added man page zlib.3 (Rick Rodgers)
+- for contrib/untgz, fix makedir() and improve Makefile
+
+- check gzseek in write mode in example.c
+- allocate extra buffer for seeks only if gzseek is actually called
+- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
+- add inflateSyncPoint in zconf.h
+- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
+
+Changes in 1.0.6 (19 Jan 1998)
+- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
+ gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
+- Fix a deflate bug occuring only with compression level 0 (thanks to
+ Andy Buckler for finding this one).
+- In minigzip, pass transparently also the first byte for .Z files.
+- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
+- check Z_FINISH in inflate (thanks to Marc Schluper)
+- Implement deflateCopy (thanks to Adam Costello)
+- make static libraries by default in configure, add --shared option.
+- move MSDOS or Windows specific files to directory msdos
+- suppress the notion of partial flush to simplify the interface
+ (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
+- suppress history buffer provided by application to simplify the interface
+ (this feature was not implemented anyway in 1.0.4)
+- next_in and avail_in must be initialized before calling inflateInit or
+ inflateInit2
+- add EXPORT in all exported functions (for Windows DLL)
+- added Makefile.nt (thanks to Stephen Williams)
+- added the unsupported "contrib" directory:
+ contrib/asm386/ by Gilles Vollant <info@winimage.com>
+ 386 asm code replacing longest_match().
+ contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+ A C++ I/O streams interface to the zlib gz* functions
+ contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
+ Another C++ I/O streams interface
+ contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+ A very simple tar.gz file extractor using zlib
+ contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+ How to use compress(), uncompress() and the gz* functions from VB.
+- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
+ level) in minigzip (thanks to Tom Lane)
+
+- use const for rommable constants in deflate
+- added test for gzseek and gztell in example.c
+- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
+- add undocumented function zError to convert error code to string
+ (for Tim Smithers)
+- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
+- Use default memcpy for Symantec MSDOS compiler.
+- Add EXPORT keyword for check_func (needed for Windows DLL)
+- add current directory to LD_LIBRARY_PATH for "make test"
+- create also a link for libz.so.1
+- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
+- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
+- added -soname for Linux in configure (Chun-Chung Chen,
+- assign numbers to the exported functions in zlib.def (for Windows DLL)
+- add advice in zlib.h for best usage of deflateSetDictionary
+- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
+- allow compilation with ANSI keywords only enabled for TurboC in large model
+- avoid "versionString"[0] (Borland bug)
+- add NEED_DUMMY_RETURN for Borland
+- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
+- allow compilation with CC
+- defined STDC for OS/2 (David Charlap)
+- limit external names to 8 chars for MVS (Thomas Lund)
+- in minigzip.c, use static buffers only for 16-bit systems
+- fix suffix check for "minigzip -d foo.gz"
+- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
+- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
+- added makelcc.bat for lcc-win32 (Tom St Denis)
+- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
+- Avoid expanded $Id: ChangeLog,v 1.1 2003/04/29 21:57:48 ace Exp $. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- check for unistd.h in configure (for off_t)
+- remove useless check parameter in inflate_blocks_free
+- avoid useless assignment of s->check to itself in inflate_blocks_new
+- do not flush twice in gzclose (thanks to Ken Raeburn)
+- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
+- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
+- work around buggy fclose on pipes for HP/UX
+- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
+- fix configure if CC is already equal to gcc
+
+Changes in 1.0.5 (3 Jan 98)
+- Fix inflate to terminate gracefully when fed corrupted or invalid data
+- Use const for rommable constants in inflate
+- Eliminate memory leaks on error conditions in inflate
+- Removed some vestigial code in inflate
+- Update web address in README
+
+Changes in 1.0.4 (24 Jul 96)
+- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
+ bit, so the decompressor could decompress all the correct data but went
+ on to attempt decompressing extra garbage data. This affected minigzip too.
+- zlibVersion and gzerror return const char* (needed for DLL)
+- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
+- use z_error only for DEBUG (avoid problem with DLLs)
+
+Changes in 1.0.3 (2 Jul 96)
+- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
+ small and medium models; this makes the library incompatible with previous
+ versions for these models. (No effect in large model or on other systems.)
+- return OK instead of BUF_ERROR if previous deflate call returned with
+ avail_out as zero but there is nothing to do
+- added memcmp for non STDC compilers
+- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
+- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
+- better check for 16-bit mode MSC (avoids problem with Symantec)
+
+Changes in 1.0.2 (23 May 96)
+- added Windows DLL support
+- added a function zlibVersion (for the DLL support)
+- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
+- Bytef is define's instead of typedef'd only for Borland C
+- avoid reading uninitialized memory in example.c
+- mention in README that the zlib format is now RFC1950
+- updated Makefile.dj2
+- added algorithm.doc
+
+Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
+- fix array overlay in deflate.c which sometimes caused bad compressed data
+- fix inflate bug with empty stored block
+- fix MSDOS medium model which was broken in 0.99
+- fix deflateParams() which could generated bad compressed data.
+- Bytef is define'd instead of typedef'ed (work around Borland bug)
+- added an INDEX file
+- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
+ Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
+- speed up adler32 for modern machines without auto-increment
+- added -ansi for IRIX in configure
+- static_init_done in trees.c is an int
+- define unlink as delete for VMS
+- fix configure for QNX
+- add configure branch for SCO and HPUX
+- avoid many warnings (unused variables, dead assignments, etc...)
+- no fdopen for BeOS
+- fix the Watcom fix for 32 bit mode (define FAR as empty)
+- removed redefinition of Byte for MKWERKS
+- work around an MWKERKS bug (incorrect merge of all .h files)
+
+Changes in 0.99 (27 Jan 96)
+- allow preset dictionary shared between compressor and decompressor
+- allow compression level 0 (no compression)
+- add deflateParams in zlib.h: allow dynamic change of compression level
+ and compression strategy.
+- test large buffers and deflateParams in example.c
+- add optional "configure" to build zlib as a shared library
+- suppress Makefile.qnx, use configure instead
+- fixed deflate for 64-bit systems (detected on Cray)
+- fixed inflate_blocks for 64-bit systems (detected on Alpha)
+- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
+- always return Z_BUF_ERROR when deflate() has nothing to do
+- deflateInit and inflateInit are now macros to allow version checking
+- prefix all global functions and types with z_ with -DZ_PREFIX
+- make falloc completely reentrant (inftrees.c)
+- fixed very unlikely race condition in ct_static_init
+- free in reverse order of allocation to help memory manager
+- use zlib-1.0/* instead of zlib/* inside the tar.gz
+- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
+ -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
+- allow gzread on concatenated .gz files
+- deflateEnd now returns Z_DATA_ERROR if it was premature
+- deflate is finally (?) fully deterministic (no matches beyond end of input)
+- Document Z_SYNC_FLUSH
+- add uninstall in Makefile
+- Check for __cpluplus in zlib.h
+- Better test in ct_align for partial flush
+- avoid harmless warnings for Borland C++
+- initialize hash_head in deflate.c
+- avoid warning on fdopen (gzio.c) for HP cc -Aa
+- include stdlib.h for STDC compilers
+- include errno.h for Cray
+- ignore error if ranlib doesn't exist
+- call ranlib twice for NeXTSTEP
+- use exec_prefix instead of prefix for libz.a
+- renamed ct_* as _tr_* to avoid conflict with applications
+- clear z->msg in inflateInit2 before any error return
+- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
+- fixed typo in zconf.h (_GNUC__ => __GNUC__)
+- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
+- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
+- in fcalloc, normalize pointer if size > 65520 bytes
+- don't use special fcalloc for 32 bit Borland C++
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
+- use Z_BINARY instead of BINARY
+- document that gzclose after gzdopen will close the file
+- allow "a" as mode in gzopen.
+- fix error checking in gzread
+- allow skipping .gz extra-field on pipes
+- added reference to Perl interface in README
+- put the crc table in FAR data (I dislike more and more the medium model :)
+- added get_crc_table
+- added a dimension to all arrays (Borland C can't count).
+- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
+- guard against multiple inclusion of *.h (for precompiled header on Mac)
+- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
+- don't use unsized arrays to avoid silly warnings by Visual C++:
+ warning C4746: 'inflate_mask' : unsized array treated as '__far'
+ (what's wrong with far data in far model?).
+- define enum out of inflate_blocks_state to allow compilation with C++
+
+Changes in 0.95 (16 Aug 95)
+- fix MSDOS small and medium model (now easier to adapt to any compiler)
+- inlined send_bits
+- fix the final (:-) bug for deflate with flush (output was correct but
+ not completely flushed in rare occasions).
+- default window size is same for compression and decompression
+ (it's now sufficient to set MAX_WBITS in zconf.h).
+- voidp -> voidpf and voidnp -> voidp (for consistency with other
+ typedefs and because voidnp was not near in large model).
+
+Changes in 0.94 (13 Aug 95)
+- support MSDOS medium model
+- fix deflate with flush (could sometimes generate bad output)
+- fix deflateReset (zlib header was incorrectly suppressed)
+- added support for VMS
+- allow a compression level in gzopen()
+- gzflush now calls fflush
+- For deflate with flush, flush even if no more input is provided.
+- rename libgz.a as libz.a
+- avoid complex expression in infcodes.c triggering Turbo C bug
+- work around a problem with gcc on Alpha (in INSERT_STRING)
+- don't use inline functions (problem with some gcc versions)
+- allow renaming of Byte, uInt, etc... with #define.
+- avoid warning about (unused) pointer before start of array in deflate.c
+- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
+- avoid reserved word 'new' in trees.c
+
+Changes in 0.93 (25 June 95)
+- temporarily disable inline functions
+- make deflate deterministic
+- give enough lookahead for PARTIAL_FLUSH
+- Set binary mode for stdin/stdout in minigzip.c for OS/2
+- don't even use signed char in inflate (not portable enough)
+- fix inflate memory leak for segmented architectures
+
+Changes in 0.92 (3 May 95)
+- don't assume that char is signed (problem on SGI)
+- Clear bit buffer when starting a stored block
+- no memcpy on Pyramid
+- suppressed inftest.c
+- optimized fill_window, put longest_match inline for gcc
+- optimized inflate on stored blocks.
+- untabify all sources to simplify patches
+
+Changes in 0.91 (2 May 95)
+- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
+- Document the memory requirements in zconf.h
+- added "make install"
+- fix sync search logic in inflateSync
+- deflate(Z_FULL_FLUSH) now works even if output buffer too short
+- after inflateSync, don't scare people with just "lo world"
+- added support for DJGPP
+
+Changes in 0.9 (1 May 95)
+- don't assume that zalloc clears the allocated memory (the TurboC bug
+ was Mark's bug after all :)
+- let again gzread copy uncompressed data unchanged (was working in 0.71)
+- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
+- added a test of inflateSync in example.c
+- moved MAX_WBITS to zconf.h because users might want to change that.
+- document explicitly that zalloc(64K) on MSDOS must return a normalized
+ pointer (zero offset)
+- added Makefiles for Microsoft C, Turbo C, Borland C++
+- faster crc32()
+
+Changes in 0.8 (29 April 95)
+- added fast inflate (inffast.c)
+- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
+ is incompatible with previous versions of zlib which returned Z_OK.
+- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
+ (actually that was not a compiler bug, see 0.81 above)
+- gzread no longer reads one extra byte in certain cases
+- In gzio destroy(), don't reference a freed structure
+- avoid many warnings for MSDOS
+- avoid the ERROR symbol which is used by MS Windows
+
+Changes in 0.71 (14 April 95)
+- Fixed more MSDOS compilation problems :( There is still a bug with
+ TurboC large model.
+
+Changes in 0.7 (14 April 95)
+- Added full inflate support.
+- Simplified the crc32() interface. The pre- and post-conditioning
+ (one's complement) is now done inside crc32(). WARNING: this is
+ incompatible with previous versions; see zlib.h for the new usage.
+
+Changes in 0.61 (12 April 95)
+- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
+
+Changes in 0.6 (11 April 95)
+- added minigzip.c
+- added gzdopen to reopen a file descriptor as gzFile
+- added transparent reading of non-gziped files in gzread.
+- fixed bug in gzread (don't read crc as data)
+- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
+- don't allocate big arrays in the stack (for MSDOS)
+- fix some MSDOS compilation problems
+
+Changes in 0.5:
+- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
+ not yet Z_FULL_FLUSH.
+- support decompression but only in a single step (forced Z_FINISH)
+- added opaque object for zalloc and zfree.
+- added deflateReset and inflateReset
+- added a variable zlib_version for consistency checking.
+- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
+ Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
+
+Changes in 0.4:
+- avoid "zip" everywhere, use zlib instead of ziplib.
+- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
+ if compression method == 8.
+- added adler32 and crc32
+- renamed deflateOptions as deflateInit2, call one or the other but not both
+- added the method parameter for deflateInit2.
+- added inflateInit2
+- simplied considerably deflateInit and inflateInit by not supporting
+ user-provided history buffer. This is supported only in deflateInit2
+ and inflateInit2.
+
+Changes in 0.3:
+- prefix all macro names with Z_
+- use Z_FINISH instead of deflateEnd to finish compression.
+- added Z_HUFFMAN_ONLY
+- added gzerror()
diff --git a/osframework/source/ImageLib/zlib/Make_vms.com b/osframework/source/ImageLib/zlib/Make_vms.com
new file mode 100644
index 0000000..3788817
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/Make_vms.com
@@ -0,0 +1,115 @@
+$! make libz under VMS
+$! written by Martin P.J. Zinser <m.zinser@gsi.de>
+$!
+$! Look for the compiler used
+$!
+$ ccopt = ""
+$ if f$getsyi("HW_MODEL").ge.1024
+$ then
+$ ccopt = "/prefix=all"+ccopt
+$ comp = "__decc__=1"
+$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
+$ else
+$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
+$ then
+$ comp = "__vaxc__=1"
+$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
+$ else
+$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
+$ ccopt = "/decc/prefix=all"+ccopt
+$ comp = "__decc__=1"
+$ endif
+$ endif
+$!
+$! Build the thing plain or with mms
+$!
+$ write sys$output "Compiling Zlib sources ..."
+$ if f$search("SYS$SYSTEM:MMS.EXE").eqs.""
+$ then
+$ dele example.obj;*,minigzip.obj;*
+$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
+ adler32.c zlib.h zconf.h
+$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
+ compress.c zlib.h zconf.h
+$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
+ crc32.c zlib.h zconf.h
+$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
+ deflate.c deflate.h zutil.h zlib.h zconf.h
+$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" -
+ gzio.c zutil.h zlib.h zconf.h
+$ CALL MAKE infblock.OBJ "CC ''CCOPT' infblock" -
+ infblock.c zutil.h zlib.h zconf.h infblock.h
+$ CALL MAKE infcodes.OBJ "CC ''CCOPT' infcodes" -
+ infcodes.c zutil.h zlib.h zconf.h inftrees.h
+$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
+ inffast.c zutil.h zlib.h zconf.h inffast.h
+$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" -
+ inflate.c zutil.h zlib.h zconf.h infblock.h
+$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" -
+ inftrees.c zutil.h zlib.h zconf.h inftrees.h
+$ CALL MAKE infutil.OBJ "CC ''CCOPT' infutil" -
+ infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h
+$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" -
+ trees.c deflate.h zutil.h zlib.h zconf.h
+$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" -
+ uncompr.c zlib.h zconf.h
+$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
+ zutil.c zutil.h zlib.h zconf.h
+$ write sys$output "Building Zlib ..."
+$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
+$ write sys$output "Building example..."
+$ CALL MAKE example.OBJ "CC ''CCOPT' example" -
+ example.c zlib.h zconf.h
+$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
+$ write sys$output "Building minigzip..."
+$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" -
+ minigzip.c zlib.h zconf.h
+$ call make minigzip.exe -
+ "LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" -
+ minigzip.obj libz.olb
+$ else
+$ mms/macro=('comp')
+$ endif
+$ write sys$output "Zlib build completed"
+$ exit
+$!
+$!
+$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
+$ V = 'F$Verify(0)
+$! P1 = What we are trying to make
+$! P2 = Command to make it
+$! P3 - P8 What it depends on
+$
+$ If F$Search(P1) .Eqs. "" Then Goto Makeit
+$ Time = F$CvTime(F$File(P1,"RDT"))
+$arg=3
+$Loop:
+$ Argument = P'arg
+$ If Argument .Eqs. "" Then Goto Exit
+$ El=0
+$Loop2:
+$ File = F$Element(El," ",Argument)
+$ If File .Eqs. " " Then Goto Endl
+$ AFile = ""
+$Loop3:
+$ OFile = AFile
+$ AFile = F$Search(File)
+$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
+$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
+$ Goto Loop3
+$NextEL:
+$ El = El + 1
+$ Goto Loop2
+$EndL:
+$ arg=arg+1
+$ If arg .Le. 8 Then Goto Loop
+$ Goto Exit
+$
+$Makeit:
+$ VV=F$VERIFY(0)
+$ write sys$output P2
+$ 'P2
+$ VV='F$Verify(VV)
+$Exit:
+$ If V Then Set Verify
+$ENDSUBROUTINE
diff --git a/osframework/source/ImageLib/zlib/Makefile b/osframework/source/ImageLib/zlib/Makefile
new file mode 100644
index 0000000..4b1472d
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/Makefile
@@ -0,0 +1,174 @@
+# Makefile for zlib
+# Copyright (C) 1995-1998 Jean-loup Gailly.
+# For conditions of distribution and use, see copyright notice in zlib.h
+
+# To compile and test, type:
+# ./configure; make test
+# The call of configure is optional if you don't have special requirements
+# If you wish to build zlib as a shared library, use: ./configure -s
+
+# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
+# make install
+# To install in $HOME instead of /usr/local, use:
+# make install prefix=$HOME
+
+CC=cc
+
+CFLAGS=-O
+#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
+#CFLAGS=-g -DDEBUG
+#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
+# -Wstrict-prototypes -Wmissing-prototypes
+
+LDFLAGS=-L. -lz
+LDSHARED=$(CC)
+CPP=$(CC) -E
+
+VER=1.1.3
+LIBS=libz.a
+SHAREDLIB=libz.so
+
+AR=ar rc
+RANLIB=ranlib
+TAR=tar
+SHELL=/bin/sh
+
+prefix = /usr/local
+exec_prefix = ${prefix}
+libdir = ${exec_prefix}/lib
+includedir = ${prefix}/include
+
+OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
+ zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
+
+OBJA =
+# to use the asm code: make OBJA=match.o
+
+TEST_OBJS = example.o minigzip.o
+
+DISTFILES = README FAQ INDEX ChangeLog configure Make*[a-z0-9] *.[ch] *.mms \
+ algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \
+ nt/Make*[a-z0-9] nt/zlib.dnt amiga/Make*.??? os2/M*.os2 os2/zlib.def \
+ contrib/RE*.contrib contrib/*.txt contrib/asm386/*.asm contrib/asm386/*.c \
+ contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/asm[56]86/*.?86 \
+ contrib/asm[56]86/*.S contrib/iostream/*.cpp \
+ contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \
+ contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 \
+ contrib/minizip/[CM]*[pe] contrib/minizip/*.[ch] contrib/minizip/*.[td]?? \
+ contrib/delphi*/*.???
+
+all: example minigzip
+
+test: all
+ @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
+ echo hello world | ./minigzip | ./minigzip -d || \
+ echo ' *** minigzip test FAILED ***' ; \
+ if ./example; then \
+ echo ' *** zlib test OK ***'; \
+ else \
+ echo ' *** zlib test FAILED ***'; \
+ fi
+
+libz.a: $(OBJS) $(OBJA)
+ $(AR) $@ $(OBJS) $(OBJA)
+ -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
+
+match.o: match.S
+ $(CPP) match.S > _match.s
+ $(CC) -c _match.s
+ mv _match.o match.o
+ rm -f _match.s
+
+$(SHAREDLIB).$(VER): $(OBJS)
+ $(LDSHARED) -o $@ $(OBJS)
+ rm -f $(SHAREDLIB) $(SHAREDLIB).1
+ ln -s $@ $(SHAREDLIB)
+ ln -s $@ $(SHAREDLIB).1
+
+example: example.o $(LIBS)
+ $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
+
+minigzip: minigzip.o $(LIBS)
+ $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
+
+install: $(LIBS)
+ -@if [ ! -d $(includedir) ]; then mkdir $(includedir); fi
+ -@if [ ! -d $(libdir) ]; then mkdir $(libdir); fi
+ cp zlib.h zconf.h $(includedir)
+ chmod 644 $(includedir)/zlib.h $(includedir)/zconf.h
+ cp $(LIBS) $(libdir)
+ cd $(libdir); chmod 755 $(LIBS)
+ -@(cd $(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
+ cd $(libdir); if test -f $(SHAREDLIB).$(VER); then \
+ rm -f $(SHAREDLIB) $(SHAREDLIB).1; \
+ ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \
+ ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \
+ (ldconfig || true) >/dev/null 2>&1; \
+ fi
+# The ranlib in install is needed on NeXTSTEP which checks file times
+# ldconfig is for Linux
+
+uninstall:
+ cd $(includedir); \
+ v=$(VER); \
+ if test -f zlib.h; then \
+ v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`; \
+ rm -f zlib.h zconf.h; \
+ fi; \
+ cd $(libdir); rm -f libz.a; \
+ if test -f $(SHAREDLIB).$$v; then \
+ rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \
+ fi
+
+clean:
+ rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \
+ _match.s maketree
+
+distclean: clean
+
+zip:
+ mv Makefile Makefile~; cp -p Makefile.in Makefile
+ rm -f test.c ztest*.c contrib/minizip/test.zip
+ v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
+ zip -ul9 zlib$$v $(DISTFILES)
+ mv Makefile~ Makefile
+
+dist:
+ mv Makefile Makefile~; cp -p Makefile.in Makefile
+ rm -f test.c ztest*.c contrib/minizip/test.zip
+ d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
+ rm -f $$d.tar.gz; \
+ if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \
+ files=""; \
+ for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \
+ cd ..; \
+ GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \
+ if test ! -d $$d; then rm -f $$d; fi
+ mv Makefile~ Makefile
+
+tags:
+ etags *.[ch]
+
+depend:
+ makedepend -- $(CFLAGS) -- *.[ch]
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+adler32.o: zlib.h zconf.h
+compress.o: zlib.h zconf.h
+crc32.o: zlib.h zconf.h
+deflate.o: deflate.h zutil.h zlib.h zconf.h
+example.o: zlib.h zconf.h
+gzio.o: zutil.h zlib.h zconf.h
+infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h
+infcodes.o: zutil.h zlib.h zconf.h
+infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h
+inffast.o: zutil.h zlib.h zconf.h inftrees.h
+inffast.o: infblock.h infcodes.h infutil.h inffast.h
+inflate.o: zutil.h zlib.h zconf.h infblock.h
+inftrees.o: zutil.h zlib.h zconf.h inftrees.h
+infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
+minigzip.o: zlib.h zconf.h
+trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
+uncompr.o: zlib.h zconf.h
+zutil.o: zutil.h zlib.h zconf.h
diff --git a/osframework/source/ImageLib/zlib/Makefile.in b/osframework/source/ImageLib/zlib/Makefile.in
new file mode 100644
index 0000000..4b1472d
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/Makefile.in
@@ -0,0 +1,174 @@
+# Makefile for zlib
+# Copyright (C) 1995-1998 Jean-loup Gailly.
+# For conditions of distribution and use, see copyright notice in zlib.h
+
+# To compile and test, type:
+# ./configure; make test
+# The call of configure is optional if you don't have special requirements
+# If you wish to build zlib as a shared library, use: ./configure -s
+
+# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
+# make install
+# To install in $HOME instead of /usr/local, use:
+# make install prefix=$HOME
+
+CC=cc
+
+CFLAGS=-O
+#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
+#CFLAGS=-g -DDEBUG
+#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
+# -Wstrict-prototypes -Wmissing-prototypes
+
+LDFLAGS=-L. -lz
+LDSHARED=$(CC)
+CPP=$(CC) -E
+
+VER=1.1.3
+LIBS=libz.a
+SHAREDLIB=libz.so
+
+AR=ar rc
+RANLIB=ranlib
+TAR=tar
+SHELL=/bin/sh
+
+prefix = /usr/local
+exec_prefix = ${prefix}
+libdir = ${exec_prefix}/lib
+includedir = ${prefix}/include
+
+OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
+ zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
+
+OBJA =
+# to use the asm code: make OBJA=match.o
+
+TEST_OBJS = example.o minigzip.o
+
+DISTFILES = README FAQ INDEX ChangeLog configure Make*[a-z0-9] *.[ch] *.mms \
+ algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \
+ nt/Make*[a-z0-9] nt/zlib.dnt amiga/Make*.??? os2/M*.os2 os2/zlib.def \
+ contrib/RE*.contrib contrib/*.txt contrib/asm386/*.asm contrib/asm386/*.c \
+ contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/asm[56]86/*.?86 \
+ contrib/asm[56]86/*.S contrib/iostream/*.cpp \
+ contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \
+ contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 \
+ contrib/minizip/[CM]*[pe] contrib/minizip/*.[ch] contrib/minizip/*.[td]?? \
+ contrib/delphi*/*.???
+
+all: example minigzip
+
+test: all
+ @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
+ echo hello world | ./minigzip | ./minigzip -d || \
+ echo ' *** minigzip test FAILED ***' ; \
+ if ./example; then \
+ echo ' *** zlib test OK ***'; \
+ else \
+ echo ' *** zlib test FAILED ***'; \
+ fi
+
+libz.a: $(OBJS) $(OBJA)
+ $(AR) $@ $(OBJS) $(OBJA)
+ -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
+
+match.o: match.S
+ $(CPP) match.S > _match.s
+ $(CC) -c _match.s
+ mv _match.o match.o
+ rm -f _match.s
+
+$(SHAREDLIB).$(VER): $(OBJS)
+ $(LDSHARED) -o $@ $(OBJS)
+ rm -f $(SHAREDLIB) $(SHAREDLIB).1
+ ln -s $@ $(SHAREDLIB)
+ ln -s $@ $(SHAREDLIB).1
+
+example: example.o $(LIBS)
+ $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
+
+minigzip: minigzip.o $(LIBS)
+ $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
+
+install: $(LIBS)
+ -@if [ ! -d $(includedir) ]; then mkdir $(includedir); fi
+ -@if [ ! -d $(libdir) ]; then mkdir $(libdir); fi
+ cp zlib.h zconf.h $(includedir)
+ chmod 644 $(includedir)/zlib.h $(includedir)/zconf.h
+ cp $(LIBS) $(libdir)
+ cd $(libdir); chmod 755 $(LIBS)
+ -@(cd $(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
+ cd $(libdir); if test -f $(SHAREDLIB).$(VER); then \
+ rm -f $(SHAREDLIB) $(SHAREDLIB).1; \
+ ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \
+ ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \
+ (ldconfig || true) >/dev/null 2>&1; \
+ fi
+# The ranlib in install is needed on NeXTSTEP which checks file times
+# ldconfig is for Linux
+
+uninstall:
+ cd $(includedir); \
+ v=$(VER); \
+ if test -f zlib.h; then \
+ v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`; \
+ rm -f zlib.h zconf.h; \
+ fi; \
+ cd $(libdir); rm -f libz.a; \
+ if test -f $(SHAREDLIB).$$v; then \
+ rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \
+ fi
+
+clean:
+ rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \
+ _match.s maketree
+
+distclean: clean
+
+zip:
+ mv Makefile Makefile~; cp -p Makefile.in Makefile
+ rm -f test.c ztest*.c contrib/minizip/test.zip
+ v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
+ zip -ul9 zlib$$v $(DISTFILES)
+ mv Makefile~ Makefile
+
+dist:
+ mv Makefile Makefile~; cp -p Makefile.in Makefile
+ rm -f test.c ztest*.c contrib/minizip/test.zip
+ d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
+ rm -f $$d.tar.gz; \
+ if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \
+ files=""; \
+ for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \
+ cd ..; \
+ GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \
+ if test ! -d $$d; then rm -f $$d; fi
+ mv Makefile~ Makefile
+
+tags:
+ etags *.[ch]
+
+depend:
+ makedepend -- $(CFLAGS) -- *.[ch]
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
+
+adler32.o: zlib.h zconf.h
+compress.o: zlib.h zconf.h
+crc32.o: zlib.h zconf.h
+deflate.o: deflate.h zutil.h zlib.h zconf.h
+example.o: zlib.h zconf.h
+gzio.o: zutil.h zlib.h zconf.h
+infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h
+infcodes.o: zutil.h zlib.h zconf.h
+infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h
+inffast.o: zutil.h zlib.h zconf.h inftrees.h
+inffast.o: infblock.h infcodes.h infutil.h inffast.h
+inflate.o: zutil.h zlib.h zconf.h infblock.h
+inftrees.o: zutil.h zlib.h zconf.h inftrees.h
+infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
+minigzip.o: zlib.h zconf.h
+trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
+uncompr.o: zlib.h zconf.h
+zutil.o: zutil.h zlib.h zconf.h
diff --git a/osframework/source/ImageLib/zlib/Makefile.riscos b/osframework/source/ImageLib/zlib/Makefile.riscos
new file mode 100644
index 0000000..8ba72ca
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/Makefile.riscos
@@ -0,0 +1,151 @@
+# Project: zlib_1_03
+# Patched for zlib 1.1.2 rw@shadow.org.uk 19980430
+# test works out-of-the-box, installs `somewhere' on demand
+
+# Toolflags:
+CCflags = -c -depend !Depend -IC: -g -throwback -DRISCOS -fah
+C++flags = -c -depend !Depend -IC: -throwback
+Linkflags = -aif -c++ -o $@
+ObjAsmflags = -throwback -NoCache -depend !Depend
+CMHGflags =
+LibFileflags = -c -l -o $@
+Squeezeflags = -o $@
+
+# change the line below to where _you_ want the library installed.
+libdest = lib:zlib
+
+# Final targets:
+@.lib: @.o.adler32 @.o.compress @.o.crc32 @.o.deflate @.o.gzio \
+ @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil @.o.trees \
+ @.o.uncompr @.o.zutil
+ LibFile $(LibFileflags) @.o.adler32 @.o.compress @.o.crc32 @.o.deflate \
+ @.o.gzio @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil \
+ @.o.trees @.o.uncompr @.o.zutil
+test: @.minigzip @.example @.lib
+ @copy @.lib @.libc A~C~DF~L~N~P~Q~RS~TV
+ @echo running tests: hang on.
+ @/@.minigzip -f -9 libc
+ @/@.minigzip -d libc-gz
+ @/@.minigzip -f -1 libc
+ @/@.minigzip -d libc-gz
+ @/@.minigzip -h -9 libc
+ @/@.minigzip -d libc-gz
+ @/@.minigzip -h -1 libc
+ @/@.minigzip -d libc-gz
+ @/@.minigzip -9 libc
+ @/@.minigzip -d libc-gz
+ @/@.minigzip -1 libc
+ @/@.minigzip -d libc-gz
+ @diff @.lib @.libc
+ @echo that should have reported '@.lib and @.libc identical' if you have diff.
+ @/@.example @.fred @.fred
+ @echo that will have given lots of hello!'s.
+
+@.minigzip: @.o.minigzip @.lib C:o.Stubs
+ Link $(Linkflags) @.o.minigzip @.lib C:o.Stubs
+@.example: @.o.example @.lib C:o.Stubs
+ Link $(Linkflags) @.o.example @.lib C:o.Stubs
+
+install: @.lib
+ cdir $(libdest)
+ cdir $(libdest).h
+ @copy @.h.zlib $(libdest).h.zlib A~C~DF~L~N~P~Q~RS~TV
+ @copy @.h.zconf $(libdest).h.zconf A~C~DF~L~N~P~Q~RS~TV
+ @copy @.lib $(libdest).lib A~C~DF~L~N~P~Q~RS~TV
+ @echo okay, installed zlib in $(libdest)
+
+clean:; remove @.minigzip
+ remove @.example
+ remove @.libc
+ -wipe @.o.* F~r~cV
+ remove @.fred
+
+# User-editable dependencies:
+.c.o:
+ cc $(ccflags) -o $@ $<
+
+# Static dependencies:
+
+# Dynamic dependencies:
+o.example: c.example
+o.example: h.zlib
+o.example: h.zconf
+o.minigzip: c.minigzip
+o.minigzip: h.zlib
+o.minigzip: h.zconf
+o.adler32: c.adler32
+o.adler32: h.zlib
+o.adler32: h.zconf
+o.compress: c.compress
+o.compress: h.zlib
+o.compress: h.zconf
+o.crc32: c.crc32
+o.crc32: h.zlib
+o.crc32: h.zconf
+o.deflate: c.deflate
+o.deflate: h.deflate
+o.deflate: h.zutil
+o.deflate: h.zlib
+o.deflate: h.zconf
+o.gzio: c.gzio
+o.gzio: h.zutil
+o.gzio: h.zlib
+o.gzio: h.zconf
+o.infblock: c.infblock
+o.infblock: h.zutil
+o.infblock: h.zlib
+o.infblock: h.zconf
+o.infblock: h.infblock
+o.infblock: h.inftrees
+o.infblock: h.infcodes
+o.infblock: h.infutil
+o.infcodes: c.infcodes
+o.infcodes: h.zutil
+o.infcodes: h.zlib
+o.infcodes: h.zconf
+o.infcodes: h.inftrees
+o.infcodes: h.infblock
+o.infcodes: h.infcodes
+o.infcodes: h.infutil
+o.infcodes: h.inffast
+o.inffast: c.inffast
+o.inffast: h.zutil
+o.inffast: h.zlib
+o.inffast: h.zconf
+o.inffast: h.inftrees
+o.inffast: h.infblock
+o.inffast: h.infcodes
+o.inffast: h.infutil
+o.inffast: h.inffast
+o.inflate: c.inflate
+o.inflate: h.zutil
+o.inflate: h.zlib
+o.inflate: h.zconf
+o.inflate: h.infblock
+o.inftrees: c.inftrees
+o.inftrees: h.zutil
+o.inftrees: h.zlib
+o.inftrees: h.zconf
+o.inftrees: h.inftrees
+o.inftrees: h.inffixed
+o.infutil: c.infutil
+o.infutil: h.zutil
+o.infutil: h.zlib
+o.infutil: h.zconf
+o.infutil: h.infblock
+o.infutil: h.inftrees
+o.infutil: h.infcodes
+o.infutil: h.infutil
+o.trees: c.trees
+o.trees: h.deflate
+o.trees: h.zutil
+o.trees: h.zlib
+o.trees: h.zconf
+o.trees: h.trees
+o.uncompr: c.uncompr
+o.uncompr: h.zlib
+o.uncompr: h.zconf
+o.zutil: c.zutil
+o.zutil: h.zutil
+o.zutil: h.zlib
+o.zutil: h.zconf
diff --git a/osframework/source/ImageLib/zlib/adler32.c b/osframework/source/ImageLib/zlib/adler32.c
new file mode 100644
index 0000000..d36febd
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/adler32.c
@@ -0,0 +1,48 @@
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: adler32.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "zlib.h"
+
+#define BASE 65521L /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
+
+#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
+#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
+#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
+#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
+#define DO16(buf) DO8(buf,0); DO8(buf,8);
+
+/* ========================================================================= */
+uLong ZEXPORT adler32(adler, buf, len)
+ uLong adler;
+ const Bytef *buf;
+ uInt len;
+{
+ unsigned long s1 = adler & 0xffff;
+ unsigned long s2 = (adler >> 16) & 0xffff;
+ int k;
+
+ if (buf == Z_NULL) return 1L;
+
+ while (len > 0) {
+ k = len < NMAX ? len : NMAX;
+ len -= k;
+ while (k >= 16) {
+ DO16(buf);
+ buf += 16;
+ k -= 16;
+ }
+ if (k != 0) do {
+ s1 += *buf++;
+ s2 += s1;
+ } while (--k);
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ return (s2 << 16) | s1;
+}
diff --git a/osframework/source/ImageLib/zlib/algorithm.txt b/osframework/source/ImageLib/zlib/algorithm.txt
new file mode 100644
index 0000000..f488cd1
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/algorithm.txt
@@ -0,0 +1,213 @@
+1. Compression algorithm (deflate)
+
+The deflation algorithm used by gzip (also zip and zlib) is a variation of
+LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
+the input data. The second occurrence of a string is replaced by a
+pointer to the previous string, in the form of a pair (distance,
+length). Distances are limited to 32K bytes, and lengths are limited
+to 258 bytes. When a string does not occur anywhere in the previous
+32K bytes, it is emitted as a sequence of literal bytes. (In this
+description, `string' must be taken as an arbitrary sequence of bytes,
+and is not restricted to printable characters.)
+
+Literals or match lengths are compressed with one Huffman tree, and
+match distances are compressed with another tree. The trees are stored
+in a compact form at the start of each block. The blocks can have any
+size (except that the compressed data for one block must fit in
+available memory). A block is terminated when deflate() determines that
+it would be useful to start another block with fresh trees. (This is
+somewhat similar to the behavior of LZW-based _compress_.)
+
+Duplicated strings are found using a hash table. All input strings of
+length 3 are inserted in the hash table. A hash index is computed for
+the next 3 bytes. If the hash chain for this index is not empty, all
+strings in the chain are compared with the current input string, and
+the longest match is selected.
+
+The hash chains are searched starting with the most recent strings, to
+favor small distances and thus take advantage of the Huffman encoding.
+The hash chains are singly linked. There are no deletions from the
+hash chains, the algorithm simply discards matches that are too old.
+
+To avoid a worst-case situation, very long hash chains are arbitrarily
+truncated at a certain length, determined by a runtime option (level
+parameter of deflateInit). So deflate() does not always find the longest
+possible match but generally finds a match which is long enough.
+
+deflate() also defers the selection of matches with a lazy evaluation
+mechanism. After a match of length N has been found, deflate() searches for
+a longer match at the next input byte. If a longer match is found, the
+previous match is truncated to a length of one (thus producing a single
+literal byte) and the process of lazy evaluation begins again. Otherwise,
+the original match is kept, and the next match search is attempted only N
+steps later.
+
+The lazy match evaluation is also subject to a runtime parameter. If
+the current match is long enough, deflate() reduces the search for a longer
+match, thus speeding up the whole process. If compression ratio is more
+important than speed, deflate() attempts a complete second search even if
+the first match is already long enough.
+
+The lazy match evaluation is not performed for the fastest compression
+modes (level parameter 1 to 3). For these fast modes, new strings
+are inserted in the hash table only when no match was found, or
+when the match is not too long. This degrades the compression ratio
+but saves time since there are both fewer insertions and fewer searches.
+
+
+2. Decompression algorithm (inflate)
+
+2.1 Introduction
+
+The real question is, given a Huffman tree, how to decode fast. The most
+important realization is that shorter codes are much more common than
+longer codes, so pay attention to decoding the short codes fast, and let
+the long codes take longer to decode.
+
+inflate() sets up a first level table that covers some number of bits of
+input less than the length of longest code. It gets that many bits from the
+stream, and looks it up in the table. The table will tell if the next
+code is that many bits or less and how many, and if it is, it will tell
+the value, else it will point to the next level table for which inflate()
+grabs more bits and tries to decode a longer code.
+
+How many bits to make the first lookup is a tradeoff between the time it
+takes to decode and the time it takes to build the table. If building the
+table took no time (and if you had infinite memory), then there would only
+be a first level table to cover all the way to the longest code. However,
+building the table ends up taking a lot longer for more bits since short
+codes are replicated many times in such a table. What inflate() does is
+simply to make the number of bits in the first table a variable, and set it
+for the maximum speed.
+
+inflate() sends new trees relatively often, so it is possibly set for a
+smaller first level table than an application that has only one tree for
+all the data. For inflate, which has 286 possible codes for the
+literal/length tree, the size of the first table is nine bits. Also the
+distance trees have 30 possible values, and the size of the first table is
+six bits. Note that for each of those cases, the table ended up one bit
+longer than the ``average'' code length, i.e. the code length of an
+approximately flat code which would be a little more than eight bits for
+286 symbols and a little less than five bits for 30 symbols. It would be
+interesting to see if optimizing the first level table for other
+applications gave values within a bit or two of the flat code size.
+
+
+2.2 More details on the inflate table lookup
+
+Ok, you want to know what this cleverly obfuscated inflate tree actually
+looks like. You are correct that it's not a Huffman tree. It is simply a
+lookup table for the first, let's say, nine bits of a Huffman symbol. The
+symbol could be as short as one bit or as long as 15 bits. If a particular
+symbol is shorter than nine bits, then that symbol's translation is duplicated
+in all those entries that start with that symbol's bits. For example, if the
+symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a
+symbol is nine bits long, it appears in the table once.
+
+If the symbol is longer than nine bits, then that entry in the table points
+to another similar table for the remaining bits. Again, there are duplicated
+entries as needed. The idea is that most of the time the symbol will be short
+and there will only be one table look up. (That's whole idea behind data
+compression in the first place.) For the less frequent long symbols, there
+will be two lookups. If you had a compression method with really long
+symbols, you could have as many levels of lookups as is efficient. For
+inflate, two is enough.
+
+So a table entry either points to another table (in which case nine bits in
+the above example are gobbled), or it contains the translation for the symbol
+and the number of bits to gobble. Then you start again with the next
+ungobbled bit.
+
+You may wonder: why not just have one lookup table for how ever many bits the
+longest symbol is? The reason is that if you do that, you end up spending
+more time filling in duplicate symbol entries than you do actually decoding.
+At least for deflate's output that generates new trees every several 10's of
+kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
+would take too long if you're only decoding several thousand symbols. At the
+other extreme, you could make a new table for every bit in the code. In fact,
+that's essentially a Huffman tree. But then you spend two much time
+traversing the tree while decoding, even for short symbols.
+
+So the number of bits for the first lookup table is a trade of the time to
+fill out the table vs. the time spent looking at the second level and above of
+the table.
+
+Here is an example, scaled down:
+
+The code being decoded, with 10 symbols, from 1 to 6 bits long:
+
+A: 0
+B: 10
+C: 1100
+D: 11010
+E: 11011
+F: 11100
+G: 11101
+H: 11110
+I: 111110
+J: 111111
+
+Let's make the first table three bits long (eight entries):
+
+000: A,1
+001: A,1
+010: A,1
+011: A,1
+100: B,2
+101: B,2
+110: -> table X (gobble 3 bits)
+111: -> table Y (gobble 3 bits)
+
+Each entry is what the bits decode to and how many bits that is, i.e. how
+many bits to gobble. Or the entry points to another table, with the number of
+bits to gobble implicit in the size of the table.
+
+Table X is two bits long since the longest code starting with 110 is five bits
+long:
+
+00: C,1
+01: C,1
+10: D,2
+11: E,2
+
+Table Y is three bits long since the longest code starting with 111 is six
+bits long:
+
+000: F,2
+001: F,2
+010: G,2
+011: G,2
+100: H,2
+101: H,2
+110: I,3
+111: J,3
+
+So what we have here are three tables with a total of 20 entries that had to
+be constructed. That's compared to 64 entries for a single table. Or
+compared to 16 entries for a Huffman tree (six two entry tables and one four
+entry table). Assuming that the code ideally represents the probability of
+the symbols, it takes on the average 1.25 lookups per symbol. That's compared
+to one lookup for the single table, or 1.66 lookups per symbol for the
+Huffman tree.
+
+There, I think that gives you a picture of what's going on. For inflate, the
+meaning of a particular symbol is often more than just a letter. It can be a
+byte (a "literal"), or it can be either a length or a distance which
+indicates a base value and a number of bits to fetch after the code that is
+added to the base value. Or it might be the special end-of-block code. The
+data structures created in inftrees.c try to encode all that information
+compactly in the tables.
+
+
+Jean-loup Gailly Mark Adler
+jloup@gzip.org madler@alumni.caltech.edu
+
+
+References:
+
+[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
+Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
+pp. 337-343.
+
+``DEFLATE Compressed Data Format Specification'' available in
+ftp://ds.internic.net/rfc/rfc1951.txt
diff --git a/osframework/source/ImageLib/zlib/compress.c b/osframework/source/ImageLib/zlib/compress.c
new file mode 100644
index 0000000..623a3d1
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/compress.c
@@ -0,0 +1,68 @@
+/* compress.c -- compress a memory buffer
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: compress.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "zlib.h"
+
+/* ===========================================================================
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+ int level;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+#ifdef MAXSEG_64K
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+#endif
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit(&stream, level);
+ if (err != Z_OK) return err;
+
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ deflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = deflateEnd(&stream);
+ return err;
+}
+
+/* ===========================================================================
+ */
+int ZEXPORT compress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
+}
diff --git a/osframework/source/ImageLib/zlib/configure b/osframework/source/ImageLib/zlib/configure
new file mode 100644
index 0000000..5cd618e
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/configure
@@ -0,0 +1,212 @@
+#!/bin/sh
+# configure script for zlib. This script is needed only if
+# you wish to build a shared library and your system supports them,
+# of if you need special compiler, flags or install directory.
+# Otherwise, you can just use directly "make test; make install"
+#
+# To create a shared library, use "configure --shared"; by default a static
+# library is created. If the primitive shared library support provided here
+# does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz
+#
+# To impose specific compiler or flags or install directory, use for example:
+# prefix=$HOME CC=cc CFLAGS="-O4" ./configure
+# or for csh/tcsh users:
+# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
+# LDSHARED is the command to be used to create a shared library
+
+# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
+# If you have problems, try without defining CC and CFLAGS before reporting
+# an error.
+
+LIBS=libz.a
+SHAREDLIB=libz.so
+VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
+AR=${AR-"ar rc"}
+RANLIB=${RANLIB-"ranlib"}
+prefix=${prefix-/usr/local}
+exec_prefix=${exec_prefix-'${prefix}'}
+libdir=${libdir-'${exec_prefix}/lib'}
+includedir=${includedir-'${prefix}/include'}
+shared_ext='.so'
+shared=0
+gcc=0
+old_cc="$CC"
+old_cflags="$CFLAGS"
+
+while test $# -ge 1
+do
+case "$1" in
+ -h* | --h*)
+ echo 'usage:'
+ echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]'
+ echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
+ exit 0;;
+ -p*=* | --p*=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
+ -e*=* | --e*=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
+ -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
+ -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;;
+ -p* | --p*) prefix="$2"; shift; shift;;
+ -e* | --e*) exec_prefix="$2"; shift; shift;;
+ -l* | --l*) libdir="$2"; shift; shift;;
+ -i* | --i*) includedir="$2"; shift; shift;;
+ -s* | --s*) shared=1; shift;;
+ esac
+done
+
+test=ztest$$
+cat > $test.c <<EOF
+extern int getchar();
+int hello() {return getchar();}
+EOF
+
+test -z "$CC" && echo Checking for gcc...
+cc=${CC-gcc}
+cflags=${CFLAGS-"-O3"}
+# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
+case "$cc" in
+ *gcc*) gcc=1;;
+esac
+
+if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
+ CC="$cc"
+ SFLAGS=${CFLAGS-"-fPIC -O3"}
+ CFLAGS="$cflags"
+ case `(uname -s || echo unknown) 2>/dev/null` in
+ Linux | linux) LDSHARED=${LDSHARED-"gcc -shared -Wl,-soname,libz.so.1"};;
+ *) LDSHARED=${LDSHARED-"gcc -shared"};;
+ esac
+else
+ # find system name and corresponding cc options
+ CC=${CC-cc}
+ case `(uname -sr || echo unknown) 2>/dev/null` in
+ HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
+ CFLAGS=${CFLAGS-"-O"}
+# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
+ LDSHARED=${LDSHARED-"ld -b"}
+ shared_ext='.sl'
+ SHAREDLIB='libz.sl';;
+ IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
+ CFLAGS=${CFLAGS-"-ansi -O2"}
+ LDSHARED=${LDSHARED-"cc -shared"};;
+ OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
+ CFLAGS=${CFLAGS-"-O -std1"}
+ LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,$SHAREDLIB -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
+ OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
+ CFLAGS=${CFLAGS-"-O -std1"}
+ LDSHARED=${LDSHARED-"cc -shared"};;
+ QNX*) SFLAGS=${CFLAGS-"-4 -O"}
+ CFLAGS=${CFLAGS-"-4 -O"}
+ LDSHARED=${LDSHARED-"cc"}
+ RANLIB=${RANLIB-"true"}
+ AR="cc -A";;
+ SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
+ CFLAGS=${CFLAGS-"-O3"}
+ LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
+ SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."}
+ CFLAGS=${CFLAGS-"-fast -xcg89"}
+ LDSHARED=${LDSHARED-"cc -G"};;
+ SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
+ CFLAGS=${CFLAGS-"-O2"}
+ LDSHARED=${LDSHARED-"ld"};;
+ UNIX_System_V\ 4.2.0)
+ SFLAGS=${CFLAGS-"-KPIC -O"}
+ CFLAGS=${CFLAGS-"-O"}
+ LDSHARED=${LDSHARED-"cc -G"};;
+ UNIX_SV\ 4.2MP)
+ SFLAGS=${CFLAGS-"-Kconform_pic -O"}
+ CFLAGS=${CFLAGS-"-O"}
+ LDSHARED=${LDSHARED-"cc -G"};;
+ # send working options for other systems to support@gzip.org
+ *) SFLAGS=${CFLAGS-"-O"}
+ CFLAGS=${CFLAGS-"-O"}
+ LDSHARED=${LDSHARED-"cc -shared"};;
+ esac
+fi
+
+if test $shared -eq 1; then
+ echo Checking for shared library support...
+ # we must test in two steps (cc then ld), required at least on SunOS 4.x
+ if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
+ test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
+ CFLAGS="$SFLAGS"
+ LIBS="$SHAREDLIB.$VER"
+ echo Building shared library $SHAREDLIB.$VER with $CC.
+ elif test -z "$old_cc" -a -z "$old_cflags"; then
+ echo No shared library suppport.
+ shared=0;
+ else
+ echo 'No shared library suppport; try without defining CC and CFLAGS'
+ shared=0;
+ fi
+fi
+if test $shared -eq 0; then
+ LDSHARED="$CC"
+ echo Building static library $LIBS version $VER with $CC.
+fi
+
+cat > $test.c <<EOF
+#include <unistd.h>
+int main() { return 0; }
+EOF
+if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
+ CFLAGS="$CFLAGS -DHAVE_UNISTD_H"
+ echo "Checking for unistd.h... Yes."
+else
+ echo "Checking for unistd.h... No."
+fi
+
+cat > $test.c <<EOF
+#include <errno.h>
+int main() { return 0; }
+EOF
+if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
+ echo "Checking for errno.h... Yes."
+else
+ echo "Checking for errno.h... No."
+ CFLAGS="$CFLAGS -DNO_ERRNO_H"
+fi
+
+cat > $test.c <<EOF
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+caddr_t hello() {
+ return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
+}
+EOF
+if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
+ CFLAGS="$CFLAGS -DUSE_MMAP"
+ echo Checking for mmap support... Yes.
+else
+ echo Checking for mmap support... No.
+fi
+
+CPP=${CPP-"$CC -E"}
+case $CFLAGS in
+ *ASMV*)
+ if test "`nm $test.o | grep _hello`" = ""; then
+ CPP="$CPP -DNO_UNDERLINE"
+ echo Checking for underline in external names... No.
+ else
+ echo Checking for underline in external names... Yes.
+ fi;;
+esac
+
+rm -f $test.[co] $test$shared_ext
+
+# udpate Makefile
+sed < Makefile.in "
+/^CC *=/s%=.*%=$CC%
+/^CFLAGS *=/s%=.*%=$CFLAGS%
+/^CPP *=/s%=.*%=$CPP%
+/^LDSHARED *=/s%=.*%=$LDSHARED%
+/^LIBS *=/s%=.*%=$LIBS%
+/^SHAREDLIB *=/s%=.*%=$SHAREDLIB%
+/^AR *=/s%=.*%=$AR%
+/^RANLIB *=/s%=.*%=$RANLIB%
+/^VER *=/s%=.*%=$VER%
+/^prefix *=/s%=.*%=$prefix%
+/^exec_prefix *=/s%=.*%=$exec_prefix%
+/^libdir *=/s%=.*%=$libdir%
+/^includedir *=/s%=.*%=$includedir%
+" > Makefile
diff --git a/osframework/source/ImageLib/zlib/crc32.c b/osframework/source/ImageLib/zlib/crc32.c
new file mode 100644
index 0000000..024bd8c
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/crc32.c
@@ -0,0 +1,162 @@
+/* crc32.c -- compute the CRC-32 of a data stream
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: crc32.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "zlib.h"
+
+#define local static
+
+#ifdef DYNAMIC_CRC_TABLE
+
+local int crc_table_empty = 1;
+local uLongf crc_table[256];
+local void make_crc_table OF((void));
+
+/*
+ Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+ Polynomials over GF(2) are represented in binary, one bit per coefficient,
+ with the lowest powers in the most significant bit. Then adding polynomials
+ is just exclusive-or, and multiplying a polynomial by x is a right shift by
+ one. If we call the above polynomial p, and represent a byte as the
+ polynomial q, also with the lowest power in the most significant bit (so the
+ byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
+ where a mod b means the remainder after dividing a by b.
+
+ This calculation is done using the shift-register method of multiplying and
+ taking the remainder. The register is initialized to zero, and for each
+ incoming bit, x^32 is added mod p to the register if the bit is a one (where
+ x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
+ x (which is shifting right by one and adding x^32 mod p if the bit shifted
+ out is a one). We start with the highest power (least significant bit) of
+ q and repeat for all eight bits of q.
+
+ The table is simply the CRC of all possible eight bit values. This is all
+ the information needed to generate CRC's on data a byte at a time for all
+ combinations of CRC register values and incoming bytes.
+*/
+local void make_crc_table()
+{
+ uLong c;
+ int n, k;
+ uLong poly; /* polynomial exclusive-or pattern */
+ /* terms of polynomial defining this crc (except x^32): */
+ static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+ /* make exclusive-or pattern from polynomial (0xedb88320L) */
+ poly = 0L;
+ for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
+ poly |= 1L << (31 - p[n]);
+
+ for (n = 0; n < 256; n++)
+ {
+ c = (uLong)n;
+ for (k = 0; k < 8; k++)
+ c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+ crc_table[n] = c;
+ }
+ crc_table_empty = 0;
+}
+#else
+/* ========================================================================
+ * Table of CRC-32's of all single-byte values (made by make_crc_table)
+ */
+local const uLongf crc_table[256] = {
+ 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
+ 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
+ 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
+ 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
+ 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
+ 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
+ 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
+ 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+ 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
+ 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
+ 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
+ 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
+ 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
+ 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
+ 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
+ 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+ 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
+ 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
+ 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
+ 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
+ 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
+ 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
+ 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
+ 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+ 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
+ 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
+ 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
+ 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
+ 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
+ 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
+ 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
+ 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+ 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
+ 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
+ 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
+ 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
+ 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
+ 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
+ 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
+ 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+ 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
+ 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
+ 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
+ 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
+ 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
+ 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
+ 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
+ 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+ 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
+ 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
+ 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
+ 0x2d02ef8dL
+};
+#endif
+
+/* =========================================================================
+ * This function can be used by asm versions of crc32()
+ */
+const uLongf * ZEXPORT get_crc_table()
+{
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty) make_crc_table();
+#endif
+ return (const uLongf *)crc_table;
+}
+
+/* ========================================================================= */
+#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
+#define DO2(buf) DO1(buf); DO1(buf);
+#define DO4(buf) DO2(buf); DO2(buf);
+#define DO8(buf) DO4(buf); DO4(buf);
+
+/* ========================================================================= */
+uLong ZEXPORT crc32(crc, buf, len)
+ uLong crc;
+ const Bytef *buf;
+ uInt len;
+{
+ if (buf == Z_NULL) return 0L;
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty)
+ make_crc_table();
+#endif
+ crc = crc ^ 0xffffffffL;
+ while (len >= 8)
+ {
+ DO8(buf);
+ len -= 8;
+ }
+ if (len) do {
+ DO1(buf);
+ } while (--len);
+ return crc ^ 0xffffffffL;
+}
diff --git a/osframework/source/ImageLib/zlib/deflate.c b/osframework/source/ImageLib/zlib/deflate.c
new file mode 100644
index 0000000..79ac4a5
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/deflate.c
@@ -0,0 +1,1350 @@
+/* deflate.c -- compress data using the deflation algorithm
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process depends on being able to identify portions
+ * of the input text which are identical to earlier input (within a
+ * sliding window trailing behind the input currently being processed).
+ *
+ * The most straightforward technique turns out to be the fastest for
+ * most input files: try all possible matches and select the longest.
+ * The key feature of this algorithm is that insertions into the string
+ * dictionary are very simple and thus fast, and deletions are avoided
+ * completely. Insertions are performed at each input character, whereas
+ * string matches are performed only when the previous match ends. So it
+ * is preferable to spend more time in matches to allow very fast string
+ * insertions and avoid deletions. The matching algorithm for small
+ * strings is inspired from that of Rabin & Karp. A brute force approach
+ * is used to find longer strings when a small match has been found.
+ * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
+ * (by Leonid Broukhis).
+ * A previous version of this file used a more sophisticated algorithm
+ * (by Fiala and Greene) which is guaranteed to run in linear amortized
+ * time, but has a larger average cost, uses more memory and is patented.
+ * However the F&G algorithm may be faster for some highly redundant
+ * files if the parameter max_chain_length (described below) is too large.
+ *
+ * ACKNOWLEDGEMENTS
+ *
+ * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
+ * I found it in 'freeze' written by Leonid Broukhis.
+ * Thanks to many people for bug reports and testing.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
+ * Available in ftp://ds.internic.net/rfc/rfc1951.txt
+ *
+ * A description of the Rabin and Karp algorithm is given in the book
+ * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
+ *
+ * Fiala,E.R., and Greene,D.H.
+ * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
+ *
+ */
+
+/* @(#) $Id: deflate.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "deflate.h"
+
+const char deflate_copyright[] =
+ " deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly ";
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/* ===========================================================================
+ * Function prototypes.
+ */
+typedef enum {
+ need_more, /* block not completed, need more input or more output */
+ block_done, /* block flush performed */
+ finish_started, /* finish started, need only more output at next deflate */
+ finish_done /* finish done, accept no more input or output */
+} block_state;
+
+typedef block_state (*compress_func) OF((deflate_state *s, int flush));
+/* Compression function. Returns the block state after the call. */
+
+local void fill_window OF((deflate_state *s));
+local block_state deflate_stored OF((deflate_state *s, int flush));
+local block_state deflate_fast OF((deflate_state *s, int flush));
+local block_state deflate_slow OF((deflate_state *s, int flush));
+local void lm_init OF((deflate_state *s));
+local void putShortMSB OF((deflate_state *s, uInt b));
+local void flush_pending OF((z_streamp strm));
+local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
+#ifdef ASMV
+ void match_init OF((void)); /* asm code initialization */
+ uInt longest_match OF((deflate_state *s, IPos cur_match));
+#else
+local uInt longest_match OF((deflate_state *s, IPos cur_match));
+#endif
+
+#ifdef DEBUG
+local void check_match OF((deflate_state *s, IPos start, IPos match,
+ int length));
+#endif
+
+/* ===========================================================================
+ * Local data
+ */
+
+#define NIL 0
+/* Tail of hash chains */
+
+#ifndef TOO_FAR
+# define TOO_FAR 4096
+#endif
+/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+/* Values for max_lazy_match, good_match and max_chain_length, depending on
+ * the desired pack level (0..9). The values given below have been tuned to
+ * exclude worst case performance for pathological files. Better values may be
+ * found for specific files.
+ */
+typedef struct config_s {
+ ush good_length; /* reduce lazy search above this match length */
+ ush max_lazy; /* do not perform lazy search above this match length */
+ ush nice_length; /* quit search above this match length */
+ ush max_chain;
+ compress_func func;
+} config;
+
+local const config configuration_table[10] = {
+/* good lazy nice chain */
+/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
+/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */
+/* 2 */ {4, 5, 16, 8, deflate_fast},
+/* 3 */ {4, 6, 32, 32, deflate_fast},
+
+/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
+/* 5 */ {8, 16, 32, 32, deflate_slow},
+/* 6 */ {8, 16, 128, 128, deflate_slow},
+/* 7 */ {8, 32, 128, 256, deflate_slow},
+/* 8 */ {32, 128, 258, 1024, deflate_slow},
+/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
+
+/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
+ * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
+ * meaning.
+ */
+
+#define EQUAL 0
+/* result of memcmp for equal strings */
+
+struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
+
+/* ===========================================================================
+ * Update a hash value with the given input byte
+ * IN assertion: all calls to to UPDATE_HASH are made with consecutive
+ * input characters, so that a running hash key can be computed from the
+ * previous key instead of complete recalculation each time.
+ */
+#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
+
+
+/* ===========================================================================
+ * Insert string str in the dictionary and set match_head to the previous head
+ * of the hash chain (the most recent string with same hash key). Return
+ * the previous length of the hash chain.
+ * If this file is compiled with -DFASTEST, the compression level is forced
+ * to 1, and no hash chains are maintained.
+ * IN assertion: all calls to to INSERT_STRING are made with consecutive
+ * input characters and the first MIN_MATCH bytes of str are valid
+ * (except for the last MIN_MATCH-1 bytes of the input file).
+ */
+#ifdef FASTEST
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ match_head = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#else
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#endif
+
+/* ===========================================================================
+ * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
+ * prev[] will be initialized on the fly.
+ */
+#define CLEAR_HASH(s) \
+ s->head[s->hash_size-1] = NIL; \
+ zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+
+/* ========================================================================= */
+int ZEXPORT deflateInit_(strm, level, version, stream_size)
+ z_streamp strm;
+ int level;
+ const char *version;
+ int stream_size;
+{
+ return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
+ Z_DEFAULT_STRATEGY, version, stream_size);
+ /* To do: ignore strm->next_in if we use it as window */
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+ version, stream_size)
+ z_streamp strm;
+ int level;
+ int method;
+ int windowBits;
+ int memLevel;
+ int strategy;
+ const char *version;
+ int stream_size;
+{
+ deflate_state *s;
+ int noheader = 0;
+ static const char* my_version = ZLIB_VERSION;
+
+ ushf *overlay;
+ /* We overlay pending_buf and d_buf+l_buf. This works since the average
+ * output size for (length,distance) codes is <= 24 bits.
+ */
+
+ if (version == Z_NULL || version[0] != my_version[0] ||
+ stream_size != sizeof(z_stream)) {
+ return Z_VERSION_ERROR;
+ }
+ if (strm == Z_NULL) return Z_STREAM_ERROR;
+
+ strm->msg = Z_NULL;
+ if (strm->zalloc == Z_NULL) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == Z_NULL) strm->zfree = zcfree;
+
+ if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#ifdef FASTEST
+ level = 1;
+#endif
+
+ if (windowBits < 0) { /* undocumented feature: suppress zlib header */
+ noheader = 1;
+ windowBits = -windowBits;
+ }
+ if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
+ windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+ strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
+ return Z_STREAM_ERROR;
+ }
+ s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
+ if (s == Z_NULL) return Z_MEM_ERROR;
+ strm->state = (struct internal_state FAR *)s;
+ s->strm = strm;
+
+ s->noheader = noheader;
+ s->w_bits = windowBits;
+ s->w_size = 1 << s->w_bits;
+ s->w_mask = s->w_size - 1;
+
+ s->hash_bits = memLevel + 7;
+ s->hash_size = 1 << s->hash_bits;
+ s->hash_mask = s->hash_size - 1;
+ s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+
+ s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
+ s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
+ s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
+
+ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
+
+ overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+ s->pending_buf = (uchf *) overlay;
+ s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
+
+ if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
+ s->pending_buf == Z_NULL) {
+ strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
+ deflateEnd (strm);
+ return Z_MEM_ERROR;
+ }
+ s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+ s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+
+ s->level = level;
+ s->strategy = strategy;
+ s->method = (Byte)method;
+
+ return deflateReset(strm);
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
+ z_streamp strm;
+ const Bytef *dictionary;
+ uInt dictLength;
+{
+ deflate_state *s;
+ uInt length = dictLength;
+ uInt n;
+ IPos hash_head = 0;
+
+ if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
+ strm->state->status != INIT_STATE) return Z_STREAM_ERROR;
+
+ s = strm->state;
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
+
+ if (length < MIN_MATCH) return Z_OK;
+ if (length > MAX_DIST(s)) {
+ length = MAX_DIST(s);
+#ifndef USE_DICT_HEAD
+ dictionary += dictLength - length; /* use the tail of the dictionary */
+#endif
+ }
+ zmemcpy(s->window, dictionary, length);
+ s->strstart = length;
+ s->block_start = (long)length;
+
+ /* Insert all strings in the hash table (except for the last two bytes).
+ * s->lookahead stays null, so s->ins_h will be recomputed at the next
+ * call of fill_window.
+ */
+ s->ins_h = s->window[0];
+ UPDATE_HASH(s, s->ins_h, s->window[1]);
+ for (n = 0; n <= length - MIN_MATCH; n++) {
+ INSERT_STRING(s, n, hash_head);
+ }
+ if (hash_head) hash_head = 0; /* to make compiler happy */
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+ z_streamp strm;
+{
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
+
+ strm->total_in = strm->total_out = 0;
+ strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
+ strm->data_type = Z_UNKNOWN;
+
+ s = (deflate_state *)strm->state;
+ s->pending = 0;
+ s->pending_out = s->pending_buf;
+
+ if (s->noheader < 0) {
+ s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
+ }
+ s->status = s->noheader ? BUSY_STATE : INIT_STATE;
+ strm->adler = 1;
+ s->last_flush = Z_NO_FLUSH;
+
+ _tr_init(s);
+ lm_init(s);
+
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateParams(strm, level, strategy)
+ z_streamp strm;
+ int level;
+ int strategy;
+{
+ deflate_state *s;
+ compress_func func;
+ int err = Z_OK;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ s = strm->state;
+
+ if (level == Z_DEFAULT_COMPRESSION) {
+ level = 6;
+ }
+ if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
+ return Z_STREAM_ERROR;
+ }
+ func = configuration_table[s->level].func;
+
+ if (func != configuration_table[level].func && strm->total_in != 0) {
+ /* Flush the last buffer: */
+ err = deflate(strm, Z_PARTIAL_FLUSH);
+ }
+ if (s->level != level) {
+ s->level = level;
+ s->max_lazy_match = configuration_table[level].max_lazy;
+ s->good_match = configuration_table[level].good_length;
+ s->nice_match = configuration_table[level].nice_length;
+ s->max_chain_length = configuration_table[level].max_chain;
+ }
+ s->strategy = strategy;
+ return err;
+}
+
+/* =========================================================================
+ * Put a short in the pending buffer. The 16-bit value is put in MSB order.
+ * IN assertion: the stream state is correct and there is enough room in
+ * pending_buf.
+ */
+local void putShortMSB (s, b)
+ deflate_state *s;
+ uInt b;
+{
+ put_byte(s, (Byte)(b >> 8));
+ put_byte(s, (Byte)(b & 0xff));
+}
+
+/* =========================================================================
+ * Flush as much pending output as possible. All deflate() output goes
+ * through this function so some applications may wish to modify it
+ * to avoid allocating a large strm->next_out buffer and copying into it.
+ * (See also read_buf()).
+ */
+local void flush_pending(strm)
+ z_streamp strm;
+{
+ unsigned len = strm->state->pending;
+
+ if (len > strm->avail_out) len = strm->avail_out;
+ if (len == 0) return;
+
+ zmemcpy(strm->next_out, strm->state->pending_out, len);
+ strm->next_out += len;
+ strm->state->pending_out += len;
+ strm->total_out += len;
+ strm->avail_out -= len;
+ strm->state->pending -= len;
+ if (strm->state->pending == 0) {
+ strm->state->pending_out = strm->state->pending_buf;
+ }
+}
+
+/* ========================================================================= */
+int ZEXPORT deflate (strm, flush)
+ z_streamp strm;
+ int flush;
+{
+ int old_flush; /* value of flush param for previous deflate call */
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ flush > Z_FINISH || flush < 0) {
+ return Z_STREAM_ERROR;
+ }
+ s = strm->state;
+
+ if (strm->next_out == Z_NULL ||
+ (strm->next_in == Z_NULL && strm->avail_in != 0) ||
+ (s->status == FINISH_STATE && flush != Z_FINISH)) {
+ ERR_RETURN(strm, Z_STREAM_ERROR);
+ }
+ if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
+
+ s->strm = strm; /* just in case */
+ old_flush = s->last_flush;
+ s->last_flush = flush;
+
+ /* Write the zlib header */
+ if (s->status == INIT_STATE) {
+
+ uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+ uInt level_flags = (s->level-1) >> 1;
+
+ if (level_flags > 3) level_flags = 3;
+ header |= (level_flags << 6);
+ if (s->strstart != 0) header |= PRESET_DICT;
+ header += 31 - (header % 31);
+
+ s->status = BUSY_STATE;
+ putShortMSB(s, header);
+
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = 1L;
+ }
+
+ /* Flush as much pending output as possible */
+ if (s->pending != 0) {
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ /* Since avail_out is 0, deflate will be called again with
+ * more output space, but possibly with both pending and
+ * avail_in equal to zero. There won't be anything to do,
+ * but this is not an error situation so make sure we
+ * return OK instead of BUF_ERROR at next call of deflate:
+ */
+ s->last_flush = -1;
+ return Z_OK;
+ }
+
+ /* Make sure there is something to do and avoid duplicate consecutive
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
+ * returning Z_STREAM_END instead of Z_BUFF_ERROR.
+ */
+ } else if (strm->avail_in == 0 && flush <= old_flush &&
+ flush != Z_FINISH) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* User must not provide more input after the first FINISH: */
+ if (s->status == FINISH_STATE && strm->avail_in != 0) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* Start a new block or continue the current one.
+ */
+ if (strm->avail_in != 0 || s->lookahead != 0 ||
+ (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
+ block_state bstate;
+
+ bstate = (*(configuration_table[s->level].func))(s, flush);
+
+ if (bstate == finish_started || bstate == finish_done) {
+ s->status = FINISH_STATE;
+ }
+ if (bstate == need_more || bstate == finish_started) {
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
+ }
+ return Z_OK;
+ /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
+ * of deflate should use the same flush parameter to make sure
+ * that the flush is complete. So we don't have to output an
+ * empty block here, this will be done at next call. This also
+ * ensures that for a very small output buffer, we emit at most
+ * one empty block.
+ */
+ }
+ if (bstate == block_done) {
+ if (flush == Z_PARTIAL_FLUSH) {
+ _tr_align(s);
+ } else { /* FULL_FLUSH or SYNC_FLUSH */
+ _tr_stored_block(s, (char*)0, 0L, 0);
+ /* For a full flush, this empty block will be recognized
+ * as a special marker by inflate_sync().
+ */
+ if (flush == Z_FULL_FLUSH) {
+ CLEAR_HASH(s); /* forget history */
+ }
+ }
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+ return Z_OK;
+ }
+ }
+ }
+ Assert(strm->avail_out > 0, "bug2");
+
+ if (flush != Z_FINISH) return Z_OK;
+ if (s->noheader) return Z_STREAM_END;
+
+ /* Write the zlib trailer (adler32) */
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ flush_pending(strm);
+ /* If avail_out is zero, the application will call deflate again
+ * to flush the rest.
+ */
+ s->noheader = -1; /* write the trailer only once! */
+ return s->pending != 0 ? Z_OK : Z_STREAM_END;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateEnd (strm)
+ z_streamp strm;
+{
+ int status;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+
+ status = strm->state->status;
+ if (status != INIT_STATE && status != BUSY_STATE &&
+ status != FINISH_STATE) {
+ return Z_STREAM_ERROR;
+ }
+
+ /* Deallocate in reverse order of allocations: */
+ TRY_FREE(strm, strm->state->pending_buf);
+ TRY_FREE(strm, strm->state->head);
+ TRY_FREE(strm, strm->state->prev);
+ TRY_FREE(strm, strm->state->window);
+
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+
+ return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
+}
+
+/* =========================================================================
+ * Copy the source state to the destination state.
+ * To simplify the source, this is not supported for 16-bit MSDOS (which
+ * doesn't have enough memory anyway to duplicate compression states).
+ */
+int ZEXPORT deflateCopy (dest, source)
+ z_streamp dest;
+ z_streamp source;
+{
+#ifdef MAXSEG_64K
+ return Z_STREAM_ERROR;
+#else
+ deflate_state *ds;
+ deflate_state *ss;
+ ushf *overlay;
+
+
+ if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ return Z_STREAM_ERROR;
+ }
+
+ ss = source->state;
+
+ *dest = *source;
+
+ ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
+ if (ds == Z_NULL) return Z_MEM_ERROR;
+ dest->state = (struct internal_state FAR *) ds;
+ *ds = *ss;
+ ds->strm = dest;
+
+ ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
+ overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+ ds->pending_buf = (uchf *) overlay;
+
+ if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
+ ds->pending_buf == Z_NULL) {
+ deflateEnd (dest);
+ return Z_MEM_ERROR;
+ }
+ /* following zmemcpy do not work for 16-bit MSDOS */
+ zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
+ zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
+ zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+ zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
+
+ ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+ ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+ ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+
+ ds->l_desc.dyn_tree = ds->dyn_ltree;
+ ds->d_desc.dyn_tree = ds->dyn_dtree;
+ ds->bl_desc.dyn_tree = ds->bl_tree;
+
+ return Z_OK;
+#endif
+}
+
+/* ===========================================================================
+ * Read a new buffer from the current input stream, update the adler32
+ * and total number of bytes read. All deflate() input goes through
+ * this function so some applications may wish to modify it to avoid
+ * allocating a large strm->next_in buffer and copying from it.
+ * (See also flush_pending()).
+ */
+local int read_buf(strm, buf, size)
+ z_streamp strm;
+ Bytef *buf;
+ unsigned size;
+{
+ unsigned len = strm->avail_in;
+
+ if (len > size) len = size;
+ if (len == 0) return 0;
+
+ strm->avail_in -= len;
+
+ if (!strm->state->noheader) {
+ strm->adler = adler32(strm->adler, strm->next_in, len);
+ }
+ zmemcpy(buf, strm->next_in, len);
+ strm->next_in += len;
+ strm->total_in += len;
+
+ return (int)len;
+}
+
+/* ===========================================================================
+ * Initialize the "longest match" routines for a new zlib stream
+ */
+local void lm_init (s)
+ deflate_state *s;
+{
+ s->window_size = (ulg)2L*s->w_size;
+
+ CLEAR_HASH(s);
+
+ /* Set the default configuration parameters:
+ */
+ s->max_lazy_match = configuration_table[s->level].max_lazy;
+ s->good_match = configuration_table[s->level].good_length;
+ s->nice_match = configuration_table[s->level].nice_length;
+ s->max_chain_length = configuration_table[s->level].max_chain;
+
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ s->ins_h = 0;
+#ifdef ASMV
+ match_init(); /* initialize the asm code */
+#endif
+}
+
+/* ===========================================================================
+ * Set match_start to the longest match starting at the given string and
+ * return its length. Matches shorter or equal to prev_length are discarded,
+ * in which case the result is equal to prev_length and match_start is
+ * garbage.
+ * IN assertions: cur_match is the head of the hash chain for the current
+ * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
+ * OUT assertion: the match length is not greater than s->lookahead.
+ */
+#ifndef ASMV
+/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
+ * match.S. The code will be functionally equivalent.
+ */
+#ifndef FASTEST
+local uInt longest_match(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ unsigned chain_length = s->max_chain_length;/* max hash chain length */
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ int best_len = s->prev_length; /* best match length so far */
+ int nice_match = s->nice_match; /* stop if match long enough */
+ IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
+ s->strstart - (IPos)MAX_DIST(s) : NIL;
+ /* Stop when cur_match becomes <= limit. To simplify the code,
+ * we prevent matches with the string of window index 0.
+ */
+ Posf *prev = s->prev;
+ uInt wmask = s->w_mask;
+
+#ifdef UNALIGNED_OK
+ /* Compare two bytes at a time. Note: this is not always beneficial.
+ * Try with and without -DUNALIGNED_OK to check.
+ */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
+ register ush scan_start = *(ushf*)scan;
+ register ush scan_end = *(ushf*)(scan+best_len-1);
+#else
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+ register Byte scan_end1 = scan[best_len-1];
+ register Byte scan_end = scan[best_len];
+#endif
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ /* Do not waste too much time if we already have a good match: */
+ if (s->prev_length >= s->good_match) {
+ chain_length >>= 2;
+ }
+ /* Do not look for matches beyond the end of the input. This is necessary
+ * to make deflate deterministic.
+ */
+ if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ do {
+ Assert(cur_match < s->strstart, "no future");
+ match = s->window + cur_match;
+
+ /* Skip to next match if the match length cannot increase
+ * or if the match length is less than 2:
+ */
+#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
+ /* This code assumes sizeof(unsigned short) == 2. Do not use
+ * UNALIGNED_OK if your compiler uses a different size.
+ */
+ if (*(ushf*)(match+best_len-1) != scan_end ||
+ *(ushf*)match != scan_start) continue;
+
+ /* It is not necessary to compare scan[2] and match[2] since they are
+ * always equal when the other bytes match, given that the hash keys
+ * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
+ * strstart+3, +5, ... up to strstart+257. We check for insufficient
+ * lookahead only every 4th comparison; the 128th check will be made
+ * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
+ * necessary to put more guard bytes at the end of the window, or
+ * to check more often for insufficient lookahead.
+ */
+ Assert(scan[2] == match[2], "scan[2]?");
+ scan++, match++;
+ do {
+ } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ scan < strend);
+ /* The funny "do {}" generates better code on most compilers */
+
+ /* Here, scan <= window+strstart+257 */
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+ if (*scan == *match) scan++;
+
+ len = (MAX_MATCH - 1) - (int)(strend-scan);
+ scan = strend - (MAX_MATCH-1);
+
+#else /* UNALIGNED_OK */
+
+ if (match[best_len] != scan_end ||
+ match[best_len-1] != scan_end1 ||
+ *match != *scan ||
+ *++match != scan[1]) continue;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match++;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+ scan = strend - MAX_MATCH;
+
+#endif /* UNALIGNED_OK */
+
+ if (len > best_len) {
+ s->match_start = cur_match;
+ best_len = len;
+ if (len >= nice_match) break;
+#ifdef UNALIGNED_OK
+ scan_end = *(ushf*)(scan+best_len-1);
+#else
+ scan_end1 = scan[best_len-1];
+ scan_end = scan[best_len];
+#endif
+ }
+ } while ((cur_match = prev[cur_match & wmask]) > limit
+ && --chain_length != 0);
+
+ if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
+ return s->lookahead;
+}
+
+#else /* FASTEST */
+/* ---------------------------------------------------------------------------
+ * Optimized version for level == 1 only
+ */
+local uInt longest_match(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ Assert(cur_match < s->strstart, "no future");
+
+ match = s->window + cur_match;
+
+ /* Return failure if the match length is less than 2:
+ */
+ if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match += 2;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+
+ if (len < MIN_MATCH) return MIN_MATCH - 1;
+
+ s->match_start = cur_match;
+ return len <= s->lookahead ? len : s->lookahead;
+}
+#endif /* FASTEST */
+#endif /* ASMV */
+
+#ifdef DEBUG
+/* ===========================================================================
+ * Check that the match at match_start is indeed a match.
+ */
+local void check_match(s, start, match, length)
+ deflate_state *s;
+ IPos start, match;
+ int length;
+{
+ /* check that the match is indeed a match */
+ if (zmemcmp(s->window + match,
+ s->window + start, length) != EQUAL) {
+ fprintf(stderr, " start %u, match %u, length %d\n",
+ start, match, length);
+ do {
+ fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
+ } while (--length != 0);
+ z_error("invalid match");
+ }
+ if (z_verbose > 1) {
+ fprintf(stderr,"\\[%d,%d]", start-match, length);
+ do { putc(s->window[start++], stderr); } while (--length != 0);
+ }
+}
+#else
+# define check_match(s, start, match, length)
+#endif
+
+/* ===========================================================================
+ * Fill the window when the lookahead becomes insufficient.
+ * Updates strstart and lookahead.
+ *
+ * IN assertion: lookahead < MIN_LOOKAHEAD
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
+ * At least one byte has been read, or avail_in == 0; reads are
+ * performed for at least two bytes (required for the zip translate_eol
+ * option -- not supported here).
+ */
+local void fill_window(s)
+ deflate_state *s;
+{
+ register unsigned n, m;
+ register Posf *p;
+ unsigned more; /* Amount of free space at the end of the window. */
+ uInt wsize = s->w_size;
+
+ do {
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
+
+ /* Deal with !@#$% 64K limit: */
+ if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+ more = wsize;
+
+ } else if (more == (unsigned)(-1)) {
+ /* Very unlikely, but possible on 16 bit machine if strstart == 0
+ * and lookahead == 1 (input done one byte at time)
+ */
+ more--;
+
+ /* If the window is almost full and there is insufficient lookahead,
+ * move the upper half to the lower one to make room in the upper half.
+ */
+ } else if (s->strstart >= wsize+MAX_DIST(s)) {
+
+ zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
+ s->match_start -= wsize;
+ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
+ s->block_start -= (long) wsize;
+
+ /* Slide the hash table (could be avoided with 32 bit values
+ at the expense of memory usage). We slide even when level == 0
+ to keep the hash table consistent if we switch back to level > 0
+ later. (Using level 0 permanently is not an optimal usage of
+ zlib, so we don't care about this pathological case.)
+ */
+ n = s->hash_size;
+ p = &s->head[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ } while (--n);
+
+ n = wsize;
+#ifndef FASTEST
+ p = &s->prev[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
+#endif
+ more += wsize;
+ }
+ if (s->strm->avail_in == 0) return;
+
+ /* If there was no sliding:
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
+ * more == window_size - lookahead - strstart
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
+ * => more >= window_size - 2*WSIZE + 2
+ * In the BIG_MEM or MMAP case (not yet supported),
+ * window_size == input_size + MIN_LOOKAHEAD &&
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
+ */
+ Assert(more >= 2, "more < 2");
+
+ n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
+ s->lookahead += n;
+
+ /* Initialize the hash value now that we have some input: */
+ if (s->lookahead >= MIN_MATCH) {
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ }
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+ * but this is not important since only literal bytes will be emitted.
+ */
+
+ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
+}
+
+/* ===========================================================================
+ * Flush the current block, with given end-of-file flag.
+ * IN assertion: strstart is set to the end of the current match.
+ */
+#define FLUSH_BLOCK_ONLY(s, eof) { \
+ _tr_flush_block(s, (s->block_start >= 0L ? \
+ (charf *)&s->window[(unsigned)s->block_start] : \
+ (charf *)Z_NULL), \
+ (ulg)((long)s->strstart - s->block_start), \
+ (eof)); \
+ s->block_start = s->strstart; \
+ flush_pending(s->strm); \
+ Tracev((stderr,"[FLUSH]")); \
+}
+
+/* Same but force premature exit if necessary. */
+#define FLUSH_BLOCK(s, eof) { \
+ FLUSH_BLOCK_ONLY(s, eof); \
+ if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
+}
+
+/* ===========================================================================
+ * Copy without compression as much as possible from the input stream, return
+ * the current block state.
+ * This function does not insert new strings in the dictionary since
+ * uncompressible data is probably not useful. This function is used
+ * only for the level=0 compression option.
+ * NOTE: this function should be optimized to avoid extra copying from
+ * window to pending_buf.
+ */
+local block_state deflate_stored(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
+ * to pending_buf_size, and each stored block has a 5 byte header:
+ */
+ ulg max_block_size = 0xffff;
+ ulg max_start;
+
+ if (max_block_size > s->pending_buf_size - 5) {
+ max_block_size = s->pending_buf_size - 5;
+ }
+
+ /* Copy as much as possible from input to output: */
+ for (;;) {
+ /* Fill the window as much as possible: */
+ if (s->lookahead <= 1) {
+
+ Assert(s->strstart < s->w_size+MAX_DIST(s) ||
+ s->block_start >= (long)s->w_size, "slide too late");
+
+ fill_window(s);
+ if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
+
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+ Assert(s->block_start >= 0L, "block gone");
+
+ s->strstart += s->lookahead;
+ s->lookahead = 0;
+
+ /* Emit a stored block if pending_buf will be full: */
+ max_start = s->block_start + max_block_size;
+ if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
+ /* strstart == 0 is possible when wraparound on 16-bit machine */
+ s->lookahead = (uInt)(s->strstart - max_start);
+ s->strstart = (uInt)max_start;
+ FLUSH_BLOCK(s, 0);
+ }
+ /* Flush if we may have to slide, otherwise block_start may become
+ * negative and the data will be gone:
+ */
+ if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
+ FLUSH_BLOCK(s, 0);
+ }
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+/* ===========================================================================
+ * Compress as much as possible from the input stream, return the current
+ * block state.
+ * This function does not perform lazy evaluation of matches and inserts
+ * new strings in the dictionary only for unmatched strings or for short
+ * matches. It is used only for the fast compression options.
+ */
+local block_state deflate_fast(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of the hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ * At this point we have always match_length < MIN_MATCH
+ */
+ if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+ if (s->strategy != Z_HUFFMAN_ONLY) {
+ s->match_length = longest_match (s, hash_head);
+ }
+ /* longest_match() sets match_start */
+ }
+ if (s->match_length >= MIN_MATCH) {
+ check_match(s, s->strstart, s->match_start, s->match_length);
+
+ _tr_tally_dist(s, s->strstart - s->match_start,
+ s->match_length - MIN_MATCH, bflush);
+
+ s->lookahead -= s->match_length;
+
+ /* Insert new strings in the hash table only if the match length
+ * is not too large. This saves time but degrades compression.
+ */
+#ifndef FASTEST
+ if (s->match_length <= s->max_insert_length &&
+ s->lookahead >= MIN_MATCH) {
+ s->match_length--; /* string at strstart already in hash table */
+ do {
+ s->strstart++;
+ INSERT_STRING(s, s->strstart, hash_head);
+ /* strstart never exceeds WSIZE-MAX_MATCH, so there are
+ * always MIN_MATCH bytes ahead.
+ */
+ } while (--s->match_length != 0);
+ s->strstart++;
+ } else
+#endif
+ {
+ s->strstart += s->match_length;
+ s->match_length = 0;
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+ * matter since it will be recomputed at next deflate call.
+ */
+ }
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+/* ===========================================================================
+ * Same as above, but achieves better compression. We use a lazy
+ * evaluation for matches: a match is finally adopted only if there is
+ * no better match at the next window position.
+ */
+local block_state deflate_slow(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ /* Process the input block. */
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ */
+ s->prev_length = s->match_length, s->prev_match = s->match_start;
+ s->match_length = MIN_MATCH-1;
+
+ if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
+ s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+ if (s->strategy != Z_HUFFMAN_ONLY) {
+ s->match_length = longest_match (s, hash_head);
+ }
+ /* longest_match() sets match_start */
+
+ if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
+ (s->match_length == MIN_MATCH &&
+ s->strstart - s->match_start > TOO_FAR))) {
+
+ /* If prev_match is also MIN_MATCH, match_start is garbage
+ * but we will ignore the current match anyway.
+ */
+ s->match_length = MIN_MATCH-1;
+ }
+ }
+ /* If there was a match at the previous step and the current
+ * match is not better, output the previous match:
+ */
+ if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+ uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
+ /* Do not insert strings in hash table beyond this. */
+
+ check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+
+ _tr_tally_dist(s, s->strstart -1 - s->prev_match,
+ s->prev_length - MIN_MATCH, bflush);
+
+ /* Insert in hash table all strings up to the end of the match.
+ * strstart-1 and strstart are already inserted. If there is not
+ * enough lookahead, the last two strings are not inserted in
+ * the hash table.
+ */
+ s->lookahead -= s->prev_length-1;
+ s->prev_length -= 2;
+ do {
+ if (++s->strstart <= max_insert) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+ } while (--s->prev_length != 0);
+ s->match_available = 0;
+ s->match_length = MIN_MATCH-1;
+ s->strstart++;
+
+ if (bflush) FLUSH_BLOCK(s, 0);
+
+ } else if (s->match_available) {
+ /* If there was no match at the previous position, output a
+ * single literal. If there was a match but the current match
+ * is longer, truncate the previous match to a single literal.
+ */
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ if (bflush) {
+ FLUSH_BLOCK_ONLY(s, 0);
+ }
+ s->strstart++;
+ s->lookahead--;
+ if (s->strm->avail_out == 0) return need_more;
+ } else {
+ /* There is no previous match to compare with, wait for
+ * the next step to decide.
+ */
+ s->match_available = 1;
+ s->strstart++;
+ s->lookahead--;
+ }
+ }
+ Assert (flush != Z_NO_FLUSH, "no flush?");
+ if (s->match_available) {
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ s->match_available = 0;
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
diff --git a/osframework/source/ImageLib/zlib/deflate.h b/osframework/source/ImageLib/zlib/deflate.h
new file mode 100644
index 0000000..d29bfb7
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/deflate.h
@@ -0,0 +1,318 @@
+/* deflate.h -- internal compression state
+ * Copyright (C) 1995-1998 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* @(#) $Id: deflate.h,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#ifndef _DEFLATE_H
+#define _DEFLATE_H
+
+#include "zutil.h"
+
+/* ===========================================================================
+ * Internal compression state.
+ */
+
+#define LENGTH_CODES 29
+/* number of length codes, not counting the special END_BLOCK code */
+
+#define LITERALS 256
+/* number of literal bytes 0..255 */
+
+#define L_CODES (LITERALS+1+LENGTH_CODES)
+/* number of Literal or Length codes, including the END_BLOCK code */
+
+#define D_CODES 30
+/* number of distance codes */
+
+#define BL_CODES 19
+/* number of codes used to transfer the bit lengths */
+
+#define HEAP_SIZE (2*L_CODES+1)
+/* maximum heap size */
+
+#define MAX_BITS 15
+/* All codes must not exceed MAX_BITS bits */
+
+#define INIT_STATE 42
+#define BUSY_STATE 113
+#define FINISH_STATE 666
+/* Stream status */
+
+
+/* Data structure describing a single value and its code string. */
+typedef struct ct_data_s {
+ union {
+ ush freq; /* frequency count */
+ ush code; /* bit string */
+ } fc;
+ union {
+ ush dad; /* father node in Huffman tree */
+ ush len; /* length of bit string */
+ } dl;
+} FAR ct_data;
+
+#define Freq fc.freq
+#define Code fc.code
+#define Dad dl.dad
+#define Len dl.len
+
+typedef struct static_tree_desc_s static_tree_desc;
+
+typedef struct tree_desc_s {
+ ct_data *dyn_tree; /* the dynamic tree */
+ int max_code; /* largest code with non zero frequency */
+ static_tree_desc *stat_desc; /* the corresponding static tree */
+} FAR tree_desc;
+
+typedef ush Pos;
+typedef Pos FAR Posf;
+typedef unsigned IPos;
+
+/* A Pos is an index in the character window. We use short instead of int to
+ * save space in the various tables. IPos is used only for parameter passing.
+ */
+
+typedef struct internal_state {
+ z_streamp strm; /* pointer back to this zlib stream */
+ int status; /* as the name implies */
+ Bytef *pending_buf; /* output still pending */
+ ulg pending_buf_size; /* size of pending_buf */
+ Bytef *pending_out; /* next pending byte to output to the stream */
+ int pending; /* nb of bytes in the pending buffer */
+ int noheader; /* suppress zlib header and adler32 */
+ Byte data_type; /* UNKNOWN, BINARY or ASCII */
+ Byte method; /* STORED (for zip only) or DEFLATED */
+ int last_flush; /* value of flush param for previous deflate call */
+
+ /* used by deflate.c: */
+
+ uInt w_size; /* LZ77 window size (32K by default) */
+ uInt w_bits; /* log2(w_size) (8..16) */
+ uInt w_mask; /* w_size - 1 */
+
+ Bytef *window;
+ /* Sliding window. Input bytes are read into the second half of the window,
+ * and move to the first half later to keep a dictionary of at least wSize
+ * bytes. With this organization, matches are limited to a distance of
+ * wSize-MAX_MATCH bytes, but this ensures that IO is always
+ * performed with a length multiple of the block size. Also, it limits
+ * the window size to 64K, which is quite useful on MSDOS.
+ * To do: use the user input buffer as sliding window.
+ */
+
+ ulg window_size;
+ /* Actual size of window: 2*wSize, except when the user input buffer
+ * is directly used as sliding window.
+ */
+
+ Posf *prev;
+ /* Link to older string with same hash index. To limit the size of this
+ * array to 64K, this link is maintained only for the last 32K strings.
+ * An index in this array is thus a window index modulo 32K.
+ */
+
+ Posf *head; /* Heads of the hash chains or NIL. */
+
+ uInt ins_h; /* hash index of string to be inserted */
+ uInt hash_size; /* number of elements in hash table */
+ uInt hash_bits; /* log2(hash_size) */
+ uInt hash_mask; /* hash_size-1 */
+
+ uInt hash_shift;
+ /* Number of bits by which ins_h must be shifted at each input
+ * step. It must be such that after MIN_MATCH steps, the oldest
+ * byte no longer takes part in the hash key, that is:
+ * hash_shift * MIN_MATCH >= hash_bits
+ */
+
+ long block_start;
+ /* Window position at the beginning of the current output block. Gets
+ * negative when the window is moved backwards.
+ */
+
+ uInt match_length; /* length of best match */
+ IPos prev_match; /* previous match */
+ int match_available; /* set if previous match exists */
+ uInt strstart; /* start of string to insert */
+ uInt match_start; /* start of matching string */
+ uInt lookahead; /* number of valid bytes ahead in window */
+
+ uInt prev_length;
+ /* Length of the best match at previous step. Matches not greater than this
+ * are discarded. This is used in the lazy match evaluation.
+ */
+
+ uInt max_chain_length;
+ /* To speed up deflation, hash chains are never searched beyond this
+ * length. A higher limit improves compression ratio but degrades the
+ * speed.
+ */
+
+ uInt max_lazy_match;
+ /* Attempt to find a better match only when the current match is strictly
+ * smaller than this value. This mechanism is used only for compression
+ * levels >= 4.
+ */
+# define max_insert_length max_lazy_match
+ /* Insert new strings in the hash table only if the match length is not
+ * greater than this length. This saves time but degrades compression.
+ * max_insert_length is used only for compression levels <= 3.
+ */
+
+ int level; /* compression level (1..9) */
+ int strategy; /* favor or force Huffman coding*/
+
+ uInt good_match;
+ /* Use a faster search when the previous match is longer than this */
+
+ int nice_match; /* Stop searching when current match exceeds this */
+
+ /* used by trees.c: */
+ /* Didn't use ct_data typedef below to supress compiler warning */
+ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
+ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
+ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
+
+ struct tree_desc_s l_desc; /* desc. for literal tree */
+ struct tree_desc_s d_desc; /* desc. for distance tree */
+ struct tree_desc_s bl_desc; /* desc. for bit length tree */
+
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
+ int heap_len; /* number of elements in the heap */
+ int heap_max; /* element of largest frequency */
+ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
+ * The same heap array is used to build all trees.
+ */
+
+ uch depth[2*L_CODES+1];
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
+ */
+
+ uchf *l_buf; /* buffer for literals or lengths */
+
+ uInt lit_bufsize;
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
+ * limiting lit_bufsize to 64K:
+ * - frequencies can be kept in 16 bit counters
+ * - if compression is not successful for the first block, all input
+ * data is still in the window so we can still emit a stored block even
+ * when input comes from standard input. (This can also be done for
+ * all blocks if lit_bufsize is not greater than 32K.)
+ * - if compression is not successful for a file smaller than 64K, we can
+ * even emit a stored file instead of a stored block (saving 5 bytes).
+ * This is applicable only for zip (not gzip or zlib).
+ * - creating new Huffman trees less frequently may not provide fast
+ * adaptation to changes in the input data statistics. (Take for
+ * example a binary file with poorly compressible code followed by
+ * a highly compressible string table.) Smaller buffer sizes give
+ * fast adaptation but have of course the overhead of transmitting
+ * trees more frequently.
+ * - I can't count above 4
+ */
+
+ uInt last_lit; /* running index in l_buf */
+
+ ushf *d_buf;
+ /* Buffer for distances. To simplify the code, d_buf and l_buf have
+ * the same number of elements. To use different lengths, an extra flag
+ * array would be necessary.
+ */
+
+ ulg opt_len; /* bit length of current block with optimal trees */
+ ulg static_len; /* bit length of current block with static trees */
+ uInt matches; /* number of string matches in current block */
+ int last_eob_len; /* bit length of EOB code for last block */
+
+#ifdef DEBUG
+ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
+ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
+#endif
+
+ ush bi_buf;
+ /* Output buffer. bits are inserted starting at the bottom (least
+ * significant bits).
+ */
+ int bi_valid;
+ /* Number of valid bits in bi_buf. All bits above the last valid bit
+ * are always zero.
+ */
+
+} FAR deflate_state;
+
+/* Output a byte on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
+/* In order to simplify the code, particularly on 16 bit machines, match
+ * distances are limited to MAX_DIST instead of WSIZE.
+ */
+
+ /* in trees.c */
+void _tr_init OF((deflate_state *s));
+int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
+void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+void _tr_align OF((deflate_state *s));
+void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+
+#define d_code(dist) \
+ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
+/* Mapping from a distance to a distance code. dist is the distance - 1 and
+ * must not have side effects. _dist_code[256] and _dist_code[257] are never
+ * used.
+ */
+
+#ifndef DEBUG
+/* Inline versions of _tr_tally for speed: */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+ extern uch _length_code[];
+ extern uch _dist_code[];
+#else
+ extern const uch _length_code[];
+ extern const uch _dist_code[];
+#endif
+
+# define _tr_tally_lit(s, c, flush) \
+ { uch cc = (c); \
+ s->d_buf[s->last_lit] = 0; \
+ s->l_buf[s->last_lit++] = cc; \
+ s->dyn_ltree[cc].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+# define _tr_tally_dist(s, distance, length, flush) \
+ { uch len = (length); \
+ ush dist = (distance); \
+ s->d_buf[s->last_lit] = dist; \
+ s->l_buf[s->last_lit++] = len; \
+ dist--; \
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
+ s->dyn_dtree[d_code(dist)].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+#else
+# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
+# define _tr_tally_dist(s, distance, length, flush) \
+ flush = _tr_tally(s, distance, length)
+#endif
+
+#endif
diff --git a/osframework/source/ImageLib/zlib/descrip.mms b/osframework/source/ImageLib/zlib/descrip.mms
new file mode 100644
index 0000000..d06e0c7
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/descrip.mms
@@ -0,0 +1,48 @@
+# descrip.mms: MMS description file for building zlib on VMS
+# written by Martin P.J. Zinser <m.zinser@gsi.de>
+
+cc_defs =
+c_deb =
+
+.ifdef __DECC__
+pref = /prefix=all
+.endif
+
+OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\
+ deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\
+ inftrees.obj, infcodes.obj, infutil.obj, inffast.obj
+
+CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
+
+all : example.exe minigzip.exe
+ @ write sys$output " Example applications available"
+libz.olb : libz.olb($(OBJS))
+ @ write sys$output " libz available"
+
+example.exe : example.obj libz.olb
+ link example,libz.olb/lib
+
+minigzip.exe : minigzip.obj libz.olb
+ link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib
+
+clean :
+ delete *.obj;*,libz.olb;*
+
+
+# Other dependencies.
+adler32.obj : zutil.h zlib.h zconf.h
+compress.obj : zlib.h zconf.h
+crc32.obj : zutil.h zlib.h zconf.h
+deflate.obj : deflate.h zutil.h zlib.h zconf.h
+example.obj : zlib.h zconf.h
+gzio.obj : zutil.h zlib.h zconf.h
+infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
+infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
+inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
+inflate.obj : zutil.h zlib.h zconf.h infblock.h
+inftrees.obj : zutil.h zlib.h zconf.h inftrees.h
+infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h
+minigzip.obj : zlib.h zconf.h
+trees.obj : deflate.h zutil.h zlib.h zconf.h
+uncompr.obj : zlib.h zconf.h
+zutil.obj : zutil.h zlib.h zconf.h
diff --git a/osframework/source/ImageLib/zlib/example.c b/osframework/source/ImageLib/zlib/example.c
new file mode 100644
index 0000000..b2c0549
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/example.c
@@ -0,0 +1,556 @@
+/* example.c -- usage example of the zlib compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: example.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include <stdio.h>
+#include "zlib.h"
+
+#ifdef STDC
+# include <string.h>
+# include <stdlib.h>
+#else
+ extern void exit OF((int));
+#endif
+
+#if defined(VMS) || defined(RISCOS)
+# define TESTFILE "foo-gz"
+#else
+# define TESTFILE "foo.gz"
+#endif
+
+#define CHECK_ERR(err, msg) { \
+ if (err != Z_OK) { \
+ fprintf(stderr, "%s error: %d\n", msg, err); \
+ exit(1); \
+ } \
+}
+
+const char hello[] = "hello, hello!";
+/* "hello world" would be more standard, but the repeated "hello"
+ * stresses the compression code better, sorry...
+ */
+
+const char dictionary[] = "hello";
+uLong dictId; /* Adler32 value of the dictionary */
+
+void test_compress OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_gzio OF((const char *out, const char *in,
+ Byte *uncompr, int uncomprLen));
+void test_deflate OF((Byte *compr, uLong comprLen));
+void test_inflate OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_large_deflate OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_large_inflate OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_flush OF((Byte *compr, uLong *comprLen));
+void test_sync OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_dict_deflate OF((Byte *compr, uLong comprLen));
+void test_dict_inflate OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+int main OF((int argc, char *argv[]));
+
+/* ===========================================================================
+ * Test compress() and uncompress()
+ */
+void test_compress(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ int err;
+ uLong len = strlen(hello)+1;
+
+ err = compress(compr, &comprLen, (const Bytef*)hello, len);
+ CHECK_ERR(err, "compress");
+
+ strcpy((char*)uncompr, "garbage");
+
+ err = uncompress(uncompr, &uncomprLen, compr, comprLen);
+ CHECK_ERR(err, "uncompress");
+
+ if (strcmp((char*)uncompr, hello)) {
+ fprintf(stderr, "bad uncompress\n");
+ exit(1);
+ } else {
+ printf("uncompress(): %s\n", (char *)uncompr);
+ }
+}
+
+/* ===========================================================================
+ * Test read/write of .gz files
+ */
+void test_gzio(out, in, uncompr, uncomprLen)
+ const char *out; /* compressed output file */
+ const char *in; /* compressed input file */
+ Byte *uncompr;
+ int uncomprLen;
+{
+ int err;
+ int len = strlen(hello)+1;
+ gzFile file;
+ z_off_t pos;
+
+ file = gzopen(out, "wb");
+ if (file == NULL) {
+ fprintf(stderr, "gzopen error\n");
+ exit(1);
+ }
+ gzputc(file, 'h');
+ if (gzputs(file, "ello") != 4) {
+ fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
+ exit(1);
+ }
+ if (gzprintf(file, ", %s!", "hello") != 8) {
+ fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
+ exit(1);
+ }
+ gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
+ gzclose(file);
+
+ file = gzopen(in, "rb");
+ if (file == NULL) {
+ fprintf(stderr, "gzopen error\n");
+ }
+ strcpy((char*)uncompr, "garbage");
+
+ uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
+ if (uncomprLen != len) {
+ fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
+ exit(1);
+ }
+ if (strcmp((char*)uncompr, hello)) {
+ fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
+ exit(1);
+ } else {
+ printf("gzread(): %s\n", (char *)uncompr);
+ }
+
+ pos = gzseek(file, -8L, SEEK_CUR);
+ if (pos != 6 || gztell(file) != pos) {
+ fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
+ (long)pos, (long)gztell(file));
+ exit(1);
+ }
+
+ if (gzgetc(file) != ' ') {
+ fprintf(stderr, "gzgetc error\n");
+ exit(1);
+ }
+
+ gzgets(file, (char*)uncompr, uncomprLen);
+ uncomprLen = strlen((char*)uncompr);
+ if (uncomprLen != 6) { /* "hello!" */
+ fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
+ exit(1);
+ }
+ if (strcmp((char*)uncompr, hello+7)) {
+ fprintf(stderr, "bad gzgets after gzseek\n");
+ exit(1);
+ } else {
+ printf("gzgets() after gzseek: %s\n", (char *)uncompr);
+ }
+
+ gzclose(file);
+}
+
+/* ===========================================================================
+ * Test deflate() with small buffers
+ */
+void test_deflate(compr, comprLen)
+ Byte *compr;
+ uLong comprLen;
+{
+ z_stream c_stream; /* compression stream */
+ int err;
+ int len = strlen(hello)+1;
+
+ c_stream.zalloc = (alloc_func)0;
+ c_stream.zfree = (free_func)0;
+ c_stream.opaque = (voidpf)0;
+
+ err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
+ CHECK_ERR(err, "deflateInit");
+
+ c_stream.next_in = (Bytef*)hello;
+ c_stream.next_out = compr;
+
+ while (c_stream.total_in != (uLong)len && c_stream.total_out < comprLen) {
+ c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
+ err = deflate(&c_stream, Z_NO_FLUSH);
+ CHECK_ERR(err, "deflate");
+ }
+ /* Finish the stream, still forcing small buffers: */
+ for (;;) {
+ c_stream.avail_out = 1;
+ err = deflate(&c_stream, Z_FINISH);
+ if (err == Z_STREAM_END) break;
+ CHECK_ERR(err, "deflate");
+ }
+
+ err = deflateEnd(&c_stream);
+ CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with small buffers
+ */
+void test_inflate(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ int err;
+ z_stream d_stream; /* decompression stream */
+
+ strcpy((char*)uncompr, "garbage");
+
+ d_stream.zalloc = (alloc_func)0;
+ d_stream.zfree = (free_func)0;
+ d_stream.opaque = (voidpf)0;
+
+ d_stream.next_in = compr;
+ d_stream.avail_in = 0;
+ d_stream.next_out = uncompr;
+
+ err = inflateInit(&d_stream);
+ CHECK_ERR(err, "inflateInit");
+
+ while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
+ d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
+ err = inflate(&d_stream, Z_NO_FLUSH);
+ if (err == Z_STREAM_END) break;
+ CHECK_ERR(err, "inflate");
+ }
+
+ err = inflateEnd(&d_stream);
+ CHECK_ERR(err, "inflateEnd");
+
+ if (strcmp((char*)uncompr, hello)) {
+ fprintf(stderr, "bad inflate\n");
+ exit(1);
+ } else {
+ printf("inflate(): %s\n", (char *)uncompr);
+ }
+}
+
+/* ===========================================================================
+ * Test deflate() with large buffers and dynamic change of compression level
+ */
+void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ z_stream c_stream; /* compression stream */
+ int err;
+
+ c_stream.zalloc = (alloc_func)0;
+ c_stream.zfree = (free_func)0;
+ c_stream.opaque = (voidpf)0;
+
+ err = deflateInit(&c_stream, Z_BEST_SPEED);
+ CHECK_ERR(err, "deflateInit");
+
+ c_stream.next_out = compr;
+ c_stream.avail_out = (uInt)comprLen;
+
+ /* At this point, uncompr is still mostly zeroes, so it should compress
+ * very well:
+ */
+ c_stream.next_in = uncompr;
+ c_stream.avail_in = (uInt)uncomprLen;
+ err = deflate(&c_stream, Z_NO_FLUSH);
+ CHECK_ERR(err, "deflate");
+ if (c_stream.avail_in != 0) {
+ fprintf(stderr, "deflate not greedy\n");
+ exit(1);
+ }
+
+ /* Feed in already compressed data and switch to no compression: */
+ deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
+ c_stream.next_in = compr;
+ c_stream.avail_in = (uInt)comprLen/2;
+ err = deflate(&c_stream, Z_NO_FLUSH);
+ CHECK_ERR(err, "deflate");
+
+ /* Switch back to compressing mode: */
+ deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
+ c_stream.next_in = uncompr;
+ c_stream.avail_in = (uInt)uncomprLen;
+ err = deflate(&c_stream, Z_NO_FLUSH);
+ CHECK_ERR(err, "deflate");
+
+ err = deflate(&c_stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ fprintf(stderr, "deflate should report Z_STREAM_END\n");
+ exit(1);
+ }
+ err = deflateEnd(&c_stream);
+ CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with large buffers
+ */
+void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ int err;
+ z_stream d_stream; /* decompression stream */
+
+ strcpy((char*)uncompr, "garbage");
+
+ d_stream.zalloc = (alloc_func)0;
+ d_stream.zfree = (free_func)0;
+ d_stream.opaque = (voidpf)0;
+
+ d_stream.next_in = compr;
+ d_stream.avail_in = (uInt)comprLen;
+
+ err = inflateInit(&d_stream);
+ CHECK_ERR(err, "inflateInit");
+
+ for (;;) {
+ d_stream.next_out = uncompr; /* discard the output */
+ d_stream.avail_out = (uInt)uncomprLen;
+ err = inflate(&d_stream, Z_NO_FLUSH);
+ if (err == Z_STREAM_END) break;
+ CHECK_ERR(err, "large inflate");
+ }
+
+ err = inflateEnd(&d_stream);
+ CHECK_ERR(err, "inflateEnd");
+
+ if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
+ fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
+ exit(1);
+ } else {
+ printf("large_inflate(): OK\n");
+ }
+}
+
+/* ===========================================================================
+ * Test deflate() with full flush
+ */
+void test_flush(compr, comprLen)
+ Byte *compr;
+ uLong *comprLen;
+{
+ z_stream c_stream; /* compression stream */
+ int err;
+ int len = strlen(hello)+1;
+
+ c_stream.zalloc = (alloc_func)0;
+ c_stream.zfree = (free_func)0;
+ c_stream.opaque = (voidpf)0;
+
+ err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
+ CHECK_ERR(err, "deflateInit");
+
+ c_stream.next_in = (Bytef*)hello;
+ c_stream.next_out = compr;
+ c_stream.avail_in = 3;
+ c_stream.avail_out = (uInt)*comprLen;
+ err = deflate(&c_stream, Z_FULL_FLUSH);
+ CHECK_ERR(err, "deflate");
+
+ compr[3]++; /* force an error in first compressed block */
+ c_stream.avail_in = len - 3;
+
+ err = deflate(&c_stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ CHECK_ERR(err, "deflate");
+ }
+ err = deflateEnd(&c_stream);
+ CHECK_ERR(err, "deflateEnd");
+
+ *comprLen = c_stream.total_out;
+}
+
+/* ===========================================================================
+ * Test inflateSync()
+ */
+void test_sync(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ int err;
+ z_stream d_stream; /* decompression stream */
+
+ strcpy((char*)uncompr, "garbage");
+
+ d_stream.zalloc = (alloc_func)0;
+ d_stream.zfree = (free_func)0;
+ d_stream.opaque = (voidpf)0;
+
+ d_stream.next_in = compr;
+ d_stream.avail_in = 2; /* just read the zlib header */
+
+ err = inflateInit(&d_stream);
+ CHECK_ERR(err, "inflateInit");
+
+ d_stream.next_out = uncompr;
+ d_stream.avail_out = (uInt)uncomprLen;
+
+ inflate(&d_stream, Z_NO_FLUSH);
+ CHECK_ERR(err, "inflate");
+
+ d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
+ err = inflateSync(&d_stream); /* but skip the damaged part */
+ CHECK_ERR(err, "inflateSync");
+
+ err = inflate(&d_stream, Z_FINISH);
+ if (err != Z_DATA_ERROR) {
+ fprintf(stderr, "inflate should report DATA_ERROR\n");
+ /* Because of incorrect adler32 */
+ exit(1);
+ }
+ err = inflateEnd(&d_stream);
+ CHECK_ERR(err, "inflateEnd");
+
+ printf("after inflateSync(): hel%s\n", (char *)uncompr);
+}
+
+/* ===========================================================================
+ * Test deflate() with preset dictionary
+ */
+void test_dict_deflate(compr, comprLen)
+ Byte *compr;
+ uLong comprLen;
+{
+ z_stream c_stream; /* compression stream */
+ int err;
+
+ c_stream.zalloc = (alloc_func)0;
+ c_stream.zfree = (free_func)0;
+ c_stream.opaque = (voidpf)0;
+
+ err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
+ CHECK_ERR(err, "deflateInit");
+
+ err = deflateSetDictionary(&c_stream,
+ (const Bytef*)dictionary, sizeof(dictionary));
+ CHECK_ERR(err, "deflateSetDictionary");
+
+ dictId = c_stream.adler;
+ c_stream.next_out = compr;
+ c_stream.avail_out = (uInt)comprLen;
+
+ c_stream.next_in = (Bytef*)hello;
+ c_stream.avail_in = (uInt)strlen(hello)+1;
+
+ err = deflate(&c_stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ fprintf(stderr, "deflate should report Z_STREAM_END\n");
+ exit(1);
+ }
+ err = deflateEnd(&c_stream);
+ CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with a preset dictionary
+ */
+void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
+ Byte *compr, *uncompr;
+ uLong comprLen, uncomprLen;
+{
+ int err;
+ z_stream d_stream; /* decompression stream */
+
+ strcpy((char*)uncompr, "garbage");
+
+ d_stream.zalloc = (alloc_func)0;
+ d_stream.zfree = (free_func)0;
+ d_stream.opaque = (voidpf)0;
+
+ d_stream.next_in = compr;
+ d_stream.avail_in = (uInt)comprLen;
+
+ err = inflateInit(&d_stream);
+ CHECK_ERR(err, "inflateInit");
+
+ d_stream.next_out = uncompr;
+ d_stream.avail_out = (uInt)uncomprLen;
+
+ for (;;) {
+ err = inflate(&d_stream, Z_NO_FLUSH);
+ if (err == Z_STREAM_END) break;
+ if (err == Z_NEED_DICT) {
+ if (d_stream.adler != dictId) {
+ fprintf(stderr, "unexpected dictionary");
+ exit(1);
+ }
+ err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
+ sizeof(dictionary));
+ }
+ CHECK_ERR(err, "inflate with dict");
+ }
+
+ err = inflateEnd(&d_stream);
+ CHECK_ERR(err, "inflateEnd");
+
+ if (strcmp((char*)uncompr, hello)) {
+ fprintf(stderr, "bad inflate with dict\n");
+ exit(1);
+ } else {
+ printf("inflate with dictionary: %s\n", (char *)uncompr);
+ }
+}
+
+/* ===========================================================================
+ * Usage: example [output.gz [input.gz]]
+ */
+
+int main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ Byte *compr, *uncompr;
+ uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
+ uLong uncomprLen = comprLen;
+ static const char* myVersion = ZLIB_VERSION;
+
+ if (zlibVersion()[0] != myVersion[0]) {
+ fprintf(stderr, "incompatible zlib version\n");
+ exit(1);
+
+ } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
+ fprintf(stderr, "warning: different zlib version\n");
+ }
+
+ compr = (Byte*)calloc((uInt)comprLen, 1);
+ uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
+ /* compr and uncompr are cleared to avoid reading uninitialized
+ * data and to ensure that uncompr compresses well.
+ */
+ if (compr == Z_NULL || uncompr == Z_NULL) {
+ printf("out of memory\n");
+ exit(1);
+ }
+ test_compress(compr, comprLen, uncompr, uncomprLen);
+
+ test_gzio((argc > 1 ? argv[1] : TESTFILE),
+ (argc > 2 ? argv[2] : TESTFILE),
+ uncompr, (int)uncomprLen);
+
+ test_deflate(compr, comprLen);
+ test_inflate(compr, comprLen, uncompr, uncomprLen);
+
+ test_large_deflate(compr, comprLen, uncompr, uncomprLen);
+ test_large_inflate(compr, comprLen, uncompr, uncomprLen);
+
+ test_flush(compr, &comprLen);
+ test_sync(compr, comprLen, uncompr, uncomprLen);
+ comprLen = uncomprLen;
+
+ test_dict_deflate(compr, comprLen);
+ test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
+
+ exit(0);
+ return 0; /* to avoid warning */
+}
diff --git a/osframework/source/ImageLib/zlib/faq b/osframework/source/ImageLib/zlib/faq
new file mode 100644
index 0000000..f297e8a
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/faq
@@ -0,0 +1,72 @@
+
+ Frequently Asked Questions about zlib
+
+
+If your question is not there, please check the zlib home page
+http://www.cdrom.com/pub/infozip/zlib/ which may have more recent information.
+
+
+1) I need a Windows DLL
+2) I need a Visual Basic interface to zlib
+3) compress() returns Z_BUF_ERROR
+4) deflate or inflate returns Z_BUF_ERROR
+5) Where is the zlib documentation (man pages, etc...)?
+6) Why don't you use GNU autoconf, libtool, etc...?
+7) There is a bug in zlib.
+8) I get "undefined reference to gzputc"
+
+
+
+1) I need a Windows DLL
+
+ The zlib sources can be compiled without change to produce a DLL.
+ If you want a precompiled DLL, see http://www.winimage.com/zLibDll
+
+
+2) I need a Visual Basic interface to zlib
+
+ See http://www.tcfb.com/dowseware/cmp-z-it.zip
+ http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
+ and contrib/visual-basic.txt
+
+3) compress() returns Z_BUF_ERROR
+
+ Make sure that before the call of compress, the length of the
+ compressed buffer is equal to the total size of the compressed buffer
+ and not zero. For Visual Basic, check that this parameter is passed
+ by reference ("as any"), not by value ("as long").
+
+
+4) deflate or inflate returns Z_BUF_ERROR
+
+ Make sure that before the call avail_in and avail_out are not zero.
+
+
+5) Where is the zlib documentation (man pages, etc...)?
+
+ It's in zlib.h for the moment. Volunteers to transform this
+ to man pages, please contact jloup@gzip.org. Examples of zlib usage
+ are in the files example.c and minigzip.c.
+
+
+6) Why don't you use GNU autoconf, libtool, etc...?
+
+ Because we would like to keep zlib as a very small and simple package.
+ zlib is rather portable and doesn't need much configuration.
+
+
+7) There is a bug in zlib.
+
+ Most of the time, such problems are due to an incorrect usage
+ of zlib. Please try to reproduce the problem with a small
+ program and send us the corresponding source at zlib@quest.jpl.nasa.gov
+ Do not send multi-megabyte data files without prior agreement.
+
+
+8) I get "undefined reference to gzputc"
+
+ If "make test" produces something like
+ example.o(.text+0x174):
+ check that you don't have old files libz.* in /usr/lib, /usr/local/lib
+ or /usr/X11R6/lib. Remove old versions then do "make install".
+
diff --git a/osframework/source/ImageLib/zlib/gzio.c b/osframework/source/ImageLib/zlib/gzio.c
new file mode 100644
index 0000000..d93e1e6
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/gzio.c
@@ -0,0 +1,875 @@
+/* gzio.c -- IO on .gz files
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Compile this file with -DNO_DEFLATE to avoid the compression code.
+ */
+
+/* @(#) $Id: gzio.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include <stdio.h>
+
+#include "zutil.h"
+
+struct internal_state {int dummy;}; /* for buggy compilers */
+
+#ifndef Z_BUFSIZE
+# ifdef MAXSEG_64K
+# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
+# else
+# define Z_BUFSIZE 16384
+# endif
+#endif
+#ifndef Z_PRINTF_BUFSIZE
+# define Z_PRINTF_BUFSIZE 4096
+#endif
+
+#define ALLOC(size) malloc(size)
+#define TRYFREE(p) {if (p) free(p);}
+
+static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
+
+/* gzip flag byte */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define RESERVED 0xE0 /* bits 5..7: reserved */
+
+typedef struct gz_stream {
+ z_stream stream;
+ int z_err; /* error code for last stream operation */
+ int z_eof; /* set if end of input file */
+ FILE *file; /* .gz file */
+ Byte *inbuf; /* input buffer */
+ Byte *outbuf; /* output buffer */
+ uLong crc; /* crc32 of uncompressed data */
+ char *msg; /* error message */
+ char *path; /* path name for debugging only */
+ int transparent; /* 1 if input file is not a .gz file */
+ char mode; /* 'w' or 'r' */
+ long startpos; /* start of compressed data in file (header skipped) */
+} gz_stream;
+
+
+local gzFile gz_open OF((const char *path, const char *mode, int fd));
+local int do_flush OF((gzFile file, int flush));
+local int get_byte OF((gz_stream *s));
+local void check_header OF((gz_stream *s));
+local int destroy OF((gz_stream *s));
+local void putLong OF((FILE *file, uLong x));
+local uLong getLong OF((gz_stream *s));
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb"). The file is given either by file descriptor
+ or path name (if fd == -1).
+ gz_open return NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR).
+*/
+local gzFile gz_open (path, mode, fd)
+ const char *path;
+ const char *mode;
+ int fd;
+{
+ int err;
+ int level = Z_DEFAULT_COMPRESSION; /* compression level */
+ int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
+ char *p = (char*)mode;
+ gz_stream *s;
+ char fmode[80]; /* copy of mode, without the compression level */
+ char *m = fmode;
+
+ if (!path || !mode) return Z_NULL;
+
+ s = (gz_stream *)ALLOC(sizeof(gz_stream));
+ if (!s) return Z_NULL;
+
+ s->stream.zalloc = (alloc_func)0;
+ s->stream.zfree = (free_func)0;
+ s->stream.opaque = (voidpf)0;
+ s->stream.next_in = s->inbuf = Z_NULL;
+ s->stream.next_out = s->outbuf = Z_NULL;
+ s->stream.avail_in = s->stream.avail_out = 0;
+ s->file = NULL;
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->crc = crc32(0L, Z_NULL, 0);
+ s->msg = NULL;
+ s->transparent = 0;
+
+ s->path = (char*)ALLOC(strlen(path)+1);
+ if (s->path == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ strcpy(s->path, path); /* do this early for debugging */
+
+ s->mode = '\0';
+ do {
+ if (*p == 'r') s->mode = 'r';
+ if (*p == 'w' || *p == 'a') s->mode = 'w';
+ if (*p >= '0' && *p <= '9') {
+ level = *p - '0';
+ } else if (*p == 'f') {
+ strategy = Z_FILTERED;
+ } else if (*p == 'h') {
+ strategy = Z_HUFFMAN_ONLY;
+ } else {
+ *m++ = *p; /* copy the mode */
+ }
+ } while (*p++ && m != fmode + sizeof(fmode));
+ if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
+
+ if (s->mode == 'w') {
+#ifdef NO_DEFLATE
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateInit2(&(s->stream), level,
+ Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
+ /* windowBits is passed < 0 to suppress zlib header */
+
+ s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+#endif
+ if (err != Z_OK || s->outbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ } else {
+ s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
+
+ err = inflateInit2(&(s->stream), -MAX_WBITS);
+ /* windowBits is passed < 0 to tell that there is no zlib header.
+ * Note that in this case inflate *requires* an extra "dummy" byte
+ * after the compressed stream in order to complete decompression and
+ * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
+ * present after the compressed stream.
+ */
+ if (err != Z_OK || s->inbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+
+ errno = 0;
+ s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
+
+ if (s->file == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ if (s->mode == 'w') {
+ /* Write a very simple .gz header:
+ */
+ fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
+ Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
+ s->startpos = 10L;
+ /* We use 10L instead of ftell(s->file) to because ftell causes an
+ * fflush on some systems. This version of the library doesn't use
+ * startpos anyway in write mode, so this initialization is not
+ * necessary.
+ */
+ } else {
+ check_header(s); /* skip the .gz header */
+ s->startpos = (ftell(s->file) - s->stream.avail_in);
+ }
+
+ return (gzFile)s;
+}
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing.
+*/
+gzFile ZEXPORT gzopen (path, mode)
+ const char *path;
+ const char *mode;
+{
+ return gz_open (path, mode, -1);
+}
+
+/* ===========================================================================
+ Associate a gzFile with the file descriptor fd. fd is not dup'ed here
+ to mimic the behavio(u)r of fdopen.
+*/
+gzFile ZEXPORT gzdopen (fd, mode)
+ int fd;
+ const char *mode;
+{
+ char name[20];
+
+ if (fd < 0) return (gzFile)Z_NULL;
+ sprintf(name, "<fd:%d>", fd); /* for debugging */
+
+ return gz_open (name, mode, fd);
+}
+
+/* ===========================================================================
+ * Update the compression level and strategy
+ */
+int ZEXPORT gzsetparams (file, level, strategy)
+ gzFile file;
+ int level;
+ int strategy;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ /* Make room to allow flushing */
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+
+ return deflateParams (&(s->stream), level, strategy);
+}
+
+/* ===========================================================================
+ Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+ for end of file.
+ IN assertion: the stream s has been sucessfully opened for reading.
+*/
+local int get_byte(s)
+ gz_stream *s;
+{
+ if (s->z_eof) return EOF;
+ if (s->stream.avail_in == 0) {
+ errno = 0;
+ s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) s->z_err = Z_ERRNO;
+ return EOF;
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->stream.avail_in--;
+ return *(s->stream.next_in)++;
+}
+
+/* ===========================================================================
+ Check the gzip header of a gz_stream opened for reading. Set the stream
+ mode to transparent if the gzip magic header is not present; set s->err
+ to Z_DATA_ERROR if the magic header is present but the rest of the header
+ is incorrect.
+ IN assertion: the stream s has already been created sucessfully;
+ s->stream.avail_in is zero for the first time, but may be non-zero
+ for concatenated .gz files.
+*/
+local void check_header(s)
+ gz_stream *s;
+{
+ int method; /* method byte */
+ int flags; /* flags byte */
+ uInt len;
+ int c;
+
+ /* Check the gzip magic header */
+ for (len = 0; len < 2; len++) {
+ c = get_byte(s);
+ if (c != gz_magic[len]) {
+ if (len != 0) s->stream.avail_in++, s->stream.next_in--;
+ if (c != EOF) {
+ s->stream.avail_in++, s->stream.next_in--;
+ s->transparent = 1;
+ }
+ s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
+ return;
+ }
+ }
+ method = get_byte(s);
+ flags = get_byte(s);
+ if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
+ s->z_err = Z_DATA_ERROR;
+ return;
+ }
+
+ /* Discard time, xflags and OS code: */
+ for (len = 0; len < 6; len++) (void)get_byte(s);
+
+ if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
+ len = (uInt)get_byte(s);
+ len += ((uInt)get_byte(s))<<8;
+ /* len is garbage if EOF but the loop below will quit anyway */
+ while (len-- != 0 && get_byte(s) != EOF) ;
+ }
+ if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
+ for (len = 0; len < 2; len++) (void)get_byte(s);
+ }
+ s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
+}
+
+ /* ===========================================================================
+ * Cleanup then free the given gz_stream. Return a zlib error code.
+ Try freeing in the reverse order of allocations.
+ */
+local int destroy (s)
+ gz_stream *s;
+{
+ int err = Z_OK;
+
+ if (!s) return Z_STREAM_ERROR;
+
+ TRYFREE(s->msg);
+
+ if (s->stream.state != NULL) {
+ if (s->mode == 'w') {
+#ifdef NO_DEFLATE
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateEnd(&(s->stream));
+#endif
+ } else if (s->mode == 'r') {
+ err = inflateEnd(&(s->stream));
+ }
+ }
+ if (s->file != NULL && fclose(s->file)) {
+#ifdef ESPIPE
+ if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
+#endif
+ err = Z_ERRNO;
+ }
+ if (s->z_err < 0) err = s->z_err;
+
+ TRYFREE(s->inbuf);
+ TRYFREE(s->outbuf);
+ TRYFREE(s->path);
+ TRYFREE(s);
+ return err;
+}
+
+/* ===========================================================================
+ Reads the given number of uncompressed bytes from the compressed file.
+ gzread returns the number of bytes actually read (0 for end of file).
+*/
+int ZEXPORT gzread (file, buf, len)
+ gzFile file;
+ voidp buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+ Bytef *start = (Bytef*)buf; /* starting point for crc computation */
+ Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
+
+ if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
+
+ if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
+ if (s->z_err == Z_STREAM_END) return 0; /* EOF */
+
+ next_out = (Byte*)buf;
+ s->stream.next_out = (Bytef*)buf;
+ s->stream.avail_out = len;
+
+ while (s->stream.avail_out != 0) {
+
+ if (s->transparent) {
+ /* Copy first the lookahead bytes: */
+ uInt n = s->stream.avail_in;
+ if (n > s->stream.avail_out) n = s->stream.avail_out;
+ if (n > 0) {
+ zmemcpy(s->stream.next_out, s->stream.next_in, n);
+ next_out += n;
+ s->stream.next_out = next_out;
+ s->stream.next_in += n;
+ s->stream.avail_out -= n;
+ s->stream.avail_in -= n;
+ }
+ if (s->stream.avail_out > 0) {
+ s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
+ s->file);
+ }
+ len -= s->stream.avail_out;
+ s->stream.total_in += (uLong)len;
+ s->stream.total_out += (uLong)len;
+ if (len == 0) s->z_eof = 1;
+ return (int)len;
+ }
+ if (s->stream.avail_in == 0 && !s->z_eof) {
+
+ errno = 0;
+ s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
+
+ if (s->z_err == Z_STREAM_END) {
+ /* Check CRC and original size */
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+ start = s->stream.next_out;
+
+ if (getLong(s) != s->crc) {
+ s->z_err = Z_DATA_ERROR;
+ } else {
+ (void)getLong(s);
+ /* The uncompressed length returned by above getlong() may
+ * be different from s->stream.total_out) in case of
+ * concatenated .gz files. Check for such files:
+ */
+ check_header(s);
+ if (s->z_err == Z_OK) {
+ uLong total_in = s->stream.total_in;
+ uLong total_out = s->stream.total_out;
+
+ inflateReset(&(s->stream));
+ s->stream.total_in = total_in;
+ s->stream.total_out = total_out;
+ s->crc = crc32(0L, Z_NULL, 0);
+ }
+ }
+ }
+ if (s->z_err != Z_OK || s->z_eof) break;
+ }
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+
+ return (int)(len - s->stream.avail_out);
+}
+
+
+/* ===========================================================================
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+int ZEXPORT gzgetc(file)
+ gzFile file;
+{
+ unsigned char c;
+
+ return gzread(file, &c, 1) == 1 ? c : -1;
+}
+
+
+/* ===========================================================================
+ Reads bytes from the compressed file until len-1 characters are
+ read, or a newline character is read and transferred to buf, or an
+ end-of-file condition is encountered. The string is then terminated
+ with a null character.
+ gzgets returns buf, or Z_NULL in case of error.
+
+ The current implementation is not optimized at all.
+*/
+char * ZEXPORT gzgets(file, buf, len)
+ gzFile file;
+ char *buf;
+ int len;
+{
+ char *b = buf;
+ if (buf == Z_NULL || len <= 0) return Z_NULL;
+
+ while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
+ *buf = '\0';
+ return b == buf && len > 0 ? Z_NULL : b;
+}
+
+
+#ifndef NO_DEFLATE
+/* ===========================================================================
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of bytes actually written (0 in case of error).
+*/
+int ZEXPORT gzwrite (file, buf, len)
+ gzFile file;
+ const voidp buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.next_in = (Bytef*)buf;
+ s->stream.avail_in = len;
+
+ while (s->stream.avail_in != 0) {
+
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
+ if (s->z_err != Z_OK) break;
+ }
+ s->crc = crc32(s->crc, (const Bytef *)buf, len);
+
+ return (int)(len - s->stream.avail_in);
+}
+
+/* ===========================================================================
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error).
+*/
+#ifdef STDC
+#include <stdarg.h>
+
+int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ va_list va;
+ int len;
+
+ va_start(va, format);
+#ifdef HAS_vsnprintf
+ (void)vsnprintf(buf, sizeof(buf), format, va);
+#else
+ (void)vsprintf(buf, format, va);
+#endif
+ va_end(va);
+ len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
+ if (len <= 0) return 0;
+
+ return gzwrite(file, buf, (unsigned)len);
+}
+#else /* not ANSI C */
+
+int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
+ gzFile file;
+ const char *format;
+ int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ int len;
+
+#ifdef HAS_snprintf
+ snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+#else
+ sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+#endif
+ len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
+ if (len <= 0) return 0;
+
+ return gzwrite(file, buf, len);
+}
+#endif
+
+/* ===========================================================================
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+int ZEXPORT gzputc(file, c)
+ gzFile file;
+ int c;
+{
+ unsigned char cc = (unsigned char) c; /* required for big endian systems */
+
+ return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
+}
+
+
+/* ===========================================================================
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+int ZEXPORT gzputs(file, s)
+ gzFile file;
+ const char *s;
+{
+ return gzwrite(file, (char*)s, (unsigned)strlen(s));
+}
+
+
+/* ===========================================================================
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function.
+*/
+local int do_flush (file, flush)
+ gzFile file;
+ int flush;
+{
+ uInt len;
+ int done = 0;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.avail_in = 0; /* should be zero already anyway */
+
+ for (;;) {
+ len = Z_BUFSIZE - s->stream.avail_out;
+
+ if (len != 0) {
+ if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
+ s->z_err = Z_ERRNO;
+ return Z_ERRNO;
+ }
+ s->stream.next_out = s->outbuf;
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ if (done) break;
+ s->z_err = deflate(&(s->stream), flush);
+
+ /* Ignore the second of two consecutive flushes: */
+ if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
+
+ /* deflate has finished flushing only when it hasn't used up
+ * all the available space in the output buffer:
+ */
+ done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
+
+ if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
+ }
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+
+int ZEXPORT gzflush (file, flush)
+ gzFile file;
+ int flush;
+{
+ gz_stream *s = (gz_stream*)file;
+ int err = do_flush (file, flush);
+
+ if (err) return err;
+ fflush(s->file);
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+#endif /* NO_DEFLATE */
+
+/* ===========================================================================
+ Sets the starting position for the next gzread or gzwrite on the given
+ compressed file. The offset represents a number of bytes in the
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error.
+ SEEK_END is not implemented, returns error.
+ In this version of the library, gzseek can be extremely slow.
+*/
+z_off_t ZEXPORT gzseek (file, offset, whence)
+ gzFile file;
+ z_off_t offset;
+ int whence;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || whence == SEEK_END ||
+ s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
+ return -1L;
+ }
+
+ if (s->mode == 'w') {
+#ifdef NO_DEFLATE
+ return -1L;
+#else
+ if (whence == SEEK_SET) {
+ offset -= s->stream.total_in;
+ }
+ if (offset < 0) return -1L;
+
+ /* At this point, offset is the number of zero bytes to write. */
+ if (s->inbuf == Z_NULL) {
+ s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
+ zmemzero(s->inbuf, Z_BUFSIZE);
+ }
+ while (offset > 0) {
+ uInt size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (uInt)offset;
+
+ size = gzwrite(file, s->inbuf, size);
+ if (size == 0) return -1L;
+
+ offset -= size;
+ }
+ return (z_off_t)s->stream.total_in;
+#endif
+ }
+ /* Rest of function is for reading only */
+
+ /* compute absolute position */
+ if (whence == SEEK_CUR) {
+ offset += s->stream.total_out;
+ }
+ if (offset < 0) return -1L;
+
+ if (s->transparent) {
+ /* map to fseek */
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
+
+ s->stream.total_in = s->stream.total_out = (uLong)offset;
+ return offset;
+ }
+
+ /* For a negative seek, rewind and use positive seek */
+ if ((uLong)offset >= s->stream.total_out) {
+ offset -= s->stream.total_out;
+ } else if (gzrewind(file) < 0) {
+ return -1L;
+ }
+ /* offset is now the number of bytes to skip. */
+
+ if (offset != 0 && s->outbuf == Z_NULL) {
+ s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+ }
+ while (offset > 0) {
+ int size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (int)offset;
+
+ size = gzread(file, s->outbuf, (uInt)size);
+ if (size <= 0) return -1L;
+ offset -= size;
+ }
+ return (z_off_t)s->stream.total_out;
+}
+
+/* ===========================================================================
+ Rewinds input file.
+*/
+int ZEXPORT gzrewind (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r') return -1;
+
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ s->crc = crc32(0L, Z_NULL, 0);
+
+ if (s->startpos == 0) { /* not a compressed file */
+ rewind(s->file);
+ return 0;
+ }
+
+ (void) inflateReset(&s->stream);
+ return fseek(s->file, s->startpos, SEEK_SET);
+}
+
+/* ===========================================================================
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+*/
+z_off_t ZEXPORT gztell (file)
+ gzFile file;
+{
+ return gzseek(file, 0L, SEEK_CUR);
+}
+
+/* ===========================================================================
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+int ZEXPORT gzeof (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
+}
+
+/* ===========================================================================
+ Outputs a long in LSB order to the given file
+*/
+local void putLong (file, x)
+ FILE *file;
+ uLong x;
+{
+ int n;
+ for (n = 0; n < 4; n++) {
+ fputc((int)(x & 0xff), file);
+ x >>= 8;
+ }
+}
+
+/* ===========================================================================
+ Reads a long in LSB order from the given gz_stream. Sets z_err in case
+ of error.
+*/
+local uLong getLong (s)
+ gz_stream *s;
+{
+ uLong x = (uLong)get_byte(s);
+ int c;
+
+ x += ((uLong)get_byte(s))<<8;
+ x += ((uLong)get_byte(s))<<16;
+ c = get_byte(s);
+ if (c == EOF) s->z_err = Z_DATA_ERROR;
+ x += ((uLong)c)<<24;
+ return x;
+}
+
+/* ===========================================================================
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state.
+*/
+int ZEXPORT gzclose (file)
+ gzFile file;
+{
+ int err;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) return Z_STREAM_ERROR;
+
+ if (s->mode == 'w') {
+#ifdef NO_DEFLATE
+ return Z_STREAM_ERROR;
+#else
+ err = do_flush (file, Z_FINISH);
+ if (err != Z_OK) return destroy((gz_stream*)file);
+
+ putLong (s->file, s->crc);
+ putLong (s->file, s->stream.total_in);
+#endif
+ }
+ return destroy((gz_stream*)file);
+}
+
+/* ===========================================================================
+ Returns the error message for the last error which occured on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occured in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+const char* ZEXPORT gzerror (file, errnum)
+ gzFile file;
+ int *errnum;
+{
+ char *m;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) {
+ *errnum = Z_STREAM_ERROR;
+ return (const char*)ERR_MSG(Z_STREAM_ERROR);
+ }
+ *errnum = s->z_err;
+ if (*errnum == Z_OK) return (const char*)"";
+
+ m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
+
+ if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
+
+ TRYFREE(s->msg);
+ s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
+ strcpy(s->msg, s->path);
+ strcat(s->msg, ": ");
+ strcat(s->msg, m);
+ return (const char*)s->msg;
+}
diff --git a/osframework/source/ImageLib/zlib/index b/osframework/source/ImageLib/zlib/index
new file mode 100644
index 0000000..9615c34
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/index
@@ -0,0 +1,86 @@
+ChangeLog history of changes
+INDEX this file
+FAQ Frequently Asked Questions about zlib
+Make_vms.com script for Vax/VMS
+Makefile makefile for Unix (generated by configure)
+Makefile.in makefile for Unix (template for configure)
+Makefile.riscos makefile for RISCOS
+README guess what
+algorithm.txt description of the (de)compression algorithm
+configure configure script for Unix
+descrip.mms makefile for Vax/VMS
+zlib.3 mini man page for zlib (volunteers to write full
+ man pages from zlib.h welcome. write to jloup@gzip.org)
+
+amiga/Makefile.sas makefile for Amiga SAS/C
+amiga/Makefile.pup makefile for Amiga powerUP SAS/C PPC
+
+msdos/Makefile.w32 makefile for Microsoft Visual C++ 32-bit
+msdos/Makefile.b32 makefile for Borland C++ 32-bit
+msdos/Makefile.bor makefile for Borland C/C++ 16-bit
+msdos/Makefile.dj2 makefile for DJGPP 2.x
+msdos/Makefile.emx makefile for EMX 0.9c (32-bit DOS/OS2)
+msdos/Makefile.msc makefile for Microsoft C 16-bit
+msdos/Makefile.tc makefile for Turbo C
+msdos/Makefile.wat makefile for Watcom C
+msdos/zlib.def definition file for Windows DLL
+msdos/zlib.rc definition file for Windows DLL
+
+nt/Makefile.nt makefile for Windows NT
+nt/zlib.dnt definition file for Windows NT DLL
+nt/Makefile.emx makefile for EMX 0.9c/RSXNT 1.41 (Win32 Intel)
+nt/Makefile.gcc makefile for Windows NT using GCC (mingw32)
+
+
+ zlib public header files (must be kept):
+zconf.h
+zlib.h
+
+ private source files used to build the zlib library:
+adler32.c
+compress.c
+crc32.c
+deflate.c
+deflate.h
+gzio.c
+infblock.c
+infblock.h
+infcodes.c
+infcodes.h
+inffast.c
+inffast.h
+inflate.c
+inftrees.c
+inftrees.h
+infutil.c
+infutil.h
+maketree.c
+trees.c
+uncompr.c
+zutil.c
+zutil.h
+
+ source files for sample programs:
+example.c
+minigzip.c
+
+ unsupported contribution by third parties
+
+contrib/asm386/ by Gilles Vollant <info@winimage.com>
+ 386 asm code replacing longest_match().
+
+contrib/minizip/ by Gilles Vollant <info@winimage.com>
+ Mini zip and unzip based on zlib
+ See http://www.winimage.com/zLibDll/unzip.html
+
+contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+ A C++ I/O streams interface to the zlib gz* functions
+
+contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
+ Another C++ I/O streams interface
+
+contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+ A very simple tar.gz extractor using zlib
+
+contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+ How to use compress(), uncompress() and the gz* functions from VB.
diff --git a/osframework/source/ImageLib/zlib/infblock.c b/osframework/source/ImageLib/zlib/infblock.c
new file mode 100644
index 0000000..478799d
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infblock.c
@@ -0,0 +1,398 @@
+/* infblock.c -- interpret and process block types to last block
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "infblock.h"
+#include "inftrees.h"
+#include "infcodes.h"
+#include "infutil.h"
+
+struct inflate_codes_state {int dummy;}; /* for buggy compilers */
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+/* Table for deflate from PKZIP's appnote.txt. */
+local const uInt border[] = { /* Order of the bit length code lengths */
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+/*
+ Notes beyond the 1.93a appnote.txt:
+
+ 1. Distance pointers never point before the beginning of the output
+ stream.
+ 2. Distance pointers can point back across blocks, up to 32k away.
+ 3. There is an implied maximum of 7 bits for the bit length table and
+ 15 bits for the actual data.
+ 4. If only one code exists, then it is encoded using one bit. (Zero
+ would be more efficient, but perhaps a little confusing.) If two
+ codes exist, they are coded using one bit each (0 and 1).
+ 5. There is no way of sending zero distance codes--a dummy must be
+ sent if there are none. (History: a pre 2.0 version of PKZIP would
+ store blocks with no distance codes, but this was discovered to be
+ too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
+ zero distance codes, which is sent as one code of zero bits in
+ length.
+ 6. There are up to 286 literal/length codes. Code 256 represents the
+ end-of-block. Note however that the static length tree defines
+ 288 codes just to fill out the Huffman codes. Codes 286 and 287
+ cannot be used though, since there is no length base or extra bits
+ defined for them. Similarily, there are up to 30 distance codes.
+ However, static trees define 32 codes (all 5 bits) to fill out the
+ Huffman codes, but the last two had better not show up in the data.
+ 7. Unzip can check dynamic Huffman blocks for complete code sets.
+ The exception is that a single code would not be complete (see #4).
+ 8. The five bits following the block type is really the number of
+ literal codes sent minus 257.
+ 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
+ (1+6+6). Therefore, to output three times the length, you output
+ three codes (1+1+1), whereas to output four times the same length,
+ you only need two codes (1+3). Hmm.
+ 10. In the tree reconstruction algorithm, Code = Code + Increment
+ only if BitLength(i) is not zero. (Pretty obvious.)
+ 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
+ 12. Note: length code 284 can represent 227-258, but length code 285
+ really is 258. The last length deserves its own, short code
+ since it gets used a lot in very redundant files. The length
+ 258 is special since 258 - 3 (the min match length) is 255.
+ 13. The literal/length and distance code bit lengths are read as a
+ single stream of lengths. It is possible (and advantageous) for
+ a repeat code (16, 17, or 18) to go across the boundary between
+ the two sets of lengths.
+ */
+
+
+void inflate_blocks_reset(s, z, c)
+inflate_blocks_statef *s;
+z_streamp z;
+uLongf *c;
+{
+ if (c != Z_NULL)
+ *c = s->check;
+ if (s->mode == BTREE || s->mode == DTREE)
+ ZFREE(z, s->sub.trees.blens);
+ if (s->mode == CODES)
+ inflate_codes_free(s->sub.decode.codes, z);
+ s->mode = TYPE;
+ s->bitk = 0;
+ s->bitb = 0;
+ s->read = s->write = s->window;
+ if (s->checkfn != Z_NULL)
+ z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
+ Tracev((stderr, "inflate: blocks reset\n"));
+}
+
+
+inflate_blocks_statef *inflate_blocks_new(z, c, w)
+z_streamp z;
+check_func c;
+uInt w;
+{
+ inflate_blocks_statef *s;
+
+ if ((s = (inflate_blocks_statef *)ZALLOC
+ (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
+ return s;
+ if ((s->hufts =
+ (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
+ {
+ ZFREE(z, s);
+ return Z_NULL;
+ }
+ if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
+ {
+ ZFREE(z, s->hufts);
+ ZFREE(z, s);
+ return Z_NULL;
+ }
+ s->end = s->window + w;
+ s->checkfn = c;
+ s->mode = TYPE;
+ Tracev((stderr, "inflate: blocks allocated\n"));
+ inflate_blocks_reset(s, z, Z_NULL);
+ return s;
+}
+
+
+int inflate_blocks(s, z, r)
+inflate_blocks_statef *s;
+z_streamp z;
+int r;
+{
+ uInt t; /* temporary storage */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Bytef *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Bytef *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+
+ /* copy input/output information to locals (UPDATE macro restores) */
+ LOAD
+
+ /* process input based on current state */
+ while (1) switch (s->mode)
+ {
+ case TYPE:
+ NEEDBITS(3)
+ t = (uInt)b & 7;
+ s->last = t & 1;
+ switch (t >> 1)
+ {
+ case 0: /* stored */
+ Tracev((stderr, "inflate: stored block%s\n",
+ s->last ? " (last)" : ""));
+ DUMPBITS(3)
+ t = k & 7; /* go to byte boundary */
+ DUMPBITS(t)
+ s->mode = LENS; /* get length of stored block */
+ break;
+ case 1: /* fixed */
+ Tracev((stderr, "inflate: fixed codes block%s\n",
+ s->last ? " (last)" : ""));
+ {
+ uInt bl, bd;
+ inflate_huft *tl, *td;
+
+ inflate_trees_fixed(&bl, &bd, &tl, &td, z);
+ s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
+ if (s->sub.decode.codes == Z_NULL)
+ {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ }
+ DUMPBITS(3)
+ s->mode = CODES;
+ break;
+ case 2: /* dynamic */
+ Tracev((stderr, "inflate: dynamic codes block%s\n",
+ s->last ? " (last)" : ""));
+ DUMPBITS(3)
+ s->mode = TABLE;
+ break;
+ case 3: /* illegal */
+ DUMPBITS(3)
+ s->mode = BAD;
+ z->msg = (char*)"invalid block type";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ break;
+ case LENS:
+ NEEDBITS(32)
+ if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
+ {
+ s->mode = BAD;
+ z->msg = (char*)"invalid stored block lengths";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ s->sub.left = (uInt)b & 0xffff;
+ b = k = 0; /* dump bits */
+ Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
+ s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
+ break;
+ case STORED:
+ if (n == 0)
+ LEAVE
+ NEEDOUT
+ t = s->sub.left;
+ if (t > n) t = n;
+ if (t > m) t = m;
+ zmemcpy(q, p, t);
+ p += t; n -= t;
+ q += t; m -= t;
+ if ((s->sub.left -= t) != 0)
+ break;
+ Tracev((stderr, "inflate: stored end, %lu total out\n",
+ z->total_out + (q >= s->read ? q - s->read :
+ (s->end - s->read) + (q - s->window))));
+ s->mode = s->last ? DRY : TYPE;
+ break;
+ case TABLE:
+ NEEDBITS(14)
+ s->sub.trees.table = t = (uInt)b & 0x3fff;
+#ifndef PKZIP_BUG_WORKAROUND
+ if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
+ {
+ s->mode = BAD;
+ z->msg = (char*)"too many length or distance symbols";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+#endif
+ t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
+ if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
+ {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ DUMPBITS(14)
+ s->sub.trees.index = 0;
+ Tracev((stderr, "inflate: table sizes ok\n"));
+ s->mode = BTREE;
+ case BTREE:
+ while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
+ {
+ NEEDBITS(3)
+ s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
+ DUMPBITS(3)
+ }
+ while (s->sub.trees.index < 19)
+ s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
+ s->sub.trees.bb = 7;
+ t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
+ &s->sub.trees.tb, s->hufts, z);
+ if (t != Z_OK)
+ {
+ ZFREE(z, s->sub.trees.blens);
+ r = t;
+ if (r == Z_DATA_ERROR)
+ s->mode = BAD;
+ LEAVE
+ }
+ s->sub.trees.index = 0;
+ Tracev((stderr, "inflate: bits tree ok\n"));
+ s->mode = DTREE;
+ case DTREE:
+ while (t = s->sub.trees.table,
+ s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
+ {
+ inflate_huft *h;
+ uInt i, j, c;
+
+ t = s->sub.trees.bb;
+ NEEDBITS(t)
+ h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
+ t = h->bits;
+ c = h->base;
+ if (c < 16)
+ {
+ DUMPBITS(t)
+ s->sub.trees.blens[s->sub.trees.index++] = c;
+ }
+ else /* c == 16..18 */
+ {
+ i = c == 18 ? 7 : c - 14;
+ j = c == 18 ? 11 : 3;
+ NEEDBITS(t + i)
+ DUMPBITS(t)
+ j += (uInt)b & inflate_mask[i];
+ DUMPBITS(i)
+ i = s->sub.trees.index;
+ t = s->sub.trees.table;
+ if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
+ (c == 16 && i < 1))
+ {
+ ZFREE(z, s->sub.trees.blens);
+ s->mode = BAD;
+ z->msg = (char*)"invalid bit length repeat";
+ r = Z_DATA_ERROR;
+ LEAVE
+ }
+ c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
+ do {
+ s->sub.trees.blens[i++] = c;
+ } while (--j);
+ s->sub.trees.index = i;
+ }
+ }
+ s->sub.trees.tb = Z_NULL;
+ {
+ uInt bl, bd;
+ inflate_huft *tl, *td;
+ inflate_codes_statef *c;
+
+ bl = 9; /* must be <= 9 for lookahead assumptions */
+ bd = 6; /* must be <= 9 for lookahead assumptions */
+ t = s->sub.trees.table;
+ t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
+ s->sub.trees.blens, &bl, &bd, &tl, &td,
+ s->hufts, z);
+ ZFREE(z, s->sub.trees.blens);
+ if (t != Z_OK)
+ {
+ if (t == (uInt)Z_DATA_ERROR)
+ s->mode = BAD;
+ r = t;
+ LEAVE
+ }
+ Tracev((stderr, "inflate: trees ok\n"));
+ if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
+ {
+ r = Z_MEM_ERROR;
+ LEAVE
+ }
+ s->sub.decode.codes = c;
+ }
+ s->mode = CODES;
+ case CODES:
+ UPDATE
+ if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
+ return inflate_flush(s, z, r);
+ r = Z_OK;
+ inflate_codes_free(s->sub.decode.codes, z);
+ LOAD
+ Tracev((stderr, "inflate: codes end, %lu total out\n",
+ z->total_out + (q >= s->read ? q - s->read :
+ (s->end - s->read) + (q - s->window))));
+ if (!s->last)
+ {
+ s->mode = TYPE;
+ break;
+ }
+ s->mode = DRY;
+ case DRY:
+ FLUSH
+ if (s->read != s->write)
+ LEAVE
+ s->mode = DONE;
+ case DONE:
+ r = Z_STREAM_END;
+ LEAVE
+ case BAD:
+ r = Z_DATA_ERROR;
+ LEAVE
+ default:
+ r = Z_STREAM_ERROR;
+ LEAVE
+ }
+}
+
+
+int inflate_blocks_free(s, z)
+inflate_blocks_statef *s;
+z_streamp z;
+{
+ inflate_blocks_reset(s, z, Z_NULL);
+ ZFREE(z, s->window);
+ ZFREE(z, s->hufts);
+ ZFREE(z, s);
+ Tracev((stderr, "inflate: blocks freed\n"));
+ return Z_OK;
+}
+
+
+void inflate_set_dictionary(s, d, n)
+inflate_blocks_statef *s;
+const Bytef *d;
+uInt n;
+{
+ zmemcpy(s->window, d, n);
+ s->read = s->write = s->window + n;
+}
+
+
+/* Returns true if inflate is currently at the end of a block generated
+ * by Z_SYNC_FLUSH or Z_FULL_FLUSH.
+ * IN assertion: s != Z_NULL
+ */
+int inflate_blocks_sync_point(s)
+inflate_blocks_statef *s;
+{
+ return s->mode == LENS;
+}
diff --git a/osframework/source/ImageLib/zlib/infblock.h b/osframework/source/ImageLib/zlib/infblock.h
new file mode 100644
index 0000000..393b25a
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infblock.h
@@ -0,0 +1,39 @@
+/* infblock.h -- header to use infblock.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+struct inflate_blocks_state;
+typedef struct inflate_blocks_state FAR inflate_blocks_statef;
+
+extern inflate_blocks_statef * inflate_blocks_new OF((
+ z_streamp z,
+ check_func c, /* check function */
+ uInt w)); /* window size */
+
+extern int inflate_blocks OF((
+ inflate_blocks_statef *,
+ z_streamp ,
+ int)); /* initial return code */
+
+extern void inflate_blocks_reset OF((
+ inflate_blocks_statef *,
+ z_streamp ,
+ uLongf *)); /* check value on output */
+
+extern int inflate_blocks_free OF((
+ inflate_blocks_statef *,
+ z_streamp));
+
+extern void inflate_set_dictionary OF((
+ inflate_blocks_statef *s,
+ const Bytef *d, /* dictionary */
+ uInt n)); /* dictionary length */
+
+extern int inflate_blocks_sync_point OF((
+ inflate_blocks_statef *s));
diff --git a/osframework/source/ImageLib/zlib/infcodes.c b/osframework/source/ImageLib/zlib/infcodes.c
new file mode 100644
index 0000000..916470d
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infcodes.c
@@ -0,0 +1,257 @@
+/* infcodes.c -- process literals and length/distance pairs
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "infblock.h"
+#include "infcodes.h"
+#include "infutil.h"
+#include "inffast.h"
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
+ START, /* x: set up for LEN */
+ LEN, /* i: get length/literal/eob next */
+ LENEXT, /* i: getting length extra (have base) */
+ DIST, /* i: get distance next */
+ DISTEXT, /* i: getting distance extra */
+ COPY, /* o: copying bytes in window, waiting for space */
+ LIT, /* o: got literal, waiting for output space */
+ WASH, /* o: got eob, possibly still output waiting */
+ END, /* x: got eob and all data flushed */
+ BADCODE} /* x: got error */
+inflate_codes_mode;
+
+/* inflate codes private state */
+struct inflate_codes_state {
+
+ /* mode */
+ inflate_codes_mode mode; /* current inflate_codes mode */
+
+ /* mode dependent information */
+ uInt len;
+ union {
+ struct {
+ inflate_huft *tree; /* pointer into tree */
+ uInt need; /* bits needed */
+ } code; /* if LEN or DIST, where in tree */
+ uInt lit; /* if LIT, literal */
+ struct {
+ uInt get; /* bits to get for extra */
+ uInt dist; /* distance back to copy from */
+ } copy; /* if EXT or COPY, where and how much */
+ } sub; /* submode */
+
+ /* mode independent information */
+ Byte lbits; /* ltree bits decoded per branch */
+ Byte dbits; /* dtree bits decoder per branch */
+ inflate_huft *ltree; /* literal/length/eob tree */
+ inflate_huft *dtree; /* distance tree */
+
+};
+
+
+inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
+uInt bl, bd;
+inflate_huft *tl;
+inflate_huft *td; /* need separate declaration for Borland C++ */
+z_streamp z;
+{
+ inflate_codes_statef *c;
+
+ if ((c = (inflate_codes_statef *)
+ ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
+ {
+ c->mode = START;
+ c->lbits = (Byte)bl;
+ c->dbits = (Byte)bd;
+ c->ltree = tl;
+ c->dtree = td;
+ Tracev((stderr, "inflate: codes new\n"));
+ }
+ return c;
+}
+
+
+int inflate_codes(s, z, r)
+inflate_blocks_statef *s;
+z_streamp z;
+int r;
+{
+ uInt j; /* temporary storage */
+ inflate_huft *t; /* temporary pointer */
+ uInt e; /* extra bits or operation */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Bytef *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Bytef *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+ Bytef *f; /* pointer to copy strings from */
+ inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
+
+ /* copy input/output information to locals (UPDATE macro restores) */
+ LOAD
+
+ /* process input and output based on current state */
+ while (1) switch (c->mode)
+ { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
+ case START: /* x: set up for LEN */
+#ifndef SLOW
+ if (m >= 258 && n >= 10)
+ {
+ UPDATE
+ r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
+ LOAD
+ if (r != Z_OK)
+ {
+ c->mode = r == Z_STREAM_END ? WASH : BADCODE;
+ break;
+ }
+ }
+#endif /* !SLOW */
+ c->sub.code.need = c->lbits;
+ c->sub.code.tree = c->ltree;
+ c->mode = LEN;
+ case LEN: /* i: get length/literal/eob next */
+ j = c->sub.code.need;
+ NEEDBITS(j)
+ t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
+ DUMPBITS(t->bits)
+ e = (uInt)(t->exop);
+ if (e == 0) /* literal */
+ {
+ c->sub.lit = t->base;
+ Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", t->base));
+ c->mode = LIT;
+ break;
+ }
+ if (e & 16) /* length */
+ {
+ c->sub.copy.get = e & 15;
+ c->len = t->base;
+ c->mode = LENEXT;
+ break;
+ }
+ if ((e & 64) == 0) /* next table */
+ {
+ c->sub.code.need = e;
+ c->sub.code.tree = t + t->base;
+ break;
+ }
+ if (e & 32) /* end of block */
+ {
+ Tracevv((stderr, "inflate: end of block\n"));
+ c->mode = WASH;
+ break;
+ }
+ c->mode = BADCODE; /* invalid code */
+ z->msg = (char*)"invalid literal/length code";
+ r = Z_DATA_ERROR;
+ LEAVE
+ case LENEXT: /* i: getting length extra (have base) */
+ j = c->sub.copy.get;
+ NEEDBITS(j)
+ c->len += (uInt)b & inflate_mask[j];
+ DUMPBITS(j)
+ c->sub.code.need = c->dbits;
+ c->sub.code.tree = c->dtree;
+ Tracevv((stderr, "inflate: length %u\n", c->len));
+ c->mode = DIST;
+ case DIST: /* i: get distance next */
+ j = c->sub.code.need;
+ NEEDBITS(j)
+ t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
+ DUMPBITS(t->bits)
+ e = (uInt)(t->exop);
+ if (e & 16) /* distance */
+ {
+ c->sub.copy.get = e & 15;
+ c->sub.copy.dist = t->base;
+ c->mode = DISTEXT;
+ break;
+ }
+ if ((e & 64) == 0) /* next table */
+ {
+ c->sub.code.need = e;
+ c->sub.code.tree = t + t->base;
+ break;
+ }
+ c->mode = BADCODE; /* invalid code */
+ z->msg = (char*)"invalid distance code";
+ r = Z_DATA_ERROR;
+ LEAVE
+ case DISTEXT: /* i: getting distance extra */
+ j = c->sub.copy.get;
+ NEEDBITS(j)
+ c->sub.copy.dist += (uInt)b & inflate_mask[j];
+ DUMPBITS(j)
+ Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
+ c->mode = COPY;
+ case COPY: /* o: copying bytes in window, waiting for space */
+#ifndef __TURBOC__ /* Turbo C bug for following expression */
+ f = (uInt)(q - s->window) < c->sub.copy.dist ?
+ s->end - (c->sub.copy.dist - (q - s->window)) :
+ q - c->sub.copy.dist;
+#else
+ f = q - c->sub.copy.dist;
+ if ((uInt)(q - s->window) < c->sub.copy.dist)
+ f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
+#endif
+ while (c->len)
+ {
+ NEEDOUT
+ OUTBYTE(*f++)
+ if (f == s->end)
+ f = s->window;
+ c->len--;
+ }
+ c->mode = START;
+ break;
+ case LIT: /* o: got literal, waiting for output space */
+ NEEDOUT
+ OUTBYTE(c->sub.lit)
+ c->mode = START;
+ break;
+ case WASH: /* o: got eob, possibly more output */
+ if (k > 7) /* return unused byte, if any */
+ {
+ Assert(k < 16, "inflate_codes grabbed too many bytes")
+ k -= 8;
+ n++;
+ p--; /* can always return one */
+ }
+ FLUSH
+ if (s->read != s->write)
+ LEAVE
+ c->mode = END;
+ case END:
+ r = Z_STREAM_END;
+ LEAVE
+ case BADCODE: /* x: got error */
+ r = Z_DATA_ERROR;
+ LEAVE
+ default:
+ r = Z_STREAM_ERROR;
+ LEAVE
+ }
+#ifdef NEED_DUMMY_RETURN
+ return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
+#endif
+}
+
+
+void inflate_codes_free(c, z)
+inflate_codes_statef *c;
+z_streamp z;
+{
+ ZFREE(z, c);
+ Tracev((stderr, "inflate: codes free\n"));
+}
diff --git a/osframework/source/ImageLib/zlib/infcodes.h b/osframework/source/ImageLib/zlib/infcodes.h
new file mode 100644
index 0000000..7957735
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infcodes.h
@@ -0,0 +1,27 @@
+/* infcodes.h -- header to use infcodes.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+struct inflate_codes_state;
+typedef struct inflate_codes_state FAR inflate_codes_statef;
+
+extern inflate_codes_statef *inflate_codes_new OF((
+ uInt, uInt,
+ inflate_huft *, inflate_huft *,
+ z_streamp ));
+
+extern int inflate_codes OF((
+ inflate_blocks_statef *,
+ z_streamp ,
+ int));
+
+extern void inflate_codes_free OF((
+ inflate_codes_statef *,
+ z_streamp ));
+
diff --git a/osframework/source/ImageLib/zlib/inffast.c b/osframework/source/ImageLib/zlib/inffast.c
new file mode 100644
index 0000000..641ccdc
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inffast.c
@@ -0,0 +1,170 @@
+/* inffast.c -- process literals and length/distance pairs fast
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "infblock.h"
+#include "infcodes.h"
+#include "infutil.h"
+#include "inffast.h"
+
+struct inflate_codes_state {int dummy;}; /* for buggy compilers */
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+/* macros for bit input with no checking and for returning unused bytes */
+#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
+#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
+
+/* Called with number of bytes left to write in window at least 258
+ (the maximum string length) and number of input bytes available
+ at least ten. The ten bytes are six bytes for the longest length/
+ distance pair plus four bytes for overloading the bit buffer. */
+
+int inflate_fast(bl, bd, tl, td, s, z)
+uInt bl, bd;
+inflate_huft *tl;
+inflate_huft *td; /* need separate declaration for Borland C++ */
+inflate_blocks_statef *s;
+z_streamp z;
+{
+ inflate_huft *t; /* temporary pointer */
+ uInt e; /* extra bits or operation */
+ uLong b; /* bit buffer */
+ uInt k; /* bits in bit buffer */
+ Bytef *p; /* input data pointer */
+ uInt n; /* bytes available there */
+ Bytef *q; /* output window write pointer */
+ uInt m; /* bytes to end of window or read pointer */
+ uInt ml; /* mask for literal/length tree */
+ uInt md; /* mask for distance tree */
+ uInt c; /* bytes to copy */
+ uInt d; /* distance back to copy from */
+ Bytef *r; /* copy source pointer */
+
+ /* load input, output, bit values */
+ LOAD
+
+ /* initialize masks */
+ ml = inflate_mask[bl];
+ md = inflate_mask[bd];
+
+ /* do until not enough input or output space for fast loop */
+ do { /* assume called with m >= 258 && n >= 10 */
+ /* get literal/length code */
+ GRABBITS(20) /* max bits for literal/length code */
+ if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
+ {
+ DUMPBITS(t->bits)
+ Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: * literal '%c'\n" :
+ "inflate: * literal 0x%02x\n", t->base));
+ *q++ = (Byte)t->base;
+ m--;
+ continue;
+ }
+ do {
+ DUMPBITS(t->bits)
+ if (e & 16)
+ {
+ /* get extra bits for length */
+ e &= 15;
+ c = t->base + ((uInt)b & inflate_mask[e]);
+ DUMPBITS(e)
+ Tracevv((stderr, "inflate: * length %u\n", c));
+
+ /* decode distance base of block to copy */
+ GRABBITS(15); /* max bits for distance code */
+ e = (t = td + ((uInt)b & md))->exop;
+ do {
+ DUMPBITS(t->bits)
+ if (e & 16)
+ {
+ /* get extra bits to add to distance base */
+ e &= 15;
+ GRABBITS(e) /* get extra bits (up to 13) */
+ d = t->base + ((uInt)b & inflate_mask[e]);
+ DUMPBITS(e)
+ Tracevv((stderr, "inflate: * distance %u\n", d));
+
+ /* do the copy */
+ m -= c;
+ if ((uInt)(q - s->window) >= d) /* offset before dest */
+ { /* just copy */
+ r = q - d;
+ *q++ = *r++; c--; /* minimum count is three, */
+ *q++ = *r++; c--; /* so unroll loop a little */
+ }
+ else /* else offset after destination */
+ {
+ e = d - (uInt)(q - s->window); /* bytes from offset to end */
+ r = s->end - e; /* pointer to offset */
+ if (c > e) /* if source crosses, */
+ {
+ c -= e; /* copy to end of window */
+ do {
+ *q++ = *r++;
+ } while (--e);
+ r = s->window; /* copy rest from start of window */
+ }
+ }
+ do { /* copy all or what's left */
+ *q++ = *r++;
+ } while (--c);
+ break;
+ }
+ else if ((e & 64) == 0)
+ {
+ t += t->base;
+ e = (t += ((uInt)b & inflate_mask[e]))->exop;
+ }
+ else
+ {
+ z->msg = (char*)"invalid distance code";
+ UNGRAB
+ UPDATE
+ return Z_DATA_ERROR;
+ }
+ } while (1);
+ break;
+ }
+ if ((e & 64) == 0)
+ {
+ t += t->base;
+ if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
+ {
+ DUMPBITS(t->bits)
+ Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
+ "inflate: * literal '%c'\n" :
+ "inflate: * literal 0x%02x\n", t->base));
+ *q++ = (Byte)t->base;
+ m--;
+ break;
+ }
+ }
+ else if (e & 32)
+ {
+ Tracevv((stderr, "inflate: * end of block\n"));
+ UNGRAB
+ UPDATE
+ return Z_STREAM_END;
+ }
+ else
+ {
+ z->msg = (char*)"invalid literal/length code";
+ UNGRAB
+ UPDATE
+ return Z_DATA_ERROR;
+ }
+ } while (1);
+ } while (m >= 258 && n >= 10);
+
+ /* not enough input or output--restore pointers and return */
+ UNGRAB
+ UPDATE
+ return Z_OK;
+}
diff --git a/osframework/source/ImageLib/zlib/inffast.h b/osframework/source/ImageLib/zlib/inffast.h
new file mode 100644
index 0000000..c6d96f4
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inffast.h
@@ -0,0 +1,17 @@
+/* inffast.h -- header to use inffast.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+extern int inflate_fast OF((
+ uInt,
+ uInt,
+ inflate_huft *,
+ inflate_huft *,
+ inflate_blocks_statef *,
+ z_streamp ));
diff --git a/osframework/source/ImageLib/zlib/inffixed.h b/osframework/source/ImageLib/zlib/inffixed.h
new file mode 100644
index 0000000..e997507
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inffixed.h
@@ -0,0 +1,151 @@
+/* inffixed.h -- table for decoding fixed codes
+ * Generated automatically by the maketree.c program
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+local uInt fixed_bl = 9;
+local uInt fixed_bd = 5;
+local inflate_huft fixed_tl[] = {
+ {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
+ {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
+ {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
+ {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
+ {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
+ {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
+ {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
+ {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
+ {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
+ {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
+ {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
+ {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
+ {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
+ {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
+ {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
+ {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
+ {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
+ {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
+ {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
+ {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
+ {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
+ {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
+ {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
+ {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
+ {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
+ {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
+ {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
+ {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
+ {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
+ {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
+ {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
+ {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
+ {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
+ {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
+ {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
+ {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
+ {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
+ {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
+ {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
+ {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
+ {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
+ {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
+ {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
+ {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
+ {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
+ {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
+ {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
+ {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
+ {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
+ {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
+ {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
+ {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
+ {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
+ {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
+ {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
+ {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
+ {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
+ {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
+ {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
+ {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
+ {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
+ {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
+ {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
+ {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
+ {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
+ {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
+ {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
+ {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
+ {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
+ {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
+ {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
+ {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
+ {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
+ {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
+ {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
+ {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
+ {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
+ {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
+ {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
+ {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
+ {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
+ {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
+ {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
+ {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
+ {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
+ {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
+ {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
+ {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
+ {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
+ {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
+ {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
+ {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
+ {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
+ {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
+ {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
+ {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
+ {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
+ {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
+ {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
+ {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
+ {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
+ {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
+ {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
+ {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
+ {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
+ {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
+ {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
+ {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
+ {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
+ {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
+ {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
+ {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
+ {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
+ {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
+ {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
+ {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
+ {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
+ {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
+ {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
+ {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
+ {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
+ {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
+ {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
+ {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
+ {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
+ };
+local inflate_huft fixed_td[] = {
+ {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
+ {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
+ {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
+ {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
+ {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
+ {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
+ {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
+ {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
+ };
diff --git a/osframework/source/ImageLib/zlib/inflate.c b/osframework/source/ImageLib/zlib/inflate.c
new file mode 100644
index 0000000..103fc2f
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inflate.c
@@ -0,0 +1,366 @@
+/* inflate.c -- zlib interface to inflate modules
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "infblock.h"
+
+struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
+
+typedef enum {
+ METHOD, /* waiting for method byte */
+ FLAG, /* waiting for flag byte */
+ DICT4, /* four dictionary check bytes to go */
+ DICT3, /* three dictionary check bytes to go */
+ DICT2, /* two dictionary check bytes to go */
+ DICT1, /* one dictionary check byte to go */
+ DICT0, /* waiting for inflateSetDictionary */
+ BLOCKS, /* decompressing blocks */
+ CHECK4, /* four check bytes to go */
+ CHECK3, /* three check bytes to go */
+ CHECK2, /* two check bytes to go */
+ CHECK1, /* one check byte to go */
+ DONE, /* finished check, done */
+ BAD} /* got an error--stay here */
+inflate_mode;
+
+/* inflate private state */
+struct internal_state {
+
+ /* mode */
+ inflate_mode mode; /* current inflate mode */
+
+ /* mode dependent information */
+ union {
+ uInt method; /* if FLAGS, method byte */
+ struct {
+ uLong was; /* computed check value */
+ uLong need; /* stream check value */
+ } check; /* if CHECK, check values to compare */
+ uInt marker; /* if BAD, inflateSync's marker bytes count */
+ } sub; /* submode */
+
+ /* mode independent information */
+ int nowrap; /* flag for no wrapper */
+ uInt wbits; /* log2(window size) (8..15, defaults to 15) */
+ inflate_blocks_statef
+ *blocks; /* current inflate_blocks state */
+
+};
+
+
+int ZEXPORT inflateReset(z)
+z_streamp z;
+{
+ if (z == Z_NULL || z->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ z->total_in = z->total_out = 0;
+ z->msg = Z_NULL;
+ z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
+ inflate_blocks_reset(z->state->blocks, z, Z_NULL);
+ Tracev((stderr, "inflate: reset\n"));
+ return Z_OK;
+}
+
+
+int ZEXPORT inflateEnd(z)
+z_streamp z;
+{
+ if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
+ return Z_STREAM_ERROR;
+ if (z->state->blocks != Z_NULL)
+ inflate_blocks_free(z->state->blocks, z);
+ ZFREE(z, z->state);
+ z->state = Z_NULL;
+ Tracev((stderr, "inflate: end\n"));
+ return Z_OK;
+}
+
+
+int ZEXPORT inflateInit2_(z, w, version, stream_size)
+z_streamp z;
+int w;
+const char *version;
+int stream_size;
+{
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != sizeof(z_stream))
+ return Z_VERSION_ERROR;
+
+ /* initialize state */
+ if (z == Z_NULL)
+ return Z_STREAM_ERROR;
+ z->msg = Z_NULL;
+ if (z->zalloc == Z_NULL)
+ {
+ z->zalloc = zcalloc;
+ z->opaque = (voidpf)0;
+ }
+ if (z->zfree == Z_NULL) z->zfree = zcfree;
+ if ((z->state = (struct internal_state FAR *)
+ ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
+ return Z_MEM_ERROR;
+ z->state->blocks = Z_NULL;
+
+ /* handle undocumented nowrap option (no zlib header or check) */
+ z->state->nowrap = 0;
+ if (w < 0)
+ {
+ w = - w;
+ z->state->nowrap = 1;
+ }
+
+ /* set window size */
+ if (w < 8 || w > 15)
+ {
+ inflateEnd(z);
+ return Z_STREAM_ERROR;
+ }
+ z->state->wbits = (uInt)w;
+
+ /* create inflate_blocks state */
+ if ((z->state->blocks =
+ inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
+ == Z_NULL)
+ {
+ inflateEnd(z);
+ return Z_MEM_ERROR;
+ }
+ Tracev((stderr, "inflate: allocated\n"));
+
+ /* reset state */
+ inflateReset(z);
+ return Z_OK;
+}
+
+
+int ZEXPORT inflateInit_(z, version, stream_size)
+z_streamp z;
+const char *version;
+int stream_size;
+{
+ return inflateInit2_(z, DEF_WBITS, version, stream_size);
+}
+
+
+#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
+#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
+
+int ZEXPORT inflate(z, f)
+z_streamp z;
+int f;
+{
+ int r;
+ uInt b;
+
+ if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
+ return Z_STREAM_ERROR;
+ f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
+ r = Z_BUF_ERROR;
+ while (1) switch (z->state->mode)
+ {
+ case METHOD:
+ NEEDBYTE
+ if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
+ {
+ z->state->mode = BAD;
+ z->msg = (char*)"unknown compression method";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
+ {
+ z->state->mode = BAD;
+ z->msg = (char*)"invalid window size";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ z->state->mode = FLAG;
+ case FLAG:
+ NEEDBYTE
+ b = NEXTBYTE;
+ if (((z->state->sub.method << 8) + b) % 31)
+ {
+ z->state->mode = BAD;
+ z->msg = (char*)"incorrect header check";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ Tracev((stderr, "inflate: zlib header ok\n"));
+ if (!(b & PRESET_DICT))
+ {
+ z->state->mode = BLOCKS;
+ break;
+ }
+ z->state->mode = DICT4;
+ case DICT4:
+ NEEDBYTE
+ z->state->sub.check.need = (uLong)NEXTBYTE << 24;
+ z->state->mode = DICT3;
+ case DICT3:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE << 16;
+ z->state->mode = DICT2;
+ case DICT2:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE << 8;
+ z->state->mode = DICT1;
+ case DICT1:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE;
+ z->adler = z->state->sub.check.need;
+ z->state->mode = DICT0;
+ return Z_NEED_DICT;
+ case DICT0:
+ z->state->mode = BAD;
+ z->msg = (char*)"need dictionary";
+ z->state->sub.marker = 0; /* can try inflateSync */
+ return Z_STREAM_ERROR;
+ case BLOCKS:
+ r = inflate_blocks(z->state->blocks, z, r);
+ if (r == Z_DATA_ERROR)
+ {
+ z->state->mode = BAD;
+ z->state->sub.marker = 0; /* can try inflateSync */
+ break;
+ }
+ if (r == Z_OK)
+ r = f;
+ if (r != Z_STREAM_END)
+ return r;
+ r = f;
+ inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
+ if (z->state->nowrap)
+ {
+ z->state->mode = DONE;
+ break;
+ }
+ z->state->mode = CHECK4;
+ case CHECK4:
+ NEEDBYTE
+ z->state->sub.check.need = (uLong)NEXTBYTE << 24;
+ z->state->mode = CHECK3;
+ case CHECK3:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE << 16;
+ z->state->mode = CHECK2;
+ case CHECK2:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE << 8;
+ z->state->mode = CHECK1;
+ case CHECK1:
+ NEEDBYTE
+ z->state->sub.check.need += (uLong)NEXTBYTE;
+
+ if (z->state->sub.check.was != z->state->sub.check.need)
+ {
+ z->state->mode = BAD;
+ z->msg = (char*)"incorrect data check";
+ z->state->sub.marker = 5; /* can't try inflateSync */
+ break;
+ }
+ Tracev((stderr, "inflate: zlib check ok\n"));
+ z->state->mode = DONE;
+ case DONE:
+ return Z_STREAM_END;
+ case BAD:
+ return Z_DATA_ERROR;
+ default:
+ return Z_STREAM_ERROR;
+ }
+#ifdef NEED_DUMMY_RETURN
+ return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
+#endif
+}
+
+
+int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
+z_streamp z;
+const Bytef *dictionary;
+uInt dictLength;
+{
+ uInt length = dictLength;
+
+ if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
+ return Z_STREAM_ERROR;
+
+ if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
+ z->adler = 1L;
+
+ if (length >= ((uInt)1<<z->state->wbits))
+ {
+ length = (1<<z->state->wbits)-1;
+ dictionary += dictLength - length;
+ }
+ inflate_set_dictionary(z->state->blocks, dictionary, length);
+ z->state->mode = BLOCKS;
+ return Z_OK;
+}
+
+
+int ZEXPORT inflateSync(z)
+z_streamp z;
+{
+ uInt n; /* number of bytes to look at */
+ Bytef *p; /* pointer to bytes */
+ uInt m; /* number of marker bytes found in a row */
+ uLong r, w; /* temporaries to save total_in and total_out */
+
+ /* set up */
+ if (z == Z_NULL || z->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ if (z->state->mode != BAD)
+ {
+ z->state->mode = BAD;
+ z->state->sub.marker = 0;
+ }
+ if ((n = z->avail_in) == 0)
+ return Z_BUF_ERROR;
+ p = z->next_in;
+ m = z->state->sub.marker;
+
+ /* search */
+ while (n && m < 4)
+ {
+ static const Byte mark[4] = {0, 0, 0xff, 0xff};
+ if (*p == mark[m])
+ m++;
+ else if (*p)
+ m = 0;
+ else
+ m = 4 - m;
+ p++, n--;
+ }
+
+ /* restore */
+ z->total_in += p - z->next_in;
+ z->next_in = p;
+ z->avail_in = n;
+ z->state->sub.marker = m;
+
+ /* return no joy or set up to restart on a new block */
+ if (m != 4)
+ return Z_DATA_ERROR;
+ r = z->total_in; w = z->total_out;
+ inflateReset(z);
+ z->total_in = r; z->total_out = w;
+ z->state->mode = BLOCKS;
+ return Z_OK;
+}
+
+
+/* Returns true if inflate is currently at the end of a block generated
+ * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
+ * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
+ * but removes the length bytes of the resulting empty stored block. When
+ * decompressing, PPP checks that at the end of input packet, inflate is
+ * waiting for these length bytes.
+ */
+int ZEXPORT inflateSyncPoint(z)
+z_streamp z;
+{
+ if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
+ return Z_STREAM_ERROR;
+ return inflate_blocks_sync_point(z->state->blocks);
+}
diff --git a/osframework/source/ImageLib/zlib/inftrees.c b/osframework/source/ImageLib/zlib/inftrees.c
new file mode 100644
index 0000000..d21c360
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inftrees.c
@@ -0,0 +1,455 @@
+/* inftrees.c -- generate Huffman trees for efficient decoding
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+
+#if !defined(BUILDFIXED) && !defined(STDC)
+# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
+#endif
+
+const char inflate_copyright[] =
+ " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+struct internal_state {int dummy;}; /* for buggy compilers */
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+
+local int huft_build OF((
+ uIntf *, /* code lengths in bits */
+ uInt, /* number of codes */
+ uInt, /* number of "simple" codes */
+ const uIntf *, /* list of base values for non-simple codes */
+ const uIntf *, /* list of extra bits for non-simple codes */
+ inflate_huft * FAR*,/* result: starting table */
+ uIntf *, /* maximum lookup bits (returns actual) */
+ inflate_huft *, /* space for trees */
+ uInt *, /* hufts used in space */
+ uIntf * )); /* space for values */
+
+/* Tables for deflate from PKZIP's appnote.txt. */
+local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
+ /* see note #13 above about 258 */
+local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
+local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+ 8193, 12289, 16385, 24577};
+local const uInt cpdext[30] = { /* Extra bits for distance codes */
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
+ 12, 12, 13, 13};
+
+/*
+ Huffman code decoding is performed using a multi-level table lookup.
+ The fastest way to decode is to simply build a lookup table whose
+ size is determined by the longest code. However, the time it takes
+ to build this table can also be a factor if the data being decoded
+ is not very long. The most common codes are necessarily the
+ shortest codes, so those codes dominate the decoding time, and hence
+ the speed. The idea is you can have a shorter table that decodes the
+ shorter, more probable codes, and then point to subsidiary tables for
+ the longer codes. The time it costs to decode the longer codes is
+ then traded against the time it takes to make longer tables.
+
+ This results of this trade are in the variables lbits and dbits
+ below. lbits is the number of bits the first level table for literal/
+ length codes can decode in one step, and dbits is the same thing for
+ the distance codes. Subsequent tables are also less than or equal to
+ those sizes. These values may be adjusted either when all of the
+ codes are shorter than that, in which case the longest code length in
+ bits is used, or when the shortest code is *longer* than the requested
+ table size, in which case the length of the shortest code in bits is
+ used.
+
+ There are two different values for the two tables, since they code a
+ different number of possibilities each. The literal/length table
+ codes 286 possible values, or in a flat code, a little over eight
+ bits. The distance table codes 30 possible values, or a little less
+ than five bits, flat. The optimum values for speed end up being
+ about one bit more than those, so lbits is 8+1 and dbits is 5+1.
+ The optimum values may differ though from machine to machine, and
+ possibly even between compilers. Your mileage may vary.
+ */
+
+
+/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
+#define BMAX 15 /* maximum bit length of any code */
+
+local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
+uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
+uInt n; /* number of codes (assumed <= 288) */
+uInt s; /* number of simple-valued codes (0..s-1) */
+const uIntf *d; /* list of base values for non-simple codes */
+const uIntf *e; /* list of extra bits for non-simple codes */
+inflate_huft * FAR *t; /* result: starting table */
+uIntf *m; /* maximum lookup bits, returns actual */
+inflate_huft *hp; /* space for trees */
+uInt *hn; /* hufts used in space */
+uIntf *v; /* working area: values in order of bit length */
+/* Given a list of code lengths and a maximum table size, make a set of
+ tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
+ if the given code set is incomplete (the tables are still built in this
+ case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
+ lengths), or Z_MEM_ERROR if not enough memory. */
+{
+
+ uInt a; /* counter for codes of length k */
+ uInt c[BMAX+1]; /* bit length count table */
+ uInt f; /* i repeats in table every f entries */
+ int g; /* maximum code length */
+ int h; /* table level */
+ register uInt i; /* counter, current code */
+ register uInt j; /* counter */
+ register int k; /* number of bits in current code */
+ int l; /* bits per table (returned in m) */
+ uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
+ register uIntf *p; /* pointer into c[], b[], or v[] */
+ inflate_huft *q; /* points to current table */
+ struct inflate_huft_s r; /* table entry for structure assignment */
+ inflate_huft *u[BMAX]; /* table stack */
+ register int w; /* bits before this table == (l * h) */
+ uInt x[BMAX+1]; /* bit offsets, then code stack */
+ uIntf *xp; /* pointer into x */
+ int y; /* number of dummy codes added */
+ uInt z; /* number of entries in current table */
+
+
+ /* Generate counts for each bit length */
+ p = c;
+#define C0 *p++ = 0;
+#define C2 C0 C0 C0 C0
+#define C4 C2 C2 C2 C2
+ C4 /* clear c[]--assume BMAX+1 is 16 */
+ p = b; i = n;
+ do {
+ c[*p++]++; /* assume all entries <= BMAX */
+ } while (--i);
+ if (c[0] == n) /* null input--all zero length codes */
+ {
+ *t = (inflate_huft *)Z_NULL;
+ *m = 0;
+ return Z_OK;
+ }
+
+
+ /* Find minimum and maximum length, bound *m by those */
+ l = *m;
+ for (j = 1; j <= BMAX; j++)
+ if (c[j])
+ break;
+ k = j; /* minimum code length */
+ if ((uInt)l < j)
+ l = j;
+ for (i = BMAX; i; i--)
+ if (c[i])
+ break;
+ g = i; /* maximum code length */
+ if ((uInt)l > i)
+ l = i;
+ *m = l;
+
+
+ /* Adjust last length count to fill out codes, if needed */
+ for (y = 1 << j; j < i; j++, y <<= 1)
+ if ((y -= c[j]) < 0)
+ return Z_DATA_ERROR;
+ if ((y -= c[i]) < 0)
+ return Z_DATA_ERROR;
+ c[i] += y;
+
+
+ /* Generate starting offsets into the value table for each length */
+ x[1] = j = 0;
+ p = c + 1; xp = x + 2;
+ while (--i) { /* note that i == g from above */
+ *xp++ = (j += *p++);
+ }
+
+
+ /* Make a table of values in order of bit lengths */
+ p = b; i = 0;
+ do {
+ if ((j = *p++) != 0)
+ v[x[j]++] = i;
+ } while (++i < n);
+ n = x[g]; /* set n to length of v */
+
+
+ /* Generate the Huffman codes and for each, make the table entries */
+ x[0] = i = 0; /* first Huffman code is zero */
+ p = v; /* grab values in bit order */
+ h = -1; /* no tables yet--level -1 */
+ w = -l; /* bits decoded == (l * h) */
+ u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
+ q = (inflate_huft *)Z_NULL; /* ditto */
+ z = 0; /* ditto */
+
+ /* go through the bit lengths (k already is bits in shortest code) */
+ for (; k <= g; k++)
+ {
+ a = c[k];
+ while (a--)
+ {
+ /* here i is the Huffman code of length k bits for value *p */
+ /* make tables up to required level */
+ while (k > w + l)
+ {
+ h++;
+ w += l; /* previous table always l bits */
+
+ /* compute minimum size table less than or equal to l bits */
+ z = g - w;
+ z = z > (uInt)l ? l : z; /* table size upper limit */
+ if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
+ { /* too few codes for k-w bit table */
+ f -= a + 1; /* deduct codes from patterns left */
+ xp = c + k;
+ if (j < z)
+ while (++j < z) /* try smaller tables up to z bits */
+ {
+ if ((f <<= 1) <= *++xp)
+ break; /* enough codes to use up j bits */
+ f -= *xp; /* else deduct codes from patterns */
+ }
+ }
+ z = 1 << j; /* table entries for j-bit table */
+
+ /* allocate new table */
+ if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
+ return Z_MEM_ERROR; /* not enough memory */
+ u[h] = q = hp + *hn;
+ *hn += z;
+
+ /* connect to last table, if there is one */
+ if (h)
+ {
+ x[h] = i; /* save pattern for backing up */
+ r.bits = (Byte)l; /* bits to dump before this table */
+ r.exop = (Byte)j; /* bits in this table */
+ j = i >> (w - l);
+ r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
+ u[h-1][j] = r; /* connect to last table */
+ }
+ else
+ *t = q; /* first table is returned result */
+ }
+
+ /* set up table entry in r */
+ r.bits = (Byte)(k - w);
+ if (p >= v + n)
+ r.exop = 128 + 64; /* out of values--invalid code */
+ else if (*p < s)
+ {
+ r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
+ r.base = *p++; /* simple code is just the value */
+ }
+ else
+ {
+ r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
+ r.base = d[*p++ - s];
+ }
+
+ /* fill code-like entries with r */
+ f = 1 << (k - w);
+ for (j = i >> w; j < z; j += f)
+ q[j] = r;
+
+ /* backwards increment the k-bit code i */
+ for (j = 1 << (k - 1); i & j; j >>= 1)
+ i ^= j;
+ i ^= j;
+
+ /* backup over finished tables */
+ mask = (1 << w) - 1; /* needed on HP, cc -O bug */
+ while ((i & mask) != x[h])
+ {
+ h--; /* don't need to update q */
+ w -= l;
+ mask = (1 << w) - 1;
+ }
+ }
+ }
+
+
+ /* Return Z_BUF_ERROR if we were given an incomplete table */
+ return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
+}
+
+
+int inflate_trees_bits(c, bb, tb, hp, z)
+uIntf *c; /* 19 code lengths */
+uIntf *bb; /* bits tree desired/actual depth */
+inflate_huft * FAR *tb; /* bits tree result */
+inflate_huft *hp; /* space for trees */
+z_streamp z; /* for messages */
+{
+ int r;
+ uInt hn = 0; /* hufts used in space */
+ uIntf *v; /* work area for huft_build */
+
+ if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
+ return Z_MEM_ERROR;
+ r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
+ tb, bb, hp, &hn, v);
+ if (r == Z_DATA_ERROR)
+ z->msg = (char*)"oversubscribed dynamic bit lengths tree";
+ else if (r == Z_BUF_ERROR || *bb == 0)
+ {
+ z->msg = (char*)"incomplete dynamic bit lengths tree";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE(z, v);
+ return r;
+}
+
+
+int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
+uInt nl; /* number of literal/length codes */
+uInt nd; /* number of distance codes */
+uIntf *c; /* that many (total) code lengths */
+uIntf *bl; /* literal desired/actual bit depth */
+uIntf *bd; /* distance desired/actual bit depth */
+inflate_huft * FAR *tl; /* literal/length tree result */
+inflate_huft * FAR *td; /* distance tree result */
+inflate_huft *hp; /* space for trees */
+z_streamp z; /* for messages */
+{
+ int r;
+ uInt hn = 0; /* hufts used in space */
+ uIntf *v; /* work area for huft_build */
+
+ /* allocate work area */
+ if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
+ return Z_MEM_ERROR;
+
+ /* build literal/length tree */
+ r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
+ if (r != Z_OK || *bl == 0)
+ {
+ if (r == Z_DATA_ERROR)
+ z->msg = (char*)"oversubscribed literal/length tree";
+ else if (r != Z_MEM_ERROR)
+ {
+ z->msg = (char*)"incomplete literal/length tree";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE(z, v);
+ return r;
+ }
+
+ /* build distance tree */
+ r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
+ if (r != Z_OK || (*bd == 0 && nl > 257))
+ {
+ if (r == Z_DATA_ERROR)
+ z->msg = (char*)"oversubscribed distance tree";
+ else if (r == Z_BUF_ERROR) {
+#ifdef PKZIP_BUG_WORKAROUND
+ r = Z_OK;
+ }
+#else
+ z->msg = (char*)"incomplete distance tree";
+ r = Z_DATA_ERROR;
+ }
+ else if (r != Z_MEM_ERROR)
+ {
+ z->msg = (char*)"empty distance tree with lengths";
+ r = Z_DATA_ERROR;
+ }
+ ZFREE(z, v);
+ return r;
+#endif
+ }
+
+ /* done */
+ ZFREE(z, v);
+ return Z_OK;
+}
+
+
+/* build fixed tables only once--keep them here */
+#ifdef BUILDFIXED
+local int fixed_built = 0;
+#define FIXEDH 544 /* number of hufts used by fixed tables */
+local inflate_huft fixed_mem[FIXEDH];
+local uInt fixed_bl;
+local uInt fixed_bd;
+local inflate_huft *fixed_tl;
+local inflate_huft *fixed_td;
+#else
+#include "inffixed.h"
+#endif
+
+
+int inflate_trees_fixed(bl, bd, tl, td, z)
+uIntf *bl; /* literal desired/actual bit depth */
+uIntf *bd; /* distance desired/actual bit depth */
+inflate_huft * FAR *tl; /* literal/length tree result */
+inflate_huft * FAR *td; /* distance tree result */
+z_streamp z; /* for memory allocation */
+{
+#ifdef BUILDFIXED
+ /* build fixed tables if not already */
+ if (!fixed_built)
+ {
+ int k; /* temporary variable */
+ uInt f = 0; /* number of hufts used in fixed_mem */
+ uIntf *c; /* length list for huft_build */
+ uIntf *v; /* work area for huft_build */
+
+ /* allocate memory */
+ if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
+ return Z_MEM_ERROR;
+ if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
+ {
+ ZFREE(z, c);
+ return Z_MEM_ERROR;
+ }
+
+ /* literal table */
+ for (k = 0; k < 144; k++)
+ c[k] = 8;
+ for (; k < 256; k++)
+ c[k] = 9;
+ for (; k < 280; k++)
+ c[k] = 7;
+ for (; k < 288; k++)
+ c[k] = 8;
+ fixed_bl = 9;
+ huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
+ fixed_mem, &f, v);
+
+ /* distance table */
+ for (k = 0; k < 30; k++)
+ c[k] = 5;
+ fixed_bd = 5;
+ huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
+ fixed_mem, &f, v);
+
+ /* done */
+ ZFREE(z, v);
+ ZFREE(z, c);
+ fixed_built = 1;
+ }
+#endif
+ *bl = fixed_bl;
+ *bd = fixed_bd;
+ *tl = fixed_tl;
+ *td = fixed_td;
+ return Z_OK;
+}
diff --git a/osframework/source/ImageLib/zlib/inftrees.h b/osframework/source/ImageLib/zlib/inftrees.h
new file mode 100644
index 0000000..8388fb8
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/inftrees.h
@@ -0,0 +1,58 @@
+/* inftrees.h -- header to use inftrees.c
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* Huffman code lookup table entry--this entry is four bytes for machines
+ that have 16-bit pointers (e.g. PC's in the small or medium model). */
+
+typedef struct inflate_huft_s FAR inflate_huft;
+
+struct inflate_huft_s {
+ union {
+ struct {
+ Byte Exop; /* number of extra bits or operation */
+ Byte Bits; /* number of bits in this code or subcode */
+ } what;
+ uInt pad; /* pad structure to a power of 2 (4 bytes for */
+ } word; /* 16-bit, 8 bytes for 32-bit int's) */
+ uInt base; /* literal, length base, distance base,
+ or table offset */
+};
+
+/* Maximum size of dynamic tree. The maximum found in a long but non-
+ exhaustive search was 1004 huft structures (850 for length/literals
+ and 154 for distances, the latter actually the result of an
+ exhaustive search). The actual maximum is not known, but the
+ value below is more than safe. */
+#define MANY 1440
+
+extern int inflate_trees_bits OF((
+ uIntf *, /* 19 code lengths */
+ uIntf *, /* bits tree desired/actual depth */
+ inflate_huft * FAR *, /* bits tree result */
+ inflate_huft *, /* space for trees */
+ z_streamp)); /* for messages */
+
+extern int inflate_trees_dynamic OF((
+ uInt, /* number of literal/length codes */
+ uInt, /* number of distance codes */
+ uIntf *, /* that many (total) code lengths */
+ uIntf *, /* literal desired/actual bit depth */
+ uIntf *, /* distance desired/actual bit depth */
+ inflate_huft * FAR *, /* literal/length tree result */
+ inflate_huft * FAR *, /* distance tree result */
+ inflate_huft *, /* space for trees */
+ z_streamp)); /* for messages */
+
+extern int inflate_trees_fixed OF((
+ uIntf *, /* literal desired/actual bit depth */
+ uIntf *, /* distance desired/actual bit depth */
+ inflate_huft * FAR *, /* literal/length tree result */
+ inflate_huft * FAR *, /* distance tree result */
+ z_streamp)); /* for memory allocation */
diff --git a/osframework/source/ImageLib/zlib/infutil.c b/osframework/source/ImageLib/zlib/infutil.c
new file mode 100644
index 0000000..16b2acc
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infutil.c
@@ -0,0 +1,87 @@
+/* inflate_util.c -- data and routines common to blocks and codes
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "infblock.h"
+#include "inftrees.h"
+#include "infcodes.h"
+#include "infutil.h"
+
+struct inflate_codes_state {int dummy;}; /* for buggy compilers */
+
+/* And'ing with mask[n] masks the lower n bits */
+uInt inflate_mask[17] = {
+ 0x0000,
+ 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
+ 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+};
+
+
+/* copy as much as possible from the sliding window to the output area */
+int inflate_flush(s, z, r)
+inflate_blocks_statef *s;
+z_streamp z;
+int r;
+{
+ uInt n;
+ Bytef *p;
+ Bytef *q;
+
+ /* local copies of source and destination pointers */
+ p = z->next_out;
+ q = s->read;
+
+ /* compute number of bytes to copy as far as end of window */
+ n = (uInt)((q <= s->write ? s->write : s->end) - q);
+ if (n > z->avail_out) n = z->avail_out;
+ if (n && r == Z_BUF_ERROR) r = Z_OK;
+
+ /* update counters */
+ z->avail_out -= n;
+ z->total_out += n;
+
+ /* update check information */
+ if (s->checkfn != Z_NULL)
+ z->adler = s->check = (*s->checkfn)(s->check, q, n);
+
+ /* copy as far as end of window */
+ zmemcpy(p, q, n);
+ p += n;
+ q += n;
+
+ /* see if more to copy at beginning of window */
+ if (q == s->end)
+ {
+ /* wrap pointers */
+ q = s->window;
+ if (s->write == s->end)
+ s->write = s->window;
+
+ /* compute bytes to copy */
+ n = (uInt)(s->write - q);
+ if (n > z->avail_out) n = z->avail_out;
+ if (n && r == Z_BUF_ERROR) r = Z_OK;
+
+ /* update counters */
+ z->avail_out -= n;
+ z->total_out += n;
+
+ /* update check information */
+ if (s->checkfn != Z_NULL)
+ z->adler = s->check = (*s->checkfn)(s->check, q, n);
+
+ /* copy */
+ zmemcpy(p, q, n);
+ p += n;
+ q += n;
+ }
+
+ /* update pointers */
+ z->next_out = p;
+ s->read = q;
+
+ /* done */
+ return r;
+}
diff --git a/osframework/source/ImageLib/zlib/infutil.h b/osframework/source/ImageLib/zlib/infutil.h
new file mode 100644
index 0000000..5c61290
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/infutil.h
@@ -0,0 +1,98 @@
+/* infutil.h -- types and macros common to blocks and codes
+ * Copyright (C) 1995-1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+#ifndef _INFUTIL_H
+#define _INFUTIL_H
+
+typedef enum {
+ TYPE, /* get type bits (3, including end bit) */
+ LENS, /* get lengths for stored */
+ STORED, /* processing stored block */
+ TABLE, /* get table lengths */
+ BTREE, /* get bit lengths tree for a dynamic block */
+ DTREE, /* get length, distance trees for a dynamic block */
+ CODES, /* processing fixed or dynamic block */
+ DRY, /* output remaining window bytes */
+ DONE, /* finished last block, done */
+ BAD} /* got a data error--stuck here */
+inflate_block_mode;
+
+/* inflate blocks semi-private state */
+struct inflate_blocks_state {
+
+ /* mode */
+ inflate_block_mode mode; /* current inflate_block mode */
+
+ /* mode dependent information */
+ union {
+ uInt left; /* if STORED, bytes left to copy */
+ struct {
+ uInt table; /* table lengths (14 bits) */
+ uInt index; /* index into blens (or border) */
+ uIntf *blens; /* bit lengths of codes */
+ uInt bb; /* bit length tree depth */
+ inflate_huft *tb; /* bit length decoding tree */
+ } trees; /* if DTREE, decoding info for trees */
+ struct {
+ inflate_codes_statef
+ *codes;
+ } decode; /* if CODES, current state */
+ } sub; /* submode */
+ uInt last; /* true if this block is the last block */
+
+ /* mode independent information */
+ uInt bitk; /* bits in bit buffer */
+ uLong bitb; /* bit buffer */
+ inflate_huft *hufts; /* single malloc for tree space */
+ Bytef *window; /* sliding window */
+ Bytef *end; /* one byte after sliding window */
+ Bytef *read; /* window read pointer */
+ Bytef *write; /* window write pointer */
+ check_func checkfn; /* check function */
+ uLong check; /* check on output */
+
+};
+
+
+/* defines for inflate input/output */
+/* update pointers and return */
+#define UPDBITS {s->bitb=b;s->bitk=k;}
+#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
+#define UPDOUT {s->write=q;}
+#define UPDATE {UPDBITS UPDIN UPDOUT}
+#define LEAVE {UPDATE return inflate_flush(s,z,r);}
+/* get bytes and bits */
+#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
+#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
+#define NEXTBYTE (n--,*p++)
+#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
+#define DUMPBITS(j) {b>>=(j);k-=(j);}
+/* output bytes */
+#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
+#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
+#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
+#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
+#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
+#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
+/* load local pointers */
+#define LOAD {LOADIN LOADOUT}
+
+/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
+extern uInt inflate_mask[17];
+
+/* copy as much as possible from the sliding window to the output area */
+extern int inflate_flush OF((
+ inflate_blocks_statef *,
+ z_streamp ,
+ int));
+
+struct internal_state {int dummy;}; /* for buggy compilers */
+
+#endif
diff --git a/osframework/source/ImageLib/zlib/maketree.c b/osframework/source/ImageLib/zlib/maketree.c
new file mode 100644
index 0000000..c547fff
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/maketree.c
@@ -0,0 +1,85 @@
+/* maketree.c -- make inffixed.h table for decoding fixed codes
+ * Copyright (C) 1998 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* This program is included in the distribution for completeness.
+ You do not need to compile or run this program since inffixed.h
+ is already included in the distribution. To use this program
+ you need to compile zlib with BUILDFIXED defined and then compile
+ and link this program with the zlib library. Then the output of
+ this program can be piped to inffixed.h. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "zutil.h"
+#include "inftrees.h"
+
+/* simplify the use of the inflate_huft type with some defines */
+#define exop word.what.Exop
+#define bits word.what.Bits
+
+/* generate initialization table for an inflate_huft structure array */
+void maketree(uInt b, inflate_huft *t)
+{
+ int i, e;
+
+ i = 0;
+ while (1)
+ {
+ e = t[i].exop;
+ if (e && (e & (16+64)) == 0) /* table pointer */
+ {
+ fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
+ exit(1);
+ }
+ if (i % 4 == 0)
+ printf("\n ");
+ printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
+ if (++i == (1<<b))
+ break;
+ putchar(',');
+ }
+ puts("");
+}
+
+/* create the fixed tables in C initialization syntax */
+void main(void)
+{
+ int r;
+ uInt bl, bd;
+ inflate_huft *tl, *td;
+ z_stream z;
+
+ z.zalloc = zcalloc;
+ z.opaque = (voidpf)0;
+ z.zfree = zcfree;
+ r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
+ if (r)
+ {
+ fprintf(stderr, "inflate_trees_fixed error %d\n", r);
+ return;
+ }
+ puts("/* inffixed.h -- table for decoding fixed codes");
+ puts(" * Generated automatically by the maketree.c program");
+ puts(" */");
+ puts("");
+ puts("/* WARNING: this file should *not* be used by applications. It is");
+ puts(" part of the implementation of the compression library and is");
+ puts(" subject to change. Applications should only use zlib.h.");
+ puts(" */");
+ puts("");
+ printf("local uInt fixed_bl = %d;\n", bl);
+ printf("local uInt fixed_bd = %d;\n", bd);
+ printf("local inflate_huft fixed_tl[] = {");
+ maketree(bl, tl);
+ puts(" };");
+ printf("local inflate_huft fixed_td[] = {");
+ maketree(bd, td);
+ puts(" };");
+}
diff --git a/osframework/source/ImageLib/zlib/minigzip.c b/osframework/source/ImageLib/zlib/minigzip.c
new file mode 100644
index 0000000..2ef801a
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/minigzip.c
@@ -0,0 +1,320 @@
+/* minigzip.c -- simulate gzip using the zlib compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * minigzip is a minimal implementation of the gzip utility. This is
+ * only an example of using zlib and isn't meant to replace the
+ * full-featured gzip. No attempt is made to deal with file systems
+ * limiting names to 14 or 8+3 characters, etc... Error checking is
+ * very limited. So use minigzip only for testing; use gzip for the
+ * real thing. On MSDOS, use only on file names without extension
+ * or in pipe mode.
+ */
+
+/* @(#) $Id: minigzip.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include <stdio.h>
+#include "zlib.h"
+
+#ifdef STDC
+# include <string.h>
+# include <stdlib.h>
+#else
+ extern void exit OF((int));
+#endif
+
+#ifdef USE_MMAP
+# include <sys/types.h>
+# include <sys/mman.h>
+# include <sys/stat.h>
+#endif
+
+#if defined(MSDOS) || defined(OS2) || defined(WIN32)
+# include <fcntl.h>
+# include <io.h>
+# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+# define SET_BINARY_MODE(file)
+#endif
+
+#ifdef VMS
+# define unlink delete
+# define GZ_SUFFIX "-gz"
+#endif
+#ifdef RISCOS
+# define unlink remove
+# define GZ_SUFFIX "-gz"
+# define fileno(file) file->__file
+#endif
+#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fileno */
+#endif
+
+#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
+ extern int unlink OF((const char *));
+#endif
+
+#ifndef GZ_SUFFIX
+# define GZ_SUFFIX ".gz"
+#endif
+#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
+
+#define BUFLEN 16384
+#define MAX_NAME_LEN 1024
+
+#ifdef MAXSEG_64K
+# define local static
+ /* Needed for systems with limitation on stack size. */
+#else
+# define local
+#endif
+
+char *prog;
+
+void error OF((const char *msg));
+void gz_compress OF((FILE *in, gzFile out));
+#ifdef USE_MMAP
+int gz_compress_mmap OF((FILE *in, gzFile out));
+#endif
+void gz_uncompress OF((gzFile in, FILE *out));
+void file_compress OF((char *file, char *mode));
+void file_uncompress OF((char *file));
+int main OF((int argc, char *argv[]));
+
+/* ===========================================================================
+ * Display error message and exit
+ */
+void error(msg)
+ const char *msg;
+{
+ fprintf(stderr, "%s: %s\n", prog, msg);
+ exit(1);
+}
+
+/* ===========================================================================
+ * Compress input to output then close both files.
+ */
+
+void gz_compress(in, out)
+ FILE *in;
+ gzFile out;
+{
+ local char buf[BUFLEN];
+ int len;
+ int err;
+
+#ifdef USE_MMAP
+ /* Try first compressing with mmap. If mmap fails (minigzip used in a
+ * pipe), use the normal fread loop.
+ */
+ if (gz_compress_mmap(in, out) == Z_OK) return;
+#endif
+ for (;;) {
+ len = fread(buf, 1, sizeof(buf), in);
+ if (ferror(in)) {
+ perror("fread");
+ exit(1);
+ }
+ if (len == 0) break;
+
+ if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
+ }
+ fclose(in);
+ if (gzclose(out) != Z_OK) error("failed gzclose");
+}
+
+#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
+
+/* Try compressing the input file at once using mmap. Return Z_OK if
+ * if success, Z_ERRNO otherwise.
+ */
+int gz_compress_mmap(in, out)
+ FILE *in;
+ gzFile out;
+{
+ int len;
+ int err;
+ int ifd = fileno(in);
+ caddr_t buf; /* mmap'ed buffer for the entire input file */
+ off_t buf_len; /* length of the input file */
+ struct stat sb;
+
+ /* Determine the size of the file, needed for mmap: */
+ if (fstat(ifd, &sb) < 0) return Z_ERRNO;
+ buf_len = sb.st_size;
+ if (buf_len <= 0) return Z_ERRNO;
+
+ /* Now do the actual mmap: */
+ buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
+ if (buf == (caddr_t)(-1)) return Z_ERRNO;
+
+ /* Compress the whole file at once: */
+ len = gzwrite(out, (char *)buf, (unsigned)buf_len);
+
+ if (len != (int)buf_len) error(gzerror(out, &err));
+
+ munmap(buf, buf_len);
+ fclose(in);
+ if (gzclose(out) != Z_OK) error("failed gzclose");
+ return Z_OK;
+}
+#endif /* USE_MMAP */
+
+/* ===========================================================================
+ * Uncompress input to output then close both files.
+ */
+void gz_uncompress(in, out)
+ gzFile in;
+ FILE *out;
+{
+ local char buf[BUFLEN];
+ int len;
+ int err;
+
+ for (;;) {
+ len = gzread(in, buf, sizeof(buf));
+ if (len < 0) error (gzerror(in, &err));
+ if (len == 0) break;
+
+ if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
+ error("failed fwrite");
+ }
+ }
+ if (fclose(out)) error("failed fclose");
+
+ if (gzclose(in) != Z_OK) error("failed gzclose");
+}
+
+
+/* ===========================================================================
+ * Compress the given file: create a corresponding .gz file and remove the
+ * original.
+ */
+void file_compress(file, mode)
+ char *file;
+ char *mode;
+{
+ local char outfile[MAX_NAME_LEN];
+ FILE *in;
+ gzFile out;
+
+ strcpy(outfile, file);
+ strcat(outfile, GZ_SUFFIX);
+
+ in = fopen(file, "rb");
+ if (in == NULL) {
+ perror(file);
+ exit(1);
+ }
+ out = gzopen(outfile, mode);
+ if (out == NULL) {
+ fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
+ exit(1);
+ }
+ gz_compress(in, out);
+
+ unlink(file);
+}
+
+
+/* ===========================================================================
+ * Uncompress the given file and remove the original.
+ */
+void file_uncompress(file)
+ char *file;
+{
+ local char buf[MAX_NAME_LEN];
+ char *infile, *outfile;
+ FILE *out;
+ gzFile in;
+ int len = strlen(file);
+
+ strcpy(buf, file);
+
+ if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
+ infile = file;
+ outfile = buf;
+ outfile[len-3] = '\0';
+ } else {
+ outfile = file;
+ infile = buf;
+ strcat(infile, GZ_SUFFIX);
+ }
+ in = gzopen(infile, "rb");
+ if (in == NULL) {
+ fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
+ exit(1);
+ }
+ out = fopen(outfile, "wb");
+ if (out == NULL) {
+ perror(file);
+ exit(1);
+ }
+
+ gz_uncompress(in, out);
+
+ unlink(infile);
+}
+
+
+/* ===========================================================================
+ * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...]
+ * -d : decompress
+ * -f : compress with Z_FILTERED
+ * -h : compress with Z_HUFFMAN_ONLY
+ * -1 to -9 : compression level
+ */
+
+int main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int uncompr = 0;
+ gzFile file;
+ char outmode[20];
+
+ strcpy(outmode, "wb6 ");
+
+ prog = argv[0];
+ argc--, argv++;
+
+ while (argc > 0) {
+ if (strcmp(*argv, "-d") == 0)
+ uncompr = 1;
+ else if (strcmp(*argv, "-f") == 0)
+ outmode[3] = 'f';
+ else if (strcmp(*argv, "-h") == 0)
+ outmode[3] = 'h';
+ else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
+ (*argv)[2] == 0)
+ outmode[2] = (*argv)[1];
+ else
+ break;
+ argc--, argv++;
+ }
+ if (argc == 0) {
+ SET_BINARY_MODE(stdin);
+ SET_BINARY_MODE(stdout);
+ if (uncompr) {
+ file = gzdopen(fileno(stdin), "rb");
+ if (file == NULL) error("can't gzdopen stdin");
+ gz_uncompress(file, stdout);
+ } else {
+ file = gzdopen(fileno(stdout), outmode);
+ if (file == NULL) error("can't gzdopen stdout");
+ gz_compress(stdin, file);
+ }
+ } else {
+ do {
+ if (uncompr) {
+ file_uncompress(*argv);
+ } else {
+ file_compress(*argv, outmode);
+ }
+ } while (argv++, --argc);
+ }
+ exit(0);
+ return 0; /* to avoid warning */
+}
diff --git a/osframework/source/ImageLib/zlib/readme b/osframework/source/ImageLib/zlib/readme
new file mode 100644
index 0000000..f9ae676
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/readme
@@ -0,0 +1,148 @@
+zlib 1.1.3 is a general purpose data compression library. All the code
+is thread safe. The data format used by the zlib library
+is described by RFCs (Request for Comments) 1950 to 1952 in the files
+ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
+format) and rfc1952.txt (gzip format). These documents are also available in
+other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+
+All functions of the compression library are documented in the file zlib.h
+(volunteer to write man pages welcome, contact jloup@gzip.org). A usage
+example of the library is given in the file example.c which also tests that
+the library is working correctly. Another example is given in the file
+minigzip.c. The compression library itself is composed of all source files
+except example.c and minigzip.c.
+
+To compile all files and run the test program, follow the instructions
+given at the top of Makefile. In short "make test; make install"
+should work for most machines. For Unix: "configure; make test; make install"
+For MSDOS, use one of the special makefiles such as Makefile.msc.
+For VMS, use Make_vms.com or descrip.mms.
+
+Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov>, or to
+Gilles Vollant <info@winimage.com> for the Windows DLL version.
+The zlib home page is http://www.cdrom.com/pub/infozip/zlib/
+The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/
+Before reporting a problem, please check those sites to verify that
+you have the latest version of zlib; otherwise get the latest version and
+check whether the problem still exists or not.
+
+Mark Nelson <markn@tiny.com> wrote an article about zlib for the Jan. 1997
+issue of Dr. Dobb's Journal; a copy of the article is available in
+http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
+
+The changes made in version 1.1.3 are documented in the file ChangeLog.
+The main changes since 1.1.2 are:
+
+- fix "an inflate input buffer bug that shows up on rare but persistent
+ occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+ (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+ See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+plus many changes for portability.
+
+Unsupported third party contributions are provided in directory "contrib".
+
+A Java implementation of zlib is available in the Java Development Kit 1.1
+http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
+See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details.
+
+A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
+is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
+ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
+
+A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
+is available in Python 1.5 and later versions, see
+http://www.python.org/doc/lib/module-zlib.html
+
+A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com>
+is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
+
+An experimental package to read and write files in .zip format,
+written on top of zlib by Gilles Vollant <info@winimage.com>, is
+available at http://www.winimage.com/zLibDll/unzip.html
+and also in the contrib/minizip directory of zlib.
+
+
+Notes for some targets:
+
+- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
+ and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
+ The zlib DLL support was initially done by Alessandro Iacopetti and is
+ now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL
+ home page at http://www.winimage.com/zLibDll
+
+ From Visual Basic, you can call the DLL functions which do not take
+ a structure as argument: compress, uncompress and all gz* functions.
+ See contrib/visual-basic.txt for more information, or get
+ http://www.tcfb.com/dowseware/cmp-z-it.zip
+
+- For 64-bit Irix, deflate.c must be compiled without any optimization.
+ With -O, one libpng test fails. The test works in 32 bit mode (with
+ the -n32 compiler flag). The compiler bug has been reported to SGI.
+
+- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1
+ it works when compiled with cc.
+
+- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1
+ is necessary to get gzprintf working correctly. This is done by configure.
+
+- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works
+ with other compilers. Use "make test" to check your compiler.
+
+- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
+
+- For Turbo C the small model is supported only with reduced performance to
+ avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
+
+- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html
+ Per Harald Myrvang <perm@stud.cs.uit.no>
+
+
+Acknowledgments:
+
+ The deflate format used by zlib was defined by Phil Katz. The deflate
+ and zlib specifications were written by L. Peter Deutsch. Thanks to all the
+ people who reported problems and suggested various improvements in zlib;
+ they are too numerous to cite here.
+
+Copyright notice:
+
+ (C) 1995-1998 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+If you use the zlib library in a product, we would appreciate *not*
+receiving lengthy legal documents to sign. The sources are provided
+for free but without warranty of any kind. The library has been
+entirely written by Jean-loup Gailly and Mark Adler; it does not
+include third-party code.
+
+If you redistribute modified sources, we would appreciate that you include
+in the file ChangeLog history information documenting your changes.
diff --git a/osframework/source/ImageLib/zlib/trees.c b/osframework/source/ImageLib/zlib/trees.c
new file mode 100644
index 0000000..d034ffa
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/trees.c
@@ -0,0 +1,1214 @@
+/* trees.c -- output deflated data using Huffman coding
+ * Copyright (C) 1995-1998 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process uses several Huffman trees. The more
+ * common source values are represented by shorter bit sequences.
+ *
+ * Each code tree is stored in a compressed form which is itself
+ * a Huffman encoding of the lengths of all the code strings (in
+ * ascending order by source values). The actual code strings are
+ * reconstructed from the lengths in the inflate process, as described
+ * in the deflate specification.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
+ * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
+ *
+ * Storer, James A.
+ * Data Compression: Methods and Theory, pp. 49-50.
+ * Computer Science Press, 1988. ISBN 0-7167-8156-5.
+ *
+ * Sedgewick, R.
+ * Algorithms, p290.
+ * Addison-Wesley, 1983. ISBN 0-201-06672-6.
+ */
+
+/* @(#) $Id: trees.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+/* #define GEN_TREES_H */
+
+#include "deflate.h"
+
+#ifdef DEBUG
+# include <ctype.h>
+#endif
+
+/* ===========================================================================
+ * Constants
+ */
+
+#define MAX_BL_BITS 7
+/* Bit length codes must not exceed MAX_BL_BITS bits */
+
+#define END_BLOCK 256
+/* end of block literal code */
+
+#define REP_3_6 16
+/* repeat previous bit length 3-6 times (2 bits of repeat count) */
+
+#define REPZ_3_10 17
+/* repeat a zero length 3-10 times (3 bits of repeat count) */
+
+#define REPZ_11_138 18
+/* repeat a zero length 11-138 times (7 bits of repeat count) */
+
+local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
+ = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
+
+local const int extra_dbits[D_CODES] /* extra bits for each distance code */
+ = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
+
+local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
+ = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
+
+local const uch bl_order[BL_CODES]
+ = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
+/* The lengths of the bit length codes are sent in order of decreasing
+ * probability, to avoid transmitting the lengths for unused bit length codes.
+ */
+
+#define Buf_size (8 * 2*sizeof(char))
+/* Number of bits used within bi_buf. (bi_buf might be implemented on
+ * more than 16 bits on some systems.)
+ */
+
+/* ===========================================================================
+ * Local data. These are initialized only once.
+ */
+
+#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+/* non ANSI compilers may not accept trees.h */
+
+local ct_data static_ltree[L_CODES+2];
+/* The static literal tree. Since the bit lengths are imposed, there is no
+ * need for the L_CODES extra codes used during heap construction. However
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
+ * below).
+ */
+
+local ct_data static_dtree[D_CODES];
+/* The static distance tree. (Actually a trivial tree since all codes use
+ * 5 bits.)
+ */
+
+uch _dist_code[DIST_CODE_LEN];
+/* Distance codes. The first 256 values correspond to the distances
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
+ * the 15 bit distances.
+ */
+
+uch _length_code[MAX_MATCH-MIN_MATCH+1];
+/* length code for each normalized match length (0 == MIN_MATCH) */
+
+local int base_length[LENGTH_CODES];
+/* First normalized length for each code (0 = MIN_MATCH) */
+
+local int base_dist[D_CODES];
+/* First normalized distance for each code (0 = distance of 1) */
+
+#else
+# include "trees.h"
+#endif /* GEN_TREES_H */
+
+struct static_tree_desc_s {
+ const ct_data *static_tree; /* static tree or NULL */
+ const intf *extra_bits; /* extra bits for each code or NULL */
+ int extra_base; /* base index for extra_bits */
+ int elems; /* max number of elements in the tree */
+ int max_length; /* max bit length for the codes */
+};
+
+local static_tree_desc static_l_desc =
+{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
+
+local static_tree_desc static_d_desc =
+{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
+
+local static_tree_desc static_bl_desc =
+{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
+
+/* ===========================================================================
+ * Local (static) routines in this file.
+ */
+
+local void tr_static_init OF((void));
+local void init_block OF((deflate_state *s));
+local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
+local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
+local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
+local void build_tree OF((deflate_state *s, tree_desc *desc));
+local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local int build_bl_tree OF((deflate_state *s));
+local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
+ int blcodes));
+local void compress_block OF((deflate_state *s, ct_data *ltree,
+ ct_data *dtree));
+local void set_data_type OF((deflate_state *s));
+local unsigned bi_reverse OF((unsigned value, int length));
+local void bi_windup OF((deflate_state *s));
+local void bi_flush OF((deflate_state *s));
+local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
+ int header));
+
+#ifdef GEN_TREES_H
+local void gen_trees_header OF((void));
+#endif
+
+#ifndef DEBUG
+# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
+ /* Send a code of the given tree. c and tree must not have side effects */
+
+#else /* DEBUG */
+# define send_code(s, c, tree) \
+ { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
+ send_bits(s, tree[c].Code, tree[c].Len); }
+#endif
+
+/* ===========================================================================
+ * Output a short LSB first on the stream.
+ * IN assertion: there is enough room in pendingBuf.
+ */
+#define put_short(s, w) { \
+ put_byte(s, (uch)((w) & 0xff)); \
+ put_byte(s, (uch)((ush)(w) >> 8)); \
+}
+
+/* ===========================================================================
+ * Send a value on a given number of bits.
+ * IN assertion: length <= 16 and value fits in length bits.
+ */
+#ifdef DEBUG
+local void send_bits OF((deflate_state *s, int value, int length));
+
+local void send_bits(s, value, length)
+ deflate_state *s;
+ int value; /* value to send */
+ int length; /* number of bits */
+{
+ Tracevv((stderr," l %2d v %4x ", length, value));
+ Assert(length > 0 && length <= 15, "invalid length");
+ s->bits_sent += (ulg)length;
+
+ /* If not enough room in bi_buf, use (valid) bits from bi_buf and
+ * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
+ * unused bits in value.
+ */
+ if (s->bi_valid > (int)Buf_size - length) {
+ s->bi_buf |= (value << s->bi_valid);
+ put_short(s, s->bi_buf);
+ s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
+ s->bi_valid += length - Buf_size;
+ } else {
+ s->bi_buf |= value << s->bi_valid;
+ s->bi_valid += length;
+ }
+}
+#else /* !DEBUG */
+
+#define send_bits(s, value, length) \
+{ int len = length;\
+ if (s->bi_valid > (int)Buf_size - len) {\
+ int val = value;\
+ s->bi_buf |= (val << s->bi_valid);\
+ put_short(s, s->bi_buf);\
+ s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
+ s->bi_valid += len - Buf_size;\
+ } else {\
+ s->bi_buf |= (value) << s->bi_valid;\
+ s->bi_valid += len;\
+ }\
+}
+#endif /* DEBUG */
+
+
+#define MAX(a,b) (a >= b ? a : b)
+/* the arguments must not have side effects */
+
+/* ===========================================================================
+ * Initialize the various 'constant' tables.
+ */
+local void tr_static_init()
+{
+#if defined(GEN_TREES_H) || !defined(STDC)
+ static int static_init_done = 0;
+ int n; /* iterates over tree elements */
+ int bits; /* bit counter */
+ int length; /* length value */
+ int code; /* code value */
+ int dist; /* distance index */
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ if (static_init_done) return;
+
+ /* For some embedded targets, global variables are not initialized: */
+ static_l_desc.static_tree = static_ltree;
+ static_l_desc.extra_bits = extra_lbits;
+ static_d_desc.static_tree = static_dtree;
+ static_d_desc.extra_bits = extra_dbits;
+ static_bl_desc.extra_bits = extra_blbits;
+
+ /* Initialize the mapping length (0..255) -> length code (0..28) */
+ length = 0;
+ for (code = 0; code < LENGTH_CODES-1; code++) {
+ base_length[code] = length;
+ for (n = 0; n < (1<<extra_lbits[code]); n++) {
+ _length_code[length++] = (uch)code;
+ }
+ }
+ Assert (length == 256, "tr_static_init: length != 256");
+ /* Note that the length 255 (match length 258) can be represented
+ * in two different ways: code 284 + 5 bits or code 285, so we
+ * overwrite length_code[255] to use the best encoding:
+ */
+ _length_code[length-1] = (uch)code;
+
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
+ dist = 0;
+ for (code = 0 ; code < 16; code++) {
+ base_dist[code] = dist;
+ for (n = 0; n < (1<<extra_dbits[code]); n++) {
+ _dist_code[dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: dist != 256");
+ dist >>= 7; /* from now on, all distances are divided by 128 */
+ for ( ; code < D_CODES; code++) {
+ base_dist[code] = dist << 7;
+ for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
+ _dist_code[256 + dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: 256+dist != 512");
+
+ /* Construct the codes of the static literal tree */
+ for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
+ n = 0;
+ while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
+ while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
+ while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
+ while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
+ /* Codes 286 and 287 do not exist, but we must include them in the
+ * tree construction to get a canonical Huffman tree (longest code
+ * all ones)
+ */
+ gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
+
+ /* The static distance tree is trivial: */
+ for (n = 0; n < D_CODES; n++) {
+ static_dtree[n].Len = 5;
+ static_dtree[n].Code = bi_reverse((unsigned)n, 5);
+ }
+ static_init_done = 1;
+
+# ifdef GEN_TREES_H
+ gen_trees_header();
+# endif
+#endif /* defined(GEN_TREES_H) || !defined(STDC) */
+}
+
+/* ===========================================================================
+ * Genererate the file trees.h describing the static trees.
+ */
+#ifdef GEN_TREES_H
+# ifndef DEBUG
+# include <stdio.h>
+# endif
+
+# define SEPARATOR(i, last, width) \
+ ((i) == (last)? "\n};\n\n" : \
+ ((i) % (width) == (width)-1 ? ",\n" : ", "))
+
+void gen_trees_header()
+{
+ FILE *header = fopen("trees.h", "w");
+ int i;
+
+ Assert (header != NULL, "Can't open trees.h");
+ fprintf(header,
+ "/* header created automatically with -DGEN_TREES_H */\n\n");
+
+ fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
+ for (i = 0; i < L_CODES+2; i++) {
+ fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
+ static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
+ }
+
+ fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
+ static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
+ }
+
+ fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
+ for (i = 0; i < DIST_CODE_LEN; i++) {
+ fprintf(header, "%2u%s", _dist_code[i],
+ SEPARATOR(i, DIST_CODE_LEN-1, 20));
+ }
+
+ fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
+ for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
+ fprintf(header, "%2u%s", _length_code[i],
+ SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
+ }
+
+ fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
+ for (i = 0; i < LENGTH_CODES; i++) {
+ fprintf(header, "%1u%s", base_length[i],
+ SEPARATOR(i, LENGTH_CODES-1, 20));
+ }
+
+ fprintf(header, "local const int base_dist[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "%5u%s", base_dist[i],
+ SEPARATOR(i, D_CODES-1, 10));
+ }
+
+ fclose(header);
+}
+#endif /* GEN_TREES_H */
+
+/* ===========================================================================
+ * Initialize the tree data structures for a new zlib stream.
+ */
+void _tr_init(s)
+ deflate_state *s;
+{
+ tr_static_init();
+
+ s->l_desc.dyn_tree = s->dyn_ltree;
+ s->l_desc.stat_desc = &static_l_desc;
+
+ s->d_desc.dyn_tree = s->dyn_dtree;
+ s->d_desc.stat_desc = &static_d_desc;
+
+ s->bl_desc.dyn_tree = s->bl_tree;
+ s->bl_desc.stat_desc = &static_bl_desc;
+
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+#ifdef DEBUG
+ s->compressed_len = 0L;
+ s->bits_sent = 0L;
+#endif
+
+ /* Initialize the first block of the first file: */
+ init_block(s);
+}
+
+/* ===========================================================================
+ * Initialize a new block.
+ */
+local void init_block(s)
+ deflate_state *s;
+{
+ int n; /* iterates over tree elements */
+
+ /* Initialize the trees. */
+ for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
+ for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
+ for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
+
+ s->dyn_ltree[END_BLOCK].Freq = 1;
+ s->opt_len = s->static_len = 0L;
+ s->last_lit = s->matches = 0;
+}
+
+#define SMALLEST 1
+/* Index within the heap array of least frequent node in the Huffman tree */
+
+
+/* ===========================================================================
+ * Remove the smallest element from the heap and recreate the heap with
+ * one less element. Updates heap and heap_len.
+ */
+#define pqremove(s, tree, top) \
+{\
+ top = s->heap[SMALLEST]; \
+ s->heap[SMALLEST] = s->heap[s->heap_len--]; \
+ pqdownheap(s, tree, SMALLEST); \
+}
+
+/* ===========================================================================
+ * Compares to subtrees, using the tree depth as tie breaker when
+ * the subtrees have equal frequency. This minimizes the worst case length.
+ */
+#define smaller(tree, n, m, depth) \
+ (tree[n].Freq < tree[m].Freq || \
+ (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
+
+/* ===========================================================================
+ * Restore the heap property by moving down the tree starting at node k,
+ * exchanging a node with the smallest of its two sons if necessary, stopping
+ * when the heap property is re-established (each father smaller than its
+ * two sons).
+ */
+local void pqdownheap(s, tree, k)
+ deflate_state *s;
+ ct_data *tree; /* the tree to restore */
+ int k; /* node to move down */
+{
+ int v = s->heap[k];
+ int j = k << 1; /* left son of k */
+ while (j <= s->heap_len) {
+ /* Set j to the smallest of the two sons: */
+ if (j < s->heap_len &&
+ smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
+ j++;
+ }
+ /* Exit if v is smaller than both sons */
+ if (smaller(tree, v, s->heap[j], s->depth)) break;
+
+ /* Exchange v with the smallest son */
+ s->heap[k] = s->heap[j]; k = j;
+
+ /* And continue down the tree, setting j to the left son of k */
+ j <<= 1;
+ }
+ s->heap[k] = v;
+}
+
+/* ===========================================================================
+ * Compute the optimal bit lengths for a tree and update the total bit length
+ * for the current block.
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
+ * above are the tree nodes sorted by increasing frequency.
+ * OUT assertions: the field len is set to the optimal bit length, the
+ * array bl_count contains the frequencies for each bit length.
+ * The length opt_len is updated; static_len is also updated if stree is
+ * not null.
+ */
+local void gen_bitlen(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ int max_code = desc->max_code;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ const intf *extra = desc->stat_desc->extra_bits;
+ int base = desc->stat_desc->extra_base;
+ int max_length = desc->stat_desc->max_length;
+ int h; /* heap index */
+ int n, m; /* iterate over the tree elements */
+ int bits; /* bit length */
+ int xbits; /* extra bits */
+ ush f; /* frequency */
+ int overflow = 0; /* number of elements with bit length too large */
+
+ for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
+
+ /* In a first pass, compute the optimal bit lengths (which may
+ * overflow in the case of the bit length tree).
+ */
+ tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
+
+ for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
+ n = s->heap[h];
+ bits = tree[tree[n].Dad].Len + 1;
+ if (bits > max_length) bits = max_length, overflow++;
+ tree[n].Len = (ush)bits;
+ /* We overwrite tree[n].Dad which is no longer needed */
+
+ if (n > max_code) continue; /* not a leaf node */
+
+ s->bl_count[bits]++;
+ xbits = 0;
+ if (n >= base) xbits = extra[n-base];
+ f = tree[n].Freq;
+ s->opt_len += (ulg)f * (bits + xbits);
+ if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
+ }
+ if (overflow == 0) return;
+
+ Trace((stderr,"\nbit length overflow\n"));
+ /* This happens for example on obj2 and pic of the Calgary corpus */
+
+ /* Find the first bit length which could increase: */
+ do {
+ bits = max_length-1;
+ while (s->bl_count[bits] == 0) bits--;
+ s->bl_count[bits]--; /* move one leaf down the tree */
+ s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
+ s->bl_count[max_length]--;
+ /* The brother of the overflow item also moves one step up,
+ * but this does not affect bl_count[max_length]
+ */
+ overflow -= 2;
+ } while (overflow > 0);
+
+ /* Now recompute all bit lengths, scanning in increasing frequency.
+ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
+ * lengths instead of fixing only the wrong ones. This idea is taken
+ * from 'ar' written by Haruhiko Okumura.)
+ */
+ for (bits = max_length; bits != 0; bits--) {
+ n = s->bl_count[bits];
+ while (n != 0) {
+ m = s->heap[--h];
+ if (m > max_code) continue;
+ if (tree[m].Len != (unsigned) bits) {
+ Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
+ s->opt_len += ((long)bits - (long)tree[m].Len)
+ *(long)tree[m].Freq;
+ tree[m].Len = (ush)bits;
+ }
+ n--;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Generate the codes for a given tree and bit counts (which need not be
+ * optimal).
+ * IN assertion: the array bl_count contains the bit length statistics for
+ * the given tree and the field len is set for all tree elements.
+ * OUT assertion: the field code is set for all tree elements of non
+ * zero code length.
+ */
+local void gen_codes (tree, max_code, bl_count)
+ ct_data *tree; /* the tree to decorate */
+ int max_code; /* largest code with non zero frequency */
+ ushf *bl_count; /* number of codes at each bit length */
+{
+ ush next_code[MAX_BITS+1]; /* next code value for each bit length */
+ ush code = 0; /* running code value */
+ int bits; /* bit index */
+ int n; /* code index */
+
+ /* The distribution counts are first used to generate the code values
+ * without bit reversal.
+ */
+ for (bits = 1; bits <= MAX_BITS; bits++) {
+ next_code[bits] = code = (code + bl_count[bits-1]) << 1;
+ }
+ /* Check that the bit counts in bl_count are consistent. The last code
+ * must be all ones.
+ */
+ Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
+ "inconsistent bit counts");
+ Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
+
+ for (n = 0; n <= max_code; n++) {
+ int len = tree[n].Len;
+ if (len == 0) continue;
+ /* Now reverse the bits */
+ tree[n].Code = bi_reverse(next_code[len]++, len);
+
+ Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
+ n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
+ }
+}
+
+/* ===========================================================================
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
+ * Update the total bit length for the current block.
+ * IN assertion: the field freq is set for all tree elements.
+ * OUT assertions: the fields len and code are set to the optimal bit length
+ * and corresponding code. The length opt_len is updated; static_len is
+ * also updated if stree is not null. The field max_code is set.
+ */
+local void build_tree(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ int elems = desc->stat_desc->elems;
+ int n, m; /* iterate over heap elements */
+ int max_code = -1; /* largest code with non zero frequency */
+ int node; /* new node being created */
+
+ /* Construct the initial heap, with least frequent element in
+ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
+ * heap[0] is not used.
+ */
+ s->heap_len = 0, s->heap_max = HEAP_SIZE;
+
+ for (n = 0; n < elems; n++) {
+ if (tree[n].Freq != 0) {
+ s->heap[++(s->heap_len)] = max_code = n;
+ s->depth[n] = 0;
+ } else {
+ tree[n].Len = 0;
+ }
+ }
+
+ /* The pkzip format requires that at least one distance code exists,
+ * and that at least one bit should be sent even if there is only one
+ * possible code. So to avoid special checks later on we force at least
+ * two codes of non zero frequency.
+ */
+ while (s->heap_len < 2) {
+ node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
+ tree[node].Freq = 1;
+ s->depth[node] = 0;
+ s->opt_len--; if (stree) s->static_len -= stree[node].Len;
+ /* node is 0 or 1 so it does not have extra bits */
+ }
+ desc->max_code = max_code;
+
+ /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
+ * establish sub-heaps of increasing lengths:
+ */
+ for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
+
+ /* Construct the Huffman tree by repeatedly combining the least two
+ * frequent nodes.
+ */
+ node = elems; /* next internal node of the tree */
+ do {
+ pqremove(s, tree, n); /* n = node of least frequency */
+ m = s->heap[SMALLEST]; /* m = node of next least frequency */
+
+ s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
+ s->heap[--(s->heap_max)] = m;
+
+ /* Create a new node father of n and m */
+ tree[node].Freq = tree[n].Freq + tree[m].Freq;
+ s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
+ tree[n].Dad = tree[m].Dad = (ush)node;
+#ifdef DUMP_BL_TREE
+ if (tree == s->bl_tree) {
+ fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
+ node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
+ }
+#endif
+ /* and insert the new node in the heap */
+ s->heap[SMALLEST] = node++;
+ pqdownheap(s, tree, SMALLEST);
+
+ } while (s->heap_len >= 2);
+
+ s->heap[--(s->heap_max)] = s->heap[SMALLEST];
+
+ /* At this point, the fields freq and dad are set. We can now
+ * generate the bit lengths.
+ */
+ gen_bitlen(s, (tree_desc *)desc);
+
+ /* The field len is now set, we can generate the bit codes */
+ gen_codes ((ct_data *)tree, max_code, s->bl_count);
+}
+
+/* ===========================================================================
+ * Scan a literal or distance tree to determine the frequencies of the codes
+ * in the bit length tree.
+ */
+local void scan_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ if (nextlen == 0) max_count = 138, min_count = 3;
+ tree[max_code+1].Len = (ush)0xffff; /* guard */
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ s->bl_tree[curlen].Freq += count;
+ } else if (curlen != 0) {
+ if (curlen != prevlen) s->bl_tree[curlen].Freq++;
+ s->bl_tree[REP_3_6].Freq++;
+ } else if (count <= 10) {
+ s->bl_tree[REPZ_3_10].Freq++;
+ } else {
+ s->bl_tree[REPZ_11_138].Freq++;
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Send a literal or distance tree in compressed form, using the codes in
+ * bl_tree.
+ */
+local void send_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
+ if (nextlen == 0) max_count = 138, min_count = 3;
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
+
+ } else if (curlen != 0) {
+ if (curlen != prevlen) {
+ send_code(s, curlen, s->bl_tree); count--;
+ }
+ Assert(count >= 3 && count <= 6, " 3_6?");
+ send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
+
+ } else if (count <= 10) {
+ send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
+
+ } else {
+ send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Construct the Huffman tree for the bit lengths and return the index in
+ * bl_order of the last bit length code to send.
+ */
+local int build_bl_tree(s)
+ deflate_state *s;
+{
+ int max_blindex; /* index of last bit length code of non zero freq */
+
+ /* Determine the bit length frequencies for literal and distance trees */
+ scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
+ scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
+
+ /* Build the bit length tree: */
+ build_tree(s, (tree_desc *)(&(s->bl_desc)));
+ /* opt_len now includes the length of the tree representations, except
+ * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
+ */
+
+ /* Determine the number of bit length codes to send. The pkzip format
+ * requires that at least 4 bit length codes be sent. (appnote.txt says
+ * 3 but the actual value used is 4.)
+ */
+ for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
+ if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
+ }
+ /* Update opt_len to include the bit length tree and counts */
+ s->opt_len += 3*(max_blindex+1) + 5+5+4;
+ Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
+ s->opt_len, s->static_len));
+
+ return max_blindex;
+}
+
+/* ===========================================================================
+ * Send the header for a block using dynamic Huffman trees: the counts, the
+ * lengths of the bit length codes, the literal tree and the distance tree.
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
+ */
+local void send_all_trees(s, lcodes, dcodes, blcodes)
+ deflate_state *s;
+ int lcodes, dcodes, blcodes; /* number of codes for each tree */
+{
+ int rank; /* index in bl_order */
+
+ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
+ Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
+ "too many codes");
+ Tracev((stderr, "\nbl counts: "));
+ send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
+ send_bits(s, dcodes-1, 5);
+ send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
+ for (rank = 0; rank < blcodes; rank++) {
+ Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
+ send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
+ }
+ Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
+ Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
+ Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
+}
+
+/* ===========================================================================
+ * Send a stored block
+ */
+void _tr_stored_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
+#ifdef DEBUG
+ s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
+ s->compressed_len += (stored_len + 4) << 3;
+#endif
+ copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
+}
+
+/* ===========================================================================
+ * Send one empty static block to give enough lookahead for inflate.
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
+ * The current inflate code requires 9 bits of lookahead. If the
+ * last two codes for the previous block (real code plus EOB) were coded
+ * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
+ * the last real code. In this case we send two empty static blocks instead
+ * of one. (There are no problems if the previous block is stored or fixed.)
+ * To simplify the code, we assume the worst case of last real code encoded
+ * on one bit only.
+ */
+void _tr_align(s)
+ deflate_state *s;
+{
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
+ bi_flush(s);
+ /* Of the 10 bits for the empty block, we have already sent
+ * (10 - bi_valid) bits. The lookahead for the last real code (before
+ * the EOB of the previous block) was thus at least one plus the length
+ * of the EOB plus what we have just sent of the empty static block.
+ */
+ if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L;
+#endif
+ bi_flush(s);
+ }
+ s->last_eob_len = 7;
+}
+
+/* ===========================================================================
+ * Determine the best encoding for the current block: dynamic trees, static
+ * trees or store, and output the encoded block to the zip file.
+ */
+void _tr_flush_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block, or NULL if too old */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
+ int max_blindex = 0; /* index of last bit length code of non zero freq */
+
+ /* Build the Huffman trees unless a stored block is forced */
+ if (s->level > 0) {
+
+ /* Check if the file is ascii or binary */
+ if (s->data_type == Z_UNKNOWN) set_data_type(s);
+
+ /* Construct the literal and distance trees */
+ build_tree(s, (tree_desc *)(&(s->l_desc)));
+ Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+
+ build_tree(s, (tree_desc *)(&(s->d_desc)));
+ Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+ /* At this point, opt_len and static_len are the total bit lengths of
+ * the compressed block data, excluding the tree representations.
+ */
+
+ /* Build the bit length tree for the above two trees, and get the index
+ * in bl_order of the last bit length code to send.
+ */
+ max_blindex = build_bl_tree(s);
+
+ /* Determine the best encoding. Compute first the block length in bytes*/
+ opt_lenb = (s->opt_len+3+7)>>3;
+ static_lenb = (s->static_len+3+7)>>3;
+
+ Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+ opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+ s->last_lit));
+
+ if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+
+ } else {
+ Assert(buf != (char*)0, "lost buf");
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
+ }
+
+#ifdef FORCE_STORED
+ if (buf != (char*)0) { /* force stored block */
+#else
+ if (stored_len+4 <= opt_lenb && buf != (char*)0) {
+ /* 4: two words for the lengths */
+#endif
+ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
+ * Otherwise we can't have processed more than WSIZE input bytes since
+ * the last block flush, because compression would have been
+ * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
+ * transform a block into a stored block.
+ */
+ _tr_stored_block(s, buf, stored_len, eof);
+
+#ifdef FORCE_STATIC
+ } else if (static_lenb >= 0) { /* force static trees */
+#else
+ } else if (static_lenb == opt_lenb) {
+#endif
+ send_bits(s, (STATIC_TREES<<1)+eof, 3);
+ compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->static_len;
+#endif
+ } else {
+ send_bits(s, (DYN_TREES<<1)+eof, 3);
+ send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
+ max_blindex+1);
+ compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->opt_len;
+#endif
+ }
+ Assert (s->compressed_len == s->bits_sent, "bad compressed size");
+ /* The above check is made mod 2^32, for files larger than 512 MB
+ * and uLong implemented on 32 bits.
+ */
+ init_block(s);
+
+ if (eof) {
+ bi_windup(s);
+#ifdef DEBUG
+ s->compressed_len += 7; /* align on byte boundary */
+#endif
+ }
+ Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
+ s->compressed_len-7*eof));
+}
+
+/* ===========================================================================
+ * Save the match info and tally the frequency counts. Return true if
+ * the current block must be flushed.
+ */
+int _tr_tally (s, dist, lc)
+ deflate_state *s;
+ unsigned dist; /* distance of matched string */
+ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
+{
+ s->d_buf[s->last_lit] = (ush)dist;
+ s->l_buf[s->last_lit++] = (uch)lc;
+ if (dist == 0) {
+ /* lc is the unmatched char */
+ s->dyn_ltree[lc].Freq++;
+ } else {
+ s->matches++;
+ /* Here, lc is the match length - MIN_MATCH */
+ dist--; /* dist = match distance - 1 */
+ Assert((ush)dist < (ush)MAX_DIST(s) &&
+ (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
+ (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
+
+ s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
+ s->dyn_dtree[d_code(dist)].Freq++;
+ }
+
+#ifdef TRUNCATE_BLOCK
+ /* Try to guess if it is profitable to stop the current block here */
+ if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
+ /* Compute an upper bound for the compressed length */
+ ulg out_length = (ulg)s->last_lit*8L;
+ ulg in_length = (ulg)((long)s->strstart - s->block_start);
+ int dcode;
+ for (dcode = 0; dcode < D_CODES; dcode++) {
+ out_length += (ulg)s->dyn_dtree[dcode].Freq *
+ (5L+extra_dbits[dcode]);
+ }
+ out_length >>= 3;
+ Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
+ s->last_lit, in_length, out_length,
+ 100L - out_length*100L/in_length));
+ if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
+ }
+#endif
+ return (s->last_lit == s->lit_bufsize-1);
+ /* We avoid equality with lit_bufsize because of wraparound at 64K
+ * on 16 bit machines and because stored blocks are restricted to
+ * 64K-1 bytes.
+ */
+}
+
+/* ===========================================================================
+ * Send the block data compressed using the given Huffman trees
+ */
+local void compress_block(s, ltree, dtree)
+ deflate_state *s;
+ ct_data *ltree; /* literal tree */
+ ct_data *dtree; /* distance tree */
+{
+ unsigned dist; /* distance of matched string */
+ int lc; /* match length or unmatched char (if dist == 0) */
+ unsigned lx = 0; /* running index in l_buf */
+ unsigned code; /* the code to send */
+ int extra; /* number of extra bits to send */
+
+ if (s->last_lit != 0) do {
+ dist = s->d_buf[lx];
+ lc = s->l_buf[lx++];
+ if (dist == 0) {
+ send_code(s, lc, ltree); /* send a literal byte */
+ Tracecv(isgraph(lc), (stderr," '%c' ", lc));
+ } else {
+ /* Here, lc is the match length - MIN_MATCH */
+ code = _length_code[lc];
+ send_code(s, code+LITERALS+1, ltree); /* send the length code */
+ extra = extra_lbits[code];
+ if (extra != 0) {
+ lc -= base_length[code];
+ send_bits(s, lc, extra); /* send the extra length bits */
+ }
+ dist--; /* dist is now the match distance - 1 */
+ code = d_code(dist);
+ Assert (code < D_CODES, "bad d_code");
+
+ send_code(s, code, dtree); /* send the distance code */
+ extra = extra_dbits[code];
+ if (extra != 0) {
+ dist -= base_dist[code];
+ send_bits(s, dist, extra); /* send the extra distance bits */
+ }
+ } /* literal or match pair ? */
+
+ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
+ Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
+
+ } while (lx < s->last_lit);
+
+ send_code(s, END_BLOCK, ltree);
+ s->last_eob_len = ltree[END_BLOCK].Len;
+}
+
+/* ===========================================================================
+ * Set the data type to ASCII or BINARY, using a crude approximation:
+ * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
+ * IN assertion: the fields freq of dyn_ltree are set and the total of all
+ * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
+ */
+local void set_data_type(s)
+ deflate_state *s;
+{
+ int n = 0;
+ unsigned ascii_freq = 0;
+ unsigned bin_freq = 0;
+ while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
+ while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
+ while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
+ s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
+}
+
+/* ===========================================================================
+ * Reverse the first len bits of a code, using straightforward code (a faster
+ * method would use a table)
+ * IN assertion: 1 <= len <= 15
+ */
+local unsigned bi_reverse(code, len)
+ unsigned code; /* the value to invert */
+ int len; /* its bit length */
+{
+ register unsigned res = 0;
+ do {
+ res |= code & 1;
+ code >>= 1, res <<= 1;
+ } while (--len > 0);
+ return res >> 1;
+}
+
+/* ===========================================================================
+ * Flush the bit buffer, keeping at most 7 bits in it.
+ */
+local void bi_flush(s)
+ deflate_state *s;
+{
+ if (s->bi_valid == 16) {
+ put_short(s, s->bi_buf);
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ } else if (s->bi_valid >= 8) {
+ put_byte(s, (Byte)s->bi_buf);
+ s->bi_buf >>= 8;
+ s->bi_valid -= 8;
+ }
+}
+
+/* ===========================================================================
+ * Flush the bit buffer and align the output on a byte boundary
+ */
+local void bi_windup(s)
+ deflate_state *s;
+{
+ if (s->bi_valid > 8) {
+ put_short(s, s->bi_buf);
+ } else if (s->bi_valid > 0) {
+ put_byte(s, (Byte)s->bi_buf);
+ }
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+#ifdef DEBUG
+ s->bits_sent = (s->bits_sent+7) & ~7;
+#endif
+}
+
+/* ===========================================================================
+ * Copy a stored block, storing first the length and its
+ * one's complement if requested.
+ */
+local void copy_block(s, buf, len, header)
+ deflate_state *s;
+ charf *buf; /* the input data */
+ unsigned len; /* its length */
+ int header; /* true if block header must be written */
+{
+ bi_windup(s); /* align on byte boundary */
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+
+ if (header) {
+ put_short(s, (ush)len);
+ put_short(s, (ush)~len);
+#ifdef DEBUG
+ s->bits_sent += 2*16;
+#endif
+ }
+#ifdef DEBUG
+ s->bits_sent += (ulg)len<<3;
+#endif
+ while (len--) {
+ put_byte(s, *buf++);
+ }
+}
diff --git a/osframework/source/ImageLib/zlib/trees.h b/osframework/source/ImageLib/zlib/trees.h
new file mode 100644
index 0000000..1ca868b
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/trees.h
@@ -0,0 +1,128 @@
+/* header created automatically with -DGEN_TREES_H */
+
+local const ct_data static_ltree[L_CODES+2] = {
+{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
+{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
+{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
+{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
+{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
+{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
+{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
+{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
+{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
+{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
+{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
+{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
+{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
+{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
+{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
+{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
+{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
+{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
+{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
+{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
+{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
+{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
+{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
+{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
+{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
+{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
+{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
+{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
+{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
+{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
+{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
+{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
+{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
+{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
+{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
+{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
+{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
+{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
+{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
+{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
+{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
+{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
+{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
+{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
+{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
+{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
+{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
+{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
+{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
+{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
+{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
+{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
+{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
+{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
+{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
+{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
+{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
+{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
+};
+
+local const ct_data static_dtree[D_CODES] = {
+{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
+{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
+{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
+{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
+{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
+{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
+};
+
+const uch _dist_code[DIST_CODE_LEN] = {
+ 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
+10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
+18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
+};
+
+const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
+13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
+17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
+19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
+};
+
+local const int base_length[LENGTH_CODES] = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
+64, 80, 96, 112, 128, 160, 192, 224, 0
+};
+
+local const int base_dist[D_CODES] = {
+ 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
+ 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
+ 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
+};
+
diff --git a/osframework/source/ImageLib/zlib/uncompr.c b/osframework/source/ImageLib/zlib/uncompr.c
new file mode 100644
index 0000000..53a7cf9
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/uncompr.c
@@ -0,0 +1,58 @@
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: uncompr.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "zlib.h"
+
+/* ===========================================================================
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+*/
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+
+ err = inflateInit(&stream);
+ if (err != Z_OK) return err;
+
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = inflateEnd(&stream);
+ return err;
+}
diff --git a/osframework/source/ImageLib/zlib/zconf.h b/osframework/source/ImageLib/zlib/zconf.h
new file mode 100644
index 0000000..a3f9962
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/zconf.h
@@ -0,0 +1,285 @@
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: zconf.h,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#ifndef _ZCONF_H
+#define _ZCONF_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ */
+#ifdef Z_PREFIX
+# define deflateInit_ z_deflateInit_
+# define deflate z_deflate
+# define deflateEnd z_deflateEnd
+# define inflateInit_ z_inflateInit_
+# define inflate z_inflate
+# define inflateEnd z_inflateEnd
+# define deflateInit2_ z_deflateInit2_
+# define deflateSetDictionary z_deflateSetDictionary
+# define deflateCopy z_deflateCopy
+# define deflateReset z_deflateReset
+# define deflateParams z_deflateParams
+# define inflateInit2_ z_inflateInit2_
+# define inflateSetDictionary z_inflateSetDictionary
+# define inflateSync z_inflateSync
+# define inflateSyncPoint z_inflateSyncPoint
+# define inflateReset z_inflateReset
+# define compress z_compress
+# define compress2 z_compress2
+# define uncompress z_uncompress
+# define adler32 z_adler32
+# define crc32 z_crc32
+# define get_crc_table z_get_crc_table
+
+# define Byte z_Byte
+# define uInt z_uInt
+# define uLong z_uLong
+# define Bytef z_Bytef
+# define charf z_charf
+# define intf z_intf
+# define uIntf z_uIntf
+# define uLongf z_uLongf
+# define voidpf z_voidpf
+# define voidp z_voidp
+#endif
+
+#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
+# define WIN32
+#endif
+#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
+# ifndef __32BIT__
+# define __32BIT__
+# endif
+#endif
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#if defined(MSDOS) && !defined(__32BIT__)
+# define MAXSEG_64K
+#endif
+#ifdef MSDOS
+# define UNALIGNED_OK
+#endif
+
+#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
+# define STDC
+#endif
+#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
+# ifndef STDC
+# define STDC
+# endif
+#endif
+
+#ifndef STDC
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define constt
+# endif
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
+# define NO_DUMMY_DECL
+#endif
+
+/* Old Borland C incorrectly complains about missing returns: */
+#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
+# define NEED_DUMMY_RETURN
+#endif
+
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+ /* Type declarations */
+
+#ifndef OF /* function prototypes */
+# ifdef STDC
+# define OF(args) args
+# else
+# define OF(args) ()
+# endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
+ /* MSC small or medium model */
+# define SMALL_MEDIUM
+# ifdef _MSC_VER
+# define FAR _far
+# else
+# define FAR far
+# endif
+#endif
+#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
+# ifndef __32BIT__
+# define SMALL_MEDIUM
+# define FAR _far
+# endif
+#endif
+
+/* Compile with -DZLIB_DLL for Windows DLL support */
+#if defined(ZLIB_DLL)
+# if defined(_WINDOWS) || defined(WINDOWS)
+# ifdef FAR
+# undef FAR
+# endif
+# include <windows.h>
+# if defined (_VISUALC_)
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXPORT WINAPI
+# define ZEXPORT ZEXPORT __declspec(dllexport)
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
+# define ZEXPORTVA __declspec(dllexport)
+# else
+# define ZEXPORTVA FAR _cdecl _export
+# endif
+# endif
+# endif
+# if defined (__BORLANDC__)
+# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
+# include <windows.h>
+# define ZEXPORT __declspec(dllexport) WINAPI
+# define ZEXPORTRVA __declspec(dllexport) WINAPIV
+# else
+# if defined (_Windows) && defined (__DLL__)
+# define ZEXPORT _export
+# define ZEXPORTVA _export
+# endif
+# endif
+# endif
+#endif
+#if defined (__BEOS__)
+# if defined (ZLIB_DLL)
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXTERN extern __declspec(dllimport)
+# endif
+#endif
+
+
+#ifndef ZEXPORT
+# define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+# define ZEXPORTVA
+#endif
+#ifndef ZEXTERN
+# define ZEXTERN extern
+#endif
+
+#ifndef FAR
+# define FAR
+#endif
+
+#if !defined(MACOS) && !defined(TARGET_OS_MAC)
+typedef unsigned char Byte; /* 8 bits */
+#endif
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+# define Bytef Byte FAR
+#else
+ typedef Byte FAR Bytef;
+#endif
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+ typedef void FAR *voidpf;
+ typedef void *voidp;
+#else
+ typedef Byte FAR *voidpf;
+ typedef Byte *voidp;
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <sys/types.h> /* for off_t */
+# include <unistd.h> /* for SEEK_* and off_t */
+# define z_off_t off_t
+#endif
+#ifndef SEEK_SET
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+#ifndef z_off_t
+# define z_off_t long
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+# pragma map(deflateInit_,"DEIN")
+# pragma map(deflateInit2_,"DEIN2")
+# pragma map(deflateEnd,"DEEND")
+# pragma map(inflateInit_,"ININ")
+# pragma map(inflateInit2_,"ININ2")
+# pragma map(inflateEnd,"INEND")
+# pragma map(inflateSync,"INSY")
+# pragma map(inflateSetDictionary,"INSEDI")
+# pragma map(inflate_blocks,"INBL")
+# pragma map(inflate_blocks_new,"INBLNE")
+# pragma map(inflate_blocks_free,"INBLFR")
+# pragma map(inflate_blocks_reset,"INBLRE")
+# pragma map(inflate_codes_free,"INCOFR")
+# pragma map(inflate_codes,"INCO")
+# pragma map(inflate_fast,"INFA")
+# pragma map(inflate_flush,"INFLU")
+# pragma map(inflate_mask,"INMA")
+# pragma map(inflate_set_dictionary,"INSEDI2")
+# pragma map(inflate_copyright,"INCOPY")
+# pragma map(inflate_trees_bits,"INTRBI")
+# pragma map(inflate_trees_dynamic,"INTRDY")
+# pragma map(inflate_trees_fixed,"INTRFI")
+# pragma map(inflate_trees_free,"INTRFR")
+#endif
+
+#endif /* _ZCONF_H */
diff --git a/osframework/source/ImageLib/zlib/zlib.3 b/osframework/source/ImageLib/zlib/zlib.3
new file mode 100644
index 0000000..0a7c40a
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/zlib.3
@@ -0,0 +1,107 @@
+.TH ZLIB 3 "9 July 1998"
+.SH NAME
+zlib \- compression/decompression library
+.SH SYNOPSIS
+[see
+.I zlib.h
+for full description]
+.SH DESCRIPTION
+The
+.I zlib
+library is a general purpose data compression library.
+The code is thread safe.
+It provides in-memory compression and decompression functions,
+including integrity checks of the uncompressed data.
+This version of the library supports only one compression method (deflation)
+but other algorithms will be added later and will have the same stream interface.
+.LP
+Compression can be done in a single step if the buffers are large enough
+(for example if an input file is mmap'ed),
+or can be done by repeated calls of the compression function.
+In the latter case,
+the application must provide more input and/or consume the output
+(providing more output space) before each call.
+.LP
+The library also supports reading and writing files in
+.I gzip
+(.gz) format
+with an interface similar to that of stdio.
+.LP
+The library does not install any signal handler. The decoder checks
+the consistency of the compressed data, so the library should never
+crash even in case of corrupted input.
+.LP
+All functions of the compression library are documented in the file
+.IR zlib.h.
+The distribution source includes examples of use of the library
+the files
+.I example.c
+and
+.IR minigzip.c .
+.LP
+A Java implementation of
+.IR zlib
+is available in the Java Development Kit 1.1
+.IP
+http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
+.LP
+A Perl interface to
+.IR zlib ,
+written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
+is available at CPAN (Comprehensive Perl Archive Network) sites,
+such as:
+.IP
+ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
+.LP
+A Python interface to
+.IR zlib
+written by A.M. Kuchling <amk@magnet.com>
+is available from the Python Software Association sites, such as:
+.IP
+ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
+.SH "SEE ALSO"
+Questions about zlib should be sent to:
+.IP
+zlib@quest.jpl.nasa.gov
+or, if this fails, to the author addresses given below.
+The zlib home page is:
+.IP
+http://www.cdrom.com/pub/infozip/zlib/
+.LP
+The data format used by the zlib library is described by RFC
+(Request for Comments) 1950 to 1952 in the files:
+.IP
+ftp://ds.internic.net/rfc/rfc1950.txt (zlib format)
+.br
+rfc1951.txt (deflate format)
+.br
+rfc1952.txt (gzip format)
+.LP
+These documents are also available in other formats from:
+.IP
+ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+.SH AUTHORS
+Version 1.1.3
+Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org)
+and Mark Adler (madler@alumni.caltech.edu).
+.LP
+This software is provided "as-is,"
+without any express or implied warranty.
+In no event will the authors be held liable for any damages
+arising from the use of this software.
+See the distribution directory with respect to requirements
+governing redistribution.
+The deflate format used by
+.I zlib
+was defined by Phil Katz.
+The deflate and
+.I zlib
+specifications were written by L. Peter Deutsch.
+Thanks to all the people who reported problems and suggested various
+improvements in
+.IR zlib ;
+who are too numerous to cite here.
+.LP
+UNIX manual page by R. P. C. Rodgers,
+U.S. National Library of Medicine (rodgers@nlm.nih.gov).
+.\" end of man page
diff --git a/osframework/source/ImageLib/zlib/zlib.h b/osframework/source/ImageLib/zlib/zlib.h
new file mode 100644
index 0000000..34fe85f
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/zlib.h
@@ -0,0 +1,893 @@
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.1.3, July 9th, 1998
+
+ Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
+ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+*/
+
+#ifndef _ZLIB_H
+#define _ZLIB_H
+
+#include "zconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZLIB_VERSION "1.1.3"
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed
+ data. This version of the library supports only one compression method
+ (deflation) but other algorithms will be added later and will have the same
+ stream interface.
+
+ Compression can be done in a single step if the buffers are large
+ enough (for example if an input file is mmap'ed), or can be done by
+ repeated calls of the compression function. In the latter case, the
+ application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never
+ crash even in case of corrupted input.
+*/
+
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
+
+struct internal_state;
+
+typedef struct z_stream_s {
+ Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ uLong total_in; /* total nb of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ uLong total_out; /* total nb of bytes output so far */
+
+ char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
+
+ int data_type; /* best guess about the data type: ascii or binary */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR *z_streamp;
+
+/*
+ The application must update next_in and avail_in when avail_in has
+ dropped to zero. It must update next_out and avail_out when avail_out
+ has dropped to zero. The application must initialize zalloc, zfree and
+ opaque before calling the init function. All other fields are set by the
+ compression library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this
+ if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
+ pointers returned by zalloc for objects of exactly 65536 bytes *must*
+ have their offset normalized to zero. The default allocation function
+ provided by this library ensures this (see zutil.c). To reduce memory
+ requirements and avoid any allocation of 64K objects, at the expense of
+ compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or
+ progress reports. After compression, total_in holds the total size of
+ the uncompressed data and may be saved for use in the decompressor
+ (particularly if the decompressor wants to decompress everything in
+ a single step).
+*/
+
+ /* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+/* Allowed flush values; see deflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions. Negative
+ * values are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_ASCII 1
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+ /* basic functions */
+
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is
+ not compatible with the zlib.h header file used by the application.
+ This check is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller.
+ If zalloc and zfree are set to Z_NULL, deflateInit updates them to
+ use default allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at
+ all (the input data is simply copied a block at a time).
+ Z_DEFAULT_COMPRESSION requests a default compromise between speed and
+ compression (currently equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if level is not a valid compression level,
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION).
+ msg is set to null if there is no error message. deflateInit does not
+ perform any compression: this will be done by deflate().
+*/
+
+
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce some
+ output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications).
+ Some output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating avail_in or avail_out accordingly; avail_out
+ should never be zero before the call. The application can consume the
+ compressed output when it wants, for example when the output buffer is full
+ (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
+ and with zero avail_out, it must be called again after making room in the
+ output buffer because there might be more output pending.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In particular
+ avail_in is zero after the call if enough output space has been provided
+ before the call.) Flushing may degrade compression for some compression
+ algorithms and so it should be used only when necessary.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ the compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out).
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there
+ was enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the
+ stream are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least
+ 0.1% larger than avail_in plus 12 bytes. If deflate does not return
+ Z_STREAM_END, then it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so far (that is, total_in bytes).
+
+ deflate() may update data_type if it can make a good guess about
+ the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect
+ the compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero).
+*/
+
+
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case,
+ msg may be set but then points to a static string (which must not be
+ deallocated).
+*/
+
+
+/*
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
+ value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller. msg is set to null if there is no error
+ message. inflateInit does not perform any decompression apart from reading
+ the zlib header if present: this will be done by inflate(). (So next_in and
+ avail_in may be modified, but next_out and avail_out are unchanged.)
+*/
+
+
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may some
+ introduce some output latency (reading input without producing any output)
+ except when forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing
+ will resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there
+ is no more input data or no more space in the output buffer (see below
+ about the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating the next_* and avail_* values accordingly.
+ The application can consume the uncompressed output when it wants, for
+ example when the output buffer is full (avail_out == 0), or after each
+ call of inflate(). If inflate returns Z_OK and with zero avail_out, it
+ must be called again after making room in the output buffer because there
+ might be more output pending.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
+ output as possible to the output buffer. The flushing behavior of inflate is
+ not specified for values of the flush parameter other than Z_SYNC_FLUSH
+ and Z_FINISH, but the current implementation actually flushes as much output
+ as possible anyway.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step
+ (a single call of inflate), the parameter flush should be set to
+ Z_FINISH. In this case all pending input is processed and all pending
+ output is flushed; avail_out must be large enough to hold all the
+ uncompressed data. (The size of the uncompressed data may have been saved
+ by the compressor for this purpose.) The next operation on this stream must
+ be inflateEnd to deallocate the decompression state. The use of Z_FINISH
+ is never required, but can be used to inform inflate that a faster routine
+ may be used for the single inflate() call.
+
+ If a preset dictionary is needed at this point (see inflateSetDictionary
+ below), inflate sets strm-adler to the adler32 checksum of the
+ dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
+ it sets strm->adler to the adler32 checksum of all output produced
+ so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
+ an error code as described below. At the end of the stream, inflate()
+ checks that its computed adler32 checksum is equal to that saved by the
+ compressor and returns Z_STREAM_END only if the checksum is correct.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect
+ adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
+ (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if no progress is possible or if there was not
+ enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
+ case, the application may then call inflateSync to look for a good
+ compression block.
+*/
+
+
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+*/
+
+ /* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+*/
+
+/*
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by
+ the caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but
+ is slow and reduces compression ratio; memLevel=9 uses maximum memory
+ for optimal speed. The default value is 8. See zconf.h for total memory
+ usage as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match). Filtered data consists mostly of small values with a
+ somewhat random distribution. In this case, the compression algorithm is
+ tuned to compress them better. The effect of Z_FILTERED is to force more
+ Huffman coding and less string matching; it is somewhat intermediate
+ between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
+ the compression ratio but not the correctness of the compressed output even
+ if it is not set appropriately.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
+ method). msg is set to null if there is no error message. deflateInit2 does
+ not perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. This function must be called
+ immediately after deflateInit, deflateInit2 or deflateReset, before any
+ call of deflate. The compressor and decompressor must use exactly the same
+ dictionary (see inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size in
+ deflate or deflate2. Thus the strings most likely to be useful should be
+ put at the end of the dictionary, not at the front.
+
+ Upon return of this function, strm->adler is set to the Adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The Adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.)
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if the compression method is bsort). deflateSetDictionary does not
+ perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and
+ can consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state.
+ The stream will keep the same compression level and any other attributes
+ that may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
+ int level,
+ int strategy));
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different
+ strategy. If the compression level is changed, the input available so far
+ is compressed with the old level (and may be flushed); the new level will
+ take effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to
+ be compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
+ if strm->avail_out was zero.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. If a compressed stream with a larger window size is given as
+ input, inflate() will return with the error code Z_DATA_ERROR instead of
+ trying to allocate a larger window.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
+ memLevel). msg is set to null if there is no error message. inflateInit2
+ does not perform any decompression apart from reading the zlib header if
+ present: this will be done by inflate(). (So next_in and avail_in may be
+ modified, but next_out and avail_out are unchanged.)
+*/
+
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate
+ if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the Adler32 value returned by this call of
+ inflate. The compressor and decompressor must use exactly the same
+ dictionary (see deflateSetDictionary).
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect Adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+*/
+
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
+/*
+ Skips invalid compressed data until a full flush point (see above the
+ description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
+ if no more input was provided, Z_DATA_ERROR if no flush point has been found,
+ or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
+ case, the application may save the current current value of total_in which
+ indicates where valid compressed data was found. In the error case, the
+ application may repeatedly call inflateSync, providing more input each time,
+ until success or end of the input data.
+*/
+
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state.
+ The stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+
+ /* utility functions */
+
+/*
+ The following utility functions are implemented on top of the
+ basic stream-oriented functions. To simplify the interface, some
+ default options are assumed (compression level and memory usage,
+ standard memory allocation functions). The source code of these
+ utility functions can easily be modified if you need special options.
+*/
+
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be at least 0.1% larger than
+ sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
+ compressed buffer.
+ This function can be used to compress a whole file at once if the
+ input file is mmap'ed.
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+*/
+
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+*/
+
+
+typedef voidp gzFile;
+
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
+/*
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb") but can also include a compression level
+ ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
+ Huffman only compression as in "wb1h". (See the description
+ of deflateInit2 for more information about the strategy parameter.)
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression.
+
+ gzopen returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR). */
+
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
+/*
+ gzdopen() associates a gzFile with the file descriptor fd. File
+ descriptors are obtained from calls like open, dup, creat, pipe or
+ fileno (in the file has been previously opened with fopen).
+ The mode parameter is as in gzopen.
+ The next call of gzclose on the returned gzFile will also close the
+ file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
+ descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
+ gzdopen returns NULL if there was insufficient memory to allocate
+ the (de)compression state.
+*/
+
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+*/
+
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+/*
+ Reads the given number of uncompressed bytes from the compressed file.
+ If the input file was not in gzip format, gzread copies the given number
+ of bytes into the buffer.
+ gzread returns the number of uncompressed bytes actually read (0 for
+ end of file, -1 for error). */
+
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
+ const voidp buf, unsigned len));
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes actually written
+ (0 in case of error).
+*/
+
+ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+/*
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error).
+*/
+
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or
+ a newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. The string is then terminated with a null
+ character.
+ gzgets returns buf, or Z_NULL in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
+/*
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
+/*
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function. The return value is the zlib
+ error number (see function gzerror below). gzflush returns Z_OK if
+ the flush parameter is Z_FINISH and all output could be flushed.
+ gzflush should be called only when strictly necessary because it can
+ degrade compression.
+*/
+
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
+ z_off_t offset, int whence));
+/*
+ Sets the starting position for the next gzread or gzwrite on the
+ given compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+*/
+
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+*/
+
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
+/*
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+*/
+
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
+/*
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
+/*
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state. The return value is the zlib
+ error number (see function gzerror below).
+*/
+
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
+/*
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+
+ /* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the
+ compression library.
+*/
+
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
+
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is NULL, this function returns
+ the required initial value for the checksum.
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster. Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+*/
+
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+/*
+ Update a running crc with the bytes buf[0..len-1] and return the updated
+ crc. If buf is NULL, this function returns the required initial value
+ for the crc. Pre- and post-conditioning (one's complement) is performed
+ within this function so it shouldn't be done by the application.
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+*/
+
+
+ /* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size));
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
+#define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+
+
+#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
+ struct internal_state {int dummy;}; /* hack for buggy compilers */
+#endif
+
+ZEXTERN const char * ZEXPORT zError OF((int err));
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
+ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ZLIB_H */
diff --git a/osframework/source/ImageLib/zlib/zutil.c b/osframework/source/ImageLib/zlib/zutil.c
new file mode 100644
index 0000000..9f04feb
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/zutil.c
@@ -0,0 +1,225 @@
+/* zutil.c -- target dependent utility functions for the compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id: zutil.c,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#include "zutil.h"
+
+struct internal_state {int dummy;}; /* for buggy compilers */
+
+#ifndef STDC
+extern void exit OF((int));
+#endif
+
+const char *z_errmsg[10] = {
+"need dictionary", /* Z_NEED_DICT 2 */
+"stream end", /* Z_STREAM_END 1 */
+"", /* Z_OK 0 */
+"file error", /* Z_ERRNO (-1) */
+"stream error", /* Z_STREAM_ERROR (-2) */
+"data error", /* Z_DATA_ERROR (-3) */
+"insufficient memory", /* Z_MEM_ERROR (-4) */
+"buffer error", /* Z_BUF_ERROR (-5) */
+"incompatible version",/* Z_VERSION_ERROR (-6) */
+""};
+
+
+const char * ZEXPORT zlibVersion()
+{
+ return ZLIB_VERSION;
+}
+
+#ifdef DEBUG
+
+# ifndef verbose
+# define verbose 0
+# endif
+int z_verbose = verbose;
+
+void z_error (m)
+ char *m;
+{
+ fprintf(stderr, "%s\n", m);
+ exit(1);
+}
+#endif
+
+/* exported to allow conversion of error code to string for compress() and
+ * uncompress()
+ */
+const char * ZEXPORT zError(err)
+ int err;
+{
+ return ERR_MSG(err);
+}
+
+
+#ifndef HAVE_MEMCPY
+
+void zmemcpy(dest, source, len)
+ Bytef* dest;
+ const Bytef* source;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = *source++; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+
+int zmemcmp(s1, s2, len)
+ const Bytef* s1;
+ const Bytef* s2;
+ uInt len;
+{
+ uInt j;
+
+ for (j = 0; j < len; j++) {
+ if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
+ }
+ return 0;
+}
+
+void zmemzero(dest, len)
+ Bytef* dest;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = 0; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+#endif
+
+#ifdef __TURBOC__
+#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
+/* Small and medium model in Turbo C are for now limited to near allocation
+ * with reduced MAX_WBITS and MAX_MEM_LEVEL
+ */
+# define MY_ZCALLOC
+
+/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
+ * and farmalloc(64K) returns a pointer with an offset of 8, so we
+ * must fix the pointer. Warning: the pointer must be put back to its
+ * original form in order to free it, use zcfree().
+ */
+
+#define MAX_PTR 10
+/* 10*64K = 640K */
+
+local int next_ptr = 0;
+
+typedef struct ptr_table_s {
+ voidpf org_ptr;
+ voidpf new_ptr;
+} ptr_table;
+
+local ptr_table table[MAX_PTR];
+/* This table is used to remember the original form of pointers
+ * to large buffers (64K). Such pointers are normalized with a zero offset.
+ * Since MSDOS is not a preemptive multitasking OS, this table is not
+ * protected from concurrent access. This hack doesn't work anyway on
+ * a protected system like OS/2. Use Microsoft C instead.
+ */
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ voidpf buf = opaque; /* just to make some compilers happy */
+ ulg bsize = (ulg)items*size;
+
+ /* If we allocate less than 65520 bytes, we assume that farmalloc
+ * will return a usable pointer which doesn't have to be normalized.
+ */
+ if (bsize < 65520L) {
+ buf = farmalloc(bsize);
+ if (*(ush*)&buf != 0) return buf;
+ } else {
+ buf = farmalloc(bsize + 16L);
+ }
+ if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+ table[next_ptr].org_ptr = buf;
+
+ /* Normalize the pointer to seg:0 */
+ *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
+ *(ush*)&buf = 0;
+ table[next_ptr++].new_ptr = buf;
+ return buf;
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ int n;
+ if (*(ush*)&ptr != 0) { /* object < 64K */
+ farfree(ptr);
+ return;
+ }
+ /* Find the original pointer */
+ for (n = 0; n < next_ptr; n++) {
+ if (ptr != table[n].new_ptr) continue;
+
+ farfree(table[n].org_ptr);
+ while (++n < next_ptr) {
+ table[n-1] = table[n];
+ }
+ next_ptr--;
+ return;
+ }
+ ptr = opaque; /* just to make some compilers happy */
+ Assert(0, "zcfree: ptr not found");
+}
+#endif
+#endif /* __TURBOC__ */
+
+
+#if defined(M_I86) && !defined(__32BIT__)
+/* Microsoft C in 16-bit mode */
+
+# define MY_ZCALLOC
+
+#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
+# define _halloc halloc
+# define _hfree hfree
+#endif
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ return _halloc((long)items, size);
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ _hfree(ptr);
+}
+
+#endif /* MSC */
+
+
+#ifndef MY_ZCALLOC /* Any system without a special alloc function */
+
+#ifndef STDC
+extern voidp calloc OF((uInt items, uInt size));
+extern void free OF((voidpf ptr));
+#endif
+
+voidpf zcalloc (opaque, items, size)
+ voidpf opaque;
+ unsigned items;
+ unsigned size;
+{
+ if (opaque) items += size - size; /* make compiler happy */
+ return (voidpf)calloc(items, size);
+}
+
+void zcfree (opaque, ptr)
+ voidpf opaque;
+ voidpf ptr;
+{
+ free(ptr);
+ if (opaque) return; /* make compiler happy */
+}
+
+#endif /* MY_ZCALLOC */
diff --git a/osframework/source/ImageLib/zlib/zutil.h b/osframework/source/ImageLib/zlib/zutil.h
new file mode 100644
index 0000000..40483ba
--- /dev/null
+++ b/osframework/source/ImageLib/zlib/zutil.h
@@ -0,0 +1,220 @@
+/* zutil.h -- internal interface and configuration of the compression library
+ * Copyright (C) 1995-1998 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* @(#) $Id: zutil.h,v 1.1 2003/04/29 21:57:48 ace Exp $ */
+
+#ifndef _Z_UTIL_H
+#define _Z_UTIL_H
+
+#include "zlib.h"
+
+#ifdef STDC
+# include <stddef.h>
+# include <string.h>
+# include <stdlib.h>
+#endif
+#ifdef NO_ERRNO_H
+ extern int errno;
+#else
+# include <errno.h>
+#endif
+
+#ifndef local
+# define local static
+#endif
+/* compile with -Dlocal if your debugger can't find static symbols */
+
+typedef unsigned char uch;
+typedef uch FAR uchf;
+typedef unsigned short ush;
+typedef ush FAR ushf;
+typedef unsigned long ulg;
+
+extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
+/* (size given to avoid silly warnings with Visual C++) */
+
+#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
+
+#define ERR_RETURN(strm,err) \
+ return (strm->msg = (char*)ERR_MSG(err), (err))
+/* To be used only when the state is known to be valid */
+
+ /* common constants */
+
+#ifndef DEF_WBITS
+# define DEF_WBITS MAX_WBITS
+#endif
+/* default windowBits for decompression. MAX_WBITS is for compression only */
+
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+/* default memLevel */
+
+#define STORED_BLOCK 0
+#define STATIC_TREES 1
+#define DYN_TREES 2
+/* The three kinds of block type */
+
+#define MIN_MATCH 3
+#define MAX_MATCH 258
+/* The minimum and maximum match lengths */
+
+#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+
+ /* target dependencies */
+
+#ifdef MSDOS
+# define OS_CODE 0x00
+# if defined(__TURBOC__) || defined(__BORLANDC__)
+# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+ /* Allow compilation with ANSI keywords only enabled */
+ void _Cdecl farfree( void *block );
+ void *_Cdecl farmalloc( unsigned long nbytes );
+# else
+# include <alloc.h>
+# endif
+# else /* MSC or DJGPP */
+# include <malloc.h>
+# endif
+#endif
+
+#ifdef OS2
+# define OS_CODE 0x06
+#endif
+
+#ifdef WIN32 /* Window 95 & Windows NT */
+# define OS_CODE 0x0b
+#endif
+
+#if defined(VAXC) || defined(VMS)
+# define OS_CODE 0x02
+# define F_OPEN(name, mode) \
+ fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
+#endif
+
+#ifdef AMIGA
+# define OS_CODE 0x01
+#endif
+
+#if defined(ATARI) || defined(atarist)
+# define OS_CODE 0x05
+#endif
+
+#if defined(MACOS) || defined(TARGET_OS_MAC)
+# define OS_CODE 0x07
+# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fdopen */
+# else
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
+# endif
+#endif
+
+#ifdef __50SERIES /* Prime/PRIMOS */
+# define OS_CODE 0x0F
+#endif
+
+#ifdef TOPS20
+# define OS_CODE 0x0a
+#endif
+
+#if defined(_BEOS_) || defined(RISCOS)
+# define fdopen(fd,mode) NULL /* No fdopen() */
+#endif
+
+#if (defined(_MSC_VER) && (_MSC_VER > 600))
+# define fdopen(fd,type) _fdopen(fd,type)
+#endif
+
+
+ /* Common defaults */
+
+#ifndef OS_CODE
+# define OS_CODE 0x03 /* assume Unix */
+#endif
+
+#ifndef F_OPEN
+# define F_OPEN(name, mode) fopen((name), (mode))
+#endif
+
+ /* functions */
+
+#ifdef HAVE_STRERROR
+ extern char *strerror OF((int));
+# define zstrerror(errnum) strerror(errnum)
+#else
+# define zstrerror(errnum) ""
+#endif
+
+#if defined(pyr)
+# define NO_MEMCPY
+#endif
+#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
+ /* Use our own functions for small and medium model with MSC <= 5.0.
+ * You may have to use the same strategy for Borland C (untested).
+ * The __SC__ check is for Symantec.
+ */
+# define NO_MEMCPY
+#endif
+#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
+# define HAVE_MEMCPY
+#endif
+#ifdef HAVE_MEMCPY
+# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
+# define zmemcpy _fmemcpy
+# define zmemcmp _fmemcmp
+# define zmemzero(dest, len) _fmemset(dest, 0, len)
+# else
+# define zmemcpy memcpy
+# define zmemcmp memcmp
+# define zmemzero(dest, len) memset(dest, 0, len)
+# endif
+#else
+ extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
+ extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
+ extern void zmemzero OF((Bytef* dest, uInt len));
+#endif
+
+/* Diagnostic functions */
+#ifdef DEBUG
+# include <stdio.h>
+ extern int z_verbose;
+ extern void z_error OF((char *m));
+# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
+# define Trace(x) {if (z_verbose>=0) fprintf x ;}
+# define Tracev(x) {if (z_verbose>0) fprintf x ;}
+# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
+# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
+# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
+#else
+# define Assert(cond,msg)
+# define Trace(x)
+# define Tracev(x)
+# define Tracevv(x)
+# define Tracec(c,x)
+# define Tracecv(c,x)
+#endif
+
+
+typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
+ uInt len));
+voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
+void zcfree OF((voidpf opaque, voidpf ptr));
+
+#define ZALLOC(strm, items, size) \
+ (*((strm)->zalloc))((strm)->opaque, (items), (size))
+#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
+#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+
+#endif /* _Z_UTIL_H */
diff --git a/osframework/source/PakLib/PakInterface.cpp b/osframework/source/PakLib/PakInterface.cpp
new file mode 100644
index 0000000..99f57e0
--- /dev/null
+++ b/osframework/source/PakLib/PakInterface.cpp
@@ -0,0 +1,434 @@
+#include "PakInterface.h"
+#include <windows.h>
+#include <direct.h>
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned long ulong;
+
+enum
+{
+ FILEFLAGS_END = 0x80
+};
+
+PakInterface* gPakInterface = new PakInterface();
+
+static std::string StringToUpper(const std::string& theString)
+{
+ std::string aString;
+
+ for (unsigned i = 0; i < theString.length(); i++)
+ aString += toupper(theString[i]);
+
+ return aString;
+}
+
+PakInterface::PakInterface()
+{
+ if (GetPakPtr() == NULL)
+ *gPakInterfaceP = this;
+}
+
+PakInterface::~PakInterface()
+{
+}
+
+bool PakInterface::AddPakFile(const std::string& theFileName)
+{
+ HANDLE aFileHandle = CreateFile(theFileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (aFileHandle == INVALID_HANDLE_VALUE)
+ return false;
+
+ int aFileSize = GetFileSize(aFileHandle, 0);
+
+ HANDLE aFileMapping = CreateFileMapping(aFileHandle, NULL, PAGE_READONLY, 0, aFileSize, NULL);
+ if (aFileMapping == NULL)
+ {
+ CloseHandle(aFileHandle);
+ return false;
+ }
+
+ void* aPtr = MapViewOfFile(aFileMapping, FILE_MAP_READ, 0, 0, aFileSize);
+ if (aPtr == NULL)
+ {
+ CloseHandle(aFileMapping);
+ CloseHandle(aFileHandle);
+ return false;
+ }
+
+ mPakCollectionList.push_back(PakCollection());
+ PakCollection* aPakCollection = &mPakCollectionList.back();
+
+ aPakCollection->mFileHandle = aFileHandle;
+ aPakCollection->mMappingHandle = aFileMapping;
+ aPakCollection->mDataPtr = aPtr;
+
+ PakRecordMap::iterator aRecordItr = mPakRecordMap.insert(PakRecordMap::value_type(StringToUpper(theFileName), PakRecord())).first;
+ PakRecord* aPakRecord = &(aRecordItr->second);
+ aPakRecord->mCollection = aPakCollection;
+ aPakRecord->mFileName = theFileName;
+ aPakRecord->mStartPos = 0;
+ aPakRecord->mSize = aFileSize;
+
+ PFILE* aFP = FOpen(theFileName.c_str(), "rb");
+ if (aFP == NULL)
+ return false;
+
+ ulong aMagic = 0;
+ FRead(&aMagic, sizeof(ulong), 1, aFP);
+ if (aMagic != 0xBAC04AC0)
+ {
+ FClose(aFP);
+ return false;
+ }
+
+ ulong aVersion = 0;
+ FRead(&aVersion, sizeof(ulong), 1, aFP);
+ if (aVersion > 0)
+ {
+ FClose(aFP);
+ return false;
+ }
+
+ int aPos = 0;
+
+ for (;;)
+ {
+ uchar aFlags = 0;
+ int aCount = FRead(&aFlags, 1, 1, aFP);
+ if ((aFlags & FILEFLAGS_END) || (aCount == 0))
+ break;
+
+ uchar aNameWidth = 0;
+ char aName[256];
+ FRead(&aNameWidth, 1, 1, aFP);
+ FRead(aName, 1, aNameWidth, aFP);
+ aName[aNameWidth] = 0;
+
+ int aSrcSize = 0;
+ FRead(&aSrcSize, sizeof(int), 1, aFP);
+ FILETIME aFileTime;
+ FRead(&aFileTime, sizeof(FILETIME), 1, aFP);
+
+ PakRecordMap::iterator aRecordItr = mPakRecordMap.insert(PakRecordMap::value_type(StringToUpper(aName), PakRecord())).first;
+ PakRecord* aPakRecord = &(aRecordItr->second);
+ aPakRecord->mCollection = aPakCollection;
+ aPakRecord->mFileName = aName;
+ aPakRecord->mStartPos = aPos;
+ aPakRecord->mSize = aSrcSize;
+ aPakRecord->mFileTime = aFileTime;
+
+ aPos += aSrcSize;
+ }
+
+ int anOffset = FTell(aFP);
+
+ // Now fix file starts
+ aRecordItr = mPakRecordMap.begin();
+ while (aRecordItr != mPakRecordMap.end())
+ {
+ PakRecord* aPakRecord = &(aRecordItr->second);
+ if (aPakRecord->mCollection == aPakCollection)
+ aPakRecord->mStartPos += anOffset;
+ ++aRecordItr;
+ }
+
+ FClose(aFP);
+
+ return true;
+}
+
+static void FixFileName(const char* theFileName, char* theUpperName)
+{
+ if ((theFileName[0] != 0) && (theFileName[1] == ':'))
+ {
+ char aDir[256];
+ getcwd(aDir, 256);
+ int aLen = strlen(aDir);
+ aDir[aLen++] = '\\';
+ aDir[aLen] = 0;
+
+ if (strnicmp(aDir, theFileName, aLen) == 0)
+ theFileName += aLen;
+ }
+
+ bool lastSlash = false;
+ const char* aSrc = theFileName;
+ char* aDest = theUpperName;
+
+ for (;;)
+ {
+ char c = *(aSrc++);
+
+ if ((c == '\\') || (c == '/'))
+ {
+ if (!lastSlash)
+ *(aDest++) = '\\';
+ lastSlash = true;
+ }
+ else if ((c == '.') && (lastSlash) && (*aSrc == '.'))
+ {
+ // We have a '/..' on our hands
+ aDest--;
+ while ((aDest > theUpperName + 1) && (*(aDest-1) != '\\'))
+ --aDest;
+ aSrc++;
+ }
+ else
+ {
+ *(aDest++) = toupper((uchar) c);
+ if (c == 0)
+ break;
+ lastSlash = false;
+ }
+ }
+}
+
+PFILE* PakInterface::FOpen(const char* theFileName, const char* anAccess)
+{
+ if ((stricmp(anAccess, "r") == 0) || (stricmp(anAccess, "rb") == 0) || (stricmp(anAccess, "rt") == 0))
+ {
+ char anUpperName[256];
+ FixFileName(theFileName, anUpperName);
+
+ PakRecordMap::iterator anItr = mPakRecordMap.find(anUpperName);
+ if (anItr != mPakRecordMap.end())
+ {
+ PFILE* aPFP = new PFILE;
+ aPFP->mRecord = &anItr->second;
+ aPFP->mPos = 0;
+ aPFP->mFP = NULL;
+ return aPFP;
+ }
+ }
+
+ FILE* aFP = fopen(theFileName, anAccess);
+ if (aFP == NULL)
+ return NULL;
+ PFILE* aPFP = new PFILE;
+ aPFP->mRecord = NULL;
+ aPFP->mPos = 0;
+ aPFP->mFP = aFP;
+ return aPFP;
+}
+
+int PakInterface::FClose(PFILE* theFile)
+{
+ if (theFile->mRecord == NULL)
+ fclose(theFile->mFP);
+ delete theFile;
+ return 0;
+}
+
+int PakInterface::FSeek(PFILE* theFile, long theOffset, int theOrigin)
+{
+ if (theFile->mRecord != NULL)
+ {
+ if (theOrigin == SEEK_SET)
+ theFile->mPos = theOffset;
+ else if (theOrigin == SEEK_END)
+ theFile->mPos = theFile->mRecord->mSize - theOffset;
+ else if (theOrigin == SEEK_CUR)
+ theFile->mPos += theOffset;
+
+ theFile->mPos = max(min(theFile->mPos, theFile->mRecord->mSize), 0);
+ return 0;
+ }
+ else
+ return fseek(theFile->mFP, theOffset, theOrigin);
+}
+
+int PakInterface::FTell(PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ return theFile->mPos;
+ else
+ return ftell(theFile->mFP);
+}
+
+size_t PakInterface::FRead(void* thePtr, int theElemSize, int theCount, PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ {
+ int aSizeBytes = min(theElemSize*theCount, theFile->mRecord->mSize - theFile->mPos);
+
+ uchar* src = (uchar*) theFile->mRecord->mCollection->mDataPtr + theFile->mRecord->mStartPos + theFile->mPos;
+ uchar* dest = (uchar*) thePtr;
+ for (int i = 0; i < aSizeBytes; i++)
+ *(dest++) = (*src++) ^ 0xF7; // 'Decrypt'
+ theFile->mPos += aSizeBytes;
+ return aSizeBytes / theElemSize;
+ }
+
+ return fread(thePtr, theElemSize, theCount, theFile->mFP);
+}
+
+int PakInterface::FGetC(PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ {
+ for (;;)
+ {
+ if (theFile->mPos >= theFile->mRecord->mSize)
+ return EOF;
+ char aChar = *((char*) theFile->mRecord->mCollection->mDataPtr + theFile->mRecord->mStartPos + theFile->mPos++) ^ 0xF7;
+ if (aChar != '\r')
+ return (uchar) aChar;
+ }
+ }
+
+ return fgetc(theFile->mFP);
+}
+
+int PakInterface::UnGetC(int theChar, PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ {
+ // This won't work if we're not pushing the same chars back in the stream
+ theFile->mPos = max(theFile->mPos - 1, 0);
+ return theChar;
+ }
+
+ return ungetc(theChar, theFile->mFP);
+}
+
+char* PakInterface::FGetS(char* thePtr, int theSize, PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ {
+ int anIdx = 0;
+ while (anIdx < theSize)
+ {
+ if (theFile->mPos >= theFile->mRecord->mSize)
+ {
+ if (anIdx == 0)
+ return NULL;
+ break;
+ }
+ char aChar = *((char*) theFile->mRecord->mCollection->mDataPtr + theFile->mRecord->mStartPos + theFile->mPos++) ^ 0xF7;
+ if (aChar != '\r')
+ thePtr[anIdx++] = aChar;
+ if (aChar == '\n')
+ break;
+ }
+ thePtr[anIdx] = 0;
+ return thePtr;
+ }
+
+ return fgets(thePtr, theSize, theFile->mFP);
+}
+
+int PakInterface::FEof(PFILE* theFile)
+{
+ if (theFile->mRecord != NULL)
+ return theFile->mPos >= theFile->mRecord->mSize;
+ else
+ return feof(theFile->mFP);
+}
+
+bool PakInterface::PFindNext(PFindData* theFindData, LPWIN32_FIND_DATA lpFindFileData)
+{
+ PakRecordMap::iterator anItr;
+ if (theFindData->mLastFind.size() == 0)
+ anItr = mPakRecordMap.begin();
+ else
+ {
+ anItr = mPakRecordMap.find(theFindData->mLastFind);
+ if (anItr != mPakRecordMap.end())
+ anItr++;
+ }
+
+ while (anItr != mPakRecordMap.end())
+ {
+ const char* aFileName = anItr->first.c_str();
+ PakRecord* aPakRecord = &anItr->second;
+
+ int aStarPos = (int) theFindData->mFindCriteria.find('*');
+ if (aStarPos != -1)
+ {
+ if (strncmp(theFindData->mFindCriteria.c_str(), aFileName, aStarPos) == 0)
+ {
+ // First part matches
+ const char* anEndData = theFindData->mFindCriteria.c_str() + aStarPos + 1;
+ if ((*anEndData == 0) || (strcmp(anEndData, ".*") == 0) ||
+ (strcmp(theFindData->mFindCriteria.c_str() + aStarPos + 1,
+ aFileName + strlen(aFileName) - (theFindData->mFindCriteria.length() - aStarPos) + 1) == 0))
+ {
+ // Matches before and after star
+ memset(lpFindFileData, 0, sizeof(lpFindFileData));
+
+ int aLastSlashPos = (int) anItr->second.mFileName.rfind('\\');
+ if (aLastSlashPos == -1)
+ strcpy(lpFindFileData->cFileName, anItr->second.mFileName.c_str());
+ else
+ strcpy(lpFindFileData->cFileName, anItr->second.mFileName.c_str() + aLastSlashPos + 1);
+
+ const char* aEndStr = aFileName + strlen(aFileName) - (theFindData->mFindCriteria.length() - aStarPos) + 1;
+ if (strchr(aEndStr, '\\') != NULL)
+ lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
+
+ lpFindFileData->nFileSizeLow = aPakRecord->mSize;
+ lpFindFileData->ftCreationTime = aPakRecord->mFileTime;
+ lpFindFileData->ftLastWriteTime = aPakRecord->mFileTime;
+ lpFindFileData->ftLastAccessTime = aPakRecord->mFileTime;
+ theFindData->mLastFind = aFileName;
+
+ return true;
+ }
+ }
+ }
+
+ ++anItr;
+ }
+
+ return false;
+}
+
+HANDLE PakInterface::FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
+{
+ PFindData* aFindData = new PFindData;
+
+ char anUpperName[256];
+ FixFileName(lpFileName, anUpperName);
+ aFindData->mFindCriteria = anUpperName;
+ aFindData->mWHandle = INVALID_HANDLE_VALUE;
+
+ if (PFindNext(aFindData, lpFindFileData))
+ return (HANDLE) aFindData;
+
+ aFindData->mWHandle = ::FindFirstFile(aFindData->mFindCriteria.c_str(), lpFindFileData);
+ if (aFindData->mWHandle != INVALID_HANDLE_VALUE)
+ return (HANDLE) aFindData;
+
+ delete aFindData;
+ return INVALID_HANDLE_VALUE;
+}
+
+BOOL PakInterface::FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData)
+{
+ PFindData* aFindData = (PFindData*) hFindFile;
+
+ if (aFindData->mWHandle == INVALID_HANDLE_VALUE)
+ {
+ if (PFindNext(aFindData, lpFindFileData))
+ return TRUE;
+
+ aFindData->mWHandle = ::FindFirstFile(aFindData->mFindCriteria.c_str(), lpFindFileData);
+ return (aFindData->mWHandle != INVALID_HANDLE_VALUE);
+ }
+
+ return ::FindNextFile(aFindData->mWHandle, lpFindFileData);
+}
+
+BOOL PakInterface::FindClose(HANDLE hFindFile)
+{
+ PFindData* aFindData = (PFindData*) hFindFile;
+
+ if (aFindData->mWHandle != INVALID_HANDLE_VALUE)
+ ::FindClose(aFindData->mWHandle);
+
+ delete aFindData;
+ return TRUE;
+}
+
diff --git a/osframework/source/PakLib/PakInterface.h b/osframework/source/PakLib/PakInterface.h
new file mode 100644
index 0000000..22a9c5a
--- /dev/null
+++ b/osframework/source/PakLib/PakInterface.h
@@ -0,0 +1,237 @@
+#ifndef __PAKINTERFACE_H__
+#define __PAKINTERFACE_H__
+
+#include <map>
+#include <list>
+#include <string>
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+class PakCollection;
+
+class PakRecord
+{
+public:
+ PakCollection* mCollection;
+ std::string mFileName;
+ FILETIME mFileTime;
+ int mStartPos;
+ int mSize;
+};
+
+typedef std::map<std::string, PakRecord> PakRecordMap;
+
+class PakCollection
+{
+public:
+ HANDLE mFileHandle;
+ HANDLE mMappingHandle;
+ void* mDataPtr;
+};
+
+typedef std::list<PakCollection> PakCollectionList;
+
+struct PFILE
+{
+ PakRecord* mRecord;
+ int mPos;
+ FILE* mFP;
+};
+
+struct PFindData
+{
+ HANDLE mWHandle;
+ std::string mLastFind;
+ std::string mFindCriteria;
+};
+
+class PakInterfaceBase
+{
+public:
+ virtual PFILE* FOpen(const char* theFileName, const char* theAccess) = 0;
+ virtual PFILE* FOpen(const wchar_t* theFileName, const wchar_t* theAccess) { return NULL; }
+ virtual int FClose(PFILE* theFile) = 0;
+ virtual int FSeek(PFILE* theFile, long theOffset, int theOrigin) = 0;
+ virtual int FTell(PFILE* theFile) = 0;
+ virtual size_t FRead(void* thePtr, int theElemSize, int theCount, PFILE* theFile) = 0;
+ virtual int FGetC(PFILE* theFile) = 0;
+ virtual int UnGetC(int theChar, PFILE* theFile) = 0;
+ virtual char* FGetS(char* thePtr, int theSize, PFILE* theFile) = 0;
+ virtual wchar_t* FGetS(wchar_t* thePtr, int theSize, PFILE* theFile) { return thePtr; }
+ virtual int FEof(PFILE* theFile) = 0;
+
+ virtual HANDLE FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData) = 0;
+ virtual BOOL FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData) = 0;
+ virtual BOOL FindClose(HANDLE hFindFile) = 0;
+};
+
+class PakInterface : public PakInterfaceBase
+{
+public:
+ PakCollectionList mPakCollectionList;
+ PakRecordMap mPakRecordMap;
+
+public:
+ bool PFindNext(PFindData* theFindData, LPWIN32_FIND_DATA lpFindFileData);
+
+public:
+ PakInterface();
+ ~PakInterface();
+
+ bool AddPakFile(const std::string& theFileName);
+ PFILE* FOpen(const char* theFileName, const char* theAccess);
+ int FClose(PFILE* theFile);
+ int FSeek(PFILE* theFile, long theOffset, int theOrigin);
+ int FTell(PFILE* theFile);
+ size_t FRead(void* thePtr, int theElemSize, int theCount, PFILE* theFile);
+ int FGetC(PFILE* theFile);
+ int UnGetC(int theChar, PFILE* theFile);
+ char* FGetS(char* thePtr, int theSize, PFILE* theFile);
+ int FEof(PFILE* theFile);
+
+ HANDLE FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
+ BOOL FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData);
+ BOOL FindClose(HANDLE hFindFile);
+};
+
+extern PakInterface* gPakInterface;
+
+static HANDLE gPakFileMapping = NULL;
+static PakInterfaceBase** gPakInterfaceP = NULL;
+
+static PakInterfaceBase* GetPakPtr()
+{
+ if (gPakFileMapping == NULL)
+ {
+ char aName[256];
+ sprintf(aName, "gPakInterfaceP_%d", GetCurrentProcessId());
+ gPakFileMapping = ::CreateFileMappingA((HANDLE)INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(PakInterface*), aName);
+ gPakInterfaceP = (PakInterfaceBase**) MapViewOfFile(gPakFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(PakInterface*));
+ }
+ return *gPakInterfaceP;
+}
+
+static PFILE* p_fopen(const char* theFileName, const char* theAccess)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FOpen(theFileName, theAccess);
+ FILE* aFP = fopen(theFileName, theAccess);
+ if (aFP == NULL)
+ return NULL;
+ PFILE* aPFile = new PFILE();
+ aPFile->mRecord = NULL;
+ aPFile->mPos = 0;
+ aPFile->mFP = aFP;
+ return aPFile;
+}
+
+static PFILE* p_fopen(const wchar_t* theFileName, const wchar_t* theAccess)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FOpen(theFileName, theAccess);
+ FILE* aFP = _wfopen(theFileName, theAccess);
+ if (aFP == NULL)
+ return NULL;
+ PFILE* aPFile = new PFILE();
+ aPFile->mRecord = NULL;
+ aPFile->mPos = 0;
+ aPFile->mFP = aFP;
+ return aPFile;
+}
+
+static int p_fclose(PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FClose(theFile);
+ int aResult = fclose(theFile->mFP);
+ delete theFile;
+ return aResult;
+}
+
+static int p_fseek(PFILE* theFile, long theOffset, int theOrigin)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FSeek(theFile, theOffset, theOrigin);
+ return fseek(theFile->mFP, theOffset, theOrigin);
+}
+
+static int p_ftell(PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FTell(theFile);
+ return ftell(theFile->mFP);
+}
+
+static size_t p_fread(void* thePtr, int theSize, int theCount, PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FRead(thePtr, theSize, theCount, theFile);
+ return fread(thePtr, theSize, theCount, theFile->mFP);
+}
+
+static size_t p_fwrite(const void* thePtr, int theSize, int theCount, PFILE* theFile)
+{
+ if (theFile->mFP == NULL)
+ return 0;
+ return fwrite(thePtr, theSize, theCount, theFile->mFP);
+}
+
+static int p_fgetc(PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FGetC(theFile);
+ return fgetc(theFile->mFP);
+}
+
+static int p_ungetc(int theChar, PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->UnGetC(theChar, theFile);
+ return ungetc(theChar, theFile->mFP);
+}
+
+static char* p_fgets(char* thePtr, int theSize, PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FGetS(thePtr, theSize, theFile);
+ return fgets(thePtr, theSize, theFile->mFP);
+}
+
+static wchar_t* p_fgets(wchar_t* thePtr, int theSize, PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FGetS(thePtr, theSize, theFile);
+ return fgetws(thePtr, theSize, theFile->mFP);
+}
+
+static int p_feof(PFILE* theFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FEof(theFile);
+ return feof(theFile->mFP);
+}
+
+static HANDLE p_FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FindFirstFile(lpFileName, lpFindFileData);
+ return FindFirstFile(lpFileName, lpFindFileData);
+}
+
+static BOOL p_FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FindNextFile(hFindFile, lpFindFileData);
+ return FindNextFile(hFindFile, lpFindFileData);
+}
+
+static BOOL p_FindClose(HANDLE hFindFile)
+{
+ if (GetPakPtr() != NULL)
+ return (*gPakInterfaceP)->FindClose(hFindFile);
+ return FindClose(hFindFile);
+}
+
+
+#endif //__PAKINTERFACE_H__
diff --git a/osframework/source/SexyAppFramework/AutoCrit.h b/osframework/source/SexyAppFramework/AutoCrit.h
new file mode 100644
index 0000000..09357e3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/AutoCrit.h
@@ -0,0 +1,34 @@
+#ifndef __AUTOCRIT_INCLUDED__
+#define __AUTOCRIT_INCLUDED__
+
+#include "Common.h"
+#include "CritSect.h"
+
+namespace Sexy
+{
+
+class AutoCrit
+{
+ LPCRITICAL_SECTION mCritSec;
+public:
+ AutoCrit(LPCRITICAL_SECTION theCritSec) :
+ mCritSec(theCritSec)
+ {
+ EnterCriticalSection(mCritSec);
+ }
+
+ AutoCrit(const CritSect& theCritSect) :
+ mCritSec((LPCRITICAL_SECTION) &theCritSect.mCriticalSection)
+ {
+ EnterCriticalSection(mCritSec);
+ }
+
+ ~AutoCrit()
+ {
+ LeaveCriticalSection(mCritSec);
+ }
+};
+
+}
+
+#endif //__AUTOCRIT_INCLUDED__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/BassLoader.cpp b/osframework/source/SexyAppFramework/BassLoader.cpp
new file mode 100644
index 0000000..a88108a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/BassLoader.cpp
@@ -0,0 +1,197 @@
+#include "BassLoader.h"
+#include <stdlib.h>
+
+using namespace Sexy;
+
+BASS_INSTANCE* Sexy::gBass = NULL;
+static long gBassLoadCount = 0;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CheckBassFunction(unsigned int theFunc, const char *theName)
+{
+ if (theFunc==0)
+ {
+ char aBuf[1024];
+ sprintf(aBuf,"%s function not found in bass.dll",theName);
+ MessageBoxA(NULL,aBuf,"Error",MB_OK | MB_ICONERROR);
+ exit(0);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+BASS_INSTANCE::BASS_INSTANCE(const char *dllName)
+{
+ mModule = LoadLibrary(dllName);
+ if (!mModule)
+ return;
+
+#define GETPROC(_x) CheckBassFunction(*((unsigned int *)&_x) = (unsigned int)GetProcAddress(mModule, #_x),#_x)
+
+ GETPROC(BASS_Init);
+ GETPROC(BASS_Free);
+ GETPROC(BASS_Stop);
+ GETPROC(BASS_Start);
+
+ *((unsigned int*) &BASS_SetGlobalVolumes) = (unsigned int) GetProcAddress(mModule, "BASS_SetGlobalVolumes");
+ *((unsigned int*) &BASS_SetVolume) = (unsigned int) GetProcAddress(mModule, "BASS_SetVolume");
+
+ if ((BASS_SetVolume == NULL) && (BASS_SetGlobalVolumes == NULL))
+ {
+ MessageBoxA(NULL,"Neither BASS_SetGlobalVolumes or BASS_SetVolume found in bass.dll","Error",MB_OK | MB_ICONERROR);
+ exit(0);
+ }
+
+ *((unsigned int*) &BASS_SetConfig) = (unsigned int) GetProcAddress(mModule, "BASS_SetConfig");
+ *((unsigned int*) &BASS_GetConfig) = (unsigned int) GetProcAddress(mModule, "BASS_GetConfig");
+
+ GETPROC(BASS_GetVolume);
+ GETPROC(BASS_GetInfo);
+
+ GETPROC(BASS_GetVersion);
+ GETPROC(BASS_ChannelStop);
+ GETPROC(BASS_ChannelPlay);
+ GETPROC(BASS_ChannelPause);
+ GETPROC(BASS_ChannelSetAttributes);
+ GETPROC(BASS_ChannelGetAttributes);
+ GETPROC(BASS_ChannelSetPosition);
+ GETPROC(BASS_ChannelGetPosition);
+ GETPROC(BASS_ChannelIsActive);
+ GETPROC(BASS_ChannelSetFlags);
+ GETPROC(BASS_ChannelSlideAttributes);
+ GETPROC(BASS_ChannelIsSliding);
+ GETPROC(BASS_ChannelGetLevel);
+ GETPROC(BASS_ChannelSetSync);
+ GETPROC(BASS_ChannelRemoveSync);
+ GETPROC(BASS_ChannelGetData);
+
+ // supported by BASS 1.1 and higher. Only work if the user has DX8 or higher though.
+ GETPROC(BASS_FXSetParameters);
+ GETPROC(BASS_FXGetParameters);
+ GETPROC(BASS_ChannelSetFX);
+ GETPROC(BASS_ChannelRemoveFX);
+
+ GETPROC(BASS_MusicLoad);
+ GETPROC(BASS_MusicFree);
+ GETPROC(BASS_MusicGetAttribute);
+ GETPROC(BASS_MusicSetAttribute);
+
+ GETPROC(BASS_StreamCreateFile);
+ GETPROC(BASS_StreamFree);
+
+ GETPROC(BASS_MusicGetOrders);
+ GETPROC(BASS_MusicGetOrderPosition);
+
+ GETPROC(BASS_SampleLoad);
+ GETPROC(BASS_SampleFree);
+ GETPROC(BASS_SampleSetInfo);
+ GETPROC(BASS_SampleGetInfo);
+ GETPROC(BASS_SampleGetChannel);
+ GETPROC(BASS_SampleStop);
+
+ GETPROC(BASS_ErrorGetCode);
+
+ mVersion2 = BASS_SetConfig != NULL;
+ if (mVersion2)
+ {
+ // Version 2 has different BASS_Init params
+ *((unsigned int*) &BASS_Init2) = (unsigned int) BASS_Init;
+ BASS_Init = NULL;
+
+ *((unsigned int*) &BASS_MusicLoad2) = (unsigned int) BASS_MusicLoad;
+ BASS_MusicLoad = NULL;
+
+ // The following are only supported in 2.2 and higher
+ *((unsigned int*) &BASS_PluginLoad) = (unsigned int) GetProcAddress(mModule, "BASS_PluginLoad");
+ *((unsigned int*) &BASS_ChannelGetLength) = (unsigned int) GetProcAddress(mModule, "BASS_ChannelGetLength");
+
+ // 2.1 and higher only
+ *((unsigned int*) &BASS_ChannelPreBuf) = (unsigned int) GetProcAddress(mModule, "BASS_ChannelPreBuf");
+ }
+ else
+ {
+ BASS_PluginLoad = NULL;
+ BASS_ChannelPreBuf = NULL;
+ }
+
+#undef GETPROC
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+BASS_INSTANCE::~BASS_INSTANCE()
+{
+ if (mModule)
+ FreeLibrary(mModule);
+}
+
+
+BOOL BASS_INSTANCE::BASS_MusicSetAmplify(HMUSIC handle, DWORD amp)
+{
+ BASS_MusicSetAttribute(handle, BASS_MUSIC_ATTRIB_AMPLIFY, amp);
+ return true;
+}
+
+
+BOOL BASS_INSTANCE::BASS_MusicPlay(HMUSIC handle)
+{
+ return BASS_ChannelPlay(handle, true);
+}
+
+
+BOOL BASS_INSTANCE::BASS_MusicPlayEx(HMUSIC handle, DWORD pos, int flags, BOOL reset)
+{
+ int anOffset = MAKEMUSICPOS(pos,0);
+
+ BASS_ChannelStop(handle);
+ BASS_ChannelSetPosition(handle, anOffset);
+ BASS_ChannelSetFlags(handle, flags);
+
+ return BASS_ChannelPlay(handle, false/*reset*/);
+}
+
+
+BOOL BASS_INSTANCE::BASS_ChannelResume(DWORD handle)
+{
+ return BASS_ChannelPlay(handle, false);
+}
+
+BOOL BASS_INSTANCE::BASS_StreamPlay(HSTREAM handle, BOOL flush, DWORD flags)
+{
+ BASS_ChannelSetFlags(handle, flags);
+ return BASS_ChannelPlay(handle, flush);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Sexy::LoadBassDLL()
+{
+ InterlockedIncrement(&gBassLoadCount);
+ if (gBass!=NULL)
+ return;
+
+ gBass = new BASS_INSTANCE(".\\bass.dll");
+ if (gBass->mModule==NULL)
+ {
+ MessageBoxA(NULL,"Can't find bass.dll." ,"Error",MB_OK | MB_ICONERROR);
+ exit(0);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Sexy::FreeBassDLL()
+{
+ if (gBass!=NULL)
+ {
+ if (InterlockedDecrement(&gBassLoadCount) <= 0)
+ {
+ delete gBass;
+ gBass = NULL;
+ }
+ }
+}
+
+
diff --git a/osframework/source/SexyAppFramework/BassLoader.h b/osframework/source/SexyAppFramework/BassLoader.h
new file mode 100644
index 0000000..b72428a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/BassLoader.h
@@ -0,0 +1,104 @@
+#ifndef __BASSLOADER_H__
+#define __BASSLOADER_H__
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdio.h>
+
+#include "bass.h"
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+namespace Sexy
+{
+
+struct BASS_INSTANCE
+{
+ BASS_INSTANCE(const char *dllName);
+ virtual ~BASS_INSTANCE();
+
+ BOOL BASS_MusicSetAmplify(HMUSIC handle, DWORD amp);
+ BOOL BASS_MusicPlay(HMUSIC handle);
+ BOOL BASS_MusicPlayEx(HMUSIC handle, DWORD pos, int flags, BOOL reset);
+ BOOL BASS_ChannelResume(DWORD handle);
+ BOOL BASS_StreamPlay(HSTREAM handle, BOOL flush, DWORD flags);
+
+
+
+ HMODULE mModule;
+ bool mVersion2;
+
+ DWORD(WINAPI *BASS_GetVersion)();
+
+ BOOL(WINAPI *BASS_Init)(int device, DWORD freq, DWORD flags, HWND win);
+ BOOL(WINAPI *BASS_Init2)(int device, DWORD freq, DWORD flags, HWND win, GUID* clsid);
+ void(WINAPI *BASS_Free)();
+ BOOL(WINAPI *BASS_Stop)();
+ BOOL(WINAPI *BASS_Start)();
+ void(WINAPI *BASS_SetGlobalVolumes)(int musvol, int samvol, int strvol);
+ BOOL(WINAPI *BASS_SetVolume)(DWORD volume);
+ BOOL(WINAPI *BASS_GetVolume)();
+ BOOL(WINAPI *BASS_GetInfo)(BASS_INFO* info);
+
+ DWORD(WINAPI *BASS_SetConfig)(DWORD option, DWORD value);
+ DWORD(WINAPI *BASS_GetConfig)(DWORD option);
+
+ BOOL(WINAPI *BASS_ChannelStop)(DWORD handle);
+ BOOL(WINAPI *BASS_ChannelPlay)(DWORD handle, BOOL restart);
+ BOOL(WINAPI *BASS_ChannelPause)(DWORD handle);
+ BOOL(WINAPI *BASS_ChannelSetAttributes)(DWORD handle, int freq, int volume, int pan);
+ BOOL(WINAPI *BASS_ChannelGetAttributes)(DWORD handle, DWORD* freq, DWORD* volume, int* pan);
+ BOOL(WINAPI *BASS_ChannelSetPosition)(DWORD handle, QWORD pos);
+ QWORD(WINAPI *BASS_ChannelGetPosition)(DWORD handle);
+ BOOL (WINAPI *BASS_ChannelSetFlags)(DWORD handle, DWORD flags);
+ DWORD(WINAPI *BASS_ChannelIsActive)(DWORD handle);
+ BOOL (WINAPI *BASS_ChannelSlideAttributes)(DWORD handle, int freq, int volume, int pan, DWORD time);
+ DWORD (WINAPI *BASS_ChannelIsSliding)(DWORD handle);
+ DWORD (WINAPI *BASS_ChannelGetLevel)(DWORD handle);
+ HFX (WINAPI *BASS_ChannelSetFX)(DWORD handle, DWORD theType, int priority);
+ BOOL (WINAPI *BASS_ChannelRemoveFX)(DWORD handle, HFX fx);
+ QWORD (WINAPI *BASS_ChannelGetLength)(DWORD handle);
+ DWORD (WINAPI *BASS_ChannelGetData)(DWORD handle, void* buffer, DWORD length);
+ BOOL (WINAPI *BASS_ChannelPreBuf)(DWORD handle, DWORD length);
+ HSYNC (WINAPI *BASS_ChannelSetSync)(DWORD handle, DWORD theType, QWORD theParam, SYNCPROC* proc, DWORD user);
+ BOOL (WINAPI *BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync);
+
+ HMUSIC(WINAPI *BASS_MusicLoad)(BOOL mem, void *file, DWORD offset, DWORD length, DWORD flags);
+ HMUSIC(WINAPI *BASS_MusicLoad2)(BOOL mem, void *file, DWORD offset, DWORD length, DWORD flags, DWORD freq);
+ void(WINAPI *BASS_MusicFree)(HMUSIC handle);
+
+ HSTREAM(WINAPI *BASS_StreamCreateFile)(BOOL mem, void *file, DWORD offset, DWORD length, DWORD flags);
+ void(WINAPI *BASS_StreamFree)(HSTREAM handle);
+
+ BOOL (WINAPI *BASS_FXSetParameters)(HFX handle, void *par);
+ BOOL (WINAPI *BASS_FXGetParameters)(HFX handle, void *par);
+
+ DWORD(WINAPI *BASS_MusicGetAttribute)(DWORD handle, DWORD attrib);
+ void(WINAPI *BASS_MusicSetAttribute)(DWORD handle, DWORD attrib,DWORD value);
+
+ DWORD (WINAPI *BASS_MusicGetOrders)(HMUSIC handle);
+ DWORD (WINAPI *BASS_MusicGetOrderPosition)(HMUSIC handle);
+
+ HPLUGIN (WINAPI *BASS_PluginLoad)(char *file, DWORD flags);
+
+ HSAMPLE (WINAPI *BASS_SampleLoad)(BOOL mem, void *file, DWORD offset, DWORD length, DWORD max, DWORD flags);
+ BOOL (WINAPI *BASS_SampleFree)(HSAMPLE handle);
+ BOOL (WINAPI *BASS_SampleSetInfo)(HSAMPLE handle, BASS_SAMPLE *info);
+ BOOL (WINAPI *BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info);
+ HCHANNEL (WINAPI *BASS_SampleGetChannel)(HSAMPLE handle, BOOL onlynew);
+ BOOL (WINAPI *BASS_SampleStop)(HSAMPLE handle);
+
+ int (WINAPI *BASS_ErrorGetCode)();
+};
+
+
+extern BASS_INSTANCE *gBass;
+
+BASS_INSTANCE* BASS_CreateInstance(char *dllName);
+void BASS_FreeInstance(BASS_INSTANCE *instance);
+void LoadBassDLL(); // exits on failure
+void FreeBassDLL();
+
+} // namespace Sexy
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/BassMusicInterface.cpp b/osframework/source/SexyAppFramework/BassMusicInterface.cpp
new file mode 100644
index 0000000..06c8f77
--- /dev/null
+++ b/osframework/source/SexyAppFramework/BassMusicInterface.cpp
@@ -0,0 +1,425 @@
+#include "BassMusicInterface.h"
+#include "BassLoader.h"
+#include "..\PakLib\PakInterface.h"
+
+using namespace Sexy;
+
+#define BASS2_MUSIC_RAMP BASS_MUSIC_RAMP // normal ramping
+
+#define BASS_CONFIG_BUFFER 0
+
+BassMusicInfo::BassMusicInfo()
+{
+ mVolume = 0.0;
+ mVolumeAdd = 0.0;
+ mVolumeCap = 1.0;
+ mStopOnFade = false;
+ mHMusic = NULL;
+ mHStream = NULL;
+}
+
+BassMusicInterface::BassMusicInterface(HWND theHWnd)
+{
+ LoadBassDLL();
+
+ MIXERCONTROLDETAILS mcd;
+ MIXERCONTROLDETAILS_UNSIGNED mxcd_u;
+ MIXERLINECONTROLS mxlc;
+ MIXERCONTROL mlct;
+ MIXERLINE mixerLine;
+ HMIXEROBJ phmx;
+ MIXERCAPS pmxcaps;
+
+ mixerOpen((HMIXER*) &phmx, 0, 0, 0, MIXER_OBJECTF_MIXER);
+ mixerGetDevCaps(0, &pmxcaps, sizeof(pmxcaps));
+
+ mxlc.cbStruct = sizeof(mxlc);
+ mxlc.cbmxctrl = sizeof(mlct);
+ mxlc.pamxctrl = &mlct;
+ mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
+ mixerLine.cbStruct = sizeof(mixerLine);
+ mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
+ mixerGetLineInfo(phmx, &mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE);
+ mxlc.dwLineID = mixerLine.dwLineID;
+ mixerGetLineControls(phmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
+
+ mcd.cbStruct = sizeof(mcd);
+ mcd.dwControlID = mlct.dwControlID;
+ mcd.cChannels = 1;
+ mcd.cMultipleItems = 0;
+ mcd.cbDetails = sizeof(mxcd_u);
+ mcd.paDetails = &mxcd_u;
+
+ mixerGetControlDetails(phmx, &mcd, 0L);
+
+ //return mxcd_u.dwValue;
+
+ BOOL success;
+
+ if (gBass->mVersion2)
+ {
+ success = gBass->BASS_Init2(1, 44100, 0, theHWnd, NULL);
+ gBass->BASS_SetConfig(BASS_CONFIG_BUFFER, 2000);
+ }
+ else
+ success = gBass->BASS_Init(-1, 44100, 0, theHWnd);
+
+ mixerSetControlDetails(phmx, &mcd, 0L);
+
+ gBass->BASS_Start();
+
+ mixerClose((HMIXER) phmx);
+
+ mMaxMusicVolume = 40;
+
+ mMusicLoadFlags = gBass->mVersion2 ? BASS_MUSIC_LOOP | BASS2_MUSIC_RAMP : BASS_MUSIC_LOOP;
+}
+
+BassMusicInterface::~BassMusicInterface()
+{
+ gBass->BASS_Stop();
+ gBass->BASS_Free();
+
+ FreeBassDLL();
+}
+
+bool BassMusicInterface::LoadMusic(int theSongId, const std::string& theFileName)
+{
+ HMUSIC aHMusic = NULL;
+ HSTREAM aStream = NULL;
+
+ std::string anExt;
+ int aDotPos = theFileName.find_last_of('.');
+ if (aDotPos!=std::string::npos)
+ anExt = StringToLower(theFileName.substr(aDotPos+1));
+
+ if (anExt=="wav" || anExt=="ogg" || anExt=="mp3")
+ aStream = gBass->BASS_StreamCreateFile(FALSE, (void*) theFileName.c_str(), 0, 0, 0);
+ else
+ {
+ PFILE* aFP = p_fopen(theFileName.c_str(), "rb");
+ if (aFP == NULL)
+ return false;
+
+ p_fseek(aFP, 0, SEEK_END);
+ int aSize = p_ftell(aFP);
+ p_fseek(aFP, 0, SEEK_SET);
+
+ uchar* aData = new uchar[aSize];
+ p_fread(aData, 1, aSize, aFP);
+ p_fclose(aFP);
+
+ if (gBass->mVersion2)
+ aHMusic = gBass->BASS_MusicLoad2(FALSE, (void*) theFileName.c_str(), 0, 0, BASS_MUSIC_LOOP | BASS2_MUSIC_RAMP, 0);
+ else
+ aHMusic = gBass->BASS_MusicLoad(FALSE, (void*) theFileName.c_str(), 0, 0, BASS_MUSIC_LOOP);
+
+ delete aData;
+ }
+
+ if (aHMusic==NULL && aStream==NULL)
+ return false;
+
+ BassMusicInfo aMusicInfo;
+ aMusicInfo.mHMusic = aHMusic;
+ aMusicInfo.mHStream = aStream;
+ mMusicMap.insert(BassMusicMap::value_type(theSongId, aMusicInfo));
+
+ return true;
+}
+
+void BassMusicInterface::PlayMusic(int theSongId, int theOffset, bool noLoop)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = aMusicInfo->mVolumeCap;
+ aMusicInfo->mVolumeAdd = 0.0;
+ aMusicInfo->mStopOnFade = noLoop;
+ gBass->BASS_ChannelSetAttributes(aMusicInfo->GetHandle(), -1, (int) (aMusicInfo->mVolume*100), -101);
+
+ gBass->BASS_ChannelStop(aMusicInfo->GetHandle());
+ if (aMusicInfo->mHMusic)
+ {
+ if (gBass->mVersion2)
+ gBass->BASS_MusicPlayEx(aMusicInfo->mHMusic, theOffset, BASS_MUSIC_POSRESET | BASS2_MUSIC_RAMP | (noLoop ? 0 : BASS_MUSIC_LOOP), TRUE);
+ else
+ gBass->BASS_MusicPlayEx(aMusicInfo->mHMusic, theOffset, noLoop ? 0 : BASS_MUSIC_LOOP, TRUE);
+ }
+ else
+ {
+ BOOL flush = theOffset == -1 ? FALSE : TRUE;
+ gBass->BASS_StreamPlay(aMusicInfo->mHStream, flush, noLoop ? 0 : BASS_MUSIC_LOOP);
+ if (theOffset > 0)
+ gBass->BASS_ChannelSetPosition(aMusicInfo->mHStream, theOffset);
+ }
+ }
+}
+
+void BassMusicInterface::StopMusic(int theSongId)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = 0.0;
+ gBass->BASS_ChannelStop(aMusicInfo->GetHandle());
+ }
+}
+
+void BassMusicInterface::StopAllMusic()
+{
+ BassMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = 0.0;
+ gBass->BASS_ChannelStop(aMusicInfo->GetHandle());
+ ++anItr;
+ }
+}
+
+void BassMusicInterface::UnloadMusic(int theSongId)
+{
+ StopMusic(theSongId);
+
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ if (aMusicInfo->mHStream)
+ gBass->BASS_StreamFree(aMusicInfo->mHStream);
+ else if (aMusicInfo->mHMusic)
+ gBass->BASS_MusicFree(aMusicInfo->mHMusic);
+
+ mMusicMap.erase(anItr);
+ }
+}
+
+void BassMusicInterface::UnloadAllMusic()
+{
+ StopAllMusic();
+ for (BassMusicMap::iterator anItr = mMusicMap.begin(); anItr != mMusicMap.end(); ++anItr)
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ if (aMusicInfo->mHStream)
+ gBass->BASS_StreamFree(aMusicInfo->mHStream);
+ else if (aMusicInfo->mHMusic)
+ gBass->BASS_MusicFree(aMusicInfo->mHMusic);
+ }
+ mMusicMap.clear();
+}
+
+void BassMusicInterface::PauseMusic(int theSongId)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ gBass->BASS_ChannelPause(aMusicInfo->GetHandle());
+ }
+}
+
+void BassMusicInterface::PauseAllMusic()
+{
+ for (BassMusicMap::iterator anItr = mMusicMap.begin(); anItr != mMusicMap.end(); ++anItr)
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ if (gBass->BASS_ChannelIsActive(aMusicInfo->GetHandle()) == BASS_ACTIVE_PLAYING)
+ gBass->BASS_ChannelPause(aMusicInfo->GetHandle());
+ }
+}
+
+void BassMusicInterface::ResumeAllMusic()
+{
+ for (BassMusicMap::iterator anItr = mMusicMap.begin(); anItr != mMusicMap.end(); ++anItr)
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ if (gBass->BASS_ChannelIsActive(aMusicInfo->GetHandle()) == BASS_ACTIVE_PAUSED)
+ gBass->BASS_ChannelResume(aMusicInfo->GetHandle());
+ }
+}
+
+void BassMusicInterface::ResumeMusic(int theSongId)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ gBass->BASS_ChannelResume(aMusicInfo->GetHandle());
+ }
+}
+
+void BassMusicInterface::FadeIn(int theSongId, int theOffset, double theSpeed, bool noLoop)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeAdd = theSpeed;
+ aMusicInfo->mStopOnFade = noLoop;
+
+ gBass->BASS_ChannelStop(aMusicInfo->GetHandle());
+ gBass->BASS_ChannelSetAttributes(aMusicInfo->GetHandle(), -1, (int) (aMusicInfo->mVolume*100), -101);
+ if (aMusicInfo->mHMusic)
+ {
+ if (theOffset == -1)
+ gBass->BASS_MusicPlay(aMusicInfo->mHMusic);
+ else
+ {
+ if (gBass->mVersion2)
+ gBass->BASS_MusicPlayEx(aMusicInfo->mHMusic, theOffset, BASS2_MUSIC_RAMP | (noLoop ? 0 : BASS_MUSIC_LOOP), TRUE);
+ else
+ gBass->BASS_MusicPlayEx(aMusicInfo->mHMusic, theOffset, noLoop ? 0 : BASS_MUSIC_LOOP, TRUE);
+ }
+ }
+ else
+ {
+ BOOL flush = theOffset == -1 ? FALSE : TRUE;
+ gBass->BASS_StreamPlay(aMusicInfo->mHStream, flush, noLoop ? 0 : BASS_MUSIC_LOOP);
+ if (theOffset > 0)
+ gBass->BASS_ChannelSetPosition(aMusicInfo->mHStream, theOffset);
+ }
+
+ }
+}
+
+void BassMusicInterface::FadeOut(int theSongId, bool stopSong, double theSpeed)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mVolume != 0.0)
+ {
+ aMusicInfo->mVolumeAdd = -theSpeed;
+ }
+
+ aMusicInfo->mStopOnFade = stopSong;
+ }
+}
+
+void BassMusicInterface::FadeOutAll(bool stopSong, double theSpeed)
+{
+ BassMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeAdd = -theSpeed;
+ aMusicInfo->mStopOnFade = stopSong;
+
+ ++anItr;
+ }
+}
+
+void BassMusicInterface::SetVolume(double theVolume)
+{
+ int aVolume = (int) (theVolume * mMaxMusicVolume);
+
+ if (gBass->mVersion2)
+ {
+ gBass->BASS_SetConfig(/*BASS_CONFIG_GVOL_MUSIC*/6, (int) (theVolume * 100));
+ gBass->BASS_SetConfig(/*BASS_CONFIG_GVOL_STREAM*/5, (int) (theVolume * 100));
+ }
+ else
+ gBass->BASS_SetGlobalVolumes(aVolume, aVolume, aVolume);
+}
+
+void BassMusicInterface::SetSongVolume(int theSongId, double theVolume)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolume = theVolume;
+ gBass->BASS_ChannelSetAttributes(aMusicInfo->GetHandle(), -1, (int) (aMusicInfo->mVolume*100), -101);
+ }
+}
+
+void BassMusicInterface::SetSongMaxVolume(int theSongId, double theMaxVolume)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeCap = theMaxVolume;
+ aMusicInfo->mVolume = min(aMusicInfo->mVolume, theMaxVolume);
+ gBass->BASS_ChannelSetAttributes(aMusicInfo->GetHandle(), -1, (int) (aMusicInfo->mVolume*100), -101);
+ }
+}
+
+bool BassMusicInterface::IsPlaying(int theSongId)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ return gBass->BASS_ChannelIsActive(aMusicInfo->GetHandle()) == BASS_ACTIVE_PLAYING;
+ }
+
+ return false;
+}
+
+void BassMusicInterface::SetMusicAmplify(int theSongId, double theAmp)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ gBass->BASS_MusicSetAmplify(aMusicInfo->GetHandle(), (int) (theAmp * 100));
+ }
+}
+
+void BassMusicInterface::Update()
+{
+ BassMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mVolumeAdd != 0.0)
+ {
+ aMusicInfo->mVolume += aMusicInfo->mVolumeAdd;
+
+ if (aMusicInfo->mVolume > aMusicInfo->mVolumeCap)
+ {
+ aMusicInfo->mVolume = aMusicInfo->mVolumeCap;
+ aMusicInfo->mVolumeAdd = 0.0;
+ }
+ else if (aMusicInfo->mVolume < 0.0)
+ {
+ aMusicInfo->mVolume = 0.0;
+ aMusicInfo->mVolumeAdd = 0.0;
+
+ if (aMusicInfo->mStopOnFade)
+ gBass->BASS_ChannelStop(aMusicInfo->GetHandle());
+ }
+
+ gBass->BASS_ChannelSetAttributes(aMusicInfo->GetHandle(), -1, (int) (aMusicInfo->mVolume*100), -101);
+ }
+
+ ++anItr;
+ }
+}
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+// MODs are broken up into several orders or patterns. This returns the current order a song is on.
+int BassMusicInterface::GetMusicOrder(int theSongId)
+{
+ BassMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ BassMusicInfo* aMusicInfo = &anItr->second;
+ int aPosition = gBass->BASS_MusicGetOrderPosition(aMusicInfo->GetHandle());
+ return aPosition;
+ }
+ return -1;
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/BassMusicInterface.h b/osframework/source/SexyAppFramework/BassMusicInterface.h
new file mode 100644
index 0000000..b29e54c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/BassMusicInterface.h
@@ -0,0 +1,68 @@
+#ifndef __BASSMUSICINTERFACE_H__
+#define __BASSMUSICINTERFACE_H__
+
+#include "MusicInterface.h"
+#include "bass.h"
+
+namespace Sexy
+{
+
+class SexyAppBase;
+
+class BassMusicInfo
+{
+public:
+ HMUSIC mHMusic;
+ HSTREAM mHStream;
+ double mVolume;
+ double mVolumeAdd;
+ double mVolumeCap;
+ bool mStopOnFade;
+
+public:
+ BassMusicInfo();
+
+ DWORD GetHandle() { return mHMusic?mHMusic:mHStream; }
+};
+
+typedef std::map<int, BassMusicInfo> BassMusicMap;
+
+class BassMusicInterface : public MusicInterface
+{
+public:
+ BassMusicMap mMusicMap;
+ int mMaxMusicVolume;
+ int mMusicLoadFlags;
+
+public:
+ BassMusicInterface(HWND theHWnd);
+ virtual ~BassMusicInterface();
+
+ virtual bool LoadMusic(int theSongId, const std::string& theFileName);
+ virtual void PlayMusic(int theSongId, int theOffset = 0, bool noLoop = false);
+ virtual void StopMusic(int theSongId);
+ virtual void StopAllMusic();
+ virtual void UnloadMusic(int theSongId);
+ virtual void UnloadAllMusic();
+ virtual void PauseAllMusic();
+ virtual void ResumeAllMusic();
+ virtual void PauseMusic(int theSongId);
+ virtual void ResumeMusic(int theSongId);
+ virtual void FadeIn(int theSongId, int theOffset = -1, double theSpeed = 0.002, bool noLoop = false);
+ virtual void FadeOut(int theSongId, bool stopSong = true, double theSpeed = 0.004);
+ virtual void FadeOutAll(bool stopSong = true, double theSpeed = 0.004);
+ virtual void SetSongVolume(int theSongId, double theVolume);
+ virtual void SetSongMaxVolume(int theSongId, double theMaxVolume);
+ virtual bool IsPlaying(int theSongId);
+
+ virtual void SetVolume(double theVolume);
+ virtual void SetMusicAmplify(int theSongId, double theAmp); // default is 0.50
+ virtual void Update();
+
+ // functions for dealing with MODs
+ int GetMusicOrder(int theSongId);
+};
+
+}
+
+#endif //__BASSMUSICINTERFACE_H__
diff --git a/osframework/source/SexyAppFramework/BltRotatedHelper.inc b/osframework/source/SexyAppFramework/BltRotatedHelper.inc
new file mode 100644
index 0000000..a8e329f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/BltRotatedHelper.inc
@@ -0,0 +1,259 @@
+#define EACH_ROW\
+ for (int y = 0; y < aDestRect.mHeight; y++, aDestPixelsRow += aDestPixelsPitch)\
+ {\
+ float aBaseX = ((int)aDestRect.mX) + 0 - theRotCenterX - theX;\
+ float aBaseY = ((int)aDestRect.mY) + y - theRotCenterY - theY;\
+ \
+ int aU = (int) ((aCos*(aBaseX) - aSin*(aBaseY) + theRotCenterX) * 0x10000);\
+ int aV = (int) ((aCos*(aBaseY) + aSin*(aBaseX) + theRotCenterY) * 0x10000);\
+ \
+ DEST_PIXEL_TYPE* aDestPixels = aDestPixelsRow;\
+ \
+ int aLeft = 0;\
+ int aRight = aDestRect.mWidth - 1;\
+ \
+ int aUInt = (aU >> 16);\
+ int aVInt = (aV >> 16);\
+ \
+ if (aCosLong <= -0x0001)\
+ {\
+ if (aUInt<0)\
+ continue;\
+ \
+ int anEdgeLeft = ((theSrcRect.mWidth << 16) - 0x27FFF - aU) / aCosLong;\
+ if (anEdgeLeft >= aLeft)\
+ aLeft = anEdgeLeft;\
+\
+ int anEdgeRight = (0x07FFF - aU) / aCosLong;\
+ if (anEdgeRight < aRight)\
+ aRight = anEdgeRight;\
+ }\
+ else if (aCosLong >= 0x0001)\
+ {\
+ if (aUInt >= theSrcRect.mWidth-1)\
+ continue;\
+ \
+ int anEdgeLeft = (0x10000 - aU) / aCosLong;\
+ if (anEdgeLeft > aLeft)\
+ aLeft = anEdgeLeft;\
+\
+ int anEdgeRight = ((theSrcRect.mWidth << 16) - 0x17FFF - aU) / aCosLong;\
+ if (anEdgeRight < aRight)\
+ aRight = anEdgeRight;\
+ }\
+ else if ((aU < 0) || (aU >= (theSrcRect.mWidth - 1) << 16))\
+ continue;\
+\
+ if (aSinLong <= -0x0001)\
+ {\
+ if (aVInt<0)\
+ continue;\
+ \
+ int anEdgeLeft = ((theSrcRect.mHeight << 16) - 0x27FFF - aV) / aSinLong;\
+ if (anEdgeLeft > aLeft)\
+ aLeft = anEdgeLeft;\
+\
+ int anEdgeRight = (0x0000 - aV) / aSinLong;\
+ if (anEdgeRight < aRight)\
+ aRight = anEdgeRight;\
+ }\
+ else if (aSinLong >= 0x0001)\
+ {\
+ if (aVInt >= theSrcRect.mHeight-1)\
+ continue;\
+ \
+ int anEdgeLeft = (0x10000 - aV) / aSinLong;\
+ if (anEdgeLeft > aLeft)\
+ aLeft = anEdgeLeft;\
+\
+ int anEdgeRight = ((theSrcRect.mHeight << 16) - 0x17FFF - aV) / aSinLong;\
+ if (anEdgeRight < aRight)\
+ aRight = anEdgeRight;\
+ }\
+ else if ((aV < 0) || (aV >= (theSrcRect.mHeight - 1) << 16))\
+ continue;\
+\
+ aU += aLeft * aCosLong;\
+ aV += aLeft * aSinLong;\
+ aDestPixels += aLeft;\
+\
+ int aWidth = theImage->mWidth;
+#define END_ROW }
+
+{
+#if defined(OPTIMIZE_SOFTWARE_DRAWING) && defined(WRITE_PIXEL_OPTIMIZED)
+ if (gOptimizeSoftwareDrawing)
+ {
+ if (aNumBits == 16)
+ {
+#ifdef WRITE_PIXEL_OPTIMIZED_565
+ if (aGMask == 0x7E0) // 5-6-5
+ {
+ EACH_ROW
+ for (int x = aLeft; x <= aRight; x++)
+ {
+ int aUInt = (aU >> 16);
+ int aVInt = (aV >> 16);
+
+ SRC_TYPE* srcptr = aSrcBits +
+ (aVInt * aWidth) + aUInt;
+
+ int aUFactor = (aU & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = (aV & 0xFFFE) + 1; // ditto for aVFactor
+
+ ulong src1 = READ_COLOR(srcptr);
+ ulong src2 = READ_COLOR(srcptr+1);
+ ulong src3 = READ_COLOR(srcptr+theImage->mWidth);
+ ulong src4 = READ_COLOR(srcptr+1+theImage->mWidth);
+
+ int a1 = ((src1 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a2 = ((src2 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a3 = ((src3 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a4 = ((src4 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+
+ WRITE_PIXEL_OPTIMIZED_565;
+
+ aU += aCosLong;
+ aV += aSinLong;
+ }
+ END_ROW
+ }
+#endif
+#ifdef WRITE_PIXEL_OPTIMIZED_555
+#ifdef WRITE_PIXEL_OPTIMIZED_565
+ else
+#endif
+ if (aGMask == 0x3E0) // 5-5-5
+ {
+ EACH_ROW
+ for (int x = aLeft; x <= aRight; x++)
+ {
+ int aUInt = (aU >> 16);
+ int aVInt = (aV >> 16);
+
+ SRC_TYPE* srcptr = aSrcBits +
+ (aVInt * aWidth) + aUInt;
+
+ int aUFactor = (aU & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = (aV & 0xFFFE) + 1; // ditto for aVFactor
+
+ ulong src1 = READ_COLOR(srcptr);
+ ulong src2 = READ_COLOR(srcptr+1);
+ ulong src3 = READ_COLOR(srcptr+theImage->mWidth);
+ ulong src4 = READ_COLOR(srcptr+1+theImage->mWidth);
+
+ int a1 = ((src1 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a2 = ((src2 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a3 = ((src3 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a4 = ((src4 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+
+ WRITE_PIXEL_OPTIMIZED_555;
+
+ aU += aCosLong;
+ aV += aSinLong;
+ }
+ END_ROW
+ }
+#endif
+#if defined(WRITE_PIXEL_OPTIMIZED_555) || defined(WRITE_PIXEL_OPTIMIZED_565)
+ else
+#endif
+ {
+ EACH_ROW
+ for (int x = aLeft; x <= aRight; x++)
+ {
+ int aUInt = (aU >> 16);
+ int aVInt = (aV >> 16);
+
+ SRC_TYPE* srcptr = aSrcBits +
+ (aVInt * aWidth) + aUInt;
+
+ int aUFactor = (aU & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = (aV & 0xFFFE) + 1; // ditto for aVFactor
+
+ ulong src1 = READ_COLOR(srcptr);
+ ulong src2 = READ_COLOR(srcptr+1);
+ ulong src3 = READ_COLOR(srcptr+theImage->mWidth);
+ ulong src4 = READ_COLOR(srcptr+1+theImage->mWidth);
+
+ int a1 = ((src1 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a2 = ((src2 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a3 = ((src3 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a4 = ((src4 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+
+ WRITE_PIXEL;
+
+ aU += aCosLong;
+ aV += aSinLong;
+ }
+ END_ROW
+ }
+ }
+ else if (aNumBits == 32)
+ {
+ EACH_ROW
+ for (int x = aLeft; x <= aRight; x++)
+ {
+ int aUInt = (aU >> 16);
+ int aVInt = (aV >> 16);
+
+ SRC_TYPE* srcptr = aSrcBits +
+ (aVInt * aWidth) + aUInt;
+
+ int aUFactor = (aU & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = (aV & 0xFFFE) + 1; // ditto for aVFactor
+
+ ulong src1 = READ_COLOR(srcptr);
+ ulong src2 = READ_COLOR(srcptr+1);
+ ulong src3 = READ_COLOR(srcptr+theImage->mWidth);
+ ulong src4 = READ_COLOR(srcptr+1+theImage->mWidth);
+
+ int a1 = ((src1 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a2 = ((src2 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a3 = ((src3 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a4 = ((src4 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+
+ WRITE_PIXEL_OPTIMIZED;
+
+ aU += aCosLong;
+ aV += aSinLong;
+ }
+ END_ROW
+ }
+ }
+ else
+ {
+#endif
+ EACH_ROW
+ for (int x = aLeft; x <= aRight; x++)
+ {
+ int aUInt = (aU >> 16);
+ int aVInt = (aV >> 16);
+
+ SRC_TYPE* srcptr = aSrcBits +
+ (aVInt * aWidth) + aUInt;
+
+ int aUFactor = (aU & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = (aV & 0xFFFE) + 1; // ditto for aVFactor
+
+ ulong src1 = READ_COLOR(srcptr);
+ ulong src2 = READ_COLOR(srcptr+1);
+ ulong src3 = READ_COLOR(srcptr+theImage->mWidth);
+ ulong src4 = READ_COLOR(srcptr+1+theImage->mWidth);
+
+ int a1 = ((src1 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a2 = ((src2 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a3 = ((src3 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a4 = ((src4 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+
+ WRITE_PIXEL;
+
+
+ aU += aCosLong;
+ aV += aSinLong;
+ }
+ END_ROW
+#if defined(OPTIMIZE_SOFTWARE_DRAWING) && defined(WRITE_PIXEL_OPTIMIZED)
+ }
+#endif
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Buffer.cpp b/osframework/source/SexyAppFramework/Buffer.cpp
new file mode 100644
index 0000000..10e3c09
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Buffer.cpp
@@ -0,0 +1,584 @@
+#include "Buffer.h"
+#include "Debug.h"
+
+#define POLYNOMIAL 0x04c11db7L
+
+static BOOL bCrcTableGenerated = FALSE;
+static unsigned long crc_table[256];
+
+using namespace Sexy;
+using namespace std;
+
+static char* gWebEncodeMap = ".-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+static int gWebDecodeMap[256] =
+{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+-1, -1, -1, 0, -1, 1, 0, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1, -1
+, -1, -1, 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, -1, -1, -1, -1, -1, -1, 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
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+
+//----------------------------------------------------------------------------
+// Generate the table of CRC remainders for all possible bytes.
+//----------------------------------------------------------------------------
+static void GenerateCRCTable(void)
+{
+ bCrcTableGenerated = TRUE;
+
+ register int i, j;
+ register unsigned long crc_accum;
+ for (i = 0; i < 256; i++)
+ {
+ crc_accum = ((unsigned long) i << 24);
+ for ( j = 0; j < 8; j++ )
+ {
+ if (crc_accum & 0x80000000L)
+ crc_accum = (crc_accum << 1) ^ POLYNOMIAL;
+ else
+ crc_accum = (crc_accum << 1);
+ }
+ crc_table[i] = crc_accum;
+ }
+}
+
+//----------------------------------------------------------------------------
+// Update the CRC on the data block one byte at a time.
+//----------------------------------------------------------------------------
+static unsigned long UpdateCRC(unsigned long crc_accum,
+ const char *data_blk_ptr,
+ int data_blk_size)
+{
+ if (!bCrcTableGenerated)
+ GenerateCRCTable();
+
+ register int i, j;
+ for (j = 0; j < data_blk_size; j++)
+ {
+ i = ((int) (crc_accum >> 24) ^ *data_blk_ptr++) & 0xff;
+ crc_accum = (crc_accum << 8) ^ crc_table[i];
+ }
+ return crc_accum;
+}
+
+//----------------------------------------------------------------------------
+// Stream UTF8 data in a const char* to keep receiving wchar_ts
+//----------------------------------------------------------------------------
+static int GetUTF8Char(const char** theBuffer, int theLen, wchar_t* theChar)
+{
+ static const unsigned short aMaskData[] = {
+ 0xC0, // 1 extra byte
+ 0xE0, // 2 extra bytes
+ 0xF0, // 3 extra bytes
+ 0xF8, // 4 extra bytes
+ 0xFC // 5 extra bytes
+ };
+
+ if (theLen == 0) return 0;
+
+ const char* aBuffer = *theBuffer;
+
+ int aTempChar = int((unsigned char)*aBuffer++);
+ if ((aTempChar & 0x80) != 0)
+ {
+ if ((aTempChar & 0xC0) != 0xC0) return 0; // sanity check: high bit should not be set without the next highest bit being set, too.
+
+ int aBytesRead[6];
+ int* aBytesReadPtr = &aBytesRead[0];
+
+ *aBytesReadPtr++ = aTempChar;
+
+ int aLen;
+ for (aLen = 0; aLen < (int)(sizeof(aMaskData)/sizeof(*aMaskData)); ++aLen)
+ {
+ if ( (aTempChar & aMaskData[aLen]) == ((aMaskData[aLen] << 1) & aMaskData[aLen]) ) break;
+ }
+ if (aLen >= (int)(sizeof(aMaskData)/sizeof(*aMaskData))) return 0;
+
+ aTempChar &= ~aMaskData[aLen];
+ int aTotalLen = aLen+1;
+
+ if (aTotalLen < 2 || aTotalLen > 6) return 0;
+
+ int anExtraChar = 0;
+ while (aLen > 0 && (aBuffer - *theBuffer) < theLen)
+ {
+ anExtraChar = int((unsigned char)*aBuffer++);
+ if ((anExtraChar & 0xC0) != 0x80) return 0; // sanity check: high bit set, and next highest bit NOT set.
+
+ *aBytesReadPtr++ = anExtraChar;
+
+ aTempChar = (aTempChar << 6) | (anExtraChar & 0x3F);
+ --aLen;
+ }
+ if (aLen > 0) return 0; // ran out of data before ending sequence
+
+ // validate substrings
+ bool valid = true;
+ switch (aTotalLen)
+ {
+ case 2:
+ valid = !((aBytesRead[0] & 0x3E) == 0);
+ break;
+ case 3:
+ valid = !((aBytesRead[0] & 0x1F) == 0 && (aBytesRead[1] & 0x20) == 0);
+ break;
+ case 4:
+ valid = !((aBytesRead[0] & 0x0F) == 0 && (aBytesRead[1] & 0x30) == 0);
+ break;
+ case 5:
+ valid = !((aBytesRead[0] & 0x07) == 0 && (aBytesRead[1] & 0x38) == 0);
+ break;
+ case 6:
+ valid = !((aBytesRead[0] & 0x03) == 0 && (aBytesRead[1] & 0x3C) == 0);
+ break;
+ }
+ if (!valid) return 0;
+ }
+
+ int aConsumedCount = aBuffer - *theBuffer;
+
+ if ( (aTempChar >= 0xD800 && aTempChar <= 0xDFFF) || (aTempChar >= 0xFFFE && aTempChar <= 0xFFFF) )
+ return 0;
+
+ *theChar = (wchar_t)aTempChar;
+
+ *theBuffer = aBuffer;
+ return aConsumedCount;
+}
+
+Buffer::Buffer()
+{
+ mDataBitSize = 0;
+ mReadBitPos = 0;
+ mWriteBitPos = 0;
+}
+
+Buffer::~Buffer()
+{
+}
+
+std::string Buffer::ToWebString() const
+{
+ std::string aString;
+ int aSizeBits = mWriteBitPos;
+
+ int anOldReadBitPos = mReadBitPos;
+ mReadBitPos = 0;
+
+ char aStr[256];
+ sprintf(aStr, "%08X", aSizeBits);
+ aString += aStr;
+
+ int aNumChars = (aSizeBits + 5) / 6;
+ for (int aCharNum = 0; aCharNum < aNumChars; aCharNum++)
+ aString += gWebEncodeMap[ReadNumBits(6, false)];
+
+ mReadBitPos = anOldReadBitPos;
+
+ return aString;
+}
+
+std::wstring Buffer::UTF8ToWideString() const
+{
+ const char* aData = (const char*)GetDataPtr();
+ int aLen = GetDataLen();
+
+ bool firstChar = true;
+
+ std::wstring aString;
+ aString.reserve(aLen); // worst case
+ while (aLen > 0)
+ {
+ wchar_t aChar;
+ int aConsumed = GetUTF8Char(&aData, aLen, &aChar);
+ if (aConsumed == 0) break;
+ aLen -= aConsumed;
+
+ if (firstChar)
+ {
+ firstChar = false;
+ if (aChar == 0xFEFF) continue;
+ }
+
+ aString += aChar;
+ }
+ return aString;
+}
+
+void Buffer::FromWebString(const std::string& theString)
+{
+ Clear();
+
+ if (theString.size() < 4)
+ return;
+
+ int aSizeBits = 0;
+
+ for (int aDigitNum = 0; aDigitNum < 8; aDigitNum++)
+ {
+ char aChar = theString[aDigitNum];
+ int aVal = 0;
+
+ if ((aChar >= '0') && (aChar <= '9'))
+ aVal = aChar - '0';
+ else if ((aChar >= 'A') && (aChar <= 'F'))
+ aVal = (aChar - 'A') + 10;
+ else if ((aChar >= 'a') && (aChar <= 'f'))
+ aVal = (aChar - 'f') + 10;
+
+ aSizeBits += (aVal << ((7 - aDigitNum) * 4));
+ }
+
+ int aCharIdx = 8;
+ int aNumBitsLeft = aSizeBits;
+ while (aNumBitsLeft > 0)
+ {
+ uchar aChar = theString[aCharIdx++];
+ int aVal = gWebDecodeMap[aChar];
+ int aNumBits = min(aNumBitsLeft, 6);
+ WriteNumBits(aVal, aNumBits);
+ aNumBitsLeft -= aNumBits;
+ }
+
+ SeekFront();
+}
+
+void Buffer::SeekFront() const
+{
+ mReadBitPos = 0;
+}
+
+void Buffer::Clear()
+{
+ mReadBitPos = 0;
+ mWriteBitPos = 0;
+ mDataBitSize = 0;
+ mData.clear();
+}
+
+void Buffer::WriteByte(uchar theByte)
+{
+ if (mWriteBitPos % 8 == 0)
+ mData.push_back((char) theByte);
+ else
+ {
+ int anOfs = mWriteBitPos % 8;
+ mData[mWriteBitPos /8] |= theByte << anOfs;
+ mData.push_back((char) (theByte >> (8-anOfs)));
+ }
+
+ mWriteBitPos += 8;
+ if (mWriteBitPos > mDataBitSize)
+ mDataBitSize = mWriteBitPos;
+}
+
+void Buffer::WriteNumBits(int theNum, int theBits)
+{
+ for (int aBitNum = 0; aBitNum < theBits; aBitNum++)
+ {
+ if (mWriteBitPos % 8 == 0)
+ mData.push_back(0);
+ if ((theNum & (1<<aBitNum)) != 0)
+ mData[mWriteBitPos/8] |= 1 << (mWriteBitPos % 8);
+ mWriteBitPos++;
+ }
+
+ if (mWriteBitPos > mDataBitSize)
+ mDataBitSize = mWriteBitPos;
+}
+
+int Buffer::GetBitsRequired(int theNum, bool isSigned)
+{
+ if (theNum < 0) // two's compliment stuff
+ theNum = -theNum - 1;
+
+ int aNumBits = 0;
+ while (theNum >= 1<<aNumBits)
+ aNumBits++;
+
+ if (isSigned)
+ aNumBits++;
+
+ return aNumBits;
+}
+
+void Buffer::WriteBoolean(bool theBool)
+{
+ WriteByte(theBool ? 1 : 0);
+}
+
+void Buffer::WriteShort(short theShort)
+{
+ WriteByte((uchar)theShort);
+ WriteByte((uchar)(theShort >> 8));
+}
+
+void Buffer::WriteLong(long theLong)
+{
+ WriteByte((uchar)theLong);
+ WriteByte((uchar)(theLong >> 8));
+ WriteByte((uchar)(theLong >> 16));
+ WriteByte((uchar)(theLong >> 24));
+}
+
+void Buffer::WriteString(const std::string& theString)
+{
+ WriteShort((short) theString.length());
+ for (int i = 0; i < (int)theString.length(); i++)
+ WriteByte(theString[i]);
+}
+
+void Buffer::WriteUTF8String(const std::wstring& theString)
+{
+ if ((mWriteBitPos & 7) != 0) // boo! let's get byte aligned.
+ mWriteBitPos = (mWriteBitPos + 8) & ~7;
+
+ WriteShort((short) theString.length());
+ for (int i = 0; i < (int)theString.length(); ++i)
+ {
+ const unsigned int c = (unsigned int)theString[i]; // just in case wchar_t is only 16 bits, and it generally is in visual studio
+ if (c < 0x80)
+ {
+ WriteByte((uchar)c);
+ }
+ else if (c < 0x800)
+ {
+ WriteByte((uchar)(0xC0 | (c>>6)));
+ WriteByte((uchar)(0x80 | (c & 0x3F)));
+ }
+ else if (c < 0x10000)
+ {
+ WriteByte((uchar)(0xE0 | c>>12));
+ WriteByte((uchar)(0x80 | ((c>>6) & 0x3F)));
+ WriteByte((uchar)(0x80 | (c & 0x3F)));
+ }
+ else if (c < 0x110000)
+ {
+ WriteByte((uchar)(0xF0 | (c>>18)));
+ WriteByte((uchar)(0x80 | ((c>>12) & 0x3F)));
+ WriteByte((uchar)(0x80 | ((c>>6) & 0x3F)));
+ WriteByte((uchar)(0x80 | (c & 0x3F)));
+ } // are the remaining ranges really necessary? add if so!
+ }
+}
+
+void Buffer::WriteLine(const std::string& theString)
+{
+ WriteBytes((const uchar*) (theString + "\r\n").c_str(), (int) theString.length() + 2);
+}
+
+void Buffer::WriteBuffer(const ByteVector& theBuffer)
+{
+ WriteLong((short) theBuffer.size());
+ for (int i = 0; i < (int)theBuffer.size(); i++)
+ WriteByte(theBuffer[i]);
+}
+
+void Buffer::WriteBytes(const uchar* theByte, int theCount)
+{
+ for (int i = 0; i < theCount; i++)
+ WriteByte(theByte[i]);
+}
+
+void Buffer::SetData(const ByteVector& theBuffer)
+{
+ mData = theBuffer;
+ mDataBitSize = mData.size() * 8;
+}
+
+void Buffer::SetData(uchar* thePtr, int theCount)
+{
+ mData.clear();
+ mData.insert(mData.begin(), thePtr, thePtr + theCount);
+ mDataBitSize = mData.size() * 8;
+}
+
+uchar Buffer::ReadByte() const
+{
+ if ((mReadBitPos + 7)/8 >= (int)mData.size())
+ {
+ return 0; // Underflow
+ }
+
+ if (mReadBitPos % 8 == 0)
+ {
+ uchar b = mData[mReadBitPos/8];
+ mReadBitPos += 8;
+ return b;
+ }
+ else
+ {
+ int anOfs = mReadBitPos % 8;
+
+ uchar b = 0;
+
+ b = mData[mReadBitPos/8] >> anOfs;
+ b |= mData[(mReadBitPos/8)+1] << (8 - anOfs);
+
+ mReadBitPos += 8;
+
+ return b;
+ }
+}
+
+int Buffer::ReadNumBits(int theBits, bool isSigned) const
+{
+ int aByteLength = (int) mData.size();
+
+ int theNum = 0;
+ bool bset = false;
+ for (int aBitNum = 0; aBitNum < theBits; aBitNum++)
+ {
+ int aBytePos = mReadBitPos/8;
+
+ if (aBytePos >= aByteLength)
+ break;
+
+ if (bset = (mData[aBytePos] & (1<<(mReadBitPos%8))) != 0)
+ theNum |= 1<<aBitNum;
+
+ mReadBitPos++;
+ }
+
+ if ((isSigned) && (bset)) // sign extend
+ for (int aBitNum = theBits; aBitNum < 32; aBitNum++)
+ theNum |= 1<<aBitNum;
+
+ return theNum;
+}
+
+bool Buffer::ReadBoolean() const
+{
+ return ReadByte() != 0;
+}
+
+short Buffer::ReadShort() const
+{
+ short aShort = ReadByte();
+ aShort |= ((short) ReadByte() << 8);
+ return aShort;
+}
+
+long Buffer::ReadLong() const
+{
+ long aLong = ReadByte();
+ aLong |= ((long) ReadByte()) << 8;
+ aLong |= ((long) ReadByte()) << 16;
+ aLong |= ((long) ReadByte()) << 24;
+
+ return aLong;
+}
+
+std::string Buffer::ReadString() const
+{
+ std::string aString;
+ int aLen = ReadShort();
+
+ for (int i = 0; i < aLen; i++)
+ aString += (char) ReadByte();
+
+ return aString;
+}
+
+std::wstring Buffer::ReadUTF8String() const
+{
+ if ((mReadBitPos & 7) != 0)
+ mReadBitPos = (mReadBitPos + 8) & ~7; // byte align the read position
+
+ std::wstring aString;
+ int aLen = ReadShort();
+
+ const char* aData = (const char*)(&mData[mReadBitPos/8]);
+ int aDataSizeBytes = (mDataBitSize - mReadBitPos)/8;
+
+ int i;
+ for (i = 0; aDataSizeBytes > 0 && i < aLen; ++i)
+ {
+ wchar_t aChar;
+ int aConsumed = GetUTF8Char(&aData, aDataSizeBytes, &aChar);
+ if (aConsumed == 0) break;
+ aDataSizeBytes -= aConsumed;
+
+ aString += aChar;
+ }
+ DBG_ASSERT(i == aLen); // if this fires, the UTF-8 data was malformed.
+
+ return aString;
+}
+
+
+std::string Buffer::ReadLine() const
+{
+ std::string aString;
+
+ for (;;)
+ {
+ char c = ReadByte();
+
+ if ((c == 0) || (c == '\n'))
+ break;
+
+ if (c != '\r')
+ aString += c;
+ }
+
+ return aString;
+}
+
+void Buffer::ReadBytes(uchar* theData, int theLen) const
+{
+ for (int i = 0; i < theLen; i++)
+ theData[i] = ReadByte();
+}
+
+void Buffer::ReadBuffer(ByteVector* theByteVector) const
+{
+ theByteVector->clear();
+
+ ulong aLength = ReadLong();
+ theByteVector->resize(aLength);
+ ReadBytes(&(*theByteVector)[0], aLength);
+}
+
+const uchar* Buffer::GetDataPtr() const
+{
+ if (mData.size() == 0)
+ return NULL;
+ return &mData[0];
+}
+
+int Buffer::GetDataLen() const
+{
+ return (mDataBitSize + 7) / 8; // Round up
+}
+
+int Buffer::GetDataLenBits() const
+{
+ return mDataBitSize;
+}
+
+ulong Buffer::GetCRC32(ulong theSeed) const
+{
+ ulong aCRC = theSeed;
+ aCRC = UpdateCRC(aCRC, (const char*) &mData[0], (int) mData.size());
+ return aCRC;
+}
+
+bool Buffer::AtEnd() const
+{
+ //return mReadBitPos >= (int)mData.size()*8;
+ return mReadBitPos >= mDataBitSize;
+}
+
+bool Buffer::PastEnd() const
+{
+ return mReadBitPos > mDataBitSize;
+}
diff --git a/osframework/source/SexyAppFramework/Buffer.h b/osframework/source/SexyAppFramework/Buffer.h
new file mode 100644
index 0000000..279ab5f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Buffer.h
@@ -0,0 +1,66 @@
+#ifndef __BUFFER_H__
+#define __BUFFER_H__
+
+#include <string>
+#include "Common.h"
+
+namespace Sexy
+{
+
+typedef std::vector<uchar> ByteVector;
+
+class Buffer
+{
+public:
+ ByteVector mData;
+ int mDataBitSize;
+ mutable int mReadBitPos;
+ mutable int mWriteBitPos;
+
+public:
+ Buffer();
+ virtual ~Buffer();
+
+ void SeekFront() const;
+ void Clear();
+
+ void FromWebString(const std::string& theString);
+ void WriteByte(uchar theByte);
+ void WriteNumBits(int theNum, int theBits);
+ static int GetBitsRequired(int theNum, bool isSigned);
+ void WriteBoolean(bool theBool);
+ void WriteShort(short theShort);
+ void WriteLong(long theLong);
+ void WriteString(const std::string& theString);
+ void WriteUTF8String(const std::wstring& theString);
+ void WriteLine(const std::string& theString);
+ void WriteBuffer(const ByteVector& theBuffer);
+ void WriteBytes(const uchar* theByte, int theCount);
+ void SetData(const ByteVector& theBuffer);
+ void SetData(uchar* thePtr, int theCount);
+
+ std::string ToWebString() const;
+ std::wstring UTF8ToWideString() const;
+ uchar ReadByte() const;
+ int ReadNumBits(int theBits, bool isSigned) const;
+ bool ReadBoolean() const;
+ short ReadShort() const;
+ long ReadLong() const;
+ std::string ReadString() const;
+ std::wstring ReadUTF8String() const;
+ std::string ReadLine() const;
+ void ReadBytes(uchar* theData, int theLen) const;
+ void ReadBuffer(ByteVector* theByteVector) const;
+
+ const uchar* GetDataPtr() const;
+ int GetDataLen() const;
+ int GetDataLenBits() const;
+ ulong GetCRC32(ulong theSeed = 0) const;
+
+ bool AtEnd() const;
+ bool PastEnd() const;
+};
+
+}
+
+#endif //__BUFFER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ButtonListener.h b/osframework/source/SexyAppFramework/ButtonListener.h
new file mode 100644
index 0000000..203622b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ButtonListener.h
@@ -0,0 +1,21 @@
+#ifndef __BUTTONLISTENER_H__
+#define __BUTTONLISTENER_H__
+
+namespace Sexy
+{
+
+class ButtonListener
+{
+public:
+ virtual void ButtonPress(int theId) {}
+ virtual void ButtonPress(int theId, int theClickCount) { ButtonPress(theId); }
+ virtual void ButtonDepress(int theId) {}
+ virtual void ButtonDownTick(int theId) {}
+ virtual void ButtonMouseEnter(int theId) {}
+ virtual void ButtonMouseLeave(int theId) {}
+ virtual void ButtonMouseMove(int theId, int theX, int theY) {}
+};
+
+}
+
+#endif //__BUTTONLISTENER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ButtonWidget.cpp b/osframework/source/SexyAppFramework/ButtonWidget.cpp
new file mode 100644
index 0000000..8896f32
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ButtonWidget.cpp
@@ -0,0 +1,288 @@
+#include "ButtonWidget.h"
+#include "Image.h"
+#include "SysFont.h"
+#include "WidgetManager.h"
+#include "ButtonListener.h"
+
+using namespace Sexy;
+
+static int gButtonWidgetColors[][3] = {
+ {0, 0, 0},
+ {0, 0, 0},
+ {0, 0, 0},
+ {255, 255, 255},
+ {132, 132, 132},
+ {212, 212, 212}};
+
+ButtonWidget::ButtonWidget(int theId, ButtonListener* theButtonListener)
+{
+ mId = theId;
+ mFont = NULL;
+ mLabelJustify = BUTTON_LABEL_CENTER;
+ mButtonImage = NULL;
+ mOverImage = NULL;
+ mDownImage = NULL;
+ mDisabledImage = NULL;
+ mInverted = false;
+ mBtnNoDraw = false;
+ mFrameNoDraw = false;
+ mButtonListener = theButtonListener;
+ mHasAlpha = true;
+
+ mOverAlpha = 0;
+ mOverAlphaSpeed = 0;
+ mOverAlphaFadeInSpeed = 0;
+
+ SetColors(gButtonWidgetColors, NUM_COLORS);
+}
+
+ButtonWidget::~ButtonWidget()
+{
+ delete mFont;
+}
+
+void ButtonWidget::SetFont(Font* theFont)
+{
+ delete mFont;
+ mFont = theFont->Duplicate();
+}
+
+bool ButtonWidget::IsButtonDown()
+{
+ return mIsDown && mIsOver && !mDisabled;
+}
+
+bool ButtonWidget::HaveButtonImage(Image *theImage, const Rect &theRect)
+{
+ return (theImage!=NULL || theRect.mWidth!=0);
+}
+
+void ButtonWidget::DrawButtonImage(Graphics *g, Image *theImage, const Rect &theRect, int x, int y)
+{
+ if (theRect.mWidth != 0)
+ g->DrawImage(mButtonImage,x,y,theRect);
+ else
+ g->DrawImage(theImage,x,y);
+}
+
+void ButtonWidget::Draw(Graphics* g)
+{
+ if (mBtnNoDraw)
+ return;
+
+ if ((mFont == NULL) && (mLabel.length() > 0))
+ mFont = new SysFont(mWidgetManager->mApp, "Arial Unicode MS", 10);
+
+ bool isDown = mIsDown && mIsOver && !mDisabled;
+ isDown ^= mInverted;
+
+ int aFontX = 0; // BUTTON_LABEL_LEFT
+ int aFontY = 0;
+
+ if (mFont != NULL)
+ {
+ if (mLabelJustify == BUTTON_LABEL_CENTER)
+ aFontX = (mWidth - mFont->StringWidth(mLabel))/2;
+ else if (mLabelJustify == BUTTON_LABEL_RIGHT)
+ aFontX = mWidth - mFont->StringWidth(mLabel);
+ aFontY = (mHeight + mFont->GetAscent() - mFont->GetAscent()/6 - 1)/2;
+
+ //aFontX = (mWidth - mFont->StringWidth(mLabel))/2;
+ //aFontY = (mHeight - mFont->GetHeight())/2 + mFont->GetAscent() - 1;
+ }
+
+ g->SetFont(mFont);
+
+ if ((mButtonImage == NULL) && (mDownImage == NULL))
+ {
+ if (!mFrameNoDraw)
+ {
+ g->SetColor(mColors[COLOR_BKG]);
+ g->FillRect(0, 0, mWidth, mHeight);
+ }
+
+ if (isDown)
+ {
+ if (!mFrameNoDraw)
+ {
+ g->SetColor(mColors[COLOR_DARK_OUTLINE]);
+ g->FillRect(0, 0, mWidth-1, 1);
+ g->FillRect(0, 0, 1, mHeight-1);
+
+ g->SetColor(mColors[COLOR_LIGHT_OUTLINE]);
+ g->FillRect(0, mHeight - 1, mWidth, 1);
+ g->FillRect(mWidth - 1, 0, 1, mHeight);
+
+ g->SetColor(mColors[COLOR_MEDIUM_OUTLINE]);
+ g->FillRect(1, 1, mWidth - 3, 1);
+ g->FillRect(1, 1, 1, mHeight - 3);
+ }
+
+ if (mIsOver)
+ g->SetColor(mColors[COLOR_LABEL_HILITE]);
+ else
+ g->SetColor(mColors[COLOR_LABEL]);
+
+ g->DrawString(mLabel, aFontX+1, aFontY+1);
+ }
+ else
+ {
+ if (!mFrameNoDraw)
+ {
+ g->SetColor(mColors[COLOR_LIGHT_OUTLINE]);
+ g->FillRect(0, 0, mWidth-1, 1);
+ g->FillRect(0, 0, 1, mHeight-1);
+
+ g->SetColor(mColors[COLOR_DARK_OUTLINE]);
+ g->FillRect(0, mHeight - 1, mWidth, 1);
+ g->FillRect(mWidth - 1, 0, 1, mHeight);
+
+ g->SetColor(mColors[COLOR_MEDIUM_OUTLINE]);
+ g->FillRect(1, mHeight - 2, mWidth - 2, 1);
+ g->FillRect(mWidth - 2, 1, 1, mHeight - 2);
+ }
+
+ if (mIsOver)
+ g->SetColor(mColors[COLOR_LABEL_HILITE]);
+ else
+ g->SetColor(mColors[COLOR_LABEL]);
+
+ g->DrawString(mLabel, aFontX, aFontY);
+ }
+ }
+ else
+ {
+ if (!isDown)
+ {
+ if (mDisabled && HaveButtonImage(mDisabledImage,mDisabledRect))
+ DrawButtonImage(g,mDisabledImage,mDisabledRect,0,0);
+ else if ((mOverAlpha > 0) && HaveButtonImage(mOverImage,mOverRect))
+ {
+ if (HaveButtonImage(mButtonImage, mNormalRect) && mOverAlpha<1)
+ DrawButtonImage(g,mButtonImage,mNormalRect,0,0);
+
+ g->SetColorizeImages(true);
+ g->SetColor(Color(255,255,255,(int)(mOverAlpha * 255)));
+ DrawButtonImage(g,mOverImage,mOverRect,0,0);
+ g->SetColorizeImages(false);
+ }
+ else if ((mIsOver || mIsDown) && HaveButtonImage(mOverImage,mOverRect))
+ {
+ DrawButtonImage(g,mOverImage,mOverRect,0,0);
+ }
+ else if (HaveButtonImage(mButtonImage,mNormalRect))
+ DrawButtonImage(g,mButtonImage,mNormalRect,0,0);
+
+ if (mIsOver)
+ g->SetColor(mColors[COLOR_LABEL_HILITE]);
+ else
+ g->SetColor(mColors[COLOR_LABEL]);
+ g->DrawString(mLabel, aFontX, aFontY);
+ }
+ else
+ {
+ if (HaveButtonImage(mDownImage, mDownRect))
+ DrawButtonImage(g, mDownImage, mDownRect, 0, 0);
+ else if (HaveButtonImage(mOverImage,mOverRect))
+ DrawButtonImage(g, mOverImage, mOverRect, 1, 1);
+ else
+ DrawButtonImage(g, mButtonImage, mNormalRect, 1, 1);
+
+ g->SetColor(mColors[COLOR_LABEL_HILITE]);
+ g->DrawString(mLabel, aFontX+1, aFontY+1);
+ }
+ }
+}
+
+void ButtonWidget::SetDisabled(bool isDisabled)
+{
+ Widget::SetDisabled(isDisabled);
+
+ if (HaveButtonImage(mDisabledImage,mDisabledRect))
+ MarkDirty();
+}
+
+void ButtonWidget::MouseEnter()
+{
+ Widget::MouseEnter();
+
+ if (mOverAlphaFadeInSpeed==0 && mOverAlpha>0)
+ mOverAlpha = 0;
+
+ if (mIsDown || (HaveButtonImage(mOverImage,mOverRect)) || (mColors[COLOR_LABEL_HILITE] != mColors[COLOR_LABEL]))
+ MarkDirty();
+
+ mButtonListener->ButtonMouseEnter(mId);
+}
+
+void ButtonWidget::MouseLeave()
+{
+ Widget::MouseLeave();
+
+ if (mOverAlphaSpeed==0 && mOverAlpha>0)
+ mOverAlpha = 0;
+ else if (mOverAlphaSpeed>0 && mOverAlpha==0) // fade out from full
+ mOverAlpha = 1;
+
+ if (mIsDown || HaveButtonImage(mOverImage,mOverRect) || (mColors[COLOR_LABEL_HILITE] != mColors[COLOR_LABEL]))
+ MarkDirty();
+
+ mButtonListener->ButtonMouseLeave(mId);
+}
+
+void ButtonWidget::MouseMove(int theX, int theY)
+{
+ Widget::MouseMove(theX, theY);
+
+ mButtonListener->ButtonMouseMove(mId, theX, theY);
+}
+
+void ButtonWidget::MouseDown(int theX, int theY, int theBtnNum, int theClickCount)
+{
+ Widget::MouseDown(theX, theY, theBtnNum, theClickCount);
+
+ mButtonListener->ButtonPress(mId, theClickCount);
+
+ MarkDirty();
+}
+
+void ButtonWidget::MouseUp(int theX, int theY, int theBtnNum, int theClickCount)
+{
+ Widget::MouseUp(theX, theY, theBtnNum, theClickCount);
+
+ if (mIsOver && mWidgetManager->mHasFocus)
+ mButtonListener->ButtonDepress(mId);
+
+ MarkDirty();
+}
+
+void ButtonWidget::Update()
+{
+ Widget::Update();
+
+ if (mIsDown && mIsOver)
+ mButtonListener->ButtonDownTick(mId);
+
+ if (!mIsDown && !mIsOver && (mOverAlpha > 0))
+ {
+ if (mOverAlphaSpeed>0)
+ {
+ mOverAlpha -= mOverAlphaSpeed;
+ if (mOverAlpha < 0)
+ mOverAlpha = 0;
+ }
+ else
+ mOverAlpha = 0;
+
+ MarkDirty();
+ }
+ else if (mIsOver && mOverAlphaFadeInSpeed>0 && mOverAlpha<1)
+ {
+ mOverAlpha += mOverAlphaFadeInSpeed;
+ if (mOverAlpha > 1)
+ mOverAlpha = 1;
+ MarkDirty();
+ }
+}
+
+
diff --git a/osframework/source/SexyAppFramework/ButtonWidget.h b/osframework/source/SexyAppFramework/ButtonWidget.h
new file mode 100644
index 0000000..dcdee35
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ButtonWidget.h
@@ -0,0 +1,78 @@
+#ifndef __BUTTONWIDGET_H__
+#define __BUTTONWIDGET_H__
+
+#include "Widget.h"
+
+namespace Sexy
+{
+
+class Image;
+class ButtonListener;
+
+class ButtonWidget : public Widget
+{
+public:
+ enum {
+ BUTTON_LABEL_LEFT = -1,
+ BUTTON_LABEL_CENTER,
+ BUTTON_LABEL_RIGHT
+ };
+ enum
+ {
+ COLOR_LABEL,
+ COLOR_LABEL_HILITE,
+ COLOR_DARK_OUTLINE,
+ COLOR_LIGHT_OUTLINE,
+ COLOR_MEDIUM_OUTLINE,
+ COLOR_BKG,
+ NUM_COLORS
+ };
+
+ int mId;
+ SexyString mLabel;
+ int mLabelJustify;
+ Font* mFont;
+ Image* mButtonImage;
+ Image* mOverImage;
+ Image* mDownImage;
+ Image* mDisabledImage;
+ Rect mNormalRect;
+ Rect mOverRect;
+ Rect mDownRect;
+ Rect mDisabledRect;
+
+ bool mInverted;
+ bool mBtnNoDraw;
+ bool mFrameNoDraw;
+ ButtonListener* mButtonListener;
+
+ double mOverAlpha;
+ double mOverAlphaSpeed;
+ double mOverAlphaFadeInSpeed;
+
+ bool HaveButtonImage(Image *theImage, const Rect &theRect);
+ virtual void DrawButtonImage(Graphics *g, Image *theImage, const Rect &theRect, int x, int y);
+
+
+public:
+ ButtonWidget(int theId, ButtonListener* theButtonListener);
+ virtual ~ButtonWidget();
+
+ virtual void SetFont(Font* theFont);
+ virtual bool IsButtonDown();
+ virtual void Draw(Graphics* g);
+ virtual void SetDisabled(bool isDisabled);
+ virtual void MouseEnter();
+ virtual void MouseLeave();
+ virtual void MouseMove(int theX, int theY);
+ virtual void MouseDown(int theX, int theY, int theClickCount) { Widget::MouseDown(theX, theY, theClickCount); }
+ virtual void MouseDown(int theX, int theY, int theBtnNum, int theClickCount);
+ virtual void MouseUp(int theX, int theY) { Widget::MouseUp(theX, theY); }
+ virtual void MouseUp(int theX, int theY, int theClickCount) { Widget::MouseUp(theX, theY, theClickCount); }
+ virtual void MouseUp(int theX, int theY, int theBtnNum, int theClickCount);
+ virtual void Update();
+};
+
+}
+
+#endif //__BUTTONWIDGET_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Checkbox.cpp b/osframework/source/SexyAppFramework/Checkbox.cpp
new file mode 100644
index 0000000..54dfd29
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Checkbox.cpp
@@ -0,0 +1,81 @@
+#include "Checkbox.h"
+#include "CheckboxListener.h"
+#include "Graphics.h"
+
+using namespace Sexy;
+
+Checkbox::Checkbox(Image* theUncheckedImage, Image* theCheckedImage, int theId, CheckboxListener* theCheckboxListener) :
+ mUncheckedImage(theUncheckedImage),
+ mCheckedImage(theCheckedImage),
+ mId(theId),
+ mListener(theCheckboxListener),
+ mChecked(false) ,
+ mOutlineColor(Color::White),
+ mBkgColor(Color(80, 80, 80)),
+ mCheckColor(Color(255, 255, 0))
+{
+ mDoFinger = true;
+}
+
+void Checkbox::SetChecked(bool checked, bool tellListener)
+{
+ mChecked = checked;
+ if (tellListener && mListener)
+ mListener->CheckboxChecked(mId, mChecked);
+ MarkDirty();
+}
+
+bool Checkbox::IsChecked()
+{
+ return mChecked;
+}
+
+void Checkbox::Draw(Graphics* g)
+{
+ Widget::Draw(g);
+
+ /*if (mChecked)
+ g->DrawImage(mApp->mImages[IMAGE_CHECKBOX], 0, 0, Rect(0, 0, 31, 32));
+ else
+ g->DrawImage(mApp->mImages[IMAGE_CHECKBOX], 0, 0, Rect(31, 0, 31, 32));*/
+
+ if ((mCheckedRect.mWidth == 0) && (mCheckedImage != NULL) && (mUncheckedImage != NULL))
+ {
+ if (mChecked)
+ g->DrawImage(mCheckedImage, 0, 0);
+ else
+ g->DrawImage(mUncheckedImage, 0, 0);
+ }
+ else if ((mCheckedRect.mWidth != 0) && (mUncheckedImage != NULL))
+ {
+ if (mChecked)
+ g->DrawImage(mUncheckedImage, 0, 0, mCheckedRect);
+ else
+ g->DrawImage(mUncheckedImage, 0, 0, mUncheckedRect);
+ }
+ else if ((mUncheckedImage == NULL) && (mCheckedImage == NULL))
+ {
+ // No image, default draw method
+ g->SetColor(mOutlineColor);
+ g->FillRect(0, 0, mWidth, mHeight);
+ g->SetColor(mBkgColor);
+ g->FillRect(1, 1, mWidth - 2, mHeight - 2);
+
+ if (mChecked)
+ {
+ g->SetColor(mCheckColor);
+ g->DrawLine(1, 1, mWidth - 2, mHeight - 2);
+ g->DrawLine(mWidth - 1, 1, 1, mHeight - 2);
+ }
+ }
+}
+
+void Checkbox::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ Widget::MouseDown(x, y, theBtnNum, theClickCount);
+
+ mChecked = !mChecked;
+ if (mListener)
+ mListener->CheckboxChecked(mId, mChecked);
+ MarkDirty();
+}
diff --git a/osframework/source/SexyAppFramework/Checkbox.h b/osframework/source/SexyAppFramework/Checkbox.h
new file mode 100644
index 0000000..b6834c1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Checkbox.h
@@ -0,0 +1,46 @@
+#ifndef __CHECKBOX_H__
+#define __CHECKBOX_H__
+
+#include "Widget.h"
+
+namespace Sexy
+{
+
+class CheckboxListener;
+class Image;
+
+class Checkbox : public Widget
+{
+protected:
+ CheckboxListener* mListener;
+
+public:
+ int mId;
+
+ bool mChecked;
+
+ Image* mUncheckedImage;
+ Image* mCheckedImage;
+
+ Rect mCheckedRect;
+ Rect mUncheckedRect;
+
+ Color mOutlineColor; // These are only used if no image is specified
+ Color mBkgColor;
+ Color mCheckColor;
+
+public:
+ virtual void SetChecked(bool checked, bool tellListener = true);
+ virtual bool IsChecked();
+
+ virtual void MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void Draw(Graphics* g);
+
+public:
+ Checkbox(Image* theUncheckedImage, Image* theCheckedImage, int theId, CheckboxListener* theCheckboxListener);
+};
+
+}
+
+#endif //__CHECKBOX_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/CheckboxListener.h b/osframework/source/SexyAppFramework/CheckboxListener.h
new file mode 100644
index 0000000..4dd1ccf
--- /dev/null
+++ b/osframework/source/SexyAppFramework/CheckboxListener.h
@@ -0,0 +1,15 @@
+#ifndef __CHECKBOX_LISTENER__
+#define __CHECKBOX_LISTENER__
+
+namespace Sexy
+{
+
+class CheckboxListener
+{
+public:
+ virtual void CheckboxChecked(int theId, bool checked) {}
+};
+
+}
+
+#endif //__CHECKBOX_LISTENER__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Color.cpp b/osframework/source/SexyAppFramework/Color.cpp
new file mode 100644
index 0000000..0d5ccc8
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Color.cpp
@@ -0,0 +1,162 @@
+#include "Color.h"
+
+using namespace Sexy;
+
+Color Color::Black(0, 0, 0);
+Color Color::White(255, 255, 255);
+
+Color::Color() :
+ mRed(0),
+ mGreen(0),
+ mBlue(0),
+ mAlpha(255)
+{
+}
+
+Color::Color(int theColor) :
+ mAlpha((theColor >> 24) & 0xFF),
+ mRed((theColor >> 16) & 0xFF),
+ mGreen((theColor >> 8 ) & 0xFF),
+ mBlue((theColor ) & 0xFF)
+{
+ if(mAlpha==0)
+ mAlpha = 0xff;
+}
+
+Color::Color(int theColor, int theAlpha) :
+ mRed((theColor >> 16) & 0xFF),
+ mGreen((theColor >> 8 ) & 0xFF),
+ mBlue((theColor ) & 0xFF),
+ mAlpha(theAlpha)
+{
+}
+
+Color::Color(int theRed, int theGreen, int theBlue) :
+ mRed(theRed),
+ mGreen(theGreen),
+ mBlue(theBlue),
+ mAlpha(0xFF)
+{
+}
+
+Color::Color(int theRed, int theGreen, int theBlue, int theAlpha) :
+ mRed(theRed),
+ mGreen(theGreen),
+ mBlue(theBlue),
+ mAlpha(theAlpha)
+{
+}
+
+Color::Color(const SexyRGBA &theColor) :
+ mRed(theColor.r),
+ mGreen(theColor.g),
+ mBlue(theColor.b),
+ mAlpha(theColor.a)
+{
+}
+
+Color::Color(const uchar* theElements) :
+ mRed(theElements[0]),
+ mGreen(theElements[1]),
+ mBlue(theElements[2]),
+ mAlpha(0xFF)
+{
+}
+
+Color::Color(const int* theElements) :
+ mRed(theElements[0]),
+ mGreen(theElements[1]),
+ mBlue(theElements[2]),
+ mAlpha(0xFF)
+{
+}
+
+int Color::GetRed() const
+{
+ return mRed;
+}
+
+int Color::GetGreen() const
+{
+ return mGreen;
+}
+
+int Color::GetBlue() const
+{
+ return mBlue;
+}
+
+int Color::GetAlpha() const
+{
+ return mAlpha;
+}
+
+int& Color::operator[](int theIdx)
+{
+ static int aJunk = 0;
+
+ switch (theIdx)
+ {
+ case 0:
+ return mRed;
+ case 1:
+ return mGreen;
+ case 2:
+ return mBlue;
+ case 3:
+ return mAlpha;
+ default:
+ return aJunk;
+ }
+}
+
+int Color::operator[](int theIdx) const
+{
+ switch (theIdx)
+ {
+ case 0:
+ return mRed;
+ case 1:
+ return mGreen;
+ case 2:
+ return mBlue;
+ case 3:
+ return mAlpha;
+ default:
+ return 0;
+ }
+}
+
+ulong Color::ToInt() const
+{
+ return (mAlpha << 24) | (mRed << 16) | (mGreen << 8) | (mBlue);
+}
+
+SexyRGBA Color::ToRGBA() const
+{
+ SexyRGBA anRGBA;
+ anRGBA.r = mRed;
+ anRGBA.g = mGreen;
+ anRGBA.b = mBlue;
+ anRGBA.a = mAlpha;
+
+ return anRGBA;
+}
+
+bool Sexy::operator==(const Color& theColor1, const Color& theColor2)
+{
+ return
+ (theColor1.mRed == theColor2.mRed) &&
+ (theColor1.mGreen == theColor2.mGreen) &&
+ (theColor1.mBlue == theColor2.mBlue) &&
+ (theColor1.mAlpha == theColor2.mAlpha);
+}
+
+bool Sexy::operator!=(const Color& theColor1, const Color& theColor2)
+{
+ return
+ (theColor1.mRed != theColor2.mRed) ||
+ (theColor1.mGreen != theColor2.mGreen) ||
+ (theColor1.mBlue != theColor2.mBlue) ||
+ (theColor1.mAlpha != theColor2.mAlpha);
+}
diff --git a/osframework/source/SexyAppFramework/Color.h b/osframework/source/SexyAppFramework/Color.h
new file mode 100644
index 0000000..c22026e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Color.h
@@ -0,0 +1,50 @@
+#ifndef __COLOR_H__
+#define __COLOR_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+#pragma pack(push,1)
+struct SexyRGBA {unsigned char b,g,r,a;};
+#pragma pack(pop)
+
+class Color
+{
+public:
+ int mRed;
+ int mGreen;
+ int mBlue;
+ int mAlpha;
+
+ static Color Black;
+ static Color White;
+
+public:
+ Color();
+ Color(int theColor);
+ Color(int theColor, int theAlpha);
+ Color(int theRed, int theGreen, int theBlue);
+ Color(int theRed, int theGreen, int theBlue, int theAlpha);
+ Color(const SexyRGBA &theColor);
+ Color(const uchar* theElements);
+ Color(const int* theElements);
+
+ int GetRed() const;
+ int GetGreen() const;
+ int GetBlue() const;
+ int GetAlpha() const;
+ ulong ToInt() const;
+ SexyRGBA ToRGBA() const;
+
+ int& operator[](int theIdx);
+ int operator[](int theIdx) const;
+};
+
+bool operator==(const Color& theColor1, const Color& theColor2);
+bool operator!=(const Color& theColor1, const Color& theColor2);
+
+}
+
+#endif //__COLOR_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Common.cpp b/osframework/source/SexyAppFramework/Common.cpp
new file mode 100644
index 0000000..ea801fd
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Common.cpp
@@ -0,0 +1,1324 @@
+#include "Common.h"
+#include "MTRand.h"
+#include "Debug.h"
+#include <direct.h>
+#include <io.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <aclapi.h>
+
+#include "PerfTimer.h"
+
+HINSTANCE Sexy::gHInstance;
+bool Sexy::gDebug = false;
+static Sexy::MTRand gMTRand;
+namespace Sexy
+{
+ std::string gAppDataFolder = "";
+}
+
+int Sexy::Rand()
+{
+ return gMTRand.Next();
+}
+
+int Sexy::Rand(int range)
+{
+ return gMTRand.Next((unsigned long)range);
+}
+
+float Sexy::Rand(float range)
+{
+ return gMTRand.Next(range);
+}
+
+void Sexy::SRand(ulong theSeed)
+{
+ gMTRand.SRand(theSeed);
+}
+
+bool Sexy::CheckFor98Mill()
+{
+ static bool needOsCheck = true;
+ static bool is98Mill = false;
+
+ if (needOsCheck)
+ {
+ bool invalid = false;
+ OSVERSIONINFOEXA osvi;
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
+
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+ if( GetVersionExA((LPOSVERSIONINFOA)&osvi) == 0)
+ {
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA);
+ if ( GetVersionExA((LPOSVERSIONINFOA)&osvi) == 0)
+ return false;
+ }
+
+ needOsCheck = false;
+ is98Mill = osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS; // let's check Win95, 98, *AND* ME.
+ }
+
+ return is98Mill;
+}
+
+bool Sexy::CheckForVista()
+{
+ static bool needOsCheck = true;
+ static bool isVista = false;
+
+ if (needOsCheck)
+ {
+ bool invalid = false;
+ OSVERSIONINFOEXA osvi;
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
+
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+ if( GetVersionExA((LPOSVERSIONINFOA)&osvi) == 0)
+ {
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA);
+ if ( GetVersionExA((LPOSVERSIONINFOA)&osvi) == 0)
+ return false;
+ }
+
+ needOsCheck = false;
+ isVista = osvi.dwMajorVersion >= 6;
+ }
+
+ return isVista;
+}
+
+std::string Sexy::GetAppDataFolder()
+{
+ return Sexy::gAppDataFolder;
+}
+
+void Sexy::SetAppDataFolder(const std::string& thePath)
+{
+ if (CheckForVista())
+ {
+ std::string aPath = thePath;
+ if (!aPath.empty())
+ {
+ if (aPath[aPath.length()-1] != '\\' && aPath[aPath.length()-1] != '/')
+ aPath += '\\';
+ }
+
+ Sexy::gAppDataFolder = aPath;
+ }
+}
+
+
+std::string Sexy::URLEncode(const std::string& theString)
+{
+ char* aHexChars = "0123456789ABCDEF";
+
+ std::string aString;
+
+ for (unsigned i = 0; i < theString.length(); i++)
+ {
+ switch (theString[i])
+ {
+ case ' ':
+ aString.insert(aString.end(), '+');
+ break;
+ case '?':
+ case '&':
+ case '%':
+ case '+':
+ case '\r':
+ case '\n':
+ case '\t':
+ aString.insert(aString.end(), '%');
+ aString.insert(aString.end(), aHexChars[(theString[i] >> 4) & 0xF]);
+ aString.insert(aString.end(), aHexChars[(theString[i] ) & 0xF]);
+ break;
+ default:
+ aString.insert(aString.end(), theString[i]);
+ }
+ }
+
+ return aString;
+}
+
+std::string Sexy::StringToUpper(const std::string& theString)
+{
+ std::string aString;
+
+ for (unsigned i = 0; i < theString.length(); i++)
+ aString += toupper(theString[i]);
+
+ return aString;
+}
+
+std::wstring Sexy::StringToUpper(const std::wstring& theString)
+{
+ std::wstring aString;
+
+ for (unsigned i = 0; i < theString.length(); i++)
+ aString += towupper(theString[i]);
+
+ return aString;
+}
+
+std::string Sexy::StringToLower(const std::string& theString)
+{
+ std::string aString;
+
+ for (unsigned i = 0; i < theString.length(); i++)
+ aString += tolower(theString[i]);
+
+ return aString;
+}
+
+std::wstring Sexy::StringToLower(const std::wstring& theString)
+{
+ std::wstring aString;
+
+ for (unsigned i = 0; i < theString.length(); ++i)
+ aString += tolower(theString[i]);
+
+ return aString;
+}
+
+std::wstring Sexy::StringToWString(const std::string &theString)
+{
+ std::wstring aString;
+ aString.reserve(theString.length());
+ for(size_t i = 0; i < theString.length(); ++i)
+ aString += (unsigned char)theString[i];
+ return aString;
+}
+
+std::string Sexy::WStringToString(const std::wstring &theString)
+{
+ size_t aRequiredLength = wcstombs( NULL, theString.c_str(), 0 );
+ if (aRequiredLength < 16384)
+ {
+ char aBuffer[16384];
+ wcstombs( aBuffer, theString.c_str(), 16384 );
+ return std::string(aBuffer);
+ }
+ else
+ {
+ DBG_ASSERTE(aRequiredLength != (size_t)-1);
+ if (aRequiredLength == (size_t)-1) return "";
+
+ char* aBuffer = new char[aRequiredLength+1];
+ wcstombs( aBuffer, theString.c_str(), aRequiredLength+1 );
+ std::string aStr = aBuffer;
+ delete[] aBuffer;
+ return aStr;
+ }
+}
+
+SexyString Sexy::StringToSexyString(const std::string& theString)
+{
+#ifdef _USE_WIDE_STRING
+ return StringToWString(theString);
+#else
+ return SexyString(theString);
+#endif
+}
+
+SexyString Sexy::WStringToSexyString(const std::wstring &theString)
+{
+#ifdef _USE_WIDE_STRING
+ return SexyString(theString);
+#else
+ return WStringToString(theString);
+#endif
+}
+
+std::string Sexy::SexyStringToString(const SexyString& theString)
+{
+#ifdef _USE_WIDE_STRING
+ return WStringToString(theString);
+#else
+ return std::string(theString);
+#endif
+}
+
+std::wstring Sexy::SexyStringToWString(const SexyString& theString)
+{
+#ifdef _USE_WIDE_STRING
+ return std::wstring(theString);
+#else
+ return StringToWString(theString);
+#endif
+}
+
+std::string Sexy::Trim(const std::string& theString)
+{
+ int aStartPos = 0;
+ while ( aStartPos < (int) theString.length() && isspace(theString[aStartPos]) )
+ aStartPos++;
+
+ int anEndPos = theString.length() - 1;
+ while ( anEndPos >= 0 && isspace(theString[anEndPos]) )
+ anEndPos--;
+
+ return theString.substr(aStartPos, anEndPos - aStartPos + 1);
+}
+
+std::wstring Sexy::Trim(const std::wstring& theString)
+{
+ int aStartPos = 0;
+ while ( aStartPos < (int) theString.length() && iswspace(theString[aStartPos]) )
+ aStartPos++;
+
+ int anEndPos = theString.length() - 1;
+ while ( anEndPos >= 0 && iswspace(theString[anEndPos]) )
+ anEndPos--;
+
+ return theString.substr(aStartPos, anEndPos - aStartPos + 1);
+}
+
+bool Sexy::StringToInt(const std::string theString, int* theIntVal)
+{
+ *theIntVal = 0;
+
+ if (theString.length() == 0)
+ return false;
+
+ int theRadix = 10;
+ bool isNeg = false;
+
+ unsigned i = 0;
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (; i < theString.length(); i++)
+ {
+ char aChar = theString[i];
+
+ if ((theRadix == 10) && (aChar >= '0') && (aChar <= '9'))
+ *theIntVal = (*theIntVal * 10) + (aChar - '0');
+ else if ((theRadix == 0x10) &&
+ (((aChar >= '0') && (aChar <= '9')) ||
+ ((aChar >= 'A') && (aChar <= 'F')) ||
+ ((aChar >= 'a') && (aChar <= 'f'))))
+ {
+ if (aChar <= '9')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - '0');
+ else if (aChar <= 'F')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - 'A') + 0x0A;
+ else
+ *theIntVal = (*theIntVal * 0x10) + (aChar - 'a') + 0x0A;
+ }
+ else if (((aChar == 'x') || (aChar == 'X')) && (i == 1) && (*theIntVal == 0))
+ {
+ theRadix = 0x10;
+ }
+ else
+ {
+ *theIntVal = 0;
+ return false;
+ }
+ }
+
+ if (isNeg)
+ *theIntVal = -*theIntVal;
+
+ return true;
+}
+
+bool Sexy::StringToInt(const std::wstring theString, int* theIntVal)
+{
+ *theIntVal = 0;
+
+ if (theString.length() == 0)
+ return false;
+
+ int theRadix = 10;
+ bool isNeg = false;
+
+ unsigned i = 0;
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (; i < theString.length(); i++)
+ {
+ wchar_t aChar = theString[i];
+
+ if ((theRadix == 10) && (aChar >= L'0') && (aChar <= L'9'))
+ *theIntVal = (*theIntVal * 10) + (aChar - L'0');
+ else if ((theRadix == 0x10) &&
+ (((aChar >= L'0') && (aChar <= L'9')) ||
+ ((aChar >= L'A') && (aChar <= L'F')) ||
+ ((aChar >= L'a') && (aChar <= L'f'))))
+ {
+ if (aChar <= L'9')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - L'0');
+ else if (aChar <= L'F')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - L'A') + 0x0A;
+ else
+ *theIntVal = (*theIntVal * 0x10) + (aChar - L'a') + 0x0A;
+ }
+ else if (((aChar == L'x') || (aChar == L'X')) && (i == 1) && (*theIntVal == 0))
+ {
+ theRadix = 0x10;
+ }
+ else
+ {
+ *theIntVal = 0;
+ return false;
+ }
+ }
+
+ if (isNeg)
+ *theIntVal = -*theIntVal;
+
+ return true;
+}
+
+bool Sexy::StringToDouble(const std::string theString, double* theDoubleVal)
+{
+ *theDoubleVal = 0.0;
+
+ if (theString.length() == 0)
+ return false;
+
+ bool isNeg = false;
+
+ unsigned i = 0;
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (; i < theString.length(); i++)
+ {
+ char aChar = theString[i];
+
+ if ((aChar >= '0') && (aChar <= '9'))
+ *theDoubleVal = (*theDoubleVal * 10) + (aChar - '0');
+ else if (aChar == '.')
+ {
+ i++;
+ break;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+ }
+
+ double aMult = 0.1;
+ for (; i < theString.length(); i++)
+ {
+ char aChar = theString[i];
+
+ if ((aChar >= '0') && (aChar <= '9'))
+ {
+ *theDoubleVal += (aChar - '0') * aMult;
+ aMult /= 10.0;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+ }
+
+ if (isNeg)
+ *theDoubleVal = -*theDoubleVal;
+
+ return true;
+}
+
+bool Sexy::StringToDouble(const std::wstring theString, double* theDoubleVal)
+{
+ *theDoubleVal = 0.0;
+
+ if (theString.length() == 0)
+ return false;
+
+ bool isNeg = false;
+
+ unsigned i = 0;
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (; i < theString.length(); i++)
+ {
+ wchar_t aChar = theString[i];
+
+ if ((aChar >= L'0') && (aChar <= L'9'))
+ *theDoubleVal = (*theDoubleVal * 10) + (aChar - L'0');
+ else if (aChar == L'.')
+ {
+ i++;
+ break;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+ }
+
+ double aMult = 0.1;
+ for (; i < theString.length(); i++)
+ {
+ wchar_t aChar = theString[i];
+
+ if ((aChar >= L'0') && (aChar <= L'9'))
+ {
+ *theDoubleVal += (aChar - L'0') * aMult;
+ aMult /= 10.0;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+ }
+
+ if (isNeg)
+ *theDoubleVal = -*theDoubleVal;
+
+ return true;
+}
+
+// TODO: Use <locale> for localization of number output?
+SexyString Sexy::CommaSeperate(int theValue)
+{
+ if (theValue == 0)
+ return _S("0");
+
+ SexyString aCurString;
+
+ int aPlace = 0;
+ int aCurValue = theValue;
+
+ while (aCurValue > 0)
+ {
+ if ((aPlace != 0) && (aPlace % 3 == 0))
+ aCurString = _S(',') + aCurString;
+ aCurString = (SexyChar) (_S('0') + (aCurValue % 10)) + aCurString;
+ aCurValue /= 10;
+ aPlace++;
+ }
+
+ return aCurString;
+}
+
+std::string Sexy::GetCurDir()
+{
+ char aDir[256];
+ return _getcwd(aDir, sizeof(aDir));
+}
+
+std::string Sexy::GetFullPath(const std::string& theRelPath)
+{
+ return GetPathFrom(theRelPath, GetCurDir());
+}
+
+std::string Sexy::GetPathFrom(const std::string& theRelPath, const std::string& theDir)
+{
+ std::string aDriveString;
+ std::string aNewPath = theDir;
+
+ if ((theRelPath.length() >= 2) && (theRelPath[1] == ':'))
+ return theRelPath;
+
+ char aSlashChar = '/';
+
+ if ((theRelPath.find('\\') != -1) || (theDir.find('\\') != -1))
+ aSlashChar = '\\';
+
+ if ((aNewPath.length() >= 2) && (aNewPath[1] == ':'))
+ {
+ aDriveString = aNewPath.substr(0, 2);
+ aNewPath.erase(aNewPath.begin(), aNewPath.begin()+2);
+ }
+
+ // Append a trailing slash if necessary
+ if ((aNewPath.length() > 0) && (aNewPath[aNewPath.length()-1] != '\\') && (aNewPath[aNewPath.length()-1] != '/'))
+ aNewPath += aSlashChar;
+
+ std::string aTempRelPath = theRelPath;
+
+ for (;;)
+ {
+ if (aNewPath.length() == 0)
+ break;
+
+ int aFirstSlash = aTempRelPath.find('\\');
+ int aFirstForwardSlash = aTempRelPath.find('/');
+
+ if ((aFirstSlash == -1) || ((aFirstForwardSlash != -1) && (aFirstForwardSlash < aFirstSlash)))
+ aFirstSlash = aFirstForwardSlash;
+
+ if (aFirstSlash == -1)
+ break;
+
+ std::string aChDir = aTempRelPath.substr(0, aFirstSlash);
+
+ aTempRelPath.erase(aTempRelPath.begin(), aTempRelPath.begin() + aFirstSlash + 1);
+
+ if (aChDir.compare("..") == 0)
+ {
+ int aLastDirStart = aNewPath.length() - 1;
+ while ((aLastDirStart > 0) && (aNewPath[aLastDirStart-1] != '\\') && (aNewPath[aLastDirStart-1] != '/'))
+ aLastDirStart--;
+
+ std::string aLastDir = aNewPath.substr(aLastDirStart, aNewPath.length() - aLastDirStart - 1);
+ if (aLastDir.compare("..") == 0)
+ {
+ aNewPath += "..";
+ aNewPath += aSlashChar;
+ }
+ else
+ {
+ aNewPath.erase(aNewPath.begin() + aLastDirStart, aNewPath.end());
+ }
+ }
+ else if (aChDir.compare("") == 0)
+ {
+ aNewPath = aSlashChar;
+ break;
+ }
+ else if (aChDir.compare(".") != 0)
+ {
+ aNewPath += aChDir + aSlashChar;
+ break;
+ }
+ }
+
+ aNewPath = aDriveString + aNewPath + aTempRelPath;
+
+ if (aSlashChar == '/')
+ {
+ for (;;)
+ {
+ int aSlashPos = aNewPath.find('\\');
+ if (aSlashPos == -1)
+ break;
+ aNewPath[aSlashPos] = '/';
+ }
+ }
+ else
+ {
+ for (;;)
+ {
+ int aSlashPos = aNewPath.find('/');
+ if (aSlashPos == -1)
+ break;
+ aNewPath[aSlashPos] = '\\';
+ }
+ }
+
+ return aNewPath;
+}
+
+bool Sexy::AllowAllAccess(const std::string& theFileName)
+{
+ HMODULE aLib = LoadLibraryA("advapi32.dll");
+ if (aLib == NULL)
+ return false;
+
+ BOOL (WINAPI *fnSetFileSecurity)(LPCTSTR lpFileName, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor);
+ BOOL (WINAPI *fnSetSecurityDescriptorDacl)(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted);
+ BOOL (WINAPI *fnInitializeSecurityDescriptor)(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision);
+ BOOL (WINAPI *fnAllocateAndInitializeSid)(
+ PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+ BYTE nSubAuthorityCount,
+ DWORD dwSubAuthority0,
+ DWORD dwSubAuthority1,
+ DWORD dwSubAuthority2,
+ DWORD dwSubAuthority3,
+ DWORD dwSubAuthority4,
+ DWORD dwSubAuthority5,
+ DWORD dwSubAuthority6,
+ DWORD dwSubAuthority7,
+ PSID* pSid
+ );
+ DWORD (WINAPI *fnSetEntriesInAcl)(ULONG cCountOfExplicitEntries, PEXPLICIT_ACCESS pListOfExplicitEntries, PACL OldAcl, PACL* NewAcl);
+ PVOID (WINAPI *fnFreeSid)(PSID pSid);
+
+ *(void**)&fnSetFileSecurity = (void*)GetProcAddress(aLib, "SetFileSecurityA");
+ *(void**)&fnSetSecurityDescriptorDacl = (void*)GetProcAddress(aLib, "SetSecurityDescriptorDacl");
+ *(void**)&fnInitializeSecurityDescriptor = (void*)GetProcAddress(aLib, "InitializeSecurityDescriptor");
+ *(void**)&fnAllocateAndInitializeSid = (void*)GetProcAddress(aLib, "AllocateAndInitializeSid");
+ *(void**)&fnSetEntriesInAcl = (void*)GetProcAddress(aLib, "SetEntriesInAclA");
+ *(void**)&fnFreeSid = (void*) GetProcAddress(aLib, "FreeSid");
+
+ if (!(fnSetFileSecurity && fnSetSecurityDescriptorDacl && fnInitializeSecurityDescriptor && fnAllocateAndInitializeSid && fnSetEntriesInAcl && fnFreeSid))
+ {
+ FreeLibrary(aLib);
+ return false;
+ }
+
+
+ PSID pEveryoneSID = NULL;
+ SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
+ bool result = false;
+
+ // Create a well-known SID for the Everyone group.
+ if (fnAllocateAndInitializeSid(&SIDAuthWorld, 1,
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &pEveryoneSID))
+ {
+ EXPLICIT_ACCESS ea;
+
+ // Initialize an EXPLICIT_ACCESS structure for an ACE.
+ // The ACE will allow Everyone read access to the key.
+ ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
+ ea.grfAccessPermissions = STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL;
+ ea.grfAccessMode = SET_ACCESS;
+ ea.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
+ ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
+ ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
+ ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
+
+ // Create a new ACL that contains the new ACEs.
+ PACL pACL = NULL;
+ if (fnSetEntriesInAcl(1, &ea, NULL, &pACL) == ERROR_SUCCESS)
+ {
+ // Initialize a security descriptor.
+ PSECURITY_DESCRIPTOR pSD = (PSECURITY_DESCRIPTOR) new char[SECURITY_DESCRIPTOR_MIN_LENGTH];
+
+ if (fnInitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
+ {
+ // Add the ACL to the security descriptor.
+ if (fnSetSecurityDescriptorDacl(pSD,
+ TRUE, // bDaclPresent flag
+ pACL,
+ FALSE)) // not a default DACL
+ {
+ if (fnSetFileSecurity(theFileName.c_str(), DACL_SECURITY_INFORMATION, pSD))
+ result = true;
+ }
+ }
+ }
+ }
+
+ FreeLibrary(aLib);
+ return result;
+}
+
+bool Sexy::Deltree(const std::string& thePath)
+{
+ bool success = true;
+
+ std::string aSourceDir = thePath;
+
+ if (aSourceDir.length() < 2)
+ return false;
+
+ if ((aSourceDir[aSourceDir.length() - 1] != '\\') ||
+ (aSourceDir[aSourceDir.length() - 1] != '/'))
+ aSourceDir += "\\";
+
+ WIN32_FIND_DATAA aFindData;
+
+ HANDLE aFindHandle = FindFirstFileA((aSourceDir + "*.*").c_str(), &aFindData);
+ if (aFindHandle == INVALID_HANDLE_VALUE)
+ return false;
+
+ do
+ {
+ if ((aFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ {
+ if ((strcmp(aFindData.cFileName, ".") != 0) &&
+ (strcmp(aFindData.cFileName, "..") != 0))
+ {
+ // Follow the directory
+ if (!Deltree(aSourceDir + aFindData.cFileName))
+ success = false;
+ }
+ }
+ else
+ {
+ std::string aFullName = aSourceDir + aFindData.cFileName;
+ if (!DeleteFileA(aFullName.c_str()))
+ success = false;
+ }
+ }
+ while (FindNextFileA(aFindHandle, &aFindData));
+ FindClose(aFindHandle);
+
+ if (rmdir(thePath.c_str()) == 0)
+ success = false;
+
+ return success;
+}
+
+bool Sexy::FileExists(const std::string& theFileName)
+{
+ WIN32_FIND_DATAA aFindData;
+
+ HANDLE aFindHandle = FindFirstFileA(theFileName.c_str(), &aFindData);
+ if (aFindHandle == INVALID_HANDLE_VALUE)
+ return false;
+
+ FindClose(aFindHandle);
+ return true;
+}
+
+void Sexy::MkDir(const std::string& theDir)
+{
+ std::string aPath = theDir;
+
+ int aCurPos = 0;
+ for (;;)
+ {
+ int aSlashPos = aPath.find_first_of("\\/", aCurPos);
+ if (aSlashPos == -1)
+ {
+ _mkdir(aPath.c_str());
+ break;
+ }
+
+ aCurPos = aSlashPos+1;
+
+ std::string aCurPath = aPath.substr(0, aSlashPos);
+ _mkdir(aCurPath.c_str());
+ }
+}
+
+std::string Sexy::GetFileName(const std::string& thePath, bool noExtension)
+{
+ int aLastSlash = max((int) thePath.rfind('\\'), (int) thePath.rfind('/'));
+
+ if (noExtension)
+ {
+ int aLastDot = (int)thePath.rfind('.');
+ if (aLastDot > aLastSlash)
+ return thePath.substr(aLastSlash + 1, aLastDot - aLastSlash - 1);
+ }
+
+ if (aLastSlash == -1)
+ return thePath;
+ else
+ return thePath.substr(aLastSlash + 1);
+}
+
+std::string Sexy::GetFileDir(const std::string& thePath, bool withSlash)
+{
+ int aLastSlash = max((int) thePath.rfind('\\'), (int) thePath.rfind('/'));
+
+ if (aLastSlash == -1)
+ return "";
+ else
+ {
+ if (withSlash)
+ return thePath.substr(0, aLastSlash+1);
+ else
+ return thePath.substr(0, aLastSlash);
+ }
+}
+
+std::string Sexy::RemoveTrailingSlash(const std::string& theDirectory)
+{
+ int aLen = theDirectory.length();
+
+ if ((aLen > 0) && ((theDirectory[aLen-1] == '\\') || (theDirectory[aLen-1] == '/')))
+ return theDirectory.substr(0, aLen - 1);
+ else
+ return theDirectory;
+}
+
+std::string Sexy::AddTrailingSlash(const std::string& theDirectory, bool backSlash)
+{
+ if (!theDirectory.empty())
+ {
+ char aChar = theDirectory[theDirectory.length()-1];
+ if (aChar!='\\' && aChar!='/')
+ return theDirectory + (backSlash?'\\':'/');
+ else
+ return theDirectory;
+ }
+ else
+ return "";
+}
+
+
+time_t Sexy::GetFileDate(const std::string& theFileName)
+{
+ time_t aFileDate = 0;
+
+ WIN32_FIND_DATAA aFindData;
+ HANDLE aFindHandle = ::FindFirstFileA(theFileName.c_str(), &aFindData);
+
+ if (aFindHandle != INVALID_HANDLE_VALUE)
+ {
+ FILETIME aFileTime = aFindData.ftLastWriteTime;
+
+ //FileTimeToUnixTime(&aFileTime, &aFileDate, FALSE);
+
+ LONGLONG ll = (__int64) aFileTime.dwHighDateTime << 32;
+ ll = ll + aFileTime.dwLowDateTime - 116444736000000000;
+ aFileDate = (time_t) (ll/10000000);
+
+ FindClose(aFindHandle);
+ }
+
+ return aFileDate;
+}
+
+std::string Sexy::vformat(const char* fmt, va_list argPtr)
+{
+ // We draw the line at a 1MB string.
+ const int maxSize = 1000000;
+
+ // If the string is less than 161 characters,
+ // allocate it on the stack because this saves
+ // the malloc/free time.
+ const int bufSize = 161;
+ char stackBuffer[bufSize];
+
+ int attemptedSize = bufSize - 1;
+
+ int numChars = 0;
+#ifdef _WIN32
+ numChars = _vsnprintf(stackBuffer, attemptedSize, fmt, argPtr);
+#else
+ numChars = vsnprintf(stackBuffer, attemptedSize, fmt, argPtr);
+#endif
+
+ //cout << "NumChars: " << numChars << endl;
+
+ if ((numChars >= 0) && (numChars <= attemptedSize))
+ {
+ // Needed for case of 160-character printf thing
+ stackBuffer[numChars] = '\0';
+
+ // Got it on the first try.
+ return std::string(stackBuffer);
+ }
+
+ // Now use the heap.
+ char* heapBuffer = NULL;
+
+ while (((numChars == -1) || (numChars > attemptedSize)) &&
+ (attemptedSize < maxSize))
+ {
+ // Try a bigger size
+ attemptedSize *= 2;
+ heapBuffer = (char*)realloc(heapBuffer, (attemptedSize + 1));
+#ifdef _WIN32
+ numChars = _vsnprintf(heapBuffer, attemptedSize, fmt, argPtr);
+#else
+ numChars = vsnprintf(heapBuffer, attemptedSize, fmt, argPtr);
+#endif
+ }
+
+ heapBuffer[numChars] = 0;
+
+ std::string result = std::string(heapBuffer);
+
+ free(heapBuffer);
+ return result;
+}
+
+//overloaded StrFormat: should only be used by the xml strings
+std::string Sexy::StrFormat(const char* fmt ...)
+{
+ va_list argList;
+ va_start(argList, fmt);
+ std::string result = vformat(fmt, argList);
+ va_end(argList);
+
+ return result;
+}
+
+std::wstring Sexy::vformat(const wchar_t* fmt, va_list argPtr)
+{
+ // We draw the line at a 1MB string.
+ const int maxSize = 1000000;
+
+ // If the string is less than 161 characters,
+ // allocate it on the stack because this saves
+ // the malloc/free time.
+ const int bufSize = 161;
+ wchar_t stackBuffer[bufSize];
+
+ int attemptedSize = bufSize - 1;
+
+ int numChars = 0;
+#ifdef _WIN32
+ numChars = _vsnwprintf(stackBuffer, attemptedSize, fmt, argPtr);
+#else
+ numChars = vsnwprintf(stackBuffer, attemptedSize, fmt, argPtr);
+#endif
+
+ //cout << "NumChars: " << numChars << endl;
+
+ if ((numChars >= 0) && (numChars <= attemptedSize))
+ {
+ // Needed for case of 160-character printf thing
+ stackBuffer[numChars] = '\0';
+
+ // Got it on the first try.
+ return std::wstring(stackBuffer);
+ }
+
+ // Now use the heap.
+ wchar_t* heapBuffer = NULL;
+
+ while (((numChars == -1) || (numChars > attemptedSize)) &&
+ (attemptedSize < maxSize))
+ {
+ // Try a bigger size
+ attemptedSize *= 2;
+ heapBuffer = (wchar_t*)realloc(heapBuffer, (attemptedSize + 1));
+#ifdef _WIN32
+ numChars = _vsnwprintf(heapBuffer, attemptedSize, fmt, argPtr);
+#else
+ numChars = vsnwprintf(heapBuffer, attemptedSize, fmt, argPtr);
+#endif
+ }
+
+ heapBuffer[numChars] = 0;
+
+ std::wstring result = std::wstring(heapBuffer);
+
+ free(heapBuffer);
+
+ return result;
+}
+
+//overloaded StrFormat: should only be used by the xml strings
+std::wstring Sexy::StrFormat(const wchar_t* fmt ...)
+{
+ va_list argList;
+ va_start(argList, fmt);
+ std::wstring result = vformat(fmt, argList);
+ va_end(argList);
+
+ return result;
+}
+
+std::string Sexy::Evaluate(const std::string& theString, const DefinesMap& theDefinesMap)
+{
+ std::string anEvaluatedString = theString;
+
+ for (;;)
+ {
+ int aPercentPos = anEvaluatedString.find('%');
+
+ if (aPercentPos == std::string::npos)
+ break;
+
+ int aSecondPercentPos = anEvaluatedString.find('%', aPercentPos + 1);
+ if (aSecondPercentPos == std::string::npos)
+ break;
+
+ std::string aName = anEvaluatedString.substr(aPercentPos + 1, aSecondPercentPos - aPercentPos - 1);
+
+ std::string aValue;
+ DefinesMap::const_iterator anItr = theDefinesMap.find(aName);
+ if (anItr != theDefinesMap.end())
+ aValue = anItr->second;
+ else
+ aValue = "";
+
+ anEvaluatedString.erase(anEvaluatedString.begin() + aPercentPos, anEvaluatedString.begin() + aSecondPercentPos + 1);
+ anEvaluatedString.insert(anEvaluatedString.begin() + aPercentPos, aValue.begin(), aValue.begin() + aValue.length());
+ }
+
+ return anEvaluatedString;
+}
+
+std::string Sexy::XMLDecodeString(const std::string& theString)
+{
+ std::string aNewString;
+
+ int aUTF8Len = 0;
+ int aUTF8CurVal = 0;
+
+ for (ulong i = 0; i < theString.length(); i++)
+ {
+ char c = theString[i];
+
+ if (c == '&')
+ {
+ int aSemiPos = theString.find(';', i);
+
+ if (aSemiPos != -1)
+ {
+ std::string anEntName = theString.substr(i+1, aSemiPos-i-1);
+ i = aSemiPos;
+
+ if (anEntName == "lt")
+ c = '<';
+ else if (anEntName == "amp")
+ c = '&';
+ else if (anEntName == "gt")
+ c = '>';
+ else if (anEntName == "quot")
+ c = '"';
+ else if (anEntName == "apos")
+ c = '\'';
+ else if (anEntName == "nbsp")
+ c = ' ';
+ else if (anEntName == "cr")
+ c = '\n';
+ }
+ }
+
+ aNewString += c;
+ }
+
+ return aNewString;
+}
+
+std::wstring Sexy::XMLDecodeString(const std::wstring& theString)
+{
+ std::wstring aNewString;
+
+ int aUTF8Len = 0;
+ int aUTF8CurVal = 0;
+
+ for (ulong i = 0; i < theString.length(); i++)
+ {
+ wchar_t c = theString[i];
+
+ if (c == L'&')
+ {
+ int aSemiPos = theString.find(L';', i);
+
+ if (aSemiPos != -1)
+ {
+ std::wstring anEntName = theString.substr(i+1, aSemiPos-i-1);
+ i = aSemiPos;
+
+ if (anEntName == L"lt")
+ c = L'<';
+ else if (anEntName == L"amp")
+ c = L'&';
+ else if (anEntName == L"gt")
+ c = L'>';
+ else if (anEntName == L"quot")
+ c = L'"';
+ else if (anEntName == L"apos")
+ c = L'\'';
+ else if (anEntName == L"nbsp")
+ c = L' ';
+ else if (anEntName == L"cr")
+ c = L'\n';
+ }
+ }
+
+ aNewString += c;
+ }
+
+ return aNewString;
+}
+
+
+std::string Sexy::XMLEncodeString(const std::string& theString)
+{
+ std::string aNewString;
+
+ bool hasSpace = false;
+
+ for (ulong i = 0; i < theString.length(); i++)
+ {
+ char c = theString[i];
+
+ if (c == ' ')
+ {
+ if (hasSpace)
+ {
+ aNewString += "&nbsp;";
+ continue;
+ }
+
+ hasSpace = true;
+ }
+ else
+ hasSpace = false;
+
+ /*if ((uchar) c >= 0x80)
+ {
+ // Convert to UTF
+ aNewString += (char) (0xC0 | ((c >> 6) & 0xFF));
+ aNewString += (char) (0x80 | (c & 0x3F));
+ }
+ else*/
+ {
+ switch (c)
+ {
+ case '<':
+ aNewString += "&lt;";
+ break;
+ case '&':
+ aNewString += "&amp;";
+ break;
+ case '>':
+ aNewString += "&gt;";
+ break;
+ case '"':
+ aNewString += "&quot;";
+ break;
+ case '\'':
+ aNewString += "&apos;";
+ break;
+ case '\n':
+ aNewString += "&cr;";
+ break;
+ default:
+ aNewString += c;
+ break;
+ }
+ }
+ }
+
+ return aNewString;
+}
+
+std::wstring Sexy::XMLEncodeString(const std::wstring& theString)
+{
+ std::wstring aNewString;
+
+ bool hasSpace = false;
+
+ for (ulong i = 0; i < theString.length(); i++)
+ {
+ wchar_t c = theString[i];
+
+ if (c == ' ')
+ {
+ if (hasSpace)
+ {
+ aNewString += L"&nbsp;";
+ continue;
+ }
+
+ hasSpace = true;
+ }
+ else
+ hasSpace = false;
+
+ /*if ((uchar) c >= 0x80)
+ {
+ // Convert to UTF
+ aNewString += (char) (0xC0 | ((c >> 6) & 0xFF));
+ aNewString += (char) (0x80 | (c & 0x3F));
+ }
+ else*/
+ {
+ switch (c)
+ {
+ case L'<':
+ aNewString += L"&lt;";
+ break;
+ case L'&':
+ aNewString += L"&amp;";
+ break;
+ case L'>':
+ aNewString += L"&gt;";
+ break;
+ case L'"':
+ aNewString += L"&quot;";
+ break;
+ case L'\'':
+ aNewString += L"&apos;";
+ break;
+ case L'\n':
+ aNewString += L"&cr;";
+ break;
+ default:
+ aNewString += c;
+ break;
+ }
+ }
+ }
+
+ return aNewString;
+}
+
+std::string Sexy::Upper(const std::string& _data)
+{
+ std::string s = _data;
+ std::transform(s.begin(), s.end(), s.begin(), toupper);
+ return s;
+}
+
+std::wstring Sexy::Upper(const std::wstring& _data)
+{
+ std::wstring s = _data;
+ std::transform(s.begin(), s.end(), s.begin(), towupper);
+ return s;
+}
+
+std::string Sexy::Lower(const std::string& _data)
+{
+ std::string s = _data;
+ std::transform(s.begin(), s.end(), s.begin(), tolower);
+ return s;
+}
+
+std::wstring Sexy::Lower(const std::wstring& _data)
+{
+ std::wstring s = _data;
+ std::transform(s.begin(), s.end(), s.begin(), towlower);
+ return s;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int Sexy::StrFindNoCase(const char *theStr, const char *theFind)
+{
+ int p1,p2;
+ int cp = 0;
+ const int len1 = (int)strlen(theStr);
+ const int len2 = (int)strlen(theFind);
+ while(cp < len1)
+ {
+ p1 = cp;
+ p2 = 0;
+ while(p1<len1 && p2<len2)
+ {
+ if(tolower(theStr[p1])!=tolower(theFind[p2]))
+ break;
+
+ p1++; p2++;
+ }
+ if(p2==len2)
+ return p1-len2;
+
+ cp++;
+ }
+
+ return -1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool Sexy::StrPrefixNoCase(const char *theStr, const char *thePrefix, int maxLength)
+{
+ int i;
+ char c1 = 0, c2 = 0;
+ for (i=0; i<maxLength; i++)
+ {
+ c1 = tolower(*theStr++);
+ c2 = tolower(*thePrefix++);
+
+ if (c1==0 || c2==0)
+ break;
+
+ if (c1!=c2)
+ return false;
+ }
+
+ return c2==0 || i==maxLength;
+}
diff --git a/osframework/source/SexyAppFramework/Common.h b/osframework/source/SexyAppFramework/Common.h
new file mode 100644
index 0000000..4925400
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Common.h
@@ -0,0 +1,230 @@
+#ifndef __SEXYAPPFRAMEWORK_COMMON_H__
+#define __SEXYAPPFRAMEWORK_COMMON_H__
+
+#pragma warning(disable:4786)
+#pragma warning(disable:4503)
+
+#undef _WIN32_WINNT
+#undef WIN32_LEAN_AND_MEAN
+
+#define WIN32_LEAN_AND_MEAN
+#define _WIN32_WINNT 0x0500
+#undef _UNICODE
+#undef UNICODE
+
+#include <string>
+#include <vector>
+#include <set>
+#include <map>
+#include <list>
+#include <algorithm>
+#include <cstdlib>
+
+#include <windows.h>
+#include <shellapi.h>
+#include <mmsystem.h>
+#include "ModVal.h"
+
+#ifdef _USE_WIDE_STRING
+
+typedef std::wstring SexyString;
+#define _S(x) L ##x
+
+
+#define sexystrncmp wcsncmp
+#define sexystrcmp wcscmp
+#define sexystricmp wcsicmp
+#define sexysscanf swscanf
+#define sexyatoi _wtoi
+#define sexystrcpy wcscpy
+
+#define SexyStringToStringFast(x) WStringToString(x)
+#define SexyStringToWStringFast(x) (x)
+#define StringToSexyStringFast(x) StringToWString(x)
+#define WStringToSexyStringFast(x) (x)
+
+#ifndef SEXYFRAMEWORK_NO_REDEFINE_WIN_API
+// Redefine the functions and structs we need to be wide-string
+#undef CreateWindowEx
+#undef RegisterClass
+#undef MessageBox
+#undef ShellExecute
+#undef GetTextExtentPoint32
+#undef RegisterWindowMessage
+#undef CreateMutex
+#undef DrawTextEx
+#undef TextOut
+
+#define CreateWindowEx CreateWindowExW
+#define RegisterClass RegisterClassW
+#define WNDCLASS WNDCLASSW
+#define MessageBox MessageBoxW
+#define ShellExecute ShellExecuteW
+#define GetTextExtentPoint32 GetTextExtentPoint32W
+#define RegisterWindowMessage RegisterWindowMessageW
+#define CreateMutex CreateMutexW
+#define DrawTextEx DrawTextExW
+#define TextOut TextOutW
+#endif
+
+#else
+
+typedef std::string SexyString;
+#define _S(x) x
+
+
+#define sexystrncmp strncmp
+#define sexystrcmp strcmp
+#define sexystricmp stricmp
+#define sexysscanf sscanf
+#define sexyatoi atoi
+#define sexystrcpy strcpy
+
+#define SexyStringToStringFast(x) (x)
+#define SexyStringToWStringFast(x) StringToWString(x)
+#define StringToSexyStringFast(x) (x)
+#define WStringToSexyStringFast(x) WStringToString(x)
+
+#endif
+
+#define LONG_BIGE_TO_NATIVE(l) (((l >> 24) & 0xFF) | ((l >> 8) & 0xFF00) | ((l << 8) & 0xFF0000) | ((l << 24) & 0xFF000000))
+#define WORD_BIGE_TO_NATIVE(w) (((w >> 8) & 0xFF) | ((w << 8) & 0xFF00))
+#define LONG_LITTLEE_TO_NATIVE(l) (l)
+#define WORD_LITTLEE_TO_NATIVE(w) (w)
+
+#define LENGTH(anyarray) (sizeof(anyarray) / sizeof(anyarray[0]))
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef __int64 int64;
+
+typedef std::map<std::string, std::string> DefinesMap;
+typedef std::map<std::wstring, std::wstring> WStringWStringMap;
+typedef SexyString::value_type SexyChar;
+#define HAS_SEXYCHAR
+
+namespace Sexy
+{
+
+const ulong SEXY_RAND_MAX = 0x7FFFFFFF;
+
+extern bool gDebug;
+extern HINSTANCE gHInstance;
+
+int Rand();
+int Rand(int range);
+float Rand(float range);
+void SRand(ulong theSeed);
+extern std::string vformat(const char* fmt, va_list argPtr);
+extern std::wstring vformat(const wchar_t* fmt, va_list argPtr);
+extern std::string StrFormat(const char* fmt ...);
+extern std::wstring StrFormat(const wchar_t* fmt ...);
+bool CheckFor98Mill();
+bool CheckForVista();
+std::string GetAppDataFolder();
+void SetAppDataFolder(const std::string& thePath);
+std::string URLEncode(const std::string& theString);
+std::string StringToUpper(const std::string& theString);
+std::wstring StringToUpper(const std::wstring& theString);
+std::string StringToLower(const std::string& theString);
+std::wstring StringToLower(const std::wstring& theString);
+std::wstring StringToWString(const std::string &theString);
+std::string WStringToString(const std::wstring &theString);
+SexyString StringToSexyString(const std::string& theString);
+SexyString WStringToSexyString(const std::wstring& theString);
+std::string SexyStringToString(const SexyString& theString);
+std::wstring SexyStringToWString(const SexyString& theString);
+std::string Upper(const std::string& theData);
+std::wstring Upper(const std::wstring& theData);
+std::string Lower(const std::string& theData);
+std::wstring Lower(const std::wstring& theData);
+std::string Trim(const std::string& theString);
+std::wstring Trim(const std::wstring& theString);
+bool StringToInt(const std::string theString, int* theIntVal);
+bool StringToDouble(const std::string theString, double* theDoubleVal);
+bool StringToInt(const std::wstring theString, int* theIntVal);
+bool StringToDouble(const std::wstring theString, double* theDoubleVal);
+int StrFindNoCase(const char *theStr, const char *theFind);
+bool StrPrefixNoCase(const char *theStr, const char *thePrefix, int maxLength = 10000000);
+SexyString CommaSeperate(int theValue);
+std::string Evaluate(const std::string& theString, const DefinesMap& theDefinesMap);
+std::string XMLDecodeString(const std::string& theString);
+std::string XMLEncodeString(const std::string& theString);
+std::wstring XMLDecodeString(const std::wstring& theString);
+std::wstring XMLEncodeString(const std::wstring& theString);
+
+bool Deltree(const std::string& thePath);
+bool FileExists(const std::string& theFileName);
+void MkDir(const std::string& theDir);
+std::string GetFileName(const std::string& thePath, bool noExtension = false);
+std::string GetFileDir(const std::string& thePath, bool withSlash = false);
+std::string RemoveTrailingSlash(const std::string& theDirectory);
+std::string AddTrailingSlash(const std::string& theDirectory, bool backSlash = false);
+time_t GetFileDate(const std::string& theFileName);
+std::string GetCurDir();
+std::string GetFullPath(const std::string& theRelPath);
+std::string GetPathFrom(const std::string& theRelPath, const std::string& theDir);
+bool AllowAllAccess(const std::string& theFileName);
+
+
+inline void inlineUpper(std::string &theData)
+{
+ //std::transform(theData.begin(), theData.end(), theData.begin(), toupper);
+
+ int aStrLen = (int) theData.length();
+ for (int i = 0; i < aStrLen; i++)
+ {
+ theData[i] = toupper(theData[i]);
+ }
+}
+
+inline void inlineUpper(std::wstring &theData)
+{
+ //std::transform(theData.begin(), theData.end(), theData.begin(), toupper);
+
+ int aStrLen = (int) theData.length();
+ for (int i = 0; i < aStrLen; i++)
+ {
+ theData[i] = towupper(theData[i]);
+ }
+}
+
+inline void inlineLower(std::string &theData)
+{
+ std::transform(theData.begin(), theData.end(), theData.begin(), tolower);
+}
+
+inline void inlineLower(std::wstring &theData)
+{
+ std::transform(theData.begin(), theData.end(), theData.begin(), tolower);
+}
+
+inline void inlineLTrim(std::string &theData, const std::string& theChars = " \t\r\n")
+{
+ theData.erase(0, theData.find_first_not_of(theChars));
+}
+
+inline void inlineLTrim(std::wstring &theData, const std::wstring& theChars = L" \t\r\n")
+{
+ theData.erase(0, theData.find_first_not_of(theChars));
+}
+
+
+inline void inlineRTrim(std::string &theData, const std::string& theChars = " \t\r\n")
+{
+ theData.resize(theData.find_last_not_of(theChars) + 1);
+}
+
+inline void inlineTrim(std::string &theData, const std::string& theChars = " \t\r\n")
+{
+ inlineRTrim(theData, theChars);
+ inlineLTrim(theData, theChars);
+}
+
+struct StringLessNoCase { bool operator()(const std::string &s1, const std::string &s2) const { return _stricmp(s1.c_str(),s2.c_str())<0; } };
+
+}
+
+#endif //__SEXYAPPFRAMEWORK_COMMON_H__
diff --git a/osframework/source/SexyAppFramework/CritSect.cpp b/osframework/source/SexyAppFramework/CritSect.cpp
new file mode 100644
index 0000000..26ae4ad
--- /dev/null
+++ b/osframework/source/SexyAppFramework/CritSect.cpp
@@ -0,0 +1,20 @@
+#pragma warning( disable : 4786 )
+
+#include "CritSect.h"
+#include <windows.h>
+
+using namespace Sexy;
+
+////////////////////////////////////////////////////////////////////////////////
+
+CritSect::CritSect(void)
+{
+ InitializeCriticalSection(&mCriticalSection);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+CritSect::~CritSect(void)
+{
+ DeleteCriticalSection(&mCriticalSection);
+}
diff --git a/osframework/source/SexyAppFramework/CritSect.h b/osframework/source/SexyAppFramework/CritSect.h
new file mode 100644
index 0000000..d6e7100
--- /dev/null
+++ b/osframework/source/SexyAppFramework/CritSect.h
@@ -0,0 +1,24 @@
+#ifndef _H_CritSect
+#define _H_CritSect
+
+#include "Common.h"
+
+class CritSync;
+
+namespace Sexy
+{
+
+class CritSect
+{
+private:
+ CRITICAL_SECTION mCriticalSection;
+ friend class AutoCrit;
+
+public:
+ CritSect(void);
+ ~CritSect(void);
+};
+
+}
+
+#endif // _H_CritSect
diff --git a/osframework/source/SexyAppFramework/CursorWidget.cpp b/osframework/source/SexyAppFramework/CursorWidget.cpp
new file mode 100644
index 0000000..a9c3b10
--- /dev/null
+++ b/osframework/source/SexyAppFramework/CursorWidget.cpp
@@ -0,0 +1,30 @@
+#include "CursorWidget.h"
+#include "Image.h"
+
+using namespace Sexy;
+
+CursorWidget::CursorWidget()
+{
+ mImage = NULL;
+ mMouseVisible = false;
+}
+
+void CursorWidget::Draw(Graphics* g)
+{
+ if (mImage != NULL)
+ g->DrawImage(mImage, 0, 0);
+}
+
+void CursorWidget::SetImage(Image* theImage)
+{
+ mImage = theImage;
+ if (mImage != NULL)
+ Resize(mX, mY, theImage->mWidth, theImage->mHeight);
+}
+
+Point CursorWidget::GetHotspot()
+{
+ if (mImage == NULL)
+ return Point(0, 0);
+ return Point(mImage->GetWidth()/2, mImage->GetHeight()/2);
+}
diff --git a/osframework/source/SexyAppFramework/CursorWidget.h b/osframework/source/SexyAppFramework/CursorWidget.h
new file mode 100644
index 0000000..8c4b7ed
--- /dev/null
+++ b/osframework/source/SexyAppFramework/CursorWidget.h
@@ -0,0 +1,28 @@
+#ifndef __CURSORWIDGET_H__
+#define __CURSORWIDGET_H__
+
+#include "Widget.h"
+#include "Point.h"
+
+namespace Sexy
+{
+
+class Image;
+
+class CursorWidget : public Widget
+{
+public:
+ Image* mImage;
+
+public:
+ CursorWidget();
+
+ virtual void Draw(Graphics* g);
+ void SetImage(Image* theImage);
+ Point GetHotspot();
+
+};
+
+}
+
+#endif //__CURSORWIDGET_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/D3D8Helper.cpp b/osframework/source/SexyAppFramework/D3D8Helper.cpp
new file mode 100644
index 0000000..ce24afe
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3D8Helper.cpp
@@ -0,0 +1,276 @@
+// This has to be its own file because d3d8.h and d3d.h conflict
+#undef DIRECT3D_VERSION
+#include <windows.h>
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// This stuff is copied from d3d8.h because you can't include both d3d.h and d3d8.h in a project
+
+#define D3D_SDK_VERSION 220
+DEFINE_GUID(IID_IDirect3D8, 0x1dd9e8da, 0x1c77, 0x4d40, 0xb0, 0xcf, 0x98, 0xfe, 0xfd, 0xff, 0x95, 0x12);
+
+#include "D3D8Helper.h"
+
+
+interface IDirect3D8;
+interface IDirect3DDevice8;
+typedef struct IDirect3D8 *LPDIRECT3D8, *PDIRECT3D8;
+
+#undef INTERFACE
+#define INTERFACE IDirect3D8
+
+typedef enum _D3DFORMAT
+{
+ D3DFMT_UNKNOWN = 0,
+
+ D3DFMT_R8G8B8 = 20,
+ D3DFMT_A8R8G8B8 = 21,
+ D3DFMT_X8R8G8B8 = 22,
+ D3DFMT_R5G6B5 = 23,
+ D3DFMT_X1R5G5B5 = 24,
+ D3DFMT_A1R5G5B5 = 25,
+ D3DFMT_A4R4G4B4 = 26,
+ D3DFMT_R3G3B2 = 27,
+ D3DFMT_A8 = 28,
+ D3DFMT_A8R3G3B2 = 29,
+ D3DFMT_X4R4G4B4 = 30,
+ D3DFMT_A2B10G10R10 = 31,
+ D3DFMT_G16R16 = 34,
+
+ D3DFMT_A8P8 = 40,
+ D3DFMT_P8 = 41,
+
+ D3DFMT_L8 = 50,
+ D3DFMT_A8L8 = 51,
+ D3DFMT_A4L4 = 52,
+
+ D3DFMT_V8U8 = 60,
+ D3DFMT_L6V5U5 = 61,
+ D3DFMT_X8L8V8U8 = 62,
+ D3DFMT_Q8W8V8U8 = 63,
+ D3DFMT_V16U16 = 64,
+ D3DFMT_W11V11U10 = 65,
+ D3DFMT_A2W10V10U10 = 67,
+
+ D3DFMT_UYVY = MAKEFOURCC('U', 'Y', 'V', 'Y'),
+ D3DFMT_YUY2 = MAKEFOURCC('Y', 'U', 'Y', '2'),
+ D3DFMT_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'),
+ D3DFMT_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'),
+ D3DFMT_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'),
+ D3DFMT_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'),
+ D3DFMT_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'),
+
+ D3DFMT_D16_LOCKABLE = 70,
+ D3DFMT_D32 = 71,
+ D3DFMT_D15S1 = 73,
+ D3DFMT_D24S8 = 75,
+ D3DFMT_D16 = 80,
+ D3DFMT_D24X8 = 77,
+ D3DFMT_D24X4S4 = 79,
+
+
+ D3DFMT_VERTEXDATA =100,
+ D3DFMT_INDEX16 =101,
+ D3DFMT_INDEX32 =102,
+
+ D3DFMT_FORCE_DWORD =0x7fffffff
+} D3DFORMAT;
+
+/* Direct3D8 Device types */
+typedef enum _D3DDEVTYPE
+{
+ D3DDEVTYPE_HAL = 1,
+ D3DDEVTYPE_REF = 2,
+ D3DDEVTYPE_SW = 3,
+
+ D3DDEVTYPE_FORCE_DWORD = 0x7fffffff
+} D3DDEVTYPE;
+
+typedef enum _D3DRESOURCETYPE {
+ D3DRTYPE_SURFACE = 1,
+ D3DRTYPE_VOLUME = 2,
+ D3DRTYPE_TEXTURE = 3,
+ D3DRTYPE_VOLUMETEXTURE = 4,
+ D3DRTYPE_CUBETEXTURE = 5,
+ D3DRTYPE_VERTEXBUFFER = 6,
+ D3DRTYPE_INDEXBUFFER = 7,
+
+
+ D3DRTYPE_FORCE_DWORD = 0x7fffffff
+} D3DRESOURCETYPE;
+
+
+
+#define MAX_DEVICE_IDENTIFIER_STRING 512
+typedef struct _D3DADAPTER_IDENTIFIER8
+{
+ char Driver[MAX_DEVICE_IDENTIFIER_STRING];
+ char Description[MAX_DEVICE_IDENTIFIER_STRING];
+
+#ifdef _WIN32
+ LARGE_INTEGER DriverVersion; /* Defined for 32 bit components */
+#else
+ DWORD DriverVersionLowPart; /* Defined for 16 bit driver components */
+ DWORD DriverVersionHighPart;
+#endif
+
+ DWORD VendorId;
+ DWORD DeviceId;
+ DWORD SubSysId;
+ DWORD Revision;
+
+ GUID DeviceIdentifier;
+
+ DWORD WHQLLevel;
+
+} D3DADAPTER_IDENTIFIER8;
+
+/* Display Modes */
+typedef struct _D3DDISPLAYMODE
+{
+ UINT Width;
+ UINT Height;
+ UINT RefreshRate;
+ D3DFORMAT Format;
+} D3DDISPLAYMODE;
+
+/* Multi-Sample buffer types */
+typedef enum _D3DMULTISAMPLE_TYPE
+{
+ D3DMULTISAMPLE_NONE = 0,
+ D3DMULTISAMPLE_2_SAMPLES = 2,
+ D3DMULTISAMPLE_3_SAMPLES = 3,
+ D3DMULTISAMPLE_4_SAMPLES = 4,
+ D3DMULTISAMPLE_5_SAMPLES = 5,
+ D3DMULTISAMPLE_6_SAMPLES = 6,
+ D3DMULTISAMPLE_7_SAMPLES = 7,
+ D3DMULTISAMPLE_8_SAMPLES = 8,
+ D3DMULTISAMPLE_9_SAMPLES = 9,
+ D3DMULTISAMPLE_10_SAMPLES = 10,
+ D3DMULTISAMPLE_11_SAMPLES = 11,
+ D3DMULTISAMPLE_12_SAMPLES = 12,
+ D3DMULTISAMPLE_13_SAMPLES = 13,
+ D3DMULTISAMPLE_14_SAMPLES = 14,
+ D3DMULTISAMPLE_15_SAMPLES = 15,
+ D3DMULTISAMPLE_16_SAMPLES = 16,
+
+ D3DMULTISAMPLE_FORCE_DWORD = 0x7fffffff
+} D3DMULTISAMPLE_TYPE;
+
+/* SwapEffects */
+typedef enum _D3DSWAPEFFECT
+{
+ D3DSWAPEFFECT_DISCARD = 1,
+ D3DSWAPEFFECT_FLIP = 2,
+ D3DSWAPEFFECT_COPY = 3,
+ D3DSWAPEFFECT_COPY_VSYNC = 4,
+
+ D3DSWAPEFFECT_FORCE_DWORD = 0x7fffffff
+} D3DSWAPEFFECT;
+
+/* Resize Optional Parameters */
+typedef struct _D3DPRESENT_PARAMETERS_
+{
+ UINT BackBufferWidth;
+ UINT BackBufferHeight;
+ D3DFORMAT BackBufferFormat;
+ UINT BackBufferCount;
+
+ D3DMULTISAMPLE_TYPE MultiSampleType;
+
+ D3DSWAPEFFECT SwapEffect;
+ HWND hDeviceWindow;
+ BOOL Windowed;
+ BOOL EnableAutoDepthStencil;
+ D3DFORMAT AutoDepthStencilFormat;
+ DWORD Flags;
+
+ /* Following elements must be zero for Windowed mode */
+ UINT FullScreen_RefreshRateInHz;
+ UINT FullScreen_PresentationInterval;
+
+} D3DPRESENT_PARAMETERS;
+#define D3DADAPTER_DEFAULT 0
+#define D3DENUM_NO_WHQL_LEVEL 0x00000002L
+
+#include "d3d8caps.h"
+
+DECLARE_INTERFACE_(IDirect3D8, IUnknown)
+{
+ /*** IUnknown methods ***/
+ STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
+ STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+ STDMETHOD_(ULONG,Release)(THIS) PURE;
+
+ /*** IDirect3D8 methods ***/
+ STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) PURE;
+ STDMETHOD_(UINT, GetAdapterCount)(THIS) PURE;
+ STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER8* pIdentifier) PURE;
+ STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter) PURE;
+ STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,UINT Mode,D3DDISPLAYMODE* pMode) PURE;
+ STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode) PURE;
+ STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter,D3DDEVTYPE CheckType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL Windowed) PURE;
+ STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) PURE;
+ STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType) PURE;
+ STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) PURE;
+ STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS8* pCaps) PURE;
+ STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
+ STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice8** ppReturnedDeviceInterface) PURE;
+};
+
+
+HMODULE gD3D8Lib = NULL;
+LPDIRECT3D8 gD3D8 = NULL;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static bool GetD3D8AdapterInfo2(GUID &theGUID, std::string &theDriver, std::string &theDescription)
+{
+ gD3D8Lib = LoadLibraryA("d3d8.dll");
+ if (gD3D8Lib==NULL)
+ return false;
+
+ typedef IDirect3D8*(WINAPI *Direct3DCreate8Func)(UINT SDKVersion);
+ Direct3DCreate8Func aDirect3DCreate8Func = (Direct3DCreate8Func)GetProcAddress(gD3D8Lib,"Direct3DCreate8");
+ if (aDirect3DCreate8Func==NULL)
+ return false;
+
+ gD3D8 = aDirect3DCreate8Func(D3D_SDK_VERSION);
+ if (gD3D8==NULL)
+ return false;
+
+ D3DADAPTER_IDENTIFIER8 anId;
+ ZeroMemory(&anId,sizeof(anId));
+ HRESULT aResult = gD3D8->GetAdapterIdentifier(D3DADAPTER_DEFAULT,D3DENUM_NO_WHQL_LEVEL,&anId);
+ if (!SUCCEEDED(aResult))
+ return false;
+
+ theGUID = anId.DeviceIdentifier;
+ theDriver = anId.Driver;
+ theDescription= anId.Description;
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool Sexy::GetD3D8AdapterInfo(GUID &theGUID, std::string &theDriver, std::string &theDescription)
+{
+ gD3D8 = NULL;
+ gD3D8Lib = NULL;
+
+ bool aResult = GetD3D8AdapterInfo2(theGUID,theDriver,theDescription);
+
+ if (gD3D8)
+ {
+ gD3D8->Release();
+ gD3D8 = NULL;
+ }
+
+ if (gD3D8Lib)
+ {
+ FreeLibrary(gD3D8Lib);
+ gD3D8Lib = NULL;
+ }
+
+ return aResult;
+}
diff --git a/osframework/source/SexyAppFramework/D3D8Helper.h b/osframework/source/SexyAppFramework/D3D8Helper.h
new file mode 100644
index 0000000..165f4cc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3D8Helper.h
@@ -0,0 +1,11 @@
+#ifndef __D3D8HELPER_H__
+#define __D3D8HELPER_H__
+
+#include <string>
+
+namespace Sexy
+{
+ bool GetD3D8AdapterInfo(GUID &theGUID, std::string &theDriver, std::string &theDescription);
+}
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/D3DInterface.cpp b/osframework/source/SexyAppFramework/D3DInterface.cpp
new file mode 100644
index 0000000..6a6214f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3DInterface.cpp
@@ -0,0 +1,2208 @@
+#include "D3DInterface.h"
+#include "DDInterface.h"
+#include "Graphics.h"
+#include "DirectXErrorString.h"
+#include "SexyMatrix.h"
+#include "SexyAppBase.h"
+#include "TriVertex.h"
+#include <assert.h>
+#include <algorithm>
+
+#pragma warning(disable:4244)
+
+using namespace Sexy;
+
+static int gMinTextureWidth;
+static int gMinTextureHeight;
+static int gMaxTextureWidth;
+static int gMaxTextureHeight;
+static int gMaxTextureAspectRatio;
+static DWORD gSupportedPixelFormats;
+static bool gTextureSizeMustBePow2;
+static const int MAX_TEXTURE_SIZE = 1024;
+static bool gLinearFilter = false;
+std::string D3DInterface::mErrorString;
+static const int gVertexType = D3DFVF_TLVERTEX;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void DisplayError(HRESULT theError, const char *theMsg)
+{
+ static bool hadError = false;
+ if (!hadError)
+ {
+ std::string aMsg;
+ std::string anError = GetDirectXErrorString(theError);
+ aMsg = theMsg;
+ aMsg += ": ";
+ aMsg += anError;
+
+ hadError = true;
+ int aResult = MessageBoxA(NULL,aMsg.c_str(),"Error",MB_ABORTRETRYIGNORE);
+ if (aResult==IDABORT)
+ exit(0);
+ else if (aResult==IDRETRY)
+ _asm int 3;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DInterface::CheckDXError(HRESULT theError, const char *theMsg)
+{
+ if(FAILED(theError))
+ {
+ std::string aMsg;
+ std::string anError = GetDirectXErrorString(theError);
+ aMsg = theMsg;
+ aMsg += ": ";
+ aMsg += anError;
+ mErrorString = aMsg;
+ gSexyAppBase->RegistryWriteString("Test3D\\RuntimeError",aMsg);
+
+ // DisplayError(theError,theMsg);
+ return true;
+ }
+ else
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DInterface::D3DInterface()
+{
+ mHWnd = NULL;
+ mWidth = 640;
+ mHeight = 480;
+ mDD = NULL;
+ mDDSDrawSurface = NULL;
+ mZBuffer = NULL;
+
+ mD3D = NULL;
+ mD3DDevice = NULL;
+ //mD3DViewport = NULL;
+ mSceneBegun = false;
+ mIsWindowed = true;
+
+ gMinTextureWidth = 64;
+ gMinTextureHeight = 64;
+ gMaxTextureWidth = 64;
+ gMaxTextureHeight = 64;
+ gMaxTextureAspectRatio = 1;
+
+/*
+ //Test Transform
+ SexyTransform2D aTrans;
+ aTrans.Translate(-320,-240);
+ aTrans.Rotate(45*3.14159f/180);
+// aTrans.Scale(1.3f,1.3f);
+ aTrans.Translate(320,240);
+ PushTransform(aTrans);
+*/
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DInterface::~D3DInterface()
+{
+ Cleanup();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::MakeDDPixelFormat(PixelFormat theFormatType, DDPIXELFORMAT* theFormat)
+{
+ ZeroMemory(theFormat,sizeof(DDPIXELFORMAT));
+ theFormat->dwSize = sizeof(DDPIXELFORMAT);
+
+ switch(theFormatType)
+ {
+ case PixelFormat_A8R8G8B8:
+ theFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_RGB;
+ theFormat->dwRGBBitCount = 32;
+ theFormat->dwRGBAlphaBitMask = 0xFF000000;
+ theFormat->dwRBitMask = 0x00FF0000;
+ theFormat->dwGBitMask = 0x0000FF00;
+ theFormat->dwBBitMask = 0x000000FF;
+ break;
+
+
+ case PixelFormat_A4R4G4B4:
+ theFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_RGB;
+ theFormat->dwRGBBitCount = 16;
+ theFormat->dwRGBAlphaBitMask = 0xF000;
+ theFormat->dwRBitMask = 0x0F00;
+ theFormat->dwGBitMask = 0x00F0;
+ theFormat->dwBBitMask = 0x000F;
+ break;
+
+ case PixelFormat_R5G6B5:
+ theFormat->dwFlags = DDPF_RGB;
+ theFormat->dwRGBBitCount = 16;
+ theFormat->dwRBitMask = 0xF800;
+ theFormat->dwGBitMask = 0x07E0;
+ theFormat->dwBBitMask = 0x001F;
+ break;
+
+ case PixelFormat_Palette8:
+ theFormat->dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
+ theFormat->dwRGBBitCount = 8;
+ break;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+PixelFormat D3DInterface::GetDDPixelFormat(LPDDPIXELFORMAT theFormat)
+{
+ if (theFormat->dwFlags == (DDPF_ALPHAPIXELS | DDPF_RGB) &&
+ theFormat->dwRGBBitCount == 32 &&
+ theFormat->dwRGBAlphaBitMask == 0xFF000000 &&
+ theFormat->dwRBitMask == 0x00FF0000 &&
+ theFormat->dwGBitMask == 0x0000FF00 &&
+ theFormat->dwBBitMask == 0x000000FF)
+ {
+ return PixelFormat_A8R8G8B8;
+ }
+
+ if (theFormat->dwFlags == (DDPF_ALPHAPIXELS | DDPF_RGB) &&
+ theFormat->dwRGBBitCount == 16 &&
+ theFormat->dwRGBAlphaBitMask == 0xF000 &&
+ theFormat->dwRBitMask == 0x0F00 &&
+ theFormat->dwGBitMask == 0x00F0 &&
+ theFormat->dwBBitMask == 0x000F)
+ {
+ return PixelFormat_A4R4G4B4;
+ }
+
+ if (theFormat->dwFlags == DDPF_RGB &&
+ theFormat->dwRGBBitCount == 16 &&
+ theFormat->dwRGBAlphaBitMask == 0x0000 &&
+ theFormat->dwRBitMask == 0xF800 &&
+ theFormat->dwGBitMask == 0x07E0 &&
+ theFormat->dwBBitMask == 0x001F)
+ {
+ return PixelFormat_R5G6B5;
+ }
+
+ if (theFormat->dwFlags == (DDPF_RGB | DDPF_PALETTEINDEXED8) &&
+ theFormat->dwRGBBitCount == 8)
+ {
+ return PixelFormat_Palette8;
+ }
+
+ return PixelFormat_Unknown;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+HRESULT CALLBACK D3DInterface::PixelFormatsCallback(LPDDPIXELFORMAT theFormat, LPVOID lpContext)
+{
+ gSupportedPixelFormats |= D3DInterface::GetDDPixelFormat(theFormat);
+
+ return D3DENUMRET_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::UpdateViewport()
+{
+ HRESULT hr;
+ RECT aRect;
+ GetClientRect(mHWnd, &aRect);
+
+ POINT aTopLeft = {aRect.left, aRect.top};
+ POINT aBotRight = {aRect.right, aRect.bottom};
+ ::ClientToScreen(mHWnd, &aTopLeft);
+ ::ClientToScreen(mHWnd, &aBotRight);
+
+ RECT aScreenRect = {aTopLeft.x, aTopLeft.y, aBotRight.x, aBotRight.y};
+
+ D3DVIEWPORT7 &aD3DViewport = mD3DViewport;
+ aD3DViewport.dwX = 0;
+ aD3DViewport.dwY = 0;
+ aD3DViewport.dwWidth = aScreenRect.right - aScreenRect.left;
+ aD3DViewport.dwHeight = aScreenRect.bottom - aScreenRect.top;
+ aD3DViewport.dvMinZ = 0; //-2048.0f;
+ aD3DViewport.dvMaxZ = 1; //2048.0f;
+
+ hr = mD3DDevice->SetViewport(&mD3DViewport);
+}
+
+
+//-----------------------------------------------------------------------------
+// Name: EnumZBufferCallback()
+// Desc: Enumeration function to report valid pixel formats for z-buffers.
+//-----------------------------------------------------------------------------
+static HRESULT WINAPI EnumZBufferCallback( DDPIXELFORMAT* pddpf, VOID* pddpfDesired )
+{
+ if( pddpf->dwFlags == DDPF_ZBUFFER )
+ {
+ memcpy( pddpfDesired, pddpf, sizeof(DDPIXELFORMAT) );
+ return D3DENUMRET_CANCEL;
+ }
+
+ return D3DENUMRET_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DInterface::InitD3D()
+{
+ if(CheckDXError(mDD->QueryInterface(IID_IDirect3D7, (LPVOID*) &mD3D),"QueryInterface IID_IDirect3D7"))
+ return false;
+
+ if(CheckDXError(mD3D->CreateDevice(IID_IDirect3DHALDevice, mDDSDrawSurface, &mD3DDevice),"CreateDevice IID_IDirect3DHALDevice"))
+ return false;
+
+ D3DDEVICEDESC7 aCaps;
+ ZeroMemory(&aCaps,sizeof(aCaps));
+ if(CheckDXError(mD3DDevice->GetCaps(&aCaps)))
+ return false;
+
+ gTextureSizeMustBePow2 = aCaps.dpcTriCaps.dwTextureCaps&D3DPTEXTURECAPS_NONPOW2CONDITIONAL?false:true;
+ gMinTextureWidth = aCaps.dwMinTextureWidth;
+ gMinTextureHeight = aCaps.dwMinTextureHeight;
+ gMaxTextureWidth = aCaps.dwMaxTextureWidth;
+ gMaxTextureHeight = aCaps.dwMaxTextureHeight;
+ gMaxTextureAspectRatio = aCaps.dwMaxTextureAspectRatio;
+ gLinearFilter = false;
+
+ if (gMaxTextureWidth==0) // the card is not filling in these values so default them to something that will work
+ {
+ gMaxTextureWidth = 64;
+ gMaxTextureHeight = 64;
+ gMinTextureWidth = 64;
+ gMinTextureHeight = 64;
+ gMaxTextureAspectRatio = 1;
+ }
+
+ if (gMaxTextureWidth > MAX_TEXTURE_SIZE)
+ gMaxTextureWidth = MAX_TEXTURE_SIZE;
+ if (gMaxTextureHeight > MAX_TEXTURE_SIZE)
+ gMaxTextureHeight = MAX_TEXTURE_SIZE;
+
+ if (gMinTextureWidth < 1)
+ gMinTextureWidth = 1;
+ if (gMinTextureHeight < 1)
+ gMinTextureWidth = 1;
+
+ if (gMaxTextureAspectRatio==0)
+ gMaxTextureAspectRatio = 65536;
+
+ gSupportedPixelFormats = 0;
+ mD3DDevice->EnumTextureFormats(PixelFormatsCallback,NULL);
+/* if (!(gSupportedPixelFormats & PixelFormat_A8R8G8B8))
+ {
+ mErrorString = "A8R8G8B8 texture format not supported.";
+ return false;
+ }*/
+
+ if (!(aCaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) // need alpha in palettes
+ gSupportedPixelFormats &= ~PixelFormat_Palette8;
+
+ UpdateViewport();
+
+ // Create ZBuffer
+ DDPIXELFORMAT ddpfZBuffer;
+ mD3D->EnumZBufferFormats( IID_IDirect3DHALDevice, EnumZBufferCallback, (VOID*)&ddpfZBuffer );
+
+ DDSURFACEDESC2 ddsd;
+ ZeroMemory( &ddsd, sizeof(DDSURFACEDESC2) );
+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
+ ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
+ ddsd.dwWidth = mD3DViewport.dwWidth;
+ ddsd.dwHeight = mD3DViewport.dwHeight;
+ memcpy( &ddsd.ddpfPixelFormat, &ddpfZBuffer, sizeof(DDPIXELFORMAT) );
+
+ /*
+ // Create z-buffer
+ if( CheckDXError(mDD->CreateSurface( &ddsd, &mZBuffer, NULL ) ) )
+ return false;
+
+ // Attach the z-buffer to the back buffer.
+ if( CheckDXError( mDDSDrawSurface->AddAttachedSurface( mZBuffer ) ) )
+ return false;*/
+
+ mD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L);
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DInterface::InitFromDDInterface(DDInterface *theInterface)
+{
+ mErrorString.erase();
+
+ mDD = theInterface->mDD7;
+ mHWnd = theInterface->mHWnd;
+ mWidth = theInterface->mWidth;
+ mHeight = theInterface->mHeight;
+
+ if (CheckDXError(theInterface->mDrawSurface->QueryInterface(IID_IDirectDrawSurface7,(LPVOID*)&mDDSDrawSurface), "Query DrawSurface"))
+ return false;
+
+
+ mIsWindowed = theInterface->mIsWindowed;
+ return InitD3D();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool gD3DInterfacePreDrawError = false;
+bool D3DInterface::PreDraw()
+{
+ if (gSexyAppBase->mPhysMinimized)
+ return false;
+
+ if (!mSceneBegun)
+ {
+ HRESULT hr;
+
+
+ if (!SUCCEEDED(mD3DDevice->SetRenderTarget(mDDSDrawSurface, 0))) // this happens when there's been a mode switch (this caused the nvidia screensaver bluescreen)
+ {
+ gD3DInterfacePreDrawError = true;
+ return false;
+ }
+ else
+ gD3DInterfacePreDrawError = false;
+
+// mD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L);
+
+ hr = mD3DDevice->BeginScene();
+
+ // alphablend states
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING , FALSE);
+
+ // filter states
+ mD3DDevice->SetTextureStageState(0,D3DTSS_MINFILTER, D3DTFG_POINT);
+ mD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER, D3DTFG_POINT);
+ mD3DDevice->SetTextureStageState(0,D3DTSS_MIPFILTER, D3DTFG_POINT);
+// mD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_CURRENT );
+// mD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2, D3DTA_CURRENT );
+// mD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE );
+// mD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
+// mD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP , D3DTOP_MODULATE );
+ mD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_MODULATE );
+ mD3DDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
+ hr = mD3DDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
+
+ // Setup non-texture render states
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, FALSE);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, FALSE);
+ hr = mD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ mSceneBegun = true;
+ gLinearFilter = false;
+ }
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static LPDIRECTDRAWSURFACE7 CreateTextureSurface(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAW7 theDraw, int theWidth, int theHeight, PixelFormat theFormat)
+{
+ if (D3DInterface::CheckDXError(theDevice->SetTexture(0, NULL),"SetTexture NULL"))
+ return NULL;
+
+ DDSURFACEDESC2 aDesc;
+ LPDIRECTDRAWSURFACE7 aSurface;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+
+ aDesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
+// aDesc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
+ aDesc.ddsCaps.dwCaps2 = DDSCAPS2_D3DTEXTUREMANAGE;
+
+ aDesc.dwWidth = theWidth;
+ aDesc.dwHeight = theHeight;
+
+ aDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+ D3DInterface::MakeDDPixelFormat(theFormat, &aDesc.ddpfPixelFormat);
+// D3DXMakeDDPixelFormat(theFormat, &aDesc.ddpfPixelFormat);
+
+ HRESULT hr = theDraw->CreateSurface(&aDesc, &aSurface, NULL);
+
+ if (FAILED(hr))
+ {
+ std::string anError = GetDirectXErrorString(hr);
+ return NULL;
+ }
+
+ return aSurface;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyImageToTexture8888(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight, bool rightPad)
+{
+
+ if (theImage->mColorTable == NULL)
+ {
+ DWORD *srcRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+ char *dstRow = (char*)theDest;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ DWORD *src = srcRow;
+ DWORD *dst = (DWORD*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ {
+ *dst++ = *src++;
+ }
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+ }
+ else // palette
+ {
+ uchar *srcRow = (uchar*)theImage->mColorIndices + offy * theImage->GetWidth() + offx;
+ uchar *dstRow = (uchar*)theDest;
+ DWORD *palette = theImage->mColorTable;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ uchar *src = srcRow;
+ DWORD *dst = (DWORD*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ *dst++ = palette[*src++];
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyTexture8888ToImage(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight)
+{
+ char *srcRow = (char*)theDest;
+ DWORD *dstRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ DWORD *src = (DWORD*)srcRow;
+ DWORD *dst = dstRow;
+
+ for(int x=0; x<theWidth; x++)
+ *dst++ = *src++;
+
+ dstRow += theImage->GetWidth();
+ srcRow += theDestPitch;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyImageToTexture4444(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight, bool rightPad)
+{
+ if (theImage->mColorTable == NULL)
+ {
+ DWORD *srcRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+ char *dstRow = (char*)theDest;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ DWORD *src = srcRow;
+ ushort *dst = (ushort*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ {
+ DWORD aPixel = *src++;
+ *dst++ = ((aPixel>>16)&0xF000) | ((aPixel>>12)&0x0F00) | ((aPixel>>8)&0x00F0) | ((aPixel>>4)&0x000F);
+ }
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+ }
+ else // palette
+ {
+ uchar *srcRow = (uchar*)theImage->mColorIndices + offy * theImage->GetWidth() + offx;
+ uchar *dstRow = (uchar*)theDest;
+ DWORD *palette = theImage->mColorTable;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ uchar *src = srcRow;
+ ushort *dst = (ushort*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ {
+ DWORD aPixel = palette[*src++];
+ *dst++ = ((aPixel>>16)&0xF000) | ((aPixel>>12)&0x0F00) | ((aPixel>>8)&0x00F0) | ((aPixel>>4)&0x000F);
+ }
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyTexture4444ToImage(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight)
+{
+ char *srcRow = (char*)theDest;
+ DWORD *dstRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ ushort *src = (ushort*)srcRow;
+ DWORD *dst = dstRow;
+
+ for(int x=0; x<theWidth; x++)
+ {
+ ushort aPixel = *src++;
+ *dst++ = 0xFF000000 | ((aPixel & 0xF000) << 16) | ((aPixel & 0x0F00) << 12) | ((aPixel & 0x00F0) << 8) | ((aPixel & 0x000F) << 4);
+ }
+
+ dstRow += theImage->GetWidth();
+ srcRow += theDestPitch;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyImageToTexture565(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight, bool rightPad)
+{
+ if (theImage->mColorTable == NULL)
+ {
+ DWORD *srcRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+ char *dstRow = (char*)theDest;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ DWORD *src = srcRow;
+ ushort *dst = (ushort*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ {
+ DWORD aPixel = *src++;
+ *dst++ = ((aPixel>>8)&0xF800) | ((aPixel>>5)&0x07E0) | ((aPixel>>3)&0x001F);
+ }
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+ }
+ else // palette
+ {
+ uchar *srcRow = (uchar*)theImage->mColorIndices + offy * theImage->GetWidth() + offx;
+ uchar *dstRow = (uchar*)theDest;
+ DWORD *palette = theImage->mColorTable;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ uchar *src = srcRow;
+ ushort *dst = (ushort*)dstRow;
+ for(int x=0; x<theWidth; x++)
+ {
+ DWORD aPixel = palette[*src++];
+ *dst++ = ((aPixel>>8)&0xF800) | ((aPixel>>5)&0x07E0) | ((aPixel>>3)&0x001F);
+ }
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyTexture565ToImage(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight)
+{
+ char *srcRow = (char*)theDest;
+ DWORD *dstRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ ushort *src = (ushort*)srcRow;
+ DWORD *dst = dstRow;
+
+ for(int x=0; x<theWidth; x++)
+ {
+ ushort aPixel = *src++;
+ *dst++ = 0xFF000000 | ((aPixel & 0xF800) << 8) | ((aPixel & 0x07E0) << 5) | ((aPixel & 0x001F) << 3);
+ }
+
+ dstRow += theImage->GetWidth();
+ srcRow += theDestPitch;
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyImageToTexturePalette8(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight, bool rightPad)
+{
+ uchar *srcRow = (uchar*)theImage->mColorIndices + offy * theImage->GetWidth() + offx;
+ uchar *dstRow = (uchar*)theDest;
+
+ for(int y=0; y<theHeight; y++)
+ {
+ uchar *src = srcRow;
+ uchar *dst = dstRow;
+ for(int x=0; x<theWidth; x++)
+ *dst++ = *src++;
+
+ if (rightPad)
+ *dst = *(dst-1);
+
+ srcRow += theImage->GetWidth();
+ dstRow += theDestPitch;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyTexturePalette8ToImage(void *theDest, DWORD theDestPitch, MemoryImage *theImage, int offx, int offy, int theWidth, int theHeight, LPDIRECTDRAWPALETTE thePalette)
+{
+ char *srcRow = (char*)theDest;
+ DWORD *dstRow = theImage->GetBits() + offy * theImage->GetWidth() + offx;
+
+ PALETTEENTRY aPaletteEntries[256];
+ thePalette->GetEntries(0, 0, 256, aPaletteEntries);
+
+ for(int y=0; y<theHeight; y++)
+ {
+ uchar *src = (uchar*) srcRow;
+ DWORD *dst = dstRow;
+
+ for(int x=0; x<theWidth; x++)
+ {
+ DWORD aPixel = *((DWORD*)(aPaletteEntries+*src++));
+ *dst++ = (aPixel&0xFF00FF00) | ((aPixel>>16)&0xFF) | ((aPixel<<16)&0xFF0000);
+ }
+
+ dstRow += theImage->GetWidth();
+ srcRow += theDestPitch;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CopyImageToTexture(LPDIRECTDRAWSURFACE7 theTexture, MemoryImage *theImage, int offx, int offy, int texWidth, int texHeight, PixelFormat theFormat)
+{
+ if (theTexture==NULL)
+ return;
+
+ DDSURFACEDESC2 aDesc;
+ aDesc.dwSize = sizeof(aDesc);
+ if (D3DInterface::CheckDXError(theTexture->Lock(NULL,&aDesc,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_WRITEONLY,NULL),"Lock Texture"))
+ return;
+
+ int aWidth = min(texWidth,(theImage->GetWidth()-offx));
+ int aHeight = min(texHeight,(theImage->GetHeight()-offy));
+
+ bool rightPad = aWidth<texWidth;
+ bool bottomPad = aHeight<texHeight;
+// if(aWidth < texWidth || aHeight < texHeight)
+// memset(aDesc.lpSurface, 0, aDesc.lPitch*aDesc.dwHeight);
+
+ if(aWidth>0 && aHeight>0)
+ {
+ switch (theFormat)
+ {
+ case PixelFormat_A8R8G8B8: CopyImageToTexture8888(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight, rightPad); break;
+ case PixelFormat_A4R4G4B4: CopyImageToTexture4444(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight, rightPad); break;
+ case PixelFormat_R5G6B5: CopyImageToTexture565(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight, rightPad); break;
+ case PixelFormat_Palette8: CopyImageToTexturePalette8(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight, rightPad); break;
+ }
+
+ if (bottomPad)
+ {
+ uchar *dstrow = ((uchar*)aDesc.lpSurface)+aDesc.lPitch*aHeight;
+ memcpy(dstrow,dstrow-aDesc.lPitch,aDesc.lPitch);
+ }
+ }
+
+ D3DInterface::CheckDXError(theTexture->Unlock(NULL),"Texture Unlock");
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static int GetClosestPowerOf2Above(int theNum)
+{
+ int aPower2 = 1;
+ while (aPower2 < theNum)
+ aPower2<<=1;
+
+ return aPower2;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static bool IsPowerOf2(int theNum)
+{
+ int aNumBits = 0;
+ while (theNum>0)
+ {
+ aNumBits += theNum&1;
+ theNum >>= 1;
+ }
+
+ return aNumBits==1;
+}
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void GetBestTextureDimensions(int &theWidth, int &theHeight, bool isEdge, bool usePow2, DWORD theImageFlags)
+{
+// theImageFlags = D3DImageFlag_MinimizeNumSubdivisions;
+ if (theImageFlags & D3DImageFlag_Use64By64Subdivisions)
+ {
+ theWidth = theHeight = 64;
+ return;
+ }
+
+ static int aGoodTextureSize[MAX_TEXTURE_SIZE];
+ static bool haveInited = false;
+ if (!haveInited)
+ {
+ haveInited = true;
+ int i;
+ int aPow2 = 1;
+ for (i=0; i<MAX_TEXTURE_SIZE; i++)
+ {
+ if (i > aPow2)
+ aPow2 <<= 1;
+
+ int aGoodValue = aPow2;
+ if ((aGoodValue - i ) > 64)
+ {
+ aGoodValue >>= 1;
+ while (true)
+ {
+ int aLeftOver = i % aGoodValue;
+ if (aLeftOver<64 || IsPowerOf2(aLeftOver))
+ break;
+
+ aGoodValue >>= 1;
+ }
+ }
+ aGoodTextureSize[i] = aGoodValue;
+ }
+ }
+
+ int aWidth = theWidth;
+ int aHeight = theHeight;
+
+ if (usePow2)
+ {
+ if (isEdge || (theImageFlags & D3DImageFlag_MinimizeNumSubdivisions))
+ {
+ aWidth = aWidth >= gMaxTextureWidth ? gMaxTextureWidth : GetClosestPowerOf2Above(aWidth);
+ aHeight = aHeight >= gMaxTextureHeight ? gMaxTextureHeight : GetClosestPowerOf2Above(aHeight);
+ }
+ else
+ {
+ aWidth = aWidth >= gMaxTextureWidth ? gMaxTextureWidth : aGoodTextureSize[aWidth];
+ aHeight = aHeight >= gMaxTextureHeight ? gMaxTextureHeight : aGoodTextureSize[aHeight];
+ }
+ }
+
+ if (aWidth < gMinTextureWidth)
+ aWidth = gMinTextureWidth;
+
+ if (aHeight < gMinTextureHeight)
+ aHeight = gMinTextureHeight;
+
+ if (aWidth > aHeight)
+ {
+ while (aWidth > gMaxTextureAspectRatio*aHeight)
+ aHeight <<= 1;
+ }
+ else if (aHeight > aWidth)
+ {
+ while (aHeight > gMaxTextureAspectRatio*aWidth)
+ aWidth <<= 1;
+ }
+
+ theWidth = aWidth;
+ theHeight = aHeight;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+TextureData::TextureData()
+{
+ mWidth = 0;
+ mHeight = 0;
+ mTexVecWidth = 0;
+ mTexVecHeight = 0;
+ mBitsChangedCount = 0;
+ mTexMemSize = 0;
+ mTexPieceWidth = 64;
+ mTexPieceHeight = 64;
+
+ mPalette = NULL;
+ mPixelFormat = PixelFormat_Unknown;
+ mImageFlags = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+TextureData::~TextureData()
+{
+ ReleaseTextures();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::ReleaseTextures()
+{
+ for(int i=0; i<(int)mTextures.size(); i++)
+ {
+ LPDIRECTDRAWSURFACE7 aSurface = mTextures[i].mTexture;
+ if (aSurface!=NULL)
+ aSurface->Release();
+ }
+
+ mTextures.clear();
+
+ mTexMemSize = 0;
+
+ if (mPalette!=NULL)
+ {
+ mPalette->Release();
+ mPalette = NULL;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::CreateTextureDimensions(MemoryImage *theImage)
+{
+ int aWidth = theImage->GetWidth();
+ int aHeight = theImage->GetHeight();
+ int i;
+/**/
+ // Calculate inner piece sizes
+ mTexPieceWidth = aWidth;
+ mTexPieceHeight = aHeight;
+ bool usePow2 = true; //gTextureSizeMustBePow2 || mPixelFormat==PixelFormat_Palette8;
+ GetBestTextureDimensions(mTexPieceWidth, mTexPieceHeight,false,usePow2,mImageFlags);
+
+ // Calculate right boundary piece sizes
+ int aRightWidth = aWidth%mTexPieceWidth;
+ int aRightHeight = mTexPieceHeight;
+ if (aRightWidth > 0)
+ GetBestTextureDimensions(aRightWidth, aRightHeight,true,usePow2,mImageFlags);
+ else
+ aRightWidth = mTexPieceWidth;
+
+ // Calculate bottom boundary piece sizes
+ int aBottomWidth = mTexPieceWidth;
+ int aBottomHeight = aHeight%mTexPieceHeight;
+ if (aBottomHeight > 0)
+ GetBestTextureDimensions(aBottomWidth, aBottomHeight,true,usePow2,mImageFlags);
+ else
+ aBottomHeight = mTexPieceHeight;
+
+ // Calculate corner piece size
+ int aCornerWidth = aRightWidth;
+ int aCornerHeight = aBottomHeight;
+ GetBestTextureDimensions(aCornerWidth, aCornerHeight,true,usePow2,mImageFlags);
+/**/
+
+// mTexPieceWidth = 64;
+// mTexPieceHeight = 64;
+
+
+ // Allocate texture array
+ mTexVecWidth = (aWidth + mTexPieceWidth - 1)/mTexPieceWidth;
+ mTexVecHeight = (aHeight + mTexPieceHeight - 1)/mTexPieceHeight;
+ mTextures.resize(mTexVecWidth*mTexVecHeight);
+
+ // Assign inner pieces
+ for(i=0; i<(int)mTextures.size(); i++)
+ {
+ TextureDataPiece &aPiece = mTextures[i];
+ aPiece.mTexture = NULL;
+ aPiece.mWidth = mTexPieceWidth;
+ aPiece.mHeight = mTexPieceHeight;
+ }
+
+ // Assign right pieces
+/**/
+ for(i=mTexVecWidth-1; i<(int)mTextures.size(); i+=mTexVecWidth)
+ {
+ TextureDataPiece &aPiece = mTextures[i];
+ aPiece.mWidth = aRightWidth;
+ aPiece.mHeight = aRightHeight;
+ }
+
+ // Assign bottom pieces
+ for(i=mTexVecWidth*(mTexVecHeight-1); i<(int)mTextures.size(); i++)
+ {
+ TextureDataPiece &aPiece = mTextures[i];
+ aPiece.mWidth = aBottomWidth;
+ aPiece.mHeight = aBottomHeight;
+ }
+
+ // Assign corner piece
+ mTextures.back().mWidth = aCornerWidth;
+ mTextures.back().mHeight = aCornerHeight;
+/**/
+
+ mMaxTotalU = aWidth/(float)mTexPieceWidth;
+ mMaxTotalV = aHeight/(float)mTexPieceHeight;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::CreateTextures(MemoryImage *theImage, LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAW7 theDraw)
+{
+ theImage->DeleteSWBuffers(); // don't need these buffers for 3d drawing
+
+ // Choose appropriate pixel format
+ PixelFormat aFormat = PixelFormat_A8R8G8B8;
+ //theImage->mD3DFlags = D3DImageFlag_UseA4R4G4B4;
+
+ theImage->CommitBits();
+ if (!theImage->mHasAlpha && !theImage->mHasTrans && (gSupportedPixelFormats & PixelFormat_R5G6B5))
+ {
+ if (!(theImage->mD3DFlags & D3DImageFlag_UseA8R8G8B8))
+ aFormat = PixelFormat_R5G6B5;
+ }
+
+ LPDIRECTDRAWPALETTE aDDPalette = NULL;
+ if (theImage->mColorIndices != NULL && (gSupportedPixelFormats & PixelFormat_Palette8))
+ {
+ PALETTEENTRY aPalette[256];
+ for (int i=0; i<256; i++)
+ {
+ DWORD aPixel = theImage->mColorTable[i];
+ *(DWORD*)(aPalette+i) = (aPixel&0xFF00FF00) | ((aPixel>>16)&0xFF) | ((aPixel<<16)&0xFF0000);
+ }
+ HRESULT aResult = theDraw->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALPHA | DDPCAPS_ALLOW256,aPalette, &aDDPalette, NULL);
+ if (SUCCEEDED(aResult))
+ aFormat = PixelFormat_Palette8;
+ else
+ {
+ std::string anError = GetDirectXErrorString(aResult);
+ gSupportedPixelFormats &= ~PixelFormat_Palette8;
+ }
+ }
+
+ if ((theImage->mD3DFlags & D3DImageFlag_UseA4R4G4B4) && aFormat==PixelFormat_A8R8G8B8 && (gSupportedPixelFormats & PixelFormat_A4R4G4B4))
+ aFormat = PixelFormat_A4R4G4B4;
+
+ if (aFormat==PixelFormat_A8R8G8B8 && !(gSupportedPixelFormats & PixelFormat_A8R8G8B8))
+ aFormat = PixelFormat_A4R4G4B4;
+
+
+ // Release texture if image size has changed
+ bool createTextures = false;
+ if (mWidth!=theImage->mWidth || mHeight!=theImage->mHeight || aFormat!=mPixelFormat || theImage->mD3DFlags!=mImageFlags)
+ {
+ ReleaseTextures();
+
+ mPixelFormat = aFormat;
+ mImageFlags = theImage->mD3DFlags;
+ CreateTextureDimensions(theImage);
+ createTextures = true;
+ }
+
+ mPalette = aDDPalette;
+
+ int i,x,y;
+
+ int aHeight = theImage->GetHeight();
+ int aWidth = theImage->GetWidth();
+
+ if (mPalette!=NULL)
+ mTexMemSize += 256*4;
+
+ int aFormatSize = 4;
+ if (aFormat==PixelFormat_Palette8)
+ aFormatSize = 1;
+ else if (aFormat==PixelFormat_R5G6B5)
+ aFormatSize = 2;
+ else if (aFormat==PixelFormat_A4R4G4B4)
+ aFormatSize = 2;
+
+ i=0;
+ for(y=0; y<aHeight; y+=mTexPieceHeight)
+ {
+ for(x=0; x<aWidth; x+=mTexPieceWidth, i++)
+ {
+ TextureDataPiece &aPiece = mTextures[i];
+ if (createTextures)
+ {
+ aPiece.mTexture = CreateTextureSurface(theDevice, theDraw, aPiece.mWidth, aPiece.mHeight, aFormat);
+ if (aPiece.mTexture==NULL) // create texture failure
+ {
+ mPixelFormat = PixelFormat_Unknown;
+ return;
+ }
+
+ if (mPalette!=NULL)
+ aPiece.mTexture->SetPalette(mPalette);
+
+ mTexMemSize += aPiece.mWidth*aPiece.mHeight*aFormatSize;
+ }
+
+ CopyImageToTexture(aPiece.mTexture,theImage,x,y,aPiece.mWidth,aPiece.mHeight,aFormat);
+ }
+ }
+
+ mWidth = theImage->mWidth;
+ mHeight = theImage->mHeight;
+ mBitsChangedCount = theImage->mBitsChangedCount;
+ mPixelFormat = aFormat;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::CheckCreateTextures(MemoryImage *theImage, LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAW7 theDraw)
+{
+ if(mPixelFormat==PixelFormat_Unknown || theImage->mWidth != mWidth || theImage->mHeight != mHeight || theImage->mBitsChangedCount != mBitsChangedCount || theImage->mD3DFlags != mImageFlags)
+ CreateTextures(theImage, theDevice, theDraw);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+LPDIRECTDRAWSURFACE7 TextureData::GetTexture(int x, int y, int &width, int &height, float &u1, float &v1, float &u2, float &v2)
+{
+ int tx = x/mTexPieceWidth;
+ int ty = y/mTexPieceHeight;
+
+ TextureDataPiece &aPiece = mTextures[ty*mTexVecWidth + tx];
+
+ int left = x%mTexPieceWidth;
+ int top = y%mTexPieceHeight;
+ int right = left+width;
+ int bottom = top+height;
+
+ if(right > aPiece.mWidth)
+ right = aPiece.mWidth;
+
+ if(bottom > aPiece.mHeight)
+ bottom = aPiece.mHeight;
+
+ width = right-left;
+ height = bottom-top;
+
+ u1 = (float)left/aPiece.mWidth;
+ v1 = (float)top/aPiece.mHeight;
+ u2 = (float)right/aPiece.mWidth;
+ v2 = (float)bottom/aPiece.mHeight;
+
+ return aPiece.mTexture;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+LPDIRECTDRAWSURFACE7 TextureData::GetTextureF(float x, float y, float &width, float &height, float &u1, float &v1, float &u2, float &v2)
+{
+ int tx = x/mTexPieceWidth;
+ int ty = y/mTexPieceHeight;
+
+ TextureDataPiece &aPiece = mTextures[ty*mTexVecWidth + tx];
+
+ float left = x - tx*mTexPieceWidth;
+ float top = y - ty*mTexPieceHeight;
+ float right = left+width;
+ float bottom = top+height;
+
+ if(right > aPiece.mWidth)
+ right = aPiece.mWidth;
+
+ if(bottom > aPiece.mHeight)
+ bottom = aPiece.mHeight;
+
+ width = right-left;
+ height = bottom-top;
+
+ u1 = (float)left/aPiece.mWidth;
+ v1 = (float)top/aPiece.mHeight;
+ u2 = (float)right/aPiece.mWidth;
+ v2 = (float)bottom/aPiece.mHeight;
+
+ return aPiece.mTexture;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void SetLinearFilter(LPDIRECT3DDEVICE7 theDevice, bool linear)
+{
+ if (gLinearFilter != linear)
+ {
+ D3DTEXTUREMAGFILTER aFilter = linear ? D3DTFG_LINEAR : D3DTFG_POINT;
+
+ const char *aDebugContext = linear ? "SetTextureStageState LINEAR" : "SetTextureStageState Point";
+
+ D3DInterface::CheckDXError(theDevice->SetTextureStageState(0,D3DTSS_MINFILTER, aFilter),aDebugContext);
+ D3DInterface::CheckDXError(theDevice->SetTextureStageState(0,D3DTSS_MAGFILTER, aFilter),aDebugContext);
+ D3DInterface::CheckDXError(theDevice->SetTextureStageState(0,D3DTSS_MIPFILTER, aFilter),aDebugContext);
+
+ gLinearFilter = linear;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::Blt(LPDIRECT3DDEVICE7 theDevice, float theX, float theY, const Rect& theSrcRect, const Color& theColor)
+{
+ int srcLeft = theSrcRect.mX;
+ int srcTop = theSrcRect.mY;
+ int srcRight = srcLeft + theSrcRect.mWidth;
+ int srcBottom = srcTop + theSrcRect.mHeight;
+ int srcX, srcY;
+ float dstX, dstY;
+ int aWidth,aHeight;
+ float u1,v1,u2,v2;
+
+ srcY = srcTop;
+ dstY = theY;
+
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+
+ if ((srcLeft >= srcRight) || (srcTop >= srcBottom))
+ return;
+
+ while(srcY < srcBottom)
+ {
+ srcX = srcLeft;
+ dstX = theX;
+ while(srcX < srcRight)
+ {
+ aWidth = srcRight-srcX;
+ aHeight = srcBottom-srcY;
+ LPDIRECTDRAWSURFACE7 aTexture = GetTexture(srcX, srcY, aWidth, aHeight, u1, v1, u2, v2);
+
+ float x = dstX - 0.5f;
+ float y = dstY - 0.5f;
+
+ D3DTLVERTEX aVertex[4] =
+ {
+ { x, y, 0, 1, aColor, 0, u1, v1 },
+ { x, y+aHeight, 0, 1, aColor, 0, u1, v2 },
+ { x+aWidth, y, 0, 1, aColor, 0, u2, v1 },
+ { x+aWidth, y+aHeight, 0, 1, aColor, 0, u2, v2 }
+ };
+
+
+ D3DInterface::CheckDXError(theDevice->SetTexture(0, aTexture),"SetTexture gTexture");
+ D3DInterface::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, gVertexType, aVertex, 4, 0),"DrawPrimitive (Tri) 1");
+
+ srcX += aWidth;
+ dstX += aWidth;
+ }
+
+ srcY += aHeight;
+ dstY += aHeight;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+//typedef std::vector<D3DTLVERTEX> VertexList;
+struct VertexList
+{
+ enum { MAX_STACK_VERTS = 100 };
+ D3DTLVERTEX mStackVerts[MAX_STACK_VERTS];
+ D3DTLVERTEX *mVerts;
+ int mSize;
+ int mCapacity;
+
+ typedef int size_type;
+
+ VertexList() : mSize(0), mCapacity(MAX_STACK_VERTS), mVerts(mStackVerts) { }
+ VertexList(const VertexList &theList) : mSize(theList.mSize), mCapacity(MAX_STACK_VERTS), mVerts(mStackVerts)
+ {
+ reserve(mSize);
+ memcpy(mVerts,theList.mVerts,mSize*sizeof(mVerts[0]));
+ }
+
+ ~VertexList()
+ {
+ if (mVerts != mStackVerts)
+ delete mVerts;
+ }
+
+ void reserve(int theCapacity)
+ {
+ if (mCapacity < theCapacity)
+ {
+ mCapacity = theCapacity;
+ D3DTLVERTEX *aNewList = new D3DTLVERTEX[theCapacity];
+ memcpy(aNewList,mVerts,mSize*sizeof(mVerts[0]));
+ if (mVerts != mStackVerts)
+ delete mVerts;
+
+ mVerts = aNewList;
+ }
+ }
+
+ void push_back(const D3DTLVERTEX &theVert)
+ {
+ if (mSize==mCapacity)
+ reserve(mCapacity*2);
+
+ mVerts[mSize++] = theVert;
+ }
+
+ void operator=(const VertexList &theList)
+ {
+ reserve(theList.mSize);
+ mSize = theList.mSize;
+ memcpy(mVerts,theList.mVerts,mSize*sizeof(mVerts[0]));
+ }
+
+
+ D3DTLVERTEX& operator[](int thePos)
+ {
+ return mVerts[thePos];
+ }
+
+ int size() { return mSize; }
+ void clear() { mSize = 0; }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static inline float GetCoord(const D3DTLVERTEX &theVertex, int theCoord)
+{
+ switch (theCoord)
+ {
+ case 0: return theVertex.sx;
+ case 1: return theVertex.sy;
+ case 2: return theVertex.sz;
+ case 3: return theVertex.tu;
+ case 4: return theVertex.tv;
+ default: return 0;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static inline D3DTLVERTEX Interpolate(const D3DTLVERTEX &v1, const D3DTLVERTEX &v2, float t)
+{
+ D3DTLVERTEX aVertex = v1;
+ aVertex.sx = v1.sx + t*(v2.sx-v1.sx);
+ aVertex.sy = v1.sy + t*(v2.sy-v1.sy);
+ aVertex.tu = v1.tu + t*(v2.tu-v1.tu);
+ aVertex.tv = v1.tv + t*(v2.tv-v1.tv);
+ if (v1.color!=v2.color)
+ {
+ int r = RGBA_GETRED(v1.color) + t*(RGBA_GETRED(v2.color) - RGBA_GETRED(v1.color));
+ int g = RGBA_GETGREEN(v1.color) + t*(RGBA_GETGREEN(v2.color) - RGBA_GETGREEN(v1.color));
+ int b = RGBA_GETBLUE(v1.color) + t*(RGBA_GETBLUE(v2.color) - RGBA_GETBLUE(v1.color));
+ int a = RGBA_GETALPHA(v1.color) + t*(RGBA_GETALPHA(v2.color) - RGBA_GETALPHA(v1.color));
+ aVertex.color = RGBA_MAKE(r,g,b,a);
+ }
+
+ return aVertex;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+template<class Pred>
+struct PointClipper
+{
+ Pred mPred;
+
+ void ClipPoint(int n, float clipVal, const D3DTLVERTEX &v1, const D3DTLVERTEX &v2, VertexList &out);
+ void ClipPoints(int n, float clipVal, VertexList &in, VertexList &out);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+template<class Pred>
+void PointClipper<Pred>::ClipPoint(int n, float clipVal, const D3DTLVERTEX &v1, const D3DTLVERTEX &v2, VertexList &out)
+{
+ if (!mPred(GetCoord(v1,n), clipVal))
+ {
+ if (!mPred(GetCoord(v2,n), clipVal)) // both inside
+ out.push_back(v2);
+ else // inside -> outside
+ {
+ float t = (clipVal - GetCoord(v1,n))/(GetCoord(v2,n)-GetCoord(v1,n));
+ out.push_back(Interpolate(v1,v2,t));
+ }
+ }
+ else
+ {
+ if (!mPred(GetCoord(v2,n), clipVal)) // outside -> inside
+ {
+ float t = (clipVal - GetCoord(v1, n))/(GetCoord(v2,n)-GetCoord(v1,n));
+ out.push_back(Interpolate(v1,v2,t));
+ out.push_back(v2);
+ }
+// else // outside -> outside
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+template<class Pred>
+void PointClipper<Pred>::ClipPoints(int n, float clipVal, VertexList &in, VertexList &out)
+{
+ if(in.size()<2)
+ return;
+
+ ClipPoint(n,clipVal,in[in.size()-1],in[0],out);
+ for(VertexList::size_type i=0; i<in.size()-1; i++)
+ ClipPoint(n,clipVal,in[i],in[i+1],out);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void DrawPolyClipped(LPDIRECT3DDEVICE7 theDevice, const Rect *theClipRect, const VertexList &theList)
+{
+ VertexList l1, l2;
+ l1 = theList;
+
+ int left = theClipRect->mX;
+ int right = left + theClipRect->mWidth;
+ int top = theClipRect->mY;
+ int bottom = top + theClipRect->mHeight;
+
+ VertexList *in = &l1, *out = &l2;
+ PointClipper<std::less<float> > aLessClipper;
+ PointClipper<std::greater_equal<float> > aGreaterClipper;
+
+ aLessClipper.ClipPoints(0,left,*in,*out); std::swap(in,out); out->clear();
+ aLessClipper.ClipPoints(1,top,*in,*out); std::swap(in,out); out->clear();
+ aGreaterClipper.ClipPoints(0,right,*in,*out); std::swap(in,out); out->clear();
+ aGreaterClipper.ClipPoints(1,bottom,*in,*out);
+
+ VertexList &aList = *out;
+
+ if (aList.size() >= 3)
+ D3DInterface::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, gVertexType, &aList[0], aList.size(), 0),"DrawPrimitive (Tri) 2");
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void DoPolyTextureClip(VertexList &theList)
+{
+ VertexList l2;
+
+ float left = 0;
+ float right = 1;
+ float top = 0;
+ float bottom = 1;
+
+ VertexList *in = &theList, *out = &l2;
+ PointClipper<std::less<float> > aLessClipper;
+ PointClipper<std::greater_equal<float> > aGreaterClipper;
+
+ aLessClipper.ClipPoints(3,left,*in,*out); std::swap(in,out); out->clear();
+ aLessClipper.ClipPoints(4,top,*in,*out); std::swap(in,out); out->clear();
+ aGreaterClipper.ClipPoints(3,right,*in,*out); std::swap(in,out); out->clear();
+ aGreaterClipper.ClipPoints(4,bottom,*in,*out);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::BltTransformed(LPDIRECT3DDEVICE7 theDevice, const SexyMatrix3 &theTrans, const Rect& theSrcRect, const Color& theColor, const Rect *theClipRect, float theX, float theY, bool center)
+{
+ int srcLeft = theSrcRect.mX;
+ int srcTop = theSrcRect.mY;
+ int srcRight = srcLeft + theSrcRect.mWidth;
+ int srcBottom = srcTop + theSrcRect.mHeight;
+ int srcX, srcY;
+ float dstX, dstY;
+ int aWidth;
+ int aHeight;
+ float u1,v1,u2,v2;
+ float startx = 0, starty = 0;
+ float pixelcorrect = 0.5f;
+
+ if (center)
+ {
+ startx = -theSrcRect.mWidth/2.0f;
+ starty = -theSrcRect.mHeight/2.0f;
+ pixelcorrect = 0.0f;
+ }
+
+ srcY = srcTop;
+ dstY = starty;
+
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+
+ if ((srcLeft >= srcRight) || (srcTop >= srcBottom))
+ return;
+
+ while(srcY < srcBottom)
+ {
+ srcX = srcLeft;
+ dstX = startx;
+ while(srcX < srcRight)
+ {
+ aWidth = srcRight-srcX;
+ aHeight = srcBottom-srcY;
+ LPDIRECTDRAWSURFACE7 aTexture = GetTexture(srcX, srcY, aWidth, aHeight, u1, v1, u2, v2);
+
+ float x = dstX; // - 0.5f;
+ float y = dstY; // - 0.5f;
+
+ SexyVector2 p[4] = { SexyVector2(x, y), SexyVector2(x,y+aHeight), SexyVector2(x+aWidth, y) , SexyVector2(x+aWidth, y+aHeight) };
+ SexyVector2 tp[4];
+
+ int i;
+ for (i=0; i<4; i++)
+ {
+ tp[i] = theTrans*p[i];
+ tp[i].x -= pixelcorrect - theX;
+ tp[i].y -= pixelcorrect - theY;
+ }
+
+ bool clipped = false;
+ if (theClipRect != NULL)
+ {
+ int left = theClipRect->mX;
+ int right = left + theClipRect->mWidth;
+ int top = theClipRect->mY;
+ int bottom = top + theClipRect->mHeight;
+ for (i=0; i<4; i++)
+ {
+ if (tp[i].x<left || tp[i].x>=right || tp[i].y<top || tp[i].y>=bottom)
+ {
+ clipped = true;
+ break;
+ }
+ }
+ }
+
+ D3DTLVERTEX aVertex[4] =
+ {
+ { tp[0].x, tp[0].y, 0, 1, aColor, 0, u1, v1 },
+ { tp[1].x, tp[1].y, 0, 1, aColor, 0, u1, v2 },
+ { tp[2].x, tp[2].y, 0, 1, aColor, 0, u2, v1 },
+ { tp[3].x, tp[3].y, 0, 1, aColor, 0, u2, v2 }
+ };
+
+ D3DInterface::CheckDXError(theDevice->SetTexture(0, aTexture),"SetTexture gTexture");
+
+ if (!clipped)
+ D3DInterface::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, gVertexType, aVertex, 4, 0),"DrawPrimitive (Tri) 3");
+ else
+ {
+ VertexList aList;
+ aList.push_back(aVertex[0]);
+ aList.push_back(aVertex[1]);
+ aList.push_back(aVertex[3]);
+ aList.push_back(aVertex[2]);
+
+ DrawPolyClipped(theDevice, theClipRect, aList);
+// DrawPolyClipped(theDevice, theClipRect, aVertex+1, 3);
+ }
+
+// D3DInterface::CheckDXError(theDevice->SetTexture(0, NULL),"SetTexture NULL");
+
+ srcX += aWidth;
+ dstX += aWidth;
+ }
+
+ srcY += aHeight;
+ dstY += aHeight;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+#define GetColorFromTriVertex(theVertex, theColor) (theVertex.color?theVertex.color:theColor)
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void TextureData::BltTriangles(LPDIRECT3DDEVICE7 theDevice, const TriVertex theVertices[][3], int theNumTriangles, DWORD theColor, float tx, float ty)
+{
+ if ((mMaxTotalU <= 1.0) && (mMaxTotalV <= 1.0))
+ {
+ D3DInterface::CheckDXError(theDevice->SetTexture(0, mTextures[0].mTexture),"SetTexture gTexture");
+
+ D3DTLVERTEX aVertexCache[100][3];
+ int aVertexCacheNum = 0;
+
+ for (int aTriangleNum = 0; aTriangleNum < theNumTriangles; aTriangleNum++)
+ {
+ TriVertex* aTriVerts = (TriVertex*) theVertices[aTriangleNum];
+ D3DTLVERTEX* aD3DVertex = (D3DTLVERTEX*) aVertexCache[aVertexCacheNum++];
+
+ aD3DVertex[0].sx = aTriVerts[0].x + tx;
+ aD3DVertex[0].sy = aTriVerts[0].y + ty;
+ aD3DVertex[0].sz = 0;
+ aD3DVertex[0].rhw = 1;
+ aD3DVertex[0].color = GetColorFromTriVertex(aTriVerts[0],theColor);
+ aD3DVertex[0].specular = 0;
+ aD3DVertex[0].tu = aTriVerts[0].u * mMaxTotalU;
+ aD3DVertex[0].tv = aTriVerts[0].v * mMaxTotalV;
+
+ aD3DVertex[1].sx = aTriVerts[1].x + tx;
+ aD3DVertex[1].sy = aTriVerts[1].y + ty;
+ aD3DVertex[1].sz = 0;
+ aD3DVertex[1].rhw = 1;
+ aD3DVertex[1].color = GetColorFromTriVertex(aTriVerts[1],theColor);
+ aD3DVertex[1].specular = 0;
+ aD3DVertex[1].tu = aTriVerts[1].u * mMaxTotalU;
+ aD3DVertex[1].tv = aTriVerts[1].v * mMaxTotalV;
+
+ aD3DVertex[2].sx = aTriVerts[2].x + tx;
+ aD3DVertex[2].sy = aTriVerts[2].y + ty;
+ aD3DVertex[2].sz = 0;
+ aD3DVertex[2].rhw = 1;
+ aD3DVertex[2].color = GetColorFromTriVertex(aTriVerts[2],theColor);
+ aD3DVertex[2].specular = 0;
+ aD3DVertex[2].tu = aTriVerts[2].u * mMaxTotalU;
+ aD3DVertex[2].tv = aTriVerts[2].v * mMaxTotalV;
+
+ if ((aVertexCacheNum == 100) || (aTriangleNum == theNumTriangles - 1))
+ {
+ // Flush the triangles now
+ D3DInterface::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLELIST, gVertexType, aVertexCache, aVertexCacheNum*3, 0),"DrawPrimitive (TriList)");
+ aVertexCacheNum = 0;
+ }
+ }
+ }
+ else
+ {
+ for (int aTriangleNum = 0; aTriangleNum < theNumTriangles; aTriangleNum++)
+ {
+ TriVertex* aTriVerts = (TriVertex*) theVertices[aTriangleNum];
+
+ D3DTLVERTEX aVertex[3] =
+ {
+ { aTriVerts[0].x + tx, aTriVerts[0].y + ty, 0, 1, GetColorFromTriVertex(aTriVerts[0],theColor), 0, aTriVerts[0].u*mMaxTotalU, aTriVerts[0].v*mMaxTotalV },
+ { aTriVerts[1].x + tx, aTriVerts[1].y + ty, 0, 1, GetColorFromTriVertex(aTriVerts[1],theColor), 0, aTriVerts[1].u*mMaxTotalU, aTriVerts[1].v*mMaxTotalV },
+ { aTriVerts[2].x + tx, aTriVerts[2].y + ty, 0, 1, GetColorFromTriVertex(aTriVerts[2],theColor), 0, aTriVerts[2].u*mMaxTotalU, aTriVerts[2].v*mMaxTotalV }
+ };
+
+ float aMinU = mMaxTotalU, aMinV = mMaxTotalV;
+ float aMaxU = 0, aMaxV = 0;
+
+ int i,j,k;
+ for (i=0; i<3; i++)
+ {
+ if(aVertex[i].tu < aMinU)
+ aMinU = aVertex[i].tu;
+
+ if(aVertex[i].tv < aMinV)
+ aMinV = aVertex[i].tv;
+
+ if(aVertex[i].tu > aMaxU)
+ aMaxU = aVertex[i].tu;
+
+ if(aVertex[i].tv > aMaxV)
+ aMaxV = aVertex[i].tv;
+ }
+
+ VertexList aMasterList;
+ aMasterList.push_back(aVertex[0]);
+ aMasterList.push_back(aVertex[1]);
+ aMasterList.push_back(aVertex[2]);
+
+
+ VertexList aList;
+
+ int aLeft = floorf(aMinU);
+ int aTop = floorf(aMinV);
+ int aRight = ceilf(aMaxU);
+ int aBottom = ceilf(aMaxV);
+ if (aLeft < 0)
+ aLeft = 0;
+ if (aTop < 0)
+ aTop = 0;
+ if (aRight > mTexVecWidth)
+ aRight = mTexVecWidth;
+ if (aBottom > mTexVecHeight)
+ aBottom = mTexVecHeight;
+
+ TextureDataPiece &aStandardPiece = mTextures[0];
+ for (i=aTop; i<aBottom; i++)
+ {
+ for (j=aLeft; j<aRight; j++)
+ {
+ TextureDataPiece &aPiece = mTextures[i*mTexVecWidth + j];
+
+
+ VertexList aList = aMasterList;
+ for(k=0; k<3; k++)
+ {
+ aList[k].tu -= j;
+ aList[k].tv -= i;
+ if (i==mTexVecHeight-1)
+ aList[k].tv *= (float)aStandardPiece.mHeight / aPiece.mHeight;
+ if (j==mTexVecWidth-1)
+ aList[k].tu *= (float)aStandardPiece.mWidth / aPiece.mWidth;
+ }
+
+ DoPolyTextureClip(aList);
+ if (aList.size() >= 3)
+ {
+ D3DInterface::CheckDXError(theDevice->SetTexture(0, aPiece.mTexture),"SetTexture gTexture");
+ D3DInterface::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, gVertexType, &aList[0], aList.size(), 0),"DrawPrimitive (Tri) 4");
+
+ /* CheckDXError(theDevice->SetTexture(0, NULL),"SetTexture NULL");
+ theDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME);
+ CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, gVertexType, &aList[0], aList.size(), D3DDP_WAIT),"DrawPrimitive (Tri)");
+ theDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);*/
+ }
+ }
+ }
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DInterface::CreateImageTexture(MemoryImage *theImage)
+{
+ bool wantPurge = false;
+
+ if(theImage->mD3DData==NULL)
+ {
+ theImage->mD3DData = new TextureData();
+
+ // The actual purging was deferred
+ wantPurge = theImage->mPurgeBits;
+
+ AutoCrit aCrit(gSexyAppBase->mDDInterface->mCritSect); // Make images thread safe
+ mImageSet.insert(theImage);
+ }
+
+ TextureData *aData = (TextureData*)theImage->mD3DData;
+ aData->CheckCreateTextures(theImage, mD3DDevice, mDD);
+
+ if (wantPurge)
+ theImage->PurgeBits();
+
+ return aData->mPixelFormat != PixelFormat_Unknown;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DInterface::RecoverBits(MemoryImage* theImage)
+{
+ if (theImage->mD3DData == NULL)
+ return false;
+
+ TextureData* aData = (TextureData*) theImage->mD3DData;
+ if (aData->mBitsChangedCount != theImage->mBitsChangedCount) // bits have changed since texture was created
+ return false;
+
+ for (int aPieceRow = 0; aPieceRow < aData->mTexVecHeight; aPieceRow++)
+ {
+ for (int aPieceCol = 0; aPieceCol < aData->mTexVecWidth; aPieceCol++)
+ {
+ TextureDataPiece* aPiece = &aData->mTextures[aPieceRow*aData->mTexVecWidth + aPieceCol];
+
+ DDSURFACEDESC2 aDesc;
+ aDesc.dwSize = sizeof(aDesc);
+ if (D3DInterface::CheckDXError(aPiece->mTexture->Lock(NULL,&aDesc,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_READONLY,NULL),"Lock Texture"))
+ return false;
+
+ int offx = aPieceCol*aData->mTexPieceWidth;
+ int offy = aPieceRow*aData->mTexPieceHeight;
+ int aWidth = min(theImage->mWidth-offx, aPiece->mWidth);
+ int aHeight = min(theImage->mHeight-offy, aPiece->mHeight);
+
+ switch (aData->mPixelFormat)
+ {
+ case PixelFormat_A8R8G8B8: CopyTexture8888ToImage(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight); break;
+ case PixelFormat_A4R4G4B4: CopyTexture4444ToImage(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight); break;
+ case PixelFormat_R5G6B5: CopyTexture565ToImage(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight); break;
+ case PixelFormat_Palette8: CopyTexturePalette8ToImage(aDesc.lpSurface, aDesc.lPitch, theImage, offx, offy, aWidth, aHeight, aData->mPalette); break;
+ }
+
+ D3DInterface::CheckDXError(aPiece->mTexture->Unlock(NULL),"Texture Unlock");
+ }
+ }
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::SetCurTexture(MemoryImage *theImage)
+{
+ if (theImage==NULL)
+ {
+ mD3DDevice->SetTexture(0,NULL);
+ return;
+ }
+
+ if (!CreateImageTexture(theImage))
+ return;
+
+ TextureData *aData = (TextureData*)theImage->mD3DData;
+ mD3DDevice->SetTexture(0,aData->mTextures[0].mTexture);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::PushTransform(const SexyMatrix3 &theTransform, bool concatenate)
+{
+ if (mTransformStack.empty() || !concatenate)
+ mTransformStack.push_back(theTransform);
+ else
+ {
+ SexyMatrix3 &aTrans = mTransformStack.back();
+ mTransformStack.push_back(theTransform*aTrans);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::PopTransform()
+{
+ if (!mTransformStack.empty())
+ mTransformStack.pop_back();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::RemoveMemoryImage(MemoryImage *theImage)
+{
+ if (theImage->mD3DData != NULL)
+ {
+ delete (TextureData*)theImage->mD3DData;
+ theImage->mD3DData = NULL;
+
+ AutoCrit aCrit(gSexyAppBase->mDDInterface->mCritSect); // Make images thread safe
+ mImageSet.erase(theImage);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::Cleanup()
+{
+ Flush();
+
+ ImageSet::iterator anItr;
+ for(anItr = mImageSet.begin(); anItr != mImageSet.end(); ++anItr)
+ {
+ MemoryImage *anImage = *anItr;
+ delete (TextureData*)anImage->mD3DData;
+ anImage->mD3DData = NULL;
+ }
+
+ mImageSet.clear();
+
+ if (mD3DDevice != NULL)
+ {
+ mD3DDevice->Release();
+ mD3DDevice = NULL;
+ }
+
+ if (mD3D != NULL)
+ {
+ mD3D->Release();
+ mD3D = NULL;
+ }
+
+ if (mDDSDrawSurface != NULL)
+ {
+ mDDSDrawSurface->Release();
+ mDDSDrawSurface = NULL;
+ }
+
+ if (mZBuffer != NULL)
+ {
+ mZBuffer->Release();
+ mZBuffer = NULL;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::SetupDrawMode(int theDrawMode, const Color &theColor, Image *theImage)
+{
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+/* if (theImage != NULL)
+ {
+ MemoryImage *anImage = (MemoryImage*)theImage;
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (anImage->mHasAlpha || anImage->mHasTrans || theColor.mAlpha<255)?TRUE:FALSE);
+ }
+ else
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, theColor.mAlpha<255?TRUE:FALSE);
+*/
+
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ }
+ else // Additive
+ {
+// mD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+// theColor.mRed = theColor.mRed * theColor.mAlpha / 255;
+// theColor.mGreen = theColor.mGreen * theColor.mAlpha / 255;
+// theColor.mBlue = theColor.mBlue * theColor.mAlpha / 255;
+
+// mD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ mD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
+ }
+// mD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::Blt(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode, bool linearFilter)
+{
+ if (!mTransformStack.empty())
+ {
+ BltClipF(theImage,theX,theY,theSrcRect,NULL,theColor,theDrawMode);
+ return;
+ }
+
+ if (!PreDraw())
+ return;
+
+ MemoryImage* aSrcMemoryImage = (MemoryImage*) theImage;
+
+ if (!CreateImageTexture(aSrcMemoryImage))
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, theImage);
+
+ TextureData *aData = (TextureData*)aSrcMemoryImage->mD3DData;
+
+ SetLinearFilter(mD3DDevice, linearFilter);
+ aData->Blt(mD3DDevice,theX,theY,theSrcRect,theColor);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::BltMirror(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode, bool linearFilter)
+{
+ SexyTransform2D aTransform;
+
+ aTransform.Translate(-theSrcRect.mWidth,0);
+ aTransform.Scale(-1, 1);
+ aTransform.Translate(theX, theY);
+
+ BltTransformed(theImage,NULL,theColor,theDrawMode,theSrcRect,aTransform,linearFilter);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::BltClipF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect *theClipRect, const Color& theColor, int theDrawMode)
+{
+ SexyTransform2D aTransform;
+ aTransform.Translate(theX, theY);
+
+ BltTransformed(theImage,theClipRect,theColor,theDrawMode,theSrcRect,aTransform,true);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect* theClipRect, const Color &theColor, int theDrawMode, bool fastStretch, bool mirror)
+{
+ float xScale = (float)theDestRect.mWidth / theSrcRect.mWidth;
+ float yScale = (float)theDestRect.mHeight / theSrcRect.mHeight;
+
+ SexyTransform2D aTransform;
+ if (mirror)
+ {
+ aTransform.Translate(-theSrcRect.mWidth,0);
+ aTransform.Scale(-xScale, yScale);
+ }
+ else
+ aTransform.Scale(xScale, yScale);
+
+ aTransform.Translate(theDestRect.mX, theDestRect.mY);
+ BltTransformed(theImage,theClipRect,theColor,theDrawMode,theSrcRect,aTransform,!fastStretch);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::BltRotated(Image* theImage, float theX, float theY, const Rect* theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY, const Rect &theSrcRect)
+{
+ SexyTransform2D aTransform;
+
+ aTransform.Translate(-theRotCenterX, -theRotCenterY);
+ aTransform.RotateRad(theRot);
+ aTransform.Translate(theX+theRotCenterX,theY+theRotCenterY);
+
+ BltTransformed(theImage,theClipRect,theColor,theDrawMode,theSrcRect,aTransform,true);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::BltTransformed(Image* theImage, const Rect* theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, const SexyMatrix3 &theTransform, bool linearFilter, float theX, float theY, bool center)
+{
+ if (!PreDraw())
+ return;
+
+ MemoryImage* aSrcMemoryImage = (MemoryImage*) theImage;
+
+ if (!CreateImageTexture(aSrcMemoryImage))
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, theImage);
+
+ TextureData *aData = (TextureData*)aSrcMemoryImage->mD3DData;
+
+ if (!mTransformStack.empty())
+ {
+ SetLinearFilter(mD3DDevice, true); // force linear filtering in the case of a global transform
+ if (theX!=0 || theY!=0)
+ {
+ SexyTransform2D aTransform;
+ if (center)
+ aTransform.Translate(-theSrcRect.mWidth/2.0f,-theSrcRect.mHeight/2.0f);
+
+ aTransform = theTransform * aTransform;
+ aTransform.Translate(theX,theY);
+ aTransform = mTransformStack.back() * aTransform;
+
+ aData->BltTransformed(mD3DDevice, aTransform, theSrcRect, theColor, theClipRect);
+ }
+ else
+ {
+ SexyTransform2D aTransform = mTransformStack.back()*theTransform;
+ aData->BltTransformed(mD3DDevice, aTransform, theSrcRect, theColor, theClipRect, theX, theY, center);
+ }
+ }
+ else
+ {
+ SetLinearFilter(mD3DDevice, linearFilter);
+ aData->BltTransformed(mD3DDevice, theTransform, theSrcRect, theColor, theClipRect, theX, theY, center);
+ }
+}
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+ if (!PreDraw())
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, NULL);
+
+ float x1, y1, x2, y2;
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+
+ if (!mTransformStack.empty())
+ {
+ SexyVector2 p1(theStartX,theStartY);
+ SexyVector2 p2(theEndX,theEndY);
+ p1 = mTransformStack.back()*p1;
+ p2 = mTransformStack.back()*p2;
+
+ x1 = p1.x;
+ y1 = p1.y;
+ x2 = p2.x;
+ y2 = p2.y;
+ }
+ else
+ {
+ x1 = theStartX;
+ y1 = theStartY;
+ x2 = theEndX;
+ y2 = theEndY;
+ }
+
+ D3DTLVERTEX aVertex[3] =
+ {
+ { x1, y1, 0, 1, aColor, 0, 0, 0 },
+ { x2, y2, 0, 1, aColor, 0, 0, 0 },
+ { x2+0.5f, y2+0.5f, 0, 1, aColor, 0, 0, 0 }
+ };
+
+ D3DInterface::CheckDXError(mD3DDevice->SetTexture(0, NULL),"SetTexture NULL");
+ D3DInterface::CheckDXError(mD3DDevice->DrawPrimitive(D3DPT_LINESTRIP, gVertexType, aVertex, 3, 0),"DrawPrimitive (Line)");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::FillRect(const Rect& theRect, const Color& theColor, int theDrawMode)
+{
+ if (!PreDraw())
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, NULL);
+
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+ float x = theRect.mX - 0.5f;
+ float y = theRect.mY - 0.5f;
+ float aWidth = theRect.mWidth;
+ float aHeight = theRect.mHeight;
+
+ D3DTLVERTEX aVertex[4] =
+ {
+ { x, y, 0, 1, aColor, 0, 0, 0 },
+ { x, y+aHeight, 0, 1, aColor, 0, 0, 0 },
+ { x+aWidth, y, 0, 1, aColor, 0, 0, 0 },
+ { x+aWidth, y+aHeight, 0, 1, aColor, 0, 0, 0 }
+ };
+
+
+ if (!mTransformStack.empty())
+ {
+ SexyVector2 p[4] = { SexyVector2(x, y), SexyVector2(x,y+aHeight), SexyVector2(x+aWidth, y) , SexyVector2(x+aWidth, y+aHeight) };
+
+ int i;
+ for (i=0; i<4; i++)
+ {
+ p[i] = mTransformStack.back()*p[i];
+ p[i].x -= 0.5f;
+ p[i].y -= 0.5f;
+ aVertex[i].sx = p[i].x;
+ aVertex[i].sy = p[i].y;
+ }
+ }
+
+ CheckDXError(mD3DDevice->SetTexture(0, NULL),"SetTexture NULL");
+ CheckDXError(mD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, gVertexType, aVertex, 4, 0),"DrawPrimitive (Rect)");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::DrawTriangle(const TriVertex &p1, const TriVertex &p2, const TriVertex &p3, const Color &theColor, int theDrawMode)
+{
+ if (!PreDraw())
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, NULL);
+
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+ D3DTLVERTEX aVertex[3] =
+ {
+ { p1.x, p1.y, 0, 1, GetColorFromTriVertex(p1, aColor), 0, 0, 0 },
+ { p2.x, p2.y, 0, 1, GetColorFromTriVertex(p2, aColor), 0, 0, 0 },
+ { p3.x, p3.y, 0, 1, GetColorFromTriVertex(p3, aColor), 0, 0, 0 }
+ };
+
+
+ CheckDXError(mD3DDevice->SetTexture(0, NULL),"SetTexture NULL");
+ CheckDXError(mD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, gVertexType, aVertex, 3, 0),"DrawPrimitive (Tri) 5");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::FillPoly(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty)
+{
+ if (theNumVertices<3)
+ return;
+
+ if (!PreDraw())
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, NULL);
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+
+ CheckDXError(mD3DDevice->SetTexture(0, NULL),"SetTexture NULL");
+
+ VertexList aList;
+ for (int i=0; i<theNumVertices; i++)
+ {
+ D3DTLVERTEX vert = { theVertices[i].mX + tx, theVertices[i].mY + ty, 0, 1, aColor, 0, 0, 0 };
+ if (!mTransformStack.empty())
+ {
+ SexyVector2 v(vert.sx,vert.sy);
+ v = mTransformStack.back()*v;
+ vert.sx = v.x;
+ vert.sy = v.y;
+ }
+
+ aList.push_back(vert);
+ }
+
+ if (theClipRect != NULL)
+ DrawPolyClipped(mD3DDevice,theClipRect,aList);
+ else
+ D3DInterface::CheckDXError(mD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, gVertexType, &aList[0], aList.size(), 0),"DrawPrimitive (FillPoly)");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::DrawTriangleTex(const TriVertex &p1, const TriVertex &p2, const TriVertex &p3, const Color &theColor, int theDrawMode, Image *theTexture, bool blend)
+{
+ TriVertex aVertices[1][3] = {{p1, p2, p3}};
+ DrawTrianglesTex(aVertices,1,theColor,theDrawMode,theTexture,blend);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::DrawTrianglesTex(const TriVertex theVertices[][3], int theNumTriangles, const Color &theColor, int theDrawMode, Image *theTexture, float tx, float ty, bool blend)
+{
+ if (!PreDraw())
+ return;
+
+ MemoryImage* aSrcMemoryImage = (MemoryImage*)theTexture;
+
+ if (!CreateImageTexture(aSrcMemoryImage))
+ return;
+
+ SetupDrawMode(theDrawMode, theColor, theTexture);
+ DWORD aColor = RGBA_MAKE(theColor.mRed, theColor.mGreen, theColor.mBlue, theColor.mAlpha);
+
+ TextureData *aData = (TextureData*)aSrcMemoryImage->mD3DData;
+
+ SetLinearFilter(mD3DDevice, blend);
+
+ aData->BltTriangles(mD3DDevice, theVertices, theNumTriangles, aColor, tx, ty);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::DrawTrianglesTexStrip(const TriVertex theVertices[], int theNumTriangles, const Color &theColor, int theDrawMode, Image *theTexture, float tx, float ty, bool blend)
+{
+ TriVertex aList[100][3];
+ int aTriNum = 0;
+ while (aTriNum < theNumTriangles)
+ {
+ int aMaxTriangles = min(100,theNumTriangles - aTriNum);
+ for (int i=0; i<aMaxTriangles; i++)
+ {
+ aList[i][0] = theVertices[aTriNum];
+ aList[i][1] = theVertices[aTriNum+1];
+ aList[i][2] = theVertices[aTriNum+2];
+ aTriNum++;
+ }
+ DrawTrianglesTex(aList,aMaxTriangles,theColor,theDrawMode,theTexture, tx, ty, blend);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DInterface::Flush()
+{
+ if (mSceneBegun)
+ {
+ mD3DDevice->EndScene();
+
+ mSceneBegun = false;
+ mErrorString.erase();
+ }
+}
+
diff --git a/osframework/source/SexyAppFramework/D3DInterface.h b/osframework/source/SexyAppFramework/D3DInterface.h
new file mode 100644
index 0000000..4d701ba
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3DInterface.h
@@ -0,0 +1,154 @@
+#ifndef __D3DINTERFACE_H__
+#define __D3DINTERFACE_H__
+
+#include "Common.h"
+#include "MemoryImage.h"
+#include "SexyMatrix.h"
+#include <d3d.h>
+
+
+namespace Sexy
+{
+
+class DDInterface;
+class SexyMatrix3;
+class TriVertex;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// The following flags apply to to the mD3DFlags member of MemoryImage
+enum D3DImageFlags
+{
+ D3DImageFlag_MinimizeNumSubdivisions = 0x0001, // subdivide image into fewest possible textures (may use more memory)
+ D3DImageFlag_Use64By64Subdivisions = 0x0002, // good to use with image strips so the entire texture isn't pulled in when drawing just a piece
+ D3DImageFlag_UseA4R4G4B4 = 0x0004, // images with not too many color gradients work well in this format
+ D3DImageFlag_UseA8R8G8B8 = 0x0008 // non-alpha images will be stored as R5G6B5 by default so use this option if you want a 32-bit non-alpha image
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct TextureDataPiece
+{
+ LPDIRECTDRAWSURFACE7 mTexture;
+ int mWidth,mHeight;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+enum PixelFormat
+{
+ PixelFormat_Unknown = 0x0000,
+ PixelFormat_A8R8G8B8 = 0x0001,
+ PixelFormat_A4R4G4B4 = 0x0002,
+ PixelFormat_R5G6B5 = 0x0004,
+ PixelFormat_Palette8 = 0x0008
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct TextureData
+{
+public:
+ typedef std::vector<TextureDataPiece> TextureVector;
+
+ TextureVector mTextures;
+ LPDIRECTDRAWPALETTE mPalette;
+
+ int mWidth,mHeight;
+ int mTexVecWidth, mTexVecHeight;
+ int mTexPieceWidth, mTexPieceHeight;
+ int mBitsChangedCount;
+ int mTexMemSize;
+ float mMaxTotalU, mMaxTotalV;
+ PixelFormat mPixelFormat;
+ DWORD mImageFlags;
+
+ TextureData();
+ ~TextureData();
+
+ void ReleaseTextures();
+
+ void CreateTextureDimensions(MemoryImage *theImage);
+ void CreateTextures(MemoryImage *theImage, LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAW7 theDraw);
+ void CheckCreateTextures(MemoryImage *theImage, LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAW7 theDraw);
+ LPDIRECTDRAWSURFACE7 GetTexture(int x, int y, int &width, int &height, float &u1, float &v1, float &u2, float &v2);
+ LPDIRECTDRAWSURFACE7 GetTextureF(float x, float y, float &width, float &height, float &u1, float &v1, float &u2, float &v2);
+
+ void Blt(LPDIRECT3DDEVICE7 theDevice, float theX, float theY, const Rect& theSrcRect, const Color& theColor);
+ void BltTransformed(LPDIRECT3DDEVICE7 theDevice, const SexyMatrix3 &theTrans, const Rect& theSrcRect, const Color& theColor, const Rect *theClipRect = NULL, float theX = 0, float theY = 0, bool center = false);
+ void BltTriangles(LPDIRECT3DDEVICE7 theDevice, const TriVertex theVertices[][3], int theNumTriangles, DWORD theColor, float tx = 0, float ty = 0);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class D3DInterface
+{
+public:
+ HWND mHWnd;
+ int mWidth;
+ int mHeight;
+
+ LPDIRECTDRAW7 mDD;
+ LPDIRECTDRAWSURFACE7 mDDSDrawSurface;
+ LPDIRECTDRAWSURFACE7 mZBuffer;
+ LPDIRECT3D7 mD3D;
+ LPDIRECT3DDEVICE7 mD3DDevice;
+ D3DVIEWPORT7 mD3DViewport;
+
+ bool mSceneBegun;
+ bool mIsWindowed;
+
+ typedef std::set<MemoryImage*> ImageSet;
+ ImageSet mImageSet;
+
+ typedef std::list<SexyMatrix3> TransformStack;
+ TransformStack mTransformStack;
+
+ static std::string mErrorString;
+
+protected:
+ void UpdateViewport();
+ bool InitD3D();
+ void SetupDrawMode(int theDrawMode, const Color &theColor, Image *theImage);
+ static HRESULT CALLBACK PixelFormatsCallback(LPDDPIXELFORMAT theFormat, LPVOID lpContext);
+
+public:
+ D3DInterface();
+ virtual ~D3DInterface();
+
+ void Cleanup();
+ void PushTransform(const SexyMatrix3 &theTransform, bool concatenate = true);
+ void PopTransform();
+
+ bool PreDraw();
+ void Flush();
+ void RemoveMemoryImage(MemoryImage *theImage);
+
+ bool CreateImageTexture(MemoryImage *theImage);
+ bool RecoverBits(MemoryImage* theImage);
+ void SetCurTexture(MemoryImage *theImage);
+ void Blt(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode, bool linearFilter = false);
+ void BltClipF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect *theClipRect, const Color& theColor, int theDrawMode);
+ void BltMirror(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode, bool linearFilter = false);
+ void StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect* theClipRect, const Color &theColor, int theDrawMode, bool fastStretch, bool mirror = false);
+ void BltRotated(Image* theImage, float theX, float theY, const Rect* theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY, const Rect& theSrcRect);
+ void BltTransformed(Image* theImage, const Rect* theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, const SexyMatrix3 &theTransform, bool linearFilter, float theX = 0, float theY = 0, bool center = false);
+ void DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ void FillRect(const Rect& theRect, const Color& theColor, int theDrawMode);
+ void DrawTriangle(const TriVertex &p1, const TriVertex &p2, const TriVertex &p3, const Color &theColor, int theDrawMode);
+ void DrawTriangleTex(const TriVertex &p1, const TriVertex &p2, const TriVertex &p3, const Color &theColor, int theDrawMode, Image *theTexture, bool blend = true);
+ void DrawTrianglesTex(const TriVertex theVertices[][3], int theNumTriangles, const Color &theColor, int theDrawMode, Image *theTexture, float tx = 0, float ty = 0, bool blend = true);
+ void DrawTrianglesTexStrip(const TriVertex theVertices[], int theNumTriangles, const Color &theColor, int theDrawMode, Image *theTexture, float tx = 0, float ty = 0, bool blend = true);
+ void FillPoly(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty);
+
+ bool InitFromDDInterface(DDInterface *theInterface);
+
+ static void MakeDDPixelFormat(PixelFormat theFormatType, DDPIXELFORMAT* theFormat);
+ static PixelFormat GetDDPixelFormat(LPDDPIXELFORMAT theFormat);
+ static bool CheckDXError(HRESULT theError, const char *theMsg="");
+
+};
+
+}
+
+#endif //__D3DINTERFACE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/D3DTester.cpp b/osframework/source/SexyAppFramework/D3DTester.cpp
new file mode 100644
index 0000000..5e21587
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3DTester.cpp
@@ -0,0 +1,1193 @@
+#include "D3D8Helper.h"
+#include "D3DTester.h"
+#include "DirectXErrorString.h"
+#include "Common.h"
+#include "D3DInterface.h"
+#include "SexyAppBase.h"
+
+
+
+using namespace Sexy;
+static const int gD3DTestTextureWidth = 64;
+static const int gD3DTestTextureHeight = 64;
+static bool gD3DTestHas32BitTexture = false;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DTestImage::D3DTestImage()
+{
+ mBits = NULL;
+ mWidth = 0;
+ mHeight = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DTestImage::D3DTestImage(int theWidth, int theHeight)
+{
+ mBits = NULL;
+ mWidth = 0;
+ mHeight = 0;
+
+ Create(theWidth,theHeight);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DTestImage::~D3DTestImage()
+{
+ FreeImage();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::Create(int theWidth, int theHeight)
+{
+ FreeImage();
+ if(theWidth>0 && theHeight>0)
+ {
+ mBits = new DWORD[theWidth*theHeight];
+ mWidth = theWidth;
+ mHeight = theHeight;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::FreeImage()
+{
+ delete [] mBits;
+ mWidth = 0;
+ mHeight = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const D3DTestImage& D3DTestImage::operator=(const D3DTestImage &theImage)
+{
+ if (&theImage==this)
+ return *this;
+
+ Create(theImage.GetWidth(), theImage.GetHeight());
+ memcpy(mBits, theImage.GetBits(), mWidth*mHeight*4);
+
+ return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTestImage::CompareEqual(const D3DTestImage &theImage) const
+{
+ if (theImage.GetWidth() != GetWidth())
+ return false;
+
+ if (theImage.GetHeight() != GetHeight())
+ return false;
+
+ return memcmp(theImage.GetBits(),GetBits(),mWidth*mHeight*4)==0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::FillRect(int x, int y, int theWidth, int theHeight, DWORD theColor)
+{
+ DWORD *aRow = mBits + y*mWidth + x;
+ for(int j=0; j<theHeight; j++)
+ {
+ DWORD *aPixel = aRow;
+ for(int i=0; i<theWidth; i++)
+ *aPixel++ = theColor;
+
+ aRow += mWidth;
+ }
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::MakeVerticalBands()
+{
+ for(int i=0; i<mWidth; i++)
+ FillRect(i,0,1,mHeight,i&1?0xFFFFFFFF:0xFF000000);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::CopyToTexture8888(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight)
+{
+ DDSURFACEDESC2 aDesc;
+ aDesc.dwSize = sizeof(aDesc);
+ D3DTester::CheckDXError(theTexture->Lock(NULL,&aDesc,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_WRITEONLY,NULL),"Lock Texture");
+
+ int aWidth = min(texWidth,(GetWidth()-offx));
+ int aHeight = min(texHeight,(GetHeight()-offy));
+
+ if(aWidth < texWidth || aHeight < texHeight)
+ memset(aDesc.lpSurface, 0, aDesc.lPitch*aDesc.dwHeight);
+
+ if(aWidth>0 && aHeight>0)
+ {
+ DWORD *srcRow = GetBits() + offy * GetWidth() + offx;
+ char *dstRow = (char*)aDesc.lpSurface;
+
+ for(int y=0; y<aHeight; y++)
+ {
+ DWORD *src = srcRow;
+ DWORD *dst = (DWORD*)dstRow;
+ for(int x=0; x<aWidth; x++)
+ *dst++ = *src++;
+
+ srcRow += GetWidth();
+ dstRow += aDesc.lPitch;
+ }
+ }
+
+ D3DTester::CheckDXError(theTexture->Unlock(NULL),"Texture Unlock");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::CopyToTexture4444(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight)
+{
+
+ DDSURFACEDESC2 aDesc;
+ aDesc.dwSize = sizeof(aDesc);
+ D3DTester::CheckDXError(theTexture->Lock(NULL,&aDesc,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_WRITEONLY,NULL),"Lock Texture");
+
+ int aWidth = min(texWidth,(GetWidth()-offx));
+ int aHeight = min(texHeight,(GetHeight()-offy));
+
+ if(aWidth < texWidth || aHeight < texHeight)
+ memset(aDesc.lpSurface, 0, aDesc.lPitch*aDesc.dwHeight);
+
+ if(aWidth>0 && aHeight>0)
+ {
+ DWORD *srcRow = GetBits() + offy * GetWidth() + offx;
+ char *dstRow = (char*)aDesc.lpSurface;
+
+ for(int y=0; y<aHeight; y++)
+ {
+ DWORD *src = srcRow;
+ ushort *dst = (ushort*)dstRow;
+ for(int x=0; x<aWidth; x++)
+ {
+ DWORD aPixel = *src++;
+ *dst++ = ((aPixel>>16)&0xF000) | ((aPixel>>12)&0x0F00) | ((aPixel>>8)&0x00F0) | ((aPixel>>4)&0x000F);
+ }
+
+ srcRow += GetWidth();
+ dstRow += aDesc.lPitch;
+ }
+ }
+
+ D3DTester::CheckDXError(theTexture->Unlock(NULL),"Texture Unlock");
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::DrawPieceToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, float x, float y, int offx, int offy, int texWidth, int texHeight, DWORD theColor)
+{
+ float maxU = (float)texWidth/gD3DTestTextureWidth;
+ float maxV = (float)texHeight/gD3DTestTextureHeight;
+
+ if (gD3DTestHas32BitTexture)
+ CopyToTexture8888(theTexture, offx, offy, texWidth, texHeight);
+ else
+ CopyToTexture4444(theTexture, offx, offy, texWidth, texHeight);
+
+ x -= 0.5f;
+ y -= 0.5f;
+
+ D3DTLVERTEX aVertex[4] =
+ {
+ { x, y, 0, 1, theColor, 0, 0, 0 },
+ { x, y+texHeight, 0, 1, theColor, 0, 0, maxV },
+ { x+texWidth, y, 0, 1, theColor, 0, maxU, 0 },
+ { x+texWidth, y+texHeight, 0, 1, theColor, 0, maxU, maxV }
+ };
+
+ D3DTester::CheckDXError(theDevice->SetTexture(0, theTexture),"SetTexture theTexture");
+ D3DTester::CheckDXError(theDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, aVertex, 4, D3DDP_WAIT),"DrawPrimitive");
+ D3DTester::CheckDXError(theDevice->SetTexture(0, NULL),"SetTexture NULL");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTestImage::DrawToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, int x, int y, DWORD theColor)
+{
+ int aWidth = GetWidth();
+ int aHeight = GetHeight();
+
+ int aTexWidth = min(64,gD3DTestTextureWidth);
+ int aTexHeight = min(64,gD3DTestTextureHeight);
+
+ for(int j=0; j<aHeight; j+=aTexHeight)
+ {
+ for(int i=0; i<aWidth; i+=aTexWidth)
+ {
+ DrawPieceToDevice(theDevice, theTexture, (float)x+i,(float)y+j,i,j,aTexWidth,aTexHeight,theColor);
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int D3DTestImage::ColorDistance(DWORD c1, DWORD c2)
+{
+ int r1 = (c1&0xff0000)>>16;
+ int g1 = (c1&0x00ff00)>>8;
+ int b1 = (c1&0xff);
+
+ int r2 = (c2&0xff0000)>>16;
+ int g2 = (c2&0x00ff00)>>8;
+ int b2 = (c2&0xff);
+
+ return (r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTestImage::IsUniformColor(DWORD theColor, int &theNumMistakes, int testWidth, int testHeight) const
+{
+ theNumMistakes = 0;
+ const DWORD *aRow = GetBits();
+ DWORD aLastPixel = *aRow;
+ bool isUniform = true;
+ for(int i=0; i<testHeight; i++)
+ {
+ const DWORD *aSrc = aRow;
+ for(int j=0; j<testWidth; j++)
+ {
+ DWORD aPixel = *aSrc++;
+ if(aLastPixel!=aPixel)
+ isUniform = false;
+
+ if(ColorDistance(aPixel,theColor)>COLOR_TOLERANCE)
+ theNumMistakes++;
+ }
+
+ aRow += GetWidth();
+ }
+
+ return isUniform;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int D3DTestImage::CheckUniformBands(int testWidth, int testHeight, int xoff, int yoff)
+{
+ int aNumMistakes = 0;
+ const DWORD *aRow = GetBits() + yoff*GetWidth() + xoff;
+ DWORD aLastPixel = *aRow;
+ bool isUniform = true;
+ for(int i=0; i<testHeight; i++)
+ {
+ const DWORD *aSrc = aRow;
+ for(int j=0; j<testWidth; j++)
+ {
+ DWORD aPixel = *aSrc++;
+ if(aLastPixel!=aPixel)
+ isUniform = false;
+
+ if(ColorDistance(aPixel,(j&1)?0xFFFFFF:0x000000)>COLOR_TOLERANCE)
+ aNumMistakes++;
+ }
+
+ aRow += GetWidth();
+ }
+
+ return aNumMistakes;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static int D3DTestHighBit(DWORD theMask)
+{
+ int aBit = 31;
+ while(aBit>0)
+ {
+ if((1<<aBit) & theMask)
+ break;
+
+ aBit--;
+ }
+
+ return aBit;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+template <class PixelType>
+static void D3DTestPixelConvert(D3DTestImage &theImage, DDSURFACEDESC2 &theDesc, PixelType)
+{
+ int rMask = theDesc.ddpfPixelFormat.dwRBitMask;
+ int gMask = theDesc.ddpfPixelFormat.dwGBitMask;
+ int bMask = theDesc.ddpfPixelFormat.dwBBitMask;
+
+ int redShift = 23-D3DTestHighBit(rMask);
+ int greenShift = 15-D3DTestHighBit(gMask);
+ int blueShift = 7-D3DTestHighBit(bMask);
+
+ char *srcRow = (char*)theDesc.lpSurface;
+ DWORD *dstRow = theImage.GetBits();
+ for(int j=0; j<theImage.GetHeight(); j++)
+ {
+ PixelType *src = (PixelType*)srcRow;
+ DWORD *dst = dstRow;
+ for(int i=0; i<theImage.GetWidth(); i++)
+ {
+
+ PixelType aPixel = *src++;
+ int r = aPixel & rMask;
+ int g = aPixel & gMask;
+ int b = aPixel & bMask;
+
+ if(redShift>0) r<<=redShift; else r>>=-redShift;
+ if(greenShift>0) g<<=greenShift; else g>>=-greenShift;
+ if(blueShift>0) b<<=blueShift; else b>>=-blueShift;
+ *dst++ = 0xFF000000 | r | g | b;
+ }
+
+ srcRow += theDesc.lPitch;
+ dstRow += theImage.GetWidth();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void D3DTestPixelConvert24(D3DTestImage &theImage, DDSURFACEDESC2 &theDesc)
+{
+ int rMask = theDesc.ddpfPixelFormat.dwRBitMask;
+ int gMask = theDesc.ddpfPixelFormat.dwGBitMask;
+ int bMask = theDesc.ddpfPixelFormat.dwBBitMask;
+
+ int redShift = 23-D3DTestHighBit(rMask);
+ int greenShift = 15-D3DTestHighBit(gMask);
+ int blueShift = 7-D3DTestHighBit(bMask);
+
+ char *srcRow = (char*)theDesc.lpSurface;
+ DWORD *dstRow = theImage.GetBits();
+ for(int j=0; j<theImage.GetHeight(); j++)
+ {
+ char *src = srcRow;
+ DWORD *dst = dstRow;
+ for(int i=0; i<theImage.GetWidth(); i++)
+ {
+
+ DWORD aPixel = *((DWORD*)src)&0xFFFFFF;
+ src += 3;
+
+ int r = aPixel & rMask;
+ int g = aPixel & gMask;
+ int b = aPixel & bMask;
+
+ if(redShift>0) r<<=redShift; else r>>=-redShift;
+ if(greenShift>0) g<<=greenShift; else g>>=-greenShift;
+ if(blueShift>0) b<<=blueShift; else b>>=-blueShift;
+ *dst++ = 0xFF000000 | r | g | b;
+ }
+
+ srcRow += theDesc.lPitch;
+ dstRow += theImage.GetWidth();
+ }
+}
+
+#define SafeSetRenderState(x,y)\
+ CheckDXError(mD3DDevice7->SetRenderState(x,y),#x ", " #y)
+
+#define SafeSetTextureStageState(i,x,y)\
+ CheckDXError(mD3DDevice7->SetTextureStageState(i,x,y),#x ", " #y)
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DTester::D3DTester()
+{
+ mDD7 = NULL;
+ mPrimarySurface = NULL;
+ mTextureSurface = NULL;
+ mTextureSurface2 = NULL;
+ mD3D7 = NULL;
+ mD3DDevice7 = NULL;
+ mRegKey = NULL;
+ memset(&mDisplayGUID, 0, sizeof(GUID));
+
+ mMinVidMemory = 0;
+ mRecommendedVidMemory = 0;
+ mDriverYear = 0;
+
+ mCheckRegistry = true;
+ mResultsChanged = false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+D3DTester::~D3DTester()
+{
+ Cleanup();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::CheckRegistry()
+{
+ mResultsChanged = true;
+
+ DWORD aSize, aType;
+
+ if (mRegKey==NULL)
+ return false;
+
+ // Check Test Version
+ DWORD aVersion = 0;
+ aSize = sizeof(aVersion);
+ aType = REG_DWORD;
+ if (RegQueryValueExA(mRegKey, "Version", 0, &aType, (uchar*) &aVersion, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ if (aVersion != TEST_VERSION)
+ return false;
+
+ // Check Min Vid Memory
+ DWORD aMinVidMemory = 0;
+ aSize = sizeof(aMinVidMemory);
+ aType = REG_DWORD;
+ if (RegQueryValueExA(mRegKey, "MinVidMemory", 0, &aType, (uchar*) &aMinVidMemory, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ if (aMinVidMemory != mMinVidMemory)
+ return false;
+
+ // Check Recommended Vid Memory
+ DWORD aRecVidMemory = 0;
+ aSize = sizeof(aRecVidMemory);
+ aType = REG_DWORD;
+ if (RegQueryValueExA(mRegKey, "RecVidMemory", 0, &aType, (uchar*) &aRecVidMemory, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ if (aRecVidMemory != mRecommendedVidMemory)
+ return false;
+
+ // Check GUID
+ UUID aGUID;
+ aSize = sizeof(aGUID);
+ aType = REG_BINARY;
+ if (RegQueryValueExA(mRegKey, "DisplayGUID", 0, &aType, (uchar*) &aGUID, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ if (aSize != sizeof(aGUID))
+ return false;
+
+ if (memcmp(&aGUID,&mDisplayGUID,sizeof(aGUID)) != 0) // different video card or driver
+ return false;
+
+ // Get failure reason
+ char aBuf[4096];
+ aType = REG_SZ;
+ aSize = 4096;
+ if (RegQueryValueExA(mRegKey, "FailureReason", 0, &aType, (uchar*) aBuf, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ mFailureReason = aBuf;
+
+ // Get warining
+ aType = REG_SZ;
+ aSize = 4096;
+ if (RegQueryValueExA(mRegKey, "Warning", 0, &aType, (uchar*) aBuf, &aSize) != ERROR_SUCCESS)
+ return false;
+
+ mWarning = aBuf;
+
+ mResultsChanged = false;
+
+ if (!mFailureReason.empty())
+ return false;
+ else
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::WriteToRegistry()
+{
+ DWORD aSize, aType;
+
+ if (mRegKey==NULL)
+ return;
+
+ // Write Test Version
+ DWORD aVersion = TEST_VERSION;
+ aSize = sizeof(aVersion);
+ aType = REG_DWORD;
+ RegSetValueExA(mRegKey, "Version", 0, aType, (uchar*) &aVersion, aSize);
+
+ // Write Min Vid Memory
+ DWORD aMinVidMemory = mMinVidMemory;
+ aSize = sizeof(aMinVidMemory);
+ aType = REG_DWORD;
+ RegSetValueExA(mRegKey, "MinVidMemory", 0, aType, (uchar*) &aMinVidMemory, aSize);
+
+ // Write Recommended Vid Memory
+ DWORD aRecVidMemory = mRecommendedVidMemory;
+ aSize = sizeof(aRecVidMemory);
+ aType = REG_DWORD;
+ RegSetValueExA(mRegKey, "RecVidMemory", 0, aType, (uchar*) &aRecVidMemory, aSize);
+
+ // Write GUID
+ aSize = sizeof(mDisplayGUID);
+ aType = REG_BINARY;
+ RegSetValueExA(mRegKey, "DisplayGUID", 0, aType, (uchar*) &mDisplayGUID, aSize);
+
+ // Write failure reason
+ aType = REG_SZ;
+ aSize = mFailureReason.length()+1;
+ RegSetValueExA(mRegKey, "FailureReason", 0, aType, (uchar*) mFailureReason.c_str(), aSize);
+
+ // Write warining
+ aType = REG_SZ;
+ aSize = mWarning.length()+1;
+ RegSetValueExA(mRegKey, "Warning", 0, aType, (uchar*) mWarning.c_str(), aSize);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::FileContains(FILE* theFile, const char* theString)
+{
+ bool found = false;
+ char aBuf[4096];
+ while (!feof(theFile))
+ {
+ if (fgets(aBuf,4000,theFile)==NULL)
+ break;
+
+ std::string aStr = Trim(aBuf);
+ if (!aStr.empty() && StrFindNoCase(theString,aStr.c_str()) >= 0)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ return found;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::IsSupportedCard(const char *theDisplayDesc)
+{
+ // Look for 'bad' exception list
+ FILE* aFile = fopen("vhwb.dat","r");
+ if (aFile != NULL)
+ {
+ bool found = FileContains(aFile, theDisplayDesc);
+ fclose(aFile);
+ if (found)
+ return false;
+ }
+
+ // Look for 'good' supported list
+ aFile = fopen("vhw.dat","r");
+ if (aFile==NULL) // default checks
+ {
+ if (mDriverYear>=2002)
+ return true;
+
+ if (StrFindNoCase(theDisplayDesc,"nvidia") >= 0)
+ return true;
+
+ if (StrFindNoCase(theDisplayDesc,"radeon") >= 0)
+ return true;
+
+ if (StrFindNoCase(theDisplayDesc,"ati ") >= 0)
+ return true;
+
+ return false;
+ }
+
+ bool found = FileContains(aFile, theDisplayDesc);
+ fclose(aFile);
+ return found;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::Init(HWND theHWND, LPDIRECTDRAW7 theDDraw)
+{
+ Cleanup();
+ mDriverYear = 0;
+
+ if (mCheckRegistry)
+ {
+ std::string aKey = RemoveTrailingSlash("SOFTWARE\\" + gSexyAppBase->mRegKey) + "\\Test3D";
+ RegCreateKeyExA(HKEY_CURRENT_USER, aKey.c_str(),0,"",REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&mRegKey,NULL);
+ }
+
+ try
+ {
+
+ if (theDDraw==NULL)
+ {
+ extern HMODULE gDDrawDLL;
+
+ typedef HRESULT (WINAPI *DirectDrawCreateExFunc)(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter);
+ DirectDrawCreateExFunc aDirectDrawCreateExFunc = (DirectDrawCreateExFunc)GetProcAddress(gDDrawDLL,"DirectDrawCreateEx");
+ if (aDirectDrawCreateExFunc == NULL)
+ return Fail("No DirectDrawCreateEx");
+
+ CheckDXError(aDirectDrawCreateExFunc(NULL, (LPVOID*)&mDD7, IID_IDirectDraw7, NULL),"DirectDrawCreateEx");
+ }
+ else
+ {
+ theDDraw->AddRef();
+ mDD7 = theDDraw;
+ }
+
+ if (!GetD3D8AdapterInfo(mDisplayGUID,mDisplayDriver,mDisplayDescription))
+ {
+ // Get Device GUID
+ DDDEVICEIDENTIFIER2 aDeviceInfo;
+ CheckDXError(mDD7->GetDeviceIdentifier(&aDeviceInfo,0), "GetDeviceIdentifier");
+ mDisplayGUID = aDeviceInfo.guidDeviceIdentifier;
+ mDisplayDriver = aDeviceInfo.szDriver;
+ mDisplayDescription = aDeviceInfo.szDescription;
+ }
+
+ // Test Video Memory
+ DWORD dwTotal, dwFree;
+ DDSCAPS2 ddsCaps;
+ ZeroMemory(&ddsCaps,sizeof(ddsCaps));
+ ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
+
+ HDC aDC = GetDC(NULL);
+ int aWidth = GetDeviceCaps(aDC, HORZRES);
+ int aHeight = GetDeviceCaps(aDC, VERTRES);
+ int aBPP = GetDeviceCaps( aDC, BITSPIXEL );
+ ReleaseDC(NULL, aDC);
+
+ HRESULT aResult = mDD7->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree);
+ if (!SUCCEEDED(aResult))
+ {
+ Warn(StrFormat("GetAvailableVidMem failed: %s",GetDirectXErrorString(aResult).c_str()));
+ }
+ else
+ {
+ dwTotal += (aBPP/8)*aWidth*aHeight;
+ dwTotal /= (1024*1024);
+ if (dwTotal < mMinVidMemory)
+ return Fail("Not enough video memory.");
+ else if (dwTotal < mRecommendedVidMemory)
+ Warn("Low video memory.");
+ }
+
+ // Check registry to see if we've already done the test
+ if (mCheckRegistry)
+ {
+ if (CheckRegistry())
+ return false;
+
+ mShouldWriteToRegistry = true;
+ }
+
+ mFailureReason = "";
+ mWarning = "";
+
+ // Get date on driver dll
+ std::string aPath = mDisplayDriver;
+ if (aPath.find_first_of("/\\")==std::string::npos)
+ {
+ char aBuf[_MAX_PATH+1];
+ if (GetSystemDirectoryA(aBuf,sizeof(aBuf)-1))
+ aPath = AddTrailingSlash(aBuf,true) + aPath;
+ }
+
+ FILETIME aFileTime;
+ memset(&aFileTime, 0, sizeof(aFileTime));
+ HANDLE aFileHandle = CreateFileA(aPath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (aFileHandle != INVALID_HANDLE_VALUE)
+ {
+ SYSTEMTIME aSystemTime;
+ if (GetFileTime(aFileHandle, NULL, NULL, &aFileTime) && FileTimeToSystemTime(&aFileTime,&aSystemTime))
+ mDriverYear = aSystemTime.wYear;
+
+ CloseHandle(aFileHandle);
+ }
+
+ // Check supported cards
+ if (!IsSupportedCard(mDisplayDescription.c_str()))
+ Warn(StrFormat("Unsupported video card: %s",mDisplayDescription.c_str()));
+
+ // Get Direct3D7 to test 3d capabilities
+ CheckDXError(mDD7->QueryInterface(IID_IDirect3D7, (LPVOID*)&mD3D7),"QueryInterface IID_IDirect3D7");
+
+ CheckDXError(mDD7->SetCooperativeLevel(theHWND, DDSCL_NORMAL),"SetCooperativeLevel");
+
+ // Create Primary Surface for test rendering
+ DDSURFACEDESC2 ddsd;
+ ZeroMemory(&ddsd, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+ ddsd.dwWidth = 100;
+ ddsd.dwHeight = 100;
+ CheckDXError(mDD7->CreateSurface(&ddsd, &mPrimarySurface, NULL),"CreateSurface (Primary)");
+ mTestImage.Create(ddsd.dwWidth,ddsd.dwHeight);
+
+
+ CheckDXError(mD3D7->CreateDevice(IID_IDirect3DHALDevice, mPrimarySurface, &mD3DDevice7),"CreateDevice");
+
+ DWORD aFormat = 0;
+ CheckDXError(mD3DDevice7->EnumTextureFormats(PixelFormatsCallback,&aFormat),"EnumTextureFormats");
+ if (!(aFormat & PixelFormat_A8R8G8B8))
+ {
+ Warn("A8R8G8B8 texture format not supported.");
+ if (!(aFormat & PixelFormat_A4R4G4B4))
+ return Fail("A4R4G4B4 and A8R8G8B8 texture formats not supported.");
+
+ gD3DTestHas32BitTexture = false;
+ }
+ else
+ gD3DTestHas32BitTexture = true;
+
+ // Create Texture Surface
+ DDSURFACEDESC2 aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
+ aDesc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
+
+ aDesc.dwWidth = 64;
+ aDesc.dwHeight = 64;
+
+ aDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+ aDesc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
+
+ if (gD3DTestHas32BitTexture)
+ {
+ aDesc.ddpfPixelFormat.dwRGBBitCount = 32;
+ aDesc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xFF000000;
+ aDesc.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
+ aDesc.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
+ aDesc.ddpfPixelFormat.dwBBitMask = 0x000000FF;
+ }
+ else
+ {
+ aDesc.ddpfPixelFormat.dwRGBBitCount = 16;
+ aDesc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xF000;
+ aDesc.ddpfPixelFormat.dwRBitMask = 0x0F00;
+ aDesc.ddpfPixelFormat.dwGBitMask = 0x00F0;
+ aDesc.ddpfPixelFormat.dwBBitMask = 0x000F;
+ }
+
+ CheckDXError(mDD7->CreateSurface(&aDesc, &mTextureSurface, NULL), "CreateSurface (TextureSurface1)");
+ CheckDXError(mDD7->CreateSurface(&aDesc, &mTextureSurface2, NULL), "CreateSurface (TextureSurfacd2)");
+ }
+ catch(TestException &ex)
+ {
+ return Fail(ex.mMsg);
+ }
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+HRESULT CALLBACK D3DTester::PixelFormatsCallback(LPDDPIXELFORMAT theFormat, LPVOID lpContext)
+{
+ *((DWORD*)lpContext) |= D3DInterface::GetDDPixelFormat(theFormat);
+
+ return D3DENUMRET_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::Cleanup()
+{
+ if (mDD7)
+ {
+ mDD7->Release();
+ mDD7 = NULL;
+ }
+
+ if (mD3D7)
+ {
+ mD3D7->Release();
+ mD3D7 = NULL;
+ }
+
+ if (mD3DDevice7)
+ {
+ mD3DDevice7->Release();
+ mD3DDevice7 = NULL;
+ }
+
+ if (mPrimarySurface)
+ {
+ mPrimarySurface->Release();
+ mPrimarySurface = NULL;
+ }
+
+ if (mTextureSurface)
+ {
+ mTextureSurface->Release();
+ mTextureSurface = NULL;
+ }
+
+ if (mTextureSurface2)
+ {
+ mTextureSurface2->Release();
+ mTextureSurface2 = NULL;
+ }
+
+ if (mRegKey)
+ {
+ RegCloseKey(mRegKey);
+ mRegKey = NULL;
+ }
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::Fail(const std::string &theStr)
+{
+ mFailureReason = theStr;
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::Warn(const std::string &theStr)
+{
+ mWarning = theStr;
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::CheckDXError(HRESULT theResult, const char *theMsg)
+{
+ if (FAILED(theResult))
+ {
+ std::string aMsg = "DXError - ";
+ aMsg += theMsg;
+ aMsg += ": ";
+ aMsg += GetDirectXErrorString(theResult);
+
+ throw TestException(aMsg);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::CopyPrimaryToTestImage()
+{
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ DDSURFACEDESC2 aDesc;
+ memset(&aDesc, 0, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+
+ D3DTester::CheckDXError(mPrimarySurface->Lock(NULL,&aDesc,DDLOCK_WAIT,NULL),"CopyPrimary Lock");
+
+ if(aDesc.ddpfPixelFormat.dwRGBBitCount==32)
+ D3DTestPixelConvert<DWORD>(mTestImage,aDesc,0);
+ else if(aDesc.ddpfPixelFormat.dwRGBBitCount==16)
+ D3DTestPixelConvert<unsigned short>(mTestImage,aDesc,0);
+ else if(aDesc.ddpfPixelFormat.dwRGBBitCount==24)
+ throw TestException("Can't test 24-bit mode.");
+// D3DTestPixelConvert24(mTestImage,aDesc);
+ else
+ {
+ mPrimarySurface->Unlock(NULL);
+ throw TestException("Invalid Color Depth");
+ }
+
+ mPrimarySurface->Unlock(NULL);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::TestAlphaBlend()
+{
+ try
+ {
+ CheckDXError(mD3DDevice7->BeginScene());
+ CheckDXError(mD3DDevice7->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L),"Clear");
+
+ SafeSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
+ SafeSetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ D3DTestImage anImage(64,64);
+
+ anImage.FillRect(0,0,64,64,0xFF0000FF);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ anImage.FillRect(0,0,64,64,0x80FF0000);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ mD3DDevice7->EndScene();
+
+ CopyPrimaryToTestImage();
+ }
+ catch(TestException &ex)
+ {
+ mD3DDevice7->EndScene();
+ return Fail(ex.mMsg);
+ }
+
+ int aNumErrors = 0;
+ bool isUniform = mTestImage.IsUniformColor(0x7f007f,aNumErrors,10,10);
+ if (aNumErrors==0)
+ {
+ if (isUniform)
+ return true;
+ else
+ return Warn("Alpha blend test not uniform.");
+ }
+ else
+ return Fail("Alpha blend Not Supported");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::TestAdditiveBlend()
+{
+ try
+ {
+ CheckDXError(mD3DDevice7->BeginScene());
+ CheckDXError(mD3DDevice7->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L),"Clear");
+
+ SafeSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
+ SafeSetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+ SafeSetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
+ SafeSetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ D3DTestImage anImage(64,64);
+
+ anImage.FillRect(0,0,64,64,0xFF404040);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ anImage.FillRect(0,0,64,64,0xFF404040);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ mD3DDevice7->EndScene();
+
+ CopyPrimaryToTestImage();
+ }
+ catch(TestException &ex)
+ {
+ mD3DDevice7->EndScene();
+ return Fail(ex.mMsg);
+ }
+
+ int aNumErrors = 0;
+ bool isUniform = mTestImage.IsUniformColor(0x808080,aNumErrors,10,10);
+ if(aNumErrors==0)
+ {
+ if (isUniform)
+ return true;
+ else
+ return Warn("Additive blend test not uniform.");
+ }
+ else
+ return Fail("Additive blend not supported.");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::TestAlphaAddBlend()
+{
+ try
+ {
+ CheckDXError(mD3DDevice7->BeginScene());
+ CheckDXError(mD3DDevice7->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L),"Clear");
+
+ SafeSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
+ SafeSetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
+ SafeSetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ D3DTestImage anImage(64,64);
+
+ anImage.FillRect(0,0,64,64,0xFF404040);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ anImage.FillRect(0,0,64,64,0x80808080);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ mD3DDevice7->EndScene();
+
+ CopyPrimaryToTestImage();
+ }
+ catch(TestException &ex)
+ {
+ mD3DDevice7->EndScene();
+ return Fail(ex.mMsg);
+ }
+
+ int aNumErrors = 0;
+ bool isUniform = mTestImage.IsUniformColor(0x808080,aNumErrors,10,10);
+ if(aNumErrors==0)
+ {
+ if (isUniform)
+ return true;
+ else
+ return Warn("AlphaAdd blend test not uniform.");
+ }
+ else
+ return Fail("AlphaAdd blend not supported.");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::TestAlphaModulate()
+{
+ try
+ {
+ CheckDXError(mD3DDevice7->BeginScene());
+ CheckDXError(mD3DDevice7->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L),"Clear");
+
+ SafeSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
+ SafeSetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ SafeSetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_MODULATE);
+
+ D3DTestImage anImage(64,64);
+
+ anImage.FillRect(0,0,64,64,0xFF0000FF);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0);
+
+ anImage.FillRect(0,0,64,64,0xFFFF0000);
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, 0, 0, 0x80FFFFFF);
+
+ mD3DDevice7->EndScene();
+
+ CopyPrimaryToTestImage();
+ }
+ catch(TestException &ex)
+ {
+ mD3DDevice7->EndScene();
+ return Fail(ex.mMsg);
+ }
+
+ int aNumErrors = 0;
+ bool isUniform = mTestImage.IsUniformColor(0x7f007f,aNumErrors,10,10);
+ if(aNumErrors==0)
+ {
+ if (isUniform)
+ return true;
+ else
+ return Warn("AlphaModulated blend test not uniform.");
+ }
+ else
+ return Fail("AlphaModulated blend not supported.");
+}
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::TestClipProblem()
+{
+ try
+ {
+ CheckDXError(mD3DDevice7->BeginScene());
+ CheckDXError(mD3DDevice7->Clear(0, NULL, D3DCLEAR_TARGET ,0xff000000, 1.0f, 0L),"Clear");
+
+ SafeSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
+ SafeSetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ SafeSetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+ D3DTestImage anImage(64,64);
+ anImage.MakeVerticalBands();
+ anImage.DrawToDevice(mD3DDevice7, mTextureSurface, -2, -2);
+
+ mD3DDevice7->EndScene();
+
+ CopyPrimaryToTestImage();
+ }
+ catch(TestException &ex)
+ {
+ mD3DDevice7->EndScene();
+ return Fail(ex.mMsg);
+ }
+
+ int aNumErrors = mTestImage.CheckUniformBands(62,62);
+ if (aNumErrors==0)
+ return true;
+ else
+ return Warn("Clip problem detected.");
+}
+
+#undef SafeSetRenderState
+#undef SafeSetTextureStageState
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool D3DTester::DoTest()
+{
+ if (!TestAlphaBlend())
+ return false;
+
+ if (!TestAdditiveBlend())
+ return false;
+
+ if (!TestAlphaAddBlend())
+ return false;
+
+ if (!TestAlphaModulate())
+ return false;
+
+ if (!TestClipProblem())
+ return false;
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::SetVidMemoryConstraints(DWORD theMin, DWORD theRecommended)
+{
+ mMinVidMemory = theMin;
+ mRecommendedVidMemory = theRecommended;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void D3DTester::TestD3D(HWND theHWND, LPDIRECTDRAW7 theDDraw)
+{
+ if (!gSexyAppBase->mPlayingDemoBuffer)
+ {
+ mShouldWriteToRegistry = false;
+ if (Init(theHWND, theDDraw))
+ {
+ DoTest();
+ }
+ else
+ {
+ if ((mCheckRegistry) && (!mShouldWriteToRegistry))
+ {
+ mResultsChanged = RegQueryValueExA(mRegKey, "FailureReason", 0, NULL, NULL, NULL) != ERROR_SUCCESS;
+ mShouldWriteToRegistry = true;
+ }
+ }
+
+ if (mShouldWriteToRegistry)
+ WriteToRegistry();
+
+ Cleanup();
+ }
+
+ gSexyAppBase->DemoSyncString(&mFailureReason);
+ gSexyAppBase->DemoSyncString(&mWarning);
+ gSexyAppBase->DemoSyncBool(&mResultsChanged);
+}
+
+
diff --git a/osframework/source/SexyAppFramework/D3DTester.h b/osframework/source/SexyAppFramework/D3DTester.h
new file mode 100644
index 0000000..e3dfff1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/D3DTester.h
@@ -0,0 +1,129 @@
+#ifndef __D3DTESTER_H__
+#define __D3DTESTER_H__
+#include <d3d.h>
+#include <exception>
+#include <string>
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class D3DTestImage
+{
+protected:
+ DWORD *mBits;
+ int mWidth;
+ int mHeight;
+
+ void FreeImage();
+
+public:
+ D3DTestImage();
+ D3DTestImage(int theWidth, int theHeight);
+ virtual ~D3DTestImage();
+
+ void Create(int theWidth, int theHeight);
+
+ const D3DTestImage& operator=(const D3DTestImage &theImage);
+
+ void MakeVerticalBands();
+ void FillRect(int x, int y, int theWidth, int theHeight, DWORD theColor);
+ void CopyToTexture8888(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight);
+ void CopyToTexture4444(LPDIRECTDRAWSURFACE7 theTexture, int offx, int offy, int texWidth, int texHeight);
+ void DrawPieceToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, float x, float y, int offx, int offy, int texWidth, int texHeight, DWORD theColor);
+ void DrawToDevice(LPDIRECT3DDEVICE7 theDevice, LPDIRECTDRAWSURFACE7 theTexture, int x, int y, DWORD theColor = 0xffffffff);
+ bool CompareEqual(const D3DTestImage &theImage) const;
+
+ DWORD* GetBits() { return mBits; }
+ const DWORD* GetBits() const { return mBits; }
+
+ int GetWidth() const { return mWidth; }
+ int GetHeight() const { return mHeight; }
+
+ enum { COLOR_TOLERANCE = 16*16*3 };
+ static int ColorDistance(DWORD c1, DWORD c2);
+ bool IsUniformColor(DWORD theColor, int &theNumMistakes, int testWidth, int testHeight) const;
+ int CheckUniformBands(int testWidth, int testHeight, int xoff = 0, int yoff = 0);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class D3DTester
+{
+protected:
+ LPDIRECTDRAW7 mDD7;
+ LPDIRECTDRAWSURFACE7 mPrimarySurface;
+ LPDIRECTDRAWSURFACE7 mTextureSurface;
+ LPDIRECTDRAWSURFACE7 mTextureSurface2;
+ LPDIRECT3D7 mD3D7;
+ LPDIRECT3DDEVICE7 mD3DDevice7;
+ HKEY mRegKey;
+ GUID mDisplayGUID;
+ std::string mDisplayDriver;
+ std::string mDisplayDescription;
+
+ enum { TEST_VERSION = 2 };
+
+ D3DTestImage mTestImage;
+
+ struct TestException : public std::exception
+ {
+ std::string mMsg;
+ TestException(const std::string &theMsg) : mMsg(theMsg) { }
+ };
+
+ static HRESULT CALLBACK PixelFormatsCallback(LPDDPIXELFORMAT theFormat, LPVOID lpContext);
+
+ void CopyPrimaryToTestImage();
+ bool TestAlphaBlend();
+ bool TestAdditiveBlend();
+ bool TestAlphaAddBlend();
+ bool TestAlphaModulate();
+ bool TestClipProblem();
+
+ std::string mFailureReason;
+ std::string mWarning;
+
+ DWORD mMinVidMemory;
+ DWORD mRecommendedVidMemory;
+ bool mCheckRegistry;
+ bool mShouldWriteToRegistry;
+ bool mResultsChanged;
+ int mDriverYear;
+
+ bool Fail(const std::string &theStr);
+ bool Warn(const std::string &theStr);
+
+ bool Init(HWND theHWND, LPDIRECTDRAW7 theDDraw);
+ bool FileContains(FILE* theFile, const char* theString);
+ bool IsSupportedCard(const char *theDisplayDesc);
+ void Cleanup();
+ bool DoTest();
+
+ bool CheckRegistry();
+ void WriteToRegistry();
+
+public:
+ D3DTester();
+ virtual ~D3DTester();
+
+ static void CheckDXError(HRESULT theResult, const char *theMsg = "");
+
+ bool HadWarning() { return !mWarning.empty(); }
+ bool HadError() { return !mFailureReason.empty(); }
+ bool Is3DSupported() { return !HadError(); }
+ bool Is3DRecommended() { return !HadError() && !HadWarning(); }
+ std::string GetWarning() { return mWarning; }
+ std::string GetError() { return mFailureReason; }
+ bool ResultsChanged() { return mResultsChanged; }
+
+ void SetVidMemoryConstraints(DWORD theMin, DWORD theRecommended);
+
+ void TestD3D(HWND theHWND, LPDIRECTDRAW7 theDDraw);
+};
+
+} // namespace Sexy
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_Additive.inc b/osframework/source/SexyAppFramework/DDI_Additive.inc
new file mode 100644
index 0000000..51c5390
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_Additive.inc
@@ -0,0 +1,265 @@
+{
+ aMemoryImage->CommitBits();
+
+ RECT aDestRect = {theX, theY, theX + theSrcRect.mWidth, theY + theSrcRect.mHeight};
+ RECT aSrcRect = {theSrcRect.mX, theSrcRect.mY, theSrcRect.mX + theSrcRect.mWidth, theSrcRect.mY + theSrcRect.mHeight};
+
+ if (!LockSurface())
+ return;
+
+ uchar* aSrcRLAdditiveData = aMemoryImage->GetRLAdditiveData(mDDInterface);
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/2) + theX;
+
+ uchar* aRLAdditiveDataRow = aSrcRLAdditiveData + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ int aMaxR = (1<<mDDInterface->mRedBits) - 1;
+ int aMaxG = (1<<mDDInterface->mGreenBits) - 1;
+ int aMaxB = (1<<mDDInterface->mBlueBits) - 1;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ if (theColor == Color::White)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAdditiveData = aRLAdditiveDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAdditiveData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ if ((src & 0xFFFFFF) == 0) // A run of black
+ {
+ aSrcPixels += rl;
+ aDestPixels _PLUSEQUALS rl;
+ }
+ else
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) + (src & aRMask)) >> aRedShift];
+ int g = aMaxGreenTable[((dest & aGMask) + (src & aGMask)) >> aGreenShift];
+ int b = aMaxBlueTable[((dest & aBMask) + (src & aBMask)) >> aBlueShift];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ }
+
+ aRLAdditiveData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAdditiveDataRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAdditiveData = aRLAdditiveDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAdditiveData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ if ((src & 0xFFFFFF) == 0) // A run of black
+ {
+ aSrcPixels += rl;
+ aDestPixels _PLUSEQUALS rl;
+ }
+ else
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + ((((src & aRMask) >> aRedShift) * cr) >> 8)];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + ((((src & aGMask) >> aGreenShift) * cg) >> 8)];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + ((((src & aBMask) >> aBlueShift) * cb) >> 8)];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ }
+
+ aRLAdditiveData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAdditiveDataRow += theImage->mWidth;
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/4) + theX;
+ uchar* aRLAdditiveDataRow = aSrcRLAdditiveData + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ int aMaxR = (1<<mDDInterface->mRedBits) - 1;
+ int aMaxG = (1<<mDDInterface->mGreenBits) - 1;
+ int aMaxB = (1<<mDDInterface->mBlueBits) - 1;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ if (theColor == Color::White)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ uchar* aRLAdditiveData = aRLAdditiveDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAdditiveData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ if ((src & 0xFFFFFF) == 0) // A run of black
+ {
+ aSrcPixels += rl;
+ aDestPixels _PLUSEQUALS rl;
+ }
+ else
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) + (src & aRMask)) >> aRedShift];
+ int g = aMaxGreenTable[((dest & aGMask) + (src & aGMask)) >> aGreenShift];
+ int b = aMaxBlueTable[((dest & aBMask) + (src & aBMask)) >> aBlueShift];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ }
+
+ aRLAdditiveData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAdditiveDataRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ uchar* aRLAdditiveData = aRLAdditiveDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAdditiveData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ if ((src & 0xFFFFFF) == 0) // A run of black
+ {
+ aSrcPixels += rl;
+ aDestPixels _PLUSEQUALS rl;
+ }
+ else
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + ((((src & aRMask) >> aRedShift) * cr) >> 8)];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + ((((src & aGMask) >> aGreenShift) * cg) >> 8)];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + ((((src & aBMask) >> aBlueShift) * cb) >> 8)];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ }
+
+ aRLAdditiveData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAdditiveDataRow += theImage->mWidth;
+ }
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_AlphaBlt.inc b/osframework/source/SexyAppFramework/DDI_AlphaBlt.inc
new file mode 100644
index 0000000..165c667
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_AlphaBlt.inc
@@ -0,0 +1,616 @@
+if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+{
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/2) + theX;
+ uchar* aRLAlphaDataRow = aSrcRLAlphaData + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (theColor == Color::White)
+ {
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ if (aGMask == 0x7E0) // 5-6-5 optimizations
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int oma = 256 - (src >> 24);
+
+ if (oma == 1) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ *aDestPixels _PLUSPLUS = NEXT_SRC_COLOR;
+ }
+ else
+ if (oma == 256) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ oma >>= 3;
+ aSrcPixels++;
+ ulong dest = (((*aDestPixels | (*aDestPixels << 16)) & 0x7E0F81F) * oma >> 5) & 0x7E0F81F;
+ *(aDestPixels _PLUSPLUS) = src + (dest | (dest >> 16));
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int oma = (256 - (src >> 24)) >> 3;
+ ulong dest = (((*aDestPixels | (*aDestPixels << 16)) & 0x7E0F81F) * oma >> 5) & 0x7E0F81F;
+ *(aDestPixels _PLUSPLUS) = src + (dest | (dest >> 16));
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ else if (aGMask == 0x3E0) // 5-5-5 optimizations
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int oma = 256 - (src >> 24);
+
+ if (oma == 1) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ *aDestPixels _PLUSPLUS = NEXT_SRC_COLOR;
+ }
+ else
+ if (oma == 256) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ oma >>= 3;
+ aSrcPixels++;
+ ulong dest = (((*aDestPixels | (*aDestPixels << 16)) & 0x3E07C1F) * oma >> 5) & 0x3E07C1F;
+ *(aDestPixels _PLUSPLUS) = src + (dest | (dest >> 16));
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int oma = (256 - (src >> 24)) >> 3;
+ ulong dest = (((*aDestPixels | (*aDestPixels << 16)) & 0x3E07C1F) * oma >> 5) & 0x3E07C1F;
+ *(aDestPixels _PLUSPLUS) = src + (dest | (dest >> 16));
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ else
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int oma = 256 - (src >> 24);
+
+ if (oma == 1) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ *aDestPixels _PLUSPLUS = NEXT_SRC_COLOR;
+ }
+ else if (oma == 256) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ aSrcPixels++;
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) = src +
+ (((((dest & aRMask) * oma) ) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) ) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) ) >> 8) & aBMask);
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int oma = 256 - (src >> 24);
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) = src +
+ (((((dest & aRMask) * oma) ) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) ) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) ) >> 8) & aBMask);
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ bool performNormalBlit = true;
+ if (cr == cg && cg == cb)
+ {
+ if (aGMask == 0x7E0)
+ {
+ performNormalBlit = false;
+ cr >>= 3;
+
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int a = src >> 24;
+
+ if ((a == 255) && (ca == 255)) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = (((( (src & 0xFFFF) | (src << 16)) & 0x7E0F81F) * cr) >> 5) & 0x7E0F81F;
+ *(aDestPixels _PLUSPLUS) = dest | (dest >> 16);
+ }
+ }
+ else if (a == 0) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+
+ a = ((src >> 24) * ca) / 255;
+ int oma = (256 - a) >> 3;
+
+ ulong dest = (*aDestPixels | (*aDestPixels << 16)) & 0x7E0F81F;
+ src &= 0xFFFF;
+ src = ( (src & 0xFFFF) | (src << 16)) & 0x7E0F81F;
+ dest = ((dest * oma + src * cr) >> 5) & 0x7E0F81F;
+ *(aDestPixels _PLUSPLUS) = dest | (dest >> 16);
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ else if (aGMask == 0x3E0)
+ {
+ performNormalBlit = false;
+ cr >>= 3;
+
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int a = src >> 24;
+
+ if ((a == 255) && (ca == 255)) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = (((( (src & 0xFFFF) | (src << 16)) & 0x3E07C1F) * cr) >> 5) & 0x3E07C1F;
+ *(aDestPixels _PLUSPLUS) = dest | (dest >> 16);
+ }
+ }
+ else if (a == 0) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+
+ a = ((src >> 24) * ca) / 255;
+ int oma = (256 - a) >> 3;
+
+ ulong dest = (*aDestPixels | (*aDestPixels << 16)) & 0x3E07C1F;
+ src &= 0xFFFF;
+ src = ( (src & 0xFFFF) | (src << 16)) & 0x3E07C1F;
+ dest = ((dest * oma + src * cr) >> 5) & 0x3E07C1F;
+ *(aDestPixels _PLUSPLUS) = (dest | (dest >> 16));
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ }
+ if (performNormalBlit)
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int a = src >> 24;
+
+ if ((a == 255) && (ca == 255)) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ *(aDestPixels _PLUSPLUS) =
+ (((((src & aRMask) * cr) ) >> 8) & aRMask) +
+ (((((src & aGMask) * cg) ) >> 8) & aGMask) +
+ (((((src & aBMask) * cb) ) >> 8) & aBMask);
+ }
+ }
+ else if (a == 0) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+
+ a = ((src >> 24) * ca) / 255;
+ int oma = 256 - a;
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) =
+ (((((dest & aRMask) * oma) + ((src & aRMask) * cr) ) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + ((src & aGMask) * cg) ) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + ((src & aBMask) * cb) ) >> 8) & aBMask);
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ }
+}
+else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+{
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/4) + theX;
+ uchar* aRLAlphaDataRow = aSrcRLAlphaData + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (theColor == Color::White)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int oma = 256 - (src >> 24);
+
+ if (oma == 1) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ *aDestPixels _PLUSPLUS = NEXT_SRC_COLOR;
+ }
+ else if (oma == 256) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ aSrcPixels++;
+
+ int oma = 256 - (src >> 24);
+ ulong dest = *aDestPixels;
+
+ *(aDestPixels _PLUSPLUS) = src +
+ ((((dest & 0xFF00FF) * oma) >> 8) & 0xFF00FF) +
+ ((((dest & 0x00FF00) * oma) >> 8) & 0x00FF00);
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int oma = 256 - (src >> 24);
+ ulong dest = *aDestPixels;
+
+ *(aDestPixels _PLUSPLUS) = src +
+ ((((dest & 0xFF00FF) * oma) >> 8) & 0xFF00FF) +
+ ((((dest & 0x00FF00) * oma) >> 8) & 0x00FF00);
+ }
+#else
+ aSrcPixels++;
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) = src +
+ (((((dest & aRMask) * oma)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma)) >> 8) & aBMask);
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int oma = 256 - (src >> 24);
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) = src +
+ (((((dest & aRMask) * oma)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma)) >> 8) & aBMask);
+ }
+#endif
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ bool performNormalBlit = true;
+ if (cr == cg && cg == cb)
+ {
+ performNormalBlit = false;
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int a = src >> 24;
+
+ if ((a == 255) && (ca == 255)) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ *(aDestPixels _PLUSPLUS) =
+ ((((src & 0xFF00FF) * cr) >> 8) & 0xFF00FF) +
+ ((((src & 0x00FF00) * cr) >> 8) & 0x00FF00);
+ }
+ }
+ else if (a == 0) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+
+ a = ((src >> 24) * ca) / 255;
+ int oma = 256 - a;
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) =
+ ((((dest & 0xFF00FF) * oma + (src & 0xFF00FF) * cr) >> 8) & 0xFF00FF) +
+ ((((dest & 0x00FF00) * oma + (src & 0x00FF00) * cr) >> 8) & 0x00FF00);
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ if (performNormalBlit)
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = PEEK_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int a = src >> 24;
+
+ if ((a == 255) && (ca == 255)) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ *(aDestPixels _PLUSPLUS) =
+ (((((src & aRMask) * cr)) >> 8) & aRMask) +
+ (((((src & aGMask) * cg)) >> 8) & aGMask) +
+ (((((src & aBMask) * cb)) >> 8) & aBMask);
+ }
+ }
+ else if (a == 0) // Fully transparent
+ {
+ aDestPixels _PLUSEQUALS rl;
+ aSrcPixels += rl;
+ }
+ else // Partially transparent
+ {
+ for (int i = 0; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+
+ a = ((src >> 24) * ca) / 255;
+ int oma = 256 - a;
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels _PLUSPLUS) =
+ (((((dest & aRMask) * oma) + ((src & aRMask) * cr)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + ((src & aGMask) * cg)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + ((src & aBMask) * cb)) >> 8) & aBMask);
+ }
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_BltRotated.inc b/osframework/source/SexyAppFramework/DDI_BltRotated.inc
new file mode 100644
index 0000000..b8e1cb9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_BltRotated.inc
@@ -0,0 +1,217 @@
+{
+ double aCos = cos(theRot);
+ double aSin = sin(theRot);
+
+ int aCosLong = (int) (aCos * 0x10000);
+ int aSinLong = (int) (aSin * 0x10000);
+
+ if (!LockSurface())
+ return;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int aRedRightShift = 32 - mDDInterface->mRedBits;
+ int aGreenRightShift = 24 - mDDInterface->mGreenBits;
+ int aBlueRightShift = 16 - mDDInterface->mBlueBits;
+
+ int aNumBits = mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int)aDestRect.mY * mLockedSurfaceDesc.lPitch/2) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mLockedSurfaceDesc.lPitch/2;
+
+ if (theColor == Color::White)
+ {
+ #define DEST_PIXEL_TYPE ushort
+ #define WRITE_PIXEL\
+ {\
+ ushort dest = *aDestPixels;\
+ int oma = 256 - (a1 + a2 + a3 + a4);\
+ *(aDestPixels++) = \
+ (((((dest & aBMask) * oma) >> 8) & aBMask) + \
+ (((((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) >> aBlueRightShift) << aBlueShift)) | \
+ (((((dest & aGMask) * oma) >> 8) & aGMask) + \
+ (((((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) >> aGreenRightShift) << aGreenShift)) | \
+ (((((dest & aRMask) * oma) >> 8) & aRMask) + \
+ (((((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> aRedRightShift) << aRedShift)); \
+ }
+ #define WRITE_PIXEL_OPTIMIZED_565\
+ {\
+ ulong dest = (*aDestPixels | (*aDestPixels << 16)) & 0x7E0F81F;\
+ int oma = (256 - (a1 + a2 + a3 + a4)) >> 3;\
+ ulong src_b = ((src1 & 0xFF00FF) * a1 + (src2 & 0xFF00FF) * a2 + (src3 & 0xFF00FF) * a3 + (src4 & 0xFF00FF) * a4) & 0xFF00FF00;\
+ src_b = ((((src1 & 0xFF00) * a1 + (src2 & 0xFF00) * a2 + (src3 & 0xFF00) * a3 + (src4 & 0xFF00) * a4) & 0xFF0000) | src_b) >> 8;\
+ ulong s = ((src_b & 0xfc00) << 11) + (src_b >> 8 & 0xf800) + (src_b >> 3 & 0x1f);\
+ dest = ((dest * oma >> 5) & 0x7E0F81F) + s;\
+ *(aDestPixels++) = dest | (dest >> 16);\
+ }
+ #define WRITE_PIXEL_OPTIMIZED_555\
+ {\
+ ulong dest = (*aDestPixels | (*aDestPixels << 16)) & 0x3E07C1F;\
+ int oma = (256 - (a1 + a2 + a3 + a4)) >> 3;\
+ ulong src_b = ((src1 & 0xFF00FF) * a1 + (src2 & 0xFF00FF) * a2 + (src3 & 0xFF00FF) * a3 + (src4 & 0xFF00FF) * a4) & 0xFF00FF00;\
+ src_b = ((((src1 & 0xFF00) * a1 + (src2 & 0xFF00) * a2 + (src3 & 0xFF00) * a3 + (src4 & 0xFF00) * a4) & 0xFF0000) | src_b) >> 8;\
+ ulong s = ((src_b & 0xf800) << 10) + (src_b >> 9 & 0x7c00) + (src_b >> 3 & 0x1f);\
+ dest = ((dest * oma >> 5) & 0x3E07C1F) + s;\
+ *(aDestPixels++) = dest | (dest >> 16);\
+ }
+ #define WRITE_PIXEL_OPTIMIZED
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+ #undef WRITE_PIXEL_OPTIMIZED
+ #undef WRITE_PIXEL_OPTIMIZED_555
+ #undef WRITE_PIXEL_OPTIMIZED_565
+ }
+ else
+ {
+ // Colorized version
+
+ int ca = theColor.mAlpha;
+ int cr = theColor.mRed + 1;
+ int cg = theColor.mGreen + 1;
+ int cb = theColor.mBlue + 1;
+
+ #define DEST_PIXEL_TYPE ushort
+ #define WRITE_PIXEL\
+ {\
+ ushort dest = *aDestPixels;\
+ a1 = (a1*ca)>>8; a2 = (a2*ca)>>8; a3 = (a3*ca)>>8; a4 = (a4*ca)>>8; \
+ int oma = 256 - (a1 + a2 + a3 + a4); \
+ *(aDestPixels++) = \
+ ( ((((dest & aBMask) * oma) >> 8) & aBMask) + \
+ (((( (((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) >> 8) * cb) >> aBlueRightShift) << aBlueShift) ) | \
+ ( ((((dest & aGMask) * oma) >> 8) & aGMask) + \
+ (((( (((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) >> 8) * cg) >> aGreenRightShift) << aGreenShift) ) | \
+ ( ((((dest & aRMask) * oma) >> 8) & aRMask) + \
+ (((( (((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> 8) * cr) >> aRedRightShift) << aRedShift) ); \
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int)aDestRect.mY * mLockedSurfaceDesc.lPitch/4) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mLockedSurfaceDesc.lPitch/4;
+
+ if (theColor == Color::White)
+ {
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ ulong dest = *aDestPixels;\
+ int oma = 256 - (a1 + a2 + a3 + a4);\
+ *(aDestPixels++) = \
+ (((((dest & aBMask) * oma) >> 8) & aBMask) + \
+ (((((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) >> aBlueRightShift) << aBlueShift)) | \
+ (((((dest & aGMask) * oma) >> 8) & aGMask) + \
+ (((((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) >> aGreenRightShift) << aGreenShift)) | \
+ (((((dest & aRMask) * oma) >> 8) & aRMask) + \
+ (((((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> aRedRightShift) << aRedShift));\
+ }
+ #define WRITE_PIXEL_OPTIMIZED\
+ {\
+ ulong dest = *aDestPixels;\
+ int oma = 256 - (a1 + a2 + a3 + a4);\
+ ulong src_b = ((src1 & 0xFF00FF) * a1 + (src2 & 0xFF00FF) * a2 + (src3 & 0xFF00FF) * a3 + (src4 & 0xFF00FF) * a4) & 0xFF00FF00;\
+ ulong src_b2 = ((src1 & 0xFF00) * a1 + (src2 & 0xFF00) * a2 + (src3 & 0xFF00) * a3 + (src4 & 0xFF00) * a4) & 0xFF0000;\
+ *(aDestPixels++) =\
+ ((((dest & 0xFF00FF) * oma + src_b) >> 8) & 0xFF00FF) |\
+ ((((dest & 0x00FF00) * oma + src_b2) >> 8) & 0x00FF00);\
+ }
+
+
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef WRITE_PIXEL_OPTIMIZED
+ #undef DEST_PIXEL_TYPE
+ }
+ else
+ {
+ // Colorized version
+
+ int ca = theColor.mAlpha;
+ int cr = theColor.mRed + 1;
+ int cg = theColor.mGreen + 1;
+ int cb = theColor.mBlue + 1;
+
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ ulong dest = *aDestPixels;\
+ a1 = (a1*ca)>>8; a2 = (a2*ca)>>8; a3 = (a3*ca)>>8; a4 = (a4*ca)>>8; \
+ int oma = 256 - (a1 + a2 + a3 + a4);\
+ *(aDestPixels++) = \
+ ( ((((dest & aBMask) * oma) >> 8) & aBMask) + \
+ (((( (((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) >> 8) * cb) >> aBlueRightShift) << aBlueShift) ) | \
+ ( ((((dest & aGMask) * oma) >> 8) & aGMask) + \
+ (((( (((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) >> 8) * cg) >> aGreenRightShift) << aGreenShift) ) | \
+ ( ((((dest & aRMask) * oma) >> 8) & aRMask) + \
+ (((( (((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> 8) * cr) >> aRedRightShift) << aRedShift) );\
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_BltRotated_Additive.inc b/osframework/source/SexyAppFramework/DDI_BltRotated_Additive.inc
new file mode 100644
index 0000000..012d432
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_BltRotated_Additive.inc
@@ -0,0 +1,138 @@
+{
+ double aCos = cos(theRot);
+ double aSin = sin(theRot);
+
+ int aCosLong = (int) (aCos * 0x10000);
+ int aSinLong = (int) (aSin * 0x10000);
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ int aRotCenterXLong = (int)(theRotCenterX * 0x10000);
+ int aRotCenterYLong = (int)(theRotCenterY * 0x10000);
+#endif
+
+ if (!LockSurface())
+ return;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int aRedRightShift = 32 - mDDInterface->mRedBits;
+ int aGreenRightShift = 24 - mDDInterface->mGreenBits;
+ int aBlueRightShift = 16 - mDDInterface->mBlueBits;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int)aDestRect.mY * mLockedSurfaceDesc.lPitch/2) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mLockedSurfaceDesc.lPitch/2;
+
+ //TODO: if (theColor == Color::White)
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ #define DEST_PIXEL_TYPE ushort
+ #define WRITE_PIXEL\
+ {\
+ ushort dest = *aDestPixels;\
+ \
+ int r = aMaxRedTable[((dest & aRMask)>>aRedShift) + \
+ ((((((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> aRedRightShift) * cr) >> 8)];\
+ int g = aMaxGreenTable[((dest & aGMask)>>aGreenShift) + \
+ (((((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) * cg) >> (aGreenRightShift + 8))];\
+ int b = aMaxBlueTable[((dest & aBMask)>>aBlueShift) + \
+ (((((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) * cb) >> (aBlueRightShift + 8))];\
+ \
+ *(aDestPixels++) = \
+ (r << aRedShift) | \
+ (g << aGreenShift) | \
+ (b << aBlueShift); \
+ }
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+ }
+ /*else
+ {
+
+ }*/
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int)aDestRect.mY * mLockedSurfaceDesc.lPitch/4) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mLockedSurfaceDesc.lPitch/4;
+
+ //if (theColor == Color::White)
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ ulong dest = *aDestPixels;\
+ \
+ int r = aMaxRedTable[((dest & aRMask)>>aRedShift) + \
+ ((((((src1 & 0xFF0000) * a1) + \
+ ((src2 & 0xFF0000) * a2) + \
+ ((src3 & 0xFF0000) * a3) + \
+ ((src4 & 0xFF0000) * a4)) >> aRedRightShift) * cr) >> 8)];\
+ int g = aMaxGreenTable[((dest & aGMask)>>aGreenShift) + \
+ (((((src1 & 0x00FF00) * a1) + \
+ ((src2 & 0x00FF00) * a2) + \
+ ((src3 & 0x00FF00) * a3) + \
+ ((src4 & 0x00FF00) * a4)) * cg) >> (aGreenRightShift + 8))];\
+ int b = aMaxBlueTable[((dest & aBMask)>>aBlueShift) + \
+ (((((src1 & 0x0000FF) * a1) + \
+ ((src2 & 0x0000FF) * a2) + \
+ ((src3 & 0x0000FF) * a3) + \
+ ((src4 & 0x0000FF) * a4)) * cb) >> (aBlueRightShift + 8))];\
+ \
+ *(aDestPixels++) = \
+ (r << aRedShift) | \
+ (g << aGreenShift) | \
+ (b << aBlueShift);\
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+
+
+ }
+ /*else
+ {
+
+ }*/
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_FastBlt_NoAlpha.inc b/osframework/source/SexyAppFramework/DDI_FastBlt_NoAlpha.inc
new file mode 100644
index 0000000..22fde4b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_FastBlt_NoAlpha.inc
@@ -0,0 +1,92 @@
+{
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/2) + theX;
+
+ if (aMemoryImage->mHasTrans)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong aSrc = NEXT_SRC_COLOR;
+
+ if (aSrc>>24 != 0)
+ *(aDestPixels++) = (ushort) aSrc;
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ *(aDestPixels++) = (ushort) NEXT_SRC_COLOR;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/4) + theX;
+
+ if (aMemoryImage->mHasTrans)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong aSrc = NEXT_SRC_COLOR;
+
+ if (aSrc>>24 != 0)
+ *(aDestPixels++) = aSrc;
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ *(aDestPixels++) = NEXT_SRC_COLOR;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_FastStretch.inc b/osframework/source/SexyAppFramework/DDI_FastStretch.inc
new file mode 100644
index 0000000..0f82d2c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_FastStretch.inc
@@ -0,0 +1,206 @@
+{
+ if (!LockSurface())
+ return;
+
+ int aFPSrcY = theSrcRect.mY * 0x10000;
+
+ int anAddX = (theSrcRect.mWidth * 0x10000) / theDestRect.mWidth;
+ int anAddY = (theSrcRect.mHeight * 0x10000) / theDestRect.mHeight;
+
+ if (theColor == Color::White)
+ {
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/2) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++, aFPSrcX += anAddX)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+
+ if (a != 0)
+ {
+ int oma = 256 - a;
+
+ *(aDestPixels _PLUSPLUS) =
+ src +
+ (((((dest & aRMask) * oma)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma)) >> 8) & aBMask);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aFPSrcY += anAddY;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/4) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++, aFPSrcX += anAddX)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+
+ if (a != 0)
+ {
+ int oma = 256 - a;
+
+ *(aDestPixels _PLUSPLUS) =
+ src +
+ (((((dest & aRMask) * oma)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma)) >> 8) & aBMask);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aFPSrcY += anAddY;
+ }
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/2) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++, aFPSrcX += anAddX)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ int a = ((src >> 24) * ca) / 255;
+
+ if (a != 0)
+ {
+ int oma = 256 - a;
+
+ *(aDestPixels _PLUSPLUS) =
+ (((((dest & aRMask) * oma) + ((src & aRMask) * cr)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + ((src & aGMask) * cg)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + ((src & aBMask) * cb)) >> 8) & aBMask);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aFPSrcY += anAddY;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/4) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++, aFPSrcX += anAddX)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ int a = ((src >> 24) * ca) / 255;
+ int oma = 256 - a;
+
+ if (a != 0)
+ {
+ int oma = 256 - a;
+
+ *(aDestPixels _PLUSPLUS) =
+ (((((dest & aRMask) * oma) + ((src & aRMask) * cr)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + ((src & aGMask) * cg)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + ((src & aBMask) * cb)) >> 8) & aBMask);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aFPSrcY += anAddY;
+ }
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_FastStretch_Additive.inc b/osframework/source/SexyAppFramework/DDI_FastStretch_Additive.inc
new file mode 100644
index 0000000..2fb5a47
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_FastStretch_Additive.inc
@@ -0,0 +1,219 @@
+{
+ if (!LockSurface())
+ return;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int aFPSrcY = theSrcRect.mY * 0x10000;
+
+ int anAddX = (theSrcRect.mWidth * 0x10000) / theDestRect.mWidth;
+ int anAddY = (theSrcRect.mHeight * 0x10000) / theDestRect.mHeight;
+
+ if (theColor == Color::White)
+ {
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/2) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ if (src != 0)
+ {
+ int r = aMaxRedTable[((dest & aRMask) + (src & aRMask)) >> aRedShift];
+ int g = aMaxGreenTable[((dest & aGMask) + (src & aGMask)) >> aGreenShift];
+ int b = aMaxBlueTable[((dest & aBMask) + (src & aBMask)) >> aBlueShift];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+
+ aFPSrcX += anAddX;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aFPSrcY += anAddY;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/4) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ if (src != 0)
+ {
+ int r = aMaxRedTable[((dest & aRMask) + (src & aRMask)) >> aRedShift];
+ int g = aMaxGreenTable[((dest & aGMask) + (src & aGMask)) >> aGreenShift];
+ int b = aMaxBlueTable[((dest & aBMask) + (src & aBMask)) >> aBlueShift];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+
+ aFPSrcX += anAddX;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aFPSrcY += anAddY;
+ }
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/2) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ if (src != 0)
+ {
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + ((((src & aRMask) >> aRedShift) * cr) >> 8)];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + ((((src & aGMask) >> aGreenShift) * cg) >> 8)];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + ((((src & aBMask) >> aBlueShift) * cb) >> 8)];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+
+ aFPSrcX += anAddX;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aFPSrcY += anAddY;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theDestRect.mY * mLockedSurfaceDesc.lPitch/4) + theDestRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ int aFPSrcX = theSrcRect.mX * 0x10000;
+
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (aSrcMemoryImage->mWidth * (aFPSrcY >> 16));
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow + (aFPSrcX >> 16);
+
+ ulong src = READ_COLOR(aSrcPixels);
+ ulong dest = *aDestPixels;
+
+ if (src != 0)
+ {
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + ((((src & aRMask) >> aRedShift) * cr) >> 8)];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + ((((src & aGMask) >> aGreenShift) * cg) >> 8)];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + ((((src & aBMask) >> aBlueShift) * cb) >> 8)];
+
+ *(aDestPixels _PLUSPLUS) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+ else
+ aDestPixels _PLUSPLUS;
+
+ aFPSrcX += anAddX;
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aFPSrcY += anAddY;
+ }
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDI_NormalBlt_Volatile.inc b/osframework/source/SexyAppFramework/DDI_NormalBlt_Volatile.inc
new file mode 100644
index 0000000..67e7051
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDI_NormalBlt_Volatile.inc
@@ -0,0 +1,194 @@
+{
+ if (mNoLock)
+ return;
+
+ // Special path that avoids generating cached native alpha data
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/2) + theX;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits +
+ (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ bool performNormalBlit = true;
+ if (gOptimizeSoftwareDrawing) // we know the ordering of the bit masks.
+ {
+ if (aGMask == 0x7E0)
+ {
+ performNormalBlit = false;
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 27;
+ //int oma = 256 - a;
+
+ src = ((src & 0xFC00) << 11) + ((src >> 8) & 0xF800) + ((src >> 3) & 0x1F);
+ dest = (dest | (dest << 16)) & 0x7E0F81F;
+ dest += ((src - dest) * a) >> 5;
+ dest &= 0x7E0F81F;
+ *(aDestPixels++) = dest | (dest >> 16);
+ //(((((dest & aBMask) * oma) + (((src & 0x000000FF) * a * aBMask) >> 8) + aBRoundAdd) >> 8) & aBMask) +
+ //(((((dest & aGMask) * oma) + ((((src & 0x0000FF00) >> 8) * a * aGMask) >> 8) + aGRoundAdd) >> 8) & aGMask) +
+ //(((((dest & aRMask) * oma) + ((((src & 0x00FF0000) >> 16) * a * aRMask) >> 8) + aRRoundAdd) >> 8) & aRMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else if (aGMask == 0x3E0)
+ {
+ performNormalBlit = false;
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 27;
+ //int oma = 256 - a;
+
+ src = ((src & 0xF800) << 10) + ((src >> 9) & 0x7C00) + ((src >> 3) & 0x1F);
+ dest = (dest | (dest << 16)) & 0x3E07C1F;
+ dest += ((src - dest) * a) >> 5; // 1*d - a*d = (1-a)*d = oma*d :)
+ dest &= 0x3E07C1F;
+ *(aDestPixels++) = dest | (dest >> 16);
+ //(((((dest & aBMask) * oma) + (((src & 0x000000FF) * a * aBMask) >> 8) + aBRoundAdd) >> 8) & aBMask) +
+ //(((((dest & aGMask) * oma) + ((((src & 0x0000FF00) >> 8) * a * aGMask) >> 8) + aGRoundAdd) >> 8) & aGMask) +
+ //(((((dest & aRMask) * oma) + ((((src & 0x00FF0000) >> 16) * a * aRMask) >> 8) + aRRoundAdd) >> 8) & aRMask);
+ }
+
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+ if (performNormalBlit)
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+ int oma = 256 - a;
+
+ *(aDestPixels++) =
+ (((((dest & aBMask) * oma) + (((src & 0x000000FF) * a * aBMask) >> 8) + aBRoundAdd) >> 8) & aBMask) +
+ (((((dest & aGMask) * oma) + ((((src & 0x0000FF00) >> 8) * a * aGMask) >> 8) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aRMask) * oma) + ((((src & 0x00FF0000) >> 16) * a * aRMask) >> 8) + aRRoundAdd) >> 8) & aRMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theY * mLockedSurfaceDesc.lPitch/4) + theX;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits +
+ (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ if (gOptimizeSoftwareDrawing)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+ //int oma = 256 - a;
+ ulong srctmp = src & 0xFF00FF;
+ ulong desttmp = dest & 0xFF00FF;
+ desttmp = (desttmp + (((srctmp - desttmp) * a) >> 8)) & 0xFF00FF;
+ src &= 0x00FF00;
+ dest &= 0x00FF00;
+ dest = (dest + (((src - dest) * a) >> 8)) & 0x00FF00;
+
+ *(aDestPixels++) = dest | desttmp;
+ //(((((dest & aBMask) * oma) + ((((src & 0x000000FF) * a) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask) +
+ //(((((dest & aGMask) * oma) + (((((src & 0x0000FF00) >> 8) * a) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ //(((((dest & aRMask) * oma) + (((((src & 0x00FF0000) >> 16) * a) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+ int oma = 256 - a;
+
+ *(aDestPixels++) =
+ (((((dest & aBMask) * oma) + ((((src & 0x000000FF) * a) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask) +
+ (((((dest & aGMask) * oma) + (((((src & 0x0000FF00) >> 8) * a) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aRMask) * oma) + (((((src & 0x00FF0000) >> 16) * a) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+
+ UnlockSurface();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDImage.cpp b/osframework/source/SexyAppFramework/DDImage.cpp
new file mode 100644
index 0000000..cbaafe5
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDImage.cpp
@@ -0,0 +1,3277 @@
+#include "DDImage.h"
+#include <Math.h>
+#include "DDInterface.h"
+#include "D3DInterface.h"
+#include "Rect.h"
+#include "Graphics.h"
+#include "SexyAppBase.h"
+#include "Debug.h"
+#include "PerfTimer.h"
+
+#pragma warning(disable:4005) // macro redefinition
+#pragma warning(disable:4244) // conversion possible loss of data
+
+using namespace Sexy;
+
+extern bool gOptimizeSoftwareDrawing;
+
+DDImage::DDImage(DDInterface* theDDInterface) :
+ MemoryImage(theDDInterface->mApp)
+{
+ mDDInterface = theDDInterface;
+ Init();
+}
+
+DDImage::DDImage() :
+ MemoryImage(gSexyAppBase)
+{
+ mDDInterface = gSexyAppBase->mDDInterface;
+ Init();
+}
+
+DDImage::~DDImage()
+{
+ if (mSurface != NULL)
+ mSurface->Release();
+ mDDInterface->RemoveDDImage(this);
+
+ DBG_ASSERTE(mLockCount == 0);
+}
+
+void DDImage::Init()
+{
+ mSurface = NULL;
+ mDDInterface->AddDDImage(this);
+
+ mNoLock = false;
+ mVideoMemory = false;
+ mFirstPixelTrans = false;
+ mWantDDSurface = false;
+ mDrawToBits = false;
+ mSurfaceSet = false;
+
+ mLockCount = 0;
+}
+
+bool DDImage::Check3D(Image *theImage)
+{
+ DDImage *anImage = dynamic_cast<DDImage*>(theImage);
+ if (anImage!=NULL)
+ return Check3D(anImage);
+ else
+ return false;
+}
+
+bool DDImage::Check3D(DDImage *theImage)
+{
+ return theImage->mDDInterface->mIs3D && theImage->mSurface==theImage->mDDInterface->mDrawSurface;
+}
+
+bool DDImage::LockSurface()
+{
+ if (Check3D(this))
+ return false;
+
+ if (mLockCount == 0)
+ {
+ memset(&mLockedSurfaceDesc, 0, sizeof(mLockedSurfaceDesc));
+ mLockedSurfaceDesc.dwSize = sizeof(mLockedSurfaceDesc);
+ int aResult = GetSurface()->Lock(NULL, &mLockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
+
+ if (aResult != DD_OK)
+ return false;
+ }
+
+ mLockCount++;
+
+ DBG_ASSERTE(mLockCount < 8);
+
+ return true;
+}
+
+bool DDImage::UnlockSurface()
+{
+ if (Check3D(this))
+ return false;
+
+ --mLockCount;
+
+ if (mLockCount == 0)
+ {
+ mSurface->Unlock(NULL);
+ }
+
+ DBG_ASSERTE(mLockCount >= 0);
+
+ return true;
+}
+
+void DDImage::SetSurface(LPDIRECTDRAWSURFACE theSurface)
+{
+ mSurfaceSet = true;
+ mSurface = theSurface;
+ mSurface->AddRef();
+
+// TDDSurfaceDesc aDesc;
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
+ HRESULT aResult = mSurface->GetSurfaceDesc(&aDesc);
+
+ mWidth = aDesc.dwWidth;
+ mHeight = aDesc.dwHeight;
+
+ mNoLock = false;
+}
+
+bool DDImage::GenerateDDSurface()
+{
+ if (mSurface != NULL)
+ return true;
+
+ CommitBits();
+
+ if (mHasAlpha)
+ return false;
+
+ mWantDDSurface = true;
+
+ // Force into non-palletized mode for this
+ if (mColorTable != NULL)
+ GetBits();
+
+ HRESULT aResult;
+// TDDSurfaceDesc aDesc;
+ DDSURFACEDESC2 aDesc;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ aDesc.ddsCaps.dwCaps = mVideoMemory ? DDSCAPS_VIDEOMEMORY : DDSCAPS_SYSTEMMEMORY;
+ aDesc.dwWidth = mWidth;
+ aDesc.dwHeight = mHeight;
+
+ AutoCrit aCrit(mDDInterface->mCritSect); // prevent mSurface from being released while we're in this code
+
+ aResult = mDDInterface->CreateSurface(&aDesc, &mSurface, NULL);
+ if (aResult != DD_OK)
+ return false;
+
+ if (!LockSurface())
+ return false;
+
+ const int rRightShift = 16 + (8-mDDInterface->mRedBits);
+ const int gRightShift = 8 + (8-mDDInterface->mGreenBits);
+ const int bRightShift = 0 + (8-mDDInterface->mBlueBits);
+
+ const int rLeftShift = mDDInterface->mRedShift;
+ const int gLeftShift = mDDInterface->mGreenShift;
+ const int bLeftShift = mDDInterface->mBlueShift;
+
+ const int rMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ const int gMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ const int bMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ int aNumBits = mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount;
+
+ if (aNumBits == 16)
+ {
+ ushort* mSurfaceBits = (ushort*) mLockedSurfaceDesc.lpSurface;
+
+ if (mSurfaceBits != NULL)
+ {
+ int i;
+ bool firstTrans = true;
+
+ ushort* a16Bits = NULL;
+ ushort aTransColor = 0;
+
+ if (mBits != NULL)
+ {
+ a16Bits = new ushort[mWidth*mHeight];
+ ulong* aSrcPtr = mBits;
+ ushort* a16SrcPtr = a16Bits;
+
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ *a16SrcPtr = (((val>>rRightShift)<<rLeftShift)&rMask) |
+ (((val>>gRightShift)<<gLeftShift)&gMask) |
+ (((val>>bRightShift)<<bLeftShift)&bMask);
+
+ int anAlpha = val >> 24;
+ if ((firstTrans) && (anAlpha < 255))
+ {
+ firstTrans = false;
+ aTransColor = *a16SrcPtr;
+ }
+
+ ++a16SrcPtr;
+ }
+ }
+
+ if ((mHasTrans) && (mBits != NULL))
+ {
+ if (mFirstPixelTrans)
+ {
+ aTransColor = *a16Bits;
+
+ if (a16Bits != NULL)
+ {
+ ushort* aDestPtr = mSurfaceBits;
+ ushort* a16SrcPtr = a16Bits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ *(aDestPtr++) = *a16SrcPtr;
+ ++a16SrcPtr;
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/2 - mWidth;
+ }
+ }
+ }
+ else
+ {
+ bool needNewColor = false;
+ ulong* aSrcPtr = mBits;
+ ushort* a16SrcPtr = a16Bits;
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+ ushort a16Val = *(a16SrcPtr++);
+
+ int anAlpha = val >> 24;
+ if ((anAlpha == 255) && (aTransColor == a16Val))
+ {
+ needNewColor = true;
+ break;
+ }
+ }
+
+ if (needNewColor)
+ {
+ int* aUsedColorArray = new int[2048];
+
+ ZeroMemory(aUsedColorArray, 2048*sizeof(int));
+
+ aSrcPtr = mBits;
+ a16SrcPtr = a16Bits;
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+ ushort a16Val = *(a16SrcPtr++);
+
+ int anAlpha = val >> 24;
+ if (anAlpha > 0)
+ aUsedColorArray[a16Val/32] |= (1<<(a16Val%32));
+ }
+
+ bool done = false;
+ for (int i = 0; i < 2048; i++)
+ {
+ if (aUsedColorArray[i] != 0xFFFF)
+ {
+ for (int aBit = 0; aBit < 32; aBit++)
+ {
+ if ((aUsedColorArray[i] & (1<<aBit)) == 0)
+ {
+ aTransColor = i*32+aBit;
+ break;
+ }
+ }
+ }
+
+ if (done)
+ break;
+ }
+
+ delete aUsedColorArray;
+ }
+
+ if (mBits != NULL)
+ {
+ ushort* aDestPtr = mSurfaceBits;
+ ulong* aSrcPtr = mBits;
+ ushort* a16SrcPtr = a16Bits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ //*(aDestPtr++) = 0xFF000000 | ((val >> 24) & 0xFF);
+
+ int anAlpha = val >> 24;
+ if (anAlpha < 255)
+ *(aDestPtr++) = aTransColor;
+ else
+ *(aDestPtr++) = *a16SrcPtr;
+
+ ++a16SrcPtr;
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/2 - mWidth;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (a16Bits != NULL)
+ {
+ ushort* aDestPtr = mSurfaceBits;
+ ushort* a16SrcPtr = a16Bits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ *(aDestPtr++) = *a16SrcPtr;
+ ++a16SrcPtr;
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/2 - mWidth;
+ }
+ }
+ }
+
+ delete a16Bits;
+
+ if (mHasTrans)
+ {
+ DDCOLORKEY aColorKey = {aTransColor, aTransColor};
+ mSurface->SetColorKey(DDCKEY_SRCBLT, &aColorKey);
+ }
+ }
+ }
+ else if (aNumBits == 32)
+ {
+ ulong* mSurfaceBits = (ulong*) mLockedSurfaceDesc.lpSurface;
+
+ if (mSurfaceBits != NULL)
+ {
+ int i;
+ bool firstTrans = true;
+
+ ulong aTransColor = 0;
+
+ if ((mHasTrans) && (mBits != NULL))
+ {
+ if (mFirstPixelTrans)
+ {
+ ulong val = *mBits;
+
+ aTransColor = (((val>>rRightShift)<<rLeftShift)&rMask) |
+ (((val>>gRightShift)<<gLeftShift)&gMask) |
+ (((val>>bRightShift)<<bLeftShift)&bMask);
+
+ if (mBits != NULL)
+ {
+ ulong* aDestPtr = mSurfaceBits;
+ ulong* aSrcPtr = mBits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ *(aDestPtr++) =
+ (((val>>rRightShift)<<rLeftShift)&rMask) |
+ (((val>>gRightShift)<<gLeftShift)&gMask) |
+ (((val>>bRightShift)<<bLeftShift)&bMask);
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/4 - mWidth;
+ }
+ }
+ }
+ else
+ {
+ ulong* aSrcPtr = mBits;
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+ if ((firstTrans) && (anAlpha < 255))
+ {
+ firstTrans = false;
+ aTransColor = val;
+ }
+ }
+
+ bool needNewColor = false;
+ aSrcPtr = mBits;
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+ if ((anAlpha == 255) && (aTransColor == (val & 0x00FFFFFF)))
+ {
+ needNewColor = true;
+ break;
+ }
+ }
+
+ if (needNewColor)
+ {
+ int* aUsedColorArray = new int[0x80000];
+
+ ZeroMemory(aUsedColorArray, 0x80000*sizeof(int));
+
+ aSrcPtr = mBits;
+ for (i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+
+ if (anAlpha > 0)
+ aUsedColorArray[(val & 0xFFFFFF)/32] |= (1<<(val%32));
+ }
+
+ bool done = false;
+ for (int i = 0; i < 0x80000; i++)
+ {
+ if (aUsedColorArray[i] != 0xFFFF)
+ {
+ for (int aBit = 0; aBit < 32; aBit++)
+ {
+ if ((aUsedColorArray[i] & (1<<aBit)) == 0)
+ {
+ aTransColor = i*32+aBit;
+ done = true;
+ break;
+ }
+ }
+ }
+
+ if (done)
+ break;
+ }
+
+ delete aUsedColorArray;
+ }
+
+ if (mBits != NULL)
+ {
+ ulong* aDestPtr = mSurfaceBits;
+ ulong* aSrcPtr = mBits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ //*(aDestPtr++) = 0xFF000000 | ((val >> 24) & 0xFF);
+
+ int anAlpha = val >> 24;
+ if (anAlpha < 255)
+ *(aDestPtr++) = aTransColor;
+ else
+ {
+ *(aDestPtr++) =
+ (((val>>rRightShift)<<rLeftShift)&rMask) |
+ (((val>>gRightShift)<<gLeftShift)&gMask) |
+ (((val>>bRightShift)<<bLeftShift)&bMask);
+ }
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/4 - mWidth;
+ }
+ }
+ }
+
+ DDCOLORKEY aColorKey = {aTransColor, aTransColor};
+ mSurface->SetColorKey(DDCKEY_SRCBLT, &aColorKey);
+ }
+ else
+ {
+ if (mBits != NULL)
+ {
+ ulong* aDestPtr = mSurfaceBits;
+ ulong* aSrcPtr = mBits;
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < mWidth; aCol++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ *(aDestPtr++) =
+ (((val>>rRightShift)<<rLeftShift)&rMask) |
+ (((val>>gRightShift)<<gLeftShift)&gMask) |
+ (((val>>bRightShift)<<bLeftShift)&bMask);
+ }
+
+ aDestPtr += mLockedSurfaceDesc.lPitch/4 - mWidth;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ UnlockSurface();
+
+ return true;
+}
+
+void DDImage::DeleteDDSurface()
+{
+ if (mSurface != NULL)
+ {
+ if ((mColorTable == NULL) && (mBits == NULL) && (mD3DData == NULL))
+ GetBits();
+
+ mSurface->Release();
+ mSurface = NULL;
+ }
+}
+
+void DDImage::ReInit()
+{
+ MemoryImage::ReInit();
+
+ if (mWantDDSurface)
+ GenerateDDSurface();
+}
+
+void DDImage::PurgeBits()
+{
+ if (mSurfaceSet)
+ return;
+
+ mPurgeBits = true;
+
+ CommitBits();
+
+ if (!mApp->Is3DAccelerated())
+ {
+ if ((mWantDDSurface) && (GenerateDDSurface()))
+ {
+ delete [] mBits;
+ mBits = NULL;
+
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+
+ return;
+ }
+ }
+ else // Accelerated
+ {
+ if (mSurface != NULL)
+ {
+ GetBits();
+ DeleteDDSurface();
+ }
+ }
+
+ MemoryImage::PurgeBits();
+}
+
+void DDImage::DeleteAllNonSurfaceData()
+{
+ delete [] mBits;
+ mBits = NULL;
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+
+ delete [] mRLAdditiveData;
+ mRLAdditiveData = NULL;
+
+ delete [] mRLAlphaData;
+ mRLAlphaData = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+}
+
+void DDImage::DeleteNativeData()
+{
+ if (mSurfaceSet)
+ return;
+
+ MemoryImage::DeleteNativeData();
+ DeleteDDSurface();
+}
+
+void DDImage::DeleteExtraBuffers()
+{
+ if (mSurfaceSet)
+ return;
+
+ MemoryImage::DeleteExtraBuffers();
+ DeleteDDSurface();
+}
+
+void DDImage::SetVideoMemory(bool wantVideoMemory)
+{
+ if (wantVideoMemory != mVideoMemory)
+ {
+ mVideoMemory = wantVideoMemory;
+
+ // Make sure that we have the bits
+ GetBits();
+
+ DeleteDDSurface();
+ }
+}
+
+void DDImage::RehupFirstPixelTrans()
+{
+ if (!GenerateDDSurface())
+ return;
+
+ if ((mNoLock) || (!mHasTrans) || (!mFirstPixelTrans))
+ return;
+
+// TDDSurfaceDesc aDesc;
+ DDSURFACEDESC aDesc;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ HRESULT aResult = mDDInterface->mPrimarySurface->GetSurfaceDesc(&aDesc);
+ if (FAILED(aResult))
+ return;
+
+ int aNumBits = aDesc.ddpfPixelFormat.dwRGBBitCount;
+
+ if (aNumBits == 16)
+ {
+ if (!LockSurface())
+ return;
+
+ ushort* aSurfaceBits = (ushort*) mLockedSurfaceDesc.lpSurface;
+
+ ushort aTransColor = *aSurfaceBits;
+
+ DDCOLORKEY aColorKey = {aTransColor, aTransColor};
+ mSurface->SetColorKey(DDCKEY_SRCBLT, &aColorKey);
+
+ UnlockSurface();
+ }
+ else if ((aNumBits == 24) || (aNumBits == 32))
+ {
+ if (!LockSurface())
+ return;
+
+ ulong* aSurfaceBits = (ulong*) mLockedSurfaceDesc.lpSurface;
+
+ ulong aTransColor = *aSurfaceBits;
+
+ DDCOLORKEY aColorKey = {aTransColor, aTransColor};
+ mSurface->SetColorKey(DDCKEY_SRCBLT, &aColorKey);
+
+ UnlockSurface();
+ }
+}
+
+LPDIRECTDRAWSURFACE DDImage::GetSurface()
+{
+ //TODO: Log if generate surface fails
+
+ if (mSurface == NULL)
+ GenerateDDSurface();
+
+ return mSurface;
+}
+
+bool DDImage::PolyFill3D(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty, bool convex)
+{
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->FillPoly(theVertices,theNumVertices,theClipRect,theColor,theDrawMode,tx,ty);
+ return true;
+ }
+ else
+ return false;
+}
+
+void DDImage::FillRect(const Rect& theRect, const Color& theColor, int theDrawMode)
+{
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->FillRect(theRect,theColor,theDrawMode);
+ return;
+ }
+
+ CommitBits();
+ if ((mDrawToBits) || (mHasAlpha) || ((mHasTrans) && (!mFirstPixelTrans)) || (mDDInterface->mIs3D))
+ {
+ MemoryImage::FillRect(theRect, theColor, theDrawMode);
+ return;
+ }
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalFillRect(theRect, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveFillRect(theRect, theColor);
+ break;
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::NormalDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ if (mNoLock)
+ return;
+
+ double aMinX = min(theStartX, theEndX);
+ double aMinY = min(theStartY, theEndY);
+ double aMaxX = max(theStartX, theEndX);
+ double aMaxY = max(theStartY, theEndY);
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ if (theColor.mAlpha == 255)
+ {
+ ushort aColor = (ushort)
+ (((((theColor.mRed * aRMask) + aRRoundAdd) >> 8) & aRMask) |
+ ((((theColor.mGreen * aGMask) + aGRoundAdd) >> 8) & aGMask) |
+ ((((theColor.mBlue * aBMask) + aBRoundAdd) >> 8) & aBMask));
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/2;
+ int aRowAdd = aRowWidth;
+
+ if (fabs(dv) < fabs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels++;
+
+ aCurY = (int) theStartY;
+ aCurX = (int) theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartY - (int) theStartY);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurX++;
+ aDestPixels++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * mLockedSurfaceDesc.lPitch/2) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ else
+ {
+ ushort src =
+ ((((((theColor.mRed * theColor.mAlpha + 0x80) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask) +
+ ((((((theColor.mGreen * theColor.mAlpha + 0x80) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ ((((((theColor.mBlue * theColor.mAlpha + 0x80) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask);
+ int oma = 256 - theColor.mAlpha;
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/2;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ushort dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartY - (int) theStartY);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * mLockedSurfaceDesc.lPitch/2) + (int) theStartX;
+ ushort dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ if (theColor.mAlpha == 255)
+ {
+ ulong aColor =
+ ((((theColor.mRed * aRMask) + aRRoundAdd) >> 8) & aRMask) |
+ ((((theColor.mGreen * aGMask) + aGRoundAdd) >> 8) & aGMask) |
+ ((((theColor.mBlue * aBMask) + aBRoundAdd) >> 8) & aBMask);
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/4;
+ int aRowAdd = aRowWidth;;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels++;
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartY - (int) theStartY);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurX++;
+ aDestPixels++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ else
+ {
+ ulong src =
+ ((((((theColor.mRed * theColor.mAlpha + 0x80) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask) +
+ ((((((theColor.mGreen * theColor.mAlpha + 0x80) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ ((((((theColor.mBlue * theColor.mAlpha + 0x80) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask);
+ int oma = 256 - theColor.mAlpha;
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/4;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ }
+
+ UnlockSurface();
+}
+
+void DDImage::AdditiveDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ if (mNoLock)
+ return;
+
+ double aMinX = min(theStartX, theEndX);
+ double aMinY = min(theStartY, theEndY);
+ double aMaxX = max(theStartX, theEndX);
+ double aMaxY = max(theStartY, theEndY);
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort rc = ((theColor.mRed * theColor.mAlpha) / 255) >> (8-mDDInterface->mRedBits);
+ ushort gc = ((theColor.mGreen * theColor.mAlpha) / 255) >> (8-mDDInterface->mGreenBits);
+ ushort bc = ((theColor.mBlue * theColor.mAlpha) / 255) >> (8-mDDInterface->mBlueBits);
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/2;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ushort dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartY - (int) theStartY);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ushort* aDestPixels = ((ushort*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * mLockedSurfaceDesc.lPitch/2) + (int) theStartX;
+
+ ushort dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong rc = ((theColor.mRed * theColor.mAlpha) / 255) >> (8-mDDInterface->mRedBits);
+ ulong gc = ((theColor.mGreen * theColor.mAlpha) / 255) >> (8-mDDInterface->mGreenBits);
+ ulong bc = ((theColor.mBlue * theColor.mAlpha) / 255) >> (8-mDDInterface->mBlueBits);
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mLockedSurfaceDesc.lPitch/4;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) mLockedSurfaceDesc.lpSurface) + ((int) theStartY * mLockedSurfaceDesc.lPitch/4) + (int) theStartX;
+
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+
+ UnlockSurface();
+}
+
+void DDImage::DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->DrawLine(theStartX,theStartY,theEndX,theEndY,theColor,theDrawMode);
+ return;
+ }
+
+ if ((mDrawToBits) || (mHasAlpha) || (mHasTrans) || (mDDInterface->mIs3D))
+ {
+ MemoryImage::DrawLine(theStartX, theStartY, theEndX, theEndY, theColor, theDrawMode);
+ return;
+ }
+
+ if (theStartY == theEndY)
+ {
+ int aStartX = min(theStartX, theEndX);
+ int aEndX = max(theStartX, theEndX);
+
+ FillRect(Rect(aStartX, theStartY, aEndX-aStartX+1, theEndY-theStartY+1), theColor, theDrawMode);
+ return;
+ }
+ else if (theStartX == theEndX)
+ {
+ int aStartY = min(theStartY, theEndY);
+ int aEndY = max(theStartY, theEndY);
+
+ FillRect(Rect(theStartX, aStartY, theEndX-theStartX+1, aEndY-aStartY+1), theColor, theDrawMode);
+ return;
+ }
+
+ CommitBits();
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalDrawLine(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveDrawLine(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::NormalDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+ ulong color = (((theColor.mRed * aRMask) >> 8) & aRMask) |
+ (((theColor.mGreen * aGMask) >> 8) & aGMask) |
+ (((theColor.mBlue * aBMask) >> 8) & aBMask);
+
+ int aX0 = (int)theStartX, aX1 = (int)theEndX;
+ int aY0 = (int)theStartY, aY1 = (int)theEndY;
+ int aXinc = 1;
+ if (aY0 > aY1)
+ {
+ int aTempX = aX0, aTempY = aY0;
+ aX0 = aX1; aY0 = aY1;
+ aX1 = aTempX; aY1 = aTempY;
+ double aTempXd = theStartX, aTempYd = theStartY;
+ theStartX = theEndX; theStartY = theEndY;
+ theEndX = aTempXd; theEndY = aTempYd;
+ }
+
+ int dx = aX1 - aX0;
+ int dy = aY1 - aY0;
+ double dxd = theEndX - theStartX;
+ double dyd = theEndY - theStartY;
+ if (dx < 0)
+ {
+ dx = -dx;
+ aXinc = -1;
+ dxd = -dxd;
+ }
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aBits = (ulong*)mLockedSurfaceDesc.lpSurface;
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ if (theColor.mAlpha != 255)
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & 0xFF00FF) * a + (dest & 0xFF00FF) * oma) >> 8) & 0xFF00FF) |\
+ ((((color & 0x00FF00) * a + (dest & 0x00FF00) * oma) >> 8) & 0x00FF00);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+ else
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (w)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & 0xFF00FF) * a + (dest & 0xFF00FF) * oma) >> 8) & 0xFF00FF) |\
+ ((((color & 0x00FF00) * a + (dest & 0x00FF00) * oma) >> 8) & 0x00FF00);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+#else
+ if (theColor.mAlpha != 255)
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & aRMask) * a + (dest & aRMask) * oma) >> 8) & aRMask) |\
+ ((((color & aGMask) * a + (dest & aGMask) * oma) >> 8) & aGMask) |\
+ ((((color & aBMask) * a + (dest & aBMask) * oma) >> 8) & aBMask);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+ else
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (w)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & aRMask) * a + (dest & aRMask) * oma) >> 8) & aRMask) |\
+ ((((color & aGMask) * a + (dest & aGMask) * oma) >> 8) & aGMask) |\
+ ((((color & aBMask) * a + (dest & aBMask) * oma) >> 8) & aBMask);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+#endif
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aBits = (ushort*)mLockedSurfaceDesc.lpSurface;
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ if (aGMask == 0x3E0) // 5-5-5
+ {
+ #define PIXEL_TYPE ushort
+ #define BLEND_PIXEL(p) \
+ {\
+ a >>= 3;\
+ oma >>= 3;\
+ ulong _src = (((color | (color << 16)) & 0x3E07C1F) * a >> 5) & 0x3E07C1F;\
+ ulong _dest = (((dest | (dest << 16)) & 0x3E07C1F) * oma >> 5) & 0x3E07C1F;\
+ *(p) = (_src | (_src>>16)) + (_dest | (_dest>>16));\
+ }
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+ if (theColor.mAlpha != 255)
+ {
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #include "GENERIC_DrawLineAA.inc"
+ #undef CALC_WEIGHT_A
+ }
+ else
+ {
+ #define CALC_WEIGHT_A(w) (w)
+ #include "GENERIC_DrawLineAA.inc"
+ #undef CALC_WEIGHT_A
+ }
+ #undef PIXEL_TYPE
+ #undef BLEND_PIXEL
+ }
+ else if (aGMask == 0x7E0) // 5-6-5
+ {
+ #define PIXEL_TYPE ushort
+ #define BLEND_PIXEL(p) \
+ {\
+ a >>= 3;\
+ oma >>= 3;\
+ ulong _src = (((color | (color << 16)) & 0x7E0F81F) * a >> 5) & 0x7E0F81F;\
+ ulong _dest = (((dest | (dest << 16)) & 0x7E0F81F) * oma >> 5) & 0x7E0F81F;\
+ *(p) = (_src | (_src>>16)) + (_dest | (_dest>>16));\
+ }
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+ if (theColor.mAlpha != 255)
+ {
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #include "GENERIC_DrawLineAA.inc"
+ #undef CALC_WEIGHT_A
+ }
+ else
+ {
+ #define CALC_WEIGHT_A(w) (w)
+ #include "GENERIC_DrawLineAA.inc"
+ #undef CALC_WEIGHT_A
+ }
+ #undef PIXEL_TYPE
+ #undef BLEND_PIXEL
+ }
+ else
+ {
+#endif
+ if (theColor.mAlpha != 255)
+ {
+ #define PIXEL_TYPE ushort
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & aRMask) * a + (dest & aRMask) * oma) >> 8) & aRMask) |\
+ ((((color & aGMask) * a + (dest & aGMask) * oma) >> 8) & aGMask) |\
+ ((((color & aBMask) * a + (dest & aBMask) * oma) >> 8) & aBMask);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+ else
+ {
+ #define PIXEL_TYPE ushort
+ #define CALC_WEIGHT_A(w) (w)
+ #define BLEND_PIXEL(p) \
+ *(p) = \
+ ((((color & aRMask) * a + (dest & aRMask) * oma) >> 8) & aRMask) |\
+ ((((color & aGMask) * a + (dest & aGMask) * oma) >> 8) & aGMask) |\
+ ((((color & aBMask) * a + (dest & aBMask) * oma) >> 8) & aBMask);
+ const int STRIDE = mLockedSurfaceDesc.lPitch / sizeof(PIXEL_TYPE);
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ }
+#endif
+ }
+
+ UnlockSurface();
+}
+
+void DDImage::AdditiveDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+}
+
+void DDImage::DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->DrawLine(theStartX,theStartY,theEndX,theEndY,theColor,theDrawMode);
+ return;
+ }
+
+ if ((mDrawToBits) || (mHasAlpha) || (mHasTrans) || (mDDInterface->mIs3D))
+ {
+ MemoryImage::DrawLine(theStartX, theStartY, theEndX, theEndY, theColor, theDrawMode);
+ return;
+ }
+
+ if (theStartY == theEndY)
+ {
+ int aStartX = min(theStartX, theEndX);
+ int aEndX = max(theStartX, theEndX);
+
+ FillRect(Rect(aStartX, theStartY, aEndX-aStartX+1, theEndY-theStartY+1), theColor, theDrawMode);
+ return;
+ }
+ else if (theStartX == theEndX)
+ {
+ int aStartY = min(theStartY, theEndY);
+ int aEndY = max(theStartY, theEndY);
+
+ FillRect(Rect(theStartX, aStartY, theEndX-theStartX+1, aEndY-aStartY+1), theColor, theDrawMode);
+ return;
+ }
+
+ CommitBits();
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalDrawLineAA(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveDrawLineAA(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::CommitBits()
+{
+ if (mSurface == NULL)
+ {
+ MemoryImage::CommitBits();
+ return;
+ }
+}
+
+void DDImage::Create(int theWidth, int theHeight)
+{
+ delete [] mBits;
+
+ mWidth = theWidth;
+ mHeight = theHeight;
+
+ mBits = NULL;
+
+ BitsChanged();
+}
+
+void DDImage::BitsChanged()
+{
+ MemoryImage::BitsChanged();
+
+ if (mSurface != NULL)
+ mSurface->Release();
+ mSurface = NULL;
+}
+
+ulong* DDImage::GetBits()
+{
+ if (mBits == NULL)
+ {
+ if (mSurface == NULL)
+ return MemoryImage::GetBits();
+
+ if (mNoLock)
+ return NULL;
+
+ LPDIRECTDRAWSURFACE aSurface = mSurface;
+
+ if (!LockSurface())
+ return NULL;
+
+ mBits = new ulong[mWidth*mHeight + 1];
+ mBits[mWidth*mHeight] = MEMORYCHECK_ID;
+
+ int aRRound = (1 << (7 - mDDInterface->mRedBits));
+ int aGRound = (1 << (7 - mDDInterface->mGreenBits));
+ int aBRound = (1 << (7 - mDDInterface->mBlueBits));
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort* aSrcPixelsRow = (ushort*) mLockedSurfaceDesc.lpSurface;
+ ulong* aDest = mBits;
+
+ for (int y = 0; y < mHeight; y++)
+ {
+ ushort* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < mWidth; x++)
+ {
+ ulong src = *(aSrcPixels++);
+
+ int r = ((src >> mDDInterface->mRedShift << (8 - mDDInterface->mRedBits)) & 0xFF);
+ int g = ((src >> mDDInterface->mGreenShift << (8 - mDDInterface->mGreenBits)) & 0xFF);
+ int b = ((src >> mDDInterface->mBlueShift << (8 - mDDInterface->mBlueBits)) & 0xFF);
+
+ *aDest++ = 0xFF000000 | (r << 16) | (g << 8) | (b);
+ }
+
+ aSrcPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong* aSrcPixelsRow = (ulong*) mLockedSurfaceDesc.lpSurface;
+ ulong* aDest = mBits;
+
+ for (int y = 0; y < mHeight; y++)
+ {
+ ulong* aSrcPixels = aSrcPixelsRow;
+
+ for (int x = 0; x < mWidth; x++)
+ {
+ ulong src = *(aSrcPixels++);
+
+ int r = (src >> mDDInterface->mRedShift << (8 - mDDInterface->mRedBits)) & 0xFF;
+ int g = (src >> mDDInterface->mGreenShift << (8 - mDDInterface->mGreenBits)) & 0xFF;
+ int b = (src >> mDDInterface->mBlueShift << (8 - mDDInterface->mBlueBits)) & 0xFF;
+
+ *aDest++ = 0xFF000000 | (r << 16) | (g << 8) | (b);
+ }
+
+ aSrcPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ }
+ }
+
+ UnlockSurface();
+ }
+
+ return mBits;
+}
+
+void DDImage::NormalFillRect(const Rect& theRect, const Color& theColor)
+{
+ if (mNoLock)
+ return;
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask;
+ ulong aGRoundAdd = aGMask;
+ ulong aBRoundAdd = aBMask;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ if (theColor.mAlpha == 255)
+ {
+ ushort aColor =
+ ((((theColor.mRed * aRMask) + aRRoundAdd) >> 8) & aRMask) |
+ ((((theColor.mGreen * aGMask) + aGRoundAdd) >> 8) & aGMask) |
+ ((((theColor.mBlue * aBMask) + aBRoundAdd) >> 8) & aBMask);
+
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/2) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ *(aDestPixels++) = aColor;
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ }
+ }
+ else
+ {
+ ushort src =
+ ((((((theColor.mRed * theColor.mAlpha + 0x80) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask) +
+ ((((((theColor.mGreen * theColor.mAlpha + 0x80) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ ((((((theColor.mBlue * theColor.mAlpha + 0x80) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask);
+ int oma = 256 - theColor.mAlpha;
+
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/2) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ {
+ ushort dest = *aDestPixels;
+
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ if (theColor.mAlpha == 255)
+ {
+ ulong aColor =
+ ((((theColor.mRed * aRMask)) >> 8) & aRMask) |
+ ((((theColor.mGreen * aGMask)) >> 8) & aGMask) |
+ ((((theColor.mBlue * aBMask)) >> 8) & aBMask);
+
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/4) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ *(aDestPixels++) = aColor;
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ }
+ }
+ else
+ {
+ ulong src =
+ ((((((theColor.mRed * theColor.mAlpha + 0x7F) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask) +
+ ((((((theColor.mGreen * theColor.mAlpha + 0x7F) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) +
+ ((((((theColor.mBlue * theColor.mAlpha + 0x7F) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask);
+ int oma = 256 - theColor.mAlpha;
+
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/4) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ {
+ ulong dest = *aDestPixels;
+
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma)) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma)) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma)) >> 8) & aBMask);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ }
+ }
+ }
+
+ UnlockSurface();
+}
+
+void DDImage::AdditiveFillRect(const Rect& theRect, const Color& theColor)
+{
+ if (mNoLock)
+ return;
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ int aRedShift = mDDInterface->mRedShift;
+ int aGreenShift = mDDInterface->mGreenShift;
+ int aBlueShift = mDDInterface->mBlueShift;
+
+ int* aMaxRedTable = mDDInterface->mRedAddTable;
+ int* aMaxGreenTable = mDDInterface->mGreenAddTable;
+ int* aMaxBlueTable = mDDInterface->mBlueAddTable;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ ushort rc = ((theColor.mRed * theColor.mAlpha) / 255) >> (8-mDDInterface->mRedBits);
+ ushort gc = ((theColor.mGreen * theColor.mAlpha) / 255) >> (8-mDDInterface->mGreenBits);
+ ushort bc = ((theColor.mBlue * theColor.mAlpha) / 255) >> (8-mDDInterface->mBlueBits);
+
+ ushort* aDestPixelsRow = ((ushort*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/2) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ushort* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ {
+ ushort dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/2;
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong rc = ((theColor.mRed * theColor.mAlpha) / 255) >> (8-mDDInterface->mRedBits);
+ ulong gc = ((theColor.mGreen * theColor.mAlpha) / 255) >> (8-mDDInterface->mGreenBits);
+ ulong bc = ((theColor.mBlue * theColor.mAlpha) / 255) >> (8-mDDInterface->mBlueBits);
+
+ ulong* aDestPixelsRow = ((ulong*) mLockedSurfaceDesc.lpSurface) + (theRect.mY * mLockedSurfaceDesc.lPitch/4) + theRect.mX;
+
+ for (int y = 0; y < theRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theRect.mWidth; x++)
+ {
+ ulong dest = *aDestPixels;
+
+ int r = aMaxRedTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxGreenTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxBlueTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+ }
+
+ aDestPixelsRow += mLockedSurfaceDesc.lPitch/4;
+ }
+ }
+
+ UnlockSurface();
+}
+
+void DDImage::NormalBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ if (aMemoryImage != NULL)
+ {
+ aMemoryImage->CommitBits();
+
+ RECT aDestRect = {theX, theY, theX + theSrcRect.mWidth, theY + theSrcRect.mHeight};
+ RECT aSrcRect = {theSrcRect.mX, theSrcRect.mY, theSrcRect.mX + theSrcRect.mWidth, theSrcRect.mY + theSrcRect.mHeight};
+
+ //TODO:
+ if ((aMemoryImage->mIsVolatile) && ((aDDImage == NULL) || (aDDImage->mSurface == NULL)) &&
+ (!mNoLock) && (theColor == Color::White))
+ {
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aMemoryImage->GetBits();
+
+ #define SRC_TYPE ulong
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #include "DDI_NormalBlt_Volatile.inc"
+ #undef SRC_TYPE
+ #undef NEXT_SRC_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = aMemoryImage->mColorTable;
+ uchar* aSrcBits = aMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define NEXT_SRC_COLOR (aColorTable[*(aSrcPixels++)])
+
+ #include "DDI_NormalBlt_Volatile.inc"
+
+ #undef SRC_TYPE
+ #undef NEXT_SRC_COLOR
+ }
+ }
+ else if ((aMemoryImage->mHasAlpha) || (theColor != Color::White))
+ {
+ if (mNoLock)
+ return;
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ // Ensure NativeAlphaData is calculated
+ void *aNativeData = aMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ // Ensure RunLength data is calculated
+ uchar* aSrcRLAlphaData = aMemoryImage->GetRLAlphaData();
+
+ #define _PLUSPLUS ++
+ #define _PLUSEQUALS +=
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aNativeData) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ ulong* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #define PEEK_SRC_COLOR (*aSrcPixels)
+
+ #include "DDI_AlphaBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ else
+ {
+ ulong* aNativeColorTable = (ulong*) aNativeData;
+
+ uchar* aSrcPixelsRow = aMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ uchar* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (aNativeColorTable[*(aSrcPixels++)])
+ #define PEEK_SRC_COLOR (aNativeColorTable[*aSrcPixels])
+
+ #include "DDI_AlphaBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+
+ #undef _PLUSPLUS
+ #undef _PLUSEQUALS
+ UnlockSurface();
+ }
+ else if ((aDDImage == NULL) || (aDDImage->mSurface == NULL) || ((!mVideoMemory) && (aDDImage->mVideoMemory)))
+ {
+ if (mNoLock)
+ return;
+
+ //TODO: Have some sort of cool thing here
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ void* aNativeAlphaData = aMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aNativeAlphaData) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ ulong* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #define PEEK_SRC_COLOR (*aSrcPixels)
+
+ #include "DDI_FastBlt_NoAlpha.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ else
+ {
+ ulong* aNativeAlphaColorTable = (ulong*) aNativeAlphaData;
+
+ uchar* aSrcPixelsRow = aMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ uchar* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (aNativeAlphaColorTable[*(aSrcPixels++)])
+ #define PEEK_SRC_COLOR (aNativeAlphaColorTable[*aSrcPixels])
+
+ #include "DDI_FastBlt_NoAlpha.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ }
+ else
+ {
+ if (mLockCount > 0)
+ mSurface->Unlock(NULL);
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ DWORD aFlags = DDBLT_WAIT;
+
+ if (aDDImage->mHasTrans)
+ aFlags |= DDBLT_KEYSRC;
+
+ HRESULT aResult = GetSurface()->Blt(&aDestRect, aDDImage->GetSurface(), &aSrcRect, aFlags, &aBltFX);
+
+ if (mLockCount > 0)
+ {
+ if (mSurface->Lock(NULL, &mLockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL) != DD_OK)
+ return;
+ }
+ }
+ }
+}
+
+void DDImage::NormalBltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRectOrig, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ Rect theSrcRect = theSrcRectOrig;
+// theSrcRect.mX = (theSrcRect.mX+theSrcRect.mWidth)*-1 + theImage->mWidth;
+ theX += theSrcRect.mWidth-1;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ if (aMemoryImage != NULL)
+ {
+ aMemoryImage->CommitBits();
+
+ if (mNoLock)
+ return;
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ // Ensure NativeAlphaData is calculated
+ void *aNativeData = aMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ // Ensure RunLength data is calculated
+ uchar* aSrcRLAlphaData = aMemoryImage->GetRLAlphaData();
+
+ #define _PLUSPLUS --
+ #define _PLUSEQUALS -=
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aNativeData) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ ulong* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #define PEEK_SRC_COLOR (*aSrcPixels)
+
+ #include "DDI_AlphaBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ else
+ {
+ ulong* aNativeColorTable = (ulong*) aNativeData;
+
+ uchar* aSrcPixelsRow = aMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ uchar* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (aNativeColorTable[*(aSrcPixels++)])
+ #define PEEK_SRC_COLOR (aNativeColorTable[*aSrcPixels])
+
+ #include "DDI_AlphaBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+
+ #undef _PLUSPLUS
+ #undef _PLUSEQUALS
+ UnlockSurface();
+ }
+}
+
+
+void DDImage::AdditiveBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ if (mNoLock)
+ return;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ if (aMemoryImage != NULL)
+ {
+ if (!LockSurface())
+ return;
+
+ // Ensure NativeAlphaData is calculated
+ void* aNativeAlphaData = aMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ #define _PLUSPLUS ++
+ #define _PLUSEQUALS +=
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aNativeAlphaData) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ ulong* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #define PEEK_SRC_COLOR (*aSrcPixels)
+
+ #include "DDI_Additive.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ else
+ {
+ ulong* aNativeAlphaColorTable = (ulong*) aNativeAlphaData;
+
+ uchar* aSrcPixelsRow = aMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ uchar* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (aNativeAlphaColorTable[*(aSrcPixels++)])
+ #define PEEK_SRC_COLOR (aNativeAlphaColorTable[*aSrcPixels])
+
+ #include "DDI_Additive.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ #undef _PLUSPLUS
+ #undef _PLUSEQUALS
+
+ UnlockSurface();
+ }
+}
+
+void DDImage::AdditiveBltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRectOrig, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ if (mNoLock)
+ return;
+
+ Rect theSrcRect = theSrcRectOrig;
+// theSrcRect.mX = (theSrcRect.mX+theSrcRect.mWidth)*-1 + theImage->mWidth;
+ theX += theSrcRect.mWidth-1;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ if (aMemoryImage != NULL)
+ {
+ if (!LockSurface())
+ return;
+
+ // Ensure NativeAlphaData is calculated
+ void* aNativeAlphaData = aMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ #define _PLUSPLUS --
+ #define _PLUSEQUALS -=
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aNativeAlphaData) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ ulong* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (*(aSrcPixels++))
+ #define PEEK_SRC_COLOR (*aSrcPixels)
+
+ #include "DDI_Additive.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ else
+ {
+ ulong* aNativeAlphaColorTable = (ulong*) aNativeAlphaData;
+
+ uchar* aSrcPixelsRow = aMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+ uchar* aSrcPixels;
+
+ #define NEXT_SRC_COLOR (aNativeAlphaColorTable[*(aSrcPixels++)])
+ #define PEEK_SRC_COLOR (aNativeAlphaColorTable[*aSrcPixels])
+
+ #include "DDI_Additive.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef PEEK_SRC_COLOR
+ }
+ #undef _PLUSPLUS
+ #undef _PLUSEQUALS
+
+ UnlockSurface();
+ }
+}
+
+void DDImage::Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ //if (gDebug)
+ // mApp->CopyToClipboard("+DDImage::Blt");
+
+ DBG_ASSERTE((theColor.mRed >= 0) && (theColor.mRed <= 255));
+ DBG_ASSERTE((theColor.mGreen >= 0) && (theColor.mGreen <= 255));
+ DBG_ASSERTE((theColor.mBlue >= 0) && (theColor.mBlue <= 255));
+ DBG_ASSERTE((theColor.mAlpha >= 0) && (theColor.mAlpha <= 255));
+
+ CommitBits();
+
+ if (Check3D(this))
+ {
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ // Special short-circuit
+ if ((aDDImage != NULL) && (aDDImage->mSurface != NULL) &&
+ (mDDInterface->mD3DInterface->mTransformStack.empty()) &&
+ (theDrawMode == Graphics::DRAWMODE_NORMAL) &&
+ (theColor == Color::White) && (!aDDImage->mHasAlpha))
+ {
+ if (mLockCount > 0)
+ mSurface->Unlock(NULL);
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ DWORD aFlags = DDBLT_WAIT;
+
+ if (aDDImage->mHasTrans)
+ aFlags |= DDBLT_KEYSRC;
+
+ RECT aDestRect = {theX, theY, theX + theSrcRect.mWidth, theY + theSrcRect.mHeight};
+ RECT aSrcRect = {theSrcRect.mX, theSrcRect.mY, theSrcRect.mX + theSrcRect.mWidth, theSrcRect.mY + theSrcRect.mHeight};
+
+ HRESULT aResult = GetSurface()->Blt(&aDestRect, aDDImage->GetSurface(), &aSrcRect, aFlags, &aBltFX);
+
+ if (mLockCount > 0)
+ {
+ if (mSurface->Lock(NULL, &mLockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL) != DD_OK)
+ return;
+ }
+
+ return;
+ }
+
+ mDDInterface->mD3DInterface->Blt(theImage,theX,theY,theSrcRect,theColor,theDrawMode);
+ return;
+ }
+
+ if ((mDrawToBits) || (mHasAlpha) || ((mHasTrans) && (!mFirstPixelTrans)) || (mDDInterface->mIs3D && this!=mDDInterface->mNewCursorAreaImage && this!=mDDInterface->mOldCursorAreaImage))
+ {
+ MemoryImage::Blt(theImage, theX, theY, theSrcRect, theColor, theDrawMode);
+ return;
+ }
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalBlt(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveBlt(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::BltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+ DBG_ASSERTE((theColor.mRed >= 0) && (theColor.mRed <= 255));
+ DBG_ASSERTE((theColor.mGreen >= 0) && (theColor.mGreen <= 255));
+ DBG_ASSERTE((theColor.mBlue >= 0) && (theColor.mBlue <= 255));
+ DBG_ASSERTE((theColor.mAlpha >= 0) && (theColor.mAlpha <= 255));
+
+ CommitBits();
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->BltMirror(theImage,theX,theY,theSrcRect,theColor,theDrawMode);
+ return;
+ }
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalBltMirror(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveBltMirror(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ if (Check3D(this))
+ {
+ FRect aClipRect(theClipRect.mX,theClipRect.mY,theClipRect.mWidth,theClipRect.mHeight);
+ FRect aDestRect(theX,theY,theSrcRect.mWidth,theSrcRect.mHeight);
+
+ FRect anIntersect = aDestRect.Intersection(aClipRect);
+ if (anIntersect.mWidth!=aDestRect.mWidth || anIntersect.mHeight!=aDestRect.mHeight)
+ {
+ if (anIntersect.mWidth!=0 && anIntersect.mHeight!=0)
+ mDDInterface->mD3DInterface->BltClipF(theImage,theX,theY,theSrcRect,&theClipRect,theColor,theDrawMode);
+ }
+ else
+ mDDInterface->mD3DInterface->Blt(theImage,theX,theY,theSrcRect,theColor,theDrawMode,true);
+
+ return;
+ }
+ else
+ BltRotated(theImage,theX,theY,theSrcRect,theClipRect,theColor,theDrawMode,0,0,0);
+}
+
+void DDImage::BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY)
+{
+ theImage->mDrawn = true;
+
+ if (mNoLock)
+ return;
+
+ CommitBits();
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->BltRotated(theImage,theX,theY,&theClipRect,theColor,theDrawMode,theRot,theRotCenterX,theRotCenterY,theSrcRect);
+ return;
+ }
+
+ if ((mDrawToBits) || (mHasAlpha) || ((mHasTrans) && (!mFirstPixelTrans)) || (mDDInterface->mIs3D))
+ {
+ MemoryImage::BltRotated(theImage, theX, theY, theSrcRect, theClipRect, theColor, theDrawMode, theRot, theRotCenterX, theRotCenterY);
+ return;
+ }
+
+ // This BltRotatedClipHelper clipping used to happen in Graphics::DrawImageRotated
+ FRect aDestRect;
+ if (!BltRotatedClipHelper(theX, theY, theSrcRect, theClipRect, theRot, aDestRect,theRotCenterX,theRotCenterY))
+ return;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ DDImage* aDDImage = dynamic_cast<DDImage*>(theImage);
+
+ if (aMemoryImage != NULL)
+ {
+ aMemoryImage->CommitBits();
+
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aMemoryImage->GetBits() + theSrcRect.mX + theSrcRect.mY*aMemoryImage->GetWidth();
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_BltRotated.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+
+ }
+ else
+ {
+ ulong* aColorTable = aMemoryImage->mColorTable;
+ uchar* aSrcBits = aMemoryImage->mColorIndices + theSrcRect.mX + theSrcRect.mY*aMemoryImage->GetWidth();
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_BltRotated.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ else
+ {
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aMemoryImage->GetBits() + theSrcRect.mX + theSrcRect.mY*aMemoryImage->GetWidth();
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_BltRotated_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+
+ }
+ else
+ {
+ ulong* aColorTable = aMemoryImage->mColorTable;
+ uchar* aSrcBits = aMemoryImage->mColorIndices + theSrcRect.mX + theSrcRect.mY*aMemoryImage->GetWidth();
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_BltRotated_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::StretchBlt(Image* theImage, const Rect& theDestRectOrig, const Rect& theSrcRectOrig, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
+{
+ theImage->mDrawn = true;
+
+ DDImage* aSrcDDImage = dynamic_cast<DDImage*>(theImage);
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ CommitBits();
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->StretchBlt(theImage,theDestRectOrig,theSrcRectOrig,&theClipRect,theColor,theDrawMode,fastStretch);
+ return;
+ }
+
+ Rect theDestRect;
+ FRect theSrcRect;
+ if (!StretchBltClipHelper(theSrcRectOrig,theClipRect,theDestRectOrig,theSrcRect,theDestRect))
+ return;
+
+ if (fastStretch)
+ {
+ if ((aSrcDDImage != NULL) && (theColor == Color::White) && (theDrawMode == Graphics::DRAWMODE_NORMAL) &&
+ (!aSrcDDImage->mHasAlpha) && (aSrcDDImage->GetSurface() != NULL))
+ {
+ LPDIRECTDRAWSURFACE aSrcSurface = aSrcDDImage->GetSurface();
+ LPDIRECTDRAWSURFACE aDestSurface = GetSurface();
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ DWORD aFlags = DDBLT_WAIT;
+
+ if (aSrcDDImage->mHasTrans)
+ aFlags |= DDBLT_KEYSRC;
+
+ RECT aDestRect = {theDestRect.mX, theDestRect.mY, theDestRect.mX + theDestRect.mWidth, theDestRect.mY + theDestRect.mHeight};
+ RECT aSrcRect = {theSrcRect.mX, theSrcRect.mY, theSrcRect.mX + theSrcRect.mWidth, theSrcRect.mY + theSrcRect.mHeight};
+
+ if (mLockCount > 0)
+ {
+ mSurface->Unlock(NULL);
+ }
+
+ HRESULT aResult = GetSurface()->Blt(&aDestRect, aSrcDDImage->GetSurface(), &aSrcRect, aFlags, &aBltFX);
+
+ if (mLockCount > 0)
+ {
+ if (mSurface->Lock(NULL, &mLockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL) != DD_OK)
+ return;
+ }
+ }
+ else
+ {
+ if (aSrcMemoryImage != NULL)
+ {
+ aSrcMemoryImage->CommitBits();
+
+ // Ensure NativeAlphaData is calculated
+ void *aNativeAlphaData = aSrcMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ #define _PLUSPLUS ++
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ //ulong* aSrcBits = aSrcMemoryImage->GetBits();
+ ulong* aSrcBits = ((ulong*) aNativeAlphaData);
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_FastStretch.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = (ulong*) aNativeAlphaData;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_FastStretch.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ else
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ //ulong* aSrcBits = aSrcMemoryImage->GetBits();
+ ulong* aSrcBits = ((ulong*) aNativeAlphaData);
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_FastStretch_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = (ulong*) aNativeAlphaData;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_FastStretch_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ #undef _PLUSPLUS
+ }
+ }
+ }
+ else
+ {
+ if ((mDrawToBits) || (mHasAlpha) || (mHasTrans) || (mDDInterface->mIs3D))
+ {
+ MemoryImage::StretchBlt(theImage, theDestRectOrig, theSrcRectOrig, theClipRect, theColor, theDrawMode, fastStretch);
+ return;
+ }
+
+ // Stretch it to a temporary image
+ MemoryImage aTempImage(mApp);
+ Rect aTempRect(0, 0, theDestRect.mWidth, theDestRect.mHeight);
+
+ aTempImage.Create(theDestRect.mWidth, theDestRect.mHeight);
+ if (fastStretch)
+ aTempImage.FastStretchBlt(theImage, aTempRect, theSrcRect, theColor, 0);
+ else
+ aTempImage.SlowStretchBlt(theImage, aTempRect, theSrcRect, theColor, 0);
+
+ Blt(&aTempImage, theDestRect.mX, theDestRect.mY, aTempRect, theColor, theDrawMode);
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::StretchBltMirror(Image* theImage, const Rect& theDestRectOrig, const Rect& theSrcRectOrig, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
+{
+ theImage->mDrawn = true;
+
+ DDImage* aSrcDDImage = dynamic_cast<DDImage*>(theImage);
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ CommitBits();
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->StretchBlt(theImage,theDestRectOrig,theSrcRectOrig,&theClipRect,theColor,theDrawMode,fastStretch,true);
+ return;
+ }
+
+ FRect theSrcRect;
+ Rect theDestRect;
+
+ if (!StretchBltMirrorClipHelper(theSrcRectOrig,theClipRect,theDestRectOrig,theSrcRect,theDestRect))
+ return;
+
+ theDestRect.mX += theDestRect.mWidth-1;
+
+
+ if (aSrcMemoryImage != NULL)
+ {
+ aSrcMemoryImage->CommitBits();
+
+ // Ensure NativeAlphaData is calculated
+ void *aNativeAlphaData = aSrcMemoryImage->GetNativeAlphaData(mDDInterface);
+
+ #define _PLUSPLUS --
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ //ulong* aSrcBits = aSrcMemoryImage->GetBits();
+ ulong* aSrcBits = ((ulong*) aNativeAlphaData);
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_FastStretch.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = (ulong*) aNativeAlphaData;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_FastStretch.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ else
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ //ulong* aSrcBits = aSrcMemoryImage->GetBits();
+ ulong* aSrcBits = ((ulong*) aNativeAlphaData);
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "DDI_FastStretch_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = (ulong*) aNativeAlphaData;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "DDI_FastStretch_Additive.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ }
+ #undef _PLUSPLUS
+ }
+
+ DeleteAllNonSurfaceData();
+}
+
+void DDImage::BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend)
+{
+ theImage->mDrawn = true;
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->BltTransformed(theImage,&theClipRect,theColor,theDrawMode,theSrcRect,theMatrix,blend,x,y,true);
+ return;
+ }
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+ if (!LockSurface())
+ return;
+
+ int aPixelFormat;
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ aPixelFormat = 0x888;
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask == 0xf800 && mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask == 0x07e0 && mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask == 0x001f)
+ aPixelFormat = 0x565;
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask == 0x7c00 && mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask == 0x03e0 && mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask == 0x001f)
+ aPixelFormat = 0x555;
+ else
+ DBG_ASSERTE(FALSE);
+
+ BltMatrixHelper(theImage,x,y,theMatrix,theClipRect,theColor,theDrawMode,theSrcRect,mLockedSurfaceDesc.lpSurface,mLockedSurfaceDesc.lPitch,aPixelFormat,blend);
+
+ UnlockSurface();
+
+ DeleteAllNonSurfaceData();
+
+}
+
+void DDImage::BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend)
+{
+ theTexture->mDrawn = true;
+
+ if (Check3D(this))
+ {
+ mDDInterface->mD3DInterface->DrawTrianglesTex(theVertices,theNumTriangles,theColor,theDrawMode,theTexture,tx,ty,blend);
+ return;
+ }
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+ if (!LockSurface())
+ return;
+
+ int aPixelFormat;
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ aPixelFormat = 0x888;
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask == 0xf800 && mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask == 0x07e0 && mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask == 0x001f)
+ aPixelFormat = 0x565;
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask == 0x7c00 && mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask == 0x03e0 && mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask == 0x001f)
+ aPixelFormat = 0x555;
+ else
+ DBG_ASSERTE(FALSE);
+
+ BltTrianglesTexHelper(theTexture,theVertices,theNumTriangles,theClipRect,theColor,theDrawMode,mLockedSurfaceDesc.lpSurface,mLockedSurfaceDesc.lPitch,aPixelFormat,tx,ty,blend);
+ UnlockSurface();
+
+ DeleteAllNonSurfaceData();
+}
+
+bool DDImage::Palletize()
+{
+ if (MemoryImage::Palletize())
+ {
+ // Don't keep around the DDSurface if we palletize the image, that
+ // would be a waste of memory
+ DeleteDDSurface();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void DDImage::FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight)
+{
+ if (theSpanCount == 0) return;
+
+ if (Check3D(this))
+ { // ugh!#@$
+ int l = theSpans[0].mX, t = theSpans[0].mY;
+ int r = l + theSpans[0].mWidth, b = t;
+ for (int i = 1; i < theSpanCount; ++i)
+ {
+ l = min(theSpans[i].mX, l);
+ r = max(theSpans[i].mX + theSpans[i].mWidth - 1, r);
+ t = min(theSpans[i].mY, t);
+ b = max(theSpans[i].mY, b);
+ }
+ for (int i = 0; i < theSpanCount; ++i)
+ {
+ theSpans[i].mX -= l;
+ theSpans[i].mY -= t;
+ }
+
+ MemoryImage aTempImage;
+ aTempImage.Create(r-l+1, b-t+1);
+ aTempImage.FillScanLinesWithCoverage(theSpans, theSpanCount, theColor, theDrawMode, theCoverage, theCoverX - l, theCoverY - t, theCoverWidth, theCoverHeight);
+ Blt(&aTempImage, l, t, Rect(0, 0, r-l+1, b-t+1), Color::White, theDrawMode);
+ return;
+ }
+
+ LPDIRECTDRAWSURFACE aSurface = GetSurface();
+
+ if (!LockSurface())
+ return;
+
+ ulong aRMask = mLockedSurfaceDesc.ddpfPixelFormat.dwRBitMask;
+ ulong aGMask = mLockedSurfaceDesc.ddpfPixelFormat.dwGBitMask;
+ ulong aBMask = mLockedSurfaceDesc.ddpfPixelFormat.dwBBitMask;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ {
+ //ushort src_red = (((theColor.mRed * (theColor.mAlpha+1)) >> 8) * aRMask) & aRMask;
+ //ushort src_green = (((theColor.mGreen * (theColor.mAlpha+1)) >> 8) * aGMask) & aGMask;
+ //ushort src_blue = (((theColor.mBlue * (theColor.mAlpha+1)) >> 8) * aBMask) & aBMask;
+ ushort src =
+ (((theColor.mRed * aRMask) >> 8) & aRMask) |
+ (((theColor.mGreen * aGMask) >> 8) & aGMask) |
+ (((theColor.mBlue * aBMask) >> 8) & aBMask);
+ ushort* theBits = (ushort*)mLockedSurfaceDesc.lpSurface;
+
+ for (int i = 0; i < theSpanCount; ++i)
+ {
+ Span* aSpan = &theSpans[i];
+ int x = aSpan->mX - theCoverX;
+ int y = aSpan->mY - theCoverY;
+
+ ushort* aDestPixels = &theBits[aSpan->mY*mWidth + aSpan->mX];
+ const BYTE* aCoverBits = &theCoverage[y*theCoverWidth+x];
+ for (int w = 0; w < aSpan->mWidth; ++w)
+ {
+ int cover = *aCoverBits++;
+ int a = ((cover+1) * theColor.mAlpha) >> 8;
+ int oma = 256 - a;
+ ushort dest = *aDestPixels;
+
+ *(aDestPixels++) =
+ ((((dest & aRMask) * oma + (src & aRMask) * a) >> 8) & aRMask) |
+ ((((dest & aGMask) * oma + (src & aGMask) * a) >> 8) & aGMask) |
+ ((((dest & aBMask) * oma + (src & aBMask) * a) >> 8) & aBMask);
+ }
+ }
+ }
+ else if (mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ //ulong src_red = (((theColor.mRed * (theColor.mAlpha+1)) >> 8) * aRMask) & aRMask;
+ //ulong src_green = (((theColor.mGreen * (theColor.mAlpha+1)) >> 8) * aGMask) & aGMask;
+ //ulong src_blue = (((theColor.mBlue * (theColor.mAlpha+1)) >> 8) * aBMask) & aBMask;
+ ulong src =
+ (((theColor.mRed * aRMask) >> 8) & aRMask) |
+ (((theColor.mGreen * aGMask) >> 8) & aGMask) |
+ (((theColor.mBlue * aBMask) >> 8) & aBMask);
+ ulong* theBits = (ulong*)mLockedSurfaceDesc.lpSurface;
+
+ for (int i = 0; i < theSpanCount; ++i)
+ {
+ Span* aSpan = &theSpans[i];
+ int x = aSpan->mX - theCoverX;
+ int y = aSpan->mY - theCoverY;
+
+ ulong* aDestPixels = &theBits[aSpan->mY*mWidth + aSpan->mX];
+ const BYTE* aCoverBits = &theCoverage[y*theCoverWidth+x];
+ for (int w = 0; w < aSpan->mWidth; ++w)
+ {
+ int cover = *aCoverBits++;
+ int a = ((cover+1) * theColor.mAlpha) >> 8;
+ int oma = 256 - a;
+ ulong dest = *aDestPixels;
+
+ *(aDestPixels++) =
+ ((((dest & aRMask) * oma + (src & aRMask) * a) >> 8) & aRMask) |
+ ((((dest & aGMask) * oma + (src & aGMask) * a) >> 8) & aGMask) |
+ ((((dest & aBMask) * oma + (src & aBMask) * a) >> 8) & aBMask);
+ }
+ }
+ }
+
+ UnlockSurface();
+ DeleteAllNonSurfaceData();
+}
diff --git a/osframework/source/SexyAppFramework/DDImage.h b/osframework/source/SexyAppFramework/DDImage.h
new file mode 100644
index 0000000..e050830
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDImage.h
@@ -0,0 +1,99 @@
+#ifndef __DDIMAGE_H__
+#define __DDIMAGE_H__
+
+#include "MemoryImage.h"
+#include <ddraw.h>
+
+namespace Sexy
+{
+
+class DDInterface;
+class SysFont;
+
+class DDImage : public MemoryImage
+{
+protected:
+ friend class SysFont;
+ void DeleteAllNonSurfaceData();
+
+public:
+ DDInterface* mDDInterface;
+ LPDIRECTDRAWSURFACE mSurface;
+ bool mSurfaceSet;
+ bool mNoLock;
+ bool mVideoMemory;
+ bool mFirstPixelTrans;
+ bool mWantDDSurface;
+ bool mDrawToBits;
+
+ int mLockCount;
+ DDSURFACEDESC mLockedSurfaceDesc;
+
+private:
+ void Init();
+
+public:
+ bool GenerateDDSurface();
+ void DeleteDDSurface();
+ virtual void ReInit();
+ virtual void SetVideoMemory(bool wantVideoMemory);
+ virtual void RehupFirstPixelTrans();
+
+ LPDIRECTDRAWSURFACE GetSurface();
+ virtual void BitsChanged();
+ virtual void CommitBits();
+
+ virtual void NormalFillRect(const Rect& theRect, const Color& theColor);
+ virtual void AdditiveFillRect(const Rect& theRect, const Color& theColor);
+ virtual void NormalBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+ virtual void AdditiveBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+ virtual void NormalDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+ virtual void AdditiveDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+ virtual void NormalDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+ virtual void AdditiveDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+
+
+ virtual void NormalBltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+ virtual void AdditiveBltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+
+ virtual void FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight);
+
+ static bool Check3D(DDImage *theImage);
+ static bool Check3D(Image *theImage);
+
+public:
+ DDImage();
+ DDImage(DDInterface* theDDInterface);
+ virtual ~DDImage();
+
+ virtual bool LockSurface();
+ virtual bool UnlockSurface();
+
+ virtual void SetSurface(LPDIRECTDRAWSURFACE theSurface);
+
+ virtual void Create(int theWidth, int theHeight);
+ virtual ulong* GetBits();
+
+ virtual bool PolyFill3D(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty, bool comvex);
+ virtual void FillRect(const Rect& theRect, const Color& theColor, int theDrawMode);
+ virtual void DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ virtual void DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ virtual void Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode);
+ virtual void BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode);
+ virtual void BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY);
+ virtual void StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch);
+ virtual void BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend);
+ virtual void BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend);
+
+ virtual void BltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode);
+ virtual void StretchBltMirror(Image* theImage, const Rect& theDestRectOrig, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch);
+
+ virtual bool Palletize();
+ virtual void PurgeBits();
+ virtual void DeleteNativeData();
+ virtual void DeleteExtraBuffers();
+};
+
+}
+
+#endif //__DDIMAGE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DDInterface.cpp b/osframework/source/SexyAppFramework/DDInterface.cpp
new file mode 100644
index 0000000..8103cff
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDInterface.cpp
@@ -0,0 +1,1432 @@
+#define INITGUID
+
+#include "DDInterface.h"
+#include "DDImage.h"
+#include "D3DInterface.h"
+#include "D3DTester.h"
+#include "SexyAppBase.h"
+#include "AutoCrit.h"
+#include "Graphics.h"
+#include "PerfTimer.h"
+#include "Debug.h"
+#include "DirectXErrorString.h"
+#include "MemoryImage.h"
+
+using namespace Sexy;
+
+typedef HRESULT (WINAPI *DirectDrawCreateFunc)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
+typedef HRESULT (WINAPI *DirectDrawCreateExFunc)(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter);
+
+extern HMODULE gDDrawDLL;
+static DirectDrawCreateFunc gDirectDrawCreateFunc = NULL;
+static DirectDrawCreateExFunc gDirectDrawCreateExFunc = NULL;
+
+DDInterface::DDInterface(SexyAppBase* theApp)
+{
+ mApp = theApp;
+ mPrimarySurface = NULL;
+ mDrawSurface = NULL;
+ mSecondarySurface = NULL;
+ mScreenImage = NULL;
+ mDD = NULL;
+ mDD7 = NULL;
+ mRedAddTable = NULL;
+ mGreenAddTable = NULL;
+ mBlueAddTable = NULL;
+ mInitialized = false;
+ mVideoOnlyDraw = false;
+ mScanLineFailCount = 0;
+
+ //TODO: Standards, anyone?
+ mNextCursorX = 0;
+ mNextCursorY = 0;
+ mCursorX = 0;
+ mCursorY = 0;
+ mInRedraw = false;
+ //mCursorWidth = 54;
+ //mCursorHeight = 54;
+ mCursorWidth = 64;
+ mCursorHeight = 64;
+ mCursorImage = NULL;
+ mOldCursorArea = NULL;
+ mNewCursorArea = NULL;
+ mHasOldCursorArea = false;
+ mOldCursorArea = NULL;
+ mNewCursorArea = NULL;
+ mNewCursorAreaImage = NULL;
+ mOldCursorAreaImage = NULL;
+ mInitCount = 0;
+ mRefreshRate = 60;
+ mMillisecondsPerFrame = 1000/mRefreshRate;
+
+ mD3DInterface = new D3DInterface;
+ mIs3D = false;
+
+ mD3DTester = NULL;
+
+ gDirectDrawCreateFunc = (DirectDrawCreateFunc)GetProcAddress(gDDrawDLL,"DirectDrawCreate");
+ gDirectDrawCreateExFunc = (DirectDrawCreateExFunc)GetProcAddress(gDDrawDLL,"DirectDrawCreateEx");
+}
+
+DDInterface::~DDInterface()
+{
+ delete [] mRedAddTable;
+ delete [] mGreenAddTable;
+ delete [] mBlueAddTable;
+
+ Cleanup();
+
+ delete mD3DInterface;
+ delete mD3DTester;
+}
+
+std::string DDInterface::ResultToString(int theResult)
+{
+ switch (theResult)
+ {
+ case RESULT_OK:
+ return "RESULT_OK";
+ case RESULT_FAIL:
+ return "RESULT_FAIL";
+ case RESULT_DD_CREATE_FAIL:
+ return "RESULT_DD_CREATE_FAIL";
+ case RESULT_SURFACE_FAIL:
+ return "RESULT_SURFACE_FAIL";
+ case RESULT_EXCLUSIVE_FAIL:
+ return "RESULT_EXCLUSIVE_FAIL";
+ case RESULT_DISPCHANGE_FAIL:
+ return "RESULT_DISPCHANGE_FAIL";
+ case RESULT_INVALID_COLORDEPTH:
+ return "RESULT_INVALID_COLORDEPTH";
+ default:
+ return "RESULT_UNKNOWN";
+ }
+}
+
+bool DDInterface::GotDXError(HRESULT theResult, const char *theContext)
+{
+ if (!SUCCEEDED(theResult))
+ {
+ std::string anError = GetDirectXErrorString(theResult);
+ mErrorString = StrFormat("%s: %s",theContext, anError.c_str());
+
+ return true;
+ }
+ else
+ return false;
+}
+
+
+DDImage* DDInterface::GetScreenImage()
+{
+ return mScreenImage;
+}
+
+HRESULT DDInterface::CreateSurface(DDSURFACEDESC2 *theDesc, LPDIRECTDRAWSURFACE *theSurface, void*)
+{
+ AutoCrit aCrit(mCritSect);
+ HRESULT aResult;
+ if (mDD7 != NULL)
+ {
+ LPDIRECTDRAWSURFACE7 aSurface;
+ aResult = mDD7->CreateSurface(theDesc, &aSurface, NULL);
+ if (!SUCCEEDED(aResult))
+ return aResult;
+
+ aResult = aSurface->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)theSurface);
+ aSurface->Release();
+
+ if (!SUCCEEDED(aResult))
+ return aResult;
+ }
+ else
+ {
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc,sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = theDesc->dwFlags;
+ aDesc.dwHeight = theDesc->dwHeight;
+ aDesc.dwWidth = theDesc->dwWidth;
+ aDesc.lPitch = theDesc->lPitch;
+ aDesc.dwBackBufferCount = theDesc->dwBackBufferCount;
+ aDesc.dwRefreshRate = theDesc->dwRefreshRate;
+ aDesc.dwAlphaBitDepth = theDesc->dwAlphaBitDepth;
+ aDesc.dwReserved = theDesc->dwReserved;
+ aDesc.lpSurface = theDesc->lpSurface;
+ aDesc.ddpfPixelFormat = theDesc->ddpfPixelFormat;
+ aDesc.ddsCaps.dwCaps = theDesc->ddsCaps.dwCaps;
+
+ aResult = mDD->CreateSurface(&aDesc, theSurface, NULL);
+ if (!SUCCEEDED(aResult))
+ return aResult;
+ }
+
+ // Make sure it's 32-bit or 16-bit
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_PIXELFORMAT;
+ mPrimarySurface->GetSurfaceDesc(&aDesc);
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ // If things are stored blue low, green middle, red high, we can optimize a lot of our software rendering based on bit patterns.
+ // This of course does not matter for native data which is already in the correct order (and can be optimized similarly).
+ gOptimizeSoftwareDrawing = aDesc.ddpfPixelFormat.dwBBitMask < aDesc.ddpfPixelFormat.dwGBitMask && aDesc.ddpfPixelFormat.dwGBitMask < aDesc.ddpfPixelFormat.dwRBitMask;
+#endif
+ int aNumBits = aDesc.ddpfPixelFormat.dwRGBBitCount;
+ if (aNumBits!=16 && aNumBits!=32)
+ {
+ (*theSurface)->Release();
+ *theSurface = NULL;
+ return DDERR_INVALIDPIXELFORMAT;
+ }
+
+ return aResult;
+}
+
+void DDInterface::ClearSurface(LPDIRECTDRAWSURFACE theSurface)
+{
+ if (theSurface)
+ {
+ DDSURFACEDESC desc;
+ memset(&desc, 0, sizeof desc);
+ desc.dwSize = sizeof desc;
+ HRESULT hr = theSurface->Lock(NULL, &desc, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL);
+ if ( DD_OK == hr )
+ {
+ DWORD pixelSize = desc.ddpfPixelFormat.dwRGBBitCount / 8;
+ unsigned char* p = (unsigned char*)desc.lpSurface;
+ for ( DWORD row = 0; row < desc.dwHeight; ++row )
+ {
+ memset(p, 0, pixelSize*desc.dwWidth);
+ p += desc.lPitch;
+ }
+ theSurface->Unlock(NULL);
+ }
+ }
+}
+
+bool DDInterface::Do3DTest(HWND theHWND)
+{
+ if (mD3DTester == NULL)
+ {
+ if (mApp->mTest3D || mApp->mAutoEnable3D)
+ {
+ mD3DTester = new D3DTester;
+ mD3DTester->SetVidMemoryConstraints(mApp->mMinVidMemory3D, mApp->mRecommendedVidMemory3D);
+ mD3DTester->TestD3D(theHWND, mDD7);
+
+ if (mApp->mAutoEnable3D && mD3DTester->Is3DRecommended())
+ mIs3D = true;
+
+ if (!mD3DTester->Is3DSupported())
+ mIs3D = false;
+
+ if (mD3DTester->ResultsChanged() && !mD3DTester->Is3DRecommended())
+ mIs3D = false;
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int DDInterface::Init(HWND theWindow, bool IsWindowed)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ mInitialized = false;
+
+ /*DDImageSet aReleasedImageSet;
+
+ DDImageSet::iterator anItr = mDDImageSet.begin();
+ while (anItr != mDDImageSet.end())
+ {
+ DDImage* aDDImage = *anItr;
+
+ if ((aDDImage->mSurface != NULL) || aDDImage->mWantDDSurface || !aDDImage->mKeepBits)
+ {
+ aDDImage->DeleteDDSurface();
+ aReleasedImageSet.insert(aDDImage);
+ }
+
+ ++anItr;
+ }*/
+
+ Cleanup();
+
+ HRESULT aResult;
+ DDSURFACEDESC2 aDesc;
+
+ if (gDirectDrawCreateExFunc != NULL)
+ {
+ aResult = gDirectDrawCreateExFunc(NULL, (LPVOID*)&mDD7, IID_IDirectDraw7, NULL);
+ if (GotDXError(aResult, "DirectDrawCreateEx"))
+ return RESULT_DD_CREATE_FAIL;
+
+ aResult = mDD7->QueryInterface(IID_IDirectDraw, (LPVOID*)&mDD);
+ if (GotDXError(aResult, "QueryrInterface IID_IDirectDraw"))
+ return RESULT_DD_CREATE_FAIL;
+ }
+ else
+ {
+ aResult = gDirectDrawCreateFunc(NULL, &mDD, NULL);
+ }
+
+ if (Do3DTest(theWindow))
+ {
+ if (mD3DTester->ResultsChanged())
+ mApp->Done3dTesting();
+ }
+
+ RECT aRect;
+ GetClientRect(theWindow, &aRect);
+
+ mHWnd = theWindow;
+ mWidth = mApp->mWidth;
+ mHeight = mApp->mHeight;
+ mAspect.Set(mWidth, mHeight);
+ mDesktopWidth = GetSystemMetrics(SM_CXSCREEN);
+ mDesktopHeight = GetSystemMetrics(SM_CYSCREEN);
+ mDesktopAspect.Set(mDesktopWidth, mDesktopHeight);
+ mDisplayWidth = mWidth;
+ mDisplayHeight = mHeight;
+ mDisplayAspect = mAspect;
+ mPresentationRect = Rect( 0, 0, mWidth, mHeight );
+ mApp->mScreenBounds = mPresentationRect;
+ mFullscreenBits = mApp->mFullscreenBits;
+ mIsWindowed = IsWindowed;
+ mHasOldCursorArea = false;
+
+ OutputDebug(_S("Application requests %4lu x %4lu [%2d:%2d]\n"), mWidth, mHeight, mAspect.mNumerator, mAspect.mDenominator);
+
+ if (GotDXError(aResult, "DirectDrawCreate"))
+ return RESULT_DD_CREATE_FAIL;
+
+ if (IsWindowed)
+ {
+ OutputDebug(_S("Hack aspect is [%2d:%2d]\n"), mApp->mWindowAspect.mNumerator, mApp->mWindowAspect.mDenominator);
+
+ if ( mApp->mEnableWindowAspect && mAspect < mApp->mWindowAspect )
+ {
+ mIsWidescreen = true;
+
+ // Setup the window at the hack aspect,
+ // but with the height requested by the application.
+ mDisplayWidth = mHeight * mApp->mWindowAspect;
+ mDisplayHeight = mHeight;
+ mDisplayAspect = mApp->mWindowAspect;
+
+ // resize the window.
+ RECT rc;
+ POINT pt;
+ WINDOWINFO info;
+ ::GetWindowInfo(theWindow, &info);
+ ::GetClientRect(theWindow, &rc);
+ pt.x = rc.left;
+ pt.y = rc.top;
+ ::ClientToScreen(theWindow, &pt);
+ rc.left = pt.x - (mDisplayWidth - mWidth) / 2;
+ rc.top = pt.y - (mDisplayHeight - mHeight) / 2;
+ rc.right = rc.left + mDisplayWidth;
+ rc.bottom = rc.top + mDisplayHeight;
+ ::AdjustWindowRectEx(&rc, info.dwStyle, false, info.dwExStyle);
+ ::MoveWindow(theWindow, max(0, rc.left), max(0, rc.top), rc.right-rc.left, rc.bottom-rc.top, false);
+
+ if ( mApp->mWidescreenAware )
+ {
+ mWidth = mDisplayWidth;
+ mHeight = mDisplayHeight;
+ mAspect = mDisplayAspect;
+
+ mPresentationRect.mWidth = mDisplayWidth;
+ mPresentationRect.mHeight = mDisplayHeight;
+ mPresentationRect.mX = 0;
+ mPresentationRect.mY = 0;
+ }
+ else
+ {
+ // Set the dest rect for drawing the back buffer to the center of
+ // the wide display.
+ mPresentationRect.mWidth = mWidth;
+ mPresentationRect.mHeight = mHeight;
+ mPresentationRect.mX = ( mDisplayWidth - mPresentationRect.mWidth ) / 2;
+ mPresentationRect.mY = 0;
+ }
+ }
+
+ OutputDebug(_S("Window is %4lu x %4lu [%2d:%2d]\n"), mDisplayWidth, mDisplayHeight, mDisplayAspect.mNumerator, mDisplayAspect.mDenominator);
+
+ aResult = mDD->SetCooperativeLevel(theWindow, DDSCL_NORMAL);
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS;
+
+ aDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+ if (mIs3D)
+ aDesc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
+
+ aDesc.dwBackBufferCount = 1;
+ aResult = CreateSurface(&aDesc, &mPrimarySurface, NULL);
+ if (aResult==DDERR_INVALIDPIXELFORMAT) // check for non 16 or 32 bit primary surface
+ return RESULT_INVALID_COLORDEPTH;
+ else if (GotDXError(aResult, "CreateSurface Windowed Primary"))
+ return RESULT_SURFACE_FAIL;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+ if (mIs3D)
+ aDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_3DDEVICE;
+
+ aDesc.dwWidth = mWidth;
+ aDesc.dwHeight = mHeight;
+
+ aResult = CreateSurface(&aDesc, &mDrawSurface, NULL);
+ if (GotDXError(aResult,"CreateSurface Windowed DrawSurface"))
+ return RESULT_SURFACE_FAIL;
+
+ IDirectDrawClipper* aClipper;
+ aResult = mDD->CreateClipper(0, &aClipper, NULL);
+ if (GotDXError(aResult,"CreateClipper Windowed")) return RESULT_FAIL;
+
+ // Associate the clipper with the window
+ aResult = aClipper->SetHWnd(0, theWindow);
+ if (SUCCEEDED(aResult))
+ aResult = mPrimarySurface->SetClipper(aClipper);
+
+ aClipper->Release();
+ }
+ else
+ {
+ OutputDebug(_S("Desktop is %4lu x %4lu [%2d:%2d]\n"), mDesktopWidth, mDesktopHeight, mDesktopAspect.mNumerator, mDesktopAspect.mDenominator);
+
+ if ( mIs3D && mAspect < mDesktopAspect )
+ {
+ mIsWidescreen = true;
+
+ // Set the display mode to the size of the desktop.
+ mDisplayWidth = mDesktopWidth;
+ mDisplayHeight = mDesktopHeight;
+ mDisplayAspect = mDesktopAspect;
+
+ if ( mApp->mWidescreenAware )
+ {
+ // Setup the draw buffer(s) at the same aspect ratio as the desktop,
+ // but with the height requested by the application.
+ mAspect = mDisplayAspect;
+ mWidth = mHeight * mAspect;
+
+ mPresentationRect.mWidth = mDisplayWidth;
+ mPresentationRect.mHeight = mDisplayHeight;
+ mPresentationRect.mX = 0;
+ mPresentationRect.mY = 0;
+ }
+ else
+ {
+ // Set the dest rect for drawing the back buffer to the center of
+ // the wide display.
+ mPresentationRect.mWidth = mWidth * mDisplayHeight / mHeight;
+ mPresentationRect.mHeight = mDisplayHeight;
+ mPresentationRect.mX = ( mDisplayWidth - mPresentationRect.mWidth ) / 2;
+ mPresentationRect.mY = 0;
+ }
+ }
+
+ OutputDebug(_S("Display is %4lu x %4lu [%2d:%2d]\n"), mDisplayWidth, mDisplayHeight, mDisplayAspect.mNumerator, mDisplayAspect.mDenominator);
+
+ aResult = mDD->SetCooperativeLevel(theWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ if (GotDXError(aResult,"SetCooperativeLevel FullScreen"))
+ return RESULT_EXCLUSIVE_FAIL;
+
+ aResult = mDD->SetDisplayMode(mDisplayWidth, mDisplayHeight, mFullscreenBits);
+
+ if (GotDXError(aResult,"SetDisplayMode FullScreen"))
+ return RESULT_DISPCHANGE_FAIL;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
+ DDSCAPS_FLIP |
+ DDSCAPS_COMPLEX/* |
+ ,DDSCAPS_FRONTBUFFER*/;
+ aDesc.dwBackBufferCount = 1;
+
+ if (mIs3D)
+ aDesc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
+
+
+ aResult = CreateSurface(&aDesc, &mPrimarySurface, NULL);
+ if (GotDXError(aResult,"CreateSurface FullScreen Primary"))
+ return RESULT_SURFACE_FAIL;
+
+ DDSCAPS aCaps;
+ ZeroMemory(&aCaps,sizeof(aCaps));
+ aCaps.dwCaps = DDSCAPS_BACKBUFFER;
+ aResult = mPrimarySurface->GetAttachedSurface(&aCaps, &mSecondarySurface);
+
+ if (GotDXError(aResult,"GetAttachedSurface"))
+ return RESULT_SURFACE_FAIL;
+
+ if (mIsWidescreen)
+ {
+ ClearSurface(mPrimarySurface);
+ ClearSurface(mSecondarySurface);
+ }
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+ if (mIs3D)
+ aDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_3DDEVICE;
+
+ aDesc.dwWidth = mWidth;
+ aDesc.dwHeight = mHeight;
+
+ aResult = CreateSurface(&aDesc, &mDrawSurface, NULL);
+ if (GotDXError(aResult, "CreateSurface FullScreen DrawSurface"))
+ return RESULT_SURFACE_FAIL;
+
+ IDirectDrawClipper* aClipper;
+ aResult = mDD->CreateClipper(0, &aClipper, NULL);
+ if (GotDXError(aResult,"CreateClipper FullScreen")) return RESULT_FAIL;
+
+ // Associate the clipper with the window
+ aResult = aClipper->SetHWnd(0, theWindow);
+ if (SUCCEEDED(aResult))
+ aResult = mPrimarySurface->SetClipper(aClipper);
+
+ aClipper->Release();
+
+ if (!mApp->mFullScreenPageFlip)
+ mDD->FlipToGDISurface();
+ }
+
+ OutputDebug(_S("Draw buffer is %4lu x %4lu [%2d:%2d]\n"), mWidth, mHeight, mAspect.mNumerator, mAspect.mDenominator);
+
+ if (FAILED(mDD->GetMonitorFrequency(&mRefreshRate)) || mRefreshRate<60)
+ {
+ mApp->mVSyncBroken = true;
+ mRefreshRate = 60;
+ }
+
+ if (mRefreshRate < 60)
+ {
+ mApp->mVSyncBroken = true;
+ mRefreshRate = 60;
+ }
+ else if (mRefreshRate > 100) // We must have at least 1 Update per UpdateF for demo compatibility
+ {
+ mApp->mVSyncBroken = true;
+ mRefreshRate = 100;
+ }
+
+ mMillisecondsPerFrame = 1000/mRefreshRate;
+
+ // Create the images needed for cursor stuff
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+ aDesc.dwWidth = mCursorWidth;
+ aDesc.dwHeight = mCursorHeight;
+
+ aResult = CreateSurface(&aDesc, &mOldCursorArea, NULL);
+ if (GotDXError(aResult, "CreateSurface OldCursorArea"))
+ return RESULT_SURFACE_FAIL;
+
+ aResult = CreateSurface(&aDesc, &mNewCursorArea, NULL);
+ if (GotDXError(aResult, "CreateSurface NewCursorArea"))
+ return RESULT_SURFACE_FAIL;
+
+ mOldCursorAreaImage = new DDImage(this);
+ mOldCursorAreaImage->SetSurface(mOldCursorArea);
+ mOldCursorAreaImage->SetImageMode(false, false);
+
+ mNewCursorAreaImage = new DDImage(this);
+ mNewCursorAreaImage->SetSurface(mNewCursorArea);
+ mNewCursorAreaImage->SetImageMode(false, false);
+
+ // Get data from the primary surface
+ if (mPrimarySurface != NULL)
+ {
+ DDSURFACEDESC aDesc;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ HRESULT aResult = mPrimarySurface->GetSurfaceDesc(&aDesc);
+
+ if ((aDesc.ddpfPixelFormat.dwRGBBitCount != 16) &&
+ (aDesc.ddpfPixelFormat.dwRGBBitCount != 32))
+ return RESULT_INVALID_COLORDEPTH;
+
+ mRGBBits = aDesc.ddpfPixelFormat.dwRGBBitCount;
+ mRedMask = aDesc.ddpfPixelFormat.dwRBitMask;
+ mGreenMask = aDesc.ddpfPixelFormat.dwGBitMask;
+ mBlueMask = aDesc.ddpfPixelFormat.dwBBitMask;
+
+ int i;
+ for (i = 32; i >= 0; i--)
+ {
+ if (((mRedMask >> i) & 1) != 0)
+ mRedShift = i;
+ if (((mGreenMask >> i) & 1) != 0)
+ mGreenShift = i;
+ if (((mBlueMask >> i) & 1) != 0)
+ mBlueShift = i;
+ }
+
+ for (i = 0; i < 32; i++)
+ {
+ if ((i+mRedShift < 32) && ((mRedMask >> (i+mRedShift)) != 0))
+ mRedBits = i+1;
+ if ((i+mGreenShift < 32) && ((mGreenMask >> (i+mGreenShift)) != 0))
+ mGreenBits = i+1;
+ if ((i+mBlueShift < 32) && ((mBlueMask >> (i+mBlueShift)) != 0))
+ mBlueBits = i+1;
+ }
+
+ delete [] mRedAddTable;
+ delete [] mGreenAddTable;
+ delete [] mBlueAddTable;
+
+ int aMaxR = (1<<mRedBits) - 1;
+ int aMaxG = (1<<mGreenBits) - 1;
+ int aMaxB = (1<<mBlueBits) - 1;
+
+ mRedAddTable = new int[aMaxR*2+1];
+ mGreenAddTable = new int[aMaxG*2+1];
+ mBlueAddTable = new int[aMaxB*2+1];
+
+ for (i = 0; i < aMaxR*2+1; i++)
+ mRedAddTable[i] = min(i, aMaxR);
+ for (i = 0; i < aMaxG*2+1; i++)
+ mGreenAddTable[i] = min(i, aMaxG);
+ for (i = 0; i < aMaxB*2+1; i++)
+ mBlueAddTable[i] = min(i, aMaxB);
+
+ // Create the tables that we will use to convert from
+ // internal color representation to surface representation
+ for (i = 0; i < 256; i++)
+ {
+ mRedConvTable[i] = ((i * mRedMask) / 255) & mRedMask;
+ mGreenConvTable[i] = ((i * mGreenMask) / 255) & mGreenMask;
+ mBlueConvTable[i] = ((i * mBlueMask) / 255) & mBlueMask;
+ }
+ }
+
+ // Generate DDSurfaces for all our... image things
+ /*anItr = aReleasedImageSet.begin();
+ while (anItr != aReleasedImageSet.end())
+ {
+ DDImage* aDDImage = *anItr;
+
+ DDImageSet::iterator aFindItr = mDDImageSet.find(aDDImage);
+ if (aFindItr != mDDImageSet.end())
+ {
+ if (mIs3D)
+ {
+ if (aDDImage->mWantPal)
+ aDDImage->mWantPal = aDDImage->Palletize();
+ }
+ else
+ {
+ //if (aDDImage->mOnlyKeepDDSurface)
+ // aDDImage->OnlyKeepDDSurface();
+ //else if (aDDImage->mWantDDSurface)
+ // aDDImage->GenerateDDSurface();
+ }
+
+ aDDImage->GenerateExtraBuffers();
+
+ }
+
+ ++anItr;
+ }*/
+
+ SetVideoOnlyDraw(mVideoOnlyDraw);
+ if(mIs3D)
+ {
+ if(!mD3DInterface->InitFromDDInterface(this))
+ {
+ mErrorString = "3D init error: ";
+ mErrorString += D3DInterface::mErrorString;
+ return RESULT_3D_FAIL;
+ }
+ }
+
+ mInitCount++;
+ mInitialized = true;
+
+ return RESULT_OK;
+}
+
+void DDInterface::SetVideoOnlyDraw(bool videoOnlyDraw)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ mVideoOnlyDraw = videoOnlyDraw;
+
+ if (mSecondarySurface == NULL)
+ {
+ DDSURFACEDESC2 aDesc;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ aDesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
+ aDesc.dwWidth = mWidth;
+ aDesc.dwHeight = mHeight;
+
+ HRESULT aResult = CreateSurface(&aDesc, &mSecondarySurface, NULL);
+
+ if (FAILED(aResult))
+ mVideoOnlyDraw = false;
+ }
+
+ bool useSecondary = mVideoOnlyDraw;
+ delete mScreenImage;
+ mScreenImage = new DDImage(this);
+ mScreenImage->SetSurface(useSecondary ? mSecondarySurface : mDrawSurface);
+ mScreenImage->mNoLock = mVideoOnlyDraw;
+ mScreenImage->mVideoMemory = mVideoOnlyDraw;
+ mScreenImage->SetImageMode(false, false);
+}
+
+void DDInterface::RemapMouse(int& theX, int& theY)
+{
+ if (mInitialized)
+ {
+ theX = ( theX - mPresentationRect.mX ) * mWidth / mPresentationRect.mWidth;
+ theY = ( theY - mPresentationRect.mY ) * mHeight / mPresentationRect.mHeight;
+ }
+}
+
+ulong DDInterface::GetColorRef(ulong theRGB)
+{
+ DDSURFACEDESC aDesc;
+
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ HRESULT aResult = mPrimarySurface->GetSurfaceDesc(&aDesc);
+
+ BYTE bRed = (BYTE) ((theRGB >> 16) & 0xFF);
+ BYTE bGreen = (BYTE) ((theRGB >> 8) & 0xFF);
+ BYTE bBlue = (BYTE) ((theRGB ) & 0xFF);
+
+ ulong aColor;
+ aColor = ((DWORD(((LONGLONG)bRed * (LONGLONG)aDesc.ddpfPixelFormat.dwRBitMask) / 255) & aDesc.ddpfPixelFormat.dwRBitMask) |
+ (DWORD(((LONGLONG)bGreen * (LONGLONG)aDesc.ddpfPixelFormat.dwGBitMask) / 255) & aDesc.ddpfPixelFormat.dwGBitMask) |
+ (DWORD(((LONGLONG)bBlue * (LONGLONG)aDesc.ddpfPixelFormat.dwBBitMask) / 255) & aDesc.ddpfPixelFormat.dwBBitMask));
+
+ return aColor;
+}
+
+void DDInterface::AddDDImage(DDImage* theDDImage)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ mDDImageSet.insert(theDDImage);
+}
+
+void DDInterface::RemoveDDImage(DDImage* theDDImage)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ DDImageSet::iterator anItr = mDDImageSet.find(theDDImage);
+ if (anItr != mDDImageSet.end())
+ mDDImageSet.erase(anItr);
+}
+
+void DDInterface::Remove3DData(MemoryImage* theImage) // for 3d texture cleanup
+{
+ mD3DInterface->RemoveMemoryImage(theImage);
+}
+
+void DDInterface::Cleanup()
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ mInitialized = false;
+ mD3DInterface->Cleanup();
+
+ if (mOldCursorAreaImage != NULL)
+ {
+ delete mOldCursorAreaImage;
+ mOldCursorAreaImage = NULL;
+ }
+
+ if (mNewCursorAreaImage != NULL)
+ {
+ delete mNewCursorAreaImage;
+ mNewCursorAreaImage = NULL;
+ }
+
+ if (mOldCursorArea != NULL)
+ {
+ mOldCursorArea->Release();
+ mOldCursorArea = NULL;
+ }
+
+ if (mNewCursorArea != NULL)
+ {
+ mNewCursorArea->Release();
+ mNewCursorArea = NULL;
+ }
+
+ if (mScreenImage != NULL)
+ {
+ delete mScreenImage;
+ mScreenImage = NULL;
+ }
+
+ if (mDrawSurface != NULL)
+ {
+ mDrawSurface->Release();
+ mDrawSurface = NULL;
+ }
+
+ if (mSecondarySurface != NULL)
+ {
+ mSecondarySurface->Release();
+ mSecondarySurface = NULL;
+ }
+
+ if (mPrimarySurface != NULL)
+ {
+ mPrimarySurface->Release();
+ mPrimarySurface = NULL;
+ }
+
+ if (mDD != NULL)
+ {
+ mDD->SetCooperativeLevel(mHWnd, DDSCL_NORMAL);
+ mDD->Release();
+ mDD = NULL;
+ }
+
+ if (mDD7 != NULL)
+ {
+ mDD7->Release();
+ mDD7 = NULL;
+ }
+}
+
+bool DDInterface::CopyBitmap(LPDIRECTDRAWSURFACE theSurface, HBITMAP theBitmap, int theX, int theY, int theWidth, int theHeight)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ HRESULT hr;
+
+ if (theBitmap == NULL || theSurface == NULL) return false;
+
+ // Make sure this surface is restored.
+ theSurface->Restore();
+
+ // Get size of the bitmap
+ BITMAP bmBitmap;
+ GetObject(theBitmap, sizeof(bmBitmap), &bmBitmap);
+ theWidth = (theWidth == 0) ? bmBitmap.bmWidth : theWidth;
+ theHeight = (theHeight == 0) ? bmBitmap.bmHeight : theHeight;
+
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
+ hr = theSurface->GetSurfaceDesc(&aDesc);
+ if (FAILED(hr)) return false;
+
+ // Create memory DC
+ HDC hdcImage = CreateCompatibleDC(NULL);
+ if (hdcImage != NULL)
+ {
+ // Select bitmap into memory DC
+ HBITMAP anOldBitmap = (HBITMAP)SelectObject(hdcImage, theBitmap);
+
+ // Get surface DC
+ HDC hdc;
+ hr = theSurface->GetDC(&hdc);
+ if (SUCCEEDED(hr))
+ {
+ // Copy the bitmap. Use BitBlt, if possible, otherwise use
+ // StretchBlt
+ if (theWidth == aDesc.dwWidth && theHeight == aDesc.dwHeight)
+ {
+ BitBlt(hdc, 0, 0, theWidth, theHeight, hdcImage, theX, theY, SRCCOPY);
+ }
+ else
+ {
+ StretchBlt(hdc, 0, 0, aDesc.dwWidth, aDesc.dwHeight, hdcImage,
+ theX, theY, theWidth, theHeight, SRCCOPY);
+ }
+
+ // Release surface DC
+ theSurface->ReleaseDC(hdc);
+ }
+
+ // Select old bitmap into the memory DC and delete the DC
+ SelectObject(hdcImage, anOldBitmap);
+ DeleteDC(hdcImage);
+ }
+ else return false;
+
+ return true;
+}
+
+extern std::fstream gStreamThing;
+
+bool DDInterface::Redraw(Rect* theClipRect)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ if (!mInitialized)
+ return false;
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ mInRedraw = true;
+
+ if(mIs3D)
+ {
+ if (!mD3DInterface->mErrorString.empty())
+ {
+ mInRedraw = false;
+ mIs3D = false;
+ return false;
+ }
+
+ mD3DInterface->Flush();
+ }
+
+ RECT aDestRect;
+ RECT aSrcRect;
+ if (NULL == theClipRect || mIsWidescreen)
+ {
+ // ClipRect cannot be supported when the draw surface and
+ // primary surface are not the same size in widescreen mode.
+ aDestRect = mPresentationRect.ToRECT();
+ aSrcRect = Rect(0, 0, mWidth, mHeight).ToRECT();
+ }
+ else
+ {
+ aDestRect = theClipRect->ToRECT();
+ aSrcRect = theClipRect->ToRECT();
+ }
+
+ if ( mIsWidescreen )
+ {
+ aBltFX.dwDDFX = DDBLTFX_ARITHSTRETCHY;
+ }
+
+ POINT aPoint = {0, 0};
+
+ ClientToScreen(mHWnd, &aPoint);
+ OffsetRect(&aDestRect, aPoint.x, aPoint.y);
+
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc,sizeof(&aDesc));
+ aDesc.dwSize=sizeof(aDesc);
+ mDrawSurface->Lock(NULL,&aDesc,DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_READONLY ,0);
+ mDrawSurface->Unlock(NULL);
+
+ if (mIsWindowed)
+ {
+ HRESULT aResult;
+
+ //DWORD aScanLine;
+ //mDD->GetScanLine(&aScanLine);
+
+ int aScreenHeight = GetSystemMetrics(SM_CYSCREEN);
+
+ if (!mVideoOnlyDraw)
+ {
+ mCursorX = mNextCursorX;
+ mCursorY = mNextCursorY;
+
+ DrawCursorTo(mDrawSurface, false);
+
+ if ((mApp->mWaitForVSync) && (!mApp->mSoftVSyncWait))
+ {
+ bool scanLineFail = false;
+
+ if (mScanLineFailCount >= 3)
+ scanLineFail = true;
+
+ if (!scanLineFail)
+ {
+ int aHalfMarkClient = mApp->mHeight / 2;
+ int aHalfMarkScreen = aDestRect.top + aHalfMarkClient;
+ int aBotMarkScreen = aDestRect.top + mHeight;
+
+ DWORD aScanLine = 0x7FFFFFFF;
+
+ bool wasLess = false;
+
+ DWORD aTopStartTick = GetTickCount();
+
+ for (;;)
+ {
+ aResult = mDD->GetScanLine(&aScanLine);
+
+ if (aResult == DD_OK)
+ {
+ // Wait until we scan below half way on the window
+ int aHalfMarkDist = aHalfMarkScreen - aScanLine;
+
+ if ((aHalfMarkDist <= 0) || ((int) aScanLine >= aScreenHeight))
+ {
+ if (wasLess)
+ break;
+ }
+ else
+ {
+ wasLess = true;
+ }
+ }
+ else
+ {
+ if (aResult == DDERR_VERTICALBLANKINPROGRESS )
+ {
+ if (wasLess)
+ break;
+ }
+ else
+ {
+ scanLineFail = true;
+ break;
+ }
+ }
+
+ DWORD aTickNow = GetTickCount();
+ if (aTickNow - aTopStartTick >= 200)
+ {
+ // It shouldn't take this long
+ scanLineFail = true;
+ break;
+ }
+ }
+
+ if (!scanLineFail)
+ {
+ mScanLineFailCount = 0;
+
+ RECT aTopDestRect = {aDestRect.left, aDestRect.top, aDestRect.right, aHalfMarkScreen};
+ RECT aTopSrcRect = {aSrcRect.left, aSrcRect.top, aSrcRect.right, aHalfMarkClient};
+ aResult = mPrimarySurface->Blt(&aTopDestRect, mDrawSurface, &aTopSrcRect, DDBLT_WAIT, &aBltFX);
+
+ DWORD aLastScanLine = aScanLine;
+
+ for (;;)
+ {
+ if (SUCCEEDED(mDD->GetScanLine(&aScanLine)))
+ {
+ // Wait until we scan below the bottom of the window
+ int aHalfMarkDist = aBotMarkScreen - aScanLine;
+ if ((aScanLine < aLastScanLine) || (aHalfMarkDist <= 0))
+ break;
+ }
+ }
+
+ RECT aBotDestRect = {aDestRect.left, aHalfMarkScreen, aDestRect.right, aDestRect.bottom};
+ RECT aBotSrcRect = {aSrcRect.left, aHalfMarkClient, aSrcRect.right, aSrcRect.bottom};
+ aResult = mPrimarySurface->Blt(&aBotDestRect, mDrawSurface, &aBotSrcRect, DDBLT_WAIT, &aBltFX);
+ }
+ else
+ {
+ mScanLineFailCount++;
+ }
+ }
+
+ if (scanLineFail)
+ {
+ mDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0);
+ aResult = mPrimarySurface->Blt(&aDestRect, mDrawSurface, &aSrcRect, DDBLT_WAIT, &aBltFX);
+ }
+ }
+ else
+ {
+ aResult = mPrimarySurface->Blt(&aDestRect, mDrawSurface, &aSrcRect, DDBLT_WAIT, &aBltFX);
+ }
+
+ if (mHasOldCursorArea)
+ {
+ // Restore from the drawn surface, incase we don't do a redraw
+ // of the drawn surface by next Redraw
+ RestoreOldCursorAreaFrom(mDrawSurface, false);
+
+ // Set it back to true so it gets removed from the primary
+ // surface when we move the mouse
+ mHasOldCursorArea = true;
+ }
+ }
+ else
+ {
+ if ((mApp->mWaitForVSync) && (!mApp->mSoftVSyncWait))
+ mDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0);
+
+ mCursorX = mNextCursorX;
+ mCursorY = mNextCursorY;
+
+ DrawCursorTo(mSecondarySurface, true);
+ aResult = mPrimarySurface->Blt(&aDestRect, mSecondarySurface, &aSrcRect, DDBLT_WAIT, &aBltFX);
+ }
+
+ mInRedraw = false;
+ return !GotDXError(aResult,"Redraw Windowed");
+ }
+ else
+ {
+ // Don't flip away from the GDI surface during the TryMedia purchasing process
+ if (!mApp->mNoDefer && mApp->mFullScreenPageFlip)
+ {
+ if (!mVideoOnlyDraw)
+ HRESULT aResult = mSecondarySurface->Blt(&aDestRect, mDrawSurface, &aSrcRect, DDBLT_WAIT, &aBltFX);
+
+ mCursorX = mNextCursorX;
+ mCursorY = mNextCursorY;
+
+ DrawCursorTo(mSecondarySurface, true);
+
+ HRESULT aResult = mPrimarySurface->Flip(NULL, DDFLIP_WAIT);
+
+ mInRedraw = false;
+ return !GotDXError(aResult,"Redraw FullScreen Flip");
+ }
+ else
+ {
+ HRESULT aResult = mPrimarySurface->Blt(&aDestRect, mDrawSurface, &aSrcRect, DDBLT_WAIT, &aBltFX);
+
+ mInRedraw = false;
+ return !GotDXError(aResult,"Redraw FullScreen Blt");
+ }
+ }
+}
+
+void DDInterface::RestoreOldCursorAreaFrom(LPDIRECTDRAWSURFACE theSurface, bool adjust)
+{
+ if ((mHasOldCursorArea) && (mPrimarySurface != NULL))
+ {
+ Rect aSexyScreenRect(
+ mCursorX - (mCursorWidth / 2),
+ mCursorY - (mCursorHeight / 2),
+ mCursorWidth,
+ mCursorHeight);
+
+ Rect aClippedScreenRect = aSexyScreenRect.Intersection(Rect(0, 0, mWidth, mHeight));
+
+ Rect aSexyLocalRect(
+ aClippedScreenRect.mX - aSexyScreenRect.mX,
+ aClippedScreenRect.mY - aSexyScreenRect.mY,
+ aClippedScreenRect.mWidth,
+ aClippedScreenRect.mHeight);
+
+ if (adjust)
+ {
+ POINT aPoint = {0, 0};
+ ClientToScreen(mHWnd, &aPoint);
+ aClippedScreenRect.Offset(aPoint.x, aPoint.y);
+ }
+
+ RECT aLocalRect = aSexyLocalRect.ToRECT();
+ RECT aScreenRect = aClippedScreenRect.ToRECT();
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ // From mNewCursorArea to theSurface
+ HRESULT aResult = theSurface->Blt(&aScreenRect, mOldCursorArea, &aLocalRect, DDBLT_WAIT, &aBltFX);
+
+ mHasOldCursorArea = false;
+ }
+}
+
+void DDInterface::DrawCursorTo(LPDIRECTDRAWSURFACE theSurface, bool adjust)
+{
+ if ((mCursorImage != NULL) && (mPrimarySurface != NULL))
+ {
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ HRESULT aResult = mPrimarySurface->GetSurfaceDesc(&aDesc);
+ Rect aDestSurfaceRect(0, 0, aDesc.dwWidth, aDesc.dwHeight);
+
+ Rect aSexyScreenRect(
+ mCursorX - (mCursorWidth / 2),
+ mCursorY - (mCursorHeight / 2),
+ mCursorWidth,
+ mCursorHeight);
+
+ Rect aClippedScreenRect = aSexyScreenRect.Intersection(mPresentationRect);
+
+ Rect aSexyLocalRect(
+ aClippedScreenRect.mX - aSexyScreenRect.mX,
+ aClippedScreenRect.mY - aSexyScreenRect.mY,
+ aClippedScreenRect.mWidth,
+ aClippedScreenRect.mHeight);
+
+ if (adjust)
+ {
+ POINT aPoint = {0, 0};
+ ClientToScreen(mHWnd, &aPoint);
+ aClippedScreenRect.Offset(aPoint.x, aPoint.y);
+ }
+
+ RECT aLocalRect = aSexyLocalRect.ToRECT();
+ RECT aScreenRect = aClippedScreenRect.ToRECT();
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ // From theSurface to mOldCursorArea
+ aResult = mOldCursorArea->Blt(&aLocalRect, theSurface, &aScreenRect, DDBLT_WAIT, &aBltFX);
+ if (aResult != DD_OK)
+ {
+ // Try to clip it now. We don't ALWAYS want to clip it, though
+ Rect aPrevRect = aClippedScreenRect;
+ aClippedScreenRect = aClippedScreenRect.Intersection(aDestSurfaceRect);
+
+ aSexyLocalRect.mX += (aClippedScreenRect.mX - aPrevRect.mX);
+ aSexyLocalRect.mY += (aClippedScreenRect.mY - aPrevRect.mY);
+ aSexyLocalRect.mWidth = aClippedScreenRect.mWidth;
+ aSexyLocalRect.mHeight = aClippedScreenRect.mHeight;
+
+ aLocalRect = aSexyLocalRect.ToRECT();
+ aScreenRect = aClippedScreenRect.ToRECT();
+
+ aResult = mOldCursorArea->Blt(&aLocalRect, theSurface, &aScreenRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+ }
+
+ mHasOldCursorArea = aResult == DD_OK;
+
+ // Kindof a hack, since we only use this for mDrawSurace
+ if (theSurface == mDrawSurface && !mIs3D)
+ {
+ // Draw directly to the screen image, instead of indirectly through mNewCursorArea
+ Graphics g(mScreenImage);
+ g.DrawImage(mCursorImage,
+ mCursorX - (mCursorWidth / 2) + (mCursorWidth - mCursorImage->mWidth)/2,
+ mCursorY - (mCursorHeight / 2) + (mCursorHeight - mCursorImage->mHeight)/2);
+ }
+ else
+ {
+ // From mOldCursorArea to mNewCursorArea
+ aResult = mNewCursorArea->Blt(&aLocalRect, mOldCursorArea, &aLocalRect, DDBLT_WAIT, &aBltFX);
+
+ // Draw image to mNewCursorAreaImage
+ Graphics aNewCursorAreaG(mNewCursorAreaImage);
+ aNewCursorAreaG.DrawImage(mCursorImage,
+ (mCursorWidth - mCursorImage->mWidth)/2,
+ (mCursorHeight - mCursorImage->mHeight)/2);
+
+ // From mNewCursorArea to theSurface
+ aResult = theSurface->Blt(&aScreenRect, mNewCursorArea, &aLocalRect, DDBLT_WAIT, &aBltFX);
+ }
+ }
+ else
+ mHasOldCursorArea = false;
+}
+
+void DDInterface::MoveCursorTo(LPDIRECTDRAWSURFACE theSurface, bool adjust, int theNewCursorX, int theNewCursorY)
+{
+ DBG_ASSERT(mHasOldCursorArea);
+
+ if ((mCursorImage != NULL) && (mPrimarySurface != NULL))
+ {
+ DDSURFACEDESC aDesc;
+ ZeroMemory(&aDesc, sizeof(aDesc));
+ aDesc.dwSize = sizeof(aDesc);
+ aDesc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ HRESULT aResult = mPrimarySurface->GetSurfaceDesc(&aDesc);
+ Rect aDestSurfaceRect(0, 0, aDesc.dwWidth, aDesc.dwHeight);
+
+ // OLD RECTANGLES
+ Rect aSexyScreenRect(
+ mCursorX - (mCursorWidth / 2),
+ mCursorY - (mCursorHeight / 2),
+ mCursorWidth,
+ mCursorHeight);
+
+ Rect aClippedScreenRect = aSexyScreenRect.Intersection(mPresentationRect);
+
+ Rect aSexyLocalRect(
+ aClippedScreenRect.mX - aSexyScreenRect.mX,
+ aClippedScreenRect.mY - aSexyScreenRect.mY,
+ aClippedScreenRect.mWidth,
+ aClippedScreenRect.mHeight);
+ if (adjust)
+ {
+ POINT aPoint = {0, 0};
+ ClientToScreen(mHWnd, &aPoint);
+ aClippedScreenRect.Offset(aPoint.x, aPoint.y);
+ //aClippedScreenRect = aClippedScreenRect.Intersection(aDestSurfaceRect);
+ }
+
+ aSexyLocalRect.mWidth = aClippedScreenRect.mWidth;
+ aSexyLocalRect.mHeight = aClippedScreenRect.mHeight;
+
+ RECT aLocalRect = aSexyLocalRect.ToRECT();
+ RECT aScreenRect = aClippedScreenRect.ToRECT();
+
+ // NEW RECTANGLES
+ Rect aNewSexyScreenRect(
+ theNewCursorX - (mCursorWidth / 2),
+ theNewCursorY - (mCursorHeight / 2),
+ mCursorWidth,
+ mCursorHeight);
+
+ Rect aNewClippedScreenRect = aNewSexyScreenRect.Intersection(mPresentationRect);
+ Rect aNewSexyLocalRect(
+ aNewClippedScreenRect.mX - aNewSexyScreenRect.mX,
+ aNewClippedScreenRect.mY - aNewSexyScreenRect.mY,
+ aNewClippedScreenRect.mWidth,
+ aNewClippedScreenRect.mHeight);
+ if (adjust)
+ {
+ POINT aPoint = {0, 0};
+ ClientToScreen(mHWnd, &aPoint);
+ aNewClippedScreenRect.Offset(aPoint.x, aPoint.y);
+ //aNewClippedScreenRect = aNewClippedScreenRect.Intersection(aDestSurfaceRect);
+ }
+
+ aNewSexyLocalRect.mWidth = aNewClippedScreenRect.mWidth;
+ aNewSexyLocalRect.mHeight = aNewClippedScreenRect.mHeight;
+
+ RECT aNewLocalRect = aNewSexyLocalRect.ToRECT();
+ RECT aNewScreenRect = aNewClippedScreenRect.ToRECT();
+
+ // Do drawing stuff now
+
+ DDBLTFX aBltFX;
+ ZeroMemory(&aBltFX, sizeof(aBltFX));
+ aBltFX.dwSize = sizeof(aBltFX);
+
+ // From theSurface to mNewCursorArea
+ // It may still have some of the old cursor on it though, since we haven't restored
+ // that area yet
+
+ aResult = mNewCursorArea->Blt(&aNewLocalRect, theSurface, &aNewScreenRect, DDBLT_WAIT, &aBltFX);
+ if (aResult != DD_OK)
+ {
+ // Try to clip it now. We don't ALWAYS want to clip it, though
+ Rect aPrevRect = aNewClippedScreenRect;
+ aNewClippedScreenRect = aNewClippedScreenRect.Intersection(aDestSurfaceRect);
+
+ aNewSexyLocalRect.mX += (aNewClippedScreenRect.mX - aPrevRect.mX);
+ aNewSexyLocalRect.mY += (aNewClippedScreenRect.mY - aPrevRect.mY);
+ aNewSexyLocalRect.mWidth = aNewClippedScreenRect.mWidth;
+ aNewSexyLocalRect.mHeight = aNewClippedScreenRect.mHeight;
+
+ aNewLocalRect = aNewSexyLocalRect.ToRECT();
+ aNewScreenRect = aNewClippedScreenRect.ToRECT();
+
+ aResult = mNewCursorArea->Blt(&aNewLocalRect, theSurface, &aNewScreenRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+ }
+ //DBG_ASSERT(aResult == DD_OK);
+
+ // Figure out the overlapping area from the source
+ Rect aCursorAreaRect(0, 0, mCursorWidth, mCursorHeight);
+ Rect aSexyOrigSrcAreaRect(aCursorAreaRect);
+ aSexyOrigSrcAreaRect.Offset(theNewCursorX - mCursorX, theNewCursorY - mCursorY);
+ Rect aSexySrcAreaRect = aSexyOrigSrcAreaRect.Intersection(aCursorAreaRect);
+
+ // Does the new cursor area overlap with the old one?
+ if ((aSexySrcAreaRect.mWidth > 0) || (aSexySrcAreaRect.mHeight > 0))
+ {
+ Rect aSexyDestAreaRect(
+ aSexySrcAreaRect.mX - aSexyOrigSrcAreaRect.mX,
+ aSexySrcAreaRect.mY - aSexyOrigSrcAreaRect.mY,
+ aSexySrcAreaRect.mWidth, aSexySrcAreaRect.mHeight);
+
+ RECT aSrcAreaRect = aSexySrcAreaRect.ToRECT();
+ RECT aDestAreaRect = aSexyDestAreaRect.ToRECT();
+
+ // Restore old area from new area
+ // This will give us our new pure OLD buffer
+ mNewCursorArea->Blt(&aDestAreaRect, mOldCursorArea, &aSrcAreaRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+
+ // Draw offset image to mOldCursorAreaImage. This is to avoid flicker
+ Graphics aOldCursorAreaG(mOldCursorAreaImage);
+ aOldCursorAreaG.DrawImage(mCursorImage,
+ theNewCursorX - mCursorX + (mCursorWidth - mCursorImage->mWidth)/2,
+ theNewCursorY - mCursorY + (mCursorHeight - mCursorImage->mHeight)/2);
+ }
+
+ // Restore the old cursor area
+ aResult = theSurface->Blt(&aScreenRect, mOldCursorArea, &aLocalRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+
+ // The screen is now PURE and restored
+
+ // Move the new cursor area to the old one, since this is what we will have to
+ // use to redraw the old area
+ RECT aFullAreaRect = {0, 0, mCursorWidth, mCursorHeight};
+ aResult = mOldCursorArea->Blt(&aFullAreaRect, mNewCursorArea, &aFullAreaRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+
+ // Draw image to mNewCursorAreaImage, preparing to draw it to the screen
+ Graphics aNewCursorAreaG(mNewCursorAreaImage);
+ aNewCursorAreaG.DrawImage(mCursorImage,
+ (mCursorWidth - mCursorImage->mWidth)/2,
+ (mCursorHeight - mCursorImage->mHeight)/2);
+
+ // From mNewCursorArea to theSurface
+ aResult = theSurface->Blt(&aNewScreenRect, mNewCursorArea, &aNewLocalRect, DDBLT_WAIT, &aBltFX);
+ //DBG_ASSERT(aResult == DD_OK);
+
+ // The cursor is now fully moved
+ mCursorX = theNewCursorX;
+ mCursorY = theNewCursorY;
+ }
+ else
+ mHasOldCursorArea = false;
+}
+
+bool DDInterface::SetCursorImage(Image* theImage)
+{
+ AutoCrit anAutoCrit(mCritSect);
+
+ if (mCursorImage != theImage)
+ {
+ // Wait until next Redraw or cursor move to draw new cursor
+ mCursorImage = theImage;
+ return true;
+ }
+ else
+ return false;
+}
+
+void DDInterface::SetCursorPos(int theCursorX, int theCursorY)
+{
+ mNextCursorX = theCursorX;
+ mNextCursorY = theCursorY;
+
+ if (mInRedraw)
+ return;
+
+ AutoCrit anAutoCrit(mCritSect);
+
+ if (mHasOldCursorArea)
+ {
+ MoveCursorTo(mPrimarySurface, true, theCursorX, theCursorY);
+ }
+ else
+ {
+ mCursorX = theCursorX;
+ mCursorY = theCursorY;
+ DrawCursorTo(mPrimarySurface, true);
+ }
+}
diff --git a/osframework/source/SexyAppFramework/DDInterface.h b/osframework/source/SexyAppFramework/DDInterface.h
new file mode 100644
index 0000000..26e78a2
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DDInterface.h
@@ -0,0 +1,136 @@
+#ifndef __DDINTERFACE_H__
+#define __DDINTERFACE_H__
+
+#include "Common.h"
+#include "CritSect.h"
+#include "NativeDisplay.h"
+#include "Rect.h"
+#include "Ratio.h"
+
+#include <ddraw.h>
+
+namespace Sexy
+{
+
+class SexyAppBase;
+class DDImage;
+class Image;
+class MemoryImage;
+class D3DInterface;
+class D3DTester;
+
+typedef std::set<DDImage*> DDImageSet;
+
+class DDInterface : public NativeDisplay
+{
+public:
+ enum
+ {
+ RESULT_OK = 0,
+ RESULT_FAIL = 1,
+ RESULT_DD_CREATE_FAIL = 2,
+ RESULT_SURFACE_FAIL = 3,
+ RESULT_EXCLUSIVE_FAIL = 4,
+ RESULT_DISPCHANGE_FAIL = 5,
+ RESULT_INVALID_COLORDEPTH = 6,
+ RESULT_3D_FAIL = 7
+ };
+
+ SexyAppBase* mApp;
+ D3DInterface* mD3DInterface;
+ D3DTester* mD3DTester;
+ bool mIs3D;
+
+ CritSect mCritSect;
+ bool mInRedraw;
+ LPDIRECTDRAW mDD;
+ LPDIRECTDRAW7 mDD7;
+ LPDIRECTDRAWSURFACE mPrimarySurface;
+ LPDIRECTDRAWSURFACE mSecondarySurface;
+ LPDIRECTDRAWSURFACE mDrawSurface;
+ int mWidth;
+ int mHeight;
+ Ratio mAspect;
+ int mDesktopWidth;
+ int mDesktopHeight;
+ Ratio mDesktopAspect;
+ bool mIsWidescreen;
+ int mDisplayWidth;
+ int mDisplayHeight;
+ Ratio mDisplayAspect;
+
+ Rect mPresentationRect;
+ int mFullscreenBits;
+ DWORD mRefreshRate;
+ DWORD mMillisecondsPerFrame;
+ int mScanLineFailCount;
+
+ int* mRedAddTable;
+ int* mGreenAddTable;
+ int* mBlueAddTable;
+
+ ulong mRedConvTable[256];
+ ulong mGreenConvTable[256];
+ ulong mBlueConvTable[256];
+
+ bool mInitialized;
+ HWND mHWnd;
+ bool mIsWindowed;
+ DDImage* mScreenImage;
+ DDImageSet mDDImageSet;
+ bool mVideoOnlyDraw;
+ ulong mInitCount;
+
+ int mCursorWidth;
+ int mCursorHeight;
+ int mNextCursorX;
+ int mNextCursorY;
+ int mCursorX;
+ int mCursorY;
+ Image* mCursorImage;
+ bool mHasOldCursorArea;
+ LPDIRECTDRAWSURFACE mOldCursorArea;
+ LPDIRECTDRAWSURFACE mNewCursorArea;
+ DDImage* mOldCursorAreaImage;
+ DDImage* mNewCursorAreaImage;
+
+ std::string mErrorString;
+
+public:
+ bool CopyBitmap(LPDIRECTDRAWSURFACE theSurface, HBITMAP TheBitmap, int theX, int theY, int theWidth, int theHeight);
+ ulong GetColorRef(ulong theRGB);
+ void AddDDImage(DDImage* theDDImage);
+ void RemoveDDImage(DDImage* theDDImage);
+ void Remove3DData(MemoryImage* theImage); // for 3d texture cleanup
+
+ void Cleanup();
+ bool GotDXError(HRESULT theResult, const char *theContext = "");
+
+ void RestoreOldCursorAreaFrom(LPDIRECTDRAWSURFACE theSurface, bool adjust);
+ void DrawCursorTo(LPDIRECTDRAWSURFACE theSurface, bool adjust);
+ void MoveCursorTo(LPDIRECTDRAWSURFACE theSurface, bool adjust, int theNewCursorX, int theNewCursorY);
+
+ HRESULT CreateSurface(DDSURFACEDESC2 *theDesc, LPDIRECTDRAWSURFACE *theSurface, void*);
+ void ClearSurface(LPDIRECTDRAWSURFACE theSurface);
+ bool Do3DTest(HWND theHWND);
+
+public:
+ DDInterface(SexyAppBase* theApp);
+ virtual ~DDInterface();
+
+ static std::string ResultToString(int theResult);
+
+ DDImage* GetScreenImage();
+ int Init(HWND theWindow, bool IsWindowed);
+ bool Redraw(Rect* theClipRect = NULL);
+ void SetVideoOnlyDraw(bool videoOnly);
+ void RemapMouse(int& theX, int& theY);
+
+ bool SetCursorImage(Image* theImage);
+ void SetCursorPos(int theCursorX, int theCursorY);
+};
+
+}
+
+#endif //__DDINTERFACE_H__
+
diff --git a/osframework/source/SexyAppFramework/DSoundInstance.cpp b/osframework/source/SexyAppFramework/DSoundInstance.cpp
new file mode 100644
index 0000000..305c83b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DSoundInstance.cpp
@@ -0,0 +1,177 @@
+#include "DSoundInstance.h"
+#include "DSoundManager.h"
+
+using namespace Sexy;
+
+DSoundInstance::DSoundInstance(DSoundManager* theSoundManager, LPDIRECTSOUNDBUFFER theSourceSound)
+{
+ mSoundManagerP = theSoundManager;
+ mReleased = false;
+ mAutoRelease = false;
+ mHasPlayed = false;
+ mSourceSoundBuffer = theSourceSound;
+ mSoundBuffer = NULL;
+
+ mBaseVolume = 1.0;
+ mBasePan = 0;
+
+ mVolume = 1.0;
+ mPan = 0;
+
+ mDefaultFrequency = 44100;
+
+ HRESULT hr;
+
+ if (mSourceSoundBuffer != NULL)
+ {
+ hr=mSoundManagerP->mDirectSound->DuplicateSoundBuffer(mSourceSoundBuffer, &mSoundBuffer);
+ if (hr!=DS_OK)
+ {
+ switch (hr)
+ {
+ case DSERR_ALLOCATED: MessageBoxA(0,"DSERR_ALLOCATED","Hey",MB_OK);break;
+ case DSERR_INVALIDCALL: MessageBoxA(0,"DSERR_INVALIDCALL","Hey",MB_OK);break;
+ case DSERR_INVALIDPARAM: MessageBoxA(0,"DSERR_INVALIDPARAM","Hey",MB_OK);break;
+ case DSERR_OUTOFMEMORY: MessageBoxA(0,"DSERR_OUTOFMEMORY","Hey",MB_OK);break;
+ case DSERR_UNINITIALIZED: MessageBoxA(0,"DSERR_UNINITIALIZED","Hey",MB_OK);break;
+ }
+ exit(0);
+ }
+
+ mSoundBuffer->GetFrequency(&mDefaultFrequency);
+ }
+
+ RehupVolume();
+}
+
+DSoundInstance::~DSoundInstance()
+{
+ if (mSoundBuffer != NULL)
+ mSoundBuffer->Release();
+}
+
+void DSoundInstance::RehupVolume()
+{
+ if (mSoundBuffer != NULL)
+ mSoundBuffer->SetVolume(mSoundManagerP->VolumeToDB(mBaseVolume * mVolume * mSoundManagerP->mMasterVolume));
+}
+
+void DSoundInstance::RehupPan()
+{
+ if (mSoundBuffer != NULL)
+ mSoundBuffer->SetPan(mBasePan + mPan);
+}
+
+void DSoundInstance::Release()
+{
+ Stop();
+ mReleased = true;
+}
+
+void DSoundInstance::SetVolume(double theVolume) // 0 = max
+{
+ mVolume = theVolume;
+ RehupVolume();
+}
+
+void DSoundInstance::SetPan(int thePosition) //-db to =db = left to right
+{
+ mPan = thePosition;
+ RehupPan();
+}
+
+void DSoundInstance::SetBaseVolume(double theBaseVolume)
+{
+ mBaseVolume = theBaseVolume;
+ RehupVolume();
+}
+
+void DSoundInstance::SetBasePan(int theBasePan)
+{
+ mBasePan = theBasePan;
+ RehupPan();
+}
+
+bool DSoundInstance::Play(bool looping, bool autoRelease)
+{
+ Stop();
+
+ mHasPlayed = true;
+ mAutoRelease = autoRelease;
+
+ if (mSoundBuffer == NULL)
+ {
+ return false;
+ }
+
+ if (looping)
+ {
+ if (mSoundBuffer->Play(0, 0, DSBPLAY_LOOPING) != DS_OK)
+ return false;
+ }
+ else
+ {
+ if (mSoundBuffer->Play(0, 0, 0) != DS_OK)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void DSoundInstance::Stop()
+{
+ if (mSoundBuffer != NULL)
+ {
+ mSoundBuffer->Stop();
+ mSoundBuffer->SetCurrentPosition(0);
+ mAutoRelease = false;
+ }
+}
+
+#include "DirectXErrorString.h"
+void DSoundInstance::AdjustPitch(double theNumSteps)
+{
+ if (mSoundBuffer != NULL)
+ {
+ double aFrequencyMult = pow(1.0594630943592952645618252949463, theNumSteps);
+ double aNewFrequency = mDefaultFrequency*aFrequencyMult;
+ if (aNewFrequency < DSBFREQUENCY_MIN)
+ aNewFrequency = DSBFREQUENCY_MIN;
+ if (aNewFrequency > DSBFREQUENCY_MAX)
+ aNewFrequency = DSBFREQUENCY_MAX;
+
+ mSoundBuffer->SetFrequency((DWORD)aNewFrequency);
+ }
+}
+
+bool DSoundInstance::IsPlaying()
+{
+ if (!mHasPlayed)
+ return false;
+
+ if (mSoundBuffer == NULL)
+ return false;
+
+ DWORD aStatus;
+ if (mSoundBuffer->GetStatus(&aStatus) == DS_OK)
+ // Has the sound stopped?
+ return ((aStatus & DSBSTATUS_PLAYING) != 0);
+ else
+ return false;
+}
+
+bool DSoundInstance::IsReleased()
+{
+ if ((!mReleased) && (mAutoRelease) && (mHasPlayed) && (!IsPlaying()))
+ Release();
+
+ return mReleased;
+}
+
+double DSoundInstance::GetVolume()
+{
+ return mVolume;
+}
+
diff --git a/osframework/source/SexyAppFramework/DSoundInstance.h b/osframework/source/SexyAppFramework/DSoundInstance.h
new file mode 100644
index 0000000..e01911a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DSoundInstance.h
@@ -0,0 +1,58 @@
+#ifndef __DSOUNDINSTANCE_H__
+#define __DSOUNDINSTANCE_H__
+
+#include "SoundInstance.h"
+#include "dsoundversion.h"
+
+namespace Sexy
+{
+
+class DSoundManager;
+
+class DSoundInstance : public SoundInstance
+{
+ friend class DSoundManager;
+
+protected:
+ DSoundManager* mSoundManagerP;
+ LPDIRECTSOUNDBUFFER mSourceSoundBuffer;
+ LPDIRECTSOUNDBUFFER mSoundBuffer;
+ bool mAutoRelease;
+ bool mHasPlayed;
+ bool mReleased;
+
+ int mBasePan;
+ double mBaseVolume;
+
+ int mPan;
+ double mVolume;
+
+ DWORD mDefaultFrequency;
+
+protected:
+ void RehupVolume();
+ void RehupPan();
+
+public:
+ DSoundInstance(DSoundManager* theSoundManager, LPDIRECTSOUNDBUFFER theSourceSound);
+ virtual ~DSoundInstance();
+ virtual void Release();
+
+ virtual void SetBaseVolume(double theBaseVolume);
+ virtual void SetBasePan(int theBasePan);
+
+ virtual void SetVolume(double theVolume);
+ virtual void SetPan(int thePosition); //-hundredth db to +hundredth db = left to right
+ virtual void AdjustPitch(double theNumSteps);
+
+ virtual bool Play(bool looping, bool autoRelease);
+ virtual void Stop();
+ virtual bool IsPlaying();
+ virtual bool IsReleased();
+ virtual double GetVolume();
+
+};
+
+}
+
+#endif //__DSOUNDINSTANCE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DSoundManager.cpp b/osframework/source/SexyAppFramework/DSoundManager.cpp
new file mode 100644
index 0000000..45ef92b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DSoundManager.cpp
@@ -0,0 +1,1098 @@
+#include "DSoundManager.h"
+#include <io.h>
+#include <fcntl.h>
+#include "debug.h"
+#include "DSoundInstance.h"
+#include "FModLoader.h"
+#include <math.h>
+#include "..\PakLib\PakInterface.h"
+
+using namespace Sexy;
+
+#define USE_OGG_LIB
+
+
+#ifdef USE_OGG_LIB
+#include "ogg/ivorbiscodec.h"
+#include "ogg/ivorbisfile.h"
+#endif
+
+#define SOUND_FLAGS (DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLFREQUENCY)
+DSoundManager::DSoundManager(HWND theHWnd, bool haveFMod)
+{
+ mHaveFMod = haveFMod;
+ mLastReleaseTick = 0;
+ mPrimaryBuffer = NULL;
+
+ int i;
+
+ for (i = 0; i < MAX_SOURCE_SOUNDS; i++)
+ {
+ mSourceSounds[i] = NULL;
+ mBaseVolumes[i] = 1;
+ mBasePans[i] = 0;
+ }
+
+ for (i = 0; i < MAX_CHANNELS; i++)
+ mPlayingSounds[i] = NULL;
+
+ mDirectSound = NULL;
+
+ mMasterVolume = 1.0;
+
+ if (theHWnd != NULL)
+ {
+ extern HMODULE gDSoundDLL;
+ typedef HRESULT (WINAPI *DirectSoundCreateFunc)(LPCGUID lpcGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter);
+ DirectSoundCreateFunc aDirectSoundCreateFunc = (DirectSoundCreateFunc)GetProcAddress(gDSoundDLL,"DirectSoundCreate");
+
+ if (aDirectSoundCreateFunc != NULL && aDirectSoundCreateFunc(NULL, &mDirectSound, NULL) == DS_OK)
+ {
+ //FSOUND_SetOutput(FSOUND_OUTPUT_WINMM);
+ if (mHaveFMod)
+ {
+ LoadFModDLL();
+
+ gFMod->FSOUND_SetHWND(theHWnd);
+ gFMod->FSOUND_SetBufferSize(200); // #LUC
+ gFMod->FSOUND_Init(44100, 64, FSOUND_INIT_GLOBALFOCUS);
+ }
+
+ HRESULT aResult = mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_PRIORITY);
+ if (SUCCEEDED(aResult))
+ {
+ // Set primary buffer to 16-bit 44.1Khz
+ WAVEFORMATEX aWaveFormat;
+ DSBUFFERDESC aBufferDesc;
+
+ // Set up wave format structure.
+ int aBitCount = 16;
+ int aChannelCount = 2;
+ int aSampleRate = 44100;
+
+ // Set up wave format structure.
+ memset(&aWaveFormat, 0, sizeof(WAVEFORMATEX));
+ aWaveFormat.cbSize = sizeof(WAVEFORMATEX);
+ aWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
+ aWaveFormat.nChannels = aChannelCount;
+ aWaveFormat.nSamplesPerSec = aSampleRate;
+ aWaveFormat.nBlockAlign = aChannelCount*aBitCount/8;
+ aWaveFormat.nAvgBytesPerSec =
+ aWaveFormat.nSamplesPerSec * aWaveFormat.nBlockAlign;
+ aWaveFormat.wBitsPerSample = aBitCount;
+
+ // Set up DSBUFFERDESC structure.
+ memset(&aBufferDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
+ aBufferDesc.dwSize = sizeof(DSBUFFERDESC1);
+ aBufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;//| DSBCAPS_CTRL3D; // Need default controls (pan, volume, frequency).
+ aBufferDesc.dwBufferBytes = 0;
+ aBufferDesc.lpwfxFormat =NULL;//(LPWAVEFORMATEX)&aWaveFormat;
+
+ HRESULT aResult = mDirectSound->CreateSoundBuffer(&aBufferDesc, &mPrimaryBuffer, NULL);
+ if (aResult == DS_OK)
+ {
+ aResult = mPrimaryBuffer->SetFormat(&aWaveFormat);
+ }
+ }
+ else
+ {
+ aResult = mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_NORMAL);
+ }
+ }
+ }
+}
+
+DSoundManager::~DSoundManager()
+{
+ ReleaseChannels();
+ ReleaseSounds();
+
+ if (mPrimaryBuffer)
+ mPrimaryBuffer->Release();
+
+ if (mDirectSound != NULL)
+ {
+ if (mHaveFMod)
+ gFMod->FSOUND_Close();
+
+ mDirectSound->Release();
+
+ if (mHaveFMod)
+ FreeFModDLL();
+ }
+}
+
+int DSoundManager::FindFreeChannel()
+{
+ DWORD aTick = GetTickCount();
+ if (aTick-mLastReleaseTick > 1000)
+ {
+ ReleaseFreeChannels();
+ mLastReleaseTick = aTick;
+ }
+
+ for (int i = 0; i < MAX_CHANNELS; i++)
+ {
+ if (mPlayingSounds[i] == NULL)
+ return i;
+
+ if (mPlayingSounds[i]->IsReleased())
+ {
+ delete mPlayingSounds[i];
+ mPlayingSounds[i] = NULL;
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+bool DSoundManager::Initialized()
+{
+/*
+ if (mDirectSound!=NULL)
+ {
+ mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_NORMAL);
+ }
+*/
+
+ return (mDirectSound != NULL);
+}
+
+int DSoundManager::VolumeToDB(double theVolume)
+{
+ int aVol = (int) ((log10(1 + theVolume*9) - 1.0) * 2333);
+ if (aVol < -2000)
+ aVol = -10000;
+
+ return aVol;
+}
+
+void DSoundManager::SetVolume(double theVolume)
+{
+ mMasterVolume = theVolume;
+
+ for (int i = 0; i < MAX_CHANNELS; i++)
+ if (mPlayingSounds[i] != NULL)
+ mPlayingSounds[i]->RehupVolume();
+}
+
+bool DSoundManager::LoadWAVSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ int aDataSize;
+
+ PFILE* fp;
+
+ fp = p_fopen(theFilename.c_str(), "rb");
+
+ if (fp <= 0)
+ return false;
+
+ char aChunkType[5];
+ aChunkType[4] = '\0';
+ ulong aChunkSize;
+
+ p_fread(aChunkType, 1, 4, fp);
+ if (!strcmp(aChunkType, "RIFF") == 0)
+ return false;
+ p_fread(&aChunkSize, 4, 1, fp);
+
+ p_fread(aChunkType, 1, 4, fp);
+ if (!strcmp(aChunkType, "WAVE") == 0)
+ return false;
+
+ ushort aBitCount = 16;
+ ushort aChannelCount = 1;
+ ulong aSampleRate = 22050;
+ uchar anXor = 0;
+
+ while (!p_feof(fp))
+ {
+ p_fread(aChunkType, 1, 4, fp);
+ if (p_fread(&aChunkSize, 4, 1, fp) == 0)
+ return false;
+
+ int aCurPos = p_ftell(fp);
+
+ if (strcmp(aChunkType, "fmt ") == 0)
+ {
+ ushort aFormatTag;
+ ulong aBytesPerSec;
+ ushort aBlockAlign;
+
+ p_fread(&aFormatTag, 2, 1, fp);
+ p_fread(&aChannelCount, 2, 1, fp);
+ p_fread(&aSampleRate, 4, 1, fp);
+ p_fread(&aBytesPerSec, 4, 1, fp);
+ p_fread(&aBlockAlign, 2, 1, fp);
+ p_fread(&aBitCount, 2, 1, fp);
+
+ if (aFormatTag != 1)
+ return false;
+ }
+ else if (strcmp(aChunkType, "dep ") == 0)
+ {
+ char aStr[256];
+ ushort aStrLen;
+
+ p_fread(&aStrLen, 2, 1, fp);
+ if (aStrLen > 255)
+ aStrLen = 255;
+ p_fread(aStr, 1, aStrLen, fp);
+ aStr[aStrLen] = '\0';
+
+ FILETIME aSavedFileTime;
+ p_fread(&aSavedFileTime, sizeof(FILETIME), 1, fp);
+
+ FILETIME anActualFileTime;
+ memset(&anActualFileTime, 0, sizeof(FILETIME));
+ GetTheFileTime(aStr, &anActualFileTime);
+
+ if ((aSavedFileTime.dwHighDateTime != anActualFileTime.dwHighDateTime) ||
+ (aSavedFileTime.dwLowDateTime != anActualFileTime.dwLowDateTime ))
+ return false;
+ }
+ else if (strcmp(aChunkType, "xor ") == 0)
+ {
+ p_fread(&anXor, 1, 1, fp);
+ }
+ else if (strcmp(aChunkType, "data") == 0)
+ {
+ aDataSize = aChunkSize;
+
+ mSourceDataSizes[theSfxID] = aChunkSize;
+
+ PCMWAVEFORMAT aWaveFormat;
+ DSBUFFERDESC aBufferDesc;
+
+ // Set up wave format structure.
+ memset(&aWaveFormat, 0, sizeof(PCMWAVEFORMAT));
+ aWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
+ aWaveFormat.wf.nChannels = aChannelCount;
+ aWaveFormat.wf.nSamplesPerSec = aSampleRate;
+ aWaveFormat.wf.nBlockAlign = aChannelCount*aBitCount/8;
+ aWaveFormat.wf.nAvgBytesPerSec =
+ aWaveFormat.wf.nSamplesPerSec * aWaveFormat.wf.nBlockAlign;
+ aWaveFormat.wBitsPerSample = aBitCount;
+ // Set up DSBUFFERDESC structure.
+ memset(&aBufferDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
+ aBufferDesc.dwSize = sizeof(DSBUFFERDESC);
+ //aBufferDesc.dwFlags = DSBCAPS_CTRL3D;
+ aBufferDesc.dwFlags = SOUND_FLAGS; //DSBCAPS_CTRLDEFAULT;
+
+ //aBufferDesc.dwFlags = 0;
+
+ aBufferDesc.dwBufferBytes = aDataSize;
+ aBufferDesc.lpwfxFormat = (LPWAVEFORMATEX)&aWaveFormat;
+
+ if (mDirectSound->CreateSoundBuffer(&aBufferDesc, &mSourceSounds[theSfxID], NULL) != DS_OK)
+ {
+ p_fclose(fp);
+ return false;
+ }
+
+
+ void* lpvPtr;
+ DWORD dwBytes;
+ if (mSourceSounds[theSfxID]->Lock(0, aDataSize, &lpvPtr, &dwBytes, NULL, NULL, 0) != DS_OK)
+ {
+ p_fclose(fp);
+ return false;
+ }
+
+ int aReadSize = p_fread(lpvPtr, 1, aDataSize, fp);
+ p_fclose(fp);
+
+ for (int i = 0; i < aDataSize; i++)
+ ((uchar*) lpvPtr)[i] ^= anXor;
+
+ if (mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, NULL) != DS_OK)
+ return false;
+
+ if (aReadSize != aDataSize)
+ return false;
+
+ return true;
+ }
+
+ p_fseek(fp, aCurPos+aChunkSize, SEEK_SET);
+ }
+
+ return false;
+}
+
+// Load FMod sound can handle oggs and mp3s and whatever else fmod can decode
+bool DSoundManager::LoadFModSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ if (!mHaveFMod)
+ return false;
+
+ FSOUND_SAMPLE* aSample = gFMod->FSOUND_Sample_Load(FSOUND_FREE, theFilename.c_str(), 0, 0);
+
+ if (aSample == NULL)
+ {
+ return false;
+ }
+
+ int aMode = gFMod->FSOUND_Sample_GetMode(aSample);
+ int aFreq;
+ gFMod->FSOUND_Sample_GetDefaults(aSample, &aFreq, NULL, NULL, NULL);
+
+ PCMWAVEFORMAT aWaveFormat;
+ DSBUFFERDESC aBufferDesc;
+
+ // Set up wave format structure.
+ memset(&aWaveFormat, 0, sizeof(PCMWAVEFORMAT));
+ aWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
+ aWaveFormat.wf.nChannels = ((aMode & FSOUND_MONO) != 0) ? 1 : 2;
+ aWaveFormat.wf.nSamplesPerSec = aFreq;
+ aWaveFormat.wBitsPerSample = ((aMode & FSOUND_8BITS) != 0) ? 8 : 16;
+ aWaveFormat.wf.nBlockAlign = aWaveFormat.wf.nChannels*aWaveFormat.wBitsPerSample/8;
+ aWaveFormat.wf.nAvgBytesPerSec = aWaveFormat.wf.nSamplesPerSec * aWaveFormat.wf.nBlockAlign;
+
+/*
+ WAVEFORMATEX rigWave;
+
+ rigWave.cbSize=sizeof(rigWave);
+ rigWave.nAvgBytesPerSec=aWaveFormat.wf.nAvgBytesPerSec;
+ rigWave.nBlockAlign=aWaveFormat.wf.nBlockAlign;
+ rigWave.nChannels=aWaveFormat.wf.nChannels;
+ rigWave.nSamplesPerSec=aWaveFormat.wf.nSamplesPerSec;
+ rigWave.wBitsPerSample=aWaveFormat.wBitsPerSample;
+ rigWave.wFormatTag=aWaveFormat.wf.wFormatTag;
+*/
+
+ // Set up DSBUFFERDESC structure.
+
+ int aLenBytes = gFMod->FSOUND_Sample_GetLength(aSample) * aWaveFormat.wf.nBlockAlign;
+ memset(&aBufferDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
+
+ mSourceDataSizes[theSfxID] = aLenBytes;
+
+ //FUNK
+ aBufferDesc.dwSize = sizeof(DSBUFFERDESC);
+ aBufferDesc.dwFlags = SOUND_FLAGS;
+ aBufferDesc.dwBufferBytes = aLenBytes;
+ aBufferDesc.lpwfxFormat =(LPWAVEFORMATEX)&aWaveFormat;
+
+ if (mDirectSound->CreateSoundBuffer(&aBufferDesc, &mSourceSounds[theSfxID], NULL) != DS_OK)
+ {
+/*
+char xmsg[100];
+sprintf(xmsg, "WAV STUFF: (%s)\n"
+ "nAvgBytesPerSec: %d\n"
+ "nBlockAlign: %d\n"
+ "nChannels: %d\n"
+ "nSamplesPerSec: %d\n"
+ "wBitsPerSample: %d\n"
+ "wFormatTag: %d\n",
+
+ theFilename.c_str(),
+ aWaveFormat.wf.nAvgBytesPerSec,
+ aWaveFormat.wf.nBlockAlign,
+ aWaveFormat.wf.nChannels,
+ aWaveFormat.wf.nSamplesPerSec,
+ aWaveFormat.wBitsPerSample,
+ aWaveFormat.wf.wFormatTag);
+
+MessageBox(0,xmsg,xmsg,MB_OK);
+
+HRESULT error=mDirectSound->CreateSoundBuffer(&aBufferDesc, &mSourceSounds[theSfxID], NULL);
+switch (error)
+{
+case DSERR_ALLOCATED:MessageBox(0,"DSERR_ALLOCATED","Ugh",MB_OK);break;
+case DSERR_BADFORMAT:MessageBox(0,"DSERR_BADFORMAT","Ugh",MB_OK);break;
+case DSERR_INVALIDPARAM:MessageBox(0,"DSERR_INVALIDPARAM(XXX)","Ugh",MB_OK);break;
+case DSERR_NOAGGREGATION:MessageBox(0,"DSERR_NOAGGREGATION","Ugh",MB_OK);break;
+case DSERR_OUTOFMEMORY:MessageBox(0,"DSERR_OUTOFMEMORY","Ugh",MB_OK);break;
+case DSERR_UNINITIALIZED:MessageBox(0,"DSERR_UNINITIALIZED","Ugh",MB_OK);break;
+case DSERR_UNSUPPORTED:MessageBox(0,"DSERR_UNSUPPORTED","Ugh",MB_OK);break;
+}
+
+
+exit(0);
+*/
+ // Delete
+ gFMod->FSOUND_Sample_Free(aSample);
+ return false;
+ }
+
+ void* lpvPtr;
+ DWORD dwBytes;
+ if (mSourceSounds[theSfxID]->Lock(0, aLenBytes, &lpvPtr, &dwBytes, NULL, NULL, 0) == DS_OK)
+ {
+
+ void* aPtr1;
+ void* aPtr2;
+ uint aLen1;
+ uint aLen2;
+
+ if (gFMod->FSOUND_Sample_Lock(aSample, 0, aLenBytes, &aPtr1, &aPtr2, &aLen1, &aLen2))
+ {
+ memcpy(lpvPtr, aPtr1, aLen1);
+
+ mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, NULL);
+ gFMod->FSOUND_Sample_Unlock(aSample, aPtr1, aPtr2, aLen1, aLen2);
+ }
+ }
+ else
+ {
+ }
+
+ mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, 0);
+
+ gFMod->FSOUND_Sample_Free(aSample);
+
+ return true;
+}
+
+#ifdef USE_OGG_LIB
+
+static int p_fseek64_wrap(PFILE *f,ogg_int64_t off,int whence){
+ if(f==NULL)return(-1);
+ return p_fseek(f,(long)off,whence);
+}
+
+int ov_pak_open(PFILE *f,OggVorbis_File *vf,char *initial,long ibytes){
+ ov_callbacks callbacks = {
+ (size_t (*)(void *, size_t, size_t, void *)) p_fread,
+ (int (*)(void *, ogg_int64_t, int)) p_fseek64_wrap,
+ (int (*)(void *)) p_fclose,
+ (long (*)(void *)) p_ftell
+ };
+
+ return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
+}
+
+bool DSoundManager::LoadOGGSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ OggVorbis_File vf;
+ int current_section;
+
+ PFILE *aFile = p_fopen(theFilename.c_str(),"rb");
+ if (aFile==NULL)
+ return false;
+
+ if(ov_pak_open(aFile, &vf, NULL, 0) < 0)
+ {
+ p_fclose(aFile);
+ return false;
+ }
+
+ vorbis_info *anInfo = ov_info(&vf,-1);
+
+ PCMWAVEFORMAT aWaveFormat;
+ DSBUFFERDESC aBufferDesc;
+
+ // Set up wave format structure.
+ memset(&aWaveFormat, 0, sizeof(PCMWAVEFORMAT));
+ aWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
+ aWaveFormat.wf.nChannels = anInfo->channels;
+ aWaveFormat.wf.nSamplesPerSec = anInfo->rate;
+ aWaveFormat.wBitsPerSample = 16;
+ aWaveFormat.wf.nBlockAlign = aWaveFormat.wf.nChannels*aWaveFormat.wBitsPerSample/8;
+ aWaveFormat.wf.nAvgBytesPerSec = aWaveFormat.wf.nSamplesPerSec * aWaveFormat.wf.nBlockAlign;
+
+ int aLenBytes = (int) (ov_pcm_total(&vf,-1) * aWaveFormat.wf.nBlockAlign);
+ memset(&aBufferDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
+
+ mSourceDataSizes[theSfxID] = aLenBytes;
+
+ //FUNK
+ aBufferDesc.dwSize = sizeof(DSBUFFERDESC);
+ aBufferDesc.dwFlags = SOUND_FLAGS;
+ aBufferDesc.dwBufferBytes = aLenBytes;
+ aBufferDesc.lpwfxFormat =(LPWAVEFORMATEX)&aWaveFormat;
+
+ if (mDirectSound->CreateSoundBuffer(&aBufferDesc, &mSourceSounds[theSfxID], NULL) != DS_OK)
+ {
+ ov_clear(&vf);
+ return false;
+ }
+
+ char* aBuf;
+ DWORD dwBytes;
+ if (mSourceSounds[theSfxID]->Lock(0, aLenBytes, (LPVOID*)&aBuf, &dwBytes, NULL, NULL, 0) != DS_OK)
+ {
+ ov_clear(&vf);
+ return false;
+ }
+
+ char *aPtr = aBuf;
+ int aNumBytes = dwBytes;
+ while(aNumBytes > 0)
+ {
+ long ret=ov_read(&vf,aPtr,aNumBytes,&current_section);
+ if (ret == 0)
+ break;
+ else if (ret < 0)
+ break;
+ else
+ {
+ aPtr += ret;
+ aNumBytes -= ret;
+ }
+ }
+
+ mSourceSounds[theSfxID]->Unlock(aBuf, dwBytes, NULL, 0);
+ ov_clear(&vf);
+ return aNumBytes==0;
+}
+#else
+bool DSoundManager::LoadOGGSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ return false;
+}
+#endif
+
+
+bool DSoundManager::LoadAUSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ PFILE* fp;
+
+ fp = p_fopen(theFilename.c_str(), "rb");
+
+ if (fp <= 0)
+ return false;
+
+ char aHeaderId[5];
+ aHeaderId[4] = '\0';
+ p_fread(aHeaderId, 1, 4, fp);
+ if (!strcmp(aHeaderId, ".snd") == 0)
+ return false;
+
+ ulong aHeaderSize;
+ p_fread(&aHeaderSize, 4, 1, fp);
+ aHeaderSize = LONG_BIGE_TO_NATIVE(aHeaderSize);
+
+ ulong aDataSize;
+ p_fread(&aDataSize, 4, 1, fp);
+ aDataSize = LONG_BIGE_TO_NATIVE(aDataSize);
+
+ ulong anEncoding;
+ p_fread(&anEncoding, 4, 1, fp);
+ anEncoding = LONG_BIGE_TO_NATIVE(anEncoding);
+
+ ulong aSampleRate;
+ p_fread(&aSampleRate, 4, 1, fp);
+ aSampleRate = LONG_BIGE_TO_NATIVE(aSampleRate);
+
+ ulong aChannelCount;
+ p_fread(&aChannelCount, 4, 1, fp);
+ aChannelCount = LONG_BIGE_TO_NATIVE(aChannelCount);
+
+ p_fseek(fp, aHeaderSize, SEEK_SET);
+
+ bool ulaw = false;
+
+ ulong aSrcBitCount = 8;
+ ulong aBitCount = 16;
+ switch (anEncoding)
+ {
+ case 1:
+ aSrcBitCount = 8;
+ aBitCount = 16;
+ ulaw = true;
+ break;
+ case 2:
+ aSrcBitCount = 8;
+ aBitCount = 8;
+ break;
+
+ /*
+ Support these formats?
+
+ case 3:
+ aBitCount = 16;
+ break;
+ case 4:
+ aBitCount = 24;
+ break;
+ case 5:
+ aBitCount = 32;
+ break;*/
+
+ default:
+ return false;
+ }
+
+
+ ulong aDestSize = aDataSize * aBitCount/aSrcBitCount;
+ mSourceDataSizes[theSfxID] = aDestSize;
+
+ PCMWAVEFORMAT aWaveFormat;
+ DSBUFFERDESC aBufferDesc;
+
+ // Set up wave format structure.
+ memset(&aWaveFormat, 0, sizeof(PCMWAVEFORMAT));
+ aWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
+ aWaveFormat.wf.nChannels = (WORD) aChannelCount;
+ aWaveFormat.wf.nSamplesPerSec = aSampleRate;
+ aWaveFormat.wf.nBlockAlign = (WORD) (aChannelCount*aBitCount/8);
+ aWaveFormat.wf.nAvgBytesPerSec =
+ aWaveFormat.wf.nSamplesPerSec * aWaveFormat.wf.nBlockAlign;
+ aWaveFormat.wBitsPerSample = (WORD) aBitCount;
+ // Set up DSBUFFERDESC structure.
+ memset(&aBufferDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
+ aBufferDesc.dwSize = sizeof(DSBUFFERDESC);
+ //aBufferDesc.dwFlags = DSBCAPS_CTRL3D;
+ aBufferDesc.dwFlags = SOUND_FLAGS;
+ aBufferDesc.dwBufferBytes = aDestSize;
+ aBufferDesc.lpwfxFormat = (LPWAVEFORMATEX)&aWaveFormat;
+
+ if (mDirectSound->CreateSoundBuffer(&aBufferDesc, &mSourceSounds[theSfxID], NULL) != DS_OK)
+ {
+ p_fclose(fp);
+ return false;
+ }
+
+ void* lpvPtr;
+ DWORD dwBytes;
+ if (mSourceSounds[theSfxID]->Lock(0, aDestSize, &lpvPtr, &dwBytes, NULL, NULL, 0) != DS_OK)
+ {
+ p_fclose(fp);
+ return false;
+ }
+
+ uchar* aSrcBuffer = new uchar[aDataSize];
+
+ int aReadSize = p_fread(aSrcBuffer, 1, aDataSize, fp);
+ p_fclose(fp);
+
+ if (ulaw)
+ {
+ short* aDestBuffer = (short*) lpvPtr;
+
+ for (ulong i = 0; i < aDataSize; i++)
+ {
+ int ch = aSrcBuffer[i];
+
+ int sign = (ch < 128) ? -1 : 1;
+ ch = ch | 0x80;
+ if (ch > 239)
+ ch = ((0xF0 | 15) - ch) * 2;
+ else if (ch > 223)
+ ch = (((0xE0 | 15) - ch) * 4) + 32;
+ else if (ch > 207)
+ ch = (((0xD0 | 15) - ch) * 8) + 96;
+ else if (ch > 191)
+ ch = (((0xC0 | 15) - ch) * 16) + 224;
+ else if (ch > 175)
+ ch = (((0xB0 | 15) - ch) * 32) + 480;
+ else if (ch > 159)
+ ch = (((0xA0 | 15) - ch) * 64) + 992;
+ else if (ch > 143)
+ ch = (((0x90 | 15) - ch) * 128) + 2016;
+ else if (ch > 128)
+ ch = (((0x80 | 15) - ch) * 256) + 4064;
+ else
+ ch = 0xff;
+
+ aDestBuffer[i] = sign * ch * 4;
+ }
+ }
+ else
+ memcpy(lpvPtr, aSrcBuffer, aDataSize);
+
+ delete [] aSrcBuffer;
+
+ if (mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, NULL) != DS_OK)
+ return false;
+
+ if (aReadSize != aDataSize)
+ return false;
+
+ return true;
+}
+
+bool DSoundManager::LoadSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ if ((theSfxID < 0) || (theSfxID >= MAX_SOURCE_SOUNDS))
+ return false;
+
+ ReleaseSound(theSfxID);
+
+ if (!mDirectSound)
+ return true; // sounds just won't play, but this is not treated as a failure condition
+
+ mSourceFileNames[theSfxID] = theFilename;
+
+ std::string aFilename = theFilename;
+ std::string aCachedName;
+
+ if ((aFilename.length() > 2) && (aFilename[0] != '\\') && (aFilename[0] != '/') &&
+ (aFilename[1] != ':'))
+ {
+ // Not an absolute path
+ aCachedName = GetAppDataFolder() + "cached\\" + aFilename + ".wav";
+ if (LoadWAVSound(theSfxID, aCachedName))
+ return true;
+ MkDir(GetFileDir(aCachedName));
+ }
+
+ if (LoadWAVSound(theSfxID, aFilename + ".wav"))
+ return true;
+
+ if (mHaveFMod)
+ {
+ if (LoadFModSound(theSfxID, aFilename + ".mp3"))
+ {
+ WriteWAV(theSfxID, aCachedName, aFilename + ".mp3");
+ return true;
+ }
+#ifndef USE_OGG_LIB
+ if (LoadFModSound(theSfxID, aFilename + ".ogg"))
+ {
+ WriteWAV(theSfxID, aCachedName, aFilename + ".ogg");
+ return true;
+ }
+#endif
+ }
+
+#ifdef USE_OGG_LIB
+ if (LoadOGGSound(theSfxID, aFilename + ".ogg"))
+ {
+ WriteWAV(theSfxID, aCachedName, aFilename + ".ogg");
+ return true;
+ }
+#endif
+
+ if (LoadAUSound(theSfxID, aFilename + ".au"))
+ {
+ WriteWAV(theSfxID, aCachedName, aFilename + ".au");
+ return true;
+ }
+
+ return false;
+}
+
+int DSoundManager::LoadSound(const std::string& theFilename)
+{
+ int i;
+ for (i = 0; i < MAX_SOURCE_SOUNDS; i++)
+ if (mSourceFileNames[i] == theFilename)
+ return i;
+
+ for (i = MAX_SOURCE_SOUNDS-1; i >= 0; i--)
+ {
+ if (mSourceSounds[i] == NULL)
+ {
+ if (!LoadSound(i, theFilename))
+ return -1;
+ else
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+void DSoundManager::ReleaseSound(unsigned int theSfxID)
+{
+ if (mSourceSounds[theSfxID] != NULL)
+ {
+ mSourceSounds[theSfxID]->Release();
+ mSourceSounds[theSfxID] = NULL;
+ mSourceFileNames[theSfxID] = "";
+ }
+}
+
+int DSoundManager::GetFreeSoundId()
+{
+ for (int i=0; i<MAX_SOURCE_SOUNDS; i++)
+ {
+ if (mSourceSounds[i]==NULL)
+ return i;
+ }
+
+ return -1;
+}
+
+int DSoundManager::GetNumSounds()
+{
+ int aCount = 0;
+ for (int i=0; i<MAX_SOURCE_SOUNDS; i++)
+ {
+ if (mSourceSounds[i]!=NULL)
+ aCount++;
+ }
+
+ return aCount;
+}
+
+bool DSoundManager::SetBaseVolume(unsigned int theSfxID, double theBaseVolume)
+{
+ if ((theSfxID < 0) || (theSfxID >= MAX_SOURCE_SOUNDS))
+ return false;
+
+ mBaseVolumes[theSfxID] = theBaseVolume;
+ return true;
+}
+
+bool DSoundManager::SetBasePan(unsigned int theSfxID, int theBasePan)
+{
+ if ((theSfxID < 0) || (theSfxID >= MAX_SOURCE_SOUNDS))
+ return false;
+
+ mBasePans[theSfxID] = theBasePan;
+ return true;
+}
+
+bool DSoundManager::GetTheFileTime(const std::string& theDepFile, FILETIME* theFileTime)
+{
+ memset(theFileTime, 0, sizeof(FILETIME));
+ HANDLE aDepFileHandle = CreateFile(theDepFile.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+ if (aDepFileHandle == INVALID_HANDLE_VALUE)
+ return false;
+
+ GetFileTime(aDepFileHandle, NULL, NULL, theFileTime);
+ CloseHandle(aDepFileHandle);
+ return true;
+}
+
+bool DSoundManager::WriteWAV(unsigned int theSfxID, const std::string& theFilename, const std::string& theDepFile)
+{
+ if ((theFilename.length() == 0) || (theSfxID < 0) || (theSfxID >= MAX_SOURCE_SOUNDS))
+ return false;
+
+ ulong aDataSize = mSourceDataSizes[theSfxID];
+
+ void* lpvPtr;
+ DWORD dwBytes;
+ if (mSourceSounds[theSfxID]->Lock(0, aDataSize, &lpvPtr, &dwBytes, NULL, NULL, 0) != DS_OK)
+ return false;
+
+ FILE* fp;
+ fp = fopen(theFilename.c_str(), "wb");
+
+ if (fp <= 0)
+ {
+ mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, NULL);
+ return false;
+ }
+
+ char aChunkType[5];
+ aChunkType[4] = '\0';
+ ulong aChunkSize = 4 + 8 + 16 + 8 + aDataSize;
+
+ fwrite("RIFF", 1, 4, fp);
+ fwrite(&aChunkSize, 4, 1, fp);
+ fwrite("WAVE", 1, 4, fp);
+
+ ulong aBufferSize;
+ mSourceSounds[theSfxID]->GetFormat(NULL, 0, &aBufferSize);
+
+ WAVEFORMATEX* aWaveFormat = (WAVEFORMATEX*) new char[aBufferSize];
+ memset(aWaveFormat, 0, sizeof(WAVEFORMATEX));
+ mSourceSounds[theSfxID]->GetFormat(aWaveFormat, aBufferSize, NULL);
+
+ ushort aFormatTag = 1;
+ ushort aChannelCount = aWaveFormat->nChannels;
+ ulong aSampleRate = aWaveFormat->nSamplesPerSec;
+ ushort aBitCount = aWaveFormat->wBitsPerSample;
+ ushort aBlockAlign = (aBitCount * aChannelCount) / 8;
+ ulong aBytesPerSec = aSampleRate * aBlockAlign;
+
+ delete aWaveFormat;
+
+ aChunkSize = 16;
+ fwrite("fmt ", 1, 4, fp);
+ fwrite(&aChunkSize, 1, 4, fp);
+ fwrite(&aFormatTag, 2, 1, fp);
+ fwrite(&aChannelCount, 2, 1, fp);
+ fwrite(&aSampleRate, 4, 1, fp);
+ fwrite(&aBytesPerSec, 4, 1, fp);
+ fwrite(&aBlockAlign, 2, 1, fp);
+ fwrite(&aBitCount, 2, 1, fp);
+
+ FILETIME aFileTime;
+ memset(&aFileTime, 0, sizeof(FILETIME));
+ GetTheFileTime(theDepFile, &aFileTime);
+
+ ushort aStrLen = theDepFile.length();
+ aChunkSize = 2 + aStrLen + sizeof(FILETIME);
+ fwrite("dep ", 1, 4, fp);
+ fwrite(&aChunkSize,4, 1, fp);
+ fwrite(&aStrLen, 2, 1, fp);
+ fwrite(theDepFile.c_str(), 1, aStrLen, fp);
+ fwrite(&aFileTime, sizeof(FILETIME), 1, fp);
+
+ aChunkSize = 1;
+ uchar anXor = 0xF7;
+ fwrite("xor ", 1, 4, fp);
+ fwrite(&aChunkSize, 4, 1, fp);
+ fwrite(&anXor, 1, 1, fp);
+
+ for (DWORD i = 0; i < dwBytes; i++)
+ ((uchar*) lpvPtr)[i] ^= anXor;
+
+ fwrite("data", 1, 4, fp);
+ fwrite(&aDataSize, 4, 1, fp);
+ fwrite(lpvPtr, 1, aDataSize, fp);
+ fclose(fp);
+
+ for (DWORD i = 0; i < dwBytes; i++)
+ ((uchar*) lpvPtr)[i] ^= anXor;
+
+ if (mSourceSounds[theSfxID]->Unlock(lpvPtr, dwBytes, NULL, NULL) != DS_OK)
+ return false;
+
+ return true;
+}
+
+SoundInstance* DSoundManager::GetSoundInstance(unsigned int theSfxID)
+{
+ if (theSfxID > MAX_SOURCE_SOUNDS)
+ return NULL;
+
+ int aFreeChannel = FindFreeChannel();
+ if (aFreeChannel < 0)
+ return NULL;
+
+ if (mDirectSound==NULL)
+ {
+ mPlayingSounds[aFreeChannel] = new DSoundInstance(this, NULL);
+ }
+ else
+ {
+ if (mSourceSounds[theSfxID] == NULL)
+ return NULL;
+
+ mPlayingSounds[aFreeChannel] = new DSoundInstance(this, mSourceSounds[theSfxID]);
+ }
+
+ mPlayingSounds[aFreeChannel]->SetBasePan(mBasePans[theSfxID]);
+ mPlayingSounds[aFreeChannel]->SetBaseVolume(mBaseVolumes[theSfxID]);
+
+ return mPlayingSounds[aFreeChannel];
+}
+
+void DSoundManager::ReleaseSounds()
+{
+ for (int i = 0; i < MAX_SOURCE_SOUNDS; i++)
+ if (mSourceSounds[i] != NULL)
+ {
+ mSourceSounds[i]->Release();
+ mSourceSounds[i] = NULL;
+ }
+}
+
+void DSoundManager::ReleaseChannels()
+{
+ for (int i = 0; i < MAX_CHANNELS; i++)
+ if (mPlayingSounds[i] != NULL)
+ {
+ delete mPlayingSounds[i];
+ mPlayingSounds[i] = NULL;
+ }
+}
+
+void DSoundManager::ReleaseFreeChannels()
+{
+ for (int i = 0; i < MAX_CHANNELS; i++)
+ if (mPlayingSounds[i] != NULL && mPlayingSounds[i]->IsReleased())
+ {
+ delete mPlayingSounds[i];
+ mPlayingSounds[i] = NULL;
+ }
+}
+
+void DSoundManager::StopAllSounds()
+{
+ for (int i = 0; i < MAX_CHANNELS; i++)
+ if (mPlayingSounds[i] != NULL)
+ {
+ bool isAutoRelease = mPlayingSounds[i]->mAutoRelease;
+ mPlayingSounds[i]->Stop();
+ mPlayingSounds[i]->mAutoRelease = isAutoRelease;
+ }
+}
+
+
+double DSoundManager::GetMasterVolume()
+{
+ MIXERCONTROLDETAILS mcd;
+ MIXERCONTROLDETAILS_UNSIGNED mxcd_u;
+ MIXERLINECONTROLS mxlc;
+ MIXERCONTROL mlct;
+ MIXERLINE mixerLine;
+ HMIXER hmx;
+ MIXERCAPS pmxcaps;
+
+ mixerOpen((HMIXER*) &hmx, 0, 0, 0, MIXER_OBJECTF_MIXER);
+ mixerGetDevCaps(0, &pmxcaps, sizeof(pmxcaps));
+
+ mxlc.cbStruct = sizeof(mxlc);
+ mxlc.cbmxctrl = sizeof(mlct);
+ mxlc.pamxctrl = &mlct;
+ mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
+ mixerLine.cbStruct = sizeof(mixerLine);
+ mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
+ mixerGetLineInfo((HMIXEROBJ) hmx, &mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE);
+ mxlc.dwLineID = mixerLine.dwLineID;
+ mixerGetLineControls((HMIXEROBJ) hmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
+
+ mcd.cbStruct = sizeof(mcd);
+ mcd.dwControlID = mlct.dwControlID;
+ mcd.cChannels = 1;
+ mcd.cMultipleItems = 0;
+ mcd.cbDetails = sizeof(mxcd_u);
+ mcd.paDetails = &mxcd_u;
+
+ mixerGetControlDetails((HMIXEROBJ) hmx, &mcd, 0L);
+
+ mixerClose(hmx);
+
+ return mxcd_u.dwValue / (double) 0xFFFF;
+}
+
+void DSoundManager::SetMasterVolume(double theVolume)
+{
+ MIXERCONTROLDETAILS mcd;
+ MIXERCONTROLDETAILS_UNSIGNED mxcd_u;
+ MIXERLINECONTROLS mxlc;
+ MIXERCONTROL mlct;
+ MIXERLINE mixerLine;
+ HMIXER hmx;
+ MIXERCAPS pmxcaps;
+
+ mixerOpen((HMIXER*) &hmx, 0, 0, 0, MIXER_OBJECTF_MIXER);
+ mixerGetDevCaps(0, &pmxcaps, sizeof(pmxcaps));
+
+ mxlc.cbStruct = sizeof(mxlc);
+ mxlc.cbmxctrl = sizeof(mlct);
+ mxlc.pamxctrl = &mlct;
+ mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
+ mixerLine.cbStruct = sizeof(mixerLine);
+ mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
+ mixerGetLineInfo((HMIXEROBJ) hmx, &mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE);
+ mxlc.dwLineID = mixerLine.dwLineID;
+ mixerGetLineControls((HMIXEROBJ) hmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
+
+ mcd.cbStruct = sizeof(mcd);
+ mcd.dwControlID = mlct.dwControlID;
+ mcd.cChannels = 1;
+ mcd.cMultipleItems = 0;
+ mcd.cbDetails = sizeof(mxcd_u);
+ mcd.paDetails = &mxcd_u;
+
+ mxcd_u.dwValue = (int) (0xFFFF * theVolume);
+ mixerSetControlDetails((HMIXEROBJ) hmx, &mcd, 0L);
+
+ mixerClose(hmx);
+}
+
+void DSoundManager::Flush()
+{
+}
+
+void DSoundManager::SetCooperativeWindow(HWND theHWnd, bool isWindowed)
+{
+ if (mDirectSound != NULL)
+ mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_NORMAL);
+/*
+ if (isWindowed==true) mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_NORMAL);
+ else mDirectSound->SetCooperativeLevel(theHWnd,DSSCL_EXCLUSIVE);
+ */
+}
+#undef SOUND_FLAGS
diff --git a/osframework/source/SexyAppFramework/DSoundManager.h b/osframework/source/SexyAppFramework/DSoundManager.h
new file mode 100644
index 0000000..4be2cad
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DSoundManager.h
@@ -0,0 +1,74 @@
+#ifndef __DSOUNDMANAGER_H__
+#define __DSOUNDMANAGER_H__
+
+#include "dsoundversion.h"
+#include "SoundManager.h"
+
+namespace Sexy
+{
+
+class DSoundInstance;
+
+class DSoundManager : public SoundManager
+{
+ friend class DSoundInstance;
+ friend class DSoundMusicInterface;
+
+protected:
+ LPDIRECTSOUNDBUFFER mSourceSounds[MAX_SOURCE_SOUNDS];
+ std::string mSourceFileNames[MAX_SOURCE_SOUNDS];
+ LPDIRECTSOUNDBUFFER mPrimaryBuffer;
+ ulong mSourceDataSizes[MAX_SOURCE_SOUNDS];
+ double mBaseVolumes[MAX_SOURCE_SOUNDS];
+ int mBasePans[MAX_SOURCE_SOUNDS];
+ DSoundInstance* mPlayingSounds[MAX_CHANNELS];
+ double mMasterVolume;
+ DWORD mLastReleaseTick;
+
+protected:
+ int FindFreeChannel();
+ int VolumeToDB(double theVolume);
+ bool LoadOGGSound(unsigned int theSfxID, const std::string& theFilename);
+ bool LoadFModSound(unsigned int theSfxID, const std::string& theFilename);
+ bool LoadWAVSound(unsigned int theSfxID, const std::string& theFilename);
+ bool LoadAUSound(unsigned int theSfxID, const std::string& theFilename);
+ bool WriteWAV(unsigned int theSfxID, const std::string& theFilename, const std::string& theDepFile);
+ bool GetTheFileTime(const std::string& theDepFile, FILETIME* theFileTime);
+ void ReleaseFreeChannels();
+
+public:
+ LPDIRECTSOUND mDirectSound;
+ bool mHaveFMod;
+
+ DSoundManager(HWND theHWnd, bool haveFMod);
+ virtual ~DSoundManager();
+
+ virtual bool Initialized();
+
+ virtual bool LoadSound(unsigned int theSfxID, const std::string& theFilename);
+ virtual int LoadSound(const std::string& theFilename);
+ virtual void ReleaseSound(unsigned int theSfxID);
+
+ virtual void SetVolume(double theVolume);
+ virtual bool SetBaseVolume(unsigned int theSfxID, double theBaseVolume);
+ virtual bool SetBasePan(unsigned int theSfxID, int theBasePan);
+
+ virtual SoundInstance* GetSoundInstance(unsigned int theSfxID);
+
+ virtual void ReleaseSounds();
+ virtual void ReleaseChannels();
+
+ virtual double GetMasterVolume();
+ virtual void SetMasterVolume(double theVolume);
+
+ virtual void Flush();
+
+ virtual void SetCooperativeWindow(HWND theHWnd, bool isWindowed);
+ virtual void StopAllSounds();
+ virtual int GetFreeSoundId();
+ virtual int GetNumSounds();
+};
+
+}
+
+#endif //__DSOUNDMANAGER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Debug.cpp b/osframework/source/SexyAppFramework/Debug.cpp
new file mode 100644
index 0000000..599ac10
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Debug.cpp
@@ -0,0 +1,246 @@
+#include "Common.h"
+#include "Debug.h"
+
+#include "AutoCrit.h"
+#include "CritSect.h"
+
+#include <time.h>
+
+#include "memmgr.h"
+
+extern bool gInAssert = false;
+extern bool gSexyDumpLeakedMem = false;
+
+static FILE *gTraceFile = NULL;
+static int gTraceFileLen = 0;
+static int gTraceFileNum = 1;
+
+using namespace Sexy;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct SEXY_ALLOC_INFO
+{
+ int size;
+ char file[_MAX_PATH+1];
+ int line;
+};
+static bool gShowLeaks = false;
+static bool gSexyAllocMapValid = false;
+class SexyAllocMap : public std::map<void*,SEXY_ALLOC_INFO>
+{
+public:
+ CritSect mCrit;
+
+public:
+ SexyAllocMap() { gSexyAllocMapValid = true; }
+ ~SexyAllocMap()
+ {
+ if (gShowLeaks)
+ SexyDumpUnfreed();
+
+ gSexyAllocMapValid = false;
+ }
+};
+static SexyAllocMap gSexyAllocMap;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyTrace(const char *theStr)
+{
+ if (gTraceFile==NULL)
+ {
+ gTraceFileNum = (gTraceFileNum+1)%2;
+ char aBuf[50];
+ sprintf(aBuf,"trace%d.txt",gTraceFileNum+1);
+ gTraceFile = fopen(aBuf,"w");
+ if (gTraceFile==NULL)
+ return;
+ }
+
+ fprintf(gTraceFile,"%s\n",theStr);
+ fflush(gTraceFile);
+
+ gTraceFileLen += strlen(theStr);
+ if (gTraceFileLen > 100000)
+ {
+ fclose(gTraceFile);
+ gTraceFile = NULL;
+ gTraceFileLen = 0;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void SexyTraceFmt(const SexyChar* fmt ...)
+{
+ // Does not append a newline by default, also takes vararg parameters
+
+ va_list argList;
+ va_start(argList, fmt);
+ std::string result = SexyStringToStringFast(vformat(fmt, argList));
+ va_end(argList);
+
+
+ if (gTraceFile==NULL)
+ {
+ gTraceFileNum = (gTraceFileNum+1)%2;
+ char aBuf[50];
+ sprintf(aBuf,"trace%d.txt",gTraceFileNum+1);
+ gTraceFile = fopen(aBuf,"w");
+ if (gTraceFile==NULL)
+ return;
+ }
+
+ fprintf(gTraceFile,"%s",result.c_str());
+ fflush(gTraceFile);
+
+ gTraceFileLen += result.length();
+ if (gTraceFileLen > 100000)
+ {
+ fclose(gTraceFile);
+ gTraceFile = NULL;
+ gTraceFileLen = 0;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyMemAddTrack(void *addr, int asize, const char* fname, int lnum)
+{
+ if (!gSexyAllocMapValid)
+ return;
+
+ AutoCrit aCrit(gSexyAllocMap.mCrit);
+ gShowLeaks = true;
+
+ SEXY_ALLOC_INFO &info = gSexyAllocMap[addr];
+ strncpy(info.file, fname, sizeof(info.file)-1);
+ info.line = lnum;
+ info.size = asize;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyMemRemoveTrack(void* addr)
+{
+ if (!gSexyAllocMapValid)
+ return;
+
+ AutoCrit aCrit(gSexyAllocMap.mCrit);
+ SexyAllocMap::iterator anItr = gSexyAllocMap.find(addr);
+ if (anItr != gSexyAllocMap.end())
+ gSexyAllocMap.erase(anItr);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyDumpUnfreed()
+{
+ if (!gSexyAllocMapValid)
+ return;
+
+ AutoCrit aCrit(gSexyAllocMap.mCrit);
+ SexyAllocMap::iterator i;
+ int totalSize = 0;
+ char buf[8192];
+
+#ifdef SEXY_DUMP_LEAKED_MEM
+ char hex_dump[1024];
+ char ascii_dump[1024];
+ int count = 0;
+ int index = 0;
+#endif
+
+ FILE* f = fopen("mem_leaks.txt", "wt");
+ if (!f)
+ return;
+
+ time_t aTime = time(NULL);
+ sprintf(buf, "Memory Leak Report for %s\n", asctime(localtime(&aTime)));
+ fprintf(f, buf);
+ OutputDebugString("\n");
+ OutputDebugString(buf);
+ for(i = gSexyAllocMap.begin(); i != gSexyAllocMap.end(); i++)
+ {
+ sprintf(buf, "%s(%d) : Leak %d byte%s\n", i->second.file, i->second.line, i->second.size,i->second.size>1?"s":"");
+ OutputDebugString(buf);
+ fprintf(f, buf);
+
+#ifdef SEXY_DUMP_LEAKED_MEM
+ unsigned char* data = (unsigned char*)i->first;
+
+ for (index = 0; index < i->second.size; index++)
+ {
+ unsigned char _c = *data;
+
+ if (count == 0)
+ sprintf(hex_dump, "\t%02X ", _c);
+ else
+ sprintf(hex_dump, "%s%02X ", hex_dump, _c);
+
+ if ((_c < 32) || (_c > 126))
+ _c = '.';
+
+ if (count == 7)
+ sprintf(ascii_dump, "%s%c ", ascii_dump, _c);
+ else
+ sprintf(ascii_dump, "%s%c", count == 0 ? "\t" : ascii_dump, _c);
+
+
+ if (++count == 16)
+ {
+ count = 0;
+ sprintf(buf, "%s\t%s\n", hex_dump, ascii_dump);
+ fprintf(f, buf);
+
+ memset((void*)hex_dump, 0, 1024);
+ memset((void*)ascii_dump, 0, 1024);
+ }
+
+ data++;
+ }
+
+ if (count != 0)
+ {
+ fprintf(f, hex_dump);
+ for (index = 0; index < 16 - count; index++)
+ fprintf(f, "\t");
+
+ fprintf(f, ascii_dump);
+
+ for (index = 0; index < 16 - count; index++)
+ fprintf(f, ".");
+ }
+
+ count = 0;
+ fprintf(f, "\n\n");
+ memset((void*)hex_dump, 0, 1024);
+ memset((void*)ascii_dump, 0, 1024);
+
+#endif // SEXY_DUMP_LEAKED_MEM
+
+ totalSize += i->second.size;
+ }
+
+
+ sprintf(buf, "-----------------------------------------------------------\n");
+ fprintf(f, buf);
+ OutputDebugString(buf);
+ sprintf(buf, "Total Unfreed: %d bytes (%dKB)\n\n", totalSize, totalSize / 1024);
+ OutputDebugString(buf);
+ fprintf(f, buf);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void OutputDebug(const SexyChar* fmt ...)
+{
+ va_list argList;
+ va_start(argList, fmt);
+ std::string result = SexyStringToStringFast(vformat(fmt, argList));
+ va_end(argList);
+
+ OutputDebugStringA(result.c_str());
+}
+
diff --git a/osframework/source/SexyAppFramework/Debug.h b/osframework/source/SexyAppFramework/Debug.h
new file mode 100644
index 0000000..d70f05d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Debug.h
@@ -0,0 +1,31 @@
+#ifndef __DEBUG_INCLUDED__
+#define __DEBUG_INCLUDED__
+
+#include "Common.h"
+#include <cassert>
+
+extern bool gInAssert;
+
+#ifdef SEXY_TRACING_ENABLED
+void SexyTrace(const char *theStr);
+#define SEXY_TRACE(theStr) SexyTrace(theStr)
+#else
+#define SEXY_TRACE(theStr)
+#endif
+
+extern void SexyTraceFmt(const SexyChar* fmt ...);
+extern void OutputDebug(const SexyChar* fmt ...);
+
+#ifdef NDEBUG
+
+#define DBG_ASSERTE(exp) ((void)0)
+#define DBG_ASSERT(exp) ((void)0)
+
+#else
+
+#define DBG_ASSERTE(exp) { gInAssert = true; assert(exp); gInAssert = false; }
+#define DBG_ASSERT(exp) { gInAssert = true; assert(exp); gInAssert = false; }
+
+#endif // NDEBUG
+
+#endif //__DEBUG_INCLUDED__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DescParser.cpp b/osframework/source/SexyAppFramework/DescParser.cpp
new file mode 100644
index 0000000..b4b4c6b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DescParser.cpp
@@ -0,0 +1,552 @@
+#include "DescParser.h"
+#include "..\PakLib\PakInterface.h"
+
+using namespace Sexy;
+
+DescParser::DescParser()
+{
+ mCmdSep = CMDSEP_SEMICOLON;
+}
+
+DescParser::~DescParser()
+{
+}
+
+bool DescParser::Error(const std::string& theError)
+{
+ mError = theError;
+ return false;
+}
+
+DataElement* DescParser::Dereference(const std::string& theString)
+{
+ std::string aDefineName = StringToUpper(theString);
+
+ DataElementMap::iterator anItr = mDefineMap.find(aDefineName);
+ if (anItr != mDefineMap.end())
+ return anItr->second;
+ else
+ return NULL;
+}
+
+bool DescParser::IsImmediate(const std::string& theString)
+{
+ return (((theString[0] >= '0') && (theString[0] <= '9')) || (theString[0] == '-') ||
+ (theString[0] == '+') || (theString[0] == '\'') || (theString[0] == '"'));
+}
+
+std::string DescParser::Unquote(const std::string& theQuotedString)
+{
+ if ((theQuotedString[0] == '\'') || (theQuotedString[0] == '"'))
+ {
+ char aQuoteChar = theQuotedString[0];
+ std::string aLiteralString;
+ bool lastWasQuote = false;
+
+ for (ulong i = 0; i < theQuotedString.length(); i++)
+ {
+ if (theQuotedString[i] == aQuoteChar)
+ {
+ if (lastWasQuote)
+ aLiteralString += aQuoteChar;
+
+ lastWasQuote = true;
+ }
+ else
+ {
+ aLiteralString += theQuotedString[i];
+ lastWasQuote = false;
+ }
+ }
+
+ return aLiteralString;
+ }
+ else
+ return theQuotedString;
+}
+
+bool DescParser::GetValues(ListDataElement* theSource, ListDataElement* theValues)
+{
+ theValues->mElementVector.clear();
+
+ for (ulong aSourceNum = 0; aSourceNum < theSource->mElementVector.size(); aSourceNum++)
+ {
+ if (theSource->mElementVector[aSourceNum]->mIsList)
+ {
+ ListDataElement* aChildList = new ListDataElement();
+ theValues->mElementVector.push_back(aChildList);
+
+ if (!GetValues((ListDataElement*) theSource->mElementVector[aSourceNum], aChildList))
+ return false;
+ }
+ else
+ {
+ std::string aString = ((SingleDataElement*) theSource->mElementVector[aSourceNum])->mString;
+
+ if (aString.length() > 0)
+ {
+ if ((aString[0] == '\'') || (aString[0] == '"'))
+ {
+ SingleDataElement* aChildData = new SingleDataElement(Unquote(aString));
+ theValues->mElementVector.push_back(aChildData);
+ }
+ else if (IsImmediate(aString))
+ {
+ theValues->mElementVector.push_back(new SingleDataElement(aString));
+ }
+ else
+ {
+ std::string aDefineName = StringToUpper(aString);
+
+ DataElementMap::iterator anItr = mDefineMap.find(aDefineName);
+
+ if (anItr == mDefineMap.end())
+ {
+ Error("Unable to Dereference \"" + aString + "\"");
+ return false;
+ }
+
+ theValues->mElementVector.push_back(anItr->second->Duplicate());
+ }
+ }
+
+
+ }
+ }
+
+ return true;
+}
+
+std::string DescParser::DataElementToString(DataElement* theDataElement)
+{
+ if (theDataElement->mIsList)
+ {
+ ListDataElement* aListDataElement = (ListDataElement*) theDataElement;
+
+ std::string aString = "(";
+
+ for (ulong i = 0; i < aListDataElement->mElementVector.size(); i++)
+ {
+ if (i != 0)
+ aString += ", ";
+
+ aString += DataElementToString(aListDataElement->mElementVector[i]);
+ }
+
+ aString += ")";
+
+ return aString;
+ }
+ else
+ {
+ SingleDataElement* aSingleDataElement = (SingleDataElement*) theDataElement;
+ return aSingleDataElement->mString;
+ }
+}
+
+bool DescParser::DataToString(DataElement* theSource, std::string* theString)
+{
+ *theString = "";
+
+ if (theSource->mIsList)
+ return false;
+
+ std::string aDefName = ((SingleDataElement*) theSource)->mString;
+
+ DataElement* aDataElement = Dereference(aDefName);
+
+ if (aDataElement != NULL)
+ {
+ if (aDataElement->mIsList)
+ return false;
+
+ *theString = Unquote(((SingleDataElement*) aDataElement)->mString);
+ }
+ else
+ *theString = Unquote(aDefName);
+
+ return true;
+}
+
+bool DescParser::DataToInt(DataElement* theSource, int* theInt)
+{
+ *theInt = 0;
+
+ std::string aTempString;
+ if (!DataToString(theSource, &aTempString))
+ return false;
+
+ if (!StringToInt(aTempString, theInt))
+ return false;
+
+ return true;
+}
+
+bool DescParser::DataToStringVector(DataElement* theSource, StringVector* theStringVector)
+{
+ theStringVector->clear();
+
+ ListDataElement aStaticValues;
+ ListDataElement* aValues;
+
+ if (theSource->mIsList)
+ {
+ if (!GetValues((ListDataElement*) theSource, &aStaticValues))
+ return false;
+
+ aValues = &aStaticValues;
+ }
+ else
+ {
+ std::string aDefName = ((SingleDataElement*) theSource)->mString;
+
+ DataElement* aDataElement = Dereference(aDefName);
+
+ if (aDataElement == NULL)
+ {
+ Error("Unable to Dereference \"" + aDefName + "\"");
+ return false;
+ }
+
+ if (!aDataElement->mIsList)
+ return false;
+
+ aValues = (ListDataElement*) aDataElement;
+ }
+
+ for (ulong i = 0; i < aValues->mElementVector.size(); i++)
+ {
+ if (aValues->mElementVector[i]->mIsList)
+ {
+ theStringVector->clear();
+ return false;
+ }
+
+ SingleDataElement* aSingleDataElement = (SingleDataElement*) aValues->mElementVector[i];
+
+ theStringVector->push_back(aSingleDataElement->mString);
+ }
+
+ return true;
+}
+
+bool DescParser::DataToList(DataElement* theSource, ListDataElement* theValues)
+{
+ if (theSource->mIsList)
+ {
+ return GetValues((ListDataElement*) theSource, theValues);
+ }
+
+ DataElement* aDataElement = Dereference(((SingleDataElement*) theSource)->mString);
+
+ if ((aDataElement == NULL) || (!aDataElement->mIsList))
+ return false;
+
+ ListDataElement* aListElement = (ListDataElement*) aDataElement;
+
+ *theValues = *aListElement;
+
+ return true;
+}
+
+bool DescParser::DataToIntVector(DataElement* theSource, IntVector* theIntVector)
+{
+ theIntVector->clear();
+
+ StringVector aStringVector;
+ if (!DataToStringVector(theSource, &aStringVector))
+ return false;
+
+ for (ulong i = 0; i < aStringVector.size(); i++)
+ {
+ int aIntVal;
+ if (!StringToInt(aStringVector[i], &aIntVal))
+ return false;
+
+ theIntVector->push_back(aIntVal);
+ }
+
+ return true;
+}
+
+bool DescParser::DataToDoubleVector(DataElement* theSource, DoubleVector* theDoubleVector)
+{
+ theDoubleVector->clear();
+
+ StringVector aStringVector;
+ if (!DataToStringVector(theSource, &aStringVector))
+ return false;
+
+ for (ulong i = 0; i < aStringVector.size(); i++)
+ {
+ double aDoubleVal;
+ if (!StringToDouble(aStringVector[i], &aDoubleVal))
+ return false;
+
+ theDoubleVector->push_back(aDoubleVal);
+ }
+
+ return true;
+}
+
+bool DescParser::ParseToList(const std::string& theString, ListDataElement* theList, bool expectListEnd, int* theStringPos)
+{
+ bool inSingleQuotes = false;
+ bool inDoubleQuotes = false;
+ bool escaped = false;
+
+ SingleDataElement* aCurSingleDataElement = NULL;
+
+ int aStringPos = 0;
+
+ if (theStringPos == NULL)
+ theStringPos = &aStringPos;
+
+ while (*theStringPos < (int) theString.length())
+ {
+ bool addSingleChar = false;
+ char aChar = theString[(*theStringPos)++];
+
+ bool isSeperator = (aChar == ' ') || (aChar == '\t') || (aChar == '\n') || (aChar == ',');
+
+ if (escaped)
+ {
+ addSingleChar = true;
+ escaped = false;
+ }
+ else
+ {
+ if ((aChar == '\'') && (!inDoubleQuotes))
+ inSingleQuotes = !inSingleQuotes;
+ else if ((aChar == '"') && (!inSingleQuotes))
+ inDoubleQuotes = !inDoubleQuotes;
+
+ if (aChar == '\\')
+ {
+ escaped = true;
+ }
+ else if ((!inSingleQuotes) && (!inDoubleQuotes))
+ {
+ if (aChar == ')')
+ {
+ if (expectListEnd)
+ return true;
+ else
+ {
+ Error("Unexpected List End");
+ return false;
+ }
+ }
+ else if (aChar == '(')
+ {
+ if (aCurSingleDataElement != NULL)
+ {
+ Error("Unexpected List Start");
+ return false;
+ }
+ else
+ {
+ ListDataElement* aChildList = new ListDataElement();
+
+ if (!ParseToList(theString, aChildList, true, theStringPos))
+ return false;
+
+ theList->mElementVector.push_back(aChildList);
+ }
+ }
+ else if (isSeperator)
+ {
+ if (aCurSingleDataElement != NULL)
+ aCurSingleDataElement = NULL;
+ }
+ else
+ addSingleChar = true;
+ }
+ else
+ addSingleChar = true;
+ }
+
+ if (addSingleChar)
+ {
+ if (aCurSingleDataElement == NULL)
+ {
+ aCurSingleDataElement = new SingleDataElement();
+ theList->mElementVector.push_back(aCurSingleDataElement);
+ }
+
+ aCurSingleDataElement->mString += aChar;
+ }
+ }
+
+ if (inSingleQuotes)
+ {
+ Error("Unterminated Single Quotes");
+ return false;
+ }
+
+ if (inDoubleQuotes)
+ {
+ Error("Unterminated Double Quotes");
+ return false;
+ }
+
+ if (expectListEnd)
+ {
+ Error("Unterminated List");
+ return false;
+ }
+
+ return true;
+}
+
+bool DescParser::ParseDescriptorLine(const std::string& theDescriptorLine)
+{
+ ListDataElement aParams;
+ if (!ParseToList(theDescriptorLine, &aParams, false, NULL))
+ return false;
+
+ if (aParams.mElementVector.size() > 0)
+ {
+ if (aParams.mElementVector[0]->mIsList)
+ {
+ Error("Missing Command");
+ return false;
+ }
+
+ if (!HandleCommand(aParams))
+ return false;
+ }
+
+ return true;
+}
+
+bool DescParser::LoadDescriptor(const std::string& theFileName)
+{
+ mCurrentLineNum = 0;
+ int aLineCount = 0;
+ bool hasErrors = false;
+
+ //Apparently VC6 doesn't have a clear() function for basic_strings
+ //mError.clear();
+ mError.erase();
+ mError.erase(mError.begin());
+
+ PFILE *aStream = p_fopen(theFileName.c_str(),"r");
+ if (aStream==NULL)
+ return false;
+
+ char aBuffChar = 0;
+
+ while (!p_feof(aStream))
+ {
+ int aChar;
+
+ bool skipLine = false;
+ bool atLineStart = true;
+ bool inSingleQuotes = false;
+ bool inDoubleQuotes = false;
+ bool escaped = false;
+ bool isIndented = false;
+
+ for (;;)
+ {
+ if (aBuffChar != 0)
+ {
+ aChar = aBuffChar;
+ aBuffChar = 0;
+ }
+ else
+ {
+ aChar = p_fgetc(aStream);
+ if (aChar==EOF)
+ break;
+ }
+
+ if (aChar != '\r')
+ {
+ if (aChar == '\n')
+ aLineCount++;
+
+ if (((aChar == ' ') || (aChar == '\t')) && (atLineStart))
+ isIndented = true;
+
+ if ((!atLineStart) || ((aChar != ' ') && (aChar != '\t') && (aChar != '\n')))
+ {
+ if (atLineStart)
+ {
+ if ((mCmdSep & CMDSEP_NO_INDENT) && (!isIndented) && (mCurrentLine.size() > 0))
+ {
+ // Start a new non-indented line
+ aBuffChar = aChar;
+ break;
+ }
+
+ if (aChar == '#')
+ skipLine = true;
+
+ atLineStart = false;
+ }
+
+ if (aChar == '\n')
+ {
+ isIndented = false;
+ atLineStart = true;
+ }
+
+ if ((aChar == '\n') && (skipLine))
+ {
+ skipLine = false;
+ }
+ else if (!skipLine)
+ {
+ if (aChar == '\\' && (inSingleQuotes || inDoubleQuotes) && !escaped)
+ escaped = true;
+ else
+ {
+ if ((aChar == '\'') && (!inDoubleQuotes) && (!escaped))
+ inSingleQuotes = !inSingleQuotes;
+
+ if ((aChar == '"') && (!inSingleQuotes) && (!escaped))
+ inDoubleQuotes = !inDoubleQuotes;
+
+ if ((aChar == ';') && (mCmdSep & CMDSEP_SEMICOLON) && (!inSingleQuotes) && (!inDoubleQuotes))
+ break;
+
+ if(escaped) // stay escaped for when this is actually parsed
+ {
+ mCurrentLine += '\\';
+ escaped = false;
+ }
+
+ if (mCurrentLine.size() == 0)
+ mCurrentLineNum = aLineCount + 1;
+
+ mCurrentLine += aChar;
+ }
+ }
+ }
+ }
+ }
+
+ if (mCurrentLine.length() > 0)
+ {
+ if (!ParseDescriptorLine(mCurrentLine))
+ {
+ hasErrors = true;
+ break;
+ }
+
+ //Apparently VC6 doesn't have a clear() function for basic_strings
+ //mCurrentLine.clear();
+ mCurrentLine.erase();
+ }
+ }
+
+ //Apparently VC6 doesn't have a clear() function for basic_strings
+ //mCurrentLine.clear();
+ mCurrentLine.erase();
+ mCurrentLineNum = 0;
+
+ p_fclose(aStream);
+ return !hasErrors;
+}
diff --git a/osframework/source/SexyAppFramework/DescParser.h b/osframework/source/SexyAppFramework/DescParser.h
new file mode 100644
index 0000000..f8821ae
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DescParser.h
@@ -0,0 +1,101 @@
+#ifndef __DESCPARSER_H__
+#define __DESCPARSER_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+class DataElement
+{
+public:
+ bool mIsList;
+
+public:
+ DataElement();
+ virtual ~DataElement();
+
+ virtual DataElement* Duplicate() = NULL;
+};
+
+class SingleDataElement : public DataElement
+{
+public:
+ std::string mString;
+
+public:
+ SingleDataElement();
+ SingleDataElement(const std::string theString);
+ virtual ~SingleDataElement();
+
+ virtual DataElement* Duplicate();
+};
+
+typedef std::vector<DataElement*> ElementVector;
+
+class ListDataElement : public DataElement
+{
+public:
+ ElementVector mElementVector;
+
+public:
+ ListDataElement();
+ ListDataElement(const ListDataElement& theListDataElement);
+ virtual ~ListDataElement();
+
+ ListDataElement& operator=(const ListDataElement& theListDataElement);
+
+ virtual DataElement* Duplicate();
+};
+
+typedef std::map<std::string, DataElement*> DataElementMap;
+typedef std::vector<std::string> StringVector;
+typedef std::vector<int> IntVector;
+typedef std::vector<double> DoubleVector;
+
+class DescParser
+{
+public:
+ enum
+ {
+ CMDSEP_SEMICOLON = 1,
+ CMDSEP_NO_INDENT = 2
+ };
+
+public:
+ int mCmdSep;
+
+ std::string mError;
+ int mCurrentLineNum;
+ std::string mCurrentLine;
+ DataElementMap mDefineMap;
+
+public:
+ virtual bool Error(const std::string& theError);
+ virtual DataElement* Dereference(const std::string& theString);
+ bool IsImmediate(const std::string& theString);
+ std::string Unquote(const std::string& theQuotedString);
+ bool GetValues(ListDataElement* theSource, ListDataElement* theValues);
+ std::string DataElementToString(DataElement* theDataElement);
+ bool DataToString(DataElement* theSource, std::string* theString);
+ bool DataToInt(DataElement* theSource, int* theInt);
+ bool DataToStringVector(DataElement* theSource, StringVector* theStringVector);
+ bool DataToList(DataElement* theSource, ListDataElement* theValues);
+ bool DataToIntVector(DataElement* theSource, IntVector* theIntVector);
+ bool DataToDoubleVector(DataElement* theSource, DoubleVector* theDoubleVector);
+ bool ParseToList(const std::string& theString, ListDataElement* theList, bool expectListEnd, int* theStringPos);
+ bool ParseDescriptorLine(const std::string& theDescriptorLine);
+
+ // You must implement this one
+ virtual bool HandleCommand(const ListDataElement& theParams) = 0;
+
+public:
+ DescParser();
+ virtual ~DescParser();
+
+ bool LoadDescriptor(const std::string& theFileName);
+};
+
+}
+
+#endif //__DESCPARSER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Dialog.cpp b/osframework/source/SexyAppFramework/Dialog.cpp
new file mode 100644
index 0000000..0a273bd
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Dialog.cpp
@@ -0,0 +1,407 @@
+#include "Common.h"
+#include "Dialog.h"
+#include "DialogButton.h"
+#include "SexyAppBase.h"
+#include "WidgetManager.h"
+#include "SysFont.h"
+#include "ImageFont.h"
+
+using namespace Sexy;
+
+
+SexyString Sexy::DIALOG_YES_STRING = _S("YES");
+SexyString Sexy::DIALOG_NO_STRING = _S("NO");
+SexyString Sexy::DIALOG_OK_STRING = _S("OK");
+SexyString Sexy::DIALOG_CANCEL_STRING = _S("CANCEL");
+
+static int gDialogColors[][3] =
+{{255, 255, 255},
+{255, 255, 0},
+{255, 255, 255},
+{255, 255, 255},
+{255, 255, 255},
+
+{80, 80, 80},
+{255, 255, 255}};
+
+Dialog::Dialog(Image* theComponentImage, Image* theButtonComponentImage, int theId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode)
+{
+ mId = theId;
+ mResult = 0x7FFFFFFF;
+ mComponentImage = theComponentImage;
+ mIsModal = isModal;
+ mContentInsets = Insets(24, 24, 24, 24);
+ mTextAlign = 0;
+ mLineSpacingOffset = 0;
+ mSpaceAfterHeader = 10;
+ mButtonSidePadding = 0;
+ mButtonHorzSpacing = 8;
+ mDialogListener = gSexyAppBase;
+
+ mDialogHeader = theDialogHeader;
+ mDialogFooter = theDialogFooter;
+ mButtonMode = theButtonMode;
+
+ if ((mButtonMode == BUTTONS_YES_NO) || (mButtonMode == BUTTONS_OK_CANCEL))
+ {
+ mYesButton = new DialogButton(theButtonComponentImage, ID_YES, this);
+ mNoButton = new DialogButton(theButtonComponentImage, ID_NO, this);
+
+ if (mButtonMode == BUTTONS_YES_NO)
+ {
+ mYesButton->mLabel = DIALOG_YES_STRING;
+ mNoButton->mLabel = DIALOG_NO_STRING;
+ }
+ else
+ {
+ mYesButton->mLabel = DIALOG_OK_STRING;
+ mNoButton->mLabel = DIALOG_CANCEL_STRING;
+ }
+ }
+ else if (mButtonMode == BUTTONS_FOOTER)
+ {
+ mYesButton = new DialogButton(theButtonComponentImage, ID_FOOTER, this);
+ mYesButton->mLabel = mDialogFooter;
+ mNoButton = NULL;
+ }
+ else
+ {
+ mYesButton = NULL;
+ mNoButton = NULL;
+ mNumButtons = 0;
+ }
+
+ mDialogLines = theDialogLines;
+
+ mButtonHeight = (theButtonComponentImage == NULL) ? 24 : theButtonComponentImage->mHeight;
+
+ mHasTransparencies = true;
+ mHasAlpha = true;
+
+ mHeaderFont = NULL;
+ mLinesFont = NULL;
+
+ mDragging = false;
+ mPriority = 1;
+
+ if (theButtonComponentImage == NULL)
+ {
+ gDialogColors[COLOR_BUTTON_TEXT][0] = 0;
+ gDialogColors[COLOR_BUTTON_TEXT][1] = 0;
+ gDialogColors[COLOR_BUTTON_TEXT][2] = 0;
+ gDialogColors[COLOR_BUTTON_TEXT_HILITE][0] = 0;
+ gDialogColors[COLOR_BUTTON_TEXT_HILITE][1] = 0;
+ gDialogColors[COLOR_BUTTON_TEXT_HILITE][2] = 0;
+ }
+
+ SetColors(gDialogColors, NUM_COLORS);
+}
+
+
+Dialog::~Dialog()
+{
+ delete mYesButton;
+ delete mNoButton;
+
+ delete mHeaderFont;
+ delete mLinesFont;
+}
+
+void Dialog::SetColor(int theIdx, const Color& theColor)
+{
+ Widget::SetColor(theIdx, theColor);
+
+ if (theIdx == COLOR_BUTTON_TEXT)
+ {
+ if (mYesButton != NULL)
+ mYesButton->SetColor(DialogButton::COLOR_LABEL, theColor);
+ if (mNoButton != NULL)
+ mNoButton->SetColor(DialogButton::COLOR_LABEL, theColor);
+ }
+ else if (theIdx == COLOR_BUTTON_TEXT_HILITE)
+ {
+ if (mYesButton != NULL)
+ mYesButton->SetColor(DialogButton::COLOR_LABEL_HILITE, theColor);
+ if (mNoButton != NULL)
+ mNoButton->SetColor(DialogButton::COLOR_LABEL_HILITE, theColor);
+ }
+}
+
+void Dialog::SetButtonFont(Font* theFont)
+{
+ if (mYesButton != NULL)
+ mYesButton->SetFont(theFont);
+
+ if (mNoButton != NULL)
+ mNoButton->SetFont(theFont);
+}
+
+void Dialog::SetHeaderFont(Font* theFont)
+{
+ delete mHeaderFont;
+ mHeaderFont = theFont->Duplicate();
+}
+
+void Dialog::SetLinesFont(Font* theFont)
+{
+ delete mLinesFont;
+ mLinesFont = theFont->Duplicate();
+}
+
+void Dialog::EnsureFonts()
+{
+ if (mHeaderFont == NULL)
+ mHeaderFont = new SysFont(gSexyAppBase, "Arial Unicode MS", 14);
+ if (mLinesFont == NULL)
+ mLinesFont = new SysFont(gSexyAppBase, "Arial Unicode MS", 12);
+}
+
+int Dialog::GetPreferredHeight(int theWidth)
+{
+ EnsureFonts();
+
+ int aHeight = mContentInsets.mTop + mContentInsets.mBottom + mBackgroundInsets.mTop + mBackgroundInsets.mBottom;
+
+ bool needSpace = false;
+ if (mDialogHeader.length() > 0)
+ {
+ aHeight += mHeaderFont->GetHeight() - mHeaderFont->GetAscentPadding();
+ needSpace = true;
+ }
+
+ if (mDialogLines.length() > 0)
+ {
+ if (needSpace)
+ aHeight += mSpaceAfterHeader;
+ Graphics g;
+ g.SetFont(mLinesFont);
+ aHeight += GetWordWrappedHeight(&g, theWidth-mContentInsets.mLeft-mContentInsets.mRight-mBackgroundInsets.mLeft-mBackgroundInsets.mRight-4, mDialogLines, mLinesFont->GetLineSpacing() + mLineSpacingOffset);
+ needSpace = true;
+ }
+
+ if ((mDialogFooter.length() != 0) && (mButtonMode != BUTTONS_FOOTER))
+ {
+ if (needSpace)
+ aHeight += 8;
+ aHeight += mHeaderFont->GetLineSpacing();
+ needSpace = true;
+ }
+
+ if (mYesButton != NULL)
+ {
+ if (needSpace)
+ aHeight += 8;
+ aHeight += mButtonHeight + 8;
+ }
+
+ return aHeight;
+}
+
+void Dialog::Draw(Graphics* g)
+{
+ EnsureFonts();
+
+ Rect aBoxRect(mBackgroundInsets.mLeft,mBackgroundInsets.mTop,mWidth-mBackgroundInsets.mLeft-mBackgroundInsets.mRight,mHeight-mBackgroundInsets.mTop-mBackgroundInsets.mBottom);
+ if (mComponentImage != NULL)
+ {
+ g->DrawImageBox(aBoxRect,mComponentImage);
+ }
+ else
+ {
+ g->SetColor(GetColor(COLOR_OUTLINE, Color(gDialogColors[COLOR_OUTLINE])));
+ g->DrawRect(12, 12, mWidth - 12*2 - 1, mHeight - 12*2 - 1);
+ g->SetColor(GetColor(COLOR_BKG, Color(gDialogColors[COLOR_BKG])));
+ g->FillRect(12+1, 12+1, mWidth - 12*2 - 2, mHeight - 12*2 - 2);
+
+ g->SetColor(Color(0, 0, 0, 128));
+ g->FillRect(mWidth - 12, 12*2, 12, mHeight - 12*3);
+ g->FillRect(12*2, mHeight-12, mWidth - 12*2, 12);
+ }
+
+ int aCurY = mContentInsets.mTop + mBackgroundInsets.mTop;
+
+ if (mDialogHeader.length() > 0)
+ {
+ aCurY += mHeaderFont->GetAscent() - mHeaderFont->GetAscentPadding();
+
+ g->SetFont(mHeaderFont);
+ g->SetColor(mColors[COLOR_HEADER]);
+ WriteCenteredLine(g, aCurY, mDialogHeader);
+
+ aCurY += mHeaderFont->GetHeight() - mHeaderFont->GetAscent();
+
+ aCurY += mSpaceAfterHeader;
+ }
+
+ //g->SetFont(mLinesFont);
+ g->SetFont(mLinesFont);
+ g->SetColor(mColors[COLOR_LINES]);
+
+ /*for (int i = 0; i < mDialogLines.size(); i++)
+ {
+ WriteCenteredLine(g, aCurY, mDialogLines[i]);
+ aCurY += mLinesFont->GetHeight();
+ }*/
+
+ Rect aRect(mBackgroundInsets.mLeft+mContentInsets.mLeft+2, aCurY, mWidth-mContentInsets.mLeft-mContentInsets.mRight-mBackgroundInsets.mLeft-mBackgroundInsets.mRight-4, 0);
+ aCurY += WriteWordWrapped(g, aRect, mDialogLines, mLinesFont->GetLineSpacing() + mLineSpacingOffset, mTextAlign);
+
+ if ((mDialogFooter.length() != 0) && (mButtonMode != BUTTONS_FOOTER))
+ {
+ aCurY += 8;
+ aCurY += mHeaderFont->GetLineSpacing();
+
+ g->SetFont(mHeaderFont);
+ g->SetColor(mColors[COLOR_FOOTER]);
+ WriteCenteredLine(g, aCurY, mDialogFooter);
+ }
+}
+
+void Dialog::AddedToManager(WidgetManager* theWidgetManager)
+{
+ Widget::AddedToManager(theWidgetManager);
+
+ if (mYesButton != NULL)
+ theWidgetManager->AddWidget(mYesButton);
+ if (mNoButton != NULL)
+ theWidgetManager->AddWidget(mNoButton);
+}
+
+void Dialog::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ Widget::RemovedFromManager(theWidgetManager);
+
+ if (mYesButton != NULL)
+ theWidgetManager->RemoveWidget(mYesButton);
+ if (mNoButton != NULL)
+ theWidgetManager->RemoveWidget(mNoButton);
+}
+
+void Dialog::OrderInManagerChanged()
+{
+ Widget::OrderInManagerChanged();
+ if (mYesButton != NULL)
+ mWidgetManager->PutInfront(mYesButton,this);
+ if (mNoButton != NULL)
+ mWidgetManager->PutInfront(mNoButton,this);
+}
+
+void Dialog::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Widget::Resize(theX, theY, theWidth, theHeight);
+
+ if ((mYesButton != NULL) && (mNoButton != NULL))
+ {
+ int aBtnWidth = (mWidth - mContentInsets.mLeft - mContentInsets.mRight - mBackgroundInsets.mLeft - mBackgroundInsets.mRight - mButtonSidePadding*2 - mButtonHorzSpacing) / 2;
+ int aBtnHeight = mButtonHeight;
+
+ mYesButton->Resize(mX + mBackgroundInsets.mLeft + mContentInsets.mLeft + mButtonSidePadding, mY + mHeight - mContentInsets.mBottom - mBackgroundInsets.mBottom - aBtnHeight, aBtnWidth, aBtnHeight);
+ mNoButton->Resize(mYesButton->mX + aBtnWidth + mButtonHorzSpacing, mYesButton->mY, aBtnWidth, aBtnHeight);
+ }
+ else if (mYesButton != NULL)
+ {
+ int aBtnHeight = mButtonHeight;
+
+ mYesButton->Resize(mX + mContentInsets.mLeft + mBackgroundInsets.mLeft, mY + mHeight - mContentInsets.mBottom - mBackgroundInsets.mBottom - aBtnHeight,
+ mWidth - mContentInsets.mLeft - mContentInsets.mRight - mBackgroundInsets.mLeft - mBackgroundInsets.mRight, aBtnHeight);
+ }
+}
+
+void Dialog::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ if (theClickCount == 1)
+ {
+ mWidgetManager->mApp->SetCursor(CURSOR_DRAGGING);
+ mDragging = true;
+ mDragMouseX = x;
+ mDragMouseY = y;
+ }
+ Widget::MouseDown(x,y,theBtnNum, theClickCount);
+}
+
+void Dialog::MouseDrag(int x, int y)
+{
+ if (mDragging)
+ {
+ int aNewX = mX + x - mDragMouseX;
+ int aNewY = mY + y - mDragMouseY;
+
+ if (aNewX < -8)
+ aNewX = -8;
+ else if (aNewX + mWidth > mWidgetManager->mWidth + 8)
+ aNewX = mWidgetManager->mWidth - mWidth + 8;
+
+ if (aNewY < -8)
+ aNewY = -8;
+ else if (aNewY + mHeight > mWidgetManager->mHeight + 8)
+ aNewY = mWidgetManager->mHeight- mHeight + 8;
+
+ mDragMouseX = mX + x - aNewX;
+ mDragMouseY = mY + y - aNewY;
+
+ if (mDragMouseX < 8)
+ mDragMouseX = 8;
+ else if (mDragMouseX > mWidth-9)
+ mDragMouseX = mWidth-9;
+
+ if (mDragMouseY < 8)
+ mDragMouseY = 8;
+ else if (mDragMouseY > mHeight-9)
+ mDragMouseY = mHeight-9;
+
+ Move(aNewX, aNewY);
+ }
+}
+
+void Dialog::MouseUp(int x, int y, int theBtnNum, int theClickCount)
+{
+ if (mDragging)
+ {
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+ mDragging = false;
+ }
+ Widget::MouseUp(x,y, theBtnNum, theClickCount);
+}
+
+void Dialog::Update()
+{
+ Widget::Update();
+
+ //Move(mX, mY+1);
+}
+
+bool Dialog::IsModal()
+{
+ return mIsModal;
+}
+
+int Dialog::WaitForResult(bool autoKill)
+{
+ //gSexyAppBase->DoMainLoop(mId);
+
+ while ((gSexyAppBase->UpdateAppStep(NULL)) && (mWidgetManager != NULL) && (mResult == 0x7FFFFFFF));
+
+ if (autoKill)
+ gSexyAppBase->KillDialog(mId);
+
+ return mResult;
+}
+
+void Dialog::ButtonPress(int theId)
+{
+ if ((theId == ID_YES) || (theId == ID_NO))
+ mDialogListener->DialogButtonPress(mId, theId);
+}
+
+void Dialog::ButtonDepress(int theId)
+{
+ if ((theId == ID_YES) || (theId == ID_NO))
+ {
+ mResult = theId;
+ mDialogListener->DialogButtonDepress(mId, theId);
+ }
+}
+
+void Dialog::ButtonDownTick(int theId)
+{
+}
diff --git a/osframework/source/SexyAppFramework/Dialog.h b/osframework/source/SexyAppFramework/Dialog.h
new file mode 100644
index 0000000..b092cdb
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Dialog.h
@@ -0,0 +1,123 @@
+#ifndef __DIALOG_H__
+#define __DIALOG_H__
+
+#include "Widget.h"
+#include "ButtonListener.h"
+
+namespace Sexy
+{
+
+class DialogListener;
+class ButtonWidget;
+class DialogButton;
+class Font;
+
+extern SexyString DIALOG_YES_STRING;
+extern SexyString DIALOG_NO_STRING;
+extern SexyString DIALOG_OK_STRING;
+extern SexyString DIALOG_CANCEL_STRING;
+
+typedef std::vector<std::string> StringVector;
+
+class Dialog : public Widget, public ButtonListener
+{
+public:
+ enum
+ {
+ BUTTONS_NONE,
+ BUTTONS_YES_NO,
+ BUTTONS_OK_CANCEL,
+ BUTTONS_FOOTER
+ };
+
+ enum
+ {
+ ID_YES = 1000,
+ ID_NO = 1001,
+ ID_OK = 1000,
+ ID_CANCEL = 1001,
+ ID_FOOTER = 1000
+ };
+
+ enum
+ {
+ COLOR_HEADER = 0,
+ COLOR_LINES,
+ COLOR_FOOTER,
+ COLOR_BUTTON_TEXT,
+ COLOR_BUTTON_TEXT_HILITE,
+ COLOR_BKG,
+ COLOR_OUTLINE,
+ NUM_COLORS
+ };
+
+ DialogListener* mDialogListener;
+ Image* mComponentImage;
+ DialogButton* mYesButton;
+ DialogButton* mNoButton;
+ int mNumButtons;
+
+ SexyString mDialogHeader;
+ SexyString mDialogFooter;
+ SexyString mDialogLines;
+
+ int mButtonMode;
+ Font* mHeaderFont;
+ Font* mLinesFont;
+ int mTextAlign;
+ int mLineSpacingOffset;
+ int mButtonHeight;
+ Insets mBackgroundInsets;
+ Insets mContentInsets;
+ int mSpaceAfterHeader;
+ bool mDragging;
+ int mDragMouseX;
+ int mDragMouseY;
+ int mId;
+ bool mIsModal;
+ int mResult;
+
+ int mButtonHorzSpacing;
+ int mButtonSidePadding;
+
+
+public:
+ void EnsureFonts();
+
+public:
+ Dialog(Image* theComponentImage, Image* theButtonComponentImage,
+ int theId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode); //UNICODE
+
+ virtual ~Dialog();
+
+ virtual void SetButtonFont(Font* theFont);
+ virtual void SetHeaderFont(Font* theFont);
+ virtual void SetLinesFont(Font* theFont);
+
+ virtual void SetColor(int theIdx, const Color& theColor);
+ virtual int GetPreferredHeight(int theWidth);
+
+ virtual void Draw(Graphics* g);
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+ virtual void OrderInManagerChanged();
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+
+ virtual void MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+ virtual void MouseUp(int x, int y) { Widget::MouseUp(x, y); }
+ virtual void MouseUp(int x, int y, int theClickCount) { Widget::MouseUp(x, y, theClickCount); }
+ virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount);
+ virtual void Update();
+ virtual bool IsModal();
+ virtual int WaitForResult(bool autoKill = true);
+
+ virtual void ButtonPress(int theId);
+ virtual void ButtonDepress(int theId);
+ virtual void ButtonDownTick(int theId);
+};
+
+}
+
+#endif //__DIALOG_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DialogButton.cpp b/osframework/source/SexyAppFramework/DialogButton.cpp
new file mode 100644
index 0000000..104bd60
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DialogButton.cpp
@@ -0,0 +1,92 @@
+#include "DialogButton.h"
+#include "SysFont.h"
+#include "WidgetManager.h"
+
+using namespace Sexy;
+
+static int gDialogButtonColors[][3] = {
+ {255, 255, 255},
+ {255, 255, 255},
+ {0, 0, 0},
+ {255, 255, 255},
+ {132, 132, 132},
+ {212, 212, 212}};
+
+DialogButton::DialogButton(Image* theComponentImage, int theId, ButtonListener* theListener) :
+ ButtonWidget(theId, theListener)
+{
+ mComponentImage = theComponentImage;
+
+ mTextOffsetX = mTextOffsetY = 0;
+ mTranslateX = mTranslateY = 1;
+ mDoFinger = true;
+
+ SetColors(gDialogButtonColors, NUM_COLORS);
+}
+
+void DialogButton::Draw(Graphics* g)
+{
+ if (mBtnNoDraw)
+ return;
+
+ if (mComponentImage==NULL)
+ {
+ ButtonWidget::Draw(g);
+ return;
+ }
+
+ if ((mFont == NULL) && (mLabel.length() > 0))
+ mFont = new SysFont(mWidgetManager->mApp, "Arial Unicode MS", 12, true);
+
+ bool doTranslate = IsButtonDown();
+
+ if (mNormalRect.mWidth==0)
+ {
+ if (doTranslate)
+ g->Translate(mTranslateX, mTranslateY);
+
+ g->DrawImageBox(Rect(0, 0, mWidth, mHeight), mComponentImage);
+ }
+ else
+ {
+ if (mDisabled && (mDisabledRect.mWidth > 0) && (mDisabledRect.mHeight > 0))
+ g->DrawImageBox(mDisabledRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+ else if (IsButtonDown())
+ g->DrawImageBox(mDownRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+ else if ((mOverAlpha > 0))
+ {
+ if (mOverAlpha<1)
+ g->DrawImageBox(mNormalRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+
+ g->SetColorizeImages(true);
+ g->SetColor(Color(255,255,255,(int)(mOverAlpha * 255)));
+ g->DrawImageBox(mOverRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+ g->SetColorizeImages(false);
+ }
+ else if(mIsOver)
+ g->DrawImageBox(mOverRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+ else
+ g->DrawImageBox(mNormalRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
+
+ if (doTranslate)
+ g->Translate(mTranslateX, mTranslateY);
+ }
+
+ if (mFont != NULL)
+ {
+ g->SetFont(mFont);
+
+ if (mIsOver)
+ g->SetColor(mColors[COLOR_LABEL_HILITE]);
+ else
+ g->SetColor(mColors[COLOR_LABEL]);
+
+ int aFontX = (mWidth - mFont->StringWidth(mLabel))/2;
+ int aFontY = (mHeight + mFont->GetAscent() - mFont->GetAscentPadding() - mFont->GetAscent()/6 - 1)/2;
+
+ g->DrawString(mLabel, aFontX + mTextOffsetX, aFontY + mTextOffsetY);
+ }
+
+ if (doTranslate)
+ g->Translate(-mTranslateX, -mTranslateY);
+}
diff --git a/osframework/source/SexyAppFramework/DialogButton.h b/osframework/source/SexyAppFramework/DialogButton.h
new file mode 100644
index 0000000..5fe94a1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DialogButton.h
@@ -0,0 +1,24 @@
+#ifndef __DIALOGBUTTON_H__
+#define __DIALOGBUTTON_H__
+
+#include "ButtonWidget.h"
+
+namespace Sexy
+{
+
+class DialogButton : public ButtonWidget
+{
+public:
+ Image* mComponentImage;
+ int mTranslateX, mTranslateY;
+ int mTextOffsetX, mTextOffsetY;
+
+public:
+ DialogButton(Image* theComponentImage, int theId, ButtonListener* theListener);
+
+ virtual void Draw(Graphics* g);
+};
+
+}
+
+#endif //__DIALOGBUTTON_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DialogListener.h b/osframework/source/SexyAppFramework/DialogListener.h
new file mode 100644
index 0000000..907759c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DialogListener.h
@@ -0,0 +1,16 @@
+#ifndef __DIALOGLISTENER_H__
+#define __DIALOGLISTENER_H__
+
+namespace Sexy
+{
+
+class DialogListener
+{
+public:
+ virtual void DialogButtonPress(int theDialogId, int theButtonId) {}
+ virtual void DialogButtonDepress(int theDialogId, int theButtonId) {}
+};
+
+}
+
+#endif // __DIALOGLISTENER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/DirectXErrorString.cpp b/osframework/source/SexyAppFramework/DirectXErrorString.cpp
new file mode 100644
index 0000000..9caa378
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DirectXErrorString.cpp
@@ -0,0 +1,220 @@
+#include "DirectXErrorString.h"
+
+#include <d3d.h>
+#include <ddraw.h>
+#include "dsoundversion.h"
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+std::string Sexy::GetDirectXErrorString(HRESULT theResult)
+{
+ switch(theResult)
+ {
+ case DSERR_ALLOCATED: return "DSERR_ALLOCATED";
+ case DSERR_ALREADYINITIALIZED: return "DSERR_ALREADYINITIALIZED";
+ case DSERR_BADFORMAT: return "DSERR_BADFORMAT";
+ case DSERR_BUFFERLOST: return "DSERR_BUFFERLOST";
+ case DSERR_CONTROLUNAVAIL: return "DSERR_CONTROLUNAVAIL";
+ case DSERR_GENERIC: return "DSERR_GENERIC";
+ case DSERR_INVALIDCALL: return "DSERR_INVALIDCALL";
+// case DSERR_INVALIDPARAM: return "DSERR_INVALIDPARAM";
+ case DSERR_NOAGGREGATION: return "DSERR_NOAGGREGATION";
+ case DSERR_NODRIVER: return "DSERR_NODRIVER";
+ case DSERR_NOINTERFACE: return "DSERR_NOINTERFACE";
+ case DSERR_OTHERAPPHASPRIO: return "DSERR_OTHERAPPHASPRIO";
+// case DSERR_OUTOFMEMORY: return "DSERR_OUTOFMEMORY";
+ case DSERR_PRIOLEVELNEEDED: return "DSERR_PRIOLEVELNEEDED";
+ case DSERR_UNINITIALIZED: return "DSERR_UNINITIALIZED";
+// case DSERR_UNSUPPORTED: return "DSERR_UNSUPPORTED";
+
+ case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED";
+ case DDERR_BLTFASTCANTCLIP: return "DDERR_BLTFASTCANTCLIP";
+ case DDERR_CANNOTATTACHSURFACE: return "DDERR_CANNOTATTACHSURFACE";
+ case DDERR_CANNOTDETACHSURFACE: return "DDERR_CANNOTDETACHSURFACE";
+ case DDERR_CANTCREATEDC: return "DDERR_CANTCREATEDC";
+ case DDERR_CANTDUPLICATE: return "DDERR_CANTDUPLICATE";
+ case DDERR_CANTLOCKSURFACE: return "DDERR_CANTLOCKSURFACE";
+ case DDERR_CANTPAGELOCK: return "DDERR_CANTPAGELOCK";
+ case DDERR_CANTPAGEUNLOCK: return "DDERR_CANTPAGEUNLOCK";
+ case DDERR_CLIPPERISUSINGHWND: return "DDERR_CLIPPERISUSINGHWND";
+ case DDERR_COLORKEYNOTSET: return "DDERR_COLORKEYNOTSET";
+ case DDERR_CURRENTLYNOTAVAIL: return "DDERR_CURRENTLYNOTAVAIL";
+ case DDERR_DCALREADYCREATED: return "DDERR_DCALREADYCREATED";
+ case DDERR_DEVICEDOESNTOWNSURFACE: return "DDERR_DEVICEDOESNTOWNSURFACE";
+ case DDERR_DIRECTDRAWALREADYCREATED: return "DDERR_DIRECTDRAWALREADYCREATED";
+ case DDERR_EXCEPTION: return "DDERR_EXCEPTION";
+ case DDERR_EXCLUSIVEMODEALREADYSET: return "DDERR_EXCLUSIVEMODEALREADYSET";
+ case DDERR_EXPIRED: return "DDERR_EXPIRED";
+ case DDERR_HEIGHTALIGN: return "DDERR_HEIGHTALIGN";
+ case DDERR_HWNDALREADYSET: return "DDERR_HWNDALREADYSET";
+ case DDERR_HWNDSUBCLASSED: return "DDERR_HWNDSUBCLASSED";
+ case DDERR_IMPLICITLYCREATED: return "DDERR_IMPLICITLYCREATED";
+ case DDERR_INCOMPATIBLEPRIMARY: return "DDERR_INCOMPATIBLEPRIMARY";
+ case DDERR_INVALIDCAPS: return "DDERR_INVALIDCAPS";
+ case DDERR_INVALIDCLIPLIST: return "DDERR_INVALIDCLIPLIST";
+ case DDERR_INVALIDDIRECTDRAWGUID: return "DDERR_INVALIDDIRECTDRAWGUID";
+ case DDERR_INVALIDMODE: return "DDERR_INVALIDMODE";
+ case DDERR_INVALIDOBJECT: return "DDERR_INVALIDOBJECT";
+ case DDERR_INVALIDPARAMS: return "DDERR_INVALIDPARAMS";
+ case DDERR_INVALIDPIXELFORMAT: return "DDERR_INVALIDPIXELFORMAT";
+ case DDERR_INVALIDPOSITION: return "DDERR_INVALIDPOSITION";
+ case DDERR_INVALIDRECT: return "DDERR_INVALIDRECT";
+ case DDERR_INVALIDSTREAM: return "DDERR_INVALIDSTREAM";
+ case DDERR_INVALIDSURFACETYPE: return "DDERR_INVALIDSURFACETYPE";
+ case DDERR_LOCKEDSURFACES: return "DDERR_LOCKEDSURFACES";
+ case DDERR_MOREDATA: return "DDERR_MOREDATA";
+ case DDERR_NO3D: return "DDERR_NO3D";
+ case DDERR_NOALPHAHW: return "DDERR_NOALPHAHW";
+ case DDERR_NOBLTHW: return "DDERR_NOBLTHW";
+ case DDERR_NOCLIPLIST: return "DDERR_NOCLIPLIST";
+ case DDERR_NOCLIPPERATTACHED: return "DDERR_NOCLIPPERATTACHED";
+ case DDERR_NOCOLORCONVHW: return "DDERR_NOCOLORCONVHW";
+ case DDERR_NOCOLORKEY: return "DDERR_NOCOLORKEY";
+ case DDERR_NOCOLORKEYHW: return "DDERR_NOCOLORKEYHW";
+ case DDERR_NOCOOPERATIVELEVELSET: return "DDERR_NOCOOPERATIVELEVELSET";
+ case DDERR_NODC: return "DDERR_NODC";
+ case DDERR_NODDROPSHW: return "DDERR_NODDROPSHW";
+ case DDERR_NODIRECTDRAWHW: return "DDERR_NODIRECTDRAWHW";
+ case DDERR_NODIRECTDRAWSUPPORT: return "DDERR_NODIRECTDRAWSUPPORT";
+ case DDERR_NOEMULATION: return "DDERR_NOEMULATION";
+ case DDERR_NOEXCLUSIVEMODE: return "DDERR_NOEXCLUSIVEMODE";
+ case DDERR_NOFLIPHW: return "DDERR_NOFLIPHW";
+ case DDERR_NOFOCUSWINDOW: return "DDERR_NOFOCUSWINDOW";
+ case DDERR_NOGDI: return "DDERR_NOGDI";
+ case DDERR_NOHWND: return "DDERR_NOHWND";
+ case DDERR_NOMIPMAPHW: return "DDERR_NOMIPMAPHW";
+ case DDERR_NOMIRRORHW: return "DDERR_NOMIRRORHW";
+ case DDERR_NONONLOCALVIDMEM: return "DDERR_NONONLOCALVIDMEM";
+ case DDERR_NOOPTIMIZEHW: return "DDERR_NOOPTIMIZEHW";
+ case DDERR_NOOVERLAYHW: return "DDERR_NOOVERLAYHW";
+ case DDERR_NOPALETTEATTACHED: return "DDERR_NOPALETTEATTACHED";
+ case DDERR_NOPALETTEHW: return "DDERR_NOPALETTEHW";
+ case DDERR_NORASTEROPHW: return "DDERR_NORASTEROPHW";
+ case DDERR_NOROTATIONHW: return "DDERR_NOROTATIONHW";
+ case DDERR_NOSTEREOHARDWARE: return "DDERR_NOSTEREOHARDWARE";
+ case DDERR_NOSTRETCHHW: return "DDERR_NOSTRETCHHW";
+ case DDERR_NOSURFACELEFT: return "DDERR_NOSURFACELEFT";
+ case DDERR_NOT4BITCOLOR: return "DDERR_NOT4BITCOLOR";
+ case DDERR_NOT4BITCOLORINDEX: return "DDERR_NOT4BITCOLORINDEX";
+ case DDERR_NOT8BITCOLOR: return "DDERR_NOT8BITCOLOR";
+ case DDERR_NOTAOVERLAYSURFACE: return "DDERR_NOTAOVERLAYSURFACE";
+ case DDERR_NOTEXTUREHW: return "DDERR_NOTEXTUREHW";
+ case DDERR_NOTFLIPPABLE: return "DDERR_NOTFLIPPABLE";
+ case DDERR_NOTFOUND: return "DDERR_NOTFOUND";
+ case DDERR_NOTINITIALIZED: return "DDERR_NOTINITIALIZED";
+ case DDERR_NOTLOADED: return "DDERR_NOTLOADED";
+ case DDERR_NOTLOCKED: return "DDERR_NOTLOCKED";
+ case DDERR_NOTPAGELOCKED: return "DDERR_NOTPAGELOCKED";
+ case DDERR_NOTPALETTIZED: return "DDERR_NOTPALETTIZED";
+ case DDERR_NOVSYNCHW: return "DDERR_NOVSYNCHW";
+ case DDERR_NOZBUFFERHW: return "DDERR_NOZBUFFERHW";
+ case DDERR_NOZOVERLAYHW: return "DDERR_NOZOVERLAYHW";
+ case DDERR_OUTOFCAPS: return "DDERR_OUTOFCAPS";
+// case DDERR_OUTOFMEMORY: return "DDERR_OUTOFMEMORY";
+ case DDERR_OUTOFVIDEOMEMORY: return "DDERR_OUTOFVIDEOMEMORY";
+ case DDERR_OVERLAPPINGRECTS: return "DDERR_OVERLAPPINGRECTS";
+ case DDERR_OVERLAYCANTCLIP: return "DDERR_OVERLAYCANTCLIP";
+ case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE";
+ case DDERR_OVERLAYNOTVISIBLE: return "DDERR_OVERLAYNOTVISIBLE";
+ case DDERR_PALETTEBUSY: return "DDERR_PALETTEBUSY";
+ case DDERR_PRIMARYSURFACEALREADYEXISTS: return "DDERR_PRIMARYSURFACEALREADYEXISTS";
+ case DDERR_REGIONTOOSMALL: return "DDERR_REGIONTOOSMALL";
+ case DDERR_SURFACEALREADYATTACHED: return "DDERR_SURFACEALREADYATTACHED";
+ case DDERR_SURFACEALREADYDEPENDENT: return "DDERR_SURFACEALREADYDEPENDENT";
+ case DDERR_SURFACEBUSY: return "DDERR_SURFACEBUSY";
+ case DDERR_SURFACEISOBSCURED: return "DDERR_SURFACEISOBSCURED";
+ case DDERR_SURFACELOST: return "DDERR_SURFACELOST";
+ case DDERR_SURFACENOTATTACHED: return "DDERR_SURFACENOTATTACHED";
+ case DDERR_TOOBIGHEIGHT: return "DDERR_TOOBIGHEIGHT";
+ case DDERR_TOOBIGSIZE: return "DDERR_TOOBIGSIZE";
+ case DDERR_TOOBIGWIDTH: return "DDERR_TOOBIGWIDTH";
+ case DDERR_UNSUPPORTED: return "DDERR_UNSUPPORTED";
+ case DDERR_UNSUPPORTEDFORMAT: return "DDERR_UNSUPPORTEDFORMAT";
+ case DDERR_UNSUPPORTEDMASK: return "DDERR_UNSUPPORTEDMASK";
+ case DDERR_UNSUPPORTEDMODE: return "DDERR_UNSUPPORTEDMODE";
+ case DDERR_VERTICALBLANKINPROGRESS: return "DDERR_VERTICALBLANKINPROGRESS";
+ case DDERR_VIDEONOTACTIVE: return "DDERR_VIDEONOTACTIVE";
+ case DDERR_WASSTILLDRAWING: return "DDERR_WASSTILLDRAWING";
+ case DDERR_WRONGMODE: return "DDERR_WRONGMODE";
+ case DDERR_XALIGN: return "DDERR_XALIGN";
+
+ case D3DERR_BADMAJORVERSION: return "D3DERR_BADMAJORVERSION";
+ case D3DERR_BADMINORVERSION: return "D3DERR_BADMINORVERSION";
+ case D3DERR_COLORKEYATTACHED: return "D3DERR_COLORKEYATTACHED";
+ case D3DERR_CONFLICTINGTEXTUREFILTER: return "D3DERR_CONFLICTINGTEXTUREFILTER";
+ case D3DERR_CONFLICTINGTEXTUREPALETTE: return "D3DERR_CONFLICTINGTEXTUREPALETTE";
+ case D3DERR_CONFLICTINGRENDERSTATE: return "D3DERR_CONFLICTINGRENDERSTATE";
+ case D3DERR_DEVICEAGGREGATED: return "D3DERR_DEVICEAGGREGATED";
+ case D3DERR_INITFAILED: return "D3DERR_INITFAILED";
+ case D3DERR_INBEGIN: return "D3DERR_INBEGIN";
+ case D3DERR_INBEGINSTATEBLOCK: return "D3DERR_INBEGINSTATEBLOCK";
+// case D3DERR_INOVERLAYSTATEBLOCK: return "D3DERR_INOVERLAYSTATEBLOCK";
+ case D3DERR_INVALID_DEVICE: return "D3DERR_INVALID_DEVICE";
+ case D3DERR_INVALIDCURRENTVIEWPORT: return "D3DERR_INVALIDCURRENTVIEWPORT";
+ case D3DERR_INVALIDMATRIX: return "D3DERR_INVALIDMATRIX";
+ case D3DERR_INVALIDPALETTE: return "D3DERR_INVALIDPALETTE";
+ case D3DERR_INVALIDPRIMITIVETYPE: return "D3DERR_INVALIDPRIMITIVETYPE";
+ case D3DERR_INVALIDRAMPTEXTURE: return "D3DERR_INVALIDRAMPTEXTURE";
+ case D3DERR_INVALIDSTATEBLOCK: return "D3DERR_INVALIDSTATEBLOCK";
+ case D3DERR_INVALIDVERTEXFORMAT: return "D3DERR_INVALIDVERTEXFORMAT";
+ case D3DERR_INVALIDVERTEXTYPE: return "D3DERR_INVALIDVERTEXTYPE";
+ case D3DERR_LIGHT_SET_FAILED: return "D3DERR_LIGHT_SET_FAILED";
+ case D3DERR_LIGHTHASVIEWPORT: return "D3DERR_LIGHTHASVIEWPORT";
+ case D3DERR_LIGHTNOTINTHISVIEWPORT: return "D3DERR_LIGHTNOTINTHISVIEWPORT";
+ case D3DERR_MATERIAL_CREATE_FAILED: return "D3DERR_MATERIAL_CREATE_FAILED";
+ case D3DERR_MATERIAL_DESTROY_FAILED: return "D3DERR_MATERIAL_DESTROY_FAILED";
+ case D3DERR_MATERIAL_GETDATA_FAILED: return "D3DERR_MATERIAL_GETDATA_FAILED";
+ case D3DERR_MATERIAL_SETDATA_FAILED: return "D3DERR_MATERIAL_SETDATA_FAILED";
+ case D3DERR_MATRIX_CREATE_FAILED: return "D3DERR_MATRIX_CREATE_FAILED";
+ case D3DERR_MATRIX_DESTROY_FAILED: return "D3DERR_MATRIX_DESTROY_FAILED";
+ case D3DERR_MATRIX_GETDATA_FAILED: return "D3DERR_MATRIX_GETDATA_FAILED";
+ case D3DERR_MATRIX_SETDATA_FAILED: return "D3DERR_MATRIX_SETDATA_FAILED";
+ case D3DERR_NOCURRENTVIEWPORT: return "D3DERR_NOCURRENTVIEWPORT";
+ case D3DERR_NOTINBEGIN: return "D3DERR_NOTINBEGIN";
+ case D3DERR_NOTINBEGINSTATEBLOCK: return "D3DERR_NOTINBEGINSTATEBLOCK";
+ case D3DERR_NOVIEWPORTS: return "D3DERR_NOVIEWPORTS";
+ case D3DERR_SCENE_BEGIN_FAILED: return "D3DERR_SCENE_BEGIN_FAILED";
+ case D3DERR_SCENE_END_FAILED: return "D3DERR_SCENE_END_FAILED";
+ case D3DERR_SCENE_IN_SCENE: return "D3DERR_SCENE_IN_SCENE";
+ case D3DERR_SCENE_NOT_IN_SCENE: return "D3DERR_SCENE_NOT_IN_SCENE";
+ case D3DERR_SETVIEWPORTDATA_FAILED: return "D3DERR_SETVIEWPORTDATA_FAILED";
+ case D3DERR_STENCILBUFFER_NOTPRESENT: return "D3DERR_STENCILBUFFER_NOTPRESENT";
+ case D3DERR_SURFACENOTINVIDMEM: return "D3DERR_SURFACENOTINVIDMEM";
+ case D3DERR_TEXTURE_BADSIZE: return "D3DERR_TEXTURE_BADSIZE";
+ case D3DERR_TEXTURE_CREATE_FAILED: return "D3DERR_TEXTURE_CREATE_FAILED";
+ case D3DERR_TEXTURE_DESTROY_FAILED: return "D3DERR_TEXTURE_DESTROY_FAILED";
+ case D3DERR_TEXTURE_GETSURF_FAILED: return "D3DERR_TEXTURE_GETSURF_FAILED";
+ case D3DERR_TEXTURE_LOAD_FAILED: return "D3DERR_TEXTURE_LOAD_FAILED";
+ case D3DERR_TEXTURE_LOCK_FAILED: return "D3DERR_TEXTURE_LOCK_FAILED";
+ case D3DERR_TEXTURE_LOCKED: return "D3DERR_TEXTURE_LOCKED";
+ case D3DERR_TEXTURE_NO_SUPPORT: return "D3DERR_TEXTURE_NO_SUPPORT";
+ case D3DERR_TEXTURE_NOT_LOCKED: return "D3DERR_TEXTURE_NOT_LOCKED";
+ case D3DERR_TEXTURE_SWAP_FAILED: return "D3DERR_TEXTURE_SWAP_FAILED";
+ case D3DERR_TEXTURE_UNLOCK_FAILED: return "D3DERR_TEXTURE_UNLOCK_FAILED";
+ case D3DERR_TOOMANYOPERATIONS: return "D3DERR_TOOMANYOPERATIONS";
+ case D3DERR_TOOMANYPRIMITIVES: return "D3DERR_TOOMANYPRIMITIVES";
+ case D3DERR_UNSUPPORTEDALPHAARG: return "D3DERR_UNSUPPORTEDALPHAARG";
+ case D3DERR_UNSUPPORTEDALPHAOPERATION: return "D3DERR_UNSUPPORTEDALPHAOPERATION";
+ case D3DERR_UNSUPPORTEDCOLORARG: return "D3DERR_UNSUPPORTEDCOLORARG";
+ case D3DERR_UNSUPPORTEDCOLOROPERATION: return "D3DERR_UNSUPPORTEDCOLOROPERATION";
+ case D3DERR_UNSUPPORTEDFACTORVALUE: return "D3DERR_UNSUPPORTEDFACTORVALUE";
+ case D3DERR_UNSUPPORTEDTEXTUREFILTER: return "D3DERR_UNSUPPORTEDTEXTUREFILTER";
+ case D3DERR_VBUF_CREATE_FAILED: return "D3DERR_VBUF_CREATE_FAILED";
+ case D3DERR_VERTEXBUFFERLOCKED: return "D3DERR_VERTEXBUFFERLOCKED";
+ case D3DERR_VERTEXBUFFEROPTIMIZED: return "D3DERR_VERTEXBUFFEROPTIMIZED";
+ case D3DERR_VERTEXBUFFERUNLOCKFAILED: return "D3DERR_VERTEXBUFFERUNLOCKFAILED";
+ case D3DERR_VIEWPORTDATANOTSET: return "D3DERR_VIEWPORTDATANOTSET";
+ case D3DERR_VIEWPORTHASNODEVICE: return "D3DERR_VIEWPORTHASNODEVICE";
+ case D3DERR_WRONGTEXTUREFORMAT: return "D3DERR_WRONGTEXTUREFORMAT";
+ case D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY: return "D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY";
+ case D3DERR_ZBUFF_NEEDS_VIDEOMEMORY: return "D3DERR_ZBUFF_NEEDS_VIDEOMEMORY";
+ case D3DERR_ZBUFFER_NOTPRESENT: return "D3DERR_ZBUFFER_NOTPRESENT";
+
+// case E_INVALIDINTERFACE: return "E_INVALIDINTERFACE";
+ case E_OUTOFMEMORY: return "E_OUTOFMEMORY";
+ }
+
+ char aBuf[50];
+ sprintf(aBuf,"%x",theResult);
+ return aBuf;
+}
diff --git a/osframework/source/SexyAppFramework/DirectXErrorString.h b/osframework/source/SexyAppFramework/DirectXErrorString.h
new file mode 100644
index 0000000..80b53bc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/DirectXErrorString.h
@@ -0,0 +1,11 @@
+#ifndef __SEXY_DIRECTXERRORSTRING_H__
+#define __SEXY_DIRECTXERRORSTRING_H__
+#include <string>
+#include <ddraw.h>
+
+namespace Sexy
+{
+ std::string GetDirectXErrorString(HRESULT theResult);
+} // namespace
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/EditListener.h b/osframework/source/SexyAppFramework/EditListener.h
new file mode 100644
index 0000000..b918194
--- /dev/null
+++ b/osframework/source/SexyAppFramework/EditListener.h
@@ -0,0 +1,22 @@
+#ifndef __EDITLISTENER_H__
+#define __EDITLISTENER_H__
+
+#include "Common.h"
+#include "KeyCodes.h"
+
+namespace Sexy
+{
+
+class EditListener
+{
+public:
+ virtual void EditWidgetText(int theId, const SexyString& theString) {};
+
+ virtual bool AllowKey(int theId, KeyCode theKey) { return true; }
+ virtual bool AllowChar(int theId, SexyChar theChar) { return true; }
+ virtual bool AllowText(int theId, const SexyString& theText) { return true; }
+};
+
+}
+
+#endif //__EDITLISTENER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/EditWidget.cpp b/osframework/source/SexyAppFramework/EditWidget.cpp
new file mode 100644
index 0000000..c47a987
--- /dev/null
+++ b/osframework/source/SexyAppFramework/EditWidget.cpp
@@ -0,0 +1,694 @@
+#include "EditWidget.h"
+#include "SysFont.h"
+#include "WidgetManager.h"
+#include "SexyAppBase.h"
+#include "EditListener.h"
+
+using namespace Sexy;
+
+static int gEditWidgetColors[][3] =
+{{255, 255, 255},
+{0, 0, 0},
+{0, 0, 0},
+{0, 0, 0},
+{255, 255, 255}};
+
+EditWidget::EditWidget(int theId, EditListener* theEditListener)
+{
+ mId = theId;
+ mEditListener = theEditListener;
+ mFont = NULL;
+
+ mHadDoubleClick = false;
+ mHilitePos = -1;
+ mLastModifyIdx = -1;
+ mLeftPos = 0;
+ mUndoCursor = 0;
+ mUndoHilitePos = 0;
+ mLastModifyIdx = 0;
+ mBlinkAcc = 0;
+ mCursorPos = 0;
+ mShowingCursor = false;
+ mDrawSelOverride = false;
+ mMaxChars = -1;
+ mMaxPixels = -1;
+ mPasswordChar = 0;
+ mBlinkDelay = 40;
+
+ SetColors(gEditWidgetColors, NUM_COLORS);
+}
+
+EditWidget::~EditWidget()
+{
+ delete mFont;
+ ClearWidthCheckFonts();
+
+}
+
+void EditWidget::ClearWidthCheckFonts()
+{
+ for (WidthCheckList::iterator anItr = mWidthCheckList.begin(); anItr != mWidthCheckList.end(); ++anItr)
+ delete anItr->mFont;
+
+ mWidthCheckList.clear();
+}
+
+void EditWidget::AddWidthCheckFont(Font *theFont, int theMaxPixels)
+{
+ mWidthCheckList.push_back(WidthCheck());
+ WidthCheck &aCheck = mWidthCheckList.back();
+ aCheck.mWidth = theMaxPixels;
+ aCheck.mFont = theFont->Duplicate();
+}
+
+void EditWidget::SetText(const SexyString& theText, bool leftPosToZero)
+{
+ mString = theText;
+ mCursorPos = mString.length();
+ mHilitePos = 0;
+ if (leftPosToZero)
+ mLeftPos = 0;
+ else
+ FocusCursor(true);
+
+ MarkDirty();
+}
+
+SexyString& EditWidget::GetDisplayString()
+{
+ if (mPasswordChar==0)
+ return mString;
+
+ if (mPasswordDisplayString.size()!=mString.size())
+ {
+ mPasswordDisplayString = SexyString(mString.size(), mPasswordChar);
+ //mPasswordDisplayString.resize(mString.size());
+ //for (int i=0; i<(int)mPasswordDisplayString.length(); i++)
+ // mPasswordDisplayString[i] = mPasswordChar;
+ }
+
+ return mPasswordDisplayString;
+}
+
+bool EditWidget::WantsFocus()
+{
+ return true;
+}
+
+void EditWidget::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Widget::Resize(theX, theY, theWidth, theHeight);
+
+ FocusCursor(false);
+}
+
+void EditWidget::SetFont(Font* theFont, Font* theWidthCheckFont)
+{
+ delete mFont;
+ mFont = theFont->Duplicate();
+
+ ClearWidthCheckFonts();
+ if (theWidthCheckFont != NULL)
+ AddWidthCheckFont(theWidthCheckFont);
+}
+
+void EditWidget::Draw(Graphics* g) // Already translated
+{
+ if (mFont == NULL)
+ mFont = new SysFont(mWidgetManager->mApp, "Arial Unicode MS", 10, false);
+
+ SexyString &aString = GetDisplayString();
+
+ g->SetColor(mColors[COLOR_BKG]);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ for (int i = 0; i < 2; i++)
+ {
+ Graphics* aClipG = g->Create();
+ aClipG->SetFont(mFont);
+
+ if (i == 1)
+ {
+ int aCursorX = mFont->StringWidth(aString.substr(0, mCursorPos)) - mFont->StringWidth(aString.substr(0, mLeftPos));
+ int aHiliteX = aCursorX+2;
+ if ((mHilitePos != -1) && (mCursorPos != mHilitePos))
+ aHiliteX = mFont->StringWidth(aString.substr(0, mHilitePos)) - mFont->StringWidth(aString.substr(0, mLeftPos));
+
+ if (!mShowingCursor)
+ aCursorX += 2;
+
+ aCursorX = min(max(0, aCursorX), mWidth-8);
+ aHiliteX = min(max(0, aHiliteX), mWidth-8);
+
+ aClipG->ClipRect(4 + min(aCursorX, aHiliteX), (mHeight - mFont->GetHeight())/2, abs(aHiliteX - aCursorX), mFont->GetHeight());
+ }
+ else
+ aClipG->ClipRect(4, 0, mWidth-8, mHeight);
+
+ bool hasfocus = mHasFocus || mDrawSelOverride;
+ if (i == 1 && hasfocus)
+ {
+ aClipG->SetColor(mColors[COLOR_HILITE]);
+ aClipG->FillRect(0, 0, mWidth, mHeight);
+ }
+
+ if (i == 0 || !hasfocus)
+ aClipG->SetColor(mColors[COLOR_TEXT]);
+ else
+ aClipG->SetColor(mColors[COLOR_HILITE_TEXT]);
+ aClipG->DrawString(aString.substr(mLeftPos), 4, (mHeight - mFont->GetHeight())/2 + mFont->GetAscent());
+
+ delete aClipG;
+ }
+
+ g->SetColor(mColors[COLOR_OUTLINE]);
+ g->DrawRect(0, 0, mWidth-1, mHeight-1);
+}
+
+void EditWidget::UpdateCaretPos()
+{
+ SexyAppBase *anApp = mWidgetManager->mApp;
+
+ Point aPoint = GetAbsPos();
+
+ if (aPoint.mX<10) aPoint.mX = 10;
+ else if (aPoint.mX>anApp->mWidth-10) aPoint.mX = anApp->mWidth-10;
+ if (aPoint.mY<10) aPoint.mY = 10;
+ else if (aPoint.mY>anApp->mHeight-10) aPoint.mY = anApp->mHeight-10;
+
+ SetCaretPos(aPoint.mX,aPoint.mY);
+}
+
+void EditWidget::GotFocus()
+{
+ Widget::GotFocus();
+ if (mWidgetManager && mWidgetManager->mApp->mTabletPC)
+ {
+ SexyAppBase *anApp = mWidgetManager->mApp;
+
+ CreateCaret(anApp->mHWnd,NULL,0,0);
+ UpdateCaretPos();
+ ShowCaret(anApp->mHWnd);
+ }
+
+ mShowingCursor = true;
+ mBlinkAcc = 0;
+ MarkDirty();
+}
+
+void EditWidget::LostFocus()
+{
+ Widget::LostFocus();
+
+ if (mWidgetManager && mWidgetManager->mApp->mTabletPC)
+ {
+ HideCaret(mWidgetManager->mApp->mHWnd);
+ DestroyCaret();
+ }
+
+ mShowingCursor = false;
+ MarkDirty();
+}
+
+void EditWidget::Update()
+{
+ Widget::Update();
+
+ if (mHasFocus)
+ {
+ if (mWidgetManager->mApp->mTabletPC)
+ {
+ UpdateCaretPos();
+ }
+
+ if (++mBlinkAcc > mBlinkDelay)
+ {
+ MarkDirty();
+ mBlinkAcc = 0;
+ mShowingCursor = !mShowingCursor;
+ }
+ }
+}
+
+void EditWidget::EnforceMaxPixels()
+{
+ if (mMaxPixels<=0 && mWidthCheckList.empty()) // no width checking in effect
+ return;
+
+ if (mWidthCheckList.empty())
+ {
+ while (mFont->StringWidth(mString) > mMaxPixels)
+ mString = mString.substr(0, mString.length()-1);
+
+ return;
+ }
+
+ for (WidthCheckList::iterator anItr = mWidthCheckList.begin(); anItr != mWidthCheckList.end(); ++anItr)
+ {
+ int aWidth = anItr->mWidth;
+ if (aWidth<=0)
+ {
+ aWidth = mMaxPixels;
+ if (aWidth<=0)
+ continue;
+ }
+
+ while (anItr->mFont->StringWidth(mString) > aWidth)
+ mString = mString.substr(0,mString.length()-1);
+ }
+}
+
+bool EditWidget::IsPartOfWord(SexyChar theChar)
+{
+ return (((theChar >= _S('A')) && (theChar <= _S('Z'))) ||
+ ((theChar >= _S('a')) && (theChar <= _S('z'))) ||
+ ((theChar >= _S('0')) && (theChar <= _S('9'))) ||
+ (((unsigned int)theChar >= (unsigned int)(L'À')) && ((unsigned int)theChar <= (unsigned int)(L'ÿ'))) ||
+ (theChar == _S('_')));
+}
+
+void EditWidget::ProcessKey(KeyCode theKey, SexyChar theChar)
+{
+ bool shiftDown = mWidgetManager->mKeyDown[KEYCODE_SHIFT];
+ bool controlDown = mWidgetManager->mKeyDown[KEYCODE_CONTROL];
+
+ if ((theKey == KEYCODE_SHIFT) || (theKey == KEYCODE_CONTROL))
+ return;
+
+ bool bigChange = false;
+ bool removeHilite = !shiftDown;
+
+ if (shiftDown && (mHilitePos == -1))
+ mHilitePos = mCursorPos;
+
+ SexyString anOldString = mString;
+ int anOldCursorPos = mCursorPos;
+ int anOldHilitePos = mHilitePos;
+ if ((theChar == 3) || (theChar == 24))
+ {
+ // Copy selection
+
+ if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
+ {
+ if (mCursorPos < mHilitePos)
+ mWidgetManager->mApp->CopyToClipboard(SexyStringToString(GetDisplayString().substr(mCursorPos, mHilitePos)));
+ else
+ mWidgetManager->mApp->CopyToClipboard(SexyStringToString(GetDisplayString().substr(mHilitePos, mCursorPos)));
+
+ if (theChar == 3)
+ {
+ removeHilite = false;
+ }
+ else
+ {
+ mString = mString.substr(0, min(mCursorPos, mHilitePos)) + mString.substr(max(mCursorPos, mHilitePos));
+ mCursorPos = min(mCursorPos, mHilitePos);
+ mHilitePos = -1;
+ bigChange = true;
+ }
+ }
+ }
+ else if (theChar == 22)
+ {
+ // Paste selection
+
+ SexyString aBaseString = StringToSexyString(mWidgetManager->mApp->GetClipboard());
+
+ if (aBaseString.length() > 0)
+ {
+ SexyString aString;
+
+ for (ulong i = 0; i < aBaseString.length(); i++)
+ {
+ if ((aBaseString[i] == '\r') || (aBaseString[i] == '\n'))
+ break;
+
+ if (mFont->CharWidth(aBaseString[i]) != 0 && mEditListener->AllowChar(mId, aBaseString[i]))
+ aString += aBaseString[i];
+ }
+
+ if (mHilitePos == -1)
+ {
+ // Insert string where cursor is
+ mString = mString.substr(0, mCursorPos) + aString + mString.substr(mCursorPos);
+ }
+ else
+ {
+ // Replace selection with new string
+ mString = mString.substr(0, min(mCursorPos, mHilitePos)) + aString + mString.substr(max(mCursorPos, mHilitePos));
+ mCursorPos = min(mCursorPos, mHilitePos);
+ mHilitePos = -1;
+ }
+
+ mCursorPos += aString.length();
+
+ bigChange = true;
+ }
+ }
+ else if (theChar == 26)
+ {
+ // Undo
+
+ mLastModifyIdx = -1;
+
+ SexyString aSwapString = mString;
+ int aSwapCursorPos = mCursorPos;
+ int aSwapHilitePos = mHilitePos;
+
+ mString = mUndoString;
+ mCursorPos = mUndoCursor;
+ mHilitePos = mUndoHilitePos;
+
+ mUndoString = aSwapString;
+ mUndoCursor = aSwapCursorPos;
+ mUndoHilitePos = aSwapHilitePos;
+
+ removeHilite = false;
+ }
+ else if (theKey == KEYCODE_LEFT)
+ {
+ if (controlDown)
+ {
+ // Get to a word
+ while ((mCursorPos > 0) && (!IsPartOfWord(mString[mCursorPos-1])))
+ mCursorPos--;
+
+ // Go beyond the word
+ while ((mCursorPos > 0) && (IsPartOfWord(mString[mCursorPos-1])))
+ mCursorPos--;
+ }
+ else if (shiftDown || (mHilitePos == -1))
+ mCursorPos--;
+ else
+ mCursorPos = min(mCursorPos, mHilitePos);
+ }
+ else if (theKey == KEYCODE_RIGHT)
+ {
+ if (controlDown)
+ {
+ // Get to whitespace
+ while ((mCursorPos < (int) mString.length()-1) && (IsPartOfWord(mString[mCursorPos+1])))
+ mCursorPos++;
+
+ // Go beyond the whitespace
+ while ((mCursorPos < (int) mString.length()-1) && (!IsPartOfWord(mString[mCursorPos+1])))
+ mCursorPos++;
+ }
+ if (shiftDown || (mHilitePos == -1))
+ mCursorPos++;
+ else
+ mCursorPos = max(mCursorPos, mHilitePos);
+ }
+ else if (theKey == KEYCODE_BACK)
+ {
+ if (mString.length() > 0)
+ {
+ if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
+ {
+ // Delete selection
+ mString = mString.substr(0, min(mCursorPos, mHilitePos)) + mString.substr(max(mCursorPos, mHilitePos));
+ mCursorPos = min(mCursorPos, mHilitePos);
+ mHilitePos = -1;
+
+ bigChange = true;
+ }
+ else
+ {
+ // Delete char behind cursor
+ if (mCursorPos > 0)
+ mString = mString.substr(0, mCursorPos-1) + mString.substr(mCursorPos);
+ else
+ mString = mString.substr(mCursorPos);
+ mCursorPos--;
+ mHilitePos = -1;
+
+ if (mCursorPos != mLastModifyIdx)
+ bigChange = true;
+ mLastModifyIdx = mCursorPos-1;
+ }
+ }
+ }
+ else if (theKey == KEYCODE_DELETE)
+ {
+ if (mString.length() > 0)
+ {
+ if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
+ {
+ // Delete selection
+ mString = mString.substr(0, min(mCursorPos, mHilitePos)) + mString.substr(max(mCursorPos, mHilitePos));
+ mCursorPos = min(mCursorPos, mHilitePos);
+ mHilitePos = -1;
+
+ bigChange = true;
+ }
+ else
+ {
+ // Delete char in front of cursor
+ if (mCursorPos < (int) mString.length())
+ mString = mString.substr(0, mCursorPos) + mString.substr(mCursorPos+1);
+
+ if (mCursorPos != mLastModifyIdx)
+ bigChange = true;
+ mLastModifyIdx = mCursorPos;
+ }
+ }
+ }
+ else if (theKey == KEYCODE_HOME)
+ {
+ mCursorPos = 0;
+ }
+ else if (theKey == KEYCODE_END)
+ {
+ mCursorPos = mString.length();
+ }
+ else if (theKey == KEYCODE_RETURN)
+ {
+ mEditListener->EditWidgetText(mId, mString);
+ }
+ else
+ {
+ SexyString aString = SexyString(1, theChar);
+ unsigned int uTheChar = (unsigned int)theChar;
+ unsigned int range = 127;
+ if (gSexyAppBase->mbAllowExtendedChars)
+ {
+ range = 255;
+ }
+
+ if ((uTheChar >= 32) && (uTheChar <= range) && (mFont->StringWidth(aString) > 0) && mEditListener->AllowChar(mId, theChar))
+ {
+ if ((mHilitePos != -1) && (mHilitePos != mCursorPos))
+ {
+ // Replace selection with new character
+ mString = mString.substr(0, min(mCursorPos, mHilitePos)) + SexyString(1, theChar) + mString.substr(max(mCursorPos, mHilitePos));
+ mCursorPos = min(mCursorPos, mHilitePos);
+ mHilitePos = -1;
+
+ bigChange = true;
+ }
+ else
+ {
+ // Insert character where cursor is
+ mString = mString.substr(0, mCursorPos) + SexyString(1, theChar) + mString.substr(mCursorPos);
+
+ if (mCursorPos != mLastModifyIdx+1)
+ bigChange = true;
+ mLastModifyIdx = mCursorPos;
+ mHilitePos = -1;
+ }
+
+ mCursorPos++;
+ FocusCursor(false);
+ }
+ else
+ removeHilite = false;
+ }
+
+ if ((mMaxChars != -1) && ((int) mString.length() > mMaxChars))
+ mString = mString.substr(0, mMaxChars);
+
+ EnforceMaxPixels();
+
+ if (mCursorPos < 0)
+ mCursorPos = 0;
+ else if (mCursorPos > (int) mString.length())
+ mCursorPos = mString.length();
+
+ if (anOldCursorPos != mCursorPos)
+ {
+ mBlinkAcc = 0;
+ mShowingCursor = true;
+ }
+
+ FocusCursor(true);
+
+ if (removeHilite || mHilitePos==mCursorPos)
+ mHilitePos = -1;
+
+ if (!mEditListener->AllowText(mId, mString))
+ {
+ mString = anOldString;
+ mCursorPos = anOldCursorPos;
+ mHilitePos = anOldHilitePos;
+ }
+ else if (bigChange)
+ {
+ mUndoString = anOldString;
+ mUndoCursor = anOldCursorPos;
+ mUndoHilitePos = anOldHilitePos;
+ }
+
+ MarkDirty();
+}
+
+void EditWidget::KeyDown(KeyCode theKey)
+{
+ if (((theKey < 'A') || (theKey >= 'Z')) && mEditListener->AllowKey(mId, theKey))
+ ProcessKey(theKey, 0);
+
+ Widget::KeyDown(theKey);
+}
+
+void EditWidget::KeyChar(SexyChar theChar)
+{
+// if (mEditListener->AllowChar(mId, theChar))
+ ProcessKey(KEYCODE_UNKNOWN, theChar);
+
+ Widget::KeyChar(theChar);
+}
+
+int EditWidget::GetCharAt(int x, int y)
+{
+ int aPos = 0;
+
+ SexyString &aString = GetDisplayString();
+
+ for (int i = mLeftPos; i < (int) aString.length(); i++)
+ {
+ SexyString aLoSubStr = aString.substr(mLeftPos, i-mLeftPos);
+ SexyString aHiSubStr = aString.substr(mLeftPos, i-mLeftPos+1);
+
+ int aLoLen = mFont->StringWidth(aLoSubStr);
+ int aHiLen = mFont->StringWidth(aHiSubStr);
+ if (x >= (aLoLen+aHiLen)/2 + 5)
+ aPos = i+1;
+ }
+
+ return aPos;
+}
+
+void EditWidget::FocusCursor(bool bigJump)
+{
+ while (mCursorPos < mLeftPos)
+ {
+ if (bigJump)
+ mLeftPos = max(0, mLeftPos-10);
+ else
+ mLeftPos = max(0, mLeftPos-1);
+ MarkDirty();
+ }
+
+ if (mFont != NULL)
+ {
+ SexyString &aString = GetDisplayString();
+ while ((mWidth-8 > 0) && (mFont->StringWidth(aString.substr(0, mCursorPos)) - mFont->StringWidth(aString.substr(0, mLeftPos)) >= mWidth-8))
+ {
+ if (bigJump)
+ mLeftPos = min(mLeftPos + 10, (int) mString.length()-1);
+ else
+ mLeftPos = min(mLeftPos + 1, (int) mString.length()-1);
+
+ MarkDirty();
+ }
+ }
+}
+
+void EditWidget::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ Widget::MouseDown(x, y, theBtnNum, theClickCount);
+
+ mHilitePos = -1;
+ mCursorPos = GetCharAt(x, y);
+
+ if (theClickCount > 1)
+ {
+ mHadDoubleClick = true;
+ HiliteWord();
+ }
+
+ MarkDirty();
+
+ FocusCursor(false);
+}
+
+void EditWidget::MouseUp(int x, int y, int theBtnNum, int theClickCount)
+{
+ Widget::MouseUp(x,y,theBtnNum,theClickCount);
+ if (mHilitePos==mCursorPos)
+ mHilitePos = -1;
+
+ if (mHadDoubleClick)
+ {
+ mHilitePos = -1;
+ mCursorPos = GetCharAt(x, y);
+
+ mHadDoubleClick = false;
+ HiliteWord();
+ }
+
+ MarkDirty();
+}
+
+void EditWidget::HiliteWord()
+{
+ SexyString &aString = GetDisplayString();
+
+ if (mCursorPos < (int) aString.length())
+ {
+ // Find first space before word
+ mHilitePos = mCursorPos;
+ while ((mHilitePos > 0) && (IsPartOfWord(aString[mHilitePos-1])))
+ mHilitePos--;
+
+ // Find first space after word
+ while ((mCursorPos < (int) aString.length()-1) && (IsPartOfWord(aString[mCursorPos+1])))
+ mCursorPos++;
+ if (mCursorPos < (int) aString.length())
+ mCursorPos++;
+ }
+}
+
+void EditWidget::MouseDrag(int x, int y)
+{
+ Widget::MouseDrag(x, y);
+
+ if (mHilitePos == -1)
+ mHilitePos = mCursorPos;
+
+ mCursorPos = GetCharAt(x, y);
+ MarkDirty();
+
+ FocusCursor(false);
+}
+
+void EditWidget::MouseEnter()
+{
+ Widget::MouseEnter();
+
+ mWidgetManager->mApp->SetCursor(CURSOR_TEXT);
+}
+
+void EditWidget::MouseLeave()
+{
+ Widget::MouseLeave();
+
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+}
+
+void EditWidget::MarkDirty()
+{
+ if (mColors[COLOR_BKG].mAlpha != 255)
+ Widget::MarkDirtyFull();
+ else
+ Widget::MarkDirty();
+}
diff --git a/osframework/source/SexyAppFramework/EditWidget.h b/osframework/source/SexyAppFramework/EditWidget.h
new file mode 100644
index 0000000..45c70e2
--- /dev/null
+++ b/osframework/source/SexyAppFramework/EditWidget.h
@@ -0,0 +1,102 @@
+#ifndef __EDITWIDGET_H__
+#define __EDITWIDGET_H__
+
+#include "Widget.h"
+
+namespace Sexy
+{
+
+class Font;
+class EditListener;
+
+class EditWidget : public Widget
+{
+public:
+ enum
+ {
+ COLOR_BKG,
+ COLOR_OUTLINE,
+ COLOR_TEXT,
+ COLOR_HILITE,
+ COLOR_HILITE_TEXT,
+ NUM_COLORS
+ };
+
+ int mId;
+ SexyString mString;
+ SexyString mPasswordDisplayString;
+ Font* mFont;
+
+ struct WidthCheck
+ {
+ Font *mFont;
+ int mWidth;
+ };
+ typedef std::list<WidthCheck> WidthCheckList;
+ WidthCheckList mWidthCheckList;
+
+ EditListener* mEditListener;
+ bool mShowingCursor;
+ bool mDrawSelOverride; // set this to true to draw selected text even when not in focus
+ bool mHadDoubleClick; // Used to fix a bug with double clicking to hilite a word after the widget manager started calling mouse drag before mouse down/up events
+ int mCursorPos;
+ int mHilitePos;
+ int mBlinkAcc;
+ int mBlinkDelay;
+ int mLeftPos;
+ int mMaxChars;
+ int mMaxPixels;
+ SexyChar mPasswordChar;
+
+ SexyString mUndoString;
+ int mUndoCursor;
+ int mUndoHilitePos;
+ int mLastModifyIdx;
+
+
+protected:
+ virtual void ProcessKey(KeyCode theKey, SexyChar theChar);
+ SexyString& GetDisplayString();
+ virtual void HiliteWord();
+ void UpdateCaretPos();
+
+public:
+ virtual void SetFont(Font* theFont, Font* theWidthCheckFont = NULL);
+ virtual void SetText(const SexyString& theText, bool leftPosToZero = true);
+ virtual bool IsPartOfWord(SexyChar theChar);
+ virtual int GetCharAt(int x, int y);
+
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+ virtual void Draw(Graphics* g); // Already translated;
+
+ virtual void Update();
+ virtual void MarkDirty();
+
+ virtual bool WantsFocus();
+ virtual void GotFocus();
+ virtual void LostFocus();
+ virtual void FocusCursor(bool bigJump);
+
+ virtual void KeyDown(KeyCode theKey);
+ virtual void KeyChar(SexyChar theChar);
+
+ virtual void MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseUp(int x, int y) { Widget::MouseUp(x, y); }
+ virtual void MouseUp(int x, int y, int theClickCount) { Widget::MouseUp(x, y, theClickCount); }
+ virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+ virtual void MouseEnter();
+ virtual void MouseLeave();
+ void ClearWidthCheckFonts();
+ void AddWidthCheckFont(Font *theFont, int theMaxPixels = -1); // defaults to mMaxPixels
+ void EnforceMaxPixels();
+
+public:
+ EditWidget(int theId, EditListener* theEditListener);
+ virtual ~EditWidget();
+};
+
+}
+
+#endif //__EDITWIDGET_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/FModLoader.cpp b/osframework/source/SexyAppFramework/FModLoader.cpp
new file mode 100644
index 0000000..165fd21
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModLoader.cpp
@@ -0,0 +1,287 @@
+#include "FModLoader.h"
+#include <stdlib.h>
+
+using namespace Sexy;
+
+FMOD_INSTANCE* Sexy::gFMod = NULL;
+static long gFModLoadCount = 0;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void CheckFModFunction(unsigned int theFunc, const char *theName)
+{
+ if (theFunc==0)
+ {
+ char aBuf[1024];
+ sprintf(aBuf,"%s function not found in fmod.dll",theName);
+ MessageBoxA(NULL,aBuf,"Error",MB_OK | MB_ICONERROR);
+ exit(0);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+FMOD_INSTANCE::FMOD_INSTANCE(const char *dllName)
+{
+ mModule = LoadLibrary(dllName);
+ if (!mModule)
+ return;
+
+ #define GETPROC(_x, _y) \
+ { \
+ CheckFModFunction(*((unsigned int *)&_x) = (unsigned int)GetProcAddress(mModule, _y),#_y); \
+ }
+
+ GETPROC(FSOUND_SetBufferSize, "_FSOUND_SetBufferSize@4");
+ GETPROC(FSOUND_SetHWND, "_FSOUND_SetHWND@4");
+ GETPROC(FSOUND_Init, "_FSOUND_Init@12");
+ GETPROC(FSOUND_Close, "_FSOUND_Close@0");
+
+ GETPROC(FSOUND_Sample_Load, "_FSOUND_Sample_Load@16");
+ GETPROC(FSOUND_Sample_Alloc, "_FSOUND_Sample_Alloc@28");
+ GETPROC(FSOUND_Sample_Free, "_FSOUND_Sample_Free@4");
+ GETPROC(FSOUND_Sample_Lock, "_FSOUND_Sample_Lock@28");
+ GETPROC(FSOUND_Sample_Unlock, "_FSOUND_Sample_Unlock@20");
+ GETPROC(FSOUND_Sample_SetLoopPoints, "_FSOUND_Sample_SetLoopPoints@12");
+ GETPROC(FSOUND_Sample_GetLength, "_FSOUND_Sample_GetLength@4");
+ GETPROC(FSOUND_Sample_GetDefaults, "_FSOUND_Sample_GetDefaults@20");
+ GETPROC(FSOUND_Sample_GetMode, "_FSOUND_Sample_GetMode@4");
+
+ GETPROC(FSOUND_PlaySound, "_FSOUND_PlaySound@8");
+ GETPROC(FSOUND_StopSound, "_FSOUND_StopSound@4");
+ GETPROC(FSOUND_SetVolume, "_FSOUND_SetVolume@8");
+ GETPROC(FSOUND_SetPaused, "_FSOUND_SetPaused@8");
+ GETPROC(FSOUND_SetLoopMode, "_FSOUND_SetLoopMode@8");
+ GETPROC(FSOUND_IsPlaying, "_FSOUND_IsPlaying@4");
+
+ GETPROC(FSOUND_Stream_OpenFile, "_FSOUND_Stream_OpenFile@12");
+ GETPROC(FSOUND_Stream_Close, "_FSOUND_Stream_Close@4");
+ GETPROC(FSOUND_Stream_Play, "_FSOUND_Stream_Play@8");
+
+ GETPROC(FMUSIC_LoadSong, "_FMUSIC_LoadSong@4");
+ GETPROC(FMUSIC_PlaySong, "_FMUSIC_PlaySong@4");
+ GETPROC(FMUSIC_StopSong, "_FMUSIC_StopSong@4");
+ GETPROC(FMUSIC_SetLooping, "_FMUSIC_SetLooping@8");
+ GETPROC(FMUSIC_SetOrder, "_FMUSIC_SetOrder@8");
+ GETPROC(FMUSIC_SetPaused, "_FMUSIC_SetPaused@8");
+ GETPROC(FMUSIC_SetMasterVolume, "_FMUSIC_SetMasterVolume@8");
+ GETPROC(FMUSIC_IsPlaying, "_FMUSIC_IsPlaying@4");
+
+/// GETPROC(FSOUND_SetOutput, "_FSOUND_SetOutput@4");
+// GETPROC(FSOUND_SetDriver, "_FSOUND_SetDriver@4");
+// GETPROC(FSOUND_SetMixer, "_FSOUND_SetMixer@4");
+// GETPROC(FSOUND_SetMinHardwareChannels, "_FSOUND_SetMinHardwareChannels@4");
+// GETPROC(FSOUND_SetMaxHardwareChannels, "_FSOUND_SetMaxHardwareChannels@4");
+// GETPROC(FSOUND_SetMemorySystem, "_FSOUND_SetMemorySystem@20");
+// GETPROC(FSOUND_SetSFXMasterVolume, "_FSOUND_SetSFXMasterVolume@4");
+// GETPROC(FSOUND_SetPanSeperation, "_FSOUND_SetPanSeperation@4");
+// GETPROC(FSOUND_SetSpeakerMode, "_FSOUND_SetSpeakerMode@4");
+// GETPROC(FSOUND_GetError, "_FSOUND_GetError@0");
+// GETPROC(FSOUND_GetVersion, "_FSOUND_GetVersion@0");
+// GETPROC(FSOUND_GetOutput, "_FSOUND_GetOutput@0");
+// GETPROC(FSOUND_GetOutputHandle, "_FSOUND_GetOutputHandle@0");
+// GETPROC(FSOUND_GetDriver, "_FSOUND_GetDriver@0");
+// GETPROC(FSOUND_GetMixer, "_FSOUND_GetMixer@0");
+// GETPROC(FSOUND_GetNumDrivers, "_FSOUND_GetNumDrivers@0");
+// GETPROC(FSOUND_GetDriverName, "_FSOUND_GetDriverName@4");
+// GETPROC(FSOUND_GetDriverCaps, "_FSOUND_GetDriverCaps@8");
+// GETPROC(FSOUND_GetOutputRate, "_FSOUND_GetOutputRate@0");
+// GETPROC(FSOUND_GetMaxChannels, "_FSOUND_GetMaxChannels@0");
+// GETPROC(FSOUND_GetMaxSamples, "_FSOUND_GetMaxSamples@0");
+// GETPROC(FSOUND_GetSFXMasterVolume, "_FSOUND_GetSFXMasterVolume@0");
+// GETPROC(FSOUND_GetNumHardwareChannels, "_FSOUND_GetNumHardwareChannels@0");
+// GETPROC(FSOUND_GetChannelsPlaying, "_FSOUND_GetChannelsPlaying@0");
+// GETPROC(FSOUND_GetCPUUsage, "_FSOUND_GetCPUUsage@0");
+// GETPROC(FSOUND_GetMemoryStats, "_FSOUND_GetMemoryStats@8");
+// GETPROC(FSOUND_Sample_Upload, "_FSOUND_Sample_Upload@12");
+// GETPROC(FSOUND_Sample_SetMode, "_FSOUND_Sample_SetMode@8");
+// GETPROC(FSOUND_Sample_SetDefaults, "_FSOUND_Sample_SetDefaults@20");
+// GETPROC(FSOUND_Sample_SetMinMaxDistance, "_FSOUND_Sample_SetMinMaxDistance@12");
+// GETPROC(FSOUND_Sample_SetMaxPlaybacks, "_FSOUND_Sample_SetMaxPlaybacks@8");
+// GETPROC(FSOUND_Sample_Get, "_FSOUND_Sample_Get@4");
+// GETPROC(FSOUND_Sample_GetName, "_FSOUND_Sample_GetName@4");
+// GETPROC(FSOUND_Sample_GetLoopPoints, "_FSOUND_Sample_GetLoopPoints@12");
+// GETPROC(FSOUND_PlaySoundEx, "_FSOUND_PlaySoundEx@16");
+// GETPROC(FSOUND_SetFrequency, "_FSOUND_SetFrequency@8");
+// GETPROC(FSOUND_SetVolumeAbsolute, "_FSOUND_SetVolumeAbsolute@8");
+// GETPROC(FSOUND_SetPan, "_FSOUND_SetPan@8");
+// GETPROC(FSOUND_SetSurround, "_FSOUND_SetSurround@8");
+// GETPROC(FSOUND_SetMute, "_FSOUND_SetMute@8");
+// GETPROC(FSOUND_SetPriority, "_FSOUND_SetPriority@8");
+// GETPROC(FSOUND_SetReserved, "_FSOUND_SetReserved@8");
+// GETPROC(FSOUND_GetFrequency, "_FSOUND_GetFrequency@4");
+// GETPROC(FSOUND_GetVolume, "_FSOUND_GetVolume@4");
+// GETPROC(FSOUND_GetPan, "_FSOUND_GetPan@4");
+// GETPROC(FSOUND_GetSurround, "_FSOUND_GetSurround@4");
+// GETPROC(FSOUND_GetMute, "_FSOUND_GetMute@4");
+// GETPROC(FSOUND_GetPriority, "_FSOUND_GetPriority@4");
+// GETPROC(FSOUND_GetReserved, "_FSOUND_GetReserved@4");
+// GETPROC(FSOUND_GetPaused, "_FSOUND_GetPaused@4");
+// GETPROC(FSOUND_GetLoopMode, "_FSOUND_GetLoopMode@4");
+// GETPROC(FSOUND_GetCurrentPosition, "_FSOUND_GetCurrentPosition@4");
+// GETPROC(FSOUND_SetCurrentPosition, "_FSOUND_SetCurrentPosition@8");
+// GETPROC(FSOUND_GetCurrentSample, "_FSOUND_GetCurrentSample@4");
+// GETPROC(FSOUND_GetCurrentLevels, "_FSOUND_GetCurrentLevels@12");
+// GETPROC(FSOUND_FX_Enable, "_FSOUND_FX_Enable@8");
+// GETPROC(FSOUND_FX_Disable, "_FSOUND_FX_Disable@4");
+// GETPROC(FSOUND_FX_SetChorus, "_FSOUND_FX_SetChorus@32");
+// GETPROC(FSOUND_FX_SetCompressor, "_FSOUND_FX_SetCompressor@28");
+// GETPROC(FSOUND_FX_SetDistortion, "_FSOUND_FX_SetDistortion@24");
+// GETPROC(FSOUND_FX_SetEcho, "_FSOUND_FX_SetEcho@24");
+// GETPROC(FSOUND_FX_SetFlanger, "_FSOUND_FX_SetFlanger@32");
+// GETPROC(FSOUND_FX_SetGargle, "_FSOUND_FX_SetGargle@12");
+// GETPROC(FSOUND_FX_SetI3DL2Reverb, "_FSOUND_FX_SetI3DL2Reverb@52");
+// GETPROC(FSOUND_FX_SetParamEQ, "_FSOUND_FX_SetParamEQ@16");
+// GETPROC(FSOUND_FX_SetWavesReverb, "_FSOUND_FX_SetWavesReverb@20");
+// GETPROC(FSOUND_Update, "_FSOUND_Update@0");
+// GETPROC(FSOUND_3D_SetAttributes, "_FSOUND_3D_SetAttributes@12");
+// GETPROC(FSOUND_3D_GetAttributes, "_FSOUND_3D_GetAttributes@12");
+// GETPROC(FSOUND_3D_Listener_SetCurrent, "_FSOUND_3D_Listener_SetCurrent@8");
+// GETPROC(FSOUND_3D_Listener_SetAttributes, "_FSOUND_3D_Listener_SetAttributes@32");
+// GETPROC(FSOUND_3D_Listener_GetAttributes, "_FSOUND_3D_Listener_GetAttributes@32");
+// GETPROC(FSOUND_3D_SetDopplerFactor, "_FSOUND_3D_SetDopplerFactor@4");
+// GETPROC(FSOUND_3D_SetDistanceFactor, "_FSOUND_3D_SetDistanceFactor@4");
+// GETPROC(FSOUND_3D_SetRolloffFactor, "_FSOUND_3D_SetRolloffFactor@4");
+// GETPROC(FSOUND_Stream_Create, "_FSOUND_Stream_Create@20");
+// GETPROC(FSOUND_Stream_PlayEx, "_FSOUND_Stream_PlayEx@16");
+// GETPROC(FSOUND_Stream_Stop, "_FSOUND_Stream_Stop@4");
+// GETPROC(FSOUND_Stream_SetEndCallback, "_FSOUND_Stream_SetEndCallback@12");
+// GETPROC(FSOUND_Stream_SetSynchCallback, "_FSOUND_Stream_SetSynchCallback@12");
+// GETPROC(FSOUND_Stream_GetSample, "_FSOUND_Stream_GetSample@4");
+// GETPROC(FSOUND_Stream_CreateDSP, "_FSOUND_Stream_CreateDSP@16");
+// GETPROC(FSOUND_Stream_SetBufferSize, "_FSOUND_Stream_SetBufferSize@4");
+// GETPROC(FSOUND_Stream_SetPosition, "_FSOUND_Stream_SetPosition@8");
+// GETPROC(FSOUND_Stream_GetPosition, "_FSOUND_Stream_GetPosition@4");
+// GETPROC(FSOUND_Stream_SetTime, "_FSOUND_Stream_SetTime@8");
+// GETPROC(FSOUND_Stream_GetTime, "_FSOUND_Stream_GetTime@4");
+// GETPROC(FSOUND_Stream_GetLength, "_FSOUND_Stream_GetLength@4");
+// GETPROC(FSOUND_Stream_GetLengthMs, "_FSOUND_Stream_GetLengthMs@4");
+// GETPROC(FSOUND_Stream_SetMode, "_FSOUND_Stream_SetMode@8");
+// GETPROC(FSOUND_Stream_GetMode, "_FSOUND_Stream_GetMode@4");
+// GETPROC(FSOUND_Stream_SetSubStream, "_FSOUND_Stream_SetSubStream@8");
+// GETPROC(FSOUND_Stream_GetNumSubStreams, "_FSOUND_Stream_GetNumSubStreams@4");
+// GETPROC(FSOUND_Stream_SetSubStreamSentence, "_FSOUND_Stream_SetSubStreamSentence@12");
+// GETPROC(FSOUND_Stream_SetLoopPoints, "_FSOUND_Stream_SetLoopPoints@12");
+// GETPROC(FSOUND_Stream_AddSynchPoint, "_FSOUND_Stream_AddSynchPoint@12");
+// GETPROC(FSOUND_Stream_DeleteSynchPoint, "_FSOUND_Stream_DeleteSynchPoint@8");
+// GETPROC(FSOUND_Stream_GetNumSynchPoints, "_FSOUND_Stream_GetNumSynchPoints@4");
+// GETPROC(FSOUND_Stream_GetOpenState, "_FSOUND_Stream_GetOpenState@4");
+// GETPROC(FSOUND_CD_Play, "_FSOUND_CD_Play@8");
+// GETPROC(FSOUND_CD_SetPlayMode, "_FSOUND_CD_SetPlayMode@8");
+// GETPROC(FSOUND_CD_Stop, "_FSOUND_CD_Stop@4");
+// GETPROC(FSOUND_CD_SetPaused, "_FSOUND_CD_SetPaused@8");
+// GETPROC(FSOUND_CD_SetVolume, "_FSOUND_CD_SetVolume@8");
+// GETPROC(FSOUND_CD_SetTrackTime, "_FSOUND_CD_SetTrackTime@8");
+// GETPROC(FSOUND_CD_Eject, "_FSOUND_CD_Eject@4");
+// GETPROC(FSOUND_CD_GetPaused, "_FSOUND_CD_GetPaused@4");
+// GETPROC(FSOUND_CD_GetTrack, "_FSOUND_CD_GetTrack@4");
+// GETPROC(FSOUND_CD_GetNumTracks, "_FSOUND_CD_GetNumTracks@4");
+// GETPROC(FSOUND_CD_GetVolume, "_FSOUND_CD_GetVolume@4");
+// GETPROC(FSOUND_CD_GetTrackLength, "_FSOUND_CD_GetTrackLength@8");
+// GETPROC(FSOUND_CD_GetTrackTime, "_FSOUND_CD_GetTrackTime@4");
+// GETPROC(FSOUND_DSP_Create, "_FSOUND_DSP_Create@12");
+// GETPROC(FSOUND_DSP_Free, "_FSOUND_DSP_Free@4");
+// GETPROC(FSOUND_DSP_SetPriority, "_FSOUND_DSP_SetPriority@8");
+// GETPROC(FSOUND_DSP_GetPriority, "_FSOUND_DSP_GetPriority@4");
+// GETPROC(FSOUND_DSP_SetActive, "_FSOUND_DSP_SetActive@8");
+// GETPROC(FSOUND_DSP_GetActive, "_FSOUND_DSP_GetActive@4");
+// GETPROC(FSOUND_DSP_GetClearUnit, "_FSOUND_DSP_GetClearUnit@0");
+// GETPROC(FSOUND_DSP_GetSFXUnit, "_FSOUND_DSP_GetSFXUnit@0");
+// GETPROC(FSOUND_DSP_GetMusicUnit, "_FSOUND_DSP_GetMusicUnit@0");
+// GETPROC(FSOUND_DSP_GetClipAndCopyUnit, "_FSOUND_DSP_GetClipAndCopyUnit@0");
+// GETPROC(FSOUND_DSP_GetFFTUnit, "_FSOUND_DSP_GetFFTUnit@0");
+// GETPROC(FSOUND_DSP_MixBuffers, "_FSOUND_DSP_MixBuffers@28");
+// GETPROC(FSOUND_DSP_ClearMixBuffer, "_FSOUND_DSP_ClearMixBuffer@0");
+// GETPROC(FSOUND_DSP_GetBufferLength, "_FSOUND_DSP_GetBufferLength@0");
+// GETPROC(FSOUND_DSP_GetBufferLengthTotal, "_FSOUND_DSP_GetBufferLengthTotal@0");
+// GETPROC(FSOUND_DSP_GetSpectrum, "_FSOUND_DSP_GetSpectrum@0");
+// GETPROC(FSOUND_Reverb_SetProperties, "_FSOUND_Reverb_SetProperties@4");
+// GETPROC(FSOUND_Reverb_GetProperties, "_FSOUND_Reverb_GetProperties@4");
+// GETPROC(FSOUND_Reverb_SetChannelProperties, "_FSOUND_Reverb_SetChannelProperties@8");
+// GETPROC(FSOUND_Reverb_GetChannelProperties, "_FSOUND_Reverb_GetChannelProperties@8");
+// GETPROC(FSOUND_Record_SetDriver, "_FSOUND_Record_SetDriver@4");
+// GETPROC(FSOUND_Record_GetNumDrivers, "_FSOUND_Record_GetNumDrivers@0");
+// GETPROC(FSOUND_Record_GetDriverName, "_FSOUND_Record_GetDriverName@4");
+// GETPROC(FSOUND_Record_GetDriver, "_FSOUND_Record_GetDriver@0");
+// GETPROC(FSOUND_Record_StartSample, "_FSOUND_Record_StartSample@8");
+// GETPROC(FSOUND_Record_Stop, "_FSOUND_Record_Stop@0");
+// GETPROC(FSOUND_Record_GetPosition, "_FSOUND_Record_GetPosition@0");
+// GETPROC(FSOUND_File_SetCallbacks, "_FSOUND_File_SetCallbacks@20");
+// GETPROC(FMUSIC_LoadSongEx, "_FMUSIC_LoadSongEx@20");
+// GETPROC(FMUSIC_FreeSong, "_FMUSIC_FreeSong@4");
+// GETPROC(FMUSIC_StopAllSongs, "_FMUSIC_StopAllSongs@0");
+// GETPROC(FMUSIC_SetZxxCallback, "_FMUSIC_SetZxxCallback@8");
+// GETPROC(FMUSIC_SetRowCallback, "_FMUSIC_SetRowCallback@12");
+// GETPROC(FMUSIC_SetOrderCallback, "_FMUSIC_SetOrderCallback@12");
+// GETPROC(FMUSIC_SetInstCallback, "_FMUSIC_SetInstCallback@12");
+// GETPROC(FMUSIC_SetSample, "_FMUSIC_SetSample@12");
+// GETPROC(FMUSIC_SetUserData, "_FMUSIC_SetUserData@8");
+// GETPROC(FMUSIC_OptimizeChannels, "_FMUSIC_OptimizeChannels@12");
+// GETPROC(FMUSIC_SetReverb, "_FMUSIC_SetReverb@4");
+
+// GETPROC(FMUSIC_SetMasterSpeed, "_FMUSIC_SetMasterSpeed@8");
+// GETPROC(FMUSIC_SetPanSeperation, "_FMUSIC_SetPanSeperation@8");
+// GETPROC(FMUSIC_GetName, "_FMUSIC_GetName@4");
+// GETPROC(FMUSIC_GetType, "_FMUSIC_GetType@4");
+// GETPROC(FMUSIC_GetNumOrders, "_FMUSIC_GetNumOrders@4");
+// GETPROC(FMUSIC_GetNumPatterns, "_FMUSIC_GetNumPatterns@4");
+// GETPROC(FMUSIC_GetNumInstruments, "_FMUSIC_GetNumInstruments@4");
+// GETPROC(FMUSIC_GetNumSamples, "_FMUSIC_GetNumSamples@4");
+// GETPROC(FMUSIC_GetNumChannels, "_FMUSIC_GetNumChannels@4");
+// GETPROC(FMUSIC_GetSample, "_FMUSIC_GetSample@8");
+// GETPROC(FMUSIC_GetPatternLength, "_FMUSIC_GetPatternLength@8");
+// GETPROC(FMUSIC_IsFinished, "_FMUSIC_IsFinished@4");
+// GETPROC(FMUSIC_GetMasterVolume, "_FMUSIC_GetMasterVolume@4");
+// GETPROC(FMUSIC_GetGlobalVolume, "_FMUSIC_GetGlobalVolume@4");
+// GETPROC(FMUSIC_GetOrder, "_FMUSIC_GetOrder@4");
+// GETPROC(FMUSIC_GetPattern, "_FMUSIC_GetPattern@4");
+// GETPROC(FMUSIC_GetSpeed, "_FMUSIC_GetSpeed@4");
+// GETPROC(FMUSIC_GetBPM, "_FMUSIC_GetBPM@4");
+// GETPROC(FMUSIC_GetRow, "_FMUSIC_GetRow@4");
+// GETPROC(FMUSIC_GetPaused, "_FMUSIC_GetPaused@4");
+// GETPROC(FMUSIC_GetTime, "_FMUSIC_GetTime@4");
+// GETPROC(FMUSIC_GetRealChannel, "_FMUSIC_GetRealChannel@8");
+// GETPROC(FMUSIC_GetUserData, "_FMUSIC_GetUserData@4");
+
+#undef GETPROC
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+FMOD_INSTANCE::~FMOD_INSTANCE()
+{
+ if (mModule)
+ FreeLibrary(mModule);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Sexy::LoadFModDLL()
+{
+ InterlockedIncrement(&gFModLoadCount);
+ if (gFMod!=NULL)
+ return;
+
+ gFMod = new FMOD_INSTANCE("fmod.dll");
+ if (gFMod->mModule==NULL)
+ {
+ MessageBoxA(NULL,"Can't find fmod.dll." ,"Error",MB_OK | MB_ICONERROR);
+ exit(0);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Sexy::FreeFModDLL()
+{
+ if (gFMod!=NULL)
+ {
+ if (InterlockedDecrement(&gFModLoadCount) <= 0)
+ {
+ delete gFMod;
+ gFMod = NULL;
+ }
+ }
+}
+
+
diff --git a/osframework/source/SexyAppFramework/FModLoader.h b/osframework/source/SexyAppFramework/FModLoader.h
new file mode 100644
index 0000000..8e17dad
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModLoader.h
@@ -0,0 +1,239 @@
+#ifndef __FMODLOADER_H__
+#define __FMODLOADER_H__
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdio.h>
+
+#include "fmod.h"
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+namespace Sexy
+{
+
+struct FMOD_INSTANCE
+{
+ FMOD_INSTANCE(const char *dllName);
+ virtual ~FMOD_INSTANCE();
+
+ HMODULE mModule;
+
+ signed char (F_API *FSOUND_SetBufferSize)(int len_ms);
+ signed char (F_API *FSOUND_SetHWND)(void *hwnd);
+ signed char (F_API *FSOUND_Init)(int mixrate, int maxsoftwarechannels, unsigned int flags);
+ void (F_API *FSOUND_Close)();
+
+ FSOUND_SAMPLE * (F_API *FSOUND_Sample_Load)(int index, const char *name_or_data, unsigned int mode, int memlength);
+ FSOUND_SAMPLE * (F_API *FSOUND_Sample_Alloc)(int index, int length, unsigned int mode, int deffreq, int defvol, int defpan, int defpri);
+ void (F_API *FSOUND_Sample_Free)(FSOUND_SAMPLE *sptr);
+ signed char (F_API *FSOUND_Sample_Lock)(FSOUND_SAMPLE *sptr, int offset, int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2);
+ signed char (F_API *FSOUND_Sample_Unlock)(FSOUND_SAMPLE *sptr, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2);
+ signed char (F_API *FSOUND_Sample_SetLoopPoints)(FSOUND_SAMPLE *sptr, int loopstart, int loopend);
+ unsigned int (F_API *FSOUND_Sample_GetLength)(FSOUND_SAMPLE *sptr);
+ signed char (F_API *FSOUND_Sample_GetDefaults)(FSOUND_SAMPLE *sptr, int *deffreq, int *defvol, int *defpan, int *defpri);
+ unsigned int (F_API *FSOUND_Sample_GetMode)(FSOUND_SAMPLE *sptr);
+
+ int (F_API *FSOUND_PlaySound)(int channel, FSOUND_SAMPLE *sptr);
+ signed char (F_API *FSOUND_StopSound)(int channel);
+ signed char (F_API *FSOUND_SetVolume)(int channel, int vol);
+ signed char (F_API *FSOUND_SetPaused)(int channel, signed char paused);
+ signed char (F_API *FSOUND_SetLoopMode)(int channel, unsigned int loopmode);
+ signed char (F_API *FSOUND_IsPlaying)(int channel);
+
+ FSOUND_STREAM * (F_API *FSOUND_Stream_OpenFile)(const char *filename, unsigned int mode, int memlength);
+ signed char (F_API *FSOUND_Stream_Close)(FSOUND_STREAM *stream);
+ int (F_API *FSOUND_Stream_Play)(int channel, FSOUND_STREAM *stream);
+
+ FMUSIC_MODULE * (F_API *FMUSIC_LoadSong)(const char *name);
+ signed char (F_API *FMUSIC_PlaySong)(FMUSIC_MODULE *mod);
+ signed char (F_API *FMUSIC_StopSong)(FMUSIC_MODULE *mod);
+ signed char (F_API *FMUSIC_SetLooping)(FMUSIC_MODULE *mod, signed char looping);
+ signed char (F_API *FMUSIC_SetOrder)(FMUSIC_MODULE *mod, int order);
+ signed char (F_API *FMUSIC_SetPaused)(FMUSIC_MODULE *mod, signed char pause);
+ signed char (F_API *FMUSIC_SetMasterVolume)(FMUSIC_MODULE *mod, int volume);
+ signed char (F_API *FMUSIC_IsPlaying)(FMUSIC_MODULE *mod);
+/*
+ signed char (F_API *FSOUND_SetOutput)(int outputtype);
+ signed char (F_API *FSOUND_SetDriver)(int driver);
+ signed char (F_API *FSOUND_SetMixer)(int mixer);
+ signed char (F_API *FSOUND_SetMinHardwareChannels)(int min);
+ signed char (F_API *FSOUND_SetMaxHardwareChannels)(int max);
+ signed char (F_API *FSOUND_SetMemorySystem)(void *pool, int poollen, FSOUND_ALLOCCALLBACK useralloc, FSOUND_REALLOCCALLBACK userrealloc, FSOUND_FREECALLBACK userfree);
+ void (F_API *FSOUND_SetSpeakerMode)(unsigned int speakermode);
+ void (F_API *FSOUND_SetSFXMasterVolume)(int volume);
+ void (F_API *FSOUND_SetPanSeperation)(float pansep);
+ void (F_API *FSOUND_File_SetCallbacks)(FSOUND_OPENCALLBACK useropen, FSOUND_CLOSECALLBACK userclose, FSOUND_READCALLBACK userread, FSOUND_SEEKCALLBACK userseek, FSOUND_TELLCALLBACK usertell);
+ int (F_API *FSOUND_GetError)();
+ float (F_API *FSOUND_GetVersion)();
+ int (F_API *FSOUND_GetOutput)();
+ void * (F_API *FSOUND_GetOutputHandle)();
+ int (F_API *FSOUND_GetDriver)();
+ int (F_API *FSOUND_GetMixer)();
+ int (F_API *FSOUND_GetNumDrivers)();
+ signed char * (F_API *FSOUND_GetDriverName)(int id);
+ signed char (F_API *FSOUND_GetDriverCaps)(int id, unsigned int *caps);
+ int (F_API *FSOUND_GetOutputRate)();
+ int (F_API *FSOUND_GetMaxChannels)();
+ int (F_API *FSOUND_GetMaxSamples)();
+ int (F_API *FSOUND_GetSFXMasterVolume)();
+ int (F_API *FSOUND_GetNumHardwareChannels)();
+ int (F_API *FSOUND_GetChannelsPlaying)();
+ float (F_API *FSOUND_GetCPUUsage)();
+ void (F_API *FSOUND_GetMemoryStats)(unsigned int *currentalloced, unsigned int *maxalloced);
+ signed char (F_API *FSOUND_Sample_Upload)(FSOUND_SAMPLE *sptr, void *srcdata, unsigned int mode);
+ signed char (F_API *FSOUND_Sample_SetMode)(FSOUND_SAMPLE *sptr, unsigned int mode);
+ signed char (F_API *FSOUND_Sample_SetDefaults)(FSOUND_SAMPLE *sptr, int deffreq, int defvol, int defpan, int defpri);
+ signed char (F_API *FSOUND_Sample_SetMinMaxDistance)(FSOUND_SAMPLE *sptr, float min, float max);
+ signed char (F_API *FSOUND_Sample_SetMaxPlaybacks)(FSOUND_SAMPLE *sptr, int max);
+ FSOUND_SAMPLE * (F_API *FSOUND_Sample_Get)(int sampno);
+ char * (F_API *FSOUND_Sample_GetName)(FSOUND_SAMPLE *sptr);
+ signed char (F_API *FSOUND_Sample_GetLoopPoints)(FSOUND_SAMPLE *sptr, int *loopstart, int *loopend);
+ int (F_API *FSOUND_PlaySoundEx)(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
+ signed char (F_API *FSOUND_SetFrequency)(int channel, int freq);
+ signed char (F_API *FSOUND_SetVolumeAbsolute)(int channel, int vol);
+ signed char (F_API *FSOUND_SetPan)(int channel, int pan);
+ signed char (F_API *FSOUND_SetSurround)(int channel, signed char surround);
+ signed char (F_API *FSOUND_SetMute)(int channel, signed char mute);
+ signed char (F_API *FSOUND_SetPriority)(int channel, int priority);
+ signed char (F_API *FSOUND_SetReserved)(int channel, signed char reserved);
+ signed char (F_API *FSOUND_SetCurrentPosition)(int channel, unsigned int offset);
+ int (F_API *FSOUND_GetFrequency)(int channel);
+ int (F_API *FSOUND_GetVolume)(int channel);
+ int (F_API *FSOUND_GetPan)(int channel);
+ signed char (F_API *FSOUND_GetSurround)(int channel);
+ signed char (F_API *FSOUND_GetMute)(int channel);
+ int (F_API *FSOUND_GetPriority)(int channel);
+ signed char (F_API *FSOUND_GetReserved)(int channel);
+ signed char (F_API *FSOUND_GetPaused)(int channel);
+ unsigned int (F_API *FSOUND_GetLoopMode)(int channel);
+ unsigned int (F_API *FSOUND_GetCurrentPosition)(int channel);
+ FSOUND_SAMPLE * (F_API *FSOUND_GetCurrentSample)(int channel);
+ signed char (F_API *FSOUND_GetCurrentLevels)(int channel, float *l, float *r);
+ int (F_API *FSOUND_FX_Enable)(int channel, unsigned int fx); // See FSOUND_FX_MODES
+ signed char (F_API *FSOUND_FX_Disable)(int channel);
+ signed char (F_API *FSOUND_FX_SetChorus)(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase);
+ signed char (F_API *FSOUND_FX_SetCompressor)(int fxid, float Gain, float Attack, float Release, float Threshold, float Ratio, float Predelay);
+ signed char (F_API *FSOUND_FX_SetDistortion)(int fxid, float Gain, float Edge, float PostEQCenterFrequency, float PostEQBandwidth, float PreLowpassCutoff);
+ signed char (F_API *FSOUND_FX_SetEcho)(int fxid, float WetDryMix, float Feedback, float LeftDelay, float RightDelay, int PanDelay);
+ signed char (F_API *FSOUND_FX_SetFlanger)(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase);
+ signed char (F_API *FSOUND_FX_SetGargle)(int fxid, int RateHz, int WaveShape);
+ signed char (F_API *FSOUND_FX_SetI3DL2Reverb)(int fxid, int Room, int RoomHF, float RoomRolloffFactor, float DecayTime, float DecayHFRatio, int Reflections, float ReflectionsDelay, int Reverb, float ReverbDelay, float Diffusion, float Density, float HFReference);
+ signed char (F_API *FSOUND_FX_SetParamEQ)(int fxid, float Center, float Bandwidth, float Gain);
+ signed char (F_API *FSOUND_FX_SetWavesReverb)(int fxid, float InGain, float ReverbMix, float ReverbTime, float HighFreqRTRatio);
+ void (F_API *FSOUND_Update)(); // you must call this once a frame
+ void (F_API *FSOUND_3D_SetDopplerFactor)(float scale);
+ void (F_API *FSOUND_3D_SetDistanceFactor)(float scale);
+ void (F_API *FSOUND_3D_SetRolloffFactor)(float scale);
+ signed char (F_API *FSOUND_3D_SetAttributes)(int channel, float *pos, float *vel);
+ signed char (F_API *FSOUND_3D_GetAttributes)(int channel, float *pos, float *vel);
+ void (F_API *FSOUND_3D_Listener_SetCurrent)(int current, int numlisteners); /* use this if you use multiple listeners / splitscreen
+ void (F_API *FSOUND_3D_Listener_SetAttributes)(float *pos, float *vel, float fx, float fy, float fz, float tx, float ty, float tz);
+ void (F_API *FSOUND_3D_Listener_GetAttributes)(float *pos, float *vel, float *fx, float *fy, float *fz, float *tx, float *ty, float *tz);
+ signed char (F_API *FSOUND_Stream_SetBufferSize)(int ms); // call this before opening streams, not after
+ FSOUND_STREAM * (F_API *FSOUND_Stream_Create)(FSOUND_STREAMCALLBACK callback, int length, unsigned int mode, int samplerate, int userdata);
+ int (F_API *FSOUND_Stream_PlayEx)(int channel, FSOUND_STREAM *stream, FSOUND_DSPUNIT *dsp, signed char startpaused);
+ signed char (F_API *FSOUND_Stream_Stop)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_Stream_SetEndCallback)(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata);
+ signed char (F_API *FSOUND_Stream_SetSynchCallback)(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata);
+ FSOUND_SAMPLE * (F_API *FSOUND_Stream_GetSample)(FSOUND_STREAM *stream); // every stream contains a sample to playback on
+ FSOUND_DSPUNIT *(F_API *FSOUND_Stream_CreateDSP)(FSOUND_STREAM *stream, FSOUND_DSPCALLBACK callback, int priority, int param);
+ signed char (F_API *FSOUND_Stream_SetPosition)(FSOUND_STREAM *stream, unsigned int position);
+ unsigned int (F_API *FSOUND_Stream_GetPosition)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_Stream_SetTime)(FSOUND_STREAM *stream, int ms);
+ int (F_API *FSOUND_Stream_GetTime)(FSOUND_STREAM *stream);
+ int (F_API *FSOUND_Stream_GetLength)(FSOUND_STREAM *stream);
+ int (F_API *FSOUND_Stream_GetLengthMs)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_Stream_SetSubStream)(FSOUND_STREAM *stream, int index);
+ int (F_API *FSOUND_Stream_GetNumSubStreams)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_Stream_SetSubStreamSentence)(FSOUND_STREAM *stream, int *sentencelist, int numitems);
+ signed char (F_API *FSOUND_Stream_SetMode)(FSOUND_STREAM *stream, unsigned int mode);
+ unsigned int (F_API *FSOUND_Stream_GetMode)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_Stream_SetLoopPoints)(FSOUND_STREAM *stream, unsigned int loopstartpcm, unsigned int loopendpcm);
+ int (F_API *FSOUND_Stream_AddSynchPoint)(FSOUND_STREAM *stream, unsigned int pcmoffset, int userdata);
+ signed char (F_API *FSOUND_Stream_DeleteSynchPoint)(FSOUND_STREAM *stream, int index);
+ int (F_API *FSOUND_Stream_GetNumSynchPoints)(FSOUND_STREAM *stream);
+ int (F_API *FSOUND_Stream_GetOpenState)(FSOUND_STREAM *stream);
+ signed char (F_API *FSOUND_CD_Play)(char drive, int track);
+ void (F_API *FSOUND_CD_SetPlayMode)(char drive, signed char mode);
+ signed char (F_API *FSOUND_CD_Stop)(char drive);
+ signed char (F_API *FSOUND_CD_SetTrackTime)(char drive, unsigned int ms);
+ signed char (F_API *FSOUND_CD_Eject)(char drive);
+ signed char (F_API *FSOUND_CD_GetPaused)(char drive);
+ int (F_API *FSOUND_CD_GetTrack)(char drive);
+ int (F_API *FSOUND_CD_GetNumTracks)(char drive);
+ int (F_API *FSOUND_CD_GetVolume)(char drive);
+ int (F_API *FSOUND_CD_GetTrackLength)(char drive, int track);
+ int (F_API *FSOUND_CD_GetTrackTime)(char drive);
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_Create)(FSOUND_DSPCALLBACK callback, int priority, int param);
+ void (F_API *FSOUND_DSP_Free)(FSOUND_DSPUNIT *unit);
+ void (F_API *FSOUND_DSP_SetPriority)(FSOUND_DSPUNIT *unit, int priority);
+ int (F_API *FSOUND_DSP_GetPriority)(FSOUND_DSPUNIT *unit);
+ void (F_API *FSOUND_DSP_SetActive)(FSOUND_DSPUNIT *unit, signed char active);
+ signed char (F_API *FSOUND_DSP_GetActive)(FSOUND_DSPUNIT *unit);
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_GetClearUnit)();
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_GetSFXUnit)();
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_GetMusicUnit)();
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_GetFFTUnit)();
+ FSOUND_DSPUNIT *(F_API *FSOUND_DSP_GetClipAndCopyUnit)();
+ signed char (F_API *FSOUND_DSP_MixBuffers)(void *destbuffer, void *srcbuffer, int len, int freq, int vol, int pan, unsigned int mode);
+ void (F_API *FSOUND_DSP_ClearMixBuffer)();
+ int (F_API *FSOUND_DSP_GetBufferLength)(); // Length of each DSP update
+ int (F_API *FSOUND_DSP_GetBufferLengthTotal)(); // Total buffer length due to FSOUND_SetBufferSize
+ float * (F_API *FSOUND_DSP_GetSpectrum)(); // Array of 512 floats - call FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE)) for this to work.
+ signed char (F_API *FSOUND_Reverb_SetProperties)(FSOUND_REVERB_PROPERTIES *prop);
+ signed char (F_API *FSOUND_Reverb_GetProperties)(FSOUND_REVERB_PROPERTIES *prop);
+ signed char (F_API *FSOUND_Reverb_SetChannelProperties)(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop);
+ signed char (F_API *FSOUND_Reverb_GetChannelProperties)(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop);
+ signed char (F_API *FSOUND_Record_SetDriver)(int outputtype);
+ int (F_API *FSOUND_Record_GetNumDrivers)();
+ signed char * (F_API *FSOUND_Record_GetDriverName)(int id);
+ int (F_API *FSOUND_Record_GetDriver)();
+ signed char (F_API *FSOUND_Record_StartSample)(FSOUND_SAMPLE *sptr, signed char loop);
+ signed char (F_API *FSOUND_Record_Stop)();
+ int (F_API *FSOUND_Record_GetPosition)();
+ FMUSIC_MODULE * (F_API *FMUSIC_LoadSongEx)(void *data, int length);
+ signed char (F_API *FMUSIC_FreeSong)(FMUSIC_MODULE *mod);
+ void (F_API *FMUSIC_StopAllSongs)();
+ signed char (F_API *FMUSIC_SetZxxCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback);
+ signed char (F_API *FMUSIC_SetRowCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int rowstep);
+ signed char (F_API *FMUSIC_SetOrderCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int orderstep);
+ signed char (F_API *FMUSIC_SetInstCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int instrument);
+ signed char (F_API *FMUSIC_SetSample)(FMUSIC_MODULE *mod, int sampno, FSOUND_SAMPLE *sptr);
+ signed char (F_API *FMUSIC_SetUserData)(FMUSIC_MODULE *mod, unsigned int userdata);
+ signed char (F_API *FMUSIC_OptimizeChannels)(FMUSIC_MODULE *mod, int maxchannels, int minvolume);
+ signed char (F_API *FMUSIC_SetReverb)(signed char reverb); // MIDI only
+ signed char (F_API *FMUSIC_SetMasterSpeed)(FMUSIC_MODULE *mode, float speed);
+ signed char (F_API *FMUSIC_SetPanSeperation)(FMUSIC_MODULE *mod, float pansep);
+ char * (F_API *FMUSIC_GetName)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetType)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetNumOrders)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetNumPatterns)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetNumInstruments)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetNumSamples)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetNumChannels)(FMUSIC_MODULE *mod);
+ FSOUND_SAMPLE * (F_API *FMUSIC_GetSample)(FMUSIC_MODULE *mod, int sampno);
+ int (F_API *FMUSIC_GetPatternLength)(FMUSIC_MODULE *mod, int orderno);
+ signed char (F_API *FMUSIC_IsFinished)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetMasterVolume)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetGlobalVolume)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetOrder)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetPattern)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetSpeed)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetBPM)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetRow)(FMUSIC_MODULE *mod);
+ signed char (F_API *FMUSIC_GetPaused)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetTime)(FMUSIC_MODULE *mod);
+ int (F_API *FMUSIC_GetRealChannel)(FMUSIC_MODULE *mod, int modchannel);
+ unsigned int (F_API *FMUSIC_GetUserData)(FMUSIC_MODULE *mod);*/
+} ;
+
+
+extern FMOD_INSTANCE *gFMod;
+
+void LoadFModDLL(); // exits on failure
+void FreeFModDLL();
+
+} // namespace Sexy
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/FModMusicInterface.cpp b/osframework/source/SexyAppFramework/FModMusicInterface.cpp
new file mode 100644
index 0000000..3951495
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModMusicInterface.cpp
@@ -0,0 +1,466 @@
+#include "FModMusicInterface.h"
+#include "SexyAppBase.h"
+#include "FModLoader.h"
+
+using namespace Sexy;
+
+FModMusicInfo::FModMusicInfo()
+{
+ mHSample = NULL;
+ mHMusic = NULL;
+ mVolume = 0.0;
+ mVolumeAdd = 0.0;
+ mVolumeCap = 1.0;
+ mStopOnFade = false;
+ mRepeats = false;
+}
+
+FModMusicInterface::FModMusicInterface(HWND theHWnd)
+{
+ LoadFModDLL();
+
+ mMasterVolume = 1.0;
+ mMaxMusicVolume = 100;
+ mMaxSampleVolume = 100;
+}
+
+FModMusicInterface::~FModMusicInterface()
+{
+ FreeFModDLL();
+}
+
+FSOUND_SAMPLE* FModMusicInterface::LoadFMODSample(const std::string& theFileName)
+{
+ std::string aFilename = theFileName;
+
+ int aLastDotPos = aFilename.rfind('.');
+ int aLastSlashPos = max((int) aFilename.rfind('\\'), (int) aFilename.rfind('/'));
+ if (aLastSlashPos < 0)
+ aLastSlashPos = 0;
+
+ std::string aCachedName = GetAppDataFolder() + "cached\\" + GetFileName(theFileName, true) + ".wav";
+ MkDir(GetFileDir(aCachedName));
+
+ FSOUND_SAMPLE* aSample = gFMod->FSOUND_Sample_Load(FSOUND_FREE, aCachedName.c_str(), 0, 0);
+
+ if (aSample == NULL)
+ {
+ aSample = gFMod->FSOUND_Sample_Load(FSOUND_FREE, (theFileName + ".ogg").c_str(), 0, 0);
+
+ if (aSample != NULL)
+ {
+ int aMode = gFMod->FSOUND_Sample_GetMode(aSample);
+ int aFreq = 0;
+ gFMod->FSOUND_Sample_GetDefaults(aSample, &aFreq, NULL, NULL, NULL);
+
+ ushort aFormatTag = 1;
+ ushort aChannelCount = ((aMode & FSOUND_MONO) != 0) ? 1 : 2;
+ ulong aSampleRate = aFreq;
+ ushort aBitCount = ((aMode & FSOUND_8BITS) != 0) ? 8 : 16;
+ ushort aBlockAlign = aChannelCount*aBitCount/8;
+ ulong aBytesPerSec = aSampleRate * aBlockAlign;
+
+ int aDataSize = gFMod->FSOUND_Sample_GetLength(aSample) * aBlockAlign;
+ ulong aChunkSize = 4 + 8 + 16 + 8 + aDataSize;
+
+ void* aPtr1;
+ void* aPtr2;
+ uint aLen1;
+ uint aLen2;
+
+ if (gFMod->FSOUND_Sample_Lock(aSample, 0, aDataSize, &aPtr1, &aPtr2, &aLen1, &aLen2))
+ {
+ FILE* fp = fopen(aCachedName.c_str(), "wb");
+
+ if (fp != NULL)
+ {
+ fwrite("RIFF", 1, 4, fp);
+ fwrite(&aChunkSize, 4, 1, fp);
+ fwrite("WAVE", 1, 4, fp);
+
+ aChunkSize = 16;
+ fwrite("fmt ", 1, 4, fp);
+ fwrite(&aChunkSize, 1, 4, fp);
+ fwrite(&aFormatTag, 2, 1, fp);
+ fwrite(&aChannelCount, 2, 1, fp);
+ fwrite(&aSampleRate, 4, 1, fp);
+ fwrite(&aBytesPerSec, 4, 1, fp);
+ fwrite(&aBlockAlign, 2, 1, fp);
+ fwrite(&aBitCount, 2, 1, fp);
+
+ fwrite("data", 1, 4, fp);
+ fwrite(&aDataSize, 4, 1, fp);
+ fwrite(aPtr1, 1, aDataSize, fp);
+ fclose(fp);
+ }
+
+ gFMod->FSOUND_Sample_Unlock(aSample, aPtr1, aPtr2, aLen1, aLen2);
+ }
+ }
+ }
+
+ return aSample;
+}
+
+bool FModMusicInterface::LoadSample(int theSongId, const std::string& theFileName, bool repeat)
+{
+ FSOUND_SAMPLE* aSample = LoadFMODSample(theFileName.c_str());
+
+ if (aSample == NULL)
+ return false;
+
+ FModMusicInfo aMusicInfo;
+ aMusicInfo.mHSample = aSample;
+ aMusicInfo.mRepeats = repeat;
+ mMusicMap.insert(FModMusicMap::value_type(theSongId, aMusicInfo));
+
+ return true;
+}
+
+bool FModMusicInterface::LoadSample(int theSongId, const std::string& theIntroFileName, const std::string& theRepeatFileName, bool repeat)
+{
+ FSOUND_SAMPLE* anIntroSample = LoadFMODSample(theIntroFileName.c_str());
+ FSOUND_SAMPLE* aLoopSample = LoadFMODSample(theRepeatFileName.c_str());
+
+ if ((anIntroSample == NULL) || (aLoopSample == NULL))
+ return false;
+
+ // Get info for intro
+ int anIntroFreq;
+ gFMod->FSOUND_Sample_GetDefaults(anIntroSample, &anIntroFreq, NULL, NULL, NULL);
+ int anIntroMode = gFMod->FSOUND_Sample_GetMode(anIntroSample);
+ int anIntroLen = gFMod->FSOUND_Sample_GetLength(anIntroSample);
+
+ // Get intro for loop
+ int aLoopFreq;
+ gFMod->FSOUND_Sample_GetDefaults(aLoopSample, &aLoopFreq, NULL, NULL, NULL);
+ int aLoopMode = gFMod->FSOUND_Sample_GetMode(aLoopSample);
+ int aLoopLen = gFMod->FSOUND_Sample_GetLength(aLoopSample);
+
+ // Formats must be the same
+ if ((anIntroFreq != aLoopFreq) || (anIntroMode != aLoopMode))
+ return false;
+
+ // Create new sound to combine these two into
+ FSOUND_SAMPLE* aSample = gFMod->FSOUND_Sample_Alloc(FSOUND_FREE, anIntroLen + aLoopLen, anIntroMode | FSOUND_LOOP_NORMAL, anIntroFreq, 255, 128, 0);
+
+ void* aSamplePtr1;
+ void* aSamplePtr2;
+ uint aSampleLen1;
+ uint aSampleLen2;
+
+ int aSampleBytes = (((anIntroMode & FSOUND_MONO) != 0) ? 1 : 2) * (((anIntroMode & FSOUND_8BITS) != 0) ? 1 : 2);
+
+ if (gFMod->FSOUND_Sample_Lock(aSample, 0, (anIntroLen + aLoopLen) * aSampleBytes, &aSamplePtr1, &aSamplePtr2, &aSampleLen1, &aSampleLen2))
+ {
+ void* aSrcPtr1;
+ void* aSrcPtr2;
+ uint aSrcLen1;
+ uint aSrcLen2;
+
+ if (gFMod->FSOUND_Sample_Lock(anIntroSample, 0, anIntroLen * aSampleBytes, &aSrcPtr1, &aSrcPtr2, &aSrcLen1, &aSrcLen2))
+ {
+ memcpy(aSamplePtr1, aSrcPtr1, aSrcLen1);
+ gFMod->FSOUND_Sample_Unlock(anIntroSample, aSrcPtr1, aSrcPtr2, aSrcLen1, aSrcLen2);
+ }
+
+ if (gFMod->FSOUND_Sample_Lock(aLoopSample, anIntroLen * aSampleBytes, aLoopLen * aSampleBytes, &aSrcPtr1, &aSrcPtr2, &aSrcLen1, &aSrcLen2))
+ {
+ memcpy((char*) aSamplePtr1 + (anIntroLen * aSampleBytes), aSrcPtr1, aSrcLen1);
+ gFMod->FSOUND_Sample_Unlock(aLoopSample, aSrcPtr1, aSrcPtr2, aSrcLen1, aSrcLen2);
+ }
+
+ gFMod->FSOUND_Sample_Unlock(aSample, aSamplePtr1, aSamplePtr2, aSampleLen1, aSampleLen2);
+ }
+
+ gFMod->FSOUND_Sample_Free(anIntroSample);
+ gFMod->FSOUND_Sample_Free(aLoopSample);
+
+ gFMod->FSOUND_Sample_SetLoopPoints(aSample, anIntroLen, aLoopLen);
+
+ FModMusicInfo aMusicInfo;
+ aMusicInfo.mHSample = aSample;
+ aMusicInfo.mRepeats = repeat;
+ mMusicMap.insert(FModMusicMap::value_type(theSongId, aMusicInfo));
+
+ return true;
+}
+
+bool FModMusicInterface::LoadMusic(int theSongId, const std::string& theFileName)
+{
+ FMUSIC_MODULE* aHMusic = gFMod->FMUSIC_LoadSong(theFileName.c_str());
+
+ if (aHMusic == NULL)
+ return false;
+
+ FModMusicInfo aMusicInfo;
+ aMusicInfo.mHMusic = aHMusic;
+ mMusicMap.insert(FModMusicMap::value_type(theSongId, aMusicInfo));
+
+ return true;
+}
+
+void FModMusicInterface::PlayMusic(int theSongId, int theOffset, bool noLoop)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = aMusicInfo->mVolumeCap;
+ aMusicInfo->mVolumeAdd = 0.0;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetMasterVolume(aMusicInfo->mHMusic, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxMusicVolume));
+ gFMod->FMUSIC_SetLooping(aMusicInfo->mHMusic, noLoop ? FSOUND_LOOP_OFF : FSOUND_LOOP_NORMAL);
+ gFMod->FMUSIC_PlaySong(aMusicInfo->mHMusic);
+ gFMod->FMUSIC_SetOrder(aMusicInfo->mHMusic, theOffset);
+ }
+ else
+ {
+ gFMod->FSOUND_PlaySound(anItr->first, aMusicInfo->mHSample);
+ gFMod->FSOUND_SetLoopMode(anItr->first, aMusicInfo->mRepeats ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF);
+ gFMod->FSOUND_SetVolume(anItr->first, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxSampleVolume));
+ }
+ }
+}
+
+void FModMusicInterface::PauseMusic(int theSongId)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetPaused(aMusicInfo->mHMusic, TRUE);
+ }
+ else
+ {
+ gFMod->FSOUND_SetPaused(theSongId, TRUE);
+ }
+ }
+}
+
+void FModMusicInterface::ResumeMusic(int theSongId)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetPaused(aMusicInfo->mHMusic, FALSE);
+ }
+ else
+ {
+ gFMod->FSOUND_SetPaused(theSongId, FALSE);
+ }
+ }
+}
+
+void FModMusicInterface::StopMusic(int theSongId)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = 0.0;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_StopSong(aMusicInfo->mHMusic);
+ }
+ else
+ {
+ gFMod->FSOUND_StopSound(theSongId);
+ }
+ }
+}
+
+void FModMusicInterface::StopAllMusic()
+{
+ FModMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+ aMusicInfo->mVolume = 0.0;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_StopSong(aMusicInfo->mHMusic);
+ }
+ else
+ {
+ gFMod->FSOUND_StopSound(anItr->first);
+ }
+
+ ++anItr;
+ }
+}
+
+void FModMusicInterface::FadeIn(int theSongId, int theOffset, double theSpeed, bool noLoop)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeAdd = theSpeed;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetMasterVolume(aMusicInfo->mHMusic, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxMusicVolume));
+
+ gFMod->FMUSIC_SetLooping(aMusicInfo->mHMusic, noLoop ? FSOUND_LOOP_OFF : FSOUND_LOOP_NORMAL);
+
+ if (!gFMod->FMUSIC_IsPlaying(aMusicInfo->mHMusic))
+ gFMod->FMUSIC_PlaySong(aMusicInfo->mHMusic);
+
+ if (theOffset != -1)
+ gFMod->FMUSIC_SetOrder(aMusicInfo->mHMusic, theOffset);
+ }
+ else
+ {
+ if (!gFMod->FSOUND_IsPlaying(theSongId))
+ {
+ gFMod->FSOUND_PlaySound(theSongId, aMusicInfo->mHSample);
+ gFMod->FSOUND_SetLoopMode(anItr->first, aMusicInfo->mRepeats ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF);
+ }
+
+ gFMod->FSOUND_SetVolume(anItr->first, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxSampleVolume));
+ }
+ }
+}
+
+void FModMusicInterface::FadeOut(int theSongId, bool stopSong, double theSpeed)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeAdd = -theSpeed;
+ aMusicInfo->mStopOnFade = stopSong;
+ }
+}
+
+void FModMusicInterface::FadeOutAll(bool stopSong, double theSpeed)
+{
+ FModMusicMap::iterator anItr = mMusicMap.begin();
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolumeAdd = -theSpeed;
+ aMusicInfo->mStopOnFade = stopSong;
+
+ ++anItr;
+ }
+}
+
+void FModMusicInterface::SetVolume(double theVolume)
+{
+ mMasterVolume = theVolume;
+
+ FModMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetMasterVolume(aMusicInfo->mHMusic, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxMusicVolume));
+ }
+ else
+ {
+ gFMod->FSOUND_SetVolume(anItr->first, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxSampleVolume));
+ }
+
+ ++anItr;
+ }
+}
+
+void FModMusicInterface::SetSongVolume(int theSongId, double theVolume)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ aMusicInfo->mVolume = theVolume;
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetMasterVolume(aMusicInfo->mHMusic, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxMusicVolume));
+ }
+ else
+ {
+ gFMod->FSOUND_SetVolume(anItr->first, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxSampleVolume));
+ }
+ }
+}
+
+bool FModMusicInterface::IsPlaying(int theSongId)
+{
+ FModMusicMap::iterator anItr = mMusicMap.find(theSongId);
+ if (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ return (gFMod->FMUSIC_IsPlaying(aMusicInfo->mHMusic) != 0);
+ }
+ else
+ return false;
+}
+
+void FModMusicInterface::Update()
+{
+ FModMusicMap::iterator anItr = mMusicMap.begin();
+ while (anItr != mMusicMap.end())
+ {
+ FModMusicInfo* aMusicInfo = &anItr->second;
+
+ if (aMusicInfo->mVolumeAdd != 0.0)
+ {
+ aMusicInfo->mVolume += aMusicInfo->mVolumeAdd;
+
+ if (aMusicInfo->mVolume > aMusicInfo->mVolumeCap)
+ {
+ aMusicInfo->mVolume = aMusicInfo->mVolumeCap;
+ aMusicInfo->mVolumeAdd = 0.0;
+ }
+ else if (aMusicInfo->mVolume < 0.0)
+ {
+ aMusicInfo->mVolume = 0.0;
+ aMusicInfo->mVolumeAdd = 0.0;
+
+ if (aMusicInfo->mStopOnFade)
+ {
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_StopSong(aMusicInfo->mHMusic);
+ }
+ else
+ {
+ gFMod->FSOUND_StopSound(anItr->first);
+ }
+ }
+ }
+
+ if (aMusicInfo->mHMusic != NULL)
+ {
+ gFMod->FMUSIC_SetMasterVolume(aMusicInfo->mHMusic, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxMusicVolume));
+ }
+ else
+ {
+ gFMod->FSOUND_SetVolume(anItr->first, (int) (mMasterVolume * aMusicInfo->mVolume * mMaxSampleVolume));
+ }
+ }
+
+ ++anItr;
+ }
+}
+
diff --git a/osframework/source/SexyAppFramework/FModMusicInterface.h b/osframework/source/SexyAppFramework/FModMusicInterface.h
new file mode 100644
index 0000000..a3f2940
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModMusicInterface.h
@@ -0,0 +1,64 @@
+#ifndef __FMODMUSICINTERFACE_H__
+#define __FMODMUSICINTERFACE_H__
+
+#include "MusicInterface.h"
+#include "fmod.h"
+
+namespace Sexy
+{
+
+class SexyAppBase;
+
+class FModMusicInfo
+{
+public:
+ FSOUND_SAMPLE* mHSample;
+ FMUSIC_MODULE* mHMusic;
+ double mVolume;
+ double mVolumeAdd;
+ double mVolumeCap;
+ bool mStopOnFade;
+ bool mRepeats;
+
+public:
+ FModMusicInfo();
+};
+
+typedef std::map<int, FModMusicInfo> FModMusicMap;
+
+class FModMusicInterface : public MusicInterface
+{
+public:
+ FModMusicMap mMusicMap;
+ double mMasterVolume;
+ int mMaxMusicVolume;
+ int mMaxSampleVolume;
+
+public:
+ FSOUND_SAMPLE* LoadFMODSample(const std::string& theFileName);
+
+public:
+ FModMusicInterface(HWND theHWnd);
+ virtual ~FModMusicInterface();
+
+ virtual bool LoadMusic(int theSongId, const std::string& theFileName);
+ virtual bool LoadSample(int theSongId, const std::string& theFileName, bool repeat);
+ virtual bool LoadSample(int theSongId, const std::string& theIntroFileName, const std::string& theRepeatFileName, bool repeat);
+ virtual void PlayMusic(int theSongId, int theOffset = 0, bool noLoop = false);
+ virtual void StopMusic(int theSongId);
+ virtual void PauseMusic(int theSongId);
+ virtual void ResumeMusic(int theSongId);
+ virtual void StopAllMusic();
+ virtual void FadeIn(int theSongId, int theOffset = -1, double theSpeed = 0.002, bool noLoop = false);
+ virtual void FadeOut(int theSongId, bool stopSong = true, double theSpeed = 0.004);
+ virtual void FadeOutAll(bool stopSong = true, double theSpeed = 0.004);
+ virtual void SetSongVolume(int theSongId, double theVolume);
+ virtual bool IsPlaying(int theSongId);
+
+ virtual void SetVolume(double theVolume);
+ virtual void Update();
+};
+
+}
+
+#endif //__FMODMUSICINTERFACE_H__
diff --git a/osframework/source/SexyAppFramework/FModSoundInstance.cpp b/osframework/source/SexyAppFramework/FModSoundInstance.cpp
new file mode 100644
index 0000000..41fc9bb
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModSoundInstance.cpp
@@ -0,0 +1,50 @@
+#include "FModSoundInstance.h"
+#include "FModLoader.h"
+
+using namespace Sexy;
+
+FModSoundInstance::FModSoundInstance()
+{
+ mStream = NULL;
+ mChannelNum = 0;
+}
+
+FModSoundInstance::~FModSoundInstance()
+{
+ Release();
+}
+
+void FModSoundInstance::Release()
+{
+}
+
+void FModSoundInstance::SetVolume(double theVolume)
+{
+}
+
+void FModSoundInstance::SetPan(int thePosition)
+{
+}
+
+bool FModSoundInstance::Play(bool looping, bool autoRelease)
+{
+ if (mStream == NULL)
+ return false;
+
+ gFMod->FSOUND_Stream_Play(FSOUND_FREE, mStream);
+ return true;
+}
+
+void FModSoundInstance::Stop()
+{
+}
+
+bool FModSoundInstance::IsPlaying()
+{
+ return true;
+}
+
+bool FModSoundInstance::IsReleased()
+{
+ return false;
+}
diff --git a/osframework/source/SexyAppFramework/FModSoundInstance.h b/osframework/source/SexyAppFramework/FModSoundInstance.h
new file mode 100644
index 0000000..ae2cecf
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModSoundInstance.h
@@ -0,0 +1,32 @@
+#ifndef __FMODSOUNDINSTANCE_H__
+#define __FMODSOUNDINSTANCE_H__
+
+#include "SoundInstance.h"
+#include "fmod.h"
+
+namespace Sexy
+{
+
+class FModSoundInstance : public SoundInstance
+{
+public:
+ int mChannelNum;
+ FSOUND_STREAM* mStream;
+
+public:
+ FModSoundInstance();
+ virtual ~FModSoundInstance();
+ virtual void Release();
+
+ virtual void SetVolume(double theVolume);
+ virtual void SetPan(int thePosition); //-db to +db = left to right
+
+ virtual bool Play(bool looping, bool autoRelease);
+ virtual void Stop();
+ virtual bool IsPlaying();
+ virtual bool IsReleased();
+};
+
+}
+
+#endif //__FMODSOUNDINSTANCE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/FModSoundManager.cpp b/osframework/source/SexyAppFramework/FModSoundManager.cpp
new file mode 100644
index 0000000..aff1cc9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModSoundManager.cpp
@@ -0,0 +1,114 @@
+#include "FModSoundManager.h"
+#include "FModLoader.h"
+
+using namespace Sexy;
+
+FModSoundManager::FModSoundManager(HWND theHWnd)
+{
+ LoadFModDLL();
+
+ gFMod->FSOUND_SetHWND(theHWnd);
+ gFMod->FSOUND_Init(44100, 64, FSOUND_INIT_GLOBALFOCUS);
+
+ mMasterVolume = 1.0;
+
+ for (int i = 0; i < MAX_SOURCE_SOUNDS; i++)
+ mSourceStreams[i] = NULL;
+}
+
+FModSoundManager::~FModSoundManager()
+{
+ for (int i = 0; i < MAX_SOURCE_SOUNDS; i++)
+ {
+ if (mSourceStreams[i] != NULL)
+ {
+ gFMod->FSOUND_Stream_Close(mSourceStreams[i]);
+ mSourceStreams[i] = NULL;
+ }
+ }
+}
+
+bool FModSoundManager::Initialized()
+{
+ return true;
+}
+
+bool FModSoundManager::LoadSound(unsigned int theSfxID, const std::string& theFilename)
+{
+ int aLastDotPos = theFilename.rfind('.');
+ if (aLastDotPos == -1)
+ {
+ if (LoadSound(theSfxID, theFilename + ".wav"))
+ return true;
+
+ if (LoadSound(theSfxID, theFilename + ".mp3"))
+ return true;
+
+ if (LoadSound(theSfxID, theFilename + ".ogg"))
+ return true;
+
+ if (LoadSound(theSfxID, theFilename + ".au"))
+ return true;
+
+ return false;
+ }
+
+ FSOUND_STREAM* aStream = gFMod->FSOUND_Stream_OpenFile(theFilename.c_str(), FSOUND_2D, 0);
+ if (aStream == NULL)
+ return false;
+
+ mSourceStreams[theSfxID] = aStream;
+ return true;
+}
+
+bool FModSoundManager::LoadSound(const std::string& theFilename)
+{
+ for (int i = MAX_SOURCE_SOUNDS-1; i >= 0; i--)
+ {
+ if (mSourceStreams[i] == NULL)
+ {
+ if (!LoadSound(i, theFilename))
+ return -1;
+ else
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+void FModSoundManager::SetVolume(double theVolume)
+{
+}
+
+SoundInstance* FModSoundManager::GetSoundInstance(unsigned int theSfxID)
+{
+ FModSoundInstance* aSoundInstance = new FModSoundInstance;
+ aSoundInstance->mStream = mSourceStreams[theSfxID];
+ return aSoundInstance;
+}
+
+void FModSoundManager::ReleaseSounds()
+{
+}
+
+void FModSoundManager::ReleaseChannels()
+{
+}
+
+double FModSoundManager::GetMasterVolume()
+{
+ return mMasterVolume;
+}
+
+void FModSoundManager::SetMasterVolume(double theVolume)
+{
+}
+
+void FModSoundManager::Flush()
+{
+}
+
+void FModSoundManager::SetCooperativeWindow(HWND theHWnd, bool isWindowed)
+{
+}
diff --git a/osframework/source/SexyAppFramework/FModSoundManager.h b/osframework/source/SexyAppFramework/FModSoundManager.h
new file mode 100644
index 0000000..8609475
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FModSoundManager.h
@@ -0,0 +1,41 @@
+#ifndef __FMODSOUNDMANAGER_H__
+#define __FMODSOUNDMANAGER_H__
+
+#include "SoundManager.h"
+#include "FModSoundInstance.h"
+#include "fmod.h"
+
+namespace Sexy
+{
+
+class FModSoundManager : public SoundManager
+{
+public:
+ double mMasterVolume;
+ FSOUND_STREAM* mSourceStreams[MAX_SOURCE_SOUNDS];
+
+public:
+ FModSoundManager(HWND theWindow);
+ virtual ~FModSoundManager();
+
+ virtual bool Initialized();
+
+ virtual bool LoadSound(unsigned int theSfxID, const std::string& theFilename);
+ virtual bool LoadSound(const std::string& theFilename);
+ virtual void SetVolume(double theVolume);
+
+ virtual SoundInstance* GetSoundInstance(unsigned int theSfxID);
+
+ virtual void ReleaseSounds();
+ virtual void ReleaseChannels();
+
+ virtual double GetMasterVolume();
+ virtual void SetMasterVolume(double theVolume);
+
+ virtual void Flush();
+ virtual void SetCooperativeWindow(HWND theHWnd, bool isWindowed);
+};
+
+}
+
+#endif //__FMODSOUNDMANAGER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Flags.cpp b/osframework/source/SexyAppFramework/Flags.cpp
new file mode 100644
index 0000000..7a02a1a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Flags.cpp
@@ -0,0 +1,2 @@
+#include "Flags.h"
+
diff --git a/osframework/source/SexyAppFramework/Flags.h b/osframework/source/SexyAppFramework/Flags.h
new file mode 100644
index 0000000..f7170dc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Flags.h
@@ -0,0 +1,76 @@
+#ifndef __FLAGS_H__
+#define __FLAGS_H__
+
+namespace Sexy
+{
+
+class FlagsMod
+{
+public:
+ int mAddFlags;
+ int mRemoveFlags;
+
+public:
+ FlagsMod()
+ {
+ mAddFlags = 0;
+ mRemoveFlags = 0;
+ }
+};
+
+inline void ModFlags(int& theFlags, const FlagsMod& theFlagMod)
+{
+ theFlags = (theFlags | theFlagMod.mAddFlags) & ~theFlagMod.mRemoveFlags;
+}
+
+inline int GetModFlags(int theFlags, const FlagsMod& theFlagMod)
+{
+ return (theFlags | theFlagMod.mAddFlags) & ~theFlagMod.mRemoveFlags;
+}
+
+class ModalFlags
+{
+public:
+ int mOverFlags;
+ int mUnderFlags;
+ bool mIsOver;
+
+public:
+ void ModFlags(const FlagsMod& theFlagsMod)
+ {
+ Sexy::ModFlags(mOverFlags, theFlagsMod);
+ Sexy::ModFlags(mUnderFlags, theFlagsMod);
+ }
+
+ int GetFlags()
+ {
+ return mIsOver ? mOverFlags : mUnderFlags;
+ }
+};
+
+class AutoModalFlags
+{
+public:
+ ModalFlags* mModalFlags;
+ int mOldOverFlags;
+ int mOldUnderFlags;
+
+public:
+ AutoModalFlags(ModalFlags* theModalFlags, const FlagsMod& theFlagMod)
+ {
+ mModalFlags = theModalFlags;
+ mOldOverFlags = theModalFlags->mOverFlags;
+ mOldUnderFlags = theModalFlags->mUnderFlags;
+ theModalFlags->ModFlags(theFlagMod);
+ }
+
+ ~AutoModalFlags()
+ {
+ mModalFlags->mOverFlags = mOldOverFlags;
+ mModalFlags->mUnderFlags = mOldUnderFlags;
+ }
+};
+
+}
+
+#endif //__FLAGS_H__
diff --git a/osframework/source/SexyAppFramework/FlashWidget.cpp b/osframework/source/SexyAppFramework/FlashWidget.cpp
new file mode 100644
index 0000000..caf5d6f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FlashWidget.cpp
@@ -0,0 +1,1384 @@
+#include "FlashWidget.h"
+#include "DDImage.h"
+#include "SexyAppBase.h"
+#include "WidgetManager.h"
+#include "Debug.h"
+
+using namespace Sexy;
+
+#pragma comment(lib, "comsuppw.lib")
+
+//////////////////////////////////////////////////////////////////////////
+// Interfaces imported from flash.ocx
+
+#include <comdef.h>
+
+#pragma pack(push, 8)
+
+namespace ShockwaveFlashObjects
+{
+
+//
+// Forward references and typedefs
+//
+
+struct __declspec(uuid("d27cdb6b-ae6d-11cf-96b8-444553540000"))
+/* LIBID */ __ShockwaveFlashObjects;
+struct __declspec(uuid("d27cdb6c-ae6d-11cf-96b8-444553540000"))
+/* dual interface */ IShockwaveFlash;
+struct __declspec(uuid("d27cdb6d-ae6d-11cf-96b8-444553540000"))
+/* dispinterface */ _IShockwaveFlashEvents;
+struct /* coclass */ ShockwaveFlash;
+struct /* coclass */ FlashProp;
+struct __declspec(uuid("d27cdb70-ae6d-11cf-96b8-444553540000"))
+/* interface */ IFlashFactory;
+struct __declspec(uuid("d27cdb72-ae6d-11cf-96b8-444553540000"))
+/* interface */ IFlashObjectInterface;
+struct __declspec(uuid("a6ef9860-c720-11d0-9337-00a0c90dcaa9"))
+/* interface */ IDispatchEx;
+struct /* coclass */ FlashObjectInterface;
+
+//
+// Smart pointer typedef declarations
+//
+
+_COM_SMARTPTR_TYPEDEF(IShockwaveFlash, __uuidof(IShockwaveFlash));
+_COM_SMARTPTR_TYPEDEF(_IShockwaveFlashEvents, __uuidof(_IShockwaveFlashEvents));
+_COM_SMARTPTR_TYPEDEF(IFlashFactory, __uuidof(IFlashFactory));
+_COM_SMARTPTR_TYPEDEF(IDispatchEx, __uuidof(IDispatchEx));
+_COM_SMARTPTR_TYPEDEF(IFlashObjectInterface, __uuidof(IFlashObjectInterface));
+
+//
+// Type library items
+//
+
+struct __declspec(uuid("d27cdb6c-ae6d-11cf-96b8-444553540000"))
+IShockwaveFlash : IDispatch
+{
+ //
+ // Property data
+ //
+
+ __declspec(property(get=GetStacking,put=PutStacking))
+ _bstr_t Stacking;
+ __declspec(property(get=GetWMode,put=PutWMode))
+ _bstr_t WMode;
+ __declspec(property(get=GetMovie,put=PutMovie))
+ _bstr_t Movie;
+ __declspec(property(get=GetSAlign,put=PutSAlign))
+ _bstr_t SAlign;
+ __declspec(property(get=GetMenu,put=PutMenu))
+ VARIANT_BOOL Menu;
+ __declspec(property(get=GetQuality,put=PutQuality))
+ int Quality;
+ __declspec(property(get=GetLoop,put=PutLoop))
+ VARIANT_BOOL Loop;
+ __declspec(property(get=GetFrameNum,put=PutFrameNum))
+ long FrameNum;
+ __declspec(property(get=GetBase,put=PutBase))
+ _bstr_t Base;
+ __declspec(property(get=Getscale,put=Putscale))
+ _bstr_t scale;
+ __declspec(property(get=GetDeviceFont,put=PutDeviceFont))
+ VARIANT_BOOL DeviceFont;
+ __declspec(property(get=GetEmbedMovie,put=PutEmbedMovie))
+ VARIANT_BOOL EmbedMovie;
+ __declspec(property(get=GetBGColor,put=PutBGColor))
+ _bstr_t BGColor;
+ __declspec(property(get=GetQuality2,put=PutQuality2))
+ _bstr_t Quality2;
+ __declspec(property(get=GetReadyState))
+ long ReadyState;
+ __declspec(property(get=GetScaleMode,put=PutScaleMode))
+ int ScaleMode;
+ __declspec(property(get=GetAlignMode,put=PutAlignMode))
+ int AlignMode;
+ __declspec(property(get=GetBackgroundColor,put=PutBackgroundColor))
+ long BackgroundColor;
+ __declspec(property(get=GetTotalFrames))
+ long TotalFrames;
+ __declspec(property(get=GetPlaying,put=PutPlaying))
+ VARIANT_BOOL Playing;
+ __declspec(property(get=GetSWRemote,put=PutSWRemote))
+ _bstr_t SWRemote;
+
+ //
+ // Raw methods provided by interface
+ //
+
+ virtual HRESULT __stdcall get_ReadyState (
+ /*[out,retval]*/ long * thestate ) = 0;
+ virtual HRESULT __stdcall get_TotalFrames (
+ /*[out,retval]*/ long * numframes ) = 0;
+ virtual HRESULT __stdcall get_Playing (
+ /*[out,retval]*/ VARIANT_BOOL * Playing ) = 0;
+ virtual HRESULT __stdcall put_Playing (
+ /*[in]*/ VARIANT_BOOL Playing ) = 0;
+ virtual HRESULT __stdcall get_Quality (
+ /*[out,retval]*/ int * Quality ) = 0;
+ virtual HRESULT __stdcall put_Quality (
+ /*[in]*/ int Quality ) = 0;
+ virtual HRESULT __stdcall get_ScaleMode (
+ /*[out,retval]*/ int * scale ) = 0;
+ virtual HRESULT __stdcall put_ScaleMode (
+ /*[in]*/ int scale ) = 0;
+ virtual HRESULT __stdcall get_AlignMode (
+ /*[out,retval]*/ int * align ) = 0;
+ virtual HRESULT __stdcall put_AlignMode (
+ /*[in]*/ int align ) = 0;
+ virtual HRESULT __stdcall get_BackgroundColor (
+ /*[out,retval]*/ long * color ) = 0;
+ virtual HRESULT __stdcall put_BackgroundColor (
+ /*[in]*/ long color ) = 0;
+ virtual HRESULT __stdcall get_Loop (
+ /*[out,retval]*/ VARIANT_BOOL * Loop ) = 0;
+ virtual HRESULT __stdcall put_Loop (
+ /*[in]*/ VARIANT_BOOL Loop ) = 0;
+ virtual HRESULT __stdcall get_Movie (
+ /*[out,retval]*/ BSTR * path ) = 0;
+ virtual HRESULT __stdcall put_Movie (
+ /*[in]*/ BSTR path ) = 0;
+ virtual HRESULT __stdcall get_FrameNum (
+ /*[out,retval]*/ long * FrameNum ) = 0;
+ virtual HRESULT __stdcall put_FrameNum (
+ /*[in]*/ long FrameNum ) = 0;
+ virtual HRESULT __stdcall SetZoomRect (
+ /*[in]*/ long left,
+ /*[in]*/ long top,
+ /*[in]*/ long right,
+ /*[in]*/ long bottom ) = 0;
+ virtual HRESULT __stdcall Zoom (
+ /*[in]*/ int factor ) = 0;
+ virtual HRESULT __stdcall Pan (
+ /*[in]*/ long x,
+ /*[in]*/ long y,
+ /*[in]*/ int mode ) = 0;
+ virtual HRESULT __stdcall Play ( ) = 0;
+ virtual HRESULT __stdcall Stop ( ) = 0;
+ virtual HRESULT __stdcall Back ( ) = 0;
+ virtual HRESULT __stdcall Forward ( ) = 0;
+ virtual HRESULT __stdcall Rewind ( ) = 0;
+ virtual HRESULT __stdcall StopPlay ( ) = 0;
+ virtual HRESULT __stdcall GotoFrame (
+ /*[in]*/ long FrameNum ) = 0;
+ virtual HRESULT __stdcall CurrentFrame (
+ /*[out,retval]*/ long * FrameNum ) = 0;
+ virtual HRESULT __stdcall IsPlaying (
+ /*[out,retval]*/ VARIANT_BOOL * Playing ) = 0;
+ virtual HRESULT __stdcall PercentLoaded (
+ /*[out,retval]*/ long * __MIDL_0011 ) = 0;
+ virtual HRESULT __stdcall FrameLoaded (
+ /*[in]*/ long FrameNum,
+ /*[out,retval]*/ VARIANT_BOOL * loaded ) = 0;
+ virtual HRESULT __stdcall FlashVersion (
+ /*[out,retval]*/ long * version ) = 0;
+ virtual HRESULT __stdcall get_WMode (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_WMode (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_SAlign (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_SAlign (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_Menu (
+ /*[out,retval]*/ VARIANT_BOOL * pVal ) = 0;
+ virtual HRESULT __stdcall put_Menu (
+ /*[in]*/ VARIANT_BOOL pVal ) = 0;
+ virtual HRESULT __stdcall get_Base (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_Base (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_scale (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_scale (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_DeviceFont (
+ /*[out,retval]*/ VARIANT_BOOL * pVal ) = 0;
+ virtual HRESULT __stdcall put_DeviceFont (
+ /*[in]*/ VARIANT_BOOL pVal ) = 0;
+ virtual HRESULT __stdcall get_EmbedMovie (
+ /*[out,retval]*/ VARIANT_BOOL * pVal ) = 0;
+ virtual HRESULT __stdcall put_EmbedMovie (
+ /*[in]*/ VARIANT_BOOL pVal ) = 0;
+ virtual HRESULT __stdcall get_BGColor (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_BGColor (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_Quality2 (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_Quality2 (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall LoadMovie (
+ /*[in]*/ int layer,
+ /*[in]*/ BSTR url ) = 0;
+ virtual HRESULT __stdcall TGotoFrame (
+ /*[in]*/ BSTR target,
+ /*[in]*/ long FrameNum ) = 0;
+ virtual HRESULT __stdcall TGotoLabel (
+ /*[in]*/ BSTR target,
+ /*[in]*/ BSTR label ) = 0;
+ virtual HRESULT __stdcall TCurrentFrame (
+ /*[in]*/ BSTR target,
+ /*[out,retval]*/ long * FrameNum ) = 0;
+ virtual HRESULT __stdcall TCurrentLabel (
+ /*[in]*/ BSTR target,
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall TPlay (
+ /*[in]*/ BSTR target ) = 0;
+ virtual HRESULT __stdcall TStopPlay (
+ /*[in]*/ BSTR target ) = 0;
+ virtual HRESULT __stdcall SetVariable (
+ /*[in]*/ BSTR name,
+ /*[in]*/ BSTR value ) = 0;
+ virtual HRESULT __stdcall GetVariable (
+ /*[in]*/ BSTR name,
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall TSetProperty (
+ /*[in]*/ BSTR target,
+ /*[in]*/ int property,
+ /*[in]*/ BSTR value ) = 0;
+ virtual HRESULT __stdcall TGetProperty (
+ /*[in]*/ BSTR target,
+ /*[in]*/ int property,
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall TCallFrame (
+ /*[in]*/ BSTR target,
+ /*[in]*/ int FrameNum ) = 0;
+ virtual HRESULT __stdcall TCallLabel (
+ /*[in]*/ BSTR target,
+ /*[in]*/ BSTR label ) = 0;
+ virtual HRESULT __stdcall TSetPropertyNum (
+ /*[in]*/ BSTR target,
+ /*[in]*/ int property,
+ /*[in]*/ double value ) = 0;
+ virtual HRESULT __stdcall TGetPropertyNum (
+ /*[in]*/ BSTR target,
+ /*[in]*/ int property,
+ /*[out,retval]*/ double * pVal ) = 0;
+ virtual HRESULT __stdcall get_SWRemote (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_SWRemote (
+ /*[in]*/ BSTR pVal ) = 0;
+ virtual HRESULT __stdcall get_Stacking (
+ /*[out,retval]*/ BSTR * pVal ) = 0;
+ virtual HRESULT __stdcall put_Stacking (
+ /*[in]*/ BSTR pVal ) = 0;
+};
+
+struct __declspec(uuid("d27cdb6d-ae6d-11cf-96b8-444553540000"))
+_IShockwaveFlashEvents : IDispatch
+{
+ //
+ // Wrapper methods for error-handling
+ //
+
+ // Methods:
+ HRESULT OnReadyStateChange (
+ long newState );
+ HRESULT OnProgress (
+ long percentDone );
+ HRESULT FSCommand (
+ _bstr_t command,
+ _bstr_t args );
+};
+
+struct __declspec(uuid("d27cdb6e-ae6d-11cf-96b8-444553540000"))
+ShockwaveFlash;
+ // [ default ] interface IShockwaveFlash
+ // [ default, source ] dispinterface _IShockwaveFlashEvents
+
+struct __declspec(uuid("1171a62f-05d2-11d1-83fc-00a0c9089c5a"))
+FlashProp;
+ // [ default ] interface IUnknown
+
+struct __declspec(uuid("d27cdb70-ae6d-11cf-96b8-444553540000"))
+IFlashFactory : IUnknown
+{};
+
+struct __declspec(uuid("a6ef9860-c720-11d0-9337-00a0c90dcaa9"))
+IDispatchEx : IDispatch
+{
+ //
+ // Wrapper methods for error-handling
+ //
+
+ HRESULT GetDispID (
+ _bstr_t bstrName,
+ unsigned long grfdex,
+ long * pid );
+ HRESULT RemoteInvokeEx (
+ long id,
+ unsigned long lcid,
+ unsigned long dwFlags,
+ struct DISPPARAMS * pdp,
+ VARIANT * pvarRes,
+ struct EXCEPINFO * pei,
+ struct IServiceProvider * pspCaller,
+ unsigned int cvarRefArg,
+ unsigned int * rgiRefArg,
+ VARIANT * rgvarRefArg );
+ HRESULT DeleteMemberByName (
+ _bstr_t bstrName,
+ unsigned long grfdex );
+ HRESULT DeleteMemberByDispID (
+ long id );
+ HRESULT GetMemberProperties (
+ long id,
+ unsigned long grfdexFetch,
+ unsigned long * pgrfdex );
+ HRESULT GetMemberName (
+ long id,
+ BSTR * pbstrName );
+ HRESULT GetNextDispID (
+ unsigned long grfdex,
+ long id,
+ long * pid );
+ HRESULT GetNameSpaceParent (
+ IUnknown * * ppunk );
+
+ //
+ // Raw methods provided by interface
+ //
+
+ virtual HRESULT __stdcall raw_GetDispID (
+ /*[in]*/ BSTR bstrName,
+ /*[in]*/ unsigned long grfdex,
+ /*[out]*/ long * pid ) = 0;
+ virtual HRESULT __stdcall raw_RemoteInvokeEx (
+ /*[in]*/ long id,
+ /*[in]*/ unsigned long lcid,
+ /*[in]*/ unsigned long dwFlags,
+ /*[in]*/ struct DISPPARAMS * pdp,
+ /*[out]*/ VARIANT * pvarRes,
+ /*[out]*/ struct EXCEPINFO * pei,
+ /*[in]*/ struct IServiceProvider * pspCaller,
+ /*[in]*/ unsigned int cvarRefArg,
+ /*[in]*/ unsigned int * rgiRefArg,
+ /*[in,out]*/ VARIANT * rgvarRefArg ) = 0;
+ virtual HRESULT __stdcall raw_DeleteMemberByName (
+ /*[in]*/ BSTR bstrName,
+ /*[in]*/ unsigned long grfdex ) = 0;
+ virtual HRESULT __stdcall raw_DeleteMemberByDispID (
+ /*[in]*/ long id ) = 0;
+ virtual HRESULT __stdcall raw_GetMemberProperties (
+ /*[in]*/ long id,
+ /*[in]*/ unsigned long grfdexFetch,
+ /*[out]*/ unsigned long * pgrfdex ) = 0;
+ virtual HRESULT __stdcall raw_GetMemberName (
+ /*[in]*/ long id,
+ /*[out]*/ BSTR * pbstrName ) = 0;
+ virtual HRESULT __stdcall raw_GetNextDispID (
+ /*[in]*/ unsigned long grfdex,
+ /*[in]*/ long id,
+ /*[out]*/ long * pid ) = 0;
+ virtual HRESULT __stdcall raw_GetNameSpaceParent (
+ /*[out]*/ IUnknown * * ppunk ) = 0;
+};
+
+struct __declspec(uuid("d27cdb72-ae6d-11cf-96b8-444553540000"))
+IFlashObjectInterface : IDispatchEx
+{};
+
+struct __declspec(uuid("d27cdb71-ae6d-11cf-96b8-444553540000"))
+FlashObjectInterface;
+ // [ default ] interface IFlashObjectInterface
+
+} // namespace ShockwaveFlashObjects
+
+#pragma pack(pop)
+
+//////////////////////////////////////////////////////////////////////////
+// FlashSink - Receives flash events
+
+namespace Sexy
+{
+
+class FlashSink : public ShockwaveFlashObjects::_IShockwaveFlashEvents
+{
+public:
+ LPCONNECTIONPOINT mConnectionPoint;
+ DWORD mCookie;
+ int mRefCount;
+ FlashWidget* mFlashWidget;
+
+public:
+ FlashSink()
+ {
+ mCookie = 0;
+ mConnectionPoint = NULL;
+ mRefCount = 0;
+ mFlashWidget = NULL;
+ }
+
+ virtual ~FlashSink()
+ {
+ mFlashWidget->mCOMCount--;
+ }
+
+ HRESULT Init(FlashWidget* theFlashWidget)
+ {
+ mFlashWidget = theFlashWidget;
+ mFlashWidget->mCOMCount++;
+
+ HRESULT aResult = NOERROR;
+ LPCONNECTIONPOINTCONTAINER aConnectionPoint = NULL;
+
+ if ((mFlashWidget->mFlashInterface->QueryInterface(IID_IConnectionPointContainer, (void**) &aConnectionPoint) == S_OK) &&
+ (aConnectionPoint->FindConnectionPoint(__uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents), &mConnectionPoint) == S_OK))
+ {
+ IDispatch* aDispatch = NULL;
+ QueryInterface(__uuidof(IDispatch), (void**) &aDispatch);
+ if (aDispatch != NULL)
+ {
+ aResult = mConnectionPoint->Advise((LPUNKNOWN)aDispatch, &mCookie);
+ aDispatch->Release();
+ }
+ }
+
+ if (aConnectionPoint != NULL)
+ aConnectionPoint->Release();
+
+ return aResult;
+ }
+
+ HRESULT Shutdown()
+ {
+ HRESULT aResult = S_OK;
+
+ if (mConnectionPoint)
+ {
+ if (mCookie)
+ {
+ aResult = mConnectionPoint->Unadvise(mCookie);
+ mCookie = 0;
+ }
+
+ mConnectionPoint->Release();
+ mConnectionPoint = NULL;
+ }
+
+ return aResult;
+ }
+
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppv)
+ {
+ *ppv = NULL;
+
+ if (riid == IID_IUnknown)
+ {
+ *ppv = (LPUNKNOWN)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IDispatch)
+ {
+ *ppv = (IDispatch*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == __uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents))
+ {
+ *ppv = (ShockwaveFlashObjects::_IShockwaveFlashEvents*) this;
+ AddRef();
+ return S_OK;
+ }
+ else
+ {
+ return E_NOTIMPL;
+ }
+ }
+
+ ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return ++mRefCount;
+ }
+
+ ULONG STDMETHODCALLTYPE Release()
+ {
+ int aRefCount = --mRefCount;
+ if (aRefCount == 0)
+ delete this;
+
+ return aRefCount;
+ }
+
+ // IDispatch method
+ virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* pctinfo)
+ { return E_NOTIMPL; }
+
+ virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
+ UINT cNames, LCID lcid,DISPID* rgDispId)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
+ WORD wFlags, ::DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult,
+ ::EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr)
+ {
+ switch(dispIdMember)
+ {
+ case 0x7a6:
+ break;
+ case 0x96:
+ if ((pDispParams->cArgs == 2) &&
+ (pDispParams->rgvarg[0].vt == VT_BSTR) &&
+ (pDispParams->rgvarg[1].vt == VT_BSTR))
+ {
+ FSCommand(pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal);
+ }
+ break;
+ case DISPID_READYSTATECHANGE:
+ break;
+ default:
+ return DISP_E_MEMBERNOTFOUND;
+ }
+
+ return NOERROR;
+ }
+
+ HRESULT OnReadyStateChange (long newState)
+ {
+ return S_OK;
+ }
+
+ HRESULT OnProgress(long percentDone )
+ {
+ return S_OK;
+ }
+
+ HRESULT FSCommand (_bstr_t command, _bstr_t args)
+ {
+ if (mFlashWidget->mFlashListener != NULL)
+ mFlashWidget->mFlashListener->FlashCommand(mFlashWidget->mId, (char*) command, (char*) args);
+ return S_OK;
+ }
+};
+
+}
+
+using namespace ShockwaveFlashObjects;
+
+//////////////////////////////////////////////////////////////////////////
+// ControlSite - container that holds the flash control
+
+namespace Sexy
+{
+
+class ControlSite :
+ public IOleInPlaceSiteWindowless,
+ public IOleClientSite
+{
+public:
+ int mRefCount;
+ FlashWidget* mFlashWidget;
+
+public:
+ ControlSite()
+ {
+ mRefCount = 0;
+ mFlashWidget = NULL;
+ }
+
+ virtual ~ControlSite()
+ {
+ if (mFlashWidget != NULL)
+ mFlashWidget->mCOMCount--;
+ }
+
+ void Init(FlashWidget* theFlashWidget)
+ {
+ mFlashWidget = theFlashWidget;
+ mFlashWidget->mCOMCount++;
+ }
+
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppv)
+ {
+ *ppv = NULL;
+
+ if (riid == IID_IUnknown)
+ {
+ *ppv = (IUnknown*) (IOleWindow*) this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IOleWindow)
+ {
+ *ppv = (IOleWindow*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IOleInPlaceSite)
+ {
+ *ppv = (IOleInPlaceSite*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IOleInPlaceSiteEx)
+ {
+ *ppv = (IOleInPlaceSiteEx*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IOleInPlaceSiteWindowless)
+ {
+ *ppv = (IOleInPlaceSiteWindowless*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == IID_IOleClientSite)
+ {
+ *ppv = (IOleClientSite*)this;
+ AddRef();
+ return S_OK;
+ }
+ else if (riid == __uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents))
+ {
+ *ppv = (ShockwaveFlashObjects::_IShockwaveFlashEvents*) this;
+ AddRef();
+ return S_OK;
+ }
+ else
+ {
+ return E_NOTIMPL;
+ }
+ }
+
+ ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return ++mRefCount;
+ }
+
+ ULONG STDMETHODCALLTYPE Release()
+ {
+ int aRefCount = --mRefCount;
+ if (aRefCount == 0)
+ delete this;
+
+ return aRefCount;
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+
+ virtual HRESULT STDMETHODCALLTYPE SaveObject(void)
+ {
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker,IMoniker** ppmk )
+ {
+ *ppmk = NULL;
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetContainer(IOleContainer ** theContainerP)
+ {
+ //return QueryInterface(__uuidof(IOleContainer), (void**) theContainerP);
+ return E_NOINTERFACE;
+ }
+
+
+ virtual HRESULT STDMETHODCALLTYPE ShowObject(void)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE OnShowWindow(BOOL)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE RequestNewObjectLayout(void)
+ {
+ return E_NOTIMPL;
+ }
+ //
+
+
+ HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(/* [in] */ BOOL fEnterMode)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetWindow(/* [out] */ HWND __RPC_FAR* theWnndow)
+ {
+ return E_FAIL;
+
+ //*theWnndow = NULL;
+ //*theWnndow = gSexyAppBase->mHWnd;
+ //return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE CanInPlaceActivate(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnInPlaceActivate(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnUIActivate(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE GetWindowContext(/* [out] */ IOleInPlaceFrame __RPC_FAR *__RPC_FAR *ppFrame, /* [out] */ IOleInPlaceUIWindow __RPC_FAR *__RPC_FAR *ppDoc, /* [out] */ LPRECT lprcPosRect, /* [out] */ LPRECT lprcClipRect, /* [out][in] */ LPOLEINPLACEFRAMEINFO lpFrameInfo)
+ {
+ RECT aRect = mFlashWidget->GetRect().ToRECT();
+
+ *lprcPosRect = aRect;
+ *lprcClipRect = aRect;
+
+ *ppFrame = NULL;
+ QueryInterface(__uuidof(IOleInPlaceFrame), (void**) ppFrame);
+ *ppDoc = NULL;
+
+ lpFrameInfo->fMDIApp = FALSE;
+ lpFrameInfo->hwndFrame = NULL;
+ lpFrameInfo->haccel = NULL;
+ lpFrameInfo->cAccelEntries = 0;
+
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE Scroll(/* [in] */ SIZE scrollExtant)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnUIDeactivate(/* [in] */ BOOL fUndoable)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE DiscardUndoState(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE DeactivateAndUndo(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnPosRectChange(/* [in] */ LPCRECT lprcPosRect)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE OnInPlaceActivateEx(/* [out] */ BOOL __RPC_FAR *pfNoRedraw, /* [in] */ DWORD dwFlags)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE OnInPlaceDeactivateEx(/* [in] */ BOOL fNoRedraw)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE RequestUIActivate(void)
+ {
+ return S_FALSE;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE CanWindowlessActivate(void)
+ {
+ // Allow windowless activation?
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE GetCapture(void)
+ {
+ // TODO capture the mouse for the object
+ return S_FALSE;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE SetCapture(/* [in] */ BOOL fCapture)
+ {
+ // TODO capture the mouse for the object
+ return S_FALSE;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE GetFocus(void)
+ {
+ return S_OK;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE SetFocus(/* [in] */ BOOL fFocus)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetDC(/* [in] */ LPCRECT pRect, /* [in] */ DWORD grfFlags, /* [out] */ HDC __RPC_FAR *phDC)
+ {
+ return E_INVALIDARG;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE ReleaseDC(/* [in] */ HDC hDC)
+ {
+ return E_INVALIDARG;
+ }
+
+
+ HRESULT STDMETHODCALLTYPE InvalidateRect(/* [in] */ LPCRECT pRect, /* [in] */ BOOL fErase)
+ {
+ if (pRect == NULL)
+ {
+ mFlashWidget->mDirtyRect = mFlashWidget->GetRect();
+ mFlashWidget->mFlashDirty = true;
+ }
+ else if (!mFlashWidget->mFlashDirty)
+ {
+ mFlashWidget->mDirtyRect = Rect(pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top);
+ mFlashWidget->mFlashDirty = true;
+ }
+ else
+ {
+ mFlashWidget->mDirtyRect = mFlashWidget->mDirtyRect.Union(Rect(pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top));
+ }
+
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE InvalidateRgn(/* [in] */ HRGN hRGN, /* [in] */ BOOL fErase)
+ {
+ mFlashWidget->mDirtyRect = mFlashWidget->GetRect();
+ mFlashWidget->mFlashDirty = true;
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE ScrollRect(/* [in] */ INT dx, /* [in] */ INT dy, /* [in] */ LPCRECT pRectScroll, /* [in] */ LPCRECT pRectClip)
+ {
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE AdjustRect(/* [out][in] */ LPRECT prc)
+ {
+ if (prc == NULL)
+ {
+ return E_INVALIDARG;
+ }
+
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE OnDefWindowMessage(/* [in] */ UINT msg, /* [in] */ WPARAM wParam, /* [in] */ LPARAM lParam, /* [out] */ LRESULT __RPC_FAR *plResult)
+ {
+ return S_FALSE;
+ }
+};
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+const CLSID CLSID_ShockwaveFlash =
+ { 0xD27CDB6E, 0xAE6D, 0x11cf, {0x96, 0xB8, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} };
+
+typedef HRESULT (__stdcall *DllGetClassObjectFunc)(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
+
+FlashWidget::FlashWidget(int theId, FlashListener* theFlashListener)
+{
+ HRESULT aResult;
+
+ mState = STATE_IDLE;
+
+ mCurCursor = CURSOR_POINTER;
+ mCurOverrideCursor = NULL;
+
+ mCOMCount = 0;
+ mPauseCount = 0;
+ mAutoPause = true;
+ mHasLostFocus = !gSexyAppBase->mHasFocus;
+ mFlashDirty = true;
+
+ mBkgColor.mAlpha = 0;
+ mId = theId;
+ mFlashListener = theFlashListener;
+
+ mFlashSink = NULL;
+
+ mImage = NULL;
+ mFlashInterface = NULL;
+ mOleObject = NULL;
+ mWindowlessObject = NULL;
+
+ mBkgImage = NULL;
+ mFlashLibHandle = NULL;
+
+ CoInitialize(NULL);
+
+ mControlSite = new ControlSite();
+ mControlSite->AddRef();
+ mControlSite->Init(this);
+
+ mFlashLibHandle = LoadLibraryA("flash.ocx");
+ if (mFlashLibHandle != NULL)
+ {
+ IClassFactory* aClassFactory = NULL;
+ DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc) GetProcAddress(mFlashLibHandle, "DllGetClassObject");
+ aResult = aDllGetClassObjectFunc(CLSID_ShockwaveFlash, IID_IClassFactory, (void**)&aClassFactory);
+ aClassFactory->CreateInstance(NULL, IID_IOleObject, (void**)&mOleObject);
+ aClassFactory->Release();
+ }
+ else
+ {
+ CoCreateInstance(CLSID_ShockwaveFlash, NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_IOleObject,
+ (void**)&mOleObject);
+ }
+
+ IOleClientSite* aClientSite = NULL;
+ mControlSite->QueryInterface(__uuidof(IOleClientSite), (void**) &aClientSite);
+ mOleObject->SetClientSite(aClientSite);
+
+ mOleObject->QueryInterface(__uuidof(IShockwaveFlash), (LPVOID*) &mFlashInterface);
+ _bstr_t aTrans = "Transparent";
+ mFlashInterface->put_WMode(aTrans);
+
+ aResult = mOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, aClientSite, 0, NULL, NULL);
+ aClientSite->Release();
+
+ mOleObject->QueryInterface(__uuidof(IOleInPlaceObjectWindowless), (LPVOID*) &mWindowlessObject);
+
+ mFlashSink = new FlashSink();
+ mFlashSink->AddRef();
+ mFlashSink->Init(this);
+}
+
+FlashWidget::~FlashWidget()
+{
+ CleanupImages();
+
+ if (mWindowlessObject != NULL)
+ mWindowlessObject->Release();
+ if (mFlashInterface != NULL)
+ mFlashInterface->Release();
+
+ if (mFlashSink != NULL)
+ {
+ mFlashSink->Shutdown();
+ mFlashSink->Release();
+ }
+
+ mOleObject->Close(OLECLOSE_NOSAVE);
+
+ if (mOleObject != NULL)
+ mOleObject->Release();
+
+ if (mControlSite != NULL)
+ mControlSite->Release();
+
+ // Make sure all our COM objects were actually destroyed
+ DBG_ASSERTE(mCOMCount == 0);
+
+ if (mFlashLibHandle != NULL)
+ FreeLibrary(mFlashLibHandle);
+}
+
+double FlashWidget::GetFlashVersion()
+{
+ CoInitialize(NULL);
+
+ IOleObject* anOleObject = NULL;
+ if (FAILED(CoCreateInstance(CLSID_ShockwaveFlash, NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_IOleObject,
+ (void**) &anOleObject)))
+ return 0.0;
+
+ IShockwaveFlash* aFlashInterface = NULL;
+ if (FAILED(anOleObject->QueryInterface(__uuidof(IShockwaveFlash), (LPVOID*) &aFlashInterface)))
+ return 0.0;
+
+ long aVersion = 0;
+ aFlashInterface->FlashVersion(&aVersion);
+
+ aFlashInterface->Release();
+ anOleObject->Release();
+
+ return aVersion / 65536.0;
+}
+
+void FlashWidget::CleanupImages()
+{
+ if (mImage != NULL)
+ {
+ delete mImage;
+ mImage = NULL;
+ }
+}
+
+void FlashWidget::RebuildImages()
+{
+ CleanupImages();
+
+ mImage = new DDImage(gSexyAppBase->mDDInterface);
+ mImage->Create(mWidth, mHeight);
+ mImage->SetImageMode(false, false);
+}
+
+void FlashWidget::CheckCursor()
+{
+ HCURSOR aCursor = GetCursor();
+ if (aCursor == ::LoadCursor(NULL, IDC_ARROW))
+ {
+ mCurCursor = CURSOR_POINTER;
+ gSexyAppBase->mOverrideCursor = NULL;
+ gSexyAppBase->SetCursor(mCurCursor);
+ }
+ else if (aCursor != NULL)
+ {
+ gSexyAppBase->mOverrideCursor = aCursor;
+ mCurCursor = CURSOR_HAND;
+ gSexyAppBase->SetCursor(mCurCursor);
+ }
+}
+
+void FlashWidget::DrawFlashBackground(Graphics* g)
+{
+ if (mBkgColor.mAlpha != 0)
+ {
+ g->SetColor(mBkgColor);
+ g->FillRect(0, 0, mWidth, mHeight);
+ }
+
+ if (mBkgImage != NULL)
+ {
+ if ((mBkgImageSrcRect.mWidth != 0) && (mBkgImageSrcRect.mHeight != 0))
+ g->DrawImage(mBkgImage, 0, 0, mBkgImageSrcRect);
+ else
+ g->DrawImage(mBkgImage, 0, 0);
+ }
+}
+
+bool FlashWidget::StartAnimation(const std::string& theFileName)
+{
+ std::string aFullPath = GetFullPath(theFileName);
+
+ _bstr_t bstr((char*) aFullPath.c_str());
+ mFlashInterface->put_Movie(bstr); // you have to change the path here
+ if ((mPauseCount == 0) && (mFlashInterface->Play() != S_OK))
+ return false;
+
+ if ((mWidgetManager != NULL) && (mIsOver))
+ MouseMove(mWidgetManager->mLastMouseX - mX, mWidgetManager->mLastMouseY - mY);
+
+ mState = STATE_PLAYING;
+ return true;
+}
+
+void FlashWidget::SetQuality(int theQuality)
+{
+ static char* aQualityNames[3] = {"Low", "Medium", "High"};
+
+ _bstr_t aNewStr = aQualityNames[theQuality];
+ mFlashInterface->put_Quality2(aNewStr);
+}
+
+void FlashWidget::Pause()
+{
+ mPauseCount++;
+
+ if (mState != STATE_STOPPED)
+ mState = STATE_IDLE;
+
+ if ((mPauseCount == 1) && (mFlashInterface != NULL) && (mState != STATE_STOPPED))
+ mFlashInterface->StopPlay();
+}
+
+void FlashWidget::Unpause()
+{
+ mPauseCount--;
+ if ((mPauseCount == 0) && (mFlashInterface != NULL) && (mState != STATE_STOPPED))
+ {
+ mState = STATE_PLAYING;
+ mFlashInterface->Play();
+ }
+}
+
+void FlashWidget::Rewind()
+{
+ if (mFlashInterface != NULL)
+ {
+ mFlashInterface->Rewind();
+ mFlashInterface->Play();
+ }
+}
+
+void FlashWidget::GotoFrame(int theFrameNum)
+{
+ if (mFlashInterface != NULL)
+ {
+ mFlashInterface->GotoFrame(theFrameNum);
+ mFlashInterface->Play();
+ }
+}
+
+void FlashWidget::Back()
+{
+ if (mFlashInterface != NULL)
+ {
+ mFlashInterface->Back();
+ mFlashInterface->Play();
+ }
+}
+
+void FlashWidget::Forward()
+{
+ if (mFlashInterface != NULL)
+ {
+ mFlashInterface->Forward();
+ mFlashInterface->Play();
+ }
+}
+
+bool FlashWidget::IsPlaying()
+{
+ VARIANT_BOOL aBool = 0;
+ if (mFlashInterface != NULL)
+ mFlashInterface->IsPlaying(&aBool);
+ return aBool != 0;
+}
+
+int FlashWidget::GetCurrentFrame()
+{
+ long aCurrentFrame = -1;
+ if (mFlashInterface != NULL)
+ mFlashInterface->CurrentFrame(&aCurrentFrame);
+ return aCurrentFrame;
+}
+
+std::string FlashWidget::GetCurrentLabel(const std::string& theTimeline)
+{
+ BSTR aBStr = L"";
+ if (mFlashInterface != NULL)
+ mFlashInterface->TCurrentLabel(_bstr_t(theTimeline.c_str()), &aBStr);
+ return (const char*) _bstr_t(aBStr);
+}
+
+void FlashWidget::CallFrame(const std::string& theTimeline, int theFrameNum)
+{
+ if (mFlashInterface != NULL)
+ mFlashInterface->TCallFrame(_bstr_t(theTimeline.c_str()), theFrameNum);
+}
+
+void FlashWidget::CallLabel(const std::string& theTimeline, const std::string& theLabel)
+{
+ if (mFlashInterface != NULL)
+ mFlashInterface->TCallLabel(_bstr_t(theTimeline.c_str()), _bstr_t(theLabel.c_str()));
+}
+
+std::string FlashWidget::GetVariable(const std::string& theName)
+{
+ BSTR aBStr = L"";
+ if (mFlashInterface != NULL)
+ mFlashInterface->GetVariable(_bstr_t(theName.c_str()), &aBStr);
+ return (const char*) _bstr_t(aBStr);
+}
+
+void FlashWidget::SetVariable(const std::string& theName, const std::string& theValue)
+{
+ if (mFlashInterface != NULL)
+ mFlashInterface->SetVariable(_bstr_t(theName.c_str()), _bstr_t(theValue.c_str()));
+}
+
+void FlashWidget::Update()
+{
+ if (mAutoPause)
+ {
+ if (!gSexyAppBase->mHasFocus)
+ {
+ if (!mHasLostFocus)
+ {
+ if (mAutoPause)
+ Pause();
+ mHasLostFocus = true;
+ }
+
+ return;
+ }
+ else
+ {
+ if (mHasLostFocus)
+ {
+ if (mAutoPause)
+ Unpause();
+ mHasLostFocus = false;
+ }
+ }
+ }
+
+ if (mState == STATE_PLAYING)
+ {
+ VARIANT_BOOL isPlaying = 0;
+ mFlashInterface->IsPlaying(&isPlaying);
+ if (!isPlaying)
+ {
+ mState = STATE_STOPPED;
+ if ((mFlashListener != NULL) && (mPauseCount == 0))
+ mFlashListener->FlashAnimEnded(mId);
+ }
+ }
+
+ if (mFlashDirty)
+ MarkDirty();
+}
+
+void FlashWidget::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Widget::Resize(theX, theY, theWidth, theHeight);
+
+ mDirtyRect = Rect(theX, theY, theWidth, theHeight);
+
+ RebuildImages();
+
+ IOleInPlaceObject* anInPlaceObject = NULL;
+ mOleObject->QueryInterface(__uuidof(IOleInPlaceObject), (LPVOID*) &anInPlaceObject);
+
+ if (anInPlaceObject != NULL)
+ {
+ RECT aRect = GetRect().ToRECT();
+ anInPlaceObject->SetObjectRects(&aRect, &aRect);
+ anInPlaceObject->Release();
+ }
+}
+
+void FlashWidget::Draw(Graphics* g)
+{
+ if (mFlashDirty)
+ {
+ Graphics anImageG(mImage);
+ DrawFlashBackground(&anImageG);
+
+ LPDIRECTDRAWSURFACE aSurface = mImage->GetSurface();
+ if (aSurface == NULL)
+ return;
+
+ HDC aDC = NULL;
+ if (aSurface->GetDC(&aDC) != S_OK)
+ return;
+
+ IViewObject* aViewObject = NULL;
+ mFlashInterface->QueryInterface(IID_IViewObject, (LPVOID*) &aViewObject);
+ if (aViewObject != NULL)
+ {
+ RECTL aRect = {0, 0, mWidth, mHeight};
+
+ Point anAbsPos = GetAbsPos();
+
+ HRGN aRgn = CreateRectRgn(mDirtyRect.mX - anAbsPos.mX, mDirtyRect.mY - anAbsPos.mY,
+ mDirtyRect.mX + mDirtyRect.mWidth - anAbsPos.mX,
+ mDirtyRect.mY + mDirtyRect.mHeight - anAbsPos.mY);
+ SelectClipRgn(aDC, aRgn);
+ DeleteObject(aRgn);
+
+ aViewObject->Draw(DVASPECT_CONTENT, 1,
+ NULL, NULL, NULL, aDC, &aRect, NULL, NULL,
+ 0);
+
+ aViewObject->Release();
+ }
+
+ aSurface->ReleaseDC(aDC);
+
+ mFlashDirty = false;
+ }
+
+ g->DrawImage(mImage, 0, 0);
+}
+
+void FlashWidget::MouseMove(int x, int y)
+{
+ Widget::MouseMove(x, y);
+
+ LRESULT aResult;
+ Point anAbsPos = GetAbsPos();
+ mWindowlessObject->OnWindowMessage(WM_MOUSEMOVE, 0, MAKELPARAM(x + anAbsPos.mX, y + anAbsPos.mY), &aResult);
+
+ if (mIsOver)
+ CheckCursor();
+}
+
+void FlashWidget::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ if (theBtnNum == 0)
+ {
+ LRESULT aResult;
+ Point anAbsPos = GetAbsPos();
+ mWindowlessObject->OnWindowMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x + anAbsPos.mX, y + anAbsPos.mY), &aResult);
+ CheckCursor();
+ }
+}
+
+void FlashWidget::MouseUp(int x, int y, int theBtnNum, int theClickCount)
+{
+ if (theBtnNum == 0)
+ {
+ LRESULT aResult;
+ Point anAbsPos = GetAbsPos();
+ mWindowlessObject->OnWindowMessage(WM_LBUTTONUP, 0, MAKELPARAM(x + anAbsPos.mX, y + anAbsPos.mY), &aResult);
+ CheckCursor();
+ }
+}
+
+void FlashWidget::MouseDrag(int x, int y)
+{
+ if (mWidgetManager->IsLeftButtonDown())
+ {
+ LRESULT aResult;
+ Point anAbsPos = GetAbsPos();
+ mWindowlessObject->OnWindowMessage(WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(x + anAbsPos.mX, y + anAbsPos.mY), &aResult);
+ CheckCursor();
+ }
+}
+
+void FlashWidget::MouseLeave()
+{
+ Widget::MouseLeave();
+
+ // To prevent Flash control from setting our cursor if it thinks
+ // our mouse is still over something
+ MouseMove(-1, -1);
+
+ gSexyAppBase->mOverrideCursor = NULL;
+ gSexyAppBase->SetCursor(CURSOR_POINTER);
+}
+
+void FlashWidget::SysColorChanged()
+{
+ mFlashDirty = true;
+ mDirtyRect = GetRect();
+
+ MarkDirty();
+}
diff --git a/osframework/source/SexyAppFramework/FlashWidget.h b/osframework/source/SexyAppFramework/FlashWidget.h
new file mode 100644
index 0000000..4362305
--- /dev/null
+++ b/osframework/source/SexyAppFramework/FlashWidget.h
@@ -0,0 +1,123 @@
+#ifndef __FLASHWIDGET_H__
+#define __FLASHWIDGET_H__
+
+#include "Common.h"
+#include "Widget.h"
+
+struct IOleObject;
+struct IOleInPlaceObjectWindowless;
+
+namespace ShockwaveFlashObjects
+{
+ struct IShockwaveFlash;
+}
+
+namespace Sexy
+{
+
+class Image;
+class FlashSink;
+class MemoryImage;
+class DDImage;
+class ControlSite;
+
+class FlashListener
+{
+public:
+ virtual void FlashAnimEnded(int theId) {}
+ virtual void FlashCommand(int theId, const std::string& theCommand, const std::string& theParam) {}
+};
+
+class FlashWidget : public Widget
+{
+public:
+ enum
+ {
+ STATE_IDLE,
+ STATE_PLAYING,
+ STATE_STOPPED
+ };
+
+ enum
+ {
+ QUALITY_LOW,
+ QUALITY_MEDIUM,
+ QUALITY_HIGH
+ };
+
+public:
+ int mState;
+ int mId;
+ FlashListener* mFlashListener;
+ HMODULE mFlashLibHandle;
+
+ ControlSite* mControlSite;
+ FlashSink* mFlashSink;
+ ShockwaveFlashObjects::IShockwaveFlash* mFlashInterface;
+ IOleObject* mOleObject;
+ IOleInPlaceObjectWindowless* mWindowlessObject;
+
+ int mCOMCount;
+ DDImage* mImage;
+ int mPauseCount;
+ bool mHasLostFocus;
+
+ Rect mDirtyRect;
+ bool mFlashDirty;
+
+ int mCurCursor;
+ HCURSOR mCurOverrideCursor;
+
+ bool mAutoPause;
+ Image* mBkgImage;
+ Rect mBkgImageSrcRect;
+ Color mBkgColor;
+
+public:
+ void CleanupImages();
+ void RebuildImages();
+ void CheckCursor();
+
+protected:
+ virtual void DrawFlashBackground(Graphics* g);
+
+public:
+ FlashWidget(int theId, FlashListener* theFlashListener);
+ ~FlashWidget();
+
+ static double GetFlashVersion();
+
+ bool StartAnimation(const std::string& theFileName);
+ void SetQuality(int theQuality);
+ void Pause();
+ void Unpause();
+ bool IsPlaying();
+ void Rewind();
+ void Back();
+ void Forward();
+ void GotoFrame(int theFrameNum);
+ int GetCurrentFrame();
+ std::string GetCurrentLabel(const std::string& theTimeline);
+ void CallFrame(const std::string& theTimeline, int theFrameNum);
+ void CallLabel(const std::string& theTimeline, const std::string& theLabel);
+ std::string GetVariable(const std::string& theName);
+ void SetVariable(const std::string& theName, const std::string& theValue);
+
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+
+ virtual void Update();
+ virtual void Draw(Graphics* g);
+
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseMove(int x, int y);
+ virtual void MouseDrag(int x, int y);
+
+ virtual void MouseLeave();
+
+ virtual void SysColorChanged();
+};
+
+}
+
+#endif //__FLASHWIDGET_H__
diff --git a/osframework/source/SexyAppFramework/Font.cpp b/osframework/source/SexyAppFramework/Font.cpp
new file mode 100644
index 0000000..65e331b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Font.cpp
@@ -0,0 +1,74 @@
+#include "Font.h"
+#include "Image.h"
+
+using namespace Sexy;
+
+Font::Font()
+{
+ mAscent = 0;
+ mHeight = 0;
+ mAscentPadding = 0;
+ mLineSpacingOffset = 0;
+}
+
+Font::Font(const Font& theFont) :
+ mAscent(theFont.mAscent),
+ mHeight(theFont.mHeight),
+ mAscentPadding(theFont.mAscentPadding),
+ mLineSpacingOffset(theFont.mLineSpacingOffset)
+{
+}
+
+Font::~Font()
+{
+}
+
+int Font::GetAscent()
+{
+ return mAscent;
+}
+
+int Font::GetAscentPadding()
+{
+ return mAscentPadding;
+}
+
+int Font::GetDescent()
+{
+ return mHeight - mAscent;
+}
+
+int Font::GetHeight()
+{
+ return mHeight;
+}
+
+int Font::GetLineSpacingOffset()
+{
+ return mLineSpacingOffset;
+}
+
+int Font::GetLineSpacing()
+{
+ return mHeight + mLineSpacingOffset;
+}
+
+int Font::StringWidth(const SexyString& theString)
+{
+ return 0;
+}
+
+int Font::CharWidth(SexyChar theChar)
+{
+ SexyString aString(1, theChar);
+ return StringWidth(aString);
+}
+
+int Font::CharWidthKern(SexyChar theChar, SexyChar thePrevChar)
+{
+ return CharWidth(theChar);
+}
+
+void Font::DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect)
+{
+}
diff --git a/osframework/source/SexyAppFramework/Font.h b/osframework/source/SexyAppFramework/Font.h
new file mode 100644
index 0000000..debae94
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Font.h
@@ -0,0 +1,43 @@
+#ifndef __FONT_H__
+#define __FONT_H__
+
+#include "Common.h"
+#include "Rect.h"
+#include "Color.h"
+
+namespace Sexy
+{
+
+class Graphics;
+
+class Font
+{
+public:
+ int mAscent;
+ int mAscentPadding; // How much space is above the avg uppercase char
+ int mHeight;
+ int mLineSpacingOffset; // This plus height should get added between lines
+
+public:
+ Font();
+ Font(const Font& theFont);
+ virtual ~Font();
+
+ virtual int GetAscent();
+ virtual int GetAscentPadding();
+ virtual int GetDescent();
+ virtual int GetHeight();
+ virtual int GetLineSpacingOffset();
+ virtual int GetLineSpacing();
+ virtual int StringWidth(const SexyString& theString);
+ virtual int CharWidth(SexyChar theChar);
+ virtual int CharWidthKern(SexyChar theChar, SexyChar thePrevChar);
+
+ virtual void DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect);
+
+ virtual Font* Duplicate() = NULL;
+};
+
+}
+
+#endif //__FONT_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/GENERIC_DrawLineAA.inc b/osframework/source/SexyAppFramework/GENERIC_DrawLineAA.inc
new file mode 100644
index 0000000..21e8cc1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/GENERIC_DrawLineAA.inc
@@ -0,0 +1,92 @@
+{
+ PIXEL_TYPE* aDestPixels = &aBits[aY0*STRIDE + aX0];
+ ulong anErrAcc = (ulong)(fabs(theStartX - aX0)*fabs(theStartY - aY0) * 0x10000);
+ if (dx >= dy) // mostly horizontal
+ {
+ //ulong anErrAdj = (((ulong)dy << 16) / (ulong)dx);
+ ulong anErrAdj = (ulong)(dyd / dxd * 0x10000);
+
+ uchar aWeight = 255 - (uchar)(anErrAcc >> 8);
+ uchar aWeight2 = (aWeight ^ 0xFF);
+
+ int a = CALC_WEIGHT_A(aWeight);
+ int oma = 256 - a;
+ PIXEL_TYPE dest = *aDestPixels;
+ BLEND_PIXEL(aDestPixels);
+ while (--dx)
+ {
+ anErrAcc += anErrAdj;
+ if (anErrAcc >= 0x10000)
+ {
+ anErrAcc &= 0xFFFF;
+ aDestPixels += STRIDE;
+ aY0++;
+ }
+ aDestPixels += aXinc;
+
+ uchar aWeight = 255 - (uchar)(anErrAcc >> 8);
+ uchar aWeight2 = (aWeight ^ 0xFF);
+
+ dest = *aDestPixels;
+ a = CALC_WEIGHT_A(aWeight);
+ oma = 256 - a;
+
+ BLEND_PIXEL(aDestPixels);
+ if (aY0 < mHeight-1)
+ {
+ dest = *(aDestPixels+STRIDE);
+ a = CALC_WEIGHT_A(aWeight2);
+ oma = 256 - a;
+ BLEND_PIXEL(aDestPixels+STRIDE);
+ }
+ }
+ }
+ else // mostly vertical
+ {
+ //ulong anErrAdj = (ulong)(((ulong)dx << 16) / (ulong)dy);
+ ulong anErrAdj = (ulong)(dxd / dyd * 0x10000);
+
+ uchar aWeight = 255 - (uchar)(anErrAcc >> 8);
+ uchar aWeight2 = (aWeight ^ 0xFF);
+
+ int a = CALC_WEIGHT_A(aWeight);
+ int oma = 256 - a;
+ PIXEL_TYPE dest = *aDestPixels;
+ BLEND_PIXEL(aDestPixels);
+ while (--dy)
+ {
+ anErrAcc += anErrAdj;
+ if (anErrAcc >= 0x10000)
+ {
+ anErrAcc &= 0xFFFF;
+ aDestPixels += aXinc;
+ aX0 += aXinc;
+ }
+ aDestPixels += STRIDE;
+
+ uchar aWeight = 255 - (uchar)(anErrAcc >> 8);
+ uchar aWeight2 = (aWeight ^ 0xFF);
+
+ dest = *aDestPixels;
+ int a = CALC_WEIGHT_A(aWeight);
+ int oma = 256 - a;
+
+ BLEND_PIXEL(aDestPixels);
+ if (aX0 < STRIDE-1)
+ {
+ a = CALC_WEIGHT_A(aWeight2);
+ oma = 256 - a;
+ dest = *(aDestPixels+aXinc);
+ BLEND_PIXEL(aDestPixels+aXinc);
+ }
+ }
+ }
+ aDestPixels = &aBits[aY1*STRIDE + aX1];
+ uchar aWeight = 255 - (uchar)(anErrAcc >> 8);
+ uchar aWeight2 = (aWeight ^ 0xFF);
+
+ int a = CALC_WEIGHT_A(aWeight);
+ int oma = 256 - a;
+ PIXEL_TYPE dest = *aDestPixels;
+ BLEND_PIXEL(aDestPixels);
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Graphics.cpp b/osframework/source/SexyAppFramework/Graphics.cpp
new file mode 100644
index 0000000..ccba9d5
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Graphics.cpp
@@ -0,0 +1,1356 @@
+#include "Graphics.h"
+#include "Image.h"
+#include "Font.h"
+#include "DDImage.h"
+#include "MemoryImage.h"
+#include "Rect.h"
+#include "Debug.h"
+#include "SexyMatrix.h"
+#include <math.h>
+
+using namespace Sexy;
+
+Image GraphicsState::mStaticImage;
+const Point* Graphics::mPFPoints;
+
+//////////////////////////////////////////////////////////////////////////
+
+void GraphicsState::CopyStateFrom(const GraphicsState* theState)
+{
+ mDestImage = theState->mDestImage;
+ mTransX = theState->mTransX;
+ mTransY = theState->mTransY;
+ mClipRect = theState->mClipRect;
+ mFont = theState->mFont;
+ mColor = theState->mColor;
+ mDrawMode = theState->mDrawMode;
+ mColorizeImages = theState->mColorizeImages;
+ mFastStretch = theState->mFastStretch;
+ mWriteColoredString = theState->mWriteColoredString;
+ mLinearBlend = theState->mLinearBlend;
+ mScaleX = theState->mScaleX;
+ mScaleY = theState->mScaleY;
+ mScaleOrigX = theState->mScaleOrigX;
+ mScaleOrigY = theState->mScaleOrigY;
+ mIs3D = theState->mIs3D;
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+Graphics::Graphics(const Graphics& theGraphics)
+{
+ CopyStateFrom(&theGraphics);
+}
+
+Graphics::Graphics(Image* theDestImage)
+{
+ mTransX = 0;
+ mTransY = 0;
+ mScaleX = 1;
+ mScaleY = 1;
+ mScaleOrigX = 0;
+ mScaleOrigY = 0;
+ mFont = NULL;
+ mDestImage = theDestImage;
+ mDrawMode = DRAWMODE_NORMAL;
+ mColorizeImages = false;
+ mFastStretch = false;
+ mWriteColoredString = true;
+ mLinearBlend = false;
+
+ if (mDestImage == NULL)
+ {
+ mDestImage = &mStaticImage;
+ mIs3D = false;
+ }
+ else
+ {
+ mIs3D = DDImage::Check3D(theDestImage);
+ }
+
+ mClipRect = Rect(0, 0, mDestImage->GetWidth(), mDestImage->GetHeight());
+}
+
+Graphics::~Graphics()
+{
+}
+
+void Graphics::PushState()
+{
+ mStateStack.push_back(GraphicsState());
+ mStateStack.back().CopyStateFrom(this);
+}
+
+void Graphics::PopState()
+{
+ DBG_ASSERTE(mStateStack.size() > 0);
+ if (mStateStack.size() > 0)
+ {
+ CopyStateFrom(&mStateStack.back());
+ mStateStack.pop_back();
+ }
+}
+
+Graphics* Graphics::Create()
+{
+ return new Graphics(*this);
+}
+
+Sexy::Font* Graphics::GetFont()
+{
+ return mFont;
+}
+
+void Graphics::SetFont(Sexy::Font* theFont)
+{
+ mFont = theFont;
+}
+
+void Graphics::SetColor(const Color& theColor)
+{
+ mColor = theColor;
+}
+
+const Color& Graphics::GetColor()
+{
+ return mColor;
+}
+
+void Graphics::SetDrawMode(int theDrawMode)
+{
+ mDrawMode = theDrawMode;
+}
+
+int Graphics::GetDrawMode()
+{
+ return mDrawMode;
+}
+
+void Graphics::SetColorizeImages(bool colorizeImages)
+{
+ mColorizeImages = colorizeImages;
+}
+
+bool Graphics::GetColorizeImages()
+{
+ return mColorizeImages;
+}
+
+void Graphics::SetFastStretch(bool fastStretch)
+{
+ mFastStretch = fastStretch;
+}
+
+bool Graphics::GetFastStretch()
+{
+ return mFastStretch;
+}
+
+void Graphics::SetLinearBlend(bool linear)
+{
+ mLinearBlend = linear;
+}
+
+bool Graphics::GetLinearBlend()
+{
+ return mLinearBlend;
+}
+
+void Graphics::ClearRect(int theX, int theY, int theWidth, int theHeight)
+{
+ Rect aDestRect = Rect(theX + mTransX, theY + mTransY, theWidth, theHeight).Intersection(mClipRect);
+ mDestImage->ClearRect(aDestRect);
+}
+
+void Graphics::ClearRect(const Rect& theRect)
+{
+ ClearRect(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+void Graphics::FillRect(int theX, int theY, int theWidth, int theHeight)
+{
+ if (mColor.mAlpha == 0)
+ return;
+
+ Rect aDestRect = Rect(theX + mTransX, theY + mTransY, theWidth, theHeight).Intersection(mClipRect);
+ mDestImage->FillRect(aDestRect, mColor, mDrawMode);
+}
+
+void Graphics::FillRect(const Rect& theRect)
+{
+ FillRect(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+void Graphics::DrawRect(int theX, int theY, int theWidth, int theHeight)
+{
+ if (mColor.mAlpha == 0)
+ return;
+
+ Rect aDestRect = Rect(theX + mTransX, theY + mTransY, theWidth, theHeight);
+ Rect aFullDestRect = Rect(theX + mTransX, theY + mTransY, theWidth + 1, theHeight + 1);
+ Rect aFullClippedRect = aFullDestRect.Intersection(mClipRect);
+
+ if (aFullDestRect == aFullClippedRect)
+ {
+ mDestImage->DrawRect(aDestRect, mColor, mDrawMode);
+ }
+ else
+ {
+ FillRect(theX, theY, theWidth + 1, 1);
+ FillRect(theX, theY + theHeight, theWidth + 1, 1);
+ FillRect(theX, theY + 1, 1, theHeight - 1);
+ FillRect(theX + theWidth, theY + 1, 1, theHeight - 1);
+
+ /*if (aClippedRect.mX == aDestRect.mX)
+ mDestImage->FillRect(Rect(aClippedRect.mX, aClippedRect.mY, 1, aClippedRect.mHeight), mColor, mDrawMode);
+ if (aClippedRect.mY == aDestRect.mY)
+ mDestImage->FillRect(Rect(aClippedRect.mX, aClippedRect.mY, aClippedRect.mWidth, 1), mColor, mDrawMode);
+ if (aClippedRect.mX + aClippedRect.mWidth == aDestRect.mX + aDestRect.mWidth)
+ mDestImage->FillRect(Rect(aClippedRect.mX + aClippedRect.mWidth, aClippedRect.mY, 1, aClippedRect.mHeight), mColor, mDrawMode);
+ if (aClippedRect.mY + aClippedRect.mHeight == aDestRect.mY + aDestRect.mHeight)
+ mDestImage->FillRect(Rect(aClippedRect.mX, aClippedRect.mY + aClippedRect.mHeight, aClippedRect.mWidth, 1), mColor, mDrawMode);*/
+ }
+}
+
+void Graphics::DrawRect(const Rect& theRect)
+{
+ DrawRect(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+int Graphics::PFCompareInd(const void* u, const void* v)
+{
+ return mPFPoints[*((int*) u)].mY <= mPFPoints[*((int*) v)].mY ? -1 : 1;
+}
+
+int Graphics::PFCompareActive(const void* u, const void* v)
+{
+ return ((Edge*) u)->mX <= ((Edge*) v)->mX ? -1 : 1;
+}
+
+void Graphics::PFDelete(int i) // remove edge i from active list
+{
+ int j;
+
+ for (j=0; j<mPFNumActiveEdges && mPFActiveEdgeList[j].i!=i; j++);
+ if (j>=mPFNumActiveEdges) return; /* edge not in active list; happens at aMinY*/
+
+ mPFNumActiveEdges--;
+ memcpy(&mPFActiveEdgeList[j], &mPFActiveEdgeList[j+1], (mPFNumActiveEdges-j)*sizeof mPFActiveEdgeList[0]);
+}
+
+void Graphics::PFInsert(int i, int y) // append edge i to end of active list
+{
+ int j;
+ double dx;
+ const Point *p, *q;
+
+ j = i<mPFNumVertices-1 ? i+1 : 0;
+ if (mPFPoints[i].mY < mPFPoints[j].mY)
+ {
+ p = &mPFPoints[i];
+ q = &mPFPoints[j];
+ }
+ else
+ {
+ p = &mPFPoints[j];
+ q = &mPFPoints[i];
+ }
+ /* initialize x position at intersection of edge with scanline y */
+ mPFActiveEdgeList[mPFNumActiveEdges].mDX = dx = (q->mX - p->mX)/(double) (q->mY - p->mY);
+ mPFActiveEdgeList[mPFNumActiveEdges].mX = dx*(y+0.5 - p->mY - mTransY) + p->mX + mTransX;
+ mPFActiveEdgeList[mPFNumActiveEdges].i = i;
+ mPFActiveEdgeList[mPFNumActiveEdges].b = p->mY - 1.0/dx * p->mX;
+ mPFNumActiveEdges++;
+}
+
+void Graphics::PolyFill(const Point *theVertexList, int theNumVertices, bool convex)
+{
+ if (convex && mDestImage->PolyFill3D(theVertexList,theNumVertices,&mClipRect,mColor,mDrawMode,mTransX,mTransY,convex))
+ return;
+
+ Span aSpans[MAX_TEMP_SPANS];
+ int aSpanPos = 0;
+
+ int k, y0, y1, y, i, j, xl, xr;
+ int *ind; /* list of vertex indices, sorted by mPFPoints[ind[j]].y */
+
+ int aMinX = mClipRect.mX;
+ int aMaxX = mClipRect.mX + mClipRect.mWidth - 1;
+ int aMinY = mClipRect.mY;
+ int aMaxY = mClipRect.mY + mClipRect.mHeight - 1;
+
+ mPFNumVertices = theNumVertices;
+ mPFPoints = theVertexList;
+
+ if (mPFNumVertices<=0) return;
+
+ ind = new int[mPFNumVertices];
+ mPFActiveEdgeList = new Edge[mPFNumVertices];
+
+ /* create y-sorted array of indices ind[k] into vertex list */
+ for (k=0; k<mPFNumVertices; k++)
+ ind[k] = k;
+ qsort(ind, mPFNumVertices, sizeof ind[0], PFCompareInd); /* sort ind by mPFPoints[ind[k]].y */
+
+ mPFNumActiveEdges = 0; /* start with empty active list */
+ k = 0; /* ind[k] is next vertex to process */
+ y0 = (int) max(aMinY, ceil(mPFPoints[ind[0]].mY-0.5 + mTransY)); /* ymin of polygon */
+ y1 = (int) min(aMaxY, floor(mPFPoints[ind[mPFNumVertices-1]].mY-0.5 + mTransY)); /* ymax of polygon */
+
+ for (y=y0; y<=y1; y++)
+ {
+ // step through scanlines
+ // scanline y is at y+.5 in continuous coordinates
+
+ // check vertices between previous scanline and current one, if any
+ for (; (k < mPFNumVertices) && (mPFPoints[ind[k]].mY + mTransY <= y + 0.5); k++)
+ {
+ // to simplify, if mPFPoints.mY=y+.5, pretend it's above
+ // invariant: y-.5 < mPFPoints[i].mY <= y+.5
+ i = ind[k];
+ // insert or delete edges before and after vertex i (i-1 to i,
+ // and i to i+1) from active list if they cross scanline y
+
+ j = i>0 ? i-1 : mPFNumVertices-1; // vertex previous to i
+ if (mPFPoints[j].mY + mTransY <= y-0.5) // old edge, remove from active list
+ PFDelete(j);
+ else if (mPFPoints[j].mY + mTransY > y+0.5) // new edge, add to active list
+ PFInsert(j, y);
+
+ j = i<mPFNumVertices-1 ? i+1 : 0; // vertex next after i
+ if (mPFPoints[j].mY + mTransY <= y-0.5) // old edge, remove from active list
+ PFDelete(i);
+ else if (mPFPoints[j].mY + mTransY > y+0.5) // new edge, add to active list
+ PFInsert(i, y);
+ }
+
+ // sort active edge list by active[j].mX
+ qsort(mPFActiveEdgeList, mPFNumActiveEdges, sizeof mPFActiveEdgeList[0], PFCompareActive);
+
+ // draw horizontal segments for scanline y
+ for (j = 0; j < mPFNumActiveEdges; j += 2)
+ { // draw horizontal segments
+ // span 'tween j & j+1 is inside, span tween j+1 & j+2 is outside
+ xl = (int) ceil(mPFActiveEdgeList[j].mX-0.5); // left end of span
+ if (xl<aMinX)
+ xl = aMinX;
+ xr = (int) floor(mPFActiveEdgeList[j+1].mX-0.5); // right end of span
+ if (xr>aMaxX)
+ xr = aMaxX;
+
+ if ((xl <= xr) && (aSpanPos < MAX_TEMP_SPANS))
+ {
+ Span* aSpan = &aSpans[aSpanPos++];
+ aSpan->mY = y;
+ aSpan->mX = xl;
+ aSpan->mWidth = xr - xl + 1;
+ }
+
+ mPFActiveEdgeList[j].mX += mPFActiveEdgeList[j].mDX; // increment edge coords
+ mPFActiveEdgeList[j+1].mX += mPFActiveEdgeList[j+1].mDX;
+ }
+ }
+
+ mDestImage->FillScanLines(aSpans, aSpanPos, mColor, mDrawMode);
+
+ delete ind;
+ delete mPFActiveEdgeList;
+}
+
+void Graphics::PolyFillAA(const Point *theVertexList, int theNumVertices, bool convex)
+{
+ if (convex && mDestImage->PolyFill3D(theVertexList,theNumVertices,&mClipRect,mColor,mDrawMode,mTransX,mTransY,convex))
+ return;
+
+ int i;
+
+ Span aSpans[MAX_TEMP_SPANS];
+ int aSpanPos = 0;
+
+ static BYTE aCoverageBuffer[256*256];
+ int aCoverWidth = 256, aCoverHeight = 256;
+ int aCoverLeft, aCoverRight, aCoverTop, aCoverBottom;
+
+ for (i = 0; i < theNumVertices; ++i)
+ {
+ const Point* aPt = &theVertexList[i];
+ if (i == 0)
+ {
+ aCoverLeft = aCoverRight = aPt->mX;
+ aCoverTop = aCoverBottom = aPt->mY;
+ }
+ else
+ {
+ aCoverLeft = min(aCoverLeft, aPt->mX);
+ aCoverRight = max(aCoverRight, aPt->mX);
+ aCoverTop = min(aCoverTop, aPt->mY);
+ aCoverBottom = max(aCoverBottom, aPt->mY);
+ }
+ }
+ BYTE* coverPtr = aCoverageBuffer;
+ if ((aCoverRight-aCoverLeft+1) > aCoverWidth || (aCoverBottom-aCoverTop+1) > aCoverHeight)
+ {
+ aCoverWidth = aCoverRight-aCoverLeft+1;
+ aCoverHeight = aCoverBottom-aCoverTop+1;
+ coverPtr = new BYTE[aCoverWidth*aCoverHeight];
+ }
+ memset(coverPtr, 0, aCoverWidth*aCoverHeight);
+
+ int k, y0, y1, y, j, xl, xr;
+ int *ind; /* list of vertex indices, sorted by mPFPoints[ind[j]].y */
+
+ int aMinX = mClipRect.mX;
+ int aMaxX = mClipRect.mX + mClipRect.mWidth - 1;
+ int aMinY = mClipRect.mY;
+ int aMaxY = mClipRect.mY + mClipRect.mHeight - 1;
+
+ mPFNumVertices = theNumVertices;
+ mPFPoints = theVertexList;
+
+ if (mPFNumVertices<=0) return;
+
+ ind = new int[mPFNumVertices];
+ mPFActiveEdgeList = new Edge[mPFNumVertices];
+
+ /* create y-sorted array of indices ind[k] into vertex list */
+ for (k=0; k<mPFNumVertices; k++)
+ ind[k] = k;
+ qsort(ind, mPFNumVertices, sizeof ind[0], PFCompareInd); /* sort ind by mPFPoints[ind[k]].y */
+
+ mPFNumActiveEdges = 0; /* start with empty active list */
+ k = 0; /* ind[k] is next vertex to process */
+ y0 = (int) max(aMinY, ceil(mPFPoints[ind[0]].mY-0.5 + mTransY)); /* ymin of polygon */
+ y1 = (int) min(aMaxY, floor(mPFPoints[ind[mPFNumVertices-1]].mY-0.5 + mTransY)); /* ymax of polygon */
+
+ for (y=y0; y<=y1; y++)
+ {
+ // step through scanlines
+ // scanline y is at y+.5 in continuous coordinates
+
+ // check vertices between previous scanline and current one, if any
+ for (; (k < mPFNumVertices) && (mPFPoints[ind[k]].mY + mTransY <= y + 0.5); k++)
+ {
+ // to simplify, if mPFPoints.mY=y+.5, pretend it's above
+ // invariant: y-.5 < mPFPoints[i].mY <= y+.5
+ i = ind[k];
+ // insert or delete edges before and after vertex i (i-1 to i,
+ // and i to i+1) from active list if they cross scanline y
+
+ j = i>0 ? i-1 : mPFNumVertices-1; // vertex previous to i
+ if (mPFPoints[j].mY + mTransY <= y-0.5) // old edge, remove from active list
+ PFDelete(j);
+ else if (mPFPoints[j].mY + mTransY > y+0.5) // new edge, add to active list
+ PFInsert(j, y);
+
+ j = i<mPFNumVertices-1 ? i+1 : 0; // vertex next after i
+ if (mPFPoints[j].mY + mTransY <= y-0.5) // old edge, remove from active list
+ PFDelete(i);
+ else if (mPFPoints[j].mY + mTransY > y+0.5) // new edge, add to active list
+ PFInsert(i, y);
+ }
+
+ // sort active edge list by active[j].mX
+ qsort(mPFActiveEdgeList, mPFNumActiveEdges, sizeof mPFActiveEdgeList[0], PFCompareActive);
+
+ // draw horizontal segments for scanline y
+ for (j = 0; j < mPFNumActiveEdges; j += 2)
+ { // draw horizontal segments
+ // span 'tween j & j+1 is inside, span tween j+1 & j+2 is outside
+ xl = (int) ceil(mPFActiveEdgeList[j].mX-0.5); // left end of span
+ int lErr = int((fabs((mPFActiveEdgeList[j].mX-0.5) - xl)) * 255);
+ if (xl<aMinX)
+ {
+ xl = aMinX;
+ lErr = 255;
+ }
+ xr = (int) floor(mPFActiveEdgeList[j+1].mX-0.5); // right end of span
+ int rErr = int((fabs((mPFActiveEdgeList[j+1].mX-0.5) - xr)) * 255);
+ if (xr>aMaxX)
+ {
+ xr = aMaxX;
+ rErr = 255;
+ }
+
+ if ((xl <= xr) && (aSpanPos < MAX_TEMP_SPANS))
+ {
+ Span* aSpan = &aSpans[aSpanPos++];
+ aSpan->mY = y;
+ aSpan->mX = xl;
+ aSpan->mWidth = xr - xl + 1;
+
+ BYTE* coverRow = coverPtr + (y - aCoverTop) * aCoverWidth;
+ if (xr == xl)
+ {
+ coverRow[xl-aCoverLeft] = min(255, coverRow[xl-aCoverLeft] + ((lErr*rErr)>>8));
+ }
+ else
+ {
+ if (fabs(mPFActiveEdgeList[j].mDX) > 1.0f) // mostly horizontal on the left edge
+ {
+ double m = 1.0 / mPFActiveEdgeList[j].mDX,
+ b = mPFActiveEdgeList[j].b,
+ c = fabs(mPFActiveEdgeList[j].mDX);
+ do
+ {
+ double _y = m * xl + b;
+ lErr = min(255, int(fabs((_y) - y - .5) * 255));
+ coverRow[xl-aCoverLeft] = min(255, coverRow[xl-aCoverLeft] + lErr);
+ xl++;
+ c -= 1.0;
+ } while (xl <= xr && c > 0);
+ }
+ else
+ {
+ coverRow[xl-aCoverLeft] = min(255, coverRow[xl-aCoverLeft] + lErr);
+ xl++;
+ }
+
+ if (fabs(mPFActiveEdgeList[j+1].mDX) > 1.0f) // mostly horizontal on the right edge
+ {
+ double m = 1.0 / mPFActiveEdgeList[j+1].mDX,
+ b = mPFActiveEdgeList[j+1].b,
+ c = fabs(mPFActiveEdgeList[j+1].mDX);
+ do
+ {
+ double _y = m * xr + b;
+ rErr = min(255, int(fabs((_y) - y - .5) * 255));
+ coverRow[xr-aCoverLeft] = min(255, coverRow[xr-aCoverLeft] + rErr);
+ xr--;
+ c -= 1.0;
+ } while (xr >= xl && c > 0);
+ }
+ else
+ {
+ coverRow[xr-aCoverLeft] = min(255, coverRow[xr-aCoverLeft] + rErr);
+ xr--;
+ }
+
+ if (xl <= xr)
+ memset(&coverRow[xl-aCoverLeft], 255, xr-xl+1);
+ }
+ }
+
+ mPFActiveEdgeList[j].mX += mPFActiveEdgeList[j].mDX; // increment edge coords
+ mPFActiveEdgeList[j+1].mX += mPFActiveEdgeList[j+1].mDX;
+ }
+ }
+
+ mDestImage->FillScanLinesWithCoverage(aSpans, aSpanPos, mColor, mDrawMode, coverPtr, aCoverLeft, aCoverTop, aCoverWidth, aCoverHeight);
+
+ if (coverPtr != aCoverageBuffer) delete[] coverPtr;
+ delete[] ind;
+ delete[] mPFActiveEdgeList;
+}
+
+
+bool Graphics::DrawLineClipHelper(double* theStartX, double* theStartY, double* theEndX, double* theEndY)
+{
+ double aStartX = *theStartX;
+ double aStartY = *theStartY;
+ double aEndX = *theEndX;
+ double aEndY = *theEndY;
+
+ // Clip X
+ if (aStartX > aEndX)
+ {
+ std::swap(aStartX,aEndX);
+ std::swap(aStartY,aEndY);
+ }
+
+ if (aStartX < mClipRect.mX)
+ {
+ if (aEndX < mClipRect.mX)
+ return false;
+
+ double aSlope = (aEndY - aStartY) / (aEndX - aStartX);
+ aStartY += (mClipRect.mX - aStartX ) * aSlope;
+ aStartX = mClipRect.mX;
+ }
+
+ if (aEndX >= mClipRect.mX + mClipRect.mWidth)
+ {
+ if (aStartX >= mClipRect.mX + mClipRect.mWidth)
+ return false;
+
+ double aSlope = (aEndY - aStartY) / (aEndX - aStartX);
+ aEndY += (mClipRect.mX + mClipRect.mWidth - 1 - aEndX) * aSlope;
+ aEndX = mClipRect.mX + mClipRect.mWidth - 1;
+ }
+
+ // Clip Y
+ if (aStartY > aEndY)
+ {
+ std::swap(aStartX,aEndX);
+ std::swap(aStartY,aEndY);
+ }
+
+
+ if (aStartY < mClipRect.mY)
+ {
+ if (aEndY < mClipRect.mY)
+ return false;
+
+ double aSlope = (aEndX - aStartX) / (aEndY - aStartY);
+ aStartX += (mClipRect.mY - aStartY ) * aSlope;
+
+ aStartY = mClipRect.mY;
+ }
+
+ if (aEndY >= mClipRect.mY + mClipRect.mHeight)
+ {
+ if (aStartY >= mClipRect.mY + mClipRect.mHeight)
+ return false;
+
+ double aSlope = (aEndX - aStartX) / (aEndY - aStartY);
+ aEndX += (mClipRect.mY + mClipRect.mHeight - 1 - aEndY) * aSlope;
+ aEndY = mClipRect.mY + mClipRect.mHeight - 1;
+ }
+
+ *theStartX = aStartX;
+ *theStartY = aStartY;
+ *theEndX = aEndX;
+ *theEndY = aEndY;
+
+ return true;
+}
+
+void Graphics::DrawLine(int theStartX, int theStartY, int theEndX, int theEndY)
+{
+ double aStartX = theStartX + mTransX;
+ double aStartY = theStartY + mTransY;
+ double aEndX = theEndX + mTransX;
+ double aEndY = theEndY + mTransY;
+
+ if (!DrawLineClipHelper(&aStartX, &aStartY, &aEndX, &aEndY))
+ return;
+
+ mDestImage->DrawLine(aStartX, aStartY, aEndX, aEndY, mColor, mDrawMode);
+}
+
+void Graphics::DrawLineAA(int theStartX, int theStartY, int theEndX, int theEndY)
+{
+ double aStartX = theStartX + mTransX;
+ double aStartY = theStartY + mTransY;
+ double aEndX = theEndX + mTransX;
+ double aEndY = theEndY + mTransY;
+
+ if (!DrawLineClipHelper(&aStartX, &aStartY, &aEndX, &aEndY))
+ return;
+
+ mDestImage->DrawLineAA(aStartX, aStartY, aEndX, aEndY, mColor, mDrawMode);
+}
+
+void Graphics::DrawString(const SexyString& theString, int theX, int theY)
+{
+ if (mFont != NULL)
+ mFont->DrawString(this, theX, theY, theString, mColor, mClipRect);
+}
+
+void Graphics::DrawImage(Sexy::Image* theImage, int theX, int theY)
+{
+ if (mScaleX!=1 || mScaleY!=1)
+ {
+ DrawImage(theImage,theX,theY,Rect(0,0,theImage->mWidth,theImage->mHeight));
+ return;
+ }
+
+ theX += mTransX;
+ theY += mTransY;
+
+ Rect aDestRect = Rect(theX, theY, theImage->GetWidth(), theImage->GetHeight()).Intersection(mClipRect);
+ Rect aSrcRect(aDestRect.mX - theX, aDestRect.mY - theY, aDestRect.mWidth, aDestRect.mHeight);
+
+ if ((aSrcRect.mWidth > 0) && (aSrcRect.mHeight > 0))
+ mDestImage->Blt(theImage, aDestRect.mX, aDestRect.mY, aSrcRect, mColorizeImages ? mColor : Color::White, mDrawMode);
+}
+
+void Graphics::DrawImage(Image* theImage, int theX, int theY, const Rect& theSrcRect)
+{
+ DBG_ASSERTE(theSrcRect.mX + theSrcRect.mWidth <= theImage->GetWidth());
+ DBG_ASSERTE(theSrcRect.mY + theSrcRect.mHeight <= theImage->GetHeight());
+
+ if ((theSrcRect.mX + theSrcRect.mWidth > theImage->GetWidth()) ||
+ (theSrcRect.mY + theSrcRect.mHeight > theImage->GetHeight()))
+ return;
+
+ theX += mTransX;
+ theY += mTransY;
+
+ if (mScaleX!=1 || mScaleY!=1)
+ {
+ Rect aDestRect(mScaleOrigX+floor((theX-mScaleOrigX)*mScaleX),mScaleOrigY+floor((theY-mScaleOrigY)*mScaleY),ceil(theSrcRect.mWidth*mScaleX),ceil(theSrcRect.mHeight*mScaleY));
+ mDestImage->StretchBlt(theImage, aDestRect, theSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, mFastStretch);
+ return;
+ }
+
+ Rect aDestRect = Rect(theX, theY, theSrcRect.mWidth, theSrcRect.mHeight).Intersection(mClipRect);
+ Rect aSrcRect(theSrcRect.mX + aDestRect.mX - theX, theSrcRect.mY + aDestRect.mY - theY, aDestRect.mWidth, aDestRect.mHeight);
+
+ if ((aSrcRect.mWidth > 0) && (aSrcRect.mHeight > 0))
+ mDestImage->Blt(theImage, aDestRect.mX, aDestRect.mY, aSrcRect, mColorizeImages ? mColor : Color::White, mDrawMode);
+}
+
+void Graphics::DrawImageMirror(Image* theImage, int theX, int theY, bool mirror)
+{
+ DrawImageMirror(theImage,theX,theY,Rect(0,0,theImage->mWidth,theImage->mHeight),mirror);
+}
+
+void Graphics::DrawImageMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, bool mirror)
+{
+ if (!mirror)
+ {
+ DrawImage(theImage, theX, theY, theSrcRect);
+ return;
+ }
+
+ theX += mTransX;
+ theY += mTransY;
+
+ DBG_ASSERTE(theSrcRect.mX + theSrcRect.mWidth <= theImage->GetWidth());
+ DBG_ASSERTE(theSrcRect.mY + theSrcRect.mHeight <= theImage->GetHeight());
+
+ if ((theSrcRect.mX + theSrcRect.mWidth > theImage->GetWidth()) ||
+ (theSrcRect.mY + theSrcRect.mHeight > theImage->GetHeight()))
+ return;
+
+ Rect aDestRect = Rect(theX, theY, theSrcRect.mWidth, theSrcRect.mHeight).Intersection(mClipRect);
+
+ int aTotalClip = theSrcRect.mWidth - aDestRect.mWidth;
+ int aLeftClip = aDestRect.mX - theX;
+ int aRightClip = aTotalClip-aLeftClip;
+
+ Rect aSrcRect(theSrcRect.mX + aRightClip, theSrcRect.mY + aDestRect.mY - theY, aDestRect.mWidth, aDestRect.mHeight);
+
+ if ((aSrcRect.mWidth > 0) && (aSrcRect.mHeight > 0))
+ mDestImage->BltMirror(theImage, aDestRect.mX, aDestRect.mY, aSrcRect, mColorizeImages ? mColor : Color::White, mDrawMode);
+}
+
+void Graphics::DrawImageMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, bool mirror)
+{
+ if (!mirror)
+ {
+ DrawImage(theImage,theDestRect,theSrcRect);
+ return;
+ }
+
+ Rect aDestRect = Rect(theDestRect.mX + mTransX, theDestRect.mY + mTransY, theDestRect.mWidth, theDestRect.mHeight);
+
+ mDestImage->StretchBltMirror(theImage, aDestRect, theSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, mFastStretch);
+}
+
+
+void Graphics::DrawImage(Image* theImage, int theX, int theY, int theStretchedWidth, int theStretchedHeight)
+{
+ Rect aDestRect = Rect(theX + mTransX, theY + mTransY, theStretchedWidth, theStretchedHeight);
+ Rect aSrcRect = Rect(0, 0, theImage->mWidth, theImage->mHeight);
+
+ mDestImage->StretchBlt(theImage, aDestRect, aSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, mFastStretch);
+}
+
+void Graphics::DrawImage(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect)
+{
+ Rect aDestRect = Rect(theDestRect.mX + mTransX, theDestRect.mY + mTransY, theDestRect.mWidth, theDestRect.mHeight);
+
+ mDestImage->StretchBlt(theImage, aDestRect, theSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, mFastStretch);
+}
+
+void Graphics::DrawImageF(Image* theImage, float theX, float theY)
+{
+ theX += mTransX;
+ theY += mTransY;
+
+ Rect aSrcRect(0, 0, theImage->mWidth, theImage->mHeight);
+ mDestImage->BltF(theImage, theX, theY, aSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode);
+}
+
+void Graphics::DrawImageF(Image* theImage, float theX, float theY, const Rect& theSrcRect)
+{
+ DBG_ASSERTE(theSrcRect.mX + theSrcRect.mWidth <= theImage->GetWidth());
+ DBG_ASSERTE(theSrcRect.mY + theSrcRect.mHeight <= theImage->GetHeight());
+
+ theX += mTransX;
+ theY += mTransY;
+
+ mDestImage->BltF(theImage, theX, theY, theSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode);
+}
+
+void Graphics::DrawImageRotated(Image* theImage, int theX, int theY, double theRot, const Rect *theSrcRect)
+{
+ if (theSrcRect == NULL)
+ {
+ int aRotCenterX = theImage->GetWidth() / 2;
+ int aRotCenterY = theImage->GetHeight() / 2;
+
+ DrawImageRotatedF(theImage, theX, theY, theRot, aRotCenterX, aRotCenterY, theSrcRect);
+ }
+ else
+ {
+ int aRotCenterX = theSrcRect->mWidth / 2;
+ int aRotCenterY = theSrcRect->mHeight / 2;
+
+ DrawImageRotatedF(theImage, theX, theY, theRot, aRotCenterX, aRotCenterY, theSrcRect);
+ }
+}
+
+void Graphics::DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, const Rect *theSrcRect)
+{
+ if (theSrcRect == NULL)
+ {
+ float aRotCenterX = theImage->GetWidth() / 2.0f;
+ float aRotCenterY = theImage->GetHeight() / 2.0f;
+
+ DrawImageRotatedF(theImage, theX, theY, theRot, aRotCenterX, aRotCenterY, theSrcRect);
+ }
+ else
+ {
+ float aRotCenterX = theSrcRect->mWidth / 2.0f;
+ float aRotCenterY = theSrcRect->mHeight / 2.0f;
+
+ DrawImageRotatedF(theImage, theX, theY, theRot, aRotCenterX, aRotCenterY, theSrcRect);
+ }
+}
+
+void Graphics::DrawImageRotated(Image* theImage, int theX, int theY, double theRot, int theRotCenterX, int theRotCenterY, const Rect *theSrcRect)
+{
+ DrawImageRotatedF(theImage,theX,theY,theRot,theRotCenterX,theRotCenterY,theSrcRect);
+}
+
+void Graphics::DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, float theRotCenterX, float theRotCenterY, const Rect *theSrcRect)
+{
+ theX += mTransX;
+ theY += mTransY;
+
+ if (theSrcRect==NULL)
+ {
+ Rect aSrcRect(0,0,theImage->mWidth,theImage->mHeight);
+ mDestImage->BltRotated(theImage, theX, theY, aSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, theRot, theRotCenterX, theRotCenterY);
+ }
+ else
+ mDestImage->BltRotated(theImage, theX, theY, *theSrcRect, mClipRect, mColorizeImages ? mColor : Color::White, mDrawMode, theRot, theRotCenterX, theRotCenterY);
+}
+
+void Graphics::DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, float x, float y)
+{
+ Rect aSrcRect(0,0,theImage->mWidth,theImage->mHeight);
+ mDestImage->BltMatrix(theImage,x+mTransX,y+mTransY,theMatrix,mClipRect,mColorizeImages?mColor:Color::White,mDrawMode,aSrcRect,mLinearBlend);
+}
+
+void Graphics::DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, const Rect &theSrcRect, float x, float y)
+{
+ mDestImage->BltMatrix(theImage,x+mTransX,y+mTransY,theMatrix,mClipRect,mColorizeImages?mColor:Color::White,mDrawMode,theSrcRect,mLinearBlend);
+}
+
+void Graphics::DrawImageTransformHelper(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x, float y, bool useFloat)
+{
+ if (theTransform.mComplex || (DDImage::Check3D(mDestImage) && useFloat))
+ {
+ DrawImageMatrix(theImage,theTransform.GetMatrix(),theSrcRect,x,y);
+ return;
+ }
+
+ // Translate into appropriate graphics call
+ float w2 = theSrcRect.mWidth/2.0f;
+ float h2 = theSrcRect.mHeight/2.0f;
+
+ if (theTransform.mHaveRot)
+ {
+ float rx = w2-theTransform.mTransX1;
+ float ry = h2-theTransform.mTransY1;
+
+ x = x + theTransform.mTransX2 - rx + 0.5f;
+ y = y + theTransform.mTransY2 - ry + 0.5f;
+
+ if (useFloat)
+ DrawImageRotatedF(theImage,x,y,theTransform.mRot,rx,ry,&theSrcRect);
+ else
+ DrawImageRotated(theImage,x,y,theTransform.mRot,rx,ry,&theSrcRect);
+ }
+ else if (theTransform.mHaveScale)
+ {
+ bool mirror = false;
+ if (theTransform.mScaleX==-1)
+ {
+ if (theTransform.mScaleY==1)
+ {
+ x = x + theTransform.mTransX1 + theTransform.mTransX2 - w2 + 0.5f;
+ y = y + theTransform.mTransY1 + theTransform.mTransY2 - h2 + 0.5f;
+ DrawImageMirror(theImage,x,y,theSrcRect);
+ return;
+ }
+ mirror = true;
+ }
+
+ float sw = w2*theTransform.mScaleX;
+ float sh = h2*theTransform.mScaleY;
+
+ x = x + theTransform.mTransX2 - sw;
+ y = y + theTransform.mTransY2 - sh;
+
+ Rect aDestRect(x,y,sw*2,sh*2);
+ DrawImageMirror(theImage,aDestRect,theSrcRect,mirror);
+ }
+ else
+ {
+ x = x + theTransform.mTransX1 + theTransform.mTransX2 - w2 + 0.5f;
+ y = y + theTransform.mTransY1 + theTransform.mTransY2 - h2 + 0.5f;
+
+ if (useFloat)
+ DrawImageF(theImage,x,y,theSrcRect);
+ else
+ DrawImage(theImage,x,y,theSrcRect);
+ }
+}
+
+void Graphics::DrawImageTransform(Image* theImage, const Transform &theTransform, float x, float y)
+{
+ DrawImageTransformHelper(theImage,theTransform,Rect(0,0,theImage->mWidth,theImage->mHeight),x,y,false);
+}
+
+void Graphics::DrawImageTransformF(Image* theImage, const Transform &theTransform, float x, float y)
+{
+ DrawImageTransformHelper(theImage,theTransform,Rect(0,0,theImage->mWidth,theImage->mHeight),x,y,true);
+}
+
+void Graphics::DrawImageTransform(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x, float y)
+{
+ DrawImageTransformHelper(theImage,theTransform,theSrcRect,x,y,false);
+}
+
+void Graphics::DrawImageTransformF(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x, float y)
+{
+ DrawImageTransformHelper(theImage,theTransform,theSrcRect,x,y,true);
+}
+
+void Graphics::DrawTriangleTex(Image *theTexture, const TriVertex &v1, const TriVertex &v2, const TriVertex &v3)
+{
+ TriVertex v[1][3] = {{v1,v2,v3}};
+ mDestImage->BltTrianglesTex(theTexture,v,1,mClipRect,mColorizeImages?mColor:Color::White,mDrawMode,mTransX,mTransY,mLinearBlend);
+}
+
+void Graphics::DrawTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles)
+{
+ mDestImage->BltTrianglesTex(theTexture,theVertices,theNumTriangles,mClipRect,mColorizeImages?mColor:Color::White,mDrawMode,mTransX,mTransY,mLinearBlend);
+}
+
+void Graphics::ClearClipRect()
+{
+ mClipRect = Rect(0, 0, mDestImage->GetWidth(), mDestImage->GetHeight());
+}
+
+void Graphics::SetClipRect(int theX, int theY, int theWidth, int theHeight)
+{
+ mClipRect =
+ Rect(0, 0, mDestImage->GetWidth(), mDestImage->GetHeight()).Intersection(
+ Rect(theX + mTransX, theY + mTransY, theWidth, theHeight));
+}
+
+void Graphics::SetClipRect(const Rect& theRect)
+{
+ SetClipRect(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+void Graphics::ClipRect(int theX, int theY, int theWidth, int theHeight)
+{
+ mClipRect = mClipRect.Intersection(Rect(theX + mTransX, theY + mTransY, theWidth, theHeight));
+}
+
+void Graphics::ClipRect(const Rect& theRect)
+{
+ ClipRect(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+void Graphics::Translate(int theTransX, int theTransY)
+{
+ mTransX += theTransX;
+ mTransY += theTransY;
+}
+
+void Graphics::TranslateF(float theTransX, float theTransY)
+{
+ mTransX += theTransX;
+ mTransY += theTransY;
+}
+
+void Graphics::SetScale(float theScaleX, float theScaleY, float theOrigX, float theOrigY)
+{
+ mScaleX = theScaleX;
+ mScaleY = theScaleY;
+ mScaleOrigX = theOrigX + mTransX;
+ mScaleOrigY = theOrigY + mTransY;
+}
+
+int Graphics::StringWidth(const SexyString& theString)
+{
+ return mFont->StringWidth(theString);
+}
+
+void Graphics::DrawImageBox(const Rect& theDest, Image* theComponentImage)
+{
+ DrawImageBox(Rect(0,0,theComponentImage->mWidth,theComponentImage->mHeight),theDest,theComponentImage);
+}
+
+void Graphics::DrawImageBox(const Rect& theSrc, const Rect &theDest, Image* theComponentImage)
+{
+ if (theSrc.mWidth<=0 || theSrc.mHeight<=0)
+ return;
+
+ int cw = theSrc.mWidth/3;
+ int ch = theSrc.mHeight/3;
+ int cx = theSrc.mX;
+ int cy = theSrc.mY;
+ int cmw = theSrc.mWidth - cw*2;
+ int cmh = theSrc.mHeight - ch*2;
+
+ // Draw 4 corners
+ DrawImage(theComponentImage, theDest.mX, theDest.mY, Rect(cx,cy, cw, ch));
+ DrawImage(theComponentImage, theDest.mX + theDest.mWidth-cw, theDest.mY, Rect(cx + cw + cmw, cy, cw, ch));
+ DrawImage(theComponentImage, theDest.mX, theDest.mY + theDest.mHeight-ch, Rect(cx, cy + ch + cmh, cw, ch));
+ DrawImage(theComponentImage, theDest.mX + theDest.mWidth-cw, theDest.mY + theDest.mHeight-ch, Rect(cx + cw + cmw, cy + ch + cmh, cw, ch));
+
+ // Draw top and bottom
+ Graphics aVertClip(*this);
+ aVertClip.ClipRect(theDest.mX + cw, theDest.mY, theDest.mWidth-cw*2, theDest.mHeight);
+ int aCol, aRow;
+ for (aCol = 0; aCol < (theDest.mWidth-cw*2+cmw-1)/cmw; aCol++)
+ {
+ aVertClip.DrawImage(theComponentImage, theDest.mX + cw + aCol*cmw, theDest.mY, Rect(cx + cw, cy, cmw, ch));
+ aVertClip.DrawImage(theComponentImage, theDest.mX + cw + aCol*cmw, theDest.mY + theDest.mHeight-ch, Rect(cx + cw, cy + ch + cmh, cmw, ch));
+ }
+
+ // Draw sides
+ Graphics aHorzClip(*this);
+ aHorzClip.ClipRect(theDest.mX, theDest.mY + ch, theDest.mWidth, theDest.mHeight-ch*2);
+ for (aRow = 0; aRow < (theDest.mHeight-ch*2+cmh-1)/cmh; aRow++)
+ {
+ aHorzClip.DrawImage(theComponentImage, theDest.mX, theDest.mY + ch + aRow*cmh, Rect(cx, cy + ch, cw, cmh));
+ aHorzClip.DrawImage(theComponentImage, theDest.mX + theDest.mWidth-cw, theDest.mY + ch + aRow*cmh, Rect(cx + cw + cmw, cy + ch, cw, cmh));
+ }
+
+ // Draw middle
+ Graphics aMidClip(*this);
+ aMidClip.ClipRect(theDest.mX + cw, theDest.mY + ch, theDest.mWidth-cw*2, theDest.mHeight-ch*2);
+ for (aCol = 0; aCol < (theDest.mWidth-cw*2+cmw-1)/cmw; aCol++)
+ for (aRow = 0; aRow < (theDest.mHeight-ch*2+cmh-1)/cmh; aRow++)
+ aMidClip.DrawImage(theComponentImage, theDest.mX + cw + aCol*cmw, theDest.mY + ch + aRow*cmh, Rect(cx + cw, cy + ch, cmw, cmh));
+}
+
+void Graphics::DrawImageCel(Image* theImageStrip, int theX, int theY, int theCel)
+{
+ DrawImageCel(theImageStrip, theX, theY, theCel % theImageStrip->mNumCols, theCel / theImageStrip->mNumCols);
+}
+
+void Graphics::DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCel)
+{
+ DrawImageCel(theImageStrip, theDestRect, theCel % theImageStrip->mNumCols, theCel / theImageStrip->mNumCols);
+}
+
+void Graphics::DrawImageCel(Image* theImageStrip, int theX, int theY, int theCelCol, int theCelRow)
+{
+ if (theCelRow<0 || theCelCol<0 || theCelRow >= theImageStrip->mNumRows || theCelCol >= theImageStrip->mNumCols)
+ return;
+
+ int aCelWidth = theImageStrip->mWidth / theImageStrip->mNumCols;
+ int aCelHeight = theImageStrip->mHeight / theImageStrip->mNumRows;
+ Rect aSrcRect(aCelWidth*theCelCol, aCelHeight*theCelRow, aCelWidth, aCelHeight);
+
+ DrawImage(theImageStrip,theX,theY,aSrcRect);
+}
+
+void Graphics::DrawImageAnim(Image* theImageAnim, int theX, int theY, int theTime)
+{
+ DrawImageCel(theImageAnim, theX, theY, theImageAnim->GetAnimCel(theTime));
+}
+
+void Graphics::DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCelCol, int theCelRow)
+{
+ if (theCelRow<0 || theCelCol<0 || theCelRow >= theImageStrip->mNumRows || theCelCol >= theImageStrip->mNumCols)
+ return;
+
+ int aCelWidth = theImageStrip->mWidth / theImageStrip->mNumCols;
+ int aCelHeight = theImageStrip->mHeight / theImageStrip->mNumRows;
+ Rect aSrcRect(aCelWidth*theCelCol, aCelHeight*theCelRow, aCelWidth, aCelHeight);
+
+ DrawImage(theImageStrip,theDestRect,aSrcRect);
+}
+
+int Graphics::WriteString(const SexyString& theString, int theX, int theY, int theWidth, int theJustification, bool drawString, int theOffset, int theLength, int theOldColor)
+{
+ Font* aFont = GetFont();
+ if (theOldColor==-1)
+ theOldColor = mColor.ToInt();
+
+ if (drawString)
+ {
+ switch (theJustification)
+ {
+ case 0:
+ theX += (theWidth - WriteString(theString, theX, theY, theWidth, -1, false, theOffset, theLength, theOldColor))/2;
+ break;
+ case 1:
+ theX += theWidth - WriteString(theString, theX, theY, theWidth, -1, false, theOffset, theLength, theOldColor);
+ break;
+ }
+ }
+
+ if(theLength<0 || theOffset+theLength>(int)theString.length())
+ theLength = (int)theString.length();
+ else
+ theLength = theOffset + theLength;
+
+
+ SexyString aString;
+ int aXOffset = 0;
+
+ for (int i = theOffset; i < theLength; i++)
+ {
+ if ((theString[i] == '^') && mWriteColoredString)
+ {
+ if (i+1<theLength && theString[i+1] == '^') // literal '^'
+ {
+ aString += _S('^');
+ i++;
+ }
+ else if (i>theLength-8) // badly formatted color specification
+ break;
+ else // change color instruction
+ {
+ DWORD aColor = 0;
+ if (theString[i+1]==_S('o'))
+ {
+ if (sexystrncmp(theString.c_str()+i+1, _S("oldclr"), 6) == 0)
+ aColor = theOldColor;
+ }
+ else
+ {
+ for (int aDigitNum = 0; aDigitNum < 6; aDigitNum++)
+ {
+ SexyChar aChar = theString[i+aDigitNum+1];
+ int aVal = 0;
+
+ if ((aChar >= _S('0')) && (aChar <= _S('9')))
+ aVal = aChar - _S('0');
+ else if ((aChar >= _S('A')) && (aChar <= _S('F')))
+ aVal = (aChar - _S('A')) + 10;
+ else if ((aChar >= _S('a')) && (aChar <= _S('f')))
+ aVal = (aChar - _S('a')) + 10;
+
+ aColor += (aVal << ((5 - aDigitNum) * 4));
+ }
+ }
+
+ if (drawString)
+ {
+ DrawString(aString, theX + aXOffset, theY);
+ SetColor(Color((aColor >> 16) & 0xFF, (aColor >> 8) & 0xFF, (aColor) & 0xFF, GetColor().mAlpha));
+ }
+
+ i += 7;
+
+ aXOffset += GetFont()->StringWidth(aString);
+
+ aString = _S("");
+ }
+ }
+ else
+ aString += theString[i];
+ }
+
+ if (drawString)
+ {
+ DrawString(aString, theX + aXOffset, theY);
+ }
+
+ aXOffset += GetFont()->StringWidth(aString);
+
+ return aXOffset;
+}
+
+static int WriteWordWrappedHelper(Graphics *g, const SexyString& theString, int theX, int theY, int theWidth, int theJustification, bool drawString, int theOffset, int theLength, int theOldColor, int theMaxChars)
+{
+ if (theOffset+theLength>theMaxChars)
+ {
+ theLength = theMaxChars-theOffset;
+ if (theLength<=0)
+ return -1;
+ }
+
+ return g->WriteString(theString,theX,theY,theWidth,theJustification,drawString,theOffset,theLength,theOldColor);
+}
+
+int Graphics::WriteWordWrapped(const Rect& theRect, const SexyString& theLine, int theLineSpacing, int theJustification, int *theMaxWidth, int theMaxChars, int *theLastWidth)
+{
+ Color anOrigColor = GetColor();
+ int anOrigColorInt = anOrigColor.ToInt();
+ if ((anOrigColorInt&0xFF000000)==0xFF000000)
+ anOrigColorInt &= ~0xFF000000;
+
+ if (theMaxChars<0)
+ theMaxChars = (int)theLine.length();
+
+ Font* aFont = GetFont();
+
+ int aYOffset = aFont->GetAscent() - aFont->GetAscentPadding();
+
+ if (theLineSpacing == -1)
+ theLineSpacing = aFont->GetLineSpacing();
+
+ SexyString aCurString;
+ ulong aCurPos = 0;
+ int aLineStartPos = 0;
+ int aCurWidth = 0;
+ SexyChar aCurChar = 0;
+ SexyChar aPrevChar = 0;
+ int aSpacePos = -1;
+ int aMaxWidth = 0;
+ int anIndentX = 0;
+
+ if (theLastWidth != NULL)
+ {
+ anIndentX = *theLastWidth;
+ aCurWidth = anIndentX;
+ }
+
+ while (aCurPos < theLine.length())
+ {
+ aCurChar = theLine[aCurPos];
+ if(aCurChar==_S('^') && mWriteColoredString) // Handle special color modifier
+ {
+ if(aCurPos+1<theLine.length())
+ {
+ if(theLine[aCurPos+1]==_S('^'))
+ aCurPos++; // literal '^' -> just skip the extra '^'
+ else
+ {
+ aCurPos+=8;
+ continue; // skip the color specifier when calculating the width
+ }
+ }
+ }
+ else if(aCurChar==_S(' '))
+ aSpacePos = aCurPos;
+ else if(aCurChar==_S('\n'))
+ {
+ aCurWidth = theRect.mWidth+1; // force word wrap
+ aSpacePos = aCurPos;
+ aCurPos++; // skip enter on next go round
+ }
+
+ aCurWidth += aFont->CharWidthKern(aCurChar, aPrevChar);
+ aPrevChar = aCurChar;
+
+ if(aCurWidth > theRect.mWidth) // need to wrap
+ {
+ int aWrittenWidth;
+ if(aSpacePos!=-1)
+ {
+ //aWrittenWidth = WriteWordWrappedHelper(this, theLine, theRect.mX, theRect.mY + aYOffset, theRect.mWidth,
+ // theJustification, true, aLineStartPos, aSpacePos-aLineStartPos, anOrigColorInt, theMaxChars);
+
+ int aPhysPos = theRect.mY + aYOffset + mTransY;
+ if ((aPhysPos >= mClipRect.mY) && (aPhysPos < mClipRect.mY + mClipRect.mHeight + theLineSpacing))
+ {
+ WriteWordWrappedHelper(this, theLine, theRect.mX + anIndentX, theRect.mY + aYOffset, theRect.mWidth,
+ theJustification, true, aLineStartPos, aSpacePos-aLineStartPos, anOrigColorInt, theMaxChars);
+
+ /*WriteString(theLine, theRect.mX + anIndentX, theRect.mY + aYOffset, theRect.mWidth,
+ theJustification, true, aLineStartPos, aSpacePos-aLineStartPos);*/
+ }
+
+ aWrittenWidth = aCurWidth + anIndentX;
+
+ if (aWrittenWidth<0)
+ break;
+
+ aCurPos = aSpacePos+1;
+ if (aCurChar != _S('\n'))
+ {
+ while (aCurPos<theLine.length() && theLine[aCurPos]==_S(' '))
+ aCurPos++;
+ }
+ aLineStartPos = aCurPos;
+ }
+ else
+ {
+ if((int)aCurPos<aLineStartPos+1)
+ aCurPos++; // ensure at least one character gets written
+
+ aWrittenWidth = WriteWordWrappedHelper(this, theLine, theRect.mX + anIndentX, theRect.mY + aYOffset, theRect.mWidth,
+ theJustification, true, aLineStartPos, aCurPos-aLineStartPos, anOrigColorInt, theMaxChars);
+
+ if (aWrittenWidth<0)
+ break;
+
+ if (theMaxWidth!=NULL && aWrittenWidth>*theMaxWidth)
+ *theMaxWidth = aWrittenWidth;
+ if (theLastWidth!=NULL)
+ *theLastWidth = aWrittenWidth;
+ }
+
+ if (aWrittenWidth > aMaxWidth)
+ aMaxWidth = aWrittenWidth;
+
+ aLineStartPos = aCurPos;
+ aSpacePos = -1;
+ aCurWidth = 0;
+ aPrevChar = 0;
+ anIndentX = 0;
+ aYOffset += theLineSpacing;
+ }
+ else
+ aCurPos++;
+ }
+
+ if(aLineStartPos<(int)theLine.length()) // write the last piece
+ {
+ int aWrittenWidth = WriteWordWrappedHelper(this, theLine, theRect.mX + anIndentX, theRect.mY + aYOffset, theRect.mWidth,
+ theJustification, true, aLineStartPos, theLine.length()-aLineStartPos, anOrigColorInt, theMaxChars);
+
+ if (aWrittenWidth>=0)
+ {
+ if (aWrittenWidth > aMaxWidth)
+ aMaxWidth = aWrittenWidth;
+
+ if (theMaxWidth!=NULL && aWrittenWidth>*theMaxWidth)
+ *theMaxWidth = aWrittenWidth;
+ if (theLastWidth!=NULL)
+ *theLastWidth = aWrittenWidth;
+
+ aYOffset += theLineSpacing;
+ }
+ }
+ else if (aCurChar == '\n')
+ {
+ aYOffset += theLineSpacing;
+ if (theLastWidth != NULL)
+ *theLastWidth = 0;
+ }
+
+ SetColor(anOrigColor);
+
+ if (theMaxWidth!=NULL)
+ *theMaxWidth = aMaxWidth;
+
+ return aYOffset + aFont->GetDescent() - theLineSpacing;
+}
+
+int Graphics::DrawStringColor(const SexyString& theLine, int theX, int theY, int theOldColor)
+{
+ return WriteString(theLine, theX, theY, -1, -1,true,0,-1,theOldColor);
+}
+
+int Graphics::DrawStringWordWrapped(const SexyString& theLine, int theX, int theY, int theWrapWidth, int theLineSpacing, int theJustification, int *theMaxWidth)
+{
+ int aYOffset = mFont->GetAscent() - mFont->GetAscentPadding();
+
+ Rect aRect(theX,theY-aYOffset,theWrapWidth,0);
+ return WriteWordWrapped(aRect, theLine, theLineSpacing, theJustification, theMaxWidth);
+}
+
+int Graphics::GetWordWrappedHeight(int theWidth, const SexyString& theLine, int theLineSpacing, int *theMaxWidth)
+{
+ Graphics aTestG;
+ aTestG.SetFont(mFont);
+ int aHeight = aTestG.WriteWordWrapped(Rect(0, 0, theWidth, 0), theLine, theLineSpacing, -1, theMaxWidth);
+
+ return aHeight;
+}
diff --git a/osframework/source/SexyAppFramework/Graphics.h b/osframework/source/SexyAppFramework/Graphics.h
new file mode 100644
index 0000000..8b731fd
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Graphics.h
@@ -0,0 +1,200 @@
+#ifndef __GRAPHICS_H__
+#define __GRAPHICS_H__
+
+#include "Common.h"
+#include "Rect.h"
+#include "Color.h"
+#include "Image.h"
+#include "TriVertex.h"
+
+namespace Sexy
+{
+
+class Font;
+class SexyMatrix3;
+class Transform;
+
+const int MAX_TEMP_SPANS = 8192;
+
+struct Edge
+{
+ double mX;
+ double mDX;
+ int i;
+ double b;
+};
+
+class Graphics;
+
+class GraphicsState
+{
+public:
+ static Image mStaticImage;
+ Image* mDestImage;
+ float mTransX;
+ float mTransY;
+ float mScaleX;
+ float mScaleY;
+ float mScaleOrigX;
+ float mScaleOrigY;
+ Rect mClipRect;
+ Color mColor;
+ Font* mFont;
+ int mDrawMode;
+ bool mColorizeImages;
+ bool mFastStretch;
+ bool mWriteColoredString;
+ bool mLinearBlend;
+ bool mIs3D;
+
+public:
+ void CopyStateFrom(const GraphicsState* theState);
+};
+
+typedef std::list<GraphicsState> GraphicsStateList;
+
+class Graphics : public GraphicsState
+{
+public:
+ enum
+ {
+ DRAWMODE_NORMAL,
+ DRAWMODE_ADDITIVE
+ };
+
+ Edge* mPFActiveEdgeList;
+ int mPFNumActiveEdges;
+ static const Point* mPFPoints;
+ int mPFNumVertices;
+
+ GraphicsStateList mStateStack;
+
+protected:
+ static int PFCompareInd(const void* u, const void* v);
+ static int PFCompareActive(const void* u, const void* v);
+ void PFDelete(int i);
+ void PFInsert(int i, int y);
+
+ void DrawImageTransformHelper(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x, float y, bool useFloat);
+
+public:
+ Graphics(const Graphics& theGraphics);
+ Graphics(Image* theDestImage = NULL);
+ virtual ~Graphics();
+
+ void PushState();
+ void PopState();
+
+ Graphics* Create();
+
+ void SetFont(Font* theFont);
+ Font* GetFont();
+
+ void SetColor(const Color& theColor);
+ const Color& GetColor();
+
+ void SetDrawMode(int theDrawMode);
+ int GetDrawMode();
+
+ void SetColorizeImages(bool colorizeImages);
+ bool GetColorizeImages();
+
+ void SetFastStretch(bool fastStretch);
+ bool GetFastStretch();
+
+ void SetLinearBlend(bool linear); // for DrawImageMatrix, DrawImageTransform, etc...
+ bool GetLinearBlend();
+
+ void FillRect(int theX, int theY, int theWidth, int theHeight);
+ void FillRect(const Rect& theRect);
+ void DrawRect(int theX, int theY, int theWidth, int theHeight);
+ void DrawRect(const Rect& theRect);
+ void ClearRect(int theX, int theY, int theWidth, int theHeight);
+ void ClearRect(const Rect& theRect);
+ void DrawString(const SexyString& theString, int theX, int theY);
+
+private:
+ bool DrawLineClipHelper(double* theStartX, double* theStartY, double *theEndX, double* theEndY);
+public:
+ void DrawLine(int theStartX, int theStartY, int theEndX, int theEndY);
+ void DrawLineAA(int theStartX, int theStartY, int theEndX, int theEndY);
+ void PolyFill(const Point *theVertexList, int theNumVertices, bool convex = false);
+ void PolyFillAA(const Point *theVertexList, int theNumVertices, bool convex = false);
+
+ void DrawImage(Image* theImage, int theX, int theY);
+ void DrawImage(Image* theImage, int theX, int theY, const Rect& theSrcRect);
+ void DrawImage(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect);
+ void DrawImage(Image* theImage, int theX, int theY, int theStretchedWidth, int theStretchedHeight);
+ void DrawImageF(Image* theImage, float theX, float theY);
+ void DrawImageF(Image* theImage, float theX, float theY, const Rect& theSrcRect);
+
+ void DrawImageMirror(Image* theImage, int theX, int theY, bool mirror = true);
+ void DrawImageMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, bool mirror = true);
+ void DrawImageMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, bool mirror = true);
+
+ void DrawImageRotated(Image* theImage, int theX, int theY, double theRot, const Rect *theSrcRect = NULL);
+ void DrawImageRotated(Image* theImage, int theX, int theY, double theRot, int theRotCenterX, int theRotCenterY, const Rect *theSrcRect = NULL);
+ void DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, const Rect *theSrcRect = NULL);
+ void DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, float theRotCenterX, float theRotCenterY, const Rect *theSrcRect = NULL);
+
+ void DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, float x = 0, float y = 0);
+ void DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, const Rect &theSrcRect, float x = 0, float y = 0);
+ void DrawImageTransform(Image* theImage, const Transform &theTransform, float x = 0, float y = 0);
+ void DrawImageTransform(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x = 0, float y = 0);
+ void DrawImageTransformF(Image* theImage, const Transform &theTransform, float x = 0, float y = 0);
+ void DrawImageTransformF(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x = 0, float y = 0);
+ void DrawTriangleTex(Image *theTexture, const TriVertex &v1, const TriVertex &v2, const TriVertex &v3);
+ void DrawTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles);
+
+ void DrawImageCel(Image* theImageStrip, int theX, int theY, int theCel);
+ void DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCel);
+ void DrawImageCel(Image* theImageStrip, int theX, int theY, int theCelCol, int theCelRow);
+ void DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCelCol, int theCelRow);
+
+ void DrawImageAnim(Image* theImageAnim, int theX, int theY, int theTime);
+
+ void ClearClipRect();
+ void SetClipRect(int theX, int theY, int theWidth, int theHeight);
+ void SetClipRect(const Rect& theRect);
+ void ClipRect(int theX, int theY, int theWidth, int theHeight);
+ void ClipRect(const Rect& theRect);
+ void Translate(int theTransX, int theTransY);
+ void TranslateF(float theTransX, float theTransY);
+
+ // In progress: Only affects DrawImage
+ void SetScale(float theScaleX, float theScaleY, float theOrigX, float theOrigY);
+
+ int StringWidth(const SexyString& theString);
+ void DrawImageBox(const Rect& theDest, Image* theComponentImage);
+ void DrawImageBox(const Rect& theSrc, const Rect& theDest, Image* theComponentImage);
+
+ int WriteString(const SexyString& theString, int theX, int theY, int theWidth = -1, int theJustification = 0, bool drawString = true, int theOffset = 0, int theLength = -1, int theOldColor = -1);
+ int WriteWordWrapped(const Rect& theRect, const SexyString& theLine, int theLineSpacing = -1, int theJustification = -1, int *theMaxWidth = NULL, int theMaxChars = -1, int* theLastWidth = NULL);
+ int DrawStringColor(const SexyString& theString, int theX, int theY, int theOldColor = -1); //works like DrawString but can have color tags like ^ff0000^.
+ int DrawStringWordWrapped(const SexyString& theLine, int theX, int theY, int theWrapWidth = 10000000, int theLineSpacing = -1, int theJustification = -1, int *theMaxWidth = NULL); //works like DrawString but also word wraps
+ int GetWordWrappedHeight(int theWidth, const SexyString& theLine, int theLineSpacing = -1, int *theMaxWidth = NULL);
+
+ bool Is3D() { return mIs3D; }
+};
+
+class GraphicsAutoState
+{
+public:
+ Graphics* mG;
+
+public:
+
+ GraphicsAutoState(Graphics* theG) : mG(theG)
+ {
+ mG->PushState();
+ }
+
+ ~GraphicsAutoState()
+ {
+ mG->PopState();
+ }
+};
+
+}
+
+#endif //__GRAPHICS_H__
diff --git a/osframework/source/SexyAppFramework/GraphicsBuild.cpp b/osframework/source/SexyAppFramework/GraphicsBuild.cpp
new file mode 100644
index 0000000..c6e1cc9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/GraphicsBuild.cpp
@@ -0,0 +1,18 @@
+#include "DDInterface.cpp" // build first because this defines INITGUID at the top
+
+#include "Color.cpp"
+#include "D3DInterface.cpp"
+#include "D3DTester.cpp"
+#include "DDImage.cpp"
+#include "Font.cpp"
+#include "Graphics.cpp"
+#include "NativeDisplay.cpp"
+#include "Image.cpp"
+#include "ImageFont.cpp"
+#include "MemoryImage.cpp"
+#include "SysFont.cpp"
+#include "Quantize.cpp"
+#include "SharedImage.cpp"
+
+// Leave this at the bottom because it undefs DIRECT3D_VERSION
+#include "D3D8Helper.cpp"
diff --git a/osframework/source/SexyAppFramework/HTTPTransfer.cpp b/osframework/source/SexyAppFramework/HTTPTransfer.cpp
new file mode 100644
index 0000000..f5445f3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/HTTPTransfer.cpp
@@ -0,0 +1,574 @@
+#include "HTTPTransfer.h"
+#include "SexyAppBase.h"
+#include <process.h>
+#include <winsock.h>
+
+using namespace Sexy;
+
+static int gCurTransferId = 1;
+
+HTTPTransfer::HTTPTransfer()
+{
+ mTransferId = gCurTransferId++;
+ mResult = RESULT_NOT_STARTED;
+ mContentLength = 0;
+ mDemoLastKnownResult = mResult;
+ mThreadRunning = false;
+}
+
+HTTPTransfer::~HTTPTransfer()
+{
+ Abort();
+ while (mThreadRunning)
+ {
+ Sleep(20);
+ }
+}
+
+std::string HTTPTransfer::GetAbsURL(const std::string& theBaseURL, const std::string& theRelURL)
+{
+ std::string aURL;
+
+ if (theRelURL.substr(0, 7).compare("http://") == 0)
+ {
+ aURL = theRelURL;
+ }
+ else if (theRelURL.substr(0, 1).compare("/") == 0)
+ {
+ int aFirstSlashPos = theBaseURL.find('/', 7);
+ if (aFirstSlashPos != -1)
+ {
+ aURL = theBaseURL.substr(0, aFirstSlashPos) + theRelURL;
+ }
+ else
+ {
+ aURL = theBaseURL + theRelURL;
+ }
+ }
+ else
+ {
+ int aLastSlashPos = theBaseURL.rfind('/');
+ if (aLastSlashPos >= 7)
+ {
+ aURL = theBaseURL.substr(0, aLastSlashPos+1) + theRelURL;
+ }
+ else
+ {
+ aURL = theBaseURL + "/" + theRelURL;
+ }
+ }
+
+ return aURL;
+}
+
+void HTTPTransfer::Fail(int theResult)
+{
+ mResult = theResult;
+ mExiting = true;
+}
+
+bool HTTPTransfer::SocketWait(bool checkRead, bool checkWrite)
+{
+ while (!mExiting)
+ {
+ fd_set aReadSet;
+ fd_set aWriteSet;
+ fd_set anExceptSet;
+
+ FD_ZERO(&aReadSet);
+ FD_ZERO(&aWriteSet);
+ FD_ZERO(&anExceptSet);
+
+ if (checkRead)
+ FD_SET(mSocket, &aReadSet);
+
+ if (checkWrite)
+ FD_SET(mSocket, &aWriteSet);
+
+ FD_SET(mSocket, &anExceptSet);
+
+ // Check every 100ms
+ int aReadTime = 100;
+
+ TIMEVAL aTimeout;
+ aTimeout.tv_sec = aReadTime/1000;
+ aTimeout.tv_usec = (aReadTime%1000)*1000;
+
+ int aVal = select(FD_SETSIZE, &aReadSet, &aWriteSet, &anExceptSet, &aTimeout);
+
+ if (aVal == SOCKET_ERROR)
+ {
+ Fail(RESULT_SOCKET_ERROR);
+ return false;
+ }
+
+ if (FD_ISSET(mSocket, &anExceptSet))
+ {
+ Fail(RESULT_SOCKET_ERROR);
+ return false;
+ }
+
+ if (FD_ISSET(mSocket, &aReadSet))
+ return true;
+
+ if (FD_ISSET(mSocket, &aWriteSet))
+ return true;
+ }
+
+ // Return true on abort
+ return true;
+}
+
+void HTTPTransfer::GetThreadProc()
+{
+ WSADATA aDat;
+ WSAStartup(MAKEWORD(1,1),&aDat);
+
+ mSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (mSocket == 0)
+ Fail(RESULT_SOCKET_ERROR);
+
+ // Set non-blocking
+ ulong anIoctlVal = 1;
+ ioctlsocket(mSocket, FIONBIO, &anIoctlVal);
+
+ if (!mExiting)
+ {
+ unsigned long anAddr = inet_addr(mHost.c_str());
+ if (anAddr == INADDR_NONE)
+ {
+ HOSTENT *aHostEnt = gethostbyname(mHost.c_str());
+ if (aHostEnt != NULL)
+ memcpy(&anAddr, aHostEnt->h_addr_list[0], 4);
+ }
+
+ if (anAddr == INADDR_NONE)
+ {
+ Fail(RESULT_INVALID_ADDR);
+ }
+ else
+ {
+ SOCKADDR_IN aSockAddrIn;
+ memset((char*) &aSockAddrIn, 0, sizeof(aSockAddrIn));
+ aSockAddrIn.sin_family = AF_INET;
+ aSockAddrIn.sin_addr.s_addr = anAddr;
+ aSockAddrIn.sin_port = htons(mPort);
+
+ if (::connect(mSocket, (sockaddr*) &aSockAddrIn, sizeof(SOCKADDR_IN)) != 0)
+ {
+ if (WSAGetLastError() != WSAEWOULDBLOCK)
+ Fail(RESULT_CONNECT_FAIL);
+
+ // Wait for socket to become writable to know we connected
+ if (!SocketWait(false, true))
+ Fail(RESULT_CONNECT_FAIL);
+ }
+
+ while ((mSendStr.length() > 0) && (!mExiting))
+ {
+ SocketWait(false, true);
+ int aResult = send(mSocket, mSendStr.c_str(), mSendStr.length(), 0);
+
+ if (aResult > 0)
+ {
+ mSendStr = mSendStr.substr(aResult);
+ }
+ else
+ {
+ int anError = WSAGetLastError();
+ Fail(RESULT_DISCONNECTED);
+ }
+ }
+
+ bool chunked = false;
+ bool gotHeader = false;
+ int aPos = 0;
+ int aLastPos = 0;
+ int aChunkLengthLeft = 0;
+ int aContentLengthLeft = 0;
+ std::string aRecvStr;
+
+ while (!mExiting)
+ {
+ // Wait for more characters if we couldn't do any processing with the
+ // current ones
+ if (aLastPos == aPos)
+ {
+ char aBuffer[257];
+ SocketWait(true, false);
+ int aResult = recv(mSocket, aBuffer, 256, 0);
+ if (aResult > 0)
+ {
+ aRecvStr.insert(aRecvStr.end(), aBuffer, aBuffer+aResult);
+
+ aBuffer[aResult] = 0;
+ }
+ else
+ {
+ int anError = WSAGetLastError();
+ break;
+ }
+ }
+
+ aLastPos = aPos;
+
+ if (!gotHeader)
+ {
+ // Still reading header...
+ int anEndLPos = aRecvStr.find("\r\n", aPos);
+ if (anEndLPos == -1)
+ continue; // Not enough for a full line yet
+ std::string aLine = aRecvStr.substr(aPos, anEndLPos-aPos);
+ aPos = anEndLPos+2;
+
+ if (aLine.substr(0, 7) == "HTTP/1.")
+ {
+ std::string aResult = aLine.substr(9, 3);
+ if (aResult == "404")
+ {
+ Fail(RESULT_NOT_FOUND);
+ }
+ else if (aResult != "200")
+ {
+ Fail(RESULT_HTTP_ERROR);
+ }
+ }
+
+ if (aLine == "Transfer-Encoding: chunked")
+ {
+ chunked = true;
+ }
+
+ char* aCheckStr = "Transfer-Encoding: ";
+ if (strncmp(aLine.c_str(), aCheckStr, strlen(aCheckStr)) == 0)
+ {
+ if (strcmp(aLine.c_str() + strlen(aCheckStr), "identity") != 0)
+ chunked = true;
+ }
+
+ aCheckStr = "Content-Length: ";
+ if (strncmp(aLine.c_str(), aCheckStr, strlen(aCheckStr)) == 0)
+ {
+ aContentLengthLeft = atoi(aLine.c_str() + strlen(aCheckStr));
+ mContentLength = aContentLengthLeft;
+ }
+
+ // Header is complete when we get a blank line
+ if (aLine.length() == 0)
+ gotHeader = true;
+ }
+ else
+ {
+ if (chunked)
+ {
+ // If it is zero, we need to get the next chunk length
+ if (aChunkLengthLeft == 0)
+ {
+ // Get a hex length
+ int anEndLPos = aRecvStr.find("\r\n", aPos);
+ if (anEndLPos == -1)
+ continue; // Not enough for a full line yet
+
+ std::string aLine = aRecvStr.substr(aPos, anEndLPos-aPos);
+ if (!StringToInt("0x" + Trim(aLine), &aChunkLengthLeft))
+ break; // End transfer on conversion error
+ if (aChunkLengthLeft == 0)
+ break; // Zero-size chunk marks end of chunked transfer
+
+ aPos = anEndLPos+2;
+ }
+
+ // Chunk it in
+ int aCopyLen = min(aChunkLengthLeft, (int)aRecvStr.length() - aPos);
+ if (aCopyLen > 0)
+ {
+ mContent += aRecvStr.substr(aPos, aCopyLen);
+ aPos += aCopyLen;
+ aChunkLengthLeft -= aCopyLen;
+
+ // There is always a CRLF at the end of the chunk data
+ if (aChunkLengthLeft == 0)
+ aPos += 2;
+ }
+ }
+ else
+ {
+ if (aContentLengthLeft > 0)
+ {
+ int aCopyLen = min(aContentLengthLeft, (int)aRecvStr.length() - aPos);
+ mContent += aRecvStr.substr(aPos, aCopyLen);
+ aPos += aCopyLen;
+ aContentLengthLeft -= aCopyLen;
+ if (aContentLengthLeft == 0)
+ {
+ // We have reached the end at this point
+ break;
+ }
+ }
+ else
+ {
+ // No length specified, we will just read until we close
+ int aCopyLen = aRecvStr.length() - aPos;
+ mContent += aRecvStr.substr(aPos, aCopyLen);
+ aPos += aCopyLen;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ closesocket(mSocket);
+ mSocket = NULL;
+ WSACleanup();
+
+ if (mAborted)
+ Fail(RESULT_ABORTED);
+ else if (mResult == RESULT_NOT_COMPLETED)
+ mResult = RESULT_DONE;
+
+ mThreadRunning = false;
+ mTransferPending = false;
+}
+
+void HTTPTransfer::GetThreadProcStub(void *theArg)
+{
+ ((HTTPTransfer*) theArg)->GetThreadProc();
+}
+
+void HTTPTransfer::PrepareTransfer(const std::string& theURL)
+{
+ Reset();
+
+ mTransferId = gCurTransferId++;
+ mURL = theURL;
+ mExiting = false;
+ mAborted = false;
+ mResult = RESULT_NOT_COMPLETED;
+ mContent.erase();
+ mContentLength = 0;
+
+ mPort = 80;
+
+ int aSSPos = mURL.find("//");
+ int aPos = 0;
+
+ if (aSSPos != -1)
+ aPos = aSSPos + 2;
+
+ if (aSSPos != -1)
+ mProto = mURL.substr(0, aSSPos-1);
+
+ int aSlashPos = mURL.find("/", aPos);
+ if (aSlashPos != -1)
+ {
+ mHost = mURL.substr(aPos, aSlashPos-aPos);
+ mPath = mURL.substr(aSlashPos);
+ }
+ else
+ {
+ mHost = mURL.substr(aPos);
+ mPath = "/";
+ }
+
+ int aSemiPos = (int) mHost.find(':');
+ if (aSemiPos != -1)
+ {
+ mPort = atoi(mHost.substr(aSemiPos + 1).c_str());
+ mHost = mHost.substr(0, aSemiPos);
+ }
+}
+
+void HTTPTransfer::StartTransfer()
+{
+ mTransferPending = true;
+
+ // Don't really start the transfer while in demo playing mode
+ if ((gSexyAppBase != NULL) && (gSexyAppBase->mPlayingDemoBuffer))
+ return;
+
+ mThreadRunning = true;
+ _beginthread(GetThreadProcStub, 0, this);
+}
+
+void HTTPTransfer::GetHelper(const std::string& theURL)
+{
+ PrepareTransfer(theURL);
+
+ mSendStr =
+ "GET " + mPath + " HTTP/1.0\r\n"
+ "User-Agent: Mozilla/4.0 (compatible; popcap)\r\n"
+ "Host: " + mHost + "\r\n"
+ "Connection: close\r\n" +
+ "\r\n";
+
+ StartTransfer();
+}
+
+void HTTPTransfer::PostHelper(const std::string& theURL, const std::string& theParams)
+{
+ PrepareTransfer(theURL);
+
+ mSendStr =
+ "POST " + mPath + " HTTP/1.0\r\n"
+ "Content-Type: application/x-www-form-urlencoded\r\n" +
+ "User-Agent: Mozilla/4.0 (compatible; popcap)\r\n"
+ "Host: " + mHost + "\r\n"
+ "Content-Length: " + StrFormat("%d", theParams.length()) + "\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" + theParams;
+
+ StartTransfer();
+}
+
+void HTTPTransfer::Get(const std::string& theURL)
+{
+ mSpecifiedBaseURL = "";
+ mSpecifiedRelURL = theURL;
+ GetHelper(theURL);
+}
+
+void HTTPTransfer::Post(const std::string& theURL, const std::string& theParams)
+{
+ mSpecifiedBaseURL = "";
+ mSpecifiedRelURL = theURL;
+ PostHelper(theURL, theParams);
+}
+
+void HTTPTransfer::Get(const std::string& theBaseURL, const std::string& theRelURL)
+{
+ mSpecifiedBaseURL = theBaseURL;
+ mSpecifiedRelURL = theRelURL;
+
+ GetHelper(GetAbsURL(theBaseURL, theRelURL));
+}
+
+void HTTPTransfer::Post(const std::string& theBaseURL, const std::string& theRelURL, const std::string& theParams)
+{
+ mSpecifiedBaseURL = theBaseURL;
+ mSpecifiedRelURL = theRelURL;
+
+ PostHelper(GetAbsURL(theBaseURL, theRelURL), theParams);
+}
+
+void HTTPTransfer::SendRequestString(const std::string& theHost, const std::string& theSendString)
+{
+ mSpecifiedBaseURL.erase();
+ mSpecifiedRelURL.erase();
+ PrepareTransfer(theHost);
+ mSendStr = theSendString;
+ StartTransfer();
+}
+
+void HTTPTransfer::Abort()
+{
+ mAborted = true;
+ mExiting = true;
+}
+
+void HTTPTransfer::Reset()
+{
+ if (mThreadRunning)
+ {
+ Abort();
+ WaitFor();
+ }
+
+ mResult = RESULT_NOT_STARTED;
+ mDemoLastKnownResult = RESULT_NOT_STARTED;
+ mTransferId = gCurTransferId++;
+ mContent.erase();
+ mExiting = false;
+ mAborted = false;
+ mURL.erase();
+ mSendStr.erase();
+ mPath.erase();
+}
+
+static int aLastThreadId = 0;
+
+void HTTPTransfer::UpdateStatus()
+{
+ // This will save the result data in demo recording mode and load it in (if available)
+ // in demo playback mode
+
+ if (gSexyAppBase != NULL)
+ {
+ if (gSexyAppBase->mPlayingDemoBuffer)
+ {
+ // We only need to try to get the result if we think we are waiting for one
+ if (gSexyAppBase->PrepareDemoCommand(false))
+ {
+ if ((!gSexyAppBase->mDemoIsShortCmd) && (gSexyAppBase->mDemoCmdNum == DEMO_HTTP_RESULT))
+ {
+ int anOldBufferPos = gSexyAppBase->mDemoBuffer.mReadBitPos;
+
+ // Since we don't require a demo result entry to be here, we must verify
+ // that this is referring to us
+ int aTransferId = gSexyAppBase->mDemoBuffer.ReadLong();
+
+ if (aTransferId == mTransferId)
+ {
+ // We finally got our result!
+ mResult = gSexyAppBase->mDemoBuffer.ReadByte();
+ mContent = gSexyAppBase->mDemoBuffer.ReadString();
+ mDemoLastKnownResult = mResult;
+ gSexyAppBase->mDemoNeedsCommand = true;
+
+ //TODO:
+ //OutputDebugString(StrFormat("Found State Change on %s (Id %d) to %d at %d\r\n", mURL.c_str(), mTransferId, mResult, gSexyAppBase->mUpdateCount).c_str());
+ }
+ else
+ {
+ // Not us, go back
+ gSexyAppBase->mDemoBuffer.mReadBitPos = anOldBufferPos;
+ }
+ }
+ }
+ }
+ else if ((gSexyAppBase->mRecordingDemoBuffer) && (mResult != mDemoLastKnownResult))
+ {
+ //TODO:
+ //OutputDebugString(StrFormat("Recording State Change on %s (Id %d) to %d at %d\r\n", mURL.c_str(), mTransferId, mResult, gSexyAppBase->mUpdateCount).c_str());
+
+ // Write out the new result
+ gSexyAppBase->WriteDemoTimingBlock();
+ gSexyAppBase->mDemoBuffer.WriteNumBits(0, 1);
+ gSexyAppBase->mDemoBuffer.WriteNumBits(DEMO_HTTP_RESULT, 5);
+ gSexyAppBase->mDemoBuffer.WriteLong(mTransferId);
+ gSexyAppBase->mDemoBuffer.WriteByte(mResult);
+
+ // Avoid any threading issues by not allowing access to mContent while in progress
+ if (mResult == RESULT_NOT_COMPLETED)
+ gSexyAppBase->mDemoBuffer.WriteString("");
+ else
+ gSexyAppBase->mDemoBuffer.WriteString(mContent);
+
+ mDemoLastKnownResult = mResult;
+ }
+ }
+}
+
+void HTTPTransfer::WaitFor()
+{
+ while (mTransferPending)
+ {
+ UpdateStatus();
+ Sleep(20);
+ }
+}
+
+int HTTPTransfer::GetResultCode()
+{
+ UpdateStatus();
+ return mResult;
+}
+
+std::string HTTPTransfer::GetContent()
+{
+ if (mResult == RESULT_NOT_COMPLETED)
+ return "";
+
+ UpdateStatus();
+ return mContent;
+}
diff --git a/osframework/source/SexyAppFramework/HTTPTransfer.h b/osframework/source/SexyAppFramework/HTTPTransfer.h
new file mode 100644
index 0000000..464cfd5
--- /dev/null
+++ b/osframework/source/SexyAppFramework/HTTPTransfer.h
@@ -0,0 +1,84 @@
+#ifndef __HTTPTRANSFER_H__
+#define __HTTPTRANSFER_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+class HTTPTransfer
+{
+public:
+ enum
+ {
+ RESULT_DONE,
+ RESULT_NOT_STARTED,
+ RESULT_NOT_COMPLETED,
+ RESULT_NOT_FOUND,
+ RESULT_HTTP_ERROR,
+ RESULT_ABORTED,
+ RESULT_SOCKET_ERROR,
+ RESULT_INVALID_ADDR,
+ RESULT_CONNECT_FAIL,
+ RESULT_DISCONNECTED
+ };
+
+ int mTransferId;
+ int mSocket;
+ std::string mSendStr;
+ std::string mSpecifiedBaseURL;
+ std::string mSpecifiedRelURL;
+ std::string mURL;
+ std::string mProto;
+ std::string mHost;
+ int mPort;
+ std::string mPath;
+
+ int mContentLength;
+ std::string mContent;
+
+ bool mTransferPending;
+ bool mThreadRunning;
+ bool mExiting;
+ bool mAborted;
+ int mResult;
+
+ int mDemoLastKnownResult;
+
+protected:
+ void PrepareTransfer(const std::string& theURL);
+ void StartTransfer();
+ void GetHelper(const std::string& theURL);
+
+ void PostHelper(const std::string& theURL, const std::string& theParams);
+
+ void Fail(int theResult);
+ void GetThreadProc();
+ static void GetThreadProcStub(void *theArg);
+ static std::string GetAbsURL(const std::string& theBaseURL, const std::string& theRelURL);
+
+ void UpdateStatus();
+ bool SocketWait(bool checkRead, bool checkWrite);
+
+public:
+ HTTPTransfer();
+ virtual ~HTTPTransfer();
+
+ void Get(const std::string& theURL);
+ void Get(const std::string& theBaseURL, const std::string& theRelURL);
+
+ void Post(const std::string& theURL, const std::string& theParams);
+ void Post(const std::string& theBaseURL, const std::string& theRelURL, const std::string& theParams);
+
+ void SendRequestString(const std::string& theHost, const std::string& theSendString);
+
+ void Reset();
+ void Abort();
+ void WaitFor();
+ int GetResultCode();
+ std::string GetContent();
+};
+
+};
+
+#endif //__HTTPTRANSFER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/HyperlinkWidget.cpp b/osframework/source/SexyAppFramework/HyperlinkWidget.cpp
new file mode 100644
index 0000000..54ff2d3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/HyperlinkWidget.cpp
@@ -0,0 +1,51 @@
+#include "HyperlinkWidget.h"
+#include "Graphics.h"
+#include "ImageFont.h"
+#include "SysFont.h"
+#include "WidgetManager.h"
+
+using namespace Sexy;
+
+HyperlinkWidget::HyperlinkWidget(int theId, ButtonListener* theButtonListener) :
+ ButtonWidget(theId, theButtonListener),
+ mColor(255, 255, 255),
+ mOverColor(255, 255, 255)
+{
+ mDoFinger = true;
+ mUnderlineOffset = 3;
+ mUnderlineSize = 1;
+}
+
+void HyperlinkWidget::Draw(Graphics* g)
+{
+ if (mFont == NULL)
+ mFont = new SysFont(mWidgetManager->mApp, "Arial Unicode MS", 10); //baz changed
+
+ int aFontX = (mWidth - mFont->StringWidth(mLabel))/2;
+ int aFontY = (mHeight + mFont->GetAscent())/2 - 1;
+
+ if (mIsOver)
+ g->SetColor(mOverColor);
+ else
+ g->SetColor(mColor);
+
+ g->SetFont(mFont);
+ g->DrawString(mLabel, aFontX, aFontY);
+
+ for (int i = 0; i < mUnderlineSize; i++)
+ g->FillRect(aFontX, aFontY+mUnderlineOffset+i, mFont->StringWidth(mLabel), 1);
+}
+
+void HyperlinkWidget::MouseEnter()
+{
+ ButtonWidget::MouseEnter();
+
+ MarkDirtyFull();
+}
+
+void HyperlinkWidget::MouseLeave()
+{
+ ButtonWidget::MouseLeave();
+
+ MarkDirtyFull();
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/HyperlinkWidget.h b/osframework/source/SexyAppFramework/HyperlinkWidget.h
new file mode 100644
index 0000000..53c435c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/HyperlinkWidget.h
@@ -0,0 +1,27 @@
+#ifndef __HYPERLINKWIDGET_H__
+#define __HYPERLINKWIDGET_H__
+
+#include "ButtonWidget.h"
+
+namespace Sexy
+{
+
+class HyperlinkWidget : public ButtonWidget
+{
+public:
+ Color mColor;
+ Color mOverColor;
+ int mUnderlineSize;
+ int mUnderlineOffset;
+
+public:
+ HyperlinkWidget(int theId, ButtonListener* theButtonListener);
+
+ void Draw(Graphics* g);
+ void MouseEnter();
+ void MouseLeave();
+};
+
+}
+
+#endif //__HYPERLINKWIDGET_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Image.cpp b/osframework/source/SexyAppFramework/Image.cpp
new file mode 100644
index 0000000..b495263
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Image.cpp
@@ -0,0 +1,290 @@
+#include "Image.h"
+#include "Graphics.h"
+
+using namespace Sexy;
+
+Image::Image()
+{
+ mWidth = 0;
+ mHeight = 0;
+
+ mNumRows = 1;
+ mNumCols = 1;
+
+ mAnimInfo = NULL;
+ mDrawn = false;
+}
+
+Image::Image(const Image& theImage) :
+ mWidth(theImage.mWidth),
+ mHeight(theImage.mHeight),
+ mNumRows(theImage.mNumRows),
+ mNumCols(theImage.mNumCols)
+{
+ mDrawn = false;
+ if (theImage.mAnimInfo != NULL)
+ mAnimInfo = new AnimInfo(*theImage.mAnimInfo);
+ else
+ mAnimInfo = NULL;
+}
+
+Image::~Image()
+{
+ delete mAnimInfo;
+}
+
+int Image::GetWidth()
+{
+ return mWidth;
+}
+
+int Image::GetHeight()
+{
+ return mHeight;
+}
+
+int Image::GetCelHeight()
+{
+ return mHeight / mNumRows;
+}
+
+int Image::GetCelWidth()
+{
+ return mWidth / mNumCols;
+}
+
+Rect Image::GetCelRect(int theCel)
+{
+ int h = GetCelHeight();
+ int w = GetCelWidth();
+ int x = (theCel % mNumCols) * w;
+ int y = (theCel / mNumCols) * h;
+
+ return Rect(x, y, w, h);
+}
+
+Rect Image::GetCelRect(int theCol, int theRow)
+{
+ int h = GetCelHeight();
+ int w = GetCelWidth();
+ int x = theCol * w;
+ int y = theRow * h;
+
+ return Rect(x, y, w, h);
+}
+
+AnimInfo::AnimInfo()
+{
+ mAnimType = AnimType_None;
+ mFrameDelay = 1;
+ mNumCels = 1;
+}
+
+void AnimInfo::SetPerFrameDelay(int theFrame, int theTime)
+{
+ if ((int)mPerFrameDelay.size()<=theFrame)
+ mPerFrameDelay.resize(theFrame+1);
+
+ mPerFrameDelay[theFrame] = theTime;
+}
+
+void AnimInfo::Compute(int theNumCels, int theBeginFrameTime, int theEndFrameTime)
+{
+ int i;
+
+ mNumCels = theNumCels;
+ if (mNumCels<=0)
+ mNumCels = 1;
+
+ if (mFrameDelay<=0)
+ mFrameDelay = 1;
+
+ if (mAnimType==AnimType_PingPong && mNumCels>1)
+ {
+ mFrameMap.resize(theNumCels*2-2);
+ int index = 0;
+ for (i=0; i<theNumCels; i++)
+ mFrameMap[index++] = i;
+ for (i=theNumCels-2; i>=1; i--)
+ mFrameMap[index++] = i;
+ }
+
+ if (!mFrameMap.empty())
+ mNumCels = (int)mFrameMap.size();
+
+ if (theBeginFrameTime>0)
+ SetPerFrameDelay(0,theBeginFrameTime);
+
+ if (theEndFrameTime>0)
+ SetPerFrameDelay(mNumCels-1,theEndFrameTime);
+
+ if (!mPerFrameDelay.empty())
+ {
+ mTotalAnimTime = 0;
+ mPerFrameDelay.resize(mNumCels);
+
+ for (i=0; i<mNumCels; i++)
+ {
+ if (mPerFrameDelay[i]<=0)
+ mPerFrameDelay[i] = mFrameDelay;
+
+ mTotalAnimTime += mPerFrameDelay[i];
+ }
+ }
+ else
+ mTotalAnimTime = mFrameDelay*mNumCels;
+
+ if (!mFrameMap.empty())
+ mFrameMap.resize(mNumCels);
+}
+
+int AnimInfo::GetPerFrameCel(int theTime)
+{
+ for (int i=0; i<mNumCels; i++)
+ {
+ theTime -= mPerFrameDelay[i];
+ if (theTime<0)
+ return i;
+ }
+
+ return mNumCels-1;
+}
+
+
+
+int AnimInfo::GetCel(int theTime)
+{
+ if (mAnimType==AnimType_Once && theTime>=mTotalAnimTime)
+ {
+ if (!mFrameMap.empty())
+ return mFrameMap[mFrameMap.size()-1];
+ else
+ return mNumCels-1;
+ }
+
+ theTime = theTime%mTotalAnimTime;
+
+ int aFrame;
+ if (!mPerFrameDelay.empty())
+ aFrame = GetPerFrameCel(theTime);
+ else
+ aFrame = (theTime/mFrameDelay)%mNumCels;
+
+ if (mFrameMap.empty())
+ return aFrame;
+ else
+ return mFrameMap[aFrame];
+}
+
+int Image::GetAnimCel(int theTime)
+{
+ if (mAnimInfo==NULL)
+ return 0;
+ else
+ return mAnimInfo->GetCel(theTime);
+}
+
+Rect Image::GetAnimCelRect(int theTime)
+{
+ Rect aRect;
+ int aCel = GetAnimCel(theTime);
+ int aCelWidth = GetCelWidth();
+ int aCelHeight = GetCelHeight();
+ if (mNumCols>1)
+ return Rect(aCel*aCelWidth,0,aCelWidth,mHeight);
+ else
+ return Rect(0,aCel*aCelHeight,mWidth,aCelHeight);
+}
+
+void Image::CopyAttributes(Image *from)
+{
+ mNumCols = from->mNumCols;
+ mNumRows = from->mNumRows;
+ delete mAnimInfo;
+ mAnimInfo = NULL;
+ if (from->mAnimInfo != NULL)
+ mAnimInfo = new AnimInfo(*from->mAnimInfo);
+}
+
+Graphics* Image::GetGraphics()
+{
+ Graphics* g = new Graphics(this);
+
+ return g;
+}
+
+void Image::FillRect(const Rect& theRect, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::ClearRect(const Rect& theRect)
+{
+}
+
+void Image::DrawRect(const Rect& theRect, const Color& theColor, int theDrawMode)
+{
+ FillRect(Rect(theRect.mX, theRect.mY, theRect.mWidth + 1, 1), theColor, theDrawMode);
+ FillRect(Rect(theRect.mX, theRect.mY + theRect.mHeight, theRect.mWidth + 1, 1), theColor, theDrawMode);
+ FillRect(Rect(theRect.mX, theRect.mY + 1, 1, theRect.mHeight - 1), theColor, theDrawMode);
+ FillRect(Rect(theRect.mX + theRect.mWidth, theRect.mY + 1, 1, theRect.mHeight - 1), theColor, theDrawMode);
+}
+
+void Image::DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::FillScanLines(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode)
+{
+ for (int i = 0; i < theSpanCount; i++)
+ {
+ Span* aSpan = &theSpans[i];
+ FillRect(Rect(aSpan->mX, aSpan->mY, aSpan->mWidth, 1), theColor, theDrawMode);
+ }
+}
+
+void Image::FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight)
+{
+}
+
+bool Image::PolyFill3D(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty, bool convex)
+{
+ return false;
+}
+
+void Image::Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY)
+{
+}
+
+void Image::StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
+{
+}
+
+void Image::BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend)
+{
+}
+
+void Image::BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend)
+{
+}
+
+
+void Image::BltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+}
+
+void Image::StretchBltMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
+{
+}
+
diff --git a/osframework/source/SexyAppFramework/Image.h b/osframework/source/SexyAppFramework/Image.h
new file mode 100644
index 0000000..e60f869
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Image.h
@@ -0,0 +1,104 @@
+#ifndef __IMAGE_H__
+#define __IMAGE_H__
+
+#include "Common.h"
+#include "Color.h"
+#include "Rect.h"
+#include "Point.h"
+
+namespace Sexy
+{
+
+struct Span
+{
+ int mY;
+ int mX;
+ int mWidth;
+};
+
+enum AnimType
+{
+ AnimType_None,
+ AnimType_Once,
+ AnimType_PingPong,
+ AnimType_Loop
+};
+
+struct AnimInfo
+{
+ AnimType mAnimType;
+ int mFrameDelay; // 1/100s
+ int mNumCels;
+ std::vector<int> mPerFrameDelay;
+ std::vector<int> mFrameMap;
+ int mTotalAnimTime;
+
+ AnimInfo();
+ void SetPerFrameDelay(int theFrame, int theTime);
+ void Compute(int theNumCels, int theBeginFrameTime = 0, int theEndFrameTime = 0);
+
+ int GetPerFrameCel(int theTime);
+ int GetCel(int theTime);
+};
+
+class Graphics;
+class SexyMatrix3;
+class SysFont;
+class TriVertex;
+
+class Image
+{
+ friend class Sexy::SysFont;
+
+public:
+ bool mDrawn;
+ std::string mFilePath;
+ int mWidth;
+ int mHeight;
+
+ // for image strips
+ int mNumRows;
+ int mNumCols;
+
+ // for animations
+ AnimInfo *mAnimInfo;
+
+public:
+ Image();
+ Image(const Image& theImage);
+ virtual ~Image();
+
+ int GetWidth();
+ int GetHeight();
+ int GetCelWidth(); // returns the width of just 1 cel in a strip of images
+ int GetCelHeight(); // like above but for vertical strips
+ int GetAnimCel(int theTime); // use animinfo to return appropriate cel to draw at the time
+ Rect GetAnimCelRect(int theTime);
+ Rect GetCelRect(int theCel); // Gets the rectangle for the given cel at the specified row/col
+ Rect GetCelRect(int theCol, int theRow); // Same as above, but for an image with both multiple rows and cols
+ void CopyAttributes(Image *from);
+ Graphics* GetGraphics();
+
+ virtual bool PolyFill3D(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty, bool convex);
+
+ virtual void FillRect(const Rect& theRect, const Color& theColor, int theDrawMode);
+ virtual void DrawRect(const Rect& theRect, const Color& theColor, int theDrawMode);
+ virtual void ClearRect(const Rect& theRect);
+ virtual void DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ virtual void DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ virtual void FillScanLines(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode);
+ virtual void FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight);
+ virtual void Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode);
+ virtual void BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode);
+ virtual void BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY);
+ virtual void StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch);
+ virtual void BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend);
+ virtual void BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend);
+
+ virtual void BltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode);
+ virtual void StretchBltMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch);
+};
+
+}
+
+#endif //__IMAGE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ImageFont.cpp b/osframework/source/SexyAppFramework/ImageFont.cpp
new file mode 100644
index 0000000..21f0f9c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ImageFont.cpp
@@ -0,0 +1,1736 @@
+#include "ImageFont.h"
+#include "Graphics.h"
+#include "Image.h"
+#include "SexyAppBase.h"
+#include "MemoryImage.h"
+#include "..\SexyAppFramework\AutoCrit.h"
+
+using namespace Sexy;
+
+////
+
+DataElement::DataElement() :
+ mIsList(false)
+{
+}
+
+DataElement::~DataElement()
+{
+}
+
+SingleDataElement::SingleDataElement()
+{
+ mIsList = false;
+}
+
+SingleDataElement::SingleDataElement(const std::string theString) :
+ mString(theString)
+{
+ mIsList = false;
+}
+
+SingleDataElement::~SingleDataElement()
+{
+}
+
+DataElement* SingleDataElement::Duplicate()
+{
+ SingleDataElement* aSingleDataElement = new SingleDataElement(*this);
+ return aSingleDataElement;
+}
+
+ListDataElement::ListDataElement()
+{
+ mIsList = true;
+}
+
+ListDataElement::~ListDataElement()
+{
+ for (ulong i = 0; i < mElementVector.size(); i++)
+ delete mElementVector[i];
+}
+
+ListDataElement::ListDataElement(const ListDataElement& theListDataElement)
+{
+ mIsList = true;
+ for (ulong i = 0; i < theListDataElement.mElementVector.size(); i++)
+ mElementVector.push_back(theListDataElement.mElementVector[i]->Duplicate());
+}
+
+ListDataElement& ListDataElement::operator=(const ListDataElement& theListDataElement)
+{
+ ulong i;
+
+ for (i = 0; i < mElementVector.size(); i++)
+ delete mElementVector[i];
+ mElementVector.clear();
+
+ for (i = 0; i < theListDataElement.mElementVector.size(); i++)
+ mElementVector.push_back(theListDataElement.mElementVector[i]->Duplicate());
+
+ return *this;
+}
+
+DataElement* ListDataElement::Duplicate()
+{
+ ListDataElement* aListDataElement = new ListDataElement(*this);
+ return aListDataElement;
+}
+
+///
+
+CharData::CharData()
+{
+ mWidth = 0;
+ mOrder = 0;
+
+ for (ulong i = 0; i < 256; i++)
+ mKerningOffsets[i] = 0;
+}
+
+FontLayer::FontLayer(FontData* theFontData)
+{
+ mFontData = theFontData;
+ mDrawMode = -1;
+ mSpacing = 0;
+ mPointSize = 0;
+ mAscent = 0;
+ mAscentPadding = 0;
+ mMinPointSize = -1;
+ mMaxPointSize = -1;
+ mHeight = 0;
+ mDefaultHeight = 0;
+ mColorMult = Color::White;
+ mColorAdd = Color(0, 0, 0, 0);
+ mLineSpacingOffset = 0;
+ mBaseOrder = 0;
+}
+
+FontLayer::FontLayer(const FontLayer& theFontLayer) :
+ mFontData(theFontLayer.mFontData),
+ mRequiredTags(theFontLayer.mRequiredTags),
+ mExcludedTags(theFontLayer.mExcludedTags),
+ mImage(theFontLayer.mImage),
+ mDrawMode(theFontLayer.mDrawMode),
+ mOffset(theFontLayer.mOffset),
+ mSpacing(theFontLayer.mSpacing),
+ mMinPointSize(theFontLayer.mMinPointSize),
+ mMaxPointSize(theFontLayer.mMaxPointSize),
+ mPointSize(theFontLayer.mPointSize),
+ mAscent(theFontLayer.mAscent),
+ mAscentPadding(theFontLayer.mAscentPadding),
+ mHeight(theFontLayer.mHeight),
+ mDefaultHeight(theFontLayer.mDefaultHeight),
+ mColorMult(theFontLayer.mColorMult),
+ mColorAdd(theFontLayer.mColorAdd),
+ mLineSpacingOffset(theFontLayer.mLineSpacingOffset),
+ mBaseOrder(theFontLayer.mBaseOrder)
+{
+ ulong i;
+
+ for (i = 0; i < 256; i++)
+ mCharData[i] = theFontLayer.mCharData[i];
+}
+
+FontData::FontData()
+{
+ mInitialized = false;
+
+ mApp = NULL;
+ mRefCount = 0;
+ mDefaultPointSize = 0;
+
+ for (ulong i = 0; i < 256; i++)
+ mCharMap[i] = (uchar) i;
+}
+
+FontData::~FontData()
+{
+ DataElementMap::iterator anItr = mDefineMap.begin();
+ while (anItr != mDefineMap.end())
+ {
+ std::string aDefineName = anItr->first;
+ DataElement* aDataElement = anItr->second;
+
+ delete aDataElement;
+ ++anItr;
+ }
+}
+
+void FontData::Ref()
+{
+ mRefCount++;
+}
+
+void FontData::DeRef()
+{
+ if (--mRefCount == 0)
+ {
+ delete this;
+ }
+}
+
+bool FontData::Error(const std::string& theError)
+{
+ if (mApp != NULL)
+ {
+ std::string anErrorString = mFontErrorHeader + theError;
+
+ if (mCurrentLine.length() > 0)
+ {
+ anErrorString += " on Line " + StrFormat("%d:\r\n\r\n", mCurrentLineNum) + mCurrentLine;
+ }
+
+ mApp->Popup(anErrorString);
+ }
+
+ return false;
+}
+
+bool FontData::DataToLayer(DataElement* theSource, FontLayer** theFontLayer)
+{
+ *theFontLayer = NULL;
+
+ if (theSource->mIsList)
+ return false;
+
+ std::string aLayerName = StringToUpper(((SingleDataElement*) theSource)->mString);
+
+ FontLayerMap::iterator anItr = mFontLayerMap.find(aLayerName);
+ if (anItr == mFontLayerMap.end())
+ {
+ Error("Undefined Layer");
+ return false;
+ }
+
+ *theFontLayer = anItr->second;
+
+ return true;
+}
+
+bool FontData::GetColorFromDataElement(DataElement *theElement, Color &theColor)
+{
+ if (theElement->mIsList)
+ {
+ DoubleVector aFactorVector;
+ if (!DataToDoubleVector(theElement, &aFactorVector) && (aFactorVector.size() == 4))
+ return false;
+
+ theColor = Color(
+ (int) (aFactorVector[0] * 255),
+ (int) (aFactorVector[1] * 255),
+ (int) (aFactorVector[2] * 255),
+ (int) (aFactorVector[3] * 255));
+
+ return true;
+ }
+
+ int aColor = 0;
+ if (!StringToInt(((SingleDataElement*) theElement)->mString, &aColor))
+ return false;
+
+ theColor = aColor;
+ return true;
+}
+
+
+bool FontData::HandleCommand(const ListDataElement& theParams)
+{
+ std::string aCmd = ((SingleDataElement*) theParams.mElementVector[0])->mString;
+
+ bool invalidNumParams = false;
+ bool invalidParamFormat = false;
+ bool literalError = false;
+ bool sizeMismatch = false;
+
+ if (stricmp(aCmd.c_str(), "Define") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ if (!theParams.mElementVector[1]->mIsList)
+ {
+ std::string aDefineName = StringToUpper(((SingleDataElement*) theParams.mElementVector[1])->mString);
+
+ if (!IsImmediate(aDefineName))
+ {
+ DataElementMap::iterator anItr = mDefineMap.find(aDefineName);
+ if (anItr != mDefineMap.end())
+ {
+ delete anItr->second;
+ mDefineMap.erase(anItr);
+ }
+
+ if (theParams.mElementVector[2]->mIsList)
+ {
+ ListDataElement* aValues = new ListDataElement();
+ if (!GetValues(((ListDataElement*) theParams.mElementVector[2]), aValues))
+ {
+ delete aValues;
+ return false;
+ }
+
+ mDefineMap.insert(DataElementMap::value_type(aDefineName, aValues));
+ }
+ else
+ {
+ SingleDataElement* aDefParam = (SingleDataElement*) theParams.mElementVector[2];
+
+ DataElement* aDerefVal = Dereference(aDefParam->mString);
+
+ if (aDerefVal)
+ mDefineMap.insert(DataElementMap::value_type(aDefineName, aDerefVal->Duplicate()));
+ else
+ mDefineMap.insert(DataElementMap::value_type(aDefineName, aDefParam->Duplicate()));
+ }
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "CreateHorzSpanRectList") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ IntVector aRectIntVector;
+ IntVector aWidthsVector;
+
+ if ((!theParams.mElementVector[1]->mIsList) &&
+ (DataToIntVector(theParams.mElementVector[2], &aRectIntVector)) &&
+ (aRectIntVector.size() == 4) &&
+ (DataToIntVector(theParams.mElementVector[3], &aWidthsVector)))
+ {
+ std::string aDefineName = StringToUpper(((SingleDataElement*) theParams.mElementVector[1])->mString);
+
+ int aXPos = 0;
+
+ ListDataElement* aRectList = new ListDataElement();
+
+ for (ulong aWidthNum = 0; aWidthNum < aWidthsVector.size(); aWidthNum++)
+ {
+ ListDataElement* aRectElement = new ListDataElement();
+ aRectList->mElementVector.push_back(aRectElement);
+
+ char aStr[256];
+
+ sprintf(aStr, "%d", aRectIntVector[0] + aXPos);
+ aRectElement->mElementVector.push_back(new SingleDataElement(aStr));
+
+ sprintf(aStr, "%d", aRectIntVector[1]);
+ aRectElement->mElementVector.push_back(new SingleDataElement(aStr));
+
+ sprintf(aStr, "%d", aWidthsVector[aWidthNum]);
+ aRectElement->mElementVector.push_back(new SingleDataElement(aStr));
+
+ sprintf(aStr, "%d", aRectIntVector[3]);
+ aRectElement->mElementVector.push_back(new SingleDataElement(aStr));
+
+ aXPos += aWidthsVector[aWidthNum];
+ }
+
+ DataElementMap::iterator anItr = mDefineMap.find(aDefineName);
+ if (anItr != mDefineMap.end())
+ {
+ delete anItr->second;
+ mDefineMap.erase(anItr);
+ }
+
+ mDefineMap.insert(DataElementMap::value_type(aDefineName, aRectList));
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "SetDefaultPointSize") == 0)
+ {
+ if (theParams.mElementVector.size() == 2)
+ {
+ int aPointSize;
+
+ if ((!theParams.mElementVector[1]->mIsList) &&
+ (StringToInt(((SingleDataElement*) theParams.mElementVector[1])->mString, &aPointSize)))
+ {
+ mDefaultPointSize = aPointSize;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "SetCharMap") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ StringVector aFromVector;
+ StringVector aToVector;
+
+ if ((DataToStringVector(theParams.mElementVector[1], &aFromVector)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aToVector)))
+ {
+ if (aFromVector.size() == aToVector.size())
+ {
+ for (ulong aMapIdx = 0; aMapIdx < aFromVector.size(); aMapIdx++)
+ {
+ if ((aFromVector[aMapIdx].length() == 1) && (aToVector[aMapIdx].length() == 1))
+ {
+ mCharMap[(uchar) aFromVector[aMapIdx][0]] = (uchar) aToVector[aMapIdx][0];
+ }
+ else
+ invalidParamFormat = true;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "CreateLayer") == 0)
+ {
+ if (theParams.mElementVector.size() == 2)
+ {
+ if (!theParams.mElementVector[1]->mIsList)
+ {
+ std::string aLayerName = StringToUpper(((SingleDataElement*) theParams.mElementVector[1])->mString);
+
+ mFontLayerList.push_back(FontLayer(this));
+ FontLayer* aFontLayer = &mFontLayerList.back();
+
+ if (!mFontLayerMap.insert(FontLayerMap::value_type(aLayerName, aFontLayer)).second)
+ {
+ Error("Layer Already Exists");
+ }
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "CreateLayerFrom") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aSourceLayer;
+
+ if ((!theParams.mElementVector[1]->mIsList) && (DataToLayer(theParams.mElementVector[2], &aSourceLayer)))
+ {
+ std::string aLayerName = StringToUpper(((SingleDataElement*) theParams.mElementVector[1])->mString);
+
+ mFontLayerList.push_back(FontLayer(*aSourceLayer));
+ FontLayer* aFontLayer = &mFontLayerList.back();
+
+ if (!mFontLayerMap.insert(FontLayerMap::value_type(aLayerName, aFontLayer)).second)
+ {
+ Error("Layer Already Exists");
+ }
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerRequireTags") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ StringVector aStringVector;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aStringVector)))
+ {
+ for (ulong i = 0; i < aStringVector.size(); i++)
+ aLayer->mRequiredTags.push_back(StringToUpper(aStringVector[i]));
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerExcludeTags") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ StringVector aStringVector;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aStringVector)))
+ {
+ for (ulong i = 0; i < aStringVector.size(); i++)
+ aLayer->mExcludedTags.push_back(StringToUpper(aStringVector[i]));
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerPointRange") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList) &&
+ (!theParams.mElementVector[3]->mIsList))
+ {
+ int aMinPointSize;
+ int aMaxPointSize;
+
+ if ((StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &aMinPointSize)) &&
+ (StringToInt(((SingleDataElement*) theParams.mElementVector[3])->mString, &aMaxPointSize)))
+ {
+ aLayer->mMinPointSize = aMinPointSize;
+ aLayer->mMaxPointSize = aMaxPointSize;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetPointSize") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int aPointSize;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &aPointSize))
+ {
+ aLayer->mPointSize = aPointSize;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetHeight") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int aHeight;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &aHeight))
+ {
+ aLayer->mHeight = aHeight;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetImage") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ std::string aFileNameString;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToString(theParams.mElementVector[2], &aFileNameString)))
+ {
+ std::string aFileName = GetPathFrom(aFileNameString, GetFileDir(mSourceFile));
+
+ bool isNew;
+ SharedImageRef anImage = mApp->GetSharedImage(aFileName, "", &isNew);
+
+ if ((Image*) anImage != NULL)
+ {
+ if (isNew)
+ anImage->Palletize();
+ aLayer->mImage = anImage;
+ }
+ else
+ {
+ Error("Failed to Load Image");
+ return false;
+ }
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetDrawMode") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) && (!theParams.mElementVector[2]->mIsList))
+ {
+ int anDrawMode;
+ if ((StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &anDrawMode)) &&
+ (anDrawMode >= 0) && (anDrawMode <= 1))
+ {
+ aLayer->mDrawMode = anDrawMode;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetColorMult") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if (DataToLayer(theParams.mElementVector[1], &aLayer))
+ {
+ if (!GetColorFromDataElement(theParams.mElementVector[2],aLayer->mColorMult))
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetColorAdd") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if (DataToLayer(theParams.mElementVector[1], &aLayer))
+ {
+ if (!GetColorFromDataElement(theParams.mElementVector[2],aLayer->mColorAdd))
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetAscent") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int anAscent;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &anAscent))
+ {
+ aLayer->mAscent = anAscent;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetAscentPadding") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int anAscent;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &anAscent))
+ {
+ aLayer->mAscentPadding = anAscent;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetLineSpacingOffset") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int anAscent;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &anAscent))
+ {
+ aLayer->mLineSpacingOffset = anAscent;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetOffset") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ IntVector anOffset;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) && (DataToIntVector(theParams.mElementVector[2], &anOffset)) && (anOffset.size() == 2))
+ {
+ aLayer->mOffset.mX = anOffset[0];
+ aLayer->mOffset.mY = anOffset[1];
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetCharWidths") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ StringVector aCharsVector;
+ IntVector aCharWidthsVector;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aCharsVector)) &&
+ (DataToIntVector(theParams.mElementVector[3], &aCharWidthsVector)))
+ {
+ if (aCharsVector.size() == aCharWidthsVector.size())
+ {
+ for (ulong i = 0; i < aCharsVector.size(); i++)
+ {
+ if (aCharsVector[i].length() == 1)
+ {
+ aLayer->mCharData[(uchar) aCharsVector[i][0]].mWidth =
+ aCharWidthsVector[i];
+ }
+ else
+ invalidParamFormat = true;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetSpacing") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ IntVector anOffset;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int aSpacing;
+
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &aSpacing))
+ {
+ aLayer->mSpacing = aSpacing;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetImageMap") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ StringVector aCharsVector;
+ ListDataElement aRectList;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aCharsVector)) &&
+ (DataToList(theParams.mElementVector[3], &aRectList)))
+ {
+ if (aCharsVector.size() == aRectList.mElementVector.size())
+ {
+ if ((Image*) aLayer->mImage != NULL)
+ {
+ int anImageWidth = aLayer->mImage->GetWidth();
+ int anImageHeight = aLayer->mImage->GetHeight();
+
+ for (ulong i = 0; i < aCharsVector.size(); i++)
+ {
+ IntVector aRectElement;
+
+ if ((aCharsVector[i].length() == 1) &&
+ (DataToIntVector(aRectList.mElementVector[i], &aRectElement)) &&
+ (aRectElement.size() == 4))
+
+ {
+ Rect aRect = Rect(aRectElement[0], aRectElement[1], aRectElement[2], aRectElement[3]);
+
+ if ((aRect.mX < 0) || (aRect.mY < 0) ||
+ (aRect.mX + aRect.mWidth > anImageWidth) || (aRect.mY + aRect.mHeight > anImageHeight))
+ {
+ Error("Image rectangle out of bounds");
+ return false;
+ }
+
+ aLayer->mCharData[(uchar) aCharsVector[i][0]].mImageRect = aRect;;
+ }
+ else
+ invalidParamFormat = true;
+ }
+
+ aLayer->mDefaultHeight = 0;
+ for (int aCharNum = 0; aCharNum < 256; aCharNum++)
+ if (aLayer->mCharData[aCharNum].mImageRect.mHeight + aLayer->mCharData[aCharNum].mOffset.mY > aLayer->mDefaultHeight)
+ aLayer->mDefaultHeight = aLayer->mCharData[aCharNum].mImageRect.mHeight + aLayer->mCharData[aCharNum].mOffset.mY;
+ }
+ else
+ {
+ Error("Layer image not set");
+ return false;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetCharOffsets") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ StringVector aCharsVector;
+ ListDataElement aRectList;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aCharsVector)) &&
+ (DataToList(theParams.mElementVector[3], &aRectList)))
+ {
+ if (aCharsVector.size() == aRectList.mElementVector.size())
+ {
+ for (ulong i = 0; i < aCharsVector.size(); i++)
+ {
+ IntVector aRectElement;
+
+ if ((aCharsVector[i].length() == 1) &&
+ (DataToIntVector(aRectList.mElementVector[i], &aRectElement)) &&
+ (aRectElement.size() == 2))
+ {
+ aLayer->mCharData[(uchar) aCharsVector[i][0]].mOffset =
+ Point(aRectElement[0], aRectElement[1]);
+ }
+ else
+ invalidParamFormat = true;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetKerningPairs") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ StringVector aPairsVector;
+ IntVector anOffsetsVector;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aPairsVector)) &&
+ (DataToIntVector(theParams.mElementVector[3], &anOffsetsVector)))
+ {
+ if (aPairsVector.size() == anOffsetsVector.size())
+ {
+ for (ulong i = 0; i < aPairsVector.size(); i++)
+ {
+ if (aPairsVector[i].length() == 2)
+ {
+ aLayer->mCharData[(uchar) aPairsVector[i][0]].mKerningOffsets
+ [(uchar) aPairsVector[i][1]] = anOffsetsVector[i];
+ }
+ else
+ invalidParamFormat = true;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetBaseOrder") == 0)
+ {
+ if (theParams.mElementVector.size() == 3)
+ {
+ FontLayer* aLayer;
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (!theParams.mElementVector[2]->mIsList))
+ {
+ int aBaseOrder;
+ if (StringToInt(((SingleDataElement*) theParams.mElementVector[2])->mString, &aBaseOrder))
+ {
+ aLayer->mBaseOrder = aBaseOrder;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else if (stricmp(aCmd.c_str(), "LayerSetCharOrders") == 0)
+ {
+ if (theParams.mElementVector.size() == 4)
+ {
+ FontLayer* aLayer;
+ StringVector aCharsVector;
+ IntVector aCharOrdersVector;
+
+ if ((DataToLayer(theParams.mElementVector[1], &aLayer)) &&
+ (DataToStringVector(theParams.mElementVector[2], &aCharsVector)) &&
+ (DataToIntVector(theParams.mElementVector[3], &aCharOrdersVector)))
+ {
+ if (aCharsVector.size() == aCharOrdersVector.size())
+ {
+ for (ulong i = 0; i < aCharsVector.size(); i++)
+ {
+ if (aCharsVector[i].length() == 1)
+ {
+ aLayer->mCharData[(uchar) aCharsVector[i][0]].mOrder =
+ aCharOrdersVector[i];
+ }
+ else
+ invalidParamFormat = true;
+ }
+ }
+ else
+ sizeMismatch = true;
+ }
+ else
+ invalidParamFormat = true;
+ }
+ else
+ invalidNumParams = true;
+ }
+ else
+ {
+ Error("Unknown Command");
+ return false;
+ }
+
+ if (invalidNumParams)
+ {
+ Error("Invalid Number of Parameters");
+ return false;
+ }
+
+ if (invalidParamFormat)
+ {
+ Error("Invalid Paramater Type");
+ return false;
+ }
+
+ if (literalError)
+ {
+ Error("Undefined Value");
+ return false;
+ }
+
+ if (sizeMismatch)
+ {
+ Error("List Size Mismatch");
+ return false;
+ }
+
+ return true;
+}
+
+bool FontData::Load(SexyAppBase* theSexyApp, const std::string& theFontDescFileName)
+{
+ if (mInitialized)
+ return false;
+
+ bool hasErrors = false;
+
+ mApp = theSexyApp;
+ mCurrentLine = "";
+
+ mFontErrorHeader = "Font Descriptor Error in " + theFontDescFileName + "\r\n";
+
+ mSourceFile = theFontDescFileName;
+
+ mInitialized = LoadDescriptor(theFontDescFileName); ;
+
+ return !hasErrors;
+}
+
+bool FontData::LoadLegacy(Image* theFontImage, const std::string& theFontDescFileName)
+{
+ if (mInitialized)
+ return false;
+
+ mFontLayerList.push_back(FontLayer(this));
+ FontLayer* aFontLayer = &mFontLayerList.back();
+
+ FontLayerMap::iterator anItr = mFontLayerMap.insert(FontLayerMap::value_type("", aFontLayer)).first;
+ if (anItr == mFontLayerMap.end())
+ return false;
+
+ aFontLayer->mImage = (MemoryImage*) theFontImage;
+ aFontLayer->mDefaultHeight = aFontLayer->mImage->GetHeight();
+ aFontLayer->mAscent = aFontLayer->mImage->GetHeight();
+
+ int aCharPos = 0;
+ FILE *aStream = fopen(theFontDescFileName.c_str(), "r");
+
+ if (aStream==NULL)
+ return false;
+
+ mSourceFile = theFontDescFileName;
+
+ int aSpaceWidth = 0;
+ fscanf(aStream,"%d%d",&aFontLayer->mCharData[' '].mWidth,&aFontLayer->mAscent);
+
+ while (!feof(aStream))
+ {
+ char aBuf[2] = { 0, 0 }; // needed because fscanf will null terminate the string it reads
+ char aChar = 0;
+ int aWidth = 0;
+
+ fscanf(aStream,"%1s%d",aBuf,&aWidth);
+ aChar = aBuf[0];
+
+
+ if (aChar == 0)
+ break;
+
+ aFontLayer->mCharData[(uchar) aChar].mImageRect = Rect(aCharPos, 0, aWidth, aFontLayer->mImage->GetHeight());
+ aFontLayer->mCharData[(uchar) aChar].mWidth = aWidth;
+
+ aCharPos += aWidth;
+ }
+
+ char c;
+
+ for (c = 'A'; c <= 'Z'; c++)
+ if ((aFontLayer->mCharData[c].mWidth == 0) && (aFontLayer->mCharData[c - 'A' + 'a'].mWidth != 0))
+ mCharMap[c] = c - 'A' + 'a';
+
+ for (c = 'a'; c <= 'z'; c++)
+ if ((aFontLayer->mCharData[c].mWidth == 0) && (aFontLayer->mCharData[c - 'a' + 'A'].mWidth != 0))
+ mCharMap[c] = c - 'a' + 'A';
+
+ mInitialized = true;
+ fclose(aStream);
+
+ return true;
+}
+
+////
+
+ActiveFontLayer::ActiveFontLayer()
+{
+ mScaledImage = NULL;
+ mOwnsImage = false;
+}
+
+ActiveFontLayer::ActiveFontLayer(const ActiveFontLayer& theActiveFontLayer) :
+ mBaseFontLayer(theActiveFontLayer.mBaseFontLayer),
+ mScaledImage(theActiveFontLayer.mScaledImage),
+ mOwnsImage(theActiveFontLayer.mOwnsImage)
+{
+ if (mOwnsImage)
+ mScaledImage = mBaseFontLayer->mFontData->mApp->CopyImage(mScaledImage);
+
+ for (int aCharNum = 0; aCharNum < 256; aCharNum++)
+ mScaledCharImageRects[aCharNum] = theActiveFontLayer.mScaledCharImageRects[aCharNum];
+}
+
+ActiveFontLayer::~ActiveFontLayer()
+{
+ if (mOwnsImage)
+ delete mScaledImage;
+}
+
+////
+
+ImageFont::ImageFont(SexyAppBase* theSexyApp, const std::string& theFontDescFileName)
+{
+ mScale = 1.0;
+ mFontData = new FontData();
+ mFontData->Ref();
+ mFontData->Load(theSexyApp, theFontDescFileName);
+ mPointSize = mFontData->mDefaultPointSize;
+ GenerateActiveFontLayers();
+ mActiveListValid = true;
+ mForceScaledImagesWhite = false;
+}
+
+ImageFont::ImageFont(Image *theFontImage)
+{
+ mScale = 1.0;
+ mFontData = new FontData();
+ mFontData->Ref();
+ mFontData->mInitialized = true;
+ mPointSize = mFontData->mDefaultPointSize;
+ mActiveListValid = false;
+ mForceScaledImagesWhite = false;
+
+ mFontData->mFontLayerList.push_back(FontLayer(mFontData));
+ FontLayer* aFontLayer = &mFontData->mFontLayerList.back();
+
+ mFontData->mFontLayerMap.insert(FontLayerMap::value_type("", aFontLayer)).first;
+ aFontLayer->mImage = (MemoryImage*) theFontImage;
+ aFontLayer->mDefaultHeight = aFontLayer->mImage->GetHeight();
+ aFontLayer->mAscent = aFontLayer->mImage->GetHeight();
+}
+
+ImageFont::ImageFont(const ImageFont& theImageFont) :
+ Font(theImageFont),
+ mScale(theImageFont.mScale),
+ mFontData(theImageFont.mFontData),
+ mPointSize(theImageFont.mPointSize),
+ mTagVector(theImageFont.mTagVector),
+ mActiveListValid(theImageFont.mActiveListValid),
+ mForceScaledImagesWhite(theImageFont.mForceScaledImagesWhite)
+{
+ mFontData->Ref();
+
+ if (mActiveListValid)
+ mActiveLayerList = theImageFont.mActiveLayerList;
+}
+
+ImageFont::ImageFont(Image* theFontImage, const std::string& theFontDescFileName)
+{
+
+ mScale = 1.0;
+ mFontData = new FontData();
+ mFontData->Ref();
+ mFontData->LoadLegacy(theFontImage, theFontDescFileName);
+ mPointSize = mFontData->mDefaultPointSize;
+ GenerateActiveFontLayers();
+ mActiveListValid = true;
+}
+
+ImageFont::~ImageFont()
+{
+ mFontData->DeRef();
+}
+
+/*ImageFont::ImageFont(const ImageFont& theImageFont, Image* theImage) :
+ Font(theImageFont),
+ mImage(theImage)
+{
+ for (int i = 0; i < 256; i++)
+ {
+ mCharPos[i] = theImageFont.mCharPos[i];
+ mCharWidth[i] = theImageFont.mCharWidth[i];
+ }
+}*/
+
+void ImageFont::GenerateActiveFontLayers()
+{
+ if (!mFontData->mInitialized)
+ return;
+
+ mActiveLayerList.clear();
+
+ ulong i;
+
+ mAscent = 0;
+ mAscentPadding = 0;
+ mHeight = 0;
+ mLineSpacingOffset = 0;
+
+ FontLayerList::iterator anItr = mFontData->mFontLayerList.begin();
+
+ bool firstLayer = true;
+
+ while (anItr != mFontData->mFontLayerList.end())
+ {
+ FontLayer* aFontLayer = &*anItr;
+
+ if ((mPointSize >= aFontLayer->mMinPointSize) &&
+ ((mPointSize <= aFontLayer->mMaxPointSize) || (aFontLayer->mMaxPointSize == -1)))
+ {
+ bool active = true;
+
+ // Make sure all required tags are included
+ for (i = 0; i < aFontLayer->mRequiredTags.size(); i++)
+ if (std::find(mTagVector.begin(), mTagVector.end(), aFontLayer->mRequiredTags[i]) == mTagVector.end())
+ active = false;
+
+ // Make sure no excluded tags are included
+ for (i = 0; i < mTagVector.size(); i++)
+ if (std::find(aFontLayer->mExcludedTags.begin(), aFontLayer->mExcludedTags.end(),
+ mTagVector[i]) != aFontLayer->mExcludedTags.end())
+ active = false;
+
+ if (active)
+ {
+ mActiveLayerList.push_back(ActiveFontLayer());
+
+ ActiveFontLayer* anActiveFontLayer = &mActiveLayerList.back();
+
+ anActiveFontLayer->mBaseFontLayer = aFontLayer;
+
+ double aLayerPointSize = 1;
+ double aPointSize = mScale;
+
+ if ((mScale == 1.0) && ((aFontLayer->mPointSize == 0) || (mPointSize == aFontLayer->mPointSize)))
+ {
+ anActiveFontLayer->mScaledImage = aFontLayer->mImage;
+ anActiveFontLayer->mOwnsImage = false;
+
+ // Use the specified point size
+
+ for (int aCharNum = 0; aCharNum < 256; aCharNum++)
+ anActiveFontLayer->mScaledCharImageRects[aCharNum] = aFontLayer->mCharData[aCharNum].mImageRect;
+ }
+ else
+ {
+ if (aFontLayer->mPointSize != 0)
+ {
+ aLayerPointSize = aFontLayer->mPointSize;
+ aPointSize = mPointSize * mScale;
+ }
+
+ // Resize font elements
+ int aCharNum;
+
+ MemoryImage* aMemoryImage = new MemoryImage(mFontData->mApp);
+
+ int aCurX = 0;
+ int aMaxHeight = 0;
+
+ for (aCharNum = 0; aCharNum < 256; aCharNum++)
+ {
+ Rect* anOrigRect = &aFontLayer->mCharData[aCharNum].mImageRect;
+
+ Rect aScaledRect(aCurX, 0,
+ (int) ((anOrigRect->mWidth * aPointSize) / aLayerPointSize),
+ (int) ((anOrigRect->mHeight * aPointSize) / aLayerPointSize));
+
+ anActiveFontLayer->mScaledCharImageRects[aCharNum] = aScaledRect;
+
+ if (aScaledRect.mHeight > aMaxHeight)
+ aMaxHeight = aScaledRect.mHeight;
+
+ aCurX += aScaledRect.mWidth;
+ }
+
+ anActiveFontLayer->mScaledImage = aMemoryImage;
+ anActiveFontLayer->mOwnsImage = true;
+
+ // Create the image now
+
+ aMemoryImage->Create(aCurX, aMaxHeight);
+
+ Graphics g(aMemoryImage);
+
+ for (aCharNum = 0; aCharNum < 256; aCharNum++)
+ {
+ if ((Image*) aFontLayer->mImage != NULL)
+ g.DrawImage(aFontLayer->mImage, anActiveFontLayer->mScaledCharImageRects[aCharNum],
+ aFontLayer->mCharData[aCharNum].mImageRect);
+ }
+
+ if (mForceScaledImagesWhite)
+ {
+ int aCount = aMemoryImage->mWidth*aMemoryImage->mHeight;
+ ulong* aBits = aMemoryImage->GetBits();
+
+ for (int i = 0; i < aCount; i++)
+ *(aBits++) = *aBits | 0x00FFFFFF;
+ }
+
+ aMemoryImage->Palletize();
+ }
+
+ int aLayerAscent = (aFontLayer->mAscent * aPointSize) / aLayerPointSize;
+ if (aLayerAscent > mAscent)
+ mAscent = aLayerAscent;
+
+ if (aFontLayer->mHeight != 0)
+ {
+ int aLayerHeight = (aFontLayer->mHeight * aPointSize) / aLayerPointSize;
+ if (aLayerHeight > mHeight)
+ mHeight = aLayerHeight;
+ }
+ else
+ {
+ int aLayerHeight = (aFontLayer->mDefaultHeight * aPointSize) / aLayerPointSize;
+ if (aLayerHeight > mHeight)
+ mHeight = aLayerHeight;
+ }
+
+ int anAscentPadding = (aFontLayer->mAscentPadding * aPointSize) / aLayerPointSize;
+ if ((firstLayer) || (anAscentPadding < mAscentPadding))
+ mAscentPadding = anAscentPadding;
+
+ int aLineSpacingOffset = (aFontLayer->mLineSpacingOffset * aPointSize) / aLayerPointSize;
+ if ((firstLayer) || (aLineSpacingOffset > mLineSpacingOffset))
+ mLineSpacingOffset = aLineSpacingOffset;
+
+ firstLayer = false;
+ }
+ }
+
+ ++anItr;
+ }
+}
+
+int ImageFont::StringWidth(const SexyString& theString)
+{
+ int aWidth = 0;
+ char aPrevChar = 0;
+ for(int i=0; i<(int)theString.length(); i++)
+ {
+ char aChar = theString[i];
+ aWidth += CharWidthKern(aChar,aPrevChar);
+ aPrevChar = aChar;
+ }
+
+ return aWidth;
+}
+
+int ImageFont::CharWidthKern(char theChar, char thePrevChar)
+{
+ Prepare();
+
+ int aMaxXPos = 0;
+ double aPointSize = mPointSize * mScale;
+
+ theChar = mFontData->mCharMap[(uchar)theChar];
+ if (thePrevChar != 0)
+ thePrevChar = mFontData->mCharMap[(uchar)thePrevChar];
+
+ ActiveFontLayerList::iterator anItr = mActiveLayerList.begin();
+ while (anItr != mActiveLayerList.end())
+ {
+ ActiveFontLayer* anActiveFontLayer = &*anItr;
+
+ int aLayerXPos = 0;
+
+ int aCharWidth;
+ int aSpacing;
+
+ int aLayerPointSize = anActiveFontLayer->mBaseFontLayer->mPointSize;
+
+ if (aLayerPointSize == 0)
+ {
+ aCharWidth = anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) theChar].mWidth * mScale;
+
+ if (thePrevChar != 0)
+ {
+ aSpacing = (anActiveFontLayer->mBaseFontLayer->mSpacing +
+ anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) thePrevChar].mKerningOffsets[(uchar) theChar]) * mScale;
+ }
+ else
+ aSpacing = 0;
+ }
+ else
+ {
+ aCharWidth = (anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) theChar].mWidth * aPointSize / aLayerPointSize);
+
+ if (thePrevChar != 0)
+ {
+ aSpacing = (anActiveFontLayer->mBaseFontLayer->mSpacing +
+ anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) thePrevChar].mKerningOffsets[(uchar) theChar]) * aPointSize / aLayerPointSize;
+ }
+ else
+ aSpacing = 0;
+ }
+
+ aLayerXPos += aCharWidth + aSpacing;
+
+ if (aLayerXPos > aMaxXPos)
+ aMaxXPos = aLayerXPos;
+
+ ++anItr;
+ }
+
+ return aMaxXPos;
+}
+
+int ImageFont::CharWidth(char theChar)
+{
+ return CharWidthKern(theChar,0);
+}
+
+CritSect gRenderCritSec;
+static const int POOL_SIZE = 4096;
+static RenderCommand gRenderCommandPool[POOL_SIZE];
+static RenderCommand* gRenderTail[256];
+static RenderCommand* gRenderHead[256];
+
+void ImageFont::DrawStringEx(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect* theClipRect, RectList* theDrawnAreas, int* theWidth)
+{
+ AutoCrit anAutoCrit(gRenderCritSec);
+
+ int aPoolIdx;
+
+ for (aPoolIdx = 0; aPoolIdx < 256; aPoolIdx++)
+ {
+ gRenderHead[aPoolIdx] = NULL;
+ gRenderTail[aPoolIdx] = NULL;
+ }
+
+ int aXPos = theX;
+
+ if (theDrawnAreas != NULL)
+ theDrawnAreas->clear();
+
+
+ /*if (theDrawnArea != NULL)
+ *theDrawnArea = Rect(0, 0, 0, 0);*/
+
+ if (!mFontData->mInitialized)
+ {
+ if (theWidth != NULL)
+ *theWidth = 0;
+ return;
+ }
+
+ Prepare();
+
+ bool colorizeImages = g->GetColorizeImages();
+ g->SetColorizeImages(true);
+
+ int aCurXPos = theX;
+ int aCurPoolIdx = 0;
+
+ for (ulong aCharNum = 0; aCharNum < theString.length(); aCharNum++)
+ {
+ char aChar = mFontData->mCharMap[(uchar) theString[aCharNum]];
+
+ char aNextChar = 0;
+ if (aCharNum < theString.length() - 1)
+ aNextChar = mFontData->mCharMap[(uchar) theString[aCharNum+1]];
+
+ int aMaxXPos = aCurXPos;
+
+ ActiveFontLayerList::iterator anItr = mActiveLayerList.begin();
+ while (anItr != mActiveLayerList.end())
+ {
+ ActiveFontLayer* anActiveFontLayer = &*anItr;
+
+ int aLayerXPos = aCurXPos;
+
+ int anImageX;
+ int anImageY;
+ int aCharWidth;
+ int aSpacing;
+
+ int aLayerPointSize = anActiveFontLayer->mBaseFontLayer->mPointSize;
+
+ double aScale = mScale;
+ if (aLayerPointSize != 0)
+ aScale *= mPointSize / aLayerPointSize;
+
+ if (aScale == 1.0)
+ {
+ anImageX = aLayerXPos + anActiveFontLayer->mBaseFontLayer->mOffset.mX + anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mOffset.mX;
+ anImageY = theY - (anActiveFontLayer->mBaseFontLayer->mAscent - anActiveFontLayer->mBaseFontLayer->mOffset.mY - anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mOffset.mY);
+ aCharWidth = anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mWidth;
+
+ if (aNextChar != 0)
+ {
+ aSpacing = anActiveFontLayer->mBaseFontLayer->mSpacing +
+ anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mKerningOffsets[(uchar) aNextChar];
+ }
+ else
+ aSpacing = 0;
+ }
+ else
+ {
+ anImageX = aLayerXPos + (int) ((anActiveFontLayer->mBaseFontLayer->mOffset.mX + anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mOffset.mX) * aScale);
+ anImageY = theY - (int) ((anActiveFontLayer->mBaseFontLayer->mAscent - anActiveFontLayer->mBaseFontLayer->mOffset.mY - anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mOffset.mY) * aScale);
+ aCharWidth = (anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mWidth * aScale);
+
+ if (aNextChar != 0)
+ {
+ aSpacing = (int) ((anActiveFontLayer->mBaseFontLayer->mSpacing +
+ anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mKerningOffsets[(uchar) aNextChar]) * aScale);
+ }
+ else
+ aSpacing = 0;
+ }
+
+ Color aColor;
+ aColor.mRed = min((theColor.mRed * anActiveFontLayer->mBaseFontLayer->mColorMult.mRed / 255) + anActiveFontLayer->mBaseFontLayer->mColorAdd.mRed, 255);
+ aColor.mGreen = min((theColor.mGreen * anActiveFontLayer->mBaseFontLayer->mColorMult.mGreen / 255) + anActiveFontLayer->mBaseFontLayer->mColorAdd.mGreen, 255);
+ aColor.mBlue = min((theColor.mBlue * anActiveFontLayer->mBaseFontLayer->mColorMult.mBlue / 255) + anActiveFontLayer->mBaseFontLayer->mColorAdd.mBlue, 255);
+ aColor.mAlpha = min((theColor.mAlpha * anActiveFontLayer->mBaseFontLayer->mColorMult.mAlpha / 255) + anActiveFontLayer->mBaseFontLayer->mColorAdd.mAlpha, 255);
+
+ int anOrder = anActiveFontLayer->mBaseFontLayer->mBaseOrder + anActiveFontLayer->mBaseFontLayer->mCharData[(uchar) aChar].mOrder;
+
+ if (aCurPoolIdx >= POOL_SIZE)
+ break;
+
+ RenderCommand* aRenderCommand = &gRenderCommandPool[aCurPoolIdx++];
+
+ aRenderCommand->mImage = anActiveFontLayer->mScaledImage;
+ aRenderCommand->mColor = aColor;
+ aRenderCommand->mDest[0] = anImageX;
+ aRenderCommand->mDest[1] = anImageY;
+ aRenderCommand->mSrc[0] = anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mX;
+ aRenderCommand->mSrc[1] = anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mY;
+ aRenderCommand->mSrc[2] = anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mWidth;
+ aRenderCommand->mSrc[3] = anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mHeight;
+ aRenderCommand->mMode = anActiveFontLayer->mBaseFontLayer->mDrawMode;
+ aRenderCommand->mNext = NULL;
+
+ int anOrderIdx = min(max(anOrder + 128, 0), 255);
+
+ if (gRenderTail[anOrderIdx] == NULL)
+ {
+ gRenderTail[anOrderIdx] = aRenderCommand;
+ gRenderHead[anOrderIdx] = aRenderCommand;
+ }
+ else
+ {
+ gRenderTail[anOrderIdx]->mNext = aRenderCommand;
+ gRenderTail[anOrderIdx] = aRenderCommand;
+ }
+
+ //aRenderCommandMap.insert(RenderCommandMap::value_type(aPriority, aRenderCommand));
+
+ /*int anOldDrawMode = g->GetDrawMode();
+ if (anActiveFontLayer->mBaseFontLayer->mDrawMode != -1)
+ g->SetDrawMode(anActiveFontLayer->mBaseFontLayer->mDrawMode);
+ Color anOrigColor = g->GetColor();
+ g->SetColor(aColor);
+ if (anActiveFontLayer->mScaledImage != NULL)
+ g->DrawImage(anActiveFontLayer->mScaledImage, anImageX, anImageY, anActiveFontLayer->mScaledCharImageRects[aChar]);
+ g->SetColor(anOrigColor);
+ g->SetDrawMode(anOldDrawMode);*/
+
+ if (theDrawnAreas != NULL)
+ {
+ Rect aDestRect = Rect(anImageX, anImageY, anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mWidth, anActiveFontLayer->mScaledCharImageRects[(uchar) aChar].mHeight);
+
+ theDrawnAreas->push_back(aDestRect);
+
+ /*if (theDrawnArea->mWidth == 0)
+ *theDrawnArea = theDestRect;
+ else
+ {
+ if (theDestRect.mX < theDrawnArea->mX)
+ {
+ int aDiff = theDestRect.mX - theDrawnArea->mX;
+ theDrawnArea->mX += aDiff;
+ theDrawnArea->mWidth += aDiff;
+ }
+
+ if (theDestRect.mX + theDestRect.mWidth > theDrawnArea->mX + theDrawnArea->mWidth)
+ theDrawnArea->mWidth = theDestRect.mX + theDestRect.mWidth - theDrawnArea->mX;
+
+ if (theDestRect.mY < theDrawnArea->mY)
+ {
+ int aDiff = theDestRect.mY - theDrawnArea->mY;
+ theDrawnArea->mY += aDiff;
+ theDrawnArea->mHeight += aDiff;
+ }
+
+ if (theDestRect.mY + theDestRect.mHeight > theDrawnArea->mY + theDrawnArea->mHeight)
+ theDrawnArea->mHeight = theDestRect.mY + theDestRect.mHeight - theDrawnArea->mY;
+ }*/
+ }
+
+ aLayerXPos += aCharWidth + aSpacing;
+
+ if (aLayerXPos > aMaxXPos)
+ aMaxXPos = aLayerXPos;
+
+ ++anItr;
+ }
+
+ aCurXPos = aMaxXPos;
+ }
+
+ if (theWidth != NULL)
+ *theWidth = aCurXPos - theX;
+
+ Color anOrigColor = g->GetColor();
+
+ for (aPoolIdx = 0; aPoolIdx < 256; aPoolIdx++)
+ {
+ RenderCommand* aRenderCommand = gRenderHead[aPoolIdx];
+
+ while (aRenderCommand != NULL)
+ {
+ int anOldDrawMode = g->GetDrawMode();
+ if (aRenderCommand->mMode != -1)
+ g->SetDrawMode(aRenderCommand->mMode);
+ g->SetColor(Color(aRenderCommand->mColor));
+ if (aRenderCommand->mImage != NULL)
+ g->DrawImage(aRenderCommand->mImage, aRenderCommand->mDest[0], aRenderCommand->mDest[1], Rect(aRenderCommand->mSrc[0], aRenderCommand->mSrc[1], aRenderCommand->mSrc[2], aRenderCommand->mSrc[3]));
+ g->SetDrawMode(anOldDrawMode);
+
+ aRenderCommand = aRenderCommand->mNext;
+ }
+ }
+
+ g->SetColor(anOrigColor);
+
+ /*RenderCommandMap::iterator anItr = aRenderCommandMap.begin();
+ while (anItr != aRenderCommandMap.end())
+ {
+ RenderCommand* aRenderCommand = &anItr->second;
+
+ int anOldDrawMode = g->GetDrawMode();
+ if (aRenderCommand->mMode != -1)
+ g->SetDrawMode(aRenderCommand->mMode);
+ Color anOrigColor = g->GetColor();
+ g->SetColor(aRenderCommand->mColor);
+ if (aRenderCommand->mImage != NULL)
+ g->DrawImage(aRenderCommand->mImage, aRenderCommand->mDest.mX, aRenderCommand->mDest.mY, aRenderCommand->mSrc);
+ g->SetColor(anOrigColor);
+ g->SetDrawMode(anOldDrawMode);
+
+ ++anItr;
+ }*/
+
+ g->SetColorizeImages(colorizeImages);
+}
+
+void ImageFont::DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect)
+{
+ DrawStringEx(g, theX, theY, theString, theColor, &theClipRect, NULL, NULL);
+}
+
+Font* ImageFont::Duplicate()
+{
+ return new ImageFont(*this);
+}
+
+void ImageFont::SetPointSize(int thePointSize)
+{
+ mPointSize = thePointSize;
+ mActiveListValid = false;
+}
+
+void ImageFont::SetScale(double theScale)
+{
+ mScale = theScale;
+ mActiveListValid = false;
+}
+
+int ImageFont::GetPointSize()
+{
+ return mPointSize;
+}
+
+int ImageFont::GetDefaultPointSize()
+{
+ return mFontData->mDefaultPointSize;
+}
+
+bool ImageFont::AddTag(const std::string& theTagName)
+{
+ if (HasTag(theTagName))
+ return false;
+
+ std::string aTagName = StringToUpper(theTagName);
+ mTagVector.push_back(aTagName);
+ mActiveListValid = false;
+ return true;
+}
+
+bool ImageFont::RemoveTag(const std::string& theTagName)
+{
+ std::string aTagName = StringToUpper(theTagName);
+
+ StringVector::iterator anItr = std::find(mTagVector.begin(), mTagVector.end(), aTagName);
+ if (anItr == mTagVector.end())
+ return false;
+
+ mTagVector.erase(anItr);
+ mActiveListValid = false;
+ return true;
+}
+
+bool ImageFont::HasTag(const std::string& theTagName)
+{
+ StringVector::iterator anItr = std::find(mTagVector.begin(), mTagVector.end(), theTagName);
+ return anItr != mTagVector.end();
+}
+
+std::string ImageFont::GetDefine(const std::string& theName)
+{
+ DataElement* aDataElement = mFontData->Dereference(theName);
+
+ if (aDataElement == NULL)
+ return "";
+
+ return mFontData->DataElementToString(aDataElement);
+}
+
+void ImageFont::Prepare()
+{
+ if (!mActiveListValid)
+ {
+ GenerateActiveFontLayers();
+ mActiveListValid = true;
+ }
+}
diff --git a/osframework/source/SexyAppFramework/ImageFont.h b/osframework/source/SexyAppFramework/ImageFont.h
new file mode 100644
index 0000000..fa9824e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ImageFont.h
@@ -0,0 +1,171 @@
+#ifndef __IMAGEFONT_H__
+#define __IMAGEFONT_H__
+
+#include "Font.h"
+#include "DescParser.h"
+#include "SharedImage.h"
+
+namespace Sexy
+{
+
+class SexyAppBase;
+class Image;
+
+class CharData
+{
+public:
+ Rect mImageRect;
+ Point mOffset;
+ char mKerningOffsets[256];
+ int mWidth;
+ int mOrder;
+
+public:
+ CharData();
+};
+
+class FontData;
+
+class FontLayer
+{
+public:
+ FontData* mFontData;
+ StringVector mRequiredTags;
+ StringVector mExcludedTags;
+ CharData mCharData[256];
+ Color mColorMult;
+ Color mColorAdd;
+ SharedImageRef mImage;
+ int mDrawMode;
+ Point mOffset;
+ int mSpacing;
+ int mMinPointSize;
+ int mMaxPointSize;
+ int mPointSize;
+ int mAscent;
+ int mAscentPadding; // How much space is above the avg uppercase char
+ int mHeight; //
+ int mDefaultHeight; // Max height of font character image rects
+ int mLineSpacingOffset; // This plus height should get added between lines
+ int mBaseOrder;
+
+public:
+ FontLayer(FontData* theFontData);
+ FontLayer(const FontLayer& theFontLayer);
+};
+
+typedef std::list<FontLayer> FontLayerList;
+typedef std::map<std::string, FontLayer*> FontLayerMap;
+typedef std::list<Rect> RectList;
+
+class FontData : public DescParser
+{
+public:
+ bool mInitialized;
+ int mRefCount;
+ SexyAppBase* mApp;
+
+ int mDefaultPointSize;
+ uchar mCharMap[256];
+ FontLayerList mFontLayerList;
+ FontLayerMap mFontLayerMap;
+
+ std::string mSourceFile;
+ std::string mFontErrorHeader;
+
+public:
+ virtual bool Error(const std::string& theError);
+
+ bool GetColorFromDataElement(DataElement *theElement, Color &theColor);
+ bool DataToLayer(DataElement* theSource, FontLayer** theFontLayer);
+ virtual bool HandleCommand(const ListDataElement& theParams);
+
+public:
+ FontData();
+ virtual ~FontData();
+
+ void Ref();
+ void DeRef();
+
+ bool Load(SexyAppBase* theSexyApp, const std::string& theFontDescFileName);
+ bool LoadLegacy(Image* theFontImage, const std::string& theFontDescFileName);
+};
+
+class ActiveFontLayer
+{
+public:
+ FontLayer* mBaseFontLayer;
+
+ Image* mScaledImage;
+ bool mOwnsImage;
+ Rect mScaledCharImageRects[256];
+
+public:
+ ActiveFontLayer();
+ ActiveFontLayer(const ActiveFontLayer& theActiveFontLayer);
+ virtual ~ActiveFontLayer();
+};
+
+typedef std::list<ActiveFontLayer> ActiveFontLayerList;
+
+class RenderCommand
+{
+public:
+ Image* mImage;
+ int mDest[2];
+ int mSrc[4];
+ int mMode;
+ Color mColor;
+ RenderCommand* mNext;
+};
+
+typedef std::multimap<int, RenderCommand> RenderCommandMap;
+
+class ImageFont : public Font
+{
+public:
+ FontData* mFontData;
+ int mPointSize;
+ StringVector mTagVector;
+
+ bool mActiveListValid;
+ ActiveFontLayerList mActiveLayerList;
+ double mScale;
+ bool mForceScaledImagesWhite;
+
+public:
+ virtual void GenerateActiveFontLayers();
+ virtual void DrawStringEx(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect* theClipRect, RectList* theDrawnAreas, int* theWidth);
+
+public:
+ ImageFont(SexyAppBase* theSexyApp, const std::string& theFontDescFileName);
+ ImageFont(Image *theFontImage); // for constructing your own image font without a file descriptor
+ ImageFont(const ImageFont& theImageFont);
+ virtual ~ImageFont();
+
+ // Deprecated
+ ImageFont(Image* theFontImage, const std::string& theFontDescFileName);
+ //ImageFont(const ImageFont& theImageFont, Image* theImage);
+
+ virtual int CharWidth(char theChar);
+ virtual int CharWidthKern(char theChar, char thePrevChar);
+ virtual int StringWidth(const SexyString& theString);
+ virtual void DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect);
+
+ virtual Font* Duplicate();
+
+ virtual void SetPointSize(int thePointSize);
+ virtual int GetPointSize();
+ virtual void SetScale(double theScale);
+ virtual int GetDefaultPointSize();
+ virtual bool AddTag(const std::string& theTagName);
+ virtual bool RemoveTag(const std::string& theTagName);
+ virtual bool HasTag(const std::string& theTagName);
+ virtual std::string GetDefine(const std::string& theName);
+
+ virtual void Prepare();
+};
+
+}
+
+#endif //__IMAGEFONT_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Insets.cpp b/osframework/source/SexyAppFramework/Insets.cpp
new file mode 100644
index 0000000..90fba6e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Insets.cpp
@@ -0,0 +1,29 @@
+#include "Insets.h"
+
+using namespace Sexy;
+
+Insets::Insets() :
+ mLeft(0),
+ mTop(0),
+ mRight(0),
+ mBottom(0)
+{
+ int a = 0;
+}
+
+Insets::Insets(int theLeft, int theTop, int theRight, int theBottom) :
+ mLeft(theLeft),
+ mTop(theTop),
+ mRight(theRight),
+ mBottom(theBottom)
+{
+}
+
+Insets::Insets(const Insets& theInsets) :
+ mLeft(theInsets.mLeft),
+ mTop(theInsets.mTop),
+ mRight(theInsets.mRight),
+ mBottom(theInsets.mBottom)
+{
+}
+
diff --git a/osframework/source/SexyAppFramework/Insets.h b/osframework/source/SexyAppFramework/Insets.h
new file mode 100644
index 0000000..41d95ee
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Insets.h
@@ -0,0 +1,23 @@
+#ifndef __INSETS_H__
+#define __INSETS_H__
+
+namespace Sexy
+{
+
+class Insets
+{
+public:
+ int mLeft;
+ int mTop;
+ int mRight;
+ int mBottom;
+
+public:
+ Insets();
+ Insets(int theLeft, int theTop, int theRight, int theBottom);
+ Insets(const Insets& theInsets);
+};
+
+}
+
+#endif //__INSETS_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/KeyCodes.cpp b/osframework/source/SexyAppFramework/KeyCodes.cpp
new file mode 100644
index 0000000..36c3e16
--- /dev/null
+++ b/osframework/source/SexyAppFramework/KeyCodes.cpp
@@ -0,0 +1,151 @@
+#include "KeyCodes.h"
+
+using namespace Sexy;
+
+#define MAX_KEYNAME_LEN 12
+
+typedef struct
+{
+ char mKeyName[MAX_KEYNAME_LEN];
+ KeyCode mKeyCode;
+} KeyNameEntry;
+
+KeyNameEntry aKeyCodeArray[] =
+{
+ {"UNKNOWN", KEYCODE_UNKNOWN},
+ {"LBUTTON", KEYCODE_LBUTTON},
+ {"RBUTTON", KEYCODE_RBUTTON},
+ {"CANCEL", KEYCODE_CANCEL},
+ {"MBUTTON", KEYCODE_MBUTTON},
+ {"BACK", KEYCODE_BACK},
+ {"TAB", KEYCODE_TAB},
+ {"CLEAR", KEYCODE_CLEAR},
+ {"RETURN", KEYCODE_RETURN},
+ {"SHIFT", KEYCODE_SHIFT},
+ {"CONTROL", KEYCODE_CONTROL},
+ {"MENU", KEYCODE_MENU},
+ {"PAUSE", KEYCODE_PAUSE},
+ {"CAPITAL", KEYCODE_CAPITAL},
+ {"KANA", KEYCODE_KANA},
+ {"HANGEUL", KEYCODE_HANGEUL},
+ {"HANGUL", KEYCODE_HANGUL},
+ {"JUNJA", KEYCODE_JUNJA},
+ {"FINAL", KEYCODE_FINAL},
+ {"HANJA", KEYCODE_HANJA},
+ {"KANJI", KEYCODE_KANJI},
+ {"ESCAPE", KEYCODE_ESCAPE},
+ {"CONVERT", KEYCODE_CONVERT},
+ {"NONCONVERT", KEYCODE_NONCONVERT},
+ {"ACCEPT", KEYCODE_ACCEPT},
+ {"MODECHANGE", KEYCODE_MODECHANGE},
+ {"SPACE", KEYCODE_SPACE},
+ {"PRIOR", KEYCODE_PRIOR},
+ {"NEXT", KEYCODE_NEXT},
+ {"END", KEYCODE_END},
+ {"HOME", KEYCODE_HOME},
+ {"LEFT", KEYCODE_LEFT},
+ {"UP", KEYCODE_UP},
+ {"RIGHT", KEYCODE_RIGHT},
+ {"DOWN", KEYCODE_DOWN},
+ {"SELECT", KEYCODE_SELECT},
+ {"PRINT", KEYCODE_PRINT},
+ {"EXECUTE", KEYCODE_EXECUTE},
+ {"SNAPSHOT", KEYCODE_SNAPSHOT},
+ {"INSERT", KEYCODE_INSERT},
+ {"DELETE", KEYCODE_DELETE},
+ {"HELP", KEYCODE_HELP},
+ {"LWIN", KEYCODE_LWIN},
+ {"RWIN", KEYCODE_RWIN},
+ {"APPS", KEYCODE_APPS},
+ {"NUMPAD0", KEYCODE_NUMPAD0},
+ {"NUMPAD1", KEYCODE_NUMPAD1},
+ {"NUMPAD2", KEYCODE_NUMPAD2},
+ {"NUMPAD3", KEYCODE_NUMPAD3},
+ {"NUMPAD4", KEYCODE_NUMPAD4},
+ {"NUMPAD5", KEYCODE_NUMPAD5},
+ {"NUMPAD6", KEYCODE_NUMPAD6},
+ {"NUMPAD7", KEYCODE_NUMPAD7},
+ {"NUMPAD8", KEYCODE_NUMPAD8},
+ {"NUMPAD9", KEYCODE_NUMPAD9},
+ {"MULTIPLY", KEYCODE_MULTIPLY},
+ {"ADD", KEYCODE_ADD},
+ {"SEPARATOR", KEYCODE_SEPARATOR},
+ {"SUBTRACT", KEYCODE_SUBTRACT},
+ {"DECIMAL", KEYCODE_DECIMAL},
+ {"DIVIDE", KEYCODE_DIVIDE},
+ {"F1", KEYCODE_F1},
+ {"F2", KEYCODE_F2},
+ {"F3", KEYCODE_F3},
+ {"F4", KEYCODE_F4},
+ {"F5", KEYCODE_F5},
+ {"F6", KEYCODE_F6},
+ {"F7", KEYCODE_F7},
+ {"F8", KEYCODE_F8},
+ {"F9", KEYCODE_F9},
+ {"F10", KEYCODE_F10},
+ {"F11", KEYCODE_F11},
+ {"F12", KEYCODE_F12},
+ {"F13", KEYCODE_F13},
+ {"F14", KEYCODE_F14},
+ {"F15", KEYCODE_F15},
+ {"F16", KEYCODE_F16},
+ {"F17", KEYCODE_F17},
+ {"F18", KEYCODE_F18},
+ {"F19", KEYCODE_F19},
+ {"F20", KEYCODE_F20},
+ {"F21", KEYCODE_F21},
+ {"F22", KEYCODE_F22},
+ {"F23", KEYCODE_F23},
+ {"F24", KEYCODE_F24},
+ {"NUMLOCK", KEYCODE_NUMLOCK},
+ {"SCROLL", KEYCODE_SCROLL}
+};
+
+KeyCode Sexy::GetKeyCodeFromName(const std::string& theKeyName)
+{
+ char aKeyName[MAX_KEYNAME_LEN];
+
+ if (theKeyName.length() >= MAX_KEYNAME_LEN-1)
+ return KEYCODE_UNKNOWN;
+
+ strcpy(aKeyName, theKeyName.c_str());
+ strupr(aKeyName);
+
+ if (theKeyName.length() == 1)
+ {
+ unsigned char aKeyNameChar = aKeyName[0];
+
+ if ((aKeyNameChar >= (unsigned char) KEYCODE_ASCIIBEGIN) && (aKeyNameChar <= (unsigned char) KEYCODE_ASCIIEND))
+ return (KeyCode) aKeyNameChar;
+
+ if ((aKeyNameChar >= ((unsigned char) KEYCODE_ASCIIBEGIN2) - 0x80) && (aKeyNameChar <= ((unsigned char) KEYCODE_ASCIIEND2) - 0x80))
+ return (KeyCode) (aKeyNameChar + 0x80);
+ }
+
+ for (int i = 0; i < sizeof(aKeyCodeArray)/sizeof(aKeyCodeArray[0]); i++)
+ if (strcmp(aKeyName, aKeyCodeArray[i].mKeyName) == 0)
+ return aKeyCodeArray[i].mKeyCode;
+
+ return KEYCODE_UNKNOWN;
+}
+
+const std::string Sexy::GetKeyNameFromCode(const KeyCode& theKeyCode)
+{
+ if ((theKeyCode >= KEYCODE_ASCIIBEGIN) && (theKeyCode <= KEYCODE_ASCIIEND))
+ {
+ char aStr[2] = {(char) theKeyCode, 0};
+ return aStr;
+ }
+
+ if ((theKeyCode >= KEYCODE_ASCIIBEGIN2) && (theKeyCode <= KEYCODE_ASCIIEND2))
+ {
+ char aStr[2] = {((unsigned char) theKeyCode) - 0x80, 0};
+ return aStr;
+ }
+
+ for (int i = 0; i < sizeof(aKeyCodeArray)/sizeof(aKeyCodeArray[0]); i++)
+ if (theKeyCode == aKeyCodeArray[i].mKeyCode)
+ return aKeyCodeArray[i].mKeyName;
+
+ return "UNKNOWN";
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/KeyCodes.h b/osframework/source/SexyAppFramework/KeyCodes.h
new file mode 100644
index 0000000..3c9fdfc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/KeyCodes.h
@@ -0,0 +1,109 @@
+#ifndef __KEYCODES_INCLUDED__
+#define __KEYCODES_INCLUDED__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+typedef enum KeyCode
+{
+ KEYCODE_UNKNOWN = 0x00,
+ KEYCODE_LBUTTON = 0x01,
+ KEYCODE_RBUTTON = 0x02,
+ KEYCODE_CANCEL = 0x03,
+ KEYCODE_MBUTTON = 0x04,
+ KEYCODE_BACK = 0x08,
+ KEYCODE_TAB = 0x09,
+ KEYCODE_CLEAR = 0x0C,
+ KEYCODE_RETURN = 0x0D,
+ KEYCODE_SHIFT = 0x10,
+ KEYCODE_CONTROL = 0x11,
+ KEYCODE_MENU = 0x12,
+ KEYCODE_PAUSE = 0x13,
+ KEYCODE_CAPITAL = 0x14,
+ KEYCODE_KANA = 0x15,
+ KEYCODE_HANGEUL = 0x15,
+ KEYCODE_HANGUL = 0x15,
+ KEYCODE_JUNJA = 0x17,
+ KEYCODE_FINAL = 0x18,
+ KEYCODE_HANJA = 0x19,
+ KEYCODE_KANJI = 0x19,
+ KEYCODE_ESCAPE = 0x1B,
+ KEYCODE_CONVERT = 0x1C,
+ KEYCODE_NONCONVERT = 0x1D,
+ KEYCODE_ACCEPT = 0x1E,
+ KEYCODE_MODECHANGE = 0x1F,
+ KEYCODE_SPACE = 0x20,
+ KEYCODE_PRIOR = 0x21,
+ KEYCODE_NEXT = 0x22,
+ KEYCODE_END = 0x23,
+ KEYCODE_HOME = 0x24,
+ KEYCODE_LEFT = 0x25,
+ KEYCODE_UP = 0x26,
+ KEYCODE_RIGHT = 0x27,
+ KEYCODE_DOWN = 0x28,
+ KEYCODE_SELECT = 0x29,
+ KEYCODE_PRINT = 0x2A,
+ KEYCODE_EXECUTE = 0x2B,
+ KEYCODE_SNAPSHOT = 0x2C,
+ KEYCODE_INSERT = 0x2D,
+ KEYCODE_DELETE = 0x2E,
+ KEYCODE_HELP = 0x2F,
+ KEYCODE_ASCIIBEGIN = 0x30,
+ KEYCODE_ASCIIEND = 0x5A,
+ KEYCODE_LWIN = 0x5B,
+ KEYCODE_RWIN = 0x5C,
+ KEYCODE_APPS = 0x5D,
+ KEYCODE_NUMPAD0 = 0x60,
+ KEYCODE_NUMPAD1 = 0x61,
+ KEYCODE_NUMPAD2 = 0x62,
+ KEYCODE_NUMPAD3 = 0x63,
+ KEYCODE_NUMPAD4 = 0x64,
+ KEYCODE_NUMPAD5 = 0x65,
+ KEYCODE_NUMPAD6 = 0x66,
+ KEYCODE_NUMPAD7 = 0x67,
+ KEYCODE_NUMPAD8 = 0x68,
+ KEYCODE_NUMPAD9 = 0x69,
+ KEYCODE_MULTIPLY = 0x6A,
+ KEYCODE_ADD = 0x6B,
+ KEYCODE_SEPARATOR = 0x6C,
+ KEYCODE_SUBTRACT = 0x6D,
+ KEYCODE_DECIMAL = 0x6E,
+ KEYCODE_DIVIDE = 0x6F,
+ KEYCODE_F1 = 0x70,
+ KEYCODE_F2 = 0x71,
+ KEYCODE_F3 = 0x72,
+ KEYCODE_F4 = 0x73,
+ KEYCODE_F5 = 0x74,
+ KEYCODE_F6 = 0x75,
+ KEYCODE_F7 = 0x76,
+ KEYCODE_F8 = 0x77,
+ KEYCODE_F9 = 0x78,
+ KEYCODE_F10 = 0x79,
+ KEYCODE_F11 = 0x7A,
+ KEYCODE_F12 = 0x7B,
+ KEYCODE_F13 = 0x7C,
+ KEYCODE_F14 = 0x7D,
+ KEYCODE_F15 = 0x7E,
+ KEYCODE_F16 = 0x7F,
+ KEYCODE_F17 = 0x80,
+ KEYCODE_F18 = 0x81,
+ KEYCODE_F19 = 0x82,
+ KEYCODE_F20 = 0x83,
+ KEYCODE_F21 = 0x84,
+ KEYCODE_F22 = 0x85,
+ KEYCODE_F23 = 0x86,
+ KEYCODE_F24 = 0x87,
+ KEYCODE_NUMLOCK = 0x90,
+ KEYCODE_SCROLL = 0x91,
+ KEYCODE_ASCIIBEGIN2 = 0xB3, //ASCII + 0x80
+ KEYCODE_ASCIIEND2 = 0xE0
+};
+
+KeyCode GetKeyCodeFromName(const std::string& theKeyName);
+const std::string GetKeyNameFromCode(const KeyCode& theKeyCode);
+
+}
+
+#endif //__KEYCODES_INCLUDED__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ListListener.h b/osframework/source/SexyAppFramework/ListListener.h
new file mode 100644
index 0000000..244d337
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ListListener.h
@@ -0,0 +1,17 @@
+#ifndef __LISTLISTENER_H__
+#define __LISTLISTENER_H__
+
+namespace Sexy
+{
+
+class ListListener
+{
+public:
+ virtual void ListClicked(int theId, int theIdx, int theClickCount) {}
+ virtual void ListClosed(int theId) {}
+ virtual void ListHiliteChanged(int theId, int theOldIdx, int theNewIdx) {}
+};
+
+}
+
+#endif //__LISTLISTENER_H__
diff --git a/osframework/source/SexyAppFramework/ListWidget.cpp b/osframework/source/SexyAppFramework/ListWidget.cpp
new file mode 100644
index 0000000..813331e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ListWidget.cpp
@@ -0,0 +1,510 @@
+#include "ListWidget.h"
+#include "Font.h"
+#include "WidgetManager.h"
+#include "ScrollbarWidget.h"
+#include "ListListener.h"
+#include "SexyAppBase.h"
+
+using namespace Sexy;
+
+static int gInitialListWidgetColors[][3] = {{255, 255, 255}, {255, 255, 255}, {0, 0, 0}, {0, 192, 0}, {0, 0, 128}, {255, 255, 255}};
+
+ListWidget::ListWidget(int theId, Font *theFont, ListListener *theListListener)
+{
+ mJustify = JUSTIFY_LEFT;
+ mHiliteIdx = -1;
+ mSelectIdx = -1;
+
+ if (theFont != NULL)
+ mItemHeight = theFont->GetHeight();
+ else
+ mItemHeight = -1;
+
+ SetColors(gInitialListWidgetColors, 6);
+
+ mId = theId;
+ mFont = theFont;
+ mListListener = theListListener;
+ mParent = NULL;
+ mChild = NULL;
+ mScrollbar = NULL;
+ mPosition = 0;
+ mPageSize = 0;
+ mSortFromChild = false;
+ mDrawOutline = true;
+ mMaxNumericPlaces = 0;
+ mDrawSelectWhenHilited = false;
+ mDoFingerWhenHilited = true;
+}
+
+ListWidget::~ListWidget()
+{
+}
+
+void ListWidget::RemovedFromManager(WidgetManager *theManager)
+{
+ Widget::RemovedFromManager(theManager);
+ if (mListListener)
+ mListListener->ListClosed(mId);
+}
+
+SexyString ListWidget::GetSortKey(int theIdx)
+{
+ SexyString aString = mLines[theIdx];
+
+ while (aString.length() < (ulong) mMaxNumericPlaces)
+ aString = _S("0") + aString;
+
+ if (mSortFromChild)
+ return mChild->GetSortKey(theIdx) + aString;
+ else
+ {
+ if (mChild == NULL)
+ return aString;
+ else
+ return aString + mChild->GetSortKey(theIdx);
+ }
+
+ return _S("");
+}
+
+void ListWidget::Sort(bool ascending)
+{
+ int aCount = mLines.size();
+ int* aMap = new int[aCount];
+ SexyString* aKeys = new SexyString[aCount];
+
+ int i;
+ for (i = 0; i < aCount; i++)
+ {
+ aMap[i] = i;
+ aKeys[i] = GetSortKey(i);
+ }
+
+ for (i = 1; i < aCount; i++)
+ for (int j = 0; j < aCount - i; j++)
+ {
+ int aComp = aKeys[j].compare(aKeys[j+1]);
+ if ((ascending && (aComp > 0)) || (!ascending && (aComp < 0)))
+ {
+ int aSwapInt = aMap[j];
+ aMap[j] = aMap[j+1];
+ aMap[j+1] = aSwapInt;
+
+ SexyString aSwapKey = aKeys[j];
+ aKeys[j] = aKeys[j+1];
+ aKeys[j+1] = aSwapKey;
+ }
+ }
+
+ ListWidget *aListWidget = this;
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ SexyStringVector aNewLines;
+ ColorVector aNewLineColors;
+
+ for (int i = 0; i < aCount; i++)
+ {
+ aNewLines.push_back(aListWidget->mLines[aMap[i]]);
+ aNewLineColors.push_back(aListWidget->mLineColors[aMap[i]]);
+ }
+
+ aListWidget->mLines = aNewLines;
+ aListWidget->mLineColors = aNewLineColors;
+
+ aListWidget->MarkDirty();
+
+ aListWidget = aListWidget->mChild;
+ }
+
+ delete aMap;
+ delete aKeys;
+}
+
+SexyString ListWidget::GetStringAt(int theIdx)
+{
+ return
+ mLines[theIdx];
+}
+
+void ListWidget::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Widget::Resize(theX, theY, theWidth, theHeight);
+
+ double aPageSize = 1;
+ int anItemHeight = (mItemHeight != -1) ? mItemHeight : mFont->GetHeight();
+
+ if (mHeight > anItemHeight+8)
+ aPageSize = (mHeight - 8.0) / anItemHeight;
+
+ mPageSize = aPageSize;
+
+ if (mScrollbar != NULL)
+ mScrollbar->SetPageSize(aPageSize);
+}
+
+int ListWidget::AddLine(const SexyString& theLine, bool alphabetical)
+{
+ int anIdx = -1;
+ bool inserted = false;
+
+ if (alphabetical)
+ {
+ for (int i = 0; i < (int) mLines.size(); i++)
+ if (sexystrcmp(theLine.c_str(), mLines[i].c_str()) < 0)
+ {
+ anIdx = i;
+
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ if (aListWidget == this)
+ aListWidget->mLines.insert(aListWidget->mLines.begin() + i, theLine);
+ else
+ aListWidget->mLines.insert(aListWidget->mLines.begin() + i, _S("-"));
+
+ aListWidget->mLineColors.insert(aListWidget->mLineColors.begin() + i, mColors[COLOR_TEXT]);
+ aListWidget->MarkDirty();
+
+ aListWidget = aListWidget->mChild;
+ }
+
+ inserted = true;
+ break;
+ }
+ }
+
+ if (!inserted)
+ {
+ anIdx = mLines.size();
+
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent!=NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget!=NULL)
+ {
+ if (aListWidget==this)
+ aListWidget->mLines.push_back(theLine);
+ else
+ aListWidget->mLines.push_back(_S("-"));
+
+ aListWidget->mLineColors.push_back(mColors[COLOR_TEXT]);
+ aListWidget->MarkDirty();
+
+ aListWidget = aListWidget->mChild;
+ }
+ }
+
+ if (mScrollbar!=NULL)
+ mScrollbar->SetMaxValue(mLines.size());
+
+ return anIdx;
+}
+
+
+void ListWidget::SetLine(int theIdx, const SexyString& theString)
+{
+ mLines[theIdx] = theString;
+ MarkDirty();
+}
+
+int ListWidget::GetLineCount()
+{
+ return mLines.size();
+}
+
+int ListWidget::GetLineIdx(const SexyString& theLine)
+{
+ for (ulong i = 0; i < mLines.size(); i++)
+ if (sexystrcmp(mLines[i].c_str(), theLine.c_str()) == 0)
+ return i;
+
+ return -1;
+}
+
+void ListWidget::SetColor(const SexyString& theLine, const Color& theColor)
+{
+ int anIdx = GetLineIdx(theLine);
+ SetLineColor(anIdx, theColor);
+}
+
+void ListWidget::SetColor(int theIdx, const Color& theColor)
+{
+ Widget::SetColor(theIdx, theColor);
+}
+
+void ListWidget::SetLineColor(int theIdx, const Color& theColor)
+{
+ if ((theIdx >= 0) && (theIdx < (int)mLines.size()))
+ {
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->mLineColors[theIdx] = theColor;
+ aListWidget->MarkDirty();
+
+ aListWidget = aListWidget->mChild;
+ }
+ }
+}
+
+void ListWidget::RemoveLine(int theIdx)
+{
+ if (theIdx != -1)
+ {
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->mLines.erase(aListWidget->mLines.begin() + theIdx);
+ aListWidget->mLineColors.erase(aListWidget->mLineColors.begin() + theIdx);
+
+ aListWidget->MarkDirty();
+ aListWidget = aListWidget->mChild;
+ }
+ }
+
+ if (mScrollbar != NULL)
+ mScrollbar->SetMaxValue(mLines.size());
+}
+
+void ListWidget::RemoveAll()
+{
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->mLines.clear();
+ aListWidget->mLineColors.clear();
+ aListWidget->mSelectIdx = -1;
+ aListWidget->mHiliteIdx = -1;
+
+ aListWidget->MarkDirty();
+ aListWidget = aListWidget->mChild;
+ }
+
+ if (mScrollbar != NULL)
+ mScrollbar->SetMaxValue(mLines.size());
+}
+
+int ListWidget::GetOptimalWidth()
+{
+ int aMaxWidth = 0;
+
+ for (ulong i = 0; i < mLines.size(); i++)
+ aMaxWidth = max(aMaxWidth, mFont->StringWidth(mLines[i]));
+
+ return aMaxWidth + 16;
+}
+
+int ListWidget::GetOptimalHeight()
+{
+ int anItemHeight = (mItemHeight != -1) ? mItemHeight : mFont->GetHeight();
+
+ return anItemHeight * mLines.size() + 8;
+}
+
+void ListWidget::OrderInManagerChanged()
+{
+ Widget::OrderInManagerChanged();
+
+ if (mChild != NULL)
+ gSexyAppBase->mWidgetManager->PutInfront(mChild, this);
+ if (mScrollbar != NULL)
+ gSexyAppBase->mWidgetManager->PutInfront(mScrollbar, this);
+}
+
+void ListWidget::Draw(Graphics *g)
+{
+ g->SetColor(mColors[COLOR_BKG]);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ Graphics aClipG(*g);
+ aClipG.ClipRect(4, 4, mWidth - 8, mHeight - 8);
+
+ Graphics aSelectClipG(*g);
+ aSelectClipG.ClipRect(0, 4, mWidth, mHeight - 8);
+
+ aClipG.SetFont(mFont);
+
+ int aFirstLine = (int) mPosition;
+ int aLastLine = min((int) mLines.size()-1, (int) mPosition + (int) mPageSize + 1);
+
+ int anItemHeight, anItemOffset;
+ if (mItemHeight != -1)
+ {
+ anItemHeight = mItemHeight;
+ anItemOffset = (anItemHeight-mFont->GetHeight())/2;
+ }
+ else
+ {
+ anItemHeight = mFont->GetHeight();
+ anItemOffset = 0;
+ }
+
+ for (int i = aFirstLine; i <= aLastLine; i++)
+ {
+ int aDrawY = 4 + (int) ((i - mPosition)*anItemHeight);
+
+ if (i == mSelectIdx || (i==mHiliteIdx && mDrawSelectWhenHilited))
+ {
+ aSelectClipG.SetColor(mColors[COLOR_SELECT]);
+ aSelectClipG.FillRect(0, aDrawY, mWidth, anItemHeight);
+ }
+
+ if (i == mHiliteIdx)
+ aClipG.SetColor(mColors[COLOR_HILITE]);
+ else if ((i == mSelectIdx) && (mColors.size() > COLOR_SELECT_TEXT))
+ aClipG.SetColor(mColors[COLOR_SELECT_TEXT]);
+ else
+ aClipG.SetColor(mLineColors[i]);
+
+ SexyString aString = mLines[i];
+ int aFontX;
+ switch (mJustify)
+ {
+ case JUSTIFY_LEFT:
+ aFontX = 4;
+ break;
+ case JUSTIFY_CENTER:
+ aFontX = (mWidth - mFont->StringWidth(aString))/2;
+ break;
+ default:
+ aFontX = mWidth - mFont->StringWidth(aString) - 4;
+ break;
+ }
+
+ aClipG.DrawString(aString, aFontX, aDrawY + mFont->GetAscent() + anItemOffset);
+ }
+
+ if (mDrawOutline)
+ {
+ g->SetColor(mColors[COLOR_OUTLINE]);
+ g->DrawRect(0, 0, mWidth-1, mHeight-1);
+ }
+}
+
+void ListWidget::ScrollPosition(int theId, double thePosition)
+{
+ if (mChild != NULL)
+ mChild->ScrollPosition(theId, thePosition);
+
+ mPosition = thePosition;
+ MarkDirty();
+}
+
+void ListWidget::SetHilite(int theHiliteIdx, bool notifyListener)
+{
+ int anOldIdx = mHiliteIdx;
+ mHiliteIdx = theHiliteIdx;
+ if (anOldIdx!=mHiliteIdx && notifyListener && mListListener!=NULL)
+ mListListener->ListHiliteChanged(mId,anOldIdx,mHiliteIdx);
+}
+
+
+void ListWidget::MouseMove(int x, int y)
+{
+ int anItemHeight = (mItemHeight != -1) ? mItemHeight : mFont->GetHeight();
+
+ int aNewHilite = (int) (((y - 4) / (double) anItemHeight) + mPosition);
+ if ((aNewHilite < 0) || (aNewHilite >= (int) mLines.size()))
+ aNewHilite = -1;
+
+ if (aNewHilite != mHiliteIdx)
+ {
+ ListWidget* aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->SetHilite(aNewHilite,true);
+ aListWidget->MarkDirty();
+ aListWidget = aListWidget->mChild;
+ }
+
+ if (mHiliteIdx == -1 || !mDoFingerWhenHilited)
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+ else
+ mWidgetManager->mApp->SetCursor(CURSOR_HAND);
+ }
+}
+
+void ListWidget::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ if ((mHiliteIdx != -1) && (mListListener != NULL))
+ mListListener->ListClicked(mId, mHiliteIdx, theClickCount);
+}
+
+void ListWidget::MouseLeave()
+{
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->SetHilite(-1,true);
+ aListWidget->MarkDirty();
+ aListWidget = aListWidget->mChild;
+ }
+
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+}
+
+void ListWidget::SetSelect(int theSelectIdx)
+{
+ ListWidget *aListWidget = this;
+
+ while (aListWidget->mParent != NULL)
+ aListWidget = aListWidget->mParent;
+
+ while (aListWidget != NULL)
+ {
+ aListWidget->mSelectIdx = theSelectIdx;
+ aListWidget->MarkDirty();
+ aListWidget = aListWidget->mChild;
+ }
+}
+
+
+void ListWidget::MouseWheel(int theDelta)
+{
+ if (mScrollbar != NULL)
+ {
+ int aScrollAmount = 5;
+ if (theDelta > 0)
+ {
+ mScrollbar->SetValue(mScrollbar->mValue - aScrollAmount);
+// mScrollbar->mUpdateMode = ScrollbarWidget::UPDATE_MODE_PGUP;
+// mScrollbar->mUpdateAcc = 0;
+ }
+ else if (theDelta < 0)
+ {
+ mScrollbar->SetValue(mScrollbar->mValue + aScrollAmount);
+// mScrollbar->mUpdateMode = ScrollbarWidget::UPDATE_MODE_PGDN;
+// mScrollbar->mUpdateAcc = 0;
+ }
+ }
+}
diff --git a/osframework/source/SexyAppFramework/ListWidget.h b/osframework/source/SexyAppFramework/ListWidget.h
new file mode 100644
index 0000000..f624b40
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ListWidget.h
@@ -0,0 +1,96 @@
+#ifndef __LISTWIDGET_H__
+#define __LISTWIDGET_H__
+
+#include "ScrollListener.h"
+#include "Widget.h"
+
+namespace Sexy
+{
+
+typedef std::vector<SexyString> SexyStringVector;
+typedef std::vector<Color> ColorVector;
+
+class ScrollbarWidget;
+class ListListener;
+class Font;
+
+class ListWidget : public Widget, public ScrollListener
+{
+public:
+ enum
+ {
+ JUSTIFY_LEFT =0,
+ JUSTIFY_CENTER,
+ JUSTIFY_RIGHT
+ };
+
+ enum
+ {
+ COLOR_BKG =0,
+ COLOR_OUTLINE,
+ COLOR_TEXT,
+ COLOR_HILITE,
+ COLOR_SELECT,
+ COLOR_SELECT_TEXT,
+ };
+
+public:
+ int mId;
+ Font* mFont;
+ ScrollbarWidget* mScrollbar;
+ int mJustify;
+
+ SexyStringVector mLines;
+ ColorVector mLineColors;
+ double mPosition;
+ double mPageSize;
+ int mHiliteIdx;
+ int mSelectIdx;
+ ListListener* mListListener;
+ ListWidget* mParent;
+ ListWidget* mChild;
+ bool mSortFromChild;
+ bool mDrawOutline;
+ int mMaxNumericPlaces;
+ int mItemHeight;
+
+ bool mDrawSelectWhenHilited;
+ bool mDoFingerWhenHilited;
+
+ void SetHilite(int theHiliteIdx, bool notifyListener = false);
+
+public:
+ ListWidget(int theId, Font *theFont, ListListener *theListListener);
+ virtual ~ListWidget();
+
+ virtual void RemovedFromManager(WidgetManager *theManager);
+
+ virtual SexyString GetSortKey(int theIdx);
+ virtual void Sort(bool ascending);
+ virtual SexyString GetStringAt(int theIdx);
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+ virtual int AddLine(const SexyString& theLine, bool alphabetical);
+ virtual void SetLine(int theIdx, const SexyString& theString);
+ virtual int GetLineCount();
+ virtual int GetLineIdx(const SexyString& theLine);
+ virtual void SetColor(const SexyString& theLine, const Color& theColor);
+ virtual void SetColor(int theIdx, const Color& theColor);
+ virtual void SetLineColor(int theIdx, const Color& theColor);
+ virtual void RemoveLine(int theIdx);
+ virtual void RemoveAll();
+ virtual int GetOptimalWidth();
+ virtual int GetOptimalHeight();
+ virtual void OrderInManagerChanged();
+ virtual void Draw(Graphics *g);
+ virtual void ScrollPosition(int theId, double thePosition);
+ virtual void MouseMove(int x, int y);
+ virtual void MouseWheel(int theDelta);
+ virtual void MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseLeave();
+ virtual void SetSelect(int theSelectIdx);
+};
+
+}
+
+#endif // __LISTWIDGET_H__
diff --git a/osframework/source/SexyAppFramework/MI_AdditiveBlt.inc b/osframework/source/SexyAppFramework/MI_AdditiveBlt.inc
new file mode 100644
index 0000000..35758d6
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_AdditiveBlt.inc
@@ -0,0 +1,110 @@
+{
+ ulong* aDestPixelsRow = ((ulong*) GetBits()) + (theY * mWidth) + theX;
+ SRC_TYPE* aSrcPixelsRow = aSrcBits + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ if (theColor == Color::White)
+ {
+ if (aSrcMemoryImage->mHasAlpha)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPtr = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = (src&0xFF000000)>>24;
+ int r = aMaxTable[((dest & 0xFF0000) + (((src & 0xFF0000)*a)>>8)) >> 16];
+ int g = aMaxTable[((dest & 0x00FF00) + (((src & 0x00FF00)*a)>>8)) >> 8 ];
+ int b = aMaxTable[((dest & 0x0000FF) + (((src & 0x0000FF)*a)>>8)) ];
+
+ *(aDestPixels++) = (dest & 0xFF000000) | (r << 16) | (g << 8) | (b);
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPtr = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxTable[((dest & 0xFF0000) + (src & 0xFF0000)) >> 16];
+ int g = aMaxTable[((dest & 0x00FF00) + (src & 0x00FF00)) >> 8 ];
+ int b = aMaxTable[((dest & 0x0000FF) + (src & 0x0000FF)) ];
+
+ *(aDestPixels++) = (dest & 0xFF000000) | (r << 16) | (g << 8) | (b);
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ if (aSrcMemoryImage->mHasAlpha)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPtr = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = (src&0xFF000000)>>24;
+ int r = aMaxTable[((dest & 0xFF0000) + (((((src & 0xFF0000) * cr) >> 8)*a)>>8)) >> 16];
+ int g = aMaxTable[((dest & 0x00FF00) + (((((src & 0x00FF00) * cg) >> 8)*a)>>8)) >> 8];
+ int b = aMaxTable[((dest & 0x0000FF) + (((((src & 0x0000FF) * cb) >> 8)*a)>>8)) ];
+
+ *(aDestPixels++) = (dest & 0xFF000000) | (r << 16) | (g << 8) | (b);
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ SRC_TYPE* aSrcPtr = aSrcPixelsRow;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxTable[((dest & 0xFF0000) + (((src & 0xFF0000) * cr) >> 8)) >> 16];
+ int g = aMaxTable[((dest & 0x00FF00) + (((src & 0x00FF00) * cg) >> 8)) >> 8];
+ int b = aMaxTable[((dest & 0x0000FF) + (((src & 0x0000FF) * cb) >> 8)) ];
+
+ *(aDestPixels++) = (dest & 0xFF000000) | (r << 16) | (g << 8) | (b);
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_BltRotated.inc b/osframework/source/SexyAppFramework/MI_BltRotated.inc
new file mode 100644
index 0000000..3873188
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_BltRotated.inc
@@ -0,0 +1,101 @@
+{
+ double aCos = cos(theRot);
+ double aSin = sin(theRot);
+
+ int aCosLong = (int) (aCos * 0x10000);
+ int aSinLong = (int) (aSin * 0x10000);
+
+
+ ulong* aDestPixelsRow = GetBits() + ((int)aDestRect.mY * mWidth) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mWidth;
+
+ if (theColor == Color::White)
+ {
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ int a = a1+a2+a3+a4; \
+ if(a==0) /* transparent */ \
+ aDestPixels++; \
+ else \
+ { \
+ ulong r = (((((src1&0xFF0000)*a1)) + (((src2&0xFF0000)*a2)) + (((src3&0xFF0000)*a3)) + (((src4&0xFF0000)*a4)))&0xFF000000); \
+ ulong g = (((((src1&0x00FF00)*a1)) + (((src2&0x00FF00)*a2)) + (((src3&0x00FF00)*a3)) + (((src4&0x00FF00)*a4)))&0x00FF0000); \
+ ulong b = (((((src1&0x0000FF)*a1)) + (((src2&0x0000FF)*a2)) + (((src3&0x0000FF)*a3)) + (((src4&0x0000FF)*a4)))&0x0000FF00); \
+ if(a > 250) /* opaque */ \
+ *aDestPixels++ = 0xFF000000 | (r>>8) | (g>>8) | (b>>8);\
+ else /* blend */ \
+ {\
+ ulong destPixel = *aDestPixels; \
+ ulong da = destPixel >> 24;\
+ \
+ ulong dr = (((destPixel&0xFF0000)*da)>>8) & 0xFF0000;\
+ ulong dg = (((destPixel&0x00FF00)*da)>>8) & 0x00FF00;\
+ ulong db = (((destPixel&0x0000FF)*da)>>8) & 0x0000FF;\
+ \
+ int finalAlpha = 256 - (((256 - a)*(256 - da))>>8);\
+ r = ((r + (256-a)*dr)/finalAlpha) & 0xFF0000;\
+ g = ((g + (256-a)*dg)/finalAlpha) & 0x00FF00;\
+ b = ((b + (256-a)*db)/finalAlpha) & 0x0000FF;\
+ \
+ *aDestPixels++ = ((finalAlpha-1)<<24) | r | g | b; \
+ }\
+ } \
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+
+
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = theColor.mRed + 1;
+ int cg = theColor.mGreen + 1;
+ int cb = theColor.mBlue + 1;
+
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ a1 = (a1*ca)>>8; a2 = (a2*ca)>>8; a3 = (a3*ca)>>8; a4 = (a4*ca)>>8; \
+ int a = a1+a2+a3+a4; \
+ \
+ if(a==0) /* transparent */ \
+ aDestPixels++; \
+ else \
+ { \
+ ulong r = (cr * (((((src1&0xFF0000)*a1)) + (((src2&0xFF0000)*a2)) + (((src3&0xFF0000)*a3)) + (((src4&0xFF0000)*a4)))>>8)) & 0xFF000000 ; \
+ ulong g = ((((((src1&0x00FF00)*a1)) + (((src2&0x00FF00)*a2)) + (((src3&0x00FF00)*a3)) + (((src4&0x00FF00)*a4)))&0x00FF0000) * cg) & 0xFF000000; \
+ ulong b = ((((((src1&0x0000FF)*a1)) + (((src2&0x0000FF)*a2)) + (((src3&0x0000FF)*a3)) + (((src4&0x0000FF)*a4)))&0x0000FF00) * cb) & 0x00FF0000; \
+ if(a > 250) /* opaque */ \
+ *aDestPixels++ = 0xFF000000 | (r>>8) | (g>>16) | (b>>16);\
+ else /* blend */ \
+ {\
+ ulong destPixel = *aDestPixels; \
+ ulong da = destPixel >> 24;\
+ \
+ ulong dr = (((destPixel&0xFF0000)*da)>>8) & 0xFF0000;\
+ ulong dg = (((destPixel&0x00FF00)*da)>>8) & 0x00FF00;\
+ ulong db = (((destPixel&0x0000FF)*da)>>8) & 0x0000FF;\
+ \
+ int finalAlpha = 256 - (((256 - a)*(256 - da))>>8);\
+ r = ((r + (256-a)*dr)/finalAlpha) & 0xFF0000;\
+ g = (((g>>8) + (256-a)*dg)/finalAlpha) & 0x00FF00;\
+ b = (((b>>8) + (256-a)*db)/finalAlpha) & 0x0000FF;\
+ \
+ *aDestPixels++ = ((finalAlpha-1)<<24) | r | g | b; \
+ }\
+ } \
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+
+
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_BltRotated_Additive.inc b/osframework/source/SexyAppFramework/MI_BltRotated_Additive.inc
new file mode 100644
index 0000000..a22b75b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_BltRotated_Additive.inc
@@ -0,0 +1,71 @@
+{
+ double aCos = cos(theRot);
+ double aSin = sin(theRot);
+
+ int aCosLong = (int) (aCos * 0x10000);
+ int aSinLong = (int) (aSin * 0x10000);
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ int aRotCenterXLong = (int)(theRotCenterX * 0x10000);
+ int aRotCenterYLong = (int)(theRotCenterY * 0x10000);
+#endif
+
+ ulong* aDestPixelsRow = GetBits() + ((int)aDestRect.mY * mWidth) + (int)aDestRect.mX;
+ int aDestPixelsPitch = mWidth;
+
+ if (theColor == Color::White)
+ {
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ ulong dest = *aDestPixels;\
+ int a = a1+a2+a3+a4; \
+ if(a==0) /* transparent */ \
+ aDestPixels++;\
+ else \
+ { \
+ ulong r = aMaxTable[((((src1&0xFF0000)*a1) + ((src2&0xFF0000)*a2) + ((src3&0xFF0000)*a3) + ((src4&0xFF0000)*a4))>>24) + ((dest&0xFF0000)>>16)]; \
+ ulong g = aMaxTable[((((src1&0x00FF00)*a1) + ((src2&0x00FF00)*a2) + ((src3&0x00FF00)*a3) + ((src4&0x00FF00)*a4))>>16) + ((dest&0x00FF00)>>8)]; \
+ ulong b = aMaxTable[((((src1&0x0000FF)*a1) + ((src2&0x0000FF)*a2) + ((src3&0x0000FF)*a3) + ((src4&0x0000FF)*a4))>>8) + (dest&0x0000FF)]; \
+ \
+ *aDestPixels++ = (dest & 0xFF000000) | (r<<16) | (g<<8) | b; \
+ } \
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = (theColor.mRed * ca) / 255;
+ int cg = (theColor.mGreen * ca) / 255;
+ int cb = (theColor.mBlue * ca) / 255;
+
+ #define DEST_PIXEL_TYPE ulong
+ #define WRITE_PIXEL\
+ {\
+ ulong dest = *aDestPixels;\
+ int a = a1+a2+a3+a4; \
+ if(a==0) /* transparent */ \
+ aDestPixels++; \
+ else \
+ { \
+ ulong destPixel = *aDestPixels; \
+ \
+ ulong r = aMaxTable[((((((src1&0xFF0000)*a1) + ((src2&0xFF0000)*a2) + ((src3&0xFF0000)*a3) + ((src4&0xFF0000)*a4))>>24)*cr)>>8) + ((dest&0xFF0000)>>16)]; \
+ ulong g = aMaxTable[(((((src1&0x00FF00)*a1) + ((src2&0x00FF00)*a2) + ((src3&0x00FF00)*a3) + ((src4&0x00FF00)*a4))*cg)>>24) + ((dest&0x00FF00)>>8)]; \
+ ulong b = aMaxTable[(((((src1&0x0000FF)*a1) + ((src2&0x0000FF)*a2) + ((src3&0x0000FF)*a3) + ((src4&0x0000FF)*a4))*cb)>>16) + (dest&0x0000FF)]; \
+ \
+ *aDestPixels++ = (dest & 0xFF000000) | (r<<16) | (g<<8) | b; \
+ }\
+ }
+
+ #include "BltRotatedHelper.inc"
+
+ #undef WRITE_PIXEL
+ #undef DEST_PIXEL_TYPE
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_GetNativeAlphaData.inc b/osframework/source/SexyAppFramework/MI_GetNativeAlphaData.inc
new file mode 100644
index 0000000..cbf8e8b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_GetNativeAlphaData.inc
@@ -0,0 +1,44 @@
+{
+ ulong* anAlphaData = new ulong[mWidth*mHeight];
+
+ if (theNumBits == 16)
+ {
+ for (int i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = NEXT_SRC_COLOR;
+
+ int anAlpha = val >> 24;
+
+ int r = ((val >> 16) & 0xFF) * anAlpha >> 8;
+ int g = ((val >> 8 ) & 0xFF) * anAlpha >> 8;
+ int b = ((val ) & 0xFF) * anAlpha >> 8;
+
+ anAlphaData[i] =
+ ((((r * theRMask) >> 8) & theRMask) |
+ (((g * theGMask) >> 8) & theGMask) |
+ (((b * theBMask) >> 8) & theBMask) |
+ (anAlpha << 24));
+ }
+ }
+ else if (theNumBits == 32)
+ {
+ for (int i = 0; i < mWidth*mHeight; i++)
+ {
+ ulong val = NEXT_SRC_COLOR;
+
+ int anAlpha = val >> 24;
+
+ int r = (((val >> 16) & 0xFF) * anAlpha) >> 8;
+ int g = (((val >> 8 ) & 0xFF) * anAlpha) >> 8;
+ int b = (((val ) & 0xFF) * anAlpha) >> 8;
+
+ anAlphaData[i] =
+ (((r * theRMask) >> 8) & theRMask) |
+ (((g * theGMask) >> 8) & theGMask) |
+ (((b * theBMask) >> 8) & theBMask) |
+ (anAlpha << 24);
+ }
+ }
+
+ mNativeAlphaData = anAlphaData;
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_GetRLAlphaData.inc b/osframework/source/SexyAppFramework/MI_GetRLAlphaData.inc
new file mode 100644
index 0000000..2dcf3ec
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_GetRLAlphaData.inc
@@ -0,0 +1,52 @@
+{
+
+ uchar* aWPtr = mRLAlphaData;
+
+ if (mWidth==1)
+ {
+ memset(aWPtr,1,mHeight);
+ }
+ else
+ {
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ int aRCount = 1;
+ int aRLCount = 1;
+
+ int anAVal = NEXT_SRC_COLOR >> 24;
+ int aLastAClass = (anAVal == 0) ? 0 : (anAVal == 255) ? 1 : 2;
+
+ while (aRCount < mWidth)
+ {
+ aRCount++;
+
+ anAVal = NEXT_SRC_COLOR >> 24;
+ int aThisAClass = (anAVal == 0) ? 0 : (anAVal == 255) ? 1 : 2;
+
+ if ((aThisAClass != aLastAClass) || (aRCount == mWidth))
+ {
+ if (aThisAClass == aLastAClass)
+ aRLCount++;
+
+ for (int i = aRLCount; i > 0; i--)
+ {
+ if (i >= 255)
+ *aWPtr++ = 255;
+ else
+ *aWPtr++ = i;
+ }
+
+ if ((aRCount == mWidth) && (aThisAClass != aLastAClass))
+ *aWPtr++ = 1;
+
+ aLastAClass = aThisAClass;
+ aRLCount = 1;
+ }
+ else
+ {
+ aRLCount++;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_NormalBlt.inc b/osframework/source/SexyAppFramework/MI_NormalBlt.inc
new file mode 100644
index 0000000..7ab3a0a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_NormalBlt.inc
@@ -0,0 +1,222 @@
+{
+ ulong* aDestPixelsRow = ((ulong*) GetBits()) + (theY * mWidth) + theX;
+
+ if ((mHasAlpha) || (mHasTrans) || (theColor != Color::White))
+ {
+ if (theColor == Color::White)
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+ EACH_ROW;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+
+ if (a != 0)
+ {
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+ a = 255 * a / aNewDestAlpha;
+
+ int oma = 256 - a;
+
+ // TODO: To avoid rounding problems for fully opaque pixels use (a+1) instead of a in the code below since we are dividing by 256
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ ((((dest & 0xFF00FF) * oma >> 8) + ((src & 0xFF00FF) * a >> 8)) & 0xFF00FF) |
+ ((((dest & 0x00FF00) * oma >> 8) + ((src & 0x00FF00) * a >> 8)) & 0x00FF00);
+#else
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * a) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * a) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((src & 0xFF0000) * a) >> 8) & 0xFF0000);
+#endif
+ }
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ else
+ {
+ int ca = theColor.mAlpha;
+ int cr = theColor.mRed;
+ int cg = theColor.mGreen;
+ int cb = theColor.mBlue;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ bool performNormalBlit = true;
+ if (cr == cg && cg == cb)
+ {
+ performNormalBlit = false;
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ EACH_ROW;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = ((src >> 24) * ca) / 255;
+
+ if (a != 0)
+ {
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+
+ a = 255 * a / aNewDestAlpha;
+
+ int oma = 256 - a;
+
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0xFF00FF) * oma >> 8) + ((((src & 0xFF00FF) * cr >> 8) & 0xFF00FF) * a >> 8)) & 0xFF00FF) |
+ ((((dest & 0x00FF00) * oma >> 8) + ((src & 0x00FF00) * cr * a >> 16)) & 0x00FF00);
+ }
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ if (performNormalBlit)
+#endif
+ {
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ EACH_ROW;
+
+ for (int x = 0; x < theSrcRect.mWidth; x++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ ulong dest = *aDestPixels;
+
+ int a = ((src >> 24) * ca) / 255;
+
+ if (a != 0)
+ {
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+
+ a = 255 * a / aNewDestAlpha;
+
+ int oma = 256 - a;
+
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * a * cb) >> 16) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * a * cg) >> 16) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((((src & 0xFF0000) * a) >> 8) * cr) >> 8) & 0xFF0000);
+ }
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ }
+ }
+ }
+ }
+ else
+ {
+ uchar* aSrcRLAlphaData = aSrcMemoryImage->GetRLAlphaData();
+ uchar* aRLAlphaDataRow = aSrcRLAlphaData + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ for (int y = 0; y < theSrcRect.mHeight; y++)
+ {
+ ulong* aDestPixels = aDestPixelsRow;
+
+ EACH_ROW;
+
+ uchar* aRLAlphaData = aRLAlphaDataRow;
+
+ for (int aSpanLeft = theSrcRect.mWidth; aSpanLeft > 0; )
+ {
+ ulong src = READ_SRC_COLOR;
+ uchar rl = *aRLAlphaData;
+
+ if (rl > aSpanLeft)
+ rl = aSpanLeft;
+
+ int oma = 256 - (src >> 24);
+
+ if (oma == 1) // Fully opaque
+ {
+ for (int i = 0; i < rl; i++)
+ *aDestPixels++ = NEXT_SRC_COLOR;
+ }
+ else if (oma == 256) // Fully transparent
+ {
+ aDestPixels += rl;
+ aSrcPtr += rl;
+ }
+ else // Partially transparent
+ {
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ int a = 256 - oma;
+
+ aSrcPtr++;
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = (0xFF000000) |
+ ((((dest & 0xFF00FF) * oma >> 8) + ((src & 0xFF00FF) * a >> 8)) & 0xFF00FF) |
+ ((((dest & 0x00FF00) * oma >> 8) + ((src & 0x00FF00) * a >> 8)) & 0x00FF00);
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int a = (src >> 24);
+ int oma = 256 - a;
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = (0xFF000000) |
+ ((((dest & 0xFF00FF) * oma >> 8) + ((src & 0xFF00FF) * a >> 8)) & 0xFF00FF) |
+ ((((dest & 0x00FF00) * oma >> 8) + ((src & 0x00FF00) * a >> 8)) & 0x00FF00);
+ }
+#else
+ int a = 256 - oma;
+
+ aSrcPtr++;
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = (0xFF000000) |
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * a) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * a) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((src & 0xFF0000) * a) >> 8) & 0xFF0000);
+
+ for (int i = 1; i < rl; i++)
+ {
+ ulong src = NEXT_SRC_COLOR;
+ int a = (src >> 24);
+ int oma = 256 - a;
+
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = (0xFF000000) |
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * a) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * a) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((src & 0xFF0000) * a) >> 8) & 0xFF0000);
+ }
+#endif
+ }
+
+ aRLAlphaData += rl;
+ aSpanLeft -= rl;
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcPixelsRow += theImage->mWidth;
+ aRLAlphaDataRow += theImage->mWidth;
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MI_SlowStretchBlt.inc b/osframework/source/SexyAppFramework/MI_SlowStretchBlt.inc
new file mode 100644
index 0000000..8abd7ab
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MI_SlowStretchBlt.inc
@@ -0,0 +1,276 @@
+{
+ ulong* aDestBits = GetBits();
+
+ int aSrcRowWidth = aSrcMemoryImage->GetWidth();
+
+ int aSrcXI = (int) floor(theSrcRect.mX);
+ int aSrcYI = (int) floor(theSrcRect.mY);
+ int aSrcWidthI = (int) ceil(theSrcRect.mWidth + (theSrcRect.mX - aSrcXI));
+ int aSrcHeightI = (int) ceil(theSrcRect.mHeight + (theSrcRect.mY - aSrcYI));
+
+ if (aSrcXI<0) aSrcXI = 0;
+ if (aSrcYI<0) aSrcYI = 0;
+ if (aSrcXI + aSrcWidthI > theImage->mWidth) aSrcWidthI = theImage->mWidth - aSrcXI;
+ if (aSrcYI + aSrcHeightI > theImage->mHeight) aSrcHeightI = theImage->mHeight - aSrcYI;
+ if (aSrcWidthI<=0 || aSrcHeightI<=0)
+ return;
+
+ int aTempDestWidth = theDestRect.mWidth+4;
+ int aTempDestHeight = theDestRect.mHeight+4;
+
+ // For holding horizontally resized pixels not vertically (yet)
+ ulong* aNewHorzPixels = new ulong[aTempDestWidth*aSrcHeightI*4];
+
+ ulong* aNewHorzPixelsEnd = aNewHorzPixels + (aTempDestWidth*aSrcHeightI*4);
+
+ ZeroMemory(aNewHorzPixels, aTempDestWidth*aSrcHeightI*4*4);
+
+ int aSrcImageWidth = theImage->GetWidth();
+
+ if (theSrcRect.mWidth >= theDestRect.mWidth)
+ {
+ double aDestXFactor = theDestRect.mWidth / theSrcRect.mWidth;
+ double aDestXOffset = 1.0 + (aSrcXI - theSrcRect.mX) * aDestXFactor;
+
+ // Shrinking
+
+ for (int aSrcX = 0; aSrcX < aSrcWidthI; aSrcX++)
+ {
+ double aDestX1 = aDestXFactor * aSrcX + aDestXOffset;
+ double aDestX2 = aDestX1 + aDestXFactor;
+
+ int aDestXI1 = (int) aDestX1;
+ int aDestXI2 = (int) aDestX2;
+
+ SRC_TYPE* s1 = &aSrcBits[aSrcYI*aSrcRowWidth + aSrcXI+aSrcX];
+
+ if (aDestXI1 == aDestXI2)
+ {
+ ulong* d = &aNewHorzPixels[aDestXI1*4];
+ int aFactor = (int) (257 * aDestXFactor);
+
+ for (int aSrcY = 0; aSrcY < aSrcHeightI; aSrcY++)
+ {
+ ulong pixel = READ_COLOR(s1);
+
+ *d++ += aFactor * ((pixel ) & 0xFF);
+ *d++ += aFactor * ((pixel >> 8) & 0xFF);
+ *d++ += aFactor * ((pixel >> 16) & 0xFF);
+ *d++ += aFactor * ((pixel >> 24) & 0xFF);
+
+ DBG_ASSERTE(d <= aNewHorzPixelsEnd);
+
+ d += aTempDestWidth*4 - 4;
+ s1 += aSrcRowWidth;
+ }
+ }
+ else
+ {
+ int aFactor1 = (int) (257 * (aDestXI2 - aDestX1));
+ int aFactor2 = (int) (257 * (aDestX2 - aDestXI2));
+
+ ulong* d = &aNewHorzPixels[aDestXI1*4];
+
+ for (int aSrcY = 0; aSrcY < aSrcHeightI; aSrcY++)
+ {
+ ulong pixel = READ_COLOR(s1);
+
+ *d++ += aFactor1 * ((pixel ) & 0xFF);
+ *d++ += aFactor1 * ((pixel >> 8) & 0xFF);
+ *d++ += aFactor1 * ((pixel >> 16) & 0xFF);
+ *d++ += aFactor1 * ((pixel >> 24) & 0xFF);
+
+ *d++ += aFactor2 * ((pixel ) & 0xFF);
+ *d++ += aFactor2 * ((pixel >> 8) & 0xFF);
+ *d++ += aFactor2 * ((pixel >> 16) & 0xFF);
+ *d++ += aFactor2 * ((pixel >> 24) & 0xFF);
+
+ DBG_ASSERTE(d <= aNewHorzPixelsEnd);
+
+ d += aTempDestWidth*4 - 8;
+ s1 += aSrcRowWidth;
+ }
+ }
+ }
+ }
+ else
+ {
+ double aSrcXFactor;
+ if (theDestRect.mWidth != 1)
+ aSrcXFactor = (theSrcRect.mWidth - 1) / (theDestRect.mWidth - 1);
+ else
+ aSrcXFactor = (theSrcRect.mWidth) / (theDestRect.mWidth);
+
+ for (int aDestX = 1; aDestX < aTempDestWidth-1; aDestX++)
+ {
+ ulong* d = &aNewHorzPixels[aDestX*4];
+
+ double aSrcX = (aDestX - 1)*aSrcXFactor + theSrcRect.mX;
+ int aSrcXI = (int) aSrcX;
+
+ int aFactor1 = (int) (257 * (1.0 - (aSrcX - aSrcXI)));
+ int aFactor2 = (int) (257 - aFactor1);
+
+ SRC_TYPE* s = &aSrcBits[aSrcYI*aSrcRowWidth+aSrcXI];
+
+ for (int aDestY = 0; aDestY < aSrcHeightI; aDestY++)
+ {
+ ulong pixel1 = READ_COLOR(s++);
+ ulong pixel2 = READ_COLOR(s);
+
+ *d++ = (aFactor1 * ((pixel1 ) & 0xFF)) + (aFactor2 * ((pixel2 ) & 0xFF));
+ *d++ = (aFactor1 * ((pixel1 >> 8) & 0xFF)) + (aFactor2 * ((pixel2 >> 8) & 0xFF));
+ *d++ = (aFactor1 * ((pixel1 >> 16) & 0xFF)) + (aFactor2 * ((pixel2 >> 16) & 0xFF));
+ *d++ = (aFactor1 * ((pixel1 >> 24) & 0xFF)) + (aFactor2 * ((pixel2 >> 24) & 0xFF));
+
+ DBG_ASSERTE(d <= aNewHorzPixelsEnd);
+
+ d += aTempDestWidth*4 - 4;
+ s += aSrcRowWidth - 1;
+ }
+ }
+ }
+
+ ulong* aNewPixels = new ulong[aTempDestWidth*aTempDestHeight*4];
+
+ ulong* aNewPixelsEnd = aNewPixels + (aTempDestWidth*aTempDestHeight*4);
+
+ ZeroMemory(aNewPixels, aTempDestWidth*aTempDestHeight*4*4);
+
+ // Now resize vertically
+ if (theSrcRect.mHeight >= theDestRect.mHeight)
+ {
+ double aDestYFactor = theDestRect.mHeight / theSrcRect.mHeight;
+
+ double aDestYOffset = 1.0 + (aSrcYI - theSrcRect.mY) * aDestYFactor;
+
+ for (int aSrcY = 0; aSrcY < aSrcHeightI; aSrcY++)
+ {
+ double aDestY1 = aDestYFactor * aSrcY + aDestYOffset;
+ double aDestY2 = aDestY1 + aDestYFactor;
+
+ int aDestYI1 = (int) floor(aDestY1);
+ int aDestYI2 = (int) floor(aDestY2);
+
+ ulong* s = &aNewHorzPixels[aSrcY*aTempDestWidth*4];
+
+ if (aDestYI1 == aDestYI2)
+ {
+ ulong* d = &aNewPixels[aDestYI1*aTempDestWidth*4];
+ int aFactor = (int) (256 * aDestYFactor);
+
+ for (int aSrcX = 0; aSrcX < aTempDestWidth; aSrcX++)
+ {
+ *d++ += aFactor * *s++;
+ *d++ += aFactor * *s++;
+ *d++ += aFactor * *s++;
+ *d++ += aFactor * *s++;
+ }
+
+ DBG_ASSERTE(d <= aNewPixelsEnd);
+ }
+ else
+ {
+ int aFactor1 = (int) (256 * (aDestYI2 - aDestY1));
+ int aFactor2 = (int) (256 * (aDestY2 - aDestYI2));
+
+ ulong* d1 = &aNewPixels[aDestYI1*aTempDestWidth*4];
+ ulong* d2 = &aNewPixels[aDestYI2*aTempDestWidth*4];
+
+ for (int aSrcX = 0; aSrcX < aTempDestWidth; aSrcX++)
+ {
+ *d1++ += aFactor1 * *s;
+ *d2++ += aFactor2 * *s++;
+
+ *d1++ += aFactor1 * *s;
+ *d2++ += aFactor2 * *s++;
+
+ *d1++ += aFactor1 * *s;
+ *d2++ += aFactor2 * *s++;
+
+ *d1++ += aFactor1 * *s;
+ *d2++ += aFactor2 * *s++;
+ }
+
+ DBG_ASSERTE(d1 <= aNewPixelsEnd);
+ DBG_ASSERTE(d2 <= aNewPixelsEnd);
+ }
+ }
+ }
+ else
+ {
+ double aSrcYFactor;
+ if (theDestRect.mHeight != 1)
+ aSrcYFactor = (theSrcRect.mHeight - 1) / (theDestRect.mHeight - 1);
+ else
+ aSrcYFactor = (theSrcRect.mHeight) / (theDestRect.mHeight);
+
+ for (int aDestY = 1; aDestY < theDestRect.mHeight + 1; aDestY++)
+ {
+ ulong* d = &aNewPixels[(aDestY*aTempDestWidth+1)*4];
+
+ double aSrcY = (aDestY-1)*aSrcYFactor + (theSrcRect.mY - ((int) theSrcRect.mY));
+ int aSrcYI = (int) aSrcY;
+
+ int aFactor1 = (int) (256 * (1.0 - (aSrcY - aSrcYI)));
+ int aFactor2 = 256 - aFactor1;
+
+ ulong* s1 = &aNewHorzPixels[(aSrcYI*aTempDestWidth+1)*4];
+ ulong* s2;
+
+ if (aSrcYI == aSrcHeightI - 1)
+ s2 = s1;
+ else
+ s2 = &aNewHorzPixels[((aSrcYI+1)*aTempDestWidth+1)*4];
+
+ for (int aDestX = 1; aDestX < aTempDestWidth-1; aDestX++)
+ {
+ *d++ = (aFactor1 * *s1++) + (aFactor2 * *s2++);
+ *d++ = (aFactor1 * *s1++) + (aFactor2 * *s2++);
+ *d++ = (aFactor1 * *s1++) + (aFactor2 * *s2++);
+ *d++ = (aFactor1 * *s1++) + (aFactor2 * *s2++);
+ }
+ }
+ }
+
+
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ ulong* aDestPixels = &aDestBits[(theDestRect.mY+y)*mWidth+theDestRect.mX];
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ ulong *p = &aNewPixels[((y+1)*aTempDestWidth+x+1)*4];
+
+ int b = (*p++) >> 16;
+ int g = (*p++) >> 16;
+ int r = (*p++) >> 16;
+ int a = (*p++) >> 16;
+
+ /*aDestBits[(theDestRect.mY+y)*mWidth+theDestRect.mX+x] =
+ (r) | (g << 8) | (b << 16) | (a << 24);*/
+
+ if (a != 0)
+ {
+ ulong dest = *aDestPixels;
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+
+ //a = 255 * a / (a + aDestAlpha);
+ int oma = 256 - a;
+
+ DBG_ASSERTE(aDestPixels < aDestEnd);
+
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ (((((dest & 0x0000FF) * oma) >> 8) & 0x0000FF) + (((b * a) >> 8))) |
+ (((((dest & 0x00FF00) * oma) >> 8) & 0x00FF00) + (((g * a) >> 8) << 8)) |
+ (((((dest & 0xFF0000) * oma) >> 8) & 0xFF0000) + (((r * a) >> 8) << 16));
+ }
+ else
+ aDestPixels++;
+ }
+ }
+
+ delete[] aNewPixels;
+ delete[] aNewHorzPixels;
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MTRand.cpp b/osframework/source/SexyAppFramework/MTRand.cpp
new file mode 100644
index 0000000..c5e6b5c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MTRand.cpp
@@ -0,0 +1,197 @@
+/*
+Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. The names of its contributors may not be used to endorse or promote
+products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+Any feedback is very welcome.
+http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
+email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
+*/
+
+#include <windows.h>
+#include "MTRand.h"
+#include "Debug.h"
+#include <stdio.h>
+
+using namespace Sexy;
+
+/* Period parameters */
+#define MTRAND_M 397
+#define MATRIX_A 0x9908b0dfUL /* constant vector a */
+#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
+#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
+
+/* Tempering parameters */
+#define TEMPERING_MASK_B 0x9d2c5680
+#define TEMPERING_MASK_C 0xefc60000
+#define TEMPERING_SHIFT_U(y) (y >> 11)
+#define TEMPERING_SHIFT_S(y) (y << 7)
+#define TEMPERING_SHIFT_T(y) (y << 15)
+#define TEMPERING_SHIFT_L(y) (y >> 18)
+
+
+MTRand::MTRand(const std::string& theSerialData)
+{
+ SRand(theSerialData);
+ mti=MTRAND_N+1; /* mti==MTRAND_N+1 means mt[MTRAND_N] is not initialized */
+}
+
+MTRand::MTRand(unsigned long seed)
+{
+ SRand(seed);
+}
+
+MTRand::MTRand()
+{
+ SRand(4357);
+}
+
+static int gRandAllowed = 0;
+void MTRand::SetRandAllowed(bool allowed)
+{
+ if (allowed)
+ {
+ if (gRandAllowed>0)
+ gRandAllowed--;
+ else
+ DBG_ASSERT(false); // mismatched calls
+ }
+ else
+ gRandAllowed++;
+}
+
+void MTRand::SRand(const std::string& theSerialData)
+{
+ if (theSerialData.size() == MTRAND_N*4)
+ {
+ memcpy(mt, theSerialData.c_str(), MTRAND_N*4);
+ }
+ else
+ SRand(4357);
+}
+
+void MTRand::SRand(unsigned long seed)
+{
+ if (seed == 0)
+ seed = 4357;
+
+ /* setting initial seeds to mt[MTRAND_N] using */
+ /* the generator Line 25 of Table 1 in */
+ /* [KNUTH 1981, The Art of Computer Programming */
+ /* Vol. 2 (2nd Ed.), pp102] */
+ mt[0]= seed & 0xffffffffUL;
+ for (mti=1; mti< MTRAND_N; mti++)
+ {
+ mt[mti] =
+ (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
+ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
+ /* In the previous versions, MSBs of the seed affect */
+ /* only MSBs of the array mt[]. */
+ /* 2002/01/09 modified by Makoto Matsumoto */
+ mt[mti] &= 0xffffffffUL;
+ /* for >32 bit machines */
+ }
+}
+
+unsigned long MTRand::Next()
+{
+ DBG_ASSERT(gRandAllowed==0);
+ return NextNoAssert();
+}
+
+unsigned long MTRand::NextNoAssert()
+{
+ unsigned long y;
+ static unsigned long mag01[2]={0x0, MATRIX_A};
+ /* mag01[x] = x * MATRIX_A for x=0,1 */
+
+ if (mti >= MTRAND_N) { /* generate MTRAND_N words at one time */
+ int kk;
+
+ for (kk=0;kk<MTRAND_N-MTRAND_M;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+MTRAND_M] ^ (y >> 1) ^ mag01[y & 0x1UL];
+ }
+ for (;kk<MTRAND_N-1;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+(MTRAND_M-MTRAND_N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
+ }
+ y = (mt[MTRAND_N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
+ mt[MTRAND_N-1] = mt[MTRAND_M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
+
+ mti = 0;
+ }
+
+ y = mt[mti++];
+ y ^= TEMPERING_SHIFT_U(y);
+ y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
+ y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
+ y ^= TEMPERING_SHIFT_L(y);
+
+ y &= 0x7FFFFFFF;
+
+ /*char aStr[256];
+ sprintf(aStr, "Rand=%d\r\n", y);
+ OutputDebugString(aStr);*/
+
+ return y;
+}
+
+unsigned long MTRand::NextNoAssert(unsigned long range)
+{
+ return NextNoAssert() % range;
+}
+
+unsigned long MTRand::Next(unsigned long range)
+{
+ DBG_ASSERT(gRandAllowed==0);
+ return NextNoAssert( range );
+}
+
+float MTRand::NextNoAssert(float range)
+{
+ return (float) ((double)NextNoAssert() / (double)0x7FFFFFFF * range);
+}
+
+float MTRand::Next(float range)
+{
+ DBG_ASSERT(gRandAllowed==0);
+ return NextNoAssert(range);
+}
+
+std::string MTRand::Serialize()
+{
+ std::string aString;
+
+ aString.resize(MTRAND_N*4);
+ memcpy((char*) aString.c_str(), mt, MTRAND_N*4);
+
+ return aString;
+}
diff --git a/osframework/source/SexyAppFramework/MTRand.h b/osframework/source/SexyAppFramework/MTRand.h
new file mode 100644
index 0000000..d01aa81
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MTRand.h
@@ -0,0 +1,43 @@
+#ifndef __MTRAND_H__
+#define __MTRAND_H__
+
+#include <string>
+
+namespace Sexy
+{
+
+#define MTRAND_N 624
+
+class MTRand
+{
+ unsigned long mt[MTRAND_N]; /* the array for the state vector */
+ int mti;
+
+public:
+ MTRand(const std::string& theSerialData);
+ MTRand(unsigned long seed);
+ MTRand();
+
+ void SRand(const std::string& theSerialData);
+ void SRand(unsigned long seed);
+ unsigned long NextNoAssert();
+ unsigned long Next();
+ unsigned long NextNoAssert(unsigned long range);
+ unsigned long Next(unsigned long range);
+ float NextNoAssert(float range);
+ float Next( float range );
+
+ std::string Serialize();
+
+ static void SetRandAllowed(bool allowed);
+};
+
+struct MTAutoDisallowRand
+{
+ MTAutoDisallowRand() { MTRand::SetRandAllowed(false); }
+ ~MTAutoDisallowRand() { MTRand::SetRandAllowed(true); }
+};
+
+}
+
+#endif //__MTRAND_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MemoryImage.cpp b/osframework/source/SexyAppFramework/MemoryImage.cpp
new file mode 100644
index 0000000..fcf8258
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MemoryImage.cpp
@@ -0,0 +1,1918 @@
+#include "MemoryImage.h"
+
+#include "SexyAppBase.h"
+#include "Graphics.h"
+#include "NativeDisplay.h"
+#include "Debug.h"
+#include "Quantize.h"
+#include "PerfTimer.h"
+#include "SWTri.h"
+
+#include <math.h>
+
+using namespace Sexy;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+bool gOptimizeSoftwareDrawing = false;
+#endif
+
+
+// Disable macro redefinition warning
+#pragma warning(disable:4005)
+
+MemoryImage::MemoryImage()
+{
+ mApp = gSexyAppBase;
+
+ Init();
+}
+
+MemoryImage::MemoryImage(SexyAppBase* theApp)
+{
+ mApp = theApp;
+ Init();
+}
+
+MemoryImage::MemoryImage(const MemoryImage& theMemoryImage) :
+ Image(theMemoryImage),
+ mApp(theMemoryImage.mApp),
+ mHasAlpha(theMemoryImage.mHasAlpha),
+ mHasTrans(theMemoryImage.mHasTrans),
+ mBitsChanged(theMemoryImage.mBitsChanged),
+ mIsVolatile(theMemoryImage.mIsVolatile),
+ mPurgeBits(theMemoryImage.mPurgeBits),
+ mWantPal(theMemoryImage.mWantPal),
+ mD3DFlags(theMemoryImage.mD3DFlags),
+ mBitsChangedCount(theMemoryImage.mBitsChangedCount),
+ mD3DData(NULL)
+{
+ bool deleteBits = false;
+
+ MemoryImage* aNonConstMemoryImage = (MemoryImage*) &theMemoryImage;
+
+ if ((theMemoryImage.mBits == NULL) && (theMemoryImage.mColorTable == NULL))
+ {
+ // Must be a DDImage with only a DDSurface
+ aNonConstMemoryImage->GetBits();
+ deleteBits = true;
+ }
+
+ if (theMemoryImage.mBits != NULL)
+ {
+ mBits = new ulong[mWidth*mHeight + 1];
+ mBits[mWidth*mHeight] = MEMORYCHECK_ID;
+ memcpy(mBits, theMemoryImage.mBits, (mWidth*mHeight + 1)*sizeof(ulong));
+ }
+ else
+ mBits = NULL;
+
+ if (deleteBits)
+ {
+ // Remove the temporary source bits
+ delete [] aNonConstMemoryImage->mBits;
+ aNonConstMemoryImage->mBits = NULL;
+ }
+
+ if (theMemoryImage.mColorTable != NULL)
+ {
+ mColorTable = new ulong[256];
+ memcpy(mColorTable, theMemoryImage.mColorTable, 256*sizeof(ulong));
+ }
+ else
+ mColorTable = NULL;
+
+ if (theMemoryImage.mColorIndices != NULL)
+ {
+ mColorIndices = new uchar[mWidth*mHeight];
+ memcpy(mColorIndices, theMemoryImage.mColorIndices, mWidth*mHeight*sizeof(uchar));
+ }
+ else
+ mColorIndices = NULL;
+
+ if (theMemoryImage.mNativeAlphaData != NULL)
+ {
+ if (theMemoryImage.mColorTable == NULL)
+ {
+ mNativeAlphaData = new ulong[mWidth*mHeight];
+ memcpy(mNativeAlphaData, theMemoryImage.mNativeAlphaData, mWidth*mHeight*sizeof(ulong));
+ }
+ else
+ {
+ mNativeAlphaData = new ulong[256];
+ memcpy(mNativeAlphaData, theMemoryImage.mNativeAlphaData, 256*sizeof(ulong));
+ }
+ }
+ else
+ mNativeAlphaData = NULL;
+
+ if (theMemoryImage.mRLAlphaData != NULL)
+ {
+ mRLAlphaData = new uchar[mWidth*mHeight];
+ memcpy(mRLAlphaData, theMemoryImage.mRLAlphaData, mWidth*mHeight);
+ }
+ else
+ mRLAlphaData = NULL;
+
+ if (theMemoryImage.mRLAdditiveData != NULL)
+ {
+ mRLAdditiveData = new uchar[mWidth*mHeight];
+ memcpy(mRLAdditiveData, theMemoryImage.mRLAdditiveData, mWidth*mHeight);
+ }
+ else
+ mRLAdditiveData = NULL;
+
+ mApp->AddMemoryImage(this);
+}
+
+MemoryImage::~MemoryImage()
+{
+ mApp->RemoveMemoryImage(this);
+
+ delete [] mBits;
+ delete [] mNativeAlphaData;
+ delete [] mRLAlphaData;
+ delete [] mRLAdditiveData;
+ delete [] mColorIndices;
+ delete [] mColorTable;
+}
+
+void MemoryImage::Init()
+{
+ mBits = NULL;
+ mColorTable = NULL;
+ mColorIndices = NULL;
+
+ mNativeAlphaData = NULL;
+ mRLAlphaData = NULL;
+ mRLAdditiveData = NULL;
+ mHasTrans = false;
+ mHasAlpha = false;
+ mBitsChanged = false;
+ mForcedMode = false;
+ mIsVolatile = false;
+
+ mD3DData = NULL;
+ mD3DFlags = 0;
+ mBitsChangedCount = 0;
+
+ mPurgeBits = false;
+ mWantPal = false;
+
+ mApp->AddMemoryImage(this);
+}
+
+void MemoryImage::BitsChanged()
+{
+ mBitsChanged = true;
+ mBitsChangedCount++;
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+
+ delete [] mRLAlphaData;
+ mRLAlphaData = NULL;
+
+ delete [] mRLAdditiveData;
+ mRLAdditiveData = NULL;
+
+ // Verify secret value at end to protect against overwrite
+ if (mBits != NULL)
+ {
+ DBG_ASSERTE(mBits[mWidth*mHeight] == MEMORYCHECK_ID);
+ }
+}
+
+void MemoryImage::NormalDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ double aMinX = min(theStartX, theEndX);
+ double aMinY = min(theStartY, theEndY);
+ double aMaxX = max(theStartX, theEndX);
+ double aMaxY = max(theStartY, theEndY);
+
+ ulong aRMask = 0xFF0000;
+ ulong aGMask = 0x00FF00;
+ ulong aBMask = 0x0000FF;
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ DWORD *aSurface = GetBits();
+
+ if (true)//(mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ if (theColor.mAlpha == 255)
+ {
+ ulong aColor = 0xFF000000 |
+ ((((theColor.mRed * aRMask) + aRRoundAdd) >> 8) & aRMask) |
+ ((((theColor.mGreen * aGMask) + aGRoundAdd) >> 8) & aGMask) |
+ ((((theColor.mBlue * aBMask) + aBRoundAdd) >> 8) & aBMask);
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mWidth;
+ int aRowAdd = aRowWidth;;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels++;
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartY - (int) theStartY);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurX++;
+ aDestPixels++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ *aDestPixels = aColor;
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ *aDestPixels = aColor;
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ else
+ {
+ ulong src = 0xFF000000 |
+ ((((((theColor.mRed * theColor.mAlpha + 0x80) >> 8) * aRMask) + aRRoundAdd) >> 8) & aRMask) |
+ ((((((theColor.mGreen * theColor.mAlpha + 0x80) >> 8) * aGMask) + aGRoundAdd) >> 8) & aGMask) |
+ ((((((theColor.mBlue * theColor.mAlpha + 0x80) >> 8) * aBMask) + aBRoundAdd) >> 8) & aBMask);
+ int oma = 256 - theColor.mAlpha;
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mWidth;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *(aDestPixels++) = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+
+ G += DeltaG2 * (theStartX - (int) theStartX);
+
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+ *aDestPixels = src +
+ (((((dest & aRMask) * oma) + aRRoundAdd) >> 8) & aRMask) +
+ (((((dest & aGMask) * oma) + aGRoundAdd) >> 8) & aGMask) +
+ (((((dest & aBMask) * oma) + aBRoundAdd) >> 8) & aBMask);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+ }
+}
+
+void MemoryImage::AdditiveDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ double aMinX = min(theStartX, theEndX);
+ double aMinY = min(theStartY, theEndY);
+ double aMaxX = max(theStartX, theEndX);
+ double aMaxY = max(theStartY, theEndY);
+
+ ulong aRMask = 0xFF0000;
+ ulong aGMask = 0x00FF00;
+ ulong aBMask = 0x0000FF;
+ int aRedShift = 16;
+ int aGreenShift = 8;
+ int aBlueShift = 0;
+
+ ulong aRRoundAdd = aRMask >> 1;
+ ulong aGRoundAdd = aGMask >> 1;
+ ulong aBRoundAdd = aBMask >> 1;
+
+ uchar* aMaxTable = mApp->mAdd8BitMaxTable;
+ DWORD *aSurface = GetBits();
+
+ if (true)//(mLockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ {
+ ulong rc = ((theColor.mRed * theColor.mAlpha) / 255);
+ ulong gc = ((theColor.mGreen * theColor.mAlpha) / 255);
+ ulong bc = ((theColor.mBlue * theColor.mAlpha) / 255);
+
+ double dv = theEndY - theStartY;
+ double dh = theEndX - theStartX;
+ int minG, maxG, G, DeltaG1, DeltaG2;
+ double swap;
+ int inc = 1;
+ int aCurX;
+ int aCurY;
+ int aRowWidth = mWidth;
+ int aRowAdd = aRowWidth;
+
+ if (abs(dv) < abs(dh))
+ {
+ // Mostly horizontal
+ if (dh < 0)
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dv < 0)
+ {
+ dv = -dv;
+ inc = -1;
+ aRowAdd = -aRowAdd;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * aRowWidth) + (int) theStartX;
+ ulong dest = *aDestPixels;
+
+ int r = aMaxTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ 0xFF000000 |
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY = theStartY;
+ aCurX = theStartX + 1;
+
+ G = 2 * dv - dh;
+ DeltaG1 = 2 * (dv - dh);
+ DeltaG2 = 2 * dv;
+
+ while (aCurX <= theEndX)
+ {
+ if (G > 0)
+ {
+ G += DeltaG1;
+ aCurY += inc;
+ aDestPixels += aRowAdd;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *(aDestPixels++) =
+ 0xFF000000 |
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurX++;
+ }
+ }
+ else
+ {
+ // Mostly vertical
+ if ( dv < 0 )
+ {
+ dh = -dh;
+ dv = -dv;
+ swap = theEndY;
+ theEndY = theStartY;
+ theStartY = swap;
+ swap = theEndX;
+ theEndX = theStartX;
+ theStartX = swap;
+ }
+
+ if (dh < 0)
+ {
+ dh = -dh;
+ inc = -1;
+ }
+
+ ulong* aDestPixels = ((ulong*) aSurface) + ((int) theStartY * mWidth) + (int) theStartX;
+
+ ulong dest = *aDestPixels;
+
+ int r = aMaxTable[((dest & aRMask) >> aRedShift) + rc];
+ int g = aMaxTable[((dest & aGMask) >> aGreenShift) + gc];
+ int b = aMaxTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ 0xFF000000 |
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aDestPixels += aRowAdd;
+
+ aCurX = theStartX;
+ aCurY = theStartY + 1;
+
+ G = 2 * dh - dv;
+ minG = maxG = G;
+ DeltaG1 = 2 * ( dh - dv );
+ DeltaG2 = 2 * dh;
+ while (aCurY <= theEndY)
+ {
+ if ( G > 0 )
+ {
+ G += DeltaG1;
+ aCurX += inc;
+ aDestPixels += inc;
+
+ if (aCurX<aMinX || aCurY<aMinY || aCurX>aMaxX || aCurY>aMaxY)
+ break;
+ }
+ else
+ G += DeltaG2;
+
+ dest = *aDestPixels;
+
+ r = aMaxTable[((dest & aRMask) >> aRedShift) + rc];
+ g = aMaxTable[((dest & aGMask) >> aGreenShift) + gc];
+ b = aMaxTable[((dest & aBMask) >> aBlueShift) + bc];
+
+ *aDestPixels =
+ 0xFF000000 |
+ (r << aRedShift) |
+ (g << aGreenShift) |
+ (b << aBlueShift);
+
+ aCurY++;
+ aDestPixels += aRowAdd;
+ }
+ }
+ }
+}
+
+
+void MemoryImage::DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+ if (theStartY == theEndY)
+ {
+ int aStartX = min(theStartX, theEndX);
+ int aEndX = max(theStartX, theEndX);
+
+ FillRect(Rect(aStartX, theStartY, aEndX-aStartX+1, theEndY-theStartY+1), theColor, theDrawMode);
+ return;
+ }
+ else if (theStartX == theEndX)
+ {
+ int aStartY = min(theStartY, theEndY);
+ int aEndY = max(theStartY, theEndY);
+
+ FillRect(Rect(theStartX, aStartY, theEndX-theStartX+1, aEndY-aStartY+1), theColor, theDrawMode);
+ return;
+ }
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalDrawLine(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveDrawLine(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ }
+
+ BitsChanged();
+}
+
+void MemoryImage::NormalDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+ ulong* aBits = GetBits();
+ ulong color = theColor.ToInt();
+
+ int aX0 = (int)theStartX, aX1 = (int)theEndX;
+ int aY0 = (int)theStartY, aY1 = (int)theEndY;
+ int aXinc = 1;
+ if (aY0 > aY1)
+ {
+ int aTempX = aX0, aTempY = aY0;
+ aX0 = aX1; aY0 = aY1;
+ aX1 = aTempX; aY1 = aTempY;
+ double aTempXd = theStartX, aTempYd = theStartY;
+ theStartX = theEndX; theStartY = theEndY;
+ theEndX = aTempXd; theEndY = aTempYd;
+ }
+
+ int dx = aX1 - aX0;
+ int dy = aY1 - aY0;
+ double dxd = theEndX - theStartX;
+ double dyd = theEndY - theStartY;
+ if (dx < 0)
+ {
+ dx = -dx;
+ aXinc = -1;
+ dxd = -dxd;
+ }
+
+ if (theColor.mAlpha != 255)
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (((w) * (theColor.mAlpha+1)) >> 8)
+ #define BLEND_PIXEL(p) \
+ {\
+ int aDestAlpha = dest >> 24;\
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;\
+ a = 255 * a / aNewDestAlpha;\
+ oma = 256 - a;\
+ *(p) = (aNewDestAlpha << 24) |\
+ ((((color & 0xFF0000) * a + (dest & 0xFF0000) * oma) >> 8) & 0xFF0000) |\
+ ((((color & 0x00FF00) * a + (dest & 0x00FF00) * oma) >> 8) & 0x00FF00) |\
+ ((((color & 0x0000FF) * a + (dest & 0x0000FF) * oma) >> 8) & 0x0000FF);\
+ }
+ const int STRIDE = mWidth;
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+ else
+ {
+ #define PIXEL_TYPE ulong
+ #define CALC_WEIGHT_A(w) (w)
+ #define BLEND_PIXEL(p) \
+ {\
+ int aDestAlpha = dest >> 24;\
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;\
+ a = 255 * a / aNewDestAlpha;\
+ oma = 256 - a;\
+ *(p) = (aNewDestAlpha << 24) |\
+ ((((color & 0xFF0000) * a + (dest & 0xFF0000) * oma) >> 8) & 0xFF0000) |\
+ ((((color & 0x00FF00) * a + (dest & 0x00FF00) * oma) >> 8) & 0x00FF00) |\
+ ((((color & 0x0000FF) * a + (dest & 0x0000FF) * oma) >> 8) & 0x0000FF);\
+ }
+ const int STRIDE = mWidth;
+
+ #include "GENERIC_DrawLineAA.inc"
+
+ #undef PIXEL_TYPE
+ #undef CALC_WEIGHT_A
+ #undef BLEND_PIXEL
+ }
+
+
+ BitsChanged();
+}
+
+void MemoryImage::AdditiveDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor)
+{
+}
+
+void MemoryImage::DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
+{
+ if (theStartY == theEndY)
+ {
+ int aStartX = min(theStartX, theEndX);
+ int aEndX = max(theStartX, theEndX);
+
+ FillRect(Rect(aStartX, theStartY, aEndX-aStartX+1, theEndY-theStartY+1), theColor, theDrawMode);
+ return;
+ }
+ else if (theStartX == theEndX)
+ {
+ int aStartY = min(theStartY, theEndY);
+ int aEndY = max(theStartY, theEndY);
+
+ FillRect(Rect(theStartX, aStartY, theEndX-theStartX+1, aEndY-aStartY+1), theColor, theDrawMode);
+ return;
+ }
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalDrawLineAA(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveDrawLineAA(theStartX, theStartY, theEndX, theEndY, theColor);
+ break;
+ }
+
+ BitsChanged();
+}
+
+
+void MemoryImage::CommitBits()
+{
+ //if (gDebug)
+ // mApp->CopyToClipboard("+MemoryImage::CommitBits");
+
+ if ((mBitsChanged) && (!mForcedMode))
+ {
+ // Analyze
+ if (mBits != NULL)
+ {
+ mHasTrans = false;
+ mHasAlpha = false;
+
+ int aSize = mWidth*mHeight;
+ ulong* ptr = mBits;
+
+ for (int i = 0; i < aSize; i++)
+ {
+ uchar anAlpha = (uchar) (*ptr++ >> 24);
+
+ if (anAlpha == 0)
+ mHasTrans = true;
+ else if (anAlpha != 255)
+ mHasAlpha = true;
+ }
+ }
+ else if (mColorTable != NULL)
+ {
+ mHasTrans = false;
+ mHasAlpha = false;
+
+ int aSize = 256;
+ ulong* ptr = mColorTable;
+
+ for (int i = 0; i < aSize; i++)
+ {
+ uchar anAlpha = (uchar) (*ptr++ >> 24);
+
+ if (anAlpha == 0)
+ mHasTrans = true;
+ else if (anAlpha != 255)
+ mHasAlpha = true;
+ }
+ }
+ else
+ {
+ mHasTrans = true;
+ mHasAlpha = false;
+ }
+
+ mBitsChanged = false;
+ }
+
+ //if (gDebug)
+ // mApp->CopyToClipboard("-MemoryImage::CommitBits");
+}
+
+void MemoryImage::SetImageMode(bool hasTrans, bool hasAlpha)
+{
+ mForcedMode = true;
+ mHasTrans = hasTrans;
+ mHasAlpha = hasAlpha;
+}
+
+void MemoryImage::SetVolatile(bool isVolatile)
+{
+ mIsVolatile = isVolatile;
+}
+
+void* MemoryImage::GetNativeAlphaData(NativeDisplay *theDisplay)
+{
+ if (mNativeAlphaData != NULL)
+ return mNativeAlphaData;
+
+ CommitBits();
+
+ const int rRightShift = 16 + (8-theDisplay->mRedBits);
+ const int gRightShift = 8 + (8-theDisplay->mGreenBits);
+ const int bRightShift = 0 + (8-theDisplay->mBlueBits);
+
+ const int rLeftShift = theDisplay->mRedShift;
+ const int gLeftShift = theDisplay->mGreenShift;
+ const int bLeftShift = theDisplay->mBlueShift;
+
+ const int rMask = theDisplay->mRedMask;
+ const int gMask = theDisplay->mGreenMask;
+ const int bMask = theDisplay->mBlueMask;
+
+ if (mColorTable == NULL)
+ {
+ ulong* aSrcPtr = GetBits();
+
+ ulong* anAlphaData = new ulong[mWidth*mHeight];
+
+ ulong* aDestPtr = anAlphaData;
+ int aSize = mWidth*mHeight;
+ for (int i = 0; i < aSize; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+
+ ulong r = ((val & 0xFF0000) * (anAlpha+1)) >> 8;
+ ulong g = ((val & 0x00FF00) * (anAlpha+1)) >> 8;
+ ulong b = ((val & 0x0000FF) * (anAlpha+1)) >> 8;
+
+ *(aDestPtr++) =
+ (((r >> rRightShift) << rLeftShift) & rMask) |
+ (((g >> gRightShift) << gLeftShift) & gMask) |
+ (((b >> bRightShift) << bLeftShift) & bMask) |
+ (anAlpha << 24);
+ }
+
+ mNativeAlphaData = anAlphaData;
+ }
+ else
+ {
+ ulong* aSrcPtr = mColorTable;
+
+ ulong* anAlphaData = new ulong[256];
+
+ for (int i = 0; i < 256; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+
+ ulong r = ((val & 0xFF0000) * (anAlpha+1)) >> 8;
+ ulong g = ((val & 0x00FF00) * (anAlpha+1)) >> 8;
+ ulong b = ((val & 0x0000FF) * (anAlpha+1)) >> 8;
+
+ anAlphaData[i] =
+ (((r >> rRightShift) << rLeftShift) & rMask) |
+ (((g >> gRightShift) << gLeftShift) & gMask) |
+ (((b >> bRightShift) << bLeftShift) & bMask) |
+ (anAlpha << 24);
+ }
+
+
+ mNativeAlphaData = anAlphaData;
+ }
+
+ return mNativeAlphaData;
+}
+
+
+uchar* MemoryImage::GetRLAlphaData()
+{
+ CommitBits();
+
+ if (mRLAlphaData == NULL)
+ {
+ mRLAlphaData = new uchar[mWidth*mHeight];
+
+ if (mColorTable == NULL)
+ {
+ ulong* aSrcPtr;
+ if (mNativeAlphaData != NULL)
+ aSrcPtr = (ulong*) mNativeAlphaData;
+ else
+ aSrcPtr = GetBits();
+
+ #define NEXT_SRC_COLOR (*(aSrcPtr++))
+
+ #include "MI_GetRLAlphaData.inc"
+
+ #undef NEXT_SRC_COLOR
+ }
+ else
+ {
+ uchar* aSrcPtr = mColorIndices;
+ ulong* aColorTable = mColorTable;
+
+ #define NEXT_SRC_COLOR (aColorTable[*(aSrcPtr++)])
+
+ #include "MI_GetRLAlphaData.inc"
+
+ #undef NEXT_SRC_COLOR
+ }
+ }
+
+ return mRLAlphaData;
+}
+
+uchar* MemoryImage::GetRLAdditiveData(NativeDisplay *theNative)
+{
+ if (mRLAdditiveData == NULL)
+ {
+ if (mColorTable == NULL)
+ {
+ ulong* aBits = (ulong*) GetNativeAlphaData(theNative);
+
+ mRLAdditiveData = new uchar[mWidth*mHeight];
+
+ uchar* aWPtr = mRLAdditiveData;
+ ulong* aRPtr = aBits;
+
+ if (mWidth==1)
+ {
+ memset(aWPtr,1,mHeight);
+ }
+ else
+ {
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ int aRCount = 1;
+ int aRLCount = 1;
+
+ int aLastAClass = (((*aRPtr++) & 0xFFFFFF) != 0) ? 1 : 0;
+
+ while (aRCount < mWidth)
+ {
+ aRCount++;
+
+ int aThisAClass = (((*aRPtr++) & 0xFFFFFF) != 0) ? 1 : 0;
+
+ if ((aThisAClass != aLastAClass) || (aRCount == mWidth))
+ {
+ if (aThisAClass == aLastAClass)
+ aRLCount++;
+
+ for (int i = aRLCount; i > 0; i--)
+ {
+ if (i >= 255)
+ *aWPtr++ = 255;
+ else
+ *aWPtr++ = i;
+ }
+
+ if ((aRCount == mWidth) && (aThisAClass != aLastAClass))
+ *aWPtr++ = 1;
+
+ aLastAClass = aThisAClass;
+ aRLCount = 1;
+ }
+ else
+ {
+ aRLCount++;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ ulong* aNativeColorTable = (ulong*) GetNativeAlphaData(theNative);
+
+ mRLAdditiveData = new uchar[mWidth*mHeight];
+
+ uchar* aWPtr = mRLAdditiveData;
+ uchar* aRPtr = mColorIndices;
+
+ if (mWidth==1)
+ {
+ memset(aWPtr,1,mHeight);
+ }
+ else
+ {
+ for (int aRow = 0; aRow < mHeight; aRow++)
+ {
+ int aRCount = 1;
+ int aRLCount = 1;
+
+ int aLastAClass = (((aNativeColorTable[*aRPtr++]) & 0xFFFFFF) != 0) ? 1 : 0;
+
+ while (aRCount < mWidth)
+ {
+ aRCount++;
+
+ int aThisAClass = (((aNativeColorTable[*aRPtr++]) & 0xFFFFFF) != 0) ? 1 : 0;
+
+ if ((aThisAClass != aLastAClass) || (aRCount == mWidth))
+ {
+ if (aThisAClass == aLastAClass)
+ aRLCount++;
+
+ for (int i = aRLCount; i > 0; i--)
+ {
+ if (i >= 255)
+ *aWPtr++ = 255;
+ else
+ *aWPtr++ = i;
+ }
+
+ if ((aRCount == mWidth) && (aThisAClass != aLastAClass))
+ *aWPtr++ = 1;
+
+ aLastAClass = aThisAClass;
+ aRLCount = 1;
+ }
+ else
+ {
+ aRLCount++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return mRLAdditiveData;
+}
+
+void MemoryImage::PurgeBits()
+{
+ mPurgeBits = true;
+
+ if (mApp->Is3DAccelerated())
+ {
+ // Due to potential D3D threading issues we have to defer the texture creation
+ // and therefore the actual purging
+ if (mD3DData == NULL)
+ return;
+ }
+ else
+ {
+ if ((mBits == NULL) && (mColorIndices == NULL))
+ return;
+
+ GetNativeAlphaData(gSexyAppBase->mDDInterface);
+ }
+
+ delete [] mBits;
+ mBits = NULL;
+
+ if (mD3DData != NULL)
+ {
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+ }
+}
+
+void MemoryImage::DeleteSWBuffers()
+{
+ if ((mBits == NULL) && (mColorIndices == NULL))
+ GetBits();
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+
+ delete [] mRLAdditiveData;
+ mRLAdditiveData = NULL;
+
+ delete [] mRLAlphaData;
+ mRLAlphaData = NULL;
+}
+
+void MemoryImage::Delete3DBuffers()
+{
+ mApp->Remove3DData(this);
+}
+
+void MemoryImage::DeleteExtraBuffers()
+{
+ DeleteSWBuffers();
+ Delete3DBuffers();
+}
+
+void MemoryImage::ReInit()
+{
+ // Fix any un-palletizing
+ if (mWantPal)
+ Palletize();
+
+ if (mPurgeBits)
+ PurgeBits();
+}
+
+void MemoryImage::DeleteNativeData()
+{
+ if ((mBits == NULL) && (mColorIndices == NULL))
+ GetBits(); // We need to keep the bits around
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+
+ delete [] mRLAdditiveData;
+ mRLAdditiveData = NULL;
+}
+
+void MemoryImage::SetBits(ulong* theBits, int theWidth, int theHeight, bool commitBits)
+{
+ if (theBits != mBits)
+ {
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+
+ if (theWidth != mWidth || theHeight != mHeight)
+ {
+ delete [] mBits;
+ mBits = new ulong[theWidth*theHeight + 1];
+ mWidth = theWidth;
+ mHeight = theHeight;
+ }
+ memcpy(mBits, theBits, mWidth*mHeight*sizeof(ulong));
+ mBits[mWidth*mHeight] = MEMORYCHECK_ID;
+
+ BitsChanged();
+ if (commitBits)
+ CommitBits();
+ }
+}
+
+void MemoryImage::Create(int theWidth, int theHeight)
+{
+ delete [] mBits;
+ mBits = NULL;
+
+ mWidth = theWidth;
+ mHeight = theHeight;
+
+ // All zeros --> trans + alpha
+ mHasTrans = true;
+ mHasAlpha = true;
+
+ BitsChanged();
+}
+
+ulong* MemoryImage::GetBits()
+{
+ if (mBits == NULL)
+ {
+ int aSize = mWidth*mHeight;
+
+ mBits = new ulong[aSize+1];
+ mBits[aSize] = MEMORYCHECK_ID;
+
+ if (mColorTable != NULL)
+ {
+ for (int i = 0; i < aSize; i++)
+ mBits[i] = mColorTable[mColorIndices[i]];
+
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+ }
+ else if (mNativeAlphaData != NULL)
+ {
+ NativeDisplay* aDisplay = gSexyAppBase->mDDInterface;
+
+ const int rMask = aDisplay->mRedMask;
+ const int gMask = aDisplay->mGreenMask;
+ const int bMask = aDisplay->mBlueMask;
+
+ const int rLeftShift = aDisplay->mRedShift + (aDisplay->mRedBits);
+ const int gLeftShift = aDisplay->mGreenShift + (aDisplay->mGreenBits);
+ const int bLeftShift = aDisplay->mBlueShift + (aDisplay->mBlueBits);
+
+ ulong* aDestPtr = mBits;
+ ulong* aSrcPtr = mNativeAlphaData;
+
+ int aSize = mWidth*mHeight;
+ for (int i = 0; i < aSize; i++)
+ {
+ ulong val = *(aSrcPtr++);
+
+ int anAlpha = val >> 24;
+
+ ulong r = (((((val & rMask) << 8) / (anAlpha+1)) & rMask) << 8) >> rLeftShift;
+ ulong g = (((((val & gMask) << 8) / (anAlpha+1)) & gMask) << 8) >> gLeftShift;
+ ulong b = (((((val & bMask) << 8) / (anAlpha+1)) & bMask) << 8) >> bLeftShift;
+
+ *(aDestPtr++) = (r << 16) | (g << 8) | (b) | (anAlpha << 24);
+ }
+ }
+ else if ((mD3DData == NULL) || (!mApp->mDDInterface->mD3DInterface->RecoverBits(this)))
+ {
+ ZeroMemory(mBits, aSize*sizeof(ulong));
+ }
+ }
+
+ return mBits;
+}
+
+void MemoryImage::FillRect(const Rect& theRect, const Color& theColor, int theDrawMode)
+{
+ ulong src = theColor.ToInt();
+
+ ulong* aBits = GetBits();
+
+ int oldAlpha = src >> 24;
+
+ if (oldAlpha == 0xFF)
+ {
+ for (int aRow = theRect.mY; aRow < theRect.mY+theRect.mHeight; aRow++)
+ {
+ ulong* aDestPixels = &aBits[aRow*mWidth+theRect.mX];
+
+ for (int i = 0; i < theRect.mWidth; i++)
+ *aDestPixels++ = src;
+ }
+ }
+ else
+ {
+ for (int aRow = theRect.mY; aRow < theRect.mY+theRect.mHeight; aRow++)
+ {
+ ulong* aDestPixels = &aBits[aRow*mWidth+theRect.mX];
+
+ for (int i = 0; i < theRect.mWidth; i++)
+ {
+ ulong dest = *aDestPixels;
+
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * oldAlpha) / 255;
+
+ int newAlpha = 255 * oldAlpha / aNewDestAlpha;
+
+ int oma = 256 - newAlpha;
+
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0xFF00FF) * oma + (src & 0xFF00FF) * newAlpha) >> 8) & 0xFF00FF) |
+ ((((dest & 0x00FF00) * oma + (src & 0x00FF00) * newAlpha) >> 8) & 0x00FF00);
+#else
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * newAlpha) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * newAlpha) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((src & 0xFF0000) * newAlpha) >> 8) & 0xFF0000);
+#endif
+ }
+ }
+ }
+
+ BitsChanged();
+}
+
+void MemoryImage::ClearRect(const Rect& theRect)
+{
+ ulong* aBits = GetBits();
+
+ for (int aRow = theRect.mY; aRow < theRect.mY+theRect.mHeight; aRow++)
+ {
+ ulong* aDestPixels = &aBits[aRow*mWidth+theRect.mX];
+
+ for (int i = 0; i < theRect.mWidth; i++)
+ *aDestPixels++ = 0;
+ }
+
+ BitsChanged();
+}
+
+void MemoryImage::Clear()
+{
+ ulong* ptr = GetBits();
+ if (ptr != NULL)
+ {
+ for (int i = 0; i < mWidth*mHeight; i++)
+ *ptr++ = 0;
+
+ BitsChanged();
+ }
+}
+
+void MemoryImage::AdditiveBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ uchar* aMaxTable = mApp->mAdd8BitMaxTable;
+
+ if (aSrcMemoryImage != NULL)
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aSrcMemoryImage->GetBits();
+
+ #define NEXT_SRC_COLOR (*(aSrcPtr++))
+ #define SRC_TYPE ulong
+
+ #include "MI_AdditiveBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef SRC_TYPE
+ }
+ else
+ {
+ ulong* aColorTable = aSrcMemoryImage->mColorTable;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define NEXT_SRC_COLOR (aColorTable[*(aSrcPtr++)])
+ #define SRC_TYPE uchar
+
+ #include "MI_AdditiveBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef SRC_TYPE
+ }
+
+ BitsChanged();
+ }
+}
+
+void MemoryImage::NormalBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor)
+{
+ theImage->mDrawn = true;
+
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ if (aSrcMemoryImage != NULL)
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcPixelsRow = ((ulong*) aSrcMemoryImage->GetBits()) + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ #define NEXT_SRC_COLOR (*(aSrcPtr++))
+ #define READ_SRC_COLOR (*(aSrcPtr))
+ #define EACH_ROW ulong* aSrcPtr = aSrcPixelsRow
+
+ #include "MI_NormalBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef READ_SRC_COLOR
+ #undef EACH_ROW
+ }
+ else
+ {
+ ulong* aColorTable = aSrcMemoryImage->mColorTable;
+ uchar* aSrcPixelsRow = aSrcMemoryImage->mColorIndices + (theSrcRect.mY * theImage->mWidth) + theSrcRect.mX;
+
+ #define NEXT_SRC_COLOR (aColorTable[*(aSrcPtr++)])
+ #define READ_SRC_COLOR (aColorTable[*(aSrcPtr)])
+ #define EACH_ROW uchar* aSrcPtr = aSrcPixelsRow
+
+ #include "MI_NormalBlt.inc"
+
+ #undef NEXT_SRC_COLOR
+ #undef READ_SRC_COLOR
+ #undef EACH_ROW
+ }
+
+ BitsChanged();
+ }
+}
+
+void MemoryImage::Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ DBG_ASSERTE((theColor.mRed >= 0) && (theColor.mRed <= 255));
+ DBG_ASSERTE((theColor.mGreen >= 0) && (theColor.mGreen <= 255));
+ DBG_ASSERTE((theColor.mBlue >= 0) && (theColor.mBlue <= 255));
+ DBG_ASSERTE((theColor.mAlpha >= 0) && (theColor.mAlpha <= 255));
+
+ switch (theDrawMode)
+ {
+ case Graphics::DRAWMODE_NORMAL:
+ NormalBlt(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ case Graphics::DRAWMODE_ADDITIVE:
+ AdditiveBlt(theImage, theX, theY, theSrcRect, theColor);
+ break;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void MemoryImage::BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ BltRotated(theImage,theX,theY,theSrcRect,theClipRect,theColor,theDrawMode,0,0,0);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool MemoryImage::BltRotatedClipHelper(float &theX, float &theY, const Rect &theSrcRect, const Rect &theClipRect, double theRot, FRect &theDestRect, float theRotCenterX, float theRotCenterY)
+{
+ // Clipping Code (this used to be in Graphics::DrawImageRotated)
+ float aCos = cosf(theRot);
+ float aSin = sinf(theRot);
+
+ // Map the four corners and find the bounding rectangle
+ float px[4] = { 0, theSrcRect.mWidth, theSrcRect.mWidth, 0 };
+ float py[4] = { 0, 0, theSrcRect.mHeight, theSrcRect.mHeight };
+ float aMinX = 10000000;
+ float aMaxX = -10000000;
+ float aMinY = 10000000;
+ float aMaxY = -10000000;
+
+ for (int i=0; i<4; i++)
+ {
+ float ox = px[i] - theRotCenterX;
+ float oy = py[i] - theRotCenterY;
+
+ px[i] = (theRotCenterX + ox*aCos + oy*aSin) + theX;
+ py[i] = (theRotCenterY + oy*aCos - ox*aSin) + theY;
+
+ if (px[i] < aMinX)
+ aMinX = px[i];
+ if (px[i] > aMaxX)
+ aMaxX = px[i];
+ if (py[i] < aMinY)
+ aMinY = py[i];
+ if (py[i] > aMaxY)
+ aMaxY = py[i];
+ }
+
+
+
+ FRect aClipRect(theClipRect.mX,theClipRect.mY,theClipRect.mWidth,theClipRect.mHeight);
+
+ FRect aDestRect = FRect(aMinX, aMinY, aMaxX-aMinX, aMaxY-aMinY).Intersection(aClipRect);
+ if ((aDestRect.mWidth <= 0) || (aDestRect.mHeight <= 0)) // nothing to draw
+ return false;
+
+ theDestRect = aDestRect;
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool MemoryImage::StretchBltClipHelper(const Rect &theSrcRect, const Rect &theClipRect, const Rect &theDestRect, FRect &theSrcRectOut, Rect &theDestRectOut)
+{
+ theDestRectOut = Rect(theDestRect.mX , theDestRect.mY, theDestRect.mWidth, theDestRect.mHeight).Intersection(theClipRect);
+
+ double aXFactor = theSrcRect.mWidth / (double) theDestRect.mWidth;
+ double aYFactor = theSrcRect.mHeight / (double) theDestRect.mHeight;
+
+ theSrcRectOut = FRect(theSrcRect.mX + (theDestRectOut.mX - theDestRect.mX)*aXFactor,
+ theSrcRect.mY + (theDestRectOut.mY - theDestRect.mY)*aYFactor,
+ theSrcRect.mWidth + (theDestRectOut.mWidth - theDestRect.mWidth)*aXFactor,
+ theSrcRect.mHeight + (theDestRectOut.mHeight - theDestRect.mHeight)*aYFactor);
+
+ return theSrcRectOut.mWidth>0 && theSrcRectOut.mHeight>0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool MemoryImage::StretchBltMirrorClipHelper(const Rect &theSrcRect, const Rect &theClipRect, const Rect &theDestRect, FRect &theSrcRectOut, Rect &theDestRectOut)
+{
+ theDestRectOut = Rect(theDestRect.mX, theDestRect.mY, theDestRect.mWidth, theDestRect.mHeight).Intersection(theClipRect);
+
+ double aXFactor = theSrcRect.mWidth / (double) theDestRect.mWidth;
+ double aYFactor = theSrcRect.mHeight / (double) theDestRect.mHeight;
+
+ int aTotalClip = theDestRect.mWidth - theDestRectOut.mWidth;
+ int aLeftClip = theDestRectOut.mX - theDestRect.mX;
+ int aRightClip = aTotalClip-aLeftClip;
+
+ theSrcRectOut = FRect(theSrcRect.mX + (aRightClip)*aXFactor,
+ theSrcRect.mY + (theDestRectOut.mY - theDestRect.mY)*aYFactor,
+ theSrcRect.mWidth + (theDestRectOut.mWidth - theDestRect.mWidth)*aXFactor,
+ theSrcRect.mHeight + (theDestRectOut.mHeight - theDestRect.mHeight)*aYFactor);
+
+ return theSrcRectOut.mWidth>0 && theSrcRectOut.mHeight>0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void MemoryImage::BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY)
+{
+ theImage->mDrawn = true;
+
+ // This BltRotatedClipHelper clipping used to happen in Graphics::DrawImageRotated
+ FRect aDestRect;
+ if (!BltRotatedClipHelper(theX, theY, theSrcRect, theClipRect, theRot, aDestRect,theRotCenterX,theRotCenterY))
+ return;
+
+ MemoryImage* aMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+ uchar* aMaxTable = mApp->mAdd8BitMaxTable;
+
+ if (aMemoryImage != NULL)
+ {
+ if (aMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aMemoryImage->GetBits() + theSrcRect.mX + theSrcRect.mY*theSrcRect.mWidth;
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+ #include "MI_BltRotated.inc"
+ }
+ else
+ {
+ #include "MI_BltRotated_Additive.inc"
+ }
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = aMemoryImage->mColorTable;
+ uchar* aSrcBits = aMemoryImage->mColorIndices + theSrcRect.mX + theSrcRect.mY*theSrcRect.mWidth;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ if (theDrawMode == Graphics::DRAWMODE_NORMAL)
+ {
+ #include "MI_BltRotated.inc"
+ }
+ else
+ {
+ #include "MI_BltRotated_Additive.inc"
+ }
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+
+ BitsChanged();
+ }
+}
+
+void MemoryImage::SlowStretchBlt(Image* theImage, const Rect& theDestRect, const FRect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ // This thing was a pain to write. I bet i could have gotten something just as good
+ // from some Graphics Gems book.
+
+ ulong* aDestEnd = GetBits() + (mWidth * mHeight);
+
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ if (aSrcMemoryImage != NULL)
+ {
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ ulong* aSrcBits = aSrcMemoryImage->GetBits();
+
+ #define SRC_TYPE ulong
+ #define READ_COLOR(ptr) (*(ptr))
+
+ #include "MI_SlowStretchBlt.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+ else
+ {
+ ulong* aColorTable = aSrcMemoryImage->mColorTable;
+ uchar* aSrcBits = aSrcMemoryImage->mColorIndices;
+
+ #define SRC_TYPE uchar
+ #define READ_COLOR(ptr) (aColorTable[*(ptr)])
+
+ #include "MI_SlowStretchBlt.inc"
+
+ #undef SRC_TYPE
+ #undef READ_COLOR
+ }
+
+ BitsChanged();
+ }
+}
+
+//TODO: Make the special version
+void MemoryImage::FastStretchBlt(Image* theImage, const Rect& theDestRect, const FRect& theSrcRect, const Color& theColor, int theDrawMode)
+{
+ theImage->mDrawn = true;
+
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ if (aSrcMemoryImage != NULL)
+ {
+ ulong* aDestPixelsRow = ((ulong*) GetBits()) + (theDestRect.mY * mWidth) + theDestRect.mX;
+ ulong* aSrcPixelsRow = (ulong*) aSrcMemoryImage->GetBits();;
+
+ double aSrcY = theSrcRect.mY;
+
+ double anAddX = theSrcRect.mWidth / theDestRect.mWidth;
+ double anAddY = theSrcRect.mHeight / theDestRect.mHeight;
+
+ if (theColor == Color::White)
+ {
+ for (int y = 0; y < theDestRect.mHeight; y++)
+ {
+ double aSrcX = theSrcRect.mX;
+
+ ulong* aDestPixels = aDestPixelsRow;
+
+ for (int x = 0; x < theDestRect.mWidth; x++)
+ {
+ aSrcX += anAddX;
+
+ ulong* aSrcPixels = aSrcPixelsRow + ((int) aSrcX) + (aSrcMemoryImage->mWidth * ((int) aSrcY));
+ ulong src = *aSrcPixels;
+
+ ulong dest = *aDestPixels;
+
+ int a = src >> 24;
+
+ if (a != 0)
+ {
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+
+ a = 255 * a / aNewDestAlpha;
+
+ int oma = 256 - a;
+
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0x0000FF) * oma) >> 8) + (((src & 0x0000FF) * a) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma) >> 8) + (((src & 0x00FF00) * a) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma) >> 8) + (((src & 0xFF0000) * a) >> 8) & 0xFF0000);
+ }
+ else
+ aDestPixels++;
+ }
+
+ aDestPixelsRow += mWidth;
+ aSrcY += anAddY;
+ }
+ }
+ else
+ {
+ }
+ }
+
+ BitsChanged();
+}
+
+void MemoryImage::StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
+{
+ theImage->mDrawn = true;
+
+ Rect aDestRect;
+ FRect aSrcRect;
+
+ if (!StretchBltClipHelper(theSrcRect, theClipRect, theDestRect, aSrcRect, aDestRect))
+ return;
+
+ if (fastStretch)
+ FastStretchBlt(theImage, aDestRect, aSrcRect, theColor, theDrawMode);
+ else
+ SlowStretchBlt(theImage, aDestRect, aSrcRect, theColor, theDrawMode);
+}
+
+void MemoryImage::BltMatrixHelper(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, void *theSurface, int theBytePitch, int thePixelFormat, bool blend)
+{
+ MemoryImage *anImage = dynamic_cast<MemoryImage*>(theImage);
+ if (anImage==NULL)
+ return;
+
+ float w2 = theSrcRect.mWidth/2.0f;
+ float h2 = theSrcRect.mHeight/2.0f;
+
+ float u0 = (float)theSrcRect.mX/theImage->mWidth;
+ float u1 = (float)(theSrcRect.mX + theSrcRect.mWidth)/theImage->mWidth;
+ float v0 = (float)theSrcRect.mY/theImage->mHeight;
+ float v1 = (float)(theSrcRect.mY + theSrcRect.mHeight)/theImage->mHeight;
+
+ SWHelper::XYZStruct aVerts[4] =
+ {
+ { -w2, -h2, u0, v0, 0xFFFFFFFF },
+ { w2, -h2, u1, v0, 0xFFFFFFFF },
+ { -w2, h2, u0, v1, 0xFFFFFFFF },
+ { w2, h2, u1, v1, 0xFFFFFFFF }
+ };
+
+ for (int i=0; i<4; i++)
+ {
+ SexyVector3 v(aVerts[i].mX, aVerts[i].mY, 1);
+ v = theMatrix*v;
+ aVerts[i].mX = v.x + x - 0.5f;
+ aVerts[i].mY = v.y + y - 0.5f;
+ }
+
+ SWHelper::SWDrawShape(aVerts, 4, anImage, theColor, theDrawMode, theClipRect, theSurface, theBytePitch, thePixelFormat, blend,false);
+}
+
+void MemoryImage::BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend)
+{
+ theImage->mDrawn = true;
+
+ DWORD *aSurface = GetBits();
+ int aPitch = mWidth*4;
+ int aFormat = 0x8888;
+ if (mForcedMode && !mHasAlpha && !mHasTrans)
+ aFormat = 0x888;
+
+ BltMatrixHelper(theImage,x,y,theMatrix,theClipRect,theColor,theDrawMode,theSrcRect,aSurface,aPitch,aFormat,blend);
+ BitsChanged();
+}
+
+void MemoryImage::BltTrianglesTexHelper(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect &theClipRect, const Color &theColor, int theDrawMode, void *theSurface, int theBytePitch, int thePixelFormat, float tx, float ty, bool blend)
+{
+ MemoryImage *anImage = dynamic_cast<MemoryImage*>(theTexture);
+// if (anImage==NULL)
+// return;
+
+ int aColor = theColor.ToInt();
+ for (int i=0; i<theNumTriangles; i++)
+ {
+ bool vertexColor = false;
+
+ SWHelper::XYZStruct aVerts[3];
+ for (int j=0; j<3; j++)
+ {
+ aVerts[j].mX = theVertices[i][j].x + tx;
+ aVerts[j].mY = theVertices[i][j].y + ty;
+ aVerts[j].mU = theVertices[i][j].u;
+ aVerts[j].mV = theVertices[i][j].v;
+ aVerts[j].mDiffuse = theVertices[i][j].color;
+
+ if (aVerts[j].mDiffuse!=0)
+ vertexColor = true;
+ }
+
+ SWHelper::SWDrawShape(aVerts, 3, anImage, theColor, theDrawMode, theClipRect, theSurface, theBytePitch, thePixelFormat, blend, vertexColor);
+ }
+
+}
+
+void MemoryImage::FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight)
+{
+ ulong* theBits = GetBits();
+ ulong src = theColor.ToInt();
+ for (int i = 0; i < theSpanCount; ++i)
+ {
+ Span* aSpan = &theSpans[i];
+ int x = aSpan->mX - theCoverX;
+ int y = aSpan->mY - theCoverY;
+
+ ulong* aDestPixels = &theBits[aSpan->mY*mWidth + aSpan->mX];
+ const BYTE* aCoverBits = &theCoverage[y*theCoverWidth+x];
+ for (int w = 0; w < aSpan->mWidth; ++w)
+ {
+ int cover = *aCoverBits++ + 1;
+ int a = (cover * theColor.mAlpha) >> 8;
+ int oma;
+ ulong dest = *aDestPixels;
+
+ if (a > 0)
+ {
+ int aDestAlpha = dest >> 24;
+ int aNewDestAlpha = aDestAlpha + ((255 - aDestAlpha) * a) / 255;
+
+ a = 255 * a / aNewDestAlpha;
+ oma = 256 - a;
+ *(aDestPixels++) = (aNewDestAlpha << 24) |
+ ((((dest & 0x0000FF) * oma + (src & 0x0000FF) * a) >> 8) & 0x0000FF) |
+ ((((dest & 0x00FF00) * oma + (src & 0x00FF00) * a) >> 8) & 0x00FF00) |
+ ((((dest & 0xFF0000) * oma + (src & 0xFF0000) * a) >> 8) & 0xFF0000);
+ }
+ }
+ }
+ BitsChanged();
+}
+
+void MemoryImage::BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend)
+{
+ theTexture->mDrawn = true;
+
+ DWORD *aSurface = GetBits();
+
+ int aPitch = mWidth*4;
+ int aFormat = 0x8888;
+ if (mForcedMode && !mHasAlpha && !mHasTrans)
+ aFormat = 0x888;
+
+ BltTrianglesTexHelper(theTexture,theVertices,theNumTriangles,theClipRect,theColor,theDrawMode,aSurface,aPitch,aFormat,tx,ty,blend);
+ BitsChanged();
+}
+
+bool MemoryImage::Palletize()
+{
+ CommitBits();
+
+ if (mColorTable != NULL)
+ return true;
+
+ GetBits();
+
+ if (mBits == NULL)
+ return false;
+
+ mColorIndices = new uchar[mWidth*mHeight];
+ mColorTable = new ulong[256];
+
+ if (!Quantize8Bit(mBits, mWidth, mHeight, mColorIndices, mColorTable))
+ {
+ delete [] mColorIndices;
+ mColorIndices = NULL;
+
+ delete [] mColorTable;
+ mColorTable = NULL;
+
+ mWantPal = false;
+
+ return false;
+ }
+
+ delete [] mBits;
+ mBits = NULL;
+
+ delete [] mNativeAlphaData;
+ mNativeAlphaData = NULL;
+
+ mWantPal = true;
+
+ return true;
+}
diff --git a/osframework/source/SexyAppFramework/MemoryImage.h b/osframework/source/SexyAppFramework/MemoryImage.h
new file mode 100644
index 0000000..9f6eab1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MemoryImage.h
@@ -0,0 +1,113 @@
+#ifndef __MEMORYIMAGE_H__
+#define __MEMORYIMAGE_H__
+
+#include "Image.h"
+
+#define OPTIMIZE_SOFTWARE_DRAWING
+#ifdef OPTIMIZE_SOFTWARE_DRAWING
+extern bool gOptimizeSoftwareDrawing;
+#endif
+
+namespace Sexy
+{
+
+const ulong MEMORYCHECK_ID = 0x4BEEFADE;
+
+class NativeDisplay;
+class SexyAppBase;
+
+class MemoryImage : public Image
+{
+public:
+ ulong* mBits;
+ int mBitsChangedCount;
+ void* mD3DData;
+ DWORD mD3DFlags; // see D3DInterface.h for possible values
+
+ ulong* mColorTable;
+ uchar* mColorIndices;
+
+ bool mForcedMode;
+ bool mHasTrans;
+ bool mHasAlpha;
+ bool mIsVolatile;
+ bool mPurgeBits;
+ bool mWantPal;
+
+ ulong* mNativeAlphaData;
+ uchar* mRLAlphaData;
+ uchar* mRLAdditiveData;
+
+ bool mBitsChanged;
+ SexyAppBase* mApp;
+
+private:
+ void Init();
+
+public:
+ virtual void* GetNativeAlphaData(NativeDisplay *theNative);
+ virtual uchar* GetRLAlphaData();
+ virtual uchar* GetRLAdditiveData(NativeDisplay *theNative);
+ virtual void PurgeBits();
+ virtual void DeleteSWBuffers();
+ virtual void Delete3DBuffers();
+ virtual void DeleteExtraBuffers();
+ virtual void ReInit();
+
+ virtual void BitsChanged();
+ virtual void CommitBits();
+
+ virtual void DeleteNativeData();
+
+ void NormalBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+ void AdditiveBlt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor);
+
+ void NormalDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+ void AdditiveDrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+
+ void NormalDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+ void AdditiveDrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor);
+
+ void SlowStretchBlt(Image* theImage, const Rect& theDestRect, const FRect& theSrcRect, const Color& theColor, int theDrawMode);
+ void FastStretchBlt(Image* theImage, const Rect& theDestRect, const FRect& theSrcRect, const Color& theColor, int theDrawMode);
+ bool BltRotatedClipHelper(float &theX, float &theY, const Rect &theSrcRect, const Rect &theClipRect, double theRot, FRect &theDestRect, float theRotCenterX, float theRotCenterY);
+ bool StretchBltClipHelper(const Rect &theSrcRect, const Rect &theClipRect, const Rect &theDestRect, FRect &theSrcRectOut, Rect &theDestRectOut);
+ bool StretchBltMirrorClipHelper(const Rect &theSrcRect, const Rect &theClipRect, const Rect &theDestRect, FRect &theSrcRectOut, Rect &theDestRectOut);
+ void BltMatrixHelper(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, void *theSurface, int theBytePitch, int thePixelFormat, bool blend);
+ void BltTrianglesTexHelper(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect &theClipRect, const Color &theColor, int theDrawMode, void *theSurface, int theBytePitch, int thePixelFormat, float tx, float ty, bool blend);
+
+ void FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const BYTE* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight);
+
+
+public:
+ MemoryImage();
+ MemoryImage(SexyAppBase* theApp);
+ MemoryImage(const MemoryImage& theMemoryImage);
+ virtual ~MemoryImage();
+
+ virtual void Clear();
+ virtual void SetBits(ulong* theBits, int theWidth, int theHeight, bool commitBits = true);
+ virtual void Create(int theWidth, int theHeight);
+ virtual ulong* GetBits();
+
+ virtual void FillRect(const Rect& theRect, const Color& theColor, int theDrawMode);
+ virtual void ClearRect(const Rect& theRect);
+ virtual void DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+ virtual void DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode);
+
+ virtual void Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode);
+ virtual void BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode);
+ virtual void BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY);
+ virtual void StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch);
+ virtual void BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend);
+ virtual void BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend);
+
+ virtual void SetImageMode(bool hasTrans, bool hasAlpha);
+ virtual void SetVolatile(bool isVolatile);
+
+ virtual bool Palletize();
+};
+
+}
+
+#endif //__MEMORYIMAGE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MemoryOuputModule.cpp b/osframework/source/SexyAppFramework/MemoryOuputModule.cpp
new file mode 100644
index 0000000..cb5cb00
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MemoryOuputModule.cpp
@@ -0,0 +1,81 @@
+#include "MemoryOutputModule.h"
+#include <decoder.h>
+
+int memory_output_module_probe(const char *name)
+{
+ ByteVector* aByteVector = (ByteVector*) atoi(name);
+
+ if (aByteVector == NULL)
+ return XA_ERROR_INVALID_PARAMETERS;
+
+ return XA_SUCCESS;
+}
+
+int memory_output_module_query(XA_OutputModuleQuery *query,
+ unsigned long query_mask)
+{
+ return XA_SUCCESS;
+}
+
+int memory_output_new(XA_OutputInstance **output, const char *name,
+ XA_OutputModuleClassInfo *class_info,
+ XA_DecoderInfo *decoder)
+{
+
+ *output = (XA_OutputInstance*) atoi(name);
+ MemoryOutput* aMemoryOutput = (MemoryOutput*) *output;
+
+ return XA_SUCCESS;
+}
+
+int memory_output_delete(XA_OutputInstance *output)
+{
+ return XA_SUCCESS;
+}
+
+int memory_output_open(XA_OutputInstance *output)
+{
+ return XA_SUCCESS;
+}
+
+int memory_output_close(XA_OutputInstance *output)
+{
+ return XA_SUCCESS;
+}
+
+int memory_output_write(XA_OutputInstance *output, const void *buffer,
+ unsigned long size, unsigned int bytes_per_sample,
+ unsigned int nb_channels, unsigned int sample_rate)
+{
+ MemoryOutput* aMemoryOutput = (MemoryOutput*) output;
+
+ aMemoryOutput->mBitsPerSample = bytes_per_sample*8;
+ aMemoryOutput->mNumChannels = nb_channels;
+ aMemoryOutput->mSamplingRate = sample_rate;
+
+ aMemoryOutput->mByteVector.insert(aMemoryOutput->mByteVector.end(),
+ (const unsigned char*) buffer,
+ (const unsigned char*) buffer + size);
+
+ return XA_SUCCESS;
+}
+
+int memory_output_module_register(XA_OutputModule *module)
+{
+ module->api_version_id = XA_SYNC_API_VERSION;
+ module->output_module_probe = memory_output_module_probe;
+ module->output_module_query = memory_output_module_query;
+ module->output_new = memory_output_new;
+ module->output_delete = memory_output_delete;
+ module->output_open = memory_output_open;
+ module->output_close = memory_output_close;
+ module->output_write = memory_output_write;
+ module->output_get_buffer = NULL;
+ module->output_set_control = NULL;
+ module->output_get_control = NULL;
+ module->output_get_status = NULL;
+ module->output_get_caps = NULL;
+ module->output_send_message = NULL;
+
+ return XA_SUCCESS;
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MiscBuild.cpp b/osframework/source/SexyAppFramework/MiscBuild.cpp
new file mode 100644
index 0000000..999c307
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MiscBuild.cpp
@@ -0,0 +1,19 @@
+#include "XMLParser.cpp"
+#include "SexyMatrix.cpp"
+#include "SEHCatcher.cpp"
+#include "PropertiesParser.cpp"
+#include "PerfTimer.cpp"
+#include "MTRand.cpp"
+#include "KeyCodes.cpp"
+#include "InternetManager.cpp"
+#include "HTTPTransfer.cpp"
+#include "DirectXErrorString.cpp"
+#include "Debug.cpp"
+#include "CritSect.cpp"
+#include "Common.cpp"
+#include "Buffer.cpp"
+#include "BetaSupport.cpp"
+#include "ResourceManager.cpp"
+#include "ModVal.cpp"
+#include "DescParser.cpp"
+#include "Ratio.cpp" \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MiscBuildBase.cpp b/osframework/source/SexyAppFramework/MiscBuildBase.cpp
new file mode 100644
index 0000000..badf3a3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MiscBuildBase.cpp
@@ -0,0 +1,18 @@
+#include "Flags.cpp"
+#include "XMLParser.cpp"
+#include "SexyMatrix.cpp"
+#include "SEHCatcher.cpp"
+#include "PropertiesParser.cpp"
+#include "PerfTimer.cpp"
+#include "MTRand.cpp"
+#include "KeyCodes.cpp"
+#include "HTTPTransfer.cpp"
+#include "DirectXErrorString.cpp"
+#include "Debug.cpp"
+#include "CritSect.cpp"
+#include "Common.cpp"
+#include "Buffer.cpp"
+#include "ResourceManager.cpp"
+#include "ModVal.cpp"
+#include "DescParser.cpp"
+#include "Ratio.cpp" \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ModVal.cpp b/osframework/source/SexyAppFramework/ModVal.cpp
new file mode 100644
index 0000000..a7333af
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ModVal.cpp
@@ -0,0 +1,669 @@
+#include "ModVal.h"
+#include "Common.h"
+#include <fstream>
+
+struct ModStorage
+{
+ bool mChanged;
+ int mInt;
+ double mDouble;
+ std::string mString;
+};
+
+struct ModPointer
+{
+ const char *mStrPtr;
+ int mLineNum;
+
+ ModPointer() : mStrPtr(NULL), mLineNum(0) {}
+ ModPointer(const char *theStrPtr, int theLineNum) : mStrPtr(theStrPtr), mLineNum(theLineNum) {}
+};
+
+typedef std::map<int,ModPointer> ModStorageMap; // stores counters
+
+struct FileMod
+{
+ bool mHasMods;
+ ModStorageMap mMap;
+
+ FileMod(bool hasMods = false) { mHasMods = hasMods; }
+};
+
+typedef std::map<std::string, int> StringToIntMap;
+typedef std::map<std::string, FileMod> FileModMap;
+
+static StringToIntMap gStringToIntMap;
+time_t gLastFileTime = 0;
+const char *gSampleString = NULL; // for finding the others
+
+static FileModMap& GetFileModMap()
+{
+ static FileModMap aMap;
+ return aMap;
+}
+
+static const char* FindFileInStringTable(const std::string &theSearch, const char *theMem, DWORD theLength, const char *theStartPos)
+{
+ const char *aFind = NULL;
+ try
+ {
+ aFind = std::search(theStartPos,theMem+theLength,theSearch.c_str(),theSearch.c_str()+theSearch.length());
+ if (aFind>=theMem+theLength)
+ return NULL;
+ else
+ return aFind;
+ }
+ catch(...)
+ {
+ return NULL;
+ }
+
+ return NULL;
+}
+
+static bool ParseModValString(std::string &theStr, int *theCounter = NULL, int *theLineNum = NULL)
+{
+ int aPos = theStr.length()-1;
+ bool foundComma = false;
+ while (aPos>0)
+ {
+ if (!foundComma && theStr[aPos]==',')
+ {
+ aPos--;
+ foundComma = true;
+ }
+ else if (isdigit(theStr[aPos]))
+ aPos--;
+ else
+ break;
+ }
+
+ if (aPos==theStr.length()-1 || aPos==0) // no number,number to erase... or empty file
+ return false;
+
+ aPos++;
+ int aCounterVal = -1, aLineNum = -1;
+ if (sscanf(theStr.c_str()+aPos,"%d,%d",&aCounterVal,&aLineNum)!=2) // couldn't parse out the numbers
+ return false;
+
+ theStr.resize(aPos);
+ if (theCounter) *theCounter = aCounterVal;
+ if (theLineNum) *theLineNum = aLineNum;
+ return true;
+}
+
+static bool FindModValsInMemoryHelper(const char *theMem, DWORD theLength)
+{
+ std::string aSearchStr = "SEXYMODVAL";
+
+ FileModMap &aMap = GetFileModMap();
+
+ bool foundOne = false;
+ const char *aPtr = theMem;
+ while (true)
+ {
+ aPtr = FindFileInStringTable(aSearchStr,theMem,theLength,aPtr);
+ if (aPtr==NULL)
+ break;
+
+ int aCounter, aLineNum;
+ std::string aFileName = aPtr+10; // skip SEXYMODVAL
+ if (ParseModValString(aFileName,&aCounter,&aLineNum))
+ {
+ if (aLineNum==4105)
+ _asm nop;
+
+ FileMod &aFileMod = aMap[aFileName];
+ aFileMod.mMap[aCounter] = ModPointer(aPtr-5,aLineNum);
+ foundOne = true;
+ }
+ aPtr++;
+ }
+
+ return foundOne;
+}
+
+static void FindModValsInMemory()
+{
+ MEMORY_BASIC_INFORMATION mbi;
+ PVOID pvAddress = 0;
+
+ const char *aMem = NULL;
+ DWORD aMemLength = 0;
+
+ int aFound = 0;
+ int aTotal = 0;
+ memset(&mbi, 0, sizeof(MEMORY_BASIC_INFORMATION));
+ for (; VirtualQuery(pvAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == sizeof(MEMORY_BASIC_INFORMATION); pvAddress = ((BYTE*)mbi.BaseAddress) + mbi.RegionSize)
+ {
+ const char *anAddress = (const char*)mbi.BaseAddress;
+ if (mbi.State==MEM_COMMIT && mbi.Type==MEM_IMAGE)
+ {
+ aTotal++;
+ if (aMem!=NULL && aMem+aMemLength==anAddress) // compact these two
+ {
+ aMemLength += mbi.RegionSize;
+ continue;
+ }
+
+ if (aMem!=NULL) // do find in old section
+ {
+ if (FindModValsInMemoryHelper(aMem,aMemLength))
+ {
+ aFound++;
+ return;
+ }
+
+ aMem = NULL;
+ }
+
+ aMem = anAddress;
+ aMemLength = mbi.RegionSize;
+ }
+ }
+
+ if (aMem!=NULL)
+ {
+ if (FindModValsInMemoryHelper(aMem,aMemLength))
+ aFound++;
+ }
+}
+
+static ModStorage* CreateFileModsHelper(const char* theFileName)
+{
+ ModStorage *aModStorage = new ModStorage;
+ aModStorage->mChanged = false;
+
+ // Change this thinggie
+ DWORD anOldProtect;
+ VirtualProtect((LPVOID) theFileName, 5, PAGE_READWRITE, &anOldProtect);
+ *((char*) theFileName) = 0;
+ *((ModStorage**) (theFileName+1)) = aModStorage;
+ VirtualProtect((LPVOID) theFileName, 5, anOldProtect, &anOldProtect);
+
+ return aModStorage;
+}
+
+
+static ModStorage* CreateFileMods(const char* theFileName)
+{
+ if (gSampleString==NULL)
+ gSampleString = theFileName;
+
+ std::string aFileName = theFileName+15; // skip SEXY_SEXYMODVAL
+ ParseModValString(aFileName);
+
+ FileModMap &aMap = GetFileModMap();
+ aMap[aFileName].mHasMods = true;
+
+ return CreateFileModsHelper(theFileName);
+}
+
+int Sexy::ModVal(int theAreaNum, const char* theFileName, int theInt)
+{
+ if (*theFileName != 0)
+ CreateFileMods(theFileName);
+
+ ModStorage* aModStorage = *(ModStorage**)(theFileName+1);
+ if (aModStorage->mChanged)
+ return aModStorage->mInt;
+ else
+ return theInt;
+}
+
+double Sexy::ModVal(int theAreaNum, const char* theFileName, double theDouble)
+{
+ if (*theFileName != 0)
+ CreateFileMods(theFileName);
+
+ ModStorage* aModStorage = *(ModStorage**)(theFileName+1);
+ if (aModStorage->mChanged)
+ return aModStorage->mDouble;
+ else
+ return theDouble;
+}
+
+float Sexy::ModVal(int theAreaNum, const char* theFileName, float theFloat)
+{
+ return (float) ModVal(theAreaNum, theFileName, (double) theFloat);
+}
+
+const char* Sexy::ModVal(int theAreaNum, const char* theFileName, const char *theStr)
+{
+ if (*theFileName != 0)
+ CreateFileMods(theFileName);
+
+ ModStorage* aModStorage = *(ModStorage**)(theFileName+1);
+ if (aModStorage->mChanged)
+ return aModStorage->mString.c_str();
+ else
+ return theStr;
+}
+
+
+void Sexy::AddModValEnum(const std::string &theEnumName, int theVal)
+{
+ gStringToIntMap[theEnumName] = theVal;
+}
+
+static bool ModStringToInteger(const char* theString, int* theIntVal)
+{
+ *theIntVal = 0;
+
+ int theRadix = 10;
+ bool isNeg = false;
+
+ unsigned i = 0;
+
+ if (isalpha((unsigned char)theString[i]) || theString[i]=='_') // enum
+ {
+
+ std::string aStr;
+ while (isalnum((unsigned char)theString[i]) || theString[i]=='_')
+ {
+ aStr += theString[i];
+ i++;
+ }
+
+ StringToIntMap::iterator anItr = gStringToIntMap.find(aStr);
+ if (anItr!=gStringToIntMap.end())
+ {
+ *theIntVal = anItr->second;
+ return true;
+ }
+
+ i = 0;
+ }
+
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (;;)
+ {
+ char aChar = theString[i];
+
+ if ((theRadix == 10) && (aChar >= '0') && (aChar <= '9'))
+ *theIntVal = (*theIntVal * 10) + (aChar - '0');
+ else if ((theRadix == 0x10) &&
+ (((aChar >= '0') && (aChar <= '9')) ||
+ ((aChar >= 'A') && (aChar <= 'F')) ||
+ ((aChar >= 'a') && (aChar <= 'f'))))
+ {
+ if (aChar <= '9')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - '0');
+ else if (aChar <= 'F')
+ *theIntVal = (*theIntVal * 0x10) + (aChar - 'A') + 0x0A;
+ else
+ *theIntVal = (*theIntVal * 0x10) + (aChar - 'a') + 0x0A;
+ }
+ else if (((aChar == 'x') || (aChar == 'X')) && (i == 1) && (*theIntVal == 0))
+ {
+ theRadix = 0x10;
+ }
+ else if (aChar == ')')
+ {
+ if (isNeg)
+ *theIntVal = -*theIntVal;
+ return true;
+ }
+ else
+ {
+ *theIntVal = 0;
+ return false;
+ }
+
+ i++;
+ }
+}
+
+static bool ModStringToDouble(const char* theString, double* theDoubleVal)
+{
+ *theDoubleVal = 0.0;
+
+ bool isNeg = false;
+
+ unsigned i = 0;
+ if (theString[i] == '-')
+ {
+ isNeg = true;
+ i++;
+ }
+
+ for (;;)
+ {
+ char aChar = theString[i];
+
+ if ((aChar >= '0') && (aChar <= '9'))
+ *theDoubleVal = (*theDoubleVal * 10) + (aChar - '0');
+ else if (aChar == '.')
+ {
+ i++;
+ break;
+ }
+ else if ((aChar == ')') || ((aChar == 'f') && (theString[i+1] == ')'))) // At end
+ {
+ if (isNeg)
+ *theDoubleVal = -*theDoubleVal;
+ return true;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+
+ i++;
+ }
+
+ double aMult = 0.1;
+ for (;;)
+ {
+ char aChar = theString[i];
+
+ if ((aChar >= '0') && (aChar <= '9'))
+ {
+ *theDoubleVal += (aChar - '0') * aMult;
+ aMult /= 10.0;
+ }
+ else if ((aChar == ')') || ((aChar == 'f') && (theString[i+1] == ')'))) // At end
+ {
+ if (isNeg)
+ *theDoubleVal = -*theDoubleVal;
+ return true;
+ }
+ else
+ {
+ *theDoubleVal = 0.0;
+ return false;
+ }
+
+ i++;
+ }
+}
+
+static bool ModStringToString(const char* theString, std::string &theStrVal)
+{
+ if (theString[0]!='"')
+ return false;
+
+ std::string &aStr = theStrVal;
+ aStr.erase();
+
+ int i=1;
+ while (true)
+ {
+ if (theString[i]=='\\')
+ {
+ i++;
+ switch (theString[i++])
+ {
+ case 'n': aStr += '\n'; break;
+ case 't': aStr += '\t'; break;
+ case '\\': aStr += '\\'; break;
+ case '"': aStr += '\"'; break;
+ default: return false;
+ }
+ }
+ else if (theString[i]=='"')
+ {
+ i++;
+ while (isspace((unsigned char)theString[i]))
+ i++;
+
+ if (theString[i]!='"') // continued string
+ return true;
+ else
+ break;
+ }
+ else if (theString[i]=='\0')
+ return false;
+ else
+ aStr += theString[i++];
+ }
+
+ return true;
+}
+
+bool Sexy::ReparseModValues()
+{
+ if (gLastFileTime == 0)
+ {
+ char anEXEName[256];
+ GetModuleFileNameA(NULL, anEXEName, 256);
+ gLastFileTime = GetFileDate(anEXEName);
+
+ FindModValsInMemory();
+ }
+
+ bool hasNewFiles = false;
+ std::string aFileList;
+
+ // Process each file one at a time
+ FileModMap &aMap = GetFileModMap();
+ FileModMap::iterator aFileModItr;
+ for (aFileModItr = aMap.begin(); aFileModItr != aMap.end(); ++aFileModItr)
+ {
+ FileMod &aFileMod = aFileModItr->second;
+ if (!aFileMod.mHasMods)
+ continue;
+
+ ModStorageMap &aModMap = aFileMod.mMap;
+ std::string aFileName = aFileModItr->first;
+
+ time_t aThisTime = GetFileDate(aFileName);
+ if (aThisTime > gLastFileTime)
+ {
+ gLastFileTime = aThisTime;
+ hasNewFiles = true;
+ }
+
+ if (aFileList.length() > 0)
+ aFileList += "\r\n ";
+ aFileList += aFileName;
+
+ int aLineNum = 1;
+ int aModNum = 0;
+ ModStorageMap::iterator aModMapItr = aModMap.begin();
+
+ std::fstream aStream(aFileName.c_str(), std::ios::in);
+
+ if (aStream.is_open())
+ {
+ while (!aStream.eof())
+ {
+ char aString[8192];
+ aStream.getline(aString, 8192);
+
+ int aCharIdx = 0;
+ int aChar = 0;
+ int aLastChar = 0;
+ while (aString[aCharIdx] != 0)
+ {
+ aLastChar = aChar;
+ aChar = aString[aCharIdx];
+
+ if (aChar == '"') // Skip strings
+ {
+ while (true)
+ {
+ aLastChar = aChar;
+ aChar = aString[++aCharIdx];
+
+ if (aChar=='\\' && aLastChar=='\\') // so we don't interpret \\" as an escaped quote
+ aChar = 0;
+ else if (aChar=='"' && aLastChar!='\\')
+ break;
+ else if (aChar==0)
+ {
+ if (aLastChar=='\\') // continuation
+ {
+ aCharIdx = -1;
+ aChar = 0;
+ aLastChar = 0;
+ aLineNum++;
+
+ aStream.getline(aString, 8192);
+ if (aString[0]!=0 || !aStream.eof()) // got valid new line
+ continue;
+ }
+
+ char aStr[512];
+ sprintf(aStr, "ERROR in %s on line %d: Error parsing quotes", aFileName.c_str(), aLineNum);
+ MessageBoxA(NULL, aStr, "MODVAL ERROR", MB_OK | MB_ICONERROR);
+ return false;
+ }
+ }
+ }
+ else if (aChar=='/') // Skip C++ comments
+ {
+ if (aLastChar=='/')
+ {
+
+ while (true)
+ {
+ aLastChar = aChar;
+ aChar = aString[++aCharIdx];
+ if (aChar==0) // line continuation
+ {
+ if (aLastChar=='\\') // continuation
+ {
+ aCharIdx = -1;
+ aChar = 0;
+ aLastChar = 0;
+ aLineNum++;
+
+ aStream.getline(aString, 8192);
+ if (aString[0]!=0 || !aStream.eof()) // got valid new line
+ continue;
+ }
+ else
+ {
+ aCharIdx--;
+ break;
+ }
+
+ char aStr[512];
+ sprintf(aStr, "ERROR in %s on line %d: Error parsing c++ comment", aFileName.c_str(), aLineNum);
+ MessageBoxA(NULL, aStr, "MODVAL ERROR", MB_OK | MB_ICONERROR);
+ return false;
+ }
+ }
+ }
+ }
+ else if (aChar=='*') // skip C comments
+ {
+ if (aLastChar=='/')
+ {
+ while (true)
+ {
+ aLastChar = aChar;
+ aChar = aString[++aCharIdx];
+ if (aChar=='/' && aLastChar=='*')
+ break;
+ else if (aChar==0) // line continuation
+ {
+ aCharIdx = -1;
+ aChar = 0;
+ aLastChar = 0;
+ aLineNum++;
+
+ aStream.getline(aString, 8192);
+ if (aString[0]!=0 || !aStream.eof()) // got valid new line
+ continue;
+
+ char aStr[512];
+ sprintf(aStr, "ERROR in %s on line %d: Error parsing c comment", aFileName.c_str(), aLineNum);
+ MessageBoxA(NULL, aStr, "MODVAL ERROR", MB_OK | MB_ICONERROR);
+ return false;
+ }
+ }
+ }
+ }
+ else if (aChar == '(')
+ {
+ int theAreaNum = -1;
+ if ((aCharIdx >= 2) && (aString[aCharIdx-1] == 'M') &&
+ (!isalpha((unsigned char) aString[aCharIdx-2])))
+ {
+ theAreaNum = 0;
+ }
+ else if ((aCharIdx >= 3) &&
+ (aString[aCharIdx-1] >= '1') && (aString[aCharIdx-1] <= '9') &&
+ (aString[aCharIdx-2] == 'M') &&
+ (!isalpha((unsigned char) aString[aCharIdx-3])))
+ {
+ theAreaNum = aString[aCharIdx-1] - '0';
+ }
+
+ if (theAreaNum != -1)
+ {
+ while (aModMapItr!=aModMap.end() && aModMapItr->second.mLineNum<aLineNum)
+ ++aModMapItr;
+
+ if (aModMapItr!=aModMap.end() && aModMapItr->second.mLineNum==aLineNum)
+ {
+ const char *aPtr = aModMapItr->second.mStrPtr;
+ aModMapItr++;
+
+ int anIntVal = 0;
+ double aDoubleVal = 0.0;
+ std::string aStrVal;
+
+ // Try to parse out a number
+ if ((ModStringToString(aString + aCharIdx + 1, aStrVal)) ||
+ (ModStringToInteger(aString + aCharIdx + 1, &anIntVal)) ||
+ (ModStringToDouble(aString + aCharIdx + 1, &aDoubleVal)))
+ {
+ // We found a mod value!
+
+ if (*aPtr!=0) // have stored something here
+ CreateFileMods(aPtr);
+
+ ModStorage* aModStorage = *(ModStorage**)(aPtr+1);
+ aModStorage->mInt = anIntVal;
+ aModStorage->mDouble = aDoubleVal;
+ aModStorage->mString = aStrVal;
+ aModStorage->mChanged = true;
+ }
+ else
+ {
+ char aStr[512];
+ sprintf(aStr, "ERROR in %s on line %d. Parsing Error.", aFileName.c_str(), aLineNum);
+ MessageBoxA(NULL, aStr, "MODVAL ERROR", MB_OK | MB_ICONERROR);
+
+ return false;
+ }
+ }
+ else
+ {
+ // Functions can be optimized out
+ }
+ }
+ }
+
+ aCharIdx++;
+ }
+
+ aLineNum++;
+ }
+ }
+ else
+ {
+ MessageBoxA(NULL, (std::string("ERROR: Unable to open ") + aFileName + " for reparsing.").c_str(), "MODVAL ERROR!", MB_OK | MB_ICONERROR);
+ return false;
+ }
+ }
+
+ if (!hasNewFiles)
+ {
+ if (aFileList.length() == 0)
+ aFileList = "none";
+ MessageBoxA(NULL, (std::string("WARNING: No file changes detected. Files parsed: \r\n ") + aFileList).c_str(), "MODVAL WARNING!", MB_OK | MB_ICONWARNING);
+ return false;
+ }
+
+ return true;
+}
diff --git a/osframework/source/SexyAppFramework/ModVal.h b/osframework/source/SexyAppFramework/ModVal.h
new file mode 100644
index 0000000..4712e3f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ModVal.h
@@ -0,0 +1,72 @@
+#ifndef __MODVAL_H__
+#define __MODVAL_H__
+
+#include <string>
+
+/*
+ This module allows for dynamic modification of integer and floating-point
+ constants at run-time.
+
+ Place the M() around values you want to allow to be changed at run-time.
+ When you want to modify a value, simply change the value in the source
+ code file and call ReparseModValues() within your program to re-read the
+ source files, checking for changes in constants. Your program will need
+ to contain some trigger such as a key combination to trigger the
+ ReparseModValues() call.
+
+ Example:
+ x = x + M(2.1);
+
+ Caveats:
+ This module determines which files to parse through (during
+ ReparseModValues()) at run-time, so if a M() macro has not yet been
+ executed within a particular source file, its value will not be
+ updated.
+
+ Performance:
+ There a small setup cost the first time each M() value is accessed
+ after program startup and reparsing, but after that there is just the
+ tiny overhead of a function call and a few vector dereferences.
+
+ */
+
+namespace Sexy
+{
+
+#if defined(SEXY_DISABLE_MODVAL) || defined(RELEASEFINAL)
+#define M(val) (val)
+#define M1(val) (val)
+#define M2(val) (val)
+#define M3(val) (val)
+#define M4(val) (val)
+#define M5(val) (val)
+#define M6(val) (val)
+#define M7(val) (val)
+#define M8(val) (val)
+#define M9(val) (val)
+#else
+#define MODVAL_STR_COUNTER2(x,y,z) x#y","#z
+#define MODVAL_STR_COUNTER1(x,y,z) MODVAL_STR_COUNTER2(x,y,z)
+#define MODVAL_STR_COUNTER(x) MODVAL_STR_COUNTER1(x,__COUNTER__,__LINE__)
+#define M(val) ModVal(0, MODVAL_STR_COUNTER("SEXY_SEXYMODVAL"__FILE__), (val))
+#define M1(val) M(val)
+#define M2(val) M(val)
+#define M3(val) M(val)
+#define M4(val) M(val)
+#define M5(val) M(val)
+#define M6(val) M(val)
+#define M7(val) M(val)
+#define M8(val) M(val)
+#define M9(val) M(val)
+#endif
+
+int ModVal(int theAreaNum, const char* theFileName, int theInt);
+double ModVal(int theAreaNum, const char* theFileName, double theDouble);
+float ModVal(int theAreaNum, const char* theFileName, float theFloat);
+const char* ModVal(int theAreaNum, const char* theFileName, const char *theStr);
+bool ReparseModValues();
+void AddModValEnum(const std::string &theEnumName, int theVal);
+
+}
+
+#endif //__MODVAL_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/MusicInterface.cpp b/osframework/source/SexyAppFramework/MusicInterface.cpp
new file mode 100644
index 0000000..39fe26d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MusicInterface.cpp
@@ -0,0 +1,90 @@
+#include "MusicInterface.h"
+#include "SexyAppBase.h"
+
+using namespace Sexy;
+
+MusicInterface::MusicInterface()
+{
+}
+
+MusicInterface::~MusicInterface()
+{
+}
+
+bool MusicInterface::LoadMusic(int theSongId, const std::string& theFileName)
+{
+ return false;
+}
+
+void MusicInterface::PlayMusic(int theSongId, int theOffset, bool noLoop)
+{
+}
+
+void MusicInterface::StopMusic(int theSongId)
+{
+}
+
+void MusicInterface::PauseMusic(int theSongId)
+{
+}
+
+void MusicInterface::ResumeMusic(int theSongId)
+{
+}
+
+void MusicInterface::StopAllMusic()
+{
+}
+
+void MusicInterface::UnloadMusic(int theSongId)
+{
+}
+
+void MusicInterface::UnloadAllMusic()
+{
+}
+
+void MusicInterface::PauseAllMusic()
+{
+}
+
+void MusicInterface::ResumeAllMusic()
+{
+}
+
+void MusicInterface::FadeIn(int theSongId, int theOffset, double theSpeed, bool noLoop)
+{
+}
+
+void MusicInterface::FadeOut(int theSongId, bool stopSong, double theSpeed)
+{
+}
+
+void MusicInterface::FadeOutAll(bool stopSong, double theSpeed)
+{
+}
+
+void MusicInterface::SetSongVolume(int theSongId, double theVolume)
+{
+}
+
+void MusicInterface::SetSongMaxVolume(int theSongId, double theMaxVolume)
+{
+}
+
+bool MusicInterface::IsPlaying(int theSongId)
+{
+ return false;
+}
+
+void MusicInterface::SetVolume(double theVolume)
+{
+}
+
+void MusicInterface::SetMusicAmplify(int theSongId, double theAmp)
+{
+}
+
+void MusicInterface::Update()
+{
+}
diff --git a/osframework/source/SexyAppFramework/MusicInterface.h b/osframework/source/SexyAppFramework/MusicInterface.h
new file mode 100644
index 0000000..a27a1e7
--- /dev/null
+++ b/osframework/source/SexyAppFramework/MusicInterface.h
@@ -0,0 +1,43 @@
+#ifndef __MUSICINTERFACE_H__
+#define __MUSICINTERFACE_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+class MusicInterface
+{
+public:
+
+public:
+ MusicInterface();
+ virtual ~MusicInterface();
+
+ virtual bool LoadMusic(int theSongId, const std::string& theFileName);
+ virtual void PlayMusic(int theSongId, int theOffset = 0, bool noLoop = false);
+ virtual void StopMusic(int theSongId);
+ virtual void PauseMusic(int theSongId);
+ virtual void ResumeMusic(int theSongId);
+ virtual void StopAllMusic();
+
+ virtual void UnloadMusic(int theSongId);
+ virtual void UnloadAllMusic();
+ virtual void PauseAllMusic();
+ virtual void ResumeAllMusic();
+
+ virtual void FadeIn(int theSongId, int theOffset = -1, double theSpeed = 0.002, bool noLoop = false);
+ virtual void FadeOut(int theSongId, bool stopSong = true, double theSpeed = 0.004);
+ virtual void FadeOutAll(bool stopSong = true, double theSpeed = 0.004);
+ virtual void SetSongVolume(int theSongId, double theVolume);
+ virtual void SetSongMaxVolume(int theSongId, double theMaxVolume);
+ virtual bool IsPlaying(int theSongId);
+
+ virtual void SetVolume(double theVolume);
+ virtual void SetMusicAmplify(int theSongId, double theAmp);
+ virtual void Update();
+};
+
+}
+
+#endif //__MUSICINTERFACE_H__
diff --git a/osframework/source/SexyAppFramework/NativeDisplay.cpp b/osframework/source/SexyAppFramework/NativeDisplay.cpp
new file mode 100644
index 0000000..e11c687
--- /dev/null
+++ b/osframework/source/SexyAppFramework/NativeDisplay.cpp
@@ -0,0 +1,28 @@
+#include "NativeDisplay.h"
+
+using namespace Sexy;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+NativeDisplay::NativeDisplay()
+{
+ mRGBBits = 0;
+
+ mRedMask = 0;
+ mGreenMask = 0;
+ mBlueMask = 0;
+
+ mRedBits = 0;
+ mGreenBits = 0;
+ mBlueBits = 0;
+
+ mRedShift = 0;
+ mGreenShift = 0;
+ mBlueShift = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+NativeDisplay::~NativeDisplay()
+{
+}
diff --git a/osframework/source/SexyAppFramework/NativeDisplay.h b/osframework/source/SexyAppFramework/NativeDisplay.h
new file mode 100644
index 0000000..88f1917
--- /dev/null
+++ b/osframework/source/SexyAppFramework/NativeDisplay.h
@@ -0,0 +1,32 @@
+#ifndef __NATIVEDISPLAY_H__
+#define __NATIVEDISPLAY_H__
+#include "Common.h"
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class NativeDisplay
+{
+public:
+ int mRGBBits;
+ ulong mRedMask;
+ ulong mGreenMask;
+ ulong mBlueMask;
+ int mRedBits;
+ int mGreenBits;
+ int mBlueBits;
+ int mRedShift;
+ int mGreenShift;
+ int mBlueShift;
+
+public:
+ NativeDisplay();
+ virtual ~NativeDisplay();
+};
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/PerfTimer.cpp b/osframework/source/SexyAppFramework/PerfTimer.cpp
new file mode 100644
index 0000000..e3ccfd2
--- /dev/null
+++ b/osframework/source/SexyAppFramework/PerfTimer.cpp
@@ -0,0 +1,321 @@
+#include "PerfTimer.h"
+#include <map>
+
+using namespace Sexy;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+inline int QueryCounters(__int64 *lpPerformanceCount)
+{
+ /* returns TSC only */
+ _asm
+ {
+ mov ebx, dword ptr [lpPerformanceCount]
+ rdtsc
+ mov dword ptr [ebx], eax
+ mov dword ptr [ebx+4], edx
+ }
+ return 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+inline int DeltaCounters(__int64 *lpPerformanceCount)
+{
+ _asm
+ {
+ mov ebx, dword ptr [lpPerformanceCount]
+ rdtsc
+ sub eax, dword ptr [ebx]
+ sbb edx, dword ptr [ebx+4]
+ mov dword ptr [ebx], eax
+ mov dword ptr [ebx+4], edx
+ }
+ return 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static __int64 CalcCPUSpeed()
+{
+ int aPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST);
+ LARGE_INTEGER goal, current, period;
+ __int64 Ticks;
+
+ if( !QueryPerformanceFrequency( &period ) ) return 0;
+
+ QueryPerformanceCounter(&goal);
+ goal.QuadPart+=period.QuadPart/100;
+ QueryCounters( &Ticks );
+ do
+ {
+ QueryPerformanceCounter(&current);
+ } while(current.QuadPart<goal.QuadPart);
+ DeltaCounters( &Ticks );
+
+ SetThreadPriority(GetCurrentThread(),aPriority);
+ return( Ticks * 100 ); // Hz
+
+}
+
+static __int64 gCPUSpeed = 0;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+PerfTimer::PerfTimer()
+{
+ mDuration = 0;
+ mStart.QuadPart = 0;
+ mRunning = false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void PerfTimer::CalcDuration()
+{
+ LARGE_INTEGER anEnd, aFreq;
+ QueryPerformanceCounter(&anEnd);
+ QueryPerformanceFrequency(&aFreq);
+ mDuration = ((anEnd.QuadPart-mStart.QuadPart)*1000)/(double)aFreq.QuadPart;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void PerfTimer::Start()
+{
+ mRunning = true;
+ QueryPerformanceCounter(&mStart);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void PerfTimer::Stop()
+{
+ if(mRunning)
+ {
+ CalcDuration();
+ mRunning = false;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+double PerfTimer::GetDuration()
+{
+ if(mRunning)
+ CalcDuration();
+
+ return mDuration;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+__int64 PerfTimer::GetCPUSpeed()
+{
+ if(gCPUSpeed<=0)
+ {
+ gCPUSpeed = CalcCPUSpeed();
+ if (gCPUSpeed<=0)
+ gCPUSpeed = 1;
+ }
+
+ return gCPUSpeed;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int PerfTimer::GetCPUSpeedMHz()
+{
+ return (int)(gCPUSpeed/1000000);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct PerfInfo
+{
+ const char *mPerfName;
+ mutable __int64 mStartTime;
+ mutable __int64 mDuration;
+ mutable double mMillisecondDuration;
+ mutable double mLongestCall;
+ mutable int mStartCount;
+ mutable int mCallCount;
+
+ PerfInfo(const char *theName) : mPerfName(theName), mStartTime(0), mDuration(0), mStartCount(0), mCallCount(0), mLongestCall(0) { }
+
+ bool operator<(const PerfInfo &theInfo) const { return stricmp(mPerfName,theInfo.mPerfName)<0; }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+typedef std::set<PerfInfo> PerfInfoSet;
+static PerfInfoSet gPerfInfoSet;
+static bool gPerfOn = false;
+static __int64 gStartTime;
+static __int64 gCollateTime;
+double gDuration = 0;
+int gStartCount = 0;
+int gPerfRecordTop = 0;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct PerfRecord
+{
+ const char *mName;
+ __int64 mTime;
+ bool mStart;
+
+ PerfRecord() { }
+ PerfRecord(const char *theName, bool start) : mName(theName), mStart(start) { QueryCounters(&mTime); }
+};
+typedef std::vector<PerfRecord> PerfRecordVector;
+PerfRecordVector gPerfRecordVector;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static inline void InsertPerfRecord(PerfRecord &theRecord)
+{
+ if(theRecord.mStart)
+ {
+ PerfInfoSet::iterator anItr = gPerfInfoSet.insert(PerfInfo(theRecord.mName)).first;
+ anItr->mCallCount++;
+
+ if ( ++anItr->mStartCount == 1)
+ anItr->mStartTime = theRecord.mTime;
+ }
+ else
+ {
+ PerfInfoSet::iterator anItr = gPerfInfoSet.find(theRecord.mName);
+ if(anItr != gPerfInfoSet.end())
+ {
+ if( --anItr->mStartCount == 0)
+ {
+ __int64 aDuration = theRecord.mTime - anItr->mStartTime;
+ anItr->mDuration += aDuration;
+
+ if (aDuration > anItr->mLongestCall)
+ anItr->mLongestCall = (double)aDuration;
+ }
+ }
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static inline void CollatePerfRecords()
+{
+ __int64 aTime1,aTime2;
+ QueryCounters(&aTime1);
+
+ for(int i=0; i<gPerfRecordTop; i++)
+ InsertPerfRecord(gPerfRecordVector[i]);
+
+ gPerfRecordTop = 0;
+ QueryCounters(&aTime2);
+
+ gCollateTime += aTime2-aTime1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static inline void PushPerfRecord(PerfRecord &theRecord)
+{
+ if(gPerfRecordTop >= (int)gPerfRecordVector.size())
+ gPerfRecordVector.push_back(theRecord);
+ else
+ gPerfRecordVector[gPerfRecordTop] = theRecord;
+
+ ++gPerfRecordTop;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool SexyPerf::IsPerfOn()
+{
+ return gPerfOn;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyPerf::BeginPerf(bool measurePerfOverhead)
+{
+ gPerfInfoSet.clear();
+ gPerfRecordTop = 0;
+ gStartCount = 0;
+ gCollateTime = 0;
+
+ if(!measurePerfOverhead)
+ gPerfOn = true;
+
+ QueryCounters(&gStartTime);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyPerf::EndPerf()
+{
+ __int64 anEndTime;
+ QueryCounters(&anEndTime);
+
+ CollatePerfRecords();
+
+ gPerfOn = false;
+
+ __int64 aFreq = PerfTimer::GetCPUSpeed();
+
+ gDuration = ((double)(anEndTime - gStartTime - gCollateTime))*1000/aFreq;
+
+ for (PerfInfoSet::iterator anItr = gPerfInfoSet.begin(); anItr != gPerfInfoSet.end(); ++anItr)
+ {
+ const PerfInfo &anInfo = *anItr;
+ anInfo.mMillisecondDuration = (double)anInfo.mDuration*1000/aFreq;
+ anInfo.mLongestCall = anInfo.mLongestCall*1000/aFreq;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyPerf::StartTiming(const char *theName)
+{
+ if(gPerfOn)
+ {
+ ++gStartCount;
+ PushPerfRecord(PerfRecord(theName,true));
+ }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyPerf::StopTiming(const char *theName)
+{
+ if(gPerfOn)
+ {
+ PushPerfRecord(PerfRecord(theName,false));
+ if(--gStartCount==0)
+ CollatePerfRecords();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+std::string SexyPerf::GetResults()
+{
+ std::string aResult;
+ char aBuf[512];
+
+ sprintf(aBuf,"Total Time: %.2f\n",gDuration);
+ aResult += aBuf;
+ for (PerfInfoSet::iterator anItr = gPerfInfoSet.begin(); anItr != gPerfInfoSet.end(); ++anItr)
+ {
+ const PerfInfo &anInfo = *anItr;
+ sprintf(aBuf,"%s (%d calls, %%%.2f time): %.2f (%.2f avg, %.2f longest)\n",anInfo.mPerfName,anInfo.mCallCount,anInfo.mMillisecondDuration/gDuration*100,anInfo.mMillisecondDuration,anInfo.mMillisecondDuration/anInfo.mCallCount,anInfo.mLongestCall);
+ aResult += aBuf;
+ }
+
+
+ return aResult;
+}
+
diff --git a/osframework/source/SexyAppFramework/PerfTimer.h b/osframework/source/SexyAppFramework/PerfTimer.h
new file mode 100644
index 0000000..dc84d2f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/PerfTimer.h
@@ -0,0 +1,122 @@
+#ifndef __SEXY_PERFTIMER_H__
+#define __SEXY_PERFTIMER_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class PerfTimer
+{
+protected:
+ LARGE_INTEGER mStart;
+ double mDuration;
+ bool mRunning;
+
+ void CalcDuration();
+
+public:
+ PerfTimer();
+ void Start();
+ void Stop();
+
+ double GetDuration();
+
+ static __int64 GetCPUSpeed(); // in Hz
+ static int GetCPUSpeedMHz();
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyPerf
+{
+public:
+ static void BeginPerf(bool measurePerfOverhead = false);
+ static void EndPerf();
+ static bool IsPerfOn();
+
+ static void StartTiming(const char *theName);
+ static void StopTiming(const char *theName);
+
+ static std::string GetResults();
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyAutoPerf
+{
+public:
+ const char *mName;
+ bool mIsStarted;
+
+ SexyAutoPerf(const char *theName) : mName(theName), mIsStarted(true) { SexyPerf::StartTiming(theName); }
+ SexyAutoPerf(const char *theName, bool doStart) : mIsStarted(doStart), mName(theName)
+ {
+ if(doStart)
+ SexyPerf::StartTiming(theName);
+ }
+
+ ~SexyAutoPerf() { Stop(); }
+
+ void Start()
+ {
+ if(!mIsStarted)
+ {
+ mIsStarted = true;
+ SexyPerf::StartTiming(mName);
+ }
+ }
+
+ void Stop()
+ {
+ if(mIsStarted)
+ {
+ SexyPerf::StopTiming(mName);
+ mIsStarted = false;
+ }
+ }
+};
+
+} // namespace Sexy
+
+#endif
+
+#pragma warning(push)
+#pragma warning(disable:4005)
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+//#define SEXY_PERF_ENABLED
+#if defined(SEXY_PERF_ENABLED) && !defined(RELEASEFINAL)
+
+#define SEXY_PERF_BEGIN(theName) SexyPerf::StartTiming(theName)
+#define SEXY_PERF_END(theName) SexyPerf::StopTiming(theName)
+#define SEXY_AUTO_PERF_MULTI(theName,theSuffix) SexyAutoPerf anAutoPerf##theSuffix(theName)
+#define SEXY_AUTO_PERF_2(theName,theSuffix) SEXY_AUTO_PERF_MULTI(theName,theSuffix)
+#define SEXY_AUTO_PERFL(theName) SEXY_AUTO_PERF_2(theName,__LINE__) // __LINE__ doesn't work correctly if Edit-and-Continue (/ZI) is enabled
+#define SEXY_AUTO_PERF(theName) SEXY_AUTO_PERF_2(theName,UNIQUE)
+
+#define SEXY_PERF_BEGIN_COND(theName,theCond) if(theCond) SexyPerf::StartTiming(theName)
+#define SEXY_PERF_END_COND(theName,theCond) if(theCond) SexyPerf::StopTiming(theName)
+#define SEXY_AUTO_PERF_MULTI_COND(theName,theSuffix,theCond) SexyAutoPerf anAutoPerf##theSuffix(theName,theCond);
+#define SEXY_AUTO_PERF_COND_2(theName,theSuffix,theCond) SEXY_AUTO_PERF_MULTI_COND(theName,theSuffix,theCond);
+#define SEXY_AUTO_PERF_CONDL(theName) SEXY_AUTO_PERF_COND_2(theName,__LINE__,theCond)
+#define SEXY_AUTO_PERF_COND(theName) SEXY_AUTO_PERF_COND_2(theName,UNIQUE,theCond)
+
+#else
+
+#define SEXY_PERF_BEGIN(theName)
+#define SEXY_PERF_END(theName)
+#define SEXY_AUTO_PERF_MULTI(theName,theSuffix)
+#define SEXY_AUTO_PERF(theName)
+
+#define SEXY_PERF_BEGIN_COND(theName,theCond)
+#define SEXY_PERF_END_COND(theName,theCond)
+#define SEXY_AUTO_PERF_MULTI_COND(theName,theSuffix,theCond)
+#define SEXY_AUTO_PERF_COND(theName)
+
+#endif
+
+#pragma warning(pop)
diff --git a/osframework/source/SexyAppFramework/Point.h b/osframework/source/SexyAppFramework/Point.h
new file mode 100644
index 0000000..66fa0dc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Point.h
@@ -0,0 +1,61 @@
+#ifndef __POINT_H__
+#define __POINT_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+template<class _T> class TPoint
+{
+public:
+ _T mX;
+ _T mY;
+
+public:
+ TPoint(_T theX, _T theY) :
+ mX(theX),
+ mY(theY)
+ {
+ }
+
+ TPoint(const TPoint<_T>& theTPoint) :
+ mX(theTPoint.mX),
+ mY(theTPoint.mY)
+ {
+ }
+
+ TPoint() :
+ mX(0),
+ mY(0)
+ {
+ }
+
+ inline bool operator==(const TPoint& p)
+ {
+ return ((p.mX == mX) && (p.mY == mY));
+ }
+
+ inline bool operator!=(const TPoint& p)
+ {
+ return ((p.mX != mX) || (p.mY != mY));
+ }
+
+ TPoint operator+(const TPoint& p) const {return TPoint(mX+p.mX, mY+p.mY);}
+ TPoint operator-(const TPoint& p) const {return TPoint(mX-p.mX, mY-p.mY);}
+ TPoint operator*(const TPoint& p) const {return TPoint(mX*p.mX, mY*p.mY);}
+ TPoint operator/(const TPoint& p) const {return TPoint(mX/p.mX, mY/p.mY);}
+ TPoint& operator+=(const TPoint& p) {mX+=p.mX; mY+=p.mY; return *this;}
+ TPoint& operator-=(const TPoint& p) {mX-=p.mX; mY-=p.mY; return *this;}
+ TPoint& operator*=(const TPoint& p) {mX*=p.mX; mY*=p.mY; return *this;}
+ TPoint& operator/=(const TPoint& p) {mX/=p.mX; mY/=p.mY; return *this;}
+ TPoint operator*(_T s) const {return TPoint(mX*s, mY*s);}
+ TPoint operator/(_T s) const {return TPoint(mX/s, mY/s);}
+};
+
+typedef TPoint<int> Point;
+typedef TPoint<double> FPoint;
+
+};
+
+#endif //__POINT_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/PropertiesParser.cpp b/osframework/source/SexyAppFramework/PropertiesParser.cpp
new file mode 100644
index 0000000..0c03ac1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/PropertiesParser.cpp
@@ -0,0 +1,265 @@
+#include "PropertiesParser.h"
+#include "XMLParser.h"
+#include <stdlib.h>
+
+using namespace Sexy;
+
+PropertiesParser::PropertiesParser(SexyAppBase* theApp)
+{
+ mApp = theApp;
+ mHasFailed = false;
+ mXMLParser = NULL;
+}
+
+void PropertiesParser::Fail(const SexyString& theErrorText)
+{
+ if (!mHasFailed)
+ {
+ mHasFailed = true;
+ int aLineNum = mXMLParser->GetCurrentLineNum();
+
+ mError = theErrorText;
+ if (aLineNum > 0) mError += StrFormat(_S(" on Line %d"), aLineNum);
+ if (!mXMLParser->GetFileName().empty()) mError += StrFormat(_S(" in File '%s'"), mXMLParser->GetFileName().c_str());
+ }
+}
+
+
+PropertiesParser::~PropertiesParser()
+{
+}
+
+
+bool PropertiesParser::ParseSingleElement(SexyString* aString)
+{
+ *aString = _S("");
+
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ Fail(_S("Unexpected Section: '") + aXMLElement.mValue + _S("'"));
+ return false;
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ *aString = aXMLElement.mValue;
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_END)
+ {
+ return true;
+ }
+ }
+}
+
+bool PropertiesParser::ParseStringArray(StringVector* theStringVector)
+{
+ theStringVector->clear();
+
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue == _S("String"))
+ {
+ SexyString aString;
+
+ if (!ParseSingleElement(&aString))
+ return false;
+
+ theStringVector->push_back(SexyStringToStringFast(aString));
+ }
+ else
+ {
+ Fail(_S("Invalid Section '") + aXMLElement.mValue + _S("'"));
+ return false;
+ }
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ Fail(_S("Element Not Expected '") + aXMLElement.mValue + _S("'"));
+ return false;
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_END)
+ {
+ return true;
+ }
+ }
+}
+
+
+bool PropertiesParser::ParseProperties()
+{
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue == _S("String"))
+ {
+ SexyString aDef;
+ if (!ParseSingleElement(&aDef))
+ return false;
+
+ std::string anId = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+ mApp->SetString(anId, SexyStringToWStringFast(aDef));
+ }
+ else if (aXMLElement.mValue == _S("StringArray"))
+ {
+ StringVector aDef;
+
+ if (!ParseStringArray(&aDef))
+ return false;
+
+ std::string anId = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+
+ mApp->mStringVectorProperties.insert(StringStringVectorMap::value_type(anId, aDef));
+ }
+ else if (aXMLElement.mValue == _S("Boolean"))
+ {
+ SexyString aVal;
+
+ if (!ParseSingleElement(&aVal))
+ return false;
+
+ aVal = Upper(aVal);
+
+ bool boolVal;
+ if ((aVal == _S("1")) || (aVal == _S("YES")) || (aVal == _S("ON")) || (aVal == _S("TRUE")))
+ boolVal = true;
+ else if ((aVal == _S("0")) || (aVal == _S("NO")) || (aVal == _S("OFF")) || (aVal == _S("FALSE")))
+ boolVal = false;
+ else
+ {
+ Fail(_S("Invalid Boolean Value: '") + aVal + _S("'"));
+ return false;
+ }
+
+ std::string anId = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+
+ mApp->SetBoolean(anId, boolVal);
+ }
+ else if (aXMLElement.mValue == _S("Integer"))
+ {
+ SexyString aVal;
+
+ if (!ParseSingleElement(&aVal))
+ return false;
+
+ int anInt;
+ if (!StringToInt(aVal, &anInt))
+ {
+ Fail(_S("Invalid Integer Value: '") + aVal + _S("'"));
+ return false;
+ }
+
+ std::string anId = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+
+ mApp->SetInteger(anId, anInt);
+ }
+ else if (aXMLElement.mValue == _S("Double"))
+ {
+ SexyString aVal;
+
+ if (!ParseSingleElement(&aVal))
+ return false;
+
+ double aDouble;
+ if (!StringToDouble(aVal, &aDouble))
+ {
+ Fail(_S("Invalid Double Value: '") + aVal + _S("'"));
+ return false;
+ }
+
+ std::string anId = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+
+ mApp->SetDouble(anId, aDouble);
+ }
+ else
+ {
+ Fail(_S("Invalid Section '") + aXMLElement.mValue + _S("'"));
+ return false;
+ }
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ Fail(_S("Element Not Expected '") + aXMLElement.mValue + _S("'"));
+ return false;
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_END)
+ {
+ return true;
+ }
+ }
+}
+
+bool PropertiesParser::DoParseProperties()
+{
+ if (!mXMLParser->HasFailed())
+ {
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ break;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue == _S("Properties"))
+ {
+ if (!ParseProperties())
+ break;
+ }
+ else
+ {
+ Fail(_S("Invalid Section '") + aXMLElement.mValue + _S("'"));
+ break;
+ }
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ Fail(_S("Element Not Expected '") + aXMLElement.mValue + _S("'"));
+ break;
+ }
+ }
+ }
+
+ if (mXMLParser->HasFailed())
+ Fail(mXMLParser->GetErrorText());
+
+ delete mXMLParser;
+ mXMLParser = NULL;
+
+ return !mHasFailed;
+}
+
+bool PropertiesParser::ParsePropertiesBuffer(const Buffer& theBuffer)
+{
+ mXMLParser = new XMLParser();
+
+ mXMLParser->SetStringSource(theBuffer.UTF8ToWideString());
+ return DoParseProperties();
+}
+
+bool PropertiesParser::ParsePropertiesFile(const std::string& theFilename)
+{
+ mXMLParser = new XMLParser();
+ mXMLParser->OpenFile(theFilename);
+ return DoParseProperties();
+}
+
+SexyString PropertiesParser::GetErrorText()
+{
+ return mError;
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/PropertiesParser.h b/osframework/source/SexyAppFramework/PropertiesParser.h
new file mode 100644
index 0000000..cc62c18
--- /dev/null
+++ b/osframework/source/SexyAppFramework/PropertiesParser.h
@@ -0,0 +1,41 @@
+#ifndef __SEXYAPPFRAMEWORK_NO_PROPERTIES_PARSER__
+#ifndef __PROPERTIESPARSER_H__
+#define __PROPERTIESPARSER_H__
+
+#include "SexyAppBase.h"
+
+namespace Sexy
+{
+
+class XMLParser;
+
+class PropertiesParser
+{
+public:
+ SexyAppBase* mApp;
+ XMLParser* mXMLParser;
+ SexyString mError;
+ bool mHasFailed;
+
+protected:
+ void Fail(const SexyString& theErrorText);
+
+ bool ParseSingleElement(SexyString* theString);
+ bool ParseStringArray(StringVector* theStringVector);
+ bool ParseProperties();
+ bool DoParseProperties();
+
+public:
+ PropertiesParser(SexyAppBase* theApp);
+ virtual ~PropertiesParser();
+
+ bool ParsePropertiesFile(const std::string& theFilename);
+ bool ParsePropertiesBuffer(const Buffer& theBuffer);
+ SexyString GetErrorText();
+};
+
+}
+
+#endif //__PROPERTIESPARSER_H__
+
+#endif // __SEXYAPPFRAMEWORK_NO_PROPERTIES_PARSER__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Quantize.cpp b/osframework/source/SexyAppFramework/Quantize.cpp
new file mode 100644
index 0000000..a68b93a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Quantize.cpp
@@ -0,0 +1,78 @@
+#include "Quantize.h"
+#include <assert.h>
+#include <math.h>
+
+using namespace Sexy;
+
+bool Sexy::Quantize8Bit(const ulong* theSrcBits, int theWidth, int theHeight, uchar* theDestColorIndices, ulong* theDestColorTable)
+{
+ int aSize = theWidth*theHeight;
+
+ int aColorTableSize = 0;
+
+ ulong aSearchTable[256];
+ uchar aTranslationTable[256]; // From search table to color table
+
+ if (aSize > 0)
+ {
+ aSearchTable[0] = theSrcBits[0];
+ theDestColorTable[0] = theSrcBits[0];
+ aTranslationTable[0] = 0;
+ theDestColorIndices[0] = 0;
+ aColorTableSize++;
+ }
+
+ for (int anIdx = 1; anIdx < aSize; anIdx++)
+ {
+ ulong aColor = theSrcBits[anIdx];
+
+ int aLeftPos = 0;
+ int aRightPos = aColorTableSize-1;
+ int aMiddlePos = (aLeftPos+aRightPos)/2;
+
+ for (;;)
+ {
+ ulong aCheckColor = aSearchTable[aMiddlePos];
+
+ if (aColor < aCheckColor)
+ aRightPos = aMiddlePos - 1;
+ else if (aColor > aCheckColor)
+ aLeftPos = aMiddlePos + 1;
+ else
+ {
+ theDestColorIndices[anIdx] = aTranslationTable[aMiddlePos];
+ break;
+ }
+
+ if (aLeftPos > aRightPos)
+ {
+ if (aColorTableSize >= 256)
+ return false;
+
+ int anInsertPos = aLeftPos;
+ if ((anInsertPos < aColorTableSize) && (aColor > aSearchTable[anInsertPos]))
+ anInsertPos++;
+
+ // Insert color into the table
+ memmove(aSearchTable+anInsertPos+1, aSearchTable+anInsertPos, (aColorTableSize-anInsertPos) * sizeof(ulong));
+ aSearchTable[anInsertPos] = aColor;
+
+ memmove(aTranslationTable+anInsertPos+1, aTranslationTable+anInsertPos, (aColorTableSize-anInsertPos) * sizeof(uchar));
+ aTranslationTable[anInsertPos] = aColorTableSize;
+
+ theDestColorTable[aColorTableSize] = aColor;
+
+ theDestColorIndices[anIdx] = aColorTableSize;
+
+ aColorTableSize++;
+
+ break;
+ }
+
+ aMiddlePos = (aLeftPos+aRightPos)/2;
+ }
+ }
+
+ return true;
+}
+
diff --git a/osframework/source/SexyAppFramework/Quantize.h b/osframework/source/SexyAppFramework/Quantize.h
new file mode 100644
index 0000000..8788733
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Quantize.h
@@ -0,0 +1,13 @@
+#ifndef __QUANTIZE_H__
+#define __QUANTIZE_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+bool Quantize8Bit(const ulong* theSrcBits, int theWidth, int theHeight, uchar* theDestColorIndices, ulong* theDestColorTable);
+
+}
+
+#endif //__QUANTIZE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Ratio.cpp b/osframework/source/SexyAppFramework/Ratio.cpp
new file mode 100644
index 0000000..059085d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Ratio.cpp
@@ -0,0 +1,36 @@
+
+#include "Ratio.h"
+
+namespace Sexy
+{
+
+ Ratio::Ratio()
+ : mNumerator(1)
+ , mDenominator(1)
+ {
+ }
+
+ Ratio::Ratio(int theNumerator, int theDenominator)
+ {
+ Set(theNumerator, theDenominator);
+ }
+
+ void Ratio::Set(int theNumerator, int theDenominator)
+ {
+ // find the greatest-common-denominator of theNumerator and theDenominator.
+ int t;
+ int a = theNumerator;
+ int b = theDenominator;
+ while (b != 0)
+ {
+ t = b;
+ b = a % b;
+ a = t;
+ }
+
+ // divide by the g-c-d to reduce mNumerator/mDenominator to lowest terms.
+ mNumerator = theNumerator/a;
+ mDenominator = theDenominator/a;
+ }
+
+}
diff --git a/osframework/source/SexyAppFramework/Ratio.h b/osframework/source/SexyAppFramework/Ratio.h
new file mode 100644
index 0000000..c5b77dc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Ratio.h
@@ -0,0 +1,58 @@
+#ifndef __RATIO_H__
+#define __RATIO_H__
+
+namespace Sexy
+{
+ struct Ratio
+ {
+ Ratio();
+ Ratio(int theNumerator, int theDenominator);
+ void Set(int theNumerator, int theDenominator);
+ bool operator==(const Ratio& theRatio) const;
+ bool operator!=(const Ratio& theRatio) const;
+ bool operator<(const Ratio& theRatio) const;
+ int operator*(int theInt) const;
+ int operator/(int theInt) const;
+ int mNumerator;
+ int mDenominator;
+ };
+
+ inline bool Ratio::operator==(const Ratio& theRatio) const
+ {
+ return mNumerator == theRatio.mNumerator && mDenominator == theRatio.mDenominator;
+ }
+
+ inline bool Ratio::operator!=(const Ratio& theRatio) const
+ {
+ return ! (*this == theRatio);
+ }
+
+ inline bool Ratio::operator<(const Ratio& theRatio) const
+ {
+ return (mNumerator*theRatio.mDenominator/mDenominator < theRatio.mNumerator)
+ || (mNumerator < theRatio.mNumerator*mDenominator/theRatio.mDenominator);
+ }
+
+ inline int Ratio::operator*(int theInt) const
+ {
+ return theInt * mNumerator / mDenominator;
+ }
+
+ inline int Ratio::operator/(int theInt) const
+ {
+ return theInt * mDenominator / mNumerator;
+ }
+
+ inline int operator*(int theInt, const Ratio& theRatio)
+ {
+ return theInt * theRatio.mNumerator / theRatio.mDenominator;
+ }
+
+ inline int operator/(int theInt, const Ratio& theRatio)
+ {
+ return theInt * theRatio.mDenominator / theRatio.mNumerator;
+ }
+
+}
+
+#endif
diff --git a/osframework/source/SexyAppFramework/Rect.h b/osframework/source/SexyAppFramework/Rect.h
new file mode 100644
index 0000000..e397aa6
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Rect.h
@@ -0,0 +1,118 @@
+#ifndef __TRectANGLE_H__
+#define __TRectANGLE_H__
+
+#include "Common.h"
+#include "Point.h"
+
+#include <list>
+
+namespace Sexy
+{
+
+template<class _T> class TRect
+{
+public:
+ _T mX;
+ _T mY;
+ _T mWidth;
+ _T mHeight;
+
+public:
+ TRect(_T theX, _T theY, _T theWidth, _T theHeight) :
+ mX(theX), mY(theY), mWidth(theWidth), mHeight(theHeight)
+ {
+ }
+
+ TRect(const TRect<_T>& theTRect) :
+ mX(theTRect.mX), mY(theTRect.mY), mWidth(theTRect.mWidth), mHeight(theTRect.mHeight)
+ {
+ }
+
+ TRect() :
+ mX(0), mY(0), mWidth(0), mHeight(0)
+ {
+ }
+
+ bool Intersects(const TRect<_T>& theTRect) const
+ {
+ return !((theTRect.mX + theTRect.mWidth <= mX) ||
+ (theTRect.mY + theTRect.mHeight <= mY) ||
+ (theTRect.mX >= mX + mWidth) ||
+ (theTRect.mY >= mY + mHeight));
+ }
+
+ TRect<_T> Intersection(const TRect<_T>& theTRect) const
+ {
+ _T x1 = max(mX, theTRect.mX);
+ _T x2 = min(mX + mWidth, theTRect.mX + theTRect.mWidth);
+ _T y1 = max(mY, theTRect.mY);
+ _T y2 = min(mY + mHeight, theTRect.mY + theTRect.mHeight);
+ if (((x2 - x1) < 0) || ((y2 - y1) < 0))
+ return TRect<_T>(0,0,0,0);
+ else
+ return TRect<_T>(x1, y1, x2 - x1, y2 - y1);
+ }
+
+ TRect<_T> Union(const TRect<_T>& theTRect)
+ {
+ _T x1 = min(mX, theTRect.mX);
+ _T x2 = max(mX + mWidth, theTRect.mX + theTRect.mWidth);
+ _T y1 = min(mY, theTRect.mY);
+ _T y2 = max(mY + mHeight, theTRect.mY + theTRect.mHeight);
+ return TRect<_T>(x1, y1, x2 - x1, y2 - y1);
+ }
+
+ bool Contains(_T theX, _T theY) const
+ {
+ return ((theX >= mX) && (theX < mX + mWidth) &&
+ (theY >= mY) && (theY < mY + mHeight));
+ }
+
+ bool Contains(const TPoint<_T>& thePoint) const
+ {
+ return ((thePoint.mX >= mX) && (thePoint.mX < mX + mWidth) &&
+ (thePoint.mY >= mY) && (thePoint.mY < mY + mHeight));
+ }
+
+ void Offset(_T theX, _T theY)
+ {
+ mX += theX;
+ mY += theY;
+ }
+
+ void Offset(const TPoint<_T>& thePoint)
+ {
+ mX += thePoint.mX;
+ mY += thePoint.mY;
+ }
+
+ TRect Inflate(_T theX, _T theY)
+ {
+ mX -= theX;
+ mWidth += theX*2;
+ mY -= theY;
+ mHeight += theY*2;
+
+ return *this;
+ }
+
+ bool operator==(const TRect<_T>& theRect) const
+ {
+ return (mX == theRect.mX) && (mY == theRect.mY) && (mWidth == theRect.mWidth) && (mHeight == theRect.mHeight);
+ }
+
+ RECT ToRECT() const
+ {
+ RECT aRect = {mX, mY, mX + mWidth, mY + mHeight};
+ return aRect;
+ }
+};
+
+typedef TRect<int> Rect;
+typedef TRect<double> FRect;
+
+
+
+}
+
+#endif //__TRectANGLE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Release - Final/BuildLog.htm b/osframework/source/SexyAppFramework/Release - Final/BuildLog.htm
new file mode 100644
index 0000000..4b35681
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Release - Final/BuildLog.htm
Binary files differ
diff --git a/osframework/source/SexyAppFramework/ResourceManager.cpp b/osframework/source/SexyAppFramework/ResourceManager.cpp
new file mode 100644
index 0000000..5f87d9a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ResourceManager.cpp
@@ -0,0 +1,1274 @@
+
+#include "ResourceManager.h"
+#include "XMLParser.h"
+#include "SoundManager.h"
+#include "DDImage.h"
+#include "D3DInterface.h"
+#include "ImageFont.h"
+#include "SysFont.h"
+#include "../ImageLib/ImageLib.h"
+
+//#define SEXY_PERF_ENABLED
+#include "PerfTimer.h"
+
+using namespace Sexy;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::ImageRes::DeleteResource()
+{
+ mImage.Release();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::SoundRes::DeleteResource()
+{
+ if (mSoundId >= 0)
+ gSexyAppBase->mSoundManager->ReleaseSound(mSoundId);
+
+ mSoundId = -1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::FontRes::DeleteResource()
+{
+ delete mFont;
+ mFont = NULL;
+
+ delete mImage;
+ mImage = NULL;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+ResourceManager::ResourceManager(SexyAppBase *theApp)
+{
+ mApp = theApp;
+ mHasFailed = false;
+ mXMLParser = NULL;
+
+ mAllowMissingProgramResources = false;
+ mAllowAlreadyDefinedResources = false;
+ mCurResGroupList = NULL;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+ResourceManager::~ResourceManager()
+{
+ DeleteMap(mImageMap);
+ DeleteMap(mSoundMap);
+ DeleteMap(mFontMap);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::IsGroupLoaded(const std::string &theGroup)
+{
+ return mLoadedGroups.find(theGroup)!=mLoadedGroups.end();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteMap(ResMap &theMap)
+{
+ for (ResMap::iterator anItr = theMap.begin(); anItr != theMap.end(); ++anItr)
+ {
+ anItr->second->DeleteResource();
+ delete anItr->second;
+ }
+
+ theMap.clear();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteResources(ResMap &theMap, const std::string &theGroup)
+{
+ for (ResMap::iterator anItr = theMap.begin(); anItr != theMap.end(); ++anItr)
+ {
+ if (theGroup.empty() || anItr->second->mResGroup==theGroup)
+ anItr->second->DeleteResource();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteResources(const std::string &theGroup)
+{
+ DeleteResources(mImageMap,theGroup);
+ DeleteResources(mSoundMap,theGroup);
+ DeleteResources(mFontMap,theGroup);
+ mLoadedGroups.erase(theGroup);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteExtraImageBuffers(const std::string &theGroup)
+{
+ for (ResMap::iterator anItr = mImageMap.begin(); anItr != mImageMap.end(); ++anItr)
+ {
+ if (theGroup.empty() || anItr->second->mResGroup==theGroup)
+ {
+ ImageRes *aRes = (ImageRes*)anItr->second;
+ MemoryImage *anImage = (MemoryImage*)aRes->mImage;
+ if (anImage != NULL)
+ anImage->DeleteExtraBuffers();
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+std::string ResourceManager::GetErrorText()
+{
+ return mError;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::HadError()
+{
+ return mHasFailed;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::Fail(const std::string& theErrorText)
+{
+ if (!mHasFailed)
+ {
+ mHasFailed = true;
+ if (mXMLParser==NULL)
+ {
+ mError = theErrorText;
+ return false;
+ }
+
+ int aLineNum = mXMLParser->GetCurrentLineNum();
+
+ char aLineNumStr[16];
+ sprintf(aLineNumStr, "%d", aLineNum);
+
+ mError = theErrorText;
+
+ if (aLineNum > 0)
+ mError += std::string(" on Line ") + aLineNumStr;
+
+ if (mXMLParser->GetFileName().length() > 0)
+ mError += " in File '" + mXMLParser->GetFileName() + "'";
+ }
+
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseCommonResource(XMLElement &theElement, BaseRes *theRes, ResMap &theMap)
+{
+ mHadAlreadyDefinedError = false;
+
+ const SexyString &aPath = theElement.mAttributes[_S("path")];
+ if (aPath.empty())
+ return Fail("No path specified.");
+
+ theRes->mXMLAttributes = theElement.mAttributes;
+ theRes->mFromProgram = false;
+ if (aPath[0]==_S('!'))
+ {
+ theRes->mPath = SexyStringToStringFast(aPath);
+ if (aPath==_S("!program"))
+ theRes->mFromProgram = true;
+ }
+ else
+ theRes->mPath = mDefaultPath + SexyStringToStringFast(aPath);
+
+
+ std::string anId;
+ XMLParamMap::iterator anItr = theElement.mAttributes.find(_S("id"));
+ if (anItr == theElement.mAttributes.end())
+ anId = mDefaultIdPrefix + GetFileName(theRes->mPath,true);
+ else
+ anId = mDefaultIdPrefix + SexyStringToStringFast(anItr->second);
+
+ theRes->mResGroup = mCurResGroup;
+ theRes->mId = anId;
+
+ std::pair<ResMap::iterator,bool> aRet = theMap.insert(ResMap::value_type(anId,theRes));
+ if (!aRet.second)
+ {
+ mHadAlreadyDefinedError = true;
+ return Fail("Resource already defined.");
+ }
+
+ mCurResGroupList->push_back(theRes);
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseSoundResource(XMLElement &theElement)
+{
+ SoundRes *aRes = new SoundRes;
+ aRes->mSoundId = -1;
+ aRes->mVolume = -1;
+ aRes->mPanning = 0;
+
+ if (!ParseCommonResource(theElement, aRes, mSoundMap))
+ {
+ if (mHadAlreadyDefinedError && mAllowAlreadyDefinedResources)
+ {
+ mError = "";
+ mHasFailed = false;
+ SoundRes *oldRes = aRes;
+ aRes = (SoundRes*)mSoundMap[oldRes->mId];
+ aRes->mPath = oldRes->mPath;
+ aRes->mXMLAttributes = oldRes->mXMLAttributes;
+ delete oldRes;
+ }
+ else
+ {
+ delete aRes;
+ return false;
+ }
+ }
+
+ XMLParamMap::iterator anItr;
+
+ anItr = theElement.mAttributes.find(_S("volume"));
+ if (anItr != theElement.mAttributes.end())
+ sexysscanf(anItr->second.c_str(),_S("%lf"),&aRes->mVolume);
+
+ anItr = theElement.mAttributes.find(_S("pan"));
+ if (anItr != theElement.mAttributes.end())
+ sexysscanf(anItr->second.c_str(),_S("%d"),&aRes->mPanning);
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+static void ReadIntVector(const SexyString &theVal, std::vector<int> &theVector)
+{
+ theVector.clear();
+
+ std::string::size_type aPos = 0;
+ while (true)
+ {
+ theVector.push_back(sexyatoi(theVal.c_str()+aPos));
+ aPos = theVal.find_first_of(_S(','),aPos);
+ if (aPos==std::string::npos)
+ break;
+
+ aPos++;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseImageResource(XMLElement &theElement)
+{
+ ImageRes *aRes = new ImageRes;
+ if (!ParseCommonResource(theElement, aRes, mImageMap))
+ {
+ if (mHadAlreadyDefinedError && mAllowAlreadyDefinedResources)
+ {
+ mError = "";
+ mHasFailed = false;
+ ImageRes *oldRes = aRes;
+ aRes = (ImageRes*)mImageMap[oldRes->mId];
+ aRes->mPath = oldRes->mPath;
+ aRes->mXMLAttributes = oldRes->mXMLAttributes;
+ delete oldRes;
+ }
+ else
+ {
+ delete aRes;
+ return false;
+ }
+ }
+
+ aRes->mPalletize = theElement.mAttributes.find(_S("nopal")) == theElement.mAttributes.end();
+ aRes->mA4R4G4B4 = theElement.mAttributes.find(_S("a4r4g4b4")) != theElement.mAttributes.end();
+ aRes->mDDSurface = theElement.mAttributes.find(_S("ddsurface")) != theElement.mAttributes.end();
+ aRes->mPurgeBits = (theElement.mAttributes.find(_S("nobits")) != theElement.mAttributes.end()) ||
+ ((mApp->Is3DAccelerated()) && (theElement.mAttributes.find(_S("nobits3d")) != theElement.mAttributes.end())) ||
+ ((!mApp->Is3DAccelerated()) && (theElement.mAttributes.find(_S("nobits2d")) != theElement.mAttributes.end()));
+ aRes->mA8R8G8B8 = theElement.mAttributes.find(_S("a8r8g8b8")) != theElement.mAttributes.end();
+ aRes->mMinimizeSubdivisions = theElement.mAttributes.find(_S("minsubdivide")) != theElement.mAttributes.end();
+ aRes->mAutoFindAlpha = theElement.mAttributes.find(_S("noalpha")) == theElement.mAttributes.end();
+
+ XMLParamMap::iterator anItr;
+ anItr = theElement.mAttributes.find(_S("alphaimage"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mAlphaImage = mDefaultPath + SexyStringToStringFast(anItr->second);
+
+ aRes->mAlphaColor = 0xFFFFFF;
+ anItr = theElement.mAttributes.find(_S("alphacolor"));
+ if (anItr != theElement.mAttributes.end())
+ sexysscanf(anItr->second.c_str(),_S("%x"),&aRes->mAlphaColor);
+
+ anItr = theElement.mAttributes.find(_S("variant"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mVariant = SexyStringToStringFast(anItr->second);
+
+ anItr = theElement.mAttributes.find(_S("alphagrid"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mAlphaGridImage = mDefaultPath + SexyStringToStringFast(anItr->second);
+
+ anItr = theElement.mAttributes.find(_S("rows"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mRows = sexyatoi(anItr->second.c_str());
+ else
+ aRes->mRows = 1;
+
+ anItr = theElement.mAttributes.find(_S("cols"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mCols = sexyatoi(anItr->second.c_str());
+ else
+ aRes->mCols = 1;
+
+ anItr = theElement.mAttributes.find(_S("anim"));
+ AnimType anAnimType = AnimType_None;
+ if (anItr != theElement.mAttributes.end())
+ {
+ const SexyChar *aType = anItr->second.c_str();
+
+ if (sexystricmp(aType,_S("none"))==0) anAnimType = AnimType_None;
+ else if (sexystricmp(aType,_S("once"))==0) anAnimType = AnimType_Once;
+ else if (sexystricmp(aType,_S("loop"))==0) anAnimType = AnimType_Loop;
+ else if (sexystricmp(aType,_S("pingpong"))==0) anAnimType = AnimType_PingPong;
+ else
+ {
+ Fail("Invalid animation type.");
+ return false;
+ }
+ }
+ aRes->mAnimInfo.mAnimType = anAnimType;
+ if (anAnimType != AnimType_None)
+ {
+ int aNumCels = max(aRes->mRows,aRes->mCols);
+ int aBeginDelay = 0, anEndDelay = 0;
+
+ anItr = theElement.mAttributes.find(_S("framedelay"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mAnimInfo.mFrameDelay = sexyatoi(anItr->second.c_str());
+
+ anItr = theElement.mAttributes.find(_S("begindelay"));
+ if (anItr != theElement.mAttributes.end())
+ aBeginDelay = sexyatoi(anItr->second.c_str());
+
+ anItr = theElement.mAttributes.find(_S("enddelay"));
+ if (anItr != theElement.mAttributes.end())
+ anEndDelay = sexyatoi(anItr->second.c_str());
+
+ anItr = theElement.mAttributes.find(_S("perframedelay"));
+ if (anItr != theElement.mAttributes.end())
+ ReadIntVector(anItr->second,aRes->mAnimInfo.mPerFrameDelay);
+
+ anItr = theElement.mAttributes.find(_S("framemap"));
+ if (anItr != theElement.mAttributes.end())
+ ReadIntVector(anItr->second,aRes->mAnimInfo.mFrameMap);
+
+ aRes->mAnimInfo.Compute(aNumCels,aBeginDelay,anEndDelay);
+ }
+
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseFontResource(XMLElement &theElement)
+{
+ FontRes *aRes = new FontRes;
+ aRes->mFont = NULL;
+ aRes->mImage = NULL;
+
+ if (!ParseCommonResource(theElement, aRes, mFontMap))
+ {
+ if (mHadAlreadyDefinedError && mAllowAlreadyDefinedResources)
+ {
+ mError = "";
+ mHasFailed = false;
+ FontRes *oldRes = aRes;
+ aRes = (FontRes*)mFontMap[oldRes->mId];
+ aRes->mPath = oldRes->mPath;
+ aRes->mXMLAttributes = oldRes->mXMLAttributes;
+ delete oldRes;
+ }
+ else
+ {
+ delete aRes;
+ return false;
+ }
+ }
+
+
+ XMLParamMap::iterator anItr;
+ anItr = theElement.mAttributes.find(_S("image"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mImagePath = SexyStringToStringFast(anItr->second);
+
+ anItr = theElement.mAttributes.find(_S("tags"));
+ if (anItr != theElement.mAttributes.end())
+ aRes->mTags = SexyStringToStringFast(anItr->second);
+
+ if (strncmp(aRes->mPath.c_str(),"!sys:",5)==0)
+ {
+ aRes->mSysFont = true;
+ aRes->mPath = aRes->mPath.substr(5);
+
+ anItr = theElement.mAttributes.find(_S("size"));
+ if (anItr==theElement.mAttributes.end())
+ return Fail("SysFont needs point size");
+
+ aRes->mSize = sexyatoi(anItr->second.c_str());
+ if (aRes->mSize<=0)
+ return Fail("SysFont needs point size");
+
+ aRes->mBold = theElement.mAttributes.find(_S("bold"))!=theElement.mAttributes.end();
+ aRes->mItalic = theElement.mAttributes.find(_S("italic"))!=theElement.mAttributes.end();
+ aRes->mShadow = theElement.mAttributes.find(_S("shadow"))!=theElement.mAttributes.end();
+ aRes->mUnderline = theElement.mAttributes.find(_S("underline"))!=theElement.mAttributes.end();
+ }
+ else
+ aRes->mSysFont = false;
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseSetDefaults(XMLElement &theElement)
+{
+ XMLParamMap::iterator anItr;
+ anItr = theElement.mAttributes.find(_S("path"));
+ if (anItr != theElement.mAttributes.end())
+ mDefaultPath = RemoveTrailingSlash(SexyStringToStringFast(anItr->second)) + '/';
+
+ anItr = theElement.mAttributes.find(_S("idprefix"));
+ if (anItr != theElement.mAttributes.end())
+ mDefaultIdPrefix = RemoveTrailingSlash(SexyStringToStringFast(anItr->second));
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseResources()
+{
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue == _S("Image"))
+ {
+ if (!ParseImageResource(aXMLElement))
+ return false;
+
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType != XMLElement::TYPE_END)
+ return Fail("Unexpected element found.");
+ }
+ else if (aXMLElement.mValue == _S("Sound"))
+ {
+ if (!ParseSoundResource(aXMLElement))
+ return false;
+
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType != XMLElement::TYPE_END)
+ return Fail("Unexpected element found.");
+ }
+ else if (aXMLElement.mValue == _S("Font"))
+ {
+ if (!ParseFontResource(aXMLElement))
+ return false;
+
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType != XMLElement::TYPE_END)
+ return Fail("Unexpected element found.");
+ }
+ else if (aXMLElement.mValue == _S("SetDefaults"))
+ {
+ if (!ParseSetDefaults(aXMLElement))
+ return false;
+
+ if (!mXMLParser->NextElement(&aXMLElement))
+ return false;
+
+ if (aXMLElement.mType != XMLElement::TYPE_END)
+ return Fail("Unexpected element found.");
+ }
+ else
+ {
+ Fail("Invalid Section '" + SexyStringToStringFast(aXMLElement.mValue) + "'");
+ return false;
+ }
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ Fail("Element Not Expected '" + SexyStringToStringFast(aXMLElement.mValue) + "'");
+ return false;
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_END)
+ {
+ return true;
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::DoParseResources()
+{
+ if (!mXMLParser->HasFailed())
+ {
+ for (;;)
+ {
+ XMLElement aXMLElement;
+ if (!mXMLParser->NextElement(&aXMLElement))
+ break;
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue == _S("Resources"))
+ {
+ mCurResGroup = SexyStringToStringFast(aXMLElement.mAttributes[_S("id")]);
+ mCurResGroupList = &mResGroupMap[mCurResGroup];
+
+ if (mCurResGroup.empty())
+ {
+ Fail("No id specified.");
+ break;
+ }
+
+ if (!ParseResources())
+ break;
+ }
+ else
+ {
+ Fail("Invalid Section '" + SexyStringToStringFast(aXMLElement.mValue) + "'");
+ break;
+ }
+ }
+ else if (aXMLElement.mType == XMLElement::TYPE_ELEMENT)
+ {
+ Fail("Element Not Expected '" + SexyStringToStringFast(aXMLElement.mValue) + "'");
+ break;
+ }
+ }
+ }
+
+ if (mXMLParser->HasFailed())
+ Fail(SexyStringToStringFast(mXMLParser->GetErrorText()));
+
+ delete mXMLParser;
+ mXMLParser = NULL;
+
+ return !mHasFailed;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ParseResourcesFile(const std::string& theFilename)
+{
+ mXMLParser = new XMLParser();
+ if (!mXMLParser->OpenFile(theFilename))
+ Fail("Resource file not found: " + theFilename);
+
+ XMLElement aXMLElement;
+ while (!mXMLParser->HasFailed())
+ {
+ if (!mXMLParser->NextElement(&aXMLElement))
+ Fail(SexyStringToStringFast(mXMLParser->GetErrorText()));
+
+ if (aXMLElement.mType == XMLElement::TYPE_START)
+ {
+ if (aXMLElement.mValue != _S("ResourceManifest"))
+ break;
+ else
+ return DoParseResources();
+ }
+ }
+
+ Fail("Expecting ResourceManifest tag");
+
+ return DoParseResources();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ReparseResourcesFile(const std::string& theFilename)
+{
+ bool oldDefined = mAllowAlreadyDefinedResources;
+ mAllowAlreadyDefinedResources = true;
+
+ bool aResult = ParseResourcesFile(theFilename);
+
+ mAllowAlreadyDefinedResources = oldDefined;
+
+ return aResult;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::LoadAlphaGridImage(ImageRes *theRes, DDImage *theImage)
+{
+ ImageLib::Image* anAlphaImage = ImageLib::GetImage(theRes->mAlphaGridImage,true);
+ if (anAlphaImage==NULL)
+ return Fail(StrFormat("Failed to load image: %s",theRes->mAlphaGridImage.c_str()));
+
+ std::auto_ptr<ImageLib::Image> aDelAlphaImage(anAlphaImage);
+
+ int aNumRows = theRes->mRows;
+ int aNumCols = theRes->mCols;
+
+ int aCelWidth = theImage->mWidth/aNumCols;
+ int aCelHeight = theImage->mHeight/aNumRows;
+
+
+ if (anAlphaImage->mWidth!=aCelWidth || anAlphaImage->mHeight!=aCelHeight)
+ return Fail(StrFormat("GridAlphaImage size mismatch between %s and %s",theRes->mPath.c_str(),theRes->mAlphaGridImage.c_str()));
+
+ unsigned long *aMasterRowPtr = theImage->mBits;
+ for (int i=0; i < aNumRows; i++)
+ {
+ unsigned long *aMasterColPtr = aMasterRowPtr;
+ for (int j=0; j < aNumCols; j++)
+ {
+ unsigned long* aRowPtr = aMasterColPtr;
+ unsigned long* anAlphaBits = anAlphaImage->mBits;
+ for (int y=0; y<aCelHeight; y++)
+ {
+ unsigned long *aDestPtr = aRowPtr;
+ for (int x=0; x<aCelWidth; x++)
+ {
+ *aDestPtr = (*aDestPtr & 0x00FFFFFF) | ((*anAlphaBits & 0xFF) << 24);
+ ++anAlphaBits;
+ ++aDestPtr;
+ }
+ aRowPtr += theImage->mWidth;
+ }
+
+ aMasterColPtr += aCelWidth;
+ }
+ aMasterRowPtr += aCelHeight*theImage->mWidth;
+ }
+
+ theImage->BitsChanged();
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::LoadAlphaImage(ImageRes *theRes, DDImage *theImage)
+{
+ SEXY_PERF_BEGIN("ResourceManager::GetImage");
+ ImageLib::Image* anAlphaImage = ImageLib::GetImage(theRes->mAlphaImage,true);
+ SEXY_PERF_END("ResourceManager::GetImage");
+
+ if (anAlphaImage==NULL)
+ return Fail(StrFormat("Failed to load image: %s",theRes->mAlphaImage.c_str()));
+
+ std::auto_ptr<ImageLib::Image> aDelAlphaImage(anAlphaImage);
+
+ if (anAlphaImage->mWidth!=theImage->mWidth || anAlphaImage->mHeight!=theImage->mHeight)
+ return Fail(StrFormat("AlphaImage size mismatch between %s and %s",theRes->mPath.c_str(),theRes->mAlphaImage.c_str()));
+
+ unsigned long* aBits1 = theImage->mBits;
+ unsigned long* aBits2 = anAlphaImage->mBits;
+ int aSize = theImage->mWidth*theImage->mHeight;
+
+ for (int i = 0; i < aSize; i++)
+ {
+ *aBits1 = (*aBits1 & 0x00FFFFFF) | ((*aBits2 & 0xFF) << 24);
+ ++aBits1;
+ ++aBits2;
+ }
+
+ theImage->BitsChanged();
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::DoLoadImage(ImageRes *theRes)
+{
+ bool lookForAlpha = theRes->mAlphaImage.empty() && theRes->mAlphaGridImage.empty() && theRes->mAutoFindAlpha;
+
+ SEXY_PERF_BEGIN("ResourceManager:GetImage");
+
+ //ImageLib::Image *anImage = ImageLib::GetImage(theRes->mPath, lookForAlpha);
+ //SEXY_PERF_END("ResourceManager:GetImage");
+
+ bool isNew;
+ ImageLib::gAlphaComposeColor = theRes->mAlphaColor;
+ SharedImageRef aSharedImageRef = gSexyAppBase->GetSharedImage(theRes->mPath, theRes->mVariant, &isNew);
+ ImageLib::gAlphaComposeColor = 0xFFFFFF;
+
+ DDImage* aDDImage = (DDImage*) aSharedImageRef;
+
+ if (aDDImage == NULL)
+ return Fail(StrFormat("Failed to load image: %s",theRes->mPath.c_str()));
+
+ if (isNew)
+ {
+ if (!theRes->mAlphaImage.empty())
+ {
+ if (!LoadAlphaImage(theRes, aSharedImageRef))
+ return false;
+ }
+
+ if (!theRes->mAlphaGridImage.empty())
+ {
+ if (!LoadAlphaGridImage(theRes, aSharedImageRef))
+ return false;
+ }
+ }
+
+ aDDImage->CommitBits();
+ theRes->mImage = aSharedImageRef;
+ aDDImage->mPurgeBits = theRes->mPurgeBits;
+
+ if (theRes->mDDSurface)
+ {
+ SEXY_PERF_BEGIN("ResourceManager:DDSurface");
+
+ aDDImage->CommitBits();
+
+ if (!aDDImage->mHasAlpha)
+ {
+ aDDImage->mWantDDSurface = true;
+ aDDImage->mPurgeBits = true;
+ }
+
+ SEXY_PERF_END("ResourceManager:DDSurface");
+ }
+
+ if (theRes->mPalletize)
+ {
+ SEXY_PERF_BEGIN("ResourceManager:Palletize");
+ if (aDDImage->mSurface==NULL)
+ aDDImage->Palletize();
+ else
+ aDDImage->mWantPal = true;
+ SEXY_PERF_END("ResourceManager:Palletize");
+ }
+
+ if (theRes->mA4R4G4B4)
+ aDDImage->mD3DFlags |= D3DImageFlag_UseA4R4G4B4;
+
+ if (theRes->mA8R8G8B8)
+ aDDImage->mD3DFlags |= D3DImageFlag_UseA8R8G8B8;
+
+ if (theRes->mMinimizeSubdivisions)
+ aDDImage->mD3DFlags |= D3DImageFlag_MinimizeNumSubdivisions;
+
+ if (theRes->mAnimInfo.mAnimType != AnimType_None)
+ aDDImage->mAnimInfo = new AnimInfo(theRes->mAnimInfo);
+
+ aDDImage->mNumRows = theRes->mRows;
+ aDDImage->mNumCols = theRes->mCols;
+
+ if (aDDImage->mPurgeBits)
+ aDDImage->PurgeBits();
+
+ ResourceLoadedHook(theRes);
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteImage(const std::string &theName)
+{
+ ReplaceImage(theName,NULL);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SharedImageRef ResourceManager::LoadImage(const std::string &theName)
+{
+ ResMap::iterator anItr = mImageMap.find(theName);
+ if (anItr == mImageMap.end())
+ return NULL;
+
+ ImageRes *aRes = (ImageRes*)anItr->second;
+ if ((DDImage*) aRes->mImage != NULL)
+ return aRes->mImage;
+
+ if (aRes->mFromProgram)
+ return NULL;
+
+ if (!DoLoadImage(aRes))
+ return NULL;
+
+ return aRes->mImage;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::DoLoadSound(SoundRes* theRes)
+{
+ SoundRes *aRes = theRes;
+
+ SEXY_PERF_BEGIN("ResourceManager:LoadSound");
+ int aSoundId = mApp->mSoundManager->GetFreeSoundId();
+ if (aSoundId<0)
+ return Fail("Out of free sound ids");
+
+ if(!mApp->mSoundManager->LoadSound(aSoundId, aRes->mPath))
+ return Fail(StrFormat("Failed to load sound: %s",aRes->mPath.c_str()));
+ SEXY_PERF_END("ResourceManager:LoadSound");
+
+ if (aRes->mVolume >= 0)
+ mApp->mSoundManager->SetBaseVolume(aSoundId, aRes->mVolume);
+
+ if (aRes->mPanning != 0)
+ mApp->mSoundManager->SetBasePan(aSoundId, aRes->mPanning);
+
+ aRes->mSoundId = aSoundId;
+
+ ResourceLoadedHook(theRes);
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::DoLoadFont(FontRes* theRes)
+{
+ Font *aFont = NULL;
+
+ SEXY_PERF_BEGIN("ResourceManager:DoLoadFont");
+
+ if (theRes->mSysFont)
+ {
+ bool bold = theRes->mBold, simulateBold = false;
+ if (Sexy::CheckFor98Mill())
+ {
+ simulateBold = bold;
+ bold = false;
+ }
+ aFont = new SysFont(theRes->mPath,theRes->mSize,bold,theRes->mItalic,theRes->mUnderline);
+ SysFont* aSysFont = (SysFont*)aFont;
+ aSysFont->mDrawShadow = theRes->mShadow;
+ aSysFont->mSimulateBold = simulateBold;
+ }
+ else if (theRes->mImagePath.empty())
+ {
+ if (strncmp(theRes->mPath.c_str(),"!ref:",5)==0)
+ {
+ std::string aRefName = theRes->mPath.substr(5);
+ Font *aRefFont = GetFont(aRefName);
+ if (aRefFont==NULL)
+ return Fail("Ref font not found: " + aRefName);
+
+ aFont = aRefFont->Duplicate();
+ }
+ else
+ aFont = new ImageFont(mApp, theRes->mPath);
+ }
+ else
+ {
+ Image *anImage = mApp->GetImage(theRes->mImagePath);
+ if (anImage==NULL)
+ return Fail(StrFormat("Failed to load image: %s",theRes->mImagePath.c_str()));
+
+ theRes->mImage = anImage;
+ aFont = new ImageFont(anImage, theRes->mPath);
+ }
+
+ ImageFont *anImageFont = dynamic_cast<ImageFont*>(aFont);
+ if (anImageFont!=NULL)
+ {
+ if (anImageFont->mFontData==NULL || !anImageFont->mFontData->mInitialized)
+ {
+ delete aFont;
+ return Fail(StrFormat("Failed to load font: %s",theRes->mPath.c_str()));
+ }
+
+ if (!theRes->mTags.empty())
+ {
+ char aBuf[1024];
+ strcpy(aBuf,theRes->mTags.c_str());
+ const char *aPtr = strtok(aBuf,", \r\n\t");
+ while (aPtr != NULL)
+ {
+ anImageFont->AddTag(aPtr);
+ aPtr = strtok(NULL,", \r\n\t");
+ }
+ anImageFont->Prepare();
+ }
+ }
+
+ theRes->mFont = aFont;
+
+ SEXY_PERF_END("ResourceManager:DoLoadFont");
+
+ ResourceLoadedHook(theRes);
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+Font* ResourceManager::LoadFont(const std::string &theName)
+{
+ ResMap::iterator anItr = mFontMap.find(theName);
+ if (anItr == mFontMap.end())
+ return NULL;
+
+ FontRes *aRes = (FontRes*)anItr->second;
+ if (aRes->mFont != NULL)
+ return aRes->mFont;
+
+ if (aRes->mFromProgram)
+ return NULL;
+
+ if (!DoLoadFont(aRes))
+ return NULL;
+
+ return aRes->mFont;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::DeleteFont(const std::string &theName)
+{
+ ReplaceFont(theName,NULL);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::LoadNextResource()
+{
+ if (HadError())
+ return false;
+
+ if (mCurResGroupList==NULL)
+ return false;
+
+ while (mCurResGroupListItr!=mCurResGroupList->end())
+ {
+ BaseRes *aRes = *mCurResGroupListItr++;
+ if (aRes->mFromProgram)
+ continue;
+
+ switch (aRes->mType)
+ {
+ case ResType_Image:
+ {
+ ImageRes *anImageRes = (ImageRes*)aRes;
+ if ((DDImage*)anImageRes->mImage!=NULL)
+ continue;
+
+ return DoLoadImage(anImageRes);
+ }
+
+ case ResType_Sound:
+ {
+ SoundRes *aSoundRes = (SoundRes*)aRes;
+ if (aSoundRes->mSoundId!=-1)
+ continue;
+
+ return DoLoadSound(aSoundRes);
+ }
+
+ case ResType_Font:
+ {
+ FontRes *aFontRes = (FontRes*)aRes;
+ if (aFontRes->mFont!=NULL)
+ continue;
+
+ return DoLoadFont(aFontRes);
+ }
+ }
+ }
+
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::ResourceLoadedHook(BaseRes *theRes)
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::StartLoadResources(const std::string &theGroup)
+{
+ mError = "";
+ mHasFailed = false;
+
+ mCurResGroup = theGroup;
+ mCurResGroupList = &mResGroupMap[theGroup];
+ mCurResGroupListItr = mCurResGroupList->begin();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void ResourceManager::DumpCurResGroup(std::string& theDestStr)
+{
+ const ResList* rl = &mResGroupMap.find(mCurResGroup)->second;
+ ResList::const_iterator it = rl->begin();
+ theDestStr = StrFormat("About to dump %d elements from current res group name %s\r\n", rl->size(), mCurResGroup.c_str());
+
+ ResList::const_iterator rl_end = rl->end();
+ while (it != rl_end)
+ {
+ BaseRes* br = *it++;
+ std::string prefix = StrFormat("%s: %s\r\n", br->mId.c_str(), br->mPath.c_str());
+ theDestStr += prefix;
+ if (br->mFromProgram)
+ theDestStr += std::string(" res is from program\r\n");
+ else if (br->mType == ResType_Image)
+ theDestStr += std::string(" res is an image\r\n");
+ else if (br->mType == ResType_Sound)
+ theDestStr += std::string(" res is a sound\r\n");
+ else if (br->mType == ResType_Font)
+ theDestStr += std::string(" res is a font\r\n");
+
+ if (it == mCurResGroupListItr)
+ theDestStr += std::string("iterator has reached mCurResGroupItr\r\n");
+
+ }
+
+ theDestStr += std::string("Done dumping resources\r\n");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::LoadResources(const std::string &theGroup)
+{
+ mError = "";
+ mHasFailed = false;
+ StartLoadResources(theGroup);
+ while (LoadNextResource())
+ {
+ }
+
+ if (!HadError())
+ {
+ mLoadedGroups.insert(theGroup);
+ return true;
+ }
+ else
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetNumResources(const std::string &theGroup, ResMap &theMap)
+{
+ if (theGroup.empty())
+ return theMap.size();
+
+ int aCount = 0;
+ for (ResMap::iterator anItr = theMap.begin(); anItr != theMap.end(); ++anItr)
+ {
+ BaseRes *aRes = anItr->second;
+ if (aRes->mResGroup==theGroup && !aRes->mFromProgram)
+ ++aCount;
+ }
+
+ return aCount;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetNumImages(const std::string &theGroup)
+{
+ return GetNumResources(theGroup, mImageMap);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetNumSounds(const std::string &theGroup)
+{
+ return GetNumResources(theGroup,mSoundMap);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetNumFonts(const std::string &theGroup)
+{
+ return GetNumResources(theGroup, mFontMap);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetNumResources(const std::string &theGroup)
+{
+ return GetNumImages(theGroup) + GetNumSounds(theGroup) + GetNumFonts(theGroup);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SharedImageRef ResourceManager::GetImage(const std::string &theId)
+{
+ ResMap::iterator anItr = mImageMap.find(theId);
+ if (anItr != mImageMap.end())
+ return ((ImageRes*)anItr->second)->mImage;
+ else
+ return NULL;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetSound(const std::string &theId)
+{
+ ResMap::iterator anItr = mSoundMap.find(theId);
+ if (anItr != mSoundMap.end())
+ return ((SoundRes*)anItr->second)->mSoundId;
+ else
+ return -1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+Font* ResourceManager::GetFont(const std::string &theId)
+{
+ ResMap::iterator anItr = mFontMap.find(theId);
+ if (anItr != mFontMap.end())
+ return ((FontRes*)anItr->second)->mFont;
+ else
+ return NULL;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SharedImageRef ResourceManager::GetImageThrow(const std::string &theId)
+{
+ ResMap::iterator anItr = mImageMap.find(theId);
+ if (anItr != mImageMap.end())
+ {
+ ImageRes *aRes = (ImageRes*)anItr->second;
+ if ((MemoryImage*) aRes->mImage != NULL)
+ return aRes->mImage;
+
+ if (mAllowMissingProgramResources && aRes->mFromProgram)
+ return NULL;
+ }
+
+
+ Fail(StrFormat("Image resource not found: %s",theId.c_str()));
+ throw ResourceManagerException(GetErrorText());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int ResourceManager::GetSoundThrow(const std::string &theId)
+{
+ ResMap::iterator anItr = mSoundMap.find(theId);
+ if (anItr != mSoundMap.end())
+ {
+ SoundRes *aRes = (SoundRes*)anItr->second;
+ if (aRes->mSoundId!=-1)
+ return aRes->mSoundId;
+
+ if (mAllowMissingProgramResources && aRes->mFromProgram)
+ return -1;
+ }
+
+
+ Fail(StrFormat("Sound resource not found: %s",theId.c_str()));
+ throw ResourceManagerException(GetErrorText());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+Font* ResourceManager::GetFontThrow(const std::string &theId)
+{
+ ResMap::iterator anItr = mFontMap.find(theId);
+ if (anItr != mFontMap.end())
+ {
+ FontRes *aRes = (FontRes*)anItr->second;
+ if (aRes->mFont!=NULL)
+ return aRes->mFont;
+
+ if (mAllowMissingProgramResources && aRes->mFromProgram)
+ return NULL;
+ }
+
+ Fail(StrFormat("Font resource not found: %s",theId.c_str()));
+ throw ResourceManagerException(GetErrorText());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void ResourceManager::SetAllowMissingProgramImages(bool allow)
+{
+ mAllowMissingProgramResources = allow;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ReplaceImage(const std::string &theId, Image *theImage)
+{
+ ResMap::iterator anItr = mImageMap.find(theId);
+ if (anItr != mImageMap.end())
+ {
+ anItr->second->DeleteResource();
+ ((ImageRes*)anItr->second)->mImage = (MemoryImage*) theImage;
+ ((ImageRes*)anItr->second)->mImage.mOwnsUnshared = true;
+ return true;
+ }
+ else
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ReplaceSound(const std::string &theId, int theSound)
+{
+ ResMap::iterator anItr = mSoundMap.find(theId);
+ if (anItr != mSoundMap.end())
+ {
+ anItr->second->DeleteResource();
+ ((SoundRes*)anItr->second)->mSoundId = theSound;
+ return true;
+ }
+ else
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool ResourceManager::ReplaceFont(const std::string &theId, Font *theFont)
+{
+ ResMap::iterator anItr = mFontMap.find(theId);
+ if (anItr != mFontMap.end())
+ {
+ anItr->second->DeleteResource();
+ ((FontRes*)anItr->second)->mFont = theFont;
+ return true;
+ }
+ else
+ return false;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const XMLParamMap& ResourceManager::GetImageAttributes(const std::string &theId)
+{
+ static XMLParamMap aStrMap;
+
+ ResMap::iterator anItr = mImageMap.find(theId);
+ if (anItr != mImageMap.end())
+ return anItr->second->mXMLAttributes;
+ else
+ return aStrMap;
+}
diff --git a/osframework/source/SexyAppFramework/ResourceManager.h b/osframework/source/SexyAppFramework/ResourceManager.h
new file mode 100644
index 0000000..7787ce1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ResourceManager.h
@@ -0,0 +1,219 @@
+#ifndef __SEXY_RESOURCEMANAGER_H__
+#define __SEXY_RESOURCEMANAGER_H__
+
+#include "Common.h"
+#include "Image.h"
+#include "SexyAppBase.h"
+#include <string>
+#include <map>
+
+namespace ImageLib
+{
+class Image;
+};
+
+namespace Sexy
+{
+
+class XMLParser;
+class XMLElement;
+class Image;
+class SoundInstance;
+class SexyAppBase;
+class Font;
+
+typedef std::map<std::string, std::string> StringToStringMap;
+typedef std::map<SexyString, SexyString> XMLParamMap;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class ResourceManager
+{
+protected:
+ enum ResType
+ {
+ ResType_Image,
+ ResType_Sound,
+ ResType_Font
+ };
+
+
+ struct BaseRes
+ {
+ ResType mType;
+ std::string mId;
+ std::string mResGroup;
+ std::string mPath;
+ XMLParamMap mXMLAttributes;
+ bool mFromProgram;
+
+ virtual ~BaseRes() {}
+ virtual void DeleteResource() { }
+ };
+
+ struct ImageRes : public BaseRes
+ {
+ SharedImageRef mImage;
+ std::string mAlphaImage;
+ std::string mAlphaGridImage;
+ std::string mVariant;
+ bool mAutoFindAlpha;
+ bool mPalletize;
+ bool mA4R4G4B4;
+ bool mA8R8G8B8;
+ bool mDDSurface;
+ bool mPurgeBits;
+ bool mMinimizeSubdivisions;
+ int mRows;
+ int mCols;
+ DWORD mAlphaColor;
+ AnimInfo mAnimInfo;
+
+ ImageRes() { mType = ResType_Image; }
+ virtual void DeleteResource();
+ };
+
+ struct SoundRes : public BaseRes
+ {
+ int mSoundId;
+ double mVolume;
+ int mPanning;
+
+ SoundRes() { mType = ResType_Sound; }
+ virtual void DeleteResource();
+ };
+
+ struct FontRes : public BaseRes
+ {
+ Font *mFont;
+ Image *mImage;
+ std::string mImagePath;
+ std::string mTags;
+
+ // For SysFonts
+ bool mSysFont;
+ bool mBold;
+ bool mItalic;
+ bool mUnderline;
+ bool mShadow;
+ int mSize;
+
+
+ FontRes() { mType = ResType_Font; }
+ virtual void DeleteResource();
+ };
+
+ typedef std::map<std::string,BaseRes*> ResMap;
+ typedef std::list<BaseRes*> ResList;
+ typedef std::map<std::string,ResList,StringLessNoCase> ResGroupMap;
+
+ std::set<std::string,StringLessNoCase> mLoadedGroups;
+
+ ResMap mImageMap;
+ ResMap mSoundMap;
+ ResMap mFontMap;
+
+ XMLParser* mXMLParser;
+ std::string mError;
+ bool mHasFailed;
+ SexyAppBase* mApp;
+ std::string mCurResGroup;
+ std::string mDefaultPath;
+ std::string mDefaultIdPrefix;
+ bool mAllowMissingProgramResources;
+ bool mAllowAlreadyDefinedResources; // for reparsing file while running
+ bool mHadAlreadyDefinedError;
+
+ ResGroupMap mResGroupMap;
+ ResList* mCurResGroupList;
+ ResList::iterator mCurResGroupListItr;
+
+
+ bool Fail(const std::string& theErrorText);
+
+ virtual bool ParseCommonResource(XMLElement &theElement, BaseRes *theRes, ResMap &theMap);
+ virtual bool ParseSoundResource(XMLElement &theElement);
+ virtual bool ParseImageResource(XMLElement &theElement);
+ virtual bool ParseFontResource(XMLElement &theElement);
+ virtual bool ParseSetDefaults(XMLElement &theElement);
+ virtual bool ParseResources();
+
+ bool DoParseResources();
+ void DeleteMap(ResMap &theMap);
+ virtual void DeleteResources(ResMap &theMap, const std::string &theGroup);
+
+ bool LoadAlphaGridImage(ImageRes *theRes, DDImage *theImage);
+ bool LoadAlphaImage(ImageRes *theRes, DDImage *theImage);
+ virtual bool DoLoadImage(ImageRes *theRes);
+ virtual bool DoLoadFont(FontRes* theRes);
+ virtual bool DoLoadSound(SoundRes* theRes);
+
+ int GetNumResources(const std::string &theGroup, ResMap &theMap);
+
+public:
+ ResourceManager(SexyAppBase *theApp);
+ virtual ~ResourceManager();
+
+ bool ParseResourcesFile(const std::string& theFilename);
+ bool ReparseResourcesFile(const std::string& theFilename);
+
+ std::string GetErrorText();
+ bool HadError();
+ bool IsGroupLoaded(const std::string &theGroup);
+
+ int GetNumImages(const std::string &theGroup);
+ int GetNumSounds(const std::string &theGroup);
+ int GetNumFonts(const std::string &theGroup);
+ int GetNumResources(const std::string &theGroup);
+
+ virtual bool LoadNextResource();
+ virtual void ResourceLoadedHook(BaseRes *theRes);
+
+ virtual void StartLoadResources(const std::string &theGroup);
+ virtual bool LoadResources(const std::string &theGroup);
+
+ bool ReplaceImage(const std::string &theId, Image *theImage);
+ bool ReplaceSound(const std::string &theId, int theSound);
+ bool ReplaceFont(const std::string &theId, Font *theFont);
+
+ void DeleteImage(const std::string &theName);
+ SharedImageRef LoadImage(const std::string &theName);
+
+ void DeleteFont(const std::string &theName);
+ Font* LoadFont(const std::string &theName);
+
+ SharedImageRef GetImage(const std::string &theId);
+ int GetSound(const std::string &theId);
+ Font* GetFont(const std::string &theId);
+
+ // Returns all the XML attributes associated with the image
+ const XMLParamMap& GetImageAttributes(const std::string &theId);
+
+ // These throw a ResourceManagerException if the resource is not found
+ virtual SharedImageRef GetImageThrow(const std::string &theId);
+ virtual int GetSoundThrow(const std::string &theId);
+ virtual Font* GetFontThrow(const std::string &theId);
+
+ void SetAllowMissingProgramImages(bool allow);
+
+ virtual void DeleteResources(const std::string &theGroup);
+ void DeleteExtraImageBuffers(const std::string &theGroup);
+
+ const ResList* GetCurResGroupList() {return mCurResGroupList;}
+ std::string GetCurResGroup() {return mCurResGroup;}
+ void DumpCurResGroup(std::string& theDestStr);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct ResourceManagerException : public std::exception
+{
+ std::string what;
+ ResourceManagerException(const std::string &theWhat) : what(theWhat) { }
+};
+
+}
+
+#endif //__PROPERTIESPARSER_H__
+
+
diff --git a/osframework/source/SexyAppFramework/SEHCatcher.cpp b/osframework/source/SexyAppFramework/SEHCatcher.cpp
new file mode 100644
index 0000000..4ecfd47
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SEHCatcher.cpp
@@ -0,0 +1,1292 @@
+#include "SEHCatcher.h"
+#include "SexyAppBase.h"
+#include <fstream>
+#include <process.h>
+
+#ifdef ZYLOM
+#include "zylomso.h"
+using namespace zylom::zylomso;
+#endif
+
+using namespace Sexy;
+
+LPTOP_LEVEL_EXCEPTION_FILTER SEHCatcher::mPreviousFilter;
+SexyAppBase* SEHCatcher::mApp = NULL;
+HFONT SEHCatcher::mDialogFont = NULL;
+HFONT SEHCatcher::mBoldFont = NULL;
+bool SEHCatcher::mHasDemoFile = false;
+bool SEHCatcher::mDebugError = false;
+std::string SEHCatcher::mErrorTitle;
+std::string SEHCatcher::mErrorText;
+std::string SEHCatcher::mUserText;
+std::string SEHCatcher::mUploadFileName;
+HWND SEHCatcher::mYesButtonWindow = NULL;
+HWND SEHCatcher::mNoButtonWindow = NULL;
+HWND SEHCatcher::mDebugButtonWindow = NULL;
+HWND SEHCatcher::mEditWindow = NULL;
+HMODULE SEHCatcher::mImageHelpLib = NULL;
+SYMINITIALIZEPROC SEHCatcher::mSymInitialize = NULL;
+SYMSETOPTIONSPROC SEHCatcher::mSymSetOptions = NULL;
+UNDECORATESYMBOLNAMEPROC SEHCatcher::mUnDecorateSymbolName = NULL;
+SYMCLEANUPPROC SEHCatcher::mSymCleanup = NULL;
+STACKWALKPROC SEHCatcher::mStackWalk = NULL;
+SYMFUNCTIONTABLEACCESSPROC SEHCatcher::mSymFunctionTableAccess = NULL;
+SYMGETMODULEBASEPROC SEHCatcher::mSymGetModuleBase = NULL;
+SYMGETSYMFROMADDRPROC SEHCatcher::mSymGetSymFromAddr = NULL;
+HTTPTransfer SEHCatcher::mSubmitReportTransfer;
+bool SEHCatcher::mExiting = false;
+bool SEHCatcher::mShowUI = true;
+bool SEHCatcher::mAllowSubmit = true;
+
+std::wstring SEHCatcher::mCrashMessage = L"An unexpected error has occured!";
+std::string SEHCatcher::mSubmitHost;
+std::wstring SEHCatcher::mSubmitMessage = L"Please help out by providing as much information as you can about this crash.";
+std::wstring SEHCatcher::mSubmitErrorMessage = L"Failed to connect to server.";
+
+static bool gUseDefaultFonts = true;
+
+struct
+{
+ DWORD dwExceptionCode;
+ char *szMessage;
+} gMsgTable[] = {
+ { STATUS_SEGMENT_NOTIFICATION, "Segment Notification" },
+ { STATUS_BREAKPOINT, "Breakpoint" },
+ { STATUS_SINGLE_STEP, "Single step" },
+ { STATUS_WAIT_0, "Wait 0" },
+ { STATUS_ABANDONED_WAIT_0, "Abandoned Wait 0" },
+ { STATUS_USER_APC, "User APC" },
+ { STATUS_TIMEOUT, "Timeout" },
+ { STATUS_PENDING, "Pending" },
+ { STATUS_GUARD_PAGE_VIOLATION, "Guard Page Violation" },
+ { STATUS_DATATYPE_MISALIGNMENT, "Data Type Misalignment" },
+ { STATUS_ACCESS_VIOLATION, "Access Violation" },
+ { STATUS_IN_PAGE_ERROR, "In Page Error" },
+ { STATUS_NO_MEMORY, "No Memory" },
+ { STATUS_ILLEGAL_INSTRUCTION, "Illegal Instruction" },
+ { STATUS_NONCONTINUABLE_EXCEPTION, "Noncontinuable Exception" },
+ { STATUS_INVALID_DISPOSITION, "Invalid Disposition" },
+ { STATUS_ARRAY_BOUNDS_EXCEEDED, "Array Bounds Exceeded" },
+ { STATUS_FLOAT_DENORMAL_OPERAND, "Float Denormal Operand" },
+ { STATUS_FLOAT_DIVIDE_BY_ZERO, "Divide by Zero" },
+ { STATUS_FLOAT_INEXACT_RESULT, "Float Inexact Result" },
+ { STATUS_FLOAT_INVALID_OPERATION, "Float Invalid Operation" },
+ { STATUS_FLOAT_OVERFLOW, "Float Overflow" },
+ { STATUS_FLOAT_STACK_CHECK, "Float Stack Check" },
+ { STATUS_FLOAT_UNDERFLOW, "Float Underflow" },
+ { STATUS_INTEGER_DIVIDE_BY_ZERO, "Integer Divide by Zero" },
+ { STATUS_INTEGER_OVERFLOW, "Integer Overflow" },
+ { STATUS_PRIVILEGED_INSTRUCTION, "Privileged Instruction" },
+ { STATUS_STACK_OVERFLOW, "Stack Overflow" },
+ { STATUS_CONTROL_C_EXIT, "Ctrl+C Exit" },
+ { 0xFFFFFFFF, "" }
+};
+
+
+SEHCatcher::SEHCatcher()
+{
+ mPreviousFilter = SetUnhandledExceptionFilter(UnhandledExceptionFilter);
+}
+
+SEHCatcher::~SEHCatcher()
+{
+ SetUnhandledExceptionFilter(mPreviousFilter);
+}
+
+long __stdcall SEHCatcher::UnhandledExceptionFilter(LPEXCEPTION_POINTERS lpExceptPtr)
+{
+ if (mApp != NULL)
+ mApp->SEHOccured();
+
+ DoHandleDebugEvent(lpExceptPtr);
+
+ if (!mDebugError)
+ SetErrorMode(SEM_NOGPFAULTERRORBOX);
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+bool SEHCatcher::LoadImageHelp()
+{
+ mImageHelpLib = LoadLibraryA("IMAGEHLP.DLL");
+ if (!mImageHelpLib)
+ return false;
+
+ mSymInitialize = (SYMINITIALIZEPROC) GetProcAddress(mImageHelpLib, "SymInitialize");
+ if (!mSymInitialize)
+ return false;
+
+ mSymSetOptions = (SYMSETOPTIONSPROC) GetProcAddress(mImageHelpLib, "SymSetOptions");
+ if (!mSymSetOptions)
+ return false;
+
+ mSymCleanup = (SYMCLEANUPPROC) GetProcAddress(mImageHelpLib, "SymCleanup");
+ if (!mSymCleanup)
+ return false;
+
+ mUnDecorateSymbolName = (UNDECORATESYMBOLNAMEPROC) GetProcAddress(mImageHelpLib, "UnDecorateSymbolName");
+ if (!mUnDecorateSymbolName)
+ return false;
+
+ mStackWalk = (STACKWALKPROC) GetProcAddress(mImageHelpLib, "StackWalk");
+ if (!mStackWalk)
+ return false;
+
+ mSymFunctionTableAccess = (SYMFUNCTIONTABLEACCESSPROC) GetProcAddress(mImageHelpLib, "SymFunctionTableAccess");
+ if (!mSymFunctionTableAccess)
+ return false;
+
+ mSymGetModuleBase = (SYMGETMODULEBASEPROC) GetProcAddress(mImageHelpLib, "SymGetModuleBase");
+ if (!mSymGetModuleBase)
+ return false;
+
+ mSymGetSymFromAddr = (SYMGETSYMFROMADDRPROC) GetProcAddress(mImageHelpLib, "SymGetSymFromAddr" );
+ if (!mSymGetSymFromAddr)
+ return false;
+
+ mSymSetOptions(SYMOPT_DEFERRED_LOADS);
+
+ // Get image filename of the main executable
+ char filepath[MAX_PATH], *lastdir, *pPath;
+ DWORD filepathlen = GetModuleFileNameA ( NULL, filepath, sizeof(filepath));
+
+ lastdir = strrchr (filepath, '/');
+ if (lastdir == NULL) lastdir = strrchr (filepath, '\\');
+ if (lastdir != NULL) lastdir[0] = '\0';
+
+ // Initialize the symbol table routines, supplying a pointer to the path
+ pPath = filepath;
+ if (strlen (filepath) == 0) pPath = NULL;
+
+ if (!mSymInitialize (GetCurrentProcess(), pPath, TRUE))
+ return false;
+
+ return true;
+}
+
+void SEHCatcher::UnloadImageHelp()
+{
+ if (mImageHelpLib != NULL)
+ FreeLibrary(mImageHelpLib);
+}
+
+static bool StrToLongHex(const std::string& aString, DWORD* theValue)
+{
+ *theValue = 0;
+
+ for (int i = 0; i < (int)aString.length(); i++)
+ {
+ char aChar = aString[i];
+
+ int aValue;
+ if ((aChar >= '0') && (aChar <= '9'))
+ aValue = aChar - '0';
+ else if ((aChar >= 'A') && (aChar <= 'F'))
+ aValue = (aChar - 'A') + 10;
+ else if ((aChar >= 'a') && (aChar <= 'f'))
+ aValue = (aChar - 'a') + 10;
+ else
+ return false;
+
+ *theValue += aValue << ((aString.length()-i-1)*4);
+ }
+
+ return true;
+}
+
+void SEHCatcher::GetSymbolsFromMapFile(std::string &theDebugDump)
+{
+ DWORD aTick = GetTickCount();
+ WIN32_FIND_DATAA aFindData;
+ HANDLE aFindHandle = FindFirstFileA("*.map",&aFindData);
+ if (aFindHandle==INVALID_HANDLE_VALUE)
+ return;
+
+ FindClose(aFindHandle);
+
+ typedef std::pair<DWORD,DWORD> SymbolPair;
+ typedef std::map<SymbolPair,std::string> SymbolMap;
+ typedef std::pair<std::string,int> LineNumPair;
+ typedef std::map<SymbolPair,LineNumPair> LineNumMap;
+
+/**/
+ SymbolMap aSymbolMap;
+ LineNumMap aLineNumMap;
+ std::fstream aFile(aFindData.cFileName, std::ios::in);
+
+ if (!aFile.is_open())
+ return;
+
+ // Parse map file
+ std::string aCurLinesFile;
+ while (!aFile.eof())
+ {
+ char aStr[4096];
+ aFile.getline(aStr, 4096);
+
+ std::string aString = aStr;
+
+ if ((aString.length() > 22) && (aString[5] == ':'))
+ {
+ std::string aFoundPreStr = aString.substr(1, 4);
+ std::string aFoundPostStr = aString.substr(6, 8);
+
+ DWORD aFoundPreVal;
+ DWORD aFoundPostVal;
+
+ if (StrToLongHex(aFoundPreStr, &aFoundPreVal) && StrToLongHex(aFoundPostStr, &aFoundPostVal))
+ {
+ int aSpacePos = aString.find(' ', 21);
+
+ if ((aString[20] == ' ') && (aSpacePos >= 0))
+ aSymbolMap[SymbolPair(aFoundPreVal,aFoundPostVal)] = aString.substr(21, aSpacePos-21);
+ }
+ }
+ else if (strcmp(aString.substr(0, strlen("Line numbers")).c_str(), "Line numbers") == 0)
+ {
+ int aSegmentPos = aString.rfind(')');
+ if (aSegmentPos == -1)
+ aSegmentPos = aString.length();
+
+ int aPreLen = strlen("Line numbers for ");
+
+ int aStartPos = aString.find('(');
+
+ aCurLinesFile = aString.substr(aStartPos + 1, aSegmentPos - aStartPos - 1);
+ }
+ else if ((aCurLinesFile.length() > 0) && (aString.length() == 80))
+ {
+ // Line number stuff
+
+ for (int i = 0; i < 4; i++)
+ {
+ int aStartLoc = 20 * i;
+
+ int aLine = atoi(aString.substr(aStartLoc, 6).c_str());
+
+ std::string aFoundPreStr = aString.substr(aStartLoc + 7, 4);
+ std::string aFoundPostStr = aString.substr(aStartLoc + 12, 8);
+
+ DWORD aFoundPreVal;
+ DWORD aFoundPostVal;
+
+ if (StrToLongHex(aFoundPreStr, &aFoundPreVal) && StrToLongHex(aFoundPostStr, &aFoundPostVal))
+ {
+ aLineNumMap[SymbolPair(aFoundPreVal,aFoundPostVal)] = LineNumPair(aCurLinesFile,aLine);
+ }
+ }
+ }
+ }
+
+ // Parse stack trace
+ for (int i = 0; i < (int)theDebugDump.length(); i++)
+ {
+ if (theDebugDump.at(i) == ':')
+ {
+ std::string aFindPreStr = theDebugDump.substr(i-4, 4);
+ std::string aFindPostStr = theDebugDump.substr(i+1, 8);
+
+ DWORD aFindPreVal;
+ DWORD aFindPostVal;
+
+ if (StrToLongHex(aFindPreStr, &aFindPreVal) && StrToLongHex(aFindPostStr, &aFindPostVal))
+ {
+
+ int aBestDist = -1;
+ SymbolMap::iterator aSymbolItr = aSymbolMap.lower_bound(SymbolPair(aFindPreVal,aFindPostVal));
+ if (aSymbolItr!=aSymbolMap.end() && aSymbolItr!=aSymbolMap.begin() && aSymbolItr->first.second!=aFindPostVal)
+ --aSymbolItr;
+
+ if (aSymbolItr!=aSymbolMap.end() && aSymbolItr->first.first==aFindPreVal)
+ aBestDist = aFindPostVal - aSymbolItr->first.second;
+
+ if (aBestDist != -1)
+ {
+ std::string &aBestName = aSymbolItr->second;
+
+ char aSymbolName[4096];
+
+ if (mUnDecorateSymbolName(aBestName.c_str(), aSymbolName, 4096,
+ UNDNAME_NO_ALLOCATION_MODEL | UNDNAME_NO_ACCESS_SPECIFIERS |
+ UNDNAME_NO_THROW_SIGNATURES | UNDNAME_NO_MEMBER_TYPE) == 0)
+ strcpy(aSymbolName, aBestName.c_str());
+
+ if (aBestDist != 0)
+ {
+ sprintf(aSymbolName+strlen(aSymbolName), "+0x%X", aBestDist);
+ }
+
+ std::string aNewText = aSymbolName;
+
+ LineNumMap::iterator aLineNumItr = aLineNumMap.lower_bound(SymbolPair(aFindPreVal,aFindPostVal));
+ if (aLineNumItr!=aLineNumMap.end() && aLineNumItr!=aLineNumMap.begin() && aLineNumItr->first.second!=aFindPostVal)
+ --aLineNumItr;
+
+ if (aLineNumItr!=aLineNumMap.end() && aLineNumItr->first.first==aFindPreVal)
+ {
+ std::string &aBestFile = aLineNumItr->second.first;
+ int aBestLine = aLineNumItr->second.second;
+ int aBestLineDist = aFindPostVal - aLineNumItr->first.second;
+
+ char aDistStr[4096];
+ sprintf(aDistStr, "\r\n %s line %d +0x%X", aBestFile.c_str(), aBestLine, aBestLineDist);
+ aNewText += aDistStr;
+ }
+
+ theDebugDump.erase(i-4, 13);
+ theDebugDump.insert(i-4, aNewText.c_str());
+ }
+ }
+ }
+ }
+
+// MessageBox(NULL,StrFormat("%d",GetTickCount()-aTick).c_str(),"Time",MB_OK);
+}
+
+void SEHCatcher::DoHandleDebugEvent(LPEXCEPTION_POINTERS lpEP)
+{
+ bool hasImageHelp = LoadImageHelp();
+
+ std::string anErrorTitle;
+ std::string aDebugDump;
+
+ char aBuffer[2048];
+
+ ///////////////////////////
+ // first name the exception
+ char *szName = NULL;
+ for (int i=0; gMsgTable[i].dwExceptionCode != 0xFFFFFFFF; i++)
+ {
+ if (gMsgTable[i].dwExceptionCode == lpEP->ExceptionRecord->ExceptionCode)
+ {
+ szName = gMsgTable[i].szMessage;
+ break;
+ }
+ }
+
+ if (szName != NULL)
+ {
+ sprintf(aBuffer,"Exception: %s (code 0x%x) at address %08X in thread %X\r\n",
+ szName, lpEP->ExceptionRecord->ExceptionCode,
+ lpEP->ExceptionRecord->ExceptionAddress, GetCurrentThreadId());
+ }
+ else
+ {
+ sprintf(aBuffer,"Unknown exception: (code 0x%x) at address %08X in thread %X\r\n",
+ lpEP->ExceptionRecord->ExceptionCode,
+ lpEP->ExceptionRecord->ExceptionAddress, GetCurrentThreadId());
+ }
+
+ aDebugDump += aBuffer;
+
+ ///////////////////////////////////////////////////////////
+ // Get logical address of the module where exception occurs
+ DWORD section, offset;
+ GetLogicalAddress(lpEP->ExceptionRecord->ExceptionAddress, aBuffer, sizeof(aBuffer), section, offset);
+ aDebugDump += "Module: " + GetFilename(aBuffer) + "\r\n";
+ sprintf(aBuffer, "Logical Address: %04X:%08X\r\n", section, offset);
+ aDebugDump += aBuffer;
+
+ aDebugDump += "\r\n";
+
+ anErrorTitle = StrFormat("Exception at %04X:%08X", section, offset);
+
+ std::string aWalkString;
+
+ if (hasImageHelp)
+ aWalkString = ImageHelpWalk(lpEP->ContextRecord, 0);
+
+ if (aWalkString.length() == 0)
+ aWalkString = IntelWalk(lpEP->ContextRecord, 0);
+
+ aDebugDump += aWalkString;
+
+ aDebugDump += "\r\n";
+ sprintf(aBuffer, ("EAX:%08X EBX:%08X ECX:%08X EDX:%08X ESI:%08X EDI:%08X\r\n"),
+ lpEP->ContextRecord->Eax, lpEP->ContextRecord->Ebx, lpEP->ContextRecord->Ecx, lpEP->ContextRecord->Edx, lpEP->ContextRecord->Esi, lpEP->ContextRecord->Edi);
+ aDebugDump += aBuffer;
+ sprintf(aBuffer, "EIP:%08X ESP:%08X EBP:%08X\r\n", lpEP->ContextRecord->Eip, lpEP->ContextRecord->Esp, lpEP->ContextRecord->Ebp);
+ aDebugDump += aBuffer;
+ sprintf(aBuffer, "CS:%04X SS:%04X DS:%04X ES:%04X FS:%04X GS:%04X\r\n", lpEP->ContextRecord->SegCs, lpEP->ContextRecord->SegSs, lpEP->ContextRecord->SegDs, lpEP->ContextRecord->SegEs, lpEP->ContextRecord->SegFs, lpEP->ContextRecord->SegGs );
+ aDebugDump += aBuffer;
+ sprintf(aBuffer, "Flags:%08X\r\n", lpEP->ContextRecord->EFlags );
+ aDebugDump += aBuffer;
+
+ aDebugDump += "\r\n";
+ aDebugDump += GetSysInfo();
+
+ if (mApp != NULL)
+ {
+ std::string aGameSEHInfo = mApp->GetGameSEHInfo();
+ if (aGameSEHInfo.length() > 0)
+ {
+ aDebugDump += "\r\n";
+ aDebugDump += aGameSEHInfo;
+ }
+
+ mApp->CopyToClipboard(aDebugDump);
+ }
+
+ if (hasImageHelp)
+ GetSymbolsFromMapFile(aDebugDump);
+
+ WriteToFile(aDebugDump);
+
+#ifdef ZYLOM
+ ZylomGS_StandAlone_SendBugReport((char*) aDebugDump.c_str());
+#else
+ if (mApp != NULL)
+ {
+ if (mApp->mRecordingDemoBuffer)
+ {
+ // Make sure we have enough update block things in there to
+ // get to the final crashing update
+ mApp->WriteDemoTimingBlock();
+ mApp->mDemoBuffer.WriteNumBits(0, 1);
+ mApp->mDemoBuffer.WriteNumBits(DEMO_IDLE, 5);
+ mApp->WriteDemoBuffer();
+ mUploadFileName = mApp->mDemoFileName;
+ }
+
+ mHasDemoFile = mApp->mRecordingDemoBuffer;
+ std::string anUploadFile = mApp->NotifyCrashHook();
+ if (!anUploadFile.empty())
+ {
+ mUploadFileName = anUploadFile;
+ mHasDemoFile = true;
+ }
+
+ mApp->mRecordingDemoBuffer = false;
+ mApp->mPlayingDemoBuffer = false;
+ }
+
+ if (mShowUI)
+ ShowErrorDialog(anErrorTitle, aDebugDump);
+#endif
+
+ //::MessageBox(NULL, aDebugDump.c_str(), "ERROR", MB_ICONERROR);
+
+ UnloadImageHelp();
+}
+
+std::string SEHCatcher::IntelWalk(PCONTEXT theContext, int theSkipCount)
+{
+ std::string aDebugDump;
+ char aBuffer[2048];
+
+ DWORD pc = theContext->Eip;
+ PDWORD pFrame, pPrevFrame;
+
+ pFrame = (PDWORD)theContext->Ebp;
+
+ for (;;)
+ {
+ char szModule[MAX_PATH] = "";
+ DWORD section = 0, offset = 0;
+
+ GetLogicalAddress((PVOID)pc, szModule, sizeof(szModule), section, offset);
+
+ sprintf(aBuffer, "%08X %08X %04X:%08X %s\r\n",
+ pc, pFrame, section, offset, GetFilename(szModule).c_str());
+ aDebugDump += aBuffer;
+
+ pc = pFrame[1];
+
+ pPrevFrame = pFrame;
+
+ pFrame = (PDWORD)pFrame[0]; // proceed to next higher frame on stack
+
+ if ((DWORD)pFrame & 3) // Frame pointer must be aligned on a
+ break; // DWORD boundary. Bail if not so.
+
+ if (pFrame <= pPrevFrame)
+ break;
+
+ // Can two DWORDs be read from the supposed frame address?
+ if (IsBadWritePtr(pFrame, sizeof(PVOID)*2))
+ break;
+ };
+
+ return aDebugDump;
+}
+
+std::string SEHCatcher::ImageHelpWalk(PCONTEXT theContext, int theSkipCount)
+{
+ char aBuffer[2048];
+ std::string aDebugDump;
+
+ STACKFRAME sf;
+ memset( &sf, 0, sizeof(sf) );
+
+ // Initialize the STACKFRAME structure for the first call. This is only
+ // necessary for Intel CPUs, and isn't mentioned in the documentation.
+ sf.AddrPC.Offset = theContext->Eip;
+ sf.AddrPC.Mode = AddrModeFlat;
+ sf.AddrStack.Offset = theContext->Esp;
+ sf.AddrStack.Mode = AddrModeFlat;
+ sf.AddrFrame.Offset = theContext->Ebp;
+ sf.AddrFrame.Mode = AddrModeFlat;
+
+ int aLevelCount = 0;
+
+ for (;;)
+ {
+ if (!mStackWalk(IMAGE_FILE_MACHINE_I386, GetCurrentProcess(), GetCurrentThread(),
+ &sf, NULL /*theContext*/, NULL, mSymFunctionTableAccess, mSymGetModuleBase, 0))
+ {
+ DWORD lastErr = GetLastError();
+ sprintf(aBuffer, "StackWalk failed (error %d)\r\n", lastErr);
+ aDebugDump += aBuffer;
+ break;
+ }
+
+ if ((sf.AddrFrame.Offset == 0) || (sf.AddrPC.Offset == 0))
+ break;
+
+ if (theSkipCount > 0)
+ {
+ theSkipCount--;
+ continue;
+ }
+
+ BYTE symbolBuffer[sizeof(IMAGEHLP_SYMBOL) + 512];
+ PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL)symbolBuffer;
+ pSymbol->SizeOfStruct = sizeof(symbolBuffer);
+ pSymbol->MaxNameLength = 512;
+
+ DWORD symDisplacement = 0; // Displacement of the input address,
+ // relative to the start of the symbol
+
+ if (mSymGetSymFromAddr(GetCurrentProcess(), sf.AddrPC.Offset, &symDisplacement, pSymbol))
+ {
+ char aUDName[256];
+ mUnDecorateSymbolName(pSymbol->Name, aUDName, 256,
+ UNDNAME_NO_ALLOCATION_MODEL | UNDNAME_NO_ALLOCATION_LANGUAGE |
+ UNDNAME_NO_MS_THISTYPE | UNDNAME_NO_ACCESS_SPECIFIERS |
+ UNDNAME_NO_THISTYPE | UNDNAME_NO_MEMBER_TYPE |
+ UNDNAME_NO_RETURN_UDT_MODEL | UNDNAME_NO_THROW_SIGNATURES |
+ UNDNAME_NO_SPECIAL_SYMS);
+
+ sprintf(aBuffer, "%08X %08X %hs+%X\r\n",
+ sf.AddrFrame.Offset, sf.AddrPC.Offset, aUDName, symDisplacement);
+ }
+ else // No symbol found. Print out the logical address instead.
+ {
+ char szModule[MAX_PATH];
+ DWORD section = 0, offset = 0;
+
+ GetLogicalAddress((PVOID)sf.AddrPC.Offset, szModule, sizeof(szModule), section, offset);
+ sprintf(aBuffer, "%08X %08X %04X:%08X %s\r\n", sf.AddrFrame.Offset, sf.AddrPC.Offset, section, offset, GetFilename(szModule).c_str());
+ }
+ aDebugDump += aBuffer;
+
+ sprintf(aBuffer, "Params: %08X %08X %08X %08X\r\n", sf.Params[0], sf.Params[1], sf.Params[2], sf.Params[3]);
+ aDebugDump += aBuffer;
+ aDebugDump += "\r\n";
+
+ aLevelCount++;
+ }
+
+ return aDebugDump;
+}
+
+bool SEHCatcher::GetLogicalAddress(void* addr, char* szModule, DWORD len, DWORD& section, DWORD& offset)
+{
+ MEMORY_BASIC_INFORMATION mbi;
+
+ if (!VirtualQuery(addr, &mbi, sizeof(mbi)))
+ return false;
+
+ DWORD hMod = (DWORD)mbi.AllocationBase;
+
+ if (!GetModuleFileNameA((HMODULE) hMod, szModule, len))
+ return false;
+
+ // Point to the DOS header in memory
+ PIMAGE_DOS_HEADER pDosHdr = (PIMAGE_DOS_HEADER) hMod;
+
+ // From the DOS header, find the NT (PE) header
+ PIMAGE_NT_HEADERS pNtHdr = (PIMAGE_NT_HEADERS) (hMod + pDosHdr->e_lfanew);
+
+ PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pNtHdr);
+
+ DWORD rva = (DWORD) addr - hMod; // RVA is offset from module load address
+
+ // Iterate through the section table, looking for the one that encompasses
+ // the linear address.
+ for (unsigned i = 0; i < pNtHdr->FileHeader.NumberOfSections; i++, pSection++)
+ {
+ DWORD sectionStart = pSection->VirtualAddress;
+ DWORD sectionEnd = sectionStart + max(pSection->SizeOfRawData, pSection->Misc.VirtualSize);
+
+ // Is the address in this section???
+ if ((rva >= sectionStart) && (rva <= sectionEnd))
+ {
+ // Yes, address is in the section. Calculate section and offset,
+ // and store in the "section" & "offset" params, which were
+ // passed by reference.
+ section = i+1;
+ offset = rva - sectionStart;
+ return true;
+ }
+ }
+
+ return false; // Should never get here!
+}
+
+std::string SEHCatcher::GetFilename(const std::string& thePath)
+{
+ int aLastSlash = max((int) thePath.rfind('\\'), (int) thePath.rfind('/'));
+
+ if (aLastSlash >= 0)
+ {
+ return thePath.substr(aLastSlash+1);
+ }
+ else
+ return thePath;
+}
+
+HWND gEditWindow = NULL;
+int aCount = 0;
+
+static LRESULT CALLBACK SEHProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_COMMAND:
+ {
+ HWND hwndCtl = (HWND) lParam;
+ if (hwndCtl == SEHCatcher::mNoButtonWindow)
+ {
+ // Cancel it, man!
+ SEHCatcher::mSubmitReportTransfer.Abort();
+ }
+ }
+ break;
+ case WM_CLOSE:
+ SEHCatcher::mSubmitReportTransfer.Abort();
+ return 0;
+ case WM_TIMER:
+ {
+ if (wParam == 0)
+ {
+ int aResult = SEHCatcher::mSubmitReportTransfer.GetResultCode();
+
+ if ((aResult != HTTPTransfer::RESULT_NOT_COMPLETED) &&
+ (aResult != HTTPTransfer::RESULT_NOT_STARTED))
+ {
+ if ((aResult != HTTPTransfer::RESULT_DONE) &&
+ (aResult != HTTPTransfer::RESULT_ABORTED))
+ {
+ SEHCatcher::mSubmitReportTransfer.Reset();
+
+ if (::MessageBoxW(hWnd, SEHCatcher::mSubmitErrorMessage.c_str(),
+ L"Connection Failed", MB_RETRYCANCEL | MB_APPLMODAL) == IDRETRY)
+ {
+ _beginthread(SEHCatcher::SubmitReportThread, 0, 0);
+ return 0;
+ }
+ }
+
+ SEHCatcher::mExiting = true;
+ }
+ }
+ else if (wParam == 1)
+ {
+ ++aCount;
+
+ std::string aNewString = "Please Wait";
+
+ for (int i = 0; i < (aCount % 10); i++)
+ aNewString += " .";
+
+ SetWindowTextA(gEditWindow, aNewString.c_str());
+ }
+ }
+ break;
+ }
+
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+static void CreateProgressWindow()
+{
+ WNDCLASSA wc;
+ wc.style = 0;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = ::GetSysColorBrush(COLOR_BTNFACE);
+ wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = ::LoadIcon(NULL, IDI_ERROR);
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = SEHProgressWindowProc;
+ wc.lpszClassName = "SEHProgressWindow";
+ wc.lpszMenuName = NULL;
+ RegisterClassA(&wc);
+
+ RECT aRect;
+ aRect.left = 0;
+ aRect.top = 0;
+ aRect.right = 240;
+ aRect.bottom = 64;
+
+ DWORD aWindowStyle = WS_CLIPCHILDREN | WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
+
+ BOOL worked = AdjustWindowRect(&aRect, aWindowStyle, FALSE);
+
+ HWND aHWnd = CreateWindowA("SEHProgressWindow", "Submitting Report",
+ aWindowStyle,
+ 64, 64,
+ aRect.right - aRect.left,
+ aRect.bottom - aRect.top,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+
+ // Check every 20ms to see if the transfer has completed
+ SetTimer(aHWnd, 0, 20, NULL);
+
+ // Every second we should change the edit text
+ SetTimer(aHWnd, 1, 1000, NULL);
+
+ gEditWindow = CreateWindowA("EDIT",
+ "Please Wait",
+
+ WS_VISIBLE | WS_CHILD | ES_READONLY,
+ 24, 10,
+ 240-8-8,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(gEditWindow, WM_SETFONT, (WPARAM) SEHCatcher::mBoldFont, 0);
+
+ SEHCatcher::mNoButtonWindow = CreateWindowA("BUTTON", "Abort",
+ WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON,
+ (240 - 96)/2, 64 - 22 - 6,
+ 96,
+ 22,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(SEHCatcher::mNoButtonWindow, WM_SETFONT, (WPARAM) SEHCatcher::mDialogFont, 0);
+
+ ShowWindow(aHWnd, SW_NORMAL);
+}
+
+LRESULT CALLBACK SEHCatcher::SEHWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_COMMAND:
+ {
+ HWND hwndCtl = (HWND) lParam;
+ if (hwndCtl == mYesButtonWindow)
+ {
+ // Hide current window and bring up score submitting stuff
+ ShowWindow(hWnd, SW_HIDE);
+
+ ShowSubmitInfoDialog();
+ }
+ else if (hwndCtl == mNoButtonWindow)
+ {
+ mExiting = true;
+ }
+ else if (hwndCtl == mDebugButtonWindow)
+ {
+ mDebugError = true;
+ mExiting = true;
+ }
+ }
+ break;
+ case WM_CLOSE:
+ mExiting = true;
+ return 0;
+ }
+
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+LRESULT CALLBACK SEHCatcher::SubmitInfoWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_COMMAND:
+ {
+ HWND hwndCtl = (HWND) lParam;
+ if (hwndCtl == mYesButtonWindow)
+ {
+ // Hide current window and bring up score submitting stuff
+ ShowWindow(hWnd, SW_HIDE);
+
+ char aStr[8192];
+ GetWindowTextA(mEditWindow, aStr, 8192);
+ mUserText = aStr;
+
+ CreateProgressWindow();
+ _beginthread(SubmitReportThread, 0, 0);
+ }
+ else if (hwndCtl == mNoButtonWindow)
+ {
+ mExiting = true;
+ }
+ }
+ break;
+ case WM_CLOSE:
+ mExiting = true;
+ return 0;
+ }
+
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+void SEHCatcher::WriteToFile(const std::string& theErrorText)
+{
+ std::fstream aStream("crash.txt", std::ios::out);
+ aStream << theErrorText.c_str() << std::endl;
+}
+
+void SEHCatcher::SubmitReportThread(void *theArg)
+{
+ std::string aSeperator = "---------------------------7d3e1f30eec";
+
+ DefinesMap aSEHWebParams;
+
+ mApp->GetSEHWebParams(&aSEHWebParams);
+
+ std::string aContent;
+
+ DefinesMap::iterator anItr = aSEHWebParams.begin();
+ while (anItr != aSEHWebParams.end())
+ {
+ aContent += "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"" + anItr->first + "\"\r\n" +
+ "\r\n" +
+ anItr->second + "\r\n";
+
+ ++anItr;
+ }
+
+ aContent +=
+
+ /*"--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"username\"\r\n" +
+ "\r\n" +
+ mApp->mUserName + "\r\n" + */
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"prod\"\r\n" +
+ "\r\n" +
+ mApp->mProdName + "\r\n" +
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"version\"\r\n" +
+ "\r\n" +
+ mApp->mProductVersion + "\r\n" +
+
+ /*"--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"buildnum\"\r\n" +
+ "\r\n" +
+ StrFormat("%d", mApp->mBuildNum) + "\r\n" +
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"builddate\"\r\n" +
+ "\r\n" +
+ mApp->mBuildDate + "\r\n" +
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"referid\"\r\n" +
+ "\r\n" +
+ mApp->mReferId + "\r\n" +*/
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"usertext\"\r\n" +
+ "\r\n" +
+ mUserText + "\r\n" +
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"errortitle\"\r\n" +
+ "\r\n" +
+ mErrorTitle + "\r\n" +
+
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"errortext\"\r\n" +
+ "\r\n" +
+ mErrorText + "\r\n";
+
+ if (mHasDemoFile)
+ {
+ Buffer aBuffer;
+ mApp->ReadBufferFromFile(mUploadFileName, &aBuffer, true);
+
+ aContent +=
+ "--" + aSeperator + "\r\n"
+ "Content-Disposition: form-data; name=\"demofile\"; filename=\"popcap.dmo\"\r\n" +
+ "Content-Type: application/octet-stream\r\n" +
+ "\r\n";
+
+ aContent.insert(aContent.end(), (char*) aBuffer.GetDataPtr(), (char*) aBuffer.GetDataPtr() + aBuffer.GetDataLen());
+
+ aContent += "\r\n";
+ }
+
+ aContent +=
+ "--" + aSeperator + "--\r\n";
+
+ std::string aSendString =
+ "POST /deluxe_error.php HTTP/1.1\r\n"
+ "Content-Type: multipart/form-data; boundary=" + aSeperator + "\r\n"
+ "User-Agent: Mozilla/4.0 (compatible; popcap)\r\n" +
+ "Host: " + mSubmitHost + "\r\n" +
+ "Content-Length: " + StrFormat("%d", aContent.length()) + "\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" + aContent;
+
+ mSubmitReportTransfer.SendRequestString(mSubmitHost, aSendString);
+}
+
+void SEHCatcher::ShowSubmitInfoDialog()
+{
+ WNDCLASSA wc;
+ wc.style = 0;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = ::GetSysColorBrush(COLOR_BTNFACE);
+ wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = ::LoadIcon(NULL, IDI_ERROR);
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = SubmitInfoWindowProc;
+ wc.lpszClassName = "SubmitInfoWindow";
+ wc.lpszMenuName = NULL;
+ RegisterClassA(&wc);
+
+ RECT aRect;
+ aRect.left = 0;
+ aRect.top = 0;
+ aRect.right = 400;
+ aRect.bottom = 300;
+
+ DWORD aWindowStyle = WS_CLIPCHILDREN | WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
+
+ BOOL worked = AdjustWindowRect(&aRect, aWindowStyle, FALSE);
+
+ HWND aHWnd = CreateWindowA("SubmitInfoWindow", "Error Details",
+ aWindowStyle,
+ 64+16, 64+16,
+ aRect.right - aRect.left,
+ aRect.bottom - aRect.top,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+
+ HWND aLabelWindow = CreateWindowW(L"EDIT", mSubmitMessage.c_str(),
+
+ WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_READONLY,
+ 8, 8,
+ 400-8-8,
+ 84,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+
+ HDC aDC = ::GetDC(aLabelWindow);
+ int aFontHeight = -MulDiv(9, 96, 72);
+ ::ReleaseDC(aLabelWindow, aDC);
+ HFONT aBoldArialFont = CreateFontA(aFontHeight, 0, 0, 0, FW_BOLD, 0, 0,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Arial");
+
+ if (!gUseDefaultFonts)
+ SendMessage(aLabelWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ mEditWindow = CreateWindowA("EDIT", "",
+ WS_VISIBLE | WS_CHILD | ES_MULTILINE | WS_BORDER | WS_VSCROLL,
+ 8, 300-168-24-8-8,
+ 400-8-8,
+ 168,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+
+ aDC = ::GetDC(mEditWindow);
+ aFontHeight = -MulDiv(8, 96, 72);
+ ::ReleaseDC(mEditWindow, aDC);
+ HFONT aCourierNewFont = CreateFontA(aFontHeight, 0, 0, 0, FW_NORMAL, 0, 0,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Courier New");
+ if (!gUseDefaultFonts)
+ SendMessage(mEditWindow, WM_SETFONT, (WPARAM) mDialogFont, 0);
+ SetFocus(mEditWindow);
+
+ int aButtonWidth = (400 - 8 - 8 - 8) / 2;
+ int aCurX = 8;
+
+ aWindowStyle = WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON;
+
+ if (mApp == NULL)
+ aWindowStyle |= WS_DISABLED;
+
+ mYesButtonWindow = CreateWindowA("BUTTON", "Continue",
+ aWindowStyle,
+ aCurX, 300-24-8,
+ aButtonWidth,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(mYesButtonWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ aCurX += aButtonWidth+8;
+
+ mNoButtonWindow = CreateWindowA("BUTTON", "Abort",
+ WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON,
+ aCurX, 300-24-8,
+ aButtonWidth,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(mNoButtonWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ ShowWindow(aHWnd, SW_NORMAL);
+}
+
+void SEHCatcher::ShowErrorDialog(const std::string& theErrorTitle, const std::string& theErrorText)
+{
+ OSVERSIONINFO aVersionInfo;
+ aVersionInfo.dwOSVersionInfoSize = sizeof(aVersionInfo);
+ GetVersionEx(&aVersionInfo);
+
+ // Setting fonts on 98 causes weirdo crash things in GDI upon the second crash.
+ // That's no good.
+ gUseDefaultFonts = aVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT;
+
+ int aHeight = -MulDiv(8, 96, 72);
+ mDialogFont = ::CreateFontA(aHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
+
+ aHeight = -MulDiv(10, 96, 72);
+ mBoldFont = ::CreateFontA(aHeight, 0, 0, 0, FW_BOLD, FALSE, FALSE,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
+
+ ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
+
+ mErrorTitle = theErrorTitle;
+ mErrorText = theErrorText;
+
+
+ WNDCLASSA wc;
+ wc.style = 0;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = ::GetSysColorBrush(COLOR_BTNFACE);
+ wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = ::LoadIcon(NULL, IDI_ERROR);
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = SEHWindowProc;
+ wc.lpszClassName = "SEHWindow";
+ wc.lpszMenuName = NULL;
+ RegisterClassA(&wc);
+
+ RECT aRect;
+ aRect.left = 0;
+ aRect.top = 0;
+ aRect.right = 400;
+ aRect.bottom = 300;
+
+ DWORD aWindowStyle = WS_CLIPCHILDREN | WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
+
+ BOOL worked = AdjustWindowRect(&aRect, aWindowStyle, FALSE);
+
+ HWND aHWnd = CreateWindowW(L"SEHWindow", L"Fatal Error!",
+ aWindowStyle,
+ 64, 64,
+ aRect.right - aRect.left,
+ aRect.bottom - aRect.top,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+
+ HWND aLabelWindow = CreateWindowW(L"EDIT",
+ mCrashMessage.c_str(),
+ WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_READONLY,
+ 8, 8,
+ 400-8-8,
+ 84,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+
+ int aFontHeight = -MulDiv(9, 96, 72);
+ HFONT aBoldArialFont = CreateFontA(aFontHeight, 0, 0, 0, FW_BOLD, 0, 0,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Arial");
+
+ if (!gUseDefaultFonts)
+ SendMessage(aLabelWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ HWND anEditWindow = CreateWindowA("EDIT", theErrorText.c_str(),
+ WS_VISIBLE | WS_CHILD | ES_MULTILINE | WS_BORDER | WS_VSCROLL | ES_READONLY,
+ 8, 300-168-24-8-8,
+ 400-8-8,
+ 168,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+
+ aFontHeight = -MulDiv(8, 96, 72);
+ HFONT aCourierNewFont = CreateFontA(aFontHeight, 0, 0, 0, FW_NORMAL, 0, 0,
+ false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, "Courier New");
+ if (!gUseDefaultFonts)
+ SendMessage(anEditWindow, WM_SETFONT, (WPARAM) aCourierNewFont, 0);
+
+ aWindowStyle = WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON;
+
+ if (mApp == NULL)
+ aWindowStyle |= WS_DISABLED;
+
+#ifdef _DEBUG
+ bool doDebugButton = true;
+#else
+ bool doDebugButton = false;
+#endif
+
+ bool canSubmit = mAllowSubmit && !mSubmitHost.empty();
+ int aNumButtons = 1 + (doDebugButton ? 1 : 0) + (canSubmit ? 1 : 0);
+
+ int aButtonWidth = (400 - 8 - 8 - (aNumButtons - 1)*8) / aNumButtons;
+
+ int aCurX = 8;
+
+ if (canSubmit)
+ {
+ mYesButtonWindow = CreateWindowA("BUTTON", "Send Report",
+ aWindowStyle,
+ aCurX, 300-24-8,
+ aButtonWidth,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(mYesButtonWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ aCurX += aButtonWidth + 8;
+ }
+
+ if (doDebugButton)
+ {
+ mDebugButtonWindow = CreateWindowA("BUTTON", "Debug",
+ aWindowStyle,
+ aCurX, 300-24-8,
+ aButtonWidth,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+ if (!gUseDefaultFonts)
+ SendMessage(mDebugButtonWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ aCurX += aButtonWidth + 8;
+ }
+
+ mNoButtonWindow = CreateWindowA("BUTTON", "Close Now",
+ WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON,
+ aCurX, 300-24-8,
+ aButtonWidth,
+ 24,
+ aHWnd,
+ NULL,
+ gHInstance,
+ 0);
+
+ if (!gUseDefaultFonts)
+ SendMessage(mNoButtonWindow, WM_SETFONT, (WPARAM) aBoldArialFont, 0);
+
+ ShowWindow(aHWnd, SW_NORMAL);
+
+ MSG msg;
+ while ((GetMessage(&msg, NULL, 0, 0) > 0) && (!mExiting))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ DestroyWindow(aHWnd);
+
+ DeleteObject(mDialogFont);
+ DeleteObject(mBoldFont);
+ DeleteObject(aBoldArialFont);
+ DeleteObject(aCourierNewFont);
+}
+
+std::string SEHCatcher::GetSysInfo()
+{
+ std::string aDebugDump;
+
+ OSVERSIONINFOA aVersionInfo;
+ aVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionExA(&aVersionInfo);
+
+ aDebugDump += "Windows Ver: ";
+ if (aVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
+ aDebugDump += "NT ";
+ else
+ aDebugDump += "9x ";
+
+ char aVersionStr[20];
+ sprintf(aVersionStr, "%d.%d", aVersionInfo.dwMajorVersion, aVersionInfo.dwMinorVersion);
+ aDebugDump += aVersionStr;
+ aDebugDump += " ";
+ aDebugDump += aVersionInfo.szCSDVersion;
+ aDebugDump += " ";
+ sprintf(aVersionStr, "%d", aVersionInfo.dwBuildNumber);
+ aDebugDump += "Build ";
+ aDebugDump += aVersionStr;
+ aDebugDump += "\r\n";
+
+ HMODULE aMod;
+ char aPath[256];
+
+ if (mApp != NULL)
+ {
+ aMod = LoadLibraryA("ddraw.dll");
+ if (aMod != NULL)
+ {
+ GetModuleFileNameA(aMod, aPath, 256);
+ aDebugDump += "DDraw Ver: " + mApp->GetProductVersion(aPath) + "\r\n";
+ FreeLibrary(aMod);
+ }
+
+ aMod = LoadLibraryA("dsound.dll");
+ if (aMod != NULL)
+ {
+ GetModuleFileNameA(aMod, aPath, 256);
+ aDebugDump += "DSound Ver: " + mApp->GetProductVersion(aPath) + "\r\n";
+ FreeLibrary(aMod);
+ }
+ }
+
+ return aDebugDump;
+}
+
diff --git a/osframework/source/SexyAppFramework/SEHCatcher.h b/osframework/source/SexyAppFramework/SEHCatcher.h
new file mode 100644
index 0000000..111e9da
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SEHCatcher.h
@@ -0,0 +1,97 @@
+#ifndef __SEHCATHER_H__
+#define __SEHCATHER_H__
+
+#include "Common.h"
+#include "HTTPTransfer.h"
+#include <imagehlp.h>
+
+namespace Sexy
+{
+
+class SexyAppBase;
+
+typedef BOOL (__stdcall * SYMINITIALIZEPROC)(HANDLE, LPSTR, BOOL);
+
+typedef DWORD (__stdcall *SYMSETOPTIONSPROC)(DWORD);
+
+typedef BOOL (__stdcall *SYMCLEANUPPROC)(HANDLE);
+
+typedef LPCSTR (__stdcall *UNDECORATESYMBOLNAMEPROC)(LPCSTR, LPSTR, DWORD, DWORD);
+
+typedef BOOL (__stdcall * STACKWALKPROC)
+ ( DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID,
+ PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
+ PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE);
+
+typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESSPROC)(HANDLE, DWORD);
+
+typedef DWORD (__stdcall *SYMGETMODULEBASEPROC)(HANDLE, DWORD);
+
+typedef BOOL (__stdcall *SYMGETSYMFROMADDRPROC)(HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL);
+
+class SEHCatcher
+{
+public:
+ static SexyAppBase* mApp;
+ static HFONT mDialogFont;
+ static HFONT mBoldFont;
+ static HWND mYesButtonWindow;
+ static HWND mNoButtonWindow;
+ static HWND mDebugButtonWindow;
+ static HWND mEditWindow;
+ static bool mHasDemoFile;
+ static bool mDebugError;
+ static std::string mErrorTitle;
+ static std::string mErrorText;
+ static std::string mUserText;
+ static std::string mUploadFileName;
+ static std::wstring mCrashMessage;
+ static std::string mSubmitHost;
+ static std::wstring mSubmitErrorMessage;
+ static std::wstring mSubmitMessage;
+ static HMODULE mImageHelpLib;
+ static SYMINITIALIZEPROC mSymInitialize;
+ static SYMSETOPTIONSPROC mSymSetOptions;
+ static UNDECORATESYMBOLNAMEPROC mUnDecorateSymbolName;
+ static SYMCLEANUPPROC mSymCleanup;
+ static STACKWALKPROC mStackWalk;
+ static SYMFUNCTIONTABLEACCESSPROC mSymFunctionTableAccess;
+ static SYMGETMODULEBASEPROC mSymGetModuleBase;
+ static SYMGETSYMFROMADDRPROC mSymGetSymFromAddr;
+ static HTTPTransfer mSubmitReportTransfer;
+ static bool mExiting;
+ static bool mShowUI;
+ static bool mAllowSubmit;
+
+protected:
+ static LPTOP_LEVEL_EXCEPTION_FILTER mPreviousFilter;
+
+public:
+ static void SubmitReportThread(void *theArg);
+
+ static LRESULT CALLBACK SEHWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static LRESULT CALLBACK SubmitInfoWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static long __stdcall UnhandledExceptionFilter(LPEXCEPTION_POINTERS lpExceptPtr);
+ static void DoHandleDebugEvent(LPEXCEPTION_POINTERS lpEP);
+ static bool GetLogicalAddress(void* addr, char* szModule, DWORD len, DWORD& section, DWORD& offset);
+ static std::string GetFilename(const std::string& thePath);
+ static void WriteToFile(const std::string& theErrorText);
+ static void ShowSubmitInfoDialog();
+ static void ShowErrorDialog(const std::string& theErrorTitle, const std::string& theErrorText);
+ static bool LoadImageHelp();
+ static void UnloadImageHelp();
+ static std::string IntelWalk(PCONTEXT theContext, int theSkipCount);
+ static std::string ImageHelpWalk(PCONTEXT theContext, int theSkipCount);
+ static std::string GetSysInfo();
+ static void GetSymbolsFromMapFile(std::string &theDebugDump);
+
+public:
+ SEHCatcher();
+ ~SEHCatcher();
+};
+
+extern SEHCatcher gSEHCatcher;
+
+}
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SWTri.cpp b/osframework/source/SexyAppFramework/SWTri.cpp
new file mode 100644
index 0000000..362caed
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri.cpp
@@ -0,0 +1,658 @@
+#pragma warning(disable:4244 4305 4309)
+
+#include "SWTri.h"
+#include "Debug.h"
+
+using namespace Sexy;
+
+static SWHelper::XYZStruct vertexReservoir[64];
+static unsigned int vertexReservoirUsed = 0;
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+static int FixedFloor(int x)
+{
+ if (x>0)
+ return x&0xFFFF0000;
+ else
+ return (x&0xFFFF0000)-0x10000;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// ********************* BEGIN CLIPPING STUFF *********************************************************************
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+static inline void lClip(SWHelper::XYZStruct & dst, const SWHelper::XYZStruct & on, const SWHelper::XYZStruct & off, const float edge)
+{
+ float delta = (edge - off.mX) / (on.mX - off.mX);
+ dst.mX = off.mX + (on.mX - off.mX) * delta;
+ dst.mY = off.mY + (on.mY - off.mY) * delta;
+ dst.mU = off.mU + (on.mU - off.mU) * delta;
+ dst.mV = off.mV + (on.mV - off.mV) * delta;
+ dst.mDiffuse = ((int) ((((off.mDiffuse >> 24)&0xff) + (((on.mDiffuse >> 24)&0xff) - ((off.mDiffuse >> 24)&0xff)) * delta))<<24) |
+ ((int) ((((off.mDiffuse >> 16)&0xff) + (((on.mDiffuse >> 16)&0xff) - ((off.mDiffuse >> 16)&0xff)) * delta))<<16) |
+ ((int) ((((off.mDiffuse >> 8)&0xff) + (((on.mDiffuse >> 8)&0xff) - ((off.mDiffuse >> 8)&0xff)) * delta))<<8 ) |
+ ((int) ((((off.mDiffuse >> 0)&0xff) + (((on.mDiffuse >> 0)&0xff) - ((off.mDiffuse >> 0)&0xff)) * delta)) );
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline void rClip(SWHelper::XYZStruct & dst, const SWHelper::XYZStruct & on, const SWHelper::XYZStruct & off, const float edge)
+{
+ float delta = (edge - off.mX) / (on.mX - off.mX);
+ dst.mX = off.mX + (on.mX - off.mX) * delta;
+ dst.mY = off.mY + (on.mY - off.mY) * delta;
+ dst.mU = off.mU + (on.mU - off.mU) * delta;
+ dst.mV = off.mV + (on.mV - off.mV) * delta;
+ dst.mDiffuse = ((int) ((((off.mDiffuse >> 24)&0xff) + (((on.mDiffuse >> 24)&0xff) - ((off.mDiffuse >> 24)&0xff)) * delta))<<24) |
+ ((int) ((((off.mDiffuse >> 16)&0xff) + (((on.mDiffuse >> 16)&0xff) - ((off.mDiffuse >> 16)&0xff)) * delta))<<16) |
+ ((int) ((((off.mDiffuse >> 8)&0xff) + (((on.mDiffuse >> 8)&0xff) - ((off.mDiffuse >> 8)&0xff)) * delta))<<8 ) |
+ ((int) ((((off.mDiffuse >> 0)&0xff) + (((on.mDiffuse >> 0)&0xff) - ((off.mDiffuse >> 0)&0xff)) * delta)) );
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline void tClip(SWHelper::XYZStruct & dst, const SWHelper::XYZStruct & on, const SWHelper::XYZStruct & off, const float edge)
+{
+ float delta = (edge - off.mY) / (on.mY - off.mY);
+ dst.mX = off.mX + (on.mX - off.mX) * delta;
+ dst.mY = off.mY + (on.mY - off.mY) * delta;
+ dst.mU = off.mU + (on.mU - off.mU) * delta;
+ dst.mV = off.mV + (on.mV - off.mV) * delta;
+ dst.mDiffuse = ((int) ((((off.mDiffuse >> 24)&0xff) + (((on.mDiffuse >> 24)&0xff) - ((off.mDiffuse >> 24)&0xff)) * delta))<<24) |
+ ((int) ((((off.mDiffuse >> 16)&0xff) + (((on.mDiffuse >> 16)&0xff) - ((off.mDiffuse >> 16)&0xff)) * delta))<<16) |
+ ((int) ((((off.mDiffuse >> 8)&0xff) + (((on.mDiffuse >> 8)&0xff) - ((off.mDiffuse >> 8)&0xff)) * delta))<<8 ) |
+ ((int) ((((off.mDiffuse >> 0)&0xff) + (((on.mDiffuse >> 0)&0xff) - ((off.mDiffuse >> 0)&0xff)) * delta)) );
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline void bClip(SWHelper::XYZStruct & dst, const SWHelper::XYZStruct & on, const SWHelper::XYZStruct & off, const float edge)
+{
+ float delta = (edge - off.mY) / (on.mY - off.mY);
+ dst.mX = off.mX + (on.mX - off.mX) * delta;
+ dst.mY = off.mY + (on.mY - off.mY) * delta;
+ dst.mU = off.mU + (on.mU - off.mU) * delta;
+ dst.mV = off.mV + (on.mV - off.mV) * delta;
+ dst.mDiffuse = ((int) ((((off.mDiffuse >> 24)&0xff) + (((on.mDiffuse >> 24)&0xff) - ((off.mDiffuse >> 24)&0xff)) * delta))<<24) |
+ ((int) ((((off.mDiffuse >> 16)&0xff) + (((on.mDiffuse >> 16)&0xff) - ((off.mDiffuse >> 16)&0xff)) * delta))<<16) |
+ ((int) ((((off.mDiffuse >> 8)&0xff) + (((on.mDiffuse >> 8)&0xff) - ((off.mDiffuse >> 8)&0xff)) * delta))<<8 ) |
+ ((int) ((((off.mDiffuse >> 0)&0xff) + (((on.mDiffuse >> 0)&0xff) - ((off.mDiffuse >> 0)&0xff)) * delta)) );
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline unsigned int leClip(SWHelper::XYZStruct ** src, SWHelper::XYZStruct ** dst, const float edge)
+{
+ SWHelper::XYZStruct ** _dst = dst;
+
+ for (SWHelper::XYZStruct ** v = src; *v; ++v)
+ {
+ SWHelper::XYZStruct * cur = *v;
+ SWHelper::XYZStruct * nex = *(v+1) ? *(v+1):*src;
+
+ switch((cur->mX < edge ? 1:0)|(nex->mX < edge ? 2:0))
+ {
+ case 0:
+ *dst = *v;
+ ++dst;
+ break;
+ case 1:
+ {
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ lClip(tmp, *nex, *cur, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ case 2:
+ {
+ *dst = *v;
+ ++dst;
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ lClip(tmp, *cur, *nex, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ }
+ }
+ *dst = 0;
+ return static_cast<int>(dst - _dst);
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline unsigned int reClip(SWHelper::XYZStruct ** src, SWHelper::XYZStruct ** dst, const float edge)
+{
+ SWHelper::XYZStruct ** _dst = dst;
+
+ for (SWHelper::XYZStruct ** v = src; *v; ++v)
+ {
+ SWHelper::XYZStruct * cur = *v;
+ SWHelper::XYZStruct * nex = *(v+1) ? *(v+1):*src;
+
+ switch((cur->mX > edge ? 1:0)|(nex->mX > edge ? 2:0))
+ {
+ case 0:
+ *dst = *v;
+ ++dst;
+ break;
+ case 1:
+ {
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ rClip(tmp, *nex, *cur, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ case 2:
+ {
+ *dst = *v;
+ ++dst;
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ rClip(tmp, *cur, *nex, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ }
+ }
+ *dst = 0;
+ return static_cast<int>(dst - _dst);
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline unsigned int teClip(SWHelper::XYZStruct ** src, SWHelper::XYZStruct ** dst, const float edge)
+{
+ SWHelper::XYZStruct ** _dst = dst;
+
+ for (SWHelper::XYZStruct ** v = src; *v; ++v)
+ {
+ SWHelper::XYZStruct * cur = *v;
+ SWHelper::XYZStruct * nex = *(v+1) ? *(v+1):*src;
+
+ switch((cur->mY < edge ? 1:0)|(nex->mY < edge ? 2:0))
+ {
+ case 0:
+ *dst = *v;
+ ++dst;
+ break;
+ case 1:
+ {
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ tClip(tmp, *nex, *cur, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ case 2:
+ {
+ *dst = *v;
+ ++dst;
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ tClip(tmp, *cur, *nex, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ }
+ }
+ *dst = 0;
+ return static_cast<int>(dst - _dst);
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline unsigned int beClip(SWHelper::XYZStruct ** src, SWHelper::XYZStruct ** dst, const float edge)
+{
+ SWHelper::XYZStruct ** _dst = dst;
+
+ for (SWHelper::XYZStruct ** v = src; *v; ++v)
+ {
+ SWHelper::XYZStruct * cur = *v;
+ SWHelper::XYZStruct * nex = *(v+1) ? *(v+1):*src;
+
+ switch((cur->mY > edge ? 1:0)|(nex->mY > edge ? 2:0))
+ {
+ case 0:
+ *dst = *v;
+ ++dst;
+ break;
+ case 1:
+ {
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ bClip(tmp, *nex, *cur, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ case 2:
+ {
+ *dst = *v;
+ ++dst;
+ SWHelper::XYZStruct & tmp = vertexReservoir[vertexReservoirUsed++];
+ bClip(tmp, *cur, *nex, edge);
+ *dst = &tmp;
+ ++dst;
+ break;
+ }
+ }
+ }
+ *dst = 0;
+ return static_cast<int>(dst - _dst);
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------
+
+static inline int clipShape(SWHelper::XYZStruct ** dst, SWHelper::XYZStruct ** src, const float left, const float right, const float top, const float bottom)
+{
+ vertexReservoirUsed = 0;
+
+ SWHelper::XYZStruct * buf[64];
+ SWHelper::XYZStruct * ptr[4];
+ ptr[0] = src[0];
+ ptr[1] = src[1];
+ ptr[2] = src[2];
+ ptr[3] = 0;
+ if (leClip(ptr, buf, left) < 3) return 0;
+ if (reClip(buf, dst, right) < 3) return 0;
+ if (teClip(dst, buf, top) < 3) return 0;
+ return beClip(buf, dst, bottom);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// ********************* END CLIPPING STUFF ***********************************************************************
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+void SWHelper::SWDrawShape(XYZStruct *theVerts, int theNumVerts, MemoryImage *theImage, const Color &theColor, int theDrawMode, const Rect &theClipRect, void *theSurface, int thePitch, int thePixelFormat, bool blend, bool vertexColor)
+{
+ float tclx0 = theClipRect.mX;
+ float tcly0 = theClipRect.mY;
+ float tclx1 = theClipRect.mX + theClipRect.mWidth - 1;
+ float tcly1 = theClipRect.mY + theClipRect.mHeight - 1;
+
+ //
+ // Okay, now we're gonna render. We have the vertex list.
+ // mSWRenderPtr is a char* pointer to the upper left
+ // bit of the of render array.
+ //
+ struct XYZStruct *aTVertPtr=theVerts;
+
+ //
+ // Some notes:
+ //
+ // If mSWTexture==NULL, no texture is selected and pure white can be substituted (clipped to
+ // the current material color).
+ //
+ // If mAlphaMode!=mAlphaModeOn, then there's no need to do any alpha rendering, period.
+ // All alpha, even in textures with it, should be ignored. Otherwise, Alpha basically
+ // boils down to: texture pixel alpha * mClippedMaterial.diffuse.a
+ //
+ // The current material is stored in mClippedMaterial. You only need to ref the
+ // diffuse color:
+ // mClippedMaterial.diffuse.a
+ // mClippedMaterial.diffuse.r
+ // mClippedMaterial.diffuse.g
+ // mClippedMaterial.diffuse.b
+ //
+ // The triangle cull can one one of three things:
+ // mCullMode=mCullModeNone (cull no triangles)
+ // mCullMode=mCullModeCW (cull CW triangles)
+ // mCullMode=mCullModeCCW (cull CCW triangles)
+ //
+ // Texture clamping
+ // For this implementation, all uv coordinates will be between 0-1. However, in DirectX, it
+ // is sometimes necessary to clamp textures in order to prevent pixel bleed. So, though you
+ // won't need to implement any texture clamping, please put a few notes in for us so that we
+ // can later flesh it out if we decide the software renderer is fast enough to handle something
+ // like Hamsterball.
+ //
+ // Clipping
+ // There is a RECT structure defined called mClipArea. Rect is x,y,width,height -- it's NOT in
+ // x1,y1,x2,y2 format. Anything outside of that rect should just not be clipped. If you decide
+ // it's easier to clip against clip planes using a transform, then please scroll up to look at
+ // the Clip() functions-- they translate the coordinates into clip planes.
+ // SPECIAL NOTE: The clipping is in "absolute" coordinates. It is not in a 640x480 capable
+ // format. Our framework allows us to specify a 'real' resolution to use, and conforms everything
+ // down to whatever the screen is displaying. So, we usually use 800x600 for absolute resolution in
+ // game.
+ //
+ // So, to turn the clip rectangle into the "screen resolution" from "page resolution" (page is what
+ // we work in, screen is what displays), multiply the rectangle member variables by mPageWidthAdjust
+ // and mPageHeightAdjust.
+ //
+ // "Game" coordinates to "Screen" coordinates:
+ // int aLeft=mClipArea.mX*mPageWidthAdjust;
+ // int aTop=mClipArea.mY*mPageHeightAdjust;
+ // int aRight=(mClipArea.mX+mClipArea.mSWTexture->mTextureInfo.dwWidth)*mPageWidthAdjust;
+ // int aBottom=(mClipArea.mY+mClipArea.mSWTexture->mTextureInfo.dwHeight)*mPageHeightAdjust;
+ //
+ // Another note: it *is* possible for the clip area to be bigger than the screen (for various
+ // reasons). So, a final clip to 0,0-mSWTexture->mTextureInfo.dwWidth,mSWTexture->mTextureInfo.dwHeight is necessary when translating vertices.
+ //
+
+ //
+ // Render the actual triangle strip.
+ //
+ int aTriCounter=0;
+ bool aOddTriangle=false;
+
+ // Our global diffuse value
+
+ SWDiffuse globalDiffuse;
+ {
+ globalDiffuse.a = theColor.mAlpha;
+ globalDiffuse.r = theColor.mRed;
+ globalDiffuse.g = theColor.mGreen;
+ globalDiffuse.b = theColor.mBlue;
+ }
+
+ // rendering flags
+
+ bool globalargb = theColor!=Color::White;
+
+ if (theImage)
+ theImage->CommitBits();
+
+ bool textured = theImage!=NULL;
+ bool talpha = (textured && (theImage->mHasAlpha || theImage->mHasTrans || blend));
+
+ for (;;)
+ {
+ //
+ // Triangle strips... vertices go:
+ // 1-2-3 2-4-3 3-4-5 4-6-5 ... every other triangle
+ // swaps #2 & #3 vertices for draw to maintain clockwise order.
+ //
+ if (aTriCounter+3>theNumVerts) break;
+
+ //
+ // Picking triangle direction for culling...
+ //
+ struct XYZStruct *aTriRef[64];
+ if (!aOddTriangle)
+ {
+ aTriRef[0]=aTVertPtr;
+ aTriRef[1]=aTVertPtr+1;
+ aTriRef[2]=aTVertPtr+2;
+ }
+ else
+ {
+ aTriRef[0]=aTVertPtr;
+ aTriRef[1]=aTVertPtr+2;
+ aTriRef[2]=aTVertPtr+1;
+ }
+ aTriRef[3] = 0;
+
+ // Clip
+
+ XYZStruct * clipped[64];
+ float clipX0 = tclx0;
+ float clipY0 = tcly0;
+ float clipX1 = tclx1;
+ float clipY1 = tcly1;
+
+ unsigned int vCount = clipShape(clipped, aTriRef, clipX0, clipX1, clipY0, clipY1);
+
+ if (vCount)
+ {
+ unsigned int * pFrameBuffer = reinterpret_cast<unsigned int *>(theSurface);
+ SWVertex pVerts[64];
+ SWTextureInfo textureInfo;
+
+ for (unsigned int i = 0; i < vCount; ++i)
+ {
+ pVerts[i].x = static_cast<int>(clipped[i]->mX * 65536.0f);
+ pVerts[i].y = static_cast<int>(clipped[i]->mY * 65536.0f);
+ }
+
+ if (textured)
+ {
+ for (unsigned int i = 0; i < vCount; ++i)
+ {
+ pVerts[i].u = static_cast<int>(clipped[i]->mU * (float) theImage->mWidth * 65536.0f);
+ pVerts[i].v = static_cast<int>(clipped[i]->mV * (float) theImage->mHeight * 65536.0f);
+ }
+
+ textureInfo.pTexture = reinterpret_cast<unsigned int *>(theImage->GetBits());
+ textureInfo.pitch = theImage->mWidth;
+ textureInfo.height = theImage->mHeight;
+ textureInfo.endpos = theImage->mWidth*theImage->mHeight;
+// unsigned int temp = static_cast<unsigned int>(mSWTexture->mTextureInfo.lPitch) / (mSWTexture->mTextureInfo.ddpfPixelFormat.dwRGBBitCount / 8);
+ unsigned int temp = theImage->mWidth;
+ temp >>= 1;
+ textureInfo.vShift = 0;
+ while(temp) {textureInfo.vShift += 1; temp >>= 1;}
+ textureInfo.vShift = 16 - textureInfo.vShift;
+
+ textureInfo.uMask = static_cast<unsigned int>(theImage->mWidth - 1) << 16;
+ textureInfo.vMask = static_cast<unsigned int>(theImage->mHeight - 1) << 16;
+ }
+
+ if (vertexColor)
+ {
+ for (unsigned int i = 0; i < vCount; ++i)
+ {
+ pVerts[i].a = (clipped[i]->mDiffuse >> 8) & 0xff0000;
+ pVerts[i].r = (clipped[i]->mDiffuse >> 0) & 0xff0000;
+ pVerts[i].g = (clipped[i]->mDiffuse << 8) & 0xff0000;
+ pVerts[i].b = (clipped[i]->mDiffuse << 16) & 0xff0000;
+ }
+ }
+
+ SWDrawTriangle(textured, talpha, vertexColor, globalargb, pVerts, pFrameBuffer, thePitch, &textureInfo, globalDiffuse, thePixelFormat, blend);
+
+ if (vCount > 3)
+ {
+ for (unsigned int extraVert = 2; extraVert < vCount-1; ++extraVert)
+ {
+ pVerts[1] = pVerts[extraVert];
+ pVerts[2] = pVerts[extraVert+1];
+ SWDrawTriangle(textured, talpha, vertexColor, globalargb, pVerts, pFrameBuffer, thePitch, &textureInfo, globalDiffuse, thePixelFormat, blend);
+ }
+ }
+ }
+
+ aTVertPtr++;
+ aTriCounter++;
+ aOddTriangle=!aOddTriangle;
+ }
+}
+
+
+static DrawTriFunc gDrawTriFunc[128] = {0};
+void Sexy::SWTri_AddDrawTriFunc(bool textured, bool talpha, bool mod_argb, bool global_argb, int thePixelFormat, bool blend, DrawTriFunc theFunc)
+{
+ int aType = (blend?1:0) | (global_argb?2:0) | (mod_argb?4:0) | (talpha?8:0) | (textured?16:0);
+ switch (thePixelFormat)
+ {
+ case 0x8888: aType |= 0<<5; break;
+ case 0x888: aType |= 1<<5; break;
+ case 0x565: aType |= 2<<5; break;
+ case 0x555: aType |= 3<<5; break;
+ }
+ gDrawTriFunc[aType] = theFunc;
+}
+
+void Sexy::SWTri_AddAllDrawTriFuncs()
+{
+ gDrawTriFunc[0] = DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[1] = DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[2] = DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[3] = DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[4] = DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[5] = DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[6] = DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[7] = DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[8] = DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[9] = DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[10] = DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[11] = DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[12] = DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[13] = DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[14] = DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[15] = DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[16] = DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[17] = DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[18] = DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[19] = DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[20] = DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[21] = DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[22] = DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[23] = DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[24] = DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[25] = DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[26] = DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[27] = DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[28] = DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[29] = DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[30] = DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[31] = DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[32] = DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[33] = DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[34] = DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[35] = DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[36] = DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[37] = DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[38] = DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[39] = DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[40] = DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[41] = DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[42] = DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[43] = DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[44] = DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[45] = DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[46] = DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[47] = DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[48] = DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[49] = DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[50] = DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[51] = DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[52] = DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[53] = DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[54] = DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[55] = DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[56] = DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[57] = DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[58] = DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[59] = DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[60] = DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[61] = DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[62] = DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[63] = DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[64] = DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[65] = DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[66] = DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[67] = DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[68] = DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[69] = DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[70] = DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[71] = DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[72] = DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[73] = DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[74] = DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[75] = DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[76] = DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[77] = DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[78] = DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[79] = DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[80] = DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[81] = DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[82] = DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[83] = DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[84] = DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[85] = DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[86] = DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[87] = DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[88] = DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[89] = DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[90] = DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[91] = DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[92] = DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[93] = DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[94] = DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[95] = DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[96] = DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[97] = DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[98] = DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[99] = DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[100] = DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[101] = DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[102] = DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[103] = DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[104] = DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[105] = DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[106] = DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[107] = DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[108] = DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[109] = DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[110] = DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[111] = DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[112] = DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[113] = DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[114] = DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[115] = DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[116] = DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[117] = DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[118] = DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[119] = DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND1;
+ gDrawTriFunc[120] = DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND0;
+ gDrawTriFunc[121] = DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND1;
+ gDrawTriFunc[122] = DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND0;
+ gDrawTriFunc[123] = DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND1;
+ gDrawTriFunc[124] = DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND0;
+ gDrawTriFunc[125] = DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND1;
+ gDrawTriFunc[126] = DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND0;
+ gDrawTriFunc[127] = DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND1;
+}
+
+#include "SWTri_DrawTriangleInc1.cpp"
+
+void SWHelper::SWDrawTriangle(bool textured, bool talpha, bool mod_argb, bool global_argb, SWVertex * pVerts, unsigned int * pFrameBuffer, const unsigned int bytepitch, const SWTextureInfo * textureInfo, SWDiffuse & globalDiffuse, int thePixelFormat, bool blend)
+{
+ int aType = (blend?1:0) | (global_argb?2:0) | (mod_argb?4:0) | (talpha?8:0) | (textured?16:0);
+ switch (thePixelFormat)
+ {
+ case 0x8888: aType |= 0<<5; break;
+ case 0x888: aType |= 1<<5; break;
+ case 0x565: aType |= 2<<5; break;
+ case 0x555: aType |= 3<<5; break;
+ }
+ DrawTriFunc aFunc = gDrawTriFunc[aType];
+ if (aFunc==NULL)
+ {
+ DBG_ASSERT("You need to call SWTri_AddDrawTriFunc or SWTri_AddAllDrawTriFuncs"==NULL);
+ }
+ else
+ aFunc(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse);
+
+// #include "SWTri_DrawTriangleInc2.cpp"
+}
+
+
diff --git a/osframework/source/SexyAppFramework/SWTri.h b/osframework/source/SexyAppFramework/SWTri.h
new file mode 100644
index 0000000..694e3a2
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri.h
@@ -0,0 +1,184 @@
+#pragma once
+
+#include "Color.h"
+#include "MemoryImage.h"
+#include "Rect.h"
+#include "SexyMatrix.h"
+
+namespace Sexy
+{
+
+class SWHelper
+{
+public:
+ struct XYZStruct
+ {
+ float mX;
+ float mY;
+ float mU;
+ float mV;
+ long mDiffuse;
+ };
+
+ struct SWVertex
+ {
+ int x, y;
+ int a, r, g, b;
+ int u, v;
+ };
+ struct SWTextureInfo
+ {
+ const unsigned int * pTexture;
+ unsigned int vShift, uMask, vMask;
+ int pitch;
+ unsigned int endpos;
+ int height;
+ };
+ struct SWDiffuse
+ {
+ unsigned int a, r, g, b;
+ };
+
+ typedef __int64 signed64;
+
+public:
+ // For drawing
+ static void SWDrawShape(XYZStruct *theVerts, int theNumVerts, MemoryImage *theImage, const Color &theColor, int theDrawMode, const Rect &theClipRect, void *theSurface, int thePitch, int thePixelFormat, bool blend, bool vertexColor);
+ static void SWDrawTriangle(bool textured, bool talpha, bool mod_argb, bool global_argb, SWVertex * pVerts, unsigned int * pFrameBuffer, const unsigned int pitch, const SWTextureInfo * textureInfo, SWDiffuse & globalDiffuse, int thePixelFormat, bool blend);
+};
+
+typedef void(*DrawTriFunc)(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+void SWTri_AddAllDrawTriFuncs();
+void SWTri_AddDrawTriFunc(bool textured, bool talpha, bool mod_argb, bool global_argb, int thePixelFormat, bool blend, DrawTriFunc theFunc);
+
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+extern void DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse);
+
+} // namespace Sexy
+
diff --git a/osframework/source/SexyAppFramework/SWTri_DrawTriangle.cpp b/osframework/source/SexyAppFramework/SWTri_DrawTriangle.cpp
new file mode 100644
index 0000000..429fec3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_DrawTriangle.cpp
@@ -0,0 +1,278 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+#pragma warning(disable:4101)
+
+#if (TRI0==0)
+ #define PTYPE unsigned long
+ #define PIXEL_INCLUDE "SWTri_Pixel8888.cpp"
+ #define NAME0 8888
+#elif (TRI0==1)
+ #define PTYPE unsigned long
+ #define PIXEL_INCLUDE "SWTri_Pixel888.cpp"
+ #define NAME0 0888
+#elif (TRI0==2)
+ #define PTYPE unsigned short
+ #define PIXEL_INCLUDE "SWTri_Pixel565.cpp"
+ #define NAME0 0565
+#elif (TRI0==3)
+ #define PTYPE unsigned short
+ #define PIXEL_INCLUDE "SWTri_Pixel555.cpp"
+ #define NAME0 0555
+#endif
+
+#if (TRI1==1)
+ #define TEXTURED
+ #define NAME1 TEX1
+#else
+ #define NAME1 TEX0
+#endif
+
+
+#if (TRI2==1)
+ #define TEX_ALPHA
+ #define NAME2 TALPHA1
+#else
+ #define NAME2 TALPHA0
+#endif
+
+#if (TRI3==1)
+ #define MOD_ARGB
+ #define NAME3 MOD1
+#else
+ #define NAME3 MOD0
+#endif
+
+#if (TRI4==1)
+ #define GLOBAL_ARGB
+ #define NAME4 GLOB1
+#else
+ #define NAME4 GLOB0
+#endif
+
+#if (TRI5==1)
+ #define LINEAR_BLEND
+ #define NAME5 BLEND1
+#else
+ #define NAME5 BLEND0
+#endif
+
+#define funcname2(t0,t1,t2,t3,t4,t5) DrawTriangle_##t0##_##t1##_##t2##_##t3##_##t4##_##t5
+#define funcname1(t0,t1,t2,t3,t4,t5) funcname2(t0,t1,t2,t3,t4,t5)
+#define funcname funcname1(NAME0,NAME1,NAME2,NAME3,NAME4,NAME5)
+void Sexy::funcname(SWHelper::SWVertex * pVerts, void * pFrameBuffer, const unsigned int bytepitch, const SWHelper::SWTextureInfo * textureInfo, SWHelper::SWDiffuse & globalDiffuse)
+{
+ const int pitch = bytepitch/sizeof(PTYPE);
+ const int tex_pitch = textureInfo->pitch;
+ const int tex_height = textureInfo->height;
+ const unsigned int tex_endpos = textureInfo->endpos;
+
+ const SWHelper::signed64 bigOne = static_cast<SWHelper::signed64>(1) << 48;
+ #define swap(a,b,type) {type tmp = a; a = b; b = tmp;}
+
+ const unsigned int * pTexture;
+ unsigned int vShift, uMask, vMask;
+
+ #if defined(TEXTURED)
+ {
+ pTexture = textureInfo->pTexture;
+ vShift = textureInfo->vShift;
+ vMask = textureInfo->vMask;
+ uMask = textureInfo->uMask;
+ }
+ #endif
+
+ // Sort vertices by Y component
+
+ SWHelper::SWVertex * v0 = pVerts+0;
+ SWHelper::SWVertex * v1 = pVerts+1;
+ SWHelper::SWVertex * v2 = pVerts+2;
+
+ if (v0->y > v1->y) swap(v0,v1,SWHelper::SWVertex *);
+ if (v1->y > v2->y) swap(v1,v2,SWHelper::SWVertex *);
+ if (v0->y > v1->y) swap(v0,v1,SWHelper::SWVertex *);
+
+ #if defined(MOD_ARGB) && defined(GLOBAL_ARGB)
+ {
+ v0->a = (v0->a * globalDiffuse.a) >> 8;
+ v0->r = (v0->r * globalDiffuse.r) >> 8;
+ v0->g = (v0->g * globalDiffuse.g) >> 8;
+ v0->b = (v0->b * globalDiffuse.b) >> 8;
+ v1->a = (v1->a * globalDiffuse.a) >> 8;
+ v1->r = (v1->r * globalDiffuse.r) >> 8;
+ v1->g = (v1->g * globalDiffuse.g) >> 8;
+ v1->b = (v1->b * globalDiffuse.b) >> 8;
+ v2->a = (v2->a * globalDiffuse.a) >> 8;
+ v2->r = (v2->r * globalDiffuse.r) >> 8;
+ v2->g = (v2->g * globalDiffuse.g) >> 8;
+ v2->b = (v2->b * globalDiffuse.b) >> 8;
+ }
+ #endif
+
+ // Integer Y values (using a quick form of ceil() for positive values)
+
+ int y0 = (v0->y + 0xffff) >> 16;
+ int y2 = (v2->y + 0xffff) >> 16;
+ if (y0 == y2) return; // Null polygon (no height)?
+ int y1 = (v1->y + 0xffff) >> 16;
+
+ // Calculate long-edge deltas
+
+ SWHelper::signed64 oneOverHeight = bigOne / (v2->y - v0->y);
+ int ldx, ldr, ldg, ldb, lda, ldu, ldv;
+ ldx = static_cast<int>(((v2->x - v0->x) * oneOverHeight) >> 32);
+
+ #if defined(MOD_ARGB)
+ lda = static_cast<int>(((v2->a - v0->a) * oneOverHeight) >> 32);
+ ldr = static_cast<int>(((v2->r - v0->r) * oneOverHeight) >> 32);
+ ldg = static_cast<int>(((v2->g - v0->g) * oneOverHeight) >> 32);
+ ldb = static_cast<int>(((v2->b - v0->b) * oneOverHeight) >> 32);
+ #endif
+
+ #if defined(TEXTURED)
+ ldu = static_cast<int>(((v2->u - v0->u) * oneOverHeight) >> 32);
+ ldv = static_cast<int>(((v2->v - v0->v) * oneOverHeight) >> 32);
+ #endif
+
+ // Long-edge midpoint
+
+ SWHelper::signed64 topHeight = v1->y - v0->y;
+ int mid = v0->x + static_cast<int>((topHeight * ldx)>>16);
+
+ if (v1->x == mid) return; // Null polygon (no width)?
+
+ // Edge variables (long)
+
+ SWHelper::signed64 subPix = (y0<<16) - v0->y;
+ int lx, lr, lg, lb, la, lu, lv;
+ lx = v0->x + static_cast<int>((ldx * subPix)>>16);
+
+ #if defined(MOD_ARGB)
+ la = v0->a + static_cast<int>((lda * subPix)>>16);
+ lr = v0->r + static_cast<int>((ldr * subPix)>>16);
+ lg = v0->g + static_cast<int>((ldg * subPix)>>16);
+ lb = v0->b + static_cast<int>((ldb * subPix)>>16);
+ #endif
+
+ #if defined(TEXTURED)
+ lu = v0->u + static_cast<int>((ldu * subPix)>>16);
+ lv = v0->v + static_cast<int>((ldv * subPix)>>16);
+ #endif
+
+ // Scanline deltas
+
+ SWHelper::signed64 oneOverWidth;
+ int dr, dg, db, da, du, dv;
+ #if defined(TEXTURED) || defined(MOD_ARGB)
+ oneOverWidth = bigOne / (v1->x - mid);
+ #endif
+
+ #if defined (MOD_ARGB)
+ da = static_cast<int>(((v1->a - (v0->a + ((topHeight * lda)>>16))) * oneOverWidth)>>32);
+ dr = static_cast<int>(((v1->r - (v0->r + ((topHeight * ldr)>>16))) * oneOverWidth)>>32);
+ dg = static_cast<int>(((v1->g - (v0->g + ((topHeight * ldg)>>16))) * oneOverWidth)>>32);
+ db = static_cast<int>(((v1->b - (v0->b + ((topHeight * ldb)>>16))) * oneOverWidth)>>32);
+ #endif
+
+ #if defined (TEXTURED)
+ du = static_cast<int>(((v1->u - (v0->u + ((topHeight * ldu)>>16))) * oneOverWidth)>>32);
+ dv = static_cast<int>(((v1->v - (v0->v + ((topHeight * ldv)>>16))) * oneOverWidth)>>32);
+ #endif
+
+ // Screen info
+
+ unsigned int offset = y0 * pitch;
+ PTYPE * fb = reinterpret_cast<PTYPE *>(pFrameBuffer) + offset;
+ int iHeight = y1 - y0;
+
+ if (iHeight)
+ {
+ // Short edge delta X
+
+ oneOverHeight = bigOne / topHeight;
+ int sdx = static_cast<int>(((v1->x - v0->x) * oneOverHeight) >> 32);
+
+ // Edge variables (short)
+
+ int sx = v0->x + static_cast<int>((sdx * subPix)>>16);
+
+ // Scan-convert the top half
+
+ if (mid < v1->x)
+ {
+ while(iHeight-- > 0)
+ {
+ // Integer (ceil()) left and right X components
+
+ int x0 = (lx + 0xffff) & 0xffff0000;
+ int x1 = (sx + 0xffff) & 0xffff0000;
+ #include "SWTri_Loop.cpp"
+ }
+ }
+ else if (mid > v1->x)
+ {
+ while(iHeight-- > 0)
+ {
+ // Integer (ceil()) left and right X components
+
+ int x0 = (sx + 0xffff) & 0xffff0000;
+ int x1 = (lx + 0xffff) & 0xffff0000;
+ #include "SWTri_Loop.cpp"
+ }
+ }
+ }
+
+ // Done?
+
+ iHeight = y2 - y1;
+ if (!iHeight) return;
+
+ // Short edge along bottom half
+
+ oneOverHeight = bigOne / (v2->y - v1->y);
+ int sdx = static_cast<int>(((v2->x - v1->x) * oneOverHeight) >> 32);
+
+ subPix = (y1<<16) - v1->y;
+ int sx = v1->x + static_cast<int>((sdx * subPix)>>16);
+
+ // Scan-convert the bottom half
+
+ if (mid < v1->x)
+ {
+ while(iHeight-- > 0)
+ {
+ // Integer (ceil()) left and right X components
+
+ int x0 = (lx + 0xffff) & 0xffff0000;
+ int x1 = (sx + 0xffff) & 0xffff0000;
+ #include "SWTri_Loop.cpp"
+ }
+ }
+ else if (mid > v1->x)
+ {
+ while(iHeight-- > 0)
+ {
+ // Integer (ceil()) left and right X components
+
+ int x0 = (sx + 0xffff) & 0xffff0000;
+ int x1 = (lx + 0xffff) & 0xffff0000;
+ #include "SWTri_Loop.cpp"
+ }
+ }
+}
+#undef funcname2
+#undef funcname1
+#undef funcname
+#undef PTYPE
+#undef PIXEL_INCLUDE
+#undef TEXTURED
+#undef TEX_ALPHA
+#undef MOD_ARGB
+#undef GLOBAL_ARGB
+#undef LINEAR_BLEND
+#undef NAME0
+#undef NAME1
+#undef NAME2
+#undef NAME3
+#undef NAME4
+#undef NAME5
+
diff --git a/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc1.cpp b/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc1.cpp
new file mode 100644
index 0000000..00e8d08
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc1.cpp
@@ -0,0 +1,762 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+#define TRI0 0
+#define TRI1 0
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#define TRI1 1
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#undef TRI0
+#define TRI0 1
+#define TRI1 0
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#define TRI1 1
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#undef TRI0
+#define TRI0 2
+#define TRI1 0
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#define TRI1 1
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#undef TRI0
+#define TRI0 3
+#define TRI1 0
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#define TRI1 1
+#define TRI2 0
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#define TRI2 1
+#define TRI3 0
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#define TRI3 1
+#define TRI4 0
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#define TRI4 1
+#define TRI5 0
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#define TRI5 1
+#include "SWTri_DrawTriangle.cpp"
+
+#undef TRI5
+#undef TRI4
+#undef TRI3
+#undef TRI2
+#undef TRI1
+#undef TRI0
diff --git a/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc2.cpp b/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc2.cpp
new file mode 100644
index 0000000..ba4fe95
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_DrawTriangleInc2.cpp
@@ -0,0 +1,142 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+int aType = (blend?1:0) | (global_argb?2:0) | (mod_argb?4:0) | (talpha?8:0) | (textured?16:0);
+switch (thePixelFormat)
+{
+ case 0x8888: aType |= 0<<5; break;
+ case 0x888: aType |= 1<<5; break;
+ case 0x565: aType |= 2<<5; break;
+ case 0x555: aType |= 3<<5; break;
+}
+
+switch (aType)
+{
+ case 0: DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 1: DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 2: DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 3: DrawTriangle_8888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 4: DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 5: DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 6: DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 7: DrawTriangle_8888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 8: DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 9: DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 10: DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 11: DrawTriangle_8888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 12: DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 13: DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 14: DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 15: DrawTriangle_8888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 16: DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 17: DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 18: DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 19: DrawTriangle_8888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 20: DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 21: DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 22: DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 23: DrawTriangle_8888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 24: DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 25: DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 26: DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 27: DrawTriangle_8888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 28: DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 29: DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 30: DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 31: DrawTriangle_8888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 32: DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 33: DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 34: DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 35: DrawTriangle_0888_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 36: DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 37: DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 38: DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 39: DrawTriangle_0888_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 40: DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 41: DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 42: DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 43: DrawTriangle_0888_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 44: DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 45: DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 46: DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 47: DrawTriangle_0888_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 48: DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 49: DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 50: DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 51: DrawTriangle_0888_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 52: DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 53: DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 54: DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 55: DrawTriangle_0888_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 56: DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 57: DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 58: DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 59: DrawTriangle_0888_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 60: DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 61: DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 62: DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 63: DrawTriangle_0888_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 64: DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 65: DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 66: DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 67: DrawTriangle_0565_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 68: DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 69: DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 70: DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 71: DrawTriangle_0565_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 72: DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 73: DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 74: DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 75: DrawTriangle_0565_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 76: DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 77: DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 78: DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 79: DrawTriangle_0565_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 80: DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 81: DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 82: DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 83: DrawTriangle_0565_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 84: DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 85: DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 86: DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 87: DrawTriangle_0565_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 88: DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 89: DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 90: DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 91: DrawTriangle_0565_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 92: DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 93: DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 94: DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 95: DrawTriangle_0565_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 96: DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 97: DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 98: DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 99: DrawTriangle_0555_TEX0_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 100: DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 101: DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 102: DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 103: DrawTriangle_0555_TEX0_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 104: DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 105: DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 106: DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 107: DrawTriangle_0555_TEX0_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 108: DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 109: DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 110: DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 111: DrawTriangle_0555_TEX0_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 112: DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 113: DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 114: DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 115: DrawTriangle_0555_TEX1_TALPHA0_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 116: DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 117: DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 118: DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 119: DrawTriangle_0555_TEX1_TALPHA0_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 120: DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 121: DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 122: DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 123: DrawTriangle_0555_TEX1_TALPHA1_MOD0_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 124: DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 125: DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB0_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 126: DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND0(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+ case 127: DrawTriangle_0555_TEX1_TALPHA1_MOD1_GLOB1_BLEND1(pVerts, pFrameBuffer, bytepitch, textureInfo, globalDiffuse); break;
+}
diff --git a/osframework/source/SexyAppFramework/SWTri_GetTexel.cpp b/osframework/source/SexyAppFramework/SWTri_GetTexel.cpp
new file mode 100644
index 0000000..4ffdd38
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_GetTexel.cpp
@@ -0,0 +1,44 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ unsigned int tex;
+ #if !defined(LINEAR_BLEND)
+ {
+ unsigned int t_pos = ((v)>>16)*tex_pitch + ((u)>>16);
+ tex = t_pos<tex_endpos?pTexture[t_pos]:0;
+ }
+ #else
+ {
+ int umid = u-0x8000;
+ int vmid = v-0x8000;
+ int umidfloor = FixedFloor(umid);
+ int vmidfloor = FixedFloor(vmid);
+
+ unsigned int t_pos = (vmidfloor>>16)*tex_pitch + (umidfloor>>16);
+
+ unsigned int t00 = t_pos<tex_endpos?pTexture[t_pos]:0;
+ unsigned int t10 = t_pos+1<tex_endpos?pTexture[t_pos+1]:0;
+ unsigned int t01 = t_pos+tex_pitch<tex_endpos?pTexture[t_pos+tex_pitch]:0;
+ unsigned int t11 = t_pos+tex_pitch+1<tex_endpos?pTexture[t_pos+tex_pitch+1]:0;
+
+ int aUFactor = ((umid-umidfloor) & 0xFFFE) + 1; // aUFactor needs to be between 1 and 0xFFFF to avoid overflow
+ int aVFactor = ((vmid-vmidfloor) & 0xFFFE) + 1; // ditto for aVFactor
+ int a00 = ((t00 >> 24) * ((ulong) ((0x10000 - aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a10 = ((t10 >> 24) * ((ulong) (( aUFactor) * (0x10000 - aVFactor)) >> 16)) >> 16;
+ int a01 = ((t01 >> 24) * ((ulong) ((0x10000 - aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ int a11 = ((t11 >> 24) * ((ulong) (( aUFactor) * ( aVFactor)) >> 16)) >> 16;
+ unsigned int r = (((t00&0x00FF0000)*a00 + (t10&0x00FF0000)*a10 + (t01&0x00FF0000)*a01 + (t11&0x00FF0000)*a11)>>8)&0xFF0000;
+ unsigned int g = (((t00&0x0000FF00)*a00 + (t10&0x0000FF00)*a10 + (t01&0x0000FF00)*a01 + (t11&0x0000FF00)*a11)>>8)&0x00FF00;
+ unsigned int b = (((t00&0x000000FF)*a00 + (t10&0x000000FF)*a10 + (t01&0x000000FF)*a01 + (t11&0x000000FF)*a11)>>8)&0x0000FF;
+ unsigned int a = ((a00 + a10 + a01 + a11)<<24)&0xFF000000;
+
+ tex = a|r|g|b;
+ }
+ #endif
+
+ unsigned int alpha;
+ #if defined (TEX_ALPHA)
+ alpha = tex>>24;
+ #else
+ alpha = 0xFF;
+ #endif
+
diff --git a/osframework/source/SexyAppFramework/SWTri_Loop.cpp b/osframework/source/SexyAppFramework/SWTri_Loop.cpp
new file mode 100644
index 0000000..f963522
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_Loop.cpp
@@ -0,0 +1,57 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ SWHelper::signed64 subTex = x0 - lx;
+ unsigned int u, v, r, g, b, a;
+
+ #if defined(MOD_ARGB)
+ a = la + static_cast<int>((da * subTex)>>16);
+ r = lr + static_cast<int>((dr * subTex)>>16);
+ g = lg + static_cast<int>((dg * subTex)>>16);
+ b = lb + static_cast<int>((db * subTex)>>16);
+ #endif
+
+ #if defined(TEXTURED)
+ u = lu + static_cast<int>((du * subTex)>>16);
+ v = lv + static_cast<int>((dv * subTex)>>16);
+ #endif
+
+ PTYPE * pix = fb + (x0>>16);
+ int width = ((x1-x0)>>16);
+
+ while(width-- > 0)
+ {
+ #include PIXEL_INCLUDE
+// if (bit_format == 0x888) PIXEL888()
+// if (bit_format == 0x565) PIXEL565()
+// if (bit_format == 0x555) PIXEL555()
+// if (bit_format == 0x8888) PIXEL8888()
+ ++pix;
+ #if defined(MOD_ARGB)
+ a += da;
+ r += dr;
+ g += dg;
+ b += db;
+ #endif
+
+ #if defined(TEXTURED)
+ u += du;
+ v += dv;
+ #endif
+ }
+
+ lx += ldx;
+ sx += sdx;
+ fb += pitch;
+
+ #if defined (MOD_ARGB)
+ la += lda;
+ lr += ldr;
+ lg += ldg;
+ lb += ldb;
+ #endif
+
+ #if defined (TEXTURED)
+ lu += ldu;
+ lv += ldv;
+ #endif
+
diff --git a/osframework/source/SexyAppFramework/SWTri_Pixel555.cpp b/osframework/source/SexyAppFramework/SWTri_Pixel555.cpp
new file mode 100644
index 0000000..4b5cd05
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_Pixel555.cpp
@@ -0,0 +1,69 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ #if defined(TEXTURED)
+ {
+ #include "SWTri_GetTexel.cpp"
+
+ if (alpha > 0x08)
+ {
+ #include "SWTri_TexelARGB.cpp"
+
+ #if defined(GLOBAL_ARGB) || defined (TEX_ALPHA) || defined(MOD_ARGB)
+ {
+ if (alpha < 0xf0)
+ {
+ unsigned int trb, tg;
+ #if !defined(LINEAR_BLEND)
+ {
+ trb = (((tex&0xff00ff) * alpha) >> 8) & 0xff00ff;
+ tg = (((tex&0x00ff00) * alpha) >> 8) & 0x00ff00;
+ }
+ #else
+ {
+ trb = tex&0xff00ff;
+ tg = tex&0x00ff00;
+ }
+ #endif
+
+ trb = ((trb>>9)&0x7c00)|((trb>>3)&0x001f);
+ tg = ((tg>>6)&0x03e0);
+ tex = *pix;
+ alpha = (0xff - alpha)>>3;
+ unsigned int prb = (((tex&0x7c1f) * alpha) >> 5) & 0x7c1f;
+ unsigned int pg = (((tex&0x03e0) * alpha) >> 5) & 0x03e0;
+ *pix = (trb|tg) + (prb|pg);
+ }
+ else
+ {
+ *pix = ((tex>>9)&0x7c00)|((tex>>6)&0x03e0)|((tex>>3)&0x001f);
+ }
+ }
+ #else
+ {
+ *pix = ((tex>>9)&0x7c00)|((tex>>6)&0x03e0)|((tex>>3)&0x001f);
+ }
+ #endif
+ }
+ }
+ #elif defined(MOD_ARGB)
+ {
+ if (a > 0xf00000)
+ {
+ *pix = ((r>>9)&0x7c00)|((g>>14)&0x03e0)|((b>>19)&0x001f);
+ }
+ else if (a > 0x080000)
+ {
+ unsigned int alpha = a >> 16;
+ unsigned int _rb = ((((r&0xff0000) | (b>>16)) * alpha)>> 8)&0xff00ff;
+ unsigned int _g = (((g&0xff0000) * alpha)>>16)&0x00ff00;
+ _rb = ((_rb>>9)&0x7c00)|((_rb>>3)&0x001f);
+ _g = ((_g>>6)&0x03e0);
+ unsigned int p = *pix;
+ alpha = (0xff - alpha)>>3;
+ unsigned int prb = (((p&0x7c1f) * alpha) >> 5) & 0x7c1f;
+ unsigned int pg = (((p&0x03e0) * alpha) >> 5) & 0x03e0;
+ *pix = (_rb|_g)+(prb|pg);
+ }
+ }
+ #endif
+
diff --git a/osframework/source/SexyAppFramework/SWTri_Pixel565.cpp b/osframework/source/SexyAppFramework/SWTri_Pixel565.cpp
new file mode 100644
index 0000000..12c9e4b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_Pixel565.cpp
@@ -0,0 +1,68 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ #if defined(TEXTURED)
+ {
+ #include "SWTri_GetTexel.cpp"
+
+ if (alpha > 0x08)
+ {
+ #include "SWTri_TexelARGB.cpp"
+
+ #if defined(GLOBAL_ARGB) || defined (TEX_ALPHA) || defined(MOD_ARGB)
+ {
+ if (alpha < 0xf0)
+ {
+ unsigned int trb, tg;
+ #if !defined(LINEAR_BLEND)
+ {
+ trb = (((tex&0xff00ff) * alpha) >> 8) & 0xff00ff;
+ tg = (((tex&0x00ff00) * alpha) >> 8) & 0x00ff00;
+ }
+ #else
+ {
+ trb = tex&0xff00ff;
+ tg = tex&0x00ff00;
+ }
+ #endif
+
+ trb = ((trb>>8)&0xf800)|((trb>>3)&0x001f);
+ tg = ((tg>>5)&0x07e0);
+ tex = *pix;
+ alpha = (0xff - alpha)>>3;
+ unsigned int prb = (((tex&0xf81f) * alpha) >> 5) & 0xf81f;
+ unsigned int pg = (((tex&0x07e0) * alpha) >> 5) & 0x07e0;
+ *pix = (trb|tg) + (prb|pg);
+ }
+ else
+ {
+ *pix = ((tex>>8)&0xf800)|((tex>>5)&0x07e0)|((tex>>3)&0x001f);
+ }
+ }
+ #else
+ {
+ *pix = ((tex>>8)&0xf800)|((tex>>5)&0x07e0)|((tex>>3)&0x001f);
+ }
+ #endif
+ }
+ }
+ #elif defined(MOD_ARGB)
+ {
+ if (a > 0xf00000)
+ {
+ *pix = ((r>>8)&0xf800)|((g>>13)&0x07e0)|((b>>19)&0x001f);
+ }
+ else if (a > 0x080000)
+ {
+ unsigned int alpha = a >> 16;
+ unsigned int _rb = ((((r&0xff0000) | (b>>16)) * alpha)>> 8)&0xff00ff;
+ unsigned int _g = (((g&0xff0000) * alpha)>>16)&0x00ff00;
+ _rb = ((_rb>>8)&0xf800)|((_rb>>3)&0x001f);
+ _g = ((_g>>5)&0x07e0);
+ unsigned int p = *pix;
+ alpha = (0xff - alpha)>>3;
+ unsigned int prb = (((p&0xf81f) * alpha) >> 5) & 0xf81f;
+ unsigned int pg = (((p&0x07e0) * alpha) >> 5) & 0x07e0;
+ *pix = (_rb|_g)+(prb|pg);
+ }
+ }
+ #endif
diff --git a/osframework/source/SexyAppFramework/SWTri_Pixel888.cpp b/osframework/source/SexyAppFramework/SWTri_Pixel888.cpp
new file mode 100644
index 0000000..14e3951
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_Pixel888.cpp
@@ -0,0 +1,64 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ #if defined(TEXTURED)
+ {
+ #include "SWTri_GetTexel.cpp"
+
+ if (alpha > 0x08)
+ {
+ #include "SWTri_TexelARGB.cpp"
+
+ #if defined(GLOBAL_ARGB) || defined (TEX_ALPHA) || defined(MOD_ARGB)
+ {
+ if (alpha < 0xf0)
+ {
+ unsigned int trb, tg;
+ #if !defined(LINEAR_BLEND)
+ {
+ trb = (((tex&0xff00ff) * alpha) >> 8) & 0xff00ff;
+ tg = (((tex&0x00ff00) * alpha) >> 8) & 0x00ff00;
+ }
+ #else
+ {
+ trb = tex&0xff00ff;
+ tg = tex&0x00ff00;
+ }
+ #endif
+
+ tex = *pix;
+ alpha = 0xff - alpha;
+ unsigned int prb = (((tex&0xff00ff) * alpha) >> 8) & 0xff00ff;
+ unsigned int pg = (((tex&0x00ff00) * alpha) >> 8) & 0x00ff00;
+ *pix = 0xFF000000 | ((trb|tg) + (prb|pg));
+ }
+ else
+ {
+ *pix = 0xFF000000 | tex;
+ }
+ }
+ #else
+ {
+ *pix = 0xFF000000 | tex;
+ }
+ #endif
+ }
+ }
+ #elif defined(MOD_ARGB)
+ {
+ if (a > 0xf00000)
+ {
+ *pix = 0xFF000000 | ((r)&0xff0000)|((g>>8)&0xff00)|((b>>16)&0xff);
+ }
+ else if (a > 0x080000)
+ {
+ unsigned int alpha = a >> 16;
+ unsigned int _rb = ((((r&0xff0000) | (b>>16)) * alpha)>> 8)&0xff00ff;
+ unsigned int _g = (((g&0xff0000) * alpha)>>16)&0x00ff00;
+ unsigned int p = *pix;
+ alpha = 0xff - alpha;
+ unsigned int prb = (((p&0xff00ff) * alpha) >> 8) & 0xff00ff;
+ unsigned int pg = (((p&0x00ff00) * alpha) >> 8) & 0x00ff00;
+ *pix = 0xFF000000 | (_rb|_g)+(prb|pg);
+ }
+ }
+ #endif
diff --git a/osframework/source/SexyAppFramework/SWTri_Pixel8888.cpp b/osframework/source/SexyAppFramework/SWTri_Pixel8888.cpp
new file mode 100644
index 0000000..030304a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_Pixel8888.cpp
@@ -0,0 +1,87 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+
+ #if defined(TEXTURED)
+ {
+ #include "SWTri_GetTexel.cpp"
+
+ if (alpha > 0x08)
+ {
+ #include "SWTri_TexelARGB.cpp"
+
+ #if defined(GLOBAL_ARGB) || defined (TEX_ALPHA) || defined(MOD_ARGB)
+ {
+ if (alpha < 0xf0)
+ {
+ unsigned int p = *pix;
+ unsigned int da = p >> 24;
+
+ unsigned int tr,tg,tb;
+ #if !defined(LINEAR_BLEND)
+ {
+ tr = ((tex&0xFF0000)*alpha)&0xFF000000;
+ tg = ((tex&0x00FF00)*alpha)&0x00FF0000;
+ tb = ((tex&0x0000FF)*alpha)&0x0000FF00;
+ }
+ #else
+ {
+ tr = (tex&0xFF0000)<<8;
+ tg = (tex&0x00FF00)<<8;
+ tb = (tex&0x0000FF)<<8;
+ }
+ #endif
+
+ unsigned int dr = (((p&0xFF0000)*da)>>8) & 0xFF0000;
+ unsigned int dg = (((p&0x00FF00)*da)>>8) & 0x00FF00;
+ unsigned int db = (((p&0x0000FF)*da)>>8) & 0x0000FF;
+
+ int finalAlpha = 256 - (((256 - alpha)*(256 - da))>>8);
+ tr = ((tr + (256-alpha)*dr)/finalAlpha) & 0xFF0000;
+ tg = ((tg + (256-alpha)*dg)/finalAlpha) & 0x00FF00;
+ tb = ((tb + (256-alpha)*db)/finalAlpha) & 0x0000FF;
+
+ *pix = ((finalAlpha-1)<<24) | tr | tg | tb;
+ }
+ else
+ {
+ *pix = tex | 0xFF000000;
+ }
+ }
+ #else
+ {
+ *pix = tex | 0xFF000000;
+ }
+ #endif
+ }
+ }
+ #elif defined(MOD_ARGB)
+ {
+ if (a > 0xf00000)
+ {
+ *pix = 0xFF000000 | ((r)&0xff0000)|((g>>8)&0xff00)|((b>>16)&0xff);
+ }
+ else if (a > 0x080000)
+ {
+ unsigned int p = *pix;
+ unsigned int da = p >> 24;
+
+ int alpha = a>>16;
+
+ unsigned int tr = ((r)*(alpha))&0xFF000000;
+ unsigned int tg = ((g>>8)*(alpha))&0x00FF0000;
+ unsigned int tb = ((b>>16)*(alpha))&0x0000FF00;
+
+ unsigned int dr = (((p&0xFF0000)*da)>>8) & 0xFF0000;
+ unsigned int dg = (((p&0x00FF00)*da)>>8) & 0x00FF00;
+ unsigned int db = (((p&0x0000FF)*da)>>8) & 0x0000FF;
+
+ int finalAlpha = 256 - (((256 - alpha)*(256 - da))>>8);
+ tr = ((tr + (256-alpha)*dr)/finalAlpha) & 0xFF0000;
+ tg = ((tg + (256-alpha)*dg)/finalAlpha) & 0x00FF00;
+ tb = ((tb + (256-alpha)*db)/finalAlpha) & 0x0000FF;
+
+ *pix = ((finalAlpha-1)<<24) | tr | tg | tb;
+ }
+ else
+ _asm nop;
+ }
+ #endif
diff --git a/osframework/source/SexyAppFramework/SWTri_TexelARGB.cpp b/osframework/source/SexyAppFramework/SWTri_TexelARGB.cpp
new file mode 100644
index 0000000..df2f2f2
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SWTri_TexelARGB.cpp
@@ -0,0 +1,39 @@
+// This file is included by SWTri.cpp and should not be built directly by the project.
+{
+ int premult;
+ #if defined(MOD_ARGB) && defined(GLOBAL_ARGB)
+ {
+ premult = ((globalDiffuse.a*a)>>24);
+ alpha = (alpha * premult) >> 8;
+ tex = ((((tex&0xff0000)*((globalDiffuse.r*r)>>24))>>8)&0xff0000)|
+ ((((tex&0x00ff00)*((globalDiffuse.g*g)>>24))>>8)&0x00ff00)|
+ ((((tex&0x0000ff)*((globalDiffuse.b*b)>>24))>>8)&0x0000ff);
+ }
+ #elif !defined(MOD_ARGB) && defined(GLOBAL_ARGB)
+ {
+ premult = globalDiffuse.a;
+ alpha = (alpha * premult) >> 8;
+ tex = ((((tex&0xff0000)*globalDiffuse.r)>>8)&0xff0000)|
+ ((((tex&0x00ff00)*globalDiffuse.g)>>8)&0x00ff00)|
+ ((((tex&0x0000ff)*globalDiffuse.b)>>8)&0x0000ff);
+ }
+ #elif defined(MOD_ARGB) && !defined(GLOBAL_ARGB)
+ {
+ premult = a>>16;
+ alpha = (alpha * premult) >> 8;
+ tex = ((((tex&0xff0000)*(r>>16))>>8)&0xff0000)|
+ ((((tex&0x00ff00)*(g>>16))>>8)&0x00ff00)|
+ ((((tex&0x0000ff)*(b>>16))>>8)&0x0000ff);
+ }
+ #endif
+
+ // linear blend expects pixel to already be premultiplied by alpha
+ #if defined(LINEAR_BLEND) && (defined(MOD_ARGB) || defined(GLOBAL_ARGB))
+ {
+ int r = (((tex&0xff0000)*premult)>>8)&0xff0000;
+ int g = (((tex&0x00ff00)*premult)>>8)&0x00ff00;
+ int b = (((tex&0x0000ff)*premult)>>8)&0x0000ff;
+ tex = r|g|b;
+ }
+ #endif
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ScrollListener.h b/osframework/source/SexyAppFramework/ScrollListener.h
new file mode 100644
index 0000000..be9c8ff
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ScrollListener.h
@@ -0,0 +1,15 @@
+#ifndef __SCROLLLISTENER_H__
+#define __SCROLLLISTENER_H__
+
+namespace Sexy
+{
+
+class ScrollListener
+{
+public:
+ virtual void ScrollPosition(int theId, double thePosition) {};
+};
+
+}
+
+#endif // __SCROLLLISTENER_H__
diff --git a/osframework/source/SexyAppFramework/ScrollbarWidget.cpp b/osframework/source/SexyAppFramework/ScrollbarWidget.cpp
new file mode 100644
index 0000000..6f8f3e4
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ScrollbarWidget.cpp
@@ -0,0 +1,362 @@
+#include "ScrollbarWidget.h"
+#include "WidgetManager.h"
+#include "ScrollListener.h"
+#include "ScrollbuttonWidget.h"
+
+using namespace Sexy;
+
+ScrollbarWidget::ScrollbarWidget(int theId, ScrollListener* theScrollListener)
+{
+ mId = theId;
+ mScrollListener = theScrollListener;
+
+ SetDisabled(true);
+
+ mUpButton = new ScrollbuttonWidget(0, this);
+ mUpButton->SetDisabled(true);
+
+ mDownButton = new ScrollbuttonWidget(1, this);
+ mDownButton->SetDisabled(true);
+
+ mInvisIfNoScroll = false;
+ mPressedOnThumb = false;
+ mValue = 0;
+ mMaxValue = 0;
+ mPageSize = 0;
+ mUpdateAcc = 0;
+ mButtonAcc = 0;
+ mUpdateMode = 0;
+ mHorizontal = false;
+
+ AddWidget(mUpButton);
+ AddWidget(mDownButton);
+}
+
+ScrollbarWidget::~ScrollbarWidget()
+{
+ RemoveAllWidgets(true);
+}
+
+void ScrollbarWidget::SetInvisIfNoScroll(bool invisIfNoScroll)
+{
+ mInvisIfNoScroll = invisIfNoScroll;
+
+ if (mInvisIfNoScroll)
+ {
+ SetVisible(false);
+ mDownButton->SetVisible(false);
+ mUpButton->SetVisible(false);
+ }
+}
+
+void ScrollbarWidget::SetHorizontal(bool isHorizontal)
+{
+ mHorizontal = isHorizontal;
+ mDownButton->mHorizontal = mHorizontal;
+ mUpButton->mHorizontal = mHorizontal;
+}
+
+
+void ScrollbarWidget::ResizeScrollbar(int theX, int theY, int theWidth, int theHeight)
+{
+ Resize(theX, theY, theWidth, theHeight);
+ if (mHorizontal)
+ {
+ theX = theY = 0; // Use New Container Stuff
+ mUpButton->Resize(theX, theY, theHeight, theHeight);
+ mDownButton->Resize(theX + theWidth - theHeight, theY, theHeight, theHeight);
+ }
+ else
+ {
+ theX = theY = 0; // Use New Container Stuff
+ mUpButton->Resize(theX, theY, theWidth, theWidth);
+ mDownButton->Resize(theX, theY + theHeight - theWidth, theWidth, theWidth);
+ }
+}
+
+void ScrollbarWidget::SetMaxValue(double theNewMaxValue)
+{
+ mMaxValue = theNewMaxValue;
+ ClampValue();
+ MarkDirty();
+}
+
+void ScrollbarWidget::SetPageSize(double theNewPageSize)
+{
+ mPageSize = theNewPageSize;
+ ClampValue();
+ MarkDirty();
+}
+
+void ScrollbarWidget::SetValue(double theNewValue)
+{
+ mValue = theNewValue;
+ ClampValue();
+ mScrollListener->ScrollPosition(mId, mValue);
+ MarkDirty();
+}
+
+bool ScrollbarWidget::AtBottom()
+{
+ return mMaxValue - mPageSize - mValue <= 1.0;
+}
+
+void ScrollbarWidget::GoToBottom()
+{
+ mValue = mMaxValue - mPageSize;
+ ClampValue();
+ SetValue(mValue);
+}
+
+void ScrollbarWidget::DrawThumb(Graphics *g, int theX, int theY, int theWidth, int theHeight)
+{
+ g->SetColor(Color(212, 212, 212));
+ g->FillRect(theX, theY, theWidth, theHeight);
+
+ g->SetColor(Color(255, 255, 255));
+ g->FillRect(theX + 1, theY + 1, theWidth-2, 1);
+ g->FillRect(theX + 1, theY + 1, 1, theHeight-2);
+
+ g->SetColor(Color::Black);
+ g->FillRect(theX, theY + theHeight - 1, theWidth, 1);
+ g->FillRect(theX + theWidth - 1, theY, 1, theHeight);
+
+ g->SetColor(Color(132, 132, 132));
+ g->FillRect(theX + 1, theY + theHeight - 2, theWidth - 2, 1);
+ g->FillRect(theX + theWidth - 2, theY + 1, 1, theHeight - 2);
+}
+
+int ScrollbarWidget::GetTrackSize()
+{
+ if (mHorizontal)
+ return mWidth-2*mUpButton->mWidth;
+ else
+ return mHeight-2*mUpButton->mWidth;
+}
+
+int ScrollbarWidget::GetThumbSize()
+{
+ if (mPageSize > mMaxValue)
+ return 0;
+
+ int aThumbSize = (int) ((double) ((GetTrackSize() * mPageSize / mMaxValue)) + 0.5);
+ return max(8, aThumbSize);
+}
+
+int ScrollbarWidget::GetThumbPosition()
+{
+ if (mPageSize > mMaxValue) return mUpButton->mWidth;
+ return (int) ((double) (((mValue * (GetTrackSize() - GetThumbSize())) / (mMaxValue - mPageSize))) + 0.5) + mUpButton->mWidth;
+}
+
+void ScrollbarWidget::Draw(Graphics *g)
+{
+ int aThumbSize = GetThumbSize();
+ int aThumbPosition = GetThumbPosition();
+
+ if (mHorizontal)
+ {
+ if (mUpdateMode == UPDATE_MODE_PGUP)
+ g->SetColor(Color(48, 48, 48));
+ else
+ g->SetColor(Color(232, 232, 232));
+ g->FillRect(0, 0, aThumbPosition, mHeight);
+
+ if (aThumbSize > 0)
+ DrawThumb(g, aThumbPosition, 0, aThumbSize, mHeight);
+
+ if (mUpdateMode == UPDATE_MODE_PGDN)
+ g->SetColor(Color(48, 48, 48));
+ else
+ g->SetColor(Color(232, 232, 232));
+ g->FillRect(aThumbPosition + aThumbSize, 0, mWidth - aThumbPosition - aThumbSize, mHeight);
+ }
+ else
+ {
+ if (mUpdateMode == UPDATE_MODE_PGUP)
+ g->SetColor(Color(48, 48, 48));
+ else
+ g->SetColor(Color(232, 232, 232));
+ g->FillRect(0, 0, mWidth, aThumbPosition);
+
+ if (aThumbSize > 0)
+ DrawThumb(g, 0, aThumbPosition, mWidth, aThumbSize);
+
+ if (mUpdateMode == UPDATE_MODE_PGDN)
+ g->SetColor(Color(48, 48, 48));
+ else
+ g->SetColor(Color(232, 232, 232));
+ g->FillRect(0, aThumbPosition + aThumbSize, mWidth, mHeight - aThumbPosition - aThumbSize);
+ }
+}
+
+void ScrollbarWidget::ClampValue()
+{
+ double anOldValue = mValue;
+
+ if (mValue > mMaxValue - mPageSize)
+ mValue = mMaxValue - mPageSize;
+ if (mValue < 0.0)
+ mValue = 0.0;
+
+ bool canScroll = mPageSize < mMaxValue;
+
+ SetDisabled(!canScroll);
+ mUpButton->SetDisabled(!canScroll);
+ mDownButton->SetDisabled(!canScroll);
+
+ if (mInvisIfNoScroll)
+ {
+ SetVisible(canScroll);
+ mDownButton->SetVisible(canScroll);
+ mUpButton->SetVisible(canScroll);
+ }
+
+ if (mValue != anOldValue) mScrollListener->ScrollPosition(mId, mValue);
+}
+
+void ScrollbarWidget::SetThumbPosition(int thePosition)
+{
+ SetValue(((thePosition-mUpButton->mWidth) * (mMaxValue - mPageSize)) / (GetTrackSize() - GetThumbSize()));
+}
+
+void ScrollbarWidget::ButtonPress(int theId)
+{
+ mButtonAcc = 0;
+
+ if (theId == 0)
+ SetValue(mValue-1);
+ else
+ SetValue(mValue+1);
+}
+
+void ScrollbarWidget::ButtonDepress(int theId)
+{
+}
+
+void ScrollbarWidget::ButtonDownTick(int theId)
+{
+ if (theId == 0)
+ {
+ if (++mButtonAcc >= 25)
+ {
+ SetValue(mValue-1);
+ mButtonAcc = 24;
+ }
+ }
+ else
+ {
+ if (++mButtonAcc >= 25)
+ {
+ SetValue(mValue+1);
+ mButtonAcc = 24;
+ }
+ }
+}
+
+void ScrollbarWidget::Update()
+{
+ Widget::Update();
+
+ switch (mUpdateMode)
+ {
+ case UPDATE_MODE_PGUP:
+ if (ThumbCompare(mLastMouseX, mLastMouseY) != -1)
+ {
+ mUpdateMode = UPDATE_MODE_IDLE;
+ MarkDirty();
+ }
+ else if (++mUpdateAcc >= 25)
+ {
+ SetValue(mValue - mPageSize);
+ mUpdateAcc = 20;
+ }
+ break;
+ case UPDATE_MODE_PGDN:
+ if (ThumbCompare(mLastMouseX, mLastMouseY) != 1)
+ {
+ mUpdateMode = UPDATE_MODE_IDLE;
+ MarkDirty();
+ }
+ else if (++mUpdateAcc >= 25)
+ {
+ SetValue(mValue + mPageSize);
+ mUpdateAcc = 20;
+ }
+ break;
+ }
+}
+
+int ScrollbarWidget::ThumbCompare(int x, int y)
+{
+ int aTrackPosition;
+
+ if (mHorizontal)
+ aTrackPosition = x;
+ else
+ aTrackPosition = y;
+
+ if (aTrackPosition < GetThumbPosition())
+ return -1;
+
+ if (aTrackPosition >= GetThumbPosition() + GetThumbSize())
+ return 1;
+
+ return 0;
+}
+
+void ScrollbarWidget::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+ Widget::MouseDown(x, y, theBtnNum, theClickCount);
+
+ if (!mDisabled)
+ {
+ switch (ThumbCompare(x, y))
+ {
+ case -1:
+ SetValue(mValue - mPageSize);
+ mUpdateMode = UPDATE_MODE_PGUP;
+ mUpdateAcc = 0;
+ break;
+ case 0:
+ mPressedOnThumb = true;
+ mMouseDownThumbPos = GetThumbPosition();
+ mMouseDownX = x;
+ mMouseDownY = y;
+ break;
+ case 1:
+ SetValue(mValue + mPageSize);
+ mUpdateMode = UPDATE_MODE_PGDN;
+ mUpdateAcc = 0;
+ break;
+ }
+ }
+
+ mLastMouseX = x;
+ mLastMouseY = y;
+}
+
+void ScrollbarWidget::MouseUp(int x, int y, int theBtnNum, int theClickCount)
+{
+ Widget::MouseUp(x, y, theBtnNum, theClickCount);
+
+ mUpdateMode = 0;
+ mPressedOnThumb = false;
+ MarkDirty();
+}
+
+void ScrollbarWidget::MouseDrag(int x, int y)
+{
+ Widget::MouseDrag(x, y);
+
+ if (mPressedOnThumb)
+ {
+ if (mHorizontal)
+ SetThumbPosition(mMouseDownThumbPos + x - mMouseDownX);
+ else
+ SetThumbPosition(mMouseDownThumbPos + y - mMouseDownY);
+ }
+
+ mLastMouseX = x;
+ mLastMouseY = y;
+}
diff --git a/osframework/source/SexyAppFramework/ScrollbarWidget.h b/osframework/source/SexyAppFramework/ScrollbarWidget.h
new file mode 100644
index 0000000..05fe0a6
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ScrollbarWidget.h
@@ -0,0 +1,90 @@
+// ScrollbarWidget.h: interface for the ScrollbarWidget class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#ifndef __SCROLLBARWIDGET_H__
+#define __SCROLLBARWIDGET_H__
+
+#include "Widget.h"
+#include "ButtonListener.h"
+
+namespace Sexy
+{
+
+class ScrollListener;
+class ScrollbuttonWidget;
+
+class ScrollbarWidget : public Widget, public ButtonListener
+{
+public:
+
+enum
+{
+ UPDATE_MODE_IDLE =0,
+ UPDATE_MODE_PGUP,
+ UPDATE_MODE_PGDN
+};
+
+public:
+
+ ScrollbuttonWidget *mUpButton;
+ ScrollbuttonWidget *mDownButton;
+
+ bool mInvisIfNoScroll;
+
+public:
+
+ int mId;
+
+ double mValue;
+ double mMaxValue;
+ double mPageSize;
+ bool mHorizontal;
+
+ bool mPressedOnThumb;
+ int mMouseDownThumbPos;
+ int mMouseDownX;
+ int mMouseDownY;
+
+ int mUpdateMode;
+ int mUpdateAcc;
+ int mButtonAcc;
+ int mLastMouseX;
+ int mLastMouseY;
+ ScrollListener* mScrollListener;
+
+public:
+ ScrollbarWidget(int theId, ScrollListener *theScrollListener);
+ virtual ~ScrollbarWidget();
+
+ virtual void SetInvisIfNoScroll(bool invisIfNoScroll);
+ virtual void SetMaxValue(double theNewMaxValue);
+ virtual void SetPageSize(double theNewPageSize);
+ virtual void SetValue(double theNewValue);
+ virtual void SetHorizontal(bool isHorizontal);
+
+ virtual void ResizeScrollbar(int theX, int theY, int theWidth, int theHeight);
+ virtual bool AtBottom();
+ virtual void GoToBottom();
+ virtual void DrawThumb(Graphics *g, int theX, int theY, int theWidth, int theHeight);
+ virtual int GetTrackSize();
+ virtual int GetThumbSize();
+ virtual int GetThumbPosition();
+ virtual void Draw(Graphics *g);
+ virtual void ClampValue();
+ virtual void SetThumbPosition(int thePosition);
+ virtual void ButtonPress(int theId);
+ virtual void ButtonDepress(int theId);
+ virtual void ButtonDownTick(int theId);
+ virtual void Update();
+ virtual int ThumbCompare(int x, int y);
+ virtual void MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseUp(int x, int y) { Widget::MouseUp(x, y); }
+ virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+};
+
+}
+
+#endif // __SCROLLBARWIDGET_H__
diff --git a/osframework/source/SexyAppFramework/ScrollbuttonWidget.cpp b/osframework/source/SexyAppFramework/ScrollbuttonWidget.cpp
new file mode 100644
index 0000000..127eba8
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ScrollbuttonWidget.cpp
@@ -0,0 +1,70 @@
+#include "ScrollbuttonWidget.h"
+#include "ButtonListener.h"
+#include "Graphics.h"
+
+using namespace Sexy;
+
+ScrollbuttonWidget::ScrollbuttonWidget(int theId, ButtonListener *theButtonListener, int theType) : ButtonWidget(theId, theButtonListener)
+{
+ mHorizontal = false;
+ mType = theType;
+}
+
+ScrollbuttonWidget::~ScrollbuttonWidget()
+{
+}
+
+void ScrollbuttonWidget::Draw(Graphics *g)
+{
+ int anArrowOffset = 0;
+
+ g->SetColor(Color(212, 212, 212));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ if (mIsDown && mIsOver && !mDisabled)
+ {
+ anArrowOffset = 1;
+ g->SetColor(Color(132, 132, 132));
+ g->DrawRect(0, 0, mWidth-1, mHeight-1);
+ }
+ else
+ {
+ g->SetColor(Color(255, 255, 255));
+ g->FillRect(1, 1, mWidth-2, 1);
+ g->FillRect(1, 1, 1, mHeight-2);
+
+ g->SetColor(Color::Black);
+ g->FillRect(0, mHeight - 1, mWidth, 1);
+ g->FillRect(mWidth - 1, 0, 1, mHeight);
+
+ g->SetColor(Color(132, 132, 132));
+ g->FillRect(1, mHeight - 2, mWidth - 2, 1);
+ g->FillRect(mWidth - 2, 1, 1, mHeight - 2);
+ }
+
+ if (!mDisabled)
+ g->SetColor(Color::Black);
+ else
+ g->SetColor(Color(132, 132, 132));
+
+ if (mHorizontal || (mType==3 || mType==4))
+ {
+ for (int i = 0; i < 4; i++)
+ {
+ if (mId == 0 || mType==3)
+ g->FillRect(i + (mWidth-4)/2 + anArrowOffset, mHeight/2 - i - 1 + anArrowOffset, 1, 1 + i*2);
+ else
+ g->FillRect((3 - i) + (mWidth-4)/2 + anArrowOffset, mHeight/2 - i - 1 + anArrowOffset, 1, 1 + i*2);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < 4; i++)
+ {
+ if (mId == 0 || mType==1)
+ g->FillRect(mWidth/2 - i - 1 + anArrowOffset, i + (mHeight-4)/2 + anArrowOffset, 1 + i*2, 1);
+ else
+ g->FillRect(mWidth/2 - i - 1 + anArrowOffset, (3 - i) + (mHeight-4)/2 + anArrowOffset, 1 + i*2, 1);
+ }
+ }
+}
diff --git a/osframework/source/SexyAppFramework/ScrollbuttonWidget.h b/osframework/source/SexyAppFramework/ScrollbuttonWidget.h
new file mode 100644
index 0000000..5f7b7a3
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ScrollbuttonWidget.h
@@ -0,0 +1,29 @@
+#ifndef __SCROLLBUTTONWIDGET_H__
+#define __SCROLLBUTTONWIDGET_H__
+
+#include "..\SexyAppFramework\ButtonWidget.h"
+
+namespace Sexy
+{
+
+class ButtonListener;
+
+class ScrollbuttonWidget : public ButtonWidget
+{
+public:
+ bool mHorizontal;
+
+ // mType is a new way of doing things (1 = up, 2 = down, 3 = left, 4 = right).
+ // This overrides mHorizontal and mId.
+ int mType;
+
+public:
+ ScrollbuttonWidget(int theId, ButtonListener *theButtonListener, int theType = 0);
+ virtual ~ScrollbuttonWidget();
+
+ void Draw(Graphics *g);
+};
+
+}
+
+#endif //__SCROLLBUTTONWIDGET_H__
diff --git a/osframework/source/SexyAppFramework/SexyAppBase VS2005 WideString.vcproj b/osframework/source/SexyAppFramework/SexyAppBase VS2005 WideString.vcproj
new file mode 100644
index 0000000..d3f7cd9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase VS2005 WideString.vcproj
@@ -0,0 +1,8261 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="SexyAppBase WSTRING"
+ ProjectGUID="{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+ RootNamespace="SexyAppBase"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\DebugVS2005"
+ IntermediateDirectory=".\DebugVS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32;_DEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\ReleaseVS2005"
+ IntermediateDirectory=".\ReleaseVS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy- /wd4996"
+ InlineFunctionExpansion="1"
+ WholeProgramOptimization="true"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32;NDEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug - Zylom|Win32"
+ OutputDirectory="Debug - Zylom"
+ IntermediateDirectory="Debug - Zylom"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING,WIN32,_DEBUG,_LIB,ZYLOM"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug - Zylom/"
+ ObjectFile=".\Debug - Zylom/"
+ ProgramDataBaseFileName=".\Debug - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release - Zylom|Win32"
+ OutputDirectory="Release - Zylom"
+ IntermediateDirectory="Release - Zylom"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="_USE_WIDE_STRING,WIN32,NDEBUG,_LIB,ZYLOM"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release - Zylom/"
+ ObjectFile=".\Release - Zylom/"
+ ProgramDataBaseFileName=".\Release - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug - Incremental|Win32"
+ OutputDirectory="Debug - Incremental"
+ IntermediateDirectory="Debug - Incremental"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING,WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release noop|Win32"
+ OutputDirectory="Release noop VS2005"
+ IntermediateDirectory="Release noop VS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="_USE_WIDE_STRING,WIN32,NDEBUG,_LIB"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Graphics"
+ >
+ <Filter
+ Name="Graphics Source"
+ >
+ <File
+ RelativePath=".\Color.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DTester.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDImage.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Font.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Graphics.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="GraphicsBuild.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Image.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ImageFont.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MemoryImage.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="NativeDisplay.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Quantize.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SWTri.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SysFont.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Graphics Include"
+ >
+ <File
+ RelativePath=".\Color.h"
+ >
+ </File>
+ <File
+ RelativePath="D3DInterface.h"
+ >
+ </File>
+ <File
+ RelativePath="D3DTester.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DDImage.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DDInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Font.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Graphics.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Image.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ImageFont.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MemoryImage.h"
+ >
+ </File>
+ <File
+ RelativePath="NativeDisplay.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Quantize.h"
+ >
+ </File>
+ <File
+ RelativePath="SWTri.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SysFont.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Inc Routines"
+ >
+ <File
+ RelativePath="BltRotatedHelper.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_AlphaBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_BltRotated.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_BltRotated_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastBlt_NoAlpha.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastStretch.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastStretch_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_NormalBlt_Volatile.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_AdditiveBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_BltRotated.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_BltRotated_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_GetNativeAlphaData.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_GetRLAlphaData.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_NormalBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_SlowStretchBlt.inc"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="ImageLib"
+ >
+ <File
+ RelativePath="..\ImageLib\ImageLib.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\ImageLib.h"
+ >
+ </File>
+ <Filter
+ Name="PNG"
+ >
+ <File
+ RelativePath="..\ImageLib\png\png.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\png.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngasmrd.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngconf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngerror.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngget.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngmem.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngpread.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngread.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrtran.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngset.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngtrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngvcrd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwrite.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwtran.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwutil.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG"
+ >
+ <File
+ RelativePath="..\ImageLib\jpeg\cderror.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapimin.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapistd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccoefct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccolor.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcdctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcinit.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmainct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmarker.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmaster.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcomapi.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jconfig.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcparam.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcphuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcprepct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcsample.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jctrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapimin.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapistd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatadst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatasrc.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcoefct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcolor.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdct.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jddctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdinput.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmainct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmarker.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmaster.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmerge.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdphuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdpostct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdsample.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdtrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctflt.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctfst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctint.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctflt.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctfst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctint.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctred.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jinclude.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemnobs.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemsys.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmorecfg.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpegint.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpeglib.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant1.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant2.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jutils.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jversion.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdbmp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdcolmap.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdgif.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdppm.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdrle.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdswitch.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdtarga.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrbmp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrgif.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrppm.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrrle.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrtarga.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB"
+ >
+ <File
+ RelativePath="..\ImageLib\zlib\adler32.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\compress.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\crc32.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\gzio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffixed.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inflate.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\uncompr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zconf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zlib.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG2000"
+ >
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config2.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_fix.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_iccdata.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_math.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_types.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jasper.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_fix.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_flt.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Misc"
+ >
+ <Filter
+ Name="Misc Source"
+ >
+ <File
+ RelativePath=".\Buffer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Common.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\CritSect.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Debug.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="DirectXErrorString.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="Flags.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\KeyCodes.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="MiscBuildBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="ModVal.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MTRand.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="PerfTimer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="ResourceManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SexyMatrix.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\XMLParser.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Misc Include"
+ >
+ <File
+ RelativePath=".\AutoCrit.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Buffer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Common.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CritSect.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Debug.h"
+ >
+ </File>
+ <File
+ RelativePath="DirectXErrorString.h"
+ >
+ </File>
+ <File
+ RelativePath="Flags.h"
+ >
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\KeyCodes.h"
+ >
+ </File>
+ <File
+ RelativePath="memmgr.h"
+ >
+ </File>
+ <File
+ RelativePath="ModVal.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MTRand.h"
+ >
+ </File>
+ <File
+ RelativePath="PerfTimer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Point.h"
+ >
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Rect.h"
+ >
+ </File>
+ <File
+ RelativePath="ResourceManager.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.h"
+ >
+ </File>
+ <File
+ RelativePath="SexyMatrix.h"
+ >
+ </File>
+ <File
+ RelativePath="SexyVector.h"
+ >
+ </File>
+ <File
+ RelativePath="SmartPtr.h"
+ >
+ </File>
+ <File
+ RelativePath=".\XMLParser.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Sound"
+ >
+ <Filter
+ Name="Sound Source"
+ >
+ <File
+ RelativePath="BassLoader.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="BassLoader.h"
+ >
+ </File>
+ <File
+ RelativePath="BassMusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FModLoader.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Insets.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SoundBuild.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Sound Include"
+ >
+ <File
+ RelativePath="BassMusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DSoundManager.h"
+ >
+ </File>
+ <File
+ RelativePath="FModLoader.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SoundManager.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Ogg"
+ >
+ <File
+ RelativePath="ogg\asm_arm.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\backends.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\bitwise.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\block.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codebook.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codebook.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codec_internal.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\config_types.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\floor0.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\floor1.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\framing.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\info.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ivorbiscodec.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ivorbisfile.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\lsp_lookup.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mapping0.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct_lookup.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\misc.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ogg.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\os.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\os_types.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\registry.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\registry.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\res012.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\sharedbook.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\synthesis.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\vorbisfile.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window_lookup.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Widget"
+ >
+ <Filter
+ Name="Widget Source"
+ >
+ <File
+ RelativePath=".\ButtonWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Checkbox.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Dialog.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DialogButton.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\EditWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FlashWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ListWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Slider.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\TextWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Widget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="WidgetBuildBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="WidgetContainer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\WidgetManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Widget Include"
+ >
+ <File
+ RelativePath=".\ButtonListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ButtonWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Checkbox.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CheckboxListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Dialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DialogButton.h"
+ >
+ </File>
+ <File
+ RelativePath="DialogListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\EditListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\EditWidget.h"
+ >
+ </File>
+ <File
+ RelativePath="FlashWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Insets.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ListListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ListWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Slider.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SliderListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\TextWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Widget.h"
+ >
+ </File>
+ <File
+ RelativePath="WidgetContainer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\WidgetManager.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="PakLib"
+ >
+ <File
+ RelativePath="..\PakLib\PakInterface.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\PakLib\PakInterface.h"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath="SexyAppBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="SexyAppBase.h"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/SexyAppFramework/SexyAppBase VS2005.vcproj b/osframework/source/SexyAppFramework/SexyAppBase VS2005.vcproj
new file mode 100644
index 0000000..a4cb086
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase VS2005.vcproj
@@ -0,0 +1,8261 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="SexyAppBase"
+ ProjectGUID="{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+ RootNamespace="SexyAppBase"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\DebugVS2005"
+ IntermediateDirectory=".\DebugVS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\ReleaseVS2005"
+ IntermediateDirectory=".\ReleaseVS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy- /wd4996"
+ InlineFunctionExpansion="1"
+ WholeProgramOptimization="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug - Zylom|Win32"
+ OutputDirectory="Debug - Zylom"
+ IntermediateDirectory="Debug - Zylom"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB,ZYLOM"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug - Zylom/"
+ ObjectFile=".\Debug - Zylom/"
+ ProgramDataBaseFileName=".\Debug - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release - Zylom|Win32"
+ OutputDirectory="Release - Zylom"
+ IntermediateDirectory="Release - Zylom"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB,ZYLOM"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release - Zylom/"
+ ObjectFile=".\Release - Zylom/"
+ ProgramDataBaseFileName=".\Release - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug - Incremental|Win32"
+ OutputDirectory="Debug - Incremental"
+ IntermediateDirectory="Debug - Incremental"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release noop|Win32"
+ OutputDirectory="Release noop VS2005"
+ IntermediateDirectory="Release noop VS2005"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Graphics"
+ >
+ <Filter
+ Name="Graphics Source"
+ >
+ <File
+ RelativePath=".\Color.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DTester.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDImage.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Font.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Graphics.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="GraphicsBuild.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Image.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ImageFont.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MemoryImage.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="NativeDisplay.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Quantize.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SWTri.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SysFont.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Graphics Include"
+ >
+ <File
+ RelativePath=".\Color.h"
+ >
+ </File>
+ <File
+ RelativePath="D3DInterface.h"
+ >
+ </File>
+ <File
+ RelativePath="D3DTester.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DDImage.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DDInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Font.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Graphics.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Image.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ImageFont.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MemoryImage.h"
+ >
+ </File>
+ <File
+ RelativePath="NativeDisplay.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Quantize.h"
+ >
+ </File>
+ <File
+ RelativePath="SWTri.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SysFont.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Inc Routines"
+ >
+ <File
+ RelativePath="BltRotatedHelper.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_AlphaBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_BltRotated.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_BltRotated_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastBlt_NoAlpha.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastStretch.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_FastStretch_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="DDI_NormalBlt_Volatile.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_AdditiveBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_BltRotated.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_BltRotated_Additive.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_GetNativeAlphaData.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_GetRLAlphaData.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_NormalBlt.inc"
+ >
+ </File>
+ <File
+ RelativePath="MI_SlowStretchBlt.inc"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="ImageLib"
+ >
+ <File
+ RelativePath="..\ImageLib\ImageLib.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\ImageLib.h"
+ >
+ </File>
+ <Filter
+ Name="PNG"
+ >
+ <File
+ RelativePath="..\ImageLib\png\png.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\png.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngasmrd.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngconf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngerror.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngget.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngmem.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngpread.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngread.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrtran.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngset.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngtrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngvcrd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwrite.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwtran.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwutil.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG"
+ >
+ <File
+ RelativePath="..\ImageLib\jpeg\cderror.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapimin.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapistd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccoefct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccolor.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcdctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcinit.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmainct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmarker.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmaster.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcomapi.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jconfig.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcparam.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcphuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcprepct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcsample.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jctrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapimin.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapistd.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatadst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatasrc.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcoefct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcolor.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdct.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jddctmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdinput.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmainct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmarker.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmaster.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmerge.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdphuff.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdpostct.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdsample.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdtrans.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctflt.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctfst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctint.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctflt.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctfst.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctint.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctred.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jinclude.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemmgr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemnobs.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemsys.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmorecfg.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpegint.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpeglib.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant1.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant2.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jutils.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jversion.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdbmp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdcolmap.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdgif.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdppm.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdrle.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdswitch.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdtarga.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrbmp.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrgif.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrppm.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrrle.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrtarga.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB"
+ >
+ <File
+ RelativePath="..\ImageLib\zlib\adler32.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\compress.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\crc32.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\gzio.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffixed.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inflate.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\uncompr.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zconf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zlib.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.c"
+ >
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG2000"
+ >
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config2.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_fix.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_iccdata.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_math.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_types.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jasper.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_fix.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_flt.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.h"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Misc"
+ >
+ <Filter
+ Name="Misc Source"
+ >
+ <File
+ RelativePath=".\Buffer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Common.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\CritSect.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Debug.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="DirectXErrorString.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="Flags.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\KeyCodes.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="MiscBuildBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="ModVal.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MTRand.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="PerfTimer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="ResourceManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SexyMatrix.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\XMLParser.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Misc Include"
+ >
+ <File
+ RelativePath=".\AutoCrit.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Buffer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Common.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CritSect.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Debug.h"
+ >
+ </File>
+ <File
+ RelativePath="DirectXErrorString.h"
+ >
+ </File>
+ <File
+ RelativePath="Flags.h"
+ >
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\KeyCodes.h"
+ >
+ </File>
+ <File
+ RelativePath="memmgr.h"
+ >
+ </File>
+ <File
+ RelativePath="ModVal.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MTRand.h"
+ >
+ </File>
+ <File
+ RelativePath="PerfTimer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Point.h"
+ >
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Rect.h"
+ >
+ </File>
+ <File
+ RelativePath="ResourceManager.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.h"
+ >
+ </File>
+ <File
+ RelativePath="SexyMatrix.h"
+ >
+ </File>
+ <File
+ RelativePath="SexyVector.h"
+ >
+ </File>
+ <File
+ RelativePath="SmartPtr.h"
+ >
+ </File>
+ <File
+ RelativePath=".\XMLParser.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Sound"
+ >
+ <Filter
+ Name="Sound Source"
+ >
+ <File
+ RelativePath="BassLoader.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="BassLoader.h"
+ >
+ </File>
+ <File
+ RelativePath="BassMusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FModLoader.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Insets.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MusicInterface.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SoundBuild.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Sound Include"
+ >
+ <File
+ RelativePath="BassMusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DSoundManager.h"
+ >
+ </File>
+ <File
+ RelativePath="FModLoader.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.h"
+ >
+ </File>
+ <File
+ RelativePath=".\MusicInterface.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SoundInstance.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SoundManager.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Ogg"
+ >
+ <File
+ RelativePath="ogg\asm_arm.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\backends.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\bitwise.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\block.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codebook.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codebook.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\codec_internal.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\config_types.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\floor0.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\floor1.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\framing.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\info.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ivorbiscodec.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ivorbisfile.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\lsp_lookup.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mapping0.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\mdct_lookup.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\misc.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\ogg.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\os.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\os_types.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\registry.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\registry.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\res012.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\sharedbook.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\synthesis.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\vorbisfile.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window.c"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window.h"
+ >
+ </File>
+ <File
+ RelativePath="ogg\window_lookup.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Widget"
+ >
+ <Filter
+ Name="Widget Source"
+ >
+ <File
+ RelativePath=".\ButtonWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Checkbox.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Dialog.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DialogButton.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\EditWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FlashWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ListWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Slider.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\TextWidget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Widget.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="WidgetBuildBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="WidgetContainer.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\WidgetManager.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Widget Include"
+ >
+ <File
+ RelativePath=".\ButtonListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ButtonWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Checkbox.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CheckboxListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Dialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\DialogButton.h"
+ >
+ </File>
+ <File
+ RelativePath="DialogListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\EditListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\EditWidget.h"
+ >
+ </File>
+ <File
+ RelativePath="FlashWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Insets.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ListListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ListWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ScrollListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Slider.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SliderListener.h"
+ >
+ </File>
+ <File
+ RelativePath=".\TextWidget.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Widget.h"
+ >
+ </File>
+ <File
+ RelativePath="WidgetContainer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\WidgetManager.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="PakLib"
+ >
+ <File
+ RelativePath="..\PakLib\PakInterface.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\PakLib\PakInterface.h"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath="SexyAppBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath="SexyAppBase.h"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/SexyAppFramework/SexyAppBase WideString.vcproj b/osframework/source/SexyAppFramework/SexyAppBase WideString.vcproj
new file mode 100644
index 0000000..df02ee6
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase WideString.vcproj
@@ -0,0 +1,6153 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="SexyAppBase WSTRING"
+ ProjectGUID="{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+ SccProjectName="&quot;$/WinAlch&quot;, YKBAAAAA"
+ SccLocalPath="..\winalch">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32;_DEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32;NDEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug - Zylom|Win32"
+ OutputDirectory="Debug - Zylom"
+ IntermediateDirectory="Debug - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32,_DEBUG,_LIB,ZYLOM"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug - Zylom/"
+ ObjectFile=".\Debug - Zylom/"
+ ProgramDataBaseFileName=".\Debug - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release - Zylom|Win32"
+ OutputDirectory="Release - Zylom"
+ IntermediateDirectory="Release - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32,NDEBUG,_LIB,ZYLOM"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release - Zylom/"
+ ObjectFile=".\Release - Zylom/"
+ ProgramDataBaseFileName=".\Release - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug - Incremental|Win32"
+ OutputDirectory="Debug - Incremental"
+ IntermediateDirectory="Debug - Incremental"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release noop|Win32"
+ OutputDirectory="Release noop"
+ IntermediateDirectory="Release noop"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="_USE_WIDE_STRING;WIN32,NDEBUG,_LIB"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Graphics"
+ Filter="">
+ <Filter
+ Name="Graphics Source"
+ Filter="">
+ <File
+ RelativePath=".\Color.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DTester.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDImage.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Font.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Graphics.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="GraphicsBuild.cpp">
+ </File>
+ <File
+ RelativePath=".\Image.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ImageFont.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MemoryImage.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="NativeDisplay.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Quantize.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SWTri.cpp">
+ </File>
+ <File
+ RelativePath=".\SysFont.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Graphics Include"
+ Filter="">
+ <File
+ RelativePath=".\Color.h">
+ </File>
+ <File
+ RelativePath="D3DInterface.h">
+ </File>
+ <File
+ RelativePath="D3DTester.h">
+ </File>
+ <File
+ RelativePath=".\DDImage.h">
+ </File>
+ <File
+ RelativePath=".\DDInterface.h">
+ </File>
+ <File
+ RelativePath=".\Font.h">
+ </File>
+ <File
+ RelativePath=".\Graphics.h">
+ </File>
+ <File
+ RelativePath=".\Image.h">
+ </File>
+ <File
+ RelativePath=".\ImageFont.h">
+ </File>
+ <File
+ RelativePath=".\MemoryImage.h">
+ </File>
+ <File
+ RelativePath="NativeDisplay.h">
+ </File>
+ <File
+ RelativePath=".\Quantize.h">
+ </File>
+ <File
+ RelativePath="SWTri.h">
+ </File>
+ <File
+ RelativePath=".\SysFont.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Inc Routines"
+ Filter="">
+ <File
+ RelativePath="BltRotatedHelper.inc">
+ </File>
+ <File
+ RelativePath="DDI_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_AlphaBlt.inc">
+ </File>
+ <File
+ RelativePath="DDI_BltRotated.inc">
+ </File>
+ <File
+ RelativePath="DDI_BltRotated_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastBlt_NoAlpha.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastStretch.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastStretch_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_NormalBlt_Volatile.inc">
+ </File>
+ <File
+ RelativePath="MI_AdditiveBlt.inc">
+ </File>
+ <File
+ RelativePath="MI_BltRotated.inc">
+ </File>
+ <File
+ RelativePath="MI_BltRotated_Additive.inc">
+ </File>
+ <File
+ RelativePath="MI_GetNativeAlphaData.inc">
+ </File>
+ <File
+ RelativePath="MI_GetRLAlphaData.inc">
+ </File>
+ <File
+ RelativePath="MI_NormalBlt.inc">
+ </File>
+ <File
+ RelativePath="MI_SlowStretchBlt.inc">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="ImageLib"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\ImageLib.cpp">
+ </File>
+ <File
+ RelativePath="..\ImageLib\ImageLib.h">
+ </File>
+ <Filter
+ Name="PNG"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\png\png.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\png.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngasmrd.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngconf.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngerror.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngget.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngmem.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngpread.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngread.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrtran.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngset.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngtrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngvcrd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwrite.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwtran.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwutil.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG">
+ <File
+ RelativePath="..\ImageLib\jpeg\cderror.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapimin.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapistd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccoefct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccolor.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcdctmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcinit.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmainct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmarker.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmaster.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcomapi.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jconfig.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcparam.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcphuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcprepct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcsample.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jctrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapimin.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapistd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatadst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatasrc.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcoefct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcolor.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdct.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jddctmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdinput.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmainct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmarker.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmaster.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmerge.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdphuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdpostct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdsample.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdtrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctflt.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctfst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctint.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctflt.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctfst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctint.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctred.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jinclude.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemnobs.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemsys.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmorecfg.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpegint.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpeglib.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant1.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant2.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jutils.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jversion.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdbmp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdcolmap.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdgif.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdppm.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdrle.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdswitch.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdtarga.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrbmp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrgif.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrppm.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrrle.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrtarga.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB">
+ <File
+ RelativePath="..\ImageLib\zlib\adler32.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\compress.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\crc32.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\gzio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffixed.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inflate.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\uncompr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zconf.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zlib.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG2000"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config2.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_fix.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_iccdata.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_math.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_types.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jasper.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_fix.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_flt.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Misc"
+ Filter="">
+ <Filter
+ Name="Misc Source"
+ Filter="">
+ <File
+ RelativePath=".\Buffer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Common.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\CritSect.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Debug.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="DirectXErrorString.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="Flags.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\KeyCodes.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MTRand.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="MiscBuildBase.cpp">
+ </File>
+ <File
+ RelativePath="ModVal.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="PerfTimer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="ResourceManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SexyMatrix.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\XMLParser.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Misc Include"
+ Filter="">
+ <File
+ RelativePath=".\AutoCrit.h">
+ </File>
+ <File
+ RelativePath=".\Buffer.h">
+ </File>
+ <File
+ RelativePath=".\Common.h">
+ </File>
+ <File
+ RelativePath=".\CritSect.h">
+ </File>
+ <File
+ RelativePath=".\Debug.h">
+ </File>
+ <File
+ RelativePath="DirectXErrorString.h">
+ </File>
+ <File
+ RelativePath="Flags.h">
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.h">
+ </File>
+ <File
+ RelativePath=".\KeyCodes.h">
+ </File>
+ <File
+ RelativePath=".\MTRand.h">
+ </File>
+ <File
+ RelativePath="ModVal.h">
+ </File>
+ <File
+ RelativePath="PerfTimer.h">
+ </File>
+ <File
+ RelativePath=".\Point.h">
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.h">
+ </File>
+ <File
+ RelativePath=".\Rect.h">
+ </File>
+ <File
+ RelativePath="ResourceManager.h">
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.h">
+ </File>
+ <File
+ RelativePath="SexyMatrix.h">
+ </File>
+ <File
+ RelativePath="SexyVector.h">
+ </File>
+ <File
+ RelativePath="SmartPtr.h">
+ </File>
+ <File
+ RelativePath=".\XMLParser.h">
+ </File>
+ <File
+ RelativePath="memmgr.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Sound"
+ Filter="">
+ <Filter
+ Name="Sound Source"
+ Filter="">
+ <File
+ RelativePath="BassLoader.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="BassLoader.h">
+ </File>
+ <File
+ RelativePath="BassMusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FModLoader.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Insets.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SoundBuild.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Sound Include"
+ Filter="">
+ <File
+ RelativePath="BassMusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\DSoundManager.h">
+ </File>
+ <File
+ RelativePath="FModLoader.h">
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.h">
+ </File>
+ <File
+ RelativePath=".\MusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\SoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\SoundManager.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Ogg"
+ Filter="">
+ <File
+ RelativePath="ogg\asm_arm.h">
+ </File>
+ <File
+ RelativePath="ogg\backends.h">
+ </File>
+ <File
+ RelativePath="ogg\bitwise.c">
+ </File>
+ <File
+ RelativePath="ogg\block.c">
+ </File>
+ <File
+ RelativePath="ogg\codebook.c">
+ </File>
+ <File
+ RelativePath="ogg\codebook.h">
+ </File>
+ <File
+ RelativePath="ogg\codec_internal.h">
+ </File>
+ <File
+ RelativePath="ogg\config_types.h">
+ </File>
+ <File
+ RelativePath="ogg\floor0.c">
+ </File>
+ <File
+ RelativePath="ogg\floor1.c">
+ </File>
+ <File
+ RelativePath="ogg\framing.c">
+ </File>
+ <File
+ RelativePath="ogg\info.c">
+ </File>
+ <File
+ RelativePath="ogg\ivorbiscodec.h">
+ </File>
+ <File
+ RelativePath="ogg\ivorbisfile.h">
+ </File>
+ <File
+ RelativePath="ogg\lsp_lookup.h">
+ </File>
+ <File
+ RelativePath="ogg\mapping0.c">
+ </File>
+ <File
+ RelativePath="ogg\mdct.c">
+ </File>
+ <File
+ RelativePath="ogg\mdct.h">
+ </File>
+ <File
+ RelativePath="ogg\mdct_lookup.h">
+ </File>
+ <File
+ RelativePath="ogg\misc.h">
+ </File>
+ <File
+ RelativePath="ogg\ogg.h">
+ </File>
+ <File
+ RelativePath="ogg\os.h">
+ </File>
+ <File
+ RelativePath="ogg\os_types.h">
+ </File>
+ <File
+ RelativePath="ogg\registry.c">
+ </File>
+ <File
+ RelativePath="ogg\registry.h">
+ </File>
+ <File
+ RelativePath="ogg\res012.c">
+ </File>
+ <File
+ RelativePath="ogg\sharedbook.c">
+ </File>
+ <File
+ RelativePath="ogg\synthesis.c">
+ </File>
+ <File
+ RelativePath="ogg\vorbisfile.c">
+ </File>
+ <File
+ RelativePath="ogg\window.c">
+ </File>
+ <File
+ RelativePath="ogg\window.h">
+ </File>
+ <File
+ RelativePath="ogg\window_lookup.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Widget"
+ Filter="">
+ <Filter
+ Name="Widget Source"
+ Filter="">
+ <File
+ RelativePath=".\ButtonWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Checkbox.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Dialog.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DialogButton.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\EditWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FlashWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ListWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Slider.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\TextWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Widget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="WidgetBuildBase.cpp">
+ </File>
+ <File
+ RelativePath="WidgetContainer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\WidgetManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Widget Include"
+ Filter="">
+ <File
+ RelativePath=".\ButtonListener.h">
+ </File>
+ <File
+ RelativePath=".\ButtonWidget.h">
+ </File>
+ <File
+ RelativePath=".\Checkbox.h">
+ </File>
+ <File
+ RelativePath=".\CheckboxListener.h">
+ </File>
+ <File
+ RelativePath=".\Dialog.h">
+ </File>
+ <File
+ RelativePath=".\DialogButton.h">
+ </File>
+ <File
+ RelativePath="DialogListener.h">
+ </File>
+ <File
+ RelativePath=".\EditListener.h">
+ </File>
+ <File
+ RelativePath=".\EditWidget.h">
+ </File>
+ <File
+ RelativePath="FlashWidget.h">
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.h">
+ </File>
+ <File
+ RelativePath=".\Insets.h">
+ </File>
+ <File
+ RelativePath=".\ListListener.h">
+ </File>
+ <File
+ RelativePath=".\ListWidget.h">
+ </File>
+ <File
+ RelativePath=".\ScrollListener.h">
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.h">
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.h">
+ </File>
+ <File
+ RelativePath=".\Slider.h">
+ </File>
+ <File
+ RelativePath=".\SliderListener.h">
+ </File>
+ <File
+ RelativePath=".\TextWidget.h">
+ </File>
+ <File
+ RelativePath=".\Widget.h">
+ </File>
+ <File
+ RelativePath="WidgetContainer.h">
+ </File>
+ <File
+ RelativePath=".\WidgetManager.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="PakLib"
+ Filter="">
+ <File
+ RelativePath="..\PakLib\PakInterface.cpp">
+ </File>
+ <File
+ RelativePath="..\PakLib\PakInterface.h">
+ </File>
+ </Filter>
+ <File
+ RelativePath="SexyAppBase.cpp">
+ </File>
+ <File
+ RelativePath="SexyAppBase.h">
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/SexyAppFramework/SexyAppBase.cpp b/osframework/source/SexyAppFramework/SexyAppBase.cpp
new file mode 100644
index 0000000..2f2f5fb
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase.cpp
@@ -0,0 +1,7087 @@
+//#define SEXY_TRACING_ENABLED
+//#define SEXY_PERF_ENABLED
+//#define SEXY_MEMTRACE
+
+#include "SexyAppBase.h"
+#include "SEHCatcher.h"
+#include "WidgetManager.h"
+#include "Widget.h"
+#include "Debug.h"
+#include "KeyCodes.h"
+#include "DDInterface.h"
+#include "D3DInterface.h"
+#include "D3DTester.h"
+#include "DDImage.h"
+#include "MemoryImage.h"
+#include "HTTPTransfer.h"
+#include "Dialog.h"
+#include "..\ImageLib\ImageLib.h"
+#include "DSoundManager.h"
+#include "DSoundInstance.h"
+#include "Rect.h"
+#include "FModMusicInterface.h"
+#include "PropertiesParser.h"
+#include "PerfTimer.h"
+#include "MTRand.h"
+#include "ModVal.h"
+#include <process.h>
+#include <direct.h>
+#include <fstream>
+#include <time.h>
+#include <math.h>
+#include <regstr.h>
+#include "SysFont.h"
+#include "ResourceManager.h"
+#include "BassMusicInterface.h"
+#include "AutoCrit.h"
+#include "Debug.h"
+#include "../PakLib/PakInterface.h"
+#include <string>
+#include <shlobj.h>
+
+#include "memmgr.h"
+
+using namespace Sexy;
+
+const int DEMO_FILE_ID = 0x42BEEF78;
+const int DEMO_VERSION = 2;
+
+SexyAppBase* Sexy::gSexyAppBase = NULL;
+
+SEHCatcher Sexy::gSEHCatcher;
+
+HMODULE gDDrawDLL = NULL;
+HMODULE gDSoundDLL = NULL;
+HMODULE gVersionDLL = NULL;
+
+//typedef struct { UINT cbSize; DWORD dwTime; } LASTINPUTINFO;
+typedef BOOL (WINAPI*GetLastInputInfoFunc)(LASTINPUTINFO *plii);
+GetLastInputInfoFunc gGetLastInputInfoFunc = NULL;
+static bool gScreenSaverActive = false;
+
+#ifndef SPI_GETSCREENSAVERRUNNING
+#define SPI_GETSCREENSAVERRUNNING 114
+#endif
+
+
+//HotSpot: 11 4
+//Size: 32 32
+unsigned char gFingerCursorData[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xc3,
+ 0xff, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0xff,
+ 0xc0, 0x07, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xfc, 0x40, 0x01, 0xff, 0xfc, 0x00, 0x01, 0xff,
+ 0xfc, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xff, 0x00, 0x01, 0xff, 0xff, 0x00, 0x01,
+ 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xc0,
+ 0x03, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+ 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
+ 0x18, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1b, 0x60, 0x00, 0x00, 0x1b, 0x68, 0x00,
+ 0x00, 0x1b, 0x6c, 0x00, 0x01, 0x9f, 0xec, 0x00, 0x01, 0xdf, 0xfc, 0x00, 0x00, 0xdf, 0xfc,
+ 0x00, 0x00, 0x5f, 0xfc, 0x00, 0x00, 0x7f, 0xfc, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x3f,
+ 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00,
+ 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+};
+
+//HotSpot: 15 10
+//Size: 32 32
+unsigned char gDraggingCursorData[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xe0,
+ 0x01, 0xff, 0xff, 0xe0, 0x00, 0xff, 0xff, 0xe0, 0x00, 0xff, 0xff, 0xe0, 0x00, 0xff, 0xff,
+ 0xe0, 0x00, 0xff, 0xfe, 0x60, 0x00, 0xff, 0xfc, 0x20, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff,
+ 0xfe, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00,
+ 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xf0,
+ 0x03, 0xff, 0xff, 0xf8, 0x03, 0xff, 0xff, 0xf8, 0x03, 0xff, 0xff, 0xf8, 0x03, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x80, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x0d, 0xb0, 0x00, 0x00, 0x0d, 0xb6, 0x00, 0x00,
+ 0x0d, 0xb6, 0x00, 0x00, 0x0d, 0xb6, 0x00, 0x00, 0x0d, 0xb6, 0x00, 0x00, 0x0d, 0xb6, 0x00,
+ 0x01, 0x8d, 0xb6, 0x00, 0x01, 0xcf, 0xfe, 0x00, 0x00, 0xef, 0xfe, 0x00, 0x00, 0xff, 0xfe,
+ 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x1f,
+ 0xfc, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00,
+ 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+};
+static DDImage* gFPSImage = NULL;
+
+//////////////////////////////////////////////////////////////////////////
+
+typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND, int, HANDLE, DWORD, LPTSTR);
+void* GetSHGetFolderPath(const char* theDLL, HMODULE* theMod)
+{
+ HMODULE aMod = LoadLibrary(theDLL);
+ SHGetFolderPathFunc aFunc = NULL;
+
+ if (aMod != NULL)
+ {
+ *((void**)&aFunc) = (void*)GetProcAddress(aMod, "SHGetFolderPathA");
+ if (aFunc == NULL)
+ {
+ FreeLibrary(aMod);
+ aMod = NULL;
+ }
+ }
+
+ *theMod = aMod;
+ return aFunc;
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+SexyAppBase::SexyAppBase()
+{
+ gSexyAppBase = this;
+
+ gVersionDLL = LoadLibraryA("version.dll");
+ gDDrawDLL = LoadLibraryA("ddraw.dll");
+ gDSoundDLL = LoadLibraryA("dsound.dll");
+ gGetLastInputInfoFunc = (GetLastInputInfoFunc) GetProcAddress(GetModuleHandleA("user32.dll"),"GetLastInputInfo");
+
+ ImageLib::InitJPEG2000();
+
+ mMutex = NULL;
+ mNotifyGameMessage = 0;
+
+#ifdef _DEBUG
+ mOnlyAllowOneCopyToRun = false;
+#else
+ mOnlyAllowOneCopyToRun = true;
+#endif
+
+ // Extract product version
+ char aPath[_MAX_PATH];
+ GetModuleFileNameA(NULL, aPath, 256);
+ mProductVersion = GetProductVersion(aPath);
+ mChangeDirTo = GetFileDir(aPath);
+
+ mNoDefer = false;
+ mFullScreenPageFlip = true; // should we page flip in fullscreen?
+ mTimeLoaded = GetTickCount();
+ mSEHOccured = false;
+ mProdName = "Product";
+ mTitle = _S("SexyApp");
+ mShutdown = false;
+ mExitToTop = false;
+ mWidth = 640;
+ mHeight = 480;
+ mFullscreenBits = 16;
+ mIsWindowed = true;
+ mIsPhysWindowed = true;
+ mFullScreenWindow = false;
+ mPreferredX = -1;
+ mPreferredY = -1;
+ mIsScreenSaver = false;
+ mAllowMonitorPowersave = true;
+ mHWnd = NULL;
+ mDDInterface = NULL;
+ mMusicInterface = NULL;
+ mInvisHWnd = NULL;
+ mFrameTime = 10;
+ mNonDrawCount = 0;
+ mDrawCount = 0;
+ mSleepCount = 0;
+ mUpdateCount = 0;
+ mUpdateAppState = 0;
+ mUpdateAppDepth = 0;
+ mPendingUpdatesAcc = 0.0;
+ mUpdateFTimeAcc = 0.0;
+ mHasPendingDraw = true;
+ mIsDrawing = false;
+ mLastDrawWasEmpty = false;
+ mLastTimeCheck = 0;
+ mUpdateMultiplier = 1;
+ mPaused = false;
+ mFastForwardToUpdateNum = 0;
+ mFastForwardToMarker = false;
+ mFastForwardStep = false;
+ mSoundManager = NULL;
+ mCursorNum = CURSOR_POINTER;
+ mMouseIn = false;
+ mRunning = false;
+ mActive = true;
+ mProcessInTimer = false;
+ mMinimized = false;
+ mPhysMinimized = false;
+ mIsDisabled = false;
+ mLoaded = false;
+ mYieldMainThread = false;
+ mLoadingFailed = false;
+ mLoadingThreadStarted = false;
+ mAutoStartLoadingThread = true;
+ mLoadingThreadCompleted = false;
+ mCursorThreadRunning = false;
+ mNumLoadingThreadTasks = 0;
+ mCompletedLoadingThreadTasks = 0;
+ mLastDrawTick = timeGetTime();
+ mNextDrawTick = timeGetTime();
+ mSysCursor = true;
+ mForceFullscreen = false;
+ mForceWindowed = false;
+ mHasFocus = true;
+ mCustomCursorsEnabled = false;
+ mCustomCursorDirty = false;
+ mOverrideCursor = NULL;
+ mIsOpeningURL = false;
+ mInitialized = false;
+ mLastShutdownWasGraceful = true;
+ mReadFromRegistry = false;
+ mCmdLineParsed = false;
+ mSkipSignatureChecks = false;
+ mCtrlDown = false;
+ mAltDown = false;
+ mStepMode = 0;
+ mCleanupSharedImages = false;
+ mStandardWordWrap = true;
+ mbAllowExtendedChars = true;
+ mEnableMaximizeButton = false;
+
+ mMusicVolume = 0.85;
+ mSfxVolume = 0.85;
+ mDemoMusicVolume = mDemoSfxVolume = 0.0;
+ mMuteCount = 0;
+ mAutoMuteCount = 0;
+ mDemoMute = false;
+ mMuteOnLostFocus = true;
+ mCurHandleNum = 0;
+ mFPSTime = 0;
+ mFPSStartTick = GetTickCount();
+ mFPSFlipCount = 0;
+ mFPSCount = 0;
+ mFPSDirtyCount = 0;
+ mShowFPS = false;
+ mShowFPSMode = FPS_ShowFPS;
+ mDrawTime = 0;
+ mScreenBltTime = 0;
+ mAlphaDisabled = false;
+ mDebugKeysEnabled = false;
+ mOldWndProc = 0;
+ mNoSoundNeeded = false;
+ mWantFMod = false;
+
+ mSyncRefreshRate = 100;
+ mVSyncUpdates = false;
+ mVSyncBroken = false;
+ mVSyncBrokenCount = 0;
+ mVSyncBrokenTestStartTick = 0;
+ mVSyncBrokenTestUpdates = 0;
+ mWaitForVSync = false;
+ mSoftVSyncWait = true;
+ mUserChanged3DSetting = false;
+ mAutoEnable3D = false;
+ mTest3D = false;
+ mMinVidMemory3D = 6;
+ mRecommendedVidMemory3D = 14;
+ mRelaxUpdateBacklogCount = 0;
+ mWidescreenAware = false;
+ mEnableWindowAspect = false;
+ mWindowAspect.Set(4, 3);
+ mIsWideWindow = false;
+
+ int i;
+
+ for (i = 0; i < NUM_CURSORS; i++)
+ mCursorImages[i] = NULL;
+
+ for (i = 0; i < 256; i++)
+ mAdd8BitMaxTable[i] = i;
+
+ for (i = 256; i < 512; i++)
+ mAdd8BitMaxTable[i] = 255;
+
+ // Set default strings. Init could read in overrides from partner.xml
+ SetString("DIALOG_BUTTON_OK", L"OK");
+ SetString("DIALOG_BUTTON_CANCEL", L"CANCEL");
+
+ SetString("UPDATE_CHECK_TITLE", L"Update Check");
+ SetString("UPDATE_CHECK_BODY", L"Checking if there are any updates available for this product ...");
+
+ SetString("UP_TO_DATE_TITLE", L"Up to Date");
+ SetString("UP_TO_DATE_BODY", L"There are no updates available for this product at this time.");
+ SetString("NEW_VERSION_TITLE", L"New Version");
+ SetString("NEW_VERSION_BODY", L"There is an update available for this product. Would you like to visit the web site to download it?");
+
+
+ mDemoPrefix = "sexyapp";
+ mDemoFileName = mDemoPrefix + ".dmo";
+ mPlayingDemoBuffer = false;
+ mManualShutdown = false;
+ mRecordingDemoBuffer = false;
+ mLastDemoMouseX = 0;
+ mLastDemoMouseY = 0;
+ mLastDemoUpdateCnt = 0;
+ mDemoNeedsCommand = true;
+ mDemoLoadingComplete = false;
+ mDemoLength = 0;
+ mDemoCmdNum = 0;
+ mDemoCmdOrder = -1; // Means we haven't processed any demo commands yet
+ mDemoCmdBitPos = 0;
+
+ mWidgetManager = new WidgetManager(this);
+ mResourceManager = new ResourceManager(this);
+
+ mPrimaryThreadId = 0;
+
+ if (GetSystemMetrics(86)) // check for tablet pc
+ {
+ mTabletPC = true;
+ mFullScreenPageFlip = false; // so that tablet keyboard can show up
+ }
+ else
+ mTabletPC = false;
+
+ gSEHCatcher.mApp = this;
+
+ //std::wifstream stringsFile(_wfopen(L".\\properties\\fstrings", L"rb"));
+ //
+ //if(!stringsFile)
+ //{
+ // MessageBox(NULL, "file missing: 'install-folder\\properties\\fstrings' Please re-install", "FATAL ERROR", MB_OK);
+ // DoExit(1);
+ //}
+ //std::getline(stringsFile, mString_HardwareAccelSwitchedOn);
+ //std::getline(stringsFile, mString_HardwareAccelConfirm);
+ //std::getline(stringsFile, mString_HardwareAccelNotWorking);
+ //std::getline(stringsFile, mString_SetColorDepth);
+ //std::getline(stringsFile, mString_FailedInitDirectDrawColon);
+ //std::getline(stringsFile, mString_UnableOpenProperties);
+ //std::getline(stringsFile, mString_SigCheckFailed);
+ //std::getline(stringsFile, mString_InvalidCommandLineParam);
+ //std::getline(stringsFile, mString_RequiresDirectX);
+ //std::getline(stringsFile, mString_YouNeedDirectX);
+ //std::getline(stringsFile, mString_FailedInitDirectDraw);
+ //std::getline(stringsFile, mString_FatalError);
+ //std::getline(stringsFile, mString_UnexpectedErrorOccured);
+ //std::getline(stringsFile, mString_PleaseHelpBy);
+ //std::getline(stringsFile, mString_FailedConnectPopcap);
+ //stringsFile.close();
+}
+
+SexyAppBase::~SexyAppBase()
+{
+ Shutdown();
+
+ // Check if we should write the current 3d setting
+ bool showedMsgBox = false;
+ if (mUserChanged3DSetting)
+ {
+ bool writeToRegistry = true;
+ bool is3D = false;
+ bool is3DOptionSet = RegistryReadBoolean("Is3D", &is3D);
+ if(!is3DOptionSet) // should we write the option?
+ {
+ if(!Is3DAccelerationRecommended()) // may need to prompt user if he wants to keep 3d acceleration on
+ {
+ if (Is3DAccelerated())
+ {
+ showedMsgBox = true;
+ int aResult = MessageBox(NULL,
+ GetString("HARDWARE_ACCEL_SWITCHED_ON",
+ _S("Hardware Acceleration was switched on during this session.\r\n")
+ _S("If this resulted in slower performance, it should be switched off.\r\n")
+ _S("Would you like to keep Hardware Acceleration switched on?")).c_str(),
+ (StringToSexyString(mCompanyName) + _S(" ") +
+ GetString("HARDWARE_ACCEL_CONFIRMATION", _S("Hardware Acceleration Confirmation"))).c_str(),
+ MB_YESNO | MB_ICONQUESTION);
+
+ mDDInterface->mIs3D = aResult == IDYES ? true : false;
+ if (aResult!=IDYES)
+ writeToRegistry = false;
+ }
+ else
+ writeToRegistry = false;
+ }
+ }
+
+ if (writeToRegistry)
+ RegistryWriteBoolean("Is3D", mDDInterface->mIs3D);
+ }
+
+ extern bool gD3DInterfacePreDrawError;
+ if (!showedMsgBox && gD3DInterfacePreDrawError && !IsScreenSaver())
+ {
+ int aResult = MessageBox(NULL,
+ GetString("HARDWARE_ACCEL_NOT_WORKING",
+ _S("Hardware Acceleration may not have been working correctly during this session.\r\n")
+ _S("If you noticed graphics problems, you may want to turn off Hardware Acceleration.\r\n")
+ _S("Would you like to keep Hardware Acceleration switched on?")).c_str(),
+ (StringToSexyString(mCompanyName) + _S(" ") +
+ GetString("HARDWARE_ACCEL_CONFIRMATION", _S("Hardware Acceleration Confirmation"))).c_str(),
+ MB_YESNO | MB_ICONQUESTION);
+
+ if (aResult==IDNO)
+ RegistryWriteBoolean("Is3D", false);
+ }
+
+
+ DialogMap::iterator aDialogItr = mDialogMap.begin();
+ while (aDialogItr != mDialogMap.end())
+ {
+ mWidgetManager->RemoveWidget(aDialogItr->second);
+ delete aDialogItr->second;
+ ++aDialogItr;
+ }
+ mDialogMap.clear();
+ mDialogList.clear();
+
+ if (mInvisHWnd != NULL)
+ {
+ HWND aWindow = mInvisHWnd;
+ mInvisHWnd = NULL;
+ SetWindowLong(aWindow, GWL_USERDATA, NULL);
+ DestroyWindow(aWindow);
+ }
+
+ delete mWidgetManager;
+ delete mResourceManager;
+ delete gFPSImage;
+ gFPSImage = NULL;
+
+ SharedImageMap::iterator aSharedImageItr = mSharedImageMap.begin();
+ while (aSharedImageItr != mSharedImageMap.end())
+ {
+ SharedImage* aSharedImage = &aSharedImageItr->second;
+ DBG_ASSERTE(aSharedImage->mRefCount == 0);
+ delete aSharedImage->mImage;
+ mSharedImageMap.erase(aSharedImageItr++);
+ }
+
+ delete mDDInterface;
+ delete mMusicInterface;
+ delete mSoundManager;
+
+ if (mHWnd != NULL)
+ {
+ HWND aWindow = mHWnd;
+ mHWnd = NULL;
+
+ SetWindowLong(aWindow, GWL_USERDATA, NULL);
+
+ /*char aStr[256];
+ sprintf(aStr, "HWND: %d\r\n", aWindow);
+ OutputDebugString(aStr);*/
+
+ DestroyWindow(aWindow);
+ }
+
+ WaitForLoadingThread();
+
+ DestroyCursor(mHandCursor);
+ DestroyCursor(mDraggingCursor);
+
+ gSexyAppBase = NULL;
+
+ WriteDemoBuffer();
+
+ if (mMutex != NULL)
+ ::CloseHandle(mMutex);
+
+ FreeLibrary(gDDrawDLL);
+ FreeLibrary(gDSoundDLL);
+ FreeLibrary(gVersionDLL);
+}
+
+static BOOL CALLBACK ChangeDisplayWindowEnumProc(HWND hwnd, LPARAM lParam)
+{
+ typedef std::map<HWND,RECT> WindowMap;
+ static WindowMap aMap;
+
+ if (lParam==0 && aMap.find(hwnd)==aMap.end()) // record
+ {
+ RECT aRect;
+ if (!IsIconic(hwnd) && IsWindowVisible(hwnd))
+ {
+ if (GetWindowRect(hwnd,&aRect))
+ {
+// char aBuf[4096];
+// GetWindowText(hwnd,aBuf,4000);
+// DWORD aProcessId = 0;
+// GetWindowThreadProcessId(hwnd,&aProcessId);
+// SEXY_TRACE(StrFormat("%s %d - %d %d %d %d",aBuf,aProcessId,aRect.left,aRect.top,aRect.right,aRect.bottom).c_str());
+ aMap[hwnd] = aRect;
+ }
+ }
+ }
+ else
+ {
+ WindowMap::iterator anItr = aMap.find(hwnd);
+ if (anItr != aMap.end())
+ {
+ RECT &r = anItr->second;
+ MoveWindow(hwnd,r.left,r.top,abs(r.right-r.left),abs(r.bottom-r.top),TRUE);
+ }
+ }
+ return TRUE;
+}
+
+void SexyAppBase::ClearUpdateBacklog(bool relaxForASecond)
+{
+ mLastTimeCheck = timeGetTime();
+ mUpdateFTimeAcc = 0.0;
+
+ if (relaxForASecond)
+ mRelaxUpdateBacklogCount = 1000;
+}
+
+bool SexyAppBase::IsScreenSaver()
+{
+ return mIsScreenSaver;
+}
+
+bool SexyAppBase::AppCanRestore()
+{
+ return !mIsDisabled;
+}
+
+bool SexyAppBase::ReadDemoBuffer(std::string &theError)
+{
+ FILE* aFP = fopen(mDemoFileName.c_str(), "rb");
+
+ if (aFP == NULL)
+ {
+ theError = "Demo file not found: " + mDemoFileName;
+ return false;
+ }
+
+ struct AutoFile { FILE *f; AutoFile(FILE *file) : f(file) {} ~AutoFile() { fclose(f); } };
+ AutoFile aCloseFile(aFP);
+
+ ulong aFileID;
+ fread(&aFileID, 4, 1, aFP);
+
+ DBG_ASSERTE(aFileID == DEMO_FILE_ID);
+ if (aFileID != DEMO_FILE_ID)
+ {
+ theError = "Invalid demo file.";
+ return false;
+ }
+
+
+ ulong aVersion;
+ fread(&aVersion, 4, 1, aFP);
+
+ fread(&mRandSeed, 4, 1, aFP);
+ SRand(mRandSeed);
+
+ ushort aStrLen = 4;
+ fread(&aStrLen, 2, 1, aFP);
+ if (aStrLen > 255)
+ aStrLen = 255;
+ char aStr[256];
+ fread(aStr, 1, aStrLen, aFP);
+ aStr[aStrLen] = '\0';
+
+ DBG_ASSERTE(mProductVersion == aStr);
+ if (mProductVersion != aStr)
+ {
+ theError = "This demo file appears to be for '" + std::string(aStr) + "'";
+ return false;
+ }
+
+ int aFilePos = ftell(aFP);
+ fseek(aFP, 0, SEEK_END);
+ int aBytesLeft = ftell(aFP) - aFilePos;
+ fseek(aFP, aFilePos, SEEK_SET);
+
+ uchar* aBuffer;
+ // read marker list
+ if (aVersion >= 2)
+ {
+ int aSize;
+ fread(&aSize, 4, 1, aFP);
+ aBytesLeft -= 4;
+
+ if (aSize >= aBytesLeft)
+ {
+ theError = "Invalid demo file.";
+ return false;
+ }
+
+ Buffer aMarkerBuffer;
+
+ aBuffer = new uchar[aSize];
+ fread(aBuffer, 1, aSize, aFP);
+ aMarkerBuffer.WriteBytes(aBuffer, aSize);
+ aMarkerBuffer.SeekFront();
+
+ int aNumItems = aMarkerBuffer.ReadLong();
+ int i;
+ for (i=0; i<aNumItems && !aMarkerBuffer.AtEnd(); i++)
+ {
+ mDemoMarkerList.push_back(DemoMarker());
+ DemoMarker &aMarker = mDemoMarkerList.back();
+ aMarker.first = aMarkerBuffer.ReadString();
+ aMarker.second = aMarkerBuffer.ReadLong();
+ }
+
+ if (i!=aNumItems)
+ {
+ theError = "Invalid demo file.";
+ return false;
+ }
+
+ aBytesLeft -= aSize;
+
+ delete [] aBuffer;
+ }
+
+ // Read demo commands
+ fread(&mDemoLength, 4, 1, aFP);
+ aBytesLeft -= 4;
+
+ if (aBytesLeft <= 0)
+ {
+ theError = "Invalid demo file.";
+ return false;
+ }
+
+
+ aBuffer = new uchar[aBytesLeft];
+ fread(aBuffer, 1, aBytesLeft, aFP);
+
+ mDemoBuffer.WriteBytes(aBuffer, aBytesLeft);
+ mDemoBuffer.SeekFront();
+
+ delete [] aBuffer;
+ return true;
+}
+
+void SexyAppBase::WriteDemoBuffer()
+{
+ if (mRecordingDemoBuffer)
+ {
+ FILE* aFP = fopen(mDemoFileName.c_str(), "w+b");
+
+ if (aFP != NULL)
+ {
+ ulong aFileID = DEMO_FILE_ID;
+ fwrite(&aFileID, 4, 1, aFP);
+
+ ulong aVersion = DEMO_VERSION;
+ fwrite(&aVersion, 4, 1, aFP);
+
+ fwrite(&mRandSeed, 4, 1, aFP);
+
+ ushort aStrLen = mProductVersion.length();
+ fwrite(&aStrLen, 2, 1, aFP);
+ fwrite(mProductVersion.c_str(), 1, mProductVersion.length(), aFP);
+
+ Buffer aMarkerBuffer;
+ aMarkerBuffer.WriteLong(mDemoMarkerList.size());
+ for (DemoMarkerList::iterator aMarkerItr = mDemoMarkerList.begin(); aMarkerItr != mDemoMarkerList.end(); ++aMarkerItr)
+ {
+ aMarkerBuffer.WriteString(aMarkerItr->first);
+ aMarkerBuffer.WriteLong(aMarkerItr->second);
+ }
+ int aMarkerBufferSize = aMarkerBuffer.GetDataLen();
+ fwrite(&aMarkerBufferSize, 4, 1, aFP);
+ fwrite(aMarkerBuffer.GetDataPtr(), aMarkerBufferSize, 1, aFP);
+
+ ulong aDemoLength = mUpdateCount;
+ fwrite(&aDemoLength, 4, 1, aFP);
+
+ fwrite(mDemoBuffer.GetDataPtr(), 1, mDemoBuffer.GetDataLen(), aFP);
+ fclose(aFP);
+ }
+ }
+}
+
+void SexyAppBase::DemoSyncBuffer(Buffer* theBuffer)
+{
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_SYNC);
+
+ ulong aLen = mDemoBuffer.ReadLong();
+
+ theBuffer->Clear();
+ for (int i = 0; i < (int) aLen; i++)
+ theBuffer->WriteByte(mDemoBuffer.ReadByte());
+ }
+ else if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_SYNC, 5);
+ mDemoBuffer.WriteLong(theBuffer->GetDataLen());
+ mDemoBuffer.WriteBytes((uchar*) theBuffer->GetDataPtr(), theBuffer->GetDataLen());
+ }
+}
+
+void SexyAppBase::DemoSyncString(std::string* theString)
+{
+ Buffer aBuffer;
+ aBuffer.WriteString(*theString);
+ DemoSyncBuffer(&aBuffer);
+ *theString = aBuffer.ReadString();
+}
+
+void SexyAppBase::DemoSyncInt(int* theInt)
+{
+ Buffer aBuffer;
+ aBuffer.WriteLong(*theInt);
+ DemoSyncBuffer(&aBuffer);
+ *theInt = aBuffer.ReadLong();
+}
+
+void SexyAppBase::DemoSyncBool(bool* theBool)
+{
+ Buffer aBuffer;
+ aBuffer.WriteBoolean(*theBool);
+ DemoSyncBuffer(&aBuffer);
+ *theBool = aBuffer.ReadBoolean();
+}
+
+void SexyAppBase::DemoAssertStringEqual(const std::string& theString)
+{
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_ASSERT_STRING_EQUAL);
+
+ std::string aString = mDemoBuffer.ReadString();
+ DBG_ASSERTE(aString == theString);
+ }
+ else if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_ASSERT_STRING_EQUAL, 5);
+ mDemoBuffer.WriteString(theString);
+ }
+}
+
+void SexyAppBase::DemoAddMarker(const std::string& theString)
+{
+ if (mPlayingDemoBuffer)
+ {
+ mFastForwardToMarker = false;
+ }
+ else if (mRecordingDemoBuffer)
+ {
+ mDemoMarkerList.push_back(DemoMarker(theString,mUpdateCount));
+ }
+}
+
+void SexyAppBase::DemoRegisterHandle(HANDLE theHandle)
+{
+ if ((mRecordingDemoBuffer) || (mPlayingDemoBuffer))
+ {
+ // Insert the handle into a map with an auto-incrementing number so
+ // we can match up the auto-incrementing numbers with the handle
+ // later on, as handles may not be the same between executions
+ std::pair<HandleToIntMap::iterator, bool> aPair = mHandleToIntMap.insert(HandleToIntMap::value_type(theHandle, mCurHandleNum));
+ DBG_ASSERT(aPair.second);
+ mCurHandleNum++;
+ }
+}
+
+void SexyAppBase::DemoWaitForHandle(HANDLE theHandle)
+{
+ WaitForSingleObject(theHandle, INFINITE);
+
+ if ((mRecordingDemoBuffer) || (mPlayingDemoBuffer))
+ {
+ // Remove the handle from our waiting map
+ HandleToIntMap::iterator anItr = mHandleToIntMap.find(theHandle);
+ DBG_ASSERT(anItr != mHandleToIntMap.end());
+ mHandleToIntMap.erase(anItr);
+ }
+}
+
+bool SexyAppBase::DemoCheckHandle(HANDLE theHandle)
+{
+ if (mPlayingDemoBuffer)
+ {
+ // We only need to try to get the result if we think we are waiting for one
+ if (gSexyAppBase->PrepareDemoCommand(false))
+ {
+ if ((!gSexyAppBase->mDemoIsShortCmd) && (gSexyAppBase->mDemoCmdNum == DEMO_HANDLE_COMPLETE))
+ {
+ // Find auto-incrementing handle num from handle
+ HandleToIntMap::iterator anItr = mHandleToIntMap.find(theHandle);
+ DBG_ASSERT(anItr != mHandleToIntMap.end());
+
+ int anOldBufferPos = gSexyAppBase->mDemoBuffer.mReadBitPos;
+
+ // Since we don't require a demo result entry to be here, we must verify
+ // that this is referring to us
+ int aDemoHandleNum = gSexyAppBase->mDemoBuffer.ReadLong();
+
+ if (aDemoHandleNum == anItr->second)
+ {
+ // Alright, this was the handle we were waiting for!
+ gSexyAppBase->mDemoNeedsCommand = true;
+
+ // Actually wait for our local buddy to complete
+ WaitForSingleObject(theHandle, INFINITE);
+ mHandleToIntMap.erase(anItr);
+
+ return true;
+ }
+ else
+ {
+ // Not us, go back
+ gSexyAppBase->mDemoBuffer.mReadBitPos = anOldBufferPos;
+ }
+ }
+ }
+
+ return false;
+ }
+ else
+ {
+ if (WaitForSingleObject(theHandle, 0) == WAIT_OBJECT_0)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ // Find auto-incrementing handle num from handle
+ HandleToIntMap::iterator anItr = mHandleToIntMap.find(theHandle);
+ DBG_ASSERT(anItr != mHandleToIntMap.end());
+
+ gSexyAppBase->WriteDemoTimingBlock();
+ gSexyAppBase->mDemoBuffer.WriteNumBits(0, 1);
+ gSexyAppBase->mDemoBuffer.WriteNumBits(DEMO_HANDLE_COMPLETE, 5);
+ gSexyAppBase->mDemoBuffer.WriteLong(anItr->second);
+
+ mHandleToIntMap.erase(anItr);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+}
+
+void SexyAppBase::DemoAssertIntEqual(int theInt)
+{
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_ASSERT_INT_EQUAL);
+
+ int anInt = mDemoBuffer.ReadLong();
+ DBG_ASSERTE(anInt == theInt);
+ }
+ else if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_ASSERT_INT_EQUAL, 5);
+ mDemoBuffer.WriteLong(theInt);
+ }
+}
+
+Dialog* SexyAppBase::NewDialog(int theDialogId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode)
+{
+ Dialog* aDialog = new Dialog(NULL, NULL, theDialogId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode);
+ return aDialog;
+}
+
+Dialog* SexyAppBase::DoDialog(int theDialogId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode)
+{
+ KillDialog(theDialogId);
+
+ Dialog* aDialog = NewDialog(theDialogId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode);
+
+ AddDialog(theDialogId, aDialog);
+
+ return aDialog;
+}
+
+
+Dialog* SexyAppBase::GetDialog(int theDialogId)
+{
+ DialogMap::iterator anItr = mDialogMap.find(theDialogId);
+
+ if (anItr != mDialogMap.end())
+ return anItr->second;
+
+ return NULL;
+}
+
+bool SexyAppBase::KillDialog(int theDialogId, bool removeWidget, bool deleteWidget)
+{
+ DialogMap::iterator anItr = mDialogMap.find(theDialogId);
+
+ if (anItr != mDialogMap.end())
+ {
+ Dialog* aDialog = anItr->second;
+
+ // set the result to something else so DoMainLoop knows that the dialog is gone
+ // in case nobody else sets mResult
+ if (aDialog->mResult == -1)
+ aDialog->mResult = 0;
+
+ DialogList::iterator aListItr = std::find(mDialogList.begin(),mDialogList.end(),aDialog);
+ if (aListItr != mDialogList.end())
+ mDialogList.erase(aListItr);
+
+ mDialogMap.erase(anItr);
+
+ if (removeWidget || deleteWidget)
+ mWidgetManager->RemoveWidget(aDialog);
+
+ if (aDialog->IsModal())
+ {
+ ModalClose();
+ mWidgetManager->RemoveBaseModal(aDialog);
+ }
+
+ if (deleteWidget)
+ SafeDeleteWidget(aDialog);
+
+ return true;
+ }
+
+ return false;
+}
+
+bool SexyAppBase::KillDialog(int theDialogId)
+{
+ return KillDialog(theDialogId,true,true);
+}
+
+bool SexyAppBase::KillDialog(Dialog* theDialog)
+{
+ return KillDialog(theDialog->mId);
+}
+
+int SexyAppBase::GetDialogCount()
+{
+ return mDialogMap.size();
+}
+
+void SexyAppBase::AddDialog(int theDialogId, Dialog* theDialog)
+{
+ KillDialog(theDialogId);
+
+ if (theDialog->mWidth == 0)
+ {
+ // Set the dialog position ourselves
+ int aWidth = mWidth/2;
+ theDialog->Resize((mWidth - aWidth)/2, mHeight / 5, aWidth, theDialog->GetPreferredHeight(aWidth));
+ }
+
+ mDialogMap.insert(DialogMap::value_type(theDialogId, theDialog));
+ mDialogList.push_back(theDialog);
+
+ mWidgetManager->AddWidget(theDialog);
+ if (theDialog->IsModal())
+ {
+ mWidgetManager->AddBaseModal(theDialog);
+ ModalOpen();
+ }
+}
+
+void SexyAppBase::AddDialog(Dialog* theDialog)
+{
+ AddDialog(theDialog->mId, theDialog);
+}
+
+void SexyAppBase::ModalOpen()
+{
+}
+
+void SexyAppBase::ModalClose()
+{
+}
+
+void SexyAppBase::DialogButtonPress(int theDialogId, int theButtonId)
+{
+ if (theButtonId == Dialog::ID_YES)
+ ButtonPress(2000 + theDialogId);
+ else if (theButtonId == Dialog::ID_NO)
+ ButtonPress(3000 + theDialogId);
+}
+
+void SexyAppBase::DialogButtonDepress(int theDialogId, int theButtonId)
+{
+ if (theButtonId == Dialog::ID_YES)
+ ButtonDepress(2000 + theDialogId);
+ else if (theButtonId == Dialog::ID_NO)
+ ButtonDepress(3000 + theDialogId);
+}
+
+void SexyAppBase::GotFocus()
+{
+}
+
+void SexyAppBase::LostFocus()
+{
+}
+
+void SexyAppBase::URLOpenFailed(const std::string& theURL)
+{
+ mIsOpeningURL = false;
+}
+
+void SexyAppBase::URLOpenSucceeded(const std::string& theURL)
+{
+ mIsOpeningURL = false;
+
+ if (mShutdownOnURLOpen)
+ Shutdown();
+}
+
+bool SexyAppBase::OpenURL(const std::string& theURL, bool shutdownOnOpen)
+{
+ if ((!mIsOpeningURL) || (theURL != mOpeningURL))
+ {
+ mShutdownOnURLOpen = shutdownOnOpen;
+ mIsOpeningURL = true;
+ mOpeningURL = theURL;
+ mOpeningURLTime = GetTickCount();
+
+ if ((int) ShellExecuteA(NULL, "open", theURL.c_str(), NULL, NULL, SW_SHOWNORMAL) > 32)
+ {
+ return true;
+ }
+ else
+ {
+ URLOpenFailed(theURL);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+std::string SexyAppBase::GetProductVersion(const std::string& thePath)
+{
+ // Dynamically Load Version.dll
+ typedef DWORD (APIENTRY *GetFileVersionInfoSizeFunc)(LPSTR lptstrFilename, LPDWORD lpdwHandle);
+ typedef BOOL (APIENTRY *GetFileVersionInfoFunc)(LPSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData);
+ typedef BOOL (APIENTRY *VerQueryValueFunc)(const LPVOID pBlock, LPSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen);
+
+ static GetFileVersionInfoSizeFunc aGetFileVersionInfoSizeFunc = NULL;
+ static GetFileVersionInfoFunc aGetFileVersionInfoFunc = NULL;
+ static VerQueryValueFunc aVerQueryValueFunc = NULL;
+
+ if (aGetFileVersionInfoSizeFunc==NULL)
+ {
+ aGetFileVersionInfoSizeFunc = (GetFileVersionInfoSizeFunc)GetProcAddress(gVersionDLL,"GetFileVersionInfoSizeA");
+ aGetFileVersionInfoFunc = (GetFileVersionInfoFunc)GetProcAddress(gVersionDLL,"GetFileVersionInfoA");
+ aVerQueryValueFunc = (VerQueryValueFunc)GetProcAddress(gVersionDLL,"VerQueryValueA");
+ }
+
+ // Get Product Version
+ std::string aProductVersion;
+
+ uint aSize = aGetFileVersionInfoSizeFunc((char*) thePath.c_str(), 0);
+ if (aSize > 0)
+ {
+ uchar* aVersionBuffer = new uchar[aSize];
+ aGetFileVersionInfoFunc((char*) thePath.c_str(), 0, aSize, aVersionBuffer);
+ char* aBuffer;
+ if (aVerQueryValueFunc(aVersionBuffer,
+ "\\StringFileInfo\\040904B0\\ProductVersion",
+ (void**) &aBuffer,
+ &aSize))
+ {
+ aProductVersion = aBuffer;
+ }
+ else if (aVerQueryValueFunc(aVersionBuffer,
+ "\\StringFileInfo\\040904E4\\ProductVersion",
+ (void**) &aBuffer,
+ &aSize))
+ {
+ aProductVersion = aBuffer;
+ }
+
+ delete aVersionBuffer;
+ }
+
+ return aProductVersion;
+}
+
+void SexyAppBase::WaitForLoadingThread()
+{
+ while ((mLoadingThreadStarted) && (!mLoadingThreadCompleted))
+ Sleep(20);
+}
+
+void SexyAppBase::SetCursorImage(int theCursorNum, Image* theImage)
+{
+ if ((theCursorNum >= 0) && (theCursorNum < NUM_CURSORS))
+ {
+ mCursorImages[theCursorNum] = theImage;
+ EnforceCursor();
+ }
+}
+
+void SexyAppBase::TakeScreenshot()
+{
+ if (mDDInterface==NULL || mDDInterface->mDrawSurface==NULL)
+ return;
+
+ // Get free image name
+ std::string anImageDir = GetAppDataFolder() + "_screenshots";
+ MkDir(anImageDir);
+ anImageDir += "/";
+
+ WIN32_FIND_DATAA aData;
+ int aMaxId = 0;
+ std::string anImagePrefix = "image";
+ HANDLE aHandle = FindFirstFileA((anImageDir + "*.png").c_str(), &aData);
+ if (aHandle!=INVALID_HANDLE_VALUE)
+ {
+ do {
+ int aNum = 0;
+ if (sscanf(aData.cFileName,(anImagePrefix + "%d.png").c_str(), &aNum)==1)
+ {
+ if (aNum>aMaxId)
+ aMaxId = aNum;
+ }
+
+ }
+ while(FindNextFileA(aHandle,&aData));
+ FindClose(aHandle);
+ }
+ std::string anImageName = anImageDir + anImagePrefix + StrFormat("%d.png",aMaxId+1);
+
+ // Capture screen
+ LPDIRECTDRAWSURFACE aSurface = mDDInterface->mDrawSurface;
+
+ // Temporarily set the mDrawSurface to NULL so DDImage::Check3D
+ // returns false so we can lock the surface.
+ mDDInterface->mDrawSurface = NULL;
+
+ DDImage anImage(mDDInterface);
+ anImage.SetSurface(aSurface);
+ anImage.GetBits();
+ anImage.DeleteDDSurface();
+ mDDInterface->mDrawSurface = aSurface;
+
+ if (anImage.mBits==NULL)
+ return;
+
+ // Write image
+ ImageLib::Image aSaveImage;
+ aSaveImage.mBits = anImage.mBits;
+ aSaveImage.mWidth = anImage.mWidth;
+ aSaveImage.mHeight = anImage.mHeight;
+ ImageLib::WritePNGImage(anImageName, &aSaveImage);
+ aSaveImage.mBits = NULL;
+
+
+/*
+ keybd_event(VK_MENU,0,0,0);
+ keybd_event(VK_SNAPSHOT,0,0,0);
+ keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
+ if (OpenClipboard(mHWnd))
+ {
+ HBITMAP aBitmap = (HBITMAP)GetClipboardData(CF_BITMAP);
+ if (aBitmap!=NULL)
+ {
+ BITMAP anObject;
+ ZeroMemory(&anObject,sizeof(anObject));
+ GetObject(aBitmap,sizeof(anObject),&anObject);
+
+ BITMAPINFO anInfo;
+ ZeroMemory(&anInfo,sizeof(anInfo));
+ BITMAPINFOHEADER &aHeader = anInfo.bmiHeader;
+ aHeader.biBitCount = 32;
+ aHeader.biPlanes = 1;
+ aHeader.biHeight = -abs(anObject.bmHeight);
+ aHeader.biWidth = abs(anObject.bmWidth);
+ aHeader.biSize = sizeof(aHeader);
+ aHeader.biSizeImage = aHeader.biHeight*aHeader.biWidth*4;
+ ImageLib::Image aSaveImage;
+ aSaveImage.mBits = new DWORD[abs(anObject.bmWidth*anObject.bmHeight)];
+ aSaveImage.mWidth = abs(anObject.bmWidth);
+ aSaveImage.mHeight = abs(anObject.bmHeight);
+
+ HDC aDC = GetDC(NULL);
+ if (GetDIBits(aDC,aBitmap,0,aSaveImage.mHeight,aSaveImage.mBits,&anInfo,DIB_RGB_COLORS))
+ ImageLib::WritePNGImage(anImageName, &aSaveImage);
+
+ ReleaseDC(NULL,aDC);
+ }
+ CloseClipboard();
+ }*/
+
+ ClearUpdateBacklog();
+}
+
+void SexyAppBase::DumpProgramInfo()
+{
+ Deltree(GetAppDataFolder() + "_dump");
+
+ for (;;)
+ {
+ if (mkdir((GetAppDataFolder() + "_dump").c_str()))
+ break;
+ Sleep(100);
+ }
+
+ std::fstream aDumpStream((GetAppDataFolder() + "_dump\\imagelist.html").c_str(), std::ios::out);
+
+ time_t aTime;
+ time(&aTime);
+ tm* aTM = localtime(&aTime);
+
+ aDumpStream << "<HTML><BODY BGCOLOR=EEEEFF><CENTER><FONT SIZE=+2><B>" << asctime(aTM) << "</B></FONT><BR>" << std::endl;
+
+ int anImgNum = 0;
+
+ int aThumbWidth = 64;
+ int aThumbHeight = 64;
+
+ ImageLib::Image anImageLibImage;
+ anImageLibImage.mWidth = aThumbWidth;
+ anImageLibImage.mHeight = aThumbHeight;
+ anImageLibImage.mBits = new unsigned long[aThumbWidth*aThumbHeight];
+
+ typedef std::multimap<int, MemoryImage*, std::greater<int> > SortedImageMap;
+
+ int aTotalMemory = 0;
+
+ SortedImageMap aSortedImageMap;
+ MemoryImageSet::iterator anItr = mMemoryImageSet.begin();
+ while (anItr != mMemoryImageSet.end())
+ {
+ MemoryImage* aMemoryImage = *anItr;
+
+ int aNumPixels = aMemoryImage->mWidth*aMemoryImage->mHeight;
+
+ DDImage* aDDImage = dynamic_cast<DDImage*>(aMemoryImage);
+
+ int aBitsMemory = 0;
+ int aSurfaceMemory = 0;
+ int aPalletizedMemory = 0;
+ int aNativeAlphaMemory = 0;
+ int aRLAlphaMemory = 0;
+ int aRLAdditiveMemory = 0;
+ int aTextureMemory = 0;
+
+ int aMemorySize = 0;
+ if (aMemoryImage->mBits != NULL)
+ aBitsMemory = aNumPixels * 4;
+ if ((aDDImage != NULL) && (aDDImage->mSurface != NULL))
+ aSurfaceMemory = aNumPixels * 4; // Assume 32bit screen...
+ if (aMemoryImage->mColorTable != NULL)
+ aPalletizedMemory = aNumPixels + 256*4;
+ if (aMemoryImage->mNativeAlphaData != NULL)
+ {
+ if (aMemoryImage->mColorTable != NULL)
+ aNativeAlphaMemory = 256*4;
+ else
+ aNativeAlphaMemory = aNumPixels * 4;
+ }
+ if (aMemoryImage->mRLAlphaData != NULL)
+ aRLAlphaMemory = aNumPixels;
+ if (aMemoryImage->mRLAdditiveData != NULL)
+ aRLAdditiveMemory = aNumPixels;
+ if (aMemoryImage->mD3DData != NULL)
+ aTextureMemory += ((TextureData*)aMemoryImage->mD3DData)->mTexMemSize;
+
+ aMemorySize = aBitsMemory + aSurfaceMemory + aPalletizedMemory + aNativeAlphaMemory + aRLAlphaMemory + aRLAdditiveMemory + aTextureMemory;
+ aTotalMemory += aMemorySize;
+
+ aSortedImageMap.insert(SortedImageMap::value_type(aMemorySize, aMemoryImage));
+
+ ++anItr;
+ }
+
+ aDumpStream << "Total Image Allocation: " << CommaSeperate(aTotalMemory).c_str() << " bytes<BR>";
+ aDumpStream << "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=4>";
+
+ int aTotalMemorySize = 0;
+ int aTotalBitsMemory = 0;
+ int aTotalSurfaceMemory = 0;
+ int aTotalPalletizedMemory = 0;
+ int aTotalNativeAlphaMemory = 0;
+ int aTotalRLAlphaMemory = 0;
+ int aTotalRLAdditiveMemory = 0;
+ int aTotalTextureMemory = 0;
+
+ SortedImageMap::iterator aSortedItr = aSortedImageMap.begin();
+ while (aSortedItr != aSortedImageMap.end())
+ {
+ MemoryImage* aMemoryImage = aSortedItr->second;
+
+ char anImageName[256];
+ sprintf(anImageName, "img%04d.png", anImgNum);
+
+ char aThumbName[256];
+ sprintf(aThumbName, "thumb%04d.jpg", anImgNum);
+
+ aDumpStream << "<TR>" << std::endl;
+
+ aDumpStream << "<TD><A HREF=" << anImageName << "><IMG SRC=" << aThumbName << " WIDTH=" << aThumbWidth << " HEIGHT=" << aThumbHeight << "></A></TD>" << std::endl;
+
+ int aNumPixels = aMemoryImage->mWidth*aMemoryImage->mHeight;
+
+ DDImage* aDDImage = dynamic_cast<DDImage*>(aMemoryImage);
+
+ int aMemorySize = aSortedItr->first;
+
+ int aBitsMemory = 0;
+ int aSurfaceMemory = 0;
+ int aPalletizedMemory = 0;
+ int aNativeAlphaMemory = 0;
+ int aRLAlphaMemory = 0;
+ int aRLAdditiveMemory = 0;
+ int aTextureMemory = 0;
+ std::string aTextureFormatName;
+
+ if (aMemoryImage->mBits != NULL)
+ aBitsMemory = aNumPixels * 4;
+ if ((aDDImage != NULL) && (aDDImage->mSurface != NULL))
+ aSurfaceMemory = aNumPixels * 4; // Assume 32bit screen...
+ if (aMemoryImage->mColorTable != NULL)
+ aPalletizedMemory = aNumPixels + 256*4;
+ if (aMemoryImage->mNativeAlphaData != NULL)
+ {
+ if (aMemoryImage->mColorTable != NULL)
+ aNativeAlphaMemory = 256*4;
+ else
+ aNativeAlphaMemory = aNumPixels * 4;
+ }
+ if (aMemoryImage->mRLAlphaData != NULL)
+ aRLAlphaMemory = aNumPixels;
+ if (aMemoryImage->mRLAdditiveData != NULL)
+ aRLAdditiveMemory = aNumPixels;
+ if (aMemoryImage->mD3DData != NULL)
+ {
+ aTextureMemory += ((TextureData*)aMemoryImage->mD3DData)->mTexMemSize;
+
+ switch (((TextureData*)aMemoryImage->mD3DData)->mPixelFormat)
+ {
+ case PixelFormat_A8R8G8B8: aTextureFormatName = "A8R8G8B8"; break;
+ case PixelFormat_A4R4G4B4: aTextureFormatName = "A4R4G4B4"; break;
+ case PixelFormat_R5G6B5: aTextureFormatName = "R5G6B5"; break;
+ case PixelFormat_Palette8: aTextureFormatName = "Palette8"; break;
+ }
+ }
+
+ aTotalMemorySize += aMemorySize;
+ aTotalBitsMemory += aBitsMemory;
+ aTotalTextureMemory += aTextureMemory;
+ aTotalSurfaceMemory += aSurfaceMemory;
+ aTotalPalletizedMemory += aPalletizedMemory;
+ aTotalNativeAlphaMemory += aNativeAlphaMemory;
+ aTotalRLAlphaMemory += aRLAlphaMemory;
+ aTotalRLAdditiveMemory += aRLAdditiveMemory;
+
+
+
+ char aStr[256];
+ sprintf(aStr, "%d x %d<BR>%s bytes", aMemoryImage->mWidth, aMemoryImage->mHeight, CommaSeperate(aMemorySize).c_str());
+ aDumpStream << "<TD ALIGN=RIGHT>" << aStr << "</TD>" << std::endl;
+
+ aDumpStream << "<TD>" << SexyStringToString(((aBitsMemory != 0) ? _S("mBits<BR>") + CommaSeperate(aBitsMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aPalletizedMemory != 0) ? _S("Palletized<BR>") + CommaSeperate(aPalletizedMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aSurfaceMemory != 0) ? _S("DDSurface<BR>") + CommaSeperate(aSurfaceMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aMemoryImage->mD3DData!=NULL) ? _S("Texture<BR>") + StringToSexyString(aTextureFormatName) + _S("<BR>") + CommaSeperate(aTextureMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+
+ aDumpStream << "<TD>" << SexyStringToString(((aMemoryImage->mIsVolatile) ? _S("Volatile") : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aMemoryImage->mForcedMode) ? _S("Forced") : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aMemoryImage->mHasAlpha) ? _S("HasAlpha") : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aMemoryImage->mHasTrans) ? _S("HasTrans") : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aNativeAlphaMemory != 0) ? _S("NativeAlpha<BR>") + CommaSeperate(aNativeAlphaMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aRLAlphaMemory != 0) ? _S("RLAlpha<BR>") + CommaSeperate(aRLAlphaMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(((aRLAdditiveMemory != 0) ? _S("RLAdditive<BR>") + CommaSeperate(aRLAdditiveMemory) : _S("&nbsp;"))) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << (aMemoryImage->mFilePath.empty()? "&nbsp;":aMemoryImage->mFilePath) << "</TD>" << std::endl;
+
+ aDumpStream << "</TR>" << std::endl;
+
+ // Write thumb
+
+ MemoryImage aCopiedImage(*aMemoryImage);
+
+ ulong* aBits = aCopiedImage.GetBits();
+
+ ulong* aThumbBitsPtr = anImageLibImage.mBits;
+
+ for (int aThumbY = 0; aThumbY < aThumbHeight; aThumbY++)
+ for (int aThumbX = 0; aThumbX < aThumbWidth; aThumbX++)
+ {
+ int aSrcX = (int) (aCopiedImage.mWidth * (aThumbX + 0.5)) / aThumbWidth;
+ int aSrcY = (int) (aCopiedImage.mHeight * (aThumbY + 0.5)) / aThumbHeight;
+
+ *(aThumbBitsPtr++) = aBits[aSrcX + (aSrcY*aCopiedImage.mWidth)];
+ }
+
+ ImageLib::WriteJPEGImage((GetAppDataFolder() + std::string("_dump\\") + aThumbName).c_str(), &anImageLibImage);
+
+ // Write high resolution image
+
+ ImageLib::Image anFullImage;
+ anFullImage.mBits = aCopiedImage.GetBits();
+ anFullImage.mWidth = aCopiedImage.GetWidth();
+ anFullImage.mHeight = aCopiedImage.GetHeight();
+
+ ImageLib::WritePNGImage((GetAppDataFolder() + std::string("_dump\\") + anImageName).c_str(), &anFullImage);
+
+ anFullImage.mBits = NULL;
+
+ anImgNum++;
+
+ aSortedItr++;
+ }
+
+ aDumpStream << "<TD>Totals</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalMemorySize)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalBitsMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalPalletizedMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalSurfaceMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalTextureMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>&nbsp;</TD>" << std::endl;
+ aDumpStream << "<TD>&nbsp;</TD>" << std::endl;
+ aDumpStream << "<TD>&nbsp;</TD>" << std::endl;
+ aDumpStream << "<TD>&nbsp;</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalNativeAlphaMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalRLAlphaMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>" << SexyStringToString(CommaSeperate(aTotalRLAdditiveMemory)) << "</TD>" << std::endl;
+ aDumpStream << "<TD>&nbsp;</TD>" << std::endl;
+
+ aDumpStream << "</TABLE></CENTER></BODY></HTML>" << std::endl;
+}
+
+double SexyAppBase::GetLoadingThreadProgress()
+{
+ if (mLoaded)
+ return 1.0;
+ if (!mLoadingThreadStarted)
+ return 0.0;
+ if (mNumLoadingThreadTasks == 0)
+ return 0.0;
+ return min(mCompletedLoadingThreadTasks / (double) mNumLoadingThreadTasks, 1.0);
+}
+
+bool SexyAppBase::RegistryWrite(const std::string& theValueName, ulong theType, const uchar* theValue, ulong theLength)
+{
+ if (mRegKey.length() == 0)
+ return false;
+
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return true;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_REGISTRY_WRITE);
+
+ return mDemoBuffer.ReadNumBits(1, false) != 0;
+ }
+
+ HKEY aGameKey;
+
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + mRegKey);
+ std::string aValueName;
+
+ int aSlashPos = (int) theValueName.rfind('\\');
+ if (aSlashPos != -1)
+ {
+ aKeyName += "\\" + theValueName.substr(0, aSlashPos);
+ aValueName = theValueName.substr(aSlashPos + 1);
+ }
+ else
+ {
+ aValueName = theValueName;
+ }
+
+ int aResult = RegOpenKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, KEY_WRITE, &aGameKey);
+ if (aResult != ERROR_SUCCESS)
+ {
+ ulong aDisp;
+ aResult = RegCreateKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, "Key", REG_OPTION_NON_VOLATILE,
+ KEY_ALL_ACCESS, NULL, &aGameKey, &aDisp);
+ }
+
+ if (aResult != ERROR_SUCCESS)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_WRITE, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+
+ RegSetValueExA(aGameKey, aValueName.c_str(), 0, theType, theValue, theLength);
+ RegCloseKey(aGameKey);
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_WRITE, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ }
+
+ return true;
+}
+
+bool SexyAppBase::RegistryWriteString(const std::string& theValueName, const std::string& theString)
+{
+ return RegistryWrite(theValueName, REG_SZ, (uchar*) theString.c_str(), theString.length());
+}
+
+bool SexyAppBase::RegistryWriteInteger(const std::string& theValueName, int theValue)
+{
+ return RegistryWrite(theValueName, REG_DWORD, (uchar*) &theValue, sizeof(int));
+}
+
+bool SexyAppBase::RegistryWriteBoolean(const std::string& theValueName, bool theValue)
+{
+ int aValue = theValue ? 1 : 0;
+ return RegistryWrite(theValueName, REG_DWORD, (uchar*) &aValue, sizeof(int));
+}
+
+bool SexyAppBase::RegistryWriteData(const std::string& theValueName, const uchar* theValue, ulong theLength)
+{
+ return RegistryWrite(theValueName, REG_BINARY, (uchar*) theValue, theLength);
+}
+
+void SexyAppBase::WriteToRegistry()
+{
+ RegistryWriteInteger("MusicVolume", (int) (mMusicVolume * 100));
+ RegistryWriteInteger("SfxVolume", (int) (mSfxVolume * 100));
+ RegistryWriteInteger("Muted", (mMuteCount - mAutoMuteCount > 0) ? 1 : 0);
+ RegistryWriteInteger("ScreenMode", mIsWindowed ? 0 : 1);
+ RegistryWriteInteger("PreferredX", mPreferredX);
+ RegistryWriteInteger("PreferredY", mPreferredY);
+ RegistryWriteInteger("CustomCursors", mCustomCursorsEnabled ? 1 : 0);
+ RegistryWriteInteger("InProgress", 0);
+ RegistryWriteBoolean("WaitForVSync", mWaitForVSync);
+}
+
+bool SexyAppBase::RegistryEraseKey(const SexyString& _theKeyName)
+{
+ std::string theKeyName = SexyStringToStringFast(_theKeyName);
+ if (mRegKey.length() == 0)
+ return false;
+
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return true;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_REGISTRY_ERASE);
+
+ return mDemoBuffer.ReadNumBits(1, false) != 0;
+ }
+
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + mRegKey) + "\\" + theKeyName;
+
+ int aResult = RegDeleteKeyA(HKEY_CURRENT_USER, aKeyName.c_str());
+ if (aResult != ERROR_SUCCESS)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_ERASE, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_ERASE, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ }
+
+ return true;
+}
+
+void SexyAppBase::RegistryEraseValue(const SexyString& _theValueName)
+{
+ std::string theValueName = SexyStringToStringFast(_theValueName);
+ if (mRegKey.length() == 0)
+ return;
+
+ HKEY aGameKey;
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + mRegKey);
+ std::string aValueName;
+
+ int aSlashPos = (int) theValueName.rfind('\\');
+ if (aSlashPos != -1)
+ {
+ aKeyName += "\\" + theValueName.substr(0, aSlashPos);
+ aValueName = theValueName.substr(aSlashPos + 1);
+ }
+ else
+ {
+ aValueName = theValueName;
+ }
+
+ int aResult = RegOpenKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, KEY_WRITE, &aGameKey);
+ if (aResult == ERROR_SUCCESS)
+ {
+ RegDeleteValueA(aGameKey, aValueName.c_str());
+ RegCloseKey(aGameKey);
+ }
+}
+
+bool SexyAppBase::RegistryGetSubKeys(const std::string& theKeyName, StringVector* theSubKeys)
+{
+ theSubKeys->clear();
+
+ if (mRegKey.length() == 0)
+ return false;
+
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return true;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_REGISTRY_GETSUBKEYS);
+
+ bool success = mDemoBuffer.ReadNumBits(1, false) != 0;
+ if (!success)
+ return false;
+
+ int aNumKeys = mDemoBuffer.ReadLong();
+
+ for (int i = 0; i < aNumKeys; i++)
+ theSubKeys->push_back(mDemoBuffer.ReadString());
+
+ return true;
+ }
+ else
+ {
+ HKEY aKey;
+
+ std::string aKeyName = RemoveTrailingSlash(RemoveTrailingSlash("SOFTWARE\\" + mRegKey) + "\\" + theKeyName);
+ int aResult = RegOpenKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, KEY_READ, &aKey);
+
+ if (aResult == ERROR_SUCCESS)
+ {
+ for (int anIdx = 0; ; anIdx++)
+ {
+ char aStr[1024];
+
+ aResult = RegEnumKeyA(aKey, anIdx, aStr, 1024);
+ if (aResult != ERROR_SUCCESS)
+ break;
+
+ theSubKeys->push_back(aStr);
+ }
+
+ RegCloseKey(aKey);
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_GETSUBKEYS, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ mDemoBuffer.WriteLong(theSubKeys->size());
+
+ for (int i = 0; i < (int) theSubKeys->size(); i++)
+ mDemoBuffer.WriteString((*theSubKeys)[i]);
+ }
+
+ return true;
+ }
+ else
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_GETSUBKEYS, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+ }
+}
+
+bool SexyAppBase::RegistryRead(const std::string& theValueName, ulong* theType, uchar* theValue, ulong* theLength)
+{
+ return RegistryReadKey(theValueName, theType, theValue, theLength, HKEY_CURRENT_USER);
+}
+
+bool SexyAppBase::RegistryReadKey(const std::string& theValueName, ulong* theType, uchar* theValue, ulong* theLength, HKEY theKey)
+{
+ if (mRegKey.length() == 0)
+ return false;
+
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return false;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_REGISTRY_READ);
+
+ bool success = mDemoBuffer.ReadNumBits(1, false) != 0;
+ if (!success)
+ return false;
+
+ *theType = mDemoBuffer.ReadLong();
+
+ ulong aLen = mDemoBuffer.ReadLong();
+ *theLength = aLen;
+
+ if (*theLength >= aLen)
+ {
+ mDemoBuffer.ReadBytes(theValue, aLen);
+ return true;
+ }
+ else
+ {
+ for (int i = 0; i < (int) aLen; i++)
+ mDemoBuffer.ReadByte();
+ return false;
+ }
+ }
+ else
+ {
+ HKEY aGameKey;
+
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + mRegKey);
+ std::string aValueName;
+
+ int aSlashPos = (int) theValueName.rfind('\\');
+ if (aSlashPos != -1)
+ {
+ aKeyName += "\\" + theValueName.substr(0, aSlashPos);
+ aValueName = theValueName.substr(aSlashPos + 1);
+ }
+ else
+ {
+ aValueName = theValueName;
+ }
+
+ if (RegOpenKeyExA(theKey, aKeyName.c_str(), 0, KEY_READ, &aGameKey) == ERROR_SUCCESS)
+ {
+ if (RegQueryValueExA(aGameKey, aValueName.c_str(), 0, theType, (uchar*) theValue, theLength) == ERROR_SUCCESS)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_READ, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ mDemoBuffer.WriteLong(*theType);
+ mDemoBuffer.WriteLong(*theLength);
+ mDemoBuffer.WriteBytes(theValue, *theLength);
+ }
+
+ RegCloseKey(aGameKey);
+ return true;
+ }
+
+ RegCloseKey(aGameKey);
+ }
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_REGISTRY_READ, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+}
+
+bool SexyAppBase::RegistryReadString(const std::string& theKey, std::string* theString)
+{
+ char aStr[1024];
+
+ ulong aType;
+ ulong aLen = sizeof(aStr) - 1;
+ if (!RegistryRead(theKey, &aType, (uchar*) aStr, &aLen))
+ return false;
+
+ if (aType != REG_SZ)
+ return false;
+
+ aStr[aLen] = 0;
+
+ *theString = aStr;
+ return true;
+}
+
+bool SexyAppBase::RegistryReadInteger(const std::string& theKey, int* theValue)
+{
+ ulong aType;
+ ulong aLong;
+ ulong aLen = 4;
+ if (!RegistryRead(theKey, &aType, (uchar*) &aLong, &aLen))
+ return false;
+
+ if (aType != REG_DWORD)
+ return false;
+
+ *theValue = aLong;
+ return true;
+}
+
+bool SexyAppBase::RegistryReadBoolean(const std::string& theKey, bool* theValue)
+{
+ int aValue;
+ if (!RegistryReadInteger(theKey, &aValue))
+ return false;
+
+ *theValue = aValue != 0;
+ return true;
+}
+
+bool SexyAppBase::RegistryReadData(const std::string& theKey, uchar* theValue, ulong* theLength)
+{
+ ulong aType;
+ ulong aLen = *theLength;
+ if (!RegistryRead(theKey, &aType, (uchar*) theValue, theLength))
+ return false;
+
+ if (aType != REG_BINARY)
+ return false;
+
+ return true;
+}
+
+void SexyAppBase::ReadFromRegistry()
+{
+ mReadFromRegistry = true;
+ mRegKey = SexyStringToString(GetString("RegistryKey", StringToSexyString(mRegKey)));
+
+ if (mRegKey.length() == 0)
+ return;
+
+ int anInt;
+ if (RegistryReadInteger("MusicVolume", &anInt))
+ mMusicVolume = anInt / 100.0;
+
+ if (RegistryReadInteger("SfxVolume", &anInt))
+ mSfxVolume = anInt / 100.0;
+
+ if (RegistryReadInteger("Muted", &anInt))
+ mMuteCount = anInt;
+
+ if (RegistryReadInteger("ScreenMode", &anInt))
+ mIsWindowed = anInt == 0;
+
+ RegistryReadInteger("PreferredX", &mPreferredX);
+ RegistryReadInteger("PreferredY", &mPreferredY);
+
+ if (RegistryReadInteger("CustomCursors", &anInt))
+ EnableCustomCursors(anInt != 0);
+
+ RegistryReadBoolean("WaitForVSync", &mWaitForVSync);
+
+ if (RegistryReadInteger("InProgress", &anInt))
+ mLastShutdownWasGraceful = anInt == 0;
+
+ if (!IsScreenSaver())
+ RegistryWriteInteger("InProgress", 1);
+}
+
+bool SexyAppBase::WriteBytesToFile(const std::string& theFileName, const void *theData, unsigned long theDataLen)
+{
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return true;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_FILE_WRITE);
+
+ bool success = mDemoBuffer.ReadNumBits(1, false) != 0;
+ if (!success)
+ return false;
+
+ return true;
+ }
+
+ MkDir(GetFileDir(theFileName));
+ FILE* aFP = fopen(theFileName.c_str(), "w+b");
+
+ if (aFP == NULL)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_FILE_WRITE, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+
+ fwrite(theData, 1, theDataLen, aFP);
+ fclose(aFP);
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_FILE_WRITE, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ }
+
+ return true;
+}
+
+bool SexyAppBase::WriteBufferToFile(const std::string& theFileName, const Buffer* theBuffer)
+{
+ return WriteBytesToFile(theFileName,theBuffer->GetDataPtr(),theBuffer->GetDataLen());
+}
+
+
+bool SexyAppBase::ReadBufferFromFile(const std::string& theFileName, Buffer* theBuffer, bool dontWriteToDemo)
+{
+ if ((mPlayingDemoBuffer) && (!dontWriteToDemo))
+ {
+ if (mManualShutdown)
+ return false;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_FILE_READ);
+
+ bool success = mDemoBuffer.ReadNumBits(1, false) != 0;
+ if (!success)
+ return false;
+
+ ulong aLen = mDemoBuffer.ReadLong();
+
+ theBuffer->Clear();
+ for (int i = 0; i < (int) aLen; i++)
+ theBuffer->WriteByte(mDemoBuffer.ReadByte());
+
+ return true;
+ }
+ else
+ {
+ PFILE* aFP = p_fopen(theFileName.c_str(), "rb");
+
+ if (aFP == NULL)
+ {
+ if ((mRecordingDemoBuffer) && (!dontWriteToDemo))
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_FILE_READ, 5);
+ mDemoBuffer.WriteNumBits(0, 1); // failure
+ }
+
+ return false;
+ }
+
+ p_fseek(aFP, 0, SEEK_END);
+ int aFileSize = p_ftell(aFP);
+ p_fseek(aFP, 0, SEEK_SET);
+
+ uchar* aData = new uchar[aFileSize];
+
+ p_fread(aData, 1, aFileSize, aFP);
+ p_fclose(aFP);
+
+ theBuffer->Clear();
+ theBuffer->SetData(aData, aFileSize);
+
+ if ((mRecordingDemoBuffer) && (!dontWriteToDemo))
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_FILE_READ, 5);
+ mDemoBuffer.WriteNumBits(1, 1); // success
+ mDemoBuffer.WriteLong(aFileSize);
+ mDemoBuffer.WriteBytes(aData, aFileSize);
+ }
+
+ delete [] aData;
+
+ return true;
+ }
+}
+
+bool SexyAppBase::FileExists(const std::string& theFileName)
+{
+ if (mPlayingDemoBuffer)
+ {
+ if (mManualShutdown)
+ return true;
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_FILE_EXISTS);
+
+ bool success = mDemoBuffer.ReadNumBits(1, false) != 0;
+ return success;
+ }
+ else
+ {
+ PFILE* aFP = p_fopen(theFileName.c_str(), "rb");
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_FILE_EXISTS, 5);
+ mDemoBuffer.WriteNumBits((aFP != NULL) ? 1 : 0, 1);
+ }
+
+ if (aFP == NULL)
+ return false;
+
+ p_fclose(aFP);
+ return true;
+ }
+}
+
+bool SexyAppBase::EraseFile(const std::string& theFileName)
+{
+ if (mPlayingDemoBuffer)
+ return true;
+
+ return DeleteFileA(theFileName.c_str()) != 0;
+}
+
+void SexyAppBase::SEHOccured()
+{
+ SetMusicVolume(0);
+ ::ShowWindow(mHWnd, SW_HIDE);
+ mSEHOccured = true;
+ EnforceCursor();
+}
+
+std::string SexyAppBase::GetGameSEHInfo()
+{
+ int aSecLoaded = (GetTickCount() - mTimeLoaded) / 1000;
+
+ char aTimeStr[16];
+ sprintf(aTimeStr, "%02d:%02d:%02d", (aSecLoaded/60/60), (aSecLoaded/60)%60, aSecLoaded%60);
+
+ char aThreadIdStr[16];
+ sprintf(aThreadIdStr, "%X", mPrimaryThreadId);
+
+ std::string anInfoString =
+ "Product: " + mProdName + "\r\n" +
+ "Version: " + mProductVersion + "\r\n";
+
+ anInfoString +=
+ "Time Loaded: " + std::string(aTimeStr) + "\r\n"
+ "Fullscreen: " + (mIsWindowed ? std::string("No") : std::string("Yes")) + "\r\n"
+ "Primary ThreadId: " + aThreadIdStr + "\r\n";
+
+ return anInfoString;
+}
+
+void SexyAppBase::GetSEHWebParams(DefinesMap* theDefinesMap)
+{
+}
+
+void SexyAppBase::ShutdownHook()
+{
+}
+
+void SexyAppBase::Shutdown()
+{
+ if ((mPrimaryThreadId != 0) && (GetCurrentThreadId() != mPrimaryThreadId))
+ {
+ mLoadingFailed = true;
+ }
+ else if (!mShutdown)
+ {
+ mExitToTop = true;
+ mShutdown = true;
+ ShutdownHook();
+
+ if (mPlayingDemoBuffer)
+ {
+ //if the music/sfx volume is 0, then it means that in playback
+ //someone pressed the "S" key to mute sounds (or that the
+ //sound volume was set to 0 in the first place). Out of politeness,
+ //return the system sound volume to what it last was in the game.
+ SetMusicVolume(mDemoMusicVolume);
+ SetSfxVolume(mDemoSfxVolume);
+ }
+
+ // Blah
+ while (mCursorThreadRunning)
+ {
+ Sleep(10);
+ }
+
+ if (mMusicInterface != NULL)
+ mMusicInterface->StopAllMusic();
+
+ if ((!mIsPhysWindowed) && (mDDInterface != NULL) && (mDDInterface->mDD != NULL))
+ {
+ mDDInterface->mDD->RestoreDisplayMode();
+ }
+
+ if (mHWnd != NULL)
+ {
+ ShowWindow(mHWnd, SW_HIDE);
+ }
+
+ RestoreScreenResolution();
+
+ if (mReadFromRegistry)
+ WriteToRegistry();
+
+ ImageLib::CloseJPEG2000();
+ }
+}
+
+void SexyAppBase::RestoreScreenResolution()
+{
+ if (mFullScreenWindow)
+ {
+ EnumWindows(ChangeDisplayWindowEnumProc,0); // get any windows that appeared while we were running
+ ChangeDisplaySettings(NULL,0);
+ EnumWindows(ChangeDisplayWindowEnumProc,1); // restore window pos
+ mFullScreenWindow = false;
+ }
+}
+
+void SexyAppBase::DoExit(int theCode)
+{
+ RestoreScreenResolution();
+ exit(theCode);
+}
+
+void SexyAppBase::UpdateFrames()
+{
+ mUpdateCount++;
+
+ if (!mMinimized)
+ {
+ if (mWidgetManager->UpdateFrame())
+ ++mFPSDirtyCount;
+ }
+
+ mMusicInterface->Update();
+ CleanSharedImages();
+}
+
+void SexyAppBase::DoUpdateFramesF(float theFrac)
+{
+ if ((mVSyncUpdates) && (!mMinimized))
+ mWidgetManager->UpdateFrameF(theFrac);
+}
+
+bool SexyAppBase::DoUpdateFrames()
+{
+ SEXY_AUTO_PERF("SexyAppBase::DoUpdateFrames");
+
+ if (gScreenSaverActive)
+ return false;
+
+ if (mPlayingDemoBuffer)
+ {
+ if ((mLoadingThreadCompleted) && (!mLoaded) && (mDemoLoadingComplete))
+ {
+ mLoaded = true;
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+ mYieldMainThread = false;
+ LoadingThreadCompleted();
+ }
+
+ // Hrrm not sure why we check (mUpdateCount != mLastDemoUpdateCnt) here
+ if ((mLoaded == mDemoLoadingComplete) && (mUpdateCount != mLastDemoUpdateCnt))
+ {
+ UpdateFrames();
+ return true;
+ }
+
+ return false;
+ }
+ else
+ {
+ if ((mLoadingThreadCompleted) && (!mLoaded))
+ {
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+ mLoaded = true;
+ mYieldMainThread = false;
+ LoadingThreadCompleted();
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_LOADING_COMPLETE, 5);
+ }
+ }
+
+ UpdateFrames();
+ return true;
+ }
+}
+
+bool gIsFailing = false;
+
+void SexyAppBase::Redraw(Rect* theClipRect)
+{
+ SEXY_AUTO_PERF("SexyAppBase::Redraw");
+
+ // Do mIsDrawing check because we could enter here at a bad time if any windows messages
+ // are processed during WidgetManager->Draw
+ if ((mIsDrawing) || (mShutdown))
+ return;
+
+ if (gScreenSaverActive)
+ return;
+
+ static DWORD aRetryTick = 0;
+ if (!mDDInterface->Redraw(theClipRect))
+ {
+ extern bool gD3DInterfacePreDrawError;
+ gD3DInterfacePreDrawError = false; // this predraw error happens naturally when ddraw is failing
+ if (!gIsFailing)
+ {
+ //gDebugStream << GetTickCount() << " Redraw failed!" << std::endl;
+ gIsFailing = true;
+ }
+
+ WINDOWPLACEMENT aWindowPlacement;
+ ZeroMemory(&aWindowPlacement, sizeof(aWindowPlacement));
+ aWindowPlacement.length = sizeof(aWindowPlacement);
+ ::GetWindowPlacement(mHWnd, &aWindowPlacement);
+
+ DWORD aTick = GetTickCount();
+ if ((mActive || (aTick-aRetryTick>1000 && mIsPhysWindowed)) && (aWindowPlacement.showCmd != SW_SHOWMINIMIZED) && (!mMinimized))
+ {
+ aRetryTick = aTick;
+
+ mWidgetManager->mImage = NULL;
+
+ // Re-check resolution at this point, because we hit here when you change your resolution.
+ if (((mWidth >= GetSystemMetrics(SM_CXFULLSCREEN)) || (mHeight >= GetSystemMetrics(SM_CYFULLSCREEN))) && (mIsWindowed))
+ {
+ if (mForceWindowed)
+ {
+ Popup(GetString("PLEASE_SET_COLOR_DEPTH", _S("Please set your desktop color depth to 16 bit.")));
+ Shutdown();
+ return;
+ }
+ mForceFullscreen = true;
+
+ SwitchScreenMode(false);
+ return;
+ }
+
+
+ int aResult = InitDDInterface();
+
+ //gDebugStream << GetTickCount() << " ReInit..." << std::endl;
+
+ if ((mIsWindowed) && (aResult == DDInterface::RESULT_INVALID_COLORDEPTH))
+ {
+ //gDebugStream << GetTickCount() << "ReInit Invalid Colordepth" << std::endl;
+ if (!mActive) // don't switch to full screen if not active app
+ return;
+
+ SwitchScreenMode(false);
+ mForceFullscreen = true;
+ return;
+ }
+ else if (aResult == DDInterface::RESULT_3D_FAIL)
+ {
+ Set3DAcclerated(false);
+ return;
+ }
+ else if (aResult != DDInterface::RESULT_OK)
+ {
+ //gDebugStream << GetTickCount() << " ReInit Failed" << std::endl;
+ //Fail("Failed to initialize DirectDraw");
+ //Sleep(1000);
+
+ return;
+ }
+
+ ReInitImages();
+
+ mWidgetManager->mImage = mDDInterface->GetScreenImage();
+ mWidgetManager->MarkAllDirty();
+
+ mLastTime = timeGetTime();
+ }
+ }
+ else
+ {
+ if (gIsFailing)
+ {
+ //gDebugStream << GetTickCount() << " Redraw succeeded" << std::endl;
+ gIsFailing = false;
+ aRetryTick = 0;
+ }
+ }
+
+ mFPSFlipCount++;
+}
+
+///////////////////////////// FPS Stuff
+static PerfTimer gFPSTimer;
+static int gFrameCount;
+static int gFPSDisplay;
+static bool gForceDisplay = false;
+static void CalculateFPS()
+{
+ gFrameCount++;
+
+ static SysFont aFont(gSexyAppBase,"Tahoma",8);
+ if (gFPSImage==NULL)
+ {
+ gFPSImage = new DDImage(gSexyAppBase->mDDInterface);
+ gFPSImage->Create(50,aFont.GetHeight()+4);
+ gFPSImage->SetImageMode(false,false);
+ gFPSImage->SetVolatile(true);
+ gFPSImage->mPurgeBits = false;
+ gFPSImage->mWantDDSurface = true;
+ gFPSImage->PurgeBits();
+ }
+
+ if (gFPSTimer.GetDuration() >= 1000 || gForceDisplay)
+ {
+ gFPSTimer.Stop();
+ if (!gForceDisplay)
+ gFPSDisplay = (int)(gFrameCount*1000/gFPSTimer.GetDuration() + 0.5f);
+ else
+ {
+ gForceDisplay = false;
+ gFPSDisplay = 0;
+ }
+
+ gFPSTimer.Start();
+ gFrameCount = 0;
+
+ Graphics aDrawG(gFPSImage);
+ aDrawG.SetFont(&aFont);
+ SexyString aFPS = StrFormat(_S("FPS: %d"), gFPSDisplay);
+ aDrawG.SetColor(0x000000);
+ aDrawG.FillRect(0,0,gFPSImage->GetWidth(),gFPSImage->GetHeight());
+ aDrawG.SetColor(0xFFFFFF);
+ aDrawG.DrawString(aFPS,2,aFont.GetAscent());
+ //gFPSImage->mKeepBits = false;
+ //gFPSImage->GenerateDDSurface();
+ gFPSImage->mBitsChangedCount++;
+ }
+}
+
+///////////////////////////// FPS Stuff to draw mouse coords
+static void FPSDrawCoords(int theX, int theY)
+{
+ static SysFont aFont(gSexyAppBase,"Tahoma",8);
+ if (gFPSImage==NULL)
+ {
+ gFPSImage = new DDImage(gSexyAppBase->mDDInterface);
+ gFPSImage->Create(50,aFont.GetHeight()+4);
+ gFPSImage->SetImageMode(false,false);
+ gFPSImage->SetVolatile(true);
+ gFPSImage->mPurgeBits = false;
+ gFPSImage->mWantDDSurface = true;
+ gFPSImage->PurgeBits();
+ }
+
+ Graphics aDrawG(gFPSImage);
+ aDrawG.SetFont(&aFont);
+ SexyString aFPS = StrFormat(_S("%d,%d"),theX,theY);
+ aDrawG.SetColor(0x000000);
+ aDrawG.FillRect(0,0,gFPSImage->GetWidth(),gFPSImage->GetHeight());
+ aDrawG.SetColor(0xFFFFFF);
+ aDrawG.DrawString(aFPS,2,aFont.GetAscent());
+ gFPSImage->mBitsChangedCount++;
+}
+
+///////////////////////////// Demo TimeLeft Stuff
+static DDImage* gDemoTimeLeftImage = NULL;
+static void CalculateDemoTimeLeft()
+{
+ static SysFont aFont(gSexyAppBase,"Tahoma",8);
+ static DWORD aLastTick = 0;
+
+ if (gDemoTimeLeftImage==NULL)
+ {
+ gDemoTimeLeftImage = new DDImage(gSexyAppBase->mDDInterface);
+ gDemoTimeLeftImage->Create(50,aFont.GetHeight()+4);
+ gDemoTimeLeftImage->SetImageMode(false,false);
+ gDemoTimeLeftImage->SetVolatile(true);
+ gDemoTimeLeftImage->mPurgeBits = false;
+ gDemoTimeLeftImage->mWantDDSurface = true;
+ gDemoTimeLeftImage->PurgeBits();
+ }
+
+ DWORD aTick = GetTickCount();
+ if (aTick - aLastTick < 1000/gSexyAppBase->mUpdateMultiplier)
+ return;
+
+ aLastTick = aTick;
+
+ int aNumUpdatesLeft = gSexyAppBase->mDemoLength - gSexyAppBase->mUpdateCount;
+ Graphics aDrawG(gDemoTimeLeftImage);
+ aDrawG.SetFont(&aFont);
+
+ int aTotalSeconds = aNumUpdatesLeft*gSexyAppBase->mFrameTime/1000;
+ int aSeconds = aTotalSeconds%60;
+ int aMinutes = (aTotalSeconds/60)%60;
+ int anHours = (aTotalSeconds/3600);
+
+ SexyString aFPS = StrFormat(_S("%02d:%02d:%02d"), anHours,aMinutes,aSeconds);
+ aDrawG.SetColor(0x000000);
+ aDrawG.FillRect(0,0,gDemoTimeLeftImage->GetWidth(),gDemoTimeLeftImage->GetHeight());
+ aDrawG.SetColor(0xFFFFFF);
+ aDrawG.DrawString(aFPS,2,aFont.GetAscent());
+ gDemoTimeLeftImage->mBitsChangedCount++;
+}
+
+static void UpdateScreenSaverInfo(DWORD theTick)
+{
+ if (gSexyAppBase->IsScreenSaver() || !gSexyAppBase->mIsPhysWindowed)
+ return;
+
+ // Get screen saver timeout
+ static DWORD aPeriodicTick = 0;
+ static DWORD aScreenSaverTimeout = 60000;
+ static BOOL aScreenSaverEnabled = TRUE;
+
+ if (theTick-aPeriodicTick > 10000)
+ {
+ aPeriodicTick = theTick;
+
+ int aTimeout = 0;
+
+ SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT,0,&aTimeout,0);
+ SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,0,&aScreenSaverEnabled,0);
+ aTimeout-=2;
+
+ if (aTimeout < 1)
+ aTimeout = 1;
+
+ aScreenSaverTimeout = aTimeout*1000;
+
+ if (!aScreenSaverEnabled)
+ gScreenSaverActive = false;
+ }
+
+ // Get more accurate last user input time
+ if (gGetLastInputInfoFunc)
+ {
+ LASTINPUTINFO anInfo;
+ anInfo.cbSize = sizeof(anInfo);
+ if (gGetLastInputInfoFunc(&anInfo))
+ {
+ if (anInfo.dwTime > theTick)
+ anInfo.dwTime = theTick;
+
+ gSexyAppBase->mLastUserInputTick = anInfo.dwTime;
+ }
+ }
+
+ if (!aScreenSaverEnabled)
+ return;
+
+ DWORD anIdleTime = theTick - gSexyAppBase->mLastUserInputTick;
+ if (gScreenSaverActive)
+ {
+ BOOL aBool = FALSE;
+ if (SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &aBool, 0))
+ {
+ if (aBool) // screen saver not off yet
+ return;
+ }
+
+ if (anIdleTime < aScreenSaverTimeout)
+ {
+ gScreenSaverActive = false;
+ gSexyAppBase->mWidgetManager->MarkAllDirty();
+ }
+ }
+ else if (anIdleTime > aScreenSaverTimeout)
+ gScreenSaverActive = true;
+}
+
+bool SexyAppBase::DrawDirtyStuff()
+{
+ SEXY_AUTO_PERF("SexyAppBase::DrawDirtyStuff");
+ MTAutoDisallowRand aDisallowRand;
+
+ if (gIsFailing) // just try to reinit
+ {
+ Redraw(NULL);
+ mHasPendingDraw = false;
+ mLastDrawWasEmpty = true;
+ return false;
+ }
+
+ if (mShowFPS)
+ {
+ switch(mShowFPSMode)
+ {
+ case FPS_ShowFPS: CalculateFPS(); break;
+ case FPS_ShowCoords:
+ if (mWidgetManager!=NULL)
+ FPSDrawCoords(mWidgetManager->mLastMouseX, mWidgetManager->mLastMouseY);
+ break;
+ }
+
+ if (mPlayingDemoBuffer)
+ CalculateDemoTimeLeft();
+ }
+
+ DWORD aStartTime = timeGetTime();
+
+ // Update user input and screen saver info
+ static DWORD aPeriodicTick = 0;
+ if (aStartTime-aPeriodicTick > 1000)
+ {
+ aPeriodicTick = aStartTime;
+ UpdateScreenSaverInfo(aStartTime);
+ }
+
+ if (gScreenSaverActive)
+ {
+ mHasPendingDraw = false;
+ mLastDrawWasEmpty = true;
+ return false;
+ }
+
+ mIsDrawing = true;
+ bool drewScreen = mWidgetManager->DrawScreen();
+ mIsDrawing = false;
+
+ if ((drewScreen || (aStartTime - mLastDrawTick >= 1000) || (mCustomCursorDirty)) &&
+ ((int) (aStartTime - mNextDrawTick) >= 0))
+ {
+ mLastDrawWasEmpty = false;
+
+ mDrawCount++;
+
+ DWORD aMidTime = timeGetTime();
+
+ mFPSCount++;
+ mFPSTime += aMidTime - aStartTime;
+
+ mDrawTime += aMidTime - aStartTime;
+
+ if (mShowFPS)
+ {
+ Graphics g(mDDInterface->GetScreenImage());
+ g.DrawImage(gFPSImage,mWidth-gFPSImage->GetWidth()-10,mHeight-gFPSImage->GetHeight()-10);
+
+ if (mPlayingDemoBuffer)
+ g.DrawImage(gDemoTimeLeftImage,mWidth-gDemoTimeLeftImage->GetWidth()-10,mHeight-gFPSImage->GetHeight()-gDemoTimeLeftImage->GetHeight()-15);
+ }
+
+ if (mWaitForVSync && mIsPhysWindowed && mSoftVSyncWait)
+ {
+ DWORD aTick = timeGetTime();
+ if (aTick-mLastDrawTick < mDDInterface->mMillisecondsPerFrame)
+ Sleep(mDDInterface->mMillisecondsPerFrame - (aTick-mLastDrawTick));
+ }
+
+ DWORD aPreScreenBltTime = timeGetTime();
+ mLastDrawTick = aPreScreenBltTime;
+
+ Redraw(NULL);
+
+ // This is our one UpdateFTimeAcc if we are vsynched
+ UpdateFTimeAcc();
+
+ DWORD aEndTime = timeGetTime();
+
+ mScreenBltTime = aEndTime - aPreScreenBltTime;
+
+#ifdef _DEBUG
+ /*if (mFPSTime >= 5000) // Show FPS about every 5 seconds
+ {
+ ulong aTickNow = GetTickCount();
+
+ OutputDebugString(StrFormat(_S("Theoretical FPS: %d\r\n"), (int) (mFPSCount * 1000 / mFPSTime)).c_str());
+ OutputDebugString(StrFormat(_S("Actual FPS: %d\r\n"), (mFPSFlipCount * 1000) / max((aTickNow - mFPSStartTick), 1)).c_str());
+ OutputDebugString(StrFormat(_S("Dirty Rate : %d\r\n"), (mFPSDirtyCount * 1000) / max((aTickNow - mFPSStartTick), 1)).c_str());
+
+ mFPSTime = 0;
+ mFPSCount = 0;
+ mFPSFlipCount = 0;
+ mFPSStartTick = aTickNow;
+ mFPSDirtyCount = 0;
+ }*/
+#endif
+
+ if ((mLoadingThreadStarted) && (!mLoadingThreadCompleted))
+ {
+ int aTotalTime = aEndTime - aStartTime;
+
+ mNextDrawTick += 35 + max(aTotalTime, 15);
+
+ if ((int) (aEndTime - mNextDrawTick) >= 0)
+ mNextDrawTick = aEndTime;
+
+ /*char aStr[256];
+ sprintf(aStr, "Next Draw Time: %d\r\n", mNextDrawTick);
+ OutputDebugString(aStr);*/
+ }
+ else
+ mNextDrawTick = aEndTime;
+
+ mHasPendingDraw = false;
+ mCustomCursorDirty = false;
+
+ return true;
+ }
+ else
+ {
+ mHasPendingDraw = false;
+ mLastDrawWasEmpty = true;
+ return false;
+ }
+}
+
+void SexyAppBase::LogScreenSaverError(const std::string &theError)
+{
+ static bool firstTime = true;
+ char aBuf[512];
+
+ const char *aFlag = firstTime?"w":"a+";
+ firstTime = false;
+
+ FILE *aFile = fopen("ScrError.txt",aFlag);
+ if (aFile != NULL)
+ {
+ fprintf(aFile,"%s %s %u\n",theError.c_str(),_strtime(aBuf),GetTickCount());
+ fclose(aFile);
+ }
+}
+
+void SexyAppBase::BeginPopup()
+{
+ if (!mIsPhysWindowed)
+ {
+ if (mDDInterface && mDDInterface->mDD)
+ {
+ mDDInterface->mDD->FlipToGDISurface();
+ mNoDefer = true;
+ }
+ }
+}
+
+void SexyAppBase::EndPopup()
+{
+ if (!mIsPhysWindowed)
+ mNoDefer = false;
+
+ ClearUpdateBacklog();
+ ClearKeysDown();
+
+ if (mWidgetManager->mDownButtons)
+ {
+ mWidgetManager->DoMouseUps();
+ ReleaseCapture();
+ }
+}
+
+int SexyAppBase::MsgBox(const std::string& theText, const std::string& theTitle, int theFlags)
+{
+// if (mDDInterface && mDDInterface->mDD)
+// mDDInterface->mDD->FlipToGDISurface();
+ if (IsScreenSaver())
+ {
+ LogScreenSaverError(theText);
+ return IDOK;
+ }
+
+ BeginPopup();
+ int aResult = MessageBoxA(mHWnd, theText.c_str(), theTitle.c_str(), theFlags);
+ EndPopup();
+
+ return aResult;
+}
+
+int SexyAppBase::MsgBox(const std::wstring& theText, const std::wstring& theTitle, int theFlags)
+{
+// if (mDDInterface && mDDInterface->mDD)
+// mDDInterface->mDD->FlipToGDISurface();
+ if (IsScreenSaver())
+ {
+ LogScreenSaverError(WStringToString(theText));
+ return IDOK;
+ }
+
+ BeginPopup();
+ int aResult = MessageBoxW(mHWnd, theText.c_str(), theTitle.c_str(), theFlags);
+ EndPopup();
+
+ return aResult;
+}
+
+void SexyAppBase::Popup(const std::string& theString)
+{
+ if (IsScreenSaver())
+ {
+ LogScreenSaverError(theString);
+ return;
+ }
+
+ BeginPopup();
+ if (!mShutdown)
+ ::MessageBoxA(mHWnd, theString.c_str(), SexyStringToString(GetString("FATAL_ERROR", _S("FATAL ERROR"))).c_str(), MB_APPLMODAL | MB_ICONSTOP);
+ EndPopup();
+}
+
+void SexyAppBase::Popup(const std::wstring& theString)
+{
+ if (IsScreenSaver())
+ {
+ LogScreenSaverError(WStringToString(theString));
+ return;
+ }
+
+ BeginPopup();
+ if (!mShutdown)
+ ::MessageBoxW(mHWnd, theString.c_str(), SexyStringToWString(GetString("FATAL_ERROR", _S("FATAL ERROR"))).c_str(), MB_APPLMODAL | MB_ICONSTOP);
+ EndPopup();
+}
+
+void SexyAppBase::SafeDeleteWidget(Widget* theWidget)
+{
+ WidgetSafeDeleteInfo aWidgetSafeDeleteInfo;
+ aWidgetSafeDeleteInfo.mUpdateAppDepth = mUpdateAppDepth;
+ aWidgetSafeDeleteInfo.mWidget = theWidget;
+ mSafeDeleteList.push_back(aWidgetSafeDeleteInfo);
+}
+
+BOOL CALLBACK EnumCloseThing2(HWND hwnd, LPARAM lParam)
+{
+ //CloseWindow(hwnd);
+ char aClassName[256];
+ if (GetClassNameA(hwnd, aClassName, 256) != 0)
+ {
+ if (strcmp(aClassName, "Internet Explorer_Server") == 0)
+ {
+ DestroyWindow(hwnd);
+ }
+ else
+ {
+ EnumChildWindows(hwnd, EnumCloseThing2, lParam);
+ }
+ }
+
+ return TRUE;
+}
+
+BOOL CALLBACK EnumCloseThing(HWND hwnd, LPARAM lParam)
+{
+ //CloseWindow(hwnd);
+ char aClassName[256];
+ if (GetClassNameA(hwnd, aClassName, 256) != 0)
+ {
+ if (strcmp(aClassName, "AmWBC_WClass") == 0)
+ {
+ EnumChildWindows(hwnd, EnumCloseThing2, lParam);
+ }
+ }
+
+ return TRUE;
+}
+
+static INT_PTR CALLBACK MarkerListDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ HWND aListBox = GetDlgItem(hwnd,100);
+
+ DWORD dwExtent = 0;
+ HDC hDCListBox;
+ HFONT hFontOld, hFontNew;
+ TEXTMETRIC tm;
+ RECT aRect;
+ SIZE aSize;
+
+ hDCListBox = GetDC(aListBox);
+ hFontNew = (HFONT)SendMessage(aListBox, WM_GETFONT, NULL, NULL);
+ hFontOld = (HFONT)SelectObject(hDCListBox, hFontNew);
+ GetTextMetrics(hDCListBox, (LPTEXTMETRIC)&tm);
+ GetClientRect(hwnd, &aRect);
+ MoveWindow(aListBox,10,10,aRect.right-aRect.left-20,aRect.bottom-aRect.top-20,FALSE);
+ for (SexyAppBase::DemoMarkerList::iterator anItr = gSexyAppBase->mDemoMarkerList.begin(); anItr != gSexyAppBase->mDemoMarkerList.end(); ++anItr)
+ {
+ if (anItr->second <= gSexyAppBase->mUpdateCount)
+ continue;
+
+ int aTotalSeconds = (gSexyAppBase->mDemoLength - anItr->second)*gSexyAppBase->mFrameTime/1000;
+ int aSeconds = aTotalSeconds%60;
+ int aMinutes = (aTotalSeconds/60)%60;
+ int anHours = (aTotalSeconds/3600);
+
+ SexyString aStr = StrFormat(_S("%s (%02d:%02d:%02d)"), anItr->first.c_str(),anHours,aMinutes,aSeconds);
+ GetTextExtentPoint32(hDCListBox, aStr.c_str(), aStr.length(), &aSize);
+ dwExtent = max (aSize.cx + tm.tmAveCharWidth, (int)dwExtent);
+ SendMessage(aListBox, LB_SETHORIZONTALEXTENT, dwExtent, 0);
+ LRESULT anIndex = SendMessage(aListBox, LB_ADDSTRING, 0, (LPARAM)aStr.c_str());
+ SendMessage(aListBox, LB_SETITEMDATA, anIndex, anItr->second);
+ }
+
+ SelectObject(hDCListBox, hFontOld);
+ ReleaseDC(aListBox, hDCListBox);
+
+ return TRUE;
+ }
+
+ case WM_CLOSE:
+ EndDialog(hwnd,0);
+ return TRUE;
+
+ case WM_COMMAND:
+ if (HIWORD(wParam)==LBN_DBLCLK)
+ {
+ HWND aListBox = GetDlgItem(hwnd,100);
+
+ int anIndex = SendMessage(aListBox,LB_GETCURSEL,0,0);
+ if (anIndex >= 0)
+ {
+ int anUpdateTime = SendMessage(aListBox,LB_GETITEMDATA,anIndex,0);
+ if (anUpdateTime > gSexyAppBase->mUpdateCount)
+ {
+ gSexyAppBase->mFastForwardToUpdateNum = anUpdateTime;
+ EndDialog(hwnd,0);
+ }
+ }
+ return TRUE;
+ }
+ break;
+
+ }
+
+ return FALSE;
+}
+
+static LPWORD lpdwAlign ( LPWORD lpIn)
+{
+ ULONG ul;
+
+ ul = (ULONG) lpIn;
+ ul +=3;
+ ul >>=2;
+ ul <<=2;
+ return (LPWORD) ul;
+}
+
+static int ListDemoMarkers()
+{
+ HGLOBAL hgbl;
+ LPDLGTEMPLATE lpdt;
+ LPDLGITEMTEMPLATE lpdit;
+ LPWORD lpw;
+ LPWSTR lpwsz;
+ LRESULT ret;
+ int nchar;
+
+ hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
+ if (!hgbl)
+ return -1;
+
+ lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
+
+ // Define a dialog box.
+ lpdt->style = WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT;
+ lpdt->cdit = 1; // number of controls
+ lpdt->x = 10; lpdt->y = 10;
+ lpdt->cx = 200; lpdt->cy = 200;
+
+ lpw = (LPWORD) (lpdt + 1);
+ *lpw++ = 0; // no menu
+ *lpw++ = 0; // predefined dialog box class (by default)
+
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Marker List", -1, lpwsz, 50);
+ lpw += nchar;
+ *lpw++ = 8;
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Tahoma", -1, lpwsz, 50);
+ lpw += nchar;
+
+ // Define Listbox
+ lpw = lpdwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
+ lpdit = (LPDLGITEMTEMPLATE) lpw;
+ lpdit->x = 5; lpdit->y = 5;
+ lpdit->cx = 190; lpdit->cy = 195;
+ lpdit->id = 100;
+ lpdit->style = WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LBS_NOTIFY;
+ lpdit->dwExtendedStyle = WS_EX_CLIENTEDGE;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0083; // listbox class
+ *lpw++ = 0; // no window text
+ *lpw++ = 0; // no creation data
+
+
+ GlobalUnlock(hgbl);
+ ret = DialogBoxIndirect(gHInstance, (LPDLGTEMPLATE) hgbl, gSexyAppBase->mHWnd, (DLGPROC) MarkerListDialogProc);
+ GlobalFree(hgbl);
+
+ gSexyAppBase->mLastTime = timeGetTime();
+
+ return ret;
+}
+
+static INT_PTR CALLBACK JumpToTimeDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ HWND anEdit = GetDlgItem(hwnd,100);
+ HKEY aGameKey;
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + gSexyAppBase->mRegKey);
+ if (RegOpenKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, KEY_READ | KEY_WRITE, &aGameKey) == ERROR_SUCCESS)
+ {
+ char aBuf[1024];
+ DWORD aLength = 1000;
+ DWORD aType = REG_SZ;
+ if (RegQueryValueExA(aGameKey, "DemoJumpTime", 0, &aType, (uchar*) aBuf, &aLength) == ERROR_SUCCESS)
+ {
+ aBuf[aLength] = 0;
+ SetWindowTextA(anEdit,aBuf);
+ SendMessage(anEdit,EM_SETSEL,0,-1);
+ }
+ RegCloseKey(aGameKey);
+ }
+ return TRUE;
+ }
+ break;
+
+ case WM_CLOSE:
+ EndDialog(hwnd,0);
+ return TRUE;
+
+ case WM_COMMAND:
+ if (HIWORD(wParam)==BN_CLICKED)
+ {
+ if (LOWORD(wParam)==IDOK)
+ {
+ char aBuf[512];
+ HWND anEdit = GetDlgItem(hwnd,100);
+ GetWindowTextA(anEdit,aBuf,500);
+
+ HKEY aGameKey;
+ std::string aKeyName = RemoveTrailingSlash("SOFTWARE\\" + gSexyAppBase->mRegKey);
+ if (RegOpenKeyExA(HKEY_CURRENT_USER, aKeyName.c_str(), 0, KEY_READ | KEY_WRITE, &aGameKey) == ERROR_SUCCESS)
+ {
+ RegSetValueExA(aGameKey, "DemoJumpTime", 0, REG_SZ, (const BYTE*)aBuf, strlen(aBuf)+1);
+ RegCloseKey(aGameKey);
+ }
+
+ int aTime = 0;
+ char *aPtr = strtok(aBuf,":");
+ while (aPtr != NULL)
+ {
+ aTime *= 60;
+ aTime += atoi(aPtr);
+ aPtr = strtok(NULL,":");
+ }
+ aTime++;
+
+ int aNumFrames = aTime*1000/gSexyAppBase->mFrameTime;
+ gSexyAppBase->mFastForwardToUpdateNum = gSexyAppBase->mDemoLength - aNumFrames;
+
+
+ }
+
+ EndDialog(hwnd,0);
+ return TRUE;
+ }
+ break;
+ }
+
+ return FALSE;
+}
+
+static int DemoJumpToTime()
+{
+ HGLOBAL hgbl;
+ LPDLGTEMPLATE lpdt;
+ LPDLGITEMTEMPLATE lpdit;
+ LPWORD lpw;
+ LPWSTR lpwsz;
+ LRESULT ret;
+ int nchar;
+
+ hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
+ if (!hgbl)
+ return -1;
+
+ lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
+
+ // Define a dialog box.
+ lpdt->style = WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT;
+ lpdt->cdit = 3; // number of controls
+ lpdt->x = 10; lpdt->y = 10;
+ lpdt->cx = 200; lpdt->cy = 50;
+
+ lpw = (LPWORD) (lpdt + 1);
+ *lpw++ = 0; // no menu
+ *lpw++ = 0; // predefined dialog box class (by default)
+
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Jump To Time", -1, lpwsz, 50);
+ lpw += nchar;
+ *lpw++ = 8;
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Tahoma", -1, lpwsz, 50);
+ lpw += nchar;
+
+ // Define Edit
+ lpw = lpdwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
+ lpdit = (LPDLGITEMTEMPLATE) lpw;
+ lpdit->x = 5; lpdit->y = 5;
+ lpdit->cx = 190; lpdit->cy = 15;
+ lpdit->id = 100;
+ lpdit->style = WS_VISIBLE | WS_CHILD;
+ lpdit->dwExtendedStyle = WS_EX_CLIENTEDGE;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0081; // edit class
+ *lpw++ = 0; // no window text
+ *lpw++ = 0; // no creation data
+
+ // Define Button
+ lpw = lpdwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
+ lpdit = (LPDLGITEMTEMPLATE) lpw;
+ lpdit->x = 30; lpdit->y = 25;
+ lpdit->cx = 60; lpdit->cy = 15;
+ lpdit->id = IDOK;
+ lpdit->style = WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON;
+// lpdit->dwExtendedStyle = WS_EX_CLIENTEDGE;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0080; // button class
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Ok", -1, lpwsz, 50);
+ lpw += nchar;
+ lpw = lpdwAlign (lpw); // align creation data on DWORD boundary
+ *lpw++ = 0; // no creation data
+
+
+ // Define Button
+ lpw = lpdwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
+ lpdit = (LPDLGITEMTEMPLATE) lpw;
+ lpdit->x = 100; lpdit->y = 25;
+ lpdit->cx = 60; lpdit->cy = 15;
+ lpdit->id = IDCANCEL;
+ lpdit->style = WS_VISIBLE | WS_CHILD;
+// lpdit->dwExtendedStyle = WS_EX_CLIENTEDGE;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0080; // button class
+ lpwsz = (LPWSTR) lpw;
+ nchar = MultiByteToWideChar (CP_ACP, 0, "Cancel", -1, lpwsz, 50);
+ lpw += nchar;
+ lpw = lpdwAlign (lpw); // align creation data on DWORD boundary
+ *lpw++ = 0; // no creation data
+
+
+
+
+ GlobalUnlock(hgbl);
+ ret = DialogBoxIndirect(gHInstance, (LPDLGTEMPLATE) hgbl, gSexyAppBase->mHWnd, (DLGPROC) JumpToTimeDialogProc);
+ GlobalFree(hgbl);
+
+ gSexyAppBase->mLastTime = timeGetTime();
+
+ return ret;
+}
+
+static void ToggleDemoSoundVolume()
+{
+ if (gSexyAppBase->GetMusicVolume() == 0.0)
+ gSexyAppBase->SetMusicVolume(gSexyAppBase->mDemoMusicVolume);
+ else
+ {
+ gSexyAppBase->mDemoMusicVolume = gSexyAppBase->mMusicVolume;
+ gSexyAppBase->SetMusicVolume(0.0);
+ }
+
+ if (gSexyAppBase->GetSfxVolume() == 0.0)
+ gSexyAppBase->SetSfxVolume(gSexyAppBase->mDemoSfxVolume);
+ else
+ {
+ gSexyAppBase->mDemoSfxVolume = gSexyAppBase->mSfxVolume;
+ gSexyAppBase->SetSfxVolume(0.0);
+ }
+}
+
+static DWORD gPowerSaveTick = 0;
+static bool ScreenSaverWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &theResult)
+{
+ static bool gCreated = false;
+ static int gMouseMoveCount = 0;
+ static int gLastMouseX = 0, gLastMouseY = 0;
+ static bool gClosed = false;
+ typedef BOOL (WINAPI *VERIFYPWDPROC)(HWND);
+ static VERIFYPWDPROC aPasswordFunc = NULL;
+ HMODULE aPasswordLib = NULL;
+
+ if (gClosed)
+ return false;
+
+ switch (uMsg)
+ {
+ case WM_CREATE:
+ {
+ if (gCreated)
+ return false;
+
+ gCreated = true;
+ POINT aMousePoint;
+ GetCursorPos(&aMousePoint);
+ gLastMouseX = aMousePoint.x;
+ gLastMouseY = aMousePoint.y;
+
+ // Password checking stuff for 95/98/ME
+ OSVERSIONINFO aVersion;
+ aVersion.dwOSVersionInfoSize = sizeof(aVersion);
+ GetVersionEx(&aVersion);
+ if (aVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+ {
+ HKEY hKey;
+ if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE ,&hKey) == ERROR_SUCCESS)
+ {
+ DWORD aCheckPwd = 0;
+ DWORD aSize = sizeof(DWORD);
+ DWORD aType;
+ LONG aResult = RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD, NULL, &aType, (PBYTE) &aCheckPwd, &aSize);
+ if (aResult==ERROR_SUCCESS && aCheckPwd)
+ {
+ aPasswordLib = LoadLibrary(TEXT("PASSWORD.CPL"));
+ if (aPasswordLib)
+ {
+ aPasswordFunc = (VERIFYPWDPROC)GetProcAddress(aPasswordLib, "VerifyScreenSavePwd");
+ // prevents user from ctrl-alt-deleting the screensaver etc to avoid typing in a password
+ int aPrev;
+ SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, &aPrev, 0);
+ }
+
+ }
+ RegCloseKey(hKey);
+ }
+ }
+ return false;
+ }
+ break;
+
+ case WM_SYSCOMMAND:
+ {
+ switch (wParam)
+ {
+ case SC_CLOSE:
+ case SC_SCREENSAVE:
+ case SC_NEXTWINDOW:
+ case SC_PREVWINDOW:
+ theResult = FALSE;
+ return true;
+
+ default:
+ return false;
+ }
+ }
+ break;
+
+ case WM_MOUSEMOVE:
+ {
+ int aMouseX = LOWORD(lParam);
+ int aMouseY = HIWORD(lParam);
+// SEXY_TRACE(StrFormat("SCR MouseMove: %d %d",aMouseX,aMouseY).c_str());
+ if (aMouseX!=gLastMouseX || aMouseY!=gLastMouseY)
+ {
+ gLastMouseX = aMouseX;
+ gLastMouseY = aMouseY;
+ gMouseMoveCount++;
+ }
+
+ if (gMouseMoveCount < 4)
+ {
+ theResult = 0;
+ return true;
+ }
+ }
+ break;
+
+ case WM_NCACTIVATE:
+ case WM_ACTIVATE:
+ case WM_ACTIVATEAPP:
+ {
+ if (wParam != FALSE)
+ return false;
+ }
+ break;
+
+ case WM_CLOSE:
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ break;
+
+ default:
+ return false;
+ }
+
+ if (gSexyAppBase!=NULL && gSexyAppBase->mHWnd!=hWnd) // wrong window
+ return false;
+
+ if (GetTickCount()-gPowerSaveTick < 1000) // powersave just went on so ignore certain messages that seem to come on certain os's at that time
+ {
+ switch (uMsg)
+ {
+ case WM_MOUSEMOVE:
+ case WM_NCACTIVATE:
+ case WM_ACTIVATE:
+ case WM_ACTIVATEAPP:
+ case WM_CLOSE:
+ return false;
+ }
+ }
+
+ if (aPasswordFunc && gSexyAppBase!=NULL && gSexyAppBase->mInitialized) // need to verify password before closing
+ {
+ if (gSexyAppBase!=NULL && gSexyAppBase->mDDInterface!=NULL && gSexyAppBase->mDDInterface->mDD!=NULL)
+ {
+ gSexyAppBase->mDDInterface->mDD->FlipToGDISurface(); // so we can see the password dialog
+ gSexyAppBase->mNoDefer = true; // so the app doesn't draw over the password dialog
+ }
+
+ gClosed = true; // prevent this function from doing anything while in the password dialog
+ BOOL aPasswordResult = aPasswordFunc(hWnd);
+ gClosed = false; // let this functino work again
+
+ if (gSexyAppBase!=NULL)
+ {
+ gSexyAppBase->mNoDefer = false;
+ gSexyAppBase->ClearUpdateBacklog();
+ }
+
+ if (!aPasswordResult) // bad password
+ {
+ // Get new mouse coordinate
+ POINT aMousePoint;
+ GetCursorPos(&aMousePoint);
+ gLastMouseX = aMousePoint.x;
+ gLastMouseY = aMousePoint.y;
+ gMouseMoveCount = 0;
+
+ return false;
+ }
+
+
+ // can turn this SPI_SCREENSAVERRUNNING off now since screensaver is about to stop
+ int aPrev;
+ SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, &aPrev, 0);
+
+ // good password -> close and unload dll
+ FreeLibrary(aPasswordLib);
+ aPasswordLib = NULL;
+ aPasswordFunc = NULL;
+ }
+
+ // Screen saver should shutdown
+ gClosed = true;
+ PostMessage(hWnd, WM_CLOSE, 0, 0);
+
+/* const char *str = "";
+ switch (uMsg)
+ {
+ case WM_CREATE: str="WM_CREATE"; break;
+ case WM_SYSCOMMAND: str="WM_SYSCOMMAND"; break;
+ case WM_MOUSEMOVE: str="WM_MOUSEMOVE"; break;
+ case WM_NCACTIVATE: str="WM_NCACTIVATE"; break;
+ case WM_ACTIVATE: str="WM_ACTIVATE"; break;
+ case WM_ACTIVATEAPP: str="WM_ACTIVATEAPP"; break;
+ case WM_CLOSE: str="WM_CLOSE"; break;
+ case WM_LBUTTONDOWN: str="WM_LBUTTONDOWN"; break;
+ case WM_RBUTTONDOWN: str="WM_RBUTTONDOWN"; break;
+ case WM_MBUTTONDOWN: str="WM_MBUTTONDOWN"; break;
+ case WM_KEYDOWN: str="WM_KEYDOWN"; break;
+ case WM_SYSKEYDOWN: str="WM_SYSKEYDOWN"; break;
+ }
+
+ SEXY_TRACE(StrFormat("Scr shutdown: %s",str).c_str());*/
+ return false;
+}
+
+LRESULT CALLBACK SexyAppBase::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ if (gSexyAppBase!=NULL && gSexyAppBase->IsScreenSaver())
+ {
+ LRESULT aResult;
+ if (ScreenSaverWindowProc(hWnd,uMsg,wParam,lParam,aResult))
+ return aResult;
+ }
+
+ SexyAppBase* aSexyApp = (SexyAppBase*) GetWindowLong(hWnd, GWL_USERDATA);
+ switch (uMsg)
+ {
+// TODO: switch to killfocus/setfocus?
+// case WM_KILLFOCUS:
+// case WM_SETFOCUS:
+// if ((aSexyApp != NULL) && (!aSexyApp->mPlayingDemoBuffer))
+// {
+// if (hWnd == aSexyApp->mHWnd)
+// aSexyApp->mActive = uMsg==WM_SETFOCUS;
+// }
+// //Fallthrough
+
+ case WM_ACTIVATEAPP:
+ if ((aSexyApp != NULL) && (!aSexyApp->mPlayingDemoBuffer))
+ {
+ if (hWnd == aSexyApp->mHWnd)
+ {
+ aSexyApp->mActive = wParam != 0;
+ }
+ }
+ //Fallthrough
+
+ case WM_SIZE:
+ case WM_MOVE:
+ case WM_TIMER:
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDBLCLK:
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_MOUSEMOVE:
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ case WM_CHAR:
+ case WM_CLOSE:
+ case WM_MOUSEWHEEL:
+ case WM_DISPLAYCHANGE:
+ case WM_SYSCOLORCHANGE:
+ {
+/* if (aSexyApp!=NULL && aSexyApp->mProcessInTimer && !aSexyApp->mShutdown && aSexyApp->mRunning)
+ {
+ if (uMsg==WM_TIMER && wParam==101)
+ {
+ for (int i=0; i<5; i++)
+ {
+ if (GetQueueStatus(QS_INPUT | QS_PAINT))
+ break;
+
+ if (!aSexyApp->Process(false))
+ break;
+ }
+ }
+
+ break;
+ }*/
+
+ /*if ((aSexyApp != NULL) && (aSexyApp->mNoDefer))
+ {
+ // Check to see if we should be windowed
+ WINDOWPLACEMENT aWindowPlacement;
+ aWindowPlacement.length = sizeof(aWindowPlacement);
+ if (GetWindowPlacement(aSexyApp->mHWnd, &aWindowPlacement))
+ {
+ if (aWindowPlacement.showCmd == SW_SHOWMINIMIZED)
+ {
+ aSexyApp->Redraw(NULL);
+ }
+ }
+ }*/
+
+ if ((aSexyApp != NULL) && (!aSexyApp->mNoDefer))
+ {
+ bool keyDown = (uMsg==WM_KEYDOWN) || (uMsg==WM_SYSKEYDOWN);
+
+ if ((keyDown) || (uMsg==WM_KEYUP) || (uMsg == WM_SYSKEYUP))
+ {
+ if (wParam == VK_CONTROL)
+ aSexyApp->mCtrlDown = keyDown;
+ if (wParam == VK_MENU)
+ aSexyApp->mAltDown = keyDown;
+ }
+
+ if ((keyDown) && (aSexyApp->DebugKeyDownAsync(wParam, aSexyApp->mCtrlDown, aSexyApp->mAltDown)))
+ return 0;
+
+ if (aSexyApp->mPlayingDemoBuffer)
+ {
+ if (uMsg==WM_CHAR)
+ {
+ switch (wParam)
+ {
+ case '+':
+ aSexyApp->mUpdateMultiplier *= 1.5;
+ break;
+ case '-':
+ aSexyApp->mUpdateMultiplier /= 1.5;
+ break;
+ case '=':
+ aSexyApp->mUpdateMultiplier = 1;
+ break;
+ case 'p':
+ case 'P':
+ aSexyApp->mPaused = !aSexyApp->mPaused;
+ aSexyApp->mLastTimeCheck = timeGetTime();
+ aSexyApp->mUpdateFTimeAcc = 0.0;
+ break;
+
+ case 'n':
+ case 'N':
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mUpdateCount+1;
+ aSexyApp->mFastForwardStep = true;
+ break;
+
+ case 'm':
+ case 'M':
+ aSexyApp->mFastForwardToMarker = true;
+ break;
+
+ case 'l':
+ case 'L':
+ ListDemoMarkers();
+ break;
+
+ case 'j':
+ case 'J':
+ DemoJumpToTime();
+ break;
+
+ case 's':
+ case 'S':
+ ToggleDemoSoundVolume();
+ break;
+
+ case '4':
+ // Fast foward to 120 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (120000 / aSexyApp->mFrameTime);
+ break;
+ case '5':
+ // Fast foward to 90 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (90000 / aSexyApp->mFrameTime);
+ break;
+ case '6':
+ // Fast foward to 60 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (60000 / aSexyApp->mFrameTime);
+ break;
+ case '7':
+ // Fast foward to 30 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (30000 / aSexyApp->mFrameTime);
+ break;
+ case '8':
+ // Fast foward to 10 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (10000 / aSexyApp->mFrameTime);
+ break;
+ case '9':
+ // Fast foward to 5 seconds before it ends
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength - (5000 / aSexyApp->mFrameTime);
+ break;
+ case '0':
+ // Fast forward to the end
+ aSexyApp->mFastForwardToUpdateNum = aSexyApp->mDemoLength;
+ break;
+
+ }
+ }
+ else if (uMsg==WM_KEYDOWN)
+ aSexyApp->DebugKeyDown(wParam);
+ }
+
+ bool pushMessage = true;
+
+ if (aSexyApp->mDeferredMessages.size() > 0)
+ {
+ // Don't add any more messages after WM_CLOSE
+ MSG* aMsg = &aSexyApp->mDeferredMessages.back();
+
+ if (aMsg->message == WM_CLOSE)
+ pushMessage = false;
+ if ((uMsg == WM_TIMER) && (uMsg == aMsg->message))
+ pushMessage = false; // Don't need more timer messages
+
+
+ if (pushMessage && (uMsg==WM_SYSCOLORCHANGE || uMsg==WM_DISPLAYCHANGE)) // kill duplicate SysColorChange() events.
+ {
+ WindowsMessageList::iterator aMsgListItr = aSexyApp->mDeferredMessages.begin();
+ while (pushMessage && aMsgListItr != aSexyApp->mDeferredMessages.end())
+ {
+ MSG& aMsg = *aMsgListItr;
+
+ if (aMsg.message == WM_SYSCOLORCHANGE || aMsg.message == WM_DISPLAYCHANGE)
+ pushMessage = false;
+
+ ++aMsgListItr;
+ }
+ }
+ }
+
+ if (pushMessage)
+ {
+ MSG msg;
+ msg.hwnd = hWnd;
+ msg.message = uMsg;
+ msg.lParam = lParam;
+ msg.wParam = wParam;
+
+ aSexyApp->mDeferredMessages.push_back(msg);
+ }
+
+ if (uMsg == WM_SIZE)
+ {
+ aSexyApp->mPhysMinimized = wParam == SIZE_MINIMIZED;
+ }
+ else if (uMsg == WM_SYSKEYDOWN)
+ {
+ if (wParam != VK_F4)
+ return 0;
+ }
+ else if (uMsg == WM_CLOSE)
+ {
+ /*char aStr[256];
+ sprintf(aStr, "CLOSED HWND: %d\r\n", hWnd);
+ OutputDebugString(aStr);*/
+
+ aSexyApp->CloseRequestAsync();
+ return 0;
+ }
+ }
+ }
+ break;
+
+ case WM_ENABLE:
+ if (aSexyApp != NULL)
+ {
+ aSexyApp->mIsDisabled = wParam == 0;
+ }
+ break;
+
+ case WM_QUERYOPEN:
+ if ((aSexyApp != NULL) && (!aSexyApp->AppCanRestore()))
+ return 0;
+ break;
+
+ case WM_SYSCHAR:
+ if ((aSexyApp != NULL) && (aSexyApp->IsAltKeyUsed(wParam)))
+ return 0;
+ break;
+
+ case WM_NCLBUTTONDOWN:
+ if (aSexyApp!=NULL)
+ {
+// aSexyApp->mProcessInTimer = true;
+ LRESULT aResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
+// aSexyApp->mProcessInTimer = false;
+ aSexyApp->ClearUpdateBacklog();
+ return aResult;
+ }
+ break;
+
+
+ case WM_SYSCOMMAND:
+ if (wParam==SC_MONITORPOWER)
+ {
+ gPowerSaveTick = GetTickCount();
+ if (aSexyApp!=NULL && (!aSexyApp->mAllowMonitorPowersave || !aSexyApp->mLoaded))
+ return FALSE;
+ }
+ if (wParam==SC_SCREENSAVE && aSexyApp!=NULL && (!aSexyApp->mLoaded || !aSexyApp->mIsPhysWindowed))
+ return FALSE;
+
+ break;
+
+/* case WM_DISPLAYCHANGE:
+ SEXY_TRACE("WM_DISPLAYCHANGE 1");
+ if (aSexyApp!=NULL && aSexyApp->mIsWindowed && aSexyApp->mDDInterface!=NULL && aSexyApp->mHWnd==hWnd && aSexyApp->mLoaded)
+ {
+ SEXY_TRACE("WM_DISPLAYCHANGE 2");
+ aSexyApp->mDDInterface->Init(aSexyApp->mHWnd,aSexyApp->mIsWindowed);
+ aSexyApp->mWidgetManager->mImage = aSexyApp->mDDInterface->GetScreenImage();
+ aSexyApp->mWidgetManager->MarkAllDirty();
+ }
+ break;*/
+
+ case WM_DESTROY:
+ {
+ char aStr[256];
+ sprintf(aStr, "DESTROYED HWND: %d\r\n", hWnd);
+ OutputDebugStringA(aStr);
+ }
+ break;
+ case WM_SETCURSOR:
+ if (!aSexyApp->mSEHOccured)
+ aSexyApp->EnforceCursor();
+ return TRUE;
+ case WM_ERASEBKGND:
+ return TRUE;
+ case WM_ENDSESSION:
+ aSexyApp->Shutdown();
+ break;
+ case WM_PAINT:
+ if ((aSexyApp->mInitialized) && (!gInAssert) && (!aSexyApp->mSEHOccured))
+ {
+ RECT aClientRect;
+ GetClientRect(hWnd, &aClientRect);
+
+ PAINTSTRUCT ps;
+ BeginPaint(hWnd, &ps);
+
+ if (aSexyApp->mRunning)
+ aSexyApp->Redraw(NULL);
+
+ EndPaint(hWnd, &ps);
+
+ return 0;
+ }
+ break;
+ }
+
+ if ((aSexyApp != NULL) && (uMsg == aSexyApp->mNotifyGameMessage) && (hWnd == aSexyApp->mHWnd))
+ {
+ // Oh, we are trying to open another instance of ourselves.
+ // Bring up the original window instead
+ aSexyApp->HandleNotifyGameMessage(wParam,lParam);
+ return 0;
+ }
+
+ if (gSexyAppBase->mIsWideWindow)
+ return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+ else
+ return DefWindowProcA(hWnd, uMsg, wParam, lParam);
+}
+
+void SexyAppBase::HandleNotifyGameMessage(int theType, int theParam)
+{
+ if (theType==0) // bring to front message
+ {
+ WINDOWPLACEMENT aWindowPlacement;
+ aWindowPlacement.length = sizeof(WINDOWPLACEMENT);
+ GetWindowPlacement(mHWnd, &aWindowPlacement);
+
+ if (aWindowPlacement.showCmd == SW_SHOWMINIMIZED)
+ ShowWindow(mHWnd, SW_RESTORE);
+
+ ::SetForegroundWindow(mHWnd);
+ }
+}
+
+void SexyAppBase::RehupFocus()
+{
+ bool wantHasFocus = mActive && !mMinimized;
+
+ if (wantHasFocus != mHasFocus)
+ {
+ mHasFocus = wantHasFocus;
+
+ if (mHasFocus)
+ {
+ if (mMuteOnLostFocus)
+ Unmute(true);
+
+ mWidgetManager->GotFocus();
+ GotFocus();
+ }
+ else
+ {
+ if (mMuteOnLostFocus)
+ Mute(true);
+
+ mWidgetManager->LostFocus();
+ LostFocus();
+
+ ReleaseCapture();
+ mWidgetManager->DoMouseUps();
+ }
+ }
+}
+
+void SexyAppBase::ClearKeysDown()
+{
+ if (mWidgetManager != NULL) // fix stuck alt-key problem
+ {
+ for (int aKeyNum = 0; aKeyNum < 0xFF; aKeyNum++)
+ mWidgetManager->mKeyDown[aKeyNum] = false;
+ }
+ mCtrlDown = false;
+ mAltDown = false;
+}
+
+void SexyAppBase::WriteDemoTimingBlock()
+{
+ // Demo writing functions can only be called from the main thread and after SexyAppBase::Init
+ DBG_ASSERTE(GetCurrentThreadId() == mPrimaryThreadId);
+
+ while (mUpdateCount - mLastDemoUpdateCnt > 15)
+ {
+ mDemoBuffer.WriteNumBits(15, 4);
+ mLastDemoUpdateCnt += 15;
+
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_IDLE, 5);
+ mDemoCmdOrder++;
+ }
+
+ mDemoBuffer.WriteNumBits(mUpdateCount - mLastDemoUpdateCnt, 4);
+ mLastDemoUpdateCnt = mUpdateCount;
+ mDemoCmdOrder++;
+}
+
+int aNumBigMoveMessages = 0;
+int aNumSmallMoveMessages = 0;
+int aNumTimerMessages = 0;
+
+bool SexyAppBase::PrepareDemoCommand(bool required)
+{
+ if (mDemoNeedsCommand)
+ {
+ mDemoCmdBitPos = mDemoBuffer.mReadBitPos;
+
+ mLastDemoUpdateCnt += mDemoBuffer.ReadNumBits(4, false);
+
+ mDemoIsShortCmd = mDemoBuffer.ReadNumBits(1, false) == 1;
+
+ if (mDemoIsShortCmd)
+ mDemoCmdNum = mDemoBuffer.ReadNumBits(1, false);
+ else
+ mDemoCmdNum = mDemoBuffer.ReadNumBits(5, false);
+
+ mDemoNeedsCommand = false;
+
+ mDemoCmdOrder++;
+ }
+
+ DBG_ASSERTE((mUpdateCount == mLastDemoUpdateCnt) || (!required));
+
+ return mUpdateCount == mLastDemoUpdateCnt;
+}
+
+void SexyAppBase::ProcessDemo()
+{
+ if (mPlayingDemoBuffer)
+ {
+ // At end of demo buffer? How dare you!
+ DBG_ASSERTE(!mDemoBuffer.AtEnd());
+
+ while ((!mShutdown) && (mUpdateCount == mLastDemoUpdateCnt) && (!mDemoBuffer.AtEnd()))
+ {
+ if (PrepareDemoCommand(false))
+ {
+ mDemoNeedsCommand = true;
+
+ if (mDemoIsShortCmd)
+ {
+ switch (mDemoCmdNum)
+ {
+ case 0:
+ {
+ int aDeltaX = mDemoBuffer.ReadNumBits(6, true);
+ int aDeltaY = mDemoBuffer.ReadNumBits(6, true);
+ mLastDemoMouseX += aDeltaX;
+ mLastDemoMouseY += aDeltaY;
+
+ mWidgetManager->MouseMove(mLastDemoMouseX, mLastDemoMouseY);
+ }
+ break;
+ case 1:
+ {
+ bool down = mDemoBuffer.ReadNumBits(1, false) != 0;
+ int aBtnCount = mDemoBuffer.ReadNumBits(3, true);
+
+ if (down)
+ mWidgetManager->MouseDown(mLastDemoMouseX, mLastDemoMouseY, aBtnCount);
+ else
+ mWidgetManager->MouseUp(mLastDemoMouseX, mLastDemoMouseY, aBtnCount);
+ }
+ break;
+ }
+ }
+ else
+ {
+ switch (mDemoCmdNum)
+ {
+ case DEMO_MOUSE_POSITION:
+ {
+ mLastDemoMouseX = mDemoBuffer.ReadNumBits(12, false);
+ mLastDemoMouseY = mDemoBuffer.ReadNumBits(12, false);
+
+ mWidgetManager->MouseMove(mLastDemoMouseX, mLastDemoMouseY);
+ }
+ break;
+ case DEMO_ACTIVATE_APP:
+ {
+ mActive = mDemoBuffer.ReadNumBits(1, false) != 0;
+
+ RehupFocus();
+
+ if ((mActive) && (!mIsWindowed))
+ mWidgetManager->MarkAllDirty();
+
+ if ((mIsOpeningURL) && (!mActive))
+ URLOpenSucceeded(mOpeningURL);
+ }
+ break;
+ case DEMO_SIZE:
+ {
+ bool isMinimized = mDemoBuffer.ReadBoolean();
+
+ if ((!mShutdown) && (isMinimized != mMinimized))
+ {
+ mMinimized = isMinimized;
+
+ // We don't want any sounds (or music) playing while its minimized
+ if (mMinimized)
+ Mute(true);
+ else
+ {
+ Unmute(true);
+ mWidgetManager->MarkAllDirty();
+ }
+ }
+
+ RehupFocus();
+ }
+ break;
+ case DEMO_MOUSE_WHEEL:
+ {
+ int aScroll = mDemoBuffer.ReadNumBits(8, true);
+ mWidgetManager->MouseWheel(aScroll);
+ }
+ break;
+ case DEMO_KEY_DOWN:
+ {
+ KeyCode aKeyCode = (KeyCode) mDemoBuffer.ReadNumBits(8, false);
+ mWidgetManager->KeyDown(aKeyCode);
+ }
+ break;
+ case DEMO_KEY_UP:
+ {
+ KeyCode aKeyCode = (KeyCode) mDemoBuffer.ReadNumBits(8, false);
+ mWidgetManager->KeyUp(aKeyCode);
+ }
+ break;
+ case DEMO_KEY_CHAR:
+ {
+ int sizeMult = (int)mDemoBuffer.ReadNumBits(1, false) + 1; // will be 1 for single, 2 for double
+ SexyChar aChar = (SexyChar) mDemoBuffer.ReadNumBits(8*sizeMult, false);
+ mWidgetManager->KeyChar(aChar);
+ }
+ break;
+ case DEMO_CLOSE:
+ Shutdown();
+ break;
+ case DEMO_MOUSE_ENTER:
+ mMouseIn = true;
+ EnforceCursor();
+ break;
+ case DEMO_MOUSE_EXIT:
+ mWidgetManager->MouseExit(mLastDemoMouseX, mLastDemoMouseY);
+ mMouseIn = false;
+ EnforceCursor();
+ break;
+ case DEMO_LOADING_COMPLETE:
+ mDemoLoadingComplete = true;
+ break;
+ case DEMO_VIDEO_DATA:
+ mIsWindowed = mDemoBuffer.ReadBoolean();
+ mSyncRefreshRate = mDemoBuffer.ReadByte();
+ break;
+ case DEMO_IDLE:
+ break;
+ default:
+ DBG_ASSERTE("Invalid Demo Command" == 0);
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+void SexyAppBase::ShowMemoryUsage()
+{
+ DWORD aTotal = 0;
+ DWORD aFree = 0;
+
+ if (mDDInterface->mDD7 != NULL)
+ {
+ DDSCAPS2 aCaps;
+ ZeroMemory(&aCaps,sizeof(aCaps));
+ aCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
+ mDDInterface->mDD7->GetAvailableVidMem(&aCaps,&aTotal,&aFree);
+ }
+
+ MemoryImageSet::iterator anItr = mMemoryImageSet.begin();
+ typedef std::pair<int,int> FormatUsage;
+ typedef std::map<PixelFormat,FormatUsage> FormatMap;
+ FormatMap aFormatMap;
+ int aTextureMemory = 0;
+ while (anItr != mMemoryImageSet.end())
+ {
+ MemoryImage* aMemoryImage = *anItr;
+ if (aMemoryImage->mD3DData != NULL)
+ {
+ TextureData *aData = (TextureData*)aMemoryImage->mD3DData;
+ aTextureMemory += aData->mTexMemSize;
+
+ FormatUsage &aUsage = aFormatMap[aData->mPixelFormat];
+ aUsage.first++;
+ aUsage.second += aData->mTexMemSize;
+ }
+
+ ++anItr;
+ }
+
+ std::string aStr;
+
+ const char *aDesc;
+ if (Is3DAccelerationRecommended())
+ aDesc = "Recommended";
+ else if (Is3DAccelerationSupported())
+ aDesc = "Supported";
+ else
+ aDesc = "Unsupported";
+
+ aStr += StrFormat("3D-Mode is %s (3D is %s on this system)\r\n\r\n",Is3DAccelerated()?"On":"Off",aDesc);
+
+ aStr += StrFormat("Num Images: %d\r\n",(int)mMemoryImageSet.size());
+ aStr += StrFormat("Num Sounds: %d\r\n",mSoundManager->GetNumSounds());
+ aStr += StrFormat("Video Memory: %s/%s KB\r\n", SexyStringToString(CommaSeperate((aTotal-aFree)/1024)).c_str(), SexyStringToString(CommaSeperate(aTotal/1024)).c_str());
+ aStr += StrFormat("Texture Memory: %s KB\r\n",CommaSeperate(aTextureMemory/1024).c_str());
+
+ FormatUsage aUsage = aFormatMap[PixelFormat_A8R8G8B8];
+ aStr += StrFormat("A8R8G8B8: %d - %s KB\r\n",aUsage.first,SexyStringToString(CommaSeperate(aUsage.second/1024)).c_str());
+ aUsage = aFormatMap[PixelFormat_A4R4G4B4];
+ aStr += StrFormat("A4R4G4B4: %d - %s KB\r\n",aUsage.first,SexyStringToString(CommaSeperate(aUsage.second/1024)).c_str());
+ aUsage = aFormatMap[PixelFormat_R5G6B5];
+ aStr += StrFormat("R5G6B5: %d - %s KB\r\n",aUsage.first,SexyStringToString(CommaSeperate(aUsage.second/1024)).c_str());
+ aUsage = aFormatMap[PixelFormat_Palette8];
+ aStr += StrFormat("Palette8: %d - %s KB\r\n",aUsage.first,SexyStringToString(CommaSeperate(aUsage.second/1024)).c_str());
+
+ MsgBox(aStr,"Video Stats",MB_OK);
+ mLastTime = timeGetTime();
+}
+
+bool SexyAppBase::IsAltKeyUsed(WPARAM wParam)
+{
+ int aChar = tolower(wParam);
+ switch (aChar)
+ {
+ case 13: // alt-enter
+ case 'r':
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool SexyAppBase::DebugKeyDown(int theKey)
+{
+ if ((theKey == 'R') && (mWidgetManager->mKeyDown[KEYCODE_MENU]))
+ {
+#ifndef RELEASEFINAL
+ if (ReparseModValues())
+ PlaySoundA("c:\\windows\\media\\Windows XP Menu Command.wav", NULL, SND_ASYNC);
+ else
+ {
+ for (int aKeyNum = 0; aKeyNum < 0xFF; aKeyNum++) // prevent alt from getting stuck
+ mWidgetManager->mKeyDown[aKeyNum] = false;
+ }
+#endif
+ }
+ else if (theKey == VK_F3)
+ {
+ if(mWidgetManager->mKeyDown[KEYCODE_SHIFT])
+ {
+ mShowFPS = true;
+ if (++mShowFPSMode >= Num_FPS_Types)
+ mShowFPSMode = 0;
+ }
+ else
+ mShowFPS = !mShowFPS;
+
+ mWidgetManager->MarkAllDirty();
+
+ if (mShowFPS)
+ {
+ gFPSTimer.Start();
+ gFrameCount = 0;
+ gFPSDisplay = 0;
+ gForceDisplay = true;
+ }
+ }
+ else if (theKey == VK_F8)
+ {
+ if(mWidgetManager->mKeyDown[KEYCODE_SHIFT])
+ {
+ Set3DAcclerated(!Is3DAccelerated());
+
+ char aBuf[512];
+ sprintf(aBuf,"3D-Mode: %s",Is3DAccelerated()?"ON":"OFF");
+ MsgBox(aBuf,"Mode Switch",MB_OK);
+ mLastTime = timeGetTime();
+ }
+ else
+ ShowMemoryUsage();
+
+ return true;
+ }
+ else if (theKey == VK_F10)
+ {
+#ifndef RELEASEFINAL
+ if (mWidgetManager->mKeyDown[KEYCODE_CONTROL])
+ {
+ if (mUpdateMultiplier==0.25)
+ mUpdateMultiplier = 1.0;
+ else
+ mUpdateMultiplier = 0.25;
+ }
+ else if(mWidgetManager->mKeyDown[KEYCODE_SHIFT])
+ {
+ mStepMode = 0;
+ ClearUpdateBacklog();
+ }
+ else
+ mStepMode = 1;
+#endif
+
+ return true;
+ }
+ else if (theKey == VK_F11)
+ {
+ if (mWidgetManager->mKeyDown[KEYCODE_SHIFT])
+ DumpProgramInfo();
+ else
+ TakeScreenshot();
+
+ return true;
+ }
+ else if (theKey == VK_F2)
+ {
+ bool isPerfOn = !SexyPerf::IsPerfOn();
+ if (isPerfOn)
+ {
+// MsgBox("Perf Monitoring: ON", "Perf Monitoring", MB_OK);
+ ClearUpdateBacklog();
+ SexyPerf::BeginPerf();
+ }
+ else
+ {
+ SexyPerf::EndPerf();
+ MsgBox(SexyPerf::GetResults().c_str(), "Perf Results", MB_OK);
+ ClearUpdateBacklog();
+ }
+ }
+ else
+ return false;
+
+ return false;
+}
+
+bool SexyAppBase::DebugKeyDownAsync(int theKey, bool ctrlDown, bool altDown)
+{
+ return false;
+}
+
+void SexyAppBase::CloseRequestAsync()
+{
+}
+
+// Why did I defer messages? Oh, incase a dialog comes up such as a crash
+// it won't keep crashing and stuff
+bool SexyAppBase::ProcessDeferredMessages(bool singleMessage)
+{
+ while (mDeferredMessages.size() > 0)
+ {
+ MSG aMsg = mDeferredMessages.front();
+ mDeferredMessages.pop_front();
+
+ UINT uMsg = aMsg.message;
+ LPARAM lParam = aMsg.lParam;
+ WPARAM wParam = aMsg.wParam;
+ HWND hWnd = aMsg.hwnd;
+
+ if ((mRecordingDemoBuffer) && (!mShutdown))
+ {
+ switch (uMsg)
+ {
+// TODO: switch to killfocus/setfocus?
+// case WM_SETFOCUS:
+// case WM_KILLFOCUS:
+// if (hWnd == mHWnd)
+// {
+// WriteDemoTimingBlock();
+// mDemoBuffer.WriteNumBits(0, 1);
+// mDemoBuffer.WriteNumBits(DEMO_ACTIVATE_APP, 5);
+// mDemoBuffer.WriteNumBits(uMsg==WM_SETFOCUS ? 1 : 0, 1);
+// }
+// break;
+
+ case WM_ACTIVATEAPP:
+ if (hWnd == mHWnd)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_ACTIVATE_APP, 5);
+ mDemoBuffer.WriteNumBits((wParam != 0) ? 1 : 0, 1);
+ }
+ break;
+
+ case WM_SIZE:
+ {
+ bool isMinimized = wParam == SIZE_MINIMIZED;
+
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_SIZE, 5);
+ mDemoBuffer.WriteBoolean(isMinimized);
+ }
+ break;
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDBLCLK:
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_MOUSEMOVE:
+ {
+ int aCurX = (short) LOWORD(lParam);
+ int aCurY = (short) HIWORD(lParam);
+
+ int aDiffX = aCurX - mLastDemoMouseX;
+ int aDiffY = aCurY - mLastDemoMouseY;
+
+ if ((abs(aCurX - mLastDemoMouseX) < 32) && (abs(aCurY - mLastDemoMouseY) < 32))
+ {
+ if ((aDiffX != 0) || (aDiffY != 0))
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(1, 1);
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(aDiffX, 6);
+ mDemoBuffer.WriteNumBits(aDiffY, 6);
+ }
+ }
+ else
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_MOUSE_POSITION, 5);
+ mDemoBuffer.WriteNumBits(aCurX, 12);
+ mDemoBuffer.WriteNumBits(aCurY, 12);
+ }
+
+ bool down = true;
+ int aBtnNum = 0;
+ switch (uMsg)
+ {
+ case WM_LBUTTONDOWN:
+ aBtnNum = 1;
+ break;
+ case WM_RBUTTONDOWN:
+ aBtnNum = -1;
+ break;
+ case WM_MBUTTONDOWN:
+ aBtnNum = 3;
+ break;
+ case WM_LBUTTONDBLCLK:
+ aBtnNum = 2;
+ break;
+ case WM_RBUTTONDBLCLK:
+ aBtnNum = -2;
+ break;
+ case WM_LBUTTONUP:
+ aBtnNum = 1;
+ down = false;
+ break;
+ case WM_RBUTTONUP:
+ aBtnNum = -1;
+ down = false;
+ break;
+ case WM_MBUTTONUP:
+ aBtnNum = 3;
+ down = false;
+ break;
+ }
+
+ if (aBtnNum != 0)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(1, 1);
+ mDemoBuffer.WriteNumBits(1, 1);
+ mDemoBuffer.WriteNumBits(down ? 1 : 0, 1);
+ mDemoBuffer.WriteNumBits(aBtnNum, 3);
+ }
+
+ mLastDemoMouseX = aCurX;
+ mLastDemoMouseY = aCurY;
+ }
+ break;
+ case WM_MOUSEWHEEL:
+ {
+ int aZDelta = ((short)HIWORD(wParam)) / 120;
+
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_MOUSE_WHEEL, 5);
+ mDemoBuffer.WriteNumBits(aZDelta, 8);
+ }
+ break;
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ {
+ KeyCode aKeyCode = (KeyCode) wParam;
+
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_KEY_DOWN, 5);
+ mDemoBuffer.WriteNumBits(aKeyCode, 8);
+ }
+ break;
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ {
+ KeyCode aKeyCode = (KeyCode) wParam;
+
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_KEY_UP, 5);
+ mDemoBuffer.WriteNumBits((int) aKeyCode, 8);
+ }
+ break;
+ case WM_CHAR:
+ {
+ SexyChar aChar = (SexyChar) wParam;
+
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_KEY_CHAR, 5);
+ mDemoBuffer.WriteNumBits(sizeof(SexyChar) == 2, 1);
+ mDemoBuffer.WriteNumBits(aChar, sizeof(SexyChar)*8);
+ }
+ break;
+ case WM_CLOSE:
+ if ((hWnd == mHWnd) || (hWnd == mInvisHWnd))
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_CLOSE, 5);
+ }
+ break;
+ }
+
+ int aBufferSize = mDemoBuffer.GetDataLen();
+ }
+
+ if (!mPlayingDemoBuffer)
+ {
+ switch (uMsg)
+ {
+// TODO: switch to killfocus/setfocus?
+// case WM_KILLFOCUS:
+// case WM_SETFOCUS:
+ case WM_ACTIVATEAPP:
+ if ((hWnd == mHWnd) && (!gInAssert) && (!mSEHOccured) && (!mShutdown))
+ {
+// mActive = uMsg==WM_SETFOCUS;
+
+ RehupFocus();
+
+ if ((mActive) && (!mIsWindowed))
+ mWidgetManager->MarkAllDirty();
+
+ if ((mIsOpeningURL) && (!mActive))
+ URLOpenSucceeded(mOpeningURL);
+ }
+ break;
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDBLCLK:
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_MOUSEMOVE:
+ if ((!gInAssert) && (!mSEHOccured))
+ {
+ int x = (short) LOWORD(lParam);
+ int y = (short) HIWORD(lParam);
+ mWidgetManager->RemapMouse(x, y);
+
+ mLastUserInputTick = mLastTimerTime;
+
+ mWidgetManager->MouseMove(x, y);
+
+ if (!mMouseIn)
+ {
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_MOUSE_ENTER, 5);
+ }
+
+ mMouseIn = true;
+ EnforceCursor();
+ }
+
+ switch (uMsg)
+ {
+ case WM_LBUTTONDOWN:
+ SetCapture(hWnd);
+ mWidgetManager->MouseDown(x, y, 1);
+ break;
+ case WM_RBUTTONDOWN:
+ SetCapture(hWnd);
+ mWidgetManager->MouseDown(x, y, -1);
+ break;
+ case WM_MBUTTONDOWN:
+ SetCapture(hWnd);
+ mWidgetManager->MouseDown(x, y, 3);
+ break;
+ case WM_LBUTTONDBLCLK:
+ SetCapture(hWnd);
+ mWidgetManager->MouseDown(x, y, 2);
+ break;
+ case WM_RBUTTONDBLCLK:
+ SetCapture(hWnd);
+ mWidgetManager->MouseDown(x, y, -2);
+ break;
+ case WM_LBUTTONUP:
+ if ((mWidgetManager->mDownButtons & ~1) == 0)
+ ReleaseCapture();
+ mWidgetManager->MouseUp(x, y, 1);
+ break;
+ case WM_RBUTTONUP:
+ if ((mWidgetManager->mDownButtons & ~2) == 0)
+ ReleaseCapture();
+ mWidgetManager->MouseUp(x, y, -1);
+ break;
+ case WM_MBUTTONUP:
+ if ((mWidgetManager->mDownButtons & ~4) == 0)
+ ReleaseCapture();
+ mWidgetManager->MouseUp(x, y, 3);
+ break;
+ }
+ }
+ break;
+ case WM_MOUSEWHEEL:
+ {
+ char aZDelta = ((short)HIWORD(wParam)) / 120;
+ mWidgetManager->MouseWheel(aZDelta);
+ }
+ break;
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ mLastUserInputTick = mLastTimerTime;
+
+ if (wParam==VK_RETURN && uMsg==WM_SYSKEYDOWN && !mForceFullscreen && !mForceWindowed)
+ {
+ SwitchScreenMode(!mIsWindowed);
+ ClearKeysDown();
+ break;
+ }
+ else if ((wParam == 'D') && (mWidgetManager != NULL) && (mWidgetManager->mKeyDown[KEYCODE_CONTROL]) && (mWidgetManager->mKeyDown[KEYCODE_MENU]))
+ {
+ PlaySoundA("c:\\windows\\media\\Windows XP Menu Command.wav", NULL, SND_ASYNC);
+ mDebugKeysEnabled = !mDebugKeysEnabled;
+ }
+
+ if (mDebugKeysEnabled)
+ {
+ if (DebugKeyDown(wParam))
+ break;
+ }
+
+ mWidgetManager->KeyDown((KeyCode) wParam);
+ break;
+
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ mLastUserInputTick = mLastTimerTime;
+ mWidgetManager->KeyUp((KeyCode) wParam);
+ break;
+ case WM_CHAR:
+ mLastUserInputTick = mLastTimerTime;
+ mWidgetManager->KeyChar((SexyChar) wParam);
+ break;
+ case WM_MOVE:
+ {
+ if ((hWnd == mHWnd) && (mIsWindowed))
+ {
+ WINDOWPLACEMENT aWindowPlacment;
+ aWindowPlacment.length = sizeof(aWindowPlacment);
+
+ GetWindowPlacement(hWnd, &aWindowPlacment);
+ if ((aWindowPlacment.showCmd == SW_SHOW) ||
+ (aWindowPlacment.showCmd == SW_SHOWNORMAL))
+ {
+ mPreferredX = aWindowPlacment.rcNormalPosition.left;
+ mPreferredY = aWindowPlacment.rcNormalPosition.top;
+ }
+ }
+ }
+ break;
+ case WM_SIZE:
+ {
+ bool isMinimized = wParam == SIZE_MINIMIZED;
+
+ if ((hWnd == mHWnd) && (!mShutdown) && (isMinimized != mMinimized))
+ {
+ mMinimized = isMinimized;
+
+ // We don't want any sounds (or music) playing while its minimized
+ if (mMinimized)
+ {
+ if (mMuteOnLostFocus)
+ Mute(true);
+ }
+ else
+ {
+ if (mMuteOnLostFocus)
+ Unmute(true);
+
+ mWidgetManager->MarkAllDirty();
+ }
+ }
+
+ RehupFocus();
+ if (wParam==SIZE_MAXIMIZED)
+ SwitchScreenMode(false);
+ }
+ break;
+ case WM_TIMER:
+ if ((!gInAssert) && (!mSEHOccured) && (mRunning))
+ {
+ DWORD aTimeNow = GetTickCount();
+ if (aTimeNow - mLastTimerTime > 500)
+ mLastBigDelayTime = aTimeNow;
+
+ mLastTimerTime = aTimeNow;
+
+ if ((mIsOpeningURL) &&
+ (aTimeNow - mLastBigDelayTime > 5000))
+ {
+ if ((aTimeNow - mOpeningURLTime > 8000) && (!mActive))
+ {
+ //TODO: Have some demo message thing
+ URLOpenSucceeded(mOpeningURL);
+ }
+ else if ((aTimeNow - mOpeningURLTime > 12000) && (mActive))
+ {
+ URLOpenFailed(mOpeningURL);
+ }
+ }
+
+ POINT aULCorner = {0, 0};
+ ::ClientToScreen(hWnd, &aULCorner);
+
+ POINT aBRCorner = {mDDInterface->mDisplayWidth, mDDInterface->mDisplayHeight};
+ ::ClientToScreen(hWnd, &aBRCorner);
+
+ POINT aPoint;
+ ::GetCursorPos(&aPoint);
+
+ HWND aWindow = ::WindowFromPoint(aPoint);
+ bool isMouseIn = (aWindow == hWnd) &&
+ (aPoint.x >= aULCorner.x) && (aPoint.y >= aULCorner.y) &&
+ (aPoint.x < aBRCorner.x) && (aPoint.y < aBRCorner.y);
+
+ if (mMouseIn != isMouseIn)
+ {
+ if ((mRecordingDemoBuffer) && (!mShutdown))
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+
+ if (isMouseIn)
+ mDemoBuffer.WriteNumBits(DEMO_MOUSE_ENTER, 5);
+ else
+ mDemoBuffer.WriteNumBits(DEMO_MOUSE_EXIT, 5);
+ }
+
+ if (!isMouseIn)
+ {
+ int x = aPoint.x - aULCorner.x;
+ int y = aPoint.y - aULCorner.y;
+ mWidgetManager->RemapMouse(x, y);
+ mWidgetManager->MouseExit(x, y);
+ }
+
+ mMouseIn = isMouseIn;
+ EnforceCursor();
+ }
+ }
+ break;
+
+ case WM_SYSCOLORCHANGE:
+ case WM_DISPLAYCHANGE:
+ mWidgetManager->SysColorChangedAll();
+ mWidgetManager->MarkAllDirty();
+ break;
+ }
+ }
+
+ switch (uMsg)
+ {
+ case WM_CLOSE:
+ if ((hWnd == mHWnd) || (hWnd == mInvisHWnd))
+ {
+ // This should short-circuit all demo calls, otherwise we will get
+ // all sorts of weird asserts because we are changing
+ // program flow
+ mManualShutdown = true;
+
+ Shutdown();
+ }
+ break;
+ }
+
+ if (singleMessage)
+ break;
+ }
+
+ return (mDeferredMessages.size() > 0);
+}
+
+void SexyAppBase::Done3dTesting()
+{
+}
+
+// return file name that you want to upload
+std::string SexyAppBase::NotifyCrashHook()
+{
+ return "";
+}
+
+void SexyAppBase::MakeWindow()
+{
+ //OutputDebugString("MAKING WINDOW\r\n");
+
+ if (mHWnd != NULL)
+ {
+ SetWindowLong(mHWnd, GWL_USERDATA, NULL);
+ HWND anOldWindow = mHWnd;
+ mHWnd = NULL;
+ DestroyWindow(anOldWindow);
+ mWidgetManager->mImage = NULL;
+ }
+
+
+ if ((mPlayingDemoBuffer) || (mIsWindowed && !mFullScreenWindow))
+ {
+ DWORD aWindowStyle = WS_CLIPCHILDREN | WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
+ if (mEnableMaximizeButton)
+ aWindowStyle |= WS_MAXIMIZEBOX;
+
+ RECT aRect;
+ aRect.left = 0;
+ aRect.top = 0;
+ aRect.right = mWidth;
+ aRect.bottom = mHeight;
+
+ BOOL worked = AdjustWindowRect(&aRect, aWindowStyle, FALSE);
+
+ int aWidth = aRect.right - aRect.left;
+ int aHeight = aRect.bottom - aRect.top;
+
+ // Get the work area of the desktop to allow us to center
+ RECT aDesktopRect;
+ ::SystemParametersInfo(SPI_GETWORKAREA, NULL, &aDesktopRect, NULL);
+
+ int aPlaceX = 64;
+ int aPlaceY = 64;
+
+ if (mPreferredX != -1)
+ {
+ aPlaceX = mPreferredX;
+ aPlaceY = mPreferredY;
+
+ int aSpacing = 4;
+
+ if (aPlaceX < aDesktopRect.left + aSpacing)
+ aPlaceX = aDesktopRect.left + aSpacing;
+
+ if (aPlaceY < aDesktopRect.top + aSpacing)
+ aPlaceY = aDesktopRect.top + aSpacing;
+
+ if (aPlaceX + aWidth >= aDesktopRect.right - aSpacing)
+ aPlaceX = aDesktopRect.right - aWidth - aSpacing;
+
+ if (aPlaceY + aHeight >= aDesktopRect.bottom - aSpacing)
+ aPlaceY = aDesktopRect.bottom - aHeight - aSpacing;
+ }
+
+ if (CheckFor98Mill())
+ {
+ mHWnd = CreateWindowExA(
+ 0,
+ "MainWindow",
+ SexyStringToStringFast(mTitle).c_str(),
+ aWindowStyle,
+ aPlaceX,
+ aPlaceY,
+ aWidth,
+ aHeight,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ }
+ else
+ {
+ mHWnd = CreateWindowEx(
+ 0,
+ _S("MainWindow"),
+ mTitle.c_str(),
+ aWindowStyle,
+ aPlaceX,
+ aPlaceY,
+ aWidth,
+ aHeight,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ }
+
+ if (mPreferredX == -1)
+ {
+ ::MoveWindow(mHWnd,
+ aDesktopRect.left + ((aDesktopRect.right - aDesktopRect.left) - aWidth)/2,
+ aDesktopRect.top + (int) (((aDesktopRect.bottom - aDesktopRect.top) - aHeight)*0.382),
+ aWidth, aHeight, FALSE);
+ }
+
+ mIsPhysWindowed = true;
+ }
+ else
+ {
+ if (CheckFor98Mill())
+ {
+ mHWnd = CreateWindowExA(
+ WS_EX_TOPMOST,
+ "MainWindow",
+ SexyStringToStringFast(mTitle).c_str(),
+ WS_POPUP | WS_VISIBLE,
+ 0,
+ 0,
+ mWidth,
+ mHeight,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ }
+ else
+ {
+ mHWnd = CreateWindowEx(
+ WS_EX_TOPMOST,
+ _S("MainWindow"),
+ mTitle.c_str(),
+ WS_POPUP | WS_VISIBLE,
+ 0,
+ 0,
+ mWidth,
+ mHeight,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ }
+
+ mIsPhysWindowed = false;
+ }
+
+ /*char aStr[256];
+ sprintf(aStr, "HWND: %d\r\n", mHWnd);
+ OutputDebugString(aStr);*/
+
+ SetWindowLong(mHWnd, GWL_USERDATA, (LONG) this);
+
+ if (mDDInterface == NULL)
+ {
+ mDDInterface = new DDInterface(this);
+
+ // Enable 3d setting
+ bool is3D = false;
+ bool is3DOptionSet = RegistryReadBoolean("Is3D", &is3D);
+ if (is3DOptionSet)
+ {
+ if (mAutoEnable3D)
+ {
+ mAutoEnable3D = false;
+ mTest3D = true;
+ }
+
+ if (is3D)
+ mTest3D = true;
+
+ mDDInterface->mIs3D = is3D;
+ }
+ }
+
+ int aResult = InitDDInterface();
+
+ if (mDDInterface->mD3DTester!=NULL && mDDInterface->mD3DTester->ResultsChanged())
+ RegistryEraseValue(_S("Is3D"));
+
+ if ((mIsWindowed) && (aResult == DDInterface::RESULT_INVALID_COLORDEPTH))
+ {
+ if (mForceWindowed)
+ {
+ Popup(GetString("PLEASE_SET_COLOR_DEPTH", _S("Please set your desktop color depth to 16 bit.")));
+ DoExit(1);
+ }
+ else
+ {
+ mForceFullscreen = true;
+ SwitchScreenMode(false);
+ }
+ return;
+ }
+ else if ((!mIsWindowed) &&
+ ((aResult == DDInterface::RESULT_EXCLUSIVE_FAIL) ||
+ (aResult == DDInterface::RESULT_DISPCHANGE_FAIL)))
+ {
+ mForceWindowed = true;
+ SwitchScreenMode(true);
+ }
+ else if (aResult == DDInterface::RESULT_3D_FAIL)
+ {
+ Set3DAcclerated(false);
+ return;
+ }
+ else if (aResult != DDInterface::RESULT_OK)
+ {
+ if (Is3DAccelerated())
+ {
+ Set3DAcclerated(false);
+ return;
+ }
+ else
+ {
+ Popup(GetString("FAILED_INIT_DIRECTDRAW", _S("Failed to initialize DirectDraw: ")) + StringToSexyString(DDInterface::ResultToString(aResult) + " " + mDDInterface->mErrorString));
+ DoExit(1);
+ }
+ }
+
+ bool isActive = mActive;
+ mActive = GetActiveWindow() == mHWnd;
+
+ mPhysMinimized = false;
+ if (mMinimized)
+ {
+ if (mMuteOnLostFocus)
+ Unmute(true);
+
+ mMinimized = false;
+ isActive = mActive; // set this here so we don't call RehupFocus again.
+ RehupFocus();
+ }
+
+ if (isActive != mActive)
+ RehupFocus();
+
+ ReInitImages();
+
+ mWidgetManager->mImage = mDDInterface->GetScreenImage();
+ mWidgetManager->MarkAllDirty();
+
+ SetTimer(mHWnd, 100, mFrameTime, NULL);
+}
+
+void SexyAppBase::DeleteNativeImageData()
+{
+ MemoryImageSet::iterator anItr = mMemoryImageSet.begin();
+ while (anItr != mMemoryImageSet.end())
+ {
+ MemoryImage* aMemoryImage = *anItr;
+ aMemoryImage->DeleteNativeData();
+ ++anItr;
+ }
+}
+
+void SexyAppBase::DeleteExtraImageData()
+{
+ AutoCrit anAutoCrit(mDDInterface->mCritSect);
+ MemoryImageSet::iterator anItr = mMemoryImageSet.begin();
+ while (anItr != mMemoryImageSet.end())
+ {
+ MemoryImage* aMemoryImage = *anItr;
+ aMemoryImage->DeleteExtraBuffers();
+ ++anItr;
+ }
+}
+
+void SexyAppBase::ReInitImages()
+{
+ MemoryImageSet::iterator anItr = mMemoryImageSet.begin();
+ while (anItr != mMemoryImageSet.end())
+ {
+ MemoryImage* aMemoryImage = *anItr;
+ aMemoryImage->ReInit();
+ ++anItr;
+ }
+}
+
+
+void SexyAppBase::LoadingThreadProc()
+{
+}
+
+void SexyAppBase::LoadingThreadCompleted()
+{
+}
+
+void SexyAppBase::LoadingThreadProcStub(void *theArg)
+{
+ SexyAppBase* aSexyApp = (SexyAppBase*) theArg;
+
+ aSexyApp->LoadingThreadProc();
+
+ char aStr[256];
+ sprintf(aStr, "Resource Loading Time: %d\r\n", (GetTickCount() - aSexyApp->mTimeLoaded));
+ OutputDebugStringA(aStr);
+
+ aSexyApp->mLoadingThreadCompleted = true;
+}
+
+void SexyAppBase::StartLoadingThread()
+{
+ if (!mLoadingThreadStarted)
+ {
+ mYieldMainThread = true;
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+ mLoadingThreadStarted = true;
+ _beginthread(LoadingThreadProcStub, 0, this);
+ }
+}
+void SexyAppBase::CursorThreadProc()
+{
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+
+ POINT aLastCursorPos = {0, 0};
+ int aLastDrawCount = 0;
+
+ while (!mShutdown)
+ {
+// if (mProcessInTimer)
+// PostMessage(mHWnd,WM_TIMER,101,0);
+
+ POINT aCursorPos;
+
+ if (mPlayingDemoBuffer)
+ {
+ aCursorPos.x = mLastDemoMouseX;
+ aCursorPos.y = mLastDemoMouseY;
+ }
+ else
+ {
+ ::GetCursorPos(&aCursorPos);
+ ::ScreenToClient(mHWnd, &aCursorPos);
+ }
+
+ if (aLastDrawCount != mDrawCount)
+ {
+ // We did a draw so we may have committed a pending mNextCursorX/Y
+ aLastCursorPos.x = mDDInterface->mCursorX;
+ aLastCursorPos.y = mDDInterface->mCursorY;
+ }
+
+ if ((aCursorPos.x != aLastCursorPos.x) ||
+ (aCursorPos.y != aLastCursorPos.y))
+ {
+ DWORD aTimeNow = timeGetTime();
+ if (aTimeNow - mNextDrawTick > mDDInterface->mMillisecondsPerFrame + 5)
+ {
+ // Do the special drawing if we are rendering at less than full framerate
+ mDDInterface->SetCursorPos(aCursorPos.x, aCursorPos.y);
+ aLastCursorPos = aCursorPos;
+ }
+ else
+ {
+ // Set them up to get assigned in the next screen redraw
+ mDDInterface->mNextCursorX = aCursorPos.x;
+ mDDInterface->mNextCursorY = aCursorPos.y;
+ }
+ }
+
+ Sleep(10);
+ }
+
+ mCursorThreadRunning = false;
+}
+
+void SexyAppBase::CursorThreadProcStub(void *theArg)
+{
+ CoInitialize(NULL);
+ SexyAppBase* aSexyApp = (SexyAppBase*) theArg;
+ aSexyApp->CursorThreadProc();
+}
+
+void SexyAppBase::StartCursorThread()
+{
+ if (!mCursorThreadRunning)
+ {
+ mCursorThreadRunning = true;
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+ _beginthread(CursorThreadProcStub, 0, this);
+ }
+}
+
+void SexyAppBase::SwitchScreenMode(bool wantWindowed, bool is3d, bool force)
+{
+ if (mForceFullscreen)
+ wantWindowed = false;
+
+ if (mIsWindowed == wantWindowed && !force)
+ {
+ Set3DAcclerated(is3d);
+ return;
+ }
+
+ // Set 3d acceleration preference
+ Set3DAcclerated(is3d,false);
+
+ // Always make the app windowed when playing demos, in order to
+ // make it easier to track down bugs. We place this after the
+ // sanity check just so things get re-initialized and stuff
+ //if (mPlayingDemoBuffer)
+ // wantWindowed = true;
+
+ mIsWindowed = wantWindowed;
+
+ MakeWindow();
+
+ // We need to do this check to allow IE to get focus instead of
+ // stealing it away for ourselves
+ if (!mIsOpeningURL)
+ {
+ ::ShowWindow(mHWnd, SW_NORMAL);
+ ::SetForegroundWindow(mHWnd);
+ }
+ else
+ {
+ // Show it but don't activate it
+ ::ShowWindow(mHWnd, SW_SHOWNOACTIVATE);
+ }
+
+ if (mSoundManager!=NULL)
+ {
+ mSoundManager->SetCooperativeWindow(mHWnd,mIsWindowed);
+ }
+
+ mLastTime = timeGetTime();
+}
+
+void SexyAppBase::SwitchScreenMode(bool wantWindowed)
+{
+ SwitchScreenMode(wantWindowed, Is3DAccelerated());
+}
+
+void SexyAppBase::SwitchScreenMode()
+{
+ SwitchScreenMode(mIsWindowed, Is3DAccelerated(), true);
+}
+
+void SexyAppBase::SetAlphaDisabled(bool isDisabled)
+{
+ if (mAlphaDisabled != isDisabled)
+ {
+ mAlphaDisabled = isDisabled;
+ mDDInterface->SetVideoOnlyDraw(mAlphaDisabled);
+ mWidgetManager->mImage = mDDInterface->GetScreenImage();
+ mWidgetManager->MarkAllDirty();
+ }
+}
+
+void SexyAppBase::EnforceCursor()
+{
+ bool wantSysCursor = true;
+
+ if (mDDInterface == NULL)
+ return;
+
+ if ((mSEHOccured) || (!mMouseIn))
+ {
+ ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
+ if (mDDInterface->SetCursorImage(NULL))
+ mCustomCursorDirty = true;
+ }
+ else
+ {
+ if ((mCursorImages[mCursorNum] == NULL) ||
+ ((!mPlayingDemoBuffer) && (!mCustomCursorsEnabled) && (mCursorNum != CURSOR_CUSTOM)))
+ {
+ if (mOverrideCursor != NULL)
+ ::SetCursor(mOverrideCursor);
+ else if (mCursorNum == CURSOR_POINTER)
+ ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
+ else if (mCursorNum == CURSOR_HAND)
+ ::SetCursor(mHandCursor);
+ else if (mCursorNum == CURSOR_TEXT)
+ ::SetCursor(::LoadCursor(NULL, IDC_IBEAM));
+ else if (mCursorNum == CURSOR_DRAGGING)
+ ::SetCursor(mDraggingCursor);
+ else if (mCursorNum == CURSOR_CIRCLE_SLASH)
+ ::SetCursor(::LoadCursor(NULL, IDC_NO));
+ else if (mCursorNum == CURSOR_SIZEALL)
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZEALL));
+ else if (mCursorNum == CURSOR_SIZENESW)
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZENESW));
+ else if (mCursorNum == CURSOR_SIZENS)
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZENS));
+ else if (mCursorNum == CURSOR_SIZENWSE)
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZENWSE));
+ else if (mCursorNum == CURSOR_SIZEWE)
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZEWE));
+ else if (mCursorNum == CURSOR_WAIT)
+ ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
+ else if (mCursorNum == CURSOR_CUSTOM)
+ ::SetCursor(NULL); // Default to not showing anything
+ else if (mCursorNum == CURSOR_NONE)
+ ::SetCursor(NULL);
+ else
+ ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
+
+ if (mDDInterface->SetCursorImage(NULL))
+ mCustomCursorDirty = true;
+ }
+ else
+ {
+ if (mDDInterface->SetCursorImage(mCursorImages[mCursorNum]))
+ mCustomCursorDirty = true;
+
+ if (!mPlayingDemoBuffer)
+ {
+ ::SetCursor(NULL);
+ }
+ else
+ {
+ // Give the NO cursor in the client area and an arrow on the title bar
+
+ POINT aULCorner = {0, 0};
+ ::ClientToScreen(mHWnd, &aULCorner);
+
+ POINT aBRCorner = {mWidth, mHeight};
+ ::ClientToScreen(mHWnd, &aBRCorner);
+
+ POINT aPoint;
+ ::GetCursorPos(&aPoint);
+
+ if ((aPoint.x >= aULCorner.x) && (aPoint.y >= aULCorner.y) &&
+ (aPoint.x < aBRCorner.x) && (aPoint.y < aBRCorner.y))
+ {
+ ::SetCursor(::LoadCursor(NULL, IDC_NO));
+ }
+ else
+ {
+ ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
+ }
+ }
+
+ wantSysCursor = false;
+ }
+ }
+
+ if (wantSysCursor != mSysCursor)
+ {
+ mSysCursor = wantSysCursor;
+
+ // Don't hide the hardware cursor when playing back a demo buffer
+// if (!mPlayingDemoBuffer)
+// ::ShowCursor(mSysCursor);
+ }
+}
+
+void SexyAppBase::ProcessSafeDeleteList()
+{
+ MTAutoDisallowRand aDisallowRand;
+
+ WidgetSafeDeleteList::iterator anItr = mSafeDeleteList.begin();
+ while (anItr != mSafeDeleteList.end())
+ {
+ WidgetSafeDeleteInfo* aWidgetSafeDeleteInfo = &(*anItr);
+ if (mUpdateAppDepth <= aWidgetSafeDeleteInfo->mUpdateAppDepth)
+ {
+ delete aWidgetSafeDeleteInfo->mWidget;
+ anItr = mSafeDeleteList.erase(anItr);
+ }
+ else
+ ++anItr;
+ }
+}
+
+void SexyAppBase::UpdateFTimeAcc()
+{
+ DWORD aCurTime = timeGetTime();
+
+ if (mLastTimeCheck != 0)
+ {
+ int aDeltaTime = aCurTime - mLastTimeCheck;
+
+ mUpdateFTimeAcc = min(mUpdateFTimeAcc + aDeltaTime, 200.0);
+
+ if (mRelaxUpdateBacklogCount > 0)
+ mRelaxUpdateBacklogCount = max(mRelaxUpdateBacklogCount - aDeltaTime, 0);
+ }
+
+ mLastTimeCheck = aCurTime;
+}
+
+//int aNumCalls = 0;
+//DWORD aLastCheck = 0;
+
+bool SexyAppBase::Process(bool allowSleep)
+{
+ /*DWORD aTimeNow = GetTickCount();
+ if (aTimeNow - aLastCheck >= 10000)
+ {
+ OutputDebugString(StrFormat(_S("FUpdates: %d\n"), aNumCalls).c_str());
+ aLastCheck = aTimeNow;
+ aNumCalls = 0;
+ }*/
+
+ if (mLoadingFailed)
+ Shutdown();
+
+ bool isVSynched = (!mPlayingDemoBuffer) && (mVSyncUpdates) && (!mLastDrawWasEmpty) && (!mVSyncBroken) &&
+ ((!mIsPhysWindowed) || (mIsPhysWindowed && mWaitForVSync && !mSoftVSyncWait));
+ double aFrameFTime;
+ double anUpdatesPerUpdateF;
+
+ if (mVSyncUpdates)
+ {
+ aFrameFTime = (1000.0 / mSyncRefreshRate) / mUpdateMultiplier;
+ anUpdatesPerUpdateF = (float) (1000.0 / (mFrameTime * mSyncRefreshRate));
+ }
+ else
+ {
+ aFrameFTime = mFrameTime / mUpdateMultiplier;
+ anUpdatesPerUpdateF = 1.0;
+ }
+
+ // Do we need to fast forward?
+ if (mPlayingDemoBuffer)
+ {
+ if (mUpdateCount < mFastForwardToUpdateNum || mFastForwardToMarker)
+ {
+ if (!mDemoMute && !mFastForwardStep)
+ {
+ mDemoMute = true;
+ Mute(true);
+ }
+
+ static DWORD aTick = GetTickCount();
+ while (mUpdateCount < mFastForwardToUpdateNum || mFastForwardToMarker)
+ {
+ ClearUpdateBacklog();
+ int aLastUpdateCount = mUpdateCount;
+
+ // Actual updating code below
+ //////////////////////////////////////////////////////////////////////////
+
+ bool hadRealUpdate = DoUpdateFrames();
+
+ if (hadRealUpdate)
+ {
+ mPendingUpdatesAcc += anUpdatesPerUpdateF;
+ mPendingUpdatesAcc -= 1.0;
+ ProcessSafeDeleteList();
+
+ // Process any extra updates
+ while (mPendingUpdatesAcc >= 1.0)
+ {
+ // These should just be IDLE commands we have to clear out
+ ProcessDemo();
+
+ bool hasRealUpdate = DoUpdateFrames();
+ DBG_ASSERTE(hasRealUpdate);
+
+ if (!hasRealUpdate)
+ break;
+
+ ProcessSafeDeleteList();
+ mPendingUpdatesAcc -= 1.0;
+ }
+
+ DoUpdateFramesF((float) anUpdatesPerUpdateF);
+ ProcessSafeDeleteList();
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+
+ // If the update count doesn't change, its because we are
+ // playing back a demo and need to read more
+ if (aLastUpdateCount == mUpdateCount)
+ return true;
+
+ DWORD aNewTick = GetTickCount();
+ if (aNewTick - aTick >= 1000 || mFastForwardStep) // let the app draw some
+ {
+ mFastForwardStep = false;
+ aTick = GetTickCount();
+ DrawDirtyStuff();
+ return true;
+ }
+ }
+ }
+
+ if (mDemoMute)
+ {
+ mDemoMute = false;
+ mSoundManager->StopAllSounds();
+ Unmute(true);
+ }
+ }
+
+ // Make sure we're not paused
+ if ((!mPaused) && (mUpdateMultiplier > 0))
+ {
+ ulong aStartTime = timeGetTime();
+
+ ulong aCurTime = aStartTime;
+ int aCumSleepTime = 0;
+
+ // When we are VSynching, only calculate this FTimeAcc right after drawing
+
+ if (!isVSynched)
+ UpdateFTimeAcc();
+
+ // mNonDrawCount is used to make sure we draw the screen at least
+ // 10 times per second, even if it means we have to slow down
+ // the updates to make it draw 10 times per second in "game time"
+
+ bool didUpdate = false;
+
+ if (mUpdateAppState == UPDATESTATE_PROCESS_1)
+ {
+ if ((++mNonDrawCount < (int) ceil(10*mUpdateMultiplier)) || (!mLoaded))
+ {
+ bool doUpdate = false;
+
+ if (isVSynched)
+ {
+ // Synch'ed to vertical refresh, so update as soon as possible after draw
+ doUpdate = (!mHasPendingDraw) || (mUpdateFTimeAcc >= (int) (aFrameFTime * 0.75));
+ }
+ else if (mUpdateFTimeAcc >= aFrameFTime)
+ {
+ doUpdate = true;
+ }
+
+ if (doUpdate)
+ {
+ // Do VSyncBroken test. This test fails if we're in fullscreen and
+ // "don't vsync" has been forced in Advanced settings up Display Properties
+ if ((!mPlayingDemoBuffer) && (mUpdateMultiplier == 1.0))
+ {
+ mVSyncBrokenTestUpdates++;
+ if (mVSyncBrokenTestUpdates >= (DWORD) ((1000+mFrameTime-1)/mFrameTime))
+ {
+ // It has to be running 33% fast to be "broken" (25% = 1/0.800)
+ if (aStartTime - mVSyncBrokenTestStartTick <= 800)
+ {
+ // The test has to fail 3 times in a row before we decide that
+ // vsync is broken overall
+ mVSyncBrokenCount++;
+ if (mVSyncBrokenCount >= 3)
+ mVSyncBroken = true;
+ }
+ else
+ mVSyncBrokenCount = 0;
+
+ mVSyncBrokenTestStartTick = aStartTime;
+ mVSyncBrokenTestUpdates = 0;
+ }
+ }
+
+ bool hadRealUpdate = DoUpdateFrames();
+ if (hadRealUpdate)
+ mUpdateAppState = UPDATESTATE_PROCESS_2;
+
+ mHasPendingDraw = true;
+ didUpdate = true;
+ }
+ }
+ }
+ else if (mUpdateAppState == UPDATESTATE_PROCESS_2)
+ {
+ mUpdateAppState = UPDATESTATE_PROCESS_DONE;
+
+ mPendingUpdatesAcc += anUpdatesPerUpdateF;
+ mPendingUpdatesAcc -= 1.0;
+ ProcessSafeDeleteList();
+
+ // Process any extra updates
+ while (mPendingUpdatesAcc >= 1.0)
+ {
+ // These should just be IDLE commands we have to clear out
+ ProcessDemo();
+
+ ++mNonDrawCount;
+ bool hasRealUpdate = DoUpdateFrames();
+ DBG_ASSERTE(hasRealUpdate);
+
+ if (!hasRealUpdate)
+ break;
+
+ ProcessSafeDeleteList();
+ mPendingUpdatesAcc -= 1.0;
+ }
+
+ //aNumCalls++;
+ DoUpdateFramesF((float) anUpdatesPerUpdateF);
+ ProcessSafeDeleteList();
+
+ // Don't let mUpdateFTimeAcc dip below 0
+ // Subtract an extra 0.2ms, because sometimes refresh rates have some
+ // fractional component that gets truncated, and it's better to take off
+ // too much to keep our timing tending toward occuring right after
+ // redraws
+ if (isVSynched)
+ mUpdateFTimeAcc = max(mUpdateFTimeAcc - aFrameFTime - 0.2f, 0.0);
+ else
+ mUpdateFTimeAcc -= aFrameFTime;
+
+ if (mRelaxUpdateBacklogCount > 0)
+ mUpdateFTimeAcc = 0;
+
+ didUpdate = true;
+ }
+
+ if (!didUpdate)
+ {
+ mUpdateAppState = UPDATESTATE_PROCESS_DONE;
+
+ mNonDrawCount = 0;
+
+ if (mHasPendingDraw)
+ {
+ DrawDirtyStuff();
+ }
+ else
+ {
+ // Let us take into account the time it took to draw dirty stuff
+ int aTimeToNextFrame = (int) (aFrameFTime - mUpdateFTimeAcc);
+ if (aTimeToNextFrame > 0)
+ {
+ if (!allowSleep)
+ return false;
+
+ // Wait till next processing cycle
+ ++mSleepCount;
+ Sleep(aTimeToNextFrame);
+
+ aCumSleepTime += aTimeToNextFrame;
+ }
+ }
+ }
+
+ if (mYieldMainThread)
+ {
+ // This is to make sure that the title screen doesn't take up any more than
+ // 1/3 of the processor time
+
+ ulong anEndTime = timeGetTime();
+ int anElapsedTime = (anEndTime - aStartTime) - aCumSleepTime;
+ int aLoadingYieldSleepTime = min(250, (anElapsedTime * 2) - aCumSleepTime);
+
+ if (aLoadingYieldSleepTime >= 0)
+ {
+ if (!allowSleep)
+ return false;
+
+ Sleep(aLoadingYieldSleepTime);
+ }
+ }
+ }
+
+ ProcessSafeDeleteList();
+ return true;
+}
+
+/*void SexyAppBase::DoMainLoop()
+{
+ Dialog* aDialog = NULL;
+ if (theModalDialogId != -1)
+ {
+ aDialog = GetDialog(theModalDialogId);
+ DBG_ASSERTE(aDialog != NULL);
+ if (aDialog == NULL)
+ return;
+ }
+
+ while (!mShutdown)
+ {
+ MSG msg;
+ while ((PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) && (!mShutdown))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ ProcessDemo();
+ ProcessDeferredMessages();
+
+ if ((aDialog != NULL) && (aDialog->mResult != -1))
+ return;
+
+ if (!mShutdown)
+ {
+ //++aCount;
+ Process();
+ }
+ }
+}*/
+
+void SexyAppBase::DoMainLoop()
+{
+ while (!mShutdown)
+ {
+ if (mExitToTop)
+ mExitToTop = false;
+ UpdateApp();
+ }
+}
+
+bool SexyAppBase::UpdateAppStep(bool* updated)
+{
+ if (updated != NULL)
+ *updated = false;
+
+ if (mExitToTop)
+ return false;
+
+ if (mUpdateAppState == UPDATESTATE_PROCESS_DONE)
+ mUpdateAppState = UPDATESTATE_MESSAGES;
+
+ mUpdateAppDepth++;
+
+ // We update in two stages to avoid doing a Process if our loop termination
+ // condition has already been met by processing windows messages
+ if (mUpdateAppState == UPDATESTATE_MESSAGES)
+ {
+ MSG msg;
+ while ((PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) && (!mShutdown))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ ProcessDemo();
+ if (!ProcessDeferredMessages(true))
+ {
+ mUpdateAppState = UPDATESTATE_PROCESS_1;
+ }
+ }
+ else
+ {
+ // Process changes state by itself
+ if (mStepMode)
+ {
+ if (mStepMode==2)
+ {
+ Sleep(mFrameTime);
+ mUpdateAppState = UPDATESTATE_PROCESS_DONE; // skip actual update until next step
+ }
+ else
+ {
+ mStepMode = 2;
+ DoUpdateFrames();
+ DoUpdateFramesF(1.0f);
+ DrawDirtyStuff();
+ }
+ }
+ else
+ {
+ int anOldUpdateCnt = mUpdateCount;
+ Process();
+ if (updated != NULL)
+ *updated = mUpdateCount != anOldUpdateCnt;
+ }
+ }
+
+ mUpdateAppDepth--;
+
+ return true;
+}
+
+bool SexyAppBase::UpdateApp()
+{
+ bool updated;
+ for (;;)
+ {
+ if (!UpdateAppStep(&updated))
+ return false;
+ if (updated)
+ return true;
+ }
+}
+
+int SexyAppBase::InitDDInterface()
+{
+ PreDDInterfaceInitHook();
+ DeleteNativeImageData();
+ int aResult = mDDInterface->Init(mHWnd, mIsPhysWindowed);
+ DemoSyncRefreshRate();
+ if ( DDInterface::RESULT_OK == aResult )
+ {
+ mScreenBounds.mX = ( mWidth - mDDInterface->mWidth ) / 2;
+ mScreenBounds.mY = ( mHeight - mDDInterface->mHeight ) / 2;
+ mScreenBounds.mWidth = mDDInterface->mWidth;
+ mScreenBounds.mHeight = mDDInterface->mHeight;
+ mWidgetManager->Resize(mScreenBounds, mDDInterface->mPresentationRect);
+ PostDDInterfaceInitHook();
+ }
+ return aResult;
+}
+
+void SexyAppBase::PreTerminate()
+{
+}
+
+void SexyAppBase::Start()
+{
+ if (mShutdown)
+ return;
+
+ StartCursorThread();
+
+ if (mAutoStartLoadingThread)
+ StartLoadingThread();
+
+ ::ShowWindow(mHWnd, SW_SHOW);
+ ::SetFocus(mHWnd);
+
+ timeBeginPeriod(1);
+
+ int aCount = 0;
+ int aSleepCount = 0;
+
+ DWORD aStartTime = timeGetTime();
+
+ mRunning = true;
+ mLastTime = aStartTime;
+ mLastUserInputTick = aStartTime;
+ mLastTimerTime = aStartTime;
+
+ DoMainLoop();
+ ProcessSafeDeleteList();
+
+ mRunning = false;
+
+ WaitForLoadingThread();
+
+ char aString[256];
+ sprintf(aString, "Seconds = %g\r\n", (timeGetTime() - aStartTime) / 1000.0);
+ OutputDebugStringA(aString);
+ //sprintf(aString, "Count = %d\r\n", aCount);
+ //OutputDebugString(aString);
+ sprintf(aString, "Sleep Count = %d\r\n", mSleepCount);
+ OutputDebugStringA(aString);
+ sprintf(aString, "Update Count = %d\r\n", mUpdateCount);
+ OutputDebugStringA(aString);
+ sprintf(aString, "Draw Count = %d\r\n", mDrawCount);
+ OutputDebugStringA(aString);
+ sprintf(aString, "Draw Time = %d\r\n", mDrawTime);
+ OutputDebugStringA(aString);
+ sprintf(aString, "Screen Blt = %d\r\n", mScreenBltTime);
+ OutputDebugStringA(aString);
+ if (mDrawTime+mScreenBltTime > 0)
+ {
+ sprintf(aString, "Avg FPS = %d\r\n", (mDrawCount*1000)/(mDrawTime+mScreenBltTime));
+ OutputDebugStringA(aString);
+ }
+
+ timeEndPeriod(1);
+
+ PreTerminate();
+
+ WriteToRegistry();
+}
+
+bool SexyAppBase::CheckSignature(const Buffer& theBuffer, const std::string& theFileName)
+{
+ // Add your own signature checking code here
+ return false;
+}
+
+bool SexyAppBase::LoadProperties(const std::string& theFileName, bool required, bool checkSig)
+{
+ Buffer aBuffer;
+ if (!ReadBufferFromFile(theFileName, &aBuffer))
+ {
+ if (!required)
+ return true;
+ else
+ {
+ Popup(GetString("UNABLE_OPEN_PROPERTIES", _S("Unable to open properties file ")) + StringToSexyString(theFileName));
+ return false;
+ }
+ }
+ if (checkSig)
+ {
+ if (!CheckSignature(aBuffer, theFileName))
+ {
+ Popup(GetString("PROPERTIES_SIG_FAILED", _S("Signature check failed on ")) + StringToSexyString(theFileName + "'"));
+ return false;
+ }
+ }
+
+ PropertiesParser aPropertiesParser(this);
+
+ // Load required language-file properties
+ if (!aPropertiesParser.ParsePropertiesBuffer(aBuffer))
+ {
+ Popup(aPropertiesParser.GetErrorText());
+ return false;
+ }
+ else
+ return true;
+}
+
+bool SexyAppBase::LoadProperties()
+{
+ // Load required language-file properties
+ return LoadProperties("properties\\default.xml", true, false);
+}
+
+void SexyAppBase::LoadResourceManifest()
+{
+ if (!mResourceManager->ParseResourcesFile("properties\\resources.xml"))
+ ShowResourceError(true);
+}
+
+void SexyAppBase::ShowResourceError(bool doExit)
+{
+ Popup(mResourceManager->GetErrorText());
+ if (doExit)
+ DoExit(0);
+}
+
+bool SexyAppBase::GetBoolean(const std::string& theId)
+{
+ StringBoolMap::iterator anItr = mBoolProperties.find(theId);
+ DBG_ASSERTE(anItr != mBoolProperties.end());
+
+ if (anItr != mBoolProperties.end())
+ return anItr->second;
+ else
+ return false;
+}
+
+bool SexyAppBase::GetBoolean(const std::string& theId, bool theDefault)
+{
+ StringBoolMap::iterator anItr = mBoolProperties.find(theId);
+
+ if (anItr != mBoolProperties.end())
+ return anItr->second;
+ else
+ return theDefault;
+}
+
+int SexyAppBase::GetInteger(const std::string& theId)
+{
+ StringIntMap::iterator anItr = mIntProperties.find(theId);
+ DBG_ASSERTE(anItr != mIntProperties.end());
+
+ if (anItr != mIntProperties.end())
+ return anItr->second;
+ else
+ return false;
+}
+
+int SexyAppBase::GetInteger(const std::string& theId, int theDefault)
+{
+ StringIntMap::iterator anItr = mIntProperties.find(theId);
+
+ if (anItr != mIntProperties.end())
+ return anItr->second;
+ else
+ return theDefault;
+}
+
+double SexyAppBase::GetDouble(const std::string& theId)
+{
+ StringDoubleMap::iterator anItr = mDoubleProperties.find(theId);
+ DBG_ASSERTE(anItr != mDoubleProperties.end());
+
+ if (anItr != mDoubleProperties.end())
+ return anItr->second;
+ else
+ return false;
+}
+
+double SexyAppBase::GetDouble(const std::string& theId, double theDefault)
+{
+ StringDoubleMap::iterator anItr = mDoubleProperties.find(theId);
+
+ if (anItr != mDoubleProperties.end())
+ return anItr->second;
+ else
+ return theDefault;
+}
+
+SexyString SexyAppBase::GetString(const std::string& theId)
+{
+ StringWStringMap::iterator anItr = mStringProperties.find(theId);
+ DBG_ASSERTE(anItr != mStringProperties.end());
+
+ if (anItr != mStringProperties.end())
+ return WStringToSexyString(anItr->second);
+ else
+ return _S("");
+}
+
+SexyString SexyAppBase::GetString(const std::string& theId, const SexyString& theDefault)
+{
+ StringWStringMap::iterator anItr = mStringProperties.find(theId);
+
+ if (anItr != mStringProperties.end())
+ return WStringToSexyString(anItr->second);
+ else
+ return theDefault;
+}
+
+StringVector SexyAppBase::GetStringVector(const std::string& theId)
+{
+ StringStringVectorMap::iterator anItr = mStringVectorProperties.find(theId);
+ DBG_ASSERTE(anItr != mStringVectorProperties.end());
+
+ if (anItr != mStringVectorProperties.end())
+ return anItr->second;
+ else
+ return StringVector();
+}
+
+void SexyAppBase::SetString(const std::string& theId, const std::wstring& theValue)
+{
+ std::pair<StringWStringMap::iterator, bool> aPair = mStringProperties.insert(StringWStringMap::value_type(theId, theValue));
+ if (!aPair.second) // Found it, change value
+ aPair.first->second = theValue;
+}
+
+
+void SexyAppBase::SetBoolean(const std::string& theId, bool theValue)
+{
+ std::pair<StringBoolMap::iterator, bool> aPair = mBoolProperties.insert(StringBoolMap::value_type(theId, theValue));
+ if (!aPair.second) // Found it, change value
+ aPair.first->second = theValue;
+}
+
+void SexyAppBase::SetInteger(const std::string& theId, int theValue)
+{
+ std::pair<StringIntMap::iterator, bool> aPair = mIntProperties.insert(StringIntMap::value_type(theId, theValue));
+ if (!aPair.second) // Found it, change value
+ aPair.first->second = theValue;
+}
+
+void SexyAppBase::SetDouble(const std::string& theId, double theValue)
+{
+ std::pair<StringDoubleMap::iterator, bool> aPair = mDoubleProperties.insert(StringDoubleMap::value_type(theId, theValue));
+ if (!aPair.second) // Found it, change value
+ aPair.first->second = theValue;
+}
+
+void SexyAppBase::DoParseCmdLine()
+{
+ char* aCmdLine = GetCommandLineA();
+ char* aCmdLinePtr = aCmdLine;
+ if (aCmdLinePtr[0] == '"')
+ {
+ aCmdLinePtr = strchr(aCmdLinePtr + 1, '"');
+ if (aCmdLinePtr != NULL)
+ aCmdLinePtr++;
+ }
+
+ if (aCmdLinePtr != NULL)
+ {
+ aCmdLinePtr = strchr(aCmdLinePtr, ' ');
+ if (aCmdLinePtr != NULL)
+ ParseCmdLine(aCmdLinePtr+1);
+ }
+
+ mCmdLineParsed = true;
+}
+
+void SexyAppBase::ParseCmdLine(const std::string& theCmdLine)
+{
+ // Command line example: -play -demofile="game demo.dmo"
+ // Results in HandleCmdLineParam("-play", ""); HandleCmdLineParam("-demofile", "game demo.dmo");
+ std::string aCurParamName;
+ std::string aCurParamValue;
+
+ int aSpacePos = 0;
+ bool inQuote = false;
+ bool onValue = false;
+
+ for (int i = 0; i < (int) theCmdLine.length(); i++)
+ {
+ char c = theCmdLine[i];
+ bool atEnd = false;
+
+ if (c == '"')
+ {
+ inQuote = !inQuote;
+
+ if (!inQuote)
+ atEnd = true;
+ }
+ else if ((c == ' ') && (!inQuote))
+ atEnd = true;
+ else if (c == '=')
+ onValue = true;
+ else if (onValue)
+ aCurParamValue += c;
+ else
+ aCurParamName += c;
+
+ if (i == theCmdLine.length() - 1)
+ atEnd = true;
+
+ if (atEnd && !aCurParamName.empty())
+ {
+ HandleCmdLineParam(aCurParamName, aCurParamValue);
+ aCurParamName = "";
+ aCurParamValue = "";
+ onValue = false;
+ }
+ }
+}
+
+static int GetMaxDemoFileNum(const std::string& theDemoPrefix, int theMaxToKeep, bool doErase)
+{
+ WIN32_FIND_DATAA aData;
+ HANDLE aHandle = FindFirstFileA((theDemoPrefix + "*.dmo").c_str(), &aData);
+ if (aHandle==INVALID_HANDLE_VALUE)
+ return 0;
+
+ typedef std::set<int> IntSet;
+ IntSet aSet;
+
+ do {
+ int aNum = 0;
+ if (sscanf(aData.cFileName,(theDemoPrefix + "%d.dmo").c_str(), &aNum)==1)
+ aSet.insert(aNum);
+
+ } while(FindNextFileA(aHandle,&aData));
+ FindClose(aHandle);
+
+ IntSet::iterator anItr = aSet.begin();
+ if ((int)aSet.size()>theMaxToKeep-1 && doErase)
+ DeleteFile(StrFormat((theDemoPrefix + "%d.dmo").c_str(),*anItr).c_str());
+
+ if (aSet.empty())
+ return 0;
+
+ anItr = aSet.end();
+ --anItr;
+ return (*anItr);
+}
+
+void SexyAppBase::HandleCmdLineParam(const std::string& theParamName, const std::string& theParamValue)
+{
+ if (theParamName == "-play")
+ {
+ mPlayingDemoBuffer = true;
+ mRecordingDemoBuffer = false;
+ }
+ else if (theParamName == "-recnum")
+ {
+ int aNum = atoi(theParamValue.c_str());
+ if (aNum<=0)
+ aNum=5;
+
+ int aDemoFileNum = GetMaxDemoFileNum(mDemoPrefix, aNum, true) + 1;
+ mDemoFileName = SexyStringToString(StrFormat(StringToSexyString(mDemoPrefix + "%d.dmo").c_str(),aDemoFileNum));
+ if (mDemoFileName.length() < 2 || (mDemoFileName[1] != ':' && mDemoFileName[2] != '\\'))
+ {
+ mDemoFileName = GetAppDataFolder() + mDemoFileName;
+ }
+ mRecordingDemoBuffer = true;
+ mPlayingDemoBuffer = false;
+ }
+ else if (theParamName == "-playnum")
+ {
+ int aNum = atoi(theParamValue.c_str())-1;
+ if (aNum<0)
+ aNum=0;
+
+ int aDemoFileNum = GetMaxDemoFileNum(mDemoPrefix, aNum, false)-aNum;
+ mDemoFileName = SexyStringToString(StrFormat(StringToSexyString(mDemoPrefix + "%d.dmo").c_str(),aDemoFileNum));
+ mRecordingDemoBuffer = false;
+ mPlayingDemoBuffer = true;
+ }
+ else if (theParamName == "-record")
+ {
+ mRecordingDemoBuffer = true;
+ mPlayingDemoBuffer = false;
+ }
+ else if (theParamName == "-demofile")
+ {
+ mDemoFileName = theParamValue;
+ if (mDemoFileName.length() < 2 || (mDemoFileName[1] != ':' && mDemoFileName[2] != '\\'))
+ {
+ mDemoFileName = GetAppDataFolder() + mDemoFileName;
+ }
+ }
+ else if (theParamName == "-crash")
+ {
+ // Try to access NULL
+ char* a = 0;
+ *a = '!';
+ }
+ else if (theParamName == "-screensaver")
+ {
+ mIsScreenSaver = true;
+ }
+ else if (theParamName == "-changedir")
+ {
+ mChangeDirTo = theParamValue;
+ }
+ else
+ {
+ Popup(GetString("INVALID_COMMANDLINE_PARAM", _S("Invalid command line parameter: ")) + StringToSexyString(theParamName));
+ DoExit(0);
+ }
+}
+
+void SexyAppBase::PreDisplayHook()
+{
+}
+
+void SexyAppBase::PreDDInterfaceInitHook()
+{
+}
+
+void SexyAppBase::PostDDInterfaceInitHook()
+{
+}
+
+bool SexyAppBase::ChangeDirHook(const char *theIntendedPath)
+{
+ return false;
+}
+
+MusicInterface* SexyAppBase::CreateMusicInterface(HWND theWindow)
+{
+ if (mNoSoundNeeded)
+ return new MusicInterface;
+ else if (mWantFMod)
+ return new FModMusicInterface(mInvisHWnd);
+ else
+ return new BassMusicInterface(mInvisHWnd);
+}
+
+void SexyAppBase::InitPropertiesHook()
+{
+}
+
+void SexyAppBase::InitHook()
+{
+}
+
+void SexyAppBase::Init()
+{
+ mPrimaryThreadId = GetCurrentThreadId();
+
+ if (mShutdown)
+ return;
+
+ if (gDDrawDLL==NULL || gDSoundDLL==NULL)
+ {
+ MessageBox(NULL,
+ GetString("APP_REQUIRES_DIRECTX", _S("This application requires DirectX to run. You can get DirectX at http://www.microsoft.com/directx")).c_str(),
+ GetString("YOU_NEED_DIRECTX", _S("You need DirectX")).c_str(),
+ MB_OK | MB_ICONERROR);
+ DoExit(0);
+ }
+
+ InitPropertiesHook();
+ ReadFromRegistry();
+
+ if (CheckForVista())
+ {
+ HMODULE aMod;
+ SHGetFolderPathFunc aFunc = (SHGetFolderPathFunc)GetSHGetFolderPath("shell32.dll", &aMod);
+ if (aFunc == NULL || aMod == NULL)
+ SHGetFolderPathFunc aFunc = (SHGetFolderPathFunc)GetSHGetFolderPath("shfolder.dll", &aMod);
+
+ if (aMod != NULL)
+ {
+ char aPath[MAX_PATH];
+ aFunc(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, aPath);
+
+ std::string aDataPath = RemoveTrailingSlash(aPath) + "\\" + mFullCompanyName + "\\" + mProdName;
+ SetAppDataFolder(aDataPath + "\\");
+ //MkDir(aDataPath);
+ //AllowAllAccess(aDataPath);
+ if (mDemoFileName.length() < 2 || (mDemoFileName[1] != ':' && mDemoFileName[2] != '\\'))
+ {
+ mDemoFileName = GetAppDataFolder() + mDemoFileName;
+ }
+
+ FreeLibrary(aMod);
+ }
+ }
+
+ if (!mCmdLineParsed)
+ DoParseCmdLine();
+
+ if (IsScreenSaver())
+ mOnlyAllowOneCopyToRun = false;
+
+
+ if(gHInstance==NULL)
+ gHInstance = (HINSTANCE)GetModuleHandle(NULL);
+
+ // Change directory
+ if (!ChangeDirHook(mChangeDirTo.c_str()))
+ chdir(mChangeDirTo.c_str());
+
+ gPakInterface->AddPakFile("main.pak");
+
+ // Create a message we can use to talk to ourselves inter-process
+ mNotifyGameMessage = RegisterWindowMessage((_S("Notify") + StringToSexyString(mProdName)).c_str());
+
+ // Create a globally unique mutex
+ mMutex = CreateMutex(NULL, TRUE, (StringToSexyString(mProdName) + _S("Mutex")).c_str());
+ if (::GetLastError() == ERROR_ALREADY_EXISTS)
+ HandleGameAlreadyRunning();
+
+ mRandSeed = GetTickCount();
+ SRand(mRandSeed);
+
+ // Set up demo recording stuff
+ if (mPlayingDemoBuffer)
+ {
+ std::string anError;
+ if (!ReadDemoBuffer(anError))
+ {
+ mPlayingDemoBuffer = false;
+ Popup(anError);
+ DoExit(0);
+ }
+ }
+
+
+ srand(GetTickCount());
+
+ if (CheckFor98Mill())
+ {
+ mIsWideWindow = false;
+
+ WNDCLASSA wc;
+ wc.style = CS_DBLCLKS;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = NULL;
+ wc.hCursor = NULL;
+ wc.hIcon = ::LoadIconA(gHInstance, "IDI_MAIN_ICON");
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = WindowProc;
+ wc.lpszClassName = "MainWindow";
+ wc.lpszMenuName = NULL;
+ bool success = RegisterClassA(&wc) != 0;
+ DBG_ASSERTE(success);
+
+ wc.style = 0;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = NULL;
+ wc.hCursor = NULL;
+ wc.hIcon = NULL;
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = WindowProc;
+ wc.lpszClassName = "InvisWindow";
+ wc.lpszMenuName = NULL;
+ success = RegisterClassA(&wc) != 0;
+ DBG_ASSERTE(success);
+
+ mInvisHWnd = CreateWindowExA(
+ 0,
+ "InvisWindow",
+ SexyStringToStringFast(mTitle).c_str(),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ SetWindowLong(mInvisHWnd, GWL_USERDATA, (LONG) this);
+ }
+ else
+ {
+ mIsWideWindow = sizeof(SexyChar) == sizeof(wchar_t);
+
+ WNDCLASS wc;
+ wc.style = CS_DBLCLKS;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = NULL;
+ wc.hCursor = NULL;
+ wc.hIcon = ::LoadIconA(gHInstance, "IDI_MAIN_ICON");
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = WindowProc;
+ wc.lpszClassName = _S("MainWindow");
+ wc.lpszMenuName = NULL;
+ bool success = RegisterClass(&wc) != 0;
+ DBG_ASSERTE(success);
+
+ wc.style = 0;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hbrBackground = NULL;
+ wc.hCursor = NULL;
+ wc.hIcon = NULL;
+ wc.hInstance = gHInstance;
+ wc.lpfnWndProc = WindowProc;
+ wc.lpszClassName = _S("InvisWindow");
+ wc.lpszMenuName = NULL;
+ success = RegisterClass(&wc) != 0;
+ DBG_ASSERTE(success);
+
+ mInvisHWnd = CreateWindowEx(
+ 0,
+ _S("InvisWindow"),
+ mTitle.c_str(),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ gHInstance,
+ 0);
+ SetWindowLong(mInvisHWnd, GWL_USERDATA, (LONG) this);
+ }
+
+ mHandCursor = CreateCursor(gHInstance, 11, 4, 32, 32, gFingerCursorData, gFingerCursorData+sizeof(gFingerCursorData)/2);
+ mDraggingCursor = CreateCursor(gHInstance, 15, 10, 32, 32, gDraggingCursorData, gDraggingCursorData+sizeof(gDraggingCursorData)/2);
+
+ // Let app do something before showing window, or switching to fullscreen mode
+ // NOTE: Moved call to PreDisplayHook above mIsWindowed and GetSystemsMetrics
+ // checks because the checks below use values that could change in PreDisplayHook.
+ // PreDisplayHook must call mWidgetManager->Resize if it changes mWidth or mHeight.
+ PreDisplayHook();
+
+ mWidgetManager->Resize(Rect(0, 0, mWidth, mHeight), Rect(0, 0, mWidth, mHeight));
+
+ // Check to see if we CAN run windowed or not...
+ if (mIsWindowed && !mFullScreenWindow)
+ {
+ // How can we be windowed if our screen isn't even big enough?
+ if ((mWidth >= GetSystemMetrics(SM_CXFULLSCREEN)) ||
+ (mHeight >= GetSystemMetrics(SM_CYFULLSCREEN)))
+ {
+ mIsWindowed = false;
+ mForceFullscreen = true;
+ }
+ }
+
+ if (mFullScreenWindow) // change resoultion using ChangeDisplaySettings
+ {
+ EnumWindows(ChangeDisplayWindowEnumProc,0); // record window pos
+ DEVMODE dm;
+ EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm );
+
+ // Switch resolutions
+ if (dm.dmPelsWidth!=mWidth || dm.dmPelsHeight!=mHeight || (dm.dmBitsPerPel!=16 && dm.dmBitsPerPel!=32))
+ {
+ dm.dmPelsWidth = mWidth;
+ dm.dmPelsHeight = mHeight;
+ dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
+
+ if (dm.dmBitsPerPel!=16 && dm.dmBitsPerPel!=32) // handle 24-bit/256 color case
+ {
+ dm.dmBitsPerPel = 16;
+ dm.dmFields |= DM_BITSPERPEL;
+ }
+
+ if (ChangeDisplaySettings(&dm,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
+ {
+ mFullScreenWindow = false;
+ mIsWindowed = false;
+ }
+ }
+ }
+
+ MakeWindow();
+
+ if (mPlayingDemoBuffer)
+ {
+ // Get video data
+
+ PrepareDemoCommand(true);
+ mDemoNeedsCommand = true;
+
+ DBG_ASSERTE(!mDemoIsShortCmd);
+ DBG_ASSERTE(mDemoCmdNum == DEMO_VIDEO_DATA);
+
+ mIsWindowed = mDemoBuffer.ReadBoolean();
+ mSyncRefreshRate = mDemoBuffer.ReadByte();
+ }
+
+ if (mSoundManager == NULL)
+ mSoundManager = new DSoundManager(mNoSoundNeeded?NULL:mHWnd, mWantFMod);
+
+ SetSfxVolume(mSfxVolume);
+
+ mMusicInterface = CreateMusicInterface(mInvisHWnd);
+
+ SetMusicVolume(mMusicVolume);
+
+ if (IsScreenSaver())
+ {
+ SetCursor(CURSOR_NONE);
+ }
+
+ InitHook();
+
+ mInitialized = true;
+}
+
+void SexyAppBase::HandleGameAlreadyRunning()
+{
+ if(mOnlyAllowOneCopyToRun)
+ {
+ // Notify the other window and then shut ourselves down
+ if (mNotifyGameMessage != 0)
+ PostMessage(HWND_BROADCAST, mNotifyGameMessage, 0, 0);
+
+ DoExit(0);
+ }
+}
+
+void SexyAppBase::CopyToClipboard(const std::string& theString)
+{
+ if (mPlayingDemoBuffer)
+ return;
+
+ HGLOBAL aGlobalHandle;
+ char* theData;
+ WCHAR* theWData;
+
+ if (OpenClipboard(mHWnd))
+ {
+ EmptyClipboard();
+
+ aGlobalHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, theString.length()+1);
+ theData = (char*) GlobalLock(aGlobalHandle);
+ strcpy(theData, theString.c_str());
+ GlobalUnlock(aGlobalHandle);
+ SetClipboardData(CF_TEXT, aGlobalHandle);
+ SetClipboardData(CF_OEMTEXT, aGlobalHandle);
+ SetClipboardData(CF_LOCALE, aGlobalHandle);
+
+ int aSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, theString.c_str(), theString.length(), NULL, 0);
+ aGlobalHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (aSize + 1) * sizeof(WCHAR));
+ theWData = (WCHAR*) GlobalLock(aGlobalHandle);
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, theString.c_str(), theString.length(), theWData, aSize);
+ theWData[aSize] = '\0';
+ GlobalUnlock(aGlobalHandle);
+ SetClipboardData(CF_UNICODETEXT, aGlobalHandle);
+
+ CloseClipboard();
+ }
+}
+
+std::string SexyAppBase::GetClipboard()
+{
+ HGLOBAL aGlobalHandle;
+ std::string aString;
+
+ if (!mPlayingDemoBuffer)
+ {
+ if (OpenClipboard(mHWnd))
+ {
+ aGlobalHandle = GetClipboardData(CF_TEXT);
+ if (aGlobalHandle != NULL)
+ {
+ char* theData = (char*) GlobalLock(aGlobalHandle);
+ if (theData != NULL)
+ {
+ aString = theData;
+ GlobalUnlock(aGlobalHandle);
+ }
+ }
+
+ CloseClipboard();
+ }
+ }
+
+ DemoSyncString(&aString);
+
+ return aString;
+}
+
+void SexyAppBase::SetCursor(int theCursorNum)
+{
+ mCursorNum = theCursorNum;
+ EnforceCursor();
+}
+
+int SexyAppBase::GetCursor()
+{
+ return mCursorNum;
+}
+
+void SexyAppBase::EnableCustomCursors(bool enabled)
+{
+ mCustomCursorsEnabled = enabled;
+ EnforceCursor();
+}
+
+Sexy::DDImage* SexyAppBase::GetImage(const std::string& theFileName, bool commitBits)
+{
+ ImageLib::Image* aLoadedImage = ImageLib::GetImage(theFileName, true);
+
+ if (aLoadedImage == NULL)
+ return NULL;
+
+ DDImage* anImage = new DDImage(mDDInterface);
+ anImage->mFilePath = theFileName;
+ anImage->SetBits(aLoadedImage->GetBits(), aLoadedImage->GetWidth(), aLoadedImage->GetHeight(), commitBits);
+ anImage->mFilePath = theFileName;
+ delete aLoadedImage;
+
+ return anImage;
+}
+
+Sexy::DDImage* SexyAppBase::CreateCrossfadeImage(Sexy::Image* theImage1, const Rect& theRect1, Sexy::Image* theImage2, const Rect& theRect2, double theFadeFactor)
+{
+ MemoryImage* aMemoryImage1 = dynamic_cast<MemoryImage*>(theImage1);
+ MemoryImage* aMemoryImage2 = dynamic_cast<MemoryImage*>(theImage2);
+
+ if ((aMemoryImage1 == NULL) || (aMemoryImage2 == NULL))
+ return NULL;
+
+ if ((theRect1.mX < 0) || (theRect1.mY < 0) ||
+ (theRect1.mX + theRect1.mWidth > theImage1->GetWidth()) ||
+ (theRect1.mY + theRect1.mHeight > theImage1->GetHeight()))
+ {
+ DBG_ASSERTE("Crossfade Rect1 out of bounds");
+ return NULL;
+ }
+
+ if ((theRect2.mX < 0) || (theRect2.mY < 0) ||
+ (theRect2.mX + theRect2.mWidth > theImage2->GetWidth()) ||
+ (theRect2.mY + theRect2.mHeight > theImage2->GetHeight()))
+ {
+ DBG_ASSERTE("Crossfade Rect2 out of bounds");
+ return NULL;
+ }
+
+ int aWidth = theRect1.mWidth;
+ int aHeight = theRect1.mHeight;
+
+ DDImage* anImage = new DDImage(mDDInterface);
+ anImage->Create(aWidth, aHeight);
+
+ ulong* aDestBits = anImage->GetBits();
+ ulong* aSrcBits1 = aMemoryImage1->GetBits();
+ ulong* aSrcBits2 = aMemoryImage2->GetBits();
+
+ int aSrc1Width = aMemoryImage1->GetWidth();
+ int aSrc2Width = aMemoryImage2->GetWidth();
+ ulong aMult = (int) (theFadeFactor*256);
+ ulong aOMM = (256 - aMult);
+
+ for (int y = 0; y < aHeight; y++)
+ {
+ ulong* s1 = &aSrcBits1[(y+theRect1.mY)*aSrc1Width+theRect1.mX];
+ ulong* s2 = &aSrcBits2[(y+theRect2.mY)*aSrc2Width+theRect2.mX];
+ ulong* d = &aDestBits[y*aWidth];
+
+ for (int x = 0; x < aWidth; x++)
+ {
+ ulong p1 = *s1++;
+ ulong p2 = *s2++;
+
+ //p1 = 0;
+ //p2 = 0xFFFFFFFF;
+
+ *d++ =
+ ((((p1 & 0x000000FF)*aOMM + (p2 & 0x000000FF)*aMult)>>8) & 0x000000FF) |
+ ((((p1 & 0x0000FF00)*aOMM + (p2 & 0x0000FF00)*aMult)>>8) & 0x0000FF00) |
+ ((((p1 & 0x00FF0000)*aOMM + (p2 & 0x00FF0000)*aMult)>>8) & 0x00FF0000) |
+ ((((p1 >> 24)*aOMM + (p2 >> 24)*aMult)<<16) & 0xFF000000);
+ }
+ }
+
+ anImage->BitsChanged();
+
+ return anImage;
+}
+
+void SexyAppBase::ColorizeImage(Image* theImage, const Color& theColor)
+{
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ if (aSrcMemoryImage == NULL)
+ return;
+
+ ulong* aBits;
+ int aNumColors;
+
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ aBits = aSrcMemoryImage->GetBits();
+ aNumColors = theImage->GetWidth()*theImage->GetHeight();
+ }
+ else
+ {
+ aBits = aSrcMemoryImage->mColorTable;
+ aNumColors = 256;
+ }
+
+ if ((theColor.mAlpha <= 255) && (theColor.mRed <= 255) &&
+ (theColor.mGreen <= 255) && (theColor.mBlue <= 255))
+ {
+ for (int i = 0; i < aNumColors; i++)
+ {
+ ulong aColor = aBits[i];
+
+ aBits[i] =
+ ((((aColor & 0xFF000000) >> 8) * theColor.mAlpha) & 0xFF000000) |
+ ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) |
+ ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00)|
+ ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < aNumColors; i++)
+ {
+ ulong aColor = aBits[i];
+
+ int aAlpha = ((aColor >> 24) * theColor.mAlpha) / 255;
+ int aRed = (((aColor >> 16) & 0xFF) * theColor.mRed) / 255;
+ int aGreen = (((aColor >> 8) & 0xFF) * theColor.mGreen) / 255;
+ int aBlue = ((aColor & 0xFF) * theColor.mBlue) / 255;
+
+ if (aAlpha > 255)
+ aAlpha = 255;
+ if (aRed > 255)
+ aRed = 255;
+ if (aGreen > 255)
+ aGreen = 255;
+ if (aBlue > 255)
+ aBlue = 255;
+
+ aBits[i] = (aAlpha << 24) | (aRed << 16) | (aGreen << 8) | (aBlue);
+ }
+ }
+
+ aSrcMemoryImage->BitsChanged();
+}
+
+DDImage* SexyAppBase::CreateColorizedImage(Image* theImage, const Color& theColor)
+{
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ if (aSrcMemoryImage == NULL)
+ return NULL;
+
+ DDImage* anImage = new DDImage(mDDInterface);
+
+ anImage->Create(theImage->GetWidth(), theImage->GetHeight());
+
+ ulong* aSrcBits;
+ ulong* aDestBits;
+ int aNumColors;
+
+ if (aSrcMemoryImage->mColorTable == NULL)
+ {
+ aSrcBits = aSrcMemoryImage->GetBits();
+ aDestBits = anImage->GetBits();
+ aNumColors = theImage->GetWidth()*theImage->GetHeight();
+ }
+ else
+ {
+ aSrcBits = aSrcMemoryImage->mColorTable;
+ aDestBits = anImage->mColorTable = new ulong[256];
+ aNumColors = 256;
+
+ anImage->mColorIndices = new uchar[anImage->mWidth*theImage->mHeight];
+ memcpy(anImage->mColorIndices, aSrcMemoryImage->mColorIndices, anImage->mWidth*theImage->mHeight);
+ }
+
+ if ((theColor.mAlpha <= 255) && (theColor.mRed <= 255) &&
+ (theColor.mGreen <= 255) && (theColor.mBlue <= 255))
+ {
+ for (int i = 0; i < aNumColors; i++)
+ {
+ ulong aColor = aSrcBits[i];
+
+ aDestBits[i] =
+ ((((aColor & 0xFF000000) >> 8) * theColor.mAlpha) & 0xFF000000) |
+ ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) |
+ ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00)|
+ ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < aNumColors; i++)
+ {
+ ulong aColor = aSrcBits[i];
+
+ int aAlpha = ((aColor >> 24) * theColor.mAlpha) / 255;
+ int aRed = (((aColor >> 16) & 0xFF) * theColor.mRed) / 255;
+ int aGreen = (((aColor >> 8) & 0xFF) * theColor.mGreen) / 255;
+ int aBlue = ((aColor & 0xFF) * theColor.mBlue) / 255;
+
+ if (aAlpha > 255)
+ aAlpha = 255;
+ if (aRed > 255)
+ aRed = 255;
+ if (aGreen > 255)
+ aGreen = 255;
+ if (aBlue > 255)
+ aBlue = 255;
+
+ aDestBits[i] = (aAlpha << 24) | (aRed << 16) | (aGreen << 8) | (aBlue);
+ }
+ }
+
+ anImage->BitsChanged();
+
+ return anImage;
+}
+
+DDImage* SexyAppBase::CopyImage(Image* theImage, const Rect& theRect)
+{
+ DDImage* anImage = new DDImage(mDDInterface);
+
+ anImage->Create(theRect.mWidth, theRect.mHeight);
+
+ Graphics g(anImage);
+ g.DrawImage(theImage, -theRect.mX, -theRect.mY);
+
+ anImage->CopyAttributes(theImage);
+
+ return anImage;
+}
+
+DDImage* SexyAppBase::CopyImage(Image* theImage)
+{
+ return CopyImage(theImage, Rect(0, 0, theImage->GetWidth(), theImage->GetHeight()));
+}
+
+void SexyAppBase::MirrorImage(Image* theImage)
+{
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ ulong* aSrcBits = aSrcMemoryImage->GetBits();
+
+ int aPhysSrcWidth = aSrcMemoryImage->mWidth;
+ for (int y = 0; y < aSrcMemoryImage->mHeight; y++)
+ {
+ ulong* aLeftBits = aSrcBits + (y * aPhysSrcWidth);
+ ulong* aRightBits = aLeftBits + (aPhysSrcWidth - 1);
+
+ for (int x = 0; x < (aPhysSrcWidth >> 1); x++)
+ {
+ ulong aSwap = *aLeftBits;
+
+ *(aLeftBits++) = *aRightBits;
+ *(aRightBits--) = aSwap;
+ }
+ }
+
+ aSrcMemoryImage->BitsChanged();
+}
+
+void SexyAppBase::FlipImage(Image* theImage)
+{
+ MemoryImage* aSrcMemoryImage = dynamic_cast<MemoryImage*>(theImage);
+
+ ulong* aSrcBits = aSrcMemoryImage->GetBits();
+
+ int aPhysSrcHeight = aSrcMemoryImage->mHeight;
+ int aPhysSrcWidth = aSrcMemoryImage->mWidth;
+ for (int x = 0; x < aPhysSrcWidth; x++)
+ {
+ ulong* aTopBits = aSrcBits + x;
+ ulong* aBottomBits = aTopBits + (aPhysSrcWidth * (aPhysSrcHeight - 1));
+
+ for (int y = 0; y < (aPhysSrcHeight >> 1); y++)
+ {
+ ulong aSwap = *aTopBits;
+
+ *aTopBits = *aBottomBits;
+ aTopBits += aPhysSrcWidth;
+ *aBottomBits = aSwap;
+ aBottomBits -= aPhysSrcWidth;
+ }
+ }
+
+ aSrcMemoryImage->BitsChanged();
+}
+
+void SexyAppBase::RotateImageHue(Sexy::MemoryImage *theImage, int theDelta)
+{
+ while (theDelta < 0)
+ theDelta += 256;
+
+ int aSize = theImage->mWidth * theImage->mHeight;
+ DWORD *aPtr = theImage->GetBits();
+ for (int i=0; i<aSize; i++)
+ {
+ DWORD aPixel = *aPtr;
+ int alpha = aPixel&0xff000000;
+ int r = (aPixel>>16)&0xff;
+ int g = (aPixel>>8) &0xff;
+ int b = aPixel&0xff;
+
+ int maxval = max(r, max(g, b));
+ int minval = min(r, min(g, b));
+ int h = 0;
+ int s = 0;
+ int l = (minval+maxval)/2;
+ int delta = maxval - minval;
+
+ if (delta != 0)
+ {
+ s = (delta * 256) / ((l <= 128) ? (minval + maxval) : (512 - maxval - minval));
+
+ if (r == maxval)
+ h = (g == minval ? 1280 + (((maxval-b) * 256) / delta) : 256 - (((maxval - g) * 256) / delta));
+ else if (g == maxval)
+ h = (b == minval ? 256 + (((maxval-r) * 256) / delta) : 768 - (((maxval - b) * 256) / delta));
+ else
+ h = (r == minval ? 768 + (((maxval-g) * 256) / delta) : 1280 - (((maxval - r) * 256) / delta));
+
+ h /= 6;
+ }
+
+ h += theDelta;
+ if (h >= 256)
+ h -= 256;
+
+ double v= (l < 128) ? (l * (255+s))/255 :
+ (l+s-l*s/255);
+
+ int y = (int) (2*l-v);
+
+ int aColorDiv = (6 * h) / 256;
+ int x = (int)(y+(v-y)*((h - (aColorDiv * 256 / 6)) * 6)/255);
+ if (x > 255)
+ x = 255;
+
+ int z = (int) (v-(v-y)*((h - (aColorDiv * 256 / 6)) * 6)/255);
+ if (z < 0)
+ z = 0;
+
+ switch (aColorDiv)
+ {
+ case 0: r = (int) v; g = x; b = y; break;
+ case 1: r = z; g= (int) v; b = y; break;
+ case 2: r = y; g= (int) v; b = x; break;
+ case 3: r = y; g = z; b = (int) v; break;
+ case 4: r = x; g = y; b = (int) v; break;
+ case 5: r = (int) v; g = y; b = z; break;
+ default: r = (int) v; g = x; b = y; break;
+ }
+
+ *aPtr++ = alpha | (r<<16) | (g << 8) | (b);
+
+ }
+
+ theImage->BitsChanged();
+}
+
+ulong SexyAppBase::HSLToRGB(int h, int s, int l)
+{
+ int r;
+ int g;
+ int b;
+
+ double v= (l < 128) ? (l * (255+s))/255 :
+ (l+s-l*s/255);
+
+ int y = (int) (2*l-v);
+
+ int aColorDiv = (6 * h) / 256;
+ int x = (int)(y+(v-y)*((h - (aColorDiv * 256 / 6)) * 6)/255);
+ if (x > 255)
+ x = 255;
+
+ int z = (int) (v-(v-y)*((h - (aColorDiv * 256 / 6)) * 6)/255);
+ if (z < 0)
+ z = 0;
+
+ switch (aColorDiv)
+ {
+ case 0: r = (int) v; g = x; b = y; break;
+ case 1: r = z; g= (int) v; b = y; break;
+ case 2: r = y; g= (int) v; b = x; break;
+ case 3: r = y; g = z; b = (int) v; break;
+ case 4: r = x; g = y; b = (int) v; break;
+ case 5: r = (int) v; g = y; b = z; break;
+ default: r = (int) v; g = x; b = y; break;
+ }
+
+ return 0xFF000000 | (r << 16) | (g << 8) | (b);
+}
+
+ulong SexyAppBase::RGBToHSL(int r, int g, int b)
+{
+ int maxval = max(r, max(g, b));
+ int minval = min(r, min(g, b));
+ int hue = 0;
+ int saturation = 0;
+ int luminosity = (minval+maxval)/2;
+ int delta = maxval - minval;
+
+ if (delta != 0)
+ {
+ saturation = (delta * 256) / ((luminosity <= 128) ? (minval + maxval) : (512 - maxval - minval));
+
+ if (r == maxval)
+ hue = (g == minval ? 1280 + (((maxval-b) * 256) / delta) : 256 - (((maxval - g) * 256) / delta));
+ else if (g == maxval)
+ hue = (b == minval ? 256 + (((maxval-r) * 256) / delta) : 768 - (((maxval - b) * 256) / delta));
+ else
+ hue = (r == minval ? 768 + (((maxval-g) * 256) / delta) : 1280 - (((maxval - r) * 256) / delta));
+
+ hue /= 6;
+ }
+
+ return 0xFF000000 | (hue) | (saturation << 8) | (luminosity << 16);
+}
+
+void SexyAppBase::HSLToRGB(const ulong* theSource, ulong* theDest, int theSize)
+{
+ for (int i = 0; i < theSize; i++)
+ {
+ ulong src = theSource[i];
+ theDest[i] = (src & 0xFF000000) | (HSLToRGB((src & 0xFF), (src >> 8) & 0xFF, (src >> 16) & 0xFF) & 0x00FFFFFF);
+ }
+}
+
+void SexyAppBase::RGBToHSL(const ulong* theSource, ulong* theDest, int theSize)
+{
+ for (int i = 0; i < theSize; i++)
+ {
+ ulong src = theSource[i];
+ theDest[i] = (src & 0xFF000000) | (RGBToHSL(((src >> 16) & 0xFF), (src >> 8) & 0xFF, (src & 0xFF)) & 0x00FFFFFF);
+ }
+}
+
+void SexyAppBase::PrecacheAdditive(MemoryImage* theImage)
+{
+ theImage->GetRLAdditiveData(mDDInterface);
+}
+
+void SexyAppBase::PrecacheAlpha(MemoryImage* theImage)
+{
+ theImage->GetRLAlphaData();
+}
+
+void SexyAppBase::PrecacheNative(MemoryImage* theImage)
+{
+ theImage->GetNativeAlphaData(mDDInterface);
+}
+
+
+void SexyAppBase::PlaySample(int theSoundNum)
+{
+ if (!mSoundManager)
+ return;
+
+ SoundInstance* aSoundInstance = mSoundManager->GetSoundInstance(theSoundNum);
+ if (aSoundInstance != NULL)
+ {
+ aSoundInstance->Play(false, true);
+ }
+}
+
+
+void SexyAppBase::PlaySample(int theSoundNum, int thePan)
+{
+ if (!mSoundManager)
+ return;
+
+ SoundInstance* aSoundInstance = mSoundManager->GetSoundInstance(theSoundNum);
+ if (aSoundInstance != NULL)
+ {
+ aSoundInstance->SetPan(thePan);
+ aSoundInstance->Play(false, true);
+ }
+}
+
+bool SexyAppBase::IsMuted()
+{
+ return mMuteCount > 0;
+}
+
+void SexyAppBase::Mute(bool autoMute)
+{
+ mMuteCount++;
+ if (autoMute)
+ mAutoMuteCount++;
+
+ SetMusicVolume(mMusicVolume);
+ SetSfxVolume(mSfxVolume);
+}
+
+void SexyAppBase::Unmute(bool autoMute)
+{
+ if (mMuteCount > 0)
+ {
+ mMuteCount--;
+ if (autoMute)
+ mAutoMuteCount--;
+ }
+
+ SetMusicVolume(mMusicVolume);
+ SetSfxVolume(mSfxVolume);
+}
+
+
+double SexyAppBase::GetMusicVolume()
+{
+ return mMusicVolume;
+}
+
+void SexyAppBase::SetMusicVolume(double theVolume)
+{
+ mMusicVolume = theVolume;
+
+ if (mMusicInterface != NULL)
+ mMusicInterface->SetVolume((mMuteCount > 0) ? 0.0 : mMusicVolume);
+}
+
+double SexyAppBase::GetSfxVolume()
+{
+ return mSfxVolume;
+}
+
+void SexyAppBase::SetSfxVolume(double theVolume)
+{
+ mSfxVolume = theVolume;
+
+ if (mSoundManager != NULL)
+ mSoundManager->SetVolume((mMuteCount > 0) ? 0.0 : mSfxVolume);
+}
+
+double SexyAppBase::GetMasterVolume()
+{
+ return mSoundManager->GetMasterVolume();
+}
+
+void SexyAppBase::SetMasterVolume(double theMasterVolume)
+{
+ mSfxVolume = theMasterVolume;
+ mSoundManager->SetMasterVolume(mSfxVolume);
+}
+
+void SexyAppBase::AddMemoryImage(MemoryImage* theMemoryImage)
+{
+ AutoCrit anAutoCrit(mDDInterface->mCritSect);
+ mMemoryImageSet.insert(theMemoryImage);
+}
+
+void SexyAppBase::RemoveMemoryImage(MemoryImage* theMemoryImage)
+{
+ AutoCrit anAutoCrit(mDDInterface->mCritSect);
+ MemoryImageSet::iterator anItr = mMemoryImageSet.find(theMemoryImage);
+ if (anItr != mMemoryImageSet.end())
+ mMemoryImageSet.erase(anItr);
+
+ Remove3DData(theMemoryImage);
+}
+
+void SexyAppBase::Remove3DData(MemoryImage* theMemoryImage)
+{
+ if (mDDInterface)
+ mDDInterface->Remove3DData(theMemoryImage);
+}
+
+
+bool SexyAppBase::Is3DAccelerated()
+{
+ return mDDInterface->mIs3D;
+}
+
+bool SexyAppBase::Is3DAccelerationSupported()
+{
+ if (mDDInterface->mD3DTester)
+ return mDDInterface->mD3DTester->Is3DSupported();
+ else
+ return false;
+}
+
+bool SexyAppBase::Is3DAccelerationRecommended()
+{
+ if (mDDInterface->mD3DTester)
+ return mDDInterface->mD3DTester->Is3DRecommended();
+ else
+ return false;
+}
+
+void SexyAppBase::DemoSyncRefreshRate()
+{
+ mSyncRefreshRate = mDDInterface->mRefreshRate;
+
+ if (mRecordingDemoBuffer)
+ {
+ WriteDemoTimingBlock();
+ mDemoBuffer.WriteNumBits(0, 1);
+ mDemoBuffer.WriteNumBits(DEMO_VIDEO_DATA, 5);
+ mDemoBuffer.WriteBoolean(mIsWindowed);
+ uchar aByte = (uchar) mSyncRefreshRate;
+ mDemoBuffer.WriteByte(aByte);
+ }
+}
+
+void SexyAppBase::Set3DAcclerated(bool is3D, bool reinit)
+{
+ if (mDDInterface->mIs3D == is3D)
+ return;
+
+ mUserChanged3DSetting = true;
+ mDDInterface->mIs3D = is3D;
+
+ if (reinit)
+ {
+ int aResult = InitDDInterface();
+
+ if (is3D && aResult != DDInterface::RESULT_OK)
+ {
+ Set3DAcclerated(false, reinit);
+ return;
+ }
+ else if (aResult != DDInterface::RESULT_OK)
+ {
+ Popup(GetString("FAILED_INIT_DIRECTDRAW", _S("Failed to initialize DirectDraw: ")) + StringToSexyString(DDInterface::ResultToString(aResult) + " " + mDDInterface->mErrorString));
+ DoExit(1);
+ }
+
+ ReInitImages();
+
+ mWidgetManager->mImage = mDDInterface->GetScreenImage();
+ mWidgetManager->MarkAllDirty();
+ }
+}
+
+SharedImageRef SexyAppBase::GetSharedImage(const std::string& theFileName, const std::string& theVariant, bool* isNew)
+{
+ std::string anUpperFileName = StringToUpper(theFileName);
+ std::string anUpperVariant = StringToUpper(theVariant);
+
+ std::pair<SharedImageMap::iterator, bool> aResultPair;
+ SharedImageRef aSharedImageRef;
+
+ {
+ AutoCrit anAutoCrit(mDDInterface->mCritSect);
+ aResultPair = mSharedImageMap.insert(SharedImageMap::value_type(SharedImageMap::key_type(anUpperFileName, anUpperVariant), SharedImage()));
+ aSharedImageRef = &aResultPair.first->second;
+ }
+
+ if (isNew != NULL)
+ *isNew = aResultPair.second;
+
+ if (aResultPair.second)
+ {
+ // Pass in a '!' as the first char of the file name to create a new image
+ if ((theFileName.length() > 0) && (theFileName[0] == '!'))
+ aSharedImageRef.mSharedImage->mImage = new DDImage(mDDInterface);
+ else
+ aSharedImageRef.mSharedImage->mImage = GetImage(theFileName,false);
+ }
+
+ return aSharedImageRef;
+}
+
+void SexyAppBase::CleanSharedImages()
+{
+ AutoCrit anAutoCrit(mDDInterface->mCritSect);
+
+ if (mCleanupSharedImages)
+ {
+ // Delete shared images with reference counts of 0
+ // This doesn't occur in ~SharedImageRef because sometimes we can not only access the image
+ // through the SharedImageRef returned by GetSharedImage, but also by calling GetSharedImage
+ // again with the same params -- so we can have instances where we do the 'final' deref on
+ // an image but immediately re-request it via GetSharedImage
+ SharedImageMap::iterator aSharedImageItr = mSharedImageMap.begin();
+ while (aSharedImageItr != mSharedImageMap.end())
+ {
+ SharedImage* aSharedImage = &aSharedImageItr->second;
+ if (aSharedImage->mRefCount == 0)
+ {
+ delete aSharedImage->mImage;
+ mSharedImageMap.erase(aSharedImageItr++);
+ }
+ else
+ ++aSharedImageItr;
+ }
+
+ mCleanupSharedImages = false;
+ }
+}
diff --git a/osframework/source/SexyAppFramework/SexyAppBase.dsp b/osframework/source/SexyAppFramework/SexyAppBase.dsp
new file mode 100644
index 0000000..5ea6de7
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase.dsp
@@ -0,0 +1,1304 @@
+# Microsoft Developer Studio Project File - Name="SexyAppBase" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=SexyAppBase - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "SexyAppBase.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "SexyAppBase.mak" CFG="SexyAppBase - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "SexyAppBase - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "SexyAppBase - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""$/WinAlch", YKBAAAAA"
+# PROP Scc_LocalPath "..\winalch"
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "SexyAppBase - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "ReleaseVC6"
+# PROP Intermediate_Dir "ReleaseVC6"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /Oy- /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "_WINDOWS" /D "_VISUALC_" /D "_JPEGLIB_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "SexyAppBase - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "DebugVC6"
+# PROP Intermediate_Dir "DebugVC6"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "_WINDOWS" /D "_VISUALC_" /D "_JPEGLIB_" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "SexyAppBase - Win32 Release"
+# Name "SexyAppBase - Win32 Debug"
+# Begin Group "Graphics"
+
+# PROP Default_Filter ""
+# Begin Group "Graphics Source"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\Color.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\D3DInterface.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\D3DTester.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DDImage.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DDInterface.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Font.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Graphics.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\GraphicsBuild.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Image.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\ImageFont.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\MemoryImage.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Quantize.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\SWTri.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\SysFont.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# End Group
+# Begin Group "Graphics Include"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\Color.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\D3DInterface.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\D3DTester.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DDImage.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DDInterface.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Font.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Graphics.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Image.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ImageFont.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\MemoryImage.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Quantize.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SWTri.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SysFont.h
+# End Source File
+# End Group
+# End Group
+# Begin Group "ImageLib"
+
+# PROP Default_Filter ""
+# Begin Group "PNG"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\ImageLib\png\png.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\png.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngasmrd.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngconf.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngget.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngmem.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngpread.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngread.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngrio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngrtran.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngrutil.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngset.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngtrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngvcrd.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngwio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngwrite.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngwtran.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\png\pngwutil.c
+# End Source File
+# End Group
+# Begin Group "JPEG"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\cderror.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\cdjpeg.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\cdjpeg.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcapimin.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcapistd.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jccoefct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jccolor.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcdctmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jchuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jchuff.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcinit.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcmainct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcmarker.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcmaster.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcomapi.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jconfig.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcparam.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcphuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcprepct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jcsample.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jctrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdapimin.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdapistd.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdatadst.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdatasrc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdcoefct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdcolor.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdct.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jddctmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdhuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdhuff.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdinput.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdmainct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdmarker.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdmaster.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdmerge.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdphuff.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdpostct.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdsample.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jdtrans.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jerror.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jfdctflt.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jfdctfst.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jfdctint.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jidctflt.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jidctfst.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jidctint.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jidctred.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jinclude.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jmemmgr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jmemnobs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jmemsys.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jmorecfg.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jpegint.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jpeglib.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jquant1.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jquant2.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jutils.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\jversion.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdbmp.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdcolmap.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdgif.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdppm.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdrle.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdswitch.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\rdtarga.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\transupp.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\transupp.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\wrbmp.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\wrgif.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\wrppm.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\wrrle.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\jpeg\wrtarga.c
+# End Source File
+# End Group
+# Begin Group "ZLIB"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\adler32.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\compress.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\crc32.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\deflate.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\deflate.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\gzio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infblock.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infblock.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infcodes.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infcodes.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inffast.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inffast.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inffixed.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inflate.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inftrees.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\inftrees.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infutil.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\infutil.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\trees.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\trees.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\uncompr.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\zconf.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\zlib.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\zutil.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\zlib\zutil.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=..\ImageLib\ImageLib.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\ImageLib\ImageLib.h
+# End Source File
+# End Group
+# Begin Group "Misc"
+
+# PROP Default_Filter ""
+# Begin Group "Misc Source"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\Buffer.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Common.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\CritSect.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DescParser.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DirectXErrorString.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Flags.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\HTTPTransfer.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\KeyCodes.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\MiscBuildBase.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\MTRand.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\PerfTimer.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\PropertiesParser.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\SEHCatcher.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\SexyMatrix.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLParser.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# End Group
+# Begin Group "Misc Include"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\AutoCrit.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Buffer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\CritSect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DescParser.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DirectXErrorString.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Flags.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\HTTPTransfer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\KeyCodes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\MTRand.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\PerfTimer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Point.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\PropertiesParser.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Rect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SEHCatcher.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SexyMatrix.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SexyVector.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLParser.h
+# End Source File
+# End Group
+# End Group
+# Begin Group "Sound"
+
+# PROP Default_Filter ""
+# Begin Group "Sound Source"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\BassLoader.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\BassMusicInterface.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSoundInstance.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSoundManager.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModLoader.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModMusicInterface.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModSoundInstance.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModSoundManager.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\MusicInterface.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\SoundBuild.cpp
+# End Source File
+# End Group
+# Begin Group "Sound Include"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\BassLoader.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\BassMusicInterface.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSoundInstance.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSoundManager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dsoundversion.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModLoader.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModMusicInterface.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModSoundInstance.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FModSoundManager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\MusicInterface.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SoundInstance.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SoundManager.h
+# End Source File
+# End Group
+# Begin Group "ogg"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\ogg\asm_arm.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\backends.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\bitwise.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\block.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\codebook.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\codebook.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\codec_internal.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\config_types.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\floor0.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\floor1.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\framing.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\info.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\ivorbiscodec.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\ivorbisfile.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\lsp_lookup.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\mapping0.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\mdct.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\mdct.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\mdct_lookup.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\misc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\ogg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\os.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\os_types.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\registry.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\registry.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\res012.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\sharedbook.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\synthesis.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\vorbisfile.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\window.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\window.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg\window_lookup.h
+# End Source File
+# End Group
+# End Group
+# Begin Group "Widget"
+
+# PROP Default_Filter ""
+# Begin Group "Widget Source"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\ButtonWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Checkbox.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dialog.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DialogButton.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\EditWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\HyperlinkWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Insets.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\ListWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\ScrollbarWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\ScrollbuttonWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Slider.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\TextWidget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Widget.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\WidgetBuildBase.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\WidgetContainer.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\WidgetManager.cpp
+# PROP Exclude_From_Build 1
+# End Source File
+# End Group
+# Begin Group "Widget Include"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\ButtonListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ButtonWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Checkbox.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\CheckboxListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dialog.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DialogButton.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DialogListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\EditListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\EditWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\HyperlinkWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Insets.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ListListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ListWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ScrollbarWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ScrollbuttonWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ScrollListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Slider.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SliderListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TextWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Widget.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\WidgetContainer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\WidgetManager.h
+# End Source File
+# End Group
+# End Group
+# Begin Source File
+
+SOURCE=.\SexyAppBase.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\SexyAppBase.h
+# End Source File
+# End Target
+# End Project
diff --git a/osframework/source/SexyAppFramework/SexyAppBase.h b/osframework/source/SexyAppFramework/SexyAppBase.h
new file mode 100644
index 0000000..98f6397
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase.h
@@ -0,0 +1,577 @@
+#ifndef __SEXYAPPBASE_H__
+#define __SEXYAPPBASE_H__
+
+#include "Common.h"
+#include "Rect.h"
+#include "Color.h"
+#include "ButtonListener.h"
+#include "DialogListener.h"
+#include "Buffer.h"
+#include "CritSect.h"
+#include "SharedImage.h"
+#include "Ratio.h"
+
+namespace ImageLib
+{
+ class Image;
+};
+
+namespace Sexy
+{
+
+class WidgetManager;
+class DDInterface;
+class Image;
+class DDImage;
+class Widget;
+class SoundManager;
+class MusicInterface;
+class MemoryImage;
+class HTTPTransfer;
+class Dialog;
+
+class ResourceManager;
+
+class WidgetSafeDeleteInfo
+{
+public:
+ int mUpdateAppDepth;
+ Widget* mWidget;
+};
+
+
+typedef std::list<WidgetSafeDeleteInfo> WidgetSafeDeleteList;
+typedef std::set<MemoryImage*> MemoryImageSet;
+typedef std::map<int, Dialog*> DialogMap;
+typedef std::list<Dialog*> DialogList;
+typedef std::list<MSG> WindowsMessageList;
+typedef std::vector<std::string> StringVector;
+//typedef std::basic_string<TCHAR> tstring; // string of TCHARs
+
+typedef std::map<std::string, SexyString> StringSexyStringMap;
+typedef std::map<std::string, std::string> StringStringMap;
+typedef std::map<std::string, std::wstring> StringWStringMap;
+typedef std::map<std::string, bool> StringBoolMap;
+typedef std::map<std::string, int> StringIntMap;
+typedef std::map<std::string, double> StringDoubleMap;
+typedef std::map<std::string, StringVector> StringStringVectorMap;
+
+enum
+{
+ CURSOR_POINTER,
+ CURSOR_HAND,
+ CURSOR_DRAGGING,
+ CURSOR_TEXT,
+ CURSOR_CIRCLE_SLASH,
+ CURSOR_SIZEALL,
+ CURSOR_SIZENESW,
+ CURSOR_SIZENS,
+ CURSOR_SIZENWSE,
+ CURSOR_SIZEWE,
+ CURSOR_WAIT,
+ CURSOR_NONE,
+ CURSOR_CUSTOM,
+ NUM_CURSORS
+};
+
+enum
+{
+ DEMO_MOUSE_POSITION,
+ DEMO_ACTIVATE_APP,
+ DEMO_SIZE,
+ DEMO_KEY_DOWN,
+ DEMO_KEY_UP,
+ DEMO_KEY_CHAR,
+ DEMO_CLOSE,
+ DEMO_MOUSE_ENTER,
+ DEMO_MOUSE_EXIT,
+ DEMO_LOADING_COMPLETE,
+ DEMO_REGISTRY_GETSUBKEYS,
+ DEMO_REGISTRY_READ,
+ DEMO_REGISTRY_WRITE,
+ DEMO_REGISTRY_ERASE,
+ DEMO_FILE_EXISTS,
+ DEMO_FILE_READ,
+ DEMO_FILE_WRITE,
+ DEMO_HTTP_RESULT,
+ DEMO_SYNC,
+ DEMO_ASSERT_STRING_EQUAL,
+ DEMO_ASSERT_INT_EQUAL,
+ DEMO_MOUSE_WHEEL,
+ DEMO_HANDLE_COMPLETE,
+ DEMO_VIDEO_DATA,
+ DEMO_IDLE = 31
+};
+
+enum {
+ FPS_ShowFPS,
+ FPS_ShowCoords,
+ Num_FPS_Types
+};
+
+enum
+{
+ UPDATESTATE_MESSAGES,
+ UPDATESTATE_PROCESS_1,
+ UPDATESTATE_PROCESS_2,
+ UPDATESTATE_PROCESS_DONE
+};
+
+typedef std::map<HANDLE, int> HandleToIntMap;
+
+class SexyAppBase : public ButtonListener, public DialogListener
+{
+public:
+
+ ulong mRandSeed;
+
+ std::string mCompanyName;
+ std::string mFullCompanyName;
+ std::string mProdName;
+ SexyString mTitle;
+ std::string mRegKey;
+ std::string mChangeDirTo;
+
+ int mRelaxUpdateBacklogCount; // app doesn't try to catch up for this many frames
+ int mPreferredX;
+ int mPreferredY;
+ int mWidth;
+ int mHeight;
+ int mFullscreenBits;
+ double mMusicVolume;
+ double mSfxVolume;
+ double mDemoMusicVolume;
+ double mDemoSfxVolume;
+ bool mNoSoundNeeded;
+ bool mWantFMod;
+ bool mCmdLineParsed;
+ bool mSkipSignatureChecks;
+ bool mStandardWordWrap;
+ bool mbAllowExtendedChars;
+
+ HANDLE mMutex;
+ bool mOnlyAllowOneCopyToRun;
+ UINT mNotifyGameMessage;
+ CritSect mCritSect;
+ bool mBetaValidate;
+ uchar mAdd8BitMaxTable[512];
+ WidgetManager* mWidgetManager;
+ DialogMap mDialogMap;
+ DialogList mDialogList;
+ DWORD mPrimaryThreadId;
+ bool mSEHOccured;
+ bool mShutdown;
+ bool mExitToTop;
+ bool mIsWindowed;
+ bool mIsPhysWindowed;
+ bool mFullScreenWindow; // uses ChangeDisplaySettings to run fullscreen with mIsWindowed true
+ bool mForceFullscreen;
+ bool mForceWindowed;
+ bool mInitialized;
+ bool mProcessInTimer;
+ DWORD mTimeLoaded;
+ HWND mHWnd;
+ HWND mInvisHWnd;
+ bool mIsScreenSaver;
+ bool mAllowMonitorPowersave;
+ WindowsMessageList mDeferredMessages;
+ bool mNoDefer;
+ bool mFullScreenPageFlip;
+ bool mTabletPC;
+ DDInterface* mDDInterface;
+ bool mAlphaDisabled;
+ MusicInterface* mMusicInterface;
+ bool mReadFromRegistry;
+ std::string mRegisterLink;
+ std::string mProductVersion;
+ Image* mCursorImages[NUM_CURSORS];
+ HCURSOR mOverrideCursor;
+ bool mIsOpeningURL;
+ bool mShutdownOnURLOpen;
+ std::string mOpeningURL;
+ DWORD mOpeningURLTime;
+ DWORD mLastTimerTime;
+ DWORD mLastBigDelayTime;
+ double mUnmutedMusicVolume;
+ double mUnmutedSfxVolume;
+ int mMuteCount;
+ int mAutoMuteCount;
+ bool mDemoMute;
+ bool mMuteOnLostFocus;
+ MemoryImageSet mMemoryImageSet;
+ SharedImageMap mSharedImageMap;
+ bool mCleanupSharedImages;
+
+ int mNonDrawCount;
+ int mFrameTime;
+
+ bool mIsDrawing;
+ bool mLastDrawWasEmpty;
+ bool mHasPendingDraw;
+ double mPendingUpdatesAcc;
+ double mUpdateFTimeAcc;
+ DWORD mLastTimeCheck;
+ DWORD mLastTime;
+ DWORD mLastUserInputTick;
+
+ int mSleepCount;
+ int mDrawCount;
+ int mUpdateCount;
+ int mUpdateAppState;
+ int mUpdateAppDepth;
+ double mUpdateMultiplier;
+ bool mPaused;
+ int mFastForwardToUpdateNum;
+ bool mFastForwardToMarker;
+ bool mFastForwardStep;
+ DWORD mLastDrawTick;
+ DWORD mNextDrawTick;
+ int mStepMode; // 0 = off, 1 = step, 2 = waiting for step
+
+ int mCursorNum;
+ SoundManager* mSoundManager;
+ HCURSOR mHandCursor;
+ HCURSOR mDraggingCursor;
+ WidgetSafeDeleteList mSafeDeleteList;
+ bool mMouseIn;
+ bool mRunning;
+ bool mActive;
+ bool mMinimized;
+ bool mPhysMinimized;
+ bool mIsDisabled;
+ bool mHasFocus;
+ int mDrawTime;
+ ulong mFPSStartTick;
+ int mFPSFlipCount;
+ int mFPSDirtyCount;
+ int mFPSTime;
+ int mFPSCount;
+ bool mShowFPS;
+ int mShowFPSMode;
+ int mScreenBltTime;
+ bool mAutoStartLoadingThread;
+ bool mLoadingThreadStarted;
+ bool mLoadingThreadCompleted;
+ bool mLoaded;
+ bool mYieldMainThread;
+ bool mLoadingFailed;
+ bool mCursorThreadRunning;
+ bool mSysCursor;
+ bool mCustomCursorsEnabled;
+ bool mCustomCursorDirty;
+ bool mLastShutdownWasGraceful;
+ bool mIsWideWindow;
+
+ int mNumLoadingThreadTasks;
+ int mCompletedLoadingThreadTasks;
+
+ // For recording/playback of program control
+ bool mRecordingDemoBuffer;
+ bool mPlayingDemoBuffer;
+ bool mManualShutdown;
+ std::string mDemoPrefix;
+ std::string mDemoFileName;
+ Buffer mDemoBuffer;
+ int mDemoLength;
+ int mLastDemoMouseX;
+ int mLastDemoMouseY;
+ int mLastDemoUpdateCnt;
+ bool mDemoNeedsCommand;
+ bool mDemoIsShortCmd;
+ int mDemoCmdNum;
+ int mDemoCmdOrder;
+ int mDemoCmdBitPos;
+ bool mDemoLoadingComplete;
+ HandleToIntMap mHandleToIntMap; // For waiting on handles
+ int mCurHandleNum;
+
+ typedef std::pair<std::string, int> DemoMarker;
+ typedef std::list<DemoMarker> DemoMarkerList;
+ DemoMarkerList mDemoMarkerList;
+
+ bool mDebugKeysEnabled;
+ bool mEnableMaximizeButton;
+ bool mCtrlDown;
+ bool mAltDown;
+
+ int mSyncRefreshRate;
+ bool mVSyncUpdates;
+ bool mVSyncBroken;
+ int mVSyncBrokenCount;
+ DWORD mVSyncBrokenTestStartTick;
+ DWORD mVSyncBrokenTestUpdates;
+ bool mWaitForVSync;
+ bool mSoftVSyncWait;
+ bool mUserChanged3DSetting;
+ bool mAutoEnable3D;
+ bool mTest3D;
+ DWORD mMinVidMemory3D;
+ DWORD mRecommendedVidMemory3D;
+
+ bool mWidescreenAware;
+ Rect mScreenBounds;
+ bool mEnableWindowAspect;
+ Ratio mWindowAspect;
+
+ StringWStringMap mStringProperties;
+ StringBoolMap mBoolProperties;
+ StringIntMap mIntProperties;
+ StringDoubleMap mDoubleProperties;
+ StringStringVectorMap mStringVectorProperties;
+ ResourceManager* mResourceManager;
+
+#ifdef ZYLOM
+ uint mZylomGameId;
+#endif
+
+ LONG mOldWndProc;
+
+protected:
+ void RehupFocus();
+ void ClearKeysDown();
+ bool ProcessDeferredMessages(bool singleMessage);
+ void UpdateFTimeAcc();
+ virtual bool Process(bool allowSleep = true);
+ virtual void UpdateFrames();
+ virtual bool DoUpdateFrames();
+ virtual void DoUpdateFramesF(float theFrac);
+ virtual void MakeWindow();
+ virtual void EnforceCursor();
+ virtual void ReInitImages();
+ virtual void DeleteNativeImageData();
+ virtual void DeleteExtraImageData();
+
+ // Loading thread methods
+ virtual void LoadingThreadCompleted();
+ static void LoadingThreadProcStub(void *theArg);
+
+ // Cursor thread methods
+ void CursorThreadProc();
+ static void CursorThreadProcStub(void *theArg);
+ void StartCursorThread();
+
+ void WaitForLoadingThread();
+ void ProcessSafeDeleteList();
+ void RestoreScreenResolution();
+ void DoExit(int theCode);
+
+ void TakeScreenshot();
+ void DumpProgramInfo();
+ void ShowMemoryUsage();
+
+ // Registry helpers
+ bool RegistryRead(const std::string& theValueName, ulong* theType, uchar* theValue, ulong* theLength);
+ bool RegistryReadKey(const std::string& theValueName, ulong* theType, uchar* theValue, ulong* theLength, HKEY theMainKey = HKEY_CURRENT_USER);
+ bool RegistryWrite(const std::string& theValueName, ulong theType, const uchar* theValue, ulong theLength);
+
+ // Demo recording helpers
+ void ProcessDemo();
+
+public:
+ SexyAppBase();
+ virtual ~SexyAppBase();
+
+ // Common overrides:
+ virtual MusicInterface* CreateMusicInterface(HWND theHWnd);
+ virtual void InitHook();
+ virtual void ShutdownHook();
+ virtual void PreTerminate();
+ virtual void LoadingThreadProc();
+ virtual void WriteToRegistry();
+ virtual void ReadFromRegistry();
+ virtual Dialog* NewDialog(int theDialogId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode);
+ virtual void PreDisplayHook();
+
+ // Public methods
+ virtual void BeginPopup();
+ virtual void EndPopup();
+ virtual int MsgBox(const std::string &theText, const std::string &theTitle = "Message", int theFlags = MB_OK);
+ virtual int MsgBox(const std::wstring &theText, const std::wstring &theTitle = L"Message", int theFlags = MB_OK);
+ virtual void Popup(const std::string& theString);
+ virtual void Popup(const std::wstring& theString);
+ virtual void LogScreenSaverError(const std::string &theError);
+ virtual void SafeDeleteWidget(Widget* theWidget);
+
+ virtual void URLOpenFailed(const std::string& theURL);
+ virtual void URLOpenSucceeded(const std::string& theURL);
+ virtual bool OpenURL(const std::string& theURL, bool shutdownOnOpen = false);
+ virtual std::string GetProductVersion(const std::string& thePath);
+
+ virtual void SEHOccured();
+ virtual std::string GetGameSEHInfo();
+ virtual void GetSEHWebParams(DefinesMap* theDefinesMap);
+ virtual void Shutdown();
+
+ virtual void DoParseCmdLine();
+ virtual void ParseCmdLine(const std::string& theCmdLine);
+ virtual void HandleCmdLineParam(const std::string& theParamName, const std::string& theParamValue);
+ virtual void HandleNotifyGameMessage(int theType, int theParam); // for HWND_BROADCAST of mNotifyGameMessage (0-1000 are reserved for SexyAppBase for theType)
+ virtual void HandleGameAlreadyRunning();
+
+ virtual void Start();
+ virtual void Init();
+ virtual void PreDDInterfaceInitHook();
+ virtual void PostDDInterfaceInitHook();
+ virtual bool ChangeDirHook(const char *theIntendedPath);
+ virtual void PlaySample(int theSoundNum);
+ virtual void PlaySample(int theSoundNum, int thePan);
+
+ virtual double GetMasterVolume();
+ virtual double GetMusicVolume();
+ virtual double GetSfxVolume();
+ virtual bool IsMuted();
+
+ virtual void SetMasterVolume(double theVolume);
+ virtual void SetMusicVolume(double theVolume);
+ virtual void SetSfxVolume(double theVolume);
+ virtual void Mute(bool autoMute = false);
+ virtual void Unmute(bool autoMute = false);
+
+ void StartLoadingThread();
+ virtual double GetLoadingThreadProgress();
+
+ void CopyToClipboard(const std::string& theString);
+ std::string GetClipboard();
+
+ void SetCursor(int theCursorNum);
+ int GetCursor();
+ void EnableCustomCursors(bool enabled);
+ virtual DDImage* GetImage(const std::string& theFileName, bool commitBits = true);
+ virtual SharedImageRef GetSharedImage(const std::string& theFileName, const std::string& theVariant = "", bool* isNew = NULL);
+
+ void CleanSharedImages();
+ void PrecacheAdditive(MemoryImage* theImage);
+ void PrecacheAlpha(MemoryImage* theImage);
+ void PrecacheNative(MemoryImage* theImage);
+ void SetCursorImage(int theCursorNum, Image* theImage);
+
+ DDImage* CreateCrossfadeImage(Image* theImage1, const Rect& theRect1, Image* theImage2, const Rect& theRect2, double theFadeFactor);
+ void ColorizeImage(Image* theImage, const Color& theColor);
+ DDImage* CreateColorizedImage(Image* theImage, const Color& theColor);
+ DDImage* CopyImage(Image* theImage, const Rect& theRect);
+ DDImage* CopyImage(Image* theImage);
+ void MirrorImage(Image* theImage);
+ void FlipImage(Image* theImage);
+ void RotateImageHue(Sexy::MemoryImage *theImage, int theDelta);
+ ulong HSLToRGB(int h, int s, int l);
+ ulong RGBToHSL(int r, int g, int b);
+ void HSLToRGB(const ulong* theSource, ulong* theDest, int theSize);
+ void RGBToHSL(const ulong* theSource, ulong* theDest, int theSize);
+
+ void AddMemoryImage(MemoryImage* theMemoryImage);
+ void RemoveMemoryImage(MemoryImage* theMemoryImage);
+ void Remove3DData(MemoryImage* theMemoryImage);
+ virtual void SwitchScreenMode();
+ virtual void SwitchScreenMode(bool wantWindowed);
+ virtual void SwitchScreenMode(bool wantWindowed, bool is3d, bool force = false);
+ virtual void SetAlphaDisabled(bool isDisabled);
+
+ virtual Dialog* DoDialog(int theDialogId, bool isModal, const SexyString& theDialogHeader, const SexyString& theDialogLines, const SexyString& theDialogFooter, int theButtonMode);
+ virtual Dialog* GetDialog(int theDialogId);
+ virtual void AddDialog(int theDialogId, Dialog* theDialog);
+ virtual void AddDialog(Dialog* theDialog);
+ virtual bool KillDialog(int theDialogId, bool removeWidget, bool deleteWidget);
+ virtual bool KillDialog(int theDialogId);
+ virtual bool KillDialog(Dialog* theDialog);
+ virtual int GetDialogCount();
+ virtual void ModalOpen();
+ virtual void ModalClose();
+ virtual void DialogButtonPress(int theDialogId, int theButtonId);
+ virtual void DialogButtonDepress(int theDialogId, int theButtonId);
+
+ virtual void GotFocus();
+ virtual void LostFocus();
+ virtual bool IsAltKeyUsed(WPARAM wParam);
+ virtual bool DebugKeyDown(int theKey);
+ virtual bool DebugKeyDownAsync(int theKey, bool ctrlDown, bool altDown);
+ virtual void CloseRequestAsync();
+ bool Is3DAccelerated();
+ bool Is3DAccelerationSupported();
+ bool Is3DAccelerationRecommended();
+ void DemoSyncRefreshRate();
+ void Set3DAcclerated(bool is3D, bool reinit = true);
+ virtual void Done3dTesting();
+ virtual std::string NotifyCrashHook(); // return file name that you want to upload
+
+ virtual bool CheckSignature(const Buffer& theBuffer, const std::string& theFileName);
+ virtual bool DrawDirtyStuff();
+ virtual void Redraw(Rect* theClipRect);
+
+ // Properties access methods
+ bool LoadProperties(const std::string& theFileName, bool required, bool checkSig);
+ bool LoadProperties();
+ virtual void InitPropertiesHook();
+
+ // Resource access methods
+ void LoadResourceManifest();
+ void ShowResourceError(bool doExit = false);
+
+ bool GetBoolean(const std::string& theId);
+ bool GetBoolean(const std::string& theId, bool theDefault);
+ int GetInteger(const std::string& theId);
+ int GetInteger(const std::string& theId, int theDefault);
+ double GetDouble(const std::string& theId);
+ double GetDouble(const std::string& theId, double theDefault);
+ SexyString GetString(const std::string& theId);
+ SexyString GetString(const std::string& theId, const SexyString& theDefault);
+
+ StringVector GetStringVector(const std::string& theId);
+
+ void SetBoolean(const std::string& theId, bool theValue);
+ void SetInteger(const std::string& theId, int theValue);
+ void SetDouble(const std::string& theId, double theValue);
+ void SetString(const std::string& theId, const std::wstring& theValue);
+
+ // Demo access methods
+ bool PrepareDemoCommand(bool required);
+ void WriteDemoTimingBlock();
+ void WriteDemoBuffer();
+ bool ReadDemoBuffer(std::string &theError);//UNICODE
+ void DemoSyncBuffer(Buffer* theBuffer);
+ void DemoSyncString(std::string* theString);
+ void DemoSyncInt(int* theInt);
+ void DemoSyncBool(bool* theBool);
+ void DemoAssertStringEqual(const std::string& theString);
+ void DemoAssertIntEqual(int theInt);
+ void DemoAddMarker(const std::string& theString);
+ void DemoRegisterHandle(HANDLE theHandle);
+ void DemoWaitForHandle(HANDLE theHandle);
+ bool DemoCheckHandle(HANDLE theHandle);
+
+
+ // Registry access methods
+ bool RegistryGetSubKeys(const std::string& theKeyName, StringVector* theSubKeys);
+ bool RegistryReadString(const std::string& theValueName, std::string* theString);
+ bool RegistryReadInteger(const std::string& theValueName, int* theValue);
+ bool RegistryReadBoolean(const std::string& theValueName, bool* theValue);
+ bool RegistryReadData(const std::string& theValueName, uchar* theValue, ulong* theLength);
+ bool RegistryWriteString(const std::string& theValueName, const std::string& theString);
+ bool RegistryWriteInteger(const std::string& theValueName, int theValue);
+ bool RegistryWriteBoolean(const std::string& theValueName, bool theValue);
+ bool RegistryWriteData(const std::string& theValueName, const uchar* theValue, ulong theLength);
+ bool RegistryEraseKey(const SexyString& theKeyName);
+ void RegistryEraseValue(const SexyString& theValueName);
+
+ // File access methods
+ bool WriteBufferToFile(const std::string& theFileName, const Buffer* theBuffer);
+ bool ReadBufferFromFile(const std::string& theFileName, Buffer* theBuffer, bool dontWriteToDemo = false);//UNICODE
+ bool WriteBytesToFile(const std::string& theFileName, const void *theData, unsigned long theDataLen);
+ bool FileExists(const std::string& theFileName);
+ bool EraseFile(const std::string& theFileName);
+
+ // Misc methods
+ virtual void DoMainLoop();
+ virtual bool UpdateAppStep(bool* updated);
+ virtual bool UpdateApp();
+ int InitDDInterface();
+ void ClearUpdateBacklog(bool relaxForASecond = false);
+ bool IsScreenSaver();
+ virtual bool AppCanRestore();
+ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+};
+
+extern SexyAppBase* gSexyAppBase;
+
+};
+
+#endif //__SEXYAPPBASE_H__
diff --git a/osframework/source/SexyAppFramework/SexyAppBase.vcproj b/osframework/source/SexyAppFramework/SexyAppBase.vcproj
new file mode 100644
index 0000000..8024d4d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyAppBase.vcproj
@@ -0,0 +1,6151 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="SexyAppBase"
+ ProjectGUID="{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_WINDOWS;_VISUALC_;_JPEGLIB_"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug - Zylom|Win32"
+ OutputDirectory="Debug - Zylom"
+ IntermediateDirectory="Debug - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB,ZYLOM"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug - Zylom/"
+ ObjectFile=".\Debug - Zylom/"
+ ProgramDataBaseFileName=".\Debug - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release - Zylom|Win32"
+ OutputDirectory="Release - Zylom"
+ IntermediateDirectory="Release - Zylom"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB,ZYLOM"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release - Zylom/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release - Zylom/"
+ ObjectFile=".\Release - Zylom/"
+ ProgramDataBaseFileName=".\Release - Zylom/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release - Zylom\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Debug - Incremental|Win32"
+ OutputDirectory="Debug - Incremental"
+ IntermediateDirectory="Debug - Incremental"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions=""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Debug\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release noop|Win32"
+ OutputDirectory="Release noop"
+ IntermediateDirectory="Release noop"
+ ConfigurationType="4"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/Oy-"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/SexyAppFramework.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ AdditionalOptions=""
+ OutputFile=".\Release\SexyAppFramework.lib"
+ SuppressStartupBanner="TRUE"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Graphics"
+ Filter="">
+ <Filter
+ Name="Graphics Source"
+ Filter="">
+ <File
+ RelativePath=".\Color.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="D3DTester.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDImage.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DDInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Font.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Graphics.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="GraphicsBuild.cpp">
+ </File>
+ <File
+ RelativePath=".\Image.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ImageFont.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MemoryImage.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="NativeDisplay.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Quantize.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SWTri.cpp">
+ </File>
+ <File
+ RelativePath=".\SysFont.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Graphics Include"
+ Filter="">
+ <File
+ RelativePath=".\Color.h">
+ </File>
+ <File
+ RelativePath="D3DInterface.h">
+ </File>
+ <File
+ RelativePath="D3DTester.h">
+ </File>
+ <File
+ RelativePath=".\DDImage.h">
+ </File>
+ <File
+ RelativePath=".\DDInterface.h">
+ </File>
+ <File
+ RelativePath=".\Font.h">
+ </File>
+ <File
+ RelativePath=".\Graphics.h">
+ </File>
+ <File
+ RelativePath=".\Image.h">
+ </File>
+ <File
+ RelativePath=".\ImageFont.h">
+ </File>
+ <File
+ RelativePath=".\MemoryImage.h">
+ </File>
+ <File
+ RelativePath="NativeDisplay.h">
+ </File>
+ <File
+ RelativePath=".\Quantize.h">
+ </File>
+ <File
+ RelativePath="SWTri.h">
+ </File>
+ <File
+ RelativePath=".\SysFont.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Inc Routines"
+ Filter="">
+ <File
+ RelativePath="BltRotatedHelper.inc">
+ </File>
+ <File
+ RelativePath="DDI_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_AlphaBlt.inc">
+ </File>
+ <File
+ RelativePath="DDI_BltRotated.inc">
+ </File>
+ <File
+ RelativePath="DDI_BltRotated_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastBlt_NoAlpha.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastStretch.inc">
+ </File>
+ <File
+ RelativePath="DDI_FastStretch_Additive.inc">
+ </File>
+ <File
+ RelativePath="DDI_NormalBlt_Volatile.inc">
+ </File>
+ <File
+ RelativePath="MI_AdditiveBlt.inc">
+ </File>
+ <File
+ RelativePath="MI_BltRotated.inc">
+ </File>
+ <File
+ RelativePath="MI_BltRotated_Additive.inc">
+ </File>
+ <File
+ RelativePath="MI_GetNativeAlphaData.inc">
+ </File>
+ <File
+ RelativePath="MI_GetRLAlphaData.inc">
+ </File>
+ <File
+ RelativePath="MI_NormalBlt.inc">
+ </File>
+ <File
+ RelativePath="MI_SlowStretchBlt.inc">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="ImageLib"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\ImageLib.cpp">
+ </File>
+ <File
+ RelativePath="..\ImageLib\ImageLib.h">
+ </File>
+ <Filter
+ Name="PNG"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\png\png.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\png.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngasmrd.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngconf.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngerror.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngget.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngmem.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngpread.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngread.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrtran.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngrutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngset.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngtrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngvcrd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwrite.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwtran.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\png\pngwutil.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG">
+ <File
+ RelativePath="..\ImageLib\jpeg\cderror.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\cdjpeg.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapimin.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcapistd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccoefct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jccolor.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcdctmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jchuff.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcinit.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmainct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmarker.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcmaster.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcomapi.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jconfig.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcparam.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcphuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcprepct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jcsample.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jctrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapimin.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdapistd.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatadst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdatasrc.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcoefct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdcolor.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdct.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jddctmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdhuff.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdinput.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmainct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmarker.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmaster.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdmerge.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdphuff.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdpostct.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdsample.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jdtrans.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jerror.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctflt.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctfst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jfdctint.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctflt.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctfst.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctint.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jidctred.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jinclude.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemmgr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemnobs.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmemsys.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jmorecfg.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpegint.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jpeglib.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant1.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jquant2.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jutils.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\jversion.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdbmp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdcolmap.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdgif.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdppm.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdrle.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdswitch.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\rdtarga.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\transupp.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrbmp.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrgif.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrppm.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrrle.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg\wrtarga.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="ZLIB">
+ <File
+ RelativePath="..\ImageLib\zlib\adler32.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\compress.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\crc32.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\deflate.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\gzio.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infblock.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infcodes.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffast.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inffixed.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inflate.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\inftrees.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\infutil.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\trees.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\uncompr.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zconf.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zlib.h">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.c">
+ </File>
+ <File
+ RelativePath="..\ImageLib\zlib\zutil.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="JPEG2000"
+ Filter="">
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_cm.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_config2.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_debug.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_fix.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_getopt.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_icc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_iccdata.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_image.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_init.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_malloc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_math.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_seq.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_stream.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_string.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_tvp.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_types.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jas_version.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jasper.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jp2_enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_bs.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_cs.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_fix.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_flt.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_math.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mct.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqcod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqdec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_mqenc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_qmfb.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t1enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2cod.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2dec.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_t2enc.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tagtree.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_tsfb.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.c">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\ImageLib\jpeg2000\jpc_util.h">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCustomBuildTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Misc"
+ Filter="">
+ <Filter
+ Name="Misc Source"
+ Filter="">
+ <File
+ RelativePath=".\Buffer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Common.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\CritSect.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Debug.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="DirectXErrorString.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="Flags.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\KeyCodes.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MTRand.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="MiscBuildBase.cpp">
+ </File>
+ <File
+ RelativePath="ModVal.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="PerfTimer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="ResourceManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SexyMatrix.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\XMLParser.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Misc Include"
+ Filter="">
+ <File
+ RelativePath=".\AutoCrit.h">
+ </File>
+ <File
+ RelativePath=".\Buffer.h">
+ </File>
+ <File
+ RelativePath=".\Common.h">
+ </File>
+ <File
+ RelativePath=".\CritSect.h">
+ </File>
+ <File
+ RelativePath=".\Debug.h">
+ </File>
+ <File
+ RelativePath="DirectXErrorString.h">
+ </File>
+ <File
+ RelativePath="Flags.h">
+ </File>
+ <File
+ RelativePath=".\HTTPTransfer.h">
+ </File>
+ <File
+ RelativePath=".\KeyCodes.h">
+ </File>
+ <File
+ RelativePath=".\MTRand.h">
+ </File>
+ <File
+ RelativePath="ModVal.h">
+ </File>
+ <File
+ RelativePath="PerfTimer.h">
+ </File>
+ <File
+ RelativePath=".\Point.h">
+ </File>
+ <File
+ RelativePath=".\PropertiesParser.h">
+ </File>
+ <File
+ RelativePath=".\Rect.h">
+ </File>
+ <File
+ RelativePath="ResourceManager.h">
+ </File>
+ <File
+ RelativePath=".\SEHCatcher.h">
+ </File>
+ <File
+ RelativePath="SexyMatrix.h">
+ </File>
+ <File
+ RelativePath="SexyVector.h">
+ </File>
+ <File
+ RelativePath="SmartPtr.h">
+ </File>
+ <File
+ RelativePath=".\XMLParser.h">
+ </File>
+ <File
+ RelativePath="memmgr.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Sound"
+ Filter="">
+ <Filter
+ Name="Sound Source"
+ Filter="">
+ <File
+ RelativePath="BassLoader.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="BassLoader.h">
+ </File>
+ <File
+ RelativePath="BassMusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DSoundManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FModLoader.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Insets.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\MusicInterface.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="SoundBuild.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Sound Include"
+ Filter="">
+ <File
+ RelativePath="BassMusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\DSoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\DSoundManager.h">
+ </File>
+ <File
+ RelativePath="FModLoader.h">
+ </File>
+ <File
+ RelativePath=".\FModMusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\FModSoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\FModSoundManager.h">
+ </File>
+ <File
+ RelativePath=".\MusicInterface.h">
+ </File>
+ <File
+ RelativePath=".\SoundInstance.h">
+ </File>
+ <File
+ RelativePath=".\SoundManager.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Ogg"
+ Filter="">
+ <File
+ RelativePath="ogg\asm_arm.h">
+ </File>
+ <File
+ RelativePath="ogg\backends.h">
+ </File>
+ <File
+ RelativePath="ogg\bitwise.c">
+ </File>
+ <File
+ RelativePath="ogg\block.c">
+ </File>
+ <File
+ RelativePath="ogg\codebook.c">
+ </File>
+ <File
+ RelativePath="ogg\codebook.h">
+ </File>
+ <File
+ RelativePath="ogg\codec_internal.h">
+ </File>
+ <File
+ RelativePath="ogg\config_types.h">
+ </File>
+ <File
+ RelativePath="ogg\floor0.c">
+ </File>
+ <File
+ RelativePath="ogg\floor1.c">
+ </File>
+ <File
+ RelativePath="ogg\framing.c">
+ </File>
+ <File
+ RelativePath="ogg\info.c">
+ </File>
+ <File
+ RelativePath="ogg\ivorbiscodec.h">
+ </File>
+ <File
+ RelativePath="ogg\ivorbisfile.h">
+ </File>
+ <File
+ RelativePath="ogg\lsp_lookup.h">
+ </File>
+ <File
+ RelativePath="ogg\mapping0.c">
+ </File>
+ <File
+ RelativePath="ogg\mdct.c">
+ </File>
+ <File
+ RelativePath="ogg\mdct.h">
+ </File>
+ <File
+ RelativePath="ogg\mdct_lookup.h">
+ </File>
+ <File
+ RelativePath="ogg\misc.h">
+ </File>
+ <File
+ RelativePath="ogg\ogg.h">
+ </File>
+ <File
+ RelativePath="ogg\os.h">
+ </File>
+ <File
+ RelativePath="ogg\os_types.h">
+ </File>
+ <File
+ RelativePath="ogg\registry.c">
+ </File>
+ <File
+ RelativePath="ogg\registry.h">
+ </File>
+ <File
+ RelativePath="ogg\res012.c">
+ </File>
+ <File
+ RelativePath="ogg\sharedbook.c">
+ </File>
+ <File
+ RelativePath="ogg\synthesis.c">
+ </File>
+ <File
+ RelativePath="ogg\vorbisfile.c">
+ </File>
+ <File
+ RelativePath="ogg\window.c">
+ </File>
+ <File
+ RelativePath="ogg\window.h">
+ </File>
+ <File
+ RelativePath="ogg\window_lookup.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Widget"
+ Filter="">
+ <Filter
+ Name="Widget Source"
+ Filter="">
+ <File
+ RelativePath=".\ButtonWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Checkbox.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Dialog.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\DialogButton.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\EditWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="FlashWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ListWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Slider.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\TextWidget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Widget.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="WidgetBuildBase.cpp">
+ </File>
+ <File
+ RelativePath="WidgetContainer.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\WidgetManager.cpp">
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release - Zylom|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug - Incremental|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release noop|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Widget Include"
+ Filter="">
+ <File
+ RelativePath=".\ButtonListener.h">
+ </File>
+ <File
+ RelativePath=".\ButtonWidget.h">
+ </File>
+ <File
+ RelativePath=".\Checkbox.h">
+ </File>
+ <File
+ RelativePath=".\CheckboxListener.h">
+ </File>
+ <File
+ RelativePath=".\Dialog.h">
+ </File>
+ <File
+ RelativePath=".\DialogButton.h">
+ </File>
+ <File
+ RelativePath="DialogListener.h">
+ </File>
+ <File
+ RelativePath=".\EditListener.h">
+ </File>
+ <File
+ RelativePath=".\EditWidget.h">
+ </File>
+ <File
+ RelativePath="FlashWidget.h">
+ </File>
+ <File
+ RelativePath=".\HyperlinkWidget.h">
+ </File>
+ <File
+ RelativePath=".\Insets.h">
+ </File>
+ <File
+ RelativePath=".\ListListener.h">
+ </File>
+ <File
+ RelativePath=".\ListWidget.h">
+ </File>
+ <File
+ RelativePath=".\ScrollListener.h">
+ </File>
+ <File
+ RelativePath=".\ScrollbarWidget.h">
+ </File>
+ <File
+ RelativePath=".\ScrollbuttonWidget.h">
+ </File>
+ <File
+ RelativePath=".\Slider.h">
+ </File>
+ <File
+ RelativePath=".\SliderListener.h">
+ </File>
+ <File
+ RelativePath=".\TextWidget.h">
+ </File>
+ <File
+ RelativePath=".\Widget.h">
+ </File>
+ <File
+ RelativePath="WidgetContainer.h">
+ </File>
+ <File
+ RelativePath=".\WidgetManager.h">
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="PakLib"
+ Filter="">
+ <File
+ RelativePath="..\PakLib\PakInterface.cpp">
+ </File>
+ <File
+ RelativePath="..\PakLib\PakInterface.h">
+ </File>
+ </Filter>
+ <File
+ RelativePath="SexyAppBase.cpp">
+ </File>
+ <File
+ RelativePath="SexyAppBase.h">
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/SexyAppFramework/SexyMatrix.cpp b/osframework/source/SexyAppFramework/SexyMatrix.cpp
new file mode 100644
index 0000000..8662595
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyMatrix.cpp
@@ -0,0 +1,295 @@
+#include "SexyMatrix.h"
+
+#include <math.h>
+
+using namespace Sexy;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyMatrix3::SexyMatrix3()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyMatrix3::ZeroMatrix()
+{
+ m00 = m01 = m02 =
+ m10 = m11 = m12 =
+ m20 = m21 = m22 = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyMatrix3::LoadIdentity()
+{
+ m01 = m02 = m10 = m12 = m20 = m21 = 0;
+ m00 = m11 = m22 = 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyMatrix3 SexyMatrix3::operator*(const SexyMatrix3 &theMat) const
+{
+ SexyMatrix3 aResult;
+
+ for(int i=0; i<3; i++)
+ {
+ for(int j=0; j<3; j++)
+ {
+ float x = 0;
+ for(int k=0; k<3; k++)
+ x += m[i][k]*theMat.m[k][j];
+
+ aResult.m[i][j] = x;
+ }
+ }
+
+ return aResult;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyVector2 SexyMatrix3::operator*(const SexyVector2 &theVec) const
+{
+ return SexyVector2(
+ m00*theVec.x + m01*theVec.y + m02,
+ m10*theVec.x + m11*theVec.y + m12);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyVector3 SexyMatrix3::operator*(const SexyVector3 &theVec) const
+{
+ return SexyVector3(
+ m00*theVec.x + m01*theVec.y + m02*theVec.z,
+ m10*theVec.x + m11*theVec.y + m12*theVec.z,
+ m20*theVec.x + m21*theVec.y + m22*theVec.z);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const SexyMatrix3& SexyMatrix3::operator*=(const SexyMatrix3 &theMat)
+{
+ return operator=(operator*(theMat));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyTransform2D::SexyTransform2D()
+{
+ LoadIdentity();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyTransform2D::SexyTransform2D(bool loadIdentity)
+{
+ if (loadIdentity)
+ LoadIdentity();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SexyTransform2D::SexyTransform2D(const SexyMatrix3& theMatrix) : SexyMatrix3(theMatrix)
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const SexyTransform2D& SexyTransform2D::operator=(const SexyMatrix3 &theMat)
+{
+ SexyMatrix3::operator=(theMat);
+ return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyTransform2D::Translate(float tx, float ty)
+{
+ SexyMatrix3 aMat;
+ aMat.LoadIdentity();
+ aMat.m02 = tx;
+ aMat.m12 = ty;
+ aMat.m22 = 1;
+
+ *this = aMat * (*this);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyTransform2D::RotateRad(float rot)
+{
+ SexyMatrix3 aMat;
+ aMat.LoadIdentity();
+
+ float sinRot = -sinf(rot);
+ float cosRot = cosf(rot);
+
+ aMat.m00 = cosRot;
+ aMat.m01 = -sinRot;
+ aMat.m10 = sinRot;
+ aMat.m11 = cosRot;
+
+ *this = aMat * (*this);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyTransform2D::RotateDeg(float rot)
+{
+ RotateRad(3.1415926535897932384626433832795028841971f * rot / 180.0f);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SexyTransform2D::Scale(float sx, float sy)
+{
+ SexyMatrix3 aMat;
+ aMat.LoadIdentity();
+ aMat.m00 = sx;
+ aMat.m11 = sy;
+
+ *this = aMat * (*this);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+Transform::Transform() : mMatrix(false)
+{
+ Reset();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::Reset()
+{
+ mNeedCalcMatrix = true;
+ mComplex = false;
+ mTransX1 = mTransY1 = 0;
+ mTransX2 = mTransY2 = 0;
+ mScaleX = mScaleY = 1;
+ mRot = 0;
+ mHaveRot = false;
+ mHaveScale = false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::Translate(float tx, float ty)
+{
+ if (!mComplex)
+ {
+ mNeedCalcMatrix = true;
+ if (mHaveRot || mHaveScale)
+ {
+ mTransX2 += tx;
+ mTransY2 += ty;
+ }
+ else
+ {
+ mTransX1 += tx;
+ mTransY1 += ty;
+ }
+ }
+ else
+ mMatrix.Translate(tx,ty);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::RotateRad(float rot)
+{
+ if (!mComplex)
+ {
+ if (mHaveScale)
+ {
+ MakeComplex();
+ mMatrix.RotateRad(rot);
+ }
+ else
+ {
+ mNeedCalcMatrix = true;
+ mHaveRot = true;
+ mRot += rot;
+ }
+ }
+ else
+ mMatrix.RotateRad(rot);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::RotateDeg(float rot)
+{
+ Transform::RotateRad(3.1415926535897932384626433832795028841971f * rot / 180.0f);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::Scale(float sx, float sy)
+{
+ if (!mComplex)
+ {
+ if (mHaveRot || mTransX1!=0 || mTransY1!=0 || (sx<0 && mScaleX*sx!=-1) || sy<0)
+ {
+ MakeComplex();
+ mMatrix.Scale(sx,sy);
+ }
+ else
+ {
+ mNeedCalcMatrix = true;
+ mHaveScale = true;
+ mScaleX *= sx;
+ mScaleY *= sy;
+ }
+ }
+ else
+ mMatrix.Scale(sx,sy);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::MakeComplex()
+{
+ if (!mComplex)
+ {
+ mComplex = true;
+ CalcMatrix();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void Transform::CalcMatrix() const
+{
+ if (mNeedCalcMatrix)
+ {
+ mNeedCalcMatrix = false;
+
+ mMatrix.LoadIdentity();
+ mMatrix.m02 = mTransX1;
+ mMatrix.m12 = mTransY1;
+ mMatrix.m22 = 1;
+
+ if (mHaveScale)
+ {
+ mMatrix.m00 = mScaleX;
+ mMatrix.m11 = mScaleY;
+ }
+ else if (mHaveRot)
+ mMatrix.RotateRad(mRot);
+
+ if (mTransX2!=0 || mTransY2!=0)
+ mMatrix.Translate(mTransX2,mTransY2);
+ }
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const SexyTransform2D& Transform::GetMatrix() const
+{
+ CalcMatrix();
+ return mMatrix;
+}
diff --git a/osframework/source/SexyAppFramework/SexyMatrix.h b/osframework/source/SexyAppFramework/SexyMatrix.h
new file mode 100644
index 0000000..e288333
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyMatrix.h
@@ -0,0 +1,91 @@
+#ifndef __SEXYMATRIX_H__
+#define __SEXYMATRIX_H__
+
+#include "SexyVector.h"
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyMatrix3
+{
+public:
+ union
+ {
+ float m[3][3];
+ struct
+ {
+ float m00, m01, m02;
+ float m10, m11, m12;
+ float m20, m21, m22;
+ };
+ };
+
+public:
+ SexyMatrix3();
+ void ZeroMatrix();
+ void LoadIdentity();
+
+ SexyVector2 operator*(const SexyVector2 &theVec) const;
+ SexyVector3 operator*(const SexyVector3 &theVec) const;
+ SexyMatrix3 operator*(const SexyMatrix3 &theMat) const;
+ const SexyMatrix3& operator*=(const SexyMatrix3 &theMat);
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyTransform2D : public SexyMatrix3
+{
+public:
+ SexyTransform2D();
+ SexyTransform2D(bool loadIdentity);
+ SexyTransform2D(const SexyMatrix3& theMatrix);
+
+ const SexyTransform2D& operator=(const SexyMatrix3 &theMat);
+
+
+ void Translate(float tx, float ty);
+
+ // Rotate has been replaced by RotateRad.
+ // NOTE: If you had Rotate(angle) you should now use RotateRad(-angle).
+ // This is to make positive rotations go counter-clockwise when using screen coordinates.
+ void RotateRad(float rot);
+ void RotateDeg(float rot);
+ void Scale(float sx, float sy);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class Transform
+{
+protected:
+ mutable SexyTransform2D mMatrix;
+ mutable bool mNeedCalcMatrix;
+ void MakeComplex();
+ void CalcMatrix() const;
+
+public:
+ bool mComplex, mHaveRot, mHaveScale;
+ float mTransX1, mTransY1, mTransX2, mTransY2;
+ float mScaleX, mScaleY;
+ float mRot;
+
+public:
+ Transform();
+
+ void Reset();
+
+ void Translate(float tx, float ty);
+ void RotateRad(float rot);
+ void RotateDeg(float rot);
+ void Scale(float sx, float sy);
+
+ const SexyTransform2D& GetMatrix() const;
+};
+
+
+} // namespace Sexy
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SexyVector.h b/osframework/source/SexyAppFramework/SexyVector.h
new file mode 100644
index 0000000..36d4b40
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SexyVector.h
@@ -0,0 +1,77 @@
+#ifndef __SEXYVECTOR_H__
+#define __SEXYVECTOR_H__
+
+#include <math.h>
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyVector2
+{
+public:
+ float x,y;
+
+public:
+ SexyVector2() : x(0), y(0) { }
+ SexyVector2(float theX, float theY) : x(theX), y(theY) { }
+
+ float Dot(const SexyVector2 &v) const { return x*v.x + y*v.y; }
+ SexyVector2 operator+(const SexyVector2 &v) const { return SexyVector2(x+v.x, y+v.y); }
+ SexyVector2 operator-(const SexyVector2 &v) const { return SexyVector2(x-v.x, y-v.y); }
+ SexyVector2 operator-() const { return SexyVector2(-x, -y); }
+ SexyVector2 operator*(float t) const { return SexyVector2(t*x, t*y); }
+ SexyVector2 operator/(float t) const { return SexyVector2(x/t, y/t); }
+ void operator+=(const SexyVector2 &v) { x+=v.x; y+=v.y; }
+ void operator-=(const SexyVector2 &v) { x-=v.x; y-=v.y; }
+ void operator*=(float t) { x*=t; y*=t; }
+ void operator/=(float t) { x/=t; y/=t; }
+
+ bool operator==(const SexyVector2 &v) { return x==v.x && y==v.y; }
+ bool operator!=(const SexyVector2 &v) { return x!=v.x || y!=v.y; }
+
+ float Magnitude() const { return sqrtf(x*x + y*y); }
+ float MagnitudeSquared() const { return x*x+y*y; }
+
+ SexyVector2 Normalize() const
+ {
+ float aMag = Magnitude();
+ return aMag!=0 ? (*this)/aMag : *this;
+ }
+
+ SexyVector2 Perp() const
+ {
+ return SexyVector2(-y, x);
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class SexyVector3
+{
+public:
+ float x,y,z;
+
+public:
+ SexyVector3() : x(0), y(0), z(0) { }
+ SexyVector3(float theX, float theY, float theZ) : x(theX), y(theY), z(theZ) { }
+
+ float Dot(const SexyVector3 &v) const { return x*v.x + y*v.y + z*v.z; }
+ SexyVector3 Cross(const SexyVector3 &v) const { return SexyVector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); }
+ SexyVector3 operator+(const SexyVector3 &v) const { return SexyVector3(x+v.x, y+v.y, z+v.z); }
+ SexyVector3 operator-(const SexyVector3 &v) const { return SexyVector3(x-v.x, y-v.y, z-v.z); }
+ SexyVector3 operator*(float t) const { return SexyVector3(t*x, t*y, t*z); }
+ SexyVector3 operator/(float t) const { return SexyVector3(x/t, y/t, z/t); }
+ float Magnitude() const { return sqrtf(x*x + y*y + z*z); }
+
+ SexyVector3 Normalize() const
+ {
+ float aMag = Magnitude();
+ return aMag!=0 ? (*this)/aMag : *this;
+ }
+};
+
+};
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SharedImage.cpp b/osframework/source/SexyAppFramework/SharedImage.cpp
new file mode 100644
index 0000000..9e3693a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SharedImage.cpp
@@ -0,0 +1,106 @@
+#include "SharedImage.h"
+#include "DDImage.h"
+#include "SexyAppBase.h"
+
+using namespace Sexy;
+
+SharedImage::SharedImage()
+{
+ mImage = NULL;
+ mRefCount = 0;
+}
+
+SharedImageRef::SharedImageRef(const SharedImageRef& theSharedImageRef)
+{
+ mSharedImage = theSharedImageRef.mSharedImage;
+ if (mSharedImage != NULL)
+ mSharedImage->mRefCount++;
+ mUnsharedImage = theSharedImageRef.mUnsharedImage;
+ mOwnsUnshared = false;
+}
+
+SharedImageRef::SharedImageRef()
+{
+ mSharedImage = NULL;
+ mUnsharedImage = NULL;
+ mOwnsUnshared = false;
+}
+
+SharedImageRef::SharedImageRef(SharedImage* theSharedImage)
+{
+ mSharedImage = theSharedImage;
+ if (theSharedImage != NULL)
+ mSharedImage->mRefCount++;
+
+ mUnsharedImage = NULL;
+ mOwnsUnshared = false;
+}
+
+SharedImageRef::~SharedImageRef()
+{
+ Release();
+}
+
+void SharedImageRef::Release()
+{
+ if (mOwnsUnshared)
+ delete mUnsharedImage;
+ mUnsharedImage = NULL;
+ if (mSharedImage != NULL)
+ {
+ if (--mSharedImage->mRefCount == 0)
+ gSexyAppBase->mCleanupSharedImages = true;
+ }
+ mSharedImage = NULL;
+}
+
+SharedImageRef& SharedImageRef::operator=(const SharedImageRef& theSharedImageRef)
+{
+ Release();
+ mSharedImage = theSharedImageRef.mSharedImage;
+ if (mSharedImage != NULL)
+ mSharedImage->mRefCount++;
+ return *this;
+}
+
+SharedImageRef& SharedImageRef::operator=(SharedImage* theSharedImage)
+{
+ Release();
+ mSharedImage = theSharedImage;
+ mSharedImage->mRefCount++;
+ return *this;
+}
+
+SharedImageRef& SharedImageRef::operator=(MemoryImage* theUnsharedImage)
+{
+ Release();
+ mUnsharedImage = theUnsharedImage;
+ return *this;
+}
+
+MemoryImage* SharedImageRef::operator->()
+{
+ return (MemoryImage*) *this;
+}
+
+
+SharedImageRef::operator Image*()
+{
+ return (MemoryImage*) *this;
+}
+
+SharedImageRef::operator MemoryImage*()
+{
+ if (mUnsharedImage != NULL)
+ return mUnsharedImage;
+ else
+ return (DDImage*) *this;
+}
+
+SharedImageRef::operator DDImage*()
+{
+ if (mSharedImage != NULL)
+ return mSharedImage->mImage;
+ else
+ return NULL;
+}
diff --git a/osframework/source/SexyAppFramework/SharedImage.h b/osframework/source/SexyAppFramework/SharedImage.h
new file mode 100644
index 0000000..b35ef98
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SharedImage.h
@@ -0,0 +1,50 @@
+#ifndef __SHARED_IMAGE_H__
+#define __SHARED_IMAGE_H__
+
+#include "Common.h"
+
+namespace Sexy
+{
+
+class Image;
+class DDImage;
+class MemoryImage;
+
+class SharedImage
+{
+public:
+ DDImage* mImage;
+ int mRefCount;
+
+ SharedImage();
+};
+
+typedef std::map<std::pair<std::string, std::string>, SharedImage> SharedImageMap;
+
+class SharedImageRef
+{
+public:
+ SharedImage* mSharedImage;
+ MemoryImage* mUnsharedImage;
+ bool mOwnsUnshared;
+
+public:
+ SharedImageRef();
+ SharedImageRef(const SharedImageRef& theSharedImageRef);
+ SharedImageRef(SharedImage* theSharedImage);
+ ~SharedImageRef();
+
+ void Release();
+
+ SharedImageRef& operator=(const SharedImageRef& theSharedImageRef);
+ SharedImageRef& operator=(SharedImage* theSharedImage);
+ SharedImageRef& operator=(MemoryImage* theUnsharedImage);
+ MemoryImage* operator->();
+ operator Image*();
+ operator MemoryImage*();
+ operator DDImage*();
+};
+
+}
+
+#endif //__SHARED_IMAGE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Slider.cpp b/osframework/source/SexyAppFramework/Slider.cpp
new file mode 100644
index 0000000..576bedc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Slider.cpp
@@ -0,0 +1,174 @@
+#include "Slider.h"
+#include "Graphics.h"
+#include "Image.h"
+#include "SliderListener.h"
+#include "WidgetManager.h"
+#include "SexyAppBase.h"
+
+using namespace Sexy;
+
+Slider::Slider(Image* theTrackImage, Image* theThumbImage, int theId, SliderListener* theListener) :
+ mTrackImage(theTrackImage),
+ mThumbImage(theThumbImage),
+ mId(theId),
+ mListener(theListener),
+ mVal(0.0)
+{
+ mDragging = false;
+ mHorizontal = true;
+ mRelX = mRelY = 0;
+}
+
+void Slider::SetValue(double theValue)
+{
+ mVal = theValue;
+ if (mVal < 0.0)
+ mVal = 0.0;
+ else if (mVal > 1.0)
+ mVal = 1.0;
+
+ MarkDirtyFull();
+}
+
+bool Slider::HasTransparencies()
+{
+ return true;
+}
+
+void Slider::Draw(Graphics* g)
+{
+ if (mTrackImage != NULL)
+ {
+ int cw = mHorizontal ? mTrackImage->GetWidth()/3 : mTrackImage->GetWidth();
+ int ch = mHorizontal ? mTrackImage->GetHeight() : mTrackImage->GetHeight()/3;
+
+ if (mHorizontal)
+ {
+ int ty = (mHeight - ch) / 2;
+
+ g->DrawImage(mTrackImage, 0, ty, Rect(0, 0, cw, ch));
+
+ Graphics aClipG(*g);
+ aClipG.ClipRect(cw, ty, mWidth - cw*2, ch);
+ for (int i = 0; i < (mWidth-cw*2+cw-1)/cw; i++)
+ aClipG.DrawImage(mTrackImage, cw + i*cw, ty, Rect(cw, 0, cw, ch));
+
+ g->DrawImage(mTrackImage, mWidth-cw, ty, Rect(cw*2, 0, cw, ch));
+ }
+ else
+ {
+ g->DrawImage(mTrackImage, 0, 0, Rect(0, 0, cw, ch));
+ Graphics aClipG(*g);
+ aClipG.ClipRect(0, ch, cw, mHeight - ch * 2);
+ for (int i = 0; i < (mHeight-ch*2+ch-1)/ch; i++)
+ aClipG.DrawImage(mTrackImage, 0, ch + i*ch, Rect(0, ch, cw, ch));
+
+ g->DrawImage(mTrackImage, 0, mHeight-ch, Rect(0, ch*2, cw, ch));
+ }
+ }
+
+ if (mHorizontal && (mThumbImage != NULL))
+ g->DrawImage(mThumbImage, (int) (mVal * (mWidth - mThumbImage->GetWidth())), (mHeight - mThumbImage->GetHeight()) / 2);
+ else if (!mHorizontal && (mThumbImage != NULL))
+ g->DrawImage(mThumbImage, (mWidth - mThumbImage->GetWidth()) / 2, (int) (mVal * (mHeight - mThumbImage->GetHeight())));
+
+ //g->SetColor(Color(255, 255, 0));
+ //g->FillRect(0, 0, mWidth, mHeight);
+}
+
+void Slider::MouseDown(int x, int y, int theClickCount)
+{
+ if (mHorizontal)
+ {
+ int aThumbX = (int) (mVal * (mWidth - mThumbImage->GetWidth()));
+
+ if ((x >= aThumbX) && (x < aThumbX + mThumbImage->GetWidth()))
+ {
+ mWidgetManager->mApp->SetCursor(CURSOR_DRAGGING);
+ mDragging = true;
+ mRelX = x - aThumbX;
+ }
+ else
+ {
+ // clicked on the bar, set position to mouse click
+ double pos = (double)x / mWidth;
+ SetValue(pos);
+ }
+ }
+ else
+ {
+ int aThumbY = (int) (mVal * (mHeight - mThumbImage->GetHeight()));
+
+ if ((y >= aThumbY) && (y < aThumbY + mThumbImage->GetHeight()))
+ {
+ mWidgetManager->mApp->SetCursor(CURSOR_DRAGGING);
+ mDragging = true;
+ mRelY = y - aThumbY;
+ }
+ else
+ {
+ // clicked on the bar, set position to mouse click
+ double pos = (double)y / mHeight;
+ SetValue(pos);
+ }
+ }
+}
+
+void Slider::MouseMove(int x, int y)
+{
+ if (mHorizontal)
+ {
+ int aThumbX = (int) (mVal * (mWidth - mThumbImage->GetWidth()));
+
+ if ((x >= aThumbX) && (x < aThumbX + mThumbImage->GetWidth()))
+ mWidgetManager->mApp->SetCursor(CURSOR_DRAGGING);
+ else
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+ }
+ else
+ {
+ int aThumbY = (int) (mVal * (mHeight - mThumbImage->GetHeight()));
+
+ if ((y >= aThumbY) && (y < aThumbY + mThumbImage->GetHeight()))
+ mWidgetManager->mApp->SetCursor(CURSOR_DRAGGING);
+ else
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+ }
+}
+
+void Slider::MouseDrag(int x, int y)
+{
+ if (mDragging)
+ {
+ double anOldVal = mVal;
+
+ if (mHorizontal)
+ mVal = (x - mRelX) / (double) (mWidth - mThumbImage->GetWidth());
+ else
+ mVal = (y - mRelY) / (double) (mHeight - mThumbImage->GetHeight());
+
+ if (mVal < 0.0)
+ mVal = 0.0;
+ if (mVal > 1.0)
+ mVal = 1.0;
+
+ if (mVal != anOldVal)
+ {
+ mListener->SliderVal(mId, mVal);
+ MarkDirtyFull();
+ }
+ }
+}
+
+void Slider::MouseUp(int x, int y)
+{
+ mDragging = false;
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+ mListener->SliderVal(mId, mVal);
+}
+
+void Slider::MouseLeave()
+{
+ if (!mDragging)
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Slider.h b/osframework/source/SexyAppFramework/Slider.h
new file mode 100644
index 0000000..6932c3a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Slider.h
@@ -0,0 +1,43 @@
+#ifndef __SLIDER_H__
+#define __SLIDER_H__
+
+#include "Widget.h"
+
+namespace Sexy
+{
+
+class SliderListener;
+
+class Slider : public Widget
+{
+public:
+ SliderListener* mListener;
+ double mVal;
+ int mId;
+ Image* mTrackImage;
+ Image* mThumbImage;
+
+ bool mDragging;
+ int mRelX;
+ int mRelY;
+
+ bool mHorizontal;
+
+public:
+ Slider(Image* theTrackImage, Image* theThumbImage, int theId, SliderListener* theListener);
+
+ virtual void SetValue(double theValue);
+
+ virtual bool HasTransparencies();
+ virtual void Draw(Graphics* g);
+
+ virtual void MouseMove(int x, int y);
+ virtual void MouseDown(int x, int y, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+ virtual void MouseUp(int x, int y);
+ virtual void MouseLeave();
+};
+
+}
+
+#endif //__SLIDER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SliderListener.h b/osframework/source/SexyAppFramework/SliderListener.h
new file mode 100644
index 0000000..1f16a02
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SliderListener.h
@@ -0,0 +1,15 @@
+#ifndef __SLIDERLISTENER_H__
+#define __SLIDERLISTENER_H__
+
+namespace Sexy
+{
+
+class SliderListener
+{
+public:
+ virtual void SliderVal(int theId, double theVal) {};
+};
+
+}
+
+#endif //__SLIDERLISTENER_H__
diff --git a/osframework/source/SexyAppFramework/SmartPtr.h b/osframework/source/SexyAppFramework/SmartPtr.h
new file mode 100644
index 0000000..49c8f04
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SmartPtr.h
@@ -0,0 +1,146 @@
+#ifndef __SEXY_SMARTPTR_H__
+#define __SEXY_SMARTPTR_H__
+#include "Common.h"
+
+#pragma pack(push,8) // need 8 byte alignment for InterlockedIncrement
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+class RefCount
+{
+private:
+ mutable long mRefCount;
+
+protected:
+ // The compiler allows a derived destructor to be called if it's not explicitly declared
+ // even if the parent destructor is private, so I make the parent destructor protected so that
+ // derived classes can make their destructors protected as well. (They get an error if the
+ // parent destructor is private.)
+ virtual ~RefCount() {}
+
+public:
+ RefCount() : mRefCount(0) {}
+
+ const RefCount* CreateRef() const
+ {
+ InterlockedIncrement(&mRefCount);
+ return this;
+ }
+
+ void Release()
+ {
+ if(InterlockedDecrement(&mRefCount)<=0)
+ delete this;
+ }
+
+ // You might want to assign one reference counted object to another simply to copy
+ // the member variables of one to the other, but you certainly don't want to copy
+ // the reference counts!
+ RefCount(const RefCount&) : mRefCount(0) {}
+ RefCount& operator=(const RefCount&) { return *this; }
+
+ unsigned long GetRefCount() { return mRefCount; }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+// Const smart pointer. Automatically performs reference counting on objects which
+// implement the CreateRef and Release interface. Allows const access to underlying object.
+template <class T> class ConstSmartPtr
+{
+protected:
+ T *p;
+
+public:
+ ConstSmartPtr() : p(NULL) {}
+
+ // Copy constructor. Assign and add reference to underlying object.
+ ConstSmartPtr(const T* theObject) : p((T*)(theObject?theObject->CreateRef():NULL)) {}
+ ConstSmartPtr(const ConstSmartPtr& theCopy) : p((T*)(theCopy?theCopy.p->CreateRef():NULL)){}
+
+ // Destructor. Remove reference to underlying object.
+ ~ConstSmartPtr() { if(p!=NULL) p->Release(); }
+
+ // Arrow operator allows ConstSmartPtr to be treated like actual pointer.
+ const T* operator->() const { return p; }
+
+ // Type case operator allows ConstSmartPtr to be cast to const T*,
+ operator const T*() const { return p; }
+
+ // Assignment operator. Release old underlying object if not null. Add reference to new object.
+ const T* operator=(const T* thePtr)
+ {
+ if(p!=thePtr) // prevent self-assignment
+ {
+ if(p!=NULL) p->Release();
+ p = (T*)(thePtr?thePtr->CreateRef():NULL);
+ }
+
+ return thePtr;
+ }
+
+ const ConstSmartPtr& operator=(const ConstSmartPtr& theCopy)
+ {
+ operator=(theCopy.get());
+ return *this;
+ }
+
+ // Allow comparions just like normal pointer.
+ bool operator==(const T* thePtr) const { return p==thePtr; }
+ bool operator!=(const T* thePtr) const { return p!=thePtr; }
+ bool operator<(const T *thePtr) const { return p < thePtr; }
+
+ // Accessor to actual object
+ const T* get() const { return p; }
+
+ struct Comp { bool operator()(const ConstSmartPtr &a, const ConstSmartPtr &b) const { return a.get()<b.get(); } };
+};
+
+
+// Smart pointer. Automatically performs reference counting on objects which
+// implement the CreateRef and Release interface. Allows non-const access to underlying object.
+template <class T> class SmartPtr : public ConstSmartPtr<T>
+{
+public:
+ SmartPtr() {}
+ SmartPtr(T* theObject) : ConstSmartPtr<T>(theObject){}
+ SmartPtr(const SmartPtr& theCopy) : ConstSmartPtr<T>(theCopy.p) {}
+
+ const SmartPtr& operator=(const SmartPtr& theCopy)
+ {
+ ConstSmartPtr<T>::operator=(theCopy.get());
+ return *this;
+ }
+
+ T* operator=(T* thePtr)
+ {
+ ConstSmartPtr<T>::operator =(thePtr);
+ return thePtr;
+ }
+
+
+ T* operator->() const { return p; }
+ operator T*() const { return p; }
+
+ T* get() const { return p; }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+typedef SmartPtr<RefCount> RefCountPtr;
+
+} // namespace Sexy
+
+#pragma pack(pop)
+
+// Helper macro to forward declare reference counted classes along with their smart pointer definitions
+#define SEXY_PTR_FORWARD(X) class X; typedef SmartPtr<X> X##Ptr
+#define SEXY_PTR_FORWARDNS(X) class X; typedef Sexy::SmartPtr<X> X##Ptr
+
+#endif
diff --git a/osframework/source/SexyAppFramework/SoundBuild.cpp b/osframework/source/SexyAppFramework/SoundBuild.cpp
new file mode 100644
index 0000000..081a07b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SoundBuild.cpp
@@ -0,0 +1,9 @@
+#include "DSoundManager.cpp" // build first because this defines DIRECTSOUND_VERSION to 0x0600
+
+#include "DSoundInstance.cpp"
+#include "BassLoader.cpp"
+#include "BassMusicInterface.cpp"
+#include "FModLoader.cpp"
+#include "FModMusicInterface.cpp"
+#include "FModSoundInstance.cpp"
+#include "MusicInterface.cpp"
diff --git a/osframework/source/SexyAppFramework/SoundInstance.h b/osframework/source/SexyAppFramework/SoundInstance.h
new file mode 100644
index 0000000..012cd80
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SoundInstance.h
@@ -0,0 +1,34 @@
+#ifndef __SOUNDINSTANCE_H__
+#define __SOUNDINSTANCE_H__
+
+#include <windows.h>
+#include "Common.h"
+
+namespace Sexy
+{
+
+class SoundInstance
+{
+public:
+ SoundInstance() {}
+ virtual ~SoundInstance() {}
+ virtual void Release() = NULL;
+
+ virtual void SetBaseVolume(double theBaseVolume) = NULL;
+ virtual void SetBasePan(int theBasePan) = NULL;
+
+ virtual void AdjustPitch(double theNumSteps) = NULL;
+
+ virtual void SetVolume(double theVolume) = NULL;
+ virtual void SetPan(int thePosition) = NULL; //-hundredth db to +hundredth db = left to right
+
+ virtual bool Play(bool looping, bool autoRelease) = NULL;
+ virtual void Stop() = NULL;
+ virtual bool IsPlaying() = NULL;
+ virtual bool IsReleased() = NULL;
+ virtual double GetVolume() = NULL;
+};
+
+}
+
+#endif //__SOUNDINSTANCE_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SoundManager.h b/osframework/source/SexyAppFramework/SoundManager.h
new file mode 100644
index 0000000..3f7159e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SoundManager.h
@@ -0,0 +1,50 @@
+#ifndef __SOUNDMANAGER_H__
+#define __SOUNDMANAGER_H__
+
+#include <windows.h>
+#include "Common.h"
+
+namespace Sexy
+{
+
+class SoundInstance;
+
+#define MAX_SOURCE_SOUNDS 256
+#define MAX_CHANNELS 32
+
+class SoundManager
+{
+public:
+ SoundManager() {}
+ virtual ~SoundManager() {}
+
+ virtual bool Initialized() = NULL;
+
+ virtual bool LoadSound(unsigned int theSfxID, const std::string& theFilename) = NULL;
+ virtual int LoadSound(const std::string& theFilename) = NULL;
+ virtual void ReleaseSound(unsigned int theSfxID) = NULL;
+
+ virtual void SetVolume(double theVolume) = NULL;
+ virtual bool SetBaseVolume(unsigned int theSfxID, double theBaseVolume) = NULL;
+ virtual bool SetBasePan(unsigned int theSfxID, int theBasePan) = NULL;
+
+ virtual SoundInstance* GetSoundInstance(unsigned int theSfxID) = NULL;
+
+ virtual void ReleaseSounds() = NULL;
+ virtual void ReleaseChannels() = NULL;
+
+ virtual double GetMasterVolume() = NULL;
+ virtual void SetMasterVolume(double theVolume) = NULL;
+
+ virtual void Flush() = NULL;
+ virtual void SetCooperativeWindow(HWND theHWnd, bool isWindowed) = NULL;
+ virtual void StopAllSounds() = NULL;
+ virtual int GetFreeSoundId() = NULL;
+ virtual int GetNumSounds() = NULL;
+
+};
+
+
+}
+
+#endif //__SOUNDMANAGER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/SysFont.cpp b/osframework/source/SexyAppFramework/SysFont.cpp
new file mode 100644
index 0000000..e4985c8
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SysFont.cpp
@@ -0,0 +1,318 @@
+#include "SysFont.h"
+#include "DDImage.h"
+#include "SexyAppBase.h"
+#include "Graphics.h"
+#include "ImageFont.h"
+#include "MemoryImage.h"
+#include "D3DInterface.h"
+#include "WidgetManager.h"
+#include <stdlib.h>
+
+using namespace Sexy;
+
+SysFont::SysFont(const std::string& theFace, int thePointSize, bool bold, bool italics, bool underline)
+{
+ Init(gSexyAppBase,theFace,thePointSize,ANSI_CHARSET,bold,italics,underline,false);
+}
+
+SysFont::SysFont(SexyAppBase* theApp, const std::string& theFace, int thePointSize, int theScript, bool bold, bool italics, bool underline)
+{
+ Init(theApp,theFace,thePointSize,theScript,bold,italics,underline,true);
+}
+
+void SysFont::Init(SexyAppBase* theApp, const std::string& theFace, int thePointSize, int theScript, bool bold, bool italics, bool underline, bool useDevCaps)
+{
+ mApp = theApp;
+
+ HDC aDC = ::GetDC(mApp->mHWnd);
+
+ int aHeight = -MulDiv(thePointSize, useDevCaps?GetDeviceCaps(aDC, LOGPIXELSY):96, 72);
+
+ mHFont = CreateFontA(aHeight, 0, 0, 0, bold ? FW_BOLD : FW_NORMAL, italics, underline,
+ false, theScript, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
+ DEFAULT_PITCH | FF_DONTCARE, theFace.c_str());
+
+ TEXTMETRIC aTextMetric;
+ HFONT anOldFont = (HFONT) SelectObject(aDC, mHFont);
+ GetTextMetrics(aDC, &aTextMetric);
+ SelectObject(aDC, anOldFont);
+ ReleaseDC(mApp->mHWnd, aDC);
+
+ mHeight = aTextMetric.tmHeight;
+ mAscent = aTextMetric.tmAscent;
+
+ mDrawShadow = false;
+ mSimulateBold = false;
+}
+
+SysFont::SysFont(const SysFont& theSysFont)
+{
+ LOGFONT aLogFont;
+
+ GetObject(theSysFont.mHFont, sizeof(LOGFONT), &aLogFont);
+ mHFont = CreateFontIndirect(&aLogFont);
+ mApp = theSysFont.mApp;
+ mHeight = theSysFont.mHeight;
+ mAscent = theSysFont.mAscent;
+
+ mDrawShadow = false;
+ mSimulateBold = false;
+}
+
+SysFont::~SysFont()
+{
+ DeleteObject(mHFont);
+}
+
+ImageFont* SysFont::CreateImageFont()
+{
+ int i;
+ MemoryImage* anImage;
+ int anImageCharWidth, anImageXOff, anImageYOff;
+
+ ////////////////////////////////////////////////////
+ // Step 1: Create image
+ anImageCharWidth = CharWidth('W')*2;
+ anImageXOff = anImageCharWidth/4;
+ anImageYOff = mHeight/2;
+ int aWidth = 257*anImageCharWidth;
+ int aHeight = mHeight*2;
+
+ BITMAPINFO aBitmapInfo;
+ memset(&aBitmapInfo,0,sizeof(aBitmapInfo));
+ BITMAPINFOHEADER &aHeader = aBitmapInfo.bmiHeader;
+ aHeader.biSize = sizeof(aHeader);
+ aHeader.biWidth = aWidth;
+ aHeader.biHeight = -aHeight;
+ aHeader.biPlanes = 1;
+ aHeader.biBitCount = 32;
+ aHeader.biCompression = BI_RGB;
+
+ HDC aDC = CreateCompatibleDC(NULL);
+
+ DWORD *aBits = NULL;
+ HBITMAP aBitmap = CreateDIBSection(aDC,&aBitmapInfo,DIB_RGB_COLORS,(void**)&aBits,NULL,0);
+
+ HBITMAP anOldBitmap = (HBITMAP)SelectObject(aDC,aBitmap);
+ HFONT anOldFont = (HFONT)SelectObject(aDC,mHFont);
+
+ HBRUSH anOldBrush = (HBRUSH)SelectObject(aDC,GetStockObject(BLACK_BRUSH));
+ Rectangle(aDC,0,0,aWidth,aHeight);
+
+ SetBkMode(aDC, TRANSPARENT);
+ SetTextColor(aDC, RGB(255,255,255));
+
+ int xpos = anImageXOff;
+ int ypos = anImageYOff;
+ for (i=0; i<256; i++)
+ {
+ char aChar = i;
+ TextOutA(aDC,xpos,ypos,&aChar,1);
+ xpos += anImageCharWidth;
+ }
+ GdiFlush();
+
+
+ SelectObject(aDC,anOldBrush);
+ SelectObject(aDC,anOldBitmap);
+ SelectObject(aDC,anOldFont);
+
+ int aSize = aWidth*aHeight;
+ anImage = new MemoryImage(mApp);
+ anImage->Create(aWidth,aHeight);
+ DWORD *src = aBits;
+ DWORD *dst = anImage->GetBits();
+ for (i=0; i<aSize; i++)
+ {
+ DWORD anAlpha = ((*src++)&0xff)<<24;
+ *dst++ = anAlpha | 0xFFFFFF;
+ }
+ anImage->BitsChanged();
+ DeleteObject(aBitmap);
+
+
+ ////////////////////////////////////////////////////
+ // Step 2: Create image font
+
+ ImageFont *aFont = new ImageFont(anImage);
+ FontLayer *aFontLayer = &aFont->mFontData->mFontLayerList.back();
+
+ aFontLayer->mAscent = mAscent;
+ aFontLayer->mHeight = mHeight;
+
+ for (i=0; i<256; i++)
+ {
+ char aChar = i;
+
+ aFontLayer->mCharData[(uchar) aChar].mImageRect = Rect(aChar*anImageCharWidth,0,anImageCharWidth,anImage->mHeight);
+ aFontLayer->mCharData[(uchar) aChar].mWidth = CharWidth(aChar);
+ aFontLayer->mCharData[(uchar) aChar].mOffset = Point(-anImageXOff,-anImageYOff);
+ }
+
+ aFont->GenerateActiveFontLayers();
+ aFont->mActiveListValid = true;
+
+ return aFont;
+}
+
+int SysFont::StringWidth(const SexyString& theString)
+{
+ HDC aDC = ::GetDC(mApp->mHWnd);
+ HFONT anOldFont = (HFONT)::SelectObject(aDC, mHFont);
+ int aWidth = 0;
+
+#ifdef _USE_WIDE_STRING
+ if (CheckFor98Mill())
+ {
+ SIZE aSize = { 0, 0 };
+ GetTextExtentPoint32W(aDC, theString.c_str(), theString.length(), &aSize);
+ aWidth = int(aSize.cx);
+ }
+ else
+#endif
+ {
+ RECT aRect = {0, 0, 0, 0};
+ DrawTextEx(aDC, (SexyChar*)theString.c_str(), theString.length(), &aRect, DT_CALCRECT | DT_NOPREFIX, NULL);
+ aWidth = aRect.right;
+ }
+
+ ::SelectObject(aDC, anOldFont);
+ ::ReleaseDC(mApp->mHWnd, aDC);
+
+ return aWidth;
+}
+
+void SysFont::DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect)
+{
+ DDImage* aDDImage = dynamic_cast<DDImage*>(g->mDestImage);
+
+ if (aDDImage != NULL)
+ {
+ LPDIRECTDRAWSURFACE aSurface = aDDImage->GetSurface();
+ if (aSurface != NULL)
+ {
+ HDC aDC;
+
+ if (aDDImage->mLockCount > 0)
+ aDDImage->mSurface->Unlock(NULL);
+
+ if ((g->mDestImage == gSexyAppBase->mWidgetManager->mImage) && (gSexyAppBase->Is3DAccelerated()))
+ gSexyAppBase->mDDInterface->mD3DInterface->Flush();
+
+ if (aSurface->GetDC(&aDC) == DD_OK)
+ {
+ HFONT anOldFont = (HFONT) SelectObject(aDC, mHFont);
+ SetBkMode(aDC, TRANSPARENT);
+ IntersectClipRect(aDC, theClipRect.mX, theClipRect.mY, theClipRect.mX + theClipRect.mWidth, theClipRect.mY + theClipRect.mHeight);
+
+ if (mDrawShadow)
+ {
+ SetTextColor(aDC, RGB(0,0,0));
+ TextOut(aDC, theX + g->mTransX+1, theY - mAscent + 1 + g->mTransY+1, theString.c_str(), theString.length());
+ if (mSimulateBold)
+ TextOut(aDC, theX + g->mTransX+2, theY - mAscent + 1 + g->mTransY+1, theString.c_str(), theString.length());
+ }
+ SetTextColor(aDC, RGB(theColor.GetRed(), theColor.GetGreen(), theColor.GetBlue()));
+ TextOut(aDC, theX + g->mTransX, theY - mAscent + 1 + g->mTransY, theString.c_str(), theString.length());
+ if (mSimulateBold)
+ TextOut(aDC, theX + g->mTransX + 1, theY - mAscent + 1 + g->mTransY, theString.c_str(), theString.length());
+
+ ::SelectObject(aDC, anOldFont);
+ aSurface->ReleaseDC(aDC);
+ aDDImage->DeleteAllNonSurfaceData();
+ }
+
+ if (aDDImage->mLockCount > 0)
+ aDDImage->mSurface->Lock(NULL, &aDDImage->mLockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
+ }
+ }
+ else if (g->mDestImage != &Graphics::mStaticImage) // DrawString can be called when not drawing onto an image.
+ {
+ HDC aDC = CreateCompatibleDC(NULL);
+ HFONT anOldFont = (HFONT) SelectObject(aDC, mHFont);
+
+ int aWidth = StringWidth(theString);
+ int aHeight = mHeight;
+
+ BITMAPINFOHEADER bih;
+ memset(&bih, 0, sizeof(bih));
+
+ bih.biPlanes = 1;
+ bih.biWidth = aWidth;
+ bih.biHeight = -aHeight;
+ bih.biCompression = BI_RGB;
+ bih.biBitCount = 32;
+ bih.biSize = sizeof(BITMAPINFOHEADER);
+
+ ulong* whiteBits, * blackBits;
+ HBITMAP whiteBitmap = (HBITMAP)CreateDIBSection(aDC, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&whiteBits, NULL, 0);
+ HBITMAP blackBitmap = (HBITMAP)CreateDIBSection(aDC, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&blackBits, NULL, 0);
+
+ RECT rc = { 0, 0, aWidth, aHeight };
+
+#define DRAW_BITMAP(bmp, brush) \
+ { \
+ HBITMAP oldBmp = (HBITMAP) SelectObject(aDC, bmp); \
+ ::FillRect(aDC, &rc, brush); \
+ SetBkMode(aDC, TRANSPARENT); \
+ \
+ if (mDrawShadow) \
+ { \
+ SetTextColor(aDC, RGB(0,0,0)); \
+ TextOut(aDC, 1, 1, theString.c_str(), theString.length()); \
+ if (mSimulateBold) \
+ TextOut(aDC, 2, 1, theString.c_str(), theString.length()); \
+ } \
+ SetTextColor(aDC, RGB(theColor.GetRed(), theColor.GetGreen(), theColor.GetBlue())); \
+ TextOut(aDC, 0, 0, theString.c_str(), theString.length()); \
+ if (mSimulateBold) \
+ TextOut(aDC, 1, 0, theString.c_str(), theString.length()); \
+ \
+ SelectObject(aDC, oldBmp); \
+ }
+
+ DRAW_BITMAP(whiteBitmap, (HBRUSH)GetStockObject(WHITE_BRUSH));
+ DRAW_BITMAP(blackBitmap, (HBRUSH)GetStockObject(BLACK_BRUSH));
+
+ SelectObject(aDC, anOldFont);
+
+ MemoryImage aTempImage;
+ aTempImage.Create(aWidth, aHeight);
+
+ int aCount = aHeight*aWidth;
+ ulong* ptr1 = whiteBits, *ptr2 = blackBits;
+ while (aCount > 0)
+ {
+ if (*ptr1 == *ptr2)
+ *ptr1 |= 0xFF000000;
+ else if ((*ptr1 & 0xFFFFFF) != 0xFFFFFF || (*ptr2 & 0xFFFFFF) != 0x000000) // if not the background of either, it's a 'blend'
+ {
+ int ba = 255 + (*ptr2 & 0xFF) - (*ptr1 & 0xFF);
+ int ga = 255 + ((*ptr2 >> 8) & 0xFF) - ((*ptr1 >> 8) & 0xFF);
+ int ra = 255 + ((*ptr2 >> 16) & 0xFF) - ((*ptr1 >> 16) & 0xFF);
+ int aBlue = 255 * (*ptr2 & 0xFF) / ba;
+ int aGreen = 255 * ((*ptr2 >> 8) & 0xFF) / ga;
+ int aRed = 255 * ((*ptr2 >> 16) & 0xFF) / ra;
+ int anAlpha = min(ra, min(ga, ba));
+ *ptr1 = (aBlue) | (aGreen << 8) | (aRed << 16) | (anAlpha << 24);
+ }
+ else *ptr1 &= 0;
+
+ ptr1++;
+ ptr2++;
+ --aCount;
+ }
+
+ memcpy(aTempImage.GetBits(), whiteBits, aWidth*aHeight*sizeof(ulong));
+ g->DrawImage(&aTempImage, theX, theY - mAscent);
+
+ DeleteObject(whiteBitmap);
+ DeleteObject(blackBitmap);
+ DeleteDC(aDC);
+ }
+}
+
+Font* SysFont::Duplicate()
+{
+ return new SysFont(*this);
+}
diff --git a/osframework/source/SexyAppFramework/SysFont.h b/osframework/source/SexyAppFramework/SysFont.h
new file mode 100644
index 0000000..f430d35
--- /dev/null
+++ b/osframework/source/SexyAppFramework/SysFont.h
@@ -0,0 +1,38 @@
+#ifndef __SYSFONT_H__
+#define __SYSFONT_H__
+
+#include "Font.h"
+
+namespace Sexy
+{
+
+class ImageFont;
+class SexyAppBase;
+
+class SysFont : public Font
+{
+public:
+ HFONT mHFont;
+ SexyAppBase* mApp;
+ bool mDrawShadow;
+ bool mSimulateBold;
+
+ void Init(SexyAppBase* theApp, const std::string& theFace, int thePointSize, int theScript, bool bold, bool italics, bool underline, bool useDevCaps);
+
+public:
+ SysFont(const std::string& theFace, int thePointSize, bool bold = false, bool italics = false, bool underline = false);
+ SysFont(SexyAppBase* theApp, const std::string& theFace, int thePointSize, int theScript = ANSI_CHARSET, bool bold = false, bool italics = false, bool underline = false);
+ SysFont(const SysFont& theSysFont);
+
+ virtual ~SysFont();
+
+ ImageFont* CreateImageFont();
+ virtual int StringWidth(const SexyString& theString);
+ virtual void DrawString(Graphics* g, int theX, int theY, const SexyString& theString, const Color& theColor, const Rect& theClipRect);
+
+ virtual Font* Duplicate();
+};
+
+}
+
+#endif //__SYSFONT_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/TextWidget.cpp b/osframework/source/SexyAppFramework/TextWidget.cpp
new file mode 100644
index 0000000..0fe8d9a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/TextWidget.cpp
@@ -0,0 +1,429 @@
+#include "TextWidget.h"
+#include "Graphics.h"
+#include "ScrollbarWidget.h"
+#include "WidgetManager.h"
+#include "Font.h"
+
+using namespace Sexy;
+
+TextWidget::TextWidget()
+{
+ mFont = NULL;
+ mPosition = 0;
+ mPageSize = 0;
+ mStickToBottom = true;
+ mMaxLines = 2048;
+ mScrollbar = NULL;
+}
+
+SexyStringVector TextWidget::GetLines()
+{
+ return mLogicalLines;
+}
+
+void TextWidget::SetLines(SexyStringVector theNewLines)
+{
+ mLogicalLines = theNewLines;
+}
+
+void TextWidget::Clear()
+{
+ mLogicalLines.clear();
+ mPhysicalLines.clear();
+ mPosition = 0.0;
+ mScrollbar->SetMaxValue(0.0);
+ MarkDirty();
+}
+
+void TextWidget::DrawColorString(Graphics* g, const SexyString& theString, int x, int y, bool useColors)
+{
+ int aWidth = 0;
+
+ if (useColors)
+ g->SetColor(Color(0, 0, 0));
+
+ SexyString aCurString = _S("");
+ for (int i = 0; i < (int)theString.length(); i++)
+ {
+ if (theString[i] == 0x100)
+ {
+ if (aCurString.length() > 0)
+ g->DrawString(aCurString, x + aWidth, y);
+
+ aWidth += g->GetFont()->StringWidth(aCurString);
+ aCurString = _S("");
+ if (useColors)
+ g->SetColor(Color(theString[i+1], theString[i+2], theString[i+3]));
+ i += 3;
+ }
+ else
+ aCurString += theString[i];
+ }
+
+ if (aCurString.length() > 0)
+ g->DrawString(aCurString, x + aWidth, y);
+}
+
+void TextWidget::DrawColorStringHilited(Graphics* g, const SexyString& theString, int x, int y, int theStartPos, int theEndPos)
+{
+ DrawColorString(g, theString, x, y, true);
+
+ if (theEndPos > theStartPos)
+ {
+ int aXOfs = GetColorStringWidth(theString.substr(0, theStartPos));
+ int aWidth = GetColorStringWidth(theString.substr(0, theEndPos)) - aXOfs;
+
+ Graphics aClipG(*g);
+ aClipG.ClipRect(x + aXOfs, y - g->GetFont()->GetAscent(), aWidth, g->GetFont()->GetHeight());
+
+ g->SetColor(Color(0, 0, 128));
+ g->FillRect(x + aXOfs, y - g->GetFont()->GetAscent(), aWidth, g->GetFont()->GetHeight());
+
+ aClipG.SetColor(Color(255, 255, 255));
+ DrawColorString(&aClipG, theString, x, y, false);
+ }
+}
+
+int TextWidget::GetStringIndex(const SexyString& theString, int thePixel)
+{
+ int aPos = 0;
+
+ for (int i = 0; i < (int)theString.length(); i++)
+ {
+ SexyString aLoSubStr = theString.substr(0, i);
+ SexyString aHiSubStr = theString.substr(0, i+1);
+
+ int aLoLen = GetColorStringWidth(aLoSubStr);
+ int aHiLen = GetColorStringWidth(aHiSubStr);
+ if (thePixel >= (aLoLen+aHiLen)/2)
+ aPos = i+1;
+ }
+
+ return aPos;
+}
+
+//UNICODE
+int TextWidget::GetColorStringWidth(const SexyString& theString)
+{
+ int aWidth = 0;
+ SexyString aTempString;
+
+ for (int i = 0; i < (int)theString.length(); i++)
+ {
+ if (theString[i] == 0x100)
+ {
+ aWidth += mFont->StringWidth(aTempString);
+ aTempString = _S("");
+
+ i += 3;
+ }
+ else
+ aTempString += theString[i];
+ }
+
+ aWidth += mFont->StringWidth(aTempString);
+
+ return aWidth;
+}
+
+void TextWidget::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Widget::Resize(theX, theY, theWidth, theHeight);
+
+ double aPageSize = 1;
+ if (mHeight > mFont->GetHeight()+16)
+ aPageSize = (mHeight - 8.0) / mFont->GetHeight();
+
+ int aLogValue = 0;
+ if (mLineMap.size() > 0)
+ {
+ //IntIntMap::iterator anItr = mLineMap.find(mScrollbar->mValue);
+
+ aLogValue = mLineMap[(int) mScrollbar->mValue];
+ }
+
+ int aNewPhysValue = 0;
+
+ mLineMap.clear();
+ mPhysicalLines.clear();
+ for (int i = 0; i < (int)mLogicalLines.size(); i++)
+ {
+ if (i == aLogValue)
+ aNewPhysValue = mPhysicalLines.size();
+
+ AddToPhysicalLines(i, mLogicalLines[i]);
+ }
+
+ bool atBottom = mScrollbar->AtBottom();
+
+ mPageSize = aPageSize;
+ mScrollbar->SetMaxValue(mPhysicalLines.size());
+ mScrollbar->SetPageSize((int) aPageSize);
+ mScrollbar->SetValue(aNewPhysValue);
+
+ if ((mStickToBottom) && (atBottom))
+ mScrollbar->GoToBottom();
+}
+
+//UNICODE
+Color TextWidget::GetLastColor(const SexyString& theString)
+{
+ int anIdx = theString.rfind((char)0xFF);
+ if (anIdx < 0)
+ return Color(0, 0, 0);
+
+ return Color(theString[anIdx+1], theString[anIdx+2], theString[anIdx+3]);
+}
+
+//UNICODE
+void TextWidget::AddToPhysicalLines(int theIdx, const SexyString& theLine)
+{
+ SexyString aCurString = _S("");
+
+ if (GetColorStringWidth(theLine) <= mWidth - 8)
+ {
+ aCurString = theLine;
+ }
+ else
+ {
+ int aCurPos = 0;
+ while (aCurPos < (int)theLine.length())
+ {
+ int aNextCheckPos = aCurPos;
+ while ((aNextCheckPos < (int)theLine.length()) && (theLine[aNextCheckPos] == ' '))
+ aNextCheckPos++;
+
+ int aSpacePos = theLine.find(_S(" "), aNextCheckPos);
+ if (aSpacePos == -1)
+ aSpacePos = theLine.length();
+
+ SexyString aNewString = aCurString + theLine.substr(aCurPos, aSpacePos - aCurPos);
+ if (GetColorStringWidth(aNewString) > mWidth-8)
+ {
+ mPhysicalLines.push_back(aCurString);
+ mLineMap.push_back(theIdx);
+ Color aColor = GetLastColor(aCurString);
+ aCurString = _S(" ") + SexyChar(0xFF) + (SexyChar) aColor.mRed + (SexyChar) aColor.mGreen + (SexyChar) aColor.mBlue +
+ theLine.substr(aNextCheckPos, aSpacePos - aNextCheckPos);
+ }
+ else
+ aCurString = aNewString;
+
+ aCurPos = aSpacePos;
+ }
+ }
+
+ if ((aCurString.compare(_S("")) != 0) || (theLine.compare(_S("")) == 0))
+ {
+ mPhysicalLines.push_back(aCurString);
+ mLineMap.push_back(theIdx);
+ }
+}
+
+//UNICODE
+void TextWidget::AddLine(const SexyString& theLine)
+{
+ SexyString aLine = theLine;
+
+ if (aLine.compare(_S("")) == 0)
+ aLine = _S(" ");
+
+ bool atBottom = mScrollbar->AtBottom();
+
+ mLogicalLines.push_back(aLine);
+
+ if ((int)mLogicalLines.size() > mMaxLines)
+ {
+ // Remove an extra 10 lines, for safty
+ int aNumLinesToRemove = mLogicalLines.size() - mMaxLines + 10;
+
+ mLogicalLines.erase(mLogicalLines.begin(), mLogicalLines.begin() + aNumLinesToRemove);
+
+ int aPhysLineRemoveCount = 0;
+
+ // Remove all physical lines and linemap entries relating to deleted logical lines
+ while (mLineMap[aPhysLineRemoveCount] < aNumLinesToRemove)
+ {
+ aPhysLineRemoveCount++;
+ }
+
+ mLineMap.erase(mLineMap.begin(), mLineMap.begin() + aPhysLineRemoveCount);
+ mPhysicalLines.erase(mPhysicalLines.begin(), mPhysicalLines.begin() + aPhysLineRemoveCount);
+
+ // Offset the line map numbers
+ int i;
+ for (i = 0; i < (int)mLineMap.size(); i++)
+ {
+ mLineMap[i] -= aNumLinesToRemove;
+ }
+ //mLineMap.setElementAt(new Integer(((Integer) mLineMap.elementAt(i)).intValue() - aNumLinesToRemove), i);
+
+ // Move the hilited area
+ for (i = 0; i < 2; i++)
+ {
+ mHiliteArea[i][1] -= aNumLinesToRemove;
+ if (mHiliteArea[i][1] < 0)
+ {
+ mHiliteArea[i][0] = 0;
+ mHiliteArea[i][1] = 0;
+ }
+ }
+
+ mScrollbar->SetValue(mScrollbar->mValue - aNumLinesToRemove);
+ }
+
+ AddToPhysicalLines(mLogicalLines.size()-1, aLine);
+
+ mScrollbar->SetMaxValue(mPhysicalLines.size());
+
+ if (atBottom)
+ mScrollbar->GoToBottom();
+
+ MarkDirty();
+}
+
+bool TextWidget::SelectionReversed()
+{
+ return ((mHiliteArea[1][1] < mHiliteArea[0][1]) ||
+ ((mHiliteArea[1][1] == mHiliteArea[0][1]) &&
+ (mHiliteArea[1][0] < mHiliteArea[0][0])));
+}
+
+void TextWidget::GetSelectedIndices(int theLineIdx, int* theIndices)
+{
+ int aXor = SelectionReversed() ? 1 : 0;
+ for (int aPosIdx = 0; aPosIdx < 2; aPosIdx++)
+ {
+ int aVal;
+
+ if (mHiliteArea[aPosIdx][1] < theLineIdx)
+ aVal = 0;
+ else if (mHiliteArea[aPosIdx][1] == theLineIdx)
+ aVal = mHiliteArea[aPosIdx][0];
+ else
+ aVal = mPhysicalLines[theLineIdx].length();
+
+ theIndices[aPosIdx ^ aXor] = aVal;
+ }
+}
+
+void TextWidget::Draw(Graphics* g)
+{
+ g->SetColor(Color(255, 255, 255));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ Graphics aClipG(*g);
+ aClipG.ClipRect(4, 4, mWidth - 8, mHeight - 8);
+
+ aClipG.SetColor(Color(0, 0, 0));
+ aClipG.SetFont(mFont);
+
+ int aFirstLine = (int) mPosition;
+ int aLastLine = min((int) mPhysicalLines.size()-1, (int) mPosition + (int) mPageSize + 1);
+
+ for (int i = aFirstLine; i <= aLastLine; i++)
+ {
+ int aYPos = 4 + (int) ((i - (int) mPosition)*mFont->GetHeight()) + mFont->GetAscent();
+ SexyString aString = mPhysicalLines[i];
+
+ int aHilitePos[2];
+ GetSelectedIndices(i, aHilitePos);
+ DrawColorStringHilited(&aClipG, aString, 4, aYPos, aHilitePos[0], aHilitePos[1]);
+ }
+}
+
+void TextWidget::ScrollPosition(int theId, double thePosition)
+{
+ mPosition = thePosition;
+ MarkDirty();
+}
+
+void TextWidget::GetTextIndexAt(int x, int y, int* thePosArray)
+{
+ int aLineNum = (int) (mScrollbar->mValue + (y / (double) mFont->GetHeight()));
+ if (y < 0)
+ {
+ thePosArray[0] = 0;
+ thePosArray[1] = 0;
+ }
+ else if (aLineNum < (int)mPhysicalLines.size())
+ {
+ thePosArray[0] = GetStringIndex(mPhysicalLines[aLineNum], x);
+ thePosArray[1] = aLineNum;
+ }
+ else
+ {
+ if (mPhysicalLines.size() > 0)
+ {
+ thePosArray[0] = mPhysicalLines[mPhysicalLines.size()-1].length();
+ thePosArray[1] = mPhysicalLines.size() - 1;
+ }
+ }
+}
+
+void TextWidget::MouseDown(int x, int y, int theClickCount)
+{
+ Widget::MouseDown(x, y, theClickCount);
+
+ GetTextIndexAt(x-4, y-4, mHiliteArea[0]);
+ mHiliteArea[1][0] = mHiliteArea[0][0];
+ mHiliteArea[1][1] = mHiliteArea[0][1];
+ MarkDirty();
+}
+
+void TextWidget::MouseDrag(int x, int y)
+{
+ Widget::MouseDrag(x, y);
+
+ GetTextIndexAt(x-4, y-4, mHiliteArea[1]);
+ MarkDirty();
+}
+
+SexyString TextWidget::GetSelection()
+{
+ SexyString aSelString = _S("");
+ int aSelIndices[2];
+ bool first = true;
+
+ bool reverse = SelectionReversed();
+ for (int aLineNum = mHiliteArea[reverse ? 1 : 0][1]; aLineNum <= mHiliteArea[reverse ? 0 : 1][1]; aLineNum++)
+ {
+ SexyString aString = mPhysicalLines[aLineNum];
+
+ GetSelectedIndices(aLineNum, aSelIndices);
+
+ if (!first)
+ aSelString += _S("\r\n");
+
+ for (int aStrIdx = aSelIndices[0]; aStrIdx < aSelIndices[1]; aStrIdx++)
+ {
+ SexyChar aChar = aString[aStrIdx];
+ if (aChar != 0x100)
+ aSelString += aChar;
+ else
+ aStrIdx += 3;
+ }
+
+ first = false;
+ }
+
+ return aSelString;
+}
+
+void TextWidget::KeyDown(KeyCode theKey)
+{
+ /*if (theKey == 3)
+ {
+ // Control-C
+ mWidgetManager.mApplet.CopyToClipboard(GetSelection());
+ }
+ else
+ {
+ if (mEditWidget != null)
+ {
+ mWidgetManager.SetFocus(mEditWidget);
+ mEditWidget.KeyDown(theKey, shiftDown, controlDown);
+ }
+ }*/
+}
+
diff --git a/osframework/source/SexyAppFramework/TextWidget.h b/osframework/source/SexyAppFramework/TextWidget.h
new file mode 100644
index 0000000..d05186a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/TextWidget.h
@@ -0,0 +1,62 @@
+#ifndef __TEXTWIDGET_H__
+#define __TEXTWIDGET_H__
+
+#include "Widget.h"
+#include "ScrollListener.h"
+
+namespace Sexy
+{
+
+class ScrollbarWidget;
+class Font;
+
+typedef std::vector<SexyString> SexyStringVector;
+typedef std::vector<int> IntVector;
+
+class TextWidget : public Widget, public ScrollListener
+{
+public:
+ Font* mFont;
+ ScrollbarWidget* mScrollbar;
+
+ SexyStringVector mLogicalLines;
+ SexyStringVector mPhysicalLines;
+ IntVector mLineMap;
+ double mPosition;
+ double mPageSize;
+ bool mStickToBottom;
+ int mHiliteArea[2][2];
+ int mMaxLines;
+
+public:
+ TextWidget();
+
+ virtual SexyStringVector GetLines();
+ virtual void SetLines(SexyStringVector theNewLines);
+ virtual void Clear();
+ virtual void DrawColorString(Graphics* g, const SexyString& theString, int x, int y, bool useColors);
+ virtual void DrawColorStringHilited(Graphics* g, const SexyString& theString, int x, int y, int theStartPos, int theEndPos);
+ virtual int GetStringIndex(const SexyString& theString, int thePixel);
+
+ virtual int GetColorStringWidth(const SexyString& theString);
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+ virtual Color GetLastColor(const SexyString& theString);
+ virtual void AddToPhysicalLines(int theIdx, const SexyString& theLine);
+
+ virtual void AddLine(const SexyString& theString);
+ virtual bool SelectionReversed();
+ virtual void GetSelectedIndices(int theLineIdx, int* theIndices);
+ virtual void Draw(Graphics* g);
+ virtual void ScrollPosition(int theId, double thePosition);
+ virtual void GetTextIndexAt(int x, int y, int* thePosArray);
+ virtual SexyString GetSelection();
+
+ virtual void MouseDown(int x, int y, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+
+ virtual void KeyDown(KeyCode theKey);
+};
+
+}
+
+#endif //__TEXTWIDGET_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/TriVertex.h b/osframework/source/SexyAppFramework/TriVertex.h
new file mode 100644
index 0000000..54966be
--- /dev/null
+++ b/osframework/source/SexyAppFramework/TriVertex.h
@@ -0,0 +1,25 @@
+#ifndef __TRIVERTEX_H__
+#define __TRIVERTEX_H__
+
+namespace Sexy
+{
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class TriVertex
+{
+public:
+ float x,y,u,v;
+ DWORD color; //ARGB (0 = use color specified in function call)
+
+public:
+ TriVertex() { color = 0; }
+ TriVertex(float theX, float theY) : x(theX), y(theY) { color = 0; }
+ TriVertex(float theX, float theY, float theU, float theV) : x(theX), y(theY), u(theU), v(theV) { color = 0; }
+ TriVertex(float theX, float theY, float theU, float theV, DWORD theColor) : x(theX), y(theY), u(theU), v(theV), color(theColor) { }
+};
+
+} // namespace Sexy
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/Widget.cpp b/osframework/source/SexyAppFramework/Widget.cpp
new file mode 100644
index 0000000..9f23cea
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Widget.cpp
@@ -0,0 +1,489 @@
+#include "Widget.h"
+#include "WidgetManager.h"
+#include "Graphics.h"
+#include "Font.h"
+#include "Image.h"
+#include "SexyAppBase.h"
+#include "debug.h"
+
+using namespace Sexy;
+
+bool Widget::mWriteColoredString = true;
+
+Widget::Widget()
+{
+ mWidgetManager = NULL;
+ mVisible = true;
+ mDisabled = false;
+ mIsDown = false;
+ mIsOver = false;
+ mDoFinger = false;
+ mMouseVisible = true;
+ mHasFocus = false;
+ mHasTransparencies = false;
+ mWantsFocus = false;
+ mTabPrev = NULL;
+ mTabNext = NULL;
+}
+
+Widget::~Widget()
+{
+ mColors.clear();
+}
+
+void Widget::WidgetRemovedHelper()
+{
+ if (mWidgetManager==NULL)
+ return;
+
+ // Call RemovedFromManager on all child widgets and disable them and stuff like that
+ for (WidgetList::iterator aWidgetItr = mWidgets.begin(); aWidgetItr != mWidgets.end(); ++aWidgetItr)
+ {
+ Widget *aWidget = *aWidgetItr;
+ aWidget->WidgetRemovedHelper();
+ }
+
+ mWidgetManager->DisableWidget(this);
+
+ PreModalInfoList::iterator anItr = mWidgetManager->mPreModalInfoList.begin();
+ while (anItr != mWidgetManager->mPreModalInfoList.end())
+ {
+ PreModalInfo* aPreModalInfo = &(*anItr);
+ if (aPreModalInfo->mPrevBaseModalWidget == this)
+ aPreModalInfo->mPrevBaseModalWidget = NULL;
+ if (aPreModalInfo->mPrevFocusWidget == this)
+ aPreModalInfo->mPrevFocusWidget = NULL;
+ ++anItr;
+ }
+
+ RemovedFromManager(mWidgetManager);
+ MarkDirtyFull(this);
+
+ mWidgetManager = NULL;
+}
+
+void Widget::OrderInManagerChanged()
+{
+}
+
+bool Widget::IsPointVisible(int x, int y)
+{
+ return true;
+}
+
+void Widget::SetVisible(bool isVisible)
+{
+ if (mVisible == isVisible)
+ return;
+
+ mVisible = isVisible;
+
+ if (mVisible)
+ MarkDirty();
+ else
+ MarkDirtyFull();
+
+ if (mWidgetManager != NULL)
+ mWidgetManager->RehupMouse();
+}
+
+void Widget::Draw(Graphics* g) // Already translated
+{
+}
+
+void Widget::DrawOverlay(Graphics* g)
+{
+}
+
+void Widget::DrawOverlay(Graphics* g, int thePriority)
+{
+ DrawOverlay(g);
+}
+
+void Widget::SetColors(int theColors[][3], int theNumColors)
+{
+ mColors.clear();
+
+ for (int i = 0; i < theNumColors; i++)
+ SetColor(i, Color(theColors[i][0], theColors[i][1], theColors[i][2]));
+ MarkDirty();
+}
+
+void Widget::SetColors(int theColors[][4], int theNumColors)
+{
+ mColors.clear();
+
+ for (int i = 0; i < theNumColors; i++)
+ SetColor(i, Color(theColors[i][0], theColors[i][1], theColors[i][2], theColors[i][3]));
+
+ MarkDirty();
+}
+
+void Widget::SetColor(int theIdx, const Color& theColor)
+{
+ if (theIdx >= (int)mColors.size())
+ mColors.resize(theIdx + 1);
+
+ mColors[theIdx] = theColor;
+ MarkDirty();
+}
+
+const Color& Widget::GetColor(int theIdx)
+{
+ static Color aColor;
+ if (theIdx < (int) mColors.size())
+ return mColors[theIdx];
+ return aColor;
+}
+
+Color Widget::GetColor(int theIdx, const Color& theDefaultColor)
+{
+ if (theIdx < (int) mColors.size())
+ return mColors[theIdx];
+ return theDefaultColor;
+}
+
+void Widget::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ if ((mX == theX) && (mY == theY) && (mWidth == theWidth) && (mHeight == theHeight))
+ return;
+
+ // Mark everything dirty that is over or under the old position
+ MarkDirtyFull();
+
+ mX = theX;
+ mY = theY;
+ mWidth = theWidth;
+ mHeight = theHeight;
+
+ // Mark things dirty that are over the new position
+ MarkDirty();
+
+ if (mWidgetManager != NULL)
+ mWidgetManager->RehupMouse();
+}
+
+void Widget::Resize(const Rect& theRect)
+{
+ Resize(theRect.mX, theRect.mY, theRect.mWidth, theRect.mHeight);
+}
+
+void Widget::Move(int theNewX, int theNewY)
+{
+ Resize(theNewX, theNewY, mWidth, mHeight);
+}
+
+bool Widget::WantsFocus()
+{
+ return mWantsFocus;
+}
+
+void Widget::SetDisabled(bool isDisabled)
+{
+ if (mDisabled == isDisabled)
+ return;
+
+ mDisabled = isDisabled;
+
+ if ((isDisabled) && (mWidgetManager != NULL))
+ mWidgetManager->DisableWidget(this);
+
+ MarkDirty();
+
+ // Incase a widget is enabled right under our cursor
+ if ((!isDisabled) && (mWidgetManager != NULL) && (Contains(mWidgetManager->mLastMouseX, mWidgetManager->mLastMouseY)))
+ mWidgetManager->MousePosition(mWidgetManager->mLastMouseX, mWidgetManager->mLastMouseY);
+}
+
+void Widget::GotFocus()
+{
+ mHasFocus = true;
+}
+
+void Widget::LostFocus()
+{
+ mHasFocus = false;
+}
+
+void Widget::Update()
+{
+ WidgetContainer::Update();
+}
+
+void Widget::UpdateF(float theFrac)
+{
+}
+
+void Widget::KeyChar(SexyChar theChar)
+{
+}
+
+void Widget::KeyDown(KeyCode theKey)
+{
+ if (theKey == KEYCODE_TAB)
+ {
+ if (mWidgetManager->mKeyDown[KEYCODE_SHIFT])
+ {
+ if (mTabPrev != NULL)
+ mWidgetManager->SetFocus(mTabPrev);
+ }
+ else
+ {
+ if (mTabNext != NULL)
+ mWidgetManager->SetFocus(mTabNext);
+ }
+ }
+}
+
+void Widget::KeyUp(KeyCode theKey)
+{
+}
+
+void Widget::ShowFinger(bool on)
+{
+ if (mWidgetManager == NULL)
+ return;
+
+ if (on)
+ mWidgetManager->mApp->SetCursor(CURSOR_HAND);
+ else
+ mWidgetManager->mApp->SetCursor(CURSOR_POINTER);
+
+ /*if (on)
+ mWidgetManager->mApplet.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ else
+ mWidgetManager->mApplet.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));*/
+}
+
+void Widget::MouseEnter()
+{
+
+}
+
+void Widget::MouseLeave()
+{
+
+}
+
+void Widget::MouseMove(int x, int y)
+{
+}
+
+void Widget::MouseDown(int x, int y, int theClickCount)
+{
+ if (theClickCount == 3)
+ MouseDown(x, y, 2, 1);
+ else if (theClickCount >= 0)
+ MouseDown(x, y, 0, theClickCount);
+ else
+ MouseDown(x, y, 1, -theClickCount);
+}
+
+void Widget::MouseDown(int x, int y, int theBtnNum, int theClickCount)
+{
+}
+
+void Widget::MouseUp(int x, int y)
+{
+}
+
+void Widget::MouseUp(int x, int y, int theLastDownButtonId)
+{
+ MouseUp(x, y);
+
+ if (theLastDownButtonId == 3)
+ MouseUp(x, y, 2, 1);
+ else if (theLastDownButtonId >= 0)
+ MouseUp(x, y, 0, theLastDownButtonId);
+ else
+ MouseUp(x, y, 1, -theLastDownButtonId);
+}
+
+void Widget::MouseUp(int x, int y, int theBtnNum, int theClickCount)
+{
+}
+
+void Widget::MouseDrag(int x, int y)
+{
+}
+
+void Widget::MouseWheel(int theDelta)
+{
+}
+
+//////// Helper functions
+
+Rect Widget::WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine)
+{
+ Font* aFont = g->GetFont();
+ int aWidth = aFont->StringWidth(theLine);
+ int aX = (mWidth - aWidth) / 2;
+
+ g->DrawString(theLine, aX, anOffset);
+
+ return Rect(aX, anOffset - aFont->GetAscent(), aWidth, aFont->GetHeight());
+}
+
+Rect Widget::WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine, Color theColor1, Color theColor2, const Point& theShadowOffset)
+{
+ Font* aFont = g->GetFont();
+ int aWidth = aFont->StringWidth(theLine);
+ int aX = (mWidth - aWidth) / 2;
+
+ g->SetColor(theColor2);
+ g->DrawString(theLine, (mWidth - aWidth)/2 + theShadowOffset.mX, anOffset + theShadowOffset.mY);
+
+ g->SetColor(theColor1);
+ g->DrawString(theLine, (mWidth - aWidth)/2, anOffset);
+
+ // account for shadow in position and size
+ // TODO: this may not be necessary.
+ return Rect(
+ aX + min(0,theShadowOffset.mX),
+ anOffset - aFont->GetAscent() + min(0,theShadowOffset.mY),
+ aWidth + abs(theShadowOffset.mX),
+ aFont->GetHeight() + abs(theShadowOffset.mY));
+}
+
+int Widget::WriteString(Graphics* g, const SexyString& theString, int theX, int theY, int theWidth, int theJustification, bool drawString, int theOffset, int theLength)
+{
+ bool oldColored = g->mWriteColoredString;
+ g->mWriteColoredString = mWriteColoredString;
+ int aXOffset = g->WriteString(theString,theX,theY,theWidth,theJustification,drawString,theOffset,theLength);
+ g->mWriteColoredString = oldColored;
+
+ return aXOffset;
+}
+
+int Widget::WriteWordWrapped(Graphics* g, const Rect& theRect, const SexyString& theLine, int theLineSpacing, int theJustification)
+{
+ bool oldColored = g->mWriteColoredString;
+ g->mWriteColoredString = mWriteColoredString;
+ int aReturn = g->WriteWordWrapped(theRect,theLine,theLineSpacing,theJustification);
+ g->mWriteColoredString = oldColored;
+
+ return aReturn;
+}
+
+int Widget::GetWordWrappedHeight(Graphics* g, int theWidth, const SexyString& theLine, int aLineSpacing)
+{
+ return g->GetWordWrappedHeight(theWidth,theLine,aLineSpacing);
+}
+
+int Widget::GetNumDigits(int theNumber)
+{
+ int aDivisor = 10;
+ int aNumDigits = 1;
+ while (theNumber >= aDivisor)
+ {
+ aNumDigits++;
+ aDivisor *= 10;
+ }
+
+ return aNumDigits;
+}
+
+void Widget::WriteNumberFromStrip(Graphics* g, int theNumber, int theX, int theY, Image* theNumberStrip, int aSpacing)
+{
+ int aDivisor = 10;
+ int aNumDigits = 1;
+ while (theNumber >= aDivisor)
+ {
+ aNumDigits++;
+ aDivisor *= 10;
+ }
+ if (theNumber == 0)
+ aDivisor = 10;
+
+ int aDigitLen = theNumberStrip->GetWidth() / 10;
+
+ for (int aDigitIdx = 0; aDigitIdx < aNumDigits; aDigitIdx++)
+ {
+ aDivisor /= 10;
+ int aDigit = (theNumber / aDivisor) % 10;
+
+ Graphics* aClipG = g->Create();
+ aClipG->ClipRect(theX + aDigitIdx*(aDigitLen + aSpacing), theY, aDigitLen, theNumberStrip->GetHeight());
+ aClipG->DrawImage(theNumberStrip, theX + aDigitIdx*(aDigitLen + aSpacing) - aDigit*aDigitLen, theY);
+ delete aClipG;
+ }
+}
+
+bool Widget::Contains(int theX, int theY)
+{
+ return ((theX >= mX) && (theX < mX + mWidth) &&
+ (theY >= mY) && (theY < mY + mHeight));
+}
+
+Rect Widget::GetInsetRect()
+{
+ return Rect(mX + mMouseInsets.mLeft, mY + mMouseInsets.mTop,
+ mWidth - mMouseInsets.mLeft - mMouseInsets.mRight,
+ mHeight - mMouseInsets.mTop - mMouseInsets.mBottom);
+}
+
+void Widget::DeferOverlay(int thePriority)
+{
+ mWidgetManager->DeferOverlay(this, thePriority);
+}
+
+void Widget::Layout(int theLayoutFlags, Widget *theRelativeWidget, int theLeftPad, int theTopPad, int theWidthPad, int theHeightPad)
+{
+ int aRelLeft = theRelativeWidget->Left();
+ int aRelTop = theRelativeWidget->Top();
+ if (theRelativeWidget==mParent)
+ {
+ aRelLeft = 0;
+ aRelTop = 0;
+ }
+
+ int aRelWidth = theRelativeWidget->Width();
+ int aRelHeight = theRelativeWidget->Height();
+ int aRelRight = aRelLeft + aRelWidth;
+ int aRelBottom = aRelTop + aRelHeight;
+
+ int aLeft = Left();
+ int aTop = Top();
+ int aWidth = Width();
+ int aHeight = Height();
+
+ int aType = 1;
+ while(aType<LAY_Max)
+ {
+ if(theLayoutFlags&aType)
+ {
+ switch(aType)
+ {
+ case LAY_SameWidth: aWidth = aRelWidth+theWidthPad; break;
+ case LAY_SameHeight: aHeight = aRelHeight+theHeightPad; break;
+
+ case LAY_Above: aTop = aRelTop-aHeight+theTopPad; break;
+ case LAY_Below: aTop = aRelBottom+theTopPad; break;
+ case LAY_Right: aLeft = aRelRight+theLeftPad; break;
+ case LAY_Left: aLeft = aRelLeft-aWidth+theLeftPad; break;
+
+ case LAY_SameLeft: aLeft = aRelLeft+theLeftPad; break;
+ case LAY_SameRight: aLeft = aRelRight-aWidth+theLeftPad; break;
+ case LAY_SameTop: aTop = aRelTop+theTopPad; break;
+ case LAY_SameBottom: aTop = aRelBottom-aHeight+theTopPad; break;
+
+ case LAY_GrowToRight: aWidth = aRelRight-aLeft+theWidthPad; break;
+ case LAY_GrowToLeft: aWidth = aRelLeft-aLeft+theWidthPad; break;
+ case LAY_GrowToTop: aHeight = aRelTop-aTop+theHeightPad; break;
+ case LAY_GrowToBottom: aHeight = aRelBottom-aTop+theHeightPad; break;
+
+ case LAY_SetLeft: aLeft = theLeftPad; break;
+ case LAY_SetTop: aTop = theTopPad; break;
+ case LAY_SetWidth: aWidth = theWidthPad; break;
+ case LAY_SetHeight: aHeight = theHeightPad; break;
+
+ case LAY_HCenter: aLeft = aRelLeft+(aRelWidth-aWidth)/2 + theLeftPad; break;
+ case LAY_VCenter: aTop = aRelTop+(aRelHeight-aHeight)/2 + theTopPad; break;
+ }
+ }
+
+ aType<<=1;
+ }
+
+ Resize(aLeft,aTop,aWidth,aHeight);
+}
diff --git a/osframework/source/SexyAppFramework/Widget.h b/osframework/source/SexyAppFramework/Widget.h
new file mode 100644
index 0000000..02bdaee
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Widget.h
@@ -0,0 +1,146 @@
+#ifndef __WIDGET_H__
+#define __WIDGET_H__
+
+#include "Common.h"
+#include "Color.h"
+#include "Insets.h"
+#include "Graphics.h"
+#include "KeyCodes.h"
+#include "WidgetContainer.h"
+
+namespace Sexy
+{
+
+class WidgetManager;
+
+typedef std::vector<Color> ColorVector;
+
+class Widget : public WidgetContainer
+{
+public:
+ bool mVisible;
+ bool mMouseVisible;
+ bool mDisabled;
+ bool mHasFocus;
+ bool mIsDown;
+ bool mIsOver;
+ bool mHasTransparencies;
+ ColorVector mColors;
+ Insets mMouseInsets;
+ bool mDoFinger;
+ bool mWantsFocus;
+
+ Widget* mTabPrev;
+ Widget* mTabNext;
+
+ static bool mWriteColoredString; // controls whether ^color^ works in calls to WriteString
+
+ void WidgetRemovedHelper();
+
+public:
+ Widget();
+ virtual ~Widget();
+
+ virtual void OrderInManagerChanged();
+ virtual void SetVisible(bool isVisible);
+
+ virtual void SetColors(int theColors[][3], int theNumColors);
+ virtual void SetColors(int theColors[][4], int theNumColors);
+ virtual void SetColor(int theIdx, const Color& theColor);
+ virtual const Color& GetColor(int theIdx);
+ virtual Color GetColor(int theIdx, const Color& theDefaultColor);
+
+ virtual void SetDisabled(bool isDisabled);
+ virtual void ShowFinger(bool on);
+
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+ virtual void Resize(const Rect& theRect);
+ virtual void Move(int theNewX, int theNewY);
+ virtual bool WantsFocus();
+ virtual void Draw(Graphics* g); // Already translated
+ virtual void DrawOverlay(Graphics* g);
+ virtual void DrawOverlay(Graphics* g, int thePriority);
+ virtual void Update();
+ virtual void UpdateF(float theFrac);
+ virtual void GotFocus();
+ virtual void LostFocus();
+ virtual void KeyChar(SexyChar theChar);
+ virtual void KeyDown(KeyCode theKey);
+ virtual void KeyUp(KeyCode theKey);
+ virtual void MouseEnter();
+ virtual void MouseLeave();
+ virtual void MouseMove(int x, int y);
+ virtual void MouseDown(int x, int y, int theClickCount);
+ virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseUp(int x, int y);
+ virtual void MouseUp(int x, int y, int theClickCount);
+ virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount);
+ virtual void MouseDrag(int x, int y);
+ virtual void MouseWheel(int theDelta);
+ virtual bool IsPointVisible(int x, int y);
+
+ //////// Helper functions
+
+ virtual Rect WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine);
+ virtual Rect WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine, Color theColor1, Color theColor2, const Point& theShadowOffset = Point(1,2));
+
+ virtual int WriteString(Graphics* g, const SexyString& theString, int theX, int theY, int theWidth = -1, int theJustification = -1, bool drawString = true, int theOffset = 0, int theLength = -1);
+ virtual int WriteWordWrapped(Graphics* g, const Rect& theRect, const SexyString& theLine, int theLineSpacing, int theJustification);
+ virtual int GetWordWrappedHeight(Graphics* g, int theWidth, const SexyString& theLine, int aLineSpacing);
+ virtual int GetNumDigits(int theNumber);
+ virtual void WriteNumberFromStrip(Graphics* g, int theNumber, int theX, int theY, Image* theNumberStrip, int aSpacing);
+ virtual bool Contains(int theX, int theY);
+ virtual Rect GetInsetRect();
+ void DeferOverlay(int thePriority = 0);
+
+ //////// Layout functions
+ int Left() { return mX; }
+ int Top() { return mY; }
+ int Right() { return mX + mWidth; }
+ int Bottom() { return mY + mHeight; }
+ int Width() { return mWidth; }
+ int Height() { return mHeight; }
+
+ void Layout(int theLayoutFlags, Widget *theRelativeWidget, int theLeftPad = 0, int theTopPad = 0, int theWidthPad = 0, int theHeightPad = 0);
+};
+
+/////// Layout flags used in Widget::Layout method
+enum LayoutFlags
+{
+ LAY_SameWidth = 0x0001,
+ LAY_SameHeight = 0x0002,
+
+ LAY_SetLeft = 0x0010,
+ LAY_SetTop = 0x0020,
+ LAY_SetWidth = 0x0040,
+ LAY_SetHeight = 0x0080,
+
+ LAY_Above = 0x0100,
+ LAY_Below = 0x0200,
+ LAY_Right = 0x0400,
+ LAY_Left = 0x0800,
+
+ LAY_SameLeft = 0x1000,
+ LAY_SameRight = 0x2000,
+ LAY_SameTop = 0x4000,
+ LAY_SameBottom = 0x8000,
+
+ LAY_GrowToRight = 0x10000,
+ LAY_GrowToLeft = 0x20000,
+ LAY_GrowToTop = 0x40000,
+ LAY_GrowToBottom = 0x80000,
+
+ LAY_HCenter = 0x100000,
+ LAY_VCenter = 0x200000,
+ LAY_Max = 0x400000,
+
+ LAY_SameSize = LAY_SameWidth | LAY_SameHeight,
+ LAY_SameCorner = LAY_SameLeft | LAY_SameTop,
+ LAY_SetPos = LAY_SetLeft | LAY_SetTop,
+ LAY_SetSize = LAY_SetWidth | LAY_SetHeight
+};
+
+
+}
+
+#endif //__WIDGET_H__
diff --git a/osframework/source/SexyAppFramework/WidgetBuildBase.cpp b/osframework/source/SexyAppFramework/WidgetBuildBase.cpp
new file mode 100644
index 0000000..e4931ea
--- /dev/null
+++ b/osframework/source/SexyAppFramework/WidgetBuildBase.cpp
@@ -0,0 +1,16 @@
+#include "WidgetManager.cpp"
+#include "Widget.cpp"
+#include "TextWidget.cpp"
+#include "Slider.cpp"
+#include "ScrollbuttonWidget.cpp"
+#include "ScrollbarWidget.cpp"
+#include "ListWidget.cpp"
+#include "Insets.cpp"
+#include "HyperlinkWidget.cpp"
+#include "EditWidget.cpp"
+#include "Checkbox.cpp"
+#include "ButtonWidget.cpp"
+#include "Dialog.cpp"
+#include "DialogButton.cpp"
+#include "FlashWidget.cpp"
+#include "WidgetContainer.cpp"
diff --git a/osframework/source/SexyAppFramework/WidgetContainer.cpp b/osframework/source/SexyAppFramework/WidgetContainer.cpp
new file mode 100644
index 0000000..a255734
--- /dev/null
+++ b/osframework/source/SexyAppFramework/WidgetContainer.cpp
@@ -0,0 +1,627 @@
+#include "WidgetContainer.h"
+#include "WidgetManager.h"
+#include "Widget.h"
+#include "Debug.h"
+#include <algorithm>
+
+using namespace Sexy;
+
+WidgetContainer::WidgetContainer()
+{
+ mX = 0;
+ mY = 0;
+ mWidth = 0;
+ mHeight = 0;
+ mParent = NULL;
+ mWidgetManager = NULL;
+ mUpdateIteratorModified = false;
+ mUpdateIterator = mWidgets.end();
+ mLastWMUpdateCount = 0;
+ mUpdateCnt = 0;
+ mDirty = false;
+ mHasAlpha = false;
+ mClip = true;
+ mPriority = 0;
+ mZOrder = 0;
+}
+
+WidgetContainer::~WidgetContainer()
+{
+ // call RemoveWidget before you delete it!
+ DBG_ASSERT(mParent == NULL);
+ DBG_ASSERT(mWidgets.empty());
+}
+
+void WidgetContainer::RemoveAllWidgets(bool doDelete, bool recursive)
+{
+ while (!mWidgets.empty())
+ {
+ Widget *aWidget = mWidgets.front();
+ RemoveWidget(aWidget);
+ if (recursive)
+ aWidget->RemoveAllWidgets(doDelete,recursive);
+
+ if (doDelete)
+ delete aWidget;
+ }
+}
+
+Rect WidgetContainer::GetRect()
+{
+ return Rect(mX, mY, mWidth, mHeight);
+}
+
+bool WidgetContainer::Intersects(WidgetContainer* theWidget)
+{
+ return GetRect().Intersects(theWidget->GetRect());
+}
+
+void WidgetContainer::AddWidget(Widget* theWidget)
+{
+ if (std::find(mWidgets.begin(), mWidgets.end(), theWidget) == mWidgets.end())
+ {
+ InsertWidgetHelper(mWidgets.end(),theWidget);
+ theWidget->mWidgetManager = mWidgetManager;
+ theWidget->mParent = this;
+
+ if (mWidgetManager != NULL)
+ {
+ theWidget->AddedToManager(mWidgetManager);
+ theWidget->MarkDirtyFull();
+ mWidgetManager->RehupMouse();
+ }
+
+ MarkDirty();
+ }
+}
+
+bool WidgetContainer::HasWidget(Widget* theWidget)
+{
+ return std::find(mWidgets.begin(), mWidgets.end(), theWidget) != mWidgets.end();
+}
+
+void WidgetContainer::RemoveWidget(Widget* theWidget)
+{
+ WidgetList::iterator anItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (anItr != mWidgets.end())
+ {
+ theWidget->WidgetRemovedHelper();
+ theWidget->mParent = NULL;
+
+ bool erasedCur = (anItr == mUpdateIterator);
+ mWidgets.erase(anItr++);
+ if (erasedCur)
+ {
+ mUpdateIterator = anItr;
+ mUpdateIteratorModified = true;
+ }
+ }
+}
+
+Widget* WidgetContainer::GetWidgetAtHelper(int x, int y, int theFlags, bool* found, int* theWidgetX, int* theWidgetY)
+{
+ bool belowModal = false;
+
+ ModFlags(theFlags, mWidgetFlagsMod);
+
+ WidgetList::reverse_iterator anItr = mWidgets.rbegin();
+ while (anItr != mWidgets.rend())
+ {
+ Widget* aWidget = *anItr;
+
+ int aCurFlags = theFlags;
+ ModFlags(aCurFlags, aWidget->mWidgetFlagsMod);
+ if (belowModal) ModFlags(aCurFlags, mWidgetManager->mBelowModalFlagsMod);
+
+ if (aCurFlags & WIDGETFLAGS_ALLOW_MOUSE)
+ {
+ if (aWidget->mVisible)
+ {
+ bool childFound;
+ Widget* aCheckWidget = aWidget->GetWidgetAtHelper(x - aWidget->mX, y - aWidget->mY, aCurFlags, &childFound, theWidgetX, theWidgetY);
+ if ((aCheckWidget != NULL) || (childFound))
+ {
+ *found = true;
+ return aCheckWidget;
+ }
+
+ if ((aWidget->mMouseVisible) && (aWidget->GetInsetRect().Contains(x, y)))
+ {
+ *found = true;
+
+ if (aWidget->IsPointVisible(x-aWidget->mX,y-aWidget->mY))
+ {
+ if (theWidgetX)
+ *theWidgetX = x - aWidget->mX;
+ if (theWidgetY)
+ *theWidgetY = y - aWidget->mY;
+ return aWidget;
+ }
+ }
+ }
+ }
+
+ belowModal |= aWidget == mWidgetManager->mBaseModalWidget;
+
+ ++anItr;
+ }
+
+ *found = false;
+ return NULL;
+}
+
+bool WidgetContainer::IsBelowHelper(Widget* theWidget1, Widget* theWidget2, bool* found)
+{
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+
+ if (aWidget == theWidget1)
+ {
+ *found = true;
+ return true;
+ }
+ else if (aWidget == theWidget2)
+ {
+ *found = true;
+ return false;
+ }
+
+ bool result = aWidget->IsBelowHelper(theWidget1, theWidget2, found);
+ if (*found)
+ return result;
+
+ ++anItr;
+ }
+
+ return false;
+}
+
+bool WidgetContainer::IsBelow(Widget* theWidget1, Widget* theWidget2)
+{
+ bool found = false;
+ return IsBelowHelper(theWidget1, theWidget2, &found);
+}
+
+void WidgetContainer::MarkAllDirty()
+{
+ MarkDirty();
+
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ (*anItr)->mDirty = true;
+ (*anItr)->MarkAllDirty();
+ ++anItr;
+ }
+}
+
+void WidgetContainer::InsertWidgetHelper(const WidgetList::iterator &where, Widget *theWidget)
+{
+ // Search forwards
+ WidgetList::iterator anItr = where;
+ while (anItr!=mWidgets.end())
+ {
+ Widget *aWidget = *anItr;
+ if (aWidget->mZOrder >= theWidget->mZOrder)
+ {
+ if (anItr!=mWidgets.begin())
+ {
+ WidgetList::iterator anItr2 = anItr;
+ anItr2--;
+ aWidget = *anItr;
+ if (aWidget->mZOrder>theWidget->mZOrder) // need to search backwards
+ break;
+ }
+
+ mWidgets.insert(anItr,theWidget);
+ return;
+ }
+ ++anItr;
+ }
+
+ // Search backwards
+ while (anItr!=mWidgets.begin())
+ {
+ --anItr;
+ Widget *aWidget = *anItr;
+ if (aWidget->mZOrder <= theWidget->mZOrder)
+ {
+ mWidgets.insert(++anItr,theWidget);
+ return;
+ }
+ }
+
+ // It goes at the beginning
+ mWidgets.push_front(theWidget);
+}
+
+void WidgetContainer::BringToFront(Widget* theWidget)
+{
+ WidgetList::iterator anItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (anItr != mWidgets.end())
+ {
+ if (anItr == mUpdateIterator)
+ {
+ mUpdateIterator++;
+ mUpdateIteratorModified = true;
+ }
+
+ mWidgets.erase(anItr);
+ InsertWidgetHelper(mWidgets.end(),theWidget);
+
+ theWidget->OrderInManagerChanged();
+ }
+}
+
+void WidgetContainer::BringToBack(Widget* theWidget)
+{
+ WidgetList::iterator anItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (anItr != mWidgets.end())
+ {
+ if (anItr == mUpdateIterator)
+ {
+ mUpdateIterator++;
+ mUpdateIteratorModified = true;
+ }
+
+ mWidgets.erase(anItr);
+ InsertWidgetHelper(mWidgets.begin(),theWidget);
+
+ theWidget->OrderInManagerChanged();
+ }
+}
+
+void WidgetContainer::PutBehind(Widget* theWidget, Widget* theRefWidget)
+{
+ WidgetList::iterator anItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (anItr != mWidgets.end())
+ {
+ if (anItr == mUpdateIterator)
+ {
+ mUpdateIterator++;
+ mUpdateIteratorModified = true;
+ }
+
+ mWidgets.erase(anItr);
+ anItr = std::find(mWidgets.begin(), mWidgets.end(), theRefWidget);
+ InsertWidgetHelper(anItr, theWidget);
+
+ theWidget->OrderInManagerChanged();
+ }
+}
+
+void WidgetContainer::PutInfront(Widget* theWidget, Widget* theRefWidget)
+{
+ WidgetList::iterator anItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (anItr != mWidgets.end())
+ {
+ if (anItr == mUpdateIterator)
+ {
+ mUpdateIterator++;
+ mUpdateIteratorModified = true;
+ }
+
+ mWidgets.erase(anItr);
+ anItr = std::find(mWidgets.begin(), mWidgets.end(), theRefWidget);
+ if (anItr != mWidgets.end())
+ anItr++;
+ InsertWidgetHelper(anItr, theWidget);
+
+ theWidget->OrderInManagerChanged();
+ }
+}
+
+Point WidgetContainer::GetAbsPos() // relative to top level
+{
+ if (mParent==NULL)
+ return Point(mX,mY);
+ else
+ return Point(mX,mY) + mParent->GetAbsPos();
+}
+
+void WidgetContainer::AddedToManager(WidgetManager* theWidgetManager)
+{
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* theWidget = *anItr;
+
+ theWidget->mWidgetManager = theWidgetManager;
+ theWidget->AddedToManager(theWidgetManager);
+ ++anItr;
+
+ MarkDirty();
+ }
+}
+
+void WidgetContainer::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ for (WidgetList::iterator anItr = mWidgets.begin(); anItr != mWidgets.end(); ++anItr)
+ {
+ Widget* aWidget = *anItr;
+
+ theWidgetManager->DisableWidget(aWidget);
+ aWidget->RemovedFromManager(theWidgetManager);
+ aWidget->mWidgetManager = NULL;
+ }
+
+ if (theWidgetManager->mPopupCommandWidget==this)
+ theWidgetManager->mPopupCommandWidget = NULL;
+}
+
+void WidgetContainer::MarkDirty()
+{
+ if (mParent != NULL)
+ mParent->MarkDirty(this);
+ else
+ mDirty = true;
+}
+
+void WidgetContainer::MarkDirtyFull()
+{
+ if (mParent != NULL)
+ mParent->MarkDirtyFull(this);
+ else
+ mDirty = true;
+}
+
+void WidgetContainer::MarkDirtyFull(WidgetContainer* theWidget)
+{
+ // Mark all things dirty that are under or over this widget
+
+ // Mark ourselves dirty
+ MarkDirtyFull();
+
+ theWidget->mDirty = true;
+
+ // Top-level windows are treated differently, as marking a child dirty always
+ // causes a parent redraw which always causes all children to redraw
+ if (mParent != NULL)
+ return;
+
+ WidgetList::iterator aFoundWidgetItr = std::find(mWidgets.begin(), mWidgets.end(), theWidget);
+ if (aFoundWidgetItr == mWidgets.end())
+ return;
+
+ WidgetList::iterator anItr = aFoundWidgetItr;
+ if (anItr != mWidgets.begin())
+ {
+ anItr--;
+
+ for (;;)
+ {
+ Widget* aWidget = *anItr;
+
+ if (aWidget->mVisible)
+ {
+ if ((!aWidget->mHasTransparencies) && (!aWidget->mHasAlpha))
+ {
+ // Clip the widget's bounds to the screen and check if it fully overlapped by this non-transparent widget underneath it
+ // If it is fully overlapped then we can stop marking dirty underneath it since it's not transparent.
+ Rect aRect = Rect(theWidget->mX,theWidget->mY,theWidget->mWidth,theWidget->mHeight).Intersection(Rect(0,0,mWidth,mHeight));
+ if ((aWidget->Contains(aRect.mX, aRect.mY) &&
+ (aWidget->Contains(aRect.mX + aRect.mWidth - 1, aRect.mY + aRect.mHeight - 1))))
+ {
+ // If this widget is fully contained within a lower widget, there is no need to dig down
+ // any deeper.
+ aWidget->MarkDirty();
+ break;
+ }
+ }
+
+ if (aWidget->Intersects(theWidget))
+ MarkDirty(aWidget);
+ }
+
+ if (anItr == mWidgets.begin())
+ break;
+
+ --anItr;
+ }
+ }
+
+ anItr = aFoundWidgetItr;
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+ if ((aWidget->mVisible) && (aWidget->Intersects(theWidget)))
+ MarkDirty(aWidget);
+
+ ++anItr;
+ }
+}
+
+void WidgetContainer::MarkDirty(WidgetContainer* theWidget)
+{
+ if (theWidget->mDirty)
+ return;
+
+ // Only mark things dirty that are on top of this widget
+ // Mark ourselves dirty
+ MarkDirty();
+
+ theWidget->mDirty = true;
+
+ // Top-level windows are treated differently, as marking a child dirty always
+ // causes a parent redraw which always causes all children to redraw
+ if (mParent != NULL)
+ return;
+
+ if (theWidget->mHasAlpha)
+ MarkDirtyFull(theWidget);
+ else
+ {
+ bool found = false;
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+ if (aWidget == theWidget)
+ found = true;
+ else if (found)
+ {
+ if ((aWidget->mVisible) && (aWidget->Intersects(theWidget)))
+ MarkDirty(aWidget);
+ }
+
+ ++anItr;
+ }
+ }
+}
+
+void WidgetContainer::Update()
+{
+ mUpdateCnt++;
+}
+
+void WidgetContainer::UpdateAll(ModalFlags* theFlags)
+{
+ AutoModalFlags anAutoModalFlags(theFlags, mWidgetFlagsMod);
+
+ if (theFlags->GetFlags() & WIDGETFLAGS_MARK_DIRTY)
+ MarkDirty();
+
+ // Can update?
+ WidgetManager *aWidgetManager = mWidgetManager;
+ if (aWidgetManager==NULL)
+ return;
+
+ if (theFlags->GetFlags() & WIDGETFLAGS_UPDATE)
+ {
+ if (mLastWMUpdateCount != mWidgetManager->mUpdateCnt)
+ {
+ mLastWMUpdateCount = mWidgetManager->mUpdateCnt;
+ Update();
+ }
+ }
+
+ mUpdateIterator = mWidgets.begin();
+
+ while (mUpdateIterator != mWidgets.end())
+ {
+ mUpdateIteratorModified = false;
+
+ Widget* aWidget = *mUpdateIterator;
+ if (aWidget == aWidgetManager->mBaseModalWidget)
+ theFlags->mIsOver = true;
+
+ aWidget->UpdateAll(theFlags);
+
+ if (!mUpdateIteratorModified)
+ ++mUpdateIterator;
+ }
+
+ mUpdateIteratorModified = true; // prevent incrementing iterator off the end of the list
+}
+
+void WidgetContainer::UpdateF(float theFrac)
+{
+}
+
+void WidgetContainer::UpdateFAll(ModalFlags* theFlags, float theFrac)
+{
+ AutoModalFlags anAutoModalFlags(theFlags, mWidgetFlagsMod);
+
+ // Can update?
+ if (theFlags->GetFlags() & WIDGETFLAGS_UPDATE)
+ {
+ UpdateF(theFrac);
+ }
+
+ mUpdateIterator = mWidgets.begin();
+ while (mUpdateIterator != mWidgets.end())
+ {
+ mUpdateIteratorModified = false;
+
+ Widget* aWidget = *mUpdateIterator;
+ if (aWidget == mWidgetManager->mBaseModalWidget)
+ theFlags->mIsOver = true;
+
+ aWidget->UpdateFAll(theFlags, theFrac);
+
+ if (!mUpdateIteratorModified)
+ ++mUpdateIterator;
+ }
+
+ mUpdateIteratorModified = true; // prevent incrementing iterator off the end of the list
+}
+
+void WidgetContainer::Draw(Graphics* g)
+{
+}
+
+void WidgetContainer::DrawAll(ModalFlags* theFlags, Graphics* g)
+{
+ if (mPriority > mWidgetManager->mMinDeferredOverlayPriority)
+ mWidgetManager->FlushDeferredOverlayWidgets(mPriority);
+
+ AutoModalFlags anAutoModalFlags(theFlags, mWidgetFlagsMod);
+
+ if ((mClip) && (theFlags->GetFlags() & WIDGETFLAGS_CLIP))
+ g->ClipRect(0, 0, mWidth, mHeight);
+
+ if (mWidgets.size() == 0)
+ {
+ if (theFlags->GetFlags() & WIDGETFLAGS_DRAW)
+ Draw(g);
+ return;
+ }
+
+ if (theFlags->GetFlags() & WIDGETFLAGS_DRAW)
+ {
+ g->PushState();
+ Draw(g);
+ g->PopState();
+ }
+
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+
+ if (aWidget->mVisible)
+ {
+ if (aWidget == mWidgetManager->mBaseModalWidget)
+ theFlags->mIsOver = true;
+
+ Graphics aClipG(*g);
+ aClipG.Translate(aWidget->mX, aWidget->mY);
+ aWidget->DrawAll(theFlags, &aClipG);
+ aWidget->mDirty = false;
+ }
+
+ ++anItr;
+ }
+}
+
+void WidgetContainer::SysColorChanged()
+{
+}
+
+void WidgetContainer::SysColorChangedAll()
+{
+ SysColorChanged();
+
+ static int aDepthCount = 0;
+ if (mWidgets.size() > 0)
+ aDepthCount++;
+
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+
+ aWidget->SysColorChangedAll();
+ ++anItr;
+ }
+}
+
+void WidgetContainer::DisableWidget(Widget* theWidget)
+{
+}
+
+void WidgetContainer::SetFocus(Widget* theWidget)
+{
+} \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/WidgetContainer.h b/osframework/source/SexyAppFramework/WidgetContainer.h
new file mode 100644
index 0000000..d587f15
--- /dev/null
+++ b/osframework/source/SexyAppFramework/WidgetContainer.h
@@ -0,0 +1,87 @@
+#ifndef __WIDGETCONTAINER_H__
+#define __WIDGETCONTAINER_H__
+
+#include "Common.h"
+#include "Rect.h"
+#include "Flags.h"
+
+namespace Sexy
+{
+
+class Graphics;
+class Widget;
+class WidgetManager;
+
+typedef std::list<Widget*> WidgetList;
+
+
+class WidgetContainer
+{
+public:
+ WidgetList mWidgets;
+ WidgetManager* mWidgetManager;
+ WidgetContainer* mParent;
+
+ bool mUpdateIteratorModified;
+ WidgetList::iterator mUpdateIterator;
+ ulong mLastWMUpdateCount;
+ int mUpdateCnt;
+ bool mDirty;
+ int mX;
+ int mY;
+ int mWidth;
+ int mHeight;
+ bool mHasAlpha;
+ bool mClip;
+ FlagsMod mWidgetFlagsMod;
+ int mPriority;
+ int mZOrder;
+
+public:
+ Widget* GetWidgetAtHelper(int x, int y, int theFlags, bool* found, int* theWidgetX, int* theWidgetY);
+ bool IsBelowHelper(Widget* theWidget1, Widget* theWidget2, bool* found);
+ void InsertWidgetHelper(const WidgetList::iterator &where, Widget *theWidget);
+
+public:
+ WidgetContainer();
+ virtual ~WidgetContainer();
+
+ virtual Rect GetRect();
+ virtual bool Intersects(WidgetContainer* theWidget);
+
+ virtual void AddWidget(Widget* theWidget);
+ virtual void RemoveWidget(Widget* theWidget);
+ virtual bool HasWidget(Widget* theWidget);
+ virtual void DisableWidget(Widget* theWidget);
+ virtual void RemoveAllWidgets(bool doDelete = false, bool recursive = false);
+
+ virtual void SetFocus(Widget* theWidget);
+ virtual bool IsBelow(Widget* theWidget1, Widget* theWidget2);
+ virtual void MarkAllDirty();
+ virtual void BringToFront(Widget* theWidget);
+ virtual void BringToBack(Widget* theWidget);
+ virtual void PutBehind(Widget* theWidget, Widget* theRefWidget);
+ virtual void PutInfront(Widget* theWidget, Widget* theRefWidget);
+ virtual Point GetAbsPos(); // relative to top level
+
+ virtual void MarkDirty();
+ virtual void MarkDirtyFull();
+ virtual void MarkDirtyFull(WidgetContainer* theWidget);
+ virtual void MarkDirty(WidgetContainer* theWidget);
+
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ virtual void Update();
+ virtual void UpdateAll(ModalFlags* theFlags);
+ virtual void UpdateF(float theFrac);
+ virtual void UpdateFAll(ModalFlags* theFlags, float theFrac);
+ virtual void Draw(Graphics* g);
+ virtual void DrawAll(ModalFlags* theFlags, Graphics* g);
+ virtual void SysColorChangedAll();
+ virtual void SysColorChanged();
+};
+
+};
+
+#endif //__WIDGETCONTAINER_H__
diff --git a/osframework/source/SexyAppFramework/WidgetManager.cpp b/osframework/source/SexyAppFramework/WidgetManager.cpp
new file mode 100644
index 0000000..0382ba8
--- /dev/null
+++ b/osframework/source/SexyAppFramework/WidgetManager.cpp
@@ -0,0 +1,806 @@
+#include "WidgetManager.h"
+#include "Widget.h"
+#include "Graphics.h"
+#include "Image.h"
+#include "KeyCodes.h"
+#include "DDImage.h"
+#include "SexyAppBase.h"
+#include "PerfTimer.h"
+#include "Debug.h"
+
+using namespace Sexy;
+using namespace std;
+
+WidgetManager::WidgetManager(SexyAppBase* theApp)
+{
+ mApp = theApp;
+
+ mMinDeferredOverlayPriority = 0x7FFFFFFF;
+ mWidgetManager = this;
+ mMouseIn = false;
+ mDefaultTab = NULL;
+ mImage = NULL;
+ mLastHadTransients = false;
+ mPopupCommandWidget = NULL;
+ mFocusWidget = NULL;
+ mLastDownWidget = NULL;
+ mOverWidget = NULL;
+ mBaseModalWidget = NULL;
+ mDefaultBelowModalFlagsMod.mRemoveFlags = WIDGETFLAGS_ALLOW_MOUSE | WIDGETFLAGS_ALLOW_FOCUS;
+ mWidth = 0;
+ mHeight = 0;
+ mHasFocus = true;
+ mUpdateCnt = 0;
+ mLastDownButtonId = 0;
+ mDownButtons = 0;
+ mActualDownButtons = 0;
+ mWidgetFlags = WIDGETFLAGS_UPDATE | WIDGETFLAGS_DRAW | WIDGETFLAGS_CLIP |
+ WIDGETFLAGS_ALLOW_MOUSE | WIDGETFLAGS_ALLOW_FOCUS;
+
+ for (int i = 0; i < 0xFF; i++)
+ mKeyDown[i] = false;
+}
+
+WidgetManager::~WidgetManager()
+{
+ FreeResources();
+}
+
+void WidgetManager::FreeResources()
+{
+
+}
+
+void WidgetManager::DisableWidget(Widget* theWidget)
+{
+ if (mOverWidget == theWidget)
+ {
+ Widget* aOverWidget = mOverWidget;
+ mOverWidget = NULL;
+ MouseLeave(aOverWidget);
+ }
+
+ if (mLastDownWidget == theWidget)
+ {
+ Widget* aLastDownWidget = mLastDownWidget;
+ mLastDownWidget = NULL;
+ DoMouseUps(aLastDownWidget, mDownButtons);
+ mDownButtons = 0;
+ }
+
+ if (mFocusWidget == theWidget)
+ {
+ Widget* aFocusWidget = mFocusWidget;
+ mFocusWidget = NULL;
+ aFocusWidget->LostFocus();
+ }
+
+ if (mBaseModalWidget == theWidget)
+ mBaseModalWidget = NULL;
+}
+
+int WidgetManager::GetWidgetFlags()
+{
+ return mHasFocus ? mWidgetFlags : GetModFlags(mWidgetFlags, mLostFocusFlagsMod);
+}
+
+Widget* WidgetManager::GetAnyWidgetAt(int x, int y, int* theWidgetX, int* theWidgetY)
+{
+ bool found;
+ return GetWidgetAtHelper(x, y, GetWidgetFlags(), &found, theWidgetX, theWidgetY);
+}
+
+Widget* WidgetManager::GetWidgetAt(int x, int y, int* theWidgetX, int* theWidgetY)
+{
+ Widget* aWidget = GetAnyWidgetAt(x, y, theWidgetX, theWidgetY);
+ if ((aWidget != NULL) && (aWidget->mDisabled))
+ aWidget = NULL;
+ return aWidget;
+}
+
+bool WidgetManager::IsLeftButtonDown()
+{
+ return (mActualDownButtons&1)?true:false;
+}
+
+bool WidgetManager::IsMiddleButtonDown()
+{
+ return (mActualDownButtons&4)?true:false;
+}
+
+bool WidgetManager::IsRightButtonDown()
+{
+ return (mActualDownButtons&2)?true:false;
+}
+
+void WidgetManager::DoMouseUps()
+{
+ if (mLastDownWidget!=NULL && mDownButtons!=0)
+ {
+ DoMouseUps(mLastDownWidget, mDownButtons);
+ mDownButtons = 0;
+ mLastDownWidget = NULL;
+ }
+}
+
+void WidgetManager::DeferOverlay(Widget* theWidget, int thePriority)
+{
+ mDeferredOverlayWidgets.push_back(std::pair<Widget*, int>(theWidget, thePriority));
+ if (thePriority < mMinDeferredOverlayPriority)
+ mMinDeferredOverlayPriority = thePriority;
+}
+
+void WidgetManager::FlushDeferredOverlayWidgets(int theMaxPriority)
+{
+ for (;;)
+ {
+ int aNextMinPriority = 0x7FFFFFFF;
+
+ for (int i = 0; i < (int) mDeferredOverlayWidgets.size(); i++)
+ {
+ Widget* aWidget = mDeferredOverlayWidgets[i].first;
+ if (aWidget != NULL)
+ {
+ int aPriority = mDeferredOverlayWidgets[i].second;
+
+ if (aPriority == mMinDeferredOverlayPriority)
+ {
+ // Overlays don't get clipped
+ Graphics g(*mCurG);
+ g.Translate(-mMouseDestRect.mX, -mMouseDestRect.mY);
+ g.Translate(aWidget->mX, aWidget->mY);
+ g.SetFastStretch(!g.Is3D());
+ g.SetLinearBlend(g.Is3D());
+
+ aWidget->DrawOverlay(&g, aPriority);
+ mDeferredOverlayWidgets[i].first = NULL;
+ }
+ else
+ {
+ if (aPriority < aNextMinPriority)
+ aNextMinPriority = aPriority;
+ }
+ }
+ }
+
+ mMinDeferredOverlayPriority = aNextMinPriority;
+ if (aNextMinPriority == 0x7FFFFFFF)
+ {
+ // No more widgets lined up for overlays, clear our vector
+ mDeferredOverlayWidgets.resize(0);
+ break;
+ }
+
+ // Lowest overlay priority is higher or equal to our current widget,
+ // so continue deferring
+ if (aNextMinPriority >= theMaxPriority)
+ break;
+ }
+}
+
+void WidgetManager::DoMouseUps(Widget* theWidget, ulong theDownCode)
+{
+ int aClickCountTable[3] = { 1,-1, 3 };
+ for (int i = 0; i < 3; i++)
+ {
+ if ((theDownCode & (1 << i)) != 0)
+ {
+ theWidget->mIsDown = false;
+ theWidget->MouseUp(mLastMouseX - theWidget->mX, mLastMouseY - theWidget->mY, aClickCountTable[i]);
+ }
+ }
+}
+
+void WidgetManager::RemapMouse(int& theX, int& theY)
+{
+ theX = ( theX - mMouseSourceRect.mX ) * mMouseDestRect.mWidth / mMouseSourceRect.mWidth + mMouseDestRect.mX;
+ theY = ( theY - mMouseSourceRect.mY ) * mMouseDestRect.mHeight / mMouseSourceRect.mHeight + mMouseDestRect.mY;
+}
+
+void WidgetManager::MouseEnter(Widget* theWidget)
+{
+ theWidget->mIsOver = true;
+
+ theWidget->MouseEnter();
+ if (theWidget->mDoFinger)
+ theWidget->ShowFinger(true);
+}
+
+void WidgetManager::MouseLeave(Widget* theWidget)
+{
+ theWidget->mIsOver = false;
+
+ theWidget->MouseLeave();
+ if (theWidget->mDoFinger)
+ theWidget->ShowFinger(false);
+}
+
+void WidgetManager::SetBaseModal(Widget* theWidget, const FlagsMod& theBelowFlagsMod)
+{
+ mBaseModalWidget = theWidget;
+ mBelowModalFlagsMod = theBelowFlagsMod;
+
+ if ((mOverWidget != NULL) && (mBelowModalFlagsMod.mRemoveFlags & WIDGETFLAGS_ALLOW_MOUSE) &&
+ (IsBelow(mOverWidget, mBaseModalWidget)))
+ {
+ Widget* aWidget = mOverWidget;
+ mOverWidget = NULL;
+ MouseLeave(aWidget);
+ }
+
+ if ((mLastDownWidget != NULL) && (mBelowModalFlagsMod.mRemoveFlags & WIDGETFLAGS_ALLOW_MOUSE) &&
+ (IsBelow(mLastDownWidget, mBaseModalWidget)))
+ {
+ Widget* aWidget = mLastDownWidget;
+ int aDownButtons = mDownButtons;
+ mDownButtons = 0;
+ mLastDownWidget = NULL;
+ DoMouseUps(aWidget, aDownButtons);
+ }
+
+ if ((mFocusWidget != NULL) && (mBelowModalFlagsMod.mRemoveFlags & WIDGETFLAGS_ALLOW_FOCUS) &&
+ (IsBelow(mFocusWidget, mBaseModalWidget)))
+ {
+ Widget* aWidget = mFocusWidget;
+ mFocusWidget = NULL;
+ aWidget->LostFocus();
+ }
+}
+
+void WidgetManager::AddBaseModal(Widget* theWidget, const FlagsMod& theBelowFlagsMod)
+{
+ PreModalInfo aPreModalInfo;
+ aPreModalInfo.mBaseModalWidget = theWidget;
+ aPreModalInfo.mPrevBaseModalWidget = mBaseModalWidget;
+ aPreModalInfo.mPrevFocusWidget = mFocusWidget;
+ aPreModalInfo.mPrevBelowModalFlagsMod = mBelowModalFlagsMod;
+ mPreModalInfoList.push_back(aPreModalInfo);
+
+ SetBaseModal(theWidget, theBelowFlagsMod);
+}
+
+void WidgetManager::AddBaseModal(Widget* theWidget)
+{
+ AddBaseModal(theWidget, mDefaultBelowModalFlagsMod);
+}
+
+void WidgetManager::RemoveBaseModal(Widget* theWidget)
+{
+ DBG_ASSERT(mPreModalInfoList.size() > 0);
+
+ bool first = true;
+
+ while (mPreModalInfoList.size() > 0)
+ {
+ PreModalInfo* aPreModalInfo = &mPreModalInfoList.back();
+
+ if ((first) && (aPreModalInfo->mBaseModalWidget != theWidget))
+ {
+ // We don't remove it yet, because we want to restore
+ // its keyboard focused widget and crap later
+ return;
+ }
+
+ // If we removed a widget's self from pre-modal info before
+ // then that means the dialog got removed out-of-order but we
+ // deferred setting the state back until now
+ bool done = (aPreModalInfo->mPrevBaseModalWidget != NULL) ||
+ (mPreModalInfoList.size() == 1);
+
+ SetBaseModal(aPreModalInfo->mPrevBaseModalWidget,
+ aPreModalInfo->mPrevBelowModalFlagsMod);
+
+ if (mFocusWidget == NULL)
+ {
+ mFocusWidget = aPreModalInfo->mPrevFocusWidget;
+ if (mFocusWidget != NULL)
+ mFocusWidget->GotFocus();
+ }
+
+ mPreModalInfoList.pop_back();
+
+ if (done)
+ break;
+
+ first = false;
+ }
+}
+
+void WidgetManager::Resize(const Rect& theMouseDestRect, const Rect& theMouseSourceRect)
+{
+ mWidth = theMouseDestRect.mWidth + 2 * theMouseDestRect.mX;
+ mHeight = theMouseDestRect.mHeight + 2 * theMouseDestRect.mY;
+ mMouseDestRect = theMouseDestRect;
+ mMouseSourceRect = theMouseSourceRect;
+}
+
+void WidgetManager::SetFocus(Widget* aWidget)
+{
+ if (aWidget==mFocusWidget)
+ return;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->LostFocus();
+
+ if ((aWidget != NULL) && (aWidget->mWidgetManager == this))
+ {
+ mFocusWidget = aWidget;
+
+ if ((mHasFocus) && (mFocusWidget != NULL))
+ mFocusWidget->GotFocus();
+ }
+ else
+ mFocusWidget = NULL;
+}
+
+void WidgetManager::GotFocus()
+{
+ if (!mHasFocus)
+ {
+ mHasFocus = true;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->GotFocus();
+ }
+}
+
+void WidgetManager::LostFocus()
+{
+ if (mHasFocus)
+ {
+ mActualDownButtons = 0;
+ for (int aKeyNum = 0; aKeyNum < 0xFF; aKeyNum++)
+ {
+ if (mKeyDown[aKeyNum])
+ KeyUp((KeyCode) aKeyNum);
+ }
+
+ mHasFocus = false;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->LostFocus();
+ }
+}
+
+void WidgetManager::InitModalFlags(ModalFlags* theModalFlags)
+{
+ theModalFlags->mIsOver = mBaseModalWidget == NULL;
+ theModalFlags->mOverFlags = GetWidgetFlags();
+ theModalFlags->mUnderFlags = GetModFlags(theModalFlags->mOverFlags, mBelowModalFlagsMod);
+}
+
+void WidgetManager::DrawWidgetsTo(Graphics* g)
+{
+ mCurG = g;
+
+ ModalFlags aModalFlags;
+ InitModalFlags(&aModalFlags);
+
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+
+ if (aWidget->mVisible)
+ {
+ Graphics aClipG(*g);
+ aClipG.SetFastStretch(true);
+ aClipG.Translate(aWidget->mX, aWidget->mY);
+ aWidget->DrawAll(&aModalFlags, &aClipG);
+ }
+
+ ++anItr;
+ }
+
+ mCurG = NULL;
+}
+
+bool WidgetManager::DrawScreen()
+{
+ SEXY_AUTO_PERF("WidgetManager::DrawScreen");
+ //DWORD start = timeGetTime();
+
+ ModalFlags aModalFlags;
+ InitModalFlags(&aModalFlags);
+
+ bool drewStuff = false;
+
+ int aDirtyCount = 0;
+ bool hasTransients = false;
+ bool hasDirtyTransients = false;
+
+ // Survey
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+ if (aWidget->mDirty)
+ aDirtyCount++;
+ ++anItr;
+ }
+
+ mMinDeferredOverlayPriority = 0x7FFFFFFF;
+ mDeferredOverlayWidgets.resize(0);
+
+ Graphics aScrG(mImage);
+ mCurG = &aScrG;
+
+ DDImage* aDDImage = dynamic_cast<DDImage*>(mImage);
+ bool surfaceLocked = false;
+ if (aDDImage != NULL)
+ surfaceLocked = aDDImage->LockSurface();
+
+ if (aDirtyCount > 0)
+ {
+ Graphics g(aScrG);
+ g.Translate(-mMouseDestRect.mX, -mMouseDestRect.mY);
+ bool is3D = mApp->Is3DAccelerated();
+
+ WidgetList::iterator anItr = mWidgets.begin();
+ while (anItr != mWidgets.end())
+ {
+ Widget* aWidget = *anItr;
+
+ if (aWidget == mWidgetManager->mBaseModalWidget)
+ aModalFlags.mIsOver = true;
+
+ if ((aWidget->mDirty) && (aWidget->mVisible))
+ {
+ Graphics aClipG(g);
+ aClipG.SetFastStretch(!is3D);
+ aClipG.SetLinearBlend(is3D);
+ aClipG.Translate(aWidget->mX, aWidget->mY);
+ aWidget->DrawAll(&aModalFlags, &aClipG);
+
+ aDirtyCount++;
+ drewStuff = true;
+ aWidget->mDirty = false;
+ }
+
+ ++anItr;
+ }
+ }
+
+ FlushDeferredOverlayWidgets(0x7FFFFFFF);
+
+ if (aDDImage != NULL && surfaceLocked)
+ aDDImage->UnlockSurface();
+
+ mCurG = NULL;
+
+ return drewStuff;
+}
+
+bool WidgetManager::UpdateFrame()
+{
+ SEXY_AUTO_PERF("WidgetManager::UpdateFrame");
+
+ ModalFlags aModalFlags;
+ InitModalFlags(&aModalFlags);
+
+ // Keep us from having mLastWMUpdateCount interfere with our own updating
+ mUpdateCnt++;
+ mLastWMUpdateCount = mUpdateCnt;
+ UpdateAll(&aModalFlags);
+
+ return mDirty;
+}
+
+bool WidgetManager::UpdateFrameF(float theFrac)
+{
+ SEXY_AUTO_PERF("WidgetManager::UpdateFrame");
+
+ ModalFlags aModalFlags;
+ InitModalFlags(&aModalFlags);
+
+ UpdateFAll(&aModalFlags, theFrac);
+ return mDirty;
+}
+
+void WidgetManager::SetPopupCommandWidget(Widget* theList)
+{
+ mPopupCommandWidget = theList;
+ AddWidget(mPopupCommandWidget);
+}
+
+void WidgetManager::RemovePopupCommandWidget()
+{
+ if (mPopupCommandWidget != NULL)
+ {
+ Widget *aWidget = mPopupCommandWidget;
+ mPopupCommandWidget = NULL;
+ RemoveWidget(aWidget);
+ }
+}
+
+void WidgetManager::MousePosition(int x, int y)
+{
+
+ int aLastMouseX = mLastMouseX;
+ int aLastMouseY = mLastMouseY;
+
+ mLastMouseX = x;
+ mLastMouseY = y;
+
+ int aWidgetX;
+ int aWidgetY;
+ Widget* aWidget = GetWidgetAt(x, y, &aWidgetX, &aWidgetY);
+
+ if (aWidget != mOverWidget)
+ {
+ Widget* aLastOverWidget = mOverWidget;
+ mOverWidget = NULL;
+
+ if (aLastOverWidget != NULL)
+ MouseLeave(aLastOverWidget);
+
+ mOverWidget = aWidget;
+ if (aWidget != NULL)
+ {
+ MouseEnter(aWidget);
+ aWidget->MouseMove(aWidgetX, aWidgetY);
+ }
+ }
+ else if ((aLastMouseX != x) || (aLastMouseY != y))
+ {
+ if (aWidget != NULL)
+ aWidget->MouseMove(aWidgetX, aWidgetY);
+ }
+}
+
+void WidgetManager::RehupMouse()
+{
+ if (mLastDownWidget != NULL)
+ {
+ if (mOverWidget != NULL)
+ {
+ Widget* aWidgetOver = GetWidgetAt(mLastMouseX, mLastMouseY, NULL, NULL);
+
+ if (aWidgetOver != mLastDownWidget)
+ {
+ Widget* anOverWidget = mOverWidget;
+ mOverWidget = NULL;
+ MouseLeave(anOverWidget);
+ }
+ }
+ }
+ else if (mMouseIn)
+ MousePosition(mLastMouseX, mLastMouseY);
+}
+
+bool WidgetManager::MouseUp(int x, int y, int theClickCount)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ int aMask;
+
+ if (theClickCount < 0)
+ aMask = 0x02;
+ else if (theClickCount == 3)
+ aMask = 0x04;
+ else
+ aMask = 0x01;
+
+ // Make sure that we thought this button was down anyway - possibly not, if we
+ // disabled the widget already or something
+ mActualDownButtons &= ~aMask;
+ if ((mLastDownWidget != NULL) && ((mDownButtons & aMask) != 0))
+ {
+ Widget* aLastDownWidget = mLastDownWidget;
+
+ mDownButtons &= ~aMask;
+ if (mDownButtons == 0)
+ mLastDownWidget = NULL;
+
+ aLastDownWidget->mIsDown = false;
+ aLastDownWidget->MouseUp(x - aLastDownWidget->mX, y - aLastDownWidget->mY, theClickCount);
+ }
+ else
+ mDownButtons &= ~aMask;
+
+ MousePosition(x, y);
+
+ return true;
+}
+
+bool WidgetManager::MouseDown(int x, int y, int theClickCount)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if (theClickCount < 0)
+ mActualDownButtons |= 0x02;
+ else if (theClickCount == 3)
+ mActualDownButtons |= 0x04;
+ else
+ mActualDownButtons |= 0x01;
+
+ MousePosition(x, y);
+
+ if ((mPopupCommandWidget != NULL) && (!mPopupCommandWidget->Contains(x, y)))
+ RemovePopupCommandWidget();
+
+ int aWidgetX;
+ int aWidgetY;
+ Widget* aWidget = GetWidgetAt(x, y, &aWidgetX, &aWidgetY);
+
+ // Begin mouse down options
+/*
+ // Option 1
+ //This code sets a new widget as the mouse drag focus widget and lets the old
+ //mousedownwidget think the buttons popped up.
+ if ((mLastDownWidget != NULL) && (mLastDownWidget != aWidget))
+ {
+ DoMouseUps(mLastDownWidget, mDownButtons);
+ mDownButtons = 0;
+ }
+*/
+ // Option 2
+ // This code passes all button downs to the mLastDownWidget
+ if (mLastDownWidget != NULL)
+ aWidget = mLastDownWidget;
+
+ // End mouse down options
+
+ if (theClickCount < 0)
+ {
+ mLastDownButtonId = -1;
+ mDownButtons |= 0x02;
+ }
+ else if (theClickCount == 3)
+ {
+ mLastDownButtonId = 2;
+ mDownButtons |= 0x04;
+ }
+ else
+ {
+ mLastDownButtonId = 1;
+ mDownButtons |= 0x01;
+ }
+
+ mLastDownWidget = aWidget;
+ if (aWidget != NULL)
+ {
+ if (aWidget->WantsFocus())
+ SetFocus(aWidget);
+
+ aWidget->mIsDown = true;
+ aWidget->MouseDown(aWidgetX, aWidgetY, theClickCount);
+ }
+
+ return true;
+}
+
+bool WidgetManager::MouseMove(int x, int y)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if (mDownButtons)
+ return MouseDrag(x,y);
+
+ mMouseIn = true;
+ MousePosition(x, y);
+
+ return true;
+}
+
+bool WidgetManager::MouseDrag(int x, int y)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ mMouseIn = true;
+ mLastMouseX = x;
+ mLastMouseY = y;
+
+ if ((mOverWidget != NULL) && (mOverWidget != mLastDownWidget))
+ {
+ Widget* anOverWidget = mOverWidget;
+ mOverWidget = NULL;
+ MouseLeave(anOverWidget);
+ }
+
+ if (mLastDownWidget != NULL)
+ {
+ Point anAbsPos = mLastDownWidget->GetAbsPos();
+
+ int aWidgetX = x - anAbsPos.mX;
+ int aWidgetY = y - anAbsPos.mY;
+ mLastDownWidget->MouseDrag(aWidgetX, aWidgetY);
+
+ Widget* aWidgetOver = GetWidgetAt(x, y, NULL, NULL);
+
+ if ((aWidgetOver == mLastDownWidget) && (aWidgetOver != NULL))
+ {
+ if (mOverWidget == NULL)
+ {
+ mOverWidget = mLastDownWidget;
+ MouseEnter(mOverWidget);
+ }
+ }
+ else
+ {
+ if (mOverWidget != NULL)
+ {
+ Widget* anOverWidget = mOverWidget;
+ mOverWidget = NULL;
+ MouseLeave(anOverWidget);
+ }
+ }
+ }
+
+ return true;
+}
+
+bool WidgetManager::MouseExit(int x, int y)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ mMouseIn = false;
+
+ if (mOverWidget != NULL)
+ {
+ MouseLeave(mOverWidget);
+ mOverWidget = NULL;
+ }
+
+ return true;
+}
+
+void WidgetManager::MouseWheel(int theDelta)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->MouseWheel(theDelta);
+}
+
+bool WidgetManager::KeyChar(SexyChar theChar)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if (theChar == KEYCODE_TAB)
+ {
+ //TODO: Check thing
+
+ if (mKeyDown[KEYCODE_CONTROL])
+ {
+ if (mDefaultTab != NULL)
+ mDefaultTab->KeyChar(theChar);
+
+ return true;
+ }
+ }
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->KeyChar(theChar);
+
+ return true;
+}
+
+bool WidgetManager::KeyDown(KeyCode key)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if ((key >= 0) && (key < 0xFF))
+ mKeyDown[key] = true;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->KeyDown(key);
+
+ return true;
+}
+
+bool WidgetManager::KeyUp(KeyCode key)
+{
+ mLastInputUpdateCnt = mUpdateCnt;
+
+ if ((key >= 0) && (key < 0xFF))
+ mKeyDown[key] = false;
+
+ if ((key == KEYCODE_TAB) && (mKeyDown[KEYCODE_CONTROL]))
+ return true;
+
+ if (mFocusWidget != NULL)
+ mFocusWidget->KeyUp(key);
+
+ return true;
+}
diff --git a/osframework/source/SexyAppFramework/WidgetManager.h b/osframework/source/SexyAppFramework/WidgetManager.h
new file mode 100644
index 0000000..3f3c906
--- /dev/null
+++ b/osframework/source/SexyAppFramework/WidgetManager.h
@@ -0,0 +1,134 @@
+#ifndef __WIDGETMANAGER_H__
+#define __WIDGETMANAGER_H__
+
+#include "Common.h"
+#include "KeyCodes.h"
+#include "WidgetContainer.h"
+
+namespace Sexy
+{
+
+class Widget;
+class Image;
+class MemoryImage;
+class SexyAppBase;
+class Graphics;
+
+typedef std::list<Widget*> WidgetList;
+
+enum
+{
+ WIDGETFLAGS_UPDATE = 1,
+ WIDGETFLAGS_MARK_DIRTY = 2,
+ WIDGETFLAGS_DRAW = 4,
+ WIDGETFLAGS_CLIP = 8,
+ WIDGETFLAGS_ALLOW_MOUSE = 16,
+ WIDGETFLAGS_ALLOW_FOCUS = 32,
+};
+
+class PreModalInfo
+{
+public:
+ Widget* mBaseModalWidget;
+ Widget* mPrevBaseModalWidget;
+ Widget* mPrevFocusWidget;
+ FlagsMod mPrevBelowModalFlagsMod;
+};
+
+typedef std::list<PreModalInfo> PreModalInfoList;
+
+typedef std::vector<std::pair<Widget*, int> > DeferredOverlayVector;
+
+class WidgetManager : public WidgetContainer
+{
+public:
+ Widget* mDefaultTab;
+
+ Graphics* mCurG;
+ SexyAppBase* mApp;
+ MemoryImage* mImage;
+ MemoryImage* mTransientImage;
+ bool mLastHadTransients;
+ Widget* mPopupCommandWidget;
+ DeferredOverlayVector mDeferredOverlayWidgets;
+ int mMinDeferredOverlayPriority;
+
+ bool mHasFocus;
+ Widget* mFocusWidget;
+ Widget* mLastDownWidget;
+ Widget* mOverWidget;
+ Widget* mBaseModalWidget;
+ FlagsMod mLostFocusFlagsMod;
+ FlagsMod mBelowModalFlagsMod;
+ FlagsMod mDefaultBelowModalFlagsMod;
+ PreModalInfoList mPreModalInfoList;
+ Rect mMouseDestRect;
+ Rect mMouseSourceRect;
+ bool mMouseIn;
+ int mLastMouseX;
+ int mLastMouseY;
+ int mDownButtons;
+ int mActualDownButtons;
+ int mLastInputUpdateCnt;
+
+ bool mKeyDown[0xFF];
+ int mLastDownButtonId;
+
+ int mWidgetFlags;
+
+protected:
+ int GetWidgetFlags();
+ void MouseEnter(Widget* theWidget);
+ void MouseLeave(Widget* theWidget);
+
+protected:
+ void SetBaseModal(Widget* theWidget, const FlagsMod& theBelowFlagsMod);
+
+public:
+ WidgetManager(SexyAppBase* theApplet);
+ virtual ~WidgetManager();
+
+ void FreeResources();
+ void AddBaseModal(Widget* theWidget, const FlagsMod& theBelowFlagsMod);
+ void AddBaseModal(Widget* theWidget);
+ void RemoveBaseModal(Widget* theWidget);
+ void Resize(const Rect& theMouseDestRect, const Rect& theMouseSourceRect);
+ void DisableWidget(Widget* theWidget);
+ Widget* GetAnyWidgetAt(int x, int y, int* theWidgetX, int* theWidgetY);
+ Widget* GetWidgetAt(int x, int y, int* theWidgetX, int* theWidgetY);
+ void SetFocus(Widget* aWidget);
+ void GotFocus();
+ void LostFocus();
+ void InitModalFlags(ModalFlags* theModalFlags);
+ void DrawWidgetsTo(Graphics* g);
+ void DoMouseUps(Widget* theWidget, ulong theDownCode);
+ void DoMouseUps();
+ void DeferOverlay(Widget* theWidget, int thePriority);
+ void FlushDeferredOverlayWidgets(int theMaxPriority);
+
+ bool DrawScreen();
+ bool UpdateFrame();
+ bool UpdateFrameF(float theFrac);
+ void SetPopupCommandWidget(Widget* theList);
+ void RemovePopupCommandWidget();
+ void MousePosition(int x, int y);
+ void RehupMouse();
+ void RemapMouse(int& theX, int& theY);
+ bool MouseUp(int x, int y, int theClickCount);
+ bool MouseDown(int x, int y, int theClickCount);
+ bool MouseMove(int x, int y);
+ bool MouseDrag(int x, int y);
+ bool MouseExit(int x, int y);
+ void MouseWheel(int theDelta);
+ bool KeyChar(SexyChar theChar);
+ bool KeyDown(KeyCode key);
+ bool KeyUp(KeyCode key);
+
+ bool IsLeftButtonDown();
+ bool IsMiddleButtonDown();
+ bool IsRightButtonDown();
+};
+
+}
+
+#endif // __WIDGETMANAGER_H__ \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/XMLParser.cpp b/osframework/source/SexyAppFramework/XMLParser.cpp
new file mode 100644
index 0000000..6a0ee11
--- /dev/null
+++ b/osframework/source/SexyAppFramework/XMLParser.cpp
@@ -0,0 +1,721 @@
+#include "XMLParser.h"
+#include "Debug.h"
+#include "..\PakLib\PakInterface.h"
+
+using namespace Sexy;
+
+XMLParser::XMLParser()
+{
+ mFile = NULL;
+ mLineNum = 0;
+ mAllowComments = false;
+ mGetCharFunc = &XMLParser::GetUTF8Char;
+ mForcedEncodingType = false;
+}
+
+XMLParser::~XMLParser()
+{
+ if (mFile != NULL)
+ p_fclose(mFile);
+}
+
+void XMLParser::SetEncodingType(XMLEncodingType theEncoding)
+{
+ switch (theEncoding)
+ {
+ case ASCII: mGetCharFunc = &XMLParser::GetAsciiChar; mForcedEncodingType = true; break;
+ case UTF_8: mGetCharFunc = &XMLParser::GetUTF8Char; mForcedEncodingType = true; break;
+ case UTF_16: mGetCharFunc = &XMLParser::GetUTF16Char; mForcedEncodingType = true; break;
+ case UTF_16_LE: mGetCharFunc = &XMLParser::GetUTF16LEChar; mForcedEncodingType = true; break;
+ case UTF_16_BE: mGetCharFunc = &XMLParser::GetUTF16BEChar; mForcedEncodingType = true; break;
+ }
+}
+
+void XMLParser::Fail(const SexyString& theErrorText)
+{
+ mHasFailed = true;
+ mErrorText = theErrorText;
+}
+
+void XMLParser::Init()
+{
+ mSection = _S("");
+ mLineNum = 1;
+ mHasFailed = false;
+ mErrorText = _S("");
+ mFirstChar = true;
+ mByteSwap = false;
+}
+
+bool XMLParser::AddAttribute(XMLElement* theElement, const SexyString& theAttributeKey, const SexyString& theAttributeValue)
+{
+ std::pair<XMLParamMap::iterator,bool> aRet;
+
+ aRet = theElement->mAttributes.insert(XMLParamMap::value_type(theAttributeKey, theAttributeValue));
+ if (!aRet.second)
+ aRet.first->second = theAttributeValue;
+
+ if (theAttributeKey != _S("/"))
+ theElement->mAttributeIteratorList.push_back(aRet.first);
+
+ return aRet.second;
+}
+
+bool XMLParser::GetAsciiChar(wchar_t* theChar, bool* error)
+{
+ wchar_t aChar = 0;
+ if (p_fread(&aChar, 1, 1, mFile) != 1)
+ return false;
+
+ *theChar = aChar;
+ return true;
+}
+
+bool XMLParser::GetUTF8Char(wchar_t* theChar, bool* error)
+{
+ static const unsigned short aMaskData[] = {
+ 0xC0, // 1 extra byte
+ 0xE0, // 2 extra bytes
+ 0xF0, // 3 extra bytes
+ 0xF8, // 4 extra bytes
+ 0xFC // 5 extra bytes
+ };
+ *error = true;
+
+ int aTempChar = 0;
+ if (p_fread(&aTempChar, 1, 1, mFile) == 1)
+ {
+ if ((aTempChar & 0x80) != 0)
+ {
+ if ((aTempChar & 0xC0) != 0xC0) return false; // sanity check: high bit should not be set without the next highest bit being set too.
+
+ int aBytesRead[6];
+ int* aBytesReadPtr = &aBytesRead[0];
+
+ *aBytesReadPtr++ = aTempChar;
+
+ int aLen;
+ for (aLen = 0; aLen < (int)(sizeof(aMaskData)/sizeof(*aMaskData)); ++aLen)
+ {
+ if ( (aTempChar & aMaskData[aLen]) == ((aMaskData[aLen] << 1) & aMaskData[aLen]) ) break;
+ }
+ if (aLen >= (int)(sizeof(aMaskData)/sizeof(*aMaskData))) return false;
+
+ aTempChar &= ~aMaskData[aLen];
+ int aTotalLen = aLen+1;
+
+ DBG_ASSERTE(aTotalLen >= 2 && aTotalLen <= 6);
+
+ int anExtraChar = 0;
+ while (aLen > 0)
+ {
+ if (p_fread(&anExtraChar, 1, 1, mFile) != 1) return false;
+ if ((anExtraChar & 0xC0) != 0x80) return false; // sanity check: high bit set, and next highest bit NOT set.
+
+ *aBytesReadPtr++ = anExtraChar;
+
+ aTempChar = (aTempChar << 6) | (anExtraChar & 0x3F);
+ --aLen;
+ }
+
+ // validate substrings
+ bool valid = true;
+ switch (aTotalLen)
+ {
+ case 2:
+ valid = !((aBytesRead[0] & 0x3E) == 0);
+ break;
+ case 3:
+ valid = !((aBytesRead[0] & 0x1F) == 0 && (aBytesRead[1] & 0x20) == 0);
+ break;
+ case 4:
+ valid = !((aBytesRead[0] & 0x0F) == 0 && (aBytesRead[1] & 0x30) == 0);
+ break;
+ case 5:
+ valid = !((aBytesRead[0] & 0x07) == 0 && (aBytesRead[1] & 0x38) == 0);
+ break;
+ case 6:
+ valid = !((aBytesRead[0] & 0x03) == 0 && (aBytesRead[1] & 0x3C) == 0);
+ break;
+ }
+ if (!valid) return false;
+ }
+
+ if ( (aTempChar >= 0xD800 && aTempChar <= 0xDFFF) || (aTempChar >= 0xFFFE && aTempChar <= 0xFFFF) ) return false;
+
+ if (aTempChar == 0xFEFF && mFirstChar) // zero-width non breaking space as the first char is a byte order marker.
+ {
+ mFirstChar = false;
+ return GetUTF8Char(theChar, error);
+ }
+
+ *theChar = (wchar_t)aTempChar;
+ *error = false;
+ return true;
+ }
+
+ *error = false;
+ return false;
+}
+
+bool XMLParser::GetUTF16Char(wchar_t* theChar, bool* error)
+{
+ wchar_t aTempChar = 0;
+ if (p_fread(&aTempChar, 2, 1, mFile) != 1)
+ return false;
+
+ if (mFirstChar)
+ {
+ mFirstChar = false;
+ if (aTempChar == 0xFEFF)
+ {
+ mByteSwap = false;
+ return GetUTF16Char(theChar, error);
+ }
+ else if (aTempChar == 0xFFFE)
+ {
+ mByteSwap = true;
+ return GetUTF16Char(theChar, error);
+ }
+ }
+ if (mByteSwap) aTempChar = (wchar_t)((aTempChar << 8) | (aTempChar >> 8));
+
+ if ((aTempChar & 0xD800) == 0xD800)
+ {
+ wchar_t aNextChar = 0;
+ if (p_fread(&aNextChar, 2, 1, mFile) != 1)
+ return false;
+
+ if (mByteSwap) aNextChar = (wchar_t)((aNextChar << 8) | (aNextChar >> 8));
+ if ((aNextChar & 0xDC00) == 0xDC00)
+ {
+ *theChar = (wchar_t)((((aTempChar & ~0xD800) << 10) | (aNextChar & ~0xDC00)) + 0x10000);
+ }
+ else return false;
+ }
+ else *theChar = aTempChar;
+
+ return true;
+}
+
+bool XMLParser::GetUTF16LEChar(wchar_t* theChar, bool* error)
+{
+ wchar_t aTempChar = 0;
+ if (p_fread(&aTempChar, 2, 1, mFile) != 1)
+ return false;
+
+ aTempChar = WORD_LITTLEE_TO_NATIVE(aTempChar);
+
+ if ((aTempChar & 0xD800) == 0xD800)
+ {
+ wchar_t aNextChar = 0;
+ if (p_fread(&aNextChar, 2, 1, mFile) != 1)
+ return false;
+
+ aNextChar = WORD_LITTLEE_TO_NATIVE(aTempChar);
+ if ((aNextChar & 0xDC00) == 0xDC00)
+ {
+ *theChar = (wchar_t)((((aTempChar & ~0xD800) << 10) | (aNextChar & ~0xDC00)) + 0x10000);
+ }
+ else return false;
+ }
+
+ return true;
+}
+
+bool XMLParser::GetUTF16BEChar(wchar_t* theChar, bool* error)
+{
+ wchar_t aTempChar = 0;
+ if (p_fread(&aTempChar, 2, 1, mFile) != 1)
+ return false;
+
+ aTempChar = WORD_BIGE_TO_NATIVE(aTempChar);
+
+ if ((aTempChar & 0xD800) == 0xD800)
+ {
+ wchar_t aNextChar = 0;
+ if (p_fread(&aNextChar, 2, 1, mFile) != 1)
+ return false;
+
+ aNextChar = WORD_BIGE_TO_NATIVE(aTempChar);
+ if ((aNextChar & 0xDC00) == 0xDC00)
+ {
+ *theChar = (wchar_t)((((aTempChar & ~0xD800) << 10) | (aNextChar & ~0xDC00)) + 0x10000);
+ }
+ else return false;
+ }
+
+ return true;
+}
+
+bool XMLParser::OpenFile(const std::string& theFileName)
+{
+ mFile = p_fopen(theFileName.c_str(), "r");
+
+ if (mFile == NULL)
+ {
+ mLineNum = 0;
+ Fail(StringToSexyString("Unable to open file " + theFileName));
+ return false;
+ }
+ else if (!mForcedEncodingType)
+ {
+ p_fseek(mFile, 0, SEEK_END);
+ long aFileLen = p_ftell(mFile);
+ p_fseek(mFile, 0, SEEK_SET);
+
+ mGetCharFunc = &XMLParser::GetAsciiChar;
+ if (aFileLen >= 2) // UTF-16?
+ {
+ int aChar1 = p_fgetc(mFile);
+ int aChar2 = p_fgetc(mFile);
+
+ if ( (aChar1 == 0xFF && aChar2 == 0xFE) || (aChar1 == 0xFE && aChar2 == 0xFF) )
+ mGetCharFunc = &XMLParser::GetUTF16Char;
+
+ p_ungetc(aChar2, mFile);
+ p_ungetc(aChar1, mFile);
+ }
+ if (mGetCharFunc = &XMLParser::GetAsciiChar)
+ {
+ if (aFileLen >= 3) // UTF-8?
+ {
+ int aChar1 = p_fgetc(mFile);
+ int aChar2 = p_fgetc(mFile);
+ int aChar3 = p_fgetc(mFile);
+
+ if (aChar1 == 0xEF && aChar2 == 0xBB && aChar3 == 0xBF)
+ mGetCharFunc = &XMLParser::GetUTF8Char;
+
+ p_ungetc(aChar3, mFile);
+ p_ungetc(aChar2, mFile);
+ p_ungetc(aChar1, mFile);
+ }
+ }
+ }
+
+ mFileName = theFileName.c_str();
+ Init();
+ return true;
+}
+
+void XMLParser::SetStringSource(const std::wstring& theString)
+{
+ Init();
+
+ int aSize = theString.size();
+
+ mBufferedText.resize(aSize);
+ for (int i = 0; i < aSize; i++)
+ mBufferedText[i] = theString[aSize - i - 1];
+}
+
+void XMLParser::SetStringSource(const std::string& theString)
+{
+ SetStringSource(StringToWString(theString));
+}
+
+bool XMLParser::NextElement(XMLElement* theElement)
+{
+ for (;;)
+ {
+ theElement->mType = XMLElement::TYPE_NONE;
+ theElement->mSection = mSection;
+ theElement->mValue = _S("");
+ theElement->mAttributes.clear();
+ theElement->mInstruction.erase();
+
+ bool hasSpace = false;
+ bool inQuote = false;
+ bool gotEndQuote = false;
+
+ bool doingAttribute = false;
+ bool AttributeVal = false;
+ std::wstring aAttributeKey;
+ std::wstring aAttributeValue;
+
+ std::wstring aLastAttributeKey;
+
+ for (;;)
+ {
+ // Process character by character
+
+ wchar_t c;
+ int aVal;
+
+ if (mBufferedText.size() > 0)
+ {
+ c = mBufferedText[mBufferedText.size()-1];
+ mBufferedText.pop_back();
+
+ aVal = 1;
+ }
+ else
+ {
+ if (mFile != NULL)
+ {
+ bool error = false;
+ if ((this->*mGetCharFunc)(&c, &error))
+ {
+ aVal = 1;
+ }
+ else
+ {
+ if (error) Fail(_S("Illegal Character"));
+ aVal = 0;
+ }
+ }
+ else
+ {
+ aVal = 0;
+ }
+ }
+
+ if (aVal == 1)
+ {
+ bool processChar = false;
+
+ if (c == L'\n')
+ {
+ mLineNum++;
+ }
+
+ if (theElement->mType == XMLElement::TYPE_COMMENT)
+ {
+ // Just add text to theElement->mInstruction until we find -->
+
+ SexyString* aStrPtr = &theElement->mInstruction;
+
+ *aStrPtr += (SexyChar)c;
+
+ int aLen = aStrPtr->length();
+
+ if ((c == L'>') && (aLen >= 3) && ((*aStrPtr)[aLen - 2] == L'-') && ((*aStrPtr)[aLen - 3] == L'-'))
+ {
+ *aStrPtr = aStrPtr->substr(0, aLen - 3);
+ break;
+ }
+ }
+ else if (theElement->mType == XMLElement::TYPE_INSTRUCTION)
+ {
+ // Just add text to theElement->mInstruction until we find ?>
+
+ SexyString* aStrPtr = &theElement->mValue;
+
+ if ((theElement->mInstruction.length() != 0) || (::iswspace(c)))
+ aStrPtr = &theElement->mInstruction;
+
+ *aStrPtr += (SexyChar)c;
+
+ int aLen = aStrPtr->length();
+
+ if ((c == L'>') && (aLen >= 2) && ((*aStrPtr)[aLen - 2] == L'?'))
+ {
+ *aStrPtr = aStrPtr->substr(0, aLen - 2);
+ break;
+ }
+ }
+ else
+ {
+ if (c == L'"')
+ {
+ inQuote = !inQuote;
+ if (theElement->mType==XMLElement::TYPE_NONE || theElement->mType==XMLElement::TYPE_ELEMENT)
+ processChar = true;
+
+ if (!inQuote)
+ gotEndQuote = true;
+ }
+ else if (!inQuote)
+ {
+ if (c == L'<')
+ {
+ if (theElement->mType == XMLElement::TYPE_ELEMENT)
+ {
+ //TODO: Fix buffered text. Not sure what I meant by that.
+
+ //OLD: mBufferedText = c + mBufferedText;
+
+ mBufferedText.push_back(c);
+ break;
+ }
+
+ if (theElement->mType == XMLElement::TYPE_NONE)
+ {
+ theElement->mType = XMLElement::TYPE_START;
+ }
+ else
+ {
+ Fail(_S("Unexpected '<'"));
+ return false;
+ }
+ }
+ else if (c == L'>')
+ {
+ if (theElement->mType == XMLElement::TYPE_START)
+ {
+ bool insertEnd = false;
+
+ if (aAttributeKey == L"/")
+ {
+ // We will get this if we have a space before the />, so we can ignore it
+ // and go about our business now
+ insertEnd = true;
+ }
+ else
+ {
+ // Probably isn't committed yet
+ if (aAttributeKey.length() > 0)
+ {
+// theElement->mAttributes[aLastAttributeKey] = aAttributeValue;
+
+ aAttributeKey = XMLDecodeString(aAttributeKey);
+ aAttributeValue = XMLDecodeString(aAttributeValue);
+
+ aLastAttributeKey = aAttributeKey;
+ AddAttribute(theElement, WStringToSexyString(aLastAttributeKey), WStringToSexyString(aAttributeValue));
+
+ aAttributeKey = L"";
+ aAttributeValue = L"";
+ }
+
+ if (aLastAttributeKey.length() > 0)
+ {
+ SexyString aVal = theElement->mAttributes[WStringToSexyString(aLastAttributeKey)];
+
+ int aLen = aVal.length();
+
+ if ((aLen > 0) && (aVal[aLen-1] == '/'))
+ {
+ // Its an empty element, fake start and end segments
+// theElement->mAttributes[aLastAttributeKey] = aVal.substr(0, aLen - 1);
+
+ AddAttribute(theElement, WStringToSexyString(aLastAttributeKey), XMLDecodeString(aVal.substr(0, aLen - 1)));
+
+ insertEnd = true;
+ }
+ }
+ else
+ {
+ int aLen = theElement->mValue.length();
+
+ if ((aLen > 0) && (theElement->mValue[aLen-1] == '/'))
+ {
+ // Its an empty element, fake start and end segments
+ theElement->mValue = theElement->mValue.substr(0, aLen - 1);
+ insertEnd = true;
+ }
+ }
+ }
+
+ // Do we want to fake an ending section?
+ if (insertEnd)
+ {
+ SexyString anAddString = _S("</") + theElement->mValue + _S(">");
+
+ int anOldSize = mBufferedText.size();
+ int anAddLength = anAddString.length();
+
+ mBufferedText.resize(anOldSize + anAddLength);
+
+ for (int i = 0; i < anAddLength; i++)
+ mBufferedText[anOldSize + i] = (wchar_t)(anAddString[anAddLength - i - 1]);
+
+ // clear out aAttributeKey, since it contains "/" as its value and will insert
+ // it into the element's attribute map.
+ aAttributeKey = L"";
+
+ //OLD: mBufferedText = "</" + theElement->mValue + ">" + mBufferedText;
+ }
+
+ if (mSection.length() != 0)
+ mSection += _S("/");
+
+ mSection += theElement->mValue;
+
+ break;
+ }
+ else if (theElement->mType == XMLElement::TYPE_END)
+ {
+ int aLastSlash = mSection.rfind(_S('/'));
+ if ((aLastSlash == -1) && (mSection.length() == 0))
+ {
+ Fail(_S("Unexpected End"));
+ return false;
+ }
+
+ SexyString aLastSectionName = mSection.substr(aLastSlash + 1);
+
+ if (aLastSectionName != theElement->mValue)
+ {
+ Fail(_S("End '") + theElement->mValue + _S("' Doesn't Match Start '") + aLastSectionName + _S("'"));
+ return false;
+ }
+
+ if (aLastSlash == -1)
+ mSection.erase(mSection.begin(), mSection.end());
+ else
+ mSection.erase(mSection.begin() + aLastSlash, mSection.end());
+
+ break;
+ }
+ else
+ {
+ Fail(_S("Unexpected '>'"));
+ return false;
+ }
+ }
+ else if ((c == L'/') && (theElement->mType == XMLElement::TYPE_START) && (theElement->mValue == _S("")))
+ {
+ theElement->mType = XMLElement::TYPE_END;
+ }
+ else if ((c == L'?') && (theElement->mType == XMLElement::TYPE_START) && (theElement->mValue == _S("")))
+ {
+ theElement->mType = XMLElement::TYPE_INSTRUCTION;
+ }
+ else if (::isspace((uchar) c))
+ {
+ if (theElement->mValue != _S(""))
+ hasSpace = true;
+
+ // It's a comment!
+ if ((theElement->mType == XMLElement::TYPE_START) && (theElement->mValue == _S("!--")))
+ theElement->mType = XMLElement::TYPE_COMMENT;
+ }
+ else if (c > 32)
+ {
+ processChar = true;
+ }
+ else
+ {
+ Fail(_S("Illegal Character"));
+ return false;
+ }
+ }
+ else
+ {
+ processChar = true;
+ }
+
+ if (processChar)
+ {
+ if (theElement->mType == XMLElement::TYPE_NONE)
+ theElement->mType = XMLElement::TYPE_ELEMENT;
+
+ if (theElement->mType == XMLElement::TYPE_START)
+ {
+ if (hasSpace)
+ {
+ if ((!doingAttribute) || ((!AttributeVal) && (c != _S('='))) ||
+ ((AttributeVal) && ((aAttributeValue.length() > 0) || gotEndQuote)))
+ {
+ if (doingAttribute)
+ {
+ aAttributeKey = XMLDecodeString(aAttributeKey);
+ aAttributeValue = XMLDecodeString(aAttributeValue);
+
+// theElement->mAttributes[aAttributeKey] = aAttributeValue;
+
+ AddAttribute(theElement, WStringToSexyString(aAttributeKey), WStringToSexyString(aAttributeValue));
+
+ aAttributeKey = L"";
+ aAttributeValue = L"";
+
+ aLastAttributeKey = aAttributeKey;
+ }
+ else
+ {
+ doingAttribute = true;
+ }
+
+ AttributeVal = false;
+ }
+
+ hasSpace = false;
+ }
+
+ std::wstring* aStrPtr = NULL;
+
+ if (!doingAttribute)
+ {
+ theElement->mValue += (SexyChar)c;
+ }
+ else
+ {
+ if (c == L'=')
+ {
+ AttributeVal = true;
+ gotEndQuote = false;
+ }
+ else
+ {
+ if (!AttributeVal)
+ aStrPtr = &aAttributeKey;
+ else
+ aStrPtr = &aAttributeValue;
+ }
+ }
+
+ if (aStrPtr != NULL)
+ {
+ *aStrPtr += c;
+ }
+ }
+ else
+ {
+ if (hasSpace)
+ {
+ theElement->mValue += _S(" ");
+ hasSpace = false;
+ }
+
+ theElement->mValue += (SexyChar)c;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (theElement->mType != XMLElement::TYPE_NONE)
+ Fail(_S("Unexpected End of File"));
+
+ return false;
+ }
+ }
+
+ if (aAttributeKey.length() > 0)
+ {
+ aAttributeKey = XMLDecodeString(aAttributeKey);
+ aAttributeValue = XMLDecodeString(aAttributeValue);
+// theElement->mAttributes[aAttributeKey] = aAttributeValue;
+
+ AddAttribute(theElement, WStringToSexyString(aAttributeKey), WStringToSexyString(aAttributeValue));
+ }
+
+ theElement->mValue = XMLDecodeString(theElement->mValue);
+
+ // Ignore comments
+ if ((theElement->mType != XMLElement::TYPE_COMMENT) || mAllowComments)
+ return true;
+ }
+}
+
+bool XMLParser::HasFailed()
+{
+ return mHasFailed;
+}
+
+SexyString XMLParser::GetErrorText()
+{
+ return mErrorText;
+}
+
+int XMLParser::GetCurrentLineNum()
+{
+ return mLineNum;
+}
+
+std::string XMLParser::GetFileName()
+{
+ return mFileName;
+}
diff --git a/osframework/source/SexyAppFramework/XMLParser.h b/osframework/source/SexyAppFramework/XMLParser.h
new file mode 100644
index 0000000..7781e08
--- /dev/null
+++ b/osframework/source/SexyAppFramework/XMLParser.h
@@ -0,0 +1,106 @@
+#ifndef __XMLPARSER_H__
+#define __XMLPARSER_H__
+
+#include "Common.h"
+
+#include "PerfTimer.h"
+
+struct PFILE;
+
+namespace Sexy
+{
+
+class XMLParam
+{
+public:
+ std::string mKey;
+ std::string mValue;
+};
+
+typedef std::map<SexyString, SexyString> XMLParamMap;
+typedef std::list<XMLParamMap::iterator> XMLParamMapIteratorList;
+
+typedef std::vector<wchar_t> XMLParserBuffer;
+
+class XMLElement
+{
+public:
+ enum
+ {
+ TYPE_NONE,
+ TYPE_START,
+ TYPE_END,
+ TYPE_ELEMENT,
+ TYPE_INSTRUCTION,
+ TYPE_COMMENT
+ };
+public:
+
+ int mType;
+ SexyString mSection;
+ SexyString mValue;
+ SexyString mInstruction;
+ XMLParamMap mAttributes;
+ XMLParamMapIteratorList mAttributeIteratorList; // stores attribute iterators in their original order
+};
+
+class XMLParser
+{
+protected:
+ std::string mFileName;
+ SexyString mErrorText;
+ int mLineNum;
+ PFILE* mFile;
+ bool mHasFailed;
+ bool mAllowComments;
+ XMLParserBuffer mBufferedText;
+ SexyString mSection;
+ bool (XMLParser::*mGetCharFunc)(wchar_t* theChar, bool* error);
+ bool mForcedEncodingType;
+ bool mFirstChar;
+ bool mByteSwap;
+
+protected:
+ void Fail(const SexyString& theErrorText);
+ void Init();
+
+ bool AddAttribute(XMLElement* theElement, const SexyString& aAttributeKey, const SexyString& aAttributeValue);
+
+ bool GetAsciiChar(wchar_t* theChar, bool* error);
+ bool GetUTF8Char(wchar_t* theChar, bool* error);
+ bool GetUTF16Char(wchar_t* theChar, bool* error);
+ bool GetUTF16LEChar(wchar_t* theChar, bool* error);
+ bool GetUTF16BEChar(wchar_t* theChar, bool* error);
+
+public:
+ enum XMLEncodingType
+ {
+ ASCII,
+ UTF_8,
+ UTF_16,
+ UTF_16_LE,
+ UTF_16_BE
+ };
+
+public:
+ XMLParser();
+ virtual ~XMLParser();
+
+ void SetEncodingType(XMLEncodingType theEncoding);
+ bool OpenFile(const std::string& theFilename);
+ void SetStringSource(const std::wstring& theString);
+ void SetStringSource(const std::string& theString);
+ bool NextElement(XMLElement* theElement);
+ SexyString GetErrorText();
+ int GetCurrentLineNum();
+ std::string GetFileName();
+
+ inline void AllowComments(bool doAllow) { mAllowComments = doAllow; }
+
+ bool HasFailed();
+ bool EndOfFile();
+};
+
+};
+
+#endif //__XMLPARSER_H__
diff --git a/osframework/source/SexyAppFramework/bass.dll b/osframework/source/SexyAppFramework/bass.dll
new file mode 100644
index 0000000..06c3317
--- /dev/null
+++ b/osframework/source/SexyAppFramework/bass.dll
Binary files differ
diff --git a/osframework/source/SexyAppFramework/bass.h b/osframework/source/SexyAppFramework/bass.h
new file mode 100644
index 0000000..d5fe6a4
--- /dev/null
+++ b/osframework/source/SexyAppFramework/bass.h
@@ -0,0 +1,808 @@
+/* BASS 2.2 C/C++ header file, copyright (c) 1999-2005 Ian Luck.
+ Please report bugs/suggestions/etc... to bass@un4seen.com
+
+ See the BASS.CHM file for more complete documentation */
+
+#ifndef BASSLIB_H
+#define BASSLIB_H
+
+#ifdef WIN32 // Windows
+#include <wtypes.h>
+typedef unsigned __int64 QWORD;
+#else // OSX
+#define WINAPI
+#define CALLBACK
+typedef unsigned char BYTE;
+typedef unsigned short WORD;
+typedef unsigned long DWORD;
+typedef unsigned long long QWORD;
+typedef int BOOL;
+#define TRUE 1
+#define FALSE 0
+#define LOWORD(a) (WORD)(a)
+#define HIWORD(a) (WORD)((a)>>16)
+#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef BASSDEF
+#define BASSDEF(f) WINAPI f
+#endif
+
+typedef DWORD HMUSIC; // MOD music handle
+typedef DWORD HSAMPLE; // sample handle
+typedef DWORD HCHANNEL; // playing sample's channel handle
+typedef DWORD HSTREAM; // sample stream handle
+typedef DWORD HRECORD; // recording handle
+typedef DWORD HSYNC; // synchronizer handle
+typedef DWORD HDSP; // DSP handle
+typedef DWORD HFX; // DX8 effect handle
+typedef DWORD HPLUGIN; // Plugin handle
+
+// Error codes returned by BASS_ErrorGetCode
+#define BASS_OK 0 // all is OK
+#define BASS_ERROR_MEM 1 // memory error
+#define BASS_ERROR_FILEOPEN 2 // can't open the file
+#define BASS_ERROR_DRIVER 3 // can't find a free/valid driver
+#define BASS_ERROR_BUFLOST 4 // the sample buffer was lost
+#define BASS_ERROR_HANDLE 5 // invalid handle
+#define BASS_ERROR_FORMAT 6 // unsupported sample format
+#define BASS_ERROR_POSITION 7 // invalid playback position
+#define BASS_ERROR_INIT 8 // BASS_Init has not been successfully called
+#define BASS_ERROR_START 9 // BASS_Start has not been successfully called
+#define BASS_ERROR_ALREADY 14 // already initialized/paused/whatever
+#define BASS_ERROR_NOPAUSE 16 // not paused
+#define BASS_ERROR_NOCHAN 18 // can't get a free channel
+#define BASS_ERROR_ILLTYPE 19 // an illegal type was specified
+#define BASS_ERROR_ILLPARAM 20 // an illegal parameter was specified
+#define BASS_ERROR_NO3D 21 // no 3D support
+#define BASS_ERROR_NOEAX 22 // no EAX support
+#define BASS_ERROR_DEVICE 23 // illegal device number
+#define BASS_ERROR_NOPLAY 24 // not playing
+#define BASS_ERROR_FREQ 25 // illegal sample rate
+#define BASS_ERROR_NOTFILE 27 // the stream is not a file stream
+#define BASS_ERROR_NOHW 29 // no hardware voices available
+#define BASS_ERROR_EMPTY 31 // the MOD music has no sequence data
+#define BASS_ERROR_NONET 32 // no internet connection could be opened
+#define BASS_ERROR_CREATE 33 // couldn't create the file
+#define BASS_ERROR_NOFX 34 // effects are not available
+#define BASS_ERROR_PLAYING 35 // the channel is playing
+#define BASS_ERROR_NOTAVAIL 37 // requested data is not available
+#define BASS_ERROR_DECODE 38 // the channel is a "decoding channel"
+#define BASS_ERROR_DX 39 // a sufficient DirectX version is not installed
+#define BASS_ERROR_TIMEOUT 40 // connection timedout
+#define BASS_ERROR_FILEFORM 41 // unsupported file format
+#define BASS_ERROR_SPEAKER 42 // unavailable speaker
+#define BASS_ERROR_UNKNOWN -1 // some other mystery error
+
+// Initialization flags
+#define BASS_DEVICE_8BITS 1 // use 8 bit resolution, else 16 bit
+#define BASS_DEVICE_MONO 2 // use mono, else stereo
+#define BASS_DEVICE_3D 4 // enable 3D functionality
+/* If the BASS_DEVICE_3D flag is not specified when initilizing BASS,
+then the 3D flags (BASS_SAMPLE_3D and BASS_MUSIC_3D) are ignored when
+loading/creating a sample/stream/music. */
+#define BASS_DEVICE_LATENCY 256 // calculate device latency (BASS_INFO struct)
+#define BASS_DEVICE_SPEAKERS 2048 // force enabling of speaker assignment
+
+// DirectSound interfaces (for use with BASS_GetDSoundObject)
+#define BASS_OBJECT_DS 1 // IDirectSound
+#define BASS_OBJECT_DS3DL 2 // IDirectSound3DListener
+
+typedef struct {
+ DWORD flags; // device capabilities (DSCAPS_xxx flags)
+ DWORD hwsize; // size of total device hardware memory
+ DWORD hwfree; // size of free device hardware memory
+ DWORD freesam; // number of free sample slots in the hardware
+ DWORD free3d; // number of free 3D sample slots in the hardware
+ DWORD minrate; // min sample rate supported by the hardware
+ DWORD maxrate; // max sample rate supported by the hardware
+ BOOL eax; // device supports EAX? (always FALSE if BASS_DEVICE_3D was not used)
+ DWORD minbuf; // recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY)
+ DWORD dsver; // DirectSound version
+ DWORD latency; // delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY)
+ DWORD initflags;// "flags" parameter of BASS_Init call
+ DWORD speakers; // number of speakers available
+ char *driver; // driver
+} BASS_INFO;
+
+// BASS_INFO flags (from DSOUND.H)
+#define DSCAPS_CONTINUOUSRATE 0x00000010
+/* supports all sample rates between min/maxrate */
+#define DSCAPS_EMULDRIVER 0x00000020
+/* device does NOT have hardware DirectSound support */
+#define DSCAPS_CERTIFIED 0x00000040
+/* device driver has been certified by Microsoft */
+/* The following flags tell what type of samples are supported by HARDWARE
+mixing, all these formats are supported by SOFTWARE mixing */
+#define DSCAPS_SECONDARYMONO 0x00000100 // mono
+#define DSCAPS_SECONDARYSTEREO 0x00000200 // stereo
+#define DSCAPS_SECONDARY8BIT 0x00000400 // 8 bit
+#define DSCAPS_SECONDARY16BIT 0x00000800 // 16 bit
+
+typedef struct {
+ DWORD flags; // device capabilities (DSCCAPS_xxx flags)
+ DWORD formats; // supported standard formats (WAVE_FORMAT_xxx flags)
+ DWORD inputs; // number of inputs
+ BOOL singlein; // TRUE = only 1 input can be set at a time
+ char *driver; // driver
+} BASS_RECORDINFO;
+
+// BASS_RECORDINFO flags (from DSOUND.H)
+#define DSCCAPS_EMULDRIVER DSCAPS_EMULDRIVER // device does NOT have hardware DirectSound recording support
+#define DSCCAPS_CERTIFIED DSCAPS_CERTIFIED // device driver has been certified by Microsoft
+
+// defines for formats field of BASS_RECORDINFO (from MMSYSTEM.H)
+#ifndef WAVE_FORMAT_1M08
+#define WAVE_FORMAT_1M08 0x00000001 /* 11.025 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_1S08 0x00000002 /* 11.025 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_1M16 0x00000004 /* 11.025 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_1S16 0x00000008 /* 11.025 kHz, Stereo, 16-bit */
+#define WAVE_FORMAT_2M08 0x00000010 /* 22.05 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_2S08 0x00000020 /* 22.05 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_2M16 0x00000040 /* 22.05 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_2S16 0x00000080 /* 22.05 kHz, Stereo, 16-bit */
+#define WAVE_FORMAT_4M08 0x00000100 /* 44.1 kHz, Mono, 8-bit */
+#define WAVE_FORMAT_4S08 0x00000200 /* 44.1 kHz, Stereo, 8-bit */
+#define WAVE_FORMAT_4M16 0x00000400 /* 44.1 kHz, Mono, 16-bit */
+#define WAVE_FORMAT_4S16 0x00000800 /* 44.1 kHz, Stereo, 16-bit */
+#endif
+
+// Sample info structure & flags
+typedef struct {
+ DWORD freq; // default playback rate
+ DWORD volume; // default volume (0-100)
+ int pan; // default pan (-100=left, 0=middle, 100=right)
+ DWORD flags; // BASS_SAMPLE_xxx flags
+ DWORD length; // length (in bytes)
+ DWORD max; // maximum simultaneous playbacks
+ DWORD origres; // original resolution bits
+ DWORD chans; // number of channels
+/* The following are the sample's default 3D attributes (if the sample
+is 3D, BASS_SAMPLE_3D is in flags) see BASS_ChannelSet3DAttributes */
+ DWORD mode3d; // BASS_3DMODE_xxx mode
+ float mindist; // minimum distance
+ float maxdist; // maximum distance
+ DWORD iangle; // angle of inside projection cone
+ DWORD oangle; // angle of outside projection cone
+ DWORD outvol; // delta-volume outside the projection cone
+/* The following are the defaults used if the sample uses the DirectX 7
+voice allocation/management features. */
+ DWORD vam; // voice allocation/management flags (BASS_VAM_xxx)
+ DWORD priority; // priority (0=lowest, 0xffffffff=highest)
+} BASS_SAMPLE;
+
+#define BASS_SAMPLE_8BITS 1 // 8 bit
+#define BASS_SAMPLE_FLOAT 256 // 32-bit floating-point
+#define BASS_SAMPLE_MONO 2 // mono
+#define BASS_SAMPLE_LOOP 4 // looped
+#define BASS_SAMPLE_3D 8 // 3D functionality enabled
+#define BASS_SAMPLE_SOFTWARE 16 // it's NOT using hardware mixing
+#define BASS_SAMPLE_MUTEMAX 32 // muted at max distance (3D only)
+#define BASS_SAMPLE_VAM 64 // uses the DX7 voice allocation & management
+#define BASS_SAMPLE_FX 128 // old implementation of DX8 effects are enabled
+#define BASS_SAMPLE_OVER_VOL 0x10000 // override lowest volume
+#define BASS_SAMPLE_OVER_POS 0x20000 // override longest playing
+#define BASS_SAMPLE_OVER_DIST 0x30000 // override furthest from listener (3D only)
+
+#define BASS_STREAM_PRESCAN 0x20000 // enable pin-point seeking (MP3/MP2/MP1)
+#define BASS_MP3_SETPOS BASS_STREAM_PRESCAN
+#define BASS_STREAM_AUTOFREE 0x40000 // automatically free the stream when it stop/ends
+#define BASS_STREAM_RESTRATE 0x80000 // restrict the download rate of internet file streams
+#define BASS_STREAM_BLOCK 0x100000// download/play internet file stream in small blocks
+#define BASS_STREAM_DECODE 0x200000// don't play the stream, only decode (BASS_ChannelGetData)
+#define BASS_STREAM_STATUS 0x800000// give server status info (HTTP/ICY tags) in DOWNLOADPROC
+
+#define BASS_MUSIC_FLOAT BASS_SAMPLE_FLOAT // 32-bit floating-point
+#define BASS_MUSIC_MONO BASS_SAMPLE_MONO // force mono mixing (less CPU usage)
+#define BASS_MUSIC_LOOP BASS_SAMPLE_LOOP // loop music
+#define BASS_MUSIC_3D BASS_SAMPLE_3D // enable 3D functionality
+#define BASS_MUSIC_FX BASS_SAMPLE_FX // enable old implementation of DX8 effects
+#define BASS_MUSIC_AUTOFREE BASS_STREAM_AUTOFREE // automatically free the music when it stop/ends
+#define BASS_MUSIC_DECODE BASS_STREAM_DECODE // don't play the music, only decode (BASS_ChannelGetData)
+#define BASS_MUSIC_PRESCAN BASS_STREAM_PRESCAN // calculate playback length
+#define BASS_MUSIC_CALCLEN BASS_MUSIC_PRESCAN
+#define BASS_MUSIC_RAMP 0x200 // normal ramping
+#define BASS_MUSIC_RAMPS 0x400 // sensitive ramping
+#define BASS_MUSIC_SURROUND 0x800 // surround sound
+#define BASS_MUSIC_SURROUND2 0x1000 // surround sound (mode 2)
+#define BASS_MUSIC_FT2MOD 0x2000 // play .MOD as FastTracker 2 does
+#define BASS_MUSIC_PT1MOD 0x4000 // play .MOD as ProTracker 1 does
+#define BASS_MUSIC_NONINTER 0x10000 // non-interpolated mixing
+#define BASS_MUSIC_POSRESET 0x8000 // stop all notes when moving position
+#define BASS_MUSIC_POSRESETEX 0x400000// stop all notes and reset bmp/etc when moving position
+#define BASS_MUSIC_STOPBACK 0x80000 // stop the music on a backwards jump effect
+#define BASS_MUSIC_NOSAMPLE 0x100000// don't load the samples
+
+// Speaker assignment flags
+#define BASS_SPEAKER_FRONT 0x1000000 // front speakers
+#define BASS_SPEAKER_REAR 0x2000000 // rear/side speakers
+#define BASS_SPEAKER_CENLFE 0x3000000 // center & LFE speakers (5.1)
+#define BASS_SPEAKER_REAR2 0x4000000 // rear center speakers (7.1)
+#define BASS_SPEAKER_N(n) ((n)<<24) // n'th pair of speakers (max 15)
+#define BASS_SPEAKER_LEFT 0x10000000 // modifier: left
+#define BASS_SPEAKER_RIGHT 0x20000000 // modifier: right
+#define BASS_SPEAKER_FRONTLEFT BASS_SPEAKER_FRONT|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_FRONTRIGHT BASS_SPEAKER_FRONT|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_REARLEFT BASS_SPEAKER_REAR|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_REARRIGHT BASS_SPEAKER_REAR|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_CENTER BASS_SPEAKER_CENLFE|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_LFE BASS_SPEAKER_CENLFE|BASS_SPEAKER_RIGHT
+#define BASS_SPEAKER_REAR2LEFT BASS_SPEAKER_REAR2|BASS_SPEAKER_LEFT
+#define BASS_SPEAKER_REAR2RIGHT BASS_SPEAKER_REAR2|BASS_SPEAKER_RIGHT
+
+#define BASS_UNICODE 0x80000000
+
+#define BASS_RECORD_PAUSE 0x8000 // start recording paused
+
+#define MAKEMUSICPOS(order,row) (0x80000000|MAKELONG(order,row))
+
+// DX7 voice allocation flags
+#define BASS_VAM_HARDWARE 1
+/* Play the sample in hardware. If no hardware voices are available then
+the "play" call will fail */
+#define BASS_VAM_SOFTWARE 2
+/* Play the sample in software (ie. non-accelerated). No other VAM flags
+may be used together with this flag. */
+
+// DX7 voice management flags
+/* These flags enable hardware resource stealing... if the hardware has no
+available voices, a currently playing buffer will be stopped to make room for
+the new buffer. NOTE: only samples loaded/created with the BASS_SAMPLE_VAM
+flag are considered for termination by the DX7 voice management. */
+#define BASS_VAM_TERM_TIME 4
+/* If there are no free hardware voices, the buffer to be terminated will be
+the one with the least time left to play. */
+#define BASS_VAM_TERM_DIST 8
+/* If there are no free hardware voices, the buffer to be terminated will be
+one that was loaded/created with the BASS_SAMPLE_MUTEMAX flag and is beyond
+it's max distance. If there are no buffers that match this criteria, then the
+"play" call will fail. */
+#define BASS_VAM_TERM_PRIO 16
+/* If there are no free hardware voices, the buffer to be terminated will be
+the one with the lowest priority. */
+
+typedef struct {
+ DWORD freq; // default playback rate
+ DWORD chans; // channels
+ DWORD flags; // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags
+ DWORD ctype; // type of channel
+ DWORD origres; // original resolution
+} BASS_CHANNELINFO;
+
+// BASS_CHANNELINFO types
+#define BASS_CTYPE_SAMPLE 1
+#define BASS_CTYPE_RECORD 2
+#define BASS_CTYPE_STREAM 0x10000
+#define BASS_CTYPE_STREAM_WAV 0x10001
+#define BASS_CTYPE_STREAM_OGG 0x10002
+#define BASS_CTYPE_STREAM_MP1 0x10003
+#define BASS_CTYPE_STREAM_MP2 0x10004
+#define BASS_CTYPE_STREAM_MP3 0x10005
+#define BASS_CTYPE_STREAM_AIFF 0x10006
+#define BASS_CTYPE_MUSIC_MOD 0x20000
+#define BASS_CTYPE_MUSIC_MTM 0x20001
+#define BASS_CTYPE_MUSIC_S3M 0x20002
+#define BASS_CTYPE_MUSIC_XM 0x20003
+#define BASS_CTYPE_MUSIC_IT 0x20004
+#define BASS_CTYPE_MUSIC_MO3 0x00100 // mo3 flag
+
+// 3D vector (for 3D positions/velocities/orientations)
+typedef struct BASS_3DVECTOR {
+#ifdef __cplusplus
+ BASS_3DVECTOR() {};
+ BASS_3DVECTOR(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {};
+#endif
+ float x; // +=right, -=left
+ float y; // +=up, -=down
+ float z; // +=front, -=behind
+} BASS_3DVECTOR;
+
+// 3D channel modes
+#define BASS_3DMODE_NORMAL 0
+/* normal 3D processing */
+#define BASS_3DMODE_RELATIVE 1
+/* The channel's 3D position (position/velocity/orientation) are relative to
+the listener. When the listener's position/velocity/orientation is changed
+with BASS_Set3DPosition, the channel's position relative to the listener does
+not change. */
+#define BASS_3DMODE_OFF 2
+/* Turn off 3D processing on the channel, the sound will be played
+in the center. */
+
+#ifdef WIN32
+// EAX environments, use with BASS_SetEAXParameters
+enum
+{
+ EAX_ENVIRONMENT_GENERIC,
+ EAX_ENVIRONMENT_PADDEDCELL,
+ EAX_ENVIRONMENT_ROOM,
+ EAX_ENVIRONMENT_BATHROOM,
+ EAX_ENVIRONMENT_LIVINGROOM,
+ EAX_ENVIRONMENT_STONEROOM,
+ EAX_ENVIRONMENT_AUDITORIUM,
+ EAX_ENVIRONMENT_CONCERTHALL,
+ EAX_ENVIRONMENT_CAVE,
+ EAX_ENVIRONMENT_ARENA,
+ EAX_ENVIRONMENT_HANGAR,
+ EAX_ENVIRONMENT_CARPETEDHALLWAY,
+ EAX_ENVIRONMENT_HALLWAY,
+ EAX_ENVIRONMENT_STONECORRIDOR,
+ EAX_ENVIRONMENT_ALLEY,
+ EAX_ENVIRONMENT_FOREST,
+ EAX_ENVIRONMENT_CITY,
+ EAX_ENVIRONMENT_MOUNTAINS,
+ EAX_ENVIRONMENT_QUARRY,
+ EAX_ENVIRONMENT_PLAIN,
+ EAX_ENVIRONMENT_PARKINGLOT,
+ EAX_ENVIRONMENT_SEWERPIPE,
+ EAX_ENVIRONMENT_UNDERWATER,
+ EAX_ENVIRONMENT_DRUGGED,
+ EAX_ENVIRONMENT_DIZZY,
+ EAX_ENVIRONMENT_PSYCHOTIC,
+
+ EAX_ENVIRONMENT_COUNT // total number of environments
+};
+
+// EAX presets, usage: BASS_SetEAXParameters(EAX_PRESET_xxx)
+#define EAX_PRESET_GENERIC EAX_ENVIRONMENT_GENERIC,0.5F,1.493F,0.5F
+#define EAX_PRESET_PADDEDCELL EAX_ENVIRONMENT_PADDEDCELL,0.25F,0.1F,0.0F
+#define EAX_PRESET_ROOM EAX_ENVIRONMENT_ROOM,0.417F,0.4F,0.666F
+#define EAX_PRESET_BATHROOM EAX_ENVIRONMENT_BATHROOM,0.653F,1.499F,0.166F
+#define EAX_PRESET_LIVINGROOM EAX_ENVIRONMENT_LIVINGROOM,0.208F,0.478F,0.0F
+#define EAX_PRESET_STONEROOM EAX_ENVIRONMENT_STONEROOM,0.5F,2.309F,0.888F
+#define EAX_PRESET_AUDITORIUM EAX_ENVIRONMENT_AUDITORIUM,0.403F,4.279F,0.5F
+#define EAX_PRESET_CONCERTHALL EAX_ENVIRONMENT_CONCERTHALL,0.5F,3.961F,0.5F
+#define EAX_PRESET_CAVE EAX_ENVIRONMENT_CAVE,0.5F,2.886F,1.304F
+#define EAX_PRESET_ARENA EAX_ENVIRONMENT_ARENA,0.361F,7.284F,0.332F
+#define EAX_PRESET_HANGAR EAX_ENVIRONMENT_HANGAR,0.5F,10.0F,0.3F
+#define EAX_PRESET_CARPETEDHALLWAY EAX_ENVIRONMENT_CARPETEDHALLWAY,0.153F,0.259F,2.0F
+#define EAX_PRESET_HALLWAY EAX_ENVIRONMENT_HALLWAY,0.361F,1.493F,0.0F
+#define EAX_PRESET_STONECORRIDOR EAX_ENVIRONMENT_STONECORRIDOR,0.444F,2.697F,0.638F
+#define EAX_PRESET_ALLEY EAX_ENVIRONMENT_ALLEY,0.25F,1.752F,0.776F
+#define EAX_PRESET_FOREST EAX_ENVIRONMENT_FOREST,0.111F,3.145F,0.472F
+#define EAX_PRESET_CITY EAX_ENVIRONMENT_CITY,0.111F,2.767F,0.224F
+#define EAX_PRESET_MOUNTAINS EAX_ENVIRONMENT_MOUNTAINS,0.194F,7.841F,0.472F
+#define EAX_PRESET_QUARRY EAX_ENVIRONMENT_QUARRY,1.0F,1.499F,0.5F
+#define EAX_PRESET_PLAIN EAX_ENVIRONMENT_PLAIN,0.097F,2.767F,0.224F
+#define EAX_PRESET_PARKINGLOT EAX_ENVIRONMENT_PARKINGLOT,0.208F,1.652F,1.5F
+#define EAX_PRESET_SEWERPIPE EAX_ENVIRONMENT_SEWERPIPE,0.652F,2.886F,0.25F
+#define EAX_PRESET_UNDERWATER EAX_ENVIRONMENT_UNDERWATER,1.0F,1.499F,0.0F
+#define EAX_PRESET_DRUGGED EAX_ENVIRONMENT_DRUGGED,0.875F,8.392F,1.388F
+#define EAX_PRESET_DIZZY EAX_ENVIRONMENT_DIZZY,0.139F,17.234F,0.666F
+#define EAX_PRESET_PSYCHOTIC EAX_ENVIRONMENT_PSYCHOTIC,0.486F,7.563F,0.806F
+#endif
+
+// software 3D mixing algorithm modes (used with BASS_Set3DAlgorithm)
+#define BASS_3DALG_DEFAULT 0
+/* default algorithm (currently translates to BASS_3DALG_OFF) */
+#define BASS_3DALG_OFF 1
+/* Uses normal left and right panning. The vertical axis is ignored except for
+scaling of volume due to distance. Doppler shift and volume scaling are still
+applied, but the 3D filtering is not performed. This is the most CPU efficient
+software implementation, but provides no virtual 3D audio effect. Head Related
+Transfer Function processing will not be done. Since only normal stereo panning
+is used, a channel using this algorithm may be accelerated by a 2D hardware
+voice if no free 3D hardware voices are available. */
+#define BASS_3DALG_FULL 2
+/* This algorithm gives the highest quality 3D audio effect, but uses more CPU.
+Requires Windows 98 2nd Edition or Windows 2000 that uses WDM drivers, if this
+mode is not available then BASS_3DALG_OFF will be used instead. */
+#define BASS_3DALG_LIGHT 3
+/* This algorithm gives a good 3D audio effect, and uses less CPU than the FULL
+mode. Requires Windows 98 2nd Edition or Windows 2000 that uses WDM drivers, if
+this mode is not available then BASS_3DALG_OFF will be used instead. */
+
+typedef DWORD (CALLBACK STREAMPROC)(HSTREAM handle, void *buffer, DWORD length, DWORD user);
+/* User stream callback function. NOTE: A stream function should obviously be as quick
+as possible, other streams (and MOD musics) can't be mixed until it's finished.
+handle : The stream that needs writing
+buffer : Buffer to write the samples in
+length : Number of bytes to write
+user : The 'user' parameter value given when calling BASS_StreamCreate
+RETURN : Number of bytes written. Set the BASS_STREAMPROC_END flag to end
+ the stream. */
+
+#define BASS_STREAMPROC_END 0x80000000 // end of user stream flag
+
+// BASS_StreamGetFilePosition modes
+#define BASS_FILEPOS_CURRENT 0
+#define BASS_FILEPOS_DECODE BASS_FILEPOS_CURRENT
+#define BASS_FILEPOS_DOWNLOAD 1
+#define BASS_FILEPOS_END 2
+#define BASS_FILEPOS_START 3
+
+// STREAMFILEPROC actions
+#define BASS_FILE_CLOSE 0
+#define BASS_FILE_READ 1
+#define BASS_FILE_LEN 3
+#define BASS_FILE_SEEK 4
+
+typedef DWORD (CALLBACK STREAMFILEPROC)(DWORD action, DWORD param1, DWORD param2, DWORD user);
+/* User file stream callback function.
+action : The action to perform, one of BASS_FILE_xxx values.
+param1 : Depends on "action"
+param2 : Depends on "action"
+user : The 'user' parameter value given when calling BASS_StreamCreate
+RETURN : Depends on "action" */
+
+typedef void (CALLBACK DOWNLOADPROC)(void *buffer, DWORD length, DWORD user);
+/* Internet stream download callback function.
+buffer : Buffer containing the downloaded data... NULL=end of download
+length : Number of bytes in the buffer
+user : The 'user' parameter value given when calling BASS_StreamCreateURL */
+
+/* Sync types (with BASS_ChannelSetSync "param" and SYNCPROC "data"
+definitions) & flags. */
+#define BASS_SYNC_POS 0
+/* Sync when a channel reaches a position.
+param: position in bytes
+data : not used */
+#define BASS_SYNC_END 2
+/* Sync when a channel reaches the end.
+param: not used
+data : 1 = the sync is triggered by a backward jump in a MOD music, otherwise not used */
+#define BASS_SYNC_META 4
+/* Sync when metadata is received in a stream.
+param: not used
+data : pointer to the metadata */
+#define BASS_SYNC_SLIDE 5
+/* Sync when an attribute slide is completed.
+param: not used
+data : the type of slide completed (one of the BASS_SLIDE_xxx values) */
+#define BASS_SYNC_STALL 6
+/* Sync when playback has stalled.
+param: not used
+data : 0=stalled, 1=resumed */
+#define BASS_SYNC_DOWNLOAD 7
+/* Sync when downloading of an internet (or "buffered" user file) stream has ended.
+param: not used
+data : not used */
+#define BASS_SYNC_FREE 8
+/* Sync when a channel is freed.
+param: not used
+data : not used */
+#define BASS_SYNC_MUSICPOS 10
+/* Sync when a MOD music reaches an order:row position.
+param: LOWORD=order (0=first, -1=all) HIWORD=row (0=first, -1=all)
+data : LOWORD=order HIWORD=row */
+#define BASS_SYNC_MUSICINST 1
+/* Sync when an instrument (sample for the non-instrument based formats)
+is played in a MOD music (not including retrigs).
+param: LOWORD=instrument (1=first) HIWORD=note (0=c0...119=b9, -1=all)
+data : LOWORD=note HIWORD=volume (0-64) */
+#define BASS_SYNC_MUSICFX 3
+/* Sync when the "sync" effect (XM/MTM/MOD: E8x/Wxx, IT/S3M: S2x) is used.
+param: 0:data=pos, 1:data="x" value
+data : param=0: LOWORD=order HIWORD=row, param=1: "x" value */
+#define BASS_SYNC_MESSAGE 0x20000000 // FLAG: post a Windows message (instead of callback)
+/* When using a window message "callback", the message to post is given in the "proc"
+parameter of BASS_ChannelSetSync, and is posted to the window specified in the BASS_Init
+call. The message parameters are: WPARAM = data, LPARAM = user. */
+#define BASS_SYNC_MIXTIME 0x40000000 // FLAG: sync at mixtime, else at playtime
+#define BASS_SYNC_ONETIME 0x80000000 // FLAG: sync only once, else continuously
+
+typedef void (CALLBACK SYNCPROC)(HSYNC handle, DWORD channel, DWORD data, DWORD user);
+/* Sync callback function. NOTE: a sync callback function should be very
+quick as other syncs can't be processed until it has finished. If the sync
+is a "mixtime" sync, then other streams and MOD musics can't be mixed until
+it's finished either.
+handle : The sync that has occured
+channel: Channel that the sync occured in
+data : Additional data associated with the sync's occurance
+user : The 'user' parameter given when calling BASS_ChannelSetSync */
+
+typedef void (CALLBACK DSPPROC)(HDSP handle, DWORD channel, void *buffer, DWORD length, DWORD user);
+/* DSP callback function. NOTE: A DSP function should obviously be as quick as
+possible... other DSP functions, streams and MOD musics can not be processed
+until it's finished.
+handle : The DSP handle
+channel: Channel that the DSP is being applied to
+buffer : Buffer to apply the DSP to
+length : Number of bytes in the buffer
+user : The 'user' parameter given when calling BASS_ChannelSetDSP */
+
+typedef BOOL (CALLBACK RECORDPROC)(HRECORD handle, void *buffer, DWORD length, DWORD user);
+/* Recording callback function.
+handle : The recording handle
+buffer : Buffer containing the recorded sample data
+length : Number of bytes
+user : The 'user' parameter value given when calling BASS_RecordStart
+RETURN : TRUE = continue recording, FALSE = stop */
+
+// BASS_ChannelGetData flags
+#define BASS_DATA_AVAILABLE 0 // query how much data is buffered
+#define BASS_DATA_FLOAT 0x40000000 // flag: return floating-point sample data
+#define BASS_DATA_FFT512 0x80000000 // 512 sample FFT
+#define BASS_DATA_FFT1024 0x80000001 // 1024 FFT
+#define BASS_DATA_FFT2048 0x80000002 // 2048 FFT
+#define BASS_DATA_FFT4096 0x80000003 // 4096 FFT
+#define BASS_DATA_FFT_INDIVIDUAL 0x10 // FFT flag: FFT for each channel, else all combined
+#define BASS_DATA_FFT_NOWINDOW 0x20 // FFT flag: no Hanning window
+
+// BASS_StreamGetTags types : what's returned
+#define BASS_TAG_ID3 0 // ID3v1 tags : 128 byte block
+#define BASS_TAG_ID3V2 1 // ID3v2 tags : variable length block
+#define BASS_TAG_OGG 2 // OGG comments : array of null-terminated strings
+#define BASS_TAG_HTTP 3 // HTTP headers : array of null-terminated strings
+#define BASS_TAG_ICY 4 // ICY headers : array of null-terminated strings
+#define BASS_TAG_META 5 // ICY metadata : null-terminated string
+
+// BASS_MusicSet/GetAttribute options
+#define BASS_MUSIC_ATTRIB_AMPLIFY 0
+#define BASS_MUSIC_ATTRIB_PANSEP 1
+#define BASS_MUSIC_ATTRIB_PSCALER 2
+#define BASS_MUSIC_ATTRIB_BPM 3
+#define BASS_MUSIC_ATTRIB_SPEED 4
+#define BASS_MUSIC_ATTRIB_VOL_GLOBAL 5
+#define BASS_MUSIC_ATTRIB_VOL_CHAN 0x100 // + channel #
+#define BASS_MUSIC_ATTRIB_VOL_INST 0x200 // + instrument #
+
+#ifdef WIN32
+// DX8 effect types, use with BASS_ChannelSetFX
+enum
+{
+ BASS_FX_CHORUS, // GUID_DSFX_STANDARD_CHORUS
+ BASS_FX_COMPRESSOR, // GUID_DSFX_STANDARD_COMPRESSOR
+ BASS_FX_DISTORTION, // GUID_DSFX_STANDARD_DISTORTION
+ BASS_FX_ECHO, // GUID_DSFX_STANDARD_ECHO
+ BASS_FX_FLANGER, // GUID_DSFX_STANDARD_FLANGER
+ BASS_FX_GARGLE, // GUID_DSFX_STANDARD_GARGLE
+ BASS_FX_I3DL2REVERB, // GUID_DSFX_STANDARD_I3DL2REVERB
+ BASS_FX_PARAMEQ, // GUID_DSFX_STANDARD_PARAMEQ
+ BASS_FX_REVERB // GUID_DSFX_WAVES_REVERB
+};
+
+typedef struct {
+ float fWetDryMix;
+ float fDepth;
+ float fFeedback;
+ float fFrequency;
+ DWORD lWaveform; // 0=triangle, 1=sine
+ float fDelay;
+ DWORD lPhase; // BASS_FX_PHASE_xxx
+} BASS_FXCHORUS; // DSFXChorus
+
+typedef struct {
+ float fGain;
+ float fAttack;
+ float fRelease;
+ float fThreshold;
+ float fRatio;
+ float fPredelay;
+} BASS_FXCOMPRESSOR; // DSFXCompressor
+
+typedef struct {
+ float fGain;
+ float fEdge;
+ float fPostEQCenterFrequency;
+ float fPostEQBandwidth;
+ float fPreLowpassCutoff;
+} BASS_FXDISTORTION; // DSFXDistortion
+
+typedef struct {
+ float fWetDryMix;
+ float fFeedback;
+ float fLeftDelay;
+ float fRightDelay;
+ BOOL lPanDelay;
+} BASS_FXECHO; // DSFXEcho
+
+typedef struct {
+ float fWetDryMix;
+ float fDepth;
+ float fFeedback;
+ float fFrequency;
+ DWORD lWaveform; // 0=triangle, 1=sine
+ float fDelay;
+ DWORD lPhase; // BASS_FX_PHASE_xxx
+} BASS_FXFLANGER; // DSFXFlanger
+
+typedef struct {
+ DWORD dwRateHz; // Rate of modulation in hz
+ DWORD dwWaveShape; // 0=triangle, 1=square
+} BASS_FXGARGLE; // DSFXGargle
+
+typedef struct {
+ int lRoom; // [-10000, 0] default: -1000 mB
+ int lRoomHF; // [-10000, 0] default: 0 mB
+ float flRoomRolloffFactor; // [0.0, 10.0] default: 0.0
+ float flDecayTime; // [0.1, 20.0] default: 1.49s
+ float flDecayHFRatio; // [0.1, 2.0] default: 0.83
+ int lReflections; // [-10000, 1000] default: -2602 mB
+ float flReflectionsDelay; // [0.0, 0.3] default: 0.007 s
+ int lReverb; // [-10000, 2000] default: 200 mB
+ float flReverbDelay; // [0.0, 0.1] default: 0.011 s
+ float flDiffusion; // [0.0, 100.0] default: 100.0 %
+ float flDensity; // [0.0, 100.0] default: 100.0 %
+ float flHFReference; // [20.0, 20000.0] default: 5000.0 Hz
+} BASS_FXI3DL2REVERB; // DSFXI3DL2Reverb
+
+typedef struct {
+ float fCenter;
+ float fBandwidth;
+ float fGain;
+} BASS_FXPARAMEQ; // DSFXParamEq
+
+typedef struct {
+ float fInGain; // [-96.0,0.0] default: 0.0 dB
+ float fReverbMix; // [-96.0,0.0] default: 0.0 db
+ float fReverbTime; // [0.001,3000.0] default: 1000.0 ms
+ float fHighFreqRTRatio; // [0.001,0.999] default: 0.001
+} BASS_FXREVERB; // DSFXWavesReverb
+
+#define BASS_FX_PHASE_NEG_180 0
+#define BASS_FX_PHASE_NEG_90 1
+#define BASS_FX_PHASE_ZERO 2
+#define BASS_FX_PHASE_90 3
+#define BASS_FX_PHASE_180 4
+#endif
+
+// BASS_ChannelIsActive return values
+#define BASS_ACTIVE_STOPPED 0
+#define BASS_ACTIVE_PLAYING 1
+#define BASS_ACTIVE_STALLED 2
+#define BASS_ACTIVE_PAUSED 3
+
+// BASS_ChannelIsSliding return flags
+#define BASS_SLIDE_FREQ 1
+#define BASS_SLIDE_VOL 2
+#define BASS_SLIDE_PAN 4
+
+// BASS_RecordSetInput flags
+#define BASS_INPUT_OFF 0x10000
+#define BASS_INPUT_ON 0x20000
+#define BASS_INPUT_LEVEL 0x40000
+
+#define BASS_INPUT_TYPE_MASK 0xff000000
+#define BASS_INPUT_TYPE_UNDEF 0x00000000
+#define BASS_INPUT_TYPE_DIGITAL 0x01000000
+#define BASS_INPUT_TYPE_LINE 0x02000000
+#define BASS_INPUT_TYPE_MIC 0x03000000
+#define BASS_INPUT_TYPE_SYNTH 0x04000000
+#define BASS_INPUT_TYPE_CD 0x05000000
+#define BASS_INPUT_TYPE_PHONE 0x06000000
+#define BASS_INPUT_TYPE_SPEAKER 0x07000000
+#define BASS_INPUT_TYPE_WAVE 0x08000000
+#define BASS_INPUT_TYPE_AUX 0x09000000
+#define BASS_INPUT_TYPE_ANALOG 0x0a000000
+
+// BASS_Set/GetConfig options
+#define BASS_CONFIG_BUFFER 0
+#define BASS_CONFIG_UPDATEPERIOD 1
+#define BASS_CONFIG_MAXVOL 3
+#define BASS_CONFIG_GVOL_SAMPLE 4
+#define BASS_CONFIG_GVOL_STREAM 5
+#define BASS_CONFIG_GVOL_MUSIC 6
+#define BASS_CONFIG_CURVE_VOL 7
+#define BASS_CONFIG_CURVE_PAN 8
+#define BASS_CONFIG_FLOATDSP 9
+#define BASS_CONFIG_3DALGORITHM 10
+#define BASS_CONFIG_NET_TIMEOUT 11
+#define BASS_CONFIG_NET_BUFFER 12
+#define BASS_CONFIG_PAUSE_NOPLAY 13
+#define BASS_CONFIG_NET_NOPROXY 14
+#define BASS_CONFIG_NET_PREBUF 15
+#define BASS_CONFIG_NET_AGENT 16
+
+DWORD BASSDEF(BASS_SetConfig)(DWORD option, DWORD value);
+DWORD BASSDEF(BASS_GetConfig)(DWORD option);
+DWORD BASSDEF(BASS_GetVersion)();
+char *BASSDEF(BASS_GetDeviceDescription)(DWORD device);
+int BASSDEF(BASS_ErrorGetCode)();
+#ifdef WIN32
+BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const GUID *dsguid);
+#else
+BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, void *win, void *dsguid);
+#endif
+BOOL BASSDEF(BASS_SetDevice)(DWORD device);
+DWORD BASSDEF(BASS_GetDevice)();
+BOOL BASSDEF(BASS_Free)();
+#ifdef WIN32
+void *BASSDEF(BASS_GetDSoundObject)(DWORD object);
+#endif
+BOOL BASSDEF(BASS_GetInfo)(BASS_INFO *info);
+BOOL BASSDEF(BASS_Update)();
+float BASSDEF(BASS_GetCPU)();
+BOOL BASSDEF(BASS_Start)();
+BOOL BASSDEF(BASS_Stop)();
+BOOL BASSDEF(BASS_Pause)();
+BOOL BASSDEF(BASS_SetVolume)(DWORD volume);
+DWORD BASSDEF(BASS_GetVolume)();
+
+HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file);
+BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle);
+
+BOOL BASSDEF(BASS_Set3DFactors)(float distf, float rollf, float doppf);
+BOOL BASSDEF(BASS_Get3DFactors)(float *distf, float *rollf, float *doppf);
+BOOL BASSDEF(BASS_Set3DPosition)(const BASS_3DVECTOR *pos, const BASS_3DVECTOR *vel, const BASS_3DVECTOR *front, const BASS_3DVECTOR *top);
+BOOL BASSDEF(BASS_Get3DPosition)(BASS_3DVECTOR *pos, BASS_3DVECTOR *vel, BASS_3DVECTOR *front, BASS_3DVECTOR *top);
+void BASSDEF(BASS_Apply3D)();
+#ifdef WIN32
+BOOL BASSDEF(BASS_SetEAXParameters)(int env, float vol, float decay, float damp);
+BOOL BASSDEF(BASS_GetEAXParameters)(DWORD *env, float *vol, float *decay, float *damp);
+#endif
+
+HMUSIC BASSDEF(BASS_MusicLoad)(BOOL mem, const void *file, DWORD offset, DWORD length, DWORD flags, DWORD freq);
+BOOL BASSDEF(BASS_MusicFree)(HMUSIC handle);
+DWORD BASSDEF(BASS_MusicSetAttribute)(HMUSIC handle, DWORD attrib, DWORD value);
+DWORD BASSDEF(BASS_MusicGetAttribute)(HMUSIC handle, DWORD attrib);
+char *BASSDEF(BASS_MusicGetName)(HMUSIC handle);
+DWORD BASSDEF(BASS_MusicGetOrders)(HMUSIC handle);
+DWORD BASSDEF(BASS_MusicGetOrderPosition)(HMUSIC handle);
+
+HSAMPLE BASSDEF(BASS_SampleLoad)(BOOL mem, const void *file, DWORD offset, DWORD length, DWORD max, DWORD flags);
+void* BASSDEF(BASS_SampleCreate)(DWORD length, DWORD freq, DWORD chans, DWORD max, DWORD flags);
+HSAMPLE BASSDEF(BASS_SampleCreateDone)();
+BOOL BASSDEF(BASS_SampleFree)(HSAMPLE handle);
+BOOL BASSDEF(BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info);
+BOOL BASSDEF(BASS_SampleSetInfo)(HSAMPLE handle, const BASS_SAMPLE *info);
+HCHANNEL BASSDEF(BASS_SampleGetChannel)(HSAMPLE handle, BOOL onlynew);
+BOOL BASSDEF(BASS_SampleStop)(HSAMPLE handle);
+
+HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, DWORD user);
+HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, DWORD offset, DWORD length, DWORD flags);
+HSTREAM BASSDEF(BASS_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, DWORD user);
+HSTREAM BASSDEF(BASS_StreamCreateFileUser)(BOOL buffered, DWORD flags, STREAMFILEPROC *proc, DWORD user);
+BOOL BASSDEF(BASS_StreamFree)(HSTREAM handle);
+char *BASSDEF(BASS_StreamGetTags)(HSTREAM handle, DWORD tags);
+DWORD BASSDEF(BASS_StreamGetFilePosition)(HSTREAM handle, DWORD mode);
+
+char *BASSDEF(BASS_RecordGetDeviceDescription)(DWORD device);
+BOOL BASSDEF(BASS_RecordInit)(int device);
+BOOL BASSDEF(BASS_RecordSetDevice)(DWORD device);
+DWORD BASSDEF(BASS_RecordGetDevice)();
+BOOL BASSDEF(BASS_RecordFree)();
+BOOL BASSDEF(BASS_RecordGetInfo)(BASS_RECORDINFO *info);
+char *BASSDEF(BASS_RecordGetInputName)(int input);
+BOOL BASSDEF(BASS_RecordSetInput)(int input, DWORD setting);
+DWORD BASSDEF(BASS_RecordGetInput)(int input);
+HRECORD BASSDEF(BASS_RecordStart)(DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc, DWORD user);
+
+float BASSDEF(BASS_ChannelBytes2Seconds)(DWORD handle, QWORD pos);
+QWORD BASSDEF(BASS_ChannelSeconds2Bytes)(DWORD handle, float pos);
+DWORD BASSDEF(BASS_ChannelGetDevice)(DWORD handle);
+DWORD BASSDEF(BASS_ChannelIsActive)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelGetInfo)(DWORD handle, BASS_CHANNELINFO *info);
+BOOL BASSDEF(BASS_ChannelSetFlags)(DWORD handle, DWORD flags);
+BOOL BASSDEF(BASS_ChannelPreBuf)(DWORD handle, DWORD length);
+BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart);
+BOOL BASSDEF(BASS_ChannelStop)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelPause)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelSetAttributes)(DWORD handle, int freq, int volume, int pan);
+BOOL BASSDEF(BASS_ChannelGetAttributes)(DWORD handle, DWORD *freq, DWORD *volume, int *pan);
+BOOL BASSDEF(BASS_ChannelSlideAttributes)(DWORD handle, int freq, int volume, int pan, DWORD time);
+DWORD BASSDEF(BASS_ChannelIsSliding)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelSet3DAttributes)(DWORD handle, int mode, float min, float max, int iangle, int oangle, int outvol);
+BOOL BASSDEF(BASS_ChannelGet3DAttributes)(DWORD handle, DWORD *mode, float *min, float *max, DWORD *iangle, DWORD *oangle, DWORD *outvol);
+BOOL BASSDEF(BASS_ChannelSet3DPosition)(DWORD handle, const BASS_3DVECTOR *pos, const BASS_3DVECTOR *orient, const BASS_3DVECTOR *vel);
+BOOL BASSDEF(BASS_ChannelGet3DPosition)(DWORD handle, BASS_3DVECTOR *pos, BASS_3DVECTOR *orient, BASS_3DVECTOR *vel);
+QWORD BASSDEF(BASS_ChannelGetLength)(DWORD handle);
+BOOL BASSDEF(BASS_ChannelSetPosition)(DWORD handle, QWORD pos);
+QWORD BASSDEF(BASS_ChannelGetPosition)(DWORD handle);
+DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle);
+DWORD BASSDEF(BASS_ChannelGetData)(DWORD handle, void *buffer, DWORD length);
+HSYNC BASSDEF(BASS_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, DWORD user);
+BOOL BASSDEF(BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync);
+HDSP BASSDEF(BASS_ChannelSetDSP)(DWORD handle, DSPPROC *proc, DWORD user, int priority);
+BOOL BASSDEF(BASS_ChannelRemoveDSP)(DWORD handle, HDSP dsp);
+BOOL BASSDEF(BASS_ChannelSetLink)(DWORD handle, DWORD chan);
+BOOL BASSDEF(BASS_ChannelRemoveLink)(DWORD handle, DWORD chan);
+#ifdef WIN32
+BOOL BASSDEF(BASS_ChannelSetEAXMix)(DWORD handle, float mix);
+BOOL BASSDEF(BASS_ChannelGetEAXMix)(DWORD handle, float *mix);
+HFX BASSDEF(BASS_ChannelSetFX)(DWORD handle, DWORD type, DWORD priority);
+BOOL BASSDEF(BASS_ChannelRemoveFX)(DWORD handle, HFX fx);
+
+BOOL BASSDEF(BASS_FXSetParameters)(HFX handle, const void *par);
+BOOL BASSDEF(BASS_FXGetParameters)(HFX handle, void *par);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/SexyAppFramework/dsoundversion.h b/osframework/source/SexyAppFramework/dsoundversion.h
new file mode 100644
index 0000000..9a70d4f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/dsoundversion.h
@@ -0,0 +1,7 @@
+#ifndef __DSOUNDVERSION_H__
+#define __DSOUNDVERSION_H__
+
+#define DIRECTSOUND_VERSION 0x0600
+#include <dsound.h>
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/fmod.h b/osframework/source/SexyAppFramework/fmod.h
new file mode 100644
index 0000000..92ae6df
--- /dev/null
+++ b/osframework/source/SexyAppFramework/fmod.h
@@ -0,0 +1,1063 @@
+/* ========================================================================================== */
+/* FMOD Main header file. Copyright (c), Firelight Technologies Pty, Ltd 1999-2002. */
+/* ========================================================================================== */
+
+#ifndef _FMOD_H_
+#define _FMOD_H_
+
+/* ========================================================================================== */
+/* DEFINITIONS */
+/* ========================================================================================== */
+
+#if !defined(WIN32) || (defined(__GNUC__) && defined(WIN32))
+ #ifndef _cdecl
+ #define _cdecl
+ #endif
+ #ifndef _stdcall
+ #define _stdcall
+ #endif
+#endif
+
+#define F_API _stdcall
+
+#ifdef DLL_EXPORTS
+ #define DLL_API __declspec(dllexport)
+#else
+ #if defined(__LCC__) || defined(__MINGW32__) || defined(__CYGWIN32__)
+ #define DLL_API F_API
+ #else
+ #define DLL_API
+ #endif /* __LCC__ || __MINGW32__ || __CYGWIN32__ */
+#endif /* DLL_EXPORTS */
+
+#define FMOD_VERSION 3.6f
+
+/*
+ FMOD defined types
+*/
+typedef struct FSOUND_SAMPLE FSOUND_SAMPLE;
+typedef struct FSOUND_STREAM FSOUND_STREAM;
+typedef struct FSOUND_DSPUNIT FSOUND_DSPUNIT;
+typedef struct FMUSIC_MODULE FMUSIC_MODULE;
+
+/*
+ Callback types
+*/
+typedef void * (_cdecl *FSOUND_DSPCALLBACK) (void *originalbuffer, void *newbuffer, int length, int param);
+typedef signed char (_cdecl *FSOUND_STREAMCALLBACK) (FSOUND_STREAM *stream, void *buff, int len, int param);
+typedef void * (_cdecl *FSOUND_ALLOCCALLBACK) (unsigned int size);
+typedef void * (_cdecl *FSOUND_REALLOCCALLBACK)(void *ptr, unsigned int size);
+typedef void (_cdecl *FSOUND_FREECALLBACK) (void *ptr);
+typedef unsigned int(_cdecl *FSOUND_OPENCALLBACK) (const char *name);
+typedef void (_cdecl *FSOUND_CLOSECALLBACK) (unsigned int handle);
+typedef int (_cdecl *FSOUND_READCALLBACK) (void *buffer, int size, unsigned int handle);
+typedef int (_cdecl *FSOUND_SEEKCALLBACK) (unsigned int handle, int pos, signed char mode);
+typedef int (_cdecl *FSOUND_TELLCALLBACK) (unsigned int handle);
+typedef void (_cdecl *FMUSIC_CALLBACK) (FMUSIC_MODULE *mod, unsigned char param);
+
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ On failure of commands in FMOD, use FSOUND_GetError to attain what happened.
+
+ [SEE_ALSO]
+ FSOUND_GetError
+]
+*/
+enum FMOD_ERRORS
+{
+ FMOD_ERR_NONE, /* No errors */
+ FMOD_ERR_BUSY, /* Cannot call this command after FSOUND_Init. Call FSOUND_Close first. */
+ FMOD_ERR_UNINITIALIZED, /* This command failed because FSOUND_Init or FSOUND_SetOutput was not called */
+ FMOD_ERR_INIT, /* Error initializing output device. */
+ FMOD_ERR_ALLOCATED, /* Error initializing output device, but more specifically, the output device is already in use and cannot be reused. */
+ FMOD_ERR_PLAY, /* Playing the sound failed. */
+ FMOD_ERR_OUTPUT_FORMAT, /* Soundcard does not support the features needed for this soundsystem (16bit stereo output) */
+ FMOD_ERR_COOPERATIVELEVEL, /* Error setting cooperative level for hardware. */
+ FMOD_ERR_CREATEBUFFER, /* Error creating hardware sound buffer. */
+ FMOD_ERR_FILE_NOTFOUND, /* File not found */
+ FMOD_ERR_FILE_FORMAT, /* Unknown file format */
+ FMOD_ERR_FILE_BAD, /* Error loading file */
+ FMOD_ERR_MEMORY, /* Not enough memory or resources */
+ FMOD_ERR_VERSION, /* The version number of this file format is not supported */
+ FMOD_ERR_INVALID_PARAM, /* An invalid parameter was passed to this function */
+ FMOD_ERR_NO_EAX, /* Tried to use an EAX command on a non EAX enabled channel or output. */
+ FMOD_ERR_CHANNEL_ALLOC, /* Failed to allocate a new channel */
+ FMOD_ERR_RECORD, /* Recording is not supported on this machine */
+ FMOD_ERR_MEDIAPLAYER, /* Windows Media Player not installed so cannot play wma or use internet streaming. */
+ FMOD_ERR_CDDEVICE /* An error occured trying to open the specified CD device */
+};
+
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ These output types are used with FSOUND_SetOutput, to choose which output driver to use.
+
+ FSOUND_OUTPUT_DSOUND will not support hardware 3d acceleration if the sound card driver
+ does not support DirectX 6 Voice Manager Extensions.
+
+ FSOUND_OUTPUT_WINMM is recommended for NT and CE.
+
+ [SEE_ALSO]
+ FSOUND_SetOutput
+ FSOUND_GetOutput
+]
+*/
+enum FSOUND_OUTPUTTYPES
+{
+ FSOUND_OUTPUT_NOSOUND, /* NoSound driver, all calls to this succeed but do nothing. */
+ FSOUND_OUTPUT_WINMM, /* Windows Multimedia driver. */
+ FSOUND_OUTPUT_DSOUND, /* DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support. */
+ FSOUND_OUTPUT_A3D, /* A3D driver. not supported any more. */
+
+ FSOUND_OUTPUT_OSS, /* Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers. */
+ FSOUND_OUTPUT_ESD, /* Linux/Unix ESD (Enlightment Sound Daemon) driver. */
+ FSOUND_OUTPUT_ALSA, /* Linux Alsa driver. */
+
+ FSOUND_OUTPUT_ASIO, /* Low latency ASIO driver */
+ FSOUND_OUTPUT_XBOX, /* Xbox driver */
+ FSOUND_OUTPUT_PS2, /* PlayStation 2 driver */
+ FSOUND_OUTPUT_MAC /* Mac SoundMager driver */
+};
+
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ These mixer types are used with FSOUND_SetMixer, to choose which mixer to use, or to act
+ upon for other reasons using FSOUND_GetMixer.
+ It is not nescessary to set the mixer. FMOD will autodetect the best mixer for you.
+
+ [SEE_ALSO]
+ FSOUND_SetMixer
+ FSOUND_GetMixer
+]
+*/
+enum FSOUND_MIXERTYPES
+{
+ FSOUND_MIXER_AUTODETECT, /* CE/PS2 Only - Non interpolating/low quality mixer. */
+ FSOUND_MIXER_BLENDMODE, /* removed / obsolete. */
+ FSOUND_MIXER_MMXP5, /* removed / obsolete. */
+ FSOUND_MIXER_MMXP6, /* removed / obsolete. */
+
+ FSOUND_MIXER_QUALITY_AUTODETECT,/* All platforms - Autodetect the fastest quality mixer based on your cpu. */
+ FSOUND_MIXER_QUALITY_FPU, /* Win32/Linux only - Interpolating/volume ramping FPU mixer. */
+ FSOUND_MIXER_QUALITY_MMXP5, /* Win32/Linux only - Interpolating/volume ramping P5 MMX mixer. */
+ FSOUND_MIXER_QUALITY_MMXP6, /* Win32/Linux only - Interpolating/volume ramping ppro+ MMX mixer. */
+
+ FSOUND_MIXER_MONO, /* CE/PS2 only - MONO non interpolating/low quality mixer. For speed*/
+ FSOUND_MIXER_QUALITY_MONO, /* CE/PS2 only - MONO Interpolating mixer. For speed */
+
+ FSOUND_MIXER_MAX
+};
+
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ These definitions describe the type of song being played.
+
+ [SEE_ALSO]
+ FMUSIC_GetType
+]
+*/
+enum FMUSIC_TYPES
+{
+ FMUSIC_TYPE_NONE,
+ FMUSIC_TYPE_MOD, /* Protracker / Fasttracker */
+ FMUSIC_TYPE_S3M, /* ScreamTracker 3 */
+ FMUSIC_TYPE_XM, /* FastTracker 2 */
+ FMUSIC_TYPE_IT, /* Impulse Tracker. */
+ FMUSIC_TYPE_MIDI /* MIDI file */
+};
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_DSP_PRIORITIES
+
+ [DESCRIPTION]
+ These default priorities are used by FMOD internal system DSP units. They describe the
+ position of the DSP chain, and the order of how audio processing is executed.
+ You can actually through the use of FSOUND_DSP_GetxxxUnit (where xxx is the name of the DSP
+ unit), disable or even change the priority of a DSP unit.
+
+ [SEE_ALSO]
+ FSOUND_DSP_Create
+ FSOUND_DSP_SetPriority
+ FSOUND_DSP_GetSpectrum
+]
+*/
+#define FSOUND_DSP_DEFAULTPRIORITY_CLEARUNIT 0 /* DSP CLEAR unit - done first */
+#define FSOUND_DSP_DEFAULTPRIORITY_SFXUNIT 100 /* DSP SFX unit - done second */
+#define FSOUND_DSP_DEFAULTPRIORITY_MUSICUNIT 200 /* DSP MUSIC unit - done third */
+#define FSOUND_DSP_DEFAULTPRIORITY_USER 300 /* User priority, use this as reference */
+#define FSOUND_DSP_DEFAULTPRIORITY_FFTUNIT 900 /* This reads data for FSOUND_DSP_GetSpectrum, so it comes after user units */
+#define FSOUND_DSP_DEFAULTPRIORITY_CLIPANDCOPYUNIT 1000 /* DSP CLIP AND COPY unit - last */
+/* [DEFINE_END] */
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_CAPS
+
+ [DESCRIPTION]
+ Driver description bitfields. Use FSOUND_Driver_GetCaps to determine if a driver enumerated
+ has the settings you are after. The enumerated driver depends on the output mode, see
+ FSOUND_OUTPUTTYPES
+
+ [SEE_ALSO]
+ FSOUND_GetDriverCaps
+ FSOUND_OUTPUTTYPES
+]
+*/
+#define FSOUND_CAPS_HARDWARE 0x1 /* This driver supports hardware accelerated 3d sound. */
+#define FSOUND_CAPS_EAX2 0x2 /* This driver supports EAX 2 reverb */
+#define FSOUND_CAPS_EAX3 0x10 /* This driver supports EAX 3 reverb */
+/* [DEFINE_END] */
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_MODES
+
+ [DESCRIPTION]
+ Sample description bitfields, OR them together for loading and describing samples.
+ NOTE. If the file format being loaded already has a defined format, such as WAV or MP3, then
+ trying to override the pre-defined format with a new set of format flags will not work. For
+ example, an 8 bit WAV file will not load as 16bit if you specify FSOUND_16BITS. It will just
+ ignore the flag and go ahead loading it as 8bits. For these type of formats the only flags
+ you can specify that will really alter the behaviour of how it is loaded, are the following.
+
+ FSOUND_LOOP_OFF
+ FSOUND_LOOP_NORMAL
+ FSOUND_LOOP_BIDI
+ FSOUND_HW3D
+ FSOUND_2D
+ FSOUND_STREAMABLE
+ FSOUND_LOADMEMORY
+ FSOUND_LOADRAW
+ FSOUND_MPEGACCURATE
+
+ See flag descriptions for what these do.
+]
+*/
+#define FSOUND_LOOP_OFF 0x00000001 /* For non looping samples. */
+#define FSOUND_LOOP_NORMAL 0x00000002 /* For forward looping samples. */
+#define FSOUND_LOOP_BIDI 0x00000004 /* For bidirectional looping samples. (no effect if in hardware). */
+#define FSOUND_8BITS 0x00000008 /* For 8 bit samples. */
+#define FSOUND_16BITS 0x00000010 /* For 16 bit samples. */
+#define FSOUND_MONO 0x00000020 /* For mono samples. */
+#define FSOUND_STEREO 0x00000040 /* For stereo samples. */
+#define FSOUND_UNSIGNED 0x00000080 /* For user created source data containing unsigned samples. */
+#define FSOUND_SIGNED 0x00000100 /* For user created source data containing signed data. */
+#define FSOUND_DELTA 0x00000200 /* For user created source data stored as delta values. */
+#define FSOUND_IT214 0x00000400 /* For user created source data stored using IT214 compression. */
+#define FSOUND_IT215 0x00000800 /* For user created source data stored using IT215 compression. */
+#define FSOUND_HW3D 0x00001000 /* Attempts to make samples use 3d hardware acceleration. (if the card supports it) */
+#define FSOUND_2D 0x00002000 /* Tells software (not hardware) based sample not to be included in 3d processing. */
+#define FSOUND_STREAMABLE 0x00004000 /* For a streamimg sound where you feed the data to it. */
+#define FSOUND_LOADMEMORY 0x00008000 /* "name" will be interpreted as a pointer to data for streaming and samples. */
+#define FSOUND_LOADRAW 0x00010000 /* Will ignore file format and treat as raw pcm. */
+#define FSOUND_MPEGACCURATE 0x00020000 /* For FSOUND_Stream_OpenFile - for accurate FSOUND_Stream_GetLengthMs/FSOUND_Stream_SetTime. WARNING, see FSOUND_Stream_OpenFile for inital opening time performance issues. */
+#define FSOUND_FORCEMONO 0x00040000 /* For forcing stereo streams and samples to be mono - needed if using FSOUND_HW3D and stereo data - incurs a small speed hit for streams */
+#define FSOUND_HW2D 0x00080000 /* 2D hardware sounds. allows hardware specific effects */
+#define FSOUND_ENABLEFX 0x00100000 /* Allows DX8 FX to be played back on a sound. Requires DirectX 8 - Note these sounds cannot be played more than once, be 8 bit, be less than a certain size, or have a changing frequency */
+#define FSOUND_MPEGHALFRATE 0x00200000 /* For FMODCE only - decodes mpeg streams using a lower quality decode, but faster execution */
+#define FSOUND_XADPCM 0x00400000 /* For XBOX only - Describes a user sample that its contents are compressed as XADPCM */
+#define FSOUND_VAG 0x00800000 /* For PS2 only - Describes a user sample that its contents are compressed as Sony VAG format */
+#define FSOUND_NONBLOCKING 0x01000000 /* For FSOUND_Stream_OpenFile - Causes stream to open in the background and not block the foreground app - stream functions only work when ready. Poll any stream function determine when it IS ready. */
+
+#define FSOUND_NORMAL (FSOUND_16BITS | FSOUND_SIGNED | FSOUND_MONO)
+/* [DEFINE_END] */
+
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_CDPLAYMODES
+
+ [DESCRIPTION]
+ Playback method for a CD Audio track, with FSOUND_CD_SetPlayMode
+
+ [SEE_ALSO]
+ FSOUND_CD_SetPlayMode
+ FSOUND_CD_Play
+]
+*/
+#define FSOUND_CD_PLAYCONTINUOUS 0 /* Starts from the current track and plays to end of CD. */
+#define FSOUND_CD_PLAYONCE 1 /* Plays the specified track then stops. */
+#define FSOUND_CD_PLAYLOOPED 2 /* Plays the specified track looped, forever until stopped manually. */
+#define FSOUND_CD_PLAYRANDOM 3 /* Plays tracks in random order */
+/* [DEFINE_END] */
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_MISC_VALUES
+
+ [DESCRIPTION]
+ Miscellaneous values for FMOD functions.
+
+ [SEE_ALSO]
+ FSOUND_PlaySound
+ FSOUND_PlaySoundEx
+ FSOUND_Sample_Alloc
+ FSOUND_Sample_Load
+ FSOUND_SetPan
+]
+*/
+#define FSOUND_FREE -1 /* value to play on any free channel, or to allocate a sample in a free sample slot. */
+#define FSOUND_UNMANAGED -2 /* value to allocate a sample that is NOT managed by FSOUND or placed in a sample slot. */
+#define FSOUND_ALL -3 /* for a channel index , this flag will affect ALL channels available! Not supported by every function. */
+#define FSOUND_STEREOPAN -1 /* value for FSOUND_SetPan so that stereo sounds are not played at half volume. See FSOUND_SetPan for more on this. */
+#define FSOUND_SYSTEMCHANNEL -1000 /* special 'channel' ID for all channel based functions that want to alter the global FSOUND software mixing output channel */
+#define FSOUND_SYSTEMSAMPLE -1000 /* special 'sample' ID for all sample based functions that want to alter the global FSOUND software mixing output sample */
+
+/* [DEFINE_END] */
+
+
+/*
+[STRUCTURE]
+[
+ [DESCRIPTION]
+ Structure defining a reverb environment.
+
+ For more indepth descriptions of the reverb properties under win32, please see the EAX2 and EAX3
+ documentation at http://developer.creative.com/ under the 'downloads' section.
+ If they do not have the EAX3 documentation, then most information can be attained from
+ the EAX2 documentation, as EAX3 only adds some more parameters and functionality on top of
+ EAX2.
+ Note the default reverb properties are the same as the FSOUND_PRESET_GENERIC preset.
+ Note that integer values that typically range from -10,000 to 1000 are represented in
+ decibels, and are of a logarithmic scale, not linear, wheras float values are typically linear.
+ PORTABILITY: Each member has the platform it supports in braces ie (win32/xbox).
+ Some reverb parameters are only supported in win32 and some only on xbox. If all parameters are set then
+ the reverb should product a similar effect on either platform.
+ Linux and FMODCE do not support the reverb api.
+
+ The numerical values listed below are the maximum, minimum and default values for each variable respectively.
+
+ [SEE_ALSO]
+ FSOUND_Reverb_SetProperties
+ FSOUND_Reverb_GetProperties
+ FSOUND_REVERB_PRESETS
+ FSOUND_REVERB_FLAGS
+]
+*/
+typedef struct _FSOUND_REVERB_PROPERTIES /* MIN MAX DEFAULT DESCRIPTION */
+{
+ unsigned int Environment; /* 0 , 25 , 0 , sets all listener properties (win32/ps2 only) */
+ float EnvSize; /* 1.0 , 100.0 , 7.5 , environment size in meters (win32 only) */
+ float EnvDiffusion; /* 0.0 , 1.0 , 1.0 , environment diffusion (win32/xbox) */
+ int Room; /* -10000, 0 , -1000 , room effect level (at mid frequencies) (win32/xbox/ps2) */
+ int RoomHF; /* -10000, 0 , -100 , relative room effect level at high frequencies (win32/xbox) */
+ int RoomLF; /* -10000, 0 , 0 , relative room effect level at low frequencies (win32 only) */
+ float DecayTime; /* 0.1 , 20.0 , 1.49 , reverberation decay time at mid frequencies (win32/xbox) */
+ float DecayHFRatio; /* 0.1 , 2.0 , 0.83 , high-frequency to mid-frequency decay time ratio (win32/xbox) */
+ float DecayLFRatio; /* 0.1 , 2.0 , 1.0 , low-frequency to mid-frequency decay time ratio (win32 only) */
+ int Reflections; /* -10000, 1000 , -2602 , early reflections level relative to room effect (win32/xbox) */
+ float ReflectionsDelay; /* 0.0 , 0.3 , 0.007 , initial reflection delay time (win32/xbox) */
+ float ReflectionsPan[3]; /* , , [0,0,0], early reflections panning vector (win32 only) */
+ int Reverb; /* -10000, 2000 , 200 , late reverberation level relative to room effect (win32/xbox) */
+ float ReverbDelay; /* 0.0 , 0.1 , 0.011 , late reverberation delay time relative to initial reflection (win32/xbox) */
+ float ReverbPan[3]; /* , , [0,0,0], late reverberation panning vector (win32 only) */
+ float EchoTime; /* .075 , 0.25 , 0.25 , echo time (win32 only) */
+ float EchoDepth; /* 0.0 , 1.0 , 0.0 , echo depth (win32 only) */
+ float ModulationTime; /* 0.04 , 4.0 , 0.25 , modulation time (win32 only) */
+ float ModulationDepth; /* 0.0 , 1.0 , 0.0 , modulation depth (win32 only) */
+ float AirAbsorptionHF; /* -100 , 0.0 , -5.0 , change in level per meter at high frequencies (win32 only) */
+ float HFReference; /* 1000.0, 20000 , 5000.0 , reference high frequency (hz) (win32/xbox) */
+ float LFReference; /* 20.0 , 1000.0, 250.0 , reference low frequency (hz) (win32 only) */
+ float RoomRolloffFactor; /* 0.0 , 10.0 , 0.0 , like FSOUND_3D_Listener_SetRolloffFactor but for room effect (win32/xbox) */
+ float Diffusion; /* 0.0 , 100.0 , 100.0 , Value that controls the echo density in the late reverberation decay. (xbox only) */
+ float Density; /* 0.0 , 100.0 , 100.0 , Value that controls the modal density in the late reverberation decay (xbox only) */
+ unsigned int Flags; /* FSOUND_REVERB_FLAGS - modifies the behavior of above properties (win32 only) */
+} FSOUND_REVERB_PROPERTIES;
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_REVERB_FLAGS
+
+ [DESCRIPTION]
+ Values for the Flags member of the FSOUND_REVERB_PROPERTIES structure.
+
+ [SEE_ALSO]
+ FSOUND_REVERB_PROPERTIES
+]
+*/
+#define FSOUND_REVERB_FLAGS_DECAYTIMESCALE 0x00000001 /* 'EnvSize' affects reverberation decay time */
+#define FSOUND_REVERB_FLAGS_REFLECTIONSSCALE 0x00000002 /* 'EnvSize' affects reflection level */
+#define FSOUND_REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004 /* 'EnvSize' affects initial reflection delay time */
+#define FSOUND_REVERB_FLAGS_REVERBSCALE 0x00000008 /* 'EnvSize' affects reflections level */
+#define FSOUND_REVERB_FLAGS_REVERBDELAYSCALE 0x00000010 /* 'EnvSize' affects late reverberation delay time */
+#define FSOUND_REVERB_FLAGS_DECAYHFLIMIT 0x00000020 /* AirAbsorptionHF affects DecayHFRatio */
+#define FSOUND_REVERB_FLAGS_ECHOTIMESCALE 0x00000040 /* 'EnvSize' affects echo time */
+#define FSOUND_REVERB_FLAGS_MODULATIONTIMESCALE 0x00000080 /* 'EnvSize' affects modulation time */
+#define FSOUND_REVERB_FLAGS_CORE0 0x00000100 /* PS2 Only - Reverb is applied to CORE0 (hw voices 0-23) */
+#define FSOUND_REVERB_FLAGS_CORE1 0x00000200 /* PS2 Only - Reverb is applied to CORE1 (hw voices 24-47) */
+#define FSOUND_REVERB_FLAGS_DEFAULT (FSOUND_REVERB_FLAGS_DECAYTIMESCALE | \
+ FSOUND_REVERB_FLAGS_REFLECTIONSSCALE | \
+ FSOUND_REVERB_FLAGS_REFLECTIONSDELAYSCALE | \
+ FSOUND_REVERB_FLAGS_REVERBSCALE | \
+ FSOUND_REVERB_FLAGS_REVERBDELAYSCALE | \
+ FSOUND_REVERB_FLAGS_DECAYHFLIMIT | \
+ FSOUND_REVERB_FLAGS_CORE0 | \
+ FSOUND_REVERB_FLAGS_CORE1 )
+/* [DEFINE_END] */
+
+
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_REVERB_PRESETS
+
+ [DESCRIPTION]
+ A set of predefined environment PARAMETERS, created by Creative Labs
+ These are used to initialize an FSOUND_REVERB_PROPERTIES structure statically.
+ ie
+ FSOUND_REVERB_PROPERTIES prop = FSOUND_PRESET_GENERIC;
+
+ [SEE_ALSO]
+ FSOUND_Reverb_SetProperties
+]
+*/
+/* Env Size Diffus Room RoomHF RmLF DecTm DecHF DecLF Refl RefDel RefPan Revb RevDel ReverbPan EchoTm EchDp ModTm ModDp AirAbs HFRef LFRef RRlOff Diffus Densty FLAGS */
+#define FSOUND_PRESET_OFF {0, 7.5f, 1.00f, -10000, -10000, 0, 1.00f, 1.00f, 1.0f, -2602, 0.007f, { 0.0f,0.0f,0.0f }, 200, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 0.0f, 0.0f, 0x33f }
+#define FSOUND_PRESET_GENERIC {0, 7.5f, 1.00f, -1000, -100, 0, 1.49f, 0.83f, 1.0f, -2602, 0.007f, { 0.0f,0.0f,0.0f }, 200, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_PADDEDCELL {1, 1.4f, 1.00f, -1000, -6000, 0, 0.17f, 0.10f, 1.0f, -1204, 0.001f, { 0.0f,0.0f,0.0f }, 207, 0.002f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_ROOM {2, 1.9f, 1.00f, -1000, -454, 0, 0.40f, 0.83f, 1.0f, -1646, 0.002f, { 0.0f,0.0f,0.0f }, 53, 0.003f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_BATHROOM {3, 1.4f, 1.00f, -1000, -1200, 0, 1.49f, 0.54f, 1.0f, -370, 0.007f, { 0.0f,0.0f,0.0f }, 1030, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 60.0f, 0x3f }
+#define FSOUND_PRESET_LIVINGROOM {4, 2.5f, 1.00f, -1000, -6000, 0, 0.50f, 0.10f, 1.0f, -1376, 0.003f, { 0.0f,0.0f,0.0f }, -1104, 0.004f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_STONEROOM {5, 11.6f, 1.00f, -1000, -300, 0, 2.31f, 0.64f, 1.0f, -711, 0.012f, { 0.0f,0.0f,0.0f }, 83, 0.017f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_AUDITORIUM {6, 21.6f, 1.00f, -1000, -476, 0, 4.32f, 0.59f, 1.0f, -789, 0.020f, { 0.0f,0.0f,0.0f }, -289, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_CONCERTHALL {7, 19.6f, 1.00f, -1000, -500, 0, 3.92f, 0.70f, 1.0f, -1230, 0.020f, { 0.0f,0.0f,0.0f }, -2, 0.029f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_CAVE {8, 14.6f, 1.00f, -1000, 0, 0, 2.91f, 1.30f, 1.0f, -602, 0.015f, { 0.0f,0.0f,0.0f }, -302, 0.022f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f }
+#define FSOUND_PRESET_ARENA {9, 36.2f, 1.00f, -1000, -698, 0, 7.24f, 0.33f, 1.0f, -1166, 0.020f, { 0.0f,0.0f,0.0f }, 16, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_HANGAR {10, 50.3f, 1.00f, -1000, -1000, 0, 10.05f, 0.23f, 1.0f, -602, 0.020f, { 0.0f,0.0f,0.0f }, 198, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_CARPETTEDHALLWAY {11, 1.9f, 1.00f, -1000, -4000, 0, 0.30f, 0.10f, 1.0f, -1831, 0.002f, { 0.0f,0.0f,0.0f }, -1630, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_HALLWAY {12, 1.8f, 1.00f, -1000, -300, 0, 1.49f, 0.59f, 1.0f, -1219, 0.007f, { 0.0f,0.0f,0.0f }, 441, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_STONECORRIDOR {13, 13.5f, 1.00f, -1000, -237, 0, 2.70f, 0.79f, 1.0f, -1214, 0.013f, { 0.0f,0.0f,0.0f }, 395, 0.020f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_ALLEY {14, 7.5f, 0.30f, -1000, -270, 0, 1.49f, 0.86f, 1.0f, -1204, 0.007f, { 0.0f,0.0f,0.0f }, -4, 0.011f, { 0.0f,0.0f,0.0f }, 0.125f, 0.95f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_FOREST {15, 38.0f, 0.30f, -1000, -3300, 0, 1.49f, 0.54f, 1.0f, -2560, 0.162f, { 0.0f,0.0f,0.0f }, -229, 0.088f, { 0.0f,0.0f,0.0f }, 0.125f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 79.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_CITY {16, 7.5f, 0.50f, -1000, -800, 0, 1.49f, 0.67f, 1.0f, -2273, 0.007f, { 0.0f,0.0f,0.0f }, -1691, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 50.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_MOUNTAINS {17, 100.0f, 0.27f, -1000, -2500, 0, 1.49f, 0.21f, 1.0f, -2780, 0.300f, { 0.0f,0.0f,0.0f }, -1434, 0.100f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 27.0f, 100.0f, 0x1f }
+#define FSOUND_PRESET_QUARRY {18, 17.5f, 1.00f, -1000, -1000, 0, 1.49f, 0.83f, 1.0f, -10000, 0.061f, { 0.0f,0.0f,0.0f }, 500, 0.025f, { 0.0f,0.0f,0.0f }, 0.125f, 0.70f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_PLAIN {19, 42.5f, 0.21f, -1000, -2000, 0, 1.49f, 0.50f, 1.0f, -2466, 0.179f, { 0.0f,0.0f,0.0f }, -1926, 0.100f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 21.0f, 100.0f, 0x3f }
+#define FSOUND_PRESET_PARKINGLOT {20, 8.3f, 1.00f, -1000, 0, 0, 1.65f, 1.50f, 1.0f, -1363, 0.008f, { 0.0f,0.0f,0.0f }, -1153, 0.012f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f }
+#define FSOUND_PRESET_SEWERPIPE {21, 1.7f, 0.80f, -1000, -1000, 0, 2.81f, 0.14f, 1.0f, 429, 0.014f, { 0.0f,0.0f,0.0f }, 1023, 0.021f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 80.0f, 60.0f, 0x3f }
+#define FSOUND_PRESET_UNDERWATER {22, 1.8f, 1.00f, -1000, -4000, 0, 1.49f, 0.10f, 1.0f, -449, 0.007f, { 0.0f,0.0f,0.0f }, 1700, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 1.18f, 0.348f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f }
+
+/* Non I3DL2 presets */
+
+#define FSOUND_PRESET_DRUGGED {23, 1.9f, 0.50f, -1000, 0, 0, 8.39f, 1.39f, 1.0f, -115, 0.002f, { 0.0f,0.0f,0.0f }, 985, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 1.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f }
+#define FSOUND_PRESET_DIZZY {24, 1.8f, 0.60f, -1000, -400, 0, 17.23f, 0.56f, 1.0f, -1713, 0.020f, { 0.0f,0.0f,0.0f }, -613, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.81f, 0.310f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f }
+#define FSOUND_PRESET_PSYCHOTIC {25, 1.0f, 0.50f, -1000, -151, 0, 7.56f, 0.91f, 1.0f, -626, 0.020f, { 0.0f,0.0f,0.0f }, 774, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 4.00f, 1.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f }
+
+/* PlayStation 2 Only presets */
+
+#define FSOUND_PRESET_PS2_ROOM {1, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_STUDIO_A {2, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_STUDIO_B {3, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_STUDIO_C {4, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_HALL {5, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_SPACE {6, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_ECHO {7, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_DELAY {8, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+#define FSOUND_PRESET_PS2_PIPE {9, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f }
+
+/* [DEFINE_END] */
+
+
+/*
+[STRUCTURE]
+[
+ [DESCRIPTION]
+ Structure defining the properties for a reverb source, related to a FSOUND channel.
+
+ For more indepth descriptions of the reverb properties under win32, please see the EAX3
+ documentation at http://developer.creative.com/ under the 'downloads' section.
+ If they do not have the EAX3 documentation, then most information can be attained from
+ the EAX2 documentation, as EAX3 only adds some more parameters and functionality on top of
+ EAX2.
+
+ Note the default reverb properties are the same as the FSOUND_PRESET_GENERIC preset.
+ Note that integer values that typically range from -10,000 to 1000 are represented in
+ decibels, and are of a logarithmic scale, not linear, wheras float values are typically linear.
+ PORTABILITY: Each member has the platform it supports in braces ie (win32/xbox).
+ Some reverb parameters are only supported in win32 and some only on xbox. If all parameters are set then
+ the reverb should product a similar effect on either platform.
+ Linux and FMODCE do not support the reverb api.
+
+ The numerical values listed below are the maximum, minimum and default values for each variable respectively.
+
+ [SEE_ALSO]
+ FSOUND_Reverb_SetChannelProperties
+ FSOUND_Reverb_GetChannelProperties
+ FSOUND_REVERB_CHANNELFLAGS
+]
+*/
+typedef struct _FSOUND_REVERB_CHANNELPROPERTIES /* MIN MAX DEFAULT */
+{
+ int Direct; /* -10000, 1000, 0, direct path level (at low and mid frequencies) (win32/xbox) */
+ int DirectHF; /* -10000, 0, 0, relative direct path level at high frequencies (win32/xbox) */
+ int Room; /* -10000, 1000, 0, room effect level (at low and mid frequencies) (win32/xbox) */
+ int RoomHF; /* -10000, 0, 0, relative room effect level at high frequencies (win32/xbox) */
+ int Obstruction; /* -10000, 0, 0, main obstruction control (attenuation at high frequencies) (win32/xbox) */
+ float ObstructionLFRatio; /* 0.0, 1.0, 0.0, obstruction low-frequency level re. main control (win32/xbox) */
+ int Occlusion; /* -10000, 0, 0, main occlusion control (attenuation at high frequencies) (win32/xbox) */
+ float OcclusionLFRatio; /* 0.0, 1.0, 0.25, occlusion low-frequency level re. main control (win32/xbox) */
+ float OcclusionRoomRatio; /* 0.0, 10.0, 1.5, relative occlusion control for room effect (win32) */
+ float OcclusionDirectRatio; /* 0.0, 10.0, 1.0, relative occlusion control for direct path (win32) */
+ int Exclusion; /* -10000, 0, 0, main exlusion control (attenuation at high frequencies) (win32) */
+ float ExclusionLFRatio; /* 0.0, 1.0, 1.0, exclusion low-frequency level re. main control (win32) */
+ int OutsideVolumeHF; /* -10000, 0, 0, outside sound cone level at high frequencies (win32) */
+ float DopplerFactor; /* 0.0, 10.0, 0.0, like DS3D flDopplerFactor but per source (win32) */
+ float RolloffFactor; /* 0.0, 10.0, 0.0, like DS3D flRolloffFactor but per source (win32) */
+ float RoomRolloffFactor; /* 0.0, 10.0, 0.0, like DS3D flRolloffFactor but for room effect (win32/xbox) */
+ float AirAbsorptionFactor; /* 0.0, 10.0, 1.0, multiplies AirAbsorptionHF member of FSOUND_REVERB_PROPERTIES (win32) */
+ int Flags; /* FSOUND_REVERB_CHANNELFLAGS - modifies the behavior of properties (win32) */
+} FSOUND_REVERB_CHANNELPROPERTIES;
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_REVERB_CHANNELFLAGS
+
+ [DESCRIPTION]
+ Values for the Flags member of the FSOUND_REVERB_CHANNELPROPERTIES structure.
+
+ [SEE_ALSO]
+ FSOUND_REVERB_CHANNELPROPERTIES
+]
+*/
+#define FSOUND_REVERB_CHANNELFLAGS_DIRECTHFAUTO 0x00000001 /* Automatic setting of 'Direct' due to distance from listener */
+#define FSOUND_REVERB_CHANNELFLAGS_ROOMAUTO 0x00000002 /* Automatic setting of 'Room' due to distance from listener */
+#define FSOUND_REVERB_CHANNELFLAGS_ROOMHFAUTO 0x00000004 /* Automatic setting of 'RoomHF' due to distance from listener */
+#define FSOUND_REVERB_CHANNELFLAGS_DEFAULT (FSOUND_REVERB_CHANNELFLAGS_DIRECTHFAUTO | \
+ FSOUND_REVERB_CHANNELFLAGS_ROOMAUTO| \
+ FSOUND_REVERB_CHANNELFLAGS_ROOMHFAUTO)
+/* [DEFINE_END] */
+
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ These values are used with FSOUND_FX_Enable to enable DirectX 8 FX for a channel.
+
+ [SEE_ALSO]
+ FSOUND_FX_Enable
+ FSOUND_FX_Disable
+ FSOUND_FX_SetChorus
+ FSOUND_FX_SetCompressor
+ FSOUND_FX_SetDistortion
+ FSOUND_FX_SetEcho
+ FSOUND_FX_SetFlanger
+ FSOUND_FX_SetGargle
+ FSOUND_FX_SetI3DL2Reverb
+ FSOUND_FX_SetParamEQ
+ FSOUND_FX_SetWavesReverb
+]
+*/
+enum FSOUND_FX_MODES
+{
+ FSOUND_FX_CHORUS,
+ FSOUND_FX_COMPRESSOR,
+ FSOUND_FX_DISTORTION,
+ FSOUND_FX_ECHO,
+ FSOUND_FX_FLANGER,
+ FSOUND_FX_GARGLE,
+ FSOUND_FX_I3DL2REVERB,
+ FSOUND_FX_PARAMEQ,
+ FSOUND_FX_WAVES_REVERB,
+
+ FSOUND_FX_MAX
+};
+
+/*
+[ENUM]
+[
+ [DESCRIPTION]
+ These are speaker types defined for use with the FSOUND_SetSpeakerMode command.
+ Note - Only reliably works with FSOUND_OUTPUT_DSOUND or FSOUND_OUTPUT_XBOX output modes. Other output modes will only
+ interpret FSOUND_SPEAKERMODE_MONO and set everything else to be stereo.
+
+ [SEE_ALSO]
+ FSOUND_SetSpeakerMode
+]
+*/
+enum FSOUND_SPEAKERMODES
+{
+ FSOUND_SPEAKERMODE_DOLBYDIGITAL, /* The audio is played through a speaker arrangement of surround speakers with a subwoofer. */
+ FSOUND_SPEAKERMODE_HEADPHONES, /* The speakers are headphones. */
+ FSOUND_SPEAKERMODE_MONO, /* The speakers are monaural. */
+ FSOUND_SPEAKERMODE_QUAD, /* The speakers are quadraphonic. */
+ FSOUND_SPEAKERMODE_STEREO, /* The speakers are stereo (default value). */
+ FSOUND_SPEAKERMODE_SURROUND, /* The speakers are surround sound. */
+ FSOUND_SPEAKERMODE_DTS /* (XBOX Only) The audio is played through a speaker arrangement of surround speakers with a subwoofer. */
+};
+
+
+/*
+[DEFINE_START]
+[
+ [NAME]
+ FSOUND_INIT_FLAGS
+
+ [DESCRIPTION]
+ Initialization flags. Use them with FSOUND_Init in the flags parameter to change various behaviour.
+
+ FSOUND_INIT_ENABLEOUTPUTFX Is an init mode which enables the FSOUND mixer buffer to be affected by DirectX 8 effects.
+ Note that due to limitations of DirectSound, FSOUND_Init may fail if this is enabled because the buffersize is too small.
+ This can be fixed with FSOUND_SetBufferSize. Increase the BufferSize until it works.
+ When it is enabled you can use the FSOUND_FX api, and use FSOUND_SYSTEMCHANNEL as the channel id when setting parameters.
+
+ [SEE_ALSO]
+ FSOUND_Init
+]
+*/
+#define FSOUND_INIT_USEDEFAULTMIDISYNTH 0x01 /* Causes MIDI playback to force software decoding. */
+#define FSOUND_INIT_GLOBALFOCUS 0x02 /* For DirectSound output - sound is not muted when window is out of focus. */
+#define FSOUND_INIT_ENABLEOUTPUTFX 0x04 /* For DirectSound output - Allows FSOUND_FX api to be used on global software mixer output! */
+#define FSOUND_INIT_ACCURATEVULEVELS 0x08 /* This latency adjusts FSOUND_GetCurrentLevels, but incurs a small cpu and memory hit */
+#define FSOUND_INIT_DISABLE_CORE0_REVERB 0x10 /* PS2 only - Disable reverb on CORE 0 to regain SRAM */
+#define FSOUND_INIT_DISABLE_CORE1_REVERB 0x20 /* PS2 only - Disable reverb on CORE 1 to regain SRAM */
+/* [DEFINE_END] */
+
+
+
+
+/* ========================================================================================== */
+/* FUNCTION PROTOTYPES */
+/* ========================================================================================== */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ================================== */
+/* Initialization / Global functions. */
+/* ================================== */
+
+/*
+ PRE - FSOUND_Init functions. These can't be called after FSOUND_Init is
+ called (they will fail). They set up FMOD system functionality.
+*/
+
+DLL_API signed char F_API FSOUND_SetOutput(int outputtype);
+DLL_API signed char F_API FSOUND_SetDriver(int driver);
+DLL_API signed char F_API FSOUND_SetMixer(int mixer);
+DLL_API signed char F_API FSOUND_SetBufferSize(int len_ms);
+DLL_API signed char F_API FSOUND_SetHWND(void *hwnd);
+DLL_API signed char F_API FSOUND_SetMinHardwareChannels(int min);
+DLL_API signed char F_API FSOUND_SetMaxHardwareChannels(int max);
+DLL_API signed char F_API FSOUND_SetMemorySystem(void *pool,
+ int poollen,
+ FSOUND_ALLOCCALLBACK useralloc,
+ FSOUND_REALLOCCALLBACK userrealloc,
+ FSOUND_FREECALLBACK userfree);
+/*
+ Main initialization / closedown functions.
+ Note : Use FSOUND_INIT_USEDEFAULTMIDISYNTH with FSOUND_Init for software override
+ with MIDI playback.
+ : Use FSOUND_INIT_GLOBALFOCUS with FSOUND_Init to make sound audible no matter
+ which window is in focus. (FSOUND_OUTPUT_DSOUND only)
+*/
+
+DLL_API signed char F_API FSOUND_Init(int mixrate, int maxsoftwarechannels, unsigned int flags);
+DLL_API void F_API FSOUND_Close();
+
+/*
+ Runtime system level functions
+*/
+
+DLL_API void F_API FSOUND_SetSpeakerMode(unsigned int speakermode);
+DLL_API void F_API FSOUND_SetSFXMasterVolume(int volume);
+DLL_API void F_API FSOUND_SetPanSeperation(float pansep);
+DLL_API void F_API FSOUND_File_SetCallbacks(FSOUND_OPENCALLBACK useropen,
+ FSOUND_CLOSECALLBACK userclose,
+ FSOUND_READCALLBACK userread,
+ FSOUND_SEEKCALLBACK userseek,
+ FSOUND_TELLCALLBACK usertell);
+
+/*
+ System information functions.
+*/
+
+DLL_API int F_API FSOUND_GetError();
+DLL_API float F_API FSOUND_GetVersion();
+DLL_API int F_API FSOUND_GetOutput();
+DLL_API void * F_API FSOUND_GetOutputHandle();
+DLL_API int F_API FSOUND_GetDriver();
+DLL_API int F_API FSOUND_GetMixer();
+DLL_API int F_API FSOUND_GetNumDrivers();
+DLL_API signed char * F_API FSOUND_GetDriverName(int id);
+DLL_API signed char F_API FSOUND_GetDriverCaps(int id, unsigned int *caps);
+DLL_API int F_API FSOUND_GetOutputRate();
+DLL_API int F_API FSOUND_GetMaxChannels();
+DLL_API int F_API FSOUND_GetMaxSamples();
+DLL_API int F_API FSOUND_GetSFXMasterVolume();
+DLL_API int F_API FSOUND_GetNumHardwareChannels();
+DLL_API int F_API FSOUND_GetChannelsPlaying();
+DLL_API float F_API FSOUND_GetCPUUsage();
+DLL_API void F_API FSOUND_GetMemoryStats(unsigned int *currentalloced, unsigned int *maxalloced);
+
+/* =================================== */
+/* Sample management / load functions. */
+/* =================================== */
+
+/*
+ Sample creation and management functions
+ Note : Use FSOUND_LOADMEMORY flag with FSOUND_Sample_Load to load from memory.
+ Use FSOUND_LOADRAW flag with FSOUND_Sample_Load to treat as as raw pcm data.
+*/
+
+DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Load(int index, const char *name_or_data, unsigned int mode, int memlength);
+DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Alloc(int index, int length, unsigned int mode, int deffreq, int defvol, int defpan, int defpri);
+DLL_API void F_API FSOUND_Sample_Free(FSOUND_SAMPLE *sptr);
+DLL_API signed char F_API FSOUND_Sample_Upload(FSOUND_SAMPLE *sptr, void *srcdata, unsigned int mode);
+DLL_API signed char F_API FSOUND_Sample_Lock(FSOUND_SAMPLE *sptr, int offset, int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2);
+DLL_API signed char F_API FSOUND_Sample_Unlock(FSOUND_SAMPLE *sptr, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2);
+
+/*
+ Sample control functions
+*/
+
+DLL_API signed char F_API FSOUND_Sample_SetMode(FSOUND_SAMPLE *sptr, unsigned int mode);
+DLL_API signed char F_API FSOUND_Sample_SetLoopPoints(FSOUND_SAMPLE *sptr, int loopstart, int loopend);
+DLL_API signed char F_API FSOUND_Sample_SetDefaults(FSOUND_SAMPLE *sptr, int deffreq, int defvol, int defpan, int defpri);
+DLL_API signed char F_API FSOUND_Sample_SetMinMaxDistance(FSOUND_SAMPLE *sptr, float min, float max);
+DLL_API signed char F_API FSOUND_Sample_SetMaxPlaybacks(FSOUND_SAMPLE *sptr, int max);
+
+/*
+ Sample information functions
+*/
+
+DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Get(int sampno);
+DLL_API char * F_API FSOUND_Sample_GetName(FSOUND_SAMPLE *sptr);
+DLL_API unsigned int F_API FSOUND_Sample_GetLength(FSOUND_SAMPLE *sptr);
+DLL_API signed char F_API FSOUND_Sample_GetLoopPoints(FSOUND_SAMPLE *sptr, int *loopstart, int *loopend);
+DLL_API signed char F_API FSOUND_Sample_GetDefaults(FSOUND_SAMPLE *sptr, int *deffreq, int *defvol, int *defpan, int *defpri);
+DLL_API unsigned int F_API FSOUND_Sample_GetMode(FSOUND_SAMPLE *sptr);
+
+/* ============================ */
+/* Channel control functions. */
+/* ============================ */
+
+/*
+ Playing and stopping sounds.
+ Note : Use FSOUND_FREE as the 'channel' variable, to let FMOD pick a free channel for you.
+ Use FSOUND_ALL as the 'channel' variable to control ALL channels with one function call!
+*/
+
+DLL_API int F_API FSOUND_PlaySound(int channel, FSOUND_SAMPLE *sptr);
+DLL_API int F_API FSOUND_PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
+DLL_API signed char F_API FSOUND_StopSound(int channel);
+
+/*
+ Functions to control playback of a channel.
+ Note : FSOUND_ALL can be used on most of these functions as a channel value.
+*/
+
+DLL_API signed char F_API FSOUND_SetFrequency(int channel, int freq);
+DLL_API signed char F_API FSOUND_SetVolume(int channel, int vol);
+DLL_API signed char F_API FSOUND_SetVolumeAbsolute(int channel, int vol);
+DLL_API signed char F_API FSOUND_SetPan(int channel, int pan);
+DLL_API signed char F_API FSOUND_SetSurround(int channel, signed char surround);
+DLL_API signed char F_API FSOUND_SetMute(int channel, signed char mute);
+DLL_API signed char F_API FSOUND_SetPriority(int channel, int priority);
+DLL_API signed char F_API FSOUND_SetReserved(int channel, signed char reserved);
+DLL_API signed char F_API FSOUND_SetPaused(int channel, signed char paused);
+DLL_API signed char F_API FSOUND_SetLoopMode(int channel, unsigned int loopmode);
+DLL_API signed char F_API FSOUND_SetCurrentPosition(int channel, unsigned int offset);
+
+/*
+ Channel information functions.
+*/
+
+DLL_API signed char F_API FSOUND_IsPlaying(int channel);
+DLL_API int F_API FSOUND_GetFrequency(int channel);
+DLL_API int F_API FSOUND_GetVolume(int channel);
+DLL_API int F_API FSOUND_GetPan(int channel);
+DLL_API signed char F_API FSOUND_GetSurround(int channel);
+DLL_API signed char F_API FSOUND_GetMute(int channel);
+DLL_API int F_API FSOUND_GetPriority(int channel);
+DLL_API signed char F_API FSOUND_GetReserved(int channel);
+DLL_API signed char F_API FSOUND_GetPaused(int channel);
+DLL_API unsigned int F_API FSOUND_GetLoopMode(int channel);
+DLL_API unsigned int F_API FSOUND_GetCurrentPosition(int channel);
+DLL_API FSOUND_SAMPLE * F_API FSOUND_GetCurrentSample(int channel);
+DLL_API signed char F_API FSOUND_GetCurrentLevels(int channel, float *l, float *r);
+
+
+/* =================== */
+/* FX functions. */
+/* =================== */
+
+/*
+ Functions to control DX8 only effects processing.
+
+ - FX enabled samples can only be played once at a time, not multiple times at once.
+ - Sounds have to be created with FSOUND_HW2D or FSOUND_HW3D for this to work.
+ - FSOUND_INIT_ENABLEOUTPUTFX can be used to apply hardware effect processing to the
+ global mixed output of FMOD's software channels.
+ - FSOUND_FX_Enable returns an FX handle that you can use to alter fx parameters.
+ - FSOUND_FX_Enable can be called multiple times in a row, even on the same FX type,
+ it will return a unique handle for each FX.
+ - FSOUND_FX_Enable cannot be called if the sound is playing or locked.
+ - FSOUND_FX_Disable must be called to reset/clear the FX from a channel.
+*/
+
+DLL_API int F_API FSOUND_FX_Enable(int channel, unsigned int fx); /* See FSOUND_FX_MODES */
+DLL_API signed char F_API FSOUND_FX_Disable(int channel);
+
+DLL_API signed char F_API FSOUND_FX_SetChorus(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase);
+DLL_API signed char F_API FSOUND_FX_SetCompressor(int fxid, float Gain, float Attack, float Release, float Threshold, float Ratio, float Predelay);
+DLL_API signed char F_API FSOUND_FX_SetDistortion(int fxid, float Gain, float Edge, float PostEQCenterFrequency, float PostEQBandwidth, float PreLowpassCutoff);
+DLL_API signed char F_API FSOUND_FX_SetEcho(int fxid, float WetDryMix, float Feedback, float LeftDelay, float RightDelay, int PanDelay);
+DLL_API signed char F_API FSOUND_FX_SetFlanger(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase);
+DLL_API signed char F_API FSOUND_FX_SetGargle(int fxid, int RateHz, int WaveShape);
+DLL_API signed char F_API FSOUND_FX_SetI3DL2Reverb(int fxid, int Room, int RoomHF, float RoomRolloffFactor, float DecayTime, float DecayHFRatio, int Reflections, float ReflectionsDelay, int Reverb, float ReverbDelay, float Diffusion, float Density, float HFReference);
+DLL_API signed char F_API FSOUND_FX_SetParamEQ(int fxid, float Center, float Bandwidth, float Gain);
+DLL_API signed char F_API FSOUND_FX_SetWavesReverb(int fxid, float InGain, float ReverbMix, float ReverbTime, float HighFreqRTRatio);
+
+/* =================== */
+/* 3D sound functions. */
+/* =================== */
+
+/*
+ See also FSOUND_Sample_SetMinMaxDistance (above)
+*/
+
+DLL_API void F_API FSOUND_3D_Update(); /* you must call this once a frame */
+DLL_API signed char F_API FSOUND_3D_SetAttributes(int channel, float *pos, float *vel);
+DLL_API signed char F_API FSOUND_3D_GetAttributes(int channel, float *pos, float *vel);
+DLL_API void F_API FSOUND_3D_Listener_SetAttributes(float *pos, float *vel, float fx, float fy, float fz, float tx, float ty, float tz);
+DLL_API void F_API FSOUND_3D_Listener_GetAttributes(float *pos, float *vel, float *fx, float *fy, float *fz, float *tx, float *ty, float *tz);
+DLL_API void F_API FSOUND_3D_Listener_SetDopplerFactor(float scale);
+DLL_API void F_API FSOUND_3D_Listener_SetDistanceFactor(float scale);
+DLL_API void F_API FSOUND_3D_Listener_SetRolloffFactor(float scale);
+
+/* ========================= */
+/* File Streaming functions. */
+/* ========================= */
+
+/*
+ Note : Use FSOUND_LOADMEMORY flag with FSOUND_Stream_OpenFile to stream from memory.
+ Use FSOUND_LOADRAW flag with FSOUND_Stream_OpenFile to treat stream as raw pcm data.
+ Use FSOUND_MPEGACCURATE flag with FSOUND_Stream_OpenFile to open mpegs in 'accurate mode' for settime/gettime/getlengthms.
+ Use FSOUND_FREE as the 'channel' variable, to let FMOD pick a free channel for you.
+*/
+
+DLL_API signed char F_API FSOUND_Stream_SetBufferSize(int ms); /* call this before opening streams, not after */
+
+DLL_API FSOUND_STREAM * F_API FSOUND_Stream_OpenFile(const char *filename, unsigned int mode, int memlength);
+DLL_API FSOUND_STREAM * F_API FSOUND_Stream_Create(FSOUND_STREAMCALLBACK callback, int length, unsigned int mode, int samplerate, int userdata);
+DLL_API int F_API FSOUND_Stream_Play(int channel, FSOUND_STREAM *stream);
+DLL_API int F_API FSOUND_Stream_PlayEx(int channel, FSOUND_STREAM *stream, FSOUND_DSPUNIT *dsp, signed char startpaused);
+
+DLL_API signed char F_API FSOUND_Stream_Stop(FSOUND_STREAM *stream);
+DLL_API signed char F_API FSOUND_Stream_Close(FSOUND_STREAM *stream);
+DLL_API signed char F_API FSOUND_Stream_SetEndCallback(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata);
+DLL_API signed char F_API FSOUND_Stream_SetSynchCallback(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata);
+DLL_API FSOUND_SAMPLE * F_API FSOUND_Stream_GetSample(FSOUND_STREAM *stream); /* every stream contains a sample to playback on */
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_Stream_CreateDSP(FSOUND_STREAM *stream, FSOUND_DSPCALLBACK callback, int priority, int param);
+
+DLL_API signed char F_API FSOUND_Stream_SetPosition(FSOUND_STREAM *stream, unsigned int position);
+DLL_API unsigned int F_API FSOUND_Stream_GetPosition(FSOUND_STREAM *stream);
+DLL_API signed char F_API FSOUND_Stream_SetTime(FSOUND_STREAM *stream, int ms);
+DLL_API int F_API FSOUND_Stream_GetTime(FSOUND_STREAM *stream);
+DLL_API int F_API FSOUND_Stream_GetLength(FSOUND_STREAM *stream);
+DLL_API int F_API FSOUND_Stream_GetLengthMs(FSOUND_STREAM *stream);
+
+/* =================== */
+/* CD audio functions. */
+/* =================== */
+
+/*
+ Note : 0 = default cdrom. Otherwise specify the drive letter, for example. 'D'.
+*/
+
+DLL_API signed char F_API FSOUND_CD_Play(char drive, int track);
+DLL_API void F_API FSOUND_CD_SetPlayMode(char drive, signed char mode);
+DLL_API signed char F_API FSOUND_CD_Stop(char drive);
+DLL_API signed char F_API FSOUND_CD_SetPaused(char drive, signed char paused);
+DLL_API signed char F_API FSOUND_CD_SetVolume(char drive, int volume);
+DLL_API signed char F_API FSOUND_CD_Eject(char drive);
+
+DLL_API signed char F_API FSOUND_CD_GetPaused(char drive);
+DLL_API int F_API FSOUND_CD_GetTrack(char drive);
+DLL_API int F_API FSOUND_CD_GetNumTracks(char drive);
+DLL_API int F_API FSOUND_CD_GetVolume(char drive);
+DLL_API int F_API FSOUND_CD_GetTrackLength(char drive, int track);
+DLL_API int F_API FSOUND_CD_GetTrackTime(char drive);
+
+/* ============== */
+/* DSP functions. */
+/* ============== */
+
+/*
+ DSP Unit control and information functions.
+ These functions allow you access to the mixed stream that FMOD uses to play back sound on.
+*/
+
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_Create(FSOUND_DSPCALLBACK callback, int priority, int param);
+DLL_API void F_API FSOUND_DSP_Free(FSOUND_DSPUNIT *unit);
+DLL_API void F_API FSOUND_DSP_SetPriority(FSOUND_DSPUNIT *unit, int priority);
+DLL_API int F_API FSOUND_DSP_GetPriority(FSOUND_DSPUNIT *unit);
+DLL_API void F_API FSOUND_DSP_SetActive(FSOUND_DSPUNIT *unit, signed char active);
+DLL_API signed char F_API FSOUND_DSP_GetActive(FSOUND_DSPUNIT *unit);
+
+/*
+ Functions to get hold of FSOUND 'system DSP unit' handles.
+*/
+
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetClearUnit();
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetSFXUnit();
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetMusicUnit();
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetFFTUnit();
+DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetClipAndCopyUnit();
+
+/*
+ Miscellaneous DSP functions
+ Note for the spectrum analysis function to work, you have to enable the FFT DSP unit with
+ the following code FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);
+ It is off by default to save cpu usage.
+*/
+
+DLL_API signed char F_API FSOUND_DSP_MixBuffers(void *destbuffer, void *srcbuffer, int len, int freq, int vol, int pan, unsigned int mode);
+DLL_API void F_API FSOUND_DSP_ClearMixBuffer();
+DLL_API int F_API FSOUND_DSP_GetBufferLength(); /* Length of each DSP update */
+DLL_API int F_API FSOUND_DSP_GetBufferLengthTotal(); /* Total buffer length due to FSOUND_SetBufferSize */
+DLL_API float * F_API FSOUND_DSP_GetSpectrum(); /* Array of 512 floats - call FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE)) for this to work. */
+
+/* ========================================================================== */
+/* Reverb functions. (eax2/eax3 reverb) (NOT SUPPORTED IN LINUX/CE) */
+/* ========================================================================== */
+
+/*
+ See top of file for definitions and information on the reverb parameters.
+*/
+
+DLL_API signed char F_API FSOUND_Reverb_SetProperties(FSOUND_REVERB_PROPERTIES *prop);
+DLL_API signed char F_API FSOUND_Reverb_GetProperties(FSOUND_REVERB_PROPERTIES *prop);
+DLL_API signed char F_API FSOUND_Reverb_SetChannelProperties(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop);
+DLL_API signed char F_API FSOUND_Reverb_GetChannelProperties(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop);
+
+/* ================================================ */
+/* Recording functions (NOT SUPPORTED IN LINUX/MAC) */
+/* ================================================ */
+
+/*
+ Recording initialization functions
+*/
+
+DLL_API signed char F_API FSOUND_Record_SetDriver(int outputtype);
+DLL_API int F_API FSOUND_Record_GetNumDrivers();
+DLL_API signed char * F_API FSOUND_Record_GetDriverName(int id);
+DLL_API int F_API FSOUND_Record_GetDriver();
+
+/*
+ Recording functionality. Only one recording session will work at a time.
+*/
+
+DLL_API signed char F_API FSOUND_Record_StartSample(FSOUND_SAMPLE *sptr, signed char loop);
+DLL_API signed char F_API FSOUND_Record_Stop();
+DLL_API int F_API FSOUND_Record_GetPosition();
+
+/* ========================================================================================== */
+/* FMUSIC API (MOD,S3M,XM,IT,MIDI PLAYBACK) */
+/* ========================================================================================== */
+
+/*
+ Song management / playback functions.
+*/
+
+DLL_API FMUSIC_MODULE * F_API FMUSIC_LoadSong(const char *name);
+DLL_API FMUSIC_MODULE * F_API FMUSIC_LoadSongMemory(void *data, int length);
+DLL_API signed char F_API FMUSIC_FreeSong(FMUSIC_MODULE *mod);
+DLL_API signed char F_API FMUSIC_PlaySong(FMUSIC_MODULE *mod);
+DLL_API signed char F_API FMUSIC_StopSong(FMUSIC_MODULE *mod);
+DLL_API void F_API FMUSIC_StopAllSongs();
+
+DLL_API signed char F_API FMUSIC_SetZxxCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback);
+DLL_API signed char F_API FMUSIC_SetRowCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int rowstep);
+DLL_API signed char F_API FMUSIC_SetOrderCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int orderstep);
+DLL_API signed char F_API FMUSIC_SetInstCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int instrument);
+
+DLL_API signed char F_API FMUSIC_SetSample(FMUSIC_MODULE *mod, int sampno, FSOUND_SAMPLE *sptr);
+DLL_API signed char F_API FMUSIC_OptimizeChannels(FMUSIC_MODULE *mod, int maxchannels, int minvolume);
+
+/*
+ Runtime song functions.
+*/
+
+DLL_API signed char F_API FMUSIC_SetReverb(signed char reverb); /* MIDI only */
+DLL_API signed char F_API FMUSIC_SetLooping(FMUSIC_MODULE *mod, signed char looping);
+DLL_API signed char F_API FMUSIC_SetOrder(FMUSIC_MODULE *mod, int order);
+DLL_API signed char F_API FMUSIC_SetPaused(FMUSIC_MODULE *mod, signed char pause);
+DLL_API signed char F_API FMUSIC_SetMasterVolume(FMUSIC_MODULE *mod, int volume);
+DLL_API signed char F_API FMUSIC_SetMasterSpeed(FMUSIC_MODULE *mode, float speed);
+DLL_API signed char F_API FMUSIC_SetPanSeperation(FMUSIC_MODULE *mod, float pansep);
+
+/*
+ Static song information functions.
+*/
+
+DLL_API char * F_API FMUSIC_GetName(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetType(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetNumOrders(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetNumPatterns(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetNumInstruments(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetNumSamples(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetNumChannels(FMUSIC_MODULE *mod);
+DLL_API FSOUND_SAMPLE * F_API FMUSIC_GetSample(FMUSIC_MODULE *mod, int sampno);
+DLL_API int F_API FMUSIC_GetPatternLength(FMUSIC_MODULE *mod, int orderno);
+
+/*
+ Runtime song information.
+*/
+
+DLL_API signed char F_API FMUSIC_IsFinished(FMUSIC_MODULE *mod);
+DLL_API signed char F_API FMUSIC_IsPlaying(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetMasterVolume(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetGlobalVolume(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetOrder(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetPattern(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetSpeed(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetBPM(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetRow(FMUSIC_MODULE *mod);
+DLL_API signed char F_API FMUSIC_GetPaused(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetTime(FMUSIC_MODULE *mod);
+DLL_API int F_API FMUSIC_GetRealChannel(FMUSIC_MODULE *mod, int modchannel);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/osframework/source/SexyAppFramework/memmgr.h b/osframework/source/SexyAppFramework/memmgr.h
new file mode 100644
index 0000000..9f3ea56
--- /dev/null
+++ b/osframework/source/SexyAppFramework/memmgr.h
@@ -0,0 +1,96 @@
+#ifndef __SEXYMEMMGR_H__
+#define __SEXYMEMMGR_H__
+
+//////////////////////////////////////////////////////////////////////////
+// HOW TO USE THIS FILE
+//
+// In the desired .CPP file (NOT header file), AFTER ALL of your
+// #include declarations, do a #include "memmgr.h" or whatever you renamed
+// this file to. It's very important that you do it only in the .cpp and
+// after every other include file, otherwise it won't compile. The memory leaks
+// will appear in a file called mem_leaks.txt and they will also be printed out
+// in the output window when the program exits.
+//
+//////////////////////////////////////////////////////////////////////////
+
+
+#include <list>
+#include <stdio.h>
+#include <stdlib.h>
+
+extern void SexyDumpUnfreed();
+
+#if defined(SEXY_MEMTRACE) && !defined(RELEASEFINAL)
+
+/************************************************************************/
+/* DO NOT CALL THESE TWO METHODS DIRECTLY */
+/************************************************************************/
+void SexyMemAddTrack(void* addr, int asize, const char *fname, int lnum);
+void SexyMemRemoveTrack(void *addr);
+
+
+//Replacement for the standard "new" operator, records size of allocation and
+//the file/line number it was on
+inline void* __cdecl operator new(unsigned int size, const char* file, int line)
+{
+ void* ptr = (void*)malloc(size);
+ SexyMemAddTrack(ptr, size, file, line);
+ return(ptr);
+}
+
+//Same as above, but for arrays
+inline void* __cdecl operator new[](unsigned int size, const char* file, int line)
+{
+ void* ptr = (void*)malloc(size);
+ SexyMemAddTrack(ptr, size, file, line);
+ return(ptr);
+}
+
+
+// These single argument new operators allow vc6 apps to compile without errors
+inline void* __cdecl operator new(unsigned int size)
+{
+ void* ptr = (void*)malloc(size);
+ return(ptr);
+}
+
+inline void* __cdecl operator new[](unsigned int size)
+{
+ void* ptr = (void*)malloc(size);
+ return(ptr);
+}
+
+
+//custom delete operators
+inline void __cdecl operator delete(void* p)
+{
+ SexyMemRemoveTrack(p);
+ free(p);
+}
+
+inline void __cdecl operator delete[](void* p)
+{
+ SexyMemRemoveTrack(p);
+ free(p);
+}
+
+//needed in case in the constructor of the class we're newing, it throws an exception
+inline void __cdecl operator delete(void* pMem, const char *file, int line)
+{
+ free(pMem);
+}
+
+inline void __cdecl operator delete[](void* pMem, const char *file, int line)
+{
+ free(pMem);
+}
+
+
+#define DEBUG_NEW new(__FILE__, __LINE__)
+#define new DEBUG_NEW
+
+
+#endif // SEXY_MEMTRACE
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/SexyAppFramework/ogg/COPYING b/osframework/source/SexyAppFramework/ogg/COPYING
new file mode 100644
index 0000000..78291a4
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/COPYING
@@ -0,0 +1,28 @@
+Copyright (c) 2002, Xiph.org Foundation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- Neither the name of the Xiph.org Foundation nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/osframework/source/SexyAppFramework/ogg/asm_arm.h b/osframework/source/SexyAppFramework/ogg/asm_arm.h
new file mode 100644
index 0000000..484dc43
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/asm_arm.h
@@ -0,0 +1,243 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: arm7 and later wide math functions
+
+ ********************************************************************/
+
+#ifdef _ARM_ASSEM_
+
+#if !defined(_V_WIDE_MATH) && !defined(_LOW_ACCURACY_)
+#define _V_WIDE_MATH
+
+STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
+ int lo,hi;
+ asm volatile("smull\t%0, %1, %2, %3"
+ : "=&r"(lo),"=&r"(hi)
+ : "%r"(x),"r"(y)
+ : "cc");
+ return(hi);
+}
+
+STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
+ return MULT32(x,y)<<1;
+}
+
+STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
+ int lo,hi;
+ asm volatile("smull %0, %1, %2, %3\n\t"
+ "movs %0, %0, lsr #15\n\t"
+ "adc %1, %0, %1, lsl #17\n\t"
+ : "=&r"(lo),"=&r"(hi)
+ : "%r"(x),"r"(y)
+ : "cc");
+ return(hi);
+}
+
+#define MB() asm volatile ("" : : : "memory")
+
+STIN void XPROD32(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "smull %0, %1, %4, %6\n\t"
+ "smlal %0, %1, %5, %7\n\t"
+ "rsb %3, %4, #0\n\t"
+ "smull %0, %2, %5, %6\n\t"
+ "smlal %0, %2, %3, %7"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
+ : "3" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1;
+ MB();
+ *y = y1;
+}
+
+STIN void XPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "smull %0, %1, %4, %6\n\t"
+ "smlal %0, %1, %5, %7\n\t"
+ "rsb %3, %4, #0\n\t"
+ "smull %0, %2, %5, %6\n\t"
+ "smlal %0, %2, %3, %7"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
+ : "3" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1 << 1;
+ MB();
+ *y = y1 << 1;
+}
+
+STIN void XNPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ int x1, y1, l;
+ asm( "rsb %2, %4, #0\n\t"
+ "smull %0, %1, %3, %5\n\t"
+ "smlal %0, %1, %2, %6\n\t"
+ "smull %0, %2, %4, %5\n\t"
+ "smlal %0, %2, %3, %6"
+ : "=&r" (l), "=&r" (x1), "=&r" (y1)
+ : "r" (a), "r" (b), "r" (t), "r" (v)
+ : "cc" );
+ *x = x1 << 1;
+ MB();
+ *y = y1 << 1;
+}
+
+#endif
+
+#ifndef _V_CLIP_MATH
+#define _V_CLIP_MATH
+
+STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
+ int tmp;
+ asm volatile("subs %1, %0, #32768\n\t"
+ "movpl %0, #0x7f00\n\t"
+ "orrpl %0, %0, #0xff\n"
+ "adds %1, %0, #32768\n\t"
+ "movmi %0, #0x8000"
+ : "+r"(x),"=r"(tmp)
+ :
+ : "cc");
+ return(x);
+}
+
+#endif
+
+#ifndef _V_LSP_MATH_ASM
+#define _V_LSP_MATH_ASM
+
+STIN void lsp_loop_asm(ogg_uint32_t *qip,ogg_uint32_t *pip,
+ ogg_int32_t *qexpp,
+ ogg_int32_t *ilsp,ogg_int32_t wi,
+ ogg_int32_t m){
+
+ ogg_uint32_t qi=*qip,pi=*pip;
+ ogg_int32_t qexp=*qexpp;
+
+ asm("mov r0,%3;"
+ "mov r1,%5,asr#1;"
+ "add r0,r0,r1,lsl#3;"
+ "1:"
+
+ "ldmdb r0!,{r1,r3};"
+ "subs r1,r1,%4;" //ilsp[j]-wi
+ "rsbmi r1,r1,#0;" //labs(ilsp[j]-wi)
+ "umull %0,r2,r1,%0;" //qi*=labs(ilsp[j]-wi)
+
+ "subs r1,r3,%4;" //ilsp[j+1]-wi
+ "rsbmi r1,r1,#0;" //labs(ilsp[j+1]-wi)
+ "umull %1,r3,r1,%1;" //pi*=labs(ilsp[j+1]-wi)
+
+ "cmn r2,r3;" // shift down 16?
+ "beq 0f;"
+ "add %2,%2,#16;"
+ "mov %0,%0,lsr #16;"
+ "orr %0,%0,r2,lsl #16;"
+ "mov %1,%1,lsr #16;"
+ "orr %1,%1,r3,lsl #16;"
+ "0:"
+ "cmp r0,%3;\n"
+ "bhi 1b;\n"
+
+ // odd filter assymetry
+ "ands r0,%5,#1;\n"
+ "beq 2f;\n"
+ "add r0,%3,%5,lsl#2;\n"
+
+ "ldr r1,[r0,#-4];\n"
+ "mov r0,#0x4000;\n"
+
+ "subs r1,r1,%4;\n" //ilsp[j]-wi
+ "rsbmi r1,r1,#0;\n" //labs(ilsp[j]-wi)
+ "umull %0,r2,r1,%0;\n" //qi*=labs(ilsp[j]-wi)
+ "umull %1,r3,r0,%1;\n" //pi*=labs(ilsp[j+1]-wi)
+
+ "cmn r2,r3;\n" // shift down 16?
+ "beq 2f;\n"
+ "add %2,%2,#16;\n"
+ "mov %0,%0,lsr #16;\n"
+ "orr %0,%0,r2,lsl #16;\n"
+ "mov %1,%1,lsr #16;\n"
+ "orr %1,%1,r3,lsl #16;\n"
+
+ //qi=(pi>>shift)*labs(ilsp[j]-wi);
+ //pi=(qi>>shift)*labs(ilsp[j+1]-wi);
+ //qexp+=shift;
+
+ //}
+
+ /* normalize to max 16 sig figs */
+ "2:"
+ "mov r2,#0;"
+ "orr r1,%0,%1;"
+ "tst r1,#0xff000000;"
+ "addne r2,r2,#8;"
+ "movne r1,r1,lsr #8;"
+ "tst r1,#0x00f00000;"
+ "addne r2,r2,#4;"
+ "movne r1,r1,lsr #4;"
+ "tst r1,#0x000c0000;"
+ "addne r2,r2,#2;"
+ "movne r1,r1,lsr #2;"
+ "tst r1,#0x00020000;"
+ "addne r2,r2,#1;"
+ "movne r1,r1,lsr #1;"
+ "tst r1,#0x00010000;"
+ "addne r2,r2,#1;"
+ "mov %0,%0,lsr r2;"
+ "mov %1,%1,lsr r2;"
+ "add %2,%2,r2;"
+
+ : "+r"(qi),"+r"(pi),"+r"(qexp)
+ : "r"(ilsp),"r"(wi),"r"(m)
+ : "r0","r1","r2","r3","cc");
+
+ *qip=qi;
+ *pip=pi;
+ *qexpp=qexp;
+}
+
+STIN void lsp_norm_asm(ogg_uint32_t *qip,ogg_int32_t *qexpp){
+
+ ogg_uint32_t qi=*qip;
+ ogg_int32_t qexp=*qexpp;
+
+ asm("tst %0,#0x0000ff00;"
+ "moveq %0,%0,lsl #8;"
+ "subeq %1,%1,#8;"
+ "tst %0,#0x0000f000;"
+ "moveq %0,%0,lsl #4;"
+ "subeq %1,%1,#4;"
+ "tst %0,#0x0000c000;"
+ "moveq %0,%0,lsl #2;"
+ "subeq %1,%1,#2;"
+ "tst %0,#0x00008000;"
+ "moveq %0,%0,lsl #1;"
+ "subeq %1,%1,#1;"
+ : "+r"(qi),"+r"(qexp)
+ :
+ : "cc");
+ *qip=qi;
+ *qexpp=qexp;
+}
+
+#endif
+#endif
+
diff --git a/osframework/source/SexyAppFramework/ogg/backends.h b/osframework/source/SexyAppFramework/ogg/backends.h
new file mode 100644
index 0000000..b6bad2f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/backends.h
@@ -0,0 +1,136 @@
+
+
+
+
+
+
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: backend and mapping structures
+
+ ********************************************************************/
+
+/* this is exposed up here because we need it for static modes.
+ Lookups for each backend aren't exposed because there's no reason
+ to do so */
+
+#ifndef _vorbis_backend_h_
+#define _vorbis_backend_h_
+
+#include "codec_internal.h"
+
+/* this would all be simpler/shorter with templates, but.... */
+/* Transform backend generic *************************************/
+
+/* only mdct right now. Flesh it out more if we ever transcend mdct
+ in the transform domain */
+
+/* Floor backend generic *****************************************/
+typedef struct{
+ vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_floor *);
+ void (*free_info) (vorbis_info_floor *);
+ void (*free_look) (vorbis_look_floor *);
+ void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
+ int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
+ void *buffer,ogg_int32_t *);
+} vorbis_func_floor;
+
+typedef struct{
+ int order;
+ long rate;
+ long barkmap;
+
+ int ampbits;
+ int ampdB;
+
+ int numbooks; /* <= 16 */
+ int books[16];
+
+} vorbis_info_floor0;
+
+#define VIF_POSIT 63
+#define VIF_CLASS 16
+#define VIF_PARTS 31
+typedef struct{
+ int partitions; /* 0 to 31 */
+ int partitionclass[VIF_PARTS]; /* 0 to 15 */
+
+ int class_dim[VIF_CLASS]; /* 1 to 8 */
+ int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
+ int class_book[VIF_CLASS]; /* subs ^ dim entries */
+ int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
+
+
+ int mult; /* 1 2 3 or 4 */
+ int postlist[VIF_POSIT+2]; /* first two implicit */
+
+} vorbis_info_floor1;
+
+/* Residue backend generic *****************************************/
+typedef struct{
+ vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_residue *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_residue *);
+ void (*free_info) (vorbis_info_residue *);
+ void (*free_look) (vorbis_look_residue *);
+ int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
+ ogg_int32_t **,int *,int);
+} vorbis_func_residue;
+
+typedef struct vorbis_info_residue0{
+/* block-partitioned VQ coded straight residue */
+ long begin;
+ long end;
+
+ /* first stage (lossless partitioning) */
+ int grouping; /* group n vectors per partition */
+ int partitions; /* possible codebooks for a partition */
+ int groupbook; /* huffbook for partitioning */
+ int secondstages[64]; /* expanded out to pointers in lookup */
+ int booklist[256]; /* list of second stage books */
+} vorbis_info_residue0;
+
+/* Mapping backend generic *****************************************/
+typedef struct{
+ vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
+ vorbis_look_mapping *(*look) (vorbis_dsp_state *,vorbis_info_mode *,
+ vorbis_info_mapping *);
+ void (*free_info) (vorbis_info_mapping *);
+ void (*free_look) (vorbis_look_mapping *);
+ int (*inverse) (struct vorbis_block *vb,vorbis_look_mapping *);
+} vorbis_func_mapping;
+
+typedef struct vorbis_info_mapping0{
+ int submaps; /* <= 16 */
+ int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
+
+ int floorsubmap[16]; /* [mux] submap to floors */
+ int residuesubmap[16]; /* [mux] submap to residue */
+
+ int psy[2]; /* by blocktype; impulse/padding for short,
+ transition/normal for long */
+
+ int coupling_steps;
+ int coupling_mag[256];
+ int coupling_ang[256];
+} vorbis_info_mapping0;
+
+#endif
+
+
+
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/bitwise.c b/osframework/source/SexyAppFramework/ogg/bitwise.c
new file mode 100644
index 0000000..de3c34a
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/bitwise.c
@@ -0,0 +1,266 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: packing variable sized words into an octet stream
+
+ ********************************************************************/
+
+/* We're 'LSb' endian; if we write a word but read individual bits,
+ then we'll read the lsb first */
+
+#include <string.h>
+#include <stdlib.h>
+#include "os.h"
+#include "ogg.h"
+
+static unsigned long mask[]=
+{0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
+ 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
+ 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
+ 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
+ 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
+ 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
+ 0x3fffffff,0x7fffffff,0xffffffff };
+
+/* mark read process as having run off the end */
+static void _adv_halt(oggpack_buffer *b){
+ b->headptr=b->head->buffer->data+b->head->begin+b->head->length;
+ b->headend=-1;
+ b->headbit=0;
+}
+
+/* spans forward, skipping as many bytes as headend is negative; if
+ headend is zero, simply finds next byte. If we're up to the end
+ of the buffer, leaves headend at zero. If we've read past the end,
+ halt the decode process. */
+static void _span(oggpack_buffer *b){
+ while(b->headend<1){
+ if(b->head->next){
+ b->count+=b->head->length;
+ b->head=b->head->next;
+ b->headptr=b->head->buffer->data+b->head->begin-b->headend;
+ b->headend+=b->head->length;
+ }else{
+ /* we've either met the end of decode, or gone past it. halt
+ only if we're past */
+ if(b->headend<0 || b->headbit)
+ /* read has fallen off the end */
+ _adv_halt(b);
+
+ break;
+ }
+ }
+}
+
+void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){
+ memset(b,0,sizeof(*b));
+
+ b->tail=b->head=r;
+ b->count=0;
+ b->headptr=b->head->buffer->data+b->head->begin;
+ b->headend=b->head->length;
+ _span(b);
+}
+
+#define _lookspan() while(!end){\
+ head=head->next;\
+ if(!head) return -1;\
+ ptr=head->buffer->data + head->begin;\
+ end=head->length;\
+ }
+
+/* Read in bits without advancing the bitptr; bits <= 32 */
+long oggpack_look(oggpack_buffer *b,int bits){
+ unsigned long m=mask[bits];
+ unsigned long ret;
+
+ bits+=b->headbit;
+
+ if(bits >= b->headend<<3){
+ int end=b->headend;
+ unsigned char *ptr=b->headptr;
+ ogg_reference *head=b->head;
+
+ if(end<0)return -1;
+
+ if(bits){
+ _lookspan();
+ ret=*ptr++>>b->headbit;
+ if(bits>8){
+ --end;
+ _lookspan();
+ ret|=*ptr++<<(8-b->headbit);
+ if(bits>16){
+ --end;
+ _lookspan();
+ ret|=*ptr++<<(16-b->headbit);
+ if(bits>24){
+ --end;
+ _lookspan();
+ ret|=*ptr++<<(24-b->headbit);
+ if(bits>32 && b->headbit){
+ --end;
+ _lookspan();
+ ret|=*ptr<<(32-b->headbit);
+ }
+ }
+ }
+ }
+ }
+
+ }else{
+
+ /* make this a switch jump-table */
+ ret=b->headptr[0]>>b->headbit;
+ if(bits>8){
+ ret|=b->headptr[1]<<(8-b->headbit);
+ if(bits>16){
+ ret|=b->headptr[2]<<(16-b->headbit);
+ if(bits>24){
+ ret|=b->headptr[3]<<(24-b->headbit);
+ if(bits>32 && b->headbit)
+ ret|=b->headptr[4]<<(32-b->headbit);
+ }
+ }
+ }
+ }
+
+ ret&=m;
+ return ret;
+}
+
+/* limited to 32 at a time */
+void oggpack_adv(oggpack_buffer *b,int bits){
+ bits+=b->headbit;
+ b->headbit=bits&7;
+ b->headptr+=bits/8;
+ if((b->headend-=bits/8)<1)_span(b);
+}
+
+/* spans forward and finds next byte. Never halts */
+static void _span_one(oggpack_buffer *b){
+ while(b->headend<1){
+ if(b->head->next){
+ b->count+=b->head->length;
+ b->head=b->head->next;
+ b->headptr=b->head->buffer->data+b->head->begin;
+ b->headend=b->head->length;
+ }else
+ break;
+ }
+}
+
+static int _halt_one(oggpack_buffer *b){
+ if(b->headend<1){
+ _adv_halt(b);
+ return -1;
+ }
+ return 0;
+}
+
+int oggpack_eop(oggpack_buffer *b){
+ if(b->headend<0)return -1;
+ return 0;
+}
+
+/* bits <= 32 */
+long oggpack_read(oggpack_buffer *b,int bits){
+ unsigned long m=mask[bits];
+ ogg_uint32_t ret;
+
+ bits+=b->headbit;
+
+ if(bits >= b->headend<<3){
+
+ if(b->headend<0)return -1;
+
+ if(bits){
+ if (_halt_one(b)) return -1;
+ ret=*b->headptr>>b->headbit;
+
+ if(bits>=8){
+ ++b->headptr;
+ --b->headend;
+ _span_one(b);
+ if(bits>8){
+ if (_halt_one(b)) return -1;
+ ret|=*b->headptr<<(8-b->headbit);
+
+ if(bits>=16){
+ ++b->headptr;
+ --b->headend;
+ _span_one(b);
+ if(bits>16){
+ if (_halt_one(b)) return -1;
+ ret|=*b->headptr<<(16-b->headbit);
+
+ if(bits>=24){
+ ++b->headptr;
+ --b->headend;
+ _span_one(b);
+ if(bits>24){
+ if (_halt_one(b)) return -1;
+ ret|=*b->headptr<<(24-b->headbit);
+
+ if(bits>=32){
+ ++b->headptr;
+ --b->headend;
+ _span_one(b);
+ if(bits>32){
+ if (_halt_one(b)) return -1;
+ if(b->headbit)ret|=*b->headptr<<(32-b->headbit);
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }else{
+
+ ret=b->headptr[0]>>b->headbit;
+ if(bits>8){
+ ret|=b->headptr[1]<<(8-b->headbit);
+ if(bits>16){
+ ret|=b->headptr[2]<<(16-b->headbit);
+ if(bits>24){
+ ret|=b->headptr[3]<<(24-b->headbit);
+ if(bits>32 && b->headbit){
+ ret|=b->headptr[4]<<(32-b->headbit);
+ }
+ }
+ }
+ }
+
+ b->headptr+=bits/8;
+ b->headend-=bits/8;
+ }
+
+ ret&=m;
+ b->headbit=bits&7;
+ return ret;
+}
+
+long oggpack_bytes(oggpack_buffer *b){
+ return(b->count+b->headptr-b->head->buffer->data-b->head->begin+
+ (b->headbit+7)/8);
+}
+
+long oggpack_bits(oggpack_buffer *b){
+ return((b->count+b->headptr-b->head->buffer->data-b->head->begin)*8+
+ b->headbit);
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/block.c b/osframework/source/SexyAppFramework/ogg/block.c
new file mode 100644
index 0000000..ec71a2c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/block.c
@@ -0,0 +1,453 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: PCM data vector blocking, windowing and dis/reassembly
+
+ ********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+
+#include "window.h"
+#include "registry.h"
+#include "misc.h"
+
+static int ilog(unsigned int v){
+ int ret=0;
+ if(v)--v;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+/* pcm accumulator examples (not exhaustive):
+
+ <-------------- lW ---------------->
+ <--------------- W ---------------->
+: .....|..... _______________ |
+: .''' | '''_--- | |\ |
+:.....''' |_____--- '''......| | \_______|
+:.................|__________________|_______|__|______|
+ |<------ Sl ------>| > Sr < |endW
+ |beginSl |endSl | |endSr
+ |beginW |endlW |beginSr
+
+
+ |< lW >|
+ <--------------- W ---------------->
+ | | .. ______________ |
+ | | ' `/ | ---_ |
+ |___.'___/`. | ---_____|
+ |_______|__|_______|_________________|
+ | >|Sl|< |<------ Sr ----->|endW
+ | | |endSl |beginSr |endSr
+ |beginW | |endlW
+ mult[0] |beginSl mult[n]
+
+ <-------------- lW ----------------->
+ |<--W-->|
+: .............. ___ | |
+: .''' |`/ \ | |
+:.....''' |/`....\|...|
+:.........................|___|___|___|
+ |Sl |Sr |endW
+ | | |endSr
+ | |beginSr
+ | |endSl
+ |beginSl
+ |beginW
+*/
+
+/* block abstraction setup *********************************************/
+
+#ifndef WORD_ALIGN
+#define WORD_ALIGN 8
+#endif
+
+int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
+ memset(vb,0,sizeof(*vb));
+ vb->vd=v;
+ vb->localalloc=0;
+ vb->localstore=NULL;
+
+ return(0);
+}
+
+void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
+ bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
+ if(bytes+vb->localtop>vb->localalloc){
+ /* can't just _ogg_realloc... there are outstanding pointers */
+ if(vb->localstore){
+ struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
+ vb->totaluse+=vb->localtop;
+ link->next=vb->reap;
+ link->ptr=vb->localstore;
+ vb->reap=link;
+ }
+ /* highly conservative */
+ vb->localalloc=bytes;
+ vb->localstore=_ogg_malloc(vb->localalloc);
+ vb->localtop=0;
+ }
+ {
+ void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
+ vb->localtop+=bytes;
+ return ret;
+ }
+}
+
+/* reap the chain, pull the ripcord */
+void _vorbis_block_ripcord(vorbis_block *vb){
+ /* reap the chain */
+ struct alloc_chain *reap=vb->reap;
+ while(reap){
+ struct alloc_chain *next=reap->next;
+ _ogg_free(reap->ptr);
+ memset(reap,0,sizeof(*reap));
+ _ogg_free(reap);
+ reap=next;
+ }
+ /* consolidate storage */
+ if(vb->totaluse){
+ vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
+ vb->localalloc+=vb->totaluse;
+ vb->totaluse=0;
+ }
+
+ /* pull the ripcord */
+ vb->localtop=0;
+ vb->reap=NULL;
+}
+
+int vorbis_block_clear(vorbis_block *vb){
+ _vorbis_block_ripcord(vb);
+ if(vb->localstore)_ogg_free(vb->localstore);
+
+ memset(vb,0,sizeof(*vb));
+ return(0);
+}
+
+static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
+ int i;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ private_state *b=NULL;
+
+ memset(v,0,sizeof(*v));
+ b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
+
+ v->vi=vi;
+ b->modebits=ilog(ci->modes);
+
+ /* Vorbis I uses only window type 0 */
+ b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
+ b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
+
+ /* finish the codebooks */
+ if(!ci->fullbooks){
+ ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
+ for(i=0;i<ci->books;i++){
+ vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
+ /* decode codebooks are now standalone after init */
+ vorbis_staticbook_destroy(ci->book_param[i]);
+ ci->book_param[i]=NULL;
+ }
+ }
+
+ v->pcm_storage=ci->blocksizes[1];
+ v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm));
+ v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
+ for(i=0;i<vi->channels;i++)
+ v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
+
+ /* all 1 (large block) or 0 (small block) */
+ /* explicitly set for the sake of clarity */
+ v->lW=0; /* previous window size */
+ v->W=0; /* current window size */
+
+ /* initialize all the mapping/backend lookups */
+ b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
+ for(i=0;i<ci->modes;i++){
+ int mapnum=ci->mode_param[i]->mapping;
+ int maptype=ci->map_type[mapnum];
+ b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
+ ci->map_param[mapnum]);
+ }
+ return(0);
+}
+
+int vorbis_synthesis_restart(vorbis_dsp_state *v){
+ vorbis_info *vi=v->vi;
+ codec_setup_info *ci;
+
+ if(!v->backend_state)return -1;
+ if(!vi)return -1;
+ ci=vi->codec_setup;
+ if(!ci)return -1;
+
+ v->centerW=ci->blocksizes[1]/2;
+ v->pcm_current=v->centerW;
+
+ v->pcm_returned=-1;
+ v->granulepos=-1;
+ v->sequence=-1;
+ ((private_state *)(v->backend_state))->sample_count=-1;
+
+ return(0);
+}
+
+int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
+ _vds_init(v,vi);
+ vorbis_synthesis_restart(v);
+
+ return(0);
+}
+
+void vorbis_dsp_clear(vorbis_dsp_state *v){
+ int i;
+ if(v){
+ vorbis_info *vi=v->vi;
+ codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
+ private_state *b=(private_state *)v->backend_state;
+
+ if(v->pcm){
+ for(i=0;i<vi->channels;i++)
+ if(v->pcm[i])_ogg_free(v->pcm[i]);
+ _ogg_free(v->pcm);
+ if(v->pcmret)_ogg_free(v->pcmret);
+ }
+
+ /* free mode lookups; these are actually vorbis_look_mapping structs */
+ if(ci){
+ for(i=0;i<ci->modes;i++){
+ int mapnum=ci->mode_param[i]->mapping;
+ int maptype=ci->map_type[mapnum];
+ if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
+ }
+ }
+
+ if(b){
+ if(b->mode)_ogg_free(b->mode);
+ _ogg_free(b);
+ }
+
+ memset(v,0,sizeof(*v));
+ }
+}
+
+/* Unlike in analysis, the window is only partially applied for each
+ block. The time domain envelope is not yet handled at the point of
+ calling (as it relies on the previous block). */
+
+int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
+ vorbis_info *vi=v->vi;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ private_state *b=v->backend_state;
+ int i,j;
+
+ if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
+
+ v->lW=v->W;
+ v->W=vb->W;
+ v->nW=-1;
+
+ if((v->sequence==-1)||
+ (v->sequence+1 != vb->sequence)){
+ v->granulepos=-1; /* out of sequence; lose count */
+ b->sample_count=-1;
+ }
+
+ v->sequence=vb->sequence;
+
+ if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
+ was called on block */
+ int n=ci->blocksizes[v->W]/2;
+ int n0=ci->blocksizes[0]/2;
+ int n1=ci->blocksizes[1]/2;
+
+ int thisCenter;
+ int prevCenter;
+
+ if(v->centerW){
+ thisCenter=n1;
+ prevCenter=0;
+ }else{
+ thisCenter=0;
+ prevCenter=n1;
+ }
+
+ /* v->pcm is now used like a two-stage double buffer. We don't want
+ to have to constantly shift *or* adjust memory usage. Don't
+ accept a new block until the old is shifted out */
+
+ /* overlap/add PCM */
+
+ for(j=0;j<vi->channels;j++){
+ /* the overlap/add section */
+ if(v->lW){
+ if(v->W){
+ /* large/large */
+ ogg_int32_t *pcm=v->pcm[j]+prevCenter;
+ ogg_int32_t *p=vb->pcm[j];
+ for(i=0;i<n1;i++)
+ pcm[i]+=p[i];
+ }else{
+ /* large/small */
+ ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
+ ogg_int32_t *p=vb->pcm[j];
+ for(i=0;i<n0;i++)
+ pcm[i]+=p[i];
+ }
+ }else{
+ if(v->W){
+ /* small/large */
+ ogg_int32_t *pcm=v->pcm[j]+prevCenter;
+ ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2;
+ for(i=0;i<n0;i++)
+ pcm[i]+=p[i];
+ for(;i<n1/2+n0/2;i++)
+ pcm[i]=p[i];
+ }else{
+ /* small/small */
+ ogg_int32_t *pcm=v->pcm[j]+prevCenter;
+ ogg_int32_t *p=vb->pcm[j];
+ for(i=0;i<n0;i++)
+ pcm[i]+=p[i];
+ }
+ }
+
+ /* the copy section */
+ {
+ ogg_int32_t *pcm=v->pcm[j]+thisCenter;
+ ogg_int32_t *p=vb->pcm[j]+n;
+ for(i=0;i<n;i++)
+ pcm[i]=p[i];
+ }
+ }
+
+ if(v->centerW)
+ v->centerW=0;
+ else
+ v->centerW=n1;
+
+ /* deal with initial packet state; we do this using the explicit
+ pcm_returned==-1 flag otherwise we're sensitive to first block
+ being short or long */
+
+ if(v->pcm_returned==-1){
+ v->pcm_returned=thisCenter;
+ v->pcm_current=thisCenter;
+ }else{
+ v->pcm_returned=prevCenter;
+ v->pcm_current=prevCenter+
+ ci->blocksizes[v->lW]/4+
+ ci->blocksizes[v->W]/4;
+ }
+
+ }
+
+ /* track the frame number... This is for convenience, but also
+ making sure our last packet doesn't end with added padding. If
+ the last packet is partial, the number of samples we'll have to
+ return will be past the vb->granulepos.
+
+ This is not foolproof! It will be confused if we begin
+ decoding at the last page after a seek or hole. In that case,
+ we don't have a starting point to judge where the last frame
+ is. For this reason, vorbisfile will always try to make sure
+ it reads the last two marked pages in proper sequence */
+
+ if(b->sample_count==-1){
+ b->sample_count=0;
+ }else{
+ b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
+ }
+
+ if(v->granulepos==-1){
+ if(vb->granulepos!=-1){ /* only set if we have a position to set to */
+
+ v->granulepos=vb->granulepos;
+
+ /* is this a short page? */
+ if(b->sample_count>v->granulepos){
+ /* corner case; if this is both the first and last audio page,
+ then spec says the end is cut, not beginning */
+ if(vb->eofflag){
+ /* trim the end */
+ /* no preceeding granulepos; assume we started at zero (we'd
+ have to in a short single-page stream) */
+ /* granulepos could be -1 due to a seek, but that would result
+ in a long coun`t, not short count */
+
+ v->pcm_current-=(b->sample_count-v->granulepos);
+ }else{
+ /* trim the beginning */
+ v->pcm_returned+=(b->sample_count-v->granulepos);
+ if(v->pcm_returned>v->pcm_current)
+ v->pcm_returned=v->pcm_current;
+ }
+
+ }
+
+ }
+ }else{
+ v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
+ if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
+
+ if(v->granulepos>vb->granulepos){
+ long extra=v->granulepos-vb->granulepos;
+
+ if(extra)
+ if(vb->eofflag){
+ /* partial last frame. Strip the extra samples off */
+ v->pcm_current-=extra;
+ } /* else {Shouldn't happen *unless* the bitstream is out of
+ spec. Either way, believe the bitstream } */
+ } /* else {Shouldn't happen *unless* the bitstream is out of
+ spec. Either way, believe the bitstream } */
+ v->granulepos=vb->granulepos;
+ }
+ }
+
+ /* Update, cleanup */
+
+ if(vb->eofflag)v->eofflag=1;
+ return(0);
+}
+
+/* pcm==NULL indicates we just want the pending samples, no more */
+int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){
+ vorbis_info *vi=v->vi;
+ if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
+ if(pcm){
+ int i;
+ for(i=0;i<vi->channels;i++)
+ v->pcmret[i]=v->pcm[i]+v->pcm_returned;
+ *pcm=v->pcmret;
+ }
+ return(v->pcm_current-v->pcm_returned);
+ }
+ return(0);
+}
+
+int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){
+ if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL);
+ v->pcm_returned+=bytes;
+ return(0);
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/codebook.c b/osframework/source/SexyAppFramework/ogg/codebook.c
new file mode 100644
index 0000000..7a07bc4
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/codebook.c
@@ -0,0 +1,350 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: basic codebook pack/unpack/code/decode operations
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codebook.h"
+#include "misc.h"
+#include "os.h"
+
+/* unpacks a codebook from the packet buffer into the codebook struct,
+ readies the codebook auxiliary structures for decode *************/
+int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
+ long i,j;
+ memset(s,0,sizeof(*s));
+
+ /* make sure alignment is correct */
+ if(oggpack_read(opb,24)!=0x564342)goto _eofout;
+
+ /* first the basic parameters */
+ s->dim=oggpack_read(opb,16);
+ s->entries=oggpack_read(opb,24);
+ if(s->entries==-1)goto _eofout;
+
+ /* codeword ordering.... length ordered or unordered? */
+ switch((int)oggpack_read(opb,1)){
+ case 0:
+ /* unordered */
+ s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
+
+ /* allocated but unused entries? */
+ if(oggpack_read(opb,1)){
+ /* yes, unused entries */
+
+ for(i=0;i<s->entries;i++){
+ if(oggpack_read(opb,1)){
+ long num=oggpack_read(opb,5);
+ if(num==-1)goto _eofout;
+ s->lengthlist[i]=num+1;
+ }else
+ s->lengthlist[i]=0;
+ }
+ }else{
+ /* all entries used; no tagging */
+ for(i=0;i<s->entries;i++){
+ long num=oggpack_read(opb,5);
+ if(num==-1)goto _eofout;
+ s->lengthlist[i]=num+1;
+ }
+ }
+
+ break;
+ case 1:
+ /* ordered */
+ {
+ long length=oggpack_read(opb,5)+1;
+ s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
+
+ for(i=0;i<s->entries;){
+ long num=oggpack_read(opb,_ilog(s->entries-i));
+ if(num==-1)goto _eofout;
+ for(j=0;j<num && i<s->entries;j++,i++)
+ s->lengthlist[i]=length;
+ length++;
+ }
+ }
+ break;
+ default:
+ /* EOF */
+ return(-1);
+ }
+
+ /* Do we have a mapping to unpack? */
+ switch((s->maptype=oggpack_read(opb,4))){
+ case 0:
+ /* no mapping */
+ break;
+ case 1: case 2:
+ /* implicitly populated value mapping */
+ /* explicitly populated value mapping */
+
+ s->q_min=oggpack_read(opb,32);
+ s->q_delta=oggpack_read(opb,32);
+ s->q_quant=oggpack_read(opb,4)+1;
+ s->q_sequencep=oggpack_read(opb,1);
+
+ {
+ int quantvals=0;
+ switch(s->maptype){
+ case 1:
+ quantvals=_book_maptype1_quantvals(s);
+ break;
+ case 2:
+ quantvals=s->entries*s->dim;
+ break;
+ }
+
+ /* quantized values */
+ s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
+ for(i=0;i<quantvals;i++)
+ s->quantlist[i]=oggpack_read(opb,s->q_quant);
+
+ if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
+ }
+ break;
+ default:
+ goto _errout;
+ }
+
+ /* all set */
+ return(0);
+
+ _errout:
+ _eofout:
+ vorbis_staticbook_clear(s);
+ return(-1);
+}
+
+/* the 'eliminate the decode tree' optimization actually requires the
+ codewords to be MSb first, not LSb. This is an annoying inelegancy
+ (and one of the first places where carefully thought out design
+ turned out to be wrong; Vorbis II and future Ogg codecs should go
+ to an MSb bitpacker), but not actually the huge hit it appears to
+ be. The first-stage decode table catches most words so that
+ bitreverse is not in the main execution path. */
+
+static ogg_uint32_t bitreverse(ogg_uint32_t x){
+ x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000);
+ x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00);
+ x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0);
+ x= ((x>> 2)&0x33333333) | ((x<< 2)&0xcccccccc);
+ return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa);
+}
+
+STIN long decode_packed_entry_number(codebook *book,
+ oggpack_buffer *b){
+ int read=book->dec_maxlength;
+ long lo,hi;
+ long lok = oggpack_look(b,book->dec_firsttablen);
+
+ if (lok >= 0) {
+ long entry = book->dec_firsttable[lok];
+ if(entry&0x80000000UL){
+ lo=(entry>>15)&0x7fff;
+ hi=book->used_entries-(entry&0x7fff);
+ }else{
+ oggpack_adv(b, book->dec_codelengths[entry-1]);
+ return(entry-1);
+ }
+ }else{
+ lo=0;
+ hi=book->used_entries;
+ }
+
+ lok = oggpack_look(b, read);
+
+ while(lok<0 && read>1)
+ lok = oggpack_look(b, --read);
+ if(lok<0)return -1;
+
+ /* bisect search for the codeword in the ordered list */
+ {
+ ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok);
+
+ while(hi-lo>1){
+ long p=(hi-lo)>>1;
+ long test=book->codelist[lo+p]>testword;
+ lo+=p&(test-1);
+ hi-=p&(-test);
+ }
+
+ if(book->dec_codelengths[lo]<=read){
+ oggpack_adv(b, book->dec_codelengths[lo]);
+ return(lo);
+ }
+ }
+
+ oggpack_adv(b, read);
+ return(-1);
+}
+
+/* Decode side is specced and easier, because we don't need to find
+ matches using different criteria; we simply read and map. There are
+ two things we need to do 'depending':
+
+ We may need to support interleave. We don't really, but it's
+ convenient to do it here rather than rebuild the vector later.
+
+ Cascades may be additive or multiplicitive; this is not inherent in
+ the codebook, but set in the code using the codebook. Like
+ interleaving, it's easiest to do it here.
+ addmul==0 -> declarative (set the value)
+ addmul==1 -> additive
+ addmul==2 -> multiplicitive */
+
+/* returns the [original, not compacted] entry number or -1 on eof *********/
+long vorbis_book_decode(codebook *book, oggpack_buffer *b){
+ long packed_entry=decode_packed_entry_number(book,b);
+ if(packed_entry>=0)
+ return(book->dec_index[packed_entry]);
+
+ /* if there's no dec_index, the codebook unpacking isn't collapsed */
+ return(packed_entry);
+}
+
+/* returns 0 on OK or -1 on eof *************************************/
+long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point){
+ int step=n/book->dim;
+ long *entry = (long *)alloca(sizeof(*entry)*step);
+ ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step);
+ int i,j,o;
+ int shift=point-book->binarypoint;
+
+ if(shift>=0){
+ for (i = 0; i < step; i++) {
+ entry[i]=decode_packed_entry_number(book,b);
+ if(entry[i]==-1)return(-1);
+ t[i] = book->valuelist+entry[i]*book->dim;
+ }
+ for(i=0,o=0;i<book->dim;i++,o+=step)
+ for (j=0;j<step;j++)
+ a[o+j]+=t[j][i]>>shift;
+ }else{
+ for (i = 0; i < step; i++) {
+ entry[i]=decode_packed_entry_number(book,b);
+ if(entry[i]==-1)return(-1);
+ t[i] = book->valuelist+entry[i]*book->dim;
+ }
+ for(i=0,o=0;i<book->dim;i++,o+=step)
+ for (j=0;j<step;j++)
+ a[o+j]+=t[j][i]<<-shift;
+ }
+ return(0);
+}
+
+long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point){
+ int i,j,entry;
+ ogg_int32_t *t;
+ int shift=point-book->binarypoint;
+
+ if(shift>=0){
+ for(i=0;i<n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;)
+ a[i++]+=t[j++]>>shift;
+ }
+ }else{
+ for(i=0;i<n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;)
+ a[i++]+=t[j++]<<-shift;
+ }
+ }
+ return(0);
+}
+
+long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point){
+ int i,j,entry;
+ ogg_int32_t *t;
+ int shift=point-book->binarypoint;
+
+ if(shift>=0){
+
+ for(i=0;i<n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;){
+ a[i++]=t[j++]>>shift;
+ }
+ }
+ }else{
+
+ for(i=0;i<n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;){
+ a[i++]=t[j++]<<-shift;
+ }
+ }
+ }
+ return(0);
+}
+
+long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,\
+ long offset,int ch,
+ oggpack_buffer *b,int n,int point){
+ long i,j,entry;
+ int chptr=0;
+ int shift=point-book->binarypoint;
+
+ if(shift>=0){
+
+ for(i=offset;i<offset+n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ {
+ const ogg_int32_t *t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;j++){
+ a[chptr++][i]+=t[j]>>shift;
+ if(chptr==ch){
+ chptr=0;
+ i++;
+ }
+ }
+ }
+ }
+ }else{
+
+ for(i=offset;i<offset+n;){
+ entry = decode_packed_entry_number(book,b);
+ if(entry==-1)return(-1);
+ {
+ const ogg_int32_t *t = book->valuelist+entry*book->dim;
+ for (j=0;j<book->dim;j++){
+ a[chptr++][i]+=t[j]<<-shift;
+ if(chptr==ch){
+ chptr=0;
+ i++;
+ }
+ }
+ }
+ }
+ }
+ return(0);
+}
diff --git a/osframework/source/SexyAppFramework/ogg/codebook.h b/osframework/source/SexyAppFramework/ogg/codebook.h
new file mode 100644
index 0000000..0b24ce9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/codebook.h
@@ -0,0 +1,102 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: basic shared codebook operations
+
+ ********************************************************************/
+
+#ifndef _V_CODEBOOK_H_
+#define _V_CODEBOOK_H_
+
+#include "ogg.h"
+
+/* This structure encapsulates huffman and VQ style encoding books; it
+ doesn't do anything specific to either.
+
+ valuelist/quantlist are nonNULL (and q_* significant) only if
+ there's entry->value mapping to be done.
+
+ If encode-side mapping must be done (and thus the entry needs to be
+ hunted), the auxiliary encode pointer will point to a decision
+ tree. This is true of both VQ and huffman, but is mostly useful
+ with VQ.
+
+*/
+
+typedef struct static_codebook{
+ long dim; /* codebook dimensions (elements per vector) */
+ long entries; /* codebook entries */
+ long *lengthlist; /* codeword lengths in bits */
+
+ /* mapping ***************************************************************/
+ int maptype; /* 0=none
+ 1=implicitly populated values from map column
+ 2=listed arbitrary values */
+
+ /* The below does a linear, single monotonic sequence mapping. */
+ long q_min; /* packed 32 bit float; quant value 0 maps to minval */
+ long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
+ int q_quant; /* bits: 0 < quant <= 16 */
+ int q_sequencep; /* bitflag */
+
+ long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
+ map == 2: list of dim*entries quantized entry vals
+ */
+} static_codebook;
+
+typedef struct codebook{
+ long dim; /* codebook dimensions (elements per vector) */
+ long entries; /* codebook entries */
+ long used_entries; /* populated codebook entries */
+
+ /* the below are ordered by bitreversed codeword and only used
+ entries are populated */
+ int binarypoint;
+ ogg_int32_t *valuelist; /* list of dim*entries actual entry values */
+ ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
+
+ int *dec_index;
+ char *dec_codelengths;
+ ogg_uint32_t *dec_firsttable;
+ int dec_firsttablen;
+ int dec_maxlength;
+
+ long q_min; /* packed 32 bit float; quant value 0 maps to minval */
+ long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
+
+} codebook;
+
+extern void vorbis_staticbook_clear(static_codebook *b);
+extern void vorbis_staticbook_destroy(static_codebook *b);
+extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
+
+extern void vorbis_book_clear(codebook *b);
+extern long _book_maptype1_quantvals(const static_codebook *b);
+
+extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
+
+extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
+extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point);
+extern long vorbis_book_decodev_set(codebook *book, ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point);
+extern long vorbis_book_decodev_add(codebook *book, ogg_int32_t *a,
+ oggpack_buffer *b,int n,int point);
+extern long vorbis_book_decodevv_add(codebook *book, ogg_int32_t **a,
+ long off,int ch,
+ oggpack_buffer *b,int n,int point);
+
+extern int _ilog(unsigned int v);
+
+
+#endif
diff --git a/osframework/source/SexyAppFramework/ogg/codec_internal.h b/osframework/source/SexyAppFramework/ogg/codec_internal.h
new file mode 100644
index 0000000..f5ae67f
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/codec_internal.h
@@ -0,0 +1,92 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: libvorbis codec headers
+
+ ********************************************************************/
+
+#ifndef _V_CODECI_H_
+#define _V_CODECI_H_
+
+#include "codebook.h"
+
+typedef void vorbis_look_mapping;
+typedef void vorbis_look_floor;
+typedef void vorbis_look_residue;
+typedef void vorbis_look_transform;
+
+/* mode ************************************************************/
+typedef struct {
+ int blockflag;
+ int windowtype;
+ int transformtype;
+ int mapping;
+} vorbis_info_mode;
+
+typedef void vorbis_info_floor;
+typedef void vorbis_info_residue;
+typedef void vorbis_info_mapping;
+
+typedef struct private_state {
+ /* local lookup storage */
+ const void *window[2];
+
+ /* backend lookups are tied to the mode, not the backend or naked mapping */
+ int modebits;
+ vorbis_look_mapping **mode;
+
+ ogg_int64_t sample_count;
+
+} private_state;
+
+/* codec_setup_info contains all the setup information specific to the
+ specific compression/decompression mode in progress (eg,
+ psychoacoustic settings, channel setup, options, codebook
+ etc).
+*********************************************************************/
+
+typedef struct codec_setup_info {
+
+ /* Vorbis supports only short and long blocks, but allows the
+ encoder to choose the sizes */
+
+ long blocksizes[2];
+
+ /* modes are the primary means of supporting on-the-fly different
+ blocksizes, different channel mappings (LR or M/A),
+ different residue backends, etc. Each mode consists of a
+ blocksize flag and a mapping (along with the mapping setup */
+
+ int modes;
+ int maps;
+ int times;
+ int floors;
+ int residues;
+ int books;
+
+ vorbis_info_mode *mode_param[64];
+ int map_type[64];
+ vorbis_info_mapping *map_param[64];
+ int time_type[64];
+ int floor_type[64];
+ vorbis_info_floor *floor_param[64];
+ int residue_type[64];
+ vorbis_info_residue *residue_param[64];
+ static_codebook *book_param[256];
+ codebook *fullbooks;
+
+ int passlimit[32]; /* iteration limit per couple/quant pass */
+ int coupling_passes;
+} codec_setup_info;
+
+#endif
diff --git a/osframework/source/SexyAppFramework/ogg/config_types.h b/osframework/source/SexyAppFramework/ogg/config_types.h
new file mode 100644
index 0000000..d2200d1
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/config_types.h
@@ -0,0 +1,25 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: #ifdef jail to whip a few platforms into the UNIX ideal.
+
+ ********************************************************************/
+#ifndef _OS_CVTYPES_H
+#define _OS_CVTYPES_H
+
+typedef long long ogg_int64_t;
+typedef int ogg_int32_t;
+typedef unsigned int ogg_uint32_t;
+typedef short ogg_int16_t;
+
+#endif
diff --git a/osframework/source/SexyAppFramework/ogg/floor0.c b/osframework/source/SexyAppFramework/ogg/floor0.c
new file mode 100644
index 0000000..42feaa5
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/floor0.c
@@ -0,0 +1,437 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: floor backend 0 implementation
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "registry.h"
+#include "codebook.h"
+#include "misc.h"
+#include "os.h"
+
+#define LSP_FRACBITS 14
+
+typedef struct {
+ long n;
+ int ln;
+ int m;
+ int *linearmap;
+
+ vorbis_info_floor0 *vi;
+ ogg_int32_t *lsp_look;
+
+} vorbis_look_floor0;
+
+/*************** LSP decode ********************/
+
+#include "lsp_lookup.h"
+
+/* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in
+ 16.16 format
+ returns in m.8 format */
+
+static long ADJUST_SQRT2[2]={8192,5792};
+STIN ogg_int32_t vorbis_invsqlook_i(long a,long e){
+ long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
+ long d=a&INVSQ_LOOKUP_I_MASK; /* 0.10 */
+ long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
+ ((INVSQ_LOOKUP_IDel[i]*d)>>INVSQ_LOOKUP_I_SHIFT); /* result 1.16 */
+ val*=ADJUST_SQRT2[e&1];
+ e=(e>>1)+21;
+ return(val>>e);
+}
+
+/* interpolated lookup based fromdB function, domain -140dB to 0dB only */
+/* a is in n.12 format */
+STIN ogg_int32_t vorbis_fromdBlook_i(long a){
+ int i=(-a)>>(12-FROMdB2_SHIFT);
+ if(i<0) return 0x7fffffff;
+ if(i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))return 0;
+
+ return FROMdB_LOOKUP[i>>FROMdB_SHIFT] * FROMdB2_LOOKUP[i&FROMdB2_MASK];
+}
+
+/* interpolated lookup based cos function, domain 0 to PI only */
+/* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */
+STIN ogg_int32_t vorbis_coslook_i(long a){
+ int i=a>>COS_LOOKUP_I_SHIFT;
+ int d=a&COS_LOOKUP_I_MASK;
+ return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
+ COS_LOOKUP_I_SHIFT);
+}
+
+/* interpolated lookup based cos function */
+/* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */
+STIN ogg_int32_t vorbis_coslook2_i(long a){
+ a=a&0x1ffff;
+
+ if(a>0x10000)a=0x20000-a;
+ {
+ int i=a>>COS_LOOKUP_I_SHIFT;
+ int d=a&COS_LOOKUP_I_MASK;
+ a=((COS_LOOKUP_I[i]<<COS_LOOKUP_I_SHIFT)-
+ d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
+ (COS_LOOKUP_I_SHIFT-LSP_FRACBITS+14);
+ }
+
+ return(a);
+}
+
+static const int barklook[28]={
+ 0,100,200,301, 405,516,635,766,
+ 912,1077,1263,1476, 1720,2003,2333,2721,
+ 3184,3742,4428,5285, 6376,7791,9662,12181,
+ 15624,20397,27087,36554
+};
+
+/* used in init only; interpolate the long way */
+STIN ogg_int32_t toBARK(int n){
+ int i;
+ for(i=0;i<27;i++)
+ if(n>=barklook[i] && n<barklook[i+1])break;
+
+ if(i==27){
+ return 27<<15;
+ }else{
+ int gap=barklook[i+1]-barklook[i];
+ int del=n-barklook[i];
+
+ return((i<<15)+((del<<15)/gap));
+ }
+}
+
+static const unsigned char MLOOP_1[64]={
+ 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
+ 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
+ 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
+ 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
+};
+
+static const unsigned char MLOOP_2[64]={
+ 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
+ 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
+ 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
+ 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
+};
+
+static const unsigned char MLOOP_3[8]={0,1,2,2,3,3,3,3};
+
+void vorbis_lsp_to_curve(ogg_int32_t *curve,int *map,int n,int ln,
+ ogg_int32_t *lsp,int m,
+ ogg_int32_t amp,
+ ogg_int32_t ampoffset,
+ ogg_int32_t *icos){
+
+ /* 0 <= m < 256 */
+
+ /* set up for using all int later */
+ int i;
+ int ampoffseti=ampoffset*4096;
+ int ampi=amp;
+ ogg_int32_t *ilsp=(ogg_int32_t *)alloca(m*sizeof(*ilsp));
+ /* lsp is in 8.24, range 0 to PI; coslook wants it in .16 0 to 1*/
+ for(i=0;i<m;i++){
+#ifndef _LOW_ACCURACY_
+ ogg_int32_t val=MULT32(lsp[i],0x517cc2);
+#else
+ ogg_int32_t val=((lsp[i]>>10)*0x517d)>>14;
+#endif
+
+ /* safeguard against a malicious stream */
+ if(val<0 || (val>>COS_LOOKUP_I_SHIFT)>=COS_LOOKUP_I_SZ){
+ memset(curve,0,sizeof(*curve)*n);
+ return;
+ }
+
+ ilsp[i]=vorbis_coslook_i(val);
+ }
+
+ i=0;
+ while(i<n){
+ int j,k=map[i];
+ ogg_uint32_t pi=46341; /* 2**-.5 in 0.16 */
+ ogg_uint32_t qi=46341;
+ ogg_int32_t qexp=0,shift;
+ ogg_int32_t wi=icos[k];
+
+#ifdef _V_LSP_MATH_ASM
+ lsp_loop_asm(&qi,&pi,&qexp,ilsp,wi,m);
+
+ pi=((pi*pi)>>16);
+ qi=((qi*qi)>>16);
+
+ if(m&1){
+ qexp= qexp*2-28*((m+1)>>1)+m;
+ pi*=(1<<14)-((wi*wi)>>14);
+ qi+=pi>>14;
+ }else{
+ qexp= qexp*2-13*m;
+
+ pi*=(1<<14)-wi;
+ qi*=(1<<14)+wi;
+
+ qi=(qi+pi)>>14;
+ }
+
+ if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
+ qi>>=1; qexp++;
+ }else
+ lsp_norm_asm(&qi,&qexp);
+
+#else
+
+ qi*=labs(ilsp[0]-wi);
+ pi*=labs(ilsp[1]-wi);
+
+ for(j=3;j<m;j+=2){
+ if(!(shift=MLOOP_1[(pi|qi)>>25]))
+ if(!(shift=MLOOP_2[(pi|qi)>>19]))
+ shift=MLOOP_3[(pi|qi)>>16];
+ qi=(qi>>shift)*labs(ilsp[j-1]-wi);
+ pi=(pi>>shift)*labs(ilsp[j]-wi);
+ qexp+=shift;
+ }
+ if(!(shift=MLOOP_1[(pi|qi)>>25]))
+ if(!(shift=MLOOP_2[(pi|qi)>>19]))
+ shift=MLOOP_3[(pi|qi)>>16];
+
+ /* pi,qi normalized collectively, both tracked using qexp */
+
+ if(m&1){
+ /* odd order filter; slightly assymetric */
+ /* the last coefficient */
+ qi=(qi>>shift)*labs(ilsp[j-1]-wi);
+ pi=(pi>>shift)<<14;
+ qexp+=shift;
+
+ if(!(shift=MLOOP_1[(pi|qi)>>25]))
+ if(!(shift=MLOOP_2[(pi|qi)>>19]))
+ shift=MLOOP_3[(pi|qi)>>16];
+
+ pi>>=shift;
+ qi>>=shift;
+ qexp+=shift-14*((m+1)>>1);
+
+ pi=((pi*pi)>>16);
+ qi=((qi*qi)>>16);
+ qexp=qexp*2+m;
+
+ pi*=(1<<14)-((wi*wi)>>14);
+ qi+=pi>>14;
+
+ }else{
+ /* even order filter; still symmetric */
+
+ /* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't
+ worth tracking step by step */
+
+ pi>>=shift;
+ qi>>=shift;
+ qexp+=shift-7*m;
+
+ pi=((pi*pi)>>16);
+ qi=((qi*qi)>>16);
+ qexp=qexp*2+m;
+
+ pi*=(1<<14)-wi;
+ qi*=(1<<14)+wi;
+ qi=(qi+pi)>>14;
+
+ }
+
+
+ /* we've let the normalization drift because it wasn't important;
+ however, for the lookup, things must be normalized again. We
+ need at most one right shift or a number of left shifts */
+
+ if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
+ qi>>=1; qexp++;
+ }else
+ while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
+ qi<<=1; qexp--;
+ }
+
+#endif
+
+ amp=vorbis_fromdBlook_i(ampi* /* n.4 */
+ vorbis_invsqlook_i(qi,qexp)-
+ /* m.8, m+n<=8 */
+ ampoffseti); /* 8.12[0] */
+
+#ifdef _LOW_ACCURACY_
+ amp>>=9;
+#endif
+ curve[i]= MULT31_SHIFT15(curve[i],amp);
+ while(map[++i]==k) curve[i]= MULT31_SHIFT15(curve[i],amp);
+ }
+}
+
+/*************** vorbis decode glue ************/
+
+static void floor0_free_info(vorbis_info_floor *i){
+ vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
+ if(info){
+ memset(info,0,sizeof(*info));
+ _ogg_free(info);
+ }
+}
+
+static void floor0_free_look(vorbis_look_floor *i){
+ vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
+ if(look){
+
+ if(look->linearmap)_ogg_free(look->linearmap);
+ if(look->lsp_look)_ogg_free(look->lsp_look);
+ memset(look,0,sizeof(*look));
+ _ogg_free(look);
+ }
+}
+
+static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ int j;
+
+ vorbis_info_floor0 *info=(vorbis_info_floor0 *)_ogg_malloc(sizeof(*info));
+ info->order=oggpack_read(opb,8);
+ info->rate=oggpack_read(opb,16);
+ info->barkmap=oggpack_read(opb,16);
+ info->ampbits=oggpack_read(opb,6);
+ info->ampdB=oggpack_read(opb,8);
+ info->numbooks=oggpack_read(opb,4)+1;
+
+ if(info->order<1)goto err_out;
+ if(info->rate<1)goto err_out;
+ if(info->barkmap<1)goto err_out;
+ if(info->numbooks<1)goto err_out;
+
+ for(j=0;j<info->numbooks;j++){
+ info->books[j]=oggpack_read(opb,8);
+ if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
+ }
+ return(info);
+
+ err_out:
+ floor0_free_info(info);
+ return(NULL);
+}
+
+/* initialize Bark scale and normalization lookups. We could do this
+ with static tables, but Vorbis allows a number of possible
+ combinations, so it's best to do it computationally.
+
+ The below is authoritative in terms of defining scale mapping.
+ Note that the scale depends on the sampling rate as well as the
+ linear block and mapping sizes */
+
+static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi,
+ vorbis_info_floor *i){
+ int j;
+ vorbis_info *vi=vd->vi;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
+ vorbis_look_floor0 *look=(vorbis_look_floor0 *)_ogg_calloc(1,sizeof(*look));
+ look->m=info->order;
+ look->n=ci->blocksizes[mi->blockflag]/2;
+ look->ln=info->barkmap;
+ look->vi=info;
+
+ /* the mapping from a linear scale to a smaller bark scale is
+ straightforward. We do *not* make sure that the linear mapping
+ does not skip bark-scale bins; the decoder simply skips them and
+ the encoder may do what it wishes in filling them. They're
+ necessary in some mapping combinations to keep the scale spacing
+ accurate */
+ look->linearmap=(int *)_ogg_malloc((look->n+1)*sizeof(*look->linearmap));
+ for(j=0;j<look->n;j++){
+
+ int val=(look->ln*
+ ((toBARK(info->rate/2*j/look->n)<<11)/toBARK(info->rate/2)))>>11;
+
+ if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
+ look->linearmap[j]=val;
+ }
+ look->linearmap[j]=-1;
+
+ look->lsp_look=(ogg_int32_t *)_ogg_malloc(look->ln*sizeof(*look->lsp_look));
+ for(j=0;j<look->ln;j++)
+ look->lsp_look[j]=vorbis_coslook2_i(0x10000*j/look->ln);
+
+ return look;
+}
+
+static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
+ vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
+ vorbis_info_floor0 *info=look->vi;
+ int j,k;
+
+ extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
+
+ int ampraw=oggpack_read(&vb->opb,info->ampbits);
+ if(ampraw>0){ /* also handles the -1 out of data case */
+ long maxval=(1<<info->ampbits)-1;
+ int amp=((ampraw*info->ampdB)<<4)/maxval;
+ int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
+
+ if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
+ codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
+ codebook *b=ci->fullbooks+info->books[booknum];
+ ogg_int32_t last=0;
+ ogg_int32_t *lsp=(ogg_int32_t *)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+1));
+
+ for(j=0;j<look->m;j+=b->dim)
+ if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim,-24)==-1)goto eop;
+ for(j=0;j<look->m;){
+ for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
+ last=lsp[j-1];
+ }
+
+ lsp[look->m]=amp;
+ return(lsp);
+ }
+ }
+ eop:
+ return(NULL);
+}
+
+static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
+ void *memo,ogg_int32_t *out){
+ vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
+ vorbis_info_floor0 *info=look->vi;
+
+ if(memo){
+ ogg_int32_t *lsp=(ogg_int32_t *)memo;
+ ogg_int32_t amp=lsp[look->m];
+
+ /* take the coefficients back to a spectral envelope curve */
+ vorbis_lsp_to_curve(out,look->linearmap,look->n,look->ln,
+ lsp,look->m,amp,info->ampdB,look->lsp_look);
+ return(1);
+ }
+ memset(out,0,sizeof(*out)*look->n);
+ return(0);
+}
+
+/* export hooks */
+vorbis_func_floor floor0_exportbundle={
+ &floor0_unpack,&floor0_look,&floor0_free_info,
+ &floor0_free_look,&floor0_inverse1,&floor0_inverse2
+};
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/floor1.c b/osframework/source/SexyAppFramework/ogg/floor1.c
new file mode 100644
index 0000000..545b7d9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/floor1.c
@@ -0,0 +1,440 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: floor backend 1 implementation
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "registry.h"
+#include "codebook.h"
+#include "misc.h"
+
+extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
+
+#define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
+
+typedef struct {
+ int forward_index[VIF_POSIT+2];
+
+ int hineighbor[VIF_POSIT];
+ int loneighbor[VIF_POSIT];
+ int posts;
+
+ int n;
+ int quant_q;
+ vorbis_info_floor1 *vi;
+
+} vorbis_look_floor1;
+
+/***********************************************/
+
+static void floor1_free_info(vorbis_info_floor *i){
+ vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
+ if(info){
+ memset(info,0,sizeof(*info));
+ _ogg_free(info);
+ }
+}
+
+static void floor1_free_look(vorbis_look_floor *i){
+ vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
+ if(look){
+ memset(look,0,sizeof(*look));
+ _ogg_free(look);
+ }
+}
+
+static int ilog(unsigned int v){
+ int ret=0;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ int j,k,count=0,maxclass=-1,rangebits;
+
+ vorbis_info_floor1 *info=(vorbis_info_floor1 *)_ogg_calloc(1,sizeof(*info));
+ /* read partitions */
+ info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
+ for(j=0;j<info->partitions;j++){
+ info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
+ if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
+ }
+
+ /* read partition classes */
+ for(j=0;j<maxclass+1;j++){
+ info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
+ info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
+ if(info->class_subs[j]<0)
+ goto err_out;
+ if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
+ if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
+ goto err_out;
+ for(k=0;k<(1<<info->class_subs[j]);k++){
+ info->class_subbook[j][k]=oggpack_read(opb,8)-1;
+ if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
+ goto err_out;
+ }
+ }
+
+ /* read the post list */
+ info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
+ rangebits=oggpack_read(opb,4);
+
+ for(j=0,k=0;j<info->partitions;j++){
+ count+=info->class_dim[info->partitionclass[j]];
+ for(;k<count;k++){
+ int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
+ if(t<0 || t>=(1<<rangebits))
+ goto err_out;
+ }
+ }
+ info->postlist[0]=0;
+ info->postlist[1]=1<<rangebits;
+
+ return(info);
+
+ err_out:
+ floor1_free_info(info);
+ return(NULL);
+}
+
+static int icomp(const void *a,const void *b){
+ return(**(int **)a-**(int **)b);
+}
+
+static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,vorbis_info_mode *mi,
+ vorbis_info_floor *in){
+
+ int *sortpointer[VIF_POSIT+2];
+ vorbis_info_floor1 *info=(vorbis_info_floor1 *)in;
+ vorbis_look_floor1 *look=(vorbis_look_floor1 *)_ogg_calloc(1,sizeof(*look));
+ int i,j,n=0;
+
+ look->vi=info;
+ look->n=info->postlist[1];
+
+ /* we drop each position value in-between already decoded values,
+ and use linear interpolation to predict each new value past the
+ edges. The positions are read in the order of the position
+ list... we precompute the bounding positions in the lookup. Of
+ course, the neighbors can change (if a position is declined), but
+ this is an initial mapping */
+
+ for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
+ n+=2;
+ look->posts=n;
+
+ /* also store a sorted position index */
+ for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
+ qsort(sortpointer,n,sizeof(*sortpointer),icomp);
+
+ /* points from sort order back to range number */
+ for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
+
+ /* quantize values to multiplier spec */
+ switch(info->mult){
+ case 1: /* 1024 -> 256 */
+ look->quant_q=256;
+ break;
+ case 2: /* 1024 -> 128 */
+ look->quant_q=128;
+ break;
+ case 3: /* 1024 -> 86 */
+ look->quant_q=86;
+ break;
+ case 4: /* 1024 -> 64 */
+ look->quant_q=64;
+ break;
+ }
+
+ /* discover our neighbors for decode where we don't use fit flags
+ (that would push the neighbors outward) */
+ for(i=0;i<n-2;i++){
+ int lo=0;
+ int hi=1;
+ int lx=0;
+ int hx=look->n;
+ int currentx=info->postlist[i+2];
+ for(j=0;j<i+2;j++){
+ int x=info->postlist[j];
+ if(x>lx && x<currentx){
+ lo=j;
+ lx=x;
+ }
+ if(x<hx && x>currentx){
+ hi=j;
+ hx=x;
+ }
+ }
+ look->loneighbor[i]=lo;
+ look->hineighbor[i]=hi;
+ }
+
+ return(look);
+}
+
+static int render_point(int x0,int x1,int y0,int y1,int x){
+ y0&=0x7fff; /* mask off flag */
+ y1&=0x7fff;
+
+ {
+ int dy=y1-y0;
+ int adx=x1-x0;
+ int ady=abs(dy);
+ int err=ady*(x-x0);
+
+ int off=err/adx;
+ if(dy<0)return(y0-off);
+ return(y0+off);
+ }
+}
+
+#ifdef _LOW_ACCURACY_
+# define XdB(n) ((((n)>>8)+1)>>1)
+#else
+# define XdB(n) (n)
+#endif
+
+static const ogg_int32_t FLOOR_fromdB_LOOKUP[256]={
+ XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114),
+ XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163),
+ XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9),
+ XdB(0x000001e7), XdB(0x00000206), XdB(0x00000228), XdB(0x0000024c),
+ XdB(0x00000272), XdB(0x0000029b), XdB(0x000002c6), XdB(0x000002f4),
+ XdB(0x00000326), XdB(0x0000035a), XdB(0x00000392), XdB(0x000003cd),
+ XdB(0x0000040c), XdB(0x00000450), XdB(0x00000497), XdB(0x000004e4),
+ XdB(0x00000535), XdB(0x0000058c), XdB(0x000005e8), XdB(0x0000064a),
+ XdB(0x000006b3), XdB(0x00000722), XdB(0x00000799), XdB(0x00000818),
+ XdB(0x0000089e), XdB(0x0000092e), XdB(0x000009c6), XdB(0x00000a69),
+ XdB(0x00000b16), XdB(0x00000bcf), XdB(0x00000c93), XdB(0x00000d64),
+ XdB(0x00000e43), XdB(0x00000f30), XdB(0x0000102d), XdB(0x0000113a),
+ XdB(0x00001258), XdB(0x0000138a), XdB(0x000014cf), XdB(0x00001629),
+ XdB(0x0000179a), XdB(0x00001922), XdB(0x00001ac4), XdB(0x00001c82),
+ XdB(0x00001e5c), XdB(0x00002055), XdB(0x0000226f), XdB(0x000024ac),
+ XdB(0x0000270e), XdB(0x00002997), XdB(0x00002c4b), XdB(0x00002f2c),
+ XdB(0x0000323d), XdB(0x00003581), XdB(0x000038fb), XdB(0x00003caf),
+ XdB(0x000040a0), XdB(0x000044d3), XdB(0x0000494c), XdB(0x00004e10),
+ XdB(0x00005323), XdB(0x0000588a), XdB(0x00005e4b), XdB(0x0000646b),
+ XdB(0x00006af2), XdB(0x000071e5), XdB(0x0000794c), XdB(0x0000812e),
+ XdB(0x00008993), XdB(0x00009283), XdB(0x00009c09), XdB(0x0000a62d),
+ XdB(0x0000b0f9), XdB(0x0000bc79), XdB(0x0000c8b9), XdB(0x0000d5c4),
+ XdB(0x0000e3a9), XdB(0x0000f274), XdB(0x00010235), XdB(0x000112fd),
+ XdB(0x000124dc), XdB(0x000137e4), XdB(0x00014c29), XdB(0x000161bf),
+ XdB(0x000178bc), XdB(0x00019137), XdB(0x0001ab4a), XdB(0x0001c70e),
+ XdB(0x0001e4a1), XdB(0x0002041f), XdB(0x000225aa), XdB(0x00024962),
+ XdB(0x00026f6d), XdB(0x000297f0), XdB(0x0002c316), XdB(0x0002f109),
+ XdB(0x000321f9), XdB(0x00035616), XdB(0x00038d97), XdB(0x0003c8b4),
+ XdB(0x000407a7), XdB(0x00044ab2), XdB(0x00049218), XdB(0x0004de23),
+ XdB(0x00052f1e), XdB(0x0005855c), XdB(0x0005e135), XdB(0x00064306),
+ XdB(0x0006ab33), XdB(0x00071a24), XdB(0x0007904b), XdB(0x00080e20),
+ XdB(0x00089422), XdB(0x000922da), XdB(0x0009bad8), XdB(0x000a5cb6),
+ XdB(0x000b091a), XdB(0x000bc0b1), XdB(0x000c8436), XdB(0x000d5471),
+ XdB(0x000e3233), XdB(0x000f1e5f), XdB(0x001019e4), XdB(0x001125c1),
+ XdB(0x00124306), XdB(0x001372d5), XdB(0x0014b663), XdB(0x00160ef7),
+ XdB(0x00177df0), XdB(0x001904c1), XdB(0x001aa4f9), XdB(0x001c603d),
+ XdB(0x001e384f), XdB(0x00202f0f), XdB(0x0022467a), XdB(0x002480b1),
+ XdB(0x0026dff7), XdB(0x002966b3), XdB(0x002c1776), XdB(0x002ef4fc),
+ XdB(0x0032022d), XdB(0x00354222), XdB(0x0038b828), XdB(0x003c67c2),
+ XdB(0x004054ae), XdB(0x004482e8), XdB(0x0048f6af), XdB(0x004db488),
+ XdB(0x0052c142), XdB(0x005821ff), XdB(0x005ddc33), XdB(0x0063f5b0),
+ XdB(0x006a74a7), XdB(0x00715faf), XdB(0x0078bdce), XdB(0x0080967f),
+ XdB(0x0088f1ba), XdB(0x0091d7f9), XdB(0x009b5247), XdB(0x00a56a41),
+ XdB(0x00b02a27), XdB(0x00bb9ce2), XdB(0x00c7ce12), XdB(0x00d4ca17),
+ XdB(0x00e29e20), XdB(0x00f15835), XdB(0x0101074b), XdB(0x0111bb4e),
+ XdB(0x01238531), XdB(0x01367704), XdB(0x014aa402), XdB(0x016020a7),
+ XdB(0x017702c3), XdB(0x018f6190), XdB(0x01a955cb), XdB(0x01c4f9cf),
+ XdB(0x01e269a8), XdB(0x0201c33b), XdB(0x0223265a), XdB(0x0246b4ea),
+ XdB(0x026c9302), XdB(0x0294e716), XdB(0x02bfda13), XdB(0x02ed9793),
+ XdB(0x031e4e09), XdB(0x03522ee4), XdB(0x03896ed0), XdB(0x03c445e2),
+ XdB(0x0402efd6), XdB(0x0445ac4b), XdB(0x048cbefc), XdB(0x04d87013),
+ XdB(0x05290c67), XdB(0x057ee5ca), XdB(0x05da5364), XdB(0x063bb204),
+ XdB(0x06a36485), XdB(0x0711d42b), XdB(0x0787710e), XdB(0x0804b299),
+ XdB(0x088a17ef), XdB(0x0918287e), XdB(0x09af747c), XdB(0x0a50957e),
+ XdB(0x0afc2f19), XdB(0x0bb2ef7f), XdB(0x0c759034), XdB(0x0d44d6ca),
+ XdB(0x0e2195bc), XdB(0x0f0cad0d), XdB(0x10070b62), XdB(0x1111aeea),
+ XdB(0x122da66c), XdB(0x135c120f), XdB(0x149e24d9), XdB(0x15f525b1),
+ XdB(0x176270e3), XdB(0x18e7794b), XdB(0x1a85c9ae), XdB(0x1c3f06d1),
+ XdB(0x1e14f07d), XdB(0x200963d7), XdB(0x221e5ccd), XdB(0x2455f870),
+ XdB(0x26b2770b), XdB(0x29363e2b), XdB(0x2be3db5c), XdB(0x2ebe06b6),
+ XdB(0x31c7a55b), XdB(0x3503ccd4), XdB(0x3875c5aa), XdB(0x3c210f44),
+ XdB(0x4009632b), XdB(0x4432b8cf), XdB(0x48a149bc), XdB(0x4d59959e),
+ XdB(0x52606733), XdB(0x57bad899), XdB(0x5d6e593a), XdB(0x6380b298),
+ XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff),
+};
+
+static void render_line(int x0,int x1,int y0,int y1,ogg_int32_t *d){
+ int dy=y1-y0;
+ int adx=x1-x0;
+ int ady=abs(dy);
+ int base=dy/adx;
+ int sy=(dy<0?base-1:base+1);
+ int x=x0;
+ int y=y0;
+ int err=0;
+
+ ady-=abs(base*adx);
+
+ d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]);
+
+ while(++x<x1){
+ err=err+ady;
+ if(err>=adx){
+ err-=adx;
+ y+=sy;
+ }else{
+ y+=base;
+ }
+ d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]);
+ }
+}
+
+static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
+ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
+ vorbis_info_floor1 *info=look->vi;
+ codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
+
+ int i,j,k;
+ codebook *books=ci->fullbooks;
+
+ /* unpack wrapped/predicted values from stream */
+ if(oggpack_read(&vb->opb,1)==1){
+ int *fit_value=(int *)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
+
+ fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
+ fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
+
+ /* partition by partition */
+ /* partition by partition */
+ for(i=0,j=2;i<info->partitions;i++){
+ int classv=info->partitionclass[i];
+ int cdim=info->class_dim[classv];
+ int csubbits=info->class_subs[classv];
+ int csub=1<<csubbits;
+ int cval=0;
+
+ /* decode the partition's first stage cascade value */
+ if(csubbits){
+ cval=vorbis_book_decode(books+info->class_book[classv],&vb->opb);
+
+ if(cval==-1)goto eop;
+ }
+
+ for(k=0;k<cdim;k++){
+ int book=info->class_subbook[classv][cval&(csub-1)];
+ cval>>=csubbits;
+ if(book>=0){
+ if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
+ goto eop;
+ }else{
+ fit_value[j+k]=0;
+ }
+ }
+ j+=cdim;
+ }
+
+ /* unwrap positive values and reconsitute via linear interpolation */
+ for(i=2;i<look->posts;i++){
+ int predicted=render_point(info->postlist[look->loneighbor[i-2]],
+ info->postlist[look->hineighbor[i-2]],
+ fit_value[look->loneighbor[i-2]],
+ fit_value[look->hineighbor[i-2]],
+ info->postlist[i]);
+ int hiroom=look->quant_q-predicted;
+ int loroom=predicted;
+ int room=(hiroom<loroom?hiroom:loroom)<<1;
+ int val=fit_value[i];
+
+ if(val){
+ if(val>=room){
+ if(hiroom>loroom){
+ val = val-loroom;
+ }else{
+ val = -1-(val-hiroom);
+ }
+ }else{
+ if(val&1){
+ val= -((val+1)>>1);
+ }else{
+ val>>=1;
+ }
+ }
+
+ fit_value[i]=val+predicted;
+ fit_value[look->loneighbor[i-2]]&=0x7fff;
+ fit_value[look->hineighbor[i-2]]&=0x7fff;
+
+ }else{
+ fit_value[i]=predicted|0x8000;
+ }
+
+ }
+
+ return(fit_value);
+ }
+ eop:
+ return(NULL);
+}
+
+static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
+ ogg_int32_t *out){
+ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
+ vorbis_info_floor1 *info=look->vi;
+
+ codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
+ int n=ci->blocksizes[vb->W]/2;
+ int j;
+
+ if(memo){
+ /* render the lines */
+ int *fit_value=(int *)memo;
+ int hx=0;
+ int lx=0;
+ int ly=fit_value[0]*info->mult;
+ for(j=1;j<look->posts;j++){
+ int current=look->forward_index[j];
+ int hy=fit_value[current]&0x7fff;
+ if(hy==fit_value[current]){
+
+ hy*=info->mult;
+ hx=info->postlist[current];
+
+ render_line(lx,hx,ly,hy,out);
+
+ lx=hx;
+ ly=hy;
+ }
+ }
+ for(j=hx;j<n;j++)out[j]*=ly; /* be certain */
+ return(1);
+ }
+ memset(out,0,sizeof(*out)*n);
+ return(0);
+}
+
+/* export hooks */
+vorbis_func_floor floor1_exportbundle={
+ &floor1_unpack,&floor1_look,&floor1_free_info,
+ &floor1_free_look,&floor1_inverse1,&floor1_inverse2
+};
+
diff --git a/osframework/source/SexyAppFramework/ogg/framing.c b/osframework/source/SexyAppFramework/ogg/framing.c
new file mode 100644
index 0000000..5ba288e
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/framing.c
@@ -0,0 +1,1126 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: decode Ogg streams back into raw packets
+
+ note: The CRC code is directly derived from public domain code by
+ Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
+ for details.
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include "ogg.h"
+#include "misc.h"
+
+
+/* A complete description of Ogg framing exists in docs/framing.html */
+
+/* basic, centralized Ogg memory management based on linked lists of
+ references to refcounted memory buffers. References and buffers
+ are both recycled. Buffers are passed around and consumed in
+ reference form. */
+
+static ogg_buffer_state *ogg_buffer_create(void){
+ ogg_buffer_state *bs=_ogg_calloc(1,sizeof(*bs));
+ return bs;
+}
+
+/* destruction is 'lazy'; there may be memory references outstanding,
+ and yanking the buffer state out from underneath would be
+ antisocial. Dealloc what is currently unused and have
+ _release_one watch for the stragglers to come in. When they do,
+ finish destruction. */
+
+/* call the helper while holding lock */
+static void _ogg_buffer_destroy(ogg_buffer_state *bs){
+ ogg_buffer *bt;
+ ogg_reference *rt;
+
+ if(bs->shutdown){
+
+ bt=bs->unused_buffers;
+ rt=bs->unused_references;
+
+ if(!bs->outstanding){
+ _ogg_free(bs);
+ return;
+ }
+
+ while(bt){
+ ogg_buffer *b=bt;
+ bt=b->ptr.next;
+ if(b->data)_ogg_free(b->data);
+ _ogg_free(b);
+ }
+ bs->unused_buffers=0;
+ while(rt){
+ ogg_reference *r=rt;
+ rt=r->next;
+ _ogg_free(r);
+ }
+ bs->unused_references=0;
+ }
+}
+
+static void ogg_buffer_destroy(ogg_buffer_state *bs){
+ bs->shutdown=1;
+ _ogg_buffer_destroy(bs);
+}
+
+static ogg_buffer *_fetch_buffer(ogg_buffer_state *bs,long bytes){
+ ogg_buffer *ob;
+ bs->outstanding++;
+
+ /* do we have an unused buffer sitting in the pool? */
+ if(bs->unused_buffers){
+ ob=bs->unused_buffers;
+ bs->unused_buffers=ob->ptr.next;
+
+ /* if the unused buffer is too small, grow it */
+ if(ob->size<bytes){
+ ob->data=_ogg_realloc(ob->data,bytes);
+ ob->size=bytes;
+ }
+ }else{
+ /* allocate a new buffer */
+ ob=_ogg_malloc(sizeof(*ob));
+ ob->data=_ogg_malloc(bytes<16?16:bytes);
+ ob->size=bytes;
+ }
+
+ ob->refcount=1;
+ ob->ptr.owner=bs;
+ return ob;
+}
+
+static ogg_reference *_fetch_ref(ogg_buffer_state *bs){
+ ogg_reference *or;
+ bs->outstanding++;
+
+ /* do we have an unused reference sitting in the pool? */
+ if(bs->unused_references){
+ or=bs->unused_references;
+ bs->unused_references=or->next;
+ }else{
+ /* allocate a new reference */
+ or=_ogg_malloc(sizeof(*or));
+ }
+
+ or->begin=0;
+ or->length=0;
+ or->next=0;
+ return or;
+}
+
+/* fetch a reference pointing to a fresh, initially continguous buffer
+ of at least [bytes] length */
+static ogg_reference *ogg_buffer_alloc(ogg_buffer_state *bs,long bytes){
+ ogg_buffer *ob=_fetch_buffer(bs,bytes);
+ ogg_reference *or=_fetch_ref(bs);
+ or->buffer=ob;
+ return or;
+}
+
+/* enlarge the data buffer in the current link */
+static void ogg_buffer_realloc(ogg_reference *or,long bytes){
+ ogg_buffer *ob=or->buffer;
+
+ /* if the unused buffer is too small, grow it */
+ if(ob->size<bytes){
+ ob->data=_ogg_realloc(ob->data,bytes);
+ ob->size=bytes;
+ }
+}
+
+static void _ogg_buffer_mark_one(ogg_reference *or){
+ or->buffer->refcount++;
+}
+
+/* increase the refcount of the buffers to which the reference points */
+static void ogg_buffer_mark(ogg_reference *or){
+ while(or){
+ _ogg_buffer_mark_one(or);
+ or=or->next;
+ }
+}
+
+/* duplicate a reference (pointing to the same actual buffer memory)
+ and increment buffer refcount. If the desired segment begins out
+ of range, NULL is returned; if the desired segment is simply zero
+ length, a zero length ref is returned. Partial range overlap
+ returns the overlap of the ranges */
+static ogg_reference *ogg_buffer_sub(ogg_reference *or,long begin,long length){
+ ogg_reference *ret=0,*head=0;
+
+ /* walk past any preceeding fragments we don't want */
+ while(or && begin>=or->length){
+ begin-=or->length;
+ or=or->next;
+ }
+
+ /* duplicate the reference chain; increment refcounts */
+ while(or && length){
+ ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner);
+ if(head)
+ head->next=temp;
+ else
+ ret=temp;
+ head=temp;
+ head->buffer=or->buffer;
+ head->begin=or->begin+begin;
+ head->length=length;
+ if(head->length>or->length-begin)
+ head->length=or->length-begin;
+
+ begin=0;
+ length-=head->length;
+ or=or->next;
+ }
+
+ ogg_buffer_mark(ret);
+ return ret;
+}
+
+ogg_reference *ogg_buffer_dup(ogg_reference *or){
+ ogg_reference *ret=0,*head=0;
+ /* duplicate the reference chain; increment refcounts */
+ while(or){
+ ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner);
+ if(head)
+ head->next=temp;
+ else
+ ret=temp;
+ head=temp;
+ head->buffer=or->buffer;
+ head->begin=or->begin;
+ head->length=or->length;
+ or=or->next;
+ }
+
+ ogg_buffer_mark(ret);
+ return ret;
+}
+
+/* split a reference into two references; 'return' is a reference to
+ the buffer preceeding pos and 'head'/'tail' are the buffer past the
+ split. If pos is at or past the end of the passed in segment,
+ 'head/tail' are NULL */
+static ogg_reference *ogg_buffer_split(ogg_reference **tail,
+ ogg_reference **head,long pos){
+
+ /* walk past any preceeding fragments to one of:
+ a) the exact boundary that seps two fragments
+ b) the fragment that needs split somewhere in the middle */
+ ogg_reference *ret=*tail;
+ ogg_reference *or=*tail;
+
+ while(or && pos>or->length){
+ pos-=or->length;
+ or=or->next;
+ }
+
+ if(!or || pos==0){
+
+ return 0;
+
+ }else{
+
+ if(pos>=or->length){
+ /* exact split, or off the end? */
+ if(or->next){
+
+ /* a split */
+ *tail=or->next;
+ or->next=0;
+
+ }else{
+
+ /* off or at the end */
+ *tail=*head=0;
+
+ }
+ }else{
+
+ /* split within a fragment */
+ long lengthA=pos;
+ long beginB=or->begin+pos;
+ long lengthB=or->length-pos;
+
+ /* make a new reference to tail the second piece */
+ *tail=_fetch_ref(or->buffer->ptr.owner);
+
+ (*tail)->buffer=or->buffer;
+ (*tail)->begin=beginB;
+ (*tail)->length=lengthB;
+ (*tail)->next=or->next;
+ _ogg_buffer_mark_one(*tail);
+ if(head && or==*head)*head=*tail;
+
+ /* update the first piece */
+ or->next=0;
+ or->length=lengthA;
+
+ }
+ }
+ return ret;
+}
+
+static void ogg_buffer_release_one(ogg_reference *or){
+ ogg_buffer *ob=or->buffer;
+ ogg_buffer_state *bs=ob->ptr.owner;
+
+ ob->refcount--;
+ if(ob->refcount==0){
+ bs->outstanding--; /* for the returned buffer */
+ ob->ptr.next=bs->unused_buffers;
+ bs->unused_buffers=ob;
+ }
+
+ bs->outstanding--; /* for the returned reference */
+ or->next=bs->unused_references;
+ bs->unused_references=or;
+
+ _ogg_buffer_destroy(bs); /* lazy cleanup (if needed) */
+
+}
+
+/* release the references, decrease the refcounts of buffers to which
+ they point, release any buffers with a refcount that drops to zero */
+static void ogg_buffer_release(ogg_reference *or){
+ while(or){
+ ogg_reference *next=or->next;
+ ogg_buffer_release_one(or);
+ or=next;
+ }
+}
+
+static ogg_reference *ogg_buffer_pretruncate(ogg_reference *or,long pos){
+ /* release preceeding fragments we don't want */
+ while(or && pos>=or->length){
+ ogg_reference *next=or->next;
+ pos-=or->length;
+ ogg_buffer_release_one(or);
+ or=next;
+ }
+ if (or) {
+ or->begin+=pos;
+ or->length-=pos;
+ }
+ return or;
+}
+
+static ogg_reference *ogg_buffer_walk(ogg_reference *or){
+ if(!or)return NULL;
+ while(or->next){
+ or=or->next;
+ }
+ return(or);
+}
+
+/* *head is appended to the front end (head) of *tail; both continue to
+ be valid pointers, with *tail at the tail and *head at the head */
+static ogg_reference *ogg_buffer_cat(ogg_reference *tail, ogg_reference *head){
+ if(!tail)return head;
+
+ while(tail->next){
+ tail=tail->next;
+ }
+ tail->next=head;
+ return ogg_buffer_walk(head);
+}
+
+static void _positionB(oggbyte_buffer *b,int pos){
+ if(pos<b->pos){
+ /* start at beginning, scan forward */
+ b->ref=b->baseref;
+ b->pos=0;
+ b->end=b->pos+b->ref->length;
+ b->ptr=b->ref->buffer->data+b->ref->begin;
+ }
+}
+
+static void _positionF(oggbyte_buffer *b,int pos){
+ /* scan forward for position */
+ while(pos>=b->end){
+ /* just seek forward */
+ b->pos+=b->ref->length;
+ b->ref=b->ref->next;
+ b->end=b->ref->length+b->pos;
+ b->ptr=b->ref->buffer->data+b->ref->begin;
+ }
+}
+
+static int oggbyte_init(oggbyte_buffer *b,ogg_reference *or){
+ memset(b,0,sizeof(*b));
+ if(or){
+ b->ref=b->baseref=or;
+ b->pos=0;
+ b->end=b->ref->length;
+ b->ptr=b->ref->buffer->data+b->ref->begin;
+ return 0;
+ }else
+ return -1;
+}
+
+static void oggbyte_set4(oggbyte_buffer *b,ogg_uint32_t val,int pos){
+ int i;
+ _positionB(b,pos);
+ for(i=0;i<4;i++){
+ _positionF(b,pos);
+ b->ptr[pos-b->pos]=val;
+ val>>=8;
+ ++pos;
+ }
+}
+
+static unsigned char oggbyte_read1(oggbyte_buffer *b,int pos){
+ _positionB(b,pos);
+ _positionF(b,pos);
+ return b->ptr[pos-b->pos];
+}
+
+static ogg_uint32_t oggbyte_read4(oggbyte_buffer *b,int pos){
+ ogg_uint32_t ret;
+ _positionB(b,pos);
+ _positionF(b,pos);
+ ret=b->ptr[pos-b->pos];
+ _positionF(b,++pos);
+ ret|=b->ptr[pos-b->pos]<<8;
+ _positionF(b,++pos);
+ ret|=b->ptr[pos-b->pos]<<16;
+ _positionF(b,++pos);
+ ret|=b->ptr[pos-b->pos]<<24;
+ return ret;
+}
+
+static ogg_int64_t oggbyte_read8(oggbyte_buffer *b,int pos){
+ ogg_int64_t ret;
+ unsigned char t[7];
+ int i;
+ _positionB(b,pos);
+ for(i=0;i<7;i++){
+ _positionF(b,pos);
+ t[i]=b->ptr[pos++ -b->pos];
+ }
+
+ _positionF(b,pos);
+ ret=b->ptr[pos-b->pos];
+
+ for(i=6;i>=0;--i)
+ ret= ret<<8 | t[i];
+
+ return ret;
+}
+
+/* Now we get to the actual framing code */
+
+int ogg_page_version(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read1(&ob,4);
+}
+
+int ogg_page_continued(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read1(&ob,5)&0x01;
+}
+
+int ogg_page_bos(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read1(&ob,5)&0x02;
+}
+
+int ogg_page_eos(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read1(&ob,5)&0x04;
+}
+
+ogg_int64_t ogg_page_granulepos(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read8(&ob,6);
+}
+
+ogg_uint32_t ogg_page_serialno(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read4(&ob,14);
+}
+
+ogg_uint32_t ogg_page_pageno(ogg_page *og){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+ return oggbyte_read4(&ob,18);
+}
+
+/* returns the number of packets that are completed on this page (if
+ the leading packet is begun on a previous page, but ends on this
+ page, it's counted */
+
+/* NOTE:
+If a page consists of a packet begun on a previous page, and a new
+packet begun (but not completed) on this page, the return will be:
+ ogg_page_packets(page) ==1,
+ ogg_page_continued(page) !=0
+
+If a page happens to be a single packet that was begun on a
+previous page, and spans to the next page (in the case of a three or
+more page packet), the return will be:
+ ogg_page_packets(page) ==0,
+ ogg_page_continued(page) !=0
+*/
+
+int ogg_page_packets(ogg_page *og){
+ int i;
+ int n;
+ int count=0;
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,og->header);
+
+ n=oggbyte_read1(&ob,26);
+ for(i=0;i<n;i++)
+ if(oggbyte_read1(&ob,27+i)<255)count++;
+ return(count);
+}
+
+/* Static CRC calculation table. See older code in CVS for dead
+ run-time initialization code. */
+
+static ogg_uint32_t crc_lookup[256]={
+ 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
+ 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
+ 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
+ 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
+ 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
+ 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
+ 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
+ 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
+ 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
+ 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
+ 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
+ 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
+ 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
+ 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
+ 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
+ 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
+ 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
+ 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
+ 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
+ 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
+ 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
+ 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
+ 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
+ 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
+ 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
+ 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
+ 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
+ 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
+ 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
+ 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
+ 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
+ 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
+ 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
+ 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
+ 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
+ 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
+ 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
+ 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
+ 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
+ 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
+ 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
+ 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
+ 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
+ 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
+ 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
+ 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
+ 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
+ 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
+ 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
+ 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
+ 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
+ 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
+ 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
+ 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
+ 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
+ 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
+ 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
+ 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
+ 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
+ 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
+ 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
+ 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
+ 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
+ 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
+
+ogg_sync_state *ogg_sync_create(void){
+ ogg_sync_state *oy=_ogg_calloc(1,sizeof(*oy));
+ memset(oy,0,sizeof(*oy));
+ oy->bufferpool=ogg_buffer_create();
+ return oy;
+}
+
+int ogg_sync_destroy(ogg_sync_state *oy){
+ if(oy){
+ ogg_sync_reset(oy);
+ ogg_buffer_destroy(oy->bufferpool);
+ memset(oy,0,sizeof(*oy));
+ _ogg_free(oy);
+ }
+ return OGG_SUCCESS;
+}
+
+unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long bytes){
+
+ /* [allocate and] expose a buffer for data submission.
+
+ If there is no head fragment
+ allocate one and expose it
+ else
+ if the current head fragment has sufficient unused space
+ expose it
+ else
+ if the current head fragment is unused
+ resize and expose it
+ else
+ allocate new fragment and expose it
+ */
+
+ /* base case; fifo uninitialized */
+ if(!oy->fifo_head){
+ oy->fifo_head=oy->fifo_tail=ogg_buffer_alloc(oy->bufferpool,bytes);
+ return oy->fifo_head->buffer->data;
+ }
+
+ /* space left in current fragment case */
+ if(oy->fifo_head->buffer->size-
+ oy->fifo_head->length-
+ oy->fifo_head->begin >= bytes)
+ return oy->fifo_head->buffer->data+
+ oy->fifo_head->length+oy->fifo_head->begin;
+
+ /* current fragment is unused, but too small */
+ if(!oy->fifo_head->length){
+ ogg_buffer_realloc(oy->fifo_head,bytes);
+ return oy->fifo_head->buffer->data+oy->fifo_head->begin;
+ }
+
+ /* current fragment used/full; get new fragment */
+ {
+ ogg_reference *new=ogg_buffer_alloc(oy->bufferpool,bytes);
+ oy->fifo_head->next=new;
+ oy->fifo_head=new;
+ }
+ return oy->fifo_head->buffer->data;
+}
+
+int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
+ if(!oy->fifo_head)return OGG_EINVAL;
+ if(oy->fifo_head->buffer->size-oy->fifo_head->length-oy->fifo_head->begin <
+ bytes)return OGG_EINVAL;
+ oy->fifo_head->length+=bytes;
+ oy->fifo_fill+=bytes;
+ return OGG_SUCCESS;
+}
+
+static ogg_uint32_t _checksum(ogg_reference *or, int bytes){
+ ogg_uint32_t crc_reg=0;
+ int j,post;
+
+ while(or){
+ unsigned char *data=or->buffer->data+or->begin;
+ post=(bytes<or->length?bytes:or->length);
+ for(j=0;j<post;++j)
+ crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^data[j]];
+ bytes-=j;
+ or=or->next;
+ }
+
+ return crc_reg;
+}
+
+
+/* sync the stream. This is meant to be useful for finding page
+ boundaries.
+
+ return values for this:
+ -n) skipped n bytes
+ 0) page not ready; more data (no bytes skipped)
+ n) page synced at current location; page length n bytes
+
+*/
+
+long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
+ oggbyte_buffer page;
+ long bytes,ret=0;
+
+ ogg_page_release(og);
+
+ bytes=oy->fifo_fill;
+ oggbyte_init(&page,oy->fifo_tail);
+
+ if(oy->headerbytes==0){
+ if(bytes<27)goto sync_out; /* not enough for even a minimal header */
+
+ /* verify capture pattern */
+ if(oggbyte_read1(&page,0)!=(int)'O' ||
+ oggbyte_read1(&page,1)!=(int)'g' ||
+ oggbyte_read1(&page,2)!=(int)'g' ||
+ oggbyte_read1(&page,3)!=(int)'S' ) goto sync_fail;
+
+ oy->headerbytes=oggbyte_read1(&page,26)+27;
+ }
+ if(bytes<oy->headerbytes)goto sync_out; /* not enough for header +
+ seg table */
+ if(oy->bodybytes==0){
+ int i;
+ /* count up body length in the segment table */
+ for(i=0;i<oy->headerbytes-27;i++)
+ oy->bodybytes+=oggbyte_read1(&page,27+i);
+ }
+
+ if(oy->bodybytes+oy->headerbytes>bytes)goto sync_out;
+
+ /* we have what appears to be a complete page; last test: verify
+ checksum */
+ {
+ ogg_uint32_t chksum=oggbyte_read4(&page,22);
+ oggbyte_set4(&page,0,22);
+
+ /* Compare checksums; memory continues to be common access */
+ if(chksum!=_checksum(oy->fifo_tail,oy->bodybytes+oy->headerbytes)){
+
+ /* D'oh. Mismatch! Corrupt page (or miscapture and not a page
+ at all). replace the computed checksum with the one actually
+ read in; remember all the memory is common access */
+
+ oggbyte_set4(&page,chksum,22);
+ goto sync_fail;
+ }
+ oggbyte_set4(&page,chksum,22);
+ }
+
+ /* We have a page. Set up page return. */
+ if(og){
+ /* set up page output */
+ og->header=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->headerbytes);
+ og->header_len=oy->headerbytes;
+ og->body=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->bodybytes);
+ og->body_len=oy->bodybytes;
+ }else{
+ /* simply advance */
+ oy->fifo_tail=
+ ogg_buffer_pretruncate(oy->fifo_tail,oy->headerbytes+oy->bodybytes);
+ if(!oy->fifo_tail)oy->fifo_head=0;
+ }
+
+ ret=oy->headerbytes+oy->bodybytes;
+ oy->unsynced=0;
+ oy->headerbytes=0;
+ oy->bodybytes=0;
+ oy->fifo_fill-=ret;
+
+ return ret;
+
+ sync_fail:
+
+ oy->headerbytes=0;
+ oy->bodybytes=0;
+ oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,1);
+ ret--;
+
+ /* search forward through fragments for possible capture */
+ while(oy->fifo_tail){
+ /* invariant: fifo_cursor points to a position in fifo_tail */
+ unsigned char *now=oy->fifo_tail->buffer->data+oy->fifo_tail->begin;
+ unsigned char *next=memchr(now, 'O', oy->fifo_tail->length);
+
+ if(next){
+ /* possible capture in this segment */
+ long bytes=next-now;
+ oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes);
+ ret-=bytes;
+ break;
+ }else{
+ /* no capture. advance to next segment */
+ long bytes=oy->fifo_tail->length;
+ ret-=bytes;
+ oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes);
+ }
+ }
+ if(!oy->fifo_tail)oy->fifo_head=0;
+ oy->fifo_fill+=ret;
+
+ sync_out:
+ return ret;
+}
+
+/* sync the stream and get a page. Keep trying until we find a page.
+ Supress 'sync errors' after reporting the first.
+
+ return values:
+ OGG_HOLE) recapture (hole in data)
+ 0) need more data
+ 1) page returned
+
+ Returns pointers into buffered data; invalidated by next call to
+ _stream, _clear, _init, or _buffer */
+
+int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
+
+ /* all we need to do is verify a page at the head of the stream
+ buffer. If it doesn't verify, we look for the next potential
+ frame */
+
+ while(1){
+ long ret=ogg_sync_pageseek(oy,og);
+ if(ret>0){
+ /* have a page */
+ return 1;
+ }
+ if(ret==0){
+ /* need more data */
+ return 0;
+ }
+
+ /* head did not start a synced page... skipped some bytes */
+ if(!oy->unsynced){
+ oy->unsynced=1;
+ return OGG_HOLE;
+ }
+
+ /* loop. keep looking */
+
+ }
+}
+
+/* clear things to an initial state. Good to call, eg, before seeking */
+int ogg_sync_reset(ogg_sync_state *oy){
+
+ ogg_buffer_release(oy->fifo_tail);
+ oy->fifo_tail=0;
+ oy->fifo_head=0;
+ oy->fifo_fill=0;
+
+ oy->unsynced=0;
+ oy->headerbytes=0;
+ oy->bodybytes=0;
+ return OGG_SUCCESS;
+}
+
+ogg_stream_state *ogg_stream_create(int serialno){
+ ogg_stream_state *os=_ogg_calloc(1,sizeof(*os));
+ os->serialno=serialno;
+ os->pageno=-1;
+ return os;
+}
+
+int ogg_stream_destroy(ogg_stream_state *os){
+ if(os){
+ ogg_buffer_release(os->header_tail);
+ ogg_buffer_release(os->body_tail);
+ memset(os,0,sizeof(*os));
+ }
+ return OGG_SUCCESS;
+}
+
+
+#define FINFLAG 0x80000000UL
+#define FINMASK 0x7fffffffUL
+
+static void _next_lace(oggbyte_buffer *ob,ogg_stream_state *os){
+ /* search ahead one lace */
+ os->body_fill_next=0;
+ while(os->laceptr<os->lacing_fill){
+ int val=oggbyte_read1(ob,27+os->laceptr++);
+ os->body_fill_next+=val;
+ if(val<255){
+ os->body_fill_next|=FINFLAG;
+ os->clearflag=1;
+ break;
+ }
+ }
+}
+
+static void _span_queued_page(ogg_stream_state *os){
+ while( !(os->body_fill&FINFLAG) ){
+
+ if(!os->header_tail)break;
+
+ /* first flush out preceeding page header (if any). Body is
+ flushed as it's consumed, so that's not done here. */
+
+ if(os->lacing_fill>=0)
+ os->header_tail=ogg_buffer_pretruncate(os->header_tail,
+ os->lacing_fill+27);
+ os->lacing_fill=0;
+ os->laceptr=0;
+ os->clearflag=0;
+
+ if(!os->header_tail){
+ os->header_head=0;
+ break;
+ }else{
+
+ /* process/prepare next page, if any */
+
+ long pageno;
+ oggbyte_buffer ob;
+ ogg_page og; /* only for parsing header values */
+ og.header=os->header_tail; /* only for parsing header values */
+ pageno=ogg_page_pageno(&og);
+
+ oggbyte_init(&ob,os->header_tail);
+ os->lacing_fill=oggbyte_read1(&ob,26);
+
+ /* are we in sequence? */
+ if(pageno!=os->pageno){
+ if(os->pageno==-1) /* indicates seek or reset */
+ os->holeflag=1; /* set for internal use */
+ else
+ os->holeflag=2; /* set for external reporting */
+
+ os->body_tail=ogg_buffer_pretruncate(os->body_tail,
+ os->body_fill);
+ if(os->body_tail==0)os->body_head=0;
+ os->body_fill=0;
+
+ }
+
+ if(ogg_page_continued(&og)){
+ if(os->body_fill==0){
+ /* continued packet, but no preceeding data to continue */
+ /* dump the first partial packet on the page */
+ _next_lace(&ob,os);
+ os->body_tail=
+ ogg_buffer_pretruncate(os->body_tail,os->body_fill_next&FINMASK);
+ if(os->body_tail==0)os->body_head=0;
+ /* set span flag */
+ if(!os->spanflag && !os->holeflag)os->spanflag=2;
+ }
+ }else{
+ if(os->body_fill>0){
+ /* preceeding data to continue, but not a continued page */
+ /* dump body_fill */
+ os->body_tail=ogg_buffer_pretruncate(os->body_tail,
+ os->body_fill);
+ if(os->body_tail==0)os->body_head=0;
+ os->body_fill=0;
+
+ /* set espan flag */
+ if(!os->spanflag && !os->holeflag)os->spanflag=2;
+ }
+ }
+
+ if(os->laceptr<os->lacing_fill){
+ os->granulepos=ogg_page_granulepos(&og);
+
+ /* get current packet size & flag */
+ _next_lace(&ob,os);
+ os->body_fill+=os->body_fill_next; /* addition handles the flag fine;
+ unsigned on purpose */
+ /* ...and next packet size & flag */
+ _next_lace(&ob,os);
+
+ }
+
+ os->pageno=pageno+1;
+ os->e_o_s=ogg_page_eos(&og);
+ os->b_o_s=ogg_page_bos(&og);
+
+ }
+ }
+}
+
+/* add the incoming page to the stream state; we decompose the page
+ into packet segments here as well. */
+
+int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
+
+ int serialno=ogg_page_serialno(og);
+ int version=ogg_page_version(og);
+
+ /* check the serial number */
+ if(serialno!=os->serialno){
+ ogg_page_release(og);
+ return OGG_ESERIAL;
+ }
+ if(version>0){
+ ogg_page_release(og);
+ return OGG_EVERSION;
+ }
+
+ /* add to fifos */
+ if(!os->body_tail){
+ os->body_tail=og->body;
+ os->body_head=ogg_buffer_walk(og->body);
+ }else{
+ os->body_head=ogg_buffer_cat(os->body_head,og->body);
+ }
+ if(!os->header_tail){
+ os->header_tail=og->header;
+ os->header_head=ogg_buffer_walk(og->header);
+ os->lacing_fill=-27;
+ }else{
+ os->header_head=ogg_buffer_cat(os->header_head,og->header);
+ }
+
+ memset(og,0,sizeof(*og));
+ return OGG_SUCCESS;
+}
+
+int ogg_stream_reset(ogg_stream_state *os){
+
+ ogg_buffer_release(os->header_tail);
+ ogg_buffer_release(os->body_tail);
+ os->header_tail=os->header_head=0;
+ os->body_tail=os->body_head=0;
+
+ os->e_o_s=0;
+ os->b_o_s=0;
+ os->pageno=-1;
+ os->packetno=0;
+ os->granulepos=0;
+
+ os->body_fill=0;
+ os->lacing_fill=0;
+
+ os->holeflag=0;
+ os->spanflag=0;
+ os->clearflag=0;
+ os->laceptr=0;
+ os->body_fill_next=0;
+
+ return OGG_SUCCESS;
+}
+
+int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
+ ogg_stream_reset(os);
+ os->serialno=serialno;
+ return OGG_SUCCESS;
+}
+
+static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
+
+ ogg_packet_release(op);
+ _span_queued_page(os);
+
+ if(os->holeflag){
+ int temp=os->holeflag;
+ if(os->clearflag)
+ os->holeflag=0;
+ else
+ os->holeflag=1;
+ if(temp==2){
+ os->packetno++;
+ return OGG_HOLE;
+ }
+ }
+ if(os->spanflag){
+ int temp=os->spanflag;
+ if(os->clearflag)
+ os->spanflag=0;
+ else
+ os->spanflag=1;
+ if(temp==2){
+ os->packetno++;
+ return OGG_SPAN;
+ }
+ }
+
+ if(!(os->body_fill&FINFLAG)) return 0;
+ if(!op && !adv)return 1; /* just using peek as an inexpensive way
+ to ask if there's a whole packet
+ waiting */
+ if(op){
+ op->b_o_s=os->b_o_s;
+ if(os->e_o_s && os->body_fill_next==0)
+ op->e_o_s=os->e_o_s;
+ else
+ op->e_o_s=0;
+ if( (os->body_fill&FINFLAG) && !(os->body_fill_next&FINFLAG) )
+ op->granulepos=os->granulepos;
+ else
+ op->granulepos=-1;
+ op->packetno=os->packetno;
+ }
+
+ if(adv){
+ oggbyte_buffer ob;
+ oggbyte_init(&ob,os->header_tail);
+
+ /* split the body contents off */
+ if(op){
+ op->packet=ogg_buffer_split(&os->body_tail,&os->body_head,
+ os->body_fill&FINMASK);
+ op->bytes=os->body_fill&FINMASK;
+ }else{
+ os->body_tail=ogg_buffer_pretruncate(os->body_tail,
+ os->body_fill&FINMASK);
+ if(os->body_tail==0)os->body_head=0;
+ }
+
+ /* update lacing pointers */
+ os->body_fill=os->body_fill_next;
+ _next_lace(&ob,os);
+ }else{
+ if(op){
+ op->packet=ogg_buffer_sub(os->body_tail,0,os->body_fill&FINMASK);
+ op->bytes=os->body_fill&FINMASK;
+ }
+ }
+
+ if(adv){
+ os->packetno++;
+ os->b_o_s=0;
+ }
+
+ return 1;
+}
+
+int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
+ return _packetout(os,op,1);
+}
+
+int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
+ return _packetout(os,op,0);
+}
+
+int ogg_packet_release(ogg_packet *op) {
+ if(op){
+ ogg_buffer_release(op->packet);
+ memset(op, 0, sizeof(*op));
+ }
+ return OGG_SUCCESS;
+}
+
+int ogg_page_release(ogg_page *og) {
+ if(og){
+ ogg_buffer_release(og->header);
+ ogg_buffer_release(og->body);
+ memset(og, 0, sizeof(*og));
+ }
+ return OGG_SUCCESS;
+}
+
+void ogg_page_dup(ogg_page *dup,ogg_page *orig){
+ dup->header_len=orig->header_len;
+ dup->body_len=orig->body_len;
+ dup->header=ogg_buffer_dup(orig->header);
+ dup->body=ogg_buffer_dup(orig->body);
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/info.c b/osframework/source/SexyAppFramework/ogg/info.c
new file mode 100644
index 0000000..b4d1d2c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/info.c
@@ -0,0 +1,354 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: maintain the info structure, info <-> header packets
+
+ ********************************************************************/
+
+/* general handling of the header and the vorbis_info structure (and
+ substructures) */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "codebook.h"
+#include "registry.h"
+#include "window.h"
+#include "misc.h"
+#include "os.h"
+
+/* helpers */
+static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
+ while(bytes--){
+ *buf++=oggpack_read(o,8);
+ }
+}
+
+void vorbis_comment_init(vorbis_comment *vc){
+ memset(vc,0,sizeof(*vc));
+}
+
+/* This is more or less the same as strncasecmp - but that doesn't exist
+ * everywhere, and this is a fairly trivial function, so we include it */
+static int tagcompare(const char *s1, const char *s2, int n){
+ int c=0;
+ while(c < n){
+ if(toupper(s1[c]) != toupper(s2[c]))
+ return !0;
+ c++;
+ }
+ return 0;
+}
+
+char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
+ long i;
+ int found = 0;
+ int taglen = strlen(tag)+1; /* +1 for the = we append */
+ char *fulltag = (char *)alloca(taglen+ 1);
+
+ strcpy(fulltag, tag);
+ strcat(fulltag, "=");
+
+ for(i=0;i<vc->comments;i++){
+ if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
+ if(count == found)
+ /* We return a pointer to the data, not a copy */
+ return vc->user_comments[i] + taglen;
+ else
+ found++;
+ }
+ }
+ return NULL; /* didn't find anything */
+}
+
+int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
+ int i,count=0;
+ int taglen = strlen(tag)+1; /* +1 for the = we append */
+ char *fulltag = (char *)alloca(taglen+1);
+ strcpy(fulltag,tag);
+ strcat(fulltag, "=");
+
+ for(i=0;i<vc->comments;i++){
+ if(!tagcompare(vc->user_comments[i], fulltag, taglen))
+ count++;
+ }
+
+ return count;
+}
+
+void vorbis_comment_clear(vorbis_comment *vc){
+ if(vc){
+ long i;
+ for(i=0;i<vc->comments;i++)
+ if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
+ if(vc->user_comments)_ogg_free(vc->user_comments);
+ if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
+ if(vc->vendor)_ogg_free(vc->vendor);
+ }
+ memset(vc,0,sizeof(*vc));
+}
+
+/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
+ They may be equal, but short will never ge greater than long */
+int vorbis_info_blocksize(vorbis_info *vi,int zo){
+ codec_setup_info *ci = (codec_setup_info *)vi->codec_setup;
+ return ci ? ci->blocksizes[zo] : -1;
+}
+
+/* used by synthesis, which has a full, alloced vi */
+void vorbis_info_init(vorbis_info *vi){
+ memset(vi,0,sizeof(*vi));
+ vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info));
+}
+
+void vorbis_info_clear(vorbis_info *vi){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ int i;
+
+ if(ci){
+
+ for(i=0;i<ci->modes;i++)
+ if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
+
+ for(i=0;i<ci->maps;i++) /* unpack does the range checking */
+ _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
+
+ for(i=0;i<ci->floors;i++) /* unpack does the range checking */
+ _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
+
+ for(i=0;i<ci->residues;i++) /* unpack does the range checking */
+ _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
+
+ for(i=0;i<ci->books;i++){
+ if(ci->book_param[i]){
+ /* knows if the book was not alloced */
+ vorbis_staticbook_destroy(ci->book_param[i]);
+ }
+ if(ci->fullbooks)
+ vorbis_book_clear(ci->fullbooks+i);
+ }
+ if(ci->fullbooks)
+ _ogg_free(ci->fullbooks);
+
+ _ogg_free(ci);
+ }
+
+ memset(vi,0,sizeof(*vi));
+}
+
+/* Header packing/unpacking ********************************************/
+
+static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ if(!ci)return(OV_EFAULT);
+
+ vi->version=oggpack_read(opb,32);
+ if(vi->version!=0)return(OV_EVERSION);
+
+ vi->channels=oggpack_read(opb,8);
+ vi->rate=oggpack_read(opb,32);
+
+ vi->bitrate_upper=oggpack_read(opb,32);
+ vi->bitrate_nominal=oggpack_read(opb,32);
+ vi->bitrate_lower=oggpack_read(opb,32);
+
+ ci->blocksizes[0]=1<<oggpack_read(opb,4);
+ ci->blocksizes[1]=1<<oggpack_read(opb,4);
+
+ if(vi->rate<1)goto err_out;
+ if(vi->channels<1)goto err_out;
+ if(ci->blocksizes[0]<64)goto err_out;
+ if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
+ if(ci->blocksizes[1]>8192)goto err_out;
+
+ if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
+
+ return(0);
+ err_out:
+ vorbis_info_clear(vi);
+ return(OV_EBADHEADER);
+}
+
+static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
+ int i;
+ int vendorlen=oggpack_read(opb,32);
+ if(vendorlen<0)goto err_out;
+ vc->vendor=(char *)_ogg_calloc(vendorlen+1,1);
+ _v_readstring(opb,vc->vendor,vendorlen);
+ vc->comments=oggpack_read(opb,32);
+ if(vc->comments<0)goto err_out;
+ vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
+ vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
+
+ for(i=0;i<vc->comments;i++){
+ int len=oggpack_read(opb,32);
+ if(len<0)goto err_out;
+ vc->comment_lengths[i]=len;
+ vc->user_comments[i]=(char *)_ogg_calloc(len+1,1);
+ _v_readstring(opb,vc->user_comments[i],len);
+ }
+ if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
+
+ return(0);
+ err_out:
+ vorbis_comment_clear(vc);
+ return(OV_EBADHEADER);
+}
+
+/* all of the real encoding details are here. The modes, books,
+ everything */
+static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ int i;
+ if(!ci)return(OV_EFAULT);
+
+ /* codebooks */
+ ci->books=oggpack_read(opb,8)+1;
+ /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/
+ for(i=0;i<ci->books;i++){
+ ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i]));
+ if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
+ }
+
+ /* time backend settings */
+ ci->times=oggpack_read(opb,6)+1;
+ /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/
+ /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/
+ for(i=0;i<ci->times;i++){
+ ci->time_type[i]=oggpack_read(opb,16);
+ if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out;
+ /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb);
+ Vorbis I has no time backend */
+ /*if(!ci->time_param[i])goto err_out;*/
+ }
+
+ /* floor backend settings */
+ ci->floors=oggpack_read(opb,6)+1;
+ /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/
+ /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/
+ for(i=0;i<ci->floors;i++){
+ ci->floor_type[i]=oggpack_read(opb,16);
+ if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
+ ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
+ if(!ci->floor_param[i])goto err_out;
+ }
+
+ /* residue backend settings */
+ ci->residues=oggpack_read(opb,6)+1;
+ /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/
+ /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/
+ for(i=0;i<ci->residues;i++){
+ ci->residue_type[i]=oggpack_read(opb,16);
+ if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
+ ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
+ if(!ci->residue_param[i])goto err_out;
+ }
+
+ /* map backend settings */
+ ci->maps=oggpack_read(opb,6)+1;
+ /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/
+ /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/
+ for(i=0;i<ci->maps;i++){
+ ci->map_type[i]=oggpack_read(opb,16);
+ if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
+ ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
+ if(!ci->map_param[i])goto err_out;
+ }
+
+ /* mode settings */
+ ci->modes=oggpack_read(opb,6)+1;
+ /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/
+ for(i=0;i<ci->modes;i++){
+ ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
+ ci->mode_param[i]->blockflag=oggpack_read(opb,1);
+ ci->mode_param[i]->windowtype=oggpack_read(opb,16);
+ ci->mode_param[i]->transformtype=oggpack_read(opb,16);
+ ci->mode_param[i]->mapping=oggpack_read(opb,8);
+
+ if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
+ if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
+ if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
+ }
+
+ if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
+
+ return(0);
+ err_out:
+ vorbis_info_clear(vi);
+ return(OV_EBADHEADER);
+}
+
+/* The Vorbis header is in three packets; the initial small packet in
+ the first page that identifies basic parameters, a second packet
+ with bitstream comments and a third packet that holds the
+ codebook. */
+
+int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
+ oggpack_buffer opb;
+
+ if(op){
+ oggpack_readinit(&opb,op->packet);
+
+ /* Which of the three types of header is this? */
+ /* Also verify header-ness, vorbis */
+ {
+ char buffer[6];
+ int packtype=oggpack_read(&opb,8);
+ memset(buffer,0,6);
+ _v_readstring(&opb,buffer,6);
+ if(memcmp(buffer,"vorbis",6)){
+ /* not a vorbis header */
+ return(OV_ENOTVORBIS);
+ }
+ switch(packtype){
+ case 0x01: /* least significant *bit* is read first */
+ if(!op->b_o_s){
+ /* Not the initial packet */
+ return(OV_EBADHEADER);
+ }
+ if(vi->rate!=0){
+ /* previously initialized info header */
+ return(OV_EBADHEADER);
+ }
+
+ return(_vorbis_unpack_info(vi,&opb));
+
+ case 0x03: /* least significant *bit* is read first */
+ if(vi->rate==0){
+ /* um... we didn't get the initial header */
+ return(OV_EBADHEADER);
+ }
+
+ return(_vorbis_unpack_comment(vc,&opb));
+
+ case 0x05: /* least significant *bit* is read first */
+ if(vi->rate==0 || vc->vendor==NULL){
+ /* um... we didn;t get the initial header or comments yet */
+ return(OV_EBADHEADER);
+ }
+
+ return(_vorbis_unpack_books(vi,&opb));
+
+ default:
+ /* Not a valid vorbis header type */
+ return(OV_EBADHEADER);
+ break;
+ }
+ }
+ }
+ return(OV_EBADHEADER);
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/ivorbiscodec.h b/osframework/source/SexyAppFramework/ogg/ivorbiscodec.h
new file mode 100644
index 0000000..b06db9c
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/ivorbiscodec.h
@@ -0,0 +1,202 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: libvorbis codec headers
+
+ ********************************************************************/
+
+#ifndef _vorbis_codec_h_
+#define _vorbis_codec_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include "ogg.h"
+
+typedef struct vorbis_info{
+ int version;
+ int channels;
+ long rate;
+
+ /* The below bitrate declarations are *hints*.
+ Combinations of the three values carry the following implications:
+
+ all three set to the same value:
+ implies a fixed rate bitstream
+ only nominal set:
+ implies a VBR stream that averages the nominal bitrate. No hard
+ upper/lower limit
+ upper and or lower set:
+ implies a VBR bitstream that obeys the bitrate limits. nominal
+ may also be set to give a nominal rate.
+ none set:
+ the coder does not care to speculate.
+ */
+
+ long bitrate_upper;
+ long bitrate_nominal;
+ long bitrate_lower;
+ long bitrate_window;
+
+ void *codec_setup;
+} vorbis_info;
+
+/* vorbis_dsp_state buffers the current vorbis audio
+ analysis/synthesis state. The DSP state belongs to a specific
+ logical bitstream ****************************************************/
+typedef struct vorbis_dsp_state{
+ int analysisp;
+ vorbis_info *vi;
+
+ ogg_int32_t **pcm;
+ ogg_int32_t **pcmret;
+ int pcm_storage;
+ int pcm_current;
+ int pcm_returned;
+
+ int preextrapolate;
+ int eofflag;
+
+ long lW;
+ long W;
+ long nW;
+ long centerW;
+
+ ogg_int64_t granulepos;
+ ogg_int64_t sequence;
+
+ void *backend_state;
+} vorbis_dsp_state;
+
+typedef struct vorbis_block{
+ /* necessary stream state for linking to the framing abstraction */
+ ogg_int32_t **pcm; /* this is a pointer into local storage */
+ oggpack_buffer opb;
+
+ long lW;
+ long W;
+ long nW;
+ int pcmend;
+ int mode;
+
+ int eofflag;
+ ogg_int64_t granulepos;
+ ogg_int64_t sequence;
+ vorbis_dsp_state *vd; /* For read-only access of configuration */
+
+ /* local storage to avoid remallocing; it's up to the mapping to
+ structure it */
+ void *localstore;
+ long localtop;
+ long localalloc;
+ long totaluse;
+ struct alloc_chain *reap;
+
+} vorbis_block;
+
+/* vorbis_block is a single block of data to be processed as part of
+the analysis/synthesis stream; it belongs to a specific logical
+bitstream, but is independant from other vorbis_blocks belonging to
+that logical bitstream. *************************************************/
+
+struct alloc_chain{
+ void *ptr;
+ struct alloc_chain *next;
+};
+
+/* vorbis_info contains all the setup information specific to the
+ specific compression/decompression mode in progress (eg,
+ psychoacoustic settings, channel setup, options, codebook
+ etc). vorbis_info and substructures are in backends.h.
+*********************************************************************/
+
+/* the comments are not part of vorbis_info so that vorbis_info can be
+ static storage */
+typedef struct vorbis_comment{
+ /* unlimited user comment fields. libvorbis writes 'libvorbis'
+ whatever vendor is set to in encode */
+ char **user_comments;
+ int *comment_lengths;
+ int comments;
+ char *vendor;
+
+} vorbis_comment;
+
+
+/* libvorbis encodes in two abstraction layers; first we perform DSP
+ and produce a packet (see docs/analysis.txt). The packet is then
+ coded into a framed OggSquish bitstream by the second layer (see
+ docs/framing.txt). Decode is the reverse process; we sync/frame
+ the bitstream and extract individual packets, then decode the
+ packet back into PCM audio.
+
+ The extra framing/packetizing is used in streaming formats, such as
+ files. Over the net (such as with UDP), the framing and
+ packetization aren't necessary as they're provided by the transport
+ and the streaming layer is not used */
+
+/* Vorbis PRIMITIVES: general ***************************************/
+
+extern void vorbis_info_init(vorbis_info *vi);
+extern void vorbis_info_clear(vorbis_info *vi);
+extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
+extern void vorbis_comment_init(vorbis_comment *vc);
+extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
+extern void vorbis_comment_add_tag(vorbis_comment *vc,
+ char *tag, char *contents);
+extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
+extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
+extern void vorbis_comment_clear(vorbis_comment *vc);
+
+extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
+extern int vorbis_block_clear(vorbis_block *vb);
+extern void vorbis_dsp_clear(vorbis_dsp_state *v);
+
+/* Vorbis PRIMITIVES: synthesis layer *******************************/
+extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
+ ogg_packet *op);
+
+extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
+extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
+extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep);
+extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
+extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm);
+extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
+extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
+
+/* Vorbis ERRORS and return codes ***********************************/
+
+#define OV_FALSE -1
+#define OV_EOF -2
+#define OV_HOLE -3
+
+#define OV_EREAD -128
+#define OV_EFAULT -129
+#define OV_EIMPL -130
+#define OV_EINVAL -131
+#define OV_ENOTVORBIS -132
+#define OV_EBADHEADER -133
+#define OV_EVERSION -134
+#define OV_ENOTAUDIO -135
+#define OV_EBADPACKET -136
+#define OV_EBADLINK -137
+#define OV_ENOSEEK -138
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
diff --git a/osframework/source/SexyAppFramework/ogg/ivorbisfile.h b/osframework/source/SexyAppFramework/ogg/ivorbisfile.h
new file mode 100644
index 0000000..425cb45
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/ivorbisfile.h
@@ -0,0 +1,130 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: stdio-based convenience library for opening/seeking/decoding
+
+ ********************************************************************/
+
+#ifndef _OV_FILE_H_
+#define _OV_FILE_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include <stdio.h>
+#include "ivorbiscodec.h"
+
+#define CHUNKSIZE 1024
+/* The function prototypes for the callbacks are basically the same as for
+ * the stdio functions fread, fseek, fclose, ftell.
+ * The one difference is that the FILE * arguments have been replaced with
+ * a void * - this is to be used as a pointer to whatever internal data these
+ * functions might need. In the stdio case, it's just a FILE * cast to a void *
+ *
+ * If you use other functions, check the docs for these functions and return
+ * the right values. For seek_func(), you *MUST* return -1 if the stream is
+ * unseekable
+ */
+typedef struct {
+ size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
+ int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
+ int (*close_func) (void *datasource);
+ long (*tell_func) (void *datasource);
+} ov_callbacks;
+
+#define NOTOPEN 0
+#define PARTOPEN 1
+#define OPENED 2
+#define STREAMSET 3
+#define INITSET 4
+
+typedef struct OggVorbis_File {
+ void *datasource; /* Pointer to a FILE *, etc. */
+ int seekable;
+ ogg_int64_t offset;
+ ogg_int64_t end;
+ ogg_sync_state *oy;
+
+ /* If the FILE handle isn't seekable (eg, a pipe), only the current
+ stream appears */
+ int links;
+ ogg_int64_t *offsets;
+ ogg_int64_t *dataoffsets;
+ ogg_uint32_t *serialnos;
+ ogg_int64_t *pcmlengths;
+ vorbis_info *vi;
+ vorbis_comment *vc;
+
+ /* Decoding working state local storage */
+ ogg_int64_t pcm_offset;
+ int ready_state;
+ ogg_uint32_t current_serialno;
+ int current_link;
+
+ ogg_int64_t bittrack;
+ ogg_int64_t samptrack;
+
+ ogg_stream_state *os; /* take physical pages, weld into a logical
+ stream of packets */
+ vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+ vorbis_block vb; /* local working space for packet->PCM decode */
+
+ ov_callbacks callbacks;
+
+} OggVorbis_File;
+
+extern int ov_clear(OggVorbis_File *vf);
+extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
+extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
+ char *initial, long ibytes, ov_callbacks callbacks);
+
+extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
+extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
+ char *initial, long ibytes, ov_callbacks callbacks);
+extern int ov_test_open(OggVorbis_File *vf);
+
+extern long ov_bitrate(OggVorbis_File *vf,int i);
+extern long ov_bitrate_instant(OggVorbis_File *vf);
+extern long ov_streams(OggVorbis_File *vf);
+extern long ov_seekable(OggVorbis_File *vf);
+extern long ov_serialnumber(OggVorbis_File *vf,int i);
+
+extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
+extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
+extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i);
+
+extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
+extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
+extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
+extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos);
+extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
+
+extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
+extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
+extern ogg_int64_t ov_time_tell(OggVorbis_File *vf);
+
+extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
+extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
+
+extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
+ int *bitstream);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/lsp_lookup.h b/osframework/source/SexyAppFramework/ogg/lsp_lookup.h
new file mode 100644
index 0000000..067f4c0
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/lsp_lookup.h
@@ -0,0 +1,136 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: lookup data
+
+ ********************************************************************/
+
+#ifndef _V_LOOKUP_DATA_H_
+#define _V_LOOKUP_DATA_H_
+
+#include "os_types.h"
+
+#define FROMdB_LOOKUP_SZ 35
+#define FROMdB2_LOOKUP_SZ 32
+#define FROMdB_SHIFT 5
+#define FROMdB2_SHIFT 3
+#define FROMdB2_MASK 31
+
+static const ogg_int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
+ 0x003fffff, 0x0028619b, 0x00197a96, 0x0010137a,
+ 0x000a24b0, 0x00066666, 0x000409c3, 0x00028c42,
+ 0x00019b8c, 0x000103ab, 0x0000a3d7, 0x00006760,
+ 0x0000413a, 0x00002928, 0x000019f8, 0x00001062,
+ 0x00000a56, 0x00000686, 0x0000041e, 0x00000299,
+ 0x000001a3, 0x00000109, 0x000000a7, 0x00000069,
+ 0x00000042, 0x0000002a, 0x0000001a, 0x00000011,
+ 0x0000000b, 0x00000007, 0x00000004, 0x00000003,
+ 0x00000002, 0x00000001, 0x00000001};
+
+static const ogg_int32_t FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
+ 0x000001fc, 0x000001f5, 0x000001ee, 0x000001e7,
+ 0x000001e0, 0x000001d9, 0x000001d2, 0x000001cc,
+ 0x000001c5, 0x000001bf, 0x000001b8, 0x000001b2,
+ 0x000001ac, 0x000001a6, 0x000001a0, 0x0000019a,
+ 0x00000194, 0x0000018e, 0x00000188, 0x00000183,
+ 0x0000017d, 0x00000178, 0x00000172, 0x0000016d,
+ 0x00000168, 0x00000163, 0x0000015e, 0x00000159,
+ 0x00000154, 0x0000014f, 0x0000014a, 0x00000145,
+};
+
+#define INVSQ_LOOKUP_I_SHIFT 10
+#define INVSQ_LOOKUP_I_MASK 1023
+static const long INVSQ_LOOKUP_I[64+1]={
+ 92682, 91966, 91267, 90583,
+ 89915, 89261, 88621, 87995,
+ 87381, 86781, 86192, 85616,
+ 85051, 84497, 83953, 83420,
+ 82897, 82384, 81880, 81385,
+ 80899, 80422, 79953, 79492,
+ 79039, 78594, 78156, 77726,
+ 77302, 76885, 76475, 76072,
+ 75674, 75283, 74898, 74519,
+ 74146, 73778, 73415, 73058,
+ 72706, 72359, 72016, 71679,
+ 71347, 71019, 70695, 70376,
+ 70061, 69750, 69444, 69141,
+ 68842, 68548, 68256, 67969,
+ 67685, 67405, 67128, 66855,
+ 66585, 66318, 66054, 65794,
+ 65536,
+};
+
+static const long INVSQ_LOOKUP_IDel[64]={
+ 716, 699, 684, 668,
+ 654, 640, 626, 614,
+ 600, 589, 576, 565,
+ 554, 544, 533, 523,
+ 513, 504, 495, 486,
+ 477, 469, 461, 453,
+ 445, 438, 430, 424,
+ 417, 410, 403, 398,
+ 391, 385, 379, 373,
+ 368, 363, 357, 352,
+ 347, 343, 337, 332,
+ 328, 324, 319, 315,
+ 311, 306, 303, 299,
+ 294, 292, 287, 284,
+ 280, 277, 273, 270,
+ 267, 264, 260, 258,
+};
+
+#define COS_LOOKUP_I_SHIFT 9
+#define COS_LOOKUP_I_MASK 511
+#define COS_LOOKUP_I_SZ 128
+static const ogg_int32_t COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
+ 16384, 16379, 16364, 16340,
+ 16305, 16261, 16207, 16143,
+ 16069, 15986, 15893, 15791,
+ 15679, 15557, 15426, 15286,
+ 15137, 14978, 14811, 14635,
+ 14449, 14256, 14053, 13842,
+ 13623, 13395, 13160, 12916,
+ 12665, 12406, 12140, 11866,
+ 11585, 11297, 11003, 10702,
+ 10394, 10080, 9760, 9434,
+ 9102, 8765, 8423, 8076,
+ 7723, 7366, 7005, 6639,
+ 6270, 5897, 5520, 5139,
+ 4756, 4370, 3981, 3590,
+ 3196, 2801, 2404, 2006,
+ 1606, 1205, 804, 402,
+ 0, -401, -803, -1204,
+ -1605, -2005, -2403, -2800,
+ -3195, -3589, -3980, -4369,
+ -4755, -5138, -5519, -5896,
+ -6269, -6638, -7004, -7365,
+ -7722, -8075, -8422, -8764,
+ -9101, -9433, -9759, -10079,
+ -10393, -10701, -11002, -11296,
+ -11584, -11865, -12139, -12405,
+ -12664, -12915, -13159, -13394,
+ -13622, -13841, -14052, -14255,
+ -14448, -14634, -14810, -14977,
+ -15136, -15285, -15425, -15556,
+ -15678, -15790, -15892, -15985,
+ -16068, -16142, -16206, -16260,
+ -16304, -16339, -16363, -16378,
+ -16383,
+};
+
+#endif
+
+
+
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/mapping0.c b/osframework/source/SexyAppFramework/ogg/mapping0.c
new file mode 100644
index 0000000..4752574
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/mapping0.c
@@ -0,0 +1,322 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: channel mapping 0 implementation
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "mdct.h"
+#include "codec_internal.h"
+#include "codebook.h"
+#include "window.h"
+#include "registry.h"
+#include "misc.h"
+
+/* simplistic, wasteful way of doing this (unique lookup for each
+ mode/submapping); there should be a central repository for
+ identical lookups. That will require minor work, so I'm putting it
+ off as low priority.
+
+ Why a lookup for each backend in a given mode? Because the
+ blocksize is set by the mode, and low backend lookups may require
+ parameters from other areas of the mode/mapping */
+
+typedef struct {
+ vorbis_info_mode *mode;
+ vorbis_info_mapping0 *map;
+
+ vorbis_look_floor **floor_look;
+
+ vorbis_look_residue **residue_look;
+
+ vorbis_func_floor **floor_func;
+ vorbis_func_residue **residue_func;
+
+ int ch;
+ long lastframe; /* if a different mode is called, we need to
+ invalidate decay */
+} vorbis_look_mapping0;
+
+static void mapping0_free_info(vorbis_info_mapping *i){
+ vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
+ if(info){
+ memset(info,0,sizeof(*info));
+ _ogg_free(info);
+ }
+}
+
+static void mapping0_free_look(vorbis_look_mapping *look){
+ int i;
+ vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look;
+ if(l){
+
+ for(i=0;i<l->map->submaps;i++){
+ l->floor_func[i]->free_look(l->floor_look[i]);
+ l->residue_func[i]->free_look(l->residue_look[i]);
+ }
+
+ _ogg_free(l->floor_func);
+ _ogg_free(l->residue_func);
+ _ogg_free(l->floor_look);
+ _ogg_free(l->residue_look);
+ memset(l,0,sizeof(*l));
+ _ogg_free(l);
+ }
+}
+
+static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
+ vorbis_info_mapping *m){
+ int i;
+ vorbis_info *vi=vd->vi;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look));
+ vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m;
+ look->mode=vm;
+
+ look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look));
+
+ look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look));
+
+ look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func));
+ look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func));
+
+ for(i=0;i<info->submaps;i++){
+ int floornum=info->floorsubmap[i];
+ int resnum=info->residuesubmap[i];
+
+ look->floor_func[i]=_floor_P[ci->floor_type[floornum]];
+ look->floor_look[i]=look->floor_func[i]->
+ look(vd,vm,ci->floor_param[floornum]);
+ look->residue_func[i]=_residue_P[ci->residue_type[resnum]];
+ look->residue_look[i]=look->residue_func[i]->
+ look(vd,vm,ci->residue_param[resnum]);
+
+ }
+
+ look->ch=vi->channels;
+
+ return(look);
+}
+
+static int ilog(unsigned int v){
+ int ret=0;
+ if(v)--v;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+/* also responsible for range checking */
+static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
+ int i;
+ vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info));
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ memset(info,0,sizeof(*info));
+
+ if(oggpack_read(opb,1))
+ info->submaps=oggpack_read(opb,4)+1;
+ else
+ info->submaps=1;
+
+ if(oggpack_read(opb,1)){
+ info->coupling_steps=oggpack_read(opb,8)+1;
+
+ for(i=0;i<info->coupling_steps;i++){
+ int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels));
+ int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels));
+
+ if(testM<0 ||
+ testA<0 ||
+ testM==testA ||
+ testM>=vi->channels ||
+ testA>=vi->channels) goto err_out;
+ }
+
+ }
+
+ if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
+
+ if(info->submaps>1){
+ for(i=0;i<vi->channels;i++){
+ info->chmuxlist[i]=oggpack_read(opb,4);
+ if(info->chmuxlist[i]>=info->submaps)goto err_out;
+ }
+ }
+ for(i=0;i<info->submaps;i++){
+ int temp=oggpack_read(opb,8);
+ if(temp>=ci->times)goto err_out;
+ info->floorsubmap[i]=oggpack_read(opb,8);
+ if(info->floorsubmap[i]>=ci->floors)goto err_out;
+ info->residuesubmap[i]=oggpack_read(opb,8);
+ if(info->residuesubmap[i]>=ci->residues)goto err_out;
+ }
+
+ return info;
+
+ err_out:
+ mapping0_free_info(info);
+ return(NULL);
+}
+
+static int seq=0;
+static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
+ vorbis_dsp_state *vd=vb->vd;
+ vorbis_info *vi=vd->vi;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ private_state *b=(private_state *)vd->backend_state;
+ vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
+ vorbis_info_mapping0 *info=look->map;
+
+ int i,j;
+ long n=vb->pcmend=ci->blocksizes[vb->W];
+
+ ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels);
+ int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels);
+
+ int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels);
+ void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels);
+
+ /* time domain information decode (note that applying the
+ information would have to happen later; we'll probably add a
+ function entry to the harness for that later */
+ /* NOT IMPLEMENTED */
+
+ /* recover the spectral envelope; store it in the PCM vector for now */
+ for(i=0;i<vi->channels;i++){
+ int submap=info->chmuxlist[i];
+ floormemo[i]=look->floor_func[submap]->
+ inverse1(vb,look->floor_look[submap]);
+ if(floormemo[i])
+ nonzero[i]=1;
+ else
+ nonzero[i]=0;
+ memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
+ }
+
+ /* channel coupling can 'dirty' the nonzero listing */
+ for(i=0;i<info->coupling_steps;i++){
+ if(nonzero[info->coupling_mag[i]] ||
+ nonzero[info->coupling_ang[i]]){
+ nonzero[info->coupling_mag[i]]=1;
+ nonzero[info->coupling_ang[i]]=1;
+ }
+ }
+
+ /* recover the residue into our working vectors */
+ for(i=0;i<info->submaps;i++){
+ int ch_in_bundle=0;
+ for(j=0;j<vi->channels;j++){
+ if(info->chmuxlist[j]==i){
+ if(nonzero[j])
+ zerobundle[ch_in_bundle]=1;
+ else
+ zerobundle[ch_in_bundle]=0;
+ pcmbundle[ch_in_bundle++]=vb->pcm[j];
+ }
+ }
+
+ look->residue_func[i]->inverse(vb,look->residue_look[i],
+ pcmbundle,zerobundle,ch_in_bundle);
+ }
+
+ //for(j=0;j<vi->channels;j++)
+ //_analysis_output("coupled",seq+j,vb->pcm[j],-8,n/2,0,0);
+
+
+ /* channel coupling */
+ for(i=info->coupling_steps-1;i>=0;i--){
+ ogg_int32_t *pcmM=vb->pcm[info->coupling_mag[i]];
+ ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]];
+
+ for(j=0;j<n/2;j++){
+ ogg_int32_t mag=pcmM[j];
+ ogg_int32_t ang=pcmA[j];
+
+ if(mag>0)
+ if(ang>0){
+ pcmM[j]=mag;
+ pcmA[j]=mag-ang;
+ }else{
+ pcmA[j]=mag;
+ pcmM[j]=mag+ang;
+ }
+ else
+ if(ang>0){
+ pcmM[j]=mag;
+ pcmA[j]=mag+ang;
+ }else{
+ pcmA[j]=mag;
+ pcmM[j]=mag-ang;
+ }
+ }
+ }
+
+ //for(j=0;j<vi->channels;j++)
+ //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0);
+
+ /* compute and apply spectral envelope */
+ for(i=0;i<vi->channels;i++){
+ ogg_int32_t *pcm=vb->pcm[i];
+ int submap=info->chmuxlist[i];
+ look->floor_func[submap]->
+ inverse2(vb,look->floor_look[submap],floormemo[i],pcm);
+ }
+
+ //for(j=0;j<vi->channels;j++)
+ //_analysis_output("mdct",seq+j,vb->pcm[j],-24,n/2,0,1);
+
+ /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
+ /* only MDCT right now.... */
+ for(i=0;i<vi->channels;i++){
+ ogg_int32_t *pcm=vb->pcm[i];
+ mdct_backward(n,pcm,pcm);
+ }
+
+ //for(j=0;j<vi->channels;j++)
+ //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0);
+
+ /* window the data */
+ for(i=0;i<vi->channels;i++){
+ ogg_int32_t *pcm=vb->pcm[i];
+ if(nonzero[i])
+ _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
+ else
+ for(j=0;j<n;j++)
+ pcm[j]=0;
+
+ }
+
+ //for(j=0;j<vi->channels;j++)
+ //_analysis_output("window",seq+j,vb->pcm[j],-24,n,0,0);
+
+ seq+=vi->channels;
+ /* all done! */
+ return(0);
+}
+
+/* export hooks */
+vorbis_func_mapping mapping0_exportbundle={
+ &mapping0_unpack,
+ &mapping0_look,
+ &mapping0_free_info,
+ &mapping0_free_look,
+ &mapping0_inverse
+};
diff --git a/osframework/source/SexyAppFramework/ogg/mdct.c b/osframework/source/SexyAppFramework/ogg/mdct.c
new file mode 100644
index 0000000..4b96d12
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/mdct.c
@@ -0,0 +1,510 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: normalized modified discrete cosine transform
+ power of two length transform only [64 <= n ]
+ last mod: $Id: mdct.c,v 1.1 2003/06/24 00:46:01 ace Exp $
+
+ Original algorithm adapted long ago from _The use of multirate filter
+ banks for coding of high quality digital audio_, by T. Sporer,
+ K. Brandenburg and B. Edler, collection of the European Signal
+ Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp
+ 211-214
+
+ The below code implements an algorithm that no longer looks much like
+ that presented in the paper, but the basic structure remains if you
+ dig deep enough to see it.
+
+ This module DOES NOT INCLUDE code to generate/apply the window
+ function. Everybody has their own weird favorite including me... I
+ happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
+ vehemently disagree.
+
+ ********************************************************************/
+
+#include "ivorbiscodec.h"
+#include "os.h"
+#include "misc.h"
+#include "mdct.h"
+#include "mdct_lookup.h"
+
+
+/* 8 point butterfly (in place) */
+STIN void mdct_butterfly_8(DATA_TYPE *x){
+
+ REG_TYPE r0 = x[4] + x[0];
+ REG_TYPE r1 = x[4] - x[0];
+ REG_TYPE r2 = x[5] + x[1];
+ REG_TYPE r3 = x[5] - x[1];
+ REG_TYPE r4 = x[6] + x[2];
+ REG_TYPE r5 = x[6] - x[2];
+ REG_TYPE r6 = x[7] + x[3];
+ REG_TYPE r7 = x[7] - x[3];
+
+ x[0] = r5 + r3;
+ x[1] = r7 - r1;
+ x[2] = r5 - r3;
+ x[3] = r7 + r1;
+ x[4] = r4 - r0;
+ x[5] = r6 - r2;
+ x[6] = r4 + r0;
+ x[7] = r6 + r2;
+ MB();
+}
+
+/* 16 point butterfly (in place, 4 register) */
+STIN void mdct_butterfly_16(DATA_TYPE *x){
+
+ REG_TYPE r0, r1;
+
+ r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0];
+ r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1];
+ x[ 0] = MULT31((r0 + r1) , cPI2_8);
+ x[ 1] = MULT31((r1 - r0) , cPI2_8);
+ MB();
+
+ r0 = x[10] - x[ 2]; x[10] += x[ 2];
+ r1 = x[ 3] - x[11]; x[11] += x[ 3];
+ x[ 2] = r1; x[ 3] = r0;
+ MB();
+
+ r0 = x[12] - x[ 4]; x[12] += x[ 4];
+ r1 = x[13] - x[ 5]; x[13] += x[ 5];
+ x[ 4] = MULT31((r0 - r1) , cPI2_8);
+ x[ 5] = MULT31((r0 + r1) , cPI2_8);
+ MB();
+
+ r0 = x[14] - x[ 6]; x[14] += x[ 6];
+ r1 = x[15] - x[ 7]; x[15] += x[ 7];
+ x[ 6] = r0; x[ 7] = r1;
+ MB();
+
+ mdct_butterfly_8(x);
+ mdct_butterfly_8(x+8);
+}
+
+/* 32 point butterfly (in place, 4 register) */
+STIN void mdct_butterfly_32(DATA_TYPE *x){
+
+ REG_TYPE r0, r1;
+
+ r0 = x[30] - x[14]; x[30] += x[14];
+ r1 = x[31] - x[15]; x[31] += x[15];
+ x[14] = r0; x[15] = r1;
+ MB();
+
+ r0 = x[28] - x[12]; x[28] += x[12];
+ r1 = x[29] - x[13]; x[29] += x[13];
+ XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] );
+ MB();
+
+ r0 = x[26] - x[10]; x[26] += x[10];
+ r1 = x[27] - x[11]; x[27] += x[11];
+ x[10] = MULT31((r0 - r1) , cPI2_8);
+ x[11] = MULT31((r0 + r1) , cPI2_8);
+ MB();
+
+ r0 = x[24] - x[ 8]; x[24] += x[ 8];
+ r1 = x[25] - x[ 9]; x[25] += x[ 9];
+ XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] );
+ MB();
+
+ r0 = x[22] - x[ 6]; x[22] += x[ 6];
+ r1 = x[ 7] - x[23]; x[23] += x[ 7];
+ x[ 6] = r1; x[ 7] = r0;
+ MB();
+
+ r0 = x[ 4] - x[20]; x[20] += x[ 4];
+ r1 = x[ 5] - x[21]; x[21] += x[ 5];
+ XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] );
+ MB();
+
+ r0 = x[ 2] - x[18]; x[18] += x[ 2];
+ r1 = x[ 3] - x[19]; x[19] += x[ 3];
+ x[ 2] = MULT31((r1 + r0) , cPI2_8);
+ x[ 3] = MULT31((r1 - r0) , cPI2_8);
+ MB();
+
+ r0 = x[ 0] - x[16]; x[16] += x[ 0];
+ r1 = x[ 1] - x[17]; x[17] += x[ 1];
+ XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] );
+ MB();
+
+ mdct_butterfly_16(x);
+ mdct_butterfly_16(x+16);
+}
+
+/* N/stage point generic N stage butterfly (in place, 2 register) */
+STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){
+
+ LOOKUP_T *T = sincos_lookup0;
+ DATA_TYPE *x1 = x + points - 8;
+ DATA_TYPE *x2 = x + (points>>1) - 8;
+ REG_TYPE r0;
+ REG_TYPE r1;
+
+ do{
+ r0 = x1[6] - x2[6]; x1[6] += x2[6];
+ r1 = x2[7] - x1[7]; x1[7] += x2[7];
+ XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step;
+
+ r0 = x1[4] - x2[4]; x1[4] += x2[4];
+ r1 = x2[5] - x1[5]; x1[5] += x2[5];
+ XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step;
+
+ r0 = x1[2] - x2[2]; x1[2] += x2[2];
+ r1 = x2[3] - x1[3]; x1[3] += x2[3];
+ XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step;
+
+ r0 = x1[0] - x2[0]; x1[0] += x2[0];
+ r1 = x2[1] - x1[1]; x1[1] += x2[1];
+ XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step;
+
+ x1-=8; x2-=8;
+ }while(T<sincos_lookup0+1024);
+ do{
+ r0 = x1[6] - x2[6]; x1[6] += x2[6];
+ r1 = x1[7] - x2[7]; x1[7] += x2[7];
+ XNPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T-=step;
+
+ r0 = x1[4] - x2[4]; x1[4] += x2[4];
+ r1 = x1[5] - x2[5]; x1[5] += x2[5];
+ XNPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T-=step;
+
+ r0 = x1[2] - x2[2]; x1[2] += x2[2];
+ r1 = x1[3] - x2[3]; x1[3] += x2[3];
+ XNPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T-=step;
+
+ r0 = x1[0] - x2[0]; x1[0] += x2[0];
+ r1 = x1[1] - x2[1]; x1[1] += x2[1];
+ XNPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T-=step;
+
+ x1-=8; x2-=8;
+ }while(T>sincos_lookup0);
+ do{
+ r0 = x2[6] - x1[6]; x1[6] += x2[6];
+ r1 = x2[7] - x1[7]; x1[7] += x2[7];
+ XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step;
+
+ r0 = x2[4] - x1[4]; x1[4] += x2[4];
+ r1 = x2[5] - x1[5]; x1[5] += x2[5];
+ XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step;
+
+ r0 = x2[2] - x1[2]; x1[2] += x2[2];
+ r1 = x2[3] - x1[3]; x1[3] += x2[3];
+ XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step;
+
+ r0 = x2[0] - x1[0]; x1[0] += x2[0];
+ r1 = x2[1] - x1[1]; x1[1] += x2[1];
+ XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step;
+
+ x1-=8; x2-=8;
+ }while(T<sincos_lookup0+1024);
+ do{
+ r0 = x1[6] - x2[6]; x1[6] += x2[6];
+ r1 = x2[7] - x1[7]; x1[7] += x2[7];
+ XNPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T-=step;
+
+ r0 = x1[4] - x2[4]; x1[4] += x2[4];
+ r1 = x2[5] - x1[5]; x1[5] += x2[5];
+ XNPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T-=step;
+
+ r0 = x1[2] - x2[2]; x1[2] += x2[2];
+ r1 = x2[3] - x1[3]; x1[3] += x2[3];
+ XNPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T-=step;
+
+ r0 = x1[0] - x2[0]; x1[0] += x2[0];
+ r1 = x2[1] - x1[1]; x1[1] += x2[1];
+ XNPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T-=step;
+
+ x1-=8; x2-=8;
+ }while(T>sincos_lookup0);
+}
+
+STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){
+
+ int stages=8-shift;
+ int i,j;
+
+ for(i=0;--stages>0;i++){
+ for(j=0;j<(1<<i);j++)
+ mdct_butterfly_generic(x+(points>>i)*j,points>>i,4<<(i+shift));
+ }
+
+ for(j=0;j<points;j+=32)
+ mdct_butterfly_32(x+j);
+
+}
+
+static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
+
+STIN int bitrev12(int x){
+ return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8);
+}
+
+STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){
+
+ int bit = 0;
+ DATA_TYPE *w0 = x;
+ DATA_TYPE *w1 = x = w0+(n>>1);
+ LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
+ LOOKUP_T *Ttop = T+1024;
+ DATA_TYPE r2;
+
+ do{
+ DATA_TYPE r3 = bitrev12(bit++);
+ DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
+ DATA_TYPE *x1 = x + (r3>>shift);
+
+ REG_TYPE r0 = x0[0] + x1[0];
+ REG_TYPE r1 = x1[1] - x0[1];
+
+ XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
+
+ w1 -= 4;
+
+ r0 = (x0[1] + x1[1])>>1;
+ r1 = (x0[0] - x1[0])>>1;
+ w0[0] = r0 + r2;
+ w0[1] = r1 + r3;
+ w1[2] = r0 - r2;
+ w1[3] = r3 - r1;
+
+ r3 = bitrev12(bit++);
+ x0 = x + ((r3 ^ 0xfff)>>shift) -1;
+ x1 = x + (r3>>shift);
+
+ r0 = x0[0] + x1[0];
+ r1 = x1[1] - x0[1];
+
+ XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
+
+ r0 = (x0[1] + x1[1])>>1;
+ r1 = (x0[0] - x1[0])>>1;
+ w0[2] = r0 + r2;
+ w0[3] = r1 + r3;
+ w1[0] = r0 - r2;
+ w1[1] = r3 - r1;
+
+ w0 += 4;
+ }while(T<Ttop);
+ do{
+ DATA_TYPE r3 = bitrev12(bit++);
+ DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
+ DATA_TYPE *x1 = x + (r3>>shift);
+
+ REG_TYPE r0 = x0[0] + x1[0];
+ REG_TYPE r1 = x1[1] - x0[1];
+
+ T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
+
+ w1 -= 4;
+
+ r0 = (x0[1] + x1[1])>>1;
+ r1 = (x0[0] - x1[0])>>1;
+ w0[0] = r0 + r2;
+ w0[1] = r1 + r3;
+ w1[2] = r0 - r2;
+ w1[3] = r3 - r1;
+
+ r3 = bitrev12(bit++);
+ x0 = x + ((r3 ^ 0xfff)>>shift) -1;
+ x1 = x + (r3>>shift);
+
+ r0 = x0[0] + x1[0];
+ r1 = x1[1] - x0[1];
+
+ T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
+
+ r0 = (x0[1] + x1[1])>>1;
+ r1 = (x0[0] - x1[0])>>1;
+ w0[2] = r0 + r2;
+ w0[3] = r1 + r3;
+ w1[0] = r0 - r2;
+ w1[1] = r3 - r1;
+
+ w0 += 4;
+ }while(w0<w1);
+}
+
+void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out){
+ int n2=n>>1;
+ int n4=n>>2;
+ DATA_TYPE *iX;
+ DATA_TYPE *oX;
+ LOOKUP_T *T;
+ LOOKUP_T *V;
+ int shift;
+ int step;
+
+ for (shift=6;!(n&(1<<shift));shift++);
+ shift=13-shift;
+ step=2<<shift;
+
+ /* rotate */
+
+ iX = in+n2-7;
+ oX = out+n2+n4;
+ T = sincos_lookup0;
+
+ do{
+ oX-=4;
+ XPROD31( iX[4], iX[6], T[0], T[1], &oX[2], &oX[3] ); T+=step;
+ XPROD31( iX[0], iX[2], T[0], T[1], &oX[0], &oX[1] ); T+=step;
+ iX-=8;
+ }while(iX>=in+n4);
+ do{
+ oX-=4;
+ XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step;
+ XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step;
+ iX-=8;
+ }while(iX>=in);
+
+ iX = in+n2-8;
+ oX = out+n2+n4;
+ T = sincos_lookup0;
+
+ do{
+ T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] );
+ T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] );
+ iX-=8;
+ oX+=4;
+ }while(iX>=in+n4);
+ do{
+ T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] );
+ T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] );
+ iX-=8;
+ oX+=4;
+ }while(iX>=in);
+
+ mdct_butterflies(out+n2,n2,shift);
+ mdct_bitreverse(out,n,step,shift);
+
+ /* rotate + window */
+
+ step>>=2;
+ {
+ DATA_TYPE *oX1=out+n2+n4;
+ DATA_TYPE *oX2=out+n2+n4;
+ DATA_TYPE *iX =out;
+
+ switch(step) {
+ default: {
+ T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
+ do{
+ oX1-=4;
+ XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step;
+ XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step;
+ XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step;
+ XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step;
+ oX2+=4;
+ iX+=8;
+ }while(iX<oX1);
+ break;
+ }
+
+ case 1: {
+ /* linear interpolation between table values: offset=0.5, step=1 */
+ REG_TYPE t0,t1,v0,v1;
+ T = sincos_lookup0;
+ V = sincos_lookup1;
+ t0 = (*T++)>>1;
+ t1 = (*T++)>>1;
+ do{
+ oX1-=4;
+
+ t0 += (v0 = (*V++)>>1);
+ t1 += (v1 = (*V++)>>1);
+ XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
+ v0 += (t0 = (*T++)>>1);
+ v1 += (t1 = (*T++)>>1);
+ XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] );
+ t0 += (v0 = (*V++)>>1);
+ t1 += (v1 = (*V++)>>1);
+ XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] );
+ v0 += (t0 = (*T++)>>1);
+ v1 += (t1 = (*T++)>>1);
+ XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
+
+ oX2+=4;
+ iX+=8;
+ }while(iX<oX1);
+ break;
+ }
+
+ case 0: {
+ /* linear interpolation between table values: offset=0.25, step=0.5 */
+ REG_TYPE t0,t1,v0,v1,q0,q1;
+ T = sincos_lookup0;
+ V = sincos_lookup1;
+ t0 = *T++;
+ t1 = *T++;
+ do{
+ oX1-=4;
+
+ v0 = *V++;
+ v1 = *V++;
+ t0 += (q0 = (v0-t0)>>2);
+ t1 += (q1 = (v1-t1)>>2);
+ XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
+ t0 = v0-q0;
+ t1 = v1-q1;
+ XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] );
+
+ t0 = *T++;
+ t1 = *T++;
+ v0 += (q0 = (t0-v0)>>2);
+ v1 += (q1 = (t1-v1)>>2);
+ XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] );
+ v0 = t0-q0;
+ v1 = t1-q1;
+ XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
+
+ oX2+=4;
+ iX+=8;
+ }while(iX<oX1);
+ break;
+ }
+ }
+
+ iX=out+n2+n4;
+ oX1=out+n4;
+ oX2=oX1;
+
+ do{
+ oX1-=4;
+ iX-=4;
+
+ oX2[0] = -(oX1[3] = iX[3]);
+ oX2[1] = -(oX1[2] = iX[2]);
+ oX2[2] = -(oX1[1] = iX[1]);
+ oX2[3] = -(oX1[0] = iX[0]);
+
+ oX2+=4;
+ }while(oX2<iX);
+
+ iX=out+n2+n4;
+ oX1=out+n2+n4;
+ oX2=out+n2;
+
+ do{
+ oX1-=4;
+ oX1[0]= iX[3];
+ oX1[1]= iX[2];
+ oX1[2]= iX[1];
+ oX1[3]= iX[0];
+ iX+=4;
+ }while(oX1>oX2);
+ }
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/mdct.h b/osframework/source/SexyAppFramework/ogg/mdct.h
new file mode 100644
index 0000000..d88d796
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/mdct.h
@@ -0,0 +1,52 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: modified discrete cosine transform prototypes
+
+ ********************************************************************/
+
+#ifndef _OGG_mdct_H_
+#define _OGG_mdct_H_
+
+#include "ivorbiscodec.h"
+#include "misc.h"
+
+#define DATA_TYPE ogg_int32_t
+#define REG_TYPE register ogg_int32_t
+
+#ifdef _LOW_ACCURACY_
+#define cPI3_8 (0x0062)
+#define cPI2_8 (0x00b5)
+#define cPI1_8 (0x00ed)
+#else
+#define cPI3_8 (0x30fbc54d)
+#define cPI2_8 (0x5a82799a)
+#define cPI1_8 (0x7641af3d)
+#endif
+
+extern void mdct_forward(int n, DATA_TYPE *in, DATA_TYPE *out);
+extern void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out);
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/mdct_lookup.h b/osframework/source/SexyAppFramework/ogg/mdct_lookup.h
new file mode 100644
index 0000000..7c548e0
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/mdct_lookup.h
@@ -0,0 +1,540 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: sin,cos lookup tables
+
+ ********************************************************************/
+
+#include "os_types.h"
+
+/* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */
+static LOOKUP_T sincos_lookup0[1026] = {
+ X(0x00000000), X(0x7fffffff), X(0x003243f5), X(0x7ffff621),
+ X(0x006487e3), X(0x7fffd886), X(0x0096cbc1), X(0x7fffa72c),
+ X(0x00c90f88), X(0x7fff6216), X(0x00fb5330), X(0x7fff0943),
+ X(0x012d96b1), X(0x7ffe9cb2), X(0x015fda03), X(0x7ffe1c65),
+ X(0x01921d20), X(0x7ffd885a), X(0x01c45ffe), X(0x7ffce093),
+ X(0x01f6a297), X(0x7ffc250f), X(0x0228e4e2), X(0x7ffb55ce),
+ X(0x025b26d7), X(0x7ffa72d1), X(0x028d6870), X(0x7ff97c18),
+ X(0x02bfa9a4), X(0x7ff871a2), X(0x02f1ea6c), X(0x7ff75370),
+ X(0x03242abf), X(0x7ff62182), X(0x03566a96), X(0x7ff4dbd9),
+ X(0x0388a9ea), X(0x7ff38274), X(0x03bae8b2), X(0x7ff21553),
+ X(0x03ed26e6), X(0x7ff09478), X(0x041f6480), X(0x7feeffe1),
+ X(0x0451a177), X(0x7fed5791), X(0x0483ddc3), X(0x7feb9b85),
+ X(0x04b6195d), X(0x7fe9cbc0), X(0x04e8543e), X(0x7fe7e841),
+ X(0x051a8e5c), X(0x7fe5f108), X(0x054cc7b1), X(0x7fe3e616),
+ X(0x057f0035), X(0x7fe1c76b), X(0x05b137df), X(0x7fdf9508),
+ X(0x05e36ea9), X(0x7fdd4eec), X(0x0615a48b), X(0x7fdaf519),
+ X(0x0647d97c), X(0x7fd8878e), X(0x067a0d76), X(0x7fd6064c),
+ X(0x06ac406f), X(0x7fd37153), X(0x06de7262), X(0x7fd0c8a3),
+ X(0x0710a345), X(0x7fce0c3e), X(0x0742d311), X(0x7fcb3c23),
+ X(0x077501be), X(0x7fc85854), X(0x07a72f45), X(0x7fc560cf),
+ X(0x07d95b9e), X(0x7fc25596), X(0x080b86c2), X(0x7fbf36aa),
+ X(0x083db0a7), X(0x7fbc040a), X(0x086fd947), X(0x7fb8bdb8),
+ X(0x08a2009a), X(0x7fb563b3), X(0x08d42699), X(0x7fb1f5fc),
+ X(0x09064b3a), X(0x7fae7495), X(0x09386e78), X(0x7faadf7c),
+ X(0x096a9049), X(0x7fa736b4), X(0x099cb0a7), X(0x7fa37a3c),
+ X(0x09cecf89), X(0x7f9faa15), X(0x0a00ece8), X(0x7f9bc640),
+ X(0x0a3308bd), X(0x7f97cebd), X(0x0a6522fe), X(0x7f93c38c),
+ X(0x0a973ba5), X(0x7f8fa4b0), X(0x0ac952aa), X(0x7f8b7227),
+ X(0x0afb6805), X(0x7f872bf3), X(0x0b2d7baf), X(0x7f82d214),
+ X(0x0b5f8d9f), X(0x7f7e648c), X(0x0b919dcf), X(0x7f79e35a),
+ X(0x0bc3ac35), X(0x7f754e80), X(0x0bf5b8cb), X(0x7f70a5fe),
+ X(0x0c27c389), X(0x7f6be9d4), X(0x0c59cc68), X(0x7f671a05),
+ X(0x0c8bd35e), X(0x7f62368f), X(0x0cbdd865), X(0x7f5d3f75),
+ X(0x0cefdb76), X(0x7f5834b7), X(0x0d21dc87), X(0x7f531655),
+ X(0x0d53db92), X(0x7f4de451), X(0x0d85d88f), X(0x7f489eaa),
+ X(0x0db7d376), X(0x7f434563), X(0x0de9cc40), X(0x7f3dd87c),
+ X(0x0e1bc2e4), X(0x7f3857f6), X(0x0e4db75b), X(0x7f32c3d1),
+ X(0x0e7fa99e), X(0x7f2d1c0e), X(0x0eb199a4), X(0x7f2760af),
+ X(0x0ee38766), X(0x7f2191b4), X(0x0f1572dc), X(0x7f1baf1e),
+ X(0x0f475bff), X(0x7f15b8ee), X(0x0f7942c7), X(0x7f0faf25),
+ X(0x0fab272b), X(0x7f0991c4), X(0x0fdd0926), X(0x7f0360cb),
+ X(0x100ee8ad), X(0x7efd1c3c), X(0x1040c5bb), X(0x7ef6c418),
+ X(0x1072a048), X(0x7ef05860), X(0x10a4784b), X(0x7ee9d914),
+ X(0x10d64dbd), X(0x7ee34636), X(0x11082096), X(0x7edc9fc6),
+ X(0x1139f0cf), X(0x7ed5e5c6), X(0x116bbe60), X(0x7ecf1837),
+ X(0x119d8941), X(0x7ec8371a), X(0x11cf516a), X(0x7ec14270),
+ X(0x120116d5), X(0x7eba3a39), X(0x1232d979), X(0x7eb31e78),
+ X(0x1264994e), X(0x7eabef2c), X(0x1296564d), X(0x7ea4ac58),
+ X(0x12c8106f), X(0x7e9d55fc), X(0x12f9c7aa), X(0x7e95ec1a),
+ X(0x132b7bf9), X(0x7e8e6eb2), X(0x135d2d53), X(0x7e86ddc6),
+ X(0x138edbb1), X(0x7e7f3957), X(0x13c0870a), X(0x7e778166),
+ X(0x13f22f58), X(0x7e6fb5f4), X(0x1423d492), X(0x7e67d703),
+ X(0x145576b1), X(0x7e5fe493), X(0x148715ae), X(0x7e57dea7),
+ X(0x14b8b17f), X(0x7e4fc53e), X(0x14ea4a1f), X(0x7e47985b),
+ X(0x151bdf86), X(0x7e3f57ff), X(0x154d71aa), X(0x7e37042a),
+ X(0x157f0086), X(0x7e2e9cdf), X(0x15b08c12), X(0x7e26221f),
+ X(0x15e21445), X(0x7e1d93ea), X(0x16139918), X(0x7e14f242),
+ X(0x16451a83), X(0x7e0c3d29), X(0x1676987f), X(0x7e0374a0),
+ X(0x16a81305), X(0x7dfa98a8), X(0x16d98a0c), X(0x7df1a942),
+ X(0x170afd8d), X(0x7de8a670), X(0x173c6d80), X(0x7ddf9034),
+ X(0x176dd9de), X(0x7dd6668f), X(0x179f429f), X(0x7dcd2981),
+ X(0x17d0a7bc), X(0x7dc3d90d), X(0x1802092c), X(0x7dba7534),
+ X(0x183366e9), X(0x7db0fdf8), X(0x1864c0ea), X(0x7da77359),
+ X(0x18961728), X(0x7d9dd55a), X(0x18c7699b), X(0x7d9423fc),
+ X(0x18f8b83c), X(0x7d8a5f40), X(0x192a0304), X(0x7d808728),
+ X(0x195b49ea), X(0x7d769bb5), X(0x198c8ce7), X(0x7d6c9ce9),
+ X(0x19bdcbf3), X(0x7d628ac6), X(0x19ef0707), X(0x7d58654d),
+ X(0x1a203e1b), X(0x7d4e2c7f), X(0x1a517128), X(0x7d43e05e),
+ X(0x1a82a026), X(0x7d3980ec), X(0x1ab3cb0d), X(0x7d2f0e2b),
+ X(0x1ae4f1d6), X(0x7d24881b), X(0x1b161479), X(0x7d19eebf),
+ X(0x1b4732ef), X(0x7d0f4218), X(0x1b784d30), X(0x7d048228),
+ X(0x1ba96335), X(0x7cf9aef0), X(0x1bda74f6), X(0x7ceec873),
+ X(0x1c0b826a), X(0x7ce3ceb2), X(0x1c3c8b8c), X(0x7cd8c1ae),
+ X(0x1c6d9053), X(0x7ccda169), X(0x1c9e90b8), X(0x7cc26de5),
+ X(0x1ccf8cb3), X(0x7cb72724), X(0x1d00843d), X(0x7cabcd28),
+ X(0x1d31774d), X(0x7ca05ff1), X(0x1d6265dd), X(0x7c94df83),
+ X(0x1d934fe5), X(0x7c894bde), X(0x1dc4355e), X(0x7c7da505),
+ X(0x1df5163f), X(0x7c71eaf9), X(0x1e25f282), X(0x7c661dbc),
+ X(0x1e56ca1e), X(0x7c5a3d50), X(0x1e879d0d), X(0x7c4e49b7),
+ X(0x1eb86b46), X(0x7c4242f2), X(0x1ee934c3), X(0x7c362904),
+ X(0x1f19f97b), X(0x7c29fbee), X(0x1f4ab968), X(0x7c1dbbb3),
+ X(0x1f7b7481), X(0x7c116853), X(0x1fac2abf), X(0x7c0501d2),
+ X(0x1fdcdc1b), X(0x7bf88830), X(0x200d888d), X(0x7bebfb70),
+ X(0x203e300d), X(0x7bdf5b94), X(0x206ed295), X(0x7bd2a89e),
+ X(0x209f701c), X(0x7bc5e290), X(0x20d0089c), X(0x7bb9096b),
+ X(0x21009c0c), X(0x7bac1d31), X(0x21312a65), X(0x7b9f1de6),
+ X(0x2161b3a0), X(0x7b920b89), X(0x219237b5), X(0x7b84e61f),
+ X(0x21c2b69c), X(0x7b77ada8), X(0x21f3304f), X(0x7b6a6227),
+ X(0x2223a4c5), X(0x7b5d039e), X(0x225413f8), X(0x7b4f920e),
+ X(0x22847de0), X(0x7b420d7a), X(0x22b4e274), X(0x7b3475e5),
+ X(0x22e541af), X(0x7b26cb4f), X(0x23159b88), X(0x7b190dbc),
+ X(0x2345eff8), X(0x7b0b3d2c), X(0x23763ef7), X(0x7afd59a4),
+ X(0x23a6887f), X(0x7aef6323), X(0x23d6cc87), X(0x7ae159ae),
+ X(0x24070b08), X(0x7ad33d45), X(0x243743fa), X(0x7ac50dec),
+ X(0x24677758), X(0x7ab6cba4), X(0x2497a517), X(0x7aa8766f),
+ X(0x24c7cd33), X(0x7a9a0e50), X(0x24f7efa2), X(0x7a8b9348),
+ X(0x25280c5e), X(0x7a7d055b), X(0x2558235f), X(0x7a6e648a),
+ X(0x2588349d), X(0x7a5fb0d8), X(0x25b84012), X(0x7a50ea47),
+ X(0x25e845b6), X(0x7a4210d8), X(0x26184581), X(0x7a332490),
+ X(0x26483f6c), X(0x7a24256f), X(0x26783370), X(0x7a151378),
+ X(0x26a82186), X(0x7a05eead), X(0x26d809a5), X(0x79f6b711),
+ X(0x2707ebc7), X(0x79e76ca7), X(0x2737c7e3), X(0x79d80f6f),
+ X(0x27679df4), X(0x79c89f6e), X(0x27976df1), X(0x79b91ca4),
+ X(0x27c737d3), X(0x79a98715), X(0x27f6fb92), X(0x7999dec4),
+ X(0x2826b928), X(0x798a23b1), X(0x2856708d), X(0x797a55e0),
+ X(0x288621b9), X(0x796a7554), X(0x28b5cca5), X(0x795a820e),
+ X(0x28e5714b), X(0x794a7c12), X(0x29150fa1), X(0x793a6361),
+ X(0x2944a7a2), X(0x792a37fe), X(0x29743946), X(0x7919f9ec),
+ X(0x29a3c485), X(0x7909a92d), X(0x29d34958), X(0x78f945c3),
+ X(0x2a02c7b8), X(0x78e8cfb2), X(0x2a323f9e), X(0x78d846fb),
+ X(0x2a61b101), X(0x78c7aba2), X(0x2a911bdc), X(0x78b6fda8),
+ X(0x2ac08026), X(0x78a63d11), X(0x2aefddd8), X(0x789569df),
+ X(0x2b1f34eb), X(0x78848414), X(0x2b4e8558), X(0x78738bb3),
+ X(0x2b7dcf17), X(0x786280bf), X(0x2bad1221), X(0x7851633b),
+ X(0x2bdc4e6f), X(0x78403329), X(0x2c0b83fa), X(0x782ef08b),
+ X(0x2c3ab2b9), X(0x781d9b65), X(0x2c69daa6), X(0x780c33b8),
+ X(0x2c98fbba), X(0x77fab989), X(0x2cc815ee), X(0x77e92cd9),
+ X(0x2cf72939), X(0x77d78daa), X(0x2d263596), X(0x77c5dc01),
+ X(0x2d553afc), X(0x77b417df), X(0x2d843964), X(0x77a24148),
+ X(0x2db330c7), X(0x7790583e), X(0x2de2211e), X(0x777e5cc3),
+ X(0x2e110a62), X(0x776c4edb), X(0x2e3fec8b), X(0x775a2e89),
+ X(0x2e6ec792), X(0x7747fbce), X(0x2e9d9b70), X(0x7735b6af),
+ X(0x2ecc681e), X(0x77235f2d), X(0x2efb2d95), X(0x7710f54c),
+ X(0x2f29ebcc), X(0x76fe790e), X(0x2f58a2be), X(0x76ebea77),
+ X(0x2f875262), X(0x76d94989), X(0x2fb5fab2), X(0x76c69647),
+ X(0x2fe49ba7), X(0x76b3d0b4), X(0x30133539), X(0x76a0f8d2),
+ X(0x3041c761), X(0x768e0ea6), X(0x30705217), X(0x767b1231),
+ X(0x309ed556), X(0x76680376), X(0x30cd5115), X(0x7654e279),
+ X(0x30fbc54d), X(0x7641af3d), X(0x312a31f8), X(0x762e69c4),
+ X(0x3158970e), X(0x761b1211), X(0x3186f487), X(0x7607a828),
+ X(0x31b54a5e), X(0x75f42c0b), X(0x31e39889), X(0x75e09dbd),
+ X(0x3211df04), X(0x75ccfd42), X(0x32401dc6), X(0x75b94a9c),
+ X(0x326e54c7), X(0x75a585cf), X(0x329c8402), X(0x7591aedd),
+ X(0x32caab6f), X(0x757dc5ca), X(0x32f8cb07), X(0x7569ca99),
+ X(0x3326e2c3), X(0x7555bd4c), X(0x3354f29b), X(0x75419de7),
+ X(0x3382fa88), X(0x752d6c6c), X(0x33b0fa84), X(0x751928e0),
+ X(0x33def287), X(0x7504d345), X(0x340ce28b), X(0x74f06b9e),
+ X(0x343aca87), X(0x74dbf1ef), X(0x3468aa76), X(0x74c7663a),
+ X(0x34968250), X(0x74b2c884), X(0x34c4520d), X(0x749e18cd),
+ X(0x34f219a8), X(0x7489571c), X(0x351fd918), X(0x74748371),
+ X(0x354d9057), X(0x745f9dd1), X(0x357b3f5d), X(0x744aa63f),
+ X(0x35a8e625), X(0x74359cbd), X(0x35d684a6), X(0x74208150),
+ X(0x36041ad9), X(0x740b53fb), X(0x3631a8b8), X(0x73f614c0),
+ X(0x365f2e3b), X(0x73e0c3a3), X(0x368cab5c), X(0x73cb60a8),
+ X(0x36ba2014), X(0x73b5ebd1), X(0x36e78c5b), X(0x73a06522),
+ X(0x3714f02a), X(0x738acc9e), X(0x37424b7b), X(0x73752249),
+ X(0x376f9e46), X(0x735f6626), X(0x379ce885), X(0x73499838),
+ X(0x37ca2a30), X(0x7333b883), X(0x37f76341), X(0x731dc70a),
+ X(0x382493b0), X(0x7307c3d0), X(0x3851bb77), X(0x72f1aed9),
+ X(0x387eda8e), X(0x72db8828), X(0x38abf0ef), X(0x72c54fc1),
+ X(0x38d8fe93), X(0x72af05a7), X(0x39060373), X(0x7298a9dd),
+ X(0x3932ff87), X(0x72823c67), X(0x395ff2c9), X(0x726bbd48),
+ X(0x398cdd32), X(0x72552c85), X(0x39b9bebc), X(0x723e8a20),
+ X(0x39e6975e), X(0x7227d61c), X(0x3a136712), X(0x7211107e),
+ X(0x3a402dd2), X(0x71fa3949), X(0x3a6ceb96), X(0x71e35080),
+ X(0x3a99a057), X(0x71cc5626), X(0x3ac64c0f), X(0x71b54a41),
+ X(0x3af2eeb7), X(0x719e2cd2), X(0x3b1f8848), X(0x7186fdde),
+ X(0x3b4c18ba), X(0x716fbd68), X(0x3b78a007), X(0x71586b74),
+ X(0x3ba51e29), X(0x71410805), X(0x3bd19318), X(0x7129931f),
+ X(0x3bfdfecd), X(0x71120cc5), X(0x3c2a6142), X(0x70fa74fc),
+ X(0x3c56ba70), X(0x70e2cbc6), X(0x3c830a50), X(0x70cb1128),
+ X(0x3caf50da), X(0x70b34525), X(0x3cdb8e09), X(0x709b67c0),
+ X(0x3d07c1d6), X(0x708378ff), X(0x3d33ec39), X(0x706b78e3),
+ X(0x3d600d2c), X(0x70536771), X(0x3d8c24a8), X(0x703b44ad),
+ X(0x3db832a6), X(0x7023109a), X(0x3de4371f), X(0x700acb3c),
+ X(0x3e10320d), X(0x6ff27497), X(0x3e3c2369), X(0x6fda0cae),
+ X(0x3e680b2c), X(0x6fc19385), X(0x3e93e950), X(0x6fa90921),
+ X(0x3ebfbdcd), X(0x6f906d84), X(0x3eeb889c), X(0x6f77c0b3),
+ X(0x3f1749b8), X(0x6f5f02b2), X(0x3f430119), X(0x6f463383),
+ X(0x3f6eaeb8), X(0x6f2d532c), X(0x3f9a5290), X(0x6f1461b0),
+ X(0x3fc5ec98), X(0x6efb5f12), X(0x3ff17cca), X(0x6ee24b57),
+ X(0x401d0321), X(0x6ec92683), X(0x40487f94), X(0x6eaff099),
+ X(0x4073f21d), X(0x6e96a99d), X(0x409f5ab6), X(0x6e7d5193),
+ X(0x40cab958), X(0x6e63e87f), X(0x40f60dfb), X(0x6e4a6e66),
+ X(0x4121589b), X(0x6e30e34a), X(0x414c992f), X(0x6e174730),
+ X(0x4177cfb1), X(0x6dfd9a1c), X(0x41a2fc1a), X(0x6de3dc11),
+ X(0x41ce1e65), X(0x6dca0d14), X(0x41f93689), X(0x6db02d29),
+ X(0x42244481), X(0x6d963c54), X(0x424f4845), X(0x6d7c3a98),
+ X(0x427a41d0), X(0x6d6227fa), X(0x42a5311b), X(0x6d48047e),
+ X(0x42d0161e), X(0x6d2dd027), X(0x42faf0d4), X(0x6d138afb),
+ X(0x4325c135), X(0x6cf934fc), X(0x4350873c), X(0x6cdece2f),
+ X(0x437b42e1), X(0x6cc45698), X(0x43a5f41e), X(0x6ca9ce3b),
+ X(0x43d09aed), X(0x6c8f351c), X(0x43fb3746), X(0x6c748b3f),
+ X(0x4425c923), X(0x6c59d0a9), X(0x4450507e), X(0x6c3f055d),
+ X(0x447acd50), X(0x6c242960), X(0x44a53f93), X(0x6c093cb6),
+ X(0x44cfa740), X(0x6bee3f62), X(0x44fa0450), X(0x6bd3316a),
+ X(0x452456bd), X(0x6bb812d1), X(0x454e9e80), X(0x6b9ce39b),
+ X(0x4578db93), X(0x6b81a3cd), X(0x45a30df0), X(0x6b66536b),
+ X(0x45cd358f), X(0x6b4af279), X(0x45f7526b), X(0x6b2f80fb),
+ X(0x4621647d), X(0x6b13fef5), X(0x464b6bbe), X(0x6af86c6c),
+ X(0x46756828), X(0x6adcc964), X(0x469f59b4), X(0x6ac115e2),
+ X(0x46c9405c), X(0x6aa551e9), X(0x46f31c1a), X(0x6a897d7d),
+ X(0x471cece7), X(0x6a6d98a4), X(0x4746b2bc), X(0x6a51a361),
+ X(0x47706d93), X(0x6a359db9), X(0x479a1d67), X(0x6a1987b0),
+ X(0x47c3c22f), X(0x69fd614a), X(0x47ed5be6), X(0x69e12a8c),
+ X(0x4816ea86), X(0x69c4e37a), X(0x48406e08), X(0x69a88c19),
+ X(0x4869e665), X(0x698c246c), X(0x48935397), X(0x696fac78),
+ X(0x48bcb599), X(0x69532442), X(0x48e60c62), X(0x69368bce),
+ X(0x490f57ee), X(0x6919e320), X(0x49389836), X(0x68fd2a3d),
+ X(0x4961cd33), X(0x68e06129), X(0x498af6df), X(0x68c387e9),
+ X(0x49b41533), X(0x68a69e81), X(0x49dd282a), X(0x6889a4f6),
+ X(0x4a062fbd), X(0x686c9b4b), X(0x4a2f2be6), X(0x684f8186),
+ X(0x4a581c9e), X(0x683257ab), X(0x4a8101de), X(0x68151dbe),
+ X(0x4aa9dba2), X(0x67f7d3c5), X(0x4ad2a9e2), X(0x67da79c3),
+ X(0x4afb6c98), X(0x67bd0fbd), X(0x4b2423be), X(0x679f95b7),
+ X(0x4b4ccf4d), X(0x67820bb7), X(0x4b756f40), X(0x676471c0),
+ X(0x4b9e0390), X(0x6746c7d8), X(0x4bc68c36), X(0x67290e02),
+ X(0x4bef092d), X(0x670b4444), X(0x4c177a6e), X(0x66ed6aa1),
+ X(0x4c3fdff4), X(0x66cf8120), X(0x4c6839b7), X(0x66b187c3),
+ X(0x4c9087b1), X(0x66937e91), X(0x4cb8c9dd), X(0x6675658c),
+ X(0x4ce10034), X(0x66573cbb), X(0x4d092ab0), X(0x66390422),
+ X(0x4d31494b), X(0x661abbc5), X(0x4d595bfe), X(0x65fc63a9),
+ X(0x4d8162c4), X(0x65ddfbd3), X(0x4da95d96), X(0x65bf8447),
+ X(0x4dd14c6e), X(0x65a0fd0b), X(0x4df92f46), X(0x65826622),
+ X(0x4e210617), X(0x6563bf92), X(0x4e48d0dd), X(0x6545095f),
+ X(0x4e708f8f), X(0x6526438f), X(0x4e984229), X(0x65076e25),
+ X(0x4ebfe8a5), X(0x64e88926), X(0x4ee782fb), X(0x64c99498),
+ X(0x4f0f1126), X(0x64aa907f), X(0x4f369320), X(0x648b7ce0),
+ X(0x4f5e08e3), X(0x646c59bf), X(0x4f857269), X(0x644d2722),
+ X(0x4faccfab), X(0x642de50d), X(0x4fd420a4), X(0x640e9386),
+ X(0x4ffb654d), X(0x63ef3290), X(0x50229da1), X(0x63cfc231),
+ X(0x5049c999), X(0x63b0426d), X(0x5070e92f), X(0x6390b34a),
+ X(0x5097fc5e), X(0x637114cc), X(0x50bf031f), X(0x635166f9),
+ X(0x50e5fd6d), X(0x6331a9d4), X(0x510ceb40), X(0x6311dd64),
+ X(0x5133cc94), X(0x62f201ac), X(0x515aa162), X(0x62d216b3),
+ X(0x518169a5), X(0x62b21c7b), X(0x51a82555), X(0x6292130c),
+ X(0x51ced46e), X(0x6271fa69), X(0x51f576ea), X(0x6251d298),
+ X(0x521c0cc2), X(0x62319b9d), X(0x524295f0), X(0x6211557e),
+ X(0x5269126e), X(0x61f1003f), X(0x528f8238), X(0x61d09be5),
+ X(0x52b5e546), X(0x61b02876), X(0x52dc3b92), X(0x618fa5f7),
+ X(0x53028518), X(0x616f146c), X(0x5328c1d0), X(0x614e73da),
+ X(0x534ef1b5), X(0x612dc447), X(0x537514c2), X(0x610d05b7),
+ X(0x539b2af0), X(0x60ec3830), X(0x53c13439), X(0x60cb5bb7),
+ X(0x53e73097), X(0x60aa7050), X(0x540d2005), X(0x60897601),
+ X(0x5433027d), X(0x60686ccf), X(0x5458d7f9), X(0x604754bf),
+ X(0x547ea073), X(0x60262dd6), X(0x54a45be6), X(0x6004f819),
+ X(0x54ca0a4b), X(0x5fe3b38d), X(0x54efab9c), X(0x5fc26038),
+ X(0x55153fd4), X(0x5fa0fe1f), X(0x553ac6ee), X(0x5f7f8d46),
+ X(0x556040e2), X(0x5f5e0db3), X(0x5585adad), X(0x5f3c7f6b),
+ X(0x55ab0d46), X(0x5f1ae274), X(0x55d05faa), X(0x5ef936d1),
+ X(0x55f5a4d2), X(0x5ed77c8a), X(0x561adcb9), X(0x5eb5b3a2),
+ X(0x56400758), X(0x5e93dc1f), X(0x566524aa), X(0x5e71f606),
+ X(0x568a34a9), X(0x5e50015d), X(0x56af3750), X(0x5e2dfe29),
+ X(0x56d42c99), X(0x5e0bec6e), X(0x56f9147e), X(0x5de9cc33),
+ X(0x571deefa), X(0x5dc79d7c), X(0x5742bc06), X(0x5da5604f),
+ X(0x57677b9d), X(0x5d8314b1), X(0x578c2dba), X(0x5d60baa7),
+ X(0x57b0d256), X(0x5d3e5237), X(0x57d5696d), X(0x5d1bdb65),
+ X(0x57f9f2f8), X(0x5cf95638), X(0x581e6ef1), X(0x5cd6c2b5),
+ X(0x5842dd54), X(0x5cb420e0), X(0x58673e1b), X(0x5c9170bf),
+ X(0x588b9140), X(0x5c6eb258), X(0x58afd6bd), X(0x5c4be5b0),
+ X(0x58d40e8c), X(0x5c290acc), X(0x58f838a9), X(0x5c0621b2),
+ X(0x591c550e), X(0x5be32a67), X(0x594063b5), X(0x5bc024f0),
+ X(0x59646498), X(0x5b9d1154), X(0x598857b2), X(0x5b79ef96),
+ X(0x59ac3cfd), X(0x5b56bfbd), X(0x59d01475), X(0x5b3381ce),
+ X(0x59f3de12), X(0x5b1035cf), X(0x5a1799d1), X(0x5aecdbc5),
+ X(0x5a3b47ab), X(0x5ac973b5), X(0x5a5ee79a), X(0x5aa5fda5),
+ X(0x5a82799a), X(0x5a82799a)
+ };
+
+ /* {sin((2*i+1)*PI/4096), cos((2*i+1)*PI/4096)}, with i = 0 to 511 */
+static LOOKUP_T sincos_lookup1[1024] = {
+ X(0x001921fb), X(0x7ffffd88), X(0x004b65ee), X(0x7fffe9cb),
+ X(0x007da9d4), X(0x7fffc251), X(0x00afeda8), X(0x7fff8719),
+ X(0x00e23160), X(0x7fff3824), X(0x011474f6), X(0x7ffed572),
+ X(0x0146b860), X(0x7ffe5f03), X(0x0178fb99), X(0x7ffdd4d7),
+ X(0x01ab3e97), X(0x7ffd36ee), X(0x01dd8154), X(0x7ffc8549),
+ X(0x020fc3c6), X(0x7ffbbfe6), X(0x024205e8), X(0x7ffae6c7),
+ X(0x027447b0), X(0x7ff9f9ec), X(0x02a68917), X(0x7ff8f954),
+ X(0x02d8ca16), X(0x7ff7e500), X(0x030b0aa4), X(0x7ff6bcf0),
+ X(0x033d4abb), X(0x7ff58125), X(0x036f8a51), X(0x7ff4319d),
+ X(0x03a1c960), X(0x7ff2ce5b), X(0x03d407df), X(0x7ff1575d),
+ X(0x040645c7), X(0x7fefcca4), X(0x04388310), X(0x7fee2e30),
+ X(0x046abfb3), X(0x7fec7c02), X(0x049cfba7), X(0x7feab61a),
+ X(0x04cf36e5), X(0x7fe8dc78), X(0x05017165), X(0x7fe6ef1c),
+ X(0x0533ab20), X(0x7fe4ee06), X(0x0565e40d), X(0x7fe2d938),
+ X(0x05981c26), X(0x7fe0b0b1), X(0x05ca5361), X(0x7fde7471),
+ X(0x05fc89b8), X(0x7fdc247a), X(0x062ebf22), X(0x7fd9c0ca),
+ X(0x0660f398), X(0x7fd74964), X(0x06932713), X(0x7fd4be46),
+ X(0x06c5598a), X(0x7fd21f72), X(0x06f78af6), X(0x7fcf6ce8),
+ X(0x0729bb4e), X(0x7fcca6a7), X(0x075bea8c), X(0x7fc9ccb2),
+ X(0x078e18a7), X(0x7fc6df08), X(0x07c04598), X(0x7fc3dda9),
+ X(0x07f27157), X(0x7fc0c896), X(0x08249bdd), X(0x7fbd9fd0),
+ X(0x0856c520), X(0x7fba6357), X(0x0888ed1b), X(0x7fb7132b),
+ X(0x08bb13c5), X(0x7fb3af4e), X(0x08ed3916), X(0x7fb037bf),
+ X(0x091f5d06), X(0x7facac7f), X(0x09517f8f), X(0x7fa90d8e),
+ X(0x0983a0a7), X(0x7fa55aee), X(0x09b5c048), X(0x7fa1949e),
+ X(0x09e7de6a), X(0x7f9dbaa0), X(0x0a19fb04), X(0x7f99ccf4),
+ X(0x0a4c1610), X(0x7f95cb9a), X(0x0a7e2f85), X(0x7f91b694),
+ X(0x0ab0475c), X(0x7f8d8de1), X(0x0ae25d8d), X(0x7f895182),
+ X(0x0b147211), X(0x7f850179), X(0x0b4684df), X(0x7f809dc5),
+ X(0x0b7895f0), X(0x7f7c2668), X(0x0baaa53b), X(0x7f779b62),
+ X(0x0bdcb2bb), X(0x7f72fcb4), X(0x0c0ebe66), X(0x7f6e4a5e),
+ X(0x0c40c835), X(0x7f698461), X(0x0c72d020), X(0x7f64aabf),
+ X(0x0ca4d620), X(0x7f5fbd77), X(0x0cd6da2d), X(0x7f5abc8a),
+ X(0x0d08dc3f), X(0x7f55a7fa), X(0x0d3adc4e), X(0x7f507fc7),
+ X(0x0d6cda53), X(0x7f4b43f2), X(0x0d9ed646), X(0x7f45f47b),
+ X(0x0dd0d01f), X(0x7f409164), X(0x0e02c7d7), X(0x7f3b1aad),
+ X(0x0e34bd66), X(0x7f359057), X(0x0e66b0c3), X(0x7f2ff263),
+ X(0x0e98a1e9), X(0x7f2a40d2), X(0x0eca90ce), X(0x7f247ba5),
+ X(0x0efc7d6b), X(0x7f1ea2dc), X(0x0f2e67b8), X(0x7f18b679),
+ X(0x0f604faf), X(0x7f12b67c), X(0x0f923546), X(0x7f0ca2e7),
+ X(0x0fc41876), X(0x7f067bba), X(0x0ff5f938), X(0x7f0040f6),
+ X(0x1027d784), X(0x7ef9f29d), X(0x1059b352), X(0x7ef390ae),
+ X(0x108b8c9b), X(0x7eed1b2c), X(0x10bd6356), X(0x7ee69217),
+ X(0x10ef377d), X(0x7edff570), X(0x11210907), X(0x7ed94538),
+ X(0x1152d7ed), X(0x7ed28171), X(0x1184a427), X(0x7ecbaa1a),
+ X(0x11b66dad), X(0x7ec4bf36), X(0x11e83478), X(0x7ebdc0c6),
+ X(0x1219f880), X(0x7eb6aeca), X(0x124bb9be), X(0x7eaf8943),
+ X(0x127d7829), X(0x7ea85033), X(0x12af33ba), X(0x7ea1039b),
+ X(0x12e0ec6a), X(0x7e99a37c), X(0x1312a230), X(0x7e922fd6),
+ X(0x13445505), X(0x7e8aa8ac), X(0x137604e2), X(0x7e830dff),
+ X(0x13a7b1bf), X(0x7e7b5fce), X(0x13d95b93), X(0x7e739e1d),
+ X(0x140b0258), X(0x7e6bc8eb), X(0x143ca605), X(0x7e63e03b),
+ X(0x146e4694), X(0x7e5be40c), X(0x149fe3fc), X(0x7e53d462),
+ X(0x14d17e36), X(0x7e4bb13c), X(0x1503153a), X(0x7e437a9c),
+ X(0x1534a901), X(0x7e3b3083), X(0x15663982), X(0x7e32d2f4),
+ X(0x1597c6b7), X(0x7e2a61ed), X(0x15c95097), X(0x7e21dd73),
+ X(0x15fad71b), X(0x7e194584), X(0x162c5a3b), X(0x7e109a24),
+ X(0x165dd9f0), X(0x7e07db52), X(0x168f5632), X(0x7dff0911),
+ X(0x16c0cef9), X(0x7df62362), X(0x16f2443e), X(0x7ded2a47),
+ X(0x1723b5f9), X(0x7de41dc0), X(0x17552422), X(0x7ddafdce),
+ X(0x17868eb3), X(0x7dd1ca75), X(0x17b7f5a3), X(0x7dc883b4),
+ X(0x17e958ea), X(0x7dbf298d), X(0x181ab881), X(0x7db5bc02),
+ X(0x184c1461), X(0x7dac3b15), X(0x187d6c82), X(0x7da2a6c6),
+ X(0x18aec0db), X(0x7d98ff17), X(0x18e01167), X(0x7d8f4409),
+ X(0x19115e1c), X(0x7d85759f), X(0x1942a6f3), X(0x7d7b93da),
+ X(0x1973ebe6), X(0x7d719eba), X(0x19a52ceb), X(0x7d679642),
+ X(0x19d669fc), X(0x7d5d7a74), X(0x1a07a311), X(0x7d534b50),
+ X(0x1a38d823), X(0x7d4908d9), X(0x1a6a0929), X(0x7d3eb30f),
+ X(0x1a9b361d), X(0x7d3449f5), X(0x1acc5ef6), X(0x7d29cd8c),
+ X(0x1afd83ad), X(0x7d1f3dd6), X(0x1b2ea43a), X(0x7d149ad5),
+ X(0x1b5fc097), X(0x7d09e489), X(0x1b90d8bb), X(0x7cff1af5),
+ X(0x1bc1ec9e), X(0x7cf43e1a), X(0x1bf2fc3a), X(0x7ce94dfb),
+ X(0x1c240786), X(0x7cde4a98), X(0x1c550e7c), X(0x7cd333f3),
+ X(0x1c861113), X(0x7cc80a0f), X(0x1cb70f43), X(0x7cbcccec),
+ X(0x1ce80906), X(0x7cb17c8d), X(0x1d18fe54), X(0x7ca618f3),
+ X(0x1d49ef26), X(0x7c9aa221), X(0x1d7adb73), X(0x7c8f1817),
+ X(0x1dabc334), X(0x7c837ad8), X(0x1ddca662), X(0x7c77ca65),
+ X(0x1e0d84f5), X(0x7c6c06c0), X(0x1e3e5ee5), X(0x7c602fec),
+ X(0x1e6f342c), X(0x7c5445e9), X(0x1ea004c1), X(0x7c4848ba),
+ X(0x1ed0d09d), X(0x7c3c3860), X(0x1f0197b8), X(0x7c3014de),
+ X(0x1f325a0b), X(0x7c23de35), X(0x1f63178f), X(0x7c179467),
+ X(0x1f93d03c), X(0x7c0b3777), X(0x1fc4840a), X(0x7bfec765),
+ X(0x1ff532f2), X(0x7bf24434), X(0x2025dcec), X(0x7be5ade6),
+ X(0x205681f1), X(0x7bd9047c), X(0x208721f9), X(0x7bcc47fa),
+ X(0x20b7bcfe), X(0x7bbf7860), X(0x20e852f6), X(0x7bb295b0),
+ X(0x2118e3dc), X(0x7ba59fee), X(0x21496fa7), X(0x7b989719),
+ X(0x2179f64f), X(0x7b8b7b36), X(0x21aa77cf), X(0x7b7e4c45),
+ X(0x21daf41d), X(0x7b710a49), X(0x220b6b32), X(0x7b63b543),
+ X(0x223bdd08), X(0x7b564d36), X(0x226c4996), X(0x7b48d225),
+ X(0x229cb0d5), X(0x7b3b4410), X(0x22cd12bd), X(0x7b2da2fa),
+ X(0x22fd6f48), X(0x7b1feee5), X(0x232dc66d), X(0x7b1227d3),
+ X(0x235e1826), X(0x7b044dc7), X(0x238e646a), X(0x7af660c2),
+ X(0x23beab33), X(0x7ae860c7), X(0x23eeec78), X(0x7ada4dd8),
+ X(0x241f2833), X(0x7acc27f7), X(0x244f5e5c), X(0x7abdef25),
+ X(0x247f8eec), X(0x7aafa367), X(0x24afb9da), X(0x7aa144bc),
+ X(0x24dfdf20), X(0x7a92d329), X(0x250ffeb7), X(0x7a844eae),
+ X(0x25401896), X(0x7a75b74f), X(0x25702cb7), X(0x7a670d0d),
+ X(0x25a03b11), X(0x7a584feb), X(0x25d0439f), X(0x7a497feb),
+ X(0x26004657), X(0x7a3a9d0f), X(0x26304333), X(0x7a2ba75a),
+ X(0x26603a2c), X(0x7a1c9ece), X(0x26902b39), X(0x7a0d836d),
+ X(0x26c01655), X(0x79fe5539), X(0x26effb76), X(0x79ef1436),
+ X(0x271fda96), X(0x79dfc064), X(0x274fb3ae), X(0x79d059c8),
+ X(0x277f86b5), X(0x79c0e062), X(0x27af53a6), X(0x79b15435),
+ X(0x27df1a77), X(0x79a1b545), X(0x280edb23), X(0x79920392),
+ X(0x283e95a1), X(0x79823f20), X(0x286e49ea), X(0x797267f2),
+ X(0x289df7f8), X(0x79627e08), X(0x28cd9fc1), X(0x79528167),
+ X(0x28fd4140), X(0x79427210), X(0x292cdc6d), X(0x79325006),
+ X(0x295c7140), X(0x79221b4b), X(0x298bffb2), X(0x7911d3e2),
+ X(0x29bb87bc), X(0x790179cd), X(0x29eb0957), X(0x78f10d0f),
+ X(0x2a1a847b), X(0x78e08dab), X(0x2a49f920), X(0x78cffba3),
+ X(0x2a796740), X(0x78bf56f9), X(0x2aa8ced3), X(0x78ae9fb0),
+ X(0x2ad82fd2), X(0x789dd5cb), X(0x2b078a36), X(0x788cf94c),
+ X(0x2b36ddf7), X(0x787c0a36), X(0x2b662b0e), X(0x786b088c),
+ X(0x2b957173), X(0x7859f44f), X(0x2bc4b120), X(0x7848cd83),
+ X(0x2bf3ea0d), X(0x7837942b), X(0x2c231c33), X(0x78264849),
+ X(0x2c52478a), X(0x7814e9df), X(0x2c816c0c), X(0x780378f1),
+ X(0x2cb089b1), X(0x77f1f581), X(0x2cdfa071), X(0x77e05f91),
+ X(0x2d0eb046), X(0x77ceb725), X(0x2d3db928), X(0x77bcfc3f),
+ X(0x2d6cbb10), X(0x77ab2ee2), X(0x2d9bb5f6), X(0x77994f11),
+ X(0x2dcaa9d5), X(0x77875cce), X(0x2df996a3), X(0x7775581d),
+ X(0x2e287c5a), X(0x776340ff), X(0x2e575af3), X(0x77511778),
+ X(0x2e863267), X(0x773edb8b), X(0x2eb502ae), X(0x772c8d3a),
+ X(0x2ee3cbc1), X(0x771a2c88), X(0x2f128d99), X(0x7707b979),
+ X(0x2f41482e), X(0x76f5340e), X(0x2f6ffb7a), X(0x76e29c4b),
+ X(0x2f9ea775), X(0x76cff232), X(0x2fcd4c19), X(0x76bd35c7),
+ X(0x2ffbe95d), X(0x76aa670d), X(0x302a7f3a), X(0x76978605),
+ X(0x30590dab), X(0x768492b4), X(0x308794a6), X(0x76718d1c),
+ X(0x30b61426), X(0x765e7540), X(0x30e48c22), X(0x764b4b23),
+ X(0x3112fc95), X(0x76380ec8), X(0x31416576), X(0x7624c031),
+ X(0x316fc6be), X(0x76115f63), X(0x319e2067), X(0x75fdec60),
+ X(0x31cc7269), X(0x75ea672a), X(0x31fabcbd), X(0x75d6cfc5),
+ X(0x3228ff5c), X(0x75c32634), X(0x32573a3f), X(0x75af6a7b),
+ X(0x32856d5e), X(0x759b9c9b), X(0x32b398b3), X(0x7587bc98),
+ X(0x32e1bc36), X(0x7573ca75), X(0x330fd7e1), X(0x755fc635),
+ X(0x333debab), X(0x754bafdc), X(0x336bf78f), X(0x7537876c),
+ X(0x3399fb85), X(0x75234ce8), X(0x33c7f785), X(0x750f0054),
+ X(0x33f5eb89), X(0x74faa1b3), X(0x3423d78a), X(0x74e63108),
+ X(0x3451bb81), X(0x74d1ae55), X(0x347f9766), X(0x74bd199f),
+ X(0x34ad6b32), X(0x74a872e8), X(0x34db36df), X(0x7493ba34),
+ X(0x3508fa66), X(0x747eef85), X(0x3536b5be), X(0x746a12df),
+ X(0x356468e2), X(0x74552446), X(0x359213c9), X(0x744023bc),
+ X(0x35bfb66e), X(0x742b1144), X(0x35ed50c9), X(0x7415ece2),
+ X(0x361ae2d3), X(0x7400b69a), X(0x36486c86), X(0x73eb6e6e),
+ X(0x3675edd9), X(0x73d61461), X(0x36a366c6), X(0x73c0a878),
+ X(0x36d0d746), X(0x73ab2ab4), X(0x36fe3f52), X(0x73959b1b),
+ X(0x372b9ee3), X(0x737ff9ae), X(0x3758f5f2), X(0x736a4671),
+ X(0x37864477), X(0x73548168), X(0x37b38a6d), X(0x733eaa96),
+ X(0x37e0c7cc), X(0x7328c1ff), X(0x380dfc8d), X(0x7312c7a5),
+ X(0x383b28a9), X(0x72fcbb8c), X(0x38684c19), X(0x72e69db7),
+ X(0x389566d6), X(0x72d06e2b), X(0x38c278d9), X(0x72ba2cea),
+ X(0x38ef821c), X(0x72a3d9f7), X(0x391c8297), X(0x728d7557),
+ X(0x39497a43), X(0x7276ff0d), X(0x39766919), X(0x7260771b),
+ X(0x39a34f13), X(0x7249dd86), X(0x39d02c2a), X(0x72333251),
+ X(0x39fd0056), X(0x721c7580), X(0x3a29cb91), X(0x7205a716),
+ X(0x3a568dd4), X(0x71eec716), X(0x3a834717), X(0x71d7d585),
+ X(0x3aaff755), X(0x71c0d265), X(0x3adc9e86), X(0x71a9bdba),
+ X(0x3b093ca3), X(0x71929789), X(0x3b35d1a5), X(0x717b5fd3),
+ X(0x3b625d86), X(0x7164169d), X(0x3b8ee03e), X(0x714cbbeb),
+ X(0x3bbb59c7), X(0x71354fc0), X(0x3be7ca1a), X(0x711dd220),
+ X(0x3c143130), X(0x7106430e), X(0x3c408f03), X(0x70eea28e),
+ X(0x3c6ce38a), X(0x70d6f0a4), X(0x3c992ec0), X(0x70bf2d53),
+ X(0x3cc5709e), X(0x70a7589f), X(0x3cf1a91c), X(0x708f728b),
+ X(0x3d1dd835), X(0x70777b1c), X(0x3d49fde1), X(0x705f7255),
+ X(0x3d761a19), X(0x70475839), X(0x3da22cd7), X(0x702f2ccd),
+ X(0x3dce3614), X(0x7016f014), X(0x3dfa35c8), X(0x6ffea212),
+ X(0x3e262bee), X(0x6fe642ca), X(0x3e52187f), X(0x6fcdd241),
+ X(0x3e7dfb73), X(0x6fb5507a), X(0x3ea9d4c3), X(0x6f9cbd79),
+ X(0x3ed5a46b), X(0x6f841942), X(0x3f016a61), X(0x6f6b63d8),
+ X(0x3f2d26a0), X(0x6f529d40), X(0x3f58d921), X(0x6f39c57d),
+ X(0x3f8481dd), X(0x6f20dc92), X(0x3fb020ce), X(0x6f07e285),
+ X(0x3fdbb5ec), X(0x6eeed758), X(0x40074132), X(0x6ed5bb10),
+ X(0x4032c297), X(0x6ebc8db0), X(0x405e3a16), X(0x6ea34f3d),
+ X(0x4089a7a8), X(0x6e89ffb9), X(0x40b50b46), X(0x6e709f2a),
+ X(0x40e064ea), X(0x6e572d93), X(0x410bb48c), X(0x6e3daaf8),
+ X(0x4136fa27), X(0x6e24175c), X(0x416235b2), X(0x6e0a72c5),
+ X(0x418d6729), X(0x6df0bd35), X(0x41b88e84), X(0x6dd6f6b1),
+ X(0x41e3abbc), X(0x6dbd1f3c), X(0x420ebecb), X(0x6da336dc),
+ X(0x4239c7aa), X(0x6d893d93), X(0x4264c653), X(0x6d6f3365),
+ X(0x428fbabe), X(0x6d551858), X(0x42baa4e6), X(0x6d3aec6e),
+ X(0x42e584c3), X(0x6d20afac), X(0x43105a50), X(0x6d066215),
+ X(0x433b2585), X(0x6cec03af), X(0x4365e65b), X(0x6cd1947c),
+ X(0x43909ccd), X(0x6cb71482), X(0x43bb48d4), X(0x6c9c83c3),
+ X(0x43e5ea68), X(0x6c81e245), X(0x44108184), X(0x6c67300b),
+ X(0x443b0e21), X(0x6c4c6d1a), X(0x44659039), X(0x6c319975),
+ X(0x449007c4), X(0x6c16b521), X(0x44ba74bd), X(0x6bfbc021),
+ X(0x44e4d71c), X(0x6be0ba7b), X(0x450f2edb), X(0x6bc5a431),
+ X(0x45397bf4), X(0x6baa7d49), X(0x4563be60), X(0x6b8f45c7),
+ X(0x458df619), X(0x6b73fdae), X(0x45b82318), X(0x6b58a503),
+ X(0x45e24556), X(0x6b3d3bcb), X(0x460c5cce), X(0x6b21c208),
+ X(0x46366978), X(0x6b0637c1), X(0x46606b4e), X(0x6aea9cf8),
+ X(0x468a624a), X(0x6acef1b2), X(0x46b44e65), X(0x6ab335f4),
+ X(0x46de2f99), X(0x6a9769c1), X(0x470805df), X(0x6a7b8d1e),
+ X(0x4731d131), X(0x6a5fa010), X(0x475b9188), X(0x6a43a29a),
+ X(0x478546de), X(0x6a2794c1), X(0x47aef12c), X(0x6a0b7689),
+ X(0x47d8906d), X(0x69ef47f6), X(0x48022499), X(0x69d3090e),
+ X(0x482badab), X(0x69b6b9d3), X(0x48552b9b), X(0x699a5a4c),
+ X(0x487e9e64), X(0x697dea7b), X(0x48a805ff), X(0x69616a65),
+ X(0x48d16265), X(0x6944da10), X(0x48fab391), X(0x6928397e),
+ X(0x4923f97b), X(0x690b88b5), X(0x494d341e), X(0x68eec7b9),
+ X(0x49766373), X(0x68d1f68f), X(0x499f8774), X(0x68b5153a),
+ X(0x49c8a01b), X(0x689823bf), X(0x49f1ad61), X(0x687b2224),
+ X(0x4a1aaf3f), X(0x685e106c), X(0x4a43a5b0), X(0x6840ee9b),
+ X(0x4a6c90ad), X(0x6823bcb7), X(0x4a957030), X(0x68067ac3),
+ X(0x4abe4433), X(0x67e928c5), X(0x4ae70caf), X(0x67cbc6c0),
+ X(0x4b0fc99d), X(0x67ae54ba), X(0x4b387af9), X(0x6790d2b6),
+ X(0x4b6120bb), X(0x677340ba), X(0x4b89badd), X(0x67559eca),
+ X(0x4bb24958), X(0x6737ecea), X(0x4bdacc28), X(0x671a2b20),
+ X(0x4c034345), X(0x66fc596f), X(0x4c2baea9), X(0x66de77dc),
+ X(0x4c540e4e), X(0x66c0866d), X(0x4c7c622d), X(0x66a28524),
+ X(0x4ca4aa41), X(0x66847408), X(0x4ccce684), X(0x6666531d),
+ X(0x4cf516ee), X(0x66482267), X(0x4d1d3b7a), X(0x6629e1ec),
+ X(0x4d455422), X(0x660b91af), X(0x4d6d60df), X(0x65ed31b5),
+ X(0x4d9561ac), X(0x65cec204), X(0x4dbd5682), X(0x65b0429f),
+ X(0x4de53f5a), X(0x6591b38c), X(0x4e0d1c30), X(0x657314cf),
+ X(0x4e34ecfc), X(0x6554666d), X(0x4e5cb1b9), X(0x6535a86b),
+ X(0x4e846a60), X(0x6516dacd), X(0x4eac16eb), X(0x64f7fd98),
+ X(0x4ed3b755), X(0x64d910d1), X(0x4efb4b96), X(0x64ba147d),
+ X(0x4f22d3aa), X(0x649b08a0), X(0x4f4a4f89), X(0x647bed3f),
+ X(0x4f71bf2e), X(0x645cc260), X(0x4f992293), X(0x643d8806),
+ X(0x4fc079b1), X(0x641e3e38), X(0x4fe7c483), X(0x63fee4f8),
+ X(0x500f0302), X(0x63df7c4d), X(0x50363529), X(0x63c0043b),
+ X(0x505d5af1), X(0x63a07cc7), X(0x50847454), X(0x6380e5f6),
+ X(0x50ab814d), X(0x63613fcd), X(0x50d281d5), X(0x63418a50),
+ X(0x50f975e6), X(0x6321c585), X(0x51205d7b), X(0x6301f171),
+ X(0x5147388c), X(0x62e20e17), X(0x516e0715), X(0x62c21b7e),
+ X(0x5194c910), X(0x62a219aa), X(0x51bb7e75), X(0x628208a1),
+ X(0x51e22740), X(0x6261e866), X(0x5208c36a), X(0x6241b8ff),
+ X(0x522f52ee), X(0x62217a72), X(0x5255d5c5), X(0x62012cc2),
+ X(0x527c4bea), X(0x61e0cff5), X(0x52a2b556), X(0x61c06410),
+ X(0x52c91204), X(0x619fe918), X(0x52ef61ee), X(0x617f5f12),
+ X(0x5315a50e), X(0x615ec603), X(0x533bdb5d), X(0x613e1df0),
+ X(0x536204d7), X(0x611d66de), X(0x53882175), X(0x60fca0d2),
+ X(0x53ae3131), X(0x60dbcbd1), X(0x53d43406), X(0x60bae7e1),
+ X(0x53fa29ed), X(0x6099f505), X(0x542012e1), X(0x6078f344),
+ X(0x5445eedb), X(0x6057e2a2), X(0x546bbdd7), X(0x6036c325),
+ X(0x54917fce), X(0x601594d1), X(0x54b734ba), X(0x5ff457ad),
+ X(0x54dcdc96), X(0x5fd30bbc), X(0x5502775c), X(0x5fb1b104),
+ X(0x55280505), X(0x5f90478a), X(0x554d858d), X(0x5f6ecf53),
+ X(0x5572f8ed), X(0x5f4d4865), X(0x55985f20), X(0x5f2bb2c5),
+ X(0x55bdb81f), X(0x5f0a0e77), X(0x55e303e6), X(0x5ee85b82),
+ X(0x5608426e), X(0x5ec699e9), X(0x562d73b2), X(0x5ea4c9b3),
+ X(0x565297ab), X(0x5e82eae5), X(0x5677ae54), X(0x5e60fd84),
+ X(0x569cb7a8), X(0x5e3f0194), X(0x56c1b3a1), X(0x5e1cf71c),
+ X(0x56e6a239), X(0x5dfade20), X(0x570b8369), X(0x5dd8b6a7),
+ X(0x5730572e), X(0x5db680b4), X(0x57551d80), X(0x5d943c4e),
+ X(0x5779d65b), X(0x5d71e979), X(0x579e81b8), X(0x5d4f883b),
+ X(0x57c31f92), X(0x5d2d189a), X(0x57e7afe4), X(0x5d0a9a9a),
+ X(0x580c32a7), X(0x5ce80e41), X(0x5830a7d6), X(0x5cc57394),
+ X(0x58550f6c), X(0x5ca2ca99), X(0x58796962), X(0x5c801354),
+ X(0x589db5b3), X(0x5c5d4dcc), X(0x58c1f45b), X(0x5c3a7a05),
+ X(0x58e62552), X(0x5c179806), X(0x590a4893), X(0x5bf4a7d2),
+ X(0x592e5e19), X(0x5bd1a971), X(0x595265df), X(0x5bae9ce7),
+ X(0x59765fde), X(0x5b8b8239), X(0x599a4c12), X(0x5b68596d),
+ X(0x59be2a74), X(0x5b452288), X(0x59e1faff), X(0x5b21dd90),
+ X(0x5a05bdae), X(0x5afe8a8b), X(0x5a29727b), X(0x5adb297d),
+ X(0x5a4d1960), X(0x5ab7ba6c), X(0x5a70b258), X(0x5a943d5e),
+};
+
diff --git a/osframework/source/SexyAppFramework/ogg/misc.h b/osframework/source/SexyAppFramework/ogg/misc.h
new file mode 100644
index 0000000..f178214
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/misc.h
@@ -0,0 +1,242 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: miscellaneous math and prototypes
+
+ ********************************************************************/
+
+#ifndef _V_RANDOM_H_
+#define _V_RANDOM_H_
+#include "ivorbiscodec.h"
+#include "os.h"
+#include "os_types.h"
+
+#include "asm_arm.h"
+
+#ifndef _V_WIDE_MATH
+#define _V_WIDE_MATH
+
+#ifndef _LOW_ACCURACY_
+/* 64 bit multiply */
+
+#include <sys/types.h>
+
+#if 1 //BYTE_ORDER==LITTLE_ENDIAN
+
+union magic {
+ struct {
+ ogg_int32_t lo;
+ ogg_int32_t hi;
+ } halves;
+ ogg_int64_t whole;
+};
+#endif
+
+#if 0 //BYTE_ORDER==BIG_ENDIAN
+union magic {
+ struct {
+ ogg_int32_t hi;
+ ogg_int32_t lo;
+ } halves;
+ ogg_int64_t whole;
+};
+#endif
+
+STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
+ union magic magic;
+ magic.whole = (ogg_int64_t)x * y;
+ return magic.halves.hi;
+}
+
+STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
+ return MULT32(x,y)<<1;
+}
+
+STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
+ union magic magic;
+ magic.whole = (ogg_int64_t)x * y;
+ return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17);
+}
+
+#else
+/* 32 bit multiply, more portable but less accurate */
+
+/*
+ * Note: Precision is biased towards the first argument therefore ordering
+ * is important. Shift values were chosen for the best sound quality after
+ * many listening tests.
+ */
+
+/*
+ * For MULT32 and MULT31: The second argument is always a lookup table
+ * value already preshifted from 31 to 8 bits. We therefore take the
+ * opportunity to save on text space and use unsigned char for those
+ * tables in this case.
+ */
+
+STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
+ return (x >> 9) * y; /* y preshifted >>23 */
+}
+
+STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
+ return (x >> 8) * y; /* y preshifted >>23 */
+}
+
+STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
+ return (x >> 6) * y; /* y preshifted >>9 */
+}
+
+#endif
+
+/*
+ * This should be used as a memory barrier, forcing all cached values in
+ * registers to wr writen back to memory. Might or might not be beneficial
+ * depending on the architecture and compiler.
+ */
+#define MB()
+
+/*
+ * The XPROD functions are meant to optimize the cross products found all
+ * over the place in mdct.c by forcing memory operation ordering to avoid
+ * unnecessary register reloads as soon as memory is being written to.
+ * However this is only beneficial on CPUs with a sane number of general
+ * purpose registers which exclude the Intel x86. On Intel, better let the
+ * compiler actually reload registers directly from original memory by using
+ * macros.
+ */
+
+#ifdef __i386__
+
+#define XPROD32(_a, _b, _t, _v, _x, _y) \
+ { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \
+ *(_y)=MULT32(_b,_t)-MULT32(_a,_v); }
+#define XPROD31(_a, _b, _t, _v, _x, _y) \
+ { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \
+ *(_y)=MULT31(_b,_t)-MULT31(_a,_v); }
+#define XNPROD31(_a, _b, _t, _v, _x, _y) \
+ { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \
+ *(_y)=MULT31(_b,_t)+MULT31(_a,_v); }
+
+#else
+
+STIN void XPROD32(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ *x = MULT32(a, t) + MULT32(b, v);
+ *y = MULT32(b, t) - MULT32(a, v);
+}
+
+STIN void XPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ *x = MULT31(a, t) + MULT31(b, v);
+ *y = MULT31(b, t) - MULT31(a, v);
+}
+
+STIN void XNPROD31(ogg_int32_t a, ogg_int32_t b,
+ ogg_int32_t t, ogg_int32_t v,
+ ogg_int32_t *x, ogg_int32_t *y)
+{
+ *x = MULT31(a, t) - MULT31(b, v);
+ *y = MULT31(b, t) + MULT31(a, v);
+}
+
+#endif
+
+#endif
+
+#ifndef _V_CLIP_MATH
+#define _V_CLIP_MATH
+
+STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
+ int ret=x;
+ ret-= ((x<=32767)-1)&(x-32767);
+ ret-= ((x>=-32768)-1)&(x+32768);
+ return(ret);
+}
+
+#endif
+
+STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap,
+ ogg_int32_t b,ogg_int32_t bp,
+ ogg_int32_t *p){
+ if(a && b){
+#ifndef _LOW_ACCURACY_
+ *p=ap+bp+32;
+ return MULT32(a,b);
+#else
+ *p=ap+bp+31;
+ return (a>>15)*(b>>16);
+#endif
+ }else
+ return 0;
+}
+
+STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap,
+ ogg_int32_t i,
+ ogg_int32_t *p){
+
+ extern int _ilog(unsigned int v);
+ int ip=_ilog(abs(i))-31;
+ return VFLOAT_MULT(a,ap,i<<-ip,ip,p);
+}
+
+STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap,
+ ogg_int32_t b,ogg_int32_t bp,
+ ogg_int32_t *p){
+
+ if(!a){
+ *p=bp;
+ return b;
+ }else if(!b){
+ *p=ap;
+ return a;
+ }
+
+ /* yes, this can leak a bit. */
+ if(ap>bp){
+ int shift=ap-bp+1;
+ *p=ap+1;
+ a>>=1;
+ if(shift<32){
+ b=(b+(1<<(shift-1)))>>shift;
+ }else{
+ b=0;
+ }
+ }else{
+ int shift=bp-ap+1;
+ *p=bp+1;
+ b>>=1;
+ if(shift<32){
+ a=(a+(1<<(shift-1)))>>shift;
+ }else{
+ a=0;
+ }
+ }
+
+ a+=b;
+ if((a&0xc0000000)==0xc0000000 ||
+ (a&0xc0000000)==0){
+ a<<=1;
+ (*p)--;
+ }
+ return(a);
+}
+
+#endif
+
+
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/ogg.h b/osframework/source/SexyAppFramework/ogg/ogg.h
new file mode 100644
index 0000000..db83c3b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/ogg.h
@@ -0,0 +1,206 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: subsumed libogg includes
+
+ ********************************************************************/
+#ifndef _OGG_H
+#define _OGG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "os_types.h"
+
+typedef struct ogg_buffer_state{
+ struct ogg_buffer *unused_buffers;
+ struct ogg_reference *unused_references;
+ int outstanding;
+ int shutdown;
+} ogg_buffer_state;
+
+typedef struct ogg_buffer {
+ unsigned char *data;
+ long size;
+ int refcount;
+
+ union {
+ ogg_buffer_state *owner;
+ struct ogg_buffer *next;
+ } ptr;
+} ogg_buffer;
+
+typedef struct ogg_reference {
+ ogg_buffer *buffer;
+ long begin;
+ long length;
+
+ struct ogg_reference *next;
+} ogg_reference;
+
+typedef struct oggpack_buffer {
+ int headbit;
+ unsigned char *headptr;
+ long headend;
+
+ /* memory management */
+ ogg_reference *head;
+ ogg_reference *tail;
+
+ /* render the byte/bit counter API constant time */
+ long count; /* doesn't count the tail */
+} oggpack_buffer;
+
+typedef struct oggbyte_buffer {
+ ogg_reference *baseref;
+
+ ogg_reference *ref;
+ unsigned char *ptr;
+ long pos;
+ long end;
+} oggbyte_buffer;
+
+typedef struct ogg_sync_state {
+ /* decode memory management pool */
+ ogg_buffer_state *bufferpool;
+
+ /* stream buffers */
+ ogg_reference *fifo_head;
+ ogg_reference *fifo_tail;
+ long fifo_fill;
+
+ /* stream sync management */
+ int unsynced;
+ int headerbytes;
+ int bodybytes;
+
+} ogg_sync_state;
+
+typedef struct ogg_stream_state {
+ ogg_reference *header_head;
+ ogg_reference *header_tail;
+ ogg_reference *body_head;
+ ogg_reference *body_tail;
+
+ int e_o_s; /* set when we have buffered the last
+ packet in the logical bitstream */
+ int b_o_s; /* set after we've written the initial page
+ of a logical bitstream */
+ long serialno;
+ long pageno;
+ ogg_int64_t packetno; /* sequence number for decode; the framing
+ knows where there's a hole in the data,
+ but we need coupling so that the codec
+ (which is in a seperate abstraction
+ layer) also knows about the gap */
+ ogg_int64_t granulepos;
+
+ int lacing_fill;
+ ogg_uint32_t body_fill;
+
+ /* decode-side state data */
+ int holeflag;
+ int spanflag;
+ int clearflag;
+ int laceptr;
+ ogg_uint32_t body_fill_next;
+
+} ogg_stream_state;
+
+typedef struct {
+ ogg_reference *packet;
+ long bytes;
+ long b_o_s;
+ long e_o_s;
+ ogg_int64_t granulepos;
+ ogg_int64_t packetno; /* sequence number for decode; the framing
+ knows where there's a hole in the data,
+ but we need coupling so that the codec
+ (which is in a seperate abstraction
+ layer) also knows about the gap */
+} ogg_packet;
+
+typedef struct {
+ ogg_reference *header;
+ int header_len;
+ ogg_reference *body;
+ long body_len;
+} ogg_page;
+
+/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
+
+extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
+extern long oggpack_look(oggpack_buffer *b,int bits);
+extern void oggpack_adv(oggpack_buffer *b,int bits);
+extern long oggpack_read(oggpack_buffer *b,int bits);
+extern long oggpack_bytes(oggpack_buffer *b);
+extern long oggpack_bits(oggpack_buffer *b);
+extern int oggpack_eop(oggpack_buffer *b);
+
+/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
+
+extern ogg_sync_state *ogg_sync_create(void);
+extern int ogg_sync_destroy(ogg_sync_state *oy);
+extern int ogg_sync_reset(ogg_sync_state *oy);
+
+extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
+extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
+extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
+extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
+extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
+extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
+extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
+
+/* Ogg BITSTREAM PRIMITIVES: general ***************************/
+
+extern ogg_stream_state *ogg_stream_create(int serialno);
+extern int ogg_stream_destroy(ogg_stream_state *os);
+extern int ogg_stream_reset(ogg_stream_state *os);
+extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
+extern int ogg_stream_eos(ogg_stream_state *os);
+
+extern int ogg_page_checksum_set(ogg_page *og);
+
+extern int ogg_page_version(ogg_page *og);
+extern int ogg_page_continued(ogg_page *og);
+extern int ogg_page_bos(ogg_page *og);
+extern int ogg_page_eos(ogg_page *og);
+extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
+extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
+extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
+extern int ogg_page_packets(ogg_page *og);
+extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
+
+extern int ogg_packet_release(ogg_packet *op);
+extern int ogg_page_release(ogg_page *og);
+
+extern void ogg_page_dup(ogg_page *d, ogg_page *s);
+
+/* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
+
+#define OGG_SUCCESS 0
+
+#define OGG_HOLE -10
+#define OGG_SPAN -11
+#define OGG_EVERSION -12
+#define OGG_ESERIAL -13
+#define OGG_EINVAL -14
+#define OGG_EEOS -15
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _OGG_H */
diff --git a/osframework/source/SexyAppFramework/ogg/os.h b/osframework/source/SexyAppFramework/ogg/os.h
new file mode 100644
index 0000000..33913bc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/os.h
@@ -0,0 +1,64 @@
+#ifndef _OS_H
+#define _OS_H
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: #ifdef jail to whip a few platforms into the UNIX ideal.
+
+ ********************************************************************/
+
+#include <math.h>
+#define __i386__
+#include "os_types.h"
+
+#ifndef _V_IFDEFJAIL_H_
+# define _V_IFDEFJAIL_H_
+
+# ifdef __GNUC__
+# define STIN static __inline__
+# elif _WIN32
+# pragma warning(disable:4267 4244)
+# define STIN static __inline
+# endif
+#else
+# define STIN static
+#endif
+
+#ifndef M_PI
+# define M_PI (3.1415926536f)
+#endif
+
+#ifdef _WIN32
+# include <malloc.h>
+# define rint(x) (floor((x)+0.5f))
+# define NO_FLOAT_MATH_LIB
+# define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
+#endif
+
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+
+#ifdef USE_MEMORY_H
+# include <memory.h>
+#endif
+
+#ifndef min
+# define min(x,y) ((x)>(y)?(y):(x))
+#endif
+
+#ifndef max
+# define max(x,y) ((x)<(y)?(y):(x))
+#endif
+
+#endif /* _OS_H */
diff --git a/osframework/source/SexyAppFramework/ogg/os_types.h b/osframework/source/SexyAppFramework/ogg/os_types.h
new file mode 100644
index 0000000..93094b7
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/os_types.h
@@ -0,0 +1,88 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: #ifdef jail to whip a few platforms into the UNIX ideal.
+
+ ********************************************************************/
+#ifndef _OS_TYPES_H
+#define _OS_TYPES_H
+
+#ifdef _LOW_ACCURACY_
+# define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9))
+# define LOOKUP_T const unsigned char
+#else
+# define X(n) (n)
+# define LOOKUP_T const ogg_int32_t
+#endif
+
+/* make it easy on the folks that want to compile the libs with a
+ different malloc than stdlib */
+#define _ogg_malloc malloc
+#define _ogg_calloc calloc
+#define _ogg_realloc realloc
+#define _ogg_free free
+
+#ifdef _WIN32
+
+# ifndef __GNUC__
+ /* MSVC/Borland */
+ typedef __int64 ogg_int64_t;
+ typedef __int32 ogg_int32_t;
+ typedef unsigned __int32 ogg_uint32_t;
+ typedef __int16 ogg_int16_t;
+# else
+ /* Cygwin */
+ #include <_G_config.h>
+ typedef _G_int64_t ogg_int64_t;
+ typedef _G_int32_t ogg_int32_t;
+ typedef _G_uint32_t ogg_uint32_t;
+ typedef _G_int16_t ogg_int16_t;
+# endif
+
+#elif defined(__MACOS__)
+
+# include <sys/types.h>
+ typedef SInt16 ogg_int16_t;
+ typedef SInt32 ogg_int32_t;
+ typedef UInt32 ogg_uint32_t;
+ typedef SInt64 ogg_int64_t;
+
+#elif defined(__MACOSX__) /* MacOS X Framework build */
+
+# include <sys/types.h>
+ typedef int16_t ogg_int16_t;
+ typedef int32_t ogg_int32_t;
+ typedef u_int32_t ogg_uint32_t;
+ typedef int64_t ogg_int64_t;
+
+#elif defined(__BEOS__)
+
+ /* Be */
+# include <inttypes.h>
+
+#elif defined (__EMX__)
+
+ /* OS/2 GCC */
+ typedef short ogg_int16_t;
+ typedef int ogg_int32_t;
+ typedef unsigned int ogg_uint32_t;
+ typedef long long ogg_int64_t;
+
+#else
+
+# include <sys/types.h>
+# include "config_types.h"
+
+#endif
+
+#endif /* _OS_TYPES_H */
diff --git a/osframework/source/SexyAppFramework/ogg/registry.c b/osframework/source/SexyAppFramework/ogg/registry.c
new file mode 100644
index 0000000..1dc57bc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/registry.c
@@ -0,0 +1,50 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: registry for floor, res backends and channel mappings
+
+ ********************************************************************/
+
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "registry.h"
+#include "misc.h"
+
+
+/* seems like major overkill now; the backend numbers will grow into
+ the infrastructure soon enough */
+
+extern vorbis_func_floor floor0_exportbundle;
+extern vorbis_func_floor floor1_exportbundle;
+extern vorbis_func_residue residue0_exportbundle;
+extern vorbis_func_residue residue1_exportbundle;
+extern vorbis_func_residue residue2_exportbundle;
+extern vorbis_func_mapping mapping0_exportbundle;
+
+vorbis_func_floor *_floor_P[]={
+ &floor0_exportbundle,
+ &floor1_exportbundle,
+};
+
+vorbis_func_residue *_residue_P[]={
+ &residue0_exportbundle,
+ &residue1_exportbundle,
+ &residue2_exportbundle,
+};
+
+vorbis_func_mapping *_mapping_P[]={
+ &mapping0_exportbundle,
+};
+
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/registry.h b/osframework/source/SexyAppFramework/ogg/registry.h
new file mode 100644
index 0000000..3d7f887
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/registry.h
@@ -0,0 +1,40 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: registry for time, floor, res backends and channel mappings
+
+ ********************************************************************/
+
+#ifndef _V_REG_H_
+#define _V_REG_H_
+
+#define VI_TRANSFORMB 1
+#define VI_WINDOWB 1
+#define VI_TIMEB 1
+#define VI_FLOORB 2
+#define VI_RESB 3
+#define VI_MAPB 1
+
+#include "backends.h"
+
+#if defined(_WIN32) && defined(VORBISDLL_IMPORT)
+# define EXTERN __declspec(dllimport) extern
+#else
+# define EXTERN extern
+#endif
+
+EXTERN vorbis_func_floor *_floor_P[];
+EXTERN vorbis_func_residue *_residue_P[];
+EXTERN vorbis_func_mapping *_mapping_P[];
+
+#endif
diff --git a/osframework/source/SexyAppFramework/ogg/res012.c b/osframework/source/SexyAppFramework/ogg/res012.c
new file mode 100644
index 0000000..447b383
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/res012.c
@@ -0,0 +1,336 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: residue backend 0, 1 and 2 implementation
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "registry.h"
+#include "codebook.h"
+#include "misc.h"
+#include "os.h"
+
+extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
+
+typedef struct {
+ vorbis_info_residue0 *info;
+ int map;
+
+ int parts;
+ int stages;
+ codebook *fullbooks;
+ codebook *phrasebook;
+ codebook ***partbooks;
+
+ int partvals;
+ int **decodemap;
+
+} vorbis_look_residue0;
+
+void res0_free_info(vorbis_info_residue *i){
+ vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
+ if(info){
+ memset(info,0,sizeof(*info));
+ _ogg_free(info);
+ }
+}
+
+void res0_free_look(vorbis_look_residue *i){
+ int j;
+ if(i){
+
+ vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
+
+ for(j=0;j<look->parts;j++)
+ if(look->partbooks[j])_ogg_free(look->partbooks[j]);
+ _ogg_free(look->partbooks);
+ for(j=0;j<look->partvals;j++)
+ _ogg_free(look->decodemap[j]);
+ _ogg_free(look->decodemap);
+
+ memset(look,0,sizeof(*look));
+ _ogg_free(look);
+ }
+}
+
+static int ilog(unsigned int v){
+ int ret=0;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+static int icount(unsigned int v){
+ int ret=0;
+ while(v){
+ ret+=v&1;
+ v>>=1;
+ }
+ return(ret);
+}
+
+/* vorbis_info is for range checking */
+vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
+ int j,acc=0;
+ vorbis_info_residue0 *info=(vorbis_info_residue0 *)_ogg_calloc(1,sizeof(*info));
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+
+ info->begin=oggpack_read(opb,24);
+ info->end=oggpack_read(opb,24);
+ info->grouping=oggpack_read(opb,24)+1;
+ info->partitions=oggpack_read(opb,6)+1;
+ info->groupbook=oggpack_read(opb,8);
+
+ for(j=0;j<info->partitions;j++){
+ int cascade=oggpack_read(opb,3);
+ if(oggpack_read(opb,1))
+ cascade|=(oggpack_read(opb,5)<<3);
+ info->secondstages[j]=cascade;
+
+ acc+=icount(cascade);
+ }
+ for(j=0;j<acc;j++)
+ info->booklist[j]=oggpack_read(opb,8);
+
+ if(info->groupbook>=ci->books)goto errout;
+ for(j=0;j<acc;j++)
+ if(info->booklist[j]>=ci->books)goto errout;
+
+ return(info);
+ errout:
+ res0_free_info(info);
+ return(NULL);
+}
+
+vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
+ vorbis_info_residue *vr){
+ vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
+ vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
+ codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
+
+ int j,k,acc=0;
+ int dim;
+ int maxstage=0;
+ look->info=info;
+ look->map=vm->mapping;
+
+ look->parts=info->partitions;
+ look->fullbooks=ci->fullbooks;
+ look->phrasebook=ci->fullbooks+info->groupbook;
+ dim=look->phrasebook->dim;
+
+ look->partbooks=(codebook ***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
+
+ for(j=0;j<look->parts;j++){
+ int stages=ilog(info->secondstages[j]);
+ if(stages){
+ if(stages>maxstage)maxstage=stages;
+ look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j]));
+ for(k=0;k<stages;k++)
+ if(info->secondstages[j]&(1<<k)){
+ look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
+#ifdef TRAIN_RES
+ look->training_data[k][j]=calloc(look->partbooks[j][k]->entries,
+ sizeof(***look->training_data));
+#endif
+ }
+ }
+ }
+
+ look->partvals=look->parts;
+ for(j=1;j<dim;j++)look->partvals*=look->parts;
+ look->stages=maxstage;
+ look->decodemap=(int **)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
+ for(j=0;j<look->partvals;j++){
+ long val=j;
+ long mult=look->partvals/look->parts;
+ look->decodemap[j]=(int *)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
+ for(k=0;k<dim;k++){
+ long deco=val/mult;
+ val-=deco*mult;
+ mult/=look->parts;
+ look->decodemap[j][k]=deco;
+ }
+ }
+
+ return(look);
+}
+
+
+/* a truncated packet here just means 'stop working'; it's not an error */
+static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
+ ogg_int32_t **in,int ch,
+ long (*decodepart)(codebook *, ogg_int32_t *,
+ oggpack_buffer *,int,int)){
+
+ long i,j,k,l,s;
+ vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
+ vorbis_info_residue0 *info=look->info;
+
+ /* move all this setup out later */
+ int samples_per_partition=info->grouping;
+ int partitions_per_word=look->phrasebook->dim;
+ int n=info->end-info->begin;
+
+ int partvals=n/samples_per_partition;
+ int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
+ int ***partword=(int ***)alloca(ch*sizeof(*partword));
+
+ for(j=0;j<ch;j++)
+ partword[j]=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
+
+ for(s=0;s<look->stages;s++){
+
+ /* each loop decodes on partition codeword containing
+ partitions_pre_word partitions */
+ for(i=0,l=0;i<partvals;l++){
+ if(s==0){
+ /* fetch the partition word for each channel */
+ for(j=0;j<ch;j++){
+ int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
+ if(temp==-1)goto eopbreak;
+ partword[j][l]=look->decodemap[temp];
+ if(partword[j][l]==NULL)goto errout;
+ }
+ }
+
+ /* now we decode residual values for the partitions */
+ for(k=0;k<partitions_per_word && i<partvals;k++,i++)
+ for(j=0;j<ch;j++){
+ long offset=info->begin+i*samples_per_partition;
+ if(info->secondstages[partword[j][l][k]]&(1<<s)){
+ codebook *stagebook=look->partbooks[partword[j][l][k]][s];
+ if(stagebook){
+ if(decodepart(stagebook,in[j]+offset,&vb->opb,
+ samples_per_partition,-8)==-1)goto eopbreak;
+ }
+ }
+ }
+ }
+ }
+
+ errout:
+ eopbreak:
+ return(0);
+}
+
+int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
+ ogg_int32_t **in,int *nonzero,int ch){
+ int i,used=0;
+ for(i=0;i<ch;i++)
+ if(nonzero[i])
+ in[used++]=in[i];
+ if(used)
+ return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
+ else
+ return(0);
+}
+
+int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
+ ogg_int32_t **in,int *nonzero,int ch){
+ int i,used=0;
+ for(i=0;i<ch;i++)
+ if(nonzero[i])
+ in[used++]=in[i];
+ if(used)
+ return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
+ else
+ return(0);
+}
+
+/* duplicate code here as speed is somewhat more important */
+int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
+ ogg_int32_t **in,int *nonzero,int ch){
+ long i,k,l,s;
+ vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
+ vorbis_info_residue0 *info=look->info;
+
+ /* move all this setup out later */
+ int samples_per_partition=info->grouping;
+ int partitions_per_word=look->phrasebook->dim;
+ int n=info->end-info->begin;
+
+ int partvals=n/samples_per_partition;
+ int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
+ int **partword=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
+ int beginoff=info->begin/ch;
+
+ for(i=0;i<ch;i++)if(nonzero[i])break;
+ if(i==ch)return(0); /* no nonzero vectors */
+
+ samples_per_partition/=ch;
+
+ for(s=0;s<look->stages;s++){
+ for(i=0,l=0;i<partvals;l++){
+
+ if(s==0){
+ /* fetch the partition word */
+ int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
+ if(temp==-1)goto eopbreak;
+ partword[l]=look->decodemap[temp];
+ if(partword[l]==NULL)goto errout;
+ }
+
+ /* now we decode residual values for the partitions */
+ for(k=0;k<partitions_per_word && i<partvals;k++,i++)
+ if(info->secondstages[partword[l][k]]&(1<<s)){
+ codebook *stagebook=look->partbooks[partword[l][k]][s];
+
+ if(stagebook){
+ if(vorbis_book_decodevv_add(stagebook,in,
+ i*samples_per_partition+beginoff,ch,
+ &vb->opb,
+ samples_per_partition,-8)==-1)
+ goto eopbreak;
+ }
+ }
+ }
+ }
+
+ errout:
+ eopbreak:
+ return(0);
+}
+
+
+vorbis_func_residue residue0_exportbundle={
+ &res0_unpack,
+ &res0_look,
+ &res0_free_info,
+ &res0_free_look,
+ &res0_inverse
+};
+
+vorbis_func_residue residue1_exportbundle={
+ &res0_unpack,
+ &res0_look,
+ &res0_free_info,
+ &res0_free_look,
+ &res1_inverse
+};
+
+vorbis_func_residue residue2_exportbundle={
+ &res0_unpack,
+ &res0_look,
+ &res0_free_info,
+ &res0_free_look,
+ &res2_inverse
+};
diff --git a/osframework/source/SexyAppFramework/ogg/sharedbook.c b/osframework/source/SexyAppFramework/ogg/sharedbook.c
new file mode 100644
index 0000000..ee54b58
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/sharedbook.c
@@ -0,0 +1,443 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: basic shared codebook operations
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include "ogg.h"
+#include "os.h"
+#include "misc.h"
+#include "ivorbiscodec.h"
+#include "codebook.h"
+
+/**** pack/unpack helpers ******************************************/
+int _ilog(unsigned int v){
+ int ret=0;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+/* 32 bit float (not IEEE; nonnormalized mantissa +
+ biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm
+ Why not IEEE? It's just not that important here. */
+
+#define VQ_FEXP 10
+#define VQ_FMAN 21
+#define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
+
+static ogg_int32_t _float32_unpack(long val,int *point){
+ long mant=val&0x1fffff;
+ int sign=val&0x80000000;
+ long exp =(val&0x7fe00000L)>>VQ_FMAN;
+
+ exp-=(VQ_FMAN-1)+VQ_FEXP_BIAS;
+
+ if(mant){
+ while(!(mant&0x40000000)){
+ mant<<=1;
+ exp-=1;
+ }
+
+ if(sign)mant= -mant;
+ }else{
+ sign=0;
+ exp=-9999;
+ }
+
+ *point=exp;
+ return mant;
+}
+
+/* given a list of word lengths, generate a list of codewords. Works
+ for length ordered or unordered, always assigns the lowest valued
+ codewords first. Extended to handle unused entries (length 0) */
+ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
+ long i,j,count=0;
+ ogg_uint32_t marker[33];
+ ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
+ memset(marker,0,sizeof(marker));
+
+ for(i=0;i<n;i++){
+ long length=l[i];
+ if(length>0){
+ ogg_uint32_t entry=marker[length];
+
+ /* when we claim a node for an entry, we also claim the nodes
+ below it (pruning off the imagined tree that may have dangled
+ from it) as well as blocking the use of any nodes directly
+ above for leaves */
+
+ /* update ourself */
+ if(length<32 && (entry>>length)){
+ /* error condition; the lengths must specify an overpopulated tree */
+ _ogg_free(r);
+ return(NULL);
+ }
+ r[count++]=entry;
+
+ /* Look to see if the next shorter marker points to the node
+ above. if so, update it and repeat. */
+ {
+ for(j=length;j>0;j--){
+
+ if(marker[j]&1){
+ /* have to jump branches */
+ if(j==1)
+ marker[1]++;
+ else
+ marker[j]=marker[j-1]<<1;
+ break; /* invariant says next upper marker would already
+ have been moved if it was on the same path */
+ }
+ marker[j]++;
+ }
+ }
+
+ /* prune the tree; the implicit invariant says all the longer
+ markers were dangling from our just-taken node. Dangle them
+ from our *new* node. */
+ for(j=length+1;j<33;j++)
+ if((marker[j]>>1) == entry){
+ entry=marker[j];
+ marker[j]=marker[j-1]<<1;
+ }else
+ break;
+ }else
+ if(sparsecount==0)count++;
+ }
+
+ /* bitreverse the words because our bitwise packer/unpacker is LSb
+ endian */
+ for(i=0,count=0;i<n;i++){
+ ogg_uint32_t temp=0;
+ for(j=0;j<l[i];j++){
+ temp<<=1;
+ temp|=(r[count]>>j)&1;
+ }
+
+ if(sparsecount){
+ if(l[i])
+ r[count++]=temp;
+ }else
+ r[count++]=temp;
+ }
+
+ return(r);
+}
+
+/* there might be a straightforward one-line way to do the below
+ that's portable and totally safe against roundoff, but I haven't
+ thought of it. Therefore, we opt on the side of caution */
+long _book_maptype1_quantvals(const static_codebook *b){
+ /* get us a starting hint, we'll polish it below */
+ int bits=_ilog(b->entries);
+ int vals=b->entries>>((bits-1)*(b->dim-1)/b->dim);
+
+ while(1){
+ long acc=1;
+ long acc1=1;
+ int i;
+ for(i=0;i<b->dim;i++){
+ acc*=vals;
+ acc1*=vals+1;
+ }
+ if(acc<=b->entries && acc1>b->entries){
+ return(vals);
+ }else{
+ if(acc>b->entries){
+ vals--;
+ }else{
+ vals++;
+ }
+ }
+ }
+}
+
+/* different than what _book_unquantize does for mainline:
+ we repack the book in a fixed point format that shares the same
+ binary point. Upon first use, we can shift point if needed */
+
+/* we need to deal with two map types: in map type 1, the values are
+ generated algorithmically (each column of the vector counts through
+ the values in the quant vector). in map type 2, all the values came
+ in in an explicit list. Both value lists must be unpacked */
+
+ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap,
+ int *maxpoint){
+ long j,k,count=0;
+ if(b->maptype==1 || b->maptype==2){
+ int quantvals;
+ int minpoint,delpoint;
+ ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint);
+ ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint);
+ ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r));
+ int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp));
+
+ *maxpoint=minpoint;
+
+ /* maptype 1 and 2 both use a quantized value vector, but
+ different sizes */
+ switch(b->maptype){
+ case 1:
+ /* most of the time, entries%dimensions == 0, but we need to be
+ well defined. We define that the possible vales at each
+ scalar is values == entries/dim. If entries%dim != 0, we'll
+ have 'too few' values (values*dim<entries), which means that
+ we'll have 'left over' entries; left over entries use zeroed
+ values (and are wasted). So don't generate codebooks like
+ that */
+ quantvals=_book_maptype1_quantvals(b);
+ for(j=0;j<b->entries;j++){
+ if((sparsemap && b->lengthlist[j]) || !sparsemap){
+ ogg_int32_t last=0;
+ int lastpoint=0;
+ int indexdiv=1;
+ for(k=0;k<b->dim;k++){
+ int index= (j/indexdiv)%quantvals;
+ int point;
+ int val=VFLOAT_MULTI(delta,delpoint,
+ abs(b->quantlist[index]),&point);
+
+ val=VFLOAT_ADD(mindel,minpoint,val,point,&point);
+ val=VFLOAT_ADD(last,lastpoint,val,point,&point);
+
+ if(b->q_sequencep){
+ last=val;
+ lastpoint=point;
+ }
+
+ if(sparsemap){
+ r[sparsemap[count]*b->dim+k]=val;
+ rp[sparsemap[count]*b->dim+k]=point;
+ }else{
+ r[count*b->dim+k]=val;
+ rp[count*b->dim+k]=point;
+ }
+ if(*maxpoint<point)*maxpoint=point;
+ indexdiv*=quantvals;
+ }
+ count++;
+ }
+
+ }
+ break;
+ case 2:
+ for(j=0;j<b->entries;j++){
+ if((sparsemap && b->lengthlist[j]) || !sparsemap){
+ ogg_int32_t last=0;
+ int lastpoint=0;
+
+ for(k=0;k<b->dim;k++){
+ int point;
+ int val=VFLOAT_MULTI(delta,delpoint,
+ abs(b->quantlist[j*b->dim+k]),&point);
+
+ val=VFLOAT_ADD(mindel,minpoint,val,point,&point);
+ val=VFLOAT_ADD(last,lastpoint,val,point,&point);
+
+ if(b->q_sequencep){
+ last=val;
+ lastpoint=point;
+ }
+
+ if(sparsemap){
+ r[sparsemap[count]*b->dim+k]=val;
+ rp[sparsemap[count]*b->dim+k]=point;
+ }else{
+ r[count*b->dim+k]=val;
+ rp[count*b->dim+k]=point;
+ }
+ if(*maxpoint<point)*maxpoint=point;
+ }
+ count++;
+ }
+ }
+ break;
+ }
+
+ for(j=0;j<n*b->dim;j++)
+ if(rp[j]<*maxpoint)
+ r[j]>>=*maxpoint-rp[j];
+
+ _ogg_free(rp);
+ return(r);
+ }
+ return(NULL);
+}
+
+void vorbis_staticbook_clear(static_codebook *b){
+ if(b->quantlist)_ogg_free(b->quantlist);
+ if(b->lengthlist)_ogg_free(b->lengthlist);
+ memset(b,0,sizeof(*b));
+
+}
+
+void vorbis_staticbook_destroy(static_codebook *b){
+ vorbis_staticbook_clear(b);
+ _ogg_free(b);
+}
+
+void vorbis_book_clear(codebook *b){
+ /* static book is not cleared; we're likely called on the lookup and
+ the static codebook belongs to the info struct */
+ if(b->valuelist)_ogg_free(b->valuelist);
+ if(b->codelist)_ogg_free(b->codelist);
+
+ if(b->dec_index)_ogg_free(b->dec_index);
+ if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
+ if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
+
+ memset(b,0,sizeof(*b));
+}
+
+static ogg_uint32_t bitreverse(ogg_uint32_t x){
+ x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
+ x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
+ x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
+ x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
+ return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
+}
+
+static int sort32a(const void *a,const void *b){
+ return (**(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
+ (**(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
+}
+
+/* decode codebook arrangement is more heavily optimized than encode */
+int vorbis_book_init_decode(codebook *c,const static_codebook *s){
+ int i,j,n=0,tabn;
+ int *sortindex;
+ memset(c,0,sizeof(*c));
+
+ /* count actually used entries */
+ for(i=0;i<s->entries;i++)
+ if(s->lengthlist[i]>0)
+ n++;
+
+ c->entries=s->entries;
+ c->used_entries=n;
+ c->dim=s->dim;
+
+ c->q_min=s->q_min;
+ c->q_delta=s->q_delta;
+
+ /* two different remappings go on here.
+
+ First, we collapse the likely sparse codebook down only to
+ actually represented values/words. This collapsing needs to be
+ indexed as map-valueless books are used to encode original entry
+ positions as integers.
+
+ Second, we reorder all vectors, including the entry index above,
+ by sorted bitreversed codeword to allow treeless decode. */
+
+ {
+ /* perform sort */
+ ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
+ ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n);
+
+ if(codes==NULL)goto err_out;
+
+ for(i=0;i<n;i++){
+ codes[i]=bitreverse(codes[i]);
+ codep[i]=codes+i;
+ }
+
+ qsort(codep,n,sizeof(*codep),sort32a);
+
+ sortindex=(int *)alloca(n*sizeof(*sortindex));
+ c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist));
+ /* the index is a reverse index */
+ for(i=0;i<n;i++){
+ int position=codep[i]-codes;
+ sortindex[position]=i;
+ }
+
+ for(i=0;i<n;i++)
+ c->codelist[sortindex[i]]=codes[i];
+ _ogg_free(codes);
+ }
+
+
+ c->valuelist=_book_unquantize(s,n,sortindex,&c->binarypoint);
+ c->dec_index=(int *)_ogg_malloc(n*sizeof(*c->dec_index));
+
+ for(n=0,i=0;i<s->entries;i++)
+ if(s->lengthlist[i]>0)
+ c->dec_index[sortindex[n++]]=i;
+
+ c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths));
+ for(n=0,i=0;i<s->entries;i++)
+ if(s->lengthlist[i]>0)
+ c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
+
+ c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
+ if(c->dec_firsttablen<5)c->dec_firsttablen=5;
+ if(c->dec_firsttablen>8)c->dec_firsttablen=8;
+
+ tabn=1<<c->dec_firsttablen;
+ c->dec_firsttable=(ogg_uint32_t *)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
+ c->dec_maxlength=0;
+
+ for(i=0;i<n;i++){
+ if(c->dec_maxlength<c->dec_codelengths[i])
+ c->dec_maxlength=c->dec_codelengths[i];
+ if(c->dec_codelengths[i]<=c->dec_firsttablen){
+ ogg_uint32_t orig=bitreverse(c->codelist[i]);
+ for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
+ c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
+ }
+ }
+
+ /* now fill in 'unused' entries in the firsttable with hi/lo search
+ hints for the non-direct-hits */
+ {
+ ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
+ long lo=0,hi=0;
+
+ for(i=0;i<tabn;i++){
+ ogg_uint32_t word=i<<(32-c->dec_firsttablen);
+ if(c->dec_firsttable[bitreverse(word)]==0){
+ while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
+ while( hi<n && word>=(c->codelist[hi]&mask))hi++;
+
+ /* we only actually have 15 bits per hint to play with here.
+ In order to overflow gracefully (nothing breaks, efficiency
+ just drops), encode as the difference from the extremes. */
+ {
+ unsigned long loval=lo;
+ unsigned long hival=n-hi;
+
+ if(loval>0x7fff)loval=0x7fff;
+ if(hival>0x7fff)hival=0x7fff;
+ c->dec_firsttable[bitreverse(word)]=
+ 0x80000000UL | (loval<<15) | hival;
+ }
+ }
+ }
+ }
+
+
+ return(0);
+ err_out:
+ vorbis_book_clear(c);
+ return(-1);
+}
+
diff --git a/osframework/source/SexyAppFramework/ogg/synthesis.c b/osframework/source/SexyAppFramework/ogg/synthesis.c
new file mode 100644
index 0000000..a8f0673
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/synthesis.c
@@ -0,0 +1,116 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: single-block PCM synthesis
+ last mod: $Id: synthesis.c,v 1.1 2003/06/24 00:46:01 ace Exp $
+
+ ********************************************************************/
+
+#include <stdio.h>
+#include "ogg.h"
+#include "ivorbiscodec.h"
+#include "codec_internal.h"
+#include "registry.h"
+#include "misc.h"
+#include "os.h"
+
+extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
+
+int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
+ vorbis_dsp_state *vd=vb->vd;
+ private_state *b=(private_state *)vd->backend_state;
+ vorbis_info *vi=vd->vi;
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ oggpack_buffer *opb=&vb->opb;
+ int type,mode,i;
+
+ /* first things first. Make sure decode is ready */
+ extern void _vorbis_block_ripcord(vorbis_block *vb);
+ _vorbis_block_ripcord(vb);
+ oggpack_readinit(opb,op->packet);
+
+ /* Check the packet type */
+ if(oggpack_read(opb,1)!=0){
+ /* Oops. This is not an audio data packet */
+ return(OV_ENOTAUDIO);
+ }
+
+ /* read our mode and pre/post windowsize */
+ mode=oggpack_read(opb,b->modebits);
+ if(mode==-1)return(OV_EBADPACKET);
+
+ vb->mode=mode;
+ vb->W=ci->mode_param[mode]->blockflag;
+ if(vb->W){
+ vb->lW=oggpack_read(opb,1);
+ vb->nW=oggpack_read(opb,1);
+ if(vb->nW==-1) return(OV_EBADPACKET);
+ }else{
+ vb->lW=0;
+ vb->nW=0;
+ }
+
+ /* more setup */
+ vb->granulepos=op->granulepos;
+ vb->sequence=op->packetno-3; /* first block is third packet */
+ vb->eofflag=op->e_o_s;
+
+ if(decodep){
+ /* alloc pcm passback storage */
+ vb->pcmend=ci->blocksizes[vb->W];
+ vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
+ for(i=0;i<vi->channels;i++)
+ vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
+
+ /* unpack_header enforces range checking */
+ type=ci->map_type[ci->mode_param[mode]->mapping];
+
+ return(_mapping_P[type]->inverse(vb,b->mode[mode]));
+ }else{
+ /* no pcm */
+ vb->pcmend=0;
+ vb->pcm=NULL;
+
+ return(0);
+ }
+}
+
+long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
+ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
+ oggpack_buffer opb;
+ int mode;
+
+ oggpack_readinit(&opb,op->packet);
+
+ /* Check the packet type */
+ if(oggpack_read(&opb,1)!=0){
+ /* Oops. This is not an audio data packet */
+ return(OV_ENOTAUDIO);
+ }
+
+ {
+ int modebits=0;
+ int v=ci->modes;
+ while(v>1){
+ modebits++;
+ v>>=1;
+ }
+
+ /* read our mode and pre/post windowsize */
+ mode=oggpack_read(&opb,modebits);
+ }
+ if(mode==-1)return(OV_EBADPACKET);
+ return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
+}
+
+
diff --git a/osframework/source/SexyAppFramework/ogg/vorbisfile.c b/osframework/source/SexyAppFramework/ogg/vorbisfile.c
new file mode 100644
index 0000000..274b7a9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/vorbisfile.c
@@ -0,0 +1,1592 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: stdio-based convenience library for opening/seeking/decoding
+ last mod: $Id: vorbisfile.c,v 1.2 2003/06/27 16:54:17 ace Exp $
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <math.h>
+
+#include "ivorbiscodec.h"
+#include "ivorbisfile.h"
+
+#include "os.h"
+#include "misc.h"
+
+/* A 'chained bitstream' is a Vorbis bitstream that contains more than
+ one logical bitstream arranged end to end (the only form of Ogg
+ multiplexing allowed in a Vorbis bitstream; grouping [parallel
+ multiplexing] is not allowed in Vorbis) */
+
+/* A Vorbis file can be played beginning to end (streamed) without
+ worrying ahead of time about chaining (see decoder_example.c). If
+ we have the whole file, however, and want random access
+ (seeking/scrubbing) or desire to know the total length/time of a
+ file, we need to account for the possibility of chaining. */
+
+/* We can handle things a number of ways; we can determine the entire
+ bitstream structure right off the bat, or find pieces on demand.
+ This example determines and caches structure for the entire
+ bitstream, but builds a virtual decoder on the fly when moving
+ between links in the chain. */
+
+/* There are also different ways to implement seeking. Enough
+ information exists in an Ogg bitstream to seek to
+ sample-granularity positions in the output. Or, one can seek by
+ picking some portion of the stream roughly in the desired area if
+ we only want coarse navigation through the stream. */
+
+/*************************************************************************
+ * Many, many internal helpers. The intention is not to be confusing;
+ * rampant duplication and monolithic function implementation would be
+ * harder to understand anyway. The high level functions are last. Begin
+ * grokking near the end of the file */
+
+
+/* read a little more data from the file/pipe into the ogg_sync framer */
+static long _get_data(OggVorbis_File *vf){
+ errno=0;
+ if(vf->datasource){
+ char *buffer=ogg_sync_bufferin(vf->oy,CHUNKSIZE);
+ long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
+ if(bytes>0)ogg_sync_wrote(vf->oy,bytes);
+ if(bytes==0 && errno)return(-1);
+ return(bytes);
+ }else
+ return(0);
+}
+
+/* save a tiny smidge of verbosity to make the code more readable */
+static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
+ if(vf->datasource){
+ (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
+ vf->offset=offset;
+ ogg_sync_reset(vf->oy);
+ }else{
+ /* shouldn't happen unless someone writes a broken callback */
+ return;
+ }
+}
+
+/* The read/seek functions track absolute position within the stream */
+
+/* from the head of the stream, get the next page. boundary specifies
+ if the function is allowed to fetch more data from the stream (and
+ how much) or only use internally buffered data.
+
+ boundary: -1) unbounded search
+ 0) read no additional data; use cached only
+ n) search for a new page beginning for n bytes
+
+ return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD)
+ n) found a page at absolute offset n
+
+ produces a refcounted page */
+
+static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
+ ogg_int64_t boundary){
+ if(boundary>0)boundary+=vf->offset;
+ while(1){
+ long more;
+
+ if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
+ more=ogg_sync_pageseek(vf->oy,og);
+
+ if(more<0){
+ /* skipped n bytes */
+ vf->offset-=more;
+ }else{
+ if(more==0){
+ /* send more paramedics */
+ if(!boundary)return(OV_FALSE);
+ {
+ long ret=_get_data(vf);
+ if(ret==0)return(OV_EOF);
+ if(ret<0)return(OV_EREAD);
+ }
+ }else{
+ /* got a page. Return the offset at the page beginning,
+ advance the internal offset past the page end */
+ ogg_int64_t ret=vf->offset;
+ vf->offset+=more;
+ return(ret);
+
+ }
+ }
+ }
+}
+
+/* find the latest page beginning before the current stream cursor
+ position. Much dirtier than the above as Ogg doesn't have any
+ backward search linkage. no 'readp' as it will certainly have to
+ read. */
+/* returns offset or OV_EREAD, OV_FAULT and produces a refcounted page */
+
+static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
+ ogg_int64_t begin=vf->offset;
+ ogg_int64_t end=begin;
+ ogg_int64_t ret;
+ ogg_int64_t offset=-1;
+
+ while(offset==-1){
+ begin-=CHUNKSIZE;
+ if(begin<0)
+ begin=0;
+ _seek_helper(vf,begin);
+ while(vf->offset<end){
+ ret=_get_next_page(vf,og,end-vf->offset);
+ if(ret==OV_EREAD)return(OV_EREAD);
+ if(ret<0){
+ break;
+ }else{
+ offset=ret;
+ }
+ }
+ }
+
+ /* we have the offset. Actually snork and hold the page now */
+ _seek_helper(vf,offset);
+ ret=_get_next_page(vf,og,CHUNKSIZE);
+ if(ret<0)
+ /* this shouldn't be possible */
+ return(OV_EFAULT);
+
+ return(offset);
+}
+
+/* finds each bitstream link one at a time using a bisection search
+ (has to begin by knowing the offset of the lb's initial page).
+ Recurses for each link so it can alloc the link storage after
+ finding them all, then unroll and fill the cache at the same time */
+static int _bisect_forward_serialno(OggVorbis_File *vf,
+ ogg_int64_t begin,
+ ogg_int64_t searched,
+ ogg_int64_t end,
+ ogg_uint32_t currentno,
+ long m){
+ ogg_int64_t endsearched=end;
+ ogg_int64_t next=end;
+ ogg_page og={0,0,0,0};
+ ogg_int64_t ret;
+
+ /* the below guards against garbage seperating the last and
+ first pages of two links. */
+ while(searched<endsearched){
+ ogg_int64_t bisect;
+
+ if(endsearched-searched<CHUNKSIZE){
+ bisect=searched;
+ }else{
+ bisect=(searched+endsearched)/2;
+ }
+
+ _seek_helper(vf,bisect);
+ ret=_get_next_page(vf,&og,-1);
+ if(ret==OV_EREAD)return(OV_EREAD);
+ if(ret<0 || ogg_page_serialno(&og)!=currentno){
+ endsearched=bisect;
+ if(ret>=0)next=ret;
+ }else{
+ searched=ret+og.header_len+og.body_len;
+ }
+ ogg_page_release(&og);
+ }
+
+ _seek_helper(vf,next);
+ ret=_get_next_page(vf,&og,-1);
+ if(ret==OV_EREAD)return(OV_EREAD);
+
+ if(searched>=end || ret<0){
+ ogg_page_release(&og);
+ vf->links=m+1;
+ vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
+ vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos));
+ vf->offsets[m+1]=searched;
+ }else{
+ ret=_bisect_forward_serialno(vf,next,vf->offset,
+ end,ogg_page_serialno(&og),m+1);
+ ogg_page_release(&og);
+ if(ret==OV_EREAD)return(OV_EREAD);
+ }
+
+ vf->offsets[m]=begin;
+ vf->serialnos[m]=currentno;
+ return(0);
+}
+
+/* uses the local ogg_stream storage in vf; this is important for
+ non-streaming input sources */
+/* consumes the page that's passed in (if any) */
+
+static int _fetch_headers(OggVorbis_File *vf,
+ vorbis_info *vi,
+ vorbis_comment *vc,
+ ogg_uint32_t *serialno,
+ ogg_page *og_ptr){
+ ogg_page og={0,0,0,0};
+ ogg_packet op={0,0,0,0,0,0};
+ int i,ret;
+
+ if(!og_ptr){
+ ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
+ if(llret==OV_EREAD)return(OV_EREAD);
+ if(llret<0)return OV_ENOTVORBIS;
+ og_ptr=&og;
+ }
+
+ ogg_stream_reset_serialno(vf->os,ogg_page_serialno(og_ptr));
+ if(serialno)*serialno=vf->os->serialno;
+ vf->ready_state=STREAMSET;
+
+ /* extract the initial header from the first page and verify that the
+ Ogg bitstream is in fact Vorbis data */
+
+ vorbis_info_init(vi);
+ vorbis_comment_init(vc);
+
+ i=0;
+ while(i<3){
+ ogg_stream_pagein(vf->os,og_ptr);
+ while(i<3){
+ int result=ogg_stream_packetout(vf->os,&op);
+ if(result==0)break;
+ if(result==-1){
+ ret=OV_EBADHEADER;
+ goto bail_header;
+ }
+ if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
+ goto bail_header;
+ }
+ i++;
+ }
+ if(i<3)
+ if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
+ ret=OV_EBADHEADER;
+ goto bail_header;
+ }
+ }
+
+ ogg_packet_release(&op);
+ ogg_page_release(&og);
+ return 0;
+
+ bail_header:
+ ogg_packet_release(&op);
+ ogg_page_release(&og);
+ vorbis_info_clear(vi);
+ vorbis_comment_clear(vc);
+ vf->ready_state=OPENED;
+
+ return ret;
+}
+
+/* last step of the OggVorbis_File initialization; get all the
+ vorbis_info structs and PCM positions. Only called by the seekable
+ initialization (local stream storage is hacked slightly; pay
+ attention to how that's done) */
+
+/* this is void and does not propogate errors up because we want to be
+ able to open and use damaged bitstreams as well as we can. Just
+ watch out for missing information for links in the OggVorbis_File
+ struct */
+static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
+ ogg_page og={0,0,0,0};
+ int i;
+ ogg_int64_t ret;
+
+ vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
+ vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
+ vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
+ vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
+
+ for(i=0;i<vf->links;i++){
+ if(i==0){
+ /* we already grabbed the initial header earlier. Just set the offset */
+ vf->dataoffsets[i]=dataoffset;
+ _seek_helper(vf,dataoffset);
+
+ }else{
+
+ /* seek to the location of the initial header */
+
+ _seek_helper(vf,vf->offsets[i]);
+ if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
+ vf->dataoffsets[i]=-1;
+ }else{
+ vf->dataoffsets[i]=vf->offset;
+ }
+ }
+
+ /* fetch beginning PCM offset */
+
+ if(vf->dataoffsets[i]!=-1){
+ ogg_int64_t accumulated=0,pos;
+ long lastblock=-1;
+ int result;
+
+ ogg_stream_reset_serialno(vf->os,vf->serialnos[i]);
+
+ while(1){
+ ogg_packet op={0,0,0,0,0,0};
+
+ ret=_get_next_page(vf,&og,-1);
+ if(ret<0)
+ /* this should not be possible unless the file is
+ truncated/mangled */
+ break;
+
+ if(ogg_page_serialno(&og)!=vf->serialnos[i])
+ break;
+
+ pos=ogg_page_granulepos(&og);
+
+ /* count blocksizes of all frames in the page */
+ ogg_stream_pagein(vf->os,&og);
+ while((result=ogg_stream_packetout(vf->os,&op))){
+ if(result>0){ /* ignore holes */
+ long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
+ if(lastblock!=-1)
+ accumulated+=(lastblock+thisblock)>>2;
+ lastblock=thisblock;
+ }
+ }
+ ogg_packet_release(&op);
+
+ if(pos!=-1){
+ /* pcm offset of last packet on the first audio page */
+ accumulated= pos-accumulated;
+ break;
+ }
+ }
+
+ /* less than zero? This is a stream with samples trimmed off
+ the beginning, a normal occurrence; set the offset to zero */
+ if(accumulated<0)accumulated=0;
+
+ vf->pcmlengths[i*2]=accumulated;
+ }
+
+ /* get the PCM length of this link. To do this,
+ get the last page of the stream */
+ {
+ ogg_int64_t end=vf->offsets[i+1];
+ _seek_helper(vf,end);
+
+ while(1){
+ ret=_get_prev_page(vf,&og);
+ if(ret<0){
+ /* this should not be possible */
+ vorbis_info_clear(vf->vi+i);
+ vorbis_comment_clear(vf->vc+i);
+ break;
+ }
+ if(ogg_page_granulepos(&og)!=-1){
+ vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
+ break;
+ }
+ vf->offset=ret;
+ }
+ }
+ }
+ ogg_page_release(&og);
+}
+
+static void _make_decode_ready(OggVorbis_File *vf){
+ if(vf->ready_state!=STREAMSET)return;
+ if(vf->seekable){
+ vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link);
+ }else{
+ vorbis_synthesis_init(&vf->vd,vf->vi);
+ }
+ vorbis_block_init(&vf->vd,&vf->vb);
+ vf->ready_state=INITSET;
+ vf->bittrack=0;
+ vf->samptrack=0;
+ return;
+}
+
+static int _open_seekable2(OggVorbis_File *vf){
+ ogg_uint32_t serialno=vf->current_serialno;
+ ogg_uint32_t tempserialno;
+ ogg_int64_t dataoffset=vf->offset, end;
+ ogg_page og={0,0,0,0};
+
+ /* we're partially open and have a first link header state in
+ storage in vf */
+ /* we can seek, so set out learning all about this file */
+ (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
+ vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
+
+ /* We get the offset for the last page of the physical bitstream.
+ Most OggVorbis files will contain a single logical bitstream */
+ end=_get_prev_page(vf,&og);
+ if(end<0)return(end);
+
+ /* more than one logical bitstream? */
+ tempserialno=ogg_page_serialno(&og);
+ ogg_page_release(&og);
+
+ if(tempserialno!=serialno){
+
+ /* Chained bitstream. Bisect-search each logical bitstream
+ section. Do so based on serial number only */
+ if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
+
+ }else{
+
+ /* Only one logical bitstream */
+ if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
+
+ }
+
+ /* the initial header memory is referenced by vf after; don't free it */
+ _prefetch_all_headers(vf,dataoffset);
+ return(ov_raw_seek(vf,0));
+}
+
+/* clear out the current logical bitstream decoder */
+static void _decode_clear(OggVorbis_File *vf){
+ vorbis_dsp_clear(&vf->vd);
+ vorbis_block_clear(&vf->vb);
+ vf->ready_state=OPENED;
+}
+
+/* fetch and process a packet. Handles the case where we're at a
+ bitstream boundary and dumps the decoding machine. If the decoding
+ machine is unloaded, it loads it. It also keeps pcm_offset up to
+ date (seek and read both use this. seek uses a special hack with
+ readp).
+
+ return: <0) error, OV_HOLE (lost packet) or OV_EOF
+ 0) need more data (only if readp==0)
+ 1) got a packet
+*/
+
+static int _fetch_and_process_packet(OggVorbis_File *vf,
+ int readp,
+ int spanp){
+ ogg_page og={0,0,0,0};
+ ogg_packet op={0,0,0,0,0,0};
+ int ret=0;
+
+ /* handle one packet. Try to fetch it from current stream state */
+ /* extract packets from page */
+ while(1){
+
+ /* process a packet if we can. If the machine isn't loaded,
+ neither is a page */
+ if(vf->ready_state==INITSET){
+ while(1) {
+ int result=ogg_stream_packetout(vf->os,&op);
+ ogg_int64_t granulepos;
+
+ if(result<0){
+ ret=OV_HOLE; /* hole in the data. */
+ goto cleanup;
+ }
+ if(result>0){
+ /* got a packet. process it */
+ granulepos=op.granulepos;
+ if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy
+ header handling. The
+ header packets aren't
+ audio, so if/when we
+ submit them,
+ vorbis_synthesis will
+ reject them */
+
+ /* suck in the synthesis data and track bitrate */
+ {
+ int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
+ /* for proper use of libvorbis within libvorbisfile,
+ oldsamples will always be zero. */
+ if(oldsamples){
+ ret=OV_EFAULT;
+ goto cleanup;
+ }
+
+ vorbis_synthesis_blockin(&vf->vd,&vf->vb);
+ vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
+ vf->bittrack+=op.bytes*8;
+ }
+
+ /* update the pcm offset. */
+ if(granulepos!=-1 && !op.e_o_s){
+ int link=(vf->seekable?vf->current_link:0);
+ int i,samples;
+
+ /* this packet has a pcm_offset on it (the last packet
+ completed on a page carries the offset) After processing
+ (above), we know the pcm position of the *last* sample
+ ready to be returned. Find the offset of the *first*
+
+ As an aside, this trick is inaccurate if we begin
+ reading anew right at the last page; the end-of-stream
+ granulepos declares the last frame in the stream, and the
+ last packet of the last page may be a partial frame.
+ So, we need a previous granulepos from an in-sequence page
+ to have a reference point. Thus the !op.e_o_s clause
+ above */
+
+ if(vf->seekable && link>0)
+ granulepos-=vf->pcmlengths[link*2];
+ if(granulepos<0)granulepos=0; /* actually, this
+ shouldn't be possible
+ here unless the stream
+ is very broken */
+
+ samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
+
+ granulepos-=samples;
+ for(i=0;i<link;i++)
+ granulepos+=vf->pcmlengths[i*2+1];
+ vf->pcm_offset=granulepos;
+ }
+ ret=1;
+ goto cleanup;
+ }
+ }
+ else
+ break;
+ }
+ }
+
+ if(vf->ready_state>=OPENED){
+ int ret;
+ if(!readp){
+ ret=0;
+ goto cleanup;
+ }
+ if((ret=_get_next_page(vf,&og,-1))<0){
+ ret=OV_EOF; /* eof. leave unitialized */
+ goto cleanup;
+ }
+
+ /* bitrate tracking; add the header's bytes here, the body bytes
+ are done by packet above */
+ vf->bittrack+=og.header_len*8;
+
+ /* has our decoding just traversed a bitstream boundary? */
+ if(vf->ready_state==INITSET){
+ if(vf->current_serialno!=ogg_page_serialno(&og)){
+ if(!spanp){
+ ret=OV_EOF;
+ goto cleanup;
+ }
+
+ _decode_clear(vf);
+
+ if(!vf->seekable){
+ vorbis_info_clear(vf->vi);
+ vorbis_comment_clear(vf->vc);
+ }
+ }
+ }
+ }
+
+ /* Do we need to load a new machine before submitting the page? */
+ /* This is different in the seekable and non-seekable cases.
+
+ In the seekable case, we already have all the header
+ information loaded and cached; we just initialize the machine
+ with it and continue on our merry way.
+
+ In the non-seekable (streaming) case, we'll only be at a
+ boundary if we just left the previous logical bitstream and
+ we're now nominally at the header of the next bitstream
+ */
+
+ if(vf->ready_state!=INITSET){
+ int link;
+
+ if(vf->ready_state<STREAMSET){
+ if(vf->seekable){
+ vf->current_serialno=ogg_page_serialno(&og);
+
+ /* match the serialno to bitstream section. We use this rather than
+ offset positions to avoid problems near logical bitstream
+ boundaries */
+ for(link=0;link<vf->links;link++)
+ if(vf->serialnos[link]==vf->current_serialno)break;
+ if(link==vf->links){
+ ret=OV_EBADLINK; /* sign of a bogus stream. error out,
+ leave machine uninitialized */
+ goto cleanup;
+ }
+
+ vf->current_link=link;
+
+ ogg_stream_reset_serialno(vf->os,vf->current_serialno);
+ vf->ready_state=STREAMSET;
+
+ }else{
+ /* we're streaming */
+ /* fetch the three header packets, build the info struct */
+
+ int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
+ if(ret) goto cleanup;
+ vf->current_link++;
+ link=0;
+ }
+ }
+
+ _make_decode_ready(vf);
+ }
+ ogg_stream_pagein(vf->os,&og);
+ }
+ cleanup:
+ ogg_packet_release(&op);
+ ogg_page_release(&og);
+ return ret;
+}
+
+/* if, eg, 64 bit stdio is configured by default, this will build with
+ fseek64 */
+static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
+ if(f==NULL)return(-1);
+ return fseek(f,(long)off,whence);
+}
+
+static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
+ long ibytes, ov_callbacks callbacks){
+ int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
+ int ret;
+
+ memset(vf,0,sizeof(*vf));
+ vf->datasource=f;
+ vf->callbacks = callbacks;
+
+ /* init the framing state */
+ vf->oy=ogg_sync_create();
+
+ /* perhaps some data was previously read into a buffer for testing
+ against other stream types. Allow initialization from this
+ previously read data (as we may be reading from a non-seekable
+ stream) */
+ if(initial){
+ char *buffer=ogg_sync_bufferin(vf->oy,ibytes);
+ memcpy(buffer,initial,ibytes);
+ ogg_sync_wrote(vf->oy,ibytes);
+ }
+
+ /* can we seek? Stevens suggests the seek test was portable */
+ if(offsettest!=-1)vf->seekable=1;
+
+ /* No seeking yet; Set up a 'single' (current) logical bitstream
+ entry for partial open */
+ vf->links=1;
+ vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi));
+ vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc));
+ vf->os=ogg_stream_create(-1); /* fill in the serialno later */
+
+ /* Try to fetch the headers, maintaining all the storage */
+ if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
+ vf->datasource=NULL;
+ ov_clear(vf);
+ }else if(vf->ready_state < PARTOPEN)
+ vf->ready_state=PARTOPEN;
+ return(ret);
+}
+
+static int _ov_open2(OggVorbis_File *vf){
+ if(vf->ready_state < OPENED)
+ vf->ready_state=OPENED;
+ if(vf->seekable){
+ int ret=_open_seekable2(vf);
+ if(ret){
+ vf->datasource=NULL;
+ ov_clear(vf);
+ }
+ return(ret);
+ }
+ return 0;
+}
+
+
+/* clear out the OggVorbis_File struct */
+int ov_clear(OggVorbis_File *vf){
+ if(vf){
+ vorbis_block_clear(&vf->vb);
+ vorbis_dsp_clear(&vf->vd);
+ ogg_stream_destroy(vf->os);
+
+ if(vf->vi && vf->links){
+ int i;
+ for(i=0;i<vf->links;i++){
+ vorbis_info_clear(vf->vi+i);
+ vorbis_comment_clear(vf->vc+i);
+ }
+ _ogg_free(vf->vi);
+ _ogg_free(vf->vc);
+ }
+ if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
+ if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
+ if(vf->serialnos)_ogg_free(vf->serialnos);
+ if(vf->offsets)_ogg_free(vf->offsets);
+ ogg_sync_destroy(vf->oy);
+
+ if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
+ memset(vf,0,sizeof(*vf));
+ }
+#ifdef DEBUG_LEAKS
+ _VDBG_dump();
+#endif
+ return(0);
+}
+
+/* inspects the OggVorbis file and finds/documents all the logical
+ bitstreams contained in it. Tries to be tolerant of logical
+ bitstream sections that are truncated/woogie.
+
+ return: -1) error
+ 0) OK
+*/
+
+int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
+ ov_callbacks callbacks){
+ int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
+ if(ret)return ret;
+ return _ov_open2(vf);
+}
+
+int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
+ ov_callbacks callbacks = {
+ (size_t (*)(void *, size_t, size_t, void *)) fread,
+ (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
+ (int (*)(void *)) fclose,
+ (long (*)(void *)) ftell
+ };
+
+ return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
+}
+
+/* Only partially open the vorbis file; test for Vorbisness, and load
+ the headers for the first chain. Do not seek (although test for
+ seekability). Use ov_test_open to finish opening the file, else
+ ov_clear to close/free it. Same return codes as open. */
+
+int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
+ ov_callbacks callbacks)
+{
+ return _ov_open1(f,vf,initial,ibytes,callbacks);
+}
+
+int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
+ ov_callbacks callbacks = {
+ (size_t (*)(void *, size_t, size_t, void *)) fread,
+ (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
+ (int (*)(void *)) fclose,
+ (long (*)(void *)) ftell
+ };
+
+ return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
+}
+
+int ov_test_open(OggVorbis_File *vf){
+ if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
+ return _ov_open2(vf);
+}
+
+/* How many logical bitstreams in this physical bitstream? */
+long ov_streams(OggVorbis_File *vf){
+ return vf->links;
+}
+
+/* Is the FILE * associated with vf seekable? */
+long ov_seekable(OggVorbis_File *vf){
+ return vf->seekable;
+}
+
+/* returns the bitrate for a given logical bitstream or the entire
+ physical bitstream. If the file is open for random access, it will
+ find the *actual* average bitrate. If the file is streaming, it
+ returns the nominal bitrate (if set) else the average of the
+ upper/lower bounds (if set) else -1 (unset).
+
+ If you want the actual bitrate field settings, get them from the
+ vorbis_info structs */
+
+long ov_bitrate(OggVorbis_File *vf,int i){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(i>=vf->links)return(OV_EINVAL);
+ if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
+ if(i<0){
+ ogg_int64_t bits=0;
+ int i;
+ for(i=0;i<vf->links;i++)
+ bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
+ /* This once read: return(rint(bits/ov_time_total(vf,-1)));
+ * gcc 3.x on x86 miscompiled this at optimisation level 2 and above,
+ * so this is slightly transformed to make it work.
+ */
+ return(bits*1000/ov_time_total(vf,-1));
+ }else{
+ if(vf->seekable){
+ /* return the actual bitrate */
+ return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i));
+ }else{
+ /* return nominal if set */
+ if(vf->vi[i].bitrate_nominal>0){
+ return vf->vi[i].bitrate_nominal;
+ }else{
+ if(vf->vi[i].bitrate_upper>0){
+ if(vf->vi[i].bitrate_lower>0){
+ return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
+ }else{
+ return vf->vi[i].bitrate_upper;
+ }
+ }
+ return(OV_FALSE);
+ }
+ }
+ }
+}
+
+/* returns the actual bitrate since last call. returns -1 if no
+ additional data to offer since last call (or at beginning of stream),
+ EINVAL if stream is only partially open
+*/
+long ov_bitrate_instant(OggVorbis_File *vf){
+ int link=(vf->seekable?vf->current_link:0);
+ long ret;
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(vf->samptrack==0)return(OV_FALSE);
+ ret=vf->bittrack/vf->samptrack*vf->vi[link].rate;
+ vf->bittrack=0;
+ vf->samptrack=0;
+ return(ret);
+}
+
+/* Guess */
+long ov_serialnumber(OggVorbis_File *vf,int i){
+ if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
+ if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
+ if(i<0){
+ return(vf->current_serialno);
+ }else{
+ return(vf->serialnos[i]);
+ }
+}
+
+/* returns: total raw (compressed) length of content if i==-1
+ raw (compressed) length of that logical bitstream for i==0 to n
+ OV_EINVAL if the stream is not seekable (we can't know the length)
+ or if stream is only partially open
+*/
+ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
+ if(i<0){
+ ogg_int64_t acc=0;
+ int i;
+ for(i=0;i<vf->links;i++)
+ acc+=ov_raw_total(vf,i);
+ return(acc);
+ }else{
+ return(vf->offsets[i+1]-vf->offsets[i]);
+ }
+}
+
+/* returns: total PCM length (samples) of content if i==-1 PCM length
+ (samples) of that logical bitstream for i==0 to n
+ OV_EINVAL if the stream is not seekable (we can't know the
+ length) or only partially open
+*/
+ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
+ if(i<0){
+ ogg_int64_t acc=0;
+ int i;
+ for(i=0;i<vf->links;i++)
+ acc+=ov_pcm_total(vf,i);
+ return(acc);
+ }else{
+ return(vf->pcmlengths[i*2+1]);
+ }
+}
+
+/* returns: total milliseconds of content if i==-1
+ milliseconds in that logical bitstream for i==0 to n
+ OV_EINVAL if the stream is not seekable (we can't know the
+ length) or only partially open
+*/
+ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
+ if(i<0){
+ ogg_int64_t acc=0;
+ int i;
+ for(i=0;i<vf->links;i++)
+ acc+=ov_time_total(vf,i);
+ return(acc);
+ }else{
+ return(((ogg_int64_t)vf->pcmlengths[i*2+1])*1000/vf->vi[i].rate);
+ }
+}
+
+/* seek to an offset relative to the *compressed* data. This also
+ scans packets to update the PCM cursor. It will cross a logical
+ bitstream boundary, but only if it can't get any packets out of the
+ tail of the bitstream we seek to (so no surprises).
+
+ returns zero on success, nonzero on failure */
+
+int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
+ ogg_stream_state *work_os=NULL;
+ ogg_page og={0,0,0,0};
+ ogg_packet op={0,0,0,0,0,0};
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable)
+ return(OV_ENOSEEK); /* don't dump machine if we can't seek */
+
+ if(pos<0 || pos>vf->end)return(OV_EINVAL);
+
+ /* don't yet clear out decoding machine (if it's initialized), in
+ the case we're in the same link. Restart the decode lapping, and
+ let _fetch_and_process_packet deal with a potential bitstream
+ boundary */
+ vf->pcm_offset=-1;
+ ogg_stream_reset_serialno(vf->os,
+ vf->current_serialno); /* must set serialno */
+ vorbis_synthesis_restart(&vf->vd);
+
+ _seek_helper(vf,pos);
+
+ /* we need to make sure the pcm_offset is set, but we don't want to
+ advance the raw cursor past good packets just to get to the first
+ with a granulepos. That's not equivalent behavior to beginning
+ decoding as immediately after the seek position as possible.
+
+ So, a hack. We use two stream states; a local scratch state and
+ the shared vf->os stream state. We use the local state to
+ scan, and the shared state as a buffer for later decode.
+
+ Unfortuantely, on the last page we still advance to last packet
+ because the granulepos on the last page is not necessarily on a
+ packet boundary, and we need to make sure the granpos is
+ correct.
+ */
+
+ {
+ int lastblock=0;
+ int accblock=0;
+ int thisblock;
+ int eosflag;
+
+ work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */
+ while(1){
+ if(vf->ready_state>=STREAMSET){
+ /* snarf/scan a packet if we can */
+ int result=ogg_stream_packetout(work_os,&op);
+
+ if(result>0){
+
+ if(vf->vi[vf->current_link].codec_setup){
+ thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
+ if(thisblock<0){
+ ogg_stream_packetout(vf->os,NULL);
+ thisblock=0;
+ }else{
+
+ if(eosflag)
+ ogg_stream_packetout(vf->os,NULL);
+ else
+ if(lastblock)accblock+=(lastblock+thisblock)>>2;
+ }
+
+ if(op.granulepos!=-1){
+ int i,link=vf->current_link;
+ ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
+ if(granulepos<0)granulepos=0;
+
+ for(i=0;i<link;i++)
+ granulepos+=vf->pcmlengths[i*2+1];
+ vf->pcm_offset=granulepos-accblock;
+ break;
+ }
+ lastblock=thisblock;
+ continue;
+ }else
+ ogg_stream_packetout(vf->os,NULL);
+ }
+ }
+
+ if(!lastblock){
+ if(_get_next_page(vf,&og,-1)<0){
+ vf->pcm_offset=ov_pcm_total(vf,-1);
+ break;
+ }
+ }else{
+ /* huh? Bogus stream with packets but no granulepos */
+ vf->pcm_offset=-1;
+ break;
+ }
+
+ /* has our decoding just traversed a bitstream boundary? */
+ if(vf->ready_state>=STREAMSET)
+ if(vf->current_serialno!=ogg_page_serialno(&og)){
+ _decode_clear(vf); /* clear out stream state */
+ ogg_stream_destroy(work_os);
+ }
+
+ if(vf->ready_state<STREAMSET){
+ int link;
+
+ vf->current_serialno=ogg_page_serialno(&og);
+ for(link=0;link<vf->links;link++)
+ if(vf->serialnos[link]==vf->current_serialno)break;
+ if(link==vf->links)
+ goto seek_error; /* sign of a bogus stream. error out,
+ leave machine uninitialized */
+
+ vf->current_link=link;
+
+ ogg_stream_reset_serialno(vf->os,vf->current_serialno);
+ ogg_stream_reset_serialno(work_os,vf->current_serialno);
+ vf->ready_state=STREAMSET;
+
+ }
+
+ {
+ ogg_page dup;
+ ogg_page_dup(&dup,&og);
+ eosflag=ogg_page_eos(&og);
+ ogg_stream_pagein(vf->os,&og);
+ ogg_stream_pagein(work_os,&dup);
+ }
+ }
+ }
+
+ ogg_packet_release(&op);
+ ogg_page_release(&og);
+ ogg_stream_destroy(work_os);
+ vf->bittrack=0;
+ vf->samptrack=0;
+ return(0);
+
+ seek_error:
+ ogg_packet_release(&op);
+ ogg_page_release(&og);
+
+ /* dump the machine so we're in a known state */
+ vf->pcm_offset=-1;
+ ogg_stream_destroy(work_os);
+ _decode_clear(vf);
+ return OV_EBADLINK;
+}
+
+/* Page granularity seek (faster than sample granularity because we
+ don't do the last bit of decode to find a specific sample).
+
+ Seek to the last [granule marked] page preceeding the specified pos
+ location, such that decoding past the returned point will quickly
+ arrive at the requested position. */
+int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
+ int link=-1;
+ ogg_int64_t result=0;
+ ogg_int64_t total=ov_pcm_total(vf,-1);
+ ogg_page og={0,0,0,0};
+ ogg_packet op={0,0,0,0,0,0};
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(pos<0 || pos>total)return(OV_EINVAL);
+
+ /* which bitstream section does this pcm offset occur in? */
+ for(link=vf->links-1;link>=0;link--){
+ total-=vf->pcmlengths[link*2+1];
+ if(pos>=total)break;
+ }
+
+ /* search within the logical bitstream for the page with the highest
+ pcm_pos preceeding (or equal to) pos. There is a danger here;
+ missing pages or incorrect frame number information in the
+ bitstream could make our task impossible. Account for that (it
+ would be an error condition) */
+
+ /* new search algorithm by HB (Nicholas Vinen) */
+ {
+ ogg_int64_t end=vf->offsets[link+1];
+ ogg_int64_t begin=vf->offsets[link];
+ ogg_int64_t begintime = vf->pcmlengths[link*2];
+ ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
+ ogg_int64_t target=pos-total+begintime;
+ ogg_int64_t best=begin;
+
+ while(begin<end){
+ ogg_int64_t bisect;
+
+ if(end-begin<CHUNKSIZE){
+ bisect=begin;
+ }else{
+ /* take a (pretty decent) guess. */
+ bisect=begin +
+ (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
+ if(bisect<=begin)
+ bisect=begin+1;
+ }
+
+ _seek_helper(vf,bisect);
+
+ while(begin<end){
+ result=_get_next_page(vf,&og,end-vf->offset);
+ if(result==OV_EREAD) goto seek_error;
+ if(result<0){
+ if(bisect<=begin+1)
+ end=begin; /* found it */
+ else{
+ if(bisect==0) goto seek_error;
+ bisect-=CHUNKSIZE;
+ if(bisect<=begin)bisect=begin+1;
+ _seek_helper(vf,bisect);
+ }
+ }else{
+ ogg_int64_t granulepos=ogg_page_granulepos(&og);
+ if(granulepos==-1)continue;
+ if(granulepos<target){
+ best=result; /* raw offset of packet with granulepos */
+ begin=vf->offset; /* raw offset of next page */
+ begintime=granulepos;
+
+ if(target-begintime>44100)break;
+ bisect=begin; /* *not* begin + 1 */
+ }else{
+ if(bisect<=begin+1)
+ end=begin; /* found it */
+ else{
+ if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
+ end=result;
+ bisect-=CHUNKSIZE; /* an endless loop otherwise. */
+ if(bisect<=begin)bisect=begin+1;
+ _seek_helper(vf,bisect);
+ }else{
+ end=result;
+ endtime=granulepos;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* found our page. seek to it, update pcm offset. Easier case than
+ raw_seek, don't keep packets preceeding granulepos. */
+ {
+
+ /* seek */
+ _seek_helper(vf,best);
+ vf->pcm_offset=-1;
+
+ if(_get_next_page(vf,&og,-1)<0){
+ ogg_page_release(&og);
+ return(OV_EOF); /* shouldn't happen */
+ }
+
+ if(link!=vf->current_link){
+ /* Different link; dump entire decode machine */
+ _decode_clear(vf);
+
+ vf->current_link=link;
+ vf->current_serialno=ogg_page_serialno(&og);
+ vf->ready_state=STREAMSET;
+
+ }else{
+ vorbis_synthesis_restart(&vf->vd);
+ }
+
+ ogg_stream_reset_serialno(vf->os,vf->current_serialno);
+ ogg_stream_pagein(vf->os,&og);
+
+ /* pull out all but last packet; the one with granulepos */
+ while(1){
+ result=ogg_stream_packetpeek(vf->os,&op);
+ if(result==0){
+ /* !!! the packet finishing this page originated on a
+ preceeding page. Keep fetching previous pages until we
+ get one with a granulepos or without the 'continued' flag
+ set. Then just use raw_seek for simplicity. */
+
+ _seek_helper(vf,best);
+
+ while(1){
+ result=_get_prev_page(vf,&og);
+ if(result<0) goto seek_error;
+ if(ogg_page_granulepos(&og)>-1 ||
+ !ogg_page_continued(&og)){
+ return ov_raw_seek(vf,result);
+ }
+ vf->offset=result;
+ }
+ }
+ if(result<0){
+ result = OV_EBADPACKET;
+ goto seek_error;
+ }
+ if(op.granulepos!=-1){
+ vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
+ if(vf->pcm_offset<0)vf->pcm_offset=0;
+ vf->pcm_offset+=total;
+ break;
+ }else
+ result=ogg_stream_packetout(vf->os,NULL);
+ }
+ }
+ }
+
+ /* verify result */
+ if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
+ result=OV_EFAULT;
+ goto seek_error;
+ }
+ vf->bittrack=0;
+ vf->samptrack=0;
+
+ ogg_page_release(&og);
+ ogg_packet_release(&op);
+ return(0);
+
+ seek_error:
+
+ ogg_page_release(&og);
+ ogg_packet_release(&op);
+
+ /* dump machine so we're in a known state */
+ vf->pcm_offset=-1;
+ _decode_clear(vf);
+ return (int)result;
+}
+
+/* seek to a sample offset relative to the decompressed pcm stream
+ returns zero on success, nonzero on failure */
+
+int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
+ ogg_packet op={0,0,0,0,0,0};
+ ogg_page og={0,0,0,0};
+ int thisblock,lastblock=0;
+ int ret=ov_pcm_seek_page(vf,pos);
+ if(ret<0)return(ret);
+ _make_decode_ready(vf);
+
+ /* discard leading packets we don't need for the lapping of the
+ position we want; don't decode them */
+
+ while(1){
+
+ int ret=ogg_stream_packetpeek(vf->os,&op);
+ if(ret>0){
+ thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
+ if(thisblock<0){
+ ogg_stream_packetout(vf->os,NULL);
+ continue; /* non audio packet */
+ }
+ if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
+
+ if(vf->pcm_offset+((thisblock+
+ vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
+
+ /* remove the packet from packet queue and track its granulepos */
+ ogg_stream_packetout(vf->os,NULL);
+ vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with
+ only tracking, no
+ pcm_decode */
+ vorbis_synthesis_blockin(&vf->vd,&vf->vb);
+
+ /* end of logical stream case is hard, especially with exact
+ length positioning. */
+
+ if(op.granulepos>-1){
+ int i;
+ /* always believe the stream markers */
+ vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
+ if(vf->pcm_offset<0)vf->pcm_offset=0;
+ for(i=0;i<vf->current_link;i++)
+ vf->pcm_offset+=vf->pcmlengths[i*2+1];
+ }
+
+ lastblock=thisblock;
+
+ }else{
+ if(ret<0 && ret!=OV_HOLE)break;
+
+ /* suck in a new page */
+ if(_get_next_page(vf,&og,-1)<0)break;
+ if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
+
+ if(vf->ready_state<STREAMSET){
+ int link;
+
+ vf->current_serialno=ogg_page_serialno(&og);
+ for(link=0;link<vf->links;link++)
+ if(vf->serialnos[link]==vf->current_serialno)break;
+ if(link==vf->links){
+ ogg_page_release(&og);
+ ogg_packet_release(&op);
+ return(OV_EBADLINK);
+ }
+ vf->current_link=link;
+
+ ogg_stream_reset_serialno(vf->os,vf->current_serialno);
+ vf->ready_state=STREAMSET;
+ _make_decode_ready(vf);
+ lastblock=0;
+ }
+
+ ogg_stream_pagein(vf->os,&og);
+ }
+ }
+
+ vf->bittrack=0;
+ vf->samptrack=0;
+ /* discard samples until we reach the desired position. Crossing a
+ logical bitstream boundary with abandon is OK. */
+ while(vf->pcm_offset<pos){
+ ogg_int64_t target=pos-vf->pcm_offset;
+ long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
+
+ if(samples>target)samples=target;
+ vorbis_synthesis_read(&vf->vd,samples);
+ vf->pcm_offset+=samples;
+
+ if(samples<target)
+ if(_fetch_and_process_packet(vf,1,1)<=0)
+ vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
+ }
+
+ ogg_page_release(&og);
+ ogg_packet_release(&op);
+ return 0;
+}
+
+/* seek to a playback time relative to the decompressed pcm stream
+ returns zero on success, nonzero on failure */
+int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){
+ /* translate time to PCM position and call ov_pcm_seek */
+
+ int link=-1;
+ ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
+ ogg_int64_t time_total=ov_time_total(vf,-1);
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL);
+
+ /* which bitstream section does this time offset occur in? */
+ for(link=vf->links-1;link>=0;link--){
+ pcm_total-=vf->pcmlengths[link*2+1];
+ time_total-=ov_time_total(vf,link);
+ if(milliseconds>=time_total)break;
+ }
+
+ /* enough information to convert time offset to pcm offset */
+ {
+ ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000;
+ return(ov_pcm_seek(vf,target));
+ }
+}
+
+/* page-granularity version of ov_time_seek
+ returns zero on success, nonzero on failure */
+int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){
+ /* translate time to PCM position and call ov_pcm_seek */
+
+ int link=-1;
+ ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
+ ogg_int64_t time_total=ov_time_total(vf,-1);
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(!vf->seekable)return(OV_ENOSEEK);
+ if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL);
+
+ /* which bitstream section does this time offset occur in? */
+ for(link=vf->links-1;link>=0;link--){
+ pcm_total-=vf->pcmlengths[link*2+1];
+ time_total-=ov_time_total(vf,link);
+ if(milliseconds>=time_total)break;
+ }
+
+ /* enough information to convert time offset to pcm offset */
+ {
+ ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000;
+ return(ov_pcm_seek_page(vf,target));
+ }
+}
+
+/* tell the current stream offset cursor. Note that seek followed by
+ tell will likely not give the set offset due to caching */
+ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ return(vf->offset);
+}
+
+/* return PCM offset (sample) of next PCM sample to be read */
+ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ return(vf->pcm_offset);
+}
+
+/* return time offset (milliseconds) of next PCM sample to be read */
+ogg_int64_t ov_time_tell(OggVorbis_File *vf){
+ int link=0;
+ ogg_int64_t pcm_total=0;
+ ogg_int64_t time_total=0;
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+ if(vf->seekable){
+ pcm_total=ov_pcm_total(vf,-1);
+ time_total=ov_time_total(vf,-1);
+
+ /* which bitstream section does this time offset occur in? */
+ for(link=vf->links-1;link>=0;link--){
+ pcm_total-=vf->pcmlengths[link*2+1];
+ time_total-=ov_time_total(vf,link);
+ if(vf->pcm_offset>=pcm_total)break;
+ }
+ }
+
+ return(time_total+(1000*vf->pcm_offset-pcm_total)/vf->vi[link].rate);
+}
+
+/* link: -1) return the vorbis_info struct for the bitstream section
+ currently being decoded
+ 0-n) to request information for a specific bitstream section
+
+ In the case of a non-seekable bitstream, any call returns the
+ current bitstream. NULL in the case that the machine is not
+ initialized */
+
+vorbis_info *ov_info(OggVorbis_File *vf,int link){
+ if(vf->seekable){
+ if(link<0)
+ if(vf->ready_state>=STREAMSET)
+ return vf->vi+vf->current_link;
+ else
+ return vf->vi;
+ else
+ if(link>=vf->links)
+ return NULL;
+ else
+ return vf->vi+link;
+ }else{
+ return vf->vi;
+ }
+}
+
+/* grr, strong typing, grr, no templates/inheritence, grr */
+vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
+ if(vf->seekable){
+ if(link<0)
+ if(vf->ready_state>=STREAMSET)
+ return vf->vc+vf->current_link;
+ else
+ return vf->vc;
+ else
+ if(link>=vf->links)
+ return NULL;
+ else
+ return vf->vc+link;
+ }else{
+ return vf->vc;
+ }
+}
+
+/* up to this point, everything could more or less hide the multiple
+ logical bitstream nature of chaining from the toplevel application
+ if the toplevel application didn't particularly care. However, at
+ the point that we actually read audio back, the multiple-section
+ nature must surface: Multiple bitstream sections do not necessarily
+ have to have the same number of channels or sampling rate.
+
+ ov_read returns the sequential logical bitstream number currently
+ being decoded along with the PCM data in order that the toplevel
+ application can take action on channel/sample rate changes. This
+ number will be incremented even for streamed (non-seekable) streams
+ (for seekable streams, it represents the actual logical bitstream
+ index within the physical bitstream. Note that the accessor
+ functions above are aware of this dichotomy).
+
+ input values: buffer) a buffer to hold packed PCM data for return
+ length) the byte length requested to be placed into buffer
+
+ return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL)
+ 0) EOF
+ n) number of bytes of PCM actually returned. The
+ below works on a packet-by-packet basis, so the
+ return length is not related to the 'length' passed
+ in, just guaranteed to fit.
+
+ *section) set to the logical bitstream number */
+
+long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
+ int i,j;
+
+ ogg_int32_t **pcm;
+ long samples;
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+
+ while(1){
+ if(vf->ready_state==INITSET){
+ samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
+ if(samples)break;
+ }
+
+ /* suck in another packet */
+ {
+ int ret=_fetch_and_process_packet(vf,1,1);
+ if(ret==OV_EOF)
+ return(0);
+ if(ret<=0)
+ return(ret);
+ }
+
+ }
+
+ if(samples>0){
+
+ /* yay! proceed to pack data into the byte buffer */
+
+ long channels=ov_info(vf,-1)->channels;
+
+ if(channels==1){
+ if(samples>(bytes_req/2))
+ samples=bytes_req/2;
+ }else{
+ if(samples>(bytes_req/4))
+ samples=bytes_req/4;
+ }
+
+ for(i=0;i<channels;i++) { /* It's faster in this order */
+ ogg_int32_t *src=pcm[i];
+ short *dest=((short *)buffer)+i;
+ for(j=0;j<samples;j++) {
+ *dest=CLIP_TO_15(src[j]>>9);
+ dest+=channels;
+ }
+ }
+
+ vorbis_synthesis_read(&vf->vd,samples);
+ vf->pcm_offset+=samples;
+ if(bitstream)*bitstream=vf->current_link;
+ return(samples*2*channels);
+ }else{
+ return(samples);
+ }
+}
diff --git a/osframework/source/SexyAppFramework/ogg/window.c b/osframework/source/SexyAppFramework/ogg/window.c
new file mode 100644
index 0000000..1208eff
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/window.c
@@ -0,0 +1,84 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: window functions
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <math.h>
+#include "os.h"
+#include "misc.h"
+#include "window.h"
+#include "window_lookup.h"
+
+const void *_vorbis_window(int type, int left){
+
+ switch(type){
+ case 0:
+
+ switch(left){
+ case 32:
+ return vwin64;
+ case 64:
+ return vwin128;
+ case 128:
+ return vwin256;
+ case 256:
+ return vwin512;
+ case 512:
+ return vwin1024;
+ case 1024:
+ return vwin2048;
+ case 2048:
+ return vwin4096;
+ case 4096:
+ return vwin8192;
+ default:
+ return(0);
+ }
+ break;
+ default:
+ return(0);
+ }
+}
+
+void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2],
+ long *blocksizes,
+ int lW,int W,int nW){
+
+ LOOKUP_T *window[2]={window_p[0],window_p[1]};
+ long n=blocksizes[W];
+ long ln=blocksizes[lW];
+ long rn=blocksizes[nW];
+
+ long leftbegin=n/4-ln/4;
+ long leftend=leftbegin+ln/2;
+
+ long rightbegin=n/2+n/4-rn/4;
+ long rightend=rightbegin+rn/2;
+
+ int i,p;
+
+ for(i=0;i<leftbegin;i++)
+ d[i]=0;
+
+ for(p=0;i<leftend;i++,p++)
+ d[i]=MULT31(d[i],window[lW][p]);
+
+ for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
+ d[i]=MULT31(d[i],window[nW][p]);
+
+ for(;i<n;i++)
+ d[i]=0;
+}
diff --git a/osframework/source/SexyAppFramework/ogg/window.h b/osframework/source/SexyAppFramework/ogg/window.h
new file mode 100644
index 0000000..e8bccf9
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/window.h
@@ -0,0 +1,27 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: window functions
+
+ ********************************************************************/
+
+#ifndef _V_WINDOW_
+#define _V_WINDOW_
+
+extern const void *_vorbis_window(int type,int left);
+extern void _vorbis_apply_window(ogg_int32_t *d,const void *window[2],
+ long *blocksizes,
+ int lW,int W,int nW);
+
+
+#endif
diff --git a/osframework/source/SexyAppFramework/ogg/window_lookup.h b/osframework/source/SexyAppFramework/ogg/window_lookup.h
new file mode 100644
index 0000000..d1f523d
--- /dev/null
+++ b/osframework/source/SexyAppFramework/ogg/window_lookup.h
@@ -0,0 +1,2084 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * *
+ ********************************************************************
+
+ function: window lookup tables
+
+ ********************************************************************/
+
+
+#include "os_types.h"
+
+static LOOKUP_T vwin64[32] = {
+ X(0x001f0003), X(0x01168c98), X(0x030333c8), X(0x05dfe3a4),
+ X(0x09a49562), X(0x0e45df18), X(0x13b47ef2), X(0x19dcf676),
+ X(0x20a74d83), X(0x27f7137c), X(0x2fabb05a), X(0x37a1105a),
+ X(0x3fb0ab28), X(0x47b2dcd1), X(0x4f807bc6), X(0x56f48e70),
+ X(0x5dedfc79), X(0x64511653), X(0x6a08cfff), X(0x6f079328),
+ X(0x734796f4), X(0x76cab7f2), X(0x7999d6e8), X(0x7bc3cf9f),
+ X(0x7d5c20c1), X(0x7e7961df), X(0x7f33a567), X(0x7fa2e1d0),
+ X(0x7fdd78a5), X(0x7ff6ec6d), X(0x7ffed0e9), X(0x7ffffc3f),
+};
+
+static LOOKUP_T vwin128[64] = {
+ X(0x0007c04d), X(0x0045bb89), X(0x00c18b87), X(0x017ae294),
+ X(0x02714a4e), X(0x03a4217a), X(0x05129952), X(0x06bbb24f),
+ X(0x089e38a1), X(0x0ab8c073), X(0x0d09a228), X(0x0f8ef6bd),
+ X(0x12469488), X(0x152e0c7a), X(0x1842a81c), X(0x1b81686d),
+ X(0x1ee705d9), X(0x226ff15d), X(0x26185705), X(0x29dc21cc),
+ X(0x2db700fe), X(0x31a46f08), X(0x359fb9c1), X(0x39a40c0c),
+ X(0x3dac78b6), X(0x41b40674), X(0x45b5bcb0), X(0x49acb109),
+ X(0x4d94152b), X(0x516744bd), X(0x5521d320), X(0x58bf98a5),
+ X(0x5c3cbef4), X(0x5f95cc5d), X(0x62c7add7), X(0x65cfbf64),
+ X(0x68abd2ba), X(0x6b5a3405), X(0x6dd9acab), X(0x7029840d),
+ X(0x72497e38), X(0x7439d8ac), X(0x75fb4532), X(0x778ee30a),
+ X(0x78f6367e), X(0x7a331f1a), X(0x7b47cccd), X(0x7c36b416),
+ X(0x7d028192), X(0x7dae0d18), X(0x7e3c4caa), X(0x7eb04763),
+ X(0x7f0d08a7), X(0x7f5593b7), X(0x7f8cd7d5), X(0x7fb5a513),
+ X(0x7fd2a1fc), X(0x7fe64212), X(0x7ff2bd4c), X(0x7ffa0890),
+ X(0x7ffdcf39), X(0x7fff6dac), X(0x7fffed01), X(0x7fffffc4),
+};
+
+static LOOKUP_T vwin256[128] = {
+ X(0x0001f018), X(0x00117066), X(0x00306e9e), X(0x005ee5f1),
+ X(0x009ccf26), X(0x00ea208b), X(0x0146cdea), X(0x01b2c87f),
+ X(0x022dfedf), X(0x02b85ced), X(0x0351cbbd), X(0x03fa317f),
+ X(0x04b17167), X(0x05776b90), X(0x064bfcdc), X(0x072efedd),
+ X(0x082047b4), X(0x091fa9f1), X(0x0a2cf477), X(0x0b47f25d),
+ X(0x0c706ad2), X(0x0da620ff), X(0x0ee8d3ef), X(0x10383e75),
+ X(0x11941716), X(0x12fc0ff6), X(0x146fd6c8), X(0x15ef14c2),
+ X(0x17796e8e), X(0x190e844f), X(0x1aadf196), X(0x1c574d6e),
+ X(0x1e0a2a62), X(0x1fc61688), X(0x218a9b9c), X(0x23573f12),
+ X(0x252b823d), X(0x2706e269), X(0x28e8d913), X(0x2ad0dc0e),
+ X(0x2cbe5dc1), X(0x2eb0cd60), X(0x30a79733), X(0x32a224d5),
+ X(0x349fdd8b), X(0x36a02690), X(0x38a2636f), X(0x3aa5f65e),
+ X(0x3caa409e), X(0x3eaea2df), X(0x40b27da6), X(0x42b531b8),
+ X(0x44b62086), X(0x46b4ac99), X(0x48b03a05), X(0x4aa82ed5),
+ X(0x4c9bf37d), X(0x4e8af349), X(0x50749ccb), X(0x52586246),
+ X(0x5435ba1c), X(0x560c1f31), X(0x57db1152), X(0x59a21591),
+ X(0x5b60b6a3), X(0x5d168535), X(0x5ec31839), X(0x60660d36),
+ X(0x61ff0886), X(0x638db595), X(0x6511c717), X(0x668af734),
+ X(0x67f907b0), X(0x695bc207), X(0x6ab2f787), X(0x6bfe815a),
+ X(0x6d3e4090), X(0x6e721e16), X(0x6f9a0ab5), X(0x70b5fef8),
+ X(0x71c5fb16), X(0x72ca06cd), X(0x73c2313d), X(0x74ae90b2),
+ X(0x758f4275), X(0x76646a85), X(0x772e335c), X(0x77eccda0),
+ X(0x78a06fd7), X(0x79495613), X(0x79e7c19c), X(0x7a7bf894),
+ X(0x7b064596), X(0x7b86f757), X(0x7bfe6044), X(0x7c6cd615),
+ X(0x7cd2b16e), X(0x7d304d71), X(0x7d860756), X(0x7dd43e06),
+ X(0x7e1b51ad), X(0x7e5ba355), X(0x7e95947e), X(0x7ec986bb),
+ X(0x7ef7db4a), X(0x7f20f2b9), X(0x7f452c7f), X(0x7f64e6a7),
+ X(0x7f807d71), X(0x7f984aff), X(0x7faca700), X(0x7fbde662),
+ X(0x7fcc5b04), X(0x7fd85372), X(0x7fe21a99), X(0x7fe9f791),
+ X(0x7ff02d58), X(0x7ff4fa9e), X(0x7ff89990), X(0x7ffb3faa),
+ X(0x7ffd1d8b), X(0x7ffe5ecc), X(0x7fff29e0), X(0x7fff9ff3),
+ X(0x7fffdcd2), X(0x7ffff6d6), X(0x7ffffed0), X(0x7ffffffc),
+};
+
+static LOOKUP_T vwin512[256] = {
+ X(0x00007c06), X(0x00045c32), X(0x000c1c62), X(0x0017bc4c),
+ X(0x00273b7a), X(0x003a9955), X(0x0051d51c), X(0x006cede7),
+ X(0x008be2a9), X(0x00aeb22a), X(0x00d55b0d), X(0x00ffdbcc),
+ X(0x012e32b6), X(0x01605df5), X(0x01965b85), X(0x01d02939),
+ X(0x020dc4ba), X(0x024f2b83), X(0x02945ae6), X(0x02dd5004),
+ X(0x032a07d3), X(0x037a7f19), X(0x03ceb26e), X(0x04269e37),
+ X(0x04823eab), X(0x04e18fcc), X(0x05448d6d), X(0x05ab3329),
+ X(0x06157c68), X(0x0683645e), X(0x06f4e607), X(0x0769fc25),
+ X(0x07e2a146), X(0x085ecfbc), X(0x08de819f), X(0x0961b0cc),
+ X(0x09e856e3), X(0x0a726d46), X(0x0affed1d), X(0x0b90cf4c),
+ X(0x0c250c79), X(0x0cbc9d0b), X(0x0d577926), X(0x0df598aa),
+ X(0x0e96f337), X(0x0f3b8026), X(0x0fe3368f), X(0x108e0d42),
+ X(0x113bfaca), X(0x11ecf56b), X(0x12a0f324), X(0x1357e9ac),
+ X(0x1411ce70), X(0x14ce9698), X(0x158e3702), X(0x1650a444),
+ X(0x1715d2aa), X(0x17ddb638), X(0x18a842aa), X(0x19756b72),
+ X(0x1a4523b9), X(0x1b175e62), X(0x1bec0e04), X(0x1cc324f0),
+ X(0x1d9c9532), X(0x1e78508a), X(0x1f564876), X(0x20366e2e),
+ X(0x2118b2a2), X(0x21fd0681), X(0x22e35a37), X(0x23cb9dee),
+ X(0x24b5c18e), X(0x25a1b4c0), X(0x268f66f1), X(0x277ec74e),
+ X(0x286fc4cc), X(0x29624e23), X(0x2a5651d7), X(0x2b4bbe34),
+ X(0x2c428150), X(0x2d3a8913), X(0x2e33c332), X(0x2f2e1d35),
+ X(0x30298478), X(0x3125e62d), X(0x32232f61), X(0x33214cfc),
+ X(0x34202bc2), X(0x351fb85a), X(0x361fdf4f), X(0x37208d10),
+ X(0x3821adf7), X(0x39232e49), X(0x3a24fa3c), X(0x3b26fdf6),
+ X(0x3c292593), X(0x3d2b5d29), X(0x3e2d90c8), X(0x3f2fac7f),
+ X(0x40319c5f), X(0x41334c81), X(0x4234a905), X(0x43359e16),
+ X(0x443617f3), X(0x453602eb), X(0x46354b65), X(0x4733dde1),
+ X(0x4831a6ff), X(0x492e937f), X(0x4a2a9045), X(0x4b258a5f),
+ X(0x4c1f6f06), X(0x4d182ba2), X(0x4e0fadce), X(0x4f05e35b),
+ X(0x4ffaba53), X(0x50ee20fd), X(0x51e005e1), X(0x52d057ca),
+ X(0x53bf05ca), X(0x54abff3b), X(0x559733c7), X(0x56809365),
+ X(0x57680e62), X(0x584d955d), X(0x59311952), X(0x5a128b96),
+ X(0x5af1dddd), X(0x5bcf023a), X(0x5ca9eb27), X(0x5d828b81),
+ X(0x5e58d68d), X(0x5f2cbffc), X(0x5ffe3be9), X(0x60cd3edf),
+ X(0x6199bdda), X(0x6263ae45), X(0x632b0602), X(0x63efbb66),
+ X(0x64b1c53f), X(0x65711ad0), X(0x662db3d7), X(0x66e7888d),
+ X(0x679e91a5), X(0x6852c84e), X(0x69042635), X(0x69b2a582),
+ X(0x6a5e40dd), X(0x6b06f36c), X(0x6bacb8d2), X(0x6c4f8d30),
+ X(0x6cef6d26), X(0x6d8c55d4), X(0x6e2644d4), X(0x6ebd3840),
+ X(0x6f512ead), X(0x6fe2272e), X(0x7070214f), X(0x70fb1d17),
+ X(0x71831b06), X(0x72081c16), X(0x728a21b5), X(0x73092dc8),
+ X(0x738542a6), X(0x73fe631b), X(0x74749261), X(0x74e7d421),
+ X(0x75582c72), X(0x75c59fd5), X(0x76303333), X(0x7697ebdd),
+ X(0x76fccf85), X(0x775ee443), X(0x77be308a), X(0x781abb2e),
+ X(0x78748b59), X(0x78cba88e), X(0x79201aa7), X(0x7971e9cd),
+ X(0x79c11e79), X(0x7a0dc170), X(0x7a57dbc2), X(0x7a9f76c1),
+ X(0x7ae49c07), X(0x7b27556b), X(0x7b67ad02), X(0x7ba5ad1b),
+ X(0x7be1603a), X(0x7c1ad118), X(0x7c520a9e), X(0x7c8717e1),
+ X(0x7cba0421), X(0x7ceadac3), X(0x7d19a74f), X(0x7d46756e),
+ X(0x7d7150e5), X(0x7d9a4592), X(0x7dc15f69), X(0x7de6aa71),
+ X(0x7e0a32c0), X(0x7e2c0479), X(0x7e4c2bc7), X(0x7e6ab4db),
+ X(0x7e87abe9), X(0x7ea31d24), X(0x7ebd14be), X(0x7ed59edd),
+ X(0x7eecc7a3), X(0x7f029b21), X(0x7f17255a), X(0x7f2a723f),
+ X(0x7f3c8daa), X(0x7f4d835d), X(0x7f5d5f00), X(0x7f6c2c1b),
+ X(0x7f79f617), X(0x7f86c83a), X(0x7f92ada2), X(0x7f9db146),
+ X(0x7fa7ddf3), X(0x7fb13e46), X(0x7fb9dcb0), X(0x7fc1c36c),
+ X(0x7fc8fc83), X(0x7fcf91c7), X(0x7fd58cd2), X(0x7fdaf702),
+ X(0x7fdfd979), X(0x7fe43d1c), X(0x7fe82a8b), X(0x7febaa29),
+ X(0x7feec412), X(0x7ff1801c), X(0x7ff3e5d6), X(0x7ff5fc86),
+ X(0x7ff7cb29), X(0x7ff9586f), X(0x7ffaaaba), X(0x7ffbc81e),
+ X(0x7ffcb660), X(0x7ffd7af3), X(0x7ffe1afa), X(0x7ffe9b42),
+ X(0x7fff0047), X(0x7fff4e2f), X(0x7fff88c9), X(0x7fffb390),
+ X(0x7fffd1a6), X(0x7fffe5d7), X(0x7ffff296), X(0x7ffff9fd),
+ X(0x7ffffdcd), X(0x7fffff6d), X(0x7fffffed), X(0x7fffffff),
+};
+
+static LOOKUP_T vwin1024[512] = {
+ X(0x00001f02), X(0x0001170e), X(0x00030724), X(0x0005ef40),
+ X(0x0009cf59), X(0x000ea767), X(0x0014775e), X(0x001b3f2e),
+ X(0x0022fec8), X(0x002bb618), X(0x00356508), X(0x00400b81),
+ X(0x004ba968), X(0x00583ea0), X(0x0065cb0a), X(0x00744e84),
+ X(0x0083c8ea), X(0x00943a14), X(0x00a5a1da), X(0x00b80010),
+ X(0x00cb5488), X(0x00df9f10), X(0x00f4df76), X(0x010b1584),
+ X(0x01224101), X(0x013a61b2), X(0x01537759), X(0x016d81b6),
+ X(0x01888087), X(0x01a47385), X(0x01c15a69), X(0x01df34e6),
+ X(0x01fe02b1), X(0x021dc377), X(0x023e76e7), X(0x02601ca9),
+ X(0x0282b466), X(0x02a63dc1), X(0x02cab85d), X(0x02f023d6),
+ X(0x03167fcb), X(0x033dcbd3), X(0x03660783), X(0x038f3270),
+ X(0x03b94c29), X(0x03e4543a), X(0x04104a2e), X(0x043d2d8b),
+ X(0x046afdd5), X(0x0499ba8c), X(0x04c9632d), X(0x04f9f734),
+ X(0x052b7615), X(0x055ddf46), X(0x05913237), X(0x05c56e53),
+ X(0x05fa9306), X(0x06309fb6), X(0x066793c5), X(0x069f6e93),
+ X(0x06d82f7c), X(0x0711d5d9), X(0x074c60fe), X(0x0787d03d),
+ X(0x07c422e4), X(0x0801583e), X(0x083f6f91), X(0x087e681f),
+ X(0x08be4129), X(0x08fef9ea), X(0x0940919a), X(0x0983076d),
+ X(0x09c65a92), X(0x0a0a8a38), X(0x0a4f9585), X(0x0a957b9f),
+ X(0x0adc3ba7), X(0x0b23d4b9), X(0x0b6c45ee), X(0x0bb58e5a),
+ X(0x0bffad0f), X(0x0c4aa11a), X(0x0c966982), X(0x0ce3054d),
+ X(0x0d30737b), X(0x0d7eb308), X(0x0dcdc2eb), X(0x0e1da21a),
+ X(0x0e6e4f83), X(0x0ebfca11), X(0x0f1210ad), X(0x0f652238),
+ X(0x0fb8fd91), X(0x100da192), X(0x10630d11), X(0x10b93ee0),
+ X(0x111035cb), X(0x1167f09a), X(0x11c06e13), X(0x1219acf5),
+ X(0x1273abfb), X(0x12ce69db), X(0x1329e54a), X(0x13861cf3),
+ X(0x13e30f80), X(0x1440bb97), X(0x149f1fd8), X(0x14fe3ade),
+ X(0x155e0b40), X(0x15be8f92), X(0x161fc662), X(0x1681ae38),
+ X(0x16e4459b), X(0x17478b0b), X(0x17ab7d03), X(0x181019fb),
+ X(0x18756067), X(0x18db4eb3), X(0x1941e34a), X(0x19a91c92),
+ X(0x1a10f8ea), X(0x1a7976af), X(0x1ae29439), X(0x1b4c4fda),
+ X(0x1bb6a7e2), X(0x1c219a9a), X(0x1c8d2649), X(0x1cf9492e),
+ X(0x1d660188), X(0x1dd34d8e), X(0x1e412b74), X(0x1eaf996a),
+ X(0x1f1e959b), X(0x1f8e1e2f), X(0x1ffe3146), X(0x206ecd01),
+ X(0x20dfef78), X(0x215196c2), X(0x21c3c0f0), X(0x22366c10),
+ X(0x22a9962a), X(0x231d3d45), X(0x23915f60), X(0x2405fa7a),
+ X(0x247b0c8c), X(0x24f09389), X(0x25668d65), X(0x25dcf80c),
+ X(0x2653d167), X(0x26cb175e), X(0x2742c7d0), X(0x27bae09e),
+ X(0x28335fa2), X(0x28ac42b3), X(0x292587a5), X(0x299f2c48),
+ X(0x2a192e69), X(0x2a938bd1), X(0x2b0e4247), X(0x2b894f8d),
+ X(0x2c04b164), X(0x2c806588), X(0x2cfc69b2), X(0x2d78bb9a),
+ X(0x2df558f4), X(0x2e723f6f), X(0x2eef6cbb), X(0x2f6cde83),
+ X(0x2fea9270), X(0x30688627), X(0x30e6b74e), X(0x31652385),
+ X(0x31e3c86b), X(0x3262a39e), X(0x32e1b2b8), X(0x3360f352),
+ X(0x33e06303), X(0x345fff5e), X(0x34dfc5f8), X(0x355fb462),
+ X(0x35dfc82a), X(0x365ffee0), X(0x36e0560f), X(0x3760cb43),
+ X(0x37e15c05), X(0x386205df), X(0x38e2c657), X(0x39639af5),
+ X(0x39e4813e), X(0x3a6576b6), X(0x3ae678e3), X(0x3b678547),
+ X(0x3be89965), X(0x3c69b2c1), X(0x3ceacedc), X(0x3d6beb37),
+ X(0x3ded0557), X(0x3e6e1abb), X(0x3eef28e6), X(0x3f702d5a),
+ X(0x3ff1259a), X(0x40720f29), X(0x40f2e789), X(0x4173ac3f),
+ X(0x41f45ad0), X(0x4274f0c2), X(0x42f56b9a), X(0x4375c8e0),
+ X(0x43f6061d), X(0x447620db), X(0x44f616a5), X(0x4575e509),
+ X(0x45f58994), X(0x467501d6), X(0x46f44b62), X(0x477363cb),
+ X(0x47f248a6), X(0x4870f78e), X(0x48ef6e1a), X(0x496da9e8),
+ X(0x49eba897), X(0x4a6967c8), X(0x4ae6e521), X(0x4b641e47),
+ X(0x4be110e5), X(0x4c5dbaa7), X(0x4cda193f), X(0x4d562a5f),
+ X(0x4dd1ebbd), X(0x4e4d5b15), X(0x4ec87623), X(0x4f433aa9),
+ X(0x4fbda66c), X(0x5037b734), X(0x50b16acf), X(0x512abf0e),
+ X(0x51a3b1c5), X(0x521c40ce), X(0x52946a06), X(0x530c2b50),
+ X(0x53838292), X(0x53fa6db8), X(0x5470eab3), X(0x54e6f776),
+ X(0x555c91fc), X(0x55d1b844), X(0x56466851), X(0x56baa02f),
+ X(0x572e5deb), X(0x57a19f98), X(0x58146352), X(0x5886a737),
+ X(0x58f8696d), X(0x5969a81c), X(0x59da6177), X(0x5a4a93b4),
+ X(0x5aba3d0f), X(0x5b295bcb), X(0x5b97ee30), X(0x5c05f28d),
+ X(0x5c736738), X(0x5ce04a8d), X(0x5d4c9aed), X(0x5db856c1),
+ X(0x5e237c78), X(0x5e8e0a89), X(0x5ef7ff6f), X(0x5f6159b0),
+ X(0x5fca17d4), X(0x6032386e), X(0x6099ba15), X(0x61009b69),
+ X(0x6166db11), X(0x61cc77b9), X(0x62317017), X(0x6295c2e7),
+ X(0x62f96eec), X(0x635c72f1), X(0x63becdc8), X(0x64207e4b),
+ X(0x6481835a), X(0x64e1dbde), X(0x654186c8), X(0x65a0830e),
+ X(0x65fecfb1), X(0x665c6bb7), X(0x66b95630), X(0x67158e30),
+ X(0x677112d7), X(0x67cbe34b), X(0x6825feb9), X(0x687f6456),
+ X(0x68d81361), X(0x69300b1e), X(0x69874ada), X(0x69ddd1ea),
+ X(0x6a339fab), X(0x6a88b382), X(0x6add0cdb), X(0x6b30ab2a),
+ X(0x6b838dec), X(0x6bd5b4a6), X(0x6c271ee2), X(0x6c77cc36),
+ X(0x6cc7bc3d), X(0x6d16ee9b), X(0x6d6562fb), X(0x6db31911),
+ X(0x6e001099), X(0x6e4c4955), X(0x6e97c311), X(0x6ee27d9f),
+ X(0x6f2c78d9), X(0x6f75b4a2), X(0x6fbe30e4), X(0x7005ed91),
+ X(0x704ceaa1), X(0x70932816), X(0x70d8a5f8), X(0x711d6457),
+ X(0x7161634b), X(0x71a4a2f3), X(0x71e72375), X(0x7228e500),
+ X(0x7269e7c8), X(0x72aa2c0a), X(0x72e9b209), X(0x73287a12),
+ X(0x73668476), X(0x73a3d18f), X(0x73e061bc), X(0x741c3566),
+ X(0x74574cfa), X(0x7491a8ee), X(0x74cb49be), X(0x75042fec),
+ X(0x753c5c03), X(0x7573ce92), X(0x75aa882f), X(0x75e08979),
+ X(0x7615d313), X(0x764a65a7), X(0x767e41e5), X(0x76b16884),
+ X(0x76e3da40), X(0x771597dc), X(0x7746a221), X(0x7776f9dd),
+ X(0x77a69fe6), X(0x77d59514), X(0x7803da49), X(0x7831706a),
+ X(0x785e5861), X(0x788a9320), X(0x78b6219c), X(0x78e104cf),
+ X(0x790b3dbb), X(0x7934cd64), X(0x795db4d5), X(0x7985f51d),
+ X(0x79ad8f50), X(0x79d48486), X(0x79fad5de), X(0x7a208478),
+ X(0x7a45917b), X(0x7a69fe12), X(0x7a8dcb6c), X(0x7ab0fabb),
+ X(0x7ad38d36), X(0x7af5841a), X(0x7b16e0a3), X(0x7b37a416),
+ X(0x7b57cfb8), X(0x7b7764d4), X(0x7b9664b6), X(0x7bb4d0b0),
+ X(0x7bd2aa14), X(0x7beff23b), X(0x7c0caa7f), X(0x7c28d43c),
+ X(0x7c4470d2), X(0x7c5f81a5), X(0x7c7a081a), X(0x7c940598),
+ X(0x7cad7b8b), X(0x7cc66b5e), X(0x7cded680), X(0x7cf6be64),
+ X(0x7d0e247b), X(0x7d250a3c), X(0x7d3b711c), X(0x7d515a95),
+ X(0x7d66c822), X(0x7d7bbb3c), X(0x7d903563), X(0x7da43814),
+ X(0x7db7c4d0), X(0x7dcadd16), X(0x7ddd826a), X(0x7defb64d),
+ X(0x7e017a44), X(0x7e12cfd3), X(0x7e23b87f), X(0x7e3435cc),
+ X(0x7e444943), X(0x7e53f467), X(0x7e6338c0), X(0x7e7217d5),
+ X(0x7e80932b), X(0x7e8eac49), X(0x7e9c64b7), X(0x7ea9bdf8),
+ X(0x7eb6b994), X(0x7ec35910), X(0x7ecf9def), X(0x7edb89b6),
+ X(0x7ee71de9), X(0x7ef25c09), X(0x7efd4598), X(0x7f07dc16),
+ X(0x7f122103), X(0x7f1c15dc), X(0x7f25bc1f), X(0x7f2f1547),
+ X(0x7f3822cd), X(0x7f40e62b), X(0x7f4960d6), X(0x7f519443),
+ X(0x7f5981e7), X(0x7f612b31), X(0x7f689191), X(0x7f6fb674),
+ X(0x7f769b45), X(0x7f7d416c), X(0x7f83aa51), X(0x7f89d757),
+ X(0x7f8fc9df), X(0x7f958348), X(0x7f9b04ef), X(0x7fa0502e),
+ X(0x7fa56659), X(0x7faa48c7), X(0x7faef8c7), X(0x7fb377a7),
+ X(0x7fb7c6b3), X(0x7fbbe732), X(0x7fbfda67), X(0x7fc3a196),
+ X(0x7fc73dfa), X(0x7fcab0ce), X(0x7fcdfb4a), X(0x7fd11ea0),
+ X(0x7fd41c00), X(0x7fd6f496), X(0x7fd9a989), X(0x7fdc3bff),
+ X(0x7fdead17), X(0x7fe0fdee), X(0x7fe32f9d), X(0x7fe54337),
+ X(0x7fe739ce), X(0x7fe9146c), X(0x7fead41b), X(0x7fec79dd),
+ X(0x7fee06b2), X(0x7fef7b94), X(0x7ff0d97b), X(0x7ff22158),
+ X(0x7ff35417), X(0x7ff472a3), X(0x7ff57de0), X(0x7ff676ac),
+ X(0x7ff75de3), X(0x7ff8345a), X(0x7ff8fae4), X(0x7ff9b24b),
+ X(0x7ffa5b58), X(0x7ffaf6cd), X(0x7ffb8568), X(0x7ffc07e2),
+ X(0x7ffc7eed), X(0x7ffceb38), X(0x7ffd4d6d), X(0x7ffda631),
+ X(0x7ffdf621), X(0x7ffe3dd8), X(0x7ffe7dea), X(0x7ffeb6e7),
+ X(0x7ffee959), X(0x7fff15c4), X(0x7fff3ca9), X(0x7fff5e80),
+ X(0x7fff7bc0), X(0x7fff94d6), X(0x7fffaa2d), X(0x7fffbc29),
+ X(0x7fffcb29), X(0x7fffd786), X(0x7fffe195), X(0x7fffe9a3),
+ X(0x7fffeffa), X(0x7ffff4dd), X(0x7ffff889), X(0x7ffffb37),
+ X(0x7ffffd1a), X(0x7ffffe5d), X(0x7fffff29), X(0x7fffffa0),
+ X(0x7fffffdd), X(0x7ffffff7), X(0x7fffffff), X(0x7fffffff),
+};
+
+static LOOKUP_T vwin2048[1024] = {
+ X(0x000007c0), X(0x000045c4), X(0x0000c1ca), X(0x00017bd3),
+ X(0x000273de), X(0x0003a9eb), X(0x00051df9), X(0x0006d007),
+ X(0x0008c014), X(0x000aee1e), X(0x000d5a25), X(0x00100428),
+ X(0x0012ec23), X(0x00161216), X(0x001975fe), X(0x001d17da),
+ X(0x0020f7a8), X(0x00251564), X(0x0029710c), X(0x002e0a9e),
+ X(0x0032e217), X(0x0037f773), X(0x003d4ab0), X(0x0042dbca),
+ X(0x0048aabe), X(0x004eb788), X(0x00550224), X(0x005b8a8f),
+ X(0x006250c5), X(0x006954c1), X(0x0070967e), X(0x007815f9),
+ X(0x007fd32c), X(0x0087ce13), X(0x009006a9), X(0x00987ce9),
+ X(0x00a130cc), X(0x00aa224f), X(0x00b3516b), X(0x00bcbe1a),
+ X(0x00c66856), X(0x00d0501a), X(0x00da755f), X(0x00e4d81f),
+ X(0x00ef7853), X(0x00fa55f4), X(0x010570fc), X(0x0110c963),
+ X(0x011c5f22), X(0x01283232), X(0x0134428c), X(0x01409027),
+ X(0x014d1afb), X(0x0159e302), X(0x0166e831), X(0x01742a82),
+ X(0x0181a9ec), X(0x018f6665), X(0x019d5fe5), X(0x01ab9663),
+ X(0x01ba09d6), X(0x01c8ba34), X(0x01d7a775), X(0x01e6d18d),
+ X(0x01f63873), X(0x0205dc1e), X(0x0215bc82), X(0x0225d997),
+ X(0x02363350), X(0x0246c9a3), X(0x02579c86), X(0x0268abed),
+ X(0x0279f7cc), X(0x028b801a), X(0x029d44c9), X(0x02af45ce),
+ X(0x02c1831d), X(0x02d3fcaa), X(0x02e6b269), X(0x02f9a44c),
+ X(0x030cd248), X(0x03203c4f), X(0x0333e255), X(0x0347c44b),
+ X(0x035be225), X(0x03703bd5), X(0x0384d14d), X(0x0399a280),
+ X(0x03aeaf5e), X(0x03c3f7d9), X(0x03d97be4), X(0x03ef3b6e),
+ X(0x0405366a), X(0x041b6cc8), X(0x0431de78), X(0x04488b6c),
+ X(0x045f7393), X(0x047696dd), X(0x048df53b), X(0x04a58e9b),
+ X(0x04bd62ee), X(0x04d57223), X(0x04edbc28), X(0x050640ed),
+ X(0x051f0060), X(0x0537fa70), X(0x05512f0a), X(0x056a9e1e),
+ X(0x05844798), X(0x059e2b67), X(0x05b84978), X(0x05d2a1b8),
+ X(0x05ed3414), X(0x06080079), X(0x062306d3), X(0x063e470f),
+ X(0x0659c119), X(0x067574dd), X(0x06916247), X(0x06ad8941),
+ X(0x06c9e9b8), X(0x06e68397), X(0x070356c8), X(0x07206336),
+ X(0x073da8cb), X(0x075b2772), X(0x0778df15), X(0x0796cf9c),
+ X(0x07b4f8f3), X(0x07d35b01), X(0x07f1f5b1), X(0x0810c8eb),
+ X(0x082fd497), X(0x084f189e), X(0x086e94e9), X(0x088e495e),
+ X(0x08ae35e6), X(0x08ce5a68), X(0x08eeb6cc), X(0x090f4af8),
+ X(0x093016d3), X(0x09511a44), X(0x09725530), X(0x0993c77f),
+ X(0x09b57115), X(0x09d751d8), X(0x09f969ae), X(0x0a1bb87c),
+ X(0x0a3e3e26), X(0x0a60fa91), X(0x0a83eda2), X(0x0aa7173c),
+ X(0x0aca7743), X(0x0aee0d9b), X(0x0b11da28), X(0x0b35dccc),
+ X(0x0b5a156a), X(0x0b7e83e5), X(0x0ba3281f), X(0x0bc801fa),
+ X(0x0bed1159), X(0x0c12561c), X(0x0c37d025), X(0x0c5d7f55),
+ X(0x0c83638d), X(0x0ca97cae), X(0x0ccfca97), X(0x0cf64d2a),
+ X(0x0d1d0444), X(0x0d43efc7), X(0x0d6b0f92), X(0x0d926383),
+ X(0x0db9eb79), X(0x0de1a752), X(0x0e0996ee), X(0x0e31ba29),
+ X(0x0e5a10e2), X(0x0e829af6), X(0x0eab5841), X(0x0ed448a2),
+ X(0x0efd6bf4), X(0x0f26c214), X(0x0f504ade), X(0x0f7a062e),
+ X(0x0fa3f3df), X(0x0fce13cd), X(0x0ff865d2), X(0x1022e9ca),
+ X(0x104d9f8e), X(0x107886f9), X(0x10a39fe5), X(0x10ceea2c),
+ X(0x10fa65a6), X(0x1126122d), X(0x1151ef9a), X(0x117dfdc5),
+ X(0x11aa3c87), X(0x11d6abb6), X(0x12034b2c), X(0x12301ac0),
+ X(0x125d1a48), X(0x128a499b), X(0x12b7a891), X(0x12e536ff),
+ X(0x1312f4bb), X(0x1340e19c), X(0x136efd75), X(0x139d481e),
+ X(0x13cbc16a), X(0x13fa692f), X(0x14293f40), X(0x14584371),
+ X(0x14877597), X(0x14b6d585), X(0x14e6630d), X(0x15161e04),
+ X(0x1546063b), X(0x15761b85), X(0x15a65db3), X(0x15d6cc99),
+ X(0x16076806), X(0x16382fcd), X(0x166923bf), X(0x169a43ab),
+ X(0x16cb8f62), X(0x16fd06b5), X(0x172ea973), X(0x1760776b),
+ X(0x1792706e), X(0x17c49449), X(0x17f6e2cb), X(0x18295bc3),
+ X(0x185bfeff), X(0x188ecc4c), X(0x18c1c379), X(0x18f4e452),
+ X(0x19282ea4), X(0x195ba23c), X(0x198f3ee6), X(0x19c3046e),
+ X(0x19f6f2a1), X(0x1a2b094a), X(0x1a5f4833), X(0x1a93af28),
+ X(0x1ac83df3), X(0x1afcf460), X(0x1b31d237), X(0x1b66d744),
+ X(0x1b9c034e), X(0x1bd15621), X(0x1c06cf84), X(0x1c3c6f40),
+ X(0x1c72351e), X(0x1ca820e6), X(0x1cde3260), X(0x1d146953),
+ X(0x1d4ac587), X(0x1d8146c3), X(0x1db7eccd), X(0x1deeb76c),
+ X(0x1e25a667), X(0x1e5cb982), X(0x1e93f085), X(0x1ecb4b33),
+ X(0x1f02c953), X(0x1f3a6aaa), X(0x1f722efb), X(0x1faa160b),
+ X(0x1fe21f9e), X(0x201a4b79), X(0x2052995d), X(0x208b0910),
+ X(0x20c39a53), X(0x20fc4cea), X(0x21352097), X(0x216e151c),
+ X(0x21a72a3a), X(0x21e05fb5), X(0x2219b54d), X(0x22532ac3),
+ X(0x228cbfd8), X(0x22c6744d), X(0x230047e2), X(0x233a3a58),
+ X(0x23744b6d), X(0x23ae7ae3), X(0x23e8c878), X(0x242333ec),
+ X(0x245dbcfd), X(0x24986369), X(0x24d326f1), X(0x250e0750),
+ X(0x25490446), X(0x25841d90), X(0x25bf52ec), X(0x25faa417),
+ X(0x263610cd), X(0x267198cc), X(0x26ad3bcf), X(0x26e8f994),
+ X(0x2724d1d6), X(0x2760c451), X(0x279cd0c0), X(0x27d8f6e0),
+ X(0x2815366a), X(0x28518f1b), X(0x288e00ac), X(0x28ca8ad8),
+ X(0x29072d5a), X(0x2943e7eb), X(0x2980ba45), X(0x29bda422),
+ X(0x29faa53c), X(0x2a37bd4a), X(0x2a74ec07), X(0x2ab2312b),
+ X(0x2aef8c6f), X(0x2b2cfd8b), X(0x2b6a8437), X(0x2ba8202c),
+ X(0x2be5d120), X(0x2c2396cc), X(0x2c6170e7), X(0x2c9f5f29),
+ X(0x2cdd6147), X(0x2d1b76fa), X(0x2d599ff7), X(0x2d97dbf5),
+ X(0x2dd62aab), X(0x2e148bcf), X(0x2e52ff16), X(0x2e918436),
+ X(0x2ed01ae5), X(0x2f0ec2d9), X(0x2f4d7bc6), X(0x2f8c4562),
+ X(0x2fcb1f62), X(0x300a097a), X(0x3049035f), X(0x30880cc6),
+ X(0x30c72563), X(0x31064cea), X(0x3145830f), X(0x3184c786),
+ X(0x31c41a03), X(0x32037a39), X(0x3242e7dc), X(0x3282629f),
+ X(0x32c1ea36), X(0x33017e53), X(0x33411ea9), X(0x3380caec),
+ X(0x33c082ce), X(0x34004602), X(0x34401439), X(0x347fed27),
+ X(0x34bfd07e), X(0x34ffbdf0), X(0x353fb52e), X(0x357fb5ec),
+ X(0x35bfbfda), X(0x35ffd2aa), X(0x363fee0f), X(0x368011b9),
+ X(0x36c03d5a), X(0x370070a4), X(0x3740ab48), X(0x3780ecf7),
+ X(0x37c13562), X(0x3801843a), X(0x3841d931), X(0x388233f7),
+ X(0x38c2943d), X(0x3902f9b4), X(0x3943640d), X(0x3983d2f8),
+ X(0x39c44626), X(0x3a04bd48), X(0x3a45380e), X(0x3a85b62a),
+ X(0x3ac6374a), X(0x3b06bb20), X(0x3b47415c), X(0x3b87c9ae),
+ X(0x3bc853c7), X(0x3c08df57), X(0x3c496c0f), X(0x3c89f99f),
+ X(0x3cca87b6), X(0x3d0b1605), X(0x3d4ba43d), X(0x3d8c320e),
+ X(0x3dccbf27), X(0x3e0d4b3a), X(0x3e4dd5f6), X(0x3e8e5f0c),
+ X(0x3ecee62b), X(0x3f0f6b05), X(0x3f4fed49), X(0x3f906ca8),
+ X(0x3fd0e8d2), X(0x40116177), X(0x4051d648), X(0x409246f6),
+ X(0x40d2b330), X(0x41131aa7), X(0x41537d0c), X(0x4193da10),
+ X(0x41d43162), X(0x421482b4), X(0x4254cdb7), X(0x4295121b),
+ X(0x42d54f91), X(0x431585ca), X(0x4355b477), X(0x4395db49),
+ X(0x43d5f9f1), X(0x44161021), X(0x44561d8a), X(0x449621dd),
+ X(0x44d61ccc), X(0x45160e08), X(0x4555f544), X(0x4595d230),
+ X(0x45d5a47f), X(0x46156be3), X(0x4655280e), X(0x4694d8b2),
+ X(0x46d47d82), X(0x4714162f), X(0x4753a26d), X(0x479321ef),
+ X(0x47d29466), X(0x4811f987), X(0x48515104), X(0x48909a91),
+ X(0x48cfd5e1), X(0x490f02a7), X(0x494e2098), X(0x498d2f66),
+ X(0x49cc2ec7), X(0x4a0b1e6f), X(0x4a49fe11), X(0x4a88cd62),
+ X(0x4ac78c18), X(0x4b0639e6), X(0x4b44d683), X(0x4b8361a2),
+ X(0x4bc1dafa), X(0x4c004241), X(0x4c3e972c), X(0x4c7cd970),
+ X(0x4cbb08c5), X(0x4cf924e1), X(0x4d372d7a), X(0x4d752247),
+ X(0x4db30300), X(0x4df0cf5a), X(0x4e2e870f), X(0x4e6c29d6),
+ X(0x4ea9b766), X(0x4ee72f78), X(0x4f2491c4), X(0x4f61de02),
+ X(0x4f9f13ec), X(0x4fdc333b), X(0x50193ba8), X(0x50562ced),
+ X(0x509306c3), X(0x50cfc8e5), X(0x510c730d), X(0x514904f6),
+ X(0x51857e5a), X(0x51c1def5), X(0x51fe2682), X(0x523a54bc),
+ X(0x52766961), X(0x52b2642c), X(0x52ee44d9), X(0x532a0b26),
+ X(0x5365b6d0), X(0x53a14793), X(0x53dcbd2f), X(0x54181760),
+ X(0x545355e5), X(0x548e787d), X(0x54c97ee6), X(0x550468e1),
+ X(0x553f362c), X(0x5579e687), X(0x55b479b3), X(0x55eeef70),
+ X(0x5629477f), X(0x566381a1), X(0x569d9d97), X(0x56d79b24),
+ X(0x57117a0a), X(0x574b3a0a), X(0x5784dae9), X(0x57be5c69),
+ X(0x57f7be4d), X(0x5831005a), X(0x586a2254), X(0x58a32400),
+ X(0x58dc0522), X(0x5914c57f), X(0x594d64de), X(0x5985e305),
+ X(0x59be3fba), X(0x59f67ac3), X(0x5a2e93e9), X(0x5a668af2),
+ X(0x5a9e5fa6), X(0x5ad611ce), X(0x5b0da133), X(0x5b450d9d),
+ X(0x5b7c56d7), X(0x5bb37ca9), X(0x5bea7ede), X(0x5c215d41),
+ X(0x5c58179d), X(0x5c8eadbe), X(0x5cc51f6f), X(0x5cfb6c7c),
+ X(0x5d3194b2), X(0x5d6797de), X(0x5d9d75cf), X(0x5dd32e51),
+ X(0x5e08c132), X(0x5e3e2e43), X(0x5e737551), X(0x5ea8962d),
+ X(0x5edd90a7), X(0x5f12648e), X(0x5f4711b4), X(0x5f7b97ea),
+ X(0x5faff702), X(0x5fe42ece), X(0x60183f20), X(0x604c27cc),
+ X(0x607fe8a6), X(0x60b38180), X(0x60e6f22f), X(0x611a3a89),
+ X(0x614d5a62), X(0x61805190), X(0x61b31fe9), X(0x61e5c545),
+ X(0x62184179), X(0x624a945d), X(0x627cbdca), X(0x62aebd98),
+ X(0x62e0939f), X(0x63123fba), X(0x6343c1c1), X(0x6375198f),
+ X(0x63a646ff), X(0x63d749ec), X(0x64082232), X(0x6438cfad),
+ X(0x64695238), X(0x6499a9b3), X(0x64c9d5f9), X(0x64f9d6ea),
+ X(0x6529ac63), X(0x65595643), X(0x6588d46a), X(0x65b826b8),
+ X(0x65e74d0e), X(0x6616474b), X(0x66451552), X(0x6673b704),
+ X(0x66a22c44), X(0x66d074f4), X(0x66fe90f8), X(0x672c8033),
+ X(0x675a428a), X(0x6787d7e1), X(0x67b5401f), X(0x67e27b27),
+ X(0x680f88e1), X(0x683c6934), X(0x68691c05), X(0x6895a13e),
+ X(0x68c1f8c7), X(0x68ee2287), X(0x691a1e68), X(0x6945ec54),
+ X(0x69718c35), X(0x699cfdf5), X(0x69c8417f), X(0x69f356c0),
+ X(0x6a1e3da3), X(0x6a48f615), X(0x6a738002), X(0x6a9ddb5a),
+ X(0x6ac80808), X(0x6af205fd), X(0x6b1bd526), X(0x6b457575),
+ X(0x6b6ee6d8), X(0x6b982940), X(0x6bc13c9f), X(0x6bea20e5),
+ X(0x6c12d605), X(0x6c3b5bf1), X(0x6c63b29c), X(0x6c8bd9fb),
+ X(0x6cb3d200), X(0x6cdb9aa0), X(0x6d0333d0), X(0x6d2a9d86),
+ X(0x6d51d7b7), X(0x6d78e25a), X(0x6d9fbd67), X(0x6dc668d3),
+ X(0x6dece498), X(0x6e1330ad), X(0x6e394d0c), X(0x6e5f39ae),
+ X(0x6e84f68d), X(0x6eaa83a2), X(0x6ecfe0ea), X(0x6ef50e5e),
+ X(0x6f1a0bfc), X(0x6f3ed9bf), X(0x6f6377a4), X(0x6f87e5a8),
+ X(0x6fac23c9), X(0x6fd03206), X(0x6ff4105c), X(0x7017becc),
+ X(0x703b3d54), X(0x705e8bf5), X(0x7081aaaf), X(0x70a49984),
+ X(0x70c75874), X(0x70e9e783), X(0x710c46b2), X(0x712e7605),
+ X(0x7150757f), X(0x71724523), X(0x7193e4f6), X(0x71b554fd),
+ X(0x71d6953e), X(0x71f7a5bd), X(0x72188681), X(0x72393792),
+ X(0x7259b8f5), X(0x727a0ab2), X(0x729a2cd2), X(0x72ba1f5d),
+ X(0x72d9e25c), X(0x72f975d8), X(0x7318d9db), X(0x73380e6f),
+ X(0x735713a0), X(0x7375e978), X(0x73949003), X(0x73b3074c),
+ X(0x73d14f61), X(0x73ef684f), X(0x740d5222), X(0x742b0ce9),
+ X(0x744898b1), X(0x7465f589), X(0x74832381), X(0x74a022a8),
+ X(0x74bcf30e), X(0x74d994c3), X(0x74f607d8), X(0x75124c5f),
+ X(0x752e6268), X(0x754a4a05), X(0x7566034b), X(0x75818e4a),
+ X(0x759ceb16), X(0x75b819c4), X(0x75d31a66), X(0x75eded12),
+ X(0x760891dc), X(0x762308da), X(0x763d5221), X(0x76576dc8),
+ X(0x76715be4), X(0x768b1c8c), X(0x76a4afd9), X(0x76be15e0),
+ X(0x76d74ebb), X(0x76f05a82), X(0x7709394d), X(0x7721eb35),
+ X(0x773a7054), X(0x7752c8c4), X(0x776af49f), X(0x7782f400),
+ X(0x779ac701), X(0x77b26dbd), X(0x77c9e851), X(0x77e136d8),
+ X(0x77f8596f), X(0x780f5032), X(0x78261b3f), X(0x783cbab2),
+ X(0x78532eaa), X(0x78697745), X(0x787f94a0), X(0x789586db),
+ X(0x78ab4e15), X(0x78c0ea6d), X(0x78d65c03), X(0x78eba2f7),
+ X(0x7900bf68), X(0x7915b179), X(0x792a7949), X(0x793f16fb),
+ X(0x79538aaf), X(0x7967d488), X(0x797bf4a8), X(0x798feb31),
+ X(0x79a3b846), X(0x79b75c0a), X(0x79cad6a1), X(0x79de282e),
+ X(0x79f150d5), X(0x7a0450bb), X(0x7a172803), X(0x7a29d6d3),
+ X(0x7a3c5d50), X(0x7a4ebb9f), X(0x7a60f1e6), X(0x7a73004a),
+ X(0x7a84e6f2), X(0x7a96a604), X(0x7aa83da7), X(0x7ab9ae01),
+ X(0x7acaf73a), X(0x7adc1979), X(0x7aed14e6), X(0x7afde9a8),
+ X(0x7b0e97e8), X(0x7b1f1fcd), X(0x7b2f8182), X(0x7b3fbd2d),
+ X(0x7b4fd2f9), X(0x7b5fc30f), X(0x7b6f8d98), X(0x7b7f32bd),
+ X(0x7b8eb2a9), X(0x7b9e0d85), X(0x7bad437d), X(0x7bbc54b9),
+ X(0x7bcb4166), X(0x7bda09ae), X(0x7be8adbc), X(0x7bf72dbc),
+ X(0x7c0589d8), X(0x7c13c23d), X(0x7c21d716), X(0x7c2fc88f),
+ X(0x7c3d96d5), X(0x7c4b4214), X(0x7c58ca78), X(0x7c66302d),
+ X(0x7c737362), X(0x7c809443), X(0x7c8d92fc), X(0x7c9a6fbc),
+ X(0x7ca72aaf), X(0x7cb3c404), X(0x7cc03be8), X(0x7ccc9288),
+ X(0x7cd8c814), X(0x7ce4dcb9), X(0x7cf0d0a5), X(0x7cfca406),
+ X(0x7d08570c), X(0x7d13e9e5), X(0x7d1f5cbf), X(0x7d2aafca),
+ X(0x7d35e335), X(0x7d40f72e), X(0x7d4bebe4), X(0x7d56c188),
+ X(0x7d617848), X(0x7d6c1054), X(0x7d7689db), X(0x7d80e50e),
+ X(0x7d8b221b), X(0x7d954133), X(0x7d9f4286), X(0x7da92643),
+ X(0x7db2ec9b), X(0x7dbc95bd), X(0x7dc621da), X(0x7dcf9123),
+ X(0x7dd8e3c6), X(0x7de219f6), X(0x7deb33e2), X(0x7df431ba),
+ X(0x7dfd13af), X(0x7e05d9f2), X(0x7e0e84b4), X(0x7e171424),
+ X(0x7e1f8874), X(0x7e27e1d4), X(0x7e302074), X(0x7e384487),
+ X(0x7e404e3c), X(0x7e483dc4), X(0x7e501350), X(0x7e57cf11),
+ X(0x7e5f7138), X(0x7e66f9f4), X(0x7e6e6979), X(0x7e75bff5),
+ X(0x7e7cfd9a), X(0x7e842298), X(0x7e8b2f22), X(0x7e922366),
+ X(0x7e98ff97), X(0x7e9fc3e4), X(0x7ea6707f), X(0x7ead0598),
+ X(0x7eb38360), X(0x7eb9ea07), X(0x7ec039bf), X(0x7ec672b7),
+ X(0x7ecc9521), X(0x7ed2a12c), X(0x7ed8970a), X(0x7ede76ea),
+ X(0x7ee440fd), X(0x7ee9f573), X(0x7eef947d), X(0x7ef51e4b),
+ X(0x7efa930d), X(0x7efff2f2), X(0x7f053e2b), X(0x7f0a74e8),
+ X(0x7f0f9758), X(0x7f14a5ac), X(0x7f19a013), X(0x7f1e86bc),
+ X(0x7f2359d8), X(0x7f281995), X(0x7f2cc623), X(0x7f315fb1),
+ X(0x7f35e66e), X(0x7f3a5a8a), X(0x7f3ebc33), X(0x7f430b98),
+ X(0x7f4748e7), X(0x7f4b7450), X(0x7f4f8e01), X(0x7f539629),
+ X(0x7f578cf5), X(0x7f5b7293), X(0x7f5f4732), X(0x7f630b00),
+ X(0x7f66be2b), X(0x7f6a60df), X(0x7f6df34b), X(0x7f71759b),
+ X(0x7f74e7fe), X(0x7f784aa0), X(0x7f7b9daf), X(0x7f7ee156),
+ X(0x7f8215c3), X(0x7f853b22), X(0x7f88519f), X(0x7f8b5967),
+ X(0x7f8e52a6), X(0x7f913d87), X(0x7f941a36), X(0x7f96e8df),
+ X(0x7f99a9ad), X(0x7f9c5ccb), X(0x7f9f0265), X(0x7fa19aa5),
+ X(0x7fa425b5), X(0x7fa6a3c1), X(0x7fa914f3), X(0x7fab7974),
+ X(0x7fadd16f), X(0x7fb01d0d), X(0x7fb25c78), X(0x7fb48fd9),
+ X(0x7fb6b75a), X(0x7fb8d323), X(0x7fbae35d), X(0x7fbce831),
+ X(0x7fbee1c7), X(0x7fc0d047), X(0x7fc2b3d9), X(0x7fc48ca5),
+ X(0x7fc65ad3), X(0x7fc81e88), X(0x7fc9d7ee), X(0x7fcb872a),
+ X(0x7fcd2c63), X(0x7fcec7bf), X(0x7fd05966), X(0x7fd1e17c),
+ X(0x7fd36027), X(0x7fd4d58d), X(0x7fd641d3), X(0x7fd7a51e),
+ X(0x7fd8ff94), X(0x7fda5157), X(0x7fdb9a8e), X(0x7fdcdb5b),
+ X(0x7fde13e2), X(0x7fdf4448), X(0x7fe06caf), X(0x7fe18d3b),
+ X(0x7fe2a60e), X(0x7fe3b74b), X(0x7fe4c114), X(0x7fe5c38b),
+ X(0x7fe6bed2), X(0x7fe7b30a), X(0x7fe8a055), X(0x7fe986d4),
+ X(0x7fea66a7), X(0x7feb3ff0), X(0x7fec12cd), X(0x7fecdf5f),
+ X(0x7feda5c5), X(0x7fee6620), X(0x7fef208d), X(0x7fefd52c),
+ X(0x7ff0841c), X(0x7ff12d7a), X(0x7ff1d164), X(0x7ff26ff9),
+ X(0x7ff30955), X(0x7ff39d96), X(0x7ff42cd9), X(0x7ff4b739),
+ X(0x7ff53cd4), X(0x7ff5bdc5), X(0x7ff63a28), X(0x7ff6b217),
+ X(0x7ff725af), X(0x7ff7950a), X(0x7ff80043), X(0x7ff86773),
+ X(0x7ff8cab4), X(0x7ff92a21), X(0x7ff985d1), X(0x7ff9dddf),
+ X(0x7ffa3262), X(0x7ffa8374), X(0x7ffad12c), X(0x7ffb1ba1),
+ X(0x7ffb62ec), X(0x7ffba723), X(0x7ffbe85c), X(0x7ffc26b0),
+ X(0x7ffc6233), X(0x7ffc9afb), X(0x7ffcd11e), X(0x7ffd04b1),
+ X(0x7ffd35c9), X(0x7ffd647b), X(0x7ffd90da), X(0x7ffdbafa),
+ X(0x7ffde2f0), X(0x7ffe08ce), X(0x7ffe2ca7), X(0x7ffe4e8e),
+ X(0x7ffe6e95), X(0x7ffe8cce), X(0x7ffea94a), X(0x7ffec41b),
+ X(0x7ffedd52), X(0x7ffef4ff), X(0x7fff0b33), X(0x7fff1ffd),
+ X(0x7fff336e), X(0x7fff4593), X(0x7fff567d), X(0x7fff663a),
+ X(0x7fff74d8), X(0x7fff8265), X(0x7fff8eee), X(0x7fff9a81),
+ X(0x7fffa52b), X(0x7fffaef8), X(0x7fffb7f5), X(0x7fffc02d),
+ X(0x7fffc7ab), X(0x7fffce7c), X(0x7fffd4a9), X(0x7fffda3e),
+ X(0x7fffdf44), X(0x7fffe3c6), X(0x7fffe7cc), X(0x7fffeb60),
+ X(0x7fffee8a), X(0x7ffff153), X(0x7ffff3c4), X(0x7ffff5e3),
+ X(0x7ffff7b8), X(0x7ffff94b), X(0x7ffffaa1), X(0x7ffffbc1),
+ X(0x7ffffcb2), X(0x7ffffd78), X(0x7ffffe19), X(0x7ffffe9a),
+ X(0x7ffffeff), X(0x7fffff4e), X(0x7fffff89), X(0x7fffffb3),
+ X(0x7fffffd2), X(0x7fffffe6), X(0x7ffffff3), X(0x7ffffffa),
+ X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
+};
+
+static LOOKUP_T vwin4096[2048] = {
+ X(0x000001f0), X(0x00001171), X(0x00003072), X(0x00005ef5),
+ X(0x00009cf8), X(0x0000ea7c), X(0x00014780), X(0x0001b405),
+ X(0x0002300b), X(0x0002bb91), X(0x00035698), X(0x0004011e),
+ X(0x0004bb25), X(0x000584ac), X(0x00065db3), X(0x0007463a),
+ X(0x00083e41), X(0x000945c7), X(0x000a5ccc), X(0x000b8350),
+ X(0x000cb954), X(0x000dfed7), X(0x000f53d8), X(0x0010b857),
+ X(0x00122c55), X(0x0013afd1), X(0x001542ca), X(0x0016e541),
+ X(0x00189735), X(0x001a58a7), X(0x001c2995), X(0x001e09ff),
+ X(0x001ff9e6), X(0x0021f948), X(0x00240826), X(0x00262680),
+ X(0x00285454), X(0x002a91a3), X(0x002cde6c), X(0x002f3aaf),
+ X(0x0031a66b), X(0x003421a0), X(0x0036ac4f), X(0x00394675),
+ X(0x003bf014), X(0x003ea92a), X(0x004171b7), X(0x004449bb),
+ X(0x00473135), X(0x004a2824), X(0x004d2e8a), X(0x00504463),
+ X(0x005369b2), X(0x00569e74), X(0x0059e2aa), X(0x005d3652),
+ X(0x0060996d), X(0x00640bf9), X(0x00678df7), X(0x006b1f66),
+ X(0x006ec045), X(0x00727093), X(0x00763051), X(0x0079ff7d),
+ X(0x007dde16), X(0x0081cc1d), X(0x0085c991), X(0x0089d671),
+ X(0x008df2bc), X(0x00921e71), X(0x00965991), X(0x009aa41a),
+ X(0x009efe0c), X(0x00a36766), X(0x00a7e028), X(0x00ac6850),
+ X(0x00b0ffde), X(0x00b5a6d1), X(0x00ba5d28), X(0x00bf22e4),
+ X(0x00c3f802), X(0x00c8dc83), X(0x00cdd065), X(0x00d2d3a8),
+ X(0x00d7e64a), X(0x00dd084c), X(0x00e239ac), X(0x00e77a69),
+ X(0x00ecca83), X(0x00f229f9), X(0x00f798ca), X(0x00fd16f5),
+ X(0x0102a479), X(0x01084155), X(0x010ded89), X(0x0113a913),
+ X(0x011973f3), X(0x011f4e27), X(0x012537af), X(0x012b308a),
+ X(0x013138b7), X(0x01375035), X(0x013d7702), X(0x0143ad1f),
+ X(0x0149f289), X(0x01504741), X(0x0156ab44), X(0x015d1e92),
+ X(0x0163a12a), X(0x016a330b), X(0x0170d433), X(0x017784a3),
+ X(0x017e4458), X(0x01851351), X(0x018bf18e), X(0x0192df0d),
+ X(0x0199dbcd), X(0x01a0e7cd), X(0x01a8030c), X(0x01af2d89),
+ X(0x01b66743), X(0x01bdb038), X(0x01c50867), X(0x01cc6fd0),
+ X(0x01d3e670), X(0x01db6c47), X(0x01e30153), X(0x01eaa593),
+ X(0x01f25907), X(0x01fa1bac), X(0x0201ed81), X(0x0209ce86),
+ X(0x0211beb8), X(0x0219be17), X(0x0221cca2), X(0x0229ea56),
+ X(0x02321733), X(0x023a5337), X(0x02429e60), X(0x024af8af),
+ X(0x02536220), X(0x025bdab3), X(0x02646267), X(0x026cf93a),
+ X(0x02759f2a), X(0x027e5436), X(0x0287185d), X(0x028feb9d),
+ X(0x0298cdf4), X(0x02a1bf62), X(0x02aabfe5), X(0x02b3cf7b),
+ X(0x02bcee23), X(0x02c61bdb), X(0x02cf58a2), X(0x02d8a475),
+ X(0x02e1ff55), X(0x02eb693e), X(0x02f4e230), X(0x02fe6a29),
+ X(0x03080127), X(0x0311a729), X(0x031b5c2d), X(0x03252031),
+ X(0x032ef334), X(0x0338d534), X(0x0342c630), X(0x034cc625),
+ X(0x0356d512), X(0x0360f2f6), X(0x036b1fce), X(0x03755b99),
+ X(0x037fa655), X(0x038a0001), X(0x0394689a), X(0x039ee020),
+ X(0x03a9668f), X(0x03b3fbe6), X(0x03bea024), X(0x03c95347),
+ X(0x03d4154d), X(0x03dee633), X(0x03e9c5f9), X(0x03f4b49b),
+ X(0x03ffb219), X(0x040abe71), X(0x0415d9a0), X(0x042103a5),
+ X(0x042c3c7d), X(0x04378428), X(0x0442daa2), X(0x044e3fea),
+ X(0x0459b3fd), X(0x046536db), X(0x0470c880), X(0x047c68eb),
+ X(0x0488181a), X(0x0493d60b), X(0x049fa2bc), X(0x04ab7e2a),
+ X(0x04b76854), X(0x04c36137), X(0x04cf68d1), X(0x04db7f21),
+ X(0x04e7a424), X(0x04f3d7d8), X(0x05001a3b), X(0x050c6b4a),
+ X(0x0518cb04), X(0x05253966), X(0x0531b66e), X(0x053e421a),
+ X(0x054adc68), X(0x05578555), X(0x05643cdf), X(0x05710304),
+ X(0x057dd7c1), X(0x058abb15), X(0x0597acfd), X(0x05a4ad76),
+ X(0x05b1bc7f), X(0x05beda14), X(0x05cc0635), X(0x05d940dd),
+ X(0x05e68a0b), X(0x05f3e1bd), X(0x060147f0), X(0x060ebca1),
+ X(0x061c3fcf), X(0x0629d176), X(0x06377194), X(0x06452027),
+ X(0x0652dd2c), X(0x0660a8a2), X(0x066e8284), X(0x067c6ad1),
+ X(0x068a6186), X(0x069866a1), X(0x06a67a1e), X(0x06b49bfc),
+ X(0x06c2cc38), X(0x06d10acf), X(0x06df57bf), X(0x06edb304),
+ X(0x06fc1c9d), X(0x070a9487), X(0x07191abe), X(0x0727af40),
+ X(0x0736520b), X(0x0745031c), X(0x0753c270), X(0x07629004),
+ X(0x07716bd6), X(0x078055e2), X(0x078f4e26), X(0x079e549f),
+ X(0x07ad694b), X(0x07bc8c26), X(0x07cbbd2e), X(0x07dafc5f),
+ X(0x07ea49b7), X(0x07f9a533), X(0x08090ed1), X(0x0818868c),
+ X(0x08280c62), X(0x0837a051), X(0x08474255), X(0x0856f26b),
+ X(0x0866b091), X(0x08767cc3), X(0x088656fe), X(0x08963f3f),
+ X(0x08a63584), X(0x08b639c8), X(0x08c64c0a), X(0x08d66c45),
+ X(0x08e69a77), X(0x08f6d69d), X(0x090720b3), X(0x091778b7),
+ X(0x0927dea5), X(0x0938527a), X(0x0948d433), X(0x095963cc),
+ X(0x096a0143), X(0x097aac94), X(0x098b65bb), X(0x099c2cb6),
+ X(0x09ad0182), X(0x09bde41a), X(0x09ced47d), X(0x09dfd2a5),
+ X(0x09f0de90), X(0x0a01f83b), X(0x0a131fa3), X(0x0a2454c3),
+ X(0x0a359798), X(0x0a46e820), X(0x0a584656), X(0x0a69b237),
+ X(0x0a7b2bc0), X(0x0a8cb2ec), X(0x0a9e47ba), X(0x0aafea24),
+ X(0x0ac19a29), X(0x0ad357c3), X(0x0ae522ef), X(0x0af6fbab),
+ X(0x0b08e1f1), X(0x0b1ad5c0), X(0x0b2cd712), X(0x0b3ee5e5),
+ X(0x0b510234), X(0x0b632bfd), X(0x0b75633b), X(0x0b87a7eb),
+ X(0x0b99fa08), X(0x0bac5990), X(0x0bbec67e), X(0x0bd140cf),
+ X(0x0be3c87e), X(0x0bf65d89), X(0x0c08ffeb), X(0x0c1bafa1),
+ X(0x0c2e6ca6), X(0x0c4136f6), X(0x0c540e8f), X(0x0c66f36c),
+ X(0x0c79e588), X(0x0c8ce4e1), X(0x0c9ff172), X(0x0cb30b37),
+ X(0x0cc6322c), X(0x0cd9664d), X(0x0ceca797), X(0x0cfff605),
+ X(0x0d135193), X(0x0d26ba3d), X(0x0d3a2fff), X(0x0d4db2d5),
+ X(0x0d6142ba), X(0x0d74dfac), X(0x0d8889a5), X(0x0d9c40a1),
+ X(0x0db0049d), X(0x0dc3d593), X(0x0dd7b380), X(0x0deb9e60),
+ X(0x0dff962f), X(0x0e139ae7), X(0x0e27ac85), X(0x0e3bcb05),
+ X(0x0e4ff662), X(0x0e642e98), X(0x0e7873a2), X(0x0e8cc57d),
+ X(0x0ea12423), X(0x0eb58f91), X(0x0eca07c2), X(0x0ede8cb1),
+ X(0x0ef31e5b), X(0x0f07bcba), X(0x0f1c67cb), X(0x0f311f88),
+ X(0x0f45e3ee), X(0x0f5ab4f7), X(0x0f6f92a0), X(0x0f847ce3),
+ X(0x0f9973bc), X(0x0fae7726), X(0x0fc3871e), X(0x0fd8a39d),
+ X(0x0fedcca1), X(0x10030223), X(0x1018441f), X(0x102d9291),
+ X(0x1042ed74), X(0x105854c3), X(0x106dc879), X(0x10834892),
+ X(0x1098d508), X(0x10ae6dd8), X(0x10c412fc), X(0x10d9c46f),
+ X(0x10ef822d), X(0x11054c30), X(0x111b2274), X(0x113104f5),
+ X(0x1146f3ac), X(0x115cee95), X(0x1172f5ab), X(0x118908e9),
+ X(0x119f284a), X(0x11b553ca), X(0x11cb8b62), X(0x11e1cf0f),
+ X(0x11f81ecb), X(0x120e7a90), X(0x1224e25a), X(0x123b5624),
+ X(0x1251d5e9), X(0x126861a3), X(0x127ef94e), X(0x12959ce3),
+ X(0x12ac4c5f), X(0x12c307bb), X(0x12d9cef2), X(0x12f0a200),
+ X(0x130780df), X(0x131e6b8a), X(0x133561fa), X(0x134c642c),
+ X(0x1363721a), X(0x137a8bbe), X(0x1391b113), X(0x13a8e214),
+ X(0x13c01eba), X(0x13d76702), X(0x13eebae5), X(0x14061a5e),
+ X(0x141d8567), X(0x1434fbfb), X(0x144c7e14), X(0x14640bae),
+ X(0x147ba4c1), X(0x14934949), X(0x14aaf941), X(0x14c2b4a2),
+ X(0x14da7b67), X(0x14f24d8a), X(0x150a2b06), X(0x152213d5),
+ X(0x153a07f1), X(0x15520755), X(0x156a11fb), X(0x158227dd),
+ X(0x159a48f5), X(0x15b2753d), X(0x15caacb1), X(0x15e2ef49),
+ X(0x15fb3d01), X(0x161395d2), X(0x162bf9b6), X(0x164468a8),
+ X(0x165ce2a1), X(0x1675679c), X(0x168df793), X(0x16a69280),
+ X(0x16bf385c), X(0x16d7e922), X(0x16f0a4cc), X(0x17096b54),
+ X(0x17223cb4), X(0x173b18e5), X(0x1753ffe2), X(0x176cf1a5),
+ X(0x1785ee27), X(0x179ef562), X(0x17b80750), X(0x17d123eb),
+ X(0x17ea4b2d), X(0x18037d10), X(0x181cb98d), X(0x1836009e),
+ X(0x184f523c), X(0x1868ae63), X(0x1882150a), X(0x189b862c),
+ X(0x18b501c4), X(0x18ce87c9), X(0x18e81836), X(0x1901b305),
+ X(0x191b582f), X(0x193507ad), X(0x194ec17a), X(0x1968858f),
+ X(0x198253e5), X(0x199c2c75), X(0x19b60f3a), X(0x19cffc2d),
+ X(0x19e9f347), X(0x1a03f482), X(0x1a1dffd7), X(0x1a381540),
+ X(0x1a5234b5), X(0x1a6c5e31), X(0x1a8691ac), X(0x1aa0cf21),
+ X(0x1abb1687), X(0x1ad567da), X(0x1aefc311), X(0x1b0a2826),
+ X(0x1b249712), X(0x1b3f0fd0), X(0x1b599257), X(0x1b741ea1),
+ X(0x1b8eb4a7), X(0x1ba95462), X(0x1bc3fdcd), X(0x1bdeb0de),
+ X(0x1bf96d91), X(0x1c1433dd), X(0x1c2f03bc), X(0x1c49dd27),
+ X(0x1c64c017), X(0x1c7fac85), X(0x1c9aa269), X(0x1cb5a1be),
+ X(0x1cd0aa7c), X(0x1cebbc9c), X(0x1d06d816), X(0x1d21fce4),
+ X(0x1d3d2aff), X(0x1d586260), X(0x1d73a2fe), X(0x1d8eecd4),
+ X(0x1daa3fda), X(0x1dc59c09), X(0x1de1015a), X(0x1dfc6fc5),
+ X(0x1e17e743), X(0x1e3367cd), X(0x1e4ef15b), X(0x1e6a83e7),
+ X(0x1e861f6a), X(0x1ea1c3da), X(0x1ebd7133), X(0x1ed9276b),
+ X(0x1ef4e67c), X(0x1f10ae5e), X(0x1f2c7f0a), X(0x1f485879),
+ X(0x1f643aa2), X(0x1f80257f), X(0x1f9c1908), X(0x1fb81536),
+ X(0x1fd41a00), X(0x1ff02761), X(0x200c3d4f), X(0x20285bc3),
+ X(0x204482b7), X(0x2060b221), X(0x207ce9fb), X(0x20992a3e),
+ X(0x20b572e0), X(0x20d1c3dc), X(0x20ee1d28), X(0x210a7ebe),
+ X(0x2126e895), X(0x21435aa6), X(0x215fd4ea), X(0x217c5757),
+ X(0x2198e1e8), X(0x21b57493), X(0x21d20f51), X(0x21eeb21b),
+ X(0x220b5ce7), X(0x22280fb0), X(0x2244ca6c), X(0x22618d13),
+ X(0x227e579f), X(0x229b2a06), X(0x22b80442), X(0x22d4e649),
+ X(0x22f1d015), X(0x230ec19d), X(0x232bbad9), X(0x2348bbc1),
+ X(0x2365c44c), X(0x2382d474), X(0x239fec30), X(0x23bd0b78),
+ X(0x23da3244), X(0x23f7608b), X(0x24149646), X(0x2431d36c),
+ X(0x244f17f5), X(0x246c63da), X(0x2489b711), X(0x24a71193),
+ X(0x24c47358), X(0x24e1dc57), X(0x24ff4c88), X(0x251cc3e2),
+ X(0x253a425e), X(0x2557c7f4), X(0x2575549a), X(0x2592e848),
+ X(0x25b082f7), X(0x25ce249e), X(0x25ebcd34), X(0x26097cb2),
+ X(0x2627330e), X(0x2644f040), X(0x2662b441), X(0x26807f07),
+ X(0x269e5089), X(0x26bc28c1), X(0x26da07a4), X(0x26f7ed2b),
+ X(0x2715d94d), X(0x2733cc02), X(0x2751c540), X(0x276fc500),
+ X(0x278dcb39), X(0x27abd7e2), X(0x27c9eaf3), X(0x27e80463),
+ X(0x28062429), X(0x28244a3e), X(0x28427697), X(0x2860a92d),
+ X(0x287ee1f7), X(0x289d20eb), X(0x28bb6603), X(0x28d9b134),
+ X(0x28f80275), X(0x291659c0), X(0x2934b709), X(0x29531a49),
+ X(0x29718378), X(0x298ff28b), X(0x29ae677b), X(0x29cce23e),
+ X(0x29eb62cb), X(0x2a09e91b), X(0x2a287523), X(0x2a4706dc),
+ X(0x2a659e3c), X(0x2a843b39), X(0x2aa2ddcd), X(0x2ac185ec),
+ X(0x2ae0338f), X(0x2afee6ad), X(0x2b1d9f3c), X(0x2b3c5d33),
+ X(0x2b5b208b), X(0x2b79e939), X(0x2b98b734), X(0x2bb78a74),
+ X(0x2bd662ef), X(0x2bf5409d), X(0x2c142374), X(0x2c330b6b),
+ X(0x2c51f87a), X(0x2c70ea97), X(0x2c8fe1b9), X(0x2caeddd6),
+ X(0x2ccddee7), X(0x2cece4e1), X(0x2d0befbb), X(0x2d2aff6d),
+ X(0x2d4a13ec), X(0x2d692d31), X(0x2d884b32), X(0x2da76de4),
+ X(0x2dc69540), X(0x2de5c13d), X(0x2e04f1d0), X(0x2e2426f0),
+ X(0x2e436095), X(0x2e629eb4), X(0x2e81e146), X(0x2ea1283f),
+ X(0x2ec07398), X(0x2edfc347), X(0x2eff1742), X(0x2f1e6f80),
+ X(0x2f3dcbf8), X(0x2f5d2ca0), X(0x2f7c916f), X(0x2f9bfa5c),
+ X(0x2fbb675d), X(0x2fdad869), X(0x2ffa4d76), X(0x3019c67b),
+ X(0x3039436f), X(0x3058c448), X(0x307848fc), X(0x3097d183),
+ X(0x30b75dd3), X(0x30d6ede2), X(0x30f681a6), X(0x31161917),
+ X(0x3135b42b), X(0x315552d8), X(0x3174f514), X(0x31949ad7),
+ X(0x31b44417), X(0x31d3f0ca), X(0x31f3a0e6), X(0x32135462),
+ X(0x32330b35), X(0x3252c555), X(0x327282b7), X(0x32924354),
+ X(0x32b20720), X(0x32d1ce13), X(0x32f19823), X(0x33116546),
+ X(0x33313573), X(0x3351089f), X(0x3370dec2), X(0x3390b7d1),
+ X(0x33b093c3), X(0x33d0728f), X(0x33f05429), X(0x3410388a),
+ X(0x34301fa7), X(0x34500977), X(0x346ff5ef), X(0x348fe506),
+ X(0x34afd6b3), X(0x34cfcaeb), X(0x34efc1a5), X(0x350fbad7),
+ X(0x352fb678), X(0x354fb47d), X(0x356fb4dd), X(0x358fb78e),
+ X(0x35afbc86), X(0x35cfc3bc), X(0x35efcd25), X(0x360fd8b8),
+ X(0x362fe66c), X(0x364ff636), X(0x3670080c), X(0x36901be5),
+ X(0x36b031b7), X(0x36d04978), X(0x36f0631e), X(0x37107ea0),
+ X(0x37309bf3), X(0x3750bb0e), X(0x3770dbe6), X(0x3790fe73),
+ X(0x37b122aa), X(0x37d14881), X(0x37f16fee), X(0x381198e8),
+ X(0x3831c365), X(0x3851ef5a), X(0x38721cbe), X(0x38924b87),
+ X(0x38b27bac), X(0x38d2ad21), X(0x38f2dfde), X(0x391313d8),
+ X(0x39334906), X(0x39537f5d), X(0x3973b6d4), X(0x3993ef60),
+ X(0x39b428f9), X(0x39d46393), X(0x39f49f25), X(0x3a14dba6),
+ X(0x3a35190a), X(0x3a555748), X(0x3a759657), X(0x3a95d62c),
+ X(0x3ab616be), X(0x3ad65801), X(0x3af699ed), X(0x3b16dc78),
+ X(0x3b371f97), X(0x3b576341), X(0x3b77a76c), X(0x3b97ec0d),
+ X(0x3bb8311b), X(0x3bd8768b), X(0x3bf8bc55), X(0x3c19026d),
+ X(0x3c3948ca), X(0x3c598f62), X(0x3c79d62b), X(0x3c9a1d1b),
+ X(0x3cba6428), X(0x3cdaab48), X(0x3cfaf271), X(0x3d1b3999),
+ X(0x3d3b80b6), X(0x3d5bc7be), X(0x3d7c0ea8), X(0x3d9c5569),
+ X(0x3dbc9bf7), X(0x3ddce248), X(0x3dfd2852), X(0x3e1d6e0c),
+ X(0x3e3db36c), X(0x3e5df866), X(0x3e7e3cf2), X(0x3e9e8106),
+ X(0x3ebec497), X(0x3edf079b), X(0x3eff4a09), X(0x3f1f8bd7),
+ X(0x3f3fccfa), X(0x3f600d69), X(0x3f804d1a), X(0x3fa08c02),
+ X(0x3fc0ca19), X(0x3fe10753), X(0x400143a7), X(0x40217f0a),
+ X(0x4041b974), X(0x4061f2da), X(0x40822b32), X(0x40a26272),
+ X(0x40c29891), X(0x40e2cd83), X(0x41030140), X(0x412333bd),
+ X(0x414364f1), X(0x416394d2), X(0x4183c355), X(0x41a3f070),
+ X(0x41c41c1b), X(0x41e4464a), X(0x42046ef4), X(0x42249610),
+ X(0x4244bb92), X(0x4264df72), X(0x428501a5), X(0x42a52222),
+ X(0x42c540de), X(0x42e55dd0), X(0x430578ed), X(0x4325922d),
+ X(0x4345a985), X(0x4365beeb), X(0x4385d255), X(0x43a5e3ba),
+ X(0x43c5f30f), X(0x43e6004b), X(0x44060b65), X(0x44261451),
+ X(0x44461b07), X(0x44661f7c), X(0x448621a7), X(0x44a6217d),
+ X(0x44c61ef6), X(0x44e61a07), X(0x450612a6), X(0x452608ca),
+ X(0x4545fc69), X(0x4565ed79), X(0x4585dbf1), X(0x45a5c7c6),
+ X(0x45c5b0ef), X(0x45e59761), X(0x46057b15), X(0x46255bfe),
+ X(0x46453a15), X(0x4665154f), X(0x4684eda2), X(0x46a4c305),
+ X(0x46c4956e), X(0x46e464d3), X(0x4704312b), X(0x4723fa6c),
+ X(0x4743c08d), X(0x47638382), X(0x47834344), X(0x47a2ffc9),
+ X(0x47c2b906), X(0x47e26ef2), X(0x48022183), X(0x4821d0b1),
+ X(0x48417c71), X(0x486124b9), X(0x4880c981), X(0x48a06abe),
+ X(0x48c00867), X(0x48dfa272), X(0x48ff38d6), X(0x491ecb8a),
+ X(0x493e5a84), X(0x495de5b9), X(0x497d6d22), X(0x499cf0b4),
+ X(0x49bc7066), X(0x49dbec2e), X(0x49fb6402), X(0x4a1ad7db),
+ X(0x4a3a47ad), X(0x4a59b370), X(0x4a791b1a), X(0x4a987ea1),
+ X(0x4ab7ddfd), X(0x4ad73924), X(0x4af6900c), X(0x4b15e2ad),
+ X(0x4b3530fc), X(0x4b547af1), X(0x4b73c082), X(0x4b9301a6),
+ X(0x4bb23e53), X(0x4bd17681), X(0x4bf0aa25), X(0x4c0fd937),
+ X(0x4c2f03ae), X(0x4c4e297f), X(0x4c6d4aa3), X(0x4c8c670f),
+ X(0x4cab7eba), X(0x4cca919c), X(0x4ce99fab), X(0x4d08a8de),
+ X(0x4d27ad2c), X(0x4d46ac8b), X(0x4d65a6f3), X(0x4d849c5a),
+ X(0x4da38cb7), X(0x4dc27802), X(0x4de15e31), X(0x4e003f3a),
+ X(0x4e1f1b16), X(0x4e3df1ba), X(0x4e5cc31e), X(0x4e7b8f3a),
+ X(0x4e9a5603), X(0x4eb91771), X(0x4ed7d37b), X(0x4ef68a18),
+ X(0x4f153b3f), X(0x4f33e6e7), X(0x4f528d08), X(0x4f712d97),
+ X(0x4f8fc88e), X(0x4fae5de1), X(0x4fcced8a), X(0x4feb777f),
+ X(0x5009fbb6), X(0x50287a28), X(0x5046f2cc), X(0x50656598),
+ X(0x5083d284), X(0x50a23988), X(0x50c09a9a), X(0x50def5b1),
+ X(0x50fd4ac7), X(0x511b99d0), X(0x5139e2c5), X(0x5158259e),
+ X(0x51766251), X(0x519498d6), X(0x51b2c925), X(0x51d0f334),
+ X(0x51ef16fb), X(0x520d3473), X(0x522b4b91), X(0x52495c4e),
+ X(0x526766a2), X(0x52856a83), X(0x52a367e9), X(0x52c15ecd),
+ X(0x52df4f24), X(0x52fd38e8), X(0x531b1c10), X(0x5338f892),
+ X(0x5356ce68), X(0x53749d89), X(0x539265eb), X(0x53b02788),
+ X(0x53cde257), X(0x53eb964f), X(0x54094369), X(0x5426e99c),
+ X(0x544488df), X(0x5462212c), X(0x547fb279), X(0x549d3cbe),
+ X(0x54babff4), X(0x54d83c12), X(0x54f5b110), X(0x55131ee7),
+ X(0x5530858d), X(0x554de4fc), X(0x556b3d2a), X(0x55888e11),
+ X(0x55a5d7a8), X(0x55c319e7), X(0x55e054c7), X(0x55fd883f),
+ X(0x561ab447), X(0x5637d8d8), X(0x5654f5ea), X(0x56720b75),
+ X(0x568f1971), X(0x56ac1fd7), X(0x56c91e9e), X(0x56e615c0),
+ X(0x57030534), X(0x571fecf2), X(0x573cccf3), X(0x5759a530),
+ X(0x577675a0), X(0x57933e3c), X(0x57affefd), X(0x57ccb7db),
+ X(0x57e968ce), X(0x580611cf), X(0x5822b2d6), X(0x583f4bdd),
+ X(0x585bdcdb), X(0x587865c9), X(0x5894e69f), X(0x58b15f57),
+ X(0x58cdcfe9), X(0x58ea384e), X(0x5906987d), X(0x5922f071),
+ X(0x593f4022), X(0x595b8788), X(0x5977c69c), X(0x5993fd57),
+ X(0x59b02bb2), X(0x59cc51a6), X(0x59e86f2c), X(0x5a04843c),
+ X(0x5a2090d0), X(0x5a3c94e0), X(0x5a589065), X(0x5a748359),
+ X(0x5a906db4), X(0x5aac4f70), X(0x5ac82884), X(0x5ae3f8ec),
+ X(0x5affc09f), X(0x5b1b7f97), X(0x5b3735cd), X(0x5b52e33a),
+ X(0x5b6e87d8), X(0x5b8a239f), X(0x5ba5b689), X(0x5bc1408f),
+ X(0x5bdcc1aa), X(0x5bf839d5), X(0x5c13a907), X(0x5c2f0f3b),
+ X(0x5c4a6c6a), X(0x5c65c08d), X(0x5c810b9e), X(0x5c9c4d97),
+ X(0x5cb78670), X(0x5cd2b623), X(0x5ceddcaa), X(0x5d08f9ff),
+ X(0x5d240e1b), X(0x5d3f18f8), X(0x5d5a1a8f), X(0x5d7512da),
+ X(0x5d9001d3), X(0x5daae773), X(0x5dc5c3b5), X(0x5de09692),
+ X(0x5dfb6004), X(0x5e162004), X(0x5e30d68d), X(0x5e4b8399),
+ X(0x5e662721), X(0x5e80c11f), X(0x5e9b518e), X(0x5eb5d867),
+ X(0x5ed055a4), X(0x5eeac940), X(0x5f053334), X(0x5f1f937b),
+ X(0x5f39ea0f), X(0x5f5436ea), X(0x5f6e7a06), X(0x5f88b35d),
+ X(0x5fa2e2e9), X(0x5fbd08a6), X(0x5fd7248d), X(0x5ff13698),
+ X(0x600b3ec2), X(0x60253d05), X(0x603f315b), X(0x60591bc0),
+ X(0x6072fc2d), X(0x608cd29e), X(0x60a69f0b), X(0x60c06171),
+ X(0x60da19ca), X(0x60f3c80f), X(0x610d6c3d), X(0x6127064d),
+ X(0x6140963a), X(0x615a1bff), X(0x61739797), X(0x618d08fc),
+ X(0x61a67029), X(0x61bfcd1a), X(0x61d91fc8), X(0x61f2682f),
+ X(0x620ba64a), X(0x6224da13), X(0x623e0386), X(0x6257229d),
+ X(0x62703754), X(0x628941a6), X(0x62a2418e), X(0x62bb3706),
+ X(0x62d4220a), X(0x62ed0296), X(0x6305d8a3), X(0x631ea42f),
+ X(0x63376533), X(0x63501bab), X(0x6368c793), X(0x638168e5),
+ X(0x6399ff9e), X(0x63b28bb8), X(0x63cb0d2f), X(0x63e383ff),
+ X(0x63fbf022), X(0x64145195), X(0x642ca853), X(0x6444f457),
+ X(0x645d359e), X(0x64756c22), X(0x648d97e0), X(0x64a5b8d3),
+ X(0x64bdcef6), X(0x64d5da47), X(0x64eddabf), X(0x6505d05c),
+ X(0x651dbb19), X(0x65359af2), X(0x654d6fe3), X(0x656539e7),
+ X(0x657cf8fb), X(0x6594ad1b), X(0x65ac5643), X(0x65c3f46e),
+ X(0x65db8799), X(0x65f30fc0), X(0x660a8ce0), X(0x6621fef3),
+ X(0x663965f7), X(0x6650c1e7), X(0x666812c1), X(0x667f5880),
+ X(0x66969320), X(0x66adc29e), X(0x66c4e6f7), X(0x66dc0026),
+ X(0x66f30e28), X(0x670a10fa), X(0x67210898), X(0x6737f4ff),
+ X(0x674ed62b), X(0x6765ac19), X(0x677c76c5), X(0x6793362c),
+ X(0x67a9ea4b), X(0x67c0931f), X(0x67d730a3), X(0x67edc2d6),
+ X(0x680449b3), X(0x681ac538), X(0x68313562), X(0x68479a2d),
+ X(0x685df396), X(0x6874419b), X(0x688a8438), X(0x68a0bb6a),
+ X(0x68b6e72e), X(0x68cd0782), X(0x68e31c63), X(0x68f925cd),
+ X(0x690f23be), X(0x69251633), X(0x693afd29), X(0x6950d89e),
+ X(0x6966a88f), X(0x697c6cf8), X(0x699225d9), X(0x69a7d32d),
+ X(0x69bd74f3), X(0x69d30b27), X(0x69e895c8), X(0x69fe14d2),
+ X(0x6a138844), X(0x6a28f01b), X(0x6a3e4c54), X(0x6a539ced),
+ X(0x6a68e1e4), X(0x6a7e1b37), X(0x6a9348e3), X(0x6aa86ae6),
+ X(0x6abd813d), X(0x6ad28be7), X(0x6ae78ae2), X(0x6afc7e2b),
+ X(0x6b1165c0), X(0x6b26419f), X(0x6b3b11c7), X(0x6b4fd634),
+ X(0x6b648ee6), X(0x6b793bda), X(0x6b8ddd0e), X(0x6ba27281),
+ X(0x6bb6fc31), X(0x6bcb7a1b), X(0x6bdfec3e), X(0x6bf45299),
+ X(0x6c08ad29), X(0x6c1cfbed), X(0x6c313ee4), X(0x6c45760a),
+ X(0x6c59a160), X(0x6c6dc0e4), X(0x6c81d493), X(0x6c95dc6d),
+ X(0x6ca9d86f), X(0x6cbdc899), X(0x6cd1acea), X(0x6ce5855f),
+ X(0x6cf951f7), X(0x6d0d12b1), X(0x6d20c78c), X(0x6d347087),
+ X(0x6d480da0), X(0x6d5b9ed6), X(0x6d6f2427), X(0x6d829d94),
+ X(0x6d960b1a), X(0x6da96cb9), X(0x6dbcc270), X(0x6dd00c3c),
+ X(0x6de34a1f), X(0x6df67c16), X(0x6e09a221), X(0x6e1cbc3f),
+ X(0x6e2fca6e), X(0x6e42ccaf), X(0x6e55c300), X(0x6e68ad60),
+ X(0x6e7b8bd0), X(0x6e8e5e4d), X(0x6ea124d8), X(0x6eb3df70),
+ X(0x6ec68e13), X(0x6ed930c3), X(0x6eebc77d), X(0x6efe5242),
+ X(0x6f10d111), X(0x6f2343e9), X(0x6f35aacb), X(0x6f4805b5),
+ X(0x6f5a54a8), X(0x6f6c97a2), X(0x6f7ecea4), X(0x6f90f9ae),
+ X(0x6fa318be), X(0x6fb52bd6), X(0x6fc732f4), X(0x6fd92e19),
+ X(0x6feb1d44), X(0x6ffd0076), X(0x700ed7ad), X(0x7020a2eb),
+ X(0x7032622f), X(0x7044157a), X(0x7055bcca), X(0x70675821),
+ X(0x7078e77e), X(0x708a6ae2), X(0x709be24c), X(0x70ad4dbd),
+ X(0x70bead36), X(0x70d000b5), X(0x70e1483d), X(0x70f283cc),
+ X(0x7103b363), X(0x7114d704), X(0x7125eead), X(0x7136fa60),
+ X(0x7147fa1c), X(0x7158ede4), X(0x7169d5b6), X(0x717ab193),
+ X(0x718b817d), X(0x719c4573), X(0x71acfd76), X(0x71bda988),
+ X(0x71ce49a8), X(0x71deddd7), X(0x71ef6617), X(0x71ffe267),
+ X(0x721052ca), X(0x7220b73e), X(0x72310fc6), X(0x72415c62),
+ X(0x72519d14), X(0x7261d1db), X(0x7271faba), X(0x728217b1),
+ X(0x729228c0), X(0x72a22dea), X(0x72b22730), X(0x72c21491),
+ X(0x72d1f611), X(0x72e1cbaf), X(0x72f1956c), X(0x7301534c),
+ X(0x7311054d), X(0x7320ab72), X(0x733045bc), X(0x733fd42d),
+ X(0x734f56c5), X(0x735ecd86), X(0x736e3872), X(0x737d9789),
+ X(0x738ceacf), X(0x739c3243), X(0x73ab6de7), X(0x73ba9dbe),
+ X(0x73c9c1c8), X(0x73d8da08), X(0x73e7e67f), X(0x73f6e72e),
+ X(0x7405dc17), X(0x7414c53c), X(0x7423a29f), X(0x74327442),
+ X(0x74413a26), X(0x744ff44d), X(0x745ea2b9), X(0x746d456c),
+ X(0x747bdc68), X(0x748a67ae), X(0x7498e741), X(0x74a75b23),
+ X(0x74b5c356), X(0x74c41fdb), X(0x74d270b6), X(0x74e0b5e7),
+ X(0x74eeef71), X(0x74fd1d57), X(0x750b3f9a), X(0x7519563c),
+ X(0x75276140), X(0x753560a8), X(0x75435477), X(0x75513cae),
+ X(0x755f1951), X(0x756cea60), X(0x757aafdf), X(0x758869d1),
+ X(0x75961837), X(0x75a3bb14), X(0x75b1526a), X(0x75bede3c),
+ X(0x75cc5e8d), X(0x75d9d35f), X(0x75e73cb5), X(0x75f49a91),
+ X(0x7601ecf6), X(0x760f33e6), X(0x761c6f65), X(0x76299f74),
+ X(0x7636c417), X(0x7643dd51), X(0x7650eb24), X(0x765ded93),
+ X(0x766ae4a0), X(0x7677d050), X(0x7684b0a4), X(0x7691859f),
+ X(0x769e4f45), X(0x76ab0d98), X(0x76b7c09c), X(0x76c46852),
+ X(0x76d104bf), X(0x76dd95e6), X(0x76ea1bc9), X(0x76f6966b),
+ X(0x770305d0), X(0x770f69fb), X(0x771bc2ef), X(0x772810af),
+ X(0x7734533e), X(0x77408aa0), X(0x774cb6d7), X(0x7758d7e8),
+ X(0x7764edd5), X(0x7770f8a2), X(0x777cf852), X(0x7788ece8),
+ X(0x7794d668), X(0x77a0b4d5), X(0x77ac8833), X(0x77b85085),
+ X(0x77c40dce), X(0x77cfc013), X(0x77db6756), X(0x77e7039b),
+ X(0x77f294e6), X(0x77fe1b3b), X(0x7809969c), X(0x7815070e),
+ X(0x78206c93), X(0x782bc731), X(0x783716ea), X(0x78425bc3),
+ X(0x784d95be), X(0x7858c4e1), X(0x7863e92d), X(0x786f02a8),
+ X(0x787a1156), X(0x78851539), X(0x78900e56), X(0x789afcb1),
+ X(0x78a5e04d), X(0x78b0b92f), X(0x78bb875b), X(0x78c64ad4),
+ X(0x78d1039e), X(0x78dbb1be), X(0x78e65537), X(0x78f0ee0e),
+ X(0x78fb7c46), X(0x7905ffe4), X(0x791078ec), X(0x791ae762),
+ X(0x79254b4a), X(0x792fa4a7), X(0x7939f380), X(0x794437d7),
+ X(0x794e71b0), X(0x7958a111), X(0x7962c5fd), X(0x796ce078),
+ X(0x7976f087), X(0x7980f62f), X(0x798af173), X(0x7994e258),
+ X(0x799ec8e2), X(0x79a8a515), X(0x79b276f7), X(0x79bc3e8b),
+ X(0x79c5fbd6), X(0x79cfaedc), X(0x79d957a2), X(0x79e2f62c),
+ X(0x79ec8a7f), X(0x79f6149f), X(0x79ff9492), X(0x7a090a5a),
+ X(0x7a1275fe), X(0x7a1bd781), X(0x7a252ee9), X(0x7a2e7c39),
+ X(0x7a37bf77), X(0x7a40f8a7), X(0x7a4a27ce), X(0x7a534cf0),
+ X(0x7a5c6813), X(0x7a65793b), X(0x7a6e806d), X(0x7a777dad),
+ X(0x7a807100), X(0x7a895a6b), X(0x7a9239f4), X(0x7a9b0f9e),
+ X(0x7aa3db6f), X(0x7aac9d6b), X(0x7ab55597), X(0x7abe03f9),
+ X(0x7ac6a895), X(0x7acf4370), X(0x7ad7d48f), X(0x7ae05bf6),
+ X(0x7ae8d9ac), X(0x7af14db5), X(0x7af9b815), X(0x7b0218d2),
+ X(0x7b0a6ff2), X(0x7b12bd78), X(0x7b1b016a), X(0x7b233bce),
+ X(0x7b2b6ca7), X(0x7b3393fc), X(0x7b3bb1d1), X(0x7b43c62c),
+ X(0x7b4bd111), X(0x7b53d286), X(0x7b5bca90), X(0x7b63b935),
+ X(0x7b6b9e78), X(0x7b737a61), X(0x7b7b4cf3), X(0x7b831634),
+ X(0x7b8ad629), X(0x7b928cd8), X(0x7b9a3a45), X(0x7ba1de77),
+ X(0x7ba97972), X(0x7bb10b3c), X(0x7bb893d9), X(0x7bc01350),
+ X(0x7bc789a6), X(0x7bcef6e0), X(0x7bd65b03), X(0x7bddb616),
+ X(0x7be5081c), X(0x7bec511c), X(0x7bf3911b), X(0x7bfac81f),
+ X(0x7c01f62c), X(0x7c091b49), X(0x7c10377b), X(0x7c174ac7),
+ X(0x7c1e5532), X(0x7c2556c4), X(0x7c2c4f80), X(0x7c333f6c),
+ X(0x7c3a268e), X(0x7c4104ec), X(0x7c47da8a), X(0x7c4ea76f),
+ X(0x7c556ba1), X(0x7c5c2724), X(0x7c62d9fe), X(0x7c698435),
+ X(0x7c7025cf), X(0x7c76bed0), X(0x7c7d4f40), X(0x7c83d723),
+ X(0x7c8a567f), X(0x7c90cd5a), X(0x7c973bb9), X(0x7c9da1a2),
+ X(0x7ca3ff1b), X(0x7caa542a), X(0x7cb0a0d3), X(0x7cb6e51e),
+ X(0x7cbd210f), X(0x7cc354ac), X(0x7cc97ffc), X(0x7ccfa304),
+ X(0x7cd5bdc9), X(0x7cdbd051), X(0x7ce1daa3), X(0x7ce7dcc3),
+ X(0x7cedd6b8), X(0x7cf3c888), X(0x7cf9b238), X(0x7cff93cf),
+ X(0x7d056d51), X(0x7d0b3ec5), X(0x7d110830), X(0x7d16c99a),
+ X(0x7d1c8306), X(0x7d22347c), X(0x7d27de00), X(0x7d2d7f9a),
+ X(0x7d33194f), X(0x7d38ab24), X(0x7d3e351f), X(0x7d43b748),
+ X(0x7d4931a2), X(0x7d4ea435), X(0x7d540f06), X(0x7d59721b),
+ X(0x7d5ecd7b), X(0x7d64212a), X(0x7d696d2f), X(0x7d6eb190),
+ X(0x7d73ee53), X(0x7d79237e), X(0x7d7e5117), X(0x7d837723),
+ X(0x7d8895a9), X(0x7d8dacae), X(0x7d92bc3a), X(0x7d97c451),
+ X(0x7d9cc4f9), X(0x7da1be39), X(0x7da6b017), X(0x7dab9a99),
+ X(0x7db07dc4), X(0x7db5599e), X(0x7dba2e2f), X(0x7dbefb7b),
+ X(0x7dc3c189), X(0x7dc8805e), X(0x7dcd3802), X(0x7dd1e879),
+ X(0x7dd691ca), X(0x7ddb33fb), X(0x7ddfcf12), X(0x7de46315),
+ X(0x7de8f00a), X(0x7ded75f8), X(0x7df1f4e3), X(0x7df66cd3),
+ X(0x7dfaddcd), X(0x7dff47d7), X(0x7e03aaf8), X(0x7e080735),
+ X(0x7e0c5c95), X(0x7e10ab1e), X(0x7e14f2d5), X(0x7e1933c1),
+ X(0x7e1d6de8), X(0x7e21a150), X(0x7e25cdff), X(0x7e29f3fc),
+ X(0x7e2e134c), X(0x7e322bf5), X(0x7e363dfd), X(0x7e3a496b),
+ X(0x7e3e4e45), X(0x7e424c90), X(0x7e464454), X(0x7e4a3595),
+ X(0x7e4e205a), X(0x7e5204aa), X(0x7e55e289), X(0x7e59b9ff),
+ X(0x7e5d8b12), X(0x7e6155c7), X(0x7e651a24), X(0x7e68d831),
+ X(0x7e6c8ff2), X(0x7e70416e), X(0x7e73ecac), X(0x7e7791b0),
+ X(0x7e7b3082), X(0x7e7ec927), X(0x7e825ba6), X(0x7e85e804),
+ X(0x7e896e48), X(0x7e8cee77), X(0x7e906899), X(0x7e93dcb2),
+ X(0x7e974aca), X(0x7e9ab2e5), X(0x7e9e150b), X(0x7ea17141),
+ X(0x7ea4c78e), X(0x7ea817f7), X(0x7eab6283), X(0x7eaea737),
+ X(0x7eb1e61a), X(0x7eb51f33), X(0x7eb85285), X(0x7ebb8019),
+ X(0x7ebea7f4), X(0x7ec1ca1d), X(0x7ec4e698), X(0x7ec7fd6d),
+ X(0x7ecb0ea1), X(0x7ece1a3a), X(0x7ed1203f), X(0x7ed420b6),
+ X(0x7ed71ba4), X(0x7eda110f), X(0x7edd00ff), X(0x7edfeb78),
+ X(0x7ee2d081), X(0x7ee5b01f), X(0x7ee88a5a), X(0x7eeb5f36),
+ X(0x7eee2eba), X(0x7ef0f8ed), X(0x7ef3bdd3), X(0x7ef67d73),
+ X(0x7ef937d3), X(0x7efbecf9), X(0x7efe9ceb), X(0x7f0147ae),
+ X(0x7f03ed4a), X(0x7f068dc4), X(0x7f092922), X(0x7f0bbf69),
+ X(0x7f0e50a1), X(0x7f10dcce), X(0x7f1363f7), X(0x7f15e622),
+ X(0x7f186355), X(0x7f1adb95), X(0x7f1d4ee9), X(0x7f1fbd57),
+ X(0x7f2226e4), X(0x7f248b96), X(0x7f26eb74), X(0x7f294683),
+ X(0x7f2b9cc9), X(0x7f2dee4d), X(0x7f303b13), X(0x7f328322),
+ X(0x7f34c680), X(0x7f370533), X(0x7f393f40), X(0x7f3b74ad),
+ X(0x7f3da581), X(0x7f3fd1c1), X(0x7f41f972), X(0x7f441c9c),
+ X(0x7f463b43), X(0x7f48556d), X(0x7f4a6b21), X(0x7f4c7c64),
+ X(0x7f4e893c), X(0x7f5091ae), X(0x7f5295c1), X(0x7f54957a),
+ X(0x7f5690e0), X(0x7f5887f7), X(0x7f5a7ac5), X(0x7f5c6951),
+ X(0x7f5e53a0), X(0x7f6039b8), X(0x7f621b9e), X(0x7f63f958),
+ X(0x7f65d2ed), X(0x7f67a861), X(0x7f6979ba), X(0x7f6b46ff),
+ X(0x7f6d1034), X(0x7f6ed560), X(0x7f709687), X(0x7f7253b1),
+ X(0x7f740ce1), X(0x7f75c21f), X(0x7f777370), X(0x7f7920d8),
+ X(0x7f7aca5f), X(0x7f7c7008), X(0x7f7e11db), X(0x7f7fafdd),
+ X(0x7f814a13), X(0x7f82e082), X(0x7f847331), X(0x7f860224),
+ X(0x7f878d62), X(0x7f8914f0), X(0x7f8a98d4), X(0x7f8c1912),
+ X(0x7f8d95b0), X(0x7f8f0eb5), X(0x7f908425), X(0x7f91f605),
+ X(0x7f93645c), X(0x7f94cf2f), X(0x7f963683), X(0x7f979a5d),
+ X(0x7f98fac4), X(0x7f9a57bb), X(0x7f9bb14a), X(0x7f9d0775),
+ X(0x7f9e5a41), X(0x7f9fa9b4), X(0x7fa0f5d3), X(0x7fa23ea4),
+ X(0x7fa3842b), X(0x7fa4c66f), X(0x7fa60575), X(0x7fa74141),
+ X(0x7fa879d9), X(0x7fa9af42), X(0x7faae182), X(0x7fac109e),
+ X(0x7fad3c9a), X(0x7fae657d), X(0x7faf8b4c), X(0x7fb0ae0b),
+ X(0x7fb1cdc0), X(0x7fb2ea70), X(0x7fb40420), X(0x7fb51ad5),
+ X(0x7fb62e95), X(0x7fb73f64), X(0x7fb84d48), X(0x7fb95846),
+ X(0x7fba6062), X(0x7fbb65a2), X(0x7fbc680c), X(0x7fbd67a3),
+ X(0x7fbe646d), X(0x7fbf5e70), X(0x7fc055af), X(0x7fc14a31),
+ X(0x7fc23bf9), X(0x7fc32b0d), X(0x7fc41773), X(0x7fc5012e),
+ X(0x7fc5e844), X(0x7fc6ccba), X(0x7fc7ae94), X(0x7fc88dd8),
+ X(0x7fc96a8a), X(0x7fca44af), X(0x7fcb1c4c), X(0x7fcbf167),
+ X(0x7fccc403), X(0x7fcd9425), X(0x7fce61d3), X(0x7fcf2d11),
+ X(0x7fcff5e3), X(0x7fd0bc4f), X(0x7fd1805a), X(0x7fd24207),
+ X(0x7fd3015c), X(0x7fd3be5d), X(0x7fd47910), X(0x7fd53178),
+ X(0x7fd5e79b), X(0x7fd69b7c), X(0x7fd74d21), X(0x7fd7fc8e),
+ X(0x7fd8a9c8), X(0x7fd954d4), X(0x7fd9fdb5), X(0x7fdaa471),
+ X(0x7fdb490b), X(0x7fdbeb89), X(0x7fdc8bef), X(0x7fdd2a42),
+ X(0x7fddc685), X(0x7fde60be), X(0x7fdef8f0), X(0x7fdf8f20),
+ X(0x7fe02353), X(0x7fe0b58d), X(0x7fe145d3), X(0x7fe1d428),
+ X(0x7fe26091), X(0x7fe2eb12), X(0x7fe373b0), X(0x7fe3fa6f),
+ X(0x7fe47f53), X(0x7fe50260), X(0x7fe5839b), X(0x7fe60308),
+ X(0x7fe680ab), X(0x7fe6fc88), X(0x7fe776a4), X(0x7fe7ef02),
+ X(0x7fe865a7), X(0x7fe8da97), X(0x7fe94dd6), X(0x7fe9bf68),
+ X(0x7fea2f51), X(0x7fea9d95), X(0x7feb0a39), X(0x7feb7540),
+ X(0x7febdeae), X(0x7fec4687), X(0x7fecaccf), X(0x7fed118b),
+ X(0x7fed74be), X(0x7fedd66c), X(0x7fee3698), X(0x7fee9548),
+ X(0x7feef27e), X(0x7fef4e3f), X(0x7fefa88e), X(0x7ff0016f),
+ X(0x7ff058e7), X(0x7ff0aef8), X(0x7ff103a6), X(0x7ff156f6),
+ X(0x7ff1a8eb), X(0x7ff1f988), X(0x7ff248d2), X(0x7ff296cc),
+ X(0x7ff2e37a), X(0x7ff32edf), X(0x7ff378ff), X(0x7ff3c1de),
+ X(0x7ff4097e), X(0x7ff44fe5), X(0x7ff49515), X(0x7ff4d911),
+ X(0x7ff51bde), X(0x7ff55d7f), X(0x7ff59df7), X(0x7ff5dd4a),
+ X(0x7ff61b7b), X(0x7ff6588d), X(0x7ff69485), X(0x7ff6cf65),
+ X(0x7ff70930), X(0x7ff741eb), X(0x7ff77998), X(0x7ff7b03b),
+ X(0x7ff7e5d7), X(0x7ff81a6f), X(0x7ff84e06), X(0x7ff880a1),
+ X(0x7ff8b241), X(0x7ff8e2ea), X(0x7ff912a0), X(0x7ff94165),
+ X(0x7ff96f3d), X(0x7ff99c2b), X(0x7ff9c831), X(0x7ff9f354),
+ X(0x7ffa1d95), X(0x7ffa46f9), X(0x7ffa6f81), X(0x7ffa9731),
+ X(0x7ffabe0d), X(0x7ffae416), X(0x7ffb0951), X(0x7ffb2dbf),
+ X(0x7ffb5164), X(0x7ffb7442), X(0x7ffb965d), X(0x7ffbb7b8),
+ X(0x7ffbd854), X(0x7ffbf836), X(0x7ffc175f), X(0x7ffc35d3),
+ X(0x7ffc5394), X(0x7ffc70a5), X(0x7ffc8d09), X(0x7ffca8c2),
+ X(0x7ffcc3d4), X(0x7ffcde3f), X(0x7ffcf809), X(0x7ffd1132),
+ X(0x7ffd29be), X(0x7ffd41ae), X(0x7ffd5907), X(0x7ffd6fc9),
+ X(0x7ffd85f9), X(0x7ffd9b97), X(0x7ffdb0a7), X(0x7ffdc52b),
+ X(0x7ffdd926), X(0x7ffdec99), X(0x7ffdff88), X(0x7ffe11f4),
+ X(0x7ffe23e0), X(0x7ffe354f), X(0x7ffe4642), X(0x7ffe56bc),
+ X(0x7ffe66bf), X(0x7ffe764e), X(0x7ffe856a), X(0x7ffe9416),
+ X(0x7ffea254), X(0x7ffeb026), X(0x7ffebd8e), X(0x7ffeca8f),
+ X(0x7ffed72a), X(0x7ffee362), X(0x7ffeef38), X(0x7ffefaaf),
+ X(0x7fff05c9), X(0x7fff1087), X(0x7fff1aec), X(0x7fff24f9),
+ X(0x7fff2eb1), X(0x7fff3816), X(0x7fff4128), X(0x7fff49eb),
+ X(0x7fff5260), X(0x7fff5a88), X(0x7fff6266), X(0x7fff69fc),
+ X(0x7fff714b), X(0x7fff7854), X(0x7fff7f1a), X(0x7fff859f),
+ X(0x7fff8be3), X(0x7fff91ea), X(0x7fff97b3), X(0x7fff9d41),
+ X(0x7fffa296), X(0x7fffa7b3), X(0x7fffac99), X(0x7fffb14b),
+ X(0x7fffb5c9), X(0x7fffba15), X(0x7fffbe31), X(0x7fffc21d),
+ X(0x7fffc5dc), X(0x7fffc96f), X(0x7fffccd8), X(0x7fffd016),
+ X(0x7fffd32d), X(0x7fffd61c), X(0x7fffd8e7), X(0x7fffdb8d),
+ X(0x7fffde0f), X(0x7fffe071), X(0x7fffe2b1), X(0x7fffe4d2),
+ X(0x7fffe6d5), X(0x7fffe8bb), X(0x7fffea85), X(0x7fffec34),
+ X(0x7fffedc9), X(0x7fffef45), X(0x7ffff0aa), X(0x7ffff1f7),
+ X(0x7ffff330), X(0x7ffff453), X(0x7ffff562), X(0x7ffff65f),
+ X(0x7ffff749), X(0x7ffff823), X(0x7ffff8ec), X(0x7ffff9a6),
+ X(0x7ffffa51), X(0x7ffffaee), X(0x7ffffb7e), X(0x7ffffc02),
+ X(0x7ffffc7a), X(0x7ffffce7), X(0x7ffffd4a), X(0x7ffffda3),
+ X(0x7ffffdf4), X(0x7ffffe3c), X(0x7ffffe7c), X(0x7ffffeb6),
+ X(0x7ffffee8), X(0x7fffff15), X(0x7fffff3c), X(0x7fffff5e),
+ X(0x7fffff7b), X(0x7fffff95), X(0x7fffffaa), X(0x7fffffbc),
+ X(0x7fffffcb), X(0x7fffffd7), X(0x7fffffe2), X(0x7fffffea),
+ X(0x7ffffff0), X(0x7ffffff5), X(0x7ffffff9), X(0x7ffffffb),
+ X(0x7ffffffd), X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff),
+ X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
+};
+
+static LOOKUP_T vwin8192[4096] = {
+ X(0x0000007c), X(0x0000045c), X(0x00000c1d), X(0x000017bd),
+ X(0x0000273e), X(0x00003a9f), X(0x000051e0), X(0x00006d02),
+ X(0x00008c03), X(0x0000aee5), X(0x0000d5a7), X(0x00010049),
+ X(0x00012ecb), X(0x0001612d), X(0x00019770), X(0x0001d193),
+ X(0x00020f96), X(0x00025178), X(0x0002973c), X(0x0002e0df),
+ X(0x00032e62), X(0x00037fc5), X(0x0003d509), X(0x00042e2c),
+ X(0x00048b30), X(0x0004ec13), X(0x000550d7), X(0x0005b97a),
+ X(0x000625fe), X(0x00069661), X(0x00070aa4), X(0x000782c8),
+ X(0x0007fecb), X(0x00087eae), X(0x00090271), X(0x00098a14),
+ X(0x000a1597), X(0x000aa4f9), X(0x000b383b), X(0x000bcf5d),
+ X(0x000c6a5f), X(0x000d0941), X(0x000dac02), X(0x000e52a3),
+ X(0x000efd23), X(0x000fab84), X(0x00105dc3), X(0x001113e3),
+ X(0x0011cde2), X(0x00128bc0), X(0x00134d7e), X(0x0014131b),
+ X(0x0014dc98), X(0x0015a9f4), X(0x00167b30), X(0x0017504a),
+ X(0x00182945), X(0x0019061e), X(0x0019e6d7), X(0x001acb6f),
+ X(0x001bb3e6), X(0x001ca03c), X(0x001d9071), X(0x001e8485),
+ X(0x001f7c79), X(0x0020784b), X(0x002177fc), X(0x00227b8c),
+ X(0x002382fb), X(0x00248e49), X(0x00259d76), X(0x0026b081),
+ X(0x0027c76b), X(0x0028e234), X(0x002a00dc), X(0x002b2361),
+ X(0x002c49c6), X(0x002d7409), X(0x002ea22a), X(0x002fd42a),
+ X(0x00310a08), X(0x003243c5), X(0x00338160), X(0x0034c2d9),
+ X(0x00360830), X(0x00375165), X(0x00389e78), X(0x0039ef6a),
+ X(0x003b4439), X(0x003c9ce6), X(0x003df971), X(0x003f59da),
+ X(0x0040be20), X(0x00422645), X(0x00439247), X(0x00450226),
+ X(0x004675e3), X(0x0047ed7e), X(0x004968f5), X(0x004ae84b),
+ X(0x004c6b7d), X(0x004df28d), X(0x004f7d7a), X(0x00510c44),
+ X(0x00529eeb), X(0x00543570), X(0x0055cfd1), X(0x00576e0f),
+ X(0x00591029), X(0x005ab621), X(0x005c5ff5), X(0x005e0da6),
+ X(0x005fbf33), X(0x0061749d), X(0x00632de4), X(0x0064eb06),
+ X(0x0066ac05), X(0x006870e0), X(0x006a3998), X(0x006c062b),
+ X(0x006dd69b), X(0x006faae6), X(0x0071830d), X(0x00735f10),
+ X(0x00753eef), X(0x007722a9), X(0x00790a3f), X(0x007af5b1),
+ X(0x007ce4fe), X(0x007ed826), X(0x0080cf29), X(0x0082ca08),
+ X(0x0084c8c2), X(0x0086cb57), X(0x0088d1c7), X(0x008adc11),
+ X(0x008cea37), X(0x008efc37), X(0x00911212), X(0x00932bc7),
+ X(0x00954957), X(0x00976ac2), X(0x00999006), X(0x009bb925),
+ X(0x009de61e), X(0x00a016f1), X(0x00a24b9e), X(0x00a48425),
+ X(0x00a6c086), X(0x00a900c0), X(0x00ab44d4), X(0x00ad8cc2),
+ X(0x00afd889), X(0x00b22829), X(0x00b47ba2), X(0x00b6d2f5),
+ X(0x00b92e21), X(0x00bb8d26), X(0x00bdf004), X(0x00c056ba),
+ X(0x00c2c149), X(0x00c52fb1), X(0x00c7a1f1), X(0x00ca180a),
+ X(0x00cc91fb), X(0x00cf0fc5), X(0x00d19166), X(0x00d416df),
+ X(0x00d6a031), X(0x00d92d5a), X(0x00dbbe5b), X(0x00de5333),
+ X(0x00e0ebe3), X(0x00e3886b), X(0x00e628c9), X(0x00e8ccff),
+ X(0x00eb750c), X(0x00ee20f0), X(0x00f0d0ab), X(0x00f3843d),
+ X(0x00f63ba5), X(0x00f8f6e4), X(0x00fbb5fa), X(0x00fe78e5),
+ X(0x01013fa7), X(0x01040a3f), X(0x0106d8ae), X(0x0109aaf2),
+ X(0x010c810c), X(0x010f5afb), X(0x011238c0), X(0x01151a5b),
+ X(0x0117ffcb), X(0x011ae910), X(0x011dd62a), X(0x0120c719),
+ X(0x0123bbdd), X(0x0126b476), X(0x0129b0e4), X(0x012cb126),
+ X(0x012fb53c), X(0x0132bd27), X(0x0135c8e6), X(0x0138d879),
+ X(0x013bebdf), X(0x013f031a), X(0x01421e28), X(0x01453d0a),
+ X(0x01485fbf), X(0x014b8648), X(0x014eb0a4), X(0x0151ded2),
+ X(0x015510d4), X(0x015846a8), X(0x015b8050), X(0x015ebdc9),
+ X(0x0161ff15), X(0x01654434), X(0x01688d24), X(0x016bd9e6),
+ X(0x016f2a7b), X(0x01727ee1), X(0x0175d718), X(0x01793321),
+ X(0x017c92fc), X(0x017ff6a7), X(0x01835e24), X(0x0186c972),
+ X(0x018a3890), X(0x018dab7f), X(0x0191223f), X(0x01949ccf),
+ X(0x01981b2f), X(0x019b9d5f), X(0x019f235f), X(0x01a2ad2f),
+ X(0x01a63acf), X(0x01a9cc3e), X(0x01ad617c), X(0x01b0fa8a),
+ X(0x01b49767), X(0x01b83813), X(0x01bbdc8d), X(0x01bf84d6),
+ X(0x01c330ee), X(0x01c6e0d4), X(0x01ca9488), X(0x01ce4c0b),
+ X(0x01d2075b), X(0x01d5c679), X(0x01d98964), X(0x01dd501d),
+ X(0x01e11aa3), X(0x01e4e8f6), X(0x01e8bb17), X(0x01ec9104),
+ X(0x01f06abd), X(0x01f44844), X(0x01f82996), X(0x01fc0eb5),
+ X(0x01fff7a0), X(0x0203e456), X(0x0207d4d9), X(0x020bc926),
+ X(0x020fc140), X(0x0213bd24), X(0x0217bcd4), X(0x021bc04e),
+ X(0x021fc793), X(0x0223d2a3), X(0x0227e17d), X(0x022bf421),
+ X(0x02300a90), X(0x023424c8), X(0x023842ca), X(0x023c6495),
+ X(0x02408a2a), X(0x0244b389), X(0x0248e0b0), X(0x024d11a0),
+ X(0x02514659), X(0x02557eda), X(0x0259bb24), X(0x025dfb35),
+ X(0x02623f0f), X(0x026686b1), X(0x026ad21a), X(0x026f214b),
+ X(0x02737443), X(0x0277cb02), X(0x027c2588), X(0x028083d5),
+ X(0x0284e5e9), X(0x02894bc2), X(0x028db562), X(0x029222c8),
+ X(0x029693f4), X(0x029b08e6), X(0x029f819d), X(0x02a3fe19),
+ X(0x02a87e5b), X(0x02ad0261), X(0x02b18a2c), X(0x02b615bb),
+ X(0x02baa50f), X(0x02bf3827), X(0x02c3cf03), X(0x02c869a3),
+ X(0x02cd0807), X(0x02d1aa2d), X(0x02d65017), X(0x02daf9c4),
+ X(0x02dfa734), X(0x02e45866), X(0x02e90d5b), X(0x02edc612),
+ X(0x02f2828b), X(0x02f742c6), X(0x02fc06c3), X(0x0300ce80),
+ X(0x030599ff), X(0x030a6940), X(0x030f3c40), X(0x03141302),
+ X(0x0318ed84), X(0x031dcbc6), X(0x0322adc8), X(0x0327938a),
+ X(0x032c7d0c), X(0x03316a4c), X(0x03365b4d), X(0x033b500c),
+ X(0x03404889), X(0x034544c6), X(0x034a44c0), X(0x034f4879),
+ X(0x03544ff0), X(0x03595b24), X(0x035e6a16), X(0x03637cc5),
+ X(0x03689331), X(0x036dad5a), X(0x0372cb40), X(0x0377ece2),
+ X(0x037d1240), X(0x03823b5a), X(0x03876830), X(0x038c98c1),
+ X(0x0391cd0e), X(0x03970516), X(0x039c40d8), X(0x03a18055),
+ X(0x03a6c38d), X(0x03ac0a7f), X(0x03b1552b), X(0x03b6a390),
+ X(0x03bbf5af), X(0x03c14b88), X(0x03c6a519), X(0x03cc0263),
+ X(0x03d16366), X(0x03d6c821), X(0x03dc3094), X(0x03e19cc0),
+ X(0x03e70ca2), X(0x03ec803d), X(0x03f1f78e), X(0x03f77296),
+ X(0x03fcf155), X(0x040273cb), X(0x0407f9f7), X(0x040d83d9),
+ X(0x04131170), X(0x0418a2bd), X(0x041e37c0), X(0x0423d077),
+ X(0x04296ce4), X(0x042f0d04), X(0x0434b0da), X(0x043a5863),
+ X(0x044003a0), X(0x0445b290), X(0x044b6534), X(0x04511b8b),
+ X(0x0456d595), X(0x045c9352), X(0x046254c1), X(0x046819e1),
+ X(0x046de2b4), X(0x0473af39), X(0x04797f6e), X(0x047f5355),
+ X(0x04852aec), X(0x048b0635), X(0x0490e52d), X(0x0496c7d6),
+ X(0x049cae2e), X(0x04a29836), X(0x04a885ed), X(0x04ae7753),
+ X(0x04b46c68), X(0x04ba652b), X(0x04c0619d), X(0x04c661bc),
+ X(0x04cc658a), X(0x04d26d04), X(0x04d8782c), X(0x04de8701),
+ X(0x04e49983), X(0x04eaafb0), X(0x04f0c98a), X(0x04f6e710),
+ X(0x04fd0842), X(0x05032d1e), X(0x050955a6), X(0x050f81d8),
+ X(0x0515b1b5), X(0x051be53d), X(0x05221c6e), X(0x05285748),
+ X(0x052e95cd), X(0x0534d7fa), X(0x053b1dd0), X(0x0541674e),
+ X(0x0547b475), X(0x054e0544), X(0x055459bb), X(0x055ab1d9),
+ X(0x05610d9e), X(0x05676d0a), X(0x056dd01c), X(0x057436d5),
+ X(0x057aa134), X(0x05810f38), X(0x058780e2), X(0x058df631),
+ X(0x05946f25), X(0x059aebbe), X(0x05a16bfa), X(0x05a7efdb),
+ X(0x05ae775f), X(0x05b50287), X(0x05bb9152), X(0x05c223c0),
+ X(0x05c8b9d0), X(0x05cf5382), X(0x05d5f0d6), X(0x05dc91cc),
+ X(0x05e33663), X(0x05e9de9c), X(0x05f08a75), X(0x05f739ee),
+ X(0x05fded07), X(0x0604a3c0), X(0x060b5e19), X(0x06121c11),
+ X(0x0618dda8), X(0x061fa2dd), X(0x06266bb1), X(0x062d3822),
+ X(0x06340831), X(0x063adbde), X(0x0641b328), X(0x06488e0e),
+ X(0x064f6c91), X(0x06564eaf), X(0x065d346a), X(0x06641dc0),
+ X(0x066b0ab1), X(0x0671fb3d), X(0x0678ef64), X(0x067fe724),
+ X(0x0686e27f), X(0x068de173), X(0x0694e400), X(0x069bea27),
+ X(0x06a2f3e6), X(0x06aa013d), X(0x06b1122c), X(0x06b826b3),
+ X(0x06bf3ed1), X(0x06c65a86), X(0x06cd79d1), X(0x06d49cb3),
+ X(0x06dbc32b), X(0x06e2ed38), X(0x06ea1adb), X(0x06f14c13),
+ X(0x06f880df), X(0x06ffb940), X(0x0706f535), X(0x070e34bd),
+ X(0x071577d9), X(0x071cbe88), X(0x072408c9), X(0x072b569d),
+ X(0x0732a802), X(0x0739fcf9), X(0x07415582), X(0x0748b19b),
+ X(0x07501145), X(0x0757747f), X(0x075edb49), X(0x076645a3),
+ X(0x076db38c), X(0x07752503), X(0x077c9a09), X(0x0784129e),
+ X(0x078b8ec0), X(0x07930e70), X(0x079a91ac), X(0x07a21876),
+ X(0x07a9a2cc), X(0x07b130ad), X(0x07b8c21b), X(0x07c05714),
+ X(0x07c7ef98), X(0x07cf8ba6), X(0x07d72b3f), X(0x07dece62),
+ X(0x07e6750e), X(0x07ee1f43), X(0x07f5cd01), X(0x07fd7e48),
+ X(0x08053316), X(0x080ceb6d), X(0x0814a74a), X(0x081c66af),
+ X(0x0824299a), X(0x082bf00c), X(0x0833ba03), X(0x083b8780),
+ X(0x08435882), X(0x084b2d09), X(0x08530514), X(0x085ae0a3),
+ X(0x0862bfb6), X(0x086aa24c), X(0x08728865), X(0x087a7201),
+ X(0x08825f1e), X(0x088a4fbe), X(0x089243de), X(0x089a3b80),
+ X(0x08a236a2), X(0x08aa3545), X(0x08b23767), X(0x08ba3d09),
+ X(0x08c2462a), X(0x08ca52c9), X(0x08d262e7), X(0x08da7682),
+ X(0x08e28d9c), X(0x08eaa832), X(0x08f2c645), X(0x08fae7d4),
+ X(0x09030cdf), X(0x090b3566), X(0x09136168), X(0x091b90e5),
+ X(0x0923c3dc), X(0x092bfa4d), X(0x09343437), X(0x093c719b),
+ X(0x0944b277), X(0x094cf6cc), X(0x09553e99), X(0x095d89dd),
+ X(0x0965d899), X(0x096e2acb), X(0x09768073), X(0x097ed991),
+ X(0x09873625), X(0x098f962e), X(0x0997f9ac), X(0x09a0609e),
+ X(0x09a8cb04), X(0x09b138dd), X(0x09b9aa29), X(0x09c21ee8),
+ X(0x09ca9719), X(0x09d312bc), X(0x09db91d0), X(0x09e41456),
+ X(0x09ec9a4b), X(0x09f523b1), X(0x09fdb087), X(0x0a0640cc),
+ X(0x0a0ed47f), X(0x0a176ba2), X(0x0a200632), X(0x0a28a42f),
+ X(0x0a31459a), X(0x0a39ea72), X(0x0a4292b5), X(0x0a4b3e65),
+ X(0x0a53ed80), X(0x0a5ca006), X(0x0a6555f7), X(0x0a6e0f51),
+ X(0x0a76cc16), X(0x0a7f8c44), X(0x0a884fda), X(0x0a9116d9),
+ X(0x0a99e140), X(0x0aa2af0e), X(0x0aab8043), X(0x0ab454df),
+ X(0x0abd2ce1), X(0x0ac60849), X(0x0acee716), X(0x0ad7c948),
+ X(0x0ae0aedf), X(0x0ae997d9), X(0x0af28437), X(0x0afb73f7),
+ X(0x0b04671b), X(0x0b0d5da0), X(0x0b165788), X(0x0b1f54d0),
+ X(0x0b285579), X(0x0b315983), X(0x0b3a60ec), X(0x0b436bb5),
+ X(0x0b4c79dd), X(0x0b558b63), X(0x0b5ea048), X(0x0b67b88a),
+ X(0x0b70d429), X(0x0b79f324), X(0x0b83157c), X(0x0b8c3b30),
+ X(0x0b95643f), X(0x0b9e90a8), X(0x0ba7c06c), X(0x0bb0f38a),
+ X(0x0bba2a01), X(0x0bc363d1), X(0x0bcca0f9), X(0x0bd5e17a),
+ X(0x0bdf2552), X(0x0be86c81), X(0x0bf1b706), X(0x0bfb04e2),
+ X(0x0c045613), X(0x0c0daa99), X(0x0c170274), X(0x0c205da3),
+ X(0x0c29bc25), X(0x0c331dfb), X(0x0c3c8323), X(0x0c45eb9e),
+ X(0x0c4f576a), X(0x0c58c688), X(0x0c6238f6), X(0x0c6baeb5),
+ X(0x0c7527c3), X(0x0c7ea421), X(0x0c8823cd), X(0x0c91a6c8),
+ X(0x0c9b2d10), X(0x0ca4b6a6), X(0x0cae4389), X(0x0cb7d3b8),
+ X(0x0cc16732), X(0x0ccafdf8), X(0x0cd49809), X(0x0cde3564),
+ X(0x0ce7d609), X(0x0cf179f7), X(0x0cfb212e), X(0x0d04cbad),
+ X(0x0d0e7974), X(0x0d182a83), X(0x0d21ded8), X(0x0d2b9673),
+ X(0x0d355154), X(0x0d3f0f7b), X(0x0d48d0e6), X(0x0d529595),
+ X(0x0d5c5d88), X(0x0d6628be), X(0x0d6ff737), X(0x0d79c8f2),
+ X(0x0d839dee), X(0x0d8d762c), X(0x0d9751aa), X(0x0da13068),
+ X(0x0dab1266), X(0x0db4f7a3), X(0x0dbee01e), X(0x0dc8cbd8),
+ X(0x0dd2bace), X(0x0ddcad02), X(0x0de6a272), X(0x0df09b1e),
+ X(0x0dfa9705), X(0x0e049627), X(0x0e0e9883), X(0x0e189e19),
+ X(0x0e22a6e8), X(0x0e2cb2f0), X(0x0e36c230), X(0x0e40d4a8),
+ X(0x0e4aea56), X(0x0e55033b), X(0x0e5f1f56), X(0x0e693ea7),
+ X(0x0e73612c), X(0x0e7d86e5), X(0x0e87afd3), X(0x0e91dbf3),
+ X(0x0e9c0b47), X(0x0ea63dcc), X(0x0eb07383), X(0x0ebaac6b),
+ X(0x0ec4e883), X(0x0ecf27cc), X(0x0ed96a44), X(0x0ee3afea),
+ X(0x0eedf8bf), X(0x0ef844c2), X(0x0f0293f2), X(0x0f0ce64e),
+ X(0x0f173bd6), X(0x0f21948a), X(0x0f2bf069), X(0x0f364f72),
+ X(0x0f40b1a5), X(0x0f4b1701), X(0x0f557f86), X(0x0f5feb32),
+ X(0x0f6a5a07), X(0x0f74cc02), X(0x0f7f4124), X(0x0f89b96b),
+ X(0x0f9434d8), X(0x0f9eb369), X(0x0fa9351e), X(0x0fb3b9f7),
+ X(0x0fbe41f3), X(0x0fc8cd11), X(0x0fd35b51), X(0x0fddecb2),
+ X(0x0fe88134), X(0x0ff318d6), X(0x0ffdb397), X(0x10085177),
+ X(0x1012f275), X(0x101d9691), X(0x10283dca), X(0x1032e81f),
+ X(0x103d9591), X(0x1048461e), X(0x1052f9c5), X(0x105db087),
+ X(0x10686a62), X(0x10732756), X(0x107de763), X(0x1088aa87),
+ X(0x109370c2), X(0x109e3a14), X(0x10a9067c), X(0x10b3d5f9),
+ X(0x10bea88b), X(0x10c97e31), X(0x10d456eb), X(0x10df32b8),
+ X(0x10ea1197), X(0x10f4f387), X(0x10ffd889), X(0x110ac09b),
+ X(0x1115abbe), X(0x112099ef), X(0x112b8b2f), X(0x11367f7d),
+ X(0x114176d9), X(0x114c7141), X(0x11576eb6), X(0x11626f36),
+ X(0x116d72c1), X(0x11787957), X(0x118382f6), X(0x118e8f9e),
+ X(0x11999f4f), X(0x11a4b208), X(0x11afc7c7), X(0x11bae08e),
+ X(0x11c5fc5a), X(0x11d11b2c), X(0x11dc3d02), X(0x11e761dd),
+ X(0x11f289ba), X(0x11fdb49b), X(0x1208e27e), X(0x12141362),
+ X(0x121f4748), X(0x122a7e2d), X(0x1235b812), X(0x1240f4f6),
+ X(0x124c34d9), X(0x125777b9), X(0x1262bd96), X(0x126e0670),
+ X(0x12795245), X(0x1284a115), X(0x128ff2e0), X(0x129b47a5),
+ X(0x12a69f63), X(0x12b1fa19), X(0x12bd57c7), X(0x12c8b86c),
+ X(0x12d41c08), X(0x12df829a), X(0x12eaec21), X(0x12f6589d),
+ X(0x1301c80c), X(0x130d3a6f), X(0x1318afc4), X(0x1324280b),
+ X(0x132fa344), X(0x133b216d), X(0x1346a286), X(0x1352268e),
+ X(0x135dad85), X(0x1369376a), X(0x1374c43c), X(0x138053fb),
+ X(0x138be6a5), X(0x13977c3b), X(0x13a314bc), X(0x13aeb026),
+ X(0x13ba4e79), X(0x13c5efb5), X(0x13d193d9), X(0x13dd3ae4),
+ X(0x13e8e4d6), X(0x13f491ad), X(0x1400416a), X(0x140bf40b),
+ X(0x1417a98f), X(0x142361f7), X(0x142f1d41), X(0x143adb6d),
+ X(0x14469c7a), X(0x14526067), X(0x145e2734), X(0x1469f0df),
+ X(0x1475bd69), X(0x14818cd0), X(0x148d5f15), X(0x14993435),
+ X(0x14a50c31), X(0x14b0e708), X(0x14bcc4b8), X(0x14c8a542),
+ X(0x14d488a5), X(0x14e06edf), X(0x14ec57f1), X(0x14f843d9),
+ X(0x15043297), X(0x1510242b), X(0x151c1892), X(0x15280fcd),
+ X(0x153409dc), X(0x154006bc), X(0x154c066e), X(0x155808f1),
+ X(0x15640e44), X(0x15701666), X(0x157c2157), X(0x15882f16),
+ X(0x15943fa2), X(0x15a052fb), X(0x15ac691f), X(0x15b8820f),
+ X(0x15c49dc8), X(0x15d0bc4c), X(0x15dcdd98), X(0x15e901ad),
+ X(0x15f52888), X(0x1601522b), X(0x160d7e93), X(0x1619adc1),
+ X(0x1625dfb3), X(0x16321469), X(0x163e4be2), X(0x164a861d),
+ X(0x1656c31a), X(0x166302d8), X(0x166f4555), X(0x167b8a92),
+ X(0x1687d28e), X(0x16941d47), X(0x16a06abe), X(0x16acbaf0),
+ X(0x16b90ddf), X(0x16c56388), X(0x16d1bbeb), X(0x16de1708),
+ X(0x16ea74dd), X(0x16f6d56a), X(0x170338ae), X(0x170f9ea8),
+ X(0x171c0758), X(0x172872bd), X(0x1734e0d6), X(0x174151a2),
+ X(0x174dc520), X(0x175a3b51), X(0x1766b432), X(0x17732fc4),
+ X(0x177fae05), X(0x178c2ef4), X(0x1798b292), X(0x17a538dd),
+ X(0x17b1c1d4), X(0x17be4d77), X(0x17cadbc5), X(0x17d76cbc),
+ X(0x17e4005e), X(0x17f096a7), X(0x17fd2f98), X(0x1809cb31),
+ X(0x1816696f), X(0x18230a53), X(0x182faddc), X(0x183c5408),
+ X(0x1848fcd8), X(0x1855a849), X(0x1862565d), X(0x186f0711),
+ X(0x187bba64), X(0x18887057), X(0x189528e9), X(0x18a1e418),
+ X(0x18aea1e3), X(0x18bb624b), X(0x18c8254e), X(0x18d4eaeb),
+ X(0x18e1b321), X(0x18ee7df1), X(0x18fb4b58), X(0x19081b57),
+ X(0x1914edec), X(0x1921c317), X(0x192e9ad6), X(0x193b7529),
+ X(0x19485210), X(0x19553189), X(0x19621393), X(0x196ef82e),
+ X(0x197bdf59), X(0x1988c913), X(0x1995b55c), X(0x19a2a432),
+ X(0x19af9595), X(0x19bc8983), X(0x19c97ffd), X(0x19d67900),
+ X(0x19e3748e), X(0x19f072a3), X(0x19fd7341), X(0x1a0a7665),
+ X(0x1a177c10), X(0x1a248440), X(0x1a318ef4), X(0x1a3e9c2c),
+ X(0x1a4babe7), X(0x1a58be24), X(0x1a65d2e2), X(0x1a72ea20),
+ X(0x1a8003de), X(0x1a8d201a), X(0x1a9a3ed5), X(0x1aa7600c),
+ X(0x1ab483bf), X(0x1ac1a9ee), X(0x1aced297), X(0x1adbfdba),
+ X(0x1ae92b56), X(0x1af65b69), X(0x1b038df4), X(0x1b10c2f5),
+ X(0x1b1dfa6b), X(0x1b2b3456), X(0x1b3870b5), X(0x1b45af87),
+ X(0x1b52f0ca), X(0x1b60347f), X(0x1b6d7aa4), X(0x1b7ac339),
+ X(0x1b880e3c), X(0x1b955bad), X(0x1ba2ab8b), X(0x1baffdd5),
+ X(0x1bbd528a), X(0x1bcaa9a9), X(0x1bd80332), X(0x1be55f24),
+ X(0x1bf2bd7d), X(0x1c001e3d), X(0x1c0d8164), X(0x1c1ae6ef),
+ X(0x1c284edf), X(0x1c35b932), X(0x1c4325e7), X(0x1c5094fe),
+ X(0x1c5e0677), X(0x1c6b7a4f), X(0x1c78f086), X(0x1c86691b),
+ X(0x1c93e40d), X(0x1ca1615c), X(0x1caee107), X(0x1cbc630c),
+ X(0x1cc9e76b), X(0x1cd76e23), X(0x1ce4f733), X(0x1cf2829a),
+ X(0x1d001057), X(0x1d0da06a), X(0x1d1b32d1), X(0x1d28c78c),
+ X(0x1d365e9a), X(0x1d43f7f9), X(0x1d5193a9), X(0x1d5f31aa),
+ X(0x1d6cd1f9), X(0x1d7a7497), X(0x1d881982), X(0x1d95c0ba),
+ X(0x1da36a3d), X(0x1db1160a), X(0x1dbec422), X(0x1dcc7482),
+ X(0x1dda272b), X(0x1de7dc1a), X(0x1df59350), X(0x1e034ccb),
+ X(0x1e11088a), X(0x1e1ec68c), X(0x1e2c86d1), X(0x1e3a4958),
+ X(0x1e480e20), X(0x1e55d527), X(0x1e639e6d), X(0x1e7169f1),
+ X(0x1e7f37b2), X(0x1e8d07b0), X(0x1e9ad9e8), X(0x1ea8ae5b),
+ X(0x1eb68507), X(0x1ec45dec), X(0x1ed23908), X(0x1ee0165b),
+ X(0x1eedf5e4), X(0x1efbd7a1), X(0x1f09bb92), X(0x1f17a1b6),
+ X(0x1f258a0d), X(0x1f337494), X(0x1f41614b), X(0x1f4f5032),
+ X(0x1f5d4147), X(0x1f6b3489), X(0x1f7929f7), X(0x1f872192),
+ X(0x1f951b56), X(0x1fa31744), X(0x1fb1155b), X(0x1fbf159a),
+ X(0x1fcd17ff), X(0x1fdb1c8b), X(0x1fe9233b), X(0x1ff72c0f),
+ X(0x20053706), X(0x20134420), X(0x2021535a), X(0x202f64b4),
+ X(0x203d782e), X(0x204b8dc6), X(0x2059a57c), X(0x2067bf4e),
+ X(0x2075db3b), X(0x2083f943), X(0x20921964), X(0x20a03b9e),
+ X(0x20ae5fef), X(0x20bc8657), X(0x20caaed5), X(0x20d8d967),
+ X(0x20e7060e), X(0x20f534c7), X(0x21036592), X(0x2111986e),
+ X(0x211fcd59), X(0x212e0454), X(0x213c3d5d), X(0x214a7873),
+ X(0x2158b594), X(0x2166f4c1), X(0x217535f8), X(0x21837938),
+ X(0x2191be81), X(0x21a005d0), X(0x21ae4f26), X(0x21bc9a81),
+ X(0x21cae7e0), X(0x21d93743), X(0x21e788a8), X(0x21f5dc0e),
+ X(0x22043174), X(0x221288da), X(0x2220e23e), X(0x222f3da0),
+ X(0x223d9afe), X(0x224bfa58), X(0x225a5bac), X(0x2268bef9),
+ X(0x2277243f), X(0x22858b7d), X(0x2293f4b0), X(0x22a25fda),
+ X(0x22b0ccf8), X(0x22bf3c09), X(0x22cdad0d), X(0x22dc2002),
+ X(0x22ea94e8), X(0x22f90bbe), X(0x23078482), X(0x2315ff33),
+ X(0x23247bd1), X(0x2332fa5b), X(0x23417acf), X(0x234ffd2c),
+ X(0x235e8173), X(0x236d07a0), X(0x237b8fb4), X(0x238a19ae),
+ X(0x2398a58c), X(0x23a7334d), X(0x23b5c2f1), X(0x23c45477),
+ X(0x23d2e7dd), X(0x23e17d22), X(0x23f01446), X(0x23fead47),
+ X(0x240d4825), X(0x241be4dd), X(0x242a8371), X(0x243923dd),
+ X(0x2447c622), X(0x24566a3e), X(0x24651031), X(0x2473b7f8),
+ X(0x24826194), X(0x24910d03), X(0x249fba44), X(0x24ae6957),
+ X(0x24bd1a39), X(0x24cbccea), X(0x24da816a), X(0x24e937b7),
+ X(0x24f7efcf), X(0x2506a9b3), X(0x25156560), X(0x252422d6),
+ X(0x2532e215), X(0x2541a31a), X(0x255065e4), X(0x255f2a74),
+ X(0x256df0c7), X(0x257cb8dd), X(0x258b82b4), X(0x259a4e4c),
+ X(0x25a91ba4), X(0x25b7eaba), X(0x25c6bb8e), X(0x25d58e1e),
+ X(0x25e46269), X(0x25f3386e), X(0x2602102d), X(0x2610e9a4),
+ X(0x261fc4d3), X(0x262ea1b7), X(0x263d8050), X(0x264c609e),
+ X(0x265b429e), X(0x266a2650), X(0x26790bb3), X(0x2687f2c6),
+ X(0x2696db88), X(0x26a5c5f7), X(0x26b4b213), X(0x26c39fda),
+ X(0x26d28f4c), X(0x26e18067), X(0x26f0732b), X(0x26ff6796),
+ X(0x270e5da7), X(0x271d555d), X(0x272c4eb7), X(0x273b49b5),
+ X(0x274a4654), X(0x27594495), X(0x27684475), X(0x277745f4),
+ X(0x27864910), X(0x27954dc9), X(0x27a4541e), X(0x27b35c0d),
+ X(0x27c26596), X(0x27d170b7), X(0x27e07d6f), X(0x27ef8bbd),
+ X(0x27fe9ba0), X(0x280dad18), X(0x281cc022), X(0x282bd4be),
+ X(0x283aeaeb), X(0x284a02a7), X(0x28591bf2), X(0x286836cb),
+ X(0x28775330), X(0x28867120), X(0x2895909b), X(0x28a4b19e),
+ X(0x28b3d42a), X(0x28c2f83d), X(0x28d21dd5), X(0x28e144f3),
+ X(0x28f06d94), X(0x28ff97b8), X(0x290ec35d), X(0x291df082),
+ X(0x292d1f27), X(0x293c4f4a), X(0x294b80eb), X(0x295ab407),
+ X(0x2969e89e), X(0x29791eaf), X(0x29885639), X(0x29978f3b),
+ X(0x29a6c9b3), X(0x29b605a0), X(0x29c54302), X(0x29d481d7),
+ X(0x29e3c21e), X(0x29f303d6), X(0x2a0246fd), X(0x2a118b94),
+ X(0x2a20d198), X(0x2a301909), X(0x2a3f61e6), X(0x2a4eac2c),
+ X(0x2a5df7dc), X(0x2a6d44f4), X(0x2a7c9374), X(0x2a8be359),
+ X(0x2a9b34a2), X(0x2aaa8750), X(0x2ab9db60), X(0x2ac930d1),
+ X(0x2ad887a3), X(0x2ae7dfd3), X(0x2af73962), X(0x2b06944e),
+ X(0x2b15f096), X(0x2b254e38), X(0x2b34ad34), X(0x2b440d89),
+ X(0x2b536f34), X(0x2b62d236), X(0x2b72368d), X(0x2b819c38),
+ X(0x2b910336), X(0x2ba06b86), X(0x2bafd526), X(0x2bbf4015),
+ X(0x2bceac53), X(0x2bde19de), X(0x2bed88b5), X(0x2bfcf8d7),
+ X(0x2c0c6a43), X(0x2c1bdcf7), X(0x2c2b50f3), X(0x2c3ac635),
+ X(0x2c4a3cbd), X(0x2c59b488), X(0x2c692d97), X(0x2c78a7e7),
+ X(0x2c882378), X(0x2c97a049), X(0x2ca71e58), X(0x2cb69da4),
+ X(0x2cc61e2c), X(0x2cd59ff0), X(0x2ce522ed), X(0x2cf4a723),
+ X(0x2d042c90), X(0x2d13b334), X(0x2d233b0d), X(0x2d32c41a),
+ X(0x2d424e5a), X(0x2d51d9cc), X(0x2d61666e), X(0x2d70f440),
+ X(0x2d808340), X(0x2d90136e), X(0x2d9fa4c7), X(0x2daf374c),
+ X(0x2dbecafa), X(0x2dce5fd1), X(0x2dddf5cf), X(0x2ded8cf4),
+ X(0x2dfd253d), X(0x2e0cbeab), X(0x2e1c593b), X(0x2e2bf4ed),
+ X(0x2e3b91c0), X(0x2e4b2fb1), X(0x2e5acec1), X(0x2e6a6eee),
+ X(0x2e7a1037), X(0x2e89b29b), X(0x2e995618), X(0x2ea8faad),
+ X(0x2eb8a05a), X(0x2ec8471c), X(0x2ed7eef4), X(0x2ee797df),
+ X(0x2ef741dc), X(0x2f06eceb), X(0x2f16990a), X(0x2f264639),
+ X(0x2f35f475), X(0x2f45a3bd), X(0x2f555412), X(0x2f650570),
+ X(0x2f74b7d8), X(0x2f846b48), X(0x2f941fbe), X(0x2fa3d53a),
+ X(0x2fb38bbb), X(0x2fc3433f), X(0x2fd2fbc5), X(0x2fe2b54c),
+ X(0x2ff26fd3), X(0x30022b58), X(0x3011e7db), X(0x3021a55a),
+ X(0x303163d4), X(0x30412348), X(0x3050e3b5), X(0x3060a519),
+ X(0x30706773), X(0x30802ac3), X(0x308fef06), X(0x309fb43d),
+ X(0x30af7a65), X(0x30bf417d), X(0x30cf0985), X(0x30ded27a),
+ X(0x30ee9c5d), X(0x30fe672b), X(0x310e32e3), X(0x311dff85),
+ X(0x312dcd0f), X(0x313d9b80), X(0x314d6ad7), X(0x315d3b12),
+ X(0x316d0c30), X(0x317cde31), X(0x318cb113), X(0x319c84d4),
+ X(0x31ac5974), X(0x31bc2ef1), X(0x31cc054b), X(0x31dbdc7f),
+ X(0x31ebb48e), X(0x31fb8d74), X(0x320b6733), X(0x321b41c7),
+ X(0x322b1d31), X(0x323af96e), X(0x324ad67e), X(0x325ab45f),
+ X(0x326a9311), X(0x327a7291), X(0x328a52e0), X(0x329a33fb),
+ X(0x32aa15e1), X(0x32b9f892), X(0x32c9dc0c), X(0x32d9c04d),
+ X(0x32e9a555), X(0x32f98b22), X(0x330971b4), X(0x33195909),
+ X(0x3329411f), X(0x333929f6), X(0x3349138c), X(0x3358fde1),
+ X(0x3368e8f2), X(0x3378d4c0), X(0x3388c147), X(0x3398ae89),
+ X(0x33a89c82), X(0x33b88b32), X(0x33c87a98), X(0x33d86ab2),
+ X(0x33e85b80), X(0x33f84d00), X(0x34083f30), X(0x34183210),
+ X(0x3428259f), X(0x343819db), X(0x34480ec3), X(0x34580455),
+ X(0x3467fa92), X(0x3477f176), X(0x3487e902), X(0x3497e134),
+ X(0x34a7da0a), X(0x34b7d384), X(0x34c7cda0), X(0x34d7c85e),
+ X(0x34e7c3bb), X(0x34f7bfb7), X(0x3507bc50), X(0x3517b985),
+ X(0x3527b756), X(0x3537b5c0), X(0x3547b4c3), X(0x3557b45d),
+ X(0x3567b48d), X(0x3577b552), X(0x3587b6aa), X(0x3597b895),
+ X(0x35a7bb12), X(0x35b7be1e), X(0x35c7c1b9), X(0x35d7c5e1),
+ X(0x35e7ca96), X(0x35f7cfd6), X(0x3607d5a0), X(0x3617dbf3),
+ X(0x3627e2cd), X(0x3637ea2d), X(0x3647f212), X(0x3657fa7b),
+ X(0x36680366), X(0x36780cd2), X(0x368816bf), X(0x3698212b),
+ X(0x36a82c14), X(0x36b83779), X(0x36c8435a), X(0x36d84fb4),
+ X(0x36e85c88), X(0x36f869d2), X(0x37087793), X(0x371885c9),
+ X(0x37289473), X(0x3738a38f), X(0x3748b31d), X(0x3758c31a),
+ X(0x3768d387), X(0x3778e461), X(0x3788f5a7), X(0x37990759),
+ X(0x37a91975), X(0x37b92bf9), X(0x37c93ee4), X(0x37d95236),
+ X(0x37e965ed), X(0x37f97a08), X(0x38098e85), X(0x3819a363),
+ X(0x3829b8a2), X(0x3839ce3f), X(0x3849e43a), X(0x3859fa91),
+ X(0x386a1143), X(0x387a284f), X(0x388a3fb4), X(0x389a5770),
+ X(0x38aa6f83), X(0x38ba87ea), X(0x38caa0a5), X(0x38dab9b2),
+ X(0x38ead311), X(0x38faecbf), X(0x390b06bc), X(0x391b2107),
+ X(0x392b3b9e), X(0x393b5680), X(0x394b71ac), X(0x395b8d20),
+ X(0x396ba8dc), X(0x397bc4dd), X(0x398be124), X(0x399bfdae),
+ X(0x39ac1a7a), X(0x39bc3788), X(0x39cc54d5), X(0x39dc7261),
+ X(0x39ec902a), X(0x39fcae2f), X(0x3a0ccc70), X(0x3a1ceaea),
+ X(0x3a2d099c), X(0x3a3d2885), X(0x3a4d47a5), X(0x3a5d66f9),
+ X(0x3a6d8680), X(0x3a7da63a), X(0x3a8dc625), X(0x3a9de63f),
+ X(0x3aae0688), X(0x3abe26fe), X(0x3ace47a0), X(0x3ade686d),
+ X(0x3aee8963), X(0x3afeaa82), X(0x3b0ecbc7), X(0x3b1eed32),
+ X(0x3b2f0ec2), X(0x3b3f3075), X(0x3b4f524a), X(0x3b5f7440),
+ X(0x3b6f9656), X(0x3b7fb889), X(0x3b8fdada), X(0x3b9ffd46),
+ X(0x3bb01fce), X(0x3bc0426e), X(0x3bd06526), X(0x3be087f6),
+ X(0x3bf0aada), X(0x3c00cdd4), X(0x3c10f0e0), X(0x3c2113fe),
+ X(0x3c31372d), X(0x3c415a6b), X(0x3c517db7), X(0x3c61a110),
+ X(0x3c71c475), X(0x3c81e7e4), X(0x3c920b5c), X(0x3ca22edc),
+ X(0x3cb25262), X(0x3cc275ee), X(0x3cd2997e), X(0x3ce2bd11),
+ X(0x3cf2e0a6), X(0x3d03043b), X(0x3d1327cf), X(0x3d234b61),
+ X(0x3d336ef0), X(0x3d43927a), X(0x3d53b5ff), X(0x3d63d97c),
+ X(0x3d73fcf1), X(0x3d84205c), X(0x3d9443bd), X(0x3da46711),
+ X(0x3db48a58), X(0x3dc4ad91), X(0x3dd4d0ba), X(0x3de4f3d1),
+ X(0x3df516d7), X(0x3e0539c9), X(0x3e155ca6), X(0x3e257f6d),
+ X(0x3e35a21d), X(0x3e45c4b4), X(0x3e55e731), X(0x3e660994),
+ X(0x3e762bda), X(0x3e864e03), X(0x3e96700d), X(0x3ea691f7),
+ X(0x3eb6b3bf), X(0x3ec6d565), X(0x3ed6f6e8), X(0x3ee71845),
+ X(0x3ef7397c), X(0x3f075a8c), X(0x3f177b73), X(0x3f279c30),
+ X(0x3f37bcc2), X(0x3f47dd27), X(0x3f57fd5f), X(0x3f681d68),
+ X(0x3f783d40), X(0x3f885ce7), X(0x3f987c5c), X(0x3fa89b9c),
+ X(0x3fb8baa7), X(0x3fc8d97c), X(0x3fd8f819), X(0x3fe9167e),
+ X(0x3ff934a8), X(0x40095296), X(0x40197049), X(0x40298dbd),
+ X(0x4039aaf2), X(0x4049c7e7), X(0x4059e49a), X(0x406a010a),
+ X(0x407a1d36), X(0x408a391d), X(0x409a54bd), X(0x40aa7015),
+ X(0x40ba8b25), X(0x40caa5ea), X(0x40dac063), X(0x40eada90),
+ X(0x40faf46e), X(0x410b0dfe), X(0x411b273d), X(0x412b402a),
+ X(0x413b58c4), X(0x414b710a), X(0x415b88fa), X(0x416ba093),
+ X(0x417bb7d5), X(0x418bcebe), X(0x419be54c), X(0x41abfb7e),
+ X(0x41bc1153), X(0x41cc26ca), X(0x41dc3be2), X(0x41ec5099),
+ X(0x41fc64ef), X(0x420c78e1), X(0x421c8c6f), X(0x422c9f97),
+ X(0x423cb258), X(0x424cc4b2), X(0x425cd6a2), X(0x426ce827),
+ X(0x427cf941), X(0x428d09ee), X(0x429d1a2c), X(0x42ad29fb),
+ X(0x42bd3959), X(0x42cd4846), X(0x42dd56bf), X(0x42ed64c3),
+ X(0x42fd7252), X(0x430d7f6a), X(0x431d8c0a), X(0x432d9831),
+ X(0x433da3dd), X(0x434daf0d), X(0x435db9c0), X(0x436dc3f5),
+ X(0x437dcdab), X(0x438dd6df), X(0x439ddf92), X(0x43ade7c1),
+ X(0x43bdef6c), X(0x43cdf691), X(0x43ddfd2f), X(0x43ee0345),
+ X(0x43fe08d2), X(0x440e0dd4), X(0x441e124b), X(0x442e1634),
+ X(0x443e198f), X(0x444e1c5a), X(0x445e1e95), X(0x446e203e),
+ X(0x447e2153), X(0x448e21d5), X(0x449e21c0), X(0x44ae2115),
+ X(0x44be1fd1), X(0x44ce1df4), X(0x44de1b7d), X(0x44ee186a),
+ X(0x44fe14ba), X(0x450e106b), X(0x451e0b7e), X(0x452e05ef),
+ X(0x453dffbf), X(0x454df8eb), X(0x455df173), X(0x456de956),
+ X(0x457de092), X(0x458dd726), X(0x459dcd10), X(0x45adc251),
+ X(0x45bdb6e5), X(0x45cdaacd), X(0x45dd9e06), X(0x45ed9091),
+ X(0x45fd826a), X(0x460d7392), X(0x461d6407), X(0x462d53c8),
+ X(0x463d42d4), X(0x464d3129), X(0x465d1ec6), X(0x466d0baa),
+ X(0x467cf7d3), X(0x468ce342), X(0x469ccdf3), X(0x46acb7e7),
+ X(0x46bca11c), X(0x46cc8990), X(0x46dc7143), X(0x46ec5833),
+ X(0x46fc3e5f), X(0x470c23c6), X(0x471c0867), X(0x472bec40),
+ X(0x473bcf50), X(0x474bb196), X(0x475b9311), X(0x476b73c0),
+ X(0x477b53a1), X(0x478b32b4), X(0x479b10f6), X(0x47aaee67),
+ X(0x47bacb06), X(0x47caa6d1), X(0x47da81c7), X(0x47ea5be7),
+ X(0x47fa3530), X(0x480a0da1), X(0x4819e537), X(0x4829bbf3),
+ X(0x483991d3), X(0x484966d6), X(0x48593afb), X(0x48690e3f),
+ X(0x4878e0a3), X(0x4888b225), X(0x489882c4), X(0x48a8527e),
+ X(0x48b82153), X(0x48c7ef41), X(0x48d7bc47), X(0x48e78863),
+ X(0x48f75396), X(0x49071ddc), X(0x4916e736), X(0x4926afa2),
+ X(0x4936771f), X(0x49463dac), X(0x49560347), X(0x4965c7ef),
+ X(0x49758ba4), X(0x49854e63), X(0x4995102c), X(0x49a4d0fe),
+ X(0x49b490d7), X(0x49c44fb6), X(0x49d40d9a), X(0x49e3ca82),
+ X(0x49f3866c), X(0x4a034159), X(0x4a12fb45), X(0x4a22b430),
+ X(0x4a326c19), X(0x4a4222ff), X(0x4a51d8e1), X(0x4a618dbd),
+ X(0x4a714192), X(0x4a80f45f), X(0x4a90a623), X(0x4aa056dd),
+ X(0x4ab0068b), X(0x4abfb52c), X(0x4acf62c0), X(0x4adf0f44),
+ X(0x4aeebab9), X(0x4afe651c), X(0x4b0e0e6c), X(0x4b1db6a9),
+ X(0x4b2d5dd1), X(0x4b3d03e2), X(0x4b4ca8dd), X(0x4b5c4cbf),
+ X(0x4b6bef88), X(0x4b7b9136), X(0x4b8b31c8), X(0x4b9ad13d),
+ X(0x4baa6f93), X(0x4bba0ccb), X(0x4bc9a8e2), X(0x4bd943d7),
+ X(0x4be8dda9), X(0x4bf87658), X(0x4c080de1), X(0x4c17a444),
+ X(0x4c27397f), X(0x4c36cd92), X(0x4c46607b), X(0x4c55f239),
+ X(0x4c6582cb), X(0x4c75122f), X(0x4c84a065), X(0x4c942d6c),
+ X(0x4ca3b942), X(0x4cb343e6), X(0x4cc2cd57), X(0x4cd25594),
+ X(0x4ce1dc9c), X(0x4cf1626d), X(0x4d00e707), X(0x4d106a68),
+ X(0x4d1fec8f), X(0x4d2f6d7a), X(0x4d3eed2a), X(0x4d4e6b9d),
+ X(0x4d5de8d1), X(0x4d6d64c5), X(0x4d7cdf79), X(0x4d8c58eb),
+ X(0x4d9bd11a), X(0x4dab4804), X(0x4dbabdaa), X(0x4dca3209),
+ X(0x4dd9a520), X(0x4de916ef), X(0x4df88774), X(0x4e07f6ae),
+ X(0x4e17649c), X(0x4e26d13c), X(0x4e363c8f), X(0x4e45a692),
+ X(0x4e550f44), X(0x4e6476a4), X(0x4e73dcb2), X(0x4e83416c),
+ X(0x4e92a4d1), X(0x4ea206df), X(0x4eb16796), X(0x4ec0c6f5),
+ X(0x4ed024fa), X(0x4edf81a5), X(0x4eeedcf3), X(0x4efe36e5),
+ X(0x4f0d8f79), X(0x4f1ce6ad), X(0x4f2c3c82), X(0x4f3b90f4),
+ X(0x4f4ae405), X(0x4f5a35b1), X(0x4f6985fa), X(0x4f78d4dc),
+ X(0x4f882257), X(0x4f976e6a), X(0x4fa6b914), X(0x4fb60254),
+ X(0x4fc54a28), X(0x4fd49090), X(0x4fe3d58b), X(0x4ff31917),
+ X(0x50025b33), X(0x50119bde), X(0x5020db17), X(0x503018dd),
+ X(0x503f552f), X(0x504e900b), X(0x505dc971), X(0x506d0160),
+ X(0x507c37d7), X(0x508b6cd3), X(0x509aa055), X(0x50a9d25b),
+ X(0x50b902e4), X(0x50c831ef), X(0x50d75f7b), X(0x50e68b87),
+ X(0x50f5b612), X(0x5104df1a), X(0x5114069f), X(0x51232ca0),
+ X(0x5132511a), X(0x5141740f), X(0x5150957b), X(0x515fb55f),
+ X(0x516ed3b8), X(0x517df087), X(0x518d0bca), X(0x519c257f),
+ X(0x51ab3da7), X(0x51ba543f), X(0x51c96947), X(0x51d87cbd),
+ X(0x51e78ea1), X(0x51f69ef1), X(0x5205adad), X(0x5214bad3),
+ X(0x5223c662), X(0x5232d05a), X(0x5241d8b9), X(0x5250df7d),
+ X(0x525fe4a7), X(0x526ee835), X(0x527dea26), X(0x528cea78),
+ X(0x529be92c), X(0x52aae63f), X(0x52b9e1b0), X(0x52c8db80),
+ X(0x52d7d3ac), X(0x52e6ca33), X(0x52f5bf15), X(0x5304b251),
+ X(0x5313a3e5), X(0x532293d0), X(0x53318212), X(0x53406ea8),
+ X(0x534f5993), X(0x535e42d2), X(0x536d2a62), X(0x537c1043),
+ X(0x538af475), X(0x5399d6f6), X(0x53a8b7c4), X(0x53b796e0),
+ X(0x53c67447), X(0x53d54ffa), X(0x53e429f6), X(0x53f3023b),
+ X(0x5401d8c8), X(0x5410ad9c), X(0x541f80b5), X(0x542e5213),
+ X(0x543d21b5), X(0x544bef9a), X(0x545abbc0), X(0x54698627),
+ X(0x54784ece), X(0x548715b3), X(0x5495dad6), X(0x54a49e35),
+ X(0x54b35fd0), X(0x54c21fa6), X(0x54d0ddb5), X(0x54df99fd),
+ X(0x54ee547c), X(0x54fd0d32), X(0x550bc41d), X(0x551a793d),
+ X(0x55292c91), X(0x5537de16), X(0x55468dce), X(0x55553bb6),
+ X(0x5563e7cd), X(0x55729213), X(0x55813a87), X(0x558fe127),
+ X(0x559e85f2), X(0x55ad28e9), X(0x55bbca08), X(0x55ca6950),
+ X(0x55d906c0), X(0x55e7a257), X(0x55f63c13), X(0x5604d3f4),
+ X(0x561369f8), X(0x5621fe1f), X(0x56309067), X(0x563f20d1),
+ X(0x564daf5a), X(0x565c3c02), X(0x566ac6c7), X(0x56794faa),
+ X(0x5687d6a8), X(0x56965bc1), X(0x56a4def4), X(0x56b36040),
+ X(0x56c1dfa4), X(0x56d05d1f), X(0x56ded8af), X(0x56ed5255),
+ X(0x56fbca0f), X(0x570a3fdc), X(0x5718b3bc), X(0x572725ac),
+ X(0x573595ad), X(0x574403bd), X(0x57526fdb), X(0x5760da07),
+ X(0x576f423f), X(0x577da883), X(0x578c0cd1), X(0x579a6f29),
+ X(0x57a8cf8a), X(0x57b72df2), X(0x57c58a61), X(0x57d3e4d6),
+ X(0x57e23d50), X(0x57f093cd), X(0x57fee84e), X(0x580d3ad1),
+ X(0x581b8b54), X(0x5829d9d8), X(0x5838265c), X(0x584670dd),
+ X(0x5854b95c), X(0x5862ffd8), X(0x5871444f), X(0x587f86c1),
+ X(0x588dc72c), X(0x589c0591), X(0x58aa41ed), X(0x58b87c40),
+ X(0x58c6b489), X(0x58d4eac7), X(0x58e31ef9), X(0x58f1511f),
+ X(0x58ff8137), X(0x590daf40), X(0x591bdb3a), X(0x592a0524),
+ X(0x59382cfc), X(0x594652c2), X(0x59547675), X(0x59629815),
+ X(0x5970b79f), X(0x597ed513), X(0x598cf071), X(0x599b09b7),
+ X(0x59a920e5), X(0x59b735f9), X(0x59c548f4), X(0x59d359d2),
+ X(0x59e16895), X(0x59ef753b), X(0x59fd7fc4), X(0x5a0b882d),
+ X(0x5a198e77), X(0x5a2792a0), X(0x5a3594a9), X(0x5a43948e),
+ X(0x5a519251), X(0x5a5f8df0), X(0x5a6d876a), X(0x5a7b7ebe),
+ X(0x5a8973ec), X(0x5a9766f2), X(0x5aa557d0), X(0x5ab34685),
+ X(0x5ac1330f), X(0x5acf1d6f), X(0x5add05a3), X(0x5aeaebaa),
+ X(0x5af8cf84), X(0x5b06b12f), X(0x5b1490ab), X(0x5b226df7),
+ X(0x5b304912), X(0x5b3e21fc), X(0x5b4bf8b2), X(0x5b59cd35),
+ X(0x5b679f84), X(0x5b756f9e), X(0x5b833d82), X(0x5b91092e),
+ X(0x5b9ed2a3), X(0x5bac99e0), X(0x5bba5ee3), X(0x5bc821ac),
+ X(0x5bd5e23a), X(0x5be3a08c), X(0x5bf15ca1), X(0x5bff1679),
+ X(0x5c0cce12), X(0x5c1a836c), X(0x5c283686), X(0x5c35e760),
+ X(0x5c4395f7), X(0x5c51424c), X(0x5c5eec5e), X(0x5c6c942b),
+ X(0x5c7a39b4), X(0x5c87dcf7), X(0x5c957df3), X(0x5ca31ca8),
+ X(0x5cb0b915), X(0x5cbe5338), X(0x5ccbeb12), X(0x5cd980a1),
+ X(0x5ce713e5), X(0x5cf4a4dd), X(0x5d023387), X(0x5d0fbfe4),
+ X(0x5d1d49f2), X(0x5d2ad1b1), X(0x5d38571f), X(0x5d45da3c),
+ X(0x5d535b08), X(0x5d60d981), X(0x5d6e55a7), X(0x5d7bcf78),
+ X(0x5d8946f5), X(0x5d96bc1c), X(0x5da42eec), X(0x5db19f65),
+ X(0x5dbf0d86), X(0x5dcc794e), X(0x5dd9e2bd), X(0x5de749d1),
+ X(0x5df4ae8a), X(0x5e0210e7), X(0x5e0f70e7), X(0x5e1cce8a),
+ X(0x5e2a29ce), X(0x5e3782b4), X(0x5e44d93a), X(0x5e522d5f),
+ X(0x5e5f7f23), X(0x5e6cce85), X(0x5e7a1b85), X(0x5e876620),
+ X(0x5e94ae58), X(0x5ea1f42a), X(0x5eaf3797), X(0x5ebc789d),
+ X(0x5ec9b73c), X(0x5ed6f372), X(0x5ee42d41), X(0x5ef164a5),
+ X(0x5efe999f), X(0x5f0bcc2f), X(0x5f18fc52), X(0x5f262a09),
+ X(0x5f335553), X(0x5f407e2f), X(0x5f4da49d), X(0x5f5ac89b),
+ X(0x5f67ea29), X(0x5f750946), X(0x5f8225f2), X(0x5f8f402b),
+ X(0x5f9c57f2), X(0x5fa96d44), X(0x5fb68023), X(0x5fc3908c),
+ X(0x5fd09e7f), X(0x5fdda9fc), X(0x5feab302), X(0x5ff7b990),
+ X(0x6004bda5), X(0x6011bf40), X(0x601ebe62), X(0x602bbb09),
+ X(0x6038b534), X(0x6045ace4), X(0x6052a216), X(0x605f94cb),
+ X(0x606c8502), X(0x607972b9), X(0x60865df2), X(0x609346aa),
+ X(0x60a02ce1), X(0x60ad1096), X(0x60b9f1c9), X(0x60c6d079),
+ X(0x60d3aca5), X(0x60e0864d), X(0x60ed5d70), X(0x60fa320d),
+ X(0x61070424), X(0x6113d3b4), X(0x6120a0bc), X(0x612d6b3c),
+ X(0x613a3332), X(0x6146f89f), X(0x6153bb82), X(0x61607bd9),
+ X(0x616d39a5), X(0x6179f4e5), X(0x6186ad98), X(0x619363bd),
+ X(0x61a01753), X(0x61acc85b), X(0x61b976d3), X(0x61c622bc),
+ X(0x61d2cc13), X(0x61df72d8), X(0x61ec170c), X(0x61f8b8ad),
+ X(0x620557ba), X(0x6211f434), X(0x621e8e18), X(0x622b2568),
+ X(0x6237ba21), X(0x62444c44), X(0x6250dbd0), X(0x625d68c4),
+ X(0x6269f320), X(0x62767ae2), X(0x6283000b), X(0x628f829a),
+ X(0x629c028e), X(0x62a87fe6), X(0x62b4faa2), X(0x62c172c2),
+ X(0x62cde844), X(0x62da5b29), X(0x62e6cb6e), X(0x62f33915),
+ X(0x62ffa41c), X(0x630c0c83), X(0x63187248), X(0x6324d56d),
+ X(0x633135ef), X(0x633d93ce), X(0x6349ef0b), X(0x635647a3),
+ X(0x63629d97), X(0x636ef0e6), X(0x637b418f), X(0x63878f92),
+ X(0x6393daef), X(0x63a023a4), X(0x63ac69b1), X(0x63b8ad15),
+ X(0x63c4edd1), X(0x63d12be3), X(0x63dd674b), X(0x63e9a008),
+ X(0x63f5d61a), X(0x64020980), X(0x640e3a39), X(0x641a6846),
+ X(0x642693a5), X(0x6432bc56), X(0x643ee258), X(0x644b05ab),
+ X(0x6457264e), X(0x64634441), X(0x646f5f83), X(0x647b7814),
+ X(0x64878df3), X(0x6493a120), X(0x649fb199), X(0x64abbf5f),
+ X(0x64b7ca71), X(0x64c3d2ce), X(0x64cfd877), X(0x64dbdb69),
+ X(0x64e7dba6), X(0x64f3d92b), X(0x64ffd3fa), X(0x650bcc11),
+ X(0x6517c16f), X(0x6523b415), X(0x652fa402), X(0x653b9134),
+ X(0x65477bad), X(0x6553636a), X(0x655f486d), X(0x656b2ab3),
+ X(0x65770a3d), X(0x6582e70a), X(0x658ec11a), X(0x659a986d),
+ X(0x65a66d00), X(0x65b23ed5), X(0x65be0deb), X(0x65c9da41),
+ X(0x65d5a3d7), X(0x65e16aac), X(0x65ed2ebf), X(0x65f8f011),
+ X(0x6604aea1), X(0x66106a6e), X(0x661c2377), X(0x6627d9be),
+ X(0x66338d40), X(0x663f3dfd), X(0x664aebf5), X(0x66569728),
+ X(0x66623f95), X(0x666de53b), X(0x6679881b), X(0x66852833),
+ X(0x6690c583), X(0x669c600b), X(0x66a7f7ca), X(0x66b38cc0),
+ X(0x66bf1eec), X(0x66caae4f), X(0x66d63ae6), X(0x66e1c4b3),
+ X(0x66ed4bb4), X(0x66f8cfea), X(0x67045153), X(0x670fcfef),
+ X(0x671b4bbe), X(0x6726c4bf), X(0x67323af3), X(0x673dae58),
+ X(0x67491eee), X(0x67548cb5), X(0x675ff7ab), X(0x676b5fd2),
+ X(0x6776c528), X(0x678227ad), X(0x678d8761), X(0x6798e443),
+ X(0x67a43e52), X(0x67af958f), X(0x67bae9f9), X(0x67c63b8f),
+ X(0x67d18a52), X(0x67dcd640), X(0x67e81f59), X(0x67f3659d),
+ X(0x67fea90c), X(0x6809e9a5), X(0x68152768), X(0x68206254),
+ X(0x682b9a68), X(0x6836cfa6), X(0x6842020b), X(0x684d3199),
+ X(0x68585e4d), X(0x68638829), X(0x686eaf2b), X(0x6879d354),
+ X(0x6884f4a2), X(0x68901316), X(0x689b2eb0), X(0x68a6476d),
+ X(0x68b15d50), X(0x68bc7056), X(0x68c78080), X(0x68d28dcd),
+ X(0x68dd983e), X(0x68e89fd0), X(0x68f3a486), X(0x68fea65d),
+ X(0x6909a555), X(0x6914a16f), X(0x691f9aa9), X(0x692a9104),
+ X(0x69358480), X(0x6940751b), X(0x694b62d5), X(0x69564daf),
+ X(0x696135a7), X(0x696c1abe), X(0x6976fcf3), X(0x6981dc46),
+ X(0x698cb8b6), X(0x69979243), X(0x69a268ed), X(0x69ad3cb4),
+ X(0x69b80d97), X(0x69c2db96), X(0x69cda6b0), X(0x69d86ee5),
+ X(0x69e33436), X(0x69edf6a1), X(0x69f8b626), X(0x6a0372c5),
+ X(0x6a0e2c7e), X(0x6a18e350), X(0x6a23973c), X(0x6a2e4840),
+ X(0x6a38f65d), X(0x6a43a191), X(0x6a4e49de), X(0x6a58ef42),
+ X(0x6a6391be), X(0x6a6e3151), X(0x6a78cdfa), X(0x6a8367ba),
+ X(0x6a8dfe90), X(0x6a98927c), X(0x6aa3237d), X(0x6aadb194),
+ X(0x6ab83cc0), X(0x6ac2c500), X(0x6acd4a55), X(0x6ad7ccbf),
+ X(0x6ae24c3c), X(0x6aecc8cd), X(0x6af74271), X(0x6b01b929),
+ X(0x6b0c2cf4), X(0x6b169dd1), X(0x6b210bc1), X(0x6b2b76c2),
+ X(0x6b35ded6), X(0x6b4043fc), X(0x6b4aa632), X(0x6b55057a),
+ X(0x6b5f61d3), X(0x6b69bb3d), X(0x6b7411b7), X(0x6b7e6541),
+ X(0x6b88b5db), X(0x6b930385), X(0x6b9d4e3f), X(0x6ba79607),
+ X(0x6bb1dadf), X(0x6bbc1cc6), X(0x6bc65bbb), X(0x6bd097bf),
+ X(0x6bdad0d0), X(0x6be506f0), X(0x6bef3a1d), X(0x6bf96a58),
+ X(0x6c0397a0), X(0x6c0dc1f5), X(0x6c17e957), X(0x6c220dc6),
+ X(0x6c2c2f41), X(0x6c364dc9), X(0x6c40695c), X(0x6c4a81fc),
+ X(0x6c5497a7), X(0x6c5eaa5d), X(0x6c68ba1f), X(0x6c72c6eb),
+ X(0x6c7cd0c3), X(0x6c86d7a6), X(0x6c90db92), X(0x6c9adc8a),
+ X(0x6ca4da8b), X(0x6caed596), X(0x6cb8cdab), X(0x6cc2c2ca),
+ X(0x6cccb4f2), X(0x6cd6a424), X(0x6ce0905e), X(0x6cea79a1),
+ X(0x6cf45fee), X(0x6cfe4342), X(0x6d0823a0), X(0x6d120105),
+ X(0x6d1bdb73), X(0x6d25b2e8), X(0x6d2f8765), X(0x6d3958ea),
+ X(0x6d432777), X(0x6d4cf30a), X(0x6d56bba5), X(0x6d608147),
+ X(0x6d6a43f0), X(0x6d7403a0), X(0x6d7dc056), X(0x6d877a13),
+ X(0x6d9130d6), X(0x6d9ae4a0), X(0x6da4956f), X(0x6dae4345),
+ X(0x6db7ee20), X(0x6dc19601), X(0x6dcb3ae7), X(0x6dd4dcd3),
+ X(0x6dde7bc4), X(0x6de817bb), X(0x6df1b0b6), X(0x6dfb46b7),
+ X(0x6e04d9bc), X(0x6e0e69c7), X(0x6e17f6d5), X(0x6e2180e9),
+ X(0x6e2b0801), X(0x6e348c1d), X(0x6e3e0d3d), X(0x6e478b62),
+ X(0x6e51068a), X(0x6e5a7eb7), X(0x6e63f3e7), X(0x6e6d661b),
+ X(0x6e76d552), X(0x6e80418e), X(0x6e89aacc), X(0x6e93110f),
+ X(0x6e9c7454), X(0x6ea5d49d), X(0x6eaf31e9), X(0x6eb88c37),
+ X(0x6ec1e389), X(0x6ecb37de), X(0x6ed48936), X(0x6eddd790),
+ X(0x6ee722ee), X(0x6ef06b4d), X(0x6ef9b0b0), X(0x6f02f315),
+ X(0x6f0c327c), X(0x6f156ee6), X(0x6f1ea852), X(0x6f27dec1),
+ X(0x6f311232), X(0x6f3a42a5), X(0x6f43701a), X(0x6f4c9a91),
+ X(0x6f55c20a), X(0x6f5ee686), X(0x6f680803), X(0x6f712682),
+ X(0x6f7a4203), X(0x6f835a86), X(0x6f8c700b), X(0x6f958291),
+ X(0x6f9e921a), X(0x6fa79ea4), X(0x6fb0a830), X(0x6fb9aebd),
+ X(0x6fc2b24c), X(0x6fcbb2dd), X(0x6fd4b06f), X(0x6fddab03),
+ X(0x6fe6a299), X(0x6fef9730), X(0x6ff888c9), X(0x70017763),
+ X(0x700a62ff), X(0x70134b9c), X(0x701c313b), X(0x702513dc),
+ X(0x702df37e), X(0x7036d021), X(0x703fa9c6), X(0x7048806d),
+ X(0x70515415), X(0x705a24bf), X(0x7062f26b), X(0x706bbd17),
+ X(0x707484c6), X(0x707d4976), X(0x70860b28), X(0x708ec9dc),
+ X(0x70978591), X(0x70a03e48), X(0x70a8f400), X(0x70b1a6bb),
+ X(0x70ba5677), X(0x70c30335), X(0x70cbacf5), X(0x70d453b6),
+ X(0x70dcf77a), X(0x70e59840), X(0x70ee3607), X(0x70f6d0d1),
+ X(0x70ff689d), X(0x7107fd6b), X(0x71108f3b), X(0x71191e0d),
+ X(0x7121a9e2), X(0x712a32b9), X(0x7132b892), X(0x713b3b6e),
+ X(0x7143bb4c), X(0x714c382d), X(0x7154b211), X(0x715d28f7),
+ X(0x71659ce0), X(0x716e0dcc), X(0x71767bbb), X(0x717ee6ac),
+ X(0x71874ea1), X(0x718fb399), X(0x71981594), X(0x71a07493),
+ X(0x71a8d094), X(0x71b1299a), X(0x71b97fa2), X(0x71c1d2af),
+ X(0x71ca22bf), X(0x71d26fd2), X(0x71dab9ea), X(0x71e30106),
+ X(0x71eb4526), X(0x71f3864a), X(0x71fbc472), X(0x7203ff9e),
+ X(0x720c37cf), X(0x72146d05), X(0x721c9f3f), X(0x7224ce7e),
+ X(0x722cfac2), X(0x7235240b), X(0x723d4a59), X(0x72456dad),
+ X(0x724d8e05), X(0x7255ab63), X(0x725dc5c7), X(0x7265dd31),
+ X(0x726df1a0), X(0x72760315), X(0x727e1191), X(0x72861d12),
+ X(0x728e259a), X(0x72962b28), X(0x729e2dbd), X(0x72a62d59),
+ X(0x72ae29fc), X(0x72b623a5), X(0x72be1a56), X(0x72c60e0e),
+ X(0x72cdfece), X(0x72d5ec95), X(0x72ddd764), X(0x72e5bf3b),
+ X(0x72eda41a), X(0x72f58601), X(0x72fd64f1), X(0x730540e9),
+ X(0x730d19e9), X(0x7314eff3), X(0x731cc305), X(0x73249321),
+ X(0x732c6046), X(0x73342a75), X(0x733bf1ad), X(0x7343b5ef),
+ X(0x734b773b), X(0x73533591), X(0x735af0f2), X(0x7362a95d),
+ X(0x736a5ed3), X(0x73721153), X(0x7379c0df), X(0x73816d76),
+ X(0x73891719), X(0x7390bdc7), X(0x73986181), X(0x73a00247),
+ X(0x73a7a01a), X(0x73af3af8), X(0x73b6d2e4), X(0x73be67dc),
+ X(0x73c5f9e1), X(0x73cd88f3), X(0x73d51513), X(0x73dc9e40),
+ X(0x73e4247c), X(0x73eba7c5), X(0x73f3281c), X(0x73faa582),
+ X(0x74021ff7), X(0x7409977b), X(0x74110c0d), X(0x74187daf),
+ X(0x741fec61), X(0x74275822), X(0x742ec0f3), X(0x743626d5),
+ X(0x743d89c7), X(0x7444e9c9), X(0x744c46dd), X(0x7453a101),
+ X(0x745af837), X(0x74624c7f), X(0x74699dd8), X(0x7470ec44),
+ X(0x747837c2), X(0x747f8052), X(0x7486c5f5), X(0x748e08ac),
+ X(0x74954875), X(0x749c8552), X(0x74a3bf43), X(0x74aaf648),
+ X(0x74b22a62), X(0x74b95b90), X(0x74c089d2), X(0x74c7b52a),
+ X(0x74cedd97), X(0x74d6031a), X(0x74dd25b2), X(0x74e44561),
+ X(0x74eb6226), X(0x74f27c02), X(0x74f992f5), X(0x7500a6ff),
+ X(0x7507b820), X(0x750ec659), X(0x7515d1aa), X(0x751cda14),
+ X(0x7523df96), X(0x752ae231), X(0x7531e1e5), X(0x7538deb2),
+ X(0x753fd89a), X(0x7546cf9b), X(0x754dc3b7), X(0x7554b4ed),
+ X(0x755ba33e), X(0x75628eaa), X(0x75697732), X(0x75705cd5),
+ X(0x75773f95), X(0x757e1f71), X(0x7584fc6a), X(0x758bd67f),
+ X(0x7592adb2), X(0x75998203), X(0x75a05371), X(0x75a721fe),
+ X(0x75adeda9), X(0x75b4b673), X(0x75bb7c5c), X(0x75c23f65),
+ X(0x75c8ff8d), X(0x75cfbcd6), X(0x75d6773f), X(0x75dd2ec8),
+ X(0x75e3e373), X(0x75ea953f), X(0x75f1442d), X(0x75f7f03d),
+ X(0x75fe996f), X(0x76053fc5), X(0x760be33d), X(0x761283d8),
+ X(0x76192197), X(0x761fbc7b), X(0x76265482), X(0x762ce9af),
+ X(0x76337c01), X(0x763a0b78), X(0x76409814), X(0x764721d7),
+ X(0x764da8c1), X(0x76542cd1), X(0x765aae08), X(0x76612c67),
+ X(0x7667a7ee), X(0x766e209d), X(0x76749675), X(0x767b0975),
+ X(0x7681799f), X(0x7687e6f3), X(0x768e5170), X(0x7694b918),
+ X(0x769b1deb), X(0x76a17fe9), X(0x76a7df13), X(0x76ae3b68),
+ X(0x76b494ea), X(0x76baeb98), X(0x76c13f74), X(0x76c7907c),
+ X(0x76cddeb3), X(0x76d42a18), X(0x76da72ab), X(0x76e0b86d),
+ X(0x76e6fb5e), X(0x76ed3b7f), X(0x76f378d0), X(0x76f9b352),
+ X(0x76ffeb05), X(0x77061fe8), X(0x770c51fe), X(0x77128145),
+ X(0x7718adbf), X(0x771ed76c), X(0x7724fe4c), X(0x772b225f),
+ X(0x773143a7), X(0x77376223), X(0x773d7dd3), X(0x774396ba),
+ X(0x7749acd5), X(0x774fc027), X(0x7755d0af), X(0x775bde6f),
+ X(0x7761e965), X(0x7767f193), X(0x776df6fa), X(0x7773f998),
+ X(0x7779f970), X(0x777ff681), X(0x7785f0cd), X(0x778be852),
+ X(0x7791dd12), X(0x7797cf0d), X(0x779dbe43), X(0x77a3aab6),
+ X(0x77a99465), X(0x77af7b50), X(0x77b55f79), X(0x77bb40e0),
+ X(0x77c11f85), X(0x77c6fb68), X(0x77ccd48a), X(0x77d2aaec),
+ X(0x77d87e8d), X(0x77de4f6f), X(0x77e41d92), X(0x77e9e8f5),
+ X(0x77efb19b), X(0x77f57782), X(0x77fb3aad), X(0x7800fb1a),
+ X(0x7806b8ca), X(0x780c73bf), X(0x78122bf7), X(0x7817e175),
+ X(0x781d9438), X(0x78234440), X(0x7828f18f), X(0x782e9c25),
+ X(0x78344401), X(0x7839e925), X(0x783f8b92), X(0x78452b46),
+ X(0x784ac844), X(0x7850628b), X(0x7855fa1c), X(0x785b8ef8),
+ X(0x7861211e), X(0x7866b090), X(0x786c3d4d), X(0x7871c757),
+ X(0x78774ead), X(0x787cd351), X(0x78825543), X(0x7887d483),
+ X(0x788d5111), X(0x7892caef), X(0x7898421c), X(0x789db69a),
+ X(0x78a32868), X(0x78a89787), X(0x78ae03f8), X(0x78b36dbb),
+ X(0x78b8d4d1), X(0x78be393a), X(0x78c39af6), X(0x78c8fa06),
+ X(0x78ce566c), X(0x78d3b026), X(0x78d90736), X(0x78de5b9c),
+ X(0x78e3ad58), X(0x78e8fc6c), X(0x78ee48d7), X(0x78f3929b),
+ X(0x78f8d9b7), X(0x78fe1e2c), X(0x79035ffb), X(0x79089f24),
+ X(0x790ddba8), X(0x79131587), X(0x79184cc2), X(0x791d8159),
+ X(0x7922b34d), X(0x7927e29e), X(0x792d0f4d), X(0x7932395a),
+ X(0x793760c6), X(0x793c8591), X(0x7941a7bd), X(0x7946c749),
+ X(0x794be435), X(0x7950fe84), X(0x79561634), X(0x795b2b47),
+ X(0x79603dbc), X(0x79654d96), X(0x796a5ad4), X(0x796f6576),
+ X(0x79746d7e), X(0x797972eb), X(0x797e75bf), X(0x798375f9),
+ X(0x7988739b), X(0x798d6ea5), X(0x79926717), X(0x79975cf2),
+ X(0x799c5037), X(0x79a140e6), X(0x79a62f00), X(0x79ab1a85),
+ X(0x79b00376), X(0x79b4e9d3), X(0x79b9cd9d), X(0x79beaed4),
+ X(0x79c38d79), X(0x79c8698d), X(0x79cd4310), X(0x79d21a03),
+ X(0x79d6ee66), X(0x79dbc03a), X(0x79e08f7f), X(0x79e55c36),
+ X(0x79ea265f), X(0x79eeedfc), X(0x79f3b30c), X(0x79f87590),
+ X(0x79fd3589), X(0x7a01f2f7), X(0x7a06addc), X(0x7a0b6636),
+ X(0x7a101c08), X(0x7a14cf52), X(0x7a198013), X(0x7a1e2e4d),
+ X(0x7a22da01), X(0x7a27832f), X(0x7a2c29d7), X(0x7a30cdfa),
+ X(0x7a356f99), X(0x7a3a0eb4), X(0x7a3eab4c), X(0x7a434561),
+ X(0x7a47dcf5), X(0x7a4c7207), X(0x7a510498), X(0x7a5594a9),
+ X(0x7a5a223a), X(0x7a5ead4d), X(0x7a6335e0), X(0x7a67bbf6),
+ X(0x7a6c3f8f), X(0x7a70c0ab), X(0x7a753f4b), X(0x7a79bb6f),
+ X(0x7a7e3519), X(0x7a82ac48), X(0x7a8720fe), X(0x7a8b933b),
+ X(0x7a9002ff), X(0x7a94704b), X(0x7a98db20), X(0x7a9d437e),
+ X(0x7aa1a967), X(0x7aa60cd9), X(0x7aaa6dd7), X(0x7aaecc61),
+ X(0x7ab32877), X(0x7ab7821b), X(0x7abbd94b), X(0x7ac02e0a),
+ X(0x7ac48058), X(0x7ac8d035), X(0x7acd1da3), X(0x7ad168a1),
+ X(0x7ad5b130), X(0x7ad9f751), X(0x7ade3b05), X(0x7ae27c4c),
+ X(0x7ae6bb27), X(0x7aeaf796), X(0x7aef319a), X(0x7af36934),
+ X(0x7af79e64), X(0x7afbd12c), X(0x7b00018a), X(0x7b042f81),
+ X(0x7b085b10), X(0x7b0c8439), X(0x7b10aafc), X(0x7b14cf5a),
+ X(0x7b18f153), X(0x7b1d10e8), X(0x7b212e1a), X(0x7b2548e9),
+ X(0x7b296155), X(0x7b2d7761), X(0x7b318b0b), X(0x7b359c55),
+ X(0x7b39ab3f), X(0x7b3db7cb), X(0x7b41c1f8), X(0x7b45c9c8),
+ X(0x7b49cf3b), X(0x7b4dd251), X(0x7b51d30b), X(0x7b55d16b),
+ X(0x7b59cd70), X(0x7b5dc71b), X(0x7b61be6d), X(0x7b65b366),
+ X(0x7b69a608), X(0x7b6d9653), X(0x7b718447), X(0x7b756fe5),
+ X(0x7b79592e), X(0x7b7d4022), X(0x7b8124c3), X(0x7b850710),
+ X(0x7b88e70a), X(0x7b8cc4b3), X(0x7b90a00a), X(0x7b947911),
+ X(0x7b984fc8), X(0x7b9c242f), X(0x7b9ff648), X(0x7ba3c612),
+ X(0x7ba79390), X(0x7bab5ec1), X(0x7baf27a5), X(0x7bb2ee3f),
+ X(0x7bb6b28e), X(0x7bba7493), X(0x7bbe344e), X(0x7bc1f1c1),
+ X(0x7bc5acec), X(0x7bc965cf), X(0x7bcd1c6c), X(0x7bd0d0c3),
+ X(0x7bd482d4), X(0x7bd832a1), X(0x7bdbe02a), X(0x7bdf8b70),
+ X(0x7be33473), X(0x7be6db34), X(0x7bea7fb4), X(0x7bee21f4),
+ X(0x7bf1c1f3), X(0x7bf55fb3), X(0x7bf8fb35), X(0x7bfc9479),
+ X(0x7c002b7f), X(0x7c03c04a), X(0x7c0752d8), X(0x7c0ae32b),
+ X(0x7c0e7144), X(0x7c11fd23), X(0x7c1586c9), X(0x7c190e36),
+ X(0x7c1c936c), X(0x7c20166b), X(0x7c239733), X(0x7c2715c6),
+ X(0x7c2a9224), X(0x7c2e0c4e), X(0x7c318444), X(0x7c34fa07),
+ X(0x7c386d98), X(0x7c3bdef8), X(0x7c3f4e26), X(0x7c42bb25),
+ X(0x7c4625f4), X(0x7c498e95), X(0x7c4cf507), X(0x7c50594c),
+ X(0x7c53bb65), X(0x7c571b51), X(0x7c5a7913), X(0x7c5dd4aa),
+ X(0x7c612e17), X(0x7c64855b), X(0x7c67da76), X(0x7c6b2d6a),
+ X(0x7c6e7e37), X(0x7c71ccdd), X(0x7c75195e), X(0x7c7863ba),
+ X(0x7c7babf1), X(0x7c7ef206), X(0x7c8235f7), X(0x7c8577c6),
+ X(0x7c88b774), X(0x7c8bf502), X(0x7c8f306f), X(0x7c9269bd),
+ X(0x7c95a0ec), X(0x7c98d5fe), X(0x7c9c08f2), X(0x7c9f39cb),
+ X(0x7ca26887), X(0x7ca59528), X(0x7ca8bfb0), X(0x7cabe81d),
+ X(0x7caf0e72), X(0x7cb232af), X(0x7cb554d4), X(0x7cb874e2),
+ X(0x7cbb92db), X(0x7cbeaebe), X(0x7cc1c88d), X(0x7cc4e047),
+ X(0x7cc7f5ef), X(0x7ccb0984), X(0x7cce1b08), X(0x7cd12a7b),
+ X(0x7cd437dd), X(0x7cd74330), X(0x7cda4c74), X(0x7cdd53aa),
+ X(0x7ce058d3), X(0x7ce35bef), X(0x7ce65cff), X(0x7ce95c04),
+ X(0x7cec58ff), X(0x7cef53f0), X(0x7cf24cd7), X(0x7cf543b7),
+ X(0x7cf8388f), X(0x7cfb2b60), X(0x7cfe1c2b), X(0x7d010af1),
+ X(0x7d03f7b2), X(0x7d06e26f), X(0x7d09cb29), X(0x7d0cb1e0),
+ X(0x7d0f9696), X(0x7d12794b), X(0x7d1559ff), X(0x7d1838b4),
+ X(0x7d1b156a), X(0x7d1df022), X(0x7d20c8dd), X(0x7d239f9b),
+ X(0x7d26745e), X(0x7d294725), X(0x7d2c17f1), X(0x7d2ee6c4),
+ X(0x7d31b39f), X(0x7d347e81), X(0x7d37476b), X(0x7d3a0e5f),
+ X(0x7d3cd35d), X(0x7d3f9665), X(0x7d425779), X(0x7d451699),
+ X(0x7d47d3c6), X(0x7d4a8f01), X(0x7d4d484b), X(0x7d4fffa3),
+ X(0x7d52b50c), X(0x7d556885), X(0x7d581a0f), X(0x7d5ac9ac),
+ X(0x7d5d775c), X(0x7d60231f), X(0x7d62ccf6), X(0x7d6574e3),
+ X(0x7d681ae6), X(0x7d6abeff), X(0x7d6d612f), X(0x7d700178),
+ X(0x7d729fd9), X(0x7d753c54), X(0x7d77d6e9), X(0x7d7a6f9a),
+ X(0x7d7d0666), X(0x7d7f9b4f), X(0x7d822e55), X(0x7d84bf79),
+ X(0x7d874ebc), X(0x7d89dc1e), X(0x7d8c67a1), X(0x7d8ef144),
+ X(0x7d91790a), X(0x7d93fef2), X(0x7d9682fd), X(0x7d99052d),
+ X(0x7d9b8581), X(0x7d9e03fb), X(0x7da0809b), X(0x7da2fb62),
+ X(0x7da57451), X(0x7da7eb68), X(0x7daa60a8), X(0x7dacd413),
+ X(0x7daf45a9), X(0x7db1b56a), X(0x7db42357), X(0x7db68f71),
+ X(0x7db8f9b9), X(0x7dbb6230), X(0x7dbdc8d6), X(0x7dc02dac),
+ X(0x7dc290b3), X(0x7dc4f1eb), X(0x7dc75156), X(0x7dc9aef4),
+ X(0x7dcc0ac5), X(0x7dce64cc), X(0x7dd0bd07), X(0x7dd31379),
+ X(0x7dd56821), X(0x7dd7bb01), X(0x7dda0c1a), X(0x7ddc5b6b),
+ X(0x7ddea8f7), X(0x7de0f4bd), X(0x7de33ebe), X(0x7de586fc),
+ X(0x7de7cd76), X(0x7dea122e), X(0x7dec5525), X(0x7dee965a),
+ X(0x7df0d5d0), X(0x7df31386), X(0x7df54f7e), X(0x7df789b8),
+ X(0x7df9c235), X(0x7dfbf8f5), X(0x7dfe2dfa), X(0x7e006145),
+ X(0x7e0292d5), X(0x7e04c2ac), X(0x7e06f0cb), X(0x7e091d32),
+ X(0x7e0b47e1), X(0x7e0d70db), X(0x7e0f981f), X(0x7e11bdaf),
+ X(0x7e13e18a), X(0x7e1603b3), X(0x7e182429), X(0x7e1a42ed),
+ X(0x7e1c6001), X(0x7e1e7b64), X(0x7e209518), X(0x7e22ad1d),
+ X(0x7e24c375), X(0x7e26d81f), X(0x7e28eb1d), X(0x7e2afc70),
+ X(0x7e2d0c17), X(0x7e2f1a15), X(0x7e31266a), X(0x7e333115),
+ X(0x7e353a1a), X(0x7e374177), X(0x7e39472e), X(0x7e3b4b3f),
+ X(0x7e3d4dac), X(0x7e3f4e75), X(0x7e414d9a), X(0x7e434b1e),
+ X(0x7e4546ff), X(0x7e474140), X(0x7e4939e0), X(0x7e4b30e2),
+ X(0x7e4d2644), X(0x7e4f1a09), X(0x7e510c30), X(0x7e52fcbc),
+ X(0x7e54ebab), X(0x7e56d900), X(0x7e58c4bb), X(0x7e5aaedd),
+ X(0x7e5c9766), X(0x7e5e7e57), X(0x7e6063b2), X(0x7e624776),
+ X(0x7e6429a5), X(0x7e660a3f), X(0x7e67e945), X(0x7e69c6b8),
+ X(0x7e6ba299), X(0x7e6d7ce7), X(0x7e6f55a5), X(0x7e712cd3),
+ X(0x7e730272), X(0x7e74d682), X(0x7e76a904), X(0x7e7879f9),
+ X(0x7e7a4962), X(0x7e7c173f), X(0x7e7de392), X(0x7e7fae5a),
+ X(0x7e817799), X(0x7e833f50), X(0x7e85057f), X(0x7e86ca27),
+ X(0x7e888d49), X(0x7e8a4ee5), X(0x7e8c0efd), X(0x7e8dcd91),
+ X(0x7e8f8aa1), X(0x7e914630), X(0x7e93003c), X(0x7e94b8c8),
+ X(0x7e966fd4), X(0x7e982560), X(0x7e99d96e), X(0x7e9b8bfe),
+ X(0x7e9d3d10), X(0x7e9eeca7), X(0x7ea09ac2), X(0x7ea24762),
+ X(0x7ea3f288), X(0x7ea59c35), X(0x7ea7446a), X(0x7ea8eb27),
+ X(0x7eaa906c), X(0x7eac343c), X(0x7eadd696), X(0x7eaf777b),
+ X(0x7eb116ed), X(0x7eb2b4eb), X(0x7eb45177), X(0x7eb5ec91),
+ X(0x7eb7863b), X(0x7eb91e74), X(0x7ebab53e), X(0x7ebc4a99),
+ X(0x7ebdde87), X(0x7ebf7107), X(0x7ec1021b), X(0x7ec291c3),
+ X(0x7ec42001), X(0x7ec5acd5), X(0x7ec7383f), X(0x7ec8c241),
+ X(0x7eca4adb), X(0x7ecbd20d), X(0x7ecd57da), X(0x7ecedc41),
+ X(0x7ed05f44), X(0x7ed1e0e2), X(0x7ed3611d), X(0x7ed4dff6),
+ X(0x7ed65d6d), X(0x7ed7d983), X(0x7ed95438), X(0x7edacd8f),
+ X(0x7edc4586), X(0x7eddbc20), X(0x7edf315c), X(0x7ee0a53c),
+ X(0x7ee217c1), X(0x7ee388ea), X(0x7ee4f8b9), X(0x7ee6672f),
+ X(0x7ee7d44c), X(0x7ee94012), X(0x7eeaaa80), X(0x7eec1397),
+ X(0x7eed7b59), X(0x7eeee1c6), X(0x7ef046df), X(0x7ef1aaa5),
+ X(0x7ef30d18), X(0x7ef46e39), X(0x7ef5ce09), X(0x7ef72c88),
+ X(0x7ef889b8), X(0x7ef9e599), X(0x7efb402c), X(0x7efc9972),
+ X(0x7efdf16b), X(0x7eff4818), X(0x7f009d79), X(0x7f01f191),
+ X(0x7f03445f), X(0x7f0495e4), X(0x7f05e620), X(0x7f073516),
+ X(0x7f0882c5), X(0x7f09cf2d), X(0x7f0b1a51), X(0x7f0c6430),
+ X(0x7f0daccc), X(0x7f0ef425), X(0x7f103a3b), X(0x7f117f11),
+ X(0x7f12c2a5), X(0x7f1404fa), X(0x7f15460f), X(0x7f1685e6),
+ X(0x7f17c47f), X(0x7f1901db), X(0x7f1a3dfb), X(0x7f1b78e0),
+ X(0x7f1cb28a), X(0x7f1deafa), X(0x7f1f2231), X(0x7f20582f),
+ X(0x7f218cf5), X(0x7f22c085), X(0x7f23f2de), X(0x7f252401),
+ X(0x7f2653f0), X(0x7f2782ab), X(0x7f28b032), X(0x7f29dc87),
+ X(0x7f2b07aa), X(0x7f2c319c), X(0x7f2d5a5e), X(0x7f2e81f0),
+ X(0x7f2fa853), X(0x7f30cd88), X(0x7f31f18f), X(0x7f33146a),
+ X(0x7f343619), X(0x7f35569c), X(0x7f3675f6), X(0x7f379425),
+ X(0x7f38b12c), X(0x7f39cd0a), X(0x7f3ae7c0), X(0x7f3c0150),
+ X(0x7f3d19ba), X(0x7f3e30fe), X(0x7f3f471e), X(0x7f405c1a),
+ X(0x7f416ff3), X(0x7f4282a9), X(0x7f43943e), X(0x7f44a4b2),
+ X(0x7f45b405), X(0x7f46c239), X(0x7f47cf4e), X(0x7f48db45),
+ X(0x7f49e61f), X(0x7f4aefdc), X(0x7f4bf87e), X(0x7f4d0004),
+ X(0x7f4e0670), X(0x7f4f0bc2), X(0x7f500ffb), X(0x7f51131c),
+ X(0x7f521525), X(0x7f531618), X(0x7f5415f4), X(0x7f5514bb),
+ X(0x7f56126e), X(0x7f570f0c), X(0x7f580a98), X(0x7f590511),
+ X(0x7f59fe78), X(0x7f5af6ce), X(0x7f5bee14), X(0x7f5ce44a),
+ X(0x7f5dd972), X(0x7f5ecd8b), X(0x7f5fc097), X(0x7f60b296),
+ X(0x7f61a389), X(0x7f629370), X(0x7f63824e), X(0x7f647021),
+ X(0x7f655ceb), X(0x7f6648ad), X(0x7f673367), X(0x7f681d19),
+ X(0x7f6905c6), X(0x7f69ed6d), X(0x7f6ad40f), X(0x7f6bb9ad),
+ X(0x7f6c9e48), X(0x7f6d81e0), X(0x7f6e6475), X(0x7f6f460a),
+ X(0x7f70269d), X(0x7f710631), X(0x7f71e4c6), X(0x7f72c25c),
+ X(0x7f739ef4), X(0x7f747a8f), X(0x7f75552e), X(0x7f762ed1),
+ X(0x7f770779), X(0x7f77df27), X(0x7f78b5db), X(0x7f798b97),
+ X(0x7f7a605a), X(0x7f7b3425), X(0x7f7c06fa), X(0x7f7cd8d9),
+ X(0x7f7da9c2), X(0x7f7e79b7), X(0x7f7f48b8), X(0x7f8016c5),
+ X(0x7f80e3e0), X(0x7f81b009), X(0x7f827b40), X(0x7f834588),
+ X(0x7f840edf), X(0x7f84d747), X(0x7f859ec1), X(0x7f86654d),
+ X(0x7f872aec), X(0x7f87ef9e), X(0x7f88b365), X(0x7f897641),
+ X(0x7f8a3832), X(0x7f8af93a), X(0x7f8bb959), X(0x7f8c7890),
+ X(0x7f8d36df), X(0x7f8df448), X(0x7f8eb0ca), X(0x7f8f6c67),
+ X(0x7f90271e), X(0x7f90e0f2), X(0x7f9199e2), X(0x7f9251f0),
+ X(0x7f93091b), X(0x7f93bf65), X(0x7f9474ce), X(0x7f952958),
+ X(0x7f95dd01), X(0x7f968fcd), X(0x7f9741ba), X(0x7f97f2ca),
+ X(0x7f98a2fd), X(0x7f995254), X(0x7f9a00d0), X(0x7f9aae71),
+ X(0x7f9b5b38), X(0x7f9c0726), X(0x7f9cb23b), X(0x7f9d5c78),
+ X(0x7f9e05de), X(0x7f9eae6e), X(0x7f9f5627), X(0x7f9ffd0b),
+ X(0x7fa0a31b), X(0x7fa14856), X(0x7fa1ecbf), X(0x7fa29054),
+ X(0x7fa33318), X(0x7fa3d50b), X(0x7fa4762c), X(0x7fa5167e),
+ X(0x7fa5b601), X(0x7fa654b5), X(0x7fa6f29b), X(0x7fa78fb3),
+ X(0x7fa82bff), X(0x7fa8c77f), X(0x7fa96234), X(0x7fa9fc1e),
+ X(0x7faa953e), X(0x7fab2d94), X(0x7fabc522), X(0x7fac5be8),
+ X(0x7facf1e6), X(0x7fad871d), X(0x7fae1b8f), X(0x7faeaf3b),
+ X(0x7faf4222), X(0x7fafd445), X(0x7fb065a4), X(0x7fb0f641),
+ X(0x7fb1861b), X(0x7fb21534), X(0x7fb2a38c), X(0x7fb33124),
+ X(0x7fb3bdfb), X(0x7fb44a14), X(0x7fb4d56f), X(0x7fb5600c),
+ X(0x7fb5e9ec), X(0x7fb6730f), X(0x7fb6fb76), X(0x7fb78323),
+ X(0x7fb80a15), X(0x7fb8904d), X(0x7fb915cc), X(0x7fb99a92),
+ X(0x7fba1ea0), X(0x7fbaa1f7), X(0x7fbb2497), X(0x7fbba681),
+ X(0x7fbc27b5), X(0x7fbca835), X(0x7fbd2801), X(0x7fbda719),
+ X(0x7fbe257e), X(0x7fbea331), X(0x7fbf2032), X(0x7fbf9c82),
+ X(0x7fc01821), X(0x7fc09311), X(0x7fc10d52), X(0x7fc186e4),
+ X(0x7fc1ffc8), X(0x7fc277ff), X(0x7fc2ef89), X(0x7fc36667),
+ X(0x7fc3dc9a), X(0x7fc45221), X(0x7fc4c6ff), X(0x7fc53b33),
+ X(0x7fc5aebe), X(0x7fc621a0), X(0x7fc693db), X(0x7fc7056f),
+ X(0x7fc7765c), X(0x7fc7e6a3), X(0x7fc85645), X(0x7fc8c542),
+ X(0x7fc9339b), X(0x7fc9a150), X(0x7fca0e63), X(0x7fca7ad3),
+ X(0x7fcae6a2), X(0x7fcb51cf), X(0x7fcbbc5c), X(0x7fcc2649),
+ X(0x7fcc8f97), X(0x7fccf846), X(0x7fcd6058), X(0x7fcdc7cb),
+ X(0x7fce2ea2), X(0x7fce94dd), X(0x7fcefa7b), X(0x7fcf5f7f),
+ X(0x7fcfc3e8), X(0x7fd027b7), X(0x7fd08aed), X(0x7fd0ed8b),
+ X(0x7fd14f90), X(0x7fd1b0fd), X(0x7fd211d4), X(0x7fd27214),
+ X(0x7fd2d1bf), X(0x7fd330d4), X(0x7fd38f55), X(0x7fd3ed41),
+ X(0x7fd44a9a), X(0x7fd4a761), X(0x7fd50395), X(0x7fd55f37),
+ X(0x7fd5ba48), X(0x7fd614c9), X(0x7fd66eba), X(0x7fd6c81b),
+ X(0x7fd720ed), X(0x7fd77932), X(0x7fd7d0e8), X(0x7fd82812),
+ X(0x7fd87eae), X(0x7fd8d4bf), X(0x7fd92a45), X(0x7fd97f40),
+ X(0x7fd9d3b0), X(0x7fda2797), X(0x7fda7af5), X(0x7fdacdca),
+ X(0x7fdb2018), X(0x7fdb71dd), X(0x7fdbc31c), X(0x7fdc13d5),
+ X(0x7fdc6408), X(0x7fdcb3b6), X(0x7fdd02df), X(0x7fdd5184),
+ X(0x7fdd9fa5), X(0x7fdded44), X(0x7fde3a60), X(0x7fde86fb),
+ X(0x7fded314), X(0x7fdf1eac), X(0x7fdf69c4), X(0x7fdfb45d),
+ X(0x7fdffe76), X(0x7fe04811), X(0x7fe0912e), X(0x7fe0d9ce),
+ X(0x7fe121f0), X(0x7fe16996), X(0x7fe1b0c1), X(0x7fe1f770),
+ X(0x7fe23da4), X(0x7fe2835f), X(0x7fe2c89f), X(0x7fe30d67),
+ X(0x7fe351b5), X(0x7fe3958c), X(0x7fe3d8ec), X(0x7fe41bd4),
+ X(0x7fe45e46), X(0x7fe4a042), X(0x7fe4e1c8), X(0x7fe522da),
+ X(0x7fe56378), X(0x7fe5a3a1), X(0x7fe5e358), X(0x7fe6229b),
+ X(0x7fe6616d), X(0x7fe69fcc), X(0x7fe6ddbb), X(0x7fe71b39),
+ X(0x7fe75847), X(0x7fe794e5), X(0x7fe7d114), X(0x7fe80cd5),
+ X(0x7fe84827), X(0x7fe8830c), X(0x7fe8bd84), X(0x7fe8f78f),
+ X(0x7fe9312f), X(0x7fe96a62), X(0x7fe9a32b), X(0x7fe9db8a),
+ X(0x7fea137e), X(0x7fea4b09), X(0x7fea822b), X(0x7feab8e5),
+ X(0x7feaef37), X(0x7feb2521), X(0x7feb5aa4), X(0x7feb8fc1),
+ X(0x7febc478), X(0x7febf8ca), X(0x7fec2cb6), X(0x7fec603e),
+ X(0x7fec9363), X(0x7fecc623), X(0x7fecf881), X(0x7fed2a7c),
+ X(0x7fed5c16), X(0x7fed8d4e), X(0x7fedbe24), X(0x7fedee9b),
+ X(0x7fee1eb1), X(0x7fee4e68), X(0x7fee7dc0), X(0x7feeacb9),
+ X(0x7feedb54), X(0x7fef0991), X(0x7fef3771), X(0x7fef64f5),
+ X(0x7fef921d), X(0x7fefbee8), X(0x7fefeb59), X(0x7ff0176f),
+ X(0x7ff0432a), X(0x7ff06e8c), X(0x7ff09995), X(0x7ff0c444),
+ X(0x7ff0ee9c), X(0x7ff1189b), X(0x7ff14243), X(0x7ff16b94),
+ X(0x7ff1948e), X(0x7ff1bd32), X(0x7ff1e581), X(0x7ff20d7b),
+ X(0x7ff2351f), X(0x7ff25c70), X(0x7ff2836d), X(0x7ff2aa17),
+ X(0x7ff2d06d), X(0x7ff2f672), X(0x7ff31c24), X(0x7ff34185),
+ X(0x7ff36695), X(0x7ff38b55), X(0x7ff3afc4), X(0x7ff3d3e4),
+ X(0x7ff3f7b4), X(0x7ff41b35), X(0x7ff43e69), X(0x7ff4614e),
+ X(0x7ff483e6), X(0x7ff4a631), X(0x7ff4c82f), X(0x7ff4e9e1),
+ X(0x7ff50b47), X(0x7ff52c62), X(0x7ff54d33), X(0x7ff56db9),
+ X(0x7ff58df5), X(0x7ff5ade7), X(0x7ff5cd90), X(0x7ff5ecf1),
+ X(0x7ff60c09), X(0x7ff62ada), X(0x7ff64963), X(0x7ff667a5),
+ X(0x7ff685a1), X(0x7ff6a357), X(0x7ff6c0c7), X(0x7ff6ddf1),
+ X(0x7ff6fad7), X(0x7ff71778), X(0x7ff733d6), X(0x7ff74fef),
+ X(0x7ff76bc6), X(0x7ff78759), X(0x7ff7a2ab), X(0x7ff7bdba),
+ X(0x7ff7d888), X(0x7ff7f315), X(0x7ff80d61), X(0x7ff8276c),
+ X(0x7ff84138), X(0x7ff85ac4), X(0x7ff87412), X(0x7ff88d20),
+ X(0x7ff8a5f0), X(0x7ff8be82), X(0x7ff8d6d7), X(0x7ff8eeef),
+ X(0x7ff906c9), X(0x7ff91e68), X(0x7ff935cb), X(0x7ff94cf2),
+ X(0x7ff963dd), X(0x7ff97a8f), X(0x7ff99105), X(0x7ff9a742),
+ X(0x7ff9bd45), X(0x7ff9d30f), X(0x7ff9e8a0), X(0x7ff9fdf9),
+ X(0x7ffa131a), X(0x7ffa2803), X(0x7ffa3cb4), X(0x7ffa512f),
+ X(0x7ffa6573), X(0x7ffa7981), X(0x7ffa8d59), X(0x7ffaa0fc),
+ X(0x7ffab46a), X(0x7ffac7a3), X(0x7ffadaa8), X(0x7ffaed78),
+ X(0x7ffb0015), X(0x7ffb127f), X(0x7ffb24b6), X(0x7ffb36bb),
+ X(0x7ffb488d), X(0x7ffb5a2e), X(0x7ffb6b9d), X(0x7ffb7cdb),
+ X(0x7ffb8de9), X(0x7ffb9ec6), X(0x7ffbaf73), X(0x7ffbbff1),
+ X(0x7ffbd03f), X(0x7ffbe05e), X(0x7ffbf04f), X(0x7ffc0012),
+ X(0x7ffc0fa6), X(0x7ffc1f0d), X(0x7ffc2e47), X(0x7ffc3d54),
+ X(0x7ffc4c35), X(0x7ffc5ae9), X(0x7ffc6971), X(0x7ffc77ce),
+ X(0x7ffc8600), X(0x7ffc9407), X(0x7ffca1e4), X(0x7ffcaf96),
+ X(0x7ffcbd1f), X(0x7ffcca7e), X(0x7ffcd7b4), X(0x7ffce4c1),
+ X(0x7ffcf1a5), X(0x7ffcfe62), X(0x7ffd0af6), X(0x7ffd1763),
+ X(0x7ffd23a9), X(0x7ffd2fc8), X(0x7ffd3bc1), X(0x7ffd4793),
+ X(0x7ffd533f), X(0x7ffd5ec5), X(0x7ffd6a27), X(0x7ffd7563),
+ X(0x7ffd807a), X(0x7ffd8b6e), X(0x7ffd963d), X(0x7ffda0e8),
+ X(0x7ffdab70), X(0x7ffdb5d5), X(0x7ffdc017), X(0x7ffdca36),
+ X(0x7ffdd434), X(0x7ffdde0f), X(0x7ffde7c9), X(0x7ffdf161),
+ X(0x7ffdfad8), X(0x7ffe042f), X(0x7ffe0d65), X(0x7ffe167b),
+ X(0x7ffe1f71), X(0x7ffe2848), X(0x7ffe30ff), X(0x7ffe3997),
+ X(0x7ffe4211), X(0x7ffe4a6c), X(0x7ffe52a9), X(0x7ffe5ac8),
+ X(0x7ffe62c9), X(0x7ffe6aae), X(0x7ffe7275), X(0x7ffe7a1f),
+ X(0x7ffe81ad), X(0x7ffe891f), X(0x7ffe9075), X(0x7ffe97b0),
+ X(0x7ffe9ece), X(0x7ffea5d2), X(0x7ffeacbb), X(0x7ffeb38a),
+ X(0x7ffeba3e), X(0x7ffec0d8), X(0x7ffec758), X(0x7ffecdbf),
+ X(0x7ffed40d), X(0x7ffeda41), X(0x7ffee05d), X(0x7ffee660),
+ X(0x7ffeec4b), X(0x7ffef21f), X(0x7ffef7da), X(0x7ffefd7e),
+ X(0x7fff030b), X(0x7fff0881), X(0x7fff0de0), X(0x7fff1328),
+ X(0x7fff185b), X(0x7fff1d77), X(0x7fff227e), X(0x7fff276f),
+ X(0x7fff2c4b), X(0x7fff3112), X(0x7fff35c4), X(0x7fff3a62),
+ X(0x7fff3eeb), X(0x7fff4360), X(0x7fff47c2), X(0x7fff4c0f),
+ X(0x7fff504a), X(0x7fff5471), X(0x7fff5885), X(0x7fff5c87),
+ X(0x7fff6076), X(0x7fff6452), X(0x7fff681d), X(0x7fff6bd6),
+ X(0x7fff6f7d), X(0x7fff7313), X(0x7fff7698), X(0x7fff7a0c),
+ X(0x7fff7d6f), X(0x7fff80c2), X(0x7fff8404), X(0x7fff8736),
+ X(0x7fff8a58), X(0x7fff8d6b), X(0x7fff906e), X(0x7fff9362),
+ X(0x7fff9646), X(0x7fff991c), X(0x7fff9be3), X(0x7fff9e9c),
+ X(0x7fffa146), X(0x7fffa3e2), X(0x7fffa671), X(0x7fffa8f1),
+ X(0x7fffab65), X(0x7fffadca), X(0x7fffb023), X(0x7fffb26f),
+ X(0x7fffb4ae), X(0x7fffb6e0), X(0x7fffb906), X(0x7fffbb20),
+ X(0x7fffbd2e), X(0x7fffbf30), X(0x7fffc126), X(0x7fffc311),
+ X(0x7fffc4f1), X(0x7fffc6c5), X(0x7fffc88f), X(0x7fffca4d),
+ X(0x7fffcc01), X(0x7fffcdab), X(0x7fffcf4a), X(0x7fffd0e0),
+ X(0x7fffd26b), X(0x7fffd3ec), X(0x7fffd564), X(0x7fffd6d2),
+ X(0x7fffd838), X(0x7fffd993), X(0x7fffdae6), X(0x7fffdc31),
+ X(0x7fffdd72), X(0x7fffdeab), X(0x7fffdfdb), X(0x7fffe104),
+ X(0x7fffe224), X(0x7fffe33c), X(0x7fffe44d), X(0x7fffe556),
+ X(0x7fffe657), X(0x7fffe751), X(0x7fffe844), X(0x7fffe930),
+ X(0x7fffea15), X(0x7fffeaf3), X(0x7fffebca), X(0x7fffec9b),
+ X(0x7fffed66), X(0x7fffee2a), X(0x7fffeee8), X(0x7fffefa0),
+ X(0x7ffff053), X(0x7ffff0ff), X(0x7ffff1a6), X(0x7ffff247),
+ X(0x7ffff2e4), X(0x7ffff37a), X(0x7ffff40c), X(0x7ffff499),
+ X(0x7ffff520), X(0x7ffff5a3), X(0x7ffff621), X(0x7ffff69b),
+ X(0x7ffff710), X(0x7ffff781), X(0x7ffff7ee), X(0x7ffff857),
+ X(0x7ffff8bb), X(0x7ffff91c), X(0x7ffff979), X(0x7ffff9d2),
+ X(0x7ffffa27), X(0x7ffffa79), X(0x7ffffac8), X(0x7ffffb13),
+ X(0x7ffffb5b), X(0x7ffffba0), X(0x7ffffbe2), X(0x7ffffc21),
+ X(0x7ffffc5d), X(0x7ffffc96), X(0x7ffffccd), X(0x7ffffd01),
+ X(0x7ffffd32), X(0x7ffffd61), X(0x7ffffd8e), X(0x7ffffdb8),
+ X(0x7ffffde0), X(0x7ffffe07), X(0x7ffffe2b), X(0x7ffffe4d),
+ X(0x7ffffe6d), X(0x7ffffe8b), X(0x7ffffea8), X(0x7ffffec3),
+ X(0x7ffffedc), X(0x7ffffef4), X(0x7fffff0a), X(0x7fffff1f),
+ X(0x7fffff33), X(0x7fffff45), X(0x7fffff56), X(0x7fffff66),
+ X(0x7fffff75), X(0x7fffff82), X(0x7fffff8f), X(0x7fffff9a),
+ X(0x7fffffa5), X(0x7fffffaf), X(0x7fffffb8), X(0x7fffffc0),
+ X(0x7fffffc8), X(0x7fffffce), X(0x7fffffd5), X(0x7fffffda),
+ X(0x7fffffdf), X(0x7fffffe4), X(0x7fffffe8), X(0x7fffffeb),
+ X(0x7fffffef), X(0x7ffffff1), X(0x7ffffff4), X(0x7ffffff6),
+ X(0x7ffffff8), X(0x7ffffff9), X(0x7ffffffb), X(0x7ffffffc),
+ X(0x7ffffffd), X(0x7ffffffd), X(0x7ffffffe), X(0x7fffffff),
+ X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
+ X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
+ X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
+};
+
diff --git a/osframework/source/SexyAppFramework/old_Quantize.cpp b/osframework/source/SexyAppFramework/old_Quantize.cpp
new file mode 100644
index 0000000..1a14ab5
--- /dev/null
+++ b/osframework/source/SexyAppFramework/old_Quantize.cpp
@@ -0,0 +1,857 @@
+#include "Quantize.h"
+#include <assert.h>
+#include <math.h>
+
+using namespace Sexy;
+
+#define ColorMatch(p,q) (((p)->red == (q)->red) && \
+ ((p)->green == (q)->green) && ((p)->blue == (q)->blue) && ((p)->opacity) == ((q)->opacity))
+
+#define MaxRGB 256
+
+#define MaxTreeDepth 8
+#define NodesInAList 1536
+
+#define ExceptionQueueLength 16
+#define MaxNodes 266817
+
+// Typdef declarations.
+
+typedef struct _QuantizeInfo
+{
+ unsigned long
+ number_colors;
+
+ unsigned int
+ tree_depth;
+} QuantizeInfo;
+
+typedef struct _PixelPacket
+{
+ uchar
+ blue,
+ green,
+ red,
+ opacity;
+} PixelPacket;
+
+typedef struct _NodeInfo
+{
+ struct _NodeInfo
+ *parent,
+ *child[8];
+
+ double
+ number_unique,
+ total_red,
+ total_green,
+ total_blue,
+ quantize_error;
+
+ unsigned long
+ color_number;
+
+ unsigned char
+ id,
+ level,
+ census;
+} NodeInfo;
+
+typedef struct _Nodes
+{
+ NodeInfo
+ nodes[NodesInAList];
+
+ struct _Nodes
+ *next;
+} Nodes;
+
+typedef struct _CubeInfo
+{
+ NodeInfo
+ *root;
+
+ unsigned long
+ colors;
+
+ PixelPacket
+ color,
+ *colormap;
+
+ double
+ distance,
+ pruning_threshold,
+ next_threshold;
+
+ unsigned long
+ nodes,
+ free_nodes,
+ color_number;
+
+ NodeInfo
+ *next_node;
+
+ Nodes
+ *node_queue;
+
+ long
+ *cache;
+
+ double
+ weights[ExceptionQueueLength];
+
+ const QuantizeInfo
+ *quantize_info;
+
+ long
+ x,
+ y;
+
+ unsigned int
+ depth;
+} CubeInfo;
+
+/*
+ Include declarations.
+*/
+
+static void *AcquireMemory(const size_t size)
+{
+ void
+ *allocation;
+
+ assert(size != 0);
+ allocation=malloc(size);
+ return(allocation);
+}
+
+static void *CloneMemory(void *destination, const void *source,
+ const size_t size)
+{
+ register unsigned char
+ *q;
+
+ register const unsigned char
+ *p;
+
+ register long
+ i;
+
+ assert(destination != (void *) NULL);
+ assert(source != (const void *) NULL);
+ p=(const unsigned char *) source;
+ q=(unsigned char *) destination;
+ if ((p <= q) || ((p+size) >= q))
+ return(memcpy(destination,source,size));
+ /*
+ Overlap, copy backwards.
+ */
+ p+=size;
+ q+=size;
+ for (i=size-1; i >= 0; i--)
+ *--q=(*--p);
+ return(destination);
+}
+
+static void LiberateMemory(void **memory)
+{
+ assert(memory != (void **) NULL);
+ if (*memory == (void *) NULL)
+ return;
+ free(*memory);
+ *memory=(void *) NULL;
+}
+
+static void ReacquireMemory(void **memory,const size_t size)
+{
+ void
+ *allocation;
+
+ assert(memory != (void **) NULL);
+ if (*memory == (void *) NULL)
+ {
+ *memory=AcquireMemory(size);
+ return;
+ }
+ allocation=realloc(*memory,size);
+ if (allocation == (void *) NULL)
+ LiberateMemory((void **) memory);
+ *memory=allocation;
+}
+
+static NodeInfo* GetNodeInfo(CubeInfo* cube_info, const unsigned int id, const unsigned int level, NodeInfo* parent)
+{
+ NodeInfo *node_info;
+
+ if (cube_info->free_nodes == 0)
+ {
+ Nodes* nodes;
+
+ // Allocate a new nodes of nodes.
+ nodes = (Nodes*) AcquireMemory(sizeof(Nodes));
+ if (nodes == (Nodes *) NULL)
+ return((NodeInfo *) NULL);
+
+ nodes->next = cube_info->node_queue;
+ cube_info->node_queue = nodes;
+ cube_info->next_node = nodes->nodes;
+ cube_info->free_nodes = NodesInAList;
+ }
+
+ cube_info->nodes++;
+ cube_info->free_nodes--;
+ node_info = cube_info->next_node++;
+ memset(node_info,0,sizeof(NodeInfo));
+ node_info->parent = parent;
+ node_info->id = id;
+ node_info->level = level;
+
+ return node_info;
+}
+
+static CubeInfo* GetCubeInfo(QuantizeInfo* theQuantizeInfo, unsigned int depth)
+{
+ CubeInfo *cube_info;
+
+ // Initialize tree to describe color cube_info.
+ cube_info = (CubeInfo*) AcquireMemory(sizeof(CubeInfo));
+
+ if (cube_info == (CubeInfo *) NULL)
+ return((CubeInfo *) NULL);
+
+ memset(cube_info,0,sizeof(CubeInfo));
+
+ if (depth > MaxTreeDepth)
+ depth = MaxTreeDepth;
+
+ if (depth < 2)
+ depth = 2;
+ cube_info->depth = depth;
+
+ // Initialize root node.
+ cube_info->root = GetNodeInfo(cube_info,0,0,(NodeInfo *) NULL);
+
+ if (cube_info->root == (NodeInfo *) NULL)
+ return((CubeInfo *) NULL);
+
+ cube_info->root->parent=cube_info->root;
+
+ cube_info->quantize_info = theQuantizeInfo;
+
+ return cube_info;
+}
+
+static void DestroyCubeInfo(CubeInfo *cube_info)
+{
+ register Nodes* nodes;
+
+ // Release color cube tree storage.
+ do
+ {
+ nodes = cube_info->node_queue->next;
+ LiberateMemory((void **) &cube_info->node_queue);
+ cube_info->node_queue = nodes;
+ } while (cube_info->node_queue != (Nodes *) NULL);
+
+ LiberateMemory((void **) &cube_info->cache);
+ LiberateMemory((void **) &cube_info);
+}
+
+static void PruneChild(CubeInfo *cube_info,const NodeInfo *node_info)
+{
+ NodeInfo *parent;
+
+ register long id;
+
+
+ // Traverse any children.
+ if (node_info->census != 0)
+ for (id=0; id < MaxTreeDepth; id++)
+ if (node_info->census & (1 << id))
+ PruneChild(cube_info,node_info->child[id]);
+
+ // Merge color statistics into parent.
+ parent = node_info->parent;
+ parent->census &= ~(1 << node_info->id);
+ parent->number_unique += node_info->number_unique;
+ parent->total_red += node_info->total_red;
+ parent->total_green += node_info->total_green;
+ parent->total_blue += node_info->total_blue;
+ cube_info->nodes--;
+}
+
+static void PruneLevel(CubeInfo *cube_info,const NodeInfo *node_info)
+{
+ register long id;
+ // Traverse any children.
+
+ if (node_info->census != 0)
+ {
+ for (id=0; id < MaxTreeDepth; id++)
+ {
+ if (node_info->census & (1 << id))
+ PruneLevel(cube_info,node_info->child[id]);
+ }
+ }
+
+ if (node_info->level == cube_info->depth)
+ PruneChild(cube_info,node_info);
+}
+
+static bool Classification(CubeInfo *cube_info, PixelPacket* thePixelPackets, int theWidth, int theHeight)
+{
+ double bisect, mid_red, mid_green, mid_blue;
+
+ long count, y;
+
+ NodeInfo* node_info;
+
+ register double blue, green, red;
+ register long x;
+ register const PixelPacket* p;
+ unsigned int index, level, id;
+
+ PixelPacket* aPixelRow = thePixelPackets;
+
+ for (y=0; y < (long) theHeight; y++)
+ {
+ p = aPixelRow;
+
+ if (cube_info->nodes > MaxNodes)
+ {
+ // Prune one level if the color tree is too large.
+ PruneLevel(cube_info,cube_info->root);
+ cube_info->depth--;
+ }
+
+ for (x=0; x < (long) theWidth; x+=count)
+ {
+ // Start at the root and descend the color cube tree.
+
+ for (count=1; (x+count) < (long) theWidth; count++)
+ if (!ColorMatch(p, p+count))
+ break;
+
+ index = MaxTreeDepth-1;
+ bisect = (MaxRGB+1)/2.0;
+ mid_red = MaxRGB/2.0;
+ mid_green = MaxRGB/2.0;
+ mid_blue = MaxRGB/2.0;
+ node_info = cube_info->root;
+ for (level=1; level <= cube_info->depth; level++)
+ {
+ bisect *= 0.5;
+ id = (unsigned int) ((((p->red) >> index) & 0x01) << 2 |
+ (((p->green) >> index) & 0x01) << 1 |
+ (((p->blue) >> index) & 0x01));
+
+ mid_red += id & 4 ? bisect : -bisect;
+ mid_green += id & 2 ? bisect : -bisect;
+ mid_blue += id & 1 ? bisect : -bisect;
+
+ if (node_info->child[id] == (NodeInfo *) NULL)
+ {
+ // Set colors of new node to contain pixel.
+ node_info->census |= (1 << id);
+ node_info->child[id] = GetNodeInfo(cube_info,id,level,node_info);
+
+ if (node_info->child[id] == (NodeInfo *) NULL)
+ {
+ //TODO: Exception
+ }
+
+ if (level == cube_info->depth)
+ cube_info->colors++;
+ }
+
+ // Approximate the quantization error represented by this node.
+ node_info = node_info->child[id];
+ red = (double) p->red-mid_red;
+ green = (double) p->green-mid_green;
+ blue = (double) p->blue-mid_blue;
+ node_info->quantize_error += count*red*red+count*green*green+count*blue*blue;
+ cube_info->root->quantize_error += node_info->quantize_error;
+
+ index--;
+ }
+
+ // Sum RGB for this leaf for later derivation of the mean cube color.
+ node_info->number_unique += count;
+ node_info->total_red += count*p->red;
+ node_info->total_green += count*p->green;
+ node_info->total_blue += count*p->blue;
+ p += count;
+ }
+
+ aPixelRow += theWidth;
+ }
+
+ return true;
+}
+
+static void Reduce(CubeInfo *cube_info,const NodeInfo *node_info)
+{
+ register unsigned int id;
+
+ // Traverse any children.
+ if (node_info->census != 0)
+ {
+ for (id=0; id < MaxTreeDepth; id++)
+ {
+ if (node_info->census & (1 << id))
+ Reduce(cube_info,node_info->child[id]);
+ }
+ }
+
+ if (node_info->quantize_error <= cube_info->pruning_threshold)
+ {
+ PruneChild(cube_info,node_info);
+ }
+ else
+ {
+ // Find minimum pruning threshold.
+ if (node_info->number_unique > 0)
+ cube_info->colors++;
+ if (node_info->quantize_error < cube_info->next_threshold)
+ cube_info->next_threshold=node_info->quantize_error;
+ }
+}
+
+static void Reduction(CubeInfo *cube_info,const unsigned long number_colors)
+{
+ unsigned long span;
+
+ span = cube_info->colors;
+ cube_info->next_threshold = 0.0;
+ while (cube_info->colors > number_colors)
+ {
+ cube_info->pruning_threshold = cube_info->next_threshold;
+ cube_info->next_threshold = cube_info->root->quantize_error-1;
+ cube_info->colors = 0;
+ Reduce(cube_info, cube_info->root);
+ }
+}
+
+static void ClosestColor(CubeInfo *cube_info,const NodeInfo *node_info)
+{
+ if (cube_info->distance != 0.0)
+ {
+ register unsigned int id;
+
+ // Traverse any children.
+ if (node_info->census != 0)
+ {
+ for (id=0; id < MaxTreeDepth; id++)
+ {
+ if (node_info->census & (1 << id))
+ ClosestColor(cube_info,node_info->child[id]);
+ }
+ }
+
+ if (node_info->number_unique != 0)
+ {
+ double distance;
+
+ register double blue, green, red;
+
+ register PixelPacket *color;
+
+ // Determine if this color is "closest".
+
+ color = cube_info->colormap+node_info->color_number;
+ red = (double) (color->red-cube_info->color.red);
+ distance = red*red;
+ if (distance < cube_info->distance)
+ {
+ green = (double) (color->green-cube_info->color.green);
+ distance += green*green;
+ if (distance < cube_info->distance)
+ {
+ blue = (double) (color->blue-cube_info->color.blue);
+ distance += blue*blue;
+ if (distance < cube_info->distance)
+ {
+ cube_info->distance = distance;
+ cube_info->color_number = node_info->color_number;
+ }
+ }
+ }
+ }
+ }
+}
+
+static void DefineColormap(CubeInfo *cube_info,NodeInfo *node_info)
+{
+ register unsigned int id;
+
+ // Traverse any children.
+
+ if (node_info->census != 0)
+ {
+ for (id=0; id < MaxTreeDepth; id++)
+ {
+ if (node_info->census & (1 << id))
+ DefineColormap(cube_info,node_info->child[id]);
+ }
+ }
+
+ if (node_info->number_unique != 0)
+ {
+ register double number_unique;
+
+ // Colormap entry is defined by the mean color in this cube.
+ number_unique = node_info->number_unique;
+ cube_info->colormap[cube_info->colors].red =
+ (uchar) ((node_info->total_red+0.5*number_unique)/number_unique);
+ cube_info->colormap[cube_info->colors].green =
+ (uchar) ((node_info->total_green+0.5*number_unique)/number_unique);
+ cube_info->colormap[cube_info->colors].blue =
+ (uchar) ((node_info->total_blue+0.5*number_unique)/number_unique);
+ node_info->color_number = cube_info->colors++;
+ }
+}
+
+static unsigned int Assignment(CubeInfo *cube_info, PixelPacket* thePixelPackets, int theWidth, int theHeight, uchar* theIndices, PixelPacket* theColorTable)
+{
+ uchar index;
+ long count, y;
+
+ register uchar *indexes;
+
+ register long i, x;
+
+ register const NodeInfo* node_info;
+
+ register PixelPacket* q;
+
+ unsigned int id;
+
+ // Allocate image colormap.
+
+ cube_info->colormap = theColorTable;
+ cube_info->colors = 0;
+ DefineColormap(cube_info, cube_info->root);
+
+ PixelPacket* aPixelRow = thePixelPackets;
+ uchar* aIndexRow = theIndices;
+
+ for (y=0; y < (long) theHeight; y++)
+ {
+ q = aPixelRow;
+
+ indexes=aIndexRow;
+
+ for (x=0; x < (long) theWidth; x+=count)
+ {
+ // Identify the deepest node containing the pixel's color.
+
+ for (count=1; (x+count) < (long) theWidth; count++)
+ if (!ColorMatch(q,q+count))
+ break;
+
+ node_info=cube_info->root;
+ for (index=MaxTreeDepth-1; (long) index > 0; index--)
+ {
+ id=(unsigned int) ((((q->red) >> index) & 0x01) << 2 |
+ (((q->green) >> index) & 0x01) << 1 |
+ (((q->blue) >> index) & 0x01));
+
+ if ((node_info->census & (1 << id)) == 0)
+ break;
+
+ node_info = node_info->child[id];
+ }
+
+ // Find closest color among siblings and their children.
+
+ cube_info->color.red = q->red;
+ cube_info->color.green = q->green;
+ cube_info->color.blue = q->blue;
+ cube_info->distance = 3.0*(MaxRGB+1)*(MaxRGB+1);
+ ClosestColor(cube_info, node_info->parent);
+ index = (unsigned int) cube_info->color_number;
+
+ for (i = 0; i < count; i++)
+ {
+ indexes[x+i] = index;
+
+ //if (image->storage_class == PseudoClass)
+ //indexes[x+i]=index;
+
+ //q->red=theColorTable[index].red;
+ //q->green=theColorTable[index].green;
+ //q->blue=theColorTable[index].blue;
+
+ q++;
+ }
+ }
+
+ aPixelRow += theWidth;
+ aIndexRow += theWidth;
+ }
+
+ return true;
+}
+
+void Sexy::Quantize8Bit(const ulong* theSrcBits, int theWidth, int theHeight, uchar* theDestColorIndices, ulong* theDestColorTable)
+{
+ QuantizeInfo aQuantizeInfo;
+ aQuantizeInfo.number_colors = 256;
+ aQuantizeInfo.tree_depth = 8;
+
+ CubeInfo *cube_info;
+
+ bool status;
+
+ unsigned long number_colors = aQuantizeInfo.number_colors;
+ unsigned int depth = aQuantizeInfo.tree_depth;
+
+ // Initialize color cube.
+
+ cube_info = GetCubeInfo(&aQuantizeInfo, depth);
+
+ if (cube_info == (CubeInfo *) NULL)
+ return;
+
+ ulong aThing = timeGetTime();
+ // 277ms
+ status = Classification(cube_info, (PixelPacket*) theSrcBits, theWidth, theHeight);
+ int aTiming = timeGetTime() - aThing;
+
+ if (status != false)
+ {
+ // Reduce the number of colors in the image.
+ aThing = timeGetTime();
+ // 1437ms
+ Reduction(cube_info, number_colors);
+ aTiming = timeGetTime() - aThing;
+
+ aThing = timeGetTime();
+ // 296 ms
+ Assignment(cube_info, (PixelPacket*) theSrcBits, theWidth, theHeight, (uchar*) theDestColorIndices, (PixelPacket*) theDestColorTable);
+ aTiming = timeGetTime() - aThing;
+ }
+
+ DestroyCubeInfo(cube_info);
+}
+
+
+
+// / / / / //
+
+struct ColorRecord
+{
+ ulong mColor;
+ uchar mIndex;
+ double mPriority;
+ ColorRecord* mNext;
+};
+
+const int MAX_COLOR_RECORDS = 60000;
+const int HASH_TABLE_SIZE = 16*16*16*16;
+
+ColorRecord gRecordPool[MAX_COLOR_RECORDS];
+ColorRecord* gColorRecordsHashTable[HASH_TABLE_SIZE]; // 4 bits each for RGBA
+
+int gSignedPowerTable[512];
+
+void Sexy::Quantize8Bit2(const ulong* theSrcBits, int theWidth, int theHeight, uchar* theDestColorIndices, ulong* theDestColorTable)
+{
+ int i;
+
+ for (i = 0; i < 512; i++)
+ gSignedPowerTable[i] = (i-256) * (i-256);
+
+ for (i = 0; i < HASH_TABLE_SIZE; i++)
+ gColorRecordsHashTable[i] = NULL;
+
+ int aSize = 0;
+
+ int aPoolSize = 0;
+
+ // Allocate from the color pool and stuff
+ const ulong* aSrcBitsPtr = theSrcBits;
+ for (int aRow = 0; aRow < theHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < theWidth; aCol++)
+ {
+ ulong src = *(aSrcBitsPtr++);
+
+ ushort aHashIndex = (ushort)
+ (((src & 0xFF000000) >> (3*8 - 3*4)) |
+ ((src & 0x00FF0000) >> (2*8 - 2*4)) |
+ ((src & 0x0000FF00) >> (1*8 - 1*4)) |
+ ((src & 0x000000FF) >> (0*8 - 0*4)));
+
+ ColorRecord* aColorRecord = gColorRecordsHashTable[aHashIndex];
+ if (aColorRecord == NULL)
+ {
+ if (aPoolSize < MAX_COLOR_RECORDS)
+ {
+ aColorRecord = &gRecordPool[aPoolSize++];
+ aColorRecord->mColor = src;
+ aColorRecord->mIndex = 0;
+ aColorRecord->mPriority = 1;
+ aColorRecord->mNext = NULL;
+
+ gColorRecordsHashTable[aHashIndex] = aColorRecord;
+ }
+ }
+ else
+ {
+ for (;;)
+ {
+ if (aColorRecord->mColor == src)
+ {
+ aColorRecord->mPriority++;
+ break;
+ }
+
+ if (aColorRecord->mNext == NULL)
+ {
+ if (aPoolSize < MAX_COLOR_RECORDS)
+ {
+ ColorRecord* aNextRecord = &gRecordPool[aPoolSize++];
+ aNextRecord->mColor = src;
+ aNextRecord->mIndex = 0;
+ aNextRecord->mPriority = 1;
+ aNextRecord->mNext = NULL;
+
+ aColorRecord->mNext = aNextRecord;
+ }
+
+ break;
+ }
+
+ aColorRecord = aColorRecord->mNext;
+ }
+ }
+ }
+ }
+
+ int aColorTableSize = 0;
+
+ while (aColorTableSize < 256)
+ {
+ double aBestPriority = 0;
+ ColorRecord* aBestColorRecord = NULL;
+
+ // Find record to use
+ for (int aPoolIdx = 0; aPoolIdx < aPoolSize; aPoolIdx++)
+ {
+ ColorRecord* aColorRecord = &gRecordPool[aPoolIdx];
+ if (aColorRecord->mPriority > aBestPriority)
+ {
+ aBestPriority = aColorRecord->mPriority;
+ aBestColorRecord = aColorRecord;
+ }
+ }
+
+ // Is the color table already completed?
+ if (aBestColorRecord == NULL)
+ break;
+
+ ulong aBestColor = aBestColorRecord->mColor;
+
+ for (int aPoolIdx = 0; aPoolIdx < aPoolSize; aPoolIdx++)
+ {
+ ColorRecord* aColorRecord = &gRecordPool[aPoolIdx];
+
+ ulong aColor = aColorRecord->mColor;
+
+ ulong aDistance =
+ gSignedPowerTable[((aColor >> 24) ) - ((aBestColor >> 24) ) + 256] +
+ gSignedPowerTable[((aColor >> 16) & 0xFF) - ((aBestColor >> 16) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor >> 8) & 0xFF) - ((aBestColor >> 8) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor ) & 0xFF) - ((aBestColor ) & 0xFF) + 256];
+
+ aColorRecord->mPriority -= aColorRecord->mPriority / ((aDistance * 0.01) + 1);
+ }
+
+ aBestColorRecord->mIndex = aColorTableSize;
+ theDestColorTable[aColorTableSize] = aBestColor;
+ aColorTableSize++;
+ }
+
+ // Assign colors now
+ aSrcBitsPtr = theSrcBits;
+ uchar* aDestIndexPtr = theDestColorIndices;
+ for (int aRow = 0; aRow < theHeight; aRow++)
+ {
+ for (int aCol = 0; aCol < theWidth; aCol++)
+ {
+ ulong src = *(aSrcBitsPtr++);
+
+ ushort aHashIndex = (ushort)
+ (((src & 0xFF000000) >> (3*8 - 3*4)) |
+ ((src & 0x00FF0000) >> (2*8 - 2*4)) |
+ ((src & 0x0000FF00) >> (1*8 - 1*4)) |
+ ((src & 0x000000FF) >> (0*8 - 0*4)));
+
+ ulong aClosestDistance = 0x7FFFFFFF;
+ uchar aClosestIndex = 0;
+
+ for (int aColorIdx = 0; aColorIdx < aColorTableSize; aColorIdx++)
+ {
+ ulong aColor = theDestColorTable[aColorIdx];
+
+ ulong aDistance =
+ gSignedPowerTable[((aColor >> 24) ) - ((src >> 24) ) + 256] +
+ gSignedPowerTable[((aColor >> 16) & 0xFF) - ((src >> 16) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor >> 8) & 0xFF) - ((src >> 8) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor ) & 0xFF) - ((src ) & 0xFF) + 256];
+
+ if (aDistance == 0)
+ {
+ aClosestDistance = 0;
+ aClosestIndex = aColorIdx;
+ break;
+ }
+ else if (aDistance < aClosestDistance)
+ {
+ aClosestDistance = aDistance;
+ aClosestIndex = aColorIdx;
+ }
+ }
+
+ /*ushort aHashIndex = (ushort)
+ (((src & 0xFF000000) >> (3*8 - 3*4)) |
+ ((src & 0x00FF0000) >> (2*8 - 2*4)) |
+ ((src & 0x0000FF00) >> (1*8 - 1*4)) |
+ ((src & 0x000000FF) >> (0*8 - 0*4)));
+
+ ulong aClosestDistance = 0x7FFFFFFF;
+ uchar aClosestIndex = 0;
+
+ ColorRecord* aColorRecord = gColorRecordsHashTable[aHashIndex];
+
+ while (aColorRecord != NULL)
+ {
+ ulong aColor = aColorRecord->mColor;
+
+ ulong aDistance =
+ gSignedPowerTable[((aColor >> 24) ) - ((src >> 24) ) + 256] +
+ gSignedPowerTable[((aColor >> 16) & 0xFF) - ((src >> 16) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor >> 8) & 0xFF) - ((src >> 8) & 0xFF) + 256] +
+ gSignedPowerTable[((aColor ) & 0xFF) - ((src ) & 0xFF) + 256];
+
+ if (aDistance == 0)
+ {
+ aClosestDistance = 0;
+ aClosestIndex = aColorRecord->mIndex;
+ break;
+ }
+ else if (aDistance < aClosestDistance)
+ {
+ aClosestDistance = aDistance;
+ aClosestIndex = aColorRecord->mIndex;
+ }
+
+ aColorRecord = aColorRecord->mNext;
+ }*/
+
+ *(aDestIndexPtr++) = aClosestIndex;
+ }
+ }
+}
+
diff --git a/osframework/source/SexyAppFramework/scrnsave.c b/osframework/source/SexyAppFramework/scrnsave.c
new file mode 100644
index 0000000..949a54b
--- /dev/null
+++ b/osframework/source/SexyAppFramework/scrnsave.c
@@ -0,0 +1,412 @@
+#pragma warning(disable:4312)
+#pragma warning(disable:4244)
+
+/*
+ Screen saver library by Anders Norlander <anorland@hem2.passagen.se>
+
+ This library is (hopefully) compatible with Microsoft's
+ screen saver library.
+
+ This is public domain software.
+
+ */
+#include <windows.h>
+#include <scrnsave.h>
+#include <regstr.h>
+
+/* screen saver window class */
+#define CLASS_SCRNSAVE TEXT("WindowsScreenSaverClass")
+
+/* globals */
+HWND hMainWindow = NULL;
+BOOL fChildPreview = FALSE;
+HINSTANCE hMainInstance;
+TCHAR szName[TITLEBARNAMELEN];
+TCHAR szAppName[APPNAMEBUFFERLEN];
+TCHAR szIniFile[MAXFILELEN];
+TCHAR szScreenSaver[22];
+TCHAR szHelpFile[MAXFILELEN];
+TCHAR szNoHelpMemory[BUFFLEN];
+UINT MyHelpMessage;
+
+/* local house keeping */
+static HINSTANCE hPwdLib = NULL;
+static POINT pt_orig;
+static BOOL checking_pwd = FALSE;
+static BOOL closing = FALSE;
+static BOOL w95 = FALSE;
+
+typedef BOOL (WINAPI *VERIFYPWDPROC)(HWND);
+typedef DWORD (WINAPI *CHPWDPROC)(LPCTSTR, HWND, DWORD, PVOID);
+static VERIFYPWDPROC VerifyScreenSavePwd = NULL;
+
+/* function names */
+#define szVerifyPassword "VerifyScreenSavePwd"
+
+#ifdef UNICODE
+#define szPwdChangePassword "PwdChangePasswordW"
+#else
+#define szPwdChangePassword "PwdChangePasswordA"
+#endif
+
+static void TerminateScreenSaver(HWND hWnd);
+static BOOL RegisterClasses(void);
+static LRESULT WINAPI SysScreenSaverProc(HWND,UINT,WPARAM,LPARAM);
+static int LaunchScreenSaver(HWND hParent);
+static void LaunchConfig(void);
+
+static int ISSPACE(char c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+#define ISNUM(c) ((c) >= '0' && c <= '9')
+static unsigned long
+_toul(const char *s)
+{
+ unsigned long res;
+ unsigned long n;
+ const char *p;
+ for (p = s; *p; p++)
+ if (!ISNUM(*p)) break;
+ p--;
+ res = 0;
+ for (n = 1; p >= s; p--, n *= 10)
+ res += (*p - '0') * n;
+ return res;
+}
+
+int APIENTRY ScreenSaverWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int nCmdShow)
+{
+ LPSTR p;
+ OSVERSIONINFO vi;
+
+ /* initialize */
+ hMainInstance = hInst;
+
+ vi.dwOSVersionInfoSize = sizeof(vi);
+ GetVersionEx(&vi);
+ /* check if we are going to check for passwords */
+ if (vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+ {
+ HKEY hKey;
+ /* we are using windows 95 */
+ w95 = TRUE;
+ if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE ,&hKey) ==
+ ERROR_SUCCESS)
+ {
+ DWORD check_pwd;
+ DWORD size = sizeof(DWORD);
+ DWORD type;
+ LONG res;
+ res = RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD,
+ NULL, &type, (PBYTE) &check_pwd, &size);
+ if (check_pwd && res == ERROR_SUCCESS)
+ {
+ hPwdLib = LoadLibrary(TEXT("PASSWORD.CPL"));
+ if (hPwdLib)
+ VerifyScreenSavePwd = (VERIFYPWDPROC)GetProcAddress(hPwdLib, szVerifyPassword);
+ }
+ RegCloseKey(hKey);
+ }
+ }
+
+ /* parse arguments */
+ for (p = CmdLine; *p; p++)
+ {
+ switch (*p)
+ {
+ case 'S':
+ case 's':
+ /* start screen saver */
+ return LaunchScreenSaver(NULL);
+
+ case 'P':
+ case 'p':
+ {
+ /* start screen saver in preview window */
+ HWND hParent;
+ fChildPreview = TRUE;
+ while (ISSPACE(*++p));
+ hParent = (HWND) _toul(p);
+ if (hParent && IsWindow(hParent))
+ return LaunchScreenSaver(hParent);
+ }
+ return 0;
+
+ case 'C':
+ case 'c':
+ /* display configure dialog */
+ LaunchConfig();
+ return 0;
+
+ case 'A':
+ case 'a':
+ {
+ /* change screen saver password */
+ HWND hParent;
+ while (ISSPACE(*++p));
+ hParent = (HWND) _toul(p);
+ if (!hParent || !IsWindow(hParent))
+ hParent = GetForegroundWindow();
+ ScreenSaverChangePassword(hParent);
+ }
+ return 0;
+
+ case '-':
+ case '/':
+ case ' ':
+ default:
+ break;
+ }
+ }
+ LaunchConfig();
+ return 0;
+}
+
+
+static void LaunchConfig(void)
+{
+ /* FIXME: should this be called */
+ RegisterDialogClasses(hMainInstance);
+ /* display configure dialog */
+ DialogBox(hMainInstance, MAKEINTRESOURCE(DLG_SCRNSAVECONFIGURE),
+ GetForegroundWindow(), (DLGPROC) ScreenSaverConfigureDialog);
+}
+
+
+static int LaunchScreenSaver(HWND hParent)
+{
+ BOOL foo;
+ UINT style;
+ RECT rc;
+ MSG msg;
+
+ /* don't allow other tasks to get into the foreground */
+ if (w95 && !fChildPreview)
+ SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, &foo, 0);
+
+ msg.wParam = 0;
+
+ /* register classes, both user defined and classes used by screen saver
+ library */
+ if (!RegisterClasses())
+ {
+ MessageBox(NULL, TEXT("RegisterClasses() failed"), NULL, MB_ICONHAND);
+ goto restore;
+ }
+
+ /* a slightly different approach needs to be used when displaying
+ in a preview window */
+ if (hParent)
+ {
+ style = WS_CHILD;
+ GetClientRect(hParent, &rc);
+ }
+ else
+ {
+ style = WS_POPUP;
+ rc.right = GetSystemMetrics(SM_CXSCREEN);
+ rc.bottom = GetSystemMetrics(SM_CYSCREEN);
+ style |= WS_VISIBLE;
+ }
+
+ /* create main screen saver window */
+ hMainWindow = CreateWindowEx(hParent ? 0 : WS_EX_TOPMOST, CLASS_SCRNSAVE,
+ TEXT("SCREENSAVER"), style,
+ 0, 0, rc.right, rc.bottom, hParent, NULL,
+ hMainInstance, NULL);
+
+ /* display window and start pumping messages */
+ if (hMainWindow)
+ {
+ UpdateWindow(hMainWindow);
+ ShowWindow(hMainWindow, SW_SHOW);
+
+ while (GetMessage(&msg, NULL, 0, 0) == TRUE)
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+restore:
+ /* restore system */
+ if (w95 && !fChildPreview)
+ SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, &foo, 0);
+ FreeLibrary(hPwdLib);
+ return msg.wParam;
+}
+
+/* this function takes care of *must* do tasks, like terminating
+ screen saver */
+static LRESULT WINAPI SysScreenSaverProc(HWND hWnd, UINT msg,
+ WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_CREATE:
+ if (!fChildPreview)
+ SetCursor(NULL);
+ /* mouse is not supposed to move from this position */
+ GetCursorPos(&pt_orig);
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ case WM_TIMER:
+ if (closing)
+ return 0;
+ break;
+ case WM_PAINT:
+ if (closing)
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+ break;
+ case WM_SYSCOMMAND:
+ if (!fChildPreview)
+ switch (wParam)
+ {
+ case SC_CLOSE:
+ case SC_SCREENSAVE:
+ case SC_NEXTWINDOW:
+ case SC_PREVWINDOW:
+ return FALSE;
+ }
+ break;
+ case WM_MOUSEMOVE:
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ case WM_NCACTIVATE:
+ case WM_ACTIVATE:
+ case WM_ACTIVATEAPP:
+ if (closing)
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+ break;
+ }
+ return ScreenSaverProc(hWnd, msg, wParam, lParam);
+}
+
+LONG WINAPI DefScreenSaverProc(HWND hWnd, UINT msg,
+ WPARAM wParam, LPARAM lParam)
+{
+ /* don't do any special processing when in preview mode */
+ if (fChildPreview || closing)
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+
+ switch (msg)
+ {
+ case WM_CLOSE:
+ TerminateScreenSaver(hWnd);
+ /* do NOT pass this to DefWindowProc; it will terminate even if
+ an invalid password was given.
+ */
+ return 0;
+ case SCRM_VERIFYPW:
+ /* verify password or return TRUE if password checking is turned off */
+ if (VerifyScreenSavePwd)
+ return VerifyScreenSavePwd(hWnd);
+ else
+ return TRUE;
+ case WM_SETCURSOR:
+ if (checking_pwd)
+ break;
+ SetCursor(NULL);
+ return TRUE;
+ case WM_NCACTIVATE:
+ case WM_ACTIVATE:
+ case WM_ACTIVATEAPP:
+ if (wParam != FALSE)
+ break;
+ case WM_MOUSEMOVE:
+ {
+ POINT pt;
+ GetCursorPos(&pt);
+ if (pt.x == pt_orig.x && pt.y == pt_orig.y)
+ break;
+ }
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ /* try to terminate screen saver */
+ if (!checking_pwd)
+ PostMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ }
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+}
+
+extern void ScreenSaverNotifyDestroy();
+static void TerminateScreenSaver(HWND hWnd)
+{
+ /* don't allow recursion */
+ if (checking_pwd || closing)
+ return;
+
+ /* verify password */
+ if (VerifyScreenSavePwd)
+ {
+ checking_pwd = TRUE;
+ closing = SendMessage(hWnd, SCRM_VERIFYPW, 0, 0);
+ checking_pwd = FALSE;
+ }
+ else
+ closing = TRUE;
+
+ /* are we closing? */
+ if (closing)
+ {
+ ScreenSaverNotifyDestroy();
+ DestroyWindow(hWnd);
+ }
+ else
+ GetCursorPos(&pt_orig); /* if not: get new mouse position */
+}
+
+/*
+ Register screen saver window class and call user
+ supplied hook.
+ */
+static BOOL RegisterClasses(void)
+{
+ WNDCLASS cls;
+
+ cls.hCursor = NULL;
+ cls.hIcon = LoadIcon(hMainInstance, MAKEINTATOM(ID_APP));
+ cls.lpszMenuName = NULL;
+ cls.lpszClassName = CLASS_SCRNSAVE;
+ cls.hbrBackground = GetStockObject(BLACK_BRUSH);
+ cls.hInstance = hMainInstance;
+ cls.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_PARENTDC;
+ cls.lpfnWndProc = (WNDPROC) SysScreenSaverProc;
+ cls.cbWndExtra = 0;
+ cls.cbClsExtra = 0;
+
+ if (!RegisterClass(&cls))
+ return FALSE;
+
+ return RegisterDialogClasses(hMainInstance);
+}
+
+void WINAPI ScreenSaverChangePassword(HWND hParent)
+{
+ /* load Master Password Router (MPR) */
+ HINSTANCE hMpr = LoadLibrary(TEXT("MPR.DLL"));
+
+ if (hMpr)
+ {
+ CHPWDPROC ChangePassword;
+ ChangePassword = (CHPWDPROC) GetProcAddress(hMpr, szPwdChangePassword);
+
+ /* change password for screen saver provider */
+ if (ChangePassword)
+ ChangePassword(TEXT("SCRSAVE"), hParent, 0, NULL);
+
+ FreeLibrary(hMpr);
+ }
+}
+
diff --git a/osframework/source/demos/Demo1/Board.cpp b/osframework/source/demos/Demo1/Board.cpp
new file mode 100644
index 0000000..77354de
--- /dev/null
+++ b/osframework/source/demos/Demo1/Board.cpp
@@ -0,0 +1,166 @@
+#include "Board.h"
+#include "SexyAppFramework/Graphics.h"
+
+// See the Draw method for more information on using the Color class.
+#include "SexyAppFramework/Color.h"
+
+// A generic X, Y point template. See Draw() below for usage info.
+#include "SexyAppFramework/Point.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+ // Let the parent class update as well. This will increment
+ // the variable mUpdateCnt which is an integer that indicates
+ // how many times the Update() method has been called. Since our
+ // Board class is updated 100 times per second, this variable will
+ // increment 100 times per second. As you will see in later demos,
+ // we will use this variable for animation since its value represents
+ // hundredths of a second, which is for almost all games a good
+ // enough timer value and doesn't rely on the system clock function
+ // call.
+ Widget::Update();
+
+
+ // For this and most of the other demos, you will see the function
+ // below called every Update() call. MarkDirty() tells the widget
+ // manager that something has changed graphically in the widget and
+ // that it needs to be repainted. All widgets follow this convention.
+ // In general, if you don't need
+ // to update your drawing every time you call the Update method
+ // (the most common case is when the game is paused) you should
+ // NOT mark dirty. Why? If you aren't marking dirty every frame,
+ // then you aren't drawing every frame and thus you use less CPU
+ // time. Because people like to multitask, or they may be on a laptop
+ // with limited battery life, using less CPU time lets people do
+ // other things besides play your game. Of course, everyone
+ // will want to play your game at all times, but it's good to be
+ // nice to those rare people that might want to read email or
+ // do other things at the same time.
+ // In this particular demo, we
+ // won't be nice, as the purpose is to bring you up to speed as
+ // quickly as possible, and so we'll dispense with optimizations
+ // for now, so you can concentrate on other core issues first.
+ // In general, this is the last method called in the Update
+ // function, but that is not necessary. In fact, the MarkDirty
+ // function can be called anywhere, in any method (although
+ // calling it in the Draw method doesn't make sense since it is
+ // already drawing) and even multiple times. Calling it multiple
+ // times does not do anything: only the first call makes a difference.
+ MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ // And now for the good stuff! The Graphics object, "g", is
+ // automatically created and passed to this method by the
+ // WidgetManager and can be thought of as the main screen
+ // bitmap/canvas upon which all drawing will be done. This object
+ // is double buffered automatically so you don't need to worry
+ // about those details. All you need to do is instruct the object
+ // that you would like to draw something to it, and when the
+ // WidgetManager gets done letting all widgets draw to the
+ // Graphics object, it will then blit everything to the screen
+ // at once.
+
+ // First, let's start by drawing some geometric primitives. By
+ // default, the drawing color is black. We will change it later
+ // on. The first command clears the screen by drawing a
+ // black rectangle (black due to the default color) that is
+ // located at coordinate 0, 0 and is the same size as our
+ // Board widget, which is the same size as the application and
+ // thus is the same size of the game window.
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // You may notice that there's another form of FillRect, one that
+ // takes a Rect object as its sole parameter. That does the
+ // same thing as the above function, but sometimes its more useful
+ // to draw using a Rect object.
+
+ // Now let's learn how to change the color of the shapes we're drawing.
+ // Call the "SetColor" method to change the current drawing color.
+ // The parameter is a Color object which can take 3 or 4 parameters.
+ // If you call it with only 3 parameters, the 4th one, which is the
+ // alpha value, is set to 255 for fully opaque. The first three are
+ // in order, red, green, and blue. They range from 0 to 255.
+
+ g->SetColor(Color(255, 128, 64)); // some ugly orangish color
+
+ // Let's draw a smaller rectangle with its upper left corner
+ // in the center of the screen.
+ g->FillRect(mWidth / 2, mHeight / 2, 50, 50);
+
+ // Now let's continue with some other primitives. How about
+ // drawing a few lines? We'll use a few other colors too.
+
+ g->SetColor(Color(255, 0, 0)); // red
+
+ // Parameter order is X1, Y1, X2, Y2
+ g->DrawLine(0, 0, 200, 150);
+
+ g->SetColor(Color(0, 255, 0)); // green
+ g->DrawLine(mWidth, 0, mWidth - 200, 150);
+
+ g->SetColor(Color(0, 0, 255)); // blue
+ g->DrawLine(0, mHeight, 200, mHeight - 150);
+
+ g->SetColor(Color(255, 255, 255)); // white
+ g->DrawLine(mWidth, mHeight, mWidth - 200, mHeight - 150);
+
+ // Let's draw another rectangle, with vertices where each of
+ // the previous 4 lines were. This time, however, let's not
+ // fill it in and just draw its outline instead. We
+ // accomplish that with the DrawRect function, which doesn't
+ // fill in the center.
+ g->SetColor(Color(255, 0, 255)); // purple
+ g->DrawRect(200, 150, (mWidth - 200) - 200, (mHeight - 150) - 150);
+
+ // Tired of drawing lines and quads? How about drawing a triangle
+ // instad? To do that, we use the generic PolyFill function which
+ // draws a closed polygon with any number of points, >= 2.
+ // We pass this function an array containing these points. We'll
+ // create such an array right now, although in reality you'd
+ // probably make this a constant instead of creating it every time.
+ // We'll make use of the Point template which will use the int type
+ // to specify the X, Y coordinates of each point in our triangle.
+ // It is assumed that the last point connects to the first point.
+ Point trianglePoints[3];
+ trianglePoints[0] = Point(30, 30);
+ trianglePoints[1] = Point(30, 60);
+ trianglePoints[2] = Point(60, 45);
+ g->SetColor(Color(255, 255, 0)); // yellow
+ g->PolyFill(trianglePoints, 3);
+
+ // And how about a pentagram as well?
+ g->SetColor(Color(0, 255, 255)); // cyan
+ Point pentaPoints[5];
+ pentaPoints[0] = Point(200, 0);
+ pentaPoints[1] = Point(150, 40);
+ pentaPoints[2] = Point(150, 80);
+ pentaPoints[3] = Point(250, 80);
+ pentaPoints[4] = Point(250, 40);
+ g->PolyFill(pentaPoints, 5);
+
+
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo1/Board.h b/osframework/source/demos/Demo1/Board.h
new file mode 100644
index 0000000..c4240a9
--- /dev/null
+++ b/osframework/source/demos/Demo1/Board.h
@@ -0,0 +1,106 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+// This file must be included so that we can derive our Board class from it
+#include "SexyAppFramework/Widget.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+
+// Forward declare the graphics class. You will see the graphics class used
+// and explained in Board.cpp: it is the main object used to draw all
+// images, fonts, etc.
+class Graphics;
+
+// We maintain a pointer to the main game application in the Board class.
+// The main game app contains functions that are often times needed
+// by the Board class, such as registry reading/writing, file reading/writing,
+// etc.
+class GameApp;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget
+{
+
+ private:
+
+ GameApp* mApp;
+
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo1/Demo1 VS2005 WideString.vcproj b/osframework/source/demos/Demo1/Demo1 VS2005 WideString.vcproj
new file mode 100644
index 0000000..ead39c9
--- /dev/null
+++ b/osframework/source/demos/Demo1/Demo1 VS2005 WideString.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo1"
+ ProjectGUID="{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo1_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo1.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo1.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo1_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo1/Demo1 VS2005.vcproj b/osframework/source/demos/Demo1/Demo1 VS2005.vcproj
new file mode 100644
index 0000000..d4d9779
--- /dev/null
+++ b/osframework/source/demos/Demo1/Demo1 VS2005.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo1"
+ ProjectGUID="{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo1_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo1.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo1.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo1_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo1/Demo1 WideString.vcproj b/osframework/source/demos/Demo1/Demo1 WideString.vcproj
new file mode 100644
index 0000000..48d9851
--- /dev/null
+++ b/osframework/source/demos/Demo1/Demo1 WideString.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo1"
+ ProjectGUID="{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo1_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo1.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo1.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo1_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo1/Demo1.dsp b/osframework/source/demos/Demo1/Demo1.dsp
new file mode 100644
index 0000000..d0976be
--- /dev/null
+++ b/osframework/source/demos/Demo1/Demo1.dsp
@@ -0,0 +1,126 @@
+# Microsoft Developer Studio Project File - Name="Demo1" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=DEMO1 - WIN32 DEBUG
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Demo1.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Demo1.mak" CFG="DEMO1 - WIN32 DEBUG"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Demo1 - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo1 - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Demo1 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Demo1___Win32_Release"
+# PROP BASE Intermediate_Dir "Demo1___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Demo1.exe"
+# SUBTRACT LINK32 /map
+
+!ELSEIF "$(CFG)" == "Demo1 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Demo1___Win32_Debug"
+# PROP BASE Intermediate_Dir "Demo1___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /map /debug /machine:I386 /out:"..\Demo1_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Demo1 - Win32 Release"
+# Name "Demo1 - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Demo1/Demo1.vcproj b/osframework/source/demos/Demo1/Demo1.vcproj
new file mode 100644
index 0000000..afa01a7
--- /dev/null
+++ b/osframework/source/demos/Demo1/Demo1.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo1"
+ ProjectGUID="{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo1_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo1.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo1.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo1_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo1/GameApp.cpp b/osframework/source/demos/Demo1/GameApp.cpp
new file mode 100644
index 0000000..b4a8549
--- /dev/null
+++ b/osframework/source/demos/Demo1/GameApp.cpp
@@ -0,0 +1,114 @@
+#include "GameApp.h"
+#include "Board.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Common.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ // mProdName is used for internal purposes to indicate the game that we're working on
+ mProdName = "Demo 1";
+
+ // For internal uses, indicates the current product version
+ mProductVersion = "1.0";
+
+ // This is the text that appears in the title bar of the application window
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+
+ // Indicates the registry location where all registry keys will be read from
+ // and written to. This is stored under the HKEY_CURRENT_USER tree on
+ // Windows systems.
+ mRegKey = "PopCap\\SexyAppFramework\\Demo1";
+
+ // Set the application width/height in terms of pixels here.
+ mWidth = 640;
+ mHeight = 480;
+
+ mBoard = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ // Remove our "Board" class which was, in this particular demo,
+ // responsible for all our game drawing and updating.
+ // All widgets MUST be removed from the widget manager before deletion.
+ // More information on the basics of widgets can be found in the Board
+ // class file. If you tried to delete the Board widget before removing
+ // it, you will get an assert.
+ mWidgetManager->RemoveWidget(mBoard);
+ delete mBoard;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+ // Let the parent class perform any needed initializations first.
+ // This should always be done.
+ SexyAppBase::Init();
+
+ // In later demos, you will see more done with this function.
+ // For now, we have nothing else to initialize, so we are done.
+ // Once complete, the LoadingThreadProc function will automatically
+ // start and we will begin loading all our needed resources.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+ // In this particular demo, there are no resources that we
+ // need to load. In every game and in all subsequent demos, however,
+ // there will be things we need to load. Besides loading data,
+ // this thread can also update the progress indicator for the loading
+ // screen, which you will see in later demos.
+ // Once complete, the LoadingThreadCompleted function will be called.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ // When we're actually loading resources, we'll set the
+ // mLoadingFailed variable to "true" if there were any problems
+ // encountered along the way. If that is the case, just return
+ // because we won't want the user to get to the main menu or any
+ // other part of the game. We will want them to exit out.
+ if (mLoadingFailed)
+ return;
+
+ // Now that we're done loading everything we need (which wasn't
+ // anything in this particular demo), we need to get the main
+ // game screen up and running: That is our "Board" class, and
+ // it will handle all the drawing, updating, and input processing
+ // for most of the game.
+ mBoard = new Board(this);
+
+ // This is a very important step: Because the Board class is a widget
+ // (see Board.h/.cpp for more details) we need to tell it what
+ // dimensions it has and where to place it.
+ // By default a widget is invisible because its
+ // width/height are 0, 0. Since the Board class is our main
+ // drawing area and game logic class, we want to make it the
+ // same size as the application. For this particular demo, that means
+ // 640x480. We will use mWidth and mHeight though, as those were
+ // already set to the proper resolution in GameApp::Init().
+ mBoard->Resize(0, 0, mWidth, mHeight);
+
+ // Also an important step is to add the newly created Board widget to
+ // the widget manager so that it will automatically have its update, draw,
+ // and input processing methods called.
+ mWidgetManager->AddWidget(mBoard);
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo1/GameApp.h b/osframework/source/demos/Demo1/GameApp.h
new file mode 100644
index 0000000..ce68822
--- /dev/null
+++ b/osframework/source/demos/Demo1/GameApp.h
@@ -0,0 +1,88 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+ // The GameApp class will be responsible for creating a class by the name
+ // of "Board", which we will use to do all the game's drawing, input processing,
+ // etc. Board is the second most important class and is where almost all of your
+ // game logic code will originate from. It is a widget, which allows for
+ // easy and automatic invocation of its update, drawing, and input processing
+ // functions. See the "Board" class for more details.
+ class Board;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo1/main.cpp b/osframework/source/demos/Demo1/main.cpp
new file mode 100644
index 0000000..bfb8175
--- /dev/null
+++ b/osframework/source/demos/Demo1/main.cpp
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Setting app width/height
+// * Drawing primitives
+// * Changing colors
+// * Widget basics: Adding, removing, drawing, updating
+// * Standardized game logic frame rate
+// * Intro to the Init and resource loading methods
+// * Introduction to the structure and organization of a SexyAppBase game
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+ // Make sure to set this. Some classes, like the exception handler and custom cursors
+ // will need to use it.
+ gHInstance = hInstance;
+
+ // Create and initialize our game application.
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+
+ // Starts the entire application: sets up the resource loading thread and
+ // custom cursor thread, and enters the game loop where the application
+ // will remain until it is shut down. You will most likely not need to
+ // override this function.
+ anApp->Start();
+
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Demo2/Board.cpp b/osframework/source/demos/Demo2/Board.cpp
new file mode 100644
index 0000000..4bc7f4a
--- /dev/null
+++ b/osframework/source/demos/Demo2/Board.cpp
@@ -0,0 +1,305 @@
+#include "Board.h"
+#include "GameApp.h"
+#include "SexyAppFramework/Graphics.h"
+
+// See the Draw method for more information on using the Color class.
+#include "SexyAppFramework/Color.h"
+
+// Why are we including ImageFont.h and not Font.h? Font.h is just a generic
+// base class. ImageFont creates fonts from an image that contains all the
+// text characters as well as a text file that indicates character widths
+// and kerning information, as well as some more advanced features not used
+// in this tutorial such as font layers, etc.
+#include "SexyAppFramework/ImageFont.h"
+
+// The Image.h file just declares basic functions. All images are either of
+// the DDImage or MemoryImage type. For this demo, we will use DDImage
+// types, as they are the type returned by the image loading code.
+// A DDImage is actually derived from MemoryImage, so where an Image or
+// MemoryImage is required, a DDImage will suffice as well. A DDImage
+// contains optimized code for use with DirectX 7+.
+#include "SexyAppFramework/DDImage.h"
+
+// The Rectangle template, used to specify X, Y, Width, Height
+#include "SexyAppFramework/Rect.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+
+ // Start by fully glowing and making the pulse decrease
+ mPulseAmt = 255;
+ mIncPulse = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+ // Let the parent class update as well. This will increment
+ // the variable mUpdateCnt which is an integer that indicates
+ // how many times the Update() method has been called. Since our
+ // Board class is updated 100 times per second, this variable will
+ // increment 100 times per second. As you will see in later demos,
+ // we will use this variable for animation since its value represents
+ // hundredths of a second, which is for almost all games a good
+ // enough timer value and doesn't rely on the system clock function
+ // call.
+ Widget::Update();
+
+ // Every frame (100 times per second) let's change the pulse amount by
+ // 1. When we reach either 0 or 255 (the lower/upper bounds of
+ // a color value) we'll reverse the pulsing direction. See the Draw()
+ // method for its usage: we're going to draw an image with varying intenstiy
+ // over time.
+ if (mIncPulse)
+ {
+ if (++mPulseAmt >= 255)
+ {
+ mIncPulse = false;
+ mPulseAmt = 255;
+ }
+ }
+ else
+ {
+ if (--mPulseAmt <= 0)
+ {
+ mIncPulse = true;
+ mPulseAmt = 0;
+ }
+ }
+
+ // Let's play the timer sound effect once every 2 second.
+ // Since this method is called 100 times per second, just mod
+ // mUpdateCnt by 200. We do that by calling GameApp's PlaySample()
+ // method and specifying the integral ID of the sound to play. This
+ // ID is the same as we used when loading the sound in GameApp::LoadingThreadProc()
+ if (mUpdateCnt % 200 == 0)
+ mApp->PlaySample(1);
+
+ // What about playing a sound but making it play on either the left or
+ // right speaker? And what about pitch shifting? These are all possible,
+ // but we won't learn about them until a later demo.
+
+
+
+ // For this and most of the other demos, you will see the function
+ // below called every Update() call. MarkDirty() tells the widget
+ // manager that something has changed graphically in the widget and
+ // that it needs to be repainted. All widgets follow this convention.
+ // In general, if you don't need
+ // to update your drawing every time you call the Update method
+ // (the most common case is when the game is paused) you should
+ // NOT mark dirty. Why? If you aren't marking dirty every frame,
+ // then you aren't drawing every frame and thus you use less CPU
+ // time. Because people like to multitask, or they may be on a laptop
+ // with limited battery life, using less CPU time lets people do
+ // other things besides play your game. Of course, everyone
+ // will want to play your game at all times, but it's good to be
+ // nice to those rare people that might want to read email or
+ // do other things at the same time.
+ // In this particular demo, we
+ // won't be nice, as the purpose is to bring you up to speed as
+ // quickly as possible, and so we'll dispense with optimizations
+ // for now, so you can concentrate on other core issues first.
+ // In general, this is the last method called in the Update
+ // function, but that is not necessary. In fact, the MarkDirty
+ // function can be called anywhere, in any method (although
+ // calling it in the Draw method doesn't make sense since it is
+ // already drawing) and even multiple times. Calling it multiple
+ // times does not do anything: only the first call makes a difference.
+ MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ // And now for the good stuff! The Graphics object, "g", is
+ // automatically created and passed to this method by the
+ // WidgetManager and can be thought of as the main screen
+ // bitmap/canvas upon which all drawing will be done. This object
+ // is double buffered automatically so you don't need to worry
+ // about those details. All you need to do is instruct the object
+ // that you would like to draw something to it, and when the
+ // WidgetManager gets done letting all widgets draw to the
+ // Graphics object, it will then blit everything to the screen
+ // at once.
+
+ // First, let's start by clearing the screen to black.
+ // As you'll recall from Demo1, we set the color with SetColor
+ // and pass in a Color object that contains either 3 or 4 parameters,
+ // that represent the r,g,b,a values (alpha is 255 if only 3 specified).
+ g->SetColor(Color(0, 0, 0));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Now let's print some text. In order to do so, we need to instruct the
+ // graphics object as to which font we want to use. We do that with
+ // the SetFont method. Then we call the DrawString method and pass in
+ // a normal string and give it an X, Y to draw at. But wait! If we just
+ // draw a string right now, we won't see it. Can you guess why?
+ // The graphics object is still using the color, white, which we
+ // set a few lines above. Thus, when it goes to draw the string,
+ // it will draw it in white. How do you change the text color?
+ // Easy: it's just like you learned for drawing those primitives:
+ // just use SetColor and you're done! It doesn't matter whether you
+ // set the color before or after you set the font, fyi.
+ g->SetColor(Color(255, 0, 0));
+ g->SetFont(mApp->mTextFont);
+ g->DrawString(_S("Woo! Text! Ya!"), 10, 10);
+
+ // Wait a minute, didn't we say to draw at a Y value of 10? Then why does it
+ // appear to be drawing at about 0? That's because the text is offset
+ // by the ascent of the font. A discussion of font terms is beyond the
+ // scope of this demo, but basically just remember that if you want to
+ // display the text at the exact Y coordinate, that you should add
+ // the value of the font's ascent. You can get the ascent by calling
+ // GetAscent() on the font in question. I'm going to use the same
+ // Y value of 10 just to show you the slight difference using GetAscent makes.
+ g->SetColor(Color(55, 90, 255));
+ // We already set the font, no need to set it again unless we want a new one
+ g->DrawString(_S("I like Techno and Drum n' Bass"), 170, 10 + mApp->mTextFont->GetAscent());
+
+ // And to help you out visually, let's draw a line at Y coordinate 10:
+ g->SetColor(Color(255, 255, 255));
+ g->DrawLine(0, 10, mWidth, 10);
+
+ // Just for fun, let's change the font. This font, as you can see from its image,
+ // only contains digits and a few symbols. As an example, I will draw a string
+ // containing only those characters as well as a string containing characters that
+ // the font can't represent to show you what would happen.
+ g->SetFont(mApp->mNumberFont);
+ g->SetColor(Color(255, 255, 0));
+ g->DrawString(_S("+200"), 10, 40);
+ g->DrawString(_S("+200 pts"), 10, 60);
+
+ // You can also get the width of a string in pixels for any given font. In addition, you
+ // can use a printf style function, StrFormat, which is defined in Common.h, to
+ // format strings. You might want to look at Common.h for some...common...and handy functions.
+ g->SetColor(Color(0, 255, 255));
+ SexyString myString = StrFormat(_S("You got %d points!"), 147);
+ g->SetFont(mApp->mTextFont);
+ g->DrawString(myString, 10, 80);
+ g->SetColor(Color(0, 255, 0));
+ g->DrawString(_S(" I am to the right of that previous string."), 10 + mApp->mTextFont->StringWidth(myString), 80);
+
+
+ // What about some other common text functions, like justifying and word wrapping?
+ // Not a problem. The Widget class contains some useful features.
+ // For justification, the easiest is to use the WriteString method.
+ // The valid justification values are:
+ // -1: Left justified (same as DrawString)
+ // 0: Centered
+ // 1: Right justified
+ //
+ // For centered/right justified, you can also specify a width indicating the size of the region you
+ // are printing in. The sole purpose of that is to control the centering/right aligning.
+ g->SetColor(Color(255, 255, 255));
+ WriteString(g, _S("Left justified at X of 200"), 200, 95, -1, -1);
+ WriteString(g, _S("Centered using app width"), 0, 110, mWidth, 0);
+ WriteString(g, _S("Centered using width of 200, X of 200"), 200, 125, 200, 0);
+
+ // And now for a word wrapping example. With this function, you specify a rectangular region
+ // that represents the "box" in which you want the text to be displayed. You can also
+ // set the line spacing, or use -1 for the default font height, and you can also set
+ // the justification using the same values as for WriteString. We'll also draw the "box" using
+ // the DrawRect function, for illustrative purposes. You may notice that I didn't offset the
+ // Y coordinate of the text by the font's ascent: that's because WriteWordWrapped automatically
+ // does that for you.
+ g->SetColor(Color(255, 255, 255));
+ g->DrawRect(30, 140, 200, 400);
+ g->SetColor(Color(0, 255, 0));
+ WriteWordWrapped(g, Rect(30, 140, 200, 400), _S("This is some text that is wrapped inside of the rectangle \
+ at X of 30, Y of 140, width of 200, height of 400. It has \
+ been wrapped using the default left justification and the \
+ default line spacing."), -1, -1);
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Enough talk, let's draw images!
+ // The simplest way to draw an image is with, coincidentally, the DrawImage method.
+ // Just specify the image and the X, Y to draw at and boom! It's done.
+ g->DrawImage(mApp->mTurbotImg, 230, 140);
+
+ // What about changing the color of an image? This is called colorization, and it works just like
+ // all the previous examples: You call SetColor with the color you want. But wait! There's
+ // an extra step: Because colorizing an image on the fly is slower than normal drawing, you have
+ // to explicity tell the graphics object that you want to enable it. This is done by calling the
+ // SetColorizeImages method of the Graphics class with a parameter value of "true".
+ // IMPORTANT: You should call SetColorizeImages again but with a parameter of "false" when you
+ // are done drawing your colorized image! Otherwise all subsequent image drawing calls will
+ // be colorized using the most recent value from SetColor. You may call SetColor either before
+ // or after SetColorizeImages, it doesn't matter. For this example, we'll draw an image normally
+ // and then colorized. We'll also use the GetHeight() method to draw this image just below the
+ // previous one.
+ g->DrawImage(mApp->mOpaqueBeamImg, 230, 140 + mApp->mTurbotImg->GetHeight());
+
+ g->SetColor(Color(255, 0, 0));
+ g->SetColorizeImages(true);
+ g->DrawImage(mApp->mOpaqueBeamImg, 230 + mApp->mOpaqueBeamImg->GetWidth(), 140 + mApp->mTurbotImg->GetHeight());
+ g->SetColorizeImages(false);
+
+ // You may have noticed that part of the previous two images was drawn offscreen. The graphics object by
+ // default sets a clipping region to the size of the widget, and anything drawn outside of it
+ // is clipped, or not drawn. You'll see some more advanced uses of clipping and widgets in a later demo.
+
+ // There's another cool effect you can do to images: Drawing additively instead of normally.
+ // Additive drawing is just what the name implies: when you draw the image, instead of
+ // drawing using the exact RGBA values of the image, it actually combines them with whatever
+ // pixel values there are in the location in which it is placed. One common use of this is
+ // to draw the same image, but brighter: To do so, you'd just draw the image normally first,
+ // then draw the same image on top of it but additively. Let's try an example and draw
+ // our first image, mApp->mTurbotImg, additively to get a bright effect.
+ g->DrawImage(mApp->mTurbotImg, 230 + mApp->mTurbotImg->GetWidth(), 140);
+
+ // Enable additive drawing with the call below. IMPORTANT: You should set the
+ // drawmode back to Graphics::DRAWMODE_NORMAL when done, so that other images
+ // don't get drawn additively. Additive drawing is slower than colorization,
+ // so keep that in mind if you are concerned about your game's performance.
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->DrawImage(mApp->mTurbotImg, 230 + mApp->mTurbotImg->GetWidth(), 140);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+
+ // You can even draw an image colorized and additively. This is comonly used to
+ // implement a pulsing sort of effect. Let's do just that: the variable,
+ // mPulseAmt, is updated in our Update method and controls the RGB value
+ // that we'll use to make our image pulse. Again, be sure to set things back
+ // to normal when you are done. Also, it matters not in which order the
+ // SetDrawMode, SetColor, and SetColorizeImages calls are made.
+ g->DrawImage(mApp->mTurbotImg, 230 + mApp->mTurbotImg->GetWidth() * 2, 140);
+
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColor(Color(mPulseAmt, mPulseAmt, mPulseAmt));
+ g->SetColorizeImages(true);
+ g->DrawImage(mApp->mTurbotImg, 230 + mApp->mTurbotImg->GetWidth() * 2, 140);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ g->SetColorizeImages(false);
+
+ // And finally, let's just have a simple example of alpha blending. We'll
+ // Draw our first image, a picture of a moon, normally, and draw
+ // our friend Turbot at reduced opacity on top of it. The result is you can
+ // see through turbot to the moon below. Notice that we set the color
+ // for turbot to r=255, g=255, b=255, alpha=128: This results in the
+ // RGB values not being changed, only the alpha. Using a value of 255 for
+ // a colorization amount basically means that the color component will not
+ // be altered.
+ g->DrawImage(mApp->mMoonImg, 400, 300);
+ g->SetColor(Color(255, 255, 255, 60));
+ g->SetColorizeImages(true);
+ g->DrawImage(mApp->mTurbotImg, 400, 300);
+ g->SetColorizeImages(false);
+
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo2/Board.h b/osframework/source/demos/Demo2/Board.h
new file mode 100644
index 0000000..04d84cd
--- /dev/null
+++ b/osframework/source/demos/Demo2/Board.h
@@ -0,0 +1,108 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+// This file must be included so that we can derive our Board class from it
+#include "SexyAppFramework/Widget.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+
+// Forward declare the graphics class. You will see the graphics class used
+// and explained in Board.cpp: it is the main object used to draw all
+// images, fonts, etc.
+class Graphics;
+
+// We maintain a pointer to the main game application in the Board class.
+// The main game app contains functions that are often times needed
+// by the Board class, such as registry reading/writing, file reading/writing,
+// etc.
+class GameApp;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget
+{
+
+ private:
+
+ GameApp* mApp;
+ int mPulseAmt; // See Draw(): used to make an image pulse over time
+ bool mIncPulse; // If true, then we're increasing the pulse value, otherwise, decreasing
+
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo2/Demo2 VS2005 WideString.vcproj b/osframework/source/demos/Demo2/Demo2 VS2005 WideString.vcproj
new file mode 100644
index 0000000..945028a
--- /dev/null
+++ b/osframework/source/demos/Demo2/Demo2 VS2005 WideString.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo2"
+ ProjectGUID="{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo2_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo2.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo2.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo2.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo2_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo2/Demo2 VS2005.vcproj b/osframework/source/demos/Demo2/Demo2 VS2005.vcproj
new file mode 100644
index 0000000..9944517
--- /dev/null
+++ b/osframework/source/demos/Demo2/Demo2 VS2005.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo2"
+ ProjectGUID="{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo2_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo2.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo2.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo2.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo2_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo2/Demo2 WideString.vcproj b/osframework/source/demos/Demo2/Demo2 WideString.vcproj
new file mode 100644
index 0000000..42e76ec
--- /dev/null
+++ b/osframework/source/demos/Demo2/Demo2 WideString.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo2"
+ ProjectGUID="{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo2_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo2.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo2.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo2.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo2_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo2/Demo2.dsp b/osframework/source/demos/Demo2/Demo2.dsp
new file mode 100644
index 0000000..67ce42b
--- /dev/null
+++ b/osframework/source/demos/Demo2/Demo2.dsp
@@ -0,0 +1,125 @@
+# Microsoft Developer Studio Project File - Name="Demo2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo2 - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Demo2.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Demo2.mak" CFG="Demo2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Demo2 - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo2 - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Demo2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Demo2___Win32_Release"
+# PROP BASE Intermediate_Dir "Demo2___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Demo2.exe"
+
+!ELSEIF "$(CFG)" == "Demo2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Demo2___Win32_Debug"
+# PROP BASE Intermediate_Dir "Demo2___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /map /debug /machine:I386 /out:"..\Demo2_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Demo2 - Win32 Release"
+# Name "Demo2 - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Demo2/Demo2.vcproj b/osframework/source/demos/Demo2/Demo2.vcproj
new file mode 100644
index 0000000..a85e4ce
--- /dev/null
+++ b/osframework/source/demos/Demo2/Demo2.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo2"
+ ProjectGUID="{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo2_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo2.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo2.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo2.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo2_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo2/GameApp.cpp b/osframework/source/demos/Demo2/GameApp.cpp
new file mode 100644
index 0000000..5b8ca83
--- /dev/null
+++ b/osframework/source/demos/Demo2/GameApp.cpp
@@ -0,0 +1,306 @@
+#include "GameApp.h"
+#include "Board.h"
+#include "SexyAppFramework/WidgetManager.h"
+
+// Why are we including ImageFont.h and not Font.h? Font.h is just a generic
+// base class. ImageFont creates fonts from an image that contains all the
+// text characters as well as a text file that indicates character widths
+// and kerning information, as well as some more advanced features not used
+// in this tutorial such as font layers, etc.
+#include "SexyAppFramework/ImageFont.h"
+
+// The Image.h file just declares basic functions. All images are either of
+// the DDImage or MemoryImage type. For this demo, we will use DDImage
+// types, as they are the type returned by the image loading code.
+// A DDImage is actually derived from MemoryImage, so where an Image or
+// MemoryImage is required, a DDImage will suffice as well. A DDImage
+// contains optimized code for use with DirectX 7+.
+#include "SexyAppFramework/DDImage.h"
+
+// This will let us load sounds
+#include "SexyAppFramework/SoundManager.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ // mProdName is used for internal purposes to indicate the game that we're working on
+ mProdName = "Demo 2";
+
+ // For internal uses, indicates the current product version
+ mProductVersion = "1.0";
+
+ // This is the text that appears in the title bar of the application window
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+
+ // Indicates the registry location where all registry keys will be read from
+ // and written to. This is stored under the HKEY_CURRENT_USER tree on
+ // Windows systems.
+ mRegKey = "PopCap\\SexyAppFramework\\Demo2";
+
+ // Set the application width/height in terms of pixels here. Let's
+ // use a different resolution from Demo 1 just for fun.
+ mWidth = 800;
+ mHeight = 600;
+
+ mBoard = NULL;
+
+ mTextFont = NULL;
+ mNumberFont = NULL;
+ mTurbotImg = NULL;
+ mMoonImg = NULL;
+ mOpaqueBeamImg = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ // Remove our "Board" class which was, in this particular demo,
+ // responsible for all our game drawing and updating.
+ // All widgets MUST be removed from the widget manager before deletion.
+ // More information on the basics of widgets can be found in the Board
+ // class file. If you tried to delete the Board widget before removing
+ // it, you will get an assert.
+ mWidgetManager->RemoveWidget(mBoard);
+ delete mBoard;
+
+ // We need to clean up after ourselves and delete the image and
+ // font information.
+ delete mTextFont;
+ delete mNumberFont;
+ delete mTurbotImg;
+ delete mMoonImg;
+ delete mOpaqueBeamImg;
+
+ // We need to release the memory allocated to our sounds too.
+ // This call frees up the memory for ALL sound effects.
+ mSoundManager->ReleaseSounds();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+ // Let the parent class perform any needed initializations first.
+ // This should always be done.
+ SexyAppBase::Init();
+
+ // In later demos, you will see more done with this function.
+ // For now, we have nothing else to initialize, so we are done.
+ // Once complete, the LoadingThreadProc function will automatically
+ // start and we will begin loading all our needed resources.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+ // This time, we have things to load. Let's load in our two fonts
+ // and our three images.
+ // Besides loading data,
+ // this thread can also update the progress indicator for the loading
+ // screen, which you will see in later demos.
+ // Once complete, the LoadingThreadCompleted function will be called.
+
+ // Loading images is easy: you don't have to specify the image type.
+ // Depending on the file extension, the appropriate image decoder
+ // will be used. The following image types are supported:
+ // Targa (.tga), JPEG (.jpg), PNG (.png), GIF (.gif). You do NOT have
+ // to specify the extension when loading the file if you don't want to.
+ // In this case, all of the above extensions will be looked for.
+ // A discussion of image formats is beyond the scope of this tutorial.
+ // There is some important information to know about images.
+ // You will notice in the "images" directory that for each image,
+ // there is a black and white image with the same name but with
+ // an underscore ("_") at the end of it. By default, when you load
+ // and image, the code automatically looks for the presence of
+ // that file to use for the alpha information. Some file formats
+ // have the alpha channel built into them, like PNG files. But
+ // others, like JPEG or GIF files, do not. The purpose of the alpha
+ // file is of course to generate an image that doesn't have jagged
+ // lines, or to control the opacity of various parts of the image.
+ // As a side not, the alpha image file may also begin with the
+ // underscore instead of ending with it, it matters not, and again,
+ // is automatically loaded in by the image loading code.
+ // You need to clean up the memory allocated by these functions yourself.
+ mOpaqueBeamImg = (DDImage*) GetImage("images/beam_opaque");
+
+ // If the file was not found or couldn't be loaded (i.e. due to an
+ // incompatible file format) the returned value will be NULL.
+ // You should always check this, and if it occurs, display an error
+ // message, then set mLoadingFailed to true, and then immediately return.
+ if (mOpaqueBeamImg == NULL)
+ {
+
+ // The PopUp method displays a standard Windows message box.
+ // If in full screen mode, this will appropriately handle things such
+ // that the GDI surface is properly rendered and the dialog box appears
+ // as expected.
+ Popup("There was an error loading the file: images/beam_opaque");
+ mLoadingFailed = true;
+
+ return;
+ }
+
+ // Now load the other two images
+ mMoonImg = (DDImage*) GetImage("images/moon");
+ if (mMoonImg == NULL)
+ {
+ Popup("There was an error loading the file: images/moon");
+ mLoadingFailed = true;
+ return;
+ }
+
+ mTurbotImg = (DDImage*) GetImage("images/turbot_worry");
+ if (mTurbotImg == NULL)
+ {
+ Popup("There was an error loading the file: images/turbot_worry");
+ mLoadingFailed = true;
+ return;
+ }
+
+ // So we've loaded the images, that's all there is right? Wrong.
+ // If possible, we should try to palletize the images. An image that
+ // contains 255 or fewer colors can be palletized. This results in
+ // a memory savings of about 4x and doesn't affect the image quality
+ // at all. It's the same principals that the GIF format uses: instead
+ // of representing each red, green, blue, alpha value as a separate
+ // quantity (1 byte each, 4 bytes in total per pixel), we represent
+ // the actual combined RGBA value as a single number, from 0-255.
+ // This number is an index into a lookup table. Thus, every time
+ // the value (200,43,11,128), for example, is used, instead of
+ // representing that value as a 4 byte value every time it
+ // appears, we'd represent it with a 1 byte index into a lookup
+ // table that contained the above RGBA value. Don't worry, you
+ // don't have to really know or care about any of that if you
+ // didn't understand it. What you need to know is that by calling the
+ // Palletize() method on an image, you potentially can reduce the
+ // amount of RAM it consumes by 4 times. The Palletize method
+ // returns a boolean indicating if it could or couldn't be palletized.
+ ((DDImage*)mOpaqueBeamImg)->Palletize();
+ ((DDImage*)mMoonImg)->Palletize();
+ ((DDImage*)mTurbotImg)->Palletize();
+
+ // Now let's load and create some fonts. A font consists of an
+ // image and a text file. The image works on the same principles
+ // as a normal image file (like the ones above) works on. Except
+ // that with fonts, there is only 1 image, the alpha image.
+ // Thus, you will see in the "fonts" directory two images that
+ // begin with the underscore prefix. If there isn't a file
+ // of the same name without an underscore, then it is assumed that
+ // the file is of the same dimensions as the underscore file and that
+ // it is to be all white and fully opaque. This is done with fonts because
+ // it's common to want to change the color of the font, and to change
+ // the color, the base, original image color, should be white and
+ // fully opaque. More information on colorizing fonts and images can
+ // be found in Board.cpp, but for now know that the image in the fonts
+ // directory contains the alpha information for your font, and that it
+ // is assumed that the "main" image is pure white.
+ // The other file in the directory is a text file, commonly with the
+ // same name as the image, but without the underscore character, but
+ // not always. The file will define the name of the image to load.
+ // This file defines the characters, their widths, their offsets
+ // within the image, the point size, and any layers (which are not
+ // used or discussed in this demo). This is the data file and is
+ // how the font knows how to take a string and convert it into
+ // the proper images representing each character. A font is really
+ // just an image but with an extra data file that tells the program
+ // how to map strings to their image representation.
+ // You load a font by specifying the text data file.
+ mTextFont = new ImageFont(this, "fonts/Kiloton9.txt");
+
+ // We need to check to see if the font was properly initialized.
+ // If it wasn't, then an error occurred and we need to abort.
+ if (!mTextFont->mFontData->mInitialized)
+ {
+ delete mTextFont;
+ Popup("There was an error loading fonts/Kiloton9.txt");
+ mLoadingFailed = true;
+ return;
+ }
+
+ mNumberFont = new ImageFont(this, "fonts/supernova20.txt");
+ if (!mNumberFont->mFontData->mInitialized)
+ {
+ delete mNumberFont;
+ Popup("There was an error loading fonts/supernova20.txt");
+ mLoadingFailed = true;
+ return;
+ }
+
+ // Let's load some sounds. You assign a unique unsigned integer ID to each
+ // sound. It is with this ID that you indicate which sound you
+ // want to play. Valid types of sounds to load are:
+ // WAV, OGG, AU, and if you have FMod and enable FMod: MP3. Although
+ // you should probably not use MP3 due to patent/copyright issues
+ // unless of course that either doesn't bother you or you happen
+ // to have the legal right to do so. Like images, you don't have
+ // to specify the file extension. LoadSound returns a boolean
+ // indicating success or failure.
+ if (!mSoundManager->LoadSound(1, "sounds/timer"))
+ {
+ Popup("There was an error loading sounds/timer");
+ mLoadingFailed = true;
+ return;
+ }
+
+ if (!mSoundManager->LoadSound(2, "sounds/mutator"))
+ {
+ Popup("There was an error loading sounds/mutator");
+ mLoadingFailed = true;
+ return;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ // When we're actually loading resources, we'll set the
+ // mLoadingFailed variable to "true" if there were any problems
+ // encountered along the way. If that is the case, just return
+ // because we won't want the user to get to the main menu or any
+ // other part of the game. We will want them to exit out.
+ if (mLoadingFailed)
+ return;
+
+ // Now that we're done loading everything we need (which wasn't
+ // anything in this particular demo), we need to get the main
+ // game screen up and running: That is our "Board" class, and
+ // it will handle all the drawing, updating, and input processing
+ // for most of the game.
+ mBoard = new Board(this);
+
+ // This is a very important step: Because the Board class is a widget
+ // (see Board.h/.cpp for more details) we need to tell it what
+ // dimensions it has and where to place it.
+ // By default a widget is invisible because its
+ // width/height are 0, 0. Since the Board class is our main
+ // drawing area and game logic class, we want to make it the
+ // same size as the application. For this particular demo, that means
+ // 800x600. We will use mWidth and mHeight though, as those were
+ // already set to the proper resolution in GameApp::Init().
+ mBoard->Resize(0, 0, mWidth, mHeight);
+
+ // Also an important step is to add the newly created Board widget to
+ // the widget manager so that it will automatically have its update, draw,
+ // and input processing methods called.
+ mWidgetManager->AddWidget(mBoard);
+
+ // And just to test out our sound playing abilities, let's play the
+ // mutator sound to indicate that we're done loading.
+ // We do that by calling GameApp's PlaySample()
+ // method and specifying the integral ID of the sound to play. This
+ // ID is the same as we used when loading the sound in GameApp::LoadingThreadProc()
+ PlaySample(2);
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo2/GameApp.h b/osframework/source/demos/Demo2/GameApp.h
new file mode 100644
index 0000000..7a60300
--- /dev/null
+++ b/osframework/source/demos/Demo2/GameApp.h
@@ -0,0 +1,105 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+ // The GameApp class will be responsible for creating a class by the name
+ // of "Board", which we will use to do all the game's drawing, input processing,
+ // etc. Board is the second most important class and is where almost all of your
+ // game logic code will originate from. It is a widget, which allows for
+ // easy and automatic invocation of its update, drawing, and input processing
+ // functions. See the "Board" class for more details.
+ class Board;
+
+ // Alright, fonts and images! You'll learn more about these in GameApp.cpp
+ // so check there for more info.
+ class ImageFont;
+ class Image;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+
+ public:
+
+ // These are the fonts and images we'll be using for this demo. See
+ // GameApp.cpp for full information on fonts and images. We're going to
+ // make them public for easy accessing, since the point of this tutorial
+ // is to quickly get you up to speed on using the framework.
+ ImageFont* mTextFont;
+ ImageFont* mNumberFont;
+ Image* mOpaqueBeamImg;
+ Image* mMoonImg;
+ Image* mTurbotImg;
+
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo2/main.cpp b/osframework/source/demos/Demo2/main.cpp
new file mode 100644
index 0000000..36f0c9e
--- /dev/null
+++ b/osframework/source/demos/Demo2/main.cpp
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Loading and displaying fonts
+// * Loading and displaying images
+// * Colorizing images
+// * Additive drawing
+// * Palletizing images to use less RAM (when possible)
+// * Loading/playing sounds
+// * Widget introduction: buttons, listeners, events, adding/removing
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+ // Make sure to set this. Some classes, like the exception handler and custom cursors
+ // will need to use it.
+ gHInstance = hInstance;
+
+ // Create and initialize our game application.
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+
+ // Starts the entire application: sets up the resource loading thread and
+ // custom cursor thread, and enters the game loop where the application
+ // will remain until it is shut down. You will most likely not need to
+ // override this function.
+ anApp->Start();
+
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Demo3/Board.cpp b/osframework/source/demos/Demo3/Board.cpp
new file mode 100644
index 0000000..e4c868f
--- /dev/null
+++ b/osframework/source/demos/Demo3/Board.cpp
@@ -0,0 +1,389 @@
+#include "Board.h"
+#include "GameApp.h"
+#include "SexyAppFramework/Graphics.h"
+
+// See the Draw method for more information on using the Color class.
+#include "SexyAppFramework/Color.h"
+
+// The Image.h file just declares basic functions. All images are either of
+// the DDImage or MemoryImage type. For this demo, we will use DDImage
+// types, as they are the type returned by the image loading code.
+// A DDImage is actually derived from MemoryImage, so where an Image or
+// MemoryImage is required, a DDImage will suffice as well. A DDImage
+// contains optimized code for use with DirectX 7+.
+#include "SexyAppFramework/DDImage.h"
+
+// The Rectangle template, used to specify X, Y, Width, Height
+#include "SexyAppFramework/Rect.h"
+
+// We're going to be making a button in this demo so we need to
+// include this file.
+#include "SexyAppFramework/ButtonWidget.h"
+
+// We're going to add our own button widget, which requires knowing about the
+// WidgetManager.
+#include "SexyAppFramework/WidgetManager.h"
+
+#include "SexyAppFramework/ImageFont.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+
+ // Start off drawing the first frame of mLightningImg
+ mAnimFrame = 0;
+
+ mButton = NULL;
+
+ mMouseX = mMouseY = 0;
+ mLeftDown = mRightDown = mMiddleDown = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+ delete mButton;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+ // Let the parent class update as well. This will increment
+ // the variable mUpdateCnt which is an integer that indicates
+ // how many times the Update() method has been called. Since our
+ // Board class is updated 100 times per second, this variable will
+ // increment 100 times per second. As you will see in later demos,
+ // we will use this variable for animation since its value represents
+ // hundredths of a second, which is for almost all games a good
+ // enough timer value and doesn't rely on the system clock function
+ // call.
+ Widget::Update();
+
+ // Let's update our animation frame every 5 update ticks. This
+ // is equivalent to 20 times per second.
+ if (mUpdateCnt % 5 == 0)
+ {
+ // In GameApp we specified how many rows and columns this image
+ // had. Thus, if our current frame of animation exceeds the number
+ // of frames that we have, we should reset the animation frame back
+ // to 0.
+ if (++mAnimFrame >= mApp->mLightningImg->mNumRows)
+ mAnimFrame = 0;
+ }
+
+
+
+ // For this and most of the other demos, you will see the function
+ // below called every Update() call. MarkDirty() tells the widget
+ // manager that something has changed graphically in the widget and
+ // that it needs to be repainted. All widgets follow this convention.
+ // In general, if you don't need
+ // to update your drawing every time you call the Update method
+ // (the most common case is when the game is paused) you should
+ // NOT mark dirty. Why? If you aren't marking dirty every frame,
+ // then you aren't drawing every frame and thus you use less CPU
+ // time. Because people like to multitask, or they may be on a laptop
+ // with limited battery life, using less CPU time lets people do
+ // other things besides play your game. Of course, everyone
+ // will want to play your game at all times, but it's good to be
+ // nice to those rare people that might want to read email or
+ // do other things at the same time.
+ // In this particular demo, we
+ // won't be nice, as the purpose is to bring you up to speed as
+ // quickly as possible, and so we'll dispense with optimizations
+ // for now, so you can concentrate on other core issues first.
+ // In general, this is the last method called in the Update
+ // function, but that is not necessary. In fact, the MarkDirty
+ // function can be called anywhere, in any method (although
+ // calling it in the Draw method doesn't make sense since it is
+ // already drawing) and even multiple times. Calling it multiple
+ // times does not do anything: only the first call makes a difference.
+ MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ // The Graphics object, "g", is
+ // automatically created and passed to this method by the
+ // WidgetManager and can be thought of as the main screen
+ // bitmap/canvas upon which all drawing will be done. This object
+ // is double buffered automatically so you don't need to worry
+ // about those details. All you need to do is instruct the object
+ // that you would like to draw something to it, and when the
+ // WidgetManager gets done letting all widgets draw to the
+ // Graphics object, it will then blit everything to the screen
+ // at once.
+
+ // First, let's start by clearing the screen to black.
+ // As you'll recall from Demo1, we set the color with SetColor
+ // and pass in a Color object that contains either 3 or 4 parameters,
+ // that represent the r,g,b,a values (alpha is 255 if only 3 specified).
+ g->SetColor(Color(0, 0, 0));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Now let's try drawing a stretched image. We'll draw the original image
+ // stretched to twice its size. Drawing a stretched image is exactly like
+ // drawing a normal image, except that you have two extra parameters:
+ // the stretched width and height. You can use this to draw a shrunk version
+ // of the image as well (which we'll do second)
+ g->DrawImage(mApp->mTurbotImg, 0, 0, mApp->mTurbotImg->GetWidth() * 2, mApp->mTurbotImg->GetHeight() * 2);
+ g->DrawImage(mApp->mTurbotImg, 0, 275, mApp->mTurbotImg->GetWidth() / 2, mApp->mTurbotImg->GetHeight() / 2);
+
+ // The default stretching algorithm (the one used in the two examples above) uses
+ // the slow stretching method. The slow stretching method anti-aliases the resulting
+ // image to give a smoother, less pixelated look. While this tends to look a lot
+ // nicer, it also requires more processing power. Thus, if you either don't need
+ // or don't care about the anti-aliasing, you can instruct the graphics object
+ // to use fast stretching. Just remember: unless you turn fast stretching off when
+ // done, it will remain on. Let's give it a try by drawing the same image
+ // stretched twice as large using fast stretching.
+ g->SetFastStretch(true);
+ g->DrawImage(mApp->mTurbotImg, 275, 0, mApp->mTurbotImg->GetWidth() * 2, mApp->mTurbotImg->GetHeight() * 2);
+ g->SetFastStretch(false);
+
+ // A good use of fast/non fast stretching is to enable the slower stretching method
+ // for users with a supported 3D card and to disable it for users that have
+ // to run in software mode. You'll learn more about determining if a user is in
+ // 3D mode or not in a later demo, but keep this simple optimization in mind
+ // when creating drawing code for your games.
+
+ // Another cool thing we can do is to draw an image mirrored. This is exactly
+ // like using the DrawImage command except that you use DrawImageMirror
+ // instead. The optional fourth argument is just a convenience switch: if it's false,
+ // it will draw the image normally. In 3D mode, this is just as fast as a normal draw.
+ g->DrawImageMirror(mApp->mTurbotImg, 75, 275);
+
+ // But what if you want to draw the image mirrored AND stretched? It's a little different,
+ // but still easy. The first parameter, like usual, is the image you want to draw.
+ // The second parameter is a Rect which indicates the destination region you want to draw
+ // the image to: The XY of the Rect is just what you think it is, it's the pixel coordinate
+ // the image should be drawn at. The Width, Height of the Rect however is how you accomplish
+ // the stretching/shrinking. Specify a different width/height from the original image size
+ // and you've just accomplished resizing the original image! Note that we have a third
+ // parameter, also a Rect. This is the source rectangle, and indicates the region of
+ // image you wish to draw. As you'll see in our animation example, you don't have to
+ // always draw the entire image. You can specify a rectangular region of the source image
+ // that you wish to draw, which is useful for large strips of animation (more below).
+ // For our current case, however, we want to draw the entire image. So we specify that
+ // we should draw from the top left (0,0) coordinate of the source image and we should
+ // use it's full width/height. Again, just like with DrawImage, you can use the
+ // SetFastStretch call to set whether you want the nice, slow, smooth scaling, or the quick
+ // and efficient exact scaling. In 3D mode, this is just as fast as a normal stretched draw.
+ g->DrawImageMirror(mApp->mTurbotImg,
+ Rect(200, 275, mApp->mTurbotImg->GetWidth() * 2, mApp->mTurbotImg->GetHeight() * 2),
+ Rect(0, 0, mApp->mTurbotImg->GetWidth(), mApp->mTurbotImg->GetHeight()));
+
+
+ // Remember that black and white image we made in GameApp::LoadingThreadCompleted?
+ // How about we draw it now so you can see what the result looks like:
+ g->DrawImage(mApp->mAlteredImg, 500, 0);
+
+ // And now for the exciting part: animation! As you can see in ::Update, we
+ // increment the animation frame every 5 update ticks. We don't want to use
+ // DrawImage because that will render the entire image. Instead, we only
+ // want to draw a particular cel. We do that with the DrawImageCel function,
+ // specifying the row or column to draw like so:
+ g->DrawImageCel(mApp->mLightningImg, 0, 540, mAnimFrame);
+
+ // If your animation strips contain both multiple rows AND columns,
+ // you will need to use one of the alternate forms of DrawImageCel.
+ // DrawImageCel is really just a convenience wrapper around DrawImage.
+ // As you may have seen, you can tell DrawImage to draw just a particular
+ // rectangular region of the image. Here is the equivalent function
+ // call that we could have used in place of DrawImageCel above:
+ //g->DrawImage(mApp->mLightningImg,
+ //Rect(0, 540, mApp->mLightningImg->GetWidth(), mApp->mLightningImg->GetCelHeight()),
+ //Rect(0, mApp->mLightningImg->GetCelHeight() * mAnimFrame, mApp->mLightningImg->GetWidth(), mApp->mLightningImg->GetCelHeight()));
+ //
+ // As you can see, DrawImageCel is a lot quicker to type.
+
+ // Let's also display the current mouse XY and which button(s) are held down.
+ // You should recall how to set fonts and change their colors from Demo2.
+ // You will notice that the X, Y is not updated when the cursor moves over
+ // the button that we added. This can be explained by reading the comments
+ // for the MouseMove/MouseDrag/MouseDown/MouseUp methods.
+ g->SetFont(mApp->mFont);
+ g->SetColor(Color(255, 255, 255));
+ g->DrawString(StrFormat(_S("X, Y is %d, %d"), mMouseX, mMouseY), 630, 20);
+
+ SexyString buttonStr;
+ if (mLeftDown)
+ buttonStr += _S("Left button is down. ");
+ if (mRightDown)
+ buttonStr += _S("Right button is down. ");
+ if (mMiddleDown)
+ buttonStr += _S("Middle button is down. ");
+
+ WriteWordWrapped(g, Rect(630, 40, mWidth - 630, 300), buttonStr, -1, -1);
+
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddedToManager(WidgetManager* theWidgetManager)
+{
+ // At this point, the Board class has already been added to the
+ // widget manager. We should call our parent class' method
+ // so that it can be sure to perform any needed tasks, first.
+ Widget::AddedToManager(theWidgetManager);
+
+ // Now let's create our first widget: a button. We do that by
+ // telling the button what integer ID it should be identified with,
+ // and by passing it a pointer to a button listener. Widgets have
+ // "listeners" which respond to their particular events. Any class
+ // can be a listener. For this particular demo, it is convenient for the
+ // Board class to be the listener, but it is also common to use GameApp
+ // as the main listener for all application buttons. The choice is up
+ // to you and your needs.
+ mButton = new ButtonWidget(1, this);
+
+ // Remember how we had to position and size the Board class when we first
+ // created it? A button is no different, it too is a widget. Let's
+ // place this button on screen and set it's size now:
+ mButton->Resize(675, 500, 100, 50);
+
+ // Because a button can have a label on it, we should set the font to use:
+ mButton->SetFont(mApp->mFont);
+
+ // And just what should that label be? How about the word "Off".
+ // We'll make it so that when it's clicked, it changes to "On" and
+ // back to "Off" again.
+ mButton->mLabel = _S("Off");
+
+ // We can also change some colors, like the label color and the color
+ // the label gets when moused over using the constants below:
+ mButton->SetColor(ButtonWidget::COLOR_LABEL, Color(0, 0, 0));
+ mButton->SetColor(ButtonWidget::COLOR_LABEL_HILITE, Color(0, 255, 0));
+
+ // And finally, just like with the Board class, we have to add it
+ // if we want to do anything with it.
+ theWidgetManager->AddWidget(mButton);
+
+ // If you want, you can also control the placement of the button.
+ // You can put it in front of another widget, behind another widget,
+ // at the top of the drawing order, or at the bottom of the
+ // drawing order. You accomplish that with the WidgetManager's
+ // PutInFront, PutBehind, BringToFront, BringToBack methods, respectively.
+
+ // But wait, what does this button look like? If you don't specify an
+ // image to use, the default Windows widget look will be used. We'll cover
+ // images and widgets in a later demo.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ // This is called after we've been removed from the widget manager.
+ // Again, we should let our base class do anything it needs to, first.
+ Widget::RemovedFromManager(theWidgetManager);
+
+ // We should now also remove any widgets we are responsible for. In
+ // our current case, we made a button in AddedToManager. Let's remove
+ // it now:
+ theWidgetManager->RemoveWidget(mButton);
+
+ // We'll delete it in our destructor.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::ButtonDepress(int theId)
+{
+ // Because we told our button that we, the Board class, are
+ // going to listen for its particular events, this method will
+ // thus be called when our button has any events it wants us
+ // to know about. In our current case, we only want to know when
+ // the button is clicked, but you could also respond to a few others.
+ // Let's change the label on our button whenever it is clicked, from
+ // "Off" to "On" and back again.
+ if (theId == 1)
+ {
+ // We assigned ID of 1 to our button. You'd ideally want to use
+ // a constant, but since this is a demo and there's only 1 button,
+ // we're going to just use a literal instead. When a button
+ // causes an action, it calls the appropriate listener function and
+ // let's the listener know who it is via the ID parameter.
+ if (mButton->mLabel == _S("Off"))
+ mButton->mLabel = _S("On");
+ else
+ mButton->mLabel = _S("Off");
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseMove(int x, int y)
+{
+ // This is called because the mouse cursor changed position and
+ // the Board class was the widget closest to the cursor.
+ // We're going to keep track of the XY coordinate whenever we
+ // get this message for the sake of this demo.
+ mMouseX = x;
+ mMouseY = y;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseDrag(int x, int y)
+{
+ // This is called because the mouse cursor changed position while
+ // a button was down (a drag) and
+ // the Board class was the widget closest to the cursor.
+ // We're going to keep track of the XY coordinate whenever we
+ // get this message for the sake of this demo.
+ // Note that MouseDrag is called instead of MouseMove under
+ // this condition.
+ mMouseX = x;
+ mMouseY = y;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseDown(int x, int y, int theClickCount)
+{
+ // Let the parent class know about this and perform any actions
+ // it needs to.
+ Widget::MouseDown(x, y, theClickCount);
+
+ // Let's just keep track of which button is currently held down.
+ if (theClickCount == 3)
+ mMiddleDown = true;
+ else if (theClickCount > 0)
+ mLeftDown = true;
+ else if (theClickCount < 0)
+ mRightDown = true;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseUp(int x, int y, int theClickCount)
+{
+ // Let the parent class know about this and perform any actions
+ // it needs to.
+ Widget::MouseUp(x, y, theClickCount);
+
+ //You can actually tell if the left, right,
+ // or middle buttons are currently held down by calling one of these
+ // WidgetManager methods: IsLeftButtonDown, IsRightButtonDown,
+ // IsMiddleButtonDown. However, we're going to keep track of this
+ // manually just to illustrate a point.
+ if (theClickCount == 3)
+ mMiddleDown = false;
+ else if (theClickCount > 0)
+ mLeftDown = false;
+ else if (theClickCount < 0)
+ mRightDown = false;
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo3/Board.h b/osframework/source/demos/Demo3/Board.h
new file mode 100644
index 0000000..3f582eb
--- /dev/null
+++ b/osframework/source/demos/Demo3/Board.h
@@ -0,0 +1,267 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+// This file must be included so that we can derive our Board class from it
+#include "SexyAppFramework/Widget.h"
+
+// You'll learn about responding to button events in this demo.
+// Any class that wants to respond to them must derive from ButtonListener.
+#include "SexyAppFramework/ButtonListener.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+
+// Forward declare the graphics class. You will see the graphics class used
+// and explained in Board.cpp: it is the main object used to draw all
+// images, fonts, etc.
+class Graphics;
+
+// We maintain a pointer to the main game application in the Board class.
+// The main game app contains functions that are often times needed
+// by the Board class, such as registry reading/writing, file reading/writing,
+// etc.
+class GameApp;
+
+// We're going to make a modified copy of GameApp::mTurbotImg, so we'll
+// need to forward declare the DDImage class. See Board::CreateMirroredStretchedImg.
+class DDImage;
+
+// We're going to create a button in this demo and respond to its
+// click event.
+class ButtonWidget;
+
+// In this demo, we're going to do some more advanced things like
+// handle the two cases where Board is added and removed from the
+// WidgetManager.
+class WidgetManager;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget, public ButtonListener
+{
+
+ private:
+
+ GameApp* mApp;
+ ButtonWidget* mButton; // The button that we're going to create in this demo
+ int mAnimFrame; // The current frame of animation we're on for the mLightningImg image.
+ int mMouseX, mMouseY; // As an example, we'll keep track of the mouse cursor position and display it on screen
+
+ // We'll also keep track of which button is down
+ bool mLeftDown;
+ bool mRightDown;
+ bool mMiddleDown;
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseMove
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime the
+ // mouse moves. The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored (you'll learn about how
+ // to bypass that in a later demo).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseMove(int x, int y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseDrag
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime the
+ // mouse moves AND a button is held down. This is the same thing as
+ // MouseMove except that it represents a drag operation. When dragging,
+ // MouseDrag will be called INSTEAD OF MouseMove.
+ // The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored (you'll learn about how
+ // to bypass that in a later demo).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseDrag(int x, int y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseDown
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ // theClickCount - An integer indicating which mouse button
+ // was pressed. One of the following:
+ // 1: Left button
+ // 2: Double-left-click
+ // 3: Middle button
+ // -1: Right button
+ // -2: Double-right-click
+ //
+ // IMPORTANT: Because you can't have a double click with a
+ // single click, you will receive BOTH a left (or right) button as well
+ // as a double left (or right) button message whenever you double-click.
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime
+ // a mouse button is in the down state.
+ // The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored (you'll learn about how
+ // to bypass that in a later demo).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseDown(int x, int y, int theClickCount);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseUp
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ // theClickCount - An integer indicating which mouse button
+ // was pressed. One of the following:
+ // 1: Left button
+ // 2: Double-left-click
+ // 3: Middle button
+ // -1: Right button
+ // -2: Double-right-click
+ //
+ // IMPORTANT: Because you can't have a double click with a
+ // single click, you will receive BOTH a left (or right) button as well
+ // as a double left (or right) button message whenever you double-click.
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime
+ // a mouse button is in the up state after previously being in the down state.
+ // The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored (you'll learn about how
+ // to bypass that in a later demo).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseUp(int x, int y, int theClickCount);
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo3/Demo3 VS2005 WideString.vcproj b/osframework/source/demos/Demo3/Demo3 VS2005 WideString.vcproj
new file mode 100644
index 0000000..058601e
--- /dev/null
+++ b/osframework/source/demos/Demo3/Demo3 VS2005 WideString.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo3"
+ ProjectGUID="{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo3_debug.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo3.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo3.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo3.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo3_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo3/Demo3 VS2005.vcproj b/osframework/source/demos/Demo3/Demo3 VS2005.vcproj
new file mode 100644
index 0000000..3c9a3f4
--- /dev/null
+++ b/osframework/source/demos/Demo3/Demo3 VS2005.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo3"
+ ProjectGUID="{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo3_debug.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo3.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo3.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo3.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapFileName="Demo3_release.map"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo3/Demo3 WideString.vcproj b/osframework/source/demos/Demo3/Demo3 WideString.vcproj
new file mode 100644
index 0000000..40f4dc6
--- /dev/null
+++ b/osframework/source/demos/Demo3/Demo3 WideString.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo3"
+ ProjectGUID="{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo3_debug.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo3.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo3.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo3.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo3_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo3/Demo3.dsp b/osframework/source/demos/Demo3/Demo3.dsp
new file mode 100644
index 0000000..2ed91d7
--- /dev/null
+++ b/osframework/source/demos/Demo3/Demo3.dsp
@@ -0,0 +1,125 @@
+# Microsoft Developer Studio Project File - Name="Demo3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo3 - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Demo3.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Demo3.mak" CFG="Demo3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Demo3 - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo3 - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Demo3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Demo3___Win32_Release"
+# PROP BASE Intermediate_Dir "Demo3___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Demo3.exe"
+
+!ELSEIF "$(CFG)" == "Demo3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Demo3___Win32_Debug"
+# PROP BASE Intermediate_Dir "Demo3___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /map /debug /machine:I386 /out:"..\Demo3_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Demo3 - Win32 Release"
+# Name "Demo3 - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Demo3/Demo3.vcproj b/osframework/source/demos/Demo3/Demo3.vcproj
new file mode 100644
index 0000000..925100a
--- /dev/null
+++ b/osframework/source/demos/Demo3/Demo3.vcproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo3"
+ ProjectGUID="{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo3_debug.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo3.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo3.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo3.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo3_release.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo3/GameApp.cpp b/osframework/source/demos/Demo3/GameApp.cpp
new file mode 100644
index 0000000..ef9767a
--- /dev/null
+++ b/osframework/source/demos/Demo3/GameApp.cpp
@@ -0,0 +1,301 @@
+#include "GameApp.h"
+#include "Board.h"
+#include "SexyAppFramework/WidgetManager.h"
+
+
+// The Image.h file just declares basic functions. All images are either of
+// the DDImage or MemoryImage type. For this demo, we will use DDImage
+// types, as they are the type returned by the image loading code.
+// A DDImage is actually derived from MemoryImage, so where an Image or
+// MemoryImage is required, a DDImage will suffice as well. A DDImage
+// contains optimized code for use with DirectX 7+.
+#include "SexyAppFramework/DDImage.h"
+
+// We're going to create a font for Board's button widget's label
+#include "SexyAppFramework/ImageFont.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ // mProdName is used for internal purposes to indicate the game that we're working on
+ mProdName = "Demo 3";
+
+ // For internal uses, indicates the current product version
+ mProductVersion = "1.0";
+
+ // This is the text that appears in the title bar of the application window
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+
+ // Indicates the registry location where all registry keys will be read from
+ // and written to. This is stored under the HKEY_CURRENT_USER tree on
+ // Windows systems.
+ mRegKey = "PopCap\\SexyAppFramework\\Demo3";
+
+ // Set the application width/height in terms of pixels here. Let's
+ // use a different resolution from Demo 1 just for fun.
+ mWidth = 800;
+ mHeight = 600;
+
+ // By setting this to true, the framework will automatically check to see
+ // if hardware acceleration can be turned on. This doesn't guarantee that it
+ // WILL be turned on, however. Some cards just aren't compatible or have
+ // known issues. Also, cards with less than 8MB of video RAM aren't supported.
+ // There are ways to override the 3D enabled settings, which we will discuss
+ // in a later demo. As a side note, if you want to see if you app is
+ // running with 3D acceleration, first enable debug keys by pressing
+ // CTRL-ALT-D and then press F9. To toggle 3D on/off, press F8. That is just
+ // for testing purposes.
+ //
+ // When 3D mode is on, the standard drawing routines will automatically use
+ // their hardware rendering versions, which in truns makes the game run faster.
+ // You do not need to do anything different when drawing in 2D or 3D mode.
+ // Although if 3D mode is disabled, you will most likely want to do less
+ // drawing intensive operations like additive drawing, colorization,
+ // real-time flipping/mirroring, etc.
+ mAutoEnable3D = true;
+
+ mBoard = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ // Remove our "Board" class which was, in this particular demo,
+ // responsible for all our game drawing and updating.
+ // All widgets MUST be removed from the widget manager before deletion.
+ // More information on the basics of widgets can be found in the Board
+ // class file. If you tried to delete the Board widget before removing
+ // it, you will get an assert.
+ mWidgetManager->RemoveWidget(mBoard);
+ delete mBoard;
+
+ // We need to clean up after ourselves and delete the image and
+ // font information.
+ delete mTurbotImg;
+ delete mLightningImg;
+ delete mAlteredImg;
+ delete mFont;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+ // Let the parent class perform any needed initializations first.
+ // This should always be done.
+ SexyAppBase::Init();
+
+ // In later demos, you will see more done with this function.
+ // For now, we have nothing else to initialize, so we are done.
+ // Once complete, the LoadingThreadProc function will automatically
+ // start and we will begin loading all our needed resources.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+ // This time, we have things to load. Let's load in our two fonts
+ // and our three images.
+ // Besides loading data,
+ // this thread can also update the progress indicator for the loading
+ // screen, which you will see in later demos.
+ // Once complete, the LoadingThreadCompleted function will be called.
+
+ // Loading images is easy: you don't have to specify the image type.
+ // Depending on the file extension, the appropriate image decoder
+ // will be used. The following image types are supported:
+ // Targa (.tga), JPEG (.jpg), PNG (.png), GIF (.gif). You do NOT have
+ // to specify the extension when loading the file if you don't want to.
+ // In this case, all of the above extensions will be looked for.
+ // A discussion of image formats is beyond the scope of this tutorial.
+ // There is some important information to know about images.
+ // You will notice in the "images" directory that for each image,
+ // there is a black and white image with the same name but with
+ // an underscore ("_") at the end of it. By default, when you load
+ // and image, the code automatically looks for the presence of
+ // that file to use for the alpha information. Some file formats
+ // have the alpha channel built into them, like PNG files. But
+ // others, like JPEG or GIF files, do not. The purpose of the alpha
+ // file is of course to generate an image that doesn't have jagged
+ // lines, or to control the opacity of various parts of the image.
+ // As a side not, the alpha image file may also begin with the
+ // underscore instead of ending with it, it matters not, and again,
+ // is automatically loaded in by the image loading code.
+ // You need to clean up the memory allocated by these functions yourself.
+ mTurbotImg = (DDImage*) GetImage("images/turbot_worry");
+
+ // If the file was not found or couldn't be loaded (i.e. due to an
+ // incompatible file format) the returned value will be NULL.
+ // You should always check this, and if it occurs, display an error
+ // message, then set mLoadingFailed to true, and then immediately return.
+ if (mTurbotImg == NULL)
+ {
+ mLoadingFailed = true;
+
+ // The PopUp method displays a standard Windows message box.
+ // If in full screen mode, this will appropriately handle things such
+ // that the GDI surface is properly rendered and the dialog box appears
+ // as expected.
+ Popup("There was an error loading the file: images/turbot_worry");
+
+ return;
+ }
+
+ mLightningImg = (DDImage*) GetImage("images/lightning");
+ if (mLightningImg == NULL)
+ {
+ mLoadingFailed = true;
+ Popup("There was an error loading the file: images/lightning");
+ return;
+ }
+
+ // There's something different about mLightningImg. If you look at the
+ // image in the iamges directory, you'll notice that it has multiple frames
+ // arranged in rows. This is an animation strip and is the main way that we
+ // accomplish animation. Rather than putting each frame in a separate file,
+ // we place it in one file and make each frame have the same width/height.
+ // When loading, the image loader has no idea that we even want to consider
+ // the image as being made of multiple frames. So we have to manually tell
+ // it how many rows and/or columns it has. In this case, there is only 1
+ // column, but there are 8 rows. We set this via mNumRows and mNumCols.
+ // You'll see why this is important in the Board class.
+ mLightningImg->mNumRows = 8;
+ mLightningImg->mNumCols = 1;
+
+
+ // So we've loaded the images, that's all there is right? Wrong.
+ // If possible, we should try to palletize the images. An image that
+ // contains 255 or fewer colors can be palletized. This results in
+ // a memory savings of about 4x and doesn't affect the image quality
+ // at all. It's the same principals that the GIF format uses: instead
+ // of representing each red, green, blue, alpha value as a separate
+ // quantity (1 byte each, 4 bytes in total per pixel), we represent
+ // the actual combined RGBA value as a single number, from 0-255.
+ // This number is an index into a lookup table. Thus, every time
+ // the value (200,43,11,128), for example, is used, instead of
+ // representing that value as a 4 byte value every time it
+ // appears, we'd represent it with a 1 byte index into a lookup
+ // table that contained the above RGBA value. Don't worry, you
+ // don't have to really know or care about any of that if you
+ // didn't understand it. What you need to know is that by calling the
+ // Palletize() method on an image, you potentially can reduce the
+ // amount of RAM it consumes by 4 times. The Palletize method
+ // returns a boolean indicating if it could or couldn't be palletized.
+ mLightningImg->Palletize();
+ mTurbotImg->Palletize();
+
+ // This is the same as in Demo2. Check the comments there
+ // if you've forgotten how to load and initialize a font.
+ mFont = new ImageFont(this, "fonts/Kiloton9.txt");
+
+ // We need to check to see if the font was properly initialized.
+ // If it wasn't, then an error occurred and we need to abort.
+ if (!mFont->mFontData->mInitialized)
+ {
+ delete mFont;
+ mLoadingFailed = true;
+ Popup("There was an error loading fonts/Kiloton9.txt");
+ return;
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ // When we're actually loading resources, we'll set the
+ // mLoadingFailed variable to "true" if there were any problems
+ // encountered along the way. If that is the case, just return
+ // because we won't want the user to get to the main menu or any
+ // other part of the game. We will want them to exit out.
+ if (mLoadingFailed)
+ return;
+
+ // Now that we're done loading everything we need (which wasn't
+ // anything in this particular demo), we need to get the main
+ // game screen up and running: That is our "Board" class, and
+ // it will handle all the drawing, updating, and input processing
+ // for most of the game.
+ mBoard = new Board(this);
+
+ // This is a very important step: Because the Board class is a widget
+ // (see Board.h/.cpp for more details) we need to tell it what
+ // dimensions it has and where to place it.
+ // By default a widget is invisible because its
+ // width/height are 0, 0. Since the Board class is our main
+ // drawing area and game logic class, we want to make it the
+ // same size as the application. For this particular demo, that means
+ // 800x600. We will use mWidth and mHeight though, as those were
+ // already set to the proper resolution in GameApp::Init().
+ mBoard->Resize(0, 0, mWidth, mHeight);
+
+ // Also an important step is to add the newly created Board widget to
+ // the widget manager so that it will automatically have its update, draw,
+ // and input processing methods called.
+ mWidgetManager->AddWidget(mBoard);
+
+
+ // As part of a new topic in this demo, we're also going to modify the image
+ // data for mTurbotImg and make a grayscale version of it. I'll explain
+ // each step of the way:
+
+ // 1. Let's make a copy of the image so we don't ruin the original.
+ // We should make sure to delete this when we're done.
+ mAlteredImg = (DDImage*) CopyImage(mTurbotImg);
+
+ // 2. Now we need to get the pixel data. The pixel data is stored as
+ // an unsigned long array, where each entry represents the RGBA value.
+ // The data is actually stored in ARGB format, where alpha is
+ // the leftmost byte and blue is the rightmost byte.
+ unsigned long* bits = mAlteredImg->GetBits();
+
+ // 3. Now we will loop over each pixel in the image. The size of the bits array
+ // is simply the width times the height.
+ for (int i = 0; i < mAlteredImg->GetWidth() * mAlteredImg->GetHeight(); i++)
+ {
+ // 4. Get the ARGB color value for this pixel
+ unsigned long c = bits[i];
+
+ // 5. To illustrate the ARGB storage format, we will assign each
+ // component to a variable, although we're actually only going to care
+ // about the RGB values, for this particular example. The 4 lines below
+ // extract out the individual ARGB values.
+ unsigned char alpha = (unsigned char) (c >> 24);
+ unsigned char red = (unsigned char) ((c >> 16) & 0xFF);
+ unsigned char green = (unsigned char) ((c >> 8) & 0xFF);
+ unsigned char blue = (unsigned char) (c & 0xFF);
+
+ // 6. Just like the Color class, the ARGB values are from 0-255.
+ // Let's alter these to produce a grayscale image using one of many
+ // conversion methods. This method uses 30% of the red value,
+ // 59% of the green value, and 11% of the blue value:
+ unsigned long gray = (unsigned long) ((float)red * 0.30f + (float)green * 0.59f + (float)blue * 0.11f);
+
+ // 7. Now we need to put the pixel data back into the image's data.
+ // We do the opposite of how we extracted the ARGB values above and
+ // use a left shift instead of a right shift:
+
+ // alpha red green blue
+ bits[i] = (alpha << 24) | (gray << 16) | (gray << 8) | gray;
+ }
+
+ // The image won't use this modified data until we inform it that we've
+ // done some messing around with it. We do that with the BitsChanged()
+ // function call. After that, we're all done! Pretty simple. It just
+ // depends on what you want to actually do with the RGBA data. Extracting
+ // the information and putting it back is as simple as a few shifts.
+ mAlteredImg->BitsChanged();
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo3/GameApp.h b/osframework/source/demos/Demo3/GameApp.h
new file mode 100644
index 0000000..25901e6
--- /dev/null
+++ b/osframework/source/demos/Demo3/GameApp.h
@@ -0,0 +1,108 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+ // The GameApp class will be responsible for creating a class by the name
+ // of "Board", which we will use to do all the game's drawing, input processing,
+ // etc. Board is the second most important class and is where almost all of your
+ // game logic code will originate from. It is a widget, which allows for
+ // easy and automatic invocation of its update, drawing, and input processing
+ // functions. See the "Board" class for more details.
+ class Board;
+
+ // You'll learn more about images in GameApp.cpp and Demo2,
+ // so check there for more info. You'll notice we're using DDImage instead
+ // of Image, like we did in Demo 2. That's for convenience only, so that
+ // we don't have to type cast the image every time we want to work with it.
+ class DDImage;
+
+ // We'll need a font for the label on our button (see Board for more info on buttons)
+ class ImageFont;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+
+ public:
+
+ // These are the images we'll be using for this demo. See
+ // GameApp.cpp for full information. We're going to
+ // make them public for easy accessing, since the point of this tutorial
+ // is to quickly get you up to speed on using the framework.
+ DDImage* mTurbotImg;
+ DDImage* mLightningImg;
+ DDImage* mAlteredImg; // Used in our example of modifying the image bits to make an altered version of an image.
+
+ ImageFont* mFont; // The font we'll use for the label on our button in Board
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo3/main.cpp b/osframework/source/demos/Demo3/main.cpp
new file mode 100644
index 0000000..8b33e44
--- /dev/null
+++ b/osframework/source/demos/Demo3/main.cpp
@@ -0,0 +1,45 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Automatically detecting and enabling 3D mode
+// * Modifying image data/bits
+// * Stretching images
+// * Mirroring/flipping images
+// * Animation using image strips
+// * Widgets: buttons, listeners, basic events, mouse move/down/up/drag
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+ // Make sure to set this. Some classes, like the exception handler and custom cursors
+ // will need to use it.
+ gHInstance = hInstance;
+
+ // Create and initialize our game application.
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+
+ // Starts the entire application: sets up the resource loading thread and
+ // custom cursor thread, and enters the game loop where the application
+ // will remain until it is shut down. You will most likely not need to
+ // override this function.
+ anApp->Start();
+
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Demo4/Board.cpp b/osframework/source/demos/Demo4/Board.cpp
new file mode 100644
index 0000000..477c0c4
--- /dev/null
+++ b/osframework/source/demos/Demo4/Board.cpp
@@ -0,0 +1,488 @@
+#include "Board.h"
+#include "GameApp.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+// You should remember these files from the previous demos
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Color.h"
+#include "SexyAppFramework/Rect.h"
+#include "SexyAppFramework/ButtonWidget.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ImageFont.h"
+
+// The following are needed for some new widgets we're going to learn about:
+#include "SexyAppFramework/EditWidget.h"
+#include "SexyAppFramework/Checkbox.h"
+#include "SexyAppFramework/ListWidget.h"
+#include "SexyAppFramework/ScrollbarWidget.h"
+#include "SexyAppFramework/ScrollListener.h"
+
+// As part of our pitch shifted sound example, we'll need to
+// access the sound manager in our GameApp class as well as
+// individual sound instances:
+#include "SexyAppFramework/SoundManager.h"
+#include "SexyAppFramework/SoundInstance.h"
+
+// Used for file I/O:
+#include "SexyAppFramework/Buffer.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+
+
+ mButton1 = NULL;
+ mButton2 = NULL;
+ mEditWidget = NULL;
+ mCheckboxWidget = NULL;
+ mListWidget = NULL;
+ mScrollbarWidget = NULL;
+
+ mMotionX = mUpdateFMotionX = 0;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+ delete mButton1;
+ delete mButton2;
+ delete mEditWidget;
+ delete mCheckboxWidget;
+ delete mListWidget;
+ delete mScrollbarWidget;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+
+ Widget::Update();
+
+ // As an example to illustrate the difference between smooth motion via UpdateF
+ // and the traditional motion via Update, we'll udpate the two MotionX variables
+ // separately.
+ if ((mMotionX += 5.0f) >= mWidth)
+ mMotionX = (float) -IMAGE_ROBOTROBOT->GetWidth();
+
+ MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::UpdateF(float theFrac)
+{
+ // This is very similar to Update, except that since this function
+ // gets called a different number of times depending on the refresh
+ // rate of the monitor, "theFrac" can be a variable number, and we
+ // need to multiply our normal motion change of 5.0 pixels per
+ // update by "theFrac" to get our smooth motion. See the header
+ // comment for this function in Board.h for more details.
+ if ((mUpdateFMotionX += 5.0f * theFrac) >= mWidth)
+ mUpdateFMotionX = (float) -IMAGE_ROBOTROBOT->GetWidth();
+
+ // No need to MarkDirty: We're doing it in Board::Update already.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ // Clear the screen to black
+ g->SetColor(Color(0, 0, 0));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Draw the image first using the standard method, with the coordinate
+ // updated via Board::Update as an example of non-smooth motion.
+ // Let's also print some text too.
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color(255, 255, 255));
+ g->DrawString(_S("Non smooth motion is jerky"), 10, 100);
+
+ // What's this? A new DrawImage function? Yes. Believe it. It is true.
+ // DrawImageF is just like it's best friend, DrawImage except that
+ // it takes floating point values instead of integer ones. This is
+ // slower than DrawImage, as the resulting image is anti-aliased to
+ // give the illusion of moving at sub-pixel increments. A common
+ // optimization technique at PopCap is to use DrawImageF
+ // for motion when the user has a supported 3D card and DrawImage if
+ // the user has to run in software mode.
+ g->DrawImageF(IMAGE_ROBOTROBOT, mMotionX, 120.0f);
+
+ // Now let's draw the image but using the smooth motion amounts:
+ g->DrawString(_S("Smooth motion is silky smoothness"), 10, 200);
+ g->DrawImageF(IMAGE_ROBOTROBOT, mUpdateFMotionX, 220.0f);
+
+ // Let's draw the currently selected list item:
+ g->DrawString(mText, mListWidget->mX, mListWidget->mY + mListWidget->mHeight + 20);
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddedToManager(WidgetManager* theWidgetManager)
+{
+ // At this point, the Board class has already been added to the
+ // widget manager. We should call our parent class' method
+ // so that it can be sure to perform any needed tasks, first.
+ Widget::AddedToManager(theWidgetManager);
+
+ // You should remember how to create buttons from Demo3. If not,
+ // go back and review. We're going to make two buttons which we'll use
+ // to do some sound playing when clicked.
+ mButton1 = new ButtonWidget(1, this);
+ mButton1->Resize(5, 5, 100, 50);
+ mButton1->SetFont(FONT_DEFAULT);
+ mButton1->mLabel = _S("Sound Left");
+ theWidgetManager->AddWidget(mButton1);
+
+ mButton2 = new ButtonWidget(2, this);
+ mButton2->Resize(106, 5, 100, 50);
+ mButton2->SetFont(FONT_DEFAULT);
+ mButton2->mLabel = _S("Sound Right");
+ theWidgetManager->AddWidget(mButton2);
+
+ // Let's set up our edit widget, shall we? The constructor is
+ // just like it is with all widgets that emit messages: first parameter
+ // is the ID to use, second is the class that will listen to its events.
+ // We're reusing some IDs here because an edit widget isn't a button
+ // widget and thus the IDs won't be confused. In your app however, you
+ // will most likely just want to use unique enums or numbers to assign
+ // to each specific widget.
+ mEditWidget = new EditWidget(1, this);
+
+ // We can't type in text if we don't have a font! Set one:
+ mEditWidget->SetFont(FONT_DEFAULT);
+
+ // Let's also set a maximum number of characters allowed.
+ // How about 15:
+ mEditWidget->mMaxChars = 15;
+
+ // If we wanted to emulate a password edit box, we could set
+ // mEditWidget->mPasswordChar. Any character typed in would
+ // then be visually replaced by mPasswordChar. We don't
+ // want to do that in this demo though.
+
+ mEditWidget->Resize(10, 300, 100, 15);
+ theWidgetManager->AddWidget(mEditWidget);
+
+ // Let's create a checkbox now. The checkbox widget does NOT
+ // have any default drawing methods, unlike the other widgets.
+ // You have to specify two images when creating a new one:
+ // an unchecked and a checked image. There is another option though:
+ // at PopCap it's common to place both the checked and unchecked image
+ // into one image file. Observe how we handle this mind warp:
+ mCheckboxWidget = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, 1, this);
+
+ // No way! The check AND unchecked images are the same! Yes. Indeed.
+ // But we're not done. Now, we need to tell the checkbox that
+ // it has to use a different part of the image for checked and a different
+ // part for unchecked. This is just like drawing a chunk of an image
+ // by specifying a Rect. For this particular image, the first cel
+ // contains the unchecked state and the second contains the checked one:
+ int checkWidth = IMAGE_CHECKBOX->GetWidth() / 2;
+ mCheckboxWidget->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ mCheckboxWidget->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ // Now add it and resize it
+ mCheckboxWidget->Resize(200, 300, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ theWidgetManager->AddWidget(mCheckboxWidget);
+
+ // Let's create our list box. The first parameter is the id, second
+ // is the font to use, and third is who's going to listen to its events:
+ mListWidget = new ListWidget(1, FONT_DEFAULT, this);
+
+ // This next line instructs the list box to draw an outline around itself
+ mListWidget->mDrawOutline = true;
+
+ // Now we need to set up the colors to use for the listbox. We create
+ // a 2D array containing RGB values, which we pass via SetColors.
+ // An explanation of each of the colors is below:
+ int listWidgetColors[][3] =
+ {
+ {255, 255, 255}, //Background color
+ {255, 0, 0}, //Outline color
+ {0, 0, 0}, //Plain text not hilited
+ {0, 0, 255}, //Text color when mouse is over text
+ {128, 128, 128}, //Color of the bar displayed when an item is selected
+ {190, 0, 80} //Color of the text if it has the bar behind it and mouse is not over it
+ };
+
+ // Now we set the colors, and tell it that we're setting 6 of them
+ mListWidget->SetColors(listWidgetColors, 6);
+
+ // Let's create a scrollbar for the list widget.
+ // The list widget is already a scrollbar listener, so we will
+ // specify it as the widget responsible for dealing with the
+ // scrollbar's messages.
+ mScrollbarWidget = new ScrollbarWidget(1, mListWidget);
+
+ // We also need to let the list widget know that it actually has a scrollbar.
+ // That way, it will automatically resize it as items are added/removed.
+ // IMPORTANT: You should do this before resizing the widgets.
+ mListWidget->mScrollbar = mScrollbarWidget;
+
+ // Now resize the list widget
+ mListWidget->Resize(300, 300, 100, 100);
+
+
+ // Let's resize the scrollbar to the right of the list box. Instead of using
+ // Resize(...), we use ResizeScrollbar to indicate that the entire scrollbar,
+ // arrows and thumb included, are to be evenly resized. This will appropriately
+ // scale all the items in the scrollbar.
+ mScrollbarWidget->ResizeScrollbar(mListWidget->mX + mListWidget->mWidth,
+ mListWidget->mY,
+ 25, // an arbitrary width for the bar itself
+ mListWidget->mHeight);
+
+ // Let's make the scrollbar invisible until there are enough items in the list box
+ // to make them all not fit
+ mScrollbarWidget->SetInvisIfNoScroll(true);
+
+ theWidgetManager->AddWidget(mListWidget);
+ theWidgetManager->AddWidget(mScrollbarWidget);
+
+ // If you check out Board::EditWidgetText you'll see that we write out the
+ // contents of the list box to disk every time something is added to it, or
+ // it is cleared. For files that were created from a buffer, we can read
+ // the data back into a buffer for ease of use.
+ //
+ // IMPORTANT: You can NOT load files into a buffer if they were not
+ // created from a buffer in the first place. Thus, loading a random
+ // text or binary file is not a good idea, since the buffer will
+ // have no way to identify the datatypes beyond just a standard byte.
+ // Plase read Board::EditWidgetText for an explanation of writing
+ // with buffers.
+ //
+ // Let's load in the contents of that file, if it exists,
+ // and repopulate the list box with it. The first step is to create
+ // a Buffer object. The Buffer object will contain all the data
+ // in the file:
+ Buffer buffer;
+
+ // Check if the file exists:
+ if (mApp->FileExists("list_items.dat"))
+ {
+ // Read in all the data from the file. It will be stored in a format
+ // unique to the Buffer object:
+ if (!mApp->ReadBufferFromFile("list_items.dat", &buffer))
+ {
+ // error, the file was corrupted or some other error occurred
+ mApp->Popup("Could not read contents of list_items.txt");
+ }
+
+ // In Board::EditWidgetText we wrote out all the strings
+ // via buffer.WriteString. The order in which data is written
+ // to the buffer is the order in which it is read. Thus, if
+ // you wrote out 2 integers, a string, and 10 booleans, when
+ // reading from the buffer you'd first ask for the 2 integers,
+ // then the string, then the 10 booleans. This is important:
+ // the order DOES matter. If you asked to read a string when
+ // a long was actually the next element in the file, you'd
+ // get an error. Buffers are very useful for userprofiles or
+ // data files like that where you can guarantee an explicit
+ // file format.
+
+ while (!buffer.AtEnd())
+ mListWidget->AddLine(StringToSexyStringFast(buffer.ReadString()), true);
+ }
+
+ // If you read Board::ListClicked, you'll see that we
+ // wrote the last selected item from the list box to the registry.
+ // Let's read that value in, if it exists, and set the mText
+ // variable to it so that it displays on screen. We use the
+ // RegsitryRead... functions to grab values from the regsitry.
+ // The values are assumed to be in the registry location that you
+ // set by setting the mRegKey variable in GameApp's constructor.
+ // The functions return false if there was an error reading the
+ // key or the key doesn't exist:
+ mApp->RegistryReadString("ListItem", &SexyStringToStringFast(mText));
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ // This is called after we've been removed from the widget manager.
+ // Again, we should let our base class do anything it needs to, first.
+ Widget::RemovedFromManager(theWidgetManager);
+
+ // We should now also remove any widgets we are responsible for.
+ theWidgetManager->RemoveWidget(mButton1);
+ theWidgetManager->RemoveWidget(mButton2);
+ theWidgetManager->RemoveWidget(mEditWidget);
+ theWidgetManager->RemoveWidget(mCheckboxWidget);
+ theWidgetManager->RemoveWidget(mListWidget);
+ theWidgetManager->RemoveWidget(mScrollbarWidget);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::ButtonDepress(int theId)
+{
+ if (theId == 1)
+ {
+ // Our "left" button was clicked. Let's play a sound
+ // in the left speaker with a slight pitch shift.
+ // In order to play a pitch shifted sample, we have to do more
+ // than just say "PlaySample." We have to get a pointer to the sound
+ // instance that represents our sound effect. We do that by asking the
+ // app's sound manager to return us a sound instance, and we tell it
+ // the ID of the sound file that we want. Let's do that now,
+ // using the sound "SOUND_MUTATOR" which we set up in properties/resources.xml:
+ SoundInstance* sample = mApp->mSoundManager->GetSoundInstance(SOUND_MUTATOR);
+
+ // It's good to make sure the sample isn't NULL. It would be NULL if you
+ // specified an invalid sound id.
+ if (sample != NULL)
+ {
+ //Now we actually adjust the pitch. Specify the number of
+ //steps to raise (positive) or lower (negative) the original sound by.
+ //We'll just arbitrarily choose 13.
+ sample->AdjustPitch(13);
+
+ //Let's make it play on the left speaker only. We set a panning value
+ //in decibels, which for DirectX range from -10000 to +10000, where
+ //-10000 is fully left and +10000 is fully right:
+ sample->SetPan(-10000);
+
+ // Now we have the sample play. This is again slightly different than
+ // our PlaySample from previous demos. The first parameter indicates
+ // whether or not we want the sample to loop (in this case, no), and
+ // the second indicates whether the memory taken up by this special
+ // sound instance pointer should be reclaimed when the sample is done
+ // playing. If true, then the pointer will be invalid once its
+ // done playing, sine the memory will be reclaimed. If false, the
+ // memory won't be reclaimed and you'll have to do it yourself.
+ sample->Play(false, true);
+ }
+ }
+ else if (theId == 2)
+ {
+ // Let's do the same as we did for the left button, except make it
+ // play on the right speaker and pitch shift it down
+ SoundInstance* sample = mApp->mSoundManager->GetSoundInstance(SOUND_MUTATOR);
+ if (sample != NULL)
+ {
+ sample->AdjustPitch(-5);
+ sample->SetPan(10000);
+ sample->Play(false, true);
+ }
+ }
+
+
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::EditWidgetText(int theId, const std::string& theString)
+{
+ // This is called when enter is pressed. Let's add the string
+ // to the list box and tell it to sort it alphabetically, if the string
+ // isn't blank.
+
+ if (theString.length() > 0)
+ {
+ // Let's also clear everything out of the list box if the user types
+ // in the word "CLEAR". StringToUpper is found in Common.h and returns
+ // the uppercase version of the string.
+ if (StringToUpper(theString) == "CLEAR")
+ mListWidget->RemoveAll();
+ else
+ mListWidget->AddLine(StringToSexyStringFast(theString), true);
+
+ // Now clear the edit box
+ mEditWidget->SetText(_S(""));
+
+ // As an example of saving data to files, let's write out the contents
+ // of the list box. Instead of using the C or C++ way of
+ // file I/O, we use buffers. As you'll see in a later demo,
+ // buffers are useful for the demo playback system and are a powerful
+ // feature of the framework. Plus, they make file I/O easy. The first
+ // step is to make a buffer:
+ Buffer buffer;
+
+ // And now all we do is say WriteString. There are other methods
+ // for writing other data types too:
+ for (unsigned int i = 0; i < mListWidget->mLines.size(); i++)
+ buffer.WriteString(SexyStringToStringFast(mListWidget->mLines.at(i)));
+
+ // Now we need to write the buffer to disk. GameApp can help us out with
+ // that. This data is saved in a special binary format that allows
+ // us to read the data easily back into another buffer later.
+ mApp->WriteBufferToFile("list_items.dat", &buffer);
+
+ // That's it!
+
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool Board::AllowChar(int theId, char theChar)
+{
+ // As an example of denying input, let's prevent the user
+ // from typing in the following: :-+.@#$%^&*()
+ switch (theChar)
+ {
+ case ':':
+ case '-':
+ case '+':
+ case '.':
+ case '@':
+ case '#':
+ case '$':
+ case '%':
+ case '^':
+ case '&':
+ case '*':
+ case '(':
+ case ')':
+ return false;
+
+ default:
+ return true;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::ListClicked(int theId, int theIdx, int theClickCount)
+{
+ if (theId == 1)
+ {
+ // Actually select the index. This is done to allow us to
+ // block the selection, if we chose to.
+ mListWidget->SetSelect(theIdx);
+
+ // And update the text that's displaying on screen...
+ // The strings are stored in the list widget's mLines variable
+ // and the one clicked can be indexed via theIdx.
+ mText = mListWidget->mLines[theIdx];
+
+ // As an example of writing to the registry, let's write this value
+ // and later on load it in when we restart the app. You'll notice
+ // a bunch of RegistryWrite... functions in SexyAppBase. Each one
+ // of these takes as first argument the name of the value to
+ // add to the registry. The second argument is the actual data
+ // to store in that value. The value is saved under the registry
+ // location that you set in GameApp's constructor when you
+ // set the mRegKey variable. The function returns false
+ // if there was an error, such as a lack of permission:
+ if (!mApp->RegistryWriteString("ListItem", SexyStringToStringFast(mText)))
+ mApp->Popup("Couldn't save \"ListItem\" to registry");
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/Board.h b/osframework/source/demos/Demo4/Board.h
new file mode 100644
index 0000000..6a4ce3f
--- /dev/null
+++ b/osframework/source/demos/Demo4/Board.h
@@ -0,0 +1,331 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+// Because we're going to be learning about some new widgets, we
+// need to include some more listener classes so we can respond to each one.
+#include "SexyAppFramework/EditListener.h"
+#include "SexyAppFramework/CheckboxListener.h"
+#include "SexyAppFramework/ListListener.h"
+
+
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+
+// Forward declare the graphics class. You will see the graphics class used
+// and explained in Board.cpp: it is the main object used to draw all
+// images, fonts, etc.
+class Graphics;
+
+// We maintain a pointer to the main game application in the Board class.
+// The main game app contains functions that are often times needed
+// by the Board class, such as registry reading/writing, file reading/writing,
+// etc.
+class GameApp;
+
+// forward declare the widgets we're going to use in this demo:
+class ButtonWidget;
+class EditWidget;
+class Checkbox;
+class ListWidget;
+class ScrollbarWidget;
+
+// In this demo, we're going to do some more advanced things like
+// handle the two cases where Board is added and removed from the
+// WidgetManager.
+class WidgetManager;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget, public ButtonListener,
+ public EditListener, public CheckboxListener,
+ public ListListener
+{
+
+ private:
+
+ GameApp* mApp;
+ ButtonWidget* mButton1; // We'll use these buttons for sound playing
+ ButtonWidget* mButton2;
+
+ // These are explained in the C++ code, they are the new widgets we're learning about.
+ EditWidget* mEditWidget;
+ Checkbox* mCheckboxWidget;
+ ListWidget* mListWidget;
+ ScrollbarWidget* mScrollbarWidget;
+
+ SexyString mText; // When we press enter on the edit box, we'll set this string and print it
+
+ // Both are floats to ensure that the only difference in the movement demo
+ // is the fact that one is updated in UpdateF and the other is in Update.
+ float mMotionX; // For our movement example, this is the X coordinate of the image as it moves rightward
+ float mUpdateFMotionX;// Same as above, but only modified in UpdateF, to illustrate the difference in motion
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: EditWidgetText
+ // Parameters:
+ // theId - Integer ID of the edit widget sending this message
+ // theString - The contents of the edit widget
+ //
+ // Returns: none
+ //
+ // Purpose: Called whenever the return/enter key is pressed on
+ // an edit widget.
+ //////////////////////////////////////////////////////////////////////////
+ void EditWidgetText(int theId, const std::string& theString);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AllowChar
+ // Parameters:
+ // theId - Integer ID of the edit widget sending this message
+ // theChar - Character just typed in
+ //
+ // Returns:
+ // true - Indicates that the character is acceptible
+ // false - Indicates that the character is invalid
+ //
+ // Purpose: Whenever an ASCII character is typed into the edit box,
+ // this method is called first. If the method returns true, then the
+ // character just typed is accepted and appended to the current edit widget
+ // string. If it returns false, the character is rejected and is not added.
+ //////////////////////////////////////////////////////////////////////////
+ bool AllowChar(int theId, char theChar);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CheckboxChecked
+ // Parameters:
+ // theId - Integer ID of the checkbox widget sending this message
+ // checked - Boolean indicating if the widget is checked or not
+ //
+ // Returns: none
+ //
+ // Purpose: Whenever a checkbox widget is checked or unchecked, this
+ // method is called. We're not actually going to do anything with this,
+ // we're just listing it here as an example of how you'd implement a
+ // function to respond to that event.
+ //////////////////////////////////////////////////////////////////////////
+ void CheckboxChecked(int theId, bool checked) {;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ListClicked
+ // Parameters:
+ // theId - Integer ID of the listbox widget sending this message
+ // theIdx - Integer indicating the index of the item selected in the list
+ // theClickCount - An integer indicating which mouse button
+ // was pressed. One of the following:
+ // 1: Left button
+ // 2: Double-left-click
+ // 3: Middle button
+ // -1: Right button
+ // -2: Double-right-click
+ //
+ // Returns: none
+ //
+ // Purpose: Called any time a list widget is clicked on. The list
+ // widget by default doesn't automatically select the item you clicked on,
+ // it instead calls this method and in here you manually select the item.
+ // This is to allow you to prevent the selection of certain items, such as
+ // disabled items, etc.
+ //////////////////////////////////////////////////////////////////////////
+ void ListClicked(int theId, int theIdx, int theClickCount);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: UpdateF
+ // Parameters:
+ // theFrac - The number of updates this time slice represents.
+ //
+ // Returns: none
+ //
+ // Purpose:
+ // There has been a fundamental temporal aliasing issue in the previous
+ // demos because games run at a 100 Hz Update rate while the user's monitor
+ // is refreshing at some other rate, generally between 60 and 85 Hz. The fixed
+ // 100 Hz Update rate is convenient because it allows game logic to proceed
+ // independantly from the refresh rate, but in some cases it's worth the extra
+ // trouble of updating at a variable rate in order to provide smoother animation,
+ // as in the case of a scrolling background, a shark with words written on it,
+ // or an Arkanoid ball.
+ //
+ // To illustrate the aliasing problem, imagine a ball that is supposed to move
+ // 200 pixels per second, running on a 75 Hz monitor. The update rate of the
+ // game is 100 Hz, so that means that we will add 2 pixels to the ball position
+ // every update, and there will be 1.33 updates per monitor refresh (on average).
+ // That means that that 2 out of every 3 monitor refreshes will show the ball
+ // moving 2 pixels, and and the third will show it moving 4 pixels. That isn't
+ // smooth motion. The correct solution would be for the ball to move 2.67
+ // pixels every monitor refresh. But how do we do that?
+ //
+ // To support smooth motion, we use UpdateF. Widget::UpdateF is similar to
+ // Widget::Update, but Widget::UpdateF gets a float passed into it that
+ // represents how many Update's this time slice represents. In the 75 Hz
+ // example, UpdateF would always be called with 1.33. Update has certainly
+ // not been made obsolete, however, and you can choose which
+ // parts of your game logic should be in Update and which should be in
+ // UpdateF. To facilitate cooperation and good behavior between the two
+ // update methods, there are some rules they follow: Updating always occurs
+ // in blocks, with one or two Update calls followed immediately with an
+ // UpdateF call. This means that the application will never get the chance
+ // to draw or process input between an Update and a Draw without calling
+ // UpdateF in the middle. Therefore, you can assume that focus won't be
+ // lost, nor will input change between an Update and an UpdateF, and you'll
+ // know that you'll have a chance to finalize your state in UpdateF so things
+ // can be left dangling (whatever that means for your app) after Update.
+ // You are also guaranteed that the value passed in to UpdateF will be between
+ // 1.67 (for a 60 Hz monitor) and 1.0 (for a 100 Hz monitor). Even if the
+ // monitor is 60 Hz but the computer is only fast enough to draw at 30 FPS
+ // you will get two Update blocks in a row before the draw, so it will still
+ // appear to your app as if you are updating at 60 Hz.
+ //
+ // IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
+ //
+ // In order to fully use this, you need to set up a few things.
+ // Set GameApp::mVSyncUpdates to true, override UpdateF(float theFrac),
+ // and move some code from Update that used to look like
+ // this: "mPos += 1.5;", changing it to "mPos += 1.5 * theFrac;".
+ // Check out the C++ code for an example of motion using both Update and
+ // UpdateF.
+ //
+ // IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
+ //
+ // Because UpdateF is called a variable number of times per second,
+ // you do NOT want to put game logic in it that needs to remain framerate
+ // independant. Use UpdateF ONLY for movement related operations, and not
+ // for your main game code.
+ //
+ // If you really want to avoid shearing in windowed mode, you can
+ // set GameApp::mWaitForVSync to true and set GameApp::mSoftVSyncWait
+ // to false. NOTE: This winds up doing some busy waiting and consumes
+ // more processor time.
+ // IMPORTANT: YOU MUST ALSO DELETE THE FOLLOWING REGISTRY KEY:
+ // Whereever your registry settings are stored
+ // (HKEY_LOCAL_MACHINE\SOFTWARE\SexyAppFramework\Demo4 for this case),
+ // you must delete the key "WaitForVSync". This is VERY important, and it
+ // won't work otherwise.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void UpdateF(float theFrac);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/Demo4 VS2005 WideString.vcproj b/osframework/source/demos/Demo4/Demo4 VS2005 WideString.vcproj
new file mode 100644
index 0000000..7c674c7
--- /dev/null
+++ b/osframework/source/demos/Demo4/Demo4 VS2005 WideString.vcproj
@@ -0,0 +1,251 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo4"
+ ProjectGUID="{11091E68-2497-4470-9719-8ED84CECF827}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo4_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo4.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo4.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo4.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo4/Demo4 VS2005.vcproj b/osframework/source/demos/Demo4/Demo4 VS2005.vcproj
new file mode 100644
index 0000000..50330d3
--- /dev/null
+++ b/osframework/source/demos/Demo4/Demo4 VS2005.vcproj
@@ -0,0 +1,251 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo4"
+ ProjectGUID="{11091E68-2497-4470-9719-8ED84CECF827}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo4_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo4.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo4.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo4.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo4/Demo4 WideString.vcproj b/osframework/source/demos/Demo4/Demo4 WideString.vcproj
new file mode 100644
index 0000000..47a8f04
--- /dev/null
+++ b/osframework/source/demos/Demo4/Demo4 WideString.vcproj
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo4"
+ ProjectGUID="{11091E68-2497-4470-9719-8ED84CECF827}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo4_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo4.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo4.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo4.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo4/Demo4.dsp b/osframework/source/demos/Demo4/Demo4.dsp
new file mode 100644
index 0000000..0177067
--- /dev/null
+++ b/osframework/source/demos/Demo4/Demo4.dsp
@@ -0,0 +1,136 @@
+# Microsoft Developer Studio Project File - Name="Demo4" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo4 - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Demo4.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Demo4.mak" CFG="Demo4 - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Demo4 - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo4 - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Demo4 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Demo4___Win32_Release"
+# PROP BASE Intermediate_Dir "Demo4___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Demo4.exe"
+
+!ELSEIF "$(CFG)" == "Demo4 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Demo4___Win32_Debug"
+# PROP BASE Intermediate_Dir "Demo4___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\Demo4_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Demo4 - Win32 Release"
+# Name "Demo4 - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Demo4/Demo4.vcproj b/osframework/source/demos/Demo4/Demo4.vcproj
new file mode 100644
index 0000000..bf5c38c
--- /dev/null
+++ b/osframework/source/demos/Demo4/Demo4.vcproj
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo4"
+ ProjectGUID="{11091E68-2497-4470-9719-8ED84CECF827}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo4_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo4.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo4.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo4.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo4/GameApp.cpp b/osframework/source/demos/Demo4/GameApp.cpp
new file mode 100644
index 0000000..2d8044f
--- /dev/null
+++ b/osframework/source/demos/Demo4/GameApp.cpp
@@ -0,0 +1,395 @@
+#include "GameApp.h"
+#include "TitleScreen.h"
+#include "Board.h"
+#include "SexyAppFramework/WidgetManager.h"
+
+// We will be accessing the resource manager in this demo, so include it's header
+#include "SexyAppFramework/ResourceManager.h"
+
+// Required for playing music
+#include "SexyAppFramework/BassMusicInterface.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ // mProdName is used for internal purposes to indicate the game that we're working on
+ mProdName = "Demo 4";
+
+ // For internal uses, indicates the current product version
+ mProductVersion = "1.0";
+
+ // This is the text that appears in the title bar of the application window
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+
+ // Indicates the registry location where all registry keys will be read from
+ // and written to. This is stored under the HKEY_CURRENT_USER tree on
+ // Windows systems.
+ mRegKey = "PopCap\\SexyAppFramework\\Demo4";
+
+ // Set the application width/height in terms of pixels here. Let's
+ // use a different resolution from Demo 1 just for fun.
+ mWidth = 800;
+ mHeight = 600;
+
+ // By setting this to true, the framework will automatically check to see
+ // if hardware acceleration can be turned on. This doesn't guarantee that it
+ // WILL be turned on, however. Some cards just aren't compatible or have
+ // known issues. Also, cards with less than 8MB of video RAM aren't supported.
+ // There are ways to override the 3D enabled settings, which we will discuss
+ // in a later demo. As a side note, if you want to see if you app is
+ // running with 3D acceleration, first enable debug keys by pressing
+ // CTRL-ALT-D and then press F9. To toggle 3D on/off, press F8. That is just
+ // for testing purposes.
+ mAutoEnable3D = true;
+
+ mBoard = NULL;
+ mTitleScreen = NULL;
+
+ // See Board::UpdateF for a very lengthy explanation of this and smooth motion
+ mVSyncUpdates = true;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ // Remove our "Board" class which was, in this particular demo,
+ // responsible for all our game drawing and updating.
+ // All widgets MUST be removed from the widget manager before deletion.
+ // More information on the basics of widgets can be found in the Board
+ // class file. If you tried to delete the Board widget before removing
+ // it, you will get an assert. Because our board might not have been
+ // added (if you shut down the app before closing the loading screen),
+ // only remove it if it isn't null.
+ if (mBoard != NULL)
+ mWidgetManager->RemoveWidget(mBoard);
+
+ // Take a look at TitleScreen::ButtonDepress if you haven't already.
+ // It explains a function called SafeDeleteWidget. Notice that we're
+ // directly deleting the widget here: that is because when our app's
+ // destructor is called, it's at the very end of the shutdown sequence
+ // and the safe delete widget list will NOT be processed. Thus we
+ // have to delete the memory manually.
+ delete mBoard;
+
+
+ // If you shut down the app before closing the loading screen, then
+ // it will need to be removed here. The rational for the next two
+ // steps is the same as for Board:
+ if (mTitleScreen != NULL)
+ mWidgetManager->RemoveWidget(mTitleScreen);
+ delete mTitleScreen;
+
+ // We should also free up all the resources that we loaded
+ // for ALL the resource groups. Deleting a group that was
+ // already deleted doesn't do anything, it's ignored.
+ mResourceManager->DeleteResources("Init");
+ mResourceManager->DeleteResources("TitleScreen");
+ mResourceManager->DeleteResources("Game");
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+ // Let the parent class perform any needed initializations first.
+ // This should always be done.
+ SexyAppBase::Init();
+
+ // We need to tell the resource manager to read in all the groups
+ // and information from that main group we made, called ResourceManifest,
+ // in the file "properties/resources.xml". The path/filename are
+ // by default set up to load that file, so you must name it exactly as such.
+ // This doesn't load any resources: it just parses the data and sets
+ // things up for loading.
+ LoadResourceManifest();
+
+ // Next, we want to load our absolutely necessary files that have to
+ // be loaded before anything else can run. You'll notice in the resources.xml
+ // file that we created a group called Init that contains these resources.
+ // You may call it whatever you like. Let's load those resources now.
+ // We do that by calling the LoadResources method of our mResourceManager
+ // variable and specifying in quotes the name of the resource group to
+ // load. This string is case sensitive.
+ if (!mResourceManager->LoadResources("Init"))
+ {
+ mLoadingFailed = true;
+ // This will display an informative error message indicating exactly
+ // what went wrong in the resource loading process.
+ ShowResourceError(true);
+ return;
+ }
+
+ // Now we've loaded the resources, but we need to extract them.
+ // Extraction is the phase that converts sound files to raw WAV
+ // files, and sets up and initializes fonts and palletizes images.
+ // The ResourceGen.exe program, when it generates C++ code for our
+ // resources, also creates a function for EVERY resource group of the
+ // form: Extract<GROUP>Resources, where <GROUP> is the exact name
+ // of the resource group you made. In our case, we made an "Init"
+ // group, so we have an ExtractInitResources method. You pass to it
+ // the pointer to the resource manager. Because an error can occur
+ // during this step, you should make sure to check for it.
+ if (!ExtractInitResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // We also need to load our title screen graphics in, since you can't
+ // display the title screen without any graphics. For an explanation of why
+ // we placed this in a separate group from Init, see properties/resources.xml.
+ // This code works exactly like the above did for the Init group.
+ if (!mResourceManager->LoadResources("TitleScreen"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractTitleScreenResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // Now let's create and add our title screen to the widget manager
+ mTitleScreen = new TitleScreen(this);
+ mTitleScreen->Resize(0, 0, mWidth, mHeight);
+
+ // Let's let the title screen initialize it's widgets and data
+ // before adding it to the widget manager:
+ mTitleScreen->Init();
+
+ mWidgetManager->AddWidget(mTitleScreen);
+
+ // Let's also load in some music to play. We use the mMusicInterface
+ // member for all our music needs, which requires the BassMusicInterface.h
+ // header to be loaded, since we use the library BASS to play our music.
+ // We can load in WAV, OGG, or MP3 files. BASS also supports a number
+ // of tracker formats, such as .it, .xm, .mod, etc. It also supports
+ // a format called MO3, which is a compressed version of a tracker
+ // file. For this example, we will use the MO3 from AstroPop.
+ // Why? Cause it's ours and we won't get sued for using it.
+ // We load our file manually, we do not use the resource manager for this.
+ // The first parameter is the ID to associate the song with. Just as sounds
+ // have IDs, so do music tracks.
+ mMusicInterface->LoadMusic(0, "music/music.mo3");
+
+ // Let's load another copy of the file. Why? In order to fade from one
+ // track to another, we need two instances of the track on different
+ // channels. Let's load it again and give it a different ID, 1.
+ mMusicInterface->LoadMusic(1, "music/music.mo3");
+
+ // Now we need to start playing a track. Because we are using an MO3
+ // and because the original format was a .it (Impulse Tracker) file,
+ // there are actually multiple songs inside of it, differentiated
+ // by various offsets. If you were just playing a single MP3 or OGG
+ // or WAV file instead of a tracker file, you would ignore this
+ // and use the default offset of 0 for the start of the song.
+ // Because the person that made the song file was nice and
+ // told us which offsets equated to which song pieces, I already
+ // know the magic offset numbers. In this particular case, the
+ // song for the intro screen is at offset 0, and the song
+ // for the main game music is at offset 9. Our music artist
+ // also was kind enough to put in tracker looping commands,
+ // so you'll notice that the songs play over and over. A discussion
+ // of tracker file formats is beyond the scope of this. Again,
+ // if you are just playing a WAV/OGG/MP3, you use offset 0 (the default)
+ // to indicate that you want to start playing from the start of the song.
+ //
+ // You can use PlayMusic to instantly play the track, or, like below,
+ // you can use FadeIn to smoothly fade the song in. The first parameter
+ // for both methods is the channel or song id that was used when the
+ // track was first loaded (In our case, either 0 or 1 works). For both,
+ // the second parameter is the offset to start playing at. Again, I just
+ // happen to know that the intro song is at offset 0. For FadeIn, the
+ // third parameter is how quickly to fade in, out of 1.0. The last parameter
+ // for both indicates whether or not you want to loop. This is kind of weird,
+ // but specify "false" to loop and "true" to not loop.
+ mMusicInterface->FadeIn(0, 0, 0.002, false);
+
+ // We'll cover changing the music and sound volumes in a later demo.
+
+ // Next, we need to know how many resources there are to load.
+ // This is necessary so we can display our progress bar on the title screen
+ // and make it be the appropriate length. There's a variable in SexyAppBase
+ // called mNumLoadingThreadTasks which holds the number of resources to
+ // load in the LoadingThreadProc function. You get the number of resources
+ // in a given group with a call to the resource manager's GetNumResources function
+ // for each of your groups that you are going to load:
+ mNumLoadingThreadTasks = mResourceManager->GetNumResources("Game");
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+ // This time, things are different. We aren't manually loading
+ // our fonts, sounds, and images. The resource manager is doing
+ // it for us. For each of the groups that we want to load,
+ // we first have to instruct the resource manager to begin the
+ // loading phase and initialize its internal variables.
+ // We do that with the StartLoadResources method and pass in the
+ // exact string name of the group to begin loading:
+ mResourceManager->StartLoadResources("Game");
+
+ // Now we need to load each individual resource. We will loop,
+ // calling LoadNextResource at the start. When it returns false,
+ // there are no more resources to load for the current group.
+ // LoadNextResource knows what group to load from because
+ // of the call to StartLoadResources above:
+ while (mResourceManager->LoadNextResource())
+ {
+ // The SexyAppBase variable, mCompletedLoadingThreadTasks, indicates the
+ // total number of resources that have so far been loaded. This is used
+ // to tell our loading screen the % progress we've made. See TitleScreen::Draw
+ // for an example of how this is used. We need to increment this value
+ // ourselves everytime we load a resource:
+ mCompletedLoadingThreadTasks++;
+
+ // If there was an error loading our resource, the resource manager
+ // will tell us to shut down by setting mShutdown to true. If that
+ // happened, immediately abort and return:
+ if (mShutdown)
+ return;
+
+ // Remember in demos 1-3 how we had the Board class call MarkDirty
+ // every update? Well, the title screen doesn't need to be such a hog.
+ // The title screen only needs to repaint when its progress bar changes
+ // size. The progress bar only changes size when a resource gets loaded.
+ // Because the game app is the only one that knows when this happens,
+ // the game app will be the one to tell the title screen that it's a
+ // dirty, dirty widget and that it needs a good and proper repainting.
+ // You COULD make an update method for the title screen and mark dirty
+ // every frame. But because this consumes more CPU time, it will take
+ // longer to load our resources. And since you want the loading time
+ // to be as quick as possible, you should only repaint when you need to.
+ mTitleScreen->MarkDirty();
+ }
+
+ // Just like in our Init function, after loading resources we
+ // need to extract them. Let's do that. Let's also ask the resource
+ // manager if an error occurred in the above loop that we
+ // didn't yet catch. We do that with the HadError method:
+ if (mResourceManager->HadError() || !ExtractGameResources(mResourceManager))
+ {
+ ShowResourceError(false);
+ mLoadingFailed = true;
+
+ return;
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ // When we're actually loading resources, we'll set the
+ // mLoadingFailed variable to "true" if there were any problems
+ // encountered along the way. If that is the case, just return
+ // because we won't want the user to get to the main menu or any
+ // other part of the game. We will want them to exit out.
+ if (mLoadingFailed)
+ return;
+
+
+ // We aren't going to make and add the Board class here like we
+ // did in the previous demos. Instead, since we are done loading
+ // everything, we're going to tell the title screen that
+ // we're done and that it should unhide the continue link and let
+ // the user enter the game.
+ mTitleScreen->LoadingComplete();
+
+ // Remember: since we didn't give our title screen an Update method,
+ // this class is responsible for telling it when to repaint. If we
+ // don't mark it dirty, you won't see the hyperlink widget
+ // appear. So mark it dirty now:
+ mTitleScreen->MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::TitleScreenIsFinished()
+{
+ // This function is called by the title screen when the user clicks
+ // on the hyperlink widget to continue. At this point, the title screen
+ // has already removed itself and its widgets and we should set up our
+ // Board class and begin the game. Let's also set our title screen
+ // pointer to NULL, since it will be safely deleted automatically at a
+ // later point, and we don't want to delete it twice.
+ mTitleScreen = NULL;
+ mBoard = new Board(this);
+
+ // Now that the title screen is done, we don't need its resources
+ // wasting memory. Let's delete all of its resources. We do that
+ // by calling DeleteResources and specifying the exact name of the
+ // resource group we want to free up:
+ mResourceManager->DeleteResources("TitleScreen");
+
+ // This is a very important step: Because the Board class is a widget
+ // (see Board.h/.cpp for more details) we need to tell it what
+ // dimensions it has and where to place it.
+ // By default a widget is invisible because its
+ // width/height are 0, 0. Since the Board class is our main
+ // drawing area and game logic class, we want to make it the
+ // same size as the application. For this particular demo, that means
+ // 800x600. We will use mWidth and mHeight though, as those were
+ // already set to the proper resolution in GameApp::Init().
+ mBoard->Resize(0, 0, mWidth, mHeight);
+
+ // Also an important step is to add the newly created Board widget to
+ // the widget manager so that it will automatically have its update, draw,
+ // and input processing methods called.
+ mWidgetManager->AddWidget(mBoard);
+
+ // Let's fade out the intro song and fade in the main game music.
+ // FadeOut works just like FadeIn did in Init() but with some
+ // slightly different parameters. The first, is like with FadeIn and
+ // PlayMusic, the channel or song id that you want to mess with.
+ // The second indicates that the song fading out should stop when
+ // done, if it is true. The final parameter indicates how fast
+ // to fade out, and is from 0 to 1.
+ mMusicInterface->FadeOut(0, true, 0.004);
+
+ // Let's fade in the main game music. This is the same as in Init.
+ // The only difference is we're using 1 instead of 0 for our song id.
+ // Why? Well, channel/song id 0 is being used to fade out the
+ // previously playing track, we can't use it to also fade in.
+ // That's why we loaded another copy of the song into channel 1.
+ // Again, as explained in Init, I happen to know that offset 9
+ // is the start of the main game music.
+ mMusicInterface->FadeIn(1, 9, 0.002, false);
+
+ // We'll cover changing the music and sound volumes in a later demo.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::HandleCmdLineParam(const std::string& theParamName, const std::string& theParamValue)
+{
+ // If you wanted to, in here you could examine command line parameters and their values.
+ // We actually don't care to, in this. The purpose was to show you how you'd do it,
+ // and this function is the one you use to read those values. We'll just print the
+ // parameters out for now:
+ OutputDebugString(StrFormat("theParamName = \"%s\", theParamValue = \"%s\"",
+ theParamName.c_str(), theParamValue.c_str()).c_str());
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/GameApp.h b/osframework/source/demos/Demo4/GameApp.h
new file mode 100644
index 0000000..3b038f1
--- /dev/null
+++ b/osframework/source/demos/Demo4/GameApp.h
@@ -0,0 +1,122 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+ // The GameApp class will be responsible for creating a class by the name
+ // of "Board", which we will use to do all the game's drawing, input processing,
+ // etc. Board is the second most important class and is where almost all of your
+ // game logic code will originate from. It is a widget, which allows for
+ // easy and automatic invocation of its update, drawing, and input processing
+ // functions. See the "Board" class for more details.
+ class Board;
+
+ // We're going to be responsible for creating and adding the title screen widget
+ class TitleScreen;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+ TitleScreen* mTitleScreen;
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreenIsFinished
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called by the TitleScreen widget when it is about to close
+ // down, this indicates that we should now add the board widget and
+ // start the game.
+ //////////////////////////////////////////////////////////////////////////
+ void TitleScreenIsFinished();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: HandleCmdLineParam
+ // Parameters:
+ // theParamName - The name of the parameter, will be of the form
+ // "-paramname". Note the "-" prefix.
+ // theParamValue - The parameter associated with the param name,
+ // or "" if none.
+ //
+ // Returns: none
+ //
+ // Purpose: This function lets you parse command line parameters and
+ // their associated values. Command line parameters are of the form:
+ // -paramname or -paramname="some value"
+ // Example:
+ // Demo4.exe -debug -printmsg="A test message" results in:
+ //
+ // theParamName = "-debug", theParamValue = ""
+ // theParamName = "-printmsg", theParamValue = "A test message"
+ //////////////////////////////////////////////////////////////////////////
+ virtual void HandleCmdLineParam(const std::string& theParamName, const std::string& theParamValue);
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/TitleScreen.cpp b/osframework/source/demos/Demo4/TitleScreen.cpp
new file mode 100644
index 0000000..2c85732
--- /dev/null
+++ b/osframework/source/demos/Demo4/TitleScreen.cpp
@@ -0,0 +1,210 @@
+#include "TitleScreen.h"
+
+#include "GameApp.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+// Now that we're on our 4th demo, the reason for including the headers
+// below should be apparent. If you forgot, review demos 1-3.
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Image.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Rect.h"
+
+// A new class: the HyperlinkWidget. It acts and resembles a standard
+// WWW hyperlink.
+#include "SexyAppFramework/HyperlinkWidget.h"
+
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::TitleScreen(GameApp *pApp)
+{
+ mApp = pApp;
+ mContinueLink = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::~TitleScreen()
+{
+ delete mContinueLink;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Init(void)
+{
+ // A hyperlink widget is basically the same thing as a button widget
+ // but with some slight differences. It is meant to emulate the look
+ // and feel of an internet hyperlink. We create the widget the
+ // same way we created a button widget in Demo3, specifying that
+ // this class is to listen to the widget events.
+ mContinueLink = new HyperlinkWidget(1, this);
+
+ // We need to set the font to use. In previous demos, we had
+ // a variable inside of GameApp that held the font. Now that we're
+ // using the resource manager, we'll use the main (and only) one
+ // that we declared from there. Remember how we named it FONT_DEFAULT?
+ // Well, you can use that name exactly now to reference it.
+ mContinueLink->SetFont(FONT_DEFAULT);
+
+ // Like the button widget, we can set the text to display:
+ mContinueLink->mLabel = _S("CLICK TO CONTINUE");
+
+ // And like the button widget, we can set the default and over colors.
+ // We don't use the SetColor method though, we just directly
+ // set mColor and mOverColor:
+ mContinueLink->mColor = Color(255, 255, 255);
+ mContinueLink->mOverColor = Color(0, 255, 0);
+ mContinueLink->mUnderlineSize = 1;
+
+
+ // We're not going to place the widget just yet. Why? Well,
+ // the TitleScreen hasn't been added to the widget manager.
+ // We'll wait until the AddedToManager method is called before
+ // adding it, just like in Demo3.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::AddedToManager(WidgetManager *theWidgetManager)
+{
+ Widget::AddedToManager(theWidgetManager);
+
+ // Just like with the button widget from Demo3, we're going to add our
+ // hyperlink widget in this method. However, we want the link to be
+ // invisible at first. Why? Well, while we're loading our resources,
+ // we don't want the user to be able to just start the game. We want
+ // them to wait until it's all loaded and ready to go. Once everything
+ // is loaded, then we'll make it visible and let them click to play.
+ // We do that with the SetVisible command:
+ mContinueLink->SetVisible(false);
+
+ // Just making it invisible isn't enough. Technically the user could
+ // still click on it even though they can't see it. We have to
+ // disable the widget to prevent it from receiving input:
+ mContinueLink->SetDisabled(true);
+
+ // Let's resize it to be at the bottom of the screen, and to be exactly
+ // the width/height of the lable that we set. Again, we use our friend
+ // the Resize function. However, note that we're setting the height to
+ // be a bit larger than that of the string. That's because the underline
+ // part of the hyperlink widget (whose thickness can be controlled via mUnderlineSize)
+ // draws a little below the string. If you didn't make the height a little
+ // larger, the line would be clipped and thus wouldn't be visible. Clipping
+ // is discussed in the next demo.
+ int labelWidth = FONT_DEFAULT->StringWidth(mContinueLink->mLabel);
+ int labelHeight = FONT_DEFAULT->GetHeight();
+ mContinueLink->Resize( mWidth / 2 - labelWidth / 2,
+ mHeight - labelHeight - 40,
+ labelWidth,
+ labelHeight+4);
+
+ // Almost done. Let's make it so that when the user mouses over the widget,
+ // that the cursor changes from the standard Windows arrow to a hand icon.
+ // We do that by setting the variable mDoFinger to true. This instructs the
+ // WidgetManager to chagne the cursor to the hand/finger icon when the mouse
+ // is inside the widget's bounds, and to reset it back to the arrow when it
+ // is not. Note that ALL widgets have this functionality.
+ mContinueLink->mDoFinger = true;
+
+ // And finally, we add the widget just like we added the button widget
+ // from demo 3 and the Board widget.
+ theWidgetManager->AddWidget(mContinueLink);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::RemovedFromManager(WidgetManager *theWidgetManager)
+{
+ // This is just like what we did in Board in Demo3.
+ // Let our parent class know about the removal, and get rid
+ // of our hyperlink widget.
+ Widget::RemovedFromManager(theWidgetManager);
+ theWidgetManager->RemoveWidget(mContinueLink);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Draw(Graphics *g)
+{
+ // Instead of having to say Color(0, 0, 0) or Color(255, 255, 255)
+ // for black/white, you can use Color::Black and Color::White.
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+
+ // We want to draw our loader bar to indicate the progress made in
+ // loading all our resources. As you recalll, GameApp::LoadingThreadProc is
+ // the thread that is actually loading everything. The app has a function,
+ // GetLoadingThreadProgress, that returns a value from 0.0 to 1.0 indicating
+ // the % complete it is. We will multiply this % complete by the width
+ // of our progress bar, so that we give the illusion of a growing bar.
+ int loaderBarWidth = IMAGE_LOADER_BAR->GetWidth();
+ int drawWidth = (int)(mApp->GetLoadingThreadProgress() * loaderBarWidth);
+ if (drawWidth > 0)
+ {
+ // As you may recall from Demo3 where we drew the frames of animation
+ // for the lightning image, the DrawImage call can take a source rectangle
+ // which indicates what chunk of the original image we want to draw.
+ // In our case, we want to start from from the upper left corner of
+ // the loader bar, but we only want to draw "drawWidth" wide. This will
+ // give the illusion that the progress bar is expanding as the resources
+ // are loaded in.
+ g->DrawImage(IMAGE_LOADER_BAR, mWidth / 2 - loaderBarWidth / 2,
+ 400,
+ Rect(0, 0, drawWidth, IMAGE_LOADER_BAR->GetHeight()));
+ }
+
+ // If our hyperlink widget is false, let's instead draw some
+ // "Loading" text (er, actually in this case it's an image) where
+ // it is located.
+ if (mContinueLink->mVisible == false)
+ g->DrawImage(IMAGE_LOADER_LOADINGTXT, mContinueLink->mX, mContinueLink->mY - 20);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::LoadingComplete()
+{
+ // Since the app told us that we're done loading all our resources,
+ // let's unhide and enable our continue link so the user can start
+ // playing.
+ mContinueLink->SetVisible(true);
+ mContinueLink->SetDisabled(false);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::ButtonDepress(int theId)
+{
+ if (theId == 1)
+ {
+ // Our hyperlink widget was pressed. We want to remove ourselves
+ // and the hyperlink widget, and tell the app to display the
+ // main board and get the game started.
+ // You might be thinking, "If I delete the title screen and
+ // hyperlink, won't I crash the program?" Yes, you will. That's
+ // why we aren't going to delete them using "delete". We're going
+ // to use SexyAppBase's SafeDeleteWidget method. This places the
+ // widget in a queue that is processed after all widgets and data
+ // get processed, and is then deleted at a time that is safe
+ // and appropriate. We still have to remove ourself and the
+ // hyperlink widget from the WidgetManager. We can easily access
+ // the WidgetManager, as it is a public variable in our game app.
+ mApp->mWidgetManager->RemoveWidget(this);
+ mApp->mWidgetManager->RemoveWidget(mContinueLink);
+ mApp->SafeDeleteWidget(this);
+ mApp->SafeDeleteWidget(mContinueLink);
+ mContinueLink = NULL;
+
+ // Now let's tell the game app that it's ok to add the board widget:
+ mApp->TitleScreenIsFinished();
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/TitleScreen.h b/osframework/source/demos/Demo4/TitleScreen.h
new file mode 100644
index 0000000..6d935cb
--- /dev/null
+++ b/osframework/source/demos/Demo4/TitleScreen.h
@@ -0,0 +1,127 @@
+#ifndef __TITLE_SCREEN_H__
+#define __TITLE_SCREEN_H__
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+namespace Sexy
+{
+
+class GameApp;
+class Graphics;
+class WidgetManager;
+
+// A new widget that we'll be learning about. It's explained in the .CPP code.
+class HyperlinkWidget;
+
+
+// If you forgot about the ButtonListener class, you should review Demo3.
+// The hyperlink widget is essentially the same thing as a button widget,
+// and emits the same messages that a button does. Thus, to act on its
+// messages we derive from the ButtonListener class.
+class TitleScreen : public Widget, public ButtonListener
+{
+
+private:
+
+ GameApp* mApp;
+ HyperlinkWidget* mContinueLink;
+
+public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreen
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ TitleScreen(GameApp* pApp);
+
+ virtual ~TitleScreen();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called BEFORE the title screen is added to the widget manager
+ // by GameApp. This initializes some things like the images used for
+ // our hyperlink widget.
+ //////////////////////////////////////////////////////////////////////////
+ void Init(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager. This is where
+ // we'll do all our display routines for the loading screen.
+ //////////////////////////////////////////////////////////////////////////
+ void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingComplete
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called manually by GameApp when we are done loading all
+ // resources, to let the title screen know that it should unhide and
+ // enable the continue link, so the user can start playing the game.
+ //////////////////////////////////////////////////////////////////////////
+ void LoadingComplete();
+};
+
+}
+
+#endif //__TITLE_SCREEN_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo4/main.cpp b/osframework/source/demos/Demo4/main.cpp
new file mode 100644
index 0000000..2d0bd68
--- /dev/null
+++ b/osframework/source/demos/Demo4/main.cpp
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Using the resource manager
+// * Title screen with progress bar
+// * Loading/playing music
+// * Playing sounds with pitch and panning values changed
+// * smooth motion with UpdateF
+// * Reading/writing to files/registry
+// * Getting command line switches
+// * Widgets: Hyperlink widget, edit widget, checkbox, list, scrollbars, safedeletewidget
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+ // Make sure to set this. Some classes, like the exception handler and custom cursors
+ // will need to use it.
+ gHInstance = hInstance;
+
+ // Create and initialize our game application.
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+
+ // Starts the entire application: sets up the resource loading thread and
+ // custom cursor thread, and enters the game loop where the application
+ // will remain until it is shut down. You will most likely not need to
+ // override this function.
+ anApp->Start();
+
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Demo5/Board.cpp b/osframework/source/demos/Demo5/Board.cpp
new file mode 100644
index 0000000..c2a3cfd
--- /dev/null
+++ b/osframework/source/demos/Demo5/Board.cpp
@@ -0,0 +1,306 @@
+#include "Board.h"
+#include "GameApp.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+// You should remember these files from the previous demos
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Color.h"
+#include "SexyAppFramework/Rect.h"
+#include "SexyAppFramework/ButtonWidget.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ImageFont.h"
+#include "SexyAppFramework/Image.h"
+
+// Our example dialog box
+#include "DemoDialog.h"
+
+// And for our performance profiling example, we first have to define SEXY_PERF_ENABLED
+// before including PerfTimer.h:
+#define SEXY_PERF_ENABLED
+#include "SexyAppFramework/PerfTimer.h"
+
+// Lastly, for our example of how to catch memory leaks, we first
+// enable leak detection with a #define in EACH of the files we want
+// to find leaks in, then include the memory management file.
+// IT IS VERY IMPORTANT THAT THIS DEFINE AND INCLUDE BE DONE AFTER ALL
+// OTHER FILE INCLUDES OR ELSE IT WILL CAUSE LINKER AND COMPILER ERRORS!
+// Memory leaks will automatically be dumped to "mem_leaks.txt" when
+// the app is closed.
+#define SEXY_MEMTRACE
+#include "SexyAppFramework/memmgr.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+
+
+ mButton = NULL;
+
+ // Set up our parallaxing layers
+ for (int i = 0; i < 3; i++)
+ {
+ mLayer[i].mX = 0;
+
+ // Get the image for this layer. You'll notice in our resource
+ // file that we named the layers IMAGE_BG0, IMAGE_BG1, IMAGE_BG2.
+ // Instead of having to manually type in the layer names for each one,
+ // we can use some convenience routines from our generated Res.h/.cpp
+ // resource files. First step: make a string of the ID of the image we want
+ // to access:
+ std::string imageStringID = StrFormat("IMAGE_BG%d", i);
+
+ // what we need to do now is get the integer ID for our resource
+ // that has the same name as imageStringID.
+ int id = GetIdByStringId(imageStringID.c_str());
+
+ // Now that we have the integer ID, we can request the actual
+ // image data with it. We do that with GetImageById:
+ mLayer[i].mImage = GetImageById(id);
+
+ // Set the Y coordinate of the background layer so that it's
+ // base is at the bottom of the screen. Because the Board hasn't
+ // been resized or added to the manager yet, it's own mHeight and
+ // mWidth are at the default of 0, 0. But not to worry, we set the
+ // overall game's width/height in GameApp's constructor, so we
+ // can just use those variables instead:
+ mLayer[i].mY = (float)(mApp->mHeight - mLayer[i].mImage->GetHeight());
+ }
+
+ // We will ON PURPOSE leak memory as an example of how to track
+ // such things in your program. Review the comments at the top of this
+ // file about memory leak detection:
+ int* aLeakedInteger = new int;
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+ delete mButton;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+
+ // As an example of how to profile things, we're going to profile
+ // the update and draw functions. Clearly, profiling this almost
+ // empty function isn't too useful, but the point is to show you
+ // HOW to profile multiple things and how to view the results.
+ // You tell the profiler that you want it to begin with the
+ // statement below, passing in a string indicating WHAT you're
+ // profiling. The string can be anything. Enabled debug keys by
+ // pressing CTRL-ALT-D and then press F2 to enabled/disable profiling.
+ SEXY_PERF_BEGIN("Start_Of_Update");
+
+ Widget::Update();
+
+
+ MarkDirty();
+
+ // And you mark the end of a profiling section with
+ // SEXY_PER_END, passing in the same string you passed to
+ // SEXY_PERF_BEGIN.
+ SEXY_PERF_END("Start_Of_Update");
+
+
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::KeyDown(KeyCode theKey)
+{
+ // If the user presses the right or left arrow keys, let's
+ // scroll the layers:
+ if (theKey == KEYCODE_RIGHT)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ // When the X coordinate has moved leftward (negative) by
+ // the image's width or more, we reset the X coordinate back to
+ // 0. Since we tile an image to the left and right of
+ // this center image, the user won't see the snapping back to 0.
+ mLayer[i].mX -= 1.0f * (i + 1);
+ if (mLayer[i].mX <= -mLayer[i].mImage->GetWidth())
+ mLayer[i].mX = 0;
+ }
+ }
+ else if (theKey == KEYCODE_LEFT)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ // This is the opposite of above, but notice that we're checking
+ // to see if the X coordinate is >= the width of the image, and not the
+ // width of the application. That's because some of the layers are wider
+ // than the screen: 960 wide, when the game is 640 wide. If we checked
+ // against the game width instead, we'd get this odd flicker appearing
+ // because the tiling would be off. You can try it and see the effect.
+ mLayer[i].mX += 1.0f * (i + 1);
+ if (mLayer[i].mX >= mLayer[i].mImage->GetWidth())
+ mLayer[i].mX = 0;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ // As an example of how to profile things, we're going to profile
+ // the update and draw functions.
+ // You tell the profiler that you want it to begin with the
+ // statement below, passing in a string indicating WHAT you're
+ // profiling. The string can be anything. Enabled debug keys by
+ // pressing CTRL-ALT-D and then press F2 to enabled/disable profiling.
+ SEXY_PERF_BEGIN("Start_Of_Draw");
+
+ // Clear the screen to black
+ g->SetColor(Color(0, 0, 0));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+
+ for (int i = 0; i < 3; i++)
+ {
+ int imgWidth = mLayer[i].mImage->GetWidth();
+
+
+ // Let's learn about Graphics translation. Normally, you draw your image
+ // at a given XY by passing the coordinates to DrawImage. As an alternative,
+ // you can "translate" the Graphics object (change its XY drawing offset)
+ // and then just draw your image at 0, 0. Think of the Graphics object by
+ // default as always being at 0, 0. By translating it, you move that
+ // to whereever you like. The usefulness is in saving extra typing,
+ // as well as some other features that come into play when scrolling
+ // large worlds with many objects. For each of the background layers,
+ // let's move the graphics object to its base XY location:
+ g->TranslateF(mLayer[i].mX, mLayer[i].mY);
+
+ // Something else to know about translation is that it is the method
+ // used when drawing widgets. For every widget, the Graphics object
+ // is translated to its own X, Y coordinate. Thus, when drawing
+ // in the widget's class, you should always draw as if the top left
+ // corner of the widget itself was 0, 0. Since all along we've been making
+ // our Board widget the size of the screen, this hasn't been something we've
+ // had to care about. But as you'll see in the dialog box example, it's something
+ // we have to take into consideration. Normally, you can't draw outside the
+ // X, Y, width, height of a widget. However, as you'll also see, you can
+ // change that to allow drawing anywhere you want.
+
+ // Remember how in previous demos we mentioned that it's common to use the
+ // smoother DrawImageF functions instead of DrawImage if the user has 3D
+ // acceleration enabled? Let's do that know. We can check if hardware acceleration
+ // is on or not with a call to SexyAppBase's Is3DAccelerated:
+ if (mApp->Is3DAccelerated())
+ {
+ // Because we translated the graphics object, we can just draw our layers
+ // offset by the image width. Had we not translated the graphics object, here
+ // is the code we would have had to use instead:
+ // g->DrawImageF(mLayer[i].mImage, mLayer[i].mX - imgWidth, mLayer[i].mY);
+ // g->DrawImageF(mLayer[i].mImage, mLayer[i].mX, mLayer[i].mY);
+ // g->DrawImageF(mLayer[i].mImage, mLayer[i].mX + imgWidth, mLayer[i].mY);
+
+ g->DrawImageF(mLayer[i].mImage, (float)-imgWidth, 0.0f);
+ g->DrawImageF(mLayer[i].mImage, 0.0f, 0.0f);
+ g->DrawImageF(mLayer[i].mImage, (float)imgWidth, 0.0f);
+ }
+ else
+ {
+ // non-hardware accelerated
+ g->DrawImage(mLayer[i].mImage, -imgWidth, 0);
+ g->DrawImage(mLayer[i].mImage, 0, 0);
+ g->DrawImage(mLayer[i].mImage, imgWidth, 0);
+ }
+
+ // You should remember to put the Graphics object back to where it was
+ // before you translated it, otherwise all subsequent drawing commands will
+ // be offset by that amount.
+ g->TranslateF(-mLayer[i].mX, -mLayer[i].mY);
+ }
+
+ // And you mark the end of a profiling section with
+ // SEXY_PER_END, passing in the same string you passed to
+ // SEXY_PERF_BEGIN.
+ SEXY_PERF_END("Start_Of_Draw");
+
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddedToManager(WidgetManager* theWidgetManager)
+{
+ // At this point, the Board class has already been added to the
+ // widget manager. We should call our parent class' method
+ // so that it can be sure to perform any needed tasks, first.
+ Widget::AddedToManager(theWidgetManager);
+
+ // You should remember how to create buttons from Demo3. If not,
+ // go back and review.
+ mButton = new ButtonWidget(Board::OPTIONS_BUTTON_ID, this);
+ mButton->SetFont(FONT_DEFAULT);
+ mButton->mLabel = _S("Click Me!");
+
+ // This time, let's use some images for our button.
+ // mOverImage is the image to use when the mouse cursor is over the button.
+ // mDownImage is the image to use when a mouse button is held down on it
+ // mButtonImage is the default image to use
+ // If we wanted to, we could specify a disabled image as well.
+ mButton->mOverImage = IMAGE_BUTTON_OVER;
+ mButton->mDownImage = IMAGE_BUTTON_DOWN;
+ mButton->mButtonImage = IMAGE_BUTTON_NORMAL;
+ mButton->mDoFinger = true;
+ mButton->Resize(56, 5, IMAGE_BUTTON_NORMAL->GetWidth(), IMAGE_BUTTON_NORMAL->GetHeight());
+
+ theWidgetManager->AddWidget(mButton);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ // This is called after we've been removed from the widget manager.
+ // Again, we should let our base class do anything it needs to, first.
+ Widget::RemovedFromManager(theWidgetManager);
+
+ // We should now also remove any widgets we are responsible for.
+ theWidgetManager->RemoveWidget(mButton);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::ButtonDepress(int theId)
+{
+ // As another PURPOSEFUL example of detecting memory leaks, let's
+ // cause a leak here as well so you can see how the leak detection works.
+ // Again, this is on purpose to illustrate a point.
+ struct ParallaxLayer* aLeakedParallaxLayer = new struct ParallaxLayer;
+
+ if (theId == Board::OPTIONS_BUTTON_ID)
+ {
+ // Let's open our options dialog box. Everything works the same
+ // except that instead of using the WidgetManager's AddWidget function,
+ // we use a special AddDialog method. The first parameter is the ID
+ // of the dialog box, the second is the dialog box itself.
+ // In this case, we don't need to maintain a pointer to the dialog box
+ // to delete later. It will automatically be cleaned up when the
+ // dialog box is closed via the KillDialog command (see DemoDialog).
+ DemoDialog* dlg = new DemoDialog("Header", "Hello! I am a dialog box.");
+ dlg->Resize(50, 50, 300, 400);
+ mApp->AddDialog(DemoDialog::DIALOG_ID, dlg);
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/Board.h b/osframework/source/demos/Demo5/Board.h
new file mode 100644
index 0000000..ae8519e
--- /dev/null
+++ b/osframework/source/demos/Demo5/Board.h
@@ -0,0 +1,205 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+// Because we're going to be learning about some new widgets, we
+// need to include some more listener classes so we can respond to each one.
+#include "SexyAppFramework/EditListener.h"
+#include "SexyAppFramework/CheckboxListener.h"
+#include "SexyAppFramework/ListListener.h"
+
+
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+
+
+class Graphics;
+class GameApp;
+class ButtonWidget;
+class WidgetManager;
+class Image;
+
+struct ParallaxLayer
+{
+ float mX;
+ float mY;
+ Image* mImage;
+};
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget, public ButtonListener
+{
+
+ private:
+
+ GameApp* mApp;
+ ButtonWidget* mButton;
+
+ // And in this demo, we're going to do some parallax scrolling whenever
+ // the arrow keys are pressed.
+ struct ParallaxLayer mLayer[3];
+
+ public:
+
+ // And let's finally use some enums for our widgets
+ enum
+ {
+ OPTIONS_BUTTON_ID
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: KeyDown
+ // Parameters:
+ // theKey - A KEYCODE_ value from Keycodes.h that represents the
+ // key pressed.
+ //
+ // Returns: none
+ //
+ // Purpose: When a key is pressed, this method is called. This method
+ // differs from KeyChar (described below) in that you can detect non-ASCII
+ // keys with it, as well as ASCII.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void KeyDown(KeyCode theKey);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: KeyChar
+ // Parameters:
+ // theChar - The ASCII character that was pressed.
+ //
+ // Returns: none.
+ //
+ // Purpose: Unlike KeyDown, this method only takes ASCII characters
+ // as input. It's common to use KeyChar for your normal ASCII processing
+ // needs, and KeyDown for your extended keyboard key needs. We're not
+ // actually going to do anything with KeyChar in this code. It's displayed
+ // here though to illustrate the differences between KeyDown and to
+ // help explain its usage.
+ //////////////////////////////////////////////////////////////////////////
+ //virtual void KeyChar(char theChar);
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/Demo5 VS2005 WideString.vcproj b/osframework/source/demos/Demo5/Demo5 VS2005 WideString.vcproj
new file mode 100644
index 0000000..639a511
--- /dev/null
+++ b/osframework/source/demos/Demo5/Demo5 VS2005 WideString.vcproj
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo5"
+ ProjectGUID="{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo5_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo5.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo5.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo5.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="DemoDialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="DemoDialog.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo5/Demo5 VS2005.vcproj b/osframework/source/demos/Demo5/Demo5 VS2005.vcproj
new file mode 100644
index 0000000..bca9888
--- /dev/null
+++ b/osframework/source/demos/Demo5/Demo5 VS2005.vcproj
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Demo5"
+ ProjectGUID="{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo5_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Demo5.pdb"
+ GenerateMapFile="true"
+ MapFileName="Demo5.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Demo5.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="DemoDialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="DemoDialog.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo5/Demo5 WideString.vcproj b/osframework/source/demos/Demo5/Demo5 WideString.vcproj
new file mode 100644
index 0000000..cb53cc1
--- /dev/null
+++ b/osframework/source/demos/Demo5/Demo5 WideString.vcproj
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo5"
+ ProjectGUID="{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo5_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo5.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo5.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo5.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="DemoDialog.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="DemoDialog.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo5/Demo5.dsp b/osframework/source/demos/Demo5/Demo5.dsp
new file mode 100644
index 0000000..1e06a9a
--- /dev/null
+++ b/osframework/source/demos/Demo5/Demo5.dsp
@@ -0,0 +1,150 @@
+# Microsoft Developer Studio Project File - Name="Demo5" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo5 - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Demo5.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Demo5.mak" CFG="Demo5 - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Demo5 - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Demo5 - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Demo5 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Demo5___Win32_Release"
+# PROP BASE Intermediate_Dir "Demo5___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Demo5.exe"
+
+!ELSEIF "$(CFG)" == "Demo5 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Demo5___Win32_Debug"
+# PROP BASE Intermediate_Dir "Demo5___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\Demo5_debug.exe" /pdbtype:sept
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "Demo5 - Win32 Release"
+# Name "Demo5 - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DemoDialog.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DemoDialog.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Demo5/Demo5.vcproj b/osframework/source/demos/Demo5/Demo5.vcproj
new file mode 100644
index 0000000..e01d522
--- /dev/null
+++ b/osframework/source/demos/Demo5/Demo5.vcproj
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Demo5"
+ ProjectGUID="{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo5_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Demo5.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Demo5.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Demo5.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="DemoDialog.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="DemoDialog.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Demo5/DemoDialog.cpp b/osframework/source/demos/Demo5/DemoDialog.cpp
new file mode 100644
index 0000000..38d4f53
--- /dev/null
+++ b/osframework/source/demos/Demo5/DemoDialog.cpp
@@ -0,0 +1,414 @@
+#include "DemoDialog.h"
+#include "Res.h"
+#include "GameApp.h"
+#include "SexyAppFramework/SexyAppBase.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/DialogButton.h"
+#include "SexyAppFramework/Checkbox.h"
+
+// We're going to use a slider widget to control sound/music volume
+#include "SexyAppFramework/Slider.h"
+
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+// Let's do a little explanation of the parent Dialog class, shall we?
+// The first parameter we pass it is an image to use for the dialog box.
+//
+// This image has to have the property that its width and height be
+// divisible by 3. Why? For stretching/tiling, in case you want the
+// dialog box to be bigger than the actual image. The image can
+// be thought of as being divided into regions. The 4 corners
+// are drawn normally, and the remaining chunks (which comprise a third
+// of the image height or the image width) are tiled to allow for
+// the stretching of the dialog box.
+//
+// The image for the dialog button works the same way and must have
+// the same properties. Dialogs use a DialogButton class which is exactly
+// the same as a normal button class, except that they support tiling
+// the image if it is stretched larger than the original image is.
+//
+// The third parameter is the ID to use for the dialog box.
+//
+// The fourth indicates if the dialog is modal. If it is, then only the
+// dialog box and any widget above it (like its buttons) will receive
+// keyboard and mouse input. This is just like in Windows when a file
+// dialog appears and you can't click on the window of the application
+// below it.
+//
+// The fifth parameter is the header to use for the dialog box.
+//
+// The sixth parameter is the text to display in the body of the dialog
+// box. You can use the newline (\n) character for line breaks.
+//
+// The seventh parameter is optional, and is only used if the eigth
+// parameter is Dialog::BUTTONS_FOOTER. This is the text to display on
+// the footer (bottom) dialog button.
+//
+// The eigth parameter indicates what type of buttons are to display.
+// You can use BUTTONS_YES_NO or BUTTONS_OK_CANCEL for the standard
+// "Yes", "No" or "OK", "Cancel" options, BUTTONS_NONE for no buttons,
+// or BUTTONS_FOOTER for a single button that runs along the bottom.
+// Of course, you can change the labels on any of the buttons if you
+// like.
+//
+// The YES/OK/FOOTER buttons have a value of 2000 + the dialog's ID.
+// The NO/CANCEL buttons have a value of 3000 + the dialog's ID.
+//////////////////////////////////////////////////////////////////////////
+DemoDialog::DemoDialog(std::string theHeader, std::string theBody) :
+Dialog(IMAGE_DIALOG_BOX, IMAGE_DIALOG_BUTTON, DemoDialog::DIALOG_ID, true, StringToSexyStringFast(theHeader), StringToSexyStringFast(theBody), _S("CLOSE"), Dialog::BUTTONS_FOOTER)
+{
+ // We can set the rectangular region in which all text/buttons are to go
+ // by changing the mContentInsets variable. The first parameter
+ // is the distance from the left side of the dialog box, the second
+ // is the distance from the top, third is distance from the right,
+ // and fourth is distance from the bottom in which content
+ // can be placed.
+ mContentInsets = Insets(23, 20, 23, 20);
+
+ // We can then set a value for how many pixels below the inset top
+ // the text body should go:
+ mSpaceAfterHeader = 30;
+
+ // Let's also set the fonts to use for the header and the text. We should
+ // use the SetXXXFont functions instead of directly modifying the font because
+ // the dialog class makes a copy of the font and then deletes it in its destructor.
+ // This is due to backwards compatibility with our old Java framework.
+ SetHeaderFont(FONT_DEFAULT);
+ SetLinesFont(FONT_DEFAULT);
+ SetButtonFont(FONT_DEFAULT);
+
+ // We can also change the color of the text
+ SetColor(COLOR_HEADER, Color::Black);
+ SetColor(COLOR_LINES, Color::Black);
+
+ // Now let's create some sliders to control the music and sound volume with.
+ // The first parameter is the image to use for the track of the slider. The
+ // second is the image to use for the little movable "thumb" icon.
+ // The third is the ID and the fourth is the widget who wants to listen to
+ // the slider.
+ mMusicVolumeSlider = new Slider(IMAGE_SLIDER_TRACK, IMAGE_SLIDER_THUMB, DemoDialog::MUSIC_SLIDER_ID, this);
+
+ // Let's set the value of the music slider to what the current volume is.
+ // SexyAppBase has a GetMusicVolume function that returns this amount.
+ // But wait, we didn't get a SexyAppBase pointer passed into the constructor!
+ // Don't worry. gSexyAppBase is externed in SexyAppBase.h and we can use that instead.
+ mMusicVolumeSlider->SetValue(gSexyAppBase->GetMusicVolume());
+
+ mSfxVolumeSlider = new Slider(IMAGE_SLIDER_TRACK, IMAGE_SLIDER_THUMB, DemoDialog::SFX_SLIDER_ID, this);
+
+ // Let's set the sound volume to the current volume, just like we did with the music slider
+ mSfxVolumeSlider->SetValue(gSexyAppBase->GetSfxVolume());
+
+ // Let's make a button to show off how to use random numbers
+ mRandomBtn = new DialogButton(IMAGE_DIALOG_BUTTON, DemoDialog::RANDOM_BTN_ID, this);
+ mRandomBtn->mLabel = _S("Random #");
+ mRandomBtn->SetFont(FONT_DEFAULT);
+
+ // To illustrate the mClip example, we'll use a button to toggle it.
+ mClipBtn = new DialogButton(IMAGE_DIALOG_BUTTON, DemoDialog::CLIP_BTN_ID, this);
+ mClipBtn->mLabel = _S("Clipping");
+ mClipBtn->SetFont(FONT_DEFAULT);
+
+ m3DCheckbox = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, DemoDialog::HARDWARE_CHECKBOX_ID, this);
+ mFSCheckbox = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, DemoDialog::FS_CHECKBOX_ID, this);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+DemoDialog::~DemoDialog()
+{
+ delete mMusicVolumeSlider;
+ delete mSfxVolumeSlider;
+ delete mRandomBtn;
+ delete mClipBtn;
+ delete m3DCheckbox;
+ delete mFSCheckbox;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::Draw(Graphics* g)
+{
+ Dialog::Draw(g);
+
+ // Let's draw some labels for the sliders
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::Black);
+
+ // We draw the X/Y at the slider's X/Y but we subtract off the dialog box's
+ // X/Y's from that. Why? The slider's XY's are in absolute screen coordinates,
+ // as are the dialog boxes. But as you may recall from Board::Draw(), where
+ // we explain graphics translation, once we get inside the draw loop of a
+ // widget, the graphics object is already moved (translated) to the widget's
+ // coordinates. Thus, in using the Graphics object, g, (0, 0) is located
+ // at the top left corner of the widget (our dialog box). So we
+ // just take the difference between the widget locations to produce the
+ // actual location we want to drawour text at:
+ g->DrawString(_S("Music volume:"), mMusicVolumeSlider->mX - mX,
+ mMusicVolumeSlider->mY - mY - mMusicVolumeSlider->mHeight);
+
+ g->DrawString(_S("Sound volume:"), mSfxVolumeSlider->mX - mX,
+ mSfxVolumeSlider->mY - mY - mSfxVolumeSlider->mHeight);
+
+ // Do the same for the checkboxes:
+ g->DrawString(_S("3D Mode:"), m3DCheckbox->mX - mX, m3DCheckbox->mY - mY - m3DCheckbox->mHeight + 20);
+ g->DrawString(_S("Full Screen:"), mFSCheckbox->mX - mX, mFSCheckbox->mY - mY - mFSCheckbox->mHeight + 20);
+
+ // As an example of clipping and how to disable it, let's draw
+ // a box and some text outside of the X/Y/Width/Height of this
+ // dialog box. You'll notice that when mClip is true (default),
+ // that anything drawn outside the bounds of the widget is clipped, or
+ // ignored. When mClip is false, no clipping is performed and we
+ // can draw anywhere.
+
+ g->SetColor(Color(255, 0, 0, 128));
+ // Draw a box in the bottom right
+ g->FillRect(mWidth, mHeight, 100, 100);
+ // Draw one in the top left
+ g->FillRect(-100, -100, 100, 100);
+ g->SetColor(Color::Black);
+ g->DrawString(_S("Top left"), -90, -20);
+ g->DrawString(_S("Bottom right"), mWidth + 10, mHeight + 20);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::Update()
+{
+ Dialog::Update();
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::AddedToManager(WidgetManager* theWidgetManager)
+{
+ Dialog::AddedToManager(theWidgetManager);
+ theWidgetManager->AddWidget(mMusicVolumeSlider);
+ theWidgetManager->AddWidget(mSfxVolumeSlider);
+ theWidgetManager->AddWidget(mRandomBtn);
+ theWidgetManager->AddWidget(mClipBtn);
+
+ int checkWidth = IMAGE_CHECKBOX->GetWidth() / 2;
+ m3DCheckbox->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ m3DCheckbox->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ mFSCheckbox->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ mFSCheckbox->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ // Let's set the initial checked state of the 3d checkbox to true if the
+ // user has 3D support enabled. We determine that via a call to Is3DAccelerated
+ m3DCheckbox->mChecked = gSexyAppBase->Is3DAccelerated();
+
+ // We can check if the app is fullscreen by examining the mIsWindowed variable:
+ mFSCheckbox->mChecked = !gSexyAppBase->mIsWindowed;
+
+ theWidgetManager->AddWidget(m3DCheckbox);
+ theWidgetManager->AddWidget(mFSCheckbox);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ Dialog::RemovedFromManager(theWidgetManager);
+ theWidgetManager->RemoveWidget(mMusicVolumeSlider);
+ theWidgetManager->RemoveWidget(mSfxVolumeSlider);
+ theWidgetManager->RemoveWidget(mRandomBtn);
+ theWidgetManager->RemoveWidget(mClipBtn);
+ theWidgetManager->RemoveWidget(m3DCheckbox);
+ theWidgetManager->RemoveWidget(mFSCheckbox);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Dialog::Resize(theX, theY, theWidth, theHeight);
+
+ // Layout the music slider so that it's left aligned with the
+ // boundary we set for the content insets. We'll make the slider fill the width
+ // of the content region (it'll be stretched if the base image isn't
+ // wide enough) too.
+ mMusicVolumeSlider->Resize(theX + mContentInsets.mLeft,
+ theY + 140,
+ mWidth - mContentInsets.mLeft - mContentInsets.mRight,
+ IMAGE_SLIDER_THUMB->GetHeight());
+
+ // Let's align the sound effect slider in the same way but using a different method.
+ // We know that we want the SFX slider to have the same X, width, and height, and
+ // to be just a few pixels below the music slider. Instead of having to mess around
+ // with the settings like we did above, we can use the layout (LAY_) flags instead.
+ // The first parameter is an ORed list of layout parameters and should be
+ // pretty self explanatory. You can find more in Widget.h.
+ // The second parameter is the widget to use as the reference.
+ // The rest are any extra padding to use for left/top/width/height related
+ // layout flags. As you can see, we wanted 60 pixels added to the top of
+ // our sound effect slider.
+ mSfxVolumeSlider->Layout(LAY_SameLeft | LAY_Below | LAY_SameWidth | LAY_SameHeight,
+ mMusicVolumeSlider, 0, 40, 0, 0);
+
+ // Place the button that will show off random number generation under the sound effect
+ // slider. But let's only make it take up 1/2 of the width of the slider
+ // and be only as tall as the original button image:
+ mRandomBtn->Layout(LAY_SameLeft | LAY_SameTop, mSfxVolumeSlider, 0, 40, 0, 0);
+ mRandomBtn->Resize(mRandomBtn->mX, mRandomBtn->mY,
+ mSfxVolumeSlider->mWidth / 2, IMAGE_DIALOG_BUTTON->mHeight);
+
+ // And let's place the clipping toggle button to its right
+ mClipBtn->Layout(LAY_Right | LAY_SameTop | LAY_SameWidth | LAY_SameHeight,
+ mRandomBtn, 0, 0, 0, 0);
+
+ // Place the 3D checkbox under the random button:
+ m3DCheckbox->Layout(LAY_SameLeft | LAY_Below, mRandomBtn, 0, 40, 0, 0);
+ m3DCheckbox->Resize(m3DCheckbox->mX, m3DCheckbox->mY,
+ IMAGE_CHECKBOX->mWidth / 2, IMAGE_CHECKBOX->mHeight);
+
+ // And the fullscreen box to the right of the 3d one. Except, let's use
+ // the mClipBtn's X coordinate to align with:
+ mFSCheckbox->Layout(LAY_SameTop | LAY_SameWidth | LAY_SameHeight, m3DCheckbox);
+ mFSCheckbox->Layout(LAY_SameLeft, mClipBtn);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::SliderVal(int theId, double theVal)
+{
+ if (theId == DemoDialog::MUSIC_SLIDER_ID)
+ {
+ // Let's set the music volume to whatever the slider position is
+ gSexyAppBase->SetMusicVolume(theVal);
+ }
+ else if (theId == DemoDialog::SFX_SLIDER_ID)
+ {
+ // Set the sound value
+ gSexyAppBase->SetSfxVolume(theVal);
+
+ // A good idea is to play a "ding" or some similar sound when
+ // the thumb is released, to indicate to the user what the current
+ // sound volume is (since sounds might not be continuously playing,
+ // unlike the music). We check for this by seeing if the mDragging
+ // variable is true or not.
+ if (!mSfxVolumeSlider->mDragging)
+ gSexyAppBase->PlaySample(SOUND_TIMER);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::ButtonDepress(int theId)
+{
+ Dialog::ButtonDepress(theId);
+
+ if (theId == mRandomBtn->mId)
+ {
+ // Let's get a random integer. The Rand() function is declared
+ // in Common.h and returns a value from 0 to SEXY_RAND_MAX (2,147,483,647)
+ int r = Rand();
+
+ // Now let's change the text of the dialog box:
+ mDialogLines = StrFormat(_S("Random number: %d"), r);
+ }
+ else if (theId == mClipBtn->mId)
+ {
+ // Toggle mClip. If mClip is off, we can draw outside the X/Y/width/height of
+ // our dialog box.
+ mClip = !mClip;
+ if (mClip)
+ mClipBtn->mLabel = _S("Clipping");
+ else
+ mClipBtn->mLabel = _S("No clipping");
+ }
+ // Previously, before framework 1.2, the line below looked like:
+ // else if (theId == 2000 + mId)
+ // With the 1.2 changes, there's just 1 slight incompatibility.
+ // If the DialogListener for a dialog your app (by default), and
+ // you don't implement your own DialogButton(De)press method (see V12Demo for
+ // more info on this), and instead are trapping button presses within ButtonDepress
+ // inside the dialog itself, then instead of the button ID being 2000 or 3000 + mId,
+ // it's just ID_YES/ID_OK for ok/cancel/1-button dialog, and ID_NO/ID_CANCEL for no/cancel 2nd button.
+ // Hence we changed our check to look for ID_YES, which is our default single close button at the bottom of this
+ // dialog.
+ else if (theId == ID_YES)
+ {
+ // Close button pressed. Tell the app to remove ourselves. This
+ // will automatically safe delete the dialog at a later time.
+ // Let's apply the 3D and fullscreen mode settings first though.
+ // We call SwitchScreenMode. The first parameter is whether or not to run
+ // windowed (false means fullscreen), the second is whether or not to do 3d.
+ gSexyAppBase->SwitchScreenMode(!mFSCheckbox->mChecked, m3DCheckbox->mChecked);
+
+ gSexyAppBase->KillDialog(this);
+
+ // Set focus back to the board
+ ((GameApp*)gSexyAppBase)->SetFocusToBoard();
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoDialog::CheckboxChecked(int theId, bool checked)
+{
+ // We'll wait until the dialog box is closed before actually applying any effects,
+ // since it's rather jarring if as soon as a user clicks the 3d or fullscreen
+ // toggle buttons to change right then and there.
+
+ if (theId == m3DCheckbox->mId)
+ {
+ if (checked)
+ {
+ // Turn on 3D acceleration. But we need to check if the user is
+ // even allowed to have it on. Some cards are just not compatible
+ // with the framework (less than 8MB RAM for instance):
+ if (!gSexyAppBase->Is3DAccelerationSupported())
+ {
+ // It's not supported. Don't let the checkbox get checked.
+ // Display an error dialog to the user to let them know why this happened.
+ // The reason we don't use a Popup or Windows-based message box here is because
+ // if the user was in full screen mode, they might not see the error message. Using
+ // a game dialog box is the safest way to warn them.
+ m3DCheckbox->SetChecked(false);
+ gSexyAppBase->DoDialog(DemoDialog::MESSAGE_BOX_ID, true, _S("Not Supported"),
+ _S("Hardware acceleration can not be enabled on this computer. \nYour\
+ video card does not meet the minimum requirements for this game."),
+ _S("OK"), Dialog::BUTTONS_FOOTER);
+ }
+ else if(!gSexyAppBase->Is3DAccelerationRecommended())
+ {
+ // We can also check if 3D acceleration is not recommended for this computer
+ // with a call to Is3DAccelerationRecommended. This allows the user to override
+ // the default setting, but with a warning that it might not work or might cause
+ // problems. Some cards fail the detection process but wind up being OK to use.
+ gSexyAppBase->DoDialog(DemoDialog::MESSAGE_BOX_ID, true, _S("Warning"),
+ _S("Your video card may not fully support this feature.\n\
+ If you experience slower performance, please disable Hardware Acceleration."),
+ _S("OK"), Dialog::BUTTONS_FOOTER);
+ }
+
+ }
+ }
+ else if (theId == mFSCheckbox->mId)
+ {
+ // Believe it or not, some people are not allowed to play in windowed mode.
+ // You can only run in windowed mode if your desktop is 16 or 32 bit, and
+ // if the resolution of their desktop is GREATER THAN the resolution of the
+ // game. It doesn't make sense to run a 800x600 game windowed when your desktop
+ // is 800x600 or less.
+ // We can determine if the user is not allowed to run in windowed mode by
+ // checking the value of SexyAppBase's mForceFullScreen variable.
+ if (gSexyAppBase->mForceFullscreen && !checked)
+ {
+ gSexyAppBase->DoDialog(DemoDialog::MESSAGE_BOX_ID, true, _S("No Windowed Mode"),
+ _S("Windowed mode is only available if your desktop is running in\n\
+ either 16 bit or 32 bit color mode, which it is not."), _S("OK"), Dialog::BUTTONS_FOOTER);
+
+ // re-check the box to indicate that fullscreen is still the selected mode:
+ mFSCheckbox->SetChecked(true);
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/DemoDialog.h b/osframework/source/demos/Demo5/DemoDialog.h
new file mode 100644
index 0000000..89fc43b
--- /dev/null
+++ b/osframework/source/demos/Demo5/DemoDialog.h
@@ -0,0 +1,209 @@
+//////////////////////////////////////////////////////////////////////////
+// DemoDialog.h
+//
+// This class demonstrates how to create a customized dialog box.
+// Most games will want to use custom implementations of the dialog
+// class if they want to go beyond the simple yes/no/ok ones.
+//
+// Basically, all we want to do is implement custom drawing and updating
+// code, as well as do some little things when we get added/removed from
+// the widget manager and handle button presses slightly differently.
+//
+// IMPORTANT: Make sure to read the comments in the .CPP file for the
+// Dialog constructor as they contain important information.
+//////////////////////////////////////////////////////////////////////////
+
+#ifndef __DEMO_DIALOG_H__
+#define __DEMO_DIALOG_H__
+
+#include "SexyAppFramework/Dialog.h"
+
+// This lets us receive slider events
+#include "SexyAppFramework/SliderListener.h"
+
+#include "SexyAppFramework/CheckboxListener.h"
+
+namespace Sexy
+{
+
+ class Graphics;
+
+ // We're going to use slider widgets to control audio volume
+ class Slider;
+
+ // This is the same as a normal button, but it automatically tiles
+ // the butotn image if we make the widget too large
+ class DialogButton;
+
+ class Checkbox;
+
+class DemoDialog : public Dialog, public SliderListener, public CheckboxListener
+{
+
+ protected:
+
+ Slider* mMusicVolumeSlider;
+ Slider* mSfxVolumeSlider;
+ DialogButton* mRandomBtn; // Click this for a random number
+ DialogButton* mClipBtn; // Click this to toggle clipping
+
+
+ public:
+
+ // Alright, fine, we'll use some constants for our widgets!
+ enum
+ {
+ MUSIC_SLIDER_ID,
+ SFX_SLIDER_ID,
+ RANDOM_BTN_ID,
+ CLIP_BTN_ID,
+ FS_CHECKBOX_ID,
+ HARDWARE_CHECKBOX_ID,
+ MESSAGE_BOX_ID,
+ DIALOG_ID
+ };
+
+ // For ease of accessing, we're going to make our checkboxes public,
+ // as the GameApp class will need to query their states as well as
+ // possibly alter the FSCheckbox's state.
+ Checkbox* m3DCheckbox; // Toggle 3D enhanced mode
+ Checkbox* mFSCheckbox; // Toggle fullscreen mode
+
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DemoDialog
+ // Parameters:
+ // theHeader - A string to use for the dialog box header
+ // theBody - A string to use for the body of the text. May use
+ // \n characters to denote new line.
+ //
+ // Returns: none
+ //
+ // Purpose: Creates a new dialog box. You can specify a custom header
+ // and content with the two parameters.
+ //////////////////////////////////////////////////////////////////////////
+ DemoDialog(std::string theHeader, std::string theBody);
+ virtual ~DemoDialog();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Resize
+ // Parameters:
+ // theX - X coordinate to place the dialog at
+ // theY - Y coordinate to place the dialog at
+ // theWidth - Width of the dialog box
+ // theHeight - Height of the dialog box
+ //
+ // Returns: none
+ //
+ // Purpose: Resizes and places the dialog box. We'll also
+ // make sure to position any widgets appropriately based on the new
+ // dimensions.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: SliderVal
+ // Parameters:
+ // theId - ID of the slider object that generated this message
+ // theVal - The value of the slider, i.e. where the thumb image
+ // is located. Leftmost is 0, rightmost is mVal in the slider widget.
+ //
+ // Returns: none
+ //
+ // Purpose: Whenever the thumb image on a slider is moved, this event is
+ // generated. The value passed in ranges from 0 to the maximum value on
+ // the slider, which is set in the slider's mVal variable.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void SliderVal(int theId, double theVal);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CheckboxChecked
+ // Parameters:
+ // theId - Integer ID of the checkbox widget sending this message
+ // checked - Boolean indicating if the widget is checked or not
+ //
+ // Returns: none
+ //
+ // Purpose: Whenever a checkbox widget is checked or unchecked, this
+ // method is called.
+ //////////////////////////////////////////////////////////////////////////
+ void CheckboxChecked(int theId, bool checked);
+};
+
+
+}
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/GameApp.cpp b/osframework/source/demos/Demo5/GameApp.cpp
new file mode 100644
index 0000000..c792683
--- /dev/null
+++ b/osframework/source/demos/Demo5/GameApp.cpp
@@ -0,0 +1,427 @@
+#include "GameApp.h"
+#include "TitleScreen.h"
+#include "Board.h"
+#include "DemoDialog.h"
+#include "SexyAppFramework/WidgetManager.h"
+
+#include "SexyAppFramework/Checkbox.h"
+
+// We will be accessing the resource manager in this demo, so include it's header
+#include "SexyAppFramework/ResourceManager.h"
+
+// Required for playing music
+#include "SexyAppFramework/BassMusicInterface.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+#include "SexyAppFramework/Dialog.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ // mProdName is used for internal purposes to indicate the game that we're working on
+ mProdName = "Demo 5";
+
+ // For internal uses, indicates the current product version
+ mProductVersion = "1.0";
+
+ // This is the text that appears in the title bar of the application window
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+
+ // Indicates the registry location where all registry keys will be read from
+ // and written to. This is stored under the HKEY_CURRENT_USER tree on
+ // Windows systems.
+ mRegKey = "PopCap\\SexyAppFramework\\Demo5";
+
+ // Set the application width/height in terms of pixels here.
+ mWidth = 640;
+ mHeight = 480;
+
+ // By setting this to true, the framework will automatically check to see
+ // if hardware acceleration can be turned on. This doesn't guarantee that it
+ // WILL be turned on, however. Some cards just aren't compatible or have
+ // known issues. Also, cards with less than 8MB of video RAM aren't supported.
+ // There are ways to override the 3D enabled settings, which we will discuss
+ // in a later demo. As a side note, if you want to see if you app is
+ // running with 3D acceleration, first enable debug keys by pressing
+ // CTRL-ALT-D and then press F8. To toggle 3D on/off, press shift-F8. That is just
+ // for testing purposes.
+ mAutoEnable3D = true;
+
+ mBoard = NULL;
+ mTitleScreen = NULL;
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ // Remove our "Board" class which was, in this particular demo,
+ // responsible for all our game drawing and updating.
+ // All widgets MUST be removed from the widget manager before deletion.
+ // More information on the basics of widgets can be found in the Board
+ // class file. If you tried to delete the Board widget before removing
+ // it, you will get an assert. Because our board might not have been
+ // added (if you shut down the app before closing the loading screen),
+ // only remove it if it isn't null.
+ if (mBoard != NULL)
+ mWidgetManager->RemoveWidget(mBoard);
+
+ // Take a look at TitleScreen::ButtonDepress if you haven't already.
+ // It explains a function called SafeDeleteWidget. Notice that we're
+ // directly deleting the widget here: that is because when our app's
+ // destructor is called, it's at the very end of the shutdown sequence
+ // and the safe delete widget list will NOT be processed. Thus we
+ // have to delete the memory manually.
+ delete mBoard;
+
+
+ // If you shut down the app before closing the loading screen, then
+ // it will need to be removed here. The rational for the next two
+ // steps is the same as for Board:
+ if (mTitleScreen != NULL)
+ mWidgetManager->RemoveWidget(mTitleScreen);
+ delete mTitleScreen;
+
+ // We should also free up all the resources that we loaded
+ // for ALL the resource groups. Deleting a group that was
+ // already deleted doesn't do anything, it's ignored.
+ mResourceManager->DeleteResources("Init");
+ mResourceManager->DeleteResources("TitleScreen");
+ mResourceManager->DeleteResources("Game");
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+ // Let the parent class perform any needed initializations first.
+ // This should always be done.
+ SexyAppBase::Init();
+
+ // We need to tell the resource manager to read in all the groups
+ // and information from that main group we made, called ResourceManifest,
+ // in the file "properties/resources.xml". The path/filename are
+ // by default set up to load that file, so you must name it exactly as such.
+ // This doesn't load any resources: it just parses the data and sets
+ // things up for loading.
+ LoadResourceManifest();
+
+ // Next, we want to load our absolutely necessary files that have to
+ // be loaded before anything else can run. You'll notice in the resources.xml
+ // file that we created a group called Init that contains these resources.
+ // You may call it whatever you like. Let's load those resources now.
+ // We do that by calling the LoadResources method of our mResourceManager
+ // variable and specifying in quotes the name of the resource group to
+ // load. This string is case sensitive.
+ if (!mResourceManager->LoadResources("Init"))
+ {
+ mLoadingFailed = true;
+ // This will display an informative error message indicating exactly
+ // what went wrong in the resource loading process.
+ ShowResourceError(true);
+ return;
+ }
+
+ // Now we've loaded the resources, but we need to extract them.
+ // Extraction is the phase that converts sound files to raw WAV
+ // files, and sets up and initializes fonts and palletizes images.
+ // The ResourceGen.exe program, when it generates C++ code for our
+ // resources, also creates a function for EVERY resource group of the
+ // form: Extract<GROUP>Resources, where <GROUP> is the exact name
+ // of the resource group you made. In our case, we made an "Init"
+ // group, so we have an ExtractInitResources method. You pass to it
+ // the pointer to the resource manager. Because an error can occur
+ // during this step, you should make sure to check for it.
+ if (!ExtractInitResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // We also need to load our title screen graphics in, since you can't
+ // display the title screen without any graphics. For an explanation of why
+ // we placed this in a separate group from Init, see properties/resources.xml.
+ // This code works exactly like the above did for the Init group.
+ if (!mResourceManager->LoadResources("TitleScreen"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractTitleScreenResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // Now let's create and add our title screen to the widget manager
+ mTitleScreen = new TitleScreen(this);
+ mTitleScreen->Resize(0, 0, mWidth, mHeight);
+
+ // Let's let the title screen initialize it's widgets and data
+ // before adding it to the widget manager:
+ mTitleScreen->Init();
+
+ mWidgetManager->AddWidget(mTitleScreen);
+
+ // Let's also load in some music to play. We use the mMusicInterface
+ // member for all our music needs, which requires the BassMusicInterface.h
+ // header to be loaded, since we use the library BASS to play our music.
+ // We can load in WAV, OGG, or MP3 files. BASS also supports a number
+ // of tracker formats, such as .it, .xm, .mod, etc. It also supports
+ // a format called MO3, which is a compressed version of a tracker
+ // file. For this example, we will use the MO3 from AstroPop.
+ // Why? Cause it's ours and we won't get sued for using it.
+ // We load our file manually, we do not use the resource manager for this.
+ // The first parameter is the ID to associate the song with. Just as sounds
+ // have IDs, so do music tracks.
+ mMusicInterface->LoadMusic(0, "music/music.mo3");
+
+ // Let's load another copy of the file. Why? In order to fade from one
+ // track to another, we need two instances of the track on different
+ // channels. Let's load it again and give it a different ID, 1.
+ mMusicInterface->LoadMusic(1, "music/music.mo3");
+
+ // Now we need to start playing a track. Because we are using an MO3
+ // and because the original format was a .it (Impulse Tracker) file,
+ // there are actually multiple songs inside of it, differentiated
+ // by various offsets. If you were just playing a single MP3 or OGG
+ // or WAV file instead of a tracker file, you would ignore this
+ // and use the default offset of 0 for the start of the song.
+ // Because the person that made the song file was nice and
+ // told us which offsets equated to which song pieces, I already
+ // know the magic offset numbers. In this particular case, the
+ // song for the intro screen is at offset 0, and the song
+ // for the main game music is at offset 9. Our music artist
+ // also was kind enough to put in tracker looping commands,
+ // so you'll notice that the songs play over and over. A discussion
+ // of tracker file formats is beyond the scope of this. Again,
+ // if you are just playing a WAV/OGG/MP3, you use offset 0 (the default)
+ // to indicate that you want to start playing from the start of the song.
+ //
+ // You can use PlayMusic to instantly play the track, or, like below,
+ // you can use FadeIn to smoothly fade the song in. The first parameter
+ // for both methods is the channel or song id that was used when the
+ // track was first loaded (In our case, either 0 or 1 works). For both,
+ // the second parameter is the offset to start playing at. Again, I just
+ // happen to know that the intro song is at offset 0. For FadeIn, the
+ // third parameter is how quickly to fade in, out of 1.0. The last parameter
+ // for both indicates whether or not you want to loop. This is kind of weird,
+ // but specify "false" to loop and "true" to not loop.
+ mMusicInterface->FadeIn(0, 0, 0.002, false);
+
+ // We'll cover changing the music and sound volumes in a later demo.
+
+ // Next, we need to know how many resources there are to load.
+ // This is necessary so we can display our progress bar on the title screen
+ // and make it be the appropriate length. There's a variable in SexyAppBase
+ // called mNumLoadingThreadTasks which holds the number of resources to
+ // load in the LoadingThreadProc function. You get the number of resources
+ // in a given group with a call to the resource manager's GetNumResources function
+ // for each of your groups that you are going to load:
+ mNumLoadingThreadTasks = mResourceManager->GetNumResources("Game");
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+ // For each of the groups that we want to load,
+ // we first have to instruct the resource manager to begin the
+ // loading phase and initialize its internal variables.
+ // We do that with the StartLoadResources method and pass in the
+ // exact string name of the group to begin loading:
+ mResourceManager->StartLoadResources("Game");
+
+ // Now we need to load each individual resource. We will loop,
+ // calling LoadNextResource at the start. When it returns true,
+ // there are no more resources to load for the current group.
+ // LoadNextResource knows what group to load from because
+ // of the call to StartLoadResources above:
+ while (mResourceManager->LoadNextResource())
+ {
+ // The SexyAppBase variable, mCompletedLoadingThreadTasks, indicates the
+ // total number of resources that have so far been loaded. This is used
+ // to tell our loading screen the % progress we've made. See TitleScreen::Draw
+ // for an example of how this is used. We need to increment this value
+ // ourselves everytime we load a resource:
+ mCompletedLoadingThreadTasks++;
+
+ // If there was an error loading our resource, the resource manager
+ // will tell us to shut down by setting mShutdown to true. If that
+ // happened, immediately abort and return:
+ if (mShutdown)
+ return;
+
+ // Remember in demos 1-3 how we had the Board class call MarkDirty
+ // every update? Well, the title screen doesn't need to be such a hog.
+ // The title screen only needs to repaint when its progress bar changes
+ // size. The progress bar only changes size when a resource gets loaded.
+ // Because the game app is the only one that knows when this happens,
+ // the game app will be the one to tell the title screen that it's a
+ // dirty, dirty widget and that it needs a good and proper repainting.
+ // You COULD make an update method for the title screen and mark dirty
+ // every frame. But because this consumes more CPU time, it will take
+ // longer to load our resources. And since you want the loading time
+ // to be as quick as possible, you should only repaint when you need to.
+ mTitleScreen->MarkDirty();
+ }
+
+ // Just like in our Init function, after loading resources we
+ // need to extract them. Let's do that. Let's also ask the resource
+ // manager if an error occurred in the above loop that we
+ // didn't yet catch. We do that with the HadError method:
+ if (mResourceManager->HadError() || !ExtractGameResources(mResourceManager))
+ {
+ ShowResourceError(false);
+ mLoadingFailed = true;
+ return;
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ // When we're actually loading resources, we'll set the
+ // mLoadingFailed variable to "true" if there were any problems
+ // encountered along the way. If that is the case, just return
+ // because we won't want the user to get to the main menu or any
+ // other part of the game. We will want them to exit out.
+ if (mLoadingFailed)
+ return;
+
+
+ // We aren't going to make and add the Board class here like we
+ // did in the previous demos. Instead, since we are done loading
+ // everything, we're going to tell the title screen that
+ // we're done and that it should unhide the continue link and let
+ // the user enter the game.
+ mTitleScreen->LoadingComplete();
+
+ // Remember: since we didn't give our title screen an Update method,
+ // this class is responsible for telling it when to repaint. If we
+ // don't mark it dirty, you won't see the hyperlink widget
+ // appear. So mark it dirty now:
+ mTitleScreen->MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::TitleScreenIsFinished()
+{
+ mTitleScreen = NULL;
+ mBoard = new Board(this);
+
+ // Now that the title screen is done, we don't need its resources
+ // wasting memory. Let's delete all of its resources. We do that
+ // by calling DeleteResources and specifying the exact name of the
+ // resource group we want to free up:
+ mResourceManager->DeleteResources("TitleScreen");
+
+ mBoard->Resize(0, 0, mWidth, mHeight);
+ mWidgetManager->AddWidget(mBoard);
+
+ // This is a new step: We're going to tell the WidgetManager
+ // that keyboard input and mouse wheel notifications should go to
+ // the board object. This way, we'll be able to respond to keypresses:
+ mWidgetManager->SetFocus(mBoard);
+
+
+
+ // Let's fade out the intro song and fade in the main game music.
+ // FadeOut works just like FadeIn did in Init() but with some
+ // slightly different parameters. The first, is like with FadeIn and
+ // PlayMusic, the channel or song id that you want to mess with.
+ // The second indicates that the song fading out should stop when
+ // done, if it is true. The final parameter indicates how fast
+ // to fade out, and is from 0 to 1.
+ mMusicInterface->FadeOut(0, true, 0.004);
+
+ // Let's fade in the main game music. This is the same as in Init.
+ // The only difference is we're using 1 instead of 0 for our song id.
+ // Why? Well, channel/song id 0 is being used to fade out the
+ // previously playing track, we can't use it to also fade in.
+ // That's why we loaded another copy of the song into channel 1.
+ // Again, as explained in Init, I happen to know that offset 9
+ // is the start of the main game music.
+ mMusicInterface->FadeIn(1, 9, 0.002, false);
+
+ // We'll cover changing the music and sound volumes in our options dialog.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Dialog* GameApp::NewDialog(int theDialogId, bool isModal, const std::string& theDialogHeader,
+ const std::string& theDialogLines, const std::string& theDialogFooter, int theButtonMode)
+{
+ // Rather than dupliate a lengthy explanation, check out the top of DemoDialog.cpp for a complete description
+ // of what all the parameters and functions are.
+ Dialog* d = new Dialog(IMAGE_DIALOG_BOX, IMAGE_DIALOG_BUTTON, theDialogId, isModal,
+ StringToSexyStringFast(theDialogHeader), StringToSexyStringFast(theDialogLines), StringToSexyStringFast(theDialogFooter), theButtonMode);
+
+ d->SetButtonFont(FONT_DEFAULT);
+ d->SetLinesFont(FONT_DEFAULT);
+ d->SetHeaderFont(FONT_DEFAULT);
+
+ d->SetColor(Dialog::COLOR_HEADER, Color::Black);
+ d->SetColor(Dialog::COLOR_LINES, Color::Black);
+
+ d->mSpaceAfterHeader = 30;
+ d->Resize(100, 100, 300, 250);
+
+ return d;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::SwitchScreenMode(bool wantWindowed, bool is3d)
+{
+ // Let the app handle the actual details of this call...
+ SexyAppBase::SwitchScreenMode(wantWindowed, is3d);
+
+ // We can see if the options dialog is up with a call to
+ // GetDialog. You pass GetDialog the unique ID of the dialog box,
+ // and if it exists it is returned to you, otherwise NULL is returned.
+ DemoDialog* d = (DemoDialog*) GetDialog(DemoDialog::DIALOG_ID);
+
+ // Set the checkbox state to our windowed state
+ if ((d != NULL) && (d->mFSCheckbox != NULL))
+ d->mFSCheckbox->SetChecked(!wantWindowed);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::ButtonPress(int theId)
+{
+ if (theId == DemoDialog::MESSAGE_BOX_ID + 2000)
+ KillDialog(theId - 2000);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::SetFocusToBoard()
+{
+ if (mBoard != NULL)
+ mWidgetManager->SetFocus(mBoard);
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/GameApp.h b/osframework/source/demos/Demo5/GameApp.h
new file mode 100644
index 0000000..629055a
--- /dev/null
+++ b/osframework/source/demos/Demo5/GameApp.h
@@ -0,0 +1,173 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+// We place all our classes inside the "Sexy" namespace to avoid name collisions
+// with other libraries that might be added.
+namespace Sexy
+{
+
+ // The GameApp class will be responsible for creating a class by the name
+ // of "Board", which we will use to do all the game's drawing, input processing,
+ // etc. Board is the second most important class and is where almost all of your
+ // game logic code will originate from. It is a widget, which allows for
+ // easy and automatic invocation of its update, drawing, and input processing
+ // functions. See the "Board" class for more details.
+ class Board;
+
+ // We're going to be responsible for creating and adding the title screen widget
+ class TitleScreen;
+
+ // We're going to learn about making and using dialog boxes in this demo
+ class Dialog;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+ TitleScreen* mTitleScreen;
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreenIsFinished
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called by the TitleScreen widget when it is about to close
+ // down, this indicates that we should now add the board widget and
+ // start the game.
+ //////////////////////////////////////////////////////////////////////////
+ void TitleScreenIsFinished();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: NewDialog
+ // Parameters:
+ // theDialogId - Unique ID to give this dialog box
+ // isModal - If true, only itself and widgets above it receive
+ // input events.
+ // theDialogHeader - String to display in the header part of the dialog box
+ // theDialogLines - String to use for the body of the dialog. May use
+ // \n characters to indicate new lines.
+ // theDialogFooter - If the button mode is BUTTONS_FOOTER, this is the text
+ // to use for the button, otherwise ignored.
+ // theButtonMode - One of 3 settings: Dialog::BUTTONS_YES_NO creates two
+ // "Yes" "No" buttons, Dialog::BUTTONS_OK_CANCEL creates two
+ // "OK" "Cancel" buttons, Dialog::BUTTONS_FOOTER creates one
+ // button with the text from theDialogFooter.
+ //
+ // Returns: A new dialog pointer for use by SexyAppBase's DoDialog method.
+ //
+ // Purpose: SexyAppBase contains a convenience function, DoDialog, that relies on
+ // this overriden function. DoDialog calls NewDialog which instructs it how to make
+ // a dialog box. You should use DoDialog to create and add your dialog boxes.
+ // The reason for this function is to allow for customized dialog boxes and to avoid
+ // having to have a gigantic function with every possible parameter to pass to the Dialog's
+ // constructor.
+ //////////////////////////////////////////////////////////////////////////
+ virtual Dialog* NewDialog(int theDialogId, bool isModal, const std::string& theDialogHeader,
+ const std::string& theDialogLines, const std::string& theDialogFooter, int theButtonMode);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: SwitchScreenMode
+ // Parameters:
+ // wantWindowed - True indicates that the game should be in windowed mode
+ // is3d - True indicates that 3D acceleration should be turned on
+ //
+ // Returns: none
+ //
+ // Purpose: Take a look at DemoDialog. In it, you can toggle whether or not
+ // the game is fullscreen. What if though, the user presses ALT-ENTER to force
+ // the game to be windowed/fullscreen while that dialog is up? The fullscreen
+ // checkbox should update to reflect the current windowed state. It's a little
+ // thing to do but if you don't wind up doing it, it can be a bit wonky
+ // for the user if the checkbox state gets out of sync with the resolution and
+ // could wind up irritating them.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void SwitchScreenMode(bool wantWindowed, bool is3d);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonPress:
+ // Parameters:
+ // theId - ID of the button pressed
+ //
+ // Returns: none
+ //
+ // Purpose: Called when the button is pressed, but before the mouse is
+ // released (which would instead generate a ButtonDepress event).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonPress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: SetFocusToBoard
+ //
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: When a dialog box closes, this is called to set keyboard focus
+ // to the board widget.
+ //////////////////////////////////////////////////////////////////////////
+ void SetFocusToBoard();
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/TitleScreen.cpp b/osframework/source/demos/Demo5/TitleScreen.cpp
new file mode 100644
index 0000000..49caebd
--- /dev/null
+++ b/osframework/source/demos/Demo5/TitleScreen.cpp
@@ -0,0 +1,205 @@
+#include "TitleScreen.h"
+
+#include "GameApp.h"
+
+// Contains all the resources from the resources.xml file in our
+// properties directory. See that file for more information.
+#include "Res.h"
+
+
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Image.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Rect.h"
+#include "SexyAppFramework/HyperlinkWidget.h"
+
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::TitleScreen(GameApp *pApp)
+{
+ mApp = pApp;
+ mContinueLink = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::~TitleScreen()
+{
+ delete mContinueLink;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Init(void)
+{
+ // A hyperlink widget is basically the same thing as a button widget
+ // but with some slight differences. It is meant to emulate the look
+ // and feel of an internet hyperlink. We create the widget the
+ // same way we created a button widget in Demo3, specifying that
+ // this class is to listen to the widget events.
+ mContinueLink = new HyperlinkWidget(1, this);
+
+ // We need to set the font to use. In previous demos, we had
+ // a variable inside of GameApp that held the font. Now that we're
+ // using the resource manager, we'll use the main (and only) one
+ // that we declared from there. Remember how we named it FONT_DEFAULT?
+ // Well, you can use that name exactly now to reference it.
+ mContinueLink->SetFont(FONT_DEFAULT);
+
+ // Like the button widget, we can set the text to display:
+ mContinueLink->mLabel = _S("CLICK TO CONTINUE");
+
+ // And like the button widget, we can set the default and over colors.
+ // We don't use the SetColor method though, we just directly
+ // set mColor and mOverColor:
+ mContinueLink->mColor = Color(255, 255, 255);
+ mContinueLink->mOverColor = Color(0, 255, 0);
+ mContinueLink->mUnderlineSize = 1;
+
+
+ // We're not going to place the widget just yet. Why? Well,
+ // the TitleScreen hasn't been added to the widget manager.
+ // We'll wait until the AddedToManager method is called before
+ // adding it, just like in Demo3.
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::AddedToManager(WidgetManager *theWidgetManager)
+{
+ Widget::AddedToManager(theWidgetManager);
+
+ // Just like with the button widget from Demo3, we're going to add our
+ // hyperlink widget in this method. However, we want the link to be
+ // invisible at first. Why? Well, while we're loading our resources,
+ // we don't want the user to be able to just start the game. We want
+ // them to wait until it's all loaded and ready to go. Once everything
+ // is loaded, then we'll make it visible and let them click to play.
+ // We do that with the SetVisible command:
+ mContinueLink->SetVisible(false);
+
+ // Just making it invisible isn't enough. Technically the user could
+ // still click on it even though they can't see it. We have to
+ // disable the widget to prevent it from receiving input:
+ mContinueLink->SetDisabled(true);
+
+ // Let's resize it to be at the bottom of the screen, and to be exactly
+ // the width/height of the lable that we set. Again, we use our friend
+ // the Resize function. However, note that we're setting the height to
+ // be a bit larger than that of the string. That's because the underline
+ // part of the hyperlink widget (whose thickness can be controlled via mUnderlineSize)
+ // draws a little below the string. If you didn't make the height a little
+ // larger, the line would be clipped and thus wouldn't be visible.
+ int labelWidth = FONT_DEFAULT->StringWidth(mContinueLink->mLabel);
+ int labelHeight = FONT_DEFAULT->GetHeight();
+ mContinueLink->Resize( mWidth / 2 - labelWidth / 2,
+ mHeight - labelHeight - 40,
+ labelWidth,
+ labelHeight+4);
+
+ // Almost done. Let's make it so that when the user mouses over the widget,
+ // that the cursor changes from the standard Windows arrow to a hand icon.
+ // We do that by setting the variable mDoFinger to true. This instructs the
+ // WidgetManager to chagne the cursor to the hand/finger icon when the mouse
+ // is inside the widget's bounds, and to reset it back to the arrow when it
+ // is not. Note that ALL widgets have this functionality.
+ mContinueLink->mDoFinger = true;
+
+ // And finally, we add the widget just like we added the button widget
+ // from demo 3 and the Board widget.
+ theWidgetManager->AddWidget(mContinueLink);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::RemovedFromManager(WidgetManager *theWidgetManager)
+{
+ // This is just like what we did in Board in Demo3.
+ // Let our parent class know about the removal, and get rid
+ // of our hyperlink widget.
+ Widget::RemovedFromManager(theWidgetManager);
+ theWidgetManager->RemoveWidget(mContinueLink);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Draw(Graphics *g)
+{
+ // Instead of having to say Color(0, 0, 0) or Color(255, 255, 255)
+ // for black/white, you can use Color::Black and Color::White.
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+
+ // We want to draw our loader bar to indicate the progress made in
+ // loading all our resources. As you recalll, GameApp::LoadingThreadProc is
+ // the thread that is actually loading everything. The app has a function,
+ // GetLoadingThreadProgress, that returns a value from 0.0 to 1.0 indicating
+ // the % complete it is. We will multiply this % complete by the width
+ // of our progress bar, so that we give the illusion of a growing bar.
+ int loaderBarWidth = IMAGE_LOADER_BAR->GetWidth();
+ int drawWidth = (int) (mApp->GetLoadingThreadProgress() * (double)loaderBarWidth);
+ if (drawWidth > 0)
+ {
+ // As you may recall from Demo3 where we drew the frames of animation
+ // for the lightning image, the DrawImage call can take a source rectangle
+ // which indicates what chunk of the original image we want to draw.
+ // In our case, we want to start from from the upper left corner of
+ // the loader bar, but we only want to draw "drawWidth" wide. This will
+ // give the illusion that the progress bar is expanding as the resources
+ // are loaded in.
+ g->DrawImage(IMAGE_LOADER_BAR, mWidth / 2 - loaderBarWidth / 2,
+ 400,
+ Rect(0, 0, drawWidth, IMAGE_LOADER_BAR->GetHeight()));
+ }
+
+ // If our hyperlink widget is false, let's instead draw some
+ // "Loading" text (er, actually in this case it's an image) where
+ // it is located.
+ if (mContinueLink->mVisible == false)
+ g->DrawImage(IMAGE_LOADER_LOADINGTXT, mContinueLink->mX - 10, mContinueLink->mY - 80);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::LoadingComplete()
+{
+ // Since the app told us that we're done loading all our resources,
+ // let's unhide and enable our continue link so the user can start
+ // playing.
+ mContinueLink->SetVisible(true);
+ mContinueLink->SetDisabled(false);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::ButtonDepress(int theId)
+{
+ if (theId == 1)
+ {
+ // Our hyperlink widget was pressed. We want to remove ourselves
+ // and the hyperlink widget, and tell the app to display the
+ // main board and get the game started.
+ // You might be thinking, "If I delete the title screen and
+ // hyperlink, won't I crash the program?" Yes, you will. That's
+ // why we aren't going to delete them using "delete". We're going
+ // to use SexyAppBase's SafeDeleteWidget method. This places the
+ // widget in a queue that is processed after all widgets and data
+ // get processed, and is then deleted at a time that is safe
+ // and appropriate. We still have to remove ourself and the
+ // hyperlink widget from the WidgetManager. We can easily access
+ // the WidgetManager, as it is a public variable in our game app.
+ mApp->mWidgetManager->RemoveWidget(this);
+ mApp->mWidgetManager->RemoveWidget(mContinueLink);
+ mApp->SafeDeleteWidget(this);
+ mApp->SafeDeleteWidget(mContinueLink);
+ mContinueLink = NULL;
+
+ // Now let's tell the game app that it's ok to add the board widget:
+ mApp->TitleScreenIsFinished();
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/TitleScreen.h b/osframework/source/demos/Demo5/TitleScreen.h
new file mode 100644
index 0000000..c55776d
--- /dev/null
+++ b/osframework/source/demos/Demo5/TitleScreen.h
@@ -0,0 +1,125 @@
+#ifndef __TITLE_SCREEN_H__
+#define __TITLE_SCREEN_H__
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+namespace Sexy
+{
+
+class GameApp;
+class Graphics;
+class WidgetManager;
+class HyperlinkWidget;
+
+
+// If you forgot about the ButtonListener class, you should review Demo3.
+// The hyperlink widget is essentially the same thing as a button widget,
+// and emits the same messages that a button does. Thus, to act on its
+// messages we derive from the ButtonListener class.
+class TitleScreen : public Widget, public ButtonListener
+{
+
+private:
+
+ GameApp* mApp;
+ HyperlinkWidget* mContinueLink;
+
+public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreen
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ TitleScreen(GameApp* pApp);
+
+ virtual ~TitleScreen();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called BEFORE the title screen is added to the widget manager
+ // by GameApp. This initializes some things like the images used for
+ // our hyperlink widget.
+ //////////////////////////////////////////////////////////////////////////
+ void Init(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager. This is where
+ // we'll do all our display routines for the loading screen.
+ //////////////////////////////////////////////////////////////////////////
+ void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingComplete
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called manually by GameApp when we are done loading all
+ // resources, to let the title screen know that it should unhide and
+ // enable the continue link, so the user can start playing the game.
+ //////////////////////////////////////////////////////////////////////////
+ void LoadingComplete();
+};
+
+}
+
+#endif //__TITLE_SCREEN_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Demo5/main.cpp b/osframework/source/demos/Demo5/main.cpp
new file mode 100644
index 0000000..812e585
--- /dev/null
+++ b/osframework/source/demos/Demo5/main.cpp
@@ -0,0 +1,50 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Drawing differently if 3D or 2D
+// * Using Translate instead of using XYs
+// * Keyboard input, setting focus
+// * Widgets: Dialog box, sliders, an options dialog box
+// * Advanced widget topics: mClip, using Layout_ flags, using images
+// * Making an options dialog box and controlling fullscreen, volumes,
+// 3D settings.
+// * Parallax scrolling
+// * Random numbers
+// * Catching memory leaks
+// * Profiling
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+// The SexyAppFramework resides in the "Sexy" namespace. As a convenience,
+// you'll see in all the .cpp files "using namespace Sexy" to avoid
+// having to prefix everything with Sexy::
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+ // Make sure to set this. Some classes, like the exception handler and custom cursors
+ // will need to use it.
+ gHInstance = hInstance;
+
+ // Create and initialize our game application.
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+
+ // Starts the entire application: sets up the resource loading thread and
+ // custom cursor thread, and enters the game loop where the application
+ // will remain until it is shut down. You will most likely not need to
+ // override this function.
+ anApp->Start();
+
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Hun-garr/Board.cpp b/osframework/source/demos/Hun-garr/Board.cpp
new file mode 100644
index 0000000..09594f1
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Board.cpp
@@ -0,0 +1,2189 @@
+#pragma warning(disable:4244)
+#pragma warning(disable:4018)
+#include "Board.h"
+#include "GameApp.h"
+#include "Res.h"
+#include "LevelupEffect.h"
+#include "GameOverEffect.h"
+#include "OptionsDialog.h"
+
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Color.h"
+#include "SexyAppFramework/Rect.h"
+#include "SexyAppFramework/ButtonWidget.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ImageFont.h"
+#include "SexyAppFramework/SoundManager.h"
+#include "SexyAppFramework/SoundInstance.h"
+#include "SexyAppFramework/Buffer.h"
+#include "SexyAppFramework/MusicInterface.h"
+
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+// VC6 workaround
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+using namespace Sexy;
+
+// How much faster the beam gets when you eat a planet
+const float BEAM_INC_SPEED = 0.05f;
+
+// Fastest the beam can go
+const float MAX_BEAM_SPEED = 2.5f;
+
+// Table of random planet names
+const int NUM_PLANET_NAMES = 28;
+const SexyString PLANET_NAME[] =
+{_S("Deev-z"), _S("SEN-Hen"), _S("Wallach IX"), _S("Salusa Secundus"), _S("Ridiculous Prime"), _S("Architekt V"),
+_S("Robot Republica"), _S("Ix"), _S("XOLDOG4000"), _S("Kliprok"), _S("TR-909"), _S("TR-808"), _S("TB-303"),
+_S("DTR011"), _S("dTech"), _S("Rotwang"), _S("Sukhtek"), _S("Romulox"), _S("Dob Reevz"), _S("Skull XII"),
+_S("Beefy Prime"), _S("Haas"), _S("Reifenrath"), _S("Gehner Subulon"), _S("ACE-DOGG"), _S("Charolastra"), _S("Nixd"), _S("BASS")};
+
+// Table of random planet exports:
+const int NUM_PLANET_EXPORTS = 23;
+const SexyString PLANET_EXPORTS[] =
+{_S("Happiness"), _S("Donkeys"), _S("Rabies"), _S("AstroPop"), _S("Idiocy"), _S("Minimal Techno"),
+_S("Citizens"), _S("Pain-relieving Pants"), _S("The Quad-Laser"), _S("Septic Systems"), _S("Video Games"),
+_S("Robots"), _S("Plaid"), _S("Octagons"), _S("Gingivitis"), _S("Recognizers"), _S("Electro"), _S("Sauce"),
+_S("Kindness"), _S("Bison"), _S("Saline"), _S("Cholera"), _S("TyperShark")};
+
+
+//////////////////////////////////////////////////////////////////////////
+// Inline functions
+//////////////////////////////////////////////////////////////////////////
+
+// Given an X coordinate, returns the grid column it maps to
+inline int GetCol(float x)
+{
+ return (int) ((x - GRID_START_X) / GRID_PIX_SIZE);
+}
+
+// Given a Y coordinate, returns the grid row it maps to
+inline int GetRow(float y)
+{
+ return (int) ((y - GRID_START_Y) / GRID_PIX_SIZE);
+}
+
+// Given a grid column, returns the X pixel of the left edge of it
+inline float GetColPix(int col)
+{
+ return col * GRID_PIX_SIZE + GRID_START_X;
+}
+
+// Given a grid row, returns the Y pixel of the top edge of it
+inline float GetRowPix(int row)
+{
+ return row * GRID_PIX_SIZE + GRID_START_Y;
+}
+
+// Given an X coordinate, adjusts it so that it is aligned
+// with the left edge of the grid square it's over
+inline float GetAlignedX(float x)
+{
+ return (float)GetCol(x) * GRID_PIX_SIZE + GRID_START_X;
+}
+
+// Given a Y coordinate, adjusts it so that it is aligned
+// with the top edge of the grid square it's over
+inline float GetAlignedY(float y)
+{
+ return (float)GetRow(y) * GRID_PIX_SIZE + GRID_START_Y;
+}
+
+// Checks to see if the Y coordinate is in the grid's bounds.
+// Needs to know if Hun-garr is oriented vertically or not
+inline bool YCoordInBounds(float y, bool vertical)
+{
+ int h = IMAGE_HUNGARR_HORIZ->GetHeight() / 2;
+
+ if ( (vertical && (y > GRID_START_Y + h) && (y < GRID_END_Y - h)) ||
+ (!vertical && (y > GRID_START_Y + 7) && (y < GRID_END_Y - 4)) )
+ return true;
+
+ return false;
+}
+
+// Checks to see if the X coordinate is in the grid's bounds
+inline bool XCoordInBounds(float x)
+{
+ if ((x > GRID_START_X + 9) && (x < GRID_END_X - 2))
+ return true;
+
+ return false;
+}
+
+// Checks to see if the column number points to a valid grid column
+inline bool ValidCol(int col)
+{
+ return ((col >= 0) && (col < GRID_WIDTH));
+}
+
+// Checks to see if the row number points to a valid grid row
+inline bool ValidRow(int row)
+{
+ return ((row >= 0) && (row < GRID_HEIGHT));
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::Board(GameApp* theApp)
+{
+ mApp = theApp;
+ mHungarrIsVertical = true;
+ mLineSpeed = 1.0f;
+
+ mNumPlanetsEaten = 0;
+ mPercentComplete = 0;
+
+ mBorderHue = 0;
+ mFlashCount = 0;
+ mLives = 3;
+ mLevel = 1;
+ mScore = 0;
+ mBeamPulseAmt = 30;
+ mBeamPulseVal = 128;
+
+ // Put Hun-garr in a valid spot
+ UpdateHungarrPosition(GetColPix(4), GetRowPix(4));
+
+ // Create a 2D array to hold the grid fill state that's of size
+ // GRID_WIDTH x GRID_HEIGHT
+ mGridState = new GridTile* [GRID_HEIGHT];
+
+ //vc6 workaround:
+ int i;
+ for (i = 0; i < GRID_HEIGHT; i++)
+ mGridState[i] = new GridTile[GRID_WIDTH];
+
+ mFillDirection = FILL_LEFT;
+ mFillSpeed = 20.0f;
+ mPlanetSpeed = 1.5f;
+ mPopulationEaten = mTotalPopulationEaten = 0;
+ mPauseLevel = 0;
+
+ // Create our starfield
+ for (i = 0; i < MAX_STARS; i++)
+ {
+ Star s;
+ s.mX = Rand() % mApp->mWidth;
+ s.mY = Rand() % mApp->mHeight;
+
+ int r = Rand() % 3;
+ switch (r)
+ {
+ case 0: s.mSpeed = 0.5f; s.mColor = Color(200, 200, 200, 128); break;
+ case 1: s.mSpeed = 0.25f; s.mColor = Color(100, 100, 100, 128); break;
+ case 2: s.mSpeed = 0.1f; s.mColor = Color(50, 50, 50, 128); break;
+ }
+
+ mStarField[i] = s;
+ }
+
+ mLevelupEffect = new LevelupEffect();
+ mGameOverEffect = new GameOverEffect();
+ mOptionsBtn = NULL;
+
+
+ // The shorting out, electrical sound of the beams moving. We use a SoundInstance pointer
+ // because we want to loop the sound while the beam is moving, and stop it when done.
+ // This is easiest done manually.
+ mShortSound = mApp->mSoundManager->GetSoundInstance(SOUND_BEAM_MOVING);
+
+ InitLevel(1);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+ // Frees up the memory allocated to our manual SoundInstance pointer. Required.
+ mShortSound->Release();
+
+ for (int i = GRID_HEIGHT; i > 0; --i)
+ delete[] mGridState[i - 1];
+ delete[] mGridState;
+
+ delete mLevelupEffect;
+ delete mGameOverEffect;
+ delete mOptionsBtn;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+ // If paused, return and don't markdirty, whcih prevents drawing
+ // and the stealing of CPU cycles
+ if (mPauseLevel > 0)
+ return;
+
+ Widget::Update();
+
+
+ // HSL is an alternative to specifying an RGB color format.
+ // Using HSL lets us easily do the hyper blinking crazy weird
+ // flashing effect commonly found in old games, such as Robotron.
+ // Below, we increment the value by 6 per update. The &0xFF is an
+ // easy way to clamp the value between 0 and 255 instead of having to
+ // do a separate if (mHue > 255) mHue -= 255. This lets the value
+ // rollover and keep cycling.
+ if (--mFlashCount > 0)
+ mBorderHue = (mBorderHue + 6) % 0xFF;
+
+ if (mGameOverEffect->IsActive())
+ {
+ mGameOverEffect->Update();
+
+ // If the game over effect is in the proper state, we will
+ // be able to initialize the first level so that when it fades out,
+ // the level will appear underneath it.
+ if (mGameOverEffect->CanInitFirstLevel())
+ {
+ //Reset the critical variables:
+ mBorderHue = 0;
+ mFlashCount = 0;
+ mLives = 3;
+ mLevel = 1;
+ mScore = 0;
+ mFillDirection = FILL_LEFT;
+ mFillSpeed = 20.0f;
+ mPlanetSpeed = 1.5f;
+ mPopulationEaten = mTotalPopulationEaten = 0;
+ mPauseLevel = 0;
+ mLineSpeed = 1.0f;
+ mPlanetIdxCount.clear();
+ mExportIdxCount.clear();
+ mOptionsBtn->SetVisible(true);
+ mApp->mMusicInterface->FadeIn(0);
+ InitLevel(1);
+ }
+ }
+
+ // Make the beams that the player emits pulse with intensity
+ mBeamPulseVal += mBeamPulseAmt;
+ if (mBeamPulseVal >= 255)
+ {
+ mBeamPulseVal = 255;
+ mBeamPulseAmt = -mBeamPulseAmt;
+ }
+ else if (mBeamPulseVal <= 0)
+ {
+ mBeamPulseVal = 0;
+ mBeamPulseAmt = -mBeamPulseAmt;
+ }
+
+ MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::UpdateF(float theFrac)
+{
+ if (mPauseLevel > 0)
+ return;
+
+ if (mFilling)
+ {
+ // If the beams have been released, update the filling of the grid
+ float amt = mFillSpeed * theFrac;
+
+ if (mFillDirection == FILL_RIGHT)
+ FillRight(amt);
+ else if (mFillDirection == FILL_LEFT)
+ FillLeft(amt);
+ else if (mFillDirection == FILL_UP)
+ FillUp(amt);
+ else if (mFillDirection == FILL_DOWN)
+ FillDown(amt);
+
+ // Check what % full the filled regions are if it's done filling
+ if (!mFilling)
+ UpdatePercentComplete();
+
+ }
+
+ // Make the bonus text float upwards and fade it out over time.
+ std::vector<BonusText>::iterator it = mBonusText.begin();
+ while (it != mBonusText.end())
+ {
+ BonusText* bt = &*it;
+ bt->mY -= 1.00f * theFrac;
+ bt->mHue = (bt->mHue + 5) % 0xFF;
+
+ if (--bt->mAlpha <= 0)
+ {
+ //Totally faded out, remove it
+ it = mBonusText.erase(it);
+ }
+ else
+ ++it;
+ }
+
+
+ // Move the starfield. If a start gets beyond the screen,
+ // randomly place it offscreen again
+ int i;
+ for (i = 0; i < MAX_STARS; i++)
+ {
+ Star* s = &mStarField[i];
+ s->mX += s->mSpeed;
+ if (s->mX > mWidth)
+ {
+ s->mX = -5;
+ s->mY = Rand() % mHeight;
+ }
+ }
+
+ if ((!mMovingLine1.mDone || !mMovingLine2.mDone) && !mGameOverEffect->IsActive())
+ MoveLines(theFrac);
+
+
+ // If we're allowed to show the planets and the game isn't paused and the game
+ // over effect isn't playing, then we can move the planets around
+ if ((!mLevelupEffect->HidePlanets() || (mPauseLevel > 0)) && !mGameOverEffect->IsActive())
+ {
+ // Move the planets
+ int w = IMAGE_PLANETS->GetCelWidth();
+ int h = IMAGE_PLANETS->GetCelHeight();
+
+ // Instead of playing the explosion sound every time a planet gets destroyed, we'll
+ // only play it once. That way, if you destroy more than 1 planet in one go, you won't
+ // hear the same sound played multipled times at once, which would result in this loud,
+ // hideous, flanging sound.
+ bool playSound = false;
+ for (int i = 0; i < mPlanets.size(); i++)
+ {
+ Planet* p = &mPlanets[i];
+
+ // Again, the timer is used solely for incrementing the animation frames
+ ++p->mTimer;
+
+ if (!p->mExploding)
+ {
+ if (MovePlanet(p, theFrac))
+ playSound = true; // Returns true if the planet is to explode
+ }
+ else
+ {
+ if ((p->mTimer % p->mExplodeSpeed) == 0)
+ {
+ if (++p->mExplodeFrame >= IMAGE_BOMB_RADIAL_DEATH->mNumCols)
+ {
+ mPlanets.erase(mPlanets.begin() + i);
+ --i;
+ }
+ }
+ }
+ }
+
+ if (playSound)
+ mApp->PlaySample(SOUND_PLANET);
+ }
+
+ // update and move the particles. When they have reached
+ // their last frame, remove them.
+ for (i = 0; i < mParticles.size(); i++)
+ {
+ Particle* p = &mParticles[i];
+ ++p->mTimer;
+
+ p->mX += p->mVX * theFrac;
+ p->mY += p->mVY * theFrac;
+ p->mVY += 0.1f;
+ if (p->mTimer % 6 == 0)
+ {
+ if (++p->mFrame >= IMAGE_PARTICLE_LIGHTNING->mNumCols)
+ {
+ mParticles.erase(mParticles.begin() + i);
+ --i;
+ }
+ }
+ }
+
+ if (mLevelupEffect->IsActive())
+ {
+ mLevelupEffect->Update(theFrac);
+
+ // If the proper state is reached in the level up effect, then we can begin
+ // setting up the next level.
+ if (mLevelupEffect->StartNextLevel())
+ {
+ // Just finished, start the next level
+ mOptionsBtn->SetVisible(true);
+ InitLevel(mLevel + 1);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::FillRight(float amt)
+{
+ bool change = true;
+
+ // Fill the entire line, moving rightward
+ for (int y = mFillRegion.mTop; y <= mFillRegion.mBottom; y++)
+ {
+ GridTile* gt = &mGridState[y][mFillRegion.mLeft];
+
+ // We only want to fill those pieces that are in the GRID_FILLING state
+ if (gt->mFillState == GRID_FILLING)
+ {
+ // This piece is filling up, expand its width
+ gt->mFillRect.mWidth += amt;
+
+ // If the width exceeds that of the grid piece, overflow the result
+ // into the tile next to it so that the filling appears continuous.
+ if (gt->mFillRect.mWidth >= GRID_PIX_SIZE)
+ {
+ float overflow = gt->mFillRect.mWidth - GRID_PIX_SIZE;
+ gt->mFillState = GRID_FILLED;
+
+ gt->mFillRect.mWidth = GRID_PIX_SIZE;
+
+ //overflow into next column, if the next column is within our
+ //fill region and if the piece is in the normal tile state.
+ if (mFillRegion.mLeft + 1 <= mFillRegion.mRight)
+ if (mGridState[y][mFillRegion.mLeft + 1].mFillState == GRID_NORMAL)
+ mGridState[y][mFillRegion.mLeft + 1].mFillRect.mWidth += overflow;
+ }
+ else
+ change = false;
+ }
+ }
+
+ //if "change" is true, then move one column right and begin filling in that column next
+ //time this function is called. If there are no more columns to fill, we're done.
+
+ if (change && (++mFillRegion.mLeft > mFillRegion.mRight))
+ mFilling = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::FillLeft(float amt)
+{
+ float leftX = GetColPix(mFillRegion.mRight);
+ bool change = true;
+
+ //This algorithm works just like FillRight except that it's filling
+ //from the right side of the grid piece instead of the left, so there's
+ //a couple extra calculations.
+
+ for (int y = mFillRegion.mTop; y <= mFillRegion.mBottom; y++)
+ {
+ GridTile* gt = &mGridState[y][mFillRegion.mRight];
+
+ if (gt->mFillState == GRID_FILLING)
+ {
+ gt->mFillRect.mWidth += amt;
+ gt->mFillRect.mX -= amt;
+
+ if ((gt->mFillRect.mWidth >= GRID_PIX_SIZE) || (gt->mFillRect.mX < leftX))
+ {
+ float overflow = gt->mFillRect.mWidth - GRID_PIX_SIZE;
+ gt->mFillState = GRID_FILLED;
+
+ gt->mFillRect.mWidth = GRID_PIX_SIZE;
+ gt->mFillRect.mX = leftX;
+
+ //overflow into next column
+ if (mFillRegion.mRight - 1 >= mFillRegion.mLeft)
+ {
+ if (mGridState[y][mFillRegion.mRight - 1].mFillState == GRID_NORMAL)
+ {
+ mGridState[y][mFillRegion.mRight - 1].mFillRect.mWidth += overflow;
+ mGridState[y][mFillRegion.mRight - 1].mFillRect.mX -= overflow;
+ }
+ }
+ }
+ else
+ change = false;
+ }
+ }
+
+ if (change && (--mFillRegion.mRight < mFillRegion.mLeft))
+ mFilling = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::FillUp(float amt)
+{
+ bool change = true;
+ float topY = GetRowPix(mFillRegion.mBottom);
+
+ //This algorithm works just like FillRight except that it's filling
+ //from the bottom side of the grid piece instead of the left, so there's
+ //a couple extra calculations.
+
+ for (int x = mFillRegion.mLeft; x <= mFillRegion.mRight; x++)
+ {
+ GridTile* gt = &mGridState[mFillRegion.mBottom][x];
+
+ if (gt->mFillState == GRID_FILLING)
+ {
+ gt->mFillRect.mHeight += amt;
+ gt->mFillRect.mY -= amt;
+
+ if ((gt->mFillRect.mHeight >= GRID_PIX_SIZE) || (gt->mFillRect.mY < topY))
+ {
+ float overflow = gt->mFillRect.mHeight - GRID_PIX_SIZE;
+ gt->mFillState = GRID_FILLED;
+
+ gt->mFillRect.mHeight = GRID_PIX_SIZE;
+ gt->mFillRect.mY = topY;
+
+ //overflow into next row
+ if (mFillRegion.mBottom - 1 > mFillRegion.mTop)
+ {
+ if (mGridState[mFillRegion.mBottom - 1][x].mFillState == GRID_NORMAL)
+ {
+ mGridState[mFillRegion.mBottom - 1][x].mFillRect.mHeight += overflow;
+ mGridState[mFillRegion.mBottom - 1][x].mFillRect.mY -= overflow;
+ }
+ }
+ }
+ else
+ change = false;
+ }
+ }
+
+ if (change && (--mFillRegion.mBottom < mFillRegion.mTop))
+ mFilling = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::FillDown(float amt)
+{
+ bool change = true;
+
+ //This algorithm works just like FillRight except that it's filling
+ //from the top side of the grid piece instead of the left.
+
+ for (int x = mFillRegion.mLeft; x <= mFillRegion.mRight; x++)
+ {
+ GridTile* gt = &mGridState[mFillRegion.mTop][x];
+
+ if (gt->mFillState == GRID_FILLING)
+ {
+ gt->mFillRect.mHeight += amt;
+
+ if (gt->mFillRect.mHeight >= GRID_PIX_SIZE)
+ {
+ float overflow = gt->mFillRect.mHeight - GRID_PIX_SIZE;
+ gt->mFillState = GRID_FILLED;
+
+ gt->mFillRect.mHeight = GRID_PIX_SIZE;
+
+ //overflow into next row
+ if (mFillRegion.mTop + 1 <= mFillRegion.mBottom)
+ if (mGridState[mFillRegion.mTop + 1][x].mFillState == GRID_NORMAL)
+ mGridState[mFillRegion.mTop + 1][x].mFillRect.mHeight += overflow;
+ }
+ else
+ change = false;
+ }
+ }
+
+ if (change && (++mFillRegion.mTop > mFillRegion.mBottom))
+ mFilling = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MoveLines(float theFrac)
+{
+
+ // Move the lines, differently depending on if they are oriented verticall
+ // or horizontally. When a line reaches its target, it is done, and planets
+ // can bounce off of it. When both lines are done, we will calculate the region
+ // to fill.
+
+ int numDone = 0;
+ if (!mMovingLine1.mDone)
+ {
+ float amt = -mLineSpeed * theFrac;
+
+ if (mMovingLine1.mIsVertical)
+ {
+ mMovingLine1.mY += amt;
+ mMovingLine1.mHeight += fabsf(amt);
+
+ if (mMovingLine1.mY <= mMovingLine1.mTargetY)
+ {
+ mMovingLine1.mY = mMovingLine1.mTargetY;
+ mMovingLine1.mDone = true;
+ ++numDone;
+ }
+ }
+ else
+ {
+ mMovingLine1.mX += amt;
+ mMovingLine1.mWidth += fabsf(amt);
+
+ if (mMovingLine1.mX <= mMovingLine1.mTargetX)
+ {
+ mMovingLine1.mX = mMovingLine1.mTargetX;
+ mMovingLine1.mDone = true;
+ ++numDone;
+ }
+ }
+ }
+
+ if (!mMovingLine2.mDone)
+ {
+ float amt = mLineSpeed * theFrac;
+
+ if (mMovingLine2.mIsVertical)
+ {
+ mMovingLine2.mHeight += amt;
+
+ if (mMovingLine2.mY + mMovingLine2.mHeight >= mMovingLine2.mTargetY)
+ {
+ mMovingLine2.mHeight = mMovingLine2.mTargetY - mMovingLine2.mY;
+ mMovingLine2.mDone = true;
+ ++numDone;
+ }
+ }
+ else
+ {
+ mMovingLine2.mWidth += amt;
+
+ if (mMovingLine2.mX + mMovingLine2.mWidth >= mMovingLine2.mTargetX)
+ {
+ mMovingLine2.mWidth = mMovingLine2.mTargetX - mMovingLine2.mX;
+ mMovingLine2.mDone = true;
+ ++numDone;
+ }
+ }
+ }
+
+ // While at least one of the lines is still moving, make a bunch of sparks shower off
+ // the edge of them. In non-3d mode, we'll only emit half the sparks to reduce the CPU time consumed.
+ if (!mMovingLine2.mDone || !mMovingLine1.mDone)
+ {
+ int modVal = gSexyAppBase->Is3DAccelerated() ? 2 : 4;
+ if (mUpdateCnt % modVal == 0)
+ EmitSparks();
+ }
+
+ // If both are done at the same time, or both are done but perhaps one completed earlier than the other,
+ // then it's time to compute the fill region.
+ if ((numDone == 2) || ((numDone == 1) && mMovingLine1.mDone && mMovingLine2.mDone))
+ {
+ mFilling = true;
+
+ CalculateFillRegions();
+ }
+
+ // Quit playing the electrical shorting out sound when both lines are broken or
+ // done or any combination of the two.
+ if ((mMovingLine1.mDone && mMovingLine2.mDone) ||
+ (mMovingLine1.mBroken && mMovingLine2.mDone) ||
+ (mMovingLine2.mBroken && mMovingLine1.mDone))
+ mShortSound->Stop();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ int incAmt = gSexyAppBase->Is3DAccelerated() ? 1 : 2;
+
+ // Draw less starts if not in 3D mode to reduce CPU usage, since they aren't a critical feature
+ for (int i = 0; i < MAX_STARS; i += incAmt)
+ {
+ Star* s = &mStarField[i];
+ g->SetColor(s->mColor);
+ g->FillRect(s->mX, s->mY, 1, 1);
+ }
+
+ // We don't draw the other game elements under certain conditions, like
+ // if the level up and game over effects are in a few particular states.
+ if (!mLevelupEffect->HideBoard() && !mGameOverEffect->HideBoard())
+ {
+ DrawGrid(g);
+ DrawUI(g);
+
+ // To prevent cheating, don't draw planets if the game is paused.
+ // Also don't show them during certain points of the level up effect
+ if (!mLevelupEffect->HidePlanets() || (mPauseLevel > 0))
+ DrawPlanets(g);
+
+ if (!mGameOverEffect->IsActive())
+ DrawMovingBeams(g);
+
+ DrawHungarr(g);
+ }
+
+ if (mLevelupEffect->IsActive())
+ mLevelupEffect->Draw(g);
+
+ if (mGameOverEffect->IsActive())
+ mGameOverEffect->Draw(g);
+
+ if (mPauseLevel > 0)
+ {
+ // Paused: draw an overlay
+ g->SetColor(Color(0, 0, 0, 128));
+ g->FillRect(0, 0, mWidth, mHeight);
+ g->SetColor(Color::White);
+ g->SetFont(FONT_HUNGARR);
+ g->DrawString(_S("PAUSED"), mWidth / 2 - FONT_HUNGARR->StringWidth(_S("PAUSED")) / 2, mHeight / 2);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawGrid(Graphics* g)
+{
+ // Draw an outline around the whole grid region. See LevelUpEffect.cpp or
+ // GameOverEffect.cpp for full details on using HSL instead of RGB for color and
+ // why it's useful.
+ if (mFlashCount > 0)
+ g->SetColor(mApp->HSLToRGB(mBorderHue, 255, 128) & 0xFFFFFFFF);
+ else
+ g->SetColor(Color(255, 0, 0, 64));
+
+ // grid outline:
+ g->FillRect(0, GRID_START_Y, GRID_START_X, mHeight - GRID_START_Y);
+ g->FillRect(0, GRID_START_Y - GRID_PIX_SIZE, mWidth, GRID_PIX_SIZE);
+ g->FillRect(GRID_END_X, GRID_START_Y, mWidth - GRID_END_X, mHeight - GRID_START_Y);
+ g->FillRect(GRID_START_X, GRID_END_Y, GRID_END_X - GRID_START_X, mHeight - GRID_END_Y);
+
+
+ // To make a weird pattern, a few of the grid pieces will be more brightly
+ // colored than the others, if they are in the normal state.
+ bool startBright = true;
+ for (int y = 0; y < GRID_HEIGHT; y++)
+ {
+ int drawY = GetRowPix(y);
+
+ for (int x = 0; x < GRID_WIDTH; x++)
+ {
+ int drawX = GetColPix(x);
+ int state = mGridState[y][x].mFillState;
+ if (state == GRID_FILLING)
+ {
+ // The grid piece is in the process of filling up. Draw a different colored rectangle for the
+ // filled in part, and then draw the rest normally.
+ FRect* fr = &mGridState[y][x].mFillRect;
+ Rect normalRect;
+
+ if (mFillDirection == FILL_RIGHT)
+ normalRect = Rect(fr->mX + fr->mWidth, drawY, GRID_PIX_SIZE - fr->mWidth + 1, GRID_PIX_SIZE);
+ else if (mFillDirection == FILL_LEFT)
+ normalRect = Rect(drawX, drawY, GRID_PIX_SIZE - fr->mWidth, GRID_PIX_SIZE);
+ else if (mFillDirection == FILL_UP)
+ normalRect = Rect(drawX, drawY, GRID_PIX_SIZE, GRID_PIX_SIZE - fr->mHeight);
+ else
+ normalRect = Rect(drawX, fr->mY + fr->mHeight, GRID_PIX_SIZE, GRID_PIX_SIZE - fr->mHeight + 1);
+
+
+ if ((normalRect.mWidth > 0) && (normalRect.mHeight > 0))
+ {
+ g->SetColor(Color(255, 255, 0, startBright && (x % 2 == 0) ? 128 : 64));
+ g->FillRect(normalRect);
+ g->SetColor(Color(0, 0, 0));
+ g->DrawRect(normalRect);
+ }
+
+ g->SetColor(Color(255, 255, 0, 100));
+ FillRectF(g, *fr);
+ }
+ else if (state == GRID_NORMAL)
+ {
+ // Just draw the grid piece normally, with a black outline around it.
+
+ g->SetColor(Color(255, 255, 0, startBright && (x % 3 == 0) ? 64 : 32));
+ g->FillRect(drawX, drawY, GRID_PIX_SIZE, GRID_PIX_SIZE);
+ g->SetColor(Color(0, 0, 0));
+ g->DrawRect(drawX, drawY, GRID_PIX_SIZE, GRID_PIX_SIZE);
+ }
+ else
+ {
+ // The piece is completely filled in, just fill the whole rectangle
+ g->SetColor(Color(255, 255, 0, 100));
+ FillRectF(g, mGridState[y][x].mFillRect);
+ }
+ }
+
+ startBright = !startBright;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawUI(Graphics* g)
+{
+ int ascent = FONT_HUNGARR->GetAscent();
+ int height = FONT_HUNGARR->GetHeight();
+
+ g->SetFont(FONT_HUNGARR);
+ SexyString s;
+ int rightX = FONT_HUNGARR->StringWidth(_S("POPULATION CONSUMED: ")) + 5;
+
+ int strWidth;
+ s = _S("WORLDS DEVOURED: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, rightX - strWidth, ascent);
+ g->SetColor(Color(255, 0, 0, 200));
+ g->DrawString(StrFormat(_S("%d"), mNumPlanetsEaten), rightX - 5, ascent);
+
+ s = _S("POPULATION CONSUMED: ");
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, 5, height * 2);
+ g->SetColor(Color(255, 0, 0, 200));
+ g->DrawString(CommaSeperate(mPopulationEaten), rightX - 5, height * 2);
+
+ s = _S("SCORE: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, rightX - strWidth, height * 3);
+ g->SetColor(Color(255, 255, 0, 200));
+ g->DrawString(StrFormat(_S("%s"), CommaSeperate(mScore).c_str()), rightX - 5, height * 3);
+
+
+
+ int x = 380;
+ s = _S("SYSTEMS SUBJUGATED: ");
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, x, ascent);
+ g->SetColor(Color(255, 0, 0, 200));
+ g->DrawString(StrFormat(_S("%d%%"), mPercentComplete), x + FONT_HUNGARR->StringWidth(s), ascent);
+
+ s = _S("LIVES: ");
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, x, height * 2);
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawImage(IMAGE_HUNGARR_SMALL, strWidth + x, ascent);
+ g->SetColor(Color(255, 0, 0, 200));
+ g->DrawString(StrFormat(_S("x%d"), mLives), x + 10 + strWidth + IMAGE_HUNGARR_SMALL->GetWidth(), height * 2);
+
+ s = _S("LEVEL: ");
+ g->SetColor(Color(255, 255, 255, 128));
+ g->DrawString(s, x, height * 3);
+ g->SetColor(Color(255, 255, 0, 200));
+ g->DrawString(StrFormat(_S("%d"), mLevel), x + FONT_HUNGARR->StringWidth(s), height * 3);
+
+ for (int i = 0; i < mBonusText.size(); i++)
+ {
+ BonusText* bt = &mBonusText[i];
+ g->SetColor( (mApp->HSLToRGB(bt->mHue, 255, 128) & 0xFFFFFF) | (bt->mAlpha << 24) );
+ g->DrawString(bt->mText, bt->mX, bt->mY);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Beam1DrawHelper(Graphics* g)
+{
+ // In 3D mode we'll use the DrawImageF versions since they look nicer and
+ // perform anti-aliasing, and make floating point movement appear smoother.
+ // Since they are more taxing, we'll use the default integer routines if hardware
+ // mode is not available.
+
+ // The offsets you see were taken from the actual image itself. You'll notice
+ // that the image has a lot of blank space around the actual beam, so we move things
+ // around a bit to get a nice aligned look. You'd either just play around with these
+ // numbers till it looked right, or your artist would inform you.
+ if (mMovingLine1.mIsVertical)
+ {
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_UP, mMovingLine1.mX - 8, mMovingLine1.mY,
+ Rect(0, 0, IMAGE_HUNGARR_BEAM_UP->GetWidth(), mMovingLine1.mHeight));
+ }
+ else
+ {
+ g->DrawImage(IMAGE_HUNGARR_BEAM_UP, mMovingLine1.mX - 8, mMovingLine1.mY,
+ Rect(0, 0, IMAGE_HUNGARR_BEAM_UP->GetWidth(), mMovingLine1.mHeight));
+ }
+ }
+ else
+ {
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_LEFT, mMovingLine1.mX, mMovingLine1.mY - 8,
+ Rect(0, 0, mMovingLine1.mWidth, IMAGE_HUNGARR_BEAM_LEFT->GetHeight()));
+ }
+ else
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_LEFT, mMovingLine1.mX, mMovingLine1.mY - 8,
+ Rect(0, 0, mMovingLine1.mWidth, IMAGE_HUNGARR_BEAM_LEFT->GetHeight()));
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Beam2DrawHelper(Graphics* g)
+{
+ // In 3D mode we'll use the DrawImageF versions since they look nicer and
+ // perform anti-aliasing, and make floating point movement appear smoother.
+ // Since they are more taxing, we'll use the default integer routines if hardware
+ // mode is not available.
+
+ // The offsets you see were taken from the actual image itself. You'll notice
+ // that the image has a lot of blank space around the actual beam, so we move things
+ // around a bit to get a nice aligned look. You'd either just play around with these
+ // numbers till it looked right, or your artist would inform you.
+
+ if (mMovingLine2.mIsVertical)
+ {
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_DOWN, mMovingLine2.mX - 8, mMovingLine2.mY - 1,
+ Rect(0, IMAGE_HUNGARR_BEAM_DOWN->GetHeight() - mMovingLine2.mHeight,
+ IMAGE_HUNGARR_BEAM_DOWN->GetWidth(), mMovingLine2.mHeight));
+ }
+ else
+ {
+ g->DrawImage(IMAGE_HUNGARR_BEAM_DOWN, mMovingLine2.mX - 8, mMovingLine2.mY - 1,
+ Rect(0, IMAGE_HUNGARR_BEAM_DOWN->GetHeight() - mMovingLine2.mHeight,
+ IMAGE_HUNGARR_BEAM_DOWN->GetWidth(), mMovingLine2.mHeight));
+ }
+ }
+ else
+ {
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_RIGHT, mMovingLine2.mX - 1, mMovingLine2.mY - 8,
+ Rect(IMAGE_HUNGARR_BEAM_RIGHT->GetWidth() - mMovingLine2.mWidth, 0,
+ mMovingLine2.mWidth, IMAGE_HUNGARR_BEAM_RIGHT->GetHeight()));
+ }
+ else
+ {
+ g->DrawImage(IMAGE_HUNGARR_BEAM_RIGHT, mMovingLine2.mX - 1, mMovingLine2.mY - 8,
+ Rect(IMAGE_HUNGARR_BEAM_RIGHT->GetWidth() - mMovingLine2.mWidth, 0,
+ mMovingLine2.mWidth, IMAGE_HUNGARR_BEAM_RIGHT->GetHeight()));
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawMovingBeams(Graphics* g)
+{
+ // If the beams are moving, then draw them. Make them pulse too. You make a
+ // pulsing effect like we did in the previous demos: draw the image a second time on
+ // top of the original additively, and colorize the image, setting the RGB values to
+ // a different intensity. The result is an image that gets brighter and dimmer over time.
+ if (!mMovingLine1.mBroken && (!mMovingLine1.mDone || mFilling || !mMovingLine2.mDone))
+ {
+ Beam1DrawHelper(g);
+
+ if (!mMovingLine1.mDone)
+ {
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+ g->SetColor(Color(mBeamPulseVal, mBeamPulseVal, mBeamPulseVal));
+ Beam1DrawHelper(g);
+ g->SetColorizeImages(false);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+
+ }
+
+ if (!mMovingLine2.mDone || mFilling || !mMovingLine1.mDone)
+ {
+ Beam2DrawHelper(g);
+
+ if (!mMovingLine2.mDone)
+ {
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+ g->SetColor(Color(mBeamPulseVal, mBeamPulseVal, mBeamPulseVal));
+ Beam2DrawHelper(g);
+ g->SetColorizeImages(false);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+ }
+
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ for (int i = 0; i < mParticles.size(); i++)
+ {
+ Particle* p = &mParticles[i];
+ g->DrawImageCel(IMAGE_PARTICLE_LIGHTNING, p->mX, p->mY, p->mFrame);
+ }
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawPlanets(Graphics* g)
+{
+ // If the user has 3d, we'll rotate the planets using the floating point
+ // smooth rotation function. If they don't, we'll avoid rotating at all to
+ // save on CPU cycles and keep the framerate up.
+ int w = IMAGE_PLANETS->GetCelWidth();
+ int h = IMAGE_PLANETS->GetCelHeight();
+ for (int i = 0; i < mPlanets.size(); i++)
+ {
+ Planet* p = &mPlanets[i];
+ if (p->mExploding)
+ {
+ g->DrawImageCel(IMAGE_BOMB_RADIAL_DEATH,
+ p->mX - (IMAGE_BOMB_RADIAL_DEATH->GetCelWidth() / 2 + w / 2),
+ p->mY - (IMAGE_BOMB_RADIAL_DEATH->GetCelHeight() / 2 + h / 2),
+ p->mExplodeFrame);
+ }
+ else
+ {
+ Rect r = Rect(p->mImgCol * w, 0, w, IMAGE_PLANETS->GetCelHeight());
+
+ if (gSexyAppBase->Is3DAccelerated())
+ g->DrawImageRotatedF(IMAGE_PLANETS, p->mX, p->mY, p->mRotationAngle, &r);
+ else
+ g->DrawImage(IMAGE_PLANETS, p->mX, p->mY, r);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawHungarrVertBeamsHelper(Graphics* g)
+{
+ // This draws the two little static beams that are always attached to
+ // Hun-garr's bitmap. If the user has hardware acceleration, we'll
+ // draw the beams pulsating. If not, we'll skip it since it's time consuming
+ // and doesn't hurt the game any. It'd be worse to drop the framrate by a few FPS
+ // for this effect.
+
+ int h = IMAGE_HUNGARR_VERT->GetHeight() / 2;
+
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_UP, mLine1X, mLine1Y,
+ Rect(0, 0, IMAGE_HUNGARR_BEAM_UP->GetWidth(), h));
+
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_DOWN, mLine2X, mLine2Y,
+ Rect(0, IMAGE_HUNGARR_BEAM_DOWN->GetHeight() - h, IMAGE_HUNGARR_BEAM_DOWN->GetWidth(), h));
+
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+
+ g->SetColor(Color(255, 255, 255, mBeamPulseVal));
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_UP, mLine1X, mLine1Y,
+ Rect(0, 0, IMAGE_HUNGARR_BEAM_UP->GetWidth(), h));
+
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_DOWN, mLine2X, mLine2Y,
+ Rect(0, IMAGE_HUNGARR_BEAM_DOWN->GetHeight() - h, IMAGE_HUNGARR_BEAM_DOWN->GetWidth(), h));
+
+
+ g->SetColorizeImages(false);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+ else
+ {
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->DrawImage(IMAGE_HUNGARR_BEAM_UP, mLine1X, mLine1Y,
+ Rect(0, 0, IMAGE_HUNGARR_BEAM_UP->GetWidth(), h));
+
+ g->DrawImage(IMAGE_HUNGARR_BEAM_DOWN, mLine2X, mLine2Y,
+ Rect(0, IMAGE_HUNGARR_BEAM_DOWN->GetHeight() - h, IMAGE_HUNGARR_BEAM_DOWN->GetWidth(), h));
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawHungarrHorizBeamsHelper(Graphics* g)
+{
+ // This draws the two little static beams that are always attached to
+ // Hun-garr's bitmap. If the user has hardware acceleration, we'll
+ // draw the beams pulsating. If not, we'll skip it since it's time consuming
+ // and doesn't hurt the game any. It'd be worse to drop the framrate by a few FPS
+ // for this effect.
+
+ int w = IMAGE_HUNGARR_HORIZ->GetWidth() / 2;
+
+ if (gSexyAppBase->Is3DAccelerated())
+ {
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_LEFT, mLine1X, mLine1Y,
+ Rect(0, 0, w, IMAGE_HUNGARR_BEAM_LEFT->GetHeight()));
+
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_RIGHT, mLine2X, mLine2Y,
+ Rect(IMAGE_HUNGARR_BEAM_RIGHT->GetWidth() - w, 0, w, IMAGE_HUNGARR_BEAM_RIGHT->GetHeight()));
+
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+
+ g->SetColor(Color(255, 255, 255, mBeamPulseVal));
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_LEFT, mLine1X, mLine1Y,
+ Rect(0, 0, w, IMAGE_HUNGARR_BEAM_LEFT->GetHeight()));
+
+ g->DrawImageF(IMAGE_HUNGARR_BEAM_RIGHT, mLine2X, mLine2Y,
+ Rect(IMAGE_HUNGARR_BEAM_RIGHT->GetWidth() - w, 0, w, IMAGE_HUNGARR_BEAM_RIGHT->GetHeight()));
+
+ g->SetColorizeImages(false);
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+ else
+ {
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+
+ g->DrawImage(IMAGE_HUNGARR_BEAM_LEFT, mLine1X, mLine1Y,
+ Rect(0, 0, w, IMAGE_HUNGARR_BEAM_LEFT->GetHeight()));
+
+ g->DrawImage(IMAGE_HUNGARR_BEAM_RIGHT, mLine2X, mLine2Y,
+ Rect(IMAGE_HUNGARR_BEAM_RIGHT->GetWidth() - w, 0, w, IMAGE_HUNGARR_BEAM_RIGHT->GetHeight()));
+
+ g->SetDrawMode(Graphics::DRAWMODE_NORMAL);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::DrawHungarr(Graphics* g)
+{
+ // again, we use the floating point functions instead of the integer ones
+ // if the user has a 3d card.
+
+ bool is3d = gSexyAppBase->Is3DAccelerated();
+
+ if (mHungarrIsVertical)
+ {
+ DrawHungarrVertBeamsHelper(g);
+
+ if (is3d)
+ g->DrawImageF(IMAGE_HUNGARR_VERT, mHungarrX, mHungarrY);
+ else
+ g->DrawImage(IMAGE_HUNGARR_VERT, mHungarrX, mHungarrY);
+ }
+ else
+ {
+ DrawHungarrHorizBeamsHelper(g);
+
+ if (is3d)
+ g->DrawImageF(IMAGE_HUNGARR_HORIZ, mHungarrX, mHungarrY);
+ else
+ g->DrawImage(IMAGE_HUNGARR_HORIZ, mHungarrX, mHungarrY);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddedToManager(WidgetManager* theWidgetManager)
+{
+ Widget::AddedToManager(theWidgetManager);
+
+
+ mOptionsBtn = new ButtonWidget(1, this);
+ mOptionsBtn->SetFont(FONT_DEFAULT);
+ mOptionsBtn->mLabel = _S("Options");
+ mOptionsBtn->SetColor(ButtonWidget::COLOR_LABEL, Color::White);
+ mOptionsBtn->SetColor(ButtonWidget::COLOR_LABEL_HILITE, Color::White);
+
+ mOptionsBtn->mOverImage = IMAGE_BUTTON_OVER;
+ mOptionsBtn->mDownImage = IMAGE_BUTTON_DOWN;
+ mOptionsBtn->mButtonImage = IMAGE_BUTTON_NORMAL;
+ mOptionsBtn->mDoFinger = true;
+ mOptionsBtn->Resize(gSexyAppBase->mWidth - IMAGE_BUTTON_NORMAL->GetWidth() - 10, FONT_HUNGARR->GetHeight() * 3 - 20,
+ IMAGE_BUTTON_NORMAL->GetWidth(), IMAGE_BUTTON_NORMAL->GetHeight());
+
+ theWidgetManager->AddWidget(mOptionsBtn);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ Widget::RemovedFromManager(theWidgetManager);
+
+ theWidgetManager->RemoveWidget(mOptionsBtn);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::ButtonDepress(int theId)
+{
+ // Play a sound whenever the options button is depressed/sad.
+ if (theId == mOptionsBtn->mId)
+ {
+ // Stop the shorting sound if it's playing, otherwise it's annoying
+ mShortSound->Stop();
+
+ mApp->PlaySample(SOUND_BUTTON);
+ Pause(true);
+ OptionsDialog* od = new OptionsDialog(this);
+ od->Resize(mWidth / 2 - 200, mHeight / 2 - 175, 400, 350);
+ mApp->AddDialog(OptionsDialog::DIALOG_ID, od);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseMove(int x, int y)
+{
+ UpdateHungarrPosition(x, y);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseDrag(int x, int y)
+{
+ UpdateHungarrPosition(x, y);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::MouseDown(int x, int y, int theClickCount)
+{
+ // if the level up effect is displaying stats, or the game over effect is too,
+ // and the user clicked, then start the next phase
+ if (mLevelupEffect->ShowingStats())
+ mLevelupEffect->DoneViewingStats();
+
+ if (mGameOverEffect->CanStartNewGame())
+ mGameOverEffect->DoneViewingStats();
+
+ // ignore mouse clicks when paused or an effect is on screen and the user has no reason to click
+ if (mLevelupEffect->IsActive() || (mPauseLevel > 0) || (mGameOverEffect->IsActive() && !mGameOverEffect->CanStartNewGame()))
+ return;
+
+ // On a right click, if the click was within the grid bounds, switch hungarr's orientation
+ if ((theClickCount < 0) && XCoordInBounds(x) && YCoordInBounds(y, mHungarrIsVertical))
+ mHungarrIsVertical = !mHungarrIsVertical;
+ else if ((theClickCount > 0) && mMovingLine1.mDone && mMovingLine2.mDone && !mFilling)
+ {
+ //left click, and there's no lines moving: drop two new lines
+
+ // Make sure the user didn't click on a planet which would instantly kill them
+ FRect hungarrRect = FRect(mHungarrX, mHungarrY, IMAGE_HUNGARR_HORIZ->mWidth, IMAGE_HUNGARR_HORIZ->mHeight);
+ for (int i = 0; i < mPlanets.size(); i++)
+ {
+ Planet* p = &mPlanets[i];
+ FRect planetRect = FRect(p->mX, p->mY, IMAGE_PLANETS->GetCelWidth(), IMAGE_PLANETS->GetCelHeight());
+ if (planetRect.Intersects(hungarrRect))
+ return;
+ }
+
+ mApp->PlaySample(SOUND_MAGZAP);
+
+ // start the electrical shorting sound
+ mShortSound->Play(true, false);
+
+ mMovingLine1.mDone = mMovingLine2.mDone = false;
+ mMovingLine1.mBroken = mMovingLine2.mBroken = false;
+ int midX = IMAGE_HUNGARR_HORIZ->GetWidth() / 2;
+ int midY = IMAGE_HUNGARR_HORIZ->GetHeight() / 2;
+
+ //Align the XYs of the lines to the grid, and set the target coordinates to the
+ //closest normal state tile.
+ if (mHungarrIsVertical)
+ {
+ mMovingLine1.mIsVertical = mMovingLine2.mIsVertical = true;
+ mMovingLine1.mX = mMovingLine2.mX = GetAlignedX(mHungarrX + midX);
+ mMovingLine1.mY = mMovingLine2.mY = GetAlignedY(mHungarrY + midY);
+ mMovingLine1.mHeight = 1;
+ mMovingLine2.mHeight = 13;
+ mMovingLine1.mWidth = mMovingLine2.mWidth = GRID_PIX_SIZE;
+ mMovingLine1.mTargetY = mMovingLine2.mTargetY = mMovingLine1.mY;
+ mMovingLine1.mTargetX = mMovingLine2.mTargetX = mMovingLine1.mX;
+
+ // Make sure the target coords end at a tile that's normal. If not, keep moving them
+ int row = GetRow(mMovingLine1.mTargetY);
+ int col = GetCol(mMovingLine1.mTargetX);
+
+ // Tile immediately below is not valid
+ if (mGridState[row][col].mFillState != GRID_NORMAL)
+ return;
+
+ while ((row >= 0) && (mGridState[row][col].mFillState == GRID_NORMAL))
+ {
+ mMovingLine1.mTargetY -= GRID_PIX_SIZE;
+ --row;
+ }
+
+ // Make it end on the last valid tile. The loop above makes it leave
+ // on an invalid tile
+ mMovingLine1.mTargetY += GRID_PIX_SIZE;
+
+ row = GetRow(mMovingLine2.mTargetY);
+ col = GetCol(mMovingLine2.mTargetX);
+
+ while ((row < GRID_HEIGHT) && (mGridState[row][col].mFillState == GRID_NORMAL))
+ {
+ mMovingLine2.mTargetY += GRID_PIX_SIZE;
+ ++row;
+ }
+
+ if (mMovingLine1.mTargetY > mMovingLine2.mTargetY)
+ mMovingLine1.mDone = mMovingLine2.mDone = true;
+ }
+ else
+ {
+ mMovingLine1.mIsVertical = mMovingLine2.mIsVertical = false;
+ mMovingLine1.mX = mMovingLine2.mX = GetAlignedX(mHungarrX + midX);
+ mMovingLine1.mY = mMovingLine2.mY = GetAlignedY(mHungarrY + midY);
+ mMovingLine1.mWidth = 1;
+ mMovingLine2.mWidth = 13;
+ mMovingLine1.mHeight = mMovingLine2.mHeight = GRID_PIX_SIZE;
+ mMovingLine1.mTargetX = mMovingLine2.mTargetX = mMovingLine1.mX;
+ mMovingLine1.mTargetY = mMovingLine2.mTargetY = mMovingLine1.mY;
+
+ // Make sure the target coords end at a tile that's normal. If not, keep moving them
+ int row = GetRow(mMovingLine1.mTargetY);
+ int col = GetCol(mMovingLine1.mTargetX);
+
+ // Tile immediately below is not valid...?
+ if (mGridState[row][col].mFillState != GRID_NORMAL)
+ return;
+
+ while ((col >= 0) && (mGridState[row][col].mFillState == GRID_NORMAL))
+ {
+ mMovingLine1.mTargetX -= GRID_PIX_SIZE;
+ --col;
+ }
+
+ // Make it end on the last valid tile. The loop above makes it leave
+ // on an invalid tile
+ mMovingLine1.mTargetX += GRID_PIX_SIZE;
+
+
+ row = GetRow(mMovingLine2.mTargetY);
+ col = GetCol(mMovingLine2.mTargetX);
+
+ while ((col < GRID_WIDTH) && (mGridState[row][col].mFillState == GRID_NORMAL))
+ {
+ mMovingLine2.mTargetX += GRID_PIX_SIZE;
+ ++col;
+ }
+
+
+ if (mMovingLine1.mTargetX > mMovingLine2.mTargetX)
+ mMovingLine1.mDone = mMovingLine2.mDone = true;
+ }
+ }
+
+ UpdateHungarrPosition(x, y);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::UpdateHungarrPosition(int x, int y)
+{
+ // Place the Hun-garr bitmap and the two lines that stick out of him
+ // so that Hun-garr is centered on the mouse cursor
+ int midX = IMAGE_HUNGARR_HORIZ->GetWidth() / 2;
+ int midY = IMAGE_HUNGARR_HORIZ->GetHeight() / 2;
+
+ if (YCoordInBounds(y, mHungarrIsVertical))
+ {
+ mHungarrY = y - midY;
+ mLine1Y = mHungarrY + (!mHungarrIsVertical ? 7 : -12);
+ mLine2Y = mHungarrY + (!mHungarrIsVertical ? 7 : 35);
+ }
+
+ if (XCoordInBounds(x))
+ {
+ mHungarrX = x - midX;
+ mLine1X = mHungarrX + (!mHungarrIsVertical ? -13 : 8);
+ mLine2X = mHungarrX + (!mHungarrIsVertical ? 36 : 9);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::CalculateFillRegions(void)
+{
+ int topRow, botRow, leftCol, rightCol;
+
+ // The basic idea is this: Find the CLOSEST edge to where the user clicks that
+ // meets the following conditions:
+ // 1. If Hun-garr is vertical, the edge must be as tall as the column created
+ // by the two emitted lines (or more) and every grid piece must be normal
+ // 2. If Hun-garr is horizontal, the edge must be as wide as the row created by
+ // the two emitted lines (or more) and every grid piece must be normal
+ // 3. If either of the lines were broken, we instead just fill in the single
+ // line made by the non-broken line (the code won't execute if both are broken)
+
+
+ if (mMovingLine1.mIsVertical)
+ {
+ topRow = GetRow(mMovingLine1.mTargetY);
+ int col1 = GetCol(mMovingLine1.mTargetX);
+ botRow = GetRow(mMovingLine2.mTargetY);
+
+ if ((mMovingLine1.mBroken && !mMovingLine2.mBroken) ||
+ (!mMovingLine1.mBroken && mMovingLine2.mBroken))
+ {
+ leftCol = col1;
+ rightCol = col1 + 1;
+ mFillDirection = FILL_RIGHT;
+ topRow = mMovingLine1.mBroken ? GetRow(mMovingLine2.mY) : topRow;
+ botRow = mMovingLine1.mBroken ? botRow : GetRow(mMovingLine2.mY);
+ }
+ else
+ {
+ int rightEdge, leftEdge;
+ GetVerticalFillValues(col1, topRow, botRow, 1, &rightEdge);
+ GetVerticalFillValues(col1, topRow, botRow, -1, &leftEdge);
+
+ if ((rightEdge - col1) <= (col1 - leftEdge))
+ {
+ leftCol = col1;
+ rightCol = rightEdge + 1;
+ mFillDirection = FILL_RIGHT;
+ }
+ else
+ {
+ leftCol = leftEdge;
+ rightCol = col1 + 1;
+ mFillDirection = FILL_LEFT;
+ }
+ }
+
+ }
+ else
+ {
+ leftCol = GetCol(mMovingLine1.mTargetX);
+ rightCol = GetCol(mMovingLine2.mTargetX);
+ int row1 = GetRow(mMovingLine1.mTargetY);
+
+ if ((mMovingLine1.mBroken && !mMovingLine2.mBroken) ||
+ (!mMovingLine1.mBroken && mMovingLine2.mBroken))
+ {
+ leftCol = mMovingLine1.mBroken ? GetCol(mMovingLine2.mX) : leftCol;
+ rightCol = mMovingLine1.mBroken ? rightCol : GetCol(mMovingLine2.mX);
+ topRow = row1;
+ botRow = row1 + 1;
+ mFillDirection = FILL_DOWN;
+ }
+ else
+ {
+ int topEdge, botEdge;
+ GetHorizontalFillValues(row1, leftCol, rightCol, -1, &topEdge);
+ GetHorizontalFillValues(row1, leftCol, rightCol, 1, &botEdge);
+
+ if ((botEdge - row1) <= (row1 - topEdge))
+ {
+ topRow = row1;
+ botRow = botEdge + 1;
+ mFillDirection = FILL_DOWN;
+ }
+ else
+ {
+ topRow = topEdge;
+ botRow = row1 + 1;
+ mFillDirection = FILL_UP;
+ }
+ }
+
+ }
+
+ //Make a rectangular fill region: every block in it will eventually be filled.
+ // Then, for all grid pieces in that region, if they are in the normal state,
+ // set them to the filling state and initialize their mFillRect's
+ mFillRegion.mLeft = leftCol;
+ mFillRegion.mRight = rightCol - 1;
+ mFillRegion.mTop = topRow;
+ mFillRegion.mBottom = botRow - 1;
+
+ for (int y = topRow; y < botRow; y++)
+ {
+ for (int x = leftCol; x < rightCol; x++)
+ {
+ if (mGridState[y][x].mFillState == GRID_NORMAL)
+ {
+ mGridState[y][x].mFillState = GRID_FILLING;
+
+ switch (mFillDirection)
+ {
+ case FILL_RIGHT:
+ mGridState[y][x].mFillRect =
+ FRect(GetColPix(x), GetRowPix(y), 0, GRID_PIX_SIZE);
+ break;
+
+ case FILL_LEFT:
+ mGridState[y][x].mFillRect =
+ FRect(GetColPix(x + 1), GetRowPix(y), 0, GRID_PIX_SIZE);
+ break;
+
+ case FILL_UP:
+ mGridState[y][x].mFillRect =
+ FRect(GetColPix(x), GetRowPix(y + 1), GRID_PIX_SIZE, 0);
+ break;
+
+ case FILL_DOWN:
+ mGridState[y][x].mFillRect =
+ FRect(GetColPix(x), GetRowPix(y), GRID_PIX_SIZE, 0);
+ break;
+ }
+ }
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::FillRectF(Graphics* g, FRect fr)
+{
+ Rect r = Rect((int)fr.mX, (int)fr.mY, (int)fr.mWidth, (int)fr.mHeight);
+ g->FillRect(r);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::GetVerticalFillValues(int startCol, int topRow, int botRow, int dir, int* edge)
+{
+ // If dir == -1, left, if 1, right
+ // See function header for algorithm description
+
+ bool done = false;
+ int col = startCol;
+
+ while (!done)
+ {
+ bool found = true;
+ for (int y = topRow; y < botRow; y++)
+ {
+ if (mGridState[y][col].mFillState != GRID_FILLED)
+ {
+ found = false;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ if ( ((dir > 0) && (++col >= GRID_WIDTH)) ||
+ ((dir < 0) && (--col < 0)) )
+ {
+ done = true;
+ *edge = col + (dir > 0 ? -1 : 1);
+ }
+ }
+ else
+ {
+ *edge = col;
+ done = true;
+ }
+
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::GetHorizontalFillValues(int startRow, int leftCol, int rightCol, int dir, int* edge)
+{
+ // If dir == -1, up, if 1, down
+ // See function header for algorithm description
+
+ bool done = false;
+ int row = startRow;
+
+ while (!done)
+ {
+
+ bool found = true;
+ for (int x = leftCol; x < rightCol; x++)
+ {
+ if (mGridState[row][x].mFillState != GRID_FILLED)
+ {
+ found = false;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ if ( ((dir > 0) && (++row >= GRID_HEIGHT)) ||
+ ((dir < 0) && (--row < 0)) )
+ {
+ done = true;
+ *edge = row + (dir > 0 ? -1 : 1);
+ }
+ }
+ else
+ {
+ *edge = row;
+ done = true;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::InitLevel(int level)
+{
+ mLives += level - mLevel;
+
+ mPopulationEaten = 0;
+ mPlanetSpeed += 0.15f;
+ mLevel = level;
+ mPlanets.clear();
+ mFlashCount = 0;
+ mPercentComplete = 0;
+ mPlanetsEaten.clear();
+ mBonusText.clear();
+ mParticles.clear();
+
+ mFilling = false;
+
+ // reset the grid state
+ int i;
+ for (i = 0; i < GRID_HEIGHT; i++)
+ {
+ for (int x = 0; x < GRID_WIDTH; x++)
+ {
+ mGridState[i][x].mFillRect = FRect(x * GRID_PIX_SIZE, GRID_START_Y + i * GRID_PIX_SIZE, 0, 0);
+ mGridState[i][x].mFillState = GRID_NORMAL;
+ }
+ }
+
+ // Start with 2 planets. Then add 1 every other level
+ int numPlanets = 2 + (mLevel / 2);
+ for (i = 0; i < numPlanets; i++)
+ {
+ Planet p;
+
+ // Choose a random name and export
+ p.mNameIdx = Rand() % NUM_PLANET_NAMES;
+ p.mExportIdx = Rand() % NUM_PLANET_EXPORTS;
+
+ // a random number I made up for the population. Increases by a random amount each level.
+ p.mPopulation = (mLevel * 133602) + 748819;
+
+ // Position it randomly within the confines of the grid
+ p.mX = GRID_START_X + 20 + (Rand() % (GRID_END_X - GRID_START_X - 20));
+ p.mY = GRID_START_Y + 20 + (Rand() % (GRID_END_Y - GRID_START_Y - 20));
+
+ // Get a random angle for the planet to travel in. It's easier to do RAND on
+ // degrees, so convert them to radians after choosing an angle
+ float a = (Rand() % 360) * M_PI / 180.0f;
+ p.mVX = mPlanetSpeed * cosf(a);
+ p.mVY = -mPlanetSpeed * sinf(a);
+
+ // don't let the speed be too close to 0 though, it's lame if the planet
+ // bounces just straight vertically or horizontally
+ if ((p.mVX >= -0.1) && (p.mVX <= 0.1))
+ p.mVX = 0.3f;
+
+ if ((p.mVY >= -0.1) && (p.mVY <= 0.1))
+ p.mVY = 0.3f;
+
+ // Set a random initial rotation angle and speed to rotate at.
+ // All angle manipulation is in radians.
+ p.mRotationAngle = (Rand() % 360) * M_PI / 180.0f;
+ p.mRotateSpeed = (float)(Rand() % 100) / 1000.0f;
+
+ // Choose a random image. There's 11 images, each is just 1 frame.
+ p.mImgCol = Rand() % IMAGE_PLANETS->mNumCols;
+
+ mPlanets.push_back(p);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool Board::MovePlanet(Planet* p, float theFrac)
+{
+ // This is a pretty simple collision detection routine and is good enough for this
+ // game. It's also a lot easier to understand than other more accurate but more
+ // complex methods. The basic idea is to check the two blocks in the direction of
+ // travel to see if they are solid or not, and if so, we reverse course, and
+ // don't move the planet to that new coordinate.
+
+ int w = IMAGE_PLANETS->GetCelWidth();
+ int h = IMAGE_PLANETS->GetCelHeight();
+ bool playSample = false;
+
+ // Update rotation
+ p->mRotationAngle += p->mRotateSpeed;
+
+ // Don't move it yet...compute where it WOULD be if the move was valid
+ float newx = p->mX + p->mVX * theFrac;
+ float newy = p->mY + p->mVY * theFrac;
+
+ // If moving right, we'll check the grid piece right of the
+ // planet to see if we hit it. Otherwise, we'll just use the grid piece that maps to
+ // where the new X coordinate is:
+ float checkx = p->mVX > 0 ? newx + GRID_PIX_SIZE : newx;
+ int col = GetCol(checkx);
+
+ // We're going to check both the current row and row below it:
+ int row = GetRow(p->mY);
+ int nextrow = ValidRow(row + 1) ? row + 1 : row;
+
+ if (ValidCol(col) && ValidRow(row))
+ {
+ int state1 = mGridState[row][col].mFillState;
+ int state2 = mGridState[nextrow][col].mFillState;
+
+ if ((state1 == GRID_NORMAL) && (state2 == GRID_NORMAL) && (newx > GRID_START_X))
+ p->mX = newx; // valid grid space
+ else if (((state1 == GRID_FILLING) || (state2 == GRID_FILLING)) && (newx > GRID_START_X))
+ {
+ // planet entered a grid space that is in the process of being filled, so make it explode
+ p->mExploding = true;
+ GivePlanetBonus(p);
+ return true;
+ }
+ else
+ {
+ // planet hit a filled in space, reverse the X velocity
+ playSample = true;
+ p->mVX = -p->mVX;
+ }
+ }
+ else
+ {
+ // Not valid cases would be if the planet hit the edges of the board, where there
+ // aren't any grid tiles. If so, just bounce it off the wall.
+ playSample = true;
+ p->mVX = -p->mVX;
+ }
+
+
+ // Now for the Y direction. The principal is the same as above.
+ int checky = p->mVY > 0 ? newy + GRID_PIX_SIZE : newy;
+ row = GetRow(checky);
+ col = GetCol(p->mX);
+ int nextcol = ValidCol(col + 1) ? col + 1 : col;
+
+ if (ValidCol(col) && ValidRow(row))
+ {
+ int state1 = mGridState[row][col].mFillState;
+ int state2 = mGridState[row][nextcol].mFillState;
+
+ if ((state1 == GRID_NORMAL) && (state2 == GRID_NORMAL) && (newy > GRID_START_Y))
+ p->mY = newy;
+ else if (((state1 == GRID_FILLING) || (state2 == GRID_FILLING)) && (newy > GRID_START_Y))
+ {
+ p->mExploding = true;
+ GivePlanetBonus(p);
+ return true;
+ }
+ else
+ {
+ playSample = true;
+ p->mVY = -p->mVY;
+ }
+ }
+ else
+ {
+ p->mVY = -p->mVY;
+ playSample = true;
+ }
+
+ // When a planet hits a wall/filled in grid piece, bounce it and play a sound
+ if (playSample)
+ mApp->PlaySample(SOUND_PLANET_HIT);
+
+ CheckPlanetBeamCollision(p);
+
+ return false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::CheckPlanetBeamCollision(Planet* p)
+{
+ // We're just going to do a rectangular collision check on each of the beams
+ // and the given planet. Because the visible "beam" part of the image is smaller
+ // than the image width/height, and the same goes for the planet too, you'll notice
+ // that offsets are used to constrain the collision rectangles to make a more fair algorithm.
+ FRect pr = FRect(p->mX + 4, p->mY + 4, 11, 11);
+
+ FRect beam1Rect;
+
+ if (!mMovingLine1.mIsVertical)
+ beam1Rect = FRect(mMovingLine1.mX + 7, mMovingLine1.mY + 12, mMovingLine1.mWidth - 12, 8);
+ else
+ beam1Rect = FRect(mMovingLine1.mX + 12, mMovingLine1.mY + 10, 9, mMovingLine1.mHeight);
+
+ // Only allow the user to lose 1 life max: if both beams break you don't lose 2. If the beam breaks,
+ // set a flag and set its target to be its current location (indicating that it's done moving)
+ if (pr.Intersects(beam1Rect))
+ {
+ if (!mMovingLine1.mDone)
+ {
+ mMovingLine1.mBroken = true;
+ mApp->PlaySample(SOUND_BEAM_HIT);
+
+ if (!mMovingLine2.mBroken)
+ LostLife();
+
+ if (!mMovingLine1.mIsVertical)
+ mMovingLine1.mTargetX = mMovingLine1.mX = mMovingLine1.mX + mMovingLine1.mWidth;
+ else
+ mMovingLine1.mTargetY = mMovingLine1.mY = mMovingLine1.mY + mMovingLine1.mHeight;
+ }
+ else if (!mMovingLine1.mBroken && mMovingLine1.mDone && !mMovingLine2.mDone)
+ {
+ // bounce off of it
+ if (mMovingLine1.mIsVertical)
+ {
+ p->mVX *= -1.0f;
+ p->mX += p->mVX;
+ }
+ else
+ {
+ p->mVY *= -1.0f;
+ p->mY += p->mVY;
+ }
+ }
+ }
+
+ FRect beam2Rect;
+
+ if (!mMovingLine2.mIsVertical)
+ beam2Rect = FRect(mMovingLine2.mX, mMovingLine2.mY + 12, mMovingLine2.mWidth - 7, 8);
+ else
+ beam2Rect = FRect(mMovingLine2.mX + 12, mMovingLine2.mY, 9, mMovingLine2.mHeight);
+
+ if (pr.Intersects(beam2Rect))
+ {
+ if (!mMovingLine2.mDone)
+ {
+ mMovingLine2.mBroken = true;
+ mApp->PlaySample(SOUND_BEAM_HIT);
+
+ if (!mMovingLine1.mBroken)
+ LostLife();
+
+ if (!mMovingLine2.mIsVertical)
+ mMovingLine2.mTargetX = mMovingLine2.mX;
+ else
+ mMovingLine2.mTargetY = mMovingLine2.mY;
+ }
+ else if (!mMovingLine2.mBroken && mMovingLine2.mDone && !mMovingLine1.mDone)
+ {
+ // bounce off of it
+ if (mMovingLine2.mIsVertical)
+ {
+ p->mVX *= -1.0f;
+ p->mX += p->mVX;
+ }
+ else
+ {
+ p->mVY *= -1.0f;
+ p->mY += p->mVY;
+ }
+ }
+ }
+
+ if ((mMovingLine1.mDone && mMovingLine2.mDone) ||
+ (mMovingLine1.mBroken && mMovingLine2.mDone) ||
+ (mMovingLine2.mBroken && mMovingLine1.mDone))
+ mShortSound->Stop();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Pause(bool p)
+{
+ if (p)
+ {
+ // Since when we're paused we don't update each frame, call
+ // MarkDirty here so that we ensure the "PAUSED" overlay appears
+ MarkDirty();
+ ++mPauseLevel;
+
+ // Don't play the looping circuit sound
+ mShortSound->Stop();
+ }
+ else
+ {
+ if (--mPauseLevel == 0)
+ {
+ // If any of the lines are moving, re-play the shorting sound
+ if (!mMovingLine1.mDone || !mMovingLine2.mDone)
+ mShortSound->Play(true, false);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::KeyChar(char theChar)
+{
+ if (theChar == ' ')
+ Pause(mPauseLevel == 0);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::GivePlanetBonus(Planet* p)
+{
+ mTotalPopulationEaten += p->mPopulation;
+ mPopulationEaten += p->mPopulation;
+ mLineSpeed += BEAM_INC_SPEED;
+ if (mLineSpeed > MAX_BEAM_SPEED)
+ mLineSpeed = MAX_BEAM_SPEED;
+
+ ++mNumPlanetsEaten;
+
+ SexyString pName = PLANET_NAME[p->mNameIdx];
+ SexyString pExport = PLANET_EXPORTS[p->mExportIdx];
+ int points = mLevel * 1000;
+ AddBonusText(StrFormat(_S("%s: +%d"), pName.c_str(), points), p->mX, p->mY);
+ mScore += points;
+
+ mPlanetsEaten.push_back(pName);
+ mPlanetsEaten.push_back(pExport.c_str());
+ mPlanetsEaten.push_back(CommaSeperate(p->mPopulation));
+
+ std::map<int, int>::iterator it = mPlanetIdxCount.find(p->mNameIdx);
+ if (it == mPlanetIdxCount.end())
+ mPlanetIdxCount[p->mNameIdx] = 1;
+ else
+ ++it->second;
+
+ it = mExportIdxCount.find(p->mExportIdx);
+ if (it == mExportIdxCount.end())
+ mExportIdxCount[p->mExportIdx] = 1;
+ else
+ ++it->second;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::UpdatePercentComplete(void)
+{
+ if (mGameOverEffect->IsActive())
+ return;
+
+ int total = GRID_WIDTH * GRID_HEIGHT;
+ int actual = 0;
+
+ for (int y = 0; y < GRID_HEIGHT; y++)
+ for (int x = 0; x < GRID_WIDTH; x++)
+ if (mGridState[y][x].mFillState == GRID_FILLED)
+ ++actual;
+
+ int newAmount = (int) (((float)actual / (float)total) * 100.0f);
+
+ int pctCleared = newAmount - mPercentComplete;
+
+ // Make the edges of the grid flash the larger the filled region was, but not
+ // for more than 3 seconds.
+ mFlashCount = pctCleared * 10;
+ if (mFlashCount > 300)
+ mFlashCount = 300;
+
+ // Points are exponential, so the larger a fill region, the much larger the score
+ int points = pctCleared * pctCleared * 20;
+ mScore += points;
+ if (points > 0)
+ {
+ mApp->PlaySample(SOUND_REGION_FILLED);
+ AddBonusText(StrFormat(_S("+%d"), points));
+ }
+
+ mPercentComplete = newAmount;
+
+ if (mPercentComplete >= LEVELUP_PERCENT)
+ {
+ // Time to level up, set up the stats
+ LevelupStats ls;
+ ls.mLevelCompleted = mLevel;
+ ls.mPercentComplete = mPercentComplete;
+ ls.mPopulationEaten = mPopulationEaten;
+ ls.mPlanetsEaten = mPlanetsEaten;
+
+ // Award a bonus for extra region filling action
+ if (mPercentComplete >= COMPLETION_BONUS_PCT)
+ mScore += COMPLETION_BONUS * mLevel;
+
+ mOptionsBtn->SetVisible(false);
+ mLevelupEffect->Activate(ls);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddBonusText(SexyString t)
+{
+ AddBonusText(t, mWidth / 2 - FONT_HUNGARR->StringWidth(t) / 2,
+ (mHeight - GRID_START_Y) / 2 - FONT_HUNGARR->GetHeight() / 2);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::AddBonusText(SexyString t, float x, float y)
+{
+ BonusText bt;
+ bt.mText = t;
+ bt.mX = x;
+ bt.mY = y;
+
+ mBonusText.push_back(bt);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::LostLife(void)
+{
+
+ if (--mLives <= 0)
+ {
+ mLives = 0;
+
+ // Game over. Set up the stats:
+ mOptionsBtn->SetVisible(false);
+ EndGameStats es;
+ es.mLevel = mLevel;
+ es.mNumPlanetsEaten = mNumPlanetsEaten;
+ es.mPopulationConsumed = mTotalPopulationEaten;
+ es.mScore = mScore;
+
+ // Find which planet and export were consumed the most:
+ int idx = -1;
+ int count = 0;
+ int i;
+ for (i = 0; i < NUM_PLANET_NAMES; i++)
+ {
+ std::map<int, int>::iterator it = mPlanetIdxCount.find(i);
+ if (it != mPlanetIdxCount.end())
+ {
+ if (it->second > count)
+ {
+ count = it->second;
+ idx = i;
+ }
+ }
+ }
+
+ if (idx != -1)
+ es.mFavoritePlanet = PLANET_NAME[idx];
+ else
+ es.mFavoritePlanet = _S("N/A");
+
+ idx = -1;
+ count = 0;
+ for (i = 0; i < NUM_PLANET_EXPORTS; i++)
+ {
+ std::map<int, int>::iterator it = mExportIdxCount.find(i);
+ if (it != mExportIdxCount.end())
+ {
+ if (it->second > count)
+ {
+ count = it->second;
+ idx = i;
+ }
+ }
+ }
+
+ if (idx != -1)
+ es.mFavoriteExport = PLANET_EXPORTS[idx];
+ else
+ es.mFavoriteExport = _S("N/A");
+
+ // Fade out the music
+ mApp->mMusicInterface->FadeOut(0, true);
+
+ mShortSound->Stop();
+
+ mGameOverEffect->Activate(es);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::EmitSparks(void)
+{
+ // This basically emits sparks between various angles, depending on
+ // the orientation of the line. The angle values I had to play around with
+ // until I found ones that I liked, and there's no magic secret formula for
+ // coming up with them, unless you just know how to guess well. Again,
+ // the Rand() function is easier dealt with using degrees, so we convert them
+ // to radians after choosing an angle. Then, using some basic math, we compute
+ // the separate XY velocities for the projectiles. In some cases, projectiles use
+ // diferent velocities, and again, that was just due to trying to get the nicest look
+ // and involved some playing around with to figure out. The offsets are to make the sparks
+ // appear to come out of the bulbous part of the line.
+ if (!mMovingLine1.mDone && !mMovingLine1.mBroken)
+ {
+ if (mMovingLine1.mIsVertical)
+ {
+ // between 90 and 180 degrees for left side emission
+ float angle = (90 + (Rand() % 90)) * M_PI / 180.0f;
+ float vx = cosf(angle) * 2.0f;
+ float vy = -sinf(angle) * 2.0f;
+ mParticles.push_back(Particle(mMovingLine1.mX + 5, mMovingLine1.mY + 8, vx, vy));
+
+ // between 0 and 90 degrees for right side emission
+ angle = (Rand() % 90) * M_PI / 180.0f;
+ vx = cosf(angle) * 2.0f;
+ vy = -sinf(angle) * 2.0f;
+ mParticles.push_back(Particle(mMovingLine1.mX + 5, mMovingLine1.mY + 8, vx, vy));
+ }
+ else
+ {
+ // between 280 and 320 degrees for bottom side emission
+ float angle = (280 + (Rand() % 40)) * M_PI / 180.0f;
+ float vx = cosf(angle) * 4.0f;
+ float vy = -sinf(angle) * 2.0f;
+ mParticles.push_back(Particle(mMovingLine1.mX + 5, mMovingLine1.mY + 8, vx, vy));
+
+ // between 50 and 90 degrees for top side emission
+ angle = (50 + (Rand() % 40)) * M_PI / 180.0f;
+ vx = cosf(angle) * 4.0f;
+ vy = -sinf(angle) * 3.0f;
+ mParticles.push_back(Particle(mMovingLine1.mX + 5, mMovingLine1.mY + 8, vx, vy));
+ }
+ }
+
+ if (!mMovingLine2.mDone && !mMovingLine2.mBroken)
+ {
+ if (mMovingLine2.mIsVertical)
+ {
+ // between 50 and 90 degrees for left side emission
+ float angle = (50 + (Rand() % 40)) * M_PI / 180.0f;
+ float vx = cosf(angle) * 3.0f;
+ float vy = -sinf(angle) * 4.0f;
+ mParticles.push_back(Particle(mMovingLine2.mX + 1, mMovingLine2.mY + mMovingLine2.mHeight - 17, vx, vy));
+
+ // between 120 and 160 degrees for right side emission
+ angle = (120 + (Rand() % 40)) * M_PI / 180.0f;
+ vx = cosf(angle) * 2.0f;
+ vy = -sinf(angle) * 4.0f;
+ mParticles.push_back(Particle(mMovingLine2.mX + 1, mMovingLine2.mY + mMovingLine2.mHeight - 17, vx, vy));
+ }
+ else
+ {
+ // between 90 and 140 degrees for top side emission
+ float angle = (90 + (Rand() % 50)) * M_PI / 180.0f;
+ float vx = cosf(angle) * 4.0f;
+ float vy = -sinf(angle) * 3.0f;
+ mParticles.push_back(Particle(mMovingLine2.mX + mMovingLine2.mWidth - 20, mMovingLine2.mY + 2, vx, vy));
+
+ // between 220 and 260 degrees for bottom side emission
+ angle = (220 + (Rand() % 40)) * M_PI / 180.0f;
+ vx = cosf(angle) * 4.0f;
+ vy = -sinf(angle) * 4.0f;
+ mParticles.push_back(Particle(mMovingLine2.mX + mMovingLine2.mWidth - 20, mMovingLine2.mY + 2, vx, vy));
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::OptionsDialogDone()
+{
+ // If any of the lines are moving, re-play the shorting sound
+ if (!mMovingLine1.mDone || !mMovingLine2.mDone)
+ mShortSound->Play(true, false);
+
+ Pause(false);
+
+ // Give focus back to the board so that it processes keyboard input
+ mApp->mWidgetManager->SetFocus(this);
+}
+ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/Board.h b/osframework/source/demos/Hun-garr/Board.h
new file mode 100644
index 0000000..e627c80
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Board.h
@@ -0,0 +1,739 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+//////////////////////////////////////////////////////////////////////////
+// Board.h
+//
+// This is the third class to look at in this particular demo
+// (after main.cpp and GameApp.h/.cpp). The Board class is where most of
+// your actual game programming will go. It is here that we will do
+// all our game drawing, updating, and input processing. Of course, in
+// a larger application, you would probably do drawing and updating in
+// multiple files, but you would still most likely use something similar
+// to a Board class as the master game logic class.
+//
+// The reason that the Board class is a widget is because when a widget
+// is added to the GameApp's WidgetManager, it will automatically have its
+// Update and Draw methods called, and it will automatically receive input
+// at the appropriate times. Furthermore, by making it a widget and adding
+// it to the WidgetManager, the game logic loop, Update(), will be guaranteed
+// to run at a standard 100FPS on all machines. This is extremely important
+// as you always want your logic code to run at the same speed, but want
+// the drawing code to run as fast as possible. That way on faster machines
+// your program doesn't run its logic faster than on a slower machine.
+//
+// You can think of the Board as a canvas upon which we do all our
+// drawing, and a central hub where if we need to, we instruct other
+// classes where and when to draw to.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+#include "SexyAppFramework/Rect.h"
+
+namespace Sexy
+{
+
+
+class Graphics;
+class GameApp;
+class ButtonWidget;
+class WidgetManager;
+class LevelupEffect;
+class GameOverEffect;
+class SoundInstance;
+
+// Each grid piece is this many pixels wide/tall
+const int GRID_PIX_SIZE = 16;
+
+// Starting/ending Y coordinate of the grid (above it is the status display)
+const int GRID_START_Y = 128;
+const int GRID_END_Y = 480 - GRID_PIX_SIZE;
+
+// Starting/ending X coordinate of the grid
+const int GRID_START_X = GRID_PIX_SIZE;
+const int GRID_END_X = 640 - GRID_PIX_SIZE;
+
+// Total number of grid tiles wide/tall
+const int GRID_WIDTH = (GRID_END_X - GRID_START_X) / GRID_PIX_SIZE;
+const int GRID_HEIGHT = (GRID_END_Y - GRID_START_Y) / GRID_PIX_SIZE;
+
+// >= this percent begins the next level
+const int LEVELUP_PERCENT = 80;
+
+// >= this percent gives a bonus
+const int COMPLETION_BONUS_PCT = 85;
+
+// Bonus for >= COMPLETION_BONUS_PCT
+const int COMPLETION_BONUS = 20000;
+
+//////////////////////////////////////////////////////////////////////////
+// Represents one segment of the two expanding lines that emit
+// from the cursor when the left mouse button is pressed on a valid
+// grid region.
+//////////////////////////////////////////////////////////////////////////
+struct ExpandingLine
+{
+ bool mIsVertical; // Orientation of the line
+
+ // When the line reaches its target, that particular segment is done and planets can bounce off it.
+ // If a planet hits it before its done, it will break and you will lose a life
+ bool mDone;
+ bool mBroken; // Indicates if the line broke and thus the player lost a life.
+ float mX;
+ float mY;
+ float mWidth;
+ float mHeight;
+ float mTargetX; // XY coordinate the line is trying to reach
+ float mTargetY;
+
+ ExpandingLine() {mIsVertical = mDone = true; mBroken = false; mX = mY = mWidth = mHeight = mTargetX = mTargetY = 0;}
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Represents one of the little grid squares on the board.
+// Each square can have 1 of 3 states. See the Board class for the states.
+//////////////////////////////////////////////////////////////////////////
+struct GridTile
+{
+ int mFillState;
+
+ // A rectangle, used when the grid space is being filled in. This indicates
+ // the actual region that is currently filled. The unfilled region is drawn
+ // normally. Regions expand over time, and don't instantly fill up.
+ FRect mFillRect;
+
+ GridTile() {mFillState = 0;}
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Represents one of the bouncing balls ("Planets" I suppose). For
+// fun, planets get a random name and export, which the player, "Hun-Garr",
+// eats. If a planet is inside a region as it fills, the planet will be
+// destroyed. Each planet destroyed makes the player's beams move faster,
+// up to a point.
+//////////////////////////////////////////////////////////////////////////
+struct Planet
+{
+ unsigned int mPopulation; // A fun little stat, indicates how many people live on the planet
+ int mImgCol; // There are 11 planets, this is the column indicating the planet image to draw
+ int mExplodeFrame; // When it's dying, this keeps track of the current frame of animation
+ int mExplodeSpeed; // How fast the death animation runs
+ int mNameIdx, mExportIdx; // Index into the two tables that contain planet names and export lists
+ int mTimer; // Counter used for animation timing
+ float mX, mY;
+ float mVX, mVY; // X/Y speed
+ float mRotationAngle; // In 3D mode, the planets rotate. This is the present angle
+ float mRotateSpeed; // How fast he planet rotates, in 3D mode
+ bool mExploding; // If true, the planet is dying and going through its explosion state
+
+ Planet() {mPopulation = mImgCol = mExportIdx = mNameIdx = mTimer = 0;
+ mX = mY = mVX = mVY = mRotationAngle = mRotateSpeed = 0;
+ mExplodeSpeed = 8; mExplodeFrame = 0; mExploding = false;}
+};
+
+
+//////////////////////////////////////////////////////////////////////////
+// Used for the 3 layer star field effect.
+//////////////////////////////////////////////////////////////////////////
+struct Star
+{
+ float mX, mY;
+ float mSpeed; // How fast the star is moving rightward
+ Color mColor; // Color, for some depth perception trickery
+};
+
+//////////////////////////////////////////////////////////////////////////
+// The flashy bonus text that floats up when you get points
+//////////////////////////////////////////////////////////////////////////
+struct BonusText
+{
+ int mHue; // See the .CPP file for info on using hue/saturation/luminance values
+ int mAlpha; // How faded out the text is
+ float mX, mY;
+ SexyString mText;
+
+ BonusText() {mAlpha = 255; mHue = 0; mX = mY = 0;}
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Used for the particle effects that fly off of the moving beams
+//////////////////////////////////////////////////////////////////////////
+struct Particle
+{
+ float mX, mY;
+ float mVX, mVY; // X/Y speed
+ int mFrame; // Which frame of animation it's on
+ int mTimer; // Used to control the animation
+
+ Particle(float x, float y, float vx, float vy)
+ {mX = x, mY = y; mVX = vx; mVY = vy; mFrame = 0; mTimer = 0;}
+};
+
+
+#define MAX_STARS 300
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+class Board : public Widget, public ButtonListener
+{
+
+ private:
+
+ // The direction that the grid is being filled in
+ enum
+ {
+ FILL_LEFT,
+ FILL_RIGHT,
+ FILL_UP,
+ FILL_DOWN
+ };
+
+ // The possible states for each little grid cube
+ enum
+ {
+ GRID_NORMAL, // Drawn regularly, not filled in
+ GRID_FILLING, // In the process of being filled in, will partially draw filled and normal
+ GRID_FILLED // Totally filled in, piece now acts as a wall and draws differently
+ };
+
+ // For the stats at the end of the game that display the planet and export you ate the most,
+ // we keep track of them in the maps below. The key is the index from the PLANET_NAME or
+ // PLANET_EXPORTS table, and the value is the number of times it has been consumed. Reset on death
+ std::map<int, int> mPlanetIdxCount;
+ std::map<int, int> mExportIdxCount;
+ std::vector<BonusText> mBonusText;
+ std::vector<Planet> mPlanets; // A list of all the planets bouncing on the level
+
+ // When a planet is eaten, we dump its name, export, and population (comma delimited) in that
+ // order into this list, which will be passed to the level up class for a stats summary of
+ // the past level.
+ std::vector<SexyString> mPlanetsEaten;
+ std::vector<Particle> mParticles;
+
+ GameApp* mApp;
+
+ // The two beams that the player emits with a left click. Line 1 is ALWAYS either
+ // up or left, and line 2 is ALWAYS either down or right.
+ ExpandingLine mMovingLine1, mMovingLine2;
+ GridTile** mGridState; // 2D array of all the grid tiles
+ Insets mFillRegion; // Indicates the rectangular region being filled.
+ Star mStarField[MAX_STARS];
+ LevelupEffect* mLevelupEffect;
+ GameOverEffect* mGameOverEffect;
+ ButtonWidget* mOptionsBtn;
+
+ // The shorting out, electrical sound of the beams moving. We use a SoundInstance pointer
+ // because we want to loop the sound while the beam is moving, and stop it when done.
+ // This is easiest done manually.
+ SoundInstance* mShortSound;
+
+ bool mHungarrIsVertical; // Orientation of the player: will the lines come out vertical or horizontal?
+ bool mFilling; // Is the grid currently being filled?
+
+ int mFillDirection; // One of the FILL_ enums
+ int mHungarrX, mHungarrY; // XY of the IMAGE of the player, not exactly where the beams go though
+ int mLevel;
+ int mPopulationEaten; // Number of people eaten this level
+ int mTotalPopulationEaten; // Total number of people eaten this game
+ int mNumPlanetsEaten; // Total number of planets eaten this game
+ int mPercentComplete; // What % filled the grid is
+
+ // Indicates the number of times the game has been asked to pause. When unpausing, we decrement
+ // this value. Not really needed in this game, but in general a good idea, as every time a dialog
+ // box pops up or the app loses focus or anything like that, you'll want to only fully unpause
+ // everything when ALL the elements that requested a pause are complete, and not just one of them.
+ int mPauseLevel;
+ int mBorderHue; // HSL value of the border for a flashing effect. See .CPP for more info
+ int mFlashCount; // How long the border will flash for
+ int mLives;
+ int mScore;
+ int mBeamPulseVal; // Current intensity for the pulsing effect of the moving beams
+ int mBeamPulseAmt; // Current amount to inc/dec the intensity by for a pulsing effect
+
+ float mLine1X, mLine1Y; // XYs of the two lines that are drawn underneath Hun-garr. These
+ float mLine2X, mLine2Y; // are always drawn and are not the same as the moving line positions.
+ float mLineSpeed; // Gets faster with each planet destroyed
+ float mFillSpeed; // How quickly to fill in the grid
+
+ // Current max rate the planets can move at. Used with the planet's angle of motion to determine separate
+ // XY movement values. This increases with each level.
+ float mPlanetSpeed;
+
+ private:
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: UpdateHungarrPosition
+ // Parameters:
+ // x, y - Pixel location of the Windows cursor
+ //
+ // Purpose: Given a pixel location of the pointer, if it is within the
+ // valid bounds of the grid region, will update the XY to draw the
+ // Hun-garr bitmap at, as well as the little pulsing beams that are attached.
+ //////////////////////////////////////////////////////////////////////////
+ void UpdateHungarrPosition(int x, int y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: UpdatePercentComplete
+ //
+ // Purpose: After the lines are done moving, this is called to see how
+ // full the grid is, and potentially take the player to the next level.
+ //////////////////////////////////////////////////////////////////////////
+ void UpdatePercentComplete(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawMovingBeams
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Helper function, draws the beams as they move across the grid.
+ //////////////////////////////////////////////////////////////////////////
+ void DrawMovingBeams(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Beam1DrawHelper
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Convenience function for DrawMovingBeams to avoid copy/pasting
+ //////////////////////////////////////////////////////////////////////////
+ void Beam1DrawHelper(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Beam2DrawHelper
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Convenience function for DrawMovingBeams to avoid copy/pasting
+ //////////////////////////////////////////////////////////////////////////
+ void Beam2DrawHelper(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawGrid
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Draws all the little rectangles that make up the grid.
+ //////////////////////////////////////////////////////////////////////////
+ void DrawGrid(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawPlanets
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Draws all the planets, convenience function
+ //////////////////////////////////////////////////////////////////////////
+ void DrawPlanets(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawGrid
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Draws the player bitmap and the two pulsing lines that are
+ // attached.
+ //////////////////////////////////////////////////////////////////////////
+ void DrawHungarr(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawHungarrVertBeamsHelper
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Helper function for DrawGrid to avoid copy/pasting
+ //////////////////////////////////////////////////////////////////////////
+ void DrawHungarrVertBeamsHelper(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawHungarrHorizBeamsHelper
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Helper function for DrawGrid to avoid copy/pasting
+ //////////////////////////////////////////////////////////////////////////
+ void DrawHungarrHorizBeamsHelper(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawUI
+ // Parameters:
+ // g - Graphics object to draw to
+ //
+ // Purpose: Draws the interface elements of the game, such as the stats.
+ //////////////////////////////////////////////////////////////////////////
+ void DrawUI(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: FillRectF
+ // Parameters:
+ // g - Graphics object to draw to
+ // fr - FRect to draw
+ //
+ // Purpose: Convenience function, since you can't pass an FRect to DrawRect.
+ // Just converts the FRect to a normal Rect. We use FRects though for
+ // more precise motion control.
+ //////////////////////////////////////////////////////////////////////////
+ void FillRectF(Graphics* g, FRect fr);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: FillLeft
+ // Parameters:
+ // amt - How many pixels to fill
+ //
+ // Purpose: Updates the filling of the grid if it's moving leftward.
+ //////////////////////////////////////////////////////////////////////////
+ void FillLeft(float amt);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: FillRight
+ // Parameters:
+ // amt - How many pixels to fill
+ //
+ // Purpose: Updates the filling of the grid if it's moving rightward.
+ //////////////////////////////////////////////////////////////////////////
+ void FillRight(float amt);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: FillUp
+ // Parameters:
+ // amt - How many pixels to fill
+ //
+ // Purpose: Updates the filling of the grid if it's moving upward.
+ //////////////////////////////////////////////////////////////////////////
+ void FillUp(float amt);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: FillDown
+ // Parameters:
+ // amt - How many pixels to fill
+ //
+ // Purpose: Updates the filling of the grid if it's moving downward.
+ //////////////////////////////////////////////////////////////////////////
+ void FillDown(float amt);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CalculateFillRegions
+ //
+ // Purpose: Determines which areas need to be filled, once the grid lines
+ // are done moving.
+ //////////////////////////////////////////////////////////////////////////
+ void CalculateFillRegions(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: GetVerticalFillValues
+ // Parameters:
+ // startCol - Column in which the beams were released
+ // topRow - The row that the top line reached
+ // botRow - The row the the bottom line reached
+ // dir - 1 to compute the target fill line in the rightward direction,
+ // -1 to compute it in the leftward direction.
+ // edge - Set to the column that the filling should proceed towards
+ //
+ // Purpose: Given a direction to look in, finds a column to fill to.
+ // The column selected is the first column found where EVERY grid piece
+ // in it, from topRow to botRow, is in the normal grid state. If one is
+ // not found, the farthest grid edge is used. Partially filled lines are
+ // bypassed. This is used to get the CLOSEST edge to fill to for both of
+ // the possible directions: the edge that is closest to the player is
+ // selected and filling will proceed in that direction.
+ //////////////////////////////////////////////////////////////////////////
+ void GetVerticalFillValues(int startCol, int topRow, int botRow, int dir, int* edge);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: GetHorizontalFillValues
+ // Parameters:
+ // startRow - Row in which the beams were released
+ // leftCol - The column that the left line reached
+ // rightCol - The column the the right line reached
+ // dir - 1 to compute the target fill line in the downward direction,
+ // -1 to compute it in the upward direction.
+ // edge - Set to the column that the filling should proceed towards
+ //
+ // Purpose: Given a direction to look in, finds a row to fill to.
+ // The row selected is the first row found where EVERY grid piece
+ // in it, from leftCol to rightCol, is in the normal grid state. If one is
+ // not found, the farthest grid edge is used. Partially filled lines are
+ // bypassed. This is used to get the CLOSEST edge to fill to for both of
+ // the possible directions: the edge that is closest to the player is
+ // selected and filling will proceed in that direction.
+ //////////////////////////////////////////////////////////////////////////
+ void GetHorizontalFillValues(int startRow, int leftCol, int rightCol, int dir, int* edge);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MoveLines
+ // Parameters:
+ // theFrac - Value from UpdateF, used for smooth motion
+ //
+ // Purpose: Handles the moving of the lines once released.
+ //////////////////////////////////////////////////////////////////////////
+ void MoveLines(float theFrac);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MovePlanet
+ // Parameters:
+ // theFrac - Value from UpdateF, used for smooth motion
+ //
+ // Returns: true or false indicating if the planet blew up or not.
+ //
+ // Purpose: Handles the moving/bouncing of the planets
+ //////////////////////////////////////////////////////////////////////////
+ bool MovePlanet(Planet* p, float theFrac);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CheckPlanetBeamCollision
+ // Parameters:
+ // p - A planet to check for collision
+ //
+ // Purpose: Called by MoveLines, checks to see if the given planet
+ // collided with either of the beams. If a beam is still moving,
+ // it will break and the player will lose a life (only 1 life can
+ // be lost though, even if both are broken you don't lose 2 lives).
+ // If the beam is not moving, the planet will bounce off of it.
+ //////////////////////////////////////////////////////////////////////////
+ void CheckPlanetBeamCollision(Planet* p);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: InitLevel
+ // Parameters:
+ // level - The level to set up
+ //
+ // Purpose: Initializes the next level
+ //////////////////////////////////////////////////////////////////////////
+ void InitLevel(int level);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: GivePlanetBonus
+ // Parameters:
+ // p - The planet that was destroyed
+ //
+ // Purpose: Awards bonuses for destroying a planet and emits bonus text.
+ //////////////////////////////////////////////////////////////////////////
+ void GivePlanetBonus(Planet* p);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddBonusText
+ // Parameters:
+ // t - The text to add
+ //
+ // Purpose: Adds floating bonus text to the center of the screen
+ //////////////////////////////////////////////////////////////////////////
+ void AddBonusText(SexyString t);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddBonusText
+ // Parameters:
+ // t - The text to add
+ // x, y - Coordinates to add the text at
+ //
+ // Purpose: Allows exact placement of the bonus text
+ //////////////////////////////////////////////////////////////////////////
+ void AddBonusText(SexyString t, float x, float y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LostLife
+ //
+ // Purpose: Convenience function, used to decrement the player's
+ // life and if it reaches 0, to start the end game sequence.
+ //////////////////////////////////////////////////////////////////////////
+ void LostLife(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: EmitSparks
+ //
+ // Purpose: Every frame, sends out more sparks from the edges of
+ // the two beams if they are moving.
+ //////////////////////////////////////////////////////////////////////////
+ void EmitSparks(void);
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Board
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ Board(GameApp* theApp);
+
+ virtual ~Board();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: KeyChar
+ // Parameters:
+ // theChar - The ASCII character pressed
+ //
+ // Purpose: Called by the WidgetManager if a key is pressed and the Board
+ // has focus. Used to see if space was pressed, to toggle pause state.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void KeyChar(char theChar);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this function
+ // is the main method that is responsible for all graphical and textual
+ // displaying.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager, this method
+ // is GUARANTEED to be called 100 times per second (100FPS) and is where
+ // all main game logic is performed. Of course, if you had a larger more
+ // complex game, you'd most likely divide your logic between several
+ // other files, but this is commonly the central place where all game
+ // logic begins and is executed.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Update();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: UpdateF
+ // Parameters:
+ // theFrac - The number of updates this time slice represents.
+ //
+ // Returns: none
+ //
+ // Purpose: Like Update, but allows for smooth motion. See previous
+ // demos or the doc for a lengthy explanation.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void UpdateF(float theFrac);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the Board class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseMove
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime the
+ // mouse moves. The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseMove(int x, int y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseDown
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ // theClickCount - An integer indicating which mouse button
+ // was pressed. One of the following:
+ // 1: Left button
+ // 2: Double-left-click
+ // 3: Middle button
+ // -1: Right button
+ // -2: Double-right-click
+ //
+ // IMPORTANT: Because you can't have a double click with a
+ // single click, you will receive BOTH a left (or right) button as well
+ // as a double left (or right) button message whenever you double-click.
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime
+ // a mouse button is in the down state.
+ // The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseDown(int x, int y, int theClickCount);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: MouseDrag
+ // Parameters:
+ // x - X coordinate relative to the application of the mouse
+ // y - Y coordinate relative to the application of the mouse
+ //
+ // Returns: none
+ //
+ // Purpose: Called by the WidgetManager automatically anytime the
+ // mouse moves AND a button is held down. This is the same thing as
+ // MouseMove except that it represents a drag operation. When dragging,
+ // MouseDrag will be called INSTEAD OF MouseMove.
+ // The topmost widget (i.e. the widget most immediately
+ // under the cursor) is the one who gets the function call, and any
+ // widgets underneath by default are ignored.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void MouseDrag(int x, int y);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Pause
+ // Parameters:
+ // p - Boolean indicating pause or unpause
+ //
+ // Purpose: Pauses/unpauses the game
+ //////////////////////////////////////////////////////////////////////////
+ void Pause(bool p);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: OptionsDialogDone
+ //
+ // Purpose: Called by the options dialog box when it closes, so the board
+ // can perform some misc tasks.
+ //////////////////////////////////////////////////////////////////////////
+ void OptionsDialogDone();
+};
+
+
+}
+
+#endif // __BOARD_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/GameApp.cpp b/osframework/source/demos/Hun-garr/GameApp.cpp
new file mode 100644
index 0000000..0c5a3c5
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/GameApp.cpp
@@ -0,0 +1,279 @@
+#include "GameApp.h"
+#include "TitleScreen.h"
+#include "Board.h"
+#include "OptionsDialog.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ResourceManager.h"
+#include "SexyAppFramework/BassMusicInterface.h"
+#include "SexyAppFramework/Dialog.h"
+#include "Res.h"
+
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::GameApp()
+{
+ mProdName = "Hun-garr Needs Planets!";
+ mProductVersion = "1.0";
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+ mRegKey = "PopCap\\SexyAppFramework\\Hungarr";
+
+ mWidth = 640;
+ mHeight = 480;
+
+ mDebugKeysEnabled = true;
+
+ // By setting this to true, the framework will automatically check to see
+ // if hardware acceleration can be turned on. This doesn't guarantee that it
+ // WILL be turned on, however. Some cards just aren't compatible or have
+ // known issues. Also, cards with less than 8MB of video RAM aren't supported.
+ // There are ways to override the 3D enabled settings, which we will discuss
+ // in a later demo. As a side note, if you want to see if you app is
+ // running with 3D acceleration, first enable debug keys by pressing
+ // CTRL-ALT-D and then press F9. To toggle 3D on/off, press F8. That is just
+ // for testing purposes.
+ mAutoEnable3D = true;
+
+ mBoard = NULL;
+ mTitleScreen = NULL;
+
+ // Enable smooth motion via UpdateF
+ mVSyncUpdates = true;
+
+ // Because it's annoying to hear the sound of the planets hitting a wall too many
+ // times in a second, we'll limit how many can occur.
+ mLastPlanetHitSoundTime = -30;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameApp::~GameApp()
+{
+ if (mBoard != NULL)
+ mWidgetManager->RemoveWidget(mBoard);
+
+ delete mBoard;
+
+ if (mTitleScreen != NULL)
+ mWidgetManager->RemoveWidget(mTitleScreen);
+ delete mTitleScreen;
+
+ // Using "" deletes ALL resources
+ mResourceManager->DeleteResources("");
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::Init()
+{
+
+ SexyAppBase::Init();
+
+ LoadResourceManifest();
+ if (!mResourceManager->LoadResources("Init"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractInitResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // To use custom cursors, you have to specify an image resource
+ // to use. The CURSOR_ defines indicate which cursor type you
+ // want to assign the image to.
+ // CURSOR_POINTER is the normal Windows pointer.
+ // CURSOR_HAND is used when mousing over widgets (if mDoFinger is true).
+ // CURSOR_DRAGGING is used when a drag operation is happening.
+ // CURSOR_TEXT is the icon used when entering text in an edit box.
+ SetCursorImage(CURSOR_POINTER, IMAGE_CUSTOM_POINTER);
+ SetCursorImage(CURSOR_HAND, IMAGE_CUSTOM_HAND);
+ SetCursorImage(CURSOR_DRAGGING, IMAGE_CUSTOM_DRAGGING);
+ SetCursorImage(CURSOR_TEXT, IMAGE_CUSTOM_TEXT);
+
+ if (!mResourceManager->LoadResources("TitleScreen"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractTitleScreenResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // Now let's create and add our title screen to the widget manager
+ mTitleScreen = new TitleScreen(this);
+ mTitleScreen->Resize(0, 0, mWidth, mHeight);
+
+ // Let's let the title screen initialize it's widgets and data
+ // before adding it to the widget manager:
+ mTitleScreen->Init();
+
+ mWidgetManager->AddWidget(mTitleScreen);
+
+ // This example just uses 1 standard OGG file instead of a tracker file.
+ // Since we aren't cross fading at all, we'll only load it once.
+ mMusicInterface->LoadMusic(0, "music/hungarr.ogg");
+ mMusicInterface->FadeIn(0, 0, 0.002, false);
+
+ mNumLoadingThreadTasks = mResourceManager->GetNumResources("Game") +
+ mResourceManager->GetNumResources("Hungarr");
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadProc()
+{
+
+ mResourceManager->StartLoadResources("Game");
+
+ while (mResourceManager->LoadNextResource())
+ {
+ mCompletedLoadingThreadTasks++;
+ if (mShutdown)
+ return;
+
+ mTitleScreen->MarkDirty();
+ }
+
+ if (mResourceManager->HadError() || !ExtractGameResources(mResourceManager))
+ {
+ ShowResourceError(false);
+ mLoadingFailed = true;
+
+ return;
+ }
+
+ mResourceManager->StartLoadResources("Hungarr");
+
+ while (mResourceManager->LoadNextResource())
+ {
+ mCompletedLoadingThreadTasks++;
+ if (mShutdown)
+ return;
+
+ mTitleScreen->MarkDirty();
+ }
+
+ if (mResourceManager->HadError() || !ExtractHungarrResources(mResourceManager))
+ {
+ ShowResourceError(false);
+ mLoadingFailed = true;
+
+ return;
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LoadingThreadCompleted()
+{
+ // Let the base app class also know that we have completed
+ SexyAppBase::LoadingThreadCompleted();
+
+ if (mLoadingFailed)
+ return;
+
+ mTitleScreen->LoadingComplete();
+
+ mTitleScreen->MarkDirty();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::TitleScreenIsFinished()
+{
+
+ mTitleScreen = NULL;
+ mBoard = new Board(this);
+ mResourceManager->DeleteResources("TitleScreen");
+
+
+ mBoard->Resize(0, 0, mWidth, mHeight);
+ mWidgetManager->AddWidget(mBoard);
+ mWidgetManager->SetFocus(mBoard);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Dialog* GameApp::NewDialog(int theDialogId, bool isModal, const std::string& theDialogHeader,
+ const std::string& theDialogLines, const std::string& theDialogFooter, int theButtonMode)
+{
+ // Rather than dupliate a lengthy explanation, check out the top of DemoDialog.cpp for a complete description
+ // of what all the parameters and functions are, in Demo5.
+ Dialog* d = new Dialog(IMAGE_DIALOG_BOX, IMAGE_DIALOG_BUTTON, theDialogId, isModal,
+ StringToSexyStringFast(theDialogHeader), StringToSexyStringFast(theDialogLines), StringToSexyStringFast(theDialogFooter), theButtonMode);
+
+ d->SetButtonFont(FONT_DEFAULT);
+ d->SetLinesFont(FONT_DEFAULT);
+ d->SetHeaderFont(FONT_DEFAULT);
+
+ d->SetColor(Dialog::COLOR_HEADER, Color::Black);
+ d->SetColor(Dialog::COLOR_LINES, Color::Black);
+
+ d->mSpaceAfterHeader = 30;
+ d->Resize(100, 100, 300, 250);
+
+ return d;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::LostFocus()
+{
+ SexyAppBase::LostFocus();
+
+ // When losing focus, we should pause the game board
+ if (mBoard)
+ mBoard->Pause(true);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::GotFocus()
+{
+ SexyAppBase::GotFocus();
+
+ if (mBoard)
+ mBoard->Pause(false);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::ButtonPress(int theId)
+{
+ if (theId == OptionsDialog::MESSAGE_BOX_ID + 2000)
+ KillDialog(theId - 2000);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameApp::PlaySample(int theSoundNum)
+{
+ // If playing the sound for when a planet hits a wall, only let it
+ // play if it hasn't played the sound for at least 30 update frames
+ // (30 hundredths of a second).
+ if (theSoundNum == SOUND_PLANET_HIT)
+ {
+ if (mUpdateCount - mLastPlanetHitSoundTime > 30)
+ {
+ mLastPlanetHitSoundTime = mUpdateCount;
+ SexyAppBase::PlaySample(theSoundNum);
+ }
+ }
+ else
+ SexyAppBase::PlaySample(theSoundNum);
+}
diff --git a/osframework/source/demos/Hun-garr/GameApp.h b/osframework/source/demos/Hun-garr/GameApp.h
new file mode 100644
index 0000000..66676d3
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/GameApp.h
@@ -0,0 +1,171 @@
+#ifndef __GAMEAPP_H__
+#define __GAMEAPP_H__
+
+//////////////////////////////////////////////////////////////////////////
+// GameApp.h
+//
+// This is what drives the whole game. In here, you derive your class
+// from SexyAppBase and implement common game tasks, such as
+// responding to widgets (covered later), initializing and loading
+// resources, setting up the various game screens, etc.
+// All applications at minimum must have a class that derives from
+// SexyAppBase.
+//
+// The GameApp class is used to do such things as create the main
+// menu screen, create the main game class (where all drawing/updating/
+// interaction takes place), etc.
+//
+// IMPORTANT: Comments for topics covered in the previous demos will
+// be kept to a minimum and removed in most cases. You should read through
+// the previous demos to familiarize yourself with anything you don't
+// understand. All functions, variables, and concepts are explained
+// either in this demo, or in previous ones if they've already been covered.
+//////////////////////////////////////////////////////////////////////////
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+
+namespace Sexy
+{
+
+ class Board;
+ class TitleScreen;
+
+class GameApp : public SexyAppBase
+{
+
+ private:
+
+ Board* mBoard;
+ TitleScreen* mTitleScreen;
+
+ // Because it's annoying to hear the sound of the planets hitting a wall too many
+ // times in a second, we'll limit how many can occur.
+ int mLastPlanetHitSoundTime;
+
+ public:
+
+ GameApp();
+ virtual ~GameApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Initializes the application. Sets the resolution, overrides
+ // any default settings, and if there is a loader/intro screen (not in this demo)
+ // creates it and displays it. The framework will then automatically
+ // call the LoadingThreadProc() method after this method returns.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadProc
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Loads all resources in a separate thread. If there is a
+ // loader/intro screen (not in this demo), would also update the
+ // loader progress indicator. When the function returns, the
+ // LoadingThreadCompleted() method is automatically called.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadProc();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingThreadCompleted
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when LoadingThreadProc is complete and all resources
+ // have been loaded. It is in this function that you would then set up
+ // your main menu or similar screen. For this particular demo however,
+ // we will go straight to the main game class, "Board".
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LoadingThreadCompleted();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreenIsFinished
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called by the TitleScreen widget when it is about to close
+ // down, this indicates that we should now add the board widget and
+ // start the game.
+ //////////////////////////////////////////////////////////////////////////
+ void TitleScreenIsFinished();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: NewDialog
+ // Parameters:
+ // theDialogId - Unique ID to give this dialog box
+ // isModal - If true, only itself and widgets above it receive
+ // input events.
+ // theDialogHeader - String to display in the header part of the dialog box
+ // theDialogLines - String to use for the body of the dialog. May use
+ // \n characters to indicate new lines.
+ // theDialogFooter - If the button mode is BUTTONS_FOOTER, this is the text
+ // to use for the button, otherwise ignored.
+ // theButtonMode - One of 3 settings: Dialog::BUTTONS_YES_NO creates two
+ // "Yes" "No" buttons, Dialog::BUTTONS_OK_CANCEL creates two
+ // "OK" "Cancel" buttons, Dialog::BUTTONS_FOOTER creates one
+ // button with the text from theDialogFooter.
+ //
+ // Returns: A new dialog pointer for use by SexyAppBase's DoDialog method.
+ //
+ // Purpose: SexyAppBase contains a convenience function, DoDialog, that relies on
+ // this overriden function. DoDialog calls NewDialog which instructs it how to make
+ // a dialog box. You should use DoDialog to create and add your dialog boxes.
+ // The reason for this function is to allow for customized dialog boxes and to avoid
+ // having to have a gigantic function with every possible parameter to pass to the Dialog's
+ // constructor.
+ //////////////////////////////////////////////////////////////////////////
+ virtual Dialog* NewDialog(int theDialogId, bool isModal, const std::string& theDialogHeader,
+ const std::string& theDialogLines, const std::string& theDialogFooter, int theButtonMode);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LostFocus
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when the game itself loses focus, such as the user switch
+ // to another application.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LostFocus(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: GotFocus
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called when the app regains focus after losing it.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void GotFocus(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonPress:
+ // Parameters:
+ // theId - ID of the button pressed
+ //
+ // Returns: none
+ //
+ // Purpose: Called when the button is pressed, but before the mouse is
+ // released (which would instead generate a ButtonDepress event).
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonPress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: PlaySample
+ // Parameters:
+ // theSoundNum - The sound ID to play
+ // Returns: none
+ //
+ // Purpose: Plays the sample at normal pitch with no panning.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void PlaySample(int theSoundNum);
+};
+
+}
+
+
+#endif // __GAMEAPP_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/GameOverEffect.cpp b/osframework/source/demos/Hun-garr/GameOverEffect.cpp
new file mode 100644
index 0000000..4845813
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/GameOverEffect.cpp
@@ -0,0 +1,452 @@
+#pragma warning(disable:4244)
+#pragma warning(disable:4018)
+
+#include "GameOverEffect.h"
+#include "Res.h"
+#include "Board.h"
+#include "SexyAppFramework/SexyAppBase.h"
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/Image.h"
+
+using namespace Sexy;
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+GameOverEffect::GameOverEffect()
+{
+ Init();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameOverEffect::Init()
+{
+ mState = GameOverEffect::RED_FADE_IN;
+ mAlpha = 0;
+ mRed = 200;
+ mRedHoldCount = 100;
+ mRedChange = 4;
+ mActive = false;
+ mUpdateCnt = 0;
+ mHue = 0;
+ mCanInitFirstLevel = false;
+ mFadeOut = false;
+ mExplosion.clear();
+
+ mText.clear();
+ mText.push_back(Letter(_S("G")));
+ mText.push_back(Letter(_S("A")));
+ mText.push_back(Letter(_S("M")));
+ mText.push_back(Letter(_S("E")));
+ mText.push_back(Letter(_S(" O")));
+ mText.push_back(Letter(_S("V")));
+ mText.push_back(Letter(_S("E")));
+ mText.push_back(Letter(_S("R")));
+
+ mLines.clear();
+
+ // Make as many lines as the screen is wide, and stagger them by a
+ // random time up to 2 seconds, with speeds between 5 and 10 pixels per update.
+ for (int i = 0; i < gSexyAppBase->mWidth; i++)
+ mLines.push_back(DrippyLine((Rand() % 5) + 5, i, Rand() % 200));
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameOverEffect::Update(void)
+{
+ ++mUpdateCnt;
+
+ // HSL is an alternative to specifying an RGB color format.
+ // Using HSL lets us easily do the hyper blinking crazy weird
+ // flashing effect commonly found in old games, such as Robotron.
+ // Below, we increment the value by 7 per update. The &0xFF is an
+ // easy way to clamp the value between 0 and 255 instead of having to
+ // do a separate if (mHue > 255) mHue -= 255. This lets the value
+ // rollover and keep cycling.
+ mHue = (mHue + 7) & 0xFF;
+
+ if (!mFadeOut)
+ {
+ // 10 times per second we create a new planet explosion animation and place it at a random
+ // position within the grid's area.
+ if (mUpdateCnt % 10 == 0)
+ {
+ Explosion e;
+ e.mFrame = 0;
+ e.mX = GRID_START_X + (Rand() % (GRID_END_X - GRID_START_X - IMAGE_ATOMIC_EXPLOSION->GetCelWidth()));
+ e.mY = GRID_START_Y + (Rand() % (GRID_END_Y - GRID_START_Y - IMAGE_ATOMIC_EXPLOSION->GetCelHeight()));
+
+ mExplosion.push_back(e);
+ }
+
+ // Play a sound of a planet exploding ever 4th new planet. If we did this every single
+ // planet, then 10 times per second you'd hear it, and trust me, it's really irritating.
+ if ((mState == RED_FADE_IN) || (mState == RED_HOLD))
+ if (mUpdateCnt % 40 == 0)
+ gSexyAppBase->PlaySample(SOUND_EXPLOSION);
+
+ // Update each explosion animation. When it's done, remove it.
+ for (int i = 0; i < mExplosion.size(); i++)
+ {
+ Explosion* e = &mExplosion[i];
+
+ // The animation runs at 20FPS, so every 5 updates step the frame.
+ if (mUpdateCnt % 5 == 0)
+ {
+ if (++e->mFrame >+ IMAGE_ATOMIC_EXPLOSION->GetCelWidth())
+ {
+ mExplosion.erase(mExplosion.begin() + i);
+ --i;
+ }
+ }
+ }
+ }
+
+ if (mState == GameOverEffect::RED_FADE_IN)
+ {
+ // Slowly make the red effect become fully opaque to cover
+ // the screen, while at the same time making the red value
+ // pulse between 200 and 255.
+ if (++mAlpha >= 255)
+ {
+ mState = GameOverEffect::RED_HOLD;
+ mAlpha = 255;
+ }
+ else
+ PulseRed();
+ }
+ else if (mState == GameOverEffect::RED_HOLD)
+ {
+ // Hold for 1 second, the red pulsing effect for dramatic fun
+ if (--mRedHoldCount <= 0)
+ {
+ mState = GameOverEffect::SHOWING_LETTERS;
+ mUpdateCnt = 0;
+ gSexyAppBase->PlaySample(SOUND_GAME_OVER_TEXT);
+ }
+ else
+ PulseRed();
+ }
+ else if (mState == GameOverEffect::SHOWING_LETTERS)
+ {
+ // Start showing the GAME OVER letters. Fade out that fully
+ // red screen, but still let it pulse while we do so.
+ if (mAlpha > 0)
+ {
+ PulseRed();
+ mAlpha -= 2;
+ }
+
+ // Increase the red value on each letter by 2 per update.
+ // Once one letter has a red value of 50, let the next letter
+ // after it begin to fade in. Stop looping if a letter has less
+ // than 50 for its red value.
+ bool done = true;
+ for (int i = 0; i < mText.size(); i++)
+ {
+ Letter* l = &mText[i];
+
+ if (l->mRed < 254)
+ {
+ done = false;
+ l->mRed += 2;
+ }
+
+ if (l->mRed < 50)
+ {
+ done = false;
+ break;
+ }
+ }
+
+ if (done)
+ mState = GameOverEffect::FADING_LETTERS;
+ }
+ else if (mState == GameOverEffect::FADING_LETTERS)
+ {
+ // Now make the lettesr fade out, starting with
+ // the last letter. When a letter's red value drops
+ // below 205, allow the letter before it to also begin
+ // decreasing.
+ bool done = true;
+ for (int i = (int)mText.size() - 1; i >= 0; i--)
+ {
+ Letter* l = &mText[i];
+
+ if (l->mRed > 1)
+ {
+ done = false;
+ l->mRed -= 2;
+ }
+
+ if (l->mRed > 205)
+ {
+ done = false;
+ break;
+ }
+ }
+
+ if (done)
+ {
+ mAlpha = 0;
+ mState = GameOverEffect::SHOWING_STATS;
+ gSexyAppBase->PlaySample(SOUND_GAME_OVER_STATS);
+ }
+
+ }
+ else if ((mState == GameOverEffect::DRIP_OUT) && !mFadeOut)
+ {
+ // move the drippy lines, but we aren't fading the screen out yet.
+ bool alldone = true;
+ for (int i = 0; i < mLines.size(); i++)
+ {
+ // Once a line's starting delay has passed, it moves downward.
+ // Once it reaches the bottom of the screen, it begins to then
+ // move back upward. When all lines have moved upward, and thus the
+ // whole screen is totally opaque, we can begin the fade out sequence.
+ DrippyLine* dl = &mLines[i];
+ if (dl->mDelay > 0)
+ {
+ alldone = false;
+ --dl->mDelay;
+ }
+ else if (!dl->mDripUp)
+ {
+ alldone = false;
+ dl->mHeight += dl->mSpeed;
+ if (dl->mHeight >= gSexyAppBase->mHeight)
+ {
+ dl->mHeight = 0;
+ dl->mSpeed = 10;
+ dl->mDripUp = true;
+ }
+ }
+ else if (dl->mDripUp && (dl->mHeight < gSexyAppBase->mHeight))
+ {
+ dl->mHeight += dl->mSpeed;
+ if (dl->mHeight >= gSexyAppBase->mHeight)
+ dl->mHeight = gSexyAppBase->mHeight;
+ else
+ alldone = false;
+ }
+
+ }
+
+ if (alldone)
+ {
+ // Now that the screen is fully covered, allow the board to set up the first level
+ mCanInitFirstLevel = true;
+ mFadeOut = true;
+ mAlpha = 255;
+ }
+ }
+ else if ((mState == GameOverEffect::DRIP_OUT) && mFadeOut)
+ {
+ if (--mAlpha <= 0)
+ mActive = false;
+ }
+}
+
+///
+//////////////////////////////////////////////////////////////////////////
+void GameOverEffect::PulseRed()
+{
+ mRed += mRedChange;
+ if (mRed >= 255)
+ {
+ mRed = 255;
+ mRedChange = -mRedChange;
+ }
+ else if (mRed <= 200)
+ {
+ mRed = 200;
+ mRedChange = -mRedChange;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameOverEffect::Draw(Graphics* g)
+{
+ // Draw explosions for every state except the final fade out
+ if (!mFadeOut)
+ {
+ for (int i = 0; i < mExplosion.size(); i++)
+ {
+ Explosion* e = &mExplosion[i];
+ g->DrawImageCel(IMAGE_ATOMIC_EXPLOSION, e->mX, e->mY, e->mFrame);
+ }
+ }
+
+ if ((mState == GameOverEffect::RED_FADE_IN) || (mState == GameOverEffect::RED_HOLD))
+ {
+ g->SetColor(Color(mRed, 0, 0, mAlpha));
+ g->FillRect(0, 0, gSexyAppBase->mWidth, gSexyAppBase->mHeight);
+ }
+ else if ((mState == GameOverEffect::SHOWING_LETTERS) || (mState == GameOverEffect::FADING_LETTERS))
+ {
+ g->SetFont(FONT_HUNGARR);
+ int x = gSexyAppBase->mWidth / 2 - FONT_HUNGARR->StringWidth(_S("GAME OVER")) / 2;
+ int y = gSexyAppBase->mHeight / 2;
+
+ for (int i = 0; i < mText.size(); i++)
+ {
+ Letter* l = &mText[i];
+ if (l->mRed > 0)
+ {
+ g->SetColor(Color(l->mRed, 0, 0));
+ g->DrawString(l->mChar, x, y);
+ x += FONT_HUNGARR->StringWidth(l->mChar);
+ }
+ }
+
+ if (mAlpha > 0)
+ {
+ g->SetColor(Color(mRed, 0, 0, mAlpha));
+ g->FillRect(0, 0, gSexyAppBase->mWidth, gSexyAppBase->mHeight);
+ }
+ }
+ else if (mState == GameOverEffect::SHOWING_STATS)
+ {
+ g->DrawImage(IMAGE_HUNGARR_LOGO, gSexyAppBase->mWidth / 2 - IMAGE_HUNGARR_LOGO->mWidth / 2, 10);
+
+ g->SetFont(FONT_HUNGARR);
+ g->SetColor(Color::White);
+ int rightX = gSexyAppBase->mWidth / 2;
+ int y = 100;
+ SexyString s;
+ int strWidth;
+
+ s = _S("FINAL SCORE: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 0, 0));
+ g->DrawString(CommaSeperate(mStats.mScore), rightX, y);
+
+ g->SetColor(Color::White);
+ y += FONT_HUNGARR->GetHeight();
+ s = _S("LEVEL REACHED: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 0, 0));
+ g->DrawString(StrFormat(_S("%d"), mStats.mLevel), rightX, y);
+
+ g->SetColor(Color::White);
+ y += FONT_HUNGARR->GetHeight();
+ s = _S("TOTAL PLANETS EATEN: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 255, 0));
+ g->DrawString(StrFormat(_S("%d"), mStats.mNumPlanetsEaten), rightX, y);
+
+ g->SetColor(Color::White);
+ y += FONT_HUNGARR->GetHeight();
+ s = _S("TOTAL PEOPLE EATEN: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 255, 0));
+ g->DrawString(CommaSeperate(mStats.mPopulationConsumed), rightX, y);
+
+ g->SetColor(Color::White);
+ y += FONT_HUNGARR->GetHeight();
+ s = _S("TASTIEST PLANET: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(0, 255, 0));
+ g->DrawString(mStats.mFavoritePlanet, rightX, y);
+
+
+ g->SetColor(Color::White);
+ y += FONT_HUNGARR->GetHeight();
+ s = _S("EXPORT EATEN MOST: ");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(0, 255, 0));
+ g->DrawString(mStats.mFavoriteExport, rightX, y);
+ }
+ else if (mState == GameOverEffect::DRIP_OUT)
+ {
+ if (!mFadeOut)
+ {
+ // This is how we convert an HSL value to an RGB value, which we have to
+ // do to specify the color for the graphics object. The function HSLToRGB
+ // takes as parameters: hue, saturation, luminance. We want to leave the
+ // saturation at max and luminance at half for our particular example.
+ // The returned value is ANDed with 0xFFFFFFFF to clamp the values for
+ // the alpha, red, green, and blue to the valid region of 0 to 255.
+ Color hue = gSexyAppBase->HSLToRGB(mHue, 255, 128) & 0xFFFFFFFF;
+ for (int i = 0; i < mLines.size(); i++)
+ {
+ DrippyLine* dl = &mLines[i];
+ if (!dl->mDripUp && (dl->mDelay == 0))
+ {
+ // Draw a black line, with its bottommost pixel using the HSL color
+ g->SetColor(Color(0, 0, 0));
+ g->DrawRect(Rect(dl->mX, 0, 1, dl->mHeight - 1));
+ g->SetColor(hue);
+ g->DrawRect(Rect(dl->mX, dl->mHeight, 1, 1));
+ }
+ else if (dl->mDelay == 0)
+ {
+ // Moving up, draw the line in HSL and the rest in black
+ if (dl->mHeight < gSexyAppBase->mHeight)
+ {
+ g->SetColor(Color(0, 0, 0));
+ g->DrawRect(Rect(dl->mX, 0, 1, gSexyAppBase->mHeight - dl->mHeight));
+ }
+
+ g->SetColor(hue);
+ g->DrawRect(Rect(dl->mX, gSexyAppBase->mHeight - dl->mHeight, 1, dl->mHeight));
+ }
+ }
+ }
+ else
+ {
+ // We AND the color with 0xFFFFFF instead of 0xFFFFFFFF. Then, we OR it with the alpha value
+ // that we're fading out with shifted left 24 bits.
+ // This then sticks the alpha value, which changes over time,
+ // into our HSL color. As you may recall from previous demos, the actual color
+ // structure is 32 bit, and looks like this in binary form:
+ // AAAA RRRR GGGG BBBB Where A,R,G,B are alpha, red, green, blue.
+ Color hue = (gSexyAppBase->HSLToRGB(mHue, 255, 128) & 0xFFFFFF) | (mAlpha << 24);
+ g->SetColor(hue);
+ g->FillRect(0, 0, gSexyAppBase->mWidth, gSexyAppBase->mHeight);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool GameOverEffect::CanInitFirstLevel(void)
+{
+ if (mCanInitFirstLevel)
+ {
+ mCanInitFirstLevel = false;
+ return true;
+ }
+
+ return false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool GameOverEffect::HideBoard()
+{
+ return (mState == GameOverEffect::SHOWING_LETTERS) ||
+ (mState == GameOverEffect::RED_HOLD) ||
+ (mState == GameOverEffect::FADING_LETTERS) ||
+ (mState == GameOverEffect::SHOWING_STATS) ||
+ ((mState == GameOverEffect::DRIP_OUT) && !mFadeOut);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void GameOverEffect::DoneViewingStats()
+{
+ mState = DRIP_OUT;
+ gSexyAppBase->PlaySample(SOUND_GAME_OVER_CLICK);
+ gSexyAppBase->PlaySample(SOUND_GAME_OVER_RESTART);
+} \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/GameOverEffect.h b/osframework/source/demos/Hun-garr/GameOverEffect.h
new file mode 100644
index 0000000..47431f5
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/GameOverEffect.h
@@ -0,0 +1,204 @@
+//////////////////////////////////////////////////////////////////////////
+// GameOverEffect.h
+//
+// Handles the entire sequence when the user dies.
+//////////////////////////////////////////////////////////////////////////
+#ifndef __GAME_OVER_EFFECT_H__
+#define __GAME_OVER_EFFECT_H__
+
+#include "SexyAppFramework/Common.h"
+
+namespace Sexy
+{
+
+ class Graphics;
+
+ //////////////////////////////////////////////////////////////////////////
+ // Represents an exploding planet at a given XY, drawing the given
+ // frame number.
+ //////////////////////////////////////////////////////////////////////////
+ struct Explosion
+ {
+ int mX, mY;
+ int mFrame;
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // Used to spell out "GAME OVER". Each letter, beginning with G,
+ // slowly goes from black to full red. Once all letters are spelled,
+ // the process reverses, making it fade back to black.
+ //////////////////////////////////////////////////////////////////////////
+ struct Letter
+ {
+ int mRed;
+ SexyString mChar;
+
+ Letter(SexyString c) {mChar = c; mRed = 0;}
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // Stats that summarize the user's entire game.
+ //////////////////////////////////////////////////////////////////////////
+ struct EndGameStats
+ {
+ SexyString mFavoritePlanet; // We keep track of the planet
+ SexyString mFavoriteExport; // and export eaten most.
+ int mScore;
+ int mLevel;
+ int mNumPlanetsEaten;
+ int mPopulationConsumed;
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // The transition to the start of the new game is done by these 1 pixel
+ // wide weird lines that drip from the top of the screen. Each line, as it
+ // drips, draws a black line but the bottommost pixel of the line blinks
+ // using our over-used HSL color effect (see LevelUpEffect for more HSL details).
+ // Once it hits the bottom, it drips upward, this time drawing the whole line
+ // with the HSL color, until the entire screen is flashing and pulsing crazily.
+ // The lines are delayed by a random time interval to make it look more ... drippy.
+ //////////////////////////////////////////////////////////////////////////
+ struct DrippyLine
+ {
+ int mSpeed; // Pixles per update the lines moves, < 0 for upward.
+ int mX;
+ int mDelay; // How long to wait before dripping down
+ int mHeight; // How far it has dripped so far
+ bool mDripUp; // Dripping upward or downward?
+
+ DrippyLine(float s, int x, int d)
+ {mSpeed = s; mX = x; mDelay = d; mHeight = 0; mDripUp = false;}
+ };
+
+class GameOverEffect
+{
+
+ private:
+
+ // The states used for this effect
+ enum
+ {
+ RED_FADE_IN, // The pulsating, red fade in that obscures the whole screen
+ RED_HOLD, // We hold the fully opaque, red screen for a short interval for dramatic effect
+ SHOWING_LETTERS, // Displaying the GAME OVER letters in dramatic style
+ FADING_LETTERS, // Making them fade out
+ SHOWING_STATS, // Displaying the user's game performance statistics
+ DRIP_OUT // Doing the weird drippy effect that takes the user to a new game.
+ };
+
+ // The whole time this effect is going on, we make these planet explosion animations trigger
+ // randomly around the screen, again for dramatic but fun uselessness.
+ std::vector<Explosion> mExplosion;
+ std::vector<Letter> mText; // The letters "GAME OVER"
+ std::vector<DrippyLine> mLines; // Each of the drippy lines
+ EndGameStats mStats;
+ int mState;
+ int mAlpha; // Used for fading the screen in/out
+ int mRed; // The red value during the RED_ states pulses between 200 and 255.
+ int mRedChange; // How fast (and which direction) the red pulsing is going
+ int mUpdateCnt; // Since this isn't a widget, we'll manually track the number of times the update method is called
+ int mHue; // For hue/saturation/luminence crazy weird flashing effect
+ int mRedHoldCount; // Counter for the RED_HOLD state, when it drops to 0 we switch to SHOWING_LETTERS
+ bool mFadeOut; // Indicates if the lines are done dripping and we're doing the final fade out
+ bool mActive; // Indicates if the game over sequence is running or not
+ bool mCanInitFirstLevel; // When true, indicates that the board should set up the first level so that it'll be there when we fade out
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ //
+ // Purpose: Sets up and initializes/resets all variables.
+ //////////////////////////////////////////////////////////////////////////
+ void Init();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: PulseRed
+ //
+ // Purpose: Convenience function that handles the pulsing of the red
+ // value between 200 and 255.
+ //////////////////////////////////////////////////////////////////////////
+ void PulseRed();
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // GameOverEffect
+ //////////////////////////////////////////////////////////////////////////
+ GameOverEffect();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Draw
+ //////////////////////////////////////////////////////////////////////////
+ void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Update
+ //////////////////////////////////////////////////////////////////////////
+ void Update(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CanInitFirstLevel
+ // Returns: true or false, indicating if the first level can be setup for
+ // restarting.
+ //
+ // Purpose: Called by the Board's Update method, this returns true
+ // when the board should initialize the first level, so that when the
+ // game over effect fades out, the level will appear underneath it.
+ // When the function returns true, it automatically sets internal variables
+ // so that the next time the function is called, it will return false,
+ // preventing the Board from accidentally initializing the first level
+ // multiple times. After the next call to Activate, it is allowed to
+ // return true again.
+ //
+ // Once the screen is totally filled after closing the stats display,
+ // the Board is allowed to init the first level.
+ //////////////////////////////////////////////////////////////////////////
+ bool CanInitFirstLevel(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: CanStartNewGame
+ //
+ // Purpose: Returns true or false indicating if the user is allowed
+ // to click to start a new game. This can only happen when the user
+ // is viewing the stats and all other states have completed.
+ // This will trigger the effects that transition to the start of a
+ // new game.
+ //////////////////////////////////////////////////////////////////////////
+ bool CanStartNewGame() {return mState == SHOWING_STATS;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: HideBoard
+ // Returns: true or false indicating whether or not the board should
+ // hide all of its display stuff, except for the starfield which always
+ // displays.
+ //////////////////////////////////////////////////////////////////////////
+ bool HideBoard();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: IsActive
+ // Returns: true or false indicating if the sequence is running or not
+ //////////////////////////////////////////////////////////////////////////
+ bool IsActive() {return mActive;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Activate
+ // Parameters:
+ // ls - A stat structure containing the info for the past level
+ //
+ // Purpose: Begins the game over sequence
+ //////////////////////////////////////////////////////////////////////////
+ void Activate(EndGameStats es) {Init(); mActive = true; mStats = es;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DoneViewingStats
+ //
+ // Purpose: Called by Board when the user clicks the mouse button,
+ // indicating that they want the stats screen to go away and have the
+ // game restart.
+ //////////////////////////////////////////////////////////////////////////
+ void DoneViewingStats();
+};
+
+
+}
+
+#endif // __GAME_OVER_EFFECT_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/Hun-garr VS2005 WideString.vcproj b/osframework/source/demos/Hun-garr/Hun-garr VS2005 WideString.vcproj
new file mode 100644
index 0000000..a4403b1
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Hun-garr VS2005 WideString.vcproj
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Hun-garr"
+ ProjectGUID="{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Hun-garr.pdb"
+ GenerateMapFile="true"
+ MapFileName="Hun-garr.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameOverEffect.cpp"
+ >
+ </File>
+ <File
+ RelativePath="LevelupEffect.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="OptionsDialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="GameOverEffect.h"
+ >
+ </File>
+ <File
+ RelativePath="LevelupEffect.h"
+ >
+ </File>
+ <File
+ RelativePath="OptionsDialog.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Hun-garr/Hun-garr VS2005.vcproj b/osframework/source/demos/Hun-garr/Hun-garr VS2005.vcproj
new file mode 100644
index 0000000..133c302
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Hun-garr VS2005.vcproj
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="Hun-garr"
+ ProjectGUID="{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Hun-garr.pdb"
+ GenerateMapFile="true"
+ MapFileName="Hun-garr.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.cpp"
+ >
+ </File>
+ <File
+ RelativePath="GameOverEffect.cpp"
+ >
+ </File>
+ <File
+ RelativePath="LevelupEffect.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="OptionsDialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="GameApp.h"
+ >
+ </File>
+ <File
+ RelativePath="GameOverEffect.h"
+ >
+ </File>
+ <File
+ RelativePath="LevelupEffect.h"
+ >
+ </File>
+ <File
+ RelativePath="OptionsDialog.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="TitleScreen.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Hun-garr/Hun-garr WideString.vcproj b/osframework/source/demos/Hun-garr/Hun-garr WideString.vcproj
new file mode 100644
index 0000000..b35508f
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Hun-garr WideString.vcproj
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Hun-garr"
+ ProjectGUID="{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Hun-garr.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Hun-garr.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="GameOverEffect.cpp">
+ </File>
+ <File
+ RelativePath="LevelupEffect.cpp">
+ </File>
+ <File
+ RelativePath="OptionsDialog.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="GameOverEffect.h">
+ </File>
+ <File
+ RelativePath="LevelupEffect.h">
+ </File>
+ <File
+ RelativePath="OptionsDialog.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Hun-garr/Hun-garr.vcproj b/osframework/source/demos/Hun-garr/Hun-garr.vcproj
new file mode 100644
index 0000000..d3ce2d8
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Hun-garr.vcproj
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="Hun-garr"
+ ProjectGUID="{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/Hun-garr.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="Hun-garr.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../Hun-garr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="GameApp.cpp">
+ </File>
+ <File
+ RelativePath="GameOverEffect.cpp">
+ </File>
+ <File
+ RelativePath="LevelupEffect.cpp">
+ </File>
+ <File
+ RelativePath="OptionsDialog.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="TitleScreen.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="GameApp.h">
+ </File>
+ <File
+ RelativePath="GameOverEffect.h">
+ </File>
+ <File
+ RelativePath="LevelupEffect.h">
+ </File>
+ <File
+ RelativePath="OptionsDialog.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="TitleScreen.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/Hun-garr/Hungarr.dsp b/osframework/source/demos/Hun-garr/Hungarr.dsp
new file mode 100644
index 0000000..69b60c8
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/Hungarr.dsp
@@ -0,0 +1,166 @@
+# Microsoft Developer Studio Project File - Name="Hungarr" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Hungarr - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Hungarr.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Hungarr.mak" CFG="Hungarr - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Hungarr - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Hungarr - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Hungarr - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Hungarr___Win32_Release"
+# PROP BASE Intermediate_Dir "Hungarr___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\Hun-garr.exe"
+
+!ELSEIF "$(CFG)" == "Hungarr - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Hungarr___Win32_Debug"
+# PROP BASE Intermediate_Dir "Hungarr___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /Zi /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\Hun-garr_debug.exe" /pdbtype:sept
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "Hungarr - Win32 Release"
+# Name "Hungarr - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameOverEffect.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\LevelupEffect.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\OptionsDialog.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameApp.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GameOverEffect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\LevelupEffect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\OptionsDialog.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TitleScreen.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/Hun-garr/LevelupEffect.cpp b/osframework/source/demos/Hun-garr/LevelupEffect.cpp
new file mode 100644
index 0000000..7c728a0
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/LevelupEffect.cpp
@@ -0,0 +1,438 @@
+#pragma warning(disable:4244)
+#pragma warning(disable:4018)
+
+
+#include "LevelupEffect.h"
+#include "Board.h"
+#include "Res.h"
+#include "SexyAppFramework/SexyAppBase.h"
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Font.h"
+
+using namespace Sexy;
+
+const int STRIP_WIDTH = 20;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+LevelupEffect::LevelupEffect()
+{
+ Init();
+ mActive = false;
+ mCoverWidth = 0;
+ mStripSizeChange = 60;
+ mStripHeight = 0;
+ mFadeOutAlpha = 255;
+ mStartNextLevel = false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void LevelupEffect::Init()
+{
+ mText.clear();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Each letter, starting with the 'L' in "LEVEL UP!", will drop, delayed
+ // by a height of FONT_HUNGARR->GetHeight() pixels. Each letter will initially
+ // drop at a rate of 5 pixels per update (500 pixels per second). Once they
+ // reach their target Y coordinate (300), the speed will decrease and reverse
+ // to make the letters bounce upward. Gravity is applied each frame, so eventually
+ // the letters return back to Y of 300, where the speed is again decreased and
+ // reversed until it drops below the threshhold speed of 0.1 pixels per update.
+ //////////////////////////////////////////////////////////////////////////
+
+ float x = (GRID_END_X - GRID_START_X) / 2 - FONT_HUNGARR->StringWidth(_S("LEVEL UP!")) / 2;
+ float y = FONT_HUNGARR->GetHeight();
+ float startingY = y;
+ float ydec = y;
+ float speed = 5.0f;
+
+ mText.push_back(BouncyChar(_S("L"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("L"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("E"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("E"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("V"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("V"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("E"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("E"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("L"), x, y, speed));
+
+
+
+ x += FONT_HUNGARR->StringWidth(_S("L "));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("U"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("U"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("P"), x, y, speed));
+
+ x += FONT_HUNGARR->StringWidth(_S("P"));
+ y -= ydec;
+ mText.push_back(BouncyChar(_S("!"), x, y, speed));
+
+ mDone = false;
+ mHue = 0;
+ mCurtainX = 0;
+ mState = LevelupEffect::LEVELUP_TEXT;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void LevelupEffect::Activate(LevelupStats ls)
+{
+ Init();
+ mActive = true;
+ mStats = ls;
+
+ gSexyAppBase->PlaySample(SOUND_LEVEL_UP1);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void LevelupEffect::Update(float theFrac)
+{
+
+ // HSL is an alternative to specifying an RGB color format.
+ // Using HSL lets us easily do the hyper blinking crazy weird
+ // flashing effect commonly found in old games, such as Robotron.
+ // Below, we increment the value by 7 per update. The &0xFF is an
+ // easy way to clamp the value between 0 and 255 instead of having to
+ // do a separate if (mHue > 255) mHue -= 255. This lets the value
+ // rollover and keep cycling.
+ mHue = (mHue + 7) & 0xFF;
+
+ if (mState == LevelupEffect::LEVELUP_TEXT)
+ {
+ // Move all the letters, applying 0.15 pixels per update of
+ // "gravity" to pull the letters down. Once reaching Y of 300,
+ // the speed of the letters decreases by 0.75 and is reversed, making
+ // them "bounce" in the up direction. Once this bounce speed drops below 0.1
+ // pixels per update, the letter is done bouncing. When all letters are done bouncing,
+ // switch to the next state.
+ bool allDone = true;
+ for (int i = 0; i < mText.size(); i++)
+ {
+ BouncyChar* c = &mText[i];
+
+ if (c->mDone)
+ continue;
+
+ c->mY += c->mBounceSpeed;
+
+ c->mBounceSpeed += 0.15f;
+
+ if (c->mY >= 300)
+ {
+ c->mY = 300;
+
+ c->mOldBounceSpeed -= 0.750f;
+ if (c->mOldBounceSpeed <= 0.1f)
+ {
+ c->mDone = true;
+ c->mOldBounceSpeed = 0;
+ }
+ else
+ {
+ allDone = false;
+ c->mBounceSpeed = -c->mOldBounceSpeed;
+ }
+ }
+ else
+ allDone = false;
+ }
+
+ if (allDone)
+ mState = LevelupEffect::CURTAIN_IN;
+ }
+ else if (mState == LevelupEffect::CURTAIN_IN)
+ {
+ // Moves the black rectangles ("curtains") inward to cover up the
+ // previous level. We only move the left one. The right one is logically
+ // just the same width but starting from the right of the screen instead
+ // of the left. The curtain moves 25 pixels per update. Once it reaches
+ // the center (and thus fully covers the screen), we switch to the next state.
+ if ((mCurtainX += 25) >= gSexyAppBase->mWidth / 2)
+ {
+ mCurtainX = gSexyAppBase->mWidth / 2;
+ mState = LevelupEffect::CURTAIN_OUT;
+ gSexyAppBase->PlaySample(SOUND_LEVEL_UP2);
+ }
+ }
+ else if (mState == LevelupEffect::CURTAIN_OUT)
+ {
+ // Now the curtain is red and slowly moves back out to reveal the
+ // stats below it. This works just like above.
+ if ((mCurtainX -= 2) <= 0)
+ mState = LevelupEffect::SHOWING_STATS;
+ }
+ else if (mState == LevelupEffect::COVERING_STATS)
+ {
+ // This state begins when the user clicks the mouse to dismiss the
+ // stats screen. We then make these strips quickly appear. Imagine
+ // rectangles of width 20 coming in from the left and right of the screen.
+ // The left one starts comign from the top left of the screen, the right
+ // from the bottom right. These strips quickly expand to be screen height in size
+ // and then move closer inward (by their width of 20) and reverse the direction
+ // that they come in at. Once the strips have traveled to the center of the screen,
+ // it's fully covered and we then move to the next state. After a strip becomes
+ // the height of the screen, we update mCoverWidth, which is just simply the width
+ // of the region fully filled in. Again, like with the curtain effects, we only
+ // keep track of the left side, since the right moves the same amount and it's
+ // easy to compute the right's offsets.
+ if (mStripSizeChange > 0)
+ {
+ // Left strip is moving downward from Y of 0, right is moving up
+ // from Y of app height
+ if ((mStripHeight += mStripSizeChange) >= gSexyAppBase->mHeight)
+ {
+ // Left strip and right strip are now the height of the screen.
+ // Reverse the direction they come in at and reset their heights.
+ // Then, increment the width of the fully covered region by the
+ // size of one of the strip's width.
+ mStripSizeChange = -mStripSizeChange;
+ mStripHeight = 0;
+ if ((mCoverWidth += STRIP_WIDTH) >= gSexyAppBase->mWidth / 2)
+ {
+ // The screen is fully covered. Fade out.
+ mStartNextLevel = true;
+ mState = LevelupEffect::FADE_OUT_STATS;
+ }
+ }
+ }
+ else
+ {
+ if ((mStripHeight -= mStripSizeChange) >= gSexyAppBase->mHeight)
+ {
+ mStripSizeChange = -mStripSizeChange;
+ mStripHeight = 0;
+ if ((mCoverWidth += STRIP_WIDTH) >= gSexyAppBase->mWidth / 2)
+ {
+ mStartNextLevel = true;
+ mState = LevelupEffect::FADE_OUT_STATS;
+ }
+ }
+ }
+ }
+ else if (mState == LevelupEffect::FADE_OUT_STATS)
+ {
+ //Fade the screen out, with the next level appearing below it.
+ if ((mFadeOutAlpha -= 2) <= 0)
+ {
+ mDone = true;
+ mActive = false;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void LevelupEffect::Draw(Graphics* g)
+{
+ g->SetFont(FONT_HUNGARR);
+ if (mState == LevelupEffect::LEVELUP_TEXT)
+ {
+ // This is how we convert an HSL value to an RGB value, which we have to
+ // do to specify the color for the graphics object. The function HSLToRGB
+ // takes as parameters: hue, saturation, luminance. We want to leave the
+ // saturation at max and luminance at half for our particular example.
+ // The returned value is ANDed with 0xFFFFFFFF to clamp the values for
+ // the alpha, red, green, and blue to the valid region of 0 to 255.
+ g->SetColor( (gSexyAppBase->HSLToRGB(mHue, 255, 128) & 0xFFFFFFFF) );
+ for (int i = 0; i < mText.size(); i++)
+ {
+ BouncyChar* c = &mText[i];
+ g->DrawString(c->mChar, c->mX, c->mY);
+ }
+ }
+ else if (mState == LevelupEffect::CURTAIN_IN)
+ {
+ // The righ tcurtain is just the same width as the left, but starts from the right
+ // side instead of X of 0.
+ g->SetColor(Color(0, 0, 0));
+ g->FillRect(0, 0, mCurtainX, gSexyAppBase->mHeight);
+ g->FillRect(gSexyAppBase->mWidth - mCurtainX, 0, mCurtainX, gSexyAppBase->mHeight);
+ }
+ else if ((mState == LevelupEffect::SHOWING_STATS) || (mState == LevelupEffect::CURTAIN_OUT) ||
+ (mState == LevelupEffect::COVERING_STATS))
+ {
+ // When just showing the stats normally, fading out the red curtain (to reveal the stats
+ // beneath it), or covering up the stats with the effect triggered when the user clicks
+ // to begin the next level, we display info on the user's performance from the last level.
+ int y = 50;
+ g->SetColor(gSexyAppBase->HSLToRGB(mHue, 255, 128) & 0xFFFFFFFF);
+ SexyString s = StrFormat(_S("LEVEL %d COMPLETE!"), mStats.mLevelCompleted);
+ g->DrawString(s, gSexyAppBase->mWidth / 2 - FONT_HUNGARR->StringWidth(s) / 2, y);
+
+ g->SetColor(Color::White);
+ s = _S("POPULATION CONSUMED:");
+ int strWidth = FONT_HUNGARR->StringWidth(s);
+
+ int rightX = strWidth + 100;
+ y += 50;
+ g->DrawString(s, 100, y);
+ g->SetColor(Color(255, 0, 0));
+ g->DrawString(CommaSeperate(mStats.mPopulationEaten), rightX + 5, y);
+
+ y += FONT_HUNGARR->GetHeight();
+ g->SetColor(Color::White);
+ s = _S("SYSTEMS SUBJUGATED:");
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 0, 0));
+ g->DrawString(StrFormat(_S("%d%%"), mStats.mPercentComplete), rightX + 5, y);
+
+ y += FONT_HUNGARR->GetHeight();
+ if (mStats.mPercentComplete >= COMPLETION_BONUS_PCT)
+ {
+ s = StrFormat(_S("%d%%+ BONUS:"), COMPLETION_BONUS_PCT);
+ g->SetColor(Color::White);
+ strWidth = FONT_HUNGARR->StringWidth(s);
+ g->DrawString(s, rightX - strWidth, y);
+ g->SetColor(Color(255, 0, 0));
+ g->DrawString(StrFormat(_S("%d"), COMPLETION_BONUS * mStats.mLevelCompleted),
+ rightX + 5, y);
+ }
+
+ if (mStats.mPlanetsEaten.size() > 0)
+ {
+ y += 50;
+ int third = gSexyAppBase->mWidth / 3;
+ g->SetColor(Color(255, 255, 0));
+
+ s = _S("PLANET EATEN:");
+ g->DrawString(s, third / 2 - FONT_HUNGARR->StringWidth(s) / 2, y);
+ s = _S("EXPORTS:");
+ g->DrawString(s, third + (third / 2 - FONT_HUNGARR->StringWidth(s) / 2), y);
+ s = _S("POPULATION:");
+ g->DrawString(s, third*2 + (third / 2 - FONT_HUNGARR->StringWidth(s) / 2), y);
+
+ y += FONT_HUNGARR->GetHeight();
+
+ // If the user ate too many planets to fit on screen, we'll just display "..."
+ // to indicate that they ate a bunch but we just can't fit it all on screen.
+ // In reality, it'd be best to either ensure that all the planets fit on screen,
+ // or that there's some sort of scrolling mechanism to allow the user to view all their
+ // stats.
+ bool drawDotDotDot = false;
+ for (int i = 0; i < mStats.mPlanetsEaten.size(); i += 3)
+ {
+ if (y >= gSexyAppBase->mHeight - FONT_HUNGARR->GetHeight() * 2)
+ {
+ drawDotDotDot = true;
+ break;
+ }
+
+ g->SetColor(Color(255, 255, 255));
+ s = mStats.mPlanetsEaten[i];
+ g->DrawString(s, third / 2 - FONT_HUNGARR->StringWidth(s) / 2, y);
+
+ g->SetColor(Color(128, 255, 0));
+ s = mStats.mPlanetsEaten[i+1];
+ g->DrawString(s, third + (third / 2 - FONT_HUNGARR->StringWidth(s) / 2), y);
+
+ g->SetColor(Color(255, 128, 0));
+ s = mStats.mPlanetsEaten[i+2];
+ g->DrawString(s, third*2 + (third / 2 - FONT_HUNGARR->StringWidth(s) / 2), y);
+
+ y += FONT_HUNGARR->GetHeight();
+
+ }
+
+ if (drawDotDotDot)
+ {
+ g->SetColor(Color::White);
+ g->DrawString(_S("..."), 5, y);
+ }
+ }
+
+ g->SetColor(Color::White);
+ s = _S("CLICK TO CONTINUE");
+ g->DrawString(s, gSexyAppBase->mWidth / 2 - FONT_HUNGARR->StringWidth(s) / 2, gSexyAppBase->mHeight - 20);
+ }
+
+ if (mState == LevelupEffect::CURTAIN_OUT)
+ {
+ // Draw a red curtain, whose alpha decreases as it withdrawls more.
+ // This lets the stats display underneath the curtain while it moves.
+ int alpha = mCurtainX > 255 ? 255 : mCurtainX;
+ g->SetColor(Color(255, 0, 0, alpha));
+ g->FillRect(0, 0, mCurtainX, gSexyAppBase->mHeight);
+ g->FillRect(gSexyAppBase->mWidth - mCurtainX, 0, mCurtainX, gSexyAppBase->mHeight);
+ }
+
+ if ((mState == LevelupEffect::COVERING_STATS) || (mState == LevelupEffect::FADE_OUT_STATS))
+ {
+ // Both the states where we cover up the stats and fade them out are controlled here,
+ // since they are functionally the same. Again, with the HSL we do the usual HSLToRGB
+ // stuff. However, since the FADE_OUT_STATS state actually fades out the screen and
+ // has an alpha value that decreases over time (mFadeOutAlpha), instead of always
+ // setting the alpha to 255, we need to set the alpha to mFadeOutAlpha. To do this,
+ // we AND with 0xFFFFFF instead of 0xFFFFFFFF. Then, we OR it with the alpha value
+ // shifted left 24 bits. This then sticks the alpha value, which changes over time,
+ // into our HSL color. As you may recall from previous demos, the actual color
+ // structure is 32 bit, and looks like this in binary form:
+ // AAAA RRRR GGGG BBBB Where A,R,G,B are alpha, red, green, blue.
+ //
+ // We draw the totally filled in regions separately, since they're easy.
+ // The strips then are drawn differently depending on if they are moving up or down.
+ // The left and right ones move oppositely.
+ g->SetColor( (gSexyAppBase->HSLToRGB(mHue, 255, 128) & 0xFFFFFF) | (mFadeOutAlpha << 24) );
+ g->FillRect(0, 0, mCoverWidth, gSexyAppBase->mHeight);
+ g->FillRect(gSexyAppBase->mWidth - mCoverWidth, 0, mCoverWidth, gSexyAppBase->mHeight);
+
+ if (mStripSizeChange > 0)
+ {
+ g->FillRect(mCoverWidth, 0, STRIP_WIDTH, mStripHeight);
+ g->FillRect(gSexyAppBase->mWidth - mCoverWidth - STRIP_WIDTH,
+ gSexyAppBase->mHeight - mStripHeight,
+ STRIP_WIDTH,
+ mStripHeight);
+ }
+ else
+ {
+ g->FillRect(mCoverWidth, gSexyAppBase->mHeight - mStripHeight, STRIP_WIDTH, mStripHeight);
+ g->FillRect(gSexyAppBase->mWidth - mCoverWidth - STRIP_WIDTH, 0, STRIP_WIDTH, mStripHeight);
+ }
+
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void LevelupEffect::DoneViewingStats()
+{
+ // The user clicked to dismiss the stats screen. Cover it up
+ // and begin the transition to the next level.
+ mState = LevelupEffect::COVERING_STATS;
+ mCoverWidth = 0;
+ mStripSizeChange = 90;
+ mStripHeight = 0;
+ mFadeOutAlpha = 255;
+ mStartNextLevel = false;
+ gSexyAppBase->PlaySample(SOUND_LEVEL_UP3);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool LevelupEffect::StartNextLevel()
+{
+ // See function header for a complete description
+ if (mStartNextLevel)
+ {
+ mStartNextLevel = false;
+ gSexyAppBase->PlaySample(SOUND_LEVEL_UP4);
+ return true;
+ }
+
+ return false;
+} \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/LevelupEffect.h b/osframework/source/demos/Hun-garr/LevelupEffect.h
new file mode 100644
index 0000000..390dc0b
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/LevelupEffect.h
@@ -0,0 +1,191 @@
+//////////////////////////////////////////////////////////////////////////
+// LevelupEffect.h
+//
+// Does the level up effect, from the bouncing "LEVEL UP!" text to
+// the stats display and weird transition effects.
+//////////////////////////////////////////////////////////////////////////
+
+
+#ifndef __LEVELUP_EFFECT_H__
+#define __LEVELUP_EFFECT_H__
+
+#include "SexyAppFramework/Common.h"
+#include "SexyAppFramework/Rect.h"
+
+namespace Sexy
+{
+
+ class Graphics;
+
+
+//////////////////////////////////////////////////////////////////////////
+// Represents a letter that bounces, used for the "LEVEL UP!" text.
+//////////////////////////////////////////////////////////////////////////
+struct BouncyChar
+{
+ SexyString mChar; // The character bouncing
+ bool mDone; // Completed bouncing yet?
+ float mX, mY;
+ float mBounceSpeed; // How fast up or down it's bouncing, affected by "gravity"
+ float mOldBounceSpeed; // The base value that mBounceSpeed started at. Gets reduced over time.
+
+ BouncyChar(SexyString t, float x, float y, float s)
+ {mChar = t; mX = x; mY = y; mBounceSpeed = mOldBounceSpeed = s; mDone = false;}
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Contains stat info to display after completing a level.
+//////////////////////////////////////////////////////////////////////////
+struct LevelupStats
+{
+ int mPopulationEaten;
+ int mPercentComplete;
+ int mLevelCompleted;
+
+ // Always 3 strings per planet:
+ // Planet name, exports, population (comma delimited)
+ std::vector<SexyString> mPlanetsEaten;
+
+};
+
+class LevelupEffect
+{
+
+ private:
+
+ // States that the level up effect goes through
+ enum
+ {
+ LEVELUP_TEXT, // Displaying the bouncy LEVEL UP! text
+ CURTAIN_IN, // Moving the black "curtain" inward to cover up the level
+ CURTAIN_OUT, // Moving the red "curtain" out after above to reveal the stats
+ SHOWING_STATS, // Displaying level stats
+ COVERING_STATS, // Doing the weird transitionary cover-up screen after clicking to continue
+ FADE_OUT_STATS // Fading out the above screen
+ };
+
+ std::vector<BouncyChar> mText; // The letters that spell LEVEL UP!, as BouncyChar structures
+ LevelupStats mStats; // Stat info to display
+ bool mActive; // If true, means we're doing the level up sequence
+ bool mDone; // If done, means all finished and the next level can actually begin
+ bool mStartNextLevel; // When true, indicates that the board should set up the next level so that it'll be there when we fade out
+
+ int mHue; // For hue/saturation/luminence crazy weird flashing effect
+ int mCurtainX; // X location of the black/red curtain edge (for the left curtain, the right is the same size)
+ int mState; // One of the above nums
+
+ // When doing the COVERING_STATS phase, this is how wide 1/2 of the filled in part of the screen is. The other half
+ // is the same size.
+ int mCoverWidth;
+ int mStripHeight; // For the above, we make strips quickly appear, alternating up/down filling
+
+ // Indicates whether the strips are increasing Y (so strip comes from top) or decreasing
+ // (so strip comes from bottom)
+ int mStripSizeChange;
+ int mFadeOutAlpha; // Alpha amount for the final fade out effect
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ //
+ // Purpose: Sets up and initializes/resets all variables.
+ //////////////////////////////////////////////////////////////////////////
+ void Init();
+
+ public:
+
+ LevelupEffect();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Update
+ // Parameters:
+ // theFrac - Value from Board::UpdateF, used for smooth motion
+ //
+ //////////////////////////////////////////////////////////////////////////
+ void Update(float theFrac);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Draw
+ //////////////////////////////////////////////////////////////////////////
+ void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Activate
+ // Parameters:
+ // ls - A stat structure containing the info for the past level
+ //
+ // Purpose: Begins the level up sequence
+ //////////////////////////////////////////////////////////////////////////
+ void Activate(LevelupStats ls);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DoneViewingStats
+ //
+ // Purpose: Called by Board when the user clicks the mouse button,
+ // indicating that they want the stats screen to go away and have the
+ // next level begin.
+ //////////////////////////////////////////////////////////////////////////
+ void DoneViewingStats();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: StartNextLevel
+ // Returns: true or false, indicating if the next level can be started.
+ //
+ // Purpose: Called by the Board's Update method, this returns true
+ // when the board should initialize the next level, so that when the
+ // level up effect fades out, the next level will appear underneath it.
+ // When the function returns true, it automatically sets internal variables
+ // so that the next time the function is called, it will return false,
+ // preventing the Board from accidentally initializing the same level
+ // multiple times. After the next call to Activate, it is allowed to
+ // return true again.
+ //
+ // Once the screen is totally filled after closing the stats display,
+ // the Board is allowed to init the next level.
+ //////////////////////////////////////////////////////////////////////////
+ bool StartNextLevel();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: IsDone
+ // Returns: true or false indicating if the entire sequence is done
+ //
+ // Purpose: Used to let the board know when playing of the next level
+ // can begin.
+ //////////////////////////////////////////////////////////////////////////
+ bool IsDone() {return mDone;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: IsActive
+ // Returns: true or false indicating if the sequence is running or not
+ //////////////////////////////////////////////////////////////////////////
+ bool IsActive() {return mActive;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ShowingStats
+ // Returns: true or false indicating if the stats display is visible
+ //////////////////////////////////////////////////////////////////////////
+ bool ShowingStats() {return mState == SHOWING_STATS;}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: HideBoard
+ // Returns: true or false indicating whether or not the board should
+ // hide all of its display stuff, except for the starfield which always
+ // displays.
+ //////////////////////////////////////////////////////////////////////////
+ bool HideBoard() {return (mState == SHOWING_STATS) || (mState == CURTAIN_OUT) || (mState == COVERING_STATS);}
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: HidePlanets
+ // Returns: true or false indicating if just the planets should be
+ // hidden.
+ //
+ // Purpose: Used to hide the planets but still allow the rest of the
+ // game board to display. Used during the transtion to the stats
+ // display screen.
+ //////////////////////////////////////////////////////////////////////////
+ bool HidePlanets() {return IsActive() && (HideBoard() || (mState == LEVELUP_TEXT) || (mState == CURTAIN_IN));}
+};
+
+
+}
+
+#endif //__LEVELUP_EFFECT_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/OptionsDialog.cpp b/osframework/source/demos/Hun-garr/OptionsDialog.cpp
new file mode 100644
index 0000000..e5de450
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/OptionsDialog.cpp
@@ -0,0 +1,273 @@
+#include "OptionsDialog.h"
+#include "Res.h"
+#include "Board.h"
+#include "SexyAppFramework/SexyAppBase.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/DialogButton.h"
+#include "SexyAppFramework/Checkbox.h"
+#include "SexyAppFramework/Slider.h"
+
+using namespace Sexy;
+
+
+OptionsDialog::OptionsDialog(Board* b) :
+Dialog(IMAGE_DIALOG_BOX, IMAGE_DIALOG_BUTTON, OptionsDialog::DIALOG_ID, true, _S("OPTIONS"), _S(""), _S("CLOSE"), Dialog::BUTTONS_FOOTER)
+{
+ mContentInsets = Insets(23, 20, 23, 20);
+ mSpaceAfterHeader = 30;
+
+ mBoard = b;
+
+ SetHeaderFont(FONT_DEFAULT);
+ SetLinesFont(FONT_DEFAULT);
+ SetButtonFont(FONT_DEFAULT);
+
+ SetColor(COLOR_HEADER, Color::Black);
+ SetColor(COLOR_LINES, Color::Black);
+
+ mMusicVolumeSlider = new Slider(IMAGE_SLIDER_TRACK, IMAGE_SLIDER_THUMB, OptionsDialog::MUSIC_SLIDER_ID, this);
+ mMusicVolumeSlider->SetValue(gSexyAppBase->GetMusicVolume());
+
+ mSfxVolumeSlider = new Slider(IMAGE_SLIDER_TRACK, IMAGE_SLIDER_THUMB, OptionsDialog::SFX_SLIDER_ID, this);
+ mSfxVolumeSlider->SetValue(gSexyAppBase->GetSfxVolume());
+
+ mQuitBtn = new DialogButton(IMAGE_DIALOG_BUTTON, OptionsDialog::QUIT_BTN_ID, this);
+ mQuitBtn->mLabel = _S("QUIT GAME");
+ mQuitBtn->SetFont(FONT_DEFAULT);
+
+ m3DCheckbox = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, OptionsDialog::HARDWARE_CHECKBOX_ID, this);
+ mFSCheckbox = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, OptionsDialog::FS_CHECKBOX_ID, this);
+ mCustomCursorsCheckbox = new Checkbox(IMAGE_CHECKBOX, IMAGE_CHECKBOX, OptionsDialog::FS_CHECKBOX_ID, this);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+OptionsDialog::~OptionsDialog()
+{
+ delete mMusicVolumeSlider;
+ delete mSfxVolumeSlider;
+ delete mQuitBtn;
+ delete mCustomCursorsCheckbox;
+ delete m3DCheckbox;
+ delete mFSCheckbox;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::Draw(Graphics* g)
+{
+ Dialog::Draw(g);
+
+ // Let's draw some labels for the sliders
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::Black);
+
+ // We draw the X/Y at the slider's X/Y but we subtract off the dialog box's
+ // X/Y's from that. Why? The slider's XY's are in absolute screen coordinates,
+ // as are the dialog boxes. But as you may recall from Board::Draw(), where
+ // we explain graphics translation, once we get inside the draw loop of a
+ // widget, the graphics object is already moved (translated) to the widget's
+ // coordinates. Thus, in using the Graphics object, g, (0, 0) is located
+ // at the top left corner of the widget (our dialog box). So we
+ // just take the difference between the widget locations to produce the
+ // actual location we want to drawour text at:
+ g->DrawString(_S("Music volume:"), mMusicVolumeSlider->mX - mX,
+ mMusicVolumeSlider->mY - mY - mMusicVolumeSlider->mHeight);
+
+ g->DrawString(_S("Sound volume:"), mSfxVolumeSlider->mX - mX,
+ mSfxVolumeSlider->mY - mY - mSfxVolumeSlider->mHeight);
+
+ // Do the same for the checkboxes:
+ g->DrawString(_S("3D Mode:"), m3DCheckbox->mX - mX - 25, m3DCheckbox->mY - mY - m3DCheckbox->mHeight + 20);
+ g->DrawString(_S("Full Screen:"), mFSCheckbox->mX - mX - 25, mFSCheckbox->mY - mY - mFSCheckbox->mHeight + 20);
+ g->DrawString(_S("Custom Cursors:"), mCustomCursorsCheckbox->mX - mX - 25,
+ mCustomCursorsCheckbox->mY - mY - mCustomCursorsCheckbox->mHeight + 20);
+
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::AddedToManager(WidgetManager* theWidgetManager)
+{
+ Dialog::AddedToManager(theWidgetManager);
+ theWidgetManager->AddWidget(mMusicVolumeSlider);
+ theWidgetManager->AddWidget(mSfxVolumeSlider);
+ theWidgetManager->AddWidget(mQuitBtn);
+
+ int checkWidth = IMAGE_CHECKBOX->GetWidth() / 2;
+ m3DCheckbox->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ m3DCheckbox->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ mFSCheckbox->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ mFSCheckbox->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ mCustomCursorsCheckbox->mUncheckedRect = Rect(0, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+ mCustomCursorsCheckbox->mCheckedRect = Rect(checkWidth, 0, checkWidth, IMAGE_CHECKBOX->GetHeight());
+
+ m3DCheckbox->mChecked = gSexyAppBase->Is3DAccelerated();
+ mFSCheckbox->mChecked = !gSexyAppBase->mIsWindowed;
+ mCustomCursorsCheckbox->mChecked = gSexyAppBase->mCustomCursorsEnabled;
+
+ theWidgetManager->AddWidget(m3DCheckbox);
+ theWidgetManager->AddWidget(mFSCheckbox);
+ theWidgetManager->AddWidget(mCustomCursorsCheckbox);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::RemovedFromManager(WidgetManager* theWidgetManager)
+{
+ Dialog::RemovedFromManager(theWidgetManager);
+ theWidgetManager->RemoveWidget(mMusicVolumeSlider);
+ theWidgetManager->RemoveWidget(mSfxVolumeSlider);
+ theWidgetManager->RemoveWidget(mQuitBtn);
+ theWidgetManager->RemoveWidget(mCustomCursorsCheckbox);
+ theWidgetManager->RemoveWidget(m3DCheckbox);
+ theWidgetManager->RemoveWidget(mFSCheckbox);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::Resize(int theX, int theY, int theWidth, int theHeight)
+{
+ Dialog::Resize(theX, theY, theWidth, theHeight);
+
+ mMusicVolumeSlider->Resize(theX + mContentInsets.mLeft + 50,
+ theY + 100, 245, IMAGE_SLIDER_THUMB->GetHeight());
+
+ mSfxVolumeSlider->Layout(LAY_SameLeft | LAY_Below | LAY_SameWidth | LAY_SameHeight,
+ mMusicVolumeSlider, 0, 40, 0, 0);
+
+ mQuitBtn->Layout(LAY_SameLeft | LAY_SameSize | LAY_Above, mYesButton);
+
+ m3DCheckbox->Layout(LAY_SameLeft | LAY_Below, mSfxVolumeSlider, 0, 40, 0, 0);
+ m3DCheckbox->Resize(m3DCheckbox->mX, m3DCheckbox->mY,
+ IMAGE_CHECKBOX->mWidth / 2, IMAGE_CHECKBOX->mHeight);
+
+ mFSCheckbox->Layout(LAY_SameTop | LAY_SameWidth | LAY_SameHeight | LAY_Right, m3DCheckbox, 80);
+
+ mCustomCursorsCheckbox->Layout(LAY_SameTop | LAY_SameWidth | LAY_SameHeight | LAY_Right, mFSCheckbox, 80);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::SliderVal(int theId, double theVal)
+{
+ if (theId == OptionsDialog::MUSIC_SLIDER_ID)
+ {
+ // Let's set the music volume to whatever the slider position is
+ gSexyAppBase->SetMusicVolume(theVal);
+ }
+ else if (theId == OptionsDialog::SFX_SLIDER_ID)
+ {
+ // Set the sound value
+ gSexyAppBase->SetSfxVolume(theVal);
+
+ if (!mSfxVolumeSlider->mDragging)
+ gSexyAppBase->PlaySample(SOUND_TIMER);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::ButtonDepress(int theId)
+{
+ Dialog::ButtonDepress(theId);
+
+ // Previously, before framework 1.2, the line below looked like:
+ // else if (theId == 2000 + mId)
+ // With the 1.2 changes, there's just 1 slight incompatibility.
+ // If the DialogListener for a dialog your app (by default), and
+ // you don't implement your own DialogButton(De)press method (see V12Demo for
+ // more info on this), and instead are trapping button presses within ButtonDepress
+ // inside the dialog itself, then instead of the button ID being 2000 or 3000 + mId,
+ // it's just 0 for no/cancel/1-button dialog, and 1 for yes/ok. Hence we changed our
+ // check to look for 0, which is our default single close button at the bottom of this
+ // dialog.
+ if (theId == ID_YES)
+ {
+ // Close button pressed. Tell the app to remove ourselves. This
+ // will automatically safe delete the dialog at a later time.
+ // Let's apply the 3D and fullscreen mode settings first though.
+ // We call SwitchScreenMode. The first parameter is whether or not to run
+ // windowed (false means fullscreen), the second is whether or not to do 3d.
+ gSexyAppBase->SwitchScreenMode(!mFSCheckbox->mChecked, m3DCheckbox->mChecked);
+
+ gSexyAppBase->EnableCustomCursors(mCustomCursorsCheckbox->mChecked);
+
+ gSexyAppBase->KillDialog(this);
+
+ mBoard->OptionsDialogDone();
+ }
+ else if (theId == mQuitBtn->mId)
+ {
+ // Quit button pressed. Shut down the app.
+ gSexyAppBase->Shutdown();
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void OptionsDialog::CheckboxChecked(int theId, bool checked)
+{
+ // We'll wait until the dialog box is closed before actually applying any effects,
+ // since it's rather jarring if as soon as a user clicks the 3d or fullscreen
+ // toggle buttons to change right then and there.
+
+ if (theId == m3DCheckbox->mId)
+ {
+ if (checked)
+ {
+ // Turn on 3D acceleration. But we need to check if the user is
+ // even allowed to have it on. Some cards are just not compatible
+ // with the framework (less than 8MB RAM for instance):
+ if (!gSexyAppBase->Is3DAccelerationSupported())
+ {
+ // It's not supported. Don't let the checkbox get checked.
+ // Display an error dialog to the user to let them know why this happened.
+ // The reason we don't use a Popup or Windows-based message box here is because
+ // if the user was in full screen mode, they might not see the error message. Using
+ // a game dialog box is the safest way to warn them.
+ m3DCheckbox->SetChecked(false);
+ gSexyAppBase->DoDialog(OptionsDialog::MESSAGE_BOX_ID, true, _S("Not Supported"),
+ _S("Hardware acceleration can not be enabled on this computer. \nYour \
+ video card does not meet the minimum requirements for this game."),
+ _S("OK"), Dialog::BUTTONS_FOOTER);
+ }
+ else if(!gSexyAppBase->Is3DAccelerationRecommended())
+ {
+ // We can also check if 3D acceleration is not recommended for this computer
+ // with a call to Is3DAccelerationRecommended. This allows the user to override
+ // the default setting, but with a warning that it might not work or might cause
+ // problems. Some cards fail the detection process but wind up being OK to use.
+ gSexyAppBase->DoDialog(OptionsDialog::MESSAGE_BOX_ID, true, _S("Warning"),
+ _S("Your video card may not fully support this feature.\n\
+ If you experience slower performance, please disable Hardware Acceleration."),
+ _S("OK"), Dialog::BUTTONS_FOOTER);
+ }
+
+ }
+ }
+ else if (theId == mFSCheckbox->mId)
+ {
+ // Believe it or not, some people are not allowed to play in windowed mode.
+ // You can only run in windowed mode if your desktop is 16 or 32 bit, and
+ // if the resolution of their desktop is GREATER THAN the resolution of the
+ // game. It doesn't make sense to run a 800x600 game windowed when your desktop
+ // is 800x600 or less.
+ // We can determine if the user is not allowed to run in windowed mode by
+ // checking the value of SexyAppBase's mForceFullScreen variable.
+ if (gSexyAppBase->mForceFullscreen && !checked)
+ {
+ gSexyAppBase->DoDialog(OptionsDialog::MESSAGE_BOX_ID, true, _S("No Windowed Mode"),
+ _S("Windowed mode is only available if your desktop is running in\n\
+ either 16 bit or 32 bit color mode, which it is not."), _S("OK"), Dialog::BUTTONS_FOOTER);
+
+ // re-check the box to indicate that fullscreen is still the selected mode:
+ mFSCheckbox->SetChecked(true);
+ }
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/OptionsDialog.h b/osframework/source/demos/Hun-garr/OptionsDialog.h
new file mode 100644
index 0000000..dd998cd
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/OptionsDialog.h
@@ -0,0 +1,110 @@
+//////////////////////////////////////////////////////////////////////////
+// OptionsDialog.h
+//
+// Represents a standard options dialog box where the user can toggle
+// 3D mode, full screen, custom cursors, adjust sound volumes, and
+// quit the game.
+//////////////////////////////////////////////////////////////////////////
+
+
+#ifndef __OPTIONS_DIALOG_H__
+#define __OPTIONS_DIALOG_H__
+
+#include "SexyAppFramework/Dialog.h"
+#include "SexyAppFramework/SliderListener.h"
+#include "SexyAppFramework/CheckboxListener.h"
+
+namespace Sexy
+{
+
+ class Graphics;
+ class Slider;
+ class DialogButton;
+ class Checkbox;
+ class Board;
+
+ class OptionsDialog : public Dialog, public SliderListener, public CheckboxListener
+ {
+
+ protected:
+
+ Slider* mMusicVolumeSlider;
+ Slider* mSfxVolumeSlider;
+ DialogButton* mQuitBtn;
+ Board* mBoard;
+
+
+ public:
+
+ enum
+ {
+ MUSIC_SLIDER_ID,
+ SFX_SLIDER_ID,
+ QUIT_BTN_ID,
+ FS_CHECKBOX_ID,
+ HARDWARE_CHECKBOX_ID,
+ CUSTOM_CURSORS_CHECKBOX_ID,
+ MESSAGE_BOX_ID,
+ DIALOG_ID
+ };
+
+
+ Checkbox* m3DCheckbox;
+ Checkbox* mFSCheckbox;
+ Checkbox* mCustomCursorsCheckbox;
+
+
+ public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: OptionsDialog
+ // Parameters:
+ // b - A pointer to the board, used to unpause when dialog closes
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ OptionsDialog(Board* b);
+ virtual ~OptionsDialog();
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // Draw
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // ButtonDepress
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // AddedToManager
+ //////////////////////////////////////////////////////////////////////////
+ virtual void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // RemovedFromManager
+ //////////////////////////////////////////////////////////////////////////
+ virtual void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Resize
+ //////////////////////////////////////////////////////////////////////////
+ virtual void Resize(int theX, int theY, int theWidth, int theHeight);
+
+ //////////////////////////////////////////////////////////////////////////
+ // SliderVal
+ //////////////////////////////////////////////////////////////////////////
+ virtual void SliderVal(int theId, double theVal);
+
+ //////////////////////////////////////////////////////////////////////////
+ // CheckboxChecked
+ //////////////////////////////////////////////////////////////////////////
+ void CheckboxChecked(int theId, bool checked);
+ };
+
+
+}
+
+
+#endif \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/TitleScreen.cpp b/osframework/source/demos/Hun-garr/TitleScreen.cpp
new file mode 100644
index 0000000..510db94
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/TitleScreen.cpp
@@ -0,0 +1,150 @@
+#include "TitleScreen.h"
+#include "GameApp.h"
+#include "Res.h"
+#include "SexyAppFramework/Font.h"
+#include "SexyAppFramework/Graphics.h"
+#include "SexyAppFramework/Image.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/Rect.h"
+#include "SexyAppFramework/HyperlinkWidget.h"
+
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::TitleScreen(GameApp *pApp)
+{
+ mApp = pApp;
+ mContinueLink = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+TitleScreen::~TitleScreen()
+{
+ delete mContinueLink;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Init(void)
+{
+ mContinueLink = new HyperlinkWidget(1, this);
+ mContinueLink->SetFont(FONT_DEFAULT);
+ mContinueLink->mLabel = _S("CLICK TO CONTINUE");
+ mContinueLink->mColor = Color(255, 255, 255);
+ mContinueLink->mOverColor = Color(0, 255, 0);
+ mContinueLink->mUnderlineSize = 1;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::AddedToManager(WidgetManager *theWidgetManager)
+{
+ Widget::AddedToManager(theWidgetManager);
+ mContinueLink->SetVisible(false);
+ mContinueLink->SetDisabled(true);
+
+ int labelWidth = FONT_DEFAULT->StringWidth(mContinueLink->mLabel);
+ int labelHeight = FONT_DEFAULT->GetHeight();
+ mContinueLink->Resize( mWidth / 2 - labelWidth / 2,
+ mHeight - labelHeight - 40,
+ labelWidth,
+ labelHeight+4);
+
+ mContinueLink->mDoFinger = true;
+ theWidgetManager->AddWidget(mContinueLink);
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::RemovedFromManager(WidgetManager *theWidgetManager)
+{
+ Widget::RemovedFromManager(theWidgetManager);
+ theWidgetManager->RemoveWidget(mContinueLink);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::Draw(Graphics *g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+
+ // We want to draw our loader bar to indicate the progress made in
+ // loading all our resources. As you recalll, GameApp::LoadingThreadProc is
+ // the thread that is actually loading everything. The app has a function,
+ // GetLoadingThreadProgress, that returns a value from 0.0 to 1.0 indicating
+ // the % complete it is. We will multiply this % complete by the width
+ // of our progress bar, so that we give the illusion of a growing bar.
+ int loaderBarWidth = IMAGE_LOADER_BAR->GetWidth();
+ int drawWidth = (int)(mApp->GetLoadingThreadProgress() * loaderBarWidth);
+ if (drawWidth > 0)
+ {
+ // As you may recall from Demo3 where we drew the frames of animation
+ // for the lightning image, the DrawImage call can take a source rectangle
+ // which indicates what chunk of the original image we want to draw.
+ // In our case, we want to start from from the upper left corner of
+ // the loader bar, but we only want to draw "drawWidth" wide. This will
+ // give the illusion that the progress bar is expanding as the resources
+ // are loaded in.
+ g->DrawImage(IMAGE_LOADER_BAR, mWidth / 2 - loaderBarWidth / 2,
+ 400,
+ Rect(0, 0, drawWidth, IMAGE_LOADER_BAR->GetHeight()));
+ }
+
+ // If our hyperlink widget is false, let's instead draw some
+ // "Loading" text (er, actually in this case it's an image) where
+ // it is located.
+ if (mContinueLink->mVisible == false)
+ g->DrawImage(IMAGE_LOADER_LOADINGTXT, mContinueLink->mX - 10, mContinueLink->mY - 80);
+
+ g->DrawImage(IMAGE_HUNGARR_LOGO, mWidth / 2 - IMAGE_HUNGARR_LOGO->mWidth / 2, 100);
+ g->SetColor(Color::White);
+ g->SetFont(FONT_HUNGARR);
+ SexyString s = _S("HUN-GARR NEEDS PLANETS!");
+ g->DrawString(s, mWidth / 2 - FONT_HUNGARR->StringWidth(s) / 2, 200);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::LoadingComplete()
+{
+ // Since the app told us that we're done loading all our resources,
+ // let's unhide and enable our continue link so the user can startr
+ // playing.
+ mContinueLink->SetVisible(true);
+ mContinueLink->SetDisabled(false);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void TitleScreen::ButtonDepress(int theId)
+{
+ if (theId == 1)
+ {
+ // Our hyperlink widget was pressed. We want to remove ourselves
+ // and the hyperlink widget, and tell the app to display the
+ // main board and get the game started.
+ // You might be thinking, "If I delete the title screen and
+ // hyperlink, won't I crash the program?" Yes, you will. That's
+ // why we aren't going to delete them using "delete". We're going
+ // to use SexyAppBase's SafeDeleteWidget method. This places the
+ // widget in a queue that is processed after all widgets and data
+ // get processed, and is then deleted at a time that is safe
+ // and appropriate. We still have to remove ourself and the
+ // hyperlink widget from the WidgetManager. We can easily access
+ // the WidgetManager, as it is a public variable in our game app.
+ mApp->mWidgetManager->RemoveWidget(this);
+ mApp->mWidgetManager->RemoveWidget(mContinueLink);
+ mApp->SafeDeleteWidget(this);
+ mApp->SafeDeleteWidget(mContinueLink);
+ mContinueLink = NULL;
+ mApp->PlaySample(SOUND_CONTINUE);
+
+ // Now let's tell the game app that it's ok to add the board widget:
+ mApp->TitleScreenIsFinished();
+ }
+} \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/TitleScreen.h b/osframework/source/demos/Hun-garr/TitleScreen.h
new file mode 100644
index 0000000..d603bf5
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/TitleScreen.h
@@ -0,0 +1,121 @@
+#ifndef __TITLE_SCREEN_H__
+#define __TITLE_SCREEN_H__
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+namespace Sexy
+{
+
+class GameApp;
+class Graphics;
+class WidgetManager;
+class HyperlinkWidget;
+
+
+class TitleScreen : public Widget, public ButtonListener
+{
+
+private:
+
+ GameApp* mApp;
+ HyperlinkWidget* mContinueLink;
+
+public:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: TitleScreen
+ // Parameters:
+ // theApp - Pointer to the main application class
+ //
+ // Returns: none
+ //////////////////////////////////////////////////////////////////////////
+ TitleScreen(GameApp* pApp);
+
+ virtual ~TitleScreen();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Init
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called BEFORE the title screen is added to the widget manager
+ // by GameApp. This initializes some things like the images used for
+ // our hyperlink widget.
+ //////////////////////////////////////////////////////////////////////////
+ void Init(void);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: AddedToManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // added to its list of widgets. Every widget gets this function
+ // called when it is first added. It useful to use this function to
+ // set up any other widgets that the class might contain, such as buttons.
+ //////////////////////////////////////////////////////////////////////////
+ void AddedToManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: RemovedFromManager
+ // Parameters:
+ // theWidgetManager - Pointer to the main widget manager from
+ // GameApp.
+ //
+ // Returns: none
+ //
+ // Purpose: This function is automatically called by the widget manager
+ // which also passes a pointer to itself, when the TitleScreen class is
+ // removed from its list of widgets. Every widget gets this function
+ // called when it is finally removed. It useful to use this function to
+ // also remove any widgets that were added and created in AddedToManager.
+ //////////////////////////////////////////////////////////////////////////
+ void RemovedFromManager(WidgetManager* theWidgetManager);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ButtonDepress
+ // Parameters:
+ // theId - Integer ID of the button that was clicked
+ //
+ // Returns: none
+ //
+ // Purpose: This method is called by the WidgetManager when a button widget
+ // is first pressed and THEN released. You can use ButtonPress if you want
+ // to know when the button is first pressed (before it is released).
+ // theId is the integer ID that was assigned to the button when it was
+ // first created.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ButtonDepress(int theId);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: Draw
+ // Parameters:
+ // g - Graphics object used to draw all images and fonts to the screen.
+ //
+ // Returns: none
+ //
+ // Purpose: Called automatically by GameApp's WidgetManager. This is where
+ // we'll do all our display routines for the loading screen.
+ //////////////////////////////////////////////////////////////////////////
+ void Draw(Graphics* g);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: LoadingComplete
+ // Parameters: none
+ // Returns: none
+ //
+ // Purpose: Called manually by GameApp when we are done loading all
+ // resources, to let the title screen know that it should unhide and
+ // enable the continue link, so the user can start playing the game.
+ //////////////////////////////////////////////////////////////////////////
+ void LoadingComplete();
+};
+
+}
+
+#endif //__TITLE_SCREEN_H__ \ No newline at end of file
diff --git a/osframework/source/demos/Hun-garr/main.cpp b/osframework/source/demos/Hun-garr/main.cpp
new file mode 100644
index 0000000..cfef199
--- /dev/null
+++ b/osframework/source/demos/Hun-garr/main.cpp
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// This demo will teach you:
+// * Using Hue, Saturation, Luminance values instead of RGB for color
+// * Custom cursors
+// * Handling loss/gain of application focus
+// * Basic particle effects
+// * Various programmatic effects/logic
+// * Putting most of the knowledge from the previous demos to work in a game
+//
+// IMPORTANT: Comments for topics covered in the previous demos will
+// be kept to a minimum and removed in most cases. You should read through
+// the previous demos to familiarize yourself with anything you don't
+// understand. All functions, variables, and concepts are explained
+// either in this demo, or in previous ones if they've already been covered.
+//////////////////////////////////////////////////////////////////////////
+
+#include "GameApp.h"
+
+
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+
+
+ gHInstance = hInstance;
+
+ GameApp* anApp = new GameApp();
+ anApp->Init();
+ anApp->Start();
+
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/Res.cpp b/osframework/source/demos/Res.cpp
new file mode 100644
index 0000000..5b12cf1
--- /dev/null
+++ b/osframework/source/demos/Res.cpp
@@ -0,0 +1,378 @@
+#include "Res.h"
+#include "SexyAppFramework/ResourceManager.h"
+
+using namespace Sexy;
+
+#pragma warning(disable:4311 4312)
+
+static bool gNeedRecalcVariableToIdMap = false;
+
+bool Sexy::ExtractResourcesByName(ResourceManager *theManager, const char *theName)
+{
+ if (strcmp(theName,"Game")==0) return ExtractGameResources(theManager);
+ if (strcmp(theName,"Hungarr")==0) return ExtractHungarrResources(theManager);
+ if (strcmp(theName,"Init")==0) return ExtractInitResources(theManager);
+ if (strcmp(theName,"TitleScreen")==0) return ExtractTitleScreenResources(theManager);
+ return false;
+}
+
+Sexy::ResourceId Sexy::GetIdByStringId(const char *theStringId)
+{
+ typedef std::map<std::string,int> MyMap;
+ static MyMap aMap;
+ if(aMap.empty())
+ {
+ for(int i=0; i<RESOURCE_ID_MAX; i++)
+ aMap[GetStringIdById(i)] = i;
+ }
+
+ MyMap::iterator anItr = aMap.find(theStringId);
+ if (anItr == aMap.end())
+ return RESOURCE_ID_MAX;
+ else
+ return (ResourceId) anItr->second;
+}
+
+// Game Resources
+Image* Sexy::IMAGE_BG0;
+Image* Sexy::IMAGE_BG1;
+Image* Sexy::IMAGE_BG2;
+Image* Sexy::IMAGE_BUTTON_DOWN;
+Image* Sexy::IMAGE_BUTTON_NORMAL;
+Image* Sexy::IMAGE_BUTTON_OVER;
+Image* Sexy::IMAGE_CHECKBOX;
+Image* Sexy::IMAGE_DIALOG_BOX;
+Image* Sexy::IMAGE_DIALOG_BUTTON;
+Image* Sexy::IMAGE_ROBOTROBOT;
+Image* Sexy::IMAGE_SLIDER_THUMB;
+Image* Sexy::IMAGE_SLIDER_TRACK;
+int Sexy::SOUND_MUTATOR;
+int Sexy::SOUND_TIMER;
+
+bool Sexy::ExtractGameResources(ResourceManager *theManager)
+{
+ gNeedRecalcVariableToIdMap = true;
+
+ ResourceManager &aMgr = *theManager;
+ try
+ {
+ IMAGE_BG0 = aMgr.GetImageThrow("IMAGE_BG0");
+ IMAGE_BG1 = aMgr.GetImageThrow("IMAGE_BG1");
+ IMAGE_BG2 = aMgr.GetImageThrow("IMAGE_BG2");
+ IMAGE_BUTTON_DOWN = aMgr.GetImageThrow("IMAGE_BUTTON_DOWN");
+ IMAGE_BUTTON_NORMAL = aMgr.GetImageThrow("IMAGE_BUTTON_NORMAL");
+ IMAGE_BUTTON_OVER = aMgr.GetImageThrow("IMAGE_BUTTON_OVER");
+ IMAGE_CHECKBOX = aMgr.GetImageThrow("IMAGE_CHECKBOX");
+ IMAGE_DIALOG_BOX = aMgr.GetImageThrow("IMAGE_DIALOG_BOX");
+ IMAGE_DIALOG_BUTTON = aMgr.GetImageThrow("IMAGE_DIALOG_BUTTON");
+ IMAGE_ROBOTROBOT = aMgr.GetImageThrow("IMAGE_ROBOTROBOT");
+ IMAGE_SLIDER_THUMB = aMgr.GetImageThrow("IMAGE_SLIDER_THUMB");
+ IMAGE_SLIDER_TRACK = aMgr.GetImageThrow("IMAGE_SLIDER_TRACK");
+ SOUND_MUTATOR = aMgr.GetSoundThrow("SOUND_MUTATOR");
+ SOUND_TIMER = aMgr.GetSoundThrow("SOUND_TIMER");
+ }
+ catch(ResourceManagerException&)
+ {
+ return false;
+ }
+ return true;
+}
+
+// Hungarr Resources
+Image* Sexy::IMAGE_ATOMIC_EXPLOSION;
+Image* Sexy::IMAGE_BOMB_RADIAL_DEATH;
+Image* Sexy::IMAGE_HUNGARR_BEAM_DOWN;
+Image* Sexy::IMAGE_HUNGARR_BEAM_LEFT;
+Image* Sexy::IMAGE_HUNGARR_BEAM_RIGHT;
+Image* Sexy::IMAGE_HUNGARR_BEAM_UP;
+Image* Sexy::IMAGE_HUNGARR_HORIZ;
+Image* Sexy::IMAGE_HUNGARR_SMALL;
+Image* Sexy::IMAGE_HUNGARR_VERT;
+Image* Sexy::IMAGE_PARTICLE_LIGHTNING;
+Image* Sexy::IMAGE_PLANETS;
+Image* Sexy::IMAGE_SPARK;
+int Sexy::SOUND_BEAM_HIT;
+int Sexy::SOUND_BEAM_MOVING;
+int Sexy::SOUND_BUTTON;
+int Sexy::SOUND_EXPLOSION;
+int Sexy::SOUND_GAME_OVER_CLICK;
+int Sexy::SOUND_GAME_OVER_RESTART;
+int Sexy::SOUND_GAME_OVER_STATS;
+int Sexy::SOUND_GAME_OVER_TEXT;
+int Sexy::SOUND_LEVEL_UP1;
+int Sexy::SOUND_LEVEL_UP2;
+int Sexy::SOUND_LEVEL_UP3;
+int Sexy::SOUND_LEVEL_UP4;
+int Sexy::SOUND_MAGZAP;
+int Sexy::SOUND_PLANET;
+int Sexy::SOUND_PLANET_HIT;
+int Sexy::SOUND_REGION_FILLED;
+
+bool Sexy::ExtractHungarrResources(ResourceManager *theManager)
+{
+ gNeedRecalcVariableToIdMap = true;
+
+ ResourceManager &aMgr = *theManager;
+ try
+ {
+ IMAGE_ATOMIC_EXPLOSION = aMgr.GetImageThrow("IMAGE_ATOMIC_EXPLOSION");
+ IMAGE_BOMB_RADIAL_DEATH = aMgr.GetImageThrow("IMAGE_BOMB_RADIAL_DEATH");
+ IMAGE_HUNGARR_BEAM_DOWN = aMgr.GetImageThrow("IMAGE_HUNGARR_BEAM_DOWN");
+ IMAGE_HUNGARR_BEAM_LEFT = aMgr.GetImageThrow("IMAGE_HUNGARR_BEAM_LEFT");
+ IMAGE_HUNGARR_BEAM_RIGHT = aMgr.GetImageThrow("IMAGE_HUNGARR_BEAM_RIGHT");
+ IMAGE_HUNGARR_BEAM_UP = aMgr.GetImageThrow("IMAGE_HUNGARR_BEAM_UP");
+ IMAGE_HUNGARR_HORIZ = aMgr.GetImageThrow("IMAGE_HUNGARR_HORIZ");
+ IMAGE_HUNGARR_SMALL = aMgr.GetImageThrow("IMAGE_HUNGARR_SMALL");
+ IMAGE_HUNGARR_VERT = aMgr.GetImageThrow("IMAGE_HUNGARR_VERT");
+ IMAGE_PARTICLE_LIGHTNING = aMgr.GetImageThrow("IMAGE_PARTICLE_LIGHTNING");
+ IMAGE_PLANETS = aMgr.GetImageThrow("IMAGE_PLANETS");
+ IMAGE_SPARK = aMgr.GetImageThrow("IMAGE_SPARK");
+ SOUND_BEAM_HIT = aMgr.GetSoundThrow("SOUND_BEAM_HIT");
+ SOUND_BEAM_MOVING = aMgr.GetSoundThrow("SOUND_BEAM_MOVING");
+ SOUND_BUTTON = aMgr.GetSoundThrow("SOUND_BUTTON");
+ SOUND_EXPLOSION = aMgr.GetSoundThrow("SOUND_EXPLOSION");
+ SOUND_GAME_OVER_CLICK = aMgr.GetSoundThrow("SOUND_GAME_OVER_CLICK");
+ SOUND_GAME_OVER_RESTART = aMgr.GetSoundThrow("SOUND_GAME_OVER_RESTART");
+ SOUND_GAME_OVER_STATS = aMgr.GetSoundThrow("SOUND_GAME_OVER_STATS");
+ SOUND_GAME_OVER_TEXT = aMgr.GetSoundThrow("SOUND_GAME_OVER_TEXT");
+ SOUND_LEVEL_UP1 = aMgr.GetSoundThrow("SOUND_LEVEL_UP1");
+ SOUND_LEVEL_UP2 = aMgr.GetSoundThrow("SOUND_LEVEL_UP2");
+ SOUND_LEVEL_UP3 = aMgr.GetSoundThrow("SOUND_LEVEL_UP3");
+ SOUND_LEVEL_UP4 = aMgr.GetSoundThrow("SOUND_LEVEL_UP4");
+ SOUND_MAGZAP = aMgr.GetSoundThrow("SOUND_MAGZAP");
+ SOUND_PLANET = aMgr.GetSoundThrow("SOUND_PLANET");
+ SOUND_PLANET_HIT = aMgr.GetSoundThrow("SOUND_PLANET_HIT");
+ SOUND_REGION_FILLED = aMgr.GetSoundThrow("SOUND_REGION_FILLED");
+ }
+ catch(ResourceManagerException&)
+ {
+ return false;
+ }
+ return true;
+}
+
+// Init Resources
+Font* Sexy::FONT_DEFAULT;
+Font* Sexy::FONT_HUNGARR;
+Image* Sexy::IMAGE_CUSTOM_DRAGGING;
+Image* Sexy::IMAGE_CUSTOM_HAND;
+Image* Sexy::IMAGE_CUSTOM_POINTER;
+Image* Sexy::IMAGE_CUSTOM_TEXT;
+Image* Sexy::IMAGE_HUNGARR_LOGO;
+
+bool Sexy::ExtractInitResources(ResourceManager *theManager)
+{
+ gNeedRecalcVariableToIdMap = true;
+
+ ResourceManager &aMgr = *theManager;
+ try
+ {
+ FONT_DEFAULT = aMgr.GetFontThrow("FONT_DEFAULT");
+ FONT_HUNGARR = aMgr.GetFontThrow("FONT_HUNGARR");
+ IMAGE_CUSTOM_DRAGGING = aMgr.GetImageThrow("IMAGE_CUSTOM_DRAGGING");
+ IMAGE_CUSTOM_HAND = aMgr.GetImageThrow("IMAGE_CUSTOM_HAND");
+ IMAGE_CUSTOM_POINTER = aMgr.GetImageThrow("IMAGE_CUSTOM_POINTER");
+ IMAGE_CUSTOM_TEXT = aMgr.GetImageThrow("IMAGE_CUSTOM_TEXT");
+ IMAGE_HUNGARR_LOGO = aMgr.GetImageThrow("IMAGE_HUNGARR_LOGO");
+ }
+ catch(ResourceManagerException&)
+ {
+ return false;
+ }
+ return true;
+}
+
+// TitleScreen Resources
+Image* Sexy::IMAGE_LOADER_BAR;
+Image* Sexy::IMAGE_LOADER_LOADINGTXT;
+int Sexy::SOUND_CONTINUE;
+
+bool Sexy::ExtractTitleScreenResources(ResourceManager *theManager)
+{
+ gNeedRecalcVariableToIdMap = true;
+
+ ResourceManager &aMgr = *theManager;
+ try
+ {
+ IMAGE_LOADER_BAR = aMgr.GetImageThrow("IMAGE_LOADER_BAR");
+ IMAGE_LOADER_LOADINGTXT = aMgr.GetImageThrow("IMAGE_LOADER_LOADINGTXT");
+ SOUND_CONTINUE = aMgr.GetSoundThrow("SOUND_CONTINUE");
+ }
+ catch(ResourceManagerException&)
+ {
+ return false;
+ }
+ return true;
+}
+
+static void* gResources[] =
+{
+ &FONT_DEFAULT,
+ &FONT_HUNGARR,
+ &IMAGE_CUSTOM_POINTER,
+ &IMAGE_CUSTOM_HAND,
+ &IMAGE_CUSTOM_DRAGGING,
+ &IMAGE_CUSTOM_TEXT,
+ &IMAGE_HUNGARR_LOGO,
+ &IMAGE_LOADER_BAR,
+ &IMAGE_LOADER_LOADINGTXT,
+ &SOUND_CONTINUE,
+ &SOUND_MUTATOR,
+ &SOUND_TIMER,
+ &IMAGE_ROBOTROBOT,
+ &IMAGE_CHECKBOX,
+ &IMAGE_BG0,
+ &IMAGE_BG1,
+ &IMAGE_BG2,
+ &IMAGE_BUTTON_DOWN,
+ &IMAGE_BUTTON_OVER,
+ &IMAGE_BUTTON_NORMAL,
+ &IMAGE_DIALOG_BOX,
+ &IMAGE_DIALOG_BUTTON,
+ &IMAGE_SLIDER_TRACK,
+ &IMAGE_SLIDER_THUMB,
+ &IMAGE_HUNGARR_SMALL,
+ &IMAGE_HUNGARR_BEAM_UP,
+ &IMAGE_HUNGARR_BEAM_DOWN,
+ &IMAGE_HUNGARR_BEAM_LEFT,
+ &IMAGE_HUNGARR_BEAM_RIGHT,
+ &IMAGE_HUNGARR_HORIZ,
+ &IMAGE_HUNGARR_VERT,
+ &IMAGE_ATOMIC_EXPLOSION,
+ &IMAGE_BOMB_RADIAL_DEATH,
+ &IMAGE_PLANETS,
+ &IMAGE_SPARK,
+ &IMAGE_PARTICLE_LIGHTNING,
+ &SOUND_MAGZAP,
+ &SOUND_BUTTON,
+ &SOUND_PLANET,
+ &SOUND_LEVEL_UP1,
+ &SOUND_LEVEL_UP2,
+ &SOUND_EXPLOSION,
+ &SOUND_BEAM_HIT,
+ &SOUND_PLANET_HIT,
+ &SOUND_BEAM_MOVING,
+ &SOUND_LEVEL_UP4,
+ &SOUND_LEVEL_UP3,
+ &SOUND_GAME_OVER_CLICK,
+ &SOUND_GAME_OVER_STATS,
+ &SOUND_GAME_OVER_RESTART,
+ &SOUND_GAME_OVER_TEXT,
+ &SOUND_REGION_FILLED,
+ NULL
+};
+
+Image* Sexy::LoadImageById(ResourceManager *theManager, int theId)
+{
+ return (*((Image**)gResources[theId]) = theManager->LoadImage(GetStringIdById(theId)));
+}
+
+Image* Sexy::GetImageById(int theId)
+{
+ return *(Image**)gResources[theId];
+}
+
+Font* Sexy::GetFontById(int theId)
+{
+ return *(Font**)gResources[theId];
+}
+
+int Sexy::GetSoundById(int theId)
+{
+ return *(int*)gResources[theId];
+}
+
+static Sexy::ResourceId GetIdByVariable(const void *theVariable)
+{
+ typedef std::map<int,int> MyMap;
+ static MyMap aMap;
+ if(gNeedRecalcVariableToIdMap)
+ {
+ gNeedRecalcVariableToIdMap = false;
+ aMap.clear();
+ for(int i=0; i<RESOURCE_ID_MAX; i++)
+ aMap[*(int*)gResources[i]] = i;
+ }
+
+ MyMap::iterator anItr = aMap.find((int)theVariable);
+ if (anItr == aMap.end())
+ return RESOURCE_ID_MAX;
+ else
+ return (ResourceId) anItr->second;
+}
+
+Sexy::ResourceId Sexy::GetIdByImage(Image *theImage)
+{
+ return GetIdByVariable(theImage);
+}
+
+Sexy::ResourceId Sexy::GetIdByFont(Font *theFont)
+{
+ return GetIdByVariable(theFont);
+}
+
+Sexy::ResourceId Sexy::GetIdBySound(int theSound)
+{
+ return GetIdByVariable((void*)theSound);
+}
+
+const char* Sexy::GetStringIdById(int theId)
+{
+ switch(theId)
+ {
+ case FONT_DEFAULT_ID: return "FONT_DEFAULT";
+ case FONT_HUNGARR_ID: return "FONT_HUNGARR";
+ case IMAGE_CUSTOM_POINTER_ID: return "IMAGE_CUSTOM_POINTER";
+ case IMAGE_CUSTOM_HAND_ID: return "IMAGE_CUSTOM_HAND";
+ case IMAGE_CUSTOM_DRAGGING_ID: return "IMAGE_CUSTOM_DRAGGING";
+ case IMAGE_CUSTOM_TEXT_ID: return "IMAGE_CUSTOM_TEXT";
+ case IMAGE_HUNGARR_LOGO_ID: return "IMAGE_HUNGARR_LOGO";
+ case IMAGE_LOADER_BAR_ID: return "IMAGE_LOADER_BAR";
+ case IMAGE_LOADER_LOADINGTXT_ID: return "IMAGE_LOADER_LOADINGTXT";
+ case SOUND_CONTINUE_ID: return "SOUND_CONTINUE";
+ case SOUND_MUTATOR_ID: return "SOUND_MUTATOR";
+ case SOUND_TIMER_ID: return "SOUND_TIMER";
+ case IMAGE_ROBOTROBOT_ID: return "IMAGE_ROBOTROBOT";
+ case IMAGE_CHECKBOX_ID: return "IMAGE_CHECKBOX";
+ case IMAGE_BG0_ID: return "IMAGE_BG0";
+ case IMAGE_BG1_ID: return "IMAGE_BG1";
+ case IMAGE_BG2_ID: return "IMAGE_BG2";
+ case IMAGE_BUTTON_DOWN_ID: return "IMAGE_BUTTON_DOWN";
+ case IMAGE_BUTTON_OVER_ID: return "IMAGE_BUTTON_OVER";
+ case IMAGE_BUTTON_NORMAL_ID: return "IMAGE_BUTTON_NORMAL";
+ case IMAGE_DIALOG_BOX_ID: return "IMAGE_DIALOG_BOX";
+ case IMAGE_DIALOG_BUTTON_ID: return "IMAGE_DIALOG_BUTTON";
+ case IMAGE_SLIDER_TRACK_ID: return "IMAGE_SLIDER_TRACK";
+ case IMAGE_SLIDER_THUMB_ID: return "IMAGE_SLIDER_THUMB";
+ case IMAGE_HUNGARR_SMALL_ID: return "IMAGE_HUNGARR_SMALL";
+ case IMAGE_HUNGARR_BEAM_UP_ID: return "IMAGE_HUNGARR_BEAM_UP";
+ case IMAGE_HUNGARR_BEAM_DOWN_ID: return "IMAGE_HUNGARR_BEAM_DOWN";
+ case IMAGE_HUNGARR_BEAM_LEFT_ID: return "IMAGE_HUNGARR_BEAM_LEFT";
+ case IMAGE_HUNGARR_BEAM_RIGHT_ID: return "IMAGE_HUNGARR_BEAM_RIGHT";
+ case IMAGE_HUNGARR_HORIZ_ID: return "IMAGE_HUNGARR_HORIZ";
+ case IMAGE_HUNGARR_VERT_ID: return "IMAGE_HUNGARR_VERT";
+ case IMAGE_ATOMIC_EXPLOSION_ID: return "IMAGE_ATOMIC_EXPLOSION";
+ case IMAGE_BOMB_RADIAL_DEATH_ID: return "IMAGE_BOMB_RADIAL_DEATH";
+ case IMAGE_PLANETS_ID: return "IMAGE_PLANETS";
+ case IMAGE_SPARK_ID: return "IMAGE_SPARK";
+ case IMAGE_PARTICLE_LIGHTNING_ID: return "IMAGE_PARTICLE_LIGHTNING";
+ case SOUND_MAGZAP_ID: return "SOUND_MAGZAP";
+ case SOUND_BUTTON_ID: return "SOUND_BUTTON";
+ case SOUND_PLANET_ID: return "SOUND_PLANET";
+ case SOUND_LEVEL_UP1_ID: return "SOUND_LEVEL_UP1";
+ case SOUND_LEVEL_UP2_ID: return "SOUND_LEVEL_UP2";
+ case SOUND_EXPLOSION_ID: return "SOUND_EXPLOSION";
+ case SOUND_BEAM_HIT_ID: return "SOUND_BEAM_HIT";
+ case SOUND_PLANET_HIT_ID: return "SOUND_PLANET_HIT";
+ case SOUND_BEAM_MOVING_ID: return "SOUND_BEAM_MOVING";
+ case SOUND_LEVEL_UP4_ID: return "SOUND_LEVEL_UP4";
+ case SOUND_LEVEL_UP3_ID: return "SOUND_LEVEL_UP3";
+ case SOUND_GAME_OVER_CLICK_ID: return "SOUND_GAME_OVER_CLICK";
+ case SOUND_GAME_OVER_STATS_ID: return "SOUND_GAME_OVER_STATS";
+ case SOUND_GAME_OVER_RESTART_ID: return "SOUND_GAME_OVER_RESTART";
+ case SOUND_GAME_OVER_TEXT_ID: return "SOUND_GAME_OVER_TEXT";
+ case SOUND_REGION_FILLED_ID: return "SOUND_REGION_FILLED";
+ default: return "";
+ }
+}
+
diff --git a/osframework/source/demos/Res.h b/osframework/source/demos/Res.h
new file mode 100644
index 0000000..dbe0fdc
--- /dev/null
+++ b/osframework/source/demos/Res.h
@@ -0,0 +1,147 @@
+#ifndef __Res_H__
+#define __Res_H__
+
+namespace Sexy
+{
+ class ResourceManager;
+ class Image;
+ class Font;
+
+ Image* LoadImageById(ResourceManager *theManager, int theId);
+ bool ExtractResourcesByName(ResourceManager *theManager, const char *theName);
+
+ // Game Resources
+ bool ExtractGameResources(ResourceManager *theMgr);
+ extern Image* IMAGE_BG0;
+ extern Image* IMAGE_BG1;
+ extern Image* IMAGE_BG2;
+ extern Image* IMAGE_BUTTON_DOWN;
+ extern Image* IMAGE_BUTTON_NORMAL;
+ extern Image* IMAGE_BUTTON_OVER;
+ extern Image* IMAGE_CHECKBOX;
+ extern Image* IMAGE_DIALOG_BOX;
+ extern Image* IMAGE_DIALOG_BUTTON;
+ extern Image* IMAGE_ROBOTROBOT;
+ extern Image* IMAGE_SLIDER_THUMB;
+ extern Image* IMAGE_SLIDER_TRACK;
+ extern int SOUND_MUTATOR;
+ extern int SOUND_TIMER;
+
+ // Hungarr Resources
+ bool ExtractHungarrResources(ResourceManager *theMgr);
+ extern Image* IMAGE_ATOMIC_EXPLOSION;
+ extern Image* IMAGE_BOMB_RADIAL_DEATH;
+ extern Image* IMAGE_HUNGARR_BEAM_DOWN;
+ extern Image* IMAGE_HUNGARR_BEAM_LEFT;
+ extern Image* IMAGE_HUNGARR_BEAM_RIGHT;
+ extern Image* IMAGE_HUNGARR_BEAM_UP;
+ extern Image* IMAGE_HUNGARR_HORIZ;
+ extern Image* IMAGE_HUNGARR_SMALL;
+ extern Image* IMAGE_HUNGARR_VERT;
+ extern Image* IMAGE_PARTICLE_LIGHTNING;
+ extern Image* IMAGE_PLANETS;
+ extern Image* IMAGE_SPARK;
+ extern int SOUND_BEAM_HIT;
+ extern int SOUND_BEAM_MOVING;
+ extern int SOUND_BUTTON;
+ extern int SOUND_EXPLOSION;
+ extern int SOUND_GAME_OVER_CLICK;
+ extern int SOUND_GAME_OVER_RESTART;
+ extern int SOUND_GAME_OVER_STATS;
+ extern int SOUND_GAME_OVER_TEXT;
+ extern int SOUND_LEVEL_UP1;
+ extern int SOUND_LEVEL_UP2;
+ extern int SOUND_LEVEL_UP3;
+ extern int SOUND_LEVEL_UP4;
+ extern int SOUND_MAGZAP;
+ extern int SOUND_PLANET;
+ extern int SOUND_PLANET_HIT;
+ extern int SOUND_REGION_FILLED;
+
+ // Init Resources
+ bool ExtractInitResources(ResourceManager *theMgr);
+ extern Font* FONT_DEFAULT;
+ extern Font* FONT_HUNGARR;
+ extern Image* IMAGE_CUSTOM_DRAGGING;
+ extern Image* IMAGE_CUSTOM_HAND;
+ extern Image* IMAGE_CUSTOM_POINTER;
+ extern Image* IMAGE_CUSTOM_TEXT;
+ extern Image* IMAGE_HUNGARR_LOGO;
+
+ // TitleScreen Resources
+ bool ExtractTitleScreenResources(ResourceManager *theMgr);
+ extern Image* IMAGE_LOADER_BAR;
+ extern Image* IMAGE_LOADER_LOADINGTXT;
+ extern int SOUND_CONTINUE;
+
+ enum ResourceId
+ {
+ FONT_DEFAULT_ID,
+ FONT_HUNGARR_ID,
+ IMAGE_CUSTOM_POINTER_ID,
+ IMAGE_CUSTOM_HAND_ID,
+ IMAGE_CUSTOM_DRAGGING_ID,
+ IMAGE_CUSTOM_TEXT_ID,
+ IMAGE_HUNGARR_LOGO_ID,
+ IMAGE_LOADER_BAR_ID,
+ IMAGE_LOADER_LOADINGTXT_ID,
+ SOUND_CONTINUE_ID,
+ SOUND_MUTATOR_ID,
+ SOUND_TIMER_ID,
+ IMAGE_ROBOTROBOT_ID,
+ IMAGE_CHECKBOX_ID,
+ IMAGE_BG0_ID,
+ IMAGE_BG1_ID,
+ IMAGE_BG2_ID,
+ IMAGE_BUTTON_DOWN_ID,
+ IMAGE_BUTTON_OVER_ID,
+ IMAGE_BUTTON_NORMAL_ID,
+ IMAGE_DIALOG_BOX_ID,
+ IMAGE_DIALOG_BUTTON_ID,
+ IMAGE_SLIDER_TRACK_ID,
+ IMAGE_SLIDER_THUMB_ID,
+ IMAGE_HUNGARR_SMALL_ID,
+ IMAGE_HUNGARR_BEAM_UP_ID,
+ IMAGE_HUNGARR_BEAM_DOWN_ID,
+ IMAGE_HUNGARR_BEAM_LEFT_ID,
+ IMAGE_HUNGARR_BEAM_RIGHT_ID,
+ IMAGE_HUNGARR_HORIZ_ID,
+ IMAGE_HUNGARR_VERT_ID,
+ IMAGE_ATOMIC_EXPLOSION_ID,
+ IMAGE_BOMB_RADIAL_DEATH_ID,
+ IMAGE_PLANETS_ID,
+ IMAGE_SPARK_ID,
+ IMAGE_PARTICLE_LIGHTNING_ID,
+ SOUND_MAGZAP_ID,
+ SOUND_BUTTON_ID,
+ SOUND_PLANET_ID,
+ SOUND_LEVEL_UP1_ID,
+ SOUND_LEVEL_UP2_ID,
+ SOUND_EXPLOSION_ID,
+ SOUND_BEAM_HIT_ID,
+ SOUND_PLANET_HIT_ID,
+ SOUND_BEAM_MOVING_ID,
+ SOUND_LEVEL_UP4_ID,
+ SOUND_LEVEL_UP3_ID,
+ SOUND_GAME_OVER_CLICK_ID,
+ SOUND_GAME_OVER_STATS_ID,
+ SOUND_GAME_OVER_RESTART_ID,
+ SOUND_GAME_OVER_TEXT_ID,
+ SOUND_REGION_FILLED_ID,
+ RESOURCE_ID_MAX
+ };
+
+ Image* GetImageById(int theId);
+ Font* GetFontById(int theId);
+ int GetSoundById(int theId);
+
+ ResourceId GetIdByImage(Image *theImage);
+ ResourceId GetIdByFont(Font *theFont);
+ ResourceId GetIdBySound(int theSound);
+ const char* GetStringIdById(int theId);
+ ResourceId GetIdByStringId(const char *theStringId);
+
+} // namespace Sexy
+
+
+#endif
diff --git a/osframework/source/demos/V12Demo/.#Board.cpp.1.7 b/osframework/source/demos/V12Demo/.#Board.cpp.1.7
new file mode 100644
index 0000000..c176a74
--- /dev/null
+++ b/osframework/source/demos/V12Demo/.#Board.cpp.1.7
@@ -0,0 +1,442 @@
+#include "Board.h"
+#include "DemoWidget.h"
+#include "Res.h"
+#include "V12DemoApp.h"
+#include "..\SexyAppFramework\Font.h"
+#include "..\SexyAppFramework\Graphics.h"
+#include "..\SexyAppFramework\ButtonWidget.h"
+#include "..\SexyAppFramework\WidgetManager.h"
+#include "..\SexyAppFramework\Dialog.h"
+#include "..\SexyAppFramework\Flags.h"
+#include "..\SexyAppFramework\SexyMatrix.h"
+#include "..\SexyAppFramework\trivertex.h"
+
+using namespace Sexy;
+
+Board::Board(V12DemoApp* theApp)
+{
+ mApp = theApp;
+
+
+ // Remeber the flag explanation in the 1.2 doc and V12Demo.cpp? Sure you do.
+ // This is basically another use of it. All widgets by default have the following
+ // flags set:
+ // WIDGETFLAGS_UPDATE - The widget gets its Update and UpdateF methods called
+ // WIDGETFLAGS_DRAW - The widget is allowed to draw
+ // WIDGETFLAGS_CLIP - Set to clip Graphics passed into Draw to the widget's bounds
+ // WIDGETFLAGS_ALLOW_MOUSE - Set to allow mouse interaction
+ // WIDGETFLAGS_ALLOW_FOCUS - Set to allow focus to be maintained
+ //
+ // Previously, if you wanted to mark the widget dirty every frame (and thus draw every
+ // frame), you had to call MarkDirty() all the time. Instead of doing that, we can just
+ // use the flag system. By ORing WIDGETFLAGS_MARK_DIRTY with mWidgetFlagsMod.mAddFlags,
+ // when we are added to the widget manager, the manager will then know that we want to
+ // be marked dirty every frame automatically, instead of manually calling MarkDirty().
+ // Yes, I know, that's not a huge deal, but as you can see from the other flags,
+ // it's now easy to set/unset various flags for various widgets and..various reasons.
+ // If you wanted to remove flags set by default for this widget, you'd just OR the
+ // flags to remove with mWidgetFlagsMod.mRemoveFlags. You can affect ALL widgets if you
+ // want to set up widget defaults, by modifying mApp->mWidgetManager's mWidgetFlags
+ // structure in a similar way.
+
+ mWidgetFlagsMod.mAddFlags |= WIDGETFLAGS_MARK_DIRTY;
+
+ // Previously, it was annoying trying to place widgets on some sort of parent widget,
+ // since there was no notion of parent/child relationship. What you had to do was
+ // override the AddedToManager and RemovedFromManager functions, create and add your
+ // widgets or remove and nuke them, and in the case of AddedToManager, you also had
+ // to then place the widget using global coordinates that had no relation to the coordinates
+ // you set the parent widget at. Not anymore. What we can do now is to dispense with
+ // overriding those methods altogether! So now, in the parent's constructor, we can
+ // create our child widgets, resize them, and place them using relative coordinates.
+ // What this also means is that moving the parent widget around results in moving
+ // ALL the child widgets, which means you no longer have to manually move everything
+ // just because the parent moved. In addition, another nice thing is that you no longer
+ // have to remove your child widgets before deleting them: this is handled automatically
+ // for you.
+ mDemoButton = new ButtonWidget(0, this);
+ mDemoButton->mLabel = "Demo Widget";
+ mDemoButton->SetFont(FONT_DEFAULT);
+ mDemoButton->Resize(10, 10, 10 + FONT_DEFAULT->StringWidth(mDemoButton->mLabel), 50);
+
+ // VERY IMPORTANT: Notice that we're calling THIS CLASS' (or really, it's parent, WidgetContainer's)
+ // AddWidget method instead of the WidgetManager's method. In order to designate a widget as a child
+ // widget, you have to call the AddWidget method of the class that will be its parent.
+ AddWidget(mDemoButton);
+
+ mDialogButton = new ButtonWidget(1, this);
+ mDialogButton->mLabel = "Do Dialog";
+ mDialogButton->SetFont(FONT_DEFAULT);
+ int w = FONT_DEFAULT->StringWidth(mDialogButton->mLabel);
+ mDialogButton->Resize(mApp->mWidth - 20 - w, 10, w + 10, 50);
+ AddWidget(mDialogButton);
+
+ mCurtainButton = new ButtonWidget(2, this);
+ mCurtainButton->mLabel = "Do Transition";
+ mCurtainButton->SetFont(FONT_DEFAULT);
+ w = FONT_DEFAULT->StringWidth(mCurtainButton->mLabel);
+ mCurtainButton->Resize(mDemoButton->mX + 20 + mDemoButton->mWidth, 10, w + 10, 50);
+ AddWidget(mCurtainButton);
+
+ mDemoWidget = NULL;
+
+ // Position and set up our pulsing rectangle, as well as the location of the lost focus text.
+ mRect = Rect(mApp->mWidth / 2 - 1, mApp->mHeight / 2 - 1, 2, 2);
+ mExpanding = true;
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+ mLostFocus = false;
+
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+
+ // We'll toggle this between 0 and 2 every second when we are unfocussed
+ mDeferPriority = 0;
+}
+
+Board::~Board()
+{
+ // We need to remove child widgets before deleting them.
+ RemoveAllWidgets();
+
+ delete mDemoButton;
+ delete mDialogButton;
+ delete mCurtainButton;
+
+ if (mDemoWidget != NULL)
+ mApp->mWidgetManager->RemoveWidget(mDemoWidget);
+
+ delete mDemoWidget;
+}
+
+void Board::Update()
+{
+ Widget::Update();
+
+ if (mLostFocus)
+ {
+ if (mUpdateCnt % 100 == 0)
+ {
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+
+ // Every second, we switch between drawing the overlay above or below
+ // the mDemoWidget object (assuming of course you have the widget on screen
+ // when you lose focus).
+ mDeferPriority = mDeferPriority == 0 ? 2 : 0;
+ }
+ }
+ else
+ {
+ // This just makes the rectangle in the middle grow/shrink. Nothing
+ // too crazy.
+ if (mExpanding)
+ {
+ mRect.mWidth += 2;
+ mRect.mHeight += 2;
+
+ if (mRect.mWidth >= mApp->mWidth)
+ {
+ mRect.mWidth = mApp->mWidth;
+ mExpanding = false;
+ }
+
+ if (mRect.mHeight >= mApp->mHeight)
+ {
+ mRect.mHeight = mApp->mHeight;
+ mExpanding = false;
+ }
+ }
+ else
+ {
+ mRect.mWidth -= 2;
+ mRect.mHeight -= 2;
+
+ if (mRect.mHeight <= 0)
+ {
+ mRect.mHeight = 0;
+ mExpanding = true;
+ }
+
+ if (mRect.mWidth <= 0)
+ {
+ mRect.mWidth = 0;
+ mExpanding = true;
+ }
+
+ }
+
+ mRect.mX = mApp->mWidth / 2 - mRect.mWidth / 2;
+ mRect.mY = mApp->mHeight / 2 - mRect.mHeight / 2;
+ }
+}
+
+void Board::Draw(Graphics* g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Draw our pulsing rectangle in the middle of the screen.
+ g->SetColor(Color(255, 0, 0));
+ g->FillRect(mRect);
+
+ if (!mLostFocus)
+ {
+ // Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // In Board::DrawOverlay, you'll see that we can use PushState and PopState to on-demand
+ // save/restore the graphics state. However, if we're either lazy, or after we draw
+ // our current stuff we don't have a need to reset the state and change it again, we
+ // can use the GraphicsAutoState object. This nifty helper class, upon instantiation on
+ // the stack, will automatically push the graphics state of the graphics object you pass in.
+ // Note that since stack variables are
+ // removed (and have their con/destructors called automatically, for classes/structs) when they
+ // go out of scope, the destructor for a GraphicsAutoState object takes care of popping the graphics
+ // state and restoring things to their previous..uh...state.
+ // NOTE: Graphics state is saved between widgets.
+ GraphicsAutoState auto_state(g);
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+ g->SetColor(Color(mUpdateCnt % 128, mUpdateCnt % 255, mUpdateCnt % 64));
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ }
+
+ if (mCurtainMode != CURTAIN_INACTIVE)
+ {
+ g->SetColor(Color(255, 255, 0));
+ g->FillRect(0, 0, mCurtainWidth, mHeight);
+ g->FillRect(mWidth - mCurtainWidth, 0, mCurtainWidth, mHeight);
+ }
+
+ // Instead of using an overlay widget to draw our stuff when focus is lost,
+ // we can just use DeferOverlay. You can ONLY call this in a Draw routine. What happens
+ // when you call DeferOverlay is that it schedules with the WidgetManager a call to
+ // this widget's DrawOverlay method at a later time. You can control the order of the
+ // overlay layer, and place it above or below other widgets by optionally specifying
+ // a defer priority in the call to DeferOverlay. The higher the priority, the more toplevel
+ // and thus the more widgets above it will be drawn. You'll notice that in DemoWidget's constructor,
+ // that we set its priority to 1. Thus, if we DeferOverlay with a value of 0, the overlay will be
+ // drawn BELOW the demo widget, but still above all our child widgets and ourself. When mDeferPriority
+ // is 2, it will be drawn above ALL widgets, including the demo widget, as its priority is only 1, which
+ // last time I checked, is less than 2. Note that widgets by default have priority 0 and dialogs have priority 1.
+ //if (mLostFocus)
+ DeferOverlay(mDeferPriority);
+
+}
+
+void Board::DrawOverlay(Graphics* g)
+{
+ // Make sure you've read through Board::Draw before this guy, as it explains
+ // how and why we get here.
+ g->SetColor(Color(0, 0, 255, 175));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::White);
+ g->DrawString("LOST FOCUS", mMsgX, mMsgY);
+
+ // PushState is a new addition. Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // With PushState, you save the entire previous state of things. Then, you can make
+ // whatever changes you like, without needing to undo them, as a resulting call to
+ // PopState restores things back to normal. Note that you can push/pop as much as you want.
+ g->PushState();
+
+ // No need to turn this off! When we PopState the previous, non-colorized state,
+ // will return.
+ g->SetColorizeImages(true);
+ g->SetColor(Color(0, 255, 255));
+
+ // MORE NEW STUFF? Yes. Think back to the previous framework version:
+ // how would you draw in real-time, a rotated and scaled image at a given
+ // location? Well, you could mess around with destination Rects for scaling,
+ // but you would have a hard time scaling and rotating all at once. You could
+ // create images in memory to hold the scaled or rotated versions, but that's annoying.
+ // BEHOLD: DrawImageTransform/F. All you have to do is create a Transform object,
+ // and apply various transformations to it, then call DrawImageTransform/F.
+ // Let's take a look:
+ Transform t;
+
+ // Let's rotate the image between 0 and 360 degrees (note that you could also
+ // use the radian version of the function). So far, not hard, right?
+ t.RotateDeg((float)(mUpdateCnt % 360));
+
+ float sw = 1.0f;
+ float sh = 1.0f;
+
+ // Don't get scared here. This is just a little trickery to expand/contract
+ // the image depending on the update count. All it does is expand the image
+ // to normal size for a second, and then shrink it to almost invisible for
+ // another second, which makes that pulse effect happen.
+ int mod = mUpdateCnt % 200;
+ if (mod < 100)
+ {
+ sw = (float)(mod + 1) / 100.0f;
+ sh = (float)(mod + 1) / 100.0f;
+ }
+ else
+ {
+ mod = 200 - mod;
+ sw = (float)mod / 100.0f;
+ sh = (float)mod / 100.0f;
+ }
+
+ // And now we just tell the transform object, t, that we want to scale.
+ // The value for the x and y direction should be a %, so 1.0 means no change in scale.
+ // Let's also mirror and flip the image at the same time too. To mirror and flip, we'll
+ // just multiply sw and sh by -1. Of course, it'll be hard to tell that it's flipped and mirrored
+ // since it's rotating at the same time, so if you don't believe me you can try commenting
+ // out the t.RotateDeg(...) call above and you'll see that it works.
+ t.Scale(-sw, -sh);
+
+ // And now we just pass in our transform object and it works in both 2D and 3D! Note that we can also
+ // draw the image at a given XY as well. We'll make it move rightward depending on the update count.
+ // ******************IMPORTANT NOTE:*********************
+ // DrawImageTransform/F and DrawImageMatrix use the CENTER of the image rather than the top left
+ // for XY drawing. For images of even size, the non-F form of the function will just truncate
+ // the the center, but for the F forms, they will be offset by 0.5f since floating point is used.
+ if (gSexyAppBase->Is3DAccelerated())
+ g->DrawImageTransformF(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+ else
+ g->DrawImageTransform(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+
+ g->PopState();
+
+ // You can now draw using matrices. Why the heck would you want to use matrices? Besides doing some
+ // crazy stuff, you can also do some cool little tricks. For example, previously it used be a pain
+ // to in real-time flip and mirror an image. While I won't give a tutorial on matrix algebra
+ // (that would take a loooooong time), I'll explain the essential parts:
+ SexyTransform2D matrix;
+
+
+ // Multiplying the X coordinate by -1 (which is the 0, 0 element of the matrix) will result in our
+ // image being mirrored, while multiplying the Y coordinate by -1 (1, 1 in the matrix) will result in our
+ // image being flipped.
+ matrix.m[0][0] *= -1;
+ matrix.m[1][1] *= -1;
+ matrix.RotateDeg(45.0f);
+ g->SetFastStretch(true);
+ bool b = g->GetFastStretch();
+
+ // Let's also shear it. While mirroring/flipping could easily be done with the DrawImageTransform methods,
+ // doing more complex matrix manipulation (like shearing) can only be done with the DrawImageMatrix function.
+ matrix.m[0][1] = 2;
+
+ // And then we just make a call to DrawImageMatrix and give it our specified XY coordinates as well,
+ // and that's it! This works in both 2D and 3D modes.
+ g->DrawImageMatrix(IMAGE_HUNGARR_LOGO, matrix, 300, 400);
+
+ // IMPORTANT COMPARISON NOTE:
+ // DrawImageTransform/F will try to use the faster drawing methods if it recognizes certain
+ // common transforms, like rotating and scaling. This only works though if you are using
+ // either one operation, or multiple operations of the same type (i.e. you only used scale
+ // or rotate with the Transform object, or used the same one multiple times). If you mix
+ // operations, like we do above, the DrawImageTransform method will actually use DrawImageMatrix.
+ // With DrawImageTransform, you can't directly modify the underlying matrix, so if that's something
+ // you need to do, then DrawImageMatrix is a better option.
+}
+
+void Board::ButtonDepress(int id)
+{
+ if (id == mDemoButton->mId)
+ {
+ delete mDemoWidget;
+ mDemoWidget = new DemoWidget();
+ mApp->mWidgetManager->AddWidget(mDemoWidget);
+
+ // What, more flags? Yup. Since our little DemoWidget isn't a dialog, when we add it,
+ // it won't change anything about the widgets drawn below it. Which means, unmodified,
+ // mouse clicks could still be passed down to the board (if the click wasn't in the DemoWidget),
+ // the board still updates, still draws, etc. Let's turn off mouse clicks for all widgets below the
+ // DemoWidget. But, let's still allow all widgets below it to update. Note that if we used the form
+ // of the method that only takes one parameter, then it would use mDefaultBelowModalFlagsMod
+ // which we modified in our app. By passing in our own flags though, they're used instead.
+ // Which means the only flag we need to remove from the widgets below it is the allow mouse flag.
+ // We do that by making a temp FlagsMod object, and setting
+ // its mRemoveFlags variable to be ORed with WIDGETFLAGS_ALLOW_MOUSE. Upon calling
+ // the WidgetManager's AddBaseModal method, we then pass in the DemoWidget, and the above flags.
+ // AddBaseModal will then treat this new widget as a modal object, applying any flags we passed in.
+ FlagsMod flags;
+ flags.mRemoveFlags |= WIDGETFLAGS_ALLOW_MOUSE;
+ mApp->mWidgetManager->AddBaseModal(mDemoWidget, flags);
+ }
+ else if (id == mDialogButton->mId)
+ {
+ // With the new 1.2 changes, you can create dialogs very easily. Previously, you had to supply
+ // images in order to skin the dialog and be able to see it in the first place. You also had to
+ // override the SexyAppBase::NewDialog method, otherwise calls to SexyAppBase::DoDialog wouldn't
+ // do anything. Not so anymore. You can rapidly prototype with dialogs even without images.
+ // A default NewDialog implementation now exists, and if a dialog doesn't have an image, it will
+ // be drawn using colored rectangles. So now, to make a little dialog box appear, it's as simple as
+ // the single line of code below. No messy functions to write, no images to create, that's a hassel
+ // when you're starting a new app and don't care about the initial appearance of your UI elements and
+ // just want to start testing gameplay immediately.
+ Dialog* d = mApp->DoDialog(100, true, "Fun Dialog", "Line 1\nLine 2\nLine 3", "Close!", Dialog::BUTTONS_FOOTER);
+
+ // Using the default font, which is a system font, can sometimes cause problems on older OS's, like
+ // Windows 95 or 98, in which printing with it appears to produce blank results. Let's set the font
+ // for the button on the dialog box to be FONT_DEFAULT.
+ d->SetButtonFont(FONT_DEFAULT);
+ }
+ else if (id == mCurtainButton->mId)
+ {
+ mCurtainMode = CURTAIN_CLOSING;
+ mCurtainWidth = 0;
+
+ // Here's some more new stuff. Previously, if you wanted to do something like
+ // a transition after a button is pressed (for example), you had to set a bunch of
+ // variables in your class, check them, and process/draw differently depending on
+ // the transition state. That can be both messy and annoying to do. Why not just
+ // do the logic for the transition right at the site where it has to trigger, in this
+ // case, right when the button is pressed? If you ignore the UpdateApp() call below for
+ // a minute, what the loop looks like is just a simple loop that makes a variable expand
+ // to 1/2 the app width, and then contract back to 0. If you removed the call to UpdateApp,
+ // obviously the program would be stuck in the loop until it completed, making it look like the
+ // whole thing is frozen, and not updating the display. By putting UpdateApp in the while loop,
+ // you enable ALL the other widgets to update, and thus draw, which in turn means we can see
+ // our little curtain transition effect working as expected. You could even use this method
+ // to block while waiting for a dialog/widget to return, but to still allow other widgets
+ // to update/draw in the process. ONE VERY IMPORTANT THING TO NOTE THOUGH:
+ // If you have code like this in your Update methods, be careful, as you can run into some
+ // reentrancy problems. If you place this sort of code in your Update methods, make sure you
+ // protect it (you could just use a simple bool that's true if doing a transition, otherwise false).
+ // Why? Think about it like this: UpdateApp updates ALL widgets, including the one in which the
+ // while loop exists. Thus, when going back into Update for said widget, it will once again get
+ // stuck in the same while loop, which will effectively prevent any drawing from occurring.
+ // Just remember that UpdateApp will update EVERY widget, and so you will want to avoid having
+ // your while loop called more often than it should. Of course, an easy way to avoid all that
+ // is to have your transition code happen elsewhere that isn't updated every frame, like a
+ // button down method.
+ //
+ // What you'll notice is that if the game lost focus, the curtain call still updates, although
+ // the shrinking/expanding rectangle in the middle does not. That is because when focus is lost,
+ // we don't update that part of the app, but this while loop is still running, which means the
+ // curtain effect is still running too.
+ while ((mCurtainMode != CURTAIN_INACTIVE) && mApp->UpdateApp())
+ {
+ if (mCurtainMode == CURTAIN_CLOSING)
+ {
+ mCurtainWidth += 4;
+ if (mCurtainWidth >= mWidth / 2)
+ {
+ mCurtainWidth = mWidth / 2;
+ mCurtainMode = CURTAIN_OPENING;
+ }
+ }
+ else
+ {
+ mCurtainWidth -= 4;
+ if (mCurtainWidth <= 0)
+ {
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+ }
+ }
+
+ }
+
+ }
+}
diff --git a/osframework/source/demos/V12Demo/.#Board.cpp.1.8 b/osframework/source/demos/V12Demo/.#Board.cpp.1.8
new file mode 100644
index 0000000..a38318b
--- /dev/null
+++ b/osframework/source/demos/V12Demo/.#Board.cpp.1.8
@@ -0,0 +1,442 @@
+#include "Board.h"
+#include "DemoWidget.h"
+#include "Res.h"
+#include "V12DemoApp.h"
+#include "..\SexyAppFramework\Font.h"
+#include "..\SexyAppFramework\Graphics.h"
+#include "..\SexyAppFramework\ButtonWidget.h"
+#include "..\SexyAppFramework\WidgetManager.h"
+#include "..\SexyAppFramework\Dialog.h"
+#include "..\SexyAppFramework\Flags.h"
+#include "..\SexyAppFramework\SexyMatrix.h"
+#include "..\SexyAppFramework\trivertex.h"
+
+using namespace Sexy;
+
+Board::Board(V12DemoApp* theApp)
+{
+ mApp = theApp;
+
+
+ // Remeber the flag explanation in the 1.2 doc and V12Demo.cpp? Sure you do.
+ // This is basically another use of it. All widgets by default have the following
+ // flags set:
+ // WIDGETFLAGS_UPDATE - The widget gets its Update and UpdateF methods called
+ // WIDGETFLAGS_DRAW - The widget is allowed to draw
+ // WIDGETFLAGS_CLIP - Set to clip Graphics passed into Draw to the widget's bounds
+ // WIDGETFLAGS_ALLOW_MOUSE - Set to allow mouse interaction
+ // WIDGETFLAGS_ALLOW_FOCUS - Set to allow focus to be maintained
+ //
+ // Previously, if you wanted to mark the widget dirty every frame (and thus draw every
+ // frame), you had to call MarkDirty() all the time. Instead of doing that, we can just
+ // use the flag system. By ORing WIDGETFLAGS_MARK_DIRTY with mWidgetFlagsMod.mAddFlags,
+ // when we are added to the widget manager, the manager will then know that we want to
+ // be marked dirty every frame automatically, instead of manually calling MarkDirty().
+ // Yes, I know, that's not a huge deal, but as you can see from the other flags,
+ // it's now easy to set/unset various flags for various widgets and..various reasons.
+ // If you wanted to remove flags set by default for this widget, you'd just OR the
+ // flags to remove with mWidgetFlagsMod.mRemoveFlags. You can affect ALL widgets if you
+ // want to set up widget defaults, by modifying mApp->mWidgetManager's mWidgetFlags
+ // structure in a similar way.
+
+ mWidgetFlagsMod.mAddFlags |= WIDGETFLAGS_MARK_DIRTY;
+
+ // Previously, it was annoying trying to place widgets on some sort of parent widget,
+ // since there was no notion of parent/child relationship. What you had to do was
+ // override the AddedToManager and RemovedFromManager functions, create and add your
+ // widgets or remove and nuke them, and in the case of AddedToManager, you also had
+ // to then place the widget using global coordinates that had no relation to the coordinates
+ // you set the parent widget at. Not anymore. What we can do now is to dispense with
+ // overriding those methods altogether! So now, in the parent's constructor, we can
+ // create our child widgets, resize them, and place them using relative coordinates.
+ // What this also means is that moving the parent widget around results in moving
+ // ALL the child widgets, which means you no longer have to manually move everything
+ // just because the parent moved. In addition, another nice thing is that you no longer
+ // have to remove your child widgets before deleting them: this is handled automatically
+ // for you.
+ mDemoButton = new ButtonWidget(0, this);
+ mDemoButton->mLabel = _S("Demo Widget");
+ mDemoButton->SetFont(FONT_DEFAULT);
+ mDemoButton->Resize(10, 10, 10 + FONT_DEFAULT->StringWidth(mDemoButton->mLabel), 50);
+
+ // VERY IMPORTANT: Notice that we're calling THIS CLASS' (or really, it's parent, WidgetContainer's)
+ // AddWidget method instead of the WidgetManager's method. In order to designate a widget as a child
+ // widget, you have to call the AddWidget method of the class that will be its parent.
+ AddWidget(mDemoButton);
+
+ mDialogButton = new ButtonWidget(1, this);
+ mDialogButton->mLabel = _S("Do Dialog");
+ mDialogButton->SetFont(FONT_DEFAULT);
+ int w = FONT_DEFAULT->StringWidth(mDialogButton->mLabel);
+ mDialogButton->Resize(mApp->mWidth - 20 - w, 10, w + 10, 50);
+ AddWidget(mDialogButton);
+
+ mCurtainButton = new ButtonWidget(2, this);
+ mCurtainButton->mLabel = _S("Do Transition");
+ mCurtainButton->SetFont(FONT_DEFAULT);
+ w = FONT_DEFAULT->StringWidth(mCurtainButton->mLabel);
+ mCurtainButton->Resize(mDemoButton->mX + 20 + mDemoButton->mWidth, 10, w + 10, 50);
+ AddWidget(mCurtainButton);
+
+ mDemoWidget = NULL;
+
+ // Position and set up our pulsing rectangle, as well as the location of the lost focus text.
+ mRect = Rect(mApp->mWidth / 2 - 1, mApp->mHeight / 2 - 1, 2, 2);
+ mExpanding = true;
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+ mLostFocus = false;
+
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+
+ // We'll toggle this between 0 and 2 every second when we are unfocussed
+ mDeferPriority = 0;
+}
+
+Board::~Board()
+{
+ // We need to remove child widgets before deleting them.
+ RemoveAllWidgets();
+
+ delete mDemoButton;
+ delete mDialogButton;
+ delete mCurtainButton;
+
+ if (mDemoWidget != NULL)
+ mApp->mWidgetManager->RemoveWidget(mDemoWidget);
+
+ delete mDemoWidget;
+}
+
+void Board::Update()
+{
+ Widget::Update();
+
+ if (mLostFocus)
+ {
+ if (mUpdateCnt % 100 == 0)
+ {
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+
+ // Every second, we switch between drawing the overlay above or below
+ // the mDemoWidget object (assuming of course you have the widget on screen
+ // when you lose focus).
+ mDeferPriority = mDeferPriority == 0 ? 2 : 0;
+ }
+ }
+ else
+ {
+ // This just makes the rectangle in the middle grow/shrink. Nothing
+ // too crazy.
+ if (mExpanding)
+ {
+ mRect.mWidth += 2;
+ mRect.mHeight += 2;
+
+ if (mRect.mWidth >= mApp->mWidth)
+ {
+ mRect.mWidth = mApp->mWidth;
+ mExpanding = false;
+ }
+
+ if (mRect.mHeight >= mApp->mHeight)
+ {
+ mRect.mHeight = mApp->mHeight;
+ mExpanding = false;
+ }
+ }
+ else
+ {
+ mRect.mWidth -= 2;
+ mRect.mHeight -= 2;
+
+ if (mRect.mHeight <= 0)
+ {
+ mRect.mHeight = 0;
+ mExpanding = true;
+ }
+
+ if (mRect.mWidth <= 0)
+ {
+ mRect.mWidth = 0;
+ mExpanding = true;
+ }
+
+ }
+
+ mRect.mX = mApp->mWidth / 2 - mRect.mWidth / 2;
+ mRect.mY = mApp->mHeight / 2 - mRect.mHeight / 2;
+ }
+}
+
+void Board::Draw(Graphics* g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Draw our pulsing rectangle in the middle of the screen.
+ g->SetColor(Color(255, 0, 0));
+ g->FillRect(mRect);
+
+ if (!mLostFocus)
+ {
+ // Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // In Board::DrawOverlay, you'll see that we can use PushState and PopState to on-demand
+ // save/restore the graphics state. However, if we're either lazy, or after we draw
+ // our current stuff we don't have a need to reset the state and change it again, we
+ // can use the GraphicsAutoState object. This nifty helper class, upon instantiation on
+ // the stack, will automatically push the graphics state of the graphics object you pass in.
+ // Note that since stack variables are
+ // removed (and have their con/destructors called automatically, for classes/structs) when they
+ // go out of scope, the destructor for a GraphicsAutoState object takes care of popping the graphics
+ // state and restoring things to their previous..uh...state.
+ // NOTE: Graphics state is saved between widgets.
+ GraphicsAutoState auto_state(g);
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+ g->SetColor(Color(mUpdateCnt % 128, mUpdateCnt % 255, mUpdateCnt % 64));
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ }
+
+ if (mCurtainMode != CURTAIN_INACTIVE)
+ {
+ g->SetColor(Color(255, 255, 0));
+ g->FillRect(0, 0, mCurtainWidth, mHeight);
+ g->FillRect(mWidth - mCurtainWidth, 0, mCurtainWidth, mHeight);
+ }
+
+ // Instead of using an overlay widget to draw our stuff when focus is lost,
+ // we can just use DeferOverlay. You can ONLY call this in a Draw routine. What happens
+ // when you call DeferOverlay is that it schedules with the WidgetManager a call to
+ // this widget's DrawOverlay method at a later time. You can control the order of the
+ // overlay layer, and place it above or below other widgets by optionally specifying
+ // a defer priority in the call to DeferOverlay. The higher the priority, the more toplevel
+ // and thus the more widgets above it will be drawn. You'll notice that in DemoWidget's constructor,
+ // that we set its priority to 1. Thus, if we DeferOverlay with a value of 0, the overlay will be
+ // drawn BELOW the demo widget, but still above all our child widgets and ourself. When mDeferPriority
+ // is 2, it will be drawn above ALL widgets, including the demo widget, as its priority is only 1, which
+ // last time I checked, is less than 2. Note that widgets by default have priority 0 and dialogs have priority 1.
+ //if (mLostFocus)
+ DeferOverlay(mDeferPriority);
+
+}
+
+void Board::DrawOverlay(Graphics* g)
+{
+ // Make sure you've read through Board::Draw before this guy, as it explains
+ // how and why we get here.
+ g->SetColor(Color(0, 0, 255, 175));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::White);
+ g->DrawString(_S("LOST FOCUS"), mMsgX, mMsgY);
+
+ // PushState is a new addition. Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // With PushState, you save the entire previous state of things. Then, you can make
+ // whatever changes you like, without needing to undo them, as a resulting call to
+ // PopState restores things back to normal. Note that you can push/pop as much as you want.
+ g->PushState();
+
+ // No need to turn this off! When we PopState the previous, non-colorized state,
+ // will return.
+ g->SetColorizeImages(true);
+ g->SetColor(Color(0, 255, 255));
+
+ // MORE NEW STUFF? Yes. Think back to the previous framework version:
+ // how would you draw in real-time, a rotated and scaled image at a given
+ // location? Well, you could mess around with destination Rects for scaling,
+ // but you would have a hard time scaling and rotating all at once. You could
+ // create images in memory to hold the scaled or rotated versions, but that's annoying.
+ // BEHOLD: DrawImageTransform/F. All you have to do is create a Transform object,
+ // and apply various transformations to it, then call DrawImageTransform/F.
+ // Let's take a look:
+ Transform t;
+
+ // Let's rotate the image between 0 and 360 degrees (note that you could also
+ // use the radian version of the function). So far, not hard, right?
+ t.RotateDeg((float)(mUpdateCnt % 360));
+
+ float sw = 1.0f;
+ float sh = 1.0f;
+
+ // Don't get scared here. This is just a little trickery to expand/contract
+ // the image depending on the update count. All it does is expand the image
+ // to normal size for a second, and then shrink it to almost invisible for
+ // another second, which makes that pulse effect happen.
+ int mod = mUpdateCnt % 200;
+ if (mod < 100)
+ {
+ sw = (float)(mod + 1) / 100.0f;
+ sh = (float)(mod + 1) / 100.0f;
+ }
+ else
+ {
+ mod = 200 - mod;
+ sw = (float)mod / 100.0f;
+ sh = (float)mod / 100.0f;
+ }
+
+ // And now we just tell the transform object, t, that we want to scale.
+ // The value for the x and y direction should be a %, so 1.0 means no change in scale.
+ // Let's also mirror and flip the image at the same time too. To mirror and flip, we'll
+ // just multiply sw and sh by -1. Of course, it'll be hard to tell that it's flipped and mirrored
+ // since it's rotating at the same time, so if you don't believe me you can try commenting
+ // out the t.RotateDeg(...) call above and you'll see that it works.
+ t.Scale(-sw, -sh);
+
+ // And now we just pass in our transform object and it works in both 2D and 3D! Note that we can also
+ // draw the image at a given XY as well. We'll make it move rightward depending on the update count.
+ // ******************IMPORTANT NOTE:*********************
+ // DrawImageTransform/F and DrawImageMatrix use the CENTER of the image rather than the top left
+ // for XY drawing. For images of even size, the non-F form of the function will just truncate
+ // the the center, but for the F forms, they will be offset by 0.5f since floating point is used.
+ if (gSexyAppBase->Is3DAccelerated())
+ g->DrawImageTransformF(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+ else
+ g->DrawImageTransform(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+
+ g->PopState();
+
+ // You can now draw using matrices. Why the heck would you want to use matrices? Besides doing some
+ // crazy stuff, you can also do some cool little tricks. For example, previously it used be a pain
+ // to in real-time flip and mirror an image. While I won't give a tutorial on matrix algebra
+ // (that would take a loooooong time), I'll explain the essential parts:
+ SexyTransform2D matrix;
+
+
+ // Multiplying the X coordinate by -1 (which is the 0, 0 element of the matrix) will result in our
+ // image being mirrored, while multiplying the Y coordinate by -1 (1, 1 in the matrix) will result in our
+ // image being flipped.
+ matrix.m[0][0] *= -1;
+ matrix.m[1][1] *= -1;
+ matrix.RotateDeg(45.0f);
+ g->SetFastStretch(true);
+ bool b = g->GetFastStretch();
+
+ // Let's also shear it. While mirroring/flipping could easily be done with the DrawImageTransform methods,
+ // doing more complex matrix manipulation (like shearing) can only be done with the DrawImageMatrix function.
+ matrix.m[0][1] = 2;
+
+ // And then we just make a call to DrawImageMatrix and give it our specified XY coordinates as well,
+ // and that's it! This works in both 2D and 3D modes.
+ g->DrawImageMatrix(IMAGE_HUNGARR_LOGO, matrix, 300, 400);
+
+ // IMPORTANT COMPARISON NOTE:
+ // DrawImageTransform/F will try to use the faster drawing methods if it recognizes certain
+ // common transforms, like rotating and scaling. This only works though if you are using
+ // either one operation, or multiple operations of the same type (i.e. you only used scale
+ // or rotate with the Transform object, or used the same one multiple times). If you mix
+ // operations, like we do above, the DrawImageTransform method will actually use DrawImageMatrix.
+ // With DrawImageTransform, you can't directly modify the underlying matrix, so if that's something
+ // you need to do, then DrawImageMatrix is a better option.
+}
+
+void Board::ButtonDepress(int id)
+{
+ if (id == mDemoButton->mId)
+ {
+ delete mDemoWidget;
+ mDemoWidget = new DemoWidget();
+ mApp->mWidgetManager->AddWidget(mDemoWidget);
+
+ // What, more flags? Yup. Since our little DemoWidget isn't a dialog, when we add it,
+ // it won't change anything about the widgets drawn below it. Which means, unmodified,
+ // mouse clicks could still be passed down to the board (if the click wasn't in the DemoWidget),
+ // the board still updates, still draws, etc. Let's turn off mouse clicks for all widgets below the
+ // DemoWidget. But, let's still allow all widgets below it to update. Note that if we used the form
+ // of the method that only takes one parameter, then it would use mDefaultBelowModalFlagsMod
+ // which we modified in our app. By passing in our own flags though, they're used instead.
+ // Which means the only flag we need to remove from the widgets below it is the allow mouse flag.
+ // We do that by making a temp FlagsMod object, and setting
+ // its mRemoveFlags variable to be ORed with WIDGETFLAGS_ALLOW_MOUSE. Upon calling
+ // the WidgetManager's AddBaseModal method, we then pass in the DemoWidget, and the above flags.
+ // AddBaseModal will then treat this new widget as a modal object, applying any flags we passed in.
+ FlagsMod flags;
+ flags.mRemoveFlags |= WIDGETFLAGS_ALLOW_MOUSE;
+ mApp->mWidgetManager->AddBaseModal(mDemoWidget, flags);
+ }
+ else if (id == mDialogButton->mId)
+ {
+ // With the new 1.2 changes, you can create dialogs very easily. Previously, you had to supply
+ // images in order to skin the dialog and be able to see it in the first place. You also had to
+ // override the SexyAppBase::NewDialog method, otherwise calls to SexyAppBase::DoDialog wouldn't
+ // do anything. Not so anymore. You can rapidly prototype with dialogs even without images.
+ // A default NewDialog implementation now exists, and if a dialog doesn't have an image, it will
+ // be drawn using colored rectangles. So now, to make a little dialog box appear, it's as simple as
+ // the single line of code below. No messy functions to write, no images to create, that's a hassel
+ // when you're starting a new app and don't care about the initial appearance of your UI elements and
+ // just want to start testing gameplay immediately.
+ Dialog* d = mApp->DoDialog(100, true, _S("Fun Dialog"), _S("Line 1\nLine 2\nLine 3"), _S("Close!"), Dialog::BUTTONS_FOOTER);
+
+ // Using the default font, which is a system font, can sometimes cause problems on older OS's, like
+ // Windows 95 or 98, in which printing with it appears to produce blank results. Let's set the font
+ // for the button on the dialog box to be FONT_DEFAULT.
+ d->SetButtonFont(FONT_DEFAULT);
+ }
+ else if (id == mCurtainButton->mId)
+ {
+ mCurtainMode = CURTAIN_CLOSING;
+ mCurtainWidth = 0;
+
+ // Here's some more new stuff. Previously, if you wanted to do something like
+ // a transition after a button is pressed (for example), you had to set a bunch of
+ // variables in your class, check them, and process/draw differently depending on
+ // the transition state. That can be both messy and annoying to do. Why not just
+ // do the logic for the transition right at the site where it has to trigger, in this
+ // case, right when the button is pressed? If you ignore the UpdateApp() call below for
+ // a minute, what the loop looks like is just a simple loop that makes a variable expand
+ // to 1/2 the app width, and then contract back to 0. If you removed the call to UpdateApp,
+ // obviously the program would be stuck in the loop until it completed, making it look like the
+ // whole thing is frozen, and not updating the display. By putting UpdateApp in the while loop,
+ // you enable ALL the other widgets to update, and thus draw, which in turn means we can see
+ // our little curtain transition effect working as expected. You could even use this method
+ // to block while waiting for a dialog/widget to return, but to still allow other widgets
+ // to update/draw in the process. ONE VERY IMPORTANT THING TO NOTE THOUGH:
+ // If you have code like this in your Update methods, be careful, as you can run into some
+ // reentrancy problems. If you place this sort of code in your Update methods, make sure you
+ // protect it (you could just use a simple bool that's true if doing a transition, otherwise false).
+ // Why? Think about it like this: UpdateApp updates ALL widgets, including the one in which the
+ // while loop exists. Thus, when going back into Update for said widget, it will once again get
+ // stuck in the same while loop, which will effectively prevent any drawing from occurring.
+ // Just remember that UpdateApp will update EVERY widget, and so you will want to avoid having
+ // your while loop called more often than it should. Of course, an easy way to avoid all that
+ // is to have your transition code happen elsewhere that isn't updated every frame, like a
+ // button down method.
+ //
+ // What you'll notice is that if the game lost focus, the curtain call still updates, although
+ // the shrinking/expanding rectangle in the middle does not. That is because when focus is lost,
+ // we don't update that part of the app, but this while loop is still running, which means the
+ // curtain effect is still running too.
+ while ((mCurtainMode != CURTAIN_INACTIVE) && mApp->UpdateApp())
+ {
+ if (mCurtainMode == CURTAIN_CLOSING)
+ {
+ mCurtainWidth += 4;
+ if (mCurtainWidth >= mWidth / 2)
+ {
+ mCurtainWidth = mWidth / 2;
+ mCurtainMode = CURTAIN_OPENING;
+ }
+ }
+ else
+ {
+ mCurtainWidth -= 4;
+ if (mCurtainWidth <= 0)
+ {
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+ }
+ }
+
+ }
+
+ }
+}
diff --git a/osframework/source/demos/V12Demo/Board.cpp b/osframework/source/demos/V12Demo/Board.cpp
new file mode 100644
index 0000000..1aa2b1e
--- /dev/null
+++ b/osframework/source/demos/V12Demo/Board.cpp
@@ -0,0 +1,439 @@
+#include "Board.h"
+#include "DemoWidget.h"
+#include "Res.h"
+#include "V12DemoApp.h"
+#include "..\SexyAppFramework\Font.h"
+#include "..\SexyAppFramework\Graphics.h"
+#include "..\SexyAppFramework\ButtonWidget.h"
+#include "..\SexyAppFramework\WidgetManager.h"
+#include "..\SexyAppFramework\Dialog.h"
+#include "..\SexyAppFramework\Flags.h"
+#include "..\SexyAppFramework\SexyMatrix.h"
+#include "..\SexyAppFramework\trivertex.h"
+
+using namespace Sexy;
+
+Board::Board(V12DemoApp* theApp)
+{
+ mApp = theApp;
+
+
+ // Remeber the flag explanation in the 1.2 doc and V12Demo.cpp? Sure you do.
+ // This is basically another use of it. All widgets by default have the following
+ // flags set:
+ // WIDGETFLAGS_UPDATE - The widget gets its Update and UpdateF methods called
+ // WIDGETFLAGS_DRAW - The widget is allowed to draw
+ // WIDGETFLAGS_CLIP - Set to clip Graphics passed into Draw to the widget's bounds
+ // WIDGETFLAGS_ALLOW_MOUSE - Set to allow mouse interaction
+ // WIDGETFLAGS_ALLOW_FOCUS - Set to allow focus to be maintained
+ //
+ // Previously, if you wanted to mark the widget dirty every frame (and thus draw every
+ // frame), you had to call MarkDirty() all the time. Instead of doing that, we can just
+ // use the flag system. By ORing WIDGETFLAGS_MARK_DIRTY with mWidgetFlagsMod.mAddFlags,
+ // when we are added to the widget manager, the manager will then know that we want to
+ // be marked dirty every frame automatically, instead of manually calling MarkDirty().
+ // Yes, I know, that's not a huge deal, but as you can see from the other flags,
+ // it's now easy to set/unset various flags for various widgets and..various reasons.
+ // If you wanted to remove flags set by default for this widget, you'd just OR the
+ // flags to remove with mWidgetFlagsMod.mRemoveFlags. You can affect ALL widgets if you
+ // want to set up widget defaults, by modifying mApp->mWidgetManager's mWidgetFlags
+ // structure in a similar way.
+
+ mWidgetFlagsMod.mAddFlags |= WIDGETFLAGS_MARK_DIRTY;
+
+ // Previously, it was annoying trying to place widgets on some sort of parent widget,
+ // since there was no notion of parent/child relationship. What you had to do was
+ // override the AddedToManager and RemovedFromManager functions, create and add your
+ // widgets or remove and nuke them, and in the case of AddedToManager, you also had
+ // to then place the widget using global coordinates that had no relation to the coordinates
+ // you set the parent widget at. Not anymore. What we can do now is to dispense with
+ // overriding those methods altogether! So now, in the parent's constructor, we can
+ // create our child widgets, resize them, and place them using relative coordinates.
+ // What this also means is that moving the parent widget around results in moving
+ // ALL the child widgets, which means you no longer have to manually move everything
+ // just because the parent moved. In addition, another nice thing is that you no longer
+ // have to remove your child widgets before deleting them: this is handled automatically
+ // for you.
+ mDemoButton = new ButtonWidget(0, this);
+ mDemoButton->mLabel = _S("Demo Widget");
+ mDemoButton->SetFont(FONT_DEFAULT);
+ mDemoButton->Resize(10, 10, 10 + FONT_DEFAULT->StringWidth(mDemoButton->mLabel), 50);
+
+ // VERY IMPORTANT: Notice that we're calling THIS CLASS' (or really, it's parent, WidgetContainer's)
+ // AddWidget method instead of the WidgetManager's method. In order to designate a widget as a child
+ // widget, you have to call the AddWidget method of the class that will be its parent.
+ AddWidget(mDemoButton);
+
+ mDialogButton = new ButtonWidget(1, this);
+ mDialogButton->mLabel = _S("Do Dialog");
+ mDialogButton->SetFont(FONT_DEFAULT);
+ int w = FONT_DEFAULT->StringWidth(mDialogButton->mLabel);
+ mDialogButton->Resize(mApp->mWidth - 20 - w, 10, w + 10, 50);
+ AddWidget(mDialogButton);
+
+ mCurtainButton = new ButtonWidget(2, this);
+ mCurtainButton->mLabel = _S("Do Transition");
+ mCurtainButton->SetFont(FONT_DEFAULT);
+ w = FONT_DEFAULT->StringWidth(mCurtainButton->mLabel);
+ mCurtainButton->Resize(mDemoButton->mX + 20 + mDemoButton->mWidth, 10, w + 10, 50);
+ AddWidget(mCurtainButton);
+
+ mDemoWidget = NULL;
+
+ // Position and set up our pulsing rectangle, as well as the location of the lost focus text.
+ mRect = Rect(mApp->mWidth / 2 - 1, mApp->mHeight / 2 - 1, 2, 2);
+ mExpanding = true;
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+ mLostFocus = false;
+
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+
+ // We'll toggle this between 0 and 2 every second when we are unfocussed
+ mDeferPriority = 0;
+}
+
+Board::~Board()
+{
+ // We need to remove child widgets before deleting them.
+ RemoveAllWidgets();
+
+ delete mDemoButton;
+ delete mDialogButton;
+ delete mCurtainButton;
+
+ if (mDemoWidget != NULL)
+ mApp->mWidgetManager->RemoveWidget(mDemoWidget);
+
+ delete mDemoWidget;
+}
+
+void Board::Update()
+{
+ Widget::Update();
+
+ if (mLostFocus)
+ {
+ if (mUpdateCnt % 100 == 0)
+ {
+ mMsgX = Rand() % (mApp->mWidth - 100);
+ mMsgY = Rand() % (mApp->mHeight - 100);
+
+ // Every second, we switch between drawing the overlay above or below
+ // the mDemoWidget object (assuming of course you have the widget on screen
+ // when you lose focus).
+ mDeferPriority = mDeferPriority == 0 ? 2 : 0;
+ }
+ }
+ else
+ {
+ // This just makes the rectangle in the middle grow/shrink. Nothing
+ // too crazy.
+ if (mExpanding)
+ {
+ mRect.mWidth += 2;
+ mRect.mHeight += 2;
+
+ if (mRect.mWidth >= mApp->mWidth)
+ {
+ mRect.mWidth = mApp->mWidth;
+ mExpanding = false;
+ }
+
+ if (mRect.mHeight >= mApp->mHeight)
+ {
+ mRect.mHeight = mApp->mHeight;
+ mExpanding = false;
+ }
+ }
+ else
+ {
+ mRect.mWidth -= 2;
+ mRect.mHeight -= 2;
+
+ if (mRect.mHeight <= 0)
+ {
+ mRect.mHeight = 0;
+ mExpanding = true;
+ }
+
+ if (mRect.mWidth <= 0)
+ {
+ mRect.mWidth = 0;
+ mExpanding = true;
+ }
+
+ }
+
+ mRect.mX = mApp->mWidth / 2 - mRect.mWidth / 2;
+ mRect.mY = mApp->mHeight / 2 - mRect.mHeight / 2;
+ }
+}
+
+void Board::Draw(Graphics* g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ // Draw our pulsing rectangle in the middle of the screen.
+ g->SetColor(Color(255, 0, 0));
+ g->FillRect(mRect);
+
+ if (!mLostFocus)
+ {
+ // Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // In Board::DrawOverlay, you'll see that we can use PushState and PopState to on-demand
+ // save/restore the graphics state. However, if we're either lazy, or after we draw
+ // our current stuff we don't have a need to reset the state and change it again, we
+ // can use the GraphicsAutoState object. This nifty helper class, upon instantiation on
+ // the stack, will automatically push the graphics state of the graphics object you pass in.
+ // Note that since stack variables are
+ // removed (and have their con/destructors called automatically, for classes/structs) when they
+ // go out of scope, the destructor for a GraphicsAutoState object takes care of popping the graphics
+ // state and restoring things to their previous..uh...state.
+ // NOTE: Graphics state is saved between widgets.
+ GraphicsAutoState auto_state(g);
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ g->SetDrawMode(Graphics::DRAWMODE_ADDITIVE);
+ g->SetColorizeImages(true);
+ g->SetColor(Color(mUpdateCnt % 128, mUpdateCnt % 255, mUpdateCnt % 64));
+ g->DrawImage(IMAGE_HUNGARR_LOGO, 10, 100);
+ }
+
+ if (mCurtainMode != CURTAIN_INACTIVE)
+ {
+ g->SetColor(Color(255, 255, 0));
+ g->FillRect(0, 0, mCurtainWidth, mHeight);
+ g->FillRect(mWidth - mCurtainWidth, 0, mCurtainWidth, mHeight);
+ }
+
+ // Instead of using an overlay widget to draw our stuff when focus is lost,
+ // we can just use DeferOverlay. You can ONLY call this in a Draw routine. What happens
+ // when you call DeferOverlay is that it schedules with the WidgetManager a call to
+ // this widget's DrawOverlay method at a later time. You can control the order of the
+ // overlay layer, and place it above or below other widgets by optionally specifying
+ // a defer priority in the call to DeferOverlay. The higher the priority, the more toplevel
+ // and thus the more widgets above it will be drawn. You'll notice that in DemoWidget's constructor,
+ // that we set its priority to 1. Thus, if we DeferOverlay with a value of 0, the overlay will be
+ // drawn BELOW the demo widget, but still above all our child widgets and ourself. When mDeferPriority
+ // is 2, it will be drawn above ALL widgets, including the demo widget, as its priority is only 1, which
+ // last time I checked, is less than 2. Note that widgets by default have priority 0 and dialogs have priority 1.
+ if (mLostFocus)
+ DeferOverlay(mDeferPriority);
+
+}
+
+void Board::DrawOverlay(Graphics* g)
+{
+ // Make sure you've read through Board::Draw before this guy, as it explains
+ // how and why we get here.
+ g->SetColor(Color(0, 0, 255, 175));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::White);
+ g->DrawString(_S("LOST FOCUS"), mMsgX, mMsgY);
+
+ // PushState is a new addition. Previously, any time you changed the
+ // graphic's state, you had to undo it, otherwise it affected anything
+ // drawn later. Common examples are SetColorizeImages, SetColor, SetDrawMode, etc.
+ // With PushState, you save the entire previous state of things. Then, you can make
+ // whatever changes you like, without needing to undo them, as a resulting call to
+ // PopState restores things back to normal. Note that you can push/pop as much as you want.
+ g->PushState();
+
+ // No need to turn this off! When we PopState the previous, non-colorized state,
+ // will return.
+ g->SetColorizeImages(true);
+ g->SetColor(Color(0, 255, 255));
+
+ // MORE NEW STUFF? Yes. Think back to the previous framework version:
+ // how would you draw in real-time, a rotated and scaled image at a given
+ // location? Well, you could mess around with destination Rects for scaling,
+ // but you would have a hard time scaling and rotating all at once. You could
+ // create images in memory to hold the scaled or rotated versions, but that's annoying.
+ // BEHOLD: DrawImageTransform/F. All you have to do is create a Transform object,
+ // and apply various transformations to it, then call DrawImageTransform/F.
+ // Let's take a look:
+ Transform t;
+
+ // Let's rotate the image between 0 and 360 degrees (note that you could also
+ // use the radian version of the function). So far, not hard, right?
+ t.RotateDeg((float)(mUpdateCnt % 360));
+
+ float sw = 1.0f;
+ float sh = 1.0f;
+
+ // Don't get scared here. This is just a little trickery to expand/contract
+ // the image depending on the update count. All it does is expand the image
+ // to normal size for a second, and then shrink it to almost invisible for
+ // another second, which makes that pulse effect happen.
+ int mod = mUpdateCnt % 200;
+ if (mod < 100)
+ {
+ sw = (float)(mod + 1) / 100.0f;
+ sh = (float)(mod + 1) / 100.0f;
+ }
+ else
+ {
+ mod = 200 - mod;
+ sw = (float)mod / 100.0f;
+ sh = (float)mod / 100.0f;
+ }
+
+ // And now we just tell the transform object, t, that we want to scale.
+ // The value for the x and y direction should be a %, so 1.0 means no change in scale.
+ // Let's also mirror and flip the image at the same time too. To mirror and flip, we'll
+ // just multiply sw and sh by -1. Of course, it'll be hard to tell that it's flipped and mirrored
+ // since it's rotating at the same time, so if you don't believe me you can try commenting
+ // out the t.RotateDeg(...) call above and you'll see that it works.
+ t.Scale(-sw, -sh);
+
+ // And now we just pass in our transform object and it works in both 2D and 3D! Note that we can also
+ // draw the image at a given XY as well. We'll make it move rightward depending on the update count.
+ // ******************IMPORTANT NOTE:*********************
+ // DrawImageTransform/F and DrawImageMatrix use the CENTER of the image rather than the top left
+ // for XY drawing. For images of even size, the non-F form of the function will just truncate
+ // the the center, but for the F forms, they will be offset by 0.5f since floating point is used.
+ if (gSexyAppBase->Is3DAccelerated())
+ g->DrawImageTransformF(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+ else
+ g->DrawImageTransform(IMAGE_HUNGARR_LOGO, t, (float)(mUpdateCnt % (mApp->mWidth + 340)), 200.0f);
+
+ g->PopState();
+
+ // You can now draw using matrices. Why the heck would you want to use matrices? Besides doing some
+ // crazy stuff, you can also do some cool little tricks. For example, previously it used be a pain
+ // to in real-time flip and mirror an image. While I won't give a tutorial on matrix algebra
+ // (that would take a loooooong time), I'll explain the essential parts:
+ SexyTransform2D matrix;
+
+
+ // Multiplying the X coordinate by -1 (which is the 0, 0 element of the matrix) will result in our
+ // image being mirrored, while multiplying the Y coordinate by -1 (1, 1 in the matrix) will result in our
+ // image being flipped.
+ matrix.m[0][0] *= -1;
+ matrix.m[1][1] *= -1;
+
+ // Let's also shear it. While mirroring/flipping could easily be done with the DrawImageTransform methods,
+ // doing more complex matrix manipulation (like shearing) can only be done with the DrawImageMatrix function.
+ matrix.m[0][1] = 2;
+
+ // And then we just make a call to DrawImageMatrix and give it our specified XY coordinates as well,
+ // and that's it! This works in both 2D and 3D modes.
+ g->DrawImageMatrix(IMAGE_HUNGARR_LOGO, matrix, 300, 400);
+
+ // IMPORTANT COMPARISON NOTE:
+ // DrawImageTransform/F will try to use the faster drawing methods if it recognizes certain
+ // common transforms, like rotating and scaling. This only works though if you are using
+ // either one operation, or multiple operations of the same type (i.e. you only used scale
+ // or rotate with the Transform object, or used the same one multiple times). If you mix
+ // operations, like we do above, the DrawImageTransform method will actually use DrawImageMatrix.
+ // With DrawImageTransform, you can't directly modify the underlying matrix, so if that's something
+ // you need to do, then DrawImageMatrix is a better option.
+}
+
+void Board::ButtonDepress(int id)
+{
+ if (id == mDemoButton->mId)
+ {
+ delete mDemoWidget;
+ mDemoWidget = new DemoWidget();
+ mApp->mWidgetManager->AddWidget(mDemoWidget);
+
+ // What, more flags? Yup. Since our little DemoWidget isn't a dialog, when we add it,
+ // it won't change anything about the widgets drawn below it. Which means, unmodified,
+ // mouse clicks could still be passed down to the board (if the click wasn't in the DemoWidget),
+ // the board still updates, still draws, etc. Let's turn off mouse clicks for all widgets below the
+ // DemoWidget. But, let's still allow all widgets below it to update. Note that if we used the form
+ // of the method that only takes one parameter, then it would use mDefaultBelowModalFlagsMod
+ // which we modified in our app. By passing in our own flags though, they're used instead.
+ // Which means the only flag we need to remove from the widgets below it is the allow mouse flag.
+ // We do that by making a temp FlagsMod object, and setting
+ // its mRemoveFlags variable to be ORed with WIDGETFLAGS_ALLOW_MOUSE. Upon calling
+ // the WidgetManager's AddBaseModal method, we then pass in the DemoWidget, and the above flags.
+ // AddBaseModal will then treat this new widget as a modal object, applying any flags we passed in.
+ FlagsMod flags;
+ flags.mRemoveFlags |= WIDGETFLAGS_ALLOW_MOUSE;
+ mApp->mWidgetManager->AddBaseModal(mDemoWidget, flags);
+ }
+ else if (id == mDialogButton->mId)
+ {
+ // With the new 1.2 changes, you can create dialogs very easily. Previously, you had to supply
+ // images in order to skin the dialog and be able to see it in the first place. You also had to
+ // override the SexyAppBase::NewDialog method, otherwise calls to SexyAppBase::DoDialog wouldn't
+ // do anything. Not so anymore. You can rapidly prototype with dialogs even without images.
+ // A default NewDialog implementation now exists, and if a dialog doesn't have an image, it will
+ // be drawn using colored rectangles. So now, to make a little dialog box appear, it's as simple as
+ // the single line of code below. No messy functions to write, no images to create, that's a hassel
+ // when you're starting a new app and don't care about the initial appearance of your UI elements and
+ // just want to start testing gameplay immediately.
+ Dialog* d = mApp->DoDialog(100, true, _S("Fun Dialog"), _S("Line 1\nLine 2\nLine 3"), _S("Close!"), Dialog::BUTTONS_FOOTER);
+
+ // Using the default font, which is a system font, can sometimes cause problems on older OS's, like
+ // Windows 95 or 98, in which printing with it appears to produce blank results. Let's set the font
+ // for the button on the dialog box to be FONT_DEFAULT.
+ d->SetButtonFont(FONT_DEFAULT);
+ }
+ else if (id == mCurtainButton->mId)
+ {
+ mCurtainMode = CURTAIN_CLOSING;
+ mCurtainWidth = 0;
+
+ // Here's some more new stuff. Previously, if you wanted to do something like
+ // a transition after a button is pressed (for example), you had to set a bunch of
+ // variables in your class, check them, and process/draw differently depending on
+ // the transition state. That can be both messy and annoying to do. Why not just
+ // do the logic for the transition right at the site where it has to trigger, in this
+ // case, right when the button is pressed? If you ignore the UpdateApp() call below for
+ // a minute, what the loop looks like is just a simple loop that makes a variable expand
+ // to 1/2 the app width, and then contract back to 0. If you removed the call to UpdateApp,
+ // obviously the program would be stuck in the loop until it completed, making it look like the
+ // whole thing is frozen, and not updating the display. By putting UpdateApp in the while loop,
+ // you enable ALL the other widgets to update, and thus draw, which in turn means we can see
+ // our little curtain transition effect working as expected. You could even use this method
+ // to block while waiting for a dialog/widget to return, but to still allow other widgets
+ // to update/draw in the process. ONE VERY IMPORTANT THING TO NOTE THOUGH:
+ // If you have code like this in your Update methods, be careful, as you can run into some
+ // reentrancy problems. If you place this sort of code in your Update methods, make sure you
+ // protect it (you could just use a simple bool that's true if doing a transition, otherwise false).
+ // Why? Think about it like this: UpdateApp updates ALL widgets, including the one in which the
+ // while loop exists. Thus, when going back into Update for said widget, it will once again get
+ // stuck in the same while loop, which will effectively prevent any drawing from occurring.
+ // Just remember that UpdateApp will update EVERY widget, and so you will want to avoid having
+ // your while loop called more often than it should. Of course, an easy way to avoid all that
+ // is to have your transition code happen elsewhere that isn't updated every frame, like a
+ // button down method.
+ //
+ // What you'll notice is that if the game lost focus, the curtain call still updates, although
+ // the shrinking/expanding rectangle in the middle does not. That is because when focus is lost,
+ // we don't update that part of the app, but this while loop is still running, which means the
+ // curtain effect is still running too.
+ while ((mCurtainMode != CURTAIN_INACTIVE) && mApp->UpdateApp())
+ {
+ if (mCurtainMode == CURTAIN_CLOSING)
+ {
+ mCurtainWidth += 4;
+ if (mCurtainWidth >= mWidth / 2)
+ {
+ mCurtainWidth = mWidth / 2;
+ mCurtainMode = CURTAIN_OPENING;
+ }
+ }
+ else
+ {
+ mCurtainWidth -= 4;
+ if (mCurtainWidth <= 0)
+ {
+ mCurtainWidth = 0;
+ mCurtainMode = CURTAIN_INACTIVE;
+ }
+ }
+
+ }
+
+ }
+}
diff --git a/osframework/source/demos/V12Demo/Board.h b/osframework/source/demos/V12Demo/Board.h
new file mode 100644
index 0000000..f14f1db
--- /dev/null
+++ b/osframework/source/demos/V12Demo/Board.h
@@ -0,0 +1,87 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include "..\SexyAppFramework\Widget.h"
+#include "..\SexyAppFramework\ButtonListener.h"
+#include "..\SexyAppFramework\Rect.h"
+
+namespace Sexy
+{
+
+class V12DemoApp;
+class DemoWidget;
+class ButtonWidget;
+
+class Board : public Widget, public ButtonListener
+{
+
+public:
+
+ V12DemoApp* mApp;
+
+private:
+
+ // We're going to do a curtain open/close effect when the mCurtainButton button is pressed.
+ enum
+ {
+ CURTAIN_CLOSING,
+ CURTAIN_OPENING,
+ CURTAIN_INACTIVE
+ };
+
+ DemoWidget* mDemoWidget;
+ ButtonWidget* mDemoButton; // Creates our DemoWidget
+ ButtonWidget* mDialogButton; // Creates a little dialog box
+ ButtonWidget* mCurtainButton; // Initiates the curtain closing/opening transition
+ Rect mRect; // A rectangle that gets larger/smaller over time
+
+ bool mExpanding; // Is the above (mRect) rectangle shrinking or growing?
+ bool mLostFocus; // If true, the app has lost focus, so we'll draw our overlay
+
+ int mCurtainMode; // One of the above enums
+ int mCurtainWidth; // How wide the curtain is. This ranges from 0 to app width / 2.
+ int mDeferPriority; // See the .cpp for full info, but we'll be toggling the overlay priority every second
+ int mMsgX, mMsgY; // For no valid reason, we'll move the "LOST FOCUS" text every second.
+
+public:
+
+ Board(V12DemoApp* theApp);
+ virtual ~Board();
+
+ void Update();
+ void Draw(Graphics* g);
+ void ButtonDepress(int id);
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DrawOverlay
+ // Parameters: g - The graphics object to draw with
+ //
+ // Purpose: Previously, you had to make a separate OverlayWidget object
+ // if you wanted to do a full screen overlay for say a paused state.
+ // That was annoying, since you had to deal with the messiness of ensuring
+ // that it covered all the appropriate widgets, and had to take care when
+ // removing it. Plus, it was a waste to have to make such a minor object
+ // just to draw a layer above other widgets. Enter the DrawOverlay method:
+ // In your main Draw(...) method, whenever you want the overlay to be drawn,
+ // you just make a call to DeferOverlay. You can pass in a priority that indicates
+ // when the overlay is drawn: the default is 0, but the higher the priority, the
+ // more toplevel (and thus the higher above the other widgets) it will be drawn at.
+ // This can be easily used to draw layers above ALL widgets, or to draw layers above
+ // most widgets but still below some sort of other widget, like an options dialog, etc.
+ // Widgets also have an mPriority variable (defaults to 0), which, setting it higher, will
+ // of course affect at which order in the drawing routine it runs at.
+ //
+ // NOTE: This can be used for anything, not just the pause state. You could
+ // easily have an effect that transitions from one level to the next, and
+ // it could be drawn above all the buttons/widgets on screen, rather than
+ // using some sort of overlay widget as well.
+ //////////////////////////////////////////////////////////////////////////
+ void DrawOverlay(Graphics* g);
+
+
+ void SetFocusLost(bool f) {mLostFocus = f; mDeferPriority = 2;}
+};
+
+}
+
+#endif //__BOARD_H__
diff --git a/osframework/source/demos/V12Demo/DemoWidget.cpp b/osframework/source/demos/V12Demo/DemoWidget.cpp
new file mode 100644
index 0000000..c705569
--- /dev/null
+++ b/osframework/source/demos/V12Demo/DemoWidget.cpp
@@ -0,0 +1,101 @@
+#include "DemoWidget.h"
+#include "Res.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ButtonWidget.h"
+#include "V12DemoApp.h"
+
+using namespace Sexy;
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+DemoWidget::DemoWidget()
+{
+
+ // Just for the heck of it, we'll resize ourselves at instantiation time.
+ int w = 200, h = 200;
+ Resize(gSexyAppBase->mWidth / 2 - w / 2, gSexyAppBase->mHeight / 2 - h / 2, w, h);
+
+ // Previously, it was annoying trying to place widgets on some sort of parent widget,
+ // since there was no notion of parent/child relationship. What you had to do was
+ // override the AddedToManager and RemovedFromManager functions, create and add your
+ // widgets or remove and nuke them, and in the case of AddedToManager, you also had
+ // to then place the widget using global coordinates that had no relation to the coordinates
+ // you set the parent widget at. Not anymore. What we can do now is to dispense with
+ // overriding those methods altogether! So now, in the parent's constructor, we can
+ // create our child widgets, resize them, and place them using relative coordinates.
+ // What this also means is that moving the parent widget around results in moving
+ // ALL the child widgets, which means you no longer have to manually move everything
+ // just because the parent moved. In addition, another nice thing is that you no longer
+ // have to remove your child widgets before deleting them: this is handled automatically
+ // for you.
+ mMoveButton = new ButtonWidget(0, this);
+ mMoveButton->mLabel = _S("MOVE");
+ mMoveButton->SetFont(FONT_DEFAULT);
+
+ mCloseButton = new ButtonWidget(1, this);
+ mCloseButton->mLabel = _S("CLOSE");
+ mCloseButton->SetFont(FONT_DEFAULT);
+
+ // VERY IMPORTANT: Notice that we're calling THIS CLASS' (or really, it's parent, WidgetContainer's)
+ // AddWidget method instead of the WidgetManager's method. In order to designate a widget as a child
+ // widget, you have to call the AddWidget method of the class that will be its parent.
+ AddWidget(mMoveButton);
+ AddWidget(mCloseButton);
+
+ mMoveButton->Resize(10, 150, 75, 50);
+ mCloseButton->Resize(115, 150, 75, 50);
+
+ // mPriority determines what..uh..priority...this widget (and thus its children)
+ // draws at when another widget is drawing an overlay (please see Board.cpp
+ // about the overlay stuff if you haven't already, in Board::Draw(...)).
+ // The higher priority widgets get drawn ABOVE (and thus AFTER) widgets
+ // with a lower priority. Thus, by changing the priority of a widget,
+ // you could enforce that it's always drawn above any overlay layer,
+ // or you could do just the opposite. We'll
+ // set it to 1, since in our Board::Draw method, you'll see that we
+ // toggle between drawing the overlay above and below this widget.
+ // Note that widgets by default have priority 0 and dialogs have priority 1.
+ mPriority = 1;
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+DemoWidget::~DemoWidget()
+{
+ // We need to remove child widgets before deleting them.
+ RemoveAllWidgets();
+
+ delete mMoveButton;
+ delete mCloseButton;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoWidget::ButtonDepress(int id)
+{
+ if (id == mMoveButton->mId)
+ {
+ // See how easy it is to move widgets now, using the new hierarchy system?
+ // By calling Move (or Resize as well), we also move ALL our child widgets,
+ // preserving their relative positions. Previously, you would have had to
+ // manually move all child widgets yourself.
+ Move(Rand() % (gSexyAppBase->mWidth - mWidth), Rand() % (gSexyAppBase->mHeight - mHeight));
+ }
+ else if (id == mCloseButton->mId)
+ {
+ // We'll remove ourselves when the close button is pressed.
+ gSexyAppBase->mWidgetManager->RemoveWidget(this);
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void DemoWidget::Draw(Graphics* g)
+{
+ g->SetColor(Color(0, 255, 0, 200));
+ g->FillRect(0, 0, mWidth, mHeight);
+
+
+} \ No newline at end of file
diff --git a/osframework/source/demos/V12Demo/DemoWidget.h b/osframework/source/demos/V12Demo/DemoWidget.h
new file mode 100644
index 0000000..0b318ea
--- /dev/null
+++ b/osframework/source/demos/V12Demo/DemoWidget.h
@@ -0,0 +1,38 @@
+#ifndef __DEMO_WIDGET_H__
+#define __DEMO_WIDGET_H__
+
+#include "SexyAppFramework/Widget.h"
+#include "SexyAppFramework/ButtonListener.h"
+
+namespace Sexy
+{
+
+ class ButtonWidget;
+
+ //////////////////////////////////////////////////////////////////////////
+ // Noting new in this header. Check the previous demos if this makes
+ // no sense to you, as it's all covered there. CHECK OUT THE .CPP FILE
+ // THOUGH, there's new stuff there.
+ //////////////////////////////////////////////////////////////////////////
+
+
+ class DemoWidget : public Widget, public ButtonListener
+ {
+
+ private:
+
+ ButtonWidget* mMoveButton;
+ ButtonWidget* mCloseButton;
+
+ public:
+
+ DemoWidget();
+ virtual ~DemoWidget();
+
+ void Draw(Graphics* g);
+ void ButtonDepress(int id);
+ };
+
+}
+
+#endif //__DEMO_WIDGET_H__
diff --git a/osframework/source/demos/V12Demo/V12Demo VS2005 WideString.vcproj b/osframework/source/demos/V12Demo/V12Demo VS2005 WideString.vcproj
new file mode 100644
index 0000000..e20c275
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12Demo VS2005 WideString.vcproj
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="V12Demo"
+ ProjectGUID="{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../V12Demo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/V12Demo.pdb"
+ GenerateMapFile="true"
+ MapFileName="V12Demo.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="true"
+ MapFileName="V12Demo.map"
+ SubSystem="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="DemoWidget.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="V12DemoApp.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="DemoWidget.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="V12DemoApp.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/V12Demo/V12Demo VS2005.vcproj b/osframework/source/demos/V12Demo/V12Demo VS2005.vcproj
new file mode 100644
index 0000000..7494e94
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12Demo VS2005.vcproj
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="V12Demo"
+ ProjectGUID="{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../V12Demo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/V12Demo.pdb"
+ GenerateMapFile="true"
+ MapFileName="V12Demo.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="true"
+ MapFileName="V12Demo.map"
+ SubSystem="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="DemoWidget.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="V12DemoApp.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="DemoWidget.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="V12DemoApp.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/V12Demo/V12Demo WideString.vcproj b/osframework/source/demos/V12Demo/V12Demo WideString.vcproj
new file mode 100644
index 0000000..f44d063
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12Demo WideString.vcproj
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="V12Demo"
+ ProjectGUID="{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../V12Demo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/V12Demo.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="V12Demo.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="2"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ WarningLevel="3"
+ DebugInformationFormat="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="TRUE"
+ MapFileName="V12Demo.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="DemoWidget.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="V12DemoApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="DemoWidget.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="V12DemoApp.h">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/V12Demo/V12Demo.dsp b/osframework/source/demos/V12Demo/V12Demo.dsp
new file mode 100644
index 0000000..9a9491f
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12Demo.dsp
@@ -0,0 +1,141 @@
+# Microsoft Developer Studio Project File - Name="V12Demo" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=V12Demo - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "V12Demo.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "V12Demo.mak" CFG="V12Demo - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "V12Demo - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "V12Demo - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "V12Demo - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "V12Demo___Win32_Release"
+# PROP BASE Intermediate_Dir "V12Demo___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX /Yc /Yu
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\V12Demo.exe"
+
+!ELSEIF "$(CFG)" == "V12Demo - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "V12Demo___Win32_Debug"
+# PROP BASE Intermediate_Dir "V12Demo___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /ZI /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\V12Demo_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "V12Demo - Win32 Release"
+# Name "V12Demo - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DemoWidget.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\V12DemoApp.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DemoWidget.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\V12DemoApp.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/V12Demo/V12Demo.vcproj b/osframework/source/demos/V12Demo/V12Demo.vcproj
new file mode 100644
index 0000000..8919386
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12Demo.vcproj
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="V12Demo"
+ ProjectGUID="{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../V12Demo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/V12Demo.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="V12Demo.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="2"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ WarningLevel="3"
+ DebugInformationFormat="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="TRUE"
+ MapFileName="V12Demo.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="DemoWidget.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="V12DemoApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="DemoWidget.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="V12DemoApp.h">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/V12Demo/V12DemoApp.cpp b/osframework/source/demos/V12Demo/V12DemoApp.cpp
new file mode 100644
index 0000000..8573f05
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12DemoApp.cpp
@@ -0,0 +1,116 @@
+#include "V12DemoApp.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/DDImage.h"
+#include "SexyAppFramework/ResourceManager.h"
+#include "SexyAppFramework/Dialog.h"
+#include "SexyAppFramework/SWTri.h"
+#include "Board.h"
+#include "Res.h"
+
+using namespace Sexy;
+
+V12DemoApp::V12DemoApp()
+{
+ mProdName = "V12Demo";
+ mProductVersion = "1.0";
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+ mRegKey = "PopCap\\SexyAppFramework\\V12Demo";
+
+ mNoSoundNeeded = true;
+ mBoard = NULL;
+
+ // Important: You now need to make this call to enable
+ // DrawImageTransform and DrawImageMatrix to work!
+ // This requirement was added so that people who don't use these functions
+ // can avoid the extra code required to support the functions
+ // (about 400K in exe size, 150K zipped).
+ SWTri_AddAllDrawTriFuncs();
+}
+
+V12DemoApp::~V12DemoApp()
+{
+ delete mBoard;
+}
+
+void V12DemoApp::ShutdownHook()
+{
+ // Notice that we don't have to check for mShutdown and return immediately if it's true.
+ // Also note that we don't have to call our parent class' Shutdown() method. This
+ // ShutdownHook() function is only called once, and only after the parent gets Shutdown
+ // called. It just saves us a few lines of extra checking, and saves some headaches that can
+ // arise when you forget to call a parent class method.
+
+ if (mBoard != NULL)
+ mWidgetManager->RemoveWidget(mBoard);
+}
+
+void V12DemoApp::InitHook()
+{
+ // Like the ShutdownHook idea, we no longer need to call the parent class' Init method.
+ // This function only gets called once, and after the parent has finished its Init code.
+ // It just saves us a few lines of extra checking, and saves some headaches that can
+ // arise when you forget to call a parent class method.
+ LoadResourceManifest();
+
+ // We're just going to wind up using the default font from this resource group.
+ // Since there's very little to load, we'll dispense with the whole
+ // title screen loading stuff.
+ if (!mResourceManager->LoadResources("Init"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractInitResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // This is new. Widgets now contain flags that alter the behavior of them.
+ // Please read the document included with the 1.2 release for a full description,
+ // but here's the general rundown:
+ // The WidgetManager's mDefaultBelowModalFlagsMod contains flags that are applied
+ // anytime a dialog box pops up on screen. If we modify these, then we modify the
+ // default behavior for ALL dialog boxes, and don't have to mess around with other
+ // function calls and setting of misc. variables. All flags variables contain 2
+ // sub-variables: mAddFlags and mRemoveFlags. By ORing stuff with mAddFlags, when
+ // a dialog box pops up, the flags in mAddFlags are applied in addition to any
+ // other flags that exist. Similarly, mRemoveFlags contains flags that are removed
+ // from a widget when the dialog pops up. Below, what we're saying is that when
+ // a dialog box pops up, we DO NOT want any widgets beneath it to be able to update.
+ // What'll happen is that any widget below the dialog gets the WIDGETFLAGS_UPDATE
+ // flag removed. This will of course be restored when the dialog box closes.
+ // Again, please see the 1.2 doc for a list of all the flags and a much more
+ // thorough explanation.
+ mWidgetManager->mDefaultBelowModalFlagsMod.mRemoveFlags |= WIDGETFLAGS_UPDATE;
+
+ mBoard = new Board(this);
+ mBoard->Resize(0, 0, mWidth, mHeight);
+ mWidgetManager->AddWidget(mBoard);
+}
+
+void V12DemoApp::LostFocus()
+{
+ if (mBoard)
+ mBoard->SetFocusLost(true);
+}
+
+void V12DemoApp::GotFocus()
+{
+ if (mBoard)
+ mBoard->SetFocusLost(false);
+}
+
+void V12DemoApp::DialogButtonDepress(int dialog_id, int button_id)
+{
+ // See how easy it is now? We only create a dialog with 1 ID in this
+ // demo: ID of 100.
+ // See, all we have to do is check if the dialog id is of the dialog
+ // we're interested in, and if the button id is of the button that
+ // we want to act on.
+ if ((dialog_id == 100) && (button_id == Dialog::ID_OK))
+ KillDialog(100);
+} \ No newline at end of file
diff --git a/osframework/source/demos/V12Demo/V12DemoApp.h b/osframework/source/demos/V12Demo/V12DemoApp.h
new file mode 100644
index 0000000..fb19732
--- /dev/null
+++ b/osframework/source/demos/V12Demo/V12DemoApp.h
@@ -0,0 +1,79 @@
+#ifndef __V12DEMOAPP_H__
+#define __V12DEMOAPP_H__
+
+#include "..\SexyAppFramework\SexyAppBase.h"
+
+namespace Sexy
+{
+
+class Board;
+
+class V12DemoApp : public SexyAppBase
+{
+
+public:
+
+ Board* mBoard;
+
+public:
+
+ V12DemoApp();
+ virtual ~V12DemoApp();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ShutdownHook
+ // Purpose: Instead of overriding Shutdown() and having to remember to
+ // call ::Shutdown(), and to remember to check if mShutdown is true
+ // or not, you can use this and forget about those previous headaches.
+ // Guaranteed to not be called once mShutdown is true so no need to worry
+ // about it occurring multiple times (unless of course for some reason you
+ // manually call it more than once). Thus, you no longer need a ShutdownHook()
+ // override.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void ShutdownHook();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: InitHook
+ // Purpose: This uses the same idea behind ShutdownHook in that you don't
+ // have to worry about calling the base class' Init method anymore
+ // and can forget about those previous hassels. This method is guaranteed
+ // to be called only once, right after SexyAppBase::Init finishes. Thus,
+ // you no longer need an Init() override.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void InitHook();
+
+ //////////////////////////////////////////////////////////////////////////
+ // With these 2 functions, we'll pause the board if focus shifts to another
+ // application.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void LostFocus();
+ virtual void GotFocus();
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: DialogButtonDepress
+ // Parameters:
+ // dialog_id - The ID of the dialog box whose button is emitting
+ // the DialogButtonDepress signal.
+ // button_id - The ID of the button in the above dialog box that
+ // has been depressed.
+ //
+ // Purpose: Previously, dialog button (de)presses were all routed through
+ // a ButtonListener. This was annoying, as to check which button was
+ // pressed, you had to check if the ID of the button was the ID of the
+ // dialog box + 2000 or + 3000. It also had the tendency to create large
+ // Button(De)press functions with giant case statements. With this new
+ // implementation, button (de)presses from a dialog box will be passed
+ // into this alternative method, and the IDs are their simple, original
+ // IDs that you assigned to the widgets upon initialization. For dialog
+ // boxes with a single button, the button's ID is 1, and for dialogs with
+ // 2 buttons, it's 1 for yes/ok and 0 for no/cancel. Of course, this is
+ // fully backwards compatible, so if you don't want to custom override
+ // the DialogButton(De)press method(s) you don't have to, and can still
+ // check which button was pressed using the old original method via the
+ // Button(De)press methods.
+ //////////////////////////////////////////////////////////////////////////
+ virtual void DialogButtonDepress(int dialog_id, int button_id);
+};
+
+}
+#endif //__V12DEMOAPP_H__
diff --git a/osframework/source/demos/V12Demo/main.cpp b/osframework/source/demos/V12Demo/main.cpp
new file mode 100644
index 0000000..a979784
--- /dev/null
+++ b/osframework/source/demos/V12Demo/main.cpp
@@ -0,0 +1,65 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// ***********************************************************************
+// NOTE: You should have read and understood demos 1-5 before
+// this, as topics that are already covered will be either not commented
+// or minimally so. In addition, you REALLY REALLY
+// should have read through the documentation included with the 1.2 release.
+// ***********************************************************************
+//
+// This demo will teach you:
+// * How to use the new InitHook/ShutdownHook for slightly safer/easier
+// init/shutdown procedures
+//
+// * How to use the new DialogListener class, to listen to button events
+// specifically from a dialog (in contrast to using ButtonListener and
+// checking if the button ID is dialog ID + 2000 or 3000).
+//
+// * How to use flags to set the default behavior of a dialog box
+//
+// * How to use flags to modify widget behavior, such as always marking
+// dirty, not allowing mouse events, etc.
+//
+// * How to take advantage of the new widget heirarchy, which lets you
+// very easily add/place widgets within a parent widget with less code
+// and less mess and do some neat things without tons of code.
+//
+// * How to use the new overlay drawing system, which eliminates the need
+// for a widget overlay (like the one in the Hun-garr demo for pausing).
+//
+// * How to easily push/pop/preserve graphics state
+//
+// * How to use the new and powerful Graphics::DrawImageTransform/F to
+// very quickly and easily apply rotation, scaling, translation, or any combo
+// to an image, as opposed to the previous messy way of doing things.
+//
+// * How to use the also new and also cool Graphics::DrawImageMatrix
+// function to draw an image in 2D and/or 3D with a matrix. This allows
+// some neat and fast tricks like easy flipping, mirroring, scaling, etc
+// with a minimal number of lines.
+//
+// * How to use UpdateApp to help with transitions
+//
+// * How to be master of the universe. OK maybe not.
+//////////////////////////////////////////////////////////////////////////
+
+#include "V12DemoApp.h"
+
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+ gHInstance = hInstance;
+
+ V12DemoApp* anApp = new V12DemoApp();
+ anApp->Init();
+ anApp->Start();
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/XMLDemo/Board.cpp b/osframework/source/demos/XMLDemo/Board.cpp
new file mode 100644
index 0000000..e4117e8
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/Board.cpp
@@ -0,0 +1,50 @@
+#include "Board.h"
+#include "XMLDemoApp.h"
+#include "..\SexyAppFramework\Graphics.h"
+#include "Res.h"
+
+using namespace Sexy;
+
+Board::Board(XMLDemoApp* theApp)
+{
+ mApp = theApp;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+Board::~Board()
+{
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Update()
+{
+ Widget::Update();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void Board::Draw(Graphics* g)
+{
+ g->SetColor(Color::Black);
+ g->FillRect(0, 0, mWidth, mHeight);
+
+ g->SetFont(FONT_DEFAULT);
+ g->SetColor(Color::White);
+
+ // Just to verify things, print out the values of everything we cared to read in from demo.xml:
+
+ g->DrawString(StrFormat(_S("Section 1/Item1 text: %s"), mApp->mSection1.mItem1Text.c_str()), 10, 20);
+ g->DrawString(StrFormat(_S("Section 1/BoolParam text: %s"), mApp->mSection1.mBoolParamText.c_str()), 10, 40);
+ g->DrawString(StrFormat(_S("Section 1/BoolParam value: %s"), mApp->mSection1.mBoolParamElement ? _S("true") : _S("false")), 10, 60);
+
+ g->DrawString(StrFormat(_S("Section 2's s2attrib = %s"), mApp->mSection2.mSectionAttribText.c_str()), 10, 90);
+ g->DrawString(StrFormat(_S("Section 2/IntParam text: %s"), mApp->mSection2.mIntParamText.c_str()), 10, 110);
+ g->DrawString(StrFormat(_S("Section 2/IntParam value: %d"), mApp->mSection2.mIntParamElement), 10, 130);
+ g->DrawString(StrFormat(_S("Section 2/MultiAttrib/attrib1 = %s"), mApp->mSection2.mMultiAttrib1.c_str()), 10, 150);
+ g->DrawString(StrFormat(_S("Section 2/MultiAttrib/attrib2 = %s"), mApp->mSection2.mMultiAttrib2.c_str()), 10, 170);
+ g->DrawString(StrFormat(_S("Section 2/MultiAttrib/attrib3 = %s"), mApp->mSection2.mMultiAttrib3.c_str()), 10, 190);
+ g->DrawString(StrFormat(_S("Section 2/Subsection/Item2 value: %s"), mApp->mSection2.mSubsectionItem2.c_str()), 10, 210);
+}
+
diff --git a/osframework/source/demos/XMLDemo/Board.h b/osframework/source/demos/XMLDemo/Board.h
new file mode 100644
index 0000000..16e76bc
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/Board.h
@@ -0,0 +1,29 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include "SexyAppFramework/Widget.h"
+
+namespace Sexy
+{
+
+class XMLDemoApp;
+
+class Board : public Widget
+{
+
+public:
+
+ XMLDemoApp* mApp;
+
+public:
+
+ Board(XMLDemoApp* theApp);
+ virtual ~Board();
+
+ void Update();
+ void Draw(Graphics* g);
+};
+
+}
+
+#endif //__BOARD_H__
diff --git a/osframework/source/demos/XMLDemo/XMLDemo VS2005 WideString.vcproj b/osframework/source/demos/XMLDemo/XMLDemo VS2005 WideString.vcproj
new file mode 100644
index 0000000..7c7339d
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemo VS2005 WideString.vcproj
@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="XMLDemo"
+ ProjectGUID="{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../XMLDemo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/XMLDemo.pdb"
+ GenerateMapFile="true"
+ MapFileName="XMLDemo.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="true"
+ MapFileName="XMLDemo.map"
+ SubSystem="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="XMLDemoApp.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="XMLDemoApp.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/XMLDemo/XMLDemo VS2005.vcproj b/osframework/source/demos/XMLDemo/XMLDemo VS2005.vcproj
new file mode 100644
index 0000000..7f888ac
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemo VS2005.vcproj
@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="XMLDemo"
+ ProjectGUID="{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="DebugVS2005"
+ IntermediateDirectory="DebugVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../XMLDemo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/XMLDemo.pdb"
+ GenerateMapFile="true"
+ MapFileName="XMLDemo.map"
+ MapExports="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="ReleaseVS2005"
+ IntermediateDirectory="ReleaseVS2005"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/wd4996"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="1"
+ OmitFramePointers="false"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="true"
+ MapFileName="XMLDemo.map"
+ SubSystem="2"
+ LinkTimeCodeGeneration="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath="Board.cpp"
+ >
+ </File>
+ <File
+ RelativePath="main.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.cpp"
+ >
+ </File>
+ <File
+ RelativePath="XMLDemoApp.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <File
+ RelativePath="Board.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Res.h"
+ >
+ </File>
+ <File
+ RelativePath="XMLDemoApp.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/XMLDemo/XMLDemo WideString.vcproj b/osframework/source/demos/XMLDemo/XMLDemo WideString.vcproj
new file mode 100644
index 0000000..f47318f
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemo WideString.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="XMLDemo"
+ ProjectGUID="{6A242898-B1D4-4EEA-AE61-AF1002462917}">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_WIDE_STRING"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../XMLDemo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/XMLDemo.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="XMLDemo.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="2"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_WIDE_STRING"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ WarningLevel="3"
+ DebugInformationFormat="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="TRUE"
+ MapFileName="XMLDemo.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="XMLDemoApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="XMLDemoApp.h">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/XMLDemo/XMLDemo.dsp b/osframework/source/demos/XMLDemo/XMLDemo.dsp
new file mode 100644
index 0000000..ae9aec5
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemo.dsp
@@ -0,0 +1,133 @@
+# Microsoft Developer Studio Project File - Name="XMLDemo" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=XMLDemo - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "XMLDemo.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "XMLDemo.mak" CFG="XMLDemo - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "XMLDemo - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "XMLDemo - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "XMLDemo - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "XMLDemo___Win32_Release"
+# PROP BASE Intermediate_Dir "XMLDemo___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I ".." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /machine:I386 /out:"..\XMLDemo.exe"
+
+!ELSEIF "$(CFG)" == "XMLDemo - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "XMLDemo___Win32_Debug"
+# PROP BASE Intermediate_Dir "XMLDemo___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /GR /GX /ZI /Od /I ".." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX /Yc /Yu
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 winmm.lib wsock32.lib gdi32.lib advapi32.lib shell32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\XMLDemo_debug.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "XMLDemo - Win32 Release"
+# Name "XMLDemo - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Board.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLDemoApp.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Board.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Res.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLDemoApp.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/osframework/source/demos/XMLDemo/XMLDemo.vcproj b/osframework/source/demos/XMLDemo/XMLDemo.vcproj
new file mode 100644
index 0000000..0e265fd
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemo.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="XMLDemo"
+ ProjectGUID="{6A242898-B1D4-4EEA-AE61-AF1002462917}">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="FALSE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ ForceConformanceInForLoopScope="TRUE"
+ RuntimeTypeInfo="TRUE"
+ BrowseInformation="1"
+ BrowseInformationFile="$(IntDir)/"
+ WarningLevel="3"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../XMLDemo_debug.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/XMLDemo.pdb"
+ GenerateMapFile="TRUE"
+ MapFileName="XMLDemo.map"
+ MapExports="TRUE"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ FavorSizeOrSpeed="2"
+ OmitFramePointers="FALSE"
+ AdditionalIncludeDirectories="..\;..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ StringPooling="TRUE"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="TRUE"
+ WarningLevel="3"
+ DebugInformationFormat="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib wsock32.lib"
+ OutputFile="$(OutDir)/../../$(ProjectName).exe"
+ GenerateMapFile="TRUE"
+ MapFileName="XMLDemo.map"
+ MapLines="TRUE"
+ SubSystem="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath="Board.cpp">
+ </File>
+ <File
+ RelativePath="..\Res.cpp">
+ </File>
+ <File
+ RelativePath="XMLDemoApp.cpp">
+ </File>
+ <File
+ RelativePath="main.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath="Board.h">
+ </File>
+ <File
+ RelativePath="..\Res.h">
+ </File>
+ <File
+ RelativePath="XMLDemoApp.h">
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/osframework/source/demos/XMLDemo/XMLDemoApp.cpp b/osframework/source/demos/XMLDemo/XMLDemoApp.cpp
new file mode 100644
index 0000000..705f34f
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemoApp.cpp
@@ -0,0 +1,217 @@
+#include "XMLDemoApp.h"
+#include "SexyAppFramework/WidgetManager.h"
+#include "SexyAppFramework/ResourceManager.h"
+#include "SexyAppFramework/XMLParser.h"
+#include "Board.h"
+#include "Res.h"
+
+using namespace Sexy;
+
+XMLDemoApp::XMLDemoApp()
+{
+ mProdName = "XMLDemo";
+ mProductVersion = "1.0";
+ mTitle = StringToSexyStringFast("SexyAppFramework: " + mProdName + " - " + mProductVersion);
+ mRegKey = "PopCap\\SexyAppFramework\\XMLDemo";
+
+ mBoard = NULL;
+ mParser = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+XMLDemoApp::~XMLDemoApp()
+{
+ delete mBoard;
+ delete mParser;
+ mResourceManager->DeleteResources("");
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void XMLDemoApp::ShutdownHook()
+{
+ if (mBoard != NULL)
+ mWidgetManager->RemoveWidget(mBoard);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+void XMLDemoApp::InitHook()
+{
+ LoadResourceManifest();
+
+ // We're just going to wind up using the default font from this resource group.
+ // Since there's very little to load, we'll dispense with the whole
+ // title screen loading stuff.
+ if (!mResourceManager->LoadResources("Init"))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ if (!ExtractInitResources(mResourceManager))
+ {
+ mLoadingFailed = true;
+ ShowResourceError(true);
+ return;
+ }
+
+ // Create our XML Parser object
+ mParser = new XMLParser();
+
+ // By default, comments are ignored and you won't see them at all once the file is read in.
+ // If you would like to not strip out the comments, you can call the AllowComments method
+ // of the XMLParser class and pass in true. Uncomment the line below to let XML comments
+ // be retained when loading the demo.xml file:
+ // mParser->AllowComments(true);
+
+ // Load in our demo XML file. If an error occurs, it'll return false.
+ if (!mParser->OpenFile("properties/demo.xml"))
+ {
+ mLoadingFailed = true;
+
+ // The parser will set an error string in the event that a problem occurred.
+ // You get this string via a call to GetErrorText().
+ MsgBox(StrFormat("Couldn't open properties/demo.xml. Error returned:\n\"%s\"",
+ mParser->GetErrorText().c_str()), "Error");
+ return;
+ }
+
+ ExtractXMLData();
+
+ mBoard = new Board(this);
+ mBoard->Resize(0, 0, mWidth, mHeight);
+ mWidgetManager->AddWidget(mBoard);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+bool XMLDemoApp::ExtractXMLData()
+{
+ // Everything will revolve around XML elements. We'll create
+ // one on the stack and pass it to the NextElement function below.
+ // The XMLElement class contains information on each element, such as
+ // whether it's a comment, start of a tag, end of a tag, what its
+ // attributes/values are, etc.
+ XMLElement e;
+
+ // We loop until there are no more elements left to process. NextElement
+ // returns false when done.
+ while (mParser->NextElement(&e))
+ {
+ // If you had enabled the option to not strip out comments (by default, comments
+ // are removed when loading an XML file, see line 65 of this file for more info),
+ // the type would be TYPE_COMMENT, the mSection field would be filled in as per usual,
+ // the mValue field would be the comment declaration syntax, !--, and the entire comment
+ // text (even if split across many lines) would be placed in mInstruction. Course, the
+ // default setup for this demo is to ignore comments, so you won't see them at all.
+
+ // TYPE_START denotes the start of a new section.
+ // For every TYPE_START, there will eventually be a corresponding
+ // TYPE_END with a matching mValue. For our current demo, we actually
+ // don't care about the end of a tag.
+ if (e.mType == XMLElement::TYPE_START)
+ {
+ // The type stays as TYPE_START until another item type appears, such as the
+ // end of a section/item, TYPE_ELEMENT is found (see a few paragraphs below),
+ // a comment is found, etc.
+ // In the meantime, the mSection field contains the full name of the current
+ // section.
+ if (e.mSection == _S("Section1"))
+ {
+ // Once inside a section, each item is read in. When an item is read in,
+ // it's tag is placed in the mValue field, and all attributes will be stored
+ // in a map (mAttributes) keyed by the attribute's string name, with a result of
+ // type std::string.
+ if (e.mValue == _S("Item1"))
+ {
+ // At this point, we've read the line from our demo.xml file:
+ // <Item1 text="Some text for Section1/Item1"/>
+ // that is, assuming you didn't change the contents of that file.
+ // As you can see, "Item1" is in the mValue field, and "text" is
+ // the key in our mAttributes map, with "Some text for Section1/Item1" as its value.
+ mSection1.mItem1Text = e.mAttributes[_S("text")];
+ }
+ else if (e.mValue == _S("BoolParam"))
+ {
+ // You'll notice that in demo.xml the line containing this part of the XML code reads:
+ // <BoolParam text="Some text for Section1/BoolParam">true</BoolParam>
+ //
+ // At this point in the processing though, we have only covered this part:
+ // <BoolParam text="Some text for Section1/BoolParam">
+ //
+ // The "true" part will be covered a few paragraphs below where we check for TYPE_ELEMENT.
+ // For now though, we can read in all parameters (in this case, just "text") stored
+ // as part of this item.
+ mSection1.mBoolParamText = e.mAttributes[_S("text")];
+ }
+ }
+ else if (e.mSection == _S("Section2"))
+ {
+ if (e.mValue == _S("IntParam"))
+ mSection2.mIntParamText = e.mAttributes[_S("text")];
+ else if (e.mValue == _S("MultiAttrib"))
+ {
+ // If you check out the demo.xml file, you'll see an entry declared like this:
+ //
+ // <MultiAttrib
+ // attrib1="attrib1"
+ // attrib2="2"
+ // attrib3="woo! attrib3!"
+ // />
+ //
+ // Again, the tag is in mValue, and all attributes are stored as key/value pairs
+ // in the mAttributes map. Note that the whitespace doesn't matter: you could
+ // have declared the above line on just a single line if you wanted to.
+ mSection2.mMultiAttrib1 = e.mAttributes[_S("attrib1")];
+ mSection2.mMultiAttrib2 = e.mAttributes[_S("attrib2")];
+ mSection2.mMultiAttrib3 = e.mAttributes[_S("attrib3")];
+ }
+
+ }
+ else if (e.mValue == _S("Section2"))
+ {
+ // Confused about this part? Don't be: When the very first line of a section
+ // is read in (in this case, it is: <Section2 s2attrib="Section2 attrib text">),
+ // if it doesn't also end on the same line (which in this case it doesn't, we get
+ // the </Section2> a few lines later) then mSection isn't updated and instead, the
+ // section name is stored in mValue. In this case, you'll see that mSection is "".
+ // That's because whitespace is ignored, so it's possible that this isn't a section
+ // and is perhaps just an item like the <MultiAttrib example above, split across several lines.
+ // Since when a line is read in, if it contains any attributes they too are read in,
+ // this is a good time to extract out the "s2attrib" attribute and record it in our mSection2
+ // structure.
+ mSection2.mSectionAttribText = e.mAttributes[_S("s2attrib")];
+ }
+
+ }
+ else if (e.mType == XMLElement::TYPE_ELEMENT)
+ {
+ // For lines of the form:
+ // <BoolParam text="Some text for Section1/BoolParam"> true </BoolParam>
+ // where there is data in between the start/end of the item (in this case, the data is "true"),
+ // the item is considered to be of type TYPE_ELEMENT. An element looks like a section declaration,
+ // except that it just contains a singular data value rather than nested XML syntax. For elements,
+ // the section name is the name of the previous sections + the tag name of the element. So in the
+ // above example, the section name is "Section1/BoolParam" since the previous (parent) section is
+ // "Section1" and the tag is "BoolParam". The data is contained in the mValue field.
+
+ if (e.mSection == _S("Section1/BoolParam"))
+ mSection1.mBoolParamElement = StringToLower(e.mValue) == _S("false") ? false : true;
+ else if (e.mSection == _S("Section2/IntParam"))
+ {
+ // This is just a handy std::string to integer function, that will return a boolean
+ // indicating success or failure. I'm ignoring the return type though in this
+ // particular case as I don't care for this particular example.
+ (void)StringToInt(e.mValue, &mSection2.mIntParamElement);
+ }
+ else if (e.mSection == _S("Section2/Subsection/Item2"))
+ mSection2.mSubsectionItem2 = e.mValue;
+ }
+ }
+
+ return true;
+}
diff --git a/osframework/source/demos/XMLDemo/XMLDemoApp.h b/osframework/source/demos/XMLDemo/XMLDemoApp.h
new file mode 100644
index 0000000..9d0c8d8
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/XMLDemoApp.h
@@ -0,0 +1,83 @@
+#ifndef __XMLDEMOAPP_H__
+#define __XMLDEMOAPP_H__
+
+#include "SexyAppFramework/SexyAppBase.h"
+
+namespace Sexy
+{
+
+class Board;
+
+// This is the new class we're going to be learning about.
+// It'll handle the loading and manipulation of XML files.
+class XMLParser;
+
+// These structs just represent the values from our properties/demo.xml
+// file. In a real game, you'd have your own made up config file format.
+// The names correspond to the attributes/sections from the XML file.
+struct s_Section1
+{
+ SexyString mItem1Text;
+
+ SexyString mBoolParamText;
+ bool mBoolParamElement;
+};
+
+struct s_Section2
+{
+ SexyString mSectionAttribText;
+
+ SexyString mIntParamText;
+ int mIntParamElement;
+
+ SexyString mMultiAttrib1;
+ SexyString mMultiAttrib2;
+ SexyString mMultiAttrib3;
+
+ SexyString mSubsectionItem2;
+};
+
+class XMLDemoApp : public SexyAppBase
+{
+
+public:
+
+ Board* mBoard;
+ s_Section1 mSection1;
+ s_Section2 mSection2;
+ SexyString mInstructionTag;
+ SexyString mInstruction;
+
+private:
+
+ // With this class, we'll read in our sample XML file, properties/demo.xml
+ XMLParser* mParser;
+
+private:
+
+ //////////////////////////////////////////////////////////////////////////
+ // Function: ExtractXMLData
+ // Parameters: none
+ // Returns: false on error, otherwise true
+ //
+ // Purpose: After opening an XML file via the XMLParser::OpenFile() method,
+ // this function then extracts out the data it needs from the sample XML file.
+ // When complete, mSection1 and mSection2 will have their values initialized.
+ //////////////////////////////////////////////////////////////////////////
+ bool ExtractXMLData();
+
+public:
+
+ XMLDemoApp();
+
+ virtual ~XMLDemoApp();
+
+ virtual void ShutdownHook();
+ virtual void InitHook();
+
+
+
+};
+
+}
+#endif //__XMLDEMOAPP_H__
diff --git a/osframework/source/demos/XMLDemo/main.cpp b/osframework/source/demos/XMLDemo/main.cpp
new file mode 100644
index 0000000..93995d4
--- /dev/null
+++ b/osframework/source/demos/XMLDemo/main.cpp
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// This is the starting point for all new projects. This file's purpose is
+// pretty small, but important. In here we create our application, initialize
+// it, and begin processing all the game code.
+//
+// NOTE: You should have read and understood demos 1 and 2 before
+// this, as topics that are already covered will be either not commented
+// or minimally so. In addition, this demo uses just a couple features from the v.1.2
+// release of the framework, so it is beneficial to have read and understood
+// V12Demo as well. Though, if you fully understand demos 1 and 2, you'll probably
+// be fine enough.
+//
+// This demo will teach you:
+// * How to read in XML files from disk
+// * How to sift through the XML data and extract the information you need
+//////////////////////////////////////////////////////////////////////////
+
+#include "XMLDemoApp.h"
+
+using namespace Sexy;
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+ gHInstance = hInstance;
+
+ XMLDemoApp* anApp = new XMLDemoApp();
+ anApp->Init();
+ anApp->Start();
+ delete anApp;
+
+ return 0;
+}
diff --git a/osframework/source/demos/bass.dll b/osframework/source/demos/bass.dll
new file mode 100644
index 0000000..06c3317
--- /dev/null
+++ b/osframework/source/demos/bass.dll
Binary files differ
diff --git a/osframework/source/demos/demos.txt b/osframework/source/demos/demos.txt
new file mode 100644
index 0000000..c1ed67d
--- /dev/null
+++ b/osframework/source/demos/demos.txt
@@ -0,0 +1,199 @@
+
+ PopCap Games Open Source Framework Demos
+
+ http://developer.popcap.com
+
+ Author: Jeff "Architekt" Weinstein
+
+ These demos are designed to quickly get you up to speed on
+ the most common and powerful features of the PopCap Framework.
+ Start at the first demo and completely read through each
+ .h and .cpp file. The suggested reading order is:
+ main.cpp, GameApp.h/.cpp, Board.h/.cpp and then any newly
+ added files after that. The demos are meant to illustrate some
+ of the most common and powerful features of the framework and
+ will not explain every single detail. However, after having
+ read through and understood each demo, you will be able
+ to figure out and understand the rest of the framework's
+ features.
+ Please note that the included images, sounds, and music
+ are taken from various PopCap games and may not be used
+ for commercial purposes. They are provided as a resource to
+ you to help out with the learning process.
+ If you find any inaccuracies, bugs, or have suggestions
+ for improving the demos, please use the forums on the
+ main website, http://developer.popcap.com
+
+ VERSION HISTORY
+
+ Framework 1.3:
+
+ * Updated all demos to work with the wide string projects.
+ Do not be alarmed by all the _S() macros: they don't do
+ anything in normal apps and are designed for the WideString
+ projects. All std::string's have been replaced with SexyString,
+ which is a typedef that is std::string in non-widestring versions,
+ and std::wstring in widestring versions.
+
+ * Fixed bug in all projects where the SexyAppFramework project was for some
+ reason not marked to build: this meant that you had to manually compile
+ the framework before you compiled all the demos. You should now simply be
+ able to do a Rebuild All without any manual fussing around.
+
+ Framework 1.22:
+
+ * Support for Visual Studio 2005
+ * Fixed some C++ language conformance issues
+ * Fixed some bugs with the flash widget and rendering issues
+ * Got tired of casting warnings, properly casting stuff now
+ * Fixed some demo bugs and bad programming practices
+ * IMPORTANT NEW CHANGE: in order to cut filesize bloat, caused
+ by the addition of the software triangle rasterizer
+ code in 1.21, you now need to do the following IF you
+ use DrawImageMatrix or DrawImageTransform (with a
+ complex transformation) or if you get errors compiling
+ or at run time you get the assert "You need to call
+ SWTri_AddDrawTriFunc or SWTri_AddAllDrawTriFuncs"
+
+ 1. Include "SexyAppFramework/SWTri.h"
+ 2. Call the function SWTri_AddAllDrawTriFuncs()
+ 3. Alternatively to #2, if you know which triangle draw
+ functions you need, you can add them specifically via
+ SWTri_AddDrawTriFunc(...) and specifying which draw
+ function you need (check SWTri.h for a list).
+
+
+ Framework 1.2:
+
+ * Corrected comment about the Popup function not working
+ in fullscreen mode.
+ * Removed call to Shutdown() in LoadingThreadProc (although
+ this is no longer incorrect as of Framework 1.2, it
+ IS incorrect in previous framework versions. For
+ backwards compatibility, it has been changed.)
+ * Removed some incorrect comments about resource manager
+ calling Shutdown
+ * Added new demo, XMLDemo, showing how to use the XMLParser
+ class for most video game XML needs.
+ * Added new demo, V12Demo, showing the new features of
+ Framework 1.2
+ * Updated Demo5::DemoDialog.cpp::ButtonDepress to work with
+ the 1.2 changes, as well as the options dialog in
+ Hun-garr.
+
+ Framework 1.0:
+ Initial release
+
+
+Demo1:
+-------
+* Setting app width/height
+* Drawing primitives
+* Changing colors
+* Loading thread proc
+* Widget basics: Adding, removing, drawing, updating
+
+Demo2:
+------
+* Loading and displaying fonts
+* Loading and displaying images
+* Colorizing images
+* Additive drawing
+* Paletizing images
+* Loading/playing sounds
+
+Demo3:
+------
+* Enabling auto-detect 3D
+* Modifying image bits
+* Stretching images
+* Mirroring/flipping images
+* Animation using image strips
+* Widgets: buttons, listeners, basic events, adding/removing, mouse move/drag/down/up
+
+Demo4:
+------
+* Using the resource manager
+* Title screen with progress bar
+* Loading/playing music
+* Playing sounds with pitch and panning values changed
+* smooth motion with UpdateF
+* Reading/writing to files/registry
+* Getting command line switches
+* Widgets: Hyperlink widget, edit widget, checkbox, list, scrollbars, safedeletewidget
+
+Demo5:
+------
+* Drawing differently if 3D or 2D
+* Using Translate instead of using XYs
+* Keyboard input, setting focus
+* Widgets: Dialog box, sliders, an options dialog box
+* Advanced widget topics: mClip, using Layout_ flags, using images
+* Random numbers
+* Catching memory leaks
+* Profiling
+
+
+Demo6:
+------
+* Game, using topics from above and including:
+* Custom cursors
+
+V12Demo:
+--------
+This demo shows off the new features in the 1.2 release of the framework.
+It builds on the knowledge of demos 1-5 so you MUST have read and understood
+those demos prior to reading this one, as previously covered material
+will either be not commented or minimally so. In addition, you REALLY REALLY
+should have read through the documentation included with the 1.2 release.
+
+
+* How to use the new InitHook/ShutdownHook for slightly safer/easier
+ init/shutdown procedures
+
+* How to use the new DialogListener class, to listen to button events
+ specifically from a dialog (in contrast to using ButtonListener and
+ checking if the button ID is dialog ID + 2000 or 3000).
+
+* How to use flags to set the default behavior of a dialog box
+
+* How to use flags to modify widget behavior, such as always marking
+ dirty, not allowing mouse events, etc.
+
+* How to take advantage of the new widget heirarchy, which lets you
+ very easily add/place widgets within a parent widget with less code
+ and less mess and do some neat things without tons of code.
+
+* How to use the new overlay drawing system, which eliminates the need
+ for a widget overlay (like the one in the Hun-garr demo for pausing).
+
+* How to easily push/pop/preserve graphics state
+
+* How to use the new and powerful Graphics::DrawImageTransform/F to
+ very quickly and easily apply rotation, scaling, translation, or any combo
+ to an image, as opposed to the previous messy way of doing things.
+
+* How to use the also new and also cool Graphics::DrawImageMatrix
+ function to draw an image in 2D and/or 3D with a matrix. This allows
+ some neat and fast tricks like easy flipping, mirroring, scaling, etc
+ with a minimal number of lines.
+
+* How to use UpdateApp to help with transitions
+
+* How to be master of the universe. OK maybe not.
+
+
+XMLDemo:
+--------
+* How to use the XMLParser class to read in XML files
+* How to sift through the XML data and extract the information you need
+
+NOTE: You should have read and understood demos 1 and 2 before
+this, as topics that are already covered will be either not commented
+or minimally so. In addition, this demo uses just a couple features from the v.1.2
+release of the framework, so it is beneficial to have read and understood
+V12Demo as well. Though, if you fully understand demos 1 and 2, you'll probably
+be fine enough.
+
+
+
diff --git a/osframework/source/demos/fonts/ArmorPiercing22.txt b/osframework/source/demos/fonts/ArmorPiercing22.txt
new file mode 100644
index 0000000..a4bfd53
--- /dev/null
+++ b/osframework/source/demos/fonts/ArmorPiercing22.txt
@@ -0,0 +1,67 @@
+Define CharList
+ ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '~', '`',
+ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{',
+ ']', '}', ';', ':',"'", '"', ',', '<', '.', '>', '/', '?');
+
+Define WidthList
+ ( 11, 10, 11, 11, 11, 11, 11, 12, 7, 11, 12, 11, 14, 12, 11, 11,
+ 11, 10, 10, 11, 11, 12, 14, 13, 11, 11, 11, 10, 11, 11, 11, 11,
+ 11, 12, 7, 11, 12, 11, 14, 12, 11, 11, 11, 10, 10, 11, 11, 12,
+ 14, 13, 11, 11, 11, 9, 11, 11, 11, 11, 11, 10, 11, 11, 15, 7,
+ 8, 18, 18, 12, 20, 15, 11, 12, 12, 11, 12, 10, 12, 12, 11, 15,
+ 11, 15, 7, 7, 7, 11, 7, 13, 7, 13, 13, 12);
+
+Define RectList
+ ( ( 0, 0, 10, 32), ( 11, 0, 10, 32), ( 22, 0, 8, 32), ( 31, 0, 9, 32),
+ ( 41, 0, 8, 32), ( 50, 0, 8, 32), ( 59, 0, 8, 32), ( 68, 0, 9, 32),
+ ( 78, 0, 3, 32), ( 82, 0, 8, 32), ( 91, 0, 9, 32), ( 101, 0, 8, 32),
+ ( 110, 0, 14, 32), ( 125, 0, 9, 32), ( 135, 0, 8, 32), ( 144, 0, 9, 32),
+ ( 154, 0, 8, 32), ( 163, 0, 10, 32), ( 174, 0, 9, 32), ( 184, 0, 7, 32),
+ ( 192, 0, 8, 32), ( 201, 0, 10, 32), ( 212, 0, 14, 32), ( 227, 0, 10, 32),
+ ( 238, 0, 8, 32), ( 247, 0, 8, 32), ( 256, 0, 10, 32), ( 267, 0, 10, 32),
+ ( 278, 0, 8, 32), ( 287, 0, 9, 32), ( 297, 0, 8, 32), ( 306, 0, 8, 32),
+ ( 315, 0, 8, 32), ( 324, 0, 9, 32), ( 334, 0, 3, 32), ( 338, 0, 8, 32),
+ ( 347, 0, 9, 32), ( 357, 0, 8, 32), ( 366, 0, 14, 32), ( 381, 0, 9, 32),
+ ( 391, 0, 8, 32), ( 400, 0, 9, 32), ( 410, 0, 8, 32), ( 419, 0, 10, 32),
+ ( 430, 0, 9, 32), ( 440, 0, 7, 32), ( 448, 0, 8, 32), ( 457, 0, 10, 32),
+ ( 468, 0, 14, 32), ( 483, 0, 10, 32), ( 494, 0, 8, 32), ( 503, 0, 8, 32),
+ ( 512, 0, 8, 32), ( 521, 0, 5, 32), ( 527, 0, 8, 32), ( 536, 0, 8, 32),
+ ( 545, 0, 8, 32), ( 554, 0, 8, 32), ( 563, 0, 9, 32), ( 573, 0, 10, 32),
+ ( 584, 0, 8, 32), ( 593, 0, 9, 32), ( 603, 0, 12, 32), ( 616, 0, 4, 32),
+ ( 621, 0, 5, 32), ( 627, 0, 18, 32), ( 646, 0, 15, 32), ( 662, 0, 8, 32),
+ ( 671, 0, 17, 32), ( 689, 0, 12, 32), ( 702, 0, 7, 32), ( 710, 0, 11, 32),
+ ( 722, 0, 8, 32), ( 731, 0, 7, 32), ( 739, 0, 9, 32), ( 749, 0, 10, 32),
+ ( 760, 0, 9, 32), ( 770, 0, 9, 32), ( 780, 0, 8, 32), ( 789, 0, 12, 32),
+ ( 802, 0, 8, 32), ( 811, 0, 12, 32), ( 824, 0, 3, 32), ( 828, 0, 3, 32),
+ ( 832, 0, 3, 32), ( 836, 0, 8, 32), ( 845, 0, 3, 32), ( 849, 0, 11, 32),
+ ( 861, 0, 3, 32), ( 865, 0, 12, 32), ( 878, 0, 10, 32), ( 889, 0, 9, 32));
+
+Define OffsetList
+ ( ( 0, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), (-1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), (-1, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0), (-1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 0, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), (-1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), (-1, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ (-1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), ( 0, 0), ( 1, 0), ( 0, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 0, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), ( 0, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 0, 0), ( 1, 0), ( 1, 0));
+
+CreateLayer Main;
+LayerSetImage Main 'ArmorPiercing22';
+LayerSetAscent Main 32;
+LayerSetCharWidths Main CharList WidthList;
+LayerSetCharWidths Main (' ') (7);
+LayerSetImageMap Main CharList RectList;
+LayerSetCharOffsets Main CharList OffsetList;
+LayerSetAscentPadding Main 0;
+LayerSetLineSpacingOffset Main 0;
+LayerSetPointSize Main 22;
+
+SetDefaultPointSize 22;
diff --git a/osframework/source/demos/fonts/ContinuumBold12.txt b/osframework/source/demos/fonts/ContinuumBold12.txt
new file mode 100644
index 0000000..7712cb5
--- /dev/null
+++ b/osframework/source/demos/fonts/ContinuumBold12.txt
@@ -0,0 +1,100 @@
+Define CharList
+ ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '~', '`',
+ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{',
+ ']', '}', ';', ':',"'", '"', ',', '<', '.', '>', '/', '?', '¡', '¢', '£', '¥',
+ '§', '©', '®', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë',
+ 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü',
+ 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í',
+ 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
+
+Define WidthList
+ ( 10, 9, 8, 9, 8, 8, 9, 9, 4, 5, 9, 8, 12, 9, 9, 9,
+ 9, 9, 8, 7, 9, 9, 13, 9, 9, 8, 8, 8, 7, 8, 8, 4,
+ 8, 8, 3, 3, 8, 3, 12, 8, 8, 8, 8, 4, 7, 4, 8, 8,
+ 11, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5,
+ 4, 11, 11, 8, 14, 9, 0, 7, 5, 5, 5, 8, 10, 9, 4, 5,
+ 4, 5, 4, 4, 3, 5, 3, 9, 3, 9, 9, 8, 4, 7, 10, 11,
+ 8, 12, 12, 8, 10, 10, 10, 10, 10, 10, 19, 10, 8, 8, 8, 9,
+ 4, 5, 4, 4, 11, 9, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9,
+ 9, 9, 9, 8, 8, 8, 8, 9, 14, 8, 8, 8, 8, 8, 4, 4,
+ 4, 4, 10, 9, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8);
+
+Define RectList
+ ( ( 0, 0, 10, 19), ( 11, 0, 9, 19), ( 21, 0, 8, 19), ( 30, 0, 9, 19),
+ ( 40, 0, 8, 19), ( 49, 0, 8, 19), ( 58, 0, 9, 19), ( 68, 0, 9, 19),
+ ( 78, 0, 3, 19), ( 82, 0, 5, 19), ( 88, 0, 9, 19), ( 98, 0, 8, 19),
+ ( 107, 0, 12, 19), ( 120, 0, 9, 19), ( 130, 0, 9, 19), ( 140, 0, 9, 19),
+ ( 150, 0, 8, 19), ( 159, 0, 8, 19), ( 168, 0, 8, 19), ( 177, 0, 8, 19),
+ ( 186, 0, 9, 19), ( 196, 0, 10, 19), ( 207, 0, 13, 19), ( 221, 0, 10, 19),
+ ( 232, 0, 10, 19), ( 243, 0, 9, 19), ( 253, 0, 8, 19), ( 262, 0, 8, 19),
+ ( 271, 0, 7, 19), ( 279, 0, 8, 19), ( 288, 0, 8, 19), ( 297, 0, 4, 19),
+ ( 302, 0, 8, 19), ( 311, 0, 8, 19), ( 320, 0, 3, 19), ( 324, 0, 5, 19),
+ ( 330, 0, 8, 19), ( 339, 0, 3, 19), ( 343, 0, 11, 19), ( 355, 0, 8, 19),
+ ( 364, 0, 8, 19), ( 373, 0, 8, 19), ( 382, 0, 8, 19), ( 391, 0, 4, 19),
+ ( 396, 0, 7, 19), ( 404, 0, 4, 19), ( 409, 0, 8, 19), ( 418, 0, 9, 19),
+ ( 428, 0, 11, 19), ( 440, 0, 8, 19), ( 449, 0, 8, 19), ( 458, 0, 8, 19),
+ ( 467, 0, 9, 19), ( 477, 0, 3, 19), ( 481, 0, 8, 19), ( 490, 0, 8, 19),
+ ( 499, 0, 8, 19), ( 508, 0, 7, 19), ( 516, 0, 9, 19), ( 526, 0, 8, 19),
+ ( 535, 0, 9, 19), ( 545, 0, 9, 19), ( 555, 0, 8, 19), ( 564, 0, 5, 19),
+ ( 570, 0, 3, 19), ( 574, 0, 11, 19), ( 586, 0, 11, 19), ( 598, 0, 8, 19),
+ ( 607, 0, 14, 19), ( 622, 0, 8, 19), ( 631, 0, 10, 19), ( 642, 0, 7, 19),
+ ( 650, 0, 4, 19), ( 655, 0, 4, 19), ( 660, 0, 5, 19), ( 666, 0, 9, 19),
+ ( 676, 0, 10, 19), ( 687, 0, 9, 19), ( 697, 0, 3, 19), ( 701, 0, 5, 19),
+ ( 707, 0, 3, 19), ( 711, 0, 5, 19), ( 717, 0, 4, 19), ( 722, 0, 4, 19),
+ ( 727, 0, 3, 19), ( 731, 0, 5, 19), ( 737, 0, 3, 19), ( 741, 0, 9, 19),
+ ( 751, 0, 3, 19), ( 755, 0, 9, 19), ( 765, 0, 9, 19), ( 775, 0, 8, 19),
+ ( 784, 0, 3, 19), ( 788, 0, 7, 19), ( 796, 0, 10, 19), ( 807, 0, 13, 19),
+ ( 821, 0, 8, 19), ( 830, 0, 12, 19), ( 843, 0, 12, 19), ( 856, 0, 8, 19),
+ ( 865, 0, 10, 19), ( 876, 0, 10, 19), ( 887, 0, 10, 19), ( 898, 0, 10, 19),
+ ( 909, 0, 10, 19), ( 920, 0, 10, 19), ( 931, 0, 21, 19), ( 953, 0, 10, 19),
+ ( 964, 0, 8, 19), ( 973, 0, 8, 19), ( 982, 0, 8, 19), ( 991, 0, 8, 19),
+ (1000, 0, 5, 19), (1006, 0, 5, 19), (1012, 0, 7, 19), (1020, 0, 6, 19),
+ (1027, 0, 11, 19), (1039, 0, 9, 19), (1049, 0, 9, 19), (1059, 0, 9, 19),
+ (1069, 0, 9, 19), (1079, 0, 9, 19), (1089, 0, 9, 19), (1099, 0, 13, 19),
+ (1113, 0, 9, 19), (1123, 0, 9, 19), (1133, 0, 9, 19), (1143, 0, 9, 19),
+ (1153, 0, 10, 19), (1164, 0, 8, 19), (1173, 0, 7, 19), (1181, 0, 8, 19),
+ (1190, 0, 8, 19), (1199, 0, 8, 19), (1208, 0, 8, 19), (1217, 0, 9, 19),
+ (1227, 0, 14, 19), (1242, 0, 9, 19), (1252, 0, 8, 19), (1261, 0, 8, 19),
+ (1270, 0, 8, 19), (1279, 0, 8, 19), (1288, 0, 3, 19), (1292, 0, 5, 19),
+ (1298, 0, 6, 19), (1305, 0, 6, 19), (1312, 0, 9, 19), (1322, 0, 8, 19),
+ (1331, 0, 8, 19), (1340, 0, 8, 19), (1349, 0, 9, 19), (1359, 0, 9, 19),
+ (1369, 0, 8, 19), (1378, 0, 11, 19), (1390, 0, 8, 19), (1399, 0, 8, 19),
+ (1408, 0, 8, 19), (1417, 0, 8, 19), (1426, 0, 8, 19), (1435, 0, 8, 19));
+
+Define OffsetList
+ ( ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 1, 0), ( 1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), (-1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 3, 0), ( 1, 0), ( 1, 0),
+ ( 1, 0), ( 1, 0), ( 0, 0), ( 1, 0), ( 0, 0), ( 0, 0), ( 1, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 1, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), (-1, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), (-1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ (-1, 0), ( 0, 0), (-1, 0), (-1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 1, 0), ( 1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), (-1, 0),
+ (-1, 0), (-1, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0));
+
+CreateLayer Main;
+LayerSetImage Main 'ContinuumBold12';
+LayerSetAscent Main 16;
+LayerSetCharWidths Main CharList WidthList;
+LayerSetCharWidths Main (' ') (9);
+LayerSetImageMap Main CharList RectList;
+LayerSetCharOffsets Main CharList OffsetList;
+LayerSetAscentPadding Main 0;
+LayerSetLineSpacingOffset Main 0;
+LayerSetPointSize Main 12;
+
+SetDefaultPointSize 12;
diff --git a/osframework/source/demos/fonts/Kiloton9.txt b/osframework/source/demos/fonts/Kiloton9.txt
new file mode 100644
index 0000000..531b72d
--- /dev/null
+++ b/osframework/source/demos/fonts/Kiloton9.txt
@@ -0,0 +1,56 @@
+Define CharList
+ ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!',"'",
+ '"', ',', '.', '?');
+
+Define WidthList
+ ( 12, 12, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 6, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 9, 12, 12, 12, 12, 12, 12, 12, 12, 6, 6,
+ 10, 6, 6, 12);
+
+Define RectList
+ ( ( 0, 0, 9, 12), ( 10, 0, 9, 12), ( 20, 0, 9, 12), ( 30, 0, 9, 12),
+ ( 40, 0, 9, 12), ( 50, 0, 9, 12), ( 60, 0, 9, 12), ( 70, 0, 9, 12),
+ ( 80, 0, 3, 12), ( 84, 0, 9, 12), ( 94, 0, 9, 12), ( 104, 0, 9, 12),
+ ( 114, 0, 9, 12), ( 124, 0, 9, 12), ( 134, 0, 9, 12), ( 144, 0, 9, 12),
+ ( 154, 0, 9, 12), ( 164, 0, 9, 12), ( 174, 0, 9, 12), ( 184, 0, 9, 12),
+ ( 194, 0, 9, 12), ( 204, 0, 9, 12), ( 214, 0, 9, 12), ( 224, 0, 9, 12),
+ ( 234, 0, 9, 12), ( 244, 0, 9, 12), ( 254, 0, 9, 12), ( 264, 0, 9, 12),
+ ( 274, 0, 9, 12), ( 284, 0, 9, 12), ( 294, 0, 9, 12), ( 304, 0, 9, 12),
+ ( 314, 0, 9, 12), ( 324, 0, 9, 12), ( 334, 0, 3, 12), ( 338, 0, 9, 12),
+ ( 348, 0, 9, 12), ( 358, 0, 9, 12), ( 368, 0, 9, 12), ( 378, 0, 9, 12),
+ ( 388, 0, 9, 12), ( 398, 0, 9, 12), ( 408, 0, 9, 12), ( 418, 0, 9, 12),
+ ( 428, 0, 9, 12), ( 438, 0, 9, 12), ( 448, 0, 9, 12), ( 458, 0, 9, 12),
+ ( 468, 0, 9, 12), ( 478, 0, 9, 12), ( 488, 0, 9, 12), ( 498, 0, 9, 12),
+ ( 508, 0, 10, 12), ( 519, 0, 6, 12), ( 526, 0, 9, 12), ( 536, 0, 9, 12),
+ ( 546, 0, 9, 12), ( 556, 0, 9, 12), ( 566, 0, 9, 12), ( 576, 0, 9, 12),
+ ( 586, 0, 9, 12), ( 596, 0, 9, 12), ( 606, 0, 3, 12), ( 610, 0, 3, 12),
+ ( 614, 0, 8, 12), ( 623, 0, 3, 12), ( 627, 0, 3, 12), ( 631, 0, 9, 12));
+
+Define OffsetList
+ ( ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0));
+
+CreateLayer Main;
+LayerSetImage Main 'Kiloton9';
+LayerSetAscent Main 10;
+LayerSetCharWidths Main CharList WidthList;
+LayerSetCharWidths Main (' ') (6);
+LayerSetImageMap Main CharList RectList;
+LayerSetCharOffsets Main CharList OffsetList;
+LayerSetAscentPadding Main 0;
+LayerSetLineSpacingOffset Main 0;
+LayerSetPointSize Main 9;
+
+SetDefaultPointSize 9;
diff --git a/osframework/source/demos/fonts/_ArmorPiercing22.png b/osframework/source/demos/fonts/_ArmorPiercing22.png
new file mode 100644
index 0000000..756f4d3
--- /dev/null
+++ b/osframework/source/demos/fonts/_ArmorPiercing22.png
Binary files differ
diff --git a/osframework/source/demos/fonts/_ContinuumBold12.gif b/osframework/source/demos/fonts/_ContinuumBold12.gif
new file mode 100644
index 0000000..41646b7
--- /dev/null
+++ b/osframework/source/demos/fonts/_ContinuumBold12.gif
Binary files differ
diff --git a/osframework/source/demos/fonts/_Kiloton9.png b/osframework/source/demos/fonts/_Kiloton9.png
new file mode 100644
index 0000000..f89d0d4
--- /dev/null
+++ b/osframework/source/demos/fonts/_Kiloton9.png
Binary files differ
diff --git a/osframework/source/demos/fonts/_supernova20.png b/osframework/source/demos/fonts/_supernova20.png
new file mode 100644
index 0000000..258e125
--- /dev/null
+++ b/osframework/source/demos/fonts/_supernova20.png
Binary files differ
diff --git a/osframework/source/demos/fonts/supernova20.txt b/osframework/source/demos/fonts/supernova20.txt
new file mode 100644
index 0000000..34dda36
--- /dev/null
+++ b/osframework/source/demos/fonts/supernova20.txt
@@ -0,0 +1,28 @@
+Define CharList
+ ( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', ',' , ':');
+
+Define WidthList
+ ( 13, 12, 13, 12, 13, 13, 13, 12, 13, 13, 13, 9, 3 , 3);
+
+Define RectList
+ ( ( 0, 0, 12, 28), ( 13, 0, 4, 28), ( 18, 0, 12, 28), ( 31, 0, 12, 28),
+ ( 44, 0, 12, 28), ( 57, 0, 12, 28), ( 70, 0, 12, 28), ( 83, 0, 11, 28),
+ ( 95, 0, 12, 28), ( 108, 0, 12, 28), ( 121, 0, 12, 28), ( 134, 0, 9, 28),
+ ( 144, 0, 3, 28), ( 148, 0, 3, 28));
+
+Define OffsetList
+ ( ( 0, 0), ( 6, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0),
+ ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0), ( 0, 0));
+
+CreateLayer Main;
+LayerSetImage Main 'supernova20';
+LayerSetAscent Main 23;
+LayerSetCharWidths Main CharList WidthList;
+LayerSetCharWidths Main (' ') (8);
+LayerSetImageMap Main CharList RectList;
+LayerSetCharOffsets Main CharList OffsetList;
+LayerSetAscentPadding Main 0;
+LayerSetLineSpacingOffset Main 0;
+LayerSetPointSize Main 20;
+
+SetDefaultPointSize 20;
diff --git a/osframework/source/demos/images/atomicexplosion.jpg b/osframework/source/demos/images/atomicexplosion.jpg
new file mode 100644
index 0000000..28958aa
--- /dev/null
+++ b/osframework/source/demos/images/atomicexplosion.jpg
Binary files differ
diff --git a/osframework/source/demos/images/atomicexplosion_.jpg b/osframework/source/demos/images/atomicexplosion_.jpg
new file mode 100644
index 0000000..7244652
--- /dev/null
+++ b/osframework/source/demos/images/atomicexplosion_.jpg
Binary files differ
diff --git a/osframework/source/demos/images/beam_opaque.jpg b/osframework/source/demos/images/beam_opaque.jpg
new file mode 100644
index 0000000..0af55d2
--- /dev/null
+++ b/osframework/source/demos/images/beam_opaque.jpg
Binary files differ
diff --git a/osframework/source/demos/images/beam_opaque_.gif b/osframework/source/demos/images/beam_opaque_.gif
new file mode 100644
index 0000000..928ebe0
--- /dev/null
+++ b/osframework/source/demos/images/beam_opaque_.gif
Binary files differ
diff --git a/osframework/source/demos/images/bomb_radial_death.jpg b/osframework/source/demos/images/bomb_radial_death.jpg
new file mode 100644
index 0000000..307efc2
--- /dev/null
+++ b/osframework/source/demos/images/bomb_radial_death.jpg
Binary files differ
diff --git a/osframework/source/demos/images/bomb_radial_death_.jpg b/osframework/source/demos/images/bomb_radial_death_.jpg
new file mode 100644
index 0000000..97563d2
--- /dev/null
+++ b/osframework/source/demos/images/bomb_radial_death_.jpg
Binary files differ
diff --git a/osframework/source/demos/images/btn_down.gif b/osframework/source/demos/images/btn_down.gif
new file mode 100644
index 0000000..914ef1c
--- /dev/null
+++ b/osframework/source/demos/images/btn_down.gif
Binary files differ
diff --git a/osframework/source/demos/images/btn_down_.gif b/osframework/source/demos/images/btn_down_.gif
new file mode 100644
index 0000000..af08bb0
--- /dev/null
+++ b/osframework/source/demos/images/btn_down_.gif
Binary files differ
diff --git a/osframework/source/demos/images/btn_over.gif b/osframework/source/demos/images/btn_over.gif
new file mode 100644
index 0000000..914ef1c
--- /dev/null
+++ b/osframework/source/demos/images/btn_over.gif
Binary files differ
diff --git a/osframework/source/demos/images/btn_over_.gif b/osframework/source/demos/images/btn_over_.gif
new file mode 100644
index 0000000..d5ca4e4
--- /dev/null
+++ b/osframework/source/demos/images/btn_over_.gif
Binary files differ
diff --git a/osframework/source/demos/images/btn_up.gif b/osframework/source/demos/images/btn_up.gif
new file mode 100644
index 0000000..914ef1c
--- /dev/null
+++ b/osframework/source/demos/images/btn_up.gif
Binary files differ
diff --git a/osframework/source/demos/images/btn_up_.gif b/osframework/source/demos/images/btn_up_.gif
new file mode 100644
index 0000000..fb59efc
--- /dev/null
+++ b/osframework/source/demos/images/btn_up_.gif
Binary files differ
diff --git a/osframework/source/demos/images/checkbox.gif b/osframework/source/demos/images/checkbox.gif
new file mode 100644
index 0000000..9c21121
--- /dev/null
+++ b/osframework/source/demos/images/checkbox.gif
Binary files differ
diff --git a/osframework/source/demos/images/checkbox_.gif b/osframework/source/demos/images/checkbox_.gif
new file mode 100644
index 0000000..9f10574
--- /dev/null
+++ b/osframework/source/demos/images/checkbox_.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_dragging.gif b/osframework/source/demos/images/custom_dragging.gif
new file mode 100644
index 0000000..9a4e254
--- /dev/null
+++ b/osframework/source/demos/images/custom_dragging.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_dragging_.gif b/osframework/source/demos/images/custom_dragging_.gif
new file mode 100644
index 0000000..a04bbae
--- /dev/null
+++ b/osframework/source/demos/images/custom_dragging_.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_hand.gif b/osframework/source/demos/images/custom_hand.gif
new file mode 100644
index 0000000..e39a2bb
--- /dev/null
+++ b/osframework/source/demos/images/custom_hand.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_hand_.gif b/osframework/source/demos/images/custom_hand_.gif
new file mode 100644
index 0000000..7484613
--- /dev/null
+++ b/osframework/source/demos/images/custom_hand_.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_pointer.gif b/osframework/source/demos/images/custom_pointer.gif
new file mode 100644
index 0000000..c6aaa92
--- /dev/null
+++ b/osframework/source/demos/images/custom_pointer.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_pointer_.gif b/osframework/source/demos/images/custom_pointer_.gif
new file mode 100644
index 0000000..c1caa3e
--- /dev/null
+++ b/osframework/source/demos/images/custom_pointer_.gif
Binary files differ
diff --git a/osframework/source/demos/images/custom_text.gif b/osframework/source/demos/images/custom_text.gif
new file mode 100644
index 0000000..05f6791
--- /dev/null
+++ b/osframework/source/demos/images/custom_text.gif
Binary files differ
diff --git a/osframework/source/demos/images/dialog.gif b/osframework/source/demos/images/dialog.gif
new file mode 100644
index 0000000..ced01fa
--- /dev/null
+++ b/osframework/source/demos/images/dialog.gif
Binary files differ
diff --git a/osframework/source/demos/images/dialog_.gif b/osframework/source/demos/images/dialog_.gif
new file mode 100644
index 0000000..cd24905
--- /dev/null
+++ b/osframework/source/demos/images/dialog_.gif
Binary files differ
diff --git a/osframework/source/demos/images/dialog_btn.gif b/osframework/source/demos/images/dialog_btn.gif
new file mode 100644
index 0000000..6b1ddee
--- /dev/null
+++ b/osframework/source/demos/images/dialog_btn.gif
Binary files differ
diff --git a/osframework/source/demos/images/dialog_btn_.gif b/osframework/source/demos/images/dialog_btn_.gif
new file mode 100644
index 0000000..650a3b6
--- /dev/null
+++ b/osframework/source/demos/images/dialog_btn_.gif
Binary files differ
diff --git a/osframework/source/demos/images/hungarr_logo.jpg b/osframework/source/demos/images/hungarr_logo.jpg
new file mode 100644
index 0000000..7f1f0d2
--- /dev/null
+++ b/osframework/source/demos/images/hungarr_logo.jpg
Binary files differ
diff --git a/osframework/source/demos/images/hungarr_logo_.gif b/osframework/source/demos/images/hungarr_logo_.gif
new file mode 100644
index 0000000..7b40389
--- /dev/null
+++ b/osframework/source/demos/images/hungarr_logo_.gif
Binary files differ
diff --git a/osframework/source/demos/images/layer0.jpg b/osframework/source/demos/images/layer0.jpg
new file mode 100644
index 0000000..a1784ad
--- /dev/null
+++ b/osframework/source/demos/images/layer0.jpg
Binary files differ
diff --git a/osframework/source/demos/images/layer1.png b/osframework/source/demos/images/layer1.png
new file mode 100644
index 0000000..e374608
--- /dev/null
+++ b/osframework/source/demos/images/layer1.png
Binary files differ
diff --git a/osframework/source/demos/images/layer2.png b/osframework/source/demos/images/layer2.png
new file mode 100644
index 0000000..19fd130
--- /dev/null
+++ b/osframework/source/demos/images/layer2.png
Binary files differ
diff --git a/osframework/source/demos/images/lightning.gif b/osframework/source/demos/images/lightning.gif
new file mode 100644
index 0000000..154b857
--- /dev/null
+++ b/osframework/source/demos/images/lightning.gif
Binary files differ
diff --git a/osframework/source/demos/images/lightning_.gif b/osframework/source/demos/images/lightning_.gif
new file mode 100644
index 0000000..acb7388
--- /dev/null
+++ b/osframework/source/demos/images/lightning_.gif
Binary files differ
diff --git a/osframework/source/demos/images/loader_bar.jpg b/osframework/source/demos/images/loader_bar.jpg
new file mode 100644
index 0000000..3a89e06
--- /dev/null
+++ b/osframework/source/demos/images/loader_bar.jpg
Binary files differ
diff --git a/osframework/source/demos/images/loader_loading.gif b/osframework/source/demos/images/loader_loading.gif
new file mode 100644
index 0000000..304c566
--- /dev/null
+++ b/osframework/source/demos/images/loader_loading.gif
Binary files differ
diff --git a/osframework/source/demos/images/loader_loading_.gif b/osframework/source/demos/images/loader_loading_.gif
new file mode 100644
index 0000000..98598fb
--- /dev/null
+++ b/osframework/source/demos/images/loader_loading_.gif
Binary files differ
diff --git a/osframework/source/demos/images/moon.gif b/osframework/source/demos/images/moon.gif
new file mode 100644
index 0000000..cce10f2
--- /dev/null
+++ b/osframework/source/demos/images/moon.gif
Binary files differ
diff --git a/osframework/source/demos/images/moon_.gif b/osframework/source/demos/images/moon_.gif
new file mode 100644
index 0000000..db1678f
--- /dev/null
+++ b/osframework/source/demos/images/moon_.gif
Binary files differ
diff --git a/osframework/source/demos/images/particle_lightning.jpg b/osframework/source/demos/images/particle_lightning.jpg
new file mode 100644
index 0000000..0574001
--- /dev/null
+++ b/osframework/source/demos/images/particle_lightning.jpg
Binary files differ
diff --git a/osframework/source/demos/images/planets_small.jpg b/osframework/source/demos/images/planets_small.jpg
new file mode 100644
index 0000000..012c544
--- /dev/null
+++ b/osframework/source/demos/images/planets_small.jpg
Binary files differ
diff --git a/osframework/source/demos/images/planets_small_.gif b/osframework/source/demos/images/planets_small_.gif
new file mode 100644
index 0000000..113bcee
--- /dev/null
+++ b/osframework/source/demos/images/planets_small_.gif
Binary files differ
diff --git a/osframework/source/demos/images/robotrobot.gif b/osframework/source/demos/images/robotrobot.gif
new file mode 100644
index 0000000..ca67363
--- /dev/null
+++ b/osframework/source/demos/images/robotrobot.gif
Binary files differ
diff --git a/osframework/source/demos/images/slider.gif b/osframework/source/demos/images/slider.gif
new file mode 100644
index 0000000..234000c
--- /dev/null
+++ b/osframework/source/demos/images/slider.gif
Binary files differ
diff --git a/osframework/source/demos/images/slider_thumb.gif b/osframework/source/demos/images/slider_thumb.gif
new file mode 100644
index 0000000..63e5a3b
--- /dev/null
+++ b/osframework/source/demos/images/slider_thumb.gif
Binary files differ
diff --git a/osframework/source/demos/images/spark.jpg b/osframework/source/demos/images/spark.jpg
new file mode 100644
index 0000000..54b2f58
--- /dev/null
+++ b/osframework/source/demos/images/spark.jpg
Binary files differ
diff --git a/osframework/source/demos/images/turbot_worry.gif b/osframework/source/demos/images/turbot_worry.gif
new file mode 100644
index 0000000..d5c0896
--- /dev/null
+++ b/osframework/source/demos/images/turbot_worry.gif
Binary files differ
diff --git a/osframework/source/demos/images/turbot_worry_.gif b/osframework/source/demos/images/turbot_worry_.gif
new file mode 100644
index 0000000..94e548b
--- /dev/null
+++ b/osframework/source/demos/images/turbot_worry_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_baby.JPG b/osframework/source/demos/images/unicron_baby.JPG
new file mode 100644
index 0000000..c694131
--- /dev/null
+++ b/osframework/source/demos/images/unicron_baby.JPG
Binary files differ
diff --git a/osframework/source/demos/images/unicron_baby_.GIF b/osframework/source/demos/images/unicron_baby_.GIF
new file mode 100644
index 0000000..0dc9607
--- /dev/null
+++ b/osframework/source/demos/images/unicron_baby_.GIF
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_down.jpg b/osframework/source/demos/images/unicron_beam_down.jpg
new file mode 100644
index 0000000..5e99e14
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_down.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_down_.gif b/osframework/source/demos/images/unicron_beam_down_.gif
new file mode 100644
index 0000000..256b6ad
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_down_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_left.jpg b/osframework/source/demos/images/unicron_beam_left.jpg
new file mode 100644
index 0000000..2c670cb
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_left.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_left_.gif b/osframework/source/demos/images/unicron_beam_left_.gif
new file mode 100644
index 0000000..f026aef
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_left_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_right.jpg b/osframework/source/demos/images/unicron_beam_right.jpg
new file mode 100644
index 0000000..05464c9
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_right.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_right_.gif b/osframework/source/demos/images/unicron_beam_right_.gif
new file mode 100644
index 0000000..1a96a80
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_right_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_up.jpg b/osframework/source/demos/images/unicron_beam_up.jpg
new file mode 100644
index 0000000..414d2cd
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_up.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_beam_up_.gif b/osframework/source/demos/images/unicron_beam_up_.gif
new file mode 100644
index 0000000..7af08a0
--- /dev/null
+++ b/osframework/source/demos/images/unicron_beam_up_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_horiz.jpg b/osframework/source/demos/images/unicron_horiz.jpg
new file mode 100644
index 0000000..de3ea7a
--- /dev/null
+++ b/osframework/source/demos/images/unicron_horiz.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_horiz_.gif b/osframework/source/demos/images/unicron_horiz_.gif
new file mode 100644
index 0000000..31b80ec
--- /dev/null
+++ b/osframework/source/demos/images/unicron_horiz_.gif
Binary files differ
diff --git a/osframework/source/demos/images/unicron_vert.jpg b/osframework/source/demos/images/unicron_vert.jpg
new file mode 100644
index 0000000..6eb277e
--- /dev/null
+++ b/osframework/source/demos/images/unicron_vert.jpg
Binary files differ
diff --git a/osframework/source/demos/images/unicron_vert_.gif b/osframework/source/demos/images/unicron_vert_.gif
new file mode 100644
index 0000000..6dc3be0
--- /dev/null
+++ b/osframework/source/demos/images/unicron_vert_.gif
Binary files differ
diff --git a/osframework/source/demos/music/hungarr.ogg b/osframework/source/demos/music/hungarr.ogg
new file mode 100644
index 0000000..1c1471f
--- /dev/null
+++ b/osframework/source/demos/music/hungarr.ogg
Binary files differ
diff --git a/osframework/source/demos/music/music.mo3 b/osframework/source/demos/music/music.mo3
new file mode 100644
index 0000000..533e78e
--- /dev/null
+++ b/osframework/source/demos/music/music.mo3
Binary files differ
diff --git a/osframework/source/demos/osfd VS2005.sln b/osframework/source/demos/osfd VS2005.sln
new file mode 100644
index 0000000..5167f7b
--- /dev/null
+++ b/osframework/source/demos/osfd VS2005.sln
@@ -0,0 +1,91 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SexyAppBase", "..\SexyAppFramework\SexyAppBase VS2005.vcproj", "{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo1", "Demo1\Demo1 VS2005.vcproj", "{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo2", "Demo2\Demo2 VS2005.vcproj", "{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo3", "Demo3\Demo3 VS2005.vcproj", "{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo4", "Demo4\Demo4 VS2005.vcproj", "{11091E68-2497-4470-9719-8ED84CECF827}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo5", "Demo5\Demo5 VS2005.vcproj", "{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hun-garr", "Hun-garr\Hun-garr VS2005.vcproj", "{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMLDemo", "XMLDemo\XMLDemo VS2005.vcproj", "{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "V12Demo", "V12Demo\V12Demo VS2005.vcproj", "{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug|Win32.ActiveCfg = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug|Win32.Build.0 = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release|Win32.ActiveCfg = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release|Win32.Build.0 = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug|Win32.Build.0 = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release|Win32.ActiveCfg = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release|Win32.Build.0 = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug|Win32.ActiveCfg = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug|Win32.Build.0 = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release|Win32.ActiveCfg = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release|Win32.Build.0 = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug|Win32.ActiveCfg = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug|Win32.Build.0 = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release|Win32.ActiveCfg = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release|Win32.Build.0 = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug|Win32.ActiveCfg = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug|Win32.Build.0 = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release|Win32.ActiveCfg = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release|Win32.Build.0 = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug|Win32.ActiveCfg = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug|Win32.Build.0 = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release|Win32.ActiveCfg = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release|Win32.Build.0 = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug|Win32.Build.0 = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release|Win32.ActiveCfg = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release|Win32.Build.0 = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug|Win32.ActiveCfg = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug|Win32.Build.0 = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release|Win32.ActiveCfg = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release|Win32.Build.0 = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug|Win32.Build.0 = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release|Win32.ActiveCfg = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/osframework/source/demos/osfd WideString VS2005.sln b/osframework/source/demos/osfd WideString VS2005.sln
new file mode 100644
index 0000000..ba10250
--- /dev/null
+++ b/osframework/source/demos/osfd WideString VS2005.sln
@@ -0,0 +1,91 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo1", "Demo1\Demo1 VS2005 WideString.vcproj", "{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo2", "Demo2\Demo2 VS2005 WideString.vcproj", "{3729E951-A2F8-4516-BFF8-312040890EA4}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo3", "Demo3\Demo3 VS2005 WideString.vcproj", "{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo4", "Demo4\Demo4 VS2005 WideString.vcproj", "{11091E68-2497-4470-9719-8ED84CECF827}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo5", "Demo5\Demo5 VS2005 WideString.vcproj", "{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hun-garr", "Hun-garr\Hun-garr VS2005 WideString.vcproj", "{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMLDemo", "XMLDemo\XMLDemo VS2005 WideString.vcproj", "{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "V12Demo", "V12Demo\V12Demo VS2005 WideString.vcproj", "{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+ ProjectSection(ProjectDependencies) = postProject
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600} = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SexyAppBase WSTRING", "..\SexyAppFramework\SexyAppBase VS2005 WideString.vcproj", "{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug|Win32.Build.0 = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release|Win32.ActiveCfg = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release|Win32.Build.0 = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug|Win32.ActiveCfg = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug|Win32.Build.0 = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release|Win32.ActiveCfg = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release|Win32.Build.0 = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug|Win32.ActiveCfg = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug|Win32.Build.0 = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release|Win32.ActiveCfg = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release|Win32.Build.0 = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug|Win32.ActiveCfg = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug|Win32.Build.0 = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release|Win32.ActiveCfg = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release|Win32.Build.0 = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug|Win32.ActiveCfg = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug|Win32.Build.0 = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release|Win32.ActiveCfg = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release|Win32.Build.0 = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug|Win32.Build.0 = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release|Win32.ActiveCfg = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release|Win32.Build.0 = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug|Win32.ActiveCfg = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug|Win32.Build.0 = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release|Win32.ActiveCfg = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release|Win32.Build.0 = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug|Win32.Build.0 = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release|Win32.ActiveCfg = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release|Win32.Build.0 = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug|Win32.ActiveCfg = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug|Win32.Build.0 = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release|Win32.ActiveCfg = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/osframework/source/demos/osfd WideString.sln b/osframework/source/demos/osfd WideString.sln
new file mode 100644
index 0000000..4af2194
--- /dev/null
+++ b/osframework/source/demos/osfd WideString.sln
@@ -0,0 +1,80 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo1", "Demo1\Demo1 WideString.vcproj", "{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo2", "Demo2\Demo2 WideString.vcproj", "{3729E951-A2F8-4516-BFF8-312040890EA4}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo3", "Demo3\Demo3 WideString.vcproj", "{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo4", "Demo4\Demo4 WideString.vcproj", "{11091E68-2497-4470-9719-8ED84CECF827}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo5", "Demo5\Demo5 WideString.vcproj", "{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hun-garr", "Hun-garr\Hun-garr WideString.vcproj", "{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMLDemo", "XMLDemo\XMLDemo WideString.vcproj", "{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "V12Demo", "V12Demo\V12Demo WideString.vcproj", "{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SexyAppBase WSTRING", "..\SexyAppFramework\SexyAppBase WideString.vcproj", "{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ ConfigName.0 = Debug
+ ConfigName.1 = Release
+ EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {11091E68-2497-4470-9719-8ED84CECF827}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug.ActiveCfg = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug.Build.0 = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release.ActiveCfg = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release.Build.0 = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug.ActiveCfg = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug.Build.0 = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release.ActiveCfg = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release.Build.0 = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug.ActiveCfg = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug.Build.0 = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release.ActiveCfg = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release.Build.0 = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug.ActiveCfg = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug.Build.0 = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release.ActiveCfg = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release.Build.0 = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug.ActiveCfg = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug.Build.0 = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release.ActiveCfg = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release.Build.0 = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug.ActiveCfg = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug.Build.0 = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release.ActiveCfg = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release.Build.0 = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug.ActiveCfg = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug.Build.0 = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release.ActiveCfg = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release.Build.0 = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug.ActiveCfg = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug.Build.0 = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release.ActiveCfg = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release.Build.0 = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug.ActiveCfg = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug.Build.0 = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release.ActiveCfg = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionItems) = postSolution
+ Item:1 = demos.txt
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/osframework/source/demos/osfd.dsw b/osframework/source/demos/osfd.dsw
new file mode 100644
index 0000000..9fb191c
--- /dev/null
+++ b/osframework/source/demos/osfd.dsw
@@ -0,0 +1,149 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Demo1"=.\Demo1\Demo1.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Demo2"=.\Demo2\Demo2.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Demo3"=.\Demo3\Demo3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Demo4"=.\Demo4\Demo4.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Demo5"=.\Demo5\Demo5.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Hungarr"=".\Hun-garr\Hungarr.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "SexyAppBase"=..\SexyAppFramework\SexyAppBase.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "V12Demo"=.\V12Demo\V12Demo.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "XMLDemo"=.\XMLDemo\XMLDemo.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name SexyAppBase
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/osframework/source/demos/osfd.sln b/osframework/source/demos/osfd.sln
new file mode 100644
index 0000000..efacc87
--- /dev/null
+++ b/osframework/source/demos/osfd.sln
@@ -0,0 +1,80 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SexyAppBase", "..\SexyAppFramework\SexyAppBase.vcproj", "{DA08CABA-92AC-40F0-B63D-6ACE7814D600}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo1", "Demo1\Demo1.vcproj", "{F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo2", "Demo2\Demo2.vcproj", "{3729E951-A2F8-4516-BFF8-312040890EA4}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo3", "Demo3\Demo3.vcproj", "{07A2B4F6-12C3-47E6-AE89-B4013461A13A}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo4", "Demo4\Demo4.vcproj", "{11091E68-2497-4470-9719-8ED84CECF827}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo5", "Demo5\Demo5.vcproj", "{7B08C75A-BF48-43F1-9B62-B1982584C06B}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hun-garr", "Hun-garr\Hun-garr.vcproj", "{1D5FBC14-C869-4CC1-8337-B084767012C3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMLDemo", "XMLDemo\XMLDemo.vcproj", "{6A242898-B1D4-4EEA-AE61-AF1002462917}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "V12Demo", "V12Demo\V12Demo.vcproj", "{9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}"
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ ConfigName.0 = Debug
+ ConfigName.1 = Release
+ EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {11091E68-2497-4470-9719-8ED84CECF827}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.0 = {DA08CABA-92AC-40F0-B63D-6ACE7814D600}
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug.ActiveCfg = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Debug.Build.0 = Debug|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release.ActiveCfg = Release|Win32
+ {DA08CABA-92AC-40F0-B63D-6ACE7814D600}.Release.Build.0 = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug.ActiveCfg = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Debug.Build.0 = Debug|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release.ActiveCfg = Release|Win32
+ {F1FFB2ED-BC5D-40C9-A46B-92DAFEC91BBC}.Release.Build.0 = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug.ActiveCfg = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Debug.Build.0 = Debug|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release.ActiveCfg = Release|Win32
+ {3729E951-A2F8-4516-BFF8-312040890EA4}.Release.Build.0 = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug.ActiveCfg = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Debug.Build.0 = Debug|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release.ActiveCfg = Release|Win32
+ {07A2B4F6-12C3-47E6-AE89-B4013461A13A}.Release.Build.0 = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug.ActiveCfg = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Debug.Build.0 = Debug|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release.ActiveCfg = Release|Win32
+ {11091E68-2497-4470-9719-8ED84CECF827}.Release.Build.0 = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug.ActiveCfg = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Debug.Build.0 = Debug|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release.ActiveCfg = Release|Win32
+ {7B08C75A-BF48-43F1-9B62-B1982584C06B}.Release.Build.0 = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug.ActiveCfg = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Debug.Build.0 = Debug|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release.ActiveCfg = Release|Win32
+ {1D5FBC14-C869-4CC1-8337-B084767012C3}.Release.Build.0 = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug.ActiveCfg = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Debug.Build.0 = Debug|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release.ActiveCfg = Release|Win32
+ {6A242898-B1D4-4EEA-AE61-AF1002462917}.Release.Build.0 = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug.ActiveCfg = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Debug.Build.0 = Debug|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release.ActiveCfg = Release|Win32
+ {9A062D6E-B4A5-44F6-8D4D-84F19BCBF4FF}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionItems) = postSolution
+ Item:1 = demos.txt
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/osframework/source/demos/properties/demo.xml b/osframework/source/demos/properties/demo.xml
new file mode 100644
index 0000000..aa31984
--- /dev/null
+++ b/osframework/source/demos/properties/demo.xml
@@ -0,0 +1,38 @@
+<!-- below is an example of an instruction. The XMLParser class can handle instruction syntax,
+ but you'll notice that in the XMLDemo we don't actually use the value, we just ignore it. -->
+<?xml version="1.0"?>
+
+<!-- Sections contain nested items -->
+<Section1>
+
+ <!-- This item, "Item1", contains just 1 attribute, "text", and nothing more -->
+ <Item1 text="Some text for Section1/Item1"/>
+
+ <!-- This item, "BoolParam", contains an attribute, "text", as well as an element value,
+ which is the string "true" -->
+ <BoolParam text="Some text for Section1/BoolParam">true</BoolParam>
+
+ <!-- end of the section -->
+</Section1>
+
+<!-- This section contains an attribute in its line -->
+<Section2 s2attrib="Section2 attrib text">
+ <IntParam text="Some text for Section2/IntParam">1234</IntParam>
+
+ <!-- This just shows that you can split things up across lines. This is functionally equivalent to:
+ <MultiAttrib attrib1="attrib1" attrib2="2" attrib3="woo! attrib3!"/> -->
+
+ <MultiAttrib
+ attrib1="attrib1"
+ attrib2="2"
+ attrib3="woo! attrib3!"
+ />
+
+ <!-- The XMLParser class handles nested sections as well -->
+ <Subsection>
+ <!-- and of course, you can put more items in here, like any other section -->
+ <Item2>Text for Section2/Subsection/Item2</Item2>
+ </Subsection>
+
+</Section2>
+ \ No newline at end of file
diff --git a/osframework/source/demos/properties/resources.xml b/osframework/source/demos/properties/resources.xml
new file mode 100644
index 0000000..cf9d36d
--- /dev/null
+++ b/osframework/source/demos/properties/resources.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0"?>
+
+<!--
+ All resources.xml files must contain the ResourceManifest section.
+
+ Just like when we loaded resources manually in demos 1-3, you do
+ not have to specify the extensions for images and sounds.
+
+ Use the ResourceGen.exe program to convert this XML into C++ code.
+ The variable names that you give to the resources below will then be
+ accessible by any file that includes your resource header file
+ (generated by ResourceGen.exe).
+
+ Resource groups can be loaded/deleted at any time. Thus, it's advantageous
+ to split your resources into groups if you don't need to have every single
+ resource in memory at the same time. A common use for grouping is to
+ split the title screen, main menu, and main game elements up. Then,
+ when the main game is playing, you can kick out the main menu and title
+ screen data. Similarly, when you are back to the main menu, you can kick out
+ the game resources. How you use the grouping is up to you, it's provided
+ for your convenience.
+
+ Remember in previous demos how we had to manually set an image's
+ mNumRows and mNumCols by hand? Not anymore. If we had an image we
+ wanted to load that contained more than 1 row or column, we could
+ specify the optional parameters: cols and rows. As an example, here's
+ how we'd load in that lightning image from a previous demo:
+
+ <Image id="LIGHTNINGT" path="images/lightning" rows="8"/>
+
+ And then it's automatically set for you when you load the resource.
+-->
+
+<ResourceManifest>
+
+ <!-- You create resource groups with the Resources tag. Specify the
+ group name in the "id" field. We tend to use "Init" to mean the resources that
+ must be loaded before ANYTHING displays. We put our main font in here instead
+ of in the TileScreen group (below) because we want the font to stick around
+ for the duration of the game and not to be removed when we get rid of the
+ title screen. -->
+ <Resources id="Init">
+
+ <!-- You can set the default directory to look for the resources in, as
+ well as a standard prefix for the resource variable names when the C++
+ code is generated. -->
+ <SetDefaults path="fonts" idprefix="FONT_" />
+
+ <!-- The Font tag indicates that we want to load and initialize a font. Just
+ give the font a name (in this case, FONT_DEFAULT) and tell the manager where
+ to look for the data file. -->
+ <Font id="DEFAULT" path="ContinuumBold12.txt"/>
+ <Font id="HUNGARR" path="ArmorPiercing22.txt"/>
+
+ <SetDefaults path="images" idprefix="IMAGE_" />
+ <Image id="CUSTOM_POINTER" path="custom_pointer"/>
+ <Image id="CUSTOM_HAND" path="custom_hand"/>
+ <Image id="CUSTOM_DRAGGING" path="custom_dragging"/>
+ <Image id="CUSTOM_TEXT" path="custom_text"/>
+ <Image id="HUNGARR_LOGO" path="hungarr_logo"/>
+
+ </Resources>
+
+ <!-- These are the resources that are going to be used solely by the title screen.
+ Again, we could have named this resource group anything we wanted.
+ These resources will be deleted after we are done using the title screen. -->
+ <Resources id="TitleScreen">
+ <SetDefaults path="images" idprefix="IMAGE_"/>
+
+ <!-- The Image tag specifies that we want to load...an image.
+ There is also a Sound tag for loading sounds. All the tags work exactly the same:
+ you specify a variable name to use (if idprefix is specified it is prepended to
+ that name) and the name of the file to load. -->
+ <Image id="LOADER_BAR" path="loader_bar"/>
+ <Image id="LOADER_LOADINGTXT" path="loader_loading"/>
+
+ <SetDefaults path="sounds" idprefix="SOUND_"/>
+ <Sound id="CONTINUE" path="slowdown1"/>
+ </Resources>
+
+ <!-- And finally, we'll put all the resources that are needed for the main game
+ part of things in this group. -->
+ <Resources id="Game">
+ <SetDefaults path="sounds" idprefix="SOUND_"/>
+
+ <Sound id="MUTATOR" path="mutator"/>
+ <Sound id="TIMER" path="timer"/>
+
+ <SetDefaults path="images" idprefix="IMAGE_"/>
+
+ <!-- in case you're wondering about some of these filenames, they are taken
+ from various PopCap games. They haven't been changed. -->
+
+ <Image id="ROBOTROBOT" path="robotrobot"/>
+ <Image id="CHECKBOX" path="checkbox"/>
+ <Image id="BG0" path="layer0"/>
+ <Image id="BG1" path="layer1"/>
+ <Image id="BG2" path="layer2"/>
+ <Image id="BUTTON_DOWN" path="btn_down"/>
+ <Image id="BUTTON_OVER" path="btn_over"/>
+ <Image id="BUTTON_NORMAL" path="btn_up"/>
+
+ <Image id="DIALOG_BOX" path="dialog"/>
+ <Image id="DIALOG_BUTTON" path="dialog_btn"/>
+ <Image id="SLIDER_TRACK" path="slider"/>
+ <Image id="SLIDER_THUMB" path="slider_thumb"/>
+ </Resources>
+
+ <!-- Resources for the Hun-garr game -->
+ <Resources id="Hungarr">
+ <SetDefaults path="images" idprefix="IMAGE_"/>
+ <Image id="HUNGARR_SMALL" path="unicron_baby"/>
+ <Image id="HUNGARR_BEAM_UP" path="unicron_beam_up"/>
+ <Image id="HUNGARR_BEAM_DOWN" path="unicron_beam_down"/>
+ <Image id="HUNGARR_BEAM_LEFT" path="unicron_beam_left"/>
+ <Image id="HUNGARR_BEAM_RIGHT" path="unicron_beam_right"/>
+ <Image id="HUNGARR_HORIZ" path="unicron_horiz"/>
+ <Image id="HUNGARR_VERT" path="unicron_vert"/>
+ <Image id="ATOMIC_EXPLOSION" path="atomicexplosion" cols="15"/>
+ <Image id="BOMB_RADIAL_DEATH" path="bomb_radial_death" cols="10"/>
+ <Image id="PLANETS" path="planets_small" cols="11" rows="3"/>
+ <Image id="SPARK" path="spark"/>
+ <Image id="PARTICLE_LIGHTNING" path="particle_lightning" cols="19"/>
+
+ <SetDefaults path="sounds" idprefix="SOUND_"/>
+ <Sound id="MAGZAP" path="magzap1"/>
+ <Sound id="BUTTON" path="mouseover"/>
+ <Sound id="PLANET" path="planet"/>
+ <Sound id="LEVEL_UP1" path="level_up"/>
+ <Sound id="LEVEL_UP2" path="level_up2"/>
+ <Sound id="EXPLOSION" path="explosion"/>
+
+ <Sound id="BEAM_HIT" path="robotlaser"/>
+ <Sound id="PLANET_HIT" path="click2"/>
+ <Sound id="BEAM_MOVING" path="shorting"/>
+ <Sound id="LEVEL_UP4" path="laserpowerup"/>
+ <Sound id="LEVEL_UP3" path="killall_explode"/>
+ <Sound id="GAME_OVER_CLICK" path="bad2"/>
+ <Sound id="GAME_OVER_STATS" path="electro_start"/>
+ <Sound id="GAME_OVER_RESTART" path="whirlpool1"/>
+ <Sound id="GAME_OVER_TEXT" path="lament"/>
+ <Sound id="REGION_FILLED" path="metal_loop"/>
+
+ </Resources>
+</ResourceManifest>
diff --git a/osframework/source/demos/sounds/bad2.ogg b/osframework/source/demos/sounds/bad2.ogg
new file mode 100644
index 0000000..4c88300
--- /dev/null
+++ b/osframework/source/demos/sounds/bad2.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/click2.ogg b/osframework/source/demos/sounds/click2.ogg
new file mode 100644
index 0000000..6215476
--- /dev/null
+++ b/osframework/source/demos/sounds/click2.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/electro_start.ogg b/osframework/source/demos/sounds/electro_start.ogg
new file mode 100644
index 0000000..b5c33b1
--- /dev/null
+++ b/osframework/source/demos/sounds/electro_start.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/explosion.ogg b/osframework/source/demos/sounds/explosion.ogg
new file mode 100644
index 0000000..c4a0027
--- /dev/null
+++ b/osframework/source/demos/sounds/explosion.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/killall_explode.ogg b/osframework/source/demos/sounds/killall_explode.ogg
new file mode 100644
index 0000000..67ca4e9
--- /dev/null
+++ b/osframework/source/demos/sounds/killall_explode.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/lament.ogg b/osframework/source/demos/sounds/lament.ogg
new file mode 100644
index 0000000..c1f8946
--- /dev/null
+++ b/osframework/source/demos/sounds/lament.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/laserpowerup.ogg b/osframework/source/demos/sounds/laserpowerup.ogg
new file mode 100644
index 0000000..c66a149
--- /dev/null
+++ b/osframework/source/demos/sounds/laserpowerup.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/level_up.ogg b/osframework/source/demos/sounds/level_up.ogg
new file mode 100644
index 0000000..1f5df38
--- /dev/null
+++ b/osframework/source/demos/sounds/level_up.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/level_up2.ogg b/osframework/source/demos/sounds/level_up2.ogg
new file mode 100644
index 0000000..2387c05
--- /dev/null
+++ b/osframework/source/demos/sounds/level_up2.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/magzap1.ogg b/osframework/source/demos/sounds/magzap1.ogg
new file mode 100644
index 0000000..40c856e
--- /dev/null
+++ b/osframework/source/demos/sounds/magzap1.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/metal_loop.wav b/osframework/source/demos/sounds/metal_loop.wav
new file mode 100644
index 0000000..6ec418a
--- /dev/null
+++ b/osframework/source/demos/sounds/metal_loop.wav
Binary files differ
diff --git a/osframework/source/demos/sounds/mouseover.ogg b/osframework/source/demos/sounds/mouseover.ogg
new file mode 100644
index 0000000..762b24d
--- /dev/null
+++ b/osframework/source/demos/sounds/mouseover.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/mutator.ogg b/osframework/source/demos/sounds/mutator.ogg
new file mode 100644
index 0000000..fdf3aac
--- /dev/null
+++ b/osframework/source/demos/sounds/mutator.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/planet.ogg b/osframework/source/demos/sounds/planet.ogg
new file mode 100644
index 0000000..796542c
--- /dev/null
+++ b/osframework/source/demos/sounds/planet.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/robotlaser.ogg b/osframework/source/demos/sounds/robotlaser.ogg
new file mode 100644
index 0000000..5be5700
--- /dev/null
+++ b/osframework/source/demos/sounds/robotlaser.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/shorting.ogg b/osframework/source/demos/sounds/shorting.ogg
new file mode 100644
index 0000000..cb95541
--- /dev/null
+++ b/osframework/source/demos/sounds/shorting.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/slowdown1.ogg b/osframework/source/demos/sounds/slowdown1.ogg
new file mode 100644
index 0000000..953d624
--- /dev/null
+++ b/osframework/source/demos/sounds/slowdown1.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/timer.ogg b/osframework/source/demos/sounds/timer.ogg
new file mode 100644
index 0000000..bcf4392
--- /dev/null
+++ b/osframework/source/demos/sounds/timer.ogg
Binary files differ
diff --git a/osframework/source/demos/sounds/whirlpool1.ogg b/osframework/source/demos/sounds/whirlpool1.ogg
new file mode 100644
index 0000000..2993ffc
--- /dev/null
+++ b/osframework/source/demos/sounds/whirlpool1.ogg
Binary files differ
diff --git a/osframework/tools/FontBuilder.exe b/osframework/tools/FontBuilder.exe
new file mode 100644
index 0000000..561a04c
--- /dev/null
+++ b/osframework/tools/FontBuilder.exe
Binary files differ
diff --git a/osframework/tools/FontTester.exe b/osframework/tools/FontTester.exe
new file mode 100644
index 0000000..032f0df
--- /dev/null
+++ b/osframework/tools/FontTester.exe
Binary files differ
diff --git a/osframework/tools/GFXMonger.exe b/osframework/tools/GFXMonger.exe
new file mode 100644
index 0000000..b930e87
--- /dev/null
+++ b/osframework/tools/GFXMonger.exe
Binary files differ
diff --git a/osframework/tools/MapLookup.exe b/osframework/tools/MapLookup.exe
new file mode 100644
index 0000000..eb3607f
--- /dev/null
+++ b/osframework/tools/MapLookup.exe
Binary files differ
diff --git a/osframework/tools/PopPak.exe b/osframework/tools/PopPak.exe
new file mode 100644
index 0000000..2ca8ddc
--- /dev/null
+++ b/osframework/tools/PopPak.exe
Binary files differ
diff --git a/osframework/tools/ResourceGen.exe b/osframework/tools/ResourceGen.exe
new file mode 100644
index 0000000..d7f2442
--- /dev/null
+++ b/osframework/tools/ResourceGen.exe
Binary files differ
diff --git a/osframework/tools/fmod.dll b/osframework/tools/fmod.dll
new file mode 100644
index 0000000..f974f41
--- /dev/null
+++ b/osframework/tools/fmod.dll
Binary files differ