bool ExifCommon::TagHeaderType::verifyTypeAndCount()

in imagecore/formats/exif/exifcommon.cpp [82:134]


bool ExifCommon::TagHeaderType::verifyTypeAndCount(unsigned short exifType, uint32_t count) const
{
	switch(m_type) {
		// relax type-checking for signed vs unsigned of the same type, since there are images out there, that don't stick to the exact spec
		case kTagType::kUnsignedByte:
		case kTagType::kSignedByte: {      // (1 byte per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kUnsignedByte, (uint16_t)kTagType::kSignedByte);
			break;
		}

		case kTagType::kUnsignedShort:
		case kTagType::kSignedShort: {      // (2 bytes per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kUnsignedShort, (uint16_t)kTagType::kSignedShort);
			break;
		}

		case kTagType::kUnsignedLong:
		case kTagType::kSignedLong: {      // (4 bytes per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kUnsignedLong, (uint16_t)kTagType::kSignedLong);
			break;
		}

		case kTagType::kUnsignedRational:
		case kTagType::kSignedRational: {  // (8 bytes per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kUnsignedRational, (uint16_t)kTagType::kSignedRational);
			break;
		}

		case kTagType::kSingle: {  // (4 bytes per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kSingle, (uint16_t)kTagType::kSingle);
			break;
		}

		case kTagType::kDouble: {  // (8 bytes per component)
			return relaxedTypeAndCountCheck(exifType, count, (uint16_t)kTagType::kDouble, (uint16_t)kTagType::kDouble);
			break;
		}

		case kTagType::kASCIIString: {
			if(((ExifCommon::kTagType)exifType != kTagType::kASCIIString) ||
			(count >= kMaxExifStringLength) ||
			(count == 0)) {
				return false;
			}
			break;
		}

		default: {
			return false;
		}
	}
	return true;
}