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. 47
      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 "pnDispatch/plDispatch.h"
#include "plDniCoordinateInfo.h" #include "plDniCoordinateInfo.h"
#include "plGImage/plMipmap.h" #include "plGImage/plMipmap.h"
#include "plGImage/plPNG.h"
#include "plJPEG/plJPEG.h" #include "plJPEG/plJPEG.h"
#include "plMessage/plVaultNotifyMsg.h" #include "plMessage/plVaultNotifyMsg.h"
#include "plNetClientComm/plNetClientComm.h" #include "plNetClientComm/plNetClientComm.h"

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

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

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

@ -290,7 +290,7 @@ struct VaultAgeLinkNode : NetVaultNodeAccess {
//============================================================================ //============================================================================
struct VaultImageNode : 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 kImageType = NetVaultNode::kInt32_1;
static const uint64_t kImageTitle = NetVaultNode::kString64_1; static const uint64_t kImageTitle = NetVaultNode::kString64_1;
@ -310,7 +310,7 @@ struct VaultImageNode : NetVaultNodeAccess {
void SetImageData (const uint8_t buffer[], unsigned bytes); void SetImageData (const uint8_t buffer[], unsigned bytes);
#ifdef CLIENT #ifdef CLIENT
void StuffImage (class plMipmap * src); void StuffImage (class plMipmap * src, int dstType=kJPEG);
bool ExtractImage (class plMipmap ** dst); bool ExtractImage (class plMipmap ** dst);
#endif #endif
}; };

Loading…
Cancel
Save