Skip to content

Commit

Permalink
Updated the member naming of the JlsParameters structure to use the s…
Browse files Browse the repository at this point in the history
…tandard CharLS naming scheme (API change).
  • Loading branch information
vbaderks committed May 18, 2016
1 parent 49b4eff commit 29f39e6
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 99 deletions.
4 changes: 2 additions & 2 deletions samples/convert.c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ static void *encode_bmp_to_jpegls(const void *pixel_data, size_t pixel_data_size
{
// This function only supports 24-bit BMP pixel data.
// 24-BMP pixel data is stored by pixel as RGB. JPEG-LS
struct JlsParameters params = { .allowedlossyerror = 0, .ilv = CHARLS_IM_SAMPLE };
struct JlsParameters params = { .allowedLossyError = 0, .interleaveMode = CHARLS_IM_SAMPLE };

params.width = header->width;
params.height = header->height;
params.bitspersample = 8;
params.bitsPerSample = 8;
params.components = 3;

// Assume that compressed pixels are smaller or equal to uncompressed pixels and reserver some room for JPEG header.
Expand Down
40 changes: 20 additions & 20 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ static void VerifyInput(const ByteStreamInfo& uncompressedStream, const JlsParam
if (parameters.height < 1 || parameters.height > 65535)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "height needs to be in the range [1, 65535]");

if (parameters.bitspersample < 2 || parameters.bitspersample > 16)
if (parameters.bitsPerSample < 2 || parameters.bitsPerSample > 16)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "bitspersample needs to be in the range [2, 16]");

if (!(parameters.ilv == InterleaveMode::None || parameters.ilv == InterleaveMode::Sample || parameters.ilv == InterleaveMode::Line))
throw CreateSystemError(ApiResult::InvalidJlsParameters, "ilv needs to be set to a value of {None, Sample, Line}");
if (!(parameters.interleaveMode == InterleaveMode::None || parameters.interleaveMode == InterleaveMode::Sample || parameters.interleaveMode == InterleaveMode::Line))
throw CreateSystemError(ApiResult::InvalidJlsParameters, "interleaveMode needs to be set to a value of {None, Sample, Line}");

if (parameters.components < 1 || parameters.components > 255)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "components needs to be in the range [1, 255]");

if (uncompressedStream.rawData)
{
if (uncompressedStream.count < size_t(parameters.height * parameters.width * parameters.components * (parameters.bitspersample > 8 ? 2 : 1)))
if (uncompressedStream.count < size_t(parameters.height * parameters.width * parameters.components * (parameters.bitsPerSample > 8 ? 2 : 1)))
throw CreateSystemError(ApiResult::InvalidJlsParameters, "uncompressed size does not match with the other parameters");
}

