Skip to content

Commit

Permalink
Options, new added and others restored
Browse files Browse the repository at this point in the history
  • Loading branch information
baAlex committed May 8, 2022
1 parent 41a44ec commit b118d0e
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 73 deletions.
6 changes: 3 additions & 3 deletions library/ako-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void akoSavePgmI16(size_t width, size_t height, size_t in_stride, const int16_t*

// format.c:

void akoFormatToPlanarI16Yuv(int keep_transparent_pixels, enum akoColor, size_t channels, size_t width, size_t height,
void akoFormatToPlanarI16Yuv(int discard_non_visible, enum akoColor, size_t channels, size_t width, size_t height,
size_t in_stride, size_t out_planes_spacing, const uint8_t* in, int16_t* out);
void akoFormatToInterleavedU8Rgb(enum akoColor, size_t channels, size_t width, size_t height, size_t in_planes_spacing,
size_t out_stride, int16_t* in,
Expand Down Expand Up @@ -94,8 +94,8 @@ size_t akoImageMaxPlanesSpacingSize(size_t image_w, size_t image_h, size_t tiles

// quantization.c:

int16_t akoGate(int factor, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h);
int16_t akoQuantization(int factor, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h);
int16_t akoGate(int factor, int factor_mul, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h);
int16_t akoQuantization(int factor, int factor_mul, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h);

// wavelet-cdf53.c:

Expand Down
38 changes: 20 additions & 18 deletions library/ako.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,15 @@ enum akoStatus
AKO_BROKEN_INPUT,
};

enum akoWrap // Wrap mode
{
AKO_WRAP_CLAMP = 0,
AKO_WRAP_MIRROR,
AKO_WRAP_REPEAT,
AKO_WRAP_ZERO,
};

enum akoWavelet // Wavelet transformation
enum akoWavelet
{
AKO_WAVELET_DD137 = 0,
AKO_WAVELET_CDF53,
AKO_WAVELET_HAAR,
AKO_WAVELET_NONE,
};

enum akoColor // Color transformation
enum akoColor
{
AKO_COLOR_YCOCG = 0,
AKO_COLOR_SUBTRACT_G,
Expand All @@ -65,9 +57,18 @@ enum akoColor // Color transformation
AKO_COLOR_YCOCG_Q, // Internal
};

enum akoCompression // Compression method
enum akoWrap
{
AKO_WRAP_CLAMP = 0,
AKO_WRAP_MIRROR,
AKO_WRAP_REPEAT,
AKO_WRAP_ZERO,
};

enum akoCompression
{
AKO_COMPRESSION_ELIAS_RLE = 0,
AKO_COMPRESSION_KAGARI = 0,
AKO_COMPRESSION_MANBAVARAN,
AKO_COMPRESSION_NONE,
};

Expand All @@ -84,16 +85,17 @@ enum akoEvent

struct akoSettings
{
enum akoWrap wrap;
enum akoWavelet wavelet;
enum akoColor color;
enum akoWrap wrap;
enum akoCompression compression;
size_t tiles_dimension;

int discard_transparent_pixels;

int quantization;
int gate;

int chroma_loss;
int discard_non_visible;
};

struct akoCallbacks
Expand All @@ -116,10 +118,10 @@ struct akoHead

uint32_t flags;
// bits 0-3 : Channels, 0 = Gray, 1 = Gray + Alpha, 2 = RGB, 3 = RGBA, etc...
// bits 4-5 : Wrap, 0 = Clamp, 1 = Repeat, 2 = Set to zero
// bits 4-5 : Wrap, 0 = Clamp, 1 = Mirror, 2 = Repeat, 3 = Zero
// bits 6-7 : Wavelet, 0 = DD137, 1 = CDF53, 2 = Haar, 3 = None
// bits 8-9 : Color, 0 = YCOCG, 1 = YCOCG-R, 2 = Subtract Green, 3 = RGB
// bits 10-11 : Compression, 0 = Elias Coding + Rle, 1 = No compression
// bits 8-9 : Color, 0 = YCOCG, 1 = Subtract Green, 2 = None, 3 = Internal
// bits 10-11 : Compression, 0 = Elias Coding, 1 = rAns, 2 = No compression
// bits 12-16 : Tiles dimension, 0 = No tiles, 1 = 8x8, 2 = 16x16, 3 = 32x32, 4 = 64x64, etc...
// bits 17-32 : Unused bits (always zero)
};
Expand Down
8 changes: 4 additions & 4 deletions library/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -131,9 +131,9 @@ AKO_EXPORT size_t akoEncodeExt(const struct akoCallbacks* c, const struct akoSet
// 1. Format
sEvent(t, tiles_no, AKO_EVENT_FORMAT_START, checked_c.events_data, checked_c.events);
{
akoFormatToPlanarI16Yuv(checked_s.discard_transparent_pixels, checked_s.color, channels, tile_w, tile_h,
image_w, planes_spacing,
(const uint8_t*)in + ((image_w * tile_y) + tile_x) * channels, workarea_a);
akoFormatToPlanarI16Yuv(checked_s.discard_non_visible, checked_s.color, channels, tile_w, tile_h, image_w,
planes_spacing, (const uint8_t*)in + ((image_w * tile_y) + tile_x) * channels,
workarea_a);
}
sEvent(t, tiles_no, AKO_EVENT_FORMAT_END, checked_c.events_data, checked_c.events);

Expand Down
17 changes: 8 additions & 9 deletions library/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,10 +27,10 @@ SOFTWARE.
#include "ako-private.h"


static inline void sDeinterleave(int discard_transparent_pixels, size_t channels, size_t width, size_t in_stride,
static inline void sDeinterleave(int discard_non_visible, size_t channels, size_t width, size_t in_stride,
size_t out_plane, const uint8_t* in, const uint8_t* in_end, int16_t* out)
{
if (discard_transparent_pixels != 0)
if (discard_non_visible != 0)
{
for (; in < in_end; in += in_stride, out += width)
for (size_t col = 0; col < width; col++)
Expand Down Expand Up @@ -61,11 +61,10 @@ static inline void sDeinterleave(int discard_transparent_pixels, size_t channels
}


void akoFormatToPlanarI16Yuv(int discard_transparent_pixels, enum akoColor color, size_t channels, size_t width,
size_t height, size_t input_stride, size_t out_planes_spacing, const uint8_t* in,
int16_t* out)
void akoFormatToPlanarI16Yuv(int discard_non_visible, enum akoColor color, size_t channels, size_t width, size_t height,
size_t input_stride, size_t out_planes_spacing, const uint8_t* in, int16_t* out)
{
// Deinterleave, convert from u8 to i16, and remove (or not) transparent pixels
// Deinterleave, convert from u8 to i16, and remove (or not) non visible pixels
{
const size_t in_stride = input_stride * channels;
const size_t out_plane = (width * height) + out_planes_spacing;
Expand All @@ -75,9 +74,9 @@ void akoFormatToPlanarI16Yuv(int discard_transparent_pixels, enum akoColor color
if (channels == 3)
sDeinterleave(0, 3, width, in_stride, out_plane, in, in_end, out);
else if (channels == 4)
sDeinterleave(discard_transparent_pixels, 4, width, in_stride, out_plane, in, in_end, out);
sDeinterleave(discard_non_visible, 4, width, in_stride, out_plane, in, in_end, out);
else if (channels == 2)
sDeinterleave(discard_transparent_pixels, 2, width, in_stride, out_plane, in, in_end, out);
sDeinterleave(discard_non_visible, 2, width, in_stride, out_plane, in, in_end, out);
else if (channels == 1)
sDeinterleave(0, 1, width, in_stride, out_plane, in, in_end, out);
else
Expand Down
4 changes: 2 additions & 2 deletions library/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -56,7 +56,7 @@ static inline enum akoStatus sValidate(size_t channels, size_t width, size_t hei
color != AKO_COLOR_NONE)
return AKO_INVALID_COLOR_TRANSFORMATION;

if (compression != AKO_COMPRESSION_ELIAS_RLE && compression != AKO_COMPRESSION_NONE)
if (compression != AKO_COMPRESSION_KAGARI && compression != AKO_COMPRESSION_NONE)
return AKO_INVALID_COMPRESSION_METHOD;

return AKO_OK;
Expand Down
17 changes: 13 additions & 4 deletions library/lifting.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -168,10 +168,19 @@ void akoLift(size_t tile_no, const struct akoSettings* s, size_t channels, size_
// Iterate in Vuy order
for (size_t ch = (channels - 1); ch < channels; ch--) // Yes, underflows
{
const int16_t q =
akoQuantization(s->quantization * ((ch == 0) ? 1 : 2), tile_w, tile_h, current_w, current_h);
int16_t q = 0;
int16_t g = 0;

const int16_t g = akoGate(s->gate * ((ch == 0) ? 1 : 2), tile_w, tile_h, current_w, current_h);
if (ch == 0)
{
q = akoQuantization(s->quantization, 1, tile_w, tile_h, current_w, current_h);
g = akoGate(s->gate, 1, tile_w, tile_h, current_w, current_h);
}
else
{
q = akoQuantization(s->quantization, s->chroma_loss + 1, tile_w, tile_h, current_w, current_h);
g = akoGate(s->gate, s->chroma_loss + 1, tile_w, tile_h, current_w, current_h);
}

// 1. Lift
int16_t* lp = in + (tile_w * tile_h + planes_space) * ch;
Expand Down
11 changes: 6 additions & 5 deletions library/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,17 +31,18 @@ AKO_EXPORT struct akoSettings akoDefaultSettings()
{
struct akoSettings s = {0};

s.wrap = AKO_WRAP_CLAMP;
s.wavelet = AKO_WAVELET_DD137;
s.color = AKO_COLOR_YCOCG;
s.compression = AKO_COMPRESSION_ELIAS_RLE;
s.wrap = AKO_WRAP_CLAMP;
s.compression = AKO_COMPRESSION_KAGARI;
s.tiles_dimension = 0;

s.discard_transparent_pixels = 0;

s.quantization = 16;
s.gate = 0;

s.chroma_loss = 1;
s.discard_non_visible = 0;

return s;
}

Expand Down
12 changes: 7 additions & 5 deletions library/quantization.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -64,12 +64,13 @@ static float sExponential(float factor, float tile_w, float tile_h, float curren
}


int16_t akoGate(int factor, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h)
int16_t akoGate(int factor, int factor_mul, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h)
{
if (factor <= 0)
return 0;

float g = sExponential((float)factor, (float)tile_w, (float)tile_h, (float)current_w, (float)current_h);
float g = sExponential((float)factor * (float)factor_mul, (float)tile_w, (float)tile_h, (float)current_w,
(float)current_h);

if (g < 0.0F)
g = 0.0F;
Expand All @@ -80,12 +81,13 @@ int16_t akoGate(int factor, size_t tile_w, size_t tile_h, size_t current_w, size
}


int16_t akoQuantization(int factor, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h)
int16_t akoQuantization(int factor, int factor_mul, size_t tile_w, size_t tile_h, size_t current_w, size_t current_h)
{
if (factor <= 0)
return 1;

float q = sExponential((float)factor, (float)tile_w, (float)tile_h, (float)current_w, (float)current_h);
float q = sExponential((float)factor * (float)factor_mul, (float)tile_w, (float)tile_h, (float)current_w,
(float)current_h);

if (q < 1.0F)
q = 1.0F;
Expand Down
27 changes: 15 additions & 12 deletions tools/akodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2021 Alexander Brandt
Copyright (c) 2021-2022 Alexander Brandt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -77,9 +77,10 @@ class AkoImage
size_t channels;
void* data;

enum akoWrap wrap;
enum akoWavelet wavelet;
enum akoColor color;
akoWavelet wavelet;
akoColor color;
akoWrap wrap;
akoCompression compression;
size_t blob_size;

public:
Expand All @@ -89,10 +90,11 @@ class AkoImage
size_t get_channels() const { return channels; };
const void* get_data() const { return (const void*)(data); };

enum akoWrap get_wrap() const { return wrap; };
enum akoWavelet get_wavelet() const { return wavelet; };
enum akoColor get_color() const { return color; };
size_t get_blob_size() const { return blob_size; };
akoWavelet get_wavelet() const { return wavelet; };
akoColor get_color() const { return color; };
akoWrap get_wrap() const { return wrap; };
akoCompression get_compression() const { return compression; };
size_t get_blob_size() const { return blob_size; };
// clang-format on

AkoImage(const std::string& filename, bool quiet, bool benchmark)
Expand Down Expand Up @@ -145,9 +147,10 @@ class AkoImage
}

// Bye!
wrap = settings.wrap;
wavelet = settings.wavelet;
color = settings.color;
wrap = settings.wrap;
compression = settings.compression;
}

~AkoImage()
Expand Down Expand Up @@ -177,9 +180,9 @@ void AkoDec(const std::string& filename_input, const std::string& filename_outpu
const auto ako = AkoImage(filename_input, quiet, benchmark);

if (verbose == true)
std::printf("Input data: %zu channels, %zux%zu px, wavelet: %i, color: %i, wrap: %i\n", ako.get_channels(),
ako.get_width(), ako.get_height(), (int)ako.get_wavelet(), (int)ako.get_color(),
(int)ako.get_wrap());
std::printf("Input data: %zu channels, %zux%zu px, wavelet: %i, color: %i, wrap: %i, compression: %i\n",
ako.get_channels(), ako.get_width(), ako.get_height(), (int)ako.get_wavelet(), (int)ako.get_color(),
(int)ako.get_wrap(), (int)ako.get_compression());

// Checksum data
uint32_t input_checksum = 0;
Expand Down
Loading

0 comments on commit b118d0e

Please sign in to comment.