changeset 4241:63eb5966f105

prevented clipping for FMT_*32_*; some endianness-related changes
author Eugene Zagidullin <e.asphyx@gmail.com>
date Mon, 04 Feb 2008 02:52:52 +0300
parents 29c8603a877a
children 21008f43bb93
files src/libSAD/dither.c src/libSAD/dither_ops.c
diffstat 2 files changed, 142 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/libSAD/dither.c	Mon Feb 04 01:30:53 2008 +0300
+++ b/src/libSAD/dither.c	Mon Feb 04 02:52:52 2008 +0300
@@ -17,8 +17,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/*#define CLIPPING_DEBUG*/
-/*#define DITHER_DEBUG*/
+/* #define CLIPPING_DEBUG */
+/* #define DITHER_DEBUG */
 
 #include "common.h"
 #include "dither_ops.h"
@@ -149,13 +149,13 @@
 #endif
   }
 
-  if (precision_loss && (n_bits_to_loose >= 1)) sample += (1L << (n_bits_to_loose - 1));
+  if (precision_loss && (n_bits_to_loose >= 1) && (inbits < 32 || fracbits != 0)) sample += (1L << (n_bits_to_loose - 1));
 
 #ifdef DITHER_DEBUG
   int32_t val_wo_dither = sample >> n_bits_to_loose;
   val_wo_dither = CLIP(val_wo_dither, maxint);
 #endif
-  if (dither && precision_loss && (n_bits_to_loose >= 1)) {
+  if (dither && precision_loss && (n_bits_to_loose >= 1) && (inbits < 32 || fracbits != 0)) {
     int32_t dither_num = triangular_dither_noise(n_bits_to_loose + 1);
     sample += dither_num;
   }
@@ -317,7 +317,11 @@
     case SAD_SAMPLE_U24_LE:
     case SAD_SAMPLE_U24_BE: priv->output_bits = 24; break;
     case SAD_SAMPLE_S32:
-    case SAD_SAMPLE_U32: priv->output_bits = 32; break;
+    case SAD_SAMPLE_S32_LE:
+    case SAD_SAMPLE_S32_BE:
+    case SAD_SAMPLE_U32:
+    case SAD_SAMPLE_U32_LE:
+    case SAD_SAMPLE_U32_BE: priv->output_bits = 32; break;
     case SAD_SAMPLE_FLOAT: break;
     default:
       free(priv);
@@ -341,7 +345,11 @@
     case SAD_SAMPLE_U24_LE:
     case SAD_SAMPLE_U24_BE: priv->input_bits = 24; break;
     case SAD_SAMPLE_S32:
-    case SAD_SAMPLE_U32: priv->input_bits = 32; break;
+    case SAD_SAMPLE_S32_LE:
+    case SAD_SAMPLE_S32_BE:
+    case SAD_SAMPLE_U32:
+    case SAD_SAMPLE_U32_LE:
+    case SAD_SAMPLE_U32_BE: priv->input_bits = 32; break;
     case SAD_SAMPLE_FIXED32: priv->input_fracbits = inbuf_format->fracbits; break;
     case SAD_SAMPLE_FLOAT: break;
     default:
--- a/src/libSAD/dither_ops.c	Mon Feb 04 01:30:53 2008 +0300
+++ b/src/libSAD/dither_ops.c	Mon Feb 04 02:52:52 2008 +0300
@@ -510,6 +510,48 @@
   ((int32_t**)buf)[ch][i] = (int32_t)sample;
 }
 
+/* LE: signed */
+static int32_t get_s32_le_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)SAD_GET_LE32(tmp);
+}
+
+static int32_t get_s32_le_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)SAD_GET_LE32(tmp);
+}
+
+static void put_s32_le_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_LE32(tmp, sample);
+}
+
+static void put_s32_le_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_LE32(tmp, sample);
+}
+
+/* BE: signed */
+static int32_t get_s32_be_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)SAD_GET_BE32(tmp);
+}
+
+static int32_t get_s32_be_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)SAD_GET_BE32(tmp);
+}
+
+static void put_s32_be_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_BE32(tmp, sample);
+}
+
+static void put_s32_be_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_BE32(tmp, sample);
+}
+
 /* unsigned */
 static int32_t get_u32_i_sample (void *buf, int nch, int ch, int i) {
   return ((int32_t*)buf)[i*nch+ch] - (int32_t)(1L<<31);
@@ -527,6 +569,48 @@
   ((uint32_t**)buf)[ch][i] = (uint32_t)(sample + (int32_t)(1L<<31));
 }
 
