Skip to content

Commit

Permalink
version 0.3.0-rc1
Browse files Browse the repository at this point in the history
Better quantization
  • Loading branch information
rcanut committed Apr 18, 2023
1 parent d3c5ddd commit aa3aa91
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 39 deletions.
63 changes: 46 additions & 17 deletions decoder/nhw_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
****************************************************************************
* NHW Image Codec *
* file: nhw_decoder.c *
* version: 0.2.7 *
* last update: $ 18112022 nhw exp $ *
* version: 0.3.0-rc1 *
* last update: $ 04182023 nhw exp $ *
* *
****************************************************************************
****************************************************************************
Expand Down Expand Up @@ -657,26 +657,55 @@ void decode_image(image_buffer *im,decode_state *os,char *file_name)
im->im_jpeg[count]=scan;

}

for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
if (im->setup->quality_setting<=LOW4)
{
for (scan=i+1,j=1;j<IM_DIM-1;j++,scan++)
for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
{
if (abs(im_nhw[scan])>8)
for (scan=i+1,j=1;j<IM_DIM-1;j++,scan++)
{
if (abs(im_nhw[scan-(2*IM_DIM+1)])>8) continue;
if (abs(im_nhw[scan-(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan-(2*IM_DIM-1)])>8) continue;
if (abs(im_nhw[scan-1])>8) continue;
if (abs(im_nhw[scan+1])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM-1)])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM+1)])>8) continue;
if (abs(im_nhw[scan])>8)
{
if (abs(im_nhw[scan-(2*IM_DIM+1)])>16) continue;
if (abs(im_nhw[scan-(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan-(2*IM_DIM-1)])>16) continue;
if (abs(im_nhw[scan-1])>8) continue;
if (abs(im_nhw[scan+1])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM-1)])>16) continue;
if (abs(im_nhw[scan+(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM+1)])>16) continue;

if (i>=IM_SIZE || j>=(IM_DIM>>1))
if (i>=IM_SIZE || j>=(IM_DIM>>1))
{
if (im_nhw[scan]>0) im_nhw[scan]--;
else im_nhw[scan]++;
}
}
}
}
}
else
{
for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
{
for (scan=i+1,j=1;j<IM_DIM-1;j++,scan++)
{
if (abs(im_nhw[scan])>8)
{
if (im_nhw[scan]>0) im_nhw[scan]--;
else im_nhw[scan]++;
if (abs(im_nhw[scan-(2*IM_DIM+1)])>8) continue;
if (abs(im_nhw[scan-(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan-(2*IM_DIM-1)])>8) continue;
if (abs(im_nhw[scan-1])>8) continue;
if (abs(im_nhw[scan+1])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM-1)])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM)])>8) continue;
if (abs(im_nhw[scan+(2*IM_DIM+1)])>8) continue;

if (i>=IM_SIZE || j>=(IM_DIM>>1))
{
if (im_nhw[scan]>0) im_nhw[scan]--;
else im_nhw[scan]++;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions decoder/nhw_decoder_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
****************************************************************************
* NHW Image Codec *
* file: nhw_decoder_cli.c *
* version: 0.2.7 *
* last update: $ 18112022 nhw exp $ *
* version: 0.3.0-rc1 *
* last update: $ 04182023 nhw exp $ *
* *
****************************************************************************
****************************************************************************
Expand Down Expand Up @@ -52,7 +52,7 @@
#include "nhw_decoder.h"

#define PROGRAM "nhw-dec"
#define VERSION "0.2.8"
#define VERSION "0.3.0-rc1"

int setup_bmp_header(char* bmp_header, nhw_image_s* im_ctx);
int write_image_bmp(decode_state *dec, image_buffer *im, char *file_name);
Expand Down
61 changes: 45 additions & 16 deletions encoder/image_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
****************************************************************************
* NHW Image Codec *
* file: image_processing.c *
* version: 0.2.9.8 *
* last update: $ 02072023 nhw exp $ *
* version: 0.3.0-rc1 *
* last update: $ 04182023 nhw exp $ *
* *
****************************************************************************
****************************************************************************
Expand Down Expand Up @@ -1791,25 +1791,54 @@ void offsetY_recons256(image_buffer *im, encode_state *enc, int m1, int part)

if (!part)
{
for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
if (im->setup->quality_setting<=LOW4)
{
for (e=i+1,j=1;j<IM_DIM-1;j++,e++)
for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
{
if (abs(im->im_jpeg[e])>=8)
for (e=i+1,j=1;j<IM_DIM-1;j++,e++)
{
if (abs(im->im_jpeg[e-(2*IM_DIM+1)])>=8) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM-1)])>=8) continue;
if (abs(im->im_jpeg[e-1])>=8) continue;
if (abs(im->im_jpeg[e+1])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM-1)])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM+1)])>=8) continue;
if (abs(im->im_jpeg[e])>=8)
{
if (abs(im->im_jpeg[e-(2*IM_DIM+1)])>=16) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM-1)])>=16) continue;
if (abs(im->im_jpeg[e-1])>=8) continue;
if (abs(im->im_jpeg[e+1])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM-1)])>=16) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM+1)])>=16) continue;

if (i>=IM_SIZE || j>=(IM_DIM>>1))
if (i>=IM_SIZE || j>=(IM_DIM>>1))
{
if (im->im_jpeg[e]>0) im->im_jpeg[e]--;
else im->im_jpeg[e]++;
}
}
}
}
}
else
{
for (i=(2*IM_DIM);i<((2*IM_SIZE)-(2*IM_DIM));i+=(2*IM_DIM))
{
for (e=i+1,j=1;j<IM_DIM-1;j++,e++)
{
if (abs(im->im_jpeg[e])>=8)
{
if (im->im_jpeg[e]>0) im->im_jpeg[e]--;
else im->im_jpeg[e]++;
if (abs(im->im_jpeg[e-(2*IM_DIM+1)])>=8) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e-(2*IM_DIM-1)])>=8) continue;
if (abs(im->im_jpeg[e-1])>=8) continue;
if (abs(im->im_jpeg[e+1])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM-1)])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM)])>=8) continue;
if (abs(im->im_jpeg[e+(2*IM_DIM+1)])>=8) continue;

if (i>=IM_SIZE || j>=(IM_DIM>>1))
{
if (im->im_jpeg[e]>0) im->im_jpeg[e]--;
else im->im_jpeg[e]++;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions encoder/nhw_encoder_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
****************************************************************************
* NHW Image Codec *
* file: nhw_encoder_cli.c *
* version: 0.2.9.8 *
* last update: $ 02072023 nhw exp $ *
* version: 0.3.0-rc1 *
* last update: $ 04182023 nhw exp $ *
* *
****************************************************************************
****************************************************************************
Expand Down Expand Up @@ -50,7 +50,7 @@
#include "codec.h"

#define PROGRAM "nhw-enc"
#define VERSION "0.2.9.8"
#define VERSION "0.3.0-rc1"

#define NHW_QUALITY_MIN LOW20
#define NHW_QUALITY_MAX HIGH3
Expand Down

0 comments on commit aa3aa91

Please sign in to comment.