Initial commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
*.o.*
|
||||||
|
*.d.*
|
||||||
|
*.a.*
|
||||||
|
.*.swp
|
||||||
|
.AppleDouble
|
||||||
|
lib
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "Makefiles"]
|
||||||
|
path = Makefiles
|
||||||
|
url = https://gogs.dierkse.nl/JDierkse/Makefiles.git
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
#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
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#include "JpegImageCollection.h"
|
||||||
|
#include <stdio.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
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../Makefile
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Makefile.conf
|
||||||
|
#
|
||||||
|
|
||||||
|
LFLAGS += -lImage
|
||||||
|
LFLAGS += -L$(ROOTPATH)/lib/$(ARCH)
|
||||||
|
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
|
||||||
|
|
||||||
|
DEBUGDIR := .debug
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#
|
||||||
|
# Makefile.target
|
||||||
|
#
|
||||||
|
|
||||||
|
Image.a.$(ARCH) : $(OBJECTS)
|
||||||
|
$(call build_target_library_arch,$@,$^)
|
||||||
|
|
||||||
|
Image.a:
|
||||||
|
$(call build_target,$@)
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := Image.a
|
||||||
|
|
||||||
|
TARGETS += Image.a
|
||||||
Submodule
+1
Submodule Makefiles added at cd9ef1a1b0
@@ -0,0 +1,55 @@
|
|||||||
|
#ifndef JPEGIMAGE_H
|
||||||
|
#define JPEGIMAGE_H
|
||||||
|
|
||||||
|
#include <stdio.h> // jpeglib issue
|
||||||
|
#include <jpeglib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef JPEGIMAGECOLLECTION_H
|
||||||
|
#define JPEGIMAGECOLLECTION_H
|
||||||
|
|
||||||
|
#include "JpegImage.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 // JPEGIMAGECOLLECTION_H
|
||||||
Reference in New Issue
Block a user