2007-04-16 06:48:20 -04:00
|
|
|
/* ====================================================================
|
|
|
|
Copyright 2002-2004 Apache Software Foundation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
|
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
|
|
|
import org.apache.poi.ddf.EscherBitmapBlip;
|
2007-08-26 11:26:29 -04:00
|
|
|
import org.apache.poi.ddf.EscherBlipRecord;
|
2008-05-05 10:20:39 -04:00
|
|
|
import org.apache.poi.ddf.EscherMetafileBlip;
|
2007-04-16 06:48:20 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents binary data stored in the file. Eg. A GIF, JPEG etc...
|
|
|
|
*
|
|
|
|
* @author Daniel Noll
|
|
|
|
*/
|
|
|
|
public class HSSFPictureData
|
|
|
|
{
|
|
|
|
// MSOBI constants for various formats.
|
|
|
|
public static final short MSOBI_WMF = 0x2160;
|
|
|
|
public static final short MSOBI_EMF = 0x3D40;
|
|
|
|
public static final short MSOBI_PICT = 0x5420;
|
|
|
|
public static final short MSOBI_PNG = 0x6E00;
|
|
|
|
public static final short MSOBI_JPEG = 0x46A0;
|
|
|
|
public static final short MSOBI_DIB = 0x7A80;
|
|
|
|
// Mask of the bits in the options used to store the image format.
|
|
|
|
public static final short FORMAT_MASK = (short) 0xFFF0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Underlying escher blip record containing the bitmap data.
|
|
|
|
*/
|
2007-08-26 11:26:29 -04:00
|
|
|
private EscherBlipRecord blip;
|
2007-04-16 06:48:20 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a picture object.
|
|
|
|
*
|
|
|
|
* @param blip the underlying blip record containing the bitmap data.
|
|
|
|
*/
|
2007-08-26 11:26:29 -04:00
|
|
|
HSSFPictureData( EscherBlipRecord blip )
|
2007-04-16 06:48:20 -04:00
|
|
|
{
|
|
|
|
this.blip = blip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the picture data.
|
|
|
|
*
|
|
|
|
* @return the picture data.
|
|
|
|
*/
|
|
|
|
public byte[] getData()
|
|
|
|
{
|
|
|
|
return blip.getPicturedata();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suggests a file extension for this image.
|
|
|
|
*
|
|
|
|
* @return the file extension.
|
|
|
|
*/
|
|
|
|
public String suggestFileExtension()
|
|
|
|
{
|
2008-05-05 10:20:39 -04:00
|
|
|
switch (blip.getRecordId())
|
2007-04-16 06:48:20 -04:00
|
|
|
{
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherMetafileBlip.RECORD_ID_WMF:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "wmf";
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherMetafileBlip.RECORD_ID_EMF:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "emf";
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherMetafileBlip.RECORD_ID_PICT:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "pict";
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherBitmapBlip.RECORD_ID_PNG:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "png";
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherBitmapBlip.RECORD_ID_JPEG:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "jpeg";
|
2008-05-05 10:20:39 -04:00
|
|
|
case EscherBitmapBlip.RECORD_ID_DIB:
|
2007-04-16 06:48:20 -04:00
|
|
|
return "dib";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|