App
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mhr.appcore.bitmap.NBitmap Class Reference

Rozhraní pro práci s nativní třídou TBitmap<> More...

Public Member Functions

BitmapInfo getInfo () throws AlreadyDisposedException
 Vrací informace o bitmapě, pokud tato již není platná, hází výjimku.
 
Rect getRect () throws AlreadyDisposedException
 Pokud je bitmapa platná, vrací obdélník odpovídající její velikosti, jinak hází výjimku.
 
int getWidth () throws AlreadyDisposedException
 Pokud je bitmapa platná, vrací její šířku, jinak hází výjimku.
 
int getHeight () throws AlreadyDisposedException
 Pokud je bitmapa platná, vrací její výšku, jinak hází výjimku.
 
long getAdress ()
 vrací adresu nativní bitmapy, pokud je tato neplatná, vrací 0x00.
 
NativeType getNativeType ()
 Vrací nativní typ bitmapy.
 
void setPremultiplied (boolean premultiplied) throws AlreadyDisposedException
 Pokud je bitmapa platná, nastaví informaci o přednásobení jejich kanálů, pokud ne, hodí výjimku. Nastavení neovlivní reálně stav pixelů.
 
 NBitmap (BitmapInfo info) throws UnsupportedBitmapException, BitmapAllocationException
 Výchozí konstruktor, vytvoří nezávislou instanci dle požadovaných parametrů.
 
 NBitmap (PDBitmap wrap) throws UnsupportedBitmapException, BitmapAllocationException
 Vytvoří bitmapu jako wrapper pro PDBitmap.
 
 NBitmap (NBitmap other) throws BitmapAllocationException, AlreadyDisposedException
 Kopírovací konstruktor, volá odpovídající nativní kopírovací konstruktor.
 
 NBitmap (long adress, BitmapInfo info) throws NullPointerException, UnsupportedBitmapException
 Konstruktor, který vytvoří NBitmapu na základě informací. Použití v případě, že jiné třídy sami alokují bitmapu na heapu.
 
synchronized void dispose ()
 Uvolní prostředky zabrané touto bitmapou.
 
int cropTo (Rect r) throws AlreadyDisposedException
 
int premultiply () throws AlreadyDisposedException
 Pokud je aplikovatelné, provede přednásobení kanálů hodnotou alphy.
 
int demultiply () throws AlreadyDisposedException
 Pokud je aplikovatelné, odstraní přednásobení kanálů hodnotou alphy.
 
NBitmap getChannel (int index) throws BitmapAllocationException, IllegalArgumentException, AlreadyDisposedException
 Extrahuje kanál s daným indexem. Aplikovatelné pouze na čtyřkanálovou bitmapu.
 
int copyTo (NBitmap dst, Rect srcRect, int srcOrigX, int srcOrigY) throws AlreadyDisposedException, IllegalArgumentException
 Zkopíruje vybranou oblast bitmapy do cílové. Význam parametrů viz. TBitmap<>.
 
int fill (Rect srcRect, int color) throws AlreadyDisposedException
 Vyplní danou oblast určenou barvou. Význam parametrů viz. TBitmap<>.
 

Protected Member Functions

native long createTBitmap (int nativeType, int width, int height, int colorMode, boolean premultiplied)
 JNI pomocná metoda.
 
native long createTBitmap (int nativeType, long adress)
 JNI pomocná metoda.
 
native long wrapAsTBitmap (int nativeType, long adress, int width, int height, int colorMode, boolean premultiplied)
 JNI pomocná metoda.
 
native int premultiply (int nativeType, long adress)
 JNI pomocná metoda.
 
native int demultiply (int nativeType, long adress)
 JNI pomocná metoda.
 
native long getChannel (int nativeType, long adress, int index)
 JNI pomocná metoda.
 
native int fill (int nativeType, long adress, int tlx, int tly, int brx, int bry, int color)
 JNI pomocná metoda.
 
native int copyTo (int nativeType, long adress, long dstAdress, int tlx, int tly, int brx, int bry, int srcOrigX, int srcOrigY)
 JNI pomocná metoda.
 
