Use Image Library
This commit is contained in:
@@ -1,124 +0,0 @@
|
|||||||
#include "JpegImage.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Image {
|
|
||||||
|
|
||||||
const static JOCTET EOI_BUFFER[1] = { JPEG_EOI };
|
|
||||||
|
|
||||||
JpegImage::JpegImage()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::SetImageData(const std::string& data)
|
|
||||||
{
|
|
||||||
DecompressImage(data.c_str(), data.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int JpegImage::Width() const
|
|
||||||
{
|
|
||||||
return m_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int JpegImage::Height() const
|
|
||||||
{
|
|
||||||
return m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int JpegImage::StrideX() const
|
|
||||||
{
|
|
||||||
return m_strideX;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int JpegImage::StrideY() const
|
|
||||||
{
|
|
||||||
return m_strideY;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<char>& JpegImage::Data() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::InitSource(j_decompress_ptr pCinfo)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean JpegImage::FillInputBuffer(j_decompress_ptr pCinfo)
|
|
||||||
{
|
|
||||||
SourceMgrPtr pSrc = reinterpret_cast<SourceMgrPtr>(pCinfo->src);
|
|
||||||
pSrc->pub.next_input_byte = EOI_BUFFER;
|
|
||||||
pSrc->pub.bytes_in_buffer = 1;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::SkipInputData(j_decompress_ptr pCinfo, long numBytes)
|
|
||||||
{
|
|
||||||
SourceMgrPtr pSrc = reinterpret_cast<SourceMgrPtr>(pCinfo->src);
|
|
||||||
if (pSrc->pub.bytes_in_buffer < static_cast<size_t>(numBytes))
|
|
||||||
{
|
|
||||||
pSrc->pub.next_input_byte = EOI_BUFFER;
|
|
||||||
pSrc->pub.bytes_in_buffer = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pSrc->pub.next_input_byte += numBytes;
|
|
||||||
pSrc->pub.bytes_in_buffer -= numBytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::TermSource(j_decompress_ptr pCinfo)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::SetSourceMgr(j_decompress_ptr pCinfo, const char* pData, size_t len) const
|
|
||||||
{
|
|
||||||
SourceMgrPtr pSrc;
|
|
||||||
if (pCinfo->src == 0)
|
|
||||||
pCinfo->src = (struct jpeg_source_mgr *)(*pCinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(pCinfo), JPOOL_PERMANENT, sizeof(SourceMgr));
|
|
||||||
|
|
||||||
pSrc = reinterpret_cast<SourceMgrPtr>(pCinfo->src);
|
|
||||||
pSrc->pub.init_source = JpegImage::InitSource;
|
|
||||||
pSrc->pub.fill_input_buffer = JpegImage::FillInputBuffer;
|
|
||||||
pSrc->pub.skip_input_data = JpegImage::SkipInputData;
|
|
||||||
pSrc->pub.resync_to_restart = jpeg_resync_to_restart;
|
|
||||||
pSrc->pub.term_source = JpegImage::TermSource;
|
|
||||||
|
|
||||||
pSrc->data = (const JOCTET *)pData;
|
|
||||||
pSrc->len = len;
|
|
||||||
pSrc->pub.bytes_in_buffer = len;
|
|
||||||
pSrc->pub.next_input_byte = pSrc->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImage::DecompressImage(const char* pData, size_t len)
|
|
||||||
{
|
|
||||||
struct jpeg_decompress_struct cinfo;
|
|
||||||
struct jpeg_error_mgr jerr;
|
|
||||||
|
|
||||||
jerr.trace_level = 0;
|
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
|
||||||
jpeg_create_decompress(&cinfo);
|
|
||||||
SetSourceMgr(&cinfo, pData, len);
|
|
||||||
|
|
||||||
jpeg_read_header(&cinfo, TRUE);
|
|
||||||
jpeg_start_decompress(&cinfo);
|
|
||||||
|
|
||||||
m_width = cinfo.image_width;
|
|
||||||
m_height = cinfo.image_height;
|
|
||||||
m_strideX = cinfo.num_components;
|
|
||||||
m_strideY = m_width * cinfo.num_components;
|
|
||||||
|
|
||||||
m_data.resize(m_height * m_strideY);
|
|
||||||
|
|
||||||
JSAMPROW scanlines[1];
|
|
||||||
while (cinfo.output_scanline < cinfo.image_height)
|
|
||||||
{
|
|
||||||
scanlines[0] = reinterpret_cast<JSAMPROW>(&m_data[cinfo.output_scanline * m_strideY]);
|
|
||||||
jpeg_read_scanlines(&cinfo, scanlines, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
jpeg_finish_decompress(&cinfo);
|
|
||||||
jpeg_destroy_decompress(&cinfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Image
|
|
||||||
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#ifndef JPEGIMAGE_H
|
|
||||||
#define JPEGIMAGE_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <jpeglib.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Image {
|
|
||||||
|
|
||||||
class JpegImage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
JpegImage();
|
|
||||||
|
|
||||||
void SetImageData(const std::string& data);
|
|
||||||
|
|
||||||
unsigned int Width() const;
|
|
||||||
unsigned int Height() const;
|
|
||||||
unsigned int StrideX() const;
|
|
||||||
unsigned int StrideY() const;
|
|
||||||
const std::vector<char>& Data() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct SourceMgr
|
|
||||||
{
|
|
||||||
struct jpeg_source_mgr pub;
|
|
||||||
const JOCTET *data;
|
|
||||||
size_t len;
|
|
||||||
};
|
|
||||||
typedef SourceMgr* SourceMgrPtr;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void InitSource(j_decompress_ptr pCinfo);
|
|
||||||
static boolean FillInputBuffer(j_decompress_ptr pCinfo);
|
|
||||||
static void SkipInputData(j_decompress_ptr pCinfo, long numBytes);
|
|
||||||
static void TermSource(j_decompress_ptr pCinfo);
|
|
||||||
|
|
||||||
void SetSourceMgr(j_decompress_ptr pCinfo, const char* pData, size_t len) const;
|
|
||||||
|
|
||||||
void DecompressImage(const char* pData, size_t len);
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int m_width;
|
|
||||||
unsigned int m_height;
|
|
||||||
unsigned int m_strideX;
|
|
||||||
unsigned int m_strideY;
|
|
||||||
|
|
||||||
std::vector<char> m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Image
|
|
||||||
|
|
||||||
#endif // JPEGIMAGE_H
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "JpegImageCollection.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Image {
|
|
||||||
|
|
||||||
JpegImageCollection::JpegImageCollection(const std::vector<JpegImage>& images) :
|
|
||||||
m_width(0),
|
|
||||||
m_height(0),
|
|
||||||
m_strideX(0),
|
|
||||||
m_strideY(0)
|
|
||||||
{
|
|
||||||
if (images.size() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_width = images[0].Width();
|
|
||||||
m_strideX = images[0].StrideX();
|
|
||||||
m_strideY = images[0].StrideY();
|
|
||||||
|
|
||||||
size_t height = images[0].Height();
|
|
||||||
m_height = height * images.size();
|
|
||||||
m_imageData.resize(m_strideY * m_height);
|
|
||||||
|
|
||||||
std::vector<char>::iterator outIterator = m_imageData.begin();
|
|
||||||
for (std::vector<JpegImage>::const_iterator it = images.begin(); it != images.end(); ++it)
|
|
||||||
outIterator = std::copy(it->Data().begin(), it->Data().end(), outIterator);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JpegImageCollection::Save(const std::string& fileName)
|
|
||||||
{
|
|
||||||
if (m_width == 0 || m_height == 0 || m_strideX == 0 || m_strideY == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
struct jpeg_compress_struct cinfo;
|
|
||||||
struct jpeg_error_mgr jerr;
|
|
||||||
|
|
||||||
FILE* outFile = fopen(fileName.c_str(), "wb");
|
|
||||||
|
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
|
||||||
jpeg_create_compress(&cinfo);
|
|
||||||
jpeg_stdio_dest(&cinfo, outFile);
|
|
||||||
|
|
||||||
cinfo.image_width = m_width;
|
|
||||||
cinfo.image_height = m_height;
|
|
||||||
cinfo.input_components = m_strideX;
|
|
||||||
cinfo.in_color_space = JCS_RGB;
|
|
||||||
|
|
||||||
jpeg_set_defaults( &cinfo );
|
|
||||||
cinfo.num_components = 3;
|
|
||||||
cinfo.dct_method = JDCT_FLOAT;
|
|
||||||
jpeg_set_quality(&cinfo, 80, TRUE);
|
|
||||||
|
|
||||||
jpeg_start_compress( &cinfo, TRUE );
|
|
||||||
|
|
||||||
JSAMPROW scanlines[1];
|
|
||||||
while (cinfo.next_scanline < cinfo.image_height)
|
|
||||||
{
|
|
||||||
scanlines[0] = reinterpret_cast<JSAMPROW>(&m_imageData[cinfo.next_scanline * m_strideY]);
|
|
||||||
jpeg_write_scanlines(&cinfo, scanlines, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
jpeg_finish_compress(&cinfo);
|
|
||||||
jpeg_destroy_compress(&cinfo);
|
|
||||||
fclose(outFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Image
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef OUTPUTIMAGE_H
|
|
||||||
#define OUTPUTIMAGE_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "JpegImage.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Image {
|
|
||||||
|
|
||||||
class JpegImageCollection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
JpegImageCollection(const std::vector<JpegImage>& images);
|
|
||||||
|
|
||||||
void Save(const std::string& fileName);
|
|
||||||
|
|
||||||
private:
|
|
||||||
size_t m_width;
|
|
||||||
size_t m_height;
|
|
||||||
size_t m_strideX;
|
|
||||||
size_t m_strideY;
|
|
||||||
|
|
||||||
std::vector<char> m_imageData;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Image
|
|
||||||
|
|
||||||
#endif // OUTPUTIMAGE_H
|
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../../Libraries/Image
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "Message.h"
|
#include "Message.h"
|
||||||
#include "Image/JpegImageCollection.h"
|
|
||||||
#include "Util/Base64.h"
|
#include "Util/Base64.h"
|
||||||
|
#include <JpegImageCollection.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <StringAlgorithm.h>
|
#include <StringAlgorithm.h>
|
||||||
#include <filesystem/path.h>
|
#include <filesystem/path.h>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#define MESSAGE_H
|
#define MESSAGE_H
|
||||||
|
|
||||||
#include "Image/MimeImage.h"
|
#include "Image/MimeImage.h"
|
||||||
#include "Image/JpegImage.h"
|
|
||||||
#include "Util/Util.h"
|
#include "Util/Util.h"
|
||||||
|
#include <JpegImage.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -14,10 +14,13 @@ LFLAGS += -lUtilities
|
|||||||
LFLAGS += -L$(ROOTPATH)/Libraries/Utilities/lib/$(ARCH)
|
LFLAGS += -L$(ROOTPATH)/Libraries/Utilities/lib/$(ARCH)
|
||||||
CFLAGS += -I$(ROOTPATH)/Libraries/Utilities/include
|
CFLAGS += -I$(ROOTPATH)/Libraries/Utilities/include
|
||||||
|
|
||||||
|
LFLAGS += -lImage -ljpeg
|
||||||
|
LFLAGS += -L$(ROOTPATH)/Libraries/Image/lib/$(ARCH)
|
||||||
|
CFLAGS += -I$(ROOTPATH)/Libraries/Image/include
|
||||||
|
|
||||||
CFLAGS += -I$(ROOTPATH)/Libraries/asio/asio/include
|
CFLAGS += -I$(ROOTPATH)/Libraries/asio/asio/include
|
||||||
CFLAGS += -I$(ROOTPATH)/Libraries/filesystem
|
CFLAGS += -I$(ROOTPATH)/Libraries/filesystem
|
||||||
|
|
||||||
LFLAGS += -ljpeg
|
|
||||||
LFLAGS += -lpthread
|
LFLAGS += -lpthread
|
||||||
|
|
||||||
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/Libraries
|
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/Libraries
|
||||||
|
|||||||
Reference in New Issue
Block a user