图形验证码 java

[java]  view plain  copy
  1. <span style="font-family:Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"></span>  

验证码效果如下:有静态的,动态的,中空的

结合网上的图形验证码技术,不依赖第三方包纯java加工了一个比较复杂的图形验证码方案,防OCR防机器人

网上的图形验证码方案都是零星的,弄了一个随机字体、随机彩色字符、随机字体大小、随机扭曲、随机旋转等技术,能有效的防OCR、描边、深浅色等技术识别

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.AlphaComposite;  
  4. import java.awt.Color;  
  5. import java.awt.Font;  
  6. import java.awt.FontFormatException;  
  7. import java.awt.Graphics;  
  8. import java.awt.Graphics2D;  
  9. import java.awt.RenderingHints;  
  10. import java.awt.geom.AffineTransform;  
  11. import java.awt.image.BufferedImage;  
  12. import java.io.ByteArrayInputStream;  
  13. import java.io.File;  
  14. import java.io.FileOutputStream;  
  15. import java.io.IOException;  
  16. import java.io.OutputStream;  
  17. import java.util.Arrays;  
  18. import java.util.Random;  
  19.   
  20. import javax.imageio.ImageIO;  
  21.   
  22. import org.apache.log4j.Logger;  
  23.   
  24. /** 
  25.  * 验证码工具类: 
  26.  * 随机字体、字体样式、字体大小(验证码图片宽度 - 8 ~ 验证码图片宽度 + 10) 
  27.  * 彩色字符 每个字符的颜色随机,一定会不相同 
  28.  * 随机字符 阿拉伯数字 + 小写字母 + 大写字母 
  29.  * 3D中空自定义字体,需要单独使用,只有阿拉伯数字和大写字母 
  30.  *  
  31.  * @author lyf
  32.  * @date 
  33.  */  
  34. public class RandomVerifyImgCodeUtil  
  35. {  
  36.     private static Logger logger = Logger.getLogger(RandomVerifyImgCodeUtil.class);  
  37.     /** 
  38.      * 随机类 
  39.      */  
  40.     private static Random random = new Random();  
  41.   
  42.     // 放到session中的key  
  43.     public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";  
  44.   
  45.     // 验证码来源范围,去掉了0,1,I,O,l,o几个容易混淆的字符  
  46.     public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz";  
  47.       
  48.     private static ImgFontByte imgFontByte = new ImgFontByte();  
  49.       
  50.     private static Font baseFont;  
  51.     static  
  52.     {  
  53.         try  
  54.         {  
  55.             baseFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(imgFontByte.hex2byte(imgFontByte.getFontByteStr())));  
  56.         }  
  57.         catch (FontFormatException e)  
  58.         {  
  59.             logger.error("new img font font format failed. e: " + e.getMessage(), e);  
  60.         }  
  61.         catch (IOException e)  
  62.         {  
  63.             logger.error("new img font io failed. e: " + e.getMessage(), e);  
  64.         }  
  65.     }  
  66.   
  67.     // 字体类型  
  68.     private static String[] fontName =  
  69.     {  
  70.             "Algerian""Arial""Arial Black""Agency FB""Calibri""Cambria""Gadugi""Georgia""Consolas""Comic Sans MS""Courier New",  
  71.             "Gill sans""Time News Roman""Tahoma""Quantzite""Verdana"  
  72.     };  
  73.   
  74.     // 字体样式  
  75.     private static int[] fontStyle =  
  76.     {  
  77.             Font.BOLD, Font.ITALIC, Font.ROMAN_BASELINE, Font.PLAIN, Font.BOLD + Font.ITALIC  
  78.     };  
  79.   
  80.     // 颜色  
  81.     private static Color[] colorRange =  
  82.     {  
  83.             Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.YELLOW, Color.GREEN, Color.BLUE,  
  84.             Color.DARK_GRAY, Color.BLACK, Color.RED  
  85.     };  
  86.   
  87.     /** 
  88.      * 使用系统默认字符源生成验证码 
  89.      *  
  90.      * @param verifySize 
  91.      *            验证码长度 
  92.      * @param uuid 
  93.      *            App端传的参数,app没有session和cookie,必须用设备号在redis记录图形验证码的值 
  94.      * @param platFormName 
  95.      *            平台名称:pc\wap\app app比较特殊,需要单独处理 
  96.      * @param request 
  97.      *            请求 
  98.      * @return 
  99.      */  
  100.     public static String generateVerifyCode(int verifySize)  
  101.     {  
  102.         return generateVerifyCode(verifySize, VERIFY_CODES);  
  103.     }  
  104.   
  105.     /** 
  106.      * 使用指定源生成验证码 
  107.      *  
  108.      * @param verifySize 
  109.      *            验证码长度 
  110.      * @param sources 
  111.      *            验证码字符源 
  112.      * @return 
  113.      */  
  114.     private static String generateVerifyCode(int verifySize, String sources)  
  115.     {  
  116.         if (sources == null || sources.length() == 0)  
  117.         {  
  118.             sources = VERIFY_CODES;  
  119.         }  
  120.         int codesLen = sources.length();  
  121.         Random rand = new Random(System.currentTimeMillis());  
  122.         StringBuilder verifyCode = new StringBuilder(verifySize);  
  123.         for (int i = 0; i < verifySize; i++)  
  124.         {  
  125.             verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1)));  
  126.         }  
  127.   
  128.         return verifyCode.toString();  
  129.     }  
  130.   
  131.     /** 
  132.      * 输出指定验证码图片流 
  133.      *  
  134.      * @param w 
  135.      *            验证码图片的宽 
  136.      * @param h 
  137.      *            验证码图片的高 
  138.      * @param os 
  139.      *            流 
  140.      * @param code 
  141.      *            验证码 
  142.      * @param type 
  143.      *            场景类型,login:登录, 
  144.      *            coupons:领券 登录清晰化,领券模糊化 
  145.      *            3D: 3D中空自定义字体 
  146.      *            GIF:普通动态GIF 
  147.      *            GIF3D:3D动态GIF 
  148.      *            mix2: 普通字体和3D字体混合 
  149.      *            mixGIF: 混合动态GIF 
  150.      * @throws IOException 
  151.      */  
  152.     public static void outputImage(int w, int h, OutputStream os, String code, String type) throws IOException  
  153.     {  
  154.         int verifySize = code.length();  
  155.         BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);  
  156.         Random rand = new Random();  
  157.         Graphics2D g2 = image.createGraphics();  
  158.         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
  159.         Color[] colors = new Color[5];  
  160.         Color[] colorSpaces = colorRange;  
  161.         float[] fractions = new float[colors.length];  
  162.         for (int i = 0; i < colors.length; i++)  
  163.         {  
  164.             colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];  
  165.             fractions[i] = rand.nextFloat();  
  166.         }  
  167.         Arrays.sort(fractions);  
  168.   
  169.         g2.setColor(Color.GRAY);// 设置边框色  
  170.         g2.fillRect(00, w, h);  
  171.   
  172.         Color c = getRandColor(200250);  
  173.         g2.setColor(c);// 设置背景色  
  174.         g2.fillRect(02, w, h - 4);  
  175.   
  176.         char[] charts = code.toCharArray();  
  177.         for (int i = 0; i < charts.length; i++)  
  178.         {  
  179.             g2.setColor(c);// 设置背景色  
  180.             g2.setFont(getRandomFont(h, type));  
  181.             g2.fillRect(02, w, h - 4);  
  182.         }  
  183.   
  184.         // 1.绘制干扰线  
  185.         Random random = new Random();  
  186.         g2.setColor(getRandColor(160200));// 设置线条的颜色  
  187.         int lineNumbers = 20;  
  188.         if (type.equals("login") || type.contains("mix") || type.contains("3D"))  
  189.         {  
  190.             lineNumbers = 20;  
  191.         }  
  192.         else if (type.equals("coupons"))  
  193.         {  
  194.             lineNumbers = getRandomDrawLine();  
  195.         }  
  196.         else  
  197.         {  
  198.             lineNumbers = getRandomDrawLine();  
  199.         }  
  200.         for (int i = 0; i < lineNumbers; i++)  
  201.         {  
  202.             int x = random.nextInt(w - 1);  
  203.             int y = random.nextInt(h - 1);  
  204.             int xl = random.nextInt(6) + 1;  
  205.             int yl = random.nextInt(12) + 1;  
  206.             g2.drawLine(x, y, x + xl + 40, y + yl + 20);  
  207.         }  
  208.   
  209.         // 2.添加噪点  
  210.         float yawpRate = 0.05f;  
  211.         if (type.equals("login") || type.contains("mix") || type.contains("3D"))  
  212.         {  
  213.             yawpRate = 0.05f; // 噪声率  
  214.         }  
  215.         else if (type.equals("coupons"))  
  216.         {  
  217.             yawpRate = getRandomDrawPoint(); // 噪声率  
  218.         }  
  219.         else  
  220.         {  
  221.             yawpRate = getRandomDrawPoint(); // 噪声率  
  222.         }  
  223.         int area = (int) (yawpRate * w * h);  
  224.         for (int i = 0; i < area; i++)  
  225.         {  
  226.             int x = random.nextInt(w);  
  227.             int y = random.nextInt(h);  
  228.             int rgb = getRandomIntColor();  
  229.             image.setRGB(x, y, rgb);  
  230.         }  
  231.   
  232.         // 3.使图片扭曲  
  233.         shear(g2, w, h, c);  
  234.   
  235.         char[] chars = code.toCharArray();  
  236.         Double rd = rand.nextDouble();  
  237.         Boolean rb = rand.nextBoolean();  
  238.   
  239.         if (type.equals("login"))  
  240.         {  
  241.             for (int i = 0; i < verifySize; i++)  
  242.             {  
  243.                 g2.setColor(getRandColor(100160));  
  244.                 g2.setFont(getRandomFont(h, type));  
  245.   
  246.                 AffineTransform affine = new AffineTransform();  
  247.                 affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  248.                 g2.setTransform(affine);  
  249.                 g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  250.                 g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  251.             }  
  252.   
  253.             g2.dispose();  
  254.             ImageIO.write(image, "jpg", os);  
  255.         }  
  256.         else if (type.contains("GIF") || type.contains("mixGIF"))  
  257.         {  
  258.             GifEncoder gifEncoder = new GifEncoder(); // gif编码类,这个利用了洋人写的编码类  
  259.             // 生成字符  
  260.             gifEncoder.start(os);  
  261.             gifEncoder.setQuality(180);  
  262.             gifEncoder.setDelay(150);  
  263.             gifEncoder.setRepeat(0);  
  264.   
  265.             AlphaComposite ac3;  
  266.             for (int i = 0; i < verifySize; i++)  
  267.             {  
  268.                 g2.setColor(getRandColor(100160));  
  269.                 g2.setFont(getRandomFont(h, type));  
  270.                 for (int j = 0; j < verifySize; j++)  
  271.                 {  
  272.                     AffineTransform affine = new AffineTransform();  
  273.                     affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  274.                     g2.setTransform(affine);  
  275.                     g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  276.   
  277.                     ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(j, i, verifySize));  
  278.                     g2.setComposite(ac3);  
  279.                     g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  280.                     gifEncoder.addFrame(image);  
  281.                     image.flush();  
  282.                 }  
  283.             }  
  284.             gifEncoder.finish();  
  285.             g2.dispose();  
  286.         }  
  287.         else  
  288.         {  
  289.             for (int i = 0; i < verifySize; i++)  
  290.             {  
  291.                 g2.setColor(getRandColor(100160));  
  292.                 g2.setFont(getRandomFont(h, type));  
  293.   
  294.                 AffineTransform affine = new AffineTransform();  
  295.                 affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  296.                 g2.setTransform(affine);  
  297.                 g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  298.                 g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  299.             }  
  300.   
  301.             g2.dispose();  
  302.             ImageIO.write(image, "jpg", os);  
  303.         }  
  304.     }  
  305.   
  306.     /** 
  307.      * 获取随机颜色 
  308.      *  
  309.      * @param fc 
  310.      * @param bc 
  311.      * @return 
  312.      */  
  313.     private static Color getRandColor(int fc, int bc)  
  314.     {  
  315.         if (fc > 255)  
  316.         {  
  317.             fc = 255;  
  318.         }  
  319.         if (bc > 255)  
  320.         {  
  321.             bc = 255;  
  322.         }  
  323.         int r = fc + random.nextInt(bc - fc);  
  324.         int g = fc + random.nextInt(bc - fc);  
  325.         int b = fc + random.nextInt(bc - fc);  
  326.         return new Color(r, g, b);  
  327.     }  
  328.   
  329.     private static int getRandomIntColor()  
  330.     {  
  331.         int[] rgb = getRandomRgb();  
  332.         int color = 0;  
  333.         for (int c : rgb)  
  334.         {  
  335.             color = color << 8;  
  336.             color = color | c;  
  337.         }  
  338.         return color;  
  339.     }  
  340.   
  341.     private static int[] getRandomRgb()  
  342.     {  
  343.         int[] rgb = new int[3];  
  344.         for (int i = 0; i < 3; i++)  
  345.         {  
  346.             rgb[i] = random.nextInt(255);  
  347.         }  
  348.         return rgb;  
  349.     }  
  350.   
  351.     /** 
  352.      * 随机字体、随机风格、随机大小 
  353.      *  
  354.      * @param h 
  355.      *            验证码图片高 
  356.      * @return 
  357.      */  
  358.     private static Font getRandomFont(int h, String type)  
  359.     {  
  360.         // 字体  
  361.         String name = fontName[random.nextInt(fontName.length)];  
  362.         // 字体样式  
  363.         int style = fontStyle[random.nextInt(fontStyle.length)];  
  364.         // 字体大小  
  365.         int size = getRandomFontSize(h);  
  366.   
  367.         if (type.equals("login"))  
  368.         {  
  369.             return new Font(name, style, size);  
  370.         }  
  371.         else if (type.equals("coupons"))  
  372.         {  
  373.             return new Font(name, style, size);  
  374.         }  
  375.         else if (type.contains("3D"))  
  376.         {  
  377.             return new ImgFontByte().getFont(size, style);  
  378.         }  
  379.         else if (type.contains("mix"))  
  380.         {  
  381.             int flag = random.nextInt(10);  
  382.             if (flag > 4)  
  383.             {  
  384.                 return new Font(name, style, size);  
  385.             }  
  386.             else  
  387.             {  
  388.                 return new ImgFontByte().getFont(size, style);  
  389.             }  
  390.         }  
  391.         else  
  392.         {  
  393.             return new Font(name, style, size);  
  394.         }  
  395.     }  
  396.   
  397.     /** 
  398.      * 干扰线按范围获取随机数 
  399.      *  
  400.      * @return 
  401.      */  
  402.     private static int getRandomDrawLine()  
  403.     {  
  404.         int min = 20;  
  405.         int max = 155;  
  406.         Random random = new Random();  
  407.         return random.nextInt(max) % (max - min + 1) + min;  
  408.     }  
  409.   
  410.     /** 
  411.      * 噪点数率按范围获取随机数 
  412.      *  
  413.      * @return 
  414.      */  
  415.     private static float getRandomDrawPoint()  
  416.     {  
  417.         float min = 0.05f;  
  418.         float max = 0.1f;  
  419.         return min + ((max - min) * new Random().nextFloat());  
  420.     }  
  421.   
  422.     /** 
  423.      * 获取字体大小按范围随机 
  424.      *  
  425.      * @param h 
  426.      *            验证码图片高 
  427.      * @return 
  428.      */  
  429.     private static int getRandomFontSize(int h)  
  430.     {  
  431.         int min = h - 8;  
  432.         // int max = 46;  
  433.         Random random = new Random();  
  434.         return random.nextInt(11) + min;  
  435.     }  
  436.   
  437.     /** 
  438.      * 3D中空字体自定义属性类 
  439.      *  
  440.      * @author cgtu 
  441.      * @date 2017年5月15日 下午3:27:52 
  442.      */  
  443.     static class ImgFontByte  
  444.     {  
  445.         public Font getFont(int fontSize, int fontStype)  
  446.         {  
  447.             try  
  448.             {  
  449.                 Font font = baseFont;  
  450.                 if (baseFont == null)  
  451.                 {  
  452.                     font = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(imgFontByte.hex2byte(imgFontByte.getFontByteStr())));  
  453.                 }  
  454.                 return font.deriveFont(fontStype, fontSize);  
  455.             }  
  456.             catch (Exception e)  
  457.             {  
  458.                 return new Font("Arial", fontStype, fontSize);  
  459.             }  
  460.         }  
  461.   
  462.         private byte[] hex2byte(String str)  
  463.         {  
  464.             if (str == null)  
  465.                 return null;  
  466.             str = str.trim();  
  467.             int len = str.length();  
  468.             if (len == 0 || len % 2 == 1)  
  469.                 return null;  
  470.   
  471.             byte[] b = new byte[len / 2];  
  472.             try  
  473.             {  
  474.                 for (int i = 0; i < str.length(); i += 2)  
  475.                 {  
  476.                     b[i / 2] = (byte) Integer.decode("0x" + str.substring(i, i + 2)).intValue();  
  477.                 }  
  478.                 return b;  
  479.             }  
  480.             catch (Exception e)  
  481.             {  
  482.                 return null;  
  483.             }  
  484.         }  
  485.   
  486.         // 字体文件的十六进制字符串  
  487.         private String getFontByteStr()  
  488.         {  
  489.   
  490.             return "0001000000100040000400c04f532f327d8175d4000087740000005650434c5461e3d9fb000087cc00000036636d61709cbc69ab00007a64000005e863767420bb32bf1600000f24000000326670676d8333c24f00000f1000000014676c7966302665d800000fc40000663c68646d7806beef530000806c0000070868656164c6469a91000088040000003668686561068002f40000883c00000024686d7478e8bd09b4000077b0000001ac6b65726efffe00650000804c0000001e6c6f6361001a319600007600000001b06d617870013e049f00008860000000206e616d65a927f7000000010c00000e04706f737469df66ea0000795c0000010670726570eacfd8a800000f580000006b0000001f017a000000000000000001de00000000000000000001001c00520000000000000002000e01de0000000000000003003201ec0000000000000004001c005200000000000000050024021e0000000000000006001a02420000000000000007005c0052000100000000000000ef025c0001000000000001000e028500010000000000020007034b0001000000000003001903520001000000000004000e028500010000000000050012036b0001000000000006000d037d0001000000000007002e0285000300010409000001de00000003000104090001001c00520003000104090002000e01de0003000104090003003201ec0003000104090004001c005200030001040900050024021e0003000104090006001a02420003000104090007005c00520003000104090008002c038a000300010409000900180aa2000300010409000a01300b16000300010409000b004c0a12000300010409000c00440c46000300010409000d076003b6000300010409000e00600a120068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f0020002d00200041006300740069006f006e0020004a00610063006b0073006f006e00200043006f007000790072006900670068007400200028004300290020003100390039003800200054006f006d0020004d00750072007000680079002000370020002d00200046007200650065002100200042007500740020006e006f007400200074006f0020006200650020007200650073006f006c006400200028006f006e00200043004400200066006f007200200069006e007300740061006e00630065002100290020002d00200049006d0069006700680074006200650054004d00400061006f006c002e0063006f006d0020002d00200033003300390020005300740069006c006c002000480069006c006c002000520064002e0020002d002000480061006d00640065006e002000430054002000300036003500310038002e00310038003300300020002d00200045006c0069006d0069007400610074006500730020004f0064006f00720073002e0020004e006f00740020004100200043006f007600650072002d0055007000210052006500670075006c0061007200460072006f0067003a002000200041006300740069006f006e0020004a00610063006b0073006f006e00200031002e003000460072006f0067003a002000200038002f00320033002f0039003800200031002e00300041006300740069006f006e004a00610063006b0073006f006e687474703a2f2f6d656d626572732e616f6c2e636f6d2f76726f6f6d666f6e64652f7474662f202d20416374696f6e204a61636b736f6e20436f7079726967687420284329203139393820546f6d204d75727068792037202d20467265652120427574206e6f7420746f206265207265736f6c6420286f6e20434420666f7220696e7374616e63652129202d20496d696768746265544d40616f6c2e636f6d202d20333339205374696c6c2048696c6c2052642e202d2048616d64656e2043542030363531382e31383330202d20456c696d697461746573204f646f72732e204e6f74204120436f7665722d557021526567756c617246726f673a2020416374696f6e204a61636b736f6e20312e3046726f673a2020382f32332f393820312e30416374696f6e4a61636b736f6e005b0044006900760069006400650020004200790020005a00650072006f005d00200046006f006e0074007300480065007200650020006900730020007400680065002000730075006d006d0061007200790020006f006600200074006800650020006c006900630065006e0073006500200066006f00720020007400680069007300200066006f006e0074002c0020007700680069006300680020006d006100790020006200650020006f00760065007200720069006400640065006e00200062007900200028006d006f007300740020006c0069006b0065006c007900200076006500720079002000730069006d0069006c0061007200290020006e006500770020006c006900630065006e0073006500730020006100740020007400680065002000550052004c002000620065006c006f0077002e000d000a000d000a004e004f0020004d004f004e004500590020006d00750073007400200065007600650072002000650078006300680061006e00670065002000680061006e0064007300200066006f00720020007400680069007300200066006f006e0074002000660069006c0065002c00200077006900740068006f007500740020004500580050004c00490043004900540020005700520049005400540045004e0020005000450052004d0049005300530049004f004e002000660072006f006d0020007400680065002000640065007300690067006e00650072002e000d000a000d000a00540068006900730020006d00650061006e007300200079006f00750020004d004100590020004e004f0054002000530045004c004c0020005400480049005300200046004f004e00540020006f006e0020006100200066006f006e0074002d0063006f006c006c0065006300740069006f006e002000430044002c0020006e006f0072002000730069006e00670075006c00610072006c00790020006e006f0072002000700061007200740020006f006600200061006e00790020006f0074006800650072002000740079007000650020007000610063006b006100670065002e000d000a000d000a0059006f00750020006d00610079002000640069007300740072006900620075007400650020007400680069007300200066006f006e0074002000660069006c006500200074006f00200061006e0079006f006e006500200079006f0075002000770061006e0074002c0020006100730020006c006f006e006700200061007300200079006f007500200064006f0020006e006f00740020006d006f006400690066007900200069007400200061006e006400200064006f0020006e006f0074002000630068006100720067006500200061006e00790020006d006f006e006500790020006f0072002000730065007200760069006300650073002e000d000a000d000a0059006f0075002000630061006e00200075007300650020007400680069007300200066006f006e007400200069006e0020006e006f006e0063006f006d006d00650072006300690061006c0020006100700070006c00690063006100740069006f006e007300200061006e006400200077006500620073006900740065007300200066007200650065006c007900200061006e006400200077006900740068006f007500740020007400680065002000640065007300690067006e00650072002700730020007000650072006d0069007300730069006f006e002e000d000a000d000a0059006f0075002000630061006e00200075007300650020007400680069007300200066006f006e007400200074006f002000630072006500610074006500200063006f006d006d00650072006300690061006c002000700072006f006400750063007400730020006f00720020007700650062002000730069007400650073002c00200062007500740020007700680065006e00200061007000700072006f00700072006900610074006500200049002700640020006c006f0076006500200066006f007200200079006f007500200074006f002000730065006e00640020006d00650020006100200063006f006d0070006c0069006d0065006e007400610072007900200063006f007000790020006f006600200074006800650020006900740065006d00200079006f0075002000750073006500200069007400200069006e002e000d000a000d000a0046006f00720020007400680065002000660075006c006c0020006c006900630065006e0073006500200061006e006400200075007000640061007400650073003a000d000a000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f006c006500670061006c002e00680074006d006c000d000a000d000a004d00610069006c0069006e006700200061006400640072006500730073003a000d000a000d000a0054006f006d0020004d0075007200700068007900200037000d000a0033003300390020005300740069006c006c002000480069006c006c002000520064000d000a00480061006d00640065006e002000430054002000300036003500310038002e0031003800330030000d000a005500530041000d000a004300720065006100740065006400200062007900200054006f006d0020004d0075007200700068007900200037002e000d000a000d000a005400680069007300200069007300200061006e00200075006e006500760065006e00200073006f007200740020006f006600200033004400200061006300740069006f006e00200066006f006e0074002e0020004c006f006f006b002000610074002000690074002e000d000a000d000a005b0044006900760069006400650020004200790020005a00650072006f005d00200066006f006e00740073003a000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f0069006d0069006700680074006200650074006d002f4001002c764520b003254523616818236860442d000b030900210018001b0023001c009b003d0063012d0169011001d800b801b200de00f901d55a725a725a725a72000400060000401f1212111110100f0f0e0e0d0d0c0c0b0b0a0a090908080707060601010000018db801ff85456844456844456844456844456844456844456844456844456844456844456844456844456844456844456844b3030246002bb3050446002bb10202456844b10404456844000002003f000001b6032000030007005640200108084009020704020100060502030205040500070605010201030000010046762f3718003f3c2f3c10fd3c10fd3c012f3cfd3c2f3cfd3c003130014968b900000008496861b0405258381137b90008ffc0385933112111253311233f0177fec7fafa0320fce03f02a300060024001000fd03060028003500480055005e006900914044016a6a406b295d5a3d3a5c56095303175f3b3a021b0029022f65032f3603034642403f3d05450304034a4902070b05495549050d68052c4f04233204612c002301011746762f3718003f3f2ffd10fd10fd2ffd3c10fd012ffd3c2f3cfd173c10fd2ffd10fd3c2ffd3c3c2ffd2e2e2e002e2e2e2e3130014968b90017006a496861b0405258381137b9006affc038591314061d01140607160706070623222726272627262726351437363534373637363736333217161716131406232226353436333217160334272627111633143d01343534263d013436031134262726270607061514131736272635160717362734232207061514163332fb0705010401050c34330d02180a0103050f0c01010d072d0e2620030412190d0102361a1e3a30222818161c020310090802062b04010103234a03258a01070a03090a0c202218131526122a02a203640289012a0a3e66060705010f15041e43958401072a2729180603030103020a0d2802fd961e2d392022301f1b021d19070e1afe000506254412291440015e0366fe5101db031d04010204041f373cfe988e15070a01320c07121a390e1119122400ffff001001aa026b03550027000ffffd024f0007000f0140024c0006002e0045021f02a7002500e500e900ef00f901020130408101fdf1f0eae9e7e6e3d3d0cbc9c3bfb8b4afacaaa89b997c6e6a5d5b57504d3a3930241d18110efffaf0eceae8e6d5cecbc6c4bdb9b1afa593898682807674717066655f322a26221b1a090807001f030514020305f502903a029059029035022d530290dc053e0b05552a2804ee553e04f6f54704d74a4404ded77a9e7e019346762f3718002f2f2fb901000004fdb801013c2f3cfd3c10fd2f3cfd2f3cfd3c10fd10fd012ffd2ffd10fd10fdb801003c10fd2f3cfd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e313001b9010400264968b900930103496861b0405258b90103004038b801031137b90103ffc03859011406073615140717151423222623220623222635343736333217071617363534263534371637142322271e01151406232235343635342e0127231407062322272627262322062322262322062322262322061514173633321514232235061514171617161d0116171617363736333217150622071615140706232227061726353437262726273e0135342627262726372e01353437363736373233323633321716171e011514062322270623222623161514062322272627071617161514232227262707161514062322271416151423222623220716333236373633321736373e013332162f01071f01060716333227230607061733363736132e012322071533320213100101140706173f030d370e040b39261f05051315290f041c030c440a0b010f340a0d2b1302062c16102a270a0104010105110405100404090302260b040a180a080f12030210030d090b5235290d1a12120827062413091813170f0b0d0713061a4b3f22031c0a0713033105081026231a0f0a03190a2a0a2d3f471e090f0b04050b060808110f150b040218031a0a08090d1407150d0e0e200b040229050e06111d431c5925030d02111c331014270618112e1b560704082c062b100409980d0216100110020e144c020c04040f0c060127021102031b140f040802260b0a050e080501130b1716070410050d14029830010724030a2d10091d040322092d250c091d0d170104040d190e040d0a0e0f0f02050a433a0a150e180303110c0f030422110f04141101140a081213130c130a0909100d111c02110f0d071480192708100d1a3732150d02070e0f1406260d050a0b0b250e0f040b17030d0208090d030f17101002120b050a1b030e03152543160e010a190106021613620f010e630434052b05110d0f0b0f17fea80109071200ffff002e0045021f02a7000600060000ffff002e0045021f02a7000600060000ffff002e0045021f02a7000600060000ffff0013019c012b03440007000f0000023e00020018ffdc010f030200220030004a40190131314032002923292318001e02272d020c0b031401010b46762f3718003f2f012f3cfd2ffd2e2e2e2e002e2e3130014968b9000b0031496861b0405258381137b90031ffc0385925140623222726272627263d0114373637363736371617161514070607061514171e010726272635343706070615141716010f290c04253a1e141914070c1e283c08100d0c130e1302112f02215b29101944371f1b171e20063e1926382455442f60053a5a49631a060809090d061b384a0a6059a3780638037e42695e899c2f695858754c6200020013fff900f303150018002600494019012727402800211d211d120a1902001f030c14010800010a46762f3718003f3f012ffd2ffd2e2e2e2e002e2e3130014968b9000a0027496861b0405258381137b90027ffc0385913140706070607062322273635342726272635343716171e010734272627161514073637363736f30809072956241010054a1a0212100b05184666411d2035363c101a22171501ad1c5155147f431c10b981ae970d3a36050605011236c8535156612da1f483a10d1c3574650000010029023000e102e4002f006140260130304031002b201f1d23201704000e271b0e1f1402061f022a272d05090d05252511011b46762f3718002f2f10fd2ffd012f3cfd2ffd10fd10fd2e2e2e2e002e2e2e2e3130014968b9001b0030496861b0405258381137b90030ffc03859131407060716151406232227262706070623222635343637262726353433321733342635343332151406151736333216e1120d0d260d0a09130d0c08080c08081614031312161110250606101f02041b08051902920a04020125050b17140e0e0f0f1717080a140b030205131f1308210812180413050613250005001800dc0210030c00300038005e00690072009b404401737340740070665a5150494740351f076e6a625c5b4b4745443e3b39312b291817090700555402354e03695f6261051c57050c383105046a040c54046c0c2301011746762f3718003f2f2ffd10fd2ffd3c10fd2ffd3c012f3cfd2ffd3c2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b900170073496861b0405258381137b90073ffc03859011407062322262316070e012322272627263506272e013d0134373633321633363736333216171e01151407161716171607262726271e0133372635343635262706070627170607363332151406151417333236333534333216333735343605262b011617163337363517262322071617323602100c0f0d1349130101042b3e380a2505021d36072c1809111042110207050d0a89030c250d272810082741032c232218212e09901129520408068b0403010e3943050412103f10191552150206fed71f341716040c1c2602b0191e0453070e145101e21a3943134b081d1306341908500208033e07512c050105535c0a1a0309370c1d3c0809040e4477200906062510af1c12196118060d525a0a04040a4d022d124412100907641f1501150f3d4d081d030801060eb925070b16030000030013ff5e012b0106001d003600460067402901474740481a37313d312f25230a042928020f1e02383733023b43021a3f0500232205131300010f46762f3718002f2f10fd3c10fd012ffd2ffd2f3cfd2ffd3c2e2e2e2e2e2e2e002e2e3130014968b9000f0047496861b0405258381137b90047ffc03859172227302736373637363726272e01353437363332171e01171615140706132627262b01161514061d0116171617161514073635342726371514161514071633323736353427268511171e010b0808120c14220d230c061d7724054102062d3103070509661f02050e161b08232e6a04041f098612023a27230601a21f2d080d0a09191d010a0a481176100a170374071c324a3b4001244a0b0f0406041004580602040209312e40295b0e161b10070c2f0c73351536323c2413020003003c0109021d01e100200038004f007a403401505040511f48443f3e4e432c3821021f2d0210323105072e2d050c04054b2505183836053b4b040722212a0418141b0c011046762f3718002f2f3c2ffd3c3c2ffd2ffd3c10fd10fd10fd3c10fd3c012ffd2ffd3c2e2e2e002e2e2e2e3130014968b900100050496861b0405258381137b90050ffc03859002322062322262322072206232227263534373617321716333236333217161514272322062322262326232207173332363b0132373637361f01262322062b0122070623173637363332163332363326020e2e0d350d1144112b590513051631070b21942c44410c071e071c100c440e081e080b26092d2c6649062a030c037e1120250e104a041123185e1682070c0f041a08123052114512103d0f060112030405054952210b040d010201041e171d67970808020a5204050601010123030c02021c03030404040b0000030012000500f200c50012001a00270051401e0128284029001715171b020013030021020a2505051e040d0d0500010a46762f3718003f2f10fd10fd012ffd2ffd10fd2e002e2e3130014968b9000a0028496861b0405258381137b90028ffc038593714070e012322262726353436333217161716073427160736373627342623220615141716333236f21e043a06134d0b132f2323350e190f1a160c150c0b082e261b161d11131f151c5e321a030a2b0e171d23301f0716151d200c1e270303042517291c161a1519260003002b0051015d02dc001b002300320058401e0133334034002d25222b24201c1200292b06141212141e0419190f011246762f3718002f2f10fd01872e0ec40efc0ec4012e2e2e2e2e2e002e2e2e3130014968b900120033496861b0405258381137b90033ffc03859011407060706070607060716070e0123222635341336373e013332162726233207163332072706070607060716173637363736015d0c0c011b1b1e0e0c0d010503350e1044551e39052a0c103b1d1410031923030a1e1f1a1e0e181d3c0f1f2c1c072c1f02a901181b034848553e337014270a16230e15011f68910c212503130d150a0f3a5e214366ca070fc35616765600000600060012023c0303001b0025003d004d005c006700794035016868406900645e241e66645d231e5702484f4e023e1c030034020c2602206202483a050853054c2e041259044412010800010c46762f3718003f3f2ffd10fd2ffd10fd012ffd2ffd2ffd2ffd2ffd3c10fd2e2e2e2e2e002e2e2e2e3130014968b9000c0068496861b0405258381137b90068ffc038590114070607060706232227263534373637363332171617161716171607342716151406151736273427262726272623220706070615141716171633323736271407060706232227263534373633320335342726232207061514333237362f01060706151417263534023c0508010e3a3e54a05b5328336b250279450d192f1113070b1a39220818073e050701073c3f51ad1d010b09192623344f833324470d1114193850261c1b2341962a120e0836241b5425141093101e08031802012a0f162005553a3f746aa57f59701d093c0f1d36222743624ce54e8969124713022b5d1b29380c534044d70d221d1278395926376447b731556513196e4e634b3f52fea3a70f490b6a5246893025f0020c1f0d33452e18165f00000400290006020f030c00450059008a0093009340420194944095008e716d645e5c59513e211f917e6b4f4e47463c170f260e1a00025a79031a75031d4b03385a038e8f6003586203544005049183050b2f010b00010f46762f3718003f3f10fd3c2ffd012ffd2ffd2f3cfd2ffd2ffd2ffd10fd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b9000f0094496861b0405258381137b90094ffc038592514070623220607060706072227263534373637363336353426353436353427060726272e01353437363736373e01333217161716151416151407061716173633321716171627351427263534263d0134271406151417161f0226270623222702372623220607060706071617363736333017161514070607160f010607161732163332373637363736373426270714173426020f140a24081e05204033830842190b043c380e04030903040d12240f3a252c02080e08920f0e1815040802020201010631051108240903970202071802050504115d04042b3d17020c011209115e0a1515191712261011180b0a0c0405010203086321070e030d0421334b092e2d364e10020117044a1c080407010206070549431f0e0c03070703110b2b0319651a11110808081308490e073b46031114020d252211275d196f19102620131c1905061e2e13600d09211c59208b1f5903220e3d0f4f745e5f0a7a22420735011bc7040c0524252b1a182e101118020a821a2a370d2546060c011e3b020609010203043c080f034b10140e3b000500210022024702f60040004a00870092009b00ae4054019c9c409d009b918c6c49209377694b46368802715802001a027199030f8e032441037160032f850205030744056e1c056e830509807e7c037b050c3d054b4b043a38363a0497545250044e63042c2c09012446762f3718002f2f10fd2f173cfd3c3c10fd10fd2ffd173c10fd2ffd10fd012f3c3cfd2ffd2ffd2ffd2ffd10fd2ffd10fd2e2e2e2e2e2e002e2e2e2e2e2e3130014968b90024009c496861b0405258381137b9009cffc038592514061514151615142322242322263534373637363736373e013534232207060734272635343e01373637363332161514060706070607323316333236333217160334262322073216073613220623222326232223262322353437363736373635342623220706070615161f013633321615140706070607141716173332173233321633323f01360134272627061514161736132627262706353017024708012d46feec4509321c072d1329233c05102a20343b17282008060c27544a44596c2f2612232e0a111f220e1042110d151be418090611111a0310c51556150b16160b0a12120a19394006291c165d4e373c19313a0f210b7f29202d841b251e1e080c020c1527271520802026230501fe471110070a22060a120305060b1525fb0c320b070e0d07670487121f22082a162a17370628081414160401372d050122210d2c1b18725a296233171b250a0108060801120911121c1016fee90501010f072f35062f48370f4f620f06181b0e1c38043a2f203e6214251f1e1c2c3b0c0106014615015906201d09200604360814fe460912264b2f016e00040010000501ed0313003f0048007b00850099404601868640873c807c6f5b5a4340277e716458574d423a2d1d0951023678023c13026223026a6247023684023c6667056d0d050073050025055e10056d55042f2f010000012d46762f3718003f3f10fd2ffd2ffd10fd10fd10fd3c012ffd2ffd2f3cfd10fd10fd10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9002d0086496861b0405258381137b90086ffc03859372227262726272e01273637363332163332363534272627262726272635343736373635342322072627262726273633321617161716151407060716151407061306071736373635340726272635343736353427262322071534173332363332171615140716173736161514062332270607163332373e013534272617060716333237363534b02208130e060f09110111101d0d0b2c0b1321341608030b010604131c1c262a1e4e0b1a1904050f56693276221612151917236a6b527a045412191e1c65111015125d4337435b420d0410401032222e76050a1320343b2501400f1d2e1c5e37284c191c5306370414110d0b0501051208150c190d2324380e110f1f032b1c0d3e05130e0a07090c0b141218200325220d12592b2b21151e23192b302c1f578375362802796d4905013d371f11bf0102040f0212584e3c231c1a0802440f11152f5024244901012f21243a0c1d3d141811702b2a2a2fa2234e192922161200000500160013022a030b00400049007b008a009400974043019595409600908b857c7a715f53514841342e03908b857c6f635b4a462d2b18150057023d69021c4102394d4c033d5003390d040f2a04267605052601100f00011c46762f3718003f3c3f2ffd10fd10fd012ffd2ffd3c10fd2ffd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001c0095496861b0405258381137b90095ffc03859011406072623220706070607060706072306272e01373e013726272635343736373637363736373217161f010607173637363736313216171615140706071617162706070e01151617361726273534363727062322262235343736372627262306070607161716171615140706070607163336373e01333217163336010e010706310607060736373637361306070e01073e013736022a300c0a300506060c0202042007101418383f1401043203383756121b0209090f0b172f111a151603101e40071603211e0a6803060e1202171722bf0b100513070a0eb818311c015c27100156321216040518110b0d1b1120205149260c0d0f0209205a19051f0307100e161f040bfe8f130d03050a120d14080c0723219a1720092e010e1e081801b61c6e02042f2a441d1d1916070d01090a120f25d2150b0c151924334d0828273d0811220806060c41820c2840060e0d1103060a1f2f3e0e0b0a11c1030c084c0a020627830b19051e6d190c9c1e0f23424f17010504305f31620a0e0c0f050c072c3306407f0c35c6102305081c014b0f1814201c372c4c040a087c75feb50b160dd917050b0a7100050018000d02510300003b0049007c0088009800974044019999409a00908b8783817b5f4f443c291f049089817461534a3c1b08002c02574424025769020e7d035778050606044795041485042622045b65048e32011400011b46762f3718003f3f2ffd2ffd2ffd10fd2ffd10fd012ffd2ffd10fd3c10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001b0099496861b0405258381137b90099ffc0385901140e0107262706071617161716151406070e0123222726272e013534373637321633323534232206232226353436373637131617161716171617160734272627262726271e013332163726272e012706070615161716151407062322272627060716171633323736353426352627262726272635343e01333216333603342726271617363332173617262322062322271e0117163332373602511f0e10438f070319313c272227301c6a2227464e160916111106077d233a600a24090d320801030954376c16a2161e0405054509072c1e1d264d0a16160f854236353e6163052a26652e55242025222d2726100b51081c4364414a111a241c3a191a281d06092baf2c09da4d136501113c04541c035a06060368215d6f05164f461e23334002520e680d041e20171b050c0f463e433c4b2415230f1214083f0f07302d0b2c1d3407570f041903172f010f020a0328040d052c2778141b070704040c18111f39c30f0f100a08377b6f46010f1a4c2217140c0c0c13302603082d34600f27082b120d0602020409088f0a3826feb03614050b05240a4a08a112292f1d1a0f0e0f13000007001800170214030e00260030004e005900680074007f00ad40510180804081257a75746f6e6c5a5440332d7e6f6e5854352f2d2c1e13023d4b022578025d46020a74693d026528026572050461054f28270510560404181a042f311e04204f044848045210010400010a46762f3718003f3f2ffd10fd2ffd3c2ffd3c10fd10fd3c10fd10fd012ffd10fd3c3c2ffd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b9000a0080496861b0405258381137b90080ffc03859250607062322272627263534373637363332161514070e0123262322070607363332171e01151403232207061d0136372607220726353437363736373635342f0106070607061514333236353427260322062322271633323726272226353437363332171615140706373426232207313236333217072206071633323736353401ea1c36392c57494423142921585c691623080309070a02912106074f2d3a212b40910e1526293f3b063756651510151c4c6d0204071512b14121f04566191c48081d07453541440c36146f23433e33392a1e213a2d4322143015071d07341c522839051716292835812720233a36543155358267464932175a100703027113251d0a0c5c2e6d01cc111210031f010ed44c022314374e20590e210210180307031ed2692ef76c46501e21fea7051129120b4e3d2334211b15182a4120188913171b0517042b25160d101d2c000005000c0012023102ec002c00390044006b00720093403c0173734074006f6c665b56554b49413a362f19156f6d6c645e533e3a36312f1f151166680806040406666808070606074502004d0425250b00011f46762f3718003f2f10fd012ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001f0073496861b0405258381137b90073ffc038590114070607060f0106070607262726272635343736372207060726272e023534373637363332171e0217162716373627263534262716171607060706071e013332373637342726272607062322070607060716073332373e013332161514070607060716173637363736013534271417160231201a1a3425540d1c0513054b340604524b19253a401920081d0509060abcae2e380e06220803041f0a020202030c0c020601d3314d720d05200509b806cc0706060d16190a23170d94613f0d01082fb006220707101f1c0929651b3d407f181826feed68012502561f37282958459f1c36080703251a0928120e9f922a0c0d021a061a0f7e0d0a05080f0d0603250d2925060a04030f1104171a08102610410a070b0206191f034a151e1a19010102020109060a482e19010a0e06073e3a1045d1132871e52c2c45fdd0090f3c081112000a0003000c0214031600190021002c00500060006f007b0088009400a3000025062322272635343726353436333217161716151407161514060316151407363534031e01151407163534272607262726373e01353426232207061514171615140706070615141716333237363736353427222726353437363332171615140706032227263534373633321716151406032206151416333237363534270e011514173534263534372613220615141633323635342627220706151417263534373637342601a0454a2536b331257a690a4e612a333b474828351d2e461b280414161a190a38020a20288a5a4d312e24070a0f011d3a3c6b3930381519ce362b2e1b20363b211f171b1d462b31161c2e772414422e20291a231e130f8f0e161f05330848233122271e321d801b0f0b2509141218182a1e1239ca6f312b4969781c232d37616c264762306a0275494c2941105071fef11c5e271d0d012f2b323a36103f0906154b2759813c384f3d2a090509090d0227576b424516192e321f2c9c25263538272d29253c2e262efec61f2444322b345a301f2b4401ee3222241e231d24322c0d3d16211f010616063b2715fea83624271e331e292534271d233c1918191b201d100d160006000c000b01ed030a003300570076008c009600a400b6405501a5a540a600a0957f706f4436a3a09e97918d8577737269584a48403e3c2002001a036f1e036f65032734030446030d4d030a07545250030444030d99052b8e8d058b72050f2120056761042b2b01100f00012746762f3718003f3c3f10fd2ffd3c10fd2ffd3c10fd012ffd2ffd3c3c2f3cfd10fd10fd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e3130014968b9002700a5496861b0405258381137b900a5ffc0385901141506151406151c011514061514072322272627262726272635343736373635232227262726353437363332161716171617160730270615140706070617160714171617363534373435343635343635342726373637362f012627262332272623220706151433321514070607060733161735343736071407061506070623302726272635343736373633320723220615141716173627262322070e011514173426353401ed0107060e3d0d2327060a0b0b0b0c0303010a1b1d353e2e2c18327d424b272910060b1c15181203040101030207080e0a020106070201010103033206081b160e0d40193a6d2d16e72203040103060b2346090d6205060101030c30292a3111102f11432c1d2d1126213108014f0d0b07080419240302751b33321a115310174b170d3c0d771604050305100c0b0f0c0e161a09bf0a0e123f3b3a1e38720b0508140b16360d347f7f1320260d1c5d4b2d05080d0e411b0f2222101a591b0e460e0b271e140714116405020605090464321a8c19121c25084b940505cc5483c52715202d0914141d0e0a0a1125172b270904432f132004060517651305034108131003090337ffff000f000500f2022b00260011000000070011fffd0165ffff0013ff5e012b02540026000f0000000700110007018fffff0018ffdc010f03020006000b0000ffff003c00be021d027700270010000000960006001000b5ffff0013fff900f303150006000c000000070001000501d90314003b00460052005e0083008d009900a9404e019a9a409b00968a8474695b554f490c8e8a84807a7672534d4925221608046a69024b5b5d02705a5902313c02421c03706203314203934703001e056d290564675f043645049140003601013146762f3718003f3f2ffd10fd2f3cfd2ffd012ffd2ffd2ffd2ffd10fd10fd3c10fd3c2ffd3c2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b90031009a496861b0405258381137b9009affc03859011407060714171615300706232227262726272627263534373637363534232207060714161514070623222726272627263534373e0133321716171603140706232235343633321334271615140716173637362526232207061d0117263534372206151433323633161735343633321615140716173637262726353436373e01353427261326272627262716171607342623221514163332373601d9161924100a04421c0e141705080606041e1c23121d222d1b1513030509392606151601050474193c284c3a1616351e0f11196c241b66050e03610c131c1a17fef5050b0d0b0909015f5c751a0412040a13562f2b366905271a33021817120918392a2e470606070c060e0a091102170e271611100b0a022332383d1904412a1c0d1609080b0d252c0c593003161b172324301b152f0a280b1e0402020a30040e0a0b8d400e102e112048fddf1a15184b1b230194242210106a55090b01493e790316120e4707080948ae7e5b1d020402432e41342b534138aa0309084d4802090a040f681d5c3338fdeb1e1d23160407242437900c1227111a1310ffff002e0045021f02a700060006000000060000001502a8030d003f006200730080008c00930094403f01949440950092908b8577655f5b4f4e410f928d87817b746e635340004a484c0627252527130221110257564c02212f043370050a7d051b33011b00012146762f3718003f3f10fd2ffd10fd012ffd2f3cfd10fd872e0ec40efc0ec40ec4012e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e3130014968b900210094496861b0405258381137b90094ffc038592514070607060706070623222627262706071615140706070607062322272627263534373637361336373637363736373637363332161716171617161716171627030e01070607060706070615141733323736373426313534373633321716173637361726232207060706070e01071633323736052e0123220706071633323736131407062322353437361716072e012706153602a8101a331c36061914041346010819182413070b2402094b160b30260219140d0d034b0d17070d191f16170e2620040a36040f1d161e23121b1c276ece1c841d12070d0a062f27040c163e3214053d370c15130e0d17403756190205212a0c192b0a1403270b04404ffe9907140404341b2f2a04062c31600a470d1519201e0f200310030609de0e080814101a020d0a520d4555050d823820070d18050828211b021513274128280b0138352c04070d0502030309081b05263f2a48522536364d4001c40d150f372646271bb5920d07041f1a0e0e3c700e1b194f42420a13102f220f1205050b040909271f276205141a0d0c23161801bb13041e19382c11010f45061906210e03000009001e000502310309002d00510061007300830092009c00a800b1000001140706071617161514232227262726353437363736373637363736373637363736333217161716171617161716073427262726272623060706070607061516333236373e013534272627263534373637360326272627262715141617161716333213140623222e0135343637363332171617160314062322263534373e013332171e0137342726270e010732163332373e01273427060732173637361134262b010615141716333227342627061514173602311e2131170501c2b031060c0b23151402030911010d0916020204090212276415161e1a071b1f072036131621437f0d16291c0a191b0802a35b0c0f03253f040d4007262f1827c80f2a33193f2d0b031942343d0d9643340c580e2a080b0f3151120801603b1b145b18020f07050635553c1c181c0518050515031411092772110d160f0a040c0b1f120d1013100922510a01140f1001dc36383e0d1e22082aac510a322f070c8e53520d1820420818152907060b04011c06060a10052428145c042a343e12231801588d325e65250721700601034b2a0a0f361e040b0713181a2afe5f0f0b0e0e241e0805240426120f01ff3637160c0b0d990b10360c2905feb41f33380f0a730915050456e718110f021042100303021b52042b2d6403112c25fe890e2331030908066a041c044711050d4a00000500170067022902f7002b0035003c0049006d00804037016e6e406f004c463f3a36332f27594a463d3b3a36006202082c02131e02484202535702316a05022120054e5a59050f02110f01010846762f3718003f3c2f10fd3c2ffd3c10fd012ffd2ffd2ffd2ffd2ffd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b90008006e496861b0405258381137b9006effc0385925062322272627263534373e013736333233161514070e020706070e01151417333237363736333216171603342627060716173436132627262715140326232206151417161726353413262706232226272635343736373637232207060706070615141716171617163332373602294759b98614110e0b11814661400d094804061015422c1c0e1a1f06292b0715120a0b4703064b0b0501060b07052e0203021c911a1b2831110a210cda060735771c4a08075940640207226638512a090f1a0f1010274a42430c2b2787208f16463e27392f477e080b2b12202e3f0506160d170b2f11411d050105044d0c1c01d2060c06244706091141fe191919141b104201550e3f29241c11221b2b54fee12345124e1e1a1a552e220824471219450b163158213c42142e1b180d0c000006000b000d02410313001900330043005a0063006f007c40330170704071006b67605b564a3c206b604e3c34280a242606100e0e101a02006402445c5b02444204062a043812010600010a46762f3718003f3f2ffd10fd012ffd3c10fd2ffd872e0ec40efc0ec4012e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9000a0070496861b0405258381137b90070ffc0385901060706070627262726353437363736373633321716171617162734272627262306070607060706071633323736373637363736032627262726272627141716171633321314070607062322272635343736373637363332161716073534272627161716173426270607060736373e01023e0624372e3f7a9b1c34231516111518185151b42109090932322c624a4b030c0d030a17163963662e270e3f36180c130cb71111102346203e2a110b0d234b6d8809010638921d18224a070e0c010c0f0c71161723260d420d113e0d2e2312121813162a233d01615f4263212f0302335d06117f5050447681224e962828313067423b2d231520280d386e61d7370f05201c321a5137fea30a0b0802040409170220140814017a08290d187e070b1506dc1c383301254d272a351235250e2c1f3d20732644113f3f522501090d410000030007000a0225031b00370068007d0072402e017e7e407f007d7165644946453b3a333126256958524e43382f231c003f02287303125554041818010600011246762f3718003f3f10fd3c012ffd2ffd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b90012007e496861b0405258381137b9007effc038592514070e0104232227262726272627262726353436373624333217161514060706070607161737161706070e010706153017363332171e0127263505272e01353437363726272322062322273426353437363726352322040716171617141716171617161533323736053427262726272627061514171615161716171617022506070afe9207180805091d150e0e020b091d0e1a013f1d130b081207214a531d05059b030e080409371b2a09a642100d04142908ff00090119422a2a0406071372040a02130804ee061905fee51b02060d16140206010f0a0727788efeaf0c100213131a050d080b13050d11090fba0d1c21085e090e163f9770710b3025161345070d4b32241e092e04140f120d221114244725080e09040609462d080361082d1432060e92010d0c070715291a05018a030904024225264c081b354b98025e152808291f11242c69172c360c6c6b90422109122b3a04801f55492447000006001b003402650302002f003a0044004b006d007b00854039017c7c407d00787064635e5b4a49473f3b3932756e68634c494542350a7202243003003c3b031051022457051e2b04505005281e2801012446762f3718003f2f10fd10fd10fd012ffd2ffd3c2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b90024007c496861b0405258381137b9007cffc03859011607063106272207140716171617161514070e022306070607062206232227262726353412363332163320171617071427140615141716173603353426271606151416273427060733362526272623030616153216333637363332163332363336352306272627363736053601302706070e0115141617363736026401070a35b80248022827250f010309433f01090d0b0f081020093c160f1211350a13061b07011b8b0a1e1b0e090506010bc3110101040d7b1004051207011369698552310103114210061403100924090e390e030914353b07080e2f010207feda170509010d0b010a15080292132034090206080e05050a3004113c16050404245b522c1a05070527241226022d120420033b09011c0f3f0a0405080145fef638041502081a060e139f04161f1a21900b0a0dfdbb030e030261b50e0403072f010909086f030c0912fede1c38720d3d10031a03499235000006001e002302ae02ea003f00500058008e0092009f00a7404d01a0a040a1009e9a92908f574d27269a93908f6555514b402f3302695a59023f002b026e7978022383021767102d95106b53053b4404787638046161043d3b2d046b7d041f8704981d0f011746762f3718002f2f2ffd2ffd2ffd2f3cfd10fd2f3cfd10fd10fd10fd012ffd2ffd3c2ffd2f3cfd3c2ffd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b9001700a0496861b0405258381137b900a0ffc038590114070e01232207060706070607062322272e01272e0135343736373633321716171615140f01270607061514333237262726353436353633321633323316172726272623220706070e0115141736373613262322071617363f01342635062726232207060716333215142322263534373637363736333217353427262726070607061514171633323e01373637360723161f0126232206232227161716333202ae03062709130e090a08071d3d2b5138412a6e17070f2126515c6002593a1401071107883a60743b0b1b010e02117a0921072a29072bb90f070b181f404808010f09304018fb0c08152e0812160f0206172428121656020109171169477034385718181e130d0b040e26372c6c48431846ae38473d030106067b13050a490e08155417374f133930242e012f182c0104100c1914143f1611180f60270d46116553624952021725021b144f0802182036707418210215140f3a0e1905022cc6150507151714040f0516092e1206fecd1f070b15093a2f0717050104050c173402196461465b4b5010060507021614290402020d21746d774c2871184d23181f0911070db7071016110b0a00050027003c02aa02dd003f0050005a00840090008140360191914092008f877c7672605d59534b43393412108b857a7870685b32180e44020b0b02474003002e02515702646a05272705011846762f3718002f2f10fd012ffd2ffd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900180091496861b0405258381137b90091ffc038590114020706232227262726353436352627060726272e023534373637363736373637363f012633321716171e011514070607161736373e0133321632161716073426270316061514171617363736373625262706070607161736252627060f0126232235343736372623220706070615162336373633321706071633323637363736373605342706070615141716173602aa510c1413123a3f071c15113f1832134b4e0917060701091419070405070e09083355160a1c0910090b012629060b0a0e191551291110101b10044a010f05070116130e0f0cfecd09100a090d010b170b011f2a540912045830450e0a0940180b1216212373060a11150e7d4c0e17460d1f0b070504031524fec2210913140907083901e819feb61b2e0809064f101450130808448902171811480a0c151a083b5e77211a1a1e1204010904290c1511101f280703070d4b440b0b0d534d1f0e5908fe8f0a24050a1217053557474829c5101617253607030520470607376e040f12183c2c2b050540a0a7351f2040651449940a182e2020104d86c80a27123d400e0e130f10ac000005000d0007024a0317003a006c00760083008d009c4041018e8e408f008c88827b76716b5856504240363216128a847c736d6968544e4a2c261a0e0a0c0e0668666668505206201e1e203c3b030077026222010600011a46762f3718003f3f012ffd2ffd3c872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001a008e496861b0405258381137b9008effc038592514070607060726272627343736372627262706070623222726273637363736373633321716151406070e01071617161716173637363330171e010735342726270623222726272627262734373637262706070607161736333217161716171617161514070607060715341736033427263506071416171326272627071617161716173607262726350615141736024a20497353960e0d0b0a21363e100c0a0a0c413d03070a07080a17082568bc43040d100d14050f3f0f040e12040412052c20110e081a1c0908085713120b0605080e0c2140272802123c7b07b2050b463a0e060a080506031b141c17162a3a1f80f1070b04050e01e8021a1c051102080b0204180b6e010e150b2205a50a3f151611191529202011470f0c3f584d4c010c0a35162c13230a05112a0f352f130a4203060b0622354512244a010a08040d691106151e1819133b26261933376f0f0e080744140f1a011d1b36120a10342625125b452617080403080d0804661901df0e182501060c045702fed43a626c2e151422290d1ca302b90e2331012103044e05000004000f001d027703150030003a0048007300a7404b0174744075005c514f4e4a413631232118604c4b494741362813064a494a4b062c29292c494a064a4b37363637700200323103003b03086803451d025562050e1b0547582c010e00011346762f3718003f3f2f3cfd10fd012ffd2ffd2ffd2ffd3c10fd872e0ec408fc0ec4872e0ec40efc08c4012e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b900130074496861b0405258381137b90074ffc038590114070607060716151407060706232226272635343e023330163332353427262706072e0327373624333216171607353427262717161716033426272e012716171615140736032705151417333633321716151406232227262706070607163332373637363534272627262726353437360277030e261d1c3d3e32664a2d397a1e173e113b06801c3012111211360d390f1f01090e018c0d083804091b0208290603090a19310a07140a131b1c142a0d16fe9223065f0a1f241e493d292e262608120c0d3a92254944212b181414010c0b3622027108090c0d0909c7625f372c1a133d2f2303084a0a186e4e384c40410119032b1873100d064b390a1643162806122719192e0afe7f1dfc100a0a0632898c2f1c2c3101d2684d071752219c88373a3b211d1d0318111071100e19213c3b685151072825020d0c07000400250013026802fd002b006000690074007f40360175754076006c67635f5c503f3b1e1c0602706a6545383426231208065602005902002c020061030072040c43041616010c00011246762f3718003f3f10fd10fd012ffd10fd10fd10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e3130014968b900120075496861b0405258381137b90075ffc03859251407222726271615140e0123222627260235343e0133221716171617363332161716151406071617161716273427262722272635343736372e0127060706072627262706071617161716171e0117161736373637363534263534363332161736173427060716173e01072623220706071633323602685721241c1b130d98080d3c08067f0b850e03151427111e3c0e0e78061440090123301123323b370d01100e2811201832191c1d2f1411201f0209770122060f0813150c05070a43072d1a03280904088e095416052c1d0508053cca1a030335380d0b0c086fbb0d4b241e1e5d1b0c07252d0e0a024f17090c2a030c223a51a0460d28160db90c0c212c162c06033f3a0e0e0b02105e2a6210230a44436b081e7e790202210b902a5426454a401e26160a02090c09051c721e040ba901492a050e182b050401356515101002161e000004002d001e02ad0302002700300040005e00604024015f5f4060005b504a3f382c281f5352413938312d2c2813002105444317010a00011346762f3718003f3f2f3cfd012e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b90013005f496861b0405258381137b9005fffc0385925140706070607060706232226272627262726353637363332171617161716173633321716171e012726272627151417162526272627262f01151417161516173605262723220623220623222726272627062315141716171617161736373602ad34222263b50a201a0f1043031013140c04025537201e420d160303040e8e3c131f1c06041521030f070d0d09feda0d0403020d1027090f0a140c0121080e1c2aa7280512050b08040d0a14662a0d11020819060724477577100904041017020807390f61adbf4f1c4a010f0a4e428333334817271d1b130a7b25223a060c0c2c1d086b233a2f30418526072136510555a8035e25492a0342468d458b120d2147610b6edc1225060e1e00060007001b031602f900410049007c0086009200a00091403f01a1a140a23b9b939189837d706c66604e482e17110b079b8d837d765e4a423b201e070604870272460293780500434205314c053154042828010000011e46762f3718003f3f10fd2ffd10fd3c10fd012ffd2ffd2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001e00a1496861b0405258381137b900a1ffc03859252227262736373506070623222e0127262706070607062322272e01272627263736373637363736333217161716173e013332171617161716171615140706070e0103230e0115141736052627062322272627262322070607060706070617161736373637363332171617161736373633321514070607161736371237070607060706073637362726270607061514171617360306070607060706073637363736025f09544b191433051915060b5b120402020b19051619130633381911140605050b0b0e10010c3e6cb30c060506010f20220a49580614141b06032a2c1906395a140a1d0321010244874b150d0f1008641d18420d08060603140f01145a1414220a04060e180f10122622213809121a181849360b043b1ed70b140519170714181da30b160109050809020abd240c0307102102050e1d070d0f1b28240e5e7b05031f1c190d1410103f7f14191b1113050a0b0a092664647156132255170b141c0521191d21020606090c07153fccd12e0a3002a00a340c0609353017348547500b0f0732463d3d196b513406206565a60b035c3a3a0507363659204a66565617141916010aa2ee050e0652491a0c0a585c2e5b0122150f101a220907016d1b15062f56e31f38050a274d7b00050008000d027e0308003d0043007b0083009600a54047019797409800958b837e72665a5449403e2a268d847f7e7c6a5d5c4d423e21006264091f1d1d1f9193061f1d1d1f700252514544023b0c06057878050910051635011900012146762f3718003f3f2ffd2ffd10fd3c012ffd3c2f3cfd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900210097496861b0405258381137b90097ffc038592514070607062322262322062322272627060706070623220623222726272627263534363736333217161736373637363736333236333217161716171416272627061514133534272627060706071617160715062322272627262706071514171e011716171633323632372627262726353433321716171633323736073427151417161727342627262726270607161716171617161736027e03111e17300c3b12092508140f0c0b020511170f39103f0f150c050509111a3c0768440c1c111112070f140d352f1a04100414160f0c090a06db1c1019fb1b0520142b2222021a17020806111d1111482d6535070903130a1605050d381b14050a021a110f0d472a29090521393dbe67211b1bec0f01090f04140a18030c1002060f090c17a4090c3f171203051f17180911300b08093f292a478ec3220853021c2b1c1c2d0d1e150d0c0b0884548d71710413d38e941e1537fe780730db2ffe0a07050638998c440d07412a2bae551303070e1d240ecf52a40209081e3b06644129148c5454020e0e2d09bf08314c3c3b160d370c418362b11522234a610c4181254c1c0006000c002f0212030d001e002f004c005b006d007700734031017878407900756e38726e38305c024d3e030f0e1f0200270234636202554a2c0508600557230419670551081901010e46762f3718003f2f2ffd10fd2ffd10fd3c012ffd3c2ffd2ffd2f3cfd2ffd2e2e2e2e002e2e2e3130014968b9000e0078496861b0405258381137b90078ffc0385901140706070607062322272627263d0114373637363736373633321716171607342726232207061514171e01333237360526272635343736370607060706070617161716171617161716333236131407062322272635343332171e0107342726232207151417163332373635343617260706072216333e010212242d4b1718141b63422422210f0412123a311246194e3e301f181f32436e69301f7f10431453342efed6452724040313080c09090901010d0b0b040b0a0a100a04150425d814192f461c0f3c200c263f42151b25100912161510100f022a0a14190301110f08140176495266220d0d0a331b5c56355e044f1d3f2b352c041458456e5845647ea97c526aaa670d1a50458c305850563a1a1640051724232824323b2b2b0f1612131f05030a011731222b683b4c840c2393321e35450e4f133e4a201c15020a2802151a010406240007001200130216030600240030004c005500650074007e008d403f017f7f4080007d786d665a4f3b2d266b514d44392b251b6002560a023e3d0702417a025d5b6675035631020053041337042169046476047321011300011b46762f3718003f3f2ffd2ffd10fd10fd012ffd2ffd3c2f3cfd2ffd2f3cfd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b9001b007f496861b0405258381137b9007fffc038590114060706070615141615140706260706070623222726272603263534373637363332171607270706070607161736373637342726272623220710133637353426353426353437363736373e0103262322071631323613140706072734353426353437363332072e01232207162332373637363332172706270615141615360216504122420105130d320b0620180d0c1714070c1110050c524128954c5737170c2b341e4a170838373b32322943320d9f492c4244060a1f15152f322f4af319020e75210d548e3a33390c0c24072f641a062713102823010508061411090b0c11142903044d01f34672140c1603041c721c26050401020109071d19101c010cf55314070f0b083a43fe020221130a10170f141317e93f2c26120d18fef4fea30c06071658160a2609100502020814137efe362611271301fd35241e020b011e1659161404013c1016092305010202250c0102080f0a250a1e000700010016021b03030022003f0043004e006d0079009100b8405601929240932176534f4d4643413c3a09918d8b7a7872584d43413e25211d4b4d09414142404041550e837402626a02621102323202132a021b468302627005667e056649040d2e041736044489045c17010300011146762f3718003f3f2ffd2ffd10fd2ffd2ffd10fd012ffd3c2ffd2ffd10fd10fd10fd10fd872e08c40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b900110092496861b0405258381137b90092ffc03859250e01232227262726270607062322272635343736373633321716151407161716151427263534363736353427262322070615141716333237363332173637260f013f010522271e0133323736370637222726270615141615140706232227262726353437363332171615140706032623220716151417363534073427262322070e01151417161716333237263534373617020b05490d05160e0f0804193e302d1a1f7e03053a456773453910060e3769020f0103333e64262479131a86305711030c3d12231714032904fee8242409151770280104414208150912273b2e29151c111b0e0a1b254c472118050734051114053d0d032c171d381e08040a080b140a11140a1f21231b6c0e48150e0e0702150c090e37e02c3972667b826c7c6e1f060c311a196809010b2b0a1b3670647a1852de2471952e0932172d1577132a17310b140c2409122ad31f0e0f18070248031114110c13503a37584057543c5026263d011d030a24a70f0d251ba1a7412f3c251f3e192d384d0b060620111a2d310700070001fff701f0031700330064006a00730083008f009c00b34057019d9d409e0098938d6965575352501184716b675f5948062402137d02749002740802506a17150313025034020096027a8c8a029a7705814d051c8605817204203c042c4a0471706b002c011900201e1c030d00012446762f3718003f173c3f3f3f2f3cfd10fd10fd2ffd10fd10fd012ffd3c2ffd2ffd2ffd173c10fd2ffd10fd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b90024009d496861b0405258381137b9009dffc0385901140706070615161514070e010726272627061514151615142322262326070623222e01353413123736373633321716171617160734272627222726232207060706070607060706171633321633321633363733161716173637262726272635343736373603363726270f0126272e012b0117360114062322263534363534373633321607262306230607061f013e012734262714061514173633343601f03b0e211c64090c6215181f250d03011d0a2a09080e11050f152c282a0b051a151013232a0b75313d1f131e39016f53070c15070d1011120701050501060b041c030f241111080a0e3b46081c380b1a022a2328301b289405042b3c0923020508530c1a1427010a643c13100b240832253522180f14020b01030301182e64170104030c0a030231704410161301a128220d0f35051c3a47150a1b0a16170c550a0101010b460a2c012f0136140a07060809020e283144152033121610072953727283610a201b0f03040690910e738a0d10231e3b0543380b022931273afe0903045d7109ec090f030b1d01023d3b520b131b6e1c19060130311201030e18320f043a1c0427030f3c101a2002104500040011003201ea0310003a0044006f007d0086403b017e7e407f00766651413b2e1076696852433c3b0e2b0e6033024d450200701602605a022031054f5605257c04061304646b047274062501010e46762f3718003f2f2f3cfd2ffd10fd10fd2ffd012ffd2ffd3c2ffd2ffd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e3130014968b9000e007e496861b0405258381137b9007effc0385901140706070623222726272627263534373216333236353427262726272627263534373e0133321716171615140623222623221514171e01171e010335342627262322071613342726272627263534333217373427262322070615141716171615140706232227060715163332373e01072627162322271617161716333201ea09070828ce1c384507050a1c3d0c7a340d20120e0e3b3a33201e0f10a62e2c343c130f2b1201601d10302344160b2b6902011d071619276024133a47142c5e2e331c3a3414275e4f494444491d192240650e1f535d3d2034427b1a11315d5458100c16312d194e010d131a1516830708090d183b0625704d1f0d0e0704051c1d20443f271e2428611416211a431237240c161e1325231168011407030d020f0f01fece4f2e181d230f222d3f16390d1312372f454e2c201f28422113114622480629070a5a940c0102241e170106060000040007000902970300003a0068007300800096403f0181814082007b756e6a6762570c087b75746e6a69605d554a491f1e7779061f1e1e1f797b061f1e1e1f5002263c3b0200454404311a04182f011800012646762f3718003f3f10fd2ffd3c012ffd3c2ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b900260081496861b0405258381137b90081ffc0385901140706070e022322272627060706070607060706070623222726272637132e0127262726353437363736373e013332171617161716171617160735262726272627262b010607061d01161716171615140615060716173637363736273426353633321633321736253506070607363736373617350607060706073637363736029711080b0308280821293605060f050e0a0b0614061a1e0c132b1d1d2302490d2712212133080903050f0234053e270d4c59232e61203a0a1d20381d1d3b7e593135030a0a2d68100f150b1035284c1924060c0301030111021c052e6b18fdda0f04080f0a0b070807a8041b011a0f1f0f121212240287294811180e101c0c11013d72212921201b350a191b140e0e0e150199130f0609090f1103151a0c1d39061703011317070815050f032817030c0a050a1e160e2621031102260304050d022907a1e30e1947892384220e0112030d09154d7d0a05053236050a12231fbd08020e068a5fad0a12396bd20000020013003e02bb02f8002d005800584021015959405a0045424030283e2e1c0022023849021124053651050a0a1501011146762f3718003f2f10fd2ffd012ffd2ffd2e2e2e2e002e2e2e2e2e3130014968b900110059496861b0405258381137b90059ffc0385901140706070607060706232226272627263534373637161716171e011514070607061516333237363716171617162726270607060706232235343736373637262716232226232207061514171617161716333237363736373602bb2e0c0c0f12486f2c2f52922d0c0a0823252936354e0c05211c1d0309012222361e1e407d0a0a0947295116281617253f5a10100c0d13161e2056051005172b211a0b191b34302a6f524b16031e1501ff327c2120241964240d474212312c1c5389943604040814074804035a600d281e37a66768091b1234305f050b43874e233a7a204c48231f4009010108a87f731435182619110f554d71106449000003000c00030289030f003b00570067007b403201686840690065625852463e372f5f59584e3c281a004e4f06161515162b02484e051c504f045f5e221f011c010c00011a46762f3718003f3f3f3c2f3cfd3c10fd012ffd872e0ec40efc0ec4012e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9001a0068496861b0405258381137b90068ffc0385901140706070615060706070623222726272e012726270326272635343332163332363332171617163114061514171617363736373637363332161716272627060706070607062322272627262726071333361736373637360135342637262b011e01333a01333216028902022a352a5b1b1a2b1615404509042405030532060708130a270a0b2e0c22140c171204060605371a2c1d081505080d93040a2711720d241f1f202036080c010710060b7f144908376d396a152b20ff000a015b172e0b181e061f060c25023c02070a425201509c2f2f47070906023f13092c01972f303827180b020f0a231d071b072f483c3b532b473b1729054108160b0a2a2a3a302f37375b0a61ba2d5a1201fd95011251a62a5237fe0707071e090f162a0400040015005202f802fb003f0073007c008600874038018787408800766c656157504842352b817d79745b5a401e005b5d061e1c1c1e7b040a8404144d042f560421810e0479780a3a3901011e46762f3718003f3c2f2f3cfd3c2ffd2ffd2ffd10fd01872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b9001e0087496861b0405258381137b90087ffc03859011407060706070607062322272627060706220623222726272627262726273e0133321f011e0117161716173637363332171617161736373637333216171e01272627060706070623222627262322062322272627262f012606271516171617161736373633321716173616333237363736373603262706072316333227262726271e0133323602f817111101130f0b097c2b120120100f14274f141a23200a0d0d1006172e0b72110324060e35080c0d100607070618262b0a0d0f050d191e0a040b8104071d43224315151f130a050c28051d1b033e1411130b0a1c1b0c164216142c0e26376c1010190a0b170c0d0c2d093f0a14171010093f070a3050040f1b02ad0509097e0c19180e3b024429594142017254151115013d16161c0225211d264d5c1a61c30719020103230d11616e1411100912050f1404416f88163c060b5d5b112162628e241471020a81643e3e732d010115010756b1509e060a2221353b24240103193482616127fe170b180d011c0e0b0e040c111d050000050019001002d902f1002d0056005f0067006f0088403a0170704071006c6b6865605e594f3b363228246c696866655754423f2e180400616002084402165102085a59021c4b050e460511200b00011646762f3718003f2f2ffd2ffd012ffd3c2ffd2ffd10fd3c2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900160070496861b0405258381137b90070ffc038590114070607161716151406232226232206232226272635343726272635343e0133221716173037363332171617162734272627060706232226272627060706151416151407161736373e0133321716173635342635343605262715141e0133320135342726271516053526312314171602d9432e2e27261a7d150c92010ec00a0d5804167c1d1e1f0e940b010d543476600e112d2a070a30201d0d126964060a143524220f3238819d2e233060023802064d2e2f507cbcfe162d300b40040601483826262bfed53701100901e6163722232f2f2c4b135c98705a104423156526262e2a3a1a7601625f5e4d3633161c0e0a28250c0b5d581e563b2b0b2c2f0402b50c08873f251b360126472b2b4a0504b5040aa89d3a4313121350fea809163a2625192f261e4620180f0003001300060278030a0032005800650090403e016666406731623b37332a6460553d31213335062c2a2a2c3d3f06211f1f214d020818034646021542021b494705605f5c03592e012501100d0a00012146762f3718003f3c3c3f3f2f173cfd3c012ffd2ffd10fd2ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e002e2e2e2e2e3130014968b900210066496861b0405258381137b90066ffc038590106070e0115140607062322262322062322272e0135343635343635342726272627363736371e011716173637363332161706270607062322272627060716171e0115140615071732333237363f01363736373e01353427260322062322262b01161736272601fe15151b0e14030c300a24060b2e0b1b0a041d080c100d0c01710247421440241108121637450c1f7901454f1a424f0e0c09214b046f204311230c0806096b1a01050a0804020119149e231f9c0a2509081c0733071098090501ca17181e284411e0041502030c0550061b6e1b134d13131a151401e40f1e1d01222a411f3c24566a72206dda2a687b1357ab012d42841a381e134810a7030309885f2e0601120fd810081a16fd7502040f1b02011200040006000f025c03130032003a00430071008840380172724073006a695c564a3b37332a67635a544c44403f3b37332a26150c0b00333506262323260c05611005262e043f461f010500011546762f3718003f3f2f3cfd2ffd2ffd01872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b900150072496861b0405258381137b90072ffc03859250706070623222e012726271306070623222e023534373637363736373633321716171e0117060706073637363332171e01032627262716171613262726271514171627262706070607263534373637363736353427060706071617363332363316151407060716173336373637363736025c0149829c290a3718151204c8193f3b1a093508161310102fbb0549331c14171b08011d010a3229540c443e0608340612480c0d07170512024f040b08180f091f0510215e522b113630102646061520ac7d4e0b0c1f050fb228116c4e3d01270628344415293b5dba092837431c11403819014a0218173b19690b0f0604030f1e01100b0a0b0f019c07134c4386031715270c58018e42460a0c354d04fe651a2a100f0a27190f031d380b1a1613040b055c501b34690b080c74061912143335073d070917b4835e0f6a0f0e12070d1c2b00ffff0018ffdc010f03020006000b000000030014003e015c02ec001e0032003a004a4018013b3b403c003531282737332a1f0d003904031103010d46762f3718002f2f10fd012e2e2e2e2e2e002e2e2e2e3130014968b9000d003b496861b0405258381137b9003bffc03859250e0123222e0127262726272635343736233217161716171617161716171627262726272627262723060716171617161317361726232207162332015c043d100e270f23151503352e075408130e0512030a1b1b1c0b0629243a1a1a210c0f200e23070d1a0205111e2851040d4a10020d2a1b0409600b171315804e4f0aa48d0c0505181507230e1e4c4b503c1e62570f3a627a232453305b060c0d1b2d5987fef1030815101b09ffff0013fff900f303150006000c0000ffff002e0045021f02a7000600060000ffff003a0011021b00e900070010fffdff080004003501b0013103560024002f004c00570077403301585840590a51432b52514d4327154602292e2503180e0c030a31300329390223494b051a56041a37350402041a2701012346762f3718003f2f2f2ffd3c10fd10fd3c012ffd2ffd3c2f173cfd3c10fd2e2e2e2e2e2e002e2e2e3130014968b900230058496861b0405258381137b90058ffc0385913363736171633321716151407141514070623220f01061635142322262726272627263534173427161532173436351407353427262322330615141606171617161716172e013534361716313217262726271514171633323f070b080d14024d194f010103110a0c01022f481861040b0b160506e11d040b0b033507102a49060b0501050303030d1f3f08220c0a0e084020060a1614150c07034b07020201010849281414151422041606081864011541181e1e3f28312c38690d22453a04061e0508103660040a150e052222190f0f2225571b0b8c120a050202c5373c040d0b11363900ffff0000001502a8030d000600240000ffff001e000502310309000600250000ffff00170067022902f7000600260000ffff000b000f023f0313000600270000ffff0007000a0225031b000600280000ffff001b003402640302000600290000ffff001e002302ae02ea0006002a0000ffff0027003c02aa02dd0006002b0000ffff000d0007024a03170006002c0000ffff000f001d027703150006002d0000ffff00250013026802fd0006002e0000ffff002d001e02ad03020006002f0000ffff000c001b031602f9000600300000ffff0008000d027e0308000600310000ffff000c002f0212030d000600320000ffff0012001302160306000600330000ffff00010016021b0303000600340000ffff0001fff701f00317000600350000ffff0011003201ea0310000600360000ffff0007000902970300000600370000ffff0013003e02bb02f8000600380000ffff000c00030289030f000600390000ffff0015005202f802fb0006003a0000ffff0019001002d902f10006003b0000ffff001300060278030a0006003c0000ffff0006000f025c03130006003d0000ffff0018ffdc010f03020006000b0000ffff002b0051015d02dc000600120000ffff0013fff900f303150006000c0000ffff002e0045021f02a7000600060000001d0012fff30328030b00300056006c007c009200a200a900b200c200cc00db00e300e600ed01790185019901ab01bf01d501df01e501e901f201fe020a0213021f022600000114070607060706070623220623220622060706272623222726272627262726353437363736333216321633321716171607342726272627262322262322070607061514171e0117163332363236323632373637363736031406232227343736372e01353437161532173637320714232226233c013516151636333216270e011514173237331407062b01222726353433321607062322353437363736343732171635272206232637331714232227353237162714070615220623342635343736371617060730263530363317270607060726273236333216173e0127072335263635320127372506072637273301140706071407060706070617062322262322062322262322073e013332163b0132373e01352635363736373637141736353426353437362322071633060706233227363534271e01333237363715333637060715301633303736373427262707060736373637363723060706070607062b013633321633323736373637363332171617161716071e013316250623223734373e0137331601140706072206232227263534373e01333217160f01262726232215141706273526363332150722262322151432170623222635343633321615270607163332171526230722273536372e01273516171335262322071516333227362707153317270717273427261514173336013522262322151417363736253427061514161532363332012226232207163332173423220615163332343332272e01232207320328141e2417200a28331102280d030b080f032a2b0e0a1e382b1d2828361211545b981e4f040e07300314505b2f2812130f353a3d370804420477516241301723a1631c4104100809082f042a4532191627922006050e01050c021304130305060c0b43190417050f030b0308118b07240805090b01050a0b0d08062c040b3e28071113071003050108054a010b0107060ec60c040e0a0d07bf0601010d0303070408087f081203100a039f0505060b0f110105040409030b0b39040e01070801520b05feba050f0104031401c207111e0512241e1f0602250b031c04044903224e131628065006083610271b200502023663190d0304070b0c0c020d111c01030808202604461f12051c040a070404180b18080701051c062104365c06123f14170a0a0e0532052c311a032f28064114030402031d0a16332d223f0f2f30261a0d18060a031a0118fe2329060f02170c05060b0301880a0306020c05120b090204210811070555070207050515050d08011b05204f0623030a2f0408101417161c060e52112321040b04230f09060e0c28032d041d32ea070504080806068f030d070e6c110211a60a0e040d070124050e040a07010c0dfe200b10030102041101300516030c07080b12670f0d110411040311a1030f030f032801804c364f2a1b1c09191f0f0304010303011a13141c2e3e474435896c751b06060d2c3c60545c2b4a384248191612252f6f5263423d61880e0303030f13203e202c4f0151084a07020402080c360304040c1c060c19171d040d390e081101051e0a08020905080908030a100c072614340a1b160d02080a04050512010403060ce20b070b0607b902070b2a03030b041820010408c3050b0f090303b61313160f05340414080325020e09050201fe8d051ff909072e1b05fee7180a1024050a160201010405170f0c210b0720310d02030204030205020f0328050d0f090423040b0c0719030901071402110d0b020d0c0a091f0609080e110314040e070a402a060315110c0302050a0113150f02221e0c030613251d0e191f1a220d21090a060614bd191a1717020c111afe1c17130405071712140a070c171a0f0407010f0b2c1b1307044f061b1723030922040b24111d15160611112709040a0503070e14220707070a060901c91d07071a07260806070b950a040a87110103190b0708fee81403120b1401030bf50f05130b040a0102feba040e045827181126032c060e14ffff0020013800d801ec0007000dfff7ff08ffff003501b001310354000600430000ffff0013019c012b03440006000a0000ffff0013ff5c012b01050007000a0000fdc1ffff003501b001310354000600430000ffff003501b0025e035400260064000000070064012d0000ffff0013019302630344002600650000000700650137fff7ffff0012000202e200c80026001100000027001100fb00030007001101f0fffd000000000000007c0000007c0000007c0000007c000002400000025a0000063a0000064a0000065a0000066a0000067c0000075c000008220000090a00000aec00000c2000000d7600000e4200000f3e000010e60000131a0000157600001788000019dc00001c2c00001e400000202c000021f40000246e000024860000249e000024ae000024c6000024d600002730000027400000298a00002b9000002d5200002f2600003108000032fa0000356400003794000039d800003bce00003da600003f240000419a000043f2000045c4000047c400004a1800004c9200004e7c00005094000051f4000053a0000055b8000057800000593800005b1800005b2800005c2c00005c3c00005c4c00005c5e00005dce00005dde00005dee00005dfe00005e0e00005e1e00005e2e00005e3e00005e4e00005e5e00005e6e00005e7e00005e8e00005e9e00005eae00005ebe00005ece00005ede00005eee00005efe00005f0e00005f1e00005f2e00005f3e00005f4e00005f5e00005f6e00005f7e00005f8e00005f9e00005fae00006598000065aa000065ba000065ca000065dc000065ec000066040000661c0000663c01f4003f00000000033d0000033d0000012f0024027c00100246002e0246002e0246002e0246002e0148001301280018011a001300f70029023a0018014800130246003c010b0012017c002b02510006022c002902740021020600100246001602680018023400180248000c023400030209000c010b000f01480013012800180246003c011a001301fb00010246002e02b60000024a001e02460017024e000b025100070282001b02df001e02c400270262000d0291000f0291002502ca002d0330000702960008023d000c02370012022e0001020900010209001102b0000702e4001302ad000c030f001502f3001902850013027c00060128001801760014011a00130246002e0246003a0159003502b60000024a001e02460017024e000b025100070282001b02df001e02c400270262000d0291000f0291002502ca002d0330000c02960008023d000c02370012022e0001020900010209001102b0000702e4001302ad000c030f001502f3001902850013027c000601280018017c002b011a00130246002e0343001200f7002001590035014800130148001301590035027c0035027c0013030100120002000000000000ff7b00140000000000000000000000000000000000000000006b0000000100020003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f006000610086008800b600b700c4010200b400b500ab0d71756f7465726576657273656400000000000300000000000004cc000100000000001c00030001000004cc000604b0000000000253000100000000000000000000000000000001000300000000000000020000000000000000000000000000000000000000000000000000000000000001000000000003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f0060006100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000640065006600670068006900000000000000000000006a0004011c0000000e000800020006007e00a700b62010201d2026ffff0000002000a700b6201020182026ffff0000000000000000000000000001000e00ca00ca00ca00ca00d4ffff0003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f00600061006200630010006400650066006700680069006a0000000000010000001a0001000200060001000600320025ffd90032003cff9900000000001000000070090805000707030605050505030303020503050203050506050506050505050203030503050506050505050607060506060607060505050505060706070706060303030505030605050505060706050606060706050505050506070607070606030303050802030303030606070000000a0805000808030606060606030303020603060304060606050606060606050303030603050607060606060607070607070708070606060505070707080806060304030606030706060606060707060707070807060606050507070708080606030403060802030303030606080000000b0906000909030706060606040303030604060304070607060607060606060304030603060608060606070708080707070809070606060606080808090807070304030606040806060607070808070707080907060606060608080809080707030403060903040404040707080000000c0a06000a0a04080707070704040303070407030507070806070707070706030404070306070807070707080908070808090a080707070606080908090908080404030707040807070707080908070808090a08070707060608090809090808040503070a03040404040808090000000d0b07000b0b04080808080804040403070408030508070807080807080707030404080407080908080808080a09080909090b090707070707090a090a0a08080405040808040908080808080a09080909090b090707070707090a090a0a0808040504080b030404040408080a0000000e0c07000c0c04090808080805040403080508040508080907080908080807040504080407080a08080808090a0a0909090a0b0908080807070a0a0a0b0b09090405040808050a08080808090a0a0909090a0b0908080807070a0a0a0b0b0909040504080c030505050509090b0000000f0d08000c0c050a0909090905040404090509040609080908090908090808040504090408090a090909090a0b0b090a0a0b0c0a09090808080a0b0a0c0b0a0a0406040909050a090909090a0b0b090a0a0b0c0a09090808080a0b0a0c0b0a0a040604090d04050505050a0a0c000000100d08000d0d050a0909090905050504090509040609090a08090a09090908040505090508090b090909090a0c0b0a0b0b0b0d0b09090908080b0c0b0d0c0a0a0506050909060b090909090a0c0b0a0b0b0b0d0b09090908080b0c0b0d0c0a0a050605090d04060505060a0a0c000000110e09000e0e050b0a0a0a0a060505040a060a05060a090b090a0a0a0a0a090506050a05090a0c0a0a0a0a0b0c0c0a0b0b0c0e0b0a0a0909090c0d0c0d0d0b0b0506050a0a060c0a0a0a0a0b0c0c0a0b0b0c0e0b0a0a0909090c0d0c0d0d0b0b0506050a0e04060606060b0b0d000000120f09000f0f050b0a0a0a0a060505040a060a05070b0a0b090a0b0a0b0a090506050a05090a0c0b0a0b0b0c0d0d0b0c0c0d0f0c0a0a0a09090c0d0c0e0e0c0b0507050a0a060c0b0a0b0b0c0d0d0b0c0c0d0f0c0a0a0a09090c0d0c0e0e0c0b0507050a0f04060606060b0b0e00000013100a001010060c0b0b0b0b060605050b060b05070b0b0c0a0b0c0b0b0b0a0506060b050a0b0d0b0b0b0b0c0e0d0c0c0c0e100d0b0b0b0a0a0d0e0d0f0e0c0c0607050b0b070d0b0b0b0b0c0e0d0c0c0c0e100d0b0b0b0a0a0d0e0d0f0e0c0c0607050b1005070606070c0c0f00000014110a001111060d0c0c0c0c070606050b070c05080c0b0d0a0c0c0b0c0b0a0507060c060a0c0e0c0c0c0c0d0f0e0c0d0d0e100d0b0b0b0a0a0e0f0e100f0d0d0607060c0c070e0c0c0c0c0d0f0e0c0d0d0e100d0b0b0b0a0a0e0f0e100f0d0d0608060c1105070707070d0d0f00000015120b001111060d0c0c0c0c070606050c070c06080c0c0d0b0c0d0c0c0c0b0607060c060b0c0f0c0c0c0c0d0f0f0d0e0e0f110e0c0c0c0b0b0e100e10100e0d0608060c0c070f0c0c0c0c0d0f0f0d0e0e0f110e0c0c0c0b0b0e100e10100e0d0608060c1205070707070d0d1000000016120b001212070e0d0d0d0d070706050d070d06080d0c0e0b0d0e0c0d0c0b0607070d060b0d0f0d0d0d0d0e10100d0e0e10120f0d0c0c0b0b0f100f11110e0e0708060d0d080f0d0d0d0d0e10100d0e0e10120f0d0c0c0b0b0f100f11110e0e0708060d1205080707080e0e1100000017130c001313070f0d0d0d0d080706060d080d06090e0d0e0c0d0e0d0d0d0c0608070d060c0d100d0d0e0e0f11100e0f0f10130f0d0d0d0c0c10111012110f0f0709060d0d08100d0d0e0e0f11100e0f0f10130f0d0d0d0c0c10111012110f0f0709060d1306080808080f0f1200000018140c001414070f0e0e0e0e080707060e080e06090e0d0f0c0e0f0e0e0e0d0608070e070c0e110e0e0e0e0f12110f10101114100e0e0d0d0d11121013120f0f0709070e0e08110e0e0e0e0f12110f10101114100e0e0d0d0d11121013120f0f0709070e1406080808080f0f120000000001029c01900005000002bc028a0000008f02bc028a000001c5003201030000000004000000000000000000000300000000000000000000000046726f670040002020260355ff5c0000035500a4000000010000000000000001000080000000033d02f10000600002dd0275416374696f6e204a61636b7320202020ffffffff37fffffe4143545230300000000000000001000000010000fae7a6eb5f0f3cf5000003e800000000b2050dda00000000b20549240000ff5c03280356000000030002000100000000000100000356ff38000003430000000d032800010000000000000000000000000000006b00010000006b0227001d01030009000200080040000a00000097013000030003";  
  491.         }  
  492.     }  
  493.   
  494.     /** 
  495.      * 字符和干扰线扭曲 
  496.      *  
  497.      * @param g 
  498.      *            绘制图形的java工具类 
  499.      * @param w1 
  500.      *            验证码图片宽 
  501.      * @param h1 
  502.      *            验证码图片高 
  503.      * @param color 
  504.      *            颜色 
  505.      */  
  506.     private static void shear(Graphics g, int w1, int h1, Color color)  
  507.     {  
  508.         shearX(g, w1, h1, color);  
  509.         shearY(g, w1, h1, color);  
  510.     }  
  511.   
  512.     /** 
  513.      * x轴扭曲 
  514.      *  
  515.      * @param g 
  516.      *            绘制图形的java工具类 
  517.      * @param w1 
  518.      *            验证码图片宽 
  519.      * @param h1 
  520.      *            验证码图片高 
  521.      * @param color 
  522.      *            颜色 
  523.      */  
  524.     private static void shearX(Graphics g, int w1, int h1, Color color)  
  525.     {  
  526.         int period = random.nextInt(2);  
  527.   
  528.         boolean borderGap = true;  
  529.         int frames = 1;  
  530.         int phase = random.nextInt(2);  
  531.   
  532.         for (int i = 0; i < h1; i++)  
  533.         {  
  534.             double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);  
  535.             g.copyArea(0, i, w1, 1, (int) d, 0);  
  536.             if (borderGap)  
  537.             {  
  538.                 g.setColor(color);  
  539.                 g.drawLine((int) d, i, 0, i);  
  540.                 g.drawLine((int) d + w1, i, w1, i);  
  541.             }  
  542.         }  
  543.     }  
  544.   
  545.     /** 
  546.      * y轴扭曲 
  547.      *  
  548.      * @param g 
  549.      *            绘制图形的java工具类 
  550.      * @param w1 
  551.      *            验证码图片宽 
  552.      * @param h1 
  553.      *            验证码图片高 
  554.      * @param color 
  555.      *            颜色 
  556.      */  
  557.     private static void shearY(Graphics g, int w1, int h1, Color color)  
  558.     {  
  559.         int period = random.nextInt(40) + 10// 50;  
  560.   
  561.         boolean borderGap = true;  
  562.         int frames = 20;  
  563.         int phase = 7;  
  564.         for (int i = 0; i < w1; i++)  
  565.         {  
  566.             double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);  
  567.             g.copyArea(i, 01, h1, 0, (int) d);  
  568.             if (borderGap)  
  569.             {  
  570.                 g.setColor(color);  
  571.                 g.drawLine(i, (int) d, i, 0);  
  572.                 g.drawLine(i, (int) d + h1, i, h1);  
  573.             }  
  574.         }  
  575.     }  
  576.   
  577.     /** 
  578.      * 获取透明度,从0到1,自动计算步长 
  579.      *  
  580.      * @param i 
  581.      * @param j 
  582.      * @return float 透明度 
  583.      */  
  584.     private static float getAlpha(int i, int j, int verifySize)  
  585.     {  
  586.         int num = i + j;  
  587.         float r = (float1 / verifySize, s = (verifySize + 1) * r;  
  588.         return num > verifySize ? (num * r - s) : num * r;  
  589.     }  
  590.   
  591.     /** 
  592.      * 生成指定验证码图像文件 - 本地测试生成图片查看效果 
  593.      *  
  594.      * @param w 
  595.      *            验证码图片宽 
  596.      * @param h 
  597.      *            验证码图片高 
  598.      * @param outputFile 
  599.      *            文件流 
  600.      * @param code 
  601.      *            随机验证码 
  602.      * @throws IOException 
  603.      */  
  604.     public static void outputImage(int w, int h, File outputFile, String code) throws IOException  
  605.     {  
  606.         if (outputFile == null)  
  607.         {  
  608.             return;  
  609.         }  
  610.         File dir = outputFile.getParentFile();  
  611.         if (!dir.exists())  
  612.         {  
  613.             dir.mkdirs();  
  614.         }  
  615.         try  
  616.         {  
  617.             outputFile.createNewFile();  
  618.             FileOutputStream fos = new FileOutputStream(outputFile);  
  619.             // outputImage(w, h, fos, code, "login"); //测试登录,噪点和干扰线为0.05f和20  
  620.             // outputImage(w, h, fos, code, "coupons"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  621.             // outputImage(w, h, fos, code, "3D"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  622.             // outputImage(w, h, fos, code, "GIF"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  623.             // outputImage(w, h, fos, code, "GIF3D"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  624.             // outputImage(w, h, fos, code, "mix2"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  625.             outputImage(w, h, fos, code, "mixGIF"); // 测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  626.             fos.close();  
  627.         }  
  628.         catch (IOException e)  
  629.         {  
  630.             throw e;  
  631.         }  
  632.     }  
  633.   
  634.     /** 
  635.      * 本地测试类,可以生成样例验证码图片供观看效果 
  636.      *  
  637.      * @param args 
  638.      * @throws IOException 
  639.      */  
  640.     public static void main(String[] args) throws IOException  
  641.     {  
  642.         File dir = new File("E:/logtest/verifies8");  
  643.         int w = 120, h = 48;  
  644.         for (int i = 0; i < 150; i++)  
  645.         {  
  646.             String verifyCode = generateVerifyCode(4);  
  647.             File file = new File(dir, verifyCode + ".gif");  
  648.             outputImage(w, h, file, verifyCode);  
  649.         }  
  650.     }  
  651. }  



调用的地方随机获取验证码样式:   分布式可以存放在redis

[java]  view plain  copy
  1. public class ValiCodeServlet extends HttpServlet  
  2. {  
  3.     private static final long serialVersionUID = 1L;  
  4.       
  5.     /** 验证码缓存key */  
  6.     public static final String RANDOMCODEKEY = "RANDOMCODEKEY";  
  7.   
  8.     private static final Logger logger = Logger.getLogger(ValiCodeServlet.class);  
  9.   
  10.     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  
  11.     {  
  12.         response.setContentType("image/jpeg");  
  13.         // 设置相应类型,告诉浏览器输出的内容为图片  
  14.         response.setHeader("Pragma""No-cache");  
  15.         // 设置响应头信息,告诉浏览器不要缓存此内容  
  16.         response.setHeader("Cache-Control""no-cache");  
  17.         response.setDateHeader("Expire"0);  
  18.           
  19.         try  
  20.         {  
  21.             // 生成随机验证码  
  22.             int charSize = 4;  
  23.             String verifyCode = RandomVerifyImgCodeUtil.generateVerifyCode(charSize);  
  24.               
  25.             if (StringUtils.isNotBlank(verifyCode))  
  26.             {  
  27.                 RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);  
  28.                   
  29.                 String key = request.getSession().getId() + "_" + RANDOMCODEKEY;  
  30.                 redisUtil.set(key, verifyCode.toString());  
  31.                 /** 设置sesionTooken,90s后失效 **/  
  32.                 redisUtil.expired(key, 90);  
  33.                   
  34.                 // 再次存cookie备份  
  35.                 CookieUtil.addCookie(request, response, RANDOMCODEKEY, verifyCode, 300);  
  36.             }  
  37.               
  38.             // 生成图片规格w宽 h高   
  39.             int w = 100, h = 40;  
  40.             int type = new Random().nextInt(7);   
  41.             if (type == 0)  
  42.             {  
  43.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "login");  
  44.             }  
  45.             else if (type == 1)  
  46.             {  
  47.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "GIF");  
  48.             }  
  49.             else if (type == 2)  
  50.             {  
  51.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "3D");  
  52.             }  
  53.             else if (type == 3)  
  54.             {  
  55.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "GIF3D");  
  56.             }  
  57.             else if (type == 4)  
  58.             {  
  59.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mix2");  
  60.             }  
  61.             else if (type == 5)  
  62.             {  
  63.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mixGIF");  
  64.             }  
  65.             else if (type == 6)  
  66.             {  
  67.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "coupons");  
  68.             }  
  69.             else  
  70.             {  
  71.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mixGIF");  
  72.             }  
  73.         }  
  74.         catch (Exception e)  
  75.         {  
  76.             logger.error(e.getMessage(), e);  
  77.         }  
  78.     }  
  79.   
  80.     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  
  81.     {  
  82.         doGet(request, response);  
  83.     }  
  84.   
  85. }  

GIF格式的老外的工具类: Encoder

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.OutputStream;  
  5.   
  6. /** 
  7.  * @author: lu
  8.  * @version:1.0 
  9.  */  
  10. public class Encoder  
  11. {  
  12.     private static final int EOF = -1;  
  13.   
  14.     private int imgW, imgH;  
  15.     private byte[] pixAry;  
  16.     private int initCodeSize;  
  17.     private int remaining;  
  18.     private int curPixel;  
  19.   
  20.     // GIFCOMPR.C - GIF Image compression routines  
  21.     //  
  22.     // Lempel-Ziv compression based on 'compress'. GIF modifications by  
  23.     // David Rowley (mgardi@watdcsu.waterloo.edu)  
  24.   
  25.     // General DEFINEs  
  26.   
  27.     static final int BITS = 12;  
  28.   
  29.     static final int HSIZE = 5003// 80% occupancy  
  30.   
  31.     // GIF Image compression - modified 'compress'  
  32.     //  
  33.     // Based on: compress.c - File compression ala IEEE Computer, June 1984.  
  34.     //  
  35.     // By Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)  
  36.     // Jim McKie (decvax!mcvax!jim)  
  37.     // Steve Davies (decvax!vax135!petsd!peora!srd)  
  38.     // Ken Turkowski (decvax!decwrl!turtlevax!ken)  
  39.     // James A. Woods (decvax!ihnp4!ames!jaw)  
  40.     // Joe Orost (decvax!vax135!petsd!joe)  
  41.   
  42.     int n_bits; // number of bits/code  
  43.     int maxbits = BITS; // user settable max # bits/code  
  44.     int maxcode; // maximum code, given n_bits  
  45.     int maxmaxcode = 1 << BITS; // should NEVER generate this code  
  46.   
  47.     int[] htab = new int[HSIZE];  
  48.     int[] codetab = new int[HSIZE];  
  49.   
  50.     int hsize = HSIZE; // for dynamic table sizing  
  51.   
  52.     int free_ent = 0// first unused entry  
  53.   
  54.     // block compression parameters -- after all codes are used up,  
  55.     // and compression rate changes, start over.  
  56.     boolean clear_flg = false;  
  57.   
  58.     // Algorithm: use open addressing double hashing (no chaining) on the  
  59.     // prefix code / next character combination. We do a variant of Knuth's  
  60.     // algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime  
  61.     // secondary probe. Here, the modular division first probe is gives way  
  62.     // to a faster exclusive-or manipulation. Also do block compression with  
  63.     // an adaptive reset, whereby the code table is cleared when the compression  
  64.     // ratio decreases, but after the table fills. The variable-length output  
  65.     // codes are re-sized at this point, and a special CLEAR code is generated  
  66.     // for the decompressor. Late addition: construct the table according to  
  67.     // file size for noticeable speed improvement on small files. Please direct  
  68.     // questions about this implementation to ames!jaw.  
  69.   
  70.     int g_init_bits;  
  71.   
  72.     int ClearCode;  
  73.     int EOFCode;  
  74.   
  75.     // output  
  76.     //  
  77.     // Output the given code.  
  78.     // Inputs:  
  79.     // code: A n_bits-bit integer. If == -1, then EOF. This assumes  
  80.     // that n_bits =< wordsize - 1.  
  81.     // Outputs:  
  82.     // Outputs code to the file.  
  83.     // Assumptions:  
  84.     // Chars are 8 bits long.  
  85.     // Algorithm:  
  86.     // Maintain a BITS character long buffer (so that 8 codes will  
  87.     // fit in it exactly). Use the VAX insv instruction to insert each  
  88.     // code in turn. When the buffer fills up empty it and start over.  
  89.   
  90.     int cur_accum = 0;  
  91.     int cur_bits = 0;  
  92.   
  93.     int masks[] =  
  94.     {  
  95.             0x00000x00010x00030x00070x000F0x001F0x003F0x007F0x00FF0x01FF0x03FF0x07FF0x0FFF0x1FFF0x3FFF0x7FFF0xFFFF  
  96.     };  
  97.   
  98.     // Number of characters so far in this 'packet'  
  99.     int a_count;  
  100.   
  101.     // Define the storage for the packet accumulator  
  102.     byte[] accum = new byte[256];  
  103.   
  104.     // ----------------------------------------------------------------------------  
  105.     Encoder(int width, int height, byte[] pixels, int color_depth)  
  106.     {  
  107.         imgW = width;  
  108.         imgH = height;  
  109.         pixAry = pixels;  
  110.         initCodeSize = Math.max(2, color_depth);  
  111.     }  
  112.   
  113.     // Add a character to the end of the current packet, and if it is 254  
  114.     // characters, flush the packet to disk.  
  115.     void char_out(byte c, OutputStream outs) throws IOException  
  116.     {  
  117.         accum[a_count++] = c;  
  118.         if (a_count >= 254)  
  119.             flush_char(outs);  
  120.     }  
  121.   
  122.     // Clear out the hash table  
  123.   
  124.     // table clear for block compress  
  125.     void cl_block(OutputStream outs) throws IOException  
  126.     {  
  127.         cl_hash(hsize);  
  128.         free_ent = ClearCode + 2;  
  129.         clear_flg = true;  
  130.   
  131.         output(ClearCode, outs);  
  132.     }  
  133.   
  134.     // reset code table  
  135.     void cl_hash(int hsize)  
  136.     {  
  137.         for (int i = 0; i < hsize; ++i)  
  138.             htab[i] = -1;  
  139.     }  
  140.   
  141.     void compress(int init_bits, OutputStream outs) throws IOException  
  142.     {  
  143.         int fcode;  
  144.         int i /* = 0 */;  
  145.         int c;  
  146.         int ent;  
  147.         int disp;  
  148.         int hsize_reg;  
  149.         int hshift;  
  150.   
  151.         // Set up the globals: g_init_bits - initial number of bits  
  152.         g_init_bits = init_bits;  
  153.   
  154.         // Set up the necessary values  
  155.         clear_flg = false;  
  156.         n_bits = g_init_bits;  
  157.         maxcode = MAXCODE(n_bits);  
  158.   
  159.         ClearCode = 1 << (init_bits - 1);  
  160.         EOFCode = ClearCode + 1;  
  161.         free_ent = ClearCode + 2;  
  162.   
  163.         a_count = 0// clear packet  
  164.   
  165.         ent = nextPixel();  
  166.   
  167.         hshift = 0;  
  168.         for (fcode = hsize; fcode < 65536; fcode *= 2)  
  169.             ++hshift;  
  170.         hshift = 8 - hshift; // set hash code range bound  
  171.   
  172.         hsize_reg = hsize;  
  173.         cl_hash(hsize_reg); // clear hash table  
  174.   
  175.         output(ClearCode, outs);  
  176.   
  177.         outer_loop: while ((c = nextPixel()) != EOF)  
  178.         {  
  179.             fcode = (c << maxbits) + ent;  
  180.             i = (c << hshift) ^ ent; // xor hashing  
  181.   
  182.             if (htab[i] == fcode)  
  183.             {  
  184.                 ent = codetab[i];  
  185.                 continue;  
  186.             }  
  187.             else if (htab[i] >= 0// non-empty slot  
  188.             {  
  189.                 disp = hsize_reg - i; // secondary hash (after G. Knott)  
  190.                 if (i == 0)  
  191.                     disp = 1;  
  192.                 do  
  193.                 {  
  194.                     if ((i -= disp) < 0)  
  195.                         i += hsize_reg;  
  196.   
  197.                     if (htab[i] == fcode)  
  198.                     {  
  199.                         ent = codetab[i];  
  200.                         continue outer_loop;  
  201.                     }  
  202.                 }  
  203.                 while (htab[i] >= 0);  
  204.             }  
  205.             output(ent, outs);  
  206.             ent = c;  
  207.             if (free_ent < maxmaxcode)  
  208.             {  
  209.                 codetab[i] = free_ent++; // code -> hashtable  
  210.                 htab[i] = fcode;  
  211.             }  
  212.             else  
  213.                 cl_block(outs);  
  214.         }  
  215.         // Put out the final code.  
  216.         output(ent, outs);  
  217.         output(EOFCode, outs);  
  218.     }  
  219.   
  220.     // ----------------------------------------------------------------------------  
  221.     void encode(OutputStream os) throws IOException  
  222.     {  
  223.         os.write(initCodeSize); // write "initial code size" byte  
  224.   
  225.         remaining = imgW * imgH; // reset navigation variables  
  226.         curPixel = 0;  
  227.   
  228.         compress(initCodeSize + 1, os); // compress and write the pixel data  
  229.   
  230.         os.write(0); // write block terminator  
  231.     }  
  232.   
  233.     // Flush the packet to disk, and reset the accumulator  
  234.     void flush_char(OutputStream outs) throws IOException  
  235.     {  
  236.         if (a_count > 0)  
  237.         {  
  238.             outs.write(a_count);  
  239.             outs.write(accum, 0, a_count);  
  240.             a_count = 0;  
  241.         }  
  242.     }  
  243.   
  244.     final int MAXCODE(int n_bits)  
  245.     {  
  246.         return (1 << n_bits) - 1;  
  247.     }  
  248.   
  249.     // ----------------------------------------------------------------------------  
  250.     // Return the next pixel from the image  
  251.     // ----------------------------------------------------------------------------  
  252.     private int nextPixel()  
  253.     {  
  254.         if (remaining == 0)  
  255.             return EOF;  
  256.   
  257.         --remaining;  
  258.   
  259.         byte pix = pixAry[curPixel++];  
  260.   
  261.         return pix & 0xff;  
  262.     }  
  263.   
  264.     void output(int code, OutputStream outs) throws IOException  
  265.     {  
  266.         cur_accum &= masks[cur_bits];  
  267.   
  268.         if (cur_bits > 0)  
  269.             cur_accum |= (code << cur_bits);  
  270.         else  
  271.             cur_accum = code;  
  272.   
  273.         cur_bits += n_bits;  
  274.   
  275.         while (cur_bits >= 8)  
  276.         {  
  277.             char_out((byte) (cur_accum & 0xff), outs);  
  278.             cur_accum >>= 8;  
  279.             cur_bits -= 8;  
  280.         }  
  281.   
  282.         // If the next entry is going to be too big for the code size,  
  283.         // then increase it, if possible.  
  284.         if (free_ent > maxcode || clear_flg)  
  285.         {  
  286.             if (clear_flg)  
  287.             {  
  288.                 maxcode = MAXCODE(n_bits = g_init_bits);  
  289.                 clear_flg = false;  
  290.             }  
  291.             else  
  292.             {  
  293.                 ++n_bits;  
  294.                 if (n_bits == maxbits)  
  295.                     maxcode = maxmaxcode;  
  296.                 else  
  297.                     maxcode = MAXCODE(n_bits);  
  298.             }  
  299.         }  
  300.   
  301.         if (code == EOFCode)  
  302.         {  
  303.             // At EOF, write the rest of the buffer.  
  304.             while (cur_bits > 0)  
  305.             {  
  306.                 char_out((byte) (cur_accum & 0xff), outs);  
  307.                 cur_accum >>= 8;  
  308.                 cur_bits -= 8;  
  309.             }  
  310.   
  311.             flush_char(outs);  
  312.         }  
  313.     }  
  314. }  

GifDecoder:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.*;  
  4. import java.awt.image.BufferedImage;  
  5. import java.awt.image.DataBufferInt;  
  6. import java.io.BufferedInputStream;  
  7. import java.io.FileInputStream;  
  8. import java.io.IOException;  
  9. import java.io.InputStream;  
  10. import java.net.URL;  
  11. import java.util.ArrayList;  
  12.   
  13. /** 
  14.  * <p> 
  15.  * </p> 
  16.  * 
  17.  * @author: lyf
  18.  * @version:1.0 
  19.  */  
  20. public class GifDecoder  
  21. {  
  22.     /** 
  23.      * File read status: No errors. 
  24.      */  
  25.     public static final int STATUS_OK = 0;  
  26.   
  27.     /** 
  28.      * File read status: Error decoding file (may be partially decoded) 
  29.      */  
  30.     public static final int STATUS_FORMAT_ERROR = 1;  
  31.   
  32.     /** 
  33.      * File read status: Unable to open source. 
  34.      */  
  35.     public static final int STATUS_OPEN_ERROR = 2;  
  36.   
  37.     protected BufferedInputStream in;  
  38.     protected int status;  
  39.   
  40.     protected int width; // full image width  
  41.     protected int height; // full image height  
  42.     protected boolean gctFlag; // global color table used  
  43.     protected int gctSize; // size of global color table  
  44.     protected int loopCount = 1// iterations; 0 = repeat forever  
  45.   
  46.     protected int[] gct; // global color table  
  47.     protected int[] lct; // local color table  
  48.     protected int[] act; // active color table  
  49.   
  50.     protected int bgIndex; // background color index  
  51.     protected int bgColor; // background color  
  52.     protected int lastBgColor; // previous bg color  
  53.     protected int pixelAspect; // pixel aspect ratio  
  54.   
  55.     protected boolean lctFlag; // local color table flag  
  56.     protected boolean interlace; // interlace flag  
  57.     protected int lctSize; // local color table size  
  58.   
  59.     protected int ix, iy, iw, ih; // current image rectangle  
  60.     protected Rectangle lastRect; // last image rect  
  61.     protected BufferedImage image; // current frame  
  62.     protected BufferedImage lastImage; // previous frame  
  63.   
  64.     protected byte[] block = new byte[256]; // current data block  
  65.     protected int blockSize = 0// block size  
  66.   
  67.     // last graphic control extension info  
  68.     protected int dispose = 0;  
  69.     // 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev  
  70.     protected int lastDispose = 0;  
  71.     protected boolean transparency = false// use transparent color  
  72.     protected int delay = 0// delay in milliseconds  
  73.     protected int transIndex; // transparent color index  
  74.   
  75.     protected static final int MaxStackSize = 4096;  
  76.     // max decoder pixel stack size  
  77.   
  78.     // LZW decoder working arrays  
  79.     protected short[] prefix;  
  80.     protected byte[] suffix;  
  81.     protected byte[] pixelStack;  
  82.     protected byte[] pixels;  
  83.   
  84.     protected ArrayList<GifFrame> frames; // frames read from current file  
  85.     protected int frameCount;  
  86.   
  87.     static class GifFrame  
  88.     {  
  89.         public GifFrame(BufferedImage im, int del)  
  90.         {  
  91.             image = im;  
  92.             delay = del;  
  93.         }  
  94.   
  95.         public BufferedImage image;  
  96.         public int delay;  
  97.     }  
  98.   
  99.     /** 
  100.      * Gets display duration for specified frame. 
  101.      * 
  102.      * @param n 
  103.      *            int index of frame 
  104.      * @return delay in milliseconds 
  105.      */  
  106.     public int getDelay(int n)  
  107.     {  
  108.         //  
  109.         delay = -1;  
  110.         if ((n >= 0) && (n < frameCount))  
  111.         {  
  112.             delay = (frames.get(n)).delay;  
  113.         }  
  114.         return delay;  
  115.     }  
  116.   
  117.     /** 
  118.      * Gets the number of frames read from file. 
  119.      *  
  120.      * @return frame count 
  121.      */  
  122.     public int getFrameCount()  
  123.     {  
  124.         return frameCount;  
  125.     }  
  126.   
  127.     /** 
  128.      * Gets the first (or only) image read. 
  129.      * 
  130.      * @return BufferedImage containing first frame, or null if none. 
  131.      */  
  132.     public BufferedImage getImage()  
  133.     {  
  134.         return getFrame(0);  
  135.     }  
  136.   
  137.     /** 
  138.      * Gets the "Netscape" iteration count, if any. 
  139.      * A count of 0 means repeat indefinitiely. 
  140.      * 
  141.      * @return iteration count if one was specified, else 1. 
  142.      */  
  143.     public int getLoopCount()  
  144.     {  
  145.         return loopCount;  
  146.     }  
  147.   
  148.     /** 
  149.      * Creates new frame image from current data (and previous 
  150.      * frames as specified by their disposition codes). 
  151.      */  
  152.     protected void setPixels()  
  153.     {  
  154.         // expose destination image's pixels as int array  
  155.         int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();  
  156.   
  157.         // fill in starting image contents based on last image's dispose code  
  158.         if (lastDispose > 0)  
  159.         {  
  160.             if (lastDispose == 3)  
  161.             {  
  162.                 // use image before last  
  163.                 int n = frameCount - 2;  
  164.                 if (n > 0)  
  165.                 {  
  166.                     lastImage = getFrame(n - 1);  
  167.                 }  
  168.                 else  
  169.                 {  
  170.                     lastImage = null;  
  171.                 }  
  172.             }  
  173.   
  174.             if (lastImage != null)  
  175.             {  
  176.                 int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();  
  177.                 System.arraycopy(prev, 0, dest, 0, width * height);  
  178.                 // copy pixels  
  179.   
  180.                 if (lastDispose == 2)  
  181.                 {  
  182.                     // fill last image rect area with background color  
  183.                     Graphics2D g = image.createGraphics();  
  184.                     Color c = null;  
  185.                     if (transparency)  
  186.                     {  
  187.                         c = new Color(0000); // assume background is transparent  
  188.                     }  
  189.                     else  
  190.                     {  
  191.                         c = new Color(lastBgColor); // use given background color  
  192.                     }  
  193.                     g.setColor(c);  
  194.                     g.setComposite(AlphaComposite.Src); // replace area  
  195.                     g.fill(lastRect);  
  196.                     g.dispose();  
  197.                 }  
  198.             }  
  199.         }  
  200.   
  201.         // copy each source line to the appropriate place in the destination  
  202.         int pass = 1;  
  203.         int inc = 8;  
  204.         int iline = 0;  
  205.         for (int i = 0; i < ih; i++)  
  206.         {  
  207.             int line = i;  
  208.             if (interlace)  
  209.             {  
  210.                 if (iline >= ih)  
  211.                 {  
  212.                     pass++;  
  213.                     switch (pass)  
  214.                     {  
  215.                     case 2:  
  216.                         iline = 4;  
  217.                         break;  
  218.                     case 3:  
  219.                         iline = 2;  
  220.                         inc = 4;  
  221.                         break;  
  222.                     case 4:  
  223.                         iline = 1;  
  224.                         inc = 2;  
  225.                     }  
  226.                 }  
  227.                 line = iline;  
  228.                 iline += inc;  
  229.             }  
  230.             line += iy;  
  231.             if (line < height)  
  232.             {  
  233.                 int k = line * width;  
  234.                 int dx = k + ix; // start of line in dest  
  235.                 int dlim = dx + iw; // end of dest line  
  236.                 if ((k + width) < dlim)  
  237.                 {  
  238.                     dlim = k + width; // past dest edge  
  239.                 }  
  240.                 int sx = i * iw; // start of line in source  
  241.                 while (dx < dlim)  
  242.                 {  
  243.                     // map color and insert in destination  
  244.                     int index = ((int) pixels[sx++]) & 0xff;  
  245.                     int c = act[index];  
  246.                     if (c != 0)  
  247.                     {  
  248.                         dest[dx] = c;  
  249.                     }  
  250.                     dx++;  
  251.                 }  
  252.             }  
  253.         }  
  254.     }  
  255.   
  256.     /** 
  257.      * Gets the image contents of frame n. 
  258.      * 
  259.      * @return BufferedImage representation of frame, or null if n is invalid. 
  260.      */  
  261.     public BufferedImage getFrame(int n)  
  262.     {  
  263.         BufferedImage im = null;  
  264.         if ((n >= 0) && (n < frameCount))  
  265.         {  
  266.             im = (frames.get(n)).image;  
  267.         }  
  268.         return im;  
  269.     }  
  270.   
  271.     /** 
  272.      * Gets image size. 
  273.      * 
  274.      * @return GIF image dimensions 
  275.      */  
  276.     public Dimension getFrameSize()  
  277.     {  
  278.         return new Dimension(width, height);  
  279.     }  
  280.   
  281.     /** 
  282.      * Reads GIF image from stream 
  283.      * 
  284.      * @param is 
  285.      *            BufferedInputStream containing GIF file. 
  286.      * @return read status code (0 = no errors) 
  287.      */  
  288.     public int read(BufferedInputStream is)  
  289.     {  
  290.         init();  
  291.         try  
  292.         {  
  293.             if (is != null)  
  294.             {  
  295.                 in = is;  
  296.                 readHeader();  
  297.                 if (!err())  
  298.                 {  
  299.                     readContents();  
  300.                     if (frameCount < 0)  
  301.                     {  
  302.                         status = STATUS_FORMAT_ERROR;  
  303.                     }  
  304.                 }  
  305.             }  
  306.             else  
  307.             {  
  308.                 status = STATUS_OPEN_ERROR;  
  309.             }  
  310.         }  
  311.         finally  
  312.         {  
  313.             if (null != is)  
  314.             {  
  315.                 try  
  316.                 {  
  317.                     is.close();  
  318.                 }  
  319.                 catch (IOException e)  
  320.                 {  
  321.                     e.printStackTrace();  
  322.                 }  
  323.             }  
  324.         }  
  325.         return status;  
  326.     }  
  327.   
  328.     /** 
  329.      * Reads GIF image from stream 
  330.      * 
  331.      * @param is 
  332.      *            InputStream containing GIF file. 
  333.      * @return read status code (0 = no errors) 
  334.      */  
  335.     public int read(InputStream is)  
  336.     {  
  337.         init();  
  338.         try  
  339.         {  
  340.             if (is != null)  
  341.             {  
  342.                 if (!(is instanceof BufferedInputStream))  
  343.                     is = new BufferedInputStream(is);  
  344.                 in = (BufferedInputStream) is;  
  345.                 readHeader();  
  346.                 if (!err())  
  347.                 {  
  348.                     readContents();  
  349.                     if (frameCount < 0)  
  350.                     {  
  351.                         status = STATUS_FORMAT_ERROR;  
  352.                     }  
  353.                 }  
  354.             }  
  355.             else  
  356.             {  
  357.                 status = STATUS_OPEN_ERROR;  
  358.             }  
  359.         }  
  360.         finally  
  361.         {  
  362.             if (null != is)  
  363.             {  
  364.                 try  
  365.                 {  
  366.                     is.close();  
  367.                 }  
  368.                 catch (IOException e)  
  369.                 {  
  370.                     e.printStackTrace();  
  371.                 }  
  372.             }  
  373.         }  
  374.         return status;  
  375.     }  
  376.   
  377.     /** 
  378.      * Reads GIF file from specified file/URL source 
  379.      * (URL assumed if name contains ":/" or "file:") 
  380.      * 
  381.      * @param name 
  382.      *            String containing source 
  383.      * @return read status code (0 = no errors) 
  384.      */  
  385.     public int read(String name)  
  386.     {  
  387.         status = STATUS_OK;  
  388.         try  
  389.         {  
  390.             name = name.trim().toLowerCase();  
  391.             if ((name.contains("file:")) || (name.indexOf(":/") > 0))  
  392.             {  
  393.                 URL url = new URL(name);  
  394.                 in = new BufferedInputStream(url.openStream());  
  395.             }  
  396.             else  
  397.             {  
  398.                 in = new BufferedInputStream(new FileInputStream(name));  
  399.             }  
  400.             status = read(in);  
  401.         }  
  402.         catch (IOException e)  
  403.         {  
  404.             status = STATUS_OPEN_ERROR;  
  405.         }  
  406.   
  407.         return status;  
  408.     }  
  409.   
  410.     /** 
  411.      * Decodes LZW image data into pixel array. 
  412.      * Adapted from John Cristy's ImageMagick. 
  413.      */  
  414.     protected void decodeImageData()  
  415.     {  
  416.         int NullCode = -1;  
  417.         int npix = iw * ih;  
  418.         int available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, count, i, datum, data_size, first, top, bi, pi;  
  419.   
  420.         if ((pixels == null) || (pixels.length < npix))  
  421.         {  
  422.             pixels = new byte[npix]; // allocate new pixel array  
  423.         }  
  424.         if (prefix == null)  
  425.             prefix = new short[MaxStackSize];  
  426.         if (suffix == null)  
  427.             suffix = new byte[MaxStackSize];  
  428.         if (pixelStack == null)  
  429.             pixelStack = new byte[MaxStackSize + 1];  
  430.   
  431.         // Initialize GIF data stream decoder.  
  432.   
  433.         data_size = read();  
  434.         clear = 1 << data_size;  
  435.         end_of_information = clear + 1;  
  436.         available = clear + 2;  
  437.         old_code = NullCode;  
  438.         code_size = data_size + 1;  
  439.         code_mask = (1 << code_size) - 1;  
  440.         for (code = 0; code < clear; code++)  
  441.         {  
  442.             prefix[code] = 0;  
  443.             suffix[code] = (byte) code;  
  444.         }  
  445.   
  446.         // Decode GIF pixel stream.  
  447.   
  448.         datum = bits = count = first = top = pi = bi = 0;  
  449.   
  450.         for (i = 0; i < npix;)  
  451.         {  
  452.             if (top == 0)  
  453.             {  
  454.                 if (bits < code_size)  
  455.                 {  
  456.                     // Load bytes until there are enough bits for a code.  
  457.                     if (count == 0)  
  458.                     {  
  459.                         // Read a new data block.  
  460.                         count = readBlock();  
  461.                         if (count <= 0)  
  462.                             break;  
  463.                         bi = 0;  
  464.                     }  
  465.                     datum += (((int) block[bi]) & 0xff) << bits;  
  466.                     bits += 8;  
  467.                     bi++;  
  468.                     count--;  
  469.                     continue;  
  470.                 }  
  471.   
  472.                 // Get the next code.  
  473.   
  474.                 code = datum & code_mask;  
  475.                 datum >>= code_size;  
  476.                 bits -= code_size;  
  477.   
  478.                 // Interpret the code  
  479.   
  480.                 if ((code > available) || (code == end_of_information))  
  481.                     break;  
  482.                 if (code == clear)  
  483.                 {  
  484.                     // Reset decoder.  
  485.                     code_size = data_size + 1;  
  486.                     code_mask = (1 << code_size) - 1;  
  487.                     available = clear + 2;  
  488.                     old_code = NullCode;  
  489.                     continue;  
  490.                 }  
  491.                 if (old_code == NullCode)  
  492.                 {  
  493.                     pixelStack[top++] = suffix[code];  
  494.                     old_code = code;  
  495.                     first = code;  
  496.                     continue;  
  497.                 }  
  498.                 in_code = code;  
  499.                 if (code == available)  
  500.                 {  
  501.                     pixelStack[top++] = (byte) first;  
  502.                     code = old_code;  
  503.                 }  
  504.                 while (code > clear)  
  505.                 {  
  506.                     pixelStack[top++] = suffix[code];  
  507.                     code = prefix[code];  
  508.                 }  
  509.                 first = ((int) suffix[code]) & 0xff;  
  510.   
  511.                 // Add a new string to the string table,  
  512.   
  513.                 if (available >= MaxStackSize)  
  514.                     break;  
  515.                 pixelStack[top++] = (byte) first;  
  516.                 prefix[available] = (short) old_code;  
  517.                 suffix[available] = (byte) first;  
  518.                 available++;  
  519.                 if (((available & code_mask) == 0) && (available < MaxStackSize))  
  520.                 {  
  521.                     code_size++;  
  522.                     code_mask += available;  
  523.                 }  
  524.                 old_code = in_code;  
  525.             }  
  526.   
  527.             // Pop a pixel off the pixel stack.  
  528.   
  529.             top--;  
  530.             pixels[pi++] = pixelStack[top];  
  531.             i++;  
  532.         }  
  533.   
  534.         for (i = pi; i < npix; i++)  
  535.         {  
  536.             pixels[i] = 0// clear missing pixels  
  537.         }  
  538.   
  539.     }  
  540.   
  541.     /** 
  542.      * Returns true if an error was encountered during reading/decoding 
  543.      */  
  544.     protected boolean err()  
  545.     {  
  546.         return status != STATUS_OK;  
  547.     }  
  548.   
  549.     /** 
  550.      * Initializes or re-initializes reader 
  551.      */  
  552.     protected void init()  
  553.     {  
  554.         status = STATUS_OK;  
  555.         frameCount = 0;  
  556.         frames = new ArrayList<GifFrame>();  
  557.         gct = null;  
  558.         lct = null;  
  559.     }  
  560.   
  561.     /** 
  562.      * Reads a single byte from the input stream. 
  563.      */  
  564.     protected int read()  
  565.     {  
  566.         int curByte = 0;  
  567.         try  
  568.         {  
  569.             curByte = in.read();  
  570.         }  
  571.         catch (IOException e)  
  572.         {  
  573.             status = STATUS_FORMAT_ERROR;  
  574.         }  
  575.         return curByte;  
  576.     }  
  577.   
  578.     /** 
  579.      * Reads next variable length block from input. 
  580.      * 
  581.      * @return number of bytes stored in "buffer" 
  582.      */  
  583.     protected int readBlock()  
  584.     {  
  585.         blockSize = read();  
  586.         int n = 0;  
  587.         if (blockSize > 0)  
  588.         {  
  589.             try  
  590.             {  
  591.                 int count = 0;  
  592.                 while (n < blockSize)  
  593.                 {  
  594.                     count = in.read(block, n, blockSize - n);  
  595.                     if (count == -1)  
  596.                         break;  
  597.                     n += count;  
  598.                 }  
  599.             }  
  600.             catch (IOException ignored)  
  601.             {  
  602.             }  
  603.   
  604.             if (n < blockSize)  
  605.             {  
  606.                 status = STATUS_FORMAT_ERROR;  
  607.             }  
  608.         }  
  609.         return n;  
  610.     }  
  611.   
  612.     /** 
  613.      * Reads color table as 256 RGB integer values 
  614.      * 
  615.      * @param ncolors 
  616.      *            int number of colors to read 
  617.      * @return int array containing 256 colors (packed ARGB with full alpha) 
  618.      */  
  619.     protected int[] readColorTable(int ncolors)  
  620.     {  
  621.         int nbytes = 3 * ncolors;  
  622.         int[] tab = null;  
  623.         byte[] c = new byte[nbytes];  
  624.         int n = 0;  
  625.         try  
  626.         {  
  627.             n = in.read(c);  
  628.         }  
  629.         catch (IOException ignored)  
  630.         {  
  631.         }  
  632.         if (n < nbytes)  
  633.         {  
  634.             status = STATUS_FORMAT_ERROR;  
  635.         }  
  636.         else  
  637.         {  
  638.             tab = new int[256]; // max size to avoid bounds checks  
  639.             int i = 0;  
  640.             int j = 0;  
  641.             while (i < ncolors)  
  642.             {  
  643.                 int r = ((int) c[j++]) & 0xff;  
  644.                 int g = ((int) c[j++]) & 0xff;  
  645.                 int b = ((int) c[j++]) & 0xff;  
  646.                 tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;  
  647.             }  
  648.         }  
  649.         return tab;  
  650.     }  
  651.   
  652.     /** 
  653.      * Main file parser. Reads GIF content blocks. 
  654.      */  
  655.     protected void readContents()  
  656.     {  
  657.         // read GIF file content blocks  
  658.         boolean done = false;  
  659.         while (!(done || err()))  
  660.         {  
  661.             int code = read();  
  662.             switch (code)  
  663.             {  
  664.   
  665.             case 0x2C// image separator  
  666.                 readImage();  
  667.                 break;  
  668.   
  669.             case 0x21// extension  
  670.                 code = read();  
  671.                 switch (code)  
  672.                 {  
  673.                 case 0xf9// graphics control extension  
  674.                     readGraphicControlExt();  
  675.                     break;  
  676.   
  677.                 case 0xff// application extension  
  678.                     readBlock();  
  679.                     String app = "";  
  680.                     for (int i = 0; i < 11; i++)  
  681.                     {  
  682.                         app += (char) block[i];  
  683.                     }  
  684.                     if (app.equals("NETSCAPE2.0"))  
  685.                     {  
  686.                         readNetscapeExt();  
  687.                     }  
  688.                     else  
  689.                         skip(); // don't care  
  690.                     break;  
  691.   
  692.                 default// uninteresting extension  
  693.                     skip();  
  694.                 }  
  695.                 break;  
  696.   
  697.             case 0x3b// terminator  
  698.                 done = true;  
  699.                 break;  
  700.   
  701.             case 0x00// bad byte, but keep going and see what happens  
  702.                 break;  
  703.   
  704.             default:  
  705.                 status = STATUS_FORMAT_ERROR;  
  706.             }  
  707.         }  
  708.     }  
  709.   
  710.     /** 
  711.      * Reads Graphics Control Extension values 
  712.      */  
  713.     protected void readGraphicControlExt()  
  714.     {  
  715.         read(); // block size  
  716.         int packed = read(); // packed fields  
  717.         dispose = (packed & 0x1c) >> 2// disposal method  
  718.         if (dispose == 0)  
  719.         {  
  720.             dispose = 1// elect to keep old image if discretionary  
  721.         }  
  722.         transparency = (packed & 1) != 0;  
  723.         delay = readShort() * 10// delay in milliseconds  
  724.         transIndex = read(); // transparent color index  
  725.         read(); // block terminator  
  726.     }  
  727.   
  728.     /** 
  729.      * Reads GIF file header information. 
  730.      */  
  731.     protected void readHeader()  
  732.     {  
  733.         String id = "";  
  734.         for (int i = 0; i < 6; i++)  
  735.         {  
  736.             id += (char) read();  
  737.         }  
  738.         if (!id.startsWith("GIF"))  
  739.         {  
  740.             status = STATUS_FORMAT_ERROR;  
  741.             return;  
  742.         }  
  743.   
  744.         readLSD();  
  745.         if (gctFlag && !err())  
  746.         {  
  747.             gct = readColorTable(gctSize);  
  748.             bgColor = gct[bgIndex];  
  749.         }  
  750.     }  
  751.   
  752.     /** 
  753.      * Reads next frame image 
  754.      */  
  755.     protected void readImage()  
  756.     {  
  757.         ix = readShort(); // (sub)image position & size  
  758.         iy = readShort();  
  759.         iw = readShort();  
  760.         ih = readShort();  
  761.   
  762.         int packed = read();  
  763.         lctFlag = (packed & 0x80) != 0// 1 - local color table flag  
  764.         interlace = (packed & 0x40) != 0// 2 - interlace flag  
  765.         // 3 - sort flag  
  766.         // 4-5 - reserved  
  767.         lctSize = 2 << (packed & 7); // 6-8 - local color table size  
  768.   
  769.         if (lctFlag)  
  770.         {  
  771.             lct = readColorTable(lctSize); // read table  
  772.             act = lct; // make local table active  
  773.         }  
  774.         else  
  775.         {  
  776.             act = gct; // make global table active  
  777.             if (bgIndex == transIndex)  
  778.                 bgColor = 0;  
  779.         }  
  780.         int save = 0;  
  781.         if (transparency)  
  782.         {  
  783.             save = act[transIndex];  
  784.             act[transIndex] = 0// set transparent color if specified  
  785.         }  
  786.   
  787.         if (act == null)  
  788.         {  
  789.             status = STATUS_FORMAT_ERROR; // no color table defined  
  790.         }  
  791.   
  792.         if (err())  
  793.             return;  
  794.   
  795.         decodeImageData(); // decode pixel data  
  796.         skip();  
  797.   
  798.         if (err())  
  799.             return;  
  800.   
  801.         frameCount++;  
  802.   
  803.         // create new image to receive frame data  
  804.         image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);  
  805.   
  806.         setPixels(); // transfer pixel data to image  
  807.   
  808.         frames.add(new GifFrame(image, delay)); // add image to frame list  
  809.   
  810.         if (transparency)  
  811.         {  
  812.             act[transIndex] = save;  
  813.         }  
  814.         resetFrame();  
  815.   
  816.     }  
  817.   
  818.     /** 
  819.      * Reads Logical Screen Descriptor 
  820.      */  
  821.     protected void readLSD()  
  822.     {  
  823.   
  824.         // logical screen size  
  825.         width = readShort();  
  826.         height = readShort();  
  827.   
  828.         // packed fields  
  829.         int packed = read();  
  830.         gctFlag = (packed & 0x80) != 0// 1 : global color table flag  
  831.         // 2-4 : color resolution  
  832.         // 5 : gct sort flag  
  833.         gctSize = 2 << (packed & 7); // 6-8 : gct size  
  834.   
  835.         bgIndex = read(); // background color index  
  836.         pixelAspect = read(); // pixel aspect ratio  
  837.     }  
  838.   
  839.     /** 
  840.      * Reads Netscape extenstion to obtain iteration count 
  841.      */  
  842.     protected void readNetscapeExt()  
  843.     {  
  844.         do  
  845.         {  
  846.             readBlock();  
  847.             if (block[0] == 1)  
  848.             {  
  849.                 // loop count sub-block  
  850.                 int b1 = ((int) block[1]) & 0xff;  
  851.                 int b2 = ((int) block[2]) & 0xff;  
  852.                 loopCount = (b2 << 8) | b1;  
  853.             }  
  854.         }  
  855.         while ((blockSize > 0) && !err());  
  856.     }  
  857.   
  858.     /** 
  859.      * Reads next 16-bit value, LSB first 
  860.      */  
  861.     protected int readShort()  
  862.     {  
  863.         // read 16-bit value, LSB first  
  864.         return read() | (read() << 8);  
  865.     }  
  866.   
  867.     /** 
  868.      * Resets frame state for reading next image. 
  869.      */  
  870.     protected void resetFrame()  
  871.     {  
  872.         lastDispose = dispose;  
  873.         lastRect = new Rectangle(ix, iy, iw, ih);  
  874.         lastImage = image;  
  875.         lastBgColor = bgColor;  
  876.         int dispose = 0;  
  877.         boolean transparency = false;  
  878.         int delay = 0;  
  879.         lct = null;  
  880.     }  
  881.   
  882.     /** 
  883.      * Skips variable length blocks up to and including 
  884.      * next zero length block. 
  885.      */  
  886.     protected void skip()  
  887.     {  
  888.         do  
  889.         {  
  890.             readBlock();  
  891.         }  
  892.         while ((blockSize > 0) && !err());  
  893.     }  
  894. }  

GifEncoder:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.*;  
  4. import java.awt.image.BufferedImage;  
  5. import java.awt.image.DataBufferByte;  
  6. import java.io.BufferedOutputStream;  
  7. import java.io.ByteArrayOutputStream;  
  8. import java.io.FileOutputStream;  
  9. import java.io.IOException;  
  10. import java.io.OutputStream;  
  11.   
  12. /** 
  13.  * Class AnimatedGifEncoder - Encodes a GIF file consisting of one or 
  14.  * more frames. 
  15.  *  
  16.  * <pre> 
  17.  * Example: 
  18.  *    AnimatedGifEncoder e = new AnimatedGifEncoder(); 
  19.  *    e.start(outputFileName); 
  20.  *    e.setDelay(1000);   // 1 frame per sec 
  21.  *    e.addFrame(image1); 
  22.  *    e.addFrame(image2); 
  23.  *    e.finish(); 
  24.  * </pre> 
  25.  *  
  26.  * No copyright asserted on the source code of this class. May be used 
  27.  * for any purpose, however, refer to the Unisys LZW patent for restrictions 
  28.  * on use of the associated Encoder class. Please forward any corrections 
  29.  * to questions at fmsware.com. 
  30.  * 
  31.  * @version 1.03 November 2003 
  32.  */  
  33. public class GifEncoder  
  34. {  
  35.     protected int width; // image size  
  36.     protected int height;  
  37.     protected Color transparent = null// transparent color if given  
  38.     protected int transIndex; // transparent index in color table  
  39.     protected int repeat = -1// no repeat  
  40.     protected int delay = 0// frame delay (hundredths)  
  41.     protected boolean started = false// ready to output frames  
  42.     protected OutputStream out;  
  43.     protected BufferedImage image; // current frame  
  44.     protected byte[] pixels; // BGR byte array from frame  
  45.     protected byte[] indexedPixels; // converted frame indexed to palette  
  46.     protected int colorDepth; // number of bit planes  
  47.     protected byte[] colorTab; // RGB palette  
  48.     protected boolean[] usedEntry = new boolean[256]; // active palette entries  
  49.     protected int palSize = 7// color table size (bits-1)  
  50.     protected int dispose = -1// disposal code (-1 = use default)  
  51.     protected boolean closeStream = false// close stream when finished  
  52.     protected boolean firstFrame = true;  
  53.     protected boolean sizeSet = false// if false, get size from first frame  
  54.     protected int sample = 10// default sample interval for quantizer  
  55.   
  56.     /** 
  57.      * Sets the delay time between each frame, or changes it 
  58.      * for subsequent frames (applies to last frame added). 
  59.      * 
  60.      * @param ms 
  61.      *            int delay time in milliseconds 
  62.      */  
  63.     public void setDelay(int ms)  
  64.     {  
  65.         delay = Math.round(ms / 10.0f);  
  66.     }  
  67.   
  68.     /** 
  69.      * Sets the GIF frame disposal code for the last added frame 
  70.      * and any subsequent frames. Default is 0 if no transparent 
  71.      * color has been set, otherwise 2. 
  72.      *  
  73.      * @param code 
  74.      *            int disposal code. 
  75.      */  
  76.     public void setDispose(int code)  
  77.     {  
  78.         if (code >= 0)  
  79.         {  
  80.             dispose = code;  
  81.         }  
  82.     }  
  83.   
  84.     /** 
  85.      * Sets the number of times the set of GIF frames 
  86.      * should be played. Default is 1; 0 means play 
  87.      * indefinitely. Must be invoked before the first 
  88.      * image is added. 
  89.      * 
  90.      * @param iter 
  91.      *            int number of iterations. 
  92.      * @return 
  93.      */  
  94.     public void setRepeat(int iter)  
  95.     {  
  96.         if (iter >= 0)  
  97.         {  
  98.             repeat = iter;  
  99.         }  
  100.     }  
  101.   
  102.     /** 
  103.      * Sets the transparent color for the last added frame 
  104.      * and any subsequent frames. 
  105.      * Since all colors are subject to modification 
  106.      * in the quantization process, the color in the final 
  107.      * palette for each frame closest to the given color 
  108.      * becomes the transparent color for that frame. 
  109.      * May be set to null to indicate no transparent color. 
  110.      * 
  111.      * @param c 
  112.      *            Color to be treated as transparent on display. 
  113.      */  
  114.     public void setTransparent(Color c)  
  115.     {  
  116.         transparent = c;  
  117.     }  
  118.   
  119.     /** 
  120.      * Adds next GIF frame. The frame is not written immediately, but is 
  121.      * actually deferred until the next frame is received so that timing 
  122.      * data can be inserted. Invoking <code>finish()</code> flushes all 
  123.      * frames. If <code>setSize</code> was not invoked, the size of the 
  124.      * first image is used for all subsequent frames. 
  125.      * 
  126.      * @param im 
  127.      *            BufferedImage containing frame to write. 
  128.      * @return true if successful. 
  129.      */  
  130.     public boolean addFrame(BufferedImage im)  
  131.     {  
  132.         if ((im == null) || !started)  
  133.         {  
  134.             return false;  
  135.         }  
  136.         boolean ok = true;  
  137.         try  
  138.         {  
  139.             if (!sizeSet)  
  140.             {  
  141.                 // use first frame's size  
  142.                 setSize(im.getWidth(), im.getHeight());  
  143.             }  
  144.             image = im;  
  145.             getImagePixels(); // convert to correct format if necessary  
  146.             analyzePixels(); // build color table & map pixels  
  147.             if (firstFrame)  
  148.             {  
  149.                 writeLSD(); // logical screen descriptior  
  150.                 writePalette(); // global color table  
  151.                 if (repeat >= 0)  
  152.                 {  
  153.                     // use NS app extension to indicate reps  
  154.                     writeNetscapeExt();  
  155.                 }  
  156.             }  
  157.             writeGraphicCtrlExt(); // write graphic control extension  
  158.             writeImageDesc(); // image descriptor  
  159.             if (!firstFrame)  
  160.             {  
  161.                 writePalette(); // local color table  
  162.             }  
  163.             writePixels(); // encode and write pixel data  
  164.             firstFrame = false;  
  165.         }  
  166.         catch (IOException e)  
  167.         {  
  168.             ok = false;  
  169.         }  
  170.   
  171.         return ok;  
  172.     }  
  173.   
  174.     // added by alvaro  
  175.     public boolean outFlush()  
  176.     {  
  177.         boolean ok = true;  
  178.         try  
  179.         {  
  180.             out.flush();  
  181.             return ok;  
  182.         }  
  183.         catch (IOException e)  
  184.         {  
  185.             ok = false;  
  186.         }  
  187.   
  188.         return ok;  
  189.     }  
  190.   
  191.     public byte[] getFrameByteArray()  
  192.     {  
  193.         return ((ByteArrayOutputStream) out).toByteArray();  
  194.     }  
  195.   
  196.     /** 
  197.      * Flushes any pending data and closes output file. 
  198.      * If writing to an OutputStream, the stream is not 
  199.      * closed. 
  200.      */  
  201.     public boolean finish()  
  202.     {  
  203.         if (!started)  
  204.             return false;  
  205.         boolean ok = true;  
  206.         started = false;  
  207.         try  
  208.         {  
  209.             out.write(0x3b); // gif trailer  
  210.             out.flush();  
  211.             if (closeStream)  
  212.             {  
  213.                 out.close();  
  214.             }  
  215.         }  
  216.         catch (IOException e)  
  217.         {  
  218.             ok = false;  
  219.         }  
  220.   
  221.         return ok;  
  222.     }  
  223.   
  224.     public void reset()  
  225.     {  
  226.         // reset for subsequent use  
  227.         transIndex = 0;  
  228.         out = null;  
  229.         image = null;  
  230.         pixels = null;  
  231.         indexedPixels = null;  
  232.         colorTab = null;  
  233.         closeStream = false;  
  234.         firstFrame = true;  
  235.     }  
  236.   
  237.     /** 
  238.      * Sets frame rate in frames per second. Equivalent to 
  239.      * <code>setDelay(1000/fps)</code>. 
  240.      * 
  241.      * @param fps 
  242.      *            float frame rate (frames per second) 
  243.      */  
  244.     public void setFrameRate(float fps)  
  245.     {  
  246.         if (fps != 0f)  
  247.         {  
  248.             delay = Math.round(100f / fps);  
  249.         }  
  250.     }  
  251.   
  252.     /** 
  253.      * Sets quality of color quantization (conversion of images 
  254.      * to the maximum 256 colors allowed by the GIF specification). 
  255.      * Lower values (minimum = 1) produce better colors, but slow 
  256.      * processing significantly. 10 is the default, and produces 
  257.      * good color mapping at reasonable speeds. Values greater 
  258.      * than 20 do not yield significant improvements in speed. 
  259.      * 
  260.      * @param quality 
  261.      *            int greater than 0. 
  262.      * @return 
  263.      */  
  264.     public void setQuality(int quality)  
  265.     {  
  266.         if (quality < 1)  
  267.             quality = 1;  
  268.         sample = quality;  
  269.     }  
  270.   
  271.     /** 
  272.      * Sets the GIF frame size. The default size is the 
  273.      * size of the first frame added if this method is 
  274.      * not invoked. 
  275.      * 
  276.      * @param w 
  277.      *            int frame width. 
  278.      * @param h 
  279.      *            int frame width. 
  280.      */  
  281.     public void setSize(int w, int h)  
  282.     {  
  283.         if (started && !firstFrame)  
  284.             return;  
  285.         width = w;  
  286.         height = h;  
  287.         if (width < 1)  
  288.             width = 320;  
  289.         if (height < 1)  
  290.             height = 240;  
  291.         sizeSet = true;  
  292.     }  
  293.   
  294.     /** 
  295.      * Initiates GIF file creation on the given stream. The stream 
  296.      * is not closed automatically. 
  297.      * 
  298.      * @param os 
  299.      *            OutputStream on which GIF images are written. 
  300.      * @return false if initial write failed. 
  301.      */  
  302.     public boolean start(OutputStream os)  
  303.     {  
  304.         if (os == null)  
  305.             return false;  
  306.         boolean ok = true;  
  307.         closeStream = false;  
  308.         out = os;  
  309.         try  
  310.         {  
  311.             writeString("GIF89a"); // header  
  312.         }  
  313.         catch (IOException e)  
  314.         {  
  315.             ok = false;  
  316.         }  
  317.         return started = ok;  
  318.     }  
  319.   
  320.     /** 
  321.      * Initiates writing of a GIF file with the specified name. 
  322.      * 
  323.      * @param file 
  324.      *            String containing output file name. 
  325.      * @return false if open or initial write failed. 
  326.      */  
  327.     public boolean start(String file)  
  328.     {  
  329.         boolean ok = true;  
  330.         try  
  331.         {  
  332.             out = new BufferedOutputStream(new FileOutputStream(file));  
  333.             ok = start(out);  
  334.             closeStream = true;  
  335.         }  
  336.         catch (IOException e)  
  337.         {  
  338.             ok = false;  
  339.         }  
  340.         return started = ok;  
  341.     }  
  342.   
  343.     /** 
  344.      * Analyzes image colors and creates color map. 
  345.      */  
  346.     protected void analyzePixels()  
  347.     {  
  348.         int len = pixels.length;  
  349.         int nPix = len / 3;  
  350.         indexedPixels = new byte[nPix];  
  351.         Quant nq = new Quant(pixels, len, sample);  
  352.         // initialize quantizer  
  353.         colorTab = nq.process(); // create reduced palette  
  354.         // convert map from BGR to RGB  
  355.         for (int i = 0; i < colorTab.length; i += 3)  
  356.         {  
  357.             byte temp = colorTab[i];  
  358.             colorTab[i] = colorTab[i + 2];  
  359.             colorTab[i + 2] = temp;  
  360.             usedEntry[i / 3] = false;  
  361.         }  
  362.         // map image pixels to new palette  
  363.         int k = 0;  
  364.         for (int i = 0; i < nPix; i++)  
  365.         {  
  366.             int index = nq.map(pixels[k++] & 0xff, pixels[k++] & 0xff, pixels[k++] & 0xff);  
  367.             usedEntry[index] = true;  
  368.             indexedPixels[i] = (byte) index;  
  369.         }  
  370.         pixels = null;  
  371.         colorDepth = 8;  
  372.         palSize = 7;  
  373.         // get closest match to transparent color if specified  
  374.         if (transparent != null)  
  375.         {  
  376.             transIndex = findClosest(transparent);  
  377.         }  
  378.     }  
  379.   
  380.     /** 
  381.      * Returns index of palette color closest to c 
  382.      */  
  383.     protected int findClosest(Color c)  
  384.     {  
  385.         if (colorTab == null)  
  386.             return -1;  
  387.         int r = c.getRed();  
  388.         int g = c.getGreen();  
  389.         int b = c.getBlue();  
  390.         int minpos = 0;  
  391.         int dmin = 256 * 256 * 256;  
  392.         int len = colorTab.length;  
  393.         for (int i = 0; i < len;)  
  394.         {  
  395.             int dr = r - (colorTab[i++] & 0xff);  
  396.             int dg = g - (colorTab[i++] & 0xff);  
  397.             int db = b - (colorTab[i] & 0xff);  
  398.             int d = dr * dr + dg * dg + db * db;  
  399.             int index = i / 3;  
  400.             if (usedEntry[index] && (d < dmin))  
  401.             {  
  402.                 dmin = d;  
  403.                 minpos = index;  
  404.             }  
  405.             i++;  
  406.         }  
  407.         return minpos;  
  408.     }  
  409.   
  410.     /** 
  411.      * Extracts image pixels into byte array "pixels" 
  412.      */  
  413.     protected void getImagePixels()  
  414.     {  
  415.         int w = image.getWidth();  
  416.         int h = image.getHeight();  
  417.         int type = image.getType();  
  418.         if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR))  
  419.         {  
  420.             // create new image with right size/format  
  421.             BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);  
  422.             Graphics2D g = temp.createGraphics();  
  423.             g.drawImage(image, 00null);  
  424.             image = temp;  
  425.         }  
  426.         pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();  
  427.     }  
  428.   
  429.     /** 
  430.      * Writes Graphic Control Extension 
  431.      */  
  432.     protected void writeGraphicCtrlExt() throws IOException  
  433.     {  
  434.         out.write(0x21); // extension introducer  
  435.         out.write(0xf9); // GCE label  
  436.         out.write(4); // data block size  
  437.         int transp, disp;  
  438.         if (transparent == null)  
  439.         {  
  440.             transp = 0;  
  441.             disp = 0// dispose = no action  
  442.         }  
  443.         else  
  444.         {  
  445.             transp = 1;  
  446.             disp = 2// force clear if using transparent color  
  447.         }  
  448.         if (dispose >= 0)  
  449.         {  
  450.             disp = dispose & 7// user override  
  451.         }  
  452.         disp <<= 2;  
  453.   
  454.         // packed fields  
  455.         out.write(0 | // 1:3 reserved  
  456.                 disp | // 4:6 disposal  
  457.                 0 | // 7 user input - 0 = none  
  458.                 transp); // 8 transparency flag  
  459.   
  460.         writeShort(delay); // delay x 1/100 sec  
  461.         out.write(transIndex); // transparent color index  
  462.         out.write(0); // block terminator  
  463.     }  
  464.   
  465.     /** 
  466.      * Writes Image Descriptor 
  467.      */  
  468.     protected void writeImageDesc() throws IOException  
  469.     {  
  470.         out.write(0x2c); // image separator  
  471.         writeShort(0); // image position x,y = 0,0  
  472.         writeShort(0);  
  473.         writeShort(width); // image size  
  474.         writeShort(height);  
  475.         // packed fields  
  476.         if (firstFrame)  
  477.         {  
  478.             // no LCT - GCT is used for first (or only) frame  
  479.             out.write(0);  
  480.         }  
  481.         else  
  482.         {  
  483.             // specify normal LCT  
  484.             out.write(0x80 | // 1 local color table 1=yes  
  485.                     0 | // 2 interlace - 0=no  
  486.                     0 | // 3 sorted - 0=no  
  487.                     0 | // 4-5 reserved  
  488.                     palSize); // 6-8 size of color table  
  489.         }  
  490.     }  
  491.   
  492.     /** 
  493.      * Writes Logical Screen Descriptor 
  494.      */  
  495.     protected void writeLSD() throws IOException  
  496.     {  
  497.         // logical screen size  
  498.         writeShort(width);  
  499.         writeShort(height);  
  500.         // packed fields  
  501.         out.write((0x80 | // 1 : global color table flag = 1 (gct used)  
  502.                 0x70 | // 2-4 : color resolution = 7  
  503.                 0x00 | // 5 : gct sort flag = 0  
  504.                 palSize)); // 6-8 : gct size  
  505.   
  506.         out.write(0); // background color index  
  507.         out.write(0); // pixel aspect ratio - assume 1:1  
  508.     }  
  509.   
  510.     /** 
  511.      * Writes Netscape application extension to define 
  512.      * repeat count. 
  513.      */  
  514.     protected void writeNetscapeExt() throws IOException  
  515.     {  
  516.         out.write(0x21); // extension introducer  
  517.         out.write(0xff); // app extension label  
  518.         out.write(11); // block size  
  519.         writeString("NETSCAPE" + "2.0"); // app id + auth code  
  520.         out.write(3); // sub-block size  
  521.         out.write(1); // loop sub-block id  
  522.         writeShort(repeat); // loop count (extra iterations, 0=repeat forever)  
  523.         out.write(0); // block terminator  
  524.     }  
  525.   
  526.     /** 
  527.      * Writes color table 
  528.      */  
  529.     protected void writePalette() throws IOException  
  530.     {  
  531.         out.write(colorTab, 0, colorTab.length);  
  532.         int n = (3 * 256) - colorTab.length;  
  533.         for (int i = 0; i < n; i++)  
  534.         {  
  535.             out.write(0);  
  536.         }  
  537.     }  
  538.   
  539.     /** 
  540.      * Encodes and writes pixel data 
  541.      */  
  542.     protected void writePixels() throws IOException  
  543.     {  
  544.         Encoder encoder = new Encoder(width, height, indexedPixels, colorDepth);  
  545.         encoder.encode(out);  
  546.     }  
  547.   
  548.     /** 
  549.      * Write 16-bit value to output stream, LSB first 
  550.      */  
  551.     protected void writeShort(int value) throws IOException  
  552.     {  
  553.         out.write(value & 0xff);  
  554.         out.write((value >> 8) & 0xff);  
  555.     }  
  556.   
  557.     /** 
  558.      * Writes string to output stream 
  559.      */  
  560.     protected void writeString(String s) throws IOException  
  561.     {  
  562.         for (int i = 0; i < s.length(); i++)  
  563.         {  
  564.             out.write((byte) s.charAt(i));  
  565.         }  
  566.     }  
  567. }  

Quant:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.io.FileNotFoundException;  
  4. import java.io.FileOutputStream;  
  5.   
  6. /** 
  7.  * <p> 
  8.  * </p> 
  9.  * 
  10.  * @version:1.0 
  11.  */  
  12. public class Quant  
  13. {  
  14.     protected static final int netsize = 256/* number of colours used */  
  15.   
  16.     /* four primes near 500 - assume no image has a length so large */  
  17.     /* that it is divisible by all four primes */  
  18.     protected static final int prime1 = 499;  
  19.     protected static final int prime2 = 491;  
  20.     protected static final int prime3 = 487;  
  21.     protected static final int prime4 = 503;  
  22.   
  23.     protected static final int minpicturebytes = (3 * prime4);  
  24.     /* minimum size for input image */  
  25.   
  26.     /* 
  27.      * Program Skeleton 
  28.      * ---------------- 
  29.      * [select samplefac in range 1..30] 
  30.      * [read image from input file] 
  31.      * pic = (unsigned char*) malloc(3*width*height); 
  32.      * initnet(pic,3*width*height,samplefac); 
  33.      * learn(); 
  34.      * unbiasnet(); 
  35.      * [write output image header, using writecolourmap(f)] 
  36.      * inxbuild(); 
  37.      * write output image using inxsearch(b,g,r) 
  38.      */  
  39.   
  40.     /* 
  41.      * Network Definitions 
  42.      * ------------------- 
  43.      */  
  44.   
  45.     protected static final int maxnetpos = (netsize - 1);  
  46.     protected static final int netbiasshift = 4/* bias for colour values */  
  47.     protected static final int ncycles = 100/* no. of learning cycles */  
  48.   
  49.     /* defs for freq and bias */  
  50.     protected static final int intbiasshift = 16/* bias for fractions */  
  51.     protected static final int intbias = (((int1) << intbiasshift);  
  52.     protected static final int gammashift = 10/* gamma = 1024 */  
  53.     protected static final int gamma = (((int1) << gammashift);  
  54.     protected static final int betashift = 10;  
  55.     protected static final int beta = (intbias >> betashift); /* beta = 1/1024 */  
  56.     protected static final int betagamma = (intbias << (gammashift - betashift));  
  57.   
  58.     /* defs for decreasing radius factor */  
  59.     protected static final int initrad = (netsize >> 3); /* for 256 cols, radius starts */  
  60.     protected static final int radiusbiasshift = 6/* at 32.0 biased by 6 bits */  
  61.     protected static final int radiusbias = (((int1) << radiusbiasshift);  
  62.     protected static final int initradius = (initrad * radiusbias); /* and decreases by a */  
  63.     protected static final int radiusdec = 30/* factor of 1/30 each cycle */  
  64.   
  65.     /* defs for decreasing alpha factor */  
  66.     protected static final int alphabiasshift = 10/* alpha starts at 1.0 */  
  67.     protected static final int initalpha = (((int1) << alphabiasshift);  
  68.   
  69.     protected int alphadec; /* biased by 10 bits */  
  70.   
  71.     /* radbias and alpharadbias used for radpower calculation */  
  72.     protected static final int radbiasshift = 8;  
  73.     protected static final int radbias = (((int1) << radbiasshift);  
  74.     protected static final int alpharadbshift = (alphabiasshift + radbiasshift);  
  75.     protected static final int alpharadbias = (((int1) << alpharadbshift);  
  76.   
  77.     /* 
  78.      * Types and Global Variables 
  79.      * -------------------------- 
  80.      */  
  81.   
  82.     protected byte[] thepicture; /* the input image itself */  
  83.     protected int lengthcount; /* lengthcount = H*W*3 */  
  84.   
  85.     protected int samplefac; /* sampling factor 1..30 */  
  86.   
  87.     // typedef int pixel[4]; /* BGRc */  
  88.     protected int[][] network; /* the network itself - [netsize][4] */  
  89.   
  90.     protected int[] netindex = new int[256];  
  91.     /* for network lookup - really 256 */  
  92.   
  93.     protected int[] bias = new int[netsize];  
  94.     /* bias and freq arrays for learning */  
  95.     protected int[] freq = new int[netsize];  
  96.     protected int[] radpower = new int[initrad];  
  97.     /* radpower for precomputation */  
  98.   
  99.     /* 
  100.      * Initialise network in range (0,0,0) to (255,255,255) and set parameters 
  101.      * ----------------------------------------------------------------------- 
  102.      */  
  103.     public Quant(byte[] thepic, int len, int sample)  
  104.     {  
  105.   
  106.         int i;  
  107.         int[] p;  
  108.   
  109.         thepicture = thepic;  
  110.         lengthcount = len;  
  111.         samplefac = sample;  
  112.   
  113.         network = new int[netsize][];  
  114.         for (i = 0; i < netsize; i++)  
  115.         {  
  116.             network[i] = new int[4];  
  117.             p = network[i];  
  118.             p[0] = p[1] = p[2] = (i << (netbiasshift + 8)) / netsize;  
  119.             freq[i] = intbias / netsize; /* 1/netsize */  
  120.             bias[i] = 0;  
  121.         }  
  122.     }  
  123.   
  124.     public byte[] colorMap()  
  125.     {  
  126.         byte[] map = new byte[3 * netsize];  
  127.         int[] index = new int[netsize];  
  128.         for (int i = 0; i < netsize; i++)  
  129.             index[network[i][3]] = i;  
  130.         int k = 0;  
  131.         for (int i = 0; i < netsize; i++)  
  132.         {  
  133.             int j = index[i];  
  134.             map[k++] = (byte) (network[j][0]);  
  135.             map[k++] = (byte) (network[j][1]);  
  136.             map[k++] = (byte) (network[j][2]);  
  137.         }  
  138.         return map;  
  139.     }  
  140.   
  141.     /* 
  142.      * Insertion sort of network and building of netindex[0..255] (to do after unbias) 
  143.      * ------------------------------------------------------------------------------- 
  144.      */  
  145.     public void inxbuild()  
  146.     {  
  147.   
  148.         int i, j, smallpos, smallval;  
  149.         int[] p;  
  150.         int[] q;  
  151.         int previouscol, startpos;  
  152.   
  153.         previouscol = 0;  
  154.         startpos = 0;  
  155.         for (i = 0; i < netsize; i++)  
  156.         {  
  157.             p = network[i];  
  158.             smallpos = i;  
  159.             smallval = p[1]; /* index on g */  
  160.             /* find smallest in i..netsize-1 */  
  161.             for (j = i + 1; j < netsize; j++)  
  162.             {  
  163.                 q = network[j];  
  164.                 if (q[1] < smallval)  
  165.                 { /* index on g */  
  166.                     smallpos = j;  
  167.                     smallval = q[1]; /* index on g */  
  168.                 }  
  169.             }  
  170.             q = network[smallpos];  
  171.             /* swap p (i) and q (smallpos) entries */  
  172.             if (i != smallpos)  
  173.             {  
  174.                 j = q[0];  
  175.                 q[0] = p[0];  
  176.                 p[0] = j;  
  177.                 j = q[1];  
  178.                 q[1] = p[1];  
  179.                 p[1] = j;  
  180.                 j = q[2];  
  181.                 q[2] = p[2];  
  182.                 p[2] = j;  
  183.                 j = q[3];  
  184.                 q[3] = p[3];  
  185.                 p[3] = j;  
  186.             }  
  187.             /* smallval entry is now in position i */  
  188.             if (smallval != previouscol)  
  189.             {  
  190.                 netindex[previouscol] = (startpos + i) >> 1;  
  191.                 for (j = previouscol + 1; j < smallval; j++)  
  192.                     netindex[j] = i;  
  193.                 previouscol = smallval;  
  194.                 startpos = i;  
  195.             }  
  196.         }  
  197.         netindex[previouscol] = (startpos + maxnetpos) >> 1;  
  198.         for (j = previouscol + 1; j < 256; j++)  
  199.             netindex[j] = maxnetpos; /* really 256 */  
  200.     }  
  201.   
  202.     /* 
  203.      * Main Learning Loop 
  204.      * ------------------ 
  205.      */  
  206.     public void learn()  
  207.     {  
  208.   
  209.         int i, j, b, g, r;  
  210.         int radius, rad, alpha, step, delta, samplepixels;  
  211.         byte[] p;  
  212.         int pix, lim;  
  213.   
  214.         if (lengthcount < minpicturebytes)  
  215.             samplefac = 1;  
  216.         alphadec = 30 + ((samplefac - 1) / 3);  
  217.         p = thepicture;  
  218.         pix = 0;  
  219.         lim = lengthcount;  
  220.         samplepixels = lengthcount / (3 * samplefac);  
  221.         delta = samplepixels / ncycles;  
  222.         alpha = initalpha;  
  223.         radius = initradius;  
  224.   
  225.         rad = radius >> radiusbiasshift;  
  226.         if (rad <= 1)  
  227.             rad = 0;  
  228.         for (i = 0; i < rad; i++)  
  229.             radpower[i] = alpha * (((rad * rad - i * i) * radbias) / (rad * rad));  
  230.   
  231.         // fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad);  
  232.   
  233.         if (lengthcount < minpicturebytes)  
  234.             step = 3;  
  235.         else if ((lengthcount % prime1) != 0)  
  236.             step = 3 * prime1;  
  237.         else  
  238.         {  
  239.             if ((lengthcount % prime2) != 0)  
  240.                 step = 3 * prime2;  
  241.             else  
  242.             {  
  243.                 if ((lengthcount % prime3) != 0)  
  244.                     step = 3 * prime3;  
  245.                 else  
  246.                     step = 3 * prime4;  
  247.             }  
  248.         }  
  249.   
  250.         i = 0;  
  251.         while (i < samplepixels)  
  252.         {  
  253.             b = (p[pix + 0] & 0xff) << netbiasshift;  
  254.             g = (p[pix + 1] & 0xff) << netbiasshift;  
  255.             r = (p[pix + 2] & 0xff) << netbiasshift;  
  256.             j = contest(b, g, r);  
  257.   
  258.             altersingle(alpha, j, b, g, r);  
  259.             if (rad != 0)  
  260.                 alterneigh(rad, j, b, g, r); /* alter neighbours */  
  261.   
  262.             pix += step;  
  263.             if (pix >= lim)  
  264.                 pix -= lengthcount;  
  265.   
  266.             i++;  
  267.             if (delta == 0)  
  268.                 delta = 1;  
  269.             if (i % delta == 0)  
  270.             {  
  271.                 alpha -= alpha / alphadec;  
  272.                 radius -= radius / radiusdec;  
  273.                 rad = radius >> radiusbiasshift;  
  274.                 if (rad <= 1)  
  275.                     rad = 0;  
  276.                 for (j = 0; j < rad; j++)  
  277.                     radpower[j] = alpha * (((rad * rad - j * j) * radbias) / (rad * rad));  
  278.             }  
  279.         }  
  280.         // fprintf(stderr,"finished 1D learning: final alpha=%f !\n",((float)alpha)/initalpha);  
  281.     }  
  282.   
  283.     /* 
  284.      * Search for BGR values 0..255 (after net is unbiased) and return colour index 
  285.      * ---------------------------------------------------------------------------- 
  286.      */  
  287.     public int map(int b, int g, int r)  
  288.     {  
  289.   
  290.         int i, j, dist, a, bestd;  
  291.         int[] p;  
  292.         int best;  
  293.   
  294.         bestd = 1000/* biggest possible dist is 256*3 */  
  295.         best = -1;  
  296.         i = netindex[g]; /* index on g */  
  297.         j = i - 1/* start at netindex[g] and work outwards */  
  298.   
  299.         while ((i < netsize) || (j >= 0))  
  300.         {  
  301.             if (i < netsize)  
  302.             {  
  303.                 p = network[i];  
  304.                 dist = p[1] - g; /* inx key */  
  305.                 if (dist >= bestd)  
  306.                     i = netsize; /* stop iter */  
  307.                 else  
  308.                 {  
  309.                     i++;  
  310.                     if (dist < 0)  
  311.                         dist = -dist;  
  312.                     a = p[0] - b;  
  313.                     if (a < 0)  
  314.                         a = -a;  
  315.                     dist += a;  
  316.                     if (dist < bestd)  
  317.                     {  
  318.                         a = p[2] - r;  
  319.                         if (a < 0)  
  320.                             a = -a;  
  321.                         dist += a;  
  322.                         if (dist < bestd)  
  323.                         {  
  324.                             bestd = dist;  
  325.                             best = p[3];  
  326.                         }  
  327.                     }  
  328.                 }  
  329.             }  
  330.             if (j >= 0)  
  331.             {  
  332.                 p = network[j];  
  333.                 dist = g - p[1]; /* inx key - reverse dif */  
  334.                 if (dist >= bestd)  
  335.                     j = -1/* stop iter */  
  336.                 else  
  337.                 {  
  338.                     j--;  
  339.                     if (dist < 0)  
  340.                         dist = -dist;  
  341.                     a = p[0] - b;  
  342.                     if (a < 0)  
  343.                         a = -a;  
  344.                     dist += a;  
  345.                     if (dist < bestd)  
  346.                     {  
  347.                         a = p[2] - r;  
  348.                         if (a < 0)  
  349.                             a = -a;  
  350.                         dist += a;  
  351.                         if (dist < bestd)  
  352.                         {  
  353.                             bestd = dist;  
  354.                             best = p[3];  
  355.                         }  
  356.                     }  
  357.                 }  
  358.             }  
  359.         }  
  360.         return (best);  
  361.     }  
  362.   
  363.     public byte[] process()  
  364.     {  
  365.         learn();  
  366.         unbiasnet();  
  367.         inxbuild();  
  368.         return colorMap();  
  369.     }  
  370.   
  371.     /* 
  372.      * Unbias network to give byte values 0..255 and record position i to prepare for sort 
  373.      * ----------------------------------------------------------------------------------- 
  374.      */  
  375.     public void unbiasnet()  
  376.     {  
  377.   
  378.         int i, j;  
  379.   
  380.         for (i = 0; i < netsize; i++)  
  381.         {  
  382.             network[i][0] >>= netbiasshift;  
  383.             network[i][1] >>= netbiasshift;  
  384.             network[i][2] >>= netbiasshift;  
  385.             network[i][3] = i; /* record colour no */  
  386.         }  
  387.     }  
  388.   
  389.     /* 
  390.      * Move adjacent neurons by precomputed alpha*(1-((i-j)^2/[r]^2)) in radpower[|i-j|] 
  391.      * --------------------------------------------------------------------------------- 
  392.      */  
  393.     protected void alterneigh(int rad, int i, int b, int g, int r)  
  394.     {  
  395.   
  396.         int j, k, lo, hi, a, m;  
  397.         int[] p;  
  398.   
  399.         lo = i - rad;  
  400.         if (lo < -1)  
  401.             lo = -1;  
  402.         hi = i + rad;  
  403.         if (hi > netsize)  
  404.             hi = netsize;  
  405.   
  406.         j = i + 1;  
  407.         k = i - 1;  
  408.         m = 1;  
  409.         while ((j < hi) || (k > lo))  
  410.         {  
  411.             a = radpower[m++];  
  412.             if (j < hi)  
  413.             {  
  414.                 p = network[j++];  
  415.                 try  
  416.                 {  
  417.                     p[0] -= (a * (p[0] - b)) / alpharadbias;  
  418.                     p[1] -= (a * (p[1] - g)) / alpharadbias;  
  419.                     p[2] -= (a * (p[2] - r)) / alpharadbias;  
  420.                 }  
  421.                 catch (Exception e)  
  422.                 {  
  423.                 } // prevents 1.3 miscompilation  
  424.             }  
  425.             if (k > lo)  
  426.             {  
  427.                 p = network[k--];  
  428.                 try  
  429.                 {  
  430.                     p[0] -= (a * (p[0] - b)) / alpharadbias;  
  431.                     p[1] -= (a * (p[1] - g)) / alpharadbias;  
  432.                     p[2] -= (a * (p[2] - r)) / alpharadbias;  
  433.                 }  
  434.                 catch (Exception e)  
  435.                 {  
  436.                 }  
  437.             }  
  438.         }  
  439.     }  
  440.   
  441.     /* 
  442.      * Move neuron i towards biased (b,g,r) by factor alpha 
  443.      * ---------------------------------------------------- 
  444.      */  
  445.     protected void altersingle(int alpha, int i, int b, int g, int r)  
  446.     {  
  447.   
  448.         /* alter hit neuron */  
  449.         int[] n = network[i];  
  450.         n[0] -= (alpha * (n[0] - b)) / initalpha;  
  451.         n[1] -= (alpha * (n[1] - g)) / initalpha;  
  452.         n[2] -= (alpha * (n[2] - r)) / initalpha;  
  453.     }  
  454.   
  455.     /* 
  456.      * Search for biased BGR values 
  457.      * ---------------------------- 
  458.      */  
  459.     protected int contest(int b, int g, int r)  
  460.     {  
  461.   
  462.         /* finds closest neuron (min dist) and updates freq */  
  463.         /* finds best neuron (min dist-bias) and returns position */  
  464.         /* for frequently chosen neurons, freq[i] is high and bias[i] is negative */  
  465.         /* bias[i] = gamma*((1/netsize)-freq[i]) */  
  466.   
  467.         int i, dist, a, biasdist, betafreq;  
  468.         int bestpos, bestbiaspos, bestd, bestbiasd;  
  469.         int[] n;  
  470.   
  471.         bestd = ~(((int1) << 31);  
  472.         bestbiasd = bestd;  
  473.         bestpos = -1;  
  474.         bestbiaspos = bestpos;  
  475.   
  476.         for (i = 0; i < netsize; i++)  
  477.         {  
  478.             n = network[i];  
  479.             dist = n[0] - b;  
  480.             if (dist < 0)  
  481.                 dist = -dist;  
  482.             a = n[1] - g;  
  483.             if (a < 0)  
  484.                 a = -a;  
  485.             dist += a;  
  486.             a = n[2] - r;  
  487.             if (a < 0)  
  488.                 a = -a;  
  489.             dist += a;  
  490.             if (dist < bestd)  
  491.             {  
  492.                 bestd = dist;  
  493.                 bestpos = i;  
  494.             }  
  495.             biasdist = dist - ((bias[i]) >> (intbiasshift - netbiasshift));  
  496.             if (biasdist < bestbiasd)  
  497.             {  
  498.                 bestbiasd = biasdist;  
  499.                 bestbiaspos = i;  
  500.             }  
  501.             betafreq = (freq[i] >> betashift);  
  502.             freq[i] -= betafreq;  
  503.             bias[i] += (betafreq << gammashift);  
  504.         }  
  505.         freq[bestpos] += beta;  
  506.         bias[bestpos] -= betagamma;  
  507.         return (bestbiaspos);  
  508.     }  
  509. }  
[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.AlphaComposite;  
  4. import java.awt.Color;  
  5. import java.awt.Font;  
  6. import java.awt.FontFormatException;  
  7. import java.awt.Graphics;  
  8. import java.awt.Graphics2D;  
  9. import java.awt.RenderingHints;  
  10. import java.awt.geom.AffineTransform;  
  11. import java.awt.image.BufferedImage;  
  12. import java.io.ByteArrayInputStream;  
  13. import java.io.File;  
  14. import java.io.FileOutputStream;  
  15. import java.io.IOException;  
  16. import java.io.OutputStream;  
  17. import java.util.Arrays;  
  18. import java.util.Random;  
  19.   
  20. import javax.imageio.ImageIO;  
  21.   
  22. import org.apache.log4j.Logger;  
  23.   
  24. /** 
  25.  * 验证码工具类: 
  26.  * 随机字体、字体样式、字体大小(验证码图片宽度 - 8 ~ 验证码图片宽度 + 10) 
  27.  * 彩色字符 每个字符的颜色随机,一定会不相同 
  28.  * 随机字符 阿拉伯数字 + 小写字母 + 大写字母 
  29.  * 3D中空自定义字体,需要单独使用,只有阿拉伯数字和大写字母 
  30.  *  
  31.  * @date 2017年5月9日 下午7:27:55 
  32.  */  
  33. public class RandomVerifyImgCodeUtil  
  34. {  
  35.     private static Logger logger = Logger.getLogger(RandomVerifyImgCodeUtil.class);  
  36.     /** 
  37.      * 随机类 
  38.      */  
  39.     private static Random random = new Random();  
  40.   
  41.     // 放到session中的key  
  42.     public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";  
  43.   
  44.     // 验证码来源范围,去掉了0,1,I,O,l,o几个容易混淆的字符  
  45.     public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz";  
  46.       
  47.     private static ImgFontByte imgFontByte = new ImgFontByte();  
  48.       
  49.     private static Font baseFont;  
  50.     static  
  51.     {  
  52.         try  
  53.         {  
  54.             baseFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(imgFontByte.hex2byte(imgFontByte.getFontByteStr())));  
  55.         }  
  56.         catch (FontFormatException e)  
  57.         {  
  58.             logger.error("new img font font format failed. e: " + e.getMessage(), e);  
  59.         }  
  60.         catch (IOException e)  
  61.         {  
  62.             logger.error("new img font io failed. e: " + e.getMessage(), e);  
  63.         }  
  64.     }  
  65.   
  66.     // 字体类型  
  67.     private static String[] fontName =  
  68.     {  
  69.             "Algerian""Arial""Arial Black""Agency FB""Calibri""Cambria""Gadugi""Georgia""Consolas""Comic Sans MS""Courier New",  
  70.             "Gill sans""Time News Roman""Tahoma""Quantzite""Verdana"  
  71.     };  
  72.   
  73.     // 字体样式  
  74.     private static int[] fontStyle =  
  75.     {  
  76.             Font.BOLD, Font.ITALIC, Font.ROMAN_BASELINE, Font.PLAIN, Font.BOLD + Font.ITALIC  
  77.     };  
  78.   
  79.     // 颜色  
  80.     private static Color[] colorRange =  
  81.     {  
  82.             Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.YELLOW, Color.GREEN, Color.BLUE,  
  83.             Color.DARK_GRAY, Color.BLACK, Color.RED  
  84.     };  
  85.   
  86.     /** 
  87.      * 使用系统默认字符源生成验证码 
  88.      *  
  89.      * @param verifySize 
  90.      *            验证码长度 
  91.      * @param uuid 
  92.      *            App端传的参数,app没有session和cookie,必须用设备号在redis记录图形验证码的值 
  93.      * @param platFormName 
  94.      *            平台名称:pc\wap\app app比较特殊,需要单独处理 
  95.      * @param request 
  96.      *            请求 
  97.      * @return 
  98.      */  
  99.     public static String generateVerifyCode(int verifySize)  
  100.     {  
  101.         return generateVerifyCode(verifySize, VERIFY_CODES);  
  102.     }  
  103.   
  104.     /** 
  105.      * 使用指定源生成验证码 
  106.      *  
  107.      * @param verifySize 
  108.      *            验证码长度 
  109.      * @param sources 
  110.      *            验证码字符源 
  111.      * @return 
  112.      */  
  113.     private static String generateVerifyCode(int verifySize, String sources)  
  114.     {  
  115.         if (sources == null || sources.length() == 0)  
  116.         {  
  117.             sources = VERIFY_CODES;  
  118.         }  
  119.         int codesLen = sources.length();  
  120.         Random rand = new Random(System.currentTimeMillis());  
  121.         StringBuilder verifyCode = new StringBuilder(verifySize);  
  122.         for (int i = 0; i < verifySize; i++)  
  123.         {  
  124.             verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1)));  
  125.         }  
  126.   
  127.         return verifyCode.toString();  
  128.     }  
  129.   
  130.     /** 
  131.      * 输出指定验证码图片流 
  132.      *  
  133.      * @param w 
  134.      *            验证码图片的宽 
  135.      * @param h 
  136.      *            验证码图片的高 
  137.      * @param os 
  138.      *            流 
  139.      * @param code 
  140.      *            验证码 
  141.      * @param type 
  142.      *            场景类型,login:登录, 
  143.      *            coupons:领券 登录清晰化,领券模糊化 
  144.      *            3D: 3D中空自定义字体 
  145.      *            GIF:普通动态GIF 
  146.      *            GIF3D:3D动态GIF 
  147.      *            mix2: 普通字体和3D字体混合 
  148.      *            mixGIF: 混合动态GIF 
  149.      * @throws IOException 
  150.      */  
  151.     public static void outputImage(int w, int h, OutputStream os, String code, String type) throws IOException  
  152.     {  
  153.         int verifySize = code.length();  
  154.         BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);  
  155.         Random rand = new Random();  
  156.         Graphics2D g2 = image.createGraphics();  
  157.         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
  158.         Color[] colors = new Color[5];  
  159.         Color[] colorSpaces = colorRange;  
  160.         float[] fractions = new float[colors.length];  
  161.         for (int i = 0; i < colors.length; i++)  
  162.         {  
  163.             colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];  
  164.             fractions[i] = rand.nextFloat();  
  165.         }  
  166.         Arrays.sort(fractions);  
  167.   
  168.         g2.setColor(Color.GRAY);// 设置边框色  
  169.         g2.fillRect(00, w, h);  
  170.   
  171.         Color c = getRandColor(200250);  
  172.         g2.setColor(c);// 设置背景色  
  173.         g2.fillRect(02, w, h - 4);  
  174.   
  175.         char[] charts = code.toCharArray();  
  176.         for (int i = 0; i < charts.length; i++)  
  177.         {  
  178.             g2.setColor(c);// 设置背景色  
  179.             g2.setFont(getRandomFont(h, type));  
  180.             g2.fillRect(02, w, h - 4);  
  181.         }  
  182.   
  183.         // 1.绘制干扰线  
  184.         Random random = new Random();  
  185.         g2.setColor(getRandColor(160200));// 设置线条的颜色  
  186.         int lineNumbers = 20;  
  187.         if (type.equals("login") || type.contains("mix") || type.contains("3D"))  
  188.         {  
  189.             lineNumbers = 20;  
  190.         }  
  191.         else if (type.equals("coupons"))  
  192.         {  
  193.             lineNumbers = getRandomDrawLine();  
  194.         }  
  195.         else  
  196.         {  
  197.             lineNumbers = getRandomDrawLine();  
  198.         }  
  199.         for (int i = 0; i < lineNumbers; i++)  
  200.         {  
  201.             int x = random.nextInt(w - 1);  
  202.             int y = random.nextInt(h - 1);  
  203.             int xl = random.nextInt(6) + 1;  
  204.             int yl = random.nextInt(12) + 1;  
  205.             g2.drawLine(x, y, x + xl + 40, y + yl + 20);  
  206.         }  
  207.   
  208.         // 2.添加噪点  
  209.         float yawpRate = 0.05f;  
  210.         if (type.equals("login") || type.contains("mix") || type.contains("3D"))  
  211.         {  
  212.             yawpRate = 0.05f; // 噪声率  
  213.         }  
  214.         else if (type.equals("coupons"))  
  215.         {  
  216.             yawpRate = getRandomDrawPoint(); // 噪声率  
  217.         }  
  218.         else  
  219.         {  
  220.             yawpRate = getRandomDrawPoint(); // 噪声率  
  221.         }  
  222.         int area = (int) (yawpRate * w * h);  
  223.         for (int i = 0; i < area; i++)  
  224.         {  
  225.             int x = random.nextInt(w);  
  226.             int y = random.nextInt(h);  
  227.             int rgb = getRandomIntColor();  
  228.             image.setRGB(x, y, rgb);  
  229.         }  
  230.   
  231.         // 3.使图片扭曲  
  232.         shear(g2, w, h, c);  
  233.   
  234.         char[] chars = code.toCharArray();  
  235.         Double rd = rand.nextDouble();  
  236.         Boolean rb = rand.nextBoolean();  
  237.   
  238.         if (type.equals("login"))  
  239.         {  
  240.             for (int i = 0; i < verifySize; i++)  
  241.             {  
  242.                 g2.setColor(getRandColor(100160));  
  243.                 g2.setFont(getRandomFont(h, type));  
  244.   
  245.                 AffineTransform affine = new AffineTransform();  
  246.                 affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  247.                 g2.setTransform(affine);  
  248.                 g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  249.                 g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  250.             }  
  251.   
  252.             g2.dispose();  
  253.             ImageIO.write(image, "jpg", os);  
  254.         }  
  255.         else if (type.contains("GIF") || type.contains("mixGIF"))  
  256.         {  
  257.             GifEncoder gifEncoder = new GifEncoder(); // gif编码类,这个利用了洋人写的编码类  
  258.             // 生成字符  
  259.             gifEncoder.start(os);  
  260.             gifEncoder.setQuality(180);  
  261.             gifEncoder.setDelay(150);  
  262.             gifEncoder.setRepeat(0);  
  263.   
  264.             AlphaComposite ac3;  
  265.             for (int i = 0; i < verifySize; i++)  
  266.             {  
  267.                 g2.setColor(getRandColor(100160));  
  268.                 g2.setFont(getRandomFont(h, type));  
  269.                 for (int j = 0; j < verifySize; j++)  
  270.                 {  
  271.                     AffineTransform affine = new AffineTransform();  
  272.                     affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  273.                     g2.setTransform(affine);  
  274.                     g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  275.   
  276.                     ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(j, i, verifySize));  
  277.                     g2.setComposite(ac3);  
  278.                     g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  279.                     gifEncoder.addFrame(image);  
  280.                     image.flush();  
  281.                 }  
  282.             }  
  283.             gifEncoder.finish();  
  284.             g2.dispose();  
  285.         }  
  286.         else  
  287.         {  
  288.             for (int i = 0; i < verifySize; i++)  
  289.             {  
  290.                 g2.setColor(getRandColor(100160));  
  291.                 g2.setFont(getRandomFont(h, type));  
  292.   
  293.                 AffineTransform affine = new AffineTransform();  
  294.                 affine.setToRotation(Math.PI / 4 * rd * (rb ? 1 : -1), (w / verifySize) * i + (h - 4) / 2, h / 2);  
  295.                 g2.setTransform(affine);  
  296.                 g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));  
  297.                 g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + (h - 4) / 2 - 10);  
  298.             }  
  299.   
  300.             g2.dispose();  
  301.             ImageIO.write(image, "jpg", os);  
  302.         }  
  303.     }  
  304.   
  305.     /** 
  306.      * 获取随机颜色 
  307.      *  
  308.      * @param fc 
  309.      * @param bc 
  310.      * @return 
  311.      */  
  312.     private static Color getRandColor(int fc, int bc)  
  313.     {  
  314.         if (fc > 255)  
  315.         {  
  316.             fc = 255;  
  317.         }  
  318.         if (bc > 255)  
  319.         {  
  320.             bc = 255;  
  321.         }  
  322.         int r = fc + random.nextInt(bc - fc);  
  323.         int g = fc + random.nextInt(bc - fc);  
  324.         int b = fc + random.nextInt(bc - fc);  
  325.         return new Color(r, g, b);  
  326.     }  
  327.   
  328.     private static int getRandomIntColor()  
  329.     {  
  330.         int[] rgb = getRandomRgb();  
  331.         int color = 0;  
  332.         for (int c : rgb)  
  333.         {  
  334.             color = color << 8;  
  335.             color = color | c;  
  336.         }  
  337.         return color;  
  338.     }  
  339.   
  340.     private static int[] getRandomRgb()  
  341.     {  
  342.         int[] rgb = new int[3];  
  343.         for (int i = 0; i < 3; i++)  
  344.         {  
  345.             rgb[i] = random.nextInt(255);  
  346.         }  
  347.         return rgb;  
  348.     }  
  349.   
  350.     /** 
  351.      * 随机字体、随机风格、随机大小 
  352.      *  
  353.      * @param h 
  354.      *            验证码图片高 
  355.      * @return 
  356.      */  
  357.     private static Font getRandomFont(int h, String type)  
  358.     {  
  359.         // 字体  
  360.         String name = fontName[random.nextInt(fontName.length)];  
  361.         // 字体样式  
  362.         int style = fontStyle[random.nextInt(fontStyle.length)];  
  363.         // 字体大小  
  364.         int size = getRandomFontSize(h);  
  365.   
  366.         if (type.equals("login"))  
  367.         {  
  368.             return new Font(name, style, size);  
  369.         }  
  370.         else if (type.equals("coupons"))  
  371.         {  
  372.             return new Font(name, style, size);  
  373.         }  
  374.         else if (type.contains("3D"))  
  375.         {  
  376.             return new ImgFontByte().getFont(size, style);  
  377.         }  
  378.         else if (type.contains("mix"))  
  379.         {  
  380.             int flag = random.nextInt(10);  
  381.             if (flag > 4)  
  382.             {  
  383.                 return new Font(name, style, size);  
  384.             }  
  385.             else  
  386.             {  
  387.                 return new ImgFontByte().getFont(size, style);  
  388.             }  
  389.         }  
  390.         else  
  391.         {  
  392.             return new Font(name, style, size);  
  393.         }  
  394.     }  
  395.   
  396.     /** 
  397.      * 干扰线按范围获取随机数 
  398.      *  
  399.      * @return 
  400.      */  
  401.     private static int getRandomDrawLine()  
  402.     {  
  403.         int min = 20;  
  404.         int max = 155;  
  405.         Random random = new Random();  
  406.         return random.nextInt(max) % (max - min + 1) + min;  
  407.     }  
  408.   
  409.     /** 
  410.      * 噪点数率按范围获取随机数 
  411.      *  
  412.      * @return 
  413.      */  
  414.     private static float getRandomDrawPoint()  
  415.     {  
  416.         float min = 0.05f;  
  417.         float max = 0.1f;  
  418.         return min + ((max - min) * new Random().nextFloat());  
  419.     }  
  420.   
  421.     /** 
  422.      * 获取字体大小按范围随机 
  423.      *  
  424.      * @param h 
  425.      *            验证码图片高 
  426.      * @return 
  427.      */  
  428.     private static int getRandomFontSize(int h)  
  429.     {  
  430.         int min = h - 8;  
  431.         // int max = 46;  
  432.         Random random = new Random();  
  433.         return random.nextInt(11) + min;  
  434.     }  
  435.   
  436.     /** 
  437.      * 3D中空字体自定义属性类 
  438.      *  
  439.      * @author cgtu 
  440.      * @date 2017年5月15日 下午3:27:52 
  441.      */  
  442.     static class ImgFontByte  
  443.     {  
  444.         public Font getFont(int fontSize, int fontStype)  
  445.         {  
  446.             try  
  447.             {  
  448.                 Font font = baseFont;  
  449.                 if (baseFont == null)  
  450.                 {  
  451.                     font = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(imgFontByte.hex2byte(imgFontByte.getFontByteStr())));  
  452.                 }  
  453.                 return font.deriveFont(fontStype, fontSize);  
  454.             }  
  455.             catch (Exception e)  
  456.             {  
  457.                 return new Font("Arial", fontStype, fontSize);  
  458.             }  
  459.         }  
  460.   
  461.         private byte[] hex2byte(String str)  
  462.         {  
  463.             if (str == null)  
  464.                 return null;  
  465.             str = str.trim();  
  466.             int len = str.length();  
  467.             if (len == 0 || len % 2 == 1)  
  468.                 return null;  
  469.   
  470.             byte[] b = new byte[len / 2];  
  471.             try  
  472.             {  
  473.                 for (int i = 0; i < str.length(); i += 2)  
  474.                 {  
  475.                     b[i / 2] = (byte) Integer.decode("0x" + str.substring(i, i + 2)).intValue();  
  476.                 }  
  477.                 return b;  
  478.             }  
  479.             catch (Exception e)  
  480.             {  
  481.                 return null;  
  482.             }  
  483.         }  
  484.   
  485.         // 字体文件的十六进制字符串  
  486.         private String getFontByteStr()  
  487.         {  
  488.   
  489.             return "0001000000100040000400c04f532f327d8175d4000087740000005650434c5461e3d9fb000087cc00000036636d61709cbc69ab00007a64000005e863767420bb32bf1600000f24000000326670676d8333c24f00000f1000000014676c7966302665d800000fc40000663c68646d7806beef530000806c0000070868656164c6469a91000088040000003668686561068002f40000883c00000024686d7478e8bd09b4000077b0000001ac6b65726efffe00650000804c0000001e6c6f6361001a319600007600000001b06d617870013e049f00008860000000206e616d65a927f7000000010c00000e04706f737469df66ea0000795c0000010670726570eacfd8a800000f580000006b0000001f017a000000000000000001de00000000000000000001001c00520000000000000002000e01de0000000000000003003201ec0000000000000004001c005200000000000000050024021e0000000000000006001a02420000000000000007005c0052000100000000000000ef025c0001000000000001000e028500010000000000020007034b0001000000000003001903520001000000000004000e028500010000000000050012036b0001000000000006000d037d0001000000000007002e0285000300010409000001de00000003000104090001001c00520003000104090002000e01de0003000104090003003201ec0003000104090004001c005200030001040900050024021e0003000104090006001a02420003000104090007005c00520003000104090008002c038a000300010409000900180aa2000300010409000a01300b16000300010409000b004c0a12000300010409000c00440c46000300010409000d076003b6000300010409000e00600a120068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f0020002d00200041006300740069006f006e0020004a00610063006b0073006f006e00200043006f007000790072006900670068007400200028004300290020003100390039003800200054006f006d0020004d00750072007000680079002000370020002d00200046007200650065002100200042007500740020006e006f007400200074006f0020006200650020007200650073006f006c006400200028006f006e00200043004400200066006f007200200069006e007300740061006e00630065002100290020002d00200049006d0069006700680074006200650054004d00400061006f006c002e0063006f006d0020002d00200033003300390020005300740069006c006c002000480069006c006c002000520064002e0020002d002000480061006d00640065006e002000430054002000300036003500310038002e00310038003300300020002d00200045006c0069006d0069007400610074006500730020004f0064006f00720073002e0020004e006f00740020004100200043006f007600650072002d0055007000210052006500670075006c0061007200460072006f0067003a002000200041006300740069006f006e0020004a00610063006b0073006f006e00200031002e003000460072006f0067003a002000200038002f00320033002f0039003800200031002e00300041006300740069006f006e004a00610063006b0073006f006e687474703a2f2f6d656d626572732e616f6c2e636f6d2f76726f6f6d666f6e64652f7474662f202d20416374696f6e204a61636b736f6e20436f7079726967687420284329203139393820546f6d204d75727068792037202d20467265652120427574206e6f7420746f206265207265736f6c6420286f6e20434420666f7220696e7374616e63652129202d20496d696768746265544d40616f6c2e636f6d202d20333339205374696c6c2048696c6c2052642e202d2048616d64656e2043542030363531382e31383330202d20456c696d697461746573204f646f72732e204e6f74204120436f7665722d557021526567756c617246726f673a2020416374696f6e204a61636b736f6e20312e3046726f673a2020382f32332f393820312e30416374696f6e4a61636b736f6e005b0044006900760069006400650020004200790020005a00650072006f005d00200046006f006e0074007300480065007200650020006900730020007400680065002000730075006d006d0061007200790020006f006600200074006800650020006c006900630065006e0073006500200066006f00720020007400680069007300200066006f006e0074002c0020007700680069006300680020006d006100790020006200650020006f00760065007200720069006400640065006e00200062007900200028006d006f007300740020006c0069006b0065006c007900200076006500720079002000730069006d0069006c0061007200290020006e006500770020006c006900630065006e0073006500730020006100740020007400680065002000550052004c002000620065006c006f0077002e000d000a000d000a004e004f0020004d004f004e004500590020006d00750073007400200065007600650072002000650078006300680061006e00670065002000680061006e0064007300200066006f00720020007400680069007300200066006f006e0074002000660069006c0065002c00200077006900740068006f007500740020004500580050004c00490043004900540020005700520049005400540045004e0020005000450052004d0049005300530049004f004e002000660072006f006d0020007400680065002000640065007300690067006e00650072002e000d000a000d000a00540068006900730020006d00650061006e007300200079006f00750020004d004100590020004e004f0054002000530045004c004c0020005400480049005300200046004f004e00540020006f006e0020006100200066006f006e0074002d0063006f006c006c0065006300740069006f006e002000430044002c0020006e006f0072002000730069006e00670075006c00610072006c00790020006e006f0072002000700061007200740020006f006600200061006e00790020006f0074006800650072002000740079007000650020007000610063006b006100670065002e000d000a000d000a0059006f00750020006d00610079002000640069007300740072006900620075007400650020007400680069007300200066006f006e0074002000660069006c006500200074006f00200061006e0079006f006e006500200079006f0075002000770061006e0074002c0020006100730020006c006f006e006700200061007300200079006f007500200064006f0020006e006f00740020006d006f006400690066007900200069007400200061006e006400200064006f0020006e006f0074002000630068006100720067006500200061006e00790020006d006f006e006500790020006f0072002000730065007200760069006300650073002e000d000a000d000a0059006f0075002000630061006e00200075007300650020007400680069007300200066006f006e007400200069006e0020006e006f006e0063006f006d006d00650072006300690061006c0020006100700070006c00690063006100740069006f006e007300200061006e006400200077006500620073006900740065007300200066007200650065006c007900200061006e006400200077006900740068006f007500740020007400680065002000640065007300690067006e00650072002700730020007000650072006d0069007300730069006f006e002e000d000a000d000a0059006f0075002000630061006e00200075007300650020007400680069007300200066006f006e007400200074006f002000630072006500610074006500200063006f006d006d00650072006300690061006c002000700072006f006400750063007400730020006f00720020007700650062002000730069007400650073002c00200062007500740020007700680065006e00200061007000700072006f00700072006900610074006500200049002700640020006c006f0076006500200066006f007200200079006f007500200074006f002000730065006e00640020006d00650020006100200063006f006d0070006c0069006d0065006e007400610072007900200063006f007000790020006f006600200074006800650020006900740065006d00200079006f0075002000750073006500200069007400200069006e002e000d000a000d000a0046006f00720020007400680065002000660075006c006c0020006c006900630065006e0073006500200061006e006400200075007000640061007400650073003a000d000a000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f006c006500670061006c002e00680074006d006c000d000a000d000a004d00610069006c0069006e006700200061006400640072006500730073003a000d000a000d000a0054006f006d0020004d0075007200700068007900200037000d000a0033003300390020005300740069006c006c002000480069006c006c002000520064000d000a00480061006d00640065006e002000430054002000300036003500310038002e0031003800330030000d000a005500530041000d000a004300720065006100740065006400200062007900200054006f006d0020004d0075007200700068007900200037002e000d000a000d000a005400680069007300200069007300200061006e00200075006e006500760065006e00200073006f007200740020006f006600200033004400200061006300740069006f006e00200066006f006e0074002e0020004c006f006f006b002000610074002000690074002e000d000a000d000a005b0044006900760069006400650020004200790020005a00650072006f005d00200066006f006e00740073003a000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f00760072006f006f006d0066006f006e00640065002f007400740066002f000d000a0068007400740070003a002f002f006d0065006d0062006500720073002e0061006f006c002e0063006f006d002f0069006d0069006700680074006200650074006d002f4001002c764520b003254523616818236860442d000b030900210018001b0023001c009b003d0063012d0169011001d800b801b200de00f901d55a725a725a725a72000400060000401f1212111110100f0f0e0e0d0d0c0c0b0b0a0a090908080707060601010000018db801ff85456844456844456844456844456844456844456844456844456844456844456844456844456844456844456844b3030246002bb3050446002bb10202456844b10404456844000002003f000001b6032000030007005640200108084009020704020100060502030205040500070605010201030000010046762f3718003f3c2f3c10fd3c10fd3c012f3cfd3c2f3cfd3c003130014968b900000008496861b0405258381137b90008ffc0385933112111253311233f0177fec7fafa0320fce03f02a300060024001000fd03060028003500480055005e006900914044016a6a406b295d5a3d3a5c56095303175f3b3a021b0029022f65032f3603034642403f3d05450304034a4902070b05495549050d68052c4f04233204612c002301011746762f3718003f3f2ffd10fd10fd2ffd3c10fd012ffd3c2f3cfd173c10fd2ffd10fd3c2ffd3c3c2ffd2e2e2e002e2e2e2e3130014968b90017006a496861b0405258381137b9006affc038591314061d01140607160706070623222726272627262726351437363534373637363736333217161716131406232226353436333217160334272627111633143d01343534263d013436031134262726270607061514131736272635160717362734232207061514163332fb0705010401050c34330d02180a0103050f0c01010d072d0e2620030412190d0102361a1e3a30222818161c020310090802062b04010103234a03258a01070a03090a0c202218131526122a02a203640289012a0a3e66060705010f15041e43958401072a2729180603030103020a0d2802fd961e2d392022301f1b021d19070e1afe000506254412291440015e0366fe5101db031d04010204041f373cfe988e15070a01320c07121a390e1119122400ffff001001aa026b03550027000ffffd024f0007000f0140024c0006002e0045021f02a7002500e500e900ef00f901020130408101fdf1f0eae9e7e6e3d3d0cbc9c3bfb8b4afacaaa89b997c6e6a5d5b57504d3a3930241d18110efffaf0eceae8e6d5cecbc6c4bdb9b1afa593898682807674717066655f322a26221b1a090807001f030514020305f502903a029059029035022d530290dc053e0b05552a2804ee553e04f6f54704d74a4404ded77a9e7e019346762f3718002f2f2fb901000004fdb801013c2f3cfd3c10fd2f3cfd2f3cfd3c10fd10fd012ffd2ffd10fd10fdb801003c10fd2f3cfd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e313001b9010400264968b900930103496861b0405258b90103004038b801031137b90103ffc03859011406073615140717151423222623220623222635343736333217071617363534263534371637142322271e01151406232235343635342e0127231407062322272627262322062322262322062322262322061514173633321514232235061514171617161d0116171617363736333217150622071615140706232227061726353437262726273e0135342627262726372e01353437363736373233323633321716171e011514062322270623222623161514062322272627071617161514232227262707161514062322271416151423222623220716333236373633321736373e013332162f01071f01060716333227230607061733363736132e012322071533320213100101140706173f030d370e040b39261f05051315290f041c030c440a0b010f340a0d2b1302062c16102a270a0104010105110405100404090302260b040a180a080f12030210030d090b5235290d1a12120827062413091813170f0b0d0713061a4b3f22031c0a0713033105081026231a0f0a03190a2a0a2d3f471e090f0b04050b060808110f150b040218031a0a08090d1407150d0e0e200b040229050e06111d431c5925030d02111c331014270618112e1b560704082c062b100409980d0216100110020e144c020c04040f0c060127021102031b140f040802260b0a050e080501130b1716070410050d14029830010724030a2d10091d040322092d250c091d0d170104040d190e040d0a0e0f0f02050a433a0a150e180303110c0f030422110f04141101140a081213130c130a0909100d111c02110f0d071480192708100d1a3732150d02070e0f1406260d050a0b0b250e0f040b17030d0208090d030f17101002120b050a1b030e03152543160e010a190106021613620f010e630434052b05110d0f0b0f17fea80109071200ffff002e0045021f02a7000600060000ffff002e0045021f02a7000600060000ffff002e0045021f02a7000600060000ffff0013019c012b03440007000f0000023e00020018ffdc010f030200220030004a40190131314032002923292318001e02272d020c0b031401010b46762f3718003f2f012f3cfd2ffd2e2e2e2e002e2e3130014968b9000b0031496861b0405258381137b90031ffc0385925140623222726272627263d0114373637363736371617161514070607061514171e010726272635343706070615141716010f290c04253a1e141914070c1e283c08100d0c130e1302112f02215b29101944371f1b171e20063e1926382455442f60053a5a49631a060809090d061b384a0a6059a3780638037e42695e899c2f695858754c6200020013fff900f303150018002600494019012727402800211d211d120a1902001f030c14010800010a46762f3718003f3f012ffd2ffd2e2e2e2e002e2e3130014968b9000a0027496861b0405258381137b90027ffc0385913140706070607062322273635342726272635343716171e010734272627161514073637363736f30809072956241010054a1a0212100b05184666411d2035363c101a22171501ad1c5155147f431c10b981ae970d3a36050605011236c8535156612da1f483a10d1c3574650000010029023000e102e4002f006140260130304031002b201f1d23201704000e271b0e1f1402061f022a272d05090d05252511011b46762f3718002f2f10fd2ffd012f3cfd2ffd10fd10fd2e2e2e2e002e2e2e2e3130014968b9001b0030496861b0405258381137b90030ffc03859131407060716151406232227262706070623222635343637262726353433321733342635343332151406151736333216e1120d0d260d0a09130d0c08080c08081614031312161110250606101f02041b08051902920a04020125050b17140e0e0f0f1717080a140b030205131f1308210812180413050613250005001800dc0210030c00300038005e00690072009b404401737340740070665a5150494740351f076e6a625c5b4b4745443e3b39312b291817090700555402354e03695f6261051c57050c383105046a040c54046c0c2301011746762f3718003f2f2ffd10fd2ffd3c10fd2ffd3c012f3cfd2ffd3c2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b900170073496861b0405258381137b90073ffc03859011407062322262316070e012322272627263506272e013d0134373633321633363736333216171e01151407161716171607262726271e0133372635343635262706070627170607363332151406151417333236333534333216333735343605262b011617163337363517262322071617323602100c0f0d1349130101042b3e380a2505021d36072c1809111042110207050d0a89030c250d272810082741032c232218212e09901129520408068b0403010e3943050412103f10191552150206fed71f341716040c1c2602b0191e0453070e145101e21a3943134b081d1306341908500208033e07512c050105535c0a1a0309370c1d3c0809040e4477200906062510af1c12196118060d525a0a04040a4d022d124412100907641f1501150f3d4d081d030801060eb925070b16030000030013ff5e012b0106001d003600460067402901474740481a37313d312f25230a042928020f1e02383733023b43021a3f0500232205131300010f46762f3718002f2f10fd3c10fd012ffd2ffd2f3cfd2ffd3c2e2e2e2e2e2e2e002e2e3130014968b9000f0047496861b0405258381137b90047ffc03859172227302736373637363726272e01353437363332171e01171615140706132627262b01161514061d0116171617161514073635342726371514161514071633323736353427268511171e010b0808120c14220d230c061d7724054102062d3103070509661f02050e161b08232e6a04041f098612023a27230601a21f2d080d0a09191d010a0a481176100a170374071c324a3b4001244a0b0f0406041004580602040209312e40295b0e161b10070c2f0c73351536323c2413020003003c0109021d01e100200038004f007a403401505040511f48443f3e4e432c3821021f2d0210323105072e2d050c04054b2505183836053b4b040722212a0418141b0c011046762f3718002f2f3c2ffd3c3c2ffd2ffd3c10fd10fd10fd3c10fd3c012ffd2ffd3c2e2e2e002e2e2e2e3130014968b900100050496861b0405258381137b90050ffc03859002322062322262322072206232227263534373617321716333236333217161514272322062322262326232207173332363b0132373637361f01262322062b0122070623173637363332163332363326020e2e0d350d1144112b590513051631070b21942c44410c071e071c100c440e081e080b26092d2c6649062a030c037e1120250e104a041123185e1682070c0f041a08123052114512103d0f060112030405054952210b040d010201041e171d67970808020a5204050601010123030c02021c03030404040b0000030012000500f200c50012001a00270051401e0128284029001715171b020013030021020a2505051e040d0d0500010a46762f3718003f2f10fd10fd012ffd2ffd10fd2e002e2e3130014968b9000a0028496861b0405258381137b90028ffc038593714070e012322262726353436333217161716073427160736373627342623220615141716333236f21e043a06134d0b132f2323350e190f1a160c150c0b082e261b161d11131f151c5e321a030a2b0e171d23301f0716151d200c1e270303042517291c161a1519260003002b0051015d02dc001b002300320058401e0133334034002d25222b24201c1200292b06141212141e0419190f011246762f3718002f2f10fd01872e0ec40efc0ec4012e2e2e2e2e2e002e2e2e3130014968b900120033496861b0405258381137b90033ffc03859011407060706070607060716070e0123222635341336373e013332162726233207163332072706070607060716173637363736015d0c0c011b1b1e0e0c0d010503350e1044551e39052a0c103b1d1410031923030a1e1f1a1e0e181d3c0f1f2c1c072c1f02a901181b034848553e337014270a16230e15011f68910c212503130d150a0f3a5e214366ca070fc35616765600000600060012023c0303001b0025003d004d005c006700794035016868406900645e241e66645d231e5702484f4e023e1c030034020c2602206202483a050853054c2e041259044412010800010c46762f3718003f3f2ffd10fd2ffd10fd012ffd2ffd2ffd2ffd2ffd3c10fd2e2e2e2e2e002e2e2e2e3130014968b9000c0068496861b0405258381137b90068ffc038590114070607060706232227263534373637363332171617161716171607342716151406151736273427262726272623220706070615141716171633323736271407060706232227263534373633320335342726232207061514333237362f01060706151417263534023c0508010e3a3e54a05b5328336b250279450d192f1113070b1a39220818073e050701073c3f51ad1d010b09192623344f833324470d1114193850261c1b2341962a120e0836241b5425141093101e08031802012a0f162005553a3f746aa57f59701d093c0f1d36222743624ce54e8969124713022b5d1b29380c534044d70d221d1278395926376447b731556513196e4e634b3f52fea3a70f490b6a5246893025f0020c1f0d33452e18165f00000400290006020f030c00450059008a0093009340420194944095008e716d645e5c59513e211f917e6b4f4e47463c170f260e1a00025a79031a75031d4b03385a038e8f6003586203544005049183050b2f010b00010f46762f3718003f3f10fd3c2ffd012ffd2ffd2f3cfd2ffd2ffd2ffd10fd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b9000f0094496861b0405258381137b90094ffc038592514070623220607060706072227263534373637363336353426353436353427060726272e01353437363736373e01333217161716151416151407061716173633321716171627351427263534263d0134271406151417161f0226270623222702372623220607060706071617363736333017161514070607160f010607161732163332373637363736373426270714173426020f140a24081e05204033830842190b043c380e04030903040d12240f3a252c02080e08920f0e1815040802020201010631051108240903970202071802050504115d04042b3d17020c011209115e0a1515191712261011180b0a0c0405010203086321070e030d0421334b092e2d364e10020117044a1c080407010206070549431f0e0c03070703110b2b0319651a11110808081308490e073b46031114020d252211275d196f19102620131c1905061e2e13600d09211c59208b1f5903220e3d0f4f745e5f0a7a22420735011bc7040c0524252b1a182e101118020a821a2a370d2546060c011e3b020609010203043c080f034b10140e3b000500210022024702f60040004a00870092009b00ae4054019c9c409d009b918c6c49209377694b46368802715802001a027199030f8e032441037160032f850205030744056e1c056e830509807e7c037b050c3d054b4b043a38363a0497545250044e63042c2c09012446762f3718002f2f10fd2f173cfd3c3c10fd10fd2ffd173c10fd2ffd10fd012f3c3cfd2ffd2ffd2ffd2ffd10fd2ffd10fd2e2e2e2e2e2e002e2e2e2e2e2e3130014968b90024009c496861b0405258381137b9009cffc038592514061514151615142322242322263534373637363736373e013534232207060734272635343e01373637363332161514060706070607323316333236333217160334262322073216073613220623222326232223262322353437363736373635342623220706070615161f013633321615140706070607141716173332173233321633323f01360134272627061514161736132627262706353017024708012d46feec4509321c072d1329233c05102a20343b17282008060c27544a44596c2f2612232e0a111f220e1042110d151be418090611111a0310c51556150b16160b0a12120a19394006291c165d4e373c19313a0f210b7f29202d841b251e1e080c020c1527271520802026230501fe471110070a22060a120305060b1525fb0c320b070e0d07670487121f22082a162a17370628081414160401372d050122210d2c1b18725a296233171b250a0108060801120911121c1016fee90501010f072f35062f48370f4f620f06181b0e1c38043a2f203e6214251f1e1c2c3b0c0106014615015906201d09200604360814fe460912264b2f016e00040010000501ed0313003f0048007b00850099404601868640873c807c6f5b5a4340277e716458574d423a2d1d0951023678023c13026223026a6247023684023c6667056d0d050073050025055e10056d55042f2f010000012d46762f3718003f3f10fd2ffd2ffd10fd10fd10fd3c012ffd2ffd2f3cfd10fd10fd10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9002d0086496861b0405258381137b90086ffc03859372227262726272e01273637363332163332363534272627262726272635343736373635342322072627262726273633321617161716151407060716151407061306071736373635340726272635343736353427262322071534173332363332171615140716173736161514062332270607163332373e013534272617060716333237363534b02208130e060f09110111101d0d0b2c0b1321341608030b010604131c1c262a1e4e0b1a1904050f56693276221612151917236a6b527a045412191e1c65111015125d4337435b420d0410401032222e76050a1320343b2501400f1d2e1c5e37284c191c5306370414110d0b0501051208150c190d2324380e110f1f032b1c0d3e05130e0a07090c0b141218200325220d12592b2b21151e23192b302c1f578375362802796d4905013d371f11bf0102040f0212584e3c231c1a0802440f11152f5024244901012f21243a0c1d3d141811702b2a2a2fa2234e192922161200000500160013022a030b00400049007b008a009400974043019595409600908b857c7a715f53514841342e03908b857c6f635b4a462d2b18150057023d69021c4102394d4c033d5003390d040f2a04267605052601100f00011c46762f3718003f3c3f2ffd10fd10fd012ffd2ffd3c10fd2ffd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001c0095496861b0405258381137b90095ffc03859011406072623220706070607060706072306272e01373e013726272635343736373637363736373217161f010607173637363736313216171615140706071617162706070e01151617361726273534363727062322262235343736372627262306070607161716171615140706070607163336373e01333217163336010e010706310607060736373637361306070e01073e013736022a300c0a300506060c0202042007101418383f1401043203383756121b0209090f0b172f111a151603101e40071603211e0a6803060e1202171722bf0b100513070a0eb818311c015c27100156321216040518110b0d1b1120205149260c0d0f0209205a19051f0307100e161f040bfe8f130d03050a120d14080c0723219a1720092e010e1e081801b61c6e02042f2a441d1d1916070d01090a120f25d2150b0c151924334d0828273d0811220806060c41820c2840060e0d1103060a1f2f3e0e0b0a11c1030c084c0a020627830b19051e6d190c9c1e0f23424f17010504305f31620a0e0c0f050c072c3306407f0c35c6102305081c014b0f1814201c372c4c040a087c75feb50b160dd917050b0a7100050018000d02510300003b0049007c0088009800974044019999409a00908b8783817b5f4f443c291f049089817461534a3c1b08002c02574424025769020e7d035778050606044795041485042622045b65048e32011400011b46762f3718003f3f2ffd2ffd2ffd10fd2ffd10fd012ffd2ffd10fd3c10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001b0099496861b0405258381137b90099ffc0385901140e0107262706071617161716151406070e0123222726272e013534373637321633323534232206232226353436373637131617161716171617160734272627262726271e013332163726272e012706070615161716151407062322272627060716171633323736353426352627262726272635343e01333216333603342726271617363332173617262322062322271e0117163332373602511f0e10438f070319313c272227301c6a2227464e160916111106077d233a600a24090d320801030954376c16a2161e0405054509072c1e1d264d0a16160f854236353e6163052a26652e55242025222d2726100b51081c4364414a111a241c3a191a281d06092baf2c09da4d136501113c04541c035a06060368215d6f05164f461e23334002520e680d041e20171b050c0f463e433c4b2415230f1214083f0f07302d0b2c1d3407570f041903172f010f020a0328040d052c2778141b070704040c18111f39c30f0f100a08377b6f46010f1a4c2217140c0c0c13302603082d34600f27082b120d0602020409088f0a3826feb03614050b05240a4a08a112292f1d1a0f0e0f13000007001800170214030e00260030004e005900680074007f00ad40510180804081257a75746f6e6c5a5440332d7e6f6e5854352f2d2c1e13023d4b022578025d46020a74693d026528026572050461054f28270510560404181a042f311e04204f044848045210010400010a46762f3718003f3f2ffd10fd2ffd3c2ffd3c10fd10fd3c10fd10fd012ffd10fd3c3c2ffd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b9000a0080496861b0405258381137b90080ffc03859250607062322272627263534373637363332161514070e0123262322070607363332171e01151403232207061d0136372607220726353437363736373635342f0106070607061514333236353427260322062322271633323726272226353437363332171615140706373426232207313236333217072206071633323736353401ea1c36392c57494423142921585c691623080309070a02912106074f2d3a212b40910e1526293f3b063756651510151c4c6d0204071512b14121f04566191c48081d07453541440c36146f23433e33392a1e213a2d4322143015071d07341c522839051716292835812720233a36543155358267464932175a100703027113251d0a0c5c2e6d01cc111210031f010ed44c022314374e20590e210210180307031ed2692ef76c46501e21fea7051129120b4e3d2334211b15182a4120188913171b0517042b25160d101d2c000005000c0012023102ec002c00390044006b00720093403c0173734074006f6c665b56554b49413a362f19156f6d6c645e533e3a36312f1f151166680806040406666808070606074502004d0425250b00011f46762f3718003f2f10fd012ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001f0073496861b0405258381137b90073ffc038590114070607060f0106070607262726272635343736372207060726272e023534373637363332171e0217162716373627263534262716171607060706071e013332373637342726272607062322070607060716073332373e013332161514070607060716173637363736013534271417160231201a1a3425540d1c0513054b340604524b19253a401920081d0509060abcae2e380e06220803041f0a020202030c0c020601d3314d720d05200509b806cc0706060d16190a23170d94613f0d01082fb006220707101f1c0929651b3d407f181826feed68012502561f37282958459f1c36080703251a0928120e9f922a0c0d021a061a0f7e0d0a05080f0d0603250d2925060a04030f1104171a08102610410a070b0206191f034a151e1a19010102020109060a482e19010a0e06073e3a1045d1132871e52c2c45fdd0090f3c081112000a0003000c0214031600190021002c00500060006f007b0088009400a3000025062322272635343726353436333217161716151407161514060316151407363534031e01151407163534272607262726373e01353426232207061514171615140706070615141716333237363736353427222726353437363332171615140706032227263534373633321716151406032206151416333237363534270e011514173534263534372613220615141633323635342627220706151417263534373637342601a0454a2536b331257a690a4e612a333b474828351d2e461b280414161a190a38020a20288a5a4d312e24070a0f011d3a3c6b3930381519ce362b2e1b20363b211f171b1d462b31161c2e772414422e20291a231e130f8f0e161f05330848233122271e321d801b0f0b2509141218182a1e1239ca6f312b4969781c232d37616c264762306a0275494c2941105071fef11c5e271d0d012f2b323a36103f0906154b2759813c384f3d2a090509090d0227576b424516192e321f2c9c25263538272d29253c2e262efec61f2444322b345a301f2b4401ee3222241e231d24322c0d3d16211f010616063b2715fea83624271e331e292534271d233c1918191b201d100d160006000c000b01ed030a003300570076008c009600a400b6405501a5a540a600a0957f706f4436a3a09e97918d8577737269584a48403e3c2002001a036f1e036f65032734030446030d4d030a07545250030444030d99052b8e8d058b72050f2120056761042b2b01100f00012746762f3718003f3c3f10fd2ffd3c10fd2ffd3c10fd012ffd2ffd3c3c2f3cfd10fd10fd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e3130014968b9002700a5496861b0405258381137b900a5ffc0385901141506151406151c011514061514072322272627262726272635343736373635232227262726353437363332161716171617160730270615140706070617160714171617363534373435343635343635342726373637362f012627262332272623220706151433321514070607060733161735343736071407061506070623302726272635343736373633320723220615141716173627262322070e011514173426353401ed0107060e3d0d2327060a0b0b0b0c0303010a1b1d353e2e2c18327d424b272910060b1c15181203040101030207080e0a020106070201010103033206081b160e0d40193a6d2d16e72203040103060b2346090d6205060101030c30292a3111102f11432c1d2d1126213108014f0d0b07080419240302751b33321a115310174b170d3c0d771604050305100c0b0f0c0e161a09bf0a0e123f3b3a1e38720b0508140b16360d347f7f1320260d1c5d4b2d05080d0e411b0f2222101a591b0e460e0b271e140714116405020605090464321a8c19121c25084b940505cc5483c52715202d0914141d0e0a0a1125172b270904432f132004060517651305034108131003090337ffff000f000500f2022b00260011000000070011fffd0165ffff0013ff5e012b02540026000f0000000700110007018fffff0018ffdc010f03020006000b0000ffff003c00be021d027700270010000000960006001000b5ffff0013fff900f303150006000c000000070001000501d90314003b00460052005e0083008d009900a9404e019a9a409b00968a8474695b554f490c8e8a84807a7672534d4925221608046a69024b5b5d02705a5902313c02421c03706203314203934703001e056d290564675f043645049140003601013146762f3718003f3f2ffd10fd2f3cfd2ffd012ffd2ffd2ffd2ffd10fd10fd3c10fd3c2ffd3c2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b90031009a496861b0405258381137b9009affc03859011407060714171615300706232227262726272627263534373637363534232207060714161514070623222726272627263534373e0133321716171603140706232235343633321334271615140716173637362526232207061d0117263534372206151433323633161735343633321615140716173637262726353436373e01353427261326272627262716171607342623221514163332373601d9161924100a04421c0e141705080606041e1c23121d222d1b1513030509392606151601050474193c284c3a1616351e0f11196c241b66050e03610c131c1a17fef5050b0d0b0909015f5c751a0412040a13562f2b366905271a33021817120918392a2e470606070c060e0a091102170e271611100b0a022332383d1904412a1c0d1609080b0d252c0c593003161b172324301b152f0a280b1e0402020a30040e0a0b8d400e102e112048fddf1a15184b1b230194242210106a55090b01493e790316120e4707080948ae7e5b1d020402432e41342b534138aa0309084d4802090a040f681d5c3338fdeb1e1d23160407242437900c1227111a1310ffff002e0045021f02a700060006000000060000001502a8030d003f006200730080008c00930094403f01949440950092908b8577655f5b4f4e410f928d87817b746e635340004a484c0627252527130221110257564c02212f043370050a7d051b33011b00012146762f3718003f3f10fd2ffd10fd012ffd2f3cfd10fd872e0ec40efc0ec40ec4012e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e3130014968b900210094496861b0405258381137b90094ffc038592514070607060706070623222627262706071615140706070607062322272627263534373637361336373637363736373637363332161716171617161716171627030e01070607060706070615141733323736373426313534373633321716173637361726232207060706070e01071633323736052e0123220706071633323736131407062322353437361716072e012706153602a8101a331c36061914041346010819182413070b2402094b160b30260219140d0d034b0d17070d191f16170e2620040a36040f1d161e23121b1c276ece1c841d12070d0a062f27040c163e3214053d370c15130e0d17403756190205212a0c192b0a1403270b04404ffe9907140404341b2f2a04062c31600a470d1519201e0f200310030609de0e080814101a020d0a520d4555050d823820070d18050828211b021513274128280b0138352c04070d0502030309081b05263f2a48522536364d4001c40d150f372646271bb5920d07041f1a0e0e3c700e1b194f42420a13102f220f1205050b040909271f276205141a0d0c23161801bb13041e19382c11010f45061906210e03000009001e000502310309002d00510061007300830092009c00a800b1000001140706071617161514232227262726353437363736373637363736373637363736333217161716171617161716073427262726272623060706070607061516333236373e013534272627263534373637360326272627262715141617161716333213140623222e0135343637363332171617160314062322263534373e013332171e0137342726270e010732163332373e01273427060732173637361134262b010615141716333227342627061514173602311e2131170501c2b031060c0b23151402030911010d0916020204090212276415161e1a071b1f072036131621437f0d16291c0a191b0802a35b0c0f03253f040d4007262f1827c80f2a33193f2d0b031942343d0d9643340c580e2a080b0f3151120801603b1b145b18020f07050635553c1c181c0518050515031411092772110d160f0a040c0b1f120d1013100922510a01140f1001dc36383e0d1e22082aac510a322f070c8e53520d1820420818152907060b04011c06060a10052428145c042a343e12231801588d325e65250721700601034b2a0a0f361e040b0713181a2afe5f0f0b0e0e241e0805240426120f01ff3637160c0b0d990b10360c2905feb41f33380f0a730915050456e718110f021042100303021b52042b2d6403112c25fe890e2331030908066a041c044711050d4a00000500170067022902f7002b0035003c0049006d00804037016e6e406f004c463f3a36332f27594a463d3b3a36006202082c02131e02484202535702316a05022120054e5a59050f02110f01010846762f3718003f3c2f10fd3c2ffd3c10fd012ffd2ffd2ffd2ffd2ffd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b90008006e496861b0405258381137b9006effc0385925062322272627263534373e013736333233161514070e020706070e01151417333237363736333216171603342627060716173436132627262715140326232206151417161726353413262706232226272635343736373637232207060706070615141716171617163332373602294759b98614110e0b11814661400d094804061015422c1c0e1a1f06292b0715120a0b4703064b0b0501060b07052e0203021c911a1b2831110a210cda060735771c4a08075940640207226638512a090f1a0f1010274a42430c2b2787208f16463e27392f477e080b2b12202e3f0506160d170b2f11411d050105044d0c1c01d2060c06244706091141fe191919141b104201550e3f29241c11221b2b54fee12345124e1e1a1a552e220824471219450b163158213c42142e1b180d0c000006000b000d02410313001900330043005a0063006f007c40330170704071006b67605b564a3c206b604e3c34280a242606100e0e101a02006402445c5b02444204062a043812010600010a46762f3718003f3f2ffd10fd012ffd3c10fd2ffd872e0ec40efc0ec4012e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9000a0070496861b0405258381137b90070ffc0385901060706070627262726353437363736373633321716171617162734272627262306070607060706071633323736373637363736032627262726272627141716171633321314070607062322272635343736373637363332161716073534272627161716173426270607060736373e01023e0624372e3f7a9b1c34231516111518185151b42109090932322c624a4b030c0d030a17163963662e270e3f36180c130cb71111102346203e2a110b0d234b6d8809010638921d18224a070e0c010c0f0c71161723260d420d113e0d2e2312121813162a233d01615f4263212f0302335d06117f5050447681224e962828313067423b2d231520280d386e61d7370f05201c321a5137fea30a0b0802040409170220140814017a08290d187e070b1506dc1c383301254d272a351235250e2c1f3d20732644113f3f522501090d410000030007000a0225031b00370068007d0072402e017e7e407f007d7165644946453b3a333126256958524e43382f231c003f02287303125554041818010600011246762f3718003f3f10fd3c012ffd2ffd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b90012007e496861b0405258381137b9007effc038592514070e0104232227262726272627262726353436373624333217161514060706070607161737161706070e010706153017363332171e0127263505272e01353437363726272322062322273426353437363726352322040716171617141716171617161533323736053427262726272627061514171615161716171617022506070afe9207180805091d150e0e020b091d0e1a013f1d130b081207214a531d05059b030e080409371b2a09a642100d04142908ff00090119422a2a0406071372040a02130804ee061905fee51b02060d16140206010f0a0727788efeaf0c100213131a050d080b13050d11090fba0d1c21085e090e163f9770710b3025161345070d4b32241e092e04140f120d221114244725080e09040609462d080361082d1432060e92010d0c070715291a05018a030904024225264c081b354b98025e152808291f11242c69172c360c6c6b90422109122b3a04801f55492447000006001b003402650302002f003a0044004b006d007b00854039017c7c407d00787064635e5b4a49473f3b3932756e68634c494542350a7202243003003c3b031051022457051e2b04505005281e2801012446762f3718003f2f10fd10fd10fd012ffd2ffd3c2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b90024007c496861b0405258381137b9007cffc03859011607063106272207140716171617161514070e022306070607062206232227262726353412363332163320171617071427140615141716173603353426271606151416273427060733362526272623030616153216333637363332163332363336352306272627363736053601302706070e0115141617363736026401070a35b80248022827250f010309433f01090d0b0f081020093c160f1211350a13061b07011b8b0a1e1b0e090506010bc3110101040d7b1004051207011369698552310103114210061403100924090e390e030914353b07080e2f010207feda170509010d0b010a15080292132034090206080e05050a3004113c16050404245b522c1a05070527241226022d120420033b09011c0f3f0a0405080145fef638041502081a060e139f04161f1a21900b0a0dfdbb030e030261b50e0403072f010909086f030c0912fede1c38720d3d10031a03499235000006001e002302ae02ea003f00500058008e0092009f00a7404d01a0a040a1009e9a92908f574d27269a93908f6555514b402f3302695a59023f002b026e7978022383021767102d95106b53053b4404787638046161043d3b2d046b7d041f8704981d0f011746762f3718002f2f2ffd2ffd2ffd2f3cfd10fd2f3cfd10fd10fd10fd012ffd2ffd3c2ffd2f3cfd3c2ffd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b9001700a0496861b0405258381137b900a0ffc038590114070e01232207060706070607062322272e01272e0135343736373633321716171615140f01270607061514333237262726353436353633321633323316172726272623220706070e0115141736373613262322071617363f01342635062726232207060716333215142322263534373637363736333217353427262726070607061514171633323e01373637360723161f0126232206232227161716333202ae03062709130e090a08071d3d2b5138412a6e17070f2126515c6002593a1401071107883a60743b0b1b010e02117a0921072a29072bb90f070b181f404808010f09304018fb0c08152e0812160f0206172428121656020109171169477034385718181e130d0b040e26372c6c48431846ae38473d030106067b13050a490e08155417374f133930242e012f182c0104100c1914143f1611180f60270d46116553624952021725021b144f0802182036707418210215140f3a0e1905022cc6150507151714040f0516092e1206fecd1f070b15093a2f0717050104050c173402196461465b4b5010060507021614290402020d21746d774c2871184d23181f0911070db7071016110b0a00050027003c02aa02dd003f0050005a00840090008140360191914092008f877c7672605d59534b43393412108b857a7870685b32180e44020b0b02474003002e02515702646a05272705011846762f3718002f2f10fd012ffd2ffd2ffd2ffd10fd2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900180091496861b0405258381137b90091ffc038590114020706232227262726353436352627060726272e023534373637363736373637363f012633321716171e011514070607161736373e0133321632161716073426270316061514171617363736373625262706070607161736252627060f0126232235343736372623220706070615162336373633321706071633323637363736373605342706070615141716173602aa510c1413123a3f071c15113f1832134b4e0917060701091419070405070e09083355160a1c0910090b012629060b0a0e191551291110101b10044a010f05070116130e0f0cfecd09100a090d010b170b011f2a540912045830450e0a0940180b1216212373060a11150e7d4c0e17460d1f0b070504031524fec2210913140907083901e819feb61b2e0809064f101450130808448902171811480a0c151a083b5e77211a1a1e1204010904290c1511101f280703070d4b440b0b0d534d1f0e5908fe8f0a24050a1217053557474829c5101617253607030520470607376e040f12183c2c2b050540a0a7351f2040651449940a182e2020104d86c80a27123d400e0e130f10ac000005000d0007024a0317003a006c00760083008d009c4041018e8e408f008c88827b76716b5856504240363216128a847c736d6968544e4a2c261a0e0a0c0e0668666668505206201e1e203c3b030077026222010600011a46762f3718003f3f012ffd2ffd3c872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001a008e496861b0405258381137b9008effc038592514070607060726272627343736372627262706070623222726273637363736373633321716151406070e01071617161716173637363330171e010735342726270623222726272627262734373637262706070607161736333217161716171617161514070607060715341736033427263506071416171326272627071617161716173607262726350615141736024a20497353960e0d0b0a21363e100c0a0a0c413d03070a07080a17082568bc43040d100d14050f3f0f040e12040412052c20110e081a1c0908085713120b0605080e0c2140272802123c7b07b2050b463a0e060a080506031b141c17162a3a1f80f1070b04050e01e8021a1c051102080b0204180b6e010e150b2205a50a3f151611191529202011470f0c3f584d4c010c0a35162c13230a05112a0f352f130a4203060b0622354512244a010a08040d691106151e1819133b26261933376f0f0e080744140f1a011d1b36120a10342625125b452617080403080d0804661901df0e182501060c045702fed43a626c2e151422290d1ca302b90e2331012103044e05000004000f001d027703150030003a0048007300a7404b0174744075005c514f4e4a413631232118604c4b494741362813064a494a4b062c29292c494a064a4b37363637700200323103003b03086803451d025562050e1b0547582c010e00011346762f3718003f3f2f3cfd10fd012ffd2ffd2ffd2ffd3c10fd872e0ec408fc0ec4872e0ec40efc08c4012e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e3130014968b900130074496861b0405258381137b90074ffc038590114070607060716151407060706232226272635343e023330163332353427262706072e0327373624333216171607353427262717161716033426272e012716171615140736032705151417333633321716151406232227262706070607163332373637363534272627262726353437360277030e261d1c3d3e32664a2d397a1e173e113b06801c3012111211360d390f1f01090e018c0d083804091b0208290603090a19310a07140a131b1c142a0d16fe9223065f0a1f241e493d292e262608120c0d3a92254944212b181414010c0b3622027108090c0d0909c7625f372c1a133d2f2303084a0a186e4e384c40410119032b1873100d064b390a1643162806122719192e0afe7f1dfc100a0a0632898c2f1c2c3101d2684d071752219c88373a3b211d1d0318111071100e19213c3b685151072825020d0c07000400250013026802fd002b006000690074007f40360175754076006c67635f5c503f3b1e1c0602706a6545383426231208065602005902002c020061030072040c43041616010c00011246762f3718003f3f10fd10fd012ffd10fd10fd10fd2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e3130014968b900120075496861b0405258381137b90075ffc03859251407222726271615140e0123222627260235343e0133221716171617363332161716151406071617161716273427262722272635343736372e0127060706072627262706071617161716171e0117161736373637363534263534363332161736173427060716173e01072623220706071633323602685721241c1b130d98080d3c08067f0b850e03151427111e3c0e0e78061440090123301123323b370d01100e2811201832191c1d2f1411201f0209770122060f0813150c05070a43072d1a03280904088e095416052c1d0508053cca1a030335380d0b0c086fbb0d4b241e1e5d1b0c07252d0e0a024f17090c2a030c223a51a0460d28160db90c0c212c162c06033f3a0e0e0b02105e2a6210230a44436b081e7e790202210b902a5426454a401e26160a02090c09051c721e040ba901492a050e182b050401356515101002161e000004002d001e02ad0302002700300040005e00604024015f5f4060005b504a3f382c281f5352413938312d2c2813002105444317010a00011346762f3718003f3f2f3cfd012e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b90013005f496861b0405258381137b9005fffc0385925140706070607060706232226272627262726353637363332171617161716173633321716171e012726272627151417162526272627262f01151417161516173605262723220623220623222726272627062315141716171617161736373602ad34222263b50a201a0f1043031013140c04025537201e420d160303040e8e3c131f1c06041521030f070d0d09feda0d0403020d1027090f0a140c0121080e1c2aa7280512050b08040d0a14662a0d11020819060724477577100904041017020807390f61adbf4f1c4a010f0a4e428333334817271d1b130a7b25223a060c0c2c1d086b233a2f30418526072136510555a8035e25492a0342468d458b120d2147610b6edc1225060e1e00060007001b031602f900410049007c0086009200a00091403f01a1a140a23b9b939189837d706c66604e482e17110b079b8d837d765e4a423b201e070604870272460293780500434205314c053154042828010000011e46762f3718003f3f10fd2ffd10fd3c10fd012ffd2ffd2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b9001e00a1496861b0405258381137b900a1ffc03859252227262736373506070623222e0127262706070607062322272e01272627263736373637363736333217161716173e013332171617161716171615140706070e0103230e0115141736052627062322272627262322070607060706070617161736373637363332171617161736373633321514070607161736371237070607060706073637362726270607061514171617360306070607060706073637363736025f09544b191433051915060b5b120402020b19051619130633381911140605050b0b0e10010c3e6cb30c060506010f20220a49580614141b06032a2c1906395a140a1d0321010244874b150d0f1008641d18420d08060603140f01145a1414220a04060e180f10122622213809121a181849360b043b1ed70b140519170714181da30b160109050809020abd240c0307102102050e1d070d0f1b28240e5e7b05031f1c190d1410103f7f14191b1113050a0b0a092664647156132255170b141c0521191d21020606090c07153fccd12e0a3002a00a340c0609353017348547500b0f0732463d3d196b513406206565a60b035c3a3a0507363659204a66565617141916010aa2ee050e0652491a0c0a585c2e5b0122150f101a220907016d1b15062f56e31f38050a274d7b00050008000d027e0308003d0043007b0083009600a54047019797409800958b837e72665a5449403e2a268d847f7e7c6a5d5c4d423e21006264091f1d1d1f9193061f1d1d1f700252514544023b0c06057878050910051635011900012146762f3718003f3f2ffd2ffd10fd3c012ffd3c2f3cfd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900210097496861b0405258381137b90097ffc038592514070607062322262322062322272627060706070623220623222726272627263534363736333217161736373637363736333236333217161716171416272627061514133534272627060706071617160715062322272627262706071514171e011716171633323632372627262726353433321716171633323736073427151417161727342627262726270607161716171617161736027e03111e17300c3b12092508140f0c0b020511170f39103f0f150c050509111a3c0768440c1c111112070f140d352f1a04100414160f0c090a06db1c1019fb1b0520142b2222021a17020806111d1111482d6535070903130a1605050d381b14050a021a110f0d472a29090521393dbe67211b1bec0f01090f04140a18030c1002060f090c17a4090c3f171203051f17180911300b08093f292a478ec3220853021c2b1c1c2d0d1e150d0c0b0884548d71710413d38e941e1537fe780730db2ffe0a07050638998c440d07412a2bae551303070e1d240ecf52a40209081e3b06644129148c5454020e0e2d09bf08314c3c3b160d370c418362b11522234a610c4181254c1c0006000c002f0212030d001e002f004c005b006d007700734031017878407900756e38726e38305c024d3e030f0e1f0200270234636202554a2c0508600557230419670551081901010e46762f3718003f2f2ffd10fd2ffd10fd3c012ffd3c2ffd2ffd2f3cfd2ffd2e2e2e2e002e2e2e3130014968b9000e0078496861b0405258381137b90078ffc0385901140706070607062322272627263d0114373637363736373633321716171607342726232207061514171e01333237360526272635343736370607060706070617161716171617161716333236131407062322272635343332171e0107342726232207151417163332373635343617260706072216333e010212242d4b1718141b63422422210f0412123a311246194e3e301f181f32436e69301f7f10431453342efed6452724040313080c09090901010d0b0b040b0a0a100a04150425d814192f461c0f3c200c263f42151b25100912161510100f022a0a14190301110f08140176495266220d0d0a331b5c56355e044f1d3f2b352c041458456e5845647ea97c526aaa670d1a50458c305850563a1a1640051724232824323b2b2b0f1612131f05030a011731222b683b4c840c2393321e35450e4f133e4a201c15020a2802151a010406240007001200130216030600240030004c005500650074007e008d403f017f7f4080007d786d665a4f3b2d266b514d44392b251b6002560a023e3d0702417a025d5b6675035631020053041337042169046476047321011300011b46762f3718003f3f2ffd2ffd10fd10fd012ffd2ffd3c2f3cfd2ffd2f3cfd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b9001b007f496861b0405258381137b9007fffc038590114060706070615141615140706260706070623222726272603263534373637363332171607270706070607161736373637342726272623220710133637353426353426353437363736373e0103262322071631323613140706072734353426353437363332072e01232207162332373637363332172706270615141615360216504122420105130d320b0620180d0c1714070c1110050c524128954c5737170c2b341e4a170838373b32322943320d9f492c4244060a1f15152f322f4af319020e75210d548e3a33390c0c24072f641a062713102823010508061411090b0c11142903044d01f34672140c1603041c721c26050401020109071d19101c010cf55314070f0b083a43fe020221130a10170f141317e93f2c26120d18fef4fea30c06071658160a2609100502020814137efe362611271301fd35241e020b011e1659161404013c1016092305010202250c0102080f0a250a1e000700010016021b03030022003f0043004e006d0079009100b8405601929240932176534f4d4643413c3a09918d8b7a7872584d43413e25211d4b4d09414142404041550e837402626a02621102323202132a021b468302627005667e056649040d2e041736044489045c17010300011146762f3718003f3f2ffd2ffd10fd2ffd2ffd10fd012ffd3c2ffd2ffd10fd10fd10fd10fd872e08c40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b900110092496861b0405258381137b90092ffc03859250e01232227262726270607062322272635343736373633321716151407161716151427263534363736353427262322070615141716333237363332173637260f013f010522271e0133323736370637222726270615141615140706232227262726353437363332171615140706032623220716151417363534073427262322070e01151417161716333237263534373617020b05490d05160e0f0804193e302d1a1f7e03053a456773453910060e3769020f0103333e64262479131a86305711030c3d12231714032904fee8242409151770280104414208150912273b2e29151c111b0e0a1b254c472118050734051114053d0d032c171d381e08040a080b140a11140a1f21231b6c0e48150e0e0702150c090e37e02c3972667b826c7c6e1f060c311a196809010b2b0a1b3670647a1852de2471952e0932172d1577132a17310b140c2409122ad31f0e0f18070248031114110c13503a37584057543c5026263d011d030a24a70f0d251ba1a7412f3c251f3e192d384d0b060620111a2d310700070001fff701f0031700330064006a00730083008f009c00b34057019d9d409e0098938d6965575352501184716b675f5948062402137d02749002740802506a17150313025034020096027a8c8a029a7705814d051c8605817204203c042c4a0471706b002c011900201e1c030d00012446762f3718003f173c3f3f3f2f3cfd10fd10fd2ffd10fd10fd012ffd3c2ffd2ffd2ffd173c10fd2ffd10fd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b90024009d496861b0405258381137b9009dffc0385901140706070615161514070e010726272627061514151615142322262326070623222e01353413123736373633321716171617160734272627222726232207060706070607060706171633321633321633363733161716173637262726272635343736373603363726270f0126272e012b0117360114062322263534363534373633321607262306230607061f013e012734262714061514173633343601f03b0e211c64090c6215181f250d03011d0a2a09080e11050f152c282a0b051a151013232a0b75313d1f131e39016f53070c15070d1011120701050501060b041c030f241111080a0e3b46081c380b1a022a2328301b289405042b3c0923020508530c1a1427010a643c13100b240832253522180f14020b01030301182e64170104030c0a030231704410161301a128220d0f35051c3a47150a1b0a16170c550a0101010b460a2c012f0136140a07060809020e283144152033121610072953727283610a201b0f03040690910e738a0d10231e3b0543380b022931273afe0903045d7109ec090f030b1d01023d3b520b131b6e1c19060130311201030e18320f043a1c0427030f3c101a2002104500040011003201ea0310003a0044006f007d0086403b017e7e407f00766651413b2e1076696852433c3b0e2b0e6033024d450200701602605a022031054f5605257c04061304646b047274062501010e46762f3718003f2f2f3cfd2ffd10fd10fd2ffd012ffd2ffd3c2ffd2ffd10fd2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e3130014968b9000e007e496861b0405258381137b9007effc0385901140706070623222726272627263534373216333236353427262726272627263534373e0133321716171615140623222623221514171e01171e010335342627262322071613342726272627263534333217373427262322070615141716171615140706232227060715163332373e01072627162322271617161716333201ea09070828ce1c384507050a1c3d0c7a340d20120e0e3b3a33201e0f10a62e2c343c130f2b1201601d10302344160b2b6902011d071619276024133a47142c5e2e331c3a3414275e4f494444491d192240650e1f535d3d2034427b1a11315d5458100c16312d194e010d131a1516830708090d183b0625704d1f0d0e0704051c1d20443f271e2428611416211a431237240c161e1325231168011407030d020f0f01fece4f2e181d230f222d3f16390d1312372f454e2c201f28422113114622480629070a5a940c0102241e170106060000040007000902970300003a0068007300800096403f0181814082007b756e6a6762570c087b75746e6a69605d554a491f1e7779061f1e1e1f797b061f1e1e1f5002263c3b0200454404311a04182f011800012646762f3718003f3f10fd2ffd3c012ffd3c2ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b900260081496861b0405258381137b90081ffc0385901140706070e022322272627060706070607060706070623222726272637132e0127262726353437363736373e013332171617161716171617160735262726272627262b010607061d01161716171615140615060716173637363736273426353633321633321736253506070607363736373617350607060706073637363736029711080b0308280821293605060f050e0a0b0614061a1e0c132b1d1d2302490d2712212133080903050f0234053e270d4c59232e61203a0a1d20381d1d3b7e593135030a0a2d68100f150b1035284c1924060c0301030111021c052e6b18fdda0f04080f0a0b070807a8041b011a0f1f0f121212240287294811180e101c0c11013d72212921201b350a191b140e0e0e150199130f0609090f1103151a0c1d39061703011317070815050f032817030c0a050a1e160e2621031102260304050d022907a1e30e1947892384220e0112030d09154d7d0a05053236050a12231fbd08020e068a5fad0a12396bd20000020013003e02bb02f8002d005800584021015959405a0045424030283e2e1c0022023849021124053651050a0a1501011146762f3718003f2f10fd2ffd012ffd2ffd2e2e2e2e002e2e2e2e2e3130014968b900110059496861b0405258381137b90059ffc0385901140706070607060706232226272627263534373637161716171e011514070607061516333237363716171617162726270607060706232235343736373637262716232226232207061514171617161716333237363736373602bb2e0c0c0f12486f2c2f52922d0c0a0823252936354e0c05211c1d0309012222361e1e407d0a0a0947295116281617253f5a10100c0d13161e2056051005172b211a0b191b34302a6f524b16031e1501ff327c2120241964240d474212312c1c5389943604040814074804035a600d281e37a66768091b1234305f050b43874e233a7a204c48231f4009010108a87f731435182619110f554d71106449000003000c00030289030f003b00570067007b403201686840690065625852463e372f5f59584e3c281a004e4f06161515162b02484e051c504f045f5e221f011c010c00011a46762f3718003f3f3f3c2f3cfd3c10fd012ffd872e0ec40efc0ec4012e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e3130014968b9001a0068496861b0405258381137b90068ffc0385901140706070615060706070623222726272e012726270326272635343332163332363332171617163114061514171617363736373637363332161716272627060706070607062322272627262726071333361736373637360135342637262b011e01333a01333216028902022a352a5b1b1a2b1615404509042405030532060708130a270a0b2e0c22140c171204060605371a2c1d081505080d93040a2711720d241f1f202036080c010710060b7f144908376d396a152b20ff000a015b172e0b181e061f060c25023c02070a425201509c2f2f47070906023f13092c01972f303827180b020f0a231d071b072f483c3b532b473b1729054108160b0a2a2a3a302f37375b0a61ba2d5a1201fd95011251a62a5237fe0707071e090f162a0400040015005202f802fb003f0073007c008600874038018787408800766c656157504842352b817d79745b5a401e005b5d061e1c1c1e7b040a8404144d042f560421810e0479780a3a3901011e46762f3718003f3c2f2f3cfd3c2ffd2ffd2ffd10fd01872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e3130014968b9001e0087496861b0405258381137b90087ffc03859011407060706070607062322272627060706220623222726272627262726273e0133321f011e0117161716173637363332171617161736373637333216171e01272627060706070623222627262322062322272627262f012606271516171617161736373633321716173616333237363736373603262706072316333227262726271e0133323602f817111101130f0b097c2b120120100f14274f141a23200a0d0d1006172e0b72110324060e35080c0d100607070618262b0a0d0f050d191e0a040b8104071d43224315151f130a050c28051d1b033e1411130b0a1c1b0c164216142c0e26376c1010190a0b170c0d0c2d093f0a14171010093f070a3050040f1b02ad0509097e0c19180e3b024429594142017254151115013d16161c0225211d264d5c1a61c30719020103230d11616e1411100912050f1404416f88163c060b5d5b112162628e241471020a81643e3e732d010115010756b1509e060a2221353b24240103193482616127fe170b180d011c0e0b0e040c111d050000050019001002d902f1002d0056005f0067006f0088403a0170704071006c6b6865605e594f3b363228246c696866655754423f2e180400616002084402165102085a59021c4b050e460511200b00011646762f3718003f2f2ffd2ffd012ffd3c2ffd2ffd10fd3c2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e2e2e2e2e3130014968b900160070496861b0405258381137b90070ffc038590114070607161716151406232226232206232226272635343726272635343e0133221716173037363332171617162734272627060706232226272627060706151416151407161736373e0133321716173635342635343605262715141e0133320135342726271516053526312314171602d9432e2e27261a7d150c92010ec00a0d5804167c1d1e1f0e940b010d543476600e112d2a070a30201d0d126964060a143524220f3238819d2e233060023802064d2e2f507cbcfe162d300b40040601483826262bfed53701100901e6163722232f2f2c4b135c98705a104423156526262e2a3a1a7601625f5e4d3633161c0e0a28250c0b5d581e563b2b0b2c2f0402b50c08873f251b360126472b2b4a0504b5040aa89d3a4313121350fea809163a2625192f261e4620180f0003001300060278030a0032005800650090403e016666406731623b37332a6460553d31213335062c2a2a2c3d3f06211f1f214d020818034646021542021b494705605f5c03592e012501100d0a00012146762f3718003f3c3c3f3f2f173cfd3c012ffd2ffd10fd2ffd872e0ec40efc0ec4872e0ec40efc0ec4012e2e2e2e2e2e002e2e2e2e2e3130014968b900210066496861b0405258381137b90066ffc038590106070e0115140607062322262322062322272e0135343635343635342726272627363736371e011716173637363332161706270607062322272627060716171e0115140615071732333237363f01363736373e01353427260322062322262b01161736272601fe15151b0e14030c300a24060b2e0b1b0a041d080c100d0c01710247421440241108121637450c1f7901454f1a424f0e0c09214b046f204311230c0806096b1a01050a0804020119149e231f9c0a2509081c0733071098090501ca17181e284411e0041502030c0550061b6e1b134d13131a151401e40f1e1d01222a411f3c24566a72206dda2a687b1357ab012d42841a381e134810a7030309885f2e0601120fd810081a16fd7502040f1b02011200040006000f025c03130032003a00430071008840380172724073006a695c564a3b37332a67635a544c44403f3b37332a26150c0b00333506262323260c05611005262e043f461f010500011546762f3718003f3f2f3cfd2ffd2ffd01872e0ec40efc0ec4012e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e002e2e2e2e2e2e2e2e2e3130014968b900150072496861b0405258381137b90072ffc03859250706070623222e012726271306070623222e023534373637363736373633321716171e0117060706073637363332171e01032627262716171613262726271514171627262706070607263534373637363736353427060706071617363332363316151407060716173336373637363736025c0149829c290a3718151204c8193f3b1a093508161310102fbb0549331c14171b08011d010a3229540c443e0608340612480c0d07170512024f040b08180f091f0510215e522b113630102646061520ac7d4e0b0c1f050fb228116c4e3d01270628344415293b5dba092837431c11403819014a0218173b19690b0f0604030f1e01100b0a0b0f019c07134c4386031715270c58018e42460a0c354d04fe651a2a100f0a27190f031d380b1a1613040b055c501b34690b080c74061912143335073d070917b4835e0f6a0f0e12070d1c2b00ffff0018ffdc010f03020006000b000000030014003e015c02ec001e0032003a004a4018013b3b403c003531282737332a1f0d003904031103010d46762f3718002f2f10fd012e2e2e2e2e2e002e2e2e2e3130014968b9000d003b496861b0405258381137b9003bffc03859250e0123222e0127262726272635343736233217161716171617161716171627262726272627262723060716171617161317361726232207162332015c043d100e270f23151503352e075408130e0512030a1b1b1c0b0629243a1a1a210c0f200e23070d1a0205111e2851040d4a10020d2a1b0409600b171315804e4f0aa48d0c0505181507230e1e4c4b503c1e62570f3a627a232453305b060c0d1b2d5987fef1030815101b09ffff0013fff900f303150006000c0000ffff002e0045021f02a7000600060000ffff003a0011021b00e900070010fffdff080004003501b0013103560024002f004c00570077403301585840590a51432b52514d4327154602292e2503180e0c030a31300329390223494b051a56041a37350402041a2701012346762f3718003f2f2f2ffd3c10fd10fd3c012ffd2ffd3c2f173cfd3c10fd2e2e2e2e2e2e002e2e2e3130014968b900230058496861b0405258381137b90058ffc0385913363736171633321716151407141514070623220f01061635142322262726272627263534173427161532173436351407353427262322330615141606171617161716172e013534361716313217262726271514171633323f070b080d14024d194f010103110a0c01022f481861040b0b160506e11d040b0b033507102a49060b0501050303030d1f3f08220c0a0e084020060a1614150c07034b07020201010849281414151422041606081864011541181e1e3f28312c38690d22453a04061e0508103660040a150e052222190f0f2225571b0b8c120a050202c5373c040d0b11363900ffff0000001502a8030d000600240000ffff001e000502310309000600250000ffff00170067022902f7000600260000ffff000b000f023f0313000600270000ffff0007000a0225031b000600280000ffff001b003402640302000600290000ffff001e002302ae02ea0006002a0000ffff0027003c02aa02dd0006002b0000ffff000d0007024a03170006002c0000ffff000f001d027703150006002d0000ffff00250013026802fd0006002e0000ffff002d001e02ad03020006002f0000ffff000c001b031602f9000600300000ffff0008000d027e0308000600310000ffff000c002f0212030d000600320000ffff0012001302160306000600330000ffff00010016021b0303000600340000ffff0001fff701f00317000600350000ffff0011003201ea0310000600360000ffff0007000902970300000600370000ffff0013003e02bb02f8000600380000ffff000c00030289030f000600390000ffff0015005202f802fb0006003a0000ffff0019001002d902f10006003b0000ffff001300060278030a0006003c0000ffff0006000f025c03130006003d0000ffff0018ffdc010f03020006000b0000ffff002b0051015d02dc000600120000ffff0013fff900f303150006000c0000ffff002e0045021f02a7000600060000001d0012fff30328030b00300056006c007c009200a200a900b200c200cc00db00e300e600ed01790185019901ab01bf01d501df01e501e901f201fe020a0213021f022600000114070607060706070623220623220622060706272623222726272627262726353437363736333216321633321716171607342726272627262322262322070607061514171e0117163332363236323632373637363736031406232227343736372e01353437161532173637320714232226233c013516151636333216270e011514173237331407062b01222726353433321607062322353437363736343732171635272206232637331714232227353237162714070615220623342635343736371617060730263530363317270607060726273236333216173e0127072335263635320127372506072637273301140706071407060706070617062322262322062322262322073e013332163b0132373e01352635363736373637141736353426353437362322071633060706233227363534271e01333237363715333637060715301633303736373427262707060736373637363723060706070607062b013633321633323736373637363332171617161716071e013316250623223734373e0137331601140706072206232227263534373e01333217160f01262726232215141706273526363332150722262322151432170623222635343633321615270607163332171526230722273536372e01273516171335262322071516333227362707153317270717273427261514173336013522262322151417363736253427061514161532363332012226232207163332173423220615163332343332272e01232207320328141e2417200a28331102280d030b080f032a2b0e0a1e382b1d2828361211545b981e4f040e07300314505b2f2812130f353a3d370804420477516241301723a1631c4104100809082f042a4532191627922006050e01050c021304130305060c0b43190417050f030b0308118b07240805090b01050a0b0d08062c040b3e28071113071003050108054a010b0107060ec60c040e0a0d07bf0601010d0303070408087f081203100a039f0505060b0f110105040409030b0b39040e01070801520b05feba050f0104031401c207111e0512241e1f0602250b031c04044903224e131628065006083610271b200502023663190d0304070b0c0c020d111c01030808202604461f12051c040a070404180b18080701051c062104365c06123f14170a0a0e0532052c311a032f28064114030402031d0a16332d223f0f2f30261a0d18060a031a0118fe2329060f02170c05060b0301880a0306020c05120b090204210811070555070207050515050d08011b05204f0623030a2f0408101417161c060e52112321040b04230f09060e0c28032d041d32ea070504080806068f030d070e6c110211a60a0e040d070124050e040a07010c0dfe200b10030102041101300516030c07080b12670f0d110411040311a1030f030f032801804c364f2a1b1c09191f0f0304010303011a13141c2e3e474435896c751b06060d2c3c60545c2b4a384248191612252f6f5263423d61880e0303030f13203e202c4f0151084a07020402080c360304040c1c060c19171d040d390e081101051e0a08020905080908030a100c072614340a1b160d02080a04050512010403060ce20b070b0607b902070b2a03030b041820010408c3050b0f090303b61313160f05340414080325020e09050201fe8d051ff909072e1b05fee7180a1024050a160201010405170f0c210b0720310d02030204030205020f0328050d0f090423040b0c0719030901071402110d0b020d0c0a091f0609080e110314040e070a402a060315110c0302050a0113150f02221e0c030613251d0e191f1a220d21090a060614bd191a1717020c111afe1c17130405071712140a070c171a0f0407010f0b2c1b1307044f061b1723030922040b24111d15160611112709040a0503070e14220707070a060901c91d07071a07260806070b950a040a87110103190b0708fee81403120b1401030bf50f05130b040a0102feba040e045827181126032c060e14ffff0020013800d801ec0007000dfff7ff08ffff003501b001310354000600430000ffff0013019c012b03440006000a0000ffff0013ff5c012b01050007000a0000fdc1ffff003501b001310354000600430000ffff003501b0025e035400260064000000070064012d0000ffff0013019302630344002600650000000700650137fff7ffff0012000202e200c80026001100000027001100fb00030007001101f0fffd000000000000007c0000007c0000007c0000007c000002400000025a0000063a0000064a0000065a0000066a0000067c0000075c000008220000090a00000aec00000c2000000d7600000e4200000f3e000010e60000131a0000157600001788000019dc00001c2c00001e400000202c000021f40000246e000024860000249e000024ae000024c6000024d600002730000027400000298a00002b9000002d5200002f2600003108000032fa0000356400003794000039d800003bce00003da600003f240000419a000043f2000045c4000047c400004a1800004c9200004e7c00005094000051f4000053a0000055b8000057800000593800005b1800005b2800005c2c00005c3c00005c4c00005c5e00005dce00005dde00005dee00005dfe00005e0e00005e1e00005e2e00005e3e00005e4e00005e5e00005e6e00005e7e00005e8e00005e9e00005eae00005ebe00005ece00005ede00005eee00005efe00005f0e00005f1e00005f2e00005f3e00005f4e00005f5e00005f6e00005f7e00005f8e00005f9e00005fae00006598000065aa000065ba000065ca000065dc000065ec000066040000661c0000663c01f4003f00000000033d0000033d0000012f0024027c00100246002e0246002e0246002e0246002e0148001301280018011a001300f70029023a0018014800130246003c010b0012017c002b02510006022c002902740021020600100246001602680018023400180248000c023400030209000c010b000f01480013012800180246003c011a001301fb00010246002e02b60000024a001e02460017024e000b025100070282001b02df001e02c400270262000d0291000f0291002502ca002d0330000702960008023d000c02370012022e0001020900010209001102b0000702e4001302ad000c030f001502f3001902850013027c00060128001801760014011a00130246002e0246003a0159003502b60000024a001e02460017024e000b025100070282001b02df001e02c400270262000d0291000f0291002502ca002d0330000c02960008023d000c02370012022e0001020900010209001102b0000702e4001302ad000c030f001502f3001902850013027c000601280018017c002b011a00130246002e0343001200f7002001590035014800130148001301590035027c0035027c0013030100120002000000000000ff7b00140000000000000000000000000000000000000000006b0000000100020003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f006000610086008800b600b700c4010200b400b500ab0d71756f7465726576657273656400000000000300000000000004cc000100000000001c00030001000004cc000604b0000000000253000100000000000000000000000000000001000300000000000000020000000000000000000000000000000000000000000000000000000000000001000000000003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f0060006100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000640065006600670068006900000000000000000000006a0004011c0000000e000800020006007e00a700b62010201d2026ffff0000002000a700b6201020182026ffff0000000000000000000000000001000e00ca00ca00ca00ca00d4ffff0003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f0020002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d004e004f0050005100520053005400550056005700580059005a005b005c005d005e005f00600061006200630010006400650066006700680069006a0000000000010000001a0001000200060001000600320025ffd90032003cff9900000000001000000070090805000707030605050505030303020503050203050506050506050505050203030503050506050505050607060506060607060505050505060706070706060303030505030605050505060706050606060706050505050506070607070606030303050802030303030606070000000a0805000808030606060606030303020603060304060606050606060606050303030603050607060606060607070607070708070606060505070707080806060304030606030706060606060707060707070807060606050507070708080606030403060802030303030606080000000b0906000909030706060606040303030604060304070607060607060606060304030603060608060606070708080707070809070606060606080808090807070304030606040806060607070808070707080907060606060608080809080707030403060903040404040707080000000c0a06000a0a04080707070704040303070407030507070806070707070706030404070306070807070707080908070808090a080707070606080908090908080404030707040807070707080908070808090a08070707060608090809090808040503070a03040404040808090000000d0b07000b0b04080808080804040403070408030508070807080807080707030404080407080908080808080a09080909090b090707070707090a090a0a08080405040808040908080808080a09080909090b090707070707090a090a0a0808040504080b030404040408080a0000000e0c07000c0c04090808080805040403080508040508080907080908080807040504080407080a08080808090a0a0909090a0b0908080807070a0a0a0b0b09090405040808050a08080808090a0a0909090a0b0908080807070a0a0a0b0b0909040504080c030505050509090b0000000f0d08000c0c050a0909090905040404090509040609080908090908090808040504090408090a090909090a0b0b090a0a0b0c0a09090808080a0b0a0c0b0a0a0406040909050a090909090a0b0b090a0a0b0c0a09090808080a0b0a0c0b0a0a040604090d04050505050a0a0c000000100d08000d0d050a0909090905050504090509040609090a08090a09090908040505090508090b090909090a0c0b0a0b0b0b0d0b09090908080b0c0b0d0c0a0a0506050909060b090909090a0c0b0a0b0b0b0d0b09090908080b0c0b0d0c0a0a050605090d04060505060a0a0c000000110e09000e0e050b0a0a0a0a060505040a060a05060a090b090a0a0a0a0a090506050a05090a0c0a0a0a0a0b0c0c0a0b0b0c0e0b0a0a0909090c0d0c0d0d0b0b0506050a0a060c0a0a0a0a0b0c0c0a0b0b0c0e0b0a0a0909090c0d0c0d0d0b0b0506050a0e04060606060b0b0d000000120f09000f0f050b0a0a0a0a060505040a060a05070b0a0b090a0b0a0b0a090506050a05090a0c0b0a0b0b0c0d0d0b0c0c0d0f0c0a0a0a09090c0d0c0e0e0c0b0507050a0a060c0b0a0b0b0c0d0d0b0c0c0d0f0c0a0a0a09090c0d0c0e0e0c0b0507050a0f04060606060b0b0e00000013100a001010060c0b0b0b0b060605050b060b05070b0b0c0a0b0c0b0b0b0a0506060b050a0b0d0b0b0b0b0c0e0d0c0c0c0e100d0b0b0b0a0a0d0e0d0f0e0c0c0607050b0b070d0b0b0b0b0c0e0d0c0c0c0e100d0b0b0b0a0a0d0e0d0f0e0c0c0607050b1005070606070c0c0f00000014110a001111060d0c0c0c0c070606050b070c05080c0b0d0a0c0c0b0c0b0a0507060c060a0c0e0c0c0c0c0d0f0e0c0d0d0e100d0b0b0b0a0a0e0f0e100f0d0d0607060c0c070e0c0c0c0c0d0f0e0c0d0d0e100d0b0b0b0a0a0e0f0e100f0d0d0608060c1105070707070d0d0f00000015120b001111060d0c0c0c0c070606050c070c06080c0c0d0b0c0d0c0c0c0b0607060c060b0c0f0c0c0c0c0d0f0f0d0e0e0f110e0c0c0c0b0b0e100e10100e0d0608060c0c070f0c0c0c0c0d0f0f0d0e0e0f110e0c0c0c0b0b0e100e10100e0d0608060c1205070707070d0d1000000016120b001212070e0d0d0d0d070706050d070d06080d0c0e0b0d0e0c0d0c0b0607070d060b0d0f0d0d0d0d0e10100d0e0e10120f0d0c0c0b0b0f100f11110e0e0708060d0d080f0d0d0d0d0e10100d0e0e10120f0d0c0c0b0b0f100f11110e0e0708060d1205080707080e0e1100000017130c001313070f0d0d0d0d080706060d080d06090e0d0e0c0d0e0d0d0d0c0608070d060c0d100d0d0e0e0f11100e0f0f10130f0d0d0d0c0c10111012110f0f0709060d0d08100d0d0e0e0f11100e0f0f10130f0d0d0d0c0c10111012110f0f0709060d1306080808080f0f1200000018140c001414070f0e0e0e0e080707060e080e06090e0d0f0c0e0f0e0e0e0d0608070e070c0e110e0e0e0e0f12110f10101114100e0e0d0d0d11121013120f0f0709070e0e08110e0e0e0e0f12110f10101114100e0e0d0d0d11121013120f0f0709070e1406080808080f0f120000000001029c01900005000002bc028a0000008f02bc028a000001c5003201030000000004000000000000000000000300000000000000000000000046726f670040002020260355ff5c0000035500a4000000010000000000000001000080000000033d02f10000600002dd0275416374696f6e204a61636b7320202020ffffffff37fffffe4143545230300000000000000001000000010000fae7a6eb5f0f3cf5000003e800000000b2050dda00000000b20549240000ff5c03280356000000030002000100000000000100000356ff38000003430000000d032800010000000000000000000000000000006b00010000006b0227001d01030009000200080040000a00000097013000030003";  
  490.         }  
  491.     }  
  492.   
  493.     /** 
  494.      * 字符和干扰线扭曲 
  495.      *  
  496.      * @param g 
  497.      *            绘制图形的java工具类 
  498.      * @param w1 
  499.      *            验证码图片宽 
  500.      * @param h1 
  501.      *            验证码图片高 
  502.      * @param color 
  503.      *            颜色 
  504.      */  
  505.     private static void shear(Graphics g, int w1, int h1, Color color)  
  506.     {  
  507.         shearX(g, w1, h1, color);  
  508.         shearY(g, w1, h1, color);  
  509.     }  
  510.   
  511.     /** 
  512.      * x轴扭曲 
  513.      *  
  514.      * @param g 
  515.      *            绘制图形的java工具类 
  516.      * @param w1 
  517.      *            验证码图片宽 
  518.      * @param h1 
  519.      *            验证码图片高 
  520.      * @param color 
  521.      *            颜色 
  522.      */  
  523.     private static void shearX(Graphics g, int w1, int h1, Color color)  
  524.     {  
  525.         int period = random.nextInt(2);  
  526.   
  527.         boolean borderGap = true;  
  528.         int frames = 1;  
  529.         int phase = random.nextInt(2);  
  530.   
  531.         for (int i = 0; i < h1; i++)  
  532.         {  
  533.             double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);  
  534.             g.copyArea(0, i, w1, 1, (int) d, 0);  
  535.             if (borderGap)  
  536.             {  
  537.                 g.setColor(color);  
  538.                 g.drawLine((int) d, i, 0, i);  
  539.                 g.drawLine((int) d + w1, i, w1, i);  
  540.             }  
  541.         }  
  542.     }  
  543.   
  544.     /** 
  545.      * y轴扭曲 
  546.      *  
  547.      * @param g 
  548.      *            绘制图形的java工具类 
  549.      * @param w1 
  550.      *            验证码图片宽 
  551.      * @param h1 
  552.      *            验证码图片高 
  553.      * @param color 
  554.      *            颜色 
  555.      */  
  556.     private static void shearY(Graphics g, int w1, int h1, Color color)  
  557.     {  
  558.         int period = random.nextInt(40) + 10// 50;  
  559.   
  560.         boolean borderGap = true;  
  561.         int frames = 20;  
  562.         int phase = 7;  
  563.         for (int i = 0; i < w1; i++)  
  564.         {  
  565.             double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);  
  566.             g.copyArea(i, 01, h1, 0, (int) d);  
  567.             if (borderGap)  
  568.             {  
  569.                 g.setColor(color);  
  570.                 g.drawLine(i, (int) d, i, 0);  
  571.                 g.drawLine(i, (int) d + h1, i, h1);  
  572.             }  
  573.         }  
  574.     }  
  575.   
  576.     /** 
  577.      * 获取透明度,从0到1,自动计算步长 
  578.      *  
  579.      * @param i 
  580.      * @param j 
  581.      * @return float 透明度 
  582.      */  
  583.     private static float getAlpha(int i, int j, int verifySize)  
  584.     {  
  585.         int num = i + j;  
  586.         float r = (float1 / verifySize, s = (verifySize + 1) * r;  
  587.         return num > verifySize ? (num * r - s) : num * r;  
  588.     }  
  589.   
  590.     /** 
  591.      * 生成指定验证码图像文件 - 本地测试生成图片查看效果 
  592.      *  
  593.      * @param w 
  594.      *            验证码图片宽 
  595.      * @param h 
  596.      *            验证码图片高 
  597.      * @param outputFile 
  598.      *            文件流 
  599.      * @param code 
  600.      *            随机验证码 
  601.      * @throws IOException 
  602.      */  
  603.     public static void outputImage(int w, int h, File outputFile, String code) throws IOException  
  604.     {  
  605.         if (outputFile == null)  
  606.         {  
  607.             return;  
  608.         }  
  609.         File dir = outputFile.getParentFile();  
  610.         if (!dir.exists())  
  611.         {  
  612.             dir.mkdirs();  
  613.         }  
  614.         try  
  615.         {  
  616.             outputFile.createNewFile();  
  617.             FileOutputStream fos = new FileOutputStream(outputFile);  
  618.             // outputImage(w, h, fos, code, "login"); //测试登录,噪点和干扰线为0.05f和20  
  619.             // outputImage(w, h, fos, code, "coupons"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  620.             // outputImage(w, h, fos, code, "3D"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  621.             // outputImage(w, h, fos, code, "GIF"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  622.             // outputImage(w, h, fos, code, "GIF3D"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  623.             // outputImage(w, h, fos, code, "mix2"); //测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  624.             outputImage(w, h, fos, code, "mixGIF"); // 测试领券,噪点和干扰线为范围随机值0.05f ~ 0.1f和20 ~ 155  
  625.             fos.close();  
  626.         }  
  627.         catch (IOException e)  
  628.         {  
  629.             throw e;  
  630.         }  
  631.     }  
  632.   
  633.     /** 
  634.      * 本地测试类,可以生成样例验证码图片供观看效果 
  635.      *  
  636.      * @param args 
  637.      * @throws IOException 
  638.      */  
  639.     public static void main(String[] args) throws IOException  
  640.     {  
  641.         File dir = new File("E:/logtest/verifies8");  
  642.         int w = 120, h = 48;  
  643.         for (int i = 0; i < 150; i++)  
  644.         {  
  645.             String verifyCode = generateVerifyCode(4);  
  646.             File file = new File(dir, verifyCode + ".gif");  
  647.             outputImage(w, h, file, verifyCode);  
  648.         }  
  649.     }  
  650. }  



调用的地方随机获取验证码样式:   分布式可以存放在redis

[java]  view plain  copy
  1. public class ValiCodeServlet extends HttpServlet  
  2. {  
  3.     private static final long serialVersionUID = 1L;  
  4.       
  5.     /** 验证码缓存key */  
  6.     public static final String RANDOMCODEKEY = "RANDOMCODEKEY";  
  7.   
  8.     private static final Logger logger = Logger.getLogger(ValiCodeServlet.class);  
  9.   
  10.     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  
  11.     {  
  12.         response.setContentType("image/jpeg");  
  13.         // 设置相应类型,告诉浏览器输出的内容为图片  
  14.         response.setHeader("Pragma""No-cache");  
  15.         // 设置响应头信息,告诉浏览器不要缓存此内容  
  16.         response.setHeader("Cache-Control""no-cache");  
  17.         response.setDateHeader("Expire"0);  
  18.           
  19.         try  
  20.         {  
  21.             // 生成随机验证码  
  22.             int charSize = 4;  
  23.             String verifyCode = RandomVerifyImgCodeUtil.generateVerifyCode(charSize);  
  24.               
  25.             if (StringUtils.isNotBlank(verifyCode))  
  26.             {  
  27.                 RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);  
  28.                   
  29.                 String key = request.getSession().getId() + "_" + RANDOMCODEKEY;  
  30.                 redisUtil.set(key, verifyCode.toString());  
  31.                 /** 设置sesionTooken,90s后失效 **/  
  32.                 redisUtil.expired(key, 90);  
  33.                   
  34.                 // 再次存cookie备份  
  35.                 CookieUtil.addCookie(request, response, RANDOMCODEKEY, verifyCode, 300);  
  36.             }  
  37.               
  38.             // 生成图片规格w宽 h高   
  39.             int w = 100, h = 40;  
  40.             int type = new Random().nextInt(7);   
  41.             if (type == 0)  
  42.             {  
  43.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "login");  
  44.             }  
  45.             else if (type == 1)  
  46.             {  
  47.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "GIF");  
  48.             }  
  49.             else if (type == 2)  
  50.             {  
  51.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "3D");  
  52.             }  
  53.             else if (type == 3)  
  54.             {  
  55.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "GIF3D");  
  56.             }  
  57.             else if (type == 4)  
  58.             {  
  59.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mix2");  
  60.             }  
  61.             else if (type == 5)  
  62.             {  
  63.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mixGIF");  
  64.             }  
  65.             else if (type == 6)  
  66.             {  
  67.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "coupons");  
  68.             }  
  69.             else  
  70.             {  
  71.                 RandomVerifyImgCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode, "mixGIF");  
  72.             }  
  73.         }  
  74.         catch (Exception e)  
  75.         {  
  76.             logger.error(e.getMessage(), e);  
  77.         }  
  78.     }  
  79.   
  80.     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  
  81.     {  
  82.         doGet(request, response);  
  83.     }  
  84.   
  85. }  

GIF格式的老外的工具类: Encoder

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.OutputStream;  
  5.   
  6. /** 
  7.  * @version:1.0 
  8.  */  
  9. public class Encoder  
  10. {  
  11.     private static final int EOF = -1;  
  12.   
  13.     private int imgW, imgH;  
  14.     private byte[] pixAry;  
  15.     private int initCodeSize;  
  16.     private int remaining;  
  17.     private int curPixel;  
  18.   
  19.     // GIFCOMPR.C - GIF Image compression routines  
  20.     //  
  21.     // Lempel-Ziv compression based on 'compress'. GIF modifications by  
  22.     // David Rowley (mgardi@watdcsu.waterloo.edu)  
  23.   
  24.     // General DEFINEs  
  25.   
  26.     static final int BITS = 12;  
  27.   
  28.     static final int HSIZE = 5003// 80% occupancy  
  29.   
  30.     // GIF Image compression - modified 'compress'  
  31.     //  
  32.     // Based on: compress.c - File compression ala IEEE Computer, June 1984.  
  33.     //  
  34.     // By Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)  
  35.     // Jim McKie (decvax!mcvax!jim)  
  36.     // Steve Davies (decvax!vax135!petsd!peora!srd)  
  37.     // Ken Turkowski (decvax!decwrl!turtlevax!ken)  
  38.     // James A. Woods (decvax!ihnp4!ames!jaw)  
  39.     // Joe Orost (decvax!vax135!petsd!joe)  
  40.   
  41.     int n_bits; // number of bits/code  
  42.     int maxbits = BITS; // user settable max # bits/code  
  43.     int maxcode; // maximum code, given n_bits  
  44.     int maxmaxcode = 1 << BITS; // should NEVER generate this code  
  45.   
  46.     int[] htab = new int[HSIZE];  
  47.     int[] codetab = new int[HSIZE];  
  48.   
  49.     int hsize = HSIZE; // for dynamic table sizing  
  50.   
  51.     int free_ent = 0// first unused entry  
  52.   
  53.     // block compression parameters -- after all codes are used up,  
  54.     // and compression rate changes, start over.  
  55.     boolean clear_flg = false;  
  56.   
  57.     // Algorithm: use open addressing double hashing (no chaining) on the  
  58.     // prefix code / next character combination. We do a variant of Knuth's  
  59.     // algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime  
  60.     // secondary probe. Here, the modular division first probe is gives way  
  61.     // to a faster exclusive-or manipulation. Also do block compression with  
  62.     // an adaptive reset, whereby the code table is cleared when the compression  
  63.     // ratio decreases, but after the table fills. The variable-length output  
  64.     // codes are re-sized at this point, and a special CLEAR code is generated  
  65.     // for the decompressor. Late addition: construct the table according to  
  66.     // file size for noticeable speed improvement on small files. Please direct  
  67.     // questions about this implementation to ames!jaw.  
  68.   
  69.     int g_init_bits;  
  70.   
  71.     int ClearCode;  
  72.     int EOFCode;  
  73.   
  74.     // output  
  75.     //  
  76.     // Output the given code.  
  77.     // Inputs:  
  78.     // code: A n_bits-bit integer. If == -1, then EOF. This assumes  
  79.     // that n_bits =< wordsize - 1.  
  80.     // Outputs:  
  81.     // Outputs code to the file.  
  82.     // Assumptions:  
  83.     // Chars are 8 bits long.  
  84.     // Algorithm:  
  85.     // Maintain a BITS character long buffer (so that 8 codes will  
  86.     // fit in it exactly). Use the VAX insv instruction to insert each  
  87.     // code in turn. When the buffer fills up empty it and start over.  
  88.   
  89.     int cur_accum = 0;  
  90.     int cur_bits = 0;  
  91.   
  92.     int masks[] =  
  93.     {  
  94.             0x00000x00010x00030x00070x000F0x001F0x003F0x007F0x00FF0x01FF0x03FF0x07FF0x0FFF0x1FFF0x3FFF0x7FFF0xFFFF  
  95.     };  
  96.   
  97.     // Number of characters so far in this 'packet'  
  98.     int a_count;  
  99.   
  100.     // Define the storage for the packet accumulator  
  101.     byte[] accum = new byte[256];  
  102.   
  103.     // ----------------------------------------------------------------------------  
  104.     Encoder(int width, int height, byte[] pixels, int color_depth)  
  105.     {  
  106.         imgW = width;  
  107.         imgH = height;  
  108.         pixAry = pixels;  
  109.         initCodeSize = Math.max(2, color_depth);  
  110.     }  
  111.   
  112.     // Add a character to the end of the current packet, and if it is 254  
  113.     // characters, flush the packet to disk.  
  114.     void char_out(byte c, OutputStream outs) throws IOException  
  115.     {  
  116.         accum[a_count++] = c;  
  117.         if (a_count >= 254)  
  118.             flush_char(outs);  
  119.     }  
  120.   
  121.     // Clear out the hash table  
  122.   
  123.     // table clear for block compress  
  124.     void cl_block(OutputStream outs) throws IOException  
  125.     {  
  126.         cl_hash(hsize);  
  127.         free_ent = ClearCode + 2;  
  128.         clear_flg = true;  
  129.   
  130.         output(ClearCode, outs);  
  131.     }  
  132.   
  133.     // reset code table  
  134.     void cl_hash(int hsize)  
  135.     {  
  136.         for (int i = 0; i < hsize; ++i)  
  137.             htab[i] = -1;  
  138.     }  
  139.   
  140.     void compress(int init_bits, OutputStream outs) throws IOException  
  141.     {  
  142.         int fcode;  
  143.         int i /* = 0 */;  
  144.         int c;  
  145.         int ent;  
  146.         int disp;  
  147.         int hsize_reg;  
  148.         int hshift;  
  149.   
  150.         // Set up the globals: g_init_bits - initial number of bits  
  151.         g_init_bits = init_bits;  
  152.   
  153.         // Set up the necessary values  
  154.         clear_flg = false;  
  155.         n_bits = g_init_bits;  
  156.         maxcode = MAXCODE(n_bits);  
  157.   
  158.         ClearCode = 1 << (init_bits - 1);  
  159.         EOFCode = ClearCode + 1;  
  160.         free_ent = ClearCode + 2;  
  161.   
  162.         a_count = 0// clear packet  
  163.   
  164.         ent = nextPixel();  
  165.   
  166.         hshift = 0;  
  167.         for (fcode = hsize; fcode < 65536; fcode *= 2)  
  168.             ++hshift;  
  169.         hshift = 8 - hshift; // set hash code range bound  
  170.   
  171.         hsize_reg = hsize;  
  172.         cl_hash(hsize_reg); // clear hash table  
  173.   
  174.         output(ClearCode, outs);  
  175.   
  176.         outer_loop: while ((c = nextPixel()) != EOF)  
  177.         {  
  178.             fcode = (c << maxbits) + ent;  
  179.             i = (c << hshift) ^ ent; // xor hashing  
  180.   
  181.             if (htab[i] == fcode)  
  182.             {  
  183.                 ent = codetab[i];  
  184.                 continue;  
  185.             }  
  186.             else if (htab[i] >= 0// non-empty slot  
  187.             {  
  188.                 disp = hsize_reg - i; // secondary hash (after G. Knott)  
  189.                 if (i == 0)  
  190.                     disp = 1;  
  191.                 do  
  192.                 {  
  193.                     if ((i -= disp) < 0)  
  194.                         i += hsize_reg;  
  195.   
  196.                     if (htab[i] == fcode)  
  197.                     {  
  198.                         ent = codetab[i];  
  199.                         continue outer_loop;  
  200.                     }  
  201.                 }  
  202.                 while (htab[i] >= 0);  
  203.             }  
  204.             output(ent, outs);  
  205.             ent = c;  
  206.             if (free_ent < maxmaxcode)  
  207.             {  
  208.                 codetab[i] = free_ent++; // code -> hashtable  
  209.                 htab[i] = fcode;  
  210.             }  
  211.             else  
  212.                 cl_block(outs);  
  213.         }  
  214.         // Put out the final code.  
  215.         output(ent, outs);  
  216.         output(EOFCode, outs);  
  217.     }  
  218.   
  219.     // ----------------------------------------------------------------------------  
  220.     void encode(OutputStream os) throws IOException  
  221.     {  
  222.         os.write(initCodeSize); // write "initial code size" byte  
  223.   
  224.         remaining = imgW * imgH; // reset navigation variables  
  225.         curPixel = 0;  
  226.   
  227.         compress(initCodeSize + 1, os); // compress and write the pixel data  
  228.   
  229.         os.write(0); // write block terminator  
  230.     }  
  231.   
  232.     // Flush the packet to disk, and reset the accumulator  
  233.     void flush_char(OutputStream outs) throws IOException  
  234.     {  
  235.         if (a_count > 0)  
  236.         {  
  237.             outs.write(a_count);  
  238.             outs.write(accum, 0, a_count);  
  239.             a_count = 0;  
  240.         }  
  241.     }  
  242.   
  243.     final int MAXCODE(int n_bits)  
  244.     {  
  245.         return (1 << n_bits) - 1;  
  246.     }  
  247.   
  248.     // ----------------------------------------------------------------------------  
  249.     // Return the next pixel from the image  
  250.     // ----------------------------------------------------------------------------  
  251.     private int nextPixel()  
  252.     {  
  253.         if (remaining == 0)  
  254.             return EOF;  
  255.   
  256.         --remaining;  
  257.   
  258.         byte pix = pixAry[curPixel++];  
  259.   
  260.         return pix & 0xff;  
  261.     }  
  262.   
  263.     void output(int code, OutputStream outs) throws IOException  
  264.     {  
  265.         cur_accum &= masks[cur_bits];  
  266.   
  267.         if (cur_bits > 0)  
  268.             cur_accum |= (code << cur_bits);  
  269.         else  
  270.             cur_accum = code;  
  271.   
  272.         cur_bits += n_bits;  
  273.   
  274.         while (cur_bits >= 8)  
  275.         {  
  276.             char_out((byte) (cur_accum & 0xff), outs);  
  277.             cur_accum >>= 8;  
  278.             cur_bits -= 8;  
  279.         }  
  280.   
  281.         // If the next entry is going to be too big for the code size,  
  282.         // then increase it, if possible.  
  283.         if (free_ent > maxcode || clear_flg)  
  284.         {  
  285.             if (clear_flg)  
  286.             {  
  287.                 maxcode = MAXCODE(n_bits = g_init_bits);  
  288.                 clear_flg = false;  
  289.             }  
  290.             else  
  291.             {  
  292.                 ++n_bits;  
  293.                 if (n_bits == maxbits)  
  294.                     maxcode = maxmaxcode;  
  295.                 else  
  296.                     maxcode = MAXCODE(n_bits);  
  297.             }  
  298.         }  
  299.   
  300.         if (code == EOFCode)  
  301.         {  
  302.             // At EOF, write the rest of the buffer.  
  303.             while (cur_bits > 0)  
  304.             {  
  305.                 char_out((byte) (cur_accum & 0xff), outs);  
  306.                 cur_accum >>= 8;  
  307.                 cur_bits -= 8;  
  308.             }  
  309.   
  310.             flush_char(outs);  
  311.         }  
  312.     }  
  313. }  

GifDecoder:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.*;  
  4. import java.awt.image.BufferedImage;  
  5. import java.awt.image.DataBufferInt;  
  6. import java.io.BufferedInputStream;  
  7. import java.io.FileInputStream;  
  8. import java.io.IOException;  
  9. import java.io.InputStream;  
  10. import java.net.URL;  
  11. import java.util.ArrayList;  
  12.   
  13. /** 
  14.  * <p> 
  15.  * </p> 
  16.  * 
  17.  * @version:1.0 
  18.  */  
  19. public class GifDecoder  
  20. {  
  21.     /** 
  22.      * File read status: No errors. 
  23.      */  
  24.     public static final int STATUS_OK = 0;  
  25.   
  26.     /** 
  27.      * File read status: Error decoding file (may be partially decoded) 
  28.      */  
  29.     public static final int STATUS_FORMAT_ERROR = 1;  
  30.   
  31.     /** 
  32.      * File read status: Unable to open source. 
  33.      */  
  34.     public static final int STATUS_OPEN_ERROR = 2;  
  35.   
  36.     protected BufferedInputStream in;  
  37.     protected int status;  
  38.   
  39.     protected int width; // full image width  
  40.     protected int height; // full image height  
  41.     protected boolean gctFlag; // global color table used  
  42.     protected int gctSize; // size of global color table  
  43.     protected int loopCount = 1// iterations; 0 = repeat forever  
  44.   
  45.     protected int[] gct; // global color table  
  46.     protected int[] lct; // local color table  
  47.     protected int[] act; // active color table  
  48.   
  49.     protected int bgIndex; // background color index  
  50.     protected int bgColor; // background color  
  51.     protected int lastBgColor; // previous bg color  
  52.     protected int pixelAspect; // pixel aspect ratio  
  53.   
  54.     protected boolean lctFlag; // local color table flag  
  55.     protected boolean interlace; // interlace flag  
  56.     protected int lctSize; // local color table size  
  57.   
  58.     protected int ix, iy, iw, ih; // current image rectangle  
  59.     protected Rectangle lastRect; // last image rect  
  60.     protected BufferedImage image; // current frame  
  61.     protected BufferedImage lastImage; // previous frame  
  62.   
  63.     protected byte[] block = new byte[256]; // current data block  
  64.     protected int blockSize = 0// block size  
  65.   
  66.     // last graphic control extension info  
  67.     protected int dispose = 0;  
  68.     // 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev  
  69.     protected int lastDispose = 0;  
  70.     protected boolean transparency = false// use transparent color  
  71.     protected int delay = 0// delay in milliseconds  
  72.     protected int transIndex; // transparent color index  
  73.   
  74.     protected static final int MaxStackSize = 4096;  
  75.     // max decoder pixel stack size  
  76.   
  77.     // LZW decoder working arrays  
  78.     protected short[] prefix;  
  79.     protected byte[] suffix;  
  80.     protected byte[] pixelStack;  
  81.     protected byte[] pixels;  
  82.   
  83.     protected ArrayList<GifFrame> frames; // frames read from current file  
  84.     protected int frameCount;  
  85.   
  86.     static class GifFrame  
  87.     {  
  88.         public GifFrame(BufferedImage im, int del)  
  89.         {  
  90.             image = im;  
  91.             delay = del;  
  92.         }  
  93.   
  94.         public BufferedImage image;  
  95.         public int delay;  
  96.     }  
  97.   
  98.     /** 
  99.      * Gets display duration for specified frame. 
  100.      * 
  101.      * @param n 
  102.      *            int index of frame 
  103.      * @return delay in milliseconds 
  104.      */  
  105.     public int getDelay(int n)  
  106.     {  
  107.         //  
  108.         delay = -1;  
  109.         if ((n >= 0) && (n < frameCount))  
  110.         {  
  111.             delay = (frames.get(n)).delay;  
  112.         }  
  113.         return delay;  
  114.     }  
  115.   
  116.     /** 
  117.      * Gets the number of frames read from file. 
  118.      *  
  119.      * @return frame count 
  120.      */  
  121.     public int getFrameCount()  
  122.     {  
  123.         return frameCount;  
  124.     }  
  125.   
  126.     /** 
  127.      * Gets the first (or only) image read. 
  128.      * 
  129.      * @return BufferedImage containing first frame, or null if none. 
  130.      */  
  131.     public BufferedImage getImage()  
  132.     {  
  133.         return getFrame(0);  
  134.     }  
  135.   
  136.     /** 
  137.      * Gets the "Netscape" iteration count, if any. 
  138.      * A count of 0 means repeat indefinitiely. 
  139.      * 
  140.      * @return iteration count if one was specified, else 1. 
  141.      */  
  142.     public int getLoopCount()  
  143.     {  
  144.         return loopCount;  
  145.     }  
  146.   
  147.     /** 
  148.      * Creates new frame image from current data (and previous 
  149.      * frames as specified by their disposition codes). 
  150.      */  
  151.     protected void setPixels()  
  152.     {  
  153.         // expose destination image's pixels as int array  
  154.         int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();  
  155.   
  156.         // fill in starting image contents based on last image's dispose code  
  157.         if (lastDispose > 0)  
  158.         {  
  159.             if (lastDispose == 3)  
  160.             {  
  161.                 // use image before last  
  162.                 int n = frameCount - 2;  
  163.                 if (n > 0)  
  164.                 {  
  165.                     lastImage = getFrame(n - 1);  
  166.                 }  
  167.                 else  
  168.                 {  
  169.                     lastImage = null;  
  170.                 }  
  171.             }  
  172.   
  173.             if (lastImage != null)  
  174.             {  
  175.                 int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();  
  176.                 System.arraycopy(prev, 0, dest, 0, width * height);  
  177.                 // copy pixels  
  178.   
  179.                 if (lastDispose == 2)  
  180.                 {  
  181.                     // fill last image rect area with background color  
  182.                     Graphics2D g = image.createGraphics();  
  183.                     Color c = null;  
  184.                     if (transparency)  
  185.                     {  
  186.                         c = new Color(0000); // assume background is transparent  
  187.                     }  
  188.                     else  
  189.                     {  
  190.                         c = new Color(lastBgColor); // use given background color  
  191.                     }  
  192.                     g.setColor(c);  
  193.                     g.setComposite(AlphaComposite.Src); // replace area  
  194.                     g.fill(lastRect);  
  195.                     g.dispose();  
  196.                 }  
  197.             }  
  198.         }  
  199.   
  200.         // copy each source line to the appropriate place in the destination  
  201.         int pass = 1;  
  202.         int inc = 8;  
  203.         int iline = 0;  
  204.         for (int i = 0; i < ih; i++)  
  205.         {  
  206.             int line = i;  
  207.             if (interlace)  
  208.             {  
  209.                 if (iline >= ih)  
  210.                 {  
  211.                     pass++;  
  212.                     switch (pass)  
  213.                     {  
  214.                     case 2:  
  215.                         iline = 4;  
  216.                         break;  
  217.                     case 3:  
  218.                         iline = 2;  
  219.                         inc = 4;  
  220.                         break;  
  221.                     case 4:  
  222.                         iline = 1;  
  223.                         inc = 2;  
  224.                     }  
  225.                 }  
  226.                 line = iline;  
  227.                 iline += inc;  
  228.             }  
  229.             line += iy;  
  230.             if (line < height)  
  231.             {  
  232.                 int k = line * width;  
  233.                 int dx = k + ix; // start of line in dest  
  234.                 int dlim = dx + iw; // end of dest line  
  235.                 if ((k + width) < dlim)  
  236.                 {  
  237.                     dlim = k + width; // past dest edge  
  238.                 }  
  239.                 int sx = i * iw; // start of line in source  
  240.                 while (dx < dlim)  
  241.                 {  
  242.                     // map color and insert in destination  
  243.                     int index = ((int) pixels[sx++]) & 0xff;  
  244.                     int c = act[index];  
  245.                     if (c != 0)  
  246.                     {  
  247.                         dest[dx] = c;  
  248.                     }  
  249.                     dx++;  
  250.                 }  
  251.             }  
  252.         }  
  253.     }  
  254.   
  255.     /** 
  256.      * Gets the image contents of frame n. 
  257.      * 
  258.      * @return BufferedImage representation of frame, or null if n is invalid. 
  259.      */  
  260.     public BufferedImage getFrame(int n)  
  261.     {  
  262.         BufferedImage im = null;  
  263.         if ((n >= 0) && (n < frameCount))  
  264.         {  
  265.             im = (frames.get(n)).image;  
  266.         }  
  267.         return im;  
  268.     }  
  269.   
  270.     /** 
  271.      * Gets image size. 
  272.      * 
  273.      * @return GIF image dimensions 
  274.      */  
  275.     public Dimension getFrameSize()  
  276.     {  
  277.         return new Dimension(width, height);  
  278.     }  
  279.   
  280.     /** 
  281.      * Reads GIF image from stream 
  282.      * 
  283.      * @param is 
  284.      *            BufferedInputStream containing GIF file. 
  285.      * @return read status code (0 = no errors) 
  286.      */  
  287.     public int read(BufferedInputStream is)  
  288.     {  
  289.         init();  
  290.         try  
  291.         {  
  292.             if (is != null)  
  293.             {  
  294.                 in = is;  
  295.                 readHeader();  
  296.                 if (!err())  
  297.                 {  
  298.                     readContents();  
  299.                     if (frameCount < 0)  
  300.                     {  
  301.                         status = STATUS_FORMAT_ERROR;  
  302.                     }  
  303.                 }  
  304.             }  
  305.             else  
  306.             {  
  307.                 status = STATUS_OPEN_ERROR;  
  308.             }  
  309.         }  
  310.         finally  
  311.         {  
  312.             if (null != is)  
  313.             {  
  314.                 try  
  315.                 {  
  316.                     is.close();  
  317.                 }  
  318.                 catch (IOException e)  
  319.                 {  
  320.                     e.printStackTrace();  
  321.                 }  
  322.             }  
  323.         }  
  324.         return status;  
  325.     }  
  326.   
  327.     /** 
  328.      * Reads GIF image from stream 
  329.      * 
  330.      * @param is 
  331.      *            InputStream containing GIF file. 
  332.      * @return read status code (0 = no errors) 
  333.      */  
  334.     public int read(InputStream is)  
  335.     {  
  336.         init();  
  337.         try  
  338.         {  
  339.             if (is != null)  
  340.             {  
  341.                 if (!(is instanceof BufferedInputStream))  
  342.                     is = new BufferedInputStream(is);  
  343.                 in = (BufferedInputStream) is;  
  344.                 readHeader();  
  345.                 if (!err())  
  346.                 {  
  347.                     readContents();  
  348.                     if (frameCount < 0)  
  349.                     {  
  350.                         status = STATUS_FORMAT_ERROR;  
  351.                     }  
  352.                 }  
  353.             }  
  354.             else  
  355.             {  
  356.                 status = STATUS_OPEN_ERROR;  
  357.             }  
  358.         }  
  359.         finally  
  360.         {  
  361.             if (null != is)  
  362.             {  
  363.                 try  
  364.                 {  
  365.                     is.close();  
  366.                 }  
  367.                 catch (IOException e)  
  368.                 {  
  369.                     e.printStackTrace();  
  370.                 }  
  371.             }  
  372.         }  
  373.         return status;  
  374.     }  
  375.   
  376.     /** 
  377.      * Reads GIF file from specified file/URL source 
  378.      * (URL assumed if name contains ":/" or "file:") 
  379.      * 
  380.      * @param name 
  381.      *            String containing source 
  382.      * @return read status code (0 = no errors) 
  383.      */  
  384.     public int read(String name)  
  385.     {  
  386.         status = STATUS_OK;  
  387.         try  
  388.         {  
  389.             name = name.trim().toLowerCase();  
  390.             if ((name.contains("file:")) || (name.indexOf(":/") > 0))  
  391.             {  
  392.                 URL url = new URL(name);  
  393.                 in = new BufferedInputStream(url.openStream());  
  394.             }  
  395.             else  
  396.             {  
  397.                 in = new BufferedInputStream(new FileInputStream(name));  
  398.             }  
  399.             status = read(in);  
  400.         }  
  401.         catch (IOException e)  
  402.         {  
  403.             status = STATUS_OPEN_ERROR;  
  404.         }  
  405.   
  406.         return status;  
  407.     }  
  408.   
  409.     /** 
  410.      * Decodes LZW image data into pixel array. 
  411.      * Adapted from John Cristy's ImageMagick. 
  412.      */  
  413.     protected void decodeImageData()  
  414.     {  
  415.         int NullCode = -1;  
  416.         int npix = iw * ih;  
  417.         int available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, count, i, datum, data_size, first, top, bi, pi;  
  418.   
  419.         if ((pixels == null) || (pixels.length < npix))  
  420.         {  
  421.             pixels = new byte[npix]; // allocate new pixel array  
  422.         }  
  423.         if (prefix == null)  
  424.             prefix = new short[MaxStackSize];  
  425.         if (suffix == null)  
  426.             suffix = new byte[MaxStackSize];  
  427.         if (pixelStack == null)  
  428.             pixelStack = new byte[MaxStackSize + 1];  
  429.   
  430.         // Initialize GIF data stream decoder.  
  431.   
  432.         data_size = read();  
  433.         clear = 1 << data_size;  
  434.         end_of_information = clear + 1;  
  435.         available = clear + 2;  
  436.         old_code = NullCode;  
  437.         code_size = data_size + 1;  
  438.         code_mask = (1 << code_size) - 1;  
  439.         for (code = 0; code < clear; code++)  
  440.         {  
  441.             prefix[code] = 0;  
  442.             suffix[code] = (byte) code;  
  443.         }  
  444.   
  445.         // Decode GIF pixel stream.  
  446.   
  447.         datum = bits = count = first = top = pi = bi = 0;  
  448.   
  449.         for (i = 0; i < npix;)  
  450.         {  
  451.             if (top == 0)  
  452.             {  
  453.                 if (bits < code_size)  
  454.                 {  
  455.                     // Load bytes until there are enough bits for a code.  
  456.                     if (count == 0)  
  457.                     {  
  458.                         // Read a new data block.  
  459.                         count = readBlock();  
  460.                         if (count <= 0)  
  461.                             break;  
  462.                         bi = 0;  
  463.                     }  
  464.                     datum += (((int) block[bi]) & 0xff) << bits;  
  465.                     bits += 8;  
  466.                     bi++;  
  467.                     count--;  
  468.                     continue;  
  469.                 }  
  470.   
  471.                 // Get the next code.  
  472.   
  473.                 code = datum & code_mask;  
  474.                 datum >>= code_size;  
  475.                 bits -= code_size;  
  476.   
  477.                 // Interpret the code  
  478.   
  479.                 if ((code > available) || (code == end_of_information))  
  480.                     break;  
  481.                 if (code == clear)  
  482.                 {  
  483.                     // Reset decoder.  
  484.                     code_size = data_size + 1;  
  485.                     code_mask = (1 << code_size) - 1;  
  486.                     available = clear + 2;  
  487.                     old_code = NullCode;  
  488.                     continue;  
  489.                 }  
  490.                 if (old_code == NullCode)  
  491.                 {  
  492.                     pixelStack[top++] = suffix[code];  
  493.                     old_code = code;  
  494.                     first = code;  
  495.                     continue;  
  496.                 }  
  497.                 in_code = code;  
  498.                 if (code == available)  
  499.                 {  
  500.                     pixelStack[top++] = (byte) first;  
  501.                     code = old_code;  
  502.                 }  
  503.                 while (code > clear)  
  504.                 {  
  505.                     pixelStack[top++] = suffix[code];  
  506.                     code = prefix[code];  
  507.                 }  
  508.                 first = ((int) suffix[code]) & 0xff;  
  509.   
  510.                 // Add a new string to the string table,  
  511.   
  512.                 if (available >= MaxStackSize)  
  513.                     break;  
  514.                 pixelStack[top++] = (byte) first;  
  515.                 prefix[available] = (short) old_code;  
  516.                 suffix[available] = (byte) first;  
  517.                 available++;  
  518.                 if (((available & code_mask) == 0) && (available < MaxStackSize))  
  519.                 {  
  520.                     code_size++;  
  521.                     code_mask += available;  
  522.                 }  
  523.                 old_code = in_code;  
  524.             }  
  525.   
  526.             // Pop a pixel off the pixel stack.  
  527.   
  528.             top--;  
  529.             pixels[pi++] = pixelStack[top];  
  530.             i++;  
  531.         }  
  532.   
  533.         for (i = pi; i < npix; i++)  
  534.         {  
  535.             pixels[i] = 0// clear missing pixels  
  536.         }  
  537.   
  538.     }  
  539.   
  540.     /** 
  541.      * Returns true if an error was encountered during reading/decoding 
  542.      */  
  543.     protected boolean err()  
  544.     {  
  545.         return status != STATUS_OK;  
  546.     }  
  547.   
  548.     /** 
  549.      * Initializes or re-initializes reader 
  550.      */  
  551.     protected void init()  
  552.     {  
  553.         status = STATUS_OK;  
  554.         frameCount = 0;  
  555.         frames = new ArrayList<GifFrame>();  
  556.         gct = null;  
  557.         lct = null;  
  558.     }  
  559.   
  560.     /** 
  561.      * Reads a single byte from the input stream. 
  562.      */  
  563.     protected int read()  
  564.     {  
  565.         int curByte = 0;  
  566.         try  
  567.         {  
  568.             curByte = in.read();  
  569.         }  
  570.         catch (IOException e)  
  571.         {  
  572.             status = STATUS_FORMAT_ERROR;  
  573.         }  
  574.         return curByte;  
  575.     }  
  576.   
  577.     /** 
  578.      * Reads next variable length block from input. 
  579.      * 
  580.      * @return number of bytes stored in "buffer" 
  581.      */  
  582.     protected int readBlock()  
  583.     {  
  584.         blockSize = read();  
  585.         int n = 0;  
  586.         if (blockSize > 0)  
  587.         {  
  588.             try  
  589.             {  
  590.                 int count = 0;  
  591.                 while (n < blockSize)  
  592.                 {  
  593.                     count = in.read(block, n, blockSize - n);  
  594.                     if (count == -1)  
  595.                         break;  
  596.                     n += count;  
  597.                 }  
  598.             }  
  599.             catch (IOException ignored)  
  600.             {  
  601.             }  
  602.   
  603.             if (n < blockSize)  
  604.             {  
  605.                 status = STATUS_FORMAT_ERROR;  
  606.             }  
  607.         }  
  608.         return n;  
  609.     }  
  610.   
  611.     /** 
  612.      * Reads color table as 256 RGB integer values 
  613.      * 
  614.      * @param ncolors 
  615.      *            int number of colors to read 
  616.      * @return int array containing 256 colors (packed ARGB with full alpha) 
  617.      */  
  618.     protected int[] readColorTable(int ncolors)  
  619.     {  
  620.         int nbytes = 3 * ncolors;  
  621.         int[] tab = null;  
  622.         byte[] c = new byte[nbytes];  
  623.         int n = 0;  
  624.         try  
  625.         {  
  626.             n = in.read(c);  
  627.         }  
  628.         catch (IOException ignored)  
  629.         {  
  630.         }  
  631.         if (n < nbytes)  
  632.         {  
  633.             status = STATUS_FORMAT_ERROR;  
  634.         }  
  635.         else  
  636.         {  
  637.             tab = new int[256]; // max size to avoid bounds checks  
  638.             int i = 0;  
  639.             int j = 0;  
  640.             while (i < ncolors)  
  641.             {  
  642.                 int r = ((int) c[j++]) & 0xff;  
  643.                 int g = ((int) c[j++]) & 0xff;  
  644.                 int b = ((int) c[j++]) & 0xff;  
  645.                 tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;  
  646.             }  
  647.         }  
  648.         return tab;  
  649.     }  
  650.   
  651.     /** 
  652.      * Main file parser. Reads GIF content blocks. 
  653.      */  
  654.     protected void readContents()  
  655.     {  
  656.         // read GIF file content blocks  
  657.         boolean done = false;  
  658.         while (!(done || err()))  
  659.         {  
  660.             int code = read();  
  661.             switch (code)  
  662.             {  
  663.   
  664.             case 0x2C// image separator  
  665.                 readImage();  
  666.                 break;  
  667.   
  668.             case 0x21// extension  
  669.                 code = read();  
  670.                 switch (code)  
  671.                 {  
  672.                 case 0xf9// graphics control extension  
  673.                     readGraphicControlExt();  
  674.                     break;  
  675.   
  676.                 case 0xff// application extension  
  677.                     readBlock();  
  678.                     String app = "";  
  679.                     for (int i = 0; i < 11; i++)  
  680.                     {  
  681.                         app += (char) block[i];  
  682.                     }  
  683.                     if (app.equals("NETSCAPE2.0"))  
  684.                     {  
  685.                         readNetscapeExt();  
  686.                     }  
  687.                     else  
  688.                         skip(); // don't care  
  689.                     break;  
  690.   
  691.                 default// uninteresting extension  
  692.                     skip();  
  693.                 }  
  694.                 break;  
  695.   
  696.             case 0x3b// terminator  
  697.                 done = true;  
  698.                 break;  
  699.   
  700.             case 0x00// bad byte, but keep going and see what happens  
  701.                 break;  
  702.   
  703.             default:  
  704.                 status = STATUS_FORMAT_ERROR;  
  705.             }  
  706.         }  
  707.     }  
  708.   
  709.     /** 
  710.      * Reads Graphics Control Extension values 
  711.      */  
  712.     protected void readGraphicControlExt()  
  713.     {  
  714.         read(); // block size  
  715.         int packed = read(); // packed fields  
  716.         dispose = (packed & 0x1c) >> 2// disposal method  
  717.         if (dispose == 0)  
  718.         {  
  719.             dispose = 1// elect to keep old image if discretionary  
  720.         }  
  721.         transparency = (packed & 1) != 0;  
  722.         delay = readShort() * 10// delay in milliseconds  
  723.         transIndex = read(); // transparent color index  
  724.         read(); // block terminator  
  725.     }  
  726.   
  727.     /** 
  728.      * Reads GIF file header information. 
  729.      */  
  730.     protected void readHeader()  
  731.     {  
  732.         String id = "";  
  733.         for (int i = 0; i < 6; i++)  
  734.         {  
  735.             id += (char) read();  
  736.         }  
  737.         if (!id.startsWith("GIF"))  
  738.         {  
  739.             status = STATUS_FORMAT_ERROR;  
  740.             return;  
  741.         }  
  742.   
  743.         readLSD();  
  744.         if (gctFlag && !err())  
  745.         {  
  746.             gct = readColorTable(gctSize);  
  747.             bgColor = gct[bgIndex];  
  748.         }  
  749.     }  
  750.   
  751.     /** 
  752.      * Reads next frame image 
  753.      */  
  754.     protected void readImage()  
  755.     {  
  756.         ix = readShort(); // (sub)image position & size  
  757.         iy = readShort();  
  758.         iw = readShort();  
  759.         ih = readShort();  
  760.   
  761.         int packed = read();  
  762.         lctFlag = (packed & 0x80) != 0// 1 - local color table flag  
  763.         interlace = (packed & 0x40) != 0// 2 - interlace flag  
  764.         // 3 - sort flag  
  765.         // 4-5 - reserved  
  766.         lctSize = 2 << (packed & 7); // 6-8 - local color table size  
  767.   
  768.         if (lctFlag)  
  769.         {  
  770.             lct = readColorTable(lctSize); // read table  
  771.             act = lct; // make local table active  
  772.         }  
  773.         else  
  774.         {  
  775.             act = gct; // make global table active  
  776.             if (bgIndex == transIndex)  
  777.                 bgColor = 0;  
  778.         }  
  779.         int save = 0;  
  780.         if (transparency)  
  781.         {  
  782.             save = act[transIndex];  
  783.             act[transIndex] = 0// set transparent color if specified  
  784.         }  
  785.   
  786.         if (act == null)  
  787.         {  
  788.             status = STATUS_FORMAT_ERROR; // no color table defined  
  789.         }  
  790.   
  791.         if (err())  
  792.             return;  
  793.   
  794.         decodeImageData(); // decode pixel data  
  795.         skip();  
  796.   
  797.         if (err())  
  798.             return;  
  799.   
  800.         frameCount++;  
  801.   
  802.         // create new image to receive frame data  
  803.         image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);  
  804.   
  805.         setPixels(); // transfer pixel data to image  
  806.   
  807.         frames.add(new GifFrame(image, delay)); // add image to frame list  
  808.   
  809.         if (transparency)  
  810.         {  
  811.             act[transIndex] = save;  
  812.         }  
  813.         resetFrame();  
  814.   
  815.     }  
  816.   
  817.     /** 
  818.      * Reads Logical Screen Descriptor 
  819.      */  
  820.     protected void readLSD()  
  821.     {  
  822.   
  823.         // logical screen size  
  824.         width = readShort();  
  825.         height = readShort();  
  826.   
  827.         // packed fields  
  828.         int packed = read();  
  829.         gctFlag = (packed & 0x80) != 0// 1 : global color table flag  
  830.         // 2-4 : color resolution  
  831.         // 5 : gct sort flag  
  832.         gctSize = 2 << (packed & 7); // 6-8 : gct size  
  833.   
  834.         bgIndex = read(); // background color index  
  835.         pixelAspect = read(); // pixel aspect ratio  
  836.     }  
  837.   
  838.     /** 
  839.      * Reads Netscape extenstion to obtain iteration count 
  840.      */  
  841.     protected void readNetscapeExt()  
  842.     {  
  843.         do  
  844.         {  
  845.             readBlock();  
  846.             if (block[0] == 1)  
  847.             {  
  848.                 // loop count sub-block  
  849.                 int b1 = ((int) block[1]) & 0xff;  
  850.                 int b2 = ((int) block[2]) & 0xff;  
  851.                 loopCount = (b2 << 8) | b1;  
  852.             }  
  853.         }  
  854.         while ((blockSize > 0) && !err());  
  855.     }  
  856.   
  857.     /** 
  858.      * Reads next 16-bit value, LSB first 
  859.      */  
  860.     protected int readShort()  
  861.     {  
  862.         // read 16-bit value, LSB first  
  863.         return read() | (read() << 8);  
  864.     }  
  865.   
  866.     /** 
  867.      * Resets frame state for reading next image. 
  868.      */  
  869.     protected void resetFrame()  
  870.     {  
  871.         lastDispose = dispose;  
  872.         lastRect = new Rectangle(ix, iy, iw, ih);  
  873.         lastImage = image;  
  874.         lastBgColor = bgColor;  
  875.         int dispose = 0;  
  876.         boolean transparency = false;  
  877.         int delay = 0;  
  878.         lct = null;  
  879.     }  
  880.   
  881.     /** 
  882.      * Skips variable length blocks up to and including 
  883.      * next zero length block. 
  884.      */  
  885.     protected void skip()  
  886.     {  
  887.         do  
  888.         {  
  889.             readBlock();  
  890.         }  
  891.         while ((blockSize > 0) && !err());  
  892.     }  
  893. }  

GifEncoder:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.awt.*;  
  4. import java.awt.image.BufferedImage;  
  5. import java.awt.image.DataBufferByte;  
  6. import java.io.BufferedOutputStream;  
  7. import java.io.ByteArrayOutputStream;  
  8. import java.io.FileOutputStream;  
  9. import java.io.IOException;  
  10. import java.io.OutputStream;  
  11.   
  12. /** 
  13.  * Class AnimatedGifEncoder - Encodes a GIF file consisting of one or 
  14.  * more frames. 
  15.  *  
  16.  * <pre> 
  17.  * Example: 
  18.  *    AnimatedGifEncoder e = new AnimatedGifEncoder(); 
  19.  *    e.start(outputFileName); 
  20.  *    e.setDelay(1000);   // 1 frame per sec 
  21.  *    e.addFrame(image1); 
  22.  *    e.addFrame(image2); 
  23.  *    e.finish(); 
  24.  * </pre> 
  25.  *  
  26.  * No copyright asserted on the source code of this class. May be used 
  27.  * for any purpose, however, refer to the Unisys LZW patent for restrictions 
  28.  * on use of the associated Encoder class. Please forward any corrections 
  29.  * to questions at fmsware.com. 
  30.  * 
  31.  * @version 1.03 November 2003 
  32.  */  
  33. public class GifEncoder  
  34. {  
  35.     protected int width; // image size  
  36.     protected int height;  
  37.     protected Color transparent = null// transparent color if given  
  38.     protected int transIndex; // transparent index in color table  
  39.     protected int repeat = -1// no repeat  
  40.     protected int delay = 0// frame delay (hundredths)  
  41.     protected boolean started = false// ready to output frames  
  42.     protected OutputStream out;  
  43.     protected BufferedImage image; // current frame  
  44.     protected byte[] pixels; // BGR byte array from frame  
  45.     protected byte[] indexedPixels; // converted frame indexed to palette  
  46.     protected int colorDepth; // number of bit planes  
  47.     protected byte[] colorTab; // RGB palette  
  48.     protected boolean[] usedEntry = new boolean[256]; // active palette entries  
  49.     protected int palSize = 7// color table size (bits-1)  
  50.     protected int dispose = -1// disposal code (-1 = use default)  
  51.     protected boolean closeStream = false// close stream when finished  
  52.     protected boolean firstFrame = true;  
  53.     protected boolean sizeSet = false// if false, get size from first frame  
  54.     protected int sample = 10// default sample interval for quantizer  
  55.   
  56.     /** 
  57.      * Sets the delay time between each frame, or changes it 
  58.      * for subsequent frames (applies to last frame added). 
  59.      * 
  60.      * @param ms 
  61.      *            int delay time in milliseconds 
  62.      */  
  63.     public void setDelay(int ms)  
  64.     {  
  65.         delay = Math.round(ms / 10.0f);  
  66.     }  
  67.   
  68.     /** 
  69.      * Sets the GIF frame disposal code for the last added frame 
  70.      * and any subsequent frames. Default is 0 if no transparent 
  71.      * color has been set, otherwise 2. 
  72.      *  
  73.      * @param code 
  74.      *            int disposal code. 
  75.      */  
  76.     public void setDispose(int code)  
  77.     {  
  78.         if (code >= 0)  
  79.         {  
  80.             dispose = code;  
  81.         }  
  82.     }  
  83.   
  84.     /** 
  85.      * Sets the number of times the set of GIF frames 
  86.      * should be played. Default is 1; 0 means play 
  87.      * indefinitely. Must be invoked before the first 
  88.      * image is added. 
  89.      * 
  90.      * @param iter 
  91.      *            int number of iterations. 
  92.      * @return 
  93.      */  
  94.     public void setRepeat(int iter)  
  95.     {  
  96.         if (iter >= 0)  
  97.         {  
  98.             repeat = iter;  
  99.         }  
  100.     }  
  101.   
  102.     /** 
  103.      * Sets the transparent color for the last added frame 
  104.      * and any subsequent frames. 
  105.      * Since all colors are subject to modification 
  106.      * in the quantization process, the color in the final 
  107.      * palette for each frame closest to the given color 
  108.      * becomes the transparent color for that frame. 
  109.      * May be set to null to indicate no transparent color. 
  110.      * 
  111.      * @param c 
  112.      *            Color to be treated as transparent on display. 
  113.      */  
  114.     public void setTransparent(Color c)  
  115.     {  
  116.         transparent = c;  
  117.     }  
  118.   
  119.     /** 
  120.      * Adds next GIF frame. The frame is not written immediately, but is 
  121.      * actually deferred until the next frame is received so that timing 
  122.      * data can be inserted. Invoking <code>finish()</code> flushes all 
  123.      * frames. If <code>setSize</code> was not invoked, the size of the 
  124.      * first image is used for all subsequent frames. 
  125.      * 
  126.      * @param im 
  127.      *            BufferedImage containing frame to write. 
  128.      * @return true if successful. 
  129.      */  
  130.     public boolean addFrame(BufferedImage im)  
  131.     {  
  132.         if ((im == null) || !started)  
  133.         {  
  134.             return false;  
  135.         }  
  136.         boolean ok = true;  
  137.         try  
  138.         {  
  139.             if (!sizeSet)  
  140.             {  
  141.                 // use first frame's size  
  142.                 setSize(im.getWidth(), im.getHeight());  
  143.             }  
  144.             image = im;  
  145.             getImagePixels(); // convert to correct format if necessary  
  146.             analyzePixels(); // build color table & map pixels  
  147.             if (firstFrame)  
  148.             {  
  149.                 writeLSD(); // logical screen descriptior  
  150.                 writePalette(); // global color table  
  151.                 if (repeat >= 0)  
  152.                 {  
  153.                     // use NS app extension to indicate reps  
  154.                     writeNetscapeExt();  
  155.                 }  
  156.             }  
  157.             writeGraphicCtrlExt(); // write graphic control extension  
  158.             writeImageDesc(); // image descriptor  
  159.             if (!firstFrame)  
  160.             {  
  161.                 writePalette(); // local color table  
  162.             }  
  163.             writePixels(); // encode and write pixel data  
  164.             firstFrame = false;  
  165.         }  
  166.         catch (IOException e)  
  167.         {  
  168.             ok = false;  
  169.         }  
  170.   
  171.         return ok;  
  172.     }  
  173.   
  174.     // added by alvaro  
  175.     public boolean outFlush()  
  176.     {  
  177.         boolean ok = true;  
  178.         try  
  179.         {  
  180.             out.flush();  
  181.             return ok;  
  182.         }  
  183.         catch (IOException e)  
  184.         {  
  185.             ok = false;  
  186.         }  
  187.   
  188.         return ok;  
  189.     }  
  190.   
  191.     public byte[] getFrameByteArray()  
  192.     {  
  193.         return ((ByteArrayOutputStream) out).toByteArray();  
  194.     }  
  195.   
  196.     /** 
  197.      * Flushes any pending data and closes output file. 
  198.      * If writing to an OutputStream, the stream is not 
  199.      * closed. 
  200.      */  
  201.     public boolean finish()  
  202.     {  
  203.         if (!started)  
  204.             return false;  
  205.         boolean ok = true;  
  206.         started = false;  
  207.         try  
  208.         {  
  209.             out.write(0x3b); // gif trailer  
  210.             out.flush();  
  211.             if (closeStream)  
  212.             {  
  213.                 out.close();  
  214.             }  
  215.         }  
  216.         catch (IOException e)  
  217.         {  
  218.             ok = false;  
  219.         }  
  220.   
  221.         return ok;  
  222.     }  
  223.   
  224.     public void reset()  
  225.     {  
  226.         // reset for subsequent use  
  227.         transIndex = 0;  
  228.         out = null;  
  229.         image = null;  
  230.         pixels = null;  
  231.         indexedPixels = null;  
  232.         colorTab = null;  
  233.         closeStream = false;  
  234.         firstFrame = true;  
  235.     }  
  236.   
  237.     /** 
  238.      * Sets frame rate in frames per second. Equivalent to 
  239.      * <code>setDelay(1000/fps)</code>. 
  240.      * 
  241.      * @param fps 
  242.      *            float frame rate (frames per second) 
  243.      */  
  244.     public void setFrameRate(float fps)  
  245.     {  
  246.         if (fps != 0f)  
  247.         {  
  248.             delay = Math.round(100f / fps);  
  249.         }  
  250.     }  
  251.   
  252.     /** 
  253.      * Sets quality of color quantization (conversion of images 
  254.      * to the maximum 256 colors allowed by the GIF specification). 
  255.      * Lower values (minimum = 1) produce better colors, but slow 
  256.      * processing significantly. 10 is the default, and produces 
  257.      * good color mapping at reasonable speeds. Values greater 
  258.      * than 20 do not yield significant improvements in speed. 
  259.      * 
  260.      * @param quality 
  261.      *            int greater than 0. 
  262.      * @return 
  263.      */  
  264.     public void setQuality(int quality)  
  265.     {  
  266.         if (quality < 1)  
  267.             quality = 1;  
  268.         sample = quality;  
  269.     }  
  270.   
  271.     /** 
  272.      * Sets the GIF frame size. The default size is the 
  273.      * size of the first frame added if this method is 
  274.      * not invoked. 
  275.      * 
  276.      * @param w 
  277.      *            int frame width. 
  278.      * @param h 
  279.      *            int frame width. 
  280.      */  
  281.     public void setSize(int w, int h)  
  282.     {  
  283.         if (started && !firstFrame)  
  284.             return;  
  285.         width = w;  
  286.         height = h;  
  287.         if (width < 1)  
  288.             width = 320;  
  289.         if (height < 1)  
  290.             height = 240;  
  291.         sizeSet = true;  
  292.     }  
  293.   
  294.     /** 
  295.      * Initiates GIF file creation on the given stream. The stream 
  296.      * is not closed automatically. 
  297.      * 
  298.      * @param os 
  299.      *            OutputStream on which GIF images are written. 
  300.      * @return false if initial write failed. 
  301.      */  
  302.     public boolean start(OutputStream os)  
  303.     {  
  304.         if (os == null)  
  305.             return false;  
  306.         boolean ok = true;  
  307.         closeStream = false;  
  308.         out = os;  
  309.         try  
  310.         {  
  311.             writeString("GIF89a"); // header  
  312.         }  
  313.         catch (IOException e)  
  314.         {  
  315.             ok = false;  
  316.         }  
  317.         return started = ok;  
  318.     }  
  319.   
  320.     /** 
  321.      * Initiates writing of a GIF file with the specified name. 
  322.      * 
  323.      * @param file 
  324.      *            String containing output file name. 
  325.      * @return false if open or initial write failed. 
  326.      */  
  327.     public boolean start(String file)  
  328.     {  
  329.         boolean ok = true;  
  330.         try  
  331.         {  
  332.             out = new BufferedOutputStream(new FileOutputStream(file));  
  333.             ok = start(out);  
  334.             closeStream = true;  
  335.         }  
  336.         catch (IOException e)  
  337.         {  
  338.             ok = false;  
  339.         }  
  340.         return started = ok;  
  341.     }  
  342.   
  343.     /** 
  344.      * Analyzes image colors and creates color map. 
  345.      */  
  346.     protected void analyzePixels()  
  347.     {  
  348.         int len = pixels.length;  
  349.         int nPix = len / 3;  
  350.         indexedPixels = new byte[nPix];  
  351.         Quant nq = new Quant(pixels, len, sample);  
  352.         // initialize quantizer  
  353.         colorTab = nq.process(); // create reduced palette  
  354.         // convert map from BGR to RGB  
  355.         for (int i = 0; i < colorTab.length; i += 3)  
  356.         {  
  357.             byte temp = colorTab[i];  
  358.             colorTab[i] = colorTab[i + 2];  
  359.             colorTab[i + 2] = temp;  
  360.             usedEntry[i / 3] = false;  
  361.         }  
  362.         // map image pixels to new palette  
  363.         int k = 0;  
  364.         for (int i = 0; i < nPix; i++)  
  365.         {  
  366.             int index = nq.map(pixels[k++] & 0xff, pixels[k++] & 0xff, pixels[k++] & 0xff);  
  367.             usedEntry[index] = true;  
  368.             indexedPixels[i] = (byte) index;  
  369.         }  
  370.         pixels = null;  
  371.         colorDepth = 8;  
  372.         palSize = 7;  
  373.         // get closest match to transparent color if specified  
  374.         if (transparent != null)  
  375.         {  
  376.             transIndex = findClosest(transparent);  
  377.         }  
  378.     }  
  379.   
  380.     /** 
  381.      * Returns index of palette color closest to c 
  382.      */  
  383.     protected int findClosest(Color c)  
  384.     {  
  385.         if (colorTab == null)  
  386.             return -1;  
  387.         int r = c.getRed();  
  388.         int g = c.getGreen();  
  389.         int b = c.getBlue();  
  390.         int minpos = 0;  
  391.         int dmin = 256 * 256 * 256;  
  392.         int len = colorTab.length;  
  393.         for (int i = 0; i < len;)  
  394.         {  
  395.             int dr = r - (colorTab[i++] & 0xff);  
  396.             int dg = g - (colorTab[i++] & 0xff);  
  397.             int db = b - (colorTab[i] & 0xff);  
  398.             int d = dr * dr + dg * dg + db * db;  
  399.             int index = i / 3;  
  400.             if (usedEntry[index] && (d < dmin))  
  401.             {  
  402.                 dmin = d;  
  403.                 minpos = index;  
  404.             }  
  405.             i++;  
  406.         }  
  407.         return minpos;  
  408.     }  
  409.   
  410.     /** 
  411.      * Extracts image pixels into byte array "pixels" 
  412.      */  
  413.     protected void getImagePixels()  
  414.     {  
  415.         int w = image.getWidth();  
  416.         int h = image.getHeight();  
  417.         int type = image.getType();  
  418.         if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR))  
  419.         {  
  420.             // create new image with right size/format  
  421.             BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);  
  422.             Graphics2D g = temp.createGraphics();  
  423.             g.drawImage(image, 00null);  
  424.             image = temp;  
  425.         }  
  426.         pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();  
  427.     }  
  428.   
  429.     /** 
  430.      * Writes Graphic Control Extension 
  431.      */  
  432.     protected void writeGraphicCtrlExt() throws IOException  
  433.     {  
  434.         out.write(0x21); // extension introducer  
  435.         out.write(0xf9); // GCE label  
  436.         out.write(4); // data block size  
  437.         int transp, disp;  
  438.         if (transparent == null)  
  439.         {  
  440.             transp = 0;  
  441.             disp = 0// dispose = no action  
  442.         }  
  443.         else  
  444.         {  
  445.             transp = 1;  
  446.             disp = 2// force clear if using transparent color  
  447.         }  
  448.         if (dispose >= 0)  
  449.         {  
  450.             disp = dispose & 7// user override  
  451.         }  
  452.         disp <<= 2;  
  453.   
  454.         // packed fields  
  455.         out.write(0 | // 1:3 reserved  
  456.                 disp | // 4:6 disposal  
  457.                 0 | // 7 user input - 0 = none  
  458.                 transp); // 8 transparency flag  
  459.   
  460.         writeShort(delay); // delay x 1/100 sec  
  461.         out.write(transIndex); // transparent color index  
  462.         out.write(0); // block terminator  
  463.     }  
  464.   
  465.     /** 
  466.      * Writes Image Descriptor 
  467.      */  
  468.     protected void writeImageDesc() throws IOException  
  469.     {  
  470.         out.write(0x2c); // image separator  
  471.         writeShort(0); // image position x,y = 0,0  
  472.         writeShort(0);  
  473.         writeShort(width); // image size  
  474.         writeShort(height);  
  475.         // packed fields  
  476.         if (firstFrame)  
  477.         {  
  478.             // no LCT - GCT is used for first (or only) frame  
  479.             out.write(0);  
  480.         }  
  481.         else  
  482.         {  
  483.             // specify normal LCT  
  484.             out.write(0x80 | // 1 local color table 1=yes  
  485.                     0 | // 2 interlace - 0=no  
  486.                     0 | // 3 sorted - 0=no  
  487.                     0 | // 4-5 reserved  
  488.                     palSize); // 6-8 size of color table  
  489.         }  
  490.     }  
  491.   
  492.     /** 
  493.      * Writes Logical Screen Descriptor 
  494.      */  
  495.     protected void writeLSD() throws IOException  
  496.     {  
  497.         // logical screen size  
  498.         writeShort(width);  
  499.         writeShort(height);  
  500.         // packed fields  
  501.         out.write((0x80 | // 1 : global color table flag = 1 (gct used)  
  502.                 0x70 | // 2-4 : color resolution = 7  
  503.                 0x00 | // 5 : gct sort flag = 0  
  504.                 palSize)); // 6-8 : gct size  
  505.   
  506.         out.write(0); // background color index  
  507.         out.write(0); // pixel aspect ratio - assume 1:1  
  508.     }  
  509.   
  510.     /** 
  511.      * Writes Netscape application extension to define 
  512.      * repeat count. 
  513.      */  
  514.     protected void writeNetscapeExt() throws IOException  
  515.     {  
  516.         out.write(0x21); // extension introducer  
  517.         out.write(0xff); // app extension label  
  518.         out.write(11); // block size  
  519.         writeString("NETSCAPE" + "2.0"); // app id + auth code  
  520.         out.write(3); // sub-block size  
  521.         out.write(1); // loop sub-block id  
  522.         writeShort(repeat); // loop count (extra iterations, 0=repeat forever)  
  523.         out.write(0); // block terminator  
  524.     }  
  525.   
  526.     /** 
  527.      * Writes color table 
  528.      */  
  529.     protected void writePalette() throws IOException  
  530.     {  
  531.         out.write(colorTab, 0, colorTab.length);  
  532.         int n = (3 * 256) - colorTab.length;  
  533.         for (int i = 0; i < n; i++)  
  534.         {  
  535.             out.write(0);  
  536.         }  
  537.     }  
  538.   
  539.     /** 
  540.      * Encodes and writes pixel data 
  541.      */  
  542.     protected void writePixels() throws IOException  
  543.     {  
  544.         Encoder encoder = new Encoder(width, height, indexedPixels, colorDepth);  
  545.         encoder.encode(out);  
  546.     }  
  547.   
  548.     /** 
  549.      * Write 16-bit value to output stream, LSB first 
  550.      */  
  551.     protected void writeShort(int value) throws IOException  
  552.     {  
  553.         out.write(value & 0xff);  
  554.         out.write((value >> 8) & 0xff);  
  555.     }  
  556.   
  557.     /** 
  558.      * Writes string to output stream 
  559.      */  
  560.     protected void writeString(String s) throws IOException  
  561.     {  
  562.         for (int i = 0; i < s.length(); i++)  
  563.         {  
  564.             out.write((byte) s.charAt(i));  
  565.         }  
  566.     }  
  567. }  

Quant:

[java]  view plain  copy
  1. package com.test;  
  2.   
  3. import java.io.FileNotFoundException;  
  4. import java.io.FileOutputStream;  
  5.   
  6. /** 
  7.  * <p> 
  8.  * </p> 
  9.  * 
  10.  * @author: wuhongjun 
  11.  * @version:1.0 
  12.  */  
  13. public class Quant  
  14. {  
  15.     protected static final int netsize = 256/* number of colours used */  
  16.   
  17.     /* four primes near 500 - assume no image has a length so large */  
  18.     /* that it is divisible by all four primes */  
  19.     protected static final int prime1 = 499;  
  20.     protected static final int prime2 = 491;  
  21.     protected static final int prime3 = 487;  
  22.     protected static final int prime4 = 503;  
  23.   
  24.     protected static final int minpicturebytes = (3 * prime4);  
  25.     /* minimum size for input image */  
  26.   
  27.     /* 
  28.      * Program Skeleton 
  29.      * ---------------- 
  30.      * [select samplefac in range 1..30] 
  31.      * [read image from input file] 
  32.      * pic = (unsigned char*) malloc(3*width*height); 
  33.      * initnet(pic,3*width*height,samplefac); 
  34.      * learn(); 
  35.      * unbiasnet(); 
  36.      * [write output image header, using writecolourmap(f)] 
  37.      * inxbuild(); 
  38.      * write output image using inxsearch(b,g,r) 
  39.      */  
  40.   
  41.     /* 
  42.      * Network Definitions 
  43.      * ------------------- 
  44.      */  
  45.   
  46.     protected static final int maxnetpos = (netsize - 1);  
  47.     protected static final int netbiasshift = 4/* bias for colour values */  
  48.     protected static final int ncycles = 100/* no. of learning cycles */  
  49.   
  50.     /* defs for freq and bias */  
  51.     protected static final int intbiasshift = 16/* bias for fractions */  
  52.     protected static final int intbias = (((int1) << intbiasshift);  
  53.     protected static final int gammashift = 10/* gamma = 1024 */  
  54.     protected static final int gamma = (((int1) << gammashift);  
  55.     protected static final int betashift = 10;  
  56.     protected static final int beta = (intbias >> betashift); /* beta = 1/1024 */  
  57.     protected static final int betagamma = (intbias << (gammashift - betashift));  
  58.   
  59.     /* defs for decreasing radius factor */  
  60.     protected static final int initrad = (netsize >> 3); /* for 256 cols, radius starts */  
  61.     protected static final int radiusbiasshift = 6/* at 32.0 biased by 6 bits */  
  62.     protected static final int radiusbias = (((int1) << radiusbiasshift);  
  63.     protected static final int initradius = (initrad * radiusbias); /* and decreases by a */  
  64.     protected static final int radiusdec = 30/* factor of 1/30 each cycle */  
  65.   
  66.     /* defs for decreasing alpha factor */  
  67.     protected static final int alphabiasshift = 10/* alpha starts at 1.0 */  
  68.     protected static final int initalpha = (((int1) << alphabiasshift);  
  69.   
  70.     protected int alphadec; /* biased by 10 bits */  
  71.   
  72.     /* radbias and alpharadbias used for radpower calculation */  
  73.     protected static final int radbiasshift = 8;  
  74.     protected static final int radbias = (((int1) << radbiasshift);  
  75.     protected static final int alpharadbshift = (alphabiasshift + radbiasshift);  
  76.     protected static final int alpharadbias = (((int1) << alpharadbshift);  
  77.   
  78.     /* 
  79.      * Types and Global Variables 
  80.      * -------------------------- 
  81.      */  
  82.   
  83.     protected byte[] thepicture; /* the input image itself */  
  84.     protected int lengthcount; /* lengthcount = H*W*3 */  
  85.   
  86.     protected int samplefac; /* sampling factor 1..30 */  
  87.   
  88.     // typedef int pixel[4]; /* BGRc */  
  89.     protected int[][] network; /* the network itself - [netsize][4] */  
  90.   
  91.     protected int[] netindex = new int[256];  
  92.     /* for network lookup - really 256 */  
  93.   
  94.     protected int[] bias = new int[netsize];  
  95.     /* bias and freq arrays for learning */  
  96.     protected int[] freq = new int[netsize];  
  97.     protected int[] radpower = new int[initrad];  
  98.     /* radpower for precomputation */  
  99.   
  100.     /* 
  101.      * Initialise network in range (0,0,0) to (255,255,255) and set parameters 
  102.      * ----------------------------------------------------------------------- 
  103.      */  
  104.     public Quant(byte[] thepic, int len, int sample)  
  105.     {  
  106.   
  107.         int i;  
  108.         int[] p;  
  109.   
  110.         thepicture = thepic;  
  111.         lengthcount = len;  
  112.         samplefac = sample;  
  113.   
  114.         network = new int[netsize][];  
  115.         for (i = 0; i < netsize; i++)  
  116.         {  
  117.             network[i] = new int[4];  
  118.             p = network[i];  
  119.             p[0] = p[1] = p[2] = (i << (netbiasshift + 8)) / netsize;  
  120.             freq[i] = intbias / netsize; /* 1/netsize */  
  121.             bias[i] = 0;  
  122.         }  
  123.     }  
  124.   
  125.     public byte[] colorMap()  
  126.     {  
  127.         byte[] map = new byte[3 * netsize];  
  128.         int[] index = new int[netsize];  
  129.         for (int i = 0; i < netsize; i++)  
  130.             index[network[i][3]] = i;  
  131.         int k = 0;  
  132.         for (int i = 0; i < netsize; i++)  
  133.         {  
  134.             int j = index[i];  
  135.             map[k++] = (byte) (network[j][0]);  
  136.             map[k++] = (byte) (network[j][1]);  
  137.             map[k++] = (byte) (network[j][2]);  
  138.         }  
  139.         return map;  
  140.     }  
  141.   
  142.     /* 
  143.      * Insertion sort of network and building of netindex[0..255] (to do after unbias) 
  144.      * ------------------------------------------------------------------------------- 
  145.      */  
  146.     public void inxbuild()  
  147.     {  
  148.   
  149.         int i, j, smallpos, smallval;  
  150.         int[] p;  
  151.         int[] q;  
  152.         int previouscol, startpos;  
  153.   
  154.         previouscol = 0;  
  155.         startpos = 0;  
  156.         for (i = 0; i < netsize; i++)  
  157.         {  
  158.             p = network[i];  
  159.             smallpos = i;  
  160.             smallval = p[1]; /* index on g */  
  161.             /* find smallest in i..netsize-1 */  
  162.             for (j = i + 1; j < netsize; j++)  
  163.             {  
  164.                 q = network[j];  
  165.                 if (q[1] < smallval)  
  166.                 { /* index on g */  
  167.                     smallpos = j;  
  168.                     smallval = q[1]; /* index on g */  
  169.                 }  
  170.             }  
  171.             q = network[smallpos];  
  172.             /* swap p (i) and q (smallpos) entries */  
  173.             if (i != smallpos)  
  174.             {  
  175.                 j = q[0];  
  176.                 q[0] = p[0];  
  177.                 p[0] = j;  
  178.                 j = q[1];  
  179.                 q[1] = p[1];  
  180.                 p[1] = j;  
  181.                 j = q[2];  
  182.                 q[2] = p[2];  
  183.                 p[2] = j;  
  184.                 j = q[3];  
  185.                 q[3] = p[3];  
  186.                 p[3] = j;  
  187.             }  
  188.             /* smallval entry is now in position i */  
  189.             if (smallval != previouscol)  
  190.             {  
  191.                 netindex[previouscol] = (startpos + i) >> 1;  
  192.                 for (j = previouscol + 1; j < smallval; j++)  
  193.                     netindex[j] = i;  
  194.                 previouscol = smallval;  
  195.                 startpos = i;  
  196.             }  
  197.         }  
  198.         netindex[previouscol] = (startpos + maxnetpos) >> 1;  
  199.         for (j = previouscol + 1; j < 256; j++)  
  200.             netindex[j] = maxnetpos; /* really 256 */  
  201.     }  
  202.   
  203.     /* 
  204.      * Main Learning Loop 
  205.      * ------------------ 
  206.      */  
  207.     public void learn()  
  208.     {  
  209.   
  210.         int i, j, b, g, r;  
  211.         int radius, rad, alpha, step, delta, samplepixels;  
  212.         byte[] p;  
  213.         int pix, lim;  
  214.   
  215.         if (lengthcount < minpicturebytes)  
  216.             samplefac = 1;  
  217.         alphadec = 30 + ((samplefac - 1) / 3);  
  218.         p = thepicture;  
  219.         pix = 0;  
  220.         lim = lengthcount;  
  221.         samplepixels = lengthcount / (3 * samplefac);  
  222.         delta = samplepixels / ncycles;  
  223.         alpha = initalpha;  
  224.         radius = initradius;  
  225.   
  226.         rad = radius >> radiusbiasshift;  
  227.         if (rad <= 1)  
  228.             rad = 0;  
  229.         for (i = 0; i < rad; i++)  
  230.             radpower[i] = alpha * (((rad * rad - i * i) * radbias) / (rad * rad));  
  231.   
  232.         // fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad);  
  233.   
  234.         if (lengthcount < minpicturebytes)  
  235.             step = 3;  
  236.         else if ((lengthcount % prime1) != 0)  
  237.             step = 3 * prime1;  
  238.         else  
  239.         {  
  240.             if ((lengthcount % prime2) != 0)  
  241.                 step = 3 * prime2;  
  242.             else  
  243.             {  
  244.                 if ((lengthcount % prime3) != 0)  
  245.                     step = 3 * prime3;  
  246.                 else  
  247.                     step = 3 * prime4;  
  248.             }  
  249.         }  
  250.   
  251.         i = 0;  
  252.         while (i < samplepixels)  
  253.         {  
  254.             b = (p[pix + 0] & 0xff) << netbiasshift;  
  255.             g = (p[pix + 1] & 0xff) << netbiasshift;  
  256.             r = (p[pix + 2] & 0xff) << netbiasshift;  
  257.             j = contest(b, g, r);  
  258.   
  259.             altersingle(alpha, j, b, g, r);  
  260.             if (rad != 0)  
  261.                 alterneigh(rad, j, b, g, r); /* alter neighbours */  
  262.   
  263.             pix += step;  
  264.             if (pix >= lim)  
  265.                 pix -= lengthcount;  
  266.   
  267.             i++;  
  268.             if (delta == 0)  
  269.                 delta = 1;  
  270.             if (i % delta == 0)  
  271.             {  
  272.                 alpha -= alpha / alphadec;  
  273.                 radius -= radius / radiusdec;  
  274.                 rad = radius >> radiusbiasshift;  
  275.                 if (rad <= 1)  
  276.                     rad = 0;  
  277.                 for (j = 0; j < rad; j++)  
  278.                     radpower[j] = alpha * (((rad * rad - j * j) * radbias) / (rad * rad));  
  279.             }  
  280.         }  
  281.         // fprintf(stderr,"finished 1D learning: final alpha=%f !\n",((float)alpha)/initalpha);  
  282.     }  
  283.   
  284.     /* 
  285.      * Search for BGR values 0..255 (after net is unbiased) and return colour index 
  286.      * ---------------------------------------------------------------------------- 
  287.      */  
  288.     public int map(int b, int g, int r)  
  289.     {  
  290.   
  291.         int i, j, dist, a, bestd;  
  292.         int[] p;  
  293.         int best;  
  294.   
  295.         bestd = 1000/* biggest possible dist is 256*3 */  
  296.         best = -1;  
  297.         i = netindex[g]; /* index on g */  
  298.         j = i - 1/* start at netindex[g] and work outwards */  
  299.   
  300.         while ((i < netsize) || (j >= 0))  
  301.         {  
  302.             if (i < netsize)  
  303.             {  
  304.                 p = network[i];  
  305.                 dist = p[1] - g; /* inx key */  
  306.                 if (dist >= bestd)  
  307.                     i = netsize; /* stop iter */  
  308.                 else  
  309.                 {  
  310.                     i++;  
  311.                     if (dist < 0)  
  312.                         dist = -dist;  
  313.                     a = p[0] - b;  
  314.                     if (a < 0)  
  315.                         a = -a;  
  316.                     dist += a;  
  317.                     if (dist < bestd)  
  318.                     {  
  319.                         a = p[2] - r;  
  320.                         if (a < 0)  
  321.                             a = -a;  
  322.                         dist += a;  
  323.                         if (dist < bestd)  
  324.                         {  
  325.                             bestd = dist;  
  326.                             best = p[3];  
  327.                         }  
  328.                     }  
  329.                 }  
  330.             }  
  331.             if (j >= 0)  
  332.             {  
  333.                 p = network[j];  
  334.                 dist = g - p[1]; /* inx key - reverse dif */  
  335.                 if (dist >= bestd)  
  336.                     j = -1/* stop iter */  
  337.                 else  
  338.                 {  
  339.                     j--;  
  340.                     if (dist < 0)  
  341.                         dist = -dist;  
  342.                     a = p[0] - b;  
  343.                     if (a < 0)  
  344.                         a = -a;  
  345.                     dist += a;  
  346.                     if (dist < bestd)  
  347.                     {  
  348.                         a = p[2] - r;  
  349.                         if (a < 0)  
  350.                             a = -a;  
  351.                         dist += a;  
  352.                         if (dist < bestd)  
  353.                         {  
  354.                             bestd = dist;  
  355.                             best = p[3];  
  356.                         }  
  357.                     }  
  358.                 }  
  359.             }  
  360.         }  
  361.         return (best);  
  362.     }  
  363.   
  364.     public byte[] process()  
  365.     {  
  366.         learn();  
  367.         unbiasnet();  
  368.         inxbuild();  
  369.         return colorMap();  
  370.     }  
  371.   
  372.     /* 
  373.      * Unbias network to give byte values 0..255 and record position i to prepare for sort 
  374.      * ----------------------------------------------------------------------------------- 
  375.      */  
  376.     public void unbiasnet()  
  377.     {  
  378.   
  379.         int i, j;  
  380.   
  381.         for (i = 0; i < netsize; i++)  
  382.         {  
  383.             network[i][0] >>= netbiasshift;  
  384.             network[i][1] >>= netbiasshift;  
  385.             network[i][2] >>= netbiasshift;  
  386.             network[i][3] = i; /* record colour no */  
  387.         }  
  388.     }  
  389.   
  390.     /* 
  391.      * Move adjacent neurons by precomputed alpha*(1-((i-j)^2/[r]^2)) in radpower[|i-j|] 
  392.      * --------------------------------------------------------------------------------- 
  393.      */  
  394.     protected void alterneigh(int rad, int i, int b, int g, int r)  
  395.     {  
  396.   
  397.         int j, k, lo, hi, a, m;  
  398.         int[] p;  
  399.   
  400.         lo = i - rad;  
  401.         if (lo < -1)  
  402.             lo = -1;  
  403.         hi = i + rad;  
  404.         if (hi > netsize)  
  405.             hi = netsize;  
  406.   
  407.         j = i + 1;  
  408.         k = i - 1;  
  409.         m = 1;  
  410.         while ((j < hi) || (k > lo))  
  411.         {  
  412.             a = radpower[m++];  
  413.             if (j < hi)  
  414.             {  
  415.                 p = network[j++];  
  416.                 try  
  417.                 {  
  418.                     p[0] -= (a * (p[0] - b)) / alpharadbias;  
  419.                     p[1] -= (a * (p[1] - g)) / alpharadbias;  
  420.                     p[2] -= (a * (p[2] - r)) / alpharadbias;  
  421.                 }  
  422.                 catch (Exception e)  
  423.                 {  
  424.                 } // prevents 1.3 miscompilation  
  425.             }  
  426.             if (k > lo)  
  427.             {  
  428.                 p = network[k--];  
  429.                 try  
  430.                 {  
  431.                     p[0] -= (a * (p[0] - b)) / alpharadbias;  
  432.                     p[1] -= (a * (p[1] - g)) / alpharadbias;  
  433.                     p[2] -= (a * (p[2] - r)) / alpharadbias;  
  434.                 }  
  435.                 catch (Exception e)  
  436.                 {  
  437.                 }  
  438.             }  
  439.         }  
  440.     }  
  441.   
  442.     /* 
  443.      * Move neuron i towards biased (b,g,r) by factor alpha 
  444.      * ---------------------------------------------------- 
  445.      */  
  446.     protected void altersingle(int alpha, int i, int b, int g, int r)  
  447.     {  
  448.   
  449.         /* alter hit neuron */  
  450.         int[] n = network[i];  
  451.         n[0] -= (alpha * (n[0] - b)) / initalpha;  
  452.         n[1] -= (alpha * (n[1] - g)) / initalpha;  
  453.         n[2] -= (alpha * (n[2] - r)) / initalpha;  
  454.     }  
  455.   
  456.     /* 
  457.      * Search for biased BGR values 
  458.      * ---------------------------- 
  459.      */  
  460.     protected int contest(int b, int g, int r)  
  461.     {  
  462.   
  463.         /* finds closest neuron (min dist) and updates freq */  
  464.         /* finds best neuron (min dist-bias) and returns position */  
  465.         /* for frequently chosen neurons, freq[i] is high and bias[i] is negative */  
  466.         /* bias[i] = gamma*((1/netsize)-freq[i]) */  
  467.   
  468.         int i, dist, a, biasdist, betafreq;  
  469.         int bestpos, bestbiaspos, bestd, bestbiasd;  
  470.         int[] n;  
  471.   
  472.         bestd = ~(((int1) << 31);  
  473.         bestbiasd = bestd;  
  474.         bestpos = -1;  
  475.         bestbiaspos = bestpos;  
  476.   
  477.         for (i = 0; i < netsize; i++)  
  478.         {  
  479.             n = network[i];  
  480.             dist = n[0] - b;  
  481.             if (dist < 0)  
  482.                 dist = -dist;  
  483.             a = n[1] - g;  
  484.             if (a < 0)  
  485.                 a = -a;  
  486.             dist += a;  
  487.             a = n[2] - r;  
  488.             if (a < 0)  
  489.                 a = -a;  
  490.             dist += a;  
  491.             if (dist < bestd)  
  492.             {  
  493.                 bestd = dist;  
  494.                 bestpos = i;  
  495.             }  
  496.             biasdist = dist - ((bias[i]) >> (intbiasshift - netbiasshift));  
  497.             if (biasdist < bestbiasd)  
  498.             {  
  499.                 bestbiasd = biasdist;  
  500.                 bestbiaspos = i;  
  501.             }  
  502.             betafreq = (freq[i] >> betashift);  
  503.             freq[i] -= betafreq;  
  504.             bias[i] += (betafreq << gammashift);  
  505.         }  
  506.         freq[bestpos] += beta;  
  507.         bias[bestpos] -= betagamma;  
  508.         return (bestbiaspos);  
  509.     }  
  510. }  

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值