native int dispose (int nativeType, long adress)
 JNI pomocná metoda.
 
native int setPremultiplied (int nativeType, long adresss, boolean premultiplied)
 JNI pomocná metoda.
 
 NBitmap ()
 Konstruktor pro factory metody.
 
void finalize () throws Throwable
 Zajistí dealokaci nativní paměti, kdyby náhodou mělo dojít k memory-leaku. Není ale garantováno kdy bude metoda zavolána!
 

Protected Attributes

BitmapInfo info = null
 Informace o bitmapě, null pokud je bitmapa neplatná.
 
NativeType nativeType = NativeType.INVALID_TYPE
 Nativní typ, který odpovídá bitmapě.
 
long adress = 0
 Adresa nativní bitmapy TBitmap<> v nativní paměti.
 
PDBitmap wrapped = null
 PDBitmap, se kterou NBitmap sdíli obrazová data, pokud je wrapper.
 

Detailed Description

Rozhraní pro práci s nativní třídou TBitmap<>

Definition at line 13 of file NBitmap.java.

Constructor & Destructor Documentation

mhr.appcore.bitmap.NBitmap.NBitmap ( )
inlineprotected

Konstruktor pro factory metody.

Definition at line 46 of file NBitmap.java.

{
}
mhr.appcore.bitmap.NBitmap.NBitmap ( BitmapInfo  info) throws UnsupportedBitmapException, BitmapAllocationException
inline

Výchozí konstruktor, vytvoří nezávislou instanci dle požadovaných parametrů.

Parameters
infoPožadované parametry bitmapy.
Exceptions
UnsupportedBitmapException
BitmapAllocationException

Definition at line 134 of file NBitmap.java.

{
if (nativeType == NativeType.INVALID_TYPE) {
throw new UnsupportedBitmapException("Specified parameters doesn't map to supported native type.");
}
if (adress == 0) {
throw new BitmapAllocationException("Failed to allocate requested bitmap.");
}
this.info = new BitmapInfo(info); // Chceme vlastní kopii, pro všechny případy
}
mhr.appcore.bitmap.NBitmap.NBitmap ( PDBitmap  wrap) throws UnsupportedBitmapException, BitmapAllocationException
inline

Vytvoří bitmapu jako wrapper pro PDBitmap.

Vytvoří bitmapu jako wrapper pro PDBitmap. Obě bitmapy sdílí společně obrazová data.

Parameters
wrap
Exceptions
UnsupportedBitmapException
BitmapAllocationException

Definition at line 154 of file NBitmap.java.

{
BitmapInfo info = wrap.getInfo();
NativeType tmpType = info.getNativeType();
if (tmpType == NativeType.INVALID_TYPE) {
throw new UnsupportedBitmapException("Supplied bitmap doesn't map to native type");
}
long wrapAdress = wrap.getAndLockData();
if (wrapAdress == 0) {
wrap.unlockData();
throw new BitmapAllocationException("Failed to get data adress from PDBitmap.");
}
adress = wrapAsTBitmap(tmpType.getValue(), wrapAdress, info.width, info.height, info.colorMode.getValue(), info.premultiplied);
if (adress == 0) {
wrap.unlockData();
throw new BitmapAllocationException("Failed to allocate requested bitmap.");
}
this.nativeType = tmpType;
this.wrapped = wrap;
this.info = new BitmapInfo(info);
}
mhr.appcore.bitmap.NBitmap.NBitmap ( NBitmap  other) throws BitmapAllocationException, AlreadyDisposedException
inline

Kopírovací konstruktor, volá odpovídající nativní kopírovací konstruktor.

Parameters
other
Exceptions
BitmapAllocationException
AlreadyDisposedException

Definition at line 181 of file NBitmap.java.

