src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 557         // Buffer for up to 8 rows of pixels
 558         int[] pixels = new int[scanlineBytes * scaleX];
 559 
 560         // Also create a buffer to hold one line of the data
 561         // to be written to the file, so we can use array writes.
 562         bpixels = new byte[destScanlineBytes];
 563 
 564         int l;
 565 
 566         if (compressionType == BI_JPEG ||
 567             compressionType == BI_PNG) {
 568 
 569             // prepare embedded buffer
 570             embedded_stream = new ByteArrayOutputStream();
 571             writeEmbedded(image, bmpParam);
 572             // update the file/image Size
 573             embedded_stream.flush();
 574             imageSize = embedded_stream.size();
 575 
 576             long endPos = stream.getStreamPosition();
 577             fileSize = (int)(offset + imageSize);
 578             stream.seek(headPos);
 579             writeSize(fileSize, 2);
 580             stream.seek(headPos);
 581             writeSize(imageSize, 34);
 582             stream.seek(endPos);
 583             stream.write(embedded_stream.toByteArray());
 584             embedded_stream = null;
 585 
 586             if (abortRequested()) {
 587                 processWriteAborted();
 588             } else {
 589                 processImageComplete();
 590                 stream.flushBefore(stream.getStreamPosition());
 591             }
 592 
 593             return;
 594         }
 595 
 596         int maxBandOffset = bandOffsets[0];
 597         for (int i = 1; i < bandOffsets.length; i++)


   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 557         // Buffer for up to 8 rows of pixels
 558         int[] pixels = new int[scanlineBytes * scaleX];
 559 
 560         // Also create a buffer to hold one line of the data
 561         // to be written to the file, so we can use array writes.
 562         bpixels = new byte[destScanlineBytes];
 563 
 564         int l;
 565 
 566         if (compressionType == BI_JPEG ||
 567             compressionType == BI_PNG) {
 568 
 569             // prepare embedded buffer
 570             embedded_stream = new ByteArrayOutputStream();
 571             writeEmbedded(image, bmpParam);
 572             // update the file/image Size
 573             embedded_stream.flush();
 574             imageSize = embedded_stream.size();
 575 
 576             long endPos = stream.getStreamPosition();
 577             fileSize = offset + imageSize;
 578             stream.seek(headPos);
 579             writeSize(fileSize, 2);
 580             stream.seek(headPos);
 581             writeSize(imageSize, 34);
 582             stream.seek(endPos);
 583             stream.write(embedded_stream.toByteArray());
 584             embedded_stream = null;
 585 
 586             if (abortRequested()) {
 587                 processWriteAborted();
 588             } else {
 589                 processImageComplete();
 590                 stream.flushBefore(stream.getStreamPosition());
 591             }
 592 
 593             return;
 594         }
 595 
 596         int maxBandOffset = bandOffsets[0];
 597         for (int i = 1; i < bandOffsets.length; i++)