|
|
@ -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 |
|
|
|
|
|
|
|
|
|
|
|