istereo2

changeset 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents 2d5abf441307
children dc735bdeeb8a
files istereo.xcodeproj/project.pbxproj libs/Makefile libs/imago2/COPYING libs/imago2/COPYING.LESSER libs/imago2/conv.c libs/imago2/file_jpeg.c libs/imago2/file_png.c libs/imago2/file_ppm.c libs/imago2/ftype_module.c libs/imago2/ftype_module.h libs/imago2/imago2.c libs/imago2/imago2.h libs/imago2/modules.c libs/libjpeg/README libs/libjpeg/cderror.h libs/libjpeg/jcapimin.c libs/libjpeg/jcapistd.c libs/libjpeg/jccoefct.c libs/libjpeg/jccolor.c libs/libjpeg/jcdctmgr.c libs/libjpeg/jchuff.c libs/libjpeg/jchuff.h libs/libjpeg/jcinit.c libs/libjpeg/jcmainct.c libs/libjpeg/jcmarker.c libs/libjpeg/jcmaster.c libs/libjpeg/jcomapi.c libs/libjpeg/jconfig.h libs/libjpeg/jcparam.c libs/libjpeg/jcphuff.c libs/libjpeg/jcprepct.c libs/libjpeg/jcsample.c libs/libjpeg/jctrans.c libs/libjpeg/jdapimin.c libs/libjpeg/jdapistd.c libs/libjpeg/jdatadst.c libs/libjpeg/jdatasrc.c libs/libjpeg/jdcoefct.c libs/libjpeg/jdcolor.c libs/libjpeg/jdct.h libs/libjpeg/jddctmgr.c libs/libjpeg/jdhuff.c libs/libjpeg/jdhuff.h libs/libjpeg/jdinput.c libs/libjpeg/jdmainct.c libs/libjpeg/jdmarker.c libs/libjpeg/jdmaster.c libs/libjpeg/jdmerge.c libs/libjpeg/jdphuff.c libs/libjpeg/jdpostct.c libs/libjpeg/jdsample.c libs/libjpeg/jdtrans.c libs/libjpeg/jerror.c libs/libjpeg/jerror.h libs/libjpeg/jfdctflt.c libs/libjpeg/jfdctfst.c libs/libjpeg/jfdctint.c libs/libjpeg/jidctflt.c libs/libjpeg/jidctfst.c libs/libjpeg/jidctint.c libs/libjpeg/jidctred.c libs/libjpeg/jinclude.h libs/libjpeg/jmemmgr.c libs/libjpeg/jmemnobs.c libs/libjpeg/jmemsys.h libs/libjpeg/jmorecfg.h libs/libjpeg/jpegint.h libs/libjpeg/jpeglib.h libs/libjpeg/jquant1.c libs/libjpeg/jquant2.c libs/libjpeg/jutils.c libs/libjpeg/jversion.h libs/libpng/LICENSE libs/libpng/png.c libs/libpng/png.h libs/libpng/pngconf.h libs/libpng/pngerror.c libs/libpng/pnggccrd.c libs/libpng/pngget.c libs/libpng/pngmem.c libs/libpng/pngpread.c libs/libpng/pngread.c libs/libpng/pngrio.c libs/libpng/pngrtran.c libs/libpng/pngrutil.c libs/libpng/pngset.c libs/libpng/pngtrans.c libs/libpng/pngvcrd.c libs/libpng/pngwio.c libs/libpng/pngwrite.c libs/libpng/pngwtran.c libs/libpng/pngwutil.c libs/vmath/COPYING libs/vmath/COPYING.LESSER libs/vmath/basis.h libs/vmath/basis_c.c libs/vmath/geom.c libs/vmath/geom.h libs/vmath/matrix.h libs/vmath/matrix.inl libs/vmath/matrix_c.c libs/vmath/quat.h libs/vmath/quat.inl libs/vmath/quat_c.c libs/vmath/ray.h libs/vmath/ray.inl libs/vmath/ray_c.c libs/vmath/sphvec.h libs/vmath/vector.h libs/vmath/vector.inl libs/vmath/vmath.c libs/vmath/vmath.h libs/vmath/vmath.inl libs/vmath/vmath_config.h libs/vmath/vmath_types.h libs/zlib/LICENSE libs/zlib/adler32.c libs/zlib/compress.c libs/zlib/crc32.c libs/zlib/crc32.h libs/zlib/deflate.c libs/zlib/deflate.h libs/zlib/gzio.c libs/zlib/infback.c libs/zlib/inffast.c libs/zlib/inffast.h libs/zlib/inffixed.h libs/zlib/inflate.c libs/zlib/inflate.h libs/zlib/inftrees.c libs/zlib/inftrees.h libs/zlib/trees.c libs/zlib/trees.h libs/zlib/uncompr.c libs/zlib/zconf.h libs/zlib/zlib.h libs/zlib/zutil.c libs/zlib/zutil.h sdr/test.p.glsl sdr/test.v.glsl sdr/text.p.glsl sdr/text.v.glsl sdr/tunnel.p.glsl sdr/tunnel.v.glsl src/cam.c src/cam.h src/config.h src/glutmain.c src/ios/viewctl.m src/istereo.c src/istereo.h src/opengl.h src/respath.c src/respath.h src/sanegl.c src/sanegl.h src/sdr.c src/sdr.h src/tex.c src/tex.h src/ui.h src/ui.xib
diffstat 162 files changed, 70872 insertions(+), 29 deletions(-) [+]
line diff
     1.1 --- a/istereo.xcodeproj/project.pbxproj	Fri Sep 18 23:02:50 2015 +0300
     1.2 +++ b/istereo.xcodeproj/project.pbxproj	Sat Sep 19 05:51:51 2015 +0300
     1.3 @@ -11,6 +11,110 @@
     1.4  		0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; };
     1.5  		0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; };
     1.6  		0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; };
     1.7 +		0669D6911BACDF6C00611CFA /* cam.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6821BACDF6C00611CFA /* cam.c */; };
     1.8 +		0669D6921BACDF6C00611CFA /* istereo.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6851BACDF6C00611CFA /* istereo.c */; };
     1.9 +		0669D6931BACDF6C00611CFA /* respath.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6881BACDF6C00611CFA /* respath.c */; };
    1.10 +		0669D6941BACDF6C00611CFA /* sanegl.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D68A1BACDF6C00611CFA /* sanegl.c */; };
    1.11 +		0669D6951BACDF6C00611CFA /* sdr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D68C1BACDF6C00611CFA /* sdr.c */; };
    1.12 +		0669D6961BACDF6C00611CFA /* tex.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D68E1BACDF6C00611CFA /* tex.c */; };
    1.13 +		0669D6B21BAD020B00611CFA /* basis_c.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D69D1BAD020B00611CFA /* basis_c.c */; };
    1.14 +		0669D6B31BAD020B00611CFA /* geom.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D69F1BAD020B00611CFA /* geom.c */; };
    1.15 +		0669D6B41BAD020B00611CFA /* matrix_c.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6A11BAD020B00611CFA /* matrix_c.c */; };
    1.16 +		0669D6B61BAD020B00611CFA /* quat_c.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6A41BAD020B00611CFA /* quat_c.c */; };
    1.17 +		0669D6B81BAD020B00611CFA /* ray_c.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6A71BAD020B00611CFA /* ray_c.c */; };
    1.18 +		0669D6BB1BAD020B00611CFA /* vmath.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6AF1BAD020B00611CFA /* vmath.c */; };
    1.19 +		0669D6C61BAD022C00611CFA /* conv.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6BD1BAD022C00611CFA /* conv.c */; };
    1.20 +		0669D6C71BAD022C00611CFA /* file_jpeg.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6BE1BAD022C00611CFA /* file_jpeg.c */; };
    1.21 +		0669D6C81BAD022C00611CFA /* file_png.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6BF1BAD022C00611CFA /* file_png.c */; };
    1.22 +		0669D6C91BAD022C00611CFA /* file_ppm.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6C01BAD022C00611CFA /* file_ppm.c */; };
    1.23 +		0669D6CA1BAD022C00611CFA /* ftype_module.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6C11BAD022C00611CFA /* ftype_module.c */; };
    1.24 +		0669D6CB1BAD022C00611CFA /* imago2.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6C31BAD022C00611CFA /* imago2.c */; };
    1.25 +		0669D6CC1BAD022C00611CFA /* modules.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6C51BAD022C00611CFA /* modules.c */; };
    1.26 +		0669D7071BAD024700611CFA /* jcapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6CE1BAD024700611CFA /* jcapimin.c */; };
    1.27 +		0669D7081BAD024700611CFA /* jcapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6CF1BAD024700611CFA /* jcapistd.c */; };
    1.28 +		0669D7091BAD024700611CFA /* jccoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D01BAD024700611CFA /* jccoefct.c */; };
    1.29 +		0669D70A1BAD024700611CFA /* jccolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D11BAD024700611CFA /* jccolor.c */; };
    1.30 +		0669D70B1BAD024700611CFA /* jcdctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D21BAD024700611CFA /* jcdctmgr.c */; };
    1.31 +		0669D70C1BAD024700611CFA /* jchuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D31BAD024700611CFA /* jchuff.c */; };
    1.32 +		0669D70D1BAD024700611CFA /* jcinit.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D51BAD024700611CFA /* jcinit.c */; };
    1.33 +		0669D70E1BAD024700611CFA /* jcmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D61BAD024700611CFA /* jcmainct.c */; };
    1.34 +		0669D70F1BAD024700611CFA /* jcmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D71BAD024700611CFA /* jcmarker.c */; };
    1.35 +		0669D7101BAD024700611CFA /* jcmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D81BAD024700611CFA /* jcmaster.c */; };
    1.36 +		0669D7111BAD024700611CFA /* jcomapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6D91BAD024700611CFA /* jcomapi.c */; };
    1.37 +		0669D7121BAD024700611CFA /* jcparam.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6DB1BAD024700611CFA /* jcparam.c */; };
    1.38 +		0669D7131BAD024700611CFA /* jcphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6DC1BAD024700611CFA /* jcphuff.c */; };
    1.39 +		0669D7141BAD024700611CFA /* jcprepct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6DD1BAD024700611CFA /* jcprepct.c */; };
    1.40 +		0669D7151BAD024700611CFA /* jcsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6DE1BAD024700611CFA /* jcsample.c */; };
    1.41 +		0669D7161BAD024700611CFA /* jctrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6DF1BAD024700611CFA /* jctrans.c */; };
    1.42 +		0669D7171BAD024700611CFA /* jdapimin.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E01BAD024700611CFA /* jdapimin.c */; };
    1.43 +		0669D7181BAD024700611CFA /* jdapistd.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E11BAD024700611CFA /* jdapistd.c */; };
    1.44 +		0669D7191BAD024700611CFA /* jdatadst.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E21BAD024700611CFA /* jdatadst.c */; };
    1.45 +		0669D71A1BAD024700611CFA /* jdatasrc.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E31BAD024700611CFA /* jdatasrc.c */; };
    1.46 +		0669D71B1BAD024700611CFA /* jdcoefct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E41BAD024700611CFA /* jdcoefct.c */; };
    1.47 +		0669D71C1BAD024700611CFA /* jdcolor.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E51BAD024700611CFA /* jdcolor.c */; };
    1.48 +		0669D71D1BAD024700611CFA /* jddctmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E71BAD024700611CFA /* jddctmgr.c */; };
    1.49 +		0669D71E1BAD024700611CFA /* jdhuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6E81BAD024700611CFA /* jdhuff.c */; };
    1.50 +		0669D71F1BAD024700611CFA /* jdinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6EA1BAD024700611CFA /* jdinput.c */; };
    1.51 +		0669D7201BAD024700611CFA /* jdmainct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6EB1BAD024700611CFA /* jdmainct.c */; };
    1.52 +		0669D7211BAD024700611CFA /* jdmarker.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6EC1BAD024700611CFA /* jdmarker.c */; };
    1.53 +		0669D7221BAD024700611CFA /* jdmaster.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6ED1BAD024700611CFA /* jdmaster.c */; };
    1.54 +		0669D7231BAD024700611CFA /* jdmerge.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6EE1BAD024700611CFA /* jdmerge.c */; };
    1.55 +		0669D7241BAD024700611CFA /* jdphuff.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6EF1BAD024700611CFA /* jdphuff.c */; };
    1.56 +		0669D7251BAD024700611CFA /* jdpostct.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F01BAD024700611CFA /* jdpostct.c */; };
    1.57 +		0669D7261BAD024700611CFA /* jdsample.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F11BAD024700611CFA /* jdsample.c */; };
    1.58 +		0669D7271BAD024700611CFA /* jdtrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F21BAD024700611CFA /* jdtrans.c */; };
    1.59 +		0669D7281BAD024700611CFA /* jerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F31BAD024700611CFA /* jerror.c */; };
    1.60 +		0669D7291BAD024700611CFA /* jfdctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F51BAD024700611CFA /* jfdctflt.c */; };
    1.61 +		0669D72A1BAD024700611CFA /* jfdctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F61BAD024700611CFA /* jfdctfst.c */; };
    1.62 +		0669D72B1BAD024700611CFA /* jfdctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F71BAD024700611CFA /* jfdctint.c */; };
    1.63 +		0669D72C1BAD024700611CFA /* jidctflt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F81BAD024700611CFA /* jidctflt.c */; };
    1.64 +		0669D72D1BAD024700611CFA /* jidctfst.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6F91BAD024700611CFA /* jidctfst.c */; };
    1.65 +		0669D72E1BAD024700611CFA /* jidctint.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6FA1BAD024700611CFA /* jidctint.c */; };
    1.66 +		0669D72F1BAD024700611CFA /* jidctred.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6FB1BAD024700611CFA /* jidctred.c */; };
    1.67 +		0669D7301BAD024700611CFA /* jmemmgr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6FD1BAD024700611CFA /* jmemmgr.c */; };
    1.68 +		0669D7311BAD024700611CFA /* jmemnobs.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D6FE1BAD024700611CFA /* jmemnobs.c */; };
    1.69 +		0669D7321BAD024700611CFA /* jquant1.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7031BAD024700611CFA /* jquant1.c */; };
    1.70 +		0669D7331BAD024700611CFA /* jquant2.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7041BAD024700611CFA /* jquant2.c */; };
    1.71 +		0669D7341BAD024700611CFA /* jutils.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7051BAD024700611CFA /* jutils.c */; };
    1.72 +		0669D7481BAD025B00611CFA /* png.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7351BAD025B00611CFA /* png.c */; };
    1.73 +		0669D7491BAD025B00611CFA /* pngerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7381BAD025B00611CFA /* pngerror.c */; };
    1.74 +		0669D74A1BAD025B00611CFA /* pnggccrd.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7391BAD025B00611CFA /* pnggccrd.c */; };
    1.75 +		0669D74B1BAD025B00611CFA /* pngget.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73A1BAD025B00611CFA /* pngget.c */; };
    1.76 +		0669D74C1BAD025B00611CFA /* pngmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73B1BAD025B00611CFA /* pngmem.c */; };
    1.77 +		0669D74D1BAD025B00611CFA /* pngpread.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73C1BAD025B00611CFA /* pngpread.c */; };
    1.78 +		0669D74E1BAD025B00611CFA /* pngread.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73D1BAD025B00611CFA /* pngread.c */; };
    1.79 +		0669D74F1BAD025B00611CFA /* pngrio.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73E1BAD025B00611CFA /* pngrio.c */; };
    1.80 +		0669D7501BAD025B00611CFA /* pngrtran.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D73F1BAD025B00611CFA /* pngrtran.c */; };
    1.81 +		0669D7511BAD025B00611CFA /* pngrutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7401BAD025B00611CFA /* pngrutil.c */; };
    1.82 +		0669D7521BAD025B00611CFA /* pngset.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7411BAD025B00611CFA /* pngset.c */; };
    1.83 +		0669D7531BAD025B00611CFA /* pngtrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7421BAD025B00611CFA /* pngtrans.c */; };
    1.84 +		0669D7541BAD025B00611CFA /* pngvcrd.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7431BAD025B00611CFA /* pngvcrd.c */; };
    1.85 +		0669D7551BAD025B00611CFA /* pngwio.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7441BAD025B00611CFA /* pngwio.c */; };
    1.86 +		0669D7561BAD025B00611CFA /* pngwrite.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7451BAD025B00611CFA /* pngwrite.c */; };
    1.87 +		0669D7571BAD025B00611CFA /* pngwtran.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7461BAD025B00611CFA /* pngwtran.c */; };
    1.88 +		0669D7581BAD025B00611CFA /* pngwutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7471BAD025B00611CFA /* pngwutil.c */; };
    1.89 +		0669D76F1BAD027000611CFA /* adler32.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7591BAD027000611CFA /* adler32.c */; };
    1.90 +		0669D7701BAD027000611CFA /* compress.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D75A1BAD027000611CFA /* compress.c */; };
    1.91 +		0669D7711BAD027000611CFA /* crc32.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D75B1BAD027000611CFA /* crc32.c */; };
    1.92 +		0669D7721BAD027000611CFA /* deflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D75D1BAD027000611CFA /* deflate.c */; };
    1.93 +		0669D7731BAD027000611CFA /* gzio.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D75F1BAD027000611CFA /* gzio.c */; };
    1.94 +		0669D7741BAD027000611CFA /* infback.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7601BAD027000611CFA /* infback.c */; };
    1.95 +		0669D7751BAD027000611CFA /* inffast.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7611BAD027000611CFA /* inffast.c */; };
    1.96 +		0669D7761BAD027000611CFA /* inflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7641BAD027000611CFA /* inflate.c */; };
    1.97 +		0669D7771BAD027000611CFA /* inftrees.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7661BAD027000611CFA /* inftrees.c */; };
    1.98 +		0669D7781BAD027000611CFA /* trees.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D7681BAD027000611CFA /* trees.c */; };
    1.99 +		0669D7791BAD027000611CFA /* uncompr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D76A1BAD027000611CFA /* uncompr.c */; };
   1.100 +		0669D77A1BAD027000611CFA /* zutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 0669D76D1BAD027000611CFA /* zutil.c */; };
   1.101 +		0669D7821BAD02A200611CFA /* test.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D77C1BAD02A200611CFA /* test.p.glsl */; };
   1.102 +		0669D7831BAD02A200611CFA /* test.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D77D1BAD02A200611CFA /* test.v.glsl */; };
   1.103 +		0669D7841BAD02A200611CFA /* text.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D77E1BAD02A200611CFA /* text.p.glsl */; };
   1.104 +		0669D7851BAD02A200611CFA /* text.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D77F1BAD02A200611CFA /* text.v.glsl */; };
   1.105 +		0669D7861BAD02A200611CFA /* tunnel.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D7801BAD02A200611CFA /* tunnel.p.glsl */; };
   1.106 +		0669D7871BAD02A200611CFA /* tunnel.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 0669D7811BAD02A200611CFA /* tunnel.v.glsl */; };
   1.107 +		0669D78D1BAD02DC00611CFA /* stonewall_normal.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 0669D7891BAD02DC00611CFA /* stonewall_normal.jpg */; };
   1.108 +		0669D78E1BAD02DC00611CFA /* stonewall.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 0669D78A1BAD02DC00611CFA /* stonewall.jpg */; };
   1.109 +		0669D78F1BAD02DC00611CFA /* text.png in Resources */ = {isa = PBXBuildFile; fileRef = 0669D78B1BAD02DC00611CFA /* text.png */; };
   1.110 +		0669D7901BAD02DC00611CFA /* tiles.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 0669D78C1BAD02DC00611CFA /* tiles.jpg */; };
   1.111  /* End PBXBuildFile section */
   1.112  
   1.113  /* Begin PBXFileReference section */
   1.114 @@ -21,6 +125,160 @@
   1.115  		0669D67C1BA85DDE00611CFA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = src/ios/main.m; sourceTree = "<group>"; };
   1.116  		0669D67D1BA85DDE00611CFA /* viewctl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = viewctl.h; path = src/ios/viewctl.h; sourceTree = "<group>"; };
   1.117  		0669D67E1BA85DDE00611CFA /* viewctl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = viewctl.m; path = src/ios/viewctl.m; sourceTree = "<group>"; };
   1.118 +		0669D6821BACDF6C00611CFA /* cam.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cam.c; path = src/cam.c; sourceTree = "<group>"; };
   1.119 +		0669D6831BACDF6C00611CFA /* cam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cam.h; path = src/cam.h; sourceTree = "<group>"; };
   1.120 +		0669D6841BACDF6C00611CFA /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = src/config.h; sourceTree = "<group>"; };
   1.121 +		0669D6851BACDF6C00611CFA /* istereo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = istereo.c; path = src/istereo.c; sourceTree = "<group>"; };
   1.122 +		0669D6861BACDF6C00611CFA /* istereo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = istereo.h; path = src/istereo.h; sourceTree = "<group>"; };
   1.123 +		0669D6871BACDF6C00611CFA /* opengl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = opengl.h; path = src/opengl.h; sourceTree = "<group>"; };
   1.124 +		0669D6881BACDF6C00611CFA /* respath.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = respath.c; path = src/respath.c; sourceTree = "<group>"; };
   1.125 +		0669D6891BACDF6C00611CFA /* respath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = respath.h; path = src/respath.h; sourceTree = "<group>"; };
   1.126 +		0669D68A1BACDF6C00611CFA /* sanegl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sanegl.c; path = src/sanegl.c; sourceTree = "<group>"; };
   1.127 +		0669D68B1BACDF6C00611CFA /* sanegl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sanegl.h; path = src/sanegl.h; sourceTree = "<group>"; };
   1.128 +		0669D68C1BACDF6C00611CFA /* sdr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sdr.c; path = src/sdr.c; sourceTree = "<group>"; };
   1.129 +		0669D68D1BACDF6C00611CFA /* sdr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sdr.h; path = src/sdr.h; sourceTree = "<group>"; };
   1.130 +		0669D68E1BACDF6C00611CFA /* tex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = tex.c; path = src/tex.c; sourceTree = "<group>"; };
   1.131 +		0669D68F1BACDF6C00611CFA /* tex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tex.h; path = src/tex.h; sourceTree = "<group>"; };
   1.132 +		0669D6901BACDF6C00611CFA /* ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ui.h; path = src/ui.h; sourceTree = "<group>"; };
   1.133 +		0669D69D1BAD020B00611CFA /* basis_c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = basis_c.c; path = libs/vmath/basis_c.c; sourceTree = "<group>"; };
   1.134 +		0669D69E1BAD020B00611CFA /* basis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = basis.h; path = libs/vmath/basis.h; sourceTree = "<group>"; };
   1.135 +		0669D69F1BAD020B00611CFA /* geom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = geom.c; path = libs/vmath/geom.c; sourceTree = "<group>"; };
   1.136 +		0669D6A01BAD020B00611CFA /* geom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = geom.h; path = libs/vmath/geom.h; sourceTree = "<group>"; };
   1.137 +		0669D6A11BAD020B00611CFA /* matrix_c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = matrix_c.c; path = libs/vmath/matrix_c.c; sourceTree = "<group>"; };
   1.138 +		0669D6A21BAD020B00611CFA /* matrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = matrix.h; path = libs/vmath/matrix.h; sourceTree = "<group>"; };
   1.139 +		0669D6A31BAD020B00611CFA /* matrix.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = matrix.inl; path = libs/vmath/matrix.inl; sourceTree = "<group>"; };
   1.140 +		0669D6A41BAD020B00611CFA /* quat_c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = quat_c.c; path = libs/vmath/quat_c.c; sourceTree = "<group>"; };
   1.141 +		0669D6A51BAD020B00611CFA /* quat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = quat.h; path = libs/vmath/quat.h; sourceTree = "<group>"; };
   1.142 +		0669D6A61BAD020B00611CFA /* quat.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = quat.inl; path = libs/vmath/quat.inl; sourceTree = "<group>"; };
   1.143 +		0669D6A71BAD020B00611CFA /* ray_c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ray_c.c; path = libs/vmath/ray_c.c; sourceTree = "<group>"; };
   1.144 +		0669D6A81BAD020B00611CFA /* ray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ray.h; path = libs/vmath/ray.h; sourceTree = "<group>"; };
   1.145 +		0669D6A91BAD020B00611CFA /* ray.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ray.inl; path = libs/vmath/ray.inl; sourceTree = "<group>"; };
   1.146 +		0669D6AA1BAD020B00611CFA /* sphvec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sphvec.h; path = libs/vmath/sphvec.h; sourceTree = "<group>"; };
   1.147 +		0669D6AB1BAD020B00611CFA /* vector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vector.h; path = libs/vmath/vector.h; sourceTree = "<group>"; };
   1.148 +		0669D6AC1BAD020B00611CFA /* vector.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = vector.inl; path = libs/vmath/vector.inl; sourceTree = "<group>"; };
   1.149 +		0669D6AD1BAD020B00611CFA /* vmath_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vmath_config.h; path = libs/vmath/vmath_config.h; sourceTree = "<group>"; };
   1.150 +		0669D6AE1BAD020B00611CFA /* vmath_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vmath_types.h; path = libs/vmath/vmath_types.h; sourceTree = "<group>"; };
   1.151 +		0669D6AF1BAD020B00611CFA /* vmath.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vmath.c; path = libs/vmath/vmath.c; sourceTree = "<group>"; };
   1.152 +		0669D6B01BAD020B00611CFA /* vmath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vmath.h; path = libs/vmath/vmath.h; sourceTree = "<group>"; };
   1.153 +		0669D6B11BAD020B00611CFA /* vmath.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = vmath.inl; path = libs/vmath/vmath.inl; sourceTree = "<group>"; };
   1.154 +		0669D6BD1BAD022C00611CFA /* conv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = conv.c; path = libs/imago2/conv.c; sourceTree = "<group>"; };
   1.155 +		0669D6BE1BAD022C00611CFA /* file_jpeg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = file_jpeg.c; path = libs/imago2/file_jpeg.c; sourceTree = "<group>"; };
   1.156 +		0669D6BF1BAD022C00611CFA /* file_png.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = file_png.c; path = libs/imago2/file_png.c; sourceTree = "<group>"; };
   1.157 +		0669D6C01BAD022C00611CFA /* file_ppm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = file_ppm.c; path = libs/imago2/file_ppm.c; sourceTree = "<group>"; };
   1.158 +		0669D6C11BAD022C00611CFA /* ftype_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ftype_module.c; path = libs/imago2/ftype_module.c; sourceTree = "<group>"; };
   1.159 +		0669D6C21BAD022C00611CFA /* ftype_module.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ftype_module.h; path = libs/imago2/ftype_module.h; sourceTree = "<group>"; };
   1.160 +		0669D6C31BAD022C00611CFA /* imago2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = imago2.c; path = libs/imago2/imago2.c; sourceTree = "<group>"; };
   1.161 +		0669D6C41BAD022C00611CFA /* imago2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imago2.h; path = libs/imago2/imago2.h; sourceTree = "<group>"; };
   1.162 +		0669D6C51BAD022C00611CFA /* modules.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = modules.c; path = libs/imago2/modules.c; sourceTree = "<group>"; };
   1.163 +		0669D6CD1BAD024700611CFA /* cderror.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cderror.h; path = libs/libjpeg/cderror.h; sourceTree = "<group>"; };
   1.164 +		0669D6CE1BAD024700611CFA /* jcapimin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcapimin.c; path = libs/libjpeg/jcapimin.c; sourceTree = "<group>"; };
   1.165 +		0669D6CF1BAD024700611CFA /* jcapistd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcapistd.c; path = libs/libjpeg/jcapistd.c; sourceTree = "<group>"; };
   1.166 +		0669D6D01BAD024700611CFA /* jccoefct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jccoefct.c; path = libs/libjpeg/jccoefct.c; sourceTree = "<group>"; };
   1.167 +		0669D6D11BAD024700611CFA /* jccolor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jccolor.c; path = libs/libjpeg/jccolor.c; sourceTree = "<group>"; };
   1.168 +		0669D6D21BAD024700611CFA /* jcdctmgr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcdctmgr.c; path = libs/libjpeg/jcdctmgr.c; sourceTree = "<group>"; };
   1.169 +		0669D6D31BAD024700611CFA /* jchuff.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jchuff.c; path = libs/libjpeg/jchuff.c; sourceTree = "<group>"; };
   1.170 +		0669D6D41BAD024700611CFA /* jchuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jchuff.h; path = libs/libjpeg/jchuff.h; sourceTree = "<group>"; };
   1.171 +		0669D6D51BAD024700611CFA /* jcinit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcinit.c; path = libs/libjpeg/jcinit.c; sourceTree = "<group>"; };
   1.172 +		0669D6D61BAD024700611CFA /* jcmainct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcmainct.c; path = libs/libjpeg/jcmainct.c; sourceTree = "<group>"; };
   1.173 +		0669D6D71BAD024700611CFA /* jcmarker.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcmarker.c; path = libs/libjpeg/jcmarker.c; sourceTree = "<group>"; };
   1.174 +		0669D6D81BAD024700611CFA /* jcmaster.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcmaster.c; path = libs/libjpeg/jcmaster.c; sourceTree = "<group>"; };
   1.175 +		0669D6D91BAD024700611CFA /* jcomapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcomapi.c; path = libs/libjpeg/jcomapi.c; sourceTree = "<group>"; };
   1.176 +		0669D6DA1BAD024700611CFA /* jconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jconfig.h; path = libs/libjpeg/jconfig.h; sourceTree = "<group>"; };
   1.177 +		0669D6DB1BAD024700611CFA /* jcparam.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcparam.c; path = libs/libjpeg/jcparam.c; sourceTree = "<group>"; };
   1.178 +		0669D6DC1BAD024700611CFA /* jcphuff.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcphuff.c; path = libs/libjpeg/jcphuff.c; sourceTree = "<group>"; };
   1.179 +		0669D6DD1BAD024700611CFA /* jcprepct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcprepct.c; path = libs/libjpeg/jcprepct.c; sourceTree = "<group>"; };
   1.180 +		0669D6DE1BAD024700611CFA /* jcsample.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jcsample.c; path = libs/libjpeg/jcsample.c; sourceTree = "<group>"; };
   1.181 +		0669D6DF1BAD024700611CFA /* jctrans.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jctrans.c; path = libs/libjpeg/jctrans.c; sourceTree = "<group>"; };
   1.182 +		0669D6E01BAD024700611CFA /* jdapimin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdapimin.c; path = libs/libjpeg/jdapimin.c; sourceTree = "<group>"; };
   1.183 +		0669D6E11BAD024700611CFA /* jdapistd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdapistd.c; path = libs/libjpeg/jdapistd.c; sourceTree = "<group>"; };
   1.184 +		0669D6E21BAD024700611CFA /* jdatadst.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdatadst.c; path = libs/libjpeg/jdatadst.c; sourceTree = "<group>"; };
   1.185 +		0669D6E31BAD024700611CFA /* jdatasrc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdatasrc.c; path = libs/libjpeg/jdatasrc.c; sourceTree = "<group>"; };
   1.186 +		0669D6E41BAD024700611CFA /* jdcoefct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdcoefct.c; path = libs/libjpeg/jdcoefct.c; sourceTree = "<group>"; };
   1.187 +		0669D6E51BAD024700611CFA /* jdcolor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdcolor.c; path = libs/libjpeg/jdcolor.c; sourceTree = "<group>"; };
   1.188 +		0669D6E61BAD024700611CFA /* jdct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jdct.h; path = libs/libjpeg/jdct.h; sourceTree = "<group>"; };
   1.189 +		0669D6E71BAD024700611CFA /* jddctmgr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jddctmgr.c; path = libs/libjpeg/jddctmgr.c; sourceTree = "<group>"; };
   1.190 +		0669D6E81BAD024700611CFA /* jdhuff.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdhuff.c; path = libs/libjpeg/jdhuff.c; sourceTree = "<group>"; };
   1.191 +		0669D6E91BAD024700611CFA /* jdhuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jdhuff.h; path = libs/libjpeg/jdhuff.h; sourceTree = "<group>"; };
   1.192 +		0669D6EA1BAD024700611CFA /* jdinput.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdinput.c; path = libs/libjpeg/jdinput.c; sourceTree = "<group>"; };
   1.193 +		0669D6EB1BAD024700611CFA /* jdmainct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdmainct.c; path = libs/libjpeg/jdmainct.c; sourceTree = "<group>"; };
   1.194 +		0669D6EC1BAD024700611CFA /* jdmarker.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdmarker.c; path = libs/libjpeg/jdmarker.c; sourceTree = "<group>"; };
   1.195 +		0669D6ED1BAD024700611CFA /* jdmaster.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdmaster.c; path = libs/libjpeg/jdmaster.c; sourceTree = "<group>"; };
   1.196 +		0669D6EE1BAD024700611CFA /* jdmerge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdmerge.c; path = libs/libjpeg/jdmerge.c; sourceTree = "<group>"; };
   1.197 +		0669D6EF1BAD024700611CFA /* jdphuff.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdphuff.c; path = libs/libjpeg/jdphuff.c; sourceTree = "<group>"; };
   1.198 +		0669D6F01BAD024700611CFA /* jdpostct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdpostct.c; path = libs/libjpeg/jdpostct.c; sourceTree = "<group>"; };
   1.199 +		0669D6F11BAD024700611CFA /* jdsample.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdsample.c; path = libs/libjpeg/jdsample.c; sourceTree = "<group>"; };
   1.200 +		0669D6F21BAD024700611CFA /* jdtrans.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jdtrans.c; path = libs/libjpeg/jdtrans.c; sourceTree = "<group>"; };
   1.201 +		0669D6F31BAD024700611CFA /* jerror.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jerror.c; path = libs/libjpeg/jerror.c; sourceTree = "<group>"; };
   1.202 +		0669D6F41BAD024700611CFA /* jerror.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jerror.h; path = libs/libjpeg/jerror.h; sourceTree = "<group>"; };
   1.203 +		0669D6F51BAD024700611CFA /* jfdctflt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jfdctflt.c; path = libs/libjpeg/jfdctflt.c; sourceTree = "<group>"; };
   1.204 +		0669D6F61BAD024700611CFA /* jfdctfst.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jfdctfst.c; path = libs/libjpeg/jfdctfst.c; sourceTree = "<group>"; };
   1.205 +		0669D6F71BAD024700611CFA /* jfdctint.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jfdctint.c; path = libs/libjpeg/jfdctint.c; sourceTree = "<group>"; };
   1.206 +		0669D6F81BAD024700611CFA /* jidctflt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jidctflt.c; path = libs/libjpeg/jidctflt.c; sourceTree = "<group>"; };
   1.207 +		0669D6F91BAD024700611CFA /* jidctfst.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jidctfst.c; path = libs/libjpeg/jidctfst.c; sourceTree = "<group>"; };
   1.208 +		0669D6FA1BAD024700611CFA /* jidctint.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jidctint.c; path = libs/libjpeg/jidctint.c; sourceTree = "<group>"; };
   1.209 +		0669D6FB1BAD024700611CFA /* jidctred.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jidctred.c; path = libs/libjpeg/jidctred.c; sourceTree = "<group>"; };
   1.210 +		0669D6FC1BAD024700611CFA /* jinclude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jinclude.h; path = libs/libjpeg/jinclude.h; sourceTree = "<group>"; };
   1.211 +		0669D6FD1BAD024700611CFA /* jmemmgr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jmemmgr.c; path = libs/libjpeg/jmemmgr.c; sourceTree = "<group>"; };
   1.212 +		0669D6FE1BAD024700611CFA /* jmemnobs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jmemnobs.c; path = libs/libjpeg/jmemnobs.c; sourceTree = "<group>"; };
   1.213 +		0669D6FF1BAD024700611CFA /* jmemsys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jmemsys.h; path = libs/libjpeg/jmemsys.h; sourceTree = "<group>"; };
   1.214 +		0669D7001BAD024700611CFA /* jmorecfg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jmorecfg.h; path = libs/libjpeg/jmorecfg.h; sourceTree = "<group>"; };
   1.215 +		0669D7011BAD024700611CFA /* jpegint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jpegint.h; path = libs/libjpeg/jpegint.h; sourceTree = "<group>"; };
   1.216 +		0669D7021BAD024700611CFA /* jpeglib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jpeglib.h; path = libs/libjpeg/jpeglib.h; sourceTree = "<group>"; };
   1.217 +		0669D7031BAD024700611CFA /* jquant1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jquant1.c; path = libs/libjpeg/jquant1.c; sourceTree = "<group>"; };
   1.218 +		0669D7041BAD024700611CFA /* jquant2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jquant2.c; path = libs/libjpeg/jquant2.c; sourceTree = "<group>"; };
   1.219 +		0669D7051BAD024700611CFA /* jutils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = jutils.c; path = libs/libjpeg/jutils.c; sourceTree = "<group>"; };
   1.220 +		0669D7061BAD024700611CFA /* jversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jversion.h; path = libs/libjpeg/jversion.h; sourceTree = "<group>"; };
   1.221 +		0669D7351BAD025B00611CFA /* png.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = png.c; path = libs/libpng/png.c; sourceTree = "<group>"; };
   1.222 +		0669D7361BAD025B00611CFA /* png.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = png.h; path = libs/libpng/png.h; sourceTree = "<group>"; };
   1.223 +		0669D7371BAD025B00611CFA /* pngconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pngconf.h; path = libs/libpng/pngconf.h; sourceTree = "<group>"; };
   1.224 +		0669D7381BAD025B00611CFA /* pngerror.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngerror.c; path = libs/libpng/pngerror.c; sourceTree = "<group>"; };
   1.225 +		0669D7391BAD025B00611CFA /* pnggccrd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pnggccrd.c; path = libs/libpng/pnggccrd.c; sourceTree = "<group>"; };
   1.226 +		0669D73A1BAD025B00611CFA /* pngget.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngget.c; path = libs/libpng/pngget.c; sourceTree = "<group>"; };
   1.227 +		0669D73B1BAD025B00611CFA /* pngmem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngmem.c; path = libs/libpng/pngmem.c; sourceTree = "<group>"; };
   1.228 +		0669D73C1BAD025B00611CFA /* pngpread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngpread.c; path = libs/libpng/pngpread.c; sourceTree = "<group>"; };
   1.229 +		0669D73D1BAD025B00611CFA /* pngread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngread.c; path = libs/libpng/pngread.c; sourceTree = "<group>"; };
   1.230 +		0669D73E1BAD025B00611CFA /* pngrio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngrio.c; path = libs/libpng/pngrio.c; sourceTree = "<group>"; };
   1.231 +		0669D73F1BAD025B00611CFA /* pngrtran.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngrtran.c; path = libs/libpng/pngrtran.c; sourceTree = "<group>"; };
   1.232 +		0669D7401BAD025B00611CFA /* pngrutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngrutil.c; path = libs/libpng/pngrutil.c; sourceTree = "<group>"; };
   1.233 +		0669D7411BAD025B00611CFA /* pngset.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngset.c; path = libs/libpng/pngset.c; sourceTree = "<group>"; };
   1.234 +		0669D7421BAD025B00611CFA /* pngtrans.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngtrans.c; path = libs/libpng/pngtrans.c; sourceTree = "<group>"; };
   1.235 +		0669D7431BAD025B00611CFA /* pngvcrd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngvcrd.c; path = libs/libpng/pngvcrd.c; sourceTree = "<group>"; };
   1.236 +		0669D7441BAD025B00611CFA /* pngwio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngwio.c; path = libs/libpng/pngwio.c; sourceTree = "<group>"; };
   1.237 +		0669D7451BAD025B00611CFA /* pngwrite.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngwrite.c; path = libs/libpng/pngwrite.c; sourceTree = "<group>"; };
   1.238 +		0669D7461BAD025B00611CFA /* pngwtran.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngwtran.c; path = libs/libpng/pngwtran.c; sourceTree = "<group>"; };
   1.239 +		0669D7471BAD025B00611CFA /* pngwutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pngwutil.c; path = libs/libpng/pngwutil.c; sourceTree = "<group>"; };
   1.240 +		0669D7591BAD027000611CFA /* adler32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = adler32.c; path = libs/zlib/adler32.c; sourceTree = "<group>"; };
   1.241 +		0669D75A1BAD027000611CFA /* compress.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compress.c; path = libs/zlib/compress.c; sourceTree = "<group>"; };
   1.242 +		0669D75B1BAD027000611CFA /* crc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = crc32.c; path = libs/zlib/crc32.c; sourceTree = "<group>"; };
   1.243 +		0669D75C1BAD027000611CFA /* crc32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = crc32.h; path = libs/zlib/crc32.h; sourceTree = "<group>"; };
   1.244 +		0669D75D1BAD027000611CFA /* deflate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = deflate.c; path = libs/zlib/deflate.c; sourceTree = "<group>"; };
   1.245 +		0669D75E1BAD027000611CFA /* deflate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = deflate.h; path = libs/zlib/deflate.h; sourceTree = "<group>"; };
   1.246 +		0669D75F1BAD027000611CFA /* gzio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = gzio.c; path = libs/zlib/gzio.c; sourceTree = "<group>"; };
   1.247 +		0669D7601BAD027000611CFA /* infback.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = infback.c; path = libs/zlib/infback.c; sourceTree = "<group>"; };
   1.248 +		0669D7611BAD027000611CFA /* inffast.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inffast.c; path = libs/zlib/inffast.c; sourceTree = "<group>"; };
   1.249 +		0669D7621BAD027000611CFA /* inffast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = inffast.h; path = libs/zlib/inffast.h; sourceTree = "<group>"; };
   1.250 +		0669D7631BAD027000611CFA /* inffixed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = inffixed.h; path = libs/zlib/inffixed.h; sourceTree = "<group>"; };
   1.251 +		0669D7641BAD027000611CFA /* inflate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inflate.c; path = libs/zlib/inflate.c; sourceTree = "<group>"; };
   1.252 +		0669D7651BAD027000611CFA /* inflate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = inflate.h; path = libs/zlib/inflate.h; sourceTree = "<group>"; };
   1.253 +		0669D7661BAD027000611CFA /* inftrees.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inftrees.c; path = libs/zlib/inftrees.c; sourceTree = "<group>"; };
   1.254 +		0669D7671BAD027000611CFA /* inftrees.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = inftrees.h; path = libs/zlib/inftrees.h; sourceTree = "<group>"; };
   1.255 +		0669D7681BAD027000611CFA /* trees.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trees.c; path = libs/zlib/trees.c; sourceTree = "<group>"; };
   1.256 +		0669D7691BAD027000611CFA /* trees.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = trees.h; path = libs/zlib/trees.h; sourceTree = "<group>"; };
   1.257 +		0669D76A1BAD027000611CFA /* uncompr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = uncompr.c; path = libs/zlib/uncompr.c; sourceTree = "<group>"; };
   1.258 +		0669D76B1BAD027000611CFA /* zconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = zconf.h; path = libs/zlib/zconf.h; sourceTree = "<group>"; };
   1.259 +		0669D76C1BAD027000611CFA /* zlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = zlib.h; path = libs/zlib/zlib.h; sourceTree = "<group>"; };
   1.260 +		0669D76D1BAD027000611CFA /* zutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = zutil.c; path = libs/zlib/zutil.c; sourceTree = "<group>"; };
   1.261 +		0669D76E1BAD027000611CFA /* zutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = zutil.h; path = libs/zlib/zutil.h; sourceTree = "<group>"; };
   1.262 +		0669D77C1BAD02A200611CFA /* test.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = test.p.glsl; path = sdr/test.p.glsl; sourceTree = "<group>"; };
   1.263 +		0669D77D1BAD02A200611CFA /* test.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = test.v.glsl; path = sdr/test.v.glsl; sourceTree = "<group>"; };
   1.264 +		0669D77E1BAD02A200611CFA /* text.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = text.p.glsl; path = sdr/text.p.glsl; sourceTree = "<group>"; };
   1.265 +		0669D77F1BAD02A200611CFA /* text.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = text.v.glsl; path = sdr/text.v.glsl; sourceTree = "<group>"; };
   1.266 +		0669D7801BAD02A200611CFA /* tunnel.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tunnel.p.glsl; path = sdr/tunnel.p.glsl; sourceTree = "<group>"; };
   1.267 +		0669D7811BAD02A200611CFA /* tunnel.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tunnel.v.glsl; path = sdr/tunnel.v.glsl; sourceTree = "<group>"; };
   1.268 +		0669D7891BAD02DC00611CFA /* stonewall_normal.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = stonewall_normal.jpg; path = data/stonewall_normal.jpg; sourceTree = "<group>"; };
   1.269 +		0669D78A1BAD02DC00611CFA /* stonewall.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = stonewall.jpg; path = data/stonewall.jpg; sourceTree = "<group>"; };
   1.270 +		0669D78B1BAD02DC00611CFA /* text.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = text.png; path = data/text.png; sourceTree = "<group>"; };
   1.271 +		0669D78C1BAD02DC00611CFA /* tiles.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = tiles.jpg; path = data/tiles.jpg; sourceTree = "<group>"; };
   1.272  /* End PBXFileReference section */
   1.273  
   1.274  /* Begin PBXFrameworksBuildPhase section */
   1.275 @@ -37,6 +295,9 @@
   1.276  		0669D63E1BA851BE00611CFA = {
   1.277  			isa = PBXGroup;
   1.278  			children = (
   1.279 +				0669D7881BAD02B000611CFA /* data */,
   1.280 +				0669D77B1BAD028300611CFA /* sdr */,
   1.281 +				0669D6971BAD01C200611CFA /* libs */,
   1.282  				0669D6761BA858D600611CFA /* src */,
   1.283  				0669D6741BA858BF00611CFA /* Info.plist */,
   1.284  				0669D6481BA851BE00611CFA /* Products */,
   1.285 @@ -54,6 +315,21 @@
   1.286  		0669D6761BA858D600611CFA /* src */ = {
   1.287  			isa = PBXGroup;
   1.288  			children = (
   1.289 +				0669D6821BACDF6C00611CFA /* cam.c */,
   1.290 +				0669D6831BACDF6C00611CFA /* cam.h */,
   1.291 +				0669D6841BACDF6C00611CFA /* config.h */,
   1.292 +				0669D6851BACDF6C00611CFA /* istereo.c */,
   1.293 +				0669D6861BACDF6C00611CFA /* istereo.h */,
   1.294 +				0669D6871BACDF6C00611CFA /* opengl.h */,
   1.295 +				0669D6881BACDF6C00611CFA /* respath.c */,
   1.296 +				0669D6891BACDF6C00611CFA /* respath.h */,
   1.297 +				0669D68A1BACDF6C00611CFA /* sanegl.c */,
   1.298 +				0669D68B1BACDF6C00611CFA /* sanegl.h */,
   1.299 +				0669D68C1BACDF6C00611CFA /* sdr.c */,
   1.300 +				0669D68D1BACDF6C00611CFA /* sdr.h */,
   1.301 +				0669D68E1BACDF6C00611CFA /* tex.c */,
   1.302 +				0669D68F1BACDF6C00611CFA /* tex.h */,
   1.303 +				0669D6901BACDF6C00611CFA /* ui.h */,
   1.304  				0669D6791BA85DCC00611CFA /* ios */,
   1.305  			);
   1.306  			name = src;
   1.307 @@ -71,6 +347,206 @@
   1.308  			name = ios;
   1.309  			sourceTree = "<group>";
   1.310  		};
   1.311 +		0669D6971BAD01C200611CFA /* libs */ = {
   1.312 +			isa = PBXGroup;
   1.313 +			children = (
   1.314 +				0669D69C1BAD01EA00611CFA /* vmath */,
   1.315 +				0669D69B1BAD01E300611CFA /* imago2 */,
   1.316 +				0669D69A1BAD01DD00611CFA /* jpeglib */,
   1.317 +				0669D6991BAD01D500611CFA /* libpng */,
   1.318 +				0669D6981BAD01C900611CFA /* zlib */,
   1.319 +			);
   1.320 +			name = libs;
   1.321 +			sourceTree = "<group>";
   1.322 +		};
   1.323 +		0669D6981BAD01C900611CFA /* zlib */ = {
   1.324 +			isa = PBXGroup;
   1.325 +			children = (
   1.326 +				0669D7591BAD027000611CFA /* adler32.c */,
   1.327 +				0669D75A1BAD027000611CFA /* compress.c */,
   1.328 +				0669D75B1BAD027000611CFA /* crc32.c */,
   1.329 +				0669D75C1BAD027000611CFA /* crc32.h */,
   1.330 +				0669D75D1BAD027000611CFA /* deflate.c */,
   1.331 +				0669D75E1BAD027000611CFA /* deflate.h */,
   1.332 +				0669D75F1BAD027000611CFA /* gzio.c */,
   1.333 +				0669D7601BAD027000611CFA /* infback.c */,
   1.334 +				0669D7611BAD027000611CFA /* inffast.c */,
   1.335 +				0669D7621BAD027000611CFA /* inffast.h */,
   1.336 +				0669D7631BAD027000611CFA /* inffixed.h */,
   1.337 +				0669D7641BAD027000611CFA /* inflate.c */,
   1.338 +				0669D7651BAD027000611CFA /* inflate.h */,
   1.339 +				0669D7661BAD027000611CFA /* inftrees.c */,
   1.340 +				0669D7671BAD027000611CFA /* inftrees.h */,
   1.341 +				0669D7681BAD027000611CFA /* trees.c */,
   1.342 +				0669D7691BAD027000611CFA /* trees.h */,
   1.343 +				0669D76A1BAD027000611CFA /* uncompr.c */,
   1.344 +				0669D76B1BAD027000611CFA /* zconf.h */,
   1.345 +				0669D76C1BAD027000611CFA /* zlib.h */,
   1.346 +				0669D76D1BAD027000611CFA /* zutil.c */,
   1.347 +				0669D76E1BAD027000611CFA /* zutil.h */,
   1.348 +			);
   1.349 +			name = zlib;
   1.350 +			sourceTree = "<group>";
   1.351 +		};
   1.352 +		0669D6991BAD01D500611CFA /* libpng */ = {
   1.353 +			isa = PBXGroup;
   1.354 +			children = (
   1.355 +				0669D7351BAD025B00611CFA /* png.c */,
   1.356 +				0669D7361BAD025B00611CFA /* png.h */,
   1.357 +				0669D7371BAD025B00611CFA /* pngconf.h */,
   1.358 +				0669D7381BAD025B00611CFA /* pngerror.c */,
   1.359 +				0669D7391BAD025B00611CFA /* pnggccrd.c */,
   1.360 +				0669D73A1BAD025B00611CFA /* pngget.c */,
   1.361 +				0669D73B1BAD025B00611CFA /* pngmem.c */,
   1.362 +				0669D73C1BAD025B00611CFA /* pngpread.c */,
   1.363 +				0669D73D1BAD025B00611CFA /* pngread.c */,
   1.364 +				0669D73E1BAD025B00611CFA /* pngrio.c */,
   1.365 +				0669D73F1BAD025B00611CFA /* pngrtran.c */,
   1.366 +				0669D7401BAD025B00611CFA /* pngrutil.c */,
   1.367 +				0669D7411BAD025B00611CFA /* pngset.c */,
   1.368 +				0669D7421BAD025B00611CFA /* pngtrans.c */,
   1.369 +				0669D7431BAD025B00611CFA /* pngvcrd.c */,
   1.370 +				0669D7441BAD025B00611CFA /* pngwio.c */,
   1.371 +				0669D7451BAD025B00611CFA /* pngwrite.c */,
   1.372 +				0669D7461BAD025B00611CFA /* pngwtran.c */,
   1.373 +				0669D7471BAD025B00611CFA /* pngwutil.c */,
   1.374 +			);
   1.375 +			name = libpng;
   1.376 +			sourceTree = "<group>";
   1.377 +		};
   1.378 +		0669D69A1BAD01DD00611CFA /* jpeglib */ = {
   1.379 +			isa = PBXGroup;
   1.380 +			children = (
   1.381 +				0669D6CD1BAD024700611CFA /* cderror.h */,
   1.382 +				0669D6CE1BAD024700611CFA /* jcapimin.c */,
   1.383 +				0669D6CF1BAD024700611CFA /* jcapistd.c */,
   1.384 +				0669D6D01BAD024700611CFA /* jccoefct.c */,
   1.385 +				0669D6D11BAD024700611CFA /* jccolor.c */,
   1.386 +				0669D6D21BAD024700611CFA /* jcdctmgr.c */,
   1.387 +				0669D6D31BAD024700611CFA /* jchuff.c */,
   1.388 +				0669D6D41BAD024700611CFA /* jchuff.h */,
   1.389 +				0669D6D51BAD024700611CFA /* jcinit.c */,
   1.390 +				0669D6D61BAD024700611CFA /* jcmainct.c */,
   1.391 +				0669D6D71BAD024700611CFA /* jcmarker.c */,
   1.392 +				0669D6D81BAD024700611CFA /* jcmaster.c */,
   1.393 +				0669D6D91BAD024700611CFA /* jcomapi.c */,
   1.394 +				0669D6DA1BAD024700611CFA /* jconfig.h */,
   1.395 +				0669D6DB1BAD024700611CFA /* jcparam.c */,
   1.396 +				0669D6DC1BAD024700611CFA /* jcphuff.c */,
   1.397 +				0669D6DD1BAD024700611CFA /* jcprepct.c */,
   1.398 +				0669D6DE1BAD024700611CFA /* jcsample.c */,
   1.399 +				0669D6DF1BAD024700611CFA /* jctrans.c */,
   1.400 +				0669D6E01BAD024700611CFA /* jdapimin.c */,
   1.401 +				0669D6E11BAD024700611CFA /* jdapistd.c */,
   1.402 +				0669D6E21BAD024700611CFA /* jdatadst.c */,
   1.403 +				0669D6E31BAD024700611CFA /* jdatasrc.c */,
   1.404 +				0669D6E41BAD024700611CFA /* jdcoefct.c */,
   1.405 +				0669D6E51BAD024700611CFA /* jdcolor.c */,
   1.406 +				0669D6E61BAD024700611CFA /* jdct.h */,
   1.407 +				0669D6E71BAD024700611CFA /* jddctmgr.c */,
   1.408 +				0669D6E81BAD024700611CFA /* jdhuff.c */,
   1.409 +				0669D6E91BAD024700611CFA /* jdhuff.h */,
   1.410 +				0669D6EA1BAD024700611CFA /* jdinput.c */,
   1.411 +				0669D6EB1BAD024700611CFA /* jdmainct.c */,
   1.412 +				0669D6EC1BAD024700611CFA /* jdmarker.c */,
   1.413 +				0669D6ED1BAD024700611CFA /* jdmaster.c */,
   1.414 +				0669D6EE1BAD024700611CFA /* jdmerge.c */,
   1.415 +				0669D6EF1BAD024700611CFA /* jdphuff.c */,
   1.416 +				0669D6F01BAD024700611CFA /* jdpostct.c */,
   1.417 +				0669D6F11BAD024700611CFA /* jdsample.c */,
   1.418 +				0669D6F21BAD024700611CFA /* jdtrans.c */,
   1.419 +				0669D6F31BAD024700611CFA /* jerror.c */,
   1.420 +				0669D6F41BAD024700611CFA /* jerror.h */,
   1.421 +				0669D6F51BAD024700611CFA /* jfdctflt.c */,
   1.422 +				0669D6F61BAD024700611CFA /* jfdctfst.c */,
   1.423 +				0669D6F71BAD024700611CFA /* jfdctint.c */,
   1.424 +				0669D6F81BAD024700611CFA /* jidctflt.c */,
   1.425 +				0669D6F91BAD024700611CFA /* jidctfst.c */,
   1.426 +				0669D6FA1BAD024700611CFA /* jidctint.c */,
   1.427 +				0669D6FB1BAD024700611CFA /* jidctred.c */,
   1.428 +				0669D6FC1BAD024700611CFA /* jinclude.h */,
   1.429 +				0669D6FD1BAD024700611CFA /* jmemmgr.c */,
   1.430 +				0669D6FE1BAD024700611CFA /* jmemnobs.c */,
   1.431 +				0669D6FF1BAD024700611CFA /* jmemsys.h */,
   1.432 +				0669D7001BAD024700611CFA /* jmorecfg.h */,
   1.433 +				0669D7011BAD024700611CFA /* jpegint.h */,
   1.434 +				0669D7021BAD024700611CFA /* jpeglib.h */,
   1.435 +				0669D7031BAD024700611CFA /* jquant1.c */,
   1.436 +				0669D7041BAD024700611CFA /* jquant2.c */,
   1.437 +				0669D7051BAD024700611CFA /* jutils.c */,
   1.438 +				0669D7061BAD024700611CFA /* jversion.h */,
   1.439 +			);
   1.440 +			name = jpeglib;
   1.441 +			sourceTree = "<group>";
   1.442 +		};
   1.443 +		0669D69B1BAD01E300611CFA /* imago2 */ = {
   1.444 +			isa = PBXGroup;
   1.445 +			children = (
   1.446 +				0669D6BD1BAD022C00611CFA /* conv.c */,
   1.447 +				0669D6BE1BAD022C00611CFA /* file_jpeg.c */,
   1.448 +				0669D6BF1BAD022C00611CFA /* file_png.c */,
   1.449 +				0669D6C01BAD022C00611CFA /* file_ppm.c */,
   1.450 +				0669D6C11BAD022C00611CFA /* ftype_module.c */,
   1.451 +				0669D6C21BAD022C00611CFA /* ftype_module.h */,
   1.452 +				0669D6C31BAD022C00611CFA /* imago2.c */,
   1.453 +				0669D6C41BAD022C00611CFA /* imago2.h */,
   1.454 +				0669D6C51BAD022C00611CFA /* modules.c */,
   1.455 +			);
   1.456 +			name = imago2;
   1.457 +			sourceTree = "<group>";
   1.458 +		};
   1.459 +		0669D69C1BAD01EA00611CFA /* vmath */ = {
   1.460 +			isa = PBXGroup;
   1.461 +			children = (
   1.462 +				0669D69D1BAD020B00611CFA /* basis_c.c */,
   1.463 +				0669D69E1BAD020B00611CFA /* basis.h */,
   1.464 +				0669D69F1BAD020B00611CFA /* geom.c */,
   1.465 +				0669D6A01BAD020B00611CFA /* geom.h */,
   1.466 +				0669D6A11BAD020B00611CFA /* matrix_c.c */,
   1.467 +				0669D6A21BAD020B00611CFA /* matrix.h */,
   1.468 +				0669D6A31BAD020B00611CFA /* matrix.inl */,
   1.469 +				0669D6A41BAD020B00611CFA /* quat_c.c */,
   1.470 +				0669D6A51BAD020B00611CFA /* quat.h */,
   1.471 +				0669D6A61BAD020B00611CFA /* quat.inl */,
   1.472 +				0669D6A71BAD020B00611CFA /* ray_c.c */,
   1.473 +				0669D6A81BAD020B00611CFA /* ray.h */,
   1.474 +				0669D6A91BAD020B00611CFA /* ray.inl */,
   1.475 +				0669D6AA1BAD020B00611CFA /* sphvec.h */,
   1.476 +				0669D6AB1BAD020B00611CFA /* vector.h */,
   1.477 +				0669D6AC1BAD020B00611CFA /* vector.inl */,
   1.478 +				0669D6AD1BAD020B00611CFA /* vmath_config.h */,
   1.479 +				0669D6AE1BAD020B00611CFA /* vmath_types.h */,
   1.480 +				0669D6AF1BAD020B00611CFA /* vmath.c */,
   1.481 +				0669D6B01BAD020B00611CFA /* vmath.h */,
   1.482 +				0669D6B11BAD020B00611CFA /* vmath.inl */,
   1.483 +			);
   1.484 +			name = vmath;
   1.485 +			sourceTree = "<group>";
   1.486 +		};
   1.487 +		0669D77B1BAD028300611CFA /* sdr */ = {
   1.488 +			isa = PBXGroup;
   1.489 +			children = (
   1.490 +				0669D77C1BAD02A200611CFA /* test.p.glsl */,
   1.491 +				0669D77D1BAD02A200611CFA /* test.v.glsl */,
   1.492 +				0669D77E1BAD02A200611CFA /* text.p.glsl */,
   1.493 +				0669D77F1BAD02A200611CFA /* text.v.glsl */,
   1.494 +				0669D7801BAD02A200611CFA /* tunnel.p.glsl */,
   1.495 +				0669D7811BAD02A200611CFA /* tunnel.v.glsl */,
   1.496 +			);
   1.497 +			name = sdr;
   1.498 +			sourceTree = "<group>";
   1.499 +		};
   1.500 +		0669D7881BAD02B000611CFA /* data */ = {
   1.501 +			isa = PBXGroup;
   1.502 +			children = (
   1.503 +				0669D7891BAD02DC00611CFA /* stonewall_normal.jpg */,
   1.504 +				0669D78A1BAD02DC00611CFA /* stonewall.jpg */,
   1.505 +				0669D78B1BAD02DC00611CFA /* text.png */,
   1.506 +				0669D78C1BAD02DC00611CFA /* tiles.jpg */,
   1.507 +			);
   1.508 +			name = data;
   1.509 +			sourceTree = "<group>";
   1.510 +		};
   1.511  /* End PBXGroup section */
   1.512  
   1.513  /* Begin PBXNativeTarget section */
   1.514 @@ -129,7 +605,17 @@
   1.515  			isa = PBXResourcesBuildPhase;
   1.516  			buildActionMask = 2147483647;
   1.517  			files = (
   1.518 +				0669D7861BAD02A200611CFA /* tunnel.p.glsl in Resources */,
   1.519  				0669D6751BA858BF00611CFA /* Info.plist in Resources */,
   1.520 +				0669D7821BAD02A200611CFA /* test.p.glsl in Resources */,
   1.521 +				0669D78D1BAD02DC00611CFA /* stonewall_normal.jpg in Resources */,
   1.522 +				0669D78E1BAD02DC00611CFA /* stonewall.jpg in Resources */,
   1.523 +				0669D7841BAD02A200611CFA /* text.p.glsl in Resources */,
   1.524 +				0669D7901BAD02DC00611CFA /* tiles.jpg in Resources */,
   1.525 +				0669D7871BAD02A200611CFA /* tunnel.v.glsl in Resources */,
   1.526 +				0669D78F1BAD02DC00611CFA /* text.png in Resources */,
   1.527 +				0669D7851BAD02A200611CFA /* text.v.glsl in Resources */,
   1.528 +				0669D7831BAD02A200611CFA /* test.v.glsl in Resources */,
   1.529  			);
   1.530  			runOnlyForDeploymentPostprocessing = 0;
   1.531  		};
   1.532 @@ -140,9 +626,103 @@
   1.533  			isa = PBXSourcesBuildPhase;
   1.534  			buildActionMask = 2147483647;
   1.535  			files = (
   1.536 +				0669D7121BAD024700611CFA /* jcparam.c in Sources */,
   1.537 +				0669D7551BAD025B00611CFA /* pngwio.c in Sources */,
   1.538 +				0669D70F1BAD024700611CFA /* jcmarker.c in Sources */,
   1.539 +				0669D6CB1BAD022C00611CFA /* imago2.c in Sources */,
   1.540 +				0669D70B1BAD024700611CFA /* jcdctmgr.c in Sources */,
   1.541 +				0669D6921BACDF6C00611CFA /* istereo.c in Sources */,
   1.542 +				0669D72F1BAD024700611CFA /* jidctred.c in Sources */,
   1.543 +				0669D7481BAD025B00611CFA /* png.c in Sources */,
   1.544 +				0669D7201BAD024700611CFA /* jdmainct.c in Sources */,
   1.545 +				0669D7531BAD025B00611CFA /* pngtrans.c in Sources */,
   1.546 +				0669D6931BACDF6C00611CFA /* respath.c in Sources */,
   1.547 +				0669D7771BAD027000611CFA /* inftrees.c in Sources */,
   1.548 +				0669D7761BAD027000611CFA /* inflate.c in Sources */,
   1.549 +				0669D6CC1BAD022C00611CFA /* modules.c in Sources */,
   1.550 +				0669D7301BAD024700611CFA /* jmemmgr.c in Sources */,
   1.551 +				0669D72E1BAD024700611CFA /* jidctint.c in Sources */,
   1.552 +				0669D6B81BAD020B00611CFA /* ray_c.c in Sources */,
   1.553 +				0669D71D1BAD024700611CFA /* jddctmgr.c in Sources */,
   1.554 +				0669D7571BAD025B00611CFA /* pngwtran.c in Sources */,
   1.555 +				0669D7081BAD024700611CFA /* jcapistd.c in Sources */,
   1.556 +				0669D72C1BAD024700611CFA /* jidctflt.c in Sources */,
   1.557 +				0669D7511BAD025B00611CFA /* pngrutil.c in Sources */,
   1.558 +				0669D6BB1BAD020B00611CFA /* vmath.c in Sources */,
   1.559 +				0669D7341BAD024700611CFA /* jutils.c in Sources */,
   1.560 +				0669D6CA1BAD022C00611CFA /* ftype_module.c in Sources */,
   1.561 +				0669D7281BAD024700611CFA /* jerror.c in Sources */,
   1.562 +				0669D7221BAD024700611CFA /* jdmaster.c in Sources */,
   1.563 +				0669D76F1BAD027000611CFA /* adler32.c in Sources */,
   1.564 +				0669D7541BAD025B00611CFA /* pngvcrd.c in Sources */,
   1.565 +				0669D72A1BAD024700611CFA /* jfdctfst.c in Sources */,
   1.566 +				0669D7791BAD027000611CFA /* uncompr.c in Sources */,
   1.567 +				0669D6941BACDF6C00611CFA /* sanegl.c in Sources */,
   1.568 +				0669D70D1BAD024700611CFA /* jcinit.c in Sources */,
   1.569 +				0669D6961BACDF6C00611CFA /* tex.c in Sources */,
   1.570 +				0669D7241BAD024700611CFA /* jdphuff.c in Sources */,
   1.571 +				0669D70C1BAD024700611CFA /* jchuff.c in Sources */,
   1.572 +				0669D71B1BAD024700611CFA /* jdcoefct.c in Sources */,
   1.573 +				0669D7091BAD024700611CFA /* jccoefct.c in Sources */,
   1.574  				0669D6801BA85DDE00611CFA /* main.m in Sources */,
   1.575 +				0669D7521BAD025B00611CFA /* pngset.c in Sources */,
   1.576 +				0669D7561BAD025B00611CFA /* pngwrite.c in Sources */,
   1.577 +				0669D7131BAD024700611CFA /* jcphuff.c in Sources */,
   1.578 +				0669D70A1BAD024700611CFA /* jccolor.c in Sources */,
   1.579 +				0669D74F1BAD025B00611CFA /* pngrio.c in Sources */,
   1.580 +				0669D6C81BAD022C00611CFA /* file_png.c in Sources */,
   1.581 +				0669D7231BAD024700611CFA /* jdmerge.c in Sources */,
   1.582 +				0669D77A1BAD027000611CFA /* zutil.c in Sources */,
   1.583 +				0669D7721BAD027000611CFA /* deflate.c in Sources */,
   1.584 +				0669D71F1BAD024700611CFA /* jdinput.c in Sources */,
   1.585 +				0669D7581BAD025B00611CFA /* pngwutil.c in Sources */,
   1.586 +				0669D7261BAD024700611CFA /* jdsample.c in Sources */,
   1.587 +				0669D7701BAD027000611CFA /* compress.c in Sources */,
   1.588 +				0669D7111BAD024700611CFA /* jcomapi.c in Sources */,
   1.589 +				0669D71A1BAD024700611CFA /* jdatasrc.c in Sources */,
   1.590 +				0669D74B1BAD025B00611CFA /* pngget.c in Sources */,
   1.591 +				0669D7211BAD024700611CFA /* jdmarker.c in Sources */,
   1.592 +				0669D7251BAD024700611CFA /* jdpostct.c in Sources */,
   1.593  				0669D6811BA85DDE00611CFA /* viewctl.m in Sources */,
   1.594  				0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */,
   1.595 +				0669D7101BAD024700611CFA /* jcmaster.c in Sources */,
   1.596 +				0669D72B1BAD024700611CFA /* jfdctint.c in Sources */,
   1.597 +				0669D7291BAD024700611CFA /* jfdctflt.c in Sources */,
   1.598 +				0669D6911BACDF6C00611CFA /* cam.c in Sources */,
   1.599 +				0669D7191BAD024700611CFA /* jdatadst.c in Sources */,
   1.600 +				0669D7731BAD027000611CFA /* gzio.c in Sources */,
   1.601 +				0669D6B61BAD020B00611CFA /* quat_c.c in Sources */,
   1.602 +				0669D6C71BAD022C00611CFA /* file_jpeg.c in Sources */,
   1.603 +				0669D7711BAD027000611CFA /* crc32.c in Sources */,
   1.604 +				0669D6B31BAD020B00611CFA /* geom.c in Sources */,
   1.605 +				0669D7741BAD027000611CFA /* infback.c in Sources */,
   1.606 +				0669D74C1BAD025B00611CFA /* pngmem.c in Sources */,
   1.607 +				0669D7271BAD024700611CFA /* jdtrans.c in Sources */,
   1.608 +				0669D6B21BAD020B00611CFA /* basis_c.c in Sources */,
   1.609 +				0669D7161BAD024700611CFA /* jctrans.c in Sources */,
   1.610 +				0669D7311BAD024700611CFA /* jmemnobs.c in Sources */,
   1.611 +				0669D74E1BAD025B00611CFA /* pngread.c in Sources */,
   1.612 +				0669D71E1BAD024700611CFA /* jdhuff.c in Sources */,
   1.613 +				0669D74A1BAD025B00611CFA /* pnggccrd.c in Sources */,
   1.614 +				0669D70E1BAD024700611CFA /* jcmainct.c in Sources */,
   1.615 +				0669D7151BAD024700611CFA /* jcsample.c in Sources */,
   1.616 +				0669D7141BAD024700611CFA /* jcprepct.c in Sources */,
   1.617 +				0669D7751BAD027000611CFA /* inffast.c in Sources */,
   1.618 +				0669D7491BAD025B00611CFA /* pngerror.c in Sources */,
   1.619 +				0669D7171BAD024700611CFA /* jdapimin.c in Sources */,
   1.620 +				0669D7331BAD024700611CFA /* jquant2.c in Sources */,
   1.621 +				0669D74D1BAD025B00611CFA /* pngpread.c in Sources */,
   1.622 +				0669D7071BAD024700611CFA /* jcapimin.c in Sources */,
   1.623 +				0669D6C61BAD022C00611CFA /* conv.c in Sources */,
   1.624 +				0669D6B41BAD020B00611CFA /* matrix_c.c in Sources */,
   1.625 +				0669D7321BAD024700611CFA /* jquant1.c in Sources */,
   1.626 +				0669D6C91BAD022C00611CFA /* file_ppm.c in Sources */,
   1.627 +				0669D72D1BAD024700611CFA /* jidctfst.c in Sources */,
   1.628 +				0669D7501BAD025B00611CFA /* pngrtran.c in Sources */,
   1.629 +				0669D7181BAD024700611CFA /* jdapistd.c in Sources */,
   1.630 +				0669D6951BACDF6C00611CFA /* sdr.c in Sources */,
   1.631 +				0669D7781BAD027000611CFA /* trees.c in Sources */,
   1.632 +				0669D71C1BAD024700611CFA /* jdcolor.c in Sources */,
   1.633  			);
   1.634  			runOnlyForDeploymentPostprocessing = 0;
   1.635  		};
   1.636 @@ -234,6 +814,7 @@
   1.637  		0669D66F1BA851BE00611CFA /* Debug */ = {
   1.638  			isa = XCBuildConfiguration;
   1.639  			buildSettings = {
   1.640 +				ALWAYS_SEARCH_USER_PATHS = YES;
   1.641  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
   1.642  				CODE_SIGN_IDENTITY = "iPhone Developer";
   1.643  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
   1.644 @@ -246,6 +827,7 @@
   1.645  		0669D6701BA851BE00611CFA /* Release */ = {
   1.646  			isa = XCBuildConfiguration;
   1.647  			buildSettings = {
   1.648 +				ALWAYS_SEARCH_USER_PATHS = YES;
   1.649  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
   1.650  				CODE_SIGN_IDENTITY = "iPhone Developer";
   1.651  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/libs/Makefile	Sat Sep 19 05:51:51 2015 +0300
     2.3 @@ -0,0 +1,7 @@
     2.4 +src += $(wildcard libs/zlib/*.c) \
     2.5 +	   $(wildcard libs/libpng/*.c) \
     2.6 +	   $(wildcard libs/libjpeg/*.c) \
     2.7 +	   $(wildcard libs/imago2/*.c) \
     2.8 +	   $(wildcard libs/vmath/*.c)
     2.9 +
    2.10 +incdir += -Ilibs/imago2 -Ilibs/zlib -Ilibs/libpng -Ilibs/libjpeg -Ilibs/vmath
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/libs/imago2/COPYING	Sat Sep 19 05:51:51 2015 +0300
     3.3 @@ -0,0 +1,674 @@
     3.4 +                    GNU GENERAL PUBLIC LICENSE
     3.5 +                       Version 3, 29 June 2007
     3.6 +
     3.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     3.8 + Everyone is permitted to copy and distribute verbatim copies
     3.9 + of this license document, but changing it is not allowed.
    3.10 +
    3.11 +                            Preamble
    3.12 +
    3.13 +  The GNU General Public License is a free, copyleft license for
    3.14 +software and other kinds of works.
    3.15 +
    3.16 +  The licenses for most software and other practical works are designed
    3.17 +to take away your freedom to share and change the works.  By contrast,
    3.18 +the GNU General Public License is intended to guarantee your freedom to
    3.19 +share and change all versions of a program--to make sure it remains free
    3.20 +software for all its users.  We, the Free Software Foundation, use the
    3.21 +GNU General Public License for most of our software; it applies also to
    3.22 +any other work released this way by its authors.  You can apply it to
    3.23 +your programs, too.
    3.24 +
    3.25 +  When we speak of free software, we are referring to freedom, not
    3.26 +price.  Our General Public Licenses are designed to make sure that you
    3.27 +have the freedom to distribute copies of free software (and charge for
    3.28 +them if you wish), that you receive source code or can get it if you
    3.29 +want it, that you can change the software or use pieces of it in new
    3.30 +free programs, and that you know you can do these things.
    3.31 +
    3.32 +  To protect your rights, we need to prevent others from denying you
    3.33 +these rights or asking you to surrender the rights.  Therefore, you have
    3.34 +certain responsibilities if you distribute copies of the software, or if
    3.35 +you modify it: responsibilities to respect the freedom of others.
    3.36 +
    3.37 +  For example, if you distribute copies of such a program, whether
    3.38 +gratis or for a fee, you must pass on to the recipients the same
    3.39 +freedoms that you received.  You must make sure that they, too, receive
    3.40 +or can get the source code.  And you must show them these terms so they
    3.41 +know their rights.
    3.42 +
    3.43 +  Developers that use the GNU GPL protect your rights with two steps:
    3.44 +(1) assert copyright on the software, and (2) offer you this License
    3.45 +giving you legal permission to copy, distribute and/or modify it.
    3.46 +
    3.47 +  For the developers' and authors' protection, the GPL clearly explains
    3.48 +that there is no warranty for this free software.  For both users' and
    3.49 +authors' sake, the GPL requires that modified versions be marked as
    3.50 +changed, so that their problems will not be attributed erroneously to
    3.51 +authors of previous versions.
    3.52 +
    3.53 +  Some devices are designed to deny users access to install or run
    3.54 +modified versions of the software inside them, although the manufacturer
    3.55 +can do so.  This is fundamentally incompatible with the aim of
    3.56 +protecting users' freedom to change the software.  The systematic
    3.57 +pattern of such abuse occurs in the area of products for individuals to
    3.58 +use, which is precisely where it is most unacceptable.  Therefore, we
    3.59 +have designed this version of the GPL to prohibit the practice for those
    3.60 +products.  If such problems arise substantially in other domains, we
    3.61 +stand ready to extend this provision to those domains in future versions
    3.62 +of the GPL, as needed to protect the freedom of users.
    3.63 +
    3.64 +  Finally, every program is threatened constantly by software patents.
    3.65 +States should not allow patents to restrict development and use of
    3.66 +software on general-purpose computers, but in those that do, we wish to
    3.67 +avoid the special danger that patents applied to a free program could
    3.68 +make it effectively proprietary.  To prevent this, the GPL assures that
    3.69 +patents cannot be used to render the program non-free.
    3.70 +
    3.71 +  The precise terms and conditions for copying, distribution and
    3.72 +modification follow.
    3.73 +
    3.74 +                       TERMS AND CONDITIONS
    3.75 +
    3.76 +  0. Definitions.
    3.77 +
    3.78 +  "This License" refers to version 3 of the GNU General Public License.
    3.79 +
    3.80 +  "Copyright" also means copyright-like laws that apply to other kinds of
    3.81 +works, such as semiconductor masks.
    3.82 +
    3.83 +  "The Program" refers to any copyrightable work licensed under this
    3.84 +License.  Each licensee is addressed as "you".  "Licensees" and
    3.85 +"recipients" may be individuals or organizations.
    3.86 +
    3.87 +  To "modify" a work means to copy from or adapt all or part of the work
    3.88 +in a fashion requiring copyright permission, other than the making of an
    3.89 +exact copy.  The resulting work is called a "modified version" of the
    3.90 +earlier work or a work "based on" the earlier work.
    3.91 +
    3.92 +  A "covered work" means either the unmodified Program or a work based
    3.93 +on the Program.
    3.94 +
    3.95 +  To "propagate" a work means to do anything with it that, without
    3.96 +permission, would make you directly or secondarily liable for
    3.97 +infringement under applicable copyright law, except executing it on a
    3.98 +computer or modifying a private copy.  Propagation includes copying,
    3.99 +distribution (with or without modification), making available to the
   3.100 +public, and in some countries other activities as well.
   3.101 +
   3.102 +  To "convey" a work means any kind of propagation that enables other
   3.103 +parties to make or receive copies.  Mere interaction with a user through
   3.104 +a computer network, with no transfer of a copy, is not conveying.
   3.105 +
   3.106 +  An interactive user interface displays "Appropriate Legal Notices"
   3.107 +to the extent that it includes a convenient and prominently visible
   3.108 +feature that (1) displays an appropriate copyright notice, and (2)
   3.109 +tells the user that there is no warranty for the work (except to the
   3.110 +extent that warranties are provided), that licensees may convey the
   3.111 +work under this License, and how to view a copy of this License.  If
   3.112 +the interface presents a list of user commands or options, such as a
   3.113 +menu, a prominent item in the list meets this criterion.
   3.114 +
   3.115 +  1. Source Code.
   3.116 +
   3.117 +  The "source code" for a work means the preferred form of the work
   3.118 +for making modifications to it.  "Object code" means any non-source
   3.119 +form of a work.
   3.120 +
   3.121 +  A "Standard Interface" means an interface that either is an official
   3.122 +standard defined by a recognized standards body, or, in the case of
   3.123 +interfaces specified for a particular programming language, one that
   3.124 +is widely used among developers working in that language.
   3.125 +
   3.126 +  The "System Libraries" of an executable work include anything, other
   3.127 +than the work as a whole, that (a) is included in the normal form of
   3.128 +packaging a Major Component, but which is not part of that Major
   3.129 +Component, and (b) serves only to enable use of the work with that
   3.130 +Major Component, or to implement a Standard Interface for which an
   3.131 +implementation is available to the public in source code form.  A
   3.132 +"Major Component", in this context, means a major essential component
   3.133 +(kernel, window system, and so on) of the specific operating system
   3.134 +(if any) on which the executable work runs, or a compiler used to
   3.135 +produce the work, or an object code interpreter used to run it.
   3.136 +
   3.137 +  The "Corresponding Source" for a work in object code form means all
   3.138 +the source code needed to generate, install, and (for an executable
   3.139 +work) run the object code and to modify the work, including scripts to
   3.140 +control those activities.  However, it does not include the work's
   3.141 +System Libraries, or general-purpose tools or generally available free
   3.142 +programs which are used unmodified in performing those activities but
   3.143 +which are not part of the work.  For example, Corresponding Source
   3.144 +includes interface definition files associated with source files for
   3.145 +the work, and the source code for shared libraries and dynamically
   3.146 +linked subprograms that the work is specifically designed to require,
   3.147 +such as by intimate data communication or control flow between those
   3.148 +subprograms and other parts of the work.
   3.149 +
   3.150 +  The Corresponding Source need not include anything that users
   3.151 +can regenerate automatically from other parts of the Corresponding
   3.152 +Source.
   3.153 +
   3.154 +  The Corresponding Source for a work in source code form is that
   3.155 +same work.
   3.156 +
   3.157 +  2. Basic Permissions.
   3.158 +
   3.159 +  All rights granted under this License are granted for the term of
   3.160 +copyright on the Program, and are irrevocable provided the stated
   3.161 +conditions are met.  This License explicitly affirms your unlimited
   3.162 +permission to run the unmodified Program.  The output from running a
   3.163 +covered work is covered by this License only if the output, given its
   3.164 +content, constitutes a covered work.  This License acknowledges your
   3.165 +rights of fair use or other equivalent, as provided by copyright law.
   3.166 +
   3.167 +  You may make, run and propagate covered works that you do not
   3.168 +convey, without conditions so long as your license otherwise remains
   3.169 +in force.  You may convey covered works to others for the sole purpose
   3.170 +of having them make modifications exclusively for you, or provide you
   3.171 +with facilities for running those works, provided that you comply with
   3.172 +the terms of this License in conveying all material for which you do
   3.173 +not control copyright.  Those thus making or running the covered works
   3.174 +for you must do so exclusively on your behalf, under your direction
   3.175 +and control, on terms that prohibit them from making any copies of
   3.176 +your copyrighted material outside their relationship with you.
   3.177 +
   3.178 +  Conveying under any other circumstances is permitted solely under
   3.179 +the conditions stated below.  Sublicensing is not allowed; section 10
   3.180 +makes it unnecessary.
   3.181 +
   3.182 +  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
   3.183 +
   3.184 +  No covered work shall be deemed part of an effective technological
   3.185 +measure under any applicable law fulfilling obligations under article
   3.186 +11 of the WIPO copyright treaty adopted on 20 December 1996, or
   3.187 +similar laws prohibiting or restricting circumvention of such
   3.188 +measures.
   3.189 +
   3.190 +  When you convey a covered work, you waive any legal power to forbid
   3.191 +circumvention of technological measures to the extent such circumvention
   3.192 +is effected by exercising rights under this License with respect to
   3.193 +the covered work, and you disclaim any intention to limit operation or
   3.194 +modification of the work as a means of enforcing, against the work's
   3.195 +users, your or third parties' legal rights to forbid circumvention of
   3.196 +technological measures.
   3.197 +
   3.198 +  4. Conveying Verbatim Copies.
   3.199 +
   3.200 +  You may convey verbatim copies of the Program's source code as you
   3.201 +receive it, in any medium, provided that you conspicuously and
   3.202 +appropriately publish on each copy an appropriate copyright notice;
   3.203 +keep intact all notices stating that this License and any
   3.204 +non-permissive terms added in accord with section 7 apply to the code;
   3.205 +keep intact all notices of the absence of any warranty; and give all
   3.206 +recipients a copy of this License along with the Program.
   3.207 +
   3.208 +  You may charge any price or no price for each copy that you convey,
   3.209 +and you may offer support or warranty protection for a fee.
   3.210 +
   3.211 +  5. Conveying Modified Source Versions.
   3.212 +
   3.213 +  You may convey a work based on the Program, or the modifications to
   3.214 +produce it from the Program, in the form of source code under the
   3.215 +terms of section 4, provided that you also meet all of these conditions:
   3.216 +
   3.217 +    a) The work must carry prominent notices stating that you modified
   3.218 +    it, and giving a relevant date.
   3.219 +
   3.220 +    b) The work must carry prominent notices stating that it is
   3.221 +    released under this License and any conditions added under section
   3.222 +    7.  This requirement modifies the requirement in section 4 to
   3.223 +    "keep intact all notices".
   3.224 +
   3.225 +    c) You must license the entire work, as a whole, under this
   3.226 +    License to anyone who comes into possession of a copy.  This
   3.227 +    License will therefore apply, along with any applicable section 7
   3.228 +    additional terms, to the whole of the work, and all its parts,
   3.229 +    regardless of how they are packaged.  This License gives no
   3.230 +    permission to license the work in any other way, but it does not
   3.231 +    invalidate such permission if you have separately received it.
   3.232 +
   3.233 +    d) If the work has interactive user interfaces, each must display
   3.234 +    Appropriate Legal Notices; however, if the Program has interactive
   3.235 +    interfaces that do not display Appropriate Legal Notices, your
   3.236 +    work need not make them do so.
   3.237 +
   3.238 +  A compilation of a covered work with other separate and independent
   3.239 +works, which are not by their nature extensions of the covered work,
   3.240 +and which are not combined with it such as to form a larger program,
   3.241 +in or on a volume of a storage or distribution medium, is called an
   3.242 +"aggregate" if the compilation and its resulting copyright are not
   3.243 +used to limit the access or legal rights of the compilation's users
   3.244 +beyond what the individual works permit.  Inclusion of a covered work
   3.245 +in an aggregate does not cause this License to apply to the other
   3.246 +parts of the aggregate.
   3.247 +
   3.248 +  6. Conveying Non-Source Forms.
   3.249 +
   3.250 +  You may convey a covered work in object code form under the terms
   3.251 +of sections 4 and 5, provided that you also convey the
   3.252 +machine-readable Corresponding Source under the terms of this License,
   3.253 +in one of these ways:
   3.254 +
   3.255 +    a) Convey the object code in, or embodied in, a physical product
   3.256 +    (including a physical distribution medium), accompanied by the
   3.257 +    Corresponding Source fixed on a durable physical medium
   3.258 +    customarily used for software interchange.
   3.259 +
   3.260 +    b) Convey the object code in, or embodied in, a physical product
   3.261 +    (including a physical distribution medium), accompanied by a
   3.262 +    written offer, valid for at least three years and valid for as
   3.263 +    long as you offer spare parts or customer support for that product
   3.264 +    model, to give anyone who possesses the object code either (1) a
   3.265 +    copy of the Corresponding Source for all the software in the
   3.266 +    product that is covered by this License, on a durable physical
   3.267 +    medium customarily used for software interchange, for a price no
   3.268 +    more than your reasonable cost of physically performing this
   3.269 +    conveying of source, or (2) access to copy the
   3.270 +    Corresponding Source from a network server at no charge.
   3.271 +
   3.272 +    c) Convey individual copies of the object code with a copy of the
   3.273 +    written offer to provide the Corresponding Source.  This
   3.274 +    alternative is allowed only occasionally and noncommercially, and
   3.275 +    only if you received the object code with such an offer, in accord
   3.276 +    with subsection 6b.
   3.277 +
   3.278 +    d) Convey the object code by offering access from a designated
   3.279 +    place (gratis or for a charge), and offer equivalent access to the
   3.280 +    Corresponding Source in the same way through the same place at no
   3.281 +    further charge.  You need not require recipients to copy the
   3.282 +    Corresponding Source along with the object code.  If the place to
   3.283 +    copy the object code is a network server, the Corresponding Source
   3.284 +    may be on a different server (operated by you or a third party)
   3.285 +    that supports equivalent copying facilities, provided you maintain
   3.286 +    clear directions next to the object code saying where to find the
   3.287 +    Corresponding Source.  Regardless of what server hosts the
   3.288 +    Corresponding Source, you remain obligated to ensure that it is
   3.289 +    available for as long as needed to satisfy these requirements.
   3.290 +
   3.291 +    e) Convey the object code using peer-to-peer transmission, provided
   3.292 +    you inform other peers where the object code and Corresponding
   3.293 +    Source of the work are being offered to the general public at no
   3.294 +    charge under subsection 6d.
   3.295 +
   3.296 +  A separable portion of the object code, whose source code is excluded
   3.297 +from the Corresponding Source as a System Library, need not be
   3.298 +included in conveying the object code work.
   3.299 +
   3.300 +  A "User Product" is either (1) a "consumer product", which means any
   3.301 +tangible personal property which is normally used for personal, family,
   3.302 +or household purposes, or (2) anything designed or sold for incorporation
   3.303 +into a dwelling.  In determining whether a product is a consumer product,
   3.304 +doubtful cases shall be resolved in favor of coverage.  For a particular
   3.305 +product received by a particular user, "normally used" refers to a
   3.306 +typical or common use of that class of product, regardless of the status
   3.307 +of the particular user or of the way in which the particular user
   3.308 +actually uses, or expects or is expected to use, the product.  A product
   3.309 +is a consumer product regardless of whether the product has substantial
   3.310 +commercial, industrial or non-consumer uses, unless such uses represent
   3.311 +the only significant mode of use of the product.
   3.312 +
   3.313 +  "Installation Information" for a User Product means any methods,
   3.314 +procedures, authorization keys, or other information required to install
   3.315 +and execute modified versions of a covered work in that User Product from
   3.316 +a modified version of its Corresponding Source.  The information must
   3.317 +suffice to ensure that the continued functioning of the modified object
   3.318 +code is in no case prevented or interfered with solely because
   3.319 +modification has been made.
   3.320 +
   3.321 +  If you convey an object code work under this section in, or with, or
   3.322 +specifically for use in, a User Product, and the conveying occurs as
   3.323 +part of a transaction in which the right of possession and use of the
   3.324 +User Product is transferred to the recipient in perpetuity or for a
   3.325 +fixed term (regardless of how the transaction is characterized), the
   3.326 +Corresponding Source conveyed under this section must be accompanied
   3.327 +by the Installation Information.  But this requirement does not apply
   3.328 +if neither you nor any third party retains the ability to install
   3.329 +modified object code on the User Product (for example, the work has
   3.330 +been installed in ROM).
   3.331 +
   3.332 +  The requirement to provide Installation Information does not include a
   3.333 +requirement to continue to provide support service, warranty, or updates
   3.334 +for a work that has been modified or installed by the recipient, or for
   3.335 +the User Product in which it has been modified or installed.  Access to a
   3.336 +network may be denied when the modification itself materially and
   3.337 +adversely affects the operation of the network or violates the rules and
   3.338 +protocols for communication across the network.
   3.339 +
   3.340 +  Corresponding Source conveyed, and Installation Information provided,
   3.341 +in accord with this section must be in a format that is publicly
   3.342 +documented (and with an implementation available to the public in
   3.343 +source code form), and must require no special password or key for
   3.344 +unpacking, reading or copying.
   3.345 +
   3.346 +  7. Additional Terms.
   3.347 +
   3.348 +  "Additional permissions" are terms that supplement the terms of this
   3.349 +License by making exceptions from one or more of its conditions.
   3.350 +Additional permissions that are applicable to the entire Program shall
   3.351 +be treated as though they were included in this License, to the extent
   3.352 +that they are valid under applicable law.  If additional permissions
   3.353 +apply only to part of the Program, that part may be used separately
   3.354 +under those permissions, but the entire Program remains governed by
   3.355 +this License without regard to the additional permissions.
   3.356 +
   3.357 +  When you convey a copy of a covered work, you may at your option
   3.358 +remove any additional permissions from that copy, or from any part of
   3.359 +it.  (Additional permissions may be written to require their own
   3.360 +removal in certain cases when you modify the work.)  You may place
   3.361 +additional permissions on material, added by you to a covered work,
   3.362 +for which you have or can give appropriate copyright permission.
   3.363 +
   3.364 +  Notwithstanding any other provision of this License, for material you
   3.365 +add to a covered work, you may (if authorized by the copyright holders of
   3.366 +that material) supplement the terms of this License with terms:
   3.367 +
   3.368 +    a) Disclaiming warranty or limiting liability differently from the
   3.369 +    terms of sections 15 and 16 of this License; or
   3.370 +
   3.371 +    b) Requiring preservation of specified reasonable legal notices or
   3.372 +    author attributions in that material or in the Appropriate Legal
   3.373 +    Notices displayed by works containing it; or
   3.374 +
   3.375 +    c) Prohibiting misrepresentation of the origin of that material, or
   3.376 +    requiring that modified versions of such material be marked in
   3.377 +    reasonable ways as different from the original version; or
   3.378 +
   3.379 +    d) Limiting the use for publicity purposes of names of licensors or
   3.380 +    authors of the material; or
   3.381 +
   3.382 +    e) Declining to grant rights under trademark law for use of some
   3.383 +    trade names, trademarks, or service marks; or
   3.384 +
   3.385 +    f) Requiring indemnification of licensors and authors of that
   3.386 +    material by anyone who conveys the material (or modified versions of
   3.387 +    it) with contractual assumptions of liability to the recipient, for
   3.388 +    any liability that these contractual assumptions directly impose on
   3.389 +    those licensors and authors.
   3.390 +
   3.391 +  All other non-permissive additional terms are considered "further
   3.392 +restrictions" within the meaning of section 10.  If the Program as you
   3.393 +received it, or any part of it, contains a notice stating that it is
   3.394 +governed by this License along with a term that is a further
   3.395 +restriction, you may remove that term.  If a license document contains
   3.396 +a further restriction but permits relicensing or conveying under this
   3.397 +License, you may add to a covered work material governed by the terms
   3.398 +of that license document, provided that the further restriction does
   3.399 +not survive such relicensing or conveying.
   3.400 +
   3.401 +  If you add terms to a covered work in accord with this section, you
   3.402 +must place, in the relevant source files, a statement of the
   3.403 +additional terms that apply to those files, or a notice indicating
   3.404 +where to find the applicable terms.
   3.405 +
   3.406 +  Additional terms, permissive or non-permissive, may be stated in the
   3.407 +form of a separately written license, or stated as exceptions;
   3.408 +the above requirements apply either way.
   3.409 +
   3.410 +  8. Termination.
   3.411 +
   3.412 +  You may not propagate or modify a covered work except as expressly
   3.413 +provided under this License.  Any attempt otherwise to propagate or
   3.414 +modify it is void, and will automatically terminate your rights under
   3.415 +this License (including any patent licenses granted under the third
   3.416 +paragraph of section 11).
   3.417 +
   3.418 +  However, if you cease all violation of this License, then your
   3.419 +license from a particular copyright holder is reinstated (a)
   3.420 +provisionally, unless and until the copyright holder explicitly and
   3.421 +finally terminates your license, and (b) permanently, if the copyright
   3.422 +holder fails to notify you of the violation by some reasonable means
   3.423 +prior to 60 days after the cessation.
   3.424 +
   3.425 +  Moreover, your license from a particular copyright holder is
   3.426 +reinstated permanently if the copyright holder notifies you of the
   3.427 +violation by some reasonable means, this is the first time you have
   3.428 +received notice of violation of this License (for any work) from that
   3.429 +copyright holder, and you cure the violation prior to 30 days after
   3.430 +your receipt of the notice.
   3.431 +
   3.432 +  Termination of your rights under this section does not terminate the
   3.433 +licenses of parties who have received copies or rights from you under
   3.434 +this License.  If your rights have been terminated and not permanently
   3.435 +reinstated, you do not qualify to receive new licenses for the same
   3.436 +material under section 10.
   3.437 +
   3.438 +  9. Acceptance Not Required for Having Copies.
   3.439 +
   3.440 +  You are not required to accept this License in order to receive or
   3.441 +run a copy of the Program.  Ancillary propagation of a covered work
   3.442 +occurring solely as a consequence of using peer-to-peer transmission
   3.443 +to receive a copy likewise does not require acceptance.  However,
   3.444 +nothing other than this License grants you permission to propagate or
   3.445 +modify any covered work.  These actions infringe copyright if you do
   3.446 +not accept this License.  Therefore, by modifying or propagating a
   3.447 +covered work, you indicate your acceptance of this License to do so.
   3.448 +
   3.449 +  10. Automatic Licensing of Downstream Recipients.
   3.450 +
   3.451 +  Each time you convey a covered work, the recipient automatically
   3.452 +receives a license from the original licensors, to run, modify and
   3.453 +propagate that work, subject to this License.  You are not responsible
   3.454 +for enforcing compliance by third parties with this License.
   3.455 +
   3.456 +  An "entity transaction" is a transaction transferring control of an
   3.457 +organization, or substantially all assets of one, or subdividing an
   3.458 +organization, or merging organizations.  If propagation of a covered
   3.459 +work results from an entity transaction, each party to that
   3.460 +transaction who receives a copy of the work also receives whatever
   3.461 +licenses to the work the party's predecessor in interest had or could
   3.462 +give under the previous paragraph, plus a right to possession of the
   3.463 +Corresponding Source of the work from the predecessor in interest, if
   3.464 +the predecessor has it or can get it with reasonable efforts.
   3.465 +
   3.466 +  You may not impose any further restrictions on the exercise of the
   3.467 +rights granted or affirmed under this License.  For example, you may
   3.468 +not impose a license fee, royalty, or other charge for exercise of
   3.469 +rights granted under this License, and you may not initiate litigation
   3.470 +(including a cross-claim or counterclaim in a lawsuit) alleging that
   3.471 +any patent claim is infringed by making, using, selling, offering for
   3.472 +sale, or importing the Program or any portion of it.
   3.473 +
   3.474 +  11. Patents.
   3.475 +
   3.476 +  A "contributor" is a copyright holder who authorizes use under this
   3.477 +License of the Program or a work on which the Program is based.  The
   3.478 +work thus licensed is called the contributor's "contributor version".
   3.479 +
   3.480 +  A contributor's "essential patent claims" are all patent claims
   3.481 +owned or controlled by the contributor, whether already acquired or
   3.482 +hereafter acquired, that would be infringed by some manner, permitted
   3.483 +by this License, of making, using, or selling its contributor version,
   3.484 +but do not include claims that would be infringed only as a
   3.485 +consequence of further modification of the contributor version.  For
   3.486 +purposes of this definition, "control" includes the right to grant
   3.487 +patent sublicenses in a manner consistent with the requirements of
   3.488 +this License.
   3.489 +
   3.490 +  Each contributor grants you a non-exclusive, worldwide, royalty-free
   3.491 +patent license under the contributor's essential patent claims, to
   3.492 +make, use, sell, offer for sale, import and otherwise run, modify and
   3.493 +propagate the contents of its contributor version.
   3.494 +
   3.495 +  In the following three paragraphs, a "patent license" is any express
   3.496 +agreement or commitment, however denominated, not to enforce a patent
   3.497 +(such as an express permission to practice a patent or covenant not to
   3.498 +sue for patent infringement).  To "grant" such a patent license to a
   3.499 +party means to make such an agreement or commitment not to enforce a
   3.500 +patent against the party.
   3.501 +
   3.502 +  If you convey a covered work, knowingly relying on a patent license,
   3.503 +and the Corresponding Source of the work is not available for anyone
   3.504 +to copy, free of charge and under the terms of this License, through a
   3.505 +publicly available network server or other readily accessible means,
   3.506 +then you must either (1) cause the Corresponding Source to be so
   3.507 +available, or (2) arrange to deprive yourself of the benefit of the
   3.508 +patent license for this particular work, or (3) arrange, in a manner
   3.509 +consistent with the requirements of this License, to extend the patent
   3.510 +license to downstream recipients.  "Knowingly relying" means you have
   3.511 +actual knowledge that, but for the patent license, your conveying the
   3.512 +covered work in a country, or your recipient's use of the covered work
   3.513 +in a country, would infringe one or more identifiable patents in that
   3.514 +country that you have reason to believe are valid.
   3.515 +
   3.516 +  If, pursuant to or in connection with a single transaction or
   3.517 +arrangement, you convey, or propagate by procuring conveyance of, a
   3.518 +covered work, and grant a patent license to some of the parties
   3.519 +receiving the covered work authorizing them to use, propagate, modify
   3.520 +or convey a specific copy of the covered work, then the patent license
   3.521 +you grant is automatically extended to all recipients of the covered
   3.522 +work and works based on it.
   3.523 +
   3.524 +  A patent license is "discriminatory" if it does not include within
   3.525 +the scope of its coverage, prohibits the exercise of, or is
   3.526 +conditioned on the non-exercise of one or more of the rights that are
   3.527 +specifically granted under this License.  You may not convey a covered
   3.528 +work if you are a party to an arrangement with a third party that is
   3.529 +in the business of distributing software, under which you make payment
   3.530 +to the third party based on the extent of your activity of conveying
   3.531 +the work, and under which the third party grants, to any of the
   3.532 +parties who would receive the covered work from you, a discriminatory
   3.533 +patent license (a) in connection with copies of the covered work
   3.534 +conveyed by you (or copies made from those copies), or (b) primarily
   3.535 +for and in connection with specific products or compilations that
   3.536 +contain the covered work, unless you entered into that arrangement,
   3.537 +or that patent license was granted, prior to 28 March 2007.
   3.538 +
   3.539 +  Nothing in this License shall be construed as excluding or limiting
   3.540 +any implied license or other defenses to infringement that may
   3.541 +otherwise be available to you under applicable patent law.
   3.542 +
   3.543 +  12. No Surrender of Others' Freedom.
   3.544 +
   3.545 +  If conditions are imposed on you (whether by court order, agreement or
   3.546 +otherwise) that contradict the conditions of this License, they do not
   3.547 +excuse you from the conditions of this License.  If you cannot convey a
   3.548 +covered work so as to satisfy simultaneously your obligations under this
   3.549 +License and any other pertinent obligations, then as a consequence you may
   3.550 +not convey it at all.  For example, if you agree to terms that obligate you
   3.551 +to collect a royalty for further conveying from those to whom you convey
   3.552 +the Program, the only way you could satisfy both those terms and this
   3.553 +License would be to refrain entirely from conveying the Program.
   3.554 +
   3.555 +  13. Use with the GNU Affero General Public License.
   3.556 +
   3.557 +  Notwithstanding any other provision of this License, you have
   3.558 +permission to link or combine any covered work with a work licensed
   3.559 +under version 3 of the GNU Affero General Public License into a single
   3.560 +combined work, and to convey the resulting work.  The terms of this
   3.561 +License will continue to apply to the part which is the covered work,
   3.562 +but the special requirements of the GNU Affero General Public License,
   3.563 +section 13, concerning interaction through a network will apply to the
   3.564 +combination as such.
   3.565 +
   3.566 +  14. Revised Versions of this License.
   3.567 +
   3.568 +  The Free Software Foundation may publish revised and/or new versions of
   3.569 +the GNU General Public License from time to time.  Such new versions will
   3.570 +be similar in spirit to the present version, but may differ in detail to
   3.571 +address new problems or concerns.
   3.572 +
   3.573 +  Each version is given a distinguishing version number.  If the
   3.574 +Program specifies that a certain numbered version of the GNU General
   3.575 +Public License "or any later version" applies to it, you have the
   3.576 +option of following the terms and conditions either of that numbered
   3.577 +version or of any later version published by the Free Software
   3.578 +Foundation.  If the Program does not specify a version number of the
   3.579 +GNU General Public License, you may choose any version ever published
   3.580 +by the Free Software Foundation.
   3.581 +
   3.582 +  If the Program specifies that a proxy can decide which future
   3.583 +versions of the GNU General Public License can be used, that proxy's
   3.584 +public statement of acceptance of a version permanently authorizes you
   3.585 +to choose that version for the Program.
   3.586 +
   3.587 +  Later license versions may give you additional or different
   3.588 +permissions.  However, no additional obligations are imposed on any
   3.589 +author or copyright holder as a result of your choosing to follow a
   3.590 +later version.
   3.591 +
   3.592 +  15. Disclaimer of Warranty.
   3.593 +
   3.594 +  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
   3.595 +APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
   3.596 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
   3.597 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
   3.598 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   3.599 +PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
   3.600 +IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
   3.601 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   3.602 +
   3.603 +  16. Limitation of Liability.
   3.604 +
   3.605 +  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
   3.606 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
   3.607 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
   3.608 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
   3.609 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
   3.610 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
   3.611 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
   3.612 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
   3.613 +SUCH DAMAGES.
   3.614 +
   3.615 +  17. Interpretation of Sections 15 and 16.
   3.616 +
   3.617 +  If the disclaimer of warranty and limitation of liability provided
   3.618 +above cannot be given local legal effect according to their terms,
   3.619 +reviewing courts shall apply local law that most closely approximates
   3.620 +an absolute waiver of all civil liability in connection with the
   3.621 +Program, unless a warranty or assumption of liability accompanies a
   3.622 +copy of the Program in return for a fee.
   3.623 +
   3.624 +                     END OF TERMS AND CONDITIONS
   3.625 +
   3.626 +            How to Apply These Terms to Your New Programs
   3.627 +
   3.628 +  If you develop a new program, and you want it to be of the greatest
   3.629 +possible use to the public, the best way to achieve this is to make it
   3.630 +free software which everyone can redistribute and change under these terms.
   3.631 +
   3.632 +  To do so, attach the following notices to the program.  It is safest
   3.633 +to attach them to the start of each source file to most effectively
   3.634 +state the exclusion of warranty; and each file should have at least
   3.635 +the "copyright" line and a pointer to where the full notice is found.
   3.636 +
   3.637 +    <one line to give the program's name and a brief idea of what it does.>
   3.638 +    Copyright (C) <year>  <name of author>
   3.639 +
   3.640 +    This program is free software: you can redistribute it and/or modify
   3.641 +    it under the terms of the GNU General Public License as published by
   3.642 +    the Free Software Foundation, either version 3 of the License, or
   3.643 +    (at your option) any later version.
   3.644 +
   3.645 +    This program is distributed in the hope that it will be useful,
   3.646 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.647 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   3.648 +    GNU General Public License for more details.
   3.649 +
   3.650 +    You should have received a copy of the GNU General Public License
   3.651 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   3.652 +
   3.653 +Also add information on how to contact you by electronic and paper mail.
   3.654 +
   3.655 +  If the program does terminal interaction, make it output a short
   3.656 +notice like this when it starts in an interactive mode:
   3.657 +
   3.658 +    <program>  Copyright (C) <year>  <name of author>
   3.659 +    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
   3.660 +    This is free software, and you are welcome to redistribute it
   3.661 +    under certain conditions; type `show c' for details.
   3.662 +
   3.663 +The hypothetical commands `show w' and `show c' should show the appropriate
   3.664 +parts of the General Public License.  Of course, your program's commands
   3.665 +might be different; for a GUI interface, you would use an "about box".
   3.666 +
   3.667 +  You should also get your employer (if you work as a programmer) or school,
   3.668 +if any, to sign a "copyright disclaimer" for the program, if necessary.
   3.669 +For more information on this, and how to apply and follow the GNU GPL, see
   3.670 +<http://www.gnu.org/licenses/>.
   3.671 +
   3.672 +  The GNU General Public License does not permit incorporating your program
   3.673 +into proprietary programs.  If your program is a subroutine library, you
   3.674 +may consider it more useful to permit linking proprietary applications with
   3.675 +the library.  If this is what you want to do, use the GNU Lesser General
   3.676 +Public License instead of this License.  But first, please read
   3.677 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/libs/imago2/COPYING.LESSER	Sat Sep 19 05:51:51 2015 +0300
     4.3 @@ -0,0 +1,165 @@
     4.4 +                   GNU LESSER GENERAL PUBLIC LICENSE
     4.5 +                       Version 3, 29 June 2007
     4.6 +
     4.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     4.8 + Everyone is permitted to copy and distribute verbatim copies
     4.9 + of this license document, but changing it is not allowed.
    4.10 +
    4.11 +
    4.12 +  This version of the GNU Lesser General Public License incorporates
    4.13 +the terms and conditions of version 3 of the GNU General Public
    4.14 +License, supplemented by the additional permissions listed below.
    4.15 +
    4.16 +  0. Additional Definitions.
    4.17 +
    4.18 +  As used herein, "this License" refers to version 3 of the GNU Lesser
    4.19 +General Public License, and the "GNU GPL" refers to version 3 of the GNU
    4.20 +General Public License.
    4.21 +
    4.22 +  "The Library" refers to a covered work governed by this License,
    4.23 +other than an Application or a Combined Work as defined below.
    4.24 +
    4.25 +  An "Application" is any work that makes use of an interface provided
    4.26 +by the Library, but which is not otherwise based on the Library.
    4.27 +Defining a subclass of a class defined by the Library is deemed a mode
    4.28 +of using an interface provided by the Library.
    4.29 +
    4.30 +  A "Combined Work" is a work produced by combining or linking an
    4.31 +Application with the Library.  The particular version of the Library
    4.32 +with which the Combined Work was made is also called the "Linked
    4.33 +Version".
    4.34 +
    4.35 +  The "Minimal Corresponding Source" for a Combined Work means the
    4.36 +Corresponding Source for the Combined Work, excluding any source code
    4.37 +for portions of the Combined Work that, considered in isolation, are
    4.38 +based on the Application, and not on the Linked Version.
    4.39 +
    4.40 +  The "Corresponding Application Code" for a Combined Work means the
    4.41 +object code and/or source code for the Application, including any data
    4.42 +and utility programs needed for reproducing the Combined Work from the
    4.43 +Application, but excluding the System Libraries of the Combined Work.
    4.44 +
    4.45 +  1. Exception to Section 3 of the GNU GPL.
    4.46 +
    4.47 +  You may convey a covered work under sections 3 and 4 of this License
    4.48 +without being bound by section 3 of the GNU GPL.
    4.49 +
    4.50 +  2. Conveying Modified Versions.
    4.51 +
    4.52 +  If you modify a copy of the Library, and, in your modifications, a
    4.53 +facility refers to a function or data to be supplied by an Application
    4.54 +that uses the facility (other than as an argument passed when the
    4.55 +facility is invoked), then you may convey a copy of the modified
    4.56 +version:
    4.57 +
    4.58 +   a) under this License, provided that you make a good faith effort to
    4.59 +   ensure that, in the event an Application does not supply the
    4.60 +   function or data, the facility still operates, and performs
    4.61 +   whatever part of its purpose remains meaningful, or
    4.62 +
    4.63 +   b) under the GNU GPL, with none of the additional permissions of
    4.64 +   this License applicable to that copy.
    4.65 +
    4.66 +  3. Object Code Incorporating Material from Library Header Files.
    4.67 +
    4.68 +  The object code form of an Application may incorporate material from
    4.69 +a header file that is part of the Library.  You may convey such object
    4.70 +code under terms of your choice, provided that, if the incorporated
    4.71 +material is not limited to numerical parameters, data structure
    4.72 +layouts and accessors, or small macros, inline functions and templates
    4.73 +(ten or fewer lines in length), you do both of the following:
    4.74 +
    4.75 +   a) Give prominent notice with each copy of the object code that the
    4.76 +   Library is used in it and that the Library and its use are
    4.77 +   covered by this License.
    4.78 +
    4.79 +   b) Accompany the object code with a copy of the GNU GPL and this license
    4.80 +   document.
    4.81 +
    4.82 +  4. Combined Works.
    4.83 +
    4.84 +  You may convey a Combined Work under terms of your choice that,
    4.85 +taken together, effectively do not restrict modification of the
    4.86 +portions of the Library contained in the Combined Work and reverse
    4.87 +engineering for debugging such modifications, if you also do each of
    4.88 +the following:
    4.89 +
    4.90 +   a) Give prominent notice with each copy of the Combined Work that
    4.91 +   the Library is used in it and that the Library and its use are
    4.92 +   covered by this License.
    4.93 +
    4.94 +   b) Accompany the Combined Work with a copy of the GNU GPL and this license
    4.95 +   document.
    4.96 +
    4.97 +   c) For a Combined Work that displays copyright notices during
    4.98 +   execution, include the copyright notice for the Library among
    4.99 +   these notices, as well as a reference directing the user to the
   4.100 +   copies of the GNU GPL and this license document.
   4.101 +
   4.102 +   d) Do one of the following:
   4.103 +
   4.104 +       0) Convey the Minimal Corresponding Source under the terms of this
   4.105 +       License, and the Corresponding Application Code in a form
   4.106 +       suitable for, and under terms that permit, the user to
   4.107 +       recombine or relink the Application with a modified version of
   4.108 +       the Linked Version to produce a modified Combined Work, in the
   4.109 +       manner specified by section 6 of the GNU GPL for conveying
   4.110 +       Corresponding Source.
   4.111 +
   4.112 +       1) Use a suitable shared library mechanism for linking with the
   4.113 +       Library.  A suitable mechanism is one that (a) uses at run time
   4.114 +       a copy of the Library already present on the user's computer
   4.115 +       system, and (b) will operate properly with a modified version
   4.116 +       of the Library that is interface-compatible with the Linked
   4.117 +       Version.
   4.118 +
   4.119 +   e) Provide Installation Information, but only if you would otherwise
   4.120 +   be required to provide such information under section 6 of the
   4.121 +   GNU GPL, and only to the extent that such information is
   4.122 +   necessary to install and execute a modified version of the
   4.123 +   Combined Work produced by recombining or relinking the
   4.124 +   Application with a modified version of the Linked Version. (If
   4.125 +   you use option 4d0, the Installation Information must accompany
   4.126 +   the Minimal Corresponding Source and Corresponding Application
   4.127 +   Code. If you use option 4d1, you must provide the Installation
   4.128 +   Information in the manner specified by section 6 of the GNU GPL
   4.129 +   for conveying Corresponding Source.)
   4.130 +
   4.131 +  5. Combined Libraries.
   4.132 +
   4.133 +  You may place library facilities that are a work based on the
   4.134 +Library side by side in a single library together with other library
   4.135 +facilities that are not Applications and are not covered by this
   4.136 +License, and convey such a combined library under terms of your
   4.137 +choice, if you do both of the following:
   4.138 +
   4.139 +   a) Accompany the combined library with a copy of the same work based
   4.140 +   on the Library, uncombined with any other library facilities,
   4.141 +   conveyed under the terms of this License.
   4.142 +
   4.143 +   b) Give prominent notice with the combined library that part of it
   4.144 +   is a work based on the Library, and explaining where to find the
   4.145 +   accompanying uncombined form of the same work.
   4.146 +
   4.147 +  6. Revised Versions of the GNU Lesser General Public License.
   4.148 +
   4.149 +  The Free Software Foundation may publish revised and/or new versions
   4.150 +of the GNU Lesser General Public License from time to time. Such new
   4.151 +versions will be similar in spirit to the present version, but may
   4.152 +differ in detail to address new problems or concerns.
   4.153 +
   4.154 +  Each version is given a distinguishing version number. If the
   4.155 +Library as you received it specifies that a certain numbered version
   4.156 +of the GNU Lesser General Public License "or any later version"
   4.157 +applies to it, you have the option of following the terms and
   4.158 +conditions either of that published version or of any later version
   4.159 +published by the Free Software Foundation. If the Library as you
   4.160 +received it does not specify a version number of the GNU Lesser
   4.161 +General Public License, you may choose any version of the GNU Lesser
   4.162 +General Public License ever published by the Free Software Foundation.
   4.163 +
   4.164 +  If the Library as you received it specifies that a proxy can decide
   4.165 +whether future versions of the GNU Lesser General Public License shall
   4.166 +apply, that proxy's public statement of acceptance of any version is
   4.167 +permanent authorization for you to choose that version for the
   4.168 +Library.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/libs/imago2/conv.c	Sat Sep 19 05:51:51 2015 +0300
     5.3 @@ -0,0 +1,251 @@
     5.4 +/*
     5.5 +libimago - a multi-format image file input/output library.
     5.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     5.7 +
     5.8 +This program is free software: you can redistribute it and/or modify
     5.9 +it under the terms of the GNU Lesser General Public License as published
    5.10 +by the Free Software Foundation, either version 3 of the License, or
    5.11 +(at your option) any later version.
    5.12 +
    5.13 +This program is distributed in the hope that it will be useful,
    5.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.16 +GNU Lesser General Public License for more details.
    5.17 +
    5.18 +You should have received a copy of the GNU Lesser General Public License
    5.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    5.20 +*/
    5.21 +#include <string.h>
    5.22 +#include "imago2.h"
    5.23 +
    5.24 +/* pixel-format conversions are sub-optimal at the moment to avoid
    5.25 + * writing a lot of code. optimize at some point ?
    5.26 + */
    5.27 +
    5.28 +#define CLAMP(x, a, b)	((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
    5.29 +
    5.30 +struct pixel {
    5.31 +	float r, g, b, a;
    5.32 +};
    5.33 +
    5.34 +static void unpack_grey8(struct pixel *unp, void *pptr, int count);
    5.35 +static void unpack_rgb24(struct pixel *unp, void *pptr, int count);
    5.36 +static void unpack_rgba32(struct pixel *unp, void *pptr, int count);
    5.37 +static void unpack_greyf(struct pixel *unp, void *pptr, int count);
    5.38 +static void unpack_rgbf(struct pixel *unp, void *pptr, int count);
    5.39 +static void unpack_rgbaf(struct pixel *unp, void *pptr, int count);
    5.40 +
    5.41 +static void pack_grey8(void *pptr, struct pixel *unp, int count);
    5.42 +static void pack_rgb24(void *pptr, struct pixel *unp, int count);
    5.43 +static void pack_rgba32(void *pptr, struct pixel *unp, int count);
    5.44 +static void pack_greyf(void *pptr, struct pixel *unp, int count);
    5.45 +static void pack_rgbf(void *pptr, struct pixel *unp, int count);
    5.46 +static void pack_rgbaf(void *pptr, struct pixel *unp, int count);
    5.47 +
    5.48 +/* XXX keep in sync with enum img_fmt at imago2.h */
    5.49 +static void (*unpack[])(struct pixel*, void*, int) = {
    5.50 +	unpack_grey8,
    5.51 +	unpack_rgb24,
    5.52 +	unpack_rgba32,
    5.53 +	unpack_greyf,
    5.54 +	unpack_rgbf,
    5.55 +	unpack_rgbaf
    5.56 +};
    5.57 +
    5.58 +/* XXX keep in sync with enum img_fmt at imago2.h */
    5.59 +static void (*pack[])(void*, struct pixel*, int) = {
    5.60 +	pack_grey8,
    5.61 +	pack_rgb24,
    5.62 +	pack_rgba32,
    5.63 +	pack_greyf,
    5.64 +	pack_rgbf,
    5.65 +	pack_rgbaf
    5.66 +};
    5.67 +
    5.68 +
    5.69 +int img_convert(struct img_pixmap *img, enum img_fmt tofmt)
    5.70 +{
    5.71 +	struct pixel pbuf[8];
    5.72 +	int bufsz = (img->width & 7) == 0 ? 8 : ((img->width & 3) == 0 ? 4 : 1);
    5.73 +	int i, num_pix = img->width * img->height;
    5.74 +	int num_iter = num_pix / bufsz;
    5.75 +	char *sptr, *dptr;
    5.76 +	struct img_pixmap nimg;
    5.77 +
    5.78 +	if(img->fmt == tofmt) {
    5.79 +		return 0;	/* nothing to do */
    5.80 +	}
    5.81 +
    5.82 +	img_init(&nimg);
    5.83 +	if(img_set_pixels(&nimg, img->width, img->height, tofmt, 0) == -1) {
    5.84 +		img_destroy(&nimg);
    5.85 +		return -1;
    5.86 +	}
    5.87 +
    5.88 +	sptr = img->pixels;
    5.89 +	dptr = nimg.pixels;
    5.90 +
    5.91 +	for(i=0; i<num_iter; i++) {
    5.92 +		unpack[img->fmt](pbuf, sptr, bufsz);
    5.93 +		pack[tofmt](dptr, pbuf, bufsz);
    5.94 +
    5.95 +		sptr += bufsz * img->pixelsz;
    5.96 +		dptr += bufsz * nimg.pixelsz;
    5.97 +	}
    5.98 +
    5.99 +	img_copy(img, &nimg);
   5.100 +	img_destroy(&nimg);
   5.101 +	return 0;
   5.102 +}
   5.103 +
   5.104 +/* the following functions *could* benefit from SIMD */
   5.105 +
   5.106 +static void unpack_grey8(struct pixel *unp, void *pptr, int count)
   5.107 +{
   5.108 +	int i;
   5.109 +	unsigned char *pix = pptr;
   5.110 +
   5.111 +	for(i=0; i<count; i++) {
   5.112 +		unp->r = unp->g = unp->b = (float)*pix++ / 255.0;
   5.113 +		unp->a = 1.0;
   5.114 +		unp++;
   5.115 +	}
   5.116 +}
   5.117 +
   5.118 +static void unpack_rgb24(struct pixel *unp, void *pptr, int count)
   5.119 +{
   5.120 +	int i;
   5.121 +	unsigned char *pix = pptr;
   5.122 +
   5.123 +	for(i=0; i<count; i++) {
   5.124 +		unp->r = (float)*pix++ / 255.0;
   5.125 +		unp->g = (float)*pix++ / 255.0;
   5.126 +		unp->b = (float)*pix++ / 255.0;
   5.127 +		unp->a = 1.0;
   5.128 +		unp++;
   5.129 +	}
   5.130 +}
   5.131 +
   5.132 +static void unpack_rgba32(struct pixel *unp, void *pptr, int count)
   5.133 +{
   5.134 +	memcpy(unp, pptr, count * sizeof *unp);
   5.135 +}
   5.136 +
   5.137 +static void unpack_greyf(struct pixel *unp, void *pptr, int count)
   5.138 +{
   5.139 +	int i;
   5.140 +	float *pix = pptr;
   5.141 +
   5.142 +	for(i=0; i<count; i++) {
   5.143 +		unp->r = unp->g = unp->b = *pix++;
   5.144 +		unp->a = 1.0;
   5.145 +		unp++;
   5.146 +	}
   5.147 +}
   5.148 +
   5.149 +static void unpack_rgbf(struct pixel *unp, void *pptr, int count)
   5.150 +{
   5.151 +	int i;
   5.152 +	float *pix = pptr;
   5.153 +
   5.154 +	for(i=0; i<count; i++) {
   5.155 +		unp->r = *pix++;
   5.156 +		unp->g = *pix++;
   5.157 +		unp->b = *pix++;
   5.158 +		unp->a = 1.0;
   5.159 +		unp++;
   5.160 +	}
   5.161 +}
   5.162 +
   5.163 +static void unpack_rgbaf(struct pixel *unp, void *pptr, int count)
   5.164 +{
   5.165 +	int i;
   5.166 +	float *pix = pptr;
   5.167 +
   5.168 +	for(i=0; i<count; i++) {
   5.169 +		unp->r = *pix++;
   5.170 +		unp->g = *pix++;
   5.171 +		unp->b = *pix++;
   5.172 +		unp->a = *pix++;
   5.173 +		unp++;
   5.174 +	}
   5.175 +}
   5.176 +
   5.177 +
   5.178 +static void pack_grey8(void *pptr, struct pixel *unp, int count)
   5.179 +{
   5.180 +	int i;
   5.181 +	unsigned char *pix = pptr;
   5.182 +
   5.183 +	for(i=0; i<count; i++) {
   5.184 +		int lum = (int)(255.0 * (unp->r + unp->g + unp->b) / 3.0);
   5.185 +		*pix++ = CLAMP(lum, 0, 255);
   5.186 +		unp++;
   5.187 +	}
   5.188 +}
   5.189 +
   5.190 +static void pack_rgb24(void *pptr, struct pixel *unp, int count)
   5.191 +{
   5.192 +	int i;
   5.193 +	unsigned char *pix = pptr;
   5.194 +
   5.195 +	for(i=0; i<count; i++) {
   5.196 +		int r = (int)(unp->r * 255.0);
   5.197 +		int g = (int)(unp->g * 255.0);
   5.198 +		int b = (int)(unp->b * 255.0);
   5.199 +
   5.200 +		*pix++ = CLAMP(r, 0, 255);
   5.201 +		*pix++ = CLAMP(g, 0, 255);
   5.202 +		*pix++ = CLAMP(b, 0, 255);
   5.203 +		unp++;
   5.204 +	}
   5.205 +}
   5.206 +
   5.207 +static void pack_rgba32(void *pptr, struct pixel *unp, int count)
   5.208 +{
   5.209 +	int i;
   5.210 +	unsigned char *pix = pptr;
   5.211 +
   5.212 +	for(i=0; i<count; i++) {
   5.213 +		int r = (int)(unp->r * 255.0);
   5.214 +		int g = (int)(unp->g * 255.0);
   5.215 +		int b = (int)(unp->b * 255.0);
   5.216 +		int a = (int)(unp->a * 255.0);
   5.217 +
   5.218 +		*pix++ = CLAMP(r, 0, 255);
   5.219 +		*pix++ = CLAMP(g, 0, 255);
   5.220 +		*pix++ = CLAMP(b, 0, 255);
   5.221 +		*pix++ = CLAMP(a, 0, 255);
   5.222 +		unp++;
   5.223 +	}
   5.224 +}
   5.225 +
   5.226 +static void pack_greyf(void *pptr, struct pixel *unp, int count)
   5.227 +{
   5.228 +	int i;
   5.229 +	float *pix = pptr;
   5.230 +
   5.231 +	for(i=0; i<count; i++) {
   5.232 +		*pix++ = (unp->r + unp->g + unp->b) / 3.0;
   5.233 +		unp++;
   5.234 +	}
   5.235 +}
   5.236 +
   5.237 +static void pack_rgbf(void *pptr, struct pixel *unp, int count)
   5.238 +{
   5.239 +	int i;
   5.240 +	float *pix = pptr;
   5.241 +
   5.242 +	for(i=0; i<count; i++) {
   5.243 +		*pix++ = unp->r;
   5.244 +		*pix++ = unp->g;
   5.245 +		*pix++ = unp->b;
   5.246 +		unp++;
   5.247 +	}
   5.248 +}
   5.249 +
   5.250 +static void pack_rgbaf(void *pptr, struct pixel *unp, int count)
   5.251 +{
   5.252 +	memcpy(pptr, unp, count * sizeof *unp);
   5.253 +}
   5.254 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/libs/imago2/file_jpeg.c	Sat Sep 19 05:51:51 2015 +0300
     6.3 @@ -0,0 +1,291 @@
     6.4 +/*
     6.5 +libimago - a multi-format image file input/output library.
     6.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     6.7 +
     6.8 +This program is free software: you can redistribute it and/or modify
     6.9 +it under the terms of the GNU Lesser General Public License as published
    6.10 +by the Free Software Foundation, either version 3 of the License, or
    6.11 +(at your option) any later version.
    6.12 +
    6.13 +This program is distributed in the hope that it will be useful,
    6.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 +GNU Lesser General Public License for more details.
    6.17 +
    6.18 +You should have received a copy of the GNU Lesser General Public License
    6.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    6.20 +*/
    6.21 +
    6.22 +/* -- JPEG module -- */
    6.23 +
    6.24 +#include <stdio.h>
    6.25 +#include <stdlib.h>
    6.26 +#include <string.h>
    6.27 +
    6.28 +#ifdef WIN32
    6.29 +#include <windows.h>
    6.30 +#define HAVE_BOOLEAN
    6.31 +#endif
    6.32 +
    6.33 +#include <jpeglib.h>
    6.34 +#include "imago2.h"
    6.35 +#include "ftype_module.h"
    6.36 +
    6.37 +#define INPUT_BUF_SIZE	512
    6.38 +#define OUTPUT_BUF_SIZE	512
    6.39 +
    6.40 +/* data source manager: adapted from jdatasrc.c */
    6.41 +struct src_mgr {
    6.42 +	struct jpeg_source_mgr pub;
    6.43 +
    6.44 +	struct img_io *io;
    6.45 +	unsigned char buffer[INPUT_BUF_SIZE];
    6.46 +	int start_of_file;
    6.47 +};
    6.48 +
    6.49 +/* data destination manager: adapted from jdatadst.c */
    6.50 +struct dst_mgr {
    6.51 +	struct jpeg_destination_mgr pub;
    6.52 +
    6.53 +	struct img_io *io;
    6.54 +	unsigned char buffer[OUTPUT_BUF_SIZE];
    6.55 +};
    6.56 +
    6.57 +static int check(struct img_io *io);
    6.58 +static int readjpeg(struct img_pixmap *img, struct img_io *io);
    6.59 +static int writejpeg(struct img_pixmap *img, struct img_io *io);
    6.60 +
    6.61 +/* read source functions */
    6.62 +static void init_source(j_decompress_ptr jd);
    6.63 +static int fill_input_buffer(j_decompress_ptr jd);
    6.64 +static void skip_input_data(j_decompress_ptr jd, long num_bytes);
    6.65 +static void term_source(j_decompress_ptr jd);
    6.66 +
    6.67 +/* write destination functions */
    6.68 +static void init_destination(j_compress_ptr jc);
    6.69 +static int empty_output_buffer(j_compress_ptr jc);
    6.70 +static void term_destination(j_compress_ptr jc);
    6.71 +
    6.72 +int img_register_jpeg(void)
    6.73 +{
    6.74 +	static struct ftype_module mod = {".jpg", check, readjpeg, writejpeg};
    6.75 +	return img_register_module(&mod);
    6.76 +}
    6.77 +
    6.78 +
    6.79 +static int check(struct img_io *io)
    6.80 +{
    6.81 +	unsigned char sig[10];
    6.82 +
    6.83 +	long pos = io->seek(0, SEEK_CUR, io->uptr);
    6.84 +
    6.85 +	if(io->read(sig, 10, io->uptr) < 10) {
    6.86 +		io->seek(pos, SEEK_SET, io->uptr);
    6.87 +		return -1;
    6.88 +	}
    6.89 +
    6.90 +	if(memcmp(sig, "\xff\xd8\xff\xe0", 4) != 0 || memcmp(sig + 6, "JFIF", 4) != 0) {
    6.91 +		io->seek(pos, SEEK_SET, io->uptr);
    6.92 +		return -1;
    6.93 +	}
    6.94 +	io->seek(pos, SEEK_SET, io->uptr);
    6.95 +	return 0;
    6.96 +}
    6.97 +
    6.98 +static int readjpeg(struct img_pixmap *img, struct img_io *io)
    6.99 +{
   6.100 +	int i, nlines = 0;
   6.101 +	struct jpeg_decompress_struct cinfo;
   6.102 +	struct jpeg_error_mgr jerr;
   6.103 +	struct src_mgr src;
   6.104 +	unsigned char **scanlines;
   6.105 +
   6.106 +	cinfo.err = jpeg_std_error(&jerr);	/* XXX change... */
   6.107 +	jpeg_create_decompress(&cinfo);
   6.108 +
   6.109 +	src.pub.init_source = init_source;
   6.110 +	src.pub.fill_input_buffer = fill_input_buffer;
   6.111 +	src.pub.skip_input_data = skip_input_data;
   6.112 +	src.pub.resync_to_restart = jpeg_resync_to_restart;
   6.113 +	src.pub.term_source = term_source;
   6.114 +	src.pub.next_input_byte = 0;
   6.115 +	src.pub.bytes_in_buffer = 0;
   6.116 +	src.io = io;
   6.117 +	cinfo.src = (struct jpeg_source_mgr*)&src;
   6.118 +
   6.119 +	jpeg_read_header(&cinfo, 1);
   6.120 +	cinfo.out_color_space = JCS_RGB;
   6.121 +
   6.122 +	if(img_set_pixels(img, cinfo.image_width, cinfo.image_height, IMG_FMT_RGB24, 0) == -1) {
   6.123 +		jpeg_destroy_decompress(&cinfo);
   6.124 +		return -1;
   6.125 +	}
   6.126 +
   6.127 +	if(!(scanlines = malloc(img->height * sizeof *scanlines))) {
   6.128 +		jpeg_destroy_decompress(&cinfo);
   6.129 +		return -1;
   6.130 +	}
   6.131 +	scanlines[0] = img->pixels;
   6.132 +	for(i=1; i<img->height; i++) {
   6.133 +		scanlines[i] = scanlines[i - 1] + img->width * img->pixelsz;
   6.134 +	}
   6.135 +
   6.136 +	jpeg_start_decompress(&cinfo);
   6.137 +	while(nlines < img->height) {
   6.138 +		int res = jpeg_read_scanlines(&cinfo, scanlines + nlines, img->height - nlines);
   6.139 +		nlines += res;
   6.140 +	}
   6.141 +	jpeg_finish_decompress(&cinfo);
   6.142 +	jpeg_destroy_decompress(&cinfo);
   6.143 +
   6.144 +	free(scanlines);
   6.145 +	return 0;
   6.146 +}
   6.147 +
   6.148 +static int writejpeg(struct img_pixmap *img, struct img_io *io)
   6.149 +{
   6.150 +	int i, nlines = 0;
   6.151 +	struct jpeg_compress_struct cinfo;
   6.152 +	struct jpeg_error_mgr jerr;
   6.153 +	struct dst_mgr dest;
   6.154 +	struct img_pixmap tmpimg;
   6.155 +	unsigned char **scanlines;
   6.156 +
   6.157 +	img_init(&tmpimg);
   6.158 +
   6.159 +	if(img->fmt != IMG_FMT_RGB24) {
   6.160 +		if(img_copy(&tmpimg, img) == -1) {
   6.161 +			return -1;
   6.162 +		}
   6.163 +		if(img_convert(&tmpimg, IMG_FMT_RGB24) == -1) {
   6.164 +			img_destroy(&tmpimg);
   6.165 +			return -1;
   6.166 +		}
   6.167 +		img = &tmpimg;
   6.168 +	}
   6.169 +
   6.170 +	if(!(scanlines = malloc(img->height * sizeof *scanlines))) {
   6.171 +		img_destroy(&tmpimg);
   6.172 +		return -1;
   6.173 +	}
   6.174 +	scanlines[0] = img->pixels;
   6.175 +	for(i=1; i<img->height; i++) {
   6.176 +		scanlines[i] = scanlines[i - 1] + img->width * img->pixelsz;
   6.177 +	}
   6.178 +
   6.179 +	cinfo.err = jpeg_std_error(&jerr);	/* XXX */
   6.180 +	jpeg_create_compress(&cinfo);
   6.181 +
   6.182 +	dest.pub.init_destination = init_destination;
   6.183 +	dest.pub.empty_output_buffer = empty_output_buffer;
   6.184 +	dest.pub.term_destination = term_destination;
   6.185 +	dest.io = io;
   6.186 +	cinfo.dest = (struct jpeg_destination_mgr*)&dest;
   6.187 +
   6.188 +	cinfo.image_width = img->width;
   6.189 +	cinfo.image_height = img->height;
   6.190 +	cinfo.input_components = 3;
   6.191 +	cinfo.in_color_space = JCS_RGB;
   6.192 +
   6.193 +	jpeg_set_defaults(&cinfo);
   6.194 +
   6.195 +	jpeg_start_compress(&cinfo, 1);
   6.196 +	while(nlines < img->height) {
   6.197 +		int res = jpeg_write_scanlines(&cinfo, scanlines + nlines, img->height - nlines);
   6.198 +		nlines += res;
   6.199 +	}
   6.200 +	jpeg_finish_compress(&cinfo);
   6.201 +	jpeg_destroy_compress(&cinfo);
   6.202 +
   6.203 +	free(scanlines);
   6.204 +	img_destroy(&tmpimg);
   6.205 +	return 0;
   6.206 +}
   6.207 +
   6.208 +/* -- read source functions --
   6.209 + * the following functions are adapted from jdatasrc.c in jpeglib
   6.210 + */
   6.211 +static void init_source(j_decompress_ptr jd)
   6.212 +{
   6.213 +	struct src_mgr *src = (struct src_mgr*)jd->src;
   6.214 +	src->start_of_file = 1;
   6.215 +}
   6.216 +
   6.217 +static int fill_input_buffer(j_decompress_ptr jd)
   6.218 +{
   6.219 +	struct src_mgr *src = (struct src_mgr*)jd->src;
   6.220 +	size_t nbytes;
   6.221 +
   6.222 +	nbytes = src->io->read(src->buffer, INPUT_BUF_SIZE, src->io->uptr);
   6.223 +
   6.224 +	if(nbytes <= 0) {
   6.225 +		if(src->start_of_file) {
   6.226 +			return 0;
   6.227 +		}
   6.228 +		/* insert a fake EOI marker */
   6.229 +		src->buffer[0] = 0xff;
   6.230 +		src->buffer[1] = JPEG_EOI;
   6.231 +		nbytes = 2;
   6.232 +	}
   6.233 +
   6.234 +	src->pub.next_input_byte = src->buffer;
   6.235 +	src->pub.bytes_in_buffer = nbytes;
   6.236 +	src->start_of_file = 0;
   6.237 +	return 1;
   6.238 +}
   6.239 +
   6.240 +static void skip_input_data(j_decompress_ptr jd, long num_bytes)
   6.241 +{
   6.242 +	struct src_mgr *src = (struct src_mgr*)jd->src;
   6.243 +
   6.244 +	if(num_bytes > 0) {
   6.245 +		while(num_bytes > (long)src->pub.bytes_in_buffer) {
   6.246 +			num_bytes -= (long)src->pub.bytes_in_buffer;
   6.247 +			fill_input_buffer(jd);
   6.248 +		}
   6.249 +		src->pub.next_input_byte += (size_t)num_bytes;
   6.250 +		src->pub.bytes_in_buffer -= (size_t)num_bytes;
   6.251 +	}
   6.252 +}
   6.253 +
   6.254 +static void term_source(j_decompress_ptr jd)
   6.255 +{
   6.256 +	/* nothing to see here, move along */
   6.257 +}
   6.258 +
   6.259 +
   6.260 +/* -- write destination functions --
   6.261 + * the following functions are adapted from jdatadst.c in jpeglib
   6.262 + */
   6.263 +static void init_destination(j_compress_ptr jc)
   6.264 +{
   6.265 +	struct dst_mgr *dest = (struct dst_mgr*)jc->dest;
   6.266 +
   6.267 +	dest->pub.next_output_byte = dest->buffer;
   6.268 +	dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
   6.269 +}
   6.270 +
   6.271 +static int empty_output_buffer(j_compress_ptr jc)
   6.272 +{
   6.273 +	struct dst_mgr *dest = (struct dst_mgr*)jc->dest;
   6.274 +
   6.275 +	if(dest->io->write(dest->buffer, OUTPUT_BUF_SIZE, dest->io->uptr) != OUTPUT_BUF_SIZE) {
   6.276 +		return 0;
   6.277 +	}
   6.278 +
   6.279 +	dest->pub.next_output_byte = dest->buffer;
   6.280 +	dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
   6.281 +	return 1;
   6.282 +}
   6.283 +
   6.284 +static void term_destination(j_compress_ptr jc)
   6.285 +{
   6.286 +	struct dst_mgr *dest = (struct dst_mgr*)jc->dest;
   6.287 +	size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
   6.288 +
   6.289 +	/* write any remaining data in the buffer */
   6.290 +	if(datacount > 0) {
   6.291 +		dest->io->write(dest->buffer, datacount, dest->io->uptr);
   6.292 +	}
   6.293 +	/* XXX flush? ... */
   6.294 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/libs/imago2/file_png.c	Sat Sep 19 05:51:51 2015 +0300
     7.3 @@ -0,0 +1,244 @@
     7.4 +/*
     7.5 +libimago - a multi-format image file input/output library.
     7.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     7.7 +
     7.8 +This program is free software: you can redistribute it and/or modify
     7.9 +it under the terms of the GNU Lesser General Public License as published
    7.10 +by the Free Software Foundation, either version 3 of the License, or
    7.11 +(at your option) any later version.
    7.12 +
    7.13 +This program is distributed in the hope that it will be useful,
    7.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 +GNU Lesser General Public License for more details.
    7.17 +
    7.18 +You should have received a copy of the GNU Lesser General Public License
    7.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    7.20 +*/
    7.21 +
    7.22 +/* -- PNG module -- */
    7.23 +
    7.24 +#include <stdlib.h>
    7.25 +#include <png.h>
    7.26 +#include "imago2.h"
    7.27 +#include "ftype_module.h"
    7.28 +
    7.29 +static int check_file(struct img_io *io);
    7.30 +static int read_file(struct img_pixmap *img, struct img_io *io);
    7.31 +static int write_file(struct img_pixmap *img, struct img_io *io);
    7.32 +
    7.33 +static void read_func(png_struct *png, unsigned char *data, size_t len);
    7.34 +static void write_func(png_struct *png, unsigned char *data, size_t len);
    7.35 +static void flush_func(png_struct *png);
    7.36 +
    7.37 +static int png_type_to_fmt(int color_type, int channel_bits);
    7.38 +static int fmt_to_png_type(enum img_fmt fmt);
    7.39 +
    7.40 +
    7.41 +int img_register_png(void)
    7.42 +{
    7.43 +	static struct ftype_module mod = {".png", check_file, read_file, write_file};
    7.44 +	return img_register_module(&mod);
    7.45 +}
    7.46 +
    7.47 +static int check_file(struct img_io *io)
    7.48 +{
    7.49 +	unsigned char sig[8];
    7.50 +	int res;
    7.51 +	long pos = io->seek(0, SEEK_CUR, io->uptr);
    7.52 +
    7.53 +	if(io->read(sig, 8, io->uptr) < 8) {
    7.54 +		io->seek(pos, SEEK_SET, io->uptr);
    7.55 +		return -1;
    7.56 +	}
    7.57 +
    7.58 +	res = png_sig_cmp(sig, 0, 8) == 0 ? 0 : -1;
    7.59 +	io->seek(pos, SEEK_SET, io->uptr);
    7.60 +	return res;
    7.61 +}
    7.62 +
    7.63 +static int read_file(struct img_pixmap *img, struct img_io *io)
    7.64 +{
    7.65 +	png_struct *png;
    7.66 +	png_info *info;
    7.67 +	unsigned char **lineptr, *dest;
    7.68 +	int i, channel_bits, color_type, ilace_type, compression, filtering, fmt;
    7.69 +	unsigned long xsz, ysz;
    7.70 +
    7.71 +	if(!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) {
    7.72 +		return -1;
    7.73 +	}
    7.74 +
    7.75 +	if(!(info = png_create_info_struct(png))) {
    7.76 +		png_destroy_read_struct(&png, 0, 0);
    7.77 +		return -1;
    7.78 +	}
    7.79 +
    7.80 +	if(setjmp(png_jmpbuf(png))) {
    7.81 +		png_destroy_read_struct(&png, &info, 0);
    7.82 +		return -1;
    7.83 +	}
    7.84 +
    7.85 +	png_set_read_fn(png, io, read_func);
    7.86 +	png_set_sig_bytes(png, 0);
    7.87 +	png_read_png(png, info, 0, 0);
    7.88 +
    7.89 +	png_get_IHDR(png, info, &xsz, &ysz, &channel_bits, &color_type, &ilace_type,
    7.90 +			&compression, &filtering);
    7.91 +	if((fmt = png_type_to_fmt(color_type, channel_bits)) == -1) {
    7.92 +		png_destroy_read_struct(&png, &info, 0);
    7.93 +		return -1;
    7.94 +	}
    7.95 +
    7.96 +	if(img_set_pixels(img, xsz, ysz, fmt, 0) == -1) {
    7.97 +		png_destroy_read_struct(&png, &info, 0);
    7.98 +		return -1;
    7.99 +	}
   7.100 +
   7.101 +	lineptr = (unsigned char**)png_get_rows(png, info);
   7.102 +
   7.103 +	dest = img->pixels;
   7.104 +	for(i=0; i<ysz; i++) {
   7.105 +		memcpy(dest, lineptr[i], xsz * img->pixelsz);
   7.106 +		dest += xsz * img->pixelsz;
   7.107 +	}
   7.108 +	png_destroy_read_struct(&png, &info, 0);
   7.109 +	return 0;
   7.110 +}
   7.111 +
   7.112 +
   7.113 +static int write_file(struct img_pixmap *img, struct img_io *io)
   7.114 +{
   7.115 +	png_struct *png;
   7.116 +	png_info *info;
   7.117 +	png_text txt;
   7.118 +	struct img_pixmap tmpimg;
   7.119 +	unsigned char **rows;
   7.120 +	unsigned char *pixptr;
   7.121 +	int i, coltype;
   7.122 +
   7.123 +	img_init(&tmpimg);
   7.124 +
   7.125 +	if(!(png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) {
   7.126 +		return -1;
   7.127 +	}
   7.128 +	if(!(info = png_create_info_struct(png))) {
   7.129 +		png_destroy_write_struct(&png, 0);
   7.130 +		return -1;
   7.131 +	}
   7.132 +
   7.133 +	/* if the input image is floating-point, we need to convert it to integer */
   7.134 +	if(img_is_float(img)) {
   7.135 +		if(img_copy(&tmpimg, img) == -1) {
   7.136 +			return -1;
   7.137 +		}
   7.138 +		if(img_to_integer(&tmpimg) == -1) {
   7.139 +			img_destroy(&tmpimg);
   7.140 +			return -1;
   7.141 +		}
   7.142 +		img = &tmpimg;
   7.143 +	}
   7.144 +
   7.145 +	txt.compression = PNG_TEXT_COMPRESSION_NONE;
   7.146 +	txt.key = "Software";
   7.147 +	txt.text = "libimago2";
   7.148 +	txt.text_length = 0;
   7.149 +
   7.150 +	if(setjmp(png_jmpbuf(png))) {
   7.151 +		png_destroy_write_struct(&png, &info);
   7.152 +		img_destroy(&tmpimg);
   7.153 +		return -1;
   7.154 +	}
   7.155 +	png_set_write_fn(png, io, write_func, flush_func);
   7.156 +
   7.157 +	coltype = fmt_to_png_type(img->fmt);
   7.158 +	png_set_IHDR(png, info, img->width, img->height, 8, coltype, PNG_INTERLACE_NONE,
   7.159 +			PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
   7.160 +	png_set_text(png, info, &txt, 1);
   7.161 +
   7.162 +	if(!(rows = malloc(img->height * sizeof *rows))) {
   7.163 +		png_destroy_write_struct(&png, &info);
   7.164 +		img_destroy(&tmpimg);
   7.165 +		return -1;
   7.166 +	}
   7.167 +
   7.168 +	pixptr = img->pixels;
   7.169 +	for(i=0; i<img->height; i++) {
   7.170 +		rows[i] = pixptr;
   7.171 +		pixptr += img->width * img->pixelsz;
   7.172 +	}
   7.173 +	png_set_rows(png, info, rows);
   7.174 +
   7.175 +	png_write_png(png, info, 0, 0);
   7.176 +	png_write_end(png, info);
   7.177 +	png_destroy_write_struct(&png, &info);
   7.178 +
   7.179 +	free(rows);
   7.180 +
   7.181 +	img_destroy(&tmpimg);
   7.182 +	return 0;
   7.183 +}
   7.184 +
   7.185 +static void read_func(png_struct *png, unsigned char *data, size_t len)
   7.186 +{
   7.187 +	struct img_io *io = (struct img_io*)png_get_io_ptr(png);
   7.188 +
   7.189 +	if(io->read(data, len, io->uptr) == -1) {
   7.190 +		longjmp(png_jmpbuf(png), 1);
   7.191 +	}
   7.192 +}
   7.193 +
   7.194 +static void write_func(png_struct *png, unsigned char *data, size_t len)
   7.195 +{
   7.196 +	struct img_io *io = (struct img_io*)png_get_io_ptr(png);
   7.197 +
   7.198 +	if(io->write(data, len, io->uptr) == -1) {
   7.199 +		longjmp(png_jmpbuf(png), 1);
   7.200 +	}
   7.201 +}
   7.202 +
   7.203 +static void flush_func(png_struct *png)
   7.204 +{
   7.205 +	/* XXX does it matter that we can't flush? */
   7.206 +}
   7.207 +
   7.208 +static int png_type_to_fmt(int color_type, int channel_bits)
   7.209 +{
   7.210 +	/* we don't support non-8bit-per-channel images yet */
   7.211 +	if(channel_bits > 8) {
   7.212 +		return -1;
   7.213 +	}
   7.214 +
   7.215 +	switch(color_type) {
   7.216 +	case PNG_COLOR_TYPE_RGB:
   7.217 +		return IMG_FMT_RGB24;
   7.218 +
   7.219 +	case PNG_COLOR_TYPE_RGB_ALPHA:
   7.220 +		return IMG_FMT_RGBA32;
   7.221 +
   7.222 +	case PNG_COLOR_TYPE_GRAY:
   7.223 +		return IMG_FMT_GREY8;
   7.224 +
   7.225 +	default:
   7.226 +		break;
   7.227 +	}
   7.228 +	return -1;
   7.229 +}
   7.230 +
   7.231 +static int fmt_to_png_type(enum img_fmt fmt)
   7.232 +{
   7.233 +	switch(fmt) {
   7.234 +	case IMG_FMT_GREY8:
   7.235 +		return PNG_COLOR_TYPE_GRAY;
   7.236 +
   7.237 +	case IMG_FMT_RGB24:
   7.238 +		return PNG_COLOR_TYPE_RGB;
   7.239 +
   7.240 +	case IMG_FMT_RGBA32:
   7.241 +		return PNG_COLOR_TYPE_RGBA;
   7.242 +
   7.243 +	default:
   7.244 +		break;
   7.245 +	}
   7.246 +	return -1;
   7.247 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/libs/imago2/file_ppm.c	Sat Sep 19 05:51:51 2015 +0300
     8.3 @@ -0,0 +1,153 @@
     8.4 +/*
     8.5 +libimago - a multi-format image file input/output library.
     8.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     8.7 +
     8.8 +This program is free software: you can redistribute it and/or modify
     8.9 +it under the terms of the GNU Lesser General Public License as published
    8.10 +by the Free Software Foundation, either version 3 of the License, or
    8.11 +(at your option) any later version.
    8.12 +
    8.13 +This program is distributed in the hope that it will be useful,
    8.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 +GNU Lesser General Public License for more details.
    8.17 +
    8.18 +You should have received a copy of the GNU Lesser General Public License
    8.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    8.20 +*/
    8.21 +
    8.22 +/* -- Portable Pixmap (PPM) module -- */
    8.23 +
    8.24 +#include <string.h>
    8.25 +#include "imago2.h"
    8.26 +#include "ftype_module.h"
    8.27 +
    8.28 +static int check(struct img_io *io);
    8.29 +static int readppm(struct img_pixmap *img, struct img_io *io);
    8.30 +static int writeppm(struct img_pixmap *img, struct img_io *io);
    8.31 +
    8.32 +int img_register_ppm(void)
    8.33 +{
    8.34 +	static struct ftype_module mod = {".ppm", check, readppm, writeppm};
    8.35 +	return img_register_module(&mod);
    8.36 +}
    8.37 +
    8.38 +
    8.39 +static int check(struct img_io *io)
    8.40 +{
    8.41 +	char id[2];
    8.42 +	int res = -1;
    8.43 +	long pos = io->seek(0, SEEK_CUR, io->uptr);
    8.44 +
    8.45 +	if(io->read(id, 2, io->uptr) < 2) {
    8.46 +		io->seek(pos, SEEK_SET, io->uptr);
    8.47 +		return -1;
    8.48 +	}
    8.49 +
    8.50 +	if(id[0] == 'P' && (id[1] == '6' || id[1] == '3')) {
    8.51 +		res = 0;
    8.52 +	}
    8.53 +	io->seek(pos, SEEK_SET, io->uptr);
    8.54 +	return res;
    8.55 +}
    8.56 +
    8.57 +static int iofgetc(struct img_io *io)
    8.58 +{
    8.59 +	char c;
    8.60 +	return io->read(&c, 1, io->uptr) < 1 ? -1 : c;
    8.61 +}
    8.62 +
    8.63 +static char *iofgets(char *buf, int size, struct img_io *io)
    8.64 +{
    8.65 +	int c;
    8.66 +	char *ptr = buf;
    8.67 +
    8.68 +	while(--size > 0 && (c = iofgetc(io)) != -1) {
    8.69 +		*ptr++ = c;
    8.70 +		if(c == '\n') break;
    8.71 +	}
    8.72 +	*ptr = 0;
    8.73 +
    8.74 +	return ptr == buf ? 0 : buf;
    8.75 +}
    8.76 +
    8.77 +/* TODO: implement P3 reading */
    8.78 +static int readppm(struct img_pixmap *img, struct img_io *io)
    8.79 +{
    8.80 +	char buf[256];
    8.81 +	int xsz, ysz, maxval, got_hdrlines = 1;
    8.82 +
    8.83 +	if(!iofgets(buf, sizeof buf, io)) {
    8.84 +		return -1;
    8.85 +	}
    8.86 +	if(!(buf[0] == 'P' && (buf[1] == '6' || buf[1] == '3'))) {
    8.87 +		return -1;
    8.88 +	}
    8.89 +
    8.90 +	while(got_hdrlines < 3 && iofgets(buf, sizeof buf, io)) {
    8.91 +		if(buf[0] == '#') continue;
    8.92 +
    8.93 +		switch(got_hdrlines) {
    8.94 +		case 1:
    8.95 +			if(sscanf(buf, "%d %d\n", &xsz, &ysz) < 2) {
    8.96 +				return -1;
    8.97 +			}
    8.98 +			break;
    8.99 +
   8.100 +		case 2:
   8.101 +			if(sscanf(buf, "%d\n", &maxval) < 1) {
   8.102 +				return -1;
   8.103 +			}
   8.104 +		default:
   8.105 +			break;
   8.106 +		}
   8.107 +		got_hdrlines++;
   8.108 +	}
   8.109 +
   8.110 +	if(xsz < 1 || ysz < 1 || maxval != 255) {
   8.111 +		return -1;
   8.112 +	}
   8.113 +
   8.114 +	if(img_set_pixels(img, xsz, ysz, IMG_FMT_RGB24, 0) == -1) {
   8.115 +		return -1;
   8.116 +	}
   8.117 +
   8.118 +	if(io->read(img->pixels, xsz * ysz * 3, io->uptr) < xsz * ysz * 3) {
   8.119 +		return -1;
   8.120 +	}
   8.121 +	return 0;
   8.122 +}
   8.123 +
   8.124 +static int writeppm(struct img_pixmap *img, struct img_io *io)
   8.125 +{
   8.126 +	int sz;
   8.127 +	char buf[256];
   8.128 +	struct img_pixmap tmpimg;
   8.129 +
   8.130 +	img_init(&tmpimg);
   8.131 +
   8.132 +	if(img->fmt != IMG_FMT_RGB24) {
   8.133 +		if(img_copy(&tmpimg, img) == -1) {
   8.134 +			return -1;
   8.135 +		}
   8.136 +		if(img_convert(&tmpimg, IMG_FMT_RGB24) == -1) {
   8.137 +			return -1;
   8.138 +		}
   8.139 +		img = &tmpimg;
   8.140 +	}
   8.141 +
   8.142 +	sprintf(buf, "P6\n#written by libimago2\n%d %d\n255\n", img->width, img->height);
   8.143 +	if(io->write(buf, strlen(buf), io->uptr) < strlen(buf)) {
   8.144 +		img_destroy(&tmpimg);
   8.145 +		return -1;
   8.146 +	}
   8.147 +
   8.148 +	sz = img->width * img->height * 3;
   8.149 +	if(io->write(img->pixels, sz, io->uptr) < sz) {
   8.150 +		img_destroy(&tmpimg);
   8.151 +		return -1;
   8.152 +	}
   8.153 +
   8.154 +	img_destroy(&tmpimg);
   8.155 +	return 0;
   8.156 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/libs/imago2/ftype_module.c	Sat Sep 19 05:51:51 2015 +0300
     9.3 @@ -0,0 +1,118 @@
     9.4 +/*
     9.5 +libimago - a multi-format image file input/output library.
     9.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     9.7 +
     9.8 +This program is free software: you can redistribute it and/or modify
     9.9 +it under the terms of the GNU Lesser General Public License as published
    9.10 +by the Free Software Foundation, either version 3 of the License, or
    9.11 +(at your option) any later version.
    9.12 +
    9.13 +This program is distributed in the hope that it will be useful,
    9.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 +GNU Lesser General Public License for more details.
    9.17 +
    9.18 +You should have received a copy of the GNU Lesser General Public License
    9.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    9.20 +*/
    9.21 +
    9.22 +#include <stdlib.h>
    9.23 +#include <string.h>
    9.24 +#include "ftype_module.h"
    9.25 +
    9.26 +static struct list_node {
    9.27 +	struct ftype_module *module;
    9.28 +	struct list_node *next;
    9.29 +} *modules;
    9.30 +
    9.31 +/* defined in modules.c which is generated by configure */
    9.32 +void img_modules_init();
    9.33 +
    9.34 +static int done_init;
    9.35 +
    9.36 +int img_register_module(struct ftype_module *mod)
    9.37 +{
    9.38 +	struct list_node *node;
    9.39 +
    9.40 +	if(!(node = malloc(sizeof *node))) {
    9.41 +		return -1;
    9.42 +	}
    9.43 +
    9.44 +	node->module = mod;
    9.45 +	node->next = modules;
    9.46 +	modules = node;
    9.47 +	return 0;
    9.48 +}
    9.49 +
    9.50 +struct ftype_module *img_find_format_module(struct img_io *io)
    9.51 +{
    9.52 +	struct list_node *node;
    9.53 +
    9.54 +	if(!done_init) {
    9.55 +		img_modules_init();
    9.56 +		done_init = 1;
    9.57 +	}
    9.58 +
    9.59 +	node = modules;
    9.60 +	while(node) {
    9.61 +		if(node->module->check(io) != -1) {
    9.62 +			return node->module;
    9.63 +		}
    9.64 +		node = node->next;
    9.65 +	}
    9.66 +	return 0;
    9.67 +}
    9.68 +
    9.69 +struct ftype_module *img_guess_format(const char *fname)
    9.70 +{
    9.71 +	struct list_node *node;
    9.72 +	char *suffix;
    9.73 +	int suffix_len;
    9.74 +
    9.75 +	if(!done_init) {
    9.76 +		img_modules_init();
    9.77 +		done_init = 1;
    9.78 +	}
    9.79 +
    9.80 +	if(!(suffix = strrchr(fname, '.'))) {
    9.81 +		return 0;	/* no suffix, can't guess ... */
    9.82 +	}
    9.83 +	suffix_len = strlen(suffix);
    9.84 +
    9.85 +	node = modules;
    9.86 +	while(node) {
    9.87 +		char *suflist = node->module->suffix;
    9.88 +		char *start, *end;
    9.89 +
    9.90 +		while(*suflist) {
    9.91 +			if(!(start = strstr(suflist, suffix))) {
    9.92 +				break;
    9.93 +			}
    9.94 +			end = start + suffix_len;
    9.95 +
    9.96 +			if(*end == ':' || *end == 0) {
    9.97 +				return node->module;	/* found it */
    9.98 +			}
    9.99 +			suflist = end;
   9.100 +		}
   9.101 +
   9.102 +		node = node->next;
   9.103 +	}
   9.104 +	return 0;
   9.105 +}
   9.106 +
   9.107 +struct ftype_module *img_get_module(int idx)
   9.108 +{
   9.109 +	struct list_node *node;
   9.110 +
   9.111 +	if(!done_init) {
   9.112 +		img_modules_init();
   9.113 +		done_init = 1;
   9.114 +	}
   9.115 +
   9.116 +	node = modules;
   9.117 +	while(node && idx--) {
   9.118 +		node = node->next;
   9.119 +	}
   9.120 +	return node->module;
   9.121 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/libs/imago2/ftype_module.h	Sat Sep 19 05:51:51 2015 +0300
    10.3 @@ -0,0 +1,39 @@
    10.4 +/*
    10.5 +libimago - a multi-format image file input/output library.
    10.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
    10.7 +
    10.8 +This program is free software: you can redistribute it and/or modify
    10.9 +it under the terms of the GNU Lesser General Public License as published
   10.10 +by the Free Software Foundation, either version 3 of the License, or
   10.11 +(at your option) any later version.
   10.12 +
   10.13 +This program is distributed in the hope that it will be useful,
   10.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 +GNU Lesser General Public License for more details.
   10.17 +
   10.18 +You should have received a copy of the GNU Lesser General Public License
   10.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   10.20 +*/
   10.21 +
   10.22 +#ifndef FTYPE_MODULE_H_
   10.23 +#define FTYPE_MODULE_H_
   10.24 +
   10.25 +#include "imago2.h"
   10.26 +
   10.27 +struct ftype_module {
   10.28 +	char *suffix;	/* used for format autodetection during saving only */
   10.29 +
   10.30 +	int (*check)(struct img_io *io);
   10.31 +	int (*read)(struct img_pixmap *img, struct img_io *io);
   10.32 +	int (*write)(struct img_pixmap *img, struct img_io *io);
   10.33 +};
   10.34 +
   10.35 +int img_register_module(struct ftype_module *mod);
   10.36 +
   10.37 +struct ftype_module *img_find_format_module(struct img_io *io);
   10.38 +struct ftype_module *img_guess_format(const char *fname);
   10.39 +struct ftype_module *img_get_module(int idx);
   10.40 +
   10.41 +
   10.42 +#endif	/* FTYPE_MODULE_H_ */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/libs/imago2/imago2.c	Sat Sep 19 05:51:51 2015 +0300
    11.3 @@ -0,0 +1,343 @@
    11.4 +/*
    11.5 +libimago - a multi-format image file input/output library.
    11.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
    11.7 +
    11.8 +This program is free software: you can redistribute it and/or modify
    11.9 +it under the terms of the GNU Lesser General Public License as published
   11.10 +by the Free Software Foundation, either version 3 of the License, or
   11.11 +(at your option) any later version.
   11.12 +
   11.13 +This program is distributed in the hope that it will be useful,
   11.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 +GNU Lesser General Public License for more details.
   11.17 +
   11.18 +You should have received a copy of the GNU Lesser General Public License
   11.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   11.20 +*/
   11.21 +
   11.22 +#include <stdio.h>
   11.23 +#include <stdlib.h>
   11.24 +#include <string.h>
   11.25 +#include "imago2.h"
   11.26 +#include "ftype_module.h"
   11.27 +
   11.28 +static int pixel_size(enum img_fmt fmt);
   11.29 +static size_t def_read(void *buf, size_t bytes, void *uptr);
   11.30 +static size_t def_write(void *buf, size_t bytes, void *uptr);
   11.31 +static long def_seek(long offset, int whence, void *uptr);
   11.32 +
   11.33 +
   11.34 +void img_init(struct img_pixmap *img)
   11.35 +{
   11.36 +	img->pixels = 0;
   11.37 +	img->width = img->height = 0;
   11.38 +	img->fmt = IMG_FMT_RGBA32;
   11.39 +	img->pixelsz = pixel_size(img->fmt);
   11.40 +	img->name = 0;
   11.41 +}
   11.42 +
   11.43 +
   11.44 +void img_destroy(struct img_pixmap *img)
   11.45 +{
   11.46 +	free(img->pixels);
   11.47 +	img->pixels = 0;	/* just in case... */
   11.48 +	img->width = img->height = 0xbadbeef;
   11.49 +	free(img->name);
   11.50 +}
   11.51 +
   11.52 +struct img_pixmap *img_create(void)
   11.53 +{
   11.54 +	struct img_pixmap *p;
   11.55 +
   11.56 +	if(!(p = malloc(sizeof *p))) {
   11.57 +		return 0;
   11.58 +	}
   11.59 +	img_init(p);
   11.60 +	return p;
   11.61 +}
   11.62 +
   11.63 +void img_free(struct img_pixmap *img)
   11.64 +{
   11.65 +	img_destroy(img);
   11.66 +	free(img);
   11.67 +}
   11.68 +
   11.69 +int img_set_name(struct img_pixmap *img, const char *name)
   11.70 +{
   11.71 +	char *tmp;
   11.72 +
   11.73 +	if(!(tmp = malloc(strlen(name) + 1))) {
   11.74 +		return -1;
   11.75 +	}
   11.76 +	strcpy(tmp, name);
   11.77 +	img->name = tmp;
   11.78 +	return 0;
   11.79 +}
   11.80 +
   11.81 +int img_set_format(struct img_pixmap *img, enum img_fmt fmt)
   11.82 +{
   11.83 +	if(img->pixels) {
   11.84 +		return img_convert(img, fmt);
   11.85 +	}
   11.86 +	img->fmt = fmt;
   11.87 +	return 0;
   11.88 +}
   11.89 +
   11.90 +int img_copy(struct img_pixmap *dest, struct img_pixmap *src)
   11.91 +{
   11.92 +	return img_set_pixels(dest, src->width, src->height, src->fmt, src->pixels);
   11.93 +}
   11.94 +
   11.95 +int img_set_pixels(struct img_pixmap *img, int w, int h, enum img_fmt fmt, void *pix)
   11.96 +{
   11.97 +	void *newpix;
   11.98 +	int pixsz = pixel_size(fmt);
   11.99 +
  11.100 +	if(!(newpix = malloc(w * h * pixsz))) {
  11.101 +		return -1;
  11.102 +	}
  11.103 +
  11.104 +	if(pix) {
  11.105 +		memcpy(newpix, pix, w * h * pixsz);
  11.106 +	} else {
  11.107 +		memset(newpix, 0, w * h * pixsz);
  11.108 +	}
  11.109 +
  11.110 +	free(img->pixels);
  11.111 +	img->pixels = newpix;
  11.112 +	img->width = w;
  11.113 +	img->height = h;
  11.114 +	img->pixelsz = pixsz;
  11.115 +	img->fmt = fmt;
  11.116 +	return 0;
  11.117 +}
  11.118 +
  11.119 +void *img_load_pixels(const char *fname, int *xsz, int *ysz, enum img_fmt fmt)
  11.120 +{
  11.121 +	struct img_pixmap img;
  11.122 +
  11.123 +	img_init(&img);
  11.124 +
  11.125 +	if(img_load(&img, fname) == -1) {
  11.126 +		return 0;
  11.127 +	}
  11.128 +	if(img.fmt != fmt) {
  11.129 +		if(img_convert(&img, fmt) == -1) {
  11.130 +			img_destroy(&img);
  11.131 +			return 0;
  11.132 +		}
  11.133 +	}
  11.134 +
  11.135 +	*xsz = img.width;
  11.136 +	*ysz = img.height;
  11.137 +	return img.pixels;
  11.138 +}
  11.139 +
  11.140 +int img_save_pixels(const char *fname, void *pix, int xsz, int ysz, enum img_fmt fmt)
  11.141 +{
  11.142 +	struct img_pixmap img;
  11.143 +
  11.144 +	img_init(&img);
  11.145 +	img.fmt = fmt;
  11.146 +	img.name = (char*)fname;
  11.147 +	img.width = xsz;
  11.148 +	img.height = ysz;
  11.149 +	img.pixels = pix;
  11.150 +
  11.151 +	return img_save(&img, fname);
  11.152 +}
  11.153 +
  11.154 +void img_free_pixels(void *pix)
  11.155 +{
  11.156 +	free(pix);
  11.157 +}
  11.158 +
  11.159 +int img_load(struct img_pixmap *img, const char *fname)
  11.160 +{
  11.161 +	int res;
  11.162 +	FILE *fp;
  11.163 +
  11.164 +	if(!(fp = fopen(fname, "rb"))) {
  11.165 +		return -1;
  11.166 +	}
  11.167 +	res = img_read_file(img, fp);
  11.168 +	fclose(fp);
  11.169 +	return res;
  11.170 +}
  11.171 +
  11.172 +/* TODO implement filetype selection */
  11.173 +int img_save(struct img_pixmap *img, const char *fname)
  11.174 +{
  11.175 +	int res;
  11.176 +	FILE *fp;
  11.177 +
  11.178 +	img_set_name(img, fname);
  11.179 +
  11.180 +	if(!(fp = fopen(fname, "wb"))) {
  11.181 +		return -1;
  11.182 +	}
  11.183 +	res = img_write_file(img, fp);
  11.184 +	fclose(fp);
  11.185 +	return res;
  11.186 +}
  11.187 +
  11.188 +int img_read_file(struct img_pixmap *img, FILE *fp)
  11.189 +{
  11.190 +	struct img_io io = {0, def_read, def_write, def_seek};
  11.191 +
  11.192 +	io.uptr = fp;
  11.193 +	return img_read(img, &io);
  11.194 +}
  11.195 +
  11.196 +int img_write_file(struct img_pixmap *img, FILE *fp)
  11.197 +{
  11.198 +	struct img_io io = {0, def_read, def_write, def_seek};
  11.199 +
  11.200 +	io.uptr = fp;
  11.201 +	return img_write(img, &io);
  11.202 +}
  11.203 +
  11.204 +int img_read(struct img_pixmap *img, struct img_io *io)
  11.205 +{
  11.206 +	struct ftype_module *mod;
  11.207 +
  11.208 +	if((mod = img_find_format_module(io))) {
  11.209 +		return mod->read(img, io);
  11.210 +	}
  11.211 +	return -1;
  11.212 +}
  11.213 +
  11.214 +int img_write(struct img_pixmap *img, struct img_io *io)
  11.215 +{
  11.216 +	struct ftype_module *mod;
  11.217 +
  11.218 +	if(!img->name || !(mod = img_guess_format(img->name))) {
  11.219 +		/* TODO throw some sort of warning? */
  11.220 +		/* TODO implement some sort of module priority or let the user specify? */
  11.221 +		if(!(mod = img_get_module(0))) {
  11.222 +			return -1;
  11.223 +		}
  11.224 +	}
  11.225 +
  11.226 +	return mod->write(img, io);
  11.227 +}
  11.228 +
  11.229 +int img_to_float(struct img_pixmap *img)
  11.230 +{
  11.231 +	enum img_fmt targ_fmt;
  11.232 +
  11.233 +	switch(img->fmt) {
  11.234 +	case IMG_FMT_GREY8:
  11.235 +		targ_fmt = IMG_FMT_GREYF;
  11.236 +		break;
  11.237 +
  11.238 +	case IMG_FMT_RGB24:
  11.239 +		targ_fmt = IMG_FMT_RGBF;
  11.240 +		break;
  11.241 +
  11.242 +	case IMG_FMT_RGBA32:
  11.243 +		targ_fmt = IMG_FMT_RGBAF;
  11.244 +		break;
  11.245 +
  11.246 +	default:
  11.247 +		return 0;	/* already float */
  11.248 +	}
  11.249 +
  11.250 +	return img_convert(img, targ_fmt);
  11.251 +}
  11.252 +
  11.253 +int img_to_integer(struct img_pixmap *img)
  11.254 +{
  11.255 +	enum img_fmt targ_fmt;
  11.256 +
  11.257 +	switch(img->fmt) {
  11.258 +	case IMG_FMT_GREYF:
  11.259 +		targ_fmt = IMG_FMT_GREY8;
  11.260 +		break;
  11.261 +
  11.262 +	case IMG_FMT_RGBF:
  11.263 +		targ_fmt = IMG_FMT_RGB24;
  11.264 +		break;
  11.265 +
  11.266 +	case IMG_FMT_RGBAF:
  11.267 +		targ_fmt = IMG_FMT_RGBA32;
  11.268 +		break;
  11.269 +
  11.270 +	default:
  11.271 +		return 0;	/* already integer */
  11.272 +	}
  11.273 +
  11.274 +	return img_convert(img, targ_fmt);
  11.275 +}
  11.276 +
  11.277 +int img_is_float(struct img_pixmap *img)
  11.278 +{
  11.279 +	return img->fmt >= IMG_FMT_GREYF && img->fmt <= IMG_FMT_RGBAF;
  11.280 +}
  11.281 +
  11.282 +int img_has_alpha(struct img_pixmap *img)
  11.283 +{
  11.284 +	return img->fmt >= IMG_FMT_GREY8 && img->fmt <= IMG_FMT_RGBA32;
  11.285 +}
  11.286 +
  11.287 +void img_io_set_user_data(struct img_io *io, void *uptr)
  11.288 +{
  11.289 +	io->uptr = uptr;
  11.290 +}
  11.291 +
  11.292 +void img_io_set_read_func(struct img_io *io, size_t (*read)(void*, size_t, void*))
  11.293 +{
  11.294 +	io->read = read;
  11.295 +}
  11.296 +
  11.297 +void img_io_set_write_func(struct img_io *io, size_t (*write)(void*, size_t, void*))
  11.298 +{
  11.299 +	io->write = write;
  11.300 +}
  11.301 +
  11.302 +void img_io_set_seek_func(struct img_io *io, long (*seek)(long, int, void*))
  11.303 +{
  11.304 +	io->seek = seek;
  11.305 +}
  11.306 +
  11.307 +
  11.308 +static int pixel_size(enum img_fmt fmt)
  11.309 +{
  11.310 +	switch(fmt) {
  11.311 +	case IMG_FMT_GREY8:
  11.312 +		return 1;
  11.313 +	case IMG_FMT_RGB24:
  11.314 +		return 3;
  11.315 +	case IMG_FMT_RGBA32:
  11.316 +		return 4;
  11.317 +	case IMG_FMT_GREYF:
  11.318 +		return sizeof(float);
  11.319 +	case IMG_FMT_RGBF:
  11.320 +		return 3 * sizeof(float);
  11.321 +	case IMG_FMT_RGBAF:
  11.322 +		return 4 * sizeof(float);
  11.323 +	default:
  11.324 +		break;
  11.325 +	}
  11.326 +	return 0;
  11.327 +}
  11.328 +
  11.329 +static size_t def_read(void *buf, size_t bytes, void *uptr)
  11.330 +{
  11.331 +	return uptr ? fread(buf, 1, bytes, uptr) : 0;
  11.332 +}
  11.333 +
  11.334 +static size_t def_write(void *buf, size_t bytes, void *uptr)
  11.335 +{
  11.336 +	return uptr ? fwrite(buf, 1, bytes, uptr) : 0;
  11.337 +}
  11.338 +
  11.339 +static long def_seek(long offset, int whence, void *uptr)
  11.340 +{
  11.341 +	if(!uptr || fseek(uptr, offset, whence) == -1) {
  11.342 +		return -1;
  11.343 +	}
  11.344 +	return ftell(uptr);
  11.345 +}
  11.346 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/libs/imago2/imago2.h	Sat Sep 19 05:51:51 2015 +0300
    12.3 @@ -0,0 +1,185 @@
    12.4 +/*
    12.5 +libimago - a multi-format image file input/output library.
    12.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
    12.7 +
    12.8 +This program is free software: you can redistribute it and/or modify
    12.9 +it under the terms of the GNU Lesser General Public License as published
   12.10 +by the Free Software Foundation, either version 3 of the License, or
   12.11 +(at your option) any later version.
   12.12 +
   12.13 +This program is distributed in the hope that it will be useful,
   12.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.16 +GNU Lesser General Public License for more details.
   12.17 +
   12.18 +You should have received a copy of the GNU Lesser General Public License
   12.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   12.20 +*/
   12.21 +
   12.22 +#ifndef IMAGO2_H_
   12.23 +#define IMAGO2_H_
   12.24 +
   12.25 +#include <stdio.h>
   12.26 +
   12.27 +#ifdef __cplusplus
   12.28 +#define IMG_OPTARG(arg, val)	arg = val
   12.29 +#else
   12.30 +#define IMG_OPTARG(arg, val)	arg
   12.31 +#endif
   12.32 +
   12.33 +/* XXX if you change this make sure to also change pack/unpack arrays in conv.c */
   12.34 +enum img_fmt {
   12.35 +	IMG_FMT_GREY8,
   12.36 +	IMG_FMT_RGB24,
   12.37 +	IMG_FMT_RGBA32,
   12.38 +	IMG_FMT_GREYF,
   12.39 +	IMG_FMT_RGBF,
   12.40 +	IMG_FMT_RGBAF,
   12.41 +
   12.42 +	NUM_IMG_FMT
   12.43 +};
   12.44 +
   12.45 +struct img_pixmap {
   12.46 +	void *pixels;
   12.47 +	int width, height;
   12.48 +	enum img_fmt fmt;
   12.49 +	int pixelsz;
   12.50 +	char *name;
   12.51 +};
   12.52 +
   12.53 +struct img_io {
   12.54 +	void *uptr;	/* user-data */
   12.55 +
   12.56 +	size_t (*read)(void *buf, size_t bytes, void *uptr);
   12.57 +	size_t (*write)(void *buf, size_t bytes, void *uptr);
   12.58 +	long (*seek)(long offs, int whence, void *uptr);
   12.59 +};
   12.60 +
   12.61 +#ifdef __cplusplus
   12.62 +extern "C" {
   12.63 +#endif
   12.64 +
   12.65 +/* initialize the img_pixmap structure */
   12.66 +void img_init(struct img_pixmap *img);
   12.67 +/* destroys the img_pixmap structure, freeing the pixel buffer (if available)
   12.68 + * and any other memory held by the pixmap.
   12.69 + */
   12.70 +void img_destroy(struct img_pixmap *img);
   12.71 +
   12.72 +/* convenience function that allocates an img_pixmap struct and then initializes it.
   12.73 + * returns null if the malloc fails.
   12.74 + */
   12.75 +struct img_pixmap *img_create(void);
   12.76 +/* frees a pixmap previously allocated with img_create (free followed by img_destroy) */
   12.77 +void img_free(struct img_pixmap *img);
   12.78 +
   12.79 +int img_set_name(struct img_pixmap *img, const char *name);
   12.80 +
   12.81 +/* set the image pixel format */
   12.82 +int img_set_format(struct img_pixmap *img, enum img_fmt fmt);
   12.83 +
   12.84 +/* copies one pixmap to another.
   12.85 + * equivalent to: img_set_pixels(dest, src->width, src->height, src->fmt, src->pixels)
   12.86 + */
   12.87 +int img_copy(struct img_pixmap *dest, struct img_pixmap *src);
   12.88 +
   12.89 +/* allocates a pixel buffer of the specified dimensions and format, and copies the
   12.90 + * pixels given through the pix pointer into it.
   12.91 + * the pix pointer can be null, in which case there's no copy, just allocation.
   12.92 + *
   12.93 + * C++: fmt and pix have default parameters IMG_FMT_RGBA32 and null respectively.
   12.94 + */
   12.95 +int img_set_pixels(struct img_pixmap *img, int w, int h, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32), IMG_OPTARG(void *pix, 0));
   12.96 +
   12.97 +/* Simplified image loading
   12.98 + * Loads the specified file, and returns a pointer to an array of pixels of the
   12.99 + * requested pixel format. The width and height of the image are returned through
  12.100 + * the xsz and ysz pointers.
  12.101 + * If the image cannot be loaded, the function returns null.
  12.102 + *
  12.103 + * C++: the format argument is optional and defaults to IMG_FMT_RGBA32
  12.104 + */
  12.105 +void *img_load_pixels(const char *fname, int *xsz, int *ysz, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32));
  12.106 +
  12.107 +/* Simplified image saving
  12.108 + * Reads an array of pixels supplied through the pix pointer, of dimensions xsz
  12.109 + * and ysz, and pixel-format fmt, and saves it to a file.
  12.110 + * The output filetype is guessed by the filename suffix.
  12.111 + *
  12.112 + * C++: the format argument is optional and defaults to IMG_FMT_RGBA32
  12.113 + */
  12.114 +int img_save_pixels(const char *fname, void *pix, int xsz, int ysz, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32));
  12.115 +
  12.116 +/* Frees the memory allocated by img_load_pixels */
  12.117 +void img_free_pixels(void *pix);
  12.118 +
  12.119 +/* Loads an image file into the supplied pixmap */
  12.120 +int img_load(struct img_pixmap *img, const char *fname);
  12.121 +/* Saves the supplied pixmap to a file. The output filetype is guessed by the filename suffix */
  12.122 +int img_save(struct img_pixmap *img, const char *fname);
  12.123 +
  12.124 +/* Reads an image from an open FILE* into the supplied pixmap */
  12.125 +int img_read_file(struct img_pixmap *img, FILE *fp);
  12.126 +/* Writes the supplied pixmap to an open FILE* */
  12.127 +int img_write_file(struct img_pixmap *img, FILE *fp);
  12.128 +
  12.129 +/* Reads an image using user-defined file-i/o functions (see img_io_set_*) */
  12.130 +int img_read(struct img_pixmap *img, struct img_io *io);
  12.131 +/* Writes an image using user-defined file-i/o functions (see img_io_set_*) */
  12.132 +int img_write(struct img_pixmap *img, struct img_io *io);
  12.133 +
  12.134 +/* Converts an image to the specified pixel format */
  12.135 +int img_convert(struct img_pixmap *img, enum img_fmt tofmt);
  12.136 +
  12.137 +/* Converts an image from an integer pixel format to the corresponding floating point one */
  12.138 +int img_to_float(struct img_pixmap *img);
  12.139 +/* Converts an image from a floating point pixel format to the corresponding integer one */
  12.140 +int img_to_integer(struct img_pixmap *img);
  12.141 +
  12.142 +/* Returns non-zero (true) if the supplied image is in a floating point pixel format */
  12.143 +int img_is_float(struct img_pixmap *img);
  12.144 +/* Returns non-zero (true) if the supplied image has an alpha channel */
  12.145 +int img_has_alpha(struct img_pixmap *img);
  12.146 +
  12.147 +
  12.148 +/* These functions can be used to fill an img_io struct before it's passed to
  12.149 + * one of the user-defined i/o image reading/writing functions (img_read/img_write).
  12.150 + *
  12.151 + * User-defined i/o functions:
  12.152 + *
  12.153 + * - size_t read_func(void *buffer, size_t bytes, void *user_ptr)
  12.154 + * Must try to fill the buffer with the specified number of bytes, and return
  12.155 + * the number of bytes actually read.
  12.156 + *
  12.157 + * - size_t write_func(void *buffer, size_t bytes, void *user_ptr)
  12.158 + * Must write the specified number of bytes from the supplied buffer and return
  12.159 + * the number of bytes actually written.
  12.160 + *
  12.161 + * - long seek_func(long offset, int whence, void *user_ptr)
  12.162 + * Must seek offset bytes from: the beginning of the file if whence is SEEK_SET,
  12.163 + * the current position if whence is SEEK_CUR, or the end of the file if whence is
  12.164 + * SEEK_END, and return the resulting file offset from the beginning of the file.
  12.165 + * (i.e. seek_func(0, SEEK_CUR, user_ptr); must be equivalent to an ftell).
  12.166 + *
  12.167 + * All three functions get the user-data pointer set through img_io_set_user_data
  12.168 + * as their last argument.
  12.169 + *
  12.170 + * Note: obviously you don't need to set a write function if you're only going
  12.171 + * to call img_read, or the read and seek function if you're only going to call
  12.172 + * img_write.
  12.173 + *
  12.174 + * Note: if the user-supplied write function is buffered, make sure to flush
  12.175 + * (or close the file) after img_write returns.
  12.176 + */
  12.177 +void img_io_set_user_data(struct img_io *io, void *uptr);
  12.178 +void img_io_set_read_func(struct img_io *io, size_t (*read)(void*, size_t, void*));
  12.179 +void img_io_set_write_func(struct img_io *io, size_t (*write)(void*, size_t, void*));
  12.180 +void img_io_set_seek_func(struct img_io *io, long (*seek)(long, int, void*));
  12.181 +
  12.182 +
  12.183 +#ifdef __cplusplus
  12.184 +}
  12.185 +#endif
  12.186 +
  12.187 +
  12.188 +#endif	/* IMAGO_H_ */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/libs/imago2/modules.c	Sat Sep 19 05:51:51 2015 +0300
    13.3 @@ -0,0 +1,11 @@
    13.4 +/* this file is generated by ./configure, do not edit */
    13.5 +int img_register_jpeg();
    13.6 +int img_register_png();
    13.7 +int img_register_ppm();
    13.8 +
    13.9 +void img_modules_init(void)
   13.10 +{
   13.11 +	img_register_jpeg();
   13.12 +	img_register_png();
   13.13 +	img_register_ppm();
   13.14 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/libs/libjpeg/README	Sat Sep 19 05:51:51 2015 +0300
    14.3 @@ -0,0 +1,326 @@
    14.4 +The Independent JPEG Group's JPEG software
    14.5 +==========================================
    14.6 +
    14.7 +README for release 8c of 16-Jan-2011
    14.8 +====================================
    14.9 +
   14.10 +This distribution contains the eighth public release of the Independent JPEG
   14.11 +Group's free JPEG software.  You are welcome to redistribute this software and
   14.12 +to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
   14.13 +
   14.14 +This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
   14.15 +Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
   14.16 +Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
   14.17 +and other members of the Independent JPEG Group.
   14.18 +
   14.19 +IJG is not affiliated with the official ISO JPEG standards committee.
   14.20 +
   14.21 +
   14.22 +DOCUMENTATION ROADMAP
   14.23 +=====================
   14.24 +
   14.25 +This file contains the following sections:
   14.26 +
   14.27 +OVERVIEW            General description of JPEG and the IJG software.
   14.28 +LEGAL ISSUES        Copyright, lack of warranty, terms of distribution.
   14.29 +REFERENCES          Where to learn more about JPEG.
   14.30 +ARCHIVE LOCATIONS   Where to find newer versions of this software.
   14.31 +ACKNOWLEDGMENTS     Special thanks.
   14.32 +FILE FORMAT WARS    Software *not* to get.
   14.33 +TO DO               Plans for future IJG releases.
   14.34 +
   14.35 +Other documentation files in the distribution are:
   14.36 +
   14.37 +User documentation:
   14.38 +  install.txt       How to configure and install the IJG software.
   14.39 +  usage.txt         Usage instructions for cjpeg, djpeg, jpegtran,
   14.40 +                    rdjpgcom, and wrjpgcom.
   14.41 +  *.1               Unix-style man pages for programs (same info as usage.txt).
   14.42 +  wizard.txt        Advanced usage instructions for JPEG wizards only.
   14.43 +  change.log        Version-to-version change highlights.
   14.44 +Programmer and internal documentation:
   14.45 +  libjpeg.txt       How to use the JPEG library in your own programs.
   14.46 +  example.c         Sample code for calling the JPEG library.
   14.47 +  structure.txt     Overview of the JPEG library's internal structure.
   14.48 +  filelist.txt      Road map of IJG files.
   14.49 +  coderules.txt     Coding style rules --- please read if you contribute code.
   14.50 +
   14.51 +Please read at least the files install.txt and usage.txt.  Some information
   14.52 +can also be found in the JPEG FAQ (Frequently Asked Questions) article.  See
   14.53 +ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
   14.54 +
   14.55 +If you want to understand how the JPEG code works, we suggest reading one or
   14.56 +more of the REFERENCES, then looking at the documentation files (in roughly
   14.57 +the order listed) before diving into the code.
   14.58 +
   14.59 +
   14.60 +OVERVIEW
   14.61 +========
   14.62 +
   14.63 +This package contains C software to implement JPEG image encoding, decoding,
   14.64 +and transcoding.  JPEG (pronounced "jay-peg") is a standardized compression
   14.65 +method for full-color and gray-scale images.
   14.66 +
   14.67 +This software implements JPEG baseline, extended-sequential, and progressive
   14.68 +compression processes.  Provision is made for supporting all variants of these
   14.69 +processes, although some uncommon parameter settings aren't implemented yet.
   14.70 +We have made no provision for supporting the hierarchical or lossless
   14.71 +processes defined in the standard.
   14.72 +
   14.73 +We provide a set of library routines for reading and writing JPEG image files,
   14.74 +plus two sample applications "cjpeg" and "djpeg", which use the library to
   14.75 +perform conversion between JPEG and some other popular image file formats.
   14.76 +The library is intended to be reused in other applications.
   14.77 +
   14.78 +In order to support file conversion and viewing software, we have included
   14.79 +considerable functionality beyond the bare JPEG coding/decoding capability;
   14.80 +for example, the color quantization modules are not strictly part of JPEG
   14.81 +decoding, but they are essential for output to colormapped file formats or
   14.82 +colormapped displays.  These extra functions can be compiled out of the
   14.83 +library if not required for a particular application.
   14.84 +
   14.85 +We have also included "jpegtran", a utility for lossless transcoding between
   14.86 +different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple
   14.87 +applications for inserting and extracting textual comments in JFIF files.
   14.88 +
   14.89 +The emphasis in designing this software has been on achieving portability and
   14.90 +flexibility, while also making it fast enough to be useful.  In particular,
   14.91 +the software is not intended to be read as a tutorial on JPEG.  (See the
   14.92 +REFERENCES section for introductory material.)  Rather, it is intended to
   14.93 +be reliable, portable, industrial-strength code.  We do not claim to have
   14.94 +achieved that goal in every aspect of the software, but we strive for it.
   14.95 +
   14.96 +We welcome the use of this software as a component of commercial products.
   14.97 +No royalty is required, but we do ask for an acknowledgement in product
   14.98 +documentation, as described under LEGAL ISSUES.
   14.99 +
  14.100 +
  14.101 +LEGAL ISSUES
  14.102 +============
  14.103 +
  14.104 +In plain English:
  14.105 +
  14.106 +1. We don't promise that this software works.  (But if you find any bugs,
  14.107 +   please let us know!)
  14.108 +2. You can use this software for whatever you want.  You don't have to pay us.
  14.109 +3. You may not pretend that you wrote this software.  If you use it in a
  14.110 +   program, you must acknowledge somewhere in your documentation that
  14.111 +   you've used the IJG code.
  14.112 +
  14.113 +In legalese:
  14.114 +
  14.115 +The authors make NO WARRANTY or representation, either express or implied,
  14.116 +with respect to this software, its quality, accuracy, merchantability, or
  14.117 +fitness for a particular purpose.  This software is provided "AS IS", and you,
  14.118 +its user, assume the entire risk as to its quality and accuracy.
  14.119 +
  14.120 +This software is copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding.
  14.121 +All Rights Reserved except as specified below.
  14.122 +
  14.123 +Permission is hereby granted to use, copy, modify, and distribute this
  14.124 +software (or portions thereof) for any purpose, without fee, subject to these
  14.125 +conditions:
  14.126 +(1) If any part of the source code for this software is distributed, then this
  14.127 +README file must be included, with this copyright and no-warranty notice
  14.128 +unaltered; and any additions, deletions, or changes to the original files
  14.129 +must be clearly indicated in accompanying documentation.
  14.130 +(2) If only executable code is distributed, then the accompanying
  14.131 +documentation must state that "this software is based in part on the work of
  14.132 +the Independent JPEG Group".
  14.133 +(3) Permission for use of this software is granted only if the user accepts
  14.134 +full responsibility for any undesirable consequences; the authors accept
  14.135 +NO LIABILITY for damages of any kind.
  14.136 +
  14.137 +These conditions apply to any software derived from or based on the IJG code,
  14.138 +not just to the unmodified library.  If you use our work, you ought to
  14.139 +acknowledge us.
  14.140 +
  14.141 +Permission is NOT granted for the use of any IJG author's name or company name
  14.142 +in advertising or publicity relating to this software or products derived from
  14.143 +it.  This software may be referred to only as "the Independent JPEG Group's
  14.144 +software".
  14.145 +
  14.146 +We specifically permit and encourage the use of this software as the basis of
  14.147 +commercial products, provided that all warranty or liability claims are
  14.148 +assumed by the product vendor.
  14.149 +
  14.150 +
  14.151 +ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
  14.152 +sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
  14.153 +ansi2knr.c is NOT covered by the above copyright and conditions, but instead
  14.154 +by the usual distribution terms of the Free Software Foundation; principally,
  14.155 +that you must include source code if you redistribute it.  (See the file
  14.156 +ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
  14.157 +of any program generated from the IJG code, this does not limit you more than
  14.158 +the foregoing paragraphs do.
  14.159 +
  14.160 +The Unix configuration script "configure" was produced with GNU Autoconf.
  14.161 +It is copyright by the Free Software Foundation but is freely distributable.
  14.162 +The same holds for its supporting scripts (config.guess, config.sub,
  14.163 +ltmain.sh).  Another support script, install-sh, is copyright by X Consortium
  14.164 +but is also freely distributable.
  14.165 +
  14.166 +The IJG distribution formerly included code to read and write GIF files.
  14.167 +To avoid entanglement with the Unisys LZW patent, GIF reading support has
  14.168 +been removed altogether, and the GIF writer has been simplified to produce
  14.169 +"uncompressed GIFs".  This technique does not use the LZW algorithm; the
  14.170 +resulting GIF files are larger than usual, but are readable by all standard
  14.171 +GIF decoders.
  14.172 +
  14.173 +We are required to state that
  14.174 +    "The Graphics Interchange Format(c) is the Copyright property of
  14.175 +    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
  14.176 +    CompuServe Incorporated."
  14.177 +
  14.178 +
  14.179 +REFERENCES
  14.180 +==========
  14.181 +
  14.182 +We recommend reading one or more of these references before trying to
  14.183 +understand the innards of the JPEG software.
  14.184 +
  14.185 +The best short technical introduction to the JPEG compression algorithm is
  14.186 +	Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  14.187 +	Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  14.188 +(Adjacent articles in that issue discuss MPEG motion picture compression,
  14.189 +applications of JPEG, and related topics.)  If you don't have the CACM issue
  14.190 +handy, a PostScript file containing a revised version of Wallace's article is
  14.191 +available at http://www.ijg.org/files/wallace.ps.gz.  The file (actually
  14.192 +a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
  14.193 +omits the sample images that appeared in CACM, but it includes corrections
  14.194 +and some added material.  Note: the Wallace article is copyright ACM and IEEE,
  14.195 +and it may not be used for commercial purposes.
  14.196 +
  14.197 +A somewhat less technical, more leisurely introduction to JPEG can be found in
  14.198 +"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
  14.199 +M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1.  This book provides
  14.200 +good explanations and example C code for a multitude of compression methods
  14.201 +including JPEG.  It is an excellent source if you are comfortable reading C
  14.202 +code but don't know much about data compression in general.  The book's JPEG
  14.203 +sample code is far from industrial-strength, but when you are ready to look
  14.204 +at a full implementation, you've got one here...
  14.205 +
  14.206 +The best currently available description of JPEG is the textbook "JPEG Still
  14.207 +Image Data Compression Standard" by William B. Pennebaker and Joan L.
  14.208 +Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.
  14.209 +Price US$59.95, 638 pp.  The book includes the complete text of the ISO JPEG
  14.210 +standards (DIS 10918-1 and draft DIS 10918-2).
  14.211 +Although this is by far the most detailed and comprehensive exposition of
  14.212 +JPEG publicly available, we point out that it is still missing an explanation
  14.213 +of the most essential properties and algorithms of the underlying DCT
  14.214 +technology.
  14.215 +If you think that you know about DCT-based JPEG after reading this book,
  14.216 +then you are in delusion.  The real fundamentals and corresponding potential
  14.217 +of DCT-based JPEG are not publicly known so far, and that is the reason for
  14.218 +all the mistaken developments taking place in the image coding domain.
  14.219 +
  14.220 +The original JPEG standard is divided into two parts, Part 1 being the actual
  14.221 +specification, while Part 2 covers compliance testing methods.  Part 1 is
  14.222 +titled "Digital Compression and Coding of Continuous-tone Still Images,
  14.223 +Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
  14.224 +10918-1, ITU-T T.81.  Part 2 is titled "Digital Compression and Coding of
  14.225 +Continuous-tone Still Images, Part 2: Compliance testing" and has document
  14.226 +numbers ISO/IEC IS 10918-2, ITU-T T.83.
  14.227 +IJG JPEG 8 introduces an implementation of the JPEG SmartScale extension
  14.228 +which is specified in a contributed document at ITU and ISO with title "ITU-T
  14.229 +JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced Image Coding", April
  14.230 +2006, Geneva, Switzerland.  The latest version of the document is Revision 3.
  14.231 +
  14.232 +The JPEG standard does not specify all details of an interchangeable file
  14.233 +format.  For the omitted details we follow the "JFIF" conventions, revision
  14.234 +1.02.  JFIF 1.02 has been adopted as an Ecma International Technical Report
  14.235 +and thus received a formal publication status.  It is available as a free
  14.236 +download in PDF format from
  14.237 +http://www.ecma-international.org/publications/techreports/E-TR-098.htm.
  14.238 +A PostScript version of the JFIF document is available at
  14.239 +http://www.ijg.org/files/jfif.ps.gz.  There is also a plain text version at
  14.240 +http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures.
  14.241 +
  14.242 +The TIFF 6.0 file format specification can be obtained by FTP from
  14.243 +ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz.  The JPEG incorporation scheme
  14.244 +found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
  14.245 +IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
  14.246 +Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
  14.247 +(Compression tag 7).  Copies of this Note can be obtained from
  14.248 +http://www.ijg.org/files/.  It is expected that the next revision
  14.249 +of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
  14.250 +Although IJG's own code does not support TIFF/JPEG, the free libtiff library
  14.251 +uses our library to implement TIFF/JPEG per the Note.
  14.252 +
  14.253 +
  14.254 +ARCHIVE LOCATIONS
  14.255 +=================
  14.256 +
  14.257 +The "official" archive site for this software is www.ijg.org.
  14.258 +The most recent released version can always be found there in
  14.259 +directory "files".  This particular version will be archived as
  14.260 +http://www.ijg.org/files/jpegsrc.v8c.tar.gz, and in Windows-compatible
  14.261 +"zip" archive format as http://www.ijg.org/files/jpegsr8c.zip.
  14.262 +
  14.263 +The JPEG FAQ (Frequently Asked Questions) article is a source of some
  14.264 +general information about JPEG.
  14.265 +It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
  14.266 +and other news.answers archive sites, including the official news.answers
  14.267 +archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
  14.268 +If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
  14.269 +with body
  14.270 +	send usenet/news.answers/jpeg-faq/part1
  14.271 +	send usenet/news.answers/jpeg-faq/part2
  14.272 +
  14.273 +
  14.274 +ACKNOWLEDGMENTS
  14.275 +===============
  14.276 +
  14.277 +Thank to Juergen Bruder for providing me with a copy of the common DCT
  14.278 +algorithm article, only to find out that I had come to the same result
  14.279 +in a more direct and comprehensible way with a more generative approach.
  14.280 +
  14.281 +Thank to Istvan Sebestyen and Joan L. Mitchell for inviting me to the
  14.282 +ITU JPEG (Study Group 16) meeting in Geneva, Switzerland.
  14.283 +
  14.284 +Thank to Thomas Wiegand and Gary Sullivan for inviting me to the
  14.285 +Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland.
  14.286 +
  14.287 +Thank to John Korejwa and Massimo Ballerini for inviting me to
  14.288 +fruitful consultations in Boston, MA and Milan, Italy.
  14.289 +
  14.290 +Thank to Hendrik Elstner, Roland Fassauer, Simone Zuck, Guenther
  14.291 +Maier-Gerber, Walter Stoeber, Fred Schmitz, and Norbert Braunagel
  14.292 +for corresponding business development.
  14.293 +
  14.294 +Thank to Nico Zschach and Dirk Stelling of the technical support team
  14.295 +at the Digital Images company in Halle for providing me with extra
  14.296 +equipment for configuration tests.
  14.297 +
  14.298 +Thank to Richard F. Lyon (then of Foveon Inc.) for fruitful
  14.299 +communication about JPEG configuration in Sigma Photo Pro software.
  14.300 +
  14.301 +Thank to Andrew Finkenstadt for hosting the ijg.org site.
  14.302 +
  14.303 +Last but not least special thank to Thomas G. Lane for the original
  14.304 +design and development of this singular software package.
  14.305 +
  14.306 +
  14.307 +FILE FORMAT WARS
  14.308 +================
  14.309 +
  14.310 +The ISO JPEG standards committee actually promotes different formats like
  14.311 +"JPEG 2000" or "JPEG XR" which are incompatible with original DCT-based
  14.312 +JPEG and which are based on faulty technologies.  IJG therefore does not
  14.313 +and will not support such momentary mistakes (see REFERENCES).
  14.314 +We have little or no sympathy for the promotion of these formats.  Indeed,
  14.315 +one of the original reasons for developing this free software was to help
  14.316 +force convergence on common, interoperable format standards for JPEG files.
  14.317 +Don't use an incompatible file format!
  14.318 +(In any case, our decoder will remain capable of reading existing JPEG
  14.319 +image files indefinitely.)
  14.320 +
  14.321 +
  14.322 +TO DO
  14.323 +=====
  14.324 +
  14.325 +Version 8 is the first release of a new generation JPEG standard
  14.326 +to overcome the limitations of the original JPEG specification.
  14.327 +More features are being prepared for coming releases...
  14.328 +
  14.329 +Please send bug reports, offers of help, etc. to jpeg-info@uc.ag.
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/libs/libjpeg/cderror.h	Sat Sep 19 05:51:51 2015 +0300
    15.3 @@ -0,0 +1,132 @@
    15.4 +/*
    15.5 + * cderror.h
    15.6 + *
    15.7 + * Copyright (C) 1994-1997, Thomas G. Lane.
    15.8 + * This file is part of the Independent JPEG Group's software.
    15.9 + * For conditions of distribution and use, see the accompanying README file.
   15.10 + *
   15.11 + * This file defines the error and message codes for the cjpeg/djpeg
   15.12 + * applications.  These strings are not needed as part of the JPEG library
   15.13 + * proper.
   15.14 + * Edit this file to add new codes, or to translate the message strings to
   15.15 + * some other language.
   15.16 + */
   15.17 +
   15.18 +/*
   15.19 + * To define the enum list of message codes, include this file without
   15.20 + * defining macro JMESSAGE.  To create a message string table, include it
   15.21 + * again with a suitable JMESSAGE definition (see jerror.c for an example).
   15.22 + */
   15.23 +#ifndef JMESSAGE
   15.24 +#ifndef CDERROR_H
   15.25 +#define CDERROR_H
   15.26 +/* First time through, define the enum list */
   15.27 +#define JMAKE_ENUM_LIST
   15.28 +#else
   15.29 +/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
   15.30 +#define JMESSAGE(code,string)
   15.31 +#endif /* CDERROR_H */
   15.32 +#endif /* JMESSAGE */
   15.33 +
   15.34 +#ifdef JMAKE_ENUM_LIST
   15.35 +
   15.36 +typedef enum {
   15.37 +
   15.38 +#define JMESSAGE(code,string)	code ,
   15.39 +
   15.40 +#endif /* JMAKE_ENUM_LIST */
   15.41 +
   15.42 +JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
   15.43 +
   15.44 +#ifdef BMP_SUPPORTED
   15.45 +JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
   15.46 +JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
   15.47 +JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
   15.48 +JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
   15.49 +JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
   15.50 +JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
   15.51 +JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
   15.52 +JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
   15.53 +JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
   15.54 +JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
   15.55 +JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
   15.56 +#endif /* BMP_SUPPORTED */
   15.57 +
   15.58 +#ifdef GIF_SUPPORTED
   15.59 +JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
   15.60 +JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
   15.61 +JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
   15.62 +JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
   15.63 +JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
   15.64 +JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
   15.65 +JMESSAGE(JTRC_GIF_BADVERSION,
   15.66 +	 "Warning: unexpected GIF version number '%c%c%c'")
   15.67 +JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
   15.68 +JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
   15.69 +JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
   15.70 +JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
   15.71 +JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
   15.72 +JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
   15.73 +#endif /* GIF_SUPPORTED */
   15.74 +
   15.75 +#ifdef PPM_SUPPORTED
   15.76 +JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
   15.77 +JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
   15.78 +JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
   15.79 +JMESSAGE(JTRC_PGM, "%ux%u PGM image")
   15.80 +JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
   15.81 +JMESSAGE(JTRC_PPM, "%ux%u PPM image")
   15.82 +JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
   15.83 +#endif /* PPM_SUPPORTED */
   15.84 +
   15.85 +#ifdef RLE_SUPPORTED
   15.86 +JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
   15.87 +JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
   15.88 +JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
   15.89 +JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
   15.90 +JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
   15.91 +JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
   15.92 +JMESSAGE(JERR_RLE_NOT, "Not an RLE file")
   15.93 +JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
   15.94 +JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
   15.95 +JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
   15.96 +JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
   15.97 +JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
   15.98 +JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
   15.99 +JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
  15.100 +#endif /* RLE_SUPPORTED */
  15.101 +
  15.102 +#ifdef TARGA_SUPPORTED
  15.103 +JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
  15.104 +JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
  15.105 +JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
  15.106 +JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
  15.107 +JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
  15.108 +JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
  15.109 +#else
  15.110 +JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
  15.111 +#endif /* TARGA_SUPPORTED */
  15.112 +
  15.113 +JMESSAGE(JERR_BAD_CMAP_FILE,
  15.114 +	 "Color map file is invalid or of unsupported format")
  15.115 +JMESSAGE(JERR_TOO_MANY_COLORS,
  15.116 +	 "Output file format cannot handle %d colormap entries")
  15.117 +JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
  15.118 +#ifdef TARGA_SUPPORTED
  15.119 +JMESSAGE(JERR_UNKNOWN_FORMAT,
  15.120 +	 "Unrecognized input file format --- perhaps you need -targa")
  15.121 +#else
  15.122 +JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
  15.123 +#endif
  15.124 +JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")
  15.125 +
  15.126 +#ifdef JMAKE_ENUM_LIST
  15.127 +
  15.128 +  JMSG_LASTADDONCODE
  15.129 +} ADDON_MESSAGE_CODE;
  15.130 +
  15.131 +#undef JMAKE_ENUM_LIST
  15.132 +#endif /* JMAKE_ENUM_LIST */
  15.133 +
  15.134 +/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
  15.135 +#undef JMESSAGE
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/libs/libjpeg/jcapimin.c	Sat Sep 19 05:51:51 2015 +0300
    16.3 @@ -0,0 +1,280 @@
    16.4 +/*
    16.5 + * jcapimin.c
    16.6 + *
    16.7 + * Copyright (C) 1994-1998, Thomas G. Lane.
    16.8 + * This file is part of the Independent JPEG Group's software.
    16.9 + * For conditions of distribution and use, see the accompanying README file.
   16.10 + *
   16.11 + * This file contains application interface code for the compression half
   16.12 + * of the JPEG library.  These are the "minimum" API routines that may be
   16.13 + * needed in either the normal full-compression case or the transcoding-only
   16.14 + * case.
   16.15 + *
   16.16 + * Most of the routines intended to be called directly by an application
   16.17 + * are in this file or in jcapistd.c.  But also see jcparam.c for
   16.18 + * parameter-setup helper routines, jcomapi.c for routines shared by
   16.19 + * compression and decompression, and jctrans.c for the transcoding case.
   16.20 + */
   16.21 +
   16.22 +#define JPEG_INTERNALS
   16.23 +#include "jinclude.h"
   16.24 +#include "jpeglib.h"
   16.25 +
   16.26 +
   16.27 +/*
   16.28 + * Initialization of a JPEG compression object.
   16.29 + * The error manager must already be set up (in case memory manager fails).
   16.30 + */
   16.31 +
   16.32 +GLOBAL(void)
   16.33 +jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
   16.34 +{
   16.35 +  int i;
   16.36 +
   16.37 +  /* Guard against version mismatches between library and caller. */
   16.38 +  cinfo->mem = NULL;		/* so jpeg_destroy knows mem mgr not called */
   16.39 +  if (version != JPEG_LIB_VERSION)
   16.40 +    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
   16.41 +  if (structsize != SIZEOF(struct jpeg_compress_struct))
   16.42 +    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 
   16.43 +	     (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
   16.44 +
   16.45 +  /* For debugging purposes, we zero the whole master structure.
   16.46 +   * But the application has already set the err pointer, and may have set
   16.47 +   * client_data, so we have to save and restore those fields.
   16.48 +   * Note: if application hasn't set client_data, tools like Purify may
   16.49 +   * complain here.
   16.50 +   */
   16.51 +  {
   16.52 +    struct jpeg_error_mgr * err = cinfo->err;
   16.53 +    void * client_data = cinfo->client_data; /* ignore Purify complaint here */
   16.54 +    MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
   16.55 +    cinfo->err = err;
   16.56 +    cinfo->client_data = client_data;
   16.57 +  }
   16.58 +  cinfo->is_decompressor = FALSE;
   16.59 +
   16.60 +  /* Initialize a memory manager instance for this object */
   16.61 +  jinit_memory_mgr((j_common_ptr) cinfo);
   16.62 +
   16.63 +  /* Zero out pointers to permanent structures. */
   16.64 +  cinfo->progress = NULL;
   16.65 +  cinfo->dest = NULL;
   16.66 +
   16.67 +  cinfo->comp_info = NULL;
   16.68 +
   16.69 +  for (i = 0; i < NUM_QUANT_TBLS; i++)
   16.70 +    cinfo->quant_tbl_ptrs[i] = NULL;
   16.71 +
   16.72 +  for (i = 0; i < NUM_HUFF_TBLS; i++) {
   16.73 +    cinfo->dc_huff_tbl_ptrs[i] = NULL;
   16.74 +    cinfo->ac_huff_tbl_ptrs[i] = NULL;
   16.75 +  }
   16.76 +
   16.77 +  cinfo->script_space = NULL;
   16.78 +
   16.79 +  cinfo->input_gamma = 1.0;	/* in case application forgets */
   16.80 +
   16.81 +  /* OK, I'm ready */
   16.82 +  cinfo->global_state = CSTATE_START;
   16.83 +}
   16.84 +
   16.85 +
   16.86 +/*
   16.87 + * Destruction of a JPEG compression object
   16.88 + */
   16.89 +
   16.90 +GLOBAL(void)
   16.91 +jpeg_destroy_compress (j_compress_ptr cinfo)
   16.92 +{
   16.93 +  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
   16.94 +}
   16.95 +
   16.96 +
   16.97 +/*
   16.98 + * Abort processing of a JPEG compression operation,
   16.99 + * but don't destroy the object itself.
  16.100 + */
  16.101 +
  16.102 +GLOBAL(void)
  16.103 +jpeg_abort_compress (j_compress_ptr cinfo)
  16.104 +{
  16.105 +  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  16.106 +}
  16.107 +
  16.108 +
  16.109 +/*
  16.110 + * Forcibly suppress or un-suppress all quantization and Huffman tables.
  16.111 + * Marks all currently defined tables as already written (if suppress)
  16.112 + * or not written (if !suppress).  This will control whether they get emitted
  16.113 + * by a subsequent jpeg_start_compress call.
  16.114 + *
  16.115 + * This routine is exported for use by applications that want to produce
  16.116 + * abbreviated JPEG datastreams.  It logically belongs in jcparam.c, but
  16.117 + * since it is called by jpeg_start_compress, we put it here --- otherwise
  16.118 + * jcparam.o would be linked whether the application used it or not.
  16.119 + */
  16.120 +
  16.121 +GLOBAL(void)
  16.122 +jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  16.123 +{
  16.124 +  int i;
  16.125 +  JQUANT_TBL * qtbl;
  16.126 +  JHUFF_TBL * htbl;
  16.127 +
  16.128 +  for (i = 0; i < NUM_QUANT_TBLS; i++) {
  16.129 +    if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  16.130 +      qtbl->sent_table = suppress;
  16.131 +  }
  16.132 +
  16.133 +  for (i = 0; i < NUM_HUFF_TBLS; i++) {
  16.134 +    if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  16.135 +      htbl->sent_table = suppress;
  16.136 +    if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  16.137 +      htbl->sent_table = suppress;
  16.138 +  }
  16.139 +}
  16.140 +
  16.141 +
  16.142 +/*
  16.143 + * Finish JPEG compression.
  16.144 + *
  16.145 + * If a multipass operating mode was selected, this may do a great deal of
  16.146 + * work including most of the actual output.
  16.147 + */
  16.148 +
  16.149 +GLOBAL(void)
  16.150 +jpeg_finish_compress (j_compress_ptr cinfo)
  16.151 +{
  16.152 +  JDIMENSION iMCU_row;
  16.153 +
  16.154 +  if (cinfo->global_state == CSTATE_SCANNING ||
  16.155 +      cinfo->global_state == CSTATE_RAW_OK) {
  16.156 +    /* Terminate first pass */
  16.157 +    if (cinfo->next_scanline < cinfo->image_height)
  16.158 +      ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  16.159 +    (*cinfo->master->finish_pass) (cinfo);
  16.160 +  } else if (cinfo->global_state != CSTATE_WRCOEFS)
  16.161 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  16.162 +  /* Perform any remaining passes */
  16.163 +  while (! cinfo->master->is_last_pass) {
  16.164 +    (*cinfo->master->prepare_for_pass) (cinfo);
  16.165 +    for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  16.166 +      if (cinfo->progress != NULL) {
  16.167 +	cinfo->progress->pass_counter = (long) iMCU_row;
  16.168 +	cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  16.169 +	(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  16.170 +      }
  16.171 +      /* We bypass the main controller and invoke coef controller directly;
  16.172 +       * all work is being done from the coefficient buffer.
  16.173 +       */
  16.174 +      if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  16.175 +	ERREXIT(cinfo, JERR_CANT_SUSPEND);
  16.176 +    }
  16.177 +    (*cinfo->master->finish_pass) (cinfo);
  16.178 +  }
  16.179 +  /* Write EOI, do final cleanup */
  16.180 +  (*cinfo->marker->write_file_trailer) (cinfo);
  16.181 +  (*cinfo->dest->term_destination) (cinfo);
  16.182 +  /* We can use jpeg_abort to release memory and reset global_state */
  16.183 +  jpeg_abort((j_common_ptr) cinfo);
  16.184 +}
  16.185 +
  16.186 +
  16.187 +/*
  16.188 + * Write a special marker.
  16.189 + * This is only recommended for writing COM or APPn markers.
  16.190 + * Must be called after jpeg_start_compress() and before
  16.191 + * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
  16.192 + */
  16.193 +
  16.194 +GLOBAL(void)
  16.195 +jpeg_write_marker (j_compress_ptr cinfo, int marker,
  16.196 +		   const JOCTET *dataptr, unsigned int datalen)
  16.197 +{
  16.198 +  JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  16.199 +
  16.200 +  if (cinfo->next_scanline != 0 ||
  16.201 +      (cinfo->global_state != CSTATE_SCANNING &&
  16.202 +       cinfo->global_state != CSTATE_RAW_OK &&
  16.203 +       cinfo->global_state != CSTATE_WRCOEFS))
  16.204 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  16.205 +
  16.206 +  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  16.207 +  write_marker_byte = cinfo->marker->write_marker_byte;	/* copy for speed */
  16.208 +  while (datalen--) {
  16.209 +    (*write_marker_byte) (cinfo, *dataptr);
  16.210 +    dataptr++;
  16.211 +  }
  16.212 +}
  16.213 +
  16.214 +/* Same, but piecemeal. */
  16.215 +
  16.216 +GLOBAL(void)
  16.217 +jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  16.218 +{
  16.219 +  if (cinfo->next_scanline != 0 ||
  16.220 +      (cinfo->global_state != CSTATE_SCANNING &&
  16.221 +       cinfo->global_state != CSTATE_RAW_OK &&
  16.222 +       cinfo->global_state != CSTATE_WRCOEFS))
  16.223 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  16.224 +
  16.225 +  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  16.226 +}
  16.227 +
  16.228 +GLOBAL(void)
  16.229 +jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  16.230 +{
  16.231 +  (*cinfo->marker->write_marker_byte) (cinfo, val);
  16.232 +}
  16.233 +
  16.234 +
  16.235 +/*
  16.236 + * Alternate compression function: just write an abbreviated table file.
  16.237 + * Before calling this, all parameters and a data destination must be set up.
  16.238 + *
  16.239 + * To produce a pair of files containing abbreviated tables and abbreviated
  16.240 + * image data, one would proceed as follows:
  16.241 + *
  16.242 + *		initialize JPEG object
  16.243 + *		set JPEG parameters
  16.244 + *		set destination to table file
  16.245 + *		jpeg_write_tables(cinfo);
  16.246 + *		set destination to image file
  16.247 + *		jpeg_start_compress(cinfo, FALSE);
  16.248 + *		write data...
  16.249 + *		jpeg_finish_compress(cinfo);
  16.250 + *
  16.251 + * jpeg_write_tables has the side effect of marking all tables written
  16.252 + * (same as jpeg_suppress_tables(..., TRUE)).  Thus a subsequent start_compress
  16.253 + * will not re-emit the tables unless it is passed write_all_tables=TRUE.
  16.254 + */
  16.255 +
  16.256 +GLOBAL(void)
  16.257 +jpeg_write_tables (j_compress_ptr cinfo)
  16.258 +{
  16.259 +  if (cinfo->global_state != CSTATE_START)
  16.260 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  16.261 +
  16.262 +  /* (Re)initialize error mgr and destination modules */
  16.263 +  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  16.264 +  (*cinfo->dest->init_destination) (cinfo);
  16.265 +  /* Initialize the marker writer ... bit of a crock to do it here. */
  16.266 +  jinit_marker_writer(cinfo);
  16.267 +  /* Write them tables! */
  16.268 +  (*cinfo->marker->write_tables_only) (cinfo);
  16.269 +  /* And clean up. */
  16.270 +  (*cinfo->dest->term_destination) (cinfo);
  16.271 +  /*
  16.272 +   * In library releases up through v6a, we called jpeg_abort() here to free
  16.273 +   * any working memory allocated by the destination manager and marker
  16.274 +   * writer.  Some applications had a problem with that: they allocated space
  16.275 +   * of their own from the library memory manager, and didn't want it to go
  16.276 +   * away during write_tables.  So now we do nothing.  This will cause a
  16.277 +   * memory leak if an app calls write_tables repeatedly without doing a full
  16.278 +   * compression cycle or otherwise resetting the JPEG object.  However, that
  16.279 +   * seems less bad than unexpectedly freeing memory in the normal case.
  16.280 +   * An app that prefers the old behavior can call jpeg_abort for itself after
  16.281 +   * each call to jpeg_write_tables().
  16.282 +   */
  16.283 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/libs/libjpeg/jcapistd.c	Sat Sep 19 05:51:51 2015 +0300
    17.3 @@ -0,0 +1,161 @@
    17.4 +/*
    17.5 + * jcapistd.c
    17.6 + *
    17.7 + * Copyright (C) 1994-1996, Thomas G. Lane.
    17.8 + * This file is part of the Independent JPEG Group's software.
    17.9 + * For conditions of distribution and use, see the accompanying README file.
   17.10 + *
   17.11 + * This file contains application interface code for the compression half
   17.12 + * of the JPEG library.  These are the "standard" API routines that are
   17.13 + * used in the normal full-compression case.  They are not used by a
   17.14 + * transcoding-only application.  Note that if an application links in
   17.15 + * jpeg_start_compress, it will end up linking in the entire compressor.
   17.16 + * We thus must separate this file from jcapimin.c to avoid linking the
   17.17 + * whole compression library into a transcoder.
   17.18 + */
   17.19 +
   17.20 +#define JPEG_INTERNALS
   17.21 +#include "jinclude.h"
   17.22 +#include "jpeglib.h"
   17.23 +
   17.24 +
   17.25 +/*
   17.26 + * Compression initialization.
   17.27 + * Before calling this, all parameters and a data destination must be set up.
   17.28 + *
   17.29 + * We require a write_all_tables parameter as a failsafe check when writing
   17.30 + * multiple datastreams from the same compression object.  Since prior runs
   17.31 + * will have left all the tables marked sent_table=TRUE, a subsequent run
   17.32 + * would emit an abbreviated stream (no tables) by default.  This may be what
   17.33 + * is wanted, but for safety's sake it should not be the default behavior:
   17.34 + * programmers should have to make a deliberate choice to emit abbreviated
   17.35 + * images.  Therefore the documentation and examples should encourage people
   17.36 + * to pass write_all_tables=TRUE; then it will take active thought to do the
   17.37 + * wrong thing.
   17.38 + */
   17.39 +
   17.40 +GLOBAL(void)
   17.41 +jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
   17.42 +{
   17.43 +  if (cinfo->global_state != CSTATE_START)
   17.44 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
   17.45 +
   17.46 +  if (write_all_tables)
   17.47 +    jpeg_suppress_tables(cinfo, FALSE);	/* mark all tables to be written */
   17.48 +
   17.49 +  /* (Re)initialize error mgr and destination modules */
   17.50 +  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
   17.51 +  (*cinfo->dest->init_destination) (cinfo);
   17.52 +  /* Perform master selection of active modules */
   17.53 +  jinit_compress_master(cinfo);
   17.54 +  /* Set up for the first pass */
   17.55 +  (*cinfo->master->prepare_for_pass) (cinfo);
   17.56 +  /* Ready for application to drive first pass through jpeg_write_scanlines
   17.57 +   * or jpeg_write_raw_data.
   17.58 +   */
   17.59 +  cinfo->next_scanline = 0;
   17.60 +  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
   17.61 +}
   17.62 +
   17.63 +
   17.64 +/*
   17.65 + * Write some scanlines of data to the JPEG compressor.
   17.66 + *
   17.67 + * The return value will be the number of lines actually written.
   17.68 + * This should be less than the supplied num_lines only in case that
   17.69 + * the data destination module has requested suspension of the compressor,
   17.70 + * or if more than image_height scanlines are passed in.
   17.71 + *
   17.72 + * Note: we warn about excess calls to jpeg_write_scanlines() since
   17.73 + * this likely signals an application programmer error.  However,
   17.74 + * excess scanlines passed in the last valid call are *silently* ignored,
   17.75 + * so that the application need not adjust num_lines for end-of-image
   17.76 + * when using a multiple-scanline buffer.
   17.77 + */
   17.78 +
   17.79 +GLOBAL(JDIMENSION)
   17.80 +jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
   17.81 +		      JDIMENSION num_lines)
   17.82 +{
   17.83 +  JDIMENSION row_ctr, rows_left;
   17.84 +
   17.85 +  if (cinfo->global_state != CSTATE_SCANNING)
   17.86 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
   17.87 +  if (cinfo->next_scanline >= cinfo->image_height)
   17.88 +    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
   17.89 +
   17.90 +  /* Call progress monitor hook if present */
   17.91 +  if (cinfo->progress != NULL) {
   17.92 +    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
   17.93 +    cinfo->progress->pass_limit = (long) cinfo->image_height;
   17.94 +    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
   17.95 +  }
   17.96 +
   17.97 +  /* Give master control module another chance if this is first call to
   17.98 +   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
   17.99 +   * delayed so that application can write COM, etc, markers between
  17.100 +   * jpeg_start_compress and jpeg_write_scanlines.
  17.101 +   */
  17.102 +  if (cinfo->master->call_pass_startup)
  17.103 +    (*cinfo->master->pass_startup) (cinfo);
  17.104 +
  17.105 +  /* Ignore any extra scanlines at bottom of image. */
  17.106 +  rows_left = cinfo->image_height - cinfo->next_scanline;
  17.107 +  if (num_lines > rows_left)
  17.108 +    num_lines = rows_left;
  17.109 +
  17.110 +  row_ctr = 0;
  17.111 +  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  17.112 +  cinfo->next_scanline += row_ctr;
  17.113 +  return row_ctr;
  17.114 +}
  17.115 +
  17.116 +
  17.117 +/*
  17.118 + * Alternate entry point to write raw data.
  17.119 + * Processes exactly one iMCU row per call, unless suspended.
  17.120 + */
  17.121 +
  17.122 +GLOBAL(JDIMENSION)
  17.123 +jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  17.124 +		     JDIMENSION num_lines)
  17.125 +{
  17.126 +  JDIMENSION lines_per_iMCU_row;
  17.127 +
  17.128 +  if (cinfo->global_state != CSTATE_RAW_OK)
  17.129 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  17.130 +  if (cinfo->next_scanline >= cinfo->image_height) {
  17.131 +    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  17.132 +    return 0;
  17.133 +  }
  17.134 +
  17.135 +  /* Call progress monitor hook if present */
  17.136 +  if (cinfo->progress != NULL) {
  17.137 +    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  17.138 +    cinfo->progress->pass_limit = (long) cinfo->image_height;
  17.139 +    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  17.140 +  }
  17.141 +
  17.142 +  /* Give master control module another chance if this is first call to
  17.143 +   * jpeg_write_raw_data.  This lets output of the frame/scan headers be
  17.144 +   * delayed so that application can write COM, etc, markers between
  17.145 +   * jpeg_start_compress and jpeg_write_raw_data.
  17.146 +   */
  17.147 +  if (cinfo->master->call_pass_startup)
  17.148 +    (*cinfo->master->pass_startup) (cinfo);
  17.149 +
  17.150 +  /* Verify that at least one iMCU row has been passed. */
  17.151 +  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  17.152 +  if (num_lines < lines_per_iMCU_row)
  17.153 +    ERREXIT(cinfo, JERR_BUFFER_SIZE);
  17.154 +
  17.155 +  /* Directly compress the row. */
  17.156 +  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  17.157 +    /* If compressor did not consume the whole row, suspend processing. */
  17.158 +    return 0;
  17.159 +  }
  17.160 +
  17.161 +  /* OK, we processed one iMCU row. */
  17.162 +  cinfo->next_scanline += lines_per_iMCU_row;
  17.163 +  return lines_per_iMCU_row;
  17.164 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/libs/libjpeg/jccoefct.c	Sat Sep 19 05:51:51 2015 +0300
    18.3 @@ -0,0 +1,449 @@
    18.4 +/*
    18.5 + * jccoefct.c
    18.6 + *
    18.7 + * Copyright (C) 1994-1997, Thomas G. Lane.
    18.8 + * This file is part of the Independent JPEG Group's software.
    18.9 + * For conditions of distribution and use, see the accompanying README file.
   18.10 + *
   18.11 + * This file contains the coefficient buffer controller for compression.
   18.12 + * This controller is the top level of the JPEG compressor proper.
   18.13 + * The coefficient buffer lies between forward-DCT and entropy encoding steps.
   18.14 + */
   18.15 +
   18.16 +#define JPEG_INTERNALS
   18.17 +#include "jinclude.h"
   18.18 +#include "jpeglib.h"
   18.19 +
   18.20 +
   18.21 +/* We use a full-image coefficient buffer when doing Huffman optimization,
   18.22 + * and also for writing multiple-scan JPEG files.  In all cases, the DCT
   18.23 + * step is run during the first pass, and subsequent passes need only read
   18.24 + * the buffered coefficients.
   18.25 + */
   18.26 +#ifdef ENTROPY_OPT_SUPPORTED
   18.27 +#define FULL_COEF_BUFFER_SUPPORTED
   18.28 +#else
   18.29 +#ifdef C_MULTISCAN_FILES_SUPPORTED
   18.30 +#define FULL_COEF_BUFFER_SUPPORTED
   18.31 +#endif
   18.32 +#endif
   18.33 +
   18.34 +
   18.35 +/* Private buffer controller object */
   18.36 +
   18.37 +typedef struct {
   18.38 +  struct jpeg_c_coef_controller pub; /* public fields */
   18.39 +
   18.40 +  JDIMENSION iMCU_row_num;	/* iMCU row # within image */
   18.41 +  JDIMENSION mcu_ctr;		/* counts MCUs processed in current row */
   18.42 +  int MCU_vert_offset;		/* counts MCU rows within iMCU row */
   18.43 +  int MCU_rows_per_iMCU_row;	/* number of such rows needed */
   18.44 +
   18.45 +  /* For single-pass compression, it's sufficient to buffer just one MCU
   18.46 +   * (although this may prove a bit slow in practice).  We allocate a
   18.47 +   * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
   18.48 +   * MCU constructed and sent.  (On 80x86, the workspace is FAR even though
   18.49 +   * it's not really very big; this is to keep the module interfaces unchanged
   18.50 +   * when a large coefficient buffer is necessary.)
   18.51 +   * In multi-pass modes, this array points to the current MCU's blocks
   18.52 +   * within the virtual arrays.
   18.53 +   */
   18.54 +  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
   18.55 +
   18.56 +  /* In multi-pass modes, we need a virtual block array for each component. */
   18.57 +  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
   18.58 +} my_coef_controller;
   18.59 +
   18.60 +typedef my_coef_controller * my_coef_ptr;
   18.61 +
   18.62 +
   18.63 +/* Forward declarations */
   18.64 +METHODDEF(boolean) compress_data
   18.65 +    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
   18.66 +#ifdef FULL_COEF_BUFFER_SUPPORTED
   18.67 +METHODDEF(boolean) compress_first_pass
   18.68 +    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
   18.69 +METHODDEF(boolean) compress_output
   18.70 +    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
   18.71 +#endif
   18.72 +
   18.73 +
   18.74 +LOCAL(void)
   18.75 +start_iMCU_row (j_compress_ptr cinfo)
   18.76 +/* Reset within-iMCU-row counters for a new row */
   18.77 +{
   18.78 +  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
   18.79 +
   18.80 +  /* In an interleaved scan, an MCU row is the same as an iMCU row.
   18.81 +   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
   18.82 +   * But at the bottom of the image, process only what's left.
   18.83 +   */
   18.84 +  if (cinfo->comps_in_scan > 1) {
   18.85 +    coef->MCU_rows_per_iMCU_row = 1;
   18.86 +  } else {
   18.87 +    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
   18.88 +      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
   18.89 +    else
   18.90 +      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
   18.91 +  }
   18.92 +
   18.93 +  coef->mcu_ctr = 0;
   18.94 +  coef->MCU_vert_offset = 0;
   18.95 +}
   18.96 +
   18.97 +
   18.98 +/*
   18.99 + * Initialize for a processing pass.
  18.100 + */
  18.101 +
  18.102 +METHODDEF(void)
  18.103 +start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  18.104 +{
  18.105 +  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  18.106 +
  18.107 +  coef->iMCU_row_num = 0;
  18.108 +  start_iMCU_row(cinfo);
  18.109 +
  18.110 +  switch (pass_mode) {
  18.111 +  case JBUF_PASS_THRU:
  18.112 +    if (coef->whole_image[0] != NULL)
  18.113 +      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  18.114 +    coef->pub.compress_data = compress_data;
  18.115 +    break;
  18.116 +#ifdef FULL_COEF_BUFFER_SUPPORTED
  18.117 +  case JBUF_SAVE_AND_PASS:
  18.118 +    if (coef->whole_image[0] == NULL)
  18.119 +      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  18.120 +    coef->pub.compress_data = compress_first_pass;
  18.121 +    break;
  18.122 +  case JBUF_CRANK_DEST:
  18.123 +    if (coef->whole_image[0] == NULL)
  18.124 +      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  18.125 +    coef->pub.compress_data = compress_output;
  18.126 +    break;
  18.127 +#endif
  18.128 +  default:
  18.129 +    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  18.130 +    break;
  18.131 +  }
  18.132 +}
  18.133 +
  18.134 +
  18.135 +/*
  18.136 + * Process some data in the single-pass case.
  18.137 + * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
  18.138 + * per call, ie, v_samp_factor block rows for each component in the image.
  18.139 + * Returns TRUE if the iMCU row is completed, FALSE if suspended.
  18.140 + *
  18.141 + * NB: input_buf contains a plane for each component in image,
  18.142 + * which we index according to the component's SOF position.
  18.143 + */
  18.144 +
  18.145 +METHODDEF(boolean)
  18.146 +compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  18.147 +{
  18.148 +  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  18.149 +  JDIMENSION MCU_col_num;	/* index of current MCU within row */
  18.150 +  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  18.151 +  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  18.152 +  int blkn, bi, ci, yindex, yoffset, blockcnt;
  18.153 +  JDIMENSION ypos, xpos;
  18.154 +  jpeg_component_info *compptr;
  18.155 +
  18.156 +  /* Loop to write as much as one whole iMCU row */
  18.157 +  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  18.158 +       yoffset++) {
  18.159 +    for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  18.160 +	 MCU_col_num++) {
  18.161 +      /* Determine where data comes from in input_buf and do the DCT thing.
  18.162 +       * Each call on forward_DCT processes a horizontal row of DCT blocks
  18.163 +       * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
  18.164 +       * sequentially.  Dummy blocks at the right or bottom edge are filled in
  18.165 +       * specially.  The data in them does not matter for image reconstruction,
  18.166 +       * so we fill them with values that will encode to the smallest amount of
  18.167 +       * data, viz: all zeroes in the AC entries, DC entries equal to previous
  18.168 +       * block's DC value.  (Thanks to Thomas Kinsman for this idea.)
  18.169 +       */
  18.170 +      blkn = 0;
  18.171 +      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  18.172 +	compptr = cinfo->cur_comp_info[ci];
  18.173 +	blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  18.174 +						: compptr->last_col_width;
  18.175 +	xpos = MCU_col_num * compptr->MCU_sample_width;
  18.176 +	ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  18.177 +	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  18.178 +	  if (coef->iMCU_row_num < last_iMCU_row ||
  18.179 +	      yoffset+yindex < compptr->last_row_height) {
  18.180 +	    (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  18.181 +					 input_buf[compptr->component_index],
  18.182 +					 coef->MCU_buffer[blkn],
  18.183 +					 ypos, xpos, (JDIMENSION) blockcnt);
  18.184 +	    if (blockcnt < compptr->MCU_width) {
  18.185 +	      /* Create some dummy blocks at the right edge of the image. */
  18.186 +	      jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  18.187 +			(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  18.188 +	      for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  18.189 +		coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  18.190 +	      }
  18.191 +	    }
  18.192 +	  } else {
  18.193 +	    /* Create a row of dummy blocks at the bottom of the image. */
  18.194 +	    jzero_far((void FAR *) coef->MCU_buffer[blkn],
  18.195 +		      compptr->MCU_width * SIZEOF(JBLOCK));
  18.196 +	    for (bi = 0; bi < compptr->MCU_width; bi++) {
  18.197 +	      coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  18.198 +	    }
  18.199 +	  }
  18.200 +	  blkn += compptr->MCU_width;
  18.201 +	  ypos += DCTSIZE;
  18.202 +	}
  18.203 +      }
  18.204 +      /* Try to write the MCU.  In event of a suspension failure, we will
  18.205 +       * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
  18.206 +       */
  18.207 +      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  18.208 +	/* Suspension forced; update state counters and exit */
  18.209 +	coef->MCU_vert_offset = yoffset;
  18.210 +	coef->mcu_ctr = MCU_col_num;
  18.211 +	return FALSE;
  18.212 +      }
  18.213 +    }
  18.214 +    /* Completed an MCU row, but perhaps not an iMCU row */
  18.215 +    coef->mcu_ctr = 0;
  18.216 +  }
  18.217 +  /* Completed the iMCU row, advance counters for next one */
  18.218 +  coef->iMCU_row_num++;
  18.219 +  start_iMCU_row(cinfo);
  18.220 +  return TRUE;
  18.221 +}
  18.222 +
  18.223 +
  18.224 +#ifdef FULL_COEF_BUFFER_SUPPORTED
  18.225 +
  18.226 +/*
  18.227 + * Process some data in the first pass of a multi-pass case.
  18.228 + * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
  18.229 + * per call, ie, v_samp_factor block rows for each component in the image.
  18.230 + * This amount of data is read from the source buffer, DCT'd and quantized,
  18.231 + * and saved into the virtual arrays.  We also generate suitable dummy blocks
  18.232 + * as needed at the right and lower edges.  (The dummy blocks are constructed
  18.233 + * in the virtual arrays, which have been padded appropriately.)  This makes
  18.234 + * it possible for subsequent passes not to worry about real vs. dummy blocks.
  18.235 + *
  18.236 + * We must also emit the data to the entropy encoder.  This is conveniently
  18.237 + * done by calling compress_output() after we've loaded the current strip
  18.238 + * of the virtual arrays.
  18.239 + *
  18.240 + * NB: input_buf contains a plane for each component in image.  All
  18.241 + * components are DCT'd and loaded into the virtual arrays in this pass.
  18.242 + * However, it may be that only a subset of the components are emitted to
  18.243 + * the entropy encoder during this first pass; be careful about looking
  18.244 + * at the scan-dependent variables (MCU dimensions, etc).
  18.245 + */
  18.246 +
  18.247 +METHODDEF(boolean)
  18.248 +compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  18.249 +{
  18.250 +  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  18.251 +  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  18.252 +  JDIMENSION blocks_across, MCUs_across, MCUindex;
  18.253 +  int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  18.254 +  JCOEF lastDC;
  18.255 +  jpeg_component_info *compptr;
  18.256 +  JBLOCKARRAY buffer;
  18.257 +  JBLOCKROW thisblockrow, lastblockrow;
  18.258 +
  18.259 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  18.260 +       ci++, compptr++) {
  18.261 +    /* Align the virtual buffer for this component. */
  18.262 +    buffer = (*cinfo->mem->access_virt_barray)
  18.263 +      ((j_common_ptr) cinfo, coef->whole_image[ci],
  18.264 +       coef->iMCU_row_num * compptr->v_samp_factor,
  18.265 +       (JDIMENSION) compptr->v_samp_factor, TRUE);
  18.266 +    /* Count non-dummy DCT block rows in this iMCU row. */
  18.267 +    if (coef->iMCU_row_num < last_iMCU_row)
  18.268 +      block_rows = compptr->v_samp_factor;
  18.269 +    else {
  18.270 +      /* NB: can't use last_row_height here, since may not be set! */
  18.271 +      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  18.272 +      if (block_rows == 0) block_rows = compptr->v_samp_factor;
  18.273 +    }
  18.274 +    blocks_across = compptr->width_in_blocks;
  18.275 +    h_samp_factor = compptr->h_samp_factor;
  18.276 +    /* Count number of dummy blocks to be added at the right margin. */
  18.277 +    ndummy = (int) (blocks_across % h_samp_factor);
  18.278 +    if (ndummy > 0)
  18.279 +      ndummy = h_samp_factor - ndummy;
  18.280 +    /* Perform DCT for all non-dummy blocks in this iMCU row.  Each call
  18.281 +     * on forward_DCT processes a complete horizontal row of DCT blocks.
  18.282 +     */
  18.283 +    for (block_row = 0; block_row < block_rows; block_row++) {
  18.284 +      thisblockrow = buffer[block_row];
  18.285 +      (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  18.286 +				   input_buf[ci], thisblockrow,
  18.287 +				   (JDIMENSION) (block_row * DCTSIZE),
  18.288 +				   (JDIMENSION) 0, blocks_across);
  18.289 +      if (ndummy > 0) {
  18.290 +	/* Create dummy blocks at the right edge of the image. */
  18.291 +	thisblockrow += blocks_across; /* => first dummy block */
  18.292 +	jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  18.293 +	lastDC = thisblockrow[-1][0];
  18.294 +	for (bi = 0; bi < ndummy; bi++) {
  18.295 +	  thisblockrow[bi][0] = lastDC;
  18.296 +	}
  18.297 +      }
  18.298 +    }
  18.299 +    /* If at end of image, create dummy block rows as needed.
  18.300 +     * The tricky part here is that within each MCU, we want the DC values
  18.301 +     * of the dummy blocks to match the last real block's DC value.
  18.302 +     * This squeezes a few more bytes out of the resulting file...
  18.303 +     */
  18.304 +    if (coef->iMCU_row_num == last_iMCU_row) {
  18.305 +      blocks_across += ndummy;	/* include lower right corner */
  18.306 +      MCUs_across = blocks_across / h_samp_factor;
  18.307 +      for (block_row = block_rows; block_row < compptr->v_samp_factor;
  18.308 +	   block_row++) {
  18.309 +	thisblockrow = buffer[block_row];
  18.310 +	lastblockrow = buffer[block_row-1];
  18.311 +	jzero_far((void FAR *) thisblockrow,
  18.312 +		  (size_t) (blocks_across * SIZEOF(JBLOCK)));
  18.313 +	for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  18.314 +	  lastDC = lastblockrow[h_samp_factor-1][0];
  18.315 +	  for (bi = 0; bi < h_samp_factor; bi++) {
  18.316 +	    thisblockrow[bi][0] = lastDC;
  18.317 +	  }
  18.318 +	  thisblockrow += h_samp_factor; /* advance to next MCU in row */
  18.319 +	  lastblockrow += h_samp_factor;
  18.320 +	}
  18.321 +      }
  18.322 +    }
  18.323 +  }
  18.324 +  /* NB: compress_output will increment iMCU_row_num if successful.
  18.325 +   * A suspension return will result in redoing all the work above next time.
  18.326 +   */
  18.327 +
  18.328 +  /* Emit data to the entropy encoder, sharing code with subsequent passes */
  18.329 +  return compress_output(cinfo, input_buf);
  18.330 +}
  18.331 +
  18.332 +
  18.333 +/*
  18.334 + * Process some data in subsequent passes of a multi-pass case.
  18.335 + * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
  18.336 + * per call, ie, v_samp_factor block rows for each component in the scan.
  18.337 + * The data is obtained from the virtual arrays and fed to the entropy coder.
  18.338 + * Returns TRUE if the iMCU row is completed, FALSE if suspended.
  18.339 + *
  18.340 + * NB: input_buf is ignored; it is likely to be a NULL pointer.
  18.341 + */
  18.342 +
  18.343 +METHODDEF(boolean)
  18.344 +compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  18.345 +{
  18.346 +  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  18.347 +  JDIMENSION MCU_col_num;	/* index of current MCU within row */
  18.348 +  int blkn, ci, xindex, yindex, yoffset;
  18.349 +  JDIMENSION start_col;
  18.350 +  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  18.351 +  JBLOCKROW buffer_ptr;
  18.352 +  jpeg_component_info *compptr;
  18.353 +
  18.354 +  /* Align the virtual buffers for the components used in this scan.
  18.355 +   * NB: during first pass, this is safe only because the buffers will
  18.356 +   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
  18.357 +   */
  18.358 +  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  18.359 +    compptr = cinfo->cur_comp_info[ci];
  18.360 +    buffer[ci] = (*cinfo->mem->access_virt_barray)
  18.361 +      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  18.362 +       coef->iMCU_row_num * compptr->v_samp_factor,
  18.363 +       (JDIMENSION) compptr->v_samp_factor, FALSE);
  18.364 +  }
  18.365 +
  18.366 +  /* Loop to process one whole iMCU row */
  18.367 +  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  18.368 +       yoffset++) {
  18.369 +    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  18.370 +	 MCU_col_num++) {
  18.371 +      /* Construct list of pointers to DCT blocks belonging to this MCU */
  18.372 +      blkn = 0;			/* index of current DCT block within MCU */
  18.373 +      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  18.374 +	compptr = cinfo->cur_comp_info[ci];
  18.375 +	start_col = MCU_col_num * compptr->MCU_width;
  18.376 +	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  18.377 +	  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  18.378 +	  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  18.379 +	    coef->MCU_buffer[blkn++] = buffer_ptr++;
  18.380 +	  }
  18.381 +	}
  18.382 +      }
  18.383 +      /* Try to write the MCU. */
  18.384 +      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  18.385 +	/* Suspension forced; update state counters and exit */
  18.386 +	coef->MCU_vert_offset = yoffset;
  18.387 +	coef->mcu_ctr = MCU_col_num;
  18.388 +	return FALSE;
  18.389 +      }
  18.390 +    }
  18.391 +    /* Completed an MCU row, but perhaps not an iMCU row */
  18.392 +    coef->mcu_ctr = 0;
  18.393 +  }
  18.394 +  /* Completed the iMCU row, advance counters for next one */
  18.395 +  coef->iMCU_row_num++;
  18.396 +  start_iMCU_row(cinfo);
  18.397 +  return TRUE;
  18.398 +}
  18.399 +
  18.400 +#endif /* FULL_COEF_BUFFER_SUPPORTED */
  18.401 +
  18.402 +
  18.403 +/*
  18.404 + * Initialize coefficient buffer controller.
  18.405 + */
  18.406 +
  18.407 +GLOBAL(void)
  18.408 +jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  18.409 +{
  18.410 +  my_coef_ptr coef;
  18.411 +
  18.412 +  coef = (my_coef_ptr)
  18.413 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  18.414 +				SIZEOF(my_coef_controller));
  18.415 +  cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  18.416 +  coef->pub.start_pass = start_pass_coef;
  18.417 +
  18.418 +  /* Create the coefficient buffer. */
  18.419 +  if (need_full_buffer) {
  18.420 +#ifdef FULL_COEF_BUFFER_SUPPORTED
  18.421 +    /* Allocate a full-image virtual array for each component, */
  18.422 +    /* padded to a multiple of samp_factor DCT blocks in each direction. */
  18.423 +    int ci;
  18.424 +    jpeg_component_info *compptr;
  18.425 +
  18.426 +    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  18.427 +	 ci++, compptr++) {
  18.428 +      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  18.429 +	((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  18.430 +	 (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  18.431 +				(long) compptr->h_samp_factor),
  18.432 +	 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  18.433 +				(long) compptr->v_samp_factor),
  18.434 +	 (JDIMENSION) compptr->v_samp_factor);
  18.435 +    }
  18.436 +#else
  18.437 +    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  18.438 +#endif
  18.439 +  } else {
  18.440 +    /* We only need a single-MCU buffer. */
  18.441 +    JBLOCKROW buffer;
  18.442 +    int i;
  18.443 +
  18.444 +    buffer = (JBLOCKROW)
  18.445 +      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  18.446 +				  C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  18.447 +    for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  18.448 +      coef->MCU_buffer[i] = buffer + i;
  18.449 +    }
  18.450 +    coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  18.451 +  }
  18.452 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/libs/libjpeg/jccolor.c	Sat Sep 19 05:51:51 2015 +0300
    19.3 @@ -0,0 +1,459 @@
    19.4 +/*
    19.5 + * jccolor.c
    19.6 + *
    19.7 + * Copyright (C) 1991-1996, Thomas G. Lane.
    19.8 + * This file is part of the Independent JPEG Group's software.
    19.9 + * For conditions of distribution and use, see the accompanying README file.
   19.10 + *
   19.11 + * This file contains input colorspace conversion routines.
   19.12 + */
   19.13 +
   19.14 +#define JPEG_INTERNALS
   19.15 +#include "jinclude.h"
   19.16 +#include "jpeglib.h"
   19.17 +
   19.18 +
   19.19 +/* Private subobject */
   19.20 +
   19.21 +typedef struct {
   19.22 +  struct jpeg_color_converter pub; /* public fields */
   19.23 +
   19.24 +  /* Private state for RGB->YCC conversion */
   19.25 +  INT32 * rgb_ycc_tab;		/* => table for RGB to YCbCr conversion */
   19.26 +} my_color_converter;
   19.27 +
   19.28 +typedef my_color_converter * my_cconvert_ptr;
   19.29 +
   19.30 +
   19.31 +/**************** RGB -> YCbCr conversion: most common case **************/
   19.32 +
   19.33 +/*
   19.34 + * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
   19.35 + * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
   19.36 + * The conversion equations to be implemented are therefore
   19.37 + *	Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
   19.38 + *	Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B  + CENTERJSAMPLE
   19.39 + *	Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B  + CENTERJSAMPLE
   19.40 + * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
   19.41 + * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
   19.42 + * rather than CENTERJSAMPLE, for Cb and Cr.  This gave equal positive and
   19.43 + * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
   19.44 + * were not represented exactly.  Now we sacrifice exact representation of
   19.45 + * maximum red and maximum blue in order to get exact grayscales.
   19.46 + *
   19.47 + * To avoid floating-point arithmetic, we represent the fractional constants
   19.48 + * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
   19.49 + * the products by 2^16, with appropriate rounding, to get the correct answer.
   19.50 + *
   19.51 + * For even more speed, we avoid doing any multiplications in the inner loop
   19.52 + * by precalculating the constants times R,G,B for all possible values.
   19.53 + * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
   19.54 + * for 12-bit samples it is still acceptable.  It's not very reasonable for
   19.55 + * 16-bit samples, but if you want lossless storage you shouldn't be changing
   19.56 + * colorspace anyway.
   19.57 + * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
   19.58 + * in the tables to save adding them separately in the inner loop.
   19.59 + */
   19.60 +
   19.61 +#define SCALEBITS	16	/* speediest right-shift on some machines */
   19.62 +#define CBCR_OFFSET	((INT32) CENTERJSAMPLE << SCALEBITS)
   19.63 +#define ONE_HALF	((INT32) 1 << (SCALEBITS-1))
   19.64 +#define FIX(x)		((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
   19.65 +
   19.66 +/* We allocate one big table and divide it up into eight parts, instead of
   19.67 + * doing eight alloc_small requests.  This lets us use a single table base
   19.68 + * address, which can be held in a register in the inner loops on many
   19.69 + * machines (more than can hold all eight addresses, anyway).
   19.70 + */
   19.71 +
   19.72 +#define R_Y_OFF		0			/* offset to R => Y section */
   19.73 +#define G_Y_OFF		(1*(MAXJSAMPLE+1))	/* offset to G => Y section */
   19.74 +#define B_Y_OFF		(2*(MAXJSAMPLE+1))	/* etc. */
   19.75 +#define R_CB_OFF	(3*(MAXJSAMPLE+1))
   19.76 +#define G_CB_OFF	(4*(MAXJSAMPLE+1))
   19.77 +#define B_CB_OFF	(5*(MAXJSAMPLE+1))
   19.78 +#define R_CR_OFF	B_CB_OFF		/* B=>Cb, R=>Cr are the same */
   19.79 +#define G_CR_OFF	(6*(MAXJSAMPLE+1))
   19.80 +#define B_CR_OFF	(7*(MAXJSAMPLE+1))
   19.81 +#define TABLE_SIZE	(8*(MAXJSAMPLE+1))
   19.82 +
   19.83 +
   19.84 +/*
   19.85 + * Initialize for RGB->YCC colorspace conversion.
   19.86 + */
   19.87 +
   19.88 +METHODDEF(void)
   19.89 +rgb_ycc_start (j_compress_ptr cinfo)
   19.90 +{
   19.91 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
   19.92 +  INT32 * rgb_ycc_tab;
   19.93 +  INT32 i;
   19.94 +
   19.95 +  /* Allocate and fill in the conversion tables. */
   19.96 +  cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
   19.97 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
   19.98 +				(TABLE_SIZE * SIZEOF(INT32)));
   19.99 +
  19.100 +  for (i = 0; i <= MAXJSAMPLE; i++) {
  19.101 +    rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  19.102 +    rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  19.103 +    rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i     + ONE_HALF;
  19.104 +    rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  19.105 +    rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  19.106 +    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
  19.107 +     * This ensures that the maximum output will round to MAXJSAMPLE
  19.108 +     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
  19.109 +     */
  19.110 +    rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
  19.111 +/*  B=>Cb and R=>Cr tables are the same
  19.112 +    rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
  19.113 +*/
  19.114 +    rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  19.115 +    rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  19.116 +  }
  19.117 +}
  19.118 +
  19.119 +
  19.120 +/*
  19.121 + * Convert some rows of samples to the JPEG colorspace.
  19.122 + *
  19.123 + * Note that we change from the application's interleaved-pixel format
  19.124 + * to our internal noninterleaved, one-plane-per-component format.
  19.125 + * The input buffer is therefore three times as wide as the output buffer.
  19.126 + *
  19.127 + * A starting row offset is provided only for the output buffer.  The caller
  19.128 + * can easily adjust the passed input_buf value to accommodate any row
  19.129 + * offset required on that side.
  19.130 + */
  19.131 +
  19.132 +METHODDEF(void)
  19.133 +rgb_ycc_convert (j_compress_ptr cinfo,
  19.134 +		 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  19.135 +		 JDIMENSION output_row, int num_rows)
  19.136 +{
  19.137 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  19.138 +  register int r, g, b;
  19.139 +  register INT32 * ctab = cconvert->rgb_ycc_tab;
  19.140 +  register JSAMPROW inptr;
  19.141 +  register JSAMPROW outptr0, outptr1, outptr2;
  19.142 +  register JDIMENSION col;
  19.143 +  JDIMENSION num_cols = cinfo->image_width;
  19.144 +
  19.145 +  while (--num_rows >= 0) {
  19.146 +    inptr = *input_buf++;
  19.147 +    outptr0 = output_buf[0][output_row];
  19.148 +    outptr1 = output_buf[1][output_row];
  19.149 +    outptr2 = output_buf[2][output_row];
  19.150 +    output_row++;
  19.151 +    for (col = 0; col < num_cols; col++) {
  19.152 +      r = GETJSAMPLE(inptr[RGB_RED]);
  19.153 +      g = GETJSAMPLE(inptr[RGB_GREEN]);
  19.154 +      b = GETJSAMPLE(inptr[RGB_BLUE]);
  19.155 +      inptr += RGB_PIXELSIZE;
  19.156 +      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
  19.157 +       * must be too; we do not need an explicit range-limiting operation.
  19.158 +       * Hence the value being shifted is never negative, and we don't
  19.159 +       * need the general RIGHT_SHIFT macro.
  19.160 +       */
  19.161 +      /* Y */
  19.162 +      outptr0[col] = (JSAMPLE)
  19.163 +		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  19.164 +		 >> SCALEBITS);
  19.165 +      /* Cb */
  19.166 +      outptr1[col] = (JSAMPLE)
  19.167 +		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  19.168 +		 >> SCALEBITS);
  19.169 +      /* Cr */
  19.170 +      outptr2[col] = (JSAMPLE)
  19.171 +		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  19.172 +		 >> SCALEBITS);
  19.173 +    }
  19.174 +  }
  19.175 +}
  19.176 +
  19.177 +
  19.178 +/**************** Cases other than RGB -> YCbCr **************/
  19.179 +
  19.180 +
  19.181 +/*
  19.182 + * Convert some rows of samples to the JPEG colorspace.
  19.183 + * This version handles RGB->grayscale conversion, which is the same
  19.184 + * as the RGB->Y portion of RGB->YCbCr.
  19.185 + * We assume rgb_ycc_start has been called (we only use the Y tables).
  19.186 + */
  19.187 +
  19.188 +METHODDEF(void)
  19.189 +rgb_gray_convert (j_compress_ptr cinfo,
  19.190 +		  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  19.191 +		  JDIMENSION output_row, int num_rows)
  19.192 +{
  19.193 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  19.194 +  register int r, g, b;
  19.195 +  register INT32 * ctab = cconvert->rgb_ycc_tab;
  19.196 +  register JSAMPROW inptr;
  19.197 +  register JSAMPROW outptr;
  19.198 +  register JDIMENSION col;
  19.199 +  JDIMENSION num_cols = cinfo->image_width;
  19.200 +
  19.201 +  while (--num_rows >= 0) {
  19.202 +    inptr = *input_buf++;
  19.203 +    outptr = output_buf[0][output_row];
  19.204 +    output_row++;
  19.205 +    for (col = 0; col < num_cols; col++) {
  19.206 +      r = GETJSAMPLE(inptr[RGB_RED]);
  19.207 +      g = GETJSAMPLE(inptr[RGB_GREEN]);
  19.208 +      b = GETJSAMPLE(inptr[RGB_BLUE]);
  19.209 +      inptr += RGB_PIXELSIZE;
  19.210 +      /* Y */
  19.211 +      outptr[col] = (JSAMPLE)
  19.212 +		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  19.213 +		 >> SCALEBITS);
  19.214 +    }
  19.215 +  }
  19.216 +}
  19.217 +
  19.218 +
  19.219 +/*
  19.220 + * Convert some rows of samples to the JPEG colorspace.
  19.221 + * This version handles Adobe-style CMYK->YCCK conversion,
  19.222 + * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
  19.223 + * conversion as above, while passing K (black) unchanged.
  19.224 + * We assume rgb_ycc_start has been called.
  19.225 + */
  19.226 +
  19.227 +METHODDEF(void)
  19.228 +cmyk_ycck_convert (j_compress_ptr cinfo,
  19.229 +		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  19.230 +		   JDIMENSION output_row, int num_rows)
  19.231 +{
  19.232 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  19.233 +  register int r, g, b;
  19.234 +  register INT32 * ctab = cconvert->rgb_ycc_tab;
  19.235 +  register JSAMPROW inptr;
  19.236 +  register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  19.237 +  register JDIMENSION col;
  19.238 +  JDIMENSION num_cols = cinfo->image_width;
  19.239 +
  19.240 +  while (--num_rows >= 0) {
  19.241 +    inptr = *input_buf++;
  19.242 +    outptr0 = output_buf[0][output_row];
  19.243 +    outptr1 = output_buf[1][output_row];
  19.244 +    outptr2 = output_buf[2][output_row];
  19.245 +    outptr3 = output_buf[3][output_row];
  19.246 +    output_row++;
  19.247 +    for (col = 0; col < num_cols; col++) {
  19.248 +      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  19.249 +      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  19.250 +      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  19.251 +      /* K passes through as-is */
  19.252 +      outptr3[col] = inptr[3];	/* don't need GETJSAMPLE here */
  19.253 +      inptr += 4;
  19.254 +      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
  19.255 +       * must be too; we do not need an explicit range-limiting operation.
  19.256 +       * Hence the value being shifted is never negative, and we don't
  19.257 +       * need the general RIGHT_SHIFT macro.
  19.258 +       */
  19.259 +      /* Y */
  19.260 +      outptr0[col] = (JSAMPLE)
  19.261 +		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  19.262 +		 >> SCALEBITS);
  19.263 +      /* Cb */
  19.264 +      outptr1[col] = (JSAMPLE)
  19.265 +		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  19.266 +		 >> SCALEBITS);
  19.267 +      /* Cr */
  19.268 +      outptr2[col] = (JSAMPLE)
  19.269 +		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  19.270 +		 >> SCALEBITS);
  19.271 +    }
  19.272 +  }
  19.273 +}
  19.274 +
  19.275 +
  19.276 +/*
  19.277 + * Convert some rows of samples to the JPEG colorspace.
  19.278 + * This version handles grayscale output with no conversion.
  19.279 + * The source can be either plain grayscale or YCbCr (since Y == gray).
  19.280 + */
  19.281 +
  19.282 +METHODDEF(void)
  19.283 +grayscale_convert (j_compress_ptr cinfo,
  19.284 +		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  19.285 +		   JDIMENSION output_row, int num_rows)
  19.286 +{
  19.287 +  register JSAMPROW inptr;
  19.288 +  register JSAMPROW outptr;
  19.289 +  register JDIMENSION col;
  19.290 +  JDIMENSION num_cols = cinfo->image_width;
  19.291 +  int instride = cinfo->input_components;
  19.292 +
  19.293 +  while (--num_rows >= 0) {
  19.294 +    inptr = *input_buf++;
  19.295 +    outptr = output_buf[0][output_row];
  19.296 +    output_row++;
  19.297 +    for (col = 0; col < num_cols; col++) {
  19.298 +      outptr[col] = inptr[0];	/* don't need GETJSAMPLE() here */
  19.299 +      inptr += instride;
  19.300 +    }
  19.301 +  }
  19.302 +}
  19.303 +
  19.304 +
  19.305 +/*
  19.306 + * Convert some rows of samples to the JPEG colorspace.
  19.307 + * This version handles multi-component colorspaces without conversion.
  19.308 + * We assume input_components == num_components.
  19.309 + */
  19.310 +
  19.311 +METHODDEF(void)
  19.312 +null_convert (j_compress_ptr cinfo,
  19.313 +	      JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  19.314 +	      JDIMENSION output_row, int num_rows)
  19.315 +{
  19.316 +  register JSAMPROW inptr;
  19.317 +  register JSAMPROW outptr;
  19.318 +  register JDIMENSION col;
  19.319 +  register int ci;
  19.320 +  int nc = cinfo->num_components;
  19.321 +  JDIMENSION num_cols = cinfo->image_width;
  19.322 +
  19.323 +  while (--num_rows >= 0) {
  19.324 +    /* It seems fastest to make a separate pass for each component. */
  19.325 +    for (ci = 0; ci < nc; ci++) {
  19.326 +      inptr = *input_buf;
  19.327 +      outptr = output_buf[ci][output_row];
  19.328 +      for (col = 0; col < num_cols; col++) {
  19.329 +	outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  19.330 +	inptr += nc;
  19.331 +      }
  19.332 +    }
  19.333 +    input_buf++;
  19.334 +    output_row++;
  19.335 +  }
  19.336 +}
  19.337 +
  19.338 +
  19.339 +/*
  19.340 + * Empty method for start_pass.
  19.341 + */
  19.342 +
  19.343 +METHODDEF(void)
  19.344 +null_method (j_compress_ptr cinfo)
  19.345 +{
  19.346 +  /* no work needed */
  19.347 +}
  19.348 +
  19.349 +
  19.350 +/*
  19.351 + * Module initialization routine for input colorspace conversion.
  19.352 + */
  19.353 +
  19.354 +GLOBAL(void)
  19.355 +jinit_color_converter (j_compress_ptr cinfo)
  19.356 +{
  19.357 +  my_cconvert_ptr cconvert;
  19.358 +
  19.359 +  cconvert = (my_cconvert_ptr)
  19.360 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  19.361 +				SIZEOF(my_color_converter));
  19.362 +  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  19.363 +  /* set start_pass to null method until we find out differently */
  19.364 +  cconvert->pub.start_pass = null_method;
  19.365 +
  19.366 +  /* Make sure input_components agrees with in_color_space */
  19.367 +  switch (cinfo->in_color_space) {
  19.368 +  case JCS_GRAYSCALE:
  19.369 +    if (cinfo->input_components != 1)
  19.370 +      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  19.371 +    break;
  19.372 +
  19.373 +  case JCS_RGB:
  19.374 +#if RGB_PIXELSIZE != 3
  19.375 +    if (cinfo->input_components != RGB_PIXELSIZE)
  19.376 +      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  19.377 +    break;
  19.378 +#endif /* else share code with YCbCr */
  19.379 +
  19.380 +  case JCS_YCbCr:
  19.381 +    if (cinfo->input_components != 3)
  19.382 +      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  19.383 +    break;
  19.384 +
  19.385 +  case JCS_CMYK:
  19.386 +  case JCS_YCCK:
  19.387 +    if (cinfo->input_components != 4)
  19.388 +      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  19.389 +    break;
  19.390 +
  19.391 +  default:			/* JCS_UNKNOWN can be anything */
  19.392 +    if (cinfo->input_components < 1)
  19.393 +      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  19.394 +    break;
  19.395 +  }
  19.396 +
  19.397 +  /* Check num_components, set conversion method based on requested space */
  19.398 +  switch (cinfo->jpeg_color_space) {
  19.399 +  case JCS_GRAYSCALE:
  19.400 +    if (cinfo->num_components != 1)
  19.401 +      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  19.402 +    if (cinfo->in_color_space == JCS_GRAYSCALE)
  19.403 +      cconvert->pub.color_convert = grayscale_convert;
  19.404 +    else if (cinfo->in_color_space == JCS_RGB) {
  19.405 +      cconvert->pub.start_pass = rgb_ycc_start;
  19.406 +      cconvert->pub.color_convert = rgb_gray_convert;
  19.407 +    } else if (cinfo->in_color_space == JCS_YCbCr)
  19.408 +      cconvert->pub.color_convert = grayscale_convert;
  19.409 +    else
  19.410 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.411 +    break;
  19.412 +
  19.413 +  case JCS_RGB:
  19.414 +    if (cinfo->num_components != 3)
  19.415 +      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  19.416 +    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  19.417 +      cconvert->pub.color_convert = null_convert;
  19.418 +    else
  19.419 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.420 +    break;
  19.421 +
  19.422 +  case JCS_YCbCr:
  19.423 +    if (cinfo->num_components != 3)
  19.424 +      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  19.425 +    if (cinfo->in_color_space == JCS_RGB) {
  19.426 +      cconvert->pub.start_pass = rgb_ycc_start;
  19.427 +      cconvert->pub.color_convert = rgb_ycc_convert;
  19.428 +    } else if (cinfo->in_color_space == JCS_YCbCr)
  19.429 +      cconvert->pub.color_convert = null_convert;
  19.430 +    else
  19.431 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.432 +    break;
  19.433 +
  19.434 +  case JCS_CMYK:
  19.435 +    if (cinfo->num_components != 4)
  19.436 +      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  19.437 +    if (cinfo->in_color_space == JCS_CMYK)
  19.438 +      cconvert->pub.color_convert = null_convert;
  19.439 +    else
  19.440 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.441 +    break;
  19.442 +
  19.443 +  case JCS_YCCK:
  19.444 +    if (cinfo->num_components != 4)
  19.445 +      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  19.446 +    if (cinfo->in_color_space == JCS_CMYK) {
  19.447 +      cconvert->pub.start_pass = rgb_ycc_start;
  19.448 +      cconvert->pub.color_convert = cmyk_ycck_convert;
  19.449 +    } else if (cinfo->in_color_space == JCS_YCCK)
  19.450 +      cconvert->pub.color_convert = null_convert;
  19.451 +    else
  19.452 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.453 +    break;
  19.454 +
  19.455 +  default:			/* allow null conversion of JCS_UNKNOWN */
  19.456 +    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  19.457 +	cinfo->num_components != cinfo->input_components)
  19.458 +      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  19.459 +    cconvert->pub.color_convert = null_convert;
  19.460 +    break;
  19.461 +  }
  19.462 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/libs/libjpeg/jcdctmgr.c	Sat Sep 19 05:51:51 2015 +0300
    20.3 @@ -0,0 +1,387 @@
    20.4 +/*
    20.5 + * jcdctmgr.c
    20.6 + *
    20.7 + * Copyright (C) 1994-1996, Thomas G. Lane.
    20.8 + * This file is part of the Independent JPEG Group's software.
    20.9 + * For conditions of distribution and use, see the accompanying README file.
   20.10 + *
   20.11 + * This file contains the forward-DCT management logic.
   20.12 + * This code selects a particular DCT implementation to be used,
   20.13 + * and it performs related housekeeping chores including coefficient
   20.14 + * quantization.
   20.15 + */
   20.16 +
   20.17 +#define JPEG_INTERNALS
   20.18 +#include "jinclude.h"
   20.19 +#include "jpeglib.h"
   20.20 +#include "jdct.h"		/* Private declarations for DCT subsystem */
   20.21 +
   20.22 +
   20.23 +/* Private subobject for this module */
   20.24 +
   20.25 +typedef struct {
   20.26 +  struct jpeg_forward_dct pub;	/* public fields */
   20.27 +
   20.28 +  /* Pointer to the DCT routine actually in use */
   20.29 +  forward_DCT_method_ptr do_dct;
   20.30 +
   20.31 +  /* The actual post-DCT divisors --- not identical to the quant table
   20.32 +   * entries, because of scaling (especially for an unnormalized DCT).
   20.33 +   * Each table is given in normal array order.
   20.34 +   */
   20.35 +  DCTELEM * divisors[NUM_QUANT_TBLS];
   20.36 +
   20.37 +#ifdef DCT_FLOAT_SUPPORTED
   20.38 +  /* Same as above for the floating-point case. */
   20.39 +  float_DCT_method_ptr do_float_dct;
   20.40 +  FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
   20.41 +#endif
   20.42 +} my_fdct_controller;
   20.43 +
   20.44 +typedef my_fdct_controller * my_fdct_ptr;
   20.45 +
   20.46 +
   20.47 +/*
   20.48 + * Initialize for a processing pass.
   20.49 + * Verify that all referenced Q-tables are present, and set up
   20.50 + * the divisor table for each one.
   20.51 + * In the current implementation, DCT of all components is done during
   20.52 + * the first pass, even if only some components will be output in the
   20.53 + * first scan.  Hence all components should be examined here.
   20.54 + */
   20.55 +
   20.56 +METHODDEF(void)
   20.57 +start_pass_fdctmgr (j_compress_ptr cinfo)
   20.58 +{
   20.59 +  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
   20.60 +  int ci, qtblno, i;
   20.61 +  jpeg_component_info *compptr;
   20.62 +  JQUANT_TBL * qtbl;
   20.63 +  DCTELEM * dtbl;
   20.64 +
   20.65 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
   20.66 +       ci++, compptr++) {
   20.67 +    qtblno = compptr->quant_tbl_no;
   20.68 +    /* Make sure specified quantization table is present */
   20.69 +    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
   20.70 +	cinfo->quant_tbl_ptrs[qtblno] == NULL)
   20.71 +      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
   20.72 +    qtbl = cinfo->quant_tbl_ptrs[qtblno];
   20.73 +    /* Compute divisors for this quant table */
   20.74 +    /* We may do this more than once for same table, but it's not a big deal */
   20.75 +    switch (cinfo->dct_method) {
   20.76 +#ifdef DCT_ISLOW_SUPPORTED
   20.77 +    case JDCT_ISLOW:
   20.78 +      /* For LL&M IDCT method, divisors are equal to raw quantization
   20.79 +       * coefficients multiplied by 8 (to counteract scaling).
   20.80 +       */
   20.81 +      if (fdct->divisors[qtblno] == NULL) {
   20.82 +	fdct->divisors[qtblno] = (DCTELEM *)
   20.83 +	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
   20.84 +				      DCTSIZE2 * SIZEOF(DCTELEM));
   20.85 +      }
   20.86 +      dtbl = fdct->divisors[qtblno];
   20.87 +      for (i = 0; i < DCTSIZE2; i++) {
   20.88 +	dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
   20.89 +      }
   20.90 +      break;
   20.91 +#endif
   20.92 +#ifdef DCT_IFAST_SUPPORTED
   20.93 +    case JDCT_IFAST:
   20.94 +      {
   20.95 +	/* For AA&N IDCT method, divisors are equal to quantization
   20.96 +	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
   20.97 +	 *   scalefactor[0] = 1
   20.98 +	 *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
   20.99 +	 * We apply a further scale factor of 8.
  20.100 +	 */
  20.101 +#define CONST_BITS 14
  20.102 +	static const INT16 aanscales[DCTSIZE2] = {
  20.103 +	  /* precomputed values scaled up by 14 bits */
  20.104 +	  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
  20.105 +	  22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
  20.106 +	  21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
  20.107 +	  19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
  20.108 +	  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
  20.109 +	  12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
  20.110 +	   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
  20.111 +	   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
  20.112 +	};
  20.113 +	SHIFT_TEMPS
  20.114 +
  20.115 +	if (fdct->divisors[qtblno] == NULL) {
  20.116 +	  fdct->divisors[qtblno] = (DCTELEM *)
  20.117 +	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  20.118 +					DCTSIZE2 * SIZEOF(DCTELEM));
  20.119 +	}
  20.120 +	dtbl = fdct->divisors[qtblno];
  20.121 +	for (i = 0; i < DCTSIZE2; i++) {
  20.122 +	  dtbl[i] = (DCTELEM)
  20.123 +	    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  20.124 +				  (INT32) aanscales[i]),
  20.125 +		    CONST_BITS-3);
  20.126 +	}
  20.127 +      }
  20.128 +      break;
  20.129 +#endif
  20.130 +#ifdef DCT_FLOAT_SUPPORTED
  20.131 +    case JDCT_FLOAT:
  20.132 +      {
  20.133 +	/* For float AA&N IDCT method, divisors are equal to quantization
  20.134 +	 * coefficients scaled by scalefactor[row]*scalefactor[col], where
  20.135 +	 *   scalefactor[0] = 1
  20.136 +	 *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
  20.137 +	 * We apply a further scale factor of 8.
  20.138 +	 * What's actually stored is 1/divisor so that the inner loop can
  20.139 +	 * use a multiplication rather than a division.
  20.140 +	 */
  20.141 +	FAST_FLOAT * fdtbl;
  20.142 +	int row, col;
  20.143 +	static const double aanscalefactor[DCTSIZE] = {
  20.144 +	  1.0, 1.387039845, 1.306562965, 1.175875602,
  20.145 +	  1.0, 0.785694958, 0.541196100, 0.275899379
  20.146 +	};
  20.147 +
  20.148 +	if (fdct->float_divisors[qtblno] == NULL) {
  20.149 +	  fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  20.150 +	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  20.151 +					DCTSIZE2 * SIZEOF(FAST_FLOAT));
  20.152 +	}
  20.153 +	fdtbl = fdct->float_divisors[qtblno];
  20.154 +	i = 0;
  20.155 +	for (row = 0; row < DCTSIZE; row++) {
  20.156 +	  for (col = 0; col < DCTSIZE; col++) {
  20.157 +	    fdtbl[i] = (FAST_FLOAT)
  20.158 +	      (1.0 / (((double) qtbl->quantval[i] *
  20.159 +		       aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  20.160 +	    i++;
  20.161 +	  }
  20.162 +	}
  20.163 +      }
  20.164 +      break;
  20.165 +#endif
  20.166 +    default:
  20.167 +      ERREXIT(cinfo, JERR_NOT_COMPILED);
  20.168 +      break;
  20.169 +    }
  20.170 +  }
  20.171 +}
  20.172 +
  20.173 +
  20.174 +/*
  20.175 + * Perform forward DCT on one or more blocks of a component.
  20.176 + *
  20.177 + * The input samples are taken from the sample_data[] array starting at
  20.178 + * position start_row/start_col, and moving to the right for any additional
  20.179 + * blocks. The quantized coefficients are returned in coef_blocks[].
  20.180 + */
  20.181 +
  20.182 +METHODDEF(void)
  20.183 +forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  20.184 +	     JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  20.185 +	     JDIMENSION start_row, JDIMENSION start_col,
  20.186 +	     JDIMENSION num_blocks)
  20.187 +/* This version is used for integer DCT implementations. */
  20.188 +{
  20.189 +  /* This routine is heavily used, so it's worth coding it tightly. */
  20.190 +  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  20.191 +  forward_DCT_method_ptr do_dct = fdct->do_dct;
  20.192 +  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  20.193 +  DCTELEM workspace[DCTSIZE2];	/* work area for FDCT subroutine */
  20.194 +  JDIMENSION bi;
  20.195 +
  20.196 +  sample_data += start_row;	/* fold in the vertical offset once */
  20.197 +
  20.198 +  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  20.199 +    /* Load data into workspace, applying unsigned->signed conversion */
  20.200 +    { register DCTELEM *workspaceptr;
  20.201 +      register JSAMPROW elemptr;
  20.202 +      register int elemr;
  20.203 +
  20.204 +      workspaceptr = workspace;
  20.205 +      for (elemr = 0; elemr < DCTSIZE; elemr++) {
  20.206 +	elemptr = sample_data[elemr] + start_col;
  20.207 +#if DCTSIZE == 8		/* unroll the inner loop */
  20.208 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.209 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.210 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.211 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.212 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.213 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.214 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.215 +	*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.216 +#else
  20.217 +	{ register int elemc;
  20.218 +	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
  20.219 +	    *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  20.220 +	  }
  20.221 +	}
  20.222 +#endif
  20.223 +      }
  20.224 +    }
  20.225 +
  20.226 +    /* Perform the DCT */
  20.227 +    (*do_dct) (workspace);
  20.228 +
  20.229 +    /* Quantize/descale the coefficients, and store into coef_blocks[] */
  20.230 +    { register DCTELEM temp, qval;
  20.231 +      register int i;
  20.232 +      register JCOEFPTR output_ptr = coef_blocks[bi];
  20.233 +
  20.234 +      for (i = 0; i < DCTSIZE2; i++) {
  20.235 +	qval = divisors[i];
  20.236 +	temp = workspace[i];
  20.237 +	/* Divide the coefficient value by qval, ensuring proper rounding.
  20.238 +	 * Since C does not specify the direction of rounding for negative
  20.239 +	 * quotients, we have to force the dividend positive for portability.
  20.240 +	 *
  20.241 +	 * In most files, at least half of the output values will be zero
  20.242 +	 * (at default quantization settings, more like three-quarters...)
  20.243 +	 * so we should ensure that this case is fast.  On many machines,
  20.244 +	 * a comparison is enough cheaper than a divide to make a special test
  20.245 +	 * a win.  Since both inputs will be nonnegative, we need only test
  20.246 +	 * for a < b to discover whether a/b is 0.
  20.247 +	 * If your machine's division is fast enough, define FAST_DIVIDE.
  20.248 +	 */
  20.249 +#ifdef FAST_DIVIDE
  20.250 +#define DIVIDE_BY(a,b)	a /= b
  20.251 +#else
  20.252 +#define DIVIDE_BY(a,b)	if (a >= b) a /= b; else a = 0
  20.253 +#endif
  20.254 +	if (temp < 0) {
  20.255 +	  temp = -temp;
  20.256 +	  temp += qval>>1;	/* for rounding */
  20.257 +	  DIVIDE_BY(temp, qval);
  20.258 +	  temp = -temp;
  20.259 +	} else {
  20.260 +	  temp += qval>>1;	/* for rounding */
  20.261 +	  DIVIDE_BY(temp, qval);
  20.262 +	}
  20.263 +	output_ptr[i] = (JCOEF) temp;
  20.264 +      }
  20.265 +    }
  20.266 +  }
  20.267 +}
  20.268 +
  20.269 +
  20.270 +#ifdef DCT_FLOAT_SUPPORTED
  20.271 +
  20.272 +METHODDEF(void)
  20.273 +forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  20.274 +		   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  20.275 +		   JDIMENSION start_row, JDIMENSION start_col,
  20.276 +		   JDIMENSION num_blocks)
  20.277 +/* This version is used for floating-point DCT implementations. */
  20.278 +{
  20.279 +  /* This routine is heavily used, so it's worth coding it tightly. */
  20.280 +  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  20.281 +  float_DCT_method_ptr do_dct = fdct->do_float_dct;
  20.282 +  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  20.283 +  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  20.284 +  JDIMENSION bi;
  20.285 +
  20.286 +  sample_data += start_row;	/* fold in the vertical offset once */
  20.287 +
  20.288 +  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  20.289 +    /* Load data into workspace, applying unsigned->signed conversion */
  20.290 +    { register FAST_FLOAT *workspaceptr;
  20.291 +      register JSAMPROW elemptr;
  20.292 +      register int elemr;
  20.293 +
  20.294 +      workspaceptr = workspace;
  20.295 +      for (elemr = 0; elemr < DCTSIZE; elemr++) {
  20.296 +	elemptr = sample_data[elemr] + start_col;
  20.297 +#if DCTSIZE == 8		/* unroll the inner loop */
  20.298 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.299 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.300 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.301 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.302 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.303 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.304 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.305 +	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.306 +#else
  20.307 +	{ register int elemc;
  20.308 +	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
  20.309 +	    *workspaceptr++ = (FAST_FLOAT)
  20.310 +	      (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  20.311 +	  }
  20.312 +	}
  20.313 +#endif
  20.314 +      }
  20.315 +    }
  20.316 +
  20.317 +    /* Perform the DCT */
  20.318 +    (*do_dct) (workspace);
  20.319 +
  20.320 +    /* Quantize/descale the coefficients, and store into coef_blocks[] */
  20.321 +    { register FAST_FLOAT temp;
  20.322 +      register int i;
  20.323 +      register JCOEFPTR output_ptr = coef_blocks[bi];
  20.324 +
  20.325 +      for (i = 0; i < DCTSIZE2; i++) {
  20.326 +	/* Apply the quantization and scaling factor */
  20.327 +	temp = workspace[i] * divisors[i];
  20.328 +	/* Round to nearest integer.
  20.329 +	 * Since C does not specify the direction of rounding for negative
  20.330 +	 * quotients, we have to force the dividend positive for portability.
  20.331 +	 * The maximum coefficient size is +-16K (for 12-bit data), so this
  20.332 +	 * code should work for either 16-bit or 32-bit ints.
  20.333 +	 */
  20.334 +	output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  20.335 +      }
  20.336 +    }
  20.337 +  }
  20.338 +}
  20.339 +
  20.340 +#endif /* DCT_FLOAT_SUPPORTED */
  20.341 +
  20.342 +
  20.343 +/*
  20.344 + * Initialize FDCT manager.
  20.345 + */
  20.346 +
  20.347 +GLOBAL(void)
  20.348 +jinit_forward_dct (j_compress_ptr cinfo)
  20.349 +{
  20.350 +  my_fdct_ptr fdct;
  20.351 +  int i;
  20.352 +
  20.353 +  fdct = (my_fdct_ptr)
  20.354 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  20.355 +				SIZEOF(my_fdct_controller));
  20.356 +  cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  20.357 +  fdct->pub.start_pass = start_pass_fdctmgr;
  20.358 +
  20.359 +  switch (cinfo->dct_method) {
  20.360 +#ifdef DCT_ISLOW_SUPPORTED
  20.361 +  case JDCT_ISLOW:
  20.362 +    fdct->pub.forward_DCT = forward_DCT;
  20.363 +    fdct->do_dct = jpeg_fdct_islow;
  20.364 +    break;
  20.365 +#endif
  20.366 +#ifdef DCT_IFAST_SUPPORTED
  20.367 +  case JDCT_IFAST:
  20.368 +    fdct->pub.forward_DCT = forward_DCT;
  20.369 +    fdct->do_dct = jpeg_fdct_ifast;
  20.370 +    break;
  20.371 +#endif
  20.372 +#ifdef DCT_FLOAT_SUPPORTED
  20.373 +  case JDCT_FLOAT:
  20.374 +    fdct->pub.forward_DCT = forward_DCT_float;
  20.375 +    fdct->do_float_dct = jpeg_fdct_float;
  20.376 +    break;
  20.377 +#endif
  20.378 +  default:
  20.379 +    ERREXIT(cinfo, JERR_NOT_COMPILED);
  20.380 +    break;
  20.381 +  }
  20.382 +
  20.383 +  /* Mark divisor tables unallocated */
  20.384 +  for (i = 0; i < NUM_QUANT_TBLS; i++) {
  20.385 +    fdct->divisors[i] = NULL;
  20.386 +#ifdef DCT_FLOAT_SUPPORTED
  20.387 +    fdct->float_divisors[i] = NULL;
  20.388 +#endif
  20.389 +  }
  20.390 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/libs/libjpeg/jchuff.c	Sat Sep 19 05:51:51 2015 +0300
    21.3 @@ -0,0 +1,909 @@
    21.4 +/*
    21.5 + * jchuff.c
    21.6 + *
    21.7 + * Copyright (C) 1991-1997, Thomas G. Lane.
    21.8 + * This file is part of the Independent JPEG Group's software.
    21.9 + * For conditions of distribution and use, see the accompanying README file.
   21.10 + *
   21.11 + * This file contains Huffman entropy encoding routines.
   21.12 + *
   21.13 + * Much of the complexity here has to do with supporting output suspension.
   21.14 + * If the data destination module demands suspension, we want to be able to
   21.15 + * back up to the start of the current MCU.  To do this, we copy state
   21.16 + * variables into local working storage, and update them back to the
   21.17 + * permanent JPEG objects only upon successful completion of an MCU.
   21.18 + */
   21.19 +
   21.20 +#define JPEG_INTERNALS
   21.21 +#include "jinclude.h"
   21.22 +#include "jpeglib.h"
   21.23 +#include "jchuff.h"		/* Declarations shared with jcphuff.c */
   21.24 +
   21.25 +
   21.26 +/* Expanded entropy encoder object for Huffman encoding.
   21.27 + *
   21.28 + * The savable_state subrecord contains fields that change within an MCU,
   21.29 + * but must not be updated permanently until we complete the MCU.
   21.30 + */
   21.31 +
   21.32 +typedef struct {
   21.33 +  INT32 put_buffer;		/* current bit-accumulation buffer */
   21.34 +  int put_bits;			/* # of bits now in it */
   21.35 +  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
   21.36 +} savable_state;
   21.37 +
   21.38 +/* This macro is to work around compilers with missing or broken
   21.39 + * structure assignment.  You'll need to fix this code if you have
   21.40 + * such a compiler and you change MAX_COMPS_IN_SCAN.
   21.41 + */
   21.42 +
   21.43 +#ifndef NO_STRUCT_ASSIGN
   21.44 +#define ASSIGN_STATE(dest,src)  ((dest) = (src))
   21.45 +#else
   21.46 +#if MAX_COMPS_IN_SCAN == 4
   21.47 +#define ASSIGN_STATE(dest,src)  \
   21.48 +	((dest).put_buffer = (src).put_buffer, \
   21.49 +	 (dest).put_bits = (src).put_bits, \
   21.50 +	 (dest).last_dc_val[0] = (src).last_dc_val[0], \
   21.51 +	 (dest).last_dc_val[1] = (src).last_dc_val[1], \
   21.52 +	 (dest).last_dc_val[2] = (src).last_dc_val[2], \
   21.53 +	 (dest).last_dc_val[3] = (src).last_dc_val[3])
   21.54 +#endif
   21.55 +#endif
   21.56 +
   21.57 +
   21.58 +typedef struct {
   21.59 +  struct jpeg_entropy_encoder pub; /* public fields */
   21.60 +
   21.61 +  savable_state saved;		/* Bit buffer & DC state at start of MCU */
   21.62 +
   21.63 +  /* These fields are NOT loaded into local working state. */
   21.64 +  unsigned int restarts_to_go;	/* MCUs left in this restart interval */
   21.65 +  int next_restart_num;		/* next restart number to write (0-7) */
   21.66 +
   21.67 +  /* Pointers to derived tables (these workspaces have image lifespan) */
   21.68 +  c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
   21.69 +  c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
   21.70 +
   21.71 +#ifdef ENTROPY_OPT_SUPPORTED	/* Statistics tables for optimization */
   21.72 +  long * dc_count_ptrs[NUM_HUFF_TBLS];
   21.73 +  long * ac_count_ptrs[NUM_HUFF_TBLS];
   21.74 +#endif
   21.75 +} huff_entropy_encoder;
   21.76 +
   21.77 +typedef huff_entropy_encoder * huff_entropy_ptr;
   21.78 +
   21.79 +/* Working state while writing an MCU.
   21.80 + * This struct contains all the fields that are needed by subroutines.
   21.81 + */
   21.82 +
   21.83 +typedef struct {
   21.84 +  JOCTET * next_output_byte;	/* => next byte to write in buffer */
   21.85 +  size_t free_in_buffer;	/* # of byte spaces remaining in buffer */
   21.86 +  savable_state cur;		/* Current bit buffer & DC state */
   21.87 +  j_compress_ptr cinfo;		/* dump_buffer needs access to this */
   21.88 +} working_state;
   21.89 +
   21.90 +
   21.91 +/* Forward declarations */
   21.92 +METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
   21.93 +					JBLOCKROW *MCU_data));
   21.94 +METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
   21.95 +#ifdef ENTROPY_OPT_SUPPORTED
   21.96 +METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
   21.97 +					  JBLOCKROW *MCU_data));
   21.98 +METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
   21.99 +#endif
  21.100 +
  21.101 +
  21.102 +/*
  21.103 + * Initialize for a Huffman-compressed scan.
  21.104 + * If gather_statistics is TRUE, we do not output anything during the scan,
  21.105 + * just count the Huffman symbols used and generate Huffman code tables.
  21.106 + */
  21.107 +
  21.108 +METHODDEF(void)
  21.109 +start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  21.110 +{
  21.111 +  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  21.112 +  int ci, dctbl, actbl;
  21.113 +  jpeg_component_info * compptr;
  21.114 +
  21.115 +  if (gather_statistics) {
  21.116 +#ifdef ENTROPY_OPT_SUPPORTED
  21.117 +    entropy->pub.encode_mcu = encode_mcu_gather;
  21.118 +    entropy->pub.finish_pass = finish_pass_gather;
  21.119 +#else
  21.120 +    ERREXIT(cinfo, JERR_NOT_COMPILED);
  21.121 +#endif
  21.122 +  } else {
  21.123 +    entropy->pub.encode_mcu = encode_mcu_huff;
  21.124 +    entropy->pub.finish_pass = finish_pass_huff;
  21.125 +  }
  21.126 +
  21.127 +  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  21.128 +    compptr = cinfo->cur_comp_info[ci];
  21.129 +    dctbl = compptr->dc_tbl_no;
  21.130 +    actbl = compptr->ac_tbl_no;
  21.131 +    if (gather_statistics) {
  21.132 +#ifdef ENTROPY_OPT_SUPPORTED
  21.133 +      /* Check for invalid table indexes */
  21.134 +      /* (make_c_derived_tbl does this in the other path) */
  21.135 +      if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  21.136 +	ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  21.137 +      if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  21.138 +	ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  21.139 +      /* Allocate and zero the statistics tables */
  21.140 +      /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
  21.141 +      if (entropy->dc_count_ptrs[dctbl] == NULL)
  21.142 +	entropy->dc_count_ptrs[dctbl] = (long *)
  21.143 +	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  21.144 +				      257 * SIZEOF(long));
  21.145 +      MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  21.146 +      if (entropy->ac_count_ptrs[actbl] == NULL)
  21.147 +	entropy->ac_count_ptrs[actbl] = (long *)
  21.148 +	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  21.149 +				      257 * SIZEOF(long));
  21.150 +      MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  21.151 +#endif
  21.152 +    } else {
  21.153 +      /* Compute derived values for Huffman tables */
  21.154 +      /* We may do this more than once for a table, but it's not expensive */
  21.155 +      jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  21.156 +			      & entropy->dc_derived_tbls[dctbl]);
  21.157 +      jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  21.158 +			      & entropy->ac_derived_tbls[actbl]);
  21.159 +    }
  21.160 +    /* Initialize DC predictions to 0 */
  21.161 +    entropy->saved.last_dc_val[ci] = 0;
  21.162 +  }
  21.163 +
  21.164 +  /* Initialize bit buffer to empty */
  21.165 +  entropy->saved.put_buffer = 0;
  21.166 +  entropy->saved.put_bits = 0;
  21.167 +
  21.168 +  /* Initialize restart stuff */
  21.169 +  entropy->restarts_to_go = cinfo->restart_interval;
  21.170 +  entropy->next_restart_num = 0;
  21.171 +}
  21.172 +
  21.173 +
  21.174 +/*
  21.175 + * Compute the derived values for a Huffman table.
  21.176 + * This routine also performs some validation checks on the table.
  21.177 + *
  21.178 + * Note this is also used by jcphuff.c.
  21.179 + */
  21.180 +
  21.181 +GLOBAL(void)
  21.182 +jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  21.183 +			 c_derived_tbl ** pdtbl)
  21.184 +{
  21.185 +  JHUFF_TBL *htbl;
  21.186 +  c_derived_tbl *dtbl;
  21.187 +  int p, i, l, lastp, si, maxsymbol;
  21.188 +  char huffsize[257];
  21.189 +  unsigned int huffcode[257];
  21.190 +  unsigned int code;
  21.191 +
  21.192 +  /* Note that huffsize[] and huffcode[] are filled in code-length order,
  21.193 +   * paralleling the order of the symbols themselves in htbl->huffval[].
  21.194 +   */
  21.195 +
  21.196 +  /* Find the input Huffman table */
  21.197 +  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  21.198 +    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  21.199 +  htbl =
  21.200 +    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  21.201 +  if (htbl == NULL)
  21.202 +    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  21.203 +
  21.204 +  /* Allocate a workspace if we haven't already done so. */
  21.205 +  if (*pdtbl == NULL)
  21.206 +    *pdtbl = (c_derived_tbl *)
  21.207 +      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  21.208 +				  SIZEOF(c_derived_tbl));
  21.209 +  dtbl = *pdtbl;
  21.210 +  
  21.211 +  /* Figure C.1: make table of Huffman code length for each symbol */
  21.212 +
  21.213 +  p = 0;
  21.214 +  for (l = 1; l <= 16; l++) {
  21.215 +    i = (int) htbl->bits[l];
  21.216 +    if (i < 0 || p + i > 256)	/* protect against table overrun */
  21.217 +      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  21.218 +    while (i--)
  21.219 +      huffsize[p++] = (char) l;
  21.220 +  }
  21.221 +  huffsize[p] = 0;
  21.222 +  lastp = p;
  21.223 +  
  21.224 +  /* Figure C.2: generate the codes themselves */
  21.225 +  /* We also validate that the counts represent a legal Huffman code tree. */
  21.226 +
  21.227 +  code = 0;
  21.228 +  si = huffsize[0];
  21.229 +  p = 0;
  21.230 +  while (huffsize[p]) {
  21.231 +    while (((int) huffsize[p]) == si) {
  21.232 +      huffcode[p++] = code;
  21.233 +      code++;
  21.234 +    }
  21.235 +    /* code is now 1 more than the last code used for codelength si; but
  21.236 +     * it must still fit in si bits, since no code is allowed to be all ones.
  21.237 +     */
  21.238 +    if (((INT32) code) >= (((INT32) 1) << si))
  21.239 +      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  21.240 +    code <<= 1;
  21.241 +    si++;
  21.242 +  }
  21.243 +  
  21.244 +  /* Figure C.3: generate encoding tables */
  21.245 +  /* These are code and size indexed by symbol value */
  21.246 +
  21.247 +  /* Set all codeless symbols to have code length 0;
  21.248 +   * this lets us detect duplicate VAL entries here, and later
  21.249 +   * allows emit_bits to detect any attempt to emit such symbols.
  21.250 +   */
  21.251 +  MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  21.252 +
  21.253 +  /* This is also a convenient place to check for out-of-range
  21.254 +   * and duplicated VAL entries.  We allow 0..255 for AC symbols
  21.255 +   * but only 0..15 for DC.  (We could constrain them further
  21.256 +   * based on data depth and mode, but this seems enough.)
  21.257 +   */
  21.258 +  maxsymbol = isDC ? 15 : 255;
  21.259 +
  21.260 +  for (p = 0; p < lastp; p++) {
  21.261 +    i = htbl->huffval[p];
  21.262 +    if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  21.263 +      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  21.264 +    dtbl->ehufco[i] = huffcode[p];
  21.265 +    dtbl->ehufsi[i] = huffsize[p];
  21.266 +  }
  21.267 +}
  21.268 +
  21.269 +
  21.270 +/* Outputting bytes to the file */
  21.271 +
  21.272 +/* Emit a byte, taking 'action' if must suspend. */
  21.273 +#define emit_byte(state,val,action)  \
  21.274 +	{ *(state)->next_output_byte++ = (JOCTET) (val);  \
  21.275 +	  if (--(state)->free_in_buffer == 0)  \
  21.276 +	    if (! dump_buffer(state))  \
  21.277 +	      { action; } }
  21.278 +
  21.279 +
  21.280 +LOCAL(boolean)
  21.281 +dump_buffer (working_state * state)
  21.282 +/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
  21.283 +{
  21.284 +  struct jpeg_destination_mgr * dest = state->cinfo->dest;
  21.285 +
  21.286 +  if (! (*dest->empty_output_buffer) (state->cinfo))
  21.287 +    return FALSE;
  21.288 +  /* After a successful buffer dump, must reset buffer pointers */
  21.289 +  state->next_output_byte = dest->next_output_byte;
  21.290 +  state->free_in_buffer = dest->free_in_buffer;
  21.291 +  return TRUE;
  21.292 +}
  21.293 +
  21.294 +
  21.295 +/* Outputting bits to the file */
  21.296 +
  21.297 +/* Only the right 24 bits of put_buffer are used; the valid bits are
  21.298 + * left-justified in this part.  At most 16 bits can be passed to emit_bits
  21.299 + * in one call, and we never retain more than 7 bits in put_buffer
  21.300 + * between calls, so 24 bits are sufficient.
  21.301 + */
  21.302 +
  21.303 +INLINE
  21.304 +LOCAL(boolean)
  21.305 +emit_bits (working_state * state, unsigned int code, int size)
  21.306 +/* Emit some bits; return TRUE if successful, FALSE if must suspend */
  21.307 +{
  21.308 +  /* This routine is heavily used, so it's worth coding tightly. */
  21.309 +  register INT32 put_buffer = (INT32) code;
  21.310 +  register int put_bits = state->cur.put_bits;
  21.311 +
  21.312 +  /* if size is 0, caller used an invalid Huffman table entry */
  21.313 +  if (size == 0)
  21.314 +    ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  21.315 +
  21.316 +  put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  21.317 +  
  21.318 +  put_bits += size;		/* new number of bits in buffer */
  21.319 +  
  21.320 +  put_buffer <<= 24 - put_bits; /* align incoming bits */
  21.321 +
  21.322 +  put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  21.323 +  
  21.324 +  while (put_bits >= 8) {
  21.325 +    int c = (int) ((put_buffer >> 16) & 0xFF);
  21.326 +    
  21.327 +    emit_byte(state, c, return FALSE);
  21.328 +    if (c == 0xFF) {		/* need to stuff a zero byte? */
  21.329 +      emit_byte(state, 0, return FALSE);
  21.330 +    }
  21.331 +    put_buffer <<= 8;
  21.332 +    put_bits -= 8;
  21.333 +  }
  21.334 +
  21.335 +  state->cur.put_buffer = put_buffer; /* update state variables */
  21.336 +  state->cur.put_bits = put_bits;
  21.337 +
  21.338 +  return TRUE;
  21.339 +}
  21.340 +
  21.341 +
  21.342 +LOCAL(boolean)
  21.343 +flush_bits (working_state * state)
  21.344 +{
  21.345 +  if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  21.346 +    return FALSE;
  21.347 +  state->cur.put_buffer = 0;	/* and reset bit-buffer to empty */
  21.348 +  state->cur.put_bits = 0;
  21.349 +  return TRUE;
  21.350 +}
  21.351 +
  21.352 +
  21.353 +/* Encode a single block's worth of coefficients */
  21.354 +
  21.355 +LOCAL(boolean)
  21.356 +encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  21.357 +		  c_derived_tbl *dctbl, c_derived_tbl *actbl)
  21.358 +{
  21.359 +  register int temp, temp2;
  21.360 +  register int nbits;
  21.361 +  register int k, r, i;
  21.362 +  
  21.363 +  /* Encode the DC coefficient difference per section F.1.2.1 */
  21.364 +  
  21.365 +  temp = temp2 = block[0] - last_dc_val;
  21.366 +
  21.367 +  if (temp < 0) {
  21.368 +    temp = -temp;		/* temp is abs value of input */
  21.369 +    /* For a negative input, want temp2 = bitwise complement of abs(input) */
  21.370 +    /* This code assumes we are on a two's complement machine */
  21.371 +    temp2--;
  21.372 +  }
  21.373 +  
  21.374 +  /* Find the number of bits needed for the magnitude of the coefficient */
  21.375 +  nbits = 0;
  21.376 +  while (temp) {
  21.377 +    nbits++;
  21.378 +    temp >>= 1;
  21.379 +  }
  21.380 +  /* Check for out-of-range coefficient values.
  21.381 +   * Since we're encoding a difference, the range limit is twice as much.
  21.382 +   */
  21.383 +  if (nbits > MAX_COEF_BITS+1)
  21.384 +    ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  21.385 +  
  21.386 +  /* Emit the Huffman-coded symbol for the number of bits */
  21.387 +  if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  21.388 +    return FALSE;
  21.389 +
  21.390 +  /* Emit that number of bits of the value, if positive, */
  21.391 +  /* or the complement of its magnitude, if negative. */
  21.392 +  if (nbits)			/* emit_bits rejects calls with size 0 */
  21.393 +    if (! emit_bits(state, (unsigned int) temp2, nbits))
  21.394 +      return FALSE;
  21.395 +
  21.396 +  /* Encode the AC coefficients per section F.1.2.2 */
  21.397 +  
  21.398 +  r = 0;			/* r = run length of zeros */
  21.399 +  
  21.400 +  for (k = 1; k < DCTSIZE2; k++) {
  21.401 +    if ((temp = block[jpeg_natural_order[k]]) == 0) {
  21.402 +      r++;
  21.403 +    } else {
  21.404 +      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
  21.405 +      while (r > 15) {
  21.406 +	if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  21.407 +	  return FALSE;
  21.408 +	r -= 16;
  21.409 +      }
  21.410 +
  21.411 +      temp2 = temp;
  21.412 +      if (temp < 0) {
  21.413 +	temp = -temp;		/* temp is abs value of input */
  21.414 +	/* This code assumes we are on a two's complement machine */
  21.415 +	temp2--;
  21.416 +      }
  21.417 +      
  21.418 +      /* Find the number of bits needed for the magnitude of the coefficient */
  21.419 +      nbits = 1;		/* there must be at least one 1 bit */
  21.420 +      while ((temp >>= 1))
  21.421 +	nbits++;
  21.422 +      /* Check for out-of-range coefficient values */
  21.423 +      if (nbits > MAX_COEF_BITS)
  21.424 +	ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  21.425 +      
  21.426 +      /* Emit Huffman symbol for run length / number of bits */
  21.427 +      i = (r << 4) + nbits;
  21.428 +      if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  21.429 +	return FALSE;
  21.430 +
  21.431 +      /* Emit that number of bits of the value, if positive, */
  21.432 +      /* or the complement of its magnitude, if negative. */
  21.433 +      if (! emit_bits(state, (unsigned int) temp2, nbits))
  21.434 +	return FALSE;
  21.435 +      
  21.436 +      r = 0;
  21.437 +    }
  21.438 +  }
  21.439 +
  21.440 +  /* If the last coef(s) were zero, emit an end-of-block code */
  21.441 +  if (r > 0)
  21.442 +    if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  21.443 +      return FALSE;
  21.444 +
  21.445 +  return TRUE;
  21.446 +}
  21.447 +
  21.448 +
  21.449 +/*
  21.450 + * Emit a restart marker & resynchronize predictions.
  21.451 + */
  21.452 +
  21.453 +LOCAL(boolean)
  21.454 +emit_restart (working_state * state, int restart_num)
  21.455 +{
  21.456 +  int ci;
  21.457 +
  21.458 +  if (! flush_bits(state))
  21.459 +    return FALSE;
  21.460 +
  21.461 +  emit_byte(state, 0xFF, return FALSE);
  21.462 +  emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  21.463 +
  21.464 +  /* Re-initialize DC predictions to 0 */
  21.465 +  for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  21.466 +    state->cur.last_dc_val[ci] = 0;
  21.467 +
  21.468 +  /* The restart counter is not updated until we successfully write the MCU. */
  21.469 +
  21.470 +  return TRUE;
  21.471 +}
  21.472 +
  21.473 +
  21.474 +/*
  21.475 + * Encode and output one MCU's worth of Huffman-compressed coefficients.
  21.476 + */
  21.477 +
  21.478 +METHODDEF(boolean)
  21.479 +encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  21.480 +{
  21.481 +  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  21.482 +  working_state state;
  21.483 +  int blkn, ci;
  21.484 +  jpeg_component_info * compptr;
  21.485 +
  21.486 +  /* Load up working state */
  21.487 +  state.next_output_byte = cinfo->dest->next_output_byte;
  21.488 +  state.free_in_buffer = cinfo->dest->free_in_buffer;
  21.489 +  ASSIGN_STATE(state.cur, entropy->saved);
  21.490 +  state.cinfo = cinfo;
  21.491 +
  21.492 +  /* Emit restart marker if needed */
  21.493 +  if (cinfo->restart_interval) {
  21.494 +    if (entropy->restarts_to_go == 0)
  21.495 +      if (! emit_restart(&state, entropy->next_restart_num))
  21.496 +	return FALSE;
  21.497 +  }
  21.498 +
  21.499 +  /* Encode the MCU data blocks */
  21.500 +  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  21.501 +    ci = cinfo->MCU_membership[blkn];
  21.502 +    compptr = cinfo->cur_comp_info[ci];
  21.503 +    if (! encode_one_block(&state,
  21.504 +			   MCU_data[blkn][0], state.cur.last_dc_val[ci],
  21.505 +			   entropy->dc_derived_tbls[compptr->dc_tbl_no],
  21.506 +			   entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  21.507 +      return FALSE;
  21.508 +    /* Update last_dc_val */
  21.509 +    state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  21.510 +  }
  21.511 +
  21.512 +  /* Completed MCU, so update state */
  21.513 +  cinfo->dest->next_output_byte = state.next_output_byte;
  21.514 +  cinfo->dest->free_in_buffer = state.free_in_buffer;
  21.515 +  ASSIGN_STATE(entropy->saved, state.cur);
  21.516 +
  21.517 +  /* Update restart-interval state too */
  21.518 +  if (cinfo->restart_interval) {
  21.519 +    if (entropy->restarts_to_go == 0) {
  21.520 +      entropy->restarts_to_go = cinfo->restart_interval;
  21.521 +      entropy->next_restart_num++;
  21.522 +      entropy->next_restart_num &= 7;
  21.523 +    }
  21.524 +    entropy->restarts_to_go--;
  21.525 +  }
  21.526 +
  21.527 +  return TRUE;
  21.528 +}
  21.529 +
  21.530 +
  21.531 +/*
  21.532 + * Finish up at the end of a Huffman-compressed scan.
  21.533 + */
  21.534 +
  21.535 +METHODDEF(void)
  21.536 +finish_pass_huff (j_compress_ptr cinfo)
  21.537 +{
  21.538 +  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  21.539 +  working_state state;
  21.540 +
  21.541 +  /* Load up working state ... flush_bits needs it */
  21.542 +  state.next_output_byte = cinfo->dest->next_output_byte;
  21.543 +  state.free_in_buffer = cinfo->dest->free_in_buffer;
  21.544 +  ASSIGN_STATE(state.cur, entropy->saved);
  21.545 +  state.cinfo = cinfo;
  21.546 +
  21.547 +  /* Flush out the last data */
  21.548 +  if (! flush_bits(&state))
  21.549 +    ERREXIT(cinfo, JERR_CANT_SUSPEND);
  21.550 +
  21.551 +  /* Update state */
  21.552 +  cinfo->dest->next_output_byte = state.next_output_byte;
  21.553 +  cinfo->dest->free_in_buffer = state.free_in_buffer;
  21.554 +  ASSIGN_STATE(entropy->saved, state.cur);
  21.555 +}
  21.556 +
  21.557 +
  21.558 +/*
  21.559 + * Huffman coding optimization.
  21.560 + *
  21.561 + * We first scan the supplied data and count the number of uses of each symbol
  21.562 + * that is to be Huffman-coded. (This process MUST agree with the code above.)
  21.563 + * Then we build a Huffman coding tree for the observed counts.
  21.564 + * Symbols which are not needed at all for the particular image are not
  21.565 + * assigned any code, which saves space in the DHT marker as well as in
  21.566 + * the compressed data.
  21.567 + */
  21.568 +
  21.569 +#ifdef ENTROPY_OPT_SUPPORTED
  21.570 +
  21.571 +
  21.572 +/* Process a single block's worth of coefficients */
  21.573 +
  21.574 +LOCAL(void)
  21.575 +htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  21.576 +		 long dc_counts[], long ac_counts[])
  21.577 +{
  21.578 +  register int temp;
  21.579 +  register int nbits;
  21.580 +  register int k, r;
  21.581 +  
  21.582 +  /* Encode the DC coefficient difference per section F.1.2.1 */
  21.583 +  
  21.584 +  temp = block[0] - last_dc_val;
  21.585 +  if (temp < 0)
  21.586 +    temp = -temp;
  21.587 +  
  21.588 +  /* Find the number of bits needed for the magnitude of the coefficient */
  21.589 +  nbits = 0;
  21.590 +  while (temp) {
  21.591 +    nbits++;
  21.592 +    temp >>= 1;
  21.593 +  }
  21.594 +  /* Check for out-of-range coefficient values.
  21.595 +   * Since we're encoding a difference, the range limit is twice as much.
  21.596 +   */
  21.597 +  if (nbits > MAX_COEF_BITS+1)
  21.598 +    ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  21.599 +
  21.600 +  /* Count the Huffman symbol for the number of bits */
  21.601 +  dc_counts[nbits]++;
  21.602 +  
  21.603 +  /* Encode the AC coefficients per section F.1.2.2 */
  21.604 +  
  21.605 +  r = 0;			/* r = run length of zeros */
  21.606 +  
  21.607 +  for (k = 1; k < DCTSIZE2; k++) {
  21.608 +    if ((temp = block[jpeg_natural_order[k]]) == 0) {
  21.609 +      r++;
  21.610 +    } else {
  21.611 +      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
  21.612 +      while (r > 15) {
  21.613 +	ac_counts[0xF0]++;
  21.614 +	r -= 16;
  21.615 +      }
  21.616 +      
  21.617 +      /* Find the number of bits needed for the magnitude of the coefficient */
  21.618 +      if (temp < 0)
  21.619 +	temp = -temp;
  21.620 +      
  21.621 +      /* Find the number of bits needed for the magnitude of the coefficient */
  21.622 +      nbits = 1;		/* there must be at least one 1 bit */
  21.623 +      while ((temp >>= 1))
  21.624 +	nbits++;
  21.625 +      /* Check for out-of-range coefficient values */
  21.626 +      if (nbits > MAX_COEF_BITS)
  21.627 +	ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  21.628 +      
  21.629 +      /* Count Huffman symbol for run length / number of bits */
  21.630 +      ac_counts[(r << 4) + nbits]++;
  21.631 +      
  21.632 +      r = 0;
  21.633 +    }
  21.634 +  }
  21.635 +
  21.636 +  /* If the last coef(s) were zero, emit an end-of-block code */
  21.637 +  if (r > 0)
  21.638 +    ac_counts[0]++;
  21.639 +}
  21.640 +
  21.641 +
  21.642 +/*
  21.643 + * Trial-encode one MCU's worth of Huffman-compressed coefficients.
  21.644 + * No data is actually output, so no suspension return is possible.
  21.645 + */
  21.646 +
  21.647 +METHODDEF(boolean)
  21.648 +encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  21.649 +{
  21.650 +  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  21.651 +  int blkn, ci;
  21.652 +  jpeg_component_info * compptr;
  21.653 +
  21.654 +  /* Take care of restart intervals if needed */
  21.655 +  if (cinfo->restart_interval) {
  21.656 +    if (entropy->restarts_to_go == 0) {
  21.657 +      /* Re-initialize DC predictions to 0 */
  21.658 +      for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  21.659 +	entropy->saved.last_dc_val[ci] = 0;
  21.660 +      /* Update restart state */
  21.661 +      entropy->restarts_to_go = cinfo->restart_interval;
  21.662 +    }
  21.663 +    entropy->restarts_to_go--;
  21.664 +  }
  21.665 +
  21.666 +  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  21.667 +    ci = cinfo->MCU_membership[blkn];
  21.668 +    compptr = cinfo->cur_comp_info[ci];
  21.669 +    htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  21.670 +		    entropy->dc_count_ptrs[compptr->dc_tbl_no],
  21.671 +		    entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  21.672 +    entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  21.673 +  }
  21.674 +
  21.675 +  return TRUE;
  21.676 +}
  21.677 +
  21.678 +
  21.679 +/*
  21.680 + * Generate the best Huffman code table for the given counts, fill htbl.
  21.681 + * Note this is also used by jcphuff.c.
  21.682 + *
  21.683 + * The JPEG standard requires that no symbol be assigned a codeword of all
  21.684 + * one bits (so that padding bits added at the end of a compressed segment
  21.685 + * can't look like a valid code).  Because of the canonical ordering of
  21.686 + * codewords, this just means that there must be an unused slot in the
  21.687 + * longest codeword length category.  Section K.2 of the JPEG spec suggests
  21.688 + * reserving such a slot by pretending that symbol 256 is a valid symbol
  21.689 + * with count 1.  In theory that's not optimal; giving it count zero but
  21.690 + * including it in the symbol set anyway should give a better Huffman code.
  21.691 + * But the theoretically better code actually seems to come out worse in
  21.692 + * practice, because it produces more all-ones bytes (which incur stuffed
  21.693 + * zero bytes in the final file).  In any case the difference is tiny.
  21.694 + *
  21.695 + * The JPEG standard requires Huffman codes to be no more than 16 bits long.
  21.696 + * If some symbols have a very small but nonzero probability, the Huffman tree
  21.697 + * must be adjusted to meet the code length restriction.  We currently use
  21.698 + * the adjustment method suggested in JPEG section K.2.  This method is *not*
  21.699 + * optimal; it may not choose the best possible limited-length code.  But
  21.700 + * typically only very-low-frequency symbols will be given less-than-optimal
  21.701 + * lengths, so the code is almost optimal.  Experimental comparisons against
  21.702 + * an optimal limited-length-code algorithm indicate that the difference is
  21.703 + * microscopic --- usually less than a hundredth of a percent of total size.
  21.704 + * So the extra complexity of an optimal algorithm doesn't seem worthwhile.
  21.705 + */
  21.706 +
  21.707 +GLOBAL(void)
  21.708 +jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  21.709 +{
  21.710 +#define MAX_CLEN 32		/* assumed maximum initial code length */
  21.711 +  UINT8 bits[MAX_CLEN+1];	/* bits[k] = # of symbols with code length k */
  21.712 +  int codesize[257];		/* codesize[k] = code length of symbol k */
  21.713 +  int others[257];		/* next symbol in current branch of tree */
  21.714 +  int c1, c2;
  21.715 +  int p, i, j;
  21.716 +  long v;
  21.717 +
  21.718 +  /* This algorithm is explained in section K.2 of the JPEG standard */
  21.719 +
  21.720 +  MEMZERO(bits, SIZEOF(bits));
  21.721 +  MEMZERO(codesize, SIZEOF(codesize));
  21.722 +  for (i = 0; i < 257; i++)
  21.723 +    others[i] = -1;		/* init links to empty */
  21.724 +  
  21.725 +  freq[256] = 1;		/* make sure 256 has a nonzero count */
  21.726 +  /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
  21.727 +   * that no real symbol is given code-value of all ones, because 256
  21.728 +   * will be placed last in the largest codeword category.
  21.729 +   */
  21.730 +
  21.731 +  /* Huffman's basic algorithm to assign optimal code lengths to symbols */
  21.732 +
  21.733 +  for (;;) {
  21.734 +    /* Find the smallest nonzero frequency, set c1 = its symbol */
  21.735 +    /* In case of ties, take the larger symbol number */
  21.736 +    c1 = -1;
  21.737 +    v = 1000000000L;
  21.738 +    for (i = 0; i <= 256; i++) {
  21.739 +      if (freq[i] && freq[i] <= v) {
  21.740 +	v = freq[i];
  21.741 +	c1 = i;
  21.742 +      }
  21.743 +    }
  21.744 +
  21.745 +    /* Find the next smallest nonzero frequency, set c2 = its symbol */
  21.746 +    /* In case of ties, take the larger symbol number */
  21.747 +    c2 = -1;
  21.748 +    v = 1000000000L;
  21.749 +    for (i = 0; i <= 256; i++) {
  21.750 +      if (freq[i] && freq[i] <= v && i != c1) {
  21.751 +	v = freq[i];
  21.752 +	c2 = i;
  21.753 +      }
  21.754 +    }
  21.755 +
  21.756 +    /* Done if we've merged everything into one frequency */
  21.757 +    if (c2 < 0)
  21.758 +      break;
  21.759 +    
  21.760 +    /* Else merge the two counts/trees */
  21.761 +    freq[c1] += freq[c2];
  21.762 +    freq[c2] = 0;
  21.763 +
  21.764 +    /* Increment the codesize of everything in c1's tree branch */
  21.765 +    codesize[c1]++;
  21.766 +    while (others[c1] >= 0) {
  21.767 +      c1 = others[c1];
  21.768 +      codesize[c1]++;
  21.769 +    }
  21.770 +    
  21.771 +    others[c1] = c2;		/* chain c2 onto c1's tree branch */
  21.772 +    
  21.773 +    /* Increment the codesize of everything in c2's tree branch */
  21.774 +    codesize[c2]++;
  21.775 +    while (others[c2] >= 0) {
  21.776 +      c2 = others[c2];
  21.777 +      codesize[c2]++;
  21.778 +    }
  21.779 +  }
  21.780 +
  21.781 +  /* Now count the number of symbols of each code length */
  21.782 +  for (i = 0; i <= 256; i++) {
  21.783 +    if (codesize[i]) {
  21.784 +      /* The JPEG standard seems to think that this can't happen, */
  21.785 +      /* but I'm paranoid... */
  21.786 +      if (codesize[i] > MAX_CLEN)
  21.787 +	ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  21.788 +
  21.789 +      bits[codesize[i]]++;
  21.790 +    }
  21.791 +  }
  21.792 +
  21.793 +  /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
  21.794 +   * Huffman procedure assigned any such lengths, we must adjust the coding.
  21.795 +   * Here is what the JPEG spec says about how this next bit works:
  21.796 +   * Since symbols are paired for the longest Huffman code, the symbols are
  21.797 +   * removed from this length category two at a time.  The prefix for the pair
  21.798 +   * (which is one bit shorter) is allocated to one of the pair; then,
  21.799 +   * skipping the BITS entry for that prefix length, a code word from the next
  21.800 +   * shortest nonzero BITS entry is converted into a prefix for two code words
  21.801 +   * one bit longer.
  21.802 +   */
  21.803 +  
  21.804 +  for (i = MAX_CLEN; i > 16; i--) {
  21.805 +    while (bits[i] > 0) {
  21.806 +      j = i - 2;		/* find length of new prefix to be used */
  21.807 +      while (bits[j] == 0)
  21.808 +	j--;
  21.809 +      
  21.810 +      bits[i] -= 2;		/* remove two symbols */
  21.811 +      bits[i-1]++;		/* one goes in this length */
  21.812 +      bits[j+1] += 2;		/* two new symbols in this length */
  21.813 +      bits[j]--;		/* symbol of this length is now a prefix */
  21.814 +    }
  21.815 +  }
  21.816 +
  21.817 +  /* Remove the count for the pseudo-symbol 256 from the largest codelength */
  21.818 +  while (bits[i] == 0)		/* find largest codelength still in use */
  21.819 +    i--;
  21.820 +  bits[i]--;
  21.821 +  
  21.822 +  /* Return final symbol counts (only for lengths 0..16) */
  21.823 +  MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  21.824 +  
  21.825 +  /* Return a list of the symbols sorted by code length */
  21.826 +  /* It's not real clear to me why we don't need to consider the codelength
  21.827 +   * changes made above, but the JPEG spec seems to think this works.
  21.828 +   */
  21.829 +  p = 0;
  21.830 +  for (i = 1; i <= MAX_CLEN; i++) {
  21.831 +    for (j = 0; j <= 255; j++) {
  21.832 +      if (codesize[j] == i) {
  21.833 +	htbl->huffval[p] = (UINT8) j;
  21.834 +	p++;
  21.835 +      }
  21.836 +    }
  21.837 +  }
  21.838 +
  21.839 +  /* Set sent_table FALSE so updated table will be written to JPEG file. */
  21.840 +  htbl->sent_table = FALSE;
  21.841 +}
  21.842 +
  21.843 +
  21.844 +/*
  21.845 + * Finish up a statistics-gathering pass and create the new Huffman tables.
  21.846 + */
  21.847 +
  21.848 +METHODDEF(void)
  21.849 +finish_pass_gather (j_compress_ptr cinfo)
  21.850 +{
  21.851 +  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  21.852 +  int ci, dctbl, actbl;
  21.853 +  jpeg_component_info * compptr;
  21.854 +  JHUFF_TBL **htblptr;
  21.855 +  boolean did_dc[NUM_HUFF_TBLS];
  21.856 +  boolean did_ac[NUM_HUFF_TBLS];
  21.857 +
  21.858 +  /* It's important not to apply jpeg_gen_optimal_table more than once
  21.859 +   * per table, because it clobbers the input frequency counts!
  21.860 +   */
  21.861 +  MEMZERO(did_dc, SIZEOF(did_dc));
  21.862 +  MEMZERO(did_ac, SIZEOF(did_ac));
  21.863 +
  21.864 +  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  21.865 +    compptr = cinfo->cur_comp_info[ci];
  21.866 +    dctbl = compptr->dc_tbl_no;
  21.867 +    actbl = compptr->ac_tbl_no;
  21.868 +    if (! did_dc[dctbl]) {
  21.869 +      htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  21.870 +      if (*htblptr == NULL)
  21.871 +	*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  21.872 +      jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  21.873 +      did_dc[dctbl] = TRUE;
  21.874 +    }
  21.875 +    if (! did_ac[actbl]) {
  21.876 +      htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  21.877 +      if (*htblptr == NULL)
  21.878 +	*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  21.879 +      jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  21.880 +      did_ac[actbl] = TRUE;
  21.881 +    }
  21.882 +  }
  21.883 +}
  21.884 +
  21.885 +
  21.886 +#endif /* ENTROPY_OPT_SUPPORTED */
  21.887 +
  21.888 +
  21.889 +/*
  21.890 + * Module initialization routine for Huffman entropy encoding.
  21.891 + */
  21.892 +
  21.893 +GLOBAL(void)
  21.894 +jinit_huff_encoder (j_compress_ptr cinfo)
  21.895 +{
  21.896 +  huff_entropy_ptr entropy;
  21.897 +  int i;
  21.898 +
  21.899 +  entropy = (huff_entropy_ptr)
  21.900 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  21.901 +				SIZEOF(huff_entropy_encoder));
  21.902 +  cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  21.903 +  entropy->pub.start_pass = start_pass_huff;
  21.904 +
  21.905 +  /* Mark tables unallocated */
  21.906 +  for (i = 0; i < NUM_HUFF_TBLS; i++) {
  21.907 +    entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  21.908 +#ifdef ENTROPY_OPT_SUPPORTED
  21.909 +    entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  21.910 +#endif
  21.911 +  }
  21.912 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/libs/libjpeg/jchuff.h	Sat Sep 19 05:51:51 2015 +0300
    22.3 @@ -0,0 +1,47 @@
    22.4 +/*
    22.5 + * jchuff.h
    22.6 + *
    22.7 + * Copyright (C) 1991-1997, Thomas G. Lane.
    22.8 + * This file is part of the Independent JPEG Group's software.
    22.9 + * For conditions of distribution and use, see the accompanying README file.
   22.10 + *
   22.11 + * This file contains declarations for Huffman entropy encoding routines
   22.12 + * that are shared between the sequential encoder (jchuff.c) and the
   22.13 + * progressive encoder (jcphuff.c).  No other modules need to see these.
   22.14 + */
   22.15 +
   22.16 +/* The legal range of a DCT coefficient is
   22.17 + *  -1024 .. +1023  for 8-bit data;
   22.18 + * -16384 .. +16383 for 12-bit data.
   22.19 + * Hence the magnitude should always fit in 10 or 14 bits respectively.
   22.20 + */
   22.21 +
   22.22 +#if BITS_IN_JSAMPLE == 8
   22.23 +#define MAX_COEF_BITS 10
   22.24 +#else
   22.25 +#define MAX_COEF_BITS 14
   22.26 +#endif
   22.27 +
   22.28 +/* Derived data constructed for each Huffman table */
   22.29 +
   22.30 +typedef struct {
   22.31 +  unsigned int ehufco[256];	/* code for each symbol */
   22.32 +  char ehufsi[256];		/* length of code for each symbol */
   22.33 +  /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
   22.34 +} c_derived_tbl;
   22.35 +
   22.36 +/* Short forms of external names for systems with brain-damaged linkers. */
   22.37 +
   22.38 +#ifdef NEED_SHORT_EXTERNAL_NAMES
   22.39 +#define jpeg_make_c_derived_tbl	jMkCDerived
   22.40 +#define jpeg_gen_optimal_table	jGenOptTbl
   22.41 +#endif /* NEED_SHORT_EXTERNAL_NAMES */
   22.42 +
   22.43 +/* Expand a Huffman table definition into the derived format */
   22.44 +EXTERN(void) jpeg_make_c_derived_tbl
   22.45 +	JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
   22.46 +	     c_derived_tbl ** pdtbl));
   22.47 +
   22.48 +/* Generate an optimal table definition given the specified counts */
   22.49 +EXTERN(void) jpeg_gen_optimal_table
   22.50 +	JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/libs/libjpeg/jcinit.c	Sat Sep 19 05:51:51 2015 +0300
    23.3 @@ -0,0 +1,72 @@
    23.4 +/*
    23.5 + * jcinit.c
    23.6 + *
    23.7 + * Copyright (C) 1991-1997, Thomas G. Lane.
    23.8 + * This file is part of the Independent JPEG Group's software.
    23.9 + * For conditions of distribution and use, see the accompanying README file.
   23.10 + *
   23.11 + * This file contains initialization logic for the JPEG compressor.
   23.12 + * This routine is in charge of selecting the modules to be executed and
   23.13 + * making an initialization call to each one.
   23.14 + *
   23.15 + * Logically, this code belongs in jcmaster.c.  It's split out because
   23.16 + * linking this routine implies linking the entire compression library.
   23.17 + * For a transcoding-only application, we want to be able to use jcmaster.c
   23.18 + * without linking in the whole library.
   23.19 + */
   23.20 +
   23.21 +#define JPEG_INTERNALS
   23.22 +#include "jinclude.h"
   23.23 +#include "jpeglib.h"
   23.24 +
   23.25 +
   23.26 +/*
   23.27 + * Master selection of compression modules.
   23.28 + * This is done once at the start of processing an image.  We determine
   23.29 + * which modules will be used and give them appropriate initialization calls.
   23.30 + */
   23.31 +
   23.32 +GLOBAL(void)
   23.33 +jinit_compress_master (j_compress_ptr cinfo)
   23.34 +{
   23.35 +  /* Initialize master control (includes parameter checking/processing) */
   23.36 +  jinit_c_master_control(cinfo, FALSE /* full compression */);
   23.37 +
   23.38 +  /* Preprocessing */
   23.39 +  if (! cinfo->raw_data_in) {
   23.40 +    jinit_color_converter(cinfo);
   23.41 +    jinit_downsampler(cinfo);
   23.42 +    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
   23.43 +  }
   23.44 +  /* Forward DCT */
   23.45 +  jinit_forward_dct(cinfo);
   23.46 +  /* Entropy encoding: either Huffman or arithmetic coding. */
   23.47 +  if (cinfo->arith_code) {
   23.48 +    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
   23.49 +  } else {
   23.50 +    if (cinfo->progressive_mode) {
   23.51 +#ifdef C_PROGRESSIVE_SUPPORTED
   23.52 +      jinit_phuff_encoder(cinfo);
   23.53 +#else
   23.54 +      ERREXIT(cinfo, JERR_NOT_COMPILED);
   23.55 +#endif
   23.56 +    } else
   23.57 +      jinit_huff_encoder(cinfo);
   23.58 +  }
   23.59 +
   23.60 +  /* Need a full-image coefficient buffer in any multi-pass mode. */
   23.61 +  jinit_c_coef_controller(cinfo,
   23.62 +		(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
   23.63 +  jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
   23.64 +
   23.65 +  jinit_marker_writer(cinfo);
   23.66 +
   23.67 +  /* We can now tell the memory manager to allocate virtual arrays. */
   23.68 +  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
   23.69 +
   23.70 +  /* Write the datastream header (SOI) immediately.
   23.71 +   * Frame and scan headers are postponed till later.
   23.72 +   * This lets application insert special markers after the SOI.
   23.73 +   */
   23.74 +  (*cinfo->marker->write_file_header) (cinfo);
   23.75 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/libs/libjpeg/jcmainct.c	Sat Sep 19 05:51:51 2015 +0300
    24.3 @@ -0,0 +1,293 @@
    24.4 +/*
    24.5 + * jcmainct.c
    24.6 + *
    24.7 + * Copyright (C) 1994-1996, Thomas G. Lane.
    24.8 + * This file is part of the Independent JPEG Group's software.
    24.9 + * For conditions of distribution and use, see the accompanying README file.
   24.10 + *
   24.11 + * This file contains the main buffer controller for compression.
   24.12 + * The main buffer lies between the pre-processor and the JPEG
   24.13 + * compressor proper; it holds downsampled data in the JPEG colorspace.
   24.14 + */
   24.15 +
   24.16 +#define JPEG_INTERNALS
   24.17 +#include "jinclude.h"
   24.18 +#include "jpeglib.h"
   24.19 +
   24.20 +
   24.21 +/* Note: currently, there is no operating mode in which a full-image buffer
   24.22 + * is needed at this step.  If there were, that mode could not be used with
   24.23 + * "raw data" input, since this module is bypassed in that case.  However,
   24.24 + * we've left the code here for possible use in special applications.
   24.25 + */
   24.26 +#undef FULL_MAIN_BUFFER_SUPPORTED
   24.27 +
   24.28 +
   24.29 +/* Private buffer controller object */
   24.30 +
   24.31 +typedef struct {
   24.32 +  struct jpeg_c_main_controller pub; /* public fields */
   24.33 +
   24.34 +  JDIMENSION cur_iMCU_row;	/* number of current iMCU row */
   24.35 +  JDIMENSION rowgroup_ctr;	/* counts row groups received in iMCU row */
   24.36 +  boolean suspended;		/* remember if we suspended output */
   24.37 +  J_BUF_MODE pass_mode;		/* current operating mode */
   24.38 +
   24.39 +  /* If using just a strip buffer, this points to the entire set of buffers
   24.40 +   * (we allocate one for each component).  In the full-image case, this
   24.41 +   * points to the currently accessible strips of the virtual arrays.
   24.42 +   */
   24.43 +  JSAMPARRAY buffer[MAX_COMPONENTS];
   24.44 +
   24.45 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
   24.46 +  /* If using full-image storage, this array holds pointers to virtual-array
   24.47 +   * control blocks for each component.  Unused if not full-image storage.
   24.48 +   */
   24.49 +  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
   24.50 +#endif
   24.51 +} my_main_controller;
   24.52 +
   24.53 +typedef my_main_controller * my_main_ptr;
   24.54 +
   24.55 +
   24.56 +/* Forward declarations */
   24.57 +METHODDEF(void) process_data_simple_main
   24.58 +	JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
   24.59 +	     JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
   24.60 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
   24.61 +METHODDEF(void) process_data_buffer_main
   24.62 +	JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
   24.63 +	     JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
   24.64 +#endif
   24.65 +
   24.66 +
   24.67 +/*
   24.68 + * Initialize for a processing pass.
   24.69 + */
   24.70 +
   24.71 +METHODDEF(void)
   24.72 +start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
   24.73 +{
   24.74 +  my_main_ptr main = (my_main_ptr) cinfo->main;
   24.75 +
   24.76 +  /* Do nothing in raw-data mode. */
   24.77 +  if (cinfo->raw_data_in)
   24.78 +    return;
   24.79 +
   24.80 +  main->cur_iMCU_row = 0;	/* initialize counters */
   24.81 +  main->rowgroup_ctr = 0;
   24.82 +  main->suspended = FALSE;
   24.83 +  main->pass_mode = pass_mode;	/* save mode for use by process_data */
   24.84 +
   24.85 +  switch (pass_mode) {
   24.86 +  case JBUF_PASS_THRU:
   24.87 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
   24.88 +    if (main->whole_image[0] != NULL)
   24.89 +      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
   24.90 +#endif
   24.91 +    main->pub.process_data = process_data_simple_main;
   24.92 +    break;
   24.93 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
   24.94 +  case JBUF_SAVE_SOURCE:
   24.95 +  case JBUF_CRANK_DEST:
   24.96 +  case JBUF_SAVE_AND_PASS:
   24.97 +    if (main->whole_image[0] == NULL)
   24.98 +      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
   24.99 +    main->pub.process_data = process_data_buffer_main;
  24.100 +    break;
  24.101 +#endif
  24.102 +  default:
  24.103 +    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  24.104 +    break;
  24.105 +  }
  24.106 +}
  24.107 +
  24.108 +
  24.109 +/*
  24.110 + * Process some data.
  24.111 + * This routine handles the simple pass-through mode,
  24.112 + * where we have only a strip buffer.
  24.113 + */
  24.114 +
  24.115 +METHODDEF(void)
  24.116 +process_data_simple_main (j_compress_ptr cinfo,
  24.117 +			  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  24.118 +			  JDIMENSION in_rows_avail)
  24.119 +{
  24.120 +  my_main_ptr main = (my_main_ptr) cinfo->main;
  24.121 +
  24.122 +  while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  24.123 +    /* Read input data if we haven't filled the main buffer yet */
  24.124 +    if (main->rowgroup_ctr < DCTSIZE)
  24.125 +      (*cinfo->prep->pre_process_data) (cinfo,
  24.126 +					input_buf, in_row_ctr, in_rows_avail,
  24.127 +					main->buffer, &main->rowgroup_ctr,
  24.128 +					(JDIMENSION) DCTSIZE);
  24.129 +
  24.130 +    /* If we don't have a full iMCU row buffered, return to application for
  24.131 +     * more data.  Note that preprocessor will always pad to fill the iMCU row
  24.132 +     * at the bottom of the image.
  24.133 +     */
  24.134 +    if (main->rowgroup_ctr != DCTSIZE)
  24.135 +      return;
  24.136 +
  24.137 +    /* Send the completed row to the compressor */
  24.138 +    if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  24.139 +      /* If compressor did not consume the whole row, then we must need to
  24.140 +       * suspend processing and return to the application.  In this situation
  24.141 +       * we pretend we didn't yet consume the last input row; otherwise, if
  24.142 +       * it happened to be the last row of the image, the application would
  24.143 +       * think we were done.
  24.144 +       */
  24.145 +      if (! main->suspended) {
  24.146 +	(*in_row_ctr)--;
  24.147 +	main->suspended = TRUE;
  24.148 +      }
  24.149 +      return;
  24.150 +    }
  24.151 +    /* We did finish the row.  Undo our little suspension hack if a previous
  24.152 +     * call suspended; then mark the main buffer empty.
  24.153 +     */
  24.154 +    if (main->suspended) {
  24.155 +      (*in_row_ctr)++;
  24.156 +      main->suspended = FALSE;
  24.157 +    }
  24.158 +    main->rowgroup_ctr = 0;
  24.159 +    main->cur_iMCU_row++;
  24.160 +  }
  24.161 +}
  24.162 +
  24.163 +
  24.164 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
  24.165 +
  24.166 +/*
  24.167 + * Process some data.
  24.168 + * This routine handles all of the modes that use a full-size buffer.
  24.169 + */
  24.170 +
  24.171 +METHODDEF(void)
  24.172 +process_data_buffer_main (j_compress_ptr cinfo,
  24.173 +			  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  24.174 +			  JDIMENSION in_rows_avail)
  24.175 +{
  24.176 +  my_main_ptr main = (my_main_ptr) cinfo->main;
  24.177 +  int ci;
  24.178 +  jpeg_component_info *compptr;
  24.179 +  boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  24.180 +
  24.181 +  while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  24.182 +    /* Realign the virtual buffers if at the start of an iMCU row. */
  24.183 +    if (main->rowgroup_ctr == 0) {
  24.184 +      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  24.185 +	   ci++, compptr++) {
  24.186 +	main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  24.187 +	  ((j_common_ptr) cinfo, main->whole_image[ci],
  24.188 +	   main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  24.189 +	   (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  24.190 +      }
  24.191 +      /* In a read pass, pretend we just read some source data. */
  24.192 +      if (! writing) {
  24.193 +	*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  24.194 +	main->rowgroup_ctr = DCTSIZE;
  24.195 +      }
  24.196 +    }
  24.197 +
  24.198 +    /* If a write pass, read input data until the current iMCU row is full. */
  24.199 +    /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
  24.200 +    if (writing) {
  24.201 +      (*cinfo->prep->pre_process_data) (cinfo,
  24.202 +					input_buf, in_row_ctr, in_rows_avail,
  24.203 +					main->buffer, &main->rowgroup_ctr,
  24.204 +					(JDIMENSION) DCTSIZE);
  24.205 +      /* Return to application if we need more data to fill the iMCU row. */
  24.206 +      if (main->rowgroup_ctr < DCTSIZE)
  24.207 +	return;
  24.208 +    }
  24.209 +
  24.210 +    /* Emit data, unless this is a sink-only pass. */
  24.211 +    if (main->pass_mode != JBUF_SAVE_SOURCE) {
  24.212 +      if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  24.213 +	/* If compressor did not consume the whole row, then we must need to
  24.214 +	 * suspend processing and return to the application.  In this situation
  24.215 +	 * we pretend we didn't yet consume the last input row; otherwise, if
  24.216 +	 * it happened to be the last row of the image, the application would
  24.217 +	 * think we were done.
  24.218 +	 */
  24.219 +	if (! main->suspended) {
  24.220 +	  (*in_row_ctr)--;
  24.221 +	  main->suspended = TRUE;
  24.222 +	}
  24.223 +	return;
  24.224 +      }
  24.225 +      /* We did finish the row.  Undo our little suspension hack if a previous
  24.226 +       * call suspended; then mark the main buffer empty.
  24.227 +       */
  24.228 +      if (main->suspended) {
  24.229 +	(*in_row_ctr)++;
  24.230 +	main->suspended = FALSE;
  24.231 +      }
  24.232 +    }
  24.233 +
  24.234 +    /* If get here, we are done with this iMCU row.  Mark buffer empty. */
  24.235 +    main->rowgroup_ctr = 0;
  24.236 +    main->cur_iMCU_row++;
  24.237 +  }
  24.238 +}
  24.239 +
  24.240 +#endif /* FULL_MAIN_BUFFER_SUPPORTED */
  24.241 +
  24.242 +
  24.243 +/*
  24.244 + * Initialize main buffer controller.
  24.245 + */
  24.246 +
  24.247 +GLOBAL(void)
  24.248 +jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  24.249 +{
  24.250 +  my_main_ptr main;
  24.251 +  int ci;
  24.252 +  jpeg_component_info *compptr;
  24.253 +
  24.254 +  main = (my_main_ptr)
  24.255 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  24.256 +				SIZEOF(my_main_controller));
  24.257 +  cinfo->main = (struct jpeg_c_main_controller *) main;
  24.258 +  main->pub.start_pass = start_pass_main;
  24.259 +
  24.260 +  /* We don't need to create a buffer in raw-data mode. */
  24.261 +  if (cinfo->raw_data_in)
  24.262 +    return;
  24.263 +
  24.264 +  /* Create the buffer.  It holds downsampled data, so each component
  24.265 +   * may be of a different size.
  24.266 +   */
  24.267 +  if (need_full_buffer) {
  24.268 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
  24.269 +    /* Allocate a full-image virtual array for each component */
  24.270 +    /* Note we pad the bottom to a multiple of the iMCU height */
  24.271 +    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  24.272 +	 ci++, compptr++) {
  24.273 +      main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  24.274 +	((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  24.275 +	 compptr->width_in_blocks * DCTSIZE,
  24.276 +	 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  24.277 +				(long) compptr->v_samp_factor) * DCTSIZE,
  24.278 +	 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  24.279 +    }
  24.280 +#else
  24.281 +    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  24.282 +#endif
  24.283 +  } else {
  24.284 +#ifdef FULL_MAIN_BUFFER_SUPPORTED
  24.285 +    main->whole_image[0] = NULL; /* flag for no virtual arrays */
  24.286 +#endif
  24.287 +    /* Allocate a strip buffer for each component */
  24.288 +    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  24.289 +	 ci++, compptr++) {
  24.290 +      main->buffer[ci] = (*cinfo->mem->alloc_sarray)
  24.291 +	((j_common_ptr) cinfo, JPOOL_IMAGE,
  24.292 +	 compptr->width_in_blocks * DCTSIZE,
  24.293 +	 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  24.294 +    }
  24.295 +  }
  24.296 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/libs/libjpeg/jcmarker.c	Sat Sep 19 05:51:51 2015 +0300
    25.3 @@ -0,0 +1,664 @@
    25.4 +/*
    25.5 + * jcmarker.c
    25.6 + *
    25.7 + * Copyright (C) 1991-1998, Thomas G. Lane.
    25.8 + * This file is part of the Independent JPEG Group's software.
    25.9 + * For conditions of distribution and use, see the accompanying README file.
   25.10 + *
   25.11 + * This file contains routines to write JPEG datastream markers.
   25.12 + */
   25.13 +
   25.14 +#define JPEG_INTERNALS
   25.15 +#include "jinclude.h"
   25.16 +#include "jpeglib.h"
   25.17 +
   25.18 +
   25.19 +typedef enum {			/* JPEG marker codes */
   25.20 +  M_SOF0  = 0xc0,
   25.21 +  M_SOF1  = 0xc1,
   25.22 +  M_SOF2  = 0xc2,
   25.23 +  M_SOF3  = 0xc3,
   25.24 +  
   25.25 +  M_SOF5  = 0xc5,
   25.26 +  M_SOF6  = 0xc6,
   25.27 +  M_SOF7  = 0xc7,
   25.28 +  
   25.29 +  M_JPG   = 0xc8,
   25.30 +  M_SOF9  = 0xc9,
   25.31 +  M_SOF10 = 0xca,
   25.32 +  M_SOF11 = 0xcb,
   25.33 +  
   25.34 +  M_SOF13 = 0xcd,
   25.35 +  M_SOF14 = 0xce,
   25.36 +  M_SOF15 = 0xcf,
   25.37 +  
   25.38 +  M_DHT   = 0xc4,
   25.39 +  
   25.40 +  M_DAC   = 0xcc,
   25.41 +  
   25.42 +  M_RST0  = 0xd0,
   25.43 +  M_RST1  = 0xd1,
   25.44 +  M_RST2  = 0xd2,
   25.45 +  M_RST3  = 0xd3,
   25.46 +  M_RST4  = 0xd4,
   25.47 +  M_RST5  = 0xd5,
   25.48 +  M_RST6  = 0xd6,
   25.49 +  M_RST7  = 0xd7,
   25.50 +  
   25.51 +  M_SOI   = 0xd8,
   25.52 +  M_EOI   = 0xd9,
   25.53 +  M_SOS   = 0xda,
   25.54 +  M_DQT   = 0xdb,
   25.55 +  M_DNL   = 0xdc,
   25.56 +  M_DRI   = 0xdd,
   25.57 +  M_DHP   = 0xde,
   25.58 +  M_EXP   = 0xdf,
   25.59 +  
   25.60 +  M_APP0  = 0xe0,
   25.61 +  M_APP1  = 0xe1,
   25.62 +  M_APP2  = 0xe2,
   25.63 +  M_APP3  = 0xe3,
   25.64 +  M_APP4  = 0xe4,
   25.65 +  M_APP5  = 0xe5,
   25.66 +  M_APP6  = 0xe6,
   25.67 +  M_APP7  = 0xe7,
   25.68 +  M_APP8  = 0xe8,
   25.69 +  M_APP9  = 0xe9,
   25.70 +  M_APP10 = 0xea,
   25.71 +  M_APP11 = 0xeb,
   25.72 +  M_APP12 = 0xec,
   25.73 +  M_APP13 = 0xed,
   25.74 +  M_APP14 = 0xee,
   25.75 +  M_APP15 = 0xef,
   25.76 +  
   25.77 +  M_JPG0  = 0xf0,
   25.78 +  M_JPG13 = 0xfd,
   25.79 +  M_COM   = 0xfe,
   25.80 +  
   25.81 +  M_TEM   = 0x01,
   25.82 +  
   25.83 +  M_ERROR = 0x100
   25.84 +} JPEG_MARKER;
   25.85 +
   25.86 +
   25.87 +/* Private state */
   25.88 +
   25.89 +typedef struct {
   25.90 +  struct jpeg_marker_writer pub; /* public fields */
   25.91 +
   25.92 +  unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
   25.93 +} my_marker_writer;
   25.94 +
   25.95 +typedef my_marker_writer * my_marker_ptr;
   25.96 +
   25.97 +
   25.98 +/*
   25.99 + * Basic output routines.
  25.100 + *
  25.101 + * Note that we do not support suspension while writing a marker.
  25.102 + * Therefore, an application using suspension must ensure that there is
  25.103 + * enough buffer space for the initial markers (typ. 600-700 bytes) before
  25.104 + * calling jpeg_start_compress, and enough space to write the trailing EOI
  25.105 + * (a few bytes) before calling jpeg_finish_compress.  Multipass compression
  25.106 + * modes are not supported at all with suspension, so those two are the only
  25.107 + * points where markers will be written.
  25.108 + */
  25.109 +
  25.110 +LOCAL(void)
  25.111 +emit_byte (j_compress_ptr cinfo, int val)
  25.112 +/* Emit a byte */
  25.113 +{
  25.114 +  struct jpeg_destination_mgr * dest = cinfo->dest;
  25.115 +
  25.116 +  *(dest->next_output_byte)++ = (JOCTET) val;
  25.117 +  if (--dest->free_in_buffer == 0) {
  25.118 +    if (! (*dest->empty_output_buffer) (cinfo))
  25.119 +      ERREXIT(cinfo, JERR_CANT_SUSPEND);
  25.120 +  }
  25.121 +}
  25.122 +
  25.123 +
  25.124 +LOCAL(void)
  25.125 +emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  25.126 +/* Emit a marker code */
  25.127 +{
  25.128 +  emit_byte(cinfo, 0xFF);
  25.129 +  emit_byte(cinfo, (int) mark);
  25.130 +}
  25.131 +
  25.132 +
  25.133 +LOCAL(void)
  25.134 +emit_2bytes (j_compress_ptr cinfo, int value)
  25.135 +/* Emit a 2-byte integer; these are always MSB first in JPEG files */
  25.136 +{
  25.137 +  emit_byte(cinfo, (value >> 8) & 0xFF);
  25.138 +  emit_byte(cinfo, value & 0xFF);
  25.139 +}
  25.140 +
  25.141 +
  25.142 +/*
  25.143 + * Routines to write specific marker types.
  25.144 + */
  25.145 +
  25.146 +LOCAL(int)
  25.147 +emit_dqt (j_compress_ptr cinfo, int index)
  25.148 +/* Emit a DQT marker */
  25.149 +/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
  25.150 +{
  25.151 +  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  25.152 +  int prec;
  25.153 +  int i;
  25.154 +
  25.155 +  if (qtbl == NULL)
  25.156 +    ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  25.157 +
  25.158 +  prec = 0;
  25.159 +  for (i = 0; i < DCTSIZE2; i++) {
  25.160 +    if (qtbl->quantval[i] > 255)
  25.161 +      prec = 1;
  25.162 +  }
  25.163 +
  25.164 +  if (! qtbl->sent_table) {
  25.165 +    emit_marker(cinfo, M_DQT);
  25.166 +
  25.167 +    emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  25.168 +
  25.169 +    emit_byte(cinfo, index + (prec<<4));
  25.170 +
  25.171 +    for (i = 0; i < DCTSIZE2; i++) {
  25.172 +      /* The table entries must be emitted in zigzag order. */
  25.173 +      unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  25.174 +      if (prec)
  25.175 +	emit_byte(cinfo, (int) (qval >> 8));
  25.176 +      emit_byte(cinfo, (int) (qval & 0xFF));
  25.177 +    }
  25.178 +
  25.179 +    qtbl->sent_table = TRUE;
  25.180 +  }
  25.181 +
  25.182 +  return prec;
  25.183 +}
  25.184 +
  25.185 +
  25.186 +LOCAL(void)
  25.187 +emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  25.188 +/* Emit a DHT marker */
  25.189 +{
  25.190 +  JHUFF_TBL * htbl;
  25.191 +  int length, i;
  25.192 +  
  25.193 +  if (is_ac) {
  25.194 +    htbl = cinfo->ac_huff_tbl_ptrs[index];
  25.195 +    index += 0x10;		/* output index has AC bit set */
  25.196 +  } else {
  25.197 +    htbl = cinfo->dc_huff_tbl_ptrs[index];
  25.198 +  }
  25.199 +
  25.200 +  if (htbl == NULL)
  25.201 +    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  25.202 +  
  25.203 +  if (! htbl->sent_table) {
  25.204 +    emit_marker(cinfo, M_DHT);
  25.205 +    
  25.206 +    length = 0;
  25.207 +    for (i = 1; i <= 16; i++)
  25.208 +      length += htbl->bits[i];
  25.209 +    
  25.210 +    emit_2bytes(cinfo, length + 2 + 1 + 16);
  25.211 +    emit_byte(cinfo, index);
  25.212 +    
  25.213 +    for (i = 1; i <= 16; i++)
  25.214 +      emit_byte(cinfo, htbl->bits[i]);
  25.215 +    
  25.216 +    for (i = 0; i < length; i++)
  25.217 +      emit_byte(cinfo, htbl->huffval[i]);
  25.218 +    
  25.219 +    htbl->sent_table = TRUE;
  25.220 +  }
  25.221 +}
  25.222 +
  25.223 +
  25.224 +LOCAL(void)
  25.225 +emit_dac (j_compress_ptr cinfo)
  25.226 +/* Emit a DAC marker */
  25.227 +/* Since the useful info is so small, we want to emit all the tables in */
  25.228 +/* one DAC marker.  Therefore this routine does its own scan of the table. */
  25.229 +{
  25.230 +#ifdef C_ARITH_CODING_SUPPORTED
  25.231 +  char dc_in_use[NUM_ARITH_TBLS];
  25.232 +  char ac_in_use[NUM_ARITH_TBLS];
  25.233 +  int length, i;
  25.234 +  jpeg_component_info *compptr;
  25.235 +  
  25.236 +  for (i = 0; i < NUM_ARITH_TBLS; i++)
  25.237 +    dc_in_use[i] = ac_in_use[i] = 0;
  25.238 +  
  25.239 +  for (i = 0; i < cinfo->comps_in_scan; i++) {
  25.240 +    compptr = cinfo->cur_comp_info[i];
  25.241 +    dc_in_use[compptr->dc_tbl_no] = 1;
  25.242 +    ac_in_use[compptr->ac_tbl_no] = 1;
  25.243 +  }
  25.244 +  
  25.245 +  length = 0;
  25.246 +  for (i = 0; i < NUM_ARITH_TBLS; i++)
  25.247 +    length += dc_in_use[i] + ac_in_use[i];
  25.248 +  
  25.249 +  emit_marker(cinfo, M_DAC);
  25.250 +  
  25.251 +  emit_2bytes(cinfo, length*2 + 2);
  25.252 +  
  25.253 +  for (i = 0; i < NUM_ARITH_TBLS; i++) {
  25.254 +    if (dc_in_use[i]) {
  25.255 +      emit_byte(cinfo, i);
  25.256 +      emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  25.257 +    }
  25.258 +    if (ac_in_use[i]) {
  25.259 +      emit_byte(cinfo, i + 0x10);
  25.260 +      emit_byte(cinfo, cinfo->arith_ac_K[i]);
  25.261 +    }
  25.262 +  }
  25.263 +#endif /* C_ARITH_CODING_SUPPORTED */
  25.264 +}
  25.265 +
  25.266 +
  25.267 +LOCAL(void)
  25.268 +emit_dri (j_compress_ptr cinfo)
  25.269 +/* Emit a DRI marker */
  25.270 +{
  25.271 +  emit_marker(cinfo, M_DRI);
  25.272 +  
  25.273 +  emit_2bytes(cinfo, 4);	/* fixed length */
  25.274 +
  25.275 +  emit_2bytes(cinfo, (int) cinfo->restart_interval);
  25.276 +}
  25.277 +
  25.278 +
  25.279 +LOCAL(void)
  25.280 +emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  25.281 +/* Emit a SOF marker */
  25.282 +{
  25.283 +  int ci;
  25.284 +  jpeg_component_info *compptr;
  25.285 +  
  25.286 +  emit_marker(cinfo, code);
  25.287 +  
  25.288 +  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  25.289 +
  25.290 +  /* Make sure image isn't bigger than SOF field can handle */
  25.291 +  if ((long) cinfo->image_height > 65535L ||
  25.292 +      (long) cinfo->image_width > 65535L)
  25.293 +    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  25.294 +
  25.295 +  emit_byte(cinfo, cinfo->data_precision);
  25.296 +  emit_2bytes(cinfo, (int) cinfo->image_height);
  25.297 +  emit_2bytes(cinfo, (int) cinfo->image_width);
  25.298 +
  25.299 +  emit_byte(cinfo, cinfo->num_components);
  25.300 +
  25.301 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  25.302 +       ci++, compptr++) {
  25.303 +    emit_byte(cinfo, compptr->component_id);
  25.304 +    emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  25.305 +    emit_byte(cinfo, compptr->quant_tbl_no);
  25.306 +  }
  25.307 +}
  25.308 +
  25.309 +
  25.310 +LOCAL(void)
  25.311 +emit_sos (j_compress_ptr cinfo)
  25.312 +/* Emit a SOS marker */
  25.313 +{
  25.314 +  int i, td, ta;
  25.315 +  jpeg_component_info *compptr;
  25.316 +  
  25.317 +  emit_marker(cinfo, M_SOS);
  25.318 +  
  25.319 +  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  25.320 +  
  25.321 +  emit_byte(cinfo, cinfo->comps_in_scan);
  25.322 +  
  25.323 +  for (i = 0; i < cinfo->comps_in_scan; i++) {
  25.324 +    compptr = cinfo->cur_comp_info[i];
  25.325 +    emit_byte(cinfo, compptr->component_id);
  25.326 +    td = compptr->dc_tbl_no;
  25.327 +    ta = compptr->ac_tbl_no;
  25.328 +    if (cinfo->progressive_mode) {
  25.329 +      /* Progressive mode: only DC or only AC tables are used in one scan;
  25.330 +       * furthermore, Huffman coding of DC refinement uses no table at all.
  25.331 +       * We emit 0 for unused field(s); this is recommended by the P&M text
  25.332 +       * but does not seem to be specified in the standard.
  25.333 +       */
  25.334 +      if (cinfo->Ss == 0) {
  25.335 +	ta = 0;			/* DC scan */
  25.336 +	if (cinfo->Ah != 0 && !cinfo->arith_code)
  25.337 +	  td = 0;		/* no DC table either */
  25.338 +      } else {
  25.339 +	td = 0;			/* AC scan */
  25.340 +      }
  25.341 +    }
  25.342 +    emit_byte(cinfo, (td << 4) + ta);
  25.343 +  }
  25.344 +
  25.345 +  emit_byte(cinfo, cinfo->Ss);
  25.346 +  emit_byte(cinfo, cinfo->Se);
  25.347 +  emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  25.348 +}
  25.349 +
  25.350 +
  25.351 +LOCAL(void)
  25.352 +emit_jfif_app0 (j_compress_ptr cinfo)
  25.353 +/* Emit a JFIF-compliant APP0 marker */
  25.354 +{
  25.355 +  /*
  25.356 +   * Length of APP0 block	(2 bytes)
  25.357 +   * Block ID			(4 bytes - ASCII "JFIF")
  25.358 +   * Zero byte			(1 byte to terminate the ID string)
  25.359 +   * Version Major, Minor	(2 bytes - major first)
  25.360 +   * Units			(1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
  25.361 +   * Xdpu			(2 bytes - dots per unit horizontal)
  25.362 +   * Ydpu			(2 bytes - dots per unit vertical)
  25.363 +   * Thumbnail X size		(1 byte)
  25.364 +   * Thumbnail Y size		(1 byte)
  25.365 +   */
  25.366 +  
  25.367 +  emit_marker(cinfo, M_APP0);
  25.368 +  
  25.369 +  emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  25.370 +
  25.371 +  emit_byte(cinfo, 0x4A);	/* Identifier: ASCII "JFIF" */
  25.372 +  emit_byte(cinfo, 0x46);
  25.373 +  emit_byte(cinfo, 0x49);
  25.374 +  emit_byte(cinfo, 0x46);
  25.375 +  emit_byte(cinfo, 0);
  25.376 +  emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  25.377 +  emit_byte(cinfo, cinfo->JFIF_minor_version);
  25.378 +  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  25.379 +  emit_2bytes(cinfo, (int) cinfo->X_density);
  25.380 +  emit_2bytes(cinfo, (int) cinfo->Y_density);
  25.381 +  emit_byte(cinfo, 0);		/* No thumbnail image */
  25.382 +  emit_byte(cinfo, 0);
  25.383 +}
  25.384 +
  25.385 +
  25.386 +LOCAL(void)
  25.387 +emit_adobe_app14 (j_compress_ptr cinfo)
  25.388 +/* Emit an Adobe APP14 marker */
  25.389 +{
  25.390 +  /*
  25.391 +   * Length of APP14 block	(2 bytes)
  25.392 +   * Block ID			(5 bytes - ASCII "Adobe")
  25.393 +   * Version Number		(2 bytes - currently 100)
  25.394 +   * Flags0			(2 bytes - currently 0)
  25.395 +   * Flags1			(2 bytes - currently 0)
  25.396 +   * Color transform		(1 byte)
  25.397 +   *
  25.398 +   * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
  25.399 +   * now in circulation seem to use Version = 100, so that's what we write.
  25.400 +   *
  25.401 +   * We write the color transform byte as 1 if the JPEG color space is
  25.402 +   * YCbCr, 2 if it's YCCK, 0 otherwise.  Adobe's definition has to do with
  25.403 +   * whether the encoder performed a transformation, which is pretty useless.
  25.404 +   */
  25.405 +  
  25.406 +  emit_marker(cinfo, M_APP14);
  25.407 +  
  25.408 +  emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  25.409 +
  25.410 +  emit_byte(cinfo, 0x41);	/* Identifier: ASCII "Adobe" */
  25.411 +  emit_byte(cinfo, 0x64);
  25.412 +  emit_byte(cinfo, 0x6F);
  25.413 +  emit_byte(cinfo, 0x62);
  25.414 +  emit_byte(cinfo, 0x65);
  25.415 +  emit_2bytes(cinfo, 100);	/* Version */
  25.416 +  emit_2bytes(cinfo, 0);	/* Flags0 */
  25.417 +  emit_2bytes(cinfo, 0);	/* Flags1 */
  25.418 +  switch (cinfo->jpeg_color_space) {
  25.419 +  case JCS_YCbCr:
  25.420 +    emit_byte(cinfo, 1);	/* Color transform = 1 */
  25.421 +    break;
  25.422 +  case JCS_YCCK:
  25.423 +    emit_byte(cinfo, 2);	/* Color transform = 2 */
  25.424 +    break;
  25.425 +  default:
  25.426 +    emit_byte(cinfo, 0);	/* Color transform = 0 */
  25.427 +    break;
  25.428 +  }
  25.429 +}
  25.430 +
  25.431 +
  25.432 +/*
  25.433 + * These routines allow writing an arbitrary marker with parameters.
  25.434 + * The only intended use is to emit COM or APPn markers after calling
  25.435 + * write_file_header and before calling write_frame_header.
  25.436 + * Other uses are not guaranteed to produce desirable results.
  25.437 + * Counting the parameter bytes properly is the caller's responsibility.
  25.438 + */
  25.439 +
  25.440 +METHODDEF(void)
  25.441 +write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  25.442 +/* Emit an arbitrary marker header */
  25.443 +{
  25.444 +  if (datalen > (unsigned int) 65533)		/* safety check */
  25.445 +    ERREXIT(cinfo, JERR_BAD_LENGTH);
  25.446 +
  25.447 +  emit_marker(cinfo, (JPEG_MARKER) marker);
  25.448 +
  25.449 +  emit_2bytes(cinfo, (int) (datalen + 2));	/* total length */
  25.450 +}
  25.451 +
  25.452 +METHODDEF(void)
  25.453 +write_marker_byte (j_compress_ptr cinfo, int val)
  25.454 +/* Emit one byte of marker parameters following write_marker_header */
  25.455 +{
  25.456 +  emit_byte(cinfo, val);
  25.457 +}
  25.458 +
  25.459 +
  25.460 +/*
  25.461 + * Write datastream header.
  25.462 + * This consists of an SOI and optional APPn markers.
  25.463 + * We recommend use of the JFIF marker, but not the Adobe marker,
  25.464 + * when using YCbCr or grayscale data.  The JFIF marker should NOT
  25.465 + * be used for any other JPEG colorspace.  The Adobe marker is helpful
  25.466 + * to distinguish RGB, CMYK, and YCCK colorspaces.
  25.467 + * Note that an application can write additional header markers after
  25.468 + * jpeg_start_compress returns.
  25.469 + */
  25.470 +
  25.471 +METHODDEF(void)
  25.472 +write_file_header (j_compress_ptr cinfo)
  25.473 +{
  25.474 +  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  25.475 +
  25.476 +  emit_marker(cinfo, M_SOI);	/* first the SOI */
  25.477 +
  25.478 +  /* SOI is defined to reset restart interval to 0 */
  25.479 +  marker->last_restart_interval = 0;
  25.480 +
  25.481 +  if (cinfo->write_JFIF_header)	/* next an optional JFIF APP0 */
  25.482 +    emit_jfif_app0(cinfo);
  25.483 +  if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  25.484 +    emit_adobe_app14(cinfo);
  25.485 +}
  25.486 +
  25.487 +
  25.488 +/*
  25.489 + * Write frame header.
  25.490 + * This consists of DQT and SOFn markers.
  25.491 + * Note that we do not emit the SOF until we have emitted the DQT(s).
  25.492 + * This avoids compatibility problems with incorrect implementations that
  25.493 + * try to error-check the quant table numbers as soon as they see the SOF.
  25.494 + */
  25.495 +
  25.496 +METHODDEF(void)
  25.497 +write_frame_header (j_compress_ptr cinfo)
  25.498 +{
  25.499 +  int ci, prec;
  25.500 +  boolean is_baseline;
  25.501 +  jpeg_component_info *compptr;
  25.502 +  
  25.503 +  /* Emit DQT for each quantization table.
  25.504 +   * Note that emit_dqt() suppresses any duplicate tables.
  25.505 +   */
  25.506 +  prec = 0;
  25.507 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  25.508 +       ci++, compptr++) {
  25.509 +    prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  25.510 +  }
  25.511 +  /* now prec is nonzero iff there are any 16-bit quant tables. */
  25.512 +
  25.513 +  /* Check for a non-baseline specification.
  25.514 +   * Note we assume that Huffman table numbers won't be changed later.
  25.515 +   */
  25.516 +  if (cinfo->arith_code || cinfo->progressive_mode ||
  25.517 +      cinfo->data_precision != 8) {
  25.518 +    is_baseline = FALSE;
  25.519 +  } else {
  25.520 +    is_baseline = TRUE;
  25.521 +    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  25.522 +	 ci++, compptr++) {
  25.523 +      if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  25.524 +	is_baseline = FALSE;
  25.525 +    }
  25.526 +    if (prec && is_baseline) {
  25.527 +      is_baseline = FALSE;
  25.528 +      /* If it's baseline except for quantizer size, warn the user */
  25.529 +      TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  25.530 +    }
  25.531 +  }
  25.532 +
  25.533 +  /* Emit the proper SOF marker */
  25.534 +  if (cinfo->arith_code) {
  25.535 +    emit_sof(cinfo, M_SOF9);	/* SOF code for arithmetic coding */
  25.536 +  } else {
  25.537 +    if (cinfo->progressive_mode)
  25.538 +      emit_sof(cinfo, M_SOF2);	/* SOF code for progressive Huffman */
  25.539 +    else if (is_baseline)
  25.540 +      emit_sof(cinfo, M_SOF0);	/* SOF code for baseline implementation */
  25.541 +    else
  25.542 +      emit_sof(cinfo, M_SOF1);	/* SOF code for non-baseline Huffman file */
  25.543 +  }
  25.544 +}
  25.545 +
  25.546 +
  25.547 +/*
  25.548 + * Write scan header.
  25.549 + * This consists of DHT or DAC markers, optional DRI, and SOS.
  25.550 + * Compressed data will be written following the SOS.
  25.551 + */
  25.552 +
  25.553 +METHODDEF(void)
  25.554 +write_scan_header (j_compress_ptr cinfo)
  25.555 +{
  25.556 +  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  25.557 +  int i;
  25.558 +  jpeg_component_info *compptr;
  25.559 +
  25.560 +  if (cinfo->arith_code) {
  25.561 +    /* Emit arith conditioning info.  We may have some duplication
  25.562 +     * if the file has multiple scans, but it's so small it's hardly
  25.563 +     * worth worrying about.
  25.564 +     */
  25.565 +    emit_dac(cinfo);
  25.566 +  } else {
  25.567 +    /* Emit Huffman tables.
  25.568 +     * Note that emit_dht() suppresses any duplicate tables.
  25.569 +     */
  25.570 +    for (i = 0; i < cinfo->comps_in_scan; i++) {
  25.571 +      compptr = cinfo->cur_comp_info[i];
  25.572 +      if (cinfo->progressive_mode) {
  25.573 +	/* Progressive mode: only DC or only AC tables are used in one scan */
  25.574 +	if (cinfo->Ss == 0) {
  25.575 +	  if (cinfo->Ah == 0)	/* DC needs no table for refinement scan */
  25.576 +	    emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  25.577 +	} else {
  25.578 +	  emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  25.579 +	}
  25.580 +      } else {
  25.581 +	/* Sequential mode: need both DC and AC tables */
  25.582 +	emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  25.583 +	emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  25.584 +      }
  25.585 +    }
  25.586 +  }
  25.587 +
  25.588 +  /* Emit DRI if required --- note that DRI value could change for each scan.
  25.589 +   * We avoid wasting space with unnecessary DRIs, however.
  25.590 +   */
  25.591 +  if (cinfo->restart_interval != marker->last_restart_interval) {
  25.592 +    emit_dri(cinfo);
  25.593 +    marker->last_restart_interval = cinfo->restart_interval;
  25.594 +  }
  25.595 +
  25.596 +  emit_sos(cinfo);
  25.597 +}
  25.598 +
  25.599 +
  25.600 +/*
  25.601 + * Write datastream trailer.
  25.602 + */
  25.603 +
  25.604 +METHODDEF(void)
  25.605 +write_file_trailer (j_compress_ptr cinfo)
  25.606 +{
  25.607 +  emit_marker(cinfo, M_EOI);
  25.608 +}
  25.609 +
  25.610 +
  25.611 +/*
  25.612 + * Write an abbreviated table-specification datastream.
  25.613 + * This consists of SOI, DQT and DHT tables, and EOI.
  25.614 + * Any table that is defined and not marked sent_table = TRUE will be
  25.615 + * emitted.  Note that all tables will be marked sent_table = TRUE at exit.
  25.616 + */
  25.617 +
  25.618 +METHODDEF(void)
  25.619 +write_tables_only (j_compress_ptr cinfo)
  25.620 +{
  25.621 +  int i;
  25.622 +
  25.623 +  emit_marker(cinfo, M_SOI);
  25.624 +
  25.625 +  for (i = 0; i < NUM_QUANT_TBLS; i++) {
  25.626 +    if (cinfo->quant_tbl_ptrs[i] != NULL)
  25.627 +      (void) emit_dqt(cinfo, i);
  25.628 +  }
  25.629 +
  25.630 +  if (! cinfo->arith_code) {
  25.631 +    for (i = 0; i < NUM_HUFF_TBLS; i++) {
  25.632 +      if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  25.633 +	emit_dht(cinfo, i, FALSE);
  25.634 +      if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  25.635 +	emit_dht(cinfo, i, TRUE);
  25.636 +    }
  25.637 +  }
  25.638 +
  25.639 +  emit_marker(cinfo, M_EOI);
  25.640 +}
  25.641 +
  25.642 +
  25.643 +/*
  25.644 + * Initialize the marker writer module.
  25.645 + */
  25.646 +
  25.647 +GLOBAL(void)
  25.648 +jinit_marker_writer (j_compress_ptr cinfo)
  25.649 +{
  25.650 +  my_marker_ptr marker;
  25.651 +
  25.652 +  /* Create the subobject */
  25.653 +  marker = (my_marker_ptr)
  25.654 +    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  25.655 +				SIZEOF(my_marker_writer));
  25.656 +  cinfo->marker = (struct jpeg_marker_writer *) marker;
  25.657 +  /* Initialize method pointers */
  25.658 +  marker->pub.write_file_header = write_file_header;
  25.659 +  marker->pub.write_frame_header = write_frame_header;
  25.660 +  marker->pub.write_scan_header = write_scan_header;
  25.661 +  marker->pub.write_file_trailer = write_file_trailer;
  25.662 +  marker->pub.write_tables_only = write_tables_only;
  25.663 +  marker->pub.write_marker_header = write_marker_header;
  25.664 +  marker->pub.write_marker_byte = write_marker_byte;
  25.665 +  /* Initialize private state */
  25.666 +  marker->last_restart_interval = 0;
  25.667 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/libs/libjpeg/jcmaster.c	Sat Sep 19 05:51:51 2015 +0300
    26.3 @@ -0,0 +1,590 @@
    26.4 +/*
    26.5 + * jcmaster.c
    26.6 + *
    26.7 + * Copyright (C) 1991-1997, Thomas G. Lane.
    26.8 + * This file is part of the Independent JPEG Group's software.
    26.9 + * For conditions of distribution and use, see the accompanying README file.
   26.10 + *
   26.11 + * This file contains master control logic for the JPEG compressor.
   26.12 + * These routines are concerned with parameter validation, initial setup,
   26.13 + * and inter-pass control (determining the number of passes and the work 
   26.14 + * to be done in each pass).
   26.15 + */
   26.16 +
   26.17 +#define JPEG_INTERNALS
   26.18 +#include "jinclude.h"
   26.19 +#include "jpeglib.h"
   26.20 +
   26.21 +
   26.22 +/* Private state */
   26.23 +
   26.24 +typedef enum {
   26.25 +	main_pass,		/* input data, also do first output step */
   26.26 +	huff_opt_pass,		/* Huffman code optimization pass */
   26.27 +	output_pass		/* data output pass */
   26.28 +} c_pass_type;
   26.29 +
   26.30 +typedef struct {
   26.31 +  struct jpeg_comp_master pub;	/* public fields */
   26.32 +
   26.33 +  c_pass_type pass_type;	/* the type of the current pass */
   26.34 +
   26.35 +  int pass_number;		/* # of passes completed */
   26.36 +  int total_passes;		/* total # of passes needed */
   26.37 +
   26.38 +  int scan_number;		/* current index in scan_info[] */
   26.39 +} my_comp_master;
   26.40 +
   26.41 +typedef my_comp_master * my_master_ptr;
   26.42 +
   26.43 +
   26.44 +/*
   26.45 + * Support routines that do various essential calculations.
   26.46 + */
   26.47 +
   26.48 +LOCAL(void)
   26.49 +initial_setup (j_compress_ptr cinfo)
   26.50 +/* Do computations that are needed before master selection phase */
   26.51 +{
   26.52 +  int ci;
   26.53 +  jpeg_component_info *compptr;
   26.54 +  long samplesperrow;
   26.55 +  JDIMENSION jd_samplesperrow;
   26.56 +
   26.57 +  /* Sanity check on image dimensions */
   26.58 +  if (cinfo->image_height <= 0 || cinfo->image_width <= 0
   26.59 +      || cinfo->num_components <= 0 || cinfo->input_components <= 0)
   26.60 +    ERREXIT(cinfo, JERR_EMPTY_IMAGE);
   26.61 +
   26.62 +  /* Make sure image isn't bigger than I can handle */
   26.63 +  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
   26.64 +      (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
   26.65 +    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
   26.66 +
   26.67 +  /* Width of an input scanline must be representable as JDIMENSION. */
   26.68 +  samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
   26.69 +  jd_samplesperrow = (JDIMENSION) samplesperrow;
   26.70 +  if ((long) jd_samplesperrow != samplesperrow)
   26.71 +    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
   26.72 +
   26.73 +  /* For now, precision must match compiled-in value... */
   26.74 +  if (cinfo->data_precision != BITS_IN_JSAMPLE)
   26.75 +    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
   26.76 +
   26.77 +  /* Check that number of components won't exceed internal array sizes */
   26.78 +  if (cinfo->num_components > MAX_COMPONENTS)
   26.79 +    ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
   26.80 +	     MAX_COMPONENTS);
   26.81 +
   26.82 +  /* Compute maximum sampling factors; check factor validity */
   26.83 +  cinfo->max_h_samp_factor = 1;
   26.84 +  cinfo->max_v_samp_factor = 1;
   26.85 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
   26.86 +       ci++, compptr++) {
   26.87 +    if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
   26.88 +	compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
   26.89 +      ERREXIT(cinfo, JERR_BAD_SAMPLING);
   26.90 +    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
   26.91 +				   compptr->h_samp_factor);
   26.92 +    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
   26.93 +				   compptr->v_samp_factor);
   26.94 +  }
   26.95 +
   26.96 +  /* Compute dimensions of components */
   26.97 +  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
   26.98 +       ci++, compptr++) {
   26.99 +    /* Fill in the correct component_index value; don't rely on application */
  26.100 +    compptr->component_index = ci;
  26.101 +    /* For compression, we never do DCT scaling. */
  26.102 +    compptr->DCT_scaled_size = DCTSIZE;
  26.103 +    /* Size in DCT blocks */
  26.104 +    compptr->width_in_blocks = (JDIMENSION)
  26.105 +      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  26.106 +		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
  26.107 +    compptr->height_in_blocks = (JDIMENSION)
  26.108 +      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  26.109 +		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
  26.110 +    /* Size in samples */
  26.111 +    compptr->downsampled_width = (JDIMENSION)
  26.112 +      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  26.113 +		    (long) cinfo->max_h_samp_factor);
  26.114 +    compptr->downsampled_height = (JDIMENSION)
  26.115 +      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  26.116 +		    (long) cinfo->max_v_samp_factor);
  26.117 +    /* Mark component needed (this flag isn't actually used for compression) */
  26.118 +    compptr->component_needed = TRUE;
  26.119 +  }
  26.120 +
  26.121 +  /* Compute number of fully interleaved MCU rows (number of times that
  26.122 +   * main controller will call coefficient controller).
  26.123 +   */
  26.124 +  cinfo->total_iMCU_rows = (JDIMENSION)
  26.125 +    jdiv_round_up((long) cinfo->image_height,
  26.126 +		  (long) (cinfo->max_v_samp_factor*DCTSIZE));
  26.127 +}
  26.128 +
  26.129 +
  26.130 +#ifdef C_MULTISCAN_FILES_SUPPORTED
  26.131 +
  26.132 +LOCAL(void)
  26.133 +validate_script (j_compress_ptr cinfo)
  26.134 +/* Verify that the scan script in cinfo->scan_info[] is valid; also
  26.135 + * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
  26.136 + */
  26.137 +{
  26.138 +  const jpeg_scan_info * scanptr;
  26.139 +  int scanno, ncomps, ci, coefi, thisi;
  26.140 +  int Ss, Se, Ah, Al;
  26.141 +  boolean component_sent[MAX_COMPONENTS];
  26.142 +#ifdef C_PROGRESSIVE_SUPPORTED
  26.143 +  int * last_bitpos_ptr;
  26.144 +  int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  26.145 +  /* -1 until that coefficient has been seen; then last Al for it */
  26.146 +#endif
  26.147 +
  26.148 +  if (cinfo->num_scans <= 0)
  26.149 +    ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  26.150 +
  26.151 +  /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
  26.152 +   * for progressive JPEG, no scan can have this.
  26.153 +   */
  26.154 +  scanptr = cinfo->scan_info;
  26.155 +  if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  26.156 +#ifdef C_PROGRESSIVE_SUPPORTED
  26.157 +    cinfo->progressive_mode = TRUE;
  26.158 +    last_bitpos_ptr = & last_bitpos[0][0];
  26.159 +    for (ci = 0; ci < cinfo->num_components; ci++) 
  26.160 +      for (coefi = 0; coefi < DCTSIZE2; coefi++)
  26.161 +	*last_bitpos_ptr++ = -1;
  26.162 +#else
  26.163 +    ERREXIT(cinfo, JERR_NOT_COMPILED);
  26.164 +#endif
  26.165 +  } else {
  26.166 +    cinfo->progressive_mode = FALSE;
  26.167 +    for (ci = 0; ci < cinfo->num_components; ci++) 
  26.168 +      component_sent[ci] = FALSE;
  26.169 +  }
  26.170 +
  26.171 +  for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  26.172 +    /* Validate component indexes */
  26.173 +    ncomps = scanptr->comps_in_scan;
  26.174 +    if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  26.175 +      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  26.176 +    for (ci = 0; ci < ncomps; ci++) {
  26.177 +      thisi = scanptr->component_index[ci];
  26.178 +      if (thisi < 0 || thisi >= cinfo->num_components)
  26.179 +	ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  26.180 +      /* Components must appear in SOF order within each scan */
  26.181 +      if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  26.182 +	ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  26.183 +    }
  26.184 +    /* Validate progression parameters */
  26.185 +    Ss = scanptr->Ss;
  26.186 +    Se = scanptr->Se;
  26.187 +    Ah = scanptr->Ah;
  26.188 +    Al = scanptr->Al;
  26.189 +    if (cinfo->progressive_mode) {
  26.190 +#ifdef C_PROGRESSIVE_SUPPORTED
  26.191 +      /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
  26.192 +       * seems wrong: the upper bound ought to depend on data precision.
  26.193 +       * Perhaps they really meant 0..N+1 for N-bit precision.
  26.194 +       * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
  26.195 +       * out-of-range reconstructed DC values during the first DC scan,
  26.196 +       * which might cause problems for some decoders.
  26.197 +       */
  26.198 +#if BITS_IN_JSAMPLE == 8
  26.199 +#define MAX_AH_AL 10
  26.200 +#else
  26.201 +#define MAX_AH_AL 13
  26.202 +#endif
  26.203 +      if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  26.204 +	  Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  26.205 +	ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.206 +      if (Ss == 0) {
  26.207 +	if (Se != 0)		/* DC and AC together not OK */
  26.208 +	  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.209 +      } else {
  26.210 +	if (ncomps != 1)	/* AC scans must be for only one component */
  26.211 +	  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.212 +      }
  26.213 +      for (ci = 0; ci < ncomps; ci++) {
  26.214 +	last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  26.215 +	if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  26.216 +	  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.217 +	for (coefi = Ss; coefi <= Se; coefi++) {
  26.218 +	  if (last_bitpos_ptr[coefi] < 0) {
  26.219 +	    /* first scan of this coefficient */
  26.220 +	    if (Ah != 0)
  26.221 +	      ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.222 +	  } else {
  26.223 +	    /* not first scan */
  26.224 +	    if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  26.225 +	      ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.226 +	  }
  26.227 +	  last_bitpos_ptr[coefi] = Al;
  26.228 +	}
  26.229 +      }
  26.230 +#endif
  26.231 +    } else {
  26.232 +      /* For sequential JPEG, all progression parameters must be these: */
  26.233 +      if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  26.234 +	ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  26.235 +      /* Make sure components are not sent twice */
  26.236 +      for (ci = 0; ci < ncomps; ci++) {
  26.237 +	thisi = scanptr->component_index[ci];
  26.238 +	if (component_sent[thisi])
  26.239 +	  ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  26.240 +	component_sent[thisi] = TRUE;
  26.241 +      }
  26.242 +    }
  26.243 +  }
  26.244 +
  26.245 +  /* Now verify that everything got sent. */
  26.246 +  if (cinfo->progressive_mode) {
  26.247 +#ifdef C_PROGRESSIVE_SUPPORTED
  26.248 +    /* For progressive mode, we only check that at least some DC data
  26.249 +     * got sent for each component; the spec does not require that all bits
  26.250 +     * of all coefficients be transmitted.  Would it be wiser to enforce
  26.251 +     * transmission of all coefficient bits??
  26.252 +     */
  26.253 +    for (ci = 0; ci < cinfo->num_components; ci++) {
  26.254 +      if (last_bitpos[ci][0] < 0)
  26.255 +	ERREXIT(cinfo, JERR_MISSING_DATA);
  26.256 +    }
  26.257 +#endif
  26.258 +  } else {
  26.259 +    for (ci = 0; ci < cinfo->num_components; ci++) {
  26.260 +      if (! component_sent[ci])
  26.261 +	ERREXIT(cinfo, JERR_MISSING_DATA);
  26.262 +    }
  26.263 +  }
  26.264 +}
  26.265 +
  26.266 +#endif /* C_MULTISCAN_FILES_SUPPORTED */
  26.267 +
  26.268 +
  26.269 +LOCAL(void)
  26.270 +select_scan_parameters (j_compress_ptr cinfo)
  26.271 +/* Set up the scan parameters for the current scan */
  26.272 +{
  26.273 +  int ci;
  26.274 +
  26.275 +#ifdef C_MULTISCAN_FILES_SUPPORTED
  26.276 +  if (cinfo->scan_info != NULL) {
  26.277 +    /* Prepare for current scan --- the script is already validated */
  26.278 +    my_master_ptr master = (my_master_ptr) cinfo->master;
  26.279 +    const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  26.280 +
  26.281 +    cinfo->comps_in_scan = scanptr->comps_in_scan;
  26.282 +    for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  26.283 +      cinfo->cur_comp_info[ci] =
  26.284 +	&cinfo->comp_info[scanptr->component_index[ci]];
  26.285 +    }
  26.286 +    cinfo->Ss = scanptr->Ss;
  26.287 +    cinfo->Se = scanptr->Se;
  26.288 +    cinfo->Ah = scanptr->Ah;
  26.289 +    cinfo->Al = scanptr->Al;
  26.290 +  }
  26.291 +  else
  26.292 +#endif
  26.293 +  {
  26.294 +    /* Prepare for single sequential-JPEG scan containing all components */
  26.295 +    if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  26.296 +      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  26.297 +	       MAX_COMPS_IN_SCAN);
  26.298 +    cinfo->comps_in_scan = cinfo->num_components;
  26.299 +    for (ci = 0; ci < cinfo->num_components; ci++) {
  26.300 +      cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  26.301 +    }
  26.302 +    cinfo->Ss = 0;
  26.303 +    cinfo->Se = DCTSIZE2-1;
  26.304 +    cinfo->Ah = 0;
  26.305 +    cinfo->Al = 0;
  26.306 +  }
  26.307 +}
  26.308 +
  26.309 +
  26.310 +LOCAL(void)
  26.311 +per_scan_setup (j_compress_ptr cinfo)
  26.312 +/* Do computations that are needed before processing a JPEG scan */
  26.313 +/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
  26.314 +{
  26.315 +  int ci, mcublks, tmp;
  26.316 +  jpeg_component_info *compptr;
  26.317 +  
  26.318 +  if (cinfo->comps_in_scan == 1) {
  26.319 +    
  26.320 +    /* Noninterleaved (single-component) scan */
  26.321 +    compptr = cinfo->cur_comp_info[0];
  26.322 +    
  26.323 +    /* Overall image size in MCUs */
  26.324 +    cinfo->MCUs_per_row = compptr->width_in_blocks;
  26.325 +    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  26.326 +    
  26.327 +    /* For noninterleaved scan, always one block per MCU */
  26.328 +    compptr->MCU_width = 1;
  26.329 +    compptr->MCU_height = 1;
  26.330 +    compptr->MCU_blocks = 1;
  26.331 +    compptr->MCU_sample_width = DCTSIZE;
  26.332 +    compptr->last_col_width = 1;
  26.333 +    /* For noninterleaved scans, it is convenient to define last_row_height
  26.334 +     * as the number of block rows present in the last iMCU row.
  26.335 +     */
  26.336 +    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  26.337 +    if (tmp == 0) tmp = compptr->v_samp_factor;
  26.338 +    compptr->last_row_height = tmp;
  26.339 +    
  26.340 +    /* Prepare array describing MCU composition */
  26.341 +    cinfo->blocks_in_MCU = 1;
  26.342 +    cinfo->MCU_membership[0] = 0;
  26.343 +    
  26.344 +  } else {
  26.345 +    
  26.346 +    /* Interleaved (multi-component) scan */
  26.347 +    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  26.348 +      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  26.349 +	       MAX_COMPS_IN_SCAN);
  26.350 +    
  26.351 +    /* Overall image size in MCUs */
  26.352 +    cinfo->MCUs_per_row = (JDIMENSION)
  26.353 +      jdiv_round_up((long) cinfo->image_width,
  26.354 +		    (long) (cinfo->max_h_samp_factor*DCTSIZE));
  26.355 +    cinfo->MCU_rows_in_scan = (JDIMENSION)
  26.356 +      jdiv_round_up((long) cinfo->image_height,
  26.357 +		    (long) (cinfo->max_v_samp_factor*DCTSIZE));
  26.358 +    
  26.359 +    cinfo->blocks_in_MCU = 0;
  26.360 +    
  26.361 +    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  26.362 +      compptr = cinfo->cur_comp_info[ci];
  26.363 +      /* Sampling factors give # of blocks of component in each MCU */
  26.364 +      compptr->MCU_width = compptr->h_samp_factor;
  26.365 +      compptr->MCU_height = compptr->v_samp_factor;
  26.366 +      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  26.367 +      compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  26.368 +      /* Figure number of non-dummy blocks in last MCU column & row */
  26.369 +      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  26.370 +      if (tmp == 0) tmp = compptr->MCU_width;
  26.371 +      compptr->last_col_width = tmp;
  26.372 +      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  26.373 +      if (tmp == 0) tmp = compptr->MCU_height;
  26.374 +      compptr->last_row_height = tmp;
  26.375 +      /* Prepare array describing MCU composition */
  26.376 +      mcublks = compptr->MCU_blocks;
  26.377 +      if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  26.378 +	ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  26.379 +      while (mcublks-- > 0) {
  26.380 +	cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  26.381 +      }
  26.382 +    }
  26.383 +    
  26.384 +  }
  26.385 +
  26.386 +  /* Convert restart specified in rows to actual MCU count. */
  26.387 +  /* Note that count must fit in 16 bits, so we provide limiting. */
  26.388 +  if (cinfo->restart_in_rows > 0) {
  26.389 +    long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  26.390 +    cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  26.391 +  }
  26.392 +}
  26.393 +
  26.394 +
  26.395 +/*
  26.396 + * Per-pass setup.
  26.397 + * This is called at the beginning of each pass.  We determine which modules
  26.398 + * will be active during this pass and give them appropriate start_pass calls.
  26.399 + * We also set is_last_pass to indicate whether any more passes will be
  26.400 + * required.
  26.401 + */
  26.402 +
  26.403 +METHODDEF(void)
  26.404 +prepare_for_pass (j_compress_ptr cinfo)
  26.405 +{
  26.406 +  my_master_ptr master = (my_master_ptr) cinfo->master;
  26.407 +
  26.408 +  switch (master->pass_type) {
  26.409 +  case main_pass:
  26.410 +    /* Initial pass: will collect input data, and do either Huffman
  26.411 +     * optimization or data output for the first scan.
  26.412 +     */
  26.413 +    select_scan_parameters(cinfo);
  26.414 +    per_scan_setup(cinfo);
  26.415 +    if (! cinfo->raw_data_in) {
  26.416 +      (*cinfo->cconvert->start_pass) (cinfo);
  26.417 +      (*cinfo->downsample->start_pass) (cinfo);
  26.418 +      (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  26.419 +    }
  26.420 +    (*cinfo->fdct->start_pass) (cinfo);
  26.421 +    (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  26.422 +    (*cinfo->coef->start_pass) (cinfo,
  26.423 +				(master->total_passes > 1 ?
  26.424 +				 JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  26.425 +    (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  26.426 +    if (cinfo->optimize_coding) {
  26.427 +      /* No immediate data output; postpone writing frame/scan headers */
  26.428 +      master->pub.call_pass_startup = FALSE;
  26.429 +    } else {
  26.430 +      /* Will write frame/scan headers at first jpeg_write_scanlines call */
  26.431 +      master->pub.call_pass_startup = TRUE;
  26.432 +    }
  26.433 +    break;
  26.434 +#ifdef ENTROPY_OPT_SUPPORTED
  26.435 +  case huff_opt_pass:
  26.436 +    /* Do Huffman optimization for a scan after the first one. */
  26.437 +    select_scan_parameters(cinfo);
  26.438 +    per_scan_setup(cinfo);
  26.439 +    if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  26.440 +      (*cinfo->entropy->start_pass) (cinfo, TRUE);
  26.441 +      (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  26.442 +      master->pub.call_pass_startup = FALSE;
  26.443 +      break;
  26.444 +    }
  26.445 +    /* Special case: Huffman DC refinement scans need no Huffman table
  26.446 +     * and therefore we can skip the optimization pass for them.
  26.447 +     */
  26.448 +    master->pass_type = output_pass;
  26.449 +    master->pass_number++;
  26.450 +    /*FALLTHROUGH*/
  26.451 +#endif
  26.452 +  case output_pass:
  26.453 +    /* Do a data-output pass. */
  26.454 +    /* We need not repeat per-scan setup if prior optimization pass did it. */
  26.455 +    if (! cinfo->optimize_coding) {
  26.456 +      select_scan_parameters(cinfo);
  26.457 +      per_scan_setup(cinfo);
  26.458 +    }
  26.459 +    (*cinfo->entropy->start_pass) (cinfo, FALSE);
  26.460 +    (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  26.461 +    /* We emit frame/scan headers now */
  26.462 +    if (master->scan_number == 0)
  26.463 +      (*cinfo->marker->write_frame_header) (cinfo);
  26.464 +    (*cinfo->marker->write_scan_header) (cinfo);
  26.465 +    master->pub.call_pass_startup = FALSE;
  26.466 +    break;
  26.467 +  default:
  26.468 +    ERREXIT(cinfo, JERR_NOT_COMPILED);
  26.469 +  }
  26.470 +
  26.471 +  master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  26.472 +
  26.473 +  /* Set up progress monitor's pass info if present */
  26.474 +  if (cinfo->progress != NULL) {
  26.475 +    cinfo->progress->completed_passes = master->pass_number;
  26.476 +    cinfo->progress->total_passes = master->total_passes;
  26.477 +  }
  26.478 +}
  26.479 +
  26.480 +
  26.481 +/*
  26.482 + * Special start-of-pass hook.
  26.483 + * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
  26.484 + * In single-pass processing, we need this hook because we don't want to
  26.485 + * write frame/scan headers during jpeg_start_compress; we want to let the
  26.486 + * application write COM markers etc. between jpeg_start_compress and the
  26.487 + * jpeg_write_scanlines loop.
  26.488 + * In multi-pass processing, this routine is not used.
  26.489 + */
  26.490 +
  26.491 +METHODDEF(void)
  26.492 +pass_startup (j_compress_ptr cinfo)
  26.493 +{
  26.494 +  cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  26.495 +
  26.496 +  (*cinfo->marker->write_frame_header) (cinfo);
  26.497 +  (*cinfo->marker->write_scan_header) (cinfo);
  26.498 +}
  26.499 +
  26.500 +
  26.501 +/*
  26.502 + * Finish up at end of pass.
  26.503 + */
  26.504 +
  26.505 +METHODDEF(void)
  26.506 +finish_pass_master (j_compress_ptr cinfo)
  26.507 +{
  26.508 +  my_master_ptr master = (my_master_ptr) cinfo->master;
  26.509 +
  26.510 +  /* The entropy coder always needs an end-of-pass call,
  26.511 +   * either to analyze statistics or to flush its output buffer.
  26.512 +   */
  26.513 +  (*cinfo->entropy->finish_pass) (cinfo);
  26.514 +
  26.515 +  /* Update state for next pass */
  26.516 +  switch (master->pass_type) {
  26.517 +  case main_pass:
  26.518 +    /* next pass is either output of scan 0 (after optimization)
  26.519 +     * or output of scan 1 (if no optimization).
  26.520 +     */
  26.521 +    master->pass_type = output_pass;
  26.522 +    if (! cinfo->optimize_coding)
  26.523 +      master->scan_number++;
  26.524 +    break;
  26.525 +  case huff_opt_pass:
  26.526 +    /* next pass is always output of current scan */
  26.527 +    master->pass_type = output_pass;
  26.528 +    break;
  26.529 +  case output_pass:
  26.530 +    /* next pass is either optimization or output of next scan */
  26.531 +    if (cinfo->optimize_coding)
  26.532 +      master->pass_type = huff_opt_pass;
  26.533 +    master->scan_number++;
  26.534 +    break;
  26.535 +  }
  26.536 +
  26.537 +  master->pass_number++;
  26.538 +}
  26.539 +
  26.540 +
  26.541 +/*
  26.542 + * Initialize master compression control.
  26.543 + */
  26.544 +
  26.545 +GLOBAL(void)
  26.546 +jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  26.547 +{
  26.548 +  my_master_ptr master;
  26.549 +
  26.550 +  master = (my_master_ptr)
  26.551 +      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  26.552 +				  SIZEOF(my_comp_master));
  26.553 +  cinfo->master = (struct jpeg_comp_master *) master;
  26.554 +  master->pub.prepare_for_pass = prepare_for_pass;
  26.555 +  master->pub.pass_startup = pass_startup;
  26.556 +  master->pub.finish_pass = finish_pass_master;
  26.557 +  master->pub.is_last_pass = FALSE;
  26.558 +
  26.559 +  /* Validate parameters, determine derived values */
  26.560 +  initial_setup(cinfo);
  26.561 +
  26.562 +  if (cinfo->scan_info != NULL) {
  26.563 +#ifdef C_MULTISCAN_FILES_SUPPORTED
  26.564 +    validate_script(cinfo);
  26.565 +#else
  26.566 +    ERREXIT(cinfo, JERR_NOT_COMPILED);
  26.567 +#endif
  26.568 +  } else {
  26.569 +    cinfo->progressive_mode = FALSE;
  26.570 +    cinfo->num_scans = 1;
  26.571 +  }
  26.572 +
  26.573 +  if (cinfo->progressive_mode)	/*  TEMPORARY HACK ??? */
  26.574 +    cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  26.575 +
  26.576 +  /* Initialize my private state */
  26.577 +  if (transcode_only) {
  26.578 +    /* no main pass in transcoding */
  26.579 +    if (cinfo->optimize_coding)
  26.580 +      master->pass_type = huff_opt_pass;
  26.581 +    else
  26.582 +      master->pass_type = output_pass;
  26.583 +  } else {
  26.584 +    /* for normal compression, first pass is always this type: */
  26.585 +    master->pass_type = main_pass;
  26.586 +  }
  26.587 +  master->scan_number = 0;
  26.588 +  master->pass_number = 0;
  26.589 +  if (cinfo->optimize_coding)
  26.590 +    master->total_passes = cinfo->num_scans * 2;
  26.591 +  else
  26.592 +    master->total_passes = cinfo->num_scans;
  26.593 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/libs/libjpeg/jcomapi.c	Sat Sep 19 05:51:51 2015 +0300
    27.3 @@ -0,0 +1,106 @@
    27.4 +/*
    27.5 + * jcomapi.c
    27.6 + *
    27.7 + * Copyright (C) 1994-1997, Thomas G. Lane.
    27.8 + * This file is part of the Independent JPEG Group's software.
    27.9 + * For conditions of distribution and use, see the accompanying README file.
   27.10 + *
   27.11 + * This file contains application interface routines that are used for both
   27.12 + * compression and decompression.
   27.13 + */
   27.14 +
   27.15 +#define JPEG_INTERNALS
   27.16 +#include "jinclude.h"
   27.17 +#include "jpeglib.h"
   27.18 +
   27.19 +
   27.20 +/*
   27.21 + * Abort processing of a JPEG compression or decompression operation,
   27.22 + * but don't destroy the object itself.
   27.23 + *
   27.24 + * For this, we merely clean up all the nonpermanent memory pools.
   27.25 + * Note that temp files (virtual arrays) are not allowed to belong to
   27.26 + * the permanent pool, so we will be able to close all temp files here.
   27.27 + * Closing a data source or destination, if necessary, is the application's
   27.28 + * responsibility.
   27.29 + */
   27.30 +
   27.31 +GLOBAL(void)
   27.32 +jpeg_abort (j_common_ptr cinfo)
   27.33 +{
   27.34 +  int pool;
   27.35 +
   27.36 +  /* Do nothing if called on a not-initialized or destroyed JPEG object. */
   27.37 +  if (cinfo->mem == NULL)
   27.38 +    return;
   27.39 +
   27.40 +  /* Releasing pools in reverse order might help avoid fragmentation
   27.41 +   * with some (brain-damaged) malloc libraries.
   27.42 +   */
   27.43 +  for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
   27.44 +    (*cinfo->mem->free_pool) (cinfo, pool);
   27.45 +  }
   27.46 +
   27.47 +  /* Reset overall state for possible reuse of object */
   27.48 +  if (cinfo->is_decompressor) {
   27.49 +    cinfo->global_state = DSTATE_START;
   27.50 +    /* Try to keep application from accessing now-deleted marker list.
   27.51 +     * A bit kludgy to do it here, but this is the most central place.
   27.52 +     */
   27.53 +    ((j_decompress_ptr) cinfo)->marker_list = NULL;
   27.54 +  } else {
   27.55 +    cinfo->global_state = CSTATE_START;
   27.56 +  }
   27.57 +}
   27.58 +
   27.59 +
   27.60 +/*
   27.61 + * Destruction of a JPEG object.
   27.62 + *
   27.63 + * Everything gets deallocated except the master jpeg_compress_struct itself
   27.64 + * and the error manager struct.  Both of these are supplied by the application
   27.65 + * and must be freed, if necessary, by the application.  (Often they are on
   27.66 + * the stack and so don't need to be freed anyway.)
   27.67 + * Closing a data source or destination, if necessary, is the application's
   27.68 + * responsibility.
   27.69 + */
   27.70 +
   27.71 +GLOBAL(void)
   27.72 +jpeg_destroy (j_common_ptr cinfo)
   27.73 +{
   27.74 +  /* We need only tell the memory manager to release everything. */
   27.75 +  /* NB: mem pointer is NULL if memory mgr failed to initialize. */
   27.76 +  if (cinfo->mem != NULL)
   27.77 +    (*cinfo->mem->self_destruct) (cinfo);
   27.78 +  cinfo->mem = NULL;		/* be safe if jpeg_destroy is called twice */
   27.79 +  cinfo->global_state = 0;	/* mark it destroyed */
   27.80 +}
   27.81 +
   27.82 +
   27.83 +/*
   27.84 + * Convenience routines for allocating quantization and Huffman tables.
   27.85 + * (Would jutils.c be a more reasonable place to put these?)
   27.86 + */
   27.87 +
   27.88 +GLOBAL(JQUANT_TBL *)
   27.89 +jpeg_alloc_quant_table (j_common_ptr cinfo)
   27.90 +{
   27.91 +  JQUANT_TBL *tbl;
   27.92 +
   27.93 +  tbl = (JQUANT_TBL *)
   27.94 +    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
   27.95 +  tbl->sent_table = FALSE;	/* make sure this is false in any new table */
   27.96 +  return tbl;
   27.97 +}
   27.98 +
   27.99 +
  27.100 +GLOBAL(JHUFF_TBL *)
  27.101 +jpeg_alloc_huff_table (j_common_ptr cinfo)
  27.102 +{
  27.103 +  JHUFF_TBL *tbl;
  27.104 +
  27.105 +  tbl = (JHUFF_TBL *)
  27.106 +    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  27.107 +  tbl->sent_table = FALSE;	/* make sure this is false in any new table */
  27.108 +  return tbl;
  27.109 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/libs/libjpeg/jconfig.h	Sat Sep 19 05:51:51 2015 +0300
    28.3 @@ -0,0 +1,45 @@
    28.4 +/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 95 or NT. */
    28.5 +/* see jconfig.doc for explanations */
    28.6 +
    28.7 +#define HAVE_PROTOTYPES
    28.8 +#define HAVE_UNSIGNED_CHAR
    28.9 +#define HAVE_UNSIGNED_SHORT
   28.10 +/* #define void char */
   28.11 +/* #define const */
   28.12 +#undef CHAR_IS_UNSIGNED
   28.13 +#define HAVE_STDDEF_H
   28.14 +#define HAVE_STDLIB_H
   28.15 +#undef NEED_BSD_STRINGS
   28.16 +#undef NEED_SYS_TYPES_H
   28.17 +#undef NEED_FAR_POINTERS	/* we presume a 32-bit flat memory model */
   28.18 +#undef NEED_SHORT_EXTERNAL_NAMES
   28.19 +#undef INCOMPLETE_TYPES_BROKEN
   28.20 +
   28.21 +/* Define "boolean" as unsigned char, not int, per Windows custom */
   28.22 +#ifndef __RPCNDR_H__		/* don't conflict if rpcndr.h already read */
   28.23 +typedef unsigned char boolean;
   28.24 +#endif
   28.25 +#define HAVE_BOOLEAN		/* prevent jmorecfg.h from redefining it */
   28.26 +
   28.27 +
   28.28 +#ifdef JPEG_INTERNALS
   28.29 +
   28.30 +#undef RIGHT_SHIFT_IS_UNSIGNED
   28.31 +
   28.32 +#endif /* JPEG_INTERNALS */
   28.33 +
   28.34 +#ifdef JPEG_CJPEG_DJPEG
   28.35 +
   28.36 +#define BMP_SUPPORTED		/* BMP image file format */
   28.37 +#define GIF_SUPPORTED		/* GIF image file format */
   28.38 +#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
   28.39 +#undef RLE_SUPPORTED		/* Utah RLE image file format */
   28.40 +#define TARGA_SUPPORTED		/* Targa image file format */
   28.41 +
   28.42 +#define TWO_FILE_COMMANDLINE	/* optional */
   28.43 +#define USE_SETMODE		/* Microsoft has setmode() */
   28.44 +#undef NEED_SIGNAL_CATCHER
   28.45 +#undef DONT_USE_B_MODE
   28.46 +#undef PROGRESS_REPORT		/* optional */
   28.47 +
   28.48 +#endif /* JPEG_CJPEG_DJPEG */
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/libs/libjpeg/jcparam.c	Sat Sep 19 05:51:51 2015 +0300
    29.3 @@ -0,0 +1,610 @@
    29.4 +/*
    29.5 + * jcparam.c
    29.6 + *
    29.7 + * Copyright (C) 1991-1998, Thomas G. Lane.
    29.8 + * This file is part of the Independent JPEG Group's software.
    29.9 + * For conditions of distribution and use, see the accompanying README file.
   29.10 + *
   29.11 + * This file contains optional default-setting code for the JPEG compressor.
   29.12 + * Applications do not have to use this file, but those that don't use it
   29.13 + * must know a lot more about the innards of the JPEG code.
   29.14 + */
   29.15 +
   29.16 +#define JPEG_INTERNALS
   29.17 +#include "jinclude.h"
   29.18 +#include "jpeglib.h"
   29.19 +
   29.20 +
   29.21 +/*
   29.22 + * Quantization table setup routines
   29.23 + */
   29.24 +
   29.25 +GLOBAL(void)
   29.26 +jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
   29.27 +		      const unsigned int *basic_table,
   29.28 +		      int scale_factor, boolean force_baseline)
   29.29 +/* Define a quantization table equal to the basic_table times
   29.30 + * a scale factor (given as a percentage).
   29.31 + * If force_baseline is TRUE, the computed quantization table entries
   29.32 + * are limited to 1..255 for JPEG baseline compatibility.
   29.33 + */
   29.34 +{
   29.35 +  JQUANT_TBL ** qtblptr;
   29.36 +  int i;
   29.37 +  long temp;
   29.38 +
   29.39 +  /* Safety check to ensure start_compress not called yet. */
   29.40 +  if (cinfo->global_state != CSTATE_START)
   29.41 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
   29.42 +
   29.43 +  if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
   29.44 +    ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
   29.45 +
   29.46 +  qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
   29.47 +
   29.48 +  if (*qtblptr == NULL)
   29.49 +    *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
   29.50 +
   29.51 +  for (i = 0; i < DCTSIZE2; i++) {
   29.52 +    temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
   29.53 +    /* limit the values to the valid range */
   29.54 +    if (temp <= 0L) temp = 1L;
   29.55 +    if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
   29.56 +    if (force_baseline && temp > 255L)
   29.57 +      temp = 255L;		/* limit to baseline range if requested */
   29.58 +    (*qtblptr)->quantval[i] = (UINT16) temp;
   29.59 +  }
   29.60 +
   29.61 +  /* Initialize sent_table FALSE so table will be written to JPEG file. */
   29.62 +  (*qtblptr)->sent_table = FALSE;
   29.63 +}
   29.64 +
   29.65 +
   29.66 +GLOBAL(void)
   29.67 +jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
   29.68 +			 boolean force_baseline)
   29.69 +/* Set or change the 'quality' (quantization) setting, using default tables
   29.70 + * and a straight percentage-scaling quality scale.  In most cases it's better
   29.71 + * to use jpeg_set_quality (below); this entry point is provided for
   29.72 + * applications that insist on a linear percentage scaling.
   29.73 + */
   29.74 +{
   29.75 +  /* These are the sample quantization tables given in JPEG spec section K.1.
   29.76 +   * The spec says that the values given produce "good" quality, and
   29.77 +   * when divided by 2, "very good" quality.
   29.78 +   */
   29.79 +  static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
   29.80 +    16,  11,  10,  16,  24,  40,  51,  61,
   29.81 +    12,  12,  14,  19,  26,  58,  60,  55,
   29.82 +    14,  13,  16,  24,  40,  57,  69,  56,
   29.83 +    14,  17,  22,  29,  51,  87,  80,  62,
   29.84 +    18,  22,  37,  56,  68, 109, 103,  77,
   29.85 +    24,  35,  55,  64,  81, 104, 113,  92,
   29.86 +    49,  64,  78,  87, 103, 121, 120, 101,
   29.87 +    72,  92,  95,  98, 112, 100, 103,  99
   29.88 +  };
   29.89 +  static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
   29.90 +    17,  18,  24,  47,  99,  99,  99,  99,
   29.91 +    18,  21,  26,  66,  99,  99,  99,  99,
   29.92 +    24,  26,  56,  99,  99,  99,  99,  99,
   29.93 +    47,  66,  99,  99,  99,  99,  99,  99,
   29.94 +    99,  99,  99,  99,  99,  99,  99,  99,
   29.95 +    99,  99,  99,  99,  99,  99,  99,  99,
   29.96 +    99,  99,  99,  99,  99,  99,  99,  99,
   29.97 +    99,  99,  99,  99,  99,  99,  99,  99
   29.98 +  };
   29.99 +
  29.100 +  /* Set up two quantization tables using the specified scaling */
  29.101 +  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  29.102 +		       scale_factor, force_baseline);
  29.103 +  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  29.104 +		       scale_factor, force_baseline);
  29.105 +}
  29.106 +
  29.107 +
  29.108 +GLOBAL(int)
  29.109 +jpeg_quality_scaling (int quality)
  29.110 +/* Convert a user-specified quality rating to a percentage scaling factor
  29.111 + * for an underlying quantization table, using our recommended scaling curve.
  29.112 + * The input 'quality' factor should be 0 (terrible) to 100 (very good).
  29.113 + */
  29.114 +{
  29.115 +  /* Safety limit on quality factor.  Convert 0 to 1 to avoid zero divide. */
  29.116 +  if (quality <= 0) quality = 1;
  29.117 +  if (quality > 100) quality = 100;
  29.118 +
  29.119 +  /* The basic table is used as-is (scaling 100) for a quality of 50.
  29.120 +   * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
  29.121 +   * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
  29.122 +   * to make all the table entries 1 (hence, minimum quantization loss).
  29.123 +   * Qualities 1..50 are converted to scaling percentage 5000/Q.
  29.124 +   */
  29.125 +  if (quality < 50)
  29.126 +    quality = 5000 / quality;
  29.127 +  else
  29.128 +    quality = 200 - quality*2;
  29.129 +
  29.130 +  return quality;
  29.131 +}
  29.132 +
  29.133 +
  29.134 +GLOBAL(void)
  29.135 +jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  29.136 +/* Set or change the 'quality' (quantization) setting, using default tables.
  29.137 + * This is the standard quality-adjusting entry point for typical user
  29.138 + * interfaces; only those who want detailed control over quantization tables
  29.139 + * would use the preceding three routines directly.
  29.140 + */
  29.141 +{
  29.142 +  /* Convert user 0-100 rating to percentage scaling */
  29.143 +  quality = jpeg_quality_scaling(quality);
  29.144 +
  29.145 +  /* Set up standard quality tables */
  29.146 +  jpeg_set_linear_quality(cinfo, quality, force_baseline);
  29.147 +}
  29.148 +
  29.149 +
  29.150 +/*
  29.151 + * Huffman table setup routines
  29.152 + */
  29.153 +
  29.154 +LOCAL(void)
  29.155 +add_huff_table (j_compress_ptr cinfo,
  29.156 +		JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  29.157 +/* Define a Huffman table */
  29.158 +{
  29.159 +  int nsymbols, len;
  29.160 +
  29.161 +  if (*htblptr == NULL)
  29.162 +    *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  29.163 +
  29.164 +  /* Copy the number-of-symbols-of-each-code-length counts */
  29.165 +  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  29.166 +
  29.167 +  /* Validate the counts.  We do this here mainly so we can copy the right
  29.168 +   * number of symbols from the val[] array, without risking marching off
  29.169 +   * the end of memory.  jchuff.c will do a more thorough test later.
  29.170 +   */
  29.171 +  nsymbols = 0;
  29.172 +  for (len = 1; len <= 16; len++)
  29.173 +    nsymbols += bits[len];
  29.174 +  if (nsymbols < 1 || nsymbols > 256)
  29.175 +    ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  29.176 +
  29.177 +  MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  29.178 +
  29.179 +  /* Initialize sent_table FALSE so table will be written to JPEG file. */
  29.180 +  (*htblptr)->sent_table = FALSE;
  29.181 +}
  29.182 +
  29.183 +
  29.184 +LOCAL(void)
  29.185 +std_huff_tables (j_compress_ptr cinfo)
  29.186 +/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
  29.187 +/* IMPORTANT: these are only valid for 8-bit data precision! */
  29.188 +{
  29.189 +  static const UINT8 bits_dc_luminance[17] =
  29.190 +    { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  29.191 +  static const UINT8 val_dc_luminance[] =
  29.192 +    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  29.193 +  
  29.194 +  static const UINT8 bits_dc_chrominance[17] =
  29.195 +    { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  29.196 +  static const UINT8 val_dc_chrominance[] =
  29.197 +    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  29.198 +  
  29.199 +  static const UINT8 bits_ac_luminance[17] =
  29.200 +    { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  29.201 +  static const UINT8 val_ac_luminance[] =
  29.202 +    { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  29.203 +      0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  29.204 +      0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  29.205 +      0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  29.206 +      0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  29.207 +      0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  29.208 +      0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  29.209 +      0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  29.210 +      0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  29.211 +      0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  29.212 +      0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  29.213 +      0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  29.214 +      0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  29.215 +      0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  29.216 +      0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  29.217 +      0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  29.218 +      0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  29.219 +      0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  29.220 +      0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  29.221 +      0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  29.222 +      0xf9, 0xfa };
  29.223 +  
  29.224 +  static const UINT8 bits_ac_chrominance[17] =
  29.225 +    { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  29.226 +  static const UINT8 val_ac_chrominance[] =
  29.227 +    { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  29.228 +      0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  29.229 +      0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  29.230 +      0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  29.231 +      0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  29.232 +      0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  29.233 +      0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  29.234 +      0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  29.235 +      0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  29.236 +      0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  29.237 +      0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  29.238 +      0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  29.239 +      0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  29.240 +      0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  29.241 +      0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  29.242 +      0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  29.243 +      0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  29.244 +      0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  29.245 +      0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  29.246 +      0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  29.247 +      0xf9, 0xfa };
  29.248 +  
  29.249 +  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  29.250 +		 bits_dc_luminance, val_dc_luminance);
  29.251 +  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  29.252 +		 bits_ac_luminance, val_ac_luminance);
  29.253 +  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  29.254 +		 bits_dc_chrominance, val_dc_chrominance);
  29.255 +  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  29.256 +		 bits_ac_chrominance, val_ac_chrominance);
  29.257 +}
  29.258 +
  29.259 +
  29.260 +/*
  29.261 + * Default parameter setup for compression.
  29.262 + *
  29.263 + * Applications that don't choose to use this routine must do their
  29.264 + * own setup of all these parameters.  Alternately, you can call this
  29.265 + * to establish defaults and then alter parameters selectively.  This
  29.266 + * is the recommended approach since, if we add any new parameters,
  29.267 + * your code will still work (they'll be set to reasonable defaults).
  29.268 + */
  29.269 +
  29.270 +GLOBAL(void)
  29.271 +jpeg_set_defaults (j_compress_ptr cinfo)
  29.272 +{
  29.273 +  int i;
  29.274 +
  29.275 +  /* Safety check to ensure start_compress not called yet. */
  29.276 +  if (cinfo->global_state != CSTATE_START)
  29.277 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  29.278 +
  29.279 +  /* Allocate comp_info array large enough for maximum component count.
  29.280 +   * Array is made permanent in case application wants to compress
  29.281 +   * multiple images at same param settings.
  29.282 +   */
  29.283 +  if (cinfo->comp_info == NULL)
  29.284 +    cinfo->comp_info = (jpeg_component_info *)
  29.285 +      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  29.286 +				  MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  29.287 +
  29.288 +  /* Initialize everything not dependent on the color space */
  29.289 +
  29.290 +  cinfo->data_precision = BITS_IN_JSAMPLE;
  29.291 +  /* Set up two quantization tables using default quality of 75 */
  29.292 +  jpeg_set_quality(cinfo, 75, TRUE);
  29.293 +  /* Set up two Huffman tables */
  29.294 +  std_huff_tables(cinfo);
  29.295 +
  29.296 +  /* Initialize default arithmetic coding conditioning */
  29.297 +  for (i = 0; i < NUM_ARITH_TBLS; i++) {
  29.298 +    cinfo->arith_dc_L[i] = 0;
  29.299 +    cinfo->arith_dc_U[i] = 1;
  29.300 +    cinfo->arith_ac_K[i] = 5;
  29.301 +  }
  29.302 +
  29.303 +  /* Default is no multiple-scan output */
  29.304 +  cinfo->scan_info = NULL;
  29.305 +  cinfo->num_scans = 0;
  29.306 +
  29.307 +  /* Expect normal source image, not raw downsampled data */
  29.308 +  cinfo->raw_data_in = FALSE;
  29.309 +
  29.310 +  /* Use Huffman coding, not arithmetic coding, by default */
  29.311 +  cinfo->arith_code = FALSE;
  29.312 +
  29.313 +  /* By default, don't do extra passes to optimize entropy coding */
  29.314 +  cinfo->optimize_coding = FALSE;
  29.315 +  /* The standard Huffman tables are only valid for 8-bit data precision.
  29.316 +   * If the precision is higher, force optimization on so that usable
  29.317 +   * tables will be computed.  This test can be removed if default tables
  29.318 +   * are supplied that are valid for the desired precision.
  29.319 +   */
  29.320 +  if (cinfo->data_precision > 8)
  29.321 +    cinfo->optimize_coding = TRUE;
  29.322 +
  29.323 +  /* By default, use the simpler non-cosited sampling alignment */
  29.324 +  cinfo->CCIR601_sampling = FALSE;
  29.325 +
  29.326 +  /* No input smoothing */
  29.327 +  cinfo->smoothing_factor = 0;
  29.328 +
  29.329 +  /* DCT algorithm preference */
  29.330 +  cinfo->dct_method = JDCT_DEFAULT;
  29.331 +
  29.332 +  /* No restart markers */
  29.333 +  cinfo->restart_interval = 0;
  29.334 +  cinfo->restart_in_rows = 0;
  29.335 +
  29.336 +  /* Fill in default JFIF marker parameters.  Note that whether the marker
  29.337 +   * will actually be written is determined by jpeg_set_colorspace.
  29.338 +   *
  29.339 +   * By default, the library emits JFIF version code 1.01.
  29.340 +   * An application that wants to emit JFIF 1.02 extension markers should set
  29.341 +   * JFIF_minor_version to 2.  We could probably get away with just defaulting
  29.342 +   * to 1.02, but there may still be some decoders in use that will complain
  29.343 +   * about that; saying 1.01 should minimize compatibility problems.
  29.344 +   */
  29.345 +  cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  29.346 +  cinfo->JFIF_minor_version = 1;
  29.347 +  cinfo->density_unit = 0;	/* Pixel size is unknown by default */
  29.348 +  cinfo->X_density = 1;		/* Pixel aspect ratio is square by default */
  29.349 +  cinfo->Y_density = 1;
  29.350 +
  29.351 +  /* Choose JPEG colorspace based on input space, set defaults accordingly */
  29.352 +
  29.353 +  jpeg_default_colorspace(cinfo);
  29.354 +}
  29.355 +
  29.356 +
  29.357 +/*
  29.358 + * Select an appropriate JPEG colorspace for in_color_space.
  29.359 + */
  29.360 +
  29.361 +GLOBAL(void)
  29.362 +jpeg_default_colorspace (j_compress_ptr cinfo)
  29.363 +{
  29.364 +  switch (cinfo->in_color_space) {
  29.365 +  case JCS_GRAYSCALE:
  29.366 +    jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  29.367 +    break;
  29.368 +  case JCS_RGB:
  29.369 +    jpeg_set_colorspace(cinfo, JCS_YCbCr);
  29.370 +    break;
  29.371 +  case JCS_YCbCr:
  29.372 +    jpeg_set_colorspace(cinfo, JCS_YCbCr);
  29.373 +    break;
  29.374 +  case JCS_CMYK:
  29.375 +    jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  29.376 +    break;
  29.377 +  case JCS_YCCK:
  29.378 +    jpeg_set_colorspace(cinfo, JCS_YCCK);
  29.379 +    break;
  29.380 +  case JCS_UNKNOWN:
  29.381 +    jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  29.382 +    break;
  29.383 +  default:
  29.384 +    ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  29.385 +  }
  29.386 +}
  29.387 +
  29.388 +
  29.389 +/*
  29.390 + * Set the JPEG colorspace, and choose colorspace-dependent default values.
  29.391 + */
  29.392 +
  29.393 +GLOBAL(void)
  29.394 +jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  29.395 +{
  29.396 +  jpeg_component_info * compptr;
  29.397 +  int ci;
  29.398 +
  29.399 +#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl)  \
  29.400 +  (compptr = &cinfo->comp_info[index], \
  29.401 +   compptr->component_id = (id), \
  29.402 +   compptr->h_samp_factor = (hsamp), \
  29.403 +   compptr->v_samp_factor = (vsamp), \
  29.404 +   compptr->quant_tbl_no = (quant), \
  29.405 +   compptr->dc_tbl_no = (dctbl), \
  29.406 +   compptr->ac_tbl_no = (actbl) )
  29.407 +
  29.408 +  /* Safety check to ensure start_compress not called yet. */
  29.409 +  if (cinfo->global_state != CSTATE_START)
  29.410 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  29.411 +
  29.412 +  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
  29.413 +   * tables 1 for chrominance components.
  29.414 +   */
  29.415 +
  29.416 +  cinfo->jpeg_color_space = colorspace;
  29.417 +
  29.418 +  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  29.419 +  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  29.420 +
  29.421 +  switch (colorspace) {
  29.422 +  case JCS_GRAYSCALE:
  29.423 +    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  29.424 +    cinfo->num_components = 1;
  29.425 +    /* JFIF specifies component ID 1 */
  29.426 +    SET_COMP(0, 1, 1,1, 0, 0,0);