@@ -337,105 +337,10 @@ double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndianDouble(ret); } -- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap16(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap32(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap64(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapFloat(buffer[i]); -#endif - - return size; -} - -- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifndef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapDouble(buffer[i]); -#endif - - return size; -} - - (uint16_t)readLittleEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromLittleEndian16(ret); @@ -467,110 +372,10 @@ double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndianDouble(ret); } -- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap16(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap32(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwap64(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapFloat(buffer[i]); -#endif - - return size; -} - -- (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer - count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - - [self readIntoBuffer: buffer exactLength: size]; - -#ifdef OF_FLOAT_BIG_ENDIAN - for (size_t i = 0; i < count; i++) - buffer[i] = OFByteSwapDouble(buffer[i]); -#endif - - return size; -} - - (OFData *)readDataWithCount: (size_t)count { return [self readDataWithItemSize: 1 count: count]; } @@ -1259,135 +1064,10 @@ { double_ = OFToBigEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } -- (void)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap16(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap32(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - -#ifdef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap64(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianFloats: (const float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - -#ifdef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - float *tmp = OFAllocMemory(count, sizeof(float)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapFloat(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeBigEndianDoubles: (const double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - -#ifdef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - double *tmp = OFAllocMemory(count, sizeof(double)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapDouble(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - - (void)writeLittleEndianInt16: (uint16_t)int16 { int16 = OFToLittleEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } @@ -1414,135 +1094,10 @@ { double_ = OFToLittleEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } -- (void)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint16_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap16(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint32_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap32(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(uint64_t); - -#ifndef OF_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwap64(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianFloats: (const float *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(float); - -#ifndef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - float *tmp = OFAllocMemory(count, sizeof(float)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapFloat(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - -- (void)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count -{ - size_t size; - - if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) - @throw [OFOutOfRangeException exception]; - - size = count * sizeof(double); - -#ifndef OF_FLOAT_BIG_ENDIAN - [self writeBuffer: buffer length: size]; -#else - double *tmp = OFAllocMemory(count, sizeof(double)); - - @try { - for (size_t i = 0; i < count; i++) - tmp[i] = OFByteSwapDouble(buffer[i]); - - [self writeBuffer: tmp length: size]; - } @finally { - OFFreeMemory(tmp); - } -#endif -} - - (void)writeData: (OFData *)data { void *pool; size_t length;