Browse Source

Add PNG support to the VaultImageNode functions.

Joseph Davies 13 years ago
parent
commit
cb697523f9
  1. 1
      Sources/Plasma/PubUtilLib/plVault/Pch.h
  2. 51
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp
  3. 4
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.h

1
Sources/Plasma/PubUtilLib/plVault/Pch.h

@ -74,6 +74,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnDispatch/plDispatch.h"
#include "plDniCoordinateInfo.h"
#include "plGImage/plMipmap.h"
#include "plGImage/plPNG.h"
#include "plJPEG/plJPEG.h"
#include "plMessage/plVaultNotifyMsg.h"
#include "plNetClientComm/plNetClientComm.h"

51
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

@ -633,18 +633,30 @@ void VaultImageNode::SetImageData (const uint8_t buffer[], unsigned bytes) {
//============================================================================
#ifdef CLIENT
void VaultImageNode::StuffImage (plMipmap * src) {
void VaultImageNode::StuffImage (plMipmap * src, int dstType) {
hsRAMStream ramStream;
plJPEG::Instance().SetWriteQuality(30/*percent*/);
if (plJPEG::Instance().WriteToStream(&ramStream, src)) {
hsBool compressSuccess = false;
switch (dstType) {
case kJPEG:
plJPEG::Instance().SetWriteQuality(70/*percent*/);
compressSuccess = plJPEG::Instance().WriteToStream(&ramStream, src);
break;
case kPNG:
compressSuccess = plPNG::Instance().WriteToStream(&ramStream, src);
break;
default:
break;
}
if (compressSuccess) {
unsigned bytes = ramStream.GetEOF();
uint8_t * buffer = (uint8_t *)malloc(bytes);
ramStream.CopyToMem(buffer);
IVaultNodeSetBlob(kImageData, base, &imgData, &imgDataLen, buffer, bytes);
SetImageType(kJPEG);
SetImageType(dstType);
free(buffer);
}
else {
} else {
IVaultNodeSetBlob(kImageData, base, &imgData, &imgDataLen, nil, 0);
SetImageType(kNone);
}
@ -654,22 +666,25 @@ void VaultImageNode::StuffImage (plMipmap * src) {
//============================================================================
#ifdef CLIENT
bool VaultImageNode::ExtractImage (plMipmap ** dst) {
hsRAMStream ramStream;
ramStream.Write(imgDataLen, imgData);
ramStream.Rewind();
switch (imgType) {
case kJPEG:
(*dst) = plJPEG::Instance().ReadFromStream(&ramStream);
break;
case kPNG:
(*dst) = plPNG::Instance().ReadFromStream(&ramStream);
break;
case kNone:
default:
(*dst) = nil;
return false;
case kJPEG: {
hsRAMStream ramStream;
ramStream.Write(imgDataLen, imgData);
ramStream.Rewind();
(*dst) = plJPEG::Instance().ReadFromStream(&ramStream);
}
return ((*dst) != nil);
DEFAULT_FATAL(imgType);
break;
}
return ((*dst) != nil);
}
#endif

4
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.h

@ -290,7 +290,7 @@ struct VaultAgeLinkNode : NetVaultNodeAccess {
//============================================================================
struct VaultImageNode : NetVaultNodeAccess {
enum ImageTypes { kNone=0, kJPEG=1 };
enum ImageTypes { kNone=0, kJPEG=1, kPNG=2 };
static const uint64_t kImageType = NetVaultNode::kInt32_1;
static const uint64_t kImageTitle = NetVaultNode::kString64_1;
@ -310,7 +310,7 @@ struct VaultImageNode : NetVaultNodeAccess {
void SetImageData (const uint8_t buffer[], unsigned bytes);
#ifdef CLIENT
void StuffImage (class plMipmap * src);
void StuffImage (class plMipmap * src, int dstType=kJPEG);
bool ExtractImage (class plMipmap ** dst);
#endif
};

Loading…
Cancel
Save