Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.0 API #10

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
89a90ae
Initial version of 0.3.0 API
chris-allan Nov 18, 2016
6b5192a
Implement new methods for v0.3.0 API
jballanc Dec 2, 2016
c4b2be1
Move debug-compensating fseek
jballanc Dec 2, 2016
c725706
Get the correct full file URL for test files
jballanc Dec 2, 2016
389e344
Try testing the big file first
jballanc Dec 2, 2016
e29028c
Recycle ByteBuffer instances in Java tests
jballanc Dec 2, 2016
fe6b4dd
Comment out tests checking non-direct-allocated ByteBuffers
jballanc Dec 2, 2016
dcf512a
Disable all ByteBuffer tests
jballanc Dec 2, 2016
2cb2fa4
Add documentation for C++ classes
jballanc Jan 5, 2017
93d7d3d
Fix name of PCRE lib for Travis
jballanc Jan 5, 2017
59b35d6
Add documentation for remaining C++ classes
jballanc Jan 16, 2017
f16c98d
Revert back to passing ImageDecoder pointers
jballanc Jan 16, 2017
ba97021
Revert "Recycle ByteBuffer instances in Java tests"
chris-allan Jan 20, 2017
a9edef8
Revert "Comment out tests checking non-direct-allocated ByteBuffers"
chris-allan Jan 20, 2017
e12b4b0
Revert "Disable all ByteBuffer tests"
chris-allan Jan 20, 2017
b0eb4ac
Ensure wrapping with a Java exception handler
chris-allan Jan 20, 2017
33e41fa
Fix offset typo
chris-allan Jan 20, 2017
317c511
Fix invalid input test cases
chris-allan Jan 20, 2017
7205ce5
Fix buffer length parameter typo
jballanc Jan 20, 2017
27dcbd9
Push crash logs if they exist
chris-allan Jan 23, 2017
a9467c6
Clean up long lines
chris-allan Jan 23, 2017
cf86193
Fix additional buffer length parameter typo
chris-allan Jan 23, 2017
8e931df
Clean up long lines
chris-allan Jan 23, 2017
eb5d7ee
Revert "Revert back to passing ImageDecoder pointers"
chris-allan Jan 23, 2017
2774f1e
Add an implementation of getImageMetadata for ByteBuffers
jballanc Jan 25, 2017
cffba3d
Add more checks on offset and length arguments
jballanc Jan 25, 2017
a98aac1
Unify API for NIO Buffers and byte[]
jballanc Feb 8, 2017
68ac6ac
Rectify documentation with revised method signatures
jballanc Feb 9, 2017
6369932
Add frameCount to ImageMetadata
jballanc Feb 9, 2017
b64c2eb
Update AbstractDecode Java class to reflect refactored C++ API
jballanc Feb 9, 2017
d8d6b57
Remove "toBytes" SWIG methods
jballanc Feb 9, 2017
df5fcc5
Remove un-used classes from SWIG
jballanc Feb 9, 2017
fbde15e
Update Travis build instructions for new macOS VM image
jballanc Feb 9, 2017
dc8392a
Also install SWIG on macOS via Homebrew
jballanc Feb 9, 2017
560f60f
Ensure that the HOMEBREW option is set for Travis macOS builds
jballanc Feb 15, 2017
d5d0f36
Attempt to force OpenSSL installation on Travis
jballanc Feb 15, 2017
7b9edf6
Modify the build.gradle to use the OME Maven and staging repositories
sbesson Nov 22, 2016
ac320ce
Use the correct terminology for Maven repositories
sbesson Nov 22, 2016
ef48836
Explicitly set xcode version
sbesson Dec 8, 2016
2977585
Update Travis build instructions for new macOS VM image
jballanc Feb 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
java/target
doc/html
*.userprefs
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ matrix:
addons:
apt:
packages:
- pcre3-dev
- libpcre3-dev
compiler: gcc
- os: linux
sudo: false
addons:
apt:
packages:
- pcre3-dev
- libpcre3-dev
compiler: clang
- os: osx
osx_image: beta-xcode6.2 # Mac OS X 10.9
osx_image: xcode6.4 # Mac OS X 10.10
compiler: gcc
before_install:
- brew update
- brew install openssl
env:
- HOMEBREW=1
- os: osx
osx_image: beta-xcode6.2 # Mac OS X 10.9
osx_image: xcode6.4 # Mac OS X 10.10
compiler: clang
before_install:
- brew update
- brew install openssl
env:
- HOMEBREW=1

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; brew install swig ; fi
Expand Down
2,468 changes: 2,468 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ endif
LIBS=-L$(DIR_BUILD) $(shell echo $(LIBRARIES) | sed -E 's%$(DIR_BUILD)/lib([^ ]*)\.(a|$(LIBSUFFIX))%-l\1%g') -lm
CXXLIBS=-L$(DIR_BUILD) -ljxr++ -lcrypto

