Examples of JPEGOutputStream


Examples of uk.co.mmscomputing.imageio.jpeg.JPEGOutputStream

      }
      ifd.add(new DEFactory.ResolutionUnitDE(Inch));                     // 296

      ByteArrayOutputStream  baos   =new ByteArrayOutputStream();
      OutputStream           os     =baos;
      JPEGOutputStream       jpegos =null;

      if(comp==JPEG){                                                    // add JPEGTables tag
        jpegos=new JPEGOutputStream(baos);

        int quality=(param==null)?50:(int)(param.getCompressionQuality()*100);

        jpegos.setZZQuantizationTable(0,JPEGConstants.LQT,quality);
        jpegos.setRawDCHuffmanTable(0,JPEGConstants.HLDCTable);
        jpegos.setRawACHuffmanTable(0,JPEGConstants.HLACTable);

        jpegos.defineQuantizationTables();
        jpegos.defineHuffmanTables();
        jpegos.close();

        DEFactory.JPEGTablesDE jpegtables=new DEFactory.JPEGTablesDE(baos.toByteArray());
        ifd.add(jpegtables);                                             // 347

        baos.reset();

        os=jpegos;
      }

      WritableRaster   raster=image.getRaster();
      DataBufferByte   buffer=(DataBufferByte)raster.getDataBuffer();
      byte[]           imgdata=(byte[])buffer.getData();

      int index=0;
      for(int y=0;y<height;y+=maxrps){
        /*
        Assume rgb image.

        Each strip: evaluate gray scale colour
                    save in byte array
                    write to image file
        */
        if((height-y)<maxrps){maxrps=height-y;}

        if(jpegos!=null){                                                // jpeg: SOI,SOF,SOS marker
          jpegos.startOfImage();
          int[] hv={0x11};                                               // (Hi<<4)|Vi
          int[] q={0};                                                   // quantization table 0
          jpegos.startOfFrame(maxrps,width,hv,q);
          int[] sel={0};                                                 // DC,AC code table 0
          jpegos.startOfScan(sel);
        }

        os.write(imgdata,y*width,maxrps*width);
        os.close();                                                      // jpeg EOF: end of frame

View Full Code Here

Examples of uk.co.mmscomputing.imageio.jpeg.JPEGOutputStream

      }
      ifd.add(new DEFactory.ResolutionUnitDE(Inch));                     // 296

      ByteArrayOutputStream  baos   =new ByteArrayOutputStream();
      OutputStream           os     =baos;
      JPEGOutputStream       jpegos =null;

      if(comp==JPEG){                                                    // add JPEGTables tag
        jpegos=new JPEGOutputStream(baos);

        int quality=(param==null)?50:(int)(param.getCompressionQuality()*100);

        jpegos.setZZQuantizationTable(0,JPEGConstants.LQT,quality);
        jpegos.setRawDCHuffmanTable(0,JPEGConstants.HLDCTable);
        jpegos.setRawACHuffmanTable(0,JPEGConstants.HLACTable);

        jpegos.defineQuantizationTables();
        jpegos.defineHuffmanTables();
        jpegos.close();

        DEFactory.JPEGTablesDE jpegtables=new DEFactory.JPEGTablesDE(baos.toByteArray());
        ifd.add(jpegtables);                                             // 347

        baos.reset();

        os=jpegos;
      }

      WritableRaster   raster=image.getRaster();
      DataBufferInt    buffer=(DataBufferInt)raster.getDataBuffer();
      int[]            imgdata=(int[])buffer.getData();

      int index=0;
      for(int y=0;y<height;y+=maxrps){
        /*
        Assume rgb image.

        Each strip: evaluate r g b colour
                    save in byte array
                    write to image file
        */
        if((height-y)<maxrps){maxrps=height-y;}

        if(jpegos!=null){                                                // jpeg: SOI,SOF,SOS marker
          jpegos.startOfImage();
          int[] hv={0x11,0x11,0x11};                                     // (Hi<<4)|Vi
          int[] q={0,0,0};                                               // quantization table 0
          jpegos.startOfFrame(maxrps,width,hv,q);
          int[] sel={0,0,0};                                             // DC,AC code table 0
          jpegos.startOfScan(sel);
        }

        for(int i=0;i<maxrps;i++){                                       // write RGB data
          for(int x=0;x<width;x++){
            int c = imgdata[x+(y+i)*width];
 
View Full Code Here

Examples of uk.co.mmscomputing.imageio.jpeg.JPEGOutputStream

      ifd.add(new DEFactory.ResolutionUnitDE(Inch));                     // 296


      ByteArrayOutputStream  baos   =new ByteArrayOutputStream();
      OutputStream           os     =baos;
      JPEGOutputStream       jpegos =null;

      if(comp==JPEG){
        jpegos=new JPEGOutputStream(baos);

        int quality=(param==null)?50:(int)(param.getCompressionQuality()*100);

        jpegos.setZZQuantizationTable(0,JPEGConstants.LQT,quality);
        jpegos.setZZQuantizationTable(1,JPEGConstants.CQT,quality);

        jpegos.setRawDCHuffmanTable(0,JPEGConstants.HLDCTable);
        jpegos.setRawACHuffmanTable(0,JPEGConstants.HLACTable);
        jpegos.setRawDCHuffmanTable(1,JPEGConstants.HCDCTable);
        jpegos.setRawACHuffmanTable(1,JPEGConstants.HCACTable);

        jpegos.defineQuantizationTables();
        jpegos.defineHuffmanTables();
        jpegos.close();

        DEFactory.JPEGTablesDE jpegtables=new DEFactory.JPEGTablesDE(baos.toByteArray());
        ifd.add(jpegtables);                                             // 347

        baos.reset();

        os=jpegos;

      }

//      CCIR Recommendation 601-1  LumaRed=299/1000 LumaGreen=587/1000 LumeBlue=114/1000
//      Y  = ( LumaRed * R + LumaGreen * G + LumaBlue * B )
//      Cb = ( B - Y ) / ( 2 - 2 * LumaBlue )
//      Cr = ( R - Y ) / ( 2 - 2 * LumaRed )

      double LumaRed   = 299.0/1000.0;
      double LumaGreen = 587.0/1000.0;
      double LumaBlue  = 114.0/1000.0;

      DEFactory.YCbCrCoefficientsDE YCbCrCoeff = new DEFactory.YCbCrCoefficientsDE();
      YCbCrCoeff.setLumaRed  (LumaRed);                                  // Y
      YCbCrCoeff.setLumaGreen(LumaGreen);                                // Cb
      YCbCrCoeff.setLumaBlue (LumaBlue);                                 // Cr
      ifd.add(YCbCrCoeff);                                               // 529

      DEFactory.YCbCrSubSamplingDE YCbCrSubSampling = new DEFactory.YCbCrSubSamplingDE();
      YCbCrSubSampling.setHoriz(ssh);
      YCbCrSubSampling.setVert(ssv);
      ifd.add(YCbCrSubSampling);                                         // 530

      double RfBY  =0;            double RfWY  =255;
      double RfBCb =128;          double RfWCb =255;   
      double RfBCr =128;          double RfWCr =255;

      DEFactory.ReferenceBlackWhiteDE ReferenceBlackWhite = new DEFactory.ReferenceBlackWhiteDE();
      ReferenceBlackWhite.setY(RfBY,RfWY);
      ReferenceBlackWhite.setCb(RfBCb,RfWCb);
      ReferenceBlackWhite.setCr(RfBCr,RfWCr);
      ifd.add(ReferenceBlackWhite);                                      // 532

      TIFFYCbCrOutputStream    ycbcros;
      if(jpegos==null){
        ycbcros=new TIFFYCbCrOutputStream(os,width,ssv,ssh);
        os=new TIFFSubSamplingOutputStream(ycbcros,width,ssv,ssh);
      }else{
        ycbcros=new TIFFYCbCrOutputStream(os,width,1,1);                 // jpeg does own subsampling
        os=ycbcros;
      }

      ycbcros.setPositioning(1);
      ycbcros.setColourCoefficients(LumaRed,LumaGreen,LumaBlue);
      ycbcros.setRfBWY (RfBY,RfWY);
      ycbcros.setRfBWCb(RfBCb,RfWCb);
      ycbcros.setRfBWCr(RfBCr,RfWCr);

      WritableRaster   raster=image.getRaster();
      DataBufferInt    buffer=(DataBufferInt)raster.getDataBuffer();
      int[]           imgdata=(int[])buffer.getData();

      int c=0,index=0;
      for(int y=0;y<height;y+=maxrps){

        if((height-y)<maxrps){maxrps=height-y;}

        if(jpegos!=null){
          jpegos.startOfImage();
          int[] hv={(ssh<<4)|ssv,0x11,0x11};                             // (Hi<<4)|Vi
          int[] q={0,1,1};                                               // quantization table Y=0, Cb=Cr=1
//          jpegos.startOfFrame(((maxrps+ssv-1)/ssv)*ssv,ww,hv,q);
          jpegos.startOfFrame(maxrps,ww,hv,q);
          int[] sel={0,1,1};                                             // DC,AC code table Y=0, Cb=Cr=1
          jpegos.startOfScan(sel);
        }

        for(int i=0;i<maxrps;i++){
          int x=0;
          while(x<width){
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.