+/* LE: unsigned */
+static int32_t get_u32_le_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)SAD_GET_LE32(tmp) - (int32_t)(1L<<31);
+}
+
+static int32_t get_u32_le_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)SAD_GET_LE32(tmp) - (int32_t)(1L<<31);
+}
+
+static void put_u32_le_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_LE32(tmp, sample + (int32_t)(1L<<31));
+}
+
+static void put_u32_le_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_LE32(tmp, sample + (int32_t)(1L<<31));
+}
+
+/* BE: unsigned */
+static int32_t get_u32_be_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)SAD_GET_BE32(tmp) - (int32_t)(1L<<31);
+}
+
+static int32_t get_u32_be_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)SAD_GET_BE32(tmp) - (int32_t)(1L<<31);
+}
+
+static void put_u32_be_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_BE32(tmp, sample + (int32_t)(1L<<31));
+}
+
+static void put_u32_be_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_BE32(tmp, sample + (int32_t)(1L<<31));
+}
+
 static SAD_buffer_ops buf_s32_i_ops = {
   &get_s32_i_sample,
   &put_s32_i_sample
@@ -537,6 +621,26 @@
   &put_s32_s_sample
 };
 
+static SAD_buffer_ops buf_s32_le_i_ops = {
+  &get_s32_le_i_sample,
+  &put_s32_le_i_sample
+};
+
+static SAD_buffer_ops buf_s32_le_s_ops = {
+  &get_s32_le_s_sample,
+  &put_s32_le_s_sample
+};
+
+static SAD_buffer_ops buf_s32_be_i_ops = {
+  &get_s32_be_i_sample,
+  &put_s32_be_i_sample
+};
+
+static SAD_buffer_ops buf_s32_be_s_ops = {
+  &get_s32_be_s_sample,
+  &put_s32_be_s_sample
+};
+
 static SAD_buffer_ops buf_u32_i_ops = {
   &get_u32_i_sample,
   &put_u32_i_sample
@@ -547,6 +651,26 @@
   &put_u32_s_sample
 };
 
+static SAD_buffer_ops buf_u32_le_i_ops = {
+  &get_u32_le_i_sample,
+  &put_u32_le_i_sample
+};
+
+static SAD_buffer_ops buf_u32_le_s_ops = {
+  &get_u32_le_s_sample,
+  &put_u32_le_s_sample
+};
+
+static SAD_buffer_ops buf_u32_be_i_ops = {
+  &get_u32_be_i_sample,
+  &put_u32_be_i_sample
+};
+
+static SAD_buffer_ops buf_u32_be_s_ops = {
+  &get_u32_be_s_sample,
+  &put_u32_be_s_sample
+};
+
 static SAD_buffer_ops *SAD_buffer_optable[SAD_SAMPLE_MAX][SAD_CHORDER_MAX] = {
   {&buf_s8_i_ops,     &buf_s8_s_ops},	  /* SAD_SAMPLE_S8     */
   {&buf_u8_i_ops,     &buf_u8_s_ops},	  /* SAD_SAMPLE_U8     */
@@ -566,11 +690,11 @@
   {&buf_u24_be_i_ops, &buf_u24_be_s_ops}, /* SAD_SAMPLE_U24_BE */
 
   {&buf_s32_i_ops,    &buf_s32_s_ops}, 	  /* SAD_SAMPLE_S32    */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_S32_LE */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_S32_BE */
+  {&buf_s32_le_i_ops, &buf_s32_le_s_ops}, /* SAD_SAMPLE_S32_LE */
+  {&buf_s32_be_i_ops, &buf_s32_be_s_ops}, /* SAD_SAMPLE_S32_BE */
   {&buf_u32_i_ops,    &buf_u32_s_ops}, 	  /* SAD_SAMPLE_U32    */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_U32_LE */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_U32_BE */
+  {&buf_u32_le_i_ops, &buf_u32_le_s_ops}, /* SAD_SAMPLE_U32_LE */
+  {&buf_u32_be_i_ops, &buf_u32_be_s_ops}, /* SAD_SAMPLE_U32_BE */
 
   {&buf_s32_i_ops,    &buf_s32_s_ops}, 	  /* SAD_SAMPLE_FIXED32*/