ifdef HOMEBREW
CFLAGS:=$(CFLAGS) -I$(shell brew --prefix openssl)/include
CXXFLAGS:=$(CXXFLAGS) -I$(shell brew --prefix openssl)/include
LIBS:=$(LIBS) -L$(shell brew --prefix openssl)/lib
endif

##--------------------------------
##
## Common files
Expand Down Expand Up @@ -260,6 +266,10 @@ $(DIR_BUILD)/libjxrjava.$(LIBSUFFIX): $(LIBRARIES) $(CXX_LIBRARIES)
@echo "JAVA_INCLUDE=$(JAVA_INCLUDE)"
$(CXX) -o $(DIR_BUILD)/libjxrjava.$(LIBSUFFIX) -shared -I$(JAVA_INCLUDE) -I$(JAVA_INCLUDE)/$(PLATFORM) -I$(DIR_CXX)/lib $(CXXFLAGS) $(OBJ_SYS) $(OBJ_ENC) $(OBJ_DEC) $(OBJ_GLUE) $(OBJ_TEST) $(OBJ_CXX) $(DIR_JAVA)/JXR_wrap.cxx

.PHONY: doc
doc:
doxygen Doxyfile

##--------------------------------
##
## Enc app files
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ on_success:
- ps: (Get-Content java\settings.xml) -replace '__MAVEN_SERVER_USERNAME__', "$env:MAVEN_SERVER_USERNAME" | %{$_ -replace '__MAVEN_SERVER_PASSWORD__', "$env:MAVEN_SERVER_PASSWORD"} | Out-File -encoding ASCII C:\Users\appveyor\.m2\settings.xml
- mvn -f java/pom.xml -DargLine="-Djava.library.path=vc14projects\Release\JXRJava\x64" test
- IF NOT DEFINED APPVEYOR_PULL_REQUEST_NUMBER mvn -f java\native-windows_64\pom.xml deploy
on_finish:
- ps: Get-ChildItem .\java\*.log | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
artifacts:
- path: 'java\native-windows_64\target\*.jar'
cache:
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/CodecFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ namespace jxrlib {
#ifdef DEBUG
printf("Advanced file...");
printf("First couple characters: %c%c%c", std::fgetc(pStream->state.file.pFile), std::fgetc(pStream->state.file.pFile), std::fgetc(pStream->state.file.pFile));
std::fseek(pStream->state.file.pFile, -3, SEEK_CUR);
#endif

// initialize the decoder with the prepared stream
Call(decoder.pDecoder->Initialize(decoder.pDecoder, pStream));
#ifdef DEBUG
printf("Initialized with the stream...");
std::fseek(pStream->state.file.pFile, -3, SEEK_CUR);
#endif
decoder.pDecoder->fStreamOwner = !0;
decoder.initialize();
Expand Down
61 changes: 61 additions & 0 deletions cpp/lib/CodecFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,88 @@

namespace jxrlib {

/**
* The CodecFactory class wraps the `pCodecFactory` struct and corresponding
* methods from the jxrlib C code. It contains methods to generate image
* decoders and format converters.
*/
class CodecFactory {
PKCodecFactory *pCodecFactory;
ERR err;
public:
CodecFactory();
~CodecFactory();

/**
* Initialize an ImageDecoder from a file.
*
* @param decoder A pre-instantiated ImageDecoder instance to be initialized
* @param inputFile The JPEG XR file to be decoded
*/
void decoderFromFile(ImageDecoder &decoder, std::string inputFile);

/**
* Initialize an ImageDecoder from data inside a file.
*
* @param decoder A pre-instantiated ImageDecoder instance to be
* initialized
* @param inputFile The file containing the JPEG XR data to be decoded
* @param offset The offset within the file where image data begins
*/
void decoderFromFile(ImageDecoder &decoder,
std::string inputFile,
long offset);

/**
* Initialize an ImageDecoder directly from JPEG XR data
*
* @param decoder A pre-instantiated ImageDecoder instance to be
* initialized
* @param data The raw JPEG XR data
*/
void decoderFromBytes(ImageDecoder &decoder,
std::vector<unsigned char> data);

/**
* Initialize an ImageDecoder directly from in-memory data containing a
* JPEG XR image
*
* @param decoder A pre-instantiated ImageDecoder instance to be
* initialized
* @param data The data containing the JPEG XR image
* @param offset Where in the `data` the JPEG XR image begins
* @param length The length of the JPEG XR image data
*/
void decoderFromBytes(ImageDecoder &decoder,
std::vector<unsigned char> data,
size_t offset,
size_t length);

/**
* Initialize an ImageDecoder directly from in-memory data containing a
* JPEG XR image
*
* @param decoder A pre-instantiated ImageDecoder instance to be
* initialized
* @param bytes A pointer to the location of the data containing the JPEG
* XR image
* @param offset The offset from `bytes` where the JPEG XR image begins
* @param length The length of the JPEG XR image data
*/
void decoderFromBytes(ImageDecoder &decoder,
unsigned char *bytes,
size_t offset,
size_t length);

/**
* Generate a FormatConverter from a decoder which will convert a JPEG XR
* image into an image format specified by extension
*
* @param decoder An ImageDecoder initialized with a JPEG XR image
* @param extension The file extension of the image format to convert to
* @return A FormatConverter ready to be used with an ImageEncoder
* to transcode a JPEG XR image
*/
FormatConverter createFormatConverter(ImageDecoder &decoder,
std::string extension);
};
Expand Down
106 changes: 98 additions & 8 deletions cpp/lib/DecodeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,115 @@

#include "CodecFactory.hpp"
#include "DecodeContext.hpp"
#include "Factory.hpp"
#include "ImageDecoder.hpp"
#include "ImageEncoder.hpp"

namespace jxrlib {

signed char* DecodeContext::decodeFirstFrame(char *source,
size_t offset,
size_t length,
size_t *size) {
void DecodeContext::decodeFrame(int frame,
ImageDecoder &source,
unsigned char *destination) {
source.selectFrame(frame);
source.getRawBytes(destination);
}

void DecodeContext::decodeFrame(int frame,
std::string inputFile,
std::string outputFile,
size_t sourceOffset) {
Factory factory;
CodecFactory codecFactory;

ImageDecoder decoder;
codecFactory.decoderFromFile(decoder, inputFile, sourceOffset);
decoder.selectFrame(frame);

std::string extension = outputFile.substr(outputFile.find_last_of(".") + 1);
FormatConverter converter = codecFactory.createFormatConverter(decoder, extension);
Stream outputStream = factory.createStreamFromFilename(outputFile);
ImageEncoder encoder(outputStream, "." + extension);

encoder.initializeWithDecoder(decoder);
encoder.writeSource(converter);
encoder.close();
}

signed char* DecodeContext::decodeFrame(int frame,
std::string inputFile,
size_t *size,
size_t sourceOffset) {
ImageDecoder decoder;
CodecFactory codecFactory;
codecFactory.decoderFromBytes(
decoder, (unsigned char *)source, offset, length);
codecFactory.decoderFromFile(decoder, inputFile, sourceOffset);
ImageMetadata metadata = decoder.getImageMetadata();

*size = metadata.height * metadata.width * metadata.bytesPerPixel;
signed char *destination = new signed char[*size];
decodeFrame(frame, decoder, (unsigned char *)destination);
return destination;
}

void DecodeContext::decodeFrame(int frame,
std::string inputFile,
unsigned char *destination,
size_t sourceOffset) {
Factory factory;
CodecFactory codecFactory;

ImageDecoder decoder;
codecFactory.decoderFromFile(decoder, inputFile, sourceOffset);
decodeFrame(frame, decoder, destination);
}

signed char* DecodeContext::decodeFrame(int frame,
unsigned char *source,
size_t *size,
size_t sourceOffset,
size_t sourceLength) {
ImageDecoder decoder;
CodecFactory codecFactory;
codecFactory.decoderFromBytes(decoder, source,
sourceOffset, sourceLength);

*size =
decoder.getWidth() * decoder.getHeight() * decoder.getBytesPerPixel();
signed char *destination = new signed char[*size];
decoder.selectFrame(0);
decoder.getRawBytes((unsigned char *)destination);
this->decodeFrame(frame, decoder, (unsigned char *)destination);
return destination;
}

void DecodeContext::decodeFrame(int frame,
unsigned char *source,
unsigned char *destination,
size_t sourceOffset,
size_t sourceLength,
size_t destinationOffset) {
ImageDecoder decoder;
CodecFactory codecFactory;
codecFactory.decoderFromBytes(
decoder, source, sourceOffset, sourceLength);

decodeFrame(
frame, decoder, destination + destinationOffset);
}

ImageMetadata DecodeContext::getImageMetadata(unsigned char *source,
size_t sourceOffset,
size_t sourceLength) {
ImageDecoder decoder;
CodecFactory codecFactory;
codecFactory.decoderFromBytes(decoder, (unsigned char *)source,
sourceOffset, sourceLength);
return decoder.getImageMetadata();
}

ImageMetadata DecodeContext::getImageMetadata(std::string inputFile,
size_t sourceOffset) {
ImageDecoder decoder;
CodecFactory codecFactory;
codecFactory.decoderFromFile(decoder, inputFile, sourceOffset);
return decoder.getImageMetadata();
}

} // namespace jxrlib
Loading