misc: Clean up endian macros, eliminate use of ntohs and friends.

This commit is contained in:
Solomon Peachy 2020-01-25 07:33:52 -05:00
parent a42576e326
commit d0d6ef32b4
5 changed files with 97 additions and 67 deletions

View File

@ -37,12 +37,6 @@
#include <libusb.h>
#ifdef _WIN32
#include <winsock.h>
#else
#include <arpa/inet.h>
#endif
#ifndef __BACKEND_COMMON_H
#define __BACKEND_COMMON_H
@ -65,8 +59,14 @@
#define le64_to_cpu(__x) __x
#define le32_to_cpu(__x) __x
#define le16_to_cpu(__x) __x
#define be16_to_cpu(__x) ntohs(__x)
#define be32_to_cpu(__x) ntohl(__x)
#define be16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define be32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define be64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
@ -75,8 +75,16 @@
(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56)))
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
#else
#define le16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define le32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define le64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
@ -86,22 +94,6 @@
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56)))
#define le32_to_cpu(x) \
({ \
uint32_t __x = (x); \
((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
})
#define le16_to_cpu(x) \
({ \
uint16_t __x = (x); \
((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8))); \
})
#define be64_to_cpu(__x) __x
#define be32_to_cpu(__x) __x
#define be16_to_cpu(__x) __x

View File

@ -109,9 +109,9 @@ static int send_plane(struct kodak1400_ctx *ctx,
cmdbuf[3] = planeno;
if (planedata) {
temp16 = htons(job->hdr.columns);
temp16 = be16_to_cpu(job->hdr.columns);
memcpy(cmdbuf+7, &temp16, 2);
temp16 = htons(job->hdr.rows);
temp16 = be16_to_cpu(job->hdr.rows);
memcpy(cmdbuf+9, &temp16, 2);
}

View File

@ -949,7 +949,7 @@ static void *mitsu70x_combine_jobs(const void *vjob1,
JOB_EQUIV(matte);
JOB_EQUIV(sharpen);
if (hdr1->multicut || hdr2->multicut)
if (hdr1->multicut || hdr2->multicut) // XXX type 5 (2x6*2) -> type4 (2x6*4), 6x9 needed, 2628 rows. use '4' in multicut field.
goto done;
if (job1->raw_format || job2->raw_format)
goto done;
@ -1491,6 +1491,7 @@ static int mitsu70x_get_memorystatus(struct mitsu70x_ctx *ctx, const struct mits
memcpy(cmdbuf + 4, &tmp, 2);
/* We have to lie about print sizes in 4x6*2 multicut modes */
// XXX what about type4 (2x6*4) and type3 (3x6*3)
tmp = job->rows;
if (tmp == 2730 && mcut == 1) {
if (ctx->type == P_MITSU_D70X ||

View File

@ -47,7 +47,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <math.h>
//-------------------------------------------------------------------------
@ -227,27 +226,45 @@ static void LeadEdgeCorrection(void);
// Endian Manipulation macros
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
#define le64_to_cpu(__x) __x
#define le32_to_cpu(__x) __x
#define le16_to_cpu(__x) __x
#define be16_to_cpu(__x) ntohs(__x)
#define be32_to_cpu(__x) ntohl(__x)
#else
#define le32_to_cpu(x) \
({ \
uint32_t __x = (x); \
((uint32_t)( \
#define be16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define be32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
})
#define le16_to_cpu(x) \
({ \
uint16_t __x = (x); \
((uint16_t)( \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define be64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
#else
#define le16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8))); \
})
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define le32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define le64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56)))
#define be64_to_cpu(__x) __x
#define be32_to_cpu(__x) __x
#define be16_to_cpu(__x) __x
#endif
@ -256,6 +273,8 @@ static void LeadEdgeCorrection(void);
#define cpu_to_le32 le32_to_cpu
#define cpu_to_be16 be16_to_cpu
#define cpu_to_be32 be32_to_cpu
#define cpu_to_le64 le64_to_cpu
#define cpu_to_be64 be64_to_cpu
//-------------------------------------------------------------------------
// Data declarations

View File

@ -51,7 +51,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include "libMitsuD70ImageReProcess.h"
@ -61,27 +60,45 @@
// Endian Manipulation macros
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
#define le64_to_cpu(__x) __x
#define le32_to_cpu(__x) __x
#define le16_to_cpu(__x) __x
#define be16_to_cpu(__x) ntohs(__x)
#define be32_to_cpu(__x) ntohl(__x)
#else
#define le32_to_cpu(x) \
({ \
uint32_t __x = (x); \
((uint32_t)( \
#define be16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define be32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
})
#define le16_to_cpu(x) \
({ \
uint16_t __x = (x); \
((uint16_t)( \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define be64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
#else
#define le16_to_cpu(__x) ((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8))); \
})
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) ))
#define le32_to_cpu(__x) ((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
#define le64_to_cpu(__x) ((uint64_t)( \
(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56)))
#define be64_to_cpu(__x) __x
#define be32_to_cpu(__x) __x
#define be16_to_cpu(__x) __x
#endif
@ -90,7 +107,8 @@
#define cpu_to_le32 le32_to_cpu
#define cpu_to_be16 be16_to_cpu
#define cpu_to_be32 be32_to_cpu
#define cpu_to_le64 le64_to_cpu
#define cpu_to_be64 be64_to_cpu
//-------------------------------------------------------------------------
// Data declarations