Expand All @@ -45,12 +45,12 @@ static void VerifyInput(const ByteStreamInfo& uncompressedStream, const JlsParam
case 3:
break;
case 4:
if (parameters.ilv == InterleaveMode::Sample)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "ilv cannot be set to Sample in combination with components = 4");
if (parameters.interleaveMode == InterleaveMode::Sample)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "interleaveMode cannot be set to Sample in combination with components = 4");
break;
default:
if (parameters.ilv != InterleaveMode::None)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "ilv can only be set to None in combination with components = 1");
if (parameters.interleaveMode != InterleaveMode::None)
throw CreateSystemError(ApiResult::InvalidJlsParameters, "interleaveMode can only be set to None in combination with components = 1");
break;
}
}
Expand Down Expand Up @@ -96,12 +96,12 @@ CHARLS_IMEXPORT(ApiResult) JpegLsEncodeStream(ByteStreamInfo compressedStreamInf
VerifyInput(rawStreamInfo, params);

JlsParameters info = params;
if (info.bytesperline == 0)
if (info.stride == 0)
{
info.bytesperline = info.width * ((info.bitspersample + 7)/8);
if (info.ilv != InterleaveMode::None)
info.stride = info.width * ((info.bitsPerSample + 7)/8);
if (info.interleaveMode != InterleaveMode::None)
{
info.bytesperline *= info.components;
info.stride *= info.components;
}
}

Expand All @@ -111,17 +111,17 @@ CHARLS_IMEXPORT(ApiResult) JpegLsEncodeStream(ByteStreamInfo compressedStreamInf
writer.AddSegment(JpegMarkerSegment::CreateJpegFileInterchangeFormatSegment(info.jfif));
}

writer.AddSegment(JpegMarkerSegment::CreateStartOfFrameSegment(info.width, info.height, info.bitspersample, info.components));
writer.AddSegment(JpegMarkerSegment::CreateStartOfFrameSegment(info.width, info.height, info.bitsPerSample, info.components));


if (info.colorTransform != ColorTransformation::None)
if (info.colorTransformation != ColorTransformation::None)
{
writer.AddColorTransform(info.colorTransform);
writer.AddColorTransform(info.colorTransformation);
}

if (info.ilv == InterleaveMode::None)
if (info.interleaveMode == InterleaveMode::None)
{
int32_t cbyteComp = info.width * info.height * ((info.bitspersample + 7) / 8);
int32_t cbyteComp = info.width * info.height * ((info.bitsPerSample + 7) / 8);
for (int32_t component = 0; component < info.components; ++component)
{
writer.AddScan(rawStreamInfo, info);
Expand Down Expand Up @@ -254,11 +254,11 @@ extern "C"
writer.AddSegment(JpegMarkerSegment::CreateJpegFileInterchangeFormatSegment(info.jfif));
}

writer.AddSegment(JpegMarkerSegment::CreateStartOfFrameSegment(info.width, info.height, info.bitspersample, info.components));
writer.AddSegment(JpegMarkerSegment::CreateStartOfFrameSegment(info.width, info.height, info.bitsPerSample, info.components));

if (info.ilv == InterleaveMode::None)
if (info.interleaveMode == InterleaveMode::None)
{
int32_t fieldLength = info.width * info.height * ((info.bitspersample + 7) / 8);
int32_t fieldLength = info.width * info.height * ((info.bitsPerSample + 7) / 8);
for (int32_t component = 0; component < info.components; ++component)
{
writer.AddScan(rawStreamInfo, info);
Expand Down
30 changes: 15 additions & 15 deletions src/jpegls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ unique_ptr<STRATEGY> JlsCodecFactory<STRATEGY>::GetCodec(const JlsParameters& pa

if (presets.RESET != 0 && presets.RESET != BASIC_RESET)
{
DefaultTraitsT<uint8_t, uint8_t> traits((1 << params.bitspersample) - 1, params.allowedlossyerror, presets.RESET);
DefaultTraitsT<uint8_t, uint8_t> traits((1 << params.bitsPerSample) - 1, params.allowedLossyError, presets.RESET);
traits.MAXVAL = presets.MAXVAL;
strategy = std::unique_ptr<STRATEGY>(new JlsCodec<DefaultTraitsT<uint8_t, uint8_t>, STRATEGY>(traits, params));
}
Expand Down Expand Up @@ -137,22 +137,22 @@ unique_ptr<STRATEGY> JlsCodecFactory<STRATEGY>::GetCodecImpl(const JlsParameters
{
STRATEGY* s = nullptr;

if (params.ilv == InterleaveMode::Sample && params.components != 3)
if (params.interleaveMode == InterleaveMode::Sample && params.components != 3)
return nullptr;

#ifndef DISABLE_SPECIALIZATIONS

// optimized lossless versions common formats
if (params.allowedlossyerror == 0)
if (params.allowedLossyError == 0)
{
if (params.ilv == InterleaveMode::Sample)
if (params.interleaveMode == InterleaveMode::Sample)
{
if (params.bitspersample == 8)
if (params.bitsPerSample == 8)
return CreateCodec(LosslessTraitsT<Triplet<uint8_t>, 8>(), s, params);
}
else
{
switch (params.bitspersample)
switch (params.bitsPerSample)
{
case 8: return CreateCodec(LosslessTraitsT<uint8_t, 8>(), s, params);
case 12: return CreateCodec(LosslessTraitsT<uint16_t, 12>(), s, params);
Expand All @@ -163,21 +163,21 @@ unique_ptr<STRATEGY> JlsCodecFactory<STRATEGY>::GetCodecImpl(const JlsParameters

#endif

int maxval = (1 << params.bitspersample) - 1;
int maxval = (1 << params.bitsPerSample) - 1;

if (params.bitspersample <= 8)
if (params.bitsPerSample <= 8)
{
if (params.ilv == InterleaveMode::Sample)
return CreateCodec(DefaultTraitsT<uint8_t, Triplet<uint8_t> >(maxval, params.allowedlossyerror), s, params);
if (params.interleaveMode == InterleaveMode::Sample)
return CreateCodec(DefaultTraitsT<uint8_t, Triplet<uint8_t> >(maxval, params.allowedLossyError), s, params);

return CreateCodec(DefaultTraitsT<uint8_t, uint8_t>((1 << params.bitspersample) - 1, params.allowedlossyerror), s, params);
return CreateCodec(DefaultTraitsT<uint8_t, uint8_t>((1 << params.bitsPerSample) - 1, params.allowedLossyError), s, params);
}
if (params.bitspersample <= 16)
if (params.bitsPerSample <= 16)
{
if (params.ilv == InterleaveMode::Sample)
return CreateCodec(DefaultTraitsT<uint16_t,Triplet<uint16_t> >(maxval, params.allowedlossyerror), s, params);
if (params.interleaveMode == InterleaveMode::Sample)
return CreateCodec(DefaultTraitsT<uint16_t,Triplet<uint16_t> >(maxval, params.allowedLossyError), s, params);

return CreateCodec(DefaultTraitsT<uint16_t, uint16_t>(maxval, params.allowedlossyerror), s, params);
return CreateCodec(DefaultTraitsT<uint16_t, uint16_t>(maxval, params.allowedLossyError), s, params);
}
return nullptr;
}
Expand Down
28 changes: 14 additions & 14 deletions src/jpegstreamreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ JlsCustomParameters ComputeDefault(int32_t MAXVAL, int32_t NEAR)

ApiResult CheckParameterCoherent(const JlsParameters& params)
{
if (params.bitspersample < 2 || params.bitspersample > 16)
if (params.bitsPerSample < 2 || params.bitsPerSample > 16)
return ApiResult::ParameterValueNotSupported;

if (params.ilv < InterleaveMode::None || params.ilv > InterleaveMode::Sample)
if (params.interleaveMode < InterleaveMode::None || params.interleaveMode > InterleaveMode::Sample)
return ApiResult::InvalidCompressedData;

switch (params.components)
{
case 4: return params.ilv == InterleaveMode::Sample ? ApiResult::ParameterValueNotSupported : ApiResult::OK;
case 4: return params.interleaveMode == InterleaveMode::Sample ? ApiResult::ParameterValueNotSupported : ApiResult::OK;
case 3: return ApiResult::OK;
case 0: return ApiResult::InvalidJlsParameters;

default: return params.ilv != InterleaveMode::None ? ApiResult::ParameterValueNotSupported : ApiResult::OK;
default: return params.interleaveMode != InterleaveMode::None ? ApiResult::ParameterValueNotSupported : ApiResult::OK;
}
}

Expand Down Expand Up @@ -106,7 +106,7 @@ void JpegStreamReader::Read(ByteStreamInfo rawPixels)
_rect.Height = _params.height;
}

int64_t bytesPerPlane = static_cast<int64_t>(_rect.Width) * _rect.Height * ((_params.bitspersample + 7)/8);
int64_t bytesPerPlane = static_cast<int64_t>(_rect.Width) * _rect.Height * ((_params.bitsPerSample + 7)/8);

if (rawPixels.rawData && int64_t(rawPixels.count) < bytesPerPlane * _params.components)
throw system_error(static_cast<int>(ApiResult::UncompressedBufferTooSmall), CharLSCategoryInstance());
Expand All @@ -122,7 +122,7 @@ void JpegStreamReader::Read(ByteStreamInfo rawPixels)
qcodec->DecodeScan(move(processLine), _rect, _byteStream, _bCompare);
SkipBytes(rawPixels, static_cast<size_t>(bytesPerPlane));

if (_params.ilv != InterleaveMode::None)
if (_params.interleaveMode != InterleaveMode::None)
return;

componentIndex += 1;
Expand Down Expand Up @@ -282,18 +282,18 @@ void JpegStreamReader::ReadStartOfScan(bool firstComponent)
ReadByte();
ReadByte();
}
_params.allowedlossyerror = ReadByte();
_params.ilv = static_cast<InterleaveMode>(ReadByte());
if (!(_params.ilv == InterleaveMode::None || _params.ilv == InterleaveMode::Line || _params.ilv == InterleaveMode::Sample))
_params.allowedLossyError = ReadByte();
_params.interleaveMode = static_cast<InterleaveMode>(ReadByte());
if (!(_params.interleaveMode == InterleaveMode::None || _params.interleaveMode == InterleaveMode::Line || _params.interleaveMode == InterleaveMode::Sample))
throw system_error(static_cast<int>(ApiResult::InvalidCompressedData), CharLSCategoryInstance());// TODO: throw more specific error code.
if (ReadByte() != 0)
throw system_error(static_cast<int>(ApiResult::InvalidCompressedData), CharLSCategoryInstance());// TODO: throw more specific error code.

if(_params.bytesperline == 0)
if(_params.stride == 0)
{
int width = _rect.Width != 0 ? _rect.Width : _params.width;
int components = _params.ilv == InterleaveMode::None ? 1 : _params.components;
_params.bytesperline = components * width * ((_params.bitspersample + 7)/8);
int components = _params.interleaveMode == InterleaveMode::None ? 1 : _params.components;
_params.stride = components * width * ((_params.bitsPerSample + 7)/8);
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ void JpegStreamReader::ReadJfif()

int JpegStreamReader::ReadStartOfFrame()
{
_params.bitspersample = ReadByte();
_params.bitsPerSample = ReadByte();
int cline = ReadWord();
int ccol = ReadWord();
_params.width = ccol;
Expand Down Expand Up @@ -384,7 +384,7 @@ int JpegStreamReader::ReadColorXForm()
case ColorTransformation::HP1:
case ColorTransformation::HP2:
case ColorTransformation::HP3:
_params.colorTransform = xform;
_params.colorTransformation = xform;
return 5;
case ColorTransformation::RgbAsYuvLossy:
case ColorTransformation::Matrix:
Expand Down
8 changes: 4 additions & 4 deletions src/jpegstreamwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ void JpegStreamWriter::AddScan(const ByteStreamInfo& info, const JlsParameters&
{
AddSegment(JpegMarkerSegment::CreateJpegLSExtendedParametersSegment(params.custom));
}
else if (params.bitspersample > 12)
else if (params.bitsPerSample > 12)
{
JlsCustomParameters preset = ComputeDefault((1 << params.bitspersample) - 1, params.allowedlossyerror);
JlsCustomParameters preset = ComputeDefault((1 << params.bitsPerSample) - 1, params.allowedLossyError);
AddSegment(JpegMarkerSegment::CreateJpegLSExtendedParametersSegment(preset));
}

// Note: it is a common practice to start to count components by index 1.
_lastCompenentIndex += 1;
int componentCount = params.ilv == InterleaveMode::None ? 1 : params.components;
AddSegment(JpegMarkerSegment::CreateStartOfScanSegment(_lastCompenentIndex, componentCount, params.allowedlossyerror, params.ilv));
int componentCount = params.interleaveMode == InterleaveMode::None ? 1 : params.components;
AddSegment(JpegMarkerSegment::CreateStartOfScanSegment(_lastCompenentIndex, componentCount, params.allowedLossyError, params.interleaveMode));

AddSegment(make_unique<JpegImageDataSegment>(info, params, componentCount));
}
20 changes: 10 additions & 10 deletions src/processline.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PostProcesSingleComponent : public ProcessLine
PostProcesSingleComponent(void* rawData, const JlsParameters& params, int bytesPerPixel) :
_rawData(static_cast<uint8_t*>(rawData)),
_bytesPerPixel(bytesPerPixel),
_bytesPerLine(params.bytesperline)
_bytesPerLine(params.stride)
{
}

Expand Down Expand Up @@ -95,7 +95,7 @@ class PostProcesSingleStream : public ProcessLine
PostProcesSingleStream(std::basic_streambuf<char>* rawData, const JlsParameters& params, int bytesPerPixel) :
_rawData(rawData),
_bytesPerPixel(bytesPerPixel),
_bytesPerLine(params.bytesperline)
_bytesPerLine(params.stride)
{
}

Expand Down Expand Up @@ -244,7 +244,7 @@ class ProcessTransformed : public ProcessLine
if (!_rawPixels.rawStream)
{
Transform(_rawPixels.rawData, dest, pixelCount, destStride);
_rawPixels.rawData += _params.bytesperline;
_rawPixels.rawData += _params.stride;
return;
}

Expand All @@ -266,7 +266,7 @@ class ProcessTransformed : public ProcessLine

bytesToRead -= read;
}
if (sizeof(SAMPLE) == 2 && _params.colorTransform == charls::ColorTransformation::BigEndian)
if (sizeof(SAMPLE) == 2 && _params.colorTransformation == charls::ColorTransformation::BigEndian)
{
ByteSwap(&_buffer[0], _params.components * sizeof(SAMPLE) * pixelCount);
}
Expand All @@ -284,7 +284,7 @@ class ProcessTransformed : public ProcessLine

if (_params.components == 3)
{
if (_params.ilv == charls::InterleaveMode::Sample)
if (_params.interleaveMode == charls::InterleaveMode::Sample)
{
TransformLine(static_cast<Triplet<SAMPLE>*>(dest), static_cast<const Triplet<SAMPLE>*>(source), pixelCount, _transform);
}
Expand All @@ -293,7 +293,7 @@ class ProcessTransformed : public ProcessLine
TransformTripletToLine(static_cast<const Triplet<SAMPLE>*>(source), pixelCount, static_cast<SAMPLE*>(dest), destStride, _transform);
}
}
else if (_params.components == 4 && _params.ilv == charls::InterleaveMode::Line)
else if (_params.components == 4 && _params.interleaveMode == charls::InterleaveMode::Line)
{
TransformQuadToLine(static_cast<const Quad<SAMPLE>*>(source), pixelCount, static_cast<SAMPLE*>(dest), destStride, _transform);
}
Expand All @@ -303,7 +303,7 @@ class ProcessTransformed : public ProcessLine
{
if (_params.components == 3)
{
if (_params.ilv == charls::InterleaveMode::Sample)
if (_params.interleaveMode == charls::InterleaveMode::Sample)
{
TransformLine(static_cast<Triplet<SAMPLE>*>(rawData), static_cast<const Triplet<SAMPLE>*>(pSrc), pixelCount, _inverseTransform);
}
Expand All @@ -312,7 +312,7 @@ class ProcessTransformed : public ProcessLine
TransformLineToTriplet(static_cast<const SAMPLE*>(pSrc), byteStride, static_cast<Triplet<SAMPLE>*>(rawData), pixelCount, _inverseTransform);
}
}
else if (_params.components == 4 && _params.ilv == charls::InterleaveMode::Line)
else if (_params.components == 4 && _params.interleaveMode == charls::InterleaveMode::Line)
{
TransformLineToQuad(static_cast<const SAMPLE*>(pSrc), byteStride, static_cast<Quad<SAMPLE>*>(rawData), pixelCount, _inverseTransform);
}
Expand All @@ -330,7 +330,7 @@ class ProcessTransformed : public ProcessLine
std::streamsize bytesToWrite = pixelCount * _params.components * sizeof(SAMPLE);
DecodeTransform(pSrc, &_buffer[0], pixelCount, sourceStride);

if (sizeof(SAMPLE) == 2 && _params.colorTransform == charls::ColorTransformation::BigEndian)
if (sizeof(SAMPLE) == 2 && _params.colorTransformation == charls::ColorTransformation::BigEndian)
{
ByteSwap(&_buffer[0], _params.components * sizeof(SAMPLE) * pixelCount);
}
Expand All @@ -342,7 +342,7 @@ class ProcessTransformed : public ProcessLine
else
{
DecodeTransform(pSrc, _rawPixels.rawData, pixelCount, sourceStride);
_rawPixels.rawData += _params.bytesperline;
_rawPixels.rawData += _params.stride;
}
}

Expand Down
Loading

0 comments on commit 29f39e6

Please sign in to comment.