{
if (other.adress != 0) { // Platná bitmapa, protože šla alokovat a není disposed
adress = createTBitmap(other.nativeType.getValue(), other.adress);
if (adress == 0) {
throw new BitmapAllocationException("Failed to get data adress from PDBitmap.");
} else {
this.info = new BitmapInfo(other.info);
this.nativeType = other.nativeType;
}
} else {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
}
mhr.appcore.bitmap.NBitmap.NBitmap ( long  adress,
BitmapInfo  info 
) throws NullPointerException, UnsupportedBitmapException
inline

Konstruktor, který vytvoří NBitmapu na základě informací. Použití v případě, že jiné třídy sami alokují bitmapu na heapu.

Parameters
adressNativní adresa bitmapy.
infoInformace o bitmapě.
Exceptions
NullPointerException
UnsupportedBitmapException

Definition at line 202 of file NBitmap.java.

{
if (adress == 0) {
throw new NullPointerException("Native adress could not be NULL");
}
if (nativeType == NativeType.INVALID_TYPE) {
throw new UnsupportedBitmapException("Supplied bitmap doesn't map to native type");
}
this.adress = adress;
this.info = new BitmapInfo(info);
}

Member Function Documentation

native int mhr.appcore.bitmap.NBitmap.copyTo ( int  nativeType,
long  adress,
long  dstAdress,
int  tlx,
int  tly,
int  brx,
int  bry,
int  srcOrigX,
int  srcOrigY 
)
protected

JNI pomocná metoda.

int mhr.appcore.bitmap.NBitmap.copyTo ( NBitmap  dst,
Rect  srcRect,
int  srcOrigX,
int  srcOrigY 
) throws AlreadyDisposedException, IllegalArgumentException
inline

Zkopíruje vybranou oblast bitmapy do cílové. Význam parametrů viz. TBitmap<>.

Parameters
dst
srcRect
srcOrigX
srcOrigY
Returns
0 v případě úspěchu, jinak kód chyby, který vrátilo volání nativní funkce.
Exceptions
AlreadyDisposedException
IllegalArgumentException

Definition at line 336 of file NBitmap.java.

{
if (this.adress == 0 || dst.adress == 0) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
if (this.nativeType != dst.nativeType) {
throw new IllegalArgumentException("Incompatible bitmaps.");
}
return copyTo(nativeType.getValue(), adress, dst.adress, srcRect.tlx, srcRect.tly, srcRect.brx, srcRect.bry, srcOrigX, srcOrigY);
}
native long mhr.appcore.bitmap.NBitmap.createTBitmap ( int  nativeType,
int  width,
int  height,
int  colorMode,
boolean  premultiplied 
)
protected

JNI pomocná metoda.

native long mhr.appcore.bitmap.NBitmap.createTBitmap ( int  nativeType,
long  adress 
)
protected

JNI pomocná metoda.

int mhr.appcore.bitmap.NBitmap.cropTo ( Rect  r) throws AlreadyDisposedException
inline

Definition at line 242 of file NBitmap.java.

{
Rect crop = r.cropBy(getRect()); // aby nepřesahoval, hodí výjimku alreadyDisposed
if (wrapped != null) {
throw new IllegalStateException("Cannot crop wrapped bitmap");
}
long newAdress = createTBitmap(nativeType.getValue(), crop.getWidth(), crop.getHeight(), info.colorMode.getValue(), info.premultiplied);
if (newAdress == 0) {
throw new BitmapAllocationException("Failed to allocate requested bitmap.");
}
int retVal = copyTo(nativeType.getValue(), adress, newAdress, crop.tlx, crop.tly, crop.brx, crop.bry, 0, 0);
adress = newAdress;
info.width = crop.getWidth();
info.height = crop.getHeight();
return retVal;
}
native int mhr.appcore.bitmap.NBitmap.demultiply ( int  nativeType,
long  adress 
)
protected

JNI pomocná metoda.

int mhr.appcore.bitmap.NBitmap.demultiply ( ) throws AlreadyDisposedException
inline

Pokud je aplikovatelné, odstraní přednásobení kanálů hodnotou alphy.

Returns
Vrací 0 v případě úspěchu, jinak kód chyby.
Exceptions
AlreadyDisposedException

Definition at line 281 of file NBitmap.java.

{
if (this.adress != 0) {
int retVal = demultiply(nativeType.getValue(), adress);
if (retVal == 0) {
this.info.premultiplied = false;
}
return retVal;
} else {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
}
native int mhr.appcore.bitmap.NBitmap.dispose ( int  nativeType,
long  adress 
)
protected

JNI pomocná metoda.

synchronized void mhr.appcore.bitmap.NBitmap.dispose ( )
inline

Uvolní prostředky zabrané touto bitmapou.

Uvolní prostředky zabrané touto bitmapou. Opakované volání nemá žádné následky. Je automaticky voláno při finalize(), ale mělo by být VŽDY voláno manuálně vzhledem k paměťovým nárokům objektu.

Definition at line 221 of file NBitmap.java.

{
if (wrapped != null) {
wrapped = null;
}
if (adress != 0) {
dispose(nativeType.getValue(), adress); // Neni problem s double free, C++ ví o tom, že je jen wrapper
adress = 0;
info = null;
}
nativeType = NativeType.INVALID_TYPE;
}
native int mhr.appcore.bitmap.NBitmap.fill ( int  nativeType,
long  adress,
int  tlx,
int  tly,
int  brx,
int  bry,
int  color 
)
protected

JNI pomocná metoda.

int mhr.appcore.bitmap.NBitmap.fill ( Rect  srcRect,
int  color 
) throws AlreadyDisposedException
inline

Vyplní danou oblast určenou barvou. Význam parametrů viz. TBitmap<>.

Parameters
srcRect
colorBarva, je ve tvaru, který odpovídá převodu int z Javy do C++, tedy 0xAABBGGRR
Returns
Exceptions
AlreadyDisposedException

Definition at line 353 of file NBitmap.java.

{
if (this.adress != 0) {
return fill(nativeType.getValue(), adress, srcRect.tlx, srcRect.tly, srcRect.brx, srcRect.bry, color);
} else {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
}
void mhr.appcore.bitmap.NBitmap.finalize ( ) throws Throwable
inlineprotected

Zajistí dealokaci nativní paměti, kdyby náhodou mělo dojít k memory-leaku. Není ale garantováno kdy bude metoda zavolána!

Definition at line 236 of file NBitmap.java.

{
super.finalize();
}
long mhr.appcore.bitmap.NBitmap.getAdress ( )
inline

vrací adresu nativní bitmapy, pokud je tato neplatná, vrací 0x00.

Returns

Definition at line 102 of file NBitmap.java.

{
return adress;
}
native long mhr.appcore.bitmap.NBitmap.getChannel ( int  nativeType,
long  adress,
int  index 
)
protected

JNI pomocná metoda.

NBitmap mhr.appcore.bitmap.NBitmap.getChannel ( int  index) throws BitmapAllocationException, IllegalArgumentException, AlreadyDisposedException
inline

Extrahuje kanál s daným indexem. Aplikovatelné pouze na čtyřkanálovou bitmapu.

Parameters
indexIndex kanálu (0 - 3)
Returns
Jednokanálovou bitmapu s daným kanálem.
Exceptions
BitmapAllocationException
IllegalArgumentException
AlreadyDisposedException

Definition at line 301 of file NBitmap.java.

{
NBitmap retVal = null;
if (this.adress != 0) {
if (info.channelCount == ChannelCount.FOUR_CHANNEL) {
long tmpAdress = getChannel(nativeType.getValue(), adress, index);
if (tmpAdress != 0) {
retVal = new NBitmap();
retVal.info = new BitmapInfo(info);
retVal.info.channelCount = ChannelCount.SINGLE_CHANNEL;
retVal.info.colorMode = ColorMode.MONO;
retVal.nativeType = NativeType.MONO_8_BIT;
retVal.adress = tmpAdress;
retVal.wrapped = null;
} else {
throw new BitmapAllocationException("Could nod allocate bitmap.");
}
} else {
throw new IllegalArgumentException("Operation not applicable to single channel bitmap, make copy instead.");
}
} else {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
return retVal;
}
int mhr.appcore.bitmap.NBitmap.getHeight ( ) throws AlreadyDisposedException
inline

Pokud je bitmapa platná, vrací její výšku, jinak hází výjimku.

Returns
Exceptions
AlreadyDisposedException

Definition at line 91 of file NBitmap.java.

{
if (info == null) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
return info.height;
}
BitmapInfo mhr.appcore.bitmap.NBitmap.getInfo ( ) throws AlreadyDisposedException
inline

Vrací informace o bitmapě, pokud tato již není platná, hází výjimku.

Returns
Exceptions
AlreadyDisposedException

Definition at line 55 of file NBitmap.java.

{
if (info == null) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
return new BitmapInfo(info);
}
NativeType mhr.appcore.bitmap.NBitmap.getNativeType ( )
inline

Vrací nativní typ bitmapy.

Returns

Definition at line 110 of file NBitmap.java.

{
return nativeType;
}
Rect mhr.appcore.bitmap.NBitmap.getRect ( ) throws AlreadyDisposedException
inline

Pokud je bitmapa platná, vrací obdélník odpovídající její velikosti, jinak hází výjimku.

Returns
Exceptions
AlreadyDisposedException

Definition at line 67 of file NBitmap.java.

{
if (info == null) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
return info.getRect();
}
int mhr.appcore.bitmap.NBitmap.getWidth ( ) throws AlreadyDisposedException
inline

Pokud je bitmapa platná, vrací její šířku, jinak hází výjimku.

Returns
Exceptions
AlreadyDisposedException

Definition at line 79 of file NBitmap.java.

{
if (info == null) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
return info.width;
}
native int mhr.appcore.bitmap.NBitmap.premultiply ( int  nativeType,
long  adress 
)
protected

JNI pomocná metoda.

int mhr.appcore.bitmap.NBitmap.premultiply ( ) throws AlreadyDisposedException
inline

Pokud je aplikovatelné, provede přednásobení kanálů hodnotou alphy.

Returns
Vrací 0 v případě úspěchu, jinak kód chyby.
Exceptions
AlreadyDisposedException

Definition at line 264 of file NBitmap.java.

{
if (this.adress != 0) {
if (retVal == 0) {
this.info.premultiplied = true;
}
return retVal;
} else {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
}
native int mhr.appcore.bitmap.NBitmap.setPremultiplied ( int  nativeType,
long  adresss,
boolean  premultiplied 
)
protected

JNI pomocná metoda.

void mhr.appcore.bitmap.NBitmap.setPremultiplied ( boolean  premultiplied) throws AlreadyDisposedException
inline

Pokud je bitmapa platná, nastaví informaci o přednásobení jejich kanálů, pokud ne, hodí výjimku. Nastavení neovlivní reálně stav pixelů.

Parameters
premultiplied

Definition at line 118 of file NBitmap.java.

{
if (info == null || adress == 0) {
throw new AlreadyDisposedException("Bitmap is already disposed.");
}
if (setPremultiplied(nativeType.getValue(), adress, premultiplied) != 0) {
throw new RuntimeException("Something went wrong.");
}
info.premultiplied = premultiplied;
}
native long mhr.appcore.bitmap.NBitmap.wrapAsTBitmap ( int  nativeType,
long  adress,
int  width,
int  height,
int  colorMode,
boolean  premultiplied 
)
protected

JNI pomocná metoda.

Member Data Documentation

long mhr.appcore.bitmap.NBitmap.adress = 0
protected

Adresa nativní bitmapy TBitmap<> v nativní paměti.

Definition at line 40 of file NBitmap.java.

BitmapInfo mhr.appcore.bitmap.NBitmap.info = null
protected

Informace o bitmapě, null pokud je bitmapa neplatná.

Definition at line 38 of file NBitmap.java.

NativeType mhr.appcore.bitmap.NBitmap.nativeType = NativeType.INVALID_TYPE
protected

Nativní typ, který odpovídá bitmapě.

Definition at line 39 of file NBitmap.java.

PDBitmap mhr.appcore.bitmap.NBitmap.wrapped = null
protected

PDBitmap, se kterou NBitmap sdíli obrazová data, pokud je wrapper.

Definition at line 41 of file NBitmap.java.


The documentation for this class was generated